@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,110 @@
1
+ export { BuildConfig, CsszyxConfig, DEFAULT_BUILD_CONFIG, DEFAULT_CSSZYX_CONFIG, DEFAULT_DEVELOPMENT_CONFIG, DEFAULT_HYDRATION_CONFIG, DEFAULT_PERFORMANCE_CONFIG, DEFAULT_PRODUCTION_CONFIG, DevelopmentConfig, Environment, HydrationConfig, PartialCsszyxConfig, PerformanceConfig, ProductionConfig, getCurrentEnvironment } from './config.js';
2
+ export { AuditLogEntry, ComponentPropsWithSz, CsszyxWindow, HydrationError, HydrationErrorType, MangleMap, MangleMapMetadata, PerformanceMetrics, RecoveryManifest, RecoveryMode, RuntimeState, SzProp, TokenData, VerificationResult, isCsszyxWindow } from './runtime.js';
3
+ export { BuildPhase, BuildPhaseResult, BuildPhaseStatus, BuildResult, BuildStatistics, CacheEntry, CacheManager, CollisionResult, CompilerContext, CompilerOptions, CompilerPlugin, FileCompilationResult, GeneratedToken, MangleMapEntry, NodeLocation, TokenMetadata, TransformOptions, ValidationError, ValidationResult } from './compiler.js';
4
+ import { SzPropValue } from '@csszyx/compiler';
5
+ export { SzPropValue, SzProps } from '@csszyx/compiler';
6
+
7
+ /**
8
+ * @csszyx/types - Core WASM Contract
9
+ *
10
+ * This file defines the strict interface between the Rust/WASM core
11
+ * and the TypeScript world. This is the source of truth for "The Forge" workstream.
12
+ */
13
+ /**
14
+ *
15
+ */
16
+ interface CsszyxCoreWasm {
17
+ /**
18
+ * Encodes a numeric index into a compact tier-based class name (z, y, x...).
19
+ */
20
+ encode(index: number): string;
21
+ /**
22
+ * Generates a unique cryptographic recovery token for SSR hydration safety.
23
+ */
24
+ generate_token(componentName: string, filePath: string, line: number, column: number, recoveryMode: 'csr' | 'dev-only', buildId: string): string;
25
+ /**
26
+ * Verifies if a recovery token is valid for the given context.
27
+ */
28
+ verify_token(token: string, componentName: string, filePath: string, line: number, column: number, recoveryMode: 'csr' | 'dev-only', buildId: string): boolean;
29
+ /**
30
+ * Computes a dual-hash for a CSS class name to prevent collisions.
31
+ */
32
+ compute_dual_hash(className: string): string;
33
+ /**
34
+ * Returns the current version of the core engine.
35
+ */
36
+ version(): string;
37
+ }
38
+ /**
39
+ * The expected structure of the WASM initialization output.
40
+ */
41
+ interface CsszyxCorePkg {
42
+ default: () => Promise<void>;
43
+ encode: (index: number) => string;
44
+ generate_token: (componentName: string, filePath: string, line: number, column: number, recoveryMode: string, buildId: string) => string;
45
+ verify_token: (token: string, componentName: string, filePath: string, line: number, column: number, recoveryMode: string, buildId: string) => boolean;
46
+ compute_dual_hash: (className: string) => string;
47
+ version: () => string;
48
+ }
49
+
50
+ /**
51
+ * JSX type augmentation for csszyx sz prop.
52
+ *
53
+ * This module extends React's JSX namespace to add the `sz` prop
54
+ * to all HTML elements. Types are re-exported from @csszyx/compiler
55
+ * for IntelliSense and autocompletion.
56
+ *
57
+ * @module @csszyx/types/jsx
58
+ */
59
+
60
+
61
+
62
+ declare module 'react' {
63
+ /**
64
+ *
65
+ */
66
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
+ interface HTMLAttributes<T> {
68
+ /**
69
+ * csszyx styling prop — Tailwind CSS via object syntax or class string.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * <div sz={{ p: 4, bg: 'blue-500', hover: { bg: 'blue-700' } }} />
74
+ * <div sz="p-4 bg-blue-500 hover:bg-blue-700" />
75
+ * ```
76
+ */
77
+ sz?: SzPropValue;
78
+ }
79
+
80
+ /**
81
+ *
82
+ */
83
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
84
+ interface SVGAttributes<T> {
85
+ /**
86
+ * csszyx styling prop — Tailwind CSS via object syntax or class string.
87
+ *
88
+ * @example
89
+ * ```tsx
90
+ * <svg sz={{ fill: 'red-500', stroke: 'current' }} />
91
+ * ```
92
+ */
93
+ sz?: SzPropValue;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @csszyx/types - Shared TypeScript types for csszyx.
99
+ *
100
+ * This package provides comprehensive type definitions used across
101
+ * the csszyx framework, including configuration, runtime, and compiler types.
102
+ *
103
+ * @module @csszyx/types
104
+ */
105
+ /**
106
+ * Package version.
107
+ */
108
+ declare const VERSION = "0.0.0";
109
+
110
+ export { type CsszyxCorePkg, type CsszyxCoreWasm, VERSION };
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
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
+ import {
11
+ isCsszyxWindow
12
+ } from "./chunk-QAJB64L5.js";
13
+
14
+ // src/index.ts
15
+ var VERSION = "0.0.0";
16
+ export {
17
+ DEFAULT_BUILD_CONFIG,
18
+ DEFAULT_CSSZYX_CONFIG,
19
+ DEFAULT_DEVELOPMENT_CONFIG,
20
+ DEFAULT_HYDRATION_CONFIG,
21
+ DEFAULT_PERFORMANCE_CONFIG,
22
+ DEFAULT_PRODUCTION_CONFIG,
23
+ VERSION,
24
+ getCurrentEnvironment,
25
+ isCsszyxWindow
26
+ };
package/dist/jsx.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * JSX type augmentation for csszyx sz prop.
3
+ *
4
+ * This module extends React's JSX namespace to add the `sz` prop
5
+ * to all HTML elements. Types are re-exported from @csszyx/compiler
6
+ * for IntelliSense and autocompletion.
7
+ *
8
+ * @module @csszyx/types/jsx
9
+ */
10
+
11
+ import 'react';
12
+
13
+ import type { SzProps, SzPropValue } from '@csszyx/compiler';
14
+
15
+ export type { SzProps, SzPropValue };
16
+
17
+ declare module 'react' {
18
+ /**
19
+ *
20
+ */
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ interface HTMLAttributes<T> {
23
+ /**
24
+ * csszyx styling prop — Tailwind CSS via object syntax or class string.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * <div sz={{ p: 4, bg: 'blue-500', hover: { bg: 'blue-700' } }} />
29
+ * <div sz="p-4 bg-blue-500 hover:bg-blue-700" />
30
+ * ```
31
+ */
32
+ sz?: SzPropValue;
33
+ }
34
+
35
+ /**
36
+ *
37
+ */
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ interface SVGAttributes<T> {
40
+ /**
41
+ * csszyx styling prop — Tailwind CSS via object syntax or class string.
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <svg sz={{ fill: 'red-500', stroke: 'current' }} />
46
+ * ```
47
+ */
48
+ sz?: SzPropValue;
49
+ }
50
+ }
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Runtime types for csszyx.
3
+ *
4
+ * This module defines types used at runtime for hydration guards,
5
+ * recovery tokens, and mangle maps.
6
+ */
7
+ /**
8
+ * Recovery mode types.
9
+ */
10
+ type RecoveryMode = 'csr' | 'dev-only';
11
+ /**
12
+ * Token data stored in the recovery manifest.
13
+ */
14
+ interface TokenData {
15
+ /**
16
+ * Recovery mode ('csr' or 'dev-only')
17
+ */
18
+ mode: RecoveryMode;
19
+ /**
20
+ * Component name where the token was generated
21
+ */
22
+ component: string;
23
+ /**
24
+ * File path relative to project root
25
+ */
26
+ path: string;
27
+ }
28
+ /**
29
+ * Recovery manifest structure.
30
+ *
31
+ * Embedded in build output as JSON in a script tag with id "__SZ_RECOVERY_MANIFEST__".
32
+ */
33
+ interface RecoveryManifest {
34
+ /**
35
+ * Build ID (git hash or timestamp)
36
+ */
37
+ buildId: string;
38
+ /**
39
+ * SHA-256 checksum of the tokens object for integrity verification
40
+ */
41
+ checksum: string;
42
+ /**
43
+ * Map of recovery token → token data
44
+ */
45
+ tokens: Record<string, TokenData>;
46
+ }
47
+ /**
48
+ * Mangle map structure.
49
+ *
50
+ * Maps original Tailwind class names to their minified equivalents.
51
+ * Embedded in build output as JSON in a script tag with id "__SZ_MANGLE_MAP__".
52
+ */
53
+ interface MangleMap {
54
+ /**
55
+ * Map of original class name → mangled class name
56
+ */
57
+ [originalClass: string]: string;
58
+ }
59
+ /**
60
+ * Mangle map metadata.
61
+ */
62
+ interface MangleMapMetadata {
63
+ /**
64
+ * Build ID
65
+ */
66
+ buildId: string;
67
+ /**
68
+ * Total number of classes in the map
69
+ */
70
+ classCount: number;
71
+ /**
72
+ * SHA-256 checksum of the map for validation
73
+ */
74
+ checksum: string;
75
+ /**
76
+ * Timestamp when the map was generated
77
+ */
78
+ timestamp: number;
79
+ }
80
+ /**
81
+ * Hydration error types.
82
+ */
83
+ type HydrationErrorType = 'checksum_mismatch' | 'map_missing' | 'invalid_token' | 'abort_failed';
84
+ /**
85
+ * Hydration error details.
86
+ */
87
+ interface HydrationError {
88
+ /**
89
+ * Error type
90
+ */
91
+ type: HydrationErrorType;
92
+ /**
93
+ * Error message
94
+ */
95
+ message: string;
96
+ /**
97
+ * Element where the error occurred (optional)
98
+ */
99
+ element?: HTMLElement;
100
+ /**
101
+ * Timestamp when error occurred
102
+ */
103
+ timestamp: number;
104
+ /**
105
+ * Stack trace (optional)
106
+ */
107
+ stack?: string;
108
+ }
109
+ /**
110
+ * Token verification result.
111
+ */
112
+ interface VerificationResult {
113
+ /**
114
+ * Whether the token is valid
115
+ */
116
+ valid: boolean;
117
+ /**
118
+ * Token data if valid
119
+ */
120
+ tokenData?: TokenData;
121
+ /**
122
+ * Error message if invalid
123
+ */
124
+ error?: string;
125
+ }
126
+ /**
127
+ * Runtime state interface.
128
+ */
129
+ interface RuntimeState {
130
+ /**
131
+ * Whether the runtime has been initialized
132
+ */
133
+ initialized: boolean;
134
+ /**
135
+ * Current environment
136
+ */
137
+ environment: 'development' | 'production' | 'test';
138
+ /**
139
+ * Whether CSR recovery is allowed
140
+ */
141
+ csrRecoveryAllowed: boolean;
142
+ /**
143
+ * Loaded recovery manifest
144
+ */
145
+ manifest?: RecoveryManifest;
146
+ /**
147
+ * Loaded mangle map
148
+ */
149
+ mangleMap?: MangleMap;
150
+ /**
151
+ * Recorded hydration errors
152
+ */
153
+ errors: HydrationError[];
154
+ /**
155
+ * Count of aborted subtrees
156
+ */
157
+ abortedCount: number;
158
+ }
159
+ /**
160
+ * JSX sz prop object type.
161
+ */
162
+ interface SzProp {
163
+ [key: string]: string | number | boolean | SzProp;
164
+ }
165
+ /**
166
+ * Component props with sz attribute.
167
+ */
168
+ interface ComponentPropsWithSz {
169
+ /**
170
+ * csszyx object syntax for Tailwind classes
171
+ */
172
+ sz?: SzProp | string;
173
+ /**
174
+ * Recovery mode (optional)
175
+ */
176
+ szRecover?: RecoveryMode;
177
+ /**
178
+ * Standard className prop (merged with sz)
179
+ */
180
+ className?: string;
181
+ }
182
+ /**
183
+ * Audit log entry.
184
+ */
185
+ interface AuditLogEntry {
186
+ /**
187
+ * Log level
188
+ */
189
+ level: 'info' | 'warn' | 'error';
190
+ /**
191
+ * Log message
192
+ */
193
+ message: string;
194
+ /**
195
+ * Timestamp
196
+ */
197
+ timestamp: number;
198
+ /**
199
+ * Additional metadata
200
+ */
201
+ metadata?: Record<string, unknown>;
202
+ }
203
+ /**
204
+ * Performance metrics.
205
+ */
206
+ interface PerformanceMetrics {
207
+ /**
208
+ * Time taken for hydration guard (ms)
209
+ */
210
+ hydrationGuardTime?: number;
211
+ /**
212
+ * Time taken for token verification (ms)
213
+ */
214
+ tokenVerificationTime?: number;
215
+ /**
216
+ * Total number of tokens verified
217
+ */
218
+ tokensVerified?: number;
219
+ /**
220
+ * Number of hydration errors
221
+ */
222
+ hydrationErrors?: number;
223
+ /**
224
+ * Memory usage (bytes)
225
+ */
226
+ memoryUsage?: number;
227
+ }
228
+ /**
229
+ * Global window interface extensions for csszyx.
230
+ */
231
+ interface CsszyxWindow extends Window {
232
+ /**
233
+ * Allow CSR recovery flag (development only)
234
+ */
235
+ __SZ_ALLOW_CSR_RECOVERY__?: boolean;
236
+ /**
237
+ * Runtime state
238
+ */
239
+ __SZ_RUNTIME_STATE__?: RuntimeState;
240
+ /**
241
+ * Performance metrics
242
+ */
243
+ __SZ_METRICS__?: PerformanceMetrics;
244
+ /**
245
+ * Debug mode flag
246
+ */
247
+ __SZ_DEBUG__?: boolean;
248
+ }
249
+ /**
250
+ * Type guard to check if window has csszyx extensions.
251
+ *
252
+ * @param {Window} win - Window object to check
253
+ * @returns {win is CsszyxWindow} True if window has csszyx extensions
254
+ */
255
+ declare function isCsszyxWindow(win: Window): win is CsszyxWindow;
256
+
257
+ export { type AuditLogEntry, type ComponentPropsWithSz, type CsszyxWindow, type HydrationError, type HydrationErrorType, type MangleMap, type MangleMapMetadata, type PerformanceMetrics, type RecoveryManifest, type RecoveryMode, type RuntimeState, type SzProp, type TokenData, type VerificationResult, isCsszyxWindow };
@@ -0,0 +1,6 @@
1
+ import {
2
+ isCsszyxWindow
3
+ } from "./chunk-QAJB64L5.js";
4
+ export {
5
+ isCsszyxWindow
6
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@csszyx/types",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript definitions for csszyx",
5
+ "keywords": [
6
+ "csszyx",
7
+ "types",
8
+ "typescript"
9
+ ],
10
+ "author": "csszyx contributors",
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/nguyennhutien/csszyx/tree/main/packages/types#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/nguyennhutien/csszyx.git",
16
+ "directory": "packages/types"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/nguyennhutien/csszyx/issues"
20
+ },
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./config": {
31
+ "types": "./dist/config.d.ts",
32
+ "import": "./dist/config.js"
33
+ },
34
+ "./runtime": {
35
+ "types": "./dist/runtime.d.ts",
36
+ "import": "./dist/runtime.js"
37
+ },
38
+ "./compiler": {
39
+ "types": "./dist/compiler.d.ts",
40
+ "import": "./dist/compiler.js"
41
+ },
42
+ "./jsx": {
43
+ "types": "./dist/jsx.d.ts"
44
+ }
45
+ },
46
+ "files": [
47
+ "dist"
48
+ ],
49
+ "scripts": {
50
+ "build": "tsup src/index.ts src/config.ts src/runtime.ts src/compiler.ts --format esm --dts && cp src/jsx.d.ts dist/jsx.d.ts",
51
+ "dev": "tsup src/index.ts src/config.ts src/runtime.ts src/compiler.ts --format esm --dts --watch",
52
+ "type-check": "tsc --noEmit"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^20.11.0",
56
+ "tsup": "^8.0.0",
57
+ "typescript": "^5.3.3"
58
+ },
59
+ "peerDependencies": {
60
+ "@csszyx/compiler": ">=0.0.0"
61
+ }
62
+ }