@homebound/truss 2.19.3 → 2.20.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 CHANGED
@@ -1054,7 +1054,7 @@ class CssBuilder<T extends Properties> {
1054
1054
 
1055
1055
  ${lines.join("\n ").replace(/ +\n/g, "\n")}
1056
1056
 
1057
- get $(): T { return maybeImportant(sortObject(this.rules), this.opts.important); }
1057
+ get $(): T { maybeImportant(sortObject(this.rules), this.opts.important); }
1058
1058
 
1059
1059
  if(bp: Breakpoint): CssBuilder<T>;
1060
1060
  if(cond: boolean): CssBuilder<T>;
@@ -1113,21 +1113,31 @@ class CssBuilder<T extends Properties> {
1113
1113
 
1114
1114
  get important() { return this.newCss({ important: true }); }
1115
1115
 
1116
- /** Adds new properties, either a specific key/value or a Properties object, to the current css. */
1116
+ /** Add real CSS property/value pairs, either as add("prop", value) or add({ prop: value, ... }). */
1117
1117
  add<P extends Properties>(props: P): CssBuilder<T & P>;
1118
1118
  add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;
1119
1119
  add<K extends keyof Properties>(propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {
1120
1120
  if (!this.enabled) return this;
1121
1121
  const newRules = typeof propOrProperties === "string" ? { [propOrProperties]: value } : propOrProperties;
1122
+ if (typeof propOrProperties !== "string" && (newRules as any).$css) {
1123
+ throw new Error("add() received a Css expression — use with() to compose Css expressions");
1124
+ }
1122
1125
  const rules = this.selector
1123
1126
  ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }
1124
1127
  : { ...this.rules, ...newRules };
1125
1128
  return this.newCss({ rules: rules as any });
1126
1129
  }
1127
1130
 
1128
- /** Adds a partial style hash, skipping any undefined values. */
1129
- addCss<P extends Properties>(props: P): CssBuilder<T & P> {
1130
- return this.add(omitUndefinedValues(props));
1131
+ /** Compose an existing Css expression or partial style hash into this builder, skipping undefined values. */
1132
+ with<P extends Properties>(cssProp: P): CssBuilder<T & P>;
1133
+ with(cssProp: Properties): CssBuilder<any> {
1134
+ if (!this.enabled) return this;
1135
+ const { $css, ...rest } = cssProp as any;
1136
+ const filtered = omitUndefinedValues(rest);
1137
+ const rules = this.selector
1138
+ ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...filtered } }
1139
+ : { ...this.rules, ...filtered };
1140
+ return this.newCss({ rules: rules as any });
1131
1141
  }
1132
1142
 
1133
1143
  /** Adds new properties, either a specific key/value or a Properties object, to a nested selector. */
@@ -1450,23 +1460,35 @@ class CssBuilder<T extends Properties> {
1450
1460
  return this.newCss({ selector: undefined, elseApplied: false });
1451
1461
  }
1452
1462
 
1463
+ /** Add real CSS property/value pairs, either as add("prop", value) or add({ prop: value, ... }). */
1453
1464
  add<P extends Properties>(props: P): CssBuilder<T & P>;
1454
1465
  add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;
1455
1466
  add<K extends keyof Properties>(propOrStyles: K | Properties, value?: Properties[K]): CssBuilder<any> {
1456
1467
  if (!this.enabled) return this;
1457
1468
 
1458
1469
  const newRules = typeof propOrStyles === "string" ? { [propOrStyles]: value } : propOrStyles;
1470
+ if (typeof propOrStyles !== "string" && (newRules as any).$css) {
1471
+ throw new Error("add() received a Css expression — use with() to compose Css expressions");
1472
+ }
1459
1473
  const rules = this.selector
1460
1474
  ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }
1461
1475
  : { ...this.rules, ...newRules };
1462
1476
  return this.newCss({ rules: rules as any });
1463
1477
  }
1464
1478
 
1465
- /** Inline a partial style hash, skipping any undefined values. */
1466
- addCss<P extends Properties>(props: P): CssBuilder<T & P> {
1467
- return this.add(omitUndefinedValues(props));
1479
+ /** Compose an existing Css expression or partial style hash into this builder, skipping undefined values. */
1480
+ with<P extends Properties>(cssProp: P): CssBuilder<T & P>;
1481
+ with(cssProp: Properties): CssBuilder<any> {
1482
+ if (!this.enabled) return this;
1483
+ const { $css, ...rest } = cssProp as any;
1484
+ const filtered = omitUndefinedValues(rest);
1485
+ const rules = this.selector
1486
+ ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...filtered } }
1487
+ : { ...this.rules, ...filtered };
1488
+ return this.newCss({ rules: rules as any });
1468
1489
  }
1469
1490
 
1491
+
1470
1492
  /** Marker for the build-time transform to append a raw className. */
1471
1493
  className(className: string | undefined): CssBuilder<T> {
1472
1494
  void className;