@unocss/vite 66.6.6 → 66.6.7

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/client.mjs CHANGED
@@ -41,6 +41,5 @@ new MutationObserver((mutations) => {
41
41
  subtree: true,
42
42
  attributes: true
43
43
  });
44
-
45
44
  //#endregion
46
- export { };
45
+ export {};
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UnocssPluginContext, UserConfig, UserConfigDefaults } from "@unocss/core";
2
- import * as vite0 from "vite";
2
+ import * as vite from "vite";
3
3
  import { Plugin } from "vite";
4
4
 
5
5
  //#region src/types.d.ts
@@ -73,7 +73,7 @@ declare function GlobalModeBuildPlugin(ctx: UnocssPluginContext<VitePluginConfig
73
73
  declare function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[];
74
74
  //#endregion
75
75
  //#region src/modes/global/index.d.ts
76
- declare function GlobalModePlugin(ctx: UnocssPluginContext): vite0.Plugin<any>[];
76
+ declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin<any>[];
77
77
  //#endregion
78
78
  //#region src/modes/per-module.d.ts
79
79
  declare function PerModuleModePlugin(ctx: UnocssPluginContext): Plugin[];
package/dist/index.mjs CHANGED
@@ -13,26 +13,15 @@ import MagicString from "magic-string";
13
13
  import { resolve as resolve$1 } from "pathe";
14
14
  import crypto from "node:crypto";
15
15
  import { Buffer } from "node:buffer";
16
-
17
- //#region ../../virtual-shared/integration/src/constants.ts
18
- const INCLUDE_COMMENT = "@unocss-include";
19
- const IGNORE_COMMENT = "@unocss-ignore";
20
16
  const CSS_PLACEHOLDER = "@unocss-placeholder";
21
17
  const SKIP_START_COMMENT = "@unocss-skip-start";
22
18
  const SKIP_END_COMMENT = "@unocss-skip-end";
23
19
  const SKIP_COMMENT_RE = new RegExp(`(\/\/\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(\/\/\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
24
20
  const VIRTUAL_ENTRY_ALIAS = [/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/];
25
- const LAYER_MARK_ALL = "__ALL__";
26
-
27
21
  //#endregion
28
22
  //#region ../../virtual-shared/integration/src/defaults.ts
29
23
  const defaultPipelineExclude = [cssIdRE];
30
24
  const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|vine.ts|mdx?|astro|elm|php|phtml|marko|html)($|\?)/];
31
-
32
- //#endregion
33
- //#region ../../virtual-shared/integration/src/deprecation.ts
34
- function deprecationCheck(config) {}
35
-
36
25
  //#endregion
37
26
  //#region ../../virtual-shared/integration/src/context.ts
38
27
  function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {}) {
@@ -57,7 +46,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
57
46
  await _uno;
58
47
  const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
59
48
  resolveConfigResult(result);
60
- /* @__PURE__ */ deprecationCheck(result.config);
49
+ result.config;
61
50
  rawConfig = result.config;
62
51
  configFileList = result.sources;
63
52
  await uno.setConfig(rawConfig);
@@ -83,15 +72,15 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
83
72
  reloadListeners.forEach((cb) => cb());
84
73
  }
85
74
  async function extract(code, id) {
86
- const uno$1 = await _uno;
75
+ const uno = await _uno;
87
76
  if (id) modules.set(id, code);
88
77
  const len = tokens.size;
89
- await uno$1.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
78
+ await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
90
79
  if (tokens.size > len) invalidate();
91
80
  }
92
81
  function filter(code, id) {
93
- if (code.includes(IGNORE_COMMENT)) return false;
94
- return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
82
+ if (code.includes("@unocss-ignore")) return false;
83
+ return code.includes("@unocss-include") || code.includes("@unocss-placeholder") || rollupFilter(id.replace(/\?v=\w+$/, ""));
95
84
  }
96
85
  async function getConfig() {
97
86
  await ready;
@@ -111,8 +100,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
111
100
  if (vmpCache.has(prefix)) return vmpCache.get(prefix);
112
101
  const regexes = {
113
102
  prefix,
114
- RESOLVED_ID_WITH_QUERY_RE: /* @__PURE__ */ new RegExp(`[/\\\\]${prefix}(_.*?)?\\.css(\\?.*)?$`),
115
- RESOLVED_ID_RE: /* @__PURE__ */ new RegExp(`[/\\\\]${prefix}(?:_(.*?))?\.css$`)
103
+ RESOLVED_ID_WITH_QUERY_RE: new RegExp(`[/\\\\]${prefix}(_.*?)?\\.css(\\?.*)?$`),
104
+ RESOLVED_ID_RE: new RegExp(`[/\\\\]${prefix}(?:_(.*?))?\.css$`)
116
105
  };
117
106
  vmpCache.set(prefix, regexes);
118
107
  return regexes;
@@ -149,7 +138,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
149
138
  getVMPRegexes
150
139
  };
151
140
  }
152
-
153
141
  //#endregion
154
142
  //#region src/config-hmr.ts
155
143
  function ConfigHMRPlugin(ctx) {
@@ -175,7 +163,6 @@ function ConfigHMRPlugin(ctx) {
175
163
  }
176
164
  };
177
165
  }
178
-
179
166
  //#endregion
180
167
  //#region src/devtool.ts
181
168
  const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
@@ -191,13 +178,13 @@ const MODULES_MAP = {
191
178
  };
192
179
  const BASE_POST_PATH = "/@unocss-devtools-update";
193
180
  function getBodyJson(req) {
194
- return new Promise((resolve$2, reject) => {
181
+ return new Promise((resolve, reject) => {
195
182
  let body = "";
196
183
  req.on("data", (chunk) => body += chunk);
197
184
  req.on("error", reject);
198
185
  req.on("end", () => {
199
186
  try {
200
- resolve$2(JSON.parse(body) || {});
187
+ resolve(JSON.parse(body) || {});
201
188
  } catch (e) {
202
189
  reject(e);
203
190
  }
@@ -296,7 +283,6 @@ function createDevtoolsPlugin(ctx, pluginConfig) {
296
283
  }
297
284
  }];
298
285
  }
299
-
300
286
  //#endregion
301
287
  //#region src/modes/chunk-build.ts
302
288
  function ChunkModeBuildPlugin(ctx) {
@@ -341,7 +327,6 @@ function ChunkModeBuildPlugin(ctx) {
341
327
  }
342
328
  };
343
329
  }
344
-
345
330
  //#endregion
346
331
  //#region ../../virtual-shared/integration/src/utils.ts
347
332
  function getPath(id) {
@@ -370,11 +355,10 @@ function restoreSkipCode(code, map) {
370
355
  for (const [withHashKey, matched] of map.entries()) code = code.replaceAll(withHashKey, matched);
371
356
  return code;
372
357
  }
373
-
374
358
  //#endregion
375
359
  //#region ../../virtual-shared/integration/src/transformers.ts
376
360
  async function applyTransformers(ctx, original, id, enforce = "default") {
377
- if (original.includes(IGNORE_COMMENT)) return;
361
+ if (original.includes("@unocss-ignore")) return;
378
362
  const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
379
363
  if (!transformers.length) return;
380
364
  const skipMap = /* @__PURE__ */ new Map();
@@ -397,13 +381,12 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
397
381
  }
398
382
  if (code !== original) return {
399
383
  code,
400
- map: remapping(maps, (_, ctx$1) => {
401
- ctx$1.content = code;
384
+ map: remapping(maps, (_, ctx) => {
385
+ ctx.content = code;
402
386
  return null;
403
387
  })
404
388
  };
405
389
  }
406
-
407
390
  //#endregion
408
391
  //#region ../../virtual-shared/integration/src/content.ts
409
392
  async function setupContentExtractor(ctx, shouldWatch = false) {
@@ -444,7 +427,6 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
444
427
  await Promise.all(files.map(extractFile));
445
428
  }
446
429
  }
447
-
448
430
  //#endregion
449
431
  //#region ../../virtual-shared/integration/src/layers.ts
450
432
  async function resolveId(ctx, id, importer) {
@@ -464,16 +446,14 @@ async function resolveId(ctx, id, importer) {
464
446
  async function resolveLayer(ctx, id) {
465
447
  const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
466
448
  const match = id.match(RESOLVED_ID_RE);
467
- if (match) return match[1] || LAYER_MARK_ALL;
449
+ if (match) return match[1] || "__ALL__";
468
450
  }
469
451
  function getLayerPlaceholder(layer) {
470
452
  return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
471
453
  }
472
-
473
454
  //#endregion
474
455
  //#region src/modes/global/shared.ts
475
456
  const MESSAGE_UNOCSS_ENTRY_NOT_FOUND = "[unocss] Entry module not found. Did you add `import 'uno.css'` in your main entry?";
476
-
477
457
  //#endregion
478
458
  //#region src/modes/global/build.ts
479
459
  function GlobalModeBuildPlugin(ctx) {
@@ -484,11 +464,11 @@ function GlobalModeBuildPlugin(ctx) {
484
464
  let viteConfig;
485
465
  const cssPostPlugins = /* @__PURE__ */ new Map();
486
466
  const cssPlugins = /* @__PURE__ */ new Map();
487
- async function applyCssTransform(css, id, dir, ctx$1) {
467
+ async function applyCssTransform(css, id, dir, ctx) {
488
468
  const { postcss = true } = await getConfig();
489
469
  if (!cssPlugins.get(dir) || !postcss) return css;
490
470
  const cssPlugin = cssPlugins.get(dir);
491
- const result = await ("handler" in cssPlugin.transform ? cssPlugin.transform.handler : cssPlugin.transform).call(ctx$1, css, id);
471
+ const result = await ("handler" in cssPlugin.transform ? cssPlugin.transform.handler : cssPlugin.transform).call(ctx, css, id);
492
472
  if (!result) return css;
493
473
  if (typeof result === "string") css = result;
494
474
  else if (result.code) css = result.code;
@@ -609,8 +589,8 @@ function GlobalModeBuildPlugin(ctx) {
609
589
  return (await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || layerContent, fakeCssId, "post"))?.code || defaultTransform?.code || preTransform?.code || layerContent;
610
590
  })));
611
591
  for (const mod of entryModules) {
612
- const layer = RESOLVED_ID_RE.exec(mod)?.[1] || LAYER_MARK_ALL;
613
- const css = await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, [LAYER_IMPORTS, ...vfsLayers.keys()]) : result.getLayer(layer) || "", mod, options.dir, resolveContexts.get(layer) || this);
592
+ const layer = RESOLVED_ID_RE.exec(mod)?.[1] || "__ALL__";
593
+ const css = await applyCssTransform(layer === "__ALL__" ? result.getLayers(void 0, [LAYER_IMPORTS, ...vfsLayers.keys()]) : result.getLayer(layer) || "", mod, options.dir, resolveContexts.get(layer) || this);
614
594
  await cssPostTransformHandler.call(this, css, mod);
615
595
  }
616
596
  },
@@ -622,14 +602,12 @@ function GlobalModeBuildPlugin(ctx) {
622
602
  }
623
603
  ];
624
604
  }
625
-
626
605
  //#endregion
627
606
  //#region ../../virtual-shared/integration/src/hash.ts
628
607
  const hash = crypto.hash ?? ((algorithm, data, outputEncoding) => crypto.createHash(algorithm).update(data).digest(outputEncoding));
629
608
  function getHash(input, length = 8) {
630
609
  return hash("sha256", input, "hex").substring(0, length);
631
610
  }
632
-
633
611
  //#endregion
634
612
  //#region src/modes/global/dev.ts
635
613
  const WARN_TIMEOUT = 2e4;
@@ -653,12 +631,12 @@ function GlobalModeDevPlugin(ctx) {
653
631
  if (tokensSize === tokens.size) break;
654
632
  tokensSize = tokens.size;
655
633
  } while (true);
656
- const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i))).then((layers) => layers.filter((i) => !!i))) : result.getLayer(layer);
657
- const hash$2 = getHash(css || "", HASH_LENGTH);
658
- lastServedHash.set(layer, hash$2);
634
+ const css = layer === "__ALL__" ? result.getLayers(void 0, await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i))).then((layers) => layers.filter((i) => !!i))) : result.getLayer(layer);
635
+ const hash = getHash(css || "", HASH_LENGTH);
636
+ lastServedHash.set(layer, hash);
659
637
  lastServedTime = Date.now();
660
638
  return {
661
- hash: hash$2,
639
+ hash,
662
640
  css
663
641
  };
664
642
  }
@@ -756,9 +734,9 @@ function GlobalModeDevPlugin(ctx) {
756
734
  async load(id) {
757
735
  const layer = await resolveLayer(ctx, getPath(id));
758
736
  if (!layer) return null;
759
- const { hash: hash$2, css } = await generateCSS(layer);
737
+ const { hash, css } = await generateCSS(layer);
760
738
  return {
761
- code: `${css}__uno_hash_${hash$2}{--:'';}`,
739
+ code: `${css}__uno_hash_${hash}{--:'';}`,
762
740
  map: { mappings: "" }
763
741
  };
764
742
  },
@@ -799,13 +777,11 @@ if (!import.meta.url.includes('?'))
799
777
  }
800
778
  }];
801
779
  }
802
-
803
780
  //#endregion
804
781
  //#region src/modes/global/index.ts
805
782
  function GlobalModePlugin(ctx) {
806
783
  return [...GlobalModeBuildPlugin(ctx), ...GlobalModeDevPlugin(ctx)];
807
784
  }
808
-
809
785
  //#endregion
810
786
  //#region src/modes/per-module.ts
811
787
  const VIRTUAL_PREFIX = "/@unocss/";
@@ -813,9 +789,9 @@ const SCOPE_IMPORT_RE = / from (['"])(@unocss\/scope)\1/;
813
789
  function PerModuleModePlugin(ctx) {
814
790
  const moduleMap = /* @__PURE__ */ new Map();
815
791
  let server;
816
- const invalidate = (hash$2) => {
792
+ const invalidate = (hash) => {
817
793
  if (!server) return;
818
- const id = `${VIRTUAL_PREFIX}${hash$2}.css`;
794
+ const id = `${VIRTUAL_PREFIX}${hash}.css`;
819
795
  const mod = server.moduleGraph.getModuleById(id);
820
796
  if (!mod) return;
821
797
  server.moduleGraph.invalidateModule(mod);
@@ -849,17 +825,17 @@ function PerModuleModePlugin(ctx) {
849
825
  async transform(code, id) {
850
826
  await ctx.ready;
851
827
  if (!ctx.filter(code, id)) return;
852
- const hash$2 = getHash(id);
828
+ const hash = getHash(id);
853
829
  const hasScope = SCOPE_IMPORT_RE.test(code);
854
830
  const { css } = await ctx.uno.generate(code, {
855
831
  id,
856
- scope: hasScope ? `.${hash$2}` : void 0,
832
+ scope: hasScope ? `.${hash}` : void 0,
857
833
  preflights: false
858
834
  });
859
835
  if (!css && !hasScope) return null;
860
- if (hasScope) code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash$2}"`).toString("base64")}'`);
861
- moduleMap.set(hash$2, [id, css]);
862
- invalidate(hash$2);
836
+ if (hasScope) code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
837
+ moduleMap.set(hash, [id, css]);
838
+ invalidate(hash);
863
839
  return null;
864
840
  }
865
841
  }, {
@@ -871,10 +847,10 @@ function PerModuleModePlugin(ctx) {
871
847
  async transform(code, id) {
872
848
  await ctx.ready;
873
849
  if (!ctx.filter(code, id)) return;
874
- const hash$2 = getHash(id);
875
- invalidate(hash$2);
876
- if ((moduleMap.get(hash$2) || []).length) return {
877
- code: `import "${VIRTUAL_PREFIX}${hash$2}.css";${code}`,
850
+ const hash = getHash(id);
851
+ invalidate(hash);
852
+ if ((moduleMap.get(hash) || []).length) return {
853
+ code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
878
854
  map: null
879
855
  };
880
856
  },
@@ -883,14 +859,13 @@ function PerModuleModePlugin(ctx) {
883
859
  },
884
860
  load(id) {
885
861
  if (!id.startsWith(VIRTUAL_PREFIX)) return null;
886
- const hash$2 = id.slice(9, -4);
887
- const [source, css] = moduleMap.get(hash$2) || [];
862
+ const hash = id.slice(9, -4);
863
+ const [source, css] = moduleMap.get(hash) || [];
888
864
  if (source) this.addWatchFile(source);
889
865
  return `\n/* unocss ${source} */\n${css}`;
890
866
  }
891
867
  }];
892
868
  }
893
-
894
869
  //#endregion
895
870
  //#region src/modes/shadow-dom.ts
896
871
  function ShadowDomModuleModePlugin(ctx) {
@@ -925,7 +900,7 @@ function ShadowDomModuleModePlugin(ctx) {
925
900
  };
926
901
  };
927
902
  const transformWebComponent = async (code, id) => {
928
- if (!code.match(CSS_PLACEHOLDER)) return code;
903
+ if (!code.match("@unocss-placeholder")) return code;
929
904
  await ctx.ready;
930
905
  let { css, matched } = await ctx.uno.generate(code, {
931
906
  preflights: true,
@@ -965,7 +940,7 @@ function ShadowDomModuleModePlugin(ctx) {
965
940
  }, css);
966
941
  }
967
942
  }
968
- if (id.includes("?vue&type=style") || id.endsWith(".vue") && vueSFCStyleRE.test(code)) return code.replace(/* @__PURE__ */ new RegExp(`(\\/\\*\\s*)?${CSS_PLACEHOLDER}(\\s*\\*\\/)?`), css || "");
943
+ if (id.includes("?vue&type=style") || id.endsWith(".vue") && vueSFCStyleRE.test(code)) return code.replace(new RegExp(`(\\/\\*\\s*)?${CSS_PLACEHOLDER}(\\s*\\*\\/)?`), css || "");
969
944
  return code.replace(CSS_PLACEHOLDER, css?.replace(/\\/g, "\\\\")?.replace(/`/g, "\\`") ?? "");
970
945
  };
971
946
  return {
@@ -977,15 +952,14 @@ function ShadowDomModuleModePlugin(ctx) {
977
952
  map: null
978
953
  };
979
954
  },
980
- handleHotUpdate(ctx$1) {
981
- const read = ctx$1.read;
982
- ctx$1.read = async () => {
983
- return await transformWebComponent(await read(), ctx$1.file);
955
+ handleHotUpdate(ctx) {
956
+ const read = ctx.read;
957
+ ctx.read = async () => {
958
+ return await transformWebComponent(await read(), ctx.file);
984
959
  };
985
960
  }
986
961
  };
987
962
  }
988
-
989
963
  //#endregion
990
964
  //#region src/modes/vue-scoped.ts
991
965
  function VueScopedPlugin(ctx) {
@@ -1011,16 +985,15 @@ function VueScopedPlugin(ctx) {
1011
985
  map: null
1012
986
  };
1013
987
  },
1014
- handleHotUpdate(ctx$1) {
1015
- const read = ctx$1.read;
1016
- if (filter(ctx$1.file)) ctx$1.read = async () => {
988
+ handleHotUpdate(ctx) {
989
+ const read = ctx.read;
990
+ if (filter(ctx.file)) ctx.read = async () => {
1017
991
  const code = await read();
1018
992
  return await transformSFC(code) || code;
1019
993
  };
1020
994
  }
1021
995
  };
1022
996
  }
1023
-
1024
997
  //#endregion
1025
998
  //#region src/transformers.ts
1026
999
  function createTransformerPlugins(ctx) {
@@ -1048,7 +1021,6 @@ function createTransformerPlugins(ctx) {
1048
1021
  };
1049
1022
  });
1050
1023
  }
1051
-
1052
1024
  //#endregion
1053
1025
  //#region src/index.ts
1054
1026
  function defineConfig(config) {
@@ -1084,6 +1056,5 @@ function UnocssPlugin(configOrPath, defaults = {}) {
1084
1056
  else throw new Error(`[unocss] unknown mode "${mode}"`);
1085
1057
  return plugins.filter(Boolean);
1086
1058
  }
1087
-
1088
1059
  //#endregion
1089
- export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
1060
+ export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
3
  "type": "module",
4
- "version": "66.6.6",
4
+ "version": "66.6.7",
5
5
  "description": "The Vite plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -48,9 +48,9 @@
48
48
  "pathe": "^2.0.3",
49
49
  "tinyglobby": "^0.2.15",
50
50
  "unplugin-utils": "^0.3.1",
51
- "@unocss/config": "66.6.6",
52
- "@unocss/core": "66.6.6",
53
- "@unocss/inspector": "66.6.6"
51
+ "@unocss/config": "66.6.7",
52
+ "@unocss/core": "66.6.7",
53
+ "@unocss/inspector": "66.6.7"
54
54
  },
55
55
  "devDependencies": {
56
56
  "vite": "^7.3.1"