@csszyx/runtime 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 +258 -0
- package/dist/index.cjs +526 -0
- package/dist/index.d.cts +695 -0
- package/dist/index.d.ts +695 -0
- package/dist/index.js +463 -0
- package/dist/lite.cjs +75 -0
- package/dist/lite.d.cts +64 -0
- package/dist/lite.d.ts +64 -0
- package/dist/lite.js +47 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
// src/verify.ts
|
|
2
|
+
function verifyRecoveryToken(element, manifest) {
|
|
3
|
+
const token = element.getAttribute("data-sz-recovery-token");
|
|
4
|
+
if (!token) {
|
|
5
|
+
return {
|
|
6
|
+
valid: false,
|
|
7
|
+
error: "No recovery token found on element"
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const tokenData = manifest.tokens[token];
|
|
11
|
+
if (!tokenData) {
|
|
12
|
+
return {
|
|
13
|
+
valid: false,
|
|
14
|
+
error: `Token not found in manifest: ${token}`
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const szRecover = element.getAttribute("szRecover");
|
|
18
|
+
if (szRecover !== tokenData.mode) {
|
|
19
|
+
return {
|
|
20
|
+
valid: false,
|
|
21
|
+
error: `szRecover attribute (${szRecover}) does not match token mode (${tokenData.mode})`
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
valid: true,
|
|
26
|
+
tokenData
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function loadManifestFromDOM() {
|
|
30
|
+
if (typeof document === "undefined") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const scriptElement = document.getElementById("__SZ_RECOVERY_MANIFEST__");
|
|
34
|
+
if (!scriptElement) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const content = scriptElement.textContent || "";
|
|
39
|
+
return JSON.parse(content);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("Failed to parse recovery manifest:", error);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isValidManifest(manifest) {
|
|
46
|
+
if (!manifest || typeof manifest !== "object") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const m = manifest;
|
|
50
|
+
return typeof m.buildId === "string" && typeof m.checksum === "string" && typeof m.tokens === "object" && m.tokens !== null;
|
|
51
|
+
}
|
|
52
|
+
function verifyAllTokens(root, manifest) {
|
|
53
|
+
const elements = root.querySelectorAll("[data-sz-recovery-token]");
|
|
54
|
+
const results = [];
|
|
55
|
+
for (let i = 0; i < elements.length; i++) {
|
|
56
|
+
const element = elements[i];
|
|
57
|
+
const result = verifyRecoveryToken(element, manifest);
|
|
58
|
+
results.push(result);
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
function hasRecoveryToken(element) {
|
|
63
|
+
return element.hasAttribute("data-sz-recovery-token");
|
|
64
|
+
}
|
|
65
|
+
function getRecoveryMode(element) {
|
|
66
|
+
const szRecover = element.getAttribute("szRecover");
|
|
67
|
+
if (szRecover === "csr" || szRecover === "dev-only") {
|
|
68
|
+
return szRecover;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/hydration.ts
|
|
74
|
+
var state = {
|
|
75
|
+
errors: [],
|
|
76
|
+
abortedSubtrees: /* @__PURE__ */ new Set(),
|
|
77
|
+
recoveryAllowed: false
|
|
78
|
+
};
|
|
79
|
+
function enableCSRRecovery() {
|
|
80
|
+
state.recoveryAllowed = true;
|
|
81
|
+
if (typeof window !== "undefined") {
|
|
82
|
+
window.__SZ_ALLOW_CSR_RECOVERY__ = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function disableCSRRecovery() {
|
|
86
|
+
state.recoveryAllowed = false;
|
|
87
|
+
if (typeof window !== "undefined") {
|
|
88
|
+
window.__SZ_ALLOW_CSR_RECOVERY__ = false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function isCSRRecoveryAllowed() {
|
|
92
|
+
return state.recoveryAllowed;
|
|
93
|
+
}
|
|
94
|
+
function loadMangleMapFromDOM() {
|
|
95
|
+
if (typeof document === "undefined") {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const scriptElement = document.getElementById("__SZ_MANGLE_MAP__");
|
|
99
|
+
if (!scriptElement) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const content = scriptElement.textContent || "";
|
|
104
|
+
return JSON.parse(content);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("Failed to parse mangle map:", error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function verifyMangleChecksum(expectedChecksum) {
|
|
111
|
+
if (typeof document === "undefined") {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const htmlElement = document.documentElement;
|
|
115
|
+
const actualChecksum = htmlElement.getAttribute("data-sz-checksum");
|
|
116
|
+
return actualChecksum === expectedChecksum;
|
|
117
|
+
}
|
|
118
|
+
function verifyMangleMapIntegrity() {
|
|
119
|
+
if (typeof document === "undefined") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const htmlElement = document.documentElement;
|
|
123
|
+
const checksum = htmlElement.getAttribute("data-sz-checksum");
|
|
124
|
+
if (!checksum) {
|
|
125
|
+
console.warn("[csszyx] No checksum found in HTML");
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const scriptElement = document.getElementById("__CSSZYX_MANGLE_MAP__");
|
|
129
|
+
if (!scriptElement) {
|
|
130
|
+
console.warn("[csszyx] Mangle map script not found");
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const mangleMap = JSON.parse(scriptElement.textContent || "{}");
|
|
135
|
+
if (typeof window !== "undefined" && "verify_mangle_checksum" in window) {
|
|
136
|
+
const isValid = window.verify_mangle_checksum(mangleMap, checksum);
|
|
137
|
+
return isValid;
|
|
138
|
+
}
|
|
139
|
+
console.warn("[csszyx] Rust core not available, using fallback verification");
|
|
140
|
+
return true;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("[csszyx] Failed to verify mangle map:", error);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function abortHydration(element, error) {
|
|
147
|
+
state.abortedSubtrees.add(element);
|
|
148
|
+
console.error(
|
|
149
|
+
`[csszyx] Hydration aborted at ${element.tagName}:`,
|
|
150
|
+
error.message
|
|
151
|
+
);
|
|
152
|
+
element.setAttribute("data-sz-hydration-aborted", error.timestamp.toString());
|
|
153
|
+
element.setAttribute("data-sz-abort-reason", error.type);
|
|
154
|
+
element.setAttribute("data-sz-interactive", "false");
|
|
155
|
+
state.errors.push({
|
|
156
|
+
...error,
|
|
157
|
+
element
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function isHydrationAborted(element) {
|
|
161
|
+
return state.abortedSubtrees.has(element) || element.hasAttribute("data-sz-hydration-aborted");
|
|
162
|
+
}
|
|
163
|
+
function guardHydration(manifest) {
|
|
164
|
+
if (typeof document === "undefined") {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (!verifyMangleChecksum(manifest.checksum)) {
|
|
168
|
+
const error = {
|
|
169
|
+
type: "checksum_mismatch",
|
|
170
|
+
message: "Mangle map checksum mismatch detected",
|
|
171
|
+
timestamp: Date.now()
|
|
172
|
+
};
|
|
173
|
+
abortHydration(document.documentElement, error);
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
function attemptCSRRecovery(element) {
|
|
179
|
+
if (!state.recoveryAllowed) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (!hasRecoveryToken(element)) {
|
|
183
|
+
console.warn("[csszyx] CSR recovery requires explicit szRecover directive");
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const mode = getRecoveryMode(element);
|
|
187
|
+
if (mode === "dev-only" && process.env.NODE_ENV === "production") {
|
|
188
|
+
console.warn('[csszyx] szRecover="dev-only" is disabled in production');
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
console.warn(
|
|
192
|
+
"[csszyx] Hydration mismatch recovered via CSR. Fix root cause before production."
|
|
193
|
+
);
|
|
194
|
+
element.removeAttribute("data-sz-hydration-aborted");
|
|
195
|
+
element.removeAttribute("data-sz-abort-reason");
|
|
196
|
+
element.removeAttribute("data-sz-interactive");
|
|
197
|
+
state.abortedSubtrees.delete(element);
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
function getHydrationErrors() {
|
|
201
|
+
return [...state.errors];
|
|
202
|
+
}
|
|
203
|
+
function clearHydrationErrors() {
|
|
204
|
+
state.errors = [];
|
|
205
|
+
state.abortedSubtrees.clear();
|
|
206
|
+
}
|
|
207
|
+
function getAbortedSubtreeCount() {
|
|
208
|
+
return state.abortedSubtrees.size;
|
|
209
|
+
}
|
|
210
|
+
function isSSREnvironment() {
|
|
211
|
+
return typeof window === "undefined";
|
|
212
|
+
}
|
|
213
|
+
function isHydrating() {
|
|
214
|
+
if (typeof window === "undefined") {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (window.__SZ_HYDRATING__ !== void 0) {
|
|
218
|
+
return window.__SZ_HYDRATING__;
|
|
219
|
+
}
|
|
220
|
+
if (window.__NEXT_DATA__ || window.__REMIX_CONTEXT__) {
|
|
221
|
+
return document.documentElement.hasAttribute("data-sz-checksum");
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
function getSSRContext() {
|
|
226
|
+
if (typeof document === "undefined") {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const htmlElement = document.documentElement;
|
|
230
|
+
const checksum = htmlElement.getAttribute("data-sz-checksum");
|
|
231
|
+
const buildId = htmlElement.getAttribute("data-sz-build-id");
|
|
232
|
+
if (!checksum || !buildId) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const timestampAttr = htmlElement.getAttribute("data-sz-timestamp");
|
|
236
|
+
const timestamp = timestampAttr ? parseInt(timestampAttr, 10) : 0;
|
|
237
|
+
const hasRecoveryTokens = document.querySelector("[data-sz-recovery-token]") !== null;
|
|
238
|
+
return {
|
|
239
|
+
buildId,
|
|
240
|
+
checksum,
|
|
241
|
+
timestamp,
|
|
242
|
+
hasRecoveryTokens
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function validateHydrationClass(className, expectedClassName) {
|
|
246
|
+
const normalize = (s) => s.split(/\s+/).filter(Boolean).sort().join(" ");
|
|
247
|
+
return normalize(className) === normalize(expectedClassName);
|
|
248
|
+
}
|
|
249
|
+
function startHydration() {
|
|
250
|
+
if (typeof window !== "undefined") {
|
|
251
|
+
window.__SZ_HYDRATING__ = true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function endHydration() {
|
|
255
|
+
if (typeof window !== "undefined") {
|
|
256
|
+
window.__SZ_HYDRATING__ = false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/concatenate.ts
|
|
261
|
+
import { transform } from "@csszyx/compiler";
|
|
262
|
+
function _sz(...classes) {
|
|
263
|
+
if (classes.length === 1) {
|
|
264
|
+
const cls = classes[0];
|
|
265
|
+
if (typeof cls === "string") {
|
|
266
|
+
return cls;
|
|
267
|
+
}
|
|
268
|
+
if (!cls) {
|
|
269
|
+
return "";
|
|
270
|
+
}
|
|
271
|
+
const res = transform(cls);
|
|
272
|
+
return typeof res === "string" ? res : res.className;
|
|
273
|
+
}
|
|
274
|
+
let result = "";
|
|
275
|
+
let needsSpace = false;
|
|
276
|
+
for (let i = 0; i < classes.length; i++) {
|
|
277
|
+
const cls = classes[i];
|
|
278
|
+
if (!cls) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const res = typeof cls === "string" ? cls : transform(cls);
|
|
282
|
+
const str = typeof res === "string" ? res : res.className;
|
|
283
|
+
if (!str) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (needsSpace) {
|
|
287
|
+
result += " ";
|
|
288
|
+
}
|
|
289
|
+
result += str;
|
|
290
|
+
needsSpace = true;
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
function _szIf(condition, truthyValue, falsyValue) {
|
|
295
|
+
const value = condition ? truthyValue : falsyValue;
|
|
296
|
+
if (!value) {
|
|
297
|
+
return "";
|
|
298
|
+
}
|
|
299
|
+
if (typeof value === "string") {
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
const res = transform(value);
|
|
303
|
+
return typeof res === "string" ? res : res.className;
|
|
304
|
+
}
|
|
305
|
+
function _szSwitch(conditions, defaultValue = "") {
|
|
306
|
+
for (let i = 0; i < conditions.length; i++) {
|
|
307
|
+
const [condition, value] = conditions[i];
|
|
308
|
+
if (condition) {
|
|
309
|
+
if (!value) {
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
if (typeof value === "string") {
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
const res2 = transform(value);
|
|
316
|
+
return typeof res2 === "string" ? res2 : res2.className;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (!defaultValue) {
|
|
320
|
+
return "";
|
|
321
|
+
}
|
|
322
|
+
if (typeof defaultValue === "string") {
|
|
323
|
+
return defaultValue;
|
|
324
|
+
}
|
|
325
|
+
const res = transform(defaultValue);
|
|
326
|
+
return typeof res === "string" ? res : res.className;
|
|
327
|
+
}
|
|
328
|
+
function _szMerge(...classes) {
|
|
329
|
+
const seen = /* @__PURE__ */ new Set();
|
|
330
|
+
const result = [];
|
|
331
|
+
for (let i = 0; i < classes.length; i++) {
|
|
332
|
+
const cls = classes[i];
|
|
333
|
+
if (!cls) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const res = typeof cls === "string" ? cls : transform(cls);
|
|
337
|
+
const str = typeof res === "string" ? res : res.className;
|
|
338
|
+
if (!str) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const parts = str.split(/\s+/);
|
|
342
|
+
for (let j = 0; j < parts.length; j++) {
|
|
343
|
+
const part = parts[j];
|
|
344
|
+
if (part && !seen.has(part)) {
|
|
345
|
+
seen.add(part);
|
|
346
|
+
result.push(part);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return result.join(" ");
|
|
351
|
+
}
|
|
352
|
+
function _sz2(a, b) {
|
|
353
|
+
if (!a) {
|
|
354
|
+
return b || "";
|
|
355
|
+
}
|
|
356
|
+
if (!b) {
|
|
357
|
+
return a;
|
|
358
|
+
}
|
|
359
|
+
return a + " " + b;
|
|
360
|
+
}
|
|
361
|
+
function _sz3(a, b, c) {
|
|
362
|
+
let result = "";
|
|
363
|
+
let needsSpace = false;
|
|
364
|
+
if (a) {
|
|
365
|
+
result = a;
|
|
366
|
+
needsSpace = true;
|
|
367
|
+
}
|
|
368
|
+
if (b) {
|
|
369
|
+
if (needsSpace) {
|
|
370
|
+
result += " ";
|
|
371
|
+
}
|
|
372
|
+
result += b;
|
|
373
|
+
needsSpace = true;
|
|
374
|
+
}
|
|
375
|
+
if (c) {
|
|
376
|
+
if (needsSpace) {
|
|
377
|
+
result += " ";
|
|
378
|
+
}
|
|
379
|
+
result += c;
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/index.ts
|
|
385
|
+
var VERSION = "0.0.0";
|
|
386
|
+
var DEFAULT_RUNTIME_CONFIG = {
|
|
387
|
+
development: false,
|
|
388
|
+
allowCSRRecovery: false,
|
|
389
|
+
strictHydration: true,
|
|
390
|
+
debug: false
|
|
391
|
+
};
|
|
392
|
+
var runtimeState = {
|
|
393
|
+
config: { ...DEFAULT_RUNTIME_CONFIG },
|
|
394
|
+
initialized: false
|
|
395
|
+
};
|
|
396
|
+
function initRuntime(config = {}) {
|
|
397
|
+
if (runtimeState.initialized) {
|
|
398
|
+
if (runtimeState.config.debug) {
|
|
399
|
+
console.warn("[csszyx] Runtime already initialized");
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
runtimeState.config = {
|
|
404
|
+
...DEFAULT_RUNTIME_CONFIG,
|
|
405
|
+
...config
|
|
406
|
+
};
|
|
407
|
+
if (runtimeState.config.allowCSRRecovery) {
|
|
408
|
+
enableCSRRecovery();
|
|
409
|
+
}
|
|
410
|
+
if (runtimeState.config.debug) {
|
|
411
|
+
console.log("[csszyx] Runtime initialized", runtimeState.config);
|
|
412
|
+
}
|
|
413
|
+
runtimeState.initialized = true;
|
|
414
|
+
}
|
|
415
|
+
function getRuntimeConfig() {
|
|
416
|
+
return { ...runtimeState.config };
|
|
417
|
+
}
|
|
418
|
+
function isRuntimeInitialized() {
|
|
419
|
+
return runtimeState.initialized;
|
|
420
|
+
}
|
|
421
|
+
function resetRuntime() {
|
|
422
|
+
runtimeState.config = { ...DEFAULT_RUNTIME_CONFIG };
|
|
423
|
+
runtimeState.initialized = false;
|
|
424
|
+
}
|
|
425
|
+
export {
|
|
426
|
+
DEFAULT_RUNTIME_CONFIG,
|
|
427
|
+
VERSION,
|
|
428
|
+
_sz,
|
|
429
|
+
_sz2,
|
|
430
|
+
_sz3,
|
|
431
|
+
_szIf,
|
|
432
|
+
_szMerge,
|
|
433
|
+
_szSwitch,
|
|
434
|
+
abortHydration,
|
|
435
|
+
attemptCSRRecovery,
|
|
436
|
+
clearHydrationErrors,
|
|
437
|
+
disableCSRRecovery,
|
|
438
|
+
enableCSRRecovery,
|
|
439
|
+
endHydration,
|
|
440
|
+
getAbortedSubtreeCount,
|
|
441
|
+
getHydrationErrors,
|
|
442
|
+
getRecoveryMode,
|
|
443
|
+
getRuntimeConfig,
|
|
444
|
+
getSSRContext,
|
|
445
|
+
guardHydration,
|
|
446
|
+
hasRecoveryToken,
|
|
447
|
+
initRuntime,
|
|
448
|
+
isCSRRecoveryAllowed,
|
|
449
|
+
isHydrating,
|
|
450
|
+
isHydrationAborted,
|
|
451
|
+
isRuntimeInitialized,
|
|
452
|
+
isSSREnvironment,
|
|
453
|
+
isValidManifest,
|
|
454
|
+
loadMangleMapFromDOM,
|
|
455
|
+
loadManifestFromDOM,
|
|
456
|
+
resetRuntime,
|
|
457
|
+
startHydration,
|
|
458
|
+
validateHydrationClass,
|
|
459
|
+
verifyAllTokens,
|
|
460
|
+
verifyMangleChecksum,
|
|
461
|
+
verifyMangleMapIntegrity,
|
|
462
|
+
verifyRecoveryToken
|
|
463
|
+
};
|
package/dist/lite.cjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lite.ts
|
|
21
|
+
var lite_exports = {};
|
|
22
|
+
__export(lite_exports, {
|
|
23
|
+
__szColorVar: () => __szColorVar,
|
|
24
|
+
_sz: () => _sz,
|
|
25
|
+
_sz2: () => _sz2,
|
|
26
|
+
_szIf: () => _szIf
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(lite_exports);
|
|
29
|
+
function _sz(...classes) {
|
|
30
|
+
if (classes.length === 1) {
|
|
31
|
+
return classes[0] || "";
|
|
32
|
+
}
|
|
33
|
+
let result = "";
|
|
34
|
+
let needsSpace = false;
|
|
35
|
+
for (let i = 0; i < classes.length; i++) {
|
|
36
|
+
const cls = classes[i];
|
|
37
|
+
if (!cls) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (needsSpace) {
|
|
41
|
+
result += " ";
|
|
42
|
+
}
|
|
43
|
+
result += cls;
|
|
44
|
+
needsSpace = true;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function _szIf(condition, truthyValue, falsyValue) {
|
|
49
|
+
return (condition ? truthyValue : falsyValue) || "";
|
|
50
|
+
}
|
|
51
|
+
function _sz2(a, b) {
|
|
52
|
+
if (!a) {
|
|
53
|
+
return b || "";
|
|
54
|
+
}
|
|
55
|
+
if (!b) {
|
|
56
|
+
return a;
|
|
57
|
+
}
|
|
58
|
+
return a + " " + b;
|
|
59
|
+
}
|
|
60
|
+
function __szColorVar(v) {
|
|
61
|
+
if (v.startsWith("#") || v.startsWith("rgb") || v.startsWith("hsl") || v.startsWith("oklch")) {
|
|
62
|
+
return v;
|
|
63
|
+
}
|
|
64
|
+
if (v.startsWith("--")) {
|
|
65
|
+
return `var(${v})`;
|
|
66
|
+
}
|
|
67
|
+
return `var(--color-${v})`;
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
__szColorVar,
|
|
72
|
+
_sz,
|
|
73
|
+
_sz2,
|
|
74
|
+
_szIf
|
|
75
|
+
});
|
package/dist/lite.d.cts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @csszyx/runtime/lite - Ultra-minimal runtime helpers.
|
|
3
|
+
*
|
|
4
|
+
* This is the lightweight entry point for csszyx runtime, containing only
|
|
5
|
+
* the essential helpers needed for className composition. All sz objects
|
|
6
|
+
* are pre-compiled to strings at build time, so this module is string-only.
|
|
7
|
+
*
|
|
8
|
+
* Bundle size target: < 500 bytes (minified + gzipped)
|
|
9
|
+
*
|
|
10
|
+
* @module @csszyx/runtime/lite
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Type for sz input - string-only (objects are pre-compiled at build time).
|
|
14
|
+
*/
|
|
15
|
+
type SzInput = string | null | undefined | false;
|
|
16
|
+
/**
|
|
17
|
+
* Zero-overhead className passthrough/concatenation.
|
|
18
|
+
*
|
|
19
|
+
* @param {...SzInput[]} classes - Class names to concatenate
|
|
20
|
+
* @returns {string} Combined className string
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* _sz('p-4 bg-red-500') // passthrough
|
|
25
|
+
* _sz('base', isActive && 'active') // conditional
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function _sz(...classes: SzInput[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* Conditional className helper.
|
|
31
|
+
*
|
|
32
|
+
* @param {boolean} condition - Condition to evaluate
|
|
33
|
+
* @param {SzInput} truthyValue - Value when true
|
|
34
|
+
* @param {SzInput} falsyValue - Value when false
|
|
35
|
+
* @returns {string} Resolved className
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* _szIf(isActive, 'bg-green-500', 'bg-gray-500')
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: SzInput): string;
|
|
43
|
+
/**
|
|
44
|
+
* Two-argument optimized concatenation.
|
|
45
|
+
* @param a - first class string
|
|
46
|
+
* @param b - second class string
|
|
47
|
+
* @returns concatenated class string
|
|
48
|
+
*/
|
|
49
|
+
declare function _sz2(a: string, b: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a dynamic color value to a CSS-compatible string.
|
|
52
|
+
* Maps Tailwind color names to CSS custom properties, passes through raw CSS values.
|
|
53
|
+
*
|
|
54
|
+
* @param v - Color value (Tailwind name, CSS color, or CSS variable)
|
|
55
|
+
* @returns CSS-compatible color string
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* __szColorVar('blue-500') // → 'var(--color-blue-500)'
|
|
59
|
+
* __szColorVar('#ff0') // → '#ff0'
|
|
60
|
+
* __szColorVar('--my-var') // → 'var(--my-var)'
|
|
61
|
+
*/
|
|
62
|
+
declare function __szColorVar(v: string): string;
|
|
63
|
+
|
|
64
|
+
export { type SzInput, __szColorVar, _sz, _sz2, _szIf };
|
package/dist/lite.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @csszyx/runtime/lite - Ultra-minimal runtime helpers.
|
|
3
|
+
*
|
|
4
|
+
* This is the lightweight entry point for csszyx runtime, containing only
|
|
5
|
+
* the essential helpers needed for className composition. All sz objects
|
|
6
|
+
* are pre-compiled to strings at build time, so this module is string-only.
|
|
7
|
+
*
|
|
8
|
+
* Bundle size target: < 500 bytes (minified + gzipped)
|
|
9
|
+
*
|
|
10
|
+
* @module @csszyx/runtime/lite
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Type for sz input - string-only (objects are pre-compiled at build time).
|
|
14
|
+
*/
|
|
15
|
+
type SzInput = string | null | undefined | false;
|
|
16
|
+
/**
|
|
17
|
+
* Zero-overhead className passthrough/concatenation.
|
|
18
|
+
*
|
|
19
|
+
* @param {...SzInput[]} classes - Class names to concatenate
|
|
20
|
+
* @returns {string} Combined className string
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* _sz('p-4 bg-red-500') // passthrough
|
|
25
|
+
* _sz('base', isActive && 'active') // conditional
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function _sz(...classes: SzInput[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* Conditional className helper.
|
|
31
|
+
*
|
|
32
|
+
* @param {boolean} condition - Condition to evaluate
|
|
33
|
+
* @param {SzInput} truthyValue - Value when true
|
|
34
|
+
* @param {SzInput} falsyValue - Value when false
|
|
35
|
+
* @returns {string} Resolved className
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* _szIf(isActive, 'bg-green-500', 'bg-gray-500')
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: SzInput): string;
|
|
43
|
+
/**
|
|
44
|
+
* Two-argument optimized concatenation.
|
|
45
|
+
* @param a - first class string
|
|
46
|
+
* @param b - second class string
|
|
47
|
+
* @returns concatenated class string
|
|
48
|
+
*/
|
|
49
|
+
declare function _sz2(a: string, b: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a dynamic color value to a CSS-compatible string.
|
|
52
|
+
* Maps Tailwind color names to CSS custom properties, passes through raw CSS values.
|
|
53
|
+
*
|
|
54
|
+
* @param v - Color value (Tailwind name, CSS color, or CSS variable)
|
|
55
|
+
* @returns CSS-compatible color string
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* __szColorVar('blue-500') // → 'var(--color-blue-500)'
|
|
59
|
+
* __szColorVar('#ff0') // → '#ff0'
|
|
60
|
+
* __szColorVar('--my-var') // → 'var(--my-var)'
|
|
61
|
+
*/
|
|
62
|
+
declare function __szColorVar(v: string): string;
|
|
63
|
+
|
|
64
|
+
export { type SzInput, __szColorVar, _sz, _sz2, _szIf };
|
package/dist/lite.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/lite.ts
|
|
2
|
+
function _sz(...classes) {
|
|
3
|
+
if (classes.length === 1) {
|
|
4
|
+
return classes[0] || "";
|
|
5
|
+
}
|
|
6
|
+
let result = "";
|
|
7
|
+
let needsSpace = false;
|
|
8
|
+
for (let i = 0; i < classes.length; i++) {
|
|
9
|
+
const cls = classes[i];
|
|
10
|
+
if (!cls) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (needsSpace) {
|
|
14
|
+
result += " ";
|
|
15
|
+
}
|
|
16
|
+
result += cls;
|
|
17
|
+
needsSpace = true;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function _szIf(condition, truthyValue, falsyValue) {
|
|
22
|
+
return (condition ? truthyValue : falsyValue) || "";
|
|
23
|
+
}
|
|
24
|
+
function _sz2(a, b) {
|
|
25
|
+
if (!a) {
|
|
26
|
+
return b || "";
|
|
27
|
+
}
|
|
28
|
+
if (!b) {
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
return a + " " + b;
|
|
32
|
+
}
|
|
33
|
+
function __szColorVar(v) {
|
|
34
|
+
if (v.startsWith("#") || v.startsWith("rgb") || v.startsWith("hsl") || v.startsWith("oklch")) {
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
if (v.startsWith("--")) {
|
|
38
|
+
return `var(${v})`;
|
|
39
|
+
}
|
|
40
|
+
return `var(--color-${v})`;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
__szColorVar,
|
|
44
|
+
_sz,
|
|
45
|
+
_sz2,
|
|
46
|
+
_szIf
|
|
47
|
+
};
|