@unocss/svelte-scoped 0.55.7 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2
- import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.08b60c2b.cjs';
3
- export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.08b60c2b.cjs';
2
+ import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.dc8ddb4d.cjs';
3
+ export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.dc8ddb4d.cjs';
4
4
  import '@unocss/core';
5
+ import '@unocss/config';
5
6
 
6
7
  declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
7
8
 
@@ -1,7 +1,8 @@
1
1
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2
- import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.08b60c2b.mjs';
3
- export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.08b60c2b.mjs';
2
+ import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.dc8ddb4d.mjs';
3
+ export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.dc8ddb4d.mjs';
4
4
  import '@unocss/core';
5
+ import '@unocss/config';
5
6
 
6
7
  declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
7
8
 
@@ -1,7 +1,8 @@
1
1
  import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2
- import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.08b60c2b.js';
3
- export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.08b60c2b.js';
2
+ import { U as UnocssSveltePreprocessOptions, S as SvelteScopedContext } from './shared/svelte-scoped.dc8ddb4d.js';
3
+ export { a as TransformApplyOptions, T as TransformClassesOptions } from './shared/svelte-scoped.dc8ddb4d.js';
4
4
  import '@unocss/core';
5
+ import '@unocss/config';
5
6
 
6
7
  declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: SvelteScopedContext, isViteBuild?: () => boolean): PreprocessorGroup;
7
8
 
@@ -1,4 +1,5 @@
1
1
  import { UserConfig, UnoGenerator } from '@unocss/core';
2
+ import { LoadConfigResult } from '@unocss/config';
2
3
 
3
4
  interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions {
4
5
  /**
@@ -21,7 +22,7 @@ interface TransformClassesOptions {
21
22
  combine?: boolean
22
23
  /**
23
24
  * Used to generate hash for compiled class names
24
- */
25
+ */
25
26
  hashFn?: (str: string) => string
26
27
  }
27
28
 
@@ -37,8 +38,8 @@ interface TransformApplyOptions {
37
38
  }
38
39
 
39
40
  interface SvelteScopedContext {
40
- uno: UnoGenerator<{}>
41
- ready: Promise<UserConfig<{}>>
41
+ uno: UnoGenerator
42
+ ready: Promise<LoadConfigResult<UserConfig>>
42
43
  }
43
44
 
44
45
  export type { SvelteScopedContext as S, TransformClassesOptions as T, UnocssSveltePreprocessOptions as U, TransformApplyOptions as a };
@@ -1,4 +1,5 @@
1
1
  import { UserConfig, UnoGenerator } from '@unocss/core';
2
+ import { LoadConfigResult } from '@unocss/config';
2
3
 
3
4
  interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions {
4
5
  /**
@@ -21,7 +22,7 @@ interface TransformClassesOptions {
21
22
  combine?: boolean
22
23
  /**
23
24
  * Used to generate hash for compiled class names
24
- */
25
+ */
25
26
  hashFn?: (str: string) => string
26
27
  }
27
28
 
@@ -37,8 +38,8 @@ interface TransformApplyOptions {
37
38
  }
38
39
 
39
40
  interface SvelteScopedContext {
40
- uno: UnoGenerator<{}>
41
- ready: Promise<UserConfig<{}>>
41
+ uno: UnoGenerator
42
+ ready: Promise<LoadConfigResult<UserConfig>>
42
43
  }
43
44
 
44
45
  export type { SvelteScopedContext as S, TransformClassesOptions as T, UnocssSveltePreprocessOptions as U, TransformApplyOptions as a };
@@ -1,4 +1,5 @@
1
1
  import { UserConfig, UnoGenerator } from '@unocss/core';
2
+ import { LoadConfigResult } from '@unocss/config';
2
3
 
3
4
  interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions {
4
5
  /**
@@ -21,7 +22,7 @@ interface TransformClassesOptions {
21
22
  combine?: boolean
22
23
  /**
23
24
  * Used to generate hash for compiled class names
24
- */
25
+ */
25
26
  hashFn?: (str: string) => string
26
27
  }
27
28
 
@@ -37,8 +38,8 @@ interface TransformApplyOptions {
37
38
  }
38
39
 
39
40
  interface SvelteScopedContext {
40
- uno: UnoGenerator<{}>
41
- ready: Promise<UserConfig<{}>>
41
+ uno: UnoGenerator
42
+ ready: Promise<LoadConfigResult<UserConfig>>
42
43
  }
43
44
 
44
45
  export type { SvelteScopedContext as S, TransformClassesOptions as T, UnocssSveltePreprocessOptions as U, TransformApplyOptions as a };
package/dist/vite.cjs CHANGED
@@ -13,6 +13,7 @@ const remapping = require('@ampproject/remapping');
13
13
  require('node:crypto');
14
14
  require('css-tree');
15
15
 
16
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
16
17
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
17
18
 
18
19
  const process__default = /*#__PURE__*/_interopDefaultCompat(process);
@@ -20,7 +21,7 @@ const presetUno__default = /*#__PURE__*/_interopDefaultCompat(presetUno);
20
21
  const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
21
22
  const remapping__default = /*#__PURE__*/_interopDefaultCompat(remapping);
22
23
 
23
- function PassPreprocessToSveltePlugin(options = {}, ctx) {
24
+ function PassPreprocessToSveltePlugin(context, options = {}) {
24
25
  let commandIsBuild = true;
25
26
  const isBuild = () => commandIsBuild;
26
27
  return {
@@ -30,7 +31,7 @@ function PassPreprocessToSveltePlugin(options = {}, ctx) {
30
31
  commandIsBuild = command === "build";
31
32
  },
32
33
  api: {
33
- sveltePreprocess: preprocess(options, ctx, isBuild)
34
+ sveltePreprocess: preprocess(options, context, isBuild)
34
35
  }
35
36
  };
36
37
  }
@@ -39,7 +40,7 @@ const PLACEHOLDER_USER_SETS_IN_INDEX_HTML = "%unocss-svelte-scoped.global%";
39
40
  const GLOBAL_STYLES_PLACEHOLDER = "unocss_svelte_scoped_global_styles";
40
41
  const DEV_GLOBAL_STYLES_DATA_TITLE = "unocss-svelte-scoped global styles";
41
42
 
42
- const _dirname = typeof __dirname !== "undefined" ? __dirname : node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('vite.cjs', document.baseURI).href))));
43
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('vite.cjs', document.baseURI).href))));
43
44
  function getReset(injectReset) {
44
45
  if (injectReset.startsWith("@unocss/reset")) {
45
46
  const resolvedPNPM = node_path.resolve(node_path.resolve(_dirname, `../../../${injectReset}`));
@@ -226,7 +227,7 @@ function restoreSkipCode(code, map) {
226
227
  }
227
228
 
228
229
  const svelteIdRE = /[&?]svelte/;
229
- function createCssTransformerPlugins(ctx, cssTransformers) {
230
+ function createCssTransformerPlugins(context, cssTransformers) {
230
231
  const enforces = ["default", "pre", "post"];
231
232
  return enforces.map((enforce) => ({
232
233
  name: `unocss:svelte-scoped-transformers:${enforce}`,
@@ -234,15 +235,34 @@ function createCssTransformerPlugins(ctx, cssTransformers) {
234
235
  async transform(code, id) {
235
236
  if (!id.match(core.cssIdRE) || id.match(svelteIdRE))
236
237
  return;
237
- ctx.uno.config.transformers = cssTransformers ?? [];
238
+ context.uno.config.transformers = cssTransformers ?? [];
238
239
  return applyTransformers({
239
- ...ctx,
240
+ ...context,
240
241
  affectedModules: /* @__PURE__ */ new Set()
241
242
  }, code, id, enforce);
242
243
  }
243
244
  }));
244
245
  }
245
246
 
247
+ function ConfigHMRPlugin({ ready }) {
248
+ return {
249
+ name: "unocss:svelte-scoped:config",
250
+ async configureServer(server) {
251
+ const { sources } = await ready;
252
+ if (!sources.length)
253
+ return;
254
+ server.watcher.add(sources);
255
+ server.watcher.on("add", handleFileChange);
256
+ server.watcher.on("change", handleFileChange);
257
+ server.watcher.on("unlink", handleFileChange);
258
+ function handleFileChange(filepath) {
259
+ if (sources.includes(filepath))
260
+ server.restart();
261
+ }
262
+ }
263
+ };
264
+ }
265
+
246
266
  function UnocssSvelteScopedVite(options = {}) {
247
267
  const context = createSvelteScopedContext(options.configOrPath);
248
268
  if (context.uno.config.transformers)
@@ -250,10 +270,11 @@ function UnocssSvelteScopedVite(options = {}) {
250
270
  if (!options.classPrefix)
251
271
  options.classPrefix = "uno-";
252
272
  const plugins = [
253
- GlobalStylesPlugin(context, options.injectReset)
273
+ GlobalStylesPlugin(context, options.injectReset),
274
+ ConfigHMRPlugin(context)
254
275
  ];
255
276
  if (!options.onlyGlobal)
256
- plugins.push(PassPreprocessToSveltePlugin(options, context));
277
+ plugins.push(PassPreprocessToSveltePlugin(context, options));
257
278
  if (options.cssFileTransformers)
258
279
  plugins.push(...createCssTransformerPlugins(context, options.cssFileTransformers));
259
280
  return plugins;
@@ -267,9 +288,9 @@ function createSvelteScopedContext(configOrPath) {
267
288
  const uno = core.createGenerator();
268
289
  const ready = reloadConfig();
269
290
  async function reloadConfig() {
270
- const { config: config$1 } = await config.loadConfig(process__default.cwd(), configOrPath);
291
+ const { config: config$1, sources } = await config.loadConfig(process__default.cwd(), configOrPath);
271
292
  uno.setConfig(config$1, defaults);
272
- return config$1;
293
+ return { config: config$1, sources };
273
294
  }
274
295
  return {
275
296
  uno,
package/dist/vite.d.cts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { PluginOptions } from '@unocss/core';
3
- import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.08b60c2b.cjs';
3
+ import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.dc8ddb4d.cjs';
4
+ import '@unocss/config';
4
5
 
5
6
  interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
6
7
  /**
7
8
  * Prefix for compiled class names
8
9
  * @default 'uno-'
9
- */
10
+ */
10
11
  classPrefix?: string
11
12
  /**
12
13
  * Inject reset to the beginning of the global stylesheet.
@@ -27,7 +28,7 @@ interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
27
28
  /**
28
29
  * When building a component library using `@unocss/svelte-scoped/preprocessor` you can also use `@unocss/svelte-scoped/vite` with this set to `true` to add needed global styles for your library demo app: resets, preflights, and safelist
29
30
  * @default false
30
- */
31
+ */
31
32
  onlyGlobal?: boolean
32
33
  /**
33
34
  * Process CSS files using UnoCSS transformers.
package/dist/vite.d.mts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { PluginOptions } from '@unocss/core';
3
- import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.08b60c2b.mjs';
3
+ import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.dc8ddb4d.mjs';
4
+ import '@unocss/config';
4
5
 
5
6
  interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
6
7
  /**
7
8
  * Prefix for compiled class names
8
9
  * @default 'uno-'
9
- */
10
+ */
10
11
  classPrefix?: string
11
12
  /**
12
13
  * Inject reset to the beginning of the global stylesheet.
@@ -27,7 +28,7 @@ interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
27
28
  /**
28
29
  * When building a component library using `@unocss/svelte-scoped/preprocessor` you can also use `@unocss/svelte-scoped/vite` with this set to `true` to add needed global styles for your library demo app: resets, preflights, and safelist
29
30
  * @default false
30
- */
31
+ */
31
32
  onlyGlobal?: boolean
32
33
  /**
33
34
  * Process CSS files using UnoCSS transformers.
package/dist/vite.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { PluginOptions } from '@unocss/core';
3
- import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.08b60c2b.js';
3
+ import { U as UnocssSveltePreprocessOptions } from './shared/svelte-scoped.dc8ddb4d.js';
4
+ import '@unocss/config';
4
5
 
5
6
  interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
6
7
  /**
7
8
  * Prefix for compiled class names
8
9
  * @default 'uno-'
9
- */
10
+ */
10
11
  classPrefix?: string
11
12
  /**
12
13
  * Inject reset to the beginning of the global stylesheet.
@@ -27,7 +28,7 @@ interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
27
28
  /**
28
29
  * When building a component library using `@unocss/svelte-scoped/preprocessor` you can also use `@unocss/svelte-scoped/vite` with this set to `true` to add needed global styles for your library demo app: resets, preflights, and safelist
29
30
  * @default false
30
- */
31
+ */
31
32
  onlyGlobal?: boolean
32
33
  /**
33
34
  * Process CSS files using UnoCSS transformers.
package/dist/vite.mjs CHANGED
@@ -11,7 +11,7 @@ import remapping from '@ampproject/remapping';
11
11
  import 'node:crypto';
12
12
  import 'css-tree';
13
13
 
14
- function PassPreprocessToSveltePlugin(options = {}, ctx) {
14
+ function PassPreprocessToSveltePlugin(context, options = {}) {
15
15
  let commandIsBuild = true;
16
16
  const isBuild = () => commandIsBuild;
17
17
  return {
@@ -21,7 +21,7 @@ function PassPreprocessToSveltePlugin(options = {}, ctx) {
21
21
  commandIsBuild = command === "build";
22
22
  },
23
23
  api: {
24
- sveltePreprocess: UnocssSveltePreprocess(options, ctx, isBuild)
24
+ sveltePreprocess: UnocssSveltePreprocess(options, context, isBuild)
25
25
  }
26
26
  };
27
27
  }
@@ -217,7 +217,7 @@ function restoreSkipCode(code, map) {
217
217
  }
218
218
 
219
219
  const svelteIdRE = /[&?]svelte/;
220
- function createCssTransformerPlugins(ctx, cssTransformers) {
220
+ function createCssTransformerPlugins(context, cssTransformers) {
221
221
  const enforces = ["default", "pre", "post"];
222
222
  return enforces.map((enforce) => ({
223
223
  name: `unocss:svelte-scoped-transformers:${enforce}`,
@@ -225,15 +225,34 @@ function createCssTransformerPlugins(ctx, cssTransformers) {
225
225
  async transform(code, id) {
226
226
  if (!id.match(cssIdRE) || id.match(svelteIdRE))
227
227
  return;
228
- ctx.uno.config.transformers = cssTransformers ?? [];
228
+ context.uno.config.transformers = cssTransformers ?? [];
229
229
  return applyTransformers({
230
- ...ctx,
230
+ ...context,
231
231
  affectedModules: /* @__PURE__ */ new Set()
232
232
  }, code, id, enforce);
233
233
  }
234
234
  }));
235
235
  }
236
236
 
237
+ function ConfigHMRPlugin({ ready }) {
238
+ return {
239
+ name: "unocss:svelte-scoped:config",
240
+ async configureServer(server) {
241
+ const { sources } = await ready;
242
+ if (!sources.length)
243
+ return;
244
+ server.watcher.add(sources);
245
+ server.watcher.on("add", handleFileChange);
246
+ server.watcher.on("change", handleFileChange);
247
+ server.watcher.on("unlink", handleFileChange);
248
+ function handleFileChange(filepath) {
249
+ if (sources.includes(filepath))
250
+ server.restart();
251
+ }
252
+ }
253
+ };
254
+ }
255
+
237
256
  function UnocssSvelteScopedVite(options = {}) {
238
257
  const context = createSvelteScopedContext(options.configOrPath);
239
258
  if (context.uno.config.transformers)
@@ -241,10 +260,11 @@ function UnocssSvelteScopedVite(options = {}) {
241
260
  if (!options.classPrefix)
242
261
  options.classPrefix = "uno-";
243
262
  const plugins = [
244
- GlobalStylesPlugin(context, options.injectReset)
263
+ GlobalStylesPlugin(context, options.injectReset),
264
+ ConfigHMRPlugin(context)
245
265
  ];
246
266
  if (!options.onlyGlobal)
247
- plugins.push(PassPreprocessToSveltePlugin(options, context));
267
+ plugins.push(PassPreprocessToSveltePlugin(context, options));
248
268
  if (options.cssFileTransformers)
249
269
  plugins.push(...createCssTransformerPlugins(context, options.cssFileTransformers));
250
270
  return plugins;
@@ -258,9 +278,9 @@ function createSvelteScopedContext(configOrPath) {
258
278
  const uno = createGenerator();
259
279
  const ready = reloadConfig();
260
280
  async function reloadConfig() {
261
- const { config } = await loadConfig(process.cwd(), configOrPath);
281
+ const { config, sources } = await loadConfig(process.cwd(), configOrPath);
262
282
  uno.setConfig(config, defaults);
263
- return config;
283
+ return { config, sources };
264
284
  }
265
285
  return {
266
286
  uno,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@unocss/svelte-scoped",
3
3
  "type": "module",
4
- "version": "0.55.7",
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, preprocessor for component libraries",
4
+ "version": "0.56.0",
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",
8
8
  "homepage": "https://github.com/unocss/unocss/tree/main/packages/svelte-scoped#readme",
@@ -54,8 +54,8 @@
54
54
  "dependencies": {
55
55
  "css-tree": "^2.3.1",
56
56
  "magic-string": "^0.30.3",
57
- "@unocss/config": "0.55.7",
58
- "@unocss/reset": "0.55.7"
57
+ "@unocss/config": "0.56.0",
58
+ "@unocss/reset": "0.56.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "prettier-plugin-svelte": "^2.10.1",