1 line
20 KiB
JSON
1 line
20 KiB
JSON
|
{"ast":null,"code":"import { COMMENT, RULESET, DECLARATION } from './Enum.js';\nimport { abs, charat, trim, from, sizeof, strlen, substr, append, replace, indexof } from './Utility.js';\nimport { node, char, prev, next, peek, caret, alloc, dealloc, delimit, whitespace, escaping, identifier, commenter } from './Tokenizer.js';\n\n/**\n * @param {string} value\n * @return {object[]}\n */\nexport function compile(value) {\n return dealloc(parse('', null, null, null, [''], value = alloc(value), 0, [0], value));\n}\n\n/**\n * @param {string} value\n * @param {object} root\n * @param {object?} parent\n * @param {string[]} rule\n * @param {string[]} rules\n * @param {string[]} rulesets\n * @param {number[]} pseudo\n * @param {number[]} points\n * @param {string[]} declarations\n * @return {object}\n */\nexport function parse(value, root, parent, rule, rules, rulesets, pseudo, points, declarations) {\n var index = 0;\n var offset = 0;\n var length = pseudo;\n var atrule = 0;\n var property = 0;\n var previous = 0;\n var variable = 1;\n var scanning = 1;\n var ampersand = 1;\n var character = 0;\n var type = '';\n var props = rules;\n var children = rulesets;\n var reference = rule;\n var characters = type;\n while (scanning) switch (previous = character, character = next()) {\n // (\n case 40:\n if (previous != 108 && charat(characters, length - 1) == 58) {\n if (indexof(characters += replace(delimit(character), '&', '&\\f'), '&\\f', abs(index ? points[index - 1] : 0)) != -1) ampersand = -1;\n break;\n }\n // \" ' [\n case 34:\n case 39:\n case 91:\n characters += delimit(character);\n break;\n // \\t \\n \\r \\s\n case 9:\n case 10:\n case 13:\n case 32:\n characters += whitespace(previous);\n break;\n // \\\n case 92:\n characters += escaping(caret() - 1, 7);\n continue;\n // /\n case 47:\n switch (peek()) {\n case 42:\n case 47:\n append(comment(commenter(next(), caret()), root, parent, declarations), declarations);\n break;\n default:\n characters += '/';\n }\n break;\n // {\n case 123 * variable:\n points[index++] = strlen(characters) * ampersand;\n // } ; \\0\n case 125 * variable:\n case 59:\n case 0:\n switch (character) {\n // \\0 }\n case 0:\n case 125:\n scanning = 0;\n // ;\n case 59 + offset:\n if (ampersand == -1) characters = replace(characters, /\\f/g, '');\n if (property > 0 && strlen(characters) - length) append(property > 32 ? declaration(characters + ';', rule, parent, length - 1, declarations) : declaration(replace(characters, ' ', '') + ';', rule, parent, length - 2, declarations), declarations);\n break;\n // @ ;\n case 59:\n characters += ';';\n // { rule/at-rule\n default:\n append(reference = ruleset(characters, root, parent, index, offset, rules, points, type, props = [], children = [], length, rulesets), rulesets);\n if (character === 123) if (offset === 0) parse(characters, root, reference, reference, props, rulesets, length, points, children);else switch (atrule === 99 && charat(characters, 3) === 110 ? 100 : atrule) {\n // d l m s\n case 100:\n case 108:\n case 109:\n case 115:\n parse(value, reference, reference, rule && append(ruleset(value, reference, reference, 0, 0, rules, points, type, rules, props = [], length, children), children), rules, children, length, points, rule ? props : children);\n break;\n default:\n parse(characters, reference, reference, reference, [''], children, 0, points, children);\n }\n }\n index = offset = property = 0, variable = ampersand = 1, type = characters = '', length = pseudo;\n break;\n // :\n case 58:\n length = 1 + strlen(characters), property = previous;\n default:\n if (variable < 1) if
|