@csszyx/runtime 0.3.1 → 0.4.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
@@ -18,10 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
23
  DEFAULT_RUNTIME_CONFIG: () => DEFAULT_RUNTIME_CONFIG,
24
24
  VERSION: () => VERSION,
25
+ __szColorVar: () => import_color_var.__szColorVar,
25
26
  _sz: () => _sz,
26
27
  _sz2: () => _sz2,
27
28
  _sz3: () => _sz3,
@@ -52,13 +53,14 @@ __export(index_exports, {
52
53
  loadManifestFromDOM: () => loadManifestFromDOM,
53
54
  resetRuntime: () => resetRuntime,
54
55
  startHydration: () => startHydration,
56
+ szv: () => szv,
55
57
  validateHydrationClass: () => validateHydrationClass,
56
58
  verifyAllTokens: () => verifyAllTokens,
57
59
  verifyMangleChecksum: () => verifyMangleChecksum,
58
60
  verifyMangleMapIntegrity: () => verifyMangleMapIntegrity,
59
61
  verifyRecoveryToken: () => verifyRecoveryToken
60
62
  });
61
- module.exports = __toCommonJS(index_exports);
63
+ module.exports = __toCommonJS(src_exports);
62
64
 
63
65
  // src/verify.ts
64
66
  function verifyRecoveryToken(element, manifest) {
@@ -320,7 +322,7 @@ function endHydration() {
320
322
  }
321
323
 
322
324
  // src/concatenate.ts
323
- var import_compiler = require("@csszyx/compiler");
325
+ var import_browser = require("@csszyx/compiler/browser");
324
326
  function _sz(...classes) {
325
327
  if (classes.length === 1) {
326
328
  const cls = classes[0];
@@ -330,7 +332,7 @@ function _sz(...classes) {
330
332
  if (!cls) {
331
333
  return "";
332
334
  }
333
- const res = (0, import_compiler.transform)(cls);
335
+ const res = (0, import_browser.transform)(cls);
334
336
  return typeof res === "string" ? res : res.className;
335
337
  }
336
338
  let result = "";
@@ -340,7 +342,7 @@ function _sz(...classes) {
340
342
  if (!cls) {
341
343
  continue;
342
344
  }
343
- const res = typeof cls === "string" ? cls : (0, import_compiler.transform)(cls);
345
+ const res = typeof cls === "string" ? cls : (0, import_browser.transform)(cls);
344
346
  const str = typeof res === "string" ? res : res.className;
345
347
  if (!str) {
346
348
  continue;
@@ -361,7 +363,7 @@ function _szIf(condition, truthyValue, falsyValue) {
361
363
  if (typeof value === "string") {
362
364
  return value;
363
365
  }
364
- const res = (0, import_compiler.transform)(value);
366
+ const res = (0, import_browser.transform)(value);
365
367
  return typeof res === "string" ? res : res.className;
366
368
  }
367
369
  function _szSwitch(conditions, defaultValue = "") {
@@ -374,7 +376,7 @@ function _szSwitch(conditions, defaultValue = "") {
374
376
  if (typeof value === "string") {
375
377
  return value;
376
378
  }
377
- const res2 = (0, import_compiler.transform)(value);
379
+ const res2 = (0, import_browser.transform)(value);
378
380
  return typeof res2 === "string" ? res2 : res2.className;
379
381
  }
380
382
  }
@@ -384,7 +386,7 @@ function _szSwitch(conditions, defaultValue = "") {
384
386
  if (typeof defaultValue === "string") {
385
387
  return defaultValue;
386
388
  }
387
- const res = (0, import_compiler.transform)(defaultValue);
389
+ const res = (0, import_browser.transform)(defaultValue);
388
390
  return typeof res === "string" ? res : res.className;
389
391
  }
390
392
  function _szMerge(...classes) {
@@ -395,7 +397,7 @@ function _szMerge(...classes) {
395
397
  if (!cls) {
396
398
  continue;
397
399
  }
398
- const res = typeof cls === "string" ? cls : (0, import_compiler.transform)(cls);
400
+ const res = typeof cls === "string" ? cls : (0, import_browser.transform)(cls);
399
401
  const str = typeof res === "string" ? res : res.className;
400
402
  if (!str) {
401
403
  continue;
@@ -443,6 +445,49 @@ function _sz3(a, b, c) {
443
445
  return result;
444
446
  }
445
447
 
448
+ // src/variants.ts
449
+ function deepMerge(target, source) {
450
+ const result = { ...target };
451
+ for (const key of Object.keys(source)) {
452
+ const sv = source[key];
453
+ const tv = target[key];
454
+ if (sv !== null && sv !== void 0 && typeof sv === "object" && !Array.isArray(sv) && tv !== null && tv !== void 0 && typeof tv === "object" && !Array.isArray(tv)) {
455
+ result[key] = deepMerge(tv, sv);
456
+ } else {
457
+ result[key] = sv;
458
+ }
459
+ }
460
+ return result;
461
+ }
462
+ function szv(config) {
463
+ return function szVariantFn(selection) {
464
+ let result = config.base ? { ...config.base } : {};
465
+ const resolved = { ...config.defaultVariants };
466
+ if (selection) {
467
+ for (const key of Object.keys(selection)) {
468
+ const val = selection[key];
469
+ if (val !== null && val !== void 0) {
470
+ resolved[key] = val;
471
+ }
472
+ }
473
+ }
474
+ for (const variantKey of Object.keys(config.variants)) {
475
+ const selectedValue = resolved[variantKey];
476
+ if (selectedValue === null || selectedValue === void 0) {
477
+ continue;
478
+ }
479
+ const variantObj = config.variants[variantKey][selectedValue];
480
+ if (variantObj) {
481
+ result = deepMerge(result, variantObj);
482
+ }
483
+ }
484
+ return result;
485
+ };
486
+ }
487
+
488
+ // src/lite.ts
489
+ var import_color_var = require("@csszyx/compiler/color-var");
490
+
446
491
  // src/index.ts
447
492
  var VERSION = "0.0.0";
448
493
  var DEFAULT_RUNTIME_CONFIG = {
@@ -488,6 +533,7 @@ function resetRuntime() {
488
533
  0 && (module.exports = {
489
534
  DEFAULT_RUNTIME_CONFIG,
490
535
  VERSION,
536
+ __szColorVar,
491
537
  _sz,
492
538
  _sz2,
493
539
  _sz3,
@@ -518,6 +564,7 @@ function resetRuntime() {
518
564
  loadManifestFromDOM,
519
565
  resetRuntime,
520
566
  startHydration,
567
+ szv,
521
568
  validateHydrationClass,
522
569
  verifyAllTokens,
523
570
  verifyMangleChecksum,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { SzObject } from '@csszyx/compiler';
1
+ import { SzObject } from '@csszyx/compiler/browser';
2
+ export { __szColorVar } from '@csszyx/compiler/color-var';
2
3
 
3
4
  /**
4
5
  * Zero-allocation className concatenation helper.
@@ -134,6 +135,81 @@ declare function _sz2(a: string, b: string): string;
134
135
  */
135
136
  declare function _sz3(a: string, b: string, c: string): string;
136
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
+
137
213
  /**
138
214
  * Recovery Token Verification - Runtime validation of recovery tokens.
139
215
  *
@@ -692,4 +768,4 @@ declare function isRuntimeInitialized(): boolean;
692
768
  */
693
769
  declare function resetRuntime(): void;
694
770
 
695
- 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, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
771
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { SzObject } from '@csszyx/compiler';
1
+ import { SzObject } from '@csszyx/compiler/browser';
2
+ export { __szColorVar } from '@csszyx/compiler/color-var';
2
3
 
3
4
  /**
4
5
  * Zero-allocation className concatenation helper.
@@ -134,6 +135,81 @@ declare function _sz2(a: string, b: string): string;
134
135
  */
135
136
  declare function _sz3(a: string, b: string, c: string): string;
136
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
+
137
213
  /**
138
214
  * Recovery Token Verification - Runtime validation of recovery tokens.
139
215
  *
@@ -692,4 +768,4 @@ declare function isRuntimeInitialized(): boolean;
692
768
  */
693
769
  declare function resetRuntime(): void;
694
770
 
695
- 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, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleMapIntegrity, verifyRecoveryToken };
771
+ 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 };
package/dist/index.js CHANGED
@@ -258,7 +258,7 @@ function endHydration() {
258
258
  }
259
259
 
260
260
  // src/concatenate.ts
261
- import { transform } from "@csszyx/compiler";
261
+ import { transform } from "@csszyx/compiler/browser";
262
262
  function _sz(...classes) {
263
263
  if (classes.length === 1) {
264
264
  const cls = classes[0];
@@ -381,6 +381,49 @@ function _sz3(a, b, c) {
381
381
  return result;
382
382
  }
383
383
 
384
+ // src/variants.ts
385
+ function deepMerge(target, source) {
386
+ const result = { ...target };
387
+ for (const key of Object.keys(source)) {
388
+ const sv = source[key];
389
+ const tv = target[key];
390
+ if (sv !== null && sv !== void 0 && typeof sv === "object" && !Array.isArray(sv) && tv !== null && tv !== void 0 && typeof tv === "object" && !Array.isArray(tv)) {
391
+ result[key] = deepMerge(tv, sv);
392
+ } else {
393
+ result[key] = sv;
394
+ }
395
+ }
396
+ return result;
397
+ }
398
+ function szv(config) {
399
+ return function szVariantFn(selection) {
400
+ let result = config.base ? { ...config.base } : {};
401
+ const resolved = { ...config.defaultVariants };
402
+ if (selection) {
403
+ for (const key of Object.keys(selection)) {
404
+ const val = selection[key];
405
+ if (val !== null && val !== void 0) {
406
+ resolved[key] = val;
407
+ }
408
+ }
409
+ }
410
+ for (const variantKey of Object.keys(config.variants)) {
411
+ const selectedValue = resolved[variantKey];
412
+ if (selectedValue === null || selectedValue === void 0) {
413
+ continue;
414
+ }
415
+ const variantObj = config.variants[variantKey][selectedValue];
416
+ if (variantObj) {
417
+ result = deepMerge(result, variantObj);
418
+ }
419
+ }
420
+ return result;
421
+ };
422
+ }
423
+
424
+ // src/lite.ts
425
+ import { __szColorVar } from "@csszyx/compiler/color-var";
426
+
384
427
  // src/index.ts
385
428
  var VERSION = "0.0.0";
386
429
  var DEFAULT_RUNTIME_CONFIG = {
@@ -425,6 +468,7 @@ function resetRuntime() {
425
468
  export {
426
469
  DEFAULT_RUNTIME_CONFIG,
427
470
  VERSION,
471
+ __szColorVar,
428
472
  _sz,
429
473
  _sz2,
430
474
  _sz3,
@@ -455,6 +499,7 @@ export {
455
499
  loadManifestFromDOM,
456
500
  resetRuntime,
457
501
  startHydration,
502
+ szv,
458
503
  validateHydrationClass,
459
504
  verifyAllTokens,
460
505
  verifyMangleChecksum,
package/dist/lite.cjs CHANGED
@@ -1,39 +1,43 @@
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 });
1
+ 'use strict';
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;
15
7
  }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
8
+ if (v.startsWith("--")) {
9
+ return `var(${v})`;
10
+ }
11
+ return `var(--color-${v})`;
12
+ }
19
13
 
20
14
  // 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);
15
+ function assertNotObject(cls, fnName) {
16
+ if (cls !== null && cls !== void 0 && cls !== false && typeof cls !== "string") {
17
+ throw new Error(
18
+ `[csszyx] ${fnName}() received a plain object \u2014 the compiler could not resolve this sz prop at build time.
19
+
20
+ Common cause: sz={{ ...(cond ? varA : varB), key: 'val' }}
21
+ Fix: sz={[cond ? varA : varB, { key: 'val' }]}
22
+
23
+ Received: ${JSON.stringify(cls)}`
24
+ );
25
+ }
26
+ }
29
27
  function _sz(...classes) {
30
28
  if (classes.length === 1) {
29
+ if (process.env.NODE_ENV !== "production") {
30
+ assertNotObject(classes[0], "_sz");
31
+ }
31
32
  return classes[0] || "";
32
33
  }
33
34
  let result = "";
34
35
  let needsSpace = false;
35
36
  for (let i = 0; i < classes.length; i++) {
36
37
  const cls = classes[i];
38
+ if (process.env.NODE_ENV !== "production") {
39
+ assertNotObject(cls, "_sz");
40
+ }
37
41
  if (!cls) {
38
42
  continue;
39
43
  }
@@ -48,6 +52,26 @@ function _sz(...classes) {
48
52
  function _szIf(condition, truthyValue, falsyValue) {
49
53
  return (condition ? truthyValue : falsyValue) || "";
50
54
  }
55
+ function _szMerge(...classes) {
56
+ const seen = /* @__PURE__ */ new Set();
57
+ const result = [];
58
+ for (let i = 0; i < classes.length; i++) {
59
+ const cls = classes[i];
60
+ if (process.env.NODE_ENV !== "production") {
61
+ assertNotObject(cls, "_szMerge");
62
+ }
63
+ if (!cls) {
64
+ continue;
65
+ }
66
+ for (const token of cls.split(" ")) {
67
+ if (token && !seen.has(token)) {
68
+ seen.add(token);
69
+ result.push(token);
70
+ }
71
+ }
72
+ }
73
+ return result.join(" ");
74
+ }
51
75
  function _sz2(a, b) {
52
76
  if (!a) {
53
77
  return b || "";
@@ -57,19 +81,9 @@ function _sz2(a, b) {
57
81
  }
58
82
  return a + " " + b;
59
83
  }
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
- });
84
+
85
+ exports.__szColorVar = __szColorVar;
86
+ exports._sz = _sz;
87
+ exports._sz2 = _sz2;
88
+ exports._szIf = _szIf;
89
+ exports._szMerge = _szMerge;
package/dist/lite.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ export { __szColorVar } from '@csszyx/compiler/color-var';
2
+
1
3
  /**
2
4
  * @csszyx/runtime/lite - Ultra-minimal runtime helpers.
3
5
  *
@@ -7,8 +9,12 @@
7
9
  *
8
10
  * Bundle size target: < 500 bytes (minified + gzipped)
9
11
  *
12
+ * __szColorVar is imported from @csszyx/compiler/color-var and inlined at
13
+ * build time by tsup (noExternal). Zero runtime deps — single source of truth.
14
+ *
10
15
  * @module @csszyx/runtime/lite
11
16
  */
17
+
12
18
  /**
13
19
  * Type for sz input - string-only (objects are pre-compiled at build time).
14
20
  */
@@ -40,6 +46,17 @@ declare function _sz(...classes: SzInput[]): string;
40
46
  * ```
41
47
  */
42
48
  declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: SzInput): string;
49
+ /**
50
+ * Merges className strings from compiled array sz props, deduplicating tokens.
51
+ *
52
+ * Emitted by the compiler for sz={[varA, cond && varB, ...]} when at least one
53
+ * element is a runtime conditional. All arguments must be pre-compiled strings
54
+ * (the compiler resolves each element to a string before passing it here).
55
+ *
56
+ * @param {...SzInput[]} classes - Pre-compiled class strings to merge
57
+ * @returns {string} Merged className string with duplicate tokens removed
58
+ */
59
+ declare function _szMerge(...classes: SzInput[]): string;
43
60
  /**
44
61
  * Two-argument optimized concatenation.
45
62
  * @param a - first class string
@@ -47,18 +64,5 @@ declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: Sz
47
64
  * @returns concatenated class string
48
65
  */
49
66
  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
67
 
64
- export { type SzInput, __szColorVar, _sz, _sz2, _szIf };
68
+ export { type SzInput, _sz, _sz2, _szIf, _szMerge };
package/dist/lite.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { __szColorVar } from '@csszyx/compiler/color-var';
2
+
1
3
  /**
2
4
  * @csszyx/runtime/lite - Ultra-minimal runtime helpers.
3
5
  *
@@ -7,8 +9,12 @@
7
9
  *
8
10
  * Bundle size target: < 500 bytes (minified + gzipped)
9
11
  *
12
+ * __szColorVar is imported from @csszyx/compiler/color-var and inlined at
13
+ * build time by tsup (noExternal). Zero runtime deps — single source of truth.
14
+ *
10
15
  * @module @csszyx/runtime/lite
11
16
  */
17
+
12
18
  /**
13
19
  * Type for sz input - string-only (objects are pre-compiled at build time).
14
20
  */
@@ -40,6 +46,17 @@ declare function _sz(...classes: SzInput[]): string;
40
46
  * ```
41
47
  */
42
48
  declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: SzInput): string;
49
+ /**
50
+ * Merges className strings from compiled array sz props, deduplicating tokens.
51
+ *
52
+ * Emitted by the compiler for sz={[varA, cond && varB, ...]} when at least one
53
+ * element is a runtime conditional. All arguments must be pre-compiled strings
54
+ * (the compiler resolves each element to a string before passing it here).
55
+ *
56
+ * @param {...SzInput[]} classes - Pre-compiled class strings to merge
57
+ * @returns {string} Merged className string with duplicate tokens removed
58
+ */
59
+ declare function _szMerge(...classes: SzInput[]): string;
43
60
  /**
44
61
  * Two-argument optimized concatenation.
45
62
  * @param a - first class string
@@ -47,18 +64,5 @@ declare function _szIf(condition: boolean, truthyValue: SzInput, falsyValue?: Sz
47
64
  * @returns concatenated class string
48
65
  */
49
66
  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
67
 
64
- export { type SzInput, __szColorVar, _sz, _sz2, _szIf };
68
+ export { type SzInput, _sz, _sz2, _szIf, _szMerge };
package/dist/lite.js CHANGED
@@ -1,12 +1,41 @@
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
+ }
11
+
1
12
  // src/lite.ts
13
+ function assertNotObject(cls, fnName) {
14
+ if (cls !== null && cls !== void 0 && cls !== false && typeof cls !== "string") {
15
+ throw new Error(
16
+ `[csszyx] ${fnName}() received a plain object \u2014 the compiler could not resolve this sz prop at build time.
17
+
18
+ Common cause: sz={{ ...(cond ? varA : varB), key: 'val' }}
19
+ Fix: sz={[cond ? varA : varB, { key: 'val' }]}
20
+
21
+ Received: ${JSON.stringify(cls)}`
22
+ );
23
+ }
24
+ }
2
25
  function _sz(...classes) {
3
26
  if (classes.length === 1) {
27
+ if (process.env.NODE_ENV !== "production") {
28
+ assertNotObject(classes[0], "_sz");
29
+ }
4
30
  return classes[0] || "";
5
31
  }
6
32
  let result = "";
7
33
  let needsSpace = false;
8
34
  for (let i = 0; i < classes.length; i++) {
9
35
  const cls = classes[i];
36
+ if (process.env.NODE_ENV !== "production") {
37
+ assertNotObject(cls, "_sz");
38
+ }
10
39
  if (!cls) {
11
40
  continue;
12
41
  }
@@ -21,6 +50,26 @@ function _sz(...classes) {
21
50
  function _szIf(condition, truthyValue, falsyValue) {
22
51
  return (condition ? truthyValue : falsyValue) || "";
23
52
  }
53
+ function _szMerge(...classes) {
54
+ const seen = /* @__PURE__ */ new Set();
55
+ const result = [];
56
+ for (let i = 0; i < classes.length; i++) {
57
+ const cls = classes[i];
58
+ if (process.env.NODE_ENV !== "production") {
59
+ assertNotObject(cls, "_szMerge");
60
+ }
61
+ if (!cls) {
62
+ continue;
63
+ }
64
+ for (const token of cls.split(" ")) {
65
+ if (token && !seen.has(token)) {
66
+ seen.add(token);
67
+ result.push(token);
68
+ }
69
+ }
70
+ }
71
+ return result.join(" ");
72
+ }
24
73
  function _sz2(a, b) {
25
74
  if (!a) {
26
75
  return b || "";
@@ -30,18 +79,5 @@ function _sz2(a, b) {
30
79
  }
31
80
  return a + " " + b;
32
81
  }
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
- };
82
+
83
+ export { __szColorVar, _sz, _sz2, _szIf, _szMerge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/runtime",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Runtime helpers and hydration guards for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -39,8 +39,8 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@csszyx/compiler": "0.3.1",
43
- "@csszyx/core": "0.3.1"
42
+ "@csszyx/compiler": "0.4.0",
43
+ "@csszyx/core": "0.4.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^20.11.0",
@@ -55,8 +55,8 @@
55
55
  },
56
56
  "sideEffects": false,
57
57
  "scripts": {
58
- "build": "tsup src/index.ts src/lite.ts --format esm,cjs --dts --clean",
59
- "dev": "tsup src/index.ts src/lite.ts --format esm --dts --watch",
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
60
  "test": "vitest run",
61
61
  "test:watch": "vitest",
62
62
  "type-check": "tsc --noEmit"