diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d676788..b86e425f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +# v1.6.1 + +- [x] fix bugs when computing math functions. +- [x] reduce array mutations +- [x] supporting additional shorthands: scroll-timeline, scroll-padding, scroll-margin. +- [x] do not minify transform function when the absolute angle is greater or equals to 360deg + +```css + + a:hover { + +transform: rotate(calc(2.5*pi * 1rad)) } + .now { + transform: translate(100px, 100px) rotate(1215deg) skewX(10deg); +} +``` +should be minified to +```css +a:hover { + transform: rotate(450deg) +} +.now { + transform: translate(100px,100px)rotate(1215deg)skew(10deg) +} +``` + # v1.6.0 - [x] added support for math function `tan()`. diff --git a/README.md b/README.md index 673fc0ee..419f0b85 100644 --- a/README.md +++ b/README.md @@ -185,9 +185,9 @@ Try it [online](https://tbela99.github.io/css-parser/playground/) - [ ] place-content - [ ] place-items - [ ] place-self -- [ ] scroll-margin -- [ ] scroll-padding -- [ ] scroll-timeline +- [x] scroll-margin +- [x] scroll-padding +- [x] scroll-timeline - [x] text-decoration - [x] text-emphasis - [x] transition diff --git a/benchmark/package.json b/benchmark/package.json index b243d652..d1ea8522 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -10,11 +10,11 @@ "all": "npm run sizes && npm run bench && npm run report" }, "dependencies": { - "@tbela99/css-parser": "^1.4.11", - "@tbela99/css-parser2": "github:tbela99/css-parser#52223b9", + "@tbela99/css-parser": "^1.6.0", + "@tbela99/css-parser2": "github:tbela99/css-parser#20f608b", "clean-css": "^5.3.3", "css-tree": "^3.2.1", - "cssnano": "^8.0.6", + "cssnano": "^9.0.2", "csso": "^5.0.5", "esbuild": "^0.28.2", "lightningcss": "^1.33.0", diff --git a/dist/index-umd-web.js b/dist/index-umd-web.js index 28299453..e2294320 100644 --- a/dist/index-umd-web.js +++ b/dist/index-umd-web.js @@ -2569,7 +2569,7 @@ syntax: "none | nearest" }, "scroll-margin": { - syntax: "{1,4}" + syntax: " {1,4}" }, "scroll-margin-block": { syntax: "{1,2}" @@ -2581,7 +2581,7 @@ syntax: "" }, "scroll-margin-bottom": { - syntax: "" + syntax: " auto | " }, "scroll-margin-inline": { syntax: "{1,2}" @@ -2593,13 +2593,13 @@ syntax: "" }, "scroll-margin-left": { - syntax: "" + syntax: " auto | " }, "scroll-margin-right": { - syntax: "" + syntax: " auto | " }, "scroll-margin-top": { - syntax: "" + syntax: " auto | " }, "scroll-marker-group": { syntax: "none | before | after" @@ -2668,13 +2668,13 @@ syntax: "none | auto" }, "scroll-timeline": { - syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" + syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" }, "scroll-timeline-axis": { - syntax: "[ block | inline | x | y ]#" + syntax: " [ block | inline | x | y ]#" }, "scroll-timeline-name": { - syntax: "[ none | ]#" + syntax: " [ none | ]#" }, "scrollbar-color": { syntax: "auto | {2}" @@ -3167,6 +3167,9 @@ acos: { syntax: "acos( )" }, + alpha: { + syntax: "alpha( from / [ | none ] )" + }, anchor: { syntax: "anchor( ? && , ? )" }, @@ -7951,10 +7954,11 @@ t = components[3]; // @ts-ignore const k = getNumber(t); + const mul = 1 - k; const rgb = [ - 1 - Math.min(1, c * (1 - k) + k), - 1 - Math.min(1, m * (1 - k) + k), - 1 - Math.min(1, y * (1 - k) + k), + 1 - Math.min(1, c * mul + k), + 1 - Math.min(1, m * mul + k), + 1 - Math.min(1, y * mul + k), ]; if (components.length == 5) { rgb.push(getNumber(components[4])); @@ -10262,7 +10266,9 @@ } const value = evaluate(values); // @ts-ignore - let val = value[0].typ == exports.EnumToken.NumberTokenType || value[0].typ == exports.EnumToken.AngleTokenType + let val = value[0].typ == exports.EnumToken.NumberTokenType || + value[0].typ == exports.EnumToken.AngleTokenType || + value[0].typ == exports.EnumToken.PercentageTokenType ? +value[0].val : // @ts-expect-error value[0].l.val / value[0].r.val; @@ -10277,7 +10283,7 @@ [LOCEND]: value[0][LOCEND], } : { - typ: exports.EnumToken.NumberTokenType, + typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ, val: Math[token.val](val), [LOCSRCID]: value[0][LOCSRCID], [LOCSTA]: value[0][LOCSTA], @@ -10307,10 +10313,23 @@ }, ]; } + case "mod": case "atan2": case "pow": - case "rem": - case "mod": { + case "rem": { + { + let typ = token.chi[0]?.typ; + for (let i = 1; i < token.chi.length; i++) { + if (token.chi[i].typ == exports.EnumToken.WhitespaceTokenType || + token.chi[i].typ == exports.EnumToken.CommaTokenType || + token.chi[i].typ == exports.EnumToken.CommentTokenType) { + continue; + } + if (token.chi[i].typ != typ) { + return null; + } + } + } const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)); if (token.val == "atan2") { for (let i = 0; i < chi.length; i++) { @@ -10931,9 +10950,10 @@ } function srgb2cmykvalues(r, g, b, a = null) { const k = 1 - Math.max(r, g, b); - const c = k == 1 ? 0 : (1 - r - k) / (1 - k); - const m = k == 1 ? 0 : (1 - g - k) / (1 - k); - const y = k == 1 ? 0 : (1 - b - k) / (1 - k); + const div = 1 - k; + const c = k == 1 ? 0 : (1 - r - k) / div; + const m = k == 1 ? 0 : (1 - g - k) / div; + const y = k == 1 ? 0 : (1 - b - k) / div; const result = [c, m, y, k]; if (a != null && a < 1) { result.push(a); @@ -11747,9 +11767,13 @@ stack.pop(); } } - if (stack.length > 0) { - throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`); - } + // if (stack.length > 0) { + // throw new SyntaxError( + // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${ + // stack.at(-1)?.[LOC]?.lin + // }:${stack.at(-1)?.[LOC]?.col}`, + // ); + // } return trimSyntaxArray(tokens); } @@ -17212,6 +17236,65 @@ "padding-left": { shorthand: "padding" }, + "scroll-margin": { + shorthand: "scroll-margin", + properties: [ + "scroll-margin-top", + "scroll-margin-right", + "scroll-margin-bottom", + "scroll-margin-left" + ], + types: [ + "Length", + "Perc" + ], + "default": [ + "0" + ], + keywords: [ + "auto" + ] + }, + "scroll-margin-top": { + shorthand: "scroll-margin" + }, + "scroll-margin-right": { + shorthand: "scroll-margin" + }, + "scroll-margin-bottom": { + shorthand: "scroll-margin" + }, + "scroll-margin-left": { + shorthand: "scroll-margin" + }, + "scroll-padding": { + shorthand: "scroll-padding", + properties: [ + "scroll-padding-top", + "scroll-padding-right", + "scroll-padding-bottom", + "scroll-padding-left" + ], + types: [ + "Length", + "Perc" + ], + keywords: [ + "auto" + ] + }, + "scroll-padding-top": { + shorthand: "scroll-padding" + }, + "scroll-padding-right": { + shorthand: "scroll-padding" + }, + "scroll-padding-bottom": { + shorthand: "scroll-padding" + }, + "scroll-padding-left": { + shorthand: "scroll-padding" + }, "border-radius": { shorthand: "border-radius", properties: [ @@ -17433,6 +17516,53 @@ "flex-wrap": { shorthand: "flex-flow" }, + "scroll-timeline": { + shorthand: "scroll-timeline", + pattern: "scroll-timeline-name scroll-timeline-axis", + keywords: [ + "none", + "block", + "inline", + "x", + "y" + ], + "default": [ + "none", + "block" + ], + properties: { + "scroll-timeline-name": { + keywords: [ + "none" + ], + "default": [ + "none" + ], + types: [ + "DashedIden" + ] + }, + "scroll-timeline-axis": { + keywords: [ + "block", + "inline", + "x", + "y" + ], + "default": [ + "block" + ], + types: [ + ] + } + } + }, + "scroll-timeline-name": { + shorthand: "scroll-timeline" + }, + "scroll-timeline-axis": { + shorthand: "scroll-timeline" + }, container: { shorthand: "container", pattern: "container-name container-type", @@ -20637,7 +20767,7 @@ return true; } function minifyTransformFunctions(transform) { - const name = transform.val.toLowerCase(); + const name = transform.val; if ("skewX" == name) { transform.val = "skew"; return transform; @@ -20772,9 +20902,36 @@ let matrix = identity(); let mat; let transforms; + let shouldComputeMatrix = true; const cumulative = []; + // all transform function arguments must be 0 or scale(1) + for (const transform of transformLists) { + switch (transform.val) { + case "rotate": + case "rotateX": + case "rotateY": + case "rotateZ": + case "rotate3d": + for (const child of transform.chi) { + if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { + continue; + } + if ((child.typ != exports.EnumToken.AngleTokenType && + child.typ != exports.EnumToken.NumberTokenType && + child.typ != exports.EnumToken.PercentageTokenType) || + // angle >= 360deg, do not transform + Math.abs(getAngle(child)) >= 1) { + shouldComputeMatrix = false; + } + } + break; + } + if (!shouldComputeMatrix) { + break; + } + } for (const transformList of splitTransformList(transformLists)) { - mat = computeMatrix(transformList, identity()); + mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null; if (mat == null) { return null; } @@ -20803,60 +20960,6 @@ cumulative, minified: minify$1(matrix) ?? [serialized], }; - // valid identity matrix - if ((result.minified.length == 1 && - result.minified[0].typ == exports.EnumToken.IdenTokenType && - result.minified[0].val == "none") || - (result.cumulative.length == 1 && - result.cumulative[0].typ == exports.EnumToken.IdenTokenType && - result.cumulative[0].val == "none") || - (result.matrix?.typ == exports.EnumToken.IdenTokenType && result.matrix.val == "none")) { - // all transform function arguments must be 0 or scale(1) - for (const transform of transformLists) { - switch (transform.val) { - case "translate": - case "translateX": - case "translateY": - case "translateZ": - case "translate3d": - case "rotate": - case "rotateX": - case "rotateY": - case "rotateZ": - case "rotate3d": - case "skew": - case "skewX": - case "skewY": - for (const child of transform.chi) { - if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != exports.EnumToken.AngleTokenType && - child.typ != exports.EnumToken.NumberTokenType && - child.typ != exports.EnumToken.PercentageTokenType) || - getNumber(child) != 0) { - return null; - } - } - break; - case "scale": - case "scaleX": - case "scaleY": - case "scaleZ": - case "scale3d": - for (const child of transform.chi) { - if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) || - getNumber(child) != 1) { - return null; - } - } - break; - } - } - } return result; } function computeMatrix(transformList, matrixVar) { @@ -21184,7 +21287,7 @@ minified: null, }; if (matrix == null || cumulative == null || minified == null) { - node.val = children; + node.val = children.map((t) => t.typ == exports.EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t); continue; } let r = [filterValues(children)]; @@ -21868,7 +21971,15 @@ // trim :is() if (curr[0] == "&") { if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) { - curr.splice(0, 2); + const all = new Array(Math.max(curr.length - 2, 0)); + let write = 0; + for (let read = 2; read < curr.length; read++) { + all[write++] = curr[read]; + } + curr.length = 0; + for (let index = 0; index < write; index++) { + curr[index] = all[index]; + } } } acc.push(curr.join("")); @@ -22146,19 +22257,40 @@ if (optimized.length > 1) { const check = optimized.at(-2); if (!combinators.includes(check)) { - let last = optimized.pop(); + const last = optimized[optimized.length - 1]; + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } wrap = false; rule = optimized.join("") + `:is(${selector .map((s) => { + const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1); + let write = 0; if (s[0] == "&") { - s.splice(0, 1, last); + next[write++] = last; + for (let read = 1; read < s.length; read++) { + next[write++] = s[read]; + } } else { - s.unshift(last); + next[write++] = last; + for (let read = 0; read < s.length; read++) { + next[write++] = s[read]; + } + } + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = next[index]; } - return s.join(""); + return rebuilt.join(""); }) .join(",")})`; } @@ -22167,7 +22299,20 @@ rule = selector .map((s) => { if (s[0] == "&") { - s.splice(0, 1, ...node[OPTIMIZED].optimized); + const replacement = node[OPTIMIZED].optimized; + const all = new Array(Math.max(s.length - 1 + replacement.length, 0)); + let write = 0; + for (let read = 0; read < replacement.length; read++) { + all[write++] = replacement[read]; + } + for (let read = 1; read < s.length; read++) { + all[write++] = s[read]; + } + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = all[index]; + } + return rebuilt.join(""); } return s.join(""); }) @@ -22399,18 +22544,42 @@ while (optimized.length > 0) { const last = optimized.at(-1); if (last == " " || combinators.includes(last)) { - optimized.pop(); + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } continue; } break; } for (let i1 = 0; i1 < selector.length; i1++) { - selector[i1].splice(0, optimized.length); + const all = new Array(Math.max(selector[i1].length - optimized.length, 0)); + let write = 0; + for (let read = optimized.length; read < selector[i1].length; read++) { + all[write++] = selector[i1][read]; + } + selector[i1].length = 0; + for (let index = 0; index < write; index++) { + selector[i1][index] = all[index]; + } } let reducible = optimized.length == 1; if (optimized[0] == "&") { if (optimized[1] == " ") { - optimized.splice(0, 2); + const all = new Array(Math.max(optimized.length - 2, 0)); + let write = 0; + for (let read = 2; read < optimized.length; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } } } if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) { @@ -22997,7 +23166,15 @@ if (selector.length > 1 && selector[0] == "&" && (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) { - selector.shift(); + const all = new Array(Math.max(selector.length - 1, 0)); + let write = 0; + for (let read = 1; read < selector.length; read++) { + all[write++] = selector[read]; + } + selector.length = 0; + for (let index = 0; index < write; index++) { + selector[index] = all[index]; + } } } const unique = new Set(); @@ -23368,9 +23545,9 @@ * @returns */ function encode(value) { - if (typeof value === 'number') { - return encode_integer(value); - } + // if (typeof value === 'number') { + // return encode_integer(value); + // } let result = ''; for (let i = 0; i < value.length; i += 1) { result += encode_integer(value[i]); @@ -23723,7 +23900,7 @@ * match url */ const matchUrl = /^(https?:)?\/\//; - const windowsPathnameRegexp = /^\/?[a-zA-Z]:\/?/; + const windowsPathnameRegexp = /^\/?[a-zA-Z]:/; /** * return the directory name of a path * @param path @@ -24534,8 +24711,8 @@ return token.val; } if (Array.isArray(token.chi)) { - const fnName = token.val.toLowerCase(); - const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase()); + const fnName = token.val; + const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val); const hasAlpha = [ "rgb", "rgba", @@ -25713,7 +25890,7 @@ * @param parseInfo * @returns */ - consumeURLToken(parseInfo) { + consumeStringAsURLToken(parseInfo) { const quote = this.advance(parseInfo).charCodeAt(0); let charCode; let decodeSegments = false; @@ -26155,7 +26332,7 @@ } return 0; } - parseURLToken(parseInfo, endPosition) { + consumeURLToken(parseInfo, endPosition) { let charCode; // consume an while (isWhiteSpace(this.peekCharCode(parseInfo))) { @@ -26163,7 +26340,7 @@ } charCode = this.peekCharCode(parseInfo); if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) { - return this.consumeURLToken(parseInfo); + return this.consumeStringAsURLToken(parseInfo); } do { this.advance(parseInfo); @@ -26427,27 +26604,24 @@ * @param end * @returns */ - isIdentToken(parseInfo, start, end) { + isIdentToken(parseInfo /* , start?: number, end?: number */) { let j = parseInfo.currentPosition - parseInfo.offset; let i = parseInfo.position - parseInfo.offset; - if (start != null) { - if (end == null) { - if (start < 0) { - j += start; - } - else { - i += start; - } - } - else { - if (end < 0) { - j += end; - } - else { - j = parseInfo.position + end; - } - } - } + // if (start != null) { + // if (end == null) { + // if (start < 0) { + // j += start; + // } else { + // i += start; + // } + // } else { + // if (end < 0) { + // j += end; + // } else { + // j = parseInfo.position + end; + // } + // } + // } j--; let codepoint = parseInfo.stream.charCodeAt(i); // - @@ -26490,18 +26664,18 @@ * @param parseInfo * @returns */ - isPseudo(parseInfo) { - let position = parseInfo.currentPosition - parseInfo.offset; - let endPosition = parseInfo.currentPosition - parseInfo.offset; - return (parseInfo.stream.charAt(position) == ":" && - parseInfo.stream.charAt(endPosition - 1) == "(" && - (parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2, -1) - : this.isIdentToken(parseInfo, 1, -1))) || - parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2) - : this.isIdentToken(parseInfo, 1); - } + // isPseudo(parseInfo: ParseInfo): boolean { + // let position: number = parseInfo.currentPosition - parseInfo.offset; + // let endPosition: number = parseInfo.currentPosition - parseInfo.offset; + // return (parseInfo.stream.charAt(position) == ":" && + // parseInfo.stream.charAt(endPosition - 1) == "(" && + // (parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2, -1) + // : this.isIdentToken(parseInfo, 1, -1))) || + // parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2) + // : this.isIdentToken(parseInfo, 1); + // } /** * * @param parseInfo @@ -26574,7 +26748,7 @@ while ((charCode = this.peekCharCode(parseInfo)) == charCode) { if (this.state === exports.EnumToken.UrlFunctionTokenDefType) { this.state = null; - return this.parseURLToken(parseInfo, endPosition); + return this.consumeURLToken(parseInfo, endPosition); } if (parseInfo.position == parseInfo.currentPosition) { if (charCode == 45 /* TokenMap.MINUS */ || @@ -26694,12 +26868,14 @@ // '(' case 40 /* TokenMap.LEFT_PARENTHESIS */: if (parseInfo.position < parseInfo.currentPosition) { - if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && - this.isPseudo(parseInfo)) { - this.advance(parseInfo); - return this.makeToken(parseInfo, exports.EnumToken.PseudoClassFunctionTokenDefType); - } - else if (this.isIdentToken(parseInfo)) { + // if ( + // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && + // this.isPseudo(parseInfo) + // ) { + // this.advance(parseInfo); + // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType); + // } else + if (this.isIdentToken(parseInfo)) { const hint = this.startsWith(parseInfo, "--") ? exports.EnumToken.CustomFunctionTokenDefType : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? exports.EnumToken.FunctionTokenDefType); @@ -27062,7 +27238,6 @@ const stack = []; const uniq = new Map(); let allowed = true; - let i = 0; let index; let parent = context; let nested = false; @@ -27096,119 +27271,130 @@ nested = parent?.typ == exports.EnumToken.RuleNodeType; parent = parent?.[PARENT]; } while (!nested && parent != null); - for (; i < tokens.length; i++) { - if (tokens[i].typ == exports.EnumToken.ColonTokenType) { - if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + const all = new Array(tokens.length); + let write = 0; + for (let read = 0; read < tokens.length; read++) { + let token = tokens[read]; + if (token.typ == exports.EnumToken.ColonTokenType) { + const next = tokens[read + 1]; + if (next?.typ == exports.EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: exports.EnumToken.PseudoElementTokenType, - val: ":" + tokens[i + 1].val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + val: ":" + next.val, + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) { - val = ":" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == exports.EnumToken.FunctionTokenDefType) { + val = ":" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? exports.EnumToken.PseudoClassFunctionTokenDefType - : tokens[i + 1].typ, + : next.typ, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == exports.EnumToken.DoubleColonTokenType) { - val = ":" + tokens[i + 1].val; - if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + if (token.typ == exports.EnumToken.DoubleColonTokenType) { + const next = tokens[read + 1]; + val = ":" + next.val; + if (next?.typ == exports.EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: exports.EnumToken.PseudoClassTokenType, val: (pseudoElements.includes(val) ? "" : ":") + val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) { - val = "::" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == exports.EnumToken.FunctionTokenDefType) { + val = "::" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? exports.EnumToken.PseudoClassFunctionTokenDefType : exports.EnumToken.FunctionTokenDefType, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == exports.EnumToken.ColorTokenType) { - if (isHash(tokens[i].val)) { - Object.assign(tokens[i], { - typ: exports.EnumToken.HashTokenType, - }); + if (token.typ == exports.EnumToken.ColorTokenType) { + if (isHash(token.val)) { + token.typ = exports.EnumToken.HashTokenType; + all[write++] = token; + continue; } - else { - return { - typ: exports.EnumToken.RuleNodeType, - sel: [ - ...tokens - .reduce((acc, curr, index, array) => { - // if (curr.typ == EnumToken.CommentTokenType) { - // return acc; - // } - if (curr.typ == exports.EnumToken.WhitespaceTokenType) { - if (trimWhiteSpace.includes(array[index - 1]?.typ) || - trimWhiteSpace.includes(array[index + 1]?.typ) || - combinators.includes(array[index - 1]?.val) || - combinators.includes(array[index + 1]?.val)) { - return acc; - } - } - let t = renderValue(curr, { minify: false }); - if (t == ",") { - acc.push([]); - } - else { - acc[acc.length - 1].push(t); + return { + typ: exports.EnumToken.RuleNodeType, + sel: [ + ...tokens + .reduce((acc, curr, index, array) => { + if (curr.typ == exports.EnumToken.WhitespaceTokenType) { + if (trimWhiteSpace.includes(array[index - 1]?.typ) || + trimWhiteSpace.includes(array[index + 1]?.typ) || + combinators.includes(array[index - 1]?.val) || + combinators.includes(array[index + 1]?.val)) { + return acc; } - return acc; - }, [[]]) - .reduce((acc, curr) => { - let i = 0; - for (; i < curr.length; i++) { - if (i + 1 < curr.length && curr[i] == "*") { - if (curr[i] == "*") { - let index = curr[i + 1] == " " ? 2 : 1; - if (![">", "~", "+"].includes(curr[index])) { - curr.splice(i, index); - } + } + let t = renderValue(curr, { minify: false }); + if (t == ",") { + acc.push([]); + } + else { + acc[acc.length - 1].push(t); + } + return acc; + }, [[]]) + .reduce((acc, curr) => { + let i = 0; + for (; i < curr.length; i++) { + if (i + 1 < curr.length && curr[i] == "*") { + if (curr[i] == "*") { + let index = curr[i + 1] == " " ? 2 : 1; + if (![">", "~", "+"].includes(curr[index])) { + curr.splice(i, index); } } } - acc.set(curr.join(""), curr); - return acc; - }, uniq) - .keys(), - ].join(","), - chi: [], - [LOCSRCID]: tokens[0][LOCSRCID], - [LOCSTA]: tokens[0][LOCSTA], - [LOCEND]: tokens[tokens.length - 1][LOCEND], - [TOKENS]: tokens, - [STATE]: exports.EnumAstNodeStatus.Invalid, - [ERRORS]: [ - { - action: "drop", - node: tokens[i], - message: "invalid hash id", - }, - ], - }; - } + } + acc.set(curr.join(""), curr); + return acc; + }, uniq) + .keys(), + ].join(","), + chi: [], + [LOCSRCID]: tokens[0][LOCSRCID], + [LOCSTA]: tokens[0][LOCSTA], + [LOCEND]: tokens[tokens.length - 1][LOCEND], + [TOKENS]: tokens, + [STATE]: exports.EnumAstNodeStatus.Invalid, + [ERRORS]: [ + { + action: "drop", + node: token, + message: "invalid hash id", + }, + ], + }; } + all[write++] = token; + } + if (write !== tokens.length) { + for (let index = 0; index < write; index++) { + tokens[index] = all[index]; + } + tokens.length = write; } const result = matchSelectorSyntax(tokens, errors, options, nested === true); trimArray(tokens); @@ -27527,7 +27713,6 @@ * @param errors */ function parseDeclaration(tokens, parent, options, errors) { - // console.error(tokens); const name = tokens.shift(); let i; let rules = null; @@ -27861,10 +28046,19 @@ } if (trimTokenSpace$1.has(token.typ)) { if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); + for (let index = i + 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; + continue; } if (tokens[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) { - tokens.splice(--i, 1); + for (let index = i - 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; } } } @@ -32606,17 +32800,18 @@ * console.log(declarations); * ``` */ - async function parseDeclarations(declaration) { + function parseDeclarations(declaration) { const stream = `.x{${declaration}}`; - return doParse(new Tokenizer({ + const result = doParseSync(new Tokenizer({ stream, offset: 0, position: 0, source: new SourceFile(stream, [], ""), currentPosition: 0, - }), { setParent: false, minify: false, validation: false }).then((result) => { - return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType); - }); + }), { setParent: false, minify: false, validation: false }); + // .then((result) => { + return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType); + // }); } /** * Parse css string and return an array of tokens diff --git a/dist/index.cjs b/dist/index.cjs index a651d369..bf8cddab 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -2572,7 +2572,7 @@ var declarations = { syntax: "none | nearest" }, "scroll-margin": { - syntax: "{1,4}" + syntax: " {1,4}" }, "scroll-margin-block": { syntax: "{1,2}" @@ -2584,7 +2584,7 @@ var declarations = { syntax: "" }, "scroll-margin-bottom": { - syntax: "" + syntax: " auto | " }, "scroll-margin-inline": { syntax: "{1,2}" @@ -2596,13 +2596,13 @@ var declarations = { syntax: "" }, "scroll-margin-left": { - syntax: "" + syntax: " auto | " }, "scroll-margin-right": { - syntax: "" + syntax: " auto | " }, "scroll-margin-top": { - syntax: "" + syntax: " auto | " }, "scroll-marker-group": { syntax: "none | before | after" @@ -2671,13 +2671,13 @@ var declarations = { syntax: "none | auto" }, "scroll-timeline": { - syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" + syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" }, "scroll-timeline-axis": { - syntax: "[ block | inline | x | y ]#" + syntax: " [ block | inline | x | y ]#" }, "scroll-timeline-name": { - syntax: "[ none | ]#" + syntax: " [ none | ]#" }, "scrollbar-color": { syntax: "auto | {2}" @@ -3170,6 +3170,9 @@ var functions = { acos: { syntax: "acos( )" }, + alpha: { + syntax: "alpha( from / [ | none ] )" + }, anchor: { syntax: "anchor( ? && , ? )" }, @@ -7954,10 +7957,11 @@ function cmyk2srgbvalues(token) { t = components[3]; // @ts-ignore const k = getNumber(t); + const mul = 1 - k; const rgb = [ - 1 - Math.min(1, c * (1 - k) + k), - 1 - Math.min(1, m * (1 - k) + k), - 1 - Math.min(1, y * (1 - k) + k), + 1 - Math.min(1, c * mul + k), + 1 - Math.min(1, m * mul + k), + 1 - Math.min(1, y * mul + k), ]; if (components.length == 5) { rgb.push(getNumber(components[4])); @@ -10265,7 +10269,9 @@ function evaluateFunc(token) { } const value = evaluate(values); // @ts-ignore - let val = value[0].typ == exports.EnumToken.NumberTokenType || value[0].typ == exports.EnumToken.AngleTokenType + let val = value[0].typ == exports.EnumToken.NumberTokenType || + value[0].typ == exports.EnumToken.AngleTokenType || + value[0].typ == exports.EnumToken.PercentageTokenType ? +value[0].val : // @ts-expect-error value[0].l.val / value[0].r.val; @@ -10280,7 +10286,7 @@ function evaluateFunc(token) { [LOCEND]: value[0][LOCEND], } : { - typ: exports.EnumToken.NumberTokenType, + typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ, val: Math[token.val](val), [LOCSRCID]: value[0][LOCSRCID], [LOCSTA]: value[0][LOCSTA], @@ -10310,10 +10316,23 @@ function evaluateFunc(token) { }, ]; } + case "mod": case "atan2": case "pow": - case "rem": - case "mod": { + case "rem": { + { + let typ = token.chi[0]?.typ; + for (let i = 1; i < token.chi.length; i++) { + if (token.chi[i].typ == exports.EnumToken.WhitespaceTokenType || + token.chi[i].typ == exports.EnumToken.CommaTokenType || + token.chi[i].typ == exports.EnumToken.CommentTokenType) { + continue; + } + if (token.chi[i].typ != typ) { + return null; + } + } + } const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)); if (token.val == "atan2") { for (let i = 0; i < chi.length; i++) { @@ -10934,9 +10953,10 @@ function color2cmykToken(token) { } function srgb2cmykvalues(r, g, b, a = null) { const k = 1 - Math.max(r, g, b); - const c = k == 1 ? 0 : (1 - r - k) / (1 - k); - const m = k == 1 ? 0 : (1 - g - k) / (1 - k); - const y = k == 1 ? 0 : (1 - b - k) / (1 - k); + const div = 1 - k; + const c = k == 1 ? 0 : (1 - r - k) / div; + const m = k == 1 ? 0 : (1 - g - k) / div; + const y = k == 1 ? 0 : (1 - b - k) / div; const result = [c, m, y, k]; if (a != null && a < 1) { result.push(a); @@ -11750,9 +11770,13 @@ function parseSyntax(syntax) { stack.pop(); } } - if (stack.length > 0) { - throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`); - } + // if (stack.length > 0) { + // throw new SyntaxError( + // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${ + // stack.at(-1)?.[LOC]?.lin + // }:${stack.at(-1)?.[LOC]?.col}`, + // ); + // } return trimSyntaxArray(tokens); } @@ -17215,6 +17239,65 @@ var properties = { "padding-left": { shorthand: "padding" }, + "scroll-margin": { + shorthand: "scroll-margin", + properties: [ + "scroll-margin-top", + "scroll-margin-right", + "scroll-margin-bottom", + "scroll-margin-left" + ], + types: [ + "Length", + "Perc" + ], + "default": [ + "0" + ], + keywords: [ + "auto" + ] + }, + "scroll-margin-top": { + shorthand: "scroll-margin" + }, + "scroll-margin-right": { + shorthand: "scroll-margin" + }, + "scroll-margin-bottom": { + shorthand: "scroll-margin" + }, + "scroll-margin-left": { + shorthand: "scroll-margin" + }, + "scroll-padding": { + shorthand: "scroll-padding", + properties: [ + "scroll-padding-top", + "scroll-padding-right", + "scroll-padding-bottom", + "scroll-padding-left" + ], + types: [ + "Length", + "Perc" + ], + keywords: [ + "auto" + ] + }, + "scroll-padding-top": { + shorthand: "scroll-padding" + }, + "scroll-padding-right": { + shorthand: "scroll-padding" + }, + "scroll-padding-bottom": { + shorthand: "scroll-padding" + }, + "scroll-padding-left": { + shorthand: "scroll-padding" + }, "border-radius": { shorthand: "border-radius", properties: [ @@ -17436,6 +17519,53 @@ var map = { "flex-wrap": { shorthand: "flex-flow" }, + "scroll-timeline": { + shorthand: "scroll-timeline", + pattern: "scroll-timeline-name scroll-timeline-axis", + keywords: [ + "none", + "block", + "inline", + "x", + "y" + ], + "default": [ + "none", + "block" + ], + properties: { + "scroll-timeline-name": { + keywords: [ + "none" + ], + "default": [ + "none" + ], + types: [ + "DashedIden" + ] + }, + "scroll-timeline-axis": { + keywords: [ + "block", + "inline", + "x", + "y" + ], + "default": [ + "block" + ], + types: [ + ] + } + } + }, + "scroll-timeline-name": { + shorthand: "scroll-timeline" + }, + "scroll-timeline-axis": { + shorthand: "scroll-timeline" + }, container: { shorthand: "container", pattern: "container-name container-type", @@ -20640,7 +20770,7 @@ function eqMatrix(a, b) { return true; } function minifyTransformFunctions(transform) { - const name = transform.val.toLowerCase(); + const name = transform.val; if ("skewX" == name) { transform.val = "skew"; return transform; @@ -20775,9 +20905,36 @@ function compute(transformLists) { let matrix = identity(); let mat; let transforms; + let shouldComputeMatrix = true; const cumulative = []; + // all transform function arguments must be 0 or scale(1) + for (const transform of transformLists) { + switch (transform.val) { + case "rotate": + case "rotateX": + case "rotateY": + case "rotateZ": + case "rotate3d": + for (const child of transform.chi) { + if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { + continue; + } + if ((child.typ != exports.EnumToken.AngleTokenType && + child.typ != exports.EnumToken.NumberTokenType && + child.typ != exports.EnumToken.PercentageTokenType) || + // angle >= 360deg, do not transform + Math.abs(getAngle(child)) >= 1) { + shouldComputeMatrix = false; + } + } + break; + } + if (!shouldComputeMatrix) { + break; + } + } for (const transformList of splitTransformList(transformLists)) { - mat = computeMatrix(transformList, identity()); + mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null; if (mat == null) { return null; } @@ -20806,60 +20963,6 @@ function compute(transformLists) { cumulative, minified: minify$1(matrix) ?? [serialized], }; - // valid identity matrix - if ((result.minified.length == 1 && - result.minified[0].typ == exports.EnumToken.IdenTokenType && - result.minified[0].val == "none") || - (result.cumulative.length == 1 && - result.cumulative[0].typ == exports.EnumToken.IdenTokenType && - result.cumulative[0].val == "none") || - (result.matrix?.typ == exports.EnumToken.IdenTokenType && result.matrix.val == "none")) { - // all transform function arguments must be 0 or scale(1) - for (const transform of transformLists) { - switch (transform.val) { - case "translate": - case "translateX": - case "translateY": - case "translateZ": - case "translate3d": - case "rotate": - case "rotateX": - case "rotateY": - case "rotateZ": - case "rotate3d": - case "skew": - case "skewX": - case "skewY": - for (const child of transform.chi) { - if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != exports.EnumToken.AngleTokenType && - child.typ != exports.EnumToken.NumberTokenType && - child.typ != exports.EnumToken.PercentageTokenType) || - getNumber(child) != 0) { - return null; - } - } - break; - case "scale": - case "scaleX": - case "scaleY": - case "scaleZ": - case "scale3d": - for (const child of transform.chi) { - if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) || - getNumber(child) != 1) { - return null; - } - } - break; - } - } - } return result; } function computeMatrix(transformList, matrixVar) { @@ -21187,7 +21290,7 @@ class TransformCssFeature { minified: null, }; if (matrix == null || cumulative == null || minified == null) { - node.val = children; + node.val = children.map((t) => t.typ == exports.EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t); continue; } let r = [filterValues(children)]; @@ -21871,7 +21974,15 @@ function reduce(acc, curr) { // trim :is() if (curr[0] == "&") { if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) { - curr.splice(0, 2); + const all = new Array(Math.max(curr.length - 2, 0)); + let write = 0; + for (let read = 2; read < curr.length; read++) { + all[write++] = curr[read]; + } + curr.length = 0; + for (let index = 0; index < write; index++) { + curr[index] = all[index]; + } } } acc.push(curr.join("")); @@ -22149,19 +22260,40 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent, if (optimized.length > 1) { const check = optimized.at(-2); if (!combinators.includes(check)) { - let last = optimized.pop(); + const last = optimized[optimized.length - 1]; + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } wrap = false; rule = optimized.join("") + `:is(${selector .map((s) => { + const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1); + let write = 0; if (s[0] == "&") { - s.splice(0, 1, last); + next[write++] = last; + for (let read = 1; read < s.length; read++) { + next[write++] = s[read]; + } } else { - s.unshift(last); + next[write++] = last; + for (let read = 0; read < s.length; read++) { + next[write++] = s[read]; + } + } + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = next[index]; } - return s.join(""); + return rebuilt.join(""); }) .join(",")})`; } @@ -22170,7 +22302,20 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent, rule = selector .map((s) => { if (s[0] == "&") { - s.splice(0, 1, ...node[OPTIMIZED].optimized); + const replacement = node[OPTIMIZED].optimized; + const all = new Array(Math.max(s.length - 1 + replacement.length, 0)); + let write = 0; + for (let read = 0; read < replacement.length; read++) { + all[write++] = replacement[read]; + } + for (let read = 1; read < s.length; read++) { + all[write++] = s[read]; + } + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = all[index]; + } + return rebuilt.join(""); } return s.join(""); }) @@ -22402,18 +22547,42 @@ function optimizeSelector(selector) { while (optimized.length > 0) { const last = optimized.at(-1); if (last == " " || combinators.includes(last)) { - optimized.pop(); + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } continue; } break; } for (let i1 = 0; i1 < selector.length; i1++) { - selector[i1].splice(0, optimized.length); + const all = new Array(Math.max(selector[i1].length - optimized.length, 0)); + let write = 0; + for (let read = optimized.length; read < selector[i1].length; read++) { + all[write++] = selector[i1][read]; + } + selector[i1].length = 0; + for (let index = 0; index < write; index++) { + selector[i1][index] = all[index]; + } } let reducible = optimized.length == 1; if (optimized[0] == "&") { if (optimized[1] == " ") { - optimized.splice(0, 2); + const all = new Array(Math.max(optimized.length - 2, 0)); + let write = 0; + for (let read = 2; read < optimized.length; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } } } if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) { @@ -23000,7 +23169,15 @@ function reduceRuleSelector(node) { if (selector.length > 1 && selector[0] == "&" && (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) { - selector.shift(); + const all = new Array(Math.max(selector.length - 1, 0)); + let write = 0; + for (let read = 1; read < selector.length; read++) { + all[write++] = selector[read]; + } + selector.length = 0; + for (let index = 0; index < write; index++) { + selector[index] = all[index]; + } } } const unique = new Set(); @@ -23371,9 +23548,9 @@ function decode(str) { * @returns */ function encode(value) { - if (typeof value === 'number') { - return encode_integer(value); - } + // if (typeof value === 'number') { + // return encode_integer(value); + // } let result = ''; for (let i = 0; i < value.length; i += 1) { result += encode_integer(value[i]); @@ -23726,7 +23903,7 @@ class LineMap { * match url */ const matchUrl = /^(https?:)?\/\//; -const windowsPathnameRegexp = /^\/?[a-zA-Z]:\/?/; +const windowsPathnameRegexp = /^\/?[a-zA-Z]:/; /** * return the directory name of a path * @param path @@ -24537,8 +24714,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, return token.val; } if (Array.isArray(token.chi)) { - const fnName = token.val.toLowerCase(); - const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase()); + const fnName = token.val; + const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val); const hasAlpha = [ "rgb", "rgba", @@ -25716,7 +25893,7 @@ class Tokenizer { * @param parseInfo * @returns */ - consumeURLToken(parseInfo) { + consumeStringAsURLToken(parseInfo) { const quote = this.advance(parseInfo).charCodeAt(0); let charCode; let decodeSegments = false; @@ -26158,7 +26335,7 @@ class Tokenizer { } return 0; } - parseURLToken(parseInfo, endPosition) { + consumeURLToken(parseInfo, endPosition) { let charCode; // consume an while (isWhiteSpace(this.peekCharCode(parseInfo))) { @@ -26166,7 +26343,7 @@ class Tokenizer { } charCode = this.peekCharCode(parseInfo); if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) { - return this.consumeURLToken(parseInfo); + return this.consumeStringAsURLToken(parseInfo); } do { this.advance(parseInfo); @@ -26430,27 +26607,24 @@ class Tokenizer { * @param end * @returns */ - isIdentToken(parseInfo, start, end) { + isIdentToken(parseInfo /* , start?: number, end?: number */) { let j = parseInfo.currentPosition - parseInfo.offset; let i = parseInfo.position - parseInfo.offset; - if (start != null) { - if (end == null) { - if (start < 0) { - j += start; - } - else { - i += start; - } - } - else { - if (end < 0) { - j += end; - } - else { - j = parseInfo.position + end; - } - } - } + // if (start != null) { + // if (end == null) { + // if (start < 0) { + // j += start; + // } else { + // i += start; + // } + // } else { + // if (end < 0) { + // j += end; + // } else { + // j = parseInfo.position + end; + // } + // } + // } j--; let codepoint = parseInfo.stream.charCodeAt(i); // - @@ -26493,18 +26667,18 @@ class Tokenizer { * @param parseInfo * @returns */ - isPseudo(parseInfo) { - let position = parseInfo.currentPosition - parseInfo.offset; - let endPosition = parseInfo.currentPosition - parseInfo.offset; - return (parseInfo.stream.charAt(position) == ":" && - parseInfo.stream.charAt(endPosition - 1) == "(" && - (parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2, -1) - : this.isIdentToken(parseInfo, 1, -1))) || - parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2) - : this.isIdentToken(parseInfo, 1); - } + // isPseudo(parseInfo: ParseInfo): boolean { + // let position: number = parseInfo.currentPosition - parseInfo.offset; + // let endPosition: number = parseInfo.currentPosition - parseInfo.offset; + // return (parseInfo.stream.charAt(position) == ":" && + // parseInfo.stream.charAt(endPosition - 1) == "(" && + // (parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2, -1) + // : this.isIdentToken(parseInfo, 1, -1))) || + // parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2) + // : this.isIdentToken(parseInfo, 1); + // } /** * * @param parseInfo @@ -26577,7 +26751,7 @@ class Tokenizer { while ((charCode = this.peekCharCode(parseInfo)) == charCode) { if (this.state === exports.EnumToken.UrlFunctionTokenDefType) { this.state = null; - return this.parseURLToken(parseInfo, endPosition); + return this.consumeURLToken(parseInfo, endPosition); } if (parseInfo.position == parseInfo.currentPosition) { if (charCode == 45 /* TokenMap.MINUS */ || @@ -26697,12 +26871,14 @@ class Tokenizer { // '(' case 40 /* TokenMap.LEFT_PARENTHESIS */: if (parseInfo.position < parseInfo.currentPosition) { - if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && - this.isPseudo(parseInfo)) { - this.advance(parseInfo); - return this.makeToken(parseInfo, exports.EnumToken.PseudoClassFunctionTokenDefType); - } - else if (this.isIdentToken(parseInfo)) { + // if ( + // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && + // this.isPseudo(parseInfo) + // ) { + // this.advance(parseInfo); + // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType); + // } else + if (this.isIdentToken(parseInfo)) { const hint = this.startsWith(parseInfo, "--") ? exports.EnumToken.CustomFunctionTokenDefType : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? exports.EnumToken.FunctionTokenDefType); @@ -27065,7 +27241,6 @@ function parseSelector(tokens, context, options, errors) { const stack = []; const uniq = new Map(); let allowed = true; - let i = 0; let index; let parent = context; let nested = false; @@ -27099,119 +27274,130 @@ function parseSelector(tokens, context, options, errors) { nested = parent?.typ == exports.EnumToken.RuleNodeType; parent = parent?.[PARENT]; } while (!nested && parent != null); - for (; i < tokens.length; i++) { - if (tokens[i].typ == exports.EnumToken.ColonTokenType) { - if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + const all = new Array(tokens.length); + let write = 0; + for (let read = 0; read < tokens.length; read++) { + let token = tokens[read]; + if (token.typ == exports.EnumToken.ColonTokenType) { + const next = tokens[read + 1]; + if (next?.typ == exports.EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: exports.EnumToken.PseudoElementTokenType, - val: ":" + tokens[i + 1].val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + val: ":" + next.val, + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) { - val = ":" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == exports.EnumToken.FunctionTokenDefType) { + val = ":" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? exports.EnumToken.PseudoClassFunctionTokenDefType - : tokens[i + 1].typ, + : next.typ, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == exports.EnumToken.DoubleColonTokenType) { - val = ":" + tokens[i + 1].val; - if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + if (token.typ == exports.EnumToken.DoubleColonTokenType) { + const next = tokens[read + 1]; + val = ":" + next.val; + if (next?.typ == exports.EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: exports.EnumToken.PseudoClassTokenType, val: (pseudoElements.includes(val) ? "" : ":") + val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) { - val = "::" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == exports.EnumToken.FunctionTokenDefType) { + val = "::" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? exports.EnumToken.PseudoClassFunctionTokenDefType : exports.EnumToken.FunctionTokenDefType, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == exports.EnumToken.ColorTokenType) { - if (isHash(tokens[i].val)) { - Object.assign(tokens[i], { - typ: exports.EnumToken.HashTokenType, - }); + if (token.typ == exports.EnumToken.ColorTokenType) { + if (isHash(token.val)) { + token.typ = exports.EnumToken.HashTokenType; + all[write++] = token; + continue; } - else { - return { - typ: exports.EnumToken.RuleNodeType, - sel: [ - ...tokens - .reduce((acc, curr, index, array) => { - // if (curr.typ == EnumToken.CommentTokenType) { - // return acc; - // } - if (curr.typ == exports.EnumToken.WhitespaceTokenType) { - if (trimWhiteSpace.includes(array[index - 1]?.typ) || - trimWhiteSpace.includes(array[index + 1]?.typ) || - combinators.includes(array[index - 1]?.val) || - combinators.includes(array[index + 1]?.val)) { - return acc; - } - } - let t = renderValue(curr, { minify: false }); - if (t == ",") { - acc.push([]); - } - else { - acc[acc.length - 1].push(t); + return { + typ: exports.EnumToken.RuleNodeType, + sel: [ + ...tokens + .reduce((acc, curr, index, array) => { + if (curr.typ == exports.EnumToken.WhitespaceTokenType) { + if (trimWhiteSpace.includes(array[index - 1]?.typ) || + trimWhiteSpace.includes(array[index + 1]?.typ) || + combinators.includes(array[index - 1]?.val) || + combinators.includes(array[index + 1]?.val)) { + return acc; } - return acc; - }, [[]]) - .reduce((acc, curr) => { - let i = 0; - for (; i < curr.length; i++) { - if (i + 1 < curr.length && curr[i] == "*") { - if (curr[i] == "*") { - let index = curr[i + 1] == " " ? 2 : 1; - if (![">", "~", "+"].includes(curr[index])) { - curr.splice(i, index); - } + } + let t = renderValue(curr, { minify: false }); + if (t == ",") { + acc.push([]); + } + else { + acc[acc.length - 1].push(t); + } + return acc; + }, [[]]) + .reduce((acc, curr) => { + let i = 0; + for (; i < curr.length; i++) { + if (i + 1 < curr.length && curr[i] == "*") { + if (curr[i] == "*") { + let index = curr[i + 1] == " " ? 2 : 1; + if (![">", "~", "+"].includes(curr[index])) { + curr.splice(i, index); } } } - acc.set(curr.join(""), curr); - return acc; - }, uniq) - .keys(), - ].join(","), - chi: [], - [LOCSRCID]: tokens[0][LOCSRCID], - [LOCSTA]: tokens[0][LOCSTA], - [LOCEND]: tokens[tokens.length - 1][LOCEND], - [TOKENS]: tokens, - [STATE]: exports.EnumAstNodeStatus.Invalid, - [ERRORS]: [ - { - action: "drop", - node: tokens[i], - message: "invalid hash id", - }, - ], - }; - } + } + acc.set(curr.join(""), curr); + return acc; + }, uniq) + .keys(), + ].join(","), + chi: [], + [LOCSRCID]: tokens[0][LOCSRCID], + [LOCSTA]: tokens[0][LOCSTA], + [LOCEND]: tokens[tokens.length - 1][LOCEND], + [TOKENS]: tokens, + [STATE]: exports.EnumAstNodeStatus.Invalid, + [ERRORS]: [ + { + action: "drop", + node: token, + message: "invalid hash id", + }, + ], + }; } + all[write++] = token; + } + if (write !== tokens.length) { + for (let index = 0; index < write; index++) { + tokens[index] = all[index]; + } + tokens.length = write; } const result = matchSelectorSyntax(tokens, errors, options, nested === true); trimArray(tokens); @@ -27530,7 +27716,6 @@ function parseGridTemplate(template) { * @param errors */ function parseDeclaration(tokens, parent, options, errors) { - // console.error(tokens); const name = tokens.shift(); let i; let rules = null; @@ -27864,10 +28049,19 @@ function parseDeclaration(tokens, parent, options, errors) { } if (trimTokenSpace$1.has(token.typ)) { if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); + for (let index = i + 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; + continue; } if (tokens[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) { - tokens.splice(--i, 1); + for (let index = i - 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; } } } @@ -32609,17 +32803,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { * console.log(declarations); * ``` */ -async function parseDeclarations(declaration) { +function parseDeclarations(declaration) { const stream = `.x{${declaration}}`; - return doParse(new Tokenizer({ + const result = doParseSync(new Tokenizer({ stream, offset: 0, position: 0, source: new SourceFile(stream, [], ""), currentPosition: 0, - }), { setParent: false, minify: false, validation: false }).then((result) => { - return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType); - }); + }), { setParent: false, minify: false, validation: false }); + // .then((result) => { + return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType); + // }); } /** * Parse css string and return an array of tokens diff --git a/dist/index.d.ts b/dist/index.d.ts index c505142f..191ad1a6 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -987,7 +987,7 @@ declare const OPTIMIZED: unique symbol; /** * Literal token */ -declare interface LiteralToken extends BaseToken { +export declare interface LiteralToken extends BaseToken { /** * @inheritdoc */ @@ -1001,7 +1001,7 @@ declare interface LiteralToken extends BaseToken { /** * Class selector token */ -declare interface ClassSelectorToken extends BaseToken { +export declare interface ClassSelectorToken extends BaseToken { /** * @inheritdoc */ @@ -1015,7 +1015,7 @@ declare interface ClassSelectorToken extends BaseToken { /** * Invalid class selector token */ -declare interface InvalidClassSelectorToken extends BaseToken { +export declare interface InvalidClassSelectorToken extends BaseToken { /** * @inheritdoc */ @@ -1029,7 +1029,7 @@ declare interface InvalidClassSelectorToken extends BaseToken { /** * Universal selector token */ -declare interface UniversalSelectorToken extends BaseToken { +export declare interface UniversalSelectorToken extends BaseToken { /** * @inheritdoc */ @@ -1039,7 +1039,7 @@ declare interface UniversalSelectorToken extends BaseToken { /** * Ident token */ -declare interface IdentToken extends BaseToken { +export declare interface IdentToken extends BaseToken { /** * @inheritdoc */ @@ -1053,7 +1053,7 @@ declare interface IdentToken extends BaseToken { /** * Ident list token */ -declare interface IdentListToken extends BaseToken { +export declare interface IdentListToken extends BaseToken { /** * @inheritdoc */ @@ -1067,7 +1067,7 @@ declare interface IdentListToken extends BaseToken { /** * Dashed ident token */ -declare interface DashedIdentToken extends BaseToken { +export declare interface DashedIdentToken extends BaseToken { /** * @inheritdoc */ @@ -1081,7 +1081,7 @@ declare interface DashedIdentToken extends BaseToken { /** * Comma token */ -declare interface CommaToken extends BaseToken { +export declare interface CommaToken extends BaseToken { /** * @inheritdoc */ @@ -1091,7 +1091,7 @@ declare interface CommaToken extends BaseToken { /** * Colon token */ -declare interface ColonToken extends BaseToken { +export declare interface ColonToken extends BaseToken { /** * @inheritdoc */ @@ -1101,7 +1101,7 @@ declare interface ColonToken extends BaseToken { /** * Double colon token */ -declare interface DoubleColonToken extends BaseToken { +export declare interface DoubleColonToken extends BaseToken { /** * @inheritdoc */ @@ -1111,7 +1111,7 @@ declare interface DoubleColonToken extends BaseToken { /** * Semicolon token */ -declare interface SemiColonToken extends BaseToken { +export declare interface SemiColonToken extends BaseToken { /** * @inheritdoc */ @@ -1121,7 +1121,7 @@ declare interface SemiColonToken extends BaseToken { /** * Nesting selector token */ -declare interface NestingSelectorToken extends BaseToken { +export declare interface NestingSelectorToken extends BaseToken { /** * @inheritdoc */ @@ -1131,7 +1131,7 @@ declare interface NestingSelectorToken extends BaseToken { /** * Number token */ -declare interface NumberToken extends BaseToken { +export declare interface NumberToken extends BaseToken { /** * @inheritdoc */ @@ -1149,7 +1149,7 @@ declare interface NumberToken extends BaseToken { /** * At rule token */ -declare interface AtRuleToken extends BaseToken { +export declare interface AtRuleToken extends BaseToken { /** * @inheritdoc */ @@ -1167,7 +1167,7 @@ declare interface AtRuleToken extends BaseToken { /** * Percentage token */ -declare interface PercentageToken extends BaseToken { +export declare interface PercentageToken extends BaseToken { /** * @inheritdoc */ @@ -1181,7 +1181,7 @@ declare interface PercentageToken extends BaseToken { /** * Flex token */ -declare interface FlexToken extends BaseToken { +export declare interface FlexToken extends BaseToken { /** * @inheritdoc */ @@ -1195,7 +1195,7 @@ declare interface FlexToken extends BaseToken { /** * Function token */ -declare interface FunctionToken extends BaseToken { +export declare interface FunctionToken extends BaseToken { /** * function type */ @@ -1225,7 +1225,7 @@ declare interface FunctionToken extends BaseToken { /** * Grid template function token */ -declare interface GridTemplateFuncToken extends BaseToken { +export declare interface GridTemplateFuncToken extends BaseToken { /** * @inheritdoc */ @@ -1243,7 +1243,7 @@ declare interface GridTemplateFuncToken extends BaseToken { /** * Function URL token */ -declare interface FunctionURLToken extends BaseToken { +export declare interface FunctionURLToken extends BaseToken { /** * @inheritdoc */ @@ -1261,7 +1261,7 @@ declare interface FunctionURLToken extends BaseToken { /** * Function image token */ -declare interface FunctionImageToken extends BaseToken { +export declare interface FunctionImageToken extends BaseToken { /** * @inheritdoc */ @@ -1288,7 +1288,7 @@ declare interface FunctionImageToken extends BaseToken { /** * Timing function token */ -declare interface TimingFunctionToken extends BaseToken { +export declare interface TimingFunctionToken extends BaseToken { /** * @inheritdoc */ @@ -1306,7 +1306,7 @@ declare interface TimingFunctionToken extends BaseToken { /** * Timeline function token */ -declare interface TimelineFunctionToken extends BaseToken { +export declare interface TimelineFunctionToken extends BaseToken { /** * @inheritdoc */ @@ -1324,7 +1324,7 @@ declare interface TimelineFunctionToken extends BaseToken { /** * String token */ -declare interface StringToken extends BaseToken { +export declare interface StringToken extends BaseToken { /** * @inheritdoc */ @@ -1338,7 +1338,7 @@ declare interface StringToken extends BaseToken { /** * Bad string token */ -declare interface BadStringToken extends BaseToken { +export declare interface BadStringToken extends BaseToken { /** * @inheritdoc */ @@ -1352,7 +1352,7 @@ declare interface BadStringToken extends BaseToken { /** * Unclosed string token */ -declare interface UnclosedStringToken extends BaseToken { +export declare interface UnclosedStringToken extends BaseToken { /** * @inheritdoc */ @@ -1366,7 +1366,7 @@ declare interface UnclosedStringToken extends BaseToken { /** * Dimension token */ -declare interface DimensionToken extends BaseToken { +export declare interface DimensionToken extends BaseToken { /** * @inheritdoc */ @@ -1384,7 +1384,7 @@ declare interface DimensionToken extends BaseToken { /** * Length token */ -declare interface LengthToken extends BaseToken { +export declare interface LengthToken extends BaseToken { /** * @inheritdoc */ @@ -1402,7 +1402,7 @@ declare interface LengthToken extends BaseToken { /** * Angle token */ -declare interface AngleToken extends BaseToken { +export declare interface AngleToken extends BaseToken { /** * @inheritdoc */ @@ -1420,7 +1420,7 @@ declare interface AngleToken extends BaseToken { /** * Time token */ -declare interface TimeToken extends BaseToken { +export declare interface TimeToken extends BaseToken { /** * @inheritdoc */ @@ -1438,7 +1438,7 @@ declare interface TimeToken extends BaseToken { /** * Frequency token */ -declare interface FrequencyToken extends BaseToken { +export declare interface FrequencyToken extends BaseToken { /** * @inheritdoc */ @@ -1456,7 +1456,7 @@ declare interface FrequencyToken extends BaseToken { /** * Resolution token */ -declare interface ResolutionToken extends BaseToken { +export declare interface ResolutionToken extends BaseToken { /** * @inheritdoc */ @@ -1474,7 +1474,7 @@ declare interface ResolutionToken extends BaseToken { /** * Hash token */ -declare interface HashToken extends BaseToken { +export declare interface HashToken extends BaseToken { /** * @inheritdoc */ @@ -1488,7 +1488,7 @@ declare interface HashToken extends BaseToken { /** * Block start token */ -declare interface BlockStartToken extends BaseToken { +export declare interface BlockStartToken extends BaseToken { /** * @inheritdoc */ @@ -1498,7 +1498,7 @@ declare interface BlockStartToken extends BaseToken { /** * Block end token */ -declare interface BlockEndToken extends BaseToken { +export declare interface BlockEndToken extends BaseToken { /** * @inheritdoc */ @@ -1508,7 +1508,7 @@ declare interface BlockEndToken extends BaseToken { /** * Attribute start token */ -declare interface AttrStartToken extends BaseToken { +export declare interface AttrStartToken extends BaseToken { /** * @inheritdoc */ @@ -1522,7 +1522,7 @@ declare interface AttrStartToken extends BaseToken { /** * Attribute end token */ -declare interface AttrEndToken extends BaseToken { +export declare interface AttrEndToken extends BaseToken { /** * @inheritdoc */ @@ -1532,7 +1532,7 @@ declare interface AttrEndToken extends BaseToken { /** * Parenthesis start token */ -declare interface ParensStartToken extends BaseToken { +export declare interface ParensStartToken extends BaseToken { /** * @inheritdoc */ @@ -1542,7 +1542,7 @@ declare interface ParensStartToken extends BaseToken { /** * Parenthesis end token */ -declare interface ParensEndToken extends BaseToken { +export declare interface ParensEndToken extends BaseToken { /** * @inheritdoc */ @@ -1552,7 +1552,7 @@ declare interface ParensEndToken extends BaseToken { /** * Parenthesis token */ -declare interface ParensToken extends BaseToken { +export declare interface ParensToken extends BaseToken { /** * @inheritdoc */ @@ -1566,7 +1566,7 @@ declare interface ParensToken extends BaseToken { /** * Whitespace token */ -declare interface WhitespaceToken extends BaseToken { +export declare interface WhitespaceToken extends BaseToken { /** * @inheritdoc */ @@ -1580,7 +1580,7 @@ declare interface WhitespaceToken extends BaseToken { /** * Comment token */ -declare interface CommentToken extends BaseToken { +export declare interface CommentToken extends BaseToken { /** * @inheritdoc */ @@ -1594,7 +1594,7 @@ declare interface CommentToken extends BaseToken { /** * Bad comment token */ -declare interface BadCommentToken extends BaseToken { +export declare interface BadCommentToken extends BaseToken { /** * @inheritdoc */ @@ -1608,7 +1608,7 @@ declare interface BadCommentToken extends BaseToken { /** * CDO comment token */ -declare interface CDOCommentToken extends BaseToken { +export declare interface CDOCommentToken extends BaseToken { /** * @inheritdoc */ @@ -1622,7 +1622,7 @@ declare interface CDOCommentToken extends BaseToken { /** * Bad CDO comment token */ -declare interface BadCDOCommentToken extends BaseToken { +export declare interface BadCDOCommentToken extends BaseToken { /** * @inheritdoc */ @@ -1636,7 +1636,7 @@ declare interface BadCDOCommentToken extends BaseToken { /** * Include match token */ -declare interface IncludeMatchToken extends BaseToken { +export declare interface IncludeMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1647,7 +1647,7 @@ declare interface IncludeMatchToken extends BaseToken { /** * Dash match token */ -declare interface DashMatchToken extends BaseToken { +export declare interface DashMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1658,7 +1658,7 @@ declare interface DashMatchToken extends BaseToken { /** * Equal match token */ -declare interface EqualMatchToken extends BaseToken { +export declare interface EqualMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1669,7 +1669,7 @@ declare interface EqualMatchToken extends BaseToken { /** * Start match token */ -declare interface StartMatchToken extends BaseToken { +export declare interface StartMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1680,7 +1680,7 @@ declare interface StartMatchToken extends BaseToken { /** * End match token */ -declare interface EndMatchToken extends BaseToken { +export declare interface EndMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1691,7 +1691,7 @@ declare interface EndMatchToken extends BaseToken { /** * Contain match token */ -declare interface ContainMatchToken extends BaseToken { +export declare interface ContainMatchToken extends BaseToken { /** * @inheritdoc */ @@ -1702,7 +1702,7 @@ declare interface ContainMatchToken extends BaseToken { /** * Less than token */ -declare interface LessThanToken extends BaseToken { +export declare interface LessThanToken extends BaseToken { /** * @inheritdoc */ @@ -1712,7 +1712,7 @@ declare interface LessThanToken extends BaseToken { /** * Less than or equal token */ -declare interface LessThanOrEqualToken extends BaseToken { +export declare interface LessThanOrEqualToken extends BaseToken { /** * @inheritdoc */ @@ -1722,7 +1722,7 @@ declare interface LessThanOrEqualToken extends BaseToken { /** * Greater than token */ -declare interface GreaterThanToken extends BaseToken { +export declare interface GreaterThanToken extends BaseToken { /** * @inheritdoc */ @@ -1732,7 +1732,7 @@ declare interface GreaterThanToken extends BaseToken { /** * Greater than or equal token */ -declare interface GreaterThanOrEqualToken extends BaseToken { +export declare interface GreaterThanOrEqualToken extends BaseToken { /** * @inheritdoc */ @@ -1742,7 +1742,7 @@ declare interface GreaterThanOrEqualToken extends BaseToken { /** * Column combinator token */ -declare interface ColumnCombinatorToken extends BaseToken { +export declare interface ColumnCombinatorToken extends BaseToken { /** * @inheritdoc */ @@ -1752,7 +1752,7 @@ declare interface ColumnCombinatorToken extends BaseToken { /** * Pseudo class token */ -declare interface PseudoClassToken extends BaseToken { +export declare interface PseudoClassToken extends BaseToken { /** * @inheritdoc */ @@ -1766,7 +1766,7 @@ declare interface PseudoClassToken extends BaseToken { /** * Pseudo element token */ -declare interface PseudoElementToken extends BaseToken { +export declare interface PseudoElementToken extends BaseToken { /** * @inheritdoc */ @@ -1780,7 +1780,7 @@ declare interface PseudoElementToken extends BaseToken { /** * Pseudo page token */ -declare interface PseudoPageToken extends BaseToken { +export declare interface PseudoPageToken extends BaseToken { /** * @inheritdoc */ @@ -1794,7 +1794,7 @@ declare interface PseudoPageToken extends BaseToken { /** * Pseudo class function token */ -declare interface PseudoClassFunctionToken extends BaseToken { +export declare interface PseudoClassFunctionToken extends BaseToken { /** * @inheritdoc */ @@ -1812,7 +1812,7 @@ declare interface PseudoClassFunctionToken extends BaseToken { /** * Delim token */ -declare interface DelimToken extends BaseToken { +export declare interface DelimToken extends BaseToken { /** * @inheritdoc */ @@ -1822,7 +1822,7 @@ declare interface DelimToken extends BaseToken { /** * Bad URL token */ -declare interface BadUrlToken extends BaseToken { +export declare interface BadUrlToken extends BaseToken { /** * @inheritdoc */ @@ -1836,7 +1836,7 @@ declare interface BadUrlToken extends BaseToken { /** * URL token */ -declare interface UrlToken extends BaseToken { +export declare interface UrlToken extends BaseToken { /** * @inheritdoc */ @@ -1850,7 +1850,7 @@ declare interface UrlToken extends BaseToken { /** * EOF token */ -declare interface EOFToken extends BaseToken { +export declare interface EOFToken extends BaseToken { /** * @inheritdoc */ @@ -1860,7 +1860,7 @@ declare interface EOFToken extends BaseToken { /** * Important token */ -declare interface ImportantToken extends BaseToken { +export declare interface ImportantToken extends BaseToken { /** * @inheritdoc */ @@ -1870,7 +1870,7 @@ declare interface ImportantToken extends BaseToken { /** * Color token */ -declare interface ColorToken extends BaseToken { +export declare interface ColorToken extends BaseToken { /** * @inheritdoc */ @@ -1896,7 +1896,7 @@ declare interface ColorToken extends BaseToken { /** * Attribute token */ -declare interface AttrToken extends BaseToken { +export declare interface AttrToken extends BaseToken { /** * @inheritdoc */ @@ -1910,7 +1910,7 @@ declare interface AttrToken extends BaseToken { /** * Invalid attribute token */ -declare interface InvalidAttrToken extends BaseToken { +export declare interface InvalidAttrToken extends BaseToken { /** * @inheritdoc */ @@ -1924,7 +1924,7 @@ declare interface InvalidAttrToken extends BaseToken { /** * Child combinator token */ -declare interface ChildCombinatorToken extends BaseToken { +export declare interface ChildCombinatorToken extends BaseToken { /** * @inheritdoc */ @@ -1934,7 +1934,7 @@ declare interface ChildCombinatorToken extends BaseToken { /** * Media feature token */ -declare interface MediaFeatureToken extends BaseToken { +export declare interface MediaFeatureToken extends BaseToken { /** * @inheritdoc */ @@ -1948,7 +1948,7 @@ declare interface MediaFeatureToken extends BaseToken { /** * Media feature not token */ -declare interface NotToken extends BaseToken { +export declare interface NotToken extends BaseToken { /** * @inheritdoc */ @@ -1962,7 +1962,7 @@ declare interface NotToken extends BaseToken { /** * Media feature only token */ -declare interface MediaFeatureOnlyToken extends BaseToken { +export declare interface MediaFeatureOnlyToken extends BaseToken { /** * @inheritdoc */ @@ -1976,7 +1976,7 @@ declare interface MediaFeatureOnlyToken extends BaseToken { /** * Media feature and token */ -declare interface AndToken extends BaseToken { +export declare interface AndToken extends BaseToken { /** * @inheritdoc */ @@ -1986,7 +1986,7 @@ declare interface AndToken extends BaseToken { /** * Media feature or token */ -declare interface OrToken extends BaseToken { +export declare interface OrToken extends BaseToken { /** * @inheritdoc */ @@ -1996,7 +1996,7 @@ declare interface OrToken extends BaseToken { /** * Media query condition token */ -declare interface MediaQueryUnaryFeatureToken extends BaseToken { +export declare interface MediaQueryUnaryFeatureToken extends BaseToken { /** * @inheritdoc */ @@ -2011,7 +2011,7 @@ declare interface MediaQueryUnaryFeatureToken extends BaseToken { r: Token$1[]; } -declare interface SupportsQueryUnaryConditionToken extends BaseToken { +export declare interface SupportsQueryUnaryConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2026,7 +2026,7 @@ declare interface SupportsQueryUnaryConditionToken extends BaseToken { r: Token$1[]; } -declare interface SupportsQueryConditionToken extends BaseToken { +export declare interface SupportsQueryConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2045,7 +2045,7 @@ declare interface SupportsQueryConditionToken extends BaseToken { r: Token$1[]; } -declare interface WhenElseQueryConditionToken extends BaseToken { +export declare interface WhenElseQueryConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2064,7 +2064,7 @@ declare interface WhenElseQueryConditionToken extends BaseToken { r: Token$1[]; } -declare interface WhenElseUnaryConditionToken extends BaseToken { +export declare interface WhenElseUnaryConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2079,7 +2079,7 @@ declare interface WhenElseUnaryConditionToken extends BaseToken { r: Token$1[]; } -declare interface MediaQueryConditionToken extends BaseToken { +export declare interface MediaQueryConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2106,7 +2106,7 @@ declare interface MediaQueryConditionToken extends BaseToken { r: Token$1[]; } -declare interface IfConditionToken extends BaseToken { +export declare interface IfConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2121,7 +2121,7 @@ declare interface IfConditionToken extends BaseToken { r: Token$1[]; } -declare interface IfElseConditionToken extends BaseToken { +export declare interface IfElseConditionToken extends BaseToken { /** * @inheritdoc */ @@ -2136,7 +2136,7 @@ declare interface IfElseConditionToken extends BaseToken { r: IfConditionToken; } -declare interface ContainerStyleRangeToken extends BaseToken { +export declare interface ContainerStyleRangeToken extends BaseToken { /** * @inheritdoc */ @@ -2159,7 +2159,7 @@ declare interface ContainerStyleRangeToken extends BaseToken { /** * @inheritdoc */ -declare interface MediaRangeQueryToken extends BaseToken { +export declare interface MediaRangeQueryToken extends BaseToken { /** * @inheritdoc */ @@ -2189,7 +2189,7 @@ declare interface MediaRangeQueryToken extends BaseToken { /** * @inheritdoc */ -declare interface InvalidMediaQueryToken extends BaseToken { +export declare interface InvalidMediaQueryToken extends BaseToken { /** * @inheritdoc */ @@ -2204,7 +2204,7 @@ declare interface InvalidMediaQueryToken extends BaseToken { /** * Descendant combinator token */ -declare interface DescendantCombinatorToken extends BaseToken { +export declare interface DescendantCombinatorToken extends BaseToken { /** * @inheritdoc */ @@ -2214,7 +2214,7 @@ declare interface DescendantCombinatorToken extends BaseToken { /** * Next sibling combinator token */ -declare interface NextSiblingCombinatorToken extends BaseToken { +export declare interface NextSiblingCombinatorToken extends BaseToken { /** * @inheritdoc */ @@ -2224,7 +2224,7 @@ declare interface NextSiblingCombinatorToken extends BaseToken { /** * Subsequent sibling combinator token */ -declare interface SubsequentCombinatorToken extends BaseToken { +export declare interface SubsequentCombinatorToken extends BaseToken { /** * @inheritdoc */ @@ -2234,7 +2234,7 @@ declare interface SubsequentCombinatorToken extends BaseToken { /** * Add token */ -declare interface AddToken extends BaseToken { +export declare interface AddToken extends BaseToken { /** * @inheritdoc */ @@ -2244,7 +2244,7 @@ declare interface AddToken extends BaseToken { /** * Sub token */ -declare interface SubToken extends BaseToken { +export declare interface SubToken extends BaseToken { /** * @inheritdoc */ @@ -2254,7 +2254,7 @@ declare interface SubToken extends BaseToken { /** * Div token */ -declare interface DivToken extends BaseToken { +export declare interface DivToken extends BaseToken { /** * @inheritdoc */ @@ -2264,7 +2264,7 @@ declare interface DivToken extends BaseToken { /** * Mul token */ -declare interface MulToken extends BaseToken { +export declare interface MulToken extends BaseToken { /** * @inheritdoc */ @@ -2274,7 +2274,7 @@ declare interface MulToken extends BaseToken { /** * Wrapped values token like {Arial, Helvetica, sans-serif} */ -declare interface WrappedValuesToken extends BaseToken { +export declare interface WrappedValuesToken extends BaseToken { /** * @inheritdoc */ @@ -2288,7 +2288,7 @@ declare interface WrappedValuesToken extends BaseToken { /** * Unary expression token */ -declare interface UnaryExpression extends BaseToken { +export declare interface UnaryExpression extends BaseToken { /** * @inheritdoc */ @@ -2306,7 +2306,7 @@ declare interface UnaryExpression extends BaseToken { /** * Fraction token */ -declare interface FractionToken extends BaseToken { +export declare interface FractionToken extends BaseToken { /** * @inheritdoc */ @@ -2324,7 +2324,7 @@ declare interface FractionToken extends BaseToken { /** * Binary expression token */ -declare interface BinaryExpressionToken extends BaseToken { +export declare interface BinaryExpressionToken extends BaseToken { /** * @inheritdoc */ @@ -2346,7 +2346,7 @@ declare interface BinaryExpressionToken extends BaseToken { /** * Match expression token */ -declare interface MatchExpressionToken extends BaseToken { +export declare interface MatchExpressionToken extends BaseToken { /** * @inheritdoc */ @@ -2372,7 +2372,7 @@ declare interface MatchExpressionToken extends BaseToken { /** * Name space attribute token */ -declare interface NameSpaceAttributeToken extends BaseToken { +export declare interface NameSpaceAttributeToken extends BaseToken { /** * @inheritdoc */ @@ -2390,7 +2390,7 @@ declare interface NameSpaceAttributeToken extends BaseToken { /** * List token */ -declare interface ListToken extends BaseToken { +export declare interface ListToken extends BaseToken { /** * @inheritdoc */ @@ -2404,7 +2404,7 @@ declare interface ListToken extends BaseToken { /** * Composes selector token */ -declare interface ComposesSelectorToken extends BaseToken { +export declare interface ComposesSelectorToken extends BaseToken { /** * @inheritdoc */ @@ -2422,7 +2422,7 @@ declare interface ComposesSelectorToken extends BaseToken { /** * Css variable token */ -declare interface CssVariableToken extends BaseToken { +export declare interface CssVariableToken extends BaseToken { /** * @inheritdoc */ @@ -2440,7 +2440,7 @@ declare interface CssVariableToken extends BaseToken { /** * Css variable import token */ -declare interface CssVariableImportTokenType extends BaseToken { +export declare interface CssVariableImportTokenType extends BaseToken { /** * @inheritdoc */ @@ -2458,7 +2458,7 @@ declare interface CssVariableImportTokenType extends BaseToken { /** * Css variable map token */ -declare interface CssVariableMapTokenType extends BaseToken { +export declare interface CssVariableMapTokenType extends BaseToken { /** * @inheritdoc */ @@ -2476,7 +2476,7 @@ declare interface CssVariableMapTokenType extends BaseToken { /** * Function definition token */ -declare interface FunctionDefToken extends BaseToken { +export declare interface FunctionDefToken extends BaseToken { /** * @inheritdoc */ @@ -2504,7 +2504,7 @@ declare interface FunctionDefToken extends BaseToken { /** * Raw node token */ -declare interface RawNodeToken extends BaseToken, EnumAstNodeStatus$1 { +export declare interface RawNodeToken extends BaseToken, EnumAstNodeStatus$1 { /** * @inheritdoc */ @@ -2518,7 +2518,7 @@ declare interface RawNodeToken extends BaseToken, EnumAstNodeStatus$1 { /** * Unary expression node */ -declare type UnaryExpressionNode = +export declare type UnaryExpressionNode = | BinaryExpressionNode | NumberToken | DimensionToken @@ -2530,7 +2530,7 @@ declare type UnaryExpressionNode = /** * Binary expression node */ -declare type BinaryExpressionNode = +export declare type BinaryExpressionNode = | NumberToken | DimensionToken | PercentageToken @@ -2546,7 +2546,7 @@ declare type BinaryExpressionNode = /** * Token */ -declare type Token$1 = +export declare type Token$1 = | InvalidClassSelectorToken | InvalidAttrToken | LiteralToken @@ -2654,7 +2654,7 @@ declare type Token$1 = /** * token or node location */ -declare interface SourceLocation { +export declare interface SourceLocation { /** * start position */ @@ -2672,7 +2672,7 @@ declare interface SourceLocation { /** * Common token interface */ -declare interface BaseToken { +export declare interface BaseToken { /** * token type */ @@ -2745,7 +2745,7 @@ declare interface BaseToken { /** * Ast node state */ -declare interface AstNodeStatus { +export declare interface AstNodeStatus { /** * Node state */ @@ -2759,7 +2759,7 @@ declare interface AstNodeStatus { /** * comment node */ -declare interface AstComment extends BaseToken { +export declare interface AstComment extends BaseToken { /** * token type */ @@ -2773,7 +2773,7 @@ declare interface AstComment extends BaseToken { /** * declaration node */ -declare interface AstDeclaration extends BaseToken, AstNodeStatus { +export declare interface AstDeclaration extends BaseToken, AstNodeStatus { /** * token name */ @@ -2791,7 +2791,7 @@ declare interface AstDeclaration extends BaseToken, AstNodeStatus { /** * rule node */ -declare interface AstRule extends BaseToken, AstNodeStatus { +export declare interface AstRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -2820,7 +2820,7 @@ declare interface AstRule extends BaseToken, AstNodeStatus { * Invalid rule node * @deprecated */ -declare interface AstInvalidRule extends BaseToken, AstNodeStatus { +export declare interface AstInvalidRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -2839,7 +2839,7 @@ declare interface AstInvalidRule extends BaseToken, AstNodeStatus { * invalid declaration node * @deprecated */ -declare interface AstInvalidDeclaration extends BaseToken, AstNodeStatus { +export declare interface AstInvalidDeclaration extends BaseToken, AstNodeStatus { /** * token type */ @@ -2858,7 +2858,7 @@ declare interface AstInvalidDeclaration extends BaseToken, AstNodeStatus { * invalid at rule node * @deprecated */ -declare interface AstInvalidAtRule extends BaseToken, AstNodeStatus { +export declare interface AstInvalidAtRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -2880,14 +2880,14 @@ declare interface AstInvalidAtRule extends BaseToken, AstNodeStatus { /** * raw selector tokens */ -declare type RawSelectorTokens = string[][]; +export declare type RawSelectorTokens = string[][]; /** * optimized selector * * @private */ -declare interface OptimizedSelector { +export declare interface OptimizedSelector { /** * matched selector */ @@ -2911,7 +2911,7 @@ declare interface OptimizedSelector { * * @private */ -declare interface OptimizedSelectorToken { +export declare interface OptimizedSelectorToken { /** * match */ @@ -2933,7 +2933,7 @@ declare interface OptimizedSelectorToken { /** * at rule node */ -declare interface AstAtRule extends BaseToken, AstNodeStatus { +export declare interface AstAtRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -2955,7 +2955,7 @@ declare interface AstAtRule extends BaseToken, AstNodeStatus { /** * keyframe rule node */ -declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { +export declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -2985,7 +2985,7 @@ declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { /** * keyframe rule node */ -declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { +export declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -3011,7 +3011,7 @@ declare interface AstKeyframesRule extends BaseToken, AstNodeStatus { /** * keyframe at rule node */ -declare interface AstKeyframesAtRule extends BaseToken, AstNodeStatus { +export declare interface AstKeyframesAtRule extends BaseToken, AstNodeStatus { /** * token type */ @@ -3033,7 +3033,7 @@ declare interface AstKeyframesAtRule extends BaseToken, AstNodeStatus { /** * rule list node */ -declare type AstRuleList = +export declare type AstRuleList = | AstStyleSheet | AstAtRule | AstRule @@ -3044,7 +3044,7 @@ declare type AstRuleList = /** * stylesheet node */ -declare interface AstStyleSheet extends BaseToken { +export declare interface AstStyleSheet extends BaseToken { /** * token type */ @@ -3058,7 +3058,7 @@ declare interface AstStyleSheet extends BaseToken { /** * ast node */ -declare type AstNode$1 = +export declare type AstNode$1 = | AstStyleSheet | AstRuleList | AstComment @@ -3338,20 +3338,20 @@ declare function walkValues(values: Token$1[], root?: AstNode$1 | Token$1 | null /** * Generic visitor result */ -declare type GenericVisitorSyncResult = T | T[] | null; +export declare type GenericVisitorSyncResult = T | T[] | null; /** * Generic visitor result */ -declare type GenericVisitorAsyncResult = Promise | Promise | Promise; +export declare type GenericVisitorAsyncResult = Promise | Promise | Promise; /** * Generic visitor result */ -declare type GenericVisitorResult = GenericVisitorSyncResult | GenericVisitorAsyncResult; +export declare type GenericVisitorResult = GenericVisitorSyncResult | GenericVisitorAsyncResult; /** * Generic visitor handler */ -declare type GenericVisitorSyncHandler = ( +export declare type GenericVisitorSyncHandler = ( node: T, parent?: AstNode | Token, root?: AstNode | Token, @@ -3360,7 +3360,7 @@ declare type GenericVisitorSyncHandler = ( /** * Generic visitor handler */ -declare type GenericVisitorAstNodeSyncHandlerMap = +export declare type GenericVisitorAstNodeSyncHandlerMap = | Record> | GenericVisitorSyncHandler | { type: WalkerEvent; handler: GenericVisitorSyncHandler } @@ -3369,13 +3369,13 @@ declare type GenericVisitorAstNodeSyncHandlerMap = /** * Generic visitor handler */ -declare type ValueVisitorSyncHandler = GenericVisitorSyncHandler; +export declare type ValueVisitorSyncHandler = GenericVisitorSyncHandler; /** * node visitor callback map * */ -declare interface VisitorSyncNodeMap { +export declare interface VisitorSyncNodeMap { /** * at rule visitor * @@ -3634,7 +3634,7 @@ declare interface VisitorSyncNodeMap { /** * Generic visitor handler */ -declare type GenericVisitorHandler = ( +export declare type GenericVisitorHandler = ( node: T, parent?: AstNode | Token, root?: AstNode | Token, @@ -3643,7 +3643,7 @@ declare type GenericVisitorHandler = ( /** * Generic visitor handler */ -declare type GenericVisitorAstNodeHandlerMap = +export declare type GenericVisitorAstNodeHandlerMap = | Record> | GenericVisitorHandler | { type: WalkerEvent; handler: GenericVisitorHandler } @@ -3652,41 +3652,41 @@ declare type GenericVisitorAstNodeHandlerMap = /** * Generic visitor handler */ -declare type ValueVisitorHandler = GenericVisitorHandler; +export declare type ValueVisitorHandler = GenericVisitorHandler; /** * Declaration visitor handler */ -declare type DeclarationVisitorHandler = GenericVisitorHandler; +export declare type DeclarationVisitorHandler = GenericVisitorHandler; /** * Declaration visitor handler */ -declare type DeclarationVisitorHandler = GenericVisitorHandler; +export declare type DeclarationVisitorHandler = GenericVisitorHandler; /** * Rule visitor handler */ -declare type RuleVisitorHandler = GenericVisitorHandler; +export declare type RuleVisitorHandler = GenericVisitorHandler; /** * Rule visitor handler */ -declare type RuleVisitorHandler = GenericVisitorHandler; +export declare type RuleVisitorHandler = GenericVisitorHandler; /** * AtRule visitor handler */ -declare type AtRuleVisitorHandler = GenericVisitorHandler; +export declare type AtRuleVisitorHandler = GenericVisitorHandler; /** * AtRule visitor handler */ -declare type AtRuleVisitorHandler = GenericVisitorHandler; +export declare type AtRuleVisitorHandler = GenericVisitorHandler; /** * node visitor callback map * */ -declare interface VisitorNodeMap { +export declare interface VisitorNodeMap { /** * at rule visitor * @@ -4147,7 +4147,7 @@ declare class SourceFile { getInputSourceMap(): SourceMap | null; } -declare interface PropertyListOptions { +export declare interface PropertyListOptions { removeDuplicateDeclarations?: boolean | string | string[]; computeShorthand?: boolean; } @@ -4155,7 +4155,7 @@ declare interface PropertyListOptions { /** * parse info */ -declare interface ParseInfo$1 { +export declare interface ParseInfo$1 { /** * stream */ @@ -4531,7 +4531,7 @@ interface ShorthandType { /** * @private */ -declare interface PropertiesConfig { +export declare interface PropertiesConfig { /** * shorthand property minification rules */ @@ -4940,7 +4940,7 @@ interface BorderRadius { /** * node walker options */ -declare interface WalkerOptions { +export declare interface WalkerOptions { /** * walk in reverse */ @@ -4959,7 +4959,7 @@ declare interface WalkerOptions { /** * node walker option */ -declare type WalkerOption = WalkerOptionEnum | AstNode$1 | Token$1 | null; +export declare type WalkerOption = WalkerOptionEnum | AstNode$1 | Token$1 | null; /** * returned value: * - {@link WalkerOptionEnum.Ignore}: ignore this node and its children @@ -4969,7 +4969,7 @@ declare type WalkerOption = WalkerOptionEnum | AstNode$1 | Token$1 | null; * - {@link AstNode}: * - {@link Token}: */ -declare type WalkerFilter = (node: AstNode$1) => WalkerOption; +export declare type WalkerFilter = (node: AstNode$1) => WalkerOption; /** * returned value: @@ -4980,7 +4980,7 @@ declare type WalkerFilter = (node: AstNode$1) => WalkerOption; * - {@link AstNode}: * - {@link Token}: */ -declare type WalkerValueFilter = ( +export declare type WalkerValueFilter = ( node: AstNode$1 | Token$1, parent?: AstNode$1 | Token$1 | AstNode$1[] | Token$1[] | null, event?: WalkerEvent, @@ -4990,7 +4990,7 @@ declare type WalkerValueFilter = ( /** * walker result */ -declare interface WalkResult { +export declare interface WalkResult { /** * current node */ @@ -5012,7 +5012,7 @@ declare interface WalkResult { /** * walker result */ -declare interface WalkAttributesResult { +export declare interface WalkAttributesResult { /** * current node */ @@ -5042,7 +5042,7 @@ declare interface WalkAttributesResult { /** * Error description */ -declare interface ErrorDescription$1 { +export declare interface ErrorDescription$1 { /** * Drop rule or declaration */ @@ -5220,7 +5220,7 @@ interface MinifyOptions { /** * Result of options.load() function call. */ -declare type LoadResult = +export declare type LoadResult = | Promise> | ReadableStream | string @@ -5229,7 +5229,7 @@ declare type LoadResult = /** * CSS module parser options */ -declare interface ModuleSyncOptions { +export declare interface ModuleSyncOptions { /** * Use local scope vs global scope */ @@ -5339,7 +5339,7 @@ declare interface ModuleSyncOptions { generateScopedName?: (localName: string, filePath: string, pattern: string, hashLength?: number) => string; } -declare interface ModuleAsyncOptions extends ModuleSyncOptions { +export declare interface ModuleAsyncOptions extends ModuleSyncOptions { /** * The pattern used to generate scoped names. the supported placeholders are: * - name: the file base name without the extension @@ -5434,7 +5434,7 @@ declare interface ModuleAsyncOptions extends ModuleSyncOptions { /** * Input file options */ -declare interface ParseInputFileOptions { +export declare interface ParseInputFileOptions { /** * File path or url */ @@ -5449,7 +5449,7 @@ declare interface ParseInputFileOptions { /** * Input options for string or stream */ -declare interface ParseInputOptions { +export declare interface ParseInputOptions { /** * Input string or stream */ @@ -5458,7 +5458,7 @@ declare interface ParseInputOptions { /** * Input options for string or stream */ -declare interface ParseInputStreamOptions { +export declare interface ParseInputStreamOptions { /** * Input string or stream */ @@ -5469,7 +5469,7 @@ declare interface ParseInputStreamOptions { * Input options for string or stream * @internal */ -declare interface ParseSourceOptions { +export declare interface ParseSourceOptions { /** * Source file to be used for sourcemap * @internal @@ -5485,7 +5485,7 @@ declare interface ParseSourceOptions { /** * Parser sourcemap options */ -declare interface ParserSourceMapOptions { +export declare interface ParserSourceMapOptions { /** * Include sourcemap in the ast. Sourcemap info is always generated */ @@ -5499,7 +5499,7 @@ declare interface ParserSourceMapOptions { /** * Sync parseroptions */ -declare interface ParserSyncOptions +export declare interface ParserSyncOptions extends MinifyOptions, ParserSourceMapOptions, @@ -5610,7 +5610,7 @@ declare interface ParserSyncOptions /** * Parser options */ -declare interface ParserOptions extends ParserSyncOptions, ModuleAsyncOptions { +export declare interface ParserOptions extends ParserSyncOptions, ModuleAsyncOptions { /** * Resolve import */ @@ -5645,7 +5645,7 @@ declare interface ParserOptions extends ParserSyncOptions, ModuleAsyncOptions { * * @internal */ -declare interface MinifyFeatureOptions { +export declare interface MinifyFeatureOptions { /** * Minify features * @@ -5659,7 +5659,7 @@ declare interface MinifyFeatureOptions { * * @internal */ -declare interface MinifyFeature { +export declare interface MinifyFeature { /** * Accepted tokens */ @@ -5701,7 +5701,7 @@ declare interface MinifyFeature { * Resolved path * @internal */ -declare interface ResolvedPath { +export declare interface ResolvedPath { /** * Absolute path */ @@ -5715,7 +5715,7 @@ declare interface ResolvedPath { /** * Ast node render options */ -declare interface RenderOptions { +export declare interface RenderOptions { /** * Source file to be used as CSS input file for sourcemap resolution */ @@ -5807,17 +5807,17 @@ declare interface RenderOptions { /** * Transform options */ -declare interface TransformSyncOptions extends ParserSyncOptions, RenderOptions {} +export declare interface TransformSyncOptions extends ParserSyncOptions, RenderOptions {} /** * Transform options */ -declare interface TransformOptions extends ParserOptions, RenderOptions {} +export declare interface TransformOptions extends ParserOptions, RenderOptions {} /** * Parse result stats object */ -declare interface ParseResultStats { +export declare interface ParseResultStats { /** * Source file */ @@ -5871,7 +5871,7 @@ declare interface ParseResultStats { /** * Parse result object */ -declare interface ParseResult { +export declare interface ParseResult { /** * Parsed ast tree */ @@ -5912,7 +5912,7 @@ declare interface ParseResult { /** * Render result object */ -declare interface RenderResult { +export declare interface RenderResult { /** * Rendered CSS */ @@ -5939,7 +5939,7 @@ declare interface RenderResult { /** * Transform result object */ -declare interface TransformResult extends ParseResult, RenderResult { +export declare interface TransformResult extends ParseResult, RenderResult { /** * Transform stats */ @@ -5986,13 +5986,13 @@ declare interface TransformResult extends ParseResult, RenderResult { /** * Parse token options */ -declare interface ParseTokenOptions extends ParserOptions {} +export declare interface ParseTokenOptions extends ParserOptions {} /** * Tokenize result object * @internal */ -declare interface TokenizeResult { +export declare interface TokenizeResult { /** * Token */ @@ -6007,7 +6007,7 @@ declare interface TokenizeResult { * Matched selector object * @internal */ -declare interface MatchedSelector { +export declare interface MatchedSelector { /** * Matched selector */ @@ -6030,7 +6030,7 @@ declare interface MatchedSelector { * Variable scope info object * @internal */ -declare interface VariableScopeInfo { +export declare interface VariableScopeInfo { /** * Global scope */ @@ -6061,7 +6061,7 @@ declare interface VariableScopeInfo { * Source map object * @internal */ -declare interface SourceMapObject { +export declare interface SourceMapObject { /** * Source map version */ @@ -6116,7 +6116,7 @@ declare const resolve: (url: string, currentDirectory?: string, cwd?: string) => * Validation syntax * @internal */ -declare interface ValidationSyntaxNode { +export declare interface ValidationSyntaxNode { /** * mdn data syntax */ @@ -6146,7 +6146,7 @@ interface ValidationSelectorOptions extends ValidationOptions { * Validation media feature * @internal */ -declare interface ValidationMediaFeature { +export declare interface ValidationMediaFeature { /** * media feature type */ @@ -6169,7 +6169,7 @@ declare interface ValidationMediaFeature { * Validation configuration * @internal */ -declare type ValidationConfiguration = Record< +export declare type ValidationConfiguration = Record< ValidationSyntaxGroupEnum, ValidationSyntaxNode | Record | Record >; @@ -6247,7 +6247,7 @@ declare function expand(ast: AstStyleSheet | AstAtRule | AstRule): AstNode$1; * console.log(declarations); * ``` */ -declare function parseDeclarations(declaration: string): Promise>; +declare function parseDeclarations(declaration: string): Array; /** * Parse css string and return an array of tokens * @param src diff --git a/dist/lib/ast/features/transform.js b/dist/lib/ast/features/transform.js index d528102a..4a29abe9 100644 --- a/dist/lib/ast/features/transform.js +++ b/dist/lib/ast/features/transform.js @@ -53,7 +53,7 @@ class TransformCssFeature { minified: null, }; if (matrix == null || cumulative == null || minified == null) { - node.val = children; + node.val = children.map((t) => t.typ == EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t); continue; } let r = [filterValues(children)]; diff --git a/dist/lib/ast/math/expression.js b/dist/lib/ast/math/expression.js index 5c0bab0a..b8cb919e 100644 --- a/dist/lib/ast/math/expression.js +++ b/dist/lib/ast/math/expression.js @@ -293,7 +293,9 @@ function evaluateFunc(token) { } const value = evaluate(values); // @ts-ignore - let val = value[0].typ == EnumToken.NumberTokenType || value[0].typ == EnumToken.AngleTokenType + let val = value[0].typ == EnumToken.NumberTokenType || + value[0].typ == EnumToken.AngleTokenType || + value[0].typ == EnumToken.PercentageTokenType ? +value[0].val : // @ts-expect-error value[0].l.val / value[0].r.val; @@ -308,7 +310,7 @@ function evaluateFunc(token) { [LOCEND]: value[0][LOCEND], } : { - typ: EnumToken.NumberTokenType, + typ: token.val == "sign" ? EnumToken.NumberTokenType : value[0].typ, val: Math[token.val](val), [LOCSRCID]: value[0][LOCSRCID], [LOCSTA]: value[0][LOCSTA], @@ -338,10 +340,23 @@ function evaluateFunc(token) { }, ]; } + case "mod": case "atan2": case "pow": - case "rem": - case "mod": { + case "rem": { + { + let typ = token.chi[0]?.typ; + for (let i = 1; i < token.chi.length; i++) { + if (token.chi[i].typ == EnumToken.WhitespaceTokenType || + token.chi[i].typ == EnumToken.CommaTokenType || + token.chi[i].typ == EnumToken.CommentTokenType) { + continue; + } + if (token.chi[i].typ != typ) { + return null; + } + } + } const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ)); if (token.val == "atan2") { for (let i = 0; i < chi.length; i++) { diff --git a/dist/lib/ast/minify.js b/dist/lib/ast/minify.js index 3004ef6b..7efb87d0 100644 --- a/dist/lib/ast/minify.js +++ b/dist/lib/ast/minify.js @@ -307,7 +307,15 @@ function reduce(acc, curr) { // trim :is() if (curr[0] == "&") { if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) { - curr.splice(0, 2); + const all = new Array(Math.max(curr.length - 2, 0)); + let write = 0; + for (let read = 2; read < curr.length; read++) { + all[write++] = curr[read]; + } + curr.length = 0; + for (let index = 0; index < write; index++) { + curr[index] = all[index]; + } } } acc.push(curr.join("")); @@ -585,19 +593,40 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent, if (optimized.length > 1) { const check = optimized.at(-2); if (!combinators.includes(check)) { - let last = optimized.pop(); + const last = optimized[optimized.length - 1]; + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } wrap = false; rule = optimized.join("") + `:is(${selector .map((s) => { + const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1); + let write = 0; if (s[0] == "&") { - s.splice(0, 1, last); + next[write++] = last; + for (let read = 1; read < s.length; read++) { + next[write++] = s[read]; + } } else { - s.unshift(last); + next[write++] = last; + for (let read = 0; read < s.length; read++) { + next[write++] = s[read]; + } } - return s.join(""); + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = next[index]; + } + return rebuilt.join(""); }) .join(",")})`; } @@ -606,7 +635,20 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent, rule = selector .map((s) => { if (s[0] == "&") { - s.splice(0, 1, ...node[OPTIMIZED].optimized); + const replacement = node[OPTIMIZED].optimized; + const all = new Array(Math.max(s.length - 1 + replacement.length, 0)); + let write = 0; + for (let read = 0; read < replacement.length; read++) { + all[write++] = replacement[read]; + } + for (let read = 1; read < s.length; read++) { + all[write++] = s[read]; + } + const rebuilt = new Array(write); + for (let index = 0; index < write; index++) { + rebuilt[index] = all[index]; + } + return rebuilt.join(""); } return s.join(""); }) @@ -838,18 +880,42 @@ function optimizeSelector(selector) { while (optimized.length > 0) { const last = optimized.at(-1); if (last == " " || combinators.includes(last)) { - optimized.pop(); + const all = new Array(Math.max(optimized.length - 1, 0)); + let write = 0; + for (let read = 0; read < optimized.length - 1; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } continue; } break; } for (let i1 = 0; i1 < selector.length; i1++) { - selector[i1].splice(0, optimized.length); + const all = new Array(Math.max(selector[i1].length - optimized.length, 0)); + let write = 0; + for (let read = optimized.length; read < selector[i1].length; read++) { + all[write++] = selector[i1][read]; + } + selector[i1].length = 0; + for (let index = 0; index < write; index++) { + selector[i1][index] = all[index]; + } } let reducible = optimized.length == 1; if (optimized[0] == "&") { if (optimized[1] == " ") { - optimized.splice(0, 2); + const all = new Array(Math.max(optimized.length - 2, 0)); + let write = 0; + for (let read = 2; read < optimized.length; read++) { + all[write++] = optimized[read]; + } + optimized.length = 0; + for (let index = 0; index < write; index++) { + optimized[index] = all[index]; + } } } if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) { @@ -1436,7 +1502,15 @@ function reduceRuleSelector(node) { if (selector.length > 1 && selector[0] == "&" && (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) { - selector.shift(); + const all = new Array(Math.max(selector.length - 1, 0)); + let write = 0; + for (let read = 1; read < selector.length; read++) { + all[write++] = selector[read]; + } + selector.length = 0; + for (let index = 0; index < write; index++) { + selector[index] = all[index]; + } } } const unique = new Set(); diff --git a/dist/lib/ast/transform/compute.js b/dist/lib/ast/transform/compute.js index ddd93996..9ce03edf 100644 --- a/dist/lib/ast/transform/compute.js +++ b/dist/lib/ast/transform/compute.js @@ -18,9 +18,36 @@ function compute(transformLists) { let matrix = identity(); let mat; let transforms; + let shouldComputeMatrix = true; const cumulative = []; + // all transform function arguments must be 0 or scale(1) + for (const transform of transformLists) { + switch (transform.val) { + case "rotate": + case "rotateX": + case "rotateY": + case "rotateZ": + case "rotate3d": + for (const child of transform.chi) { + if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) { + continue; + } + if ((child.typ != EnumToken.AngleTokenType && + child.typ != EnumToken.NumberTokenType && + child.typ != EnumToken.PercentageTokenType) || + // angle >= 360deg, do not transform + Math.abs(getAngle(child)) >= 1) { + shouldComputeMatrix = false; + } + } + break; + } + if (!shouldComputeMatrix) { + break; + } + } for (const transformList of splitTransformList(transformLists)) { - mat = computeMatrix(transformList, identity()); + mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null; if (mat == null) { return null; } @@ -49,60 +76,6 @@ function compute(transformLists) { cumulative, minified: minify(matrix) ?? [serialized], }; - // valid identity matrix - if ((result.minified.length == 1 && - result.minified[0].typ == EnumToken.IdenTokenType && - result.minified[0].val == "none") || - (result.cumulative.length == 1 && - result.cumulative[0].typ == EnumToken.IdenTokenType && - result.cumulative[0].val == "none") || - (result.matrix?.typ == EnumToken.IdenTokenType && result.matrix.val == "none")) { - // all transform function arguments must be 0 or scale(1) - for (const transform of transformLists) { - switch (transform.val) { - case "translate": - case "translateX": - case "translateY": - case "translateZ": - case "translate3d": - case "rotate": - case "rotateX": - case "rotateY": - case "rotateZ": - case "rotate3d": - case "skew": - case "skewX": - case "skewY": - for (const child of transform.chi) { - if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != EnumToken.AngleTokenType && - child.typ != EnumToken.NumberTokenType && - child.typ != EnumToken.PercentageTokenType) || - getNumber(child) != 0) { - return null; - } - } - break; - case "scale": - case "scaleX": - case "scaleY": - case "scaleZ": - case "scale3d": - for (const child of transform.chi) { - if (child.typ == EnumToken.WhitespaceTokenType || child.typ == EnumToken.CommaTokenType) { - continue; - } - if ((child.typ != EnumToken.NumberTokenType && child.typ != EnumToken.PercentageTokenType) || - getNumber(child) != 1) { - return null; - } - } - break; - } - } - } return result; } function computeMatrix(transformList, matrixVar) { diff --git a/dist/lib/ast/transform/minify.js b/dist/lib/ast/transform/minify.js index b1113e22..a66fcde2 100644 --- a/dist/lib/ast/transform/minify.js +++ b/dist/lib/ast/transform/minify.js @@ -266,7 +266,7 @@ function eqMatrix(a, b) { return true; } function minifyTransformFunctions(transform) { - const name = transform.val.toLowerCase(); + const name = transform.val; if ("skewX" == name) { transform.val = "skew"; return transform; diff --git a/dist/config.json.js b/dist/lib/data/properties.json.js similarity index 93% rename from dist/config.json.js rename to dist/lib/data/properties.json.js index 12c7300d..732ea4dd 100644 --- a/dist/config.json.js +++ b/dist/lib/data/properties.json.js @@ -108,6 +108,65 @@ var properties = { "padding-left": { shorthand: "padding" }, + "scroll-margin": { + shorthand: "scroll-margin", + properties: [ + "scroll-margin-top", + "scroll-margin-right", + "scroll-margin-bottom", + "scroll-margin-left" + ], + types: [ + "Length", + "Perc" + ], + "default": [ + "0" + ], + keywords: [ + "auto" + ] + }, + "scroll-margin-top": { + shorthand: "scroll-margin" + }, + "scroll-margin-right": { + shorthand: "scroll-margin" + }, + "scroll-margin-bottom": { + shorthand: "scroll-margin" + }, + "scroll-margin-left": { + shorthand: "scroll-margin" + }, + "scroll-padding": { + shorthand: "scroll-padding", + properties: [ + "scroll-padding-top", + "scroll-padding-right", + "scroll-padding-bottom", + "scroll-padding-left" + ], + types: [ + "Length", + "Perc" + ], + keywords: [ + "auto" + ] + }, + "scroll-padding-top": { + shorthand: "scroll-padding" + }, + "scroll-padding-right": { + shorthand: "scroll-padding" + }, + "scroll-padding-bottom": { + shorthand: "scroll-padding" + }, + "scroll-padding-left": { + shorthand: "scroll-padding" + }, "border-radius": { shorthand: "border-radius", properties: [ @@ -329,6 +388,53 @@ var map = { "flex-wrap": { shorthand: "flex-flow" }, + "scroll-timeline": { + shorthand: "scroll-timeline", + pattern: "scroll-timeline-name scroll-timeline-axis", + keywords: [ + "none", + "block", + "inline", + "x", + "y" + ], + "default": [ + "none", + "block" + ], + properties: { + "scroll-timeline-name": { + keywords: [ + "none" + ], + "default": [ + "none" + ], + types: [ + "DashedIden" + ] + }, + "scroll-timeline-axis": { + keywords: [ + "block", + "inline", + "x", + "y" + ], + "default": [ + "block" + ], + types: [ + ] + } + } + }, + "scroll-timeline-name": { + shorthand: "scroll-timeline" + }, + "scroll-timeline-axis": { + shorthand: "scroll-timeline" + }, container: { shorthand: "container", pattern: "container-name container-type", diff --git a/dist/lib/validation/config.json.js b/dist/lib/data/validation.json.js similarity index 99% rename from dist/lib/validation/config.json.js rename to dist/lib/data/validation.json.js index c4f8f4aa..fab708a3 100644 --- a/dist/lib/validation/config.json.js +++ b/dist/lib/data/validation.json.js @@ -1584,7 +1584,7 @@ var declarations = { syntax: "none | nearest" }, "scroll-margin": { - syntax: "{1,4}" + syntax: " {1,4}" }, "scroll-margin-block": { syntax: "{1,2}" @@ -1596,7 +1596,7 @@ var declarations = { syntax: "" }, "scroll-margin-bottom": { - syntax: "" + syntax: " auto | " }, "scroll-margin-inline": { syntax: "{1,2}" @@ -1608,13 +1608,13 @@ var declarations = { syntax: "" }, "scroll-margin-left": { - syntax: "" + syntax: " auto | " }, "scroll-margin-right": { - syntax: "" + syntax: " auto | " }, "scroll-margin-top": { - syntax: "" + syntax: " auto | " }, "scroll-marker-group": { syntax: "none | before | after" @@ -1683,13 +1683,13 @@ var declarations = { syntax: "none | auto" }, "scroll-timeline": { - syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" + syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#" }, "scroll-timeline-axis": { - syntax: "[ block | inline | x | y ]#" + syntax: " [ block | inline | x | y ]#" }, "scroll-timeline-name": { - syntax: "[ none | ]#" + syntax: " [ none | ]#" }, "scrollbar-color": { syntax: "auto | {2}" @@ -2182,6 +2182,9 @@ var functions = { acos: { syntax: "acos( )" }, + alpha: { + syntax: "alpha( from / [ | none ] )" + }, anchor: { syntax: "anchor( ? && , ? )" }, diff --git a/dist/lib/parser/parse.js b/dist/lib/parser/parse.js index 1ab703dd..c103cc25 100644 --- a/dist/lib/parser/parse.js +++ b/dist/lib/parser/parse.js @@ -3393,17 +3393,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { * console.log(declarations); * ``` */ -async function parseDeclarations(declaration) { +function parseDeclarations(declaration) { const stream = `.x{${declaration}}`; - return doParse(new Tokenizer({ + const result = doParseSync(new Tokenizer({ stream, offset: 0, position: 0, source: new SourceFile(stream, [], ""), currentPosition: 0, - }), { setParent: false, minify: false, validation: false }).then((result) => { - return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType); - }); + }), { setParent: false, minify: false, validation: false }); + // .then((result) => { + return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType); + // }); } /** * Parse css string and return an array of tokens diff --git a/dist/lib/parser/tokenize.js b/dist/lib/parser/tokenize.js index 3d76a7a8..822a2e82 100644 --- a/dist/lib/parser/tokenize.js +++ b/dist/lib/parser/tokenize.js @@ -324,7 +324,7 @@ class Tokenizer { * @param parseInfo * @returns */ - consumeURLToken(parseInfo) { + consumeStringAsURLToken(parseInfo) { const quote = this.advance(parseInfo).charCodeAt(0); let charCode; let decodeSegments = false; @@ -766,7 +766,7 @@ class Tokenizer { } return 0; } - parseURLToken(parseInfo, endPosition) { + consumeURLToken(parseInfo, endPosition) { let charCode; // consume an while (isWhiteSpace(this.peekCharCode(parseInfo))) { @@ -774,7 +774,7 @@ class Tokenizer { } charCode = this.peekCharCode(parseInfo); if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) { - return this.consumeURLToken(parseInfo); + return this.consumeStringAsURLToken(parseInfo); } do { this.advance(parseInfo); @@ -1038,27 +1038,24 @@ class Tokenizer { * @param end * @returns */ - isIdentToken(parseInfo, start, end) { + isIdentToken(parseInfo /* , start?: number, end?: number */) { let j = parseInfo.currentPosition - parseInfo.offset; let i = parseInfo.position - parseInfo.offset; - if (start != null) { - if (end == null) { - if (start < 0) { - j += start; - } - else { - i += start; - } - } - else { - if (end < 0) { - j += end; - } - else { - j = parseInfo.position + end; - } - } - } + // if (start != null) { + // if (end == null) { + // if (start < 0) { + // j += start; + // } else { + // i += start; + // } + // } else { + // if (end < 0) { + // j += end; + // } else { + // j = parseInfo.position + end; + // } + // } + // } j--; let codepoint = parseInfo.stream.charCodeAt(i); // - @@ -1101,18 +1098,18 @@ class Tokenizer { * @param parseInfo * @returns */ - isPseudo(parseInfo) { - let position = parseInfo.currentPosition - parseInfo.offset; - let endPosition = parseInfo.currentPosition - parseInfo.offset; - return (parseInfo.stream.charAt(position) == ":" && - parseInfo.stream.charAt(endPosition - 1) == "(" && - (parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2, -1) - : this.isIdentToken(parseInfo, 1, -1))) || - parseInfo.stream.charAt(position + 1) == ":" - ? this.isIdentToken(parseInfo, 2) - : this.isIdentToken(parseInfo, 1); - } + // isPseudo(parseInfo: ParseInfo): boolean { + // let position: number = parseInfo.currentPosition - parseInfo.offset; + // let endPosition: number = parseInfo.currentPosition - parseInfo.offset; + // return (parseInfo.stream.charAt(position) == ":" && + // parseInfo.stream.charAt(endPosition - 1) == "(" && + // (parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2, -1) + // : this.isIdentToken(parseInfo, 1, -1))) || + // parseInfo.stream.charAt(position + 1) == ":" + // ? this.isIdentToken(parseInfo, 2) + // : this.isIdentToken(parseInfo, 1); + // } /** * * @param parseInfo @@ -1185,7 +1182,7 @@ class Tokenizer { while ((charCode = this.peekCharCode(parseInfo)) == charCode) { if (this.state === EnumToken.UrlFunctionTokenDefType) { this.state = null; - return this.parseURLToken(parseInfo, endPosition); + return this.consumeURLToken(parseInfo, endPosition); } if (parseInfo.position == parseInfo.currentPosition) { if (charCode == 45 /* TokenMap.MINUS */ || @@ -1305,12 +1302,14 @@ class Tokenizer { // '(' case 40 /* TokenMap.LEFT_PARENTHESIS */: if (parseInfo.position < parseInfo.currentPosition) { - if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && - this.isPseudo(parseInfo)) { - this.advance(parseInfo); - return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType); - } - else if (this.isIdentToken(parseInfo)) { + // if ( + // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && + // this.isPseudo(parseInfo) + // ) { + // this.advance(parseInfo); + // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType); + // } else + if (this.isIdentToken(parseInfo)) { const hint = this.startsWith(parseInfo, "--") ? EnumToken.CustomFunctionTokenDefType : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? EnumToken.FunctionTokenDefType); diff --git a/dist/lib/parser/utils/config.js b/dist/lib/parser/utils/config.js index 3dee8ca7..3e31991a 100644 --- a/dist/lib/parser/utils/config.js +++ b/dist/lib/parser/utils/config.js @@ -1,4 +1,4 @@ -import config from '../../../config.json.js'; +import config from '../../data/properties.json.js'; Object.freeze(config); // @ts-expect-error diff --git a/dist/lib/parser/utils/declaration.js b/dist/lib/parser/utils/declaration.js index c093ee84..06d1b87b 100644 --- a/dist/lib/parser/utils/declaration.js +++ b/dist/lib/parser/utils/declaration.js @@ -50,7 +50,6 @@ function parseGridTemplate(template) { * @param errors */ function parseDeclaration(tokens, parent, options, errors) { - // console.error(tokens); const name = tokens.shift(); let i; let rules = null; @@ -384,10 +383,19 @@ function parseDeclaration(tokens, parent, options, errors) { } if (trimTokenSpace.has(token.typ)) { if (tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); + for (let index = i + 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; + continue; } if (tokens[i - 1]?.typ == EnumToken.WhitespaceTokenType) { - tokens.splice(--i, 1); + for (let index = i - 1; index < tokens.length - 1; index++) { + tokens[index] = tokens[index + 1]; + } + tokens.length--; + i--; } } } diff --git a/dist/lib/parser/utils/selector.js b/dist/lib/parser/utils/selector.js index 560cd9e8..d3ef7b3e 100644 --- a/dist/lib/parser/utils/selector.js +++ b/dist/lib/parser/utils/selector.js @@ -74,7 +74,6 @@ function parseSelector(tokens, context, options, errors) { const stack = []; const uniq = new Map(); let allowed = true; - let i = 0; let index; let parent = context; let nested = false; @@ -108,119 +107,130 @@ function parseSelector(tokens, context, options, errors) { nested = parent?.typ == EnumToken.RuleNodeType; parent = parent?.[PARENT]; } while (!nested && parent != null); - for (; i < tokens.length; i++) { - if (tokens[i].typ == EnumToken.ColonTokenType) { - if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + const all = new Array(tokens.length); + let write = 0; + for (let read = 0; read < tokens.length; read++) { + let token = tokens[read]; + if (token.typ == EnumToken.ColonTokenType) { + const next = tokens[read + 1]; + if (next?.typ == EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: EnumToken.PseudoElementTokenType, - val: ":" + tokens[i + 1].val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + val: ":" + next.val, + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) { - val = ":" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == EnumToken.FunctionTokenDefType) { + val = ":" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? EnumToken.PseudoClassFunctionTokenDefType - : tokens[i + 1].typ, + : next.typ, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == EnumToken.DoubleColonTokenType) { - val = ":" + tokens[i + 1].val; - if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) { - Object.assign(tokens[i], { + if (token.typ == EnumToken.DoubleColonTokenType) { + const next = tokens[read + 1]; + val = ":" + next.val; + if (next?.typ == EnumToken.IdenTokenType) { + all[write++] = { + ...token, typ: EnumToken.PseudoClassTokenType, val: (pseudoElements.includes(val) ? "" : ":") + val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } - if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) { - val = "::" + tokens[i + 1].val; - Object.assign(tokens[i], { + if (next?.typ == EnumToken.FunctionTokenDefType) { + val = "::" + next.val; + all[write++] = { + ...token, typ: val + "()" in getSyntaxConfig().selectors ? EnumToken.PseudoClassFunctionTokenDefType : EnumToken.FunctionTokenDefType, val, - }); - tokens[i][LOCEND] = tokens[i + 1][LOCEND]; - tokens.splice(i + 1, 1); + [LOCEND]: next[LOCEND], + }; + read++; continue; } } - if (tokens[i].typ == EnumToken.ColorTokenType) { - if (isHash(tokens[i].val)) { - Object.assign(tokens[i], { - typ: EnumToken.HashTokenType, - }); + if (token.typ == EnumToken.ColorTokenType) { + if (isHash(token.val)) { + token.typ = EnumToken.HashTokenType; + all[write++] = token; + continue; } - else { - return { - typ: EnumToken.RuleNodeType, - sel: [ - ...tokens - .reduce((acc, curr, index, array) => { - // if (curr.typ == EnumToken.CommentTokenType) { - // return acc; - // } - if (curr.typ == EnumToken.WhitespaceTokenType) { - if (trimWhiteSpace.includes(array[index - 1]?.typ) || - trimWhiteSpace.includes(array[index + 1]?.typ) || - combinators.includes(array[index - 1]?.val) || - combinators.includes(array[index + 1]?.val)) { - return acc; - } - } - let t = renderValue(curr, { minify: false }); - if (t == ",") { - acc.push([]); - } - else { - acc[acc.length - 1].push(t); + return { + typ: EnumToken.RuleNodeType, + sel: [ + ...tokens + .reduce((acc, curr, index, array) => { + if (curr.typ == EnumToken.WhitespaceTokenType) { + if (trimWhiteSpace.includes(array[index - 1]?.typ) || + trimWhiteSpace.includes(array[index + 1]?.typ) || + combinators.includes(array[index - 1]?.val) || + combinators.includes(array[index + 1]?.val)) { + return acc; } - return acc; - }, [[]]) - .reduce((acc, curr) => { - let i = 0; - for (; i < curr.length; i++) { - if (i + 1 < curr.length && curr[i] == "*") { - if (curr[i] == "*") { - let index = curr[i + 1] == " " ? 2 : 1; - if (![">", "~", "+"].includes(curr[index])) { - curr.splice(i, index); - } + } + let t = renderValue(curr, { minify: false }); + if (t == ",") { + acc.push([]); + } + else { + acc[acc.length - 1].push(t); + } + return acc; + }, [[]]) + .reduce((acc, curr) => { + let i = 0; + for (; i < curr.length; i++) { + if (i + 1 < curr.length && curr[i] == "*") { + if (curr[i] == "*") { + let index = curr[i + 1] == " " ? 2 : 1; + if (![">", "~", "+"].includes(curr[index])) { + curr.splice(i, index); } } } - acc.set(curr.join(""), curr); - return acc; - }, uniq) - .keys(), - ].join(","), - chi: [], - [LOCSRCID]: tokens[0][LOCSRCID], - [LOCSTA]: tokens[0][LOCSTA], - [LOCEND]: tokens[tokens.length - 1][LOCEND], - [TOKENS]: tokens, - [STATE]: EnumAstNodeStatus.Invalid, - [ERRORS]: [ - { - action: "drop", - node: tokens[i], - message: "invalid hash id", - }, - ], - }; - } + } + acc.set(curr.join(""), curr); + return acc; + }, uniq) + .keys(), + ].join(","), + chi: [], + [LOCSRCID]: tokens[0][LOCSRCID], + [LOCSTA]: tokens[0][LOCSTA], + [LOCEND]: tokens[tokens.length - 1][LOCEND], + [TOKENS]: tokens, + [STATE]: EnumAstNodeStatus.Invalid, + [ERRORS]: [ + { + action: "drop", + node: token, + message: "invalid hash id", + }, + ], + }; + } + all[write++] = token; + } + if (write !== tokens.length) { + for (let index = 0; index < write; index++) { + tokens[index] = all[index]; } + tokens.length = write; } const result = matchSelectorSyntax(tokens, errors, options, nested === true); trimArray(tokens); diff --git a/dist/lib/renderer/render.js b/dist/lib/renderer/render.js index 000f21c0..ddd92cc9 100644 --- a/dist/lib/renderer/render.js +++ b/dist/lib/renderer/render.js @@ -515,8 +515,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, return token.val; } if (Array.isArray(token.chi)) { - const fnName = token.val.toLowerCase(); - const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase()); + const fnName = token.val; + const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val); const hasAlpha = [ "rgb", "rgba", diff --git a/dist/lib/renderer/sourcemap/lib/codec.js b/dist/lib/renderer/sourcemap/lib/codec.js index 00fb734a..0925b579 100644 --- a/dist/lib/renderer/sourcemap/lib/codec.js +++ b/dist/lib/renderer/sourcemap/lib/codec.js @@ -47,9 +47,9 @@ function decode(str) { * @returns */ function encode(value) { - if (typeof value === 'number') { - return encode_integer(value); - } + // if (typeof value === 'number') { + // return encode_integer(value); + // } let result = ''; for (let i = 0; i < value.length; i += 1) { result += encode_integer(value[i]); diff --git a/dist/lib/syntax/color/cmyk.js b/dist/lib/syntax/color/cmyk.js index 7b09361b..935e3173 100644 --- a/dist/lib/syntax/color/cmyk.js +++ b/dist/lib/syntax/color/cmyk.js @@ -61,9 +61,10 @@ function color2cmykToken(token) { } function srgb2cmykvalues(r, g, b, a = null) { const k = 1 - Math.max(r, g, b); - const c = k == 1 ? 0 : (1 - r - k) / (1 - k); - const m = k == 1 ? 0 : (1 - g - k) / (1 - k); - const y = k == 1 ? 0 : (1 - b - k) / (1 - k); + const div = 1 - k; + const c = k == 1 ? 0 : (1 - r - k) / div; + const m = k == 1 ? 0 : (1 - g - k) / div; + const y = k == 1 ? 0 : (1 - b - k) / div; const result = [c, m, y, k]; if (a != null && a < 1) { result.push(a); diff --git a/dist/lib/syntax/color/srgb.js b/dist/lib/syntax/color/srgb.js index 8523bc08..04a72655 100644 --- a/dist/lib/syntax/color/srgb.js +++ b/dist/lib/syntax/color/srgb.js @@ -116,10 +116,11 @@ function cmyk2srgbvalues(token) { t = components[3]; // @ts-ignore const k = getNumber(t); + const mul = 1 - k; const rgb = [ - 1 - Math.min(1, c * (1 - k) + k), - 1 - Math.min(1, m * (1 - k) + k), - 1 - Math.min(1, y * (1 - k) + k), + 1 - Math.min(1, c * mul + k), + 1 - Math.min(1, m * mul + k), + 1 - Math.min(1, y * mul + k), ]; if (components.length == 5) { rgb.push(getNumber(components[4])); diff --git a/dist/lib/syntax/constants.js b/dist/lib/syntax/constants.js index 75f5d4d9..de5a6921 100644 --- a/dist/lib/syntax/constants.js +++ b/dist/lib/syntax/constants.js @@ -1,5 +1,5 @@ import { EnumToken } from '../ast/types.js'; -import config from '../validation/config.json.js'; +import config from '../data/validation.json.js'; /** * Location source id diff --git a/dist/lib/validation/config.js b/dist/lib/validation/config.js index eee3dc61..cf74de38 100644 --- a/dist/lib/validation/config.js +++ b/dist/lib/validation/config.js @@ -1,4 +1,4 @@ -import config from './config.json.js'; +import config from '../data/validation.json.js'; import { trimSyntaxArray, parseSyntax } from './parser/parse.js'; import { ValidationTokenEnum } from './parser/typedef.js'; import { memoize } from '../parser/utils/cache.js'; diff --git a/dist/lib/validation/parser/parse.js b/dist/lib/validation/parser/parse.js index 8cb3029c..e4d640da 100644 --- a/dist/lib/validation/parser/parse.js +++ b/dist/lib/validation/parser/parse.js @@ -677,9 +677,13 @@ function parseSyntax(syntax) { stack.pop(); } } - if (stack.length > 0) { - throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`); - } + // if (stack.length > 0) { + // throw new SyntaxError( + // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${ + // stack.at(-1)?.[LOC]?.lin + // }:${stack.at(-1)?.[LOC]?.col}`, + // ); + // } return trimSyntaxArray(tokens); } diff --git a/files/getting-started.md b/files/getting-started.md index 1aafb051..0d9298d5 100644 --- a/files/getting-started.md +++ b/files/getting-started.md @@ -62,7 +62,7 @@ It can be imported as an umd module. ```html