@eslint/css-tree 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +194 -0
- package/cjs/convertor/create.cjs +32 -0
- package/cjs/convertor/index.cjs +8 -0
- package/cjs/data-patch.cjs +7 -0
- package/cjs/data.cjs +120 -0
- package/cjs/definition-syntax/SyntaxError.cjs +16 -0
- package/cjs/definition-syntax/generate.cjs +139 -0
- package/cjs/definition-syntax/index.cjs +13 -0
- package/cjs/definition-syntax/parse.cjs +556 -0
- package/cjs/definition-syntax/scanner.cjs +113 -0
- package/cjs/definition-syntax/walk.cjs +57 -0
- package/cjs/generator/create.cjs +102 -0
- package/cjs/generator/index.cjs +8 -0
- package/cjs/generator/sourceMap.cjs +96 -0
- package/cjs/generator/token-before.cjs +170 -0
- package/cjs/index.cjs +65 -0
- package/cjs/lexer/Lexer.cjs +517 -0
- package/cjs/lexer/error.cjs +128 -0
- package/cjs/lexer/generic-an-plus-b.cjs +235 -0
- package/cjs/lexer/generic-const.cjs +12 -0
- package/cjs/lexer/generic-urange.cjs +149 -0
- package/cjs/lexer/generic.cjs +589 -0
- package/cjs/lexer/index.cjs +7 -0
- package/cjs/lexer/match-graph.cjs +530 -0
- package/cjs/lexer/match.cjs +632 -0
- package/cjs/lexer/prepare-tokens.cjs +54 -0
- package/cjs/lexer/search.cjs +65 -0
- package/cjs/lexer/structure.cjs +173 -0
- package/cjs/lexer/trace.cjs +73 -0
- package/cjs/lexer/units.cjs +38 -0
- package/cjs/parser/SyntaxError.cjs +74 -0
- package/cjs/parser/create.cjs +378 -0
- package/cjs/parser/index.cjs +8 -0
- package/cjs/parser/parse-selector.cjs +8 -0
- package/cjs/parser/sequence.cjs +47 -0
- package/cjs/syntax/atrule/container.cjs +32 -0
- package/cjs/syntax/atrule/font-face.cjs +12 -0
- package/cjs/syntax/atrule/import.cjs +101 -0
- package/cjs/syntax/atrule/index.cjs +27 -0
- package/cjs/syntax/atrule/layer.cjs +16 -0
- package/cjs/syntax/atrule/media.cjs +16 -0
- package/cjs/syntax/atrule/nest.cjs +16 -0
- package/cjs/syntax/atrule/page.cjs +16 -0
- package/cjs/syntax/atrule/scope.cjs +16 -0
- package/cjs/syntax/atrule/starting-style.cjs +12 -0
- package/cjs/syntax/atrule/supports.cjs +16 -0
- package/cjs/syntax/config/generator.cjs +9 -0
- package/cjs/syntax/config/lexer.cjs +14 -0
- package/cjs/syntax/config/mix.cjs +126 -0
- package/cjs/syntax/config/parser-selector.cjs +19 -0
- package/cjs/syntax/config/parser.cjs +49 -0
- package/cjs/syntax/config/walker.cjs +9 -0
- package/cjs/syntax/create.cjs +58 -0
- package/cjs/syntax/function/expression.cjs +11 -0
- package/cjs/syntax/function/var.cjs +43 -0
- package/cjs/syntax/index.cjs +14 -0
- package/cjs/syntax/node/AnPlusB.cjs +293 -0
- package/cjs/syntax/node/Atrule.cjs +103 -0
- package/cjs/syntax/node/AtrulePrelude.cjs +52 -0
- package/cjs/syntax/node/AttributeSelector.cjs +148 -0
- package/cjs/syntax/node/Block.cjs +96 -0
- package/cjs/syntax/node/Brackets.cjs +38 -0
- package/cjs/syntax/node/CDC.cjs +26 -0
- package/cjs/syntax/node/CDO.cjs +26 -0
- package/cjs/syntax/node/ClassSelector.cjs +31 -0
- package/cjs/syntax/node/Combinator.cjs +61 -0
- package/cjs/syntax/node/Comment.cjs +40 -0
- package/cjs/syntax/node/Condition.cjs +120 -0
- package/cjs/syntax/node/Declaration.cjs +166 -0
- package/cjs/syntax/node/DeclarationList.cjs +62 -0
- package/cjs/syntax/node/Dimension.cjs +30 -0
- package/cjs/syntax/node/Feature.cjs +101 -0
- package/cjs/syntax/node/FeatureFunction.cjs +67 -0
- package/cjs/syntax/node/FeatureRange.cjs +133 -0
- package/cjs/syntax/node/Function.cjs +45 -0
- package/cjs/syntax/node/GeneralEnclosed.cjs +68 -0
- package/cjs/syntax/node/Hash.cjs +30 -0
- package/cjs/syntax/node/IdSelector.cjs +33 -0
- package/cjs/syntax/node/Identifier.cjs +25 -0
- package/cjs/syntax/node/Layer.cjs +35 -0
- package/cjs/syntax/node/LayerList.cjs +43 -0
- package/cjs/syntax/node/MediaQuery.cjs +100 -0
- package/cjs/syntax/node/MediaQueryList.cjs +41 -0
- package/cjs/syntax/node/NestingSelector.cjs +29 -0
- package/cjs/syntax/node/Nth.cjs +54 -0
- package/cjs/syntax/node/Number.cjs +25 -0
- package/cjs/syntax/node/Operator.cjs +28 -0
- package/cjs/syntax/node/Parentheses.cjs +38 -0
- package/cjs/syntax/node/Percentage.cjs +25 -0
- package/cjs/syntax/node/PseudoClassSelector.cjs +67 -0
- package/cjs/syntax/node/PseudoElementSelector.cjs +69 -0
- package/cjs/syntax/node/Ratio.cjs +71 -0
- package/cjs/syntax/node/Raw.cjs +48 -0
- package/cjs/syntax/node/Rule.cjs +58 -0
- package/cjs/syntax/node/Scope.cjs +69 -0
- package/cjs/syntax/node/Selector.cjs +38 -0
- package/cjs/syntax/node/SelectorList.cjs +43 -0
- package/cjs/syntax/node/String.cjs +26 -0
- package/cjs/syntax/node/StyleSheet.cjs +83 -0
- package/cjs/syntax/node/SupportsDeclaration.cjs +38 -0
- package/cjs/syntax/node/TypeSelector.cjs +59 -0
- package/cjs/syntax/node/UnicodeRange.cjs +158 -0
- package/cjs/syntax/node/Url.cjs +54 -0
- package/cjs/syntax/node/Value.cjs +26 -0
- package/cjs/syntax/node/WhiteSpace.cjs +34 -0
- package/cjs/syntax/node/index-generate.cjs +103 -0
- package/cjs/syntax/node/index-parse-selector.cjs +39 -0
- package/cjs/syntax/node/index-parse.cjs +103 -0
- package/cjs/syntax/node/index.cjs +103 -0
- package/cjs/syntax/pseudo/index.cjs +60 -0
- package/cjs/syntax/pseudo/lang.cjs +37 -0
- package/cjs/syntax/scope/atrulePrelude.cjs +9 -0
- package/cjs/syntax/scope/default.cjs +76 -0
- package/cjs/syntax/scope/index.cjs +11 -0
- package/cjs/syntax/scope/selector.cjs +88 -0
- package/cjs/syntax/scope/value.cjs +29 -0
- package/cjs/tokenizer/OffsetToLocation.cjs +91 -0
- package/cjs/tokenizer/TokenStream.cjs +358 -0
- package/cjs/tokenizer/adopt-buffer.cjs +13 -0
- package/cjs/tokenizer/char-code-definitions.cjs +236 -0
- package/cjs/tokenizer/index.cjs +554 -0
- package/cjs/tokenizer/names.cjs +32 -0
- package/cjs/tokenizer/types.cjs +57 -0
- package/cjs/tokenizer/utils.cjs +261 -0
- package/cjs/utils/List.cjs +473 -0
- package/cjs/utils/clone.cjs +25 -0
- package/cjs/utils/create-custom-error.cjs +18 -0
- package/cjs/utils/ident.cjs +102 -0
- package/cjs/utils/index.cjs +20 -0
- package/cjs/utils/names.cjs +113 -0
- package/cjs/utils/string.cjs +99 -0
- package/cjs/utils/url.cjs +108 -0
- package/cjs/version.cjs +5 -0
- package/cjs/walker/create.cjs +291 -0
- package/cjs/walker/index.cjs +8 -0
- package/data/patch.json +874 -0
- package/dist/csstree.esm.js +12 -0
- package/dist/csstree.js +12 -0
- package/dist/data.cjs +1341 -0
- package/dist/data.js +1341 -0
- package/dist/version.cjs +1 -0
- package/dist/version.js +1 -0
- package/lib/convertor/create.js +28 -0
- package/lib/convertor/index.js +4 -0
- package/lib/data-patch.js +6 -0
- package/lib/data.js +118 -0
- package/lib/definition-syntax/SyntaxError.js +12 -0
- package/lib/definition-syntax/generate.js +135 -0
- package/lib/definition-syntax/index.js +4 -0
- package/lib/definition-syntax/parse.js +552 -0
- package/lib/definition-syntax/scanner.js +109 -0
- package/lib/definition-syntax/walk.js +53 -0
- package/lib/generator/create.js +97 -0
- package/lib/generator/index.js +4 -0
- package/lib/generator/sourceMap.js +92 -0
- package/lib/generator/token-before.js +182 -0
- package/lib/index.d.ts +3016 -0
- package/lib/index.js +30 -0
- package/lib/lexer/Lexer.js +511 -0
- package/lib/lexer/error.js +123 -0
- package/lib/lexer/generic-an-plus-b.js +238 -0
- package/lib/lexer/generic-const.js +8 -0
- package/lib/lexer/generic-urange.js +151 -0
- package/lib/lexer/generic.js +622 -0
- package/lib/lexer/index.js +1 -0
- package/lib/lexer/match-graph.js +527 -0
- package/lib/lexer/match.js +630 -0
- package/lib/lexer/prepare-tokens.js +50 -0
- package/lib/lexer/search.js +61 -0
- package/lib/lexer/structure.js +169 -0
- package/lib/lexer/trace.js +66 -0
- package/lib/lexer/units.js +27 -0
- package/lib/parser/SyntaxError.js +70 -0
- package/lib/parser/create.js +388 -0
- package/lib/parser/index.js +4 -0
- package/lib/parser/parse-selector.js +4 -0
- package/lib/parser/sequence.js +43 -0
- package/lib/syntax/atrule/container.js +28 -0
- package/lib/syntax/atrule/font-face.js +8 -0
- package/lib/syntax/atrule/import.js +104 -0
- package/lib/syntax/atrule/index.js +23 -0
- package/lib/syntax/atrule/layer.js +12 -0
- package/lib/syntax/atrule/media.js +12 -0
- package/lib/syntax/atrule/nest.js +12 -0
- package/lib/syntax/atrule/page.js +12 -0
- package/lib/syntax/atrule/scope.js +12 -0
- package/lib/syntax/atrule/starting-style.js +8 -0
- package/lib/syntax/atrule/supports.js +12 -0
- package/lib/syntax/config/generator.js +5 -0
- package/lib/syntax/config/lexer.js +10 -0
- package/lib/syntax/config/mix.js +122 -0
- package/lib/syntax/config/parser-selector.js +15 -0
- package/lib/syntax/config/parser.js +45 -0
- package/lib/syntax/config/walker.js +5 -0
- package/lib/syntax/create.js +55 -0
- package/lib/syntax/function/expression.js +7 -0
- package/lib/syntax/function/var.js +39 -0
- package/lib/syntax/index.js +10 -0
- package/lib/syntax/node/AnPlusB.js +292 -0
- package/lib/syntax/node/Atrule.js +100 -0
- package/lib/syntax/node/AtrulePrelude.js +47 -0
- package/lib/syntax/node/AttributeSelector.js +147 -0
- package/lib/syntax/node/Block.js +95 -0
- package/lib/syntax/node/Brackets.js +35 -0
- package/lib/syntax/node/CDC.js +19 -0
- package/lib/syntax/node/CDO.js +19 -0
- package/lib/syntax/node/ClassSelector.js +24 -0
- package/lib/syntax/node/Combinator.js +54 -0
- package/lib/syntax/node/Comment.js +33 -0
- package/lib/syntax/node/Condition.js +123 -0
- package/lib/syntax/node/Declaration.js +165 -0
- package/lib/syntax/node/DeclarationList.js +62 -0
- package/lib/syntax/node/Dimension.js +23 -0
- package/lib/syntax/node/Feature.js +103 -0
- package/lib/syntax/node/FeatureFunction.js +63 -0
- package/lib/syntax/node/FeatureRange.js +133 -0
- package/lib/syntax/node/Function.js +41 -0
- package/lib/syntax/node/GeneralEnclosed.js +66 -0
- package/lib/syntax/node/Hash.js +23 -0
- package/lib/syntax/node/IdSelector.js +26 -0
- package/lib/syntax/node/Identifier.js +18 -0
- package/lib/syntax/node/Layer.js +28 -0
- package/lib/syntax/node/LayerList.js +36 -0
- package/lib/syntax/node/MediaQuery.js +102 -0
- package/lib/syntax/node/MediaQueryList.js +34 -0
- package/lib/syntax/node/NestingSelector.js +22 -0
- package/lib/syntax/node/Nth.js +47 -0
- package/lib/syntax/node/Number.js +18 -0
- package/lib/syntax/node/Operator.js +21 -0
- package/lib/syntax/node/Parentheses.js +34 -0
- package/lib/syntax/node/Percentage.js +18 -0
- package/lib/syntax/node/PseudoClassSelector.js +65 -0
- package/lib/syntax/node/PseudoElementSelector.js +66 -0
- package/lib/syntax/node/Ratio.js +68 -0
- package/lib/syntax/node/Raw.js +41 -0
- package/lib/syntax/node/Rule.js +51 -0
- package/lib/syntax/node/Scope.js +66 -0
- package/lib/syntax/node/Selector.js +31 -0
- package/lib/syntax/node/SelectorList.js +35 -0
- package/lib/syntax/node/String.js +19 -0
- package/lib/syntax/node/StyleSheet.js +82 -0
- package/lib/syntax/node/SupportsDeclaration.js +34 -0
- package/lib/syntax/node/TypeSelector.js +52 -0
- package/lib/syntax/node/UnicodeRange.js +156 -0
- package/lib/syntax/node/Url.js +52 -0
- package/lib/syntax/node/Value.js +19 -0
- package/lib/syntax/node/WhiteSpace.js +27 -0
- package/lib/syntax/node/index-generate.js +49 -0
- package/lib/syntax/node/index-parse-selector.js +17 -0
- package/lib/syntax/node/index-parse.js +49 -0
- package/lib/syntax/node/index.js +49 -0
- package/lib/syntax/pseudo/index.js +56 -0
- package/lib/syntax/pseudo/lang.js +33 -0
- package/lib/syntax/scope/atrulePrelude.js +5 -0
- package/lib/syntax/scope/default.js +85 -0
- package/lib/syntax/scope/index.js +3 -0
- package/lib/syntax/scope/selector.js +94 -0
- package/lib/syntax/scope/value.js +25 -0
- package/lib/tokenizer/OffsetToLocation.js +87 -0
- package/lib/tokenizer/TokenStream.js +366 -0
- package/lib/tokenizer/adopt-buffer.js +9 -0
- package/lib/tokenizer/char-code-definitions.js +212 -0
- package/lib/tokenizer/index.js +513 -0
- package/lib/tokenizer/names.js +28 -0
- package/lib/tokenizer/types.js +28 -0
- package/lib/tokenizer/utils.js +254 -0
- package/lib/utils/List.js +469 -0
- package/lib/utils/clone.js +21 -0
- package/lib/utils/create-custom-error.js +14 -0
- package/lib/utils/ident.js +101 -0
- package/lib/utils/index.js +6 -0
- package/lib/utils/names.js +106 -0
- package/lib/utils/string.js +99 -0
- package/lib/utils/url.js +108 -0
- package/lib/version.js +5 -0
- package/lib/walker/create.js +287 -0
- package/lib/walker/index.js +4 -0
- package/package.json +133 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('../tokenizer/index.cjs');
|
|
4
|
+
const sourceMap = require('./sourceMap.cjs');
|
|
5
|
+
const tokenBefore = require('./token-before.cjs');
|
|
6
|
+
const types = require('../tokenizer/types.cjs');
|
|
7
|
+
|
|
8
|
+
const REVERSESOLIDUS = 0x005c; // U+005C REVERSE SOLIDUS (\)
|
|
9
|
+
|
|
10
|
+
function processChildren(node, delimeter) {
|
|
11
|
+
if (typeof delimeter === 'function') {
|
|
12
|
+
let prev = null;
|
|
13
|
+
|
|
14
|
+
node.children.forEach(node => {
|
|
15
|
+
if (prev !== null) {
|
|
16
|
+
delimeter.call(this, prev);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.node(node);
|
|
20
|
+
prev = node;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
node.children.forEach(this.node, this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function processChunk(chunk) {
|
|
30
|
+
index.tokenize(chunk, (type, start, end) => {
|
|
31
|
+
this.token(type, chunk.slice(start, end));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createGenerator(config) {
|
|
36
|
+
const types$1 = new Map();
|
|
37
|
+
|
|
38
|
+
for (let [name, item] of Object.entries(config.node)) {
|
|
39
|
+
const fn = item.generate || item;
|
|
40
|
+
|
|
41
|
+
if (typeof fn === 'function') {
|
|
42
|
+
types$1.set(name, item.generate || item);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return function(node, options) {
|
|
47
|
+
let buffer = '';
|
|
48
|
+
let prevCode = 0;
|
|
49
|
+
let handlers = {
|
|
50
|
+
node(node) {
|
|
51
|
+
if (types$1.has(node.type)) {
|
|
52
|
+
types$1.get(node.type).call(publicApi, node);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error('Unknown node type: ' + node.type);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
tokenBefore: tokenBefore.safe,
|
|
58
|
+
token(type, value) {
|
|
59
|
+
prevCode = this.tokenBefore(prevCode, type, value);
|
|
60
|
+
|
|
61
|
+
this.emit(value, type, false);
|
|
62
|
+
|
|
63
|
+
if (type === types.Delim && value.charCodeAt(0) === REVERSESOLIDUS) {
|
|
64
|
+
this.emit('\n', types.WhiteSpace, true);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
emit(value) {
|
|
68
|
+
buffer += value;
|
|
69
|
+
},
|
|
70
|
+
result() {
|
|
71
|
+
return buffer;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (options) {
|
|
76
|
+
if (typeof options.decorator === 'function') {
|
|
77
|
+
handlers = options.decorator(handlers);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options.sourceMap) {
|
|
81
|
+
handlers = sourceMap.generateSourceMap(handlers);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (options.mode in tokenBefore) {
|
|
85
|
+
handlers.tokenBefore = tokenBefore[options.mode];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const publicApi = {
|
|
90
|
+
node: (node) => handlers.node(node),
|
|
91
|
+
children: processChildren,
|
|
92
|
+
token: (type, value) => handlers.token(type, value),
|
|
93
|
+
tokenize: processChunk
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
handlers.node(node);
|
|
97
|
+
|
|
98
|
+
return handlers.result();
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.createGenerator = createGenerator;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const sourceMapGenerator_js = require('source-map-js/lib/source-map-generator.js');
|
|
4
|
+
|
|
5
|
+
const trackNodes = new Set(['Atrule', 'Selector', 'Declaration']);
|
|
6
|
+
|
|
7
|
+
function generateSourceMap(handlers) {
|
|
8
|
+
const map = new sourceMapGenerator_js.SourceMapGenerator();
|
|
9
|
+
const generated = {
|
|
10
|
+
line: 1,
|
|
11
|
+
column: 0
|
|
12
|
+
};
|
|
13
|
+
const original = {
|
|
14
|
+
line: 0, // should be zero to add first mapping
|
|
15
|
+
column: 0
|
|
16
|
+
};
|
|
17
|
+
const activatedGenerated = {
|
|
18
|
+
line: 1,
|
|
19
|
+
column: 0
|
|
20
|
+
};
|
|
21
|
+
const activatedMapping = {
|
|
22
|
+
generated: activatedGenerated
|
|
23
|
+
};
|
|
24
|
+
let line = 1;
|
|
25
|
+
let column = 0;
|
|
26
|
+
let sourceMappingActive = false;
|
|
27
|
+
|
|
28
|
+
const origHandlersNode = handlers.node;
|
|
29
|
+
handlers.node = function(node) {
|
|
30
|
+
if (node.loc && node.loc.start && trackNodes.has(node.type)) {
|
|
31
|
+
const nodeLine = node.loc.start.line;
|
|
32
|
+
const nodeColumn = node.loc.start.column - 1;
|
|
33
|
+
|
|
34
|
+
if (original.line !== nodeLine ||
|
|
35
|
+
original.column !== nodeColumn) {
|
|
36
|
+
original.line = nodeLine;
|
|
37
|
+
original.column = nodeColumn;
|
|
38
|
+
|
|
39
|
+
generated.line = line;
|
|
40
|
+
generated.column = column;
|
|
41
|
+
|
|
42
|
+
if (sourceMappingActive) {
|
|
43
|
+
sourceMappingActive = false;
|
|
44
|
+
if (generated.line !== activatedGenerated.line ||
|
|
45
|
+
generated.column !== activatedGenerated.column) {
|
|
46
|
+
map.addMapping(activatedMapping);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
sourceMappingActive = true;
|
|
51
|
+
map.addMapping({
|
|
52
|
+
source: node.loc.source,
|
|
53
|
+
original,
|
|
54
|
+
generated
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
origHandlersNode.call(this, node);
|
|
60
|
+
|
|
61
|
+
if (sourceMappingActive && trackNodes.has(node.type)) {
|
|
62
|
+
activatedGenerated.line = line;
|
|
63
|
+
activatedGenerated.column = column;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const origHandlersEmit = handlers.emit;
|
|
68
|
+
handlers.emit = function(value, type, auto) {
|
|
69
|
+
for (let i = 0; i < value.length; i++) {
|
|
70
|
+
if (value.charCodeAt(i) === 10) { // \n
|
|
71
|
+
line++;
|
|
72
|
+
column = 0;
|
|
73
|
+
} else {
|
|
74
|
+
column++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
origHandlersEmit(value, type, auto);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const origHandlersResult = handlers.result;
|
|
82
|
+
handlers.result = function() {
|
|
83
|
+
if (sourceMappingActive) {
|
|
84
|
+
map.addMapping(activatedMapping);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
css: origHandlersResult(),
|
|
89
|
+
map
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return handlers;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
exports.generateSourceMap = generateSourceMap;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
6
|
+
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
|
7
|
+
|
|
8
|
+
const code = (type, value) => {
|
|
9
|
+
if (type === types.Delim) {
|
|
10
|
+
type = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof type === 'string') {
|
|
14
|
+
const charCode = type.charCodeAt(0);
|
|
15
|
+
return charCode > 0x7F ? 0x8000 : charCode << 8;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return type;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// https://www.w3.org/TR/css-syntax-3/#serialization
|
|
22
|
+
// The only requirement for serialization is that it must "round-trip" with parsing,
|
|
23
|
+
// that is, parsing the stylesheet must produce the same data structures as parsing,
|
|
24
|
+
// serializing, and parsing again, except for consecutive <whitespace-token>s,
|
|
25
|
+
// which may be collapsed into a single token.
|
|
26
|
+
|
|
27
|
+
const specPairs = [
|
|
28
|
+
[types.Ident, types.Ident],
|
|
29
|
+
[types.Ident, types.Function],
|
|
30
|
+
[types.Ident, types.Url],
|
|
31
|
+
[types.Ident, types.BadUrl],
|
|
32
|
+
[types.Ident, '-'],
|
|
33
|
+
[types.Ident, types.Number],
|
|
34
|
+
[types.Ident, types.Percentage],
|
|
35
|
+
[types.Ident, types.Dimension],
|
|
36
|
+
[types.Ident, types.CDC],
|
|
37
|
+
[types.Ident, types.LeftParenthesis],
|
|
38
|
+
|
|
39
|
+
[types.AtKeyword, types.Ident],
|
|
40
|
+
[types.AtKeyword, types.Function],
|
|
41
|
+
[types.AtKeyword, types.Url],
|
|
42
|
+
[types.AtKeyword, types.BadUrl],
|
|
43
|
+
[types.AtKeyword, '-'],
|
|
44
|
+
[types.AtKeyword, types.Number],
|
|
45
|
+
[types.AtKeyword, types.Percentage],
|
|
46
|
+
[types.AtKeyword, types.Dimension],
|
|
47
|
+
[types.AtKeyword, types.CDC],
|
|
48
|
+
|
|
49
|
+
[types.Hash, types.Ident],
|
|
50
|
+
[types.Hash, types.Function],
|
|
51
|
+
[types.Hash, types.Url],
|
|
52
|
+
[types.Hash, types.BadUrl],
|
|
53
|
+
[types.Hash, '-'],
|
|
54
|
+
[types.Hash, types.Number],
|
|
55
|
+
[types.Hash, types.Percentage],
|
|
56
|
+
[types.Hash, types.Dimension],
|
|
57
|
+
[types.Hash, types.CDC],
|
|
58
|
+
|
|
59
|
+
[types.Dimension, types.Ident],
|
|
60
|
+
[types.Dimension, types.Function],
|
|
61
|
+
[types.Dimension, types.Url],
|
|
62
|
+
[types.Dimension, types.BadUrl],
|
|
63
|
+
[types.Dimension, '-'],
|
|
64
|
+
[types.Dimension, types.Number],
|
|
65
|
+
[types.Dimension, types.Percentage],
|
|
66
|
+
[types.Dimension, types.Dimension],
|
|
67
|
+
[types.Dimension, types.CDC],
|
|
68
|
+
|
|
69
|
+
['#', types.Ident],
|
|
70
|
+
['#', types.Function],
|
|
71
|
+
['#', types.Url],
|
|
72
|
+
['#', types.BadUrl],
|
|
73
|
+
['#', '-'],
|
|
74
|
+
['#', types.Number],
|
|
75
|
+
['#', types.Percentage],
|
|
76
|
+
['#', types.Dimension],
|
|
77
|
+
['#', types.CDC], // https://github.com/w3c/csswg-drafts/pull/6874
|
|
78
|
+
|
|
79
|
+
['-', types.Ident],
|
|
80
|
+
['-', types.Function],
|
|
81
|
+
['-', types.Url],
|
|
82
|
+
['-', types.BadUrl],
|
|
83
|
+
['-', '-'],
|
|
84
|
+
['-', types.Number],
|
|
85
|
+
['-', types.Percentage],
|
|
86
|
+
['-', types.Dimension],
|
|
87
|
+
['-', types.CDC], // https://github.com/w3c/csswg-drafts/pull/6874
|
|
88
|
+
|
|
89
|
+
[types.Number, types.Ident],
|
|
90
|
+
[types.Number, types.Function],
|
|
91
|
+
[types.Number, types.Url],
|
|
92
|
+
[types.Number, types.BadUrl],
|
|
93
|
+
[types.Number, types.Number],
|
|
94
|
+
[types.Number, types.Percentage],
|
|
95
|
+
[types.Number, types.Dimension],
|
|
96
|
+
[types.Number, '%'],
|
|
97
|
+
[types.Number, types.CDC], // https://github.com/w3c/csswg-drafts/pull/6874
|
|
98
|
+
|
|
99
|
+
['@', types.Ident],
|
|
100
|
+
['@', types.Function],
|
|
101
|
+
['@', types.Url],
|
|
102
|
+
['@', types.BadUrl],
|
|
103
|
+
['@', '-'],
|
|
104
|
+
['@', types.CDC], // https://github.com/w3c/csswg-drafts/pull/6874
|
|
105
|
+
|
|
106
|
+
['.', types.Number],
|
|
107
|
+
['.', types.Percentage],
|
|
108
|
+
['.', types.Dimension],
|
|
109
|
+
|
|
110
|
+
['+', types.Number],
|
|
111
|
+
['+', types.Percentage],
|
|
112
|
+
['+', types.Dimension],
|
|
113
|
+
|
|
114
|
+
['/', '*']
|
|
115
|
+
];
|
|
116
|
+
// validate with scripts/generate-safe
|
|
117
|
+
const safePairs = specPairs.concat([
|
|
118
|
+
[types.Ident, types.Hash],
|
|
119
|
+
|
|
120
|
+
[types.Dimension, types.Hash],
|
|
121
|
+
|
|
122
|
+
[types.Hash, types.Hash],
|
|
123
|
+
|
|
124
|
+
[types.AtKeyword, types.LeftParenthesis],
|
|
125
|
+
[types.AtKeyword, types.String],
|
|
126
|
+
[types.AtKeyword, types.Colon],
|
|
127
|
+
|
|
128
|
+
[types.Percentage, types.Percentage],
|
|
129
|
+
[types.Percentage, types.Dimension],
|
|
130
|
+
[types.Percentage, types.Function],
|
|
131
|
+
[types.Percentage, '-'],
|
|
132
|
+
|
|
133
|
+
[types.RightParenthesis, types.Ident],
|
|
134
|
+
[types.RightParenthesis, types.Function],
|
|
135
|
+
[types.RightParenthesis, types.Percentage],
|
|
136
|
+
[types.RightParenthesis, types.Dimension],
|
|
137
|
+
[types.RightParenthesis, types.Hash],
|
|
138
|
+
[types.RightParenthesis, '-']
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
function createMap(pairs) {
|
|
142
|
+
const isWhiteSpaceRequired = new Set(
|
|
143
|
+
pairs.map(([prev, next]) => (code(prev) << 16 | code(next)))
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return function(prevCode, type, value) {
|
|
147
|
+
const nextCode = code(type, value);
|
|
148
|
+
const nextCharCode = value.charCodeAt(0);
|
|
149
|
+
const emitWs =
|
|
150
|
+
(nextCharCode === HYPHENMINUS &&
|
|
151
|
+
type !== types.Ident &&
|
|
152
|
+
type !== types.Function &&
|
|
153
|
+
type !== types.CDC) ||
|
|
154
|
+
(nextCharCode === PLUSSIGN)
|
|
155
|
+
? isWhiteSpaceRequired.has(prevCode << 16 | nextCharCode << 8)
|
|
156
|
+
: isWhiteSpaceRequired.has(prevCode << 16 | nextCode);
|
|
157
|
+
|
|
158
|
+
if (emitWs) {
|
|
159
|
+
this.emit(' ', types.WhiteSpace, true);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return nextCode;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const spec = createMap(specPairs);
|
|
167
|
+
const safe = createMap(safePairs);
|
|
168
|
+
|
|
169
|
+
exports.safe = safe;
|
|
170
|
+
exports.spec = spec;
|
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index$1 = require('./syntax/index.cjs');
|
|
4
|
+
const version = require('./version.cjs');
|
|
5
|
+
const create = require('./syntax/create.cjs');
|
|
6
|
+
const List = require('./utils/List.cjs');
|
|
7
|
+
const Lexer = require('./lexer/Lexer.cjs');
|
|
8
|
+
const index = require('./definition-syntax/index.cjs');
|
|
9
|
+
const clone = require('./utils/clone.cjs');
|
|
10
|
+
const names$1 = require('./utils/names.cjs');
|
|
11
|
+
const ident = require('./utils/ident.cjs');
|
|
12
|
+
const string = require('./utils/string.cjs');
|
|
13
|
+
const url = require('./utils/url.cjs');
|
|
14
|
+
const types = require('./tokenizer/types.cjs');
|
|
15
|
+
const names = require('./tokenizer/names.cjs');
|
|
16
|
+
const TokenStream = require('./tokenizer/TokenStream.cjs');
|
|
17
|
+
const OffsetToLocation = require('./tokenizer/OffsetToLocation.cjs');
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
tokenize,
|
|
21
|
+
parse,
|
|
22
|
+
generate,
|
|
23
|
+
lexer,
|
|
24
|
+
createLexer,
|
|
25
|
+
|
|
26
|
+
walk,
|
|
27
|
+
find,
|
|
28
|
+
findLast,
|
|
29
|
+
findAll,
|
|
30
|
+
|
|
31
|
+
toPlainObject,
|
|
32
|
+
fromPlainObject,
|
|
33
|
+
|
|
34
|
+
fork
|
|
35
|
+
} = index$1;
|
|
36
|
+
|
|
37
|
+
exports.version = version.version;
|
|
38
|
+
exports.createSyntax = create;
|
|
39
|
+
exports.List = List.List;
|
|
40
|
+
exports.Lexer = Lexer.Lexer;
|
|
41
|
+
exports.definitionSyntax = index;
|
|
42
|
+
exports.clone = clone.clone;
|
|
43
|
+
exports.isCustomProperty = names$1.isCustomProperty;
|
|
44
|
+
exports.keyword = names$1.keyword;
|
|
45
|
+
exports.property = names$1.property;
|
|
46
|
+
exports.vendorPrefix = names$1.vendorPrefix;
|
|
47
|
+
exports.ident = ident;
|
|
48
|
+
exports.string = string;
|
|
49
|
+
exports.url = url;
|
|
50
|
+
exports.tokenTypes = types;
|
|
51
|
+
exports.tokenNames = names;
|
|
52
|
+
exports.TokenStream = TokenStream.TokenStream;
|
|
53
|
+
exports.OffsetToLocation = OffsetToLocation.OffsetToLocation;
|
|
54
|
+
exports.createLexer = createLexer;
|
|
55
|
+
exports.find = find;
|
|
56
|
+
exports.findAll = findAll;
|
|
57
|
+
exports.findLast = findLast;
|
|
58
|
+
exports.fork = fork;
|
|
59
|
+
exports.fromPlainObject = fromPlainObject;
|
|
60
|
+
exports.generate = generate;
|
|
61
|
+
exports.lexer = lexer;
|
|
62
|
+
exports.parse = parse;
|
|
63
|
+
exports.toPlainObject = toPlainObject;
|
|
64
|
+
exports.tokenize = tokenize;
|
|
65
|
+
exports.walk = walk;
|