@csszyx/compiler 0.2.0 → 0.3.1
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 +2 -2
- package/dist/index.cjs +134 -27
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +134 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @csszyx/compiler
|
|
2
2
|
|
|
3
|
-
TypeScript compiler package for
|
|
3
|
+
TypeScript compiler package for CSSzyx - handles JSX transformation, recovery token generation, and manifest creation.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -83,7 +83,7 @@ const manifest = builder.build();
|
|
|
83
83
|
|
|
84
84
|
#### `transform(szProp: SzObject, prefix?: string): string`
|
|
85
85
|
|
|
86
|
-
Transforms a
|
|
86
|
+
Transforms a CSSzyx sz object into a Tailwind CSS className string.
|
|
87
87
|
|
|
88
88
|
#### `isValidSzProp(szProp: unknown): boolean`
|
|
89
89
|
|
package/dist/index.cjs
CHANGED
|
@@ -463,6 +463,7 @@ var PROPERTY_MAP = {
|
|
|
463
463
|
color: "text",
|
|
464
464
|
text: "text",
|
|
465
465
|
fontWeight: "font",
|
|
466
|
+
weight: "font",
|
|
466
467
|
fontFamily: "font",
|
|
467
468
|
fontStretch: "font-stretch",
|
|
468
469
|
textAlign: "text",
|
|
@@ -554,9 +555,14 @@ var PROPERTY_MAP = {
|
|
|
554
555
|
scale: "scale",
|
|
555
556
|
scaleX: "scale-x",
|
|
556
557
|
scaleY: "scale-y",
|
|
558
|
+
scaleZ: "scale-z",
|
|
557
559
|
rotate: "rotate",
|
|
560
|
+
rotateX: "rotate-x",
|
|
561
|
+
rotateY: "rotate-y",
|
|
562
|
+
rotateZ: "rotate-z",
|
|
558
563
|
translateX: "translate-x",
|
|
559
564
|
translateY: "translate-y",
|
|
565
|
+
translateZ: "translate-z",
|
|
560
566
|
skewX: "skew-x",
|
|
561
567
|
skewY: "skew-y",
|
|
562
568
|
origin: "origin",
|
|
@@ -564,6 +570,7 @@ var PROPERTY_MAP = {
|
|
|
564
570
|
perspective: "perspective",
|
|
565
571
|
perspectiveOrigin: "perspective-origin",
|
|
566
572
|
transformStyle: "transform",
|
|
573
|
+
transform: "transform",
|
|
567
574
|
// Transitions & Animation
|
|
568
575
|
transition: "transition",
|
|
569
576
|
transitionBehavior: "transition",
|
|
@@ -581,6 +588,8 @@ var PROPERTY_MAP = {
|
|
|
581
588
|
cursor: "cursor",
|
|
582
589
|
caret: "caret",
|
|
583
590
|
pointerEvents: "pointer-events",
|
|
591
|
+
fieldSizing: "field-sizing",
|
|
592
|
+
scheme: "scheme",
|
|
584
593
|
resize: "resize",
|
|
585
594
|
scroll: "scroll",
|
|
586
595
|
scrollM: "scroll-m",
|
|
@@ -954,6 +963,7 @@ var BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
|
|
|
954
963
|
// Misc
|
|
955
964
|
"container",
|
|
956
965
|
"prose",
|
|
966
|
+
"proseInvert",
|
|
957
967
|
"srOnly",
|
|
958
968
|
"notSrOnly",
|
|
959
969
|
"isolate",
|
|
@@ -980,8 +990,7 @@ var BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
|
|
|
980
990
|
"rotate3d",
|
|
981
991
|
"translate3d",
|
|
982
992
|
"transformGpu",
|
|
983
|
-
"transformCpu"
|
|
984
|
-
"transformNone"
|
|
993
|
+
"transformCpu"
|
|
985
994
|
]);
|
|
986
995
|
var BOOLEAN_TO_CLASS = {
|
|
987
996
|
inlineBlock: "inline-block",
|
|
@@ -1019,7 +1028,8 @@ var BOOLEAN_TO_CLASS = {
|
|
|
1019
1028
|
translate3d: "translate-3d",
|
|
1020
1029
|
transformGpu: "transform-gpu",
|
|
1021
1030
|
transformCpu: "transform-cpu",
|
|
1022
|
-
|
|
1031
|
+
// Misc
|
|
1032
|
+
proseInvert: "prose-invert"
|
|
1023
1033
|
};
|
|
1024
1034
|
var SNAP_DIRECT_MAP = {
|
|
1025
1035
|
snapAlign: {
|
|
@@ -1076,10 +1086,16 @@ var NEGATIVE_ALLOWED = /* @__PURE__ */ new Set([
|
|
|
1076
1086
|
"row-start",
|
|
1077
1087
|
"row-end",
|
|
1078
1088
|
"rotate",
|
|
1089
|
+
"rotate-x",
|
|
1090
|
+
"rotate-y",
|
|
1091
|
+
"rotate-z",
|
|
1092
|
+
"scale-z",
|
|
1079
1093
|
"skew-x",
|
|
1080
1094
|
"skew-y",
|
|
1081
1095
|
"translate-x",
|
|
1082
1096
|
"translate-y",
|
|
1097
|
+
"translate-z",
|
|
1098
|
+
"mask",
|
|
1083
1099
|
"space-x",
|
|
1084
1100
|
"space-y",
|
|
1085
1101
|
"tracking",
|
|
@@ -1119,7 +1135,7 @@ function normalizeArbitraryVariant(key) {
|
|
|
1119
1135
|
return key.replace(/\s+/g, "");
|
|
1120
1136
|
}
|
|
1121
1137
|
function normalizeArbitraryValue(value) {
|
|
1122
|
-
return value.trim().replace(/\s
|
|
1138
|
+
return value.trim().replace(/\s+/g, "_");
|
|
1123
1139
|
}
|
|
1124
1140
|
var FRACTION_SUPPORTED_PROPS = /* @__PURE__ */ new Set([
|
|
1125
1141
|
// Sizing (both rawKey and resolved key forms)
|
|
@@ -1160,11 +1176,15 @@ var FRACTION_SUPPORTED_PROPS = /* @__PURE__ */ new Set([
|
|
|
1160
1176
|
"translate-x",
|
|
1161
1177
|
"translateX",
|
|
1162
1178
|
"translate-y",
|
|
1163
|
-
"translateY"
|
|
1179
|
+
"translateY",
|
|
1180
|
+
// Aspect
|
|
1181
|
+
"aspect"
|
|
1164
1182
|
]);
|
|
1165
1183
|
function needsArbitraryBrackets(value) {
|
|
1166
|
-
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || //
|
|
1184
|
+
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || // Positive units
|
|
1185
|
+
/^-\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || // Negative units like -1px, -2rem
|
|
1167
1186
|
/^\.\d+(px|rem|em|%|vh|vw|ch)?$/.test(value) || // Values starting with . like .25em
|
|
1187
|
+
/^-\.\d+(px|rem|em|%|vh|vw|ch)?$/.test(value) || // Negative values starting with -. like -.25em
|
|
1168
1188
|
value.startsWith("#") || // Hex colors
|
|
1169
1189
|
value.startsWith("rgb") || // RGB colors
|
|
1170
1190
|
value.startsWith("hsl") || // HSL colors
|
|
@@ -1616,12 +1636,13 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1616
1636
|
}
|
|
1617
1637
|
let className = prefix;
|
|
1618
1638
|
if (rawKey === "willChange" && typeof value === "string") {
|
|
1619
|
-
|
|
1620
|
-
|
|
1639
|
+
const WILL_CHANGE_KEYWORDS = /* @__PURE__ */ new Set(["auto", "scroll", "contents", "transform"]);
|
|
1640
|
+
if (WILL_CHANGE_KEYWORDS.has(value)) {
|
|
1641
|
+
classes.push(`${prefix}will-change-${value}`);
|
|
1621
1642
|
} else if (value.startsWith("--")) {
|
|
1622
1643
|
classes.push(`${prefix}will-change-(${value})`);
|
|
1623
1644
|
} else {
|
|
1624
|
-
classes.push(`${prefix}will-change
|
|
1645
|
+
classes.push(`${prefix}will-change-[${normalizeArbitraryValue(value)}]`);
|
|
1625
1646
|
}
|
|
1626
1647
|
continue;
|
|
1627
1648
|
}
|
|
@@ -1735,10 +1756,10 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1735
1756
|
continue;
|
|
1736
1757
|
}
|
|
1737
1758
|
if (rawKey === "textOverflow") {
|
|
1738
|
-
if (value === "ellipsis") {
|
|
1739
|
-
classes.push(`${prefix}truncate`);
|
|
1740
|
-
} else {
|
|
1759
|
+
if (value === "ellipsis" || value === "clip") {
|
|
1741
1760
|
classes.push(`${prefix}text-${value}`);
|
|
1761
|
+
} else {
|
|
1762
|
+
classes.push(`${prefix}text-[${value}]`);
|
|
1742
1763
|
}
|
|
1743
1764
|
continue;
|
|
1744
1765
|
}
|
|
@@ -1806,8 +1827,13 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1806
1827
|
className += `font-${sValue}`;
|
|
1807
1828
|
} else if (sValue.startsWith("--")) {
|
|
1808
1829
|
className += `font-stretch-(${sValue})`;
|
|
1809
|
-
} else if (/^\d
|
|
1810
|
-
|
|
1830
|
+
} else if (/^\d+(\.\d+)?%$/.test(sValue)) {
|
|
1831
|
+
const valNum = parseFloat(sValue);
|
|
1832
|
+
if (sValue.includes(".") || !Number.isInteger(valNum)) {
|
|
1833
|
+
className += `font-stretch-[${sValue}]`;
|
|
1834
|
+
} else {
|
|
1835
|
+
className += `font-stretch-${sValue}`;
|
|
1836
|
+
}
|
|
1811
1837
|
} else {
|
|
1812
1838
|
className += `font-stretch-[${sValue}]`;
|
|
1813
1839
|
}
|
|
@@ -1928,6 +1954,17 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1928
1954
|
classes.push(className);
|
|
1929
1955
|
continue;
|
|
1930
1956
|
}
|
|
1957
|
+
if (rawKey === "bgRepeat" || rawKey === "backgroundRepeat") {
|
|
1958
|
+
if (value === "repeat") {
|
|
1959
|
+
className += "bg-repeat";
|
|
1960
|
+
} else if (value === "no-repeat") {
|
|
1961
|
+
className += "bg-no-repeat";
|
|
1962
|
+
} else {
|
|
1963
|
+
className += `bg-repeat-${value}`;
|
|
1964
|
+
}
|
|
1965
|
+
classes.push(className);
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1931
1968
|
if (rawKey === "maskSize") {
|
|
1932
1969
|
className += `mask-${value}`;
|
|
1933
1970
|
classes.push(className);
|
|
@@ -1953,13 +1990,18 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1953
1990
|
classes.push(className);
|
|
1954
1991
|
continue;
|
|
1955
1992
|
}
|
|
1993
|
+
if (rawKey === "alignContent") {
|
|
1994
|
+
className += `content-${value}`;
|
|
1995
|
+
classes.push(className);
|
|
1996
|
+
continue;
|
|
1997
|
+
}
|
|
1956
1998
|
if (rawKey === "content") {
|
|
1957
|
-
if (value
|
|
1999
|
+
if (value === "none") {
|
|
2000
|
+
className += "content-none";
|
|
2001
|
+
} else if (value.startsWith("--")) {
|
|
1958
2002
|
className += `content-(${value})`;
|
|
1959
|
-
} else if (!["none", "empty"].includes(value)) {
|
|
1960
|
-
className += `content-[${value}]`;
|
|
1961
2003
|
} else {
|
|
1962
|
-
className += `content
|
|
2004
|
+
className += `content-[${value}]`;
|
|
1963
2005
|
}
|
|
1964
2006
|
classes.push(className);
|
|
1965
2007
|
continue;
|
|
@@ -2104,7 +2146,6 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2104
2146
|
classes.push(className);
|
|
2105
2147
|
continue;
|
|
2106
2148
|
}
|
|
2107
|
-
const isAspectRatio = key === "aspect" && /^\d+\/\d+$/.test(finalValue);
|
|
2108
2149
|
if (finalValue.startsWith("--")) {
|
|
2109
2150
|
const typeHint = CSS_VAR_TYPE_HINTS[rawKey];
|
|
2110
2151
|
if (typeHint) {
|
|
@@ -2118,10 +2159,19 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2118
2159
|
if (!FRACTION_SUPPORTED_PROPS.has(rawKey)) {
|
|
2119
2160
|
finalValue = `[${finalValue}]`;
|
|
2120
2161
|
}
|
|
2121
|
-
} else if (
|
|
2162
|
+
} else if (key === "aspect" && /^[0-9]+(?:\.[0-9]+)?\/[0-9]+(?:\.[0-9]+)?$/.test(finalValue)) {
|
|
2163
|
+
if (finalValue === "auto" || finalValue === "square" || finalValue === "video" || /^\d+\/\d+$/.test(finalValue)) {
|
|
2164
|
+
} else {
|
|
2165
|
+
finalValue = `[${finalValue}]`;
|
|
2166
|
+
}
|
|
2167
|
+
} else if (needsArbitraryBrackets(finalValue) || /^\d+\.\d+%$/.test(finalValue)) {
|
|
2122
2168
|
finalValue = `[${normalizeArbitraryValue(finalValue)}]`;
|
|
2123
2169
|
}
|
|
2124
|
-
|
|
2170
|
+
if (finalValue.startsWith("-") && NEGATIVE_ALLOWED.has(key)) {
|
|
2171
|
+
className = `-${prefix}${key}-${finalValue.substring(1)}`;
|
|
2172
|
+
} else {
|
|
2173
|
+
className += `${key}-${finalValue}`;
|
|
2174
|
+
}
|
|
2125
2175
|
if (important) {
|
|
2126
2176
|
className += "!";
|
|
2127
2177
|
}
|
|
@@ -2129,7 +2179,7 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2129
2179
|
}
|
|
2130
2180
|
}
|
|
2131
2181
|
let mergedClasses = classes;
|
|
2132
|
-
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(
|
|
2182
|
+
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(xs|sm|base|lg|[2-9]?xl|\[.+\]|\(.+\))$/;
|
|
2133
2183
|
const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
|
|
2134
2184
|
const textEntries = [];
|
|
2135
2185
|
const leadingEntries = [];
|
|
@@ -2146,11 +2196,15 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2146
2196
|
}
|
|
2147
2197
|
if (textEntries.length > 0 && leadingEntries.length > 0) {
|
|
2148
2198
|
const removeIndices = /* @__PURE__ */ new Set();
|
|
2199
|
+
const consumedLeading = /* @__PURE__ */ new Set();
|
|
2149
2200
|
for (const te of textEntries) {
|
|
2150
|
-
const matchingLeading = leadingEntries.find(
|
|
2201
|
+
const matchingLeading = leadingEntries.find(
|
|
2202
|
+
(le) => le.prefix === te.prefix && !consumedLeading.has(le.index)
|
|
2203
|
+
);
|
|
2151
2204
|
if (matchingLeading) {
|
|
2152
2205
|
mergedClasses[te.index] = `${te.prefix}text-${te.size}/${matchingLeading.value}`;
|
|
2153
2206
|
removeIndices.add(matchingLeading.index);
|
|
2207
|
+
consumedLeading.add(matchingLeading.index);
|
|
2154
2208
|
}
|
|
2155
2209
|
}
|
|
2156
2210
|
if (removeIndices.size > 0) {
|
|
@@ -2182,8 +2236,9 @@ function transformSourceCode(source) {
|
|
|
2182
2236
|
let usesRuntime = false;
|
|
2183
2237
|
let usesColorVar = false;
|
|
2184
2238
|
let transformed = false;
|
|
2239
|
+
const collectedClasses = /* @__PURE__ */ new Set();
|
|
2185
2240
|
if (!source.includes("sz")) {
|
|
2186
|
-
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false };
|
|
2241
|
+
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false, classes: collectedClasses };
|
|
2187
2242
|
}
|
|
2188
2243
|
try {
|
|
2189
2244
|
const result = babel.transformSync(source, {
|
|
@@ -2201,12 +2256,29 @@ function transformSourceCode(source) {
|
|
|
2201
2256
|
return {
|
|
2202
2257
|
visitor: {
|
|
2203
2258
|
JSXAttribute(path) {
|
|
2204
|
-
|
|
2259
|
+
const attrName = t.isJSXIdentifier(path.node.name) ? path.node.name.name : "";
|
|
2260
|
+
if (attrName === "className" || attrName === "class") {
|
|
2261
|
+
const val = path.node.value;
|
|
2262
|
+
if (t.isStringLiteral(val)) {
|
|
2263
|
+
for (const c of val.value.split(/\s+/)) {
|
|
2264
|
+
if (c) {
|
|
2265
|
+
collectedClasses.add(c);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
if (attrName !== "sz") {
|
|
2205
2272
|
return;
|
|
2206
2273
|
}
|
|
2207
2274
|
const value = path.node.value;
|
|
2208
2275
|
if (t.isStringLiteral(value)) {
|
|
2209
2276
|
path.node.name.name = "className";
|
|
2277
|
+
for (const c of value.value.split(/\s+/)) {
|
|
2278
|
+
if (c) {
|
|
2279
|
+
collectedClasses.add(c);
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2210
2282
|
transformed = true;
|
|
2211
2283
|
return;
|
|
2212
2284
|
}
|
|
@@ -2216,6 +2288,11 @@ function transformSourceCode(source) {
|
|
|
2216
2288
|
const staticObject = evaluateStaticObject(expression);
|
|
2217
2289
|
if (staticObject !== null) {
|
|
2218
2290
|
const { className, attributes } = transform(staticObject);
|
|
2291
|
+
for (const c of className.split(/\s+/)) {
|
|
2292
|
+
if (c) {
|
|
2293
|
+
collectedClasses.add(c);
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2219
2296
|
path.node.name.name = "className";
|
|
2220
2297
|
path.node.value = t.stringLiteral(className);
|
|
2221
2298
|
Object.entries(attributes).forEach(([key, val]) => {
|
|
@@ -2254,6 +2331,11 @@ function transformSourceCode(source) {
|
|
|
2254
2331
|
);
|
|
2255
2332
|
}
|
|
2256
2333
|
const allClasses = [...staticClasses, ...partial.rawClasses, ...cssVarClasses].join(" ");
|
|
2334
|
+
for (const c of allClasses.split(/\s+/)) {
|
|
2335
|
+
if (c) {
|
|
2336
|
+
collectedClasses.add(c);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2257
2339
|
path.node.name.name = "className";
|
|
2258
2340
|
path.node.value = t.stringLiteral(allClasses);
|
|
2259
2341
|
if (styleProps.length > 0 && path.parentPath?.isJSXOpeningElement()) {
|
|
@@ -2282,8 +2364,14 @@ function transformSourceCode(source) {
|
|
|
2282
2364
|
path.node.name.name = "className";
|
|
2283
2365
|
if (t.isStringLiteral(resolved)) {
|
|
2284
2366
|
path.node.value = resolved;
|
|
2367
|
+
for (const c of resolved.value.split(/\s+/)) {
|
|
2368
|
+
if (c) {
|
|
2369
|
+
collectedClasses.add(c);
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2285
2372
|
} else {
|
|
2286
2373
|
value.expression = resolved;
|
|
2374
|
+
collectFromExpr(resolved, collectedClasses);
|
|
2287
2375
|
}
|
|
2288
2376
|
transformed = true;
|
|
2289
2377
|
return;
|
|
@@ -2297,8 +2385,14 @@ function transformSourceCode(source) {
|
|
|
2297
2385
|
path.node.name.name = "className";
|
|
2298
2386
|
if (t.isStringLiteral(resolved)) {
|
|
2299
2387
|
path.node.value = resolved;
|
|
2388
|
+
for (const c of resolved.value.split(/\s+/)) {
|
|
2389
|
+
if (c) {
|
|
2390
|
+
collectedClasses.add(c);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2300
2393
|
} else {
|
|
2301
2394
|
value.expression = resolved;
|
|
2395
|
+
collectFromExpr(resolved, collectedClasses);
|
|
2302
2396
|
}
|
|
2303
2397
|
transformed = true;
|
|
2304
2398
|
return;
|
|
@@ -2323,11 +2417,12 @@ function transformSourceCode(source) {
|
|
|
2323
2417
|
code: result?.code || source,
|
|
2324
2418
|
transformed,
|
|
2325
2419
|
usesRuntime,
|
|
2326
|
-
usesColorVar
|
|
2420
|
+
usesColorVar,
|
|
2421
|
+
classes: collectedClasses
|
|
2327
2422
|
};
|
|
2328
2423
|
} catch (e) {
|
|
2329
2424
|
console.warn("[csszyx] AST transform failed, falling back to original code:", e);
|
|
2330
|
-
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false };
|
|
2425
|
+
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false, classes: collectedClasses };
|
|
2331
2426
|
}
|
|
2332
2427
|
}
|
|
2333
2428
|
function tryStaticTransformNode(node) {
|
|
@@ -2566,6 +2661,18 @@ function generateStyleValueExpression(info) {
|
|
|
2566
2661
|
);
|
|
2567
2662
|
}
|
|
2568
2663
|
}
|
|
2664
|
+
function collectFromExpr(node, classes) {
|
|
2665
|
+
if (t.isStringLiteral(node)) {
|
|
2666
|
+
for (const c of node.value.split(/\s+/)) {
|
|
2667
|
+
if (c) {
|
|
2668
|
+
classes.add(c);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
} else if (t.isConditionalExpression(node)) {
|
|
2672
|
+
collectFromExpr(node.consequent, classes);
|
|
2673
|
+
collectFromExpr(node.alternate, classes);
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2569
2676
|
function buildCSSVarClassName(info) {
|
|
2570
2677
|
const { twPrefix, varName, variantChain } = info;
|
|
2571
2678
|
const variantPrefix = variantChain ? `${getVariantPrefix(variantChain)}:` : "";
|
package/dist/index.d.cts
CHANGED
|
@@ -61,6 +61,7 @@ declare function transformSourceCode(source: string): {
|
|
|
61
61
|
transformed: boolean;
|
|
62
62
|
usesRuntime: boolean;
|
|
63
63
|
usesColorVar: boolean;
|
|
64
|
+
classes: Set<string>;
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -606,6 +607,8 @@ interface LayoutProps {
|
|
|
606
607
|
container?: boolean;
|
|
607
608
|
/** Boolean sugar for prose */
|
|
608
609
|
prose?: boolean;
|
|
610
|
+
/** Boolean sugar for prose-invert (requires @tailwindcss/typography plugin) */
|
|
611
|
+
proseInvert?: boolean;
|
|
609
612
|
/** @see https://tailwindcss.com/docs/float */
|
|
610
613
|
float?: 'right' | 'left' | 'start' | 'end' | 'none';
|
|
611
614
|
/** @see https://tailwindcss.com/docs/clear */
|
|
@@ -704,6 +707,8 @@ interface FlexboxGridProps {
|
|
|
704
707
|
justifyItems?: 'start' | 'end' | 'center' | 'stretch' | 'normal' | 'safe-center' | 'safe-end';
|
|
705
708
|
/** @see https://tailwindcss.com/docs/justify-self */
|
|
706
709
|
justifySelf?: 'auto' | 'start' | 'end' | 'center' | 'stretch' | 'safe-center' | 'safe-end';
|
|
710
|
+
/** @see https://tailwindcss.com/docs/align-content */
|
|
711
|
+
alignContent?: 'normal' | 'start' | 'end' | 'center' | 'between' | 'around' | 'evenly' | 'baseline' | 'stretch';
|
|
707
712
|
/** @see https://tailwindcss.com/docs/align-items */
|
|
708
713
|
items?: 'start' | 'end' | 'center' | 'baseline' | 'stretch' | 'safe-center' | 'safe-end' | (string & {});
|
|
709
714
|
/** @see https://tailwindcss.com/docs/align-self */
|
|
@@ -884,8 +889,8 @@ interface TypographyProps {
|
|
|
884
889
|
break?: 'normal' | 'all' | 'keep';
|
|
885
890
|
/** @see https://tailwindcss.com/docs/hyphens */
|
|
886
891
|
hyphens?: 'none' | 'manual' | 'auto';
|
|
887
|
-
/** @see https://tailwindcss.com/docs/content
|
|
888
|
-
content?: 'none' |
|
|
892
|
+
/** @see https://tailwindcss.com/docs/content */
|
|
893
|
+
content?: 'none' | (string & {});
|
|
889
894
|
/** @see https://tailwindcss.com/docs/font-feature-settings */
|
|
890
895
|
fontFeatures?: string & {};
|
|
891
896
|
/** @see https://tailwindcss.com/docs/forced-color-adjust */
|
|
@@ -1066,15 +1071,25 @@ interface TransformProps {
|
|
|
1066
1071
|
scale?: 0 | 50 | 75 | 90 | 95 | 100 | 105 | 110 | 125 | 150 | 200 | number | (string & {});
|
|
1067
1072
|
scaleX?: TransformProps['scale'];
|
|
1068
1073
|
scaleY?: TransformProps['scale'];
|
|
1074
|
+
/** @see https://tailwindcss.com/docs/scale (Z-axis, 3D) */
|
|
1075
|
+
scaleZ?: TransformProps['scale'];
|
|
1069
1076
|
/** Boolean sugar for 3D scale */
|
|
1070
1077
|
scale3d?: boolean;
|
|
1071
1078
|
/** @see https://tailwindcss.com/docs/rotate */
|
|
1072
1079
|
rotate?: 0 | 1 | 2 | 3 | 6 | 12 | 45 | 90 | 180 | number | (string & {});
|
|
1080
|
+
/** @see https://tailwindcss.com/docs/rotate (X-axis, 3D) */
|
|
1081
|
+
rotateX?: TransformProps['rotate'];
|
|
1082
|
+
/** @see https://tailwindcss.com/docs/rotate (Y-axis, 3D) */
|
|
1083
|
+
rotateY?: TransformProps['rotate'];
|
|
1084
|
+
/** @see https://tailwindcss.com/docs/rotate (Z-axis, 3D) */
|
|
1085
|
+
rotateZ?: TransformProps['rotate'];
|
|
1073
1086
|
/** Boolean sugar for 3D rotate */
|
|
1074
1087
|
rotate3d?: boolean;
|
|
1075
1088
|
/** @see https://tailwindcss.com/docs/translate */
|
|
1076
1089
|
translateX?: SpacingValue | FractionValue;
|
|
1077
1090
|
translateY?: SpacingValue | FractionValue;
|
|
1091
|
+
/** @see https://tailwindcss.com/docs/translate (Z-axis, 3D) */
|
|
1092
|
+
translateZ?: SpacingValue;
|
|
1078
1093
|
/** Boolean sugar for 3D translate */
|
|
1079
1094
|
translate3d?: boolean;
|
|
1080
1095
|
/** @see https://tailwindcss.com/docs/skew */
|
|
@@ -1085,7 +1100,8 @@ interface TransformProps {
|
|
|
1085
1100
|
/** Transform rendering hints */
|
|
1086
1101
|
transformGpu?: boolean;
|
|
1087
1102
|
transformCpu?: boolean;
|
|
1088
|
-
|
|
1103
|
+
/** @see https://tailwindcss.com/docs/transform */
|
|
1104
|
+
transform?: 'none';
|
|
1089
1105
|
/** @see https://tailwindcss.com/docs/perspective */
|
|
1090
1106
|
perspective?: 'none' | (string & {});
|
|
1091
1107
|
perspectiveOrigin?: (string & {});
|
|
@@ -1121,6 +1137,10 @@ interface InteractivityProps {
|
|
|
1121
1137
|
caret?: 'auto' | ColorPropValue;
|
|
1122
1138
|
/** @see https://tailwindcss.com/docs/pointer-events */
|
|
1123
1139
|
pointerEvents?: 'none' | 'auto';
|
|
1140
|
+
/** @see https://tailwindcss.com/docs/field-sizing */
|
|
1141
|
+
fieldSizing?: 'fixed' | 'content';
|
|
1142
|
+
/** @see https://tailwindcss.com/docs/color-scheme */
|
|
1143
|
+
scheme?: 'normal' | 'dark' | 'light' | 'light-dark' | 'only-dark' | 'only-light';
|
|
1124
1144
|
/** @see https://tailwindcss.com/docs/resize */
|
|
1125
1145
|
resize?: 'none' | 'y' | 'x' | boolean;
|
|
1126
1146
|
/** @see https://tailwindcss.com/docs/scroll-behavior */
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ declare function transformSourceCode(source: string): {
|
|
|
61
61
|
transformed: boolean;
|
|
62
62
|
usesRuntime: boolean;
|
|
63
63
|
usesColorVar: boolean;
|
|
64
|
+
classes: Set<string>;
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -606,6 +607,8 @@ interface LayoutProps {
|
|
|
606
607
|
container?: boolean;
|
|
607
608
|
/** Boolean sugar for prose */
|
|
608
609
|
prose?: boolean;
|
|
610
|
+
/** Boolean sugar for prose-invert (requires @tailwindcss/typography plugin) */
|
|
611
|
+
proseInvert?: boolean;
|
|
609
612
|
/** @see https://tailwindcss.com/docs/float */
|
|
610
613
|
float?: 'right' | 'left' | 'start' | 'end' | 'none';
|
|
611
614
|
/** @see https://tailwindcss.com/docs/clear */
|
|
@@ -704,6 +707,8 @@ interface FlexboxGridProps {
|
|
|
704
707
|
justifyItems?: 'start' | 'end' | 'center' | 'stretch' | 'normal' | 'safe-center' | 'safe-end';
|
|
705
708
|
/** @see https://tailwindcss.com/docs/justify-self */
|
|
706
709
|
justifySelf?: 'auto' | 'start' | 'end' | 'center' | 'stretch' | 'safe-center' | 'safe-end';
|
|
710
|
+
/** @see https://tailwindcss.com/docs/align-content */
|
|
711
|
+
alignContent?: 'normal' | 'start' | 'end' | 'center' | 'between' | 'around' | 'evenly' | 'baseline' | 'stretch';
|
|
707
712
|
/** @see https://tailwindcss.com/docs/align-items */
|
|
708
713
|
items?: 'start' | 'end' | 'center' | 'baseline' | 'stretch' | 'safe-center' | 'safe-end' | (string & {});
|
|
709
714
|
/** @see https://tailwindcss.com/docs/align-self */
|
|
@@ -884,8 +889,8 @@ interface TypographyProps {
|
|
|
884
889
|
break?: 'normal' | 'all' | 'keep';
|
|
885
890
|
/** @see https://tailwindcss.com/docs/hyphens */
|
|
886
891
|
hyphens?: 'none' | 'manual' | 'auto';
|
|
887
|
-
/** @see https://tailwindcss.com/docs/content
|
|
888
|
-
content?: 'none' |
|
|
892
|
+
/** @see https://tailwindcss.com/docs/content */
|
|
893
|
+
content?: 'none' | (string & {});
|
|
889
894
|
/** @see https://tailwindcss.com/docs/font-feature-settings */
|
|
890
895
|
fontFeatures?: string & {};
|
|
891
896
|
/** @see https://tailwindcss.com/docs/forced-color-adjust */
|
|
@@ -1066,15 +1071,25 @@ interface TransformProps {
|
|
|
1066
1071
|
scale?: 0 | 50 | 75 | 90 | 95 | 100 | 105 | 110 | 125 | 150 | 200 | number | (string & {});
|
|
1067
1072
|
scaleX?: TransformProps['scale'];
|
|
1068
1073
|
scaleY?: TransformProps['scale'];
|
|
1074
|
+
/** @see https://tailwindcss.com/docs/scale (Z-axis, 3D) */
|
|
1075
|
+
scaleZ?: TransformProps['scale'];
|
|
1069
1076
|
/** Boolean sugar for 3D scale */
|
|
1070
1077
|
scale3d?: boolean;
|
|
1071
1078
|
/** @see https://tailwindcss.com/docs/rotate */
|
|
1072
1079
|
rotate?: 0 | 1 | 2 | 3 | 6 | 12 | 45 | 90 | 180 | number | (string & {});
|
|
1080
|
+
/** @see https://tailwindcss.com/docs/rotate (X-axis, 3D) */
|
|
1081
|
+
rotateX?: TransformProps['rotate'];
|
|
1082
|
+
/** @see https://tailwindcss.com/docs/rotate (Y-axis, 3D) */
|
|
1083
|
+
rotateY?: TransformProps['rotate'];
|
|
1084
|
+
/** @see https://tailwindcss.com/docs/rotate (Z-axis, 3D) */
|
|
1085
|
+
rotateZ?: TransformProps['rotate'];
|
|
1073
1086
|
/** Boolean sugar for 3D rotate */
|
|
1074
1087
|
rotate3d?: boolean;
|
|
1075
1088
|
/** @see https://tailwindcss.com/docs/translate */
|
|
1076
1089
|
translateX?: SpacingValue | FractionValue;
|
|
1077
1090
|
translateY?: SpacingValue | FractionValue;
|
|
1091
|
+
/** @see https://tailwindcss.com/docs/translate (Z-axis, 3D) */
|
|
1092
|
+
translateZ?: SpacingValue;
|
|
1078
1093
|
/** Boolean sugar for 3D translate */
|
|
1079
1094
|
translate3d?: boolean;
|
|
1080
1095
|
/** @see https://tailwindcss.com/docs/skew */
|
|
@@ -1085,7 +1100,8 @@ interface TransformProps {
|
|
|
1085
1100
|
/** Transform rendering hints */
|
|
1086
1101
|
transformGpu?: boolean;
|
|
1087
1102
|
transformCpu?: boolean;
|
|
1088
|
-
|
|
1103
|
+
/** @see https://tailwindcss.com/docs/transform */
|
|
1104
|
+
transform?: 'none';
|
|
1089
1105
|
/** @see https://tailwindcss.com/docs/perspective */
|
|
1090
1106
|
perspective?: 'none' | (string & {});
|
|
1091
1107
|
perspectiveOrigin?: (string & {});
|
|
@@ -1121,6 +1137,10 @@ interface InteractivityProps {
|
|
|
1121
1137
|
caret?: 'auto' | ColorPropValue;
|
|
1122
1138
|
/** @see https://tailwindcss.com/docs/pointer-events */
|
|
1123
1139
|
pointerEvents?: 'none' | 'auto';
|
|
1140
|
+
/** @see https://tailwindcss.com/docs/field-sizing */
|
|
1141
|
+
fieldSizing?: 'fixed' | 'content';
|
|
1142
|
+
/** @see https://tailwindcss.com/docs/color-scheme */
|
|
1143
|
+
scheme?: 'normal' | 'dark' | 'light' | 'light-dark' | 'only-dark' | 'only-light';
|
|
1124
1144
|
/** @see https://tailwindcss.com/docs/resize */
|
|
1125
1145
|
resize?: 'none' | 'y' | 'x' | boolean;
|
|
1126
1146
|
/** @see https://tailwindcss.com/docs/scroll-behavior */
|
package/dist/index.js
CHANGED
|
@@ -411,6 +411,7 @@ var PROPERTY_MAP = {
|
|
|
411
411
|
color: "text",
|
|
412
412
|
text: "text",
|
|
413
413
|
fontWeight: "font",
|
|
414
|
+
weight: "font",
|
|
414
415
|
fontFamily: "font",
|
|
415
416
|
fontStretch: "font-stretch",
|
|
416
417
|
textAlign: "text",
|
|
@@ -502,9 +503,14 @@ var PROPERTY_MAP = {
|
|
|
502
503
|
scale: "scale",
|
|
503
504
|
scaleX: "scale-x",
|
|
504
505
|
scaleY: "scale-y",
|
|
506
|
+
scaleZ: "scale-z",
|
|
505
507
|
rotate: "rotate",
|
|
508
|
+
rotateX: "rotate-x",
|
|
509
|
+
rotateY: "rotate-y",
|
|
510
|
+
rotateZ: "rotate-z",
|
|
506
511
|
translateX: "translate-x",
|
|
507
512
|
translateY: "translate-y",
|
|
513
|
+
translateZ: "translate-z",
|
|
508
514
|
skewX: "skew-x",
|
|
509
515
|
skewY: "skew-y",
|
|
510
516
|
origin: "origin",
|
|
@@ -512,6 +518,7 @@ var PROPERTY_MAP = {
|
|
|
512
518
|
perspective: "perspective",
|
|
513
519
|
perspectiveOrigin: "perspective-origin",
|
|
514
520
|
transformStyle: "transform",
|
|
521
|
+
transform: "transform",
|
|
515
522
|
// Transitions & Animation
|
|
516
523
|
transition: "transition",
|
|
517
524
|
transitionBehavior: "transition",
|
|
@@ -529,6 +536,8 @@ var PROPERTY_MAP = {
|
|
|
529
536
|
cursor: "cursor",
|
|
530
537
|
caret: "caret",
|
|
531
538
|
pointerEvents: "pointer-events",
|
|
539
|
+
fieldSizing: "field-sizing",
|
|
540
|
+
scheme: "scheme",
|
|
532
541
|
resize: "resize",
|
|
533
542
|
scroll: "scroll",
|
|
534
543
|
scrollM: "scroll-m",
|
|
@@ -902,6 +911,7 @@ var BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
|
|
|
902
911
|
// Misc
|
|
903
912
|
"container",
|
|
904
913
|
"prose",
|
|
914
|
+
"proseInvert",
|
|
905
915
|
"srOnly",
|
|
906
916
|
"notSrOnly",
|
|
907
917
|
"isolate",
|
|
@@ -928,8 +938,7 @@ var BOOLEAN_SHORTHANDS = /* @__PURE__ */ new Set([
|
|
|
928
938
|
"rotate3d",
|
|
929
939
|
"translate3d",
|
|
930
940
|
"transformGpu",
|
|
931
|
-
"transformCpu"
|
|
932
|
-
"transformNone"
|
|
941
|
+
"transformCpu"
|
|
933
942
|
]);
|
|
934
943
|
var BOOLEAN_TO_CLASS = {
|
|
935
944
|
inlineBlock: "inline-block",
|
|
@@ -967,7 +976,8 @@ var BOOLEAN_TO_CLASS = {
|
|
|
967
976
|
translate3d: "translate-3d",
|
|
968
977
|
transformGpu: "transform-gpu",
|
|
969
978
|
transformCpu: "transform-cpu",
|
|
970
|
-
|
|
979
|
+
// Misc
|
|
980
|
+
proseInvert: "prose-invert"
|
|
971
981
|
};
|
|
972
982
|
var SNAP_DIRECT_MAP = {
|
|
973
983
|
snapAlign: {
|
|
@@ -1024,10 +1034,16 @@ var NEGATIVE_ALLOWED = /* @__PURE__ */ new Set([
|
|
|
1024
1034
|
"row-start",
|
|
1025
1035
|
"row-end",
|
|
1026
1036
|
"rotate",
|
|
1037
|
+
"rotate-x",
|
|
1038
|
+
"rotate-y",
|
|
1039
|
+
"rotate-z",
|
|
1040
|
+
"scale-z",
|
|
1027
1041
|
"skew-x",
|
|
1028
1042
|
"skew-y",
|
|
1029
1043
|
"translate-x",
|
|
1030
1044
|
"translate-y",
|
|
1045
|
+
"translate-z",
|
|
1046
|
+
"mask",
|
|
1031
1047
|
"space-x",
|
|
1032
1048
|
"space-y",
|
|
1033
1049
|
"tracking",
|
|
@@ -1067,7 +1083,7 @@ function normalizeArbitraryVariant(key) {
|
|
|
1067
1083
|
return key.replace(/\s+/g, "");
|
|
1068
1084
|
}
|
|
1069
1085
|
function normalizeArbitraryValue(value) {
|
|
1070
|
-
return value.trim().replace(/\s
|
|
1086
|
+
return value.trim().replace(/\s+/g, "_");
|
|
1071
1087
|
}
|
|
1072
1088
|
var FRACTION_SUPPORTED_PROPS = /* @__PURE__ */ new Set([
|
|
1073
1089
|
// Sizing (both rawKey and resolved key forms)
|
|
@@ -1108,11 +1124,15 @@ var FRACTION_SUPPORTED_PROPS = /* @__PURE__ */ new Set([
|
|
|
1108
1124
|
"translate-x",
|
|
1109
1125
|
"translateX",
|
|
1110
1126
|
"translate-y",
|
|
1111
|
-
"translateY"
|
|
1127
|
+
"translateY",
|
|
1128
|
+
// Aspect
|
|
1129
|
+
"aspect"
|
|
1112
1130
|
]);
|
|
1113
1131
|
function needsArbitraryBrackets(value) {
|
|
1114
|
-
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || //
|
|
1132
|
+
return /^\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || // Positive units
|
|
1133
|
+
/^-\d+(\.\d+)?(px|rem|em|%|vh|vw|ch|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|deg|rad|turn|grad|ms|s|fr)$/.test(value) || // Negative units like -1px, -2rem
|
|
1115
1134
|
/^\.\d+(px|rem|em|%|vh|vw|ch)?$/.test(value) || // Values starting with . like .25em
|
|
1135
|
+
/^-\.\d+(px|rem|em|%|vh|vw|ch)?$/.test(value) || // Negative values starting with -. like -.25em
|
|
1116
1136
|
value.startsWith("#") || // Hex colors
|
|
1117
1137
|
value.startsWith("rgb") || // RGB colors
|
|
1118
1138
|
value.startsWith("hsl") || // HSL colors
|
|
@@ -1564,12 +1584,13 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1564
1584
|
}
|
|
1565
1585
|
let className = prefix;
|
|
1566
1586
|
if (rawKey === "willChange" && typeof value === "string") {
|
|
1567
|
-
|
|
1568
|
-
|
|
1587
|
+
const WILL_CHANGE_KEYWORDS = /* @__PURE__ */ new Set(["auto", "scroll", "contents", "transform"]);
|
|
1588
|
+
if (WILL_CHANGE_KEYWORDS.has(value)) {
|
|
1589
|
+
classes.push(`${prefix}will-change-${value}`);
|
|
1569
1590
|
} else if (value.startsWith("--")) {
|
|
1570
1591
|
classes.push(`${prefix}will-change-(${value})`);
|
|
1571
1592
|
} else {
|
|
1572
|
-
classes.push(`${prefix}will-change
|
|
1593
|
+
classes.push(`${prefix}will-change-[${normalizeArbitraryValue(value)}]`);
|
|
1573
1594
|
}
|
|
1574
1595
|
continue;
|
|
1575
1596
|
}
|
|
@@ -1683,10 +1704,10 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1683
1704
|
continue;
|
|
1684
1705
|
}
|
|
1685
1706
|
if (rawKey === "textOverflow") {
|
|
1686
|
-
if (value === "ellipsis") {
|
|
1687
|
-
classes.push(`${prefix}truncate`);
|
|
1688
|
-
} else {
|
|
1707
|
+
if (value === "ellipsis" || value === "clip") {
|
|
1689
1708
|
classes.push(`${prefix}text-${value}`);
|
|
1709
|
+
} else {
|
|
1710
|
+
classes.push(`${prefix}text-[${value}]`);
|
|
1690
1711
|
}
|
|
1691
1712
|
continue;
|
|
1692
1713
|
}
|
|
@@ -1754,8 +1775,13 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1754
1775
|
className += `font-${sValue}`;
|
|
1755
1776
|
} else if (sValue.startsWith("--")) {
|
|
1756
1777
|
className += `font-stretch-(${sValue})`;
|
|
1757
|
-
} else if (/^\d
|
|
1758
|
-
|
|
1778
|
+
} else if (/^\d+(\.\d+)?%$/.test(sValue)) {
|
|
1779
|
+
const valNum = parseFloat(sValue);
|
|
1780
|
+
if (sValue.includes(".") || !Number.isInteger(valNum)) {
|
|
1781
|
+
className += `font-stretch-[${sValue}]`;
|
|
1782
|
+
} else {
|
|
1783
|
+
className += `font-stretch-${sValue}`;
|
|
1784
|
+
}
|
|
1759
1785
|
} else {
|
|
1760
1786
|
className += `font-stretch-[${sValue}]`;
|
|
1761
1787
|
}
|
|
@@ -1876,6 +1902,17 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1876
1902
|
classes.push(className);
|
|
1877
1903
|
continue;
|
|
1878
1904
|
}
|
|
1905
|
+
if (rawKey === "bgRepeat" || rawKey === "backgroundRepeat") {
|
|
1906
|
+
if (value === "repeat") {
|
|
1907
|
+
className += "bg-repeat";
|
|
1908
|
+
} else if (value === "no-repeat") {
|
|
1909
|
+
className += "bg-no-repeat";
|
|
1910
|
+
} else {
|
|
1911
|
+
className += `bg-repeat-${value}`;
|
|
1912
|
+
}
|
|
1913
|
+
classes.push(className);
|
|
1914
|
+
continue;
|
|
1915
|
+
}
|
|
1879
1916
|
if (rawKey === "maskSize") {
|
|
1880
1917
|
className += `mask-${value}`;
|
|
1881
1918
|
classes.push(className);
|
|
@@ -1901,13 +1938,18 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1901
1938
|
classes.push(className);
|
|
1902
1939
|
continue;
|
|
1903
1940
|
}
|
|
1941
|
+
if (rawKey === "alignContent") {
|
|
1942
|
+
className += `content-${value}`;
|
|
1943
|
+
classes.push(className);
|
|
1944
|
+
continue;
|
|
1945
|
+
}
|
|
1904
1946
|
if (rawKey === "content") {
|
|
1905
|
-
if (value
|
|
1947
|
+
if (value === "none") {
|
|
1948
|
+
className += "content-none";
|
|
1949
|
+
} else if (value.startsWith("--")) {
|
|
1906
1950
|
className += `content-(${value})`;
|
|
1907
|
-
} else if (!["none", "empty"].includes(value)) {
|
|
1908
|
-
className += `content-[${value}]`;
|
|
1909
1951
|
} else {
|
|
1910
|
-
className += `content
|
|
1952
|
+
className += `content-[${value}]`;
|
|
1911
1953
|
}
|
|
1912
1954
|
classes.push(className);
|
|
1913
1955
|
continue;
|
|
@@ -2052,7 +2094,6 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2052
2094
|
classes.push(className);
|
|
2053
2095
|
continue;
|
|
2054
2096
|
}
|
|
2055
|
-
const isAspectRatio = key === "aspect" && /^\d+\/\d+$/.test(finalValue);
|
|
2056
2097
|
if (finalValue.startsWith("--")) {
|
|
2057
2098
|
const typeHint = CSS_VAR_TYPE_HINTS[rawKey];
|
|
2058
2099
|
if (typeHint) {
|
|
@@ -2066,10 +2107,19 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2066
2107
|
if (!FRACTION_SUPPORTED_PROPS.has(rawKey)) {
|
|
2067
2108
|
finalValue = `[${finalValue}]`;
|
|
2068
2109
|
}
|
|
2069
|
-
} else if (
|
|
2110
|
+
} else if (key === "aspect" && /^[0-9]+(?:\.[0-9]+)?\/[0-9]+(?:\.[0-9]+)?$/.test(finalValue)) {
|
|
2111
|
+
if (finalValue === "auto" || finalValue === "square" || finalValue === "video" || /^\d+\/\d+$/.test(finalValue)) {
|
|
2112
|
+
} else {
|
|
2113
|
+
finalValue = `[${finalValue}]`;
|
|
2114
|
+
}
|
|
2115
|
+
} else if (needsArbitraryBrackets(finalValue) || /^\d+\.\d+%$/.test(finalValue)) {
|
|
2070
2116
|
finalValue = `[${normalizeArbitraryValue(finalValue)}]`;
|
|
2071
2117
|
}
|
|
2072
|
-
|
|
2118
|
+
if (finalValue.startsWith("-") && NEGATIVE_ALLOWED.has(key)) {
|
|
2119
|
+
className = `-${prefix}${key}-${finalValue.substring(1)}`;
|
|
2120
|
+
} else {
|
|
2121
|
+
className += `${key}-${finalValue}`;
|
|
2122
|
+
}
|
|
2073
2123
|
if (important) {
|
|
2074
2124
|
className += "!";
|
|
2075
2125
|
}
|
|
@@ -2077,7 +2127,7 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2077
2127
|
}
|
|
2078
2128
|
}
|
|
2079
2129
|
let mergedClasses = classes;
|
|
2080
|
-
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(
|
|
2130
|
+
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(xs|sm|base|lg|[2-9]?xl|\[.+\]|\(.+\))$/;
|
|
2081
2131
|
const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
|
|
2082
2132
|
const textEntries = [];
|
|
2083
2133
|
const leadingEntries = [];
|
|
@@ -2094,11 +2144,15 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
2094
2144
|
}
|
|
2095
2145
|
if (textEntries.length > 0 && leadingEntries.length > 0) {
|
|
2096
2146
|
const removeIndices = /* @__PURE__ */ new Set();
|
|
2147
|
+
const consumedLeading = /* @__PURE__ */ new Set();
|
|
2097
2148
|
for (const te of textEntries) {
|
|
2098
|
-
const matchingLeading = leadingEntries.find(
|
|
2149
|
+
const matchingLeading = leadingEntries.find(
|
|
2150
|
+
(le) => le.prefix === te.prefix && !consumedLeading.has(le.index)
|
|
2151
|
+
);
|
|
2099
2152
|
if (matchingLeading) {
|
|
2100
2153
|
mergedClasses[te.index] = `${te.prefix}text-${te.size}/${matchingLeading.value}`;
|
|
2101
2154
|
removeIndices.add(matchingLeading.index);
|
|
2155
|
+
consumedLeading.add(matchingLeading.index);
|
|
2102
2156
|
}
|
|
2103
2157
|
}
|
|
2104
2158
|
if (removeIndices.size > 0) {
|
|
@@ -2130,8 +2184,9 @@ function transformSourceCode(source) {
|
|
|
2130
2184
|
let usesRuntime = false;
|
|
2131
2185
|
let usesColorVar = false;
|
|
2132
2186
|
let transformed = false;
|
|
2187
|
+
const collectedClasses = /* @__PURE__ */ new Set();
|
|
2133
2188
|
if (!source.includes("sz")) {
|
|
2134
|
-
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false };
|
|
2189
|
+
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false, classes: collectedClasses };
|
|
2135
2190
|
}
|
|
2136
2191
|
try {
|
|
2137
2192
|
const result = babel.transformSync(source, {
|
|
@@ -2149,12 +2204,29 @@ function transformSourceCode(source) {
|
|
|
2149
2204
|
return {
|
|
2150
2205
|
visitor: {
|
|
2151
2206
|
JSXAttribute(path) {
|
|
2152
|
-
|
|
2207
|
+
const attrName = t.isJSXIdentifier(path.node.name) ? path.node.name.name : "";
|
|
2208
|
+
if (attrName === "className" || attrName === "class") {
|
|
2209
|
+
const val = path.node.value;
|
|
2210
|
+
if (t.isStringLiteral(val)) {
|
|
2211
|
+
for (const c of val.value.split(/\s+/)) {
|
|
2212
|
+
if (c) {
|
|
2213
|
+
collectedClasses.add(c);
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
if (attrName !== "sz") {
|
|
2153
2220
|
return;
|
|
2154
2221
|
}
|
|
2155
2222
|
const value = path.node.value;
|
|
2156
2223
|
if (t.isStringLiteral(value)) {
|
|
2157
2224
|
path.node.name.name = "className";
|
|
2225
|
+
for (const c of value.value.split(/\s+/)) {
|
|
2226
|
+
if (c) {
|
|
2227
|
+
collectedClasses.add(c);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2158
2230
|
transformed = true;
|
|
2159
2231
|
return;
|
|
2160
2232
|
}
|
|
@@ -2164,6 +2236,11 @@ function transformSourceCode(source) {
|
|
|
2164
2236
|
const staticObject = evaluateStaticObject(expression);
|
|
2165
2237
|
if (staticObject !== null) {
|
|
2166
2238
|
const { className, attributes } = transform(staticObject);
|
|
2239
|
+
for (const c of className.split(/\s+/)) {
|
|
2240
|
+
if (c) {
|
|
2241
|
+
collectedClasses.add(c);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2167
2244
|
path.node.name.name = "className";
|
|
2168
2245
|
path.node.value = t.stringLiteral(className);
|
|
2169
2246
|
Object.entries(attributes).forEach(([key, val]) => {
|
|
@@ -2202,6 +2279,11 @@ function transformSourceCode(source) {
|
|
|
2202
2279
|
);
|
|
2203
2280
|
}
|
|
2204
2281
|
const allClasses = [...staticClasses, ...partial.rawClasses, ...cssVarClasses].join(" ");
|
|
2282
|
+
for (const c of allClasses.split(/\s+/)) {
|
|
2283
|
+
if (c) {
|
|
2284
|
+
collectedClasses.add(c);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2205
2287
|
path.node.name.name = "className";
|
|
2206
2288
|
path.node.value = t.stringLiteral(allClasses);
|
|
2207
2289
|
if (styleProps.length > 0 && path.parentPath?.isJSXOpeningElement()) {
|
|
@@ -2230,8 +2312,14 @@ function transformSourceCode(source) {
|
|
|
2230
2312
|
path.node.name.name = "className";
|
|
2231
2313
|
if (t.isStringLiteral(resolved)) {
|
|
2232
2314
|
path.node.value = resolved;
|
|
2315
|
+
for (const c of resolved.value.split(/\s+/)) {
|
|
2316
|
+
if (c) {
|
|
2317
|
+
collectedClasses.add(c);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2233
2320
|
} else {
|
|
2234
2321
|
value.expression = resolved;
|
|
2322
|
+
collectFromExpr(resolved, collectedClasses);
|
|
2235
2323
|
}
|
|
2236
2324
|
transformed = true;
|
|
2237
2325
|
return;
|
|
@@ -2245,8 +2333,14 @@ function transformSourceCode(source) {
|
|
|
2245
2333
|
path.node.name.name = "className";
|
|
2246
2334
|
if (t.isStringLiteral(resolved)) {
|
|
2247
2335
|
path.node.value = resolved;
|
|
2336
|
+
for (const c of resolved.value.split(/\s+/)) {
|
|
2337
|
+
if (c) {
|
|
2338
|
+
collectedClasses.add(c);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2248
2341
|
} else {
|
|
2249
2342
|
value.expression = resolved;
|
|
2343
|
+
collectFromExpr(resolved, collectedClasses);
|
|
2250
2344
|
}
|
|
2251
2345
|
transformed = true;
|
|
2252
2346
|
return;
|
|
@@ -2271,11 +2365,12 @@ function transformSourceCode(source) {
|
|
|
2271
2365
|
code: result?.code || source,
|
|
2272
2366
|
transformed,
|
|
2273
2367
|
usesRuntime,
|
|
2274
|
-
usesColorVar
|
|
2368
|
+
usesColorVar,
|
|
2369
|
+
classes: collectedClasses
|
|
2275
2370
|
};
|
|
2276
2371
|
} catch (e) {
|
|
2277
2372
|
console.warn("[csszyx] AST transform failed, falling back to original code:", e);
|
|
2278
|
-
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false };
|
|
2373
|
+
return { code: source, transformed: false, usesRuntime: false, usesColorVar: false, classes: collectedClasses };
|
|
2279
2374
|
}
|
|
2280
2375
|
}
|
|
2281
2376
|
function tryStaticTransformNode(node) {
|
|
@@ -2514,6 +2609,18 @@ function generateStyleValueExpression(info) {
|
|
|
2514
2609
|
);
|
|
2515
2610
|
}
|
|
2516
2611
|
}
|
|
2612
|
+
function collectFromExpr(node, classes) {
|
|
2613
|
+
if (t.isStringLiteral(node)) {
|
|
2614
|
+
for (const c of node.value.split(/\s+/)) {
|
|
2615
|
+
if (c) {
|
|
2616
|
+
classes.add(c);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
} else if (t.isConditionalExpression(node)) {
|
|
2620
|
+
collectFromExpr(node.consequent, classes);
|
|
2621
|
+
collectFromExpr(node.alternate, classes);
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2517
2624
|
function buildCSSVarClassName(info) {
|
|
2518
2625
|
const { twPrefix, varName, variantChain } = info;
|
|
2519
2626
|
const variantPrefix = variantChain ? `${getVariantPrefix(variantChain)}:` : "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Core compiler and transformation logic for csszyx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csszyx",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@babel/core": "^7.23.7",
|
|
39
39
|
"@babel/types": "^7.23.6",
|
|
40
40
|
"@babel/traverse": "^7.23.7",
|
|
41
|
-
"@csszyx/core": "0.
|
|
41
|
+
"@csszyx/core": "0.3.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/babel__core": "^7.20.5",
|