@unocss/vite 0.3.0 → 0.4.3
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/dist/index.d.ts +8 -2
- package/dist/index.js +430 -181
- package/dist/index.mjs +416 -169
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -258,8 +258,7 @@ var variantMatcher = (name, selector) => {
|
|
|
258
258
|
|
|
259
259
|
// ../preset-uno/src/rules/color.ts
|
|
260
260
|
import { hex2rgba } from "@unocss/core";
|
|
261
|
-
var
|
|
262
|
-
var _a;
|
|
261
|
+
var extractColor = (body) => {
|
|
263
262
|
const [main, opacity2] = body.split(/(?:\/|:)/);
|
|
264
263
|
const [name, no = "DEFAULT"] = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
|
|
265
264
|
if (!name)
|
|
@@ -270,6 +269,17 @@ var colorResolver = (attribute, varName) => ([, body], { theme: theme2 }) => {
|
|
|
270
269
|
color = bracket2.slice(1);
|
|
271
270
|
if (bracket2.startsWith("hex-"))
|
|
272
271
|
color = bracket2.slice(4);
|
|
272
|
+
return { opacity: opacity2, name, no, color };
|
|
273
|
+
};
|
|
274
|
+
var colorResolver = (attribute, varName) => ([, body], { theme: theme2 }) => {
|
|
275
|
+
var _a;
|
|
276
|
+
const data = extractColor(body);
|
|
277
|
+
if (!data)
|
|
278
|
+
return;
|
|
279
|
+
const { opacity: opacity2, name, no, color } = data;
|
|
280
|
+
if (!name)
|
|
281
|
+
return;
|
|
282
|
+
let useColor = color;
|
|
273
283
|
if (!color) {
|
|
274
284
|
if (name === "transparent") {
|
|
275
285
|
return {
|
|
@@ -284,13 +294,13 @@ var colorResolver = (attribute, varName) => ([, body], { theme: theme2 }) => {
|
|
|
284
294
|
[attribute]: "currentColor"
|
|
285
295
|
};
|
|
286
296
|
}
|
|
287
|
-
|
|
288
|
-
if (no &&
|
|
289
|
-
|
|
297
|
+
useColor = (_a = theme2.colors) == null ? void 0 : _a[name];
|
|
298
|
+
if (no && useColor && typeof useColor !== "string")
|
|
299
|
+
useColor = useColor[no];
|
|
290
300
|
}
|
|
291
|
-
if (typeof
|
|
301
|
+
if (typeof useColor !== "string")
|
|
292
302
|
return;
|
|
293
|
-
const rgba = hex2rgba(
|
|
303
|
+
const rgba = hex2rgba(useColor);
|
|
294
304
|
if (rgba) {
|
|
295
305
|
const a = opacity2 ? opacity2[0] === "[" ? handler.bracket.percent(opacity2) : parseFloat(opacity2) / 100 : rgba[3];
|
|
296
306
|
if (a != null && !Number.isNaN(a)) {
|
|
@@ -372,6 +382,174 @@ function handlerRounded([, a, b], { theme: theme2 }) {
|
|
|
372
382
|
return cornerMap[d].map((i) => [`border${i}-radius`, v]);
|
|
373
383
|
}
|
|
374
384
|
|
|
385
|
+
// ../preset-uno/src/rules/background.ts
|
|
386
|
+
import { hex2rgba as hex2rgba2 } from "@unocss/core";
|
|
387
|
+
var colorResolver2 = (mode) => ([, body], { theme: theme2 }) => {
|
|
388
|
+
var _a;
|
|
389
|
+
const data = extractColor(body);
|
|
390
|
+
if (!data)
|
|
391
|
+
return;
|
|
392
|
+
const { opacity: opacity2, name, no, color } = data;
|
|
393
|
+
if (!name)
|
|
394
|
+
return;
|
|
395
|
+
let useColor = color;
|
|
396
|
+
if (!color) {
|
|
397
|
+
if (name === "transparent") {
|
|
398
|
+
switch (mode) {
|
|
399
|
+
case "from":
|
|
400
|
+
return {
|
|
401
|
+
"--un-gradient-from": "transparent",
|
|
402
|
+
"--un-gradient-stops": "var(--un-gradient-from), var(--un-gradient-to, rgba(255, 255, 255, 0))"
|
|
403
|
+
};
|
|
404
|
+
case "via":
|
|
405
|
+
return {
|
|
406
|
+
"--un-gradient-stops": "var(--un-gradient-from), transparent, var(--un-gradient-to, rgba(255, 255, 255, 0))"
|
|
407
|
+
};
|
|
408
|
+
case "to":
|
|
409
|
+
return {
|
|
410
|
+
"--un-gradient-to": "transparent"
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
} else if (name === "current") {
|
|
414
|
+
switch (mode) {
|
|
415
|
+
case "from":
|
|
416
|
+
return {
|
|
417
|
+
"--un-gradient-from": "currentColor",
|
|
418
|
+
"--un-gradient-stops": "var(--un-gradient-from), var(--un-gradient-to, rgba(255, 255, 255, 0))"
|
|
419
|
+
};
|
|
420
|
+
case "via":
|
|
421
|
+
return {
|
|
422
|
+
"--un-gradient-stops": "var(--un-gradient-from), currentColor, var(--un-gradient-to, rgba(255, 255, 255, 0))"
|
|
423
|
+
};
|
|
424
|
+
case "to":
|
|
425
|
+
return {
|
|
426
|
+
"--un-gradient-to": "currentColor"
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
useColor = (_a = theme2.colors) == null ? void 0 : _a[name];
|
|
431
|
+
if (no && useColor && typeof useColor !== "string")
|
|
432
|
+
useColor = useColor[no];
|
|
433
|
+
}
|
|
434
|
+
if (typeof useColor !== "string")
|
|
435
|
+
return;
|
|
436
|
+
const rgba = hex2rgba2(useColor);
|
|
437
|
+
if (rgba) {
|
|
438
|
+
const a = opacity2 ? opacity2[0] === "[" ? handler.bracket.percent(opacity2) : parseFloat(opacity2) / 100 : rgba[3];
|
|
439
|
+
if (a != null && !Number.isNaN(a)) {
|
|
440
|
+
rgba[3] = typeof a === "string" && !a.includes("%") ? parseFloat(a) : a;
|
|
441
|
+
useColor = rgba.join(",");
|
|
442
|
+
} else {
|
|
443
|
+
useColor = rgba.slice(0, 3).join(",");
|
|
444
|
+
}
|
|
445
|
+
switch (mode) {
|
|
446
|
+
case "from":
|
|
447
|
+
return {
|
|
448
|
+
"--un-gradient-from": `rgba(${useColor}, var(--un-from-opacity, 1))`,
|
|
449
|
+
"--un-gradient-stops": "var(--un-gradient-from), var(--un-gradient-to, rgba(255, 255, 255, 0))"
|
|
450
|
+
};
|
|
451
|
+
case "via":
|
|
452
|
+
return {
|
|
453
|
+
"--un-gradient-stops": `var(--un-gradient-from), rgba(${useColor}, var(--un-via-opacity, 1)), var(--un-gradient-to, rgba(255, 255, 255, 0))`
|
|
454
|
+
};
|
|
455
|
+
case "to":
|
|
456
|
+
return {
|
|
457
|
+
"--un-gradient-to": `rgba(${useColor}, var(--un-to-opacity, 1))`
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
var bgAttachments = [
|
|
463
|
+
["bg-fixed", { "background-attachment": "fixed" }],
|
|
464
|
+
["bg-local", { "background-attachment": "local" }],
|
|
465
|
+
["bg-scroll", { "background-attachment": "scroll" }]
|
|
466
|
+
];
|
|
467
|
+
var bgBlendModes = [
|
|
468
|
+
["bg-blend-normal", { "background-blend-mode": "normal" }],
|
|
469
|
+
["bg-blend-multiply", { "background-blend-mode": "multiply" }],
|
|
470
|
+
["bg-blend-screen", { "background-blend-mode": "screen" }],
|
|
471
|
+
["bg-blend-overlay", { "background-blend-mode": "overlay" }],
|
|
472
|
+
["bg-blend-darken", { "background-blend-mode": "darken" }],
|
|
473
|
+
["bg-blend-lighten", { "background-blend-mode": "lighten" }],
|
|
474
|
+
["bg-blend-color-dodge", { "background-blend-mode": "color-dodge" }],
|
|
475
|
+
["bg-blend-color-burn", { "background-blend-mode": "color-burn" }],
|
|
476
|
+
["bg-blend-hard-light", { "background-blend-mode": "hard-light" }],
|
|
477
|
+
["bg-blend-soft-light", { "background-blend-mode": "soft-light" }],
|
|
478
|
+
["bg-blend-difference", { "background-blend-mode": "difference" }],
|
|
479
|
+
["bg-blend-exclusion", { "background-blend-mode": "exclusion" }],
|
|
480
|
+
["bg-blend-hue", { "background-blend-mode": "hue" }],
|
|
481
|
+
["bg-blend-saturation", { "background-blend-mode": "saturation" }],
|
|
482
|
+
["bg-blend-color", { "background-blend-mode": "color" }],
|
|
483
|
+
["bg-blend-luminosity", { "background-blend-mode": "luminosity" }]
|
|
484
|
+
];
|
|
485
|
+
var bgClips = [
|
|
486
|
+
["bg-clip-border", { "-webkit-background-clip": "border-box", "background-attachment": "border-box" }],
|
|
487
|
+
["bg-clip-content", { "-webkit-background-clip": "content-box", "background-attachment": "content-box" }],
|
|
488
|
+
["bg-clip-padding", { "-webkit-background-clip": "padding-box", "background-attachment": "padding-box" }],
|
|
489
|
+
["bg-clip-text", { "-webkit-background-clip": "text", "background-attachment": "text" }]
|
|
490
|
+
];
|
|
491
|
+
var bgGradients = [
|
|
492
|
+
[/^from-(.+)$/, colorResolver2("from")],
|
|
493
|
+
[/^to-(.+)$/, colorResolver2("to")],
|
|
494
|
+
[/^via-(.+)$/, colorResolver2("via")]
|
|
495
|
+
];
|
|
496
|
+
var bgImages = [
|
|
497
|
+
["bg-none", { "background-image": "none" }],
|
|
498
|
+
["bg-gradient-to-t", {
|
|
499
|
+
"background-image": "linear-gradient(to top, var(--un-gradient-stops))"
|
|
500
|
+
}],
|
|
501
|
+
["bg-gradient-to-tr", {
|
|
502
|
+
"background-image": "linear-gradient(to top right, var(--un-gradient-stops))"
|
|
503
|
+
}],
|
|
504
|
+
["bg-gradient-to-r", {
|
|
505
|
+
"background-image": "linear-gradient(to right, var(--un-gradient-stops))"
|
|
506
|
+
}],
|
|
507
|
+
["bg-gradient-to-br", {
|
|
508
|
+
"background-image": "linear-gradient(to bottom right, var(--un-gradient-stops))"
|
|
509
|
+
}],
|
|
510
|
+
["bg-gradient-to-b", {
|
|
511
|
+
"background-image": "linear-gradient(to bottom, var(--un-gradient-stops))"
|
|
512
|
+
}],
|
|
513
|
+
["bg-gradient-to-bl", {
|
|
514
|
+
"background-image": "linear-gradient(to bottom left, var(--un-gradient-stops))"
|
|
515
|
+
}],
|
|
516
|
+
["bg-gradient-to-l", {
|
|
517
|
+
"background-image": "linear-gradient(to left, var(--un-gradient-stops))"
|
|
518
|
+
}],
|
|
519
|
+
["bg-gradient-to-tl", {
|
|
520
|
+
"background-image": "linear-gradient(to top left, var(--un-gradient-stops))"
|
|
521
|
+
}]
|
|
522
|
+
];
|
|
523
|
+
var bgOrigins = [
|
|
524
|
+
["bg-origin-border", { "background-origin": "border-box" }],
|
|
525
|
+
["bg-origin-padding", { "background-origin": "padding-box" }],
|
|
526
|
+
["bg-origin-content", { "background-origin": "content-box" }]
|
|
527
|
+
];
|
|
528
|
+
var bgPositions = [
|
|
529
|
+
["bg-bottom", { "background-position": "bottom" }],
|
|
530
|
+
["bg-center", { "background-position": "center" }],
|
|
531
|
+
["bg-left", { "background-position": "left" }],
|
|
532
|
+
["bg-left-bottom", { "background-position": "left bottom" }],
|
|
533
|
+
["bg-left-top", { "background-position": "left top" }],
|
|
534
|
+
["bg-right", { "background-position": "right" }],
|
|
535
|
+
["bg-right-bottom", { "background-position": "right bottom" }],
|
|
536
|
+
["bg-right-top", { "background-position": "right top" }],
|
|
537
|
+
["bg-top", { "background-position": "top" }]
|
|
538
|
+
];
|
|
539
|
+
var bgRepeats = [
|
|
540
|
+
["bg-repeat", { "background-repeat": "repeat" }],
|
|
541
|
+
["bg-no-repeat", { "background-repeat": "no-repeat" }],
|
|
542
|
+
["bg-repeat-x", { "background-position": "repeat-x" }],
|
|
543
|
+
["bg-repeat-y", { "background-position": "repeat-y" }],
|
|
544
|
+
["bg-repeat-round", { "background-position": "round" }],
|
|
545
|
+
["bg-repeat-space", { "background-position": "space" }]
|
|
546
|
+
];
|
|
547
|
+
var bgSizes = [
|
|
548
|
+
["bg-auto", { "background-size": "auto" }],
|
|
549
|
+
["bg-cover", { "background-repeat": "cover" }],
|
|
550
|
+
["bg-contain", { "background-position": "contain" }]
|
|
551
|
+
];
|
|
552
|
+
|
|
375
553
|
// ../preset-uno/src/rules/filters.ts
|
|
376
554
|
var filterContnet = "var(--un-blur) var(--un-brightness) var(--un-contrast) var(--un-grayscale) var(--un-hue-rotate) var(--un-invert) var(--un-saturate) var(--un-sepia) var(--un-drop-shadow)";
|
|
377
555
|
var init = {
|
|
@@ -883,7 +1061,16 @@ var rules = [
|
|
|
883
1061
|
margins,
|
|
884
1062
|
displays,
|
|
885
1063
|
opacity,
|
|
1064
|
+
bgAttachments,
|
|
1065
|
+
bgBlendModes,
|
|
1066
|
+
bgClips,
|
|
886
1067
|
bgColors,
|
|
1068
|
+
bgGradients,
|
|
1069
|
+
bgImages,
|
|
1070
|
+
bgOrigins,
|
|
1071
|
+
bgPositions,
|
|
1072
|
+
bgSizes,
|
|
1073
|
+
bgRepeats,
|
|
887
1074
|
borders,
|
|
888
1075
|
fonts,
|
|
889
1076
|
textOverflows,
|
|
@@ -1376,17 +1563,7 @@ var variantColorsClass = [
|
|
|
1376
1563
|
|
|
1377
1564
|
// ../preset-uno/src/variants/pseudo.ts
|
|
1378
1565
|
import { toArray as toArray3 } from "@unocss/core";
|
|
1379
|
-
|
|
1380
|
-
return [
|
|
1381
|
-
variantMatcher(name, (input) => `${input}:${pseudo}`),
|
|
1382
|
-
variantMatcher(`not-${name}`, (input) => `${input}:not(:${pseudo})`),
|
|
1383
|
-
variantMatcher(`group-${name}`, (input) => `.group:${pseudo} ${input}`)
|
|
1384
|
-
];
|
|
1385
|
-
}
|
|
1386
|
-
function createPseudoElementVariant(name) {
|
|
1387
|
-
return variantMatcher(name, (input) => `${input}::${name}`);
|
|
1388
|
-
}
|
|
1389
|
-
var variantPseudoClasses = [
|
|
1566
|
+
var PseudoClasses = Object.fromEntries([
|
|
1390
1567
|
"active",
|
|
1391
1568
|
"checked",
|
|
1392
1569
|
"default",
|
|
@@ -1418,14 +1595,57 @@ var variantPseudoClasses = [
|
|
|
1418
1595
|
["even", "nth-child(even)"],
|
|
1419
1596
|
["odd-of-type", "nth-of-type(odd)"],
|
|
1420
1597
|
["odd", "nth-child(odd)"]
|
|
1421
|
-
].
|
|
1422
|
-
var
|
|
1598
|
+
].map(toArray3));
|
|
1599
|
+
var PseudoElements = [
|
|
1423
1600
|
"before",
|
|
1424
1601
|
"after",
|
|
1425
1602
|
"first-letter",
|
|
1426
1603
|
"first-line",
|
|
1427
1604
|
"selection"
|
|
1428
|
-
]
|
|
1605
|
+
];
|
|
1606
|
+
var PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
|
|
1607
|
+
var PseudoClassesStr = Object.keys(PseudoClasses).join("|");
|
|
1608
|
+
var PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
|
|
1609
|
+
var PseudoClassesNotRE = new RegExp(`^not-(${PseudoClassesStr})[:-]`);
|
|
1610
|
+
var PseudoClassesGroupRE = new RegExp(`^group-(${PseudoClassesStr})[:-]`);
|
|
1611
|
+
var variantPseudoElements = (input) => {
|
|
1612
|
+
const match = input.match(PseudoElementsRE);
|
|
1613
|
+
if (match) {
|
|
1614
|
+
return {
|
|
1615
|
+
matcher: input.slice(match[1].length + 1),
|
|
1616
|
+
selector: (input2) => `${input2}::${match[1]}`
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
var variantPseudoClasses = {
|
|
1621
|
+
match: (input) => {
|
|
1622
|
+
let match = input.match(PseudoClassesRE);
|
|
1623
|
+
if (match) {
|
|
1624
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
1625
|
+
return {
|
|
1626
|
+
matcher: input.slice(match[1].length + 1),
|
|
1627
|
+
selector: (input2) => `${input2}:${pseudo}`
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
match = input.match(PseudoClassesNotRE);
|
|
1631
|
+
if (match) {
|
|
1632
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
1633
|
+
return {
|
|
1634
|
+
matcher: input.slice(match[1].length + 5),
|
|
1635
|
+
selector: (input2) => `${input2}:not(:${pseudo})`
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
match = input.match(PseudoClassesGroupRE);
|
|
1639
|
+
if (match) {
|
|
1640
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
1641
|
+
return {
|
|
1642
|
+
matcher: input.slice(match[1].length + 7),
|
|
1643
|
+
selector: (input2) => `.group:${pseudo} ${input2}`
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
},
|
|
1647
|
+
multiPass: true
|
|
1648
|
+
};
|
|
1429
1649
|
|
|
1430
1650
|
// ../preset-uno/src/variants/index.ts
|
|
1431
1651
|
var variantImportant = {
|
|
@@ -1467,8 +1687,8 @@ var variants = [
|
|
|
1467
1687
|
variantBreakpoints,
|
|
1468
1688
|
...variantChildren,
|
|
1469
1689
|
...variantColorsClass,
|
|
1470
|
-
|
|
1471
|
-
|
|
1690
|
+
variantPseudoClasses,
|
|
1691
|
+
variantPseudoElements
|
|
1472
1692
|
];
|
|
1473
1693
|
|
|
1474
1694
|
// ../preset-uno/src/index.ts
|
|
@@ -1489,7 +1709,7 @@ var strippedPrefixes = [
|
|
|
1489
1709
|
":"
|
|
1490
1710
|
];
|
|
1491
1711
|
var splitterRE = /[\s'"`;]+/g;
|
|
1492
|
-
var elementRE = /<[\w:\.$-]+\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
1712
|
+
var elementRE = /<[\w][\w:\.$-]+\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
1493
1713
|
var valuedAttributeRE = /([\w:-]+)(?:=(["'])([^\2]+?)\2)?/g;
|
|
1494
1714
|
var extractorAttributify = (options) => (code) => {
|
|
1495
1715
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
@@ -1585,7 +1805,7 @@ function createContext(uno, config, configFilepath) {
|
|
|
1585
1805
|
};
|
|
1586
1806
|
}
|
|
1587
1807
|
|
|
1588
|
-
// src/chunk-build.ts
|
|
1808
|
+
// src/modes/chunk-build.ts
|
|
1589
1809
|
import { createFilter } from "@rollup/pluginutils";
|
|
1590
1810
|
|
|
1591
1811
|
// src/utils.ts
|
|
@@ -1596,7 +1816,7 @@ function getHash(input, length = 8) {
|
|
|
1596
1816
|
return createHash("sha256").update(input).digest("hex").substr(0, length);
|
|
1597
1817
|
}
|
|
1598
1818
|
|
|
1599
|
-
// src/chunk-build.ts
|
|
1819
|
+
// src/modes/chunk-build.ts
|
|
1600
1820
|
function ChunkModeBuildPlugin({ uno, config }) {
|
|
1601
1821
|
let cssPlugin;
|
|
1602
1822
|
const filter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
@@ -1640,27 +1860,103 @@ function ChunkModeBuildPlugin({ uno, config }) {
|
|
|
1640
1860
|
};
|
|
1641
1861
|
}
|
|
1642
1862
|
|
|
1643
|
-
// src/global
|
|
1863
|
+
// src/modes/global/build.ts
|
|
1644
1864
|
import { createFilter as createFilter2 } from "@rollup/pluginutils";
|
|
1865
|
+
|
|
1866
|
+
// src/modes/global/shared.ts
|
|
1645
1867
|
var VIRTUAL_ENTRY = "/@unocss-entry.css";
|
|
1868
|
+
var VIRTUAL_ENTRY_ALIAS = [
|
|
1869
|
+
"/@unocss-entry.css",
|
|
1870
|
+
"uno.css",
|
|
1871
|
+
"virtual:uno.css"
|
|
1872
|
+
];
|
|
1646
1873
|
var READY_CALLBACK = "/__unocss_ready";
|
|
1647
|
-
var
|
|
1874
|
+
var PLACEHOLDER = "#--unocss--{--unocss:true}";
|
|
1875
|
+
var PLACEHOLDER_RE = /#--unocss--\s*{\s*--unocss:\s*true;?\s*}/;
|
|
1876
|
+
|
|
1877
|
+
// src/modes/global/build.ts
|
|
1878
|
+
function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
1879
|
+
const filter = createFilter2(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
1880
|
+
const tasks = [];
|
|
1881
|
+
return [
|
|
1882
|
+
{
|
|
1883
|
+
name: "unocss:global:build:scan",
|
|
1884
|
+
apply: "build",
|
|
1885
|
+
enforce: "pre",
|
|
1886
|
+
transform(code, id) {
|
|
1887
|
+
if (filter(id))
|
|
1888
|
+
tasks.push(scan(code, id));
|
|
1889
|
+
return null;
|
|
1890
|
+
},
|
|
1891
|
+
transformIndexHtml: {
|
|
1892
|
+
enforce: "pre",
|
|
1893
|
+
transform(code, { path }) {
|
|
1894
|
+
tasks.push(scan(code, path));
|
|
1895
|
+
}
|
|
1896
|
+
},
|
|
1897
|
+
resolveId(id) {
|
|
1898
|
+
return VIRTUAL_ENTRY_ALIAS.includes(id) ? VIRTUAL_ENTRY : null;
|
|
1899
|
+
},
|
|
1900
|
+
async load(id) {
|
|
1901
|
+
if (id !== VIRTUAL_ENTRY)
|
|
1902
|
+
return null;
|
|
1903
|
+
return PLACEHOLDER;
|
|
1904
|
+
}
|
|
1905
|
+
},
|
|
1906
|
+
{
|
|
1907
|
+
name: "unocss:global:build:generate",
|
|
1908
|
+
apply(options, { command }) {
|
|
1909
|
+
var _a;
|
|
1910
|
+
return command === "build" && !((_a = options.build) == null ? void 0 : _a.ssr);
|
|
1911
|
+
},
|
|
1912
|
+
enforce: "post",
|
|
1913
|
+
async generateBundle(options, bundle) {
|
|
1914
|
+
const files = Object.keys(bundle).filter((i) => i.endsWith(".css"));
|
|
1915
|
+
if (!files.length)
|
|
1916
|
+
return;
|
|
1917
|
+
await Promise.all(tasks);
|
|
1918
|
+
const { css } = await uno.generate(tokens);
|
|
1919
|
+
let replaced = false;
|
|
1920
|
+
if (!css)
|
|
1921
|
+
return;
|
|
1922
|
+
for (const file of files) {
|
|
1923
|
+
const chunk = bundle[file];
|
|
1924
|
+
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
1925
|
+
if (PLACEHOLDER_RE.test(chunk.source)) {
|
|
1926
|
+
chunk.source = chunk.source.replace(PLACEHOLDER_RE, css);
|
|
1927
|
+
replaced = true;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (!replaced)
|
|
1932
|
+
this.error(new Error("[unocss] does not found CSS placeholder in the generated chunks,\nthis is likely an internal bug of unocss vite plugin"));
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
];
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
// src/modes/global/dev.ts
|
|
1939
|
+
import { createFilter as createFilter3 } from "@rollup/pluginutils";
|
|
1940
|
+
var WARN_TIMEOUT = 2e3;
|
|
1648
1941
|
function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
1649
1942
|
let server;
|
|
1650
|
-
const filter =
|
|
1943
|
+
const filter = createFilter3(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
1651
1944
|
const tasks = [];
|
|
1652
|
-
let
|
|
1653
|
-
let lastUpdate =
|
|
1654
|
-
|
|
1945
|
+
let invalidateTimer;
|
|
1946
|
+
let lastUpdate = Date.now();
|
|
1947
|
+
let lastServed = 0;
|
|
1948
|
+
let resolved = false;
|
|
1949
|
+
let resolvedWarnTimer;
|
|
1950
|
+
function invalidate(timer = 10) {
|
|
1655
1951
|
if (!server)
|
|
1656
1952
|
return;
|
|
1657
1953
|
const mod = server.moduleGraph.getModuleById(VIRTUAL_ENTRY);
|
|
1658
1954
|
if (!mod)
|
|
1659
1955
|
return;
|
|
1660
|
-
lastUpdate =
|
|
1956
|
+
lastUpdate = Date.now();
|
|
1661
1957
|
server.moduleGraph.invalidateModule(mod);
|
|
1662
|
-
clearTimeout(
|
|
1663
|
-
|
|
1958
|
+
clearTimeout(invalidateTimer);
|
|
1959
|
+
invalidateTimer = setTimeout(sendUpdate, timer);
|
|
1664
1960
|
}
|
|
1665
1961
|
function sendUpdate() {
|
|
1666
1962
|
server.ws.send({
|
|
@@ -1673,69 +1969,97 @@ function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
|
1673
1969
|
}]
|
|
1674
1970
|
});
|
|
1675
1971
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
server = _server;
|
|
1687
|
-
server.middlewares.use(async (req, res, next) => {
|
|
1688
|
-
if (req.url === READY_CALLBACK) {
|
|
1689
|
-
sendUpdate();
|
|
1690
|
-
res.statusCode = 200;
|
|
1691
|
-
res.end();
|
|
1692
|
-
} else {
|
|
1693
|
-
return next();
|
|
1972
|
+
function setWarnTimer() {
|
|
1973
|
+
if (!resolved && !resolvedWarnTimer) {
|
|
1974
|
+
resolvedWarnTimer = setTimeout(() => {
|
|
1975
|
+
if (!resolved) {
|
|
1976
|
+
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
1977
|
+
console.warn(msg);
|
|
1978
|
+
server.ws.send({
|
|
1979
|
+
type: "error",
|
|
1980
|
+
err: { message: msg, stack: "" }
|
|
1981
|
+
});
|
|
1694
1982
|
}
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1983
|
+
}, WARN_TIMEOUT);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
onInvalidate(invalidate);
|
|
1987
|
+
return [
|
|
1988
|
+
{
|
|
1989
|
+
name: "unocss:global",
|
|
1990
|
+
apply: "serve",
|
|
1991
|
+
enforce: "pre",
|
|
1992
|
+
configureServer(_server) {
|
|
1993
|
+
server = _server;
|
|
1994
|
+
server.middlewares.use(async (req, res, next) => {
|
|
1995
|
+
var _a;
|
|
1996
|
+
setWarnTimer();
|
|
1997
|
+
if ((_a = req.url) == null ? void 0 : _a.startsWith(READY_CALLBACK)) {
|
|
1998
|
+
const servedTime = +req.url.slice(READY_CALLBACK.length + 1);
|
|
1999
|
+
if (servedTime < lastUpdate)
|
|
2000
|
+
invalidate(0);
|
|
2001
|
+
res.statusCode = 200;
|
|
2002
|
+
res.end();
|
|
2003
|
+
} else {
|
|
2004
|
+
return next();
|
|
1707
2005
|
}
|
|
1708
|
-
};
|
|
2006
|
+
});
|
|
2007
|
+
},
|
|
2008
|
+
transform(code, id) {
|
|
2009
|
+
if (filter(id))
|
|
2010
|
+
scan(code, id);
|
|
2011
|
+
return null;
|
|
2012
|
+
},
|
|
2013
|
+
transformIndexHtml: {
|
|
2014
|
+
enforce: "pre",
|
|
2015
|
+
transform(code, { path }) {
|
|
2016
|
+
scan(code, path);
|
|
2017
|
+
}
|
|
2018
|
+
},
|
|
2019
|
+
resolveId(id) {
|
|
2020
|
+
if (VIRTUAL_ENTRY_ALIAS.includes(id)) {
|
|
2021
|
+
resolved = true;
|
|
2022
|
+
return VIRTUAL_ENTRY;
|
|
2023
|
+
}
|
|
2024
|
+
},
|
|
2025
|
+
async load(id) {
|
|
2026
|
+
if (id !== VIRTUAL_ENTRY)
|
|
2027
|
+
return null;
|
|
2028
|
+
await Promise.all(tasks);
|
|
2029
|
+
const { css } = await uno.generate(tokens);
|
|
2030
|
+
lastServed = Date.now();
|
|
2031
|
+
return css;
|
|
1709
2032
|
}
|
|
1710
|
-
return null;
|
|
1711
2033
|
},
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
2034
|
+
{
|
|
2035
|
+
name: "unocss:global:post",
|
|
2036
|
+
apply: "serve",
|
|
2037
|
+
enforce: "post",
|
|
2038
|
+
transform(code, id) {
|
|
2039
|
+
if (id === VIRTUAL_ENTRY)
|
|
2040
|
+
return `${code}
|
|
2041
|
+
await fetch("${READY_CALLBACK}/${lastServed}")`;
|
|
1716
2042
|
}
|
|
1717
|
-
},
|
|
1718
|
-
resolveId(id) {
|
|
1719
|
-
return id === VIRTUAL_ENTRY ? id : null;
|
|
1720
|
-
},
|
|
1721
|
-
async load(id) {
|
|
1722
|
-
if (id !== VIRTUAL_ENTRY)
|
|
1723
|
-
return null;
|
|
1724
|
-
await Promise.all(tasks);
|
|
1725
|
-
const { css } = await uno.generate(tokens);
|
|
1726
|
-
return css;
|
|
1727
2043
|
}
|
|
1728
|
-
|
|
2044
|
+
];
|
|
1729
2045
|
}
|
|
1730
2046
|
|
|
1731
|
-
// src/
|
|
1732
|
-
|
|
2047
|
+
// src/modes/global/index.ts
|
|
2048
|
+
function GlobalModePlugin(ctx) {
|
|
2049
|
+
return [
|
|
2050
|
+
...GlobalModeBuildPlugin(ctx),
|
|
2051
|
+
...GlobalModeDevPlugin(ctx)
|
|
2052
|
+
];
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// src/modes/per-module.ts
|
|
2056
|
+
import { createFilter as createFilter4 } from "@rollup/pluginutils";
|
|
1733
2057
|
var VIRTUAL_PREFIX = "/@unocss/";
|
|
1734
2058
|
var SCOPE_IMPORT_RE = / from (['"])(@unocss\/scope)\1/;
|
|
1735
2059
|
function PerModuleModePlugin({ uno, config }) {
|
|
1736
2060
|
const moduleMap = new Map();
|
|
1737
2061
|
let server;
|
|
1738
|
-
const filter =
|
|
2062
|
+
const filter = createFilter4(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
1739
2063
|
const invalidate = (hash) => {
|
|
1740
2064
|
if (!server)
|
|
1741
2065
|
return;
|
|
@@ -1794,10 +2118,10 @@ ${css}`;
|
|
|
1794
2118
|
};
|
|
1795
2119
|
}
|
|
1796
2120
|
|
|
1797
|
-
// src/vue-scoped.ts
|
|
1798
|
-
import { createFilter as
|
|
2121
|
+
// src/modes/vue-scoped.ts
|
|
2122
|
+
import { createFilter as createFilter5 } from "@rollup/pluginutils";
|
|
1799
2123
|
function VueScopedPlugin({ uno, config }) {
|
|
1800
|
-
const filter =
|
|
2124
|
+
const filter = createFilter5(config.include || [/\.vue$/], config.exclude || defaultExclude);
|
|
1801
2125
|
async function transformSFC(code) {
|
|
1802
2126
|
const { css } = await uno.generate(code);
|
|
1803
2127
|
if (!css)
|
|
@@ -1825,85 +2149,6 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
1825
2149
|
};
|
|
1826
2150
|
}
|
|
1827
2151
|
|
|
1828
|
-
// src/global-build.ts
|
|
1829
|
-
import { createFilter as createFilter5 } from "@rollup/pluginutils";
|
|
1830
|
-
var VIRTUAL_ENTRY2 = "/@unocss-entry.css";
|
|
1831
|
-
var PLACEHOLDER = "#--unocss--{--unocss:true}";
|
|
1832
|
-
var PLACEHOLDER_RE = /#--unocss--\s*{\s*--unocss:\s*true;?\s*}/;
|
|
1833
|
-
var JS_RE2 = /\.[mc]?[tj]sx?$/;
|
|
1834
|
-
function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
1835
|
-
const filter = createFilter5(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
1836
|
-
let mainEntry;
|
|
1837
|
-
const tasks = [];
|
|
1838
|
-
return [
|
|
1839
|
-
{
|
|
1840
|
-
name: "unocss:global:build:scan",
|
|
1841
|
-
apply: "build",
|
|
1842
|
-
enforce: "pre",
|
|
1843
|
-
buildStart() {
|
|
1844
|
-
mainEntry = void 0;
|
|
1845
|
-
},
|
|
1846
|
-
transform(code, id) {
|
|
1847
|
-
if (filter(id))
|
|
1848
|
-
tasks.push(scan(code, id));
|
|
1849
|
-
if (mainEntry === id || mainEntry == null && !id.includes("node_modules/vite") && JS_RE2.test(id) && id.startsWith("/")) {
|
|
1850
|
-
mainEntry = id;
|
|
1851
|
-
return {
|
|
1852
|
-
code: `${code};import '${VIRTUAL_ENTRY2}';`,
|
|
1853
|
-
map: {
|
|
1854
|
-
mappings: ""
|
|
1855
|
-
}
|
|
1856
|
-
};
|
|
1857
|
-
}
|
|
1858
|
-
return null;
|
|
1859
|
-
},
|
|
1860
|
-
transformIndexHtml: {
|
|
1861
|
-
enforce: "pre",
|
|
1862
|
-
transform(code, { path }) {
|
|
1863
|
-
tasks.push(scan(code, path));
|
|
1864
|
-
}
|
|
1865
|
-
},
|
|
1866
|
-
resolveId(id) {
|
|
1867
|
-
return id === VIRTUAL_ENTRY2 ? id : null;
|
|
1868
|
-
},
|
|
1869
|
-
async load(id) {
|
|
1870
|
-
if (id !== VIRTUAL_ENTRY2)
|
|
1871
|
-
return null;
|
|
1872
|
-
return PLACEHOLDER;
|
|
1873
|
-
}
|
|
1874
|
-
},
|
|
1875
|
-
{
|
|
1876
|
-
name: "unocss:global:build:generate",
|
|
1877
|
-
apply(options, { command }) {
|
|
1878
|
-
var _a;
|
|
1879
|
-
return command === "build" && !((_a = options.build) == null ? void 0 : _a.ssr);
|
|
1880
|
-
},
|
|
1881
|
-
enforce: "post",
|
|
1882
|
-
async generateBundle(options, bundle) {
|
|
1883
|
-
const files = Object.keys(bundle).filter((i) => i.endsWith(".css"));
|
|
1884
|
-
if (!files.length)
|
|
1885
|
-
return;
|
|
1886
|
-
await Promise.all(tasks);
|
|
1887
|
-
const { css } = await uno.generate(tokens);
|
|
1888
|
-
let replaced = false;
|
|
1889
|
-
if (!css)
|
|
1890
|
-
return;
|
|
1891
|
-
for (const file of files) {
|
|
1892
|
-
const chunk = bundle[file];
|
|
1893
|
-
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
1894
|
-
if (PLACEHOLDER_RE.test(chunk.source)) {
|
|
1895
|
-
chunk.source = chunk.source.replace(PLACEHOLDER_RE, css);
|
|
1896
|
-
replaced = true;
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
if (!replaced)
|
|
1901
|
-
this.error(new Error("[unocss] does not found CSS placeholder in the generated chunks,\nthis is likely an internal bug of unocss vite plugin"));
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
];
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
2152
|
// src/config-hmr.ts
|
|
1908
2153
|
import { loadConfig } from "@unocss/config";
|
|
1909
2154
|
function ConfigHMRPlugin({ uno, configFilepath: filepath, invalidate, tokens, modules }) {
|
|
@@ -1944,9 +2189,9 @@ function UnocssPlugin(configOrPath, defaults = {
|
|
|
1944
2189
|
} else if (mode === "vue-scoped") {
|
|
1945
2190
|
plugins.push(VueScopedPlugin(ctx));
|
|
1946
2191
|
} else if (mode === "global") {
|
|
1947
|
-
plugins.push(...
|
|
2192
|
+
plugins.push(...GlobalModePlugin(ctx));
|
|
1948
2193
|
} else if (mode === "dist-chunk") {
|
|
1949
|
-
plugins.push(ChunkModeBuildPlugin(ctx), GlobalModeDevPlugin(ctx));
|
|
2194
|
+
plugins.push(ChunkModeBuildPlugin(ctx), ...GlobalModeDevPlugin(ctx));
|
|
1950
2195
|
} else {
|
|
1951
2196
|
throw new Error(`[unocss] unknown mode "${mode}"`);
|
|
1952
2197
|
}
|
|
@@ -1954,7 +2199,9 @@ function UnocssPlugin(configOrPath, defaults = {
|
|
|
1954
2199
|
}
|
|
1955
2200
|
export {
|
|
1956
2201
|
ChunkModeBuildPlugin,
|
|
2202
|
+
GlobalModeBuildPlugin,
|
|
1957
2203
|
GlobalModeDevPlugin,
|
|
2204
|
+
GlobalModePlugin,
|
|
1958
2205
|
PerModuleModePlugin,
|
|
1959
2206
|
VueScopedPlugin,
|
|
1960
2207
|
UnocssPlugin as default
|