@csszyx/core 0.4.0 → 0.6.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/package.json +3 -4
- package/pkg/csszyx_core.d.ts +244 -225
- package/pkg/csszyx_core.js +2 -4
- package/pkg/csszyx_core_bg.js +722 -637
- package/pkg/csszyx_core_bg.wasm +0 -0
- package/pkg/csszyx_core_bg.wasm.d.ts +19 -21
- package/pkg-node/csszyx_core.d.ts +244 -225
- package/pkg-node/csszyx_core.js +746 -668
- package/pkg-node/csszyx_core_bg.wasm +0 -0
- package/pkg-node/csszyx_core_bg.wasm.d.ts +19 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "WASM core for csszyx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csszyx",
|
|
@@ -37,9 +37,8 @@
|
|
|
37
37
|
"vitest": "^1.2.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "wasm-pack build --target bundler --out-dir pkg && wasm-pack build --target nodejs --out-dir pkg-node && rm -f pkg/.gitignore pkg-node/.gitignore",
|
|
41
|
-
"
|
|
42
|
-
"test": "npm run build:test && vitest run",
|
|
40
|
+
"build": "node scripts/preflight.mjs && wasm-pack build --mode no-install --target bundler --out-dir pkg && wasm-pack build --mode no-install --target nodejs --out-dir pkg-node && rm -f pkg/.gitignore pkg-node/.gitignore && node scripts/run-wasm-opt.mjs",
|
|
41
|
+
"test": "vitest run",
|
|
43
42
|
"test:watch": "vitest",
|
|
44
43
|
"clean": "rm -rf pkg pkg-node target"
|
|
45
44
|
}
|
package/pkg/csszyx_core.d.ts
CHANGED
|
@@ -1,238 +1,257 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* * `value` - CSS value to hash
|
|
16
|
-
*
|
|
17
|
-
* # Returns
|
|
18
|
-
*
|
|
19
|
-
* Variable name (e.g., "--v-abc123" or "--v-abc123-def456")
|
|
20
|
-
*/
|
|
21
|
-
add(value: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Gets the total number of variables (WASM binding).
|
|
24
|
-
*
|
|
25
|
-
* # Returns
|
|
26
|
-
*
|
|
27
|
-
* Number of unique CSS values
|
|
28
|
-
*/
|
|
29
|
-
count(): number;
|
|
30
|
-
/**
|
|
31
|
-
* Checks if any collision occurred (WASM binding).
|
|
32
|
-
*
|
|
33
|
-
* # Returns
|
|
34
|
-
*
|
|
35
|
-
* `true` if collision detected
|
|
36
|
-
*/
|
|
37
|
-
has_collision(): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new collision detector (WASM binding).
|
|
40
|
-
*/
|
|
41
|
-
constructor();
|
|
42
|
-
}
|
|
43
|
-
|
|
4
|
+
* Transforms a csszyx sz object into a Tailwind CSS className string in Rust for maximum performance.
|
|
5
|
+
*
|
|
6
|
+
* Phase 3 Enhancements:
|
|
7
|
+
* - Handles nested variants (hover, focus, md, etc.)
|
|
8
|
+
* - Handles negative values (m: -4 -> -m-4)
|
|
9
|
+
* - Handles boolean flags
|
|
10
|
+
* @param {any} val
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function transform_sz(val: any): string;
|
|
44
14
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* # Arguments
|
|
60
|
-
*
|
|
61
|
-
* * `map` - The mangle map to checksum
|
|
62
|
-
*
|
|
63
|
-
* # Returns
|
|
64
|
-
*
|
|
65
|
-
* A 16-character hex string checksum
|
|
66
|
-
*
|
|
67
|
-
* # Performance
|
|
68
|
-
*
|
|
69
|
-
* - Time complexity: O(n log n) for sorting + O(n) for hashing
|
|
70
|
-
* - Space complexity: O(n) for canonical string
|
|
71
|
-
* - Typical runtime: ~10-50µs for 1000 entries (10-15x faster than JS)
|
|
72
|
-
*
|
|
73
|
-
* # Security
|
|
74
|
-
*
|
|
75
|
-
* While we only use 64 bits of SHA-256, this provides sufficient collision
|
|
76
|
-
* resistance for our use case (detecting accidental mismatches, not
|
|
77
|
-
* cryptographic attacks). Birthday paradox gives us ~4 billion hashes
|
|
78
|
-
* before 50% collision probability.
|
|
79
|
-
*
|
|
80
|
-
* # Examples
|
|
81
|
-
*
|
|
82
|
-
* ```ignore
|
|
83
|
-
* // This function is wasm_bindgen — call from JS, not Rust directly.
|
|
84
|
-
* // Use compute_checksum_internal() for pure-Rust usage.
|
|
85
|
-
* let checksum = compute_mangle_checksum(js_map);
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export function compute_mangle_checksum(map: any): string;
|
|
89
|
-
|
|
15
|
+
* Initializes the WASM module.
|
|
16
|
+
*
|
|
17
|
+
* Should be called once before using any functions.
|
|
18
|
+
*
|
|
19
|
+
* # Examples
|
|
20
|
+
*
|
|
21
|
+
* ```javascript
|
|
22
|
+
* import init, { encode } from 'csszyx-core';
|
|
23
|
+
*
|
|
24
|
+
* await init();
|
|
25
|
+
* const id = encode(42);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function init(): void;
|
|
90
29
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* A Base62 encoded string following tier-based rules with reversed sequence
|
|
100
|
-
*
|
|
101
|
-
* # Performance
|
|
102
|
-
*
|
|
103
|
-
* - Time complexity: O(log n)
|
|
104
|
-
* - Space complexity: O(log n)
|
|
105
|
-
* - Average: ~5ns per encoding (measured on x86_64)
|
|
106
|
-
*
|
|
107
|
-
* # Examples
|
|
108
|
-
*
|
|
109
|
-
* ```
|
|
110
|
-
* use csszyx_core::encoder::encode;
|
|
111
|
-
*
|
|
112
|
-
* // Tier 1: Single letters (reversed)
|
|
113
|
-
* assert_eq!(encode(0), "z");
|
|
114
|
-
* assert_eq!(encode(25), "a");
|
|
115
|
-
* assert_eq!(encode(26), "Z");
|
|
116
|
-
* assert_eq!(encode(51), "A");
|
|
117
|
-
*
|
|
118
|
-
* // Tier 2: Letter + digit (both reversed)
|
|
119
|
-
* assert_eq!(encode(52), "z9");
|
|
120
|
-
* assert_eq!(encode(53), "z8");
|
|
121
|
-
* assert_eq!(encode(571), "A0");
|
|
122
|
-
*
|
|
123
|
-
* // Tier 3: Two letters (both reversed)
|
|
124
|
-
* assert_eq!(encode(572), "zz");
|
|
125
|
-
* assert_eq!(encode(573), "zy");
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
export function encode(index: number): string;
|
|
129
|
-
|
|
30
|
+
* Gets the version of csszyx-core.
|
|
31
|
+
*
|
|
32
|
+
* # Returns
|
|
33
|
+
*
|
|
34
|
+
* Version string
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
export function version(): string;
|
|
130
38
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
39
|
+
* Generates a cryptographic token for a recovery declaration.
|
|
40
|
+
*
|
|
41
|
+
* # Arguments
|
|
42
|
+
*
|
|
43
|
+
* * `component` - Component name
|
|
44
|
+
* * `path` - Absolute file path
|
|
45
|
+
* * `line` - Line number in source
|
|
46
|
+
* * `column` - Column number in source
|
|
47
|
+
* * `mode` - Recovery mode ('csr' or 'dev-only')
|
|
48
|
+
* * `build_id` - Build identifier (git hash or timestamp)
|
|
49
|
+
*
|
|
50
|
+
* # Returns
|
|
51
|
+
*
|
|
52
|
+
* A 12-character Base62 encoded token (first 12 chars of SHA-256 hash)
|
|
53
|
+
*
|
|
54
|
+
* # Security
|
|
55
|
+
*
|
|
56
|
+
* - Uses SHA-256 for cryptographic strength
|
|
57
|
+
* - Includes source location for uniqueness
|
|
58
|
+
* - Build ID ensures different builds have different tokens
|
|
59
|
+
* - Base62 encoding for URL safety
|
|
60
|
+
*
|
|
61
|
+
* # Examples
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
* use csszyx_core::token::generate_token;
|
|
65
|
+
*
|
|
66
|
+
* let token = generate_token(
|
|
67
|
+
* "DataTable",
|
|
68
|
+
* "/src/components/DataTable.tsx",
|
|
69
|
+
* 42,
|
|
70
|
+
* 8,
|
|
71
|
+
* "csr",
|
|
72
|
+
* "abc123def456"
|
|
73
|
+
* );
|
|
74
|
+
*
|
|
75
|
+
* assert_eq!(token.len(), 12);
|
|
76
|
+
* ```
|
|
77
|
+
* @param {string} component
|
|
78
|
+
* @param {string} path
|
|
79
|
+
* @param {number} line
|
|
80
|
+
* @param {number} column
|
|
81
|
+
* @param {string} mode
|
|
82
|
+
* @param {string} build_id
|
|
83
|
+
* @returns {string}
|
|
84
|
+
*/
|
|
170
85
|
export function generate_token(component: string, path: string, line: number, column: number, mode: string, build_id: string): string;
|
|
171
|
-
|
|
172
86
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
87
|
+
* Verifies a token against component information.
|
|
88
|
+
*
|
|
89
|
+
* # Arguments
|
|
90
|
+
*
|
|
91
|
+
* * `token` - Token to verify
|
|
92
|
+
* * `component` - Component name
|
|
93
|
+
* * `path` - File path
|
|
94
|
+
* * `line` - Line number
|
|
95
|
+
* * `column` - Column number
|
|
96
|
+
* * `mode` - Recovery mode
|
|
97
|
+
* * `build_id` - Build identifier
|
|
98
|
+
*
|
|
99
|
+
* # Returns
|
|
100
|
+
*
|
|
101
|
+
* `true` if token matches, `false` otherwise
|
|
102
|
+
* @param {string} token
|
|
103
|
+
* @param {string} component
|
|
104
|
+
* @param {string} path
|
|
105
|
+
* @param {number} line
|
|
106
|
+
* @param {number} column
|
|
107
|
+
* @param {string} mode
|
|
108
|
+
* @param {string} build_id
|
|
109
|
+
* @returns {boolean}
|
|
110
|
+
*/
|
|
111
|
+
export function verify_token(token: string, component: string, path: string, line: number, column: number, mode: string, build_id: string): boolean;
|
|
188
112
|
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
113
|
+
* Computes a deterministic SHA-256 checksum for a mangle map.
|
|
114
|
+
*
|
|
115
|
+
* The checksum is designed to be:
|
|
116
|
+
* 1. **Deterministic**: Same map always produces same checksum
|
|
117
|
+
* 2. **Collision-resistant**: Different maps produce different checksums
|
|
118
|
+
* 3. **Compact**: 16-character hex string (64 bits of SHA-256)
|
|
119
|
+
*
|
|
120
|
+
* # Algorithm
|
|
121
|
+
*
|
|
122
|
+
* 1. Sort all entries by original class name (determinism)
|
|
123
|
+
* 2. Create canonical string: "orig1:mangle1|orig2:mangle2|..."
|
|
124
|
+
* 3. Compute SHA-256 hash
|
|
125
|
+
* 4. Take first 16 hex characters (64 bits, ~1.8e19 possible values)
|
|
126
|
+
*
|
|
127
|
+
* # Arguments
|
|
128
|
+
*
|
|
129
|
+
* * `map` - The mangle map to checksum
|
|
130
|
+
*
|
|
131
|
+
* # Returns
|
|
132
|
+
*
|
|
133
|
+
* A 16-character hex string checksum
|
|
134
|
+
*
|
|
135
|
+
* # Performance
|
|
136
|
+
*
|
|
137
|
+
* - Time complexity: O(n log n) for sorting + O(n) for hashing
|
|
138
|
+
* - Space complexity: O(n) for canonical string
|
|
139
|
+
* - Typical runtime: ~10-50µs for 1000 entries (10-15x faster than JS)
|
|
140
|
+
*
|
|
141
|
+
* # Security
|
|
142
|
+
*
|
|
143
|
+
* While we only use 64 bits of SHA-256, this provides sufficient collision
|
|
144
|
+
* resistance for our use case (detecting accidental mismatches, not
|
|
145
|
+
* cryptographic attacks). Birthday paradox gives us ~4 billion hashes
|
|
146
|
+
* before 50% collision probability.
|
|
147
|
+
*
|
|
148
|
+
* # Examples
|
|
149
|
+
*
|
|
150
|
+
* ```ignore
|
|
151
|
+
* // This function is wasm_bindgen — call from JS, not Rust directly.
|
|
152
|
+
* // Use compute_checksum_internal() for pure-Rust usage.
|
|
153
|
+
* let checksum = compute_mangle_checksum(js_map);
|
|
154
|
+
* ```
|
|
155
|
+
* @param {any} map
|
|
156
|
+
* @returns {string}
|
|
157
|
+
*/
|
|
158
|
+
export function compute_mangle_checksum(map: any): string;
|
|
198
159
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
160
|
+
* WASM-exposed checksum verification.
|
|
161
|
+
*
|
|
162
|
+
* # Arguments
|
|
163
|
+
*
|
|
164
|
+
* * `map` - JavaScript object representing the mangle map
|
|
165
|
+
* * `expected_checksum` - The expected checksum string
|
|
166
|
+
*
|
|
167
|
+
* # Returns
|
|
168
|
+
*
|
|
169
|
+
* `true` if checksum matches, `false` otherwise
|
|
170
|
+
* @param {any} map
|
|
171
|
+
* @param {string} expected_checksum
|
|
172
|
+
* @returns {boolean}
|
|
173
|
+
*/
|
|
210
174
|
export function verify_mangle_checksum(map: any, expected_checksum: string): boolean;
|
|
211
|
-
|
|
212
175
|
/**
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
176
|
+
* Encodes an index to a reversed tier-based Base62 string.
|
|
177
|
+
*
|
|
178
|
+
* # Arguments
|
|
179
|
+
*
|
|
180
|
+
* * `index` - The zero-based index to encode
|
|
181
|
+
*
|
|
182
|
+
* # Returns
|
|
183
|
+
*
|
|
184
|
+
* A Base62 encoded string following tier-based rules with reversed sequence
|
|
185
|
+
*
|
|
186
|
+
* # Performance
|
|
187
|
+
*
|
|
188
|
+
* - Time complexity: O(log n)
|
|
189
|
+
* - Space complexity: O(log n)
|
|
190
|
+
* - Average: ~5ns per encoding (measured on x86_64)
|
|
191
|
+
*
|
|
192
|
+
* # Examples
|
|
193
|
+
*
|
|
194
|
+
* ```
|
|
195
|
+
* use csszyx_core::encoder::encode;
|
|
196
|
+
*
|
|
197
|
+
* // Tier 1: Single letters (reversed)
|
|
198
|
+
* assert_eq!(encode(0), "z");
|
|
199
|
+
* assert_eq!(encode(25), "a");
|
|
200
|
+
* assert_eq!(encode(26), "Z");
|
|
201
|
+
* assert_eq!(encode(51), "A");
|
|
202
|
+
*
|
|
203
|
+
* // Tier 2: Letter + digit (both reversed)
|
|
204
|
+
* assert_eq!(encode(52), "z9");
|
|
205
|
+
* assert_eq!(encode(53), "z8");
|
|
206
|
+
* assert_eq!(encode(571), "A0");
|
|
207
|
+
*
|
|
208
|
+
* // Tier 3: Two letters (both reversed)
|
|
209
|
+
* assert_eq!(encode(572), "zz");
|
|
210
|
+
* assert_eq!(encode(573), "zy");
|
|
211
|
+
* ```
|
|
212
|
+
* @param {number} index
|
|
213
|
+
* @returns {string}
|
|
214
|
+
*/
|
|
215
|
+
export function encode(index: number): string;
|
|
231
216
|
/**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
217
|
+
* WASM bindings for JavaScript interop
|
|
218
|
+
*/
|
|
219
|
+
export class WasmCollisionDetector {
|
|
220
|
+
free(): void;
|
|
221
|
+
/**
|
|
222
|
+
* Checks if any collision occurred (WASM binding).
|
|
223
|
+
*
|
|
224
|
+
* # Returns
|
|
225
|
+
*
|
|
226
|
+
* `true` if collision detected
|
|
227
|
+
* @returns {boolean}
|
|
228
|
+
*/
|
|
229
|
+
has_collision(): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Adds a CSS value and returns its variable name (WASM binding).
|
|
232
|
+
*
|
|
233
|
+
* # Arguments
|
|
234
|
+
*
|
|
235
|
+
* * `value` - CSS value to hash
|
|
236
|
+
*
|
|
237
|
+
* # Returns
|
|
238
|
+
*
|
|
239
|
+
* Variable name (e.g., "--v-abc123" or "--v-abc123-def456")
|
|
240
|
+
* @param {string} value
|
|
241
|
+
* @returns {string}
|
|
242
|
+
*/
|
|
243
|
+
add(value: string): string;
|
|
244
|
+
/**
|
|
245
|
+
* Creates a new collision detector (WASM binding).
|
|
246
|
+
*/
|
|
247
|
+
constructor();
|
|
248
|
+
/**
|
|
249
|
+
* Gets the total number of variables (WASM binding).
|
|
250
|
+
*
|
|
251
|
+
* # Returns
|
|
252
|
+
*
|
|
253
|
+
* Number of unique CSS values
|
|
254
|
+
* @returns {number}
|
|
255
|
+
*/
|
|
256
|
+
count(): number;
|
|
257
|
+
}
|
package/pkg/csszyx_core.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/* @ts-self-types="./csszyx_core.d.ts" */
|
|
2
1
|
|
|
3
2
|
import * as wasm from "./csszyx_core_bg.wasm";
|
|
4
3
|
import { __wbg_set_wasm } from "./csszyx_core_bg.js";
|
|
5
4
|
__wbg_set_wasm(wasm);
|
|
5
|
+
export * from "./csszyx_core_bg.js";
|
|
6
|
+
|
|
6
7
|
wasm.__wbindgen_start();
|
|
7
|
-
export {
|
|
8
|
-
WasmCollisionDetector, compute_mangle_checksum, encode, generate_token, init, transform_sz, verify_mangle_checksum, verify_token, version
|
|
9
|
-
} from "./csszyx_core_bg.js";
|