@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/config.d.ts DELETED
@@ -1,109 +0,0 @@
1
- import { Properties } from "csstype";
2
- import { Code } from "ts-poet";
3
- /**
4
- * A map from human name to font size, i.e. `f12` -> `12px`.
5
- *
6
- * Or a set of properties, i.e. `f12` -> `{ fontFamily: ..., fontWeight: ... }`.
7
- */
8
- export type FontConfig = Record<string, string | Properties>;
9
- /**
10
- * Provides users with an easy way to configure the major/most-often configurable
11
- * aspect of a design system, i.e. the palette, fonts, and increments.
12
- *
13
- * Truss's built-in rules, i.e. `typeScale.ts` for fonts, `skins.ts` for colors,
14
- * will read these values to determine their output.
15
- *
16
- * Note that users can always override whole sections of Truss's default set
17
- * of rules by setting `methods["typeScale"] = {}`, see the readme for more
18
- * information.
19
- */
20
- export interface Config {
21
- /** The output path of the `Css.ts` file. */
22
- outputPath: string;
23
- /**
24
- * A map from the human/design system name to color value, i.e. `black` -> `#000000`.
25
- *
26
- * Design systems can use either physical names, i.e. `Sky50 -> #...`, or logical
27
- * names, i.e. `Primary -> #...`, where the logical names are more themeable, but
28
- * that's up to each design system to decide.
29
- */
30
- palette: Record<string, string>;
31
- /**
32
- * A map from human name to font size, i.e. `f12` -> `12px`.
33
- *
34
- * Or a set of properties, i.e. `f12` -> `{ fontFamily: ..., fontWeight: ... }`.
35
- */
36
- fonts: FontConfig;
37
- /** The design system's increment in pixels. */
38
- increment: number;
39
- /** The number of increments to generate for rules like `mt1`, `mt2`, etc. */
40
- numberOfIncrements: number;
41
- /** Short-hand aliases like `bodyText` --> `["f12", "black"]`. */
42
- aliases?: Aliases;
43
- /** Type aliases for Only clauses, i.e. `Margin` --> `["marginTop", ...]`. `Margin` and `Padding` are provided. */
44
- typeAliases?: Record<string, Array<keyof Properties>>;
45
- /** Breakpoints, i.e. `{ sm: 0, md: 500 }`. */
46
- breakpoints?: Record<string, number>;
47
- /**
48
- * Which default methods to include.
49
- *
50
- * Currently, we support either `tachyons`, `tachyons-rn`, or `none`.
51
- * Could eventually support `tailwinds` / `tailwinds-rn` as additional options.
52
- */
53
- defaultMethods?: "tachyons" | "none" | "tachyons-rn";
54
- /**
55
- * A map of "section" to list of rules to create application-specific
56
- * utility methods.
57
- *
58
- * I.e. "borderColors" -> () => [`get ml1() { ... }`].
59
- *
60
- * This can be used to either add new sections or override built-in sections.
61
- */
62
- sections?: Sections;
63
- /** Any extra chunks of code you want appended to the end of the file. */
64
- extras?: Array<string | Code>;
65
- }
66
- /**
67
- * A helper method to define config w/o a trailing cast.
68
- *
69
- * Based on `vite.config.ts`'s approach.
70
- *
71
- * We could eventually use this as a place to apply defaults, but currently
72
- * just return the passed in `config` object as-is.
73
- */
74
- export declare function defineConfig(config: Config): Config;
75
- /**
76
- * A function takes the project's `Config` and produces a list of utility methods to
77
- * add to the generated `Css.ts` file.
78
- *
79
- * I.e. a return value might be:
80
- *
81
- * ```
82
- * [
83
- * "get mb0() { return this.mb(0); }",
84
- * "get mb1() { return this.mb(1); }",
85
- * ]
86
- * ```
87
- *
88
- * See the `newMethod` and `newParamMethod` functions for more easily
89
- * creating the `get ...() { ... }` output.
90
- */
91
- export type CreateMethodsFn = (config: Config) => UtilityMethod[];
92
- /**
93
- * A type-alias to clarify strings that are meant to be abbreviation/utility names.
94
- */
95
- export type UtilityName = string;
96
- /**
97
- * A type-alias to clarify which method returns types are utility methods.
98
- *
99
- * I.e. they should be a line of TypeScript code like `get abbr() { ... }`.
100
- *
101
- * See `newMethod` for a helper method to create the string.
102
- */
103
- export type UtilityMethod = string;
104
- /** A type-alias to clarify groups of utility methods. */
105
- export type SectionName = string;
106
- /** A type-alias for a group of utility methods. */
107
- export type Sections = Record<SectionName, CreateMethodsFn>;
108
- /** A type-alias for aliasing existing utility methods as a new utility method. */
109
- export type Aliases = Record<UtilityName, UtilityName[]>;
package/build/config.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineConfig = defineConfig;
4
- /**
5
- * A helper method to define config w/o a trailing cast.
6
- *
7
- * Based on `vite.config.ts`'s approach.
8
- *
9
- * We could eventually use this as a place to apply defaults, but currently
10
- * just return the passed in `config` object as-is.
11
- */
12
- function defineConfig(config) {
13
- return config;
14
- }
15
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAsFA,oCAEC;AAVD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +0,0 @@
1
- import { Properties } from "csstype";
2
- import { Config } from "./config";
3
- export declare const defaultTypeAliases: Record<string, Array<keyof Properties>>;
4
- export declare function generate(config: Config): Promise<void>;
package/build/generate.js DELETED
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
- var __assign = (this && this.__assign) || function () {
7
- __assign = Object.assign || function(t) {
8
- for (var s, i = 1, n = arguments.length; i < n; i++) {
9
- s = arguments[i];
10
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
- t[p] = s[p];
12
- }
13
- return t;
14
- };
15
- return __assign.apply(this, arguments);
16
- };
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __read = (this && this.__read) || function (o, n) {
54
- var m = typeof Symbol === "function" && o[Symbol.iterator];
55
- if (!m) return o;
56
- var i = m.call(o), r, ar = [], e;
57
- try {
58
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
- }
60
- catch (error) { e = { error: error }; }
61
- finally {
62
- try {
63
- if (r && !r.done && (m = i["return"])) m.call(i);
64
- }
65
- finally { if (e) throw e.error; }
66
- }
67
- return ar;
68
- };
69
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
- if (ar || !(i in from)) {
72
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
- ar[i] = from[i];
74
- }
75
- }
76
- return to.concat(ar || Array.prototype.slice.call(from));
77
- };
78
- Object.defineProperty(exports, "__esModule", { value: true });
79
- exports.defaultTypeAliases = void 0;
80
- exports.generate = generate;
81
- var fs_1 = require("fs");
82
- var ts_poet_1 = require("ts-poet");
83
- var breakpoints_1 = require("./breakpoints");
84
- var methods_1 = require("./methods");
85
- var tachyons_1 = require("./sections/tachyons");
86
- var utils_1 = require("./utils");
87
- var change_case_1 = require("change-case");
88
- var tachyons_rn_1 = require("./sections/tachyons-rn");
89
- exports.defaultTypeAliases = {
90
- Margin: ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft"],
91
- Padding: ["padding", "paddingTop", "paddingRight", "paddingBottom", "paddingLeft"],
92
- };
93
- function generate(config) {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var outputPath, output;
96
- return __generator(this, function (_a) {
97
- switch (_a.label) {
98
- case 0:
99
- outputPath = config.outputPath;
100
- output = generateCssBuilder(config).toString();
101
- return [4 /*yield*/, fs_1.promises.writeFile(outputPath, output)];
102
- case 1:
103
- _a.sent();
104
- return [2 /*return*/];
105
- }
106
- });
107
- });
108
- }
109
- function generateCssBuilder(config) {
110
- var aliases = config.aliases, fonts = config.fonts, increment = config.increment, extras = config.extras, typeAliases = config.typeAliases, _a = config.breakpoints, breakpoints = _a === void 0 ? {} : _a, palette = config.palette, _b = config.defaultMethods, defaultMethods = _b === void 0 ? "tachyons" : _b, customSections = config.sections;
111
- // Combine our out-of-the-box utility methods with any custom ones
112
- var sections = __assign(__assign(__assign({}, (defaultMethods === "tachyons"
113
- ? generateMethods(config, tachyons_1.defaultSections)
114
- : defaultMethods === "tachyons-rn"
115
- ? generateMethods(config, tachyons_rn_1.reactNativeSections)
116
- : {})), (customSections ? generateMethods(config, customSections) : {})), (aliases && { aliases: (0, methods_1.newAliasesMethods)(aliases) }));
117
- var Properties = (0, ts_poet_1.imp)("Properties@csstype");
118
- var lines = Object.entries(sections)
119
- .map(function (_a) {
120
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
121
- return __spreadArray(__spreadArray(["// ".concat(name)], __read(value), false), [""], false);
122
- })
123
- .flat();
124
- var typeAliasCode = Object.entries(__assign(__assign({}, exports.defaultTypeAliases), typeAliases)).map(function (_a) {
125
- var _b = __read(_a, 2), name = _b[0], props = _b[1];
126
- return "export type ".concat(name, " = ").concat(props.map(utils_1.quote).join(" | "), ";\n\n");
127
- });
128
- var typographyType = (0, ts_poet_1.code)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n export type ", " = ", ";\n "], ["\n export type ", " = ", ";\n "])), (0, ts_poet_1.def)("Typography"), Object.keys(fonts).map(utils_1.quote).join(" | "));
129
- var genBreakpoints = (0, breakpoints_1.makeBreakpoints)(breakpoints);
130
- var breakpointCode = [
131
- "export type Breakpoint = ".concat(Object.keys(genBreakpoints).map(utils_1.quote).join(" | "), ";"),
132
- "export enum Breakpoints {\n ".concat(Object.entries(genBreakpoints).map(function (_a) {
133
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
134
- return "".concat(name, " = \"").concat(value, "\"");
135
- }), "\n };"),
136
- ];
137
- var breakpointIfs = Object.entries(genBreakpoints).map(function (_a) {
138
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
139
- return (0, ts_poet_1.code)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n get if", "() {\n return this.newCss({ selector: ", " });\n }"], ["\n get if", "() {\n return this.newCss({ selector: ", " });\n }"])), (0, change_case_1.pascalCase)(name), (0, utils_1.quote)(value));
140
- });
141
- var containerQueriesCode = (0, ts_poet_1.code)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n /**\n * Utility to help write `@container` queries\n *\n * @param name - The name of the container.\n * @param lt - The maximum width of the container inclusive.\n * @param gt - The minimum width of the container exclusive.\n */\n type ContainerProps = { name?: string } & ({ lt: number } | { gt: number } | { lt: number; gt: number });\n export function Container(props: ContainerProps) {\n const { name = \"\" } = props;\n const lt = \"lt\" in props ? props.lt : undefined;\n const gt = \"gt\" in props ? props.gt : undefined;\n\n const ltQuery = lt !== undefined ? `(max-width: ${lt}px)` : \"\";\n const gtQuery = gt !== undefined ? `(min-width: ${gt + 1}px)` : \"\";\n const query = [ltQuery, gtQuery].filter(Boolean).join(\" and \");\n\n return `@container ${name} ${query}`;\n }"], ["\n /**\n * Utility to help write \\`@container\\` queries\n *\n * @param name - The name of the container.\n * @param lt - The maximum width of the container inclusive.\n * @param gt - The minimum width of the container exclusive.\n */\n type ContainerProps = { name?: string } & ({ lt: number } | { gt: number } | { lt: number; gt: number });\n export function Container(props: ContainerProps) {\n const { name = \"\" } = props;\n const lt = \"lt\" in props ? props.lt : undefined;\n const gt = \"gt\" in props ? props.gt : undefined;\n\n const ltQuery = lt !== undefined ? \\`(max-width: \\${lt}px)\\` : \"\";\n const gtQuery = gt !== undefined ? \\`(min-width: \\${gt + 1}px)\\` : \"\";\n const query = [ltQuery, gtQuery].filter(Boolean).join(\" and \");\n\n return \\`@container \\${name} \\${query}\\`;\n }"])));
142
- return (0, ts_poet_1.code)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n// This file is auto-generated by truss: https://github.com/homebound-team/truss.\n// See your project's `truss-config.ts` to make configuration changes (fonts, increments, etc).\n\n/** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */\nexport type Only<X, T> = X & Record<Exclude<keyof T, keyof X>, never>;\n\nexport type ", " = ", "<string | 0, string>;\n\n", "\n\ntype Opts<T> = {\n rules: T,\n enabled: boolean,\n important: boolean,\n selector: string | undefined\n};\n\nclass CssBuilder<T extends Properties> {\n constructor(private opts: Opts<T>) {}\n\n private get rules(): T { return this.opts.rules };\n private get enabled(): boolean { return this.opts.enabled };\n private get selector(): string | undefined { return this.opts.selector };\n private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {\n return new CssBuilder({ ...this.opts, ...opts });\n }\n\n ", "\n \n get $(): T { return maybeImportant(sortObject(this.rules), this.opts.important); }\n\n if(bp: Breakpoint): CssBuilder<T>;\n if(cond: boolean): CssBuilder<T>;\n if(attr: string, value: boolean | string): CssBuilder<T>;\n if(arg: boolean | Breakpoint | string, value?: boolean | string): CssBuilder<T> {\n if (value !== undefined) {\n return this.newCss({ selector: `[${arg}='${value}']` });\n } else if (typeof arg === \"boolean\") {\n return this.newCss({ enabled: arg });\n } else {\n return this.newCss({ selector: Breakpoints[arg as Breakpoint] });\n }\n }\n\n get onHover() {\n return this.newCss({ selector: \":hover\" });\n }\n \n ifContainer(props: ContainerProps) {\n return this.newCss({ selector: Container(props) });\n }\n \n ", "\n\n get else() {\n if (this.selector !== undefined) {\n if (this.selector.includes(\"not\")) {\n throw new Error(\"else was already called\");\n } else {\n return this.newCss({ selector: this.selector.replace(\"@media\", \"@media not\") });\n }\n }\n return this.newCss({ enabled: !this.enabled });\n }\n\n get important() { return this.newCss({ important: true }); }\n\n /** Adds new properties, either a specific key/value or a Properties object, to the current css. */\n add<P extends Properties>(props: P): CssBuilder<T & P>;\n add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;\n add<K extends keyof Properties>(propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {\n if (!this.enabled) return this;\n const newRules = typeof propOrProperties === \"string\" ? { [propOrProperties]: value } : propOrProperties;\n const rules = this.selector\n ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }\n : { ...this.rules, ...newRules };\n return this.newCss({ rules: rules as any });\n }\n\n /** Adds new properties, either a specific key/value or a Properties object, to a nested selector. */\n addIn<P extends Properties>(selector: string, props: P | undefined): CssBuilder<T & P>;\n addIn<K extends keyof Properties>(selector: string, prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;\n addIn<K extends keyof Properties>(selector: string, propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {\n const newRules = typeof propOrProperties === \"string\" ? { [propOrProperties]: value } : propOrProperties;\n if (!this.enabled) return this;\n if (newRules === undefined) {\n return this;\n }\n const rules = { ...this.rules, [selector]: { ...(this.rules as any)[selector], ...newRules } };\n return this.newCss({ rules: rules as any });\n }\n}\n\n/** Emotion treats the same rules, ordered differently as different classes, but naively they can be the same. */\nfunction sortObject<T extends object>(obj: T): T {\n return Object.keys(obj)\n .sort()\n .reduce((acc, key) => {\n acc[key as keyof T] = obj[key as keyof T];\n return acc;\n }, ({} as any) as T) as T;\n}\n\n/** Conditionally adds `important!` to everything. */\nfunction maybeImportant<T extends object>(obj: T, important: boolean): T {\n if (important) {\n Object.keys(obj).forEach(key => {\n (obj as any)[key] = `${(obj as any)[key]} !important`;\n });\n }\n return obj;\n}\n\n/** Converts `inc` into pixels value with a `px` suffix. */\nexport function maybeInc(inc: number | string): string {\n return typeof inc === \"string\" ? inc : `${increment(inc)}px`;\n}\n\n/** Converts `inc` into pixels. */\nexport function increment(inc: number): number {\n return inc * ", ";\n}\n\n/** Convert `pixels` to a `px` units string so it's not ambiguous. */\nexport function px(pixels: number): string {\n return `${pixels}px`;\n}\n\nexport enum Palette {\n ", "\n}\n\n/** A shortcut for defining Xss types. */\nexport type Xss<P extends keyof Properties> = Pick<Properties, P>;\n\n/** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */\nexport const Css = new CssBuilder({ rules: {}, enabled: true, important: false, selector: undefined });\n\n", "\n\n", "\n\n", "\n\n", "\n "], ["\n// This file is auto-generated by truss: https://github.com/homebound-team/truss.\n// See your project's \\`truss-config.ts\\` to make configuration changes (fonts, increments, etc).\n\n/** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */\nexport type Only<X, T> = X & Record<Exclude<keyof T, keyof X>, never>;\n\nexport type ", " = ", "<string | 0, string>;\n\n", "\n\ntype Opts<T> = {\n rules: T,\n enabled: boolean,\n important: boolean,\n selector: string | undefined\n};\n\nclass CssBuilder<T extends Properties> {\n constructor(private opts: Opts<T>) {}\n\n private get rules(): T { return this.opts.rules };\n private get enabled(): boolean { return this.opts.enabled };\n private get selector(): string | undefined { return this.opts.selector };\n private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {\n return new CssBuilder({ ...this.opts, ...opts });\n }\n\n ", "\n \n get $(): T { return maybeImportant(sortObject(this.rules), this.opts.important); }\n\n if(bp: Breakpoint): CssBuilder<T>;\n if(cond: boolean): CssBuilder<T>;\n if(attr: string, value: boolean | string): CssBuilder<T>;\n if(arg: boolean | Breakpoint | string, value?: boolean | string): CssBuilder<T> {\n if (value !== undefined) {\n return this.newCss({ selector: \\`[\\${arg}='\\${value}']\\` });\n } else if (typeof arg === \"boolean\") {\n return this.newCss({ enabled: arg });\n } else {\n return this.newCss({ selector: Breakpoints[arg as Breakpoint] });\n }\n }\n\n get onHover() {\n return this.newCss({ selector: \":hover\" });\n }\n \n ifContainer(props: ContainerProps) {\n return this.newCss({ selector: Container(props) });\n }\n \n ", "\n\n get else() {\n if (this.selector !== undefined) {\n if (this.selector.includes(\"not\")) {\n throw new Error(\"else was already called\");\n } else {\n return this.newCss({ selector: this.selector.replace(\"@media\", \"@media not\") });\n }\n }\n return this.newCss({ enabled: !this.enabled });\n }\n\n get important() { return this.newCss({ important: true }); }\n\n /** Adds new properties, either a specific key/value or a Properties object, to the current css. */\n add<P extends Properties>(props: P): CssBuilder<T & P>;\n add<K extends keyof Properties>(prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;\n add<K extends keyof Properties>(propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {\n if (!this.enabled) return this;\n const newRules = typeof propOrProperties === \"string\" ? { [propOrProperties]: value } : propOrProperties;\n const rules = this.selector\n ? { ...this.rules, [this.selector]: { ...(this.rules as any)[this.selector], ...newRules } }\n : { ...this.rules, ...newRules };\n return this.newCss({ rules: rules as any });\n }\n\n /** Adds new properties, either a specific key/value or a Properties object, to a nested selector. */\n addIn<P extends Properties>(selector: string, props: P | undefined): CssBuilder<T & P>;\n addIn<K extends keyof Properties>(selector: string, prop: K, value: Properties[K]): CssBuilder<T & { [U in K]: Properties[K] }>;\n addIn<K extends keyof Properties>(selector: string, propOrProperties: K | Properties, value?: Properties[K]): CssBuilder<any> {\n const newRules = typeof propOrProperties === \"string\" ? { [propOrProperties]: value } : propOrProperties;\n if (!this.enabled) return this;\n if (newRules === undefined) {\n return this;\n }\n const rules = { ...this.rules, [selector]: { ...(this.rules as any)[selector], ...newRules } };\n return this.newCss({ rules: rules as any });\n }\n}\n\n/** Emotion treats the same rules, ordered differently as different classes, but naively they can be the same. */\nfunction sortObject<T extends object>(obj: T): T {\n return Object.keys(obj)\n .sort()\n .reduce((acc, key) => {\n acc[key as keyof T] = obj[key as keyof T];\n return acc;\n }, ({} as any) as T) as T;\n}\n\n/** Conditionally adds \\`important!\\` to everything. */\nfunction maybeImportant<T extends object>(obj: T, important: boolean): T {\n if (important) {\n Object.keys(obj).forEach(key => {\n (obj as any)[key] = \\`\\${(obj as any)[key]} !important\\`;\n });\n }\n return obj;\n}\n\n/** Converts \\`inc\\` into pixels value with a \\`px\\` suffix. */\nexport function maybeInc(inc: number | string): string {\n return typeof inc === \"string\" ? inc : \\`\\${increment(inc)}px\\`;\n}\n\n/** Converts \\`inc\\` into pixels. */\nexport function increment(inc: number): number {\n return inc * ", ";\n}\n\n/** Convert \\`pixels\\` to a \\`px\\` units string so it's not ambiguous. */\nexport function px(pixels: number): string {\n return \\`\\${pixels}px\\`;\n}\n\nexport enum Palette {\n ", "\n}\n\n/** A shortcut for defining Xss types. */\nexport type Xss<P extends keyof Properties> = Pick<Properties, P>;\n\n/** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */\nexport const Css = new CssBuilder({ rules: {}, enabled: true, important: false, selector: undefined });\n\n", "\n\n", "\n\n", "\n\n", "\n "])), (0, ts_poet_1.def)("Properties"), Properties, typographyType, lines.join("\n ").replace(/ +\n/g, "\n"), breakpointIfs, increment, Object.entries(palette).map(function (_a) {
143
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
144
- return "".concat(name, " = \"").concat(value, "\",");
145
- }), typeAliasCode, breakpointCode, containerQueriesCode, extras || "");
146
- }
147
- /** Invokes all of the `MethodFns` to create actual `UtilityMethod`s. */
148
- function generateMethods(config, methodFns) {
149
- return Object.fromEntries(Object.entries(methodFns).map(function (_a) {
150
- var _b = __read(_a, 2), name = _b[0], fn = _b[1];
151
- return [name, fn(config)];
152
- }));
153
- }
154
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
155
- //# sourceMappingURL=generate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,4BAIC;AAnBD,yBAAoC;AACpC,mCAA+C;AAC/C,6CAAkD;AAElD,qCAAgD;AAChD,gDAAwD;AACxD,iCAAkC;AAClC,2CAAyC;AACzC,sDAA+D;AAElD,QAAA,kBAAkB,GAA4C;IACzE,MAAM,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,CAAC;IAC5E,OAAO,EAAE,CAAC,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,CAAC;CACnF,CAAC;AAEF,SAAsB,QAAQ,CAAC,MAAc;;;;;;oBACnC,UAAU,GAAK,MAAM,WAAX,CAAY;oBACxB,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;oBACrD,qBAAM,aAAE,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;;;;;CACxC;AAED,SAAS,kBAAkB,CAAC,MAAc;IAEtC,IAAA,OAAO,GASL,MAAM,QATD,EACP,KAAK,GAQH,MAAM,MARH,EACL,SAAS,GAOP,MAAM,UAPC,EACT,MAAM,GAMJ,MAAM,OANF,EACN,WAAW,GAKT,MAAM,YALG,EACX,KAIE,MAAM,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AE7C,cAAc,EAmBZ,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAyBzC,aAAa,EAoEA,SAAS,EAStB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,UAAC,EAAa;YAAb,KAAA,aAAa,EAAZ,IAAI,QAAA,EAAE,KAAK,QAAA;QACzC,OAAO,UAAG,IAAI,kBAAO,KAAK,QAAI,CAAC;IACjC,CAAC,CAAC,EASF,aAAa,EAEb,cAAc,EAEd,oBAAoB,EAEpB,MAAM,IAAI,EAAE,EACV;AACJ,CAAC;AAED,wEAAwE;AACxE,SAAS,eAAe,CAAC,MAAc,EAAE,SAAmB;IAC1D,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,UAAC,EAAU;YAAV,KAAA,aAAU,EAAT,IAAI,QAAA,EAAE,EAAE,QAAA;QAAM,OAAA,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAAlB,CAAkB,CAAC,CAAC,CAAC;AAC/F,CAAC"}
@@ -1,82 +0,0 @@
1
- import { Aliases, Config, UtilityMethod, UtilityName } from "./config";
2
- import { Properties } from "csstype";
3
- export type Prop = keyof Properties;
4
- /**
5
- * Given a single abbreviation (i.e. `mt0`) and multiple `{ prop: value }` CSS values, returns
6
- * the TypeScript code for a `mt0` utility method that sets those values.
7
- */
8
- export declare function newMethod(abbr: UtilityName, defs: Properties): UtilityMethod;
9
- /**
10
- * Given a single abbreviation (i.e. `mt`) and a property name (i.e. `marginTop`), returns the
11
- * TypeScript code for a `mt` utility method that accepts a user-provided value of the prop to set.
12
- * Use `extraProperties` for additional properties to set.
13
- *
14
- * I.e. `Css.mt(someValue).$`
15
- */
16
- export declare function newParamMethod(abbr: UtilityName, prop: keyof Properties, extraProperties?: Properties): UtilityMethod;
17
- /**
18
- * Given a prop to set (i.e. `marginTop`), and multiple abbr/value pairs (i.e. `{ mt0: "0px", mt1: "4px" }`),
19
- * returns a utility method for each abbr/value pair.
20
- *
21
- * I.e. `mt0() { ...add("marginTop", "0px")... }`
22
- *
23
- * By default, we also generate a param method for `prop`, i.e. if `prop` is `marginTop`, we'll
24
- * make a `marginTop(value)` method for users to pass variable values. You can change the
25
- * name of this method by setting `baseName` or disable it completely by setting `baseName`
26
- * to `null`.
27
- *
28
- * @param prop the CSS property we're setting, i.e. `marginTop`
29
- * @param defs a map of abbreviation name --> value (a property value or an object of properties to set)
30
- * @param baseName the base name to use, i.e. `mt`
31
- * @param includePx generate an extra `${baseName}Px` method that calls the base method with a converted px value
32
- * @param baseDefs additional properties to set for the base method
33
- */
34
- export declare function newMethodsForProp<P extends Prop>(prop: P, defs: Record<UtilityName, Properties[P] | Properties>, baseName?: string | null, includePx?: boolean, valueMethodExtraProperties?: Omit<Properties, P>): UtilityMethod[];
35
- /**
36
- * Given aliases, i.e. `{ bodyText: ["f12", "bold"] }`, returns a utility method
37
- * for each alias that calls its corresponding utility classes.
38
- */
39
- export declare function newAliasesMethods(aliases: Aliases): UtilityMethod[];
40
- /**
41
- * Makes a utility method that can set CSS custom variables.
42
- *
43
- * I.e. `newSetCssVariableMethod("dark", { "--Primary": "white" })` will create a
44
- * utility method `Css.dark.$ that will set `--Primary` to `white`.
45
- *
46
- * Currently, this only supports compile-time/hard-coded values. I.e. we don't support
47
- * something like `Css.dark({ "--Primary", someRuntimeValue }).$` yet.
48
- *
49
- * TODO: Create a `Css.set(cssVars).$` method.
50
- */
51
- export declare function newSetCssVariablesMethod(abbr: UtilityName, defs: Record<string, string>): UtilityMethod;
52
- /** An abbreviation and its single or multiple CSS properties to set. */
53
- export type IncConfig = [string, Prop | Prop[]];
54
- /**
55
- * Makes [`mt0`, `mt1`, ...] utility methods for each configured increment
56
- * to set `prop` to that given increment's value in pixels.
57
- *
58
- * I.e. we assume `prop` is a CSS property like `margin` that accepts pixels as values,
59
- * and so convert each increment `x` (1, 2, 3) to pixels `Y` (8, 16, 24) and create
60
- * a utility method for each `x -> Y` pair, i.e. `mt0 = mt(px(0))`.
61
- *
62
- * We also create a final param method, i.e. `mt(number)`, for callers that
63
- * need to call `mt` with a conditional amount of increments.
64
- *
65
- * @param config the config
66
- * @param abbr the utility prefix, i.e. `mt`
67
- * @param props if a CSS prop like `marginTop`, we output "mt0 --> marginTop: 0px", if an array like
68
- * `["marginTop", "marginBottom"]`, we output "my0 --> marginTop: 0px, marginBottom: 0px"
69
- * @param opts.auto if set to true, include an `a` suffix for auto values, i.e. `mta`
70
- */
71
- export declare function newIncrementMethods(config: Config, abbr: UtilityName, prop: Prop | Prop[], opts?: {
72
- auto?: boolean;
73
- }): UtilityMethod[];
74
- /**
75
- * Creates just the core `<abbr>X` utility methods that set `props` with each increment value.
76
- *
77
- * See `newIncrementMethods` for handling the `<abbr>Px`, `<abbr>a`, and `<attr>(value)` methods.
78
- */
79
- export declare function newCoreIncrementMethods(config: Config, abbr: UtilityName, props: Prop[]): UtilityMethod[];
80
- export declare function newPxMethod(abbr: UtilityName, prop: Prop): UtilityMethod;
81
- export declare const zeroTo: (n: number) => number[];
82
- export declare function comment(defs: object): string;
package/build/methods.js DELETED
@@ -1,190 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.zeroTo = void 0;
29
- exports.newMethod = newMethod;
30
- exports.newParamMethod = newParamMethod;
31
- exports.newMethodsForProp = newMethodsForProp;
32
- exports.newAliasesMethods = newAliasesMethods;
33
- exports.newSetCssVariablesMethod = newSetCssVariablesMethod;
34
- exports.newIncrementMethods = newIncrementMethods;
35
- exports.newCoreIncrementMethods = newCoreIncrementMethods;
36
- exports.newPxMethod = newPxMethod;
37
- exports.comment = comment;
38
- /**
39
- * Given a single abbreviation (i.e. `mt0`) and multiple `{ prop: value }` CSS values, returns
40
- * the TypeScript code for a `mt0` utility method that sets those values.
41
- */
42
- function newMethod(abbr, defs) {
43
- return "".concat(comment(defs), " get ").concat(abbr, "() { return this").concat(Object.entries(defs)
44
- .map(function (_a) {
45
- var _b = __read(_a, 2), prop = _b[0], value = _b[1];
46
- return ".add(\"".concat(prop, "\", ").concat(maybeWrap(value), ")");
47
- })
48
- .join(""), "; }");
49
- }
50
- /**
51
- * Given a single abbreviation (i.e. `mt`) and a property name (i.e. `marginTop`), returns the
52
- * TypeScript code for a `mt` utility method that accepts a user-provided value of the prop to set.
53
- * Use `extraProperties` for additional properties to set.
54
- *
55
- * I.e. `Css.mt(someValue).$`
56
- */
57
- function newParamMethod(abbr, prop, extraProperties) {
58
- var _a;
59
- if (extraProperties === void 0) { extraProperties = {}; }
60
- var additionalDefs = Object.entries(extraProperties).map(function (_a) {
61
- var _b = __read(_a, 2), prop = _b[0], value = _b[1];
62
- return ".add(\"".concat(prop, "\", ").concat(maybeWrap(value), ")");
63
- }).join("");
64
- return "".concat(comment((_a = {}, _a[prop] = "value", _a)), " ").concat(abbr, "(value: Properties[\"").concat(prop, "\"]) { return this.add(\"").concat(prop, "\", value)").concat(additionalDefs, "; }");
65
- }
66
- /**
67
- * Given a prop to set (i.e. `marginTop`), and multiple abbr/value pairs (i.e. `{ mt0: "0px", mt1: "4px" }`),
68
- * returns a utility method for each abbr/value pair.
69
- *
70
- * I.e. `mt0() { ...add("marginTop", "0px")... }`
71
- *
72
- * By default, we also generate a param method for `prop`, i.e. if `prop` is `marginTop`, we'll
73
- * make a `marginTop(value)` method for users to pass variable values. You can change the
74
- * name of this method by setting `baseName` or disable it completely by setting `baseName`
75
- * to `null`.
76
- *
77
- * @param prop the CSS property we're setting, i.e. `marginTop`
78
- * @param defs a map of abbreviation name --> value (a property value or an object of properties to set)
79
- * @param baseName the base name to use, i.e. `mt`
80
- * @param includePx generate an extra `${baseName}Px` method that calls the base method with a converted px value
81
- * @param baseDefs additional properties to set for the base method
82
- */
83
- function newMethodsForProp(prop, defs, baseName, includePx, valueMethodExtraProperties) {
84
- if (baseName === void 0) { baseName = prop; }
85
- if (includePx === void 0) { includePx = false; }
86
- return __spreadArray(__spreadArray(__spreadArray([], __read(Object.entries(defs).map(function (_a) {
87
- var _b;
88
- var _c = __read(_a, 2), abbr = _c[0], value = _c[1];
89
- return newMethod(abbr,
90
- // If the value is an object, use it as the full defs, otherwise, use it as the prop value
91
- typeof value === "object" ? value : (_b = {}, _b[prop] = value, _b));
92
- })), false), __read((baseName !== null ? [newParamMethod(baseName, prop, valueMethodExtraProperties)] : [])), false), __read((baseName !== null && includePx ? [newPxMethod(baseName, prop)] : [])), false);
93
- }
94
- /**
95
- * Given aliases, i.e. `{ bodyText: ["f12", "bold"] }`, returns a utility method
96
- * for each alias that calls its corresponding utility classes.
97
- */
98
- function newAliasesMethods(aliases) {
99
- return Object.entries(aliases).map(function (_a) {
100
- var _b = __read(_a, 2), abbr = _b[0], values = _b[1];
101
- return "get ".concat(abbr, "() { return this").concat(values.map(function (v) { return ".".concat(v); }).join(""), "; }");
102
- });
103
- }
104
- /**
105
- * Makes a utility method that can set CSS custom variables.
106
- *
107
- * I.e. `newSetCssVariableMethod("dark", { "--Primary": "white" })` will create a
108
- * utility method `Css.dark.$ that will set `--Primary` to `white`.
109
- *
110
- * Currently, this only supports compile-time/hard-coded values. I.e. we don't support
111
- * something like `Css.dark({ "--Primary", someRuntimeValue }).$` yet.
112
- *
113
- * TODO: Create a `Css.set(cssVars).$` method.
114
- */
115
- function newSetCssVariablesMethod(abbr, defs) {
116
- return "get ".concat(abbr, "() { return this").concat(Object.entries(defs)
117
- .map(function (_a) {
118
- var _b = __read(_a, 2), prop = _b[0], value = _b[1];
119
- return ".add(\"".concat(prop, "\" as any, \"").concat(value, "\")");
120
- })
121
- .join(""), "; }");
122
- }
123
- /**
124
- * Makes [`mt0`, `mt1`, ...] utility methods for each configured increment
125
- * to set `prop` to that given increment's value in pixels.
126
- *
127
- * I.e. we assume `prop` is a CSS property like `margin` that accepts pixels as values,
128
- * and so convert each increment `x` (1, 2, 3) to pixels `Y` (8, 16, 24) and create
129
- * a utility method for each `x -> Y` pair, i.e. `mt0 = mt(px(0))`.
130
- *
131
- * We also create a final param method, i.e. `mt(number)`, for callers that
132
- * need to call `mt` with a conditional amount of increments.
133
- *
134
- * @param config the config
135
- * @param abbr the utility prefix, i.e. `mt`
136
- * @param props if a CSS prop like `marginTop`, we output "mt0 --> marginTop: 0px", if an array like
137
- * `["marginTop", "marginBottom"]`, we output "my0 --> marginTop: 0px, marginBottom: 0px"
138
- * @param opts.auto if set to true, include an `a` suffix for auto values, i.e. `mta`
139
- */
140
- function newIncrementMethods(config, abbr, prop, opts) {
141
- if (opts === void 0) { opts = {}; }
142
- // Create `m1`, `m2`, etc. that will call our main `m` method.
143
- var props = typeof prop === "string" ? [prop] : prop;
144
- var delegateMethods = newCoreIncrementMethods(config, abbr, props);
145
- var autoComment = comment(Object.fromEntries(props.map(function (p) { return [p, "auto"]; })));
146
- var valueComment = comment(Object.fromEntries(props.map(function (p) { return [p, "v"]; })));
147
- var pxComment = comment(Object.fromEntries(props.map(function (p) { return [p, "px"]; })));
148
- return __spreadArray(__spreadArray(__spreadArray([], __read(delegateMethods), false), __read((opts.auto
149
- ? ["".concat(autoComment, " get ").concat(abbr, "a() { return this.").concat(props.map(function (p) { return "add(\"".concat(p, "\", \"auto\")"); }).join("."), "; }")]
150
- : [])), false), [
151
- "".concat(valueComment, " ").concat(abbr, "(v: number | string) { return this.").concat(props
152
- .map(function (p) { return "add(\"".concat(p, "\", maybeInc(v))"); })
153
- .join("."), "; }"),
154
- "".concat(pxComment, " ").concat(abbr, "Px(px: number) { return this.").concat(props.map(function (p) { return "add(\"".concat(p, "\", `${px}px`)"); }).join("."), "; }"),
155
- ], false);
156
- }
157
- /**
158
- * Creates just the core `<abbr>X` utility methods that set `props` with each increment value.
159
- *
160
- * See `newIncrementMethods` for handling the `<abbr>Px`, `<abbr>a`, and `<attr>(value)` methods.
161
- */
162
- function newCoreIncrementMethods(config, abbr, props) {
163
- return (0, exports.zeroTo)(config.numberOfIncrements).map(function (i) {
164
- var px = "".concat(i * config.increment, "px");
165
- var defs = Object.fromEntries(props.map(function (p) { return [p, px]; }));
166
- var sets = props.map(function (p) { return "add(\"".concat(p, "\", \"").concat(px, "\")"); }).join(".");
167
- return "".concat(comment(defs), " get ").concat(abbr).concat(i, "() { return this.").concat(sets, "; }");
168
- });
169
- }
170
- function newPxMethod(abbr, prop) {
171
- var _a;
172
- return "".concat(comment((_a = {}, _a[prop] = "px", _a)), " ").concat(abbr, "Px(px: number) { return this.").concat(abbr, "(`${px}px`); }");
173
- }
174
- var zeroTo = function (n) { return __spreadArray([], __read(Array(n + 1).keys()), false); };
175
- exports.zeroTo = zeroTo;
176
- /** Keeps numbers as literals, and wraps anything else with double quotes. */
177
- function maybeWrap(value) {
178
- return typeof value === "number" ? String(value) : "\"".concat(value, "\"");
179
- }
180
- function comment(defs) {
181
- var paramNames = ["value", "px", "inc"];
182
- var values = Object.entries(defs)
183
- .map(function (_a) {
184
- var _b = __read(_a, 2), prop = _b[0], value = _b[1];
185
- return "".concat(prop, ": ").concat(paramNames.includes(value) ? value : maybeWrap(value));
186
- })
187
- .join("; ");
188
- return "/** Sets `".concat(values, "`. */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