@csszyx/compiler 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.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @csszyx/compiler
2
+
3
+ TypeScript compiler package for csszyx - handles JSX transformation, recovery token generation, and manifest creation.
4
+
5
+ ## Features
6
+
7
+ - **JSX Transform**: Converts `sz` prop to Tailwind CSS `className` strings
8
+ - **Recovery Token System**: Cryptographic tokens for hydration recovery control
9
+ - **Manifest Generation**: Build-time manifest for recovery metadata
10
+ - **Type Safety**: Full TypeScript support with strict types
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @csszyx/compiler
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Basic Transform
21
+
22
+ ```typescript
23
+ import { transform } from "@csszyx/compiler";
24
+
25
+ // Transform sz object to className string
26
+ const className = transform({ p: 4, bg: "red-500" });
27
+ // Returns: "p-4 bg-red-500"
28
+
29
+ // With variants
30
+ const classNameWithVariants = transform({
31
+ p: 4,
32
+ hover: { bg: "blue-500" },
33
+ });
34
+ // Returns: "p-4 hover:bg-blue-500"
35
+ ```
36
+
37
+ ### Recovery Token Generation
38
+
39
+ ```typescript
40
+ import { createRecoveryToken } from "@csszyx/compiler";
41
+
42
+ const recovery = createRecoveryToken(
43
+ {
44
+ mode: "csr",
45
+ component: "Button",
46
+ filePath: "/app/Button.tsx",
47
+ line: 10,
48
+ column: 5,
49
+ },
50
+ "build-123",
51
+ );
52
+
53
+ console.log(recovery.token); // "a94f1c2e8b3d"
54
+ ```
55
+
56
+ ### Manifest Builder
57
+
58
+ ```typescript
59
+ import { ManifestBuilder } from "@csszyx/compiler";
60
+
61
+ const builder = new ManifestBuilder("build-123");
62
+
63
+ builder.addToken("token1", {
64
+ mode: "csr",
65
+ component: "Button",
66
+ filePath: "/app/Button.tsx",
67
+ line: 10,
68
+ column: 5,
69
+ buildId: "build-123",
70
+ });
71
+
72
+ const manifest = builder.build();
73
+ // {
74
+ // buildId: 'build-123',
75
+ // checksum: '...',
76
+ // tokens: { token1: { mode: 'csr', component: 'Button', path: '...' } }
77
+ // }
78
+ ```
79
+
80
+ ## API Reference
81
+
82
+ ### Transform
83
+
84
+ #### `transform(szProp: SzObject, prefix?: string): string`
85
+
86
+ Transforms a csszyx sz object into a Tailwind CSS className string.
87
+
88
+ #### `isValidSzProp(szProp: unknown): boolean`
89
+
90
+ Validates that an sz prop object is valid.
91
+
92
+ #### `normalizeClassName(className: string): string`
93
+
94
+ Normalizes a className string by removing extra whitespace.
95
+
96
+ ### Recovery
97
+
98
+ #### `generateRecoveryToken(metadata: TokenMetadata): string`
99
+
100
+ Generates a cryptographic token for a recovery declaration.
101
+
102
+ #### `createRecoveryToken(metadata, buildId): RecoveryToken`
103
+
104
+ Creates a recovery token with full metadata.
105
+
106
+ #### `isValidRecoveryMode(value: unknown): boolean`
107
+
108
+ Validates if a value is a valid recovery mode ('csr' or 'dev-only').
109
+
110
+ #### `validateSzRecover(value, componentName): { valid: boolean; error?: string }`
111
+
112
+ Validates szRecover attribute value.
113
+
114
+ #### `injectRecoveryToken(attributes, token): Record<string, unknown>`
115
+
116
+ Injects recovery token into JSX attributes.
117
+
118
+ ### Manifest
119
+
120
+ #### `class ManifestBuilder`
121
+
122
+ Builder class for creating recovery manifests.
123
+
124
+ Methods:
125
+
126
+ - `addToken(token: string, metadata: TokenMetadata): void`
127
+ - `build(): RecoveryManifest`
128
+ - `size(): number`
129
+ - `hasToken(token: string): boolean`
130
+ - `clear(): void`
131
+
132
+ #### `serializeManifest(manifest, pretty?): string`
133
+
134
+ Serializes a recovery manifest to JSON string.
135
+
136
+ #### `parseManifest(json: string): RecoveryManifest`
137
+
138
+ Parses a recovery manifest from JSON string.
139
+
140
+ #### `validateManifest(manifest): { valid: boolean; error?: string }`
141
+
142
+ Validates a recovery manifest structure.
143
+
144
+ ## License
145
+
146
+ MIT