@csszyx/compiler 0.9.10 → 0.10.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.
@@ -193,6 +193,22 @@ function getCSSVariableName(property, variantPrefix) {
193
193
  return `--_sz-${prop}`;
194
194
  }
195
195
 
196
+ const MAX_SZ_DEPTH = 32;
197
+ class SzDepthError extends Error {
198
+ /**
199
+ * @param depth - the depth limit that was exceeded (for the message).
200
+ */
201
+ constructor(depth = MAX_SZ_DEPTH) {
202
+ super(
203
+ `[csszyx] sz nesting exceeded the maximum depth of ${depth}. This usually means untrusted/looping data reached an sz prop.`
204
+ );
205
+ this.name = "SzDepthError";
206
+ }
207
+ }
208
+ function isForbiddenSzKey(key) {
209
+ return key === "__proto__" || key === "constructor" || key === "prototype";
210
+ }
211
+
196
212
  const COLOR_STRING_KEYWORDS = /* @__PURE__ */ new Set([
197
213
  "inherit",
198
214
  "current",
@@ -232,11 +248,17 @@ function hasSlashOpacity(value) {
232
248
  }
233
249
  return slashIdx > 0 && /\d$/.test(value.slice(0, slashIdx));
234
250
  }
235
- function stripInvalidColorStrings(sz) {
251
+ function stripInvalidColorStrings(sz, _depth = 0) {
252
+ if (_depth >= MAX_SZ_DEPTH) {
253
+ throw new SzDepthError();
254
+ }
236
255
  const result = {};
237
256
  for (const [key, value] of Object.entries(sz)) {
257
+ if (isForbiddenSzKey(key)) {
258
+ continue;
259
+ }
238
260
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
239
- result[key] = stripInvalidColorStrings(value);
261
+ result[key] = stripInvalidColorStrings(value, _depth + 1);
240
262
  continue;
241
263
  }
242
264
  if (typeof value === "string" && PROPERTY_CATEGORY_MAP[key] === PropertyCategory.COLOR) {
@@ -414,10 +436,13 @@ const PROPERTY_MAP = {
414
436
  // Typography
415
437
  color: "text",
416
438
  text: "text",
417
- fontWeight: "font",
418
439
  weight: "font",
419
440
  fontFamily: "font",
420
441
  fontStretch: "font-stretch",
442
+ // fontStyle/fontSmoothing are emitted by closed direct-output handlers; the
443
+ // prefix here only marks them as known props (diagnostics, editor tooling).
444
+ fontStyle: "font-style",
445
+ fontSmoothing: "font-smoothing",
421
446
  textAlign: "text",
422
447
  decoration: "decoration",
423
448
  decorationColor: "decoration",
@@ -443,6 +468,9 @@ const PROPERTY_MAP = {
443
468
  listImg: "list-image",
444
469
  // Flex & Grid
445
470
  basis: "basis",
471
+ // `flex` is the flex shorthand (flex: 1 → flex-1, flex: 'auto' → flex-auto).
472
+ // The `flex: true` display sugar was removed (use display: 'flex').
473
+ flex: "flex",
446
474
  flexDir: "flex",
447
475
  flexWrap: "flex",
448
476
  grow: "grow",
@@ -484,6 +512,8 @@ const PROPERTY_MAP = {
484
512
  mixBlend: "mix-blend",
485
513
  bgBlend: "bg-blend",
486
514
  // Filters
515
+ filter: "filter",
516
+ backdropFilter: "backdrop-filter",
487
517
  blur: "blur",
488
518
  brightness: "brightness",
489
519
  contrast: "contrast",
@@ -539,6 +569,8 @@ const PROPERTY_MAP = {
539
569
  maskPos: "mask-position",
540
570
  maskRepeat: "mask-repeat",
541
571
  maskShape: "mask",
572
+ maskClip: "mask-clip",
573
+ maskOrigin: "mask-origin",
542
574
  // Interactivity
543
575
  cursor: "cursor",
544
576
  caret: "caret",
@@ -607,7 +639,7 @@ const PROPERTY_MAP = {
607
639
  };
608
640
  const CSS_VAR_TYPE_HINTS = {
609
641
  fontFamily: "family-name",
610
- fontWeight: "weight",
642
+ weight: "weight",
611
643
  text: "length"
612
644
  };
613
645
  const SUGGESTION_MAP = {
@@ -656,10 +688,10 @@ const SUGGESTION_MAP = {
656
688
  objectPosition: "objectPos",
657
689
  zIndex: "z",
658
690
  // Typography
659
- font: "fontWeight (for weight) or fontFamily (for family)",
660
- fontStyle: "italic/notItalic (boolean)",
661
- weight: "fontWeight",
662
- textDecoration: "decoration or underline/lineThrough/noUnderline (boolean)",
691
+ font: "weight (for font-weight) or fontFamily (for family)",
692
+ fontWeight: "weight",
693
+ fontSize: "text",
694
+ textDecoration: "decoration",
663
695
  textDecorationColor: "decorationColor",
664
696
  textDecorationStyle: "decorationStyle",
665
697
  textDecorationThickness: "decorationThickness",
@@ -670,7 +702,6 @@ const SUGGESTION_MAP = {
670
702
  verticalAlign: "align",
671
703
  wordBreak: "break",
672
704
  overflowWrap: "wrap",
673
- textWrap: "textWrap",
674
705
  listStyleType: "list",
675
706
  listStylePosition: "listPos",
676
707
  listStyleImage: "listImg",
@@ -926,45 +957,8 @@ const ARIA_STATES = /* @__PURE__ */ new Set([
926
957
  "modal"
927
958
  ]);
928
959
  const BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
929
- // Display
930
- "block",
931
- "inline",
932
- "inlineBlock",
933
- "flex",
934
- "inlineFlex",
935
- "grid",
936
- "inlineGrid",
937
- "hidden",
938
- "contents",
939
- "table",
940
- "tableRow",
941
- "tableCell",
942
- "flowRoot",
943
- "listItem",
944
- // Position
945
- "static",
946
- "fixed",
947
- "absolute",
948
- "relative",
949
- "sticky",
950
- // Visibility
951
- "visible",
952
- "invisible",
953
- "collapse",
954
- // Typography
960
+ // Typography (composite — no single-property canonical form)
955
961
  "truncate",
956
- "uppercase",
957
- "lowercase",
958
- "capitalize",
959
- "normalCase",
960
- "underline",
961
- "overline",
962
- "lineThrough",
963
- "noUnderline",
964
- "italic",
965
- "notItalic",
966
- "antialiased",
967
- "subpixelAntialiased",
968
962
  // Flexbox (grow/shrink only — flexWrap uses string values)
969
963
  "grow",
970
964
  "shrink",
@@ -983,10 +977,9 @@ const BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
983
977
  "proseInvert",
984
978
  "srOnly",
985
979
  "notSrOnly",
986
- "isolate",
987
980
  "ordinal",
988
981
  "slashedZero",
989
- // Font variant numeric
982
+ // Font variant numeric (additive — these combine, so they stay boolean flags)
990
983
  "liningNums",
991
984
  "oldstyleNums",
992
985
  "proportionalNums",
@@ -1003,19 +996,52 @@ const BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
1003
996
  // Outline
1004
997
  "outline"
1005
998
  ]);
999
+ const REMOVED_BOOLEAN_SUGAR = {
1000
+ // display
1001
+ block: { key: "display", value: "block" },
1002
+ inline: { key: "display", value: "inline" },
1003
+ inlineBlock: { key: "display", value: "inline-block" },
1004
+ flex: { key: "display", value: "flex" },
1005
+ inlineFlex: { key: "display", value: "inline-flex" },
1006
+ grid: { key: "display", value: "grid" },
1007
+ inlineGrid: { key: "display", value: "inline-grid" },
1008
+ hidden: { key: "display", value: "none" },
1009
+ contents: { key: "display", value: "contents" },
1010
+ table: { key: "display", value: "table" },
1011
+ tableRow: { key: "display", value: "table-row" },
1012
+ tableCell: { key: "display", value: "table-cell" },
1013
+ flowRoot: { key: "display", value: "flow-root" },
1014
+ listItem: { key: "display", value: "list-item" },
1015
+ // position
1016
+ static: { key: "position", value: "static" },
1017
+ fixed: { key: "position", value: "fixed" },
1018
+ absolute: { key: "position", value: "absolute" },
1019
+ relative: { key: "position", value: "relative" },
1020
+ sticky: { key: "position", value: "sticky" },
1021
+ // visibility
1022
+ visible: { key: "visibility", value: "visible" },
1023
+ invisible: { key: "visibility", value: "hidden" },
1024
+ collapse: { key: "visibility", value: "collapse" },
1025
+ // isolation
1026
+ isolate: { key: "isolation", value: "isolate" },
1027
+ // text-transform
1028
+ uppercase: { key: "textTransform", value: "uppercase" },
1029
+ lowercase: { key: "textTransform", value: "lowercase" },
1030
+ capitalize: { key: "textTransform", value: "capitalize" },
1031
+ normalCase: { key: "textTransform", value: "none" },
1032
+ // font-style
1033
+ italic: { key: "fontStyle", value: "italic" },
1034
+ notItalic: { key: "fontStyle", value: "normal" },
1035
+ // text-decoration-line
1036
+ underline: { key: "decoration", value: "underline" },
1037
+ overline: { key: "decoration", value: "overline" },
1038
+ lineThrough: { key: "decoration", value: "line-through" },
1039
+ noUnderline: { key: "decoration", value: "none" },
1040
+ // font-smoothing
1041
+ antialiased: { key: "fontSmoothing", value: "grayscale" },
1042
+ subpixelAntialiased: { key: "fontSmoothing", value: "subpixel" }
1043
+ };
1006
1044
  const BOOLEAN_TO_CLASS = {
1007
- inlineBlock: "inline-block",
1008
- inlineFlex: "inline-flex",
1009
- inlineGrid: "inline-grid",
1010
- tableRow: "table-row",
1011
- tableCell: "table-cell",
1012
- flowRoot: "flow-root",
1013
- listItem: "list-item",
1014
- normalCase: "normal-case",
1015
- lineThrough: "line-through",
1016
- noUnderline: "no-underline",
1017
- notItalic: "not-italic",
1018
- subpixelAntialiased: "subpixel-antialiased",
1019
1045
  backdropBlur: "backdrop-blur",
1020
1046
  backdropGrayscale: "backdrop-grayscale",
1021
1047
  backdropInvert: "backdrop-invert",
@@ -1435,23 +1461,38 @@ function handleSupports(supportsObj, prefix) {
1435
1461
  }
1436
1462
  return classes;
1437
1463
  }
1464
+ let szTransformDepth = 0;
1438
1465
  function transform(szProp, prefix = "", mangleMap) {
1439
1466
  if (!szProp || typeof szProp !== "object") {
1440
1467
  return { className: "", attributes: {} };
1441
1468
  }
1469
+ if (szTransformDepth >= MAX_SZ_DEPTH) {
1470
+ throw new SzDepthError();
1471
+ }
1472
+ szTransformDepth++;
1473
+ try {
1474
+ return transformImpl(szProp, prefix, mangleMap);
1475
+ } finally {
1476
+ szTransformDepth--;
1477
+ }
1478
+ }
1479
+ function transformImpl(szProp, prefix, mangleMap) {
1442
1480
  const classes = [];
1443
1481
  const attributes = {};
1444
1482
  for (const [rawKey, value] of Object.entries(szProp)) {
1445
- if (value === false) {
1446
- if (rawKey === "italic") {
1447
- classes.push(`${prefix}not-italic`);
1448
- } else if (rawKey === "antialiased") {
1449
- classes.push(`${prefix}subpixel-antialiased`);
1450
- }
1483
+ if (value === false || value === null || value === void 0) {
1451
1484
  continue;
1452
1485
  }
1453
- if (value === null || value === void 0) {
1454
- continue;
1486
+ if (value === true) {
1487
+ const removed = REMOVED_BOOLEAN_SUGAR[rawKey];
1488
+ if (removed) {
1489
+ if (process.env.NODE_ENV !== "production" && typeof window === "undefined") {
1490
+ console.warn(
1491
+ `[csszyx] "${rawKey}" boolean sugar was removed. Use { ${removed.key}: '${removed.value}' } instead, or run \`csszyx migrate\`.`
1492
+ );
1493
+ }
1494
+ continue;
1495
+ }
1455
1496
  }
1456
1497
  if (rawKey === "css") {
1457
1498
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -1794,11 +1835,52 @@ function transform(szProp, prefix = "", mangleMap) {
1794
1835
  }
1795
1836
  }
1796
1837
  if (rawKey === "textTransform") {
1797
- if (["uppercase", "lowercase", "capitalize", "normal-case"].includes(value)) {
1838
+ if (["uppercase", "lowercase", "capitalize"].includes(value)) {
1798
1839
  className += value;
1799
1840
  classes.push(className);
1800
1841
  continue;
1801
1842
  }
1843
+ if (value === "normal-case" || value === "none") {
1844
+ className += "normal-case";
1845
+ classes.push(className);
1846
+ continue;
1847
+ }
1848
+ }
1849
+ if (rawKey === "fontStyle") {
1850
+ if (value === "italic") {
1851
+ className += "italic";
1852
+ classes.push(className);
1853
+ continue;
1854
+ }
1855
+ if (value === "normal") {
1856
+ className += "not-italic";
1857
+ classes.push(className);
1858
+ continue;
1859
+ }
1860
+ if (process.env.NODE_ENV !== "production" && typeof window === "undefined") {
1861
+ console.warn(
1862
+ `[csszyx] fontStyle: '${value}' is not supported \u2014 Tailwind only models 'italic' and 'normal'. For oblique, use css: { fontStyle: '${value}' }.`
1863
+ );
1864
+ }
1865
+ continue;
1866
+ }
1867
+ if (rawKey === "fontSmoothing") {
1868
+ if (value === "grayscale") {
1869
+ className += "antialiased";
1870
+ classes.push(className);
1871
+ continue;
1872
+ }
1873
+ if (value === "subpixel") {
1874
+ className += "subpixel-antialiased";
1875
+ classes.push(className);
1876
+ continue;
1877
+ }
1878
+ if (process.env.NODE_ENV !== "production" && typeof window === "undefined") {
1879
+ console.warn(
1880
+ `[csszyx] fontSmoothing: '${value}' is not supported \u2014 use 'grayscale' or 'subpixel'.`
1881
+ );
1882
+ }
1883
+ continue;
1802
1884
  }
1803
1885
  if (rawKey === "fontVariant") {
1804
1886
  const FONT_VARIANT_CLASSES = /* @__PURE__ */ new Set([
@@ -1859,7 +1941,9 @@ function transform(szProp, prefix = "", mangleMap) {
1859
1941
  }
1860
1942
  if (rawKey === "lineClamp") {
1861
1943
  const sValue = String(value);
1862
- if (sValue.startsWith("--")) {
1944
+ if (sValue === "none") {
1945
+ className += "line-clamp-none";
1946
+ } else if (sValue.startsWith("--")) {
1863
1947
  className += `line-clamp-(${sValue})`;
1864
1948
  } else {
1865
1949
  const numVal = Number(sValue);
@@ -2205,7 +2289,7 @@ function transform(szProp, prefix = "", mangleMap) {
2205
2289
  if (STANDARD_ORIGINS.has(value)) {
2206
2290
  className += `perspective-origin-${value}`;
2207
2291
  } else {
2208
- className += `perspective-origin-[${value}]`;
2292
+ className += `perspective-origin-[${normalizeArbitraryValue(value)}]`;
2209
2293
  }
2210
2294
  classes.push(className);
2211
2295
  continue;
@@ -2350,15 +2434,19 @@ function normalizeClassName(className) {
2350
2434
  exports.BOOLEAN_SHORTHANDS = BOOLEAN_SHORTHANDS;
2351
2435
  exports.COLOR_PROPERTIES = COLOR_PROPERTIES;
2352
2436
  exports.KNOWN_VARIANTS = KNOWN_VARIANTS;
2437
+ exports.MAX_SZ_DEPTH = MAX_SZ_DEPTH;
2353
2438
  exports.PROPERTY_CATEGORY_MAP = PROPERTY_CATEGORY_MAP;
2354
2439
  exports.PROPERTY_MAP = PROPERTY_MAP;
2355
2440
  exports.PropertyCategory = PropertyCategory;
2441
+ exports.REMOVED_BOOLEAN_SUGAR = REMOVED_BOOLEAN_SUGAR;
2356
2442
  exports.SPECIAL_VARIANTS = SPECIAL_VARIANTS;
2357
2443
  exports.SUGGESTION_MAP = SUGGESTION_MAP;
2444
+ exports.SzDepthError = SzDepthError;
2358
2445
  exports.VARIANT_MAP = VARIANT_MAP;
2359
2446
  exports.getCSSVariableName = getCSSVariableName;
2360
2447
  exports.getPropertyCategory = getPropertyCategory;
2361
2448
  exports.getVariantPrefix = getVariantPrefix;
2449
+ exports.isForbiddenSzKey = isForbiddenSzKey;
2362
2450
  exports.isValidSzProp = isValidSzProp;
2363
2451
  exports.normalizeArbitraryValue = normalizeArbitraryValue;
2364
2452
  exports.normalizeArbitraryVariant = normalizeArbitraryVariant;
@@ -1,16 +1,20 @@
1
1
  'use strict';
2
2
 
3
- const transformCore = require('./shared/compiler.BsKlgPl4.cjs');
3
+ const transformCore = require('./shared/compiler.DmlsP739.cjs');
4
4
 
5
5
 
6
6
 
7
7
  exports.BOOLEAN_SHORTHANDS = transformCore.BOOLEAN_SHORTHANDS;
8
8
  exports.KNOWN_VARIANTS = transformCore.KNOWN_VARIANTS;
9
+ exports.MAX_SZ_DEPTH = transformCore.MAX_SZ_DEPTH;
9
10
  exports.PROPERTY_MAP = transformCore.PROPERTY_MAP;
11
+ exports.REMOVED_BOOLEAN_SUGAR = transformCore.REMOVED_BOOLEAN_SUGAR;
10
12
  exports.SPECIAL_VARIANTS = transformCore.SPECIAL_VARIANTS;
11
13
  exports.SUGGESTION_MAP = transformCore.SUGGESTION_MAP;
14
+ exports.SzDepthError = transformCore.SzDepthError;
12
15
  exports.VARIANT_MAP = transformCore.VARIANT_MAP;
13
16
  exports.getVariantPrefix = transformCore.getVariantPrefix;
17
+ exports.isForbiddenSzKey = transformCore.isForbiddenSzKey;
14
18
  exports.isValidSzProp = transformCore.isValidSzProp;
15
19
  exports.normalizeArbitraryValue = transformCore.normalizeArbitraryValue;
16
20
  exports.normalizeArbitraryVariant = transformCore.normalizeArbitraryVariant;
@@ -1,3 +1,43 @@
1
+ /**
2
+ * Shared limits that bound how much work a single sz object can force.
3
+ *
4
+ * sz objects can come from untrusted runtime data (e.g. a JSON-driven UI), and
5
+ * the transform / merge helpers recurse over nested variant objects. Without a
6
+ * bound, a deeply nested object (`{hover:{hover:{…}}}`) overflows the call stack
7
+ * — a denial-of-service that is reachable at request time, not just at build.
8
+ * These limits convert that crash into a catchable, typed error.
9
+ *
10
+ * Kept dependency-free so both the compiler and the runtime can import it.
11
+ */
12
+ /**
13
+ * Maximum nesting depth for an sz object / array before processing aborts.
14
+ * Far above real usage — authored sz nests only a few levels (a variant chain
15
+ * like `dark:{ hover:{ md:{…} } }` is ~3-4), so legitimate input never hits it.
16
+ */
17
+ declare const MAX_SZ_DEPTH = 32;
18
+ /**
19
+ * Thrown when an sz object/array nests deeper than {@link MAX_SZ_DEPTH}. A typed
20
+ * error so callers can distinguish a hostile-input limit from a real bug, and so
21
+ * the build pipeline's per-file fallback can swallow it without a stack overflow.
22
+ */
23
+ declare class SzDepthError extends Error {
24
+ /**
25
+ * @param depth - the depth limit that was exceeded (for the message).
26
+ */
27
+ constructor(depth?: number);
28
+ }
29
+ /**
30
+ * Keys that must never be written through a computed `obj[key] = …` on data that
31
+ * may be `JSON.parse`d: assigning to `__proto__`/`constructor`/`prototype`
32
+ * pollutes `Object.prototype` for the whole process. (Literal keys in source are
33
+ * inert; the risk is request-time JSON whose own enumerable `__proto__` key is
34
+ * copied during a merge.)
35
+ *
36
+ * @param key - the property key about to be written.
37
+ * @returns true when the key is unsafe to assign and should be skipped.
38
+ */
39
+ declare function isForbiddenSzKey(key: string): boolean;
40
+
1
41
  /**
2
42
  * JSX Transform - Converts sz prop to className string.
3
43
  *
@@ -5,6 +45,7 @@
5
45
  * Tailwind CSS class strings. It processes nested objects for variants
6
46
  * like hover, focus, etc.
7
47
  */
48
+
8
49
  /**
9
50
  * Represents a value in the sz object.
10
51
  * Can be a string, number, boolean, or nested object for variants.
@@ -34,6 +75,10 @@ declare const VARIANT_MAP: Record<string, string>;
34
75
  declare const SPECIAL_VARIANTS: Set<string>;
35
76
  declare const KNOWN_VARIANTS: Set<string>;
36
77
  declare const BOOLEAN_SHORTHANDS: Set<string>;
78
+ declare const REMOVED_BOOLEAN_SUGAR: Record<string, {
79
+ key: string;
80
+ value: string;
81
+ }>;
37
82
  /**
38
83
  * Represents the result of a transformation.
39
84
  */
@@ -60,12 +105,13 @@ declare function normalizeArbitraryValue(value: string): string;
60
105
  */
61
106
  declare function getVariantPrefix(key: string): string;
62
107
  /**
63
- * Transforms a csszyx sz object into a Tailwind CSS className string and extracted attributes.
108
+ * Transform an sz object into a className string plus any attributes, bounding
109
+ * recursion depth via {@link szTransformDepth}.
64
110
  *
65
- * @param {SzObject} szProp - The sz object from JSX
66
- * @param {string} prefix - Variant prefix for nested properties
67
- * @param {Record<string, string>} [mangleMap] - Optional map for property name mangling
68
- * @returns {TransformResult} The transformation result
111
+ * @param szProp - the sz object to transform.
112
+ * @param prefix - variant prefix to prepend to emitted classes.
113
+ * @param mangleMap - optional original→mangled class-name map.
114
+ * @returns the emitted className and attributes.
69
115
  */
70
116
  declare function transform(szProp: SzObject, prefix?: string, mangleMap?: Record<string, string>): TransformResult;
71
117
  /**
@@ -83,5 +129,5 @@ declare function isValidSzProp(szProp: unknown): szProp is SzObject;
83
129
  */
84
130
  declare function normalizeClassName(className: string): string;
85
131
 
86
- export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, PROPERTY_MAP, SPECIAL_VARIANTS, SUGGESTION_MAP, VARIANT_MAP, getVariantPrefix, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
132
+ export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, MAX_SZ_DEPTH, PROPERTY_MAP, REMOVED_BOOLEAN_SUGAR, SPECIAL_VARIANTS, SUGGESTION_MAP, SzDepthError, VARIANT_MAP, getVariantPrefix, isForbiddenSzKey, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
87
133
  export type { ReadonlySzObject, ReadonlySzValue, SzObject, SzValue, TransformResult };
@@ -1,3 +1,43 @@
1
+ /**
2
+ * Shared limits that bound how much work a single sz object can force.
3
+ *
4
+ * sz objects can come from untrusted runtime data (e.g. a JSON-driven UI), and
5
+ * the transform / merge helpers recurse over nested variant objects. Without a
6
+ * bound, a deeply nested object (`{hover:{hover:{…}}}`) overflows the call stack
7
+ * — a denial-of-service that is reachable at request time, not just at build.
8
+ * These limits convert that crash into a catchable, typed error.
9
+ *
10
+ * Kept dependency-free so both the compiler and the runtime can import it.
11
+ */
12
+ /**
13
+ * Maximum nesting depth for an sz object / array before processing aborts.
14
+ * Far above real usage — authored sz nests only a few levels (a variant chain
15
+ * like `dark:{ hover:{ md:{…} } }` is ~3-4), so legitimate input never hits it.
16
+ */
17
+ declare const MAX_SZ_DEPTH = 32;
18
+ /**
19
+ * Thrown when an sz object/array nests deeper than {@link MAX_SZ_DEPTH}. A typed
20
+ * error so callers can distinguish a hostile-input limit from a real bug, and so
21
+ * the build pipeline's per-file fallback can swallow it without a stack overflow.
22
+ */
23
+ declare class SzDepthError extends Error {
24
+ /**
25
+ * @param depth - the depth limit that was exceeded (for the message).
26
+ */
27
+ constructor(depth?: number);
28
+ }
29
+ /**
30
+ * Keys that must never be written through a computed `obj[key] = …` on data that
31
+ * may be `JSON.parse`d: assigning to `__proto__`/`constructor`/`prototype`
32
+ * pollutes `Object.prototype` for the whole process. (Literal keys in source are
33
+ * inert; the risk is request-time JSON whose own enumerable `__proto__` key is
34
+ * copied during a merge.)
35
+ *
36
+ * @param key - the property key about to be written.
37
+ * @returns true when the key is unsafe to assign and should be skipped.
38
+ */
39
+ declare function isForbiddenSzKey(key: string): boolean;
40
+
1
41
  /**
2
42
  * JSX Transform - Converts sz prop to className string.
3
43
  *
@@ -5,6 +45,7 @@
5
45
  * Tailwind CSS class strings. It processes nested objects for variants
6
46
  * like hover, focus, etc.
7
47
  */
48
+
8
49
  /**
9
50
  * Represents a value in the sz object.
10
51
  * Can be a string, number, boolean, or nested object for variants.
@@ -34,6 +75,10 @@ declare const VARIANT_MAP: Record<string, string>;
34
75
  declare const SPECIAL_VARIANTS: Set<string>;
35
76
  declare const KNOWN_VARIANTS: Set<string>;
36
77
  declare const BOOLEAN_SHORTHANDS: Set<string>;
78
+ declare const REMOVED_BOOLEAN_SUGAR: Record<string, {
79
+ key: string;
80
+ value: string;
81
+ }>;
37
82
  /**
38
83
  * Represents the result of a transformation.
39
84
  */
@@ -60,12 +105,13 @@ declare function normalizeArbitraryValue(value: string): string;
60
105
  */
61
106
  declare function getVariantPrefix(key: string): string;
62
107
  /**
63
- * Transforms a csszyx sz object into a Tailwind CSS className string and extracted attributes.
108
+ * Transform an sz object into a className string plus any attributes, bounding
109
+ * recursion depth via {@link szTransformDepth}.
64
110
  *
65
- * @param {SzObject} szProp - The sz object from JSX
66
- * @param {string} prefix - Variant prefix for nested properties
67
- * @param {Record<string, string>} [mangleMap] - Optional map for property name mangling
68
- * @returns {TransformResult} The transformation result
111
+ * @param szProp - the sz object to transform.
112
+ * @param prefix - variant prefix to prepend to emitted classes.
113
+ * @param mangleMap - optional original→mangled class-name map.
114
+ * @returns the emitted className and attributes.
69
115
  */
70
116
  declare function transform(szProp: SzObject, prefix?: string, mangleMap?: Record<string, string>): TransformResult;
71
117
  /**
@@ -83,5 +129,5 @@ declare function isValidSzProp(szProp: unknown): szProp is SzObject;
83
129
  */
84
130
  declare function normalizeClassName(className: string): string;
85
131
 
86
- export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, PROPERTY_MAP, SPECIAL_VARIANTS, SUGGESTION_MAP, VARIANT_MAP, getVariantPrefix, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
132
+ export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, MAX_SZ_DEPTH, PROPERTY_MAP, REMOVED_BOOLEAN_SUGAR, SPECIAL_VARIANTS, SUGGESTION_MAP, SzDepthError, VARIANT_MAP, getVariantPrefix, isForbiddenSzKey, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
87
133
  export type { ReadonlySzObject, ReadonlySzValue, SzObject, SzValue, TransformResult };
@@ -1 +1 @@
1
- export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, P as PROPERTY_MAP, S as SPECIAL_VARIANTS, e as SUGGESTION_MAP, V as VARIANT_MAP, b as getVariantPrefix, i as isValidSzProp, f as normalizeArbitraryValue, h as normalizeArbitraryVariant, n as normalizeClassName, t as transform } from './shared/compiler.fR1gse9A.mjs';
1
+ export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, M as MAX_SZ_DEPTH, P as PROPERTY_MAP, R as REMOVED_BOOLEAN_SUGAR, S as SPECIAL_VARIANTS, e as SUGGESTION_MAP, f as SzDepthError, V as VARIANT_MAP, b as getVariantPrefix, h as isForbiddenSzKey, i as isValidSzProp, j as normalizeArbitraryValue, k as normalizeArbitraryVariant, n as normalizeClassName, t as transform } from './shared/compiler.BUCRKtMU.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/compiler",
3
- "version": "0.9.10",
3
+ "version": "0.10.0",
4
4
  "description": "Core compiler and transformation logic for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -60,12 +60,12 @@
60
60
  "dist"
61
61
  ],
62
62
  "dependencies": {
63
- "@babel/core": "^7.23.7",
63
+ "@babel/core": "^7.29.6",
64
64
  "@babel/traverse": "^7.23.7",
65
65
  "@babel/types": "^7.23.6",
66
66
  "magic-string": "0.30.21",
67
67
  "oxc-parser": "0.131.0",
68
- "@csszyx/core": "0.9.10"
68
+ "@csszyx/core": "0.10.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__core": "^7.20.5",