@csszyx/core 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 +113 -0
- package/package.json +46 -0
- package/pkg/README.md +113 -0
- package/pkg/csszyx_core.d.ts +248 -0
- package/pkg/csszyx_core.js +9 -0
- package/pkg/csszyx_core_bg.js +780 -0
- package/pkg/csszyx_core_bg.wasm +0 -0
- package/pkg/csszyx_core_bg.wasm.d.ts +24 -0
- package/pkg/package.json +26 -0
- package/pkg-node/README.md +113 -0
- package/pkg-node/csszyx_core.d.ts +248 -0
- package/pkg-node/csszyx_core.js +794 -0
- package/pkg-node/csszyx_core_bg.wasm +0 -0
- package/pkg-node/csszyx_core_bg.wasm.d.ts +24 -0
- package/pkg-node/package.json +20 -0
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const transform_sz: (a: any) => [number, number, number, number];
|
|
5
|
+
export const generate_token: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number];
|
|
6
|
+
export const verify_token: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => number;
|
|
7
|
+
export const __wbg_wasmcollisiondetector_free: (a: number, b: number) => void;
|
|
8
|
+
export const wasmcollisiondetector_add: (a: number, b: number, c: number) => [number, number];
|
|
9
|
+
export const wasmcollisiondetector_count: (a: number) => number;
|
|
10
|
+
export const wasmcollisiondetector_has_collision: (a: number) => number;
|
|
11
|
+
export const wasmcollisiondetector_new: () => number;
|
|
12
|
+
export const encode: (a: number) => [number, number];
|
|
13
|
+
export const compute_mangle_checksum: (a: any) => [number, number, number, number];
|
|
14
|
+
export const verify_mangle_checksum: (a: any, b: number, c: number) => [number, number, number];
|
|
15
|
+
export const init: () => void;
|
|
16
|
+
export const version: () => [number, number];
|
|
17
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
18
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
19
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
20
|
+
export const __externref_table_alloc: () => number;
|
|
21
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
22
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
23
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
24
|
+
export const __wbindgen_start: () => void;
|
package/pkg/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "csszyx-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Tien Nguyen <tien@example.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "Performance-critical core for csszyx CSS-in-JS framework",
|
|
8
|
+
"version": "0.0.0",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/nguyennhutien/csszyx"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"csszyx_core_bg.wasm",
|
|
16
|
+
"csszyx_core.js",
|
|
17
|
+
"csszyx_core_bg.js",
|
|
18
|
+
"csszyx_core.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "csszyx_core.js",
|
|
21
|
+
"types": "csszyx_core.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./csszyx_core.js",
|
|
24
|
+
"./snippets/*"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# <p align="center">π @csszyx/core</p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/badge/WASM-Powered-624de3?style=for-the-badge&logo=webassembly" alt="WASM Powered" />
|
|
5
|
+
<img src="https://img.shields.io/badge/Rust-Core-dea584?style=for-the-badge&logo=rust" alt="Rust Core" />
|
|
6
|
+
<img src="https://img.shields.io/badge/TypeScript-Ready-3178c6?style=for-the-badge&logo=typescript" alt="TypeScript Ready" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## β¨ The Engine of csszyx
|
|
12
|
+
|
|
13
|
+
`@csszyx/core` is a high-performance, precision-engineered Rust core for the **csszyx** ecosystem. Compiled to WebAssembly, it brings near-native performance to Node.js, Browsers, and Edge environments.
|
|
14
|
+
|
|
15
|
+
### π₯ Why Core?
|
|
16
|
+
|
|
17
|
+
- **Blazing Speed**: Offloads performance-critical operations (Hashing, Transformation, Encoding) to optimized Rust.
|
|
18
|
+
- **Universal Integrity**: Ensures bit-perfect mangle map consistency between SSR and hydration.
|
|
19
|
+
- **Security-First**: Uses SHA-256 and Base62 for tamper-proof tokens and collision-free variable names.
|
|
20
|
+
- **Zero Dependencies**: Lightweight WASM binary with no external runtimes required.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## π Quick Start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add @csszyx/core
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Initialization
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { init } from '@csszyx/core';
|
|
34
|
+
|
|
35
|
+
async function bootstrap() {
|
|
36
|
+
await init();
|
|
37
|
+
// Core is ready to flow π
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## π Modules
|
|
44
|
+
|
|
45
|
+
### πΊοΈ Mangle Map Integrity
|
|
46
|
+
|
|
47
|
+
Deterministic SHA-256 checksums to synchronize server-side class names with client-side hydration.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { compute_mangle_checksum, verify_mangle_checksum } from '@csszyx/core';
|
|
51
|
+
|
|
52
|
+
const mangleMap = { 'p-4': 'z', 'm-2': 'y' };
|
|
53
|
+
const checksum = compute_mangle_checksum(mangleMap);
|
|
54
|
+
// Results in a deterministic 16-char hex hash
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### π Transformer
|
|
58
|
+
|
|
59
|
+
Universal conversion of object-based Tailwind syntax into optimized class strings.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { transform_sz } from '@csszyx/core';
|
|
63
|
+
|
|
64
|
+
// Supports: Negatives, Opacity, Nesting, Integers
|
|
65
|
+
transform_sz({
|
|
66
|
+
m: -4,
|
|
67
|
+
bg: 'blue-500/20',
|
|
68
|
+
hover: { scale: 110 }
|
|
69
|
+
});
|
|
70
|
+
// "-m-4 bg-blue-500/20 hover:scale-110"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### π’ Tiered Encoder
|
|
74
|
+
|
|
75
|
+
The world's smallest CSS-compliant class name generator.
|
|
76
|
+
|
|
77
|
+
| Tier | Range | Format | Example |
|
|
78
|
+
| :--- | :--- | :--- | :--- |
|
|
79
|
+
| **Tier 1** | 0 - 51 | \[z-aZ-A\] | `z`, `y`, `x` |
|
|
80
|
+
| **Tier 2** | 52 - 571 | \[z-aZ-A\]\[9-0\] | `z9`, `y8` |
|
|
81
|
+
| **Tier 3** | 572 - 3275 | \[z-aZ-A\]{2} | `zz`, `zy` |
|
|
82
|
+
|
|
83
|
+
### π‘οΈ Collision Detector
|
|
84
|
+
|
|
85
|
+
Dual-hash resolution strategy for unique CSS variable names.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { WasmCollisionDetector } from '@csszyx/core';
|
|
89
|
+
|
|
90
|
+
const detector = new WasmCollisionDetector();
|
|
91
|
+
const varId = detector.add('#ff0000'); // "--v-a1b2c3"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## β‘ Performance Matrix
|
|
97
|
+
|
|
98
|
+
Benchmarks performed on Apple M2 (WASM Node v20 target)
|
|
99
|
+
|
|
100
|
+
| Operation | WASM (Rust) | Pure JS (Legacy) | Improvement |
|
|
101
|
+
| :--- | :--- | :--- | :--- |
|
|
102
|
+
| **Integrity Check** | < 1ms | ~15ms | **15x faster** |
|
|
103
|
+
| **ID Encoding** | ~5ns | ~50ns | **10x faster** |
|
|
104
|
+
| **Token Auth** | ~25ns | ~250ns | **10x faster** |
|
|
105
|
+
| **Transformer** | Optimized | Variable | Stable π |
|
|
106
|
+
|
|
107
|
+
> **Tech Tip**: WASM excels in consistency. Unlike JS which relies on JIT optimization, WASM provides deterministic, high-speed execution from the very first call.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## π License
|
|
112
|
+
|
|
113
|
+
MIT Β© 2026 csszyx Team
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WASM bindings for JavaScript interop
|
|
6
|
+
*/
|
|
7
|
+
export class WasmCollisionDetector {
|
|
8
|
+
free(): void;
|
|
9
|
+
[Symbol.dispose](): void;
|
|
10
|
+
/**
|
|
11
|
+
* Adds a CSS value and returns its variable name (WASM binding).
|
|
12
|
+
*
|
|
13
|
+
* # Arguments
|
|
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
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Computes a deterministic SHA-256 checksum for a mangle map.
|
|
46
|
+
*
|
|
47
|
+
* The checksum is designed to be:
|
|
48
|
+
* 1. **Deterministic**: Same map always produces same checksum
|
|
49
|
+
* 2. **Collision-resistant**: Different maps produce different checksums
|
|
50
|
+
* 3. **Compact**: 16-character hex string (64 bits of SHA-256)
|
|
51
|
+
*
|
|
52
|
+
* # Algorithm
|
|
53
|
+
*
|
|
54
|
+
* 1. Sort all entries by original class name (determinism)
|
|
55
|
+
* 2. Create canonical string: "orig1:mangle1|orig2:mangle2|..."
|
|
56
|
+
* 3. Compute SHA-256 hash
|
|
57
|
+
* 4. Take first 16 hex characters (64 bits, ~1.8e19 possible values)
|
|
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
|
+
* ```
|
|
83
|
+
* use csszyx_core::mangle::{compute_mangle_checksum, MangleMap};
|
|
84
|
+
* use std::collections::HashMap;
|
|
85
|
+
*
|
|
86
|
+
* let mut map = HashMap::new();
|
|
87
|
+
* map.insert("p-4".to_string(), "a".to_string());
|
|
88
|
+
* map.insert("bg-red-500".to_string(), "b".to_string());
|
|
89
|
+
*
|
|
90
|
+
* let checksum = compute_mangle_checksum(&map);
|
|
91
|
+
* assert_eq!(checksum.len(), 16);
|
|
92
|
+
*
|
|
93
|
+
* // Same map produces same checksum
|
|
94
|
+
* let checksum2 = compute_mangle_checksum(&map);
|
|
95
|
+
* assert_eq!(checksum, checksum2);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function compute_mangle_checksum(map: any): string;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Encodes an index to a reversed tier-based Base62 string.
|
|
102
|
+
*
|
|
103
|
+
* # Arguments
|
|
104
|
+
*
|
|
105
|
+
* * `index` - The zero-based index to encode
|
|
106
|
+
*
|
|
107
|
+
* # Returns
|
|
108
|
+
*
|
|
109
|
+
* A Base62 encoded string following tier-based rules with reversed sequence
|
|
110
|
+
*
|
|
111
|
+
* # Performance
|
|
112
|
+
*
|
|
113
|
+
* - Time complexity: O(log n)
|
|
114
|
+
* - Space complexity: O(log n)
|
|
115
|
+
* - Average: ~5ns per encoding (measured on x86_64)
|
|
116
|
+
*
|
|
117
|
+
* # Examples
|
|
118
|
+
*
|
|
119
|
+
* ```
|
|
120
|
+
* use csszyx_core::encoder::encode;
|
|
121
|
+
*
|
|
122
|
+
* // Tier 1: Single letters (reversed)
|
|
123
|
+
* assert_eq!(encode(0), "z");
|
|
124
|
+
* assert_eq!(encode(25), "a");
|
|
125
|
+
* assert_eq!(encode(26), "Z");
|
|
126
|
+
* assert_eq!(encode(51), "A");
|
|
127
|
+
*
|
|
128
|
+
* // Tier 2: Letter + digit (both reversed)
|
|
129
|
+
* assert_eq!(encode(52), "z9");
|
|
130
|
+
* assert_eq!(encode(53), "z8");
|
|
131
|
+
* assert_eq!(encode(571), "A0");
|
|
132
|
+
*
|
|
133
|
+
* // Tier 3: Two letters (both reversed)
|
|
134
|
+
* assert_eq!(encode(572), "zz");
|
|
135
|
+
* assert_eq!(encode(573), "zy");
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function encode(index: number): string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Generates a cryptographic token for a recovery declaration.
|
|
142
|
+
*
|
|
143
|
+
* # Arguments
|
|
144
|
+
*
|
|
145
|
+
* * `component` - Component name
|
|
146
|
+
* * `path` - Absolute file path
|
|
147
|
+
* * `line` - Line number in source
|
|
148
|
+
* * `column` - Column number in source
|
|
149
|
+
* * `mode` - Recovery mode ('csr' or 'dev-only')
|
|
150
|
+
* * `build_id` - Build identifier (git hash or timestamp)
|
|
151
|
+
*
|
|
152
|
+
* # Returns
|
|
153
|
+
*
|
|
154
|
+
* A 12-character Base62 encoded token (first 12 chars of SHA-256 hash)
|
|
155
|
+
*
|
|
156
|
+
* # Security
|
|
157
|
+
*
|
|
158
|
+
* - Uses SHA-256 for cryptographic strength
|
|
159
|
+
* - Includes source location for uniqueness
|
|
160
|
+
* - Build ID ensures different builds have different tokens
|
|
161
|
+
* - Base62 encoding for URL safety
|
|
162
|
+
*
|
|
163
|
+
* # Examples
|
|
164
|
+
*
|
|
165
|
+
* ```
|
|
166
|
+
* use csszyx_core::token::generate_token;
|
|
167
|
+
*
|
|
168
|
+
* let token = generate_token(
|
|
169
|
+
* "DataTable",
|
|
170
|
+
* "/src/components/DataTable.tsx",
|
|
171
|
+
* 42,
|
|
172
|
+
* 8,
|
|
173
|
+
* "csr",
|
|
174
|
+
* "abc123def456"
|
|
175
|
+
* );
|
|
176
|
+
*
|
|
177
|
+
* assert_eq!(token.len(), 12);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export function generate_token(component: string, path: string, line: number, column: number, mode: string, build_id: string): string;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Initializes the WASM module.
|
|
184
|
+
*
|
|
185
|
+
* Should be called once before using any functions.
|
|
186
|
+
*
|
|
187
|
+
* # Examples
|
|
188
|
+
*
|
|
189
|
+
* ```javascript
|
|
190
|
+
* import init, { encode } from 'csszyx-core';
|
|
191
|
+
*
|
|
192
|
+
* await init();
|
|
193
|
+
* const id = encode(42);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export function init(): void;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Transforms a csszyx sz object into a Tailwind CSS className string in Rust for maximum performance.
|
|
200
|
+
*
|
|
201
|
+
* Phase 3 Enhancements:
|
|
202
|
+
* - Handles nested variants (hover, focus, md, etc.)
|
|
203
|
+
* - Handles negative values (m: -4 -> -m-4)
|
|
204
|
+
* - Handles boolean flags
|
|
205
|
+
*/
|
|
206
|
+
export function transform_sz(val: any): string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* WASM-exposed checksum verification.
|
|
210
|
+
*
|
|
211
|
+
* # Arguments
|
|
212
|
+
*
|
|
213
|
+
* * `map` - JavaScript object representing the mangle map
|
|
214
|
+
* * `expected_checksum` - The expected checksum string
|
|
215
|
+
*
|
|
216
|
+
* # Returns
|
|
217
|
+
*
|
|
218
|
+
* `true` if checksum matches, `false` otherwise
|
|
219
|
+
*/
|
|
220
|
+
export function verify_mangle_checksum(map: any, expected_checksum: string): boolean;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Verifies a token against component information.
|
|
224
|
+
*
|
|
225
|
+
* # Arguments
|
|
226
|
+
*
|
|
227
|
+
* * `token` - Token to verify
|
|
228
|
+
* * `component` - Component name
|
|
229
|
+
* * `path` - File path
|
|
230
|
+
* * `line` - Line number
|
|
231
|
+
* * `column` - Column number
|
|
232
|
+
* * `mode` - Recovery mode
|
|
233
|
+
* * `build_id` - Build identifier
|
|
234
|
+
*
|
|
235
|
+
* # Returns
|
|
236
|
+
*
|
|
237
|
+
* `true` if token matches, `false` otherwise
|
|
238
|
+
*/
|
|
239
|
+
export function verify_token(token: string, component: string, path: string, line: number, column: number, mode: string, build_id: string): boolean;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Gets the version of csszyx-core.
|
|
243
|
+
*
|
|
244
|
+
* # Returns
|
|
245
|
+
*
|
|
246
|
+
* Version string
|
|
247
|
+
*/
|
|
248
|
+
export function version(): string;
|