css-typed-vars 0.13.0 → 0.14.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/README.md +10 -7
- package/dist/{chunk-JGJ53FND.js → chunk-7J7UZYHB.js} +1 -1
- package/dist/{chunk-XSFYQPH6.js → chunk-BPZRXE6W.js} +141 -22
- package/dist/{chunk-FWKCSH2F.js → chunk-VWEQJVXA.js} +1 -1
- package/dist/cli.cjs +145 -21
- package/dist/cli.js +8 -3
- package/dist/esbuild.cjs +135 -17
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/{generator-BokM5zux.d.ts → generator-TJNk6ET_.d.cts} +5 -0
- package/dist/{generator-BokM5zux.d.cts → generator-TJNk6ET_.d.ts} +5 -0
- package/dist/index.cjs +133 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +135 -17
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +135 -17
- package/dist/unplugin.d.cts +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +135 -17
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +135 -17
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/dist/unplugin.cjs
CHANGED
|
@@ -181,17 +181,78 @@ function extractValue(text, start) {
|
|
|
181
181
|
else if (char === open[open.length - 1]) open.pop();
|
|
182
182
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
183
183
|
}
|
|
184
|
-
return text.slice(start, i).trim();
|
|
184
|
+
return joinLines(text.slice(start, i).trim());
|
|
185
|
+
}
|
|
186
|
+
function joinLines(value) {
|
|
187
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
188
|
+
const masked = maskQuotedContent(value);
|
|
189
|
+
let result = "";
|
|
190
|
+
let last = 0;
|
|
191
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
192
|
+
result += value.slice(last, match.index) + " ";
|
|
193
|
+
last = match.index + match[0].length;
|
|
194
|
+
}
|
|
195
|
+
return result + value.slice(last);
|
|
185
196
|
}
|
|
186
197
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
198
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
187
199
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
188
200
|
const masked = maskQuotedContent(block);
|
|
189
|
-
for (const prop of masked.matchAll(
|
|
201
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
190
202
|
const name = prop[0];
|
|
191
203
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
192
204
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
193
205
|
}
|
|
194
206
|
}
|
|
207
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
208
|
+
function nestedRanges(block) {
|
|
209
|
+
const masked = maskQuotedContent(block);
|
|
210
|
+
const ranges = [];
|
|
211
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
212
|
+
let i = 0;
|
|
213
|
+
while (i < block.length) {
|
|
214
|
+
statement.lastIndex = i;
|
|
215
|
+
const match = statement.exec(masked);
|
|
216
|
+
i = statement.lastIndex;
|
|
217
|
+
if (match[1]) {
|
|
218
|
+
const raw = block.slice(i);
|
|
219
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
220
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
221
|
+
i++;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
for (let depth = 0; i < block.length; i++) {
|
|
225
|
+
const char = masked[i];
|
|
226
|
+
if (char === "(") depth++;
|
|
227
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
228
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
229
|
+
}
|
|
230
|
+
if (masked[i] === "{") {
|
|
231
|
+
const body = extractBlock(block, i + 1);
|
|
232
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
233
|
+
i += body.length + 1;
|
|
234
|
+
}
|
|
235
|
+
i++;
|
|
236
|
+
}
|
|
237
|
+
return ranges;
|
|
238
|
+
}
|
|
239
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
240
|
+
const nested = nestedRanges(block);
|
|
241
|
+
forEachProperty(block, (name, value, position) => {
|
|
242
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
243
|
+
}, offset);
|
|
244
|
+
}
|
|
245
|
+
function conditionalRanges(stripped) {
|
|
246
|
+
const masked = maskQuotedContent(stripped);
|
|
247
|
+
const ranges = [];
|
|
248
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
249
|
+
let match;
|
|
250
|
+
while (match = openRegex.exec(masked)) {
|
|
251
|
+
const start = match.index + match[0].length;
|
|
252
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
253
|
+
}
|
|
254
|
+
return ranges;
|
|
255
|
+
}
|
|
195
256
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
196
257
|
for (const sel of selectors) {
|
|
197
258
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -208,11 +269,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
208
269
|
}
|
|
209
270
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
210
271
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
272
|
+
const conditional = conditionalRanges(stripped);
|
|
211
273
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
212
|
-
|
|
213
|
-
forEachProperty(block,
|
|
274
|
+
const nested = nestedRanges(block);
|
|
275
|
+
forEachProperty(block, (name, value, position) => {
|
|
276
|
+
if (inRanges(skip, position)) return;
|
|
277
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
278
|
+
}, bodyStart);
|
|
214
279
|
});
|
|
215
280
|
}
|
|
281
|
+
function makeDeclarationCollector() {
|
|
282
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
283
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
284
|
+
const add = (name, value, isConditional) => {
|
|
285
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
286
|
+
declarations.set(name, value);
|
|
287
|
+
if (isConditional) conditional.add(name);
|
|
288
|
+
else conditional.delete(name);
|
|
289
|
+
return true;
|
|
290
|
+
};
|
|
291
|
+
return { declarations, conditional, add };
|
|
292
|
+
}
|
|
216
293
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
217
294
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
218
295
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -268,15 +345,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
268
345
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
269
346
|
const values = /* @__PURE__ */ new Map();
|
|
270
347
|
themeValues.set(themeName, values);
|
|
271
|
-
const
|
|
348
|
+
const onProperty = (name, value, position) => {
|
|
272
349
|
values.set(name, value);
|
|
273
350
|
const doc = docAt(position);
|
|
274
351
|
if (doc) themeDocs.set(name, doc);
|
|
275
|
-
}
|
|
352
|
+
};
|
|
353
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
276
354
|
const selector = themeSelector.trim();
|
|
277
355
|
if (/^@media\b/i.test(selector)) {
|
|
278
356
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
279
357
|
skip.push(range);
|
|
358
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
280
359
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
281
360
|
});
|
|
282
361
|
} else {
|
|
@@ -286,17 +365,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
286
365
|
});
|
|
287
366
|
}
|
|
288
367
|
}
|
|
289
|
-
const declarations
|
|
368
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
290
369
|
const docs = /* @__PURE__ */ new Map();
|
|
291
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
292
|
-
|
|
370
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
371
|
+
if (!add(name, value, isConditional)) return;
|
|
293
372
|
const doc = docAt(position);
|
|
294
373
|
if (doc) docs.set(name, doc);
|
|
295
374
|
}, skip, stripped);
|
|
296
375
|
for (const [name, doc] of themeDocs) {
|
|
297
376
|
if (!docs.has(name)) docs.set(name, doc);
|
|
298
377
|
}
|
|
299
|
-
return { declarations, themes: themeValues, docs };
|
|
378
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
300
379
|
}
|
|
301
380
|
var PROPERTY_DESCRIPTORS = [
|
|
302
381
|
["syntax", "syntax"],
|
|
@@ -374,9 +453,13 @@ async function findFiles(patterns, exclude) {
|
|
|
374
453
|
return [...new Set(files.reverse())].reverse();
|
|
375
454
|
}
|
|
376
455
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
377
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
378
|
-
const
|
|
379
|
-
const
|
|
456
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
457
|
+
const normalized = normalizePatterns(patterns);
|
|
458
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
459
|
+
const ignore = compile([
|
|
460
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
461
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
462
|
+
]);
|
|
380
463
|
return (file) => {
|
|
381
464
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
382
465
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -387,6 +470,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
387
470
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
388
471
|
const roots = /* @__PURE__ */ new Map();
|
|
389
472
|
for (const pattern of normalizePatterns(patterns)) {
|
|
473
|
+
if (pattern.startsWith("!")) continue;
|
|
390
474
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
391
475
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
392
476
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -421,12 +505,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
421
505
|
})
|
|
422
506
|
);
|
|
423
507
|
const declarations = /* @__PURE__ */ new Map();
|
|
508
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
424
509
|
const properties = /* @__PURE__ */ new Map();
|
|
425
510
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
426
511
|
const docs = /* @__PURE__ */ new Map();
|
|
427
512
|
for (const result of perFile) {
|
|
428
513
|
if (!result) continue;
|
|
429
|
-
for (const [name, value] of result.declarations)
|
|
514
|
+
for (const [name, value] of result.declarations) {
|
|
515
|
+
const isConditional = result.conditional.has(name);
|
|
516
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
517
|
+
declarations.set(name, value);
|
|
518
|
+
if (isConditional) conditional.add(name);
|
|
519
|
+
else conditional.delete(name);
|
|
520
|
+
}
|
|
430
521
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
431
522
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
432
523
|
for (const [theme, values] of result.themes) {
|
|
@@ -447,19 +538,46 @@ function rootPattern(text) {
|
|
|
447
538
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
448
539
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
449
540
|
}
|
|
450
|
-
var ACCESS_RE = /\s*(
|
|
541
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
451
542
|
function readAccess(text, from) {
|
|
452
543
|
ACCESS_RE.lastIndex = from;
|
|
453
544
|
const match = ACCESS_RE.exec(text);
|
|
454
545
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
455
546
|
}
|
|
547
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
548
|
+
function readPatternKeys(text, at) {
|
|
549
|
+
let i = at - 1;
|
|
550
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
551
|
+
if (text[i] !== "=") return [];
|
|
552
|
+
i--;
|
|
553
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
554
|
+
if (text[i] !== "}") return [];
|
|
555
|
+
const open = text.lastIndexOf("{", i);
|
|
556
|
+
if (open === -1) return [];
|
|
557
|
+
const body = text.slice(open + 1, i);
|
|
558
|
+
if (body.includes("}")) return [];
|
|
559
|
+
const keys = [];
|
|
560
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
561
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
562
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
563
|
+
}
|
|
564
|
+
return keys;
|
|
565
|
+
}
|
|
456
566
|
function extractUsage(text, into) {
|
|
457
567
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
458
568
|
const first = readAccess(text, root.index + root[0].length);
|
|
459
|
-
|
|
569
|
+
const second = first && readAccess(text, first.end);
|
|
570
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
571
|
+
if (!first) {
|
|
572
|
+
for (const key of destructured) {
|
|
573
|
+
into.keys.add(key);
|
|
574
|
+
into.wholeKeys.add(key);
|
|
575
|
+
}
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
460
578
|
into.keys.add(first.key);
|
|
461
|
-
const second = readAccess(text, first.end);
|
|
462
579
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
580
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
463
581
|
else into.wholeKeys.add(first.key);
|
|
464
582
|
}
|
|
465
583
|
}
|
package/dist/unplugin.d.cts
CHANGED
package/dist/unplugin.d.ts
CHANGED
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -183,17 +183,78 @@ function extractValue(text, start) {
|
|
|
183
183
|
else if (char === open[open.length - 1]) open.pop();
|
|
184
184
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
185
185
|
}
|
|
186
|
-
return text.slice(start, i).trim();
|
|
186
|
+
return joinLines(text.slice(start, i).trim());
|
|
187
|
+
}
|
|
188
|
+
function joinLines(value) {
|
|
189
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
190
|
+
const masked = maskQuotedContent(value);
|
|
191
|
+
let result = "";
|
|
192
|
+
let last = 0;
|
|
193
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
194
|
+
result += value.slice(last, match.index) + " ";
|
|
195
|
+
last = match.index + match[0].length;
|
|
196
|
+
}
|
|
197
|
+
return result + value.slice(last);
|
|
187
198
|
}
|
|
188
199
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
200
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
189
201
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
190
202
|
const masked = maskQuotedContent(block);
|
|
191
|
-
for (const prop of masked.matchAll(
|
|
203
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
192
204
|
const name = prop[0];
|
|
193
205
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
194
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
195
207
|
}
|
|
196
208
|
}
|
|
209
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
210
|
+
function nestedRanges(block) {
|
|
211
|
+
const masked = maskQuotedContent(block);
|
|
212
|
+
const ranges = [];
|
|
213
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
214
|
+
let i = 0;
|
|
215
|
+
while (i < block.length) {
|
|
216
|
+
statement.lastIndex = i;
|
|
217
|
+
const match = statement.exec(masked);
|
|
218
|
+
i = statement.lastIndex;
|
|
219
|
+
if (match[1]) {
|
|
220
|
+
const raw = block.slice(i);
|
|
221
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
222
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
223
|
+
i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
for (let depth = 0; i < block.length; i++) {
|
|
227
|
+
const char = masked[i];
|
|
228
|
+
if (char === "(") depth++;
|
|
229
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
230
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
231
|
+
}
|
|
232
|
+
if (masked[i] === "{") {
|
|
233
|
+
const body = extractBlock(block, i + 1);
|
|
234
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
235
|
+
i += body.length + 1;
|
|
236
|
+
}
|
|
237
|
+
i++;
|
|
238
|
+
}
|
|
239
|
+
return ranges;
|
|
240
|
+
}
|
|
241
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
242
|
+
const nested = nestedRanges(block);
|
|
243
|
+
forEachProperty(block, (name, value, position) => {
|
|
244
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
245
|
+
}, offset);
|
|
246
|
+
}
|
|
247
|
+
function conditionalRanges(stripped) {
|
|
248
|
+
const masked = maskQuotedContent(stripped);
|
|
249
|
+
const ranges = [];
|
|
250
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
251
|
+
let match;
|
|
252
|
+
while (match = openRegex.exec(masked)) {
|
|
253
|
+
const start = match.index + match[0].length;
|
|
254
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
255
|
+
}
|
|
256
|
+
return ranges;
|
|
257
|
+
}
|
|
197
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
198
259
|
for (const sel of selectors) {
|
|
199
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -210,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
210
271
|
}
|
|
211
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
212
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
213
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
214
|
-
|
|
215
|
-
forEachProperty(block,
|
|
276
|
+
const nested = nestedRanges(block);
|
|
277
|
+
forEachProperty(block, (name, value, position) => {
|
|
278
|
+
if (inRanges(skip, position)) return;
|
|
279
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
280
|
+
}, bodyStart);
|
|
216
281
|
});
|
|
217
282
|
}
|
|
283
|
+
function makeDeclarationCollector() {
|
|
284
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
285
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
286
|
+
const add = (name, value, isConditional) => {
|
|
287
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
288
|
+
declarations.set(name, value);
|
|
289
|
+
if (isConditional) conditional.add(name);
|
|
290
|
+
else conditional.delete(name);
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
return { declarations, conditional, add };
|
|
294
|
+
}
|
|
218
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
219
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
220
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -270,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
270
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
271
348
|
const values = /* @__PURE__ */ new Map();
|
|
272
349
|
themeValues.set(themeName, values);
|
|
273
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
274
351
|
values.set(name, value);
|
|
275
352
|
const doc = docAt(position);
|
|
276
353
|
if (doc) themeDocs.set(name, doc);
|
|
277
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
278
356
|
const selector = themeSelector.trim();
|
|
279
357
|
if (/^@media\b/i.test(selector)) {
|
|
280
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
281
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
282
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
283
362
|
});
|
|
284
363
|
} else {
|
|
@@ -288,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
288
367
|
});
|
|
289
368
|
}
|
|
290
369
|
}
|
|
291
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
292
371
|
const docs = /* @__PURE__ */ new Map();
|
|
293
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
294
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
295
374
|
const doc = docAt(position);
|
|
296
375
|
if (doc) docs.set(name, doc);
|
|
297
376
|
}, skip, stripped);
|
|
298
377
|
for (const [name, doc] of themeDocs) {
|
|
299
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
300
379
|
}
|
|
301
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
302
381
|
}
|
|
303
382
|
var PROPERTY_DESCRIPTORS = [
|
|
304
383
|
["syntax", "syntax"],
|
|
@@ -376,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
376
455
|
return [...new Set(files.reverse())].reverse();
|
|
377
456
|
}
|
|
378
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
379
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
380
|
-
const
|
|
381
|
-
const
|
|
458
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
459
|
+
const normalized = normalizePatterns(patterns);
|
|
460
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
461
|
+
const ignore = compile([
|
|
462
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
463
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
464
|
+
]);
|
|
382
465
|
return (file) => {
|
|
383
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
384
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -389,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
389
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
390
473
|
const roots = /* @__PURE__ */ new Map();
|
|
391
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
392
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
393
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
394
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -423,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
423
507
|
})
|
|
424
508
|
);
|
|
425
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
426
511
|
const properties = /* @__PURE__ */ new Map();
|
|
427
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
428
513
|
const docs = /* @__PURE__ */ new Map();
|
|
429
514
|
for (const result of perFile) {
|
|
430
515
|
if (!result) continue;
|
|
431
|
-
for (const [name, value] of result.declarations)
|
|
516
|
+
for (const [name, value] of result.declarations) {
|
|
517
|
+
const isConditional = result.conditional.has(name);
|
|
518
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
519
|
+
declarations.set(name, value);
|
|
520
|
+
if (isConditional) conditional.add(name);
|
|
521
|
+
else conditional.delete(name);
|
|
522
|
+
}
|
|
432
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
433
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
434
525
|
for (const [theme, values] of result.themes) {
|
|
@@ -449,19 +540,46 @@ function rootPattern(text) {
|
|
|
449
540
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
450
541
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
451
542
|
}
|
|
452
|
-
var ACCESS_RE = /\s*(
|
|
543
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
453
544
|
function readAccess(text, from) {
|
|
454
545
|
ACCESS_RE.lastIndex = from;
|
|
455
546
|
const match = ACCESS_RE.exec(text);
|
|
456
547
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
457
548
|
}
|
|
549
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
550
|
+
function readPatternKeys(text, at) {
|
|
551
|
+
let i = at - 1;
|
|
552
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
553
|
+
if (text[i] !== "=") return [];
|
|
554
|
+
i--;
|
|
555
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
556
|
+
if (text[i] !== "}") return [];
|
|
557
|
+
const open = text.lastIndexOf("{", i);
|
|
558
|
+
if (open === -1) return [];
|
|
559
|
+
const body = text.slice(open + 1, i);
|
|
560
|
+
if (body.includes("}")) return [];
|
|
561
|
+
const keys = [];
|
|
562
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
563
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
564
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
565
|
+
}
|
|
566
|
+
return keys;
|
|
567
|
+
}
|
|
458
568
|
function extractUsage(text, into) {
|
|
459
569
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
460
570
|
const first = readAccess(text, root.index + root[0].length);
|
|
461
|
-
|
|
571
|
+
const second = first && readAccess(text, first.end);
|
|
572
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
573
|
+
if (!first) {
|
|
574
|
+
for (const key of destructured) {
|
|
575
|
+
into.keys.add(key);
|
|
576
|
+
into.wholeKeys.add(key);
|
|
577
|
+
}
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
462
580
|
into.keys.add(first.key);
|
|
463
|
-
const second = readAccess(text, first.end);
|
|
464
581
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
582
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
465
583
|
else into.wholeKeys.add(first.key);
|
|
466
584
|
}
|
|
467
585
|
}
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED