@homebound/truss 2.1.3 → 2.2.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/build/index.js +24 -0
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +71 -10
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -688,17 +688,28 @@ function computeStaticBaseName(seg, cssProp, cssValue, isMultiProp, mapping) {
|
|
|
688
688
|
function collectAtomicRules(chains, mapping) {
|
|
689
689
|
const rules = /* @__PURE__ */ new Map();
|
|
690
690
|
let needsMaybeInc = false;
|
|
691
|
+
function collectSegment(seg) {
|
|
692
|
+
if (seg.error || seg.styleArrayArg) return;
|
|
693
|
+
if (seg.typographyLookup) {
|
|
694
|
+
for (const segments of Object.values(seg.typographyLookup.segmentsByName)) {
|
|
695
|
+
for (const nestedSeg of segments) {
|
|
696
|
+
collectSegment(nestedSeg);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
if (seg.incremented) needsMaybeInc = true;
|
|
702
|
+
if (seg.variableProps) {
|
|
703
|
+
collectVariableRules(rules, seg, mapping);
|
|
704
|
+
} else {
|
|
705
|
+
collectStaticRules(rules, seg, mapping);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
691
708
|
for (const chain of chains) {
|
|
692
709
|
for (const part of chain.parts) {
|
|
693
710
|
const segs = part.type === "unconditional" ? part.segments : [...part.thenSegments, ...part.elseSegments];
|
|
694
711
|
for (const seg of segs) {
|
|
695
|
-
|
|
696
|
-
if (seg.incremented) needsMaybeInc = true;
|
|
697
|
-
if (seg.variableProps) {
|
|
698
|
-
collectVariableRules(rules, seg, mapping);
|
|
699
|
-
} else {
|
|
700
|
-
collectStaticRules(rules, seg, mapping);
|
|
701
|
-
}
|
|
712
|
+
collectSegment(seg);
|
|
702
713
|
}
|
|
703
714
|
}
|
|
704
715
|
}
|
|
@@ -1198,7 +1209,7 @@ function resolveChain(chain, mapping) {
|
|
|
1198
1209
|
currentWhenPseudo = null;
|
|
1199
1210
|
continue;
|
|
1200
1211
|
}
|
|
1201
|
-
if (abbr === "add") {
|
|
1212
|
+
if (abbr === "add" || abbr === "addCss") {
|
|
1202
1213
|
const seg = resolveAddCall(
|
|
1203
1214
|
node,
|
|
1204
1215
|
mapping,
|
|
@@ -1453,6 +1464,24 @@ function buildParameterizedSegment(params) {
|
|
|
1453
1464
|
return base;
|
|
1454
1465
|
}
|
|
1455
1466
|
function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
|
|
1467
|
+
const isAddCss = node.name === "addCss";
|
|
1468
|
+
if (isAddCss) {
|
|
1469
|
+
if (node.args.length !== 1) {
|
|
1470
|
+
throw new UnsupportedPatternError(
|
|
1471
|
+
`addCss() requires exactly 1 argument (an existing CssProp/style hash expression)`
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
const styleArg = node.args[0];
|
|
1475
|
+
if (styleArg.type === "SpreadElement") {
|
|
1476
|
+
throw new UnsupportedPatternError(`addCss() does not support spread arguments`);
|
|
1477
|
+
}
|
|
1478
|
+
return {
|
|
1479
|
+
abbr: "__composed_css_prop",
|
|
1480
|
+
defs: {},
|
|
1481
|
+
styleArrayArg: styleArg,
|
|
1482
|
+
isAddCss: true
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1456
1485
|
if (node.args.length === 1) {
|
|
1457
1486
|
const styleArg = node.args[0];
|
|
1458
1487
|
if (styleArg.type === "SpreadElement") {
|
|
@@ -1471,7 +1500,7 @@ function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, w
|
|
|
1471
1500
|
}
|
|
1472
1501
|
if (node.args.length !== 2) {
|
|
1473
1502
|
throw new UnsupportedPatternError(
|
|
1474
|
-
`add() requires exactly 2 arguments (property name and value), got ${node.args.length}. Supported overloads are add(cssProp) and add("propName", value)`
|
|
1503
|
+
`add() requires exactly 2 arguments (property name and value), got ${node.args.length}. Supported overloads are add(cssProp), addCss(cssProp), and add("propName", value)`
|
|
1475
1504
|
);
|
|
1476
1505
|
}
|
|
1477
1506
|
const propArg = node.args[0];
|
|
@@ -1997,7 +2026,11 @@ function buildStyleHashMembers(segments, options) {
|
|
|
1997
2026
|
if (seg.error) continue;
|
|
1998
2027
|
if (seg.styleArrayArg) {
|
|
1999
2028
|
flushNormal();
|
|
2000
|
-
|
|
2029
|
+
if (seg.isAddCss && t3.isObjectExpression(seg.styleArrayArg)) {
|
|
2030
|
+
members.push(...buildAddCssObjectMembers(seg.styleArrayArg));
|
|
2031
|
+
} else {
|
|
2032
|
+
members.push(t3.spreadElement(seg.styleArrayArg));
|
|
2033
|
+
}
|
|
2001
2034
|
continue;
|
|
2002
2035
|
}
|
|
2003
2036
|
if (seg.typographyLookup) {
|
|
@@ -2018,6 +2051,34 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2018
2051
|
flushNormal();
|
|
2019
2052
|
return members;
|
|
2020
2053
|
}
|
|
2054
|
+
function buildAddCssObjectMembers(styleObject) {
|
|
2055
|
+
const members = [];
|
|
2056
|
+
for (const property of styleObject.properties) {
|
|
2057
|
+
if (t3.isSpreadElement(property)) {
|
|
2058
|
+
members.push(t3.spreadElement(t3.cloneNode(property.argument, true)));
|
|
2059
|
+
continue;
|
|
2060
|
+
}
|
|
2061
|
+
if (!t3.isObjectProperty(property) || property.computed) {
|
|
2062
|
+
members.push(t3.spreadElement(t3.objectExpression([t3.cloneNode(property, true)])));
|
|
2063
|
+
continue;
|
|
2064
|
+
}
|
|
2065
|
+
const value = property.value;
|
|
2066
|
+
if (t3.isIdentifier(value) || t3.isMemberExpression(value) || t3.isOptionalMemberExpression(value)) {
|
|
2067
|
+
members.push(
|
|
2068
|
+
t3.spreadElement(
|
|
2069
|
+
t3.conditionalExpression(
|
|
2070
|
+
t3.binaryExpression("===", t3.cloneNode(value, true), t3.identifier("undefined")),
|
|
2071
|
+
t3.objectExpression([]),
|
|
2072
|
+
t3.objectExpression([t3.objectProperty(clonePropertyKey(property.key), t3.cloneNode(value, true))])
|
|
2073
|
+
)
|
|
2074
|
+
)
|
|
2075
|
+
);
|
|
2076
|
+
continue;
|
|
2077
|
+
}
|
|
2078
|
+
members.push(t3.spreadElement(t3.objectExpression([t3.cloneNode(property, true)])));
|
|
2079
|
+
}
|
|
2080
|
+
return members;
|
|
2081
|
+
}
|
|
2021
2082
|
function collectConditionalOnlyProps(segments) {
|
|
2022
2083
|
const allProps = /* @__PURE__ */ new Map();
|
|
2023
2084
|
for (const seg of segments) {
|