@unocss/svelte-scoped 0.53.0 → 0.53.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/preprocess.cjs +1 -1
- package/dist/preprocess.mjs +1 -1
- package/dist/shared/{svelte-scoped.d229bfc8.mjs → svelte-scoped.089933b6.mjs} +1 -1
- package/dist/shared/{svelte-scoped.2f74d0fb.cjs → svelte-scoped.ff02f958.cjs} +1 -1
- package/dist/vite.cjs +96 -2
- package/dist/vite.d.ts +6 -1
- package/dist/vite.mjs +92 -3
- package/package.json +5 -4
package/dist/preprocess.cjs
CHANGED
package/dist/preprocess.mjs
CHANGED
|
@@ -129,7 +129,7 @@ async function sortClassesIntoCategories(body, options, uno, filename) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const expressionsRE = /\S*{[^{}]+?}\S*/g;
|
|
132
|
-
const classesRE = /(["'\`])([\S\s]
|
|
132
|
+
const classesRE = /(["'\`])([\S\s]*?)\1/g;
|
|
133
133
|
async function processExpressions(body, options, uno, filename) {
|
|
134
134
|
const rulesToGenerate = {};
|
|
135
135
|
const updatedExpressions = [];
|
|
@@ -136,7 +136,7 @@ async function sortClassesIntoCategories(body, options, uno, filename) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
const expressionsRE = /\S*{[^{}]+?}\S*/g;
|
|
139
|
-
const classesRE = /(["'\`])([\S\s]
|
|
139
|
+
const classesRE = /(["'\`])([\S\s]*?)\1/g;
|
|
140
140
|
async function processExpressions(body, options, uno, filename) {
|
|
141
141
|
const rulesToGenerate = {};
|
|
142
142
|
const updatedExpressions = [];
|
package/dist/vite.cjs
CHANGED
|
@@ -2,14 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
const core = require('@unocss/core');
|
|
4
4
|
const config = require('@unocss/config');
|
|
5
|
-
const index = require('./shared/svelte-scoped.
|
|
5
|
+
const index = require('./shared/svelte-scoped.ff02f958.cjs');
|
|
6
6
|
const node_fs = require('node:fs');
|
|
7
7
|
const node_path = require('node:path');
|
|
8
8
|
const node_url = require('node:url');
|
|
9
|
+
const MagicString = require('magic-string');
|
|
10
|
+
const remapping = require('@ampproject/remapping');
|
|
11
|
+
require('node:crypto');
|
|
9
12
|
require('@unocss/preset-uno');
|
|
10
|
-
require('magic-string');
|
|
11
13
|
require('css-tree');
|
|
12
14
|
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
16
|
+
|
|
17
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
18
|
+
const remapping__default = /*#__PURE__*/_interopDefaultLegacy(remapping);
|
|
19
|
+
|
|
13
20
|
function PassPreprocessToSveltePlugin(options = {}, ctx) {
|
|
14
21
|
let commandIsBuild = true;
|
|
15
22
|
const isBuild = () => commandIsBuild;
|
|
@@ -144,13 +151,100 @@ function GlobalStylesPlugin({ ready, uno }, injectReset) {
|
|
|
144
151
|
};
|
|
145
152
|
}
|
|
146
153
|
|
|
154
|
+
const IGNORE_COMMENT = "@unocss-ignore";
|
|
155
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
156
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
157
|
+
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");
|
|
158
|
+
|
|
159
|
+
function hash(str) {
|
|
160
|
+
let i;
|
|
161
|
+
let l;
|
|
162
|
+
let hval = 2166136261;
|
|
163
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
164
|
+
hval ^= str.charCodeAt(i);
|
|
165
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
166
|
+
}
|
|
167
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
171
|
+
if (original.includes(IGNORE_COMMENT))
|
|
172
|
+
return;
|
|
173
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
174
|
+
if (!transformers.length)
|
|
175
|
+
return;
|
|
176
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
177
|
+
let code = original;
|
|
178
|
+
let s = new MagicString__default(transformSkipCode(code, skipMap));
|
|
179
|
+
const maps = [];
|
|
180
|
+
for (const t of transformers) {
|
|
181
|
+
if (t.idFilter) {
|
|
182
|
+
if (!t.idFilter(id))
|
|
183
|
+
continue;
|
|
184
|
+
} else if (!ctx.filter(code, id)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
await t.transform(s, id, ctx);
|
|
188
|
+
if (s.hasChanged()) {
|
|
189
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
190
|
+
maps.push(s.generateMap({ hires: true, source: id }));
|
|
191
|
+
s = new MagicString__default(code);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (code !== original) {
|
|
195
|
+
ctx.affectedModules.add(id);
|
|
196
|
+
return {
|
|
197
|
+
code,
|
|
198
|
+
map: remapping__default(maps, () => null)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function transformSkipCode(code, map) {
|
|
203
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
204
|
+
if (item != null) {
|
|
205
|
+
const matched = item[0];
|
|
206
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
207
|
+
map.set(withHashKey, matched);
|
|
208
|
+
code = code.replace(matched, withHashKey);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return code;
|
|
212
|
+
}
|
|
213
|
+
function restoreSkipCode(code, map) {
|
|
214
|
+
for (const [withHashKey, matched] of map.entries())
|
|
215
|
+
code = code.replace(withHashKey, matched);
|
|
216
|
+
return code;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const svelteIdRE = /[&?]svelte/;
|
|
220
|
+
function createCssTransformerPlugins(ctx, cssTransformers) {
|
|
221
|
+
const enforces = ["default", "pre", "post"];
|
|
222
|
+
return enforces.map((enforce) => ({
|
|
223
|
+
name: `unocss:svelte-scoped-transformers:${enforce}`,
|
|
224
|
+
enforce: enforce === "default" ? void 0 : enforce,
|
|
225
|
+
async transform(code, id) {
|
|
226
|
+
if (!id.match(core.cssIdRE) || id.match(svelteIdRE))
|
|
227
|
+
return;
|
|
228
|
+
ctx.uno.config.transformers = cssTransformers ?? [];
|
|
229
|
+
return applyTransformers({
|
|
230
|
+
...ctx,
|
|
231
|
+
affectedModules: /* @__PURE__ */ new Set()
|
|
232
|
+
}, code, id, enforce);
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
|
|
147
237
|
function UnocssSvelteScopedVite(options = {}) {
|
|
148
238
|
const context = createSvelteScopedContext(options.configOrPath);
|
|
239
|
+
if (context.uno.config.transformers)
|
|
240
|
+
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.');
|
|
149
241
|
const plugins = [
|
|
150
242
|
GlobalStylesPlugin(context, options.injectReset)
|
|
151
243
|
];
|
|
152
244
|
if (!options.onlyGlobal)
|
|
153
245
|
plugins.push(PassPreprocessToSveltePlugin(options, context));
|
|
246
|
+
if (options.cssFileTransformers)
|
|
247
|
+
plugins.push(...createCssTransformerPlugins(context, options.cssFileTransformers));
|
|
154
248
|
return plugins;
|
|
155
249
|
}
|
|
156
250
|
function createSvelteScopedContext(configOrPath) {
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import { U as UnocssSveltePreprocessOptions } from './types.d-20d48151.js';
|
|
3
|
-
import '@unocss/core';
|
|
3
|
+
import { PluginOptions } from '@unocss/core';
|
|
4
4
|
|
|
5
5
|
interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
|
|
6
6
|
/**
|
|
@@ -29,6 +29,11 @@ interface UnocssSvelteScopedViteOptions extends UnocssSveltePreprocessOptions {
|
|
|
29
29
|
* @default false
|
|
30
30
|
*/
|
|
31
31
|
onlyGlobal?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Process CSS files using UnoCSS transformers.
|
|
34
|
+
* @default undefined
|
|
35
|
+
*/
|
|
36
|
+
cssFileTransformers?: PluginOptions['transformers']
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
declare function UnocssSvelteScopedVite(options?: UnocssSvelteScopedViteOptions): Plugin[];
|
package/dist/vite.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { createGenerator } from '@unocss/core';
|
|
1
|
+
import { cssIdRE, createGenerator } from '@unocss/core';
|
|
2
2
|
import { loadConfig } from '@unocss/config';
|
|
3
|
-
import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.
|
|
3
|
+
import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.089933b6.mjs';
|
|
4
4
|
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
5
5
|
import { dirname, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import MagicString from 'magic-string';
|
|
8
|
+
import remapping from '@ampproject/remapping';
|
|
9
|
+
import 'node:crypto';
|
|
7
10
|
import '@unocss/preset-uno';
|
|
8
|
-
import 'magic-string';
|
|
9
11
|
import 'css-tree';
|
|
10
12
|
|
|
11
13
|
function PassPreprocessToSveltePlugin(options = {}, ctx) {
|
|
@@ -142,13 +144,100 @@ function GlobalStylesPlugin({ ready, uno }, injectReset) {
|
|
|
142
144
|
};
|
|
143
145
|
}
|
|
144
146
|
|
|
147
|
+
const IGNORE_COMMENT = "@unocss-ignore";
|
|
148
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
149
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
150
|
+
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");
|
|
151
|
+
|
|
152
|
+
function hash(str) {
|
|
153
|
+
let i;
|
|
154
|
+
let l;
|
|
155
|
+
let hval = 2166136261;
|
|
156
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
157
|
+
hval ^= str.charCodeAt(i);
|
|
158
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
159
|
+
}
|
|
160
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
164
|
+
if (original.includes(IGNORE_COMMENT))
|
|
165
|
+
return;
|
|
166
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
167
|
+
if (!transformers.length)
|
|
168
|
+
return;
|
|
169
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
170
|
+
let code = original;
|
|
171
|
+
let s = new MagicString(transformSkipCode(code, skipMap));
|
|
172
|
+
const maps = [];
|
|
173
|
+
for (const t of transformers) {
|
|
174
|
+
if (t.idFilter) {
|
|
175
|
+
if (!t.idFilter(id))
|
|
176
|
+
continue;
|
|
177
|
+
} else if (!ctx.filter(code, id)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
await t.transform(s, id, ctx);
|
|
181
|
+
if (s.hasChanged()) {
|
|
182
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
183
|
+
maps.push(s.generateMap({ hires: true, source: id }));
|
|
184
|
+
s = new MagicString(code);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (code !== original) {
|
|
188
|
+
ctx.affectedModules.add(id);
|
|
189
|
+
return {
|
|
190
|
+
code,
|
|
191
|
+
map: remapping(maps, () => null)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function transformSkipCode(code, map) {
|
|
196
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
197
|
+
if (item != null) {
|
|
198
|
+
const matched = item[0];
|
|
199
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
200
|
+
map.set(withHashKey, matched);
|
|
201
|
+
code = code.replace(matched, withHashKey);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return code;
|
|
205
|
+
}
|
|
206
|
+
function restoreSkipCode(code, map) {
|
|
207
|
+
for (const [withHashKey, matched] of map.entries())
|
|
208
|
+
code = code.replace(withHashKey, matched);
|
|
209
|
+
return code;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const svelteIdRE = /[&?]svelte/;
|
|
213
|
+
function createCssTransformerPlugins(ctx, cssTransformers) {
|
|
214
|
+
const enforces = ["default", "pre", "post"];
|
|
215
|
+
return enforces.map((enforce) => ({
|
|
216
|
+
name: `unocss:svelte-scoped-transformers:${enforce}`,
|
|
217
|
+
enforce: enforce === "default" ? void 0 : enforce,
|
|
218
|
+
async transform(code, id) {
|
|
219
|
+
if (!id.match(cssIdRE) || id.match(svelteIdRE))
|
|
220
|
+
return;
|
|
221
|
+
ctx.uno.config.transformers = cssTransformers ?? [];
|
|
222
|
+
return applyTransformers({
|
|
223
|
+
...ctx,
|
|
224
|
+
affectedModules: /* @__PURE__ */ new Set()
|
|
225
|
+
}, code, id, enforce);
|
|
226
|
+
}
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
145
230
|
function UnocssSvelteScopedVite(options = {}) {
|
|
146
231
|
const context = createSvelteScopedContext(options.configOrPath);
|
|
232
|
+
if (context.uno.config.transformers)
|
|
233
|
+
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.');
|
|
147
234
|
const plugins = [
|
|
148
235
|
GlobalStylesPlugin(context, options.injectReset)
|
|
149
236
|
];
|
|
150
237
|
if (!options.onlyGlobal)
|
|
151
238
|
plugins.push(PassPreprocessToSveltePlugin(options, context));
|
|
239
|
+
if (options.cssFileTransformers)
|
|
240
|
+
plugins.push(...createCssTransformerPlugins(context, options.cssFileTransformers));
|
|
152
241
|
return plugins;
|
|
153
242
|
}
|
|
154
243
|
function createSvelteScopedContext(configOrPath) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/svelte-scoped",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.53.
|
|
4
|
+
"version": "0.53.3",
|
|
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, preprocessor for component libraries",
|
|
6
6
|
"author": "Jacob Bowdoin",
|
|
7
7
|
"license": "MIT",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"css-tree": "^2.3.1",
|
|
56
56
|
"magic-string": "^0.30.0",
|
|
57
|
-
"@unocss/config": "0.53.
|
|
58
|
-
"@unocss/reset": "0.53.
|
|
57
|
+
"@unocss/config": "0.53.3",
|
|
58
|
+
"@unocss/reset": "0.53.3"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"prettier-plugin-svelte": "^2.10.1",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "unbuild",
|
|
66
66
|
"stub": "unbuild --stub",
|
|
67
|
-
"bench": "vitest bench"
|
|
67
|
+
"bench": "vitest bench",
|
|
68
|
+
"test:integration": "pnpm -r --filter=\"./test/fixtures/*\" test"
|
|
68
69
|
}
|
|
69
70
|
}
|