css-typed-vars 0.13.1 → 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 +6 -6
- package/dist/{chunk-3QCGO2EN.js → chunk-7J7UZYHB.js} +1 -1
- package/dist/{chunk-L2T4LBKN.js → chunk-BPZRXE6W.js} +105 -15
- package/dist/{chunk-DIGUOQES.js → chunk-VWEQJVXA.js} +1 -1
- package/dist/cli.cjs +109 -14
- package/dist/cli.js +8 -3
- package/dist/esbuild.cjs +103 -13
- 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 +97 -12
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +103 -13
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +103 -13
- package/dist/unplugin.d.cts +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +103 -13
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +103 -13
- 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/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -181,7 +181,18 @@ 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;
|
|
187
198
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -193,6 +204,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
193
204
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
194
205
|
}
|
|
195
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
|
+
}
|
|
196
256
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
197
257
|
for (const sel of selectors) {
|
|
198
258
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -209,11 +269,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
209
269
|
}
|
|
210
270
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
211
271
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
272
|
+
const conditional = conditionalRanges(stripped);
|
|
212
273
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
213
|
-
|
|
214
|
-
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);
|
|
215
279
|
});
|
|
216
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
|
+
}
|
|
217
293
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
218
294
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
219
295
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -269,15 +345,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
269
345
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
270
346
|
const values = /* @__PURE__ */ new Map();
|
|
271
347
|
themeValues.set(themeName, values);
|
|
272
|
-
const
|
|
348
|
+
const onProperty = (name, value, position) => {
|
|
273
349
|
values.set(name, value);
|
|
274
350
|
const doc = docAt(position);
|
|
275
351
|
if (doc) themeDocs.set(name, doc);
|
|
276
|
-
}
|
|
352
|
+
};
|
|
353
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
277
354
|
const selector = themeSelector.trim();
|
|
278
355
|
if (/^@media\b/i.test(selector)) {
|
|
279
356
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
280
357
|
skip.push(range);
|
|
358
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
281
359
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
282
360
|
});
|
|
283
361
|
} else {
|
|
@@ -287,17 +365,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
287
365
|
});
|
|
288
366
|
}
|
|
289
367
|
}
|
|
290
|
-
const declarations
|
|
368
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
291
369
|
const docs = /* @__PURE__ */ new Map();
|
|
292
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
293
|
-
|
|
370
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
371
|
+
if (!add(name, value, isConditional)) return;
|
|
294
372
|
const doc = docAt(position);
|
|
295
373
|
if (doc) docs.set(name, doc);
|
|
296
374
|
}, skip, stripped);
|
|
297
375
|
for (const [name, doc] of themeDocs) {
|
|
298
376
|
if (!docs.has(name)) docs.set(name, doc);
|
|
299
377
|
}
|
|
300
|
-
return { declarations, themes: themeValues, docs };
|
|
378
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
301
379
|
}
|
|
302
380
|
var PROPERTY_DESCRIPTORS = [
|
|
303
381
|
["syntax", "syntax"],
|
|
@@ -375,9 +453,13 @@ async function findFiles(patterns, exclude) {
|
|
|
375
453
|
return [...new Set(files.reverse())].reverse();
|
|
376
454
|
}
|
|
377
455
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
378
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
379
|
-
const
|
|
380
|
-
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
|
+
]);
|
|
381
463
|
return (file) => {
|
|
382
464
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
383
465
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -388,6 +470,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
388
470
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
389
471
|
const roots = /* @__PURE__ */ new Map();
|
|
390
472
|
for (const pattern of normalizePatterns(patterns)) {
|
|
473
|
+
if (pattern.startsWith("!")) continue;
|
|
391
474
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
392
475
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
393
476
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -422,12 +505,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
422
505
|
})
|
|
423
506
|
);
|
|
424
507
|
const declarations = /* @__PURE__ */ new Map();
|
|
508
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
425
509
|
const properties = /* @__PURE__ */ new Map();
|
|
426
510
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
427
511
|
const docs = /* @__PURE__ */ new Map();
|
|
428
512
|
for (const result of perFile) {
|
|
429
513
|
if (!result) continue;
|
|
430
|
-
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
|
+
}
|
|
431
521
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
432
522
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
433
523
|
for (const [theme, values] of result.themes) {
|
package/dist/unplugin.d.cts
CHANGED
package/dist/unplugin.d.ts
CHANGED
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -183,7 +183,18 @@ 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;
|
|
189
200
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -195,6 +206,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
195
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
196
207
|
}
|
|
197
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
|
+
}
|
|
198
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
199
259
|
for (const sel of selectors) {
|
|
200
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -211,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
211
271
|
}
|
|
212
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
213
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
214
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
215
|
-
|
|
216
|
-
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);
|
|
217
281
|
});
|
|
218
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
|
+
}
|
|
219
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
220
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
221
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -271,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
271
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
272
348
|
const values = /* @__PURE__ */ new Map();
|
|
273
349
|
themeValues.set(themeName, values);
|
|
274
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
275
351
|
values.set(name, value);
|
|
276
352
|
const doc = docAt(position);
|
|
277
353
|
if (doc) themeDocs.set(name, doc);
|
|
278
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
279
356
|
const selector = themeSelector.trim();
|
|
280
357
|
if (/^@media\b/i.test(selector)) {
|
|
281
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
282
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
283
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
284
362
|
});
|
|
285
363
|
} else {
|
|
@@ -289,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
289
367
|
});
|
|
290
368
|
}
|
|
291
369
|
}
|
|
292
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
293
371
|
const docs = /* @__PURE__ */ new Map();
|
|
294
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
295
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
296
374
|
const doc = docAt(position);
|
|
297
375
|
if (doc) docs.set(name, doc);
|
|
298
376
|
}, skip, stripped);
|
|
299
377
|
for (const [name, doc] of themeDocs) {
|
|
300
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
301
379
|
}
|
|
302
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
303
381
|
}
|
|
304
382
|
var PROPERTY_DESCRIPTORS = [
|
|
305
383
|
["syntax", "syntax"],
|
|
@@ -377,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
377
455
|
return [...new Set(files.reverse())].reverse();
|
|
378
456
|
}
|
|
379
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
380
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
381
|
-
const
|
|
382
|
-
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
|
+
]);
|
|
383
465
|
return (file) => {
|
|
384
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
385
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -390,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
390
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
391
473
|
const roots = /* @__PURE__ */ new Map();
|
|
392
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
393
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
394
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
395
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -424,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
424
507
|
})
|
|
425
508
|
);
|
|
426
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
427
511
|
const properties = /* @__PURE__ */ new Map();
|
|
428
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
429
513
|
const docs = /* @__PURE__ */ new Map();
|
|
430
514
|
for (const result of perFile) {
|
|
431
515
|
if (!result) continue;
|
|
432
|
-
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
|
+
}
|
|
433
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
434
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
435
525
|
for (const [theme, values] of result.themes) {
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -183,7 +183,18 @@ 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;
|
|
189
200
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -195,6 +206,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
195
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
196
207
|
}
|
|
197
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
|
+
}
|
|
198
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
199
259
|
for (const sel of selectors) {
|
|
200
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -211,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
211
271
|
}
|
|
212
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
213
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
214
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
215
|
-
|
|
216
|
-
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);
|
|
217
281
|
});
|
|
218
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
|
+
}
|
|
219
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
220
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
221
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -271,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
271
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
272
348
|
const values = /* @__PURE__ */ new Map();
|
|
273
349
|
themeValues.set(themeName, values);
|
|
274
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
275
351
|
values.set(name, value);
|
|
276
352
|
const doc = docAt(position);
|
|
277
353
|
if (doc) themeDocs.set(name, doc);
|
|
278
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
279
356
|
const selector = themeSelector.trim();
|
|
280
357
|
if (/^@media\b/i.test(selector)) {
|
|
281
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
282
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
283
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
284
362
|
});
|
|
285
363
|
} else {
|
|
@@ -289,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
289
367
|
});
|
|
290
368
|
}
|
|
291
369
|
}
|
|
292
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
293
371
|
const docs = /* @__PURE__ */ new Map();
|
|
294
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
295
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
296
374
|
const doc = docAt(position);
|
|
297
375
|
if (doc) docs.set(name, doc);
|
|
298
376
|
}, skip, stripped);
|
|
299
377
|
for (const [name, doc] of themeDocs) {
|
|
300
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
301
379
|
}
|
|
302
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
303
381
|
}
|
|
304
382
|
var PROPERTY_DESCRIPTORS = [
|
|
305
383
|
["syntax", "syntax"],
|
|
@@ -377,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
377
455
|
return [...new Set(files.reverse())].reverse();
|
|
378
456
|
}
|
|
379
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
380
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
381
|
-
const
|
|
382
|
-
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
|
+
]);
|
|
383
465
|
return (file) => {
|
|
384
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
385
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -390,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
390
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
391
473
|
const roots = /* @__PURE__ */ new Map();
|
|
392
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
393
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
394
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
395
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -424,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
424
507
|
})
|
|
425
508
|
);
|
|
426
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
427
511
|
const properties = /* @__PURE__ */ new Map();
|
|
428
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
429
513
|
const docs = /* @__PURE__ */ new Map();
|
|
430
514
|
for (const result of perFile) {
|
|
431
515
|
if (!result) continue;
|
|
432
|
-
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
|
+
}
|
|
433
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
434
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
435
525
|
for (const [theme, values] of result.themes) {
|