@homebound/truss 2.1.3 → 2.2.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.
@@ -1198,7 +1198,7 @@ function resolveChain(chain, mapping) {
1198
1198
  currentWhenPseudo = null;
1199
1199
  continue;
1200
1200
  }
1201
- if (abbr === "add") {
1201
+ if (abbr === "add" || abbr === "addCss") {
1202
1202
  const seg = resolveAddCall(
1203
1203
  node,
1204
1204
  mapping,
@@ -1453,6 +1453,24 @@ function buildParameterizedSegment(params) {
1453
1453
  return base;
1454
1454
  }
1455
1455
  function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, whenPseudo) {
1456
+ const isAddCss = node.name === "addCss";
1457
+ if (isAddCss) {
1458
+ if (node.args.length !== 1) {
1459
+ throw new UnsupportedPatternError(
1460
+ `addCss() requires exactly 1 argument (an existing CssProp/style hash expression)`
1461
+ );
1462
+ }
1463
+ const styleArg = node.args[0];
1464
+ if (styleArg.type === "SpreadElement") {
1465
+ throw new UnsupportedPatternError(`addCss() does not support spread arguments`);
1466
+ }
1467
+ return {
1468
+ abbr: "__composed_css_prop",
1469
+ defs: {},
1470
+ styleArrayArg: styleArg,
1471
+ isAddCss: true
1472
+ };
1473
+ }
1456
1474
  if (node.args.length === 1) {
1457
1475
  const styleArg = node.args[0];
1458
1476
  if (styleArg.type === "SpreadElement") {
@@ -1471,7 +1489,7 @@ function resolveAddCall(node, mapping, mediaQuery, pseudoClass, pseudoElement, w
1471
1489
  }
1472
1490
  if (node.args.length !== 2) {
1473
1491
  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)`
1492
+ `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
1493
  );
1476
1494
  }
1477
1495
  const propArg = node.args[0];
@@ -1997,7 +2015,11 @@ function buildStyleHashMembers(segments, options) {
1997
2015
  if (seg.error) continue;
1998
2016
  if (seg.styleArrayArg) {
1999
2017
  flushNormal();
2000
- members.push(t3.spreadElement(seg.styleArrayArg));
2018
+ if (seg.isAddCss && t3.isObjectExpression(seg.styleArrayArg)) {
2019
+ members.push(...buildAddCssObjectMembers(seg.styleArrayArg));
2020
+ } else {
2021
+ members.push(t3.spreadElement(seg.styleArrayArg));
2022
+ }
2001
2023
  continue;
2002
2024
  }
2003
2025
  if (seg.typographyLookup) {
@@ -2018,6 +2040,34 @@ function buildStyleHashMembers(segments, options) {
2018
2040
  flushNormal();
2019
2041
  return members;
2020
2042
  }
2043
+ function buildAddCssObjectMembers(styleObject) {
2044
+ const members = [];
2045
+ for (const property of styleObject.properties) {
2046
+ if (t3.isSpreadElement(property)) {
2047
+ members.push(t3.spreadElement(t3.cloneNode(property.argument, true)));
2048
+ continue;
2049
+ }
2050
+ if (!t3.isObjectProperty(property) || property.computed) {
2051
+ members.push(t3.spreadElement(t3.objectExpression([t3.cloneNode(property, true)])));
2052
+ continue;
2053
+ }
2054
+ const value = property.value;
2055
+ if (t3.isIdentifier(value) || t3.isMemberExpression(value) || t3.isOptionalMemberExpression(value)) {
2056
+ members.push(
2057
+ t3.spreadElement(
2058
+ t3.conditionalExpression(
2059
+ t3.binaryExpression("===", t3.cloneNode(value, true), t3.identifier("undefined")),
2060
+ t3.objectExpression([]),
2061
+ t3.objectExpression([t3.objectProperty(clonePropertyKey(property.key), t3.cloneNode(value, true))])
2062
+ )
2063
+ )
2064
+ );
2065
+ continue;
2066
+ }
2067
+ members.push(t3.spreadElement(t3.objectExpression([t3.cloneNode(property, true)])));
2068
+ }
2069
+ return members;
2070
+ }
2021
2071
  function collectConditionalOnlyProps(segments) {
2022
2072
  const allProps = /* @__PURE__ */ new Map();
2023
2073
  for (const seg of segments) {