@unocss/vite 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/index.cjs +34 -4
- package/dist/index.mjs +34 -4
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,9 @@ function getHashPlaceholder(hash) {
|
|
|
61
61
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
62
62
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
63
63
|
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
64
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
65
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
66
|
+
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");
|
|
64
67
|
|
|
65
68
|
function deprecationCheck(config) {
|
|
66
69
|
let warned = false;
|
|
@@ -107,7 +110,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
107
110
|
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
|
|
108
111
|
);
|
|
109
112
|
tokens.clear();
|
|
110
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
113
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
111
114
|
invalidate();
|
|
112
115
|
dispatchReload();
|
|
113
116
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -138,7 +141,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
138
141
|
if (id)
|
|
139
142
|
modules.set(id, code);
|
|
140
143
|
const len = tokens.size;
|
|
141
|
-
await uno.applyExtractors(code, id, tokens);
|
|
144
|
+
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
142
145
|
if (tokens.size > len)
|
|
143
146
|
invalidate();
|
|
144
147
|
}
|
|
@@ -190,6 +193,16 @@ function getPath(id) {
|
|
|
190
193
|
function getHash(input, length = 8) {
|
|
191
194
|
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
192
195
|
}
|
|
196
|
+
function hash(str) {
|
|
197
|
+
let i;
|
|
198
|
+
let l;
|
|
199
|
+
let hval = 2166136261;
|
|
200
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
201
|
+
hval ^= str.charCodeAt(i);
|
|
202
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
203
|
+
}
|
|
204
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
205
|
+
}
|
|
193
206
|
|
|
194
207
|
function replaceAsync(string, searchValue, replacer) {
|
|
195
208
|
try {
|
|
@@ -262,8 +275,9 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
262
275
|
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
263
276
|
if (!transformers.length)
|
|
264
277
|
return;
|
|
278
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
265
279
|
let code = original;
|
|
266
|
-
let s = new MagicString__default(code);
|
|
280
|
+
let s = new MagicString__default(transformSkipCode(code, skipMap));
|
|
267
281
|
const maps = [];
|
|
268
282
|
for (const t of transformers) {
|
|
269
283
|
if (t.idFilter) {
|
|
@@ -274,7 +288,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
274
288
|
}
|
|
275
289
|
await t.transform(s, id, ctx);
|
|
276
290
|
if (s.hasChanged()) {
|
|
277
|
-
code = s.toString();
|
|
291
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
278
292
|
maps.push(s.generateMap({ hires: true, source: id }));
|
|
279
293
|
s = new MagicString__default(code);
|
|
280
294
|
}
|
|
@@ -287,6 +301,22 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
287
301
|
};
|
|
288
302
|
}
|
|
289
303
|
}
|
|
304
|
+
function transformSkipCode(code, map) {
|
|
305
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
306
|
+
if (item != null) {
|
|
307
|
+
const matched = item[0];
|
|
308
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
309
|
+
map.set(withHashKey, matched);
|
|
310
|
+
code = code.replace(matched, withHashKey);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return code;
|
|
314
|
+
}
|
|
315
|
+
function restoreSkipCode(code, map) {
|
|
316
|
+
for (const [withHashKey, matched] of map.entries())
|
|
317
|
+
code = code.replace(withHashKey, matched);
|
|
318
|
+
return code;
|
|
319
|
+
}
|
|
290
320
|
|
|
291
321
|
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
292
322
|
const { content } = await ctx.getConfig();
|
package/dist/index.mjs
CHANGED
|
@@ -48,6 +48,9 @@ function getHashPlaceholder(hash) {
|
|
|
48
48
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
49
49
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
50
50
|
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
51
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
52
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
53
|
+
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");
|
|
51
54
|
|
|
52
55
|
function deprecationCheck(config) {
|
|
53
56
|
let warned = false;
|
|
@@ -94,7 +97,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
94
97
|
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
|
|
95
98
|
);
|
|
96
99
|
tokens.clear();
|
|
97
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
100
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
98
101
|
invalidate();
|
|
99
102
|
dispatchReload();
|
|
100
103
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -125,7 +128,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
125
128
|
if (id)
|
|
126
129
|
modules.set(id, code);
|
|
127
130
|
const len = tokens.size;
|
|
128
|
-
await uno.applyExtractors(code, id, tokens);
|
|
131
|
+
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
129
132
|
if (tokens.size > len)
|
|
130
133
|
invalidate();
|
|
131
134
|
}
|
|
@@ -177,6 +180,16 @@ function getPath(id) {
|
|
|
177
180
|
function getHash(input, length = 8) {
|
|
178
181
|
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
179
182
|
}
|
|
183
|
+
function hash(str) {
|
|
184
|
+
let i;
|
|
185
|
+
let l;
|
|
186
|
+
let hval = 2166136261;
|
|
187
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
188
|
+
hval ^= str.charCodeAt(i);
|
|
189
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
190
|
+
}
|
|
191
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
192
|
+
}
|
|
180
193
|
|
|
181
194
|
function replaceAsync(string, searchValue, replacer) {
|
|
182
195
|
try {
|
|
@@ -249,8 +262,9 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
249
262
|
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
250
263
|
if (!transformers.length)
|
|
251
264
|
return;
|
|
265
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
252
266
|
let code = original;
|
|
253
|
-
let s = new MagicString(code);
|
|
267
|
+
let s = new MagicString(transformSkipCode(code, skipMap));
|
|
254
268
|
const maps = [];
|
|
255
269
|
for (const t of transformers) {
|
|
256
270
|
if (t.idFilter) {
|
|
@@ -261,7 +275,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
261
275
|
}
|
|
262
276
|
await t.transform(s, id, ctx);
|
|
263
277
|
if (s.hasChanged()) {
|
|
264
|
-
code = s.toString();
|
|
278
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
265
279
|
maps.push(s.generateMap({ hires: true, source: id }));
|
|
266
280
|
s = new MagicString(code);
|
|
267
281
|
}
|
|
@@ -274,6 +288,22 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
274
288
|
};
|
|
275
289
|
}
|
|
276
290
|
}
|
|
291
|
+
function transformSkipCode(code, map) {
|
|
292
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
293
|
+
if (item != null) {
|
|
294
|
+
const matched = item[0];
|
|
295
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
296
|
+
map.set(withHashKey, matched);
|
|
297
|
+
code = code.replace(matched, withHashKey);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return code;
|
|
301
|
+
}
|
|
302
|
+
function restoreSkipCode(code, map) {
|
|
303
|
+
for (const [withHashKey, matched] of map.entries())
|
|
304
|
+
code = code.replace(withHashKey, matched);
|
|
305
|
+
return code;
|
|
306
|
+
}
|
|
277
307
|
|
|
278
308
|
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
279
309
|
const { content } = await ctx.getConfig();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.3",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"chokidar": "^3.5.3",
|
|
48
48
|
"fast-glob": "^3.2.12",
|
|
49
49
|
"magic-string": "^0.30.0",
|
|
50
|
-
"@unocss/config": "0.53.
|
|
51
|
-
"@unocss/core": "0.53.
|
|
52
|
-
"@unocss/inspector": "0.53.
|
|
53
|
-
"@unocss/scope": "0.53.
|
|
54
|
-
"@unocss/transformer-directives": "0.53.
|
|
50
|
+
"@unocss/config": "0.53.3",
|
|
51
|
+
"@unocss/core": "0.53.3",
|
|
52
|
+
"@unocss/inspector": "0.53.3",
|
|
53
|
+
"@unocss/scope": "0.53.3",
|
|
54
|
+
"@unocss/transformer-directives": "0.53.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"vite": "^4.3.9",
|
|
58
|
-
"@unocss/shared-integration": "0.53.
|
|
58
|
+
"@unocss/shared-integration": "0.53.3"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|