@csszyx/types 0.1.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,435 @@
1
+ import { RecoveryMode } from './runtime.js';
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
+ * Auto-inject recovery tokens
56
+ */
57
+ autoInjectRecovery?: boolean;
58
+ /**
59
+ * Strict mode - fail build on warnings
60
+ */
61
+ strictMode?: boolean;
62
+ /**
63
+ * Enable debug output
64
+ */
65
+ debug?: boolean;
66
+ /**
67
+ * Source root directory
68
+ */
69
+ sourceRoot?: string;
70
+ /**
71
+ * Output directory
72
+ */
73
+ outDir?: string;
74
+ }
75
+ /**
76
+ * Transform options for JSX transformation.
77
+ */
78
+ interface TransformOptions {
79
+ /**
80
+ * File path being transformed
81
+ */
82
+ filePath: string;
83
+ /**
84
+ * Build ID
85
+ */
86
+ buildId: string;
87
+ /**
88
+ * Whether to inject recovery tokens
89
+ */
90
+ injectRecovery: boolean;
91
+ /**
92
+ * Development mode
93
+ */
94
+ development: boolean;
95
+ }
96
+ /**
97
+ * Token metadata for compiler.
98
+ */
99
+ interface TokenMetadata {
100
+ /**
101
+ * Recovery mode
102
+ */
103
+ mode: RecoveryMode;
104
+ /**
105
+ * Component name
106
+ */
107
+ component: string;
108
+ /**
109
+ * Absolute file path
110
+ */
111
+ filePath: string;
112
+ /**
113
+ * Line number in source
114
+ */
115
+ line: number;
116
+ /**
117
+ * Column number in source
118
+ */
119
+ column: number;
120
+ /**
121
+ * Build ID
122
+ */
123
+ buildId: string;
124
+ }
125
+ /**
126
+ * Generated recovery token with metadata.
127
+ */
128
+ interface GeneratedToken {
129
+ /**
130
+ * The token string
131
+ */
132
+ token: string;
133
+ /**
134
+ * Token metadata
135
+ */
136
+ metadata: TokenMetadata;
137
+ }
138
+ /**
139
+ * Compilation result for a single file.
140
+ */
141
+ interface FileCompilationResult {
142
+ /**
143
+ * File path
144
+ */
145
+ filePath: string;
146
+ /**
147
+ * Transformed code
148
+ */
149
+ code: string;
150
+ /**
151
+ * Source map (optional)
152
+ */
153
+ map?: string;
154
+ /**
155
+ * Generated tokens
156
+ */
157
+ tokens: GeneratedToken[];
158
+ /**
159
+ * Extracted class names
160
+ */
161
+ classNames: string[];
162
+ /**
163
+ * Whether file was cached
164
+ */
165
+ cached: boolean;
166
+ }
167
+ /**
168
+ * Build statistics.
169
+ */
170
+ interface BuildStatistics {
171
+ /**
172
+ * Total files processed
173
+ */
174
+ filesProcessed: number;
175
+ /**
176
+ * Files from cache
177
+ */
178
+ filesCached: number;
179
+ /**
180
+ * Total class names found
181
+ */
182
+ totalClasses: number;
183
+ /**
184
+ * Unique class names
185
+ */
186
+ uniqueClasses: number;
187
+ /**
188
+ * Recovery tokens generated
189
+ */
190
+ tokensGenerated: number;
191
+ /**
192
+ * Total build time (ms)
193
+ */
194
+ totalTime: number;
195
+ /**
196
+ * Phase durations
197
+ */
198
+ phaseTimes: Partial<Record<BuildPhase, number>>;
199
+ /**
200
+ * Memory usage (bytes)
201
+ */
202
+ memoryUsage?: number;
203
+ }
204
+ /**
205
+ * Build result.
206
+ */
207
+ interface BuildResult {
208
+ /**
209
+ * Success flag
210
+ */
211
+ success: boolean;
212
+ /**
213
+ * Build statistics
214
+ */
215
+ stats: BuildStatistics;
216
+ /**
217
+ * Phase results
218
+ */
219
+ phases: BuildPhaseResult[];
220
+ /**
221
+ * Errors encountered
222
+ */
223
+ errors: Error[];
224
+ /**
225
+ * Warnings generated
226
+ */
227
+ warnings: string[];
228
+ /**
229
+ * Output artifacts
230
+ */
231
+ artifacts: Record<string, string>;
232
+ }
233
+ /**
234
+ * Mangle map entry.
235
+ */
236
+ interface MangleMapEntry {
237
+ /**
238
+ * Original class name
239
+ */
240
+ original: string;
241
+ /**
242
+ * Mangled class name
243
+ */
244
+ mangled: string;
245
+ /**
246
+ * Usage count
247
+ */
248
+ usageCount: number;
249
+ /**
250
+ * First seen at file
251
+ */
252
+ firstSeenIn?: string;
253
+ }
254
+ /**
255
+ * Collision detection result.
256
+ */
257
+ interface CollisionResult {
258
+ /**
259
+ * Whether a collision was detected
260
+ */
261
+ hasCollision: boolean;
262
+ /**
263
+ * Colliding class names
264
+ */
265
+ collisions?: Array<{
266
+ className: string;
267
+ hash: string;
268
+ conflictsWith: string;
269
+ }>;
270
+ }
271
+ /**
272
+ * AST node location.
273
+ */
274
+ interface NodeLocation {
275
+ /**
276
+ * Line number
277
+ */
278
+ line: number;
279
+ /**
280
+ * Column number
281
+ */
282
+ column: number;
283
+ /**
284
+ * File path
285
+ */
286
+ filePath: string;
287
+ }
288
+ /**
289
+ * Validation error.
290
+ */
291
+ interface ValidationError {
292
+ /**
293
+ * Error type
294
+ */
295
+ type: 'syntax' | 'semantic' | 'type' | 'warning';
296
+ /**
297
+ * Error message
298
+ */
299
+ message: string;
300
+ /**
301
+ * Location where error occurred
302
+ */
303
+ location?: NodeLocation;
304
+ /**
305
+ * Suggestions for fixing
306
+ */
307
+ suggestions?: string[];
308
+ }
309
+ /**
310
+ * Validation result.
311
+ */
312
+ interface ValidationResult {
313
+ /**
314
+ * Whether validation passed
315
+ */
316
+ valid: boolean;
317
+ /**
318
+ * Validation errors
319
+ */
320
+ errors: ValidationError[];
321
+ /**
322
+ * Warnings
323
+ */
324
+ warnings: ValidationError[];
325
+ }
326
+ /**
327
+ * Plugin interface for extending compiler.
328
+ */
329
+ interface CompilerPlugin {
330
+ /**
331
+ * Plugin name
332
+ */
333
+ name: string;
334
+ /**
335
+ * Plugin version
336
+ */
337
+ version?: string;
338
+ /**
339
+ * Setup hook - called once at initialization
340
+ */
341
+ setup?: (compiler: CompilerContext) => void | Promise<void>;
342
+ /**
343
+ * Transform hook - called for each file
344
+ */
345
+ transform?: (code: string, filePath: string, options: TransformOptions) => string | Promise<string>;
346
+ /**
347
+ * Post-process hook - called after all transformations
348
+ */
349
+ postProcess?: (result: BuildResult) => BuildResult | Promise<BuildResult>;
350
+ }
351
+ /**
352
+ * Compiler context passed to plugins.
353
+ */
354
+ interface CompilerContext {
355
+ /**
356
+ * Compiler options
357
+ */
358
+ options: CompilerOptions;
359
+ /**
360
+ * Build statistics (read-only)
361
+ */
362
+ readonly stats: BuildStatistics;
363
+ /**
364
+ * Register a new file for processing
365
+ */
366
+ addFile: (filePath: string) => void;
367
+ /**
368
+ * Get compilation result for a file
369
+ */
370
+ getFileResult: (filePath: string) => FileCompilationResult | undefined;
371
+ /**
372
+ * Emit a warning
373
+ */
374
+ warn: (message: string, location?: NodeLocation) => void;
375
+ /**
376
+ * Emit an error
377
+ */
378
+ error: (message: string, location?: NodeLocation) => void;
379
+ }
380
+ /**
381
+ * Cache entry for incremental builds.
382
+ */
383
+ interface CacheEntry {
384
+ /**
385
+ * File path
386
+ */
387
+ filePath: string;
388
+ /**
389
+ * Content hash
390
+ */
391
+ contentHash: string;
392
+ /**
393
+ * Compilation result
394
+ */
395
+ result: FileCompilationResult;
396
+ /**
397
+ * Timestamp when cached
398
+ */
399
+ timestamp: number;
400
+ /**
401
+ * Build ID when cached
402
+ */
403
+ buildId: string;
404
+ }
405
+ /**
406
+ * Cache manager interface.
407
+ */
408
+ interface CacheManager {
409
+ /**
410
+ * Get cached result for a file
411
+ */
412
+ get: (filePath: string, contentHash: string) => CacheEntry | undefined;
413
+ /**
414
+ * Set cache entry for a file
415
+ */
416
+ set: (filePath: string, contentHash: string, result: FileCompilationResult) => void;
417
+ /**
418
+ * Clear cache for a file
419
+ */
420
+ clear: (filePath: string) => void;
421
+ /**
422
+ * Clear all cache entries
423
+ */
424
+ clearAll: () => void;
425
+ /**
426
+ * Get cache statistics
427
+ */
428
+ getStats: () => {
429
+ entries: number;
430
+ totalSize: number;
431
+ hitRate: number;
432
+ };
433
+ }
434
+
435
+ export type { BuildPhase, BuildPhaseResult, BuildPhaseStatus, BuildResult, BuildStatistics, CacheEntry, CacheManager, CollisionResult, CompilerContext, CompilerOptions, CompilerPlugin, FileCompilationResult, GeneratedToken, MangleMapEntry, NodeLocation, TokenMetadata, TransformOptions, ValidationError, ValidationResult };
File without changes
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Configuration types for csszyx.
3
+ *
4
+ * This module defines all configuration interfaces and types used
5
+ * throughout the csszyx framework.
6
+ */
7
+ /**
8
+ * Development mode configuration options.
9
+ */
10
+ interface DevelopmentConfig {
11
+ /**
12
+ * Automatically inject recovery tokens for all components.
13
+ * When enabled, all components get szRecover="dev-only" by default.
14
+ *
15
+ * @default false
16
+ */
17
+ autoInjectRecovery: boolean;
18
+ /**
19
+ * Enable strict mode - fail build on warnings.
20
+ * When enabled, warnings are treated as errors.
21
+ *
22
+ * @default false
23
+ */
24
+ strictMode: boolean;
25
+ /**
26
+ * Enable debug logging during build.
27
+ *
28
+ * @default false
29
+ */
30
+ debug: boolean;
31
+ /**
32
+ * Allow client-side recovery on hydration mismatch.
33
+ * Only works in development mode.
34
+ *
35
+ * @default true
36
+ */
37
+ allowCSRRecovery: boolean;
38
+ }
39
+ /**
40
+ * Production mode configuration options.
41
+ */
42
+ interface ProductionConfig {
43
+ /**
44
+ * Enable global class name mangling.
45
+ * Minifies class names to single characters (a, b, c, etc.).
46
+ *
47
+ * @default true
48
+ */
49
+ mangle: boolean;
50
+ /**
51
+ * Enable content hashing for immutable caching.
52
+ *
53
+ * @default true
54
+ */
55
+ contentHashing: boolean;
56
+ /**
57
+ * Inject checksum for SSR hydration validation.
58
+ *
59
+ * @default true
60
+ */
61
+ injectChecksum: boolean;
62
+ /**
63
+ * Enable incremental build caching.
64
+ *
65
+ * @default true
66
+ */
67
+ incrementalBuild: boolean;
68
+ /**
69
+ * Minify output (class names and attributes).
70
+ *
71
+ * @default true in production
72
+ */
73
+ minify: boolean;
74
+ }
75
+ /**
76
+ * Build pipeline configuration.
77
+ */
78
+ interface BuildConfig {
79
+ /**
80
+ * Build ID (git hash or timestamp).
81
+ * Auto-generated if not provided.
82
+ */
83
+ buildId?: string;
84
+ /**
85
+ * Path to Tailwind config file.
86
+ *
87
+ * @default "tailwind.config.js"
88
+ */
89
+ tailwindConfig?: string;
90
+ /**
91
+ * Output directory for generated files.
92
+ *
93
+ * @default ".csszyx"
94
+ */
95
+ outputDir?: string;
96
+ /**
97
+ * Cache directory for incremental builds.
98
+ *
99
+ * @default ".csszyx/cache"
100
+ */
101
+ cacheDir?: string;
102
+ /**
103
+ * Maximum AST nodes per file before warning.
104
+ *
105
+ * @default 50000
106
+ */
107
+ astBudgetLimit?: number;
108
+ }
109
+ /**
110
+ * Hydration safety configuration.
111
+ */
112
+ interface HydrationConfig {
113
+ /**
114
+ * Enable strict hydration checks.
115
+ * When enabled, hydration mismatches trigger abort protocol.
116
+ *
117
+ * @default true
118
+ */
119
+ strict: boolean;
120
+ /**
121
+ * Default recovery mode for components without explicit szRecover.
122
+ *
123
+ * @default null (no recovery)
124
+ */
125
+ defaultRecoveryMode?: 'csr' | 'dev-only' | null;
126
+ /**
127
+ * Enable hydration audit logging.
128
+ *
129
+ * @default true
130
+ */
131
+ auditLog: boolean;
132
+ }
133
+ /**
134
+ * Performance optimization configuration.
135
+ */
136
+ interface PerformanceConfig {
137
+ /**
138
+ * Enable parallel processing during build.
139
+ *
140
+ * @default true
141
+ */
142
+ parallel: boolean;
143
+ /**
144
+ * Number of worker threads for parallel processing.
145
+ * Auto-detected if not provided.
146
+ */
147
+ workers?: number;
148
+ /**
149
+ * Enable CSS variable optimization.
150
+ *
151
+ * @default true
152
+ */
153
+ optimizeVariables: boolean;
154
+ /**
155
+ * Enable zero-runtime optimization for static cases.
156
+ *
157
+ * @default true
158
+ */
159
+ zeroRuntime: boolean;
160
+ }
161
+ /**
162
+ * Main csszyx configuration.
163
+ */
164
+ interface CsszyxConfig {
165
+ /**
166
+ * Development mode configuration.
167
+ */
168
+ development: DevelopmentConfig;
169
+ /**
170
+ * Production mode configuration.
171
+ */
172
+ production: ProductionConfig;
173
+ /**
174
+ * Build pipeline configuration.
175
+ */
176
+ build: BuildConfig;
177
+ /**
178
+ * Hydration safety configuration.
179
+ */
180
+ hydration: HydrationConfig;
181
+ /**
182
+ * Performance optimization configuration.
183
+ */
184
+ performance: PerformanceConfig;
185
+ }
186
+ /**
187
+ * Partial configuration for user-provided config.
188
+ * All fields are optional and will be merged with defaults.
189
+ */
190
+ type PartialCsszyxConfig = {
191
+ development?: Partial<DevelopmentConfig>;
192
+ production?: Partial<ProductionConfig>;
193
+ build?: Partial<BuildConfig>;
194
+ hydration?: Partial<HydrationConfig>;
195
+ performance?: Partial<PerformanceConfig>;
196
+ };
197
+ /**
198
+ * Default development configuration.
199
+ */
200
+ declare const DEFAULT_DEVELOPMENT_CONFIG: DevelopmentConfig;
201
+ /**
202
+ * Default production configuration.
203
+ */
204
+ declare const DEFAULT_PRODUCTION_CONFIG: ProductionConfig;
205
+ /**
206
+ * Default build configuration.
207
+ */
208
+ declare const DEFAULT_BUILD_CONFIG: BuildConfig;
209
+ /**
210
+ * Default hydration configuration.
211
+ */
212
+ declare const DEFAULT_HYDRATION_CONFIG: HydrationConfig;
213
+ /**
214
+ * Default performance configuration.
215
+ */
216
+ declare const DEFAULT_PERFORMANCE_CONFIG: PerformanceConfig;
217
+ /**
218
+ * Default csszyx configuration.
219
+ */
220
+ declare const DEFAULT_CSSZYX_CONFIG: CsszyxConfig;
221
+ /**
222
+ * Environment type.
223
+ */
224
+ type Environment = 'development' | 'production' | 'test';
225
+ /**
226
+ * Gets the current environment.
227
+ *
228
+ * @returns {Environment} Current environment
229
+ */
230
+ declare function getCurrentEnvironment(): Environment;
231
+
232
+ 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 };
package/dist/config.js ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ DEFAULT_BUILD_CONFIG,
3
+ DEFAULT_CSSZYX_CONFIG,
4
+ DEFAULT_DEVELOPMENT_CONFIG,
5
+ DEFAULT_HYDRATION_CONFIG,
6
+ DEFAULT_PERFORMANCE_CONFIG,
7
+ DEFAULT_PRODUCTION_CONFIG,
8
+ getCurrentEnvironment
9
+ } from "./chunk-2KLMBDLU.js";
10
+ export {
11
+ DEFAULT_BUILD_CONFIG,
12
+ DEFAULT_CSSZYX_CONFIG,
13
+ DEFAULT_DEVELOPMENT_CONFIG,
14
+ DEFAULT_HYDRATION_CONFIG,
15
+ DEFAULT_PERFORMANCE_CONFIG,
16
+ DEFAULT_PRODUCTION_CONFIG,
17
+ getCurrentEnvironment
18
+ };