@styleframe/scanner 3.0.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,595 +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) {
140
- const matches = content.match(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:(_[a-zA-Z][a-zA-Z0-9-:[\]._]*)/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) {
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]));
210
- }
211
- }
212
- return classes;
213
- }
214
- function extractFromJSX(content) {
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]));
221
- }
222
- }
223
- const expressions = extractClassNameExpressions(content);
224
- for (const expr of expressions) {
225
- classes.push(...extractFromStringLiterals(expr));
226
- }
227
- return [...new Set(classes)];
228
- }
229
- function extractFromVue(content) {
230
- const classes = [];
231
- const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
232
- if (templateMatch?.[1]) {
233
- classes.push(...extractFromHTML(templateMatch[1]));
234
- classes.push(...extractFromStringLiterals(templateMatch[1]));
235
- }
236
- const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
237
- if (scriptMatch?.[1]) {
238
- classes.push(...extractFromStringLiterals(scriptMatch[1]));
239
- }
240
- return [...new Set(classes)];
241
- }
242
- function extractFromSvelte(content) {
243
- const classes = [];
244
- classes.push(...extractFromHTML(content));
245
- const expressions = extractClassExpressions(content);
246
- for (const expr of expressions) {
247
- classes.push(...extractFromStringLiterals(expr));
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]));
259
- }
260
- return [...new Set(classes)];
261
- }
262
- function extractFromAstro(content) {
263
- const classes = [];
264
- classes.push(...extractFromHTML(content));
265
- classes.push(...extractFromJSX(content));
266
- const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
267
- if (frontmatterMatch?.[1]) {
268
- classes.push(...extractFromStringLiterals(frontmatterMatch[1]));
269
- }
270
- return [...new Set(classes)];
271
- }
272
- function extractFromStringLiterals(content) {
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]));
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]));
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]));
291
- }
292
- }
293
- return classes;
294
- }
295
- function extractFromMDX(content) {
296
- const classes = [];
297
- classes.push(...extractFromHTML(content));
298
- classes.push(...extractFromJSX(content));
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) {
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));
335
- } else {
336
- classes.push(...extractFromStringLiterals(content));
337
- }
338
- return [...new Set(classes)];
339
- }
340
- function generateValueKey(value, modifiers) {
341
- if (modifiers.length === 0) {
342
- return value;
343
- }
344
- const sortedModifiers = [...modifiers].sort().join(",");
345
- return `${value}|${sortedModifiers}`;
346
- }
347
- function matchUtilities(parsed, root) {
348
- const utilityMap = /* @__PURE__ */ new Map();
349
- const modifierMap = /* @__PURE__ */ new Map();
350
- const factoryValueSets = /* @__PURE__ */ new Map();
351
- for (const utility of root.utilities) {
352
- utilityMap.set(utility.name, utility);
353
- const valueSet = /* @__PURE__ */ new Set();
354
- for (const v of utility.values) {
355
- valueSet.add(generateValueKey(v.key, v.modifiers));
356
- }
357
- factoryValueSets.set(utility, valueSet);
358
- }
359
- for (const modifier of root.modifiers) {
360
- for (const key of modifier.key) {
361
- modifierMap.set(key, modifier);
362
- }
363
- }
364
- const matches = [];
365
- for (const parsedClass of parsed) {
366
- const factory = utilityMap.get(parsedClass.name) ?? null;
367
- const matchedModifiers = [];
368
- for (const modKey of parsedClass.modifiers) {
369
- const modifier = modifierMap.get(modKey);
370
- if (modifier) {
371
- matchedModifiers.push(modifier);
372
- }
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);
373
244
  }
374
- let exists = false;
375
- if (factory) {
376
- const lookupKey = generateValueKey(
377
- parsedClass.value,
378
- parsedClass.modifiers
245
+ let S = !1;
246
+ if (l) {
247
+ const T = U(
248
+ a.value,
249
+ a.modifiers
379
250
  );
380
- const valueSet = factoryValueSets.get(factory);
381
- exists = valueSet?.has(lookupKey) ?? false;
251
+ S = r.get(l)?.has(T) ?? !1;
382
252
  }
383
- matches.push({
384
- parsed: parsedClass,
385
- factory,
386
- modifierFactories: matchedModifiers,
387
- exists
253
+ c.push({
254
+ parsed: a,
255
+ factory: l,
256
+ modifierFactories: u,
257
+ exists: S
388
258
  });
389
259
  }
390
- return matches;
391
- }
392
- function generateUtilitySelector(options) {
393
- const { name, value, modifiers } = options;
394
- const parts = [
395
- ...modifiers,
396
- name,
397
- ...value === "default" ? [] : [value]
398
- ].filter(Boolean);
399
- return `._${parts.join("\\:").replace(/[[\].#()%,]/g, "\\$&")}`;
400
- }
401
- function classNameFromUtilityOptions(options) {
402
- const { name, value, modifiers } = options;
403
- const parts = [
404
- ...modifiers,
405
- name,
406
- ...value === "default" ? [] : [value]
407
- ].filter(Boolean);
408
- return `_${parts.join(":")}`;
409
- }
410
- function createUtilityFilter(usedClasses) {
411
- return (utility) => {
412
- const className = classNameFromUtilityOptions({
413
- name: utility.name,
414
- value: utility.value,
415
- modifiers: utility.modifiers
416
- });
417
- return usedClasses.has(className);
260
+ return c;
261
+ }
262
+ function me(s, e) {
263
+ const t = V(s, e);
264
+ return z(t);
265
+ }
266
+ function V(s, e) {
267
+ return (e ?? k)(s);
268
+ }
269
+ function re(s, e) {
270
+ return (t) => {
271
+ const n = V(
272
+ {
273
+ name: t.name,
274
+ value: t.value,
275
+ modifiers: t.modifiers
276
+ },
277
+ e
278
+ );
279
+ return s.has(n);
418
280
  };
419
281
  }
420
- function filterUtilities(root, usedClasses) {
421
- const filter = createUtilityFilter(usedClasses);
422
- return root.children.filter((child) => {
423
- if (child.type !== "utility") {
424
- return true;
425
- }
426
- return filter(child);
427
- });
282
+ function de(s, e, t) {
283
+ const n = re(e, t);
284
+ return s.children.filter((r) => r.type !== "utility" ? !0 : n(r));
428
285
  }
429
- function getUsedClassNames(matches) {
430
- const classNames = /* @__PURE__ */ new Set();
431
- for (const match of matches) {
432
- classNames.add(match.parsed.raw);
433
- }
434
- 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;
435
291
  }
436
- function getValidMatches(matches) {
437
- return matches.filter((m) => m.factory !== null);
292
+ function xe(s) {
293
+ return s.filter((e) => e.factory !== null);
438
294
  }
439
- function getExistingMatches(matches) {
440
- return matches.filter((m) => m.exists);
295
+ function Se(s) {
296
+ return s.filter((e) => e.exists);
441
297
  }
442
- function getArbitraryMatches(matches) {
443
- return matches.filter((m) => m.parsed.isArbitrary);
298
+ function Te(s) {
299
+ return s.filter((e) => e.parsed.isArbitrary);
444
300
  }
445
- const compiledPatternCache = /* @__PURE__ */ new Map();
446
- function getCompiledPattern(pattern) {
447
- const normalized = pattern.replace(/\\/g, "/");
448
- if (compiledPatternCache.has(normalized)) {
449
- return compiledPatternCache.get(normalized);
450
- }
451
- if (!normalized.includes("**") && !normalized.includes("*") && !normalized.includes("?")) {
452
- compiledPatternCache.set(normalized, null);
453
- return null;
454
- }
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;
455
308
  try {
456
- const regexStr = globToRegex(normalized);
457
- const regex = new RegExp(`^${regexStr}$`);
458
- compiledPatternCache.set(normalized, regex);
459
- return regex;
309
+ const t = oe(e), n = new RegExp(`^${t}$`);
310
+ return E.set(e, n), n;
460
311
  } catch {
461
- compiledPatternCache.set(normalized, null);
462
- return null;
312
+ return E.set(e, null), null;
463
313
  }
464
314
  }
465
- function debounce(fn, delay) {
466
- let timeoutId = null;
467
- return (...args) => {
468
- if (timeoutId) {
469
- clearTimeout(timeoutId);
470
- }
471
- timeoutId = setTimeout(() => {
472
- fn(...args);
473
- timeoutId = null;
474
- }, 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);
475
321
  };
476
322
  }
477
- function createChangeHandler(callback, options = {}) {
478
- const { debounce: debounceMs = 100 } = options;
479
- const changedFiles = /* @__PURE__ */ new Set();
480
- let timeoutId = null;
481
- const flush = () => {
482
- if (changedFiles.size > 0) {
483
- const files = [...changedFiles];
484
- changedFiles.clear();
485
- callback(files);
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);
486
330
  }
487
331
  };
488
- const onChange = (filePath) => {
489
- changedFiles.add(filePath);
490
- if (timeoutId) {
491
- clearTimeout(timeoutId);
492
- }
493
- timeoutId = setTimeout(() => {
494
- flush();
495
- timeoutId = null;
496
- }, debounceMs);
497
- };
498
- return { onChange, flush };
499
- }
500
- function escapeRegexChars(str) {
501
- return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
502
- }
503
- function globToRegex(pattern) {
504
- return pattern.replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "<<<STAR>>>").replace(/\?/g, "<<<QUESTION>>>").split("<<<GLOBSTAR>>>").map(escapeRegexChars).join(".*").replace(/<<<STAR>>>/g, "[^/]*").replace(/<<<QUESTION>>>/g, ".");
505
- }
506
- function matchesPatterns(filePath, patterns) {
507
- const normalizedPath = filePath.replace(/\\/g, "/");
508
- for (const pattern of patterns) {
509
- const compiledRegex = getCompiledPattern(pattern);
510
- if (compiledRegex !== null) {
511
- if (compiledRegex.test(normalizedPath)) {
512
- return true;
513
- }
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;
514
351
  } else {
515
- const normalizedPattern = pattern.replace(/\\/g, "/");
516
- if (normalizedPath === normalizedPattern) {
517
- return true;
518
- }
352
+ const c = n.replace(/\\/g, "/");
353
+ if (t === c)
354
+ return !0;
519
355
  }
520
356
  }
521
- return false;
522
- }
523
- function createScanner(config) {
524
- const cache = createCache();
525
- const cwd = config.cwd ?? process.cwd();
526
- const customExtractors = config.extractors;
527
- async function getFilePaths() {
528
- return fg(config.content, {
529
- cwd,
530
- absolute: true,
531
- 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
532
366
  });
533
367
  }
534
- async function scanFile(filePath) {
535
- const content = await readFile(filePath, "utf-8");
536
- const contentHash = hashContent(content);
537
- const cached = cache.getIfValid(filePath, contentHash);
538
- if (cached) {
539
- return cached;
540
- }
541
- const classNames = extractClasses(content, filePath, customExtractors);
542
- const parsed = classNames.map(parseUtilityClass).filter((p) => p !== null);
543
- const result = {
544
- path: filePath,
545
- classes: new Set(classNames),
546
- 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,
547
381
  lastScanned: Date.now()
548
382
  };
549
- cache.set(filePath, result, contentHash);
550
- return result;
551
- }
552
- function scanContent(content, filePath = "inline") {
553
- const classNames = extractClasses(content, filePath, customExtractors);
554
- return classNames.map(parseUtilityClass).filter((p) => p !== null);
555
- }
556
- async function scan() {
557
- const filePaths = await getFilePaths();
558
- const files = /* @__PURE__ */ new Map();
559
- const allClasses = /* @__PURE__ */ new Set();
560
- const allParsed = [];
561
- const results = await Promise.all(
562
- 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) => {
563
396
  try {
564
- return await scanFile(filePath);
565
- } catch (error) {
566
- console.warn(
567
- `[styleframe/scanner] Failed to scan ${filePath}:`,
568
- error
569
- );
570
- 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;
571
403
  }
572
404
  })
573
405
  );
574
- for (const result of results) {
575
- if (result) {
576
- files.set(result.path, result);
577
- for (const className of result.classes) {
578
- allClasses.add(className);
579
- }
580
- 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);
581
412
  }
582
- }
583
413
  return {
584
- files,
585
- allClasses,
586
- allParsed
414
+ files: f,
415
+ allClasses: d,
416
+ allParsed: p
587
417
  };
588
418
  }
589
- function match(parsed, root) {
590
- return matchUtilities(parsed, root);
419
+ function T(o, f) {
420
+ return ne(o, f);
591
421
  }
592
- function watch(callback) {
593
- const { onChange, flush } = createChangeHandler(async (changedFiles) => {
594
- for (const filePath of changedFiles) {
595
- cache.invalidate(filePath);
596
- }
597
- const result = await scan();
598
- 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);
599
428
  });
600
429
  return () => {
601
- flush();
430
+ d();
602
431
  };
603
432
  }
604
- function invalidate(filePath) {
605
- if (filePath) {
606
- cache.invalidate(filePath);
607
- } else {
608
- cache.clear();
609
- }
433
+ function $(o) {
434
+ o ? e.invalidate(o) : e.clear();
610
435
  }
611
436
  return {
612
- scan,
613
- scanFile,
614
- scanContent,
615
- match,
616
- watch,
617
- invalidate
437
+ scan: S,
438
+ scanFile: l,
439
+ scanContent: u,
440
+ match: T,
441
+ watch: w,
442
+ invalidate: $
618
443
  };
619
444
  }
620
- function quickScan(content, filePath = "inline.html") {
621
- const classNames = extractClasses(content, filePath);
622
- return classNames.map(parseUtilityClass).filter((p) => p !== null);
623
- }
624
- function createContentScanner(customExtractors) {
625
- return (content, filePath = "inline") => {
626
- const classNames = extractClasses(content, filePath, customExtractors);
627
- return classNames.map(parseUtilityClass).filter((p) => p !== null);
628
- };
445
+ function ye(s, e = "inline.html", t) {
446
+ const n = t?.parse ?? C;
447
+ return N(
448
+ s,
449
+ e,
450
+ void 0,
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);
629
462
  }
630
463
  export {
631
- ARBITRARY_VALUE_PATTERN,
632
- DEFAULT_EXTENSIONS,
633
- DEFAULT_IGNORE_PATTERNS,
634
- UTILITY_CLASS_PATTERN,
635
- classNameFromUtilityOptions,
636
- createCache,
637
- createChangeHandler,
638
- createContentScanner,
639
- createScanner,
640
- createUtilityFilter,
641
- debounce,
642
- extractClasses,
643
- extractFromAstro,
644
- extractFromHTML,
645
- extractFromJSX,
646
- extractFromMDX,
647
- extractFromStringLiterals,
648
- extractFromSvelte,
649
- extractFromVue,
650
- extractUtilityClasses,
651
- filterUtilities,
652
- generateUtilityClassName,
653
- generateUtilitySelector,
654
- getArbitraryMatches,
655
- getExistingMatches,
656
- getUsedClassNames,
657
- getValidMatches,
658
- hashContent,
659
- matchUtilities,
660
- matchesPatterns,
661
- parseUtilityClass,
662
- 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
663
496
  };