@unocss/svelte-scoped 0.62.2 → 0.62.4

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,8 +1,8 @@
1
1
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2
- import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.BJnJpFJ9.mjs';
3
- export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.BJnJpFJ9.mjs';
4
- import '@unocss/core';
2
+ import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.rCC-t1bd.mjs';
3
+ export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.rCC-t1bd.mjs';
5
4
  import '@unocss/config';
5
+ import '@unocss/core';
6
6
 
7
7
  declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
8
8
 
@@ -1,8 +1,8 @@
1
1
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2
- import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.BJnJpFJ9.js';
3
- export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.BJnJpFJ9.js';
4
- import '@unocss/core';
2
+ import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.rCC-t1bd.js';
3
+ export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.rCC-t1bd.js';
5
4
  import '@unocss/config';
5
+ import '@unocss/core';
6
6
 
7
7
  declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
8
8
 
@@ -1,7 +1,7 @@
1
- export { U as default } from './shared/svelte-scoped.BBcG3K4A.mjs';
1
+ export { U as default } from './shared/svelte-scoped.C_b8iifX.mjs';
2
2
  import 'node:process';
3
+ import '@unocss/config';
3
4
  import '@unocss/core';
4
5
  import '@unocss/preset-uno';
5
- import '@unocss/config';
6
6
  import 'magic-string';
7
7
  import 'css-tree';
@@ -1,16 +1,20 @@
1
1
  import process from 'node:process';
2
- import { expandVariantGroup, regexScopePlaceholder, warnOnce, toArray, createGenerator } from '@unocss/core';
3
- import presetUno from '@unocss/preset-uno';
4
2
  import { createRecoveryConfigLoader } from '@unocss/config';
3
+ import { expandVariantGroup, warnOnce, regexScopePlaceholder, toArray, createGenerator } from '@unocss/core';
4
+ import presetUno from '@unocss/preset-uno';
5
5
  import MagicString from 'magic-string';
6
6
  import { generate, parse, clone, walk } from 'css-tree';
7
7
 
8
- const NOT_PRECEDED_BY_DIGIT_OR_OPEN_PARENTHESIS_RE = /(?<![\d(])/;
9
- const SELECTOR_STARTING_WITH_BRACKET_OR_PERIOD_RE = /([[.][\s\S]+?)/;
10
- const STYLES_RE = /(\{[\s\S]+?\})/;
11
- const EXTRACT_SELECTOR_RE = new RegExp(NOT_PRECEDED_BY_DIGIT_OR_OPEN_PARENTHESIS_RE.source + SELECTOR_STARTING_WITH_BRACKET_OR_PERIOD_RE.source + STYLES_RE.source, "g");
12
- function wrapSelectorsWithGlobal(css) {
13
- return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
8
+ const notInCommentRE = /(?<!<!--\s*)/;
9
+ const stylesTagWithCapturedDirectivesRE = /<style([^>]*)>[\s\S]*?<\/style\s*>/;
10
+ const actualStylesTagWithCapturedDirectivesRE = new RegExp(notInCommentRE.source + stylesTagWithCapturedDirectivesRE.source, "g");
11
+ const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
12
+ function addGeneratedStylesIntoStyleBlock(code, styles) {
13
+ const preExistingStylesTag = code.match(actualStylesTagWithCapturedDirectivesRE);
14
+ if (preExistingStylesTag)
15
+ return code.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
16
+ return `${code}
17
+ <style>${styles}</style>`;
14
18
  }
15
19
 
16
20
  const classesRE$1 = /class=(["'`])([\s\S]*?)\1/g;
@@ -41,26 +45,6 @@ function hasBody(foundClass) {
41
45
  return foundClass.body;
42
46
  }
43
47
 
44
- const notInCommentRE = /(?<!<!--\s*)/;
45
- const stylesTagWithCapturedDirectivesRE = /<style([^>]*)>[\s\S]*?<\/style\s*>/;
46
- const actualStylesTagWithCapturedDirectivesRE = new RegExp(notInCommentRE.source + stylesTagWithCapturedDirectivesRE.source, "g");
47
- const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
48
- function addGeneratedStylesIntoStyleBlock(code, styles) {
49
- const preExistingStylesTag = code.match(actualStylesTagWithCapturedDirectivesRE);
50
- if (preExistingStylesTag)
51
- return code.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
52
- return `${code}
53
- <style>${styles}</style>`;
54
- }
55
-
56
- async function needsGenerated(token, uno) {
57
- const inSafelist = uno.config.safelist.includes(token);
58
- if (inSafelist)
59
- return false;
60
- const result = await uno.parseToken(token);
61
- return !!result;
62
- }
63
-
64
48
  function hash(str) {
65
49
  let i;
66
50
  let l;
@@ -91,16 +75,12 @@ function isShortcut(token, shortcuts) {
91
75
  return shortcuts.some((s) => s[0] === token);
92
76
  }
93
77
 
94
- async function processDirective({ body: token, start, end, type }, options, uno, filename) {
95
- const isShortcutOrUtility = isShortcut(token, uno.config.shortcuts) || await needsGenerated(token, uno);
96
- if (!isShortcutOrUtility)
97
- return;
98
- const generatedClassName = generateClassName(token, options, filename);
99
- const content = type === "directiveShorthand" ? `${generatedClassName}={${token}}` : generatedClassName;
100
- return {
101
- rulesToGenerate: { [generatedClassName]: [token] },
102
- codeUpdate: { content, start, end }
103
- };
78
+ async function needsGenerated(token, uno) {
79
+ const inSafelist = uno.config.safelist.includes(token);
80
+ if (inSafelist)
81
+ return false;
82
+ const result = await uno.parseToken(token);
83
+ return !!result;
104
84
  }
105
85
 
106
86
  async function sortClassesIntoCategories(body, options, uno, filename) {
@@ -166,6 +146,18 @@ async function processClassBody({ body, start, end }, options, uno, filename) {
166
146
  return { rulesToGenerate, codeUpdate };
167
147
  }
168
148
 
149
+ async function processDirective({ body: token, start, end, type }, options, uno, filename) {
150
+ const isShortcutOrUtility = isShortcut(token, uno.config.shortcuts) || await needsGenerated(token, uno);
151
+ if (!isShortcutOrUtility)
152
+ return;
153
+ const generatedClassName = generateClassName(token, options, filename);
154
+ const content = type === "directiveShorthand" ? `${generatedClassName}={${token}}` : generatedClassName;
155
+ return {
156
+ rulesToGenerate: { [generatedClassName]: [token] },
157
+ codeUpdate: { content, start, end }
158
+ };
159
+ }
160
+
169
161
  async function processClasses(classes, options, uno, filename) {
170
162
  const result = {
171
163
  rulesToGenerate: {},
@@ -189,6 +181,14 @@ async function processClasses(classes, options, uno, filename) {
189
181
  return result;
190
182
  }
191
183
 
184
+ const NOT_PRECEDED_BY_DIGIT_OR_OPEN_PARENTHESIS_RE = /(?<![\d(])/;
185
+ const SELECTOR_STARTING_WITH_BRACKET_OR_PERIOD_RE = /([[.][\s\S]+?)/;
186
+ const STYLES_RE = /(\{[\s\S]+?\})/;
187
+ const EXTRACT_SELECTOR_RE = new RegExp(NOT_PRECEDED_BY_DIGIT_OR_OPEN_PARENTHESIS_RE.source + SELECTOR_STARTING_WITH_BRACKET_OR_PERIOD_RE.source + STYLES_RE.source, "g");
188
+ function wrapSelectorsWithGlobal(css) {
189
+ return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
190
+ }
191
+
192
192
  async function transformClasses({ content, filename, uno, options }) {
193
193
  const classesToProcess = findClasses(content);
194
194
  if (!classesToProcess.length)
@@ -229,6 +229,33 @@ async function generateStyles(rulesToGenerate, uno) {
229
229
  return cssPreparedForSvelteCompiler;
230
230
  }
231
231
 
232
+ async function getUtils(body, uno) {
233
+ const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
234
+ const utils = await parseUtils(classNames, uno);
235
+ const sortedByRankIndex = utils.sort(([aIndex], [bIndex]) => aIndex - bIndex);
236
+ const sortedByParentOrders = sortedByRankIndex.sort(([, , , aParent], [, , , bParent]) => (aParent ? uno.parentOrders.get(aParent) ?? 0 : 0) - (bParent ? uno.parentOrders.get(bParent) ?? 0 : 0));
237
+ return sortedByParentOrders.reduce((acc, item) => {
238
+ const [, selector, body2, parent] = item;
239
+ const sibling = acc.find(([, targetSelector, , targetParent]) => targetSelector === selector && targetParent === parent);
240
+ if (sibling)
241
+ sibling[2] += body2;
242
+ else
243
+ acc.push([...item]);
244
+ return acc;
245
+ }, []);
246
+ }
247
+ async function parseUtils(classNames, uno) {
248
+ const foundUtils = [];
249
+ for (const token of classNames) {
250
+ const util = await uno.parseToken(token, "-");
251
+ if (util)
252
+ foundUtils.push(util);
253
+ else
254
+ warnOnce(`'${token}' not found. You have a typo or need to add a preset.`);
255
+ }
256
+ return foundUtils.flat();
257
+ }
258
+
232
259
  function removeOuterQuotes(input) {
233
260
  if (!input)
234
261
  return "";
@@ -297,33 +324,6 @@ function findFirstCombinatorIndex(input) {
297
324
  return -1;
298
325
  }
299
326
 
300
- async function getUtils(body, uno) {
301
- const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
302
- const utils = await parseUtils(classNames, uno);
303
- const sortedByRankIndex = utils.sort(([aIndex], [bIndex]) => aIndex - bIndex);
304
- const sortedByParentOrders = sortedByRankIndex.sort(([, , , aParent], [, , , bParent]) => (aParent ? uno.parentOrders.get(aParent) ?? 0 : 0) - (bParent ? uno.parentOrders.get(bParent) ?? 0 : 0));
305
- return sortedByParentOrders.reduce((acc, item) => {
306
- const [, selector, body2, parent] = item;
307
- const sibling = acc.find(([, targetSelector, , targetParent]) => targetSelector === selector && targetParent === parent);
308
- if (sibling)
309
- sibling[2] += body2;
310
- else
311
- acc.push([...item]);
312
- return acc;
313
- }, []);
314
- }
315
- async function parseUtils(classNames, uno) {
316
- const foundUtils = [];
317
- for (const token of classNames) {
318
- const util = await uno.parseToken(token, "-");
319
- if (util)
320
- foundUtils.push(util);
321
- else
322
- warnOnce(`'${token}' not found. You have a typo or need to add a preset.`);
323
- }
324
- return foundUtils.flat();
325
- }
326
-
327
327
  async function transformApply(ctx) {
328
328
  const ast = parse(ctx.s.original, {
329
329
  parseAtrulePrelude: false,
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { PluginOptions } from '@unocss/core';
3
- import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.BJnJpFJ9.mjs';
3
+ import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.rCC-t1bd.mjs';
4
4
  import '@unocss/config';
5
5
 
6
6
  interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { PluginOptions } from '@unocss/core';
3
- import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.BJnJpFJ9.js';
3
+ import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.rCC-t1bd.js';
4
4
  import '@unocss/config';
5
5
 
6
6
  interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
package/dist/vite.mjs CHANGED
@@ -1,30 +1,119 @@
1
1
  import process from 'node:process';
2
- import { cssIdRE, createGenerator } from '@unocss/core';
3
2
  import { createRecoveryConfigLoader } from '@unocss/config';
3
+ import { cssIdRE, createGenerator } from '@unocss/core';
4
4
  import presetUno from '@unocss/preset-uno';
5
- import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.BBcG3K4A.mjs';
5
+ import remapping from '@ampproject/remapping';
6
+ import MagicString from 'magic-string';
6
7
  import { readFileSync, existsSync, statSync } from 'node:fs';
7
8
  import { dirname, resolve } from 'node:path';
8
9
  import { fileURLToPath } from 'node:url';
9
- import MagicString from 'magic-string';
10
- import remapping from '@ampproject/remapping';
10
+ import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.C_b8iifX.mjs';
11
11
  import 'css-tree';
12
12
 
13
- function PassPreprocessToSveltePlugin(context, options = {}) {
14
- let commandIsBuild = true;
15
- const isBuild = () => commandIsBuild;
13
+ function ConfigHMRPlugin({ ready }) {
16
14
  return {
17
- name: "unocss:svelte-scoped:pass-preprocess",
18
- enforce: "pre",
19
- configResolved({ command }) {
20
- commandIsBuild = command === "build";
21
- },
22
- api: {
23
- sveltePreprocess: UnocssSveltePreprocess(options, context, isBuild)
15
+ name: "unocss:svelte-scoped:config",
16
+ async configureServer(server) {
17
+ const { sources } = await ready;
18
+ if (!sources.length)
19
+ return;
20
+ server.watcher.add(sources);
21
+ server.watcher.on("add", handleFileChange);
22
+ server.watcher.on("change", handleFileChange);
23
+ server.watcher.on("unlink", handleFileChange);
24
+ function handleFileChange(filepath) {
25
+ if (sources.includes(filepath))
26
+ server.restart();
27
+ }
24
28
  }
25
29
  };
26
30
  }
27
31
 
32
+ const IGNORE_COMMENT = "@unocss-ignore";
33
+ const SKIP_START_COMMENT = "@unocss-skip-start";
34
+ const SKIP_END_COMMENT = "@unocss-skip-end";
35
+ 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");
36
+
37
+ function hash(str) {
38
+ let i;
39
+ let l;
40
+ let hval = 2166136261;
41
+ for (i = 0, l = str.length; i < l; i++) {
42
+ hval ^= str.charCodeAt(i);
43
+ hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
44
+ }
45
+ return `00000${(hval >>> 0).toString(36)}`.slice(-6);
46
+ }
47
+ function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
48
+ for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
49
+ if (item != null) {
50
+ const matched = item[0];
51
+ const withHashKey = `${keyFlag}${hash(matched)}`;
52
+ map.set(withHashKey, matched);
53
+ code = code.replace(matched, withHashKey);
54
+ }
55
+ }
56
+ return code;
57
+ }
58
+ function restoreSkipCode(code, map) {
59
+ for (const [withHashKey, matched] of map.entries())
60
+ code = code.replaceAll(withHashKey, matched);
61
+ return code;
62
+ }
63
+
64
+ async function applyTransformers(ctx, original, id, enforce = "default") {
65
+ if (original.includes(IGNORE_COMMENT))
66
+ return;
67
+ const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
68
+ if (!transformers.length)
69
+ return;
70
+ const skipMap = /* @__PURE__ */ new Map();
71
+ let code = original;
72
+ let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
73
+ const maps = [];
74
+ for (const t of transformers) {
75
+ if (t.idFilter) {
76
+ if (!t.idFilter(id))
77
+ continue;
78
+ } else if (!ctx.filter(code, id)) {
79
+ continue;
80
+ }
81
+ await t.transform(s, id, ctx);
82
+ if (s.hasChanged()) {
83
+ code = restoreSkipCode(s.toString(), skipMap);
84
+ maps.push(s.generateMap({ hires: true, source: id }));
85
+ s = new MagicString(code);
86
+ }
87
+ }
88
+ if (code !== original) {
89
+ return {
90
+ code,
91
+ map: remapping(maps, (_, ctx2) => {
92
+ ctx2.content = code;
93
+ return null;
94
+ })
95
+ };
96
+ }
97
+ }
98
+
99
+ const svelteIdRE = /[&?]svelte/;
100
+ function createCssTransformerPlugins(context, cssTransformers) {
101
+ const enforces = ["default", "pre", "post"];
102
+ return enforces.map((enforce) => ({
103
+ name: `unocss:svelte-scoped-transformers:${enforce}`,
104
+ enforce: enforce === "default" ? void 0 : enforce,
105
+ async transform(code, id) {
106
+ if (!cssIdRE.test(id) || svelteIdRE.test(id))
107
+ return;
108
+ context.uno.config.transformers = cssTransformers ?? [];
109
+ return applyTransformers({
110
+ ...context,
111
+ affectedModules: /* @__PURE__ */ new Set()
112
+ }, code, id, enforce);
113
+ }
114
+ }));
115
+ }
116
+
28
117
  const PLACEHOLDER_USER_SETS_IN_INDEX_HTML = "%unocss-svelte-scoped.global%";
29
118
  const GLOBAL_STYLES_PLACEHOLDER = "unocss_svelte_scoped_global_styles";
30
119
  const DEV_GLOBAL_STYLES_DATA_TITLE = "unocss-svelte-scoped global styles";
@@ -150,113 +239,24 @@ function GlobalStylesPlugin({ ready, uno }, injectReset) {
150
239
  };
151
240
  }
152
241
 
153
- const IGNORE_COMMENT = "@unocss-ignore";
154
- const SKIP_START_COMMENT = "@unocss-skip-start";
155
- const SKIP_END_COMMENT = "@unocss-skip-end";
156
- 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");
157
-
158
- function hash(str) {
159
- let i;
160
- let l;
161
- let hval = 2166136261;
162
- for (i = 0, l = str.length; i < l; i++) {
163
- hval ^= str.charCodeAt(i);
164
- hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
165
- }
166
- return `00000${(hval >>> 0).toString(36)}`.slice(-6);
167
- }
168
- function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
169
- for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
170
- if (item != null) {
171
- const matched = item[0];
172
- const withHashKey = `${keyFlag}${hash(matched)}`;
173
- map.set(withHashKey, matched);
174
- code = code.replace(matched, withHashKey);
175
- }
176
- }
177
- return code;
178
- }
179
- function restoreSkipCode(code, map) {
180
- for (const [withHashKey, matched] of map.entries())
181
- code = code.replaceAll(withHashKey, matched);
182
- return code;
183
- }
184
-
185
- async function applyTransformers(ctx, original, id, enforce = "default") {
186
- if (original.includes(IGNORE_COMMENT))
187
- return;
188
- const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
189
- if (!transformers.length)
190
- return;
191
- const skipMap = /* @__PURE__ */ new Map();
192
- let code = original;
193
- let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
194
- const maps = [];
195
- for (const t of transformers) {
196
- if (t.idFilter) {
197
- if (!t.idFilter(id))
198
- continue;
199
- } else if (!ctx.filter(code, id)) {
200
- continue;
201
- }
202
- await t.transform(s, id, ctx);
203
- if (s.hasChanged()) {
204
- code = restoreSkipCode(s.toString(), skipMap);
205
- maps.push(s.generateMap({ hires: true, source: id }));
206
- s = new MagicString(code);
207
- }
208
- }
209
- if (code !== original) {
210
- return {
211
- code,
212
- map: remapping(maps, (_, ctx2) => {
213
- ctx2.content = code;
214
- return null;
215
- })
216
- };
217
- }
218
- }
219
-
220
- const svelteIdRE = /[&?]svelte/;
221
- function createCssTransformerPlugins(context, cssTransformers) {
222
- const enforces = ["default", "pre", "post"];
223
- return enforces.map((enforce) => ({
224
- name: `unocss:svelte-scoped-transformers:${enforce}`,
225
- enforce: enforce === "default" ? void 0 : enforce,
226
- async transform(code, id) {
227
- if (!cssIdRE.test(id) || svelteIdRE.test(id))
228
- return;
229
- context.uno.config.transformers = cssTransformers ?? [];
230
- return applyTransformers({
231
- ...context,
232
- affectedModules: /* @__PURE__ */ new Set()
233
- }, code, id, enforce);
234
- }
235
- }));
236
- }
237
-
238
- function ConfigHMRPlugin({ ready }) {
242
+ function PassPreprocessToSveltePlugin(context, options = {}) {
243
+ let commandIsBuild = true;
244
+ const isBuild = () => commandIsBuild;
239
245
  return {
240
- name: "unocss:svelte-scoped:config",
241
- async configureServer(server) {
242
- const { sources } = await ready;
243
- if (!sources.length)
244
- return;
245
- server.watcher.add(sources);
246
- server.watcher.on("add", handleFileChange);
247
- server.watcher.on("change", handleFileChange);
248
- server.watcher.on("unlink", handleFileChange);
249
- function handleFileChange(filepath) {
250
- if (sources.includes(filepath))
251
- server.restart();
252
- }
246
+ name: "unocss:svelte-scoped:pass-preprocess",
247
+ enforce: "pre",
248
+ configResolved({ command }) {
249
+ commandIsBuild = command === "build";
250
+ },
251
+ api: {
252
+ sveltePreprocess: UnocssSveltePreprocess(options, context, isBuild)
253
253
  }
254
254
  };
255
255
  }
256
256
 
257
257
  function UnocssSvelteScopedVite(options = {}) {
258
258
  const context = createSvelteScopedContext(options.configOrPath);
259
- if (context.uno.config.transformers)
259
+ if (context.uno.config.transformers?.length)
260
260
  throw new Error('Due to the differences in normal UnoCSS global usage and Svelte Scoped usage, "config.transformers" will be ignored. You can still use transformers in CSS files with the "cssFileTransformers" option.');
261
261
  if (!options.classPrefix)
262
262
  options.classPrefix = "uno-";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/svelte-scoped",
3
3
  "type": "module",
4
- "version": "0.62.2",
4
+ "version": "0.62.4",
5
5
  "description": "Use UnoCSS in a modular fashion with styles being stored only in the Svelte component they are used in: Vite plugin for apps, Svelte preprocessor for component libraries",
6
6
  "author": "Jacob Bowdoin",
7
7
  "license": "MIT",
@@ -52,12 +52,13 @@
52
52
  "dependencies": {
53
53
  "css-tree": "^2.3.1",
54
54
  "magic-string": "^0.30.11",
55
- "@unocss/config": "0.62.2",
56
- "@unocss/reset": "0.62.2"
55
+ "@unocss/config": "0.62.4",
56
+ "@unocss/preset-uno": "0.62.4",
57
+ "@unocss/reset": "0.62.4"
57
58
  },
58
59
  "devDependencies": {
59
60
  "prettier-plugin-svelte": "^2.10.1",
60
- "svelte": "^4.2.18"
61
+ "svelte": "^4.2.19"
61
62
  },
62
63
  "scripts": {
63
64
  "build": "unbuild",
@@ -1,5 +1,5 @@
1
- import { UserConfig, UnoGenerator } from '@unocss/core';
2
1
  import { LoadConfigResult } from '@unocss/config';
2
+ import { UserConfig, UnoGenerator } from '@unocss/core';
3
3
 
4
4
  interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions {
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { UserConfig, UnoGenerator } from '@unocss/core';
2
1
  import { LoadConfigResult } from '@unocss/config';
2
+ import { UserConfig, UnoGenerator } from '@unocss/core';
3
3
 
4
4
  interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions {
5
5
  /**