@homebound/truss 1.137.5 → 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.d.ts CHANGED
@@ -1,5 +1,264 @@
1
- export * from "./config";
2
- export { defaultSections } from "./sections/tachyons";
3
- export { generate } from "./generate";
4
- export type { IncConfig } from "./methods";
5
- export { newAliasesMethods, newMethod, newPxMethod, newMethodsForProp, newCoreIncrementMethods, newIncrementMethods, newParamMethod, newSetCssVariablesMethod, } from "./methods";
1
+ import { Properties } from 'csstype';
2
+ import { Code } from 'ts-poet';
3
+
4
+ /**
5
+ * A map from human name to font size, i.e. `f12` -> `12px`.
6
+ *
7
+ * Or a set of properties, i.e. `f12` -> `{ fontFamily: ..., fontWeight: ... }`.
8
+ */
9
+ type FontConfig = Record<string, string | Properties>;
10
+ /**
11
+ * Provides users with an easy way to configure the major/most-often configurable
12
+ * aspect of a design system, i.e. the palette, fonts, and increments.
13
+ *
14
+ * Truss's built-in rules, i.e. `typeScale.ts` for fonts, `skins.ts` for colors,
15
+ * will read these values to determine their output.
16
+ *
17
+ * Note that users can always override whole sections of Truss's default set
18
+ * of rules by setting `methods["typeScale"] = {}`, see the readme for more
19
+ * information.
20
+ */
21
+ interface Config {
22
+ /** The output path of the `Css.ts` file. */
23
+ outputPath: string;
24
+ /**
25
+ * A map from the human/design system name to color value, i.e. `black` -> `#000000`.
26
+ *
27
+ * Design systems can use either physical names, i.e. `Sky50 -> #...`, or logical
28
+ * names, i.e. `Primary -> #...`, where the logical names are more themeable, but
29
+ * that's up to each design system to decide.
30
+ */
31
+ palette: Record<string, string>;
32
+ /**
33
+ * A map from human name to font size, i.e. `f12` -> `12px`.
34
+ *
35
+ * Or a set of properties, i.e. `f12` -> `{ fontFamily: ..., fontWeight: ... }`.
36
+ */
37
+ fonts: FontConfig;
38
+ /** The design system's increment in pixels. */
39
+ increment: number;
40
+ /** The number of increments to generate for rules like `mt1`, `mt2`, etc. */
41
+ numberOfIncrements: number;
42
+ /** Short-hand aliases like `bodyText` --> `["f12", "black"]`. */
43
+ aliases?: Aliases;
44
+ /** Type aliases for Only clauses, i.e. `Margin` --> `["marginTop", ...]`. `Margin` and `Padding` are provided. */
45
+ typeAliases?: Record<string, Array<keyof Properties>>;
46
+ /** Breakpoints, i.e. `{ sm: 0, md: 500 }`. */
47
+ breakpoints?: Record<string, number>;
48
+ /**
49
+ * Which default methods to include.
50
+ *
51
+ * Currently, we support either `tachyons`, `tachyons-rn`, or `none`.
52
+ * Could eventually support `tailwinds` / `tailwinds-rn` as additional options.
53
+ */
54
+ defaultMethods?: "tachyons" | "none" | "tachyons-rn";
55
+ /**
56
+ * The target CSS runtime to generate for.
57
+ *
58
+ * - `"stylex"` (default): Generates a StyleX-friendly CssBuilder (for IDE autocomplete + types) plus a
59
+ * `Css.json` mapping file consumed by the truss Vite plugin, which transforms
60
+ * `Css.*.$` expressions into file-local `stylex.create()` + `stylex.props()` calls at build time.
61
+ * - `"react-native"`: Generates a runtime CssBuilder that accumulates plain style objects,
62
+ * intended for React Native usage.
63
+ */
64
+ target?: "react-native" | "stylex";
65
+ /**
66
+ * The output path for the truss mapping file (only used when target is "stylex").
67
+ * Defaults to a `.json` sibling of `outputPath` (e.g. `./src/Css.json`).
68
+ */
69
+ mappingOutputPath?: string;
70
+ /**
71
+ * A map of "section" to list of rules to create application-specific
72
+ * utility methods.
73
+ *
74
+ * I.e. "borderColors" -> () => [`get ml1() { ... }`].
75
+ *
76
+ * This can be used to either add new sections or override built-in sections.
77
+ */
78
+ sections?: Sections;
79
+ /** Any extra chunks of code you want appended to the end of the file. */
80
+ extras?: Array<string | Code>;
81
+ }
82
+ /**
83
+ * A helper method to define config w/o a trailing cast.
84
+ *
85
+ * Based on `vite.config.ts`'s approach.
86
+ *
87
+ * We could eventually use this as a place to apply defaults, but currently
88
+ * just return the passed in `config` object as-is.
89
+ */
90
+ declare function defineConfig(config: Config): Config;
91
+ /**
92
+ * A function takes the project's `Config` and produces a list of utility methods to
93
+ * add to the generated `Css.ts` file.
94
+ *
95
+ * I.e. a return value might be:
96
+ *
97
+ * ```
98
+ * [
99
+ * "get mb0() { return this.mb(0); }",
100
+ * "get mb1() { return this.mb(1); }",
101
+ * ]
102
+ * ```
103
+ *
104
+ * See the `newMethod` and `newParamMethod` functions for more easily
105
+ * creating the `get ...() { ... }` output.
106
+ */
107
+ type CreateMethodsFn = (config: Config) => UtilityMethod[];
108
+ /**
109
+ * A type-alias to clarify strings that are meant to be abbreviation/utility names.
110
+ */
111
+ type UtilityName = string;
112
+ /**
113
+ * A type-alias to clarify which method returns types are utility methods.
114
+ *
115
+ * I.e. they should be a line of TypeScript code like `get abbr() { ... }`.
116
+ *
117
+ * See `newMethod` for a helper method to create the string.
118
+ */
119
+ type UtilityMethod = string;
120
+ /** A type-alias to clarify groups of utility methods. */
121
+ type SectionName = string;
122
+ /** A type-alias for a group of utility methods. */
123
+ type Sections = Record<SectionName, CreateMethodsFn>;
124
+ /** A type-alias for aliasing existing utility methods as a new utility method. */
125
+ type Aliases = Record<UtilityName, UtilityName[]>;
126
+
127
+ declare const defaultSections: {
128
+ readonly border: CreateMethodsFn;
129
+ readonly borderColor: CreateMethodsFn;
130
+ readonly borderRadius: CreateMethodsFn;
131
+ readonly borderStyle: CreateMethodsFn;
132
+ readonly borderWidth: CreateMethodsFn;
133
+ readonly boxShadow: CreateMethodsFn;
134
+ readonly container: CreateMethodsFn;
135
+ readonly coordinates: CreateMethodsFn;
136
+ readonly cursor: CreateMethodsFn;
137
+ readonly display: CreateMethodsFn;
138
+ readonly flexbox: CreateMethodsFn;
139
+ readonly float: CreateMethodsFn;
140
+ readonly fontWeight: CreateMethodsFn;
141
+ readonly grid: CreateMethodsFn;
142
+ readonly height: CreateMethodsFn;
143
+ readonly lineClamp: CreateMethodsFn;
144
+ readonly objectFit: CreateMethodsFn;
145
+ readonly opacity: CreateMethodsFn;
146
+ readonly outline: CreateMethodsFn;
147
+ readonly overflow: CreateMethodsFn;
148
+ readonly position: CreateMethodsFn;
149
+ readonly skins: CreateMethodsFn;
150
+ readonly spacing: CreateMethodsFn;
151
+ readonly textAlign: CreateMethodsFn;
152
+ readonly textDecoration: CreateMethodsFn;
153
+ readonly textTransform: CreateMethodsFn;
154
+ readonly typeScale: CreateMethodsFn;
155
+ readonly typography: CreateMethodsFn;
156
+ readonly userSelect: CreateMethodsFn;
157
+ readonly verticalAlign: CreateMethodsFn;
158
+ readonly visibility: CreateMethodsFn;
159
+ readonly whitespace: CreateMethodsFn;
160
+ readonly width: CreateMethodsFn;
161
+ readonly wordBreak: CreateMethodsFn;
162
+ readonly zIndex: CreateMethodsFn;
163
+ };
164
+
165
+ declare function generate(config: Config): Promise<void>;
166
+
167
+ type Prop = keyof Properties;
168
+ interface StylexEntry {
169
+ kind: "static" | "param" | "increment-param" | "px-delegate" | "alias" | "cssvar";
170
+ abbr: string;
171
+ /** For static: the CSS properties object, e.g. { display: "flex" } */
172
+ defs?: Record<string, unknown>;
173
+ /** For param/increment-param: the CSS property name(s) */
174
+ props?: string[];
175
+ /** For increment-param: whether to use maybeInc */
176
+ usesMaybeInc?: boolean;
177
+ /** For param methods: extra properties to set alongside the main prop */
178
+ extraDefs?: Record<string, unknown>;
179
+ /** For aliases: the list of chained abbreviations */
180
+ aliasTargets?: string[];
181
+ }
182
+ /** Start collecting StylexEntry metadata from method helpers. */
183
+ declare function startStylexCollection(): void;
184
+ /** Stop collecting and return all accumulated entries. */
185
+ declare function stopStylexCollection(): StylexEntry[];
186
+ /**
187
+ * Given a single abbreviation (i.e. `mt0`) and multiple `{ prop: value }` CSS values, returns
188
+ * the TypeScript code for a `mt0` utility method that sets those values.
189
+ */
190
+ declare function newMethod(abbr: UtilityName, defs: Properties): UtilityMethod;
191
+ /**
192
+ * Given a single abbreviation (i.e. `mt`) and a property name (i.e. `marginTop`), returns the
193
+ * TypeScript code for a `mt` utility method that accepts a user-provided value of the prop to set.
194
+ * Use `extraProperties` for additional properties to set.
195
+ *
196
+ * I.e. `Css.mt(someValue).$`
197
+ */
198
+ declare function newParamMethod(abbr: UtilityName, prop: keyof Properties, extraProperties?: Properties): UtilityMethod;
199
+ /**
200
+ * Given a prop to set (i.e. `marginTop`), and multiple abbr/value pairs (i.e. `{ mt0: "0px", mt1: "4px" }`),
201
+ * returns a utility method for each abbr/value pair.
202
+ *
203
+ * I.e. `mt0() { ...add("marginTop", "0px")... }`
204
+ *
205
+ * By default, we also generate a param method for `prop`, i.e. if `prop` is `marginTop`, we'll
206
+ * make a `marginTop(value)` method for users to pass variable values. You can change the
207
+ * name of this method by setting `baseName` or disable it completely by setting `baseName`
208
+ * to `null`.
209
+ *
210
+ * @param prop the CSS property we're setting, i.e. `marginTop`
211
+ * @param defs a map of abbreviation name --> value (a property value or an object of properties to set)
212
+ * @param baseName the base name to use, i.e. `mt`
213
+ * @param includePx generate an extra `${baseName}Px` method that calls the base method with a converted px value
214
+ * @param baseDefs additional properties to set for the base method
215
+ */
216
+ declare function newMethodsForProp<P extends Prop>(prop: P, defs: Record<UtilityName, Properties[P] | Properties>, baseName?: string | null, includePx?: boolean, valueMethodExtraProperties?: Omit<Properties, P>): UtilityMethod[];
217
+ /**
218
+ * Given aliases, i.e. `{ bodyText: ["f12", "bold"] }`, returns a utility method
219
+ * for each alias that calls its corresponding utility classes.
220
+ */
221
+ declare function newAliasesMethods(aliases: Aliases): UtilityMethod[];
222
+ /**
223
+ * Makes a utility method that can set CSS custom variables.
224
+ *
225
+ * I.e. `newSetCssVariableMethod("dark", { "--Primary": "white" })` will create a
226
+ * utility method `Css.dark.$ that will set `--Primary` to `white`.
227
+ *
228
+ * Currently, this only supports compile-time/hard-coded values. I.e. we don't support
229
+ * something like `Css.dark({ "--Primary", someRuntimeValue }).$` yet.
230
+ *
231
+ * TODO: Create a `Css.set(cssVars).$` method.
232
+ */
233
+ declare function newSetCssVariablesMethod(abbr: UtilityName, defs: Record<string, string>): UtilityMethod;
234
+ /** An abbreviation and its single or multiple CSS properties to set. */
235
+ type IncConfig = [string, Prop | Prop[]];
236
+ /**
237
+ * Makes [`mt0`, `mt1`, ...] utility methods for each configured increment
238
+ * to set `prop` to that given increment's value in pixels.
239
+ *
240
+ * I.e. we assume `prop` is a CSS property like `margin` that accepts pixels as values,
241
+ * and so convert each increment `x` (1, 2, 3) to pixels `Y` (8, 16, 24) and create
242
+ * a utility method for each `x -> Y` pair, i.e. `mt0 = mt(px(0))`.
243
+ *
244
+ * We also create a final param method, i.e. `mt(number)`, for callers that
245
+ * need to call `mt` with a conditional amount of increments.
246
+ *
247
+ * @param config the config
248
+ * @param abbr the utility prefix, i.e. `mt`
249
+ * @param props if a CSS prop like `marginTop`, we output "mt0 --> marginTop: 0px", if an array like
250
+ * `["marginTop", "marginBottom"]`, we output "my0 --> marginTop: 0px, marginBottom: 0px"
251
+ * @param opts.auto if set to true, include an `a` suffix for auto values, i.e. `mta`
252
+ */
253
+ declare function newIncrementMethods(config: Config, abbr: UtilityName, prop: Prop | Prop[], opts?: {
254
+ auto?: boolean;
255
+ }): UtilityMethod[];
256
+ /**
257
+ * Creates just the core `<abbr>X` utility methods that set `props` with each increment value.
258
+ *
259
+ * See `newIncrementMethods` for handling the `<abbr>Px`, `<abbr>a`, and `<attr>(value)` methods.
260
+ */
261
+ declare function newCoreIncrementMethods(config: Config, abbr: UtilityName, props: Prop[]): UtilityMethod[];
262
+ declare function newPxMethod(abbr: UtilityName, prop: Prop): UtilityMethod;
263
+
264
+ export { type Aliases, type Config, type CreateMethodsFn, type FontConfig, type IncConfig, type SectionName, type Sections, type StylexEntry, type UtilityMethod, type UtilityName, defaultSections, defineConfig, generate, newAliasesMethods, newCoreIncrementMethods, newIncrementMethods, newMethod, newMethodsForProp, newParamMethod, newPxMethod, newSetCssVariablesMethod, startStylexCollection, stopStylexCollection };