@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.d.ts CHANGED
@@ -2,6 +2,8 @@ import { ModifierFactory } from '@styleframe/core';
2
2
  import { Root } from '@styleframe/core';
3
3
  import { Utility } from '@styleframe/core';
4
4
  import { UtilityFactory } from '@styleframe/core';
5
+ import { UtilitySelectorFn } from '@styleframe/core';
6
+ import { UtilitySelectorOptions } from '@styleframe/core';
5
7
 
6
8
  /**
7
9
  * Pattern to extract the value from an arbitrary value bracket notation.
@@ -24,7 +26,7 @@ export declare interface CacheEntry {
24
26
  /**
25
27
  * Generate the raw utility class name from options (without CSS escaping).
26
28
  */
27
- export declare function classNameFromUtilityOptions(options: UtilitySelectorOptions): string;
29
+ export declare function classNameFromUtilityOptions(options: UtilitySelectorOptions, selectorFn?: UtilitySelectorFn): string;
28
30
 
29
31
  /**
30
32
  * Create a scanner cache instance.
@@ -55,7 +57,7 @@ export declare function createChangeHandler(callback: (changedFiles: string[]) =
55
57
  *
56
58
  * Useful for testing or one-off scans.
57
59
  */
58
- export declare function createContentScanner(customExtractors?: Extractor[]): (content: string, filePath?: string) => ParsedUtility[];
60
+ export declare function createContentScanner(customExtractors?: Extractor[], utilities?: ScannerUtilitiesConfig): (content: string, filePath?: string) => ParsedUtility[];
59
61
 
60
62
  /**
61
63
  * Create a scanner instance for detecting utility classes in content files.
@@ -79,9 +81,10 @@ export declare function createScanner(config: ScannerConfig): Scanner;
79
81
  * Create a filter function that checks if a utility is in the used set.
80
82
  *
81
83
  * @param usedClasses Set of used utility class names
84
+ * @param selectorFn Optional custom selector function
82
85
  * @returns Filter function for utilities
83
86
  */
84
- export declare function createUtilityFilter(usedClasses: Set<string>): (utility: Utility) => boolean;
87
+ export declare function createUtilityFilter(usedClasses: Set<string>, selectorFn?: UtilitySelectorFn): (utility: Utility) => boolean;
85
88
 
86
89
  /**
87
90
  * Simple debounce utility
@@ -104,33 +107,34 @@ export declare const DEFAULT_IGNORE_PATTERNS: string[];
104
107
  * @param content The file content
105
108
  * @param filePath The file path (used to determine extractor)
106
109
  * @param customExtractors Optional custom extractors to use in addition to defaults
110
+ * @param utilityPattern Optional custom regex pattern for utility class extraction
107
111
  * @returns Array of unique utility class names found
108
112
  */
109
- export declare function extractClasses(content: string, filePath: string, customExtractors?: Extractor[]): string[];
113
+ export declare function extractClasses(content: string, filePath: string, customExtractors?: Extractor[], utilityPattern?: RegExp): string[];
110
114
 
111
115
  /**
112
116
  * Extract utility classes from Astro content.
113
117
  * Handles both HTML-like and JSX-like patterns.
114
118
  */
115
- export declare function extractFromAstro(content: string): string[];
119
+ export declare function extractFromAstro(content: string, pattern?: RegExp): string[];
116
120
 
117
121
  /**
118
122
  * Extract utility classes from HTML-like content.
119
123
  * Handles class="..." attributes.
120
124
  */
121
- export declare function extractFromHTML(content: string): string[];
125
+ export declare function extractFromHTML(content: string, pattern?: RegExp): string[];
122
126
 
123
127
  /**
124
128
  * Extract utility classes from JSX/TSX content.
125
129
  * Handles className="..." and className={...} patterns.
126
130
  */
127
- export declare function extractFromJSX(content: string): string[];
131
+ export declare function extractFromJSX(content: string, pattern?: RegExp): string[];
128
132
 
129
133
  /**
130
134
  * Extract utility classes from MDX content.
131
135
  * Handles both Markdown and JSX patterns.
132
136
  */
133
- export declare function extractFromMDX(content: string): string[];
137
+ export declare function extractFromMDX(content: string, pattern?: RegExp): string[];
134
138
 
135
139
  /**
136
140
  * Extract utility classes from string literals in JavaScript/TypeScript code.
@@ -140,19 +144,19 @@ export declare function extractFromMDX(content: string): string[];
140
144
  * extract the static portions. Dynamic class names cannot be statically analyzed.
141
145
  * For full coverage, use explicit string arrays or safelist patterns.
142
146
  */
143
- export declare function extractFromStringLiterals(content: string): string[];
147
+ export declare function extractFromStringLiterals(content: string, pattern?: RegExp): string[];
144
148
 
145
149
  /**
146
150
  * Extract utility classes from Svelte content.
147
151
  * Handles class="...", class:directive={condition}, and class={...} patterns.
148
152
  */
149
- export declare function extractFromSvelte(content: string): string[];
153
+ export declare function extractFromSvelte(content: string, pattern?: RegExp): string[];
150
154
 
151
155
  /**
152
156
  * Extract utility classes from Vue SFC content.
153
157
  * Handles class="...", :class="...", and :class="{...}" patterns.
154
158
  */
155
- export declare function extractFromVue(content: string): string[];
159
+ export declare function extractFromVue(content: string, pattern?: RegExp): string[];
156
160
 
157
161
  /**
158
162
  * Custom extractor function type
@@ -163,9 +167,10 @@ export declare type Extractor = (content: string, filePath: string) => string[];
163
167
  * Extract all utility class names from a content string.
164
168
  *
165
169
  * @param content The content to search
170
+ * @param pattern Optional custom regex pattern (must use global flag). Defaults to UTILITY_CLASS_PATTERN.
166
171
  * @returns Array of unique utility class names found
167
172
  */
168
- export declare function extractUtilityClasses(content: string): string[];
173
+ export declare function extractUtilityClasses(content: string, pattern?: RegExp): string[];
169
174
 
170
175
  /**
171
176
  * Scan result for a single file
@@ -186,9 +191,10 @@ export declare interface FileScanResult {
186
191
  *
187
192
  * @param root The Styleframe root instance
188
193
  * @param usedClasses Set of used utility class names
194
+ * @param selectorFn Optional custom selector function
189
195
  * @returns Array of used children (utilities are filtered, other types pass through)
190
196
  */
191
- export declare function filterUtilities(root: Root, usedClasses: Set<string>): Root["children"];
197
+ export declare function filterUtilities(root: Root, usedClasses: Set<string>, selectorFn?: UtilitySelectorFn): Root["children"];
192
198
 
193
199
  /**
194
200
  * Generate a utility selector string from components.
@@ -204,9 +210,9 @@ export declare function generateUtilityClassName(name: string, value: string, mo
204
210
  /**
205
211
  * Generate the CSS selector for a utility instance.
206
212
  *
207
- * This mirrors the logic from @styleframe/transpiler/defaults.ts
213
+ * Derives the selector from the class name by adding a `.` prefix and escaping special characters.
208
214
  */
209
- export declare function generateUtilitySelector(options: UtilitySelectorOptions): string;
215
+ export declare function generateUtilitySelector(options: UtilitySelectorOptions, selectorFn?: UtilitySelectorFn): string;
210
216
 
211
217
  /**
212
218
  * Get matches for arbitrary values.
@@ -292,9 +298,10 @@ export declare function parseUtilityClass(className: string): ParsedUtility | nu
292
298
  *
293
299
  * @param content Content string to scan
294
300
  * @param filePath Optional file path hint for extractor selection
301
+ * @param utilities Optional custom utility syntax configuration
295
302
  * @returns Array of parsed utilities
296
303
  */
297
- export declare function quickScan(content: string, filePath?: string): ParsedUtility[];
304
+ export declare function quickScan(content: string, filePath?: string, utilities?: ScannerUtilitiesConfig): ParsedUtility[];
298
305
 
299
306
  /**
300
307
  * Scanner instance interface
@@ -342,6 +349,21 @@ export declare interface ScannerConfig {
342
349
  extractors?: Extractor[];
343
350
  /** Base directory for glob resolution (defaults to process.cwd()) */
344
351
  cwd?: string;
352
+ /** Custom utility class syntax configuration */
353
+ utilities?: ScannerUtilitiesConfig;
354
+ }
355
+
356
+ /**
357
+ * Configuration for custom utility class syntax.
358
+ * All fields are optional — defaults match the `_modifier:property:value` format.
359
+ */
360
+ export declare interface ScannerUtilitiesConfig {
361
+ /** Regex pattern to extract utility class candidates from content strings. Must use the global (`g`) flag. */
362
+ pattern?: RegExp;
363
+ /** Parse a matched class name into its components (name, value, modifiers) */
364
+ parse?: UtilityClassParseFn;
365
+ /** Generate a raw class name from components (inverse of parse) */
366
+ selector?: UtilitySelectorFn;
345
367
  }
346
368
 
347
369
  /**
@@ -375,6 +397,12 @@ export declare interface ScanResult {
375
397
  */
376
398
  export declare const UTILITY_CLASS_PATTERN: RegExp;
377
399
 
400
+ /**
401
+ * Function that parses a class name string into its structured components.
402
+ * Returns null if the string is not a valid utility class.
403
+ */
404
+ export declare type UtilityClassParseFn = (className: string) => ParsedUtility | null;
405
+
378
406
  /**
379
407
  * Filter function for utilities
380
408
  */
@@ -394,14 +422,9 @@ export declare interface UtilityMatch {
394
422
  exists: boolean;
395
423
  }
396
424
 
397
- /**
398
- * Utility selector generation options
399
- */
400
- export declare interface UtilitySelectorOptions {
401
- name: string;
402
- value: string;
403
- modifiers: string[];
404
- }
425
+ export { UtilitySelectorFn }
426
+
427
+ export { UtilitySelectorOptions }
405
428
 
406
429
  /**
407
430
  * Callback type for file change events