@master/css-lexer 2.0.0-rc.70
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/README.md +37 -0
- package/dist/class.d.ts +32 -0
- package/dist/class.mjs +526 -0
- package/dist/css-manifest-entry.d.ts +30 -0
- package/dist/css-manifest-entry.mjs +188 -0
- package/dist/directive-ranges.d.ts +29 -0
- package/dist/directive-ranges.mjs +262 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/source.d.ts +31 -0
- package/dist/source.mjs +211 -0
- package/dist/units.d.ts +2 -0
- package/dist/units.mjs +70 -0
- package/package.json +1 -0
package/dist/source.mjs
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
function escapeRegExp(source) {
|
|
2
|
+
return source.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
}
|
|
4
|
+
function cssEscape(value) {
|
|
5
|
+
if (typeof CSS !== 'undefined') return CSS.escape(value);
|
|
6
|
+
if (arguments.length == 0) {
|
|
7
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
8
|
+
}
|
|
9
|
+
const string = String(value);
|
|
10
|
+
const length = string.length;
|
|
11
|
+
let index = -1;
|
|
12
|
+
let result = '';
|
|
13
|
+
let codeUnit;
|
|
14
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
15
|
+
if (length == 1 && firstCodeUnit == 0x002D) {
|
|
16
|
+
return '\\' + string;
|
|
17
|
+
}
|
|
18
|
+
while(++index < length){
|
|
19
|
+
codeUnit = string.charCodeAt(index);
|
|
20
|
+
if (codeUnit == 0x0000) {
|
|
21
|
+
result += '\uFFFD';
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
25
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
29
|
+
result += string.charAt(index);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
result += '\\' + string.charAt(index);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function isCSSIdentChar(char) {
|
|
37
|
+
return Boolean(char && /[-_a-zA-Z0-9]/.test(char));
|
|
38
|
+
}
|
|
39
|
+
function isCSSIdentStart(char) {
|
|
40
|
+
return Boolean(char && /[_a-zA-Z-]/.test(char));
|
|
41
|
+
}
|
|
42
|
+
function skipCSSWhitespace(source, index) {
|
|
43
|
+
while(/\s/.test(source[index] || ''))index++;
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
function readCSSIdent(source, index) {
|
|
47
|
+
const start = index;
|
|
48
|
+
while(isCSSIdentChar(source[index]))index++;
|
|
49
|
+
return {
|
|
50
|
+
start,
|
|
51
|
+
end: index,
|
|
52
|
+
value: source.slice(start, index)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createSourceLocationResolver(source) {
|
|
56
|
+
const lineStarts = [
|
|
57
|
+
0
|
|
58
|
+
];
|
|
59
|
+
for(let index = 0; index < source.length; index++){
|
|
60
|
+
if (source[index] === '\n') {
|
|
61
|
+
lineStarts.push(index + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return (loc)=>{
|
|
65
|
+
if (!loc) return -1;
|
|
66
|
+
const lineStart = lineStarts[loc.line];
|
|
67
|
+
if (lineStart === undefined) return -1;
|
|
68
|
+
return lineStart + Math.max(0, loc.column - 1);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function findCSSStatementEnd(source, start) {
|
|
72
|
+
let quote = '';
|
|
73
|
+
let comment = false;
|
|
74
|
+
let depth = 0;
|
|
75
|
+
for(let index = start; index < source.length; index++){
|
|
76
|
+
const char = source[index];
|
|
77
|
+
const next = source[index + 1];
|
|
78
|
+
if (comment) {
|
|
79
|
+
if (char === '*' && next === '/') {
|
|
80
|
+
comment = false;
|
|
81
|
+
index++;
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (quote) {
|
|
86
|
+
if (char === '\\') {
|
|
87
|
+
index++;
|
|
88
|
+
} else if (char === quote) {
|
|
89
|
+
quote = '';
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (char === '/' && next === '*') {
|
|
94
|
+
comment = true;
|
|
95
|
+
index++;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (char === '"' || char === '\'') {
|
|
99
|
+
quote = char;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === '(' || char === '[') {
|
|
103
|
+
depth++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (char === ')' || char === ']') {
|
|
107
|
+
depth = Math.max(0, depth - 1);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (depth === 0 && char === ';') {
|
|
111
|
+
return {
|
|
112
|
+
end: index + 1,
|
|
113
|
+
reason: 'semicolon',
|
|
114
|
+
delimiterRange: {
|
|
115
|
+
start: index,
|
|
116
|
+
end: index + 1
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (depth === 0 && char === '{') {
|
|
121
|
+
return {
|
|
122
|
+
end: index,
|
|
123
|
+
reason: 'block',
|
|
124
|
+
delimiterRange: {
|
|
125
|
+
start: index,
|
|
126
|
+
end: index + 1
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
end: source.length,
|
|
133
|
+
reason: 'eof'
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function findCSSClosingQuote(source, start, quote, limit = source.length) {
|
|
137
|
+
for(let index = start + 1; index < limit; index++){
|
|
138
|
+
if (source[index] === '\\') {
|
|
139
|
+
index++;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (source[index] === quote) return index;
|
|
143
|
+
}
|
|
144
|
+
return Math.max(start, limit - 1);
|
|
145
|
+
}
|
|
146
|
+
function findCSSBlockEnd(source, open) {
|
|
147
|
+
if (source[open] !== '{') return -1;
|
|
148
|
+
let quote = '';
|
|
149
|
+
let comment = false;
|
|
150
|
+
let depth = 0;
|
|
151
|
+
for(let index = open; index < source.length; index++){
|
|
152
|
+
const char = source[index];
|
|
153
|
+
const next = source[index + 1];
|
|
154
|
+
if (comment) {
|
|
155
|
+
if (char === '*' && next === '/') {
|
|
156
|
+
comment = false;
|
|
157
|
+
index++;
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (quote) {
|
|
162
|
+
if (char === '\\') {
|
|
163
|
+
index++;
|
|
164
|
+
} else if (char === quote) {
|
|
165
|
+
quote = '';
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (char === '/' && next === '*') {
|
|
170
|
+
comment = true;
|
|
171
|
+
index++;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (char === '"' || char === '\'') {
|
|
175
|
+
quote = char;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (char === '{') {
|
|
179
|
+
depth++;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (char === '}') {
|
|
183
|
+
depth--;
|
|
184
|
+
if (depth === 0) return index;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
function removeSourceRanges(source, ranges) {
|
|
190
|
+
if (!ranges.length) return source;
|
|
191
|
+
let output = '';
|
|
192
|
+
let offset = 0;
|
|
193
|
+
for (const range of ranges){
|
|
194
|
+
output += source.slice(offset, range.start);
|
|
195
|
+
offset = range.end;
|
|
196
|
+
}
|
|
197
|
+
return output + source.slice(offset);
|
|
198
|
+
}
|
|
199
|
+
function replaceSourceRanges(source, ranges) {
|
|
200
|
+
if (!ranges.length) return source;
|
|
201
|
+
let output = '';
|
|
202
|
+
let offset = 0;
|
|
203
|
+
for (const range of ranges){
|
|
204
|
+
output += source.slice(offset, range.start);
|
|
205
|
+
output += range.replacement;
|
|
206
|
+
offset = range.end;
|
|
207
|
+
}
|
|
208
|
+
return output + source.slice(offset);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { createSourceLocationResolver, cssEscape, escapeRegExp, findCSSBlockEnd, findCSSClosingQuote, findCSSStatementEnd, isCSSIdentChar, isCSSIdentStart, readCSSIdent, removeSourceRanges, replaceSourceRanges, skipCSSWhitespace };
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const MASTER_CSS_VALUE_UNITS: readonly ["%", "cm", "mm", "q", "in", "pt", "pc", "px", "em", "rem", "ex", "rex", "cap", "rcap", "ch", "rch", "ic", "ric", "lh", "rlh", "vw", "svw", "lvw", "dvw", "vh", "svh", "lvh", "dvh", "vi", "svi", "lvi", "dvi", "vb", "svb", "lvb", "dvb", "vmin", "svmin", "lvmin", "dvmin", "vmax", "svmax", "lvmax", "dvmax", "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax", "deg", "grad", "rad", "turn", "s", "ms", "hz", "khz", "dpi", "dpcm", "dppx", "x", "fr", "db", "st"];
|
|
2
|
+
export declare const MASTER_CSS_VALUE_UNIT_PATTERN: string;
|
package/dist/units.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const MASTER_CSS_VALUE_UNITS = [
|
|
2
|
+
'%',
|
|
3
|
+
'cm',
|
|
4
|
+
'mm',
|
|
5
|
+
'q',
|
|
6
|
+
'in',
|
|
7
|
+
'pt',
|
|
8
|
+
'pc',
|
|
9
|
+
'px',
|
|
10
|
+
'em',
|
|
11
|
+
'rem',
|
|
12
|
+
'ex',
|
|
13
|
+
'rex',
|
|
14
|
+
'cap',
|
|
15
|
+
'rcap',
|
|
16
|
+
'ch',
|
|
17
|
+
'rch',
|
|
18
|
+
'ic',
|
|
19
|
+
'ric',
|
|
20
|
+
'lh',
|
|
21
|
+
'rlh',
|
|
22
|
+
'vw',
|
|
23
|
+
'svw',
|
|
24
|
+
'lvw',
|
|
25
|
+
'dvw',
|
|
26
|
+
'vh',
|
|
27
|
+
'svh',
|
|
28
|
+
'lvh',
|
|
29
|
+
'dvh',
|
|
30
|
+
'vi',
|
|
31
|
+
'svi',
|
|
32
|
+
'lvi',
|
|
33
|
+
'dvi',
|
|
34
|
+
'vb',
|
|
35
|
+
'svb',
|
|
36
|
+
'lvb',
|
|
37
|
+
'dvb',
|
|
38
|
+
'vmin',
|
|
39
|
+
'svmin',
|
|
40
|
+
'lvmin',
|
|
41
|
+
'dvmin',
|
|
42
|
+
'vmax',
|
|
43
|
+
'svmax',
|
|
44
|
+
'lvmax',
|
|
45
|
+
'dvmax',
|
|
46
|
+
'cqw',
|
|
47
|
+
'cqh',
|
|
48
|
+
'cqi',
|
|
49
|
+
'cqb',
|
|
50
|
+
'cqmin',
|
|
51
|
+
'cqmax',
|
|
52
|
+
'deg',
|
|
53
|
+
'grad',
|
|
54
|
+
'rad',
|
|
55
|
+
'turn',
|
|
56
|
+
's',
|
|
57
|
+
'ms',
|
|
58
|
+
'hz',
|
|
59
|
+
'khz',
|
|
60
|
+
'dpi',
|
|
61
|
+
'dpcm',
|
|
62
|
+
'dppx',
|
|
63
|
+
'x',
|
|
64
|
+
'fr',
|
|
65
|
+
'db',
|
|
66
|
+
'st'
|
|
67
|
+
];
|
|
68
|
+
const MASTER_CSS_VALUE_UNIT_PATTERN = MASTER_CSS_VALUE_UNITS.join('|');
|
|
69
|
+
|
|
70
|
+
export { MASTER_CSS_VALUE_UNITS, MASTER_CSS_VALUE_UNIT_PATTERN };
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@master/css-lexer","type":"module","scripts":{"build":"techor build \"src/**/*.ts\" --formats esm","dev":"pnpm build --watch","lint":"eslint","type-check":"tsc --noEmit","test":"vitest"},"license":"MIT","description":"Dependency-free lexical source scanners for Master CSS tooling","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/lexer"},"keywords":["lexer","scanner","classes","directives","css","mastercss"],"sideEffects":false,"main":"./dist/index.mjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","default":"./dist/index.mjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.70"}
|