@homebound/truss 2.24.0 → 2.26.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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Utilities for CSS custom properties (`--token`) in Truss style values.
3
+ */
4
+ /**
5
+ * If `value` is a custom property name (`--token`), wrap as `var(--token)` for use as a property value.
6
+ * Passes through values that are not custom-property names (including existing `var(...)`).
7
+ */
8
+ declare function maybeCssVar<T>(value: T): T;
9
+
10
+ export { maybeCssVar as m };
package/build/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Properties } from 'csstype';
2
2
  import { Code } from 'ts-poet';
3
+ export { m as maybeCssVar } from './css-custom-property-B-Ncwzgt.js';
3
4
 
4
5
  /**
5
6
  * A map from human name to font size, i.e. `f12` -> `12px`.
@@ -147,6 +148,7 @@ declare const defaultSections: {
147
148
  readonly display: CreateMethodsFn;
148
149
  readonly flexbox: CreateMethodsFn;
149
150
  readonly float: CreateMethodsFn;
151
+ readonly fontStyle: CreateMethodsFn;
150
152
  readonly fontWeight: CreateMethodsFn;
151
153
  readonly grid: CreateMethodsFn;
152
154
  readonly height: CreateMethodsFn;
package/build/index.js CHANGED
@@ -380,6 +380,16 @@ var float = () => newMethodsForProp(
380
380
  "float"
381
381
  );
382
382
 
383
+ // src/sections/tachyons/fontStyle.ts
384
+ var fontStyle = () => newMethodsForProp(
385
+ "fontStyle",
386
+ {
387
+ fsyi: "italic",
388
+ fsynm: "normal"
389
+ },
390
+ "fsy"
391
+ );
392
+
383
393
  // src/sections/tachyons/fontWeight.ts
384
394
  var fontWeight = () => newMethodsForProp(
385
395
  "fontWeight",
@@ -834,6 +844,7 @@ var defaultSections = {
834
844
  display,
835
845
  flexbox,
836
846
  float,
847
+ fontStyle,
837
848
  fontWeight,
838
849
  grid,
839
850
  height,
@@ -1078,6 +1089,17 @@ type Opts<T> = {
1078
1089
  elseApplied: boolean,
1079
1090
  };
1080
1091
 
1092
+ /** Wraps \`--token\` custom property names as \`var(--token)\` for CSS property values. */
1093
+ function maybeCssVar<T>(value: T): T {
1094
+ if (typeof value !== "string") return value;
1095
+ if (value.startsWith("--")) return \`var(\${value})\` as T;
1096
+ return value;
1097
+ }
1098
+
1099
+ function maybeCssVarValues<O extends Record<string, unknown>>(obj: O): O {
1100
+ return Object.fromEntries(Object.entries(obj).map(([key, val]) => [key, maybeCssVar(val)])) as O;
1101
+ }
1102
+
1081
1103
  function invertMediaQuery(query: string): string {
1082
1104
  const screenPrefix = "@media screen and ";
1083
1105
  if (query.startsWith(screenPrefix)) {
@@ -1174,7 +1196,10 @@ class CssBuilder<T extends Properties> {
1174
1196
  add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;
1175
1197
  add<K extends keyof Properties>(propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {
1176
1198
  if (!this.enabled) return this;
1177
- const newRules = typeof propOrProperties === "string" ? { [propOrProperties]: value } : propOrProperties;
1199
+ const newRules =
1200
+ typeof propOrProperties === "string"
1201
+ ? { [propOrProperties]: maybeCssVar(value) }
1202
+ : maybeCssVarValues(propOrProperties as Record<string, unknown>);
1178
1203
  if (typeof propOrProperties !== "string" && (newRules as any).$css) {
1179
1204
  throw new Error("add() received a Css expression — use with() to compose Css expressions");
1180
1205
  }
@@ -1189,7 +1214,7 @@ class CssBuilder<T extends Properties> {
1189
1214
  with(cssProp: Properties): CssBuilder<any> {
1190
1215
  if (!this.enabled) return this;
1191
1216
  const { $css, ...rest } = cssProp as any;
1192
- const filtered = omitUndefinedValues(rest);
1217
+ const filtered = maybeCssVarValues(omitUndefinedValues(rest));
1193
1218
  const rules = this.selector
1194
1219
  ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...filtered } }
1195
1220
  : { ...this.rules, ...filtered };
@@ -1504,7 +1529,10 @@ class CssBuilder<T extends Properties, S extends StyleKind = "buildtime"> {
1504
1529
  add<K extends keyof Properties>(propOrStyles: K | Properties, value?: Properties[K]): CssBuilder<any, S> {
1505
1530
  if (!this.enabled) return this;
1506
1531
 
1507
- const newRules = typeof propOrStyles === "string" ? { [propOrStyles]: value } : propOrStyles;
1532
+ const newRules =
1533
+ typeof propOrStyles === "string"
1534
+ ? { [propOrStyles]: maybeCssVar(value) }
1535
+ : maybeCssVarValues(propOrStyles as Record<string, unknown>);
1508
1536
  if (typeof propOrStyles !== "string" && (newRules as any).$css) {
1509
1537
  throw new Error("add() received a Css expression — use with() to compose Css expressions");
1510
1538
  }
@@ -1519,7 +1547,7 @@ class CssBuilder<T extends Properties, S extends StyleKind = "buildtime"> {
1519
1547
  with(cssProp: Properties): CssBuilder<any, S> {
1520
1548
  if (!this.enabled) return this;
1521
1549
  const { $css, ...rest } = cssProp as any;
1522
- const filtered = omitUndefinedValues(rest);
1550
+ const filtered = maybeCssVarValues(omitUndefinedValues(rest));
1523
1551
  const rules = this.selector
1524
1552
  ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...filtered } }
1525
1553
  : { ...this.rules, ...filtered };
@@ -1577,6 +1605,17 @@ export function maybeInc(inc: number | string): string {
1577
1605
  return typeof inc === "string" ? inc : \`calc(var(${SPACING_CUSTOM_PROPERTY}) * \${inc})\`;
1578
1606
  }
1579
1607
 
1608
+ /** Wraps \`--token\` custom property names as \`var(--token)\` for CSS property values. */
1609
+ export function maybeCssVar<T>(value: T): T {
1610
+ if (typeof value !== "string") return value;
1611
+ if (value.startsWith("--")) return \`var(\${value})\` as T;
1612
+ return value;
1613
+ }
1614
+
1615
+ function maybeCssVarValues<O extends Record<string, unknown>>(obj: O): O {
1616
+ return Object.fromEntries(Object.entries(obj).map(([key, val]) => [key, maybeCssVar(val)])) as O;
1617
+ }
1618
+
1580
1619
  /** Converts \`inc\` into pixels. */
1581
1620
  export function increment(inc: number): number {
1582
1621
  return inc * ${increment};
@@ -1713,12 +1752,20 @@ function condensedJson(mapping) {
1713
1752
  lines.push("}");
1714
1753
  return lines.join("\n");
1715
1754
  }
1755
+
1756
+ // src/css-custom-property.ts
1757
+ function maybeCssVar(value) {
1758
+ if (typeof value !== "string") return value;
1759
+ if (value.startsWith("--")) return `var(${value})`;
1760
+ return value;
1761
+ }
1716
1762
  export {
1717
1763
  SPACING_CUSTOM_PROPERTY,
1718
1764
  defaultSections,
1719
1765
  defineConfig,
1720
1766
  generate,
1721
1767
  incrementCssValue,
1768
+ maybeCssVar,
1722
1769
  newAliasesMethods,
1723
1770
  newCoreIncrementMethods,
1724
1771
  newIncrementMethods,