diff --git a/CHANGELOG.md b/CHANGELOG.md index 90b9c62d5..b47007556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,71 @@ # Changelog +# v1.6.8 + +- [x] allow a visitor to visit all nodes + +```ts +import {transformSync} from '@tbela99/css-parser'; + + const options = { + input: ` + + button { + line-height: 2.5 !important; + line-height: 1.5; + } + `, + beautify: true, +// visit all nodes + visitor (node) { + + console.error(EnumToken[node.typ]); + } + }; + + const result = transformSync(options); + console.debug(result.code); +``` + +- [x] implement CSS [at-rule function](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@function) support + # v1.6.7 ## Improvement -- limit the amount of memory used when parsing large files -- use node flags as bitmasks +- [x] limit the amount of memory used when parsing large files +- [x] use node flags as bitmasks +- [x] merging properties now takes into consideration the !important flag + +```ts +import {transformSync} from '@tbela99/css-parser'; + + const options = { + input: ` + + button { + line-height: 2.5 !important; + line-height: 1.5; + } + `, + beautify: true, + }; + + const result = transformSync(options); + console.debug(result.code); +``` + +result + +```css +button { + line-height: 2.5!important +} +``` ## Fixes -- [x] fix powerless and missing components handling with color-mix(). missing and powerless colors are now [carried forwarded](https://drafts.csswg.org/css-color-5/#rcs-intro) +- [x] fix powerless and missing components handling with color-mix(). missing and powerless colors are now [carried forward](https://drafts.csswg.org/css-color-5/#rcs-intro) ```ts const css = ` @@ -33,7 +89,7 @@ const result = transformSync({input: css, removeDuplicateDeclarations: false, convertColor: ColorType.SRGB }); -// console.debug(result); + console.debug(result.code); ``` diff --git a/dist/index-umd-web.js b/dist/index-umd-web.js index e2c6a48cf..cb1e002c8 100644 --- a/dist/index-umd-web.js +++ b/dist/index-umd-web.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -547,7 +554,7 @@ /** * '|' */ - EnumToken[EnumToken["Pipe"] = 109] = "Pipe"; + EnumToken[EnumToken["PipeTokenType"] = 109] = "PipeTokenType"; /** * '::' */ @@ -686,6 +693,10 @@ * negative infinity token */ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType"; + /** + * CSS type token + */ + EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType"; /* aliases */ /** * alias for time token type @@ -12485,8 +12496,7 @@ case MediaFeatureType.RatioType: return { valid: true, - success: (tokens.length == 1 && - tokens[0].typ == exports.EnumToken.NumberTokenType) || + success: (tokens.length == 1 && tokens[0].typ == exports.EnumToken.NumberTokenType) || (tokens.length === 3 && tokens[0].typ == exports.EnumToken.NumberTokenType && typeof tokens[0].val === "number" && @@ -12793,7 +12803,7 @@ } stack.push(token); break; - case exports.EnumToken.Pipe: + case exports.EnumToken.PipeTokenType: case exports.EnumToken.DelimTokenType: case exports.EnumToken.StringTokenType: case exports.EnumToken.IncludeMatchTokenType: @@ -12841,10 +12851,10 @@ } slice.push(tokens[n]); } - if (slice[1]?.typ === exports.EnumToken.Pipe) { + if (slice[1]?.typ === exports.EnumToken.PipeTokenType) { slice.shift(); } - if (slice[0].typ === exports.EnumToken.Pipe) { + if (slice[0].typ === exports.EnumToken.PipeTokenType) { slice.shift(); } if (slice.length === 1) { @@ -13206,8 +13216,8 @@ // custom function token if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) { if (syntaxes[i].typ != ValidationTokenEnum.PropertyType || - syntaxes[i + 1].typ != ValidationTokenEnum.OpenParenthesis || - syntaxes[i + 2].typ == null) { + syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis || + syntaxes[i + 2]?.typ == null) { if (!isOptional) { return { success: false, @@ -14054,17 +14064,15 @@ case "display-internal": case "display-outside": case "display-legacy": - case "content-position": - { - let values = propertyKeywordValues.get(property.val); - if (values == null) { - values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/)); - propertyKeywordValues.set(property.val, values); - } - success = - token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); - break; + case "content-position": { + let values = propertyKeywordValues.get(property.val); + if (values == null) { + values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/)); + propertyKeywordValues.set(property.val, values); } + success = token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); + break; + } case "mf-name": { const token = context.peek(); @@ -14084,8 +14092,7 @@ case "custom-ident": case "counter-name": case "counter-style-name": - success = - token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType; + success = token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType; if (success && token?.typ === exports.EnumToken.IdenTokenType) { const val = token.val.toLowerCase(); success = "none" !== val && !allValues.includes(val); @@ -14556,6 +14563,21 @@ } break; } + case "css-type": { + success = context.peek()?.typ == exports.EnumToken.CssTypeTokenType; + if (success) { + context.next(); + return { + success: true, + valid: true, + token: null, + context, + syntaxToken: null, + errors: [], + }; + } + break; + } default: if (!(property.val in config$3.syntaxes)) { console.debug("Unknown syntax", context.peek(), property); @@ -21132,12 +21154,15 @@ exports.EnumToken.LtTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ChildCombinatorTokenType, + exports.EnumToken.PipeTokenType, ]); const trimSpaceAfter = new Set([ ...tokensfuncSet.values(), exports.EnumToken.ChildCombinatorTokenType, exports.EnumToken.SupportsQueryConditionTokenType, exports.EnumToken.SupportsQueryUnaryConditionTokenType, + exports.EnumToken.CommaTokenType, + exports.EnumToken.PipeTokenType, ]); /** * Replace token in its parent node @@ -21207,17 +21232,18 @@ return tokens; } for (; i < tokens.length; i++) { - if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); - } - else if (trimTokenSpace.has(tokens[i].typ)) { + if (trimTokenSpace.has(tokens[i].typ)) { if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { tokens.splice(i + 1, 1); } if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) { tokens.splice(--i, 1); + continue; } } + if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { + tokens.splice(i + 1, 1); + } } return tokens; } @@ -26667,7 +26693,7 @@ return ","; case exports.EnumToken.ImportantTokenType: return "!important"; - case exports.EnumToken.Pipe: + case exports.EnumToken.PipeTokenType: return "|"; case exports.EnumToken.AttrTokenType: case exports.EnumToken.IdenListTokenType: @@ -26790,6 +26816,7 @@ pseudoElements.includes(token.val.slice(1))) { return token.val.slice(1); } + case exports.EnumToken.CssTypeTokenType: case exports.EnumToken.UrlTokenTokenType: case exports.EnumToken.HashTokenType: case exports.EnumToken.IdenTokenType: @@ -26943,7 +26970,7 @@ SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType; SymbolsMapTokens["+"] = exports.EnumToken.Plus; SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType; - SymbolsMapTokens["|"] = exports.EnumToken.Pipe; + SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType; SymbolsMapTokens["||"] = exports.EnumToken.ColumnCombinatorTokenType; SymbolsMapTokens["|="] = exports.EnumToken.DashMatchTokenType; SymbolsMapTokens["&"] = exports.EnumToken.NestingSelectorTokenType; @@ -27602,7 +27629,6 @@ if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) { // eof if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) { - // this.next(parseInfo, position); return 0; } // \n \r \f \v @@ -28375,7 +28401,7 @@ return this.makeToken(parseInfo, exports.EnumToken.DashMatchTokenType); } this.advance(parseInfo); - return this.makeToken(parseInfo, exports.EnumToken.Pipe); + return this.makeToken(parseInfo, exports.EnumToken.PipeTokenType); case 33 /* TokenMap.EXCLAMATION */: if (parseInfo.position < parseInfo.currentPosition) { return this.makeToken(parseInfo); @@ -28441,6 +28467,21 @@ return this.makeToken(parseInfo, exports.EnumToken.CDOCOMMTokenType); } } + { + const startPosition = parseInfo.position - parseInfo.offset; + let offset = 1; + let charCode = parseInfo.stream.charCodeAt(startPosition + offset); + if (isLetter(charCode)) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + } + if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) { + this.advance(parseInfo, offset); + return this.makeToken(parseInfo, exports.EnumToken.CssTypeTokenType); + } + } + } break; case 35 /* TokenMap.HASH */: if (parseInfo.position < parseInfo.currentPosition) { @@ -31170,6 +31211,9 @@ let key; let value; let i; + const allVisitorsHandlers = new Set(); + const preAllVisitorsHandlers = new Set(); + const postAllVisitorsHandlers = new Set(); const valuesHandlers = new Map(); const preValuesHandlers = new Map(); const postValuesHandlers = new Map(); @@ -31270,6 +31314,21 @@ errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } } + else if (key == "All" || key == "visitor") { + if (typeof value == "function") { + allVisitorsHandlers.add(value); + } + else if (typeof value == "object") { + if ("type" in value && "handler" in value && value.type in exports.WalkerEvent) { + if (value.type == exports.WalkerEvent.Enter) { + preAllVisitorsHandlers.add(value.handler); + } + else if (value.type == exports.WalkerEvent.Leave) { + postAllVisitorsHandlers.add(value.handler); + } + } + } + } else { errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } @@ -31293,10 +31352,25 @@ if (postValuesHandlers.size > 0) { allHandlers.push(postValuesHandlers); } - return { + const result = { allHandlers, - includeTokens: preValuesHandlers.size > 0 || valuesHandlers.size > 0 || postValuesHandlers.size > 0, + includeTokens: preValuesHandlers.size > 0 || + valuesHandlers.size > 0 || + postValuesHandlers.size > 0 || + allVisitorsHandlers.size > 0 || + preAllVisitorsHandlers.size > 0 || + postAllVisitorsHandlers.size > 0, }; + if (allVisitorsHandlers.size > 0) { + result.allVisitorsHandlers = allVisitorsHandlers; + } + if (preAllVisitorsHandlers.size > 0) { + result.preAllVisitorsHandlers = preAllVisitorsHandlers; + } + if (postAllVisitorsHandlers.size > 0) { + result.postAllVisitorsHandlers = postAllVisitorsHandlers; + } + return result; } /** * Parse css string @@ -31369,12 +31443,10 @@ // @ts-ignore ignore error let parensMatch = 0; let curlyBracketMatch = 0; - // let currentItemIndex: number; ast[LOCSRCID] = options.source.id; ast[LOCSTA] = 0; while (!tokenizer.done()) { tokenizer.next(); - // item = (iter as Array)[currentItemIndex]; if (tokenizer.unit != null) { item = { typ: tokenizer.typ, @@ -31520,7 +31592,6 @@ parensMatch = 0; curlyBracketMatch = 0; } - // } } if (tokens.length > 0) { node = parseNode(tokens, context, options, errors, stats, invalidNodes); @@ -31590,6 +31661,9 @@ } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == exports.EnumToken.DeclarationNodeType ? "Declaration" @@ -31609,6 +31683,9 @@ : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -31617,20 +31694,6 @@ if (typeof handler == "function") { handlers.push(handler); } - // else if (Array.isArray(handler)) { - // for (const h of handler) { - // if (typeof h == "function") { - // handlers.push(h); - // } - // // @ts-ignore - // else if (h[keyName] != null) { - // // @ts-ignore - // handlers.push(h[keyName]); - // } - // } - // } else if (typeof handler.handler! == "function") { - // handlers.push(handler.handler); - // } // @ts-ignore else if (typeof handler[keyName] == "function") { // @ts-ignore @@ -31663,6 +31726,9 @@ } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -32582,6 +32648,9 @@ } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == exports.EnumToken.DeclarationNodeType ? "Declaration" @@ -32601,6 +32670,9 @@ : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -32655,6 +32727,9 @@ } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -33515,7 +33590,6 @@ const syntax = syntaxRules?.getPreludeRules()?.slice?.(1); const blockAllowed = syntaxRules?.getBlockRules() != null; if (syntaxRules == null) { - // if (!options.lenient) { errors.push({ action: "drop", node: atRule, @@ -34232,7 +34306,7 @@ stream[index][LOCEND] = stream[i][LOCEND]; Object.assign(stream[index], { typ: tokensfuncDefMap.get(stream[index].typ), - chi: stream.splice(index + 1, i - index - 1), + chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)), }); i = index; stream.splice(index + 1, 1); @@ -34704,6 +34778,8 @@ } } + var version = "1.6.8"; + /** * Load file or url * @param url @@ -35137,6 +35213,7 @@ exports.transform = transform; exports.transformFile = transformFile; exports.transformSync = transformSync; + exports.version = version; exports.walk = walk; exports.walkValues = walkValues; diff --git a/dist/index.cjs b/dist/index.cjs index 85e0c9e54..956baf354 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -550,7 +550,7 @@ exports.EnumToken = void 0; /** * '|' */ - EnumToken[EnumToken["Pipe"] = 109] = "Pipe"; + EnumToken[EnumToken["PipeTokenType"] = 109] = "PipeTokenType"; /** * '::' */ @@ -689,6 +689,10 @@ exports.EnumToken = void 0; * negative infinity token */ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType"; + /** + * CSS type token + */ + EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType"; /* aliases */ /** * alias for time token type @@ -12488,8 +12492,7 @@ function isMFValue(featureName, tokens, isMFRange) { case MediaFeatureType.RatioType: return { valid: true, - success: (tokens.length == 1 && - tokens[0].typ == exports.EnumToken.NumberTokenType) || + success: (tokens.length == 1 && tokens[0].typ == exports.EnumToken.NumberTokenType) || (tokens.length === 3 && tokens[0].typ == exports.EnumToken.NumberTokenType && typeof tokens[0].val === "number" && @@ -12796,7 +12799,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) { } stack.push(token); break; - case exports.EnumToken.Pipe: + case exports.EnumToken.PipeTokenType: case exports.EnumToken.DelimTokenType: case exports.EnumToken.StringTokenType: case exports.EnumToken.IncludeMatchTokenType: @@ -12844,10 +12847,10 @@ function matchSelectorSyntax(stream, errors, options, nested = true) { } slice.push(tokens[n]); } - if (slice[1]?.typ === exports.EnumToken.Pipe) { + if (slice[1]?.typ === exports.EnumToken.PipeTokenType) { slice.shift(); } - if (slice[0].typ === exports.EnumToken.Pipe) { + if (slice[0].typ === exports.EnumToken.PipeTokenType) { slice.shift(); } if (slice.length === 1) { @@ -13209,8 +13212,8 @@ function matchSyntax(syntaxes, context, options) { // custom function token if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) { if (syntaxes[i].typ != ValidationTokenEnum.PropertyType || - syntaxes[i + 1].typ != ValidationTokenEnum.OpenParenthesis || - syntaxes[i + 2].typ == null) { + syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis || + syntaxes[i + 2]?.typ == null) { if (!isOptional) { return { success: false, @@ -14057,17 +14060,15 @@ function matchProperty(property, context, options) { case "display-internal": case "display-outside": case "display-legacy": - case "content-position": - { - let values = propertyKeywordValues.get(property.val); - if (values == null) { - values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/)); - propertyKeywordValues.set(property.val, values); - } - success = - token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); - break; + case "content-position": { + let values = propertyKeywordValues.get(property.val); + if (values == null) { + values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/)); + propertyKeywordValues.set(property.val, values); } + success = token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); + break; + } case "mf-name": { const token = context.peek(); @@ -14087,8 +14088,7 @@ function matchProperty(property, context, options) { case "custom-ident": case "counter-name": case "counter-style-name": - success = - token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType; + success = token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType; if (success && token?.typ === exports.EnumToken.IdenTokenType) { const val = token.val.toLowerCase(); success = "none" !== val && !allValues.includes(val); @@ -14559,6 +14559,21 @@ function matchProperty(property, context, options) { } break; } + case "css-type": { + success = context.peek()?.typ == exports.EnumToken.CssTypeTokenType; + if (success) { + context.next(); + return { + success: true, + valid: true, + token: null, + context, + syntaxToken: null, + errors: [], + }; + } + break; + } default: if (!(property.val in config$3.syntaxes)) { console.debug("Unknown syntax", context.peek(), property); @@ -21135,12 +21150,15 @@ const trimTokenSpace = new Set([ exports.EnumToken.LtTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ChildCombinatorTokenType, + exports.EnumToken.PipeTokenType, ]); const trimSpaceAfter = new Set([ ...tokensfuncSet.values(), exports.EnumToken.ChildCombinatorTokenType, exports.EnumToken.SupportsQueryConditionTokenType, exports.EnumToken.SupportsQueryUnaryConditionTokenType, + exports.EnumToken.CommaTokenType, + exports.EnumToken.PipeTokenType, ]); /** * Replace token in its parent node @@ -21210,17 +21228,18 @@ function trimWhiteSpaceTokens(tokens) { return tokens; } for (; i < tokens.length; i++) { - if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); - } - else if (trimTokenSpace.has(tokens[i].typ)) { + if (trimTokenSpace.has(tokens[i].typ)) { if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { tokens.splice(i + 1, 1); } if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) { tokens.splice(--i, 1); + continue; } } + if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) { + tokens.splice(i + 1, 1); + } } return tokens; } @@ -26670,7 +26689,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, return ","; case exports.EnumToken.ImportantTokenType: return "!important"; - case exports.EnumToken.Pipe: + case exports.EnumToken.PipeTokenType: return "|"; case exports.EnumToken.AttrTokenType: case exports.EnumToken.IdenListTokenType: @@ -26793,6 +26812,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, pseudoElements.includes(token.val.slice(1))) { return token.val.slice(1); } + case exports.EnumToken.CssTypeTokenType: case exports.EnumToken.UrlTokenTokenType: case exports.EnumToken.HashTokenType: case exports.EnumToken.IdenTokenType: @@ -26946,7 +26966,7 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) { SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType; SymbolsMapTokens["+"] = exports.EnumToken.Plus; SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType; -SymbolsMapTokens["|"] = exports.EnumToken.Pipe; +SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType; SymbolsMapTokens["||"] = exports.EnumToken.ColumnCombinatorTokenType; SymbolsMapTokens["|="] = exports.EnumToken.DashMatchTokenType; SymbolsMapTokens["&"] = exports.EnumToken.NestingSelectorTokenType; @@ -27605,7 +27625,6 @@ class Tokenizer { if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) { // eof if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) { - // this.next(parseInfo, position); return 0; } // \n \r \f \v @@ -28378,7 +28397,7 @@ class Tokenizer { return this.makeToken(parseInfo, exports.EnumToken.DashMatchTokenType); } this.advance(parseInfo); - return this.makeToken(parseInfo, exports.EnumToken.Pipe); + return this.makeToken(parseInfo, exports.EnumToken.PipeTokenType); case 33 /* TokenMap.EXCLAMATION */: if (parseInfo.position < parseInfo.currentPosition) { return this.makeToken(parseInfo); @@ -28444,6 +28463,21 @@ class Tokenizer { return this.makeToken(parseInfo, exports.EnumToken.CDOCOMMTokenType); } } + { + const startPosition = parseInfo.position - parseInfo.offset; + let offset = 1; + let charCode = parseInfo.stream.charCodeAt(startPosition + offset); + if (isLetter(charCode)) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + } + if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) { + this.advance(parseInfo, offset); + return this.makeToken(parseInfo, exports.EnumToken.CssTypeTokenType); + } + } + } break; case 35 /* TokenMap.HASH */: if (parseInfo.position < parseInfo.currentPosition) { @@ -31173,6 +31207,9 @@ function parseVisitors(visitorsDef, errors) { let key; let value; let i; + const allVisitorsHandlers = new Set(); + const preAllVisitorsHandlers = new Set(); + const postAllVisitorsHandlers = new Set(); const valuesHandlers = new Map(); const preValuesHandlers = new Map(); const postValuesHandlers = new Map(); @@ -31273,6 +31310,21 @@ function parseVisitors(visitorsDef, errors) { errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } } + else if (key == "All" || key == "visitor") { + if (typeof value == "function") { + allVisitorsHandlers.add(value); + } + else if (typeof value == "object") { + if ("type" in value && "handler" in value && value.type in exports.WalkerEvent) { + if (value.type == exports.WalkerEvent.Enter) { + preAllVisitorsHandlers.add(value.handler); + } + else if (value.type == exports.WalkerEvent.Leave) { + postAllVisitorsHandlers.add(value.handler); + } + } + } + } else { errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } @@ -31296,10 +31348,25 @@ function parseVisitors(visitorsDef, errors) { if (postValuesHandlers.size > 0) { allHandlers.push(postValuesHandlers); } - return { + const result = { allHandlers, - includeTokens: preValuesHandlers.size > 0 || valuesHandlers.size > 0 || postValuesHandlers.size > 0, + includeTokens: preValuesHandlers.size > 0 || + valuesHandlers.size > 0 || + postValuesHandlers.size > 0 || + allVisitorsHandlers.size > 0 || + preAllVisitorsHandlers.size > 0 || + postAllVisitorsHandlers.size > 0, }; + if (allVisitorsHandlers.size > 0) { + result.allVisitorsHandlers = allVisitorsHandlers; + } + if (preAllVisitorsHandlers.size > 0) { + result.preAllVisitorsHandlers = preAllVisitorsHandlers; + } + if (postAllVisitorsHandlers.size > 0) { + result.postAllVisitorsHandlers = postAllVisitorsHandlers; + } + return result; } /** * Parse css string @@ -31372,12 +31439,10 @@ function doParseSync(tokenizer, options = {}) { // @ts-ignore ignore error let parensMatch = 0; let curlyBracketMatch = 0; - // let currentItemIndex: number; ast[LOCSRCID] = options.source.id; ast[LOCSTA] = 0; while (!tokenizer.done()) { tokenizer.next(); - // item = (iter as Array)[currentItemIndex]; if (tokenizer.unit != null) { item = { typ: tokenizer.typ, @@ -31523,7 +31588,6 @@ function doParseSync(tokenizer, options = {}) { parensMatch = 0; curlyBracketMatch = 0; } - // } } if (tokens.length > 0) { node = parseNode(tokens, context, options, errors, stats, invalidNodes); @@ -31593,6 +31657,9 @@ function doParseSync(tokenizer, options = {}) { } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == exports.EnumToken.DeclarationNodeType ? "Declaration" @@ -31612,6 +31679,9 @@ function doParseSync(tokenizer, options = {}) { : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -31620,20 +31690,6 @@ function doParseSync(tokenizer, options = {}) { if (typeof handler == "function") { handlers.push(handler); } - // else if (Array.isArray(handler)) { - // for (const h of handler) { - // if (typeof h == "function") { - // handlers.push(h); - // } - // // @ts-ignore - // else if (h[keyName] != null) { - // // @ts-ignore - // handlers.push(h[keyName]); - // } - // } - // } else if (typeof handler.handler! == "function") { - // handlers.push(handler.handler); - // } // @ts-ignore else if (typeof handler[keyName] == "function") { // @ts-ignore @@ -31666,6 +31722,9 @@ function doParseSync(tokenizer, options = {}) { } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -32585,6 +32644,9 @@ async function doParse(iter, options = {}) { } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == exports.EnumToken.DeclarationNodeType ? "Declaration" @@ -32604,6 +32666,9 @@ async function doParse(iter, options = {}) { : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -32658,6 +32723,9 @@ async function doParse(iter, options = {}) { } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -33518,7 +33586,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { const syntax = syntaxRules?.getPreludeRules()?.slice?.(1); const blockAllowed = syntaxRules?.getBlockRules() != null; if (syntaxRules == null) { - // if (!options.lenient) { errors.push({ action: "drop", node: atRule, @@ -34235,7 +34302,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { stream[index][LOCEND] = stream[i][LOCEND]; Object.assign(stream[index], { typ: tokensfuncDefMap.get(stream[index].typ), - chi: stream.splice(index + 1, i - index - 1), + chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)), }); i = index; stream.splice(index + 1, 1); @@ -34707,6 +34774,8 @@ function setNodeProperty(node, key, value) { } } +var version = "1.6.8"; + /** * Load file or url * @param url @@ -35190,5 +35259,6 @@ exports.setNodeProperty = setNodeProperty; exports.transform = transform; exports.transformFile = transformFile; exports.transformSync = transformSync; +exports.version = version; exports.walk = walk; exports.walkValues = walkValues; diff --git a/dist/index.d.ts b/dist/index.d.ts index 0d5f7830f..779062c99 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -534,7 +534,7 @@ declare enum EnumToken { /** * '|' */ - Pipe = 109, + PipeTokenType = 109, /** * '::' */ @@ -673,6 +673,10 @@ declare enum EnumToken { * negative infinity token */ NegativeInfinityTokenType = 143, + /** + * CSS type token + */ + CssTypeTokenType = 144, /** * alias for time token type */ @@ -1070,6 +1074,20 @@ export declare interface IdentToken extends BaseToken { val: string; } +/** + * Css type token + */ +export declare interface CssTypeTokenType extends BaseToken { + /** + * @inheritdoc + */ + typ: EnumToken.CssTypeTokenType; + /** + * css type value + */ + val: string; +} + /** * Ident list token */ @@ -2693,6 +2711,7 @@ export declare type Token$1 = | NaNToken | InfinityToken | NegativeInfinityToken + | CssTypeTokenType | EOFToken; /** @@ -3407,6 +3426,7 @@ export declare type GenericVisitorSyncHandler = ( export declare type GenericVisitorAstNodeSyncHandlerMap = | Record> | GenericVisitorSyncHandler + | Function | { type: WalkerEvent; handler: GenericVisitorSyncHandler } | { type: WalkerEvent; handler: Record> }; @@ -3978,6 +3998,32 @@ export declare interface VisitorNodeMap { [key: keyof typeof EnumToken]: GenericVisitorAstNodeHandlerMap | GenericVisitorAstNodeHandlerMap; } +/** + * Parsed visitor handlers + */ +interface ParsedVisitorHandlers { + /** + * include tokens + */ + includeTokens: boolean; + /** + * all handlers + */ + allHandlers: Array>; + /** + * all visitors + */ + allVisitorsHandlers?: Set> | Set>; + /** + * pre all visitors + */ + preAllVisitorsHandlers?: Set> | Set>; + /** + * post all visitors + */ + postAllVisitorsHandlers?: Set> | Set>; +} + /** * Generate and parse source map * @@ -6641,6 +6687,8 @@ declare function setNodeProperty(node: AstNode$1, key: 'errors', value: ErrorDes */ declare function setNodeProperty(node: AstNode$1, key: 'tokens', value: Token$1[] | null): void; +declare let version: string; + /** * Load file or url * @param url @@ -7028,5 +7076,5 @@ declare function transform(options: ParseInputStreamOptions & TransformOptions): */ declare function transform(options: ParseInputFileOptions & TransformOptions): Promise; -export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, cloneNode, convertColor, dirname, expand, find, findAll, findByValue, findLast, getNodeProperty, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseSync, render, renderValue as renderToken, replaceNodeOrValue, resolve, setNodeProperty, transform, transformFile, transformSync, walk, walkValues }; -export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InfinityToken, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NaNToken, NameSpaceAttributeToken, NegativeInfinityToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenSearchResult, TokenizeResult, TransformOptions, TransformResult, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerOptions, WalkerValueFilter, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken }; +export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, cloneNode, convertColor, dirname, expand, find, findAll, findByValue, findLast, getNodeProperty, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseSync, render, renderValue as renderToken, replaceNodeOrValue, resolve, setNodeProperty, transform, transformFile, transformSync, version, walk, walkValues }; +export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssTypeTokenType, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InfinityToken, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NaNToken, NameSpaceAttributeToken, NegativeInfinityToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParsedVisitorHandlers, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenSearchResult, TokenizeResult, TransformOptions, TransformResult, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerOptions, WalkerValueFilter, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken }; diff --git a/dist/lib/syntax/color/hsv.js b/dist/lib/syntax/color/hsv.js deleted file mode 100644 index 585c991e4..000000000 --- a/dist/lib/syntax/color/hsv.js +++ /dev/null @@ -1,6 +0,0 @@ -function hwb2hsv(h, w, b, a) { - // @ts-ignore - return [h, 1 - w / (1 - b), 1 - b, a]; -} - -export { hwb2hsv }; diff --git a/dist/package.json.js b/dist/package.json.js new file mode 100644 index 000000000..60ef566f3 --- /dev/null +++ b/dist/package.json.js @@ -0,0 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ +var version = "1.6.8"; + +export { version }; diff --git a/dist/data/properties.json.js b/dist/src/data/properties.json.js similarity index 99% rename from dist/data/properties.json.js rename to dist/src/data/properties.json.js index 334f1c39d..60f886b19 100644 --- a/dist/data/properties.json.js +++ b/dist/src/data/properties.json.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ var properties = { gap: { shorthand: "gap", diff --git a/dist/data/validation.json.js b/dist/src/data/validation.json.js similarity index 99% rename from dist/data/validation.json.js rename to dist/src/data/validation.json.js index 70439690c..dda1ec13e 100644 --- a/dist/data/validation.json.js +++ b/dist/src/data/validation.json.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ var declarations = { "-ms-accelerator": { syntax: "false | true" diff --git a/dist/lib/ast/clone.js b/dist/src/lib/ast/clone.js similarity index 90% rename from dist/lib/ast/clone.js rename to dist/src/lib/ast/clone.js index 37b9563a0..4c43a3b52 100644 --- a/dist/lib/ast/clone.js +++ b/dist/src/lib/ast/clone.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from './types.js'; /** diff --git a/dist/lib/ast/expand.js b/dist/src/lib/ast/expand.js similarity index 99% rename from dist/lib/ast/expand.js rename to dist/src/lib/ast/expand.js index b87c30094..5677f978d 100644 --- a/dist/lib/ast/expand.js +++ b/dist/src/lib/ast/expand.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { splitRule } from './minify.js'; import { STATE, PARENT, combinators, RAW } from '../syntax/constants.js'; import { parseString } from '../parser/parse.js'; diff --git a/dist/lib/ast/features/calc.js b/dist/src/lib/ast/features/calc.js similarity index 98% rename from dist/lib/ast/features/calc.js rename to dist/src/lib/ast/features/calc.js index 63ce047d8..77b3d79c1 100644 --- a/dist/lib/ast/features/calc.js +++ b/dist/src/lib/ast/features/calc.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../types.js'; import { walkValues } from '../walk.js'; import { evaluate } from '../math/expression.js'; diff --git a/dist/lib/ast/features/if.js b/dist/src/lib/ast/features/if.js similarity index 98% rename from dist/lib/ast/features/if.js rename to dist/src/lib/ast/features/if.js index 0acfa25c5..90eb588fc 100644 --- a/dist/lib/ast/features/if.js +++ b/dist/src/lib/ast/features/if.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../types.js'; import { renderValue } from '../../printer/render.js'; import { FeatureWalkMode } from './type.js'; diff --git a/dist/lib/ast/features/index.js b/dist/src/lib/ast/features/index.js similarity index 72% rename from dist/lib/ast/features/index.js rename to dist/src/lib/ast/features/index.js index dfb0c7296..e0065d5f7 100644 --- a/dist/lib/ast/features/index.js +++ b/dist/src/lib/ast/features/index.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ export { ComputePrefixFeature } from './prefix.js'; export { InlineCssVariablesFeature } from './inlinecssvariables.js'; export { ComputeShorthandFeature } from './shorthand.js'; diff --git a/dist/lib/ast/features/inlinecssvariables.js b/dist/src/lib/ast/features/inlinecssvariables.js similarity index 97% rename from dist/lib/ast/features/inlinecssvariables.js rename to dist/src/lib/ast/features/inlinecssvariables.js index 9dc33e0ce..00265176d 100644 --- a/dist/lib/ast/features/inlinecssvariables.js +++ b/dist/src/lib/ast/features/inlinecssvariables.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../types.js'; import { walkValues } from '../walk.js'; import { renderValue } from '../../printer/render.js'; diff --git a/dist/lib/ast/features/prefix.js b/dist/src/lib/ast/features/prefix.js similarity index 99% rename from dist/lib/ast/features/prefix.js rename to dist/src/lib/ast/features/prefix.js index 1de25da35..62340357c 100644 --- a/dist/lib/ast/features/prefix.js +++ b/dist/src/lib/ast/features/prefix.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumAstNodeStatus, EnumToken } from '../types.js'; import { walkValues } from '../walk.js'; import { pseudoAliasMap } from '../../syntax/syntax.js'; diff --git a/dist/lib/ast/features/shorthand.js b/dist/src/lib/ast/features/shorthand.js similarity index 94% rename from dist/lib/ast/features/shorthand.js rename to dist/src/lib/ast/features/shorthand.js index 684f0e747..d90b5e1bc 100644 --- a/dist/lib/ast/features/shorthand.js +++ b/dist/src/lib/ast/features/shorthand.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { PropertyList } from '../../parser/declaration/list.js'; import { EnumToken } from '../types.js'; import { FeatureWalkMode } from './type.js'; diff --git a/dist/lib/ast/features/transform.js b/dist/src/lib/ast/features/transform.js similarity index 95% rename from dist/lib/ast/features/transform.js rename to dist/src/lib/ast/features/transform.js index 266c6f91f..ac57ab13b 100644 --- a/dist/lib/ast/features/transform.js +++ b/dist/src/lib/ast/features/transform.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, EnumAstNodeStatus } from '../types.js'; import { compute } from '../transform/compute.js'; import { filterValues, renderValue } from '../../printer/render.js'; diff --git a/dist/lib/ast/features/type.js b/dist/src/lib/ast/features/type.js similarity index 74% rename from dist/lib/ast/features/type.js rename to dist/src/lib/ast/features/type.js index d2ee5c1dc..7cfa1ffcf 100644 --- a/dist/lib/ast/features/type.js +++ b/dist/src/lib/ast/features/type.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * feature walk mode * diff --git a/dist/lib/ast/find.js b/dist/src/lib/ast/find.js similarity index 97% rename from dist/lib/ast/find.js rename to dist/src/lib/ast/find.js index 8c46228fb..12778c0d6 100644 --- a/dist/lib/ast/find.js +++ b/dist/src/lib/ast/find.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from './types.js'; import { walk, walkValues } from './walk.js'; import { TOKENS } from '../syntax/constants.js'; diff --git a/dist/lib/ast/math/expression.js b/dist/src/lib/ast/math/expression.js similarity index 99% rename from dist/lib/ast/math/expression.js rename to dist/src/lib/ast/math/expression.js index 75e2d5893..1ec1c4010 100644 --- a/dist/lib/ast/math/expression.js +++ b/dist/src/lib/ast/math/expression.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { equalsIgnoreCase } from '../../parser/utils/text.js'; import { mathFuncs, PARENT, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js'; import { EnumToken } from '../types.js'; diff --git a/dist/lib/ast/math/math.js b/dist/src/lib/ast/math/math.js similarity index 96% rename from dist/lib/ast/math/math.js rename to dist/src/lib/ast/math/math.js index a2d4cded2..6958b5711 100644 --- a/dist/lib/ast/math/math.js +++ b/dist/src/lib/ast/math/math.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { minifyNumber } from '../../syntax/syntax.js'; import { EnumToken } from '../types.js'; diff --git a/dist/lib/ast/minify.js b/dist/src/lib/ast/minify.js similarity index 99% rename from dist/lib/ast/minify.js rename to dist/src/lib/ast/minify.js index 6817fbf1d..96251edf6 100644 --- a/dist/lib/ast/minify.js +++ b/dist/src/lib/ast/minify.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { eq } from '../parser/utils/eq.js'; import { renderValue, doRender } from '../printer/render.js'; import * as index from './features/index.js'; diff --git a/dist/lib/ast/node.js b/dist/src/lib/ast/node.js similarity index 91% rename from dist/lib/ast/node.js rename to dist/src/lib/ast/node.js index 99b652873..47b2477c2 100644 --- a/dist/lib/ast/node.js +++ b/dist/src/lib/ast/node.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { TOKENS, ERRORS, STATE, LOCSRCID, LOCSTA, LOCEND, PARENT } from '../syntax/constants.js'; /** diff --git a/dist/lib/ast/transform/compute.js b/dist/src/lib/ast/transform/compute.js similarity index 99% rename from dist/lib/ast/transform/compute.js rename to dist/src/lib/ast/transform/compute.js index f34888b54..246cc9d69 100644 --- a/dist/lib/ast/transform/compute.js +++ b/dist/src/lib/ast/transform/compute.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply, toZero } from './utils.js'; import { EnumToken } from '../types.js'; import { stripCommaToken } from '../../validation/utils/list.js'; diff --git a/dist/lib/ast/transform/matrix.js b/dist/src/lib/ast/transform/matrix.js similarity index 96% rename from dist/lib/ast/transform/matrix.js rename to dist/src/lib/ast/transform/matrix.js index 325b62199..d5b2764f7 100644 --- a/dist/lib/ast/transform/matrix.js +++ b/dist/src/lib/ast/transform/matrix.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, is2DMatrix } from './utils.js'; import { EnumToken } from '../types.js'; import { eq } from '../../parser/utils/eq.js'; diff --git a/dist/lib/ast/transform/minify.js b/dist/src/lib/ast/transform/minify.js similarity index 99% rename from dist/lib/ast/transform/minify.js rename to dist/src/lib/ast/transform/minify.js index a66fcde22..d49484231 100644 --- a/dist/lib/ast/transform/minify.js +++ b/dist/src/lib/ast/transform/minify.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply, decompose, round, toZero } from './utils.js'; import { epsilon } from '../../syntax/constants.js'; import { EnumToken } from '../types.js'; diff --git a/dist/lib/ast/transform/perspective.js b/dist/src/lib/ast/transform/perspective.js similarity index 71% rename from dist/lib/ast/transform/perspective.js rename to dist/src/lib/ast/transform/perspective.js index 923af9401..e0ecb65ca 100644 --- a/dist/lib/ast/transform/perspective.js +++ b/dist/src/lib/ast/transform/perspective.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply } from './utils.js'; function perspective(x, from) { diff --git a/dist/lib/ast/transform/rotate.js b/dist/src/lib/ast/transform/rotate.js similarity index 90% rename from dist/lib/ast/transform/rotate.js rename to dist/src/lib/ast/transform/rotate.js index 637e30809..f3b76405d 100644 --- a/dist/lib/ast/transform/rotate.js +++ b/dist/src/lib/ast/transform/rotate.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply } from './utils.js'; /** diff --git a/dist/lib/ast/transform/scale.js b/dist/src/lib/ast/transform/scale.js similarity index 85% rename from dist/lib/ast/transform/scale.js rename to dist/src/lib/ast/transform/scale.js index b83072c51..ad41c8049 100644 --- a/dist/lib/ast/transform/scale.js +++ b/dist/src/lib/ast/transform/scale.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply } from './utils.js'; function scaleX(x, from) { diff --git a/dist/lib/ast/transform/skew.js b/dist/src/lib/ast/transform/skew.js similarity index 81% rename from dist/lib/ast/transform/skew.js rename to dist/src/lib/ast/transform/skew.js index c15baa38d..079cf49ae 100644 --- a/dist/lib/ast/transform/skew.js +++ b/dist/src/lib/ast/transform/skew.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply } from './utils.js'; function skewX(x, from) { diff --git a/dist/lib/ast/transform/translate.js b/dist/src/lib/ast/transform/translate.js similarity index 87% rename from dist/lib/ast/transform/translate.js rename to dist/src/lib/ast/transform/translate.js index 9ec60679e..50963647d 100644 --- a/dist/lib/ast/transform/translate.js +++ b/dist/src/lib/ast/transform/translate.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { identity, multiply } from './utils.js'; function translateX(x, from) { diff --git a/dist/lib/ast/transform/utils.js b/dist/src/lib/ast/transform/utils.js similarity index 98% rename from dist/lib/ast/transform/utils.js rename to dist/src/lib/ast/transform/utils.js index f1aed605f..bcec65fe0 100644 --- a/dist/lib/ast/transform/utils.js +++ b/dist/src/lib/ast/transform/utils.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { epsilon } from '../../syntax/constants.js'; const identityMatrix = new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); diff --git a/dist/lib/ast/types.js b/dist/src/lib/ast/types.js similarity index 99% rename from dist/lib/ast/types.js rename to dist/src/lib/ast/types.js index 0429e5519..7ebb73a82 100644 --- a/dist/lib/ast/types.js +++ b/dist/src/lib/ast/types.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * Syntax validation enum */ @@ -541,7 +548,7 @@ var EnumToken; /** * '|' */ - EnumToken[EnumToken["Pipe"] = 109] = "Pipe"; + EnumToken[EnumToken["PipeTokenType"] = 109] = "PipeTokenType"; /** * '::' */ @@ -680,6 +687,10 @@ var EnumToken; * negative infinity token */ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType"; + /** + * CSS type token + */ + EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType"; /* aliases */ /** * alias for time token type diff --git a/dist/lib/ast/walk.js b/dist/src/lib/ast/walk.js similarity index 99% rename from dist/lib/ast/walk.js rename to dist/src/lib/ast/walk.js index 8da3b5038..45bc0f54e 100644 --- a/dist/lib/ast/walk.js +++ b/dist/src/lib/ast/walk.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { PARENT, TOKENS } from '../syntax/constants.js'; /** diff --git a/dist/lib/fs/resolve.js b/dist/src/lib/fs/resolve.js similarity index 97% rename from dist/lib/fs/resolve.js rename to dist/src/lib/fs/resolve.js index ea3627500..be4068e3f 100644 --- a/dist/lib/fs/resolve.js +++ b/dist/src/lib/fs/resolve.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { memoize } from '../parser/utils/cache.js'; /** diff --git a/dist/lib/parser/declaration/list.js b/dist/src/lib/parser/declaration/list.js similarity index 98% rename from dist/lib/parser/declaration/list.js rename to dist/src/lib/parser/declaration/list.js index dba6678bb..30a01767c 100644 --- a/dist/lib/parser/declaration/list.js +++ b/dist/src/lib/parser/declaration/list.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { PropertySet } from './set.js'; import { getConfig } from '../utils/config.js'; import { PropertyMap } from './map.js'; diff --git a/dist/lib/parser/declaration/map.js b/dist/src/lib/parser/declaration/map.js similarity index 99% rename from dist/lib/parser/declaration/map.js rename to dist/src/lib/parser/declaration/map.js index f1447261c..e22a1002d 100644 --- a/dist/lib/parser/declaration/map.js +++ b/dist/src/lib/parser/declaration/map.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { eq } from '../utils/eq.js'; import { getConfig } from '../utils/config.js'; import { matchType } from '../utils/type.js'; diff --git a/dist/lib/parser/declaration/set.js b/dist/src/lib/parser/declaration/set.js similarity index 98% rename from dist/lib/parser/declaration/set.js rename to dist/src/lib/parser/declaration/set.js index 8cc9b30d8..925fca65c 100644 --- a/dist/lib/parser/declaration/set.js +++ b/dist/src/lib/parser/declaration/set.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { eq } from '../utils/eq.js'; import { EnumToken } from '../../ast/types.js'; import { isLength } from '../../syntax/syntax.js'; diff --git a/dist/lib/parser/linesmap.js b/dist/src/lib/parser/linesmap.js similarity index 92% rename from dist/lib/parser/linesmap.js rename to dist/src/lib/parser/linesmap.js index 4212e077b..e43c9858b 100644 --- a/dist/lib/parser/linesmap.js +++ b/dist/src/lib/parser/linesmap.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * Compute line and column of the offset */ diff --git a/dist/lib/parser/parse.js b/dist/src/lib/parser/parse.js similarity index 98% rename from dist/lib/parser/parse.js rename to dist/src/lib/parser/parse.js index 2a527cf33..701bbdc9f 100644 --- a/dist/lib/parser/parse.js +++ b/dist/src/lib/parser/parse.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js'; import { camelize, equalsIgnoreCase, dasherize } from './utils/text.js'; import { renderValue } from '../printer/render.js'; @@ -304,6 +311,9 @@ function parseVisitors(visitorsDef, errors) { let key; let value; let i; + const allVisitorsHandlers = new Set(); + const preAllVisitorsHandlers = new Set(); + const postAllVisitorsHandlers = new Set(); const valuesHandlers = new Map(); const preValuesHandlers = new Map(); const postValuesHandlers = new Map(); @@ -404,6 +414,21 @@ function parseVisitors(visitorsDef, errors) { errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } } + else if (key == "All" || key == "visitor") { + if (typeof value == "function") { + allVisitorsHandlers.add(value); + } + else if (typeof value == "object") { + if ("type" in value && "handler" in value && value.type in WalkerEvent) { + if (value.type == WalkerEvent.Enter) { + preAllVisitorsHandlers.add(value.handler); + } + else if (value.type == WalkerEvent.Leave) { + postAllVisitorsHandlers.add(value.handler); + } + } + } + } else { errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` }); } @@ -427,10 +452,25 @@ function parseVisitors(visitorsDef, errors) { if (postValuesHandlers.size > 0) { allHandlers.push(postValuesHandlers); } - return { + const result = { allHandlers, - includeTokens: preValuesHandlers.size > 0 || valuesHandlers.size > 0 || postValuesHandlers.size > 0, + includeTokens: preValuesHandlers.size > 0 || + valuesHandlers.size > 0 || + postValuesHandlers.size > 0 || + allVisitorsHandlers.size > 0 || + preAllVisitorsHandlers.size > 0 || + postAllVisitorsHandlers.size > 0, }; + if (allVisitorsHandlers.size > 0) { + result.allVisitorsHandlers = allVisitorsHandlers; + } + if (preAllVisitorsHandlers.size > 0) { + result.preAllVisitorsHandlers = preAllVisitorsHandlers; + } + if (postAllVisitorsHandlers.size > 0) { + result.postAllVisitorsHandlers = postAllVisitorsHandlers; + } + return result; } /** * Parse css string @@ -503,12 +543,10 @@ function doParseSync(tokenizer, options = {}) { // @ts-ignore ignore error let parensMatch = 0; let curlyBracketMatch = 0; - // let currentItemIndex: number; ast[LOCSRCID] = options.source.id; ast[LOCSTA] = 0; while (!tokenizer.done()) { tokenizer.next(); - // item = (iter as Array)[currentItemIndex]; if (tokenizer.unit != null) { item = { typ: tokenizer.typ, @@ -654,7 +692,6 @@ function doParseSync(tokenizer, options = {}) { parensMatch = 0; curlyBracketMatch = 0; } - // } } if (tokens.length > 0) { node = parseNode(tokens, context, options, errors, stats, invalidNodes); @@ -724,6 +761,9 @@ function doParseSync(tokenizer, options = {}) { } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == EnumToken.DeclarationNodeType ? "Declaration" @@ -743,6 +783,9 @@ function doParseSync(tokenizer, options = {}) { : nodes[i].typ == EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -751,20 +794,6 @@ function doParseSync(tokenizer, options = {}) { if (typeof handler == "function") { handlers.push(handler); } - // else if (Array.isArray(handler)) { - // for (const h of handler) { - // if (typeof h == "function") { - // handlers.push(h); - // } - // // @ts-ignore - // else if (h[keyName] != null) { - // // @ts-ignore - // handlers.push(h[keyName]); - // } - // } - // } else if (typeof handler.handler! == "function") { - // handlers.push(handler.handler); - // } // @ts-ignore else if (typeof handler[keyName] == "function") { // @ts-ignore @@ -797,6 +826,9 @@ function doParseSync(tokenizer, options = {}) { } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -1716,6 +1748,9 @@ async function doParse(iter, options = {}) { } parens = null; handlers.length = 0; + if (visitors.preAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.preAllVisitorsHandlers); + } genericKey = nodes[i].typ == EnumToken.DeclarationNodeType ? "Declaration" @@ -1735,6 +1770,9 @@ async function doParse(iter, options = {}) { : nodes[i].typ == EnumToken.KeyframesAtRuleNodeType ? camelize(nodes[i].val) : null; + if (visitors.allVisitorsHandlers?.size > 0) { + handlers.push(...visitors.allVisitorsHandlers); + } for (const map of visitors.allHandlers) { // @ts-ignore if (genericKey != null && map.has(genericKey)) { @@ -1789,6 +1827,9 @@ async function doParse(iter, options = {}) { } } } + if (visitors.postAllVisitorsHandlers?.size > 0) { + handlers.push(...visitors.postAllVisitorsHandlers); + } if (handlers.length == 0) { continue; } @@ -2649,7 +2690,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { const syntax = syntaxRules?.getPreludeRules()?.slice?.(1); const blockAllowed = syntaxRules?.getBlockRules() != null; if (syntaxRules == null) { - // if (!options.lenient) { errors.push({ action: "drop", node: atRule, @@ -3366,7 +3406,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) { stream[index][LOCEND] = stream[i][LOCEND]; Object.assign(stream[index], { typ: tokensfuncDefMap.get(stream[index].typ), - chi: stream.splice(index + 1, i - index - 1), + chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)), }); i = index; stream.splice(index + 1, 1); diff --git a/dist/lib/parser/source.js b/dist/src/lib/parser/source.js similarity index 94% rename from dist/lib/parser/source.js rename to dist/src/lib/parser/source.js index 6736612ba..0ac41f39d 100644 --- a/dist/lib/parser/source.js +++ b/dist/src/lib/parser/source.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { SourceMap } from '../printer/sourcemap/sourcemap.js'; import { LineMap } from './linesmap.js'; diff --git a/dist/lib/parser/tokenize.js b/dist/src/lib/parser/tokenize.js similarity index 98% rename from dist/lib/parser/tokenize.js rename to dist/src/lib/parser/tokenize.js index 3abc35c43..2fa9b2590 100644 --- a/dist/lib/parser/tokenize.js +++ b/dist/src/lib/parser/tokenize.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, ColorType } from '../ast/types.js'; import { wildCardFuncs, whenElseFunc, mathFuncs, timingFunc, supportFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc, colorsFunc, transformFunctions, pseudoElements } from '../syntax/constants.js'; import { isWhiteSpace, isNewLine, isDigit, isLetter, isIdentStart, isIdentCodepoint, isNonPrintable, timeUnits, angleUnits, flexUnits, dimensionUnits, resolutionUnits, frequencyUnits } from '../syntax/syntax.js'; @@ -41,7 +48,7 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) { SymbolsMapTokens[""] = EnumToken.DelimTokenType; SymbolsMapTokens["+"] = EnumToken.Plus; SymbolsMapTokens["="] = EnumToken.DelimTokenType; -SymbolsMapTokens["|"] = EnumToken.Pipe; +SymbolsMapTokens["|"] = EnumToken.PipeTokenType; SymbolsMapTokens["||"] = EnumToken.ColumnCombinatorTokenType; SymbolsMapTokens["|="] = EnumToken.DashMatchTokenType; SymbolsMapTokens["&"] = EnumToken.NestingSelectorTokenType; @@ -700,7 +707,6 @@ class Tokenizer { if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) { // eof if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) { - // this.next(parseInfo, position); return 0; } // \n \r \f \v @@ -1473,7 +1479,7 @@ class Tokenizer { return this.makeToken(parseInfo, EnumToken.DashMatchTokenType); } this.advance(parseInfo); - return this.makeToken(parseInfo, EnumToken.Pipe); + return this.makeToken(parseInfo, EnumToken.PipeTokenType); case 33 /* TokenMap.EXCLAMATION */: if (parseInfo.position < parseInfo.currentPosition) { return this.makeToken(parseInfo); @@ -1539,6 +1545,21 @@ class Tokenizer { return this.makeToken(parseInfo, EnumToken.CDOCOMMTokenType); } } + { + const startPosition = parseInfo.position - parseInfo.offset; + let offset = 1; + let charCode = parseInfo.stream.charCodeAt(startPosition + offset); + if (isLetter(charCode)) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) { + charCode = parseInfo.stream.charCodeAt(++offset + startPosition); + } + if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) { + this.advance(parseInfo, offset); + return this.makeToken(parseInfo, EnumToken.CssTypeTokenType); + } + } + } break; case 35 /* TokenMap.HASH */: if (parseInfo.position < parseInfo.currentPosition) { diff --git a/dist/lib/parser/utils/angle.js b/dist/src/lib/parser/utils/angle.js similarity index 83% rename from dist/lib/parser/utils/angle.js rename to dist/src/lib/parser/utils/angle.js index 262a2ac7c..f22b5a5c1 100644 --- a/dist/lib/parser/utils/angle.js +++ b/dist/src/lib/parser/utils/angle.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * convert angle to degrees * @param angle diff --git a/dist/lib/parser/utils/at-rule-container.js b/dist/src/lib/parser/utils/at-rule-container.js similarity index 99% rename from dist/lib/parser/utils/at-rule-container.js rename to dist/src/lib/parser/utils/at-rule-container.js index 18d5863ca..acb720ba6 100644 --- a/dist/lib/parser/utils/at-rule-container.js +++ b/dist/src/lib/parser/utils/at-rule-container.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { tokensfuncDefMap, LOCSTA, mFGT, mFLT, LOCEND, LOCSRCID } from '../../syntax/constants.js'; import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js'; diff --git a/dist/lib/parser/utils/at-rule-font-feature-values.js b/dist/src/lib/parser/utils/at-rule-font-feature-values.js similarity index 84% rename from dist/lib/parser/utils/at-rule-font-feature-values.js rename to dist/src/lib/parser/utils/at-rule-font-feature-values.js index 128792187..dd16cbc91 100644 --- a/dist/lib/parser/utils/at-rule-font-feature-values.js +++ b/dist/src/lib/parser/utils/at-rule-font-feature-values.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getSyntaxRule } from '../../validation/config.js'; import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js'; import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js'; diff --git a/dist/lib/parser/utils/at-rule-generic.js b/dist/src/lib/parser/utils/at-rule-generic.js similarity index 96% rename from dist/lib/parser/utils/at-rule-generic.js rename to dist/src/lib/parser/utils/at-rule-generic.js index 56f49e133..9e43a706a 100644 --- a/dist/lib/parser/utils/at-rule-generic.js +++ b/dist/src/lib/parser/utils/at-rule-generic.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { tokensfuncDefMap, LOCSTA } from '../../syntax/constants.js'; import { equalsIgnoreCase } from './text.js'; diff --git a/dist/lib/parser/utils/at-rule-import.js b/dist/src/lib/parser/utils/at-rule-import.js similarity index 98% rename from dist/lib/parser/utils/at-rule-import.js rename to dist/src/lib/parser/utils/at-rule-import.js index 69c216748..2585f66ed 100644 --- a/dist/lib/parser/utils/at-rule-import.js +++ b/dist/src/lib/parser/utils/at-rule-import.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { getSyntaxRule } from '../../validation/config.js'; import { trimArray } from '../../validation/match.js'; diff --git a/dist/lib/parser/utils/at-rule-media.js b/dist/src/lib/parser/utils/at-rule-media.js similarity index 99% rename from dist/lib/parser/utils/at-rule-media.js rename to dist/src/lib/parser/utils/at-rule-media.js index c589e3aa4..d133c9b09 100644 --- a/dist/lib/parser/utils/at-rule-media.js +++ b/dist/src/lib/parser/utils/at-rule-media.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { evaluate } from '../../ast/math/expression.js'; import { gcd } from '../../ast/math/math.js'; diff --git a/dist/lib/parser/utils/at-rule-support.js b/dist/src/lib/parser/utils/at-rule-support.js similarity index 98% rename from dist/lib/parser/utils/at-rule-support.js rename to dist/src/lib/parser/utils/at-rule-support.js index 9751c7d57..08a0107bc 100644 --- a/dist/lib/parser/utils/at-rule-support.js +++ b/dist/src/lib/parser/utils/at-rule-support.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { pseudoElements, LOCEND, tokensfuncDefMap, LOCSTA, LOCSRCID } from '../../syntax/constants.js'; import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js'; diff --git a/dist/lib/parser/utils/at-rule-when-else.js b/dist/src/lib/parser/utils/at-rule-when-else.js similarity index 97% rename from dist/lib/parser/utils/at-rule-when-else.js rename to dist/src/lib/parser/utils/at-rule-when-else.js index c055637f6..b8a8674b3 100644 --- a/dist/lib/parser/utils/at-rule-when-else.js +++ b/dist/src/lib/parser/utils/at-rule-when-else.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { trimArray } from '../../validation/match.js'; import { tokensfuncDefMap, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js'; diff --git a/dist/lib/parser/utils/at-rule.js b/dist/src/lib/parser/utils/at-rule.js similarity index 85% rename from dist/lib/parser/utils/at-rule.js rename to dist/src/lib/parser/utils/at-rule.js index 8d7594614..7e834477c 100644 --- a/dist/lib/parser/utils/at-rule.js +++ b/dist/src/lib/parser/utils/at-rule.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js'; import { getSyntaxRule } from '../../validation/config.js'; import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js'; diff --git a/dist/lib/parser/utils/base64.js b/dist/src/lib/parser/utils/base64.js similarity index 65% rename from dist/lib/parser/utils/base64.js rename to dist/src/lib/parser/utils/base64.js index 6e9ccb0de..870c7ef8d 100644 --- a/dist/lib/parser/utils/base64.js +++ b/dist/src/lib/parser/utils/base64.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * * @param value diff --git a/dist/lib/parser/utils/cache.js b/dist/src/lib/parser/utils/cache.js similarity index 90% rename from dist/lib/parser/utils/cache.js rename to dist/src/lib/parser/utils/cache.js index a468c06ec..41923d323 100644 --- a/dist/lib/parser/utils/cache.js +++ b/dist/src/lib/parser/utils/cache.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * * @param fn diff --git a/dist/lib/parser/utils/config.js b/dist/src/lib/parser/utils/config.js similarity index 55% rename from dist/lib/parser/utils/config.js rename to dist/src/lib/parser/utils/config.js index 0c8a26ee3..c1023ca5f 100644 --- a/dist/lib/parser/utils/config.js +++ b/dist/src/lib/parser/utils/config.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import config from '../../../data/properties.json.js'; Object.freeze(config); diff --git a/dist/lib/parser/utils/declaration.js b/dist/src/lib/parser/utils/declaration.js similarity index 99% rename from dist/lib/parser/utils/declaration.js rename to dist/src/lib/parser/utils/declaration.js index f3e6e484d..934d65e80 100644 --- a/dist/lib/parser/utils/declaration.js +++ b/dist/src/lib/parser/utils/declaration.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, EnumAstNodeStatus, ColorType } from '../../ast/types.js'; import { LOCEND, STATE, ERRORS, LOCSTA, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace, LOCSRCID } from '../../syntax/constants.js'; import { renamedStandardProperties, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js'; diff --git a/dist/lib/parser/utils/eq.js b/dist/src/lib/parser/utils/eq.js similarity index 87% rename from dist/lib/parser/utils/eq.js rename to dist/src/lib/parser/utils/eq.js index 6fccf5fd6..17d1e2937 100644 --- a/dist/lib/parser/utils/eq.js +++ b/dist/src/lib/parser/utils/eq.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * * @param a diff --git a/dist/lib/parser/utils/hash.js b/dist/src/lib/parser/utils/hash.js similarity index 97% rename from dist/lib/parser/utils/hash.js rename to dist/src/lib/parser/utils/hash.js index 71115e663..1c87f8465 100644 --- a/dist/lib/parser/utils/hash.js +++ b/dist/src/lib/parser/utils/hash.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ // Alphabet: a-z, A-Z, 0-9, _, - const LOWER = "abcdefghijklmnopqrstuvwxyz"; const DIGITS = "0123456789"; diff --git a/dist/lib/parser/utils/selector.js b/dist/src/lib/parser/utils/selector.js similarity index 99% rename from dist/lib/parser/utils/selector.js rename to dist/src/lib/parser/utils/selector.js index 3b28a731c..987ba86b7 100644 --- a/dist/lib/parser/utils/selector.js +++ b/dist/src/lib/parser/utils/selector.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js'; import { renderValue } from '../../printer/render.js'; import { LOCEND, LOCSTA, LOCSRCID, ERRORS, STATE, TOKENS, pseudoElements, combinators, tokensfuncDefMap, PARENT } from '../../syntax/constants.js'; diff --git a/dist/lib/parser/utils/text.js b/dist/src/lib/parser/utils/text.js similarity index 86% rename from dist/lib/parser/utils/text.js rename to dist/src/lib/parser/utils/text.js index db394c89f..13ab0b25c 100644 --- a/dist/lib/parser/utils/text.js +++ b/dist/src/lib/parser/utils/text.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * * @param value diff --git a/dist/lib/parser/utils/token.js b/dist/src/lib/parser/utils/token.js similarity index 91% rename from dist/lib/parser/utils/token.js rename to dist/src/lib/parser/utils/token.js index 00bae0e2c..ac8e51db0 100644 --- a/dist/lib/parser/utils/token.js +++ b/dist/src/lib/parser/utils/token.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { PARENT, tokensfuncSet } from '../../syntax/constants.js'; @@ -9,12 +16,15 @@ const trimTokenSpace = new Set([ EnumToken.LtTokenType, EnumToken.LteTokenType, EnumToken.ChildCombinatorTokenType, + EnumToken.PipeTokenType, ]); const trimSpaceAfter = new Set([ ...tokensfuncSet.values(), EnumToken.ChildCombinatorTokenType, EnumToken.SupportsQueryConditionTokenType, EnumToken.SupportsQueryUnaryConditionTokenType, + EnumToken.CommaTokenType, + EnumToken.PipeTokenType, ]); /** * Replace token in its parent node @@ -84,17 +94,18 @@ function trimWhiteSpaceTokens(tokens) { return tokens; } for (; i < tokens.length; i++) { - if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) { - tokens.splice(i + 1, 1); - } - else if (trimTokenSpace.has(tokens[i].typ)) { + if (trimTokenSpace.has(tokens[i].typ)) { if (tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) { tokens.splice(i + 1, 1); } if (i > 0 && tokens[i - 1].typ === EnumToken.Whitespace) { tokens.splice(--i, 1); + continue; } } + if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) { + tokens.splice(i + 1, 1); + } } return tokens; } diff --git a/dist/lib/parser/utils/type.js b/dist/src/lib/parser/utils/type.js similarity index 93% rename from dist/lib/parser/utils/type.js rename to dist/src/lib/parser/utils/type.js index 23ba6c185..6965a3b69 100644 --- a/dist/lib/parser/utils/type.js +++ b/dist/src/lib/parser/utils/type.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { tokensfuncSet } from '../../syntax/constants.js'; import { isColor } from '../../syntax/syntax.js'; diff --git a/dist/lib/printer/render.js b/dist/src/lib/printer/render.js similarity index 99% rename from dist/lib/printer/render.js rename to dist/src/lib/printer/render.js index de5b68993..c2409d296 100644 --- a/dist/lib/printer/render.js +++ b/dist/src/lib/printer/render.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { convertColor, getAngle } from '../syntax/color/color.js'; import { reduceHexValue } from '../syntax/color/hex.js'; import { EnumToken, ColorType } from '../ast/types.js'; @@ -1128,7 +1135,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, return ","; case EnumToken.ImportantTokenType: return "!important"; - case EnumToken.Pipe: + case EnumToken.PipeTokenType: return "|"; case EnumToken.AttrTokenType: case EnumToken.IdenListTokenType: @@ -1251,6 +1258,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer, pseudoElements.includes(token.val.slice(1))) { return token.val.slice(1); } + case EnumToken.CssTypeTokenType: case EnumToken.UrlTokenTokenType: case EnumToken.HashTokenType: case EnumToken.IdenTokenType: diff --git a/dist/lib/printer/sourcemap/lib/codec.js b/dist/src/lib/printer/sourcemap/lib/codec.js similarity index 93% rename from dist/lib/printer/sourcemap/lib/codec.js rename to dist/src/lib/printer/sourcemap/lib/codec.js index baa8bad64..1a0656563 100644 --- a/dist/lib/printer/sourcemap/lib/codec.js +++ b/dist/src/lib/printer/sourcemap/lib/codec.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ // from https://github.com/Rich-Harris/vlq/tree/master // credit: Rich Harris const integer_to_char = {}; diff --git a/dist/lib/printer/sourcemap/sourcemap.js b/dist/src/lib/printer/sourcemap/sourcemap.js similarity index 98% rename from dist/lib/printer/sourcemap/sourcemap.js rename to dist/src/lib/printer/sourcemap/sourcemap.js index 3cc7aac8e..a624fea12 100644 --- a/dist/lib/printer/sourcemap/sourcemap.js +++ b/dist/src/lib/printer/sourcemap/sourcemap.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { toBase64 } from '../../parser/utils/base64.js'; import { decode, encode } from './lib/codec.js'; diff --git a/dist/lib/syntax/color/a98rgb.js b/dist/src/lib/syntax/color/a98rgb.js similarity index 95% rename from dist/lib/syntax/color/a98rgb.js rename to dist/src/lib/syntax/color/a98rgb.js index 1b5ada0af..e4fe75c50 100644 --- a/dist/lib/syntax/color/a98rgb.js +++ b/dist/src/lib/syntax/color/a98rgb.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { xyz2srgb } from './srgb.js'; import { multiplyMatrices } from './utils/matrix.js'; import { srgb2xyz } from './xyz.js'; diff --git a/dist/lib/syntax/color/alpha.js b/dist/src/lib/syntax/color/alpha.js similarity index 96% rename from dist/lib/syntax/color/alpha.js rename to dist/src/lib/syntax/color/alpha.js index d85237b70..018757a09 100644 --- a/dist/lib/syntax/color/alpha.js +++ b/dist/src/lib/syntax/color/alpha.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ColorType, EnumToken } from '../../ast/types.js'; import { convertColor } from './color.js'; import { getColorComponents } from './utils/components.js'; diff --git a/dist/lib/syntax/color/cmyk.js b/dist/src/lib/syntax/color/cmyk.js similarity index 96% rename from dist/lib/syntax/color/cmyk.js rename to dist/src/lib/syntax/color/cmyk.js index 935e31733..b7ffc08ad 100644 --- a/dist/lib/syntax/color/cmyk.js +++ b/dist/src/lib/syntax/color/cmyk.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ColorType, EnumToken } from '../../ast/types.js'; import { color2srgbvalues } from './color.js'; import { lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, hwb2srgbvalues, rgb2srgbvalues } from './srgb.js'; diff --git a/dist/lib/syntax/color/color-mix.js b/dist/src/lib/syntax/color/color-mix.js similarity index 99% rename from dist/lib/syntax/color/color-mix.js rename to dist/src/lib/syntax/color/color-mix.js index b48ff7d27..d68029c47 100644 --- a/dist/lib/syntax/color/color-mix.js +++ b/dist/src/lib/syntax/color/color-mix.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js'; import { minmax, getNumber } from './color.js'; import { srgbvalues, srgb2lsrgbvalues, hslvalues } from './srgb.js'; diff --git a/dist/lib/syntax/color/color.js b/dist/src/lib/syntax/color/color.js similarity index 99% rename from dist/lib/syntax/color/color.js rename to dist/src/lib/syntax/color/color.js index b1fdfaae7..23701e758 100644 --- a/dist/lib/syntax/color/color.js +++ b/dist/src/lib/syntax/color/color.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ColorType, EnumToken } from '../../ast/types.js'; import { color2RgbToken, lch2RgbToken, lab2RgbToken, oklch2RgbToken, oklab2RgbToken, cmyk2RgbToken, hwb2RgbToken, hsl2RgbToken, hex2RgbToken } from './rgb.js'; import { color2HslToken, lch2HslToken, lab2HslToken, oklch2HslToken, oklab2HslToken, cmyk2HslToken, hwb2HslToken, hex2HslToken, rgb2HslToken } from './hsl.js'; diff --git a/dist/lib/syntax/color/hex.js b/dist/src/lib/syntax/color/hex.js similarity index 97% rename from dist/lib/syntax/color/hex.js rename to dist/src/lib/syntax/color/hex.js index 6fdc2bc42..dd1707fc7 100644 --- a/dist/lib/syntax/color/hex.js +++ b/dist/src/lib/syntax/color/hex.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, ColorType } from '../../ast/types.js'; import { color2srgbvalues, getNumber } from './color.js'; import { srgb2rgb, cmyk2rgbvalues, hwb2rgbvalues, hsl2rgbvalues } from './rgb.js'; diff --git a/dist/lib/syntax/color/hsl.js b/dist/src/lib/syntax/color/hsl.js similarity index 98% rename from dist/lib/syntax/color/hsl.js rename to dist/src/lib/syntax/color/hsl.js index 3ead52059..2e317c5e1 100644 --- a/dist/lib/syntax/color/hsl.js +++ b/dist/src/lib/syntax/color/hsl.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { color2srgbvalues, getNumber } from './color.js'; import { lch2rgbvalues, lab2rgbvalues, cmyk2rgbvalues } from './rgb.js'; import { getColorComponents } from './utils/components.js'; diff --git a/dist/lib/syntax/color/hwb.js b/dist/src/lib/syntax/color/hwb.js similarity index 98% rename from dist/lib/syntax/color/hwb.js rename to dist/src/lib/syntax/color/hwb.js index 6d87ef65c..5669d153c 100644 --- a/dist/lib/syntax/color/hwb.js +++ b/dist/src/lib/syntax/color/hwb.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getColorComponents } from './utils/components.js'; import { color2srgbvalues, getNumber, getAngle } from './color.js'; import { EnumToken, ColorType } from '../../ast/types.js'; diff --git a/dist/lib/syntax/color/lab.js b/dist/src/lib/syntax/color/lab.js similarity index 98% rename from dist/lib/syntax/color/lab.js rename to dist/src/lib/syntax/color/lab.js index 72da31a65..fad2c18db 100644 --- a/dist/lib/syntax/color/lab.js +++ b/dist/src/lib/syntax/color/lab.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { e, k, D50 } from '../constants.js'; import { getColorComponents } from './utils/components.js'; import { srgb2xyz_d65, XYZ_D50_to_D65 } from './xyz.js'; diff --git a/dist/lib/syntax/color/lch.js b/dist/src/lib/syntax/color/lch.js similarity index 98% rename from dist/lib/syntax/color/lch.js rename to dist/src/lib/syntax/color/lch.js index 65017d2c4..897f17ee9 100644 --- a/dist/lib/syntax/color/lch.js +++ b/dist/src/lib/syntax/color/lch.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getColorComponents } from './utils/components.js'; import { color2srgbvalues, getNumber, getAngle } from './color.js'; import { EnumToken, ColorType } from '../../ast/types.js'; diff --git a/dist/lib/syntax/color/oklab.js b/dist/src/lib/syntax/color/oklab.js similarity index 98% rename from dist/lib/syntax/color/oklab.js rename to dist/src/lib/syntax/color/oklab.js index c41e53ad6..12ed73c6b 100644 --- a/dist/lib/syntax/color/oklab.js +++ b/dist/src/lib/syntax/color/oklab.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getColorComponents } from './utils/components.js'; import { multiplyMatrices } from './utils/matrix.js'; import { srgb2lsrgbvalues, lch2srgbvalues, lab2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues, hsl2srgb, rgb2srgb, hex2srgbvalues, lsrgb2srgbvalues } from './srgb.js'; diff --git a/dist/lib/syntax/color/oklch.js b/dist/src/lib/syntax/color/oklch.js similarity index 97% rename from dist/lib/syntax/color/oklch.js rename to dist/src/lib/syntax/color/oklch.js index 063fc8345..ed9d491b9 100644 --- a/dist/lib/syntax/color/oklch.js +++ b/dist/src/lib/syntax/color/oklch.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getColorComponents } from './utils/components.js'; import { color2srgbvalues, getNumber, getAngle } from './color.js'; import { EnumToken, ColorType } from '../../ast/types.js'; diff --git a/dist/lib/syntax/color/p3.js b/dist/src/lib/syntax/color/p3.js similarity index 95% rename from dist/lib/syntax/color/p3.js rename to dist/src/lib/syntax/color/p3.js index ead5bc02b..f995b89ce 100644 --- a/dist/lib/syntax/color/p3.js +++ b/dist/src/lib/syntax/color/p3.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { lsrgb2srgbvalues, xyz2srgb, srgb2lsrgbvalues } from './srgb.js'; import { multiplyMatrices } from './utils/matrix.js'; import { srgb2xyz } from './xyz.js'; diff --git a/dist/lib/syntax/color/prophotorgb.js b/dist/src/lib/syntax/color/prophotorgb.js similarity index 93% rename from dist/lib/syntax/color/prophotorgb.js rename to dist/src/lib/syntax/color/prophotorgb.js index 1044619d3..98e57c221 100644 --- a/dist/lib/syntax/color/prophotorgb.js +++ b/dist/src/lib/syntax/color/prophotorgb.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js'; import { srgb2xyz } from './xyz.js'; diff --git a/dist/lib/syntax/color/rec2020.js b/dist/src/lib/syntax/color/rec2020.js similarity index 95% rename from dist/lib/syntax/color/rec2020.js rename to dist/src/lib/syntax/color/rec2020.js index 49d7e49e9..dde0c4824 100644 --- a/dist/lib/syntax/color/rec2020.js +++ b/dist/src/lib/syntax/color/rec2020.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { xyz2srgb } from './srgb.js'; import { multiplyMatrices } from './utils/matrix.js'; import { srgb2xyz } from './xyz.js'; diff --git a/dist/lib/syntax/color/relative-color.js b/dist/src/lib/syntax/color/relative-color.js similarity index 98% rename from dist/lib/syntax/color/relative-color.js rename to dist/src/lib/syntax/color/relative-color.js index 8caadfe44..81a883974 100644 --- a/dist/lib/syntax/color/relative-color.js +++ b/dist/src/lib/syntax/color/relative-color.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { convertColor, getNumber } from './color.js'; import { EnumToken, ColorType } from '../../ast/types.js'; import { walkValues } from '../../ast/walk.js'; diff --git a/dist/lib/syntax/color/rgb.js b/dist/src/lib/syntax/color/rgb.js similarity index 97% rename from dist/lib/syntax/color/rgb.js rename to dist/src/lib/syntax/color/rgb.js index 24b6a5c85..49e935b18 100644 --- a/dist/lib/syntax/color/rgb.js +++ b/dist/src/lib/syntax/color/rgb.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { color2srgbvalues, minmax } from './color.js'; import { expandHexValue } from './hex.js'; import { hslvalues, hslvalues2srgbvalues, lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues } from './srgb.js'; diff --git a/dist/lib/syntax/color/srgb.js b/dist/src/lib/syntax/color/srgb.js similarity index 98% rename from dist/lib/syntax/color/srgb.js rename to dist/src/lib/syntax/color/srgb.js index dfa99169a..be44568f2 100644 --- a/dist/lib/syntax/color/srgb.js +++ b/dist/src/lib/syntax/color/srgb.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getColorComponents } from './utils/components.js'; import { color2srgbvalues, getNumber, getAngle } from './color.js'; import { EnumToken, ColorType } from '../../ast/types.js'; diff --git a/dist/lib/syntax/color/utils/color-type.js b/dist/src/lib/syntax/color/utils/color-type.js similarity index 80% rename from dist/lib/syntax/color/utils/color-type.js rename to dist/src/lib/syntax/color/utils/color-type.js index bd065e219..9c79e36cc 100644 --- a/dist/lib/syntax/color/utils/color-type.js +++ b/dist/src/lib/syntax/color/utils/color-type.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ColorType } from '../../../ast/types.js'; /** diff --git a/dist/lib/syntax/color/utils/colorspace.js b/dist/src/lib/syntax/color/utils/colorspace.js similarity index 90% rename from dist/lib/syntax/color/utils/colorspace.js rename to dist/src/lib/syntax/color/utils/colorspace.js index b27d1343e..863697876 100644 --- a/dist/lib/syntax/color/utils/colorspace.js +++ b/dist/src/lib/syntax/color/utils/colorspace.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { equalsIgnoreCase } from '../../../parser/utils/text.js'; import { getColorComponents } from './components.js'; diff --git a/dist/lib/syntax/color/utils/components.js b/dist/src/lib/syntax/color/utils/components.js similarity index 92% rename from dist/lib/syntax/color/utils/components.js rename to dist/src/lib/syntax/color/utils/components.js index 2cd077053..9c8b3dc3b 100644 --- a/dist/lib/syntax/color/utils/components.js +++ b/dist/src/lib/syntax/color/utils/components.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { ColorType, EnumToken } from '../../../ast/types.js'; import { COLORS_NAMES } from '../../constants.js'; import { expandHexValue } from '../hex.js'; diff --git a/dist/lib/syntax/color/utils/distance.js b/dist/src/lib/syntax/color/utils/distance.js similarity index 93% rename from dist/lib/syntax/color/utils/distance.js rename to dist/src/lib/syntax/color/utils/distance.js index 74eca907e..dd345b615 100644 --- a/dist/lib/syntax/color/utils/distance.js +++ b/dist/src/lib/syntax/color/utils/distance.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { convertColor } from '../color.js'; import { getOKLABComponents } from '../oklab.js'; import { ColorType } from '../../../ast/types.js'; diff --git a/dist/lib/syntax/color/utils/make-color.js b/dist/src/lib/syntax/color/utils/make-color.js similarity index 93% rename from dist/lib/syntax/color/utils/make-color.js rename to dist/src/lib/syntax/color/utils/make-color.js index 27e61d9e1..c555264ac 100644 --- a/dist/lib/syntax/color/utils/make-color.js +++ b/dist/src/lib/syntax/color/utils/make-color.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken, ColorType } from '../../../ast/types.js'; import { equalsIgnoreCase } from '../../../parser/utils/text.js'; import { minmax, getNumber } from '../color.js'; diff --git a/dist/lib/syntax/color/utils/matrix.js b/dist/src/lib/syntax/color/utils/matrix.js similarity index 90% rename from dist/lib/syntax/color/utils/matrix.js rename to dist/src/lib/syntax/color/utils/matrix.js index a88e09943..ffa8f1709 100644 --- a/dist/lib/syntax/color/utils/matrix.js +++ b/dist/src/lib/syntax/color/utils/matrix.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ // from https://www.w3.org/TR/css-color-4/multiply-matrices.js /** * Simple matrix (and vector) multiplication diff --git a/dist/lib/syntax/color/xyz.js b/dist/src/lib/syntax/color/xyz.js similarity index 94% rename from dist/lib/syntax/color/xyz.js rename to dist/src/lib/syntax/color/xyz.js index c9fcfa883..6ac1eda87 100644 --- a/dist/lib/syntax/color/xyz.js +++ b/dist/src/lib/syntax/color/xyz.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { multiplyMatrices } from './utils/matrix.js'; import { srgb2lsrgbvalues } from './srgb.js'; import { XYZ_D65_to_D50 } from './xyzd50.js'; diff --git a/dist/lib/syntax/color/xyzd50.js b/dist/src/lib/syntax/color/xyzd50.js similarity index 92% rename from dist/lib/syntax/color/xyzd50.js rename to dist/src/lib/syntax/color/xyzd50.js index 0edcdce68..fbd8973d6 100644 --- a/dist/lib/syntax/color/xyzd50.js +++ b/dist/src/lib/syntax/color/xyzd50.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { lsrgb2srgbvalues } from './srgb.js'; import { multiplyMatrices } from './utils/matrix.js'; import { xyz2lab } from './lab.js'; diff --git a/dist/lib/syntax/constants.js b/dist/src/lib/syntax/constants.js similarity index 99% rename from dist/lib/syntax/constants.js rename to dist/src/lib/syntax/constants.js index e92ac312b..bb5adb3cf 100644 --- a/dist/lib/syntax/constants.js +++ b/dist/src/lib/syntax/constants.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../ast/types.js'; import config from '../../data/validation.json.js'; diff --git a/dist/lib/syntax/syntax.js b/dist/src/lib/syntax/syntax.js similarity index 99% rename from dist/lib/syntax/syntax.js rename to dist/src/lib/syntax/syntax.js index 4690cf7ce..849c7d8c3 100644 --- a/dist/lib/syntax/syntax.js +++ b/dist/src/lib/syntax/syntax.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { isOkLabClose } from './color/utils/distance.js'; import { EnumToken, ColorType } from '../ast/types.js'; import { walkValues, WalkerOptionEnum } from '../ast/walk.js'; diff --git a/dist/lib/validation/config.js b/dist/src/lib/validation/config.js similarity index 96% rename from dist/lib/validation/config.js rename to dist/src/lib/validation/config.js index b653d5296..1bf33b659 100644 --- a/dist/lib/validation/config.js +++ b/dist/src/lib/validation/config.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import config from '../../data/validation.json.js'; import { trimSyntaxArray, parseSyntax } from './parser/parse.js'; import { ValidationTokenEnum } from './parser/typedef.js'; diff --git a/dist/lib/validation/match.js b/dist/src/lib/validation/match.js similarity index 98% rename from dist/lib/validation/match.js rename to dist/src/lib/validation/match.js index fe0076b02..69cff96ea 100644 --- a/dist/lib/validation/match.js +++ b/dist/src/lib/validation/match.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { getParsedSyntax, getSyntaxConfig } from './config.js'; import { EnumToken } from '../ast/types.js'; import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js'; @@ -126,8 +133,7 @@ function isMFValue(featureName, tokens, isMFRange) { case MediaFeatureType.RatioType: return { valid: true, - success: (tokens.length == 1 && - tokens[0].typ == EnumToken.NumberTokenType) || + success: (tokens.length == 1 && tokens[0].typ == EnumToken.NumberTokenType) || (tokens.length === 3 && tokens[0].typ == EnumToken.NumberTokenType && typeof tokens[0].val === "number" && @@ -434,7 +440,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) { } stack.push(token); break; - case EnumToken.Pipe: + case EnumToken.PipeTokenType: case EnumToken.DelimTokenType: case EnumToken.StringTokenType: case EnumToken.IncludeMatchTokenType: @@ -482,10 +488,10 @@ function matchSelectorSyntax(stream, errors, options, nested = true) { } slice.push(tokens[n]); } - if (slice[1]?.typ === EnumToken.Pipe) { + if (slice[1]?.typ === EnumToken.PipeTokenType) { slice.shift(); } - if (slice[0].typ === EnumToken.Pipe) { + if (slice[0].typ === EnumToken.PipeTokenType) { slice.shift(); } if (slice.length === 1) { @@ -847,8 +853,8 @@ function matchSyntax(syntaxes, context, options) { // custom function token if (token.typ === EnumToken.CustomFunctionTokenDefType) { if (syntaxes[i].typ != ValidationTokenEnum.PropertyType || - syntaxes[i + 1].typ != ValidationTokenEnum.OpenParenthesis || - syntaxes[i + 2].typ == null) { + syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis || + syntaxes[i + 2]?.typ == null) { if (!isOptional) { return { success: false, @@ -1695,17 +1701,15 @@ function matchProperty(property, context, options) { case "display-internal": case "display-outside": case "display-legacy": - case "content-position": - { - let values = propertyKeywordValues.get(property.val); - if (values == null) { - values = new Set(config.syntaxes[property.val].syntax.split(/[\s|]+/)); - propertyKeywordValues.set(property.val, values); - } - success = - token?.typ == EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); - break; + case "content-position": { + let values = propertyKeywordValues.get(property.val); + if (values == null) { + values = new Set(config.syntaxes[property.val].syntax.split(/[\s|]+/)); + propertyKeywordValues.set(property.val, values); } + success = token?.typ == EnumToken.IdenTokenType && values.has(token.val.toLowerCase()); + break; + } case "mf-name": { const token = context.peek(); @@ -1725,8 +1729,7 @@ function matchProperty(property, context, options) { case "custom-ident": case "counter-name": case "counter-style-name": - success = - token?.typ == EnumToken.IdenTokenType || token?.typ == EnumToken.DashedIdenTokenType; + success = token?.typ == EnumToken.IdenTokenType || token?.typ == EnumToken.DashedIdenTokenType; if (success && token?.typ === EnumToken.IdenTokenType) { const val = token.val.toLowerCase(); success = "none" !== val && !allValues.includes(val); @@ -2197,6 +2200,21 @@ function matchProperty(property, context, options) { } break; } + case "css-type": { + success = context.peek()?.typ == EnumToken.CssTypeTokenType; + if (success) { + context.next(); + return { + success: true, + valid: true, + token: null, + context, + syntaxToken: null, + errors: [], + }; + } + break; + } default: if (!(property.val in config.syntaxes)) { console.debug("Unknown syntax", context.peek(), property); diff --git a/dist/lib/validation/parser/parse.js b/dist/src/lib/validation/parser/parse.js similarity index 99% rename from dist/lib/validation/parser/parse.js rename to dist/src/lib/validation/parser/parse.js index e4d640dad..615c19ce0 100644 --- a/dist/lib/validation/parser/parse.js +++ b/dist/src/lib/validation/parser/parse.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; import { isIdentStart, isIdent, parseDimension, isPseudo } from '../../syntax/syntax.js'; import { ValidationTokenEnum } from './typedef.js'; diff --git a/dist/lib/validation/parser/typedef.js b/dist/src/lib/validation/parser/typedef.js similarity index 97% rename from dist/lib/validation/parser/typedef.js rename to dist/src/lib/validation/parser/typedef.js index 54fa7e4ec..4ddbac08d 100644 --- a/dist/lib/validation/parser/typedef.js +++ b/dist/src/lib/validation/parser/typedef.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ var ValidationTokenEnum; (function (ValidationTokenEnum) { ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root"; diff --git a/dist/lib/validation/utils/list.js b/dist/src/lib/validation/utils/list.js similarity index 87% rename from dist/lib/validation/utils/list.js rename to dist/src/lib/validation/utils/list.js index f6b32f306..487ea934a 100644 --- a/dist/lib/validation/utils/list.js +++ b/dist/src/lib/validation/utils/list.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../../ast/types.js'; function stripCommaToken(tokenList) { diff --git a/dist/node.js b/dist/src/node.js similarity index 98% rename from dist/node.js rename to dist/src/node.js index c8740ff41..d54e607ac 100644 --- a/dist/node.js +++ b/dist/src/node.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { deprecate } from 'node:util'; import { Readable } from 'node:stream'; import { createReadStream } from 'node:fs'; @@ -26,6 +33,7 @@ export { replaceNodeOrValue } from './lib/parser/utils/token.js'; export { SourceMap } from './lib/printer/sourcemap/sourcemap.js'; export { FeatureWalkMode } from './lib/ast/features/type.js'; export { getNodeProperty, setNodeProperty } from './lib/ast/node.js'; +export { version } from '../package.json.js'; /** * Load file or url diff --git a/dist/types.js b/dist/src/types.js similarity index 81% rename from dist/types.js rename to dist/src/types.js index a4e528605..c725cb63a 100644 --- a/dist/types.js +++ b/dist/src/types.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ /** * response type */ diff --git a/dist/utils/sync.js b/dist/src/utils/sync.js similarity index 95% rename from dist/utils/sync.js rename to dist/src/utils/sync.js index beaf894d6..c6cfde1f6 100644 --- a/dist/utils/sync.js +++ b/dist/src/utils/sync.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { EnumToken } from '../lib/ast/types.js'; import { dirname } from '../lib/fs/resolve.js'; import { ResponseType } from '../types.js'; diff --git a/dist/web.js b/dist/src/web.js similarity index 98% rename from dist/web.js rename to dist/src/web.js index e3e3363d2..c2c9e84b1 100644 --- a/dist/web.js +++ b/dist/src/web.js @@ -1,3 +1,10 @@ +/* + CSS parser, minifier and validator for node and the browser + + Author(s): Thierry Bela + Version: 1.6.8 + License: MIT + */ import { doParse, doParseSync } from './lib/parser/parse.js'; export { parseDeclarations, parseString } from './lib/parser/parse.js'; import { doRender } from './lib/printer/render.js'; @@ -21,6 +28,7 @@ export { PropertyList } from './lib/parser/declaration/list.js'; export { SourceMap } from './lib/printer/sourcemap/sourcemap.js'; export { FeatureWalkMode } from './lib/ast/features/type.js'; export { getNodeProperty, setNodeProperty } from './lib/ast/node.js'; +export { version } from '../package.json.js'; /** * Load file or url diff --git a/files/getting-started.md b/files/getting-started.md index d4e70f945..f9c852b0b 100644 --- a/files/getting-started.md +++ b/files/getting-started.md @@ -62,7 +62,7 @@ It can be imported as an umd module. ```html + +