@styleframe/scanner 3.1.0 → 3.1.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.
package/dist/index.js CHANGED
@@ -1,50 +1,44 @@
1
- import { readFile } from "node:fs/promises";
2
- import fg from "fast-glob";
3
- function hashContent(content) {
4
- let hash = 0;
5
- for (let i = 0; i < content.length; i++) {
6
- const char = content.charCodeAt(i);
7
- hash = (hash << 5) - hash + char;
8
- hash = hash & hash;
9
- }
10
- return `${hash.toString(16)}-${content.length}`;
11
- }
12
- function createCache() {
13
- const entries = /* @__PURE__ */ new Map();
1
+ import { readFile as D } from "node:fs/promises";
2
+ import j from "fast-glob";
3
+ import { classNameToCssSelector as z, defaultUtilitySelectorFn as k } from "@styleframe/core";
4
+ function B(s) {
5
+ let e = 0;
6
+ for (let t = 0; t < s.length; t++) {
7
+ const n = s.charCodeAt(t);
8
+ e = (e << 5) - e + n, e = e & e;
9
+ }
10
+ return `${e.toString(16)}-${s.length}`;
11
+ }
12
+ function G() {
13
+ const s = /* @__PURE__ */ new Map();
14
14
  return {
15
- get(filePath) {
16
- const entry = entries.get(filePath);
17
- return entry?.result ?? null;
15
+ get(e) {
16
+ return s.get(e)?.result ?? null;
18
17
  },
19
- set(filePath, result, contentHash) {
20
- entries.set(filePath, {
21
- hash: contentHash,
22
- result,
18
+ set(e, t, n) {
19
+ s.set(e, {
20
+ hash: n,
21
+ result: t,
23
22
  timestamp: Date.now()
24
23
  });
25
24
  },
26
- isValid(filePath, contentHash) {
27
- const entry = entries.get(filePath);
28
- return entry !== void 0 && entry.hash === contentHash;
25
+ isValid(e, t) {
26
+ const n = s.get(e);
27
+ return n !== void 0 && n.hash === t;
29
28
  },
30
- getIfValid(filePath, contentHash) {
31
- const entry = entries.get(filePath);
32
- if (entry && entry.hash === contentHash) {
33
- return entry.result;
34
- }
35
- return null;
29
+ getIfValid(e, t) {
30
+ const n = s.get(e);
31
+ return n && n.hash === t ? n.result : null;
36
32
  },
37
- invalidate(filePath) {
38
- entries.delete(filePath);
33
+ invalidate(e) {
34
+ s.delete(e);
39
35
  },
40
36
  clear() {
41
- entries.clear();
37
+ s.clear();
42
38
  }
43
39
  };
44
40
  }
45
- const UTILITY_CLASS_PATTERN = /_[a-zA-Z][a-zA-Z0-9-]*(?::[a-zA-Z0-9._-]+|:\[[^\]]+\])*/g;
46
- const ARBITRARY_VALUE_PATTERN = /^\[(.+)\]$/;
47
- const DEFAULT_EXTENSIONS = [
41
+ const X = /_[a-zA-Z][a-zA-Z0-9-]*(?::[a-zA-Z0-9._-]+|:\[[^\]]+\])*/g, Q = /^\[(.+)\]$/, he = [
48
42
  "html",
49
43
  "htm",
50
44
  "vue",
@@ -59,8 +53,7 @@ const DEFAULT_EXTENSIONS = [
59
53
  "erb",
60
54
  "twig",
61
55
  "blade.php"
62
- ];
63
- const DEFAULT_IGNORE_PATTERNS = [
56
+ ], H = [
64
57
  "**/node_modules/**",
65
58
  "**/.git/**",
66
59
  "**/dist/**",
@@ -69,759 +62,435 @@ const DEFAULT_IGNORE_PATTERNS = [
69
62
  "**/.nuxt/**",
70
63
  "**/coverage/**"
71
64
  ];
72
- function parseUtilityClass(className) {
73
- if (!className.startsWith("_")) {
65
+ function C(s) {
66
+ if (!s.startsWith("_"))
74
67
  return null;
75
- }
76
- const withoutPrefix = className.slice(1);
77
- if (!withoutPrefix) {
68
+ const e = s.slice(1);
69
+ if (!e)
78
70
  return null;
79
- }
80
- const segments = splitByColons(withoutPrefix);
81
- if (segments.length === 0) {
71
+ const t = K(e);
72
+ if (t.length === 0)
82
73
  return null;
83
- }
84
- let name;
85
- let value;
86
- let modifiers = [];
87
- if (segments.length === 1) {
88
- name = segments[0];
89
- value = "default";
90
- } else {
91
- value = segments[segments.length - 1];
92
- name = segments[segments.length - 2];
93
- modifiers = segments.slice(0, -2);
94
- }
95
- let isArbitrary = false;
96
- let arbitraryValue;
97
- const arbitraryMatch = value.match(ARBITRARY_VALUE_PATTERN);
98
- if (arbitraryMatch) {
99
- isArbitrary = true;
100
- arbitraryValue = arbitraryMatch[1];
101
- }
102
- return {
103
- raw: className,
104
- name,
105
- value,
106
- modifiers,
107
- isArbitrary,
108
- arbitraryValue
74
+ let n, r, c = [];
75
+ t.length === 1 ? (n = t[0], r = "default") : (r = t[t.length - 1], n = t[t.length - 2], c = t.slice(0, -2));
76
+ let a = !1, l;
77
+ const u = r.match(Q);
78
+ return u && (a = !0, l = u[1]), {
79
+ raw: s,
80
+ name: n,
81
+ value: r,
82
+ modifiers: c,
83
+ isArbitrary: a,
84
+ arbitraryValue: l
109
85
  };
110
86
  }
111
- function splitByColons(str) {
112
- const segments = [];
113
- let current = "";
114
- let bracketDepth = 0;
115
- for (const char of str) {
116
- if (char === "[") {
117
- bracketDepth++;
118
- current += char;
119
- } else if (char === "]") {
120
- bracketDepth--;
121
- current += char;
122
- } else if (char === ":" && bracketDepth === 0) {
123
- if (current) {
124
- segments.push(current);
125
- }
126
- current = "";
127
- } else {
128
- current += char;
129
- }
130
- }
131
- if (bracketDepth !== 0) {
132
- return [];
133
- }
134
- if (current) {
135
- segments.push(current);
136
- }
137
- return segments;
138
- }
139
- function extractUtilityClasses(content, pattern) {
140
- const matches = content.match(pattern ?? UTILITY_CLASS_PATTERN);
141
- return matches ? [...new Set(matches)] : [];
142
- }
143
- function generateUtilityClassName(name, value, modifiers = []) {
144
- const parts = [...modifiers, name];
145
- if (value !== "default") {
146
- parts.push(value);
147
- }
148
- return `_${parts.join(":")}`;
149
- }
150
- const CLASSNAME_EXPR_PATTERN = /\bclassName\s*=\s*\{/g;
151
- const CLASS_EXPR_PATTERN = /\bclass\s*=\s*\{/g;
152
- const CLASS_ATTR_PATTERN = /\bclass\s*=\s*["']([^"']+)["']/gi;
153
- const CLASSNAME_STRING_PATTERN = /\bclassName\s*=\s*["']([^"']+)["']/gi;
154
- const SVELTE_CLASS_DIRECTIVE_PATTERN = /\bclass:([^\s={>]+)/g;
155
- const SINGLE_QUOTE_PATTERN = /'([^'\\]*(?:\\.[^'\\]*)*)'/g;
156
- const DOUBLE_QUOTE_PATTERN = /"([^"\\]*(?:\\.[^"\\]*)*)"/g;
157
- const TEMPLATE_LITERAL_PATTERN = /`([^`\\]*(?:\\.[^`\\]*)*)`/g;
158
- function extractBracedContent(str) {
159
- let depth = 1;
160
- let i = 0;
161
- while (i < str.length && depth > 0) {
162
- const char = str[i];
163
- if (char === "{") {
164
- depth++;
165
- } else if (char === "}") {
166
- depth--;
167
- }
168
- i++;
169
- }
170
- if (depth !== 0) {
171
- return null;
172
- }
173
- return str.slice(0, i - 1);
174
- }
175
- function extractClassNameExpressions(content) {
176
- const results = [];
177
- CLASSNAME_EXPR_PATTERN.lastIndex = 0;
178
- let match;
179
- while ((match = CLASSNAME_EXPR_PATTERN.exec(content)) !== null) {
180
- const startIndex = match.index + match[0].length;
181
- const remaining = content.slice(startIndex);
182
- const bracedContent = extractBracedContent(remaining);
183
- if (bracedContent !== null) {
184
- results.push(bracedContent);
185
- }
186
- }
187
- return results;
188
- }
189
- function extractClassExpressions(content) {
190
- const results = [];
191
- CLASS_EXPR_PATTERN.lastIndex = 0;
192
- let match;
193
- while ((match = CLASS_EXPR_PATTERN.exec(content)) !== null) {
194
- const startIndex = match.index + match[0].length;
195
- const remaining = content.slice(startIndex);
196
- const bracedContent = extractBracedContent(remaining);
197
- if (bracedContent !== null) {
198
- results.push(bracedContent);
199
- }
200
- }
201
- return results;
202
- }
203
- function extractFromHTML(content, pattern) {
204
- const classes = [];
205
- CLASS_ATTR_PATTERN.lastIndex = 0;
206
- let match;
207
- while ((match = CLASS_ATTR_PATTERN.exec(content)) !== null) {
208
- if (match[1]) {
209
- classes.push(...extractUtilityClasses(match[1], pattern));
210
- }
211
- }
212
- return classes;
213
- }
214
- function extractFromJSX(content, pattern) {
215
- const classes = [];
216
- CLASSNAME_STRING_PATTERN.lastIndex = 0;
217
- let match;
218
- while ((match = CLASSNAME_STRING_PATTERN.exec(content)) !== null) {
219
- if (match[1]) {
220
- classes.push(...extractUtilityClasses(match[1], pattern));
221
- }
222
- }
223
- const expressions = extractClassNameExpressions(content);
224
- for (const expr of expressions) {
225
- classes.push(...extractFromStringLiterals(expr, pattern));
226
- }
227
- return [...new Set(classes)];
228
- }
229
- function extractFromVue(content, pattern) {
230
- const classes = [];
231
- const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
232
- if (templateMatch?.[1]) {
233
- classes.push(...extractFromHTML(templateMatch[1], pattern));
234
- classes.push(...extractFromStringLiterals(templateMatch[1], pattern));
235
- }
236
- const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
237
- if (scriptMatch?.[1]) {
238
- classes.push(...extractFromStringLiterals(scriptMatch[1], pattern));
239
- }
240
- return [...new Set(classes)];
241
- }
242
- function extractFromSvelte(content, pattern) {
243
- const classes = [];
244
- classes.push(...extractFromHTML(content, pattern));
245
- const expressions = extractClassExpressions(content);
246
- for (const expr of expressions) {
247
- classes.push(...extractFromStringLiterals(expr, pattern));
248
- }
249
- SVELTE_CLASS_DIRECTIVE_PATTERN.lastIndex = 0;
250
- let match;
251
- while ((match = SVELTE_CLASS_DIRECTIVE_PATTERN.exec(content)) !== null) {
252
- if (match[1]) {
253
- classes.push(match[1]);
254
- }
255
- }
256
- const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
257
- if (scriptMatch?.[1]) {
258
- classes.push(...extractFromStringLiterals(scriptMatch[1], pattern));
259
- }
260
- return [...new Set(classes)];
261
- }
262
- function extractFromAstro(content, pattern) {
263
- const classes = [];
264
- classes.push(...extractFromHTML(content, pattern));
265
- classes.push(...extractFromJSX(content, pattern));
266
- const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
267
- if (frontmatterMatch?.[1]) {
268
- classes.push(...extractFromStringLiterals(frontmatterMatch[1], pattern));
269
- }
270
- return [...new Set(classes)];
271
- }
272
- function extractFromStringLiterals(content, pattern) {
273
- const classes = [];
274
- let match;
275
- SINGLE_QUOTE_PATTERN.lastIndex = 0;
276
- while ((match = SINGLE_QUOTE_PATTERN.exec(content)) !== null) {
277
- if (match[1]) {
278
- classes.push(...extractUtilityClasses(match[1], pattern));
279
- }
280
- }
281
- DOUBLE_QUOTE_PATTERN.lastIndex = 0;
282
- while ((match = DOUBLE_QUOTE_PATTERN.exec(content)) !== null) {
283
- if (match[1]) {
284
- classes.push(...extractUtilityClasses(match[1], pattern));
285
- }
286
- }
287
- TEMPLATE_LITERAL_PATTERN.lastIndex = 0;
288
- while ((match = TEMPLATE_LITERAL_PATTERN.exec(content)) !== null) {
289
- if (match[1]) {
290
- classes.push(...extractUtilityClasses(match[1], pattern));
291
- }
292
- }
293
- return classes;
294
- }
295
- function extractFromMDX(content, pattern) {
296
- const classes = [];
297
- classes.push(...extractFromHTML(content, pattern));
298
- classes.push(...extractFromJSX(content, pattern));
299
- return [...new Set(classes)];
300
- }
301
- const defaultExtractors = {
302
- html: extractFromHTML,
303
- htm: extractFromHTML,
304
- vue: extractFromVue,
305
- svelte: extractFromSvelte,
306
- jsx: extractFromJSX,
307
- tsx: extractFromJSX,
308
- js: extractFromStringLiterals,
309
- ts: extractFromStringLiterals,
310
- astro: extractFromAstro,
311
- mdx: extractFromMDX,
312
- php: extractFromHTML,
313
- erb: extractFromHTML,
314
- twig: extractFromHTML,
315
- "blade.php": extractFromHTML
87
+ function K(s) {
88
+ const e = [];
89
+ let t = "", n = 0;
90
+ for (const r of s)
91
+ r === "[" ? (n++, t += r) : r === "]" ? (n--, t += r) : r === ":" && n === 0 ? (t && e.push(t), t = "") : t += r;
92
+ return n !== 0 ? [] : (t && e.push(t), e);
93
+ }
94
+ function A(s, e) {
95
+ const t = s.match(e ?? X);
96
+ return t ? [...new Set(t)] : [];
97
+ }
98
+ function pe(s, e, t = []) {
99
+ const n = [...t, s];
100
+ return e !== "default" && n.push(e), `_${n.join(":")}`;
101
+ }
102
+ const R = /\bclassName\s*=\s*\{/g, _ = /\bclass\s*=\s*\{/g, I = /\bclass\s*=\s*["']([^"']+)["']/gi, b = /\bclassName\s*=\s*["']([^"']+)["']/gi, M = /\bclass:([^\s={>]+)/g, L = /'([^'\\]*(?:\\.[^'\\]*)*)'/g, F = /"([^"\\]*(?:\\.[^"\\]*)*)"/g, v = /`([^`\\]*(?:\\.[^`\\]*)*)`/g;
103
+ function P(s) {
104
+ let e = 1, t = 0;
105
+ for (; t < s.length && e > 0; ) {
106
+ const n = s[t];
107
+ n === "{" ? e++ : n === "}" && e--, t++;
108
+ }
109
+ return e !== 0 ? null : s.slice(0, t - 1);
110
+ }
111
+ function Z(s) {
112
+ const e = [];
113
+ R.lastIndex = 0;
114
+ let t;
115
+ for (; (t = R.exec(s)) !== null; ) {
116
+ const n = t.index + t[0].length, r = s.slice(n), c = P(r);
117
+ c !== null && e.push(c);
118
+ }
119
+ return e;
120
+ }
121
+ function W(s) {
122
+ const e = [];
123
+ _.lastIndex = 0;
124
+ let t;
125
+ for (; (t = _.exec(s)) !== null; ) {
126
+ const n = t.index + t[0].length, r = s.slice(n), c = P(r);
127
+ c !== null && e.push(c);
128
+ }
129
+ return e;
130
+ }
131
+ function h(s, e) {
132
+ const t = [];
133
+ I.lastIndex = 0;
134
+ let n;
135
+ for (; (n = I.exec(s)) !== null; )
136
+ n[1] && t.push(...A(n[1], e));
137
+ return t;
138
+ }
139
+ function y(s, e) {
140
+ const t = [];
141
+ b.lastIndex = 0;
142
+ let n;
143
+ for (; (n = b.exec(s)) !== null; )
144
+ n[1] && t.push(...A(n[1], e));
145
+ const r = Z(s);
146
+ for (const c of r)
147
+ t.push(...m(c, e));
148
+ return [...new Set(t)];
149
+ }
150
+ function Y(s, e) {
151
+ const t = [], n = s.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
152
+ n?.[1] && (t.push(...h(n[1], e)), t.push(...m(n[1], e)));
153
+ const r = s.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
154
+ return r?.[1] && t.push(...m(r[1], e)), [...new Set(t)];
155
+ }
156
+ function q(s, e) {
157
+ const t = [];
158
+ t.push(...h(s, e));
159
+ const n = W(s);
160
+ for (const a of n)
161
+ t.push(...m(a, e));
162
+ M.lastIndex = 0;
163
+ let r;
164
+ for (; (r = M.exec(s)) !== null; )
165
+ r[1] && t.push(r[1]);
166
+ const c = s.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
167
+ return c?.[1] && t.push(...m(c[1], e)), [...new Set(t)];
168
+ }
169
+ function J(s, e) {
170
+ const t = [];
171
+ t.push(...h(s, e)), t.push(...y(s, e));
172
+ const n = s.match(/^---\n([\s\S]*?)\n---/);
173
+ return n?.[1] && t.push(...m(n[1], e)), [...new Set(t)];
174
+ }
175
+ function m(s, e) {
176
+ const t = [];
177
+ let n;
178
+ for (L.lastIndex = 0; (n = L.exec(s)) !== null; )
179
+ n[1] && t.push(...A(n[1], e));
180
+ for (F.lastIndex = 0; (n = F.exec(s)) !== null; )
181
+ n[1] && t.push(...A(n[1], e));
182
+ for (v.lastIndex = 0; (n = v.exec(s)) !== null; )
183
+ n[1] && t.push(...A(n[1], e));
184
+ return t;
185
+ }
186
+ function ee(s, e) {
187
+ const t = [];
188
+ return t.push(...h(s, e)), t.push(...y(s, e)), [...new Set(t)];
189
+ }
190
+ const te = {
191
+ html: h,
192
+ htm: h,
193
+ vue: Y,
194
+ svelte: q,
195
+ jsx: y,
196
+ tsx: y,
197
+ js: m,
198
+ ts: m,
199
+ astro: J,
200
+ mdx: ee,
201
+ php: h,
202
+ erb: h,
203
+ twig: h,
204
+ "blade.php": h
316
205
  };
317
- function getExtension(filePath) {
318
- if (filePath.endsWith(".blade.php")) {
206
+ function se(s) {
207
+ if (s.endsWith(".blade.php"))
319
208
  return "blade.php";
320
- }
321
- const parts = filePath.split(".");
322
- return parts[parts.length - 1]?.toLowerCase() ?? "";
323
- }
324
- function extractClasses(content, filePath, customExtractors, utilityPattern) {
325
- const classes = [];
326
- const extension = getExtension(filePath);
327
- if (customExtractors) {
328
- for (const extractor of customExtractors) {
329
- classes.push(...extractor(content, filePath));
330
- }
331
- }
332
- const defaultExtractor = defaultExtractors[extension];
333
- if (defaultExtractor) {
334
- classes.push(...defaultExtractor(content, utilityPattern));
335
- } else {
336
- classes.push(...extractFromStringLiterals(content, utilityPattern));
337
- }
338
- return [...new Set(classes)];
339
- }
340
- const Be = ({
341
- name: e,
342
- value: t,
343
- modifiers: r
344
- }) => `_${[
345
- ...r,
346
- e,
347
- ...t === "default" ? [] : [t]
348
- ].filter(Boolean).join(":")}`;
349
- function Ke(e) {
350
- return `.${e.replace(/[[\].#()%,:/]/g, "\\$&")}`;
351
- }
352
- function v(e) {
353
- if (e instanceof Buffer)
354
- return Buffer.from(e);
355
- const t = e.constructor;
356
- return new t(
357
- e.buffer.slice(0),
358
- e.byteOffset,
359
- e.byteLength / e.BYTES_PER_ELEMENT || 1
360
- );
361
- }
362
- function ue(e) {
363
- if (e = e || {}, e.circular)
364
- return le(e);
365
- const t = /* @__PURE__ */ new Map();
366
- if (t.set(Date, (i) => new Date(i)), t.set(
367
- Map,
368
- (i, f) => new Map(n(Array.from(i), f))
369
- ), t.set(
370
- Set,
371
- (i, f) => new Set(n(Array.from(i), f))
372
- ), e.constructorHandlers)
373
- for (const i of e.constructorHandlers)
374
- t.set(i[0], i[1]);
375
- let r;
376
- return e.proto ? o : s;
377
- function n(i, f) {
378
- const c = Object.keys(i), a = Array.from({ length: c.length });
379
- for (let l = 0; l < c.length; l++) {
380
- const u = c[l], d = i[u];
381
- typeof d != "object" || d === null ? a[u] = d : d.constructor !== Object && (r = t.get(d.constructor)) ? a[u] = r(d, f) : ArrayBuffer.isView(d) ? a[u] = v(d) : a[u] = f(d);
209
+ const e = s.split(".");
210
+ return e[e.length - 1]?.toLowerCase() ?? "";
211
+ }
212
+ function N(s, e, t, n) {
213
+ const r = [], c = se(e);
214
+ if (t)
215
+ for (const l of t)
216
+ r.push(...l(s, e));
217
+ const a = te[c];
218
+ return a ? r.push(...a(s, n)) : r.push(...m(s, n)), [...new Set(r)];
219
+ }
220
+ function U(s, e) {
221
+ if (e.length === 0)
222
+ return s;
223
+ const t = [...e].sort().join(",");
224
+ return `${s}|${t}`;
225
+ }
226
+ function ne(s, e) {
227
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
228
+ for (const a of e.utilities) {
229
+ t.set(a.name, a);
230
+ const l = /* @__PURE__ */ new Set();
231
+ for (const u of a.values)
232
+ l.add(U(u.key, u.modifiers));
233
+ r.set(a, l);
234
+ }
235
+ for (const a of e.modifiers)
236
+ for (const l of a.key)
237
+ n.set(l, a);
238
+ const c = [];
239
+ for (const a of s) {
240
+ const l = t.get(a.name) ?? null, u = [];
241
+ for (const T of a.modifiers) {
242
+ const w = n.get(T);
243
+ w && u.push(w);
382
244
  }
383
- return a;
384
- }
385
- function s(i) {
386
- if (typeof i != "object" || i === null) return i;
387
- if (Array.isArray(i)) return n(i, s);
388
- if (i.constructor !== Object && (r = t.get(i.constructor)))
389
- return r(i, s);
390
- const f = {};
391
- for (const c in i) {
392
- if (Object.hasOwnProperty.call(i, c) === false) continue;
393
- const a = i[c];
394
- typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, s) : ArrayBuffer.isView(a) ? f[c] = v(a) : f[c] = s(a);
395
- }
396
- return f;
397
- }
398
- function o(i) {
399
- if (typeof i != "object" || i === null) return i;
400
- if (Array.isArray(i)) return n(i, o);
401
- if (i.constructor !== Object && (r = t.get(i.constructor)))
402
- return r(i, o);
403
- const f = {};
404
- for (const c in i) {
405
- const a = i[c];
406
- typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, o) : ArrayBuffer.isView(a) ? f[c] = v(a) : f[c] = o(a);
407
- }
408
- return f;
409
- }
410
- }
411
- function le(e) {
412
- const t = [], r = [], n = /* @__PURE__ */ new Map();
413
- if (n.set(Date, (c) => new Date(c)), n.set(
414
- Map,
415
- (c, a) => new Map(o(Array.from(c), a))
416
- ), n.set(
417
- Set,
418
- (c, a) => new Set(o(Array.from(c), a))
419
- ), e.constructorHandlers)
420
- for (const c of e.constructorHandlers)
421
- n.set(c[0], c[1]);
422
- let s;
423
- return e.proto ? f : i;
424
- function o(c, a) {
425
- const l = Object.keys(c), u = Array.from({ length: l.length });
426
- for (let d = 0; d < l.length; d++) {
427
- const y = l[d], m = c[y];
428
- if (typeof m != "object" || m === null)
429
- u[y] = m;
430
- else if (m.constructor !== Object && (s = n.get(m.constructor)))
431
- u[y] = s(m, a);
432
- else if (ArrayBuffer.isView(m))
433
- u[y] = v(m);
434
- else {
435
- const p = t.indexOf(m);
436
- p !== -1 ? u[y] = r[p] : u[y] = a(m);
437
- }
438
- }
439
- return u;
440
- }
441
- function i(c) {
442
- if (typeof c != "object" || c === null) return c;
443
- if (Array.isArray(c)) return o(c, i);
444
- if (c.constructor !== Object && (s = n.get(c.constructor)))
445
- return s(c, i);
446
- const a = {};
447
- t.push(c), r.push(a);
448
- for (const l in c) {
449
- if (Object.hasOwnProperty.call(c, l) === false) continue;
450
- const u = c[l];
451
- if (typeof u != "object" || u === null)
452
- a[l] = u;
453
- else if (u.constructor !== Object && (s = n.get(u.constructor)))
454
- a[l] = s(u, i);
455
- else if (ArrayBuffer.isView(u))
456
- a[l] = v(u);
457
- else {
458
- const d = t.indexOf(u);
459
- d !== -1 ? a[l] = r[d] : a[l] = i(u);
460
- }
461
- }
462
- return t.pop(), r.pop(), a;
463
- }
464
- function f(c) {
465
- if (typeof c != "object" || c === null) return c;
466
- if (Array.isArray(c)) return o(c, f);
467
- if (c.constructor !== Object && (s = n.get(c.constructor)))
468
- return s(c, f);
469
- const a = {};
470
- t.push(c), r.push(a);
471
- for (const l in c) {
472
- const u = c[l];
473
- if (typeof u != "object" || u === null)
474
- a[l] = u;
475
- else if (u.constructor !== Object && (s = n.get(u.constructor)))
476
- a[l] = s(u, f);
477
- else if (ArrayBuffer.isView(u))
478
- a[l] = v(u);
479
- else {
480
- const d = t.indexOf(u);
481
- d !== -1 ? a[l] = r[d] : a[l] = f(u);
482
- }
483
- }
484
- return t.pop(), r.pop(), a;
485
- }
486
- }
487
- ue();
488
- function generateValueKey(value, modifiers) {
489
- if (modifiers.length === 0) {
490
- return value;
491
- }
492
- const sortedModifiers = [...modifiers].sort().join(",");
493
- return `${value}|${sortedModifiers}`;
494
- }
495
- function matchUtilities(parsed, root) {
496
- const utilityMap = /* @__PURE__ */ new Map();
497
- const modifierMap = /* @__PURE__ */ new Map();
498
- const factoryValueSets = /* @__PURE__ */ new Map();
499
- for (const utility of root.utilities) {
500
- utilityMap.set(utility.name, utility);
501
- const valueSet = /* @__PURE__ */ new Set();
502
- for (const v2 of utility.values) {
503
- valueSet.add(generateValueKey(v2.key, v2.modifiers));
504
- }
505
- factoryValueSets.set(utility, valueSet);
506
- }
507
- for (const modifier of root.modifiers) {
508
- for (const key of modifier.key) {
509
- modifierMap.set(key, modifier);
510
- }
511
- }
512
- const matches = [];
513
- for (const parsedClass of parsed) {
514
- const factory = utilityMap.get(parsedClass.name) ?? null;
515
- const matchedModifiers = [];
516
- for (const modKey of parsedClass.modifiers) {
517
- const modifier = modifierMap.get(modKey);
518
- if (modifier) {
519
- matchedModifiers.push(modifier);
520
- }
521
- }
522
- let exists = false;
523
- if (factory) {
524
- const lookupKey = generateValueKey(
525
- parsedClass.value,
526
- parsedClass.modifiers
245
+ let S = !1;
246
+ if (l) {
247
+ const T = U(
248
+ a.value,
249
+ a.modifiers
527
250
  );
528
- const valueSet = factoryValueSets.get(factory);
529
- exists = valueSet?.has(lookupKey) ?? false;
251
+ S = r.get(l)?.has(T) ?? !1;
530
252
  }
531
- matches.push({
532
- parsed: parsedClass,
533
- factory,
534
- modifierFactories: matchedModifiers,
535
- exists
253
+ c.push({
254
+ parsed: a,
255
+ factory: l,
256
+ modifierFactories: u,
257
+ exists: S
536
258
  });
537
259
  }
538
- return matches;
260
+ return c;
539
261
  }
540
- function generateUtilitySelector(options, selectorFn) {
541
- const className = classNameFromUtilityOptions(options, selectorFn);
542
- return Ke(className);
262
+ function me(s, e) {
263
+ const t = V(s, e);
264
+ return z(t);
543
265
  }
544
- function classNameFromUtilityOptions(options, selectorFn) {
545
- return (selectorFn ?? Be)(options);
266
+ function V(s, e) {
267
+ return (e ?? k)(s);
546
268
  }
547
- function createUtilityFilter(usedClasses, selectorFn) {
548
- return (utility) => {
549
- const className = classNameFromUtilityOptions(
269
+ function re(s, e) {
270
+ return (t) => {
271
+ const n = V(
550
272
  {
551
- name: utility.name,
552
- value: utility.value,
553
- modifiers: utility.modifiers
273
+ name: t.name,
274
+ value: t.value,
275
+ modifiers: t.modifiers
554
276
  },
555
- selectorFn
277
+ e
556
278
  );
557
- return usedClasses.has(className);
279
+ return s.has(n);
558
280
  };
559
281
  }
560
- function filterUtilities(root, usedClasses, selectorFn) {
561
- const filter = createUtilityFilter(usedClasses, selectorFn);
562
- return root.children.filter((child) => {
563
- if (child.type !== "utility") {
564
- return true;
565
- }
566
- return filter(child);
567
- });
282
+ function de(s, e, t) {
283
+ const n = re(e, t);
284
+ return s.children.filter((r) => r.type !== "utility" ? !0 : n(r));
568
285
  }
569
- function getUsedClassNames(matches) {
570
- const classNames = /* @__PURE__ */ new Set();
571
- for (const match of matches) {
572
- classNames.add(match.parsed.raw);
573
- }
574
- return classNames;
286
+ function ge(s) {
287
+ const e = /* @__PURE__ */ new Set();
288
+ for (const t of s)
289
+ e.add(t.parsed.raw);
290
+ return e;
575
291
  }
576
- function getValidMatches(matches) {
577
- return matches.filter((m) => m.factory !== null);
292
+ function xe(s) {
293
+ return s.filter((e) => e.factory !== null);
578
294
  }
579
- function getExistingMatches(matches) {
580
- return matches.filter((m) => m.exists);
295
+ function Se(s) {
296
+ return s.filter((e) => e.exists);
581
297
  }
582
- function getArbitraryMatches(matches) {
583
- return matches.filter((m) => m.parsed.isArbitrary);
298
+ function Te(s) {
299
+ return s.filter((e) => e.parsed.isArbitrary);
584
300
  }
585
- const compiledPatternCache = /* @__PURE__ */ new Map();
586
- function getCompiledPattern(pattern) {
587
- const normalized = pattern.replace(/\\/g, "/");
588
- if (compiledPatternCache.has(normalized)) {
589
- return compiledPatternCache.get(normalized);
590
- }
591
- if (!normalized.includes("**") && !normalized.includes("*") && !normalized.includes("?")) {
592
- compiledPatternCache.set(normalized, null);
593
- return null;
594
- }
301
+ const E = /* @__PURE__ */ new Map();
302
+ function ce(s) {
303
+ const e = s.replace(/\\/g, "/");
304
+ if (E.has(e))
305
+ return E.get(e);
306
+ if (!e.includes("**") && !e.includes("*") && !e.includes("?"))
307
+ return E.set(e, null), null;
595
308
  try {
596
- const regexStr = globToRegex(normalized);
597
- const regex = new RegExp(`^${regexStr}$`);
598
- compiledPatternCache.set(normalized, regex);
599
- return regex;
309
+ const t = oe(e), n = new RegExp(`^${t}$`);
310
+ return E.set(e, n), n;
600
311
  } catch {
601
- compiledPatternCache.set(normalized, null);
602
- return null;
312
+ return E.set(e, null), null;
603
313
  }
604
314
  }
605
- function debounce(fn, delay) {
606
- let timeoutId = null;
607
- return (...args) => {
608
- if (timeoutId) {
609
- clearTimeout(timeoutId);
610
- }
611
- timeoutId = setTimeout(() => {
612
- fn(...args);
613
- timeoutId = null;
614
- }, delay);
315
+ function we(s, e) {
316
+ let t = null;
317
+ return (...n) => {
318
+ t && clearTimeout(t), t = setTimeout(() => {
319
+ s(...n), t = null;
320
+ }, e);
615
321
  };
616
322
  }
617
- function createChangeHandler(callback, options = {}) {
618
- const { debounce: debounceMs = 100 } = options;
619
- const changedFiles = /* @__PURE__ */ new Set();
620
- let timeoutId = null;
621
- const flush = () => {
622
- if (changedFiles.size > 0) {
623
- const files = [...changedFiles];
624
- changedFiles.clear();
625
- callback(files);
626
- }
627
- };
628
- const onChange = (filePath) => {
629
- changedFiles.add(filePath);
630
- if (timeoutId) {
631
- clearTimeout(timeoutId);
323
+ function ae(s, e = {}) {
324
+ const { debounce: t = 100 } = e, n = /* @__PURE__ */ new Set();
325
+ let r = null;
326
+ const c = () => {
327
+ if (n.size > 0) {
328
+ const l = [...n];
329
+ n.clear(), s(l);
632
330
  }
633
- timeoutId = setTimeout(() => {
634
- flush();
635
- timeoutId = null;
636
- }, debounceMs);
637
331
  };
638
- return { onChange, flush };
639
- }
640
- function escapeRegexChars(str) {
641
- return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
642
- }
643
- function globToRegex(pattern) {
644
- return pattern.replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "<<<STAR>>>").replace(/\?/g, "<<<QUESTION>>>").split("<<<GLOBSTAR>>>").map(escapeRegexChars).join(".*").replace(/<<<STAR>>>/g, "[^/]*").replace(/<<<QUESTION>>>/g, ".");
645
- }
646
- function matchesPatterns(filePath, patterns) {
647
- const normalizedPath = filePath.replace(/\\/g, "/");
648
- for (const pattern of patterns) {
649
- const compiledRegex = getCompiledPattern(pattern);
650
- if (compiledRegex !== null) {
651
- if (compiledRegex.test(normalizedPath)) {
652
- return true;
653
- }
332
+ return { onChange: (l) => {
333
+ n.add(l), r && clearTimeout(r), r = setTimeout(() => {
334
+ c(), r = null;
335
+ }, t);
336
+ }, flush: c };
337
+ }
338
+ function le(s) {
339
+ return s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
340
+ }
341
+ function oe(s) {
342
+ return s.replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "<<<STAR>>>").replace(/\?/g, "<<<QUESTION>>>").split("<<<GLOBSTAR>>>").map(le).join(".*").replace(/<<<STAR>>>/g, "[^/]*").replace(/<<<QUESTION>>>/g, ".");
343
+ }
344
+ function Ee(s, e) {
345
+ const t = s.replace(/\\/g, "/");
346
+ for (const n of e) {
347
+ const r = ce(n);
348
+ if (r !== null) {
349
+ if (r.test(t))
350
+ return !0;
654
351
  } else {
655
- const normalizedPattern = pattern.replace(/\\/g, "/");
656
- if (normalizedPath === normalizedPattern) {
657
- return true;
658
- }
352
+ const c = n.replace(/\\/g, "/");
353
+ if (t === c)
354
+ return !0;
659
355
  }
660
356
  }
661
- return false;
662
- }
663
- function createScanner(config) {
664
- const cache = createCache();
665
- const cwd = config.cwd ?? process.cwd();
666
- const customExtractors = config.extractors;
667
- const utilityPattern = config.utilities?.pattern;
668
- const utilityParse = config.utilities?.parse ?? parseUtilityClass;
669
- async function getFilePaths() {
670
- return fg(config.content, {
671
- cwd,
672
- absolute: true,
673
- ignore: DEFAULT_IGNORE_PATTERNS
357
+ return !1;
358
+ }
359
+ function Ae(s) {
360
+ const e = G(), t = s.cwd ?? process.cwd(), n = s.extractors, r = s.utilities?.pattern, c = s.utilities?.parse ?? C;
361
+ async function a() {
362
+ return j(s.content, {
363
+ cwd: t,
364
+ absolute: !0,
365
+ ignore: H
674
366
  });
675
367
  }
676
- async function scanFile(filePath) {
677
- const content = await readFile(filePath, "utf-8");
678
- const contentHash = hashContent(content);
679
- const cached = cache.getIfValid(filePath, contentHash);
680
- if (cached) {
681
- return cached;
682
- }
683
- const classNames = extractClasses(
684
- content,
685
- filePath,
686
- customExtractors,
687
- utilityPattern
688
- );
689
- const parsed = classNames.map(utilityParse).filter((p) => p !== null);
690
- const result = {
691
- path: filePath,
692
- classes: new Set(classNames),
693
- parsed,
368
+ async function l(o) {
369
+ const f = await D(o, "utf-8"), d = B(f), p = e.getIfValid(o, d);
370
+ if (p)
371
+ return p;
372
+ const g = N(
373
+ f,
374
+ o,
375
+ n,
376
+ r
377
+ ), i = g.map(c).filter((O) => O !== null), x = {
378
+ path: o,
379
+ classes: new Set(g),
380
+ parsed: i,
694
381
  lastScanned: Date.now()
695
382
  };
696
- cache.set(filePath, result, contentHash);
697
- return result;
698
- }
699
- function scanContent(content, filePath = "inline") {
700
- const classNames = extractClasses(
701
- content,
702
- filePath,
703
- customExtractors,
704
- utilityPattern
705
- );
706
- return classNames.map(utilityParse).filter((p) => p !== null);
707
- }
708
- async function scan() {
709
- const filePaths = await getFilePaths();
710
- const files = /* @__PURE__ */ new Map();
711
- const allClasses = /* @__PURE__ */ new Set();
712
- const allParsed = [];
713
- const results = await Promise.all(
714
- filePaths.map(async (filePath) => {
383
+ return e.set(o, x, d), x;
384
+ }
385
+ function u(o, f = "inline") {
386
+ return N(
387
+ o,
388
+ f,
389
+ n,
390
+ r
391
+ ).map(c).filter((p) => p !== null);
392
+ }
393
+ async function S() {
394
+ const o = await a(), f = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), p = [], g = await Promise.all(
395
+ o.map(async (i) => {
715
396
  try {
716
- return await scanFile(filePath);
717
- } catch (error) {
718
- console.warn(
719
- `[styleframe/scanner] Failed to scan ${filePath}:`,
720
- error
721
- );
722
- return null;
397
+ return await l(i);
398
+ } catch (x) {
399
+ return console.warn(
400
+ `[styleframe/scanner] Failed to scan ${i}:`,
401
+ x
402
+ ), null;
723
403
  }
724
404
  })
725
405
  );
726
- for (const result of results) {
727
- if (result) {
728
- files.set(result.path, result);
729
- for (const className of result.classes) {
730
- allClasses.add(className);
731
- }
732
- allParsed.push(...result.parsed);
406
+ for (const i of g)
407
+ if (i) {
408
+ f.set(i.path, i);
409
+ for (const x of i.classes)
410
+ d.add(x);
411
+ p.push(...i.parsed);
733
412
  }
734
- }
735
413
  return {
736
- files,
737
- allClasses,
738
- allParsed
414
+ files: f,
415
+ allClasses: d,
416
+ allParsed: p
739
417
  };
740
418
  }
741
- function match(parsed, root) {
742
- return matchUtilities(parsed, root);
419
+ function T(o, f) {
420
+ return ne(o, f);
743
421
  }
744
- function watch(callback) {
745
- const { onChange, flush } = createChangeHandler(async (changedFiles) => {
746
- for (const filePath of changedFiles) {
747
- cache.invalidate(filePath);
748
- }
749
- const result = await scan();
750
- callback(result);
422
+ function w(o) {
423
+ const { onChange: f, flush: d } = ae(async (p) => {
424
+ for (const i of p)
425
+ e.invalidate(i);
426
+ const g = await S();
427
+ o(g);
751
428
  });
752
429
  return () => {
753
- flush();
430
+ d();
754
431
  };
755
432
  }
756
- function invalidate(filePath) {
757
- if (filePath) {
758
- cache.invalidate(filePath);
759
- } else {
760
- cache.clear();
761
- }
433
+ function $(o) {
434
+ o ? e.invalidate(o) : e.clear();
762
435
  }
763
436
  return {
764
- scan,
765
- scanFile,
766
- scanContent,
767
- match,
768
- watch,
769
- invalidate
437
+ scan: S,
438
+ scanFile: l,
439
+ scanContent: u,
440
+ match: T,
441
+ watch: w,
442
+ invalidate: $
770
443
  };
771
444
  }
772
- function quickScan(content, filePath = "inline.html", utilities) {
773
- const parseFn = utilities?.parse ?? parseUtilityClass;
774
- const classNames = extractClasses(
775
- content,
776
- filePath,
445
+ function ye(s, e = "inline.html", t) {
446
+ const n = t?.parse ?? C;
447
+ return N(
448
+ s,
449
+ e,
777
450
  void 0,
778
- utilities?.pattern
779
- );
780
- return classNames.map(parseFn).filter((p) => p !== null);
781
- }
782
- function createContentScanner(customExtractors, utilities) {
783
- const parseFn = utilities?.parse ?? parseUtilityClass;
784
- return (content, filePath = "inline") => {
785
- const classNames = extractClasses(
786
- content,
787
- filePath,
788
- customExtractors,
789
- utilities?.pattern
790
- );
791
- return classNames.map(parseFn).filter((p) => p !== null);
792
- };
451
+ t?.pattern
452
+ ).map(n).filter((c) => c !== null);
453
+ }
454
+ function Ne(s, e) {
455
+ const t = e?.parse ?? C;
456
+ return (n, r = "inline") => N(
457
+ n,
458
+ r,
459
+ s,
460
+ e?.pattern
461
+ ).map(t).filter((a) => a !== null);
793
462
  }
794
463
  export {
795
- ARBITRARY_VALUE_PATTERN,
796
- DEFAULT_EXTENSIONS,
797
- DEFAULT_IGNORE_PATTERNS,
798
- UTILITY_CLASS_PATTERN,
799
- classNameFromUtilityOptions,
800
- createCache,
801
- createChangeHandler,
802
- createContentScanner,
803
- createScanner,
804
- createUtilityFilter,
805
- debounce,
806
- extractClasses,
807
- extractFromAstro,
808
- extractFromHTML,
809
- extractFromJSX,
810
- extractFromMDX,
811
- extractFromStringLiterals,
812
- extractFromSvelte,
813
- extractFromVue,
814
- extractUtilityClasses,
815
- filterUtilities,
816
- generateUtilityClassName,
817
- generateUtilitySelector,
818
- getArbitraryMatches,
819
- getExistingMatches,
820
- getUsedClassNames,
821
- getValidMatches,
822
- hashContent,
823
- matchUtilities,
824
- matchesPatterns,
825
- parseUtilityClass,
826
- quickScan
464
+ Q as ARBITRARY_VALUE_PATTERN,
465
+ he as DEFAULT_EXTENSIONS,
466
+ H as DEFAULT_IGNORE_PATTERNS,
467
+ X as UTILITY_CLASS_PATTERN,
468
+ V as classNameFromUtilityOptions,
469
+ G as createCache,
470
+ ae as createChangeHandler,
471
+ Ne as createContentScanner,
472
+ Ae as createScanner,
473
+ re as createUtilityFilter,
474
+ we as debounce,
475
+ N as extractClasses,
476
+ J as extractFromAstro,
477
+ h as extractFromHTML,
478
+ y as extractFromJSX,
479
+ ee as extractFromMDX,
480
+ m as extractFromStringLiterals,
481
+ q as extractFromSvelte,
482
+ Y as extractFromVue,
483
+ A as extractUtilityClasses,
484
+ de as filterUtilities,
485
+ pe as generateUtilityClassName,
486
+ me as generateUtilitySelector,
487
+ Te as getArbitraryMatches,
488
+ Se as getExistingMatches,
489
+ ge as getUsedClassNames,
490
+ xe as getValidMatches,
491
+ B as hashContent,
492
+ ne as matchUtilities,
493
+ Ee as matchesPatterns,
494
+ C as parseUtilityClass,
495
+ ye as quickScan
827
496
  };