@homebound/truss 2.1.0-next.9 → 2.1.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.
@@ -570,7 +570,9 @@ function isVariableRule(rule) {
570
570
  }
571
571
  function sortRulesByPriority(rules) {
572
572
  rules.sort(function(a, b) {
573
- return computeRulePriority(a) - computeRulePriority(b);
573
+ const diff = computeRulePriority(a) - computeRulePriority(b);
574
+ if (diff !== 0) return diff;
575
+ return a.className < b.className ? -1 : a.className > b.className ? 1 : 0;
574
576
  });
575
577
  }
576
578
 
@@ -882,17 +884,30 @@ ${body}
882
884
  }
883
885
  function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
884
886
  const propGroups = /* @__PURE__ */ new Map();
887
+ function pushEntry(cssProp, entry) {
888
+ if (!propGroups.has(cssProp)) propGroups.set(cssProp, []);
889
+ const entries = propGroups.get(cssProp);
890
+ if (!entry.isConditional) {
891
+ for (let i = entries.length - 1; i >= 0; i--) {
892
+ if (!entries[i].isConditional) {
893
+ entries.splice(i, 1);
894
+ }
895
+ }
896
+ }
897
+ entries.push(entry);
898
+ }
885
899
  for (const seg of segments) {
886
900
  if (seg.error || seg.styleArrayArg || seg.typographyLookup) continue;
887
901
  const { prefix } = segmentContext(seg, mapping);
902
+ const isConditional = prefix !== "";
888
903
  if (seg.variableProps) {
889
904
  for (const prop of seg.variableProps) {
890
905
  const className = prefix ? `${prefix}${seg.abbr}_var` : `${seg.abbr}_var`;
891
906
  const varName = toCssVariableName(className, seg.abbr, prop);
892
- if (!propGroups.has(prop)) propGroups.set(prop, []);
893
- propGroups.get(prop).push({
907
+ pushEntry(prop, {
894
908
  className,
895
909
  isVariable: true,
910
+ isConditional,
896
911
  varName,
897
912
  argNode: seg.argNode,
898
913
  incremented: seg.incremented,
@@ -903,8 +918,7 @@ function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
903
918
  for (const [cssProp, value] of Object.entries(seg.variableExtraDefs)) {
904
919
  const extraBase = `${seg.abbr}_${cssProp}`;
905
920
  const extraName = prefix ? `${prefix}${extraBase}` : extraBase;
906
- if (!propGroups.has(cssProp)) propGroups.set(cssProp, []);
907
- propGroups.get(cssProp).push({ className: extraName, isVariable: false });
921
+ pushEntry(cssProp, { className: extraName, isVariable: false, isConditional });
908
922
  }
909
923
  }
910
924
  } else {
@@ -912,8 +926,7 @@ function buildStyleHashProperties(segments, mapping, maybeIncHelperName) {
912
926
  for (const [cssProp, val] of Object.entries(seg.defs)) {
913
927
  const baseName = computeStaticBaseName(seg, cssProp, String(val), isMultiProp, mapping);
914
928
  const className = prefix ? `${prefix}${baseName}` : baseName;
915
- if (!propGroups.has(cssProp)) propGroups.set(cssProp, []);
916
- propGroups.get(cssProp).push({ className, isVariable: false });
929
+ pushEntry(cssProp, { className, isVariable: false, isConditional });
917
930
  }
918
931
  }
919
932
  }
@@ -1950,11 +1963,13 @@ function buildStyleHashFromChain(chain, options) {
1950
1963
  } else {
1951
1964
  const thenMembers = mergeConditionalBranchMembers(
1952
1965
  buildStyleHashMembers(part.thenSegments, options),
1953
- previousProperties
1966
+ previousProperties,
1967
+ collectConditionalOnlyProps(part.thenSegments)
1954
1968
  );
1955
1969
  const elseMembers = mergeConditionalBranchMembers(
1956
1970
  buildStyleHashMembers(part.elseSegments, options),
1957
- previousProperties
1971
+ previousProperties,
1972
+ collectConditionalOnlyProps(part.elseSegments)
1958
1973
  );
1959
1974
  members.push(
1960
1975
  t3.spreadElement(
@@ -1999,13 +2014,31 @@ function buildStyleHashMembers(segments, options) {
1999
2014
  flushNormal();
2000
2015
  return members;
2001
2016
  }
2002
- function mergeConditionalBranchMembers(members, previousProperties) {
2017
+ function collectConditionalOnlyProps(segments) {
2018
+ const allProps = /* @__PURE__ */ new Map();
2019
+ for (const seg of segments) {
2020
+ if (seg.error || seg.styleArrayArg || seg.typographyLookup) continue;
2021
+ const hasCondition = !!(seg.pseudoClass || seg.mediaQuery || seg.pseudoElement || seg.whenPseudo);
2022
+ const props = seg.variableProps ?? Object.keys(seg.defs);
2023
+ for (const prop of props) {
2024
+ const current = allProps.get(prop);
2025
+ allProps.set(prop, current === void 0 ? hasCondition : current && hasCondition);
2026
+ }
2027
+ }
2028
+ const result = /* @__PURE__ */ new Set();
2029
+ for (const [prop, isConditionalOnly] of allProps) {
2030
+ if (isConditionalOnly) result.add(prop);
2031
+ }
2032
+ return result;
2033
+ }
2034
+ function mergeConditionalBranchMembers(members, previousProperties, conditionalOnlyProps) {
2003
2035
  return members.map(function(member) {
2004
2036
  if (!t3.isObjectProperty(member)) {
2005
2037
  return member;
2006
2038
  }
2007
- const prior = previousProperties.get(propertyName(member.key));
2008
- if (!prior) {
2039
+ const prop = propertyName(member.key);
2040
+ const prior = previousProperties.get(prop);
2041
+ if (!prior || !conditionalOnlyProps.has(prop)) {
2009
2042
  return member;
2010
2043
  }
2011
2044
  return t3.objectProperty(