@csszyx/runtime 0.7.0 → 0.8.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/dist/index.cjs CHANGED
@@ -1,68 +1,8 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- DEFAULT_RUNTIME_CONFIG: () => DEFAULT_RUNTIME_CONFIG,
24
- VERSION: () => VERSION,
25
- __szColorVar: () => import_color_var.__szColorVar,
26
- _sz: () => _sz,
27
- _sz2: () => _sz2,
28
- _sz3: () => _sz3,
29
- _szIf: () => _szIf,
30
- _szMerge: () => _szMerge,
31
- _szSwitch: () => _szSwitch,
32
- abortHydration: () => abortHydration,
33
- attemptCSRRecovery: () => attemptCSRRecovery,
34
- clearHydrationErrors: () => clearHydrationErrors,
35
- disableCSRRecovery: () => disableCSRRecovery,
36
- enableCSRRecovery: () => enableCSRRecovery,
37
- endHydration: () => endHydration,
38
- getAbortedSubtreeCount: () => getAbortedSubtreeCount,
39
- getHydrationErrors: () => getHydrationErrors,
40
- getRecoveryMode: () => getRecoveryMode,
41
- getRuntimeConfig: () => getRuntimeConfig,
42
- getSSRContext: () => getSSRContext,
43
- guardHydration: () => guardHydration,
44
- hasRecoveryToken: () => hasRecoveryToken,
45
- initRuntime: () => initRuntime,
46
- isCSRRecoveryAllowed: () => isCSRRecoveryAllowed,
47
- isHydrating: () => isHydrating,
48
- isHydrationAborted: () => isHydrationAborted,
49
- isRuntimeInitialized: () => isRuntimeInitialized,
50
- isSSREnvironment: () => isSSREnvironment,
51
- isValidManifest: () => isValidManifest,
52
- loadMangleMapFromDOM: () => loadMangleMapFromDOM,
53
- loadManifestFromDOM: () => loadManifestFromDOM,
54
- resetRuntime: () => resetRuntime,
55
- startHydration: () => startHydration,
56
- szv: () => szv,
57
- validateHydrationClass: () => validateHydrationClass,
58
- verifyAllTokens: () => verifyAllTokens,
59
- verifyMangleChecksum: () => verifyMangleChecksum,
60
- verifyMangleMapIntegrity: () => verifyMangleMapIntegrity,
61
- verifyRecoveryToken: () => verifyRecoveryToken
62
- });
63
- module.exports = __toCommonJS(src_exports);
3
+ const browser = require('@csszyx/compiler/browser');
4
+ const colorVar = require('@csszyx/compiler/color-var');
64
5
 
65
- // src/verify.ts
66
6
  function verifyRecoveryToken(element, manifest) {
67
7
  const token = element.getAttribute("data-sz-recovery-token");
68
8
  if (!token) {
@@ -134,8 +74,7 @@ function getRecoveryMode(element) {
134
74
  return null;
135
75
  }
136
76
 
137
- // src/hydration.ts
138
- var state = {
77
+ const state = {
139
78
  errors: [],
140
79
  abortedSubtrees: /* @__PURE__ */ new Set(),
141
80
  recoveryAllowed: false
@@ -209,10 +148,7 @@ function verifyMangleMapIntegrity() {
209
148
  }
210
149
  function abortHydration(element, error) {
211
150
  state.abortedSubtrees.add(element);
212
- console.error(
213
- `[csszyx] Hydration aborted at ${element.tagName}:`,
214
- error.message
215
- );
151
+ console.error(`[csszyx] Hydration aborted at ${element.tagName}:`, error.message);
216
152
  element.setAttribute("data-sz-hydration-aborted", error.timestamp.toString());
217
153
  element.setAttribute("data-sz-abort-reason", error.type);
218
154
  element.setAttribute("data-sz-interactive", "false");
@@ -321,8 +257,6 @@ function endHydration() {
321
257
  }
322
258
  }
323
259
 
324
- // src/concatenate.ts
325
- var import_browser = require("@csszyx/compiler/browser");
326
260
  function _sz(...classes) {
327
261
  if (classes.length === 1) {
328
262
  const cls = classes[0];
@@ -332,7 +266,7 @@ function _sz(...classes) {
332
266
  if (!cls) {
333
267
  return "";
334
268
  }
335
- const res = (0, import_browser.transform)(cls);
269
+ const res = browser.transform(cls);
336
270
  return typeof res === "string" ? res : res.className;
337
271
  }
338
272
  let result = "";
@@ -342,7 +276,7 @@ function _sz(...classes) {
342
276
  if (!cls) {
343
277
  continue;
344
278
  }
345
- const res = typeof cls === "string" ? cls : (0, import_browser.transform)(cls);
279
+ const res = typeof cls === "string" ? cls : browser.transform(cls);
346
280
  const str = typeof res === "string" ? res : res.className;
347
281
  if (!str) {
348
282
  continue;
@@ -363,7 +297,7 @@ function _szIf(condition, truthyValue, falsyValue) {
363
297
  if (typeof value === "string") {
364
298
  return value;
365
299
  }
366
- const res = (0, import_browser.transform)(value);
300
+ const res = browser.transform(value);
367
301
  return typeof res === "string" ? res : res.className;
368
302
  }
369
303
  function _szSwitch(conditions, defaultValue = "") {
@@ -376,7 +310,7 @@ function _szSwitch(conditions, defaultValue = "") {
376
310
  if (typeof value === "string") {
377
311
  return value;
378
312
  }
379
- const res2 = (0, import_browser.transform)(value);
313
+ const res2 = browser.transform(value);
380
314
  return typeof res2 === "string" ? res2 : res2.className;
381
315
  }
382
316
  }
@@ -386,7 +320,7 @@ function _szSwitch(conditions, defaultValue = "") {
386
320
  if (typeof defaultValue === "string") {
387
321
  return defaultValue;
388
322
  }
389
- const res = (0, import_browser.transform)(defaultValue);
323
+ const res = browser.transform(defaultValue);
390
324
  return typeof res === "string" ? res : res.className;
391
325
  }
392
326
  function _szMerge(...classes) {
@@ -397,7 +331,7 @@ function _szMerge(...classes) {
397
331
  if (!cls) {
398
332
  continue;
399
333
  }
400
- const res = typeof cls === "string" ? cls : (0, import_browser.transform)(cls);
334
+ const res = typeof cls === "string" ? cls : browser.transform(cls);
401
335
  const str = typeof res === "string" ? res : res.className;
402
336
  if (!str) {
403
337
  continue;
@@ -420,7 +354,7 @@ function _sz2(a, b) {
420
354
  if (!b) {
421
355
  return a;
422
356
  }
423
- return a + " " + b;
357
+ return `${a} ${b}`;
424
358
  }
425
359
  function _sz3(a, b, c) {
426
360
  let result = "";
@@ -445,7 +379,6 @@ function _sz3(a, b, c) {
445
379
  return result;
446
380
  }
447
381
 
448
- // src/variants.ts
449
382
  function deepMerge(target, source) {
450
383
  const result = { ...target };
451
384
  for (const key of Object.keys(source)) {
@@ -485,18 +418,14 @@ function szv(config) {
485
418
  };
486
419
  }
487
420
 
488
- // src/lite.ts
489
- var import_color_var = require("@csszyx/compiler/color-var");
490
-
491
- // src/index.ts
492
- var VERSION = "0.0.0";
493
- var DEFAULT_RUNTIME_CONFIG = {
421
+ const VERSION = "0.0.0";
422
+ const DEFAULT_RUNTIME_CONFIG = {
494
423
  development: false,
495
424
  allowCSRRecovery: false,
496
425
  strictHydration: true,
497
426
  debug: false
498
427
  };
499
- var runtimeState = {
428
+ const runtimeState = {
500
429
  config: { ...DEFAULT_RUNTIME_CONFIG },
501
430
  initialized: false
502
431
  };
@@ -529,45 +458,43 @@ function resetRuntime() {
529
458
  runtimeState.config = { ...DEFAULT_RUNTIME_CONFIG };
530
459
  runtimeState.initialized = false;
531
460
  }
532
- // Annotate the CommonJS export names for ESM import in node:
533
- 0 && (module.exports = {
534
- DEFAULT_RUNTIME_CONFIG,
535
- VERSION,
536
- __szColorVar,
537
- _sz,
538
- _sz2,
539
- _sz3,
540
- _szIf,
541
- _szMerge,
542
- _szSwitch,
543
- abortHydration,
544
- attemptCSRRecovery,
545
- clearHydrationErrors,
546
- disableCSRRecovery,
547
- enableCSRRecovery,
548
- endHydration,
549
- getAbortedSubtreeCount,
550
- getHydrationErrors,
551
- getRecoveryMode,
552
- getRuntimeConfig,
553
- getSSRContext,
554
- guardHydration,
555
- hasRecoveryToken,
556
- initRuntime,
557
- isCSRRecoveryAllowed,
558
- isHydrating,
559
- isHydrationAborted,
560
- isRuntimeInitialized,
561
- isSSREnvironment,
562
- isValidManifest,
563
- loadMangleMapFromDOM,
564
- loadManifestFromDOM,
565
- resetRuntime,
566
- startHydration,
567
- szv,
568
- validateHydrationClass,
569
- verifyAllTokens,
570
- verifyMangleChecksum,
571
- verifyMangleMapIntegrity,
572
- verifyRecoveryToken
573
- });
461
+
462
+ exports.__szColorVar = colorVar.__szColorVar;
463
+ exports.DEFAULT_RUNTIME_CONFIG = DEFAULT_RUNTIME_CONFIG;
464
+ exports.VERSION = VERSION;
465
+ exports._sz = _sz;
466
+ exports._sz2 = _sz2;
467
+ exports._sz3 = _sz3;
468
+ exports._szIf = _szIf;
469
+ exports._szMerge = _szMerge;
470
+ exports._szSwitch = _szSwitch;
471
+ exports.abortHydration = abortHydration;
472
+ exports.attemptCSRRecovery = attemptCSRRecovery;
473
+ exports.clearHydrationErrors = clearHydrationErrors;
474
+ exports.disableCSRRecovery = disableCSRRecovery;
475
+ exports.enableCSRRecovery = enableCSRRecovery;
476
+ exports.endHydration = endHydration;
477
+ exports.getAbortedSubtreeCount = getAbortedSubtreeCount;
478
+ exports.getHydrationErrors = getHydrationErrors;
479
+ exports.getRecoveryMode = getRecoveryMode;
480
+ exports.getRuntimeConfig = getRuntimeConfig;
481
+ exports.getSSRContext = getSSRContext;
482
+ exports.guardHydration = guardHydration;
483
+ exports.hasRecoveryToken = hasRecoveryToken;
484
+ exports.initRuntime = initRuntime;
485
+ exports.isCSRRecoveryAllowed = isCSRRecoveryAllowed;
486
+ exports.isHydrating = isHydrating;
487
+ exports.isHydrationAborted = isHydrationAborted;
488
+ exports.isRuntimeInitialized = isRuntimeInitialized;
489
+ exports.isSSREnvironment = isSSREnvironment;
490
+ exports.isValidManifest = isValidManifest;
491
+ exports.loadMangleMapFromDOM = loadMangleMapFromDOM;
492
+ exports.loadManifestFromDOM = loadManifestFromDOM;
493
+ exports.resetRuntime = resetRuntime;
494
+ exports.startHydration = startHydration;
495
+ exports.szv = szv;
496
+ exports.validateHydrationClass = validateHydrationClass;
497
+ exports.verifyAllTokens = verifyAllTokens;
498
+ exports.verifyMangleChecksum = verifyMangleChecksum;
499
+ exports.verifyMangleMapIntegrity = verifyMangleMapIntegrity;
500
+ exports.verifyRecoveryToken = verifyRecoveryToken;
package/dist/index.d.cts CHANGED
@@ -135,81 +135,6 @@ declare function _sz2(a: string, b: string): string;
135
135
  */
136
136
  declare function _sz3(a: string, b: string, c: string): string;
137
137
 
138
- /**
139
- * szv() — variant-based sz object factory.
140
- *
141
- * CVA-equivalent but returns sz objects instead of className strings,
142
- * keeping DX consistent with the sz prop throughout. Use with the sz prop
143
- * (build-time transform) or with sz() from @csszyx/dynamic (runtime injection).
144
- *
145
- * @module @csszyx/runtime/variants
146
- */
147
-
148
- /**
149
- *
150
- */
151
- type VariantSchema = Record<string, Record<string, SzObject>>;
152
- /**
153
- *
154
- */
155
- type VariantSelection<V extends VariantSchema> = {
156
- [K in keyof V]?: keyof V[K] | null | undefined;
157
- };
158
- /**
159
- *
160
- */
161
- interface SzvConfig<V extends VariantSchema> {
162
- base?: SzObject;
163
- variants: V;
164
- defaultVariants?: Partial<VariantSelection<V>>;
165
- }
166
- /**
167
- * Creates a variant-based sz object factory with strong TypeScript inference.
168
- *
169
- * TypeScript catches invalid variant values at compile time — no runtime
170
- * surprises. All variant objects are plain sz objects, fully compatible
171
- * with the sz prop and @csszyx/dynamic's sz() function.
172
- *
173
- * @param {SzvConfig<V>} config - Variant configuration with base, variants, and defaultVariants
174
- * @returns {Function} A factory function that accepts a variant selection and returns an SzObject
175
- *
176
- * @example
177
- * ```tsx
178
- * import { szv } from 'csszyx';
179
- *
180
- * const buttonSz = szv({
181
- * base: { inlineFlex: true, items: 'center', rounded: 'md', fontWeight: 'medium' },
182
- * variants: {
183
- * variant: {
184
- * default: { bg: 'primary', text: 'primary-foreground' },
185
- * outline: { border: true, borderColor: 'blue-500', bg: 'transparent' },
186
- * ghost: { hover: { bg: 'accent' } },
187
- * },
188
- * size: {
189
- * sm: { h: 9, px: 3, text: 'sm' },
190
- * md: { h: 10, px: 4 },
191
- * lg: { h: 11, px: 8 },
192
- * },
193
- * },
194
- * defaultVariants: { variant: 'default', size: 'md' },
195
- * });
196
- *
197
- * // Usage — consistent with sz prop, TypeScript catches invalid values
198
- * <button sz={buttonSz({ variant: 'outline', size: 'sm' })} />
199
- *
200
- * // Compose with sz array syntax
201
- * <button sz={[
202
- * buttonSz({ variant: props.variant, size: props.size }),
203
- * isLoading && { opacity: 50, cursor: 'wait' },
204
- * ]} />
205
- *
206
- * // With @csszyx/dynamic for fully runtime-resolved styling
207
- * const { sz } = useSz();
208
- * <button className={sz(buttonSz({ variant: props.variant }))} />
209
- * ```
210
- */
211
- declare function szv<V extends VariantSchema>(config: SzvConfig<V>): (selection?: VariantSelection<V>) => SzObject;
212
-
213
138
  /**
214
139
  * Recovery Token Verification - Runtime validation of recovery tokens.
215
140
  *
@@ -687,6 +612,81 @@ declare function startHydration(): void;
687
612
  */
688
613
  declare function endHydration(): void;
689
614
 
615
+ /**
616
+ * szv() — variant-based sz object factory.
617
+ *
618
+ * CVA-equivalent but returns sz objects instead of className strings,
619
+ * keeping DX consistent with the sz prop throughout. Use with the sz prop
620
+ * (build-time transform) or with sz() from @csszyx/dynamic (runtime injection).
621
+ *
622
+ * @module @csszyx/runtime/variants
623
+ */
624
+
625
+ /**
626
+ *
627
+ */
628
+ type VariantSchema = Record<string, Record<string, SzObject>>;
629
+ /**
630
+ *
631
+ */
632
+ type VariantSelection<V extends VariantSchema> = {
633
+ [K in keyof V]?: keyof V[K] | null | undefined;
634
+ };
635
+ /**
636
+ *
637
+ */
638
+ interface SzvConfig<V extends VariantSchema> {
639
+ base?: SzObject;
640
+ variants: V;
641
+ defaultVariants?: Partial<VariantSelection<V>>;
642
+ }
643
+ /**
644
+ * Creates a variant-based sz object factory with strong TypeScript inference.
645
+ *
646
+ * TypeScript catches invalid variant values at compile time — no runtime
647
+ * surprises. All variant objects are plain sz objects, fully compatible
648
+ * with the sz prop and @csszyx/dynamic's sz() function.
649
+ *
650
+ * @param {SzvConfig<V>} config - Variant configuration with base, variants, and defaultVariants
651
+ * @returns {Function} A factory function that accepts a variant selection and returns an SzObject
652
+ *
653
+ * @example
654
+ * ```tsx
655
+ * import { szv } from 'csszyx';
656
+ *
657
+ * const buttonSz = szv({
658
+ * base: { inlineFlex: true, items: 'center', rounded: 'md', fontWeight: 'medium' },
659
+ * variants: {
660
+ * variant: {
661
+ * default: { bg: 'primary', text: 'primary-foreground' },
662
+ * outline: { border: true, borderColor: 'blue-500', bg: 'transparent' },
663
+ * ghost: { hover: { bg: 'accent' } },
664
+ * },
665
+ * size: {
666
+ * sm: { h: 9, px: 3, text: 'sm' },
667
+ * md: { h: 10, px: 4 },
668
+ * lg: { h: 11, px: 8 },
669
+ * },
670
+ * },
671
+ * defaultVariants: { variant: 'default', size: 'md' },
672
+ * });
673
+ *
674
+ * // Usage — consistent with sz prop, TypeScript catches invalid values
675
+ * <button sz={buttonSz({ variant: 'outline', size: 'sm' })} />
676
+ *
677
+ * // Compose with sz array syntax
678
+ * <button sz={[
679
+ * buttonSz({ variant: props.variant, size: props.size }),
680
+ * isLoading && { opacity: 50, cursor: 'wait' },
681
+ * ]} />
682
+ *
683
+ * // With @csszyx/dynamic for fully runtime-resolved styling
684
+ * const { sz } = useSz();
685
+ * <button className={sz(buttonSz({ variant: props.variant }))} />
686
+ * ```
687
+ */
688
+ declare function szv<V extends VariantSchema>(config: SzvConfig<V>): (selection?: VariantSelection<V>) => SzObject;
689
+
690
690
  /**
691
691
  * @csszyx/runtime - Runtime package for csszyx.
692
692
  *
@@ -769,4 +769,5 @@ declare function isRuntimeInitialized(): boolean;
769
769
  */
770
770
  declare function resetRuntime(): void;
771
771
 
772
- export { DEFAULT_RUNTIME_CONFIG, type HydrationError, type HydrationErrorType, type MangleMap, type RecoveryManifest, type RecoveryMode, type RuntimeConfig, type SSRContext, type SzInput, type TokenData, VERSION, type VerificationResult, _sz, _sz2, _sz3, _szIf, _szMerge, _szSwitch, abortHydration, attemptCSRRecovery, clearHydrationErrors, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, hasRecoveryToken, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, resetRuntime, startHydration, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
772
+ export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szIf, _szMerge, _szSwitch, abortHydration, attemptCSRRecovery, clearHydrationErrors, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, hasRecoveryToken, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, resetRuntime, startHydration, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
773
+ export type { HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SzInput, TokenData, VerificationResult };
@@ -135,81 +135,6 @@ declare function _sz2(a: string, b: string): string;
135
135
  */
136
136
  declare function _sz3(a: string, b: string, c: string): string;
137
137
 
138
- /**
139
- * szv() — variant-based sz object factory.
140
- *
141
- * CVA-equivalent but returns sz objects instead of className strings,
142
- * keeping DX consistent with the sz prop throughout. Use with the sz prop
143
- * (build-time transform) or with sz() from @csszyx/dynamic (runtime injection).
144
- *
145
- * @module @csszyx/runtime/variants
146
- */
147
-
148
- /**
149
- *
150
- */
151
- type VariantSchema = Record<string, Record<string, SzObject>>;
152
- /**
153
- *
154
- */
155
- type VariantSelection<V extends VariantSchema> = {
156
- [K in keyof V]?: keyof V[K] | null | undefined;
157
- };
158
- /**
159
- *
160
- */
161
- interface SzvConfig<V extends VariantSchema> {
162
- base?: SzObject;
163
- variants: V;
164
- defaultVariants?: Partial<VariantSelection<V>>;
165
- }
166
- /**
167
- * Creates a variant-based sz object factory with strong TypeScript inference.
168
- *
169
- * TypeScript catches invalid variant values at compile time — no runtime
170
- * surprises. All variant objects are plain sz objects, fully compatible
171
- * with the sz prop and @csszyx/dynamic's sz() function.
172
- *
173
- * @param {SzvConfig<V>} config - Variant configuration with base, variants, and defaultVariants
174
- * @returns {Function} A factory function that accepts a variant selection and returns an SzObject
175
- *
176
- * @example
177
- * ```tsx
178
- * import { szv } from 'csszyx';
179
- *
180
- * const buttonSz = szv({
181
- * base: { inlineFlex: true, items: 'center', rounded: 'md', fontWeight: 'medium' },
182
- * variants: {
183
- * variant: {
184
- * default: { bg: 'primary', text: 'primary-foreground' },
185
- * outline: { border: true, borderColor: 'blue-500', bg: 'transparent' },
186
- * ghost: { hover: { bg: 'accent' } },
187
- * },
188
- * size: {
189
- * sm: { h: 9, px: 3, text: 'sm' },
190
- * md: { h: 10, px: 4 },
191
- * lg: { h: 11, px: 8 },
192
- * },
193
- * },
194
- * defaultVariants: { variant: 'default', size: 'md' },
195
- * });
196
- *
197
- * // Usage — consistent with sz prop, TypeScript catches invalid values
198
- * <button sz={buttonSz({ variant: 'outline', size: 'sm' })} />
199
- *
200
- * // Compose with sz array syntax
201
- * <button sz={[
202
- * buttonSz({ variant: props.variant, size: props.size }),
203
- * isLoading && { opacity: 50, cursor: 'wait' },
204
- * ]} />
205
- *
206
- * // With @csszyx/dynamic for fully runtime-resolved styling
207
- * const { sz } = useSz();
208
- * <button className={sz(buttonSz({ variant: props.variant }))} />
209
- * ```
210
- */
211
- declare function szv<V extends VariantSchema>(config: SzvConfig<V>): (selection?: VariantSelection<V>) => SzObject;
212
-
213
138
  /**
214
139
  * Recovery Token Verification - Runtime validation of recovery tokens.
215
140
  *
@@ -687,6 +612,81 @@ declare function startHydration(): void;
687
612
  */
688
613
  declare function endHydration(): void;
689
614
 
615
+ /**
616
+ * szv() — variant-based sz object factory.
617
+ *
618
+ * CVA-equivalent but returns sz objects instead of className strings,
619
+ * keeping DX consistent with the sz prop throughout. Use with the sz prop
620
+ * (build-time transform) or with sz() from @csszyx/dynamic (runtime injection).
621
+ *
622
+ * @module @csszyx/runtime/variants
623
+ */
624
+
625
+ /**
626
+ *
627
+ */
628
+ type VariantSchema = Record<string, Record<string, SzObject>>;
629
+ /**
630
+ *
631
+ */
632
+ type VariantSelection<V extends VariantSchema> = {
633
+ [K in keyof V]?: keyof V[K] | null | undefined;
634
+ };
635
+ /**
636
+ *
637
+ */
638
+ interface SzvConfig<V extends VariantSchema> {
639
+ base?: SzObject;
640
+ variants: V;
641
+ defaultVariants?: Partial<VariantSelection<V>>;
642
+ }
643
+ /**
644
+ * Creates a variant-based sz object factory with strong TypeScript inference.
645
+ *
646
+ * TypeScript catches invalid variant values at compile time — no runtime
647
+ * surprises. All variant objects are plain sz objects, fully compatible
648
+ * with the sz prop and @csszyx/dynamic's sz() function.
649
+ *
650
+ * @param {SzvConfig<V>} config - Variant configuration with base, variants, and defaultVariants
651
+ * @returns {Function} A factory function that accepts a variant selection and returns an SzObject
652
+ *
653
+ * @example
654
+ * ```tsx
655
+ * import { szv } from 'csszyx';
656
+ *
657
+ * const buttonSz = szv({
658
+ * base: { inlineFlex: true, items: 'center', rounded: 'md', fontWeight: 'medium' },
659
+ * variants: {
660
+ * variant: {
661
+ * default: { bg: 'primary', text: 'primary-foreground' },
662
+ * outline: { border: true, borderColor: 'blue-500', bg: 'transparent' },
663
+ * ghost: { hover: { bg: 'accent' } },
664
+ * },
665
+ * size: {
666
+ * sm: { h: 9, px: 3, text: 'sm' },
667
+ * md: { h: 10, px: 4 },
668
+ * lg: { h: 11, px: 8 },
669
+ * },
670
+ * },
671
+ * defaultVariants: { variant: 'default', size: 'md' },
672
+ * });
673
+ *
674
+ * // Usage — consistent with sz prop, TypeScript catches invalid values
675
+ * <button sz={buttonSz({ variant: 'outline', size: 'sm' })} />
676
+ *
677
+ * // Compose with sz array syntax
678
+ * <button sz={[
679
+ * buttonSz({ variant: props.variant, size: props.size }),
680
+ * isLoading && { opacity: 50, cursor: 'wait' },
681
+ * ]} />
682
+ *
683
+ * // With @csszyx/dynamic for fully runtime-resolved styling
684
+ * const { sz } = useSz();
685
+ * <button className={sz(buttonSz({ variant: props.variant }))} />
686
+ * ```
687
+ */
688
+ declare function szv<V extends VariantSchema>(config: SzvConfig<V>): (selection?: VariantSelection<V>) => SzObject;
689
+
690
690
  /**
691
691
  * @csszyx/runtime - Runtime package for csszyx.
692
692
  *
@@ -769,4 +769,5 @@ declare function isRuntimeInitialized(): boolean;
769
769
  */
770
770
  declare function resetRuntime(): void;
771
771
 
772
- export { DEFAULT_RUNTIME_CONFIG, type HydrationError, type HydrationErrorType, type MangleMap, type RecoveryManifest, type RecoveryMode, type RuntimeConfig, type SSRContext, type SzInput, type TokenData, VERSION, type VerificationResult, _sz, _sz2, _sz3, _szIf, _szMerge, _szSwitch, abortHydration, attemptCSRRecovery, clearHydrationErrors, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, hasRecoveryToken, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, resetRuntime, startHydration, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
772
+ export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szIf, _szMerge, _szSwitch, abortHydration, attemptCSRRecovery, clearHydrationErrors, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, hasRecoveryToken, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, resetRuntime, startHydration, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
773
+ export type { HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SzInput, TokenData, VerificationResult };
@@ -1,4 +1,6 @@
1
- // src/verify.ts
1
+ import { transform } from '@csszyx/compiler/browser';
2
+ export { __szColorVar } from '@csszyx/compiler/color-var';
3
+
2
4
  function verifyRecoveryToken(element, manifest) {
3
5
  const token = element.getAttribute("data-sz-recovery-token");
4
6
  if (!token) {
@@ -70,8 +72,7 @@ function getRecoveryMode(element) {
70
72
  return null;
71
73
  }
72
74
 
73
- // src/hydration.ts
74
- var state = {
75
+ const state = {
75
76
  errors: [],
76
77
  abortedSubtrees: /* @__PURE__ */ new Set(),
77
78
  recoveryAllowed: false
@@ -145,10 +146,7 @@ function verifyMangleMapIntegrity() {
145
146
  }
146
147
  function abortHydration(element, error) {
147
148
  state.abortedSubtrees.add(element);
148
- console.error(
149
- `[csszyx] Hydration aborted at ${element.tagName}:`,
150
- error.message
151
- );
149
+ console.error(`[csszyx] Hydration aborted at ${element.tagName}:`, error.message);
152
150
  element.setAttribute("data-sz-hydration-aborted", error.timestamp.toString());
153
151
  element.setAttribute("data-sz-abort-reason", error.type);
154
152
  element.setAttribute("data-sz-interactive", "false");
@@ -257,8 +255,6 @@ function endHydration() {
257
255
  }
258
256
  }
259
257
 
260
- // src/concatenate.ts
261
- import { transform } from "@csszyx/compiler/browser";
262
258
  function _sz(...classes) {
263
259
  if (classes.length === 1) {
264
260
  const cls = classes[0];
@@ -356,7 +352,7 @@ function _sz2(a, b) {
356
352
  if (!b) {
357
353
  return a;
358
354
  }
359
- return a + " " + b;
355
+ return `${a} ${b}`;
360
356
  }
361
357
  function _sz3(a, b, c) {
362
358
  let result = "";
@@ -381,7 +377,6 @@ function _sz3(a, b, c) {
381
377
  return result;
382
378
  }
383
379
 
384
- // src/variants.ts
385
380
  function deepMerge(target, source) {
386
381
  const result = { ...target };
387
382
  for (const key of Object.keys(source)) {
@@ -421,18 +416,14 @@ function szv(config) {
421
416
  };
422
417
  }
423
418
 
424
- // src/lite.ts
425
- import { __szColorVar } from "@csszyx/compiler/color-var";
426
-
427
- // src/index.ts
428
- var VERSION = "0.0.0";
429
- var DEFAULT_RUNTIME_CONFIG = {
419
+ const VERSION = "0.0.0";
420
+ const DEFAULT_RUNTIME_CONFIG = {
430
421
  development: false,
431
422
  allowCSRRecovery: false,
432
423
  strictHydration: true,
433
424
  debug: false
434
425
  };
435
- var runtimeState = {
426
+ const runtimeState = {
436
427
  config: { ...DEFAULT_RUNTIME_CONFIG },
437
428
  initialized: false
438
429
  };
@@ -465,44 +456,5 @@ function resetRuntime() {
465
456
  runtimeState.config = { ...DEFAULT_RUNTIME_CONFIG };
466
457
  runtimeState.initialized = false;
467
458
  }
468
- export {
469
- DEFAULT_RUNTIME_CONFIG,
470
- VERSION,
471
- __szColorVar,
472
- _sz,
473
- _sz2,
474
- _sz3,
475
- _szIf,
476
- _szMerge,
477
- _szSwitch,
478
- abortHydration,
479
- attemptCSRRecovery,
480
- clearHydrationErrors,
481
- disableCSRRecovery,
482
- enableCSRRecovery,
483
- endHydration,
484
- getAbortedSubtreeCount,
485
- getHydrationErrors,
486
- getRecoveryMode,
487
- getRuntimeConfig,
488
- getSSRContext,
489
- guardHydration,
490
- hasRecoveryToken,
491
- initRuntime,
492
- isCSRRecoveryAllowed,
493
- isHydrating,
494
- isHydrationAborted,
495
- isRuntimeInitialized,
496
- isSSREnvironment,
497
- isValidManifest,
498
- loadMangleMapFromDOM,
499
- loadManifestFromDOM,
500
- resetRuntime,
501
- startHydration,
502
- szv,
503
- validateHydrationClass,
504
- verifyAllTokens,
505
- verifyMangleChecksum,
506
- verifyMangleMapIntegrity,
507
- verifyRecoveryToken
508
- };
459
+
460
+ export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szIf, _szMerge, _szSwitch, abortHydration, attemptCSRRecovery, clearHydrationErrors, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, hasRecoveryToken, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, resetRuntime, startHydration, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
package/dist/lite.cjs CHANGED
@@ -1,17 +1,7 @@
1
1
  'use strict';
2
2
 
3
- // ../compiler/dist/color-var.js
4
- function __szColorVar(v) {
5
- if (v.startsWith("#") || v.startsWith("rgb") || v.startsWith("hsl") || v.startsWith("oklch")) {
6
- return v;
7
- }
8
- if (v.startsWith("--")) {
9
- return `var(${v})`;
10
- }
11
- return `var(--color-${v})`;
12
- }
3
+ const colorVar = require('@csszyx/compiler/color-var');
13
4
 
14
- // src/lite.ts
15
5
  function assertNotObject(cls, fnName) {
16
6
  if (cls !== null && cls !== void 0 && cls !== false && typeof cls !== "string") {
17
7
  throw new Error(
@@ -79,10 +69,10 @@ function _sz2(a, b) {
79
69
  if (!b) {
80
70
  return a;
81
71
  }
82
- return a + " " + b;
72
+ return `${a} ${b}`;
83
73
  }
84
74
 
85
- exports.__szColorVar = __szColorVar;
75
+ exports.__szColorVar = colorVar.__szColorVar;
86
76
  exports._sz = _sz;
87
77
  exports._sz2 = _sz2;
88
78
  exports._szIf = _szIf;
package/dist/lite.d.cts CHANGED
@@ -65,4 +65,5 @@ declare function _szMerge(...classes: SzInput[]): string;
65
65
  */
66
66
  declare function _sz2(a: string, b: string): string;
67
67
 
68
- export { type SzInput, _sz, _sz2, _szIf, _szMerge };
68
+ export { _sz, _sz2, _szIf, _szMerge };
69
+ export type { SzInput };
@@ -65,4 +65,5 @@ declare function _szMerge(...classes: SzInput[]): string;
65
65
  */
66
66
  declare function _sz2(a: string, b: string): string;
67
67
 
68
- export { type SzInput, _sz, _sz2, _szIf, _szMerge };
68
+ export { _sz, _sz2, _szIf, _szMerge };
69
+ export type { SzInput };
@@ -1,15 +1,5 @@
1
- // ../compiler/dist/color-var.js
2
- function __szColorVar(v) {
3
- if (v.startsWith("#") || v.startsWith("rgb") || v.startsWith("hsl") || v.startsWith("oklch")) {
4
- return v;
5
- }
6
- if (v.startsWith("--")) {
7
- return `var(${v})`;
8
- }
9
- return `var(--color-${v})`;
10
- }
1
+ export { __szColorVar } from '@csszyx/compiler/color-var';
11
2
 
12
- // src/lite.ts
13
3
  function assertNotObject(cls, fnName) {
14
4
  if (cls !== null && cls !== void 0 && cls !== false && typeof cls !== "string") {
15
5
  throw new Error(
@@ -77,7 +67,7 @@ function _sz2(a, b) {
77
67
  if (!b) {
78
68
  return a;
79
69
  }
80
- return a + " " + b;
70
+ return `${a} ${b}`;
81
71
  }
82
72
 
83
- export { __szColorVar, _sz, _sz2, _szIf, _szMerge };
73
+ export { _sz, _sz2, _szIf, _szMerge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/runtime",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Runtime helpers and hydration guards for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -20,43 +20,56 @@
20
20
  "url": "https://github.com/nguyennhutien/csszyx/issues"
21
21
  },
22
22
  "type": "module",
23
- "main": "./dist/index.js",
24
- "module": "./dist/index.js",
25
- "types": "./dist/index.d.ts",
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.mjs",
25
+ "types": "./dist/index.d.mts",
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js",
30
- "require": "./dist/index.cjs"
28
+ "import": {
29
+ "types": "./dist/index.d.mts",
30
+ "default": "./dist/index.mjs"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
31
36
  },
32
37
  "./lite": {
33
- "types": "./dist/lite.d.ts",
34
- "import": "./dist/lite.js",
35
- "require": "./dist/lite.cjs"
38
+ "import": {
39
+ "types": "./dist/lite.d.mts",
40
+ "default": "./dist/lite.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/lite.d.cts",
44
+ "default": "./dist/lite.cjs"
45
+ }
36
46
  }
37
47
  },
38
48
  "files": [
39
49
  "dist"
40
50
  ],
41
51
  "dependencies": {
42
- "@csszyx/compiler": "0.7.0",
43
- "@csszyx/core": "0.7.0"
52
+ "@csszyx/core": "0.8.0",
53
+ "@csszyx/compiler": "0.8.0"
44
54
  },
45
55
  "devDependencies": {
46
56
  "@types/node": "^20.11.0",
47
57
  "jsdom": "^23.0.0",
48
- "tsup": "^8.0.0",
49
- "typescript": "^5.3.3",
58
+ "typescript": "^6.0.3",
50
59
  "vite-plugin-wasm": "^3.3.0",
51
- "vitest": "^1.2.0"
60
+ "vitest": "^4.1.6",
61
+ "unbuild": "^3.6.1"
52
62
  },
53
63
  "optionalDependencies": {
54
64
  "@esbuild/linux-arm64": "^0.19.0"
55
65
  },
56
66
  "sideEffects": false,
67
+ "engines": {
68
+ "node": ">=22.12.0"
69
+ },
57
70
  "scripts": {
58
- "build": "tsup",
59
- "dev": "tsup --watch",
71
+ "build": "unbuild",
72
+ "dev": "unbuild --stub",
60
73
  "test": "vitest run",
61
74
  "test:watch": "vitest",
62
75
  "type-check": "tsc --noEmit"