@csszyx/types 0.7.0 → 0.8.0

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.
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,4 +1,4 @@
1
- import { RecoveryMode } from './runtime.js';
1
+ import { RecoveryMode } from './runtime.cjs';
2
2
 
3
3
  /**
4
4
  * Compiler types for csszyx.
@@ -0,0 +1,431 @@
1
+ import { RecoveryMode } from './runtime.mjs';
2
+
3
+ /**
4
+ * Compiler types for csszyx.
5
+ *
6
+ * This module defines types used during compilation and build phases.
7
+ */
8
+
9
+ /**
10
+ * Build phase identifiers.
11
+ */
12
+ type BuildPhase = 'type_generation' | 'jsx_transform' | 'tailwind_jit' | 'global_mangling' | 'output_emit';
13
+ /**
14
+ * Build phase status.
15
+ */
16
+ type BuildPhaseStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
17
+ /**
18
+ * Build phase result.
19
+ */
20
+ interface BuildPhaseResult {
21
+ /**
22
+ * Phase identifier
23
+ */
24
+ phase: BuildPhase;
25
+ /**
26
+ * Phase status
27
+ */
28
+ status: BuildPhaseStatus;
29
+ /**
30
+ * Time taken in milliseconds
31
+ */
32
+ duration?: number;
33
+ /**
34
+ * Error if phase failed
35
+ */
36
+ error?: Error;
37
+ /**
38
+ * Output artifacts from this phase
39
+ */
40
+ artifacts?: string[];
41
+ }
42
+ /**
43
+ * Compiler options.
44
+ */
45
+ interface CompilerOptions {
46
+ /**
47
+ * Build ID (git hash or timestamp)
48
+ */
49
+ buildId?: string;
50
+ /**
51
+ * Enable development mode features
52
+ */
53
+ development?: boolean;
54
+ /**
55
+ * Strict mode - fail build on warnings
56
+ */
57
+ strictMode?: boolean;
58
+ /**
59
+ * Enable debug output
60
+ */
61
+ debug?: boolean;
62
+ /**
63
+ * Source root directory
64
+ */
65
+ sourceRoot?: string;
66
+ /**
67
+ * Output directory
68
+ */
69
+ outDir?: string;
70
+ }
71
+ /**
72
+ * Transform options for JSX transformation.
73
+ */
74
+ interface TransformOptions {
75
+ /**
76
+ * File path being transformed
77
+ */
78
+ filePath: string;
79
+ /**
80
+ * Build ID
81
+ */
82
+ buildId: string;
83
+ /**
84
+ * Whether to inject recovery tokens
85
+ */
86
+ injectRecovery: boolean;
87
+ /**
88
+ * Development mode
89
+ */
90
+ development: boolean;
91
+ }
92
+ /**
93
+ * Token metadata for compiler.
94
+ */
95
+ interface TokenMetadata {
96
+ /**
97
+ * Recovery mode
98
+ */
99
+ mode: RecoveryMode;
100
+ /**
101
+ * Component name
102
+ */
103
+ component: string;
104
+ /**
105
+ * Absolute file path
106
+ */
107
+ filePath: string;
108
+ /**
109
+ * Line number in source
110
+ */
111
+ line: number;
112
+ /**
113
+ * Column number in source
114
+ */
115
+ column: number;
116
+ /**
117
+ * Build ID
118
+ */
119
+ buildId: string;
120
+ }
121
+ /**
122
+ * Generated recovery token with metadata.
123
+ */
124
+ interface GeneratedToken {
125
+ /**
126
+ * The token string
127
+ */
128
+ token: string;
129
+ /**
130
+ * Token metadata
131
+ */
132
+ metadata: TokenMetadata;
133
+ }
134
+ /**
135
+ * Compilation result for a single file.
136
+ */
137
+ interface FileCompilationResult {
138
+ /**
139
+ * File path
140
+ */
141
+ filePath: string;
142
+ /**
143
+ * Transformed code
144
+ */
145
+ code: string;
146
+ /**
147
+ * Source map (optional)
148
+ */
149
+ map?: string;
150
+ /**
151
+ * Generated tokens
152
+ */
153
+ tokens: GeneratedToken[];
154
+ /**
155
+ * Extracted class names
156
+ */
157
+ classNames: string[];
158
+ /**
159
+ * Whether file was cached
160
+ */
161
+ cached: boolean;
162
+ }
163
+ /**
164
+ * Build statistics.
165
+ */
166
+ interface BuildStatistics {
167
+ /**
168
+ * Total files processed
169
+ */
170
+ filesProcessed: number;
171
+ /**
172
+ * Files from cache
173
+ */
174
+ filesCached: number;
175
+ /**
176
+ * Total class names found
177
+ */
178
+ totalClasses: number;
179
+ /**
180
+ * Unique class names
181
+ */
182
+ uniqueClasses: number;
183
+ /**
184
+ * Recovery tokens generated
185
+ */
186
+ tokensGenerated: number;
187
+ /**
188
+ * Total build time (ms)
189
+ */
190
+ totalTime: number;
191
+ /**
192
+ * Phase durations
193
+ */
194
+ phaseTimes: Partial<Record<BuildPhase, number>>;
195
+ /**
196
+ * Memory usage (bytes)
197
+ */
198
+ memoryUsage?: number;
199
+ }
200
+ /**
201
+ * Build result.
202
+ */
203
+ interface BuildResult {
204
+ /**
205
+ * Success flag
206
+ */
207
+ success: boolean;
208
+ /**
209
+ * Build statistics
210
+ */
211
+ stats: BuildStatistics;
212
+ /**
213
+ * Phase results
214
+ */
215
+ phases: BuildPhaseResult[];
216
+ /**
217
+ * Errors encountered
218
+ */
219
+ errors: Error[];
220
+ /**
221
+ * Warnings generated
222
+ */
223
+ warnings: string[];
224
+ /**
225
+ * Output artifacts
226
+ */
227
+ artifacts: Record<string, string>;
228
+ }
229
+ /**
230
+ * Mangle map entry.
231
+ */
232
+ interface MangleMapEntry {
233
+ /**
234
+ * Original class name
235
+ */
236
+ original: string;
237
+ /**
238
+ * Mangled class name
239
+ */
240
+ mangled: string;
241
+ /**
242
+ * Usage count
243
+ */
244
+ usageCount: number;
245
+ /**
246
+ * First seen at file
247
+ */
248
+ firstSeenIn?: string;
249
+ }
250
+ /**
251
+ * Collision detection result.
252
+ */
253
+ interface CollisionResult {
254
+ /**
255
+ * Whether a collision was detected
256
+ */
257
+ hasCollision: boolean;
258
+ /**
259
+ * Colliding class names
260
+ */
261
+ collisions?: Array<{
262
+ className: string;
263
+ hash: string;
264
+ conflictsWith: string;
265
+ }>;
266
+ }
267
+ /**
268
+ * AST node location.
269
+ */
270
+ interface NodeLocation {
271
+ /**
272
+ * Line number
273
+ */
274
+ line: number;
275
+ /**
276
+ * Column number
277
+ */
278
+ column: number;
279
+ /**
280
+ * File path
281
+ */
282
+ filePath: string;
283
+ }
284
+ /**
285
+ * Validation error.
286
+ */
287
+ interface ValidationError {
288
+ /**
289
+ * Error type
290
+ */
291
+ type: 'syntax' | 'semantic' | 'type' | 'warning';
292
+ /**
293
+ * Error message
294
+ */
295
+ message: string;
296
+ /**
297
+ * Location where error occurred
298
+ */
299
+ location?: NodeLocation;
300
+ /**
301
+ * Suggestions for fixing
302
+ */
303
+ suggestions?: string[];
304
+ }
305
+ /**
306
+ * Validation result.
307
+ */
308
+ interface ValidationResult {
309
+ /**
310
+ * Whether validation passed
311
+ */
312
+ valid: boolean;
313
+ /**
314
+ * Validation errors
315
+ */
316
+ errors: ValidationError[];
317
+ /**
318
+ * Warnings
319
+ */
320
+ warnings: ValidationError[];
321
+ }
322
+ /**
323
+ * Plugin interface for extending compiler.
324
+ */
325
+ interface CompilerPlugin {
326
+ /**
327
+ * Plugin name
328
+ */
329
+ name: string;
330
+ /**
331
+ * Plugin version
332
+ */
333
+ version?: string;
334
+ /**
335
+ * Setup hook - called once at initialization
336
+ */
337
+ setup?: (compiler: CompilerContext) => void | Promise<void>;
338
+ /**
339
+ * Transform hook - called for each file
340
+ */
341
+ transform?: (code: string, filePath: string, options: TransformOptions) => string | Promise<string>;
342
+ /**
343
+ * Post-process hook - called after all transformations
344
+ */
345
+ postProcess?: (result: BuildResult) => BuildResult | Promise<BuildResult>;
346
+ }
347
+ /**
348
+ * Compiler context passed to plugins.
349
+ */
350
+ interface CompilerContext {
351
+ /**
352
+ * Compiler options
353
+ */
354
+ options: CompilerOptions;
355
+ /**
356
+ * Build statistics (read-only)
357
+ */
358
+ readonly stats: BuildStatistics;
359
+ /**
360
+ * Register a new file for processing
361
+ */
362
+ addFile: (filePath: string) => void;
363
+ /**
364
+ * Get compilation result for a file
365
+ */
366
+ getFileResult: (filePath: string) => FileCompilationResult | undefined;
367
+ /**
368
+ * Emit a warning
369
+ */
370
+ warn: (message: string, location?: NodeLocation) => void;
371
+ /**
372
+ * Emit an error
373
+ */
374
+ error: (message: string, location?: NodeLocation) => void;
375
+ }
376
+ /**
377
+ * Cache entry for incremental builds.
378
+ */
379
+ interface CacheEntry {
380
+ /**
381
+ * File path
382
+ */
383
+ filePath: string;
384
+ /**
385
+ * Content hash
386
+ */
387
+ contentHash: string;
388
+ /**
389
+ * Compilation result
390
+ */
391
+ result: FileCompilationResult;
392
+ /**
393
+ * Timestamp when cached
394
+ */
395
+ timestamp: number;
396
+ /**
397
+ * Build ID when cached
398
+ */
399
+ buildId: string;
400
+ }
401
+ /**
402
+ * Cache manager interface.
403
+ */
404
+ interface CacheManager {
405
+ /**
406
+ * Get cached result for a file
407
+ */
408
+ get: (filePath: string, contentHash: string) => CacheEntry | undefined;
409
+ /**
410
+ * Set cache entry for a file
411
+ */
412
+ set: (filePath: string, contentHash: string, result: FileCompilationResult) => void;
413
+ /**
414
+ * Clear cache for a file
415
+ */
416
+ clear: (filePath: string) => void;
417
+ /**
418
+ * Clear all cache entries
419
+ */
420
+ clearAll: () => void;
421
+ /**
422
+ * Get cache statistics
423
+ */
424
+ getStats: () => {
425
+ entries: number;
426
+ totalSize: number;
427
+ hitRate: number;
428
+ };
429
+ }
430
+
431
+ export type { BuildPhase, BuildPhaseResult, BuildPhaseStatus, BuildResult, BuildStatistics, CacheEntry, CacheManager, CollisionResult, CompilerContext, CompilerOptions, CompilerPlugin, FileCompilationResult, GeneratedToken, MangleMapEntry, NodeLocation, TokenMetadata, TransformOptions, ValidationError, ValidationResult };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const DEFAULT_DEVELOPMENT_CONFIG = {
4
+ strictMode: false,
5
+ debug: false
6
+ };
7
+ const DEFAULT_PRODUCTION_CONFIG = {
8
+ mangle: true,
9
+ contentHashing: true,
10
+ injectChecksum: true,
11
+ incrementalBuild: true,
12
+ minify: true
13
+ };
14
+ const DEFAULT_BUILD_CONFIG = {
15
+ tailwindConfig: "tailwind.config.js",
16
+ outputDir: ".csszyx",
17
+ cacheDir: ".csszyx/cache",
18
+ astBudgetLimit: 5e4,
19
+ parser: "oxc"
20
+ };
21
+ const DEFAULT_HYDRATION_CONFIG = {
22
+ strict: true,
23
+ defaultRecoveryMode: null,
24
+ auditLog: true
25
+ };
26
+ const DEFAULT_PERFORMANCE_CONFIG = {
27
+ parallel: true,
28
+ optimizeVariables: true,
29
+ zeroRuntime: true
30
+ };
31
+ const DEFAULT_CSSZYX_CONFIG = {
32
+ development: DEFAULT_DEVELOPMENT_CONFIG,
33
+ production: DEFAULT_PRODUCTION_CONFIG,
34
+ build: DEFAULT_BUILD_CONFIG,
35
+ hydration: DEFAULT_HYDRATION_CONFIG,
36
+ performance: DEFAULT_PERFORMANCE_CONFIG
37
+ };
38
+ function getCurrentEnvironment() {
39
+ const env = process.env.NODE_ENV;
40
+ if (env === "production") {
41
+ return "production";
42
+ }
43
+ if (env === "test") {
44
+ return "test";
45
+ }
46
+ return "development";
47
+ }
48
+
49
+ exports.DEFAULT_BUILD_CONFIG = DEFAULT_BUILD_CONFIG;
50
+ exports.DEFAULT_CSSZYX_CONFIG = DEFAULT_CSSZYX_CONFIG;
51
+ exports.DEFAULT_DEVELOPMENT_CONFIG = DEFAULT_DEVELOPMENT_CONFIG;
52
+ exports.DEFAULT_HYDRATION_CONFIG = DEFAULT_HYDRATION_CONFIG;
53
+ exports.DEFAULT_PERFORMANCE_CONFIG = DEFAULT_PERFORMANCE_CONFIG;
54
+ exports.DEFAULT_PRODUCTION_CONFIG = DEFAULT_PRODUCTION_CONFIG;
55
+ exports.getCurrentEnvironment = getCurrentEnvironment;
@@ -91,6 +91,15 @@ interface BuildConfig {
91
91
  * @default 50000
92
92
  */
93
93
  astBudgetLimit?: number;
94
+ /**
95
+ * Source parser used for JSX/TSX sz transforms.
96
+ *
97
+ * `oxc` is the default parser. `babel` remains available as a compatibility
98
+ * fallback while the migration keeps Babel dependencies installed.
99
+ *
100
+ * @default "oxc"
101
+ */
102
+ parser?: 'babel' | 'oxc';
94
103
  /**
95
104
  * CSS file(s) to scan for Tailwind v4 @theme blocks.
96
105
  * When set, the plugin generates .csszyx/theme.d.ts with TypeScript augmentation
@@ -102,6 +111,14 @@ interface BuildConfig {
102
111
  */
103
112
  scanCss?: string | string[];
104
113
  }
114
+ /**
115
+ * File patterns accepted by csszyx plugin filters.
116
+ *
117
+ * String patterns may be literal paths (`src/generated/icon-dump.tsx`) or
118
+ * simple globs such as `src/generated/**` or any TSX file. RegExp patterns are matched
119
+ * against both absolute paths and paths relative to the project root.
120
+ */
121
+ type FilePattern = string | RegExp;
105
122
  /**
106
123
  * Hydration safety configuration.
107
124
  */
@@ -184,6 +201,21 @@ interface CsszyxConfig {
184
201
  * All fields are optional and will be merged with defaults.
185
202
  */
186
203
  type PartialCsszyxConfig = {
204
+ /**
205
+ * Restrict source files that csszyx transforms.
206
+ *
207
+ * CSS files used for Tailwind class discovery are still processed unless
208
+ * excluded explicitly, so narrow source includes do not accidentally disable
209
+ * CSS safelist injection.
210
+ */
211
+ include?: FilePattern | FilePattern[];
212
+ /**
213
+ * Exclude files from csszyx processing before parsing.
214
+ *
215
+ * Use this for large generated source files that happen to contain an `sz`
216
+ * marker and would otherwise hit the AST budget guard.
217
+ */
218
+ exclude?: FilePattern | FilePattern[];
187
219
  development?: Partial<DevelopmentConfig>;
188
220
  production?: Partial<ProductionConfig>;
189
221
  build?: Partial<BuildConfig>;
@@ -225,4 +257,5 @@ type Environment = 'development' | 'production' | 'test';
225
257
  */
226
258
  declare function getCurrentEnvironment(): Environment;
227
259
 
228
- export { type BuildConfig, type CsszyxConfig, DEFAULT_BUILD_CONFIG, DEFAULT_CSSZYX_CONFIG, DEFAULT_DEVELOPMENT_CONFIG, DEFAULT_HYDRATION_CONFIG, DEFAULT_PERFORMANCE_CONFIG, DEFAULT_PRODUCTION_CONFIG, type DevelopmentConfig, type Environment, type HydrationConfig, type PartialCsszyxConfig, type PerformanceConfig, type ProductionConfig, getCurrentEnvironment };
260
+ export { DEFAULT_BUILD_CONFIG, DEFAULT_CSSZYX_CONFIG, DEFAULT_DEVELOPMENT_CONFIG, DEFAULT_HYDRATION_CONFIG, DEFAULT_PERFORMANCE_CONFIG, DEFAULT_PRODUCTION_CONFIG, getCurrentEnvironment };
261
+ export type { BuildConfig, CsszyxConfig, DevelopmentConfig, Environment, FilePattern, HydrationConfig, PartialCsszyxConfig, PerformanceConfig, ProductionConfig };