@homebound/truss 1.137.4 → 2.0.0-next.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.
Files changed (146) hide show
  1. package/build/index.d.ts +264 -5
  2. package/build/index.js +1418 -31
  3. package/build/index.js.map +1 -1
  4. package/build/plugin/index.d.ts +71 -0
  5. package/build/plugin/index.js +1577 -0
  6. package/build/plugin/index.js.map +1 -0
  7. package/cli.js +32 -16
  8. package/package.json +27 -20
  9. package/tsup.config.ts +18 -0
  10. package/vitest.config.ts +13 -0
  11. package/build/breakpoints.d.ts +0 -7
  12. package/build/breakpoints.js +0 -79
  13. package/build/breakpoints.js.map +0 -1
  14. package/build/breakpoints.test.d.ts +0 -1
  15. package/build/breakpoints.test.js +0 -49
  16. package/build/breakpoints.test.js.map +0 -1
  17. package/build/config.d.ts +0 -109
  18. package/build/config.js +0 -15
  19. package/build/config.js.map +0 -1
  20. package/build/generate.d.ts +0 -4
  21. package/build/generate.js +0 -155
  22. package/build/generate.js.map +0 -1
  23. package/build/methods.d.ts +0 -82
  24. package/build/methods.js +0 -190
  25. package/build/methods.js.map +0 -1
  26. package/build/methods.test.d.ts +0 -1
  27. package/build/methods.test.js +0 -69
  28. package/build/methods.test.js.map +0 -1
  29. package/build/sections/tachyons/border.d.ts +0 -2
  30. package/build/sections/tachyons/border.js +0 -45
  31. package/build/sections/tachyons/border.js.map +0 -1
  32. package/build/sections/tachyons/borderColors.d.ts +0 -2
  33. package/build/sections/tachyons/borderColors.js +0 -30
  34. package/build/sections/tachyons/borderColors.js.map +0 -1
  35. package/build/sections/tachyons/borderRadius.d.ts +0 -2
  36. package/build/sections/tachyons/borderRadius.js +0 -17
  37. package/build/sections/tachyons/borderRadius.js.map +0 -1
  38. package/build/sections/tachyons/borderStyles.d.ts +0 -2
  39. package/build/sections/tachyons/borderStyles.js +0 -16
  40. package/build/sections/tachyons/borderStyles.js.map +0 -1
  41. package/build/sections/tachyons/borderWidths.d.ts +0 -2
  42. package/build/sections/tachyons/borderWidths.js +0 -13
  43. package/build/sections/tachyons/borderWidths.js.map +0 -1
  44. package/build/sections/tachyons/boxShadow.d.ts +0 -2
  45. package/build/sections/tachyons/boxShadow.js +0 -10
  46. package/build/sections/tachyons/boxShadow.js.map +0 -1
  47. package/build/sections/tachyons/container.d.ts +0 -2
  48. package/build/sections/tachyons/container.js +0 -36
  49. package/build/sections/tachyons/container.js.map +0 -1
  50. package/build/sections/tachyons/coordinates.d.ts +0 -2
  51. package/build/sections/tachyons/coordinates.js +0 -12
  52. package/build/sections/tachyons/coordinates.js.map +0 -1
  53. package/build/sections/tachyons/cursor.d.ts +0 -2
  54. package/build/sections/tachyons/cursor.js +0 -35
  55. package/build/sections/tachyons/cursor.js.map +0 -1
  56. package/build/sections/tachyons/display.d.ts +0 -2
  57. package/build/sections/tachyons/display.js +0 -25
  58. package/build/sections/tachyons/display.js.map +0 -1
  59. package/build/sections/tachyons/flexbox.d.ts +0 -2
  60. package/build/sections/tachyons/flexbox.js +0 -129
  61. package/build/sections/tachyons/flexbox.js.map +0 -1
  62. package/build/sections/tachyons/floats.d.ts +0 -2
  63. package/build/sections/tachyons/floats.js +0 -13
  64. package/build/sections/tachyons/floats.js.map +0 -1
  65. package/build/sections/tachyons/fontWeight.d.ts +0 -2
  66. package/build/sections/tachyons/fontWeight.js +0 -21
  67. package/build/sections/tachyons/fontWeight.js.map +0 -1
  68. package/build/sections/tachyons/grid.d.ts +0 -2
  69. package/build/sections/tachyons/grid.js +0 -39
  70. package/build/sections/tachyons/grid.js.map +0 -1
  71. package/build/sections/tachyons/heights.d.ts +0 -2
  72. package/build/sections/tachyons/heights.js +0 -62
  73. package/build/sections/tachyons/heights.js.map +0 -1
  74. package/build/sections/tachyons/index.d.ts +0 -37
  75. package/build/sections/tachyons/index.js +0 -76
  76. package/build/sections/tachyons/index.js.map +0 -1
  77. package/build/sections/tachyons/lineClamp.d.ts +0 -2
  78. package/build/sections/tachyons/lineClamp.js +0 -38
  79. package/build/sections/tachyons/lineClamp.js.map +0 -1
  80. package/build/sections/tachyons/objectFit.d.ts +0 -2
  81. package/build/sections/tachyons/objectFit.js +0 -16
  82. package/build/sections/tachyons/objectFit.js.map +0 -1
  83. package/build/sections/tachyons/opacity.d.ts +0 -2
  84. package/build/sections/tachyons/opacity.js +0 -38
  85. package/build/sections/tachyons/opacity.js.map +0 -1
  86. package/build/sections/tachyons/outlines.d.ts +0 -2
  87. package/build/sections/tachyons/outlines.js +0 -13
  88. package/build/sections/tachyons/outlines.js.map +0 -1
  89. package/build/sections/tachyons/overflow.d.ts +0 -2
  90. package/build/sections/tachyons/overflow.js +0 -50
  91. package/build/sections/tachyons/overflow.js.map +0 -1
  92. package/build/sections/tachyons/position.d.ts +0 -2
  93. package/build/sections/tachyons/position.js +0 -17
  94. package/build/sections/tachyons/position.js.map +0 -1
  95. package/build/sections/tachyons/skins.d.ts +0 -2
  96. package/build/sections/tachyons/skins.js +0 -51
  97. package/build/sections/tachyons/skins.js.map +0 -1
  98. package/build/sections/tachyons/spacing.d.ts +0 -2
  99. package/build/sections/tachyons/spacing.js +0 -60
  100. package/build/sections/tachyons/spacing.js.map +0 -1
  101. package/build/sections/tachyons/textAlign.d.ts +0 -2
  102. package/build/sections/tachyons/textAlign.js +0 -15
  103. package/build/sections/tachyons/textAlign.js.map +0 -1
  104. package/build/sections/tachyons/textDecoration.d.ts +0 -2
  105. package/build/sections/tachyons/textDecoration.js +0 -13
  106. package/build/sections/tachyons/textDecoration.js.map +0 -1
  107. package/build/sections/tachyons/textTransform.d.ts +0 -2
  108. package/build/sections/tachyons/textTransform.js +0 -15
  109. package/build/sections/tachyons/textTransform.js.map +0 -1
  110. package/build/sections/tachyons/typeScale.d.ts +0 -3
  111. package/build/sections/tachyons/typeScale.js +0 -42
  112. package/build/sections/tachyons/typeScale.js.map +0 -1
  113. package/build/sections/tachyons/typography.d.ts +0 -2
  114. package/build/sections/tachyons/typography.js +0 -48
  115. package/build/sections/tachyons/typography.js.map +0 -1
  116. package/build/sections/tachyons/userSelect.d.ts +0 -2
  117. package/build/sections/tachyons/userSelect.js +0 -15
  118. package/build/sections/tachyons/userSelect.js.map +0 -1
  119. package/build/sections/tachyons/verticalAlign.d.ts +0 -2
  120. package/build/sections/tachyons/verticalAlign.js +0 -14
  121. package/build/sections/tachyons/verticalAlign.js.map +0 -1
  122. package/build/sections/tachyons/visibility.d.ts +0 -2
  123. package/build/sections/tachyons/visibility.js +0 -13
  124. package/build/sections/tachyons/visibility.js.map +0 -1
  125. package/build/sections/tachyons/whitespace.d.ts +0 -2
  126. package/build/sections/tachyons/whitespace.js +0 -16
  127. package/build/sections/tachyons/whitespace.js.map +0 -1
  128. package/build/sections/tachyons/widths.d.ts +0 -2
  129. package/build/sections/tachyons/widths.js +0 -60
  130. package/build/sections/tachyons/widths.js.map +0 -1
  131. package/build/sections/tachyons/wordBreak.d.ts +0 -2
  132. package/build/sections/tachyons/wordBreak.js +0 -15
  133. package/build/sections/tachyons/wordBreak.js.map +0 -1
  134. package/build/sections/tachyons/zIndex.d.ts +0 -2
  135. package/build/sections/tachyons/zIndex.js +0 -45
  136. package/build/sections/tachyons/zIndex.js.map +0 -1
  137. package/build/sections/tachyons-rn/index.d.ts +0 -3
  138. package/build/sections/tachyons-rn/index.js +0 -8
  139. package/build/sections/tachyons-rn/index.js.map +0 -1
  140. package/build/sections/tachyons-rn/spacing.d.ts +0 -2
  141. package/build/sections/tachyons-rn/spacing.js +0 -60
  142. package/build/sections/tachyons-rn/spacing.js.map +0 -1
  143. package/build/tsconfig.tsbuildinfo +0 -1
  144. package/build/utils.d.ts +0 -2
  145. package/build/utils.js +0 -11
  146. package/build/utils.js.map +0 -1
package/build/index.js CHANGED
@@ -1,32 +1,1419 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.newSetCssVariablesMethod = exports.newParamMethod = exports.newIncrementMethods = exports.newCoreIncrementMethods = exports.newMethodsForProp = exports.newPxMethod = exports.newMethod = exports.newAliasesMethods = exports.generate = exports.defaultSections = void 0;
18
- __exportStar(require("./config"), exports);
19
- var tachyons_1 = require("./sections/tachyons");
20
- Object.defineProperty(exports, "defaultSections", { enumerable: true, get: function () { return tachyons_1.defaultSections; } });
21
- var generate_1 = require("./generate");
22
- Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
23
- var methods_1 = require("./methods");
24
- Object.defineProperty(exports, "newAliasesMethods", { enumerable: true, get: function () { return methods_1.newAliasesMethods; } });
25
- Object.defineProperty(exports, "newMethod", { enumerable: true, get: function () { return methods_1.newMethod; } });
26
- Object.defineProperty(exports, "newPxMethod", { enumerable: true, get: function () { return methods_1.newPxMethod; } });
27
- Object.defineProperty(exports, "newMethodsForProp", { enumerable: true, get: function () { return methods_1.newMethodsForProp; } });
28
- Object.defineProperty(exports, "newCoreIncrementMethods", { enumerable: true, get: function () { return methods_1.newCoreIncrementMethods; } });
29
- Object.defineProperty(exports, "newIncrementMethods", { enumerable: true, get: function () { return methods_1.newIncrementMethods; } });
30
- Object.defineProperty(exports, "newParamMethod", { enumerable: true, get: function () { return methods_1.newParamMethod; } });
31
- Object.defineProperty(exports, "newSetCssVariablesMethod", { enumerable: true, get: function () { return methods_1.newSetCssVariablesMethod; } });
1
+ // src/config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
6
+ // src/methods.ts
7
+ var _stylexCollector = null;
8
+ function startStylexCollection() {
9
+ _stylexCollector = [];
10
+ }
11
+ function stopStylexCollection() {
12
+ const result = _stylexCollector;
13
+ _stylexCollector = null;
14
+ return result;
15
+ }
16
+ function collect(entry) {
17
+ if (_stylexCollector) _stylexCollector.push(entry);
18
+ }
19
+ function newMethod(abbr, defs) {
20
+ collect({ kind: "static", abbr, defs: { ...defs } });
21
+ return `${comment(defs)} get ${abbr}() { return this${Object.entries(defs).map(([prop, value]) => `.add("${prop}", ${maybeWrap(value)})`).join("")}; }`;
22
+ }
23
+ function newParamMethod(abbr, prop, extraProperties = {}) {
24
+ collect({
25
+ kind: "param",
26
+ abbr,
27
+ props: [prop],
28
+ extraDefs: Object.keys(extraProperties).length > 0 ? { ...extraProperties } : void 0
29
+ });
30
+ const additionalDefs2 = Object.entries(extraProperties).map(([prop2, value]) => `.add("${prop2}", ${maybeWrap(value)})`).join("");
31
+ return `${comment({
32
+ [prop]: "value"
33
+ })} ${abbr}(value: Properties["${prop}"]) { return this.add("${prop}", value)${additionalDefs2}; }`;
34
+ }
35
+ function newMethodsForProp(prop, defs, baseName = prop, includePx = false, valueMethodExtraProperties) {
36
+ return [
37
+ ...Object.entries(defs).map(
38
+ ([abbr, value]) => newMethod(
39
+ abbr,
40
+ // If the value is an object, use it as the full defs, otherwise, use it as the prop value
41
+ typeof value === "object" ? value : { [prop]: value }
42
+ )
43
+ ),
44
+ // Conditionally add a method that directly accepts a value for prop
45
+ ...baseName !== null ? [newParamMethod(baseName, prop, valueMethodExtraProperties)] : [],
46
+ ...baseName !== null && includePx ? [newPxMethod(baseName, prop)] : []
47
+ ];
48
+ }
49
+ function newAliasesMethods(aliases) {
50
+ return Object.entries(aliases).map(([abbr, values]) => {
51
+ collect({ kind: "alias", abbr, aliasTargets: values });
52
+ return `get ${abbr}() { return this${values.map((v) => `.${v}`).join("")}; }`;
53
+ });
54
+ }
55
+ function newSetCssVariablesMethod(abbr, defs) {
56
+ collect({ kind: "cssvar", abbr, defs: { ...defs } });
57
+ return `get ${abbr}() { return this${Object.entries(defs).map(([prop, value]) => `.add("${prop}" as any, "${value}")`).join("")}; }`;
58
+ }
59
+ function newIncrementMethods(config, abbr, prop, opts = {}) {
60
+ const props = typeof prop === "string" ? [prop] : prop;
61
+ const delegateMethods = newCoreIncrementMethods(config, abbr, props);
62
+ const autoComment = comment(Object.fromEntries(props.map((p) => [p, "auto"])));
63
+ const valueComment = comment(Object.fromEntries(props.map((p) => [p, "v"])));
64
+ const pxComment = comment(Object.fromEntries(props.map((p) => [p, "px"])));
65
+ if (opts.auto) {
66
+ collect({ kind: "static", abbr: `${abbr}a`, defs: Object.fromEntries(props.map((p) => [p, "auto"])) });
67
+ }
68
+ collect({ kind: "increment-param", abbr, props, usesMaybeInc: true });
69
+ collect({ kind: "px-delegate", abbr: `${abbr}Px`, props });
70
+ return [
71
+ ...delegateMethods,
72
+ ...opts.auto ? [`${autoComment} get ${abbr}a() { return this.${props.map((p) => `add("${p}", "auto")`).join(".")}; }`] : [],
73
+ `${valueComment} ${abbr}(v: number | string) { return this.${props.map((p) => `add("${p}", maybeInc(v))`).join(".")}; }`,
74
+ `${pxComment} ${abbr}Px(px: number) { return this.${props.map((p) => `add("${p}", \`\${px}px\`)`).join(".")}; }`
75
+ ];
76
+ }
77
+ function newCoreIncrementMethods(config, abbr, props) {
78
+ return zeroTo(config.numberOfIncrements).map((i) => {
79
+ const px = `${i * config.increment}px`;
80
+ const defs = Object.fromEntries(props.map((p) => [p, px]));
81
+ collect({ kind: "static", abbr: `${abbr}${i}`, defs });
82
+ const sets = props.map((p) => `add("${p}", "${px}")`).join(".");
83
+ return `${comment(defs)} get ${abbr}${i}() { return this.${sets}; }`;
84
+ });
85
+ }
86
+ function newPxMethod(abbr, prop) {
87
+ collect({ kind: "px-delegate", abbr: `${abbr}Px`, props: [prop] });
88
+ return `${comment({ [prop]: "px" })} ${abbr}Px(px: number) { return this.${abbr}(\`\${px}px\`); }`;
89
+ }
90
+ var zeroTo = (n) => [...Array(n + 1).keys()];
91
+ function maybeWrap(value) {
92
+ return typeof value === "number" ? String(value) : `"${value}"`;
93
+ }
94
+ function comment(defs) {
95
+ const paramNames = ["value", "px", "inc"];
96
+ const values = Object.entries(defs).map(([prop, value]) => `${prop}: ${paramNames.includes(value) ? value : maybeWrap(value)}`).join("; ");
97
+ return `/** Sets \`${values}\`. */
98
+ `;
99
+ }
100
+
101
+ // src/sections/tachyons/border.ts
102
+ var borderDefs = [
103
+ ["ba", ["borderStyle", "borderWidth"]],
104
+ ["bt", ["borderTopStyle", "borderTopWidth"]],
105
+ ["br", ["borderRightStyle", "borderRightWidth"]],
106
+ ["bb", ["borderBottomStyle", "borderBottomWidth"]],
107
+ ["bl", ["borderLeftStyle", "borderLeftWidth"]]
108
+ ];
109
+ var border = () => [
110
+ ...borderDefs.map(([abbr, [style, width2]]) => {
111
+ return newMethod(abbr, { [style]: "solid", [width2]: "1px" });
112
+ }),
113
+ newMethod("bn", { borderStyle: "none", borderWidth: "0" })
114
+ ];
115
+
116
+ // src/sections/tachyons/borderColors.ts
117
+ var borderColor = ({ palette }) => {
118
+ const defs = Object.fromEntries(Object.entries(palette).map(([key, value]) => [`bc${key}`, value]));
119
+ return newMethodsForProp("borderColor", defs, "bc");
120
+ };
121
+
122
+ // src/sections/tachyons/borderRadius.ts
123
+ var borderRadius = () => newMethodsForProp("borderRadius", {
124
+ br0: "0",
125
+ br1: ".125rem",
126
+ br2: ".25rem",
127
+ br3: ".5rem",
128
+ br4: "1rem",
129
+ br100: "100%",
130
+ brPill: "9999px"
131
+ });
132
+
133
+ // src/sections/tachyons/borderStyles.ts
134
+ var borderStyle = () => newMethodsForProp(
135
+ "borderStyle",
136
+ {
137
+ bsDashed: "dashed",
138
+ bsDotted: "dotted",
139
+ bsn: "none",
140
+ bss: "solid"
141
+ },
142
+ "bs"
143
+ );
144
+
145
+ // src/sections/tachyons/borderWidths.ts
146
+ var borderWidth = () => newMethodsForProp(
147
+ "borderWidth",
148
+ {
149
+ bw1: "1px",
150
+ bw2: "2px"
151
+ },
152
+ "bw"
153
+ );
154
+
155
+ // src/sections/tachyons/boxShadow.ts
156
+ var boxShadow = () => [
157
+ // bsn is taken by `borderStyle: none`.
158
+ newMethod("shadowNone", { boxShadow: "none" })
159
+ ];
160
+
161
+ // src/sections/tachyons/coordinates.ts
162
+ var directions = ["top", "right", "bottom", "left"];
163
+ var coordinates = (config) => directions.flatMap((d) => {
164
+ return newIncrementMethods(config, d, d);
165
+ });
166
+
167
+ // src/sections/tachyons/cursor.ts
168
+ var cursor = () => [
169
+ ...newMethodsForProp("cursor", {
170
+ cursorPointer: "pointer",
171
+ cursorNotAllowed: "not-allowed"
172
+ })
173
+ ];
174
+
175
+ // src/sections/tachyons/display.ts
176
+ var display = () => newMethodsForProp("display", {
177
+ dn: "none",
178
+ db: "block",
179
+ dib: "inline-block",
180
+ dit: "inline-table",
181
+ dt: "table",
182
+ dtc: "table-cell",
183
+ dtRow: "table-row",
184
+ dtColumn: "table-column",
185
+ dtColumnGroup: "table-column-group",
186
+ // added
187
+ dg: "grid",
188
+ dig: "inline-grid",
189
+ df: "flex",
190
+ dif: "inline-flex"
191
+ });
192
+
193
+ // src/sections/tachyons/flexbox.ts
194
+ var flexbox = () => [
195
+ ...newMethodsForProp(
196
+ "flex",
197
+ {
198
+ fi: "initial",
199
+ fa: "auto",
200
+ fn: "none",
201
+ f1: "1",
202
+ f2: "2",
203
+ f3: "3",
204
+ f4: "4",
205
+ f5: "5"
206
+ },
207
+ "f"
208
+ ),
209
+ ...newMethodsForProp(
210
+ "justifyContent",
211
+ {
212
+ jcfs: "flex-start",
213
+ jcfe: "flex-end",
214
+ jcc: "center",
215
+ jcsb: "space-between",
216
+ jcsa: "space-around",
217
+ jcse: "space-evenly"
218
+ },
219
+ "jc"
220
+ ),
221
+ ...newMethodsForProp(
222
+ "justifySelf",
223
+ {
224
+ jsa: "auto",
225
+ jsc: "center",
226
+ jss: "start",
227
+ jse: "end"
228
+ },
229
+ "js"
230
+ ),
231
+ ...newMethodsForProp(
232
+ "justifyItems",
233
+ {
234
+ jifs: "flex-start",
235
+ jife: "flex-end",
236
+ jic: "center",
237
+ jisb: "space-between",
238
+ jisa: "space-around",
239
+ jise: "space-evenly"
240
+ },
241
+ "ji"
242
+ ),
243
+ ...newMethodsForProp(
244
+ "alignSelf",
245
+ {
246
+ asfs: "flex-start",
247
+ asfe: "flex-end",
248
+ asc: "center",
249
+ asb: "baseline",
250
+ asStretch: "stretch"
251
+ },
252
+ "as"
253
+ ),
254
+ ...newMethodsForProp(
255
+ "alignItems",
256
+ {
257
+ aifs: "flex-start",
258
+ aife: "flex-end",
259
+ ais: "start",
260
+ aie: "end",
261
+ aic: "center",
262
+ aib: "baseline",
263
+ aiStretch: "stretch"
264
+ },
265
+ "ai"
266
+ ),
267
+ ...newMethodsForProp(
268
+ "placeSelf",
269
+ {
270
+ psa: "auto",
271
+ psc: "center",
272
+ pss: "start",
273
+ pse: "end",
274
+ psfs: "flex-start",
275
+ psfe: "flex-end",
276
+ psStretch: "stretch"
277
+ },
278
+ "ps"
279
+ ),
280
+ ...newMethodsForProp(
281
+ "placeContent",
282
+ {
283
+ pcc: "center",
284
+ pcs: "start",
285
+ pce: "end",
286
+ pcsb: "space-between",
287
+ pcsa: "space-around",
288
+ pcse: "space-evenly",
289
+ pcb: "baseline",
290
+ pcStretch: "stretch"
291
+ },
292
+ "pc"
293
+ ),
294
+ ...newMethodsForProp(
295
+ "placeItems",
296
+ {
297
+ pic: "center",
298
+ pis: "start",
299
+ pie: "end",
300
+ pisb: "space-between",
301
+ pisa: "space-around",
302
+ pise: "space-evenly",
303
+ pib: "baseline",
304
+ piStretch: "stretch"
305
+ },
306
+ "pi"
307
+ ),
308
+ ...newMethodsForProp(
309
+ "flexBasis",
310
+ // https://github.com/tack-hammer/tailwind-plugin-flex-basis#usage
311
+ {
312
+ fb1: "100%",
313
+ fb2: "50%",
314
+ fb3: "33.333333%",
315
+ fb4: "25%",
316
+ fb5: "20%",
317
+ fb6: "16.666666%",
318
+ fb7: "14.285714%",
319
+ fb0: "12.5%"
320
+ },
321
+ "fb"
322
+ ),
323
+ ...newMethodsForProp("flexGrow", { fg0: 0, fg1: 1 }),
324
+ ...newMethodsForProp("flexShrink", { fs0: 0, fs1: 1 }),
325
+ ...newMethodsForProp(
326
+ "flexDirection",
327
+ {
328
+ fdr: "row",
329
+ fdrr: "row-reverse",
330
+ fdc: "column",
331
+ fdcr: "column-reverse"
332
+ },
333
+ "fd"
334
+ ),
335
+ ...newMethodsForProp(
336
+ "flexWrap",
337
+ {
338
+ fww: "wrap",
339
+ fwr: "wrap-reverse",
340
+ fwnw: "nowrap"
341
+ },
342
+ "flexWrap"
343
+ ),
344
+ newParamMethod("order", "order")
345
+ ];
346
+
347
+ // src/sections/tachyons/floats.ts
348
+ var float = () => newMethodsForProp(
349
+ "float",
350
+ {
351
+ fl: "left",
352
+ fr: "right"
353
+ },
354
+ "float"
355
+ );
356
+
357
+ // src/sections/tachyons/fontWeight.ts
358
+ var fontWeight = () => newMethodsForProp(
359
+ "fontWeight",
360
+ {
361
+ fwn: "normal",
362
+ fwb: "bold",
363
+ fw1: 100,
364
+ fw2: 200,
365
+ fw3: 300,
366
+ fw4: 400,
367
+ fw5: 500,
368
+ fw6: 600,
369
+ fw7: 700,
370
+ fw8: 800,
371
+ fw9: 900
372
+ },
373
+ "fw"
374
+ );
375
+
376
+ // src/sections/tachyons/grid.ts
377
+ var grid = (config) => [
378
+ newParamMethod("gtc", "gridTemplateColumns"),
379
+ newParamMethod("gtr", "gridTemplateRows"),
380
+ newParamMethod("gr", "gridRow"),
381
+ newParamMethod("gc", "gridColumn"),
382
+ newParamMethod("gar", "gridAutoRows"),
383
+ newParamMethod("gac", "gridAutoColumns"),
384
+ ...newIncrementMethods(config, "gap", "gap"),
385
+ ...newIncrementMethods(config, "rg", "rowGap"),
386
+ ...newIncrementMethods(config, "cg", "columnGap")
387
+ ];
388
+
389
+ // src/sections/tachyons/heights.ts
390
+ var height = (config) => [
391
+ // https://github.com/tachyons-css/tachyons/blob/master/src/_heights.css
392
+ // Technically h1 in tachyons is 1em and ours is 1 inc
393
+ ...newIncrementMethods(config, "h", "height", { auto: true }),
394
+ ...newMethodsForProp(
395
+ "height",
396
+ {
397
+ h25: "25%",
398
+ h50: "50%",
399
+ h75: "75%",
400
+ h100: "100%",
401
+ vh25: "25vh",
402
+ vh50: "50vh",
403
+ vh75: "75vh",
404
+ vh100: "100vh",
405
+ hfc: "fit-content",
406
+ hmaxc: "max-content",
407
+ hminc: "min-content"
408
+ },
409
+ // Skip `h` here b/c it's created by newIncrementMethods below
410
+ null
411
+ ),
412
+ ...newMethodsForProp(
413
+ "minHeight",
414
+ {
415
+ mh0: 0,
416
+ mh25: "25%",
417
+ mh50: "50%",
418
+ mh75: "75%",
419
+ mh100: "100%",
420
+ mvh100: "100vh"
421
+ },
422
+ "mh",
423
+ true
424
+ ),
425
+ ...newMethodsForProp(
426
+ "maxHeight",
427
+ {
428
+ maxh0: "0",
429
+ maxh25: "25%",
430
+ maxh50: "50%",
431
+ maxh75: "75%",
432
+ maxh100: "100%"
433
+ },
434
+ "maxh",
435
+ true
436
+ ),
437
+ // Sneak this into heights.ts even though it's for width & height
438
+ `${comment({ height: "px", width: "px" })}
439
+ sqPx(px: number) { return this.add("height", \`\${px}px\`).add("width", \`\${px}px\`); }`
440
+ ];
441
+
442
+ // src/sections/tachyons/lineClamp.ts
443
+ var additionalDefs = {
444
+ overflow: "hidden",
445
+ display: "-webkit-box",
446
+ // As of 11/28/2022, this is deprecated but still necessary for lineClamp to work:
447
+ // https://github.com/tailwindlabs/tailwindcss-line-clamp/blob/master/src/index.js
448
+ WebkitBoxOrient: "vertical",
449
+ // tailwinds doesn't add this by default, but it seems like a good default for us.
450
+ textOverflow: "ellipsis"
451
+ };
452
+ var lineClamp = () => newMethodsForProp(
453
+ "WebkitLineClamp",
454
+ {
455
+ lineClamp1: { ...additionalDefs, WebkitLineClamp: 1 },
456
+ lineClamp2: { ...additionalDefs, WebkitLineClamp: 2 },
457
+ lineClamp3: { ...additionalDefs, WebkitLineClamp: 3 },
458
+ lineClamp4: { ...additionalDefs, WebkitLineClamp: 4 },
459
+ lineClamp5: { ...additionalDefs, WebkitLineClamp: 5 },
460
+ lineClamp6: { ...additionalDefs, WebkitLineClamp: 6 },
461
+ lineClampNone: { WebkitLineClamp: "unset" }
462
+ },
463
+ "lineClamp",
464
+ false,
465
+ additionalDefs
466
+ );
467
+
468
+ // src/sections/tachyons/objectFit.ts
469
+ var objectFit = () => newMethodsForProp("objectFit", {
470
+ objectContain: "contain",
471
+ objectCover: "cover",
472
+ objectFill: "fill",
473
+ objectNone: "none",
474
+ objectScaleDown: "scale-down"
475
+ });
476
+
477
+ // src/sections/tachyons/outlines.ts
478
+ var outline = () => newMethodsForProp("outline", {
479
+ outline1: "1px solid",
480
+ outlineTransparent: "1px solid transparent",
481
+ outline0: "0"
482
+ });
483
+
484
+ // src/sections/tachyons/overflow.ts
485
+ var overflow = () => {
486
+ return [
487
+ ...newMethodsForProp("overflow", {
488
+ ov: "visible",
489
+ oh: "hidden",
490
+ os: "scroll",
491
+ oa: "auto"
492
+ }),
493
+ ...newMethodsForProp("overflowY", {
494
+ oyv: "visible",
495
+ oyh: "hidden",
496
+ oys: "scroll",
497
+ oya: "auto"
498
+ }),
499
+ ...newMethodsForProp("overflowX", {
500
+ oxv: "visible",
501
+ oxh: "hidden",
502
+ oxs: "scroll",
503
+ oxa: "auto"
504
+ })
505
+ ];
506
+ };
507
+
508
+ // src/sections/tachyons/position.ts
509
+ var position = () => newMethodsForProp("position", {
510
+ absolute: "absolute",
511
+ fixed: "fixed",
512
+ static: "static",
513
+ relative: "relative",
514
+ // added
515
+ sticky: "sticky"
516
+ });
517
+
518
+ // src/utils.ts
519
+ function lowerCaseFirst(s) {
520
+ return s.charAt(0).toLowerCase() + s.substr(1);
521
+ }
522
+ function quote(s) {
523
+ return `"${s}"`;
524
+ }
525
+
526
+ // src/sections/tachyons/skins.ts
527
+ var skins = (config) => {
528
+ const { palette } = config;
529
+ const colors = newMethodsForProp(
530
+ "color",
531
+ Object.fromEntries(
532
+ Object.entries(palette).map(([key, value]) => [
533
+ lowerCaseFirst(key),
534
+ value
535
+ ])
536
+ )
537
+ );
538
+ const backgroundColors = newMethodsForProp(
539
+ "backgroundColor",
540
+ Object.fromEntries(
541
+ Object.entries(palette).map(([key, value]) => [`bg${key}`, value])
542
+ ),
543
+ "bgColor"
544
+ );
545
+ const fillColors = newMethodsForProp(
546
+ "fill",
547
+ Object.fromEntries(
548
+ Object.entries(palette).map(([key, value]) => [`f${key}`, value])
549
+ )
550
+ );
551
+ return [...colors, ...backgroundColors, ...fillColors];
552
+ };
553
+
554
+ // src/sections/tachyons/spacing.ts
555
+ var spacing = (config) => {
556
+ const marginDefs = [
557
+ ["mt", "marginTop"],
558
+ ["mr", "marginRight"],
559
+ ["mb", "marginBottom"],
560
+ ["ml", "marginLeft"],
561
+ ["mx", ["marginLeft", "marginRight"]],
562
+ ["my", ["marginTop", "marginBottom"]],
563
+ ["m", ["marginTop", "marginBottom", "marginRight", "marginLeft"]]
564
+ ];
565
+ const margins = [...marginDefs.map(([abbr, conf]) => newIncrementMethods(config, abbr, conf, { auto: true })).flat()];
566
+ const paddingDefs = [
567
+ ["pt", "paddingTop"],
568
+ ["pr", "paddingRight"],
569
+ ["pb", "paddingBottom"],
570
+ ["pl", "paddingLeft"],
571
+ ["px", ["paddingLeft", "paddingRight"]],
572
+ ["py", ["paddingTop", "paddingBottom"]],
573
+ ["p", ["paddingTop", "paddingBottom", "paddingRight", "paddingLeft"]]
574
+ ];
575
+ const paddings = paddingDefs.map(([abbr, conf]) => newIncrementMethods(config, abbr, conf)).flat();
576
+ return [...margins, ...paddings];
577
+ };
578
+
579
+ // src/sections/tachyons/textAlign.ts
580
+ var textAlign = () => newMethodsForProp(
581
+ "textAlign",
582
+ {
583
+ tal: "left",
584
+ tac: "center",
585
+ tar: "right",
586
+ taj: "justify"
587
+ },
588
+ "ta"
589
+ );
590
+
591
+ // src/sections/tachyons/textDecoration.ts
592
+ var textDecoration = () => newMethodsForProp("textDecoration", {
593
+ tdn: "none",
594
+ tdlt: "line-through",
595
+ tdu: "underline"
596
+ });
597
+
598
+ // src/sections/tachyons/textTransform.ts
599
+ var textTransform = () => newMethodsForProp(
600
+ "textTransform",
601
+ {
602
+ ttc: "capitalize",
603
+ ttl: "lowercase",
604
+ ttu: "uppercase",
605
+ ttn: "none"
606
+ },
607
+ "tt"
608
+ );
609
+
610
+ // src/sections/tachyons/typeScale.ts
611
+ var typeScale = ({ fonts }) => [
612
+ ...Object.entries(fonts).map(([abbr, defs]) => {
613
+ if (typeof defs === "string") {
614
+ return newMethod(abbr, { fontSize: defs });
615
+ }
616
+ return newMethod(abbr, defs);
617
+ })
618
+ ];
619
+
620
+ // src/sections/tachyons/typography.ts
621
+ var typography = () => [
622
+ newMethod("measure", { maxWidth: "30em" }),
623
+ newMethod("measureWide", { maxWidth: "34em" }),
624
+ newMethod("measureNarrow", { maxWidth: "20em" }),
625
+ newMethod("indent", {
626
+ textIndent: "1em",
627
+ marginTop: 0,
628
+ marginBottom: 0
629
+ }),
630
+ newMethod("smallCaps", { fontVariant: "small-caps" }),
631
+ newMethod("truncate", {
632
+ whiteSpace: "nowrap",
633
+ overflow: "hidden",
634
+ textOverflow: "ellipsis"
635
+ }),
636
+ // Include `fs(...)` & `fsPx(...)` for one-off font-sizes. We technically also have
637
+ // `fs0` and `fs1` for `flexShrink`, but this seems fine.
638
+ ...newMethodsForProp("fontSize", {}, "fs", true),
639
+ ...newMethodsForProp("lineHeight", {}, "lh", true)
640
+ ];
641
+
642
+ // src/sections/tachyons/userSelect.ts
643
+ var userSelect = () => newMethodsForProp(
644
+ "userSelect",
645
+ {
646
+ usn: "none",
647
+ ust: "text",
648
+ usAll: "all",
649
+ usAuto: "auto"
650
+ },
651
+ "select"
652
+ );
653
+
654
+ // src/sections/tachyons/verticalAlign.ts
655
+ var verticalAlign = () => newMethodsForProp(
656
+ "verticalAlign",
657
+ {
658
+ vaBaseline: "baseline",
659
+ vam: "middle",
660
+ vat: "top",
661
+ vaBottom: "bottom"
662
+ },
663
+ "va"
664
+ );
665
+
666
+ // src/sections/tachyons/visibility.ts
667
+ var visibility = () => newMethodsForProp("visibility", {
668
+ vv: "visible",
669
+ vh: "hidden"
670
+ });
671
+
672
+ // src/sections/tachyons/whitespace.ts
673
+ var whitespace = () => newMethodsForProp("whiteSpace", {
674
+ wsp: "pre",
675
+ wsn: "normal",
676
+ wsnw: "nowrap",
677
+ wsbs: "break-spaces",
678
+ wspw: "pre-wrap",
679
+ wspl: "pre-line"
680
+ });
681
+
682
+ // src/sections/tachyons/widths.ts
683
+ var width = (config) => [
684
+ ...newMethodsForProp(
685
+ "width",
686
+ {
687
+ w25: "25%",
688
+ w50: "50%",
689
+ w75: "75%",
690
+ w100: "100%",
691
+ wfc: "fit-content",
692
+ wmaxc: "max-content",
693
+ wminc: "min-content"
694
+ },
695
+ // Skip `w` here b/c it's created by newIncrementMethods below
696
+ null
697
+ ),
698
+ ...newMethodsForProp(
699
+ "minWidth",
700
+ {
701
+ mw0: 0,
702
+ mw25: "25%",
703
+ mw50: "50%",
704
+ mw75: "75%",
705
+ mw100: "100%",
706
+ mwfc: "fit-content",
707
+ mwminc: "min-content",
708
+ mwmaxc: "max-content"
709
+ },
710
+ "mw",
711
+ true
712
+ ),
713
+ ...newMethodsForProp(
714
+ "maxWidth",
715
+ {
716
+ maxw0: "0",
717
+ maxw25: "25%",
718
+ maxw50: "50%",
719
+ maxw75: "75%",
720
+ maxw100: "100%",
721
+ maxwfc: "fit-content",
722
+ maxwminc: "min-content",
723
+ maxwmaxc: "max-content"
724
+ },
725
+ "maxw",
726
+ true
727
+ ),
728
+ ...newIncrementMethods(config, "w", "width", { auto: true })
729
+ ];
730
+
731
+ // src/sections/tachyons/wordBreak.ts
732
+ var wordBreak = () => newMethodsForProp("wordBreak", {
733
+ wbn: "normal",
734
+ wbba: "break-all",
735
+ wbka: "keep-all",
736
+ wbbw: "break-word"
737
+ });
738
+
739
+ // src/sections/tachyons/zIndex.ts
740
+ var zIndex = (config) => [
741
+ // Even though we define const z0/z1/etc indexes to follow Tachyons, ideally applications
742
+ // should define their own application-specific indexes, i.e.:
743
+ //
744
+ // export const zIndexes = {
745
+ // ourModals: 10,
746
+ // ourLabels: 12,
747
+ // }
748
+ //
749
+ // And then use `Css.z(zIndexes.ourModals).$` to get better documentation and maintainability
750
+ // then just using the zN abbreviations.
751
+ ...newMethodsForProp(
752
+ "zIndex",
753
+ {
754
+ z0: 0,
755
+ z1: 1,
756
+ z2: 2,
757
+ z3: 3,
758
+ z4: 4,
759
+ z5: 5,
760
+ z999: 999,
761
+ z9999: 9999,
762
+ zInherit: "inherit",
763
+ zInitial: "initial",
764
+ zUnset: "unset"
765
+ },
766
+ "z"
767
+ )
768
+ ];
769
+
770
+ // src/sections/tachyons/container.ts
771
+ var container = () => [
772
+ ...newMethodsForProp(
773
+ "containerType",
774
+ {
775
+ cts: "size",
776
+ ctis: "inline-size",
777
+ ctn: "normal"
778
+ },
779
+ "ct"
780
+ ),
781
+ ...newMethodsForProp("containerName", {}, "cn")
782
+ ];
783
+
784
+ // src/sections/tachyons/opacity.ts
785
+ var opacity = () => [
786
+ ...newMethodsForProp(
787
+ "opacity",
788
+ {
789
+ o0: "0",
790
+ o25: "0.25",
791
+ o50: "0.5",
792
+ o75: "0.75",
793
+ o100: "1"
794
+ },
795
+ "o"
796
+ )
797
+ ];
798
+
799
+ // src/sections/tachyons/index.ts
800
+ var defaultSections = {
801
+ border,
802
+ borderColor,
803
+ borderRadius,
804
+ borderStyle,
805
+ borderWidth,
806
+ boxShadow,
807
+ container,
808
+ coordinates,
809
+ cursor,
810
+ display,
811
+ flexbox,
812
+ float,
813
+ fontWeight,
814
+ grid,
815
+ height,
816
+ lineClamp,
817
+ objectFit,
818
+ opacity,
819
+ outline,
820
+ overflow,
821
+ position,
822
+ skins,
823
+ spacing,
824
+ textAlign,
825
+ textDecoration,
826
+ textTransform,
827
+ typeScale,
828
+ typography,
829
+ userSelect,
830
+ verticalAlign,
831
+ visibility,
832
+ whitespace,
833
+ width,
834
+ wordBreak,
835
+ zIndex
836
+ };
837
+
838
+ // src/generate.ts
839
+ import { promises as fs } from "fs";
840
+ import { code, def, imp } from "ts-poet";
841
+
842
+ // src/breakpoints.ts
843
+ function makeBreakpoints(breakpoints) {
844
+ const r = {
845
+ print: "@media print"
846
+ };
847
+ const bps = Object.keys(breakpoints);
848
+ Object.entries(breakpoints).forEach(([bp, px], i) => {
849
+ const isFirst = i === 0;
850
+ const isLast = i === bps.length - 1;
851
+ const min = !isFirst ? `${px}px` : "0";
852
+ const max = !isLast ? `${breakpoints[bps[i + 1]] - 1}px` : "0";
853
+ if (isFirst) {
854
+ r[bp] = `@media (max-width: ${max})`;
855
+ } else if (isLast) {
856
+ r[bp] = `@media (min-width: ${min})`;
857
+ } else {
858
+ r[bp] = `@media (min-width: ${min}) and (max-width: ${max})`;
859
+ }
860
+ if (!isFirst) {
861
+ const isSecond = i === 1;
862
+ const prevBp = bps[i - 1];
863
+ const name = `${prevBp}Or${capitalize(bp)}`;
864
+ const parts = [];
865
+ if (!isSecond) {
866
+ const prevMin = breakpoints[bps[i - 1]];
867
+ parts.push(`(min-width: ${prevMin}px)`);
868
+ }
869
+ if (!isLast) {
870
+ parts.push(`(max-width: ${max})`);
871
+ }
872
+ r[name] = `@media ${parts.join(" and ")}`;
873
+ }
874
+ if (!isFirst && !isLast) {
875
+ r[`${bp}AndUp`] = `@media (min-width: ${min})`;
876
+ r[`${bp}AndDown`] = `@media (max-width: ${max})`;
877
+ }
878
+ });
879
+ return r;
880
+ }
881
+ function capitalize(s) {
882
+ return `${s[0].toUpperCase()}${s.substring(1)}`;
883
+ }
884
+
885
+ // src/generate.ts
886
+ import { pascalCase } from "change-case";
887
+
888
+ // src/sections/tachyons-rn/spacing.ts
889
+ var spacing2 = (config) => {
890
+ const marginDefs = [
891
+ ["mt", "marginTop"],
892
+ ["mr", "marginRight"],
893
+ ["mb", "marginBottom"],
894
+ ["ml", "marginLeft"],
895
+ ["mx", ["marginLeft", "marginRight"]],
896
+ ["my", ["marginTop", "marginBottom"]],
897
+ ["m", ["marginTop", "marginBottom", "marginRight", "marginLeft"]]
898
+ ];
899
+ const margins = [...marginDefs.map(([abbr, conf]) => newIncrementMethods(config, abbr, conf, { auto: true })).flat()];
900
+ const paddingDefs = [
901
+ ["pt", "paddingTop"],
902
+ ["pr", "paddingRight"],
903
+ ["pb", "paddingBottom"],
904
+ ["pl", "paddingLeft"],
905
+ ["px", ["paddingLeft", "paddingRight"]],
906
+ ["py", ["paddingTop", "paddingBottom"]],
907
+ ["p", ["paddingTop", "paddingBottom", "paddingRight", "paddingLeft"]]
908
+ ];
909
+ const paddings = paddingDefs.map(([abbr, conf]) => newIncrementMethods(config, abbr, conf)).flat();
910
+ return [...margins, ...paddings];
911
+ };
912
+
913
+ // src/sections/tachyons-rn/index.ts
914
+ var reactNativeSections = {
915
+ spacing: spacing2
916
+ };
917
+
918
+ // src/generate.ts
919
+ var CssProperties = imp("Properties@csstype");
920
+ var defaultTypeAliases = {
921
+ Margin: ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft"],
922
+ Padding: ["padding", "paddingTop", "paddingRight", "paddingBottom", "paddingLeft"]
923
+ };
924
+ async function generate(config) {
925
+ const { outputPath } = config;
926
+ const target = config.target ?? "stylex";
927
+ if (target === "stylex") {
928
+ const { sections, entries } = collectStylexGenerationData(config);
929
+ const cssOutput = generateStylexCssBuilder(config, sections).toString();
930
+ await fs.writeFile(outputPath, cssOutput);
931
+ const mappingPath = config.mappingOutputPath || outputPath.replace(/\.ts$/, ".json");
932
+ const mapping = generateTrussMapping(config, entries);
933
+ await fs.writeFile(mappingPath, condensedJson(mapping) + "\n");
934
+ return;
935
+ }
936
+ if (target === "react-native") {
937
+ const output = generateCssBuilder(config).toString();
938
+ await fs.writeFile(outputPath, output);
939
+ return;
940
+ }
941
+ throw new Error(`Unsupported truss target "${target}". Use "stylex" (default) or "react-native".`);
942
+ }
943
+ function generateCssBuilder(config) {
944
+ const { fonts, increment, extras, typeAliases, breakpoints = {}, palette } = config;
945
+ const sections = generateSections(config);
946
+ const lines = Object.entries(sections).map(([name, value]) => [`// ${name}`, ...value, ""]).flat();
947
+ const typeAliasCode = Object.entries({
948
+ ...defaultTypeAliases,
949
+ ...typeAliases
950
+ }).map(([name, props]) => {
951
+ return `export type ${name} = ${props.map(quote).join(" | ")};
952
+
953
+ `;
954
+ });
955
+ const typographyType = code`
956
+ export type ${def("Typography")} = ${Object.keys(fonts).map(quote).join(" | ")};
957
+ `;
958
+ const genBreakpoints = makeBreakpoints(breakpoints);
959
+ const breakpointCode = [
960
+ `export type Breakpoint = ${Object.keys(genBreakpoints).map(quote).join(" | ")};`,
961
+ `export enum Breakpoints {
962
+ ${Object.entries(genBreakpoints).map(([name, value]) => `${name} = "${value}"`)}
963
+ };`
964
+ ];
965
+ const breakpointIfs = Object.entries(genBreakpoints).map(([name, value]) => {
966
+ return code`
967
+ get if${pascalCase(name)}() {
968
+ return this.newCss({ selector: ${quote(value)} });
969
+ }`;
970
+ });
971
+ const containerQueriesCode = code`
972
+ /**
973
+ * Utility to help write \`@container\` queries
974
+ *
975
+ * @param name - The name of the container.
976
+ * @param lt - The maximum width of the container inclusive.
977
+ * @param gt - The minimum width of the container exclusive.
978
+ */
979
+ type ContainerProps = { name?: string } & ({ lt: number } | { gt: number } | { lt: number; gt: number });
980
+ export function Container(props: ContainerProps) {
981
+ const { name = "" } = props;
982
+ const lt = "lt" in props ? props.lt : undefined;
983
+ const gt = "gt" in props ? props.gt : undefined;
984
+
985
+ const ltQuery = lt !== undefined ? \`(max-width: \${lt}px)\` : "";
986
+ const gtQuery = gt !== undefined ? \`(min-width: \${gt + 1}px)\` : "";
987
+ const query = [ltQuery, gtQuery].filter(Boolean).join(" and ");
988
+
989
+ return \`@container \${name} \${query}\`;
990
+ }`;
991
+ return code`
992
+ // This file is auto-generated by truss: https://github.com/homebound-team/truss.
993
+ // See your project's \`truss-config.ts\` to make configuration changes (fonts, increments, etc).
994
+
995
+ /** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */
996
+ export type Only<X, T> = X & Record<Exclude<keyof T, keyof X>, never>;
997
+
998
+ export type ${def("Properties")} = ${CssProperties}<string | 0, string>;
999
+
1000
+ ${typographyType}
1001
+
1002
+ type Opts<T> = {
1003
+ rules: T,
1004
+ enabled: boolean,
1005
+ important: boolean,
1006
+ selector: string | undefined
1007
+ };
1008
+
1009
+ class CssBuilder<T extends Properties> {
1010
+ constructor(private opts: Opts<T>) {}
1011
+
1012
+ private get rules(): T { return this.opts.rules };
1013
+ private get enabled(): boolean { return this.opts.enabled };
1014
+ private get selector(): string | undefined { return this.opts.selector };
1015
+ private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {
1016
+ return new CssBuilder({ ...this.opts, ...opts });
1017
+ }
1018
+
1019
+ ${lines.join("\n ").replace(/ +\n/g, "\n")}
1020
+
1021
+ get $(): T { return maybeImportant(sortObject(this.rules), this.opts.important); }
1022
+
1023
+ if(bp: Breakpoint): CssBuilder<T>;
1024
+ if(cond: boolean): CssBuilder<T>;
1025
+ if(attr: string, value: boolean | string): CssBuilder<T>;
1026
+ if(arg: boolean | Breakpoint | string, value?: boolean | string): CssBuilder<T> {
1027
+ if (value !== undefined) {
1028
+ return this.newCss({ selector: \`[\${arg}='\${value}']\` });
1029
+ } else if (typeof arg === "boolean") {
1030
+ return this.newCss({ enabled: arg });
1031
+ } else {
1032
+ return this.newCss({ selector: Breakpoints[arg as Breakpoint] });
1033
+ }
1034
+ }
1035
+
1036
+ get onHover() {
1037
+ return this.newCss({ selector: ":hover" });
1038
+ }
1039
+
1040
+ ifContainer(props: ContainerProps) {
1041
+ return this.newCss({ selector: Container(props) });
1042
+ }
1043
+
1044
+ ${breakpointIfs}
1045
+
1046
+ get else() {
1047
+ if (this.selector !== undefined) {
1048
+ if (this.selector.includes("not")) {
1049
+ throw new Error("else was already called");
1050
+ } else {
1051
+ return this.newCss({ selector: this.selector.replace("@media", "@media not") });
1052
+ }
1053
+ }
1054
+ return this.newCss({ enabled: !this.enabled });
1055
+ }
1056
+
1057
+ get important() { return this.newCss({ important: true }); }
1058
+
1059
+ /** Adds new properties, either a specific key/value or a Properties object, to the current css. */
1060
+ add<P extends Properties>(props: P): CssBuilder<T & P>;
1061
+ add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;
1062
+ add<K extends keyof Properties>(propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {
1063
+ if (!this.enabled) return this;
1064
+ const newRules = typeof propOrProperties === "string" ? { [propOrProperties]: value } : propOrProperties;
1065
+ const rules = this.selector
1066
+ ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }
1067
+ : { ...this.rules, ...newRules };
1068
+ return this.newCss({ rules: rules as any });
1069
+ }
1070
+
1071
+ /** Adds new properties, either a specific key/value or a Properties object, to a nested selector. */
1072
+ addIn<P extends Properties>(selector: string, props: P | undefined): CssBuilder<T & P>;
1073
+ addIn<K extends keyof Properties>(selector: string, prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;
1074
+ addIn<K extends keyof Properties>(selector: string, propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {
1075
+ const newRules = typeof propOrProperties === "string" ? { [propOrProperties]: value } : propOrProperties;
1076
+ if (!this.enabled) return this;
1077
+ if (newRules === undefined) {
1078
+ return this;
1079
+ }
1080
+ const rules = { ...this.rules, [selector]: { ...(this.rules as any)[selector], ...newRules } };
1081
+ return this.newCss({ rules: rules as any });
1082
+ }
1083
+ }
1084
+
1085
+ /** Sort keys so equivalent rule objects have deterministic shape. */
1086
+ function sortObject<T extends object>(obj: T): T {
1087
+ return Object.keys(obj)
1088
+ .sort()
1089
+ .reduce((acc, key) => {
1090
+ acc[key as keyof T] = obj[key as keyof T];
1091
+ return acc;
1092
+ }, ({} as any) as T) as T;
1093
+ }
1094
+
1095
+ /** Conditionally adds \`important!\` to everything. */
1096
+ function maybeImportant<T extends object>(obj: T, important: boolean): T {
1097
+ if (important) {
1098
+ Object.keys(obj).forEach(key => {
1099
+ (obj as any)[key] = \`\${(obj as any)[key]} !important\`;
1100
+ });
1101
+ }
1102
+ return obj;
1103
+ }
1104
+
1105
+ /** Converts \`inc\` into pixels value with a \`px\` suffix. */
1106
+ export function maybeInc(inc: number | string): string {
1107
+ return typeof inc === "string" ? inc : \`\${increment(inc)}px\`;
1108
+ }
1109
+
1110
+ /** Converts \`inc\` into pixels. */
1111
+ export function increment(inc: number): number {
1112
+ return inc * ${increment};
1113
+ }
1114
+
1115
+ /** Convert \`pixels\` to a \`px\` units string so it's not ambiguous. */
1116
+ export function px(pixels: number): string {
1117
+ return \`\${pixels}px\`;
1118
+ }
1119
+
1120
+ export enum Palette {
1121
+ ${Object.entries(palette).map(([name, value]) => {
1122
+ return `${name} = "${value}",`;
1123
+ })}
1124
+ }
1125
+
1126
+ /** A shortcut for defining Xss types. */
1127
+ export type Xss<P extends keyof Properties> = Pick<Properties, P>;
1128
+
1129
+ /** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */
1130
+ export const Css = new CssBuilder({ rules: {}, enabled: true, important: false, selector: undefined });
1131
+
1132
+ ${typeAliasCode}
1133
+
1134
+ ${breakpointCode}
1135
+
1136
+ ${containerQueriesCode}
1137
+
1138
+ ${extras || ""}
1139
+ `;
1140
+ }
1141
+ function generateMethods(config, methodFns) {
1142
+ return Object.fromEntries(Object.entries(methodFns).map(([name, fn]) => [name, fn(config)]));
1143
+ }
1144
+ function generateSections(config) {
1145
+ const { aliases, defaultMethods = "tachyons", sections: customSections } = config;
1146
+ return {
1147
+ ...defaultMethods === "tachyons" ? generateMethods(config, defaultSections) : defaultMethods === "tachyons-rn" ? generateMethods(config, reactNativeSections) : {},
1148
+ ...customSections ? generateMethods(config, customSections) : {},
1149
+ ...aliases && { aliases: newAliasesMethods(aliases) }
1150
+ };
1151
+ }
1152
+ function collectStylexGenerationData(config) {
1153
+ startStylexCollection();
1154
+ try {
1155
+ const sections = generateSections(config);
1156
+ const entries = stopStylexCollection();
1157
+ return { sections, entries };
1158
+ } catch (error) {
1159
+ stopStylexCollection();
1160
+ throw error;
1161
+ }
1162
+ }
1163
+ function generateStylexCssBuilder(config, sections) {
1164
+ const { fonts, increment, extras, palette, breakpoints = {} } = config;
1165
+ const lines = Object.entries(sections).map(([name, value]) => [`// ${name}`, ...value, ""]).flat();
1166
+ const genBreakpointsMap = makeBreakpoints(breakpoints);
1167
+ const breakpointIfs = Object.entries(genBreakpointsMap).map(([name, value]) => {
1168
+ return code`
1169
+ get if${pascalCase(name)}() {
1170
+ return this.newCss({ selector: ${quote(value)} });
1171
+ }`;
1172
+ });
1173
+ const breakpointCode = [
1174
+ `export type Breakpoint = ${Object.keys(genBreakpointsMap).map(quote).join(" | ")};`,
1175
+ `export enum Breakpoints {`,
1176
+ ...Object.entries(genBreakpointsMap).map(([name, value]) => ` ${name} = "${value}",`),
1177
+ `}`
1178
+ ];
1179
+ const typographyType = code`
1180
+ export type ${def("Typography")} = ${Object.keys(fonts).map(quote).join(" | ")};
1181
+ `;
1182
+ return code`
1183
+ // This file is auto-generated by truss: https://github.com/homebound-team/truss.
1184
+ // See your project's \`truss-config.ts\` to make configuration changes (fonts, increments, etc).
1185
+ // Target: stylex (build-time plugin)
1186
+
1187
+ import * as stylex from "@stylexjs/stylex";
1188
+
1189
+ export type ${def("Properties")} = ${CssProperties}<string | 0, string>;
1190
+
1191
+ /** A marker returned by \`stylex.defineMarker()\`, used with \`when\`/\`markerOf\` etc. */
1192
+ export type Marker = ReturnType<typeof stylex.defineMarker>;
1193
+
1194
+ ${typographyType}
1195
+
1196
+ /** The type accepted by the \`css\` JSX prop. Opaque - the build-time plugin resolves this. */
1197
+ export type CssProp = any[];
1198
+
1199
+ // Augment React types so JSX elements accept the \`css\` prop
1200
+ declare module "react" {
1201
+ interface HTMLAttributes<T> {
1202
+ css?: CssProp;
1203
+ }
1204
+ interface SVGAttributes<T> {
1205
+ css?: CssProp;
1206
+ }
1207
+ }
1208
+
1209
+ type Opts<T> = {
1210
+ rules: T;
1211
+ enabled: boolean;
1212
+ selector: string | undefined;
1213
+ };
1214
+
1215
+ class CssBuilder<T extends Properties> {
1216
+ constructor(private opts: Opts<T>) {}
1217
+
1218
+ ${lines.join("\n ").replace(/ +\n/g, "\n")}
1219
+
1220
+ get $(): CssProp {
1221
+ return this.rules as any;
1222
+ }
1223
+
1224
+ get onHover() {
1225
+ return this.newCss({ selector: ":hover" });
1226
+ }
1227
+ get onFocus() {
1228
+ return this.newCss({ selector: ":focus" });
1229
+ }
1230
+ get onFocusVisible() {
1231
+ return this.newCss({ selector: ":focus-visible" });
1232
+ }
1233
+ get onActive() {
1234
+ return this.newCss({ selector: ":active" });
1235
+ }
1236
+ get onDisabled() {
1237
+ return this.newCss({ selector: ":disabled" });
1238
+ }
1239
+
1240
+ /** Marks this element as a default hover marker (for ancestor pseudo selectors). */
1241
+ get marker(): CssBuilder<T> {
1242
+ return this;
1243
+ }
1244
+
1245
+ /** Marks this element with a user-defined marker (return value of stylex.defineMarker()). */
1246
+ markerOf(_marker: Marker): CssBuilder<T> {
1247
+ return this;
1248
+ }
1249
+
1250
+ /**
1251
+ * Styles after this \`when\` are applied based on a relationship + pseudo selector.
1252
+ *
1253
+ * \`when("ancestor", ":hover")\` — react to ancestor hover
1254
+ * \`when("descendant", ":focus")\` — react to descendant focus
1255
+ * \`when("siblingAfter", ":hover")\` — react to a following sibling's hover
1256
+ */
1257
+ when(relationship: "ancestor" | "descendant" | "anySibling" | "siblingBefore" | "siblingAfter", pseudo: string): CssBuilder<T>;
1258
+ /**
1259
+ * Styles after this \`when\` are applied based on a relationship-to-marker + pseudo selector.
1260
+ *
1261
+ * \`when("ancestor", marker, ":hover")\` — react to a specific ancestor's hover
1262
+ */
1263
+ when(relationship: "ancestor" | "descendant" | "anySibling" | "siblingBefore" | "siblingAfter", marker: Marker, pseudo: string): CssBuilder<T>;
1264
+ when(_relationship: string, _pseudoOrMarker: string | Marker, _pseudo?: string): CssBuilder<T> {
1265
+ return this;
1266
+ }
1267
+
1268
+ ifContainer(_props: { name?: string; lt?: number; gt?: number }) {
1269
+ return this;
1270
+ }
1271
+
1272
+ /** Apply styles within a pseudo-element (e.g. \`"::placeholder"\`, \`"::selection"\`). */
1273
+ element(_pseudoElement: string): CssBuilder<T> {
1274
+ return this;
1275
+ }
1276
+
1277
+ ${breakpointIfs}
1278
+
1279
+ /** Conditionally apply styles when \`cond\` is true. */
1280
+ if(cond: boolean): CssBuilder<T>;
1281
+ /** Apply styles within a media query (e.g. \`Breakpoints.sm\` or a raw \`@media\` string). */
1282
+ if(mediaQuery: string): CssBuilder<T>;
1283
+ if(condOrMediaQuery: boolean | string): CssBuilder<T> {
1284
+ if (typeof condOrMediaQuery === "boolean") {
1285
+ return new CssBuilder({ ...this.opts, enabled: condOrMediaQuery });
1286
+ }
1287
+ return this.newCss({ selector: condOrMediaQuery });
1288
+ }
1289
+
1290
+ get else(): CssBuilder<T> {
1291
+ return new CssBuilder({ ...this.opts, enabled: !this.enabled });
1292
+ }
1293
+
1294
+ add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }> {
1295
+ if (!this.enabled) return this;
1296
+ const newRules = { [prop]: value };
1297
+ const rules = this.selector
1298
+ ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }
1299
+ : { ...this.rules, ...newRules };
1300
+ return this.newCss({ rules });
1301
+ }
1302
+
1303
+ private get rules(): T {
1304
+ return this.opts.rules;
1305
+ }
1306
+ private get enabled(): boolean {
1307
+ return this.opts.enabled;
1308
+ }
1309
+ private get selector(): string | undefined {
1310
+ return this.opts.selector;
1311
+ }
1312
+ private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {
1313
+ return new CssBuilder({ ...this.opts, ...opts });
1314
+ }
1315
+ }
1316
+
1317
+ /** Converts \`inc\` into pixels value with a \`px\` suffix. */
1318
+ export function maybeInc(inc: number | string): string {
1319
+ return typeof inc === "string" ? inc : \`\${inc * ${increment}}px\`;
1320
+ }
1321
+
1322
+ export enum Palette {
1323
+ ${Object.entries(palette).map(([name, value]) => {
1324
+ return `${name} = "${value}",`;
1325
+ })}
1326
+ }
1327
+
1328
+ /** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */
1329
+ export const Css = new CssBuilder({ rules: {}, enabled: true, selector: undefined });
1330
+
1331
+ ${breakpointCode}
1332
+
1333
+ ${extras || ""}
1334
+ `;
1335
+ }
1336
+ function generateTrussMapping(config, entries) {
1337
+ const { breakpoints = {} } = config;
1338
+ const abbreviations = {};
1339
+ for (const entry of entries) {
1340
+ switch (entry.kind) {
1341
+ case "static":
1342
+ case "cssvar":
1343
+ abbreviations[entry.abbr] = { kind: "static", defs: entry.defs || {} };
1344
+ break;
1345
+ case "param":
1346
+ abbreviations[entry.abbr] = {
1347
+ kind: "dynamic",
1348
+ props: entry.props || [],
1349
+ incremented: false,
1350
+ extraDefs: entry.extraDefs
1351
+ };
1352
+ break;
1353
+ case "increment-param":
1354
+ abbreviations[entry.abbr] = {
1355
+ kind: "dynamic",
1356
+ props: entry.props || [],
1357
+ incremented: true,
1358
+ extraDefs: entry.extraDefs
1359
+ };
1360
+ break;
1361
+ case "px-delegate":
1362
+ abbreviations[entry.abbr] = {
1363
+ kind: "delegate",
1364
+ target: entry.abbr.replace(/Px$/, "")
1365
+ };
1366
+ break;
1367
+ case "alias":
1368
+ abbreviations[entry.abbr] = {
1369
+ kind: "alias",
1370
+ chain: entry.aliasTargets || []
1371
+ };
1372
+ break;
1373
+ }
1374
+ }
1375
+ const genBreakpointsMap = makeBreakpoints(breakpoints);
1376
+ const breakpointEntries = {};
1377
+ for (const [name, mediaQuery] of Object.entries(genBreakpointsMap)) {
1378
+ breakpointEntries[`if${pascalCase(name)}`] = mediaQuery;
1379
+ }
1380
+ return {
1381
+ increment: config.increment,
1382
+ ...Object.keys(breakpointEntries).length > 0 ? { breakpoints: breakpointEntries } : {},
1383
+ abbreviations
1384
+ };
1385
+ }
1386
+ function condensedJson(mapping) {
1387
+ const lines = [];
1388
+ lines.push("{");
1389
+ lines.push(` "increment": ${mapping.increment},`);
1390
+ if (mapping.breakpoints && Object.keys(mapping.breakpoints).length > 0) {
1391
+ lines.push(` "breakpoints": ${JSON.stringify(mapping.breakpoints)},`);
1392
+ }
1393
+ lines.push(` "abbreviations": {`);
1394
+ const entries = Object.entries(mapping.abbreviations);
1395
+ for (let i = 0; i < entries.length; i++) {
1396
+ const [key, value] = entries[i];
1397
+ const comma = i < entries.length - 1 ? "," : "";
1398
+ lines.push(` ${JSON.stringify(key)}: ${JSON.stringify(value)}${comma}`);
1399
+ }
1400
+ lines.push(" }");
1401
+ lines.push("}");
1402
+ return lines.join("\n");
1403
+ }
1404
+ export {
1405
+ defaultSections,
1406
+ defineConfig,
1407
+ generate,
1408
+ newAliasesMethods,
1409
+ newCoreIncrementMethods,
1410
+ newIncrementMethods,
1411
+ newMethod,
1412
+ newMethodsForProp,
1413
+ newParamMethod,
1414
+ newPxMethod,
1415
+ newSetCssVariablesMethod,
1416
+ startStylexCollection,
1417
+ stopStylexCollection
1418
+ };
32
1419
  //# sourceMappingURL=index.js.map