@homebound/truss 2.8.4 → 2.9.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/build/index.js +12 -0
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +57 -4
- package/build/plugin/index.js.map +1 -1
- package/build/runtime.d.ts +3 -2
- package/build/runtime.js +17 -1
- package/build/runtime.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -724,7 +724,7 @@ function collectAtomicRules(chains, mapping) {
|
|
|
724
724
|
const rules = /* @__PURE__ */ new Map();
|
|
725
725
|
let needsMaybeInc = false;
|
|
726
726
|
function collectSegment(seg) {
|
|
727
|
-
if (seg.error || seg.styleArrayArg) return;
|
|
727
|
+
if (seg.error || seg.styleArrayArg || seg.classNameArg) return;
|
|
728
728
|
if (seg.typographyLookup) {
|
|
729
729
|
for (const segments of Object.values(seg.typographyLookup.segmentsByName)) {
|
|
730
730
|
for (const nestedSeg of segments) {
|
|
@@ -942,7 +942,7 @@ function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
|
|
|
942
942
|
entries.push(entry);
|
|
943
943
|
}
|
|
944
944
|
for (const seg of segments) {
|
|
945
|
-
if (seg.error || seg.styleArrayArg || seg.typographyLookup) continue;
|
|
945
|
+
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg) continue;
|
|
946
946
|
const { prefix } = segmentContext(seg, mapping);
|
|
947
947
|
const isConditional = prefix !== "";
|
|
948
948
|
if (seg.variableProps) {
|
|
@@ -1252,6 +1252,17 @@ function resolveChain(chain, mapping) {
|
|
|
1252
1252
|
segments.push(seg);
|
|
1253
1253
|
continue;
|
|
1254
1254
|
}
|
|
1255
|
+
if (abbr === "className") {
|
|
1256
|
+
const seg = resolveClassNameCall(
|
|
1257
|
+
node,
|
|
1258
|
+
currentMediaQuery,
|
|
1259
|
+
currentPseudoClass,
|
|
1260
|
+
currentPseudoElement,
|
|
1261
|
+
currentWhenPseudo
|
|
1262
|
+
);
|
|
1263
|
+
segments.push(seg);
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1255
1266
|
if (abbr === "typography") {
|
|
1256
1267
|
const resolved = resolveTypographyCall(
|
|
1257
1268
|
node,
|
|
@@ -1499,6 +1510,26 @@ function buildParameterizedSegment(params) {
|
|
|
1499
1510
|
}
|
|
1500
1511
|
return base;
|
|
1501
1512
|
}
|
|
1513
|
+
function resolveClassNameCall(node, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
|
|
1514
|
+
if (node.args.length !== 1) {
|
|
1515
|
+
throw new UnsupportedPatternError(`className() expects exactly 1 argument, got ${node.args.length}`);
|
|
1516
|
+
}
|
|
1517
|
+
const arg = node.args[0];
|
|
1518
|
+
if (arg.type === "SpreadElement") {
|
|
1519
|
+
throw new UnsupportedPatternError(`className() does not support spread arguments`);
|
|
1520
|
+
}
|
|
1521
|
+
if (mediaQuery || pseudoClass || pseudoElement || whenPseudo) {
|
|
1522
|
+
throw new UnsupportedPatternError(
|
|
1523
|
+
`className() cannot be used inside media query, pseudo-class, pseudo-element, or when() contexts`
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
return {
|
|
1527
|
+
// I.e. this is metadata for the rewriter/runtime, not an atomic CSS rule.
|
|
1528
|
+
abbr: "className",
|
|
1529
|
+
defs: {},
|
|
1530
|
+
classNameArg: arg
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1502
1533
|
function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
|
|
1503
1534
|
const isAddCss = node.name === "addCss";
|
|
1504
1535
|
if (isAddCss) {
|
|
@@ -2072,6 +2103,7 @@ function buildStyleHashFromChain(chain, options) {
|
|
|
2072
2103
|
function buildStyleHashMembers(segments, options) {
|
|
2073
2104
|
const members = [];
|
|
2074
2105
|
const normalSegs = [];
|
|
2106
|
+
const classNameArgs = [];
|
|
2075
2107
|
function flushNormal() {
|
|
2076
2108
|
if (normalSegs.length > 0) {
|
|
2077
2109
|
members.push(...buildStyleHashProperties(normalSegs, options.mapping, options.maybeIncHelperName));
|
|
@@ -2080,6 +2112,10 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2080
2112
|
}
|
|
2081
2113
|
for (const seg of segments) {
|
|
2082
2114
|
if (seg.error) continue;
|
|
2115
|
+
if (seg.classNameArg) {
|
|
2116
|
+
classNameArgs.push(t3.cloneNode(seg.classNameArg, true));
|
|
2117
|
+
continue;
|
|
2118
|
+
}
|
|
2083
2119
|
if (seg.styleArrayArg) {
|
|
2084
2120
|
flushNormal();
|
|
2085
2121
|
if (seg.isAddCss && t3.isObjectExpression(seg.styleArrayArg)) {
|
|
@@ -2105,6 +2141,9 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2105
2141
|
normalSegs.push(seg);
|
|
2106
2142
|
}
|
|
2107
2143
|
flushNormal();
|
|
2144
|
+
if (classNameArgs.length > 0) {
|
|
2145
|
+
members.push(t3.objectProperty(t3.identifier("className"), t3.arrayExpression(classNameArgs)));
|
|
2146
|
+
}
|
|
2108
2147
|
return members;
|
|
2109
2148
|
}
|
|
2110
2149
|
function buildAddCssObjectMembers(styleObject) {
|
|
@@ -2138,7 +2177,7 @@ function buildAddCssObjectMembers(styleObject) {
|
|
|
2138
2177
|
function collectConditionalOnlyProps(segments) {
|
|
2139
2178
|
const allProps = /* @__PURE__ */ new Map();
|
|
2140
2179
|
for (const seg of segments) {
|
|
2141
|
-
if (seg.error || seg.styleArrayArg || seg.typographyLookup) continue;
|
|
2180
|
+
if (seg.error || seg.styleArrayArg || seg.typographyLookup || seg.classNameArg) continue;
|
|
2142
2181
|
const hasCondition = !!(seg.pseudoClass || seg.mediaQuery || seg.pseudoElement || seg.whenPseudo);
|
|
2143
2182
|
const props = seg.variableProps ?? Object.keys(seg.defs);
|
|
2144
2183
|
for (const prop of props) {
|
|
@@ -2159,6 +2198,9 @@ function mergeConditionalBranchMembers(members, previousProperties, conditionalO
|
|
|
2159
2198
|
}
|
|
2160
2199
|
const prop = propertyName(member.key);
|
|
2161
2200
|
const prior = previousProperties.get(prop);
|
|
2201
|
+
if (prop === "className" && prior) {
|
|
2202
|
+
return t3.objectProperty(clonePropertyKey(member.key), mergeClassNameValues(prior.value, member.value));
|
|
2203
|
+
}
|
|
2162
2204
|
if (!prior || !conditionalOnlyProps.has(prop)) {
|
|
2163
2205
|
return member;
|
|
2164
2206
|
}
|
|
@@ -2184,6 +2226,17 @@ function mergePropertyValues(previousValue, currentValue) {
|
|
|
2184
2226
|
}
|
|
2185
2227
|
return t3.cloneNode(currentValue, true);
|
|
2186
2228
|
}
|
|
2229
|
+
function mergeClassNameValues(previousValue, currentValue) {
|
|
2230
|
+
return t3.arrayExpression([...toClassNameElements(previousValue), ...toClassNameElements(currentValue)]);
|
|
2231
|
+
}
|
|
2232
|
+
function toClassNameElements(value) {
|
|
2233
|
+
if (t3.isArrayExpression(value)) {
|
|
2234
|
+
return value.elements.flatMap((element) => {
|
|
2235
|
+
return element && !t3.isSpreadElement(element) ? [t3.cloneNode(element, true)] : [];
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
return [t3.cloneNode(value, true)];
|
|
2239
|
+
}
|
|
2187
2240
|
function mergeTupleValue(tuple, classNames, prependClassNames, previousVars) {
|
|
2188
2241
|
const currentClassNames = tupleClassNames(tuple);
|
|
2189
2242
|
const mergedClassNames = prependClassNames ? `${classNames} ${currentClassNames}` : `${currentClassNames} ${classNames}`;
|
|
@@ -2232,7 +2285,7 @@ function clonePropertyKey(key) {
|
|
|
2232
2285
|
function injectDebugInfo(expr, line, options) {
|
|
2233
2286
|
if (!options.debug) return;
|
|
2234
2287
|
const firstProp = expr.properties.find((p) => {
|
|
2235
|
-
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
|
|
2288
|
+
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name === "className" || t3.isStringLiteral(p.key) && p.key.value === "className" || t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
|
|
2236
2289
|
});
|
|
2237
2290
|
if (!firstProp) return;
|
|
2238
2291
|
options.needsTrussDebugInfo.current = true;
|