@unocss/svelte-scoped 66.6.7 → 66.7.0-beta.1

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.
@@ -1,14 +1,7 @@
1
- import { LoadConfigResult } from "@unocss/config";
2
- import { UnoGenerator, UserConfig } from "@unocss/core";
1
+ import { UnocssPluginContext } from "@unocss/core";
3
2
  import { PreprocessorGroup } from "svelte/types/compiler/preprocess";
4
3
 
5
- //#region src/_preprocess/types.d.ts
6
- interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions, TransformDirectivesOptions {
7
- /**
8
- * UnoCSS config or path to config file. If not provided, will load unocss.config.ts/js. It's recommended to use the separate config file if you are having trouble with the UnoCSS extension in VSCode.
9
- */
10
- configOrPath?: UserConfig | string;
11
- }
4
+ //#region src/types.d.ts
12
5
  interface TransformClassesOptions {
13
6
  /**
14
7
  * Prefix for compiled class names. Distinct between `@unocss/svelte-scoped/vite` and `@unocss/svelte-scoped/preprocessor` to avoid bugs when using a component library built with `@unocss/svelte-scoped/preprocessor` in a project using `@unocss/svelte-scoped/vite`.
@@ -25,6 +18,13 @@ interface TransformClassesOptions {
25
18
  * Used to generate hash for compiled class names
26
19
  */
27
20
  hashFn?: (str: string) => string;
21
+ /**
22
+ * Hash safelist classes (including shortcuts in the safelist) instead of passing them through as-is.
23
+ * When false (default), safelist classes are left unhashed so they match the globally generated safelist CSS.
24
+ * Set to true to restore the legacy behavior where shortcut classes in the safelist were still hashed.
25
+ * @default false
26
+ */
27
+ hashSafelistClasses?: boolean;
28
28
  }
29
29
  interface TransformApplyOptions {
30
30
  /**
@@ -48,12 +48,16 @@ interface TransformDirectivesOptions {
48
48
  */
49
49
  transformThemeDirective?: boolean;
50
50
  }
51
- interface SvelteScopedContext {
52
- uno: UnoGenerator;
53
- ready: Promise<LoadConfigResult<UserConfig>>;
51
+ //#endregion
52
+ //#region src/_preprocess/types.d.ts
53
+ interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions, TransformDirectivesOptions {
54
+ /**
55
+ * UnoCSS config or path to config file. If not provided, will load unocss.config.ts/js. It's recommended to use the separate config file if you are having trouble with the UnoCSS extension in VSCode.
56
+ */
57
+ configOrPath?: UserConfig | string;
54
58
  }
55
59
  //#endregion
56
60
  //#region src/_preprocess/index.d.ts
57
- declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
61
+ declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: Pick<UnocssPluginContext, 'ready' | 'uno'>, isViteBuild?: () => boolean): PreprocessorGroup;
58
62
  //#endregion
59
- export { TransformDirectivesOptions as a, TransformClassesOptions as i, SvelteScopedContext as n, UnocssSveltePreprocessOptions as o, TransformApplyOptions as r, UnocssSveltePreprocess as t };
63
+ export { TransformDirectivesOptions as a, TransformClassesOptions as i, UnocssSveltePreprocessOptions as n, TransformApplyOptions as r, UnocssSveltePreprocess as t };
@@ -1,2 +1,2 @@
1
- import { a as TransformDirectivesOptions, i as TransformClassesOptions, n as SvelteScopedContext, o as UnocssSveltePreprocessOptions, r as TransformApplyOptions, t as UnocssSveltePreprocess } from "./preprocess-eGXggMC-.mjs";
2
- export { SvelteScopedContext, TransformApplyOptions, TransformClassesOptions, TransformDirectivesOptions, UnocssSveltePreprocessOptions, UnocssSveltePreprocess as default };
1
+ import { a as TransformDirectivesOptions, i as TransformClassesOptions, n as UnocssSveltePreprocessOptions, r as TransformApplyOptions, t as UnocssSveltePreprocess } from "./preprocess-BlFuH8z9.mjs";
2
+ export { type TransformApplyOptions, type TransformClassesOptions, type TransformDirectivesOptions, type UnocssSveltePreprocessOptions, UnocssSveltePreprocess as default };
@@ -1,2 +1,102 @@
1
- import { t as UnocssSveltePreprocess } from "./preprocess-C0sgyK1A.mjs";
1
+ import { i as transformClasses, n as transformStyle, r as themeRE, t as checkForApply } from "./transformStyle-NRa-cUil.mjs";
2
+ import process from "node:process";
3
+ import { createRecoveryConfigLoader } from "@unocss/config";
4
+ import { createGenerator, warnOnce } from "@unocss/core";
5
+ import presetWind3 from "@unocss/preset-wind3";
6
+ import MagicString from "magic-string";
7
+ //#region src/_preprocess/addGeneratedStyles.ts
8
+ const actualStylesTagWithCapturedDirectivesRE = new RegExp(/(?<!<!--\s*)/.source + /<style([^>]*)>[\s\S]*?<\/style\s*>/.source, "g");
9
+ const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
10
+ function addGeneratedStylesIntoStyleBlock(s, styles) {
11
+ if (s.original.match(actualStylesTagWithCapturedDirectivesRE)) s.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
12
+ else s.append(`\n<style>${styles}</style>`);
13
+ }
14
+ //#endregion
15
+ //#region src/_preprocess/wrapGlobal.ts
16
+ const EXTRACT_SELECTOR_RE = new RegExp(/(?<![\d(])/.source + /([[.][\s\S]+?)/.source + /(\{[\s\S]+?\})/.source, "g");
17
+ function wrapSelectorsWithGlobal(css) {
18
+ return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
19
+ }
20
+ //#endregion
21
+ //#region src/_preprocess/index.ts
22
+ function UnocssSveltePreprocess(options = {}, unoContextFromVite, isViteBuild) {
23
+ if (!options.classPrefix) options.classPrefix = "usp-";
24
+ let uno;
25
+ const makeGenerator = async () => {
26
+ if (unoContextFromVite) {
27
+ await unoContextFromVite.ready;
28
+ return unoContextFromVite.uno;
29
+ }
30
+ const defaults = { presets: [presetWind3()] };
31
+ return await createGenerator((await createRecoveryConfigLoader()(process.cwd(), options.configOrPath)).config, defaults);
32
+ };
33
+ return {
34
+ markup: async ({ content, filename }) => {
35
+ uno ??= await makeGenerator();
36
+ if (isViteBuild && options.combine === void 0) options.combine = isViteBuild();
37
+ const s = new MagicString(content);
38
+ const transformed = await transformClasses({
39
+ s,
40
+ filename: filename ?? "",
41
+ uno,
42
+ options,
43
+ removeCommentsToMakeGlobalWrappingEasy: true
44
+ });
45
+ if (!transformed) return;
46
+ addGeneratedStylesIntoStyleBlock(s, wrapSelectorsWithGlobal(transformed.generatedStyles));
47
+ if (s.hasChanged()) return {
48
+ code: s.toString(),
49
+ map: s.generateMap({
50
+ hires: true,
51
+ source: filename ?? ""
52
+ })
53
+ };
54
+ },
55
+ style: async ({ content, attributes, filename }) => {
56
+ const svelte3AddPreflights = attributes["uno:preflights"];
57
+ const svelte3AddSafelist = attributes["uno:safelist"];
58
+ const svelte4DeprecatedAddPreflights = attributes.uno && attributes.preflights;
59
+ const svelte4DeprecatedAddSafelist = attributes.uno && attributes.safelist;
60
+ let addPreflights = attributes["uno-preflights"] || svelte3AddPreflights || svelte4DeprecatedAddPreflights;
61
+ let addSafelist = attributes["uno-safelist"] || svelte3AddSafelist || svelte4DeprecatedAddSafelist;
62
+ if (unoContextFromVite && (addPreflights || addSafelist)) {
63
+ addPreflights = false;
64
+ addSafelist = false;
65
+ warnOnce("Notice for those transitioning to @unocss/svelte-scoped/vite: uno-preflights and uno-safelist are only for use in component libraries. Please see the documentation for how to add preflights and safelist into your head tag. If you are consuming a component library built by @unocss/svelte-scoped/preprocess, you can ignore this upgrade notice.");
66
+ }
67
+ const { hasApply, applyVariables } = checkForApply(content, options.applyVariables);
68
+ const hasThemeFn = options.transformThemeDirective === false ? false : !!content.match(themeRE);
69
+ if (!(addPreflights || addSafelist || hasApply || hasThemeFn)) return;
70
+ uno ??= await makeGenerator();
71
+ let preflightsSafelistCss = "";
72
+ if (addPreflights || addSafelist) {
73
+ const { css } = await uno.generate([], {
74
+ preflights: !!addPreflights,
75
+ safelist: !!addSafelist,
76
+ minify: true
77
+ });
78
+ preflightsSafelistCss = wrapSelectorsWithGlobal(css);
79
+ }
80
+ if (hasApply || hasThemeFn) {
81
+ const s = new MagicString(content);
82
+ await transformStyle({
83
+ s,
84
+ uno,
85
+ prepend: preflightsSafelistCss,
86
+ applyVariables,
87
+ transformThemeFn: hasThemeFn
88
+ });
89
+ if (s.hasChanged()) return {
90
+ code: s.toString(),
91
+ map: s.generateMap({
92
+ hires: true,
93
+ source: filename ?? ""
94
+ })
95
+ };
96
+ }
97
+ if (preflightsSafelistCss) return { code: preflightsSafelistCss + content };
98
+ }
99
+ };
100
+ }
101
+ //#endregion
2
102
  export { UnocssSveltePreprocess as default };
@@ -1,20 +1,8 @@
1
- import process from "node:process";
2
- import { createRecoveryConfigLoader } from "@unocss/config";
3
- import { createGenerator, expandVariantGroup, regexScopePlaceholder, toArray, warnOnce } from "@unocss/core";
4
- import presetWind3 from "@unocss/preset-wind3";
5
- import MagicString from "magic-string";
1
+ import { expandVariantGroup, regexScopePlaceholder, toArray, warnOnce } from "@unocss/core";
6
2
  import * as acorn from "acorn";
7
3
  import { walk } from "zimmerframe";
8
4
  import { clone, generate, parse, walk as walk$1 } from "css-tree";
9
- //#region src/_preprocess/transformClasses/addGeneratedStyles.ts
10
- const actualStylesTagWithCapturedDirectivesRE = new RegExp(/(?<!<!--\s*)/.source + /<style([^>]*)>[\s\S]*?<\/style\s*>/.source, "g");
11
- const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
12
- function addGeneratedStylesIntoStyleBlock(code, styles) {
13
- if (code.match(actualStylesTagWithCapturedDirectivesRE)) return code.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
14
- return `${code}\n<style>${styles}</style>`;
15
- }
16
- //#endregion
17
- //#region src/_preprocess/transformClasses/findClasses.ts
5
+ //#region src/_common/transformClasses/findClasses.ts
18
6
  const classesRE$1 = /class=(["'`])([\s\S]*?)\1/g;
19
7
  const classDirectivesRE = /class:(\S+?)="?\{/g;
20
8
  const classDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
@@ -104,7 +92,7 @@ function parseMatchesWithAcorn(matches, code) {
104
92
  }).filter(hasBody);
105
93
  }
106
94
  //#endregion
107
- //#region src/_preprocess/transformClasses/hash.ts
95
+ //#region src/_common/transformClasses/hash.ts
108
96
  function hash(str) {
109
97
  let i;
110
98
  let l;
@@ -116,32 +104,36 @@ function hash(str) {
116
104
  return `00000${(hval >>> 0).toString(36)}`.slice(-6);
117
105
  }
118
106
  //#endregion
119
- //#region src/_preprocess/transformClasses/generateClassName.ts
107
+ //#region src/_common/transformClasses/generateClassName.ts
120
108
  function generateClassName(body, options, filename) {
121
109
  const { classPrefix = "uno-", combine = true, hashFn = hash } = options;
122
110
  if (combine) return `${classPrefix}${hashFn(body + filename)}`;
123
111
  else return `_${body}_${hashFn(filename)}`;
124
112
  }
125
113
  //#endregion
126
- //#region src/_preprocess/transformClasses/isShortcut.ts
114
+ //#region src/_common/transformClasses/isShortcut.ts
127
115
  function isShortcut(token, shortcuts) {
128
116
  return shortcuts.some((s) => s[0] === token);
129
117
  }
130
118
  //#endregion
131
- //#region src/_preprocess/transformClasses/needsGenerated.ts
119
+ //#region src/_common/transformClasses/needsGenerated.ts
132
120
  async function needsGenerated(token, uno) {
133
121
  if (uno.config.safelist.includes(token)) return false;
134
122
  return !!await uno.parseToken(token);
135
123
  }
136
124
  //#endregion
137
- //#region src/_preprocess/transformClasses/sortClassesIntoCategories.ts
125
+ //#region src/_common/transformClasses/sortClassesIntoCategories.ts
138
126
  async function sortClassesIntoCategories(body, options, uno, filename) {
139
- const { combine = true } = options;
127
+ const { combine = true, hashSafelistClasses = false } = options;
140
128
  const rulesToGenerate = {};
141
129
  const ignore = [];
142
130
  const classes = body.trim().split(/\s+/);
143
131
  const knownClassesToCombine = [];
144
132
  for (const token of classes) {
133
+ if (!hashSafelistClasses && uno.config.safelist.includes(token)) {
134
+ ignore.push(token);
135
+ continue;
136
+ }
145
137
  if (!(isShortcut(token, uno.config.shortcuts) || await needsGenerated(token, uno))) {
146
138
  ignore.push(token);
147
139
  continue;
@@ -162,7 +154,7 @@ async function sortClassesIntoCategories(body, options, uno, filename) {
162
154
  };
163
155
  }
164
156
  //#endregion
165
- //#region src/_preprocess/transformClasses/processExpressions.ts
157
+ //#region src/_common/transformClasses/processExpressions.ts
166
158
  const expressionsRE = /\S*\{[^{}]+\}\S*/g;
167
159
  const classesRE = /(?<=\?\s*|:\s*)(["'`])([\s\S]*?)\1/g;
168
160
  async function processExpressions(body, options, uno, filename) {
@@ -188,7 +180,7 @@ async function processExpressions(body, options, uno, filename) {
188
180
  };
189
181
  }
190
182
  //#endregion
191
- //#region src/_preprocess/transformClasses/processClassBody.ts
183
+ //#region src/_common/transformClasses/processClassBody.ts
192
184
  async function processClassBody({ body, start, end }, options, uno, filename) {
193
185
  const { rulesToGenerate: rulesFromExpressions, restOfBody, updatedExpressions } = await processExpressions(expandVariantGroup(body), options, uno, filename);
194
186
  const { rulesToGenerate: rulesFromRegularClasses, ignore } = await sortClassesIntoCategories(restOfBody, options, uno, filename);
@@ -207,7 +199,7 @@ async function processClassBody({ body, start, end }, options, uno, filename) {
207
199
  };
208
200
  }
209
201
  //#endregion
210
- //#region src/_preprocess/transformClasses/processDirective.ts
202
+ //#region src/_common/transformClasses/processDirective.ts
211
203
  async function processDirective({ body: token, start, end, type }, options, uno, filename) {
212
204
  if (!(isShortcut(token, uno.config.shortcuts) || await needsGenerated(token, uno))) return;
213
205
  const generatedClassName = generateClassName(token, options, filename);
@@ -222,7 +214,7 @@ async function processDirective({ body: token, start, end, type }, options, uno,
222
214
  };
223
215
  }
224
216
  //#endregion
225
- //#region src/_preprocess/transformClasses/processClsx.ts
217
+ //#region src/_common/transformClasses/processClsx.ts
226
218
  async function processClsx(cls, options, uno, filename) {
227
219
  if (cls.type === "clsxObject") {
228
220
  const { rulesToGenerate, codeUpdate } = await processClassBody({
@@ -251,7 +243,7 @@ async function processClsx(cls, options, uno, filename) {
251
243
  }
252
244
  }
253
245
  //#endregion
254
- //#region src/_preprocess/transformClasses/processClasses.ts
246
+ //#region src/_common/transformClasses/processClasses.ts
255
247
  async function processClasses(classes, options, uno, filename) {
256
248
  const result = {
257
249
  rulesToGenerate: {},
@@ -270,53 +262,28 @@ async function processClass(foundClass, options, uno, filename) {
270
262
  return await processDirective(foundClass, options, uno, filename) ?? {};
271
263
  }
272
264
  //#endregion
273
- //#region src/_preprocess/transformClasses/wrapGlobal.ts
274
- const EXTRACT_SELECTOR_RE = new RegExp(/(?<![\d(])/.source + /([[.][\s\S]+?)/.source + /(\{[\s\S]+?\})/.source, "g");
275
- function wrapSelectorsWithGlobal(css) {
276
- return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
277
- }
278
- //#endregion
279
- //#region src/_preprocess/transformClasses/index.ts
280
- async function transformClasses({ content, filename, uno, options }) {
281
- const classesToProcess = findClasses(content);
265
+ //#region src/_common/transformClasses/index.ts
266
+ async function transformClasses({ s, filename, uno, options, removeCommentsToMakeGlobalWrappingEasy }) {
267
+ const classesToProcess = findClasses(s.original);
282
268
  if (!classesToProcess.length) return;
283
269
  const { rulesToGenerate, codeUpdates } = await processClasses(classesToProcess, options, uno, filename);
284
270
  if (!Object.keys(rulesToGenerate).length) return;
285
- const { map, code } = updateTemplateCodeIfNeeded(codeUpdates, content, filename);
286
- return {
287
- code: addGeneratedStylesIntoStyleBlock(code, await generateStyles(rulesToGenerate, uno)),
288
- map
289
- };
290
- }
291
- function updateTemplateCodeIfNeeded(codeUpdates, source, filename) {
292
- if (!codeUpdates.length) return {
293
- code: source,
294
- map: void 0
295
- };
296
- const s = new MagicString(source);
297
- for (const { start, end, content } of codeUpdates) s.overwrite(start, end, content);
298
- return {
299
- code: s.toString(),
300
- map: s.generateMap({
301
- hires: true,
302
- source: filename
303
- })
304
- };
271
+ if (codeUpdates.length) for (const { start, end, content } of codeUpdates) s.overwrite(start, end, content);
272
+ return { generatedStyles: await generateStyles(rulesToGenerate, uno, removeCommentsToMakeGlobalWrappingEasy) };
305
273
  }
306
- const REMOVE_COMMENTS_TO_MAKE_GLOBAL_WRAPPING_EASY = true;
307
- async function generateStyles(rulesToGenerate, uno) {
274
+ async function generateStyles(rulesToGenerate, uno, minify) {
308
275
  const shortcutsForThisComponent = Object.entries(rulesToGenerate);
309
276
  uno.config.shortcuts.push(...shortcutsForThisComponent);
310
277
  const selectorsToGenerate = Object.keys(rulesToGenerate);
311
278
  const { css } = await uno.generate(selectorsToGenerate, {
312
279
  preflights: false,
313
280
  safelist: false,
314
- minify: REMOVE_COMMENTS_TO_MAKE_GLOBAL_WRAPPING_EASY
281
+ minify
315
282
  });
316
- return wrapSelectorsWithGlobal(css);
283
+ return css;
317
284
  }
318
285
  //#endregion
319
- //#region src/_preprocess/transformApply/getUtils.ts
286
+ //#region src/_common/transformApply/getUtils.ts
320
287
  async function getUtils(body, uno) {
321
288
  return (await parseUtils(expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, "")), uno)).sort(([aIndex], [bIndex]) => aIndex - bIndex).sort(([, , , aParent], [, , , bParent]) => (aParent ? uno.parentOrders.get(aParent) ?? 0 : 0) - (bParent ? uno.parentOrders.get(bParent) ?? 0 : 0)).reduce((acc, item) => {
322
289
  const [, selector, body, parent] = item;
@@ -336,13 +303,13 @@ async function parseUtils(classNames, uno) {
336
303
  return foundUtils.flat();
337
304
  }
338
305
  //#endregion
339
- //#region src/_preprocess/transformApply/removeOuterQuotes.ts
306
+ //#region src/_common/transformApply/removeOuterQuotes.ts
340
307
  function removeOuterQuotes(input) {
341
308
  if (!input) return "";
342
309
  return /^(['"]).*\1$/.test(input) ? input.slice(1, -1) : input;
343
310
  }
344
311
  //#endregion
345
- //#region src/_preprocess/transformApply/writeUtilStyles.ts
312
+ //#region src/_common/transformApply/writeUtilStyles.ts
346
313
  function writeUtilStyles([, selector, body, parent], s, node, childNode) {
347
314
  if (!selector) return;
348
315
  const selectorChanged = selector !== ".\\-";
@@ -394,7 +361,7 @@ function findFirstCombinatorIndex(input) {
394
361
  return -1;
395
362
  }
396
363
  //#endregion
397
- //#region src/_preprocess/transformApply/index.ts
364
+ //#region src/_common/transformApply/index.ts
398
365
  async function transformApply(ctx) {
399
366
  const ast = parse(ctx.s.original, {
400
367
  parseAtrulePrelude: false,
@@ -430,7 +397,7 @@ function getChildNodeValue(childNode, applyVariables) {
430
397
  if (childNode.type === "Declaration" && applyVariables.includes(childNode.property) && childNode.value.type === "Raw") return removeOuterQuotes(childNode.value.value.trim());
431
398
  }
432
399
  //#endregion
433
- //#region src/_preprocess/transformTheme.ts
400
+ //#region src/_common/transformTheme.ts
434
401
  const themeRE = /theme\((.+?)\)/g;
435
402
  function transformTheme(s, theme) {
436
403
  return s.replace(themeRE, (_, match) => {
@@ -445,7 +412,7 @@ function getThemeValue(rawArguments, theme) {
445
412
  return current;
446
413
  }
447
414
  //#endregion
448
- //#region src/_preprocess/transformStyle.ts
415
+ //#region src/_common/transformStyle.ts
449
416
  const DEFAULT_APPLY_VARIABLES = ["--at-apply"];
450
417
  function checkForApply(content, _applyVariables) {
451
418
  if (_applyVariables === false) return {
@@ -458,8 +425,7 @@ function checkForApply(content, _applyVariables) {
458
425
  applyVariables
459
426
  };
460
427
  }
461
- async function transformStyle({ content, uno, prepend, filename, applyVariables, transformThemeFn }) {
462
- const s = new MagicString(content);
428
+ async function transformStyle({ s, uno, prepend, applyVariables, transformThemeFn }) {
463
429
  if (applyVariables?.length) await transformApply({
464
430
  s,
465
431
  uno,
@@ -468,74 +434,6 @@ async function transformStyle({ content, uno, prepend, filename, applyVariables,
468
434
  if (transformThemeFn) transformTheme(s, uno.config.theme);
469
435
  if (!s.hasChanged()) return;
470
436
  if (prepend) s.prepend(prepend);
471
- return {
472
- code: s.toString(),
473
- map: s.generateMap({
474
- hires: true,
475
- source: filename || ""
476
- })
477
- };
478
- }
479
- //#endregion
480
- //#region src/_preprocess/index.ts
481
- function UnocssSveltePreprocess(options = {}, unoContextFromVite, isViteBuild) {
482
- if (!options.classPrefix) options.classPrefix = "usp-";
483
- let uno;
484
- const makeGenerator = async () => {
485
- if (unoContextFromVite) {
486
- await unoContextFromVite.ready;
487
- return unoContextFromVite.uno;
488
- }
489
- const defaults = { presets: [presetWind3()] };
490
- return await createGenerator((await createRecoveryConfigLoader()(process.cwd(), options.configOrPath)).config, defaults);
491
- };
492
- return {
493
- markup: async ({ content, filename }) => {
494
- uno ??= await makeGenerator();
495
- if (isViteBuild && options.combine === void 0) options.combine = isViteBuild();
496
- return await transformClasses({
497
- content,
498
- filename: filename || "",
499
- uno,
500
- options
501
- });
502
- },
503
- style: async ({ content, attributes, filename }) => {
504
- const svelte3AddPreflights = attributes["uno:preflights"];
505
- const svelte3AddSafelist = attributes["uno:safelist"];
506
- const svelte4DeprecatedAddPreflights = attributes.uno && attributes.preflights;
507
- const svelte4DeprecatedAddSafelist = attributes.uno && attributes.safelist;
508
- let addPreflights = attributes["uno-preflights"] || svelte3AddPreflights || svelte4DeprecatedAddPreflights;
509
- let addSafelist = attributes["uno-safelist"] || svelte3AddSafelist || svelte4DeprecatedAddSafelist;
510
- if (unoContextFromVite && (addPreflights || addSafelist)) {
511
- addPreflights = false;
512
- addSafelist = false;
513
- warnOnce("Notice for those transitioning to @unocss/svelte-scoped/vite: uno-preflights and uno-safelist are only for use in component libraries. Please see the documentation for how to add preflights and safelist into your head tag. If you are consuming a component library built by @unocss/svelte-scoped/preprocess, you can ignore this upgrade notice.");
514
- }
515
- const { hasApply, applyVariables } = checkForApply(content, options.applyVariables);
516
- const hasThemeFn = options.transformThemeDirective === false ? false : !!content.match(themeRE);
517
- if (!(addPreflights || addSafelist || hasApply || hasThemeFn)) return;
518
- uno ??= await makeGenerator();
519
- let preflightsSafelistCss = "";
520
- if (addPreflights || addSafelist) {
521
- const { css } = await uno.generate([], {
522
- preflights: !!addPreflights,
523
- safelist: !!addSafelist,
524
- minify: true
525
- });
526
- preflightsSafelistCss = wrapSelectorsWithGlobal(css);
527
- }
528
- if (hasApply || hasThemeFn) return await transformStyle({
529
- content,
530
- uno,
531
- filename,
532
- prepend: preflightsSafelistCss,
533
- applyVariables,
534
- transformThemeFn: hasThemeFn
535
- });
536
- if (preflightsSafelistCss) return { code: preflightsSafelistCss + content };
537
- }
538
- };
539
437
  }
540
438
  //#endregion
541
- export { UnocssSveltePreprocess as t };
439
+ export { transformClasses as i, transformStyle as n, themeRE as r, checkForApply as t };
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as UnocssSveltePreprocessOptions } from "./preprocess-eGXggMC-.mjs";
1
+ import { n as UnocssSveltePreprocessOptions } from "./preprocess-BlFuH8z9.mjs";
2
2
  import { PluginOptions } from "@unocss/core";
3
3
  import { Plugin } from "vite";
4
4