@servicetitan/hammer-token 2.5.2 → 3.0.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.
- package/CHANGELOG.md +52 -2
- package/README.md +332 -0
- package/build/web/core/component-variables.scss +1088 -131
- package/build/web/core/component.d.ts +558 -0
- package/build/web/core/component.js +6685 -249
- package/build/web/core/component.scss +557 -69
- package/build/web/core/css-utils/a2-border.css +23 -51
- package/build/web/core/css-utils/a2-color.css +221 -233
- package/build/web/core/css-utils/a2-font.css +1 -29
- package/build/web/core/css-utils/a2-spacing.css +238 -483
- package/build/web/core/css-utils/a2-utils.css +496 -781
- package/build/web/core/css-utils/border.css +23 -51
- package/build/web/core/css-utils/color.css +221 -233
- package/build/web/core/css-utils/font.css +1 -29
- package/build/web/core/css-utils/spacing.css +238 -483
- package/build/web/core/css-utils/utils.css +496 -781
- package/build/web/core/index.d.ts +6 -0
- package/build/web/core/index.js +1 -1
- package/build/web/core/primitive-variables.scss +148 -65
- package/build/web/core/primitive.d.ts +209 -0
- package/build/web/core/primitive.js +779 -61
- package/build/web/core/primitive.scss +207 -124
- package/build/web/core/semantic-variables.scss +363 -245
- package/build/web/core/semantic.d.ts +221 -0
- package/build/web/core/semantic.js +1592 -347
- package/build/web/core/semantic.scss +219 -140
- package/build/web/index.d.ts +3 -4
- package/build/web/types.d.ts +17 -0
- package/config.js +121 -496
- package/eslint.config.mjs +11 -1
- package/package.json +15 -5
- package/src/global/primitive/breakpoint.tokens.json +54 -0
- package/src/global/primitive/color.tokens.json +1092 -0
- package/src/global/primitive/duration.tokens.json +44 -0
- package/src/global/primitive/font.tokens.json +151 -0
- package/src/global/primitive/radius.tokens.json +94 -0
- package/src/global/primitive/size.tokens.json +174 -0
- package/src/global/primitive/transition.tokens.json +32 -0
- package/src/theme/core/background.tokens.json +1312 -0
- package/src/theme/core/border.tokens.json +192 -0
- package/src/theme/core/chart.tokens.json +982 -0
- package/src/theme/core/component/ai-mark.tokens.json +20 -0
- package/src/theme/core/component/alert.tokens.json +261 -0
- package/src/theme/core/component/announcement.tokens.json +460 -0
- package/src/theme/core/component/avatar.tokens.json +137 -0
- package/src/theme/core/component/badge.tokens.json +42 -0
- package/src/theme/core/component/breadcrumb.tokens.json +42 -0
- package/src/theme/core/component/button-toggle.tokens.json +428 -0
- package/src/theme/core/component/button.tokens.json +941 -0
- package/src/theme/core/component/calendar.tokens.json +391 -0
- package/src/theme/core/component/card.tokens.json +107 -0
- package/src/theme/core/component/checkbox.tokens.json +631 -0
- package/src/theme/core/component/chip.tokens.json +169 -0
- package/src/theme/core/component/combobox.tokens.json +269 -0
- package/src/theme/core/component/details.tokens.json +152 -0
- package/src/theme/core/component/dialog.tokens.json +87 -0
- package/src/theme/core/component/divider.tokens.json +23 -0
- package/src/theme/core/component/dnd.tokens.json +208 -0
- package/src/theme/core/component/drawer.tokens.json +61 -0
- package/src/theme/core/component/drilldown.tokens.json +61 -0
- package/src/theme/core/component/edit-card.tokens.json +381 -0
- package/src/theme/core/component/field-label.tokens.json +42 -0
- package/src/theme/core/component/field-message.tokens.json +65 -0
- package/src/theme/core/component/icon.tokens.json +42 -0
- package/src/theme/core/component/link.tokens.json +108 -0
- package/src/theme/core/component/list-view.tokens.json +82 -0
- package/src/theme/core/component/listbox.tokens.json +283 -0
- package/src/theme/core/component/menu.tokens.json +230 -0
- package/src/theme/core/component/overflow.tokens.json +84 -0
- package/src/theme/core/component/page.tokens.json +377 -0
- package/src/theme/core/component/pagination.tokens.json +63 -0
- package/src/theme/core/component/popover.tokens.json +122 -0
- package/src/theme/core/component/progress-bar.tokens.json +133 -0
- package/src/theme/core/component/radio.tokens.json +631 -0
- package/src/theme/core/component/segmented-control.tokens.json +175 -0
- package/src/theme/core/component/select-card.tokens.json +943 -0
- package/src/theme/core/component/side-nav.tokens.json +349 -0
- package/src/theme/core/component/skeleton.tokens.json +42 -0
- package/src/theme/core/component/spinner.tokens.json +96 -0
- package/src/theme/core/component/status-icon.tokens.json +164 -0
- package/src/theme/core/component/stepper.tokens.json +484 -0
- package/src/theme/core/component/switch.tokens.json +285 -0
- package/src/theme/core/component/tab.tokens.json +192 -0
- package/src/theme/core/component/text-field.tokens.json +160 -0
- package/src/theme/core/component/text.tokens.json +59 -0
- package/src/theme/core/component/toast.tokens.json +343 -0
- package/src/theme/core/component/toolbar.tokens.json +114 -0
- package/src/theme/core/component/tooltip.tokens.json +61 -0
- package/src/theme/core/focus.tokens.json +56 -0
- package/src/theme/core/foreground.tokens.json +416 -0
- package/src/theme/core/gradient.tokens.json +41 -0
- package/src/theme/core/opacity.tokens.json +25 -0
- package/src/theme/core/shadow.tokens.json +81 -0
- package/src/theme/core/status.tokens.json +74 -0
- package/src/theme/core/typography.tokens.json +163 -0
- package/src/utils/__tests__/css-utils-format-utils.test.js +312 -0
- package/src/utils/__tests__/sd-build-configs.test.js +306 -0
- package/src/utils/__tests__/sd-formats.test.js +942 -0
- package/src/utils/__tests__/sd-transforms.test.js +336 -0
- package/src/utils/__tests__/token-helpers.test.js +1160 -0
- package/src/utils/copy-css-utils-cli.js +13 -1
- package/src/utils/css-utils-format-utils.js +105 -176
- package/src/utils/figma/__tests__/sync-gradient.test.js +561 -0
- package/src/utils/figma/__tests__/token-conversion.test.js +117 -0
- package/src/utils/figma/__tests__/token-resolution.test.js +231 -0
- package/src/utils/figma/auth.js +355 -0
- package/src/utils/figma/constants.js +22 -0
- package/src/utils/figma/errors.js +80 -0
- package/src/utils/figma/figma-api.js +1069 -0
- package/src/utils/figma/get-token.js +348 -0
- package/src/utils/figma/sync-components.js +909 -0
- package/src/utils/figma/sync-main.js +692 -0
- package/src/utils/figma/sync-orchestration.js +683 -0
- package/src/utils/figma/sync-primitives.js +230 -0
- package/src/utils/figma/sync-semantic.js +1056 -0
- package/src/utils/figma/token-conversion.js +340 -0
- package/src/utils/figma/token-parsing.js +186 -0
- package/src/utils/figma/token-resolution.js +569 -0
- package/src/utils/figma/utils.js +199 -0
- package/src/utils/sd-build-configs.js +305 -0
- package/src/utils/sd-formats.js +948 -0
- package/src/utils/sd-transforms.js +165 -0
- package/src/utils/token-helpers.js +848 -0
- package/tsconfig.json +18 -0
- package/vitest.config.js +17 -0
- package/.turbo/turbo-build.log +0 -37
- package/build/web/core/raw.js +0 -234
- package/src/global/primitive/breakpoint.js +0 -19
- package/src/global/primitive/color.js +0 -231
- package/src/global/primitive/duration.js +0 -16
- package/src/global/primitive/font.js +0 -60
- package/src/global/primitive/radius.js +0 -31
- package/src/global/primitive/size.js +0 -55
- package/src/global/primitive/transition.js +0 -16
- package/src/theme/core/background.js +0 -170
- package/src/theme/core/border.js +0 -103
- package/src/theme/core/charts.js +0 -464
- package/src/theme/core/component/button.js +0 -708
- package/src/theme/core/component/checkbox.js +0 -405
- package/src/theme/core/focus.js +0 -35
- package/src/theme/core/foreground.js +0 -148
- package/src/theme/core/overlay.js +0 -137
- package/src/theme/core/shadow.js +0 -29
- package/src/theme/core/status.js +0 -49
- package/src/theme/core/typography.js +0 -82
- package/type/types.ts +0 -344
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* CLI tool for copying CSS utility files from hammer-token to a target project
|
|
4
|
+
* @module copy-css-utils-cli
|
|
5
|
+
*/
|
|
3
6
|
const { program } = require("commander");
|
|
4
7
|
const path = require("path");
|
|
5
8
|
const fs = require("fs");
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Runs the CLI program that provides the copy-css-utils command.
|
|
12
|
+
* This command copies all CSS utility files from the hammer-token build directory
|
|
13
|
+
* to a specified destination directory in the user's project.
|
|
14
|
+
* @returns {void}
|
|
15
|
+
* @example
|
|
16
|
+
* // From command line:
|
|
17
|
+
* // npx hammer-token copy-css-utils ./src/styles
|
|
18
|
+
*/
|
|
7
19
|
function run() {
|
|
8
20
|
program
|
|
9
21
|
.command("copy-css-utils")
|
|
@@ -1,209 +1,119 @@
|
|
|
1
|
-
const cssUtilsFormatter = (
|
|
2
|
-
dictionary,
|
|
3
|
-
generateFn,
|
|
4
|
-
{ hasDark, prefix = "" },
|
|
5
|
-
) => {
|
|
6
|
-
const result = dictionary.allTokens
|
|
7
|
-
.filter((token) => token.name.includes("color"))
|
|
8
|
-
.map((token) => {
|
|
9
|
-
const value = getVarValue(dictionary, token);
|
|
10
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
11
|
-
|
|
12
|
-
if (hasDark && token.attributes.appearance) {
|
|
13
|
-
const darkValue = getVarValue(dictionary, token, { isDark: true });
|
|
14
|
-
return generateFn(name, value, { darkValue, prefix });
|
|
15
|
-
}
|
|
16
|
-
return generateFn(name, value, { prefix });
|
|
17
|
-
})
|
|
18
|
-
.flat()
|
|
19
|
-
.map((t) => `${t}`)
|
|
20
|
-
.sort((a, b) => a.localeCompare(b))
|
|
21
|
-
.join(`\n`);
|
|
22
|
-
|
|
23
|
-
const fallback = dictionary.allTokens
|
|
24
|
-
.map((token) => {
|
|
25
|
-
const value = getVarValue(dictionary, token);
|
|
26
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
27
|
-
return generateFn(name, value, { prefix });
|
|
28
|
-
})
|
|
29
|
-
.flat()
|
|
30
|
-
.map((t) => `${t}`)
|
|
31
|
-
.sort((a, b) => a.localeCompare(b))
|
|
32
|
-
.join(`\n`);
|
|
33
|
-
|
|
34
|
-
return `@layer starter, reset, base, state, application;
|
|
35
|
-
|
|
36
|
-
${fallback}
|
|
37
|
-
${
|
|
38
|
-
result.length > 0
|
|
39
|
-
? `\n@supports (color: light-dark(#fff, #000)) {
|
|
40
|
-
${result.replaceAll("\n", "\n ")}
|
|
41
|
-
}`
|
|
42
|
-
: ""
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@layer application {
|
|
46
|
-
${fallback.replaceAll("\n", "\n ")}
|
|
47
|
-
${
|
|
48
|
-
result.length > 0
|
|
49
|
-
? `\n @supports (color: light-dark(#fff, #000)) {
|
|
50
|
-
${result.replaceAll("\n", "\n ")}
|
|
51
|
-
}`
|
|
52
|
-
: ""
|
|
53
|
-
}
|
|
54
|
-
}`;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const getNewValueFromRef = (value, ref) => {
|
|
58
|
-
return value.replace(ref.value, function () {
|
|
59
|
-
// fallback for nested vars
|
|
60
|
-
if (ref.name === undefined) {
|
|
61
|
-
return `${ref.value}`;
|
|
62
|
-
} else {
|
|
63
|
-
return `var(--${ref.name}, ${ref.value})`;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const colorHasAlphaValue = (value) => {
|
|
69
|
-
// e.g. var(--something)44 isn't valid
|
|
70
|
-
return /\)[\d]+/.test(value);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
1
|
/**
|
|
74
|
-
*
|
|
2
|
+
* CSS utility class generation functions for Style Dictionary
|
|
3
|
+
* @module css-utils-format-utils
|
|
75
4
|
*/
|
|
76
|
-
const getVarValue = (dictionary, token, { isDark } = {}) => {
|
|
77
|
-
let value;
|
|
78
|
-
|
|
79
|
-
if (isDark) {
|
|
80
|
-
value = JSON.stringify(token.attributes.appearance.dark.value);
|
|
81
|
-
if (
|
|
82
|
-
dictionary.usesReference(token.original.attributes.appearance.dark.value)
|
|
83
|
-
) {
|
|
84
|
-
const refs = dictionary.getReferences(
|
|
85
|
-
token.original.attributes.appearance.dark.value,
|
|
86
|
-
);
|
|
87
|
-
refs.forEach((ref) => {
|
|
88
|
-
const newValue = getNewValueFromRef(value, ref);
|
|
89
|
-
if (colorHasAlphaValue(newValue) === false) {
|
|
90
|
-
value = newValue;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
value = JSON.stringify(token.value);
|
|
96
|
-
if (dictionary.usesReference(token.original.value)) {
|
|
97
|
-
const refs = dictionary.getReferences(token.original.value);
|
|
98
|
-
refs.forEach((ref) => {
|
|
99
|
-
const newValue = getNewValueFromRef(value, ref);
|
|
100
|
-
if (colorHasAlphaValue(newValue) === false) {
|
|
101
|
-
value = newValue;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return value.replaceAll('"', "");
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const removeDefaultFromName = (name) => {
|
|
111
|
-
return name.replace("-default", "");
|
|
112
|
-
};
|
|
113
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Generates CSS utility classes for border tokens (radius, width, color).
|
|
8
|
+
* @param {string} name - The token name
|
|
9
|
+
* @param {string} value - The token value
|
|
10
|
+
* @param {Object} [options] - Generation options
|
|
11
|
+
* @param {string} [options.darkValue] - The dark mode value for light-dark() support
|
|
12
|
+
* @param {string} [options.prefix=''] - CSS class prefix
|
|
13
|
+
* @param {string} [options.cssVarPrefix=''] - CSS variable prefix (e.g., 'a2-')
|
|
14
|
+
* @returns {string[]} Array of CSS class declarations
|
|
15
|
+
* @example
|
|
16
|
+
* generateBorderClasses('border-radius-small', '4px', { prefix: 'a2-', cssVarPrefix: 'a2-' })
|
|
17
|
+
* // Returns: ['.a2-border-radius-small {border-radius: var(--a2-border-radius-small, 4px)}']
|
|
18
|
+
*/
|
|
114
19
|
const generateBorderClasses = (
|
|
115
20
|
name,
|
|
116
21
|
value,
|
|
117
|
-
{ darkValue, prefix = "" } = {},
|
|
22
|
+
{ darkValue, prefix = "", cssVarPrefix = "" } = {},
|
|
118
23
|
) => {
|
|
119
24
|
const classes = [];
|
|
25
|
+
const cssVar = `${cssVarPrefix}${name}`;
|
|
120
26
|
|
|
121
27
|
if (name.startsWith("border-radius")) {
|
|
122
28
|
classes.push(
|
|
123
|
-
`.${prefix}${name} {border-radius: var(--${
|
|
29
|
+
`.${prefix}${name} {border-radius: var(--${cssVar}, ${value})}`,
|
|
124
30
|
);
|
|
125
31
|
} else if (name.startsWith("border-width")) {
|
|
126
32
|
classes.push(
|
|
127
|
-
`.${prefix}${name} {border-width: var(--${
|
|
33
|
+
`.${prefix}${name} {border-width: var(--${cssVar}, ${value})}`,
|
|
128
34
|
);
|
|
129
35
|
} else if (name.startsWith("border-color")) {
|
|
130
36
|
if (darkValue) {
|
|
131
37
|
classes.push(
|
|
132
|
-
`.${prefix}${name} {border-color: var(--${
|
|
38
|
+
`.${prefix}${name} {border-color: var(--${cssVar}, light-dark(${value}, ${darkValue}))}`,
|
|
133
39
|
);
|
|
134
40
|
} else {
|
|
135
41
|
classes.push(
|
|
136
|
-
`.${prefix}${name} {border-color: var(--${
|
|
42
|
+
`.${prefix}${name} {border-color: var(--${cssVar}, ${value})}`,
|
|
137
43
|
);
|
|
138
44
|
}
|
|
139
45
|
}
|
|
140
46
|
return classes;
|
|
141
47
|
};
|
|
142
48
|
|
|
143
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Generates CSS utility classes for color tokens (background, foreground, status, overlay, border).
|
|
51
|
+
* Creates appropriate class names based on the token type (bg-, c-, bg-status-, etc.).
|
|
52
|
+
* @param {string} name - The token name
|
|
53
|
+
* @param {string} value - The token value
|
|
54
|
+
* @param {Object} [options] - Generation options
|
|
55
|
+
* @param {string} [options.darkValue] - The dark mode value for light-dark() support
|
|
56
|
+
* @param {string} [options.prefix=''] - CSS class prefix
|
|
57
|
+
* @param {string} [options.cssVarPrefix=''] - CSS variable prefix (e.g., 'a2-')
|
|
58
|
+
* @returns {string[]} Array of CSS class declarations
|
|
59
|
+
* @example
|
|
60
|
+
* generateColorClasses('background-color-primary', '#fff', { prefix: 'a2-', cssVarPrefix: 'a2-' })
|
|
61
|
+
* // Returns: ['.a2-bg-primary {background-color: var(--a2-background-color-primary, #fff)}']
|
|
62
|
+
*/
|
|
63
|
+
const generateColorClasses = (
|
|
64
|
+
name,
|
|
65
|
+
value,
|
|
66
|
+
{ darkValue, prefix = "", cssVarPrefix = "" } = {},
|
|
67
|
+
) => {
|
|
144
68
|
const classes = [];
|
|
69
|
+
const resolvedValue = darkValue
|
|
70
|
+
? `light-dark(${value}, ${darkValue})`
|
|
71
|
+
: value;
|
|
72
|
+
const cssVar = `${cssVarPrefix}${name}`;
|
|
145
73
|
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (!name.includes("danger")) {
|
|
165
|
-
classes.push(
|
|
166
|
-
`.${prefix}${name.replace("status-color", "border-color-status")} {border-color: var(--${removeDefaultFromName(name)}, light-dark(${value}, ${darkValue}))}`,
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
} else if (name.startsWith("border-color")) {
|
|
170
|
-
classes.push(
|
|
171
|
-
`.${prefix}${name} {border-color: var(--${removeDefaultFromName(name)}, light-dark(${value}, ${darkValue}))}`,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
if (name.startsWith("background-color")) {
|
|
176
|
-
classes.push(
|
|
177
|
-
`.${prefix}${name.replace("background-color", "bg")} {background-color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
178
|
-
);
|
|
179
|
-
} else if (name.startsWith("foreground-color")) {
|
|
180
|
-
classes.push(
|
|
181
|
-
`.${prefix}${name.replace("foreground-color", "c")} {color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
182
|
-
);
|
|
183
|
-
} else if (name.startsWith("overlay-color")) {
|
|
184
|
-
classes.push(
|
|
185
|
-
`.${prefix}${name.replace("overlay-color", "bg-overlay")} {background-color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
186
|
-
);
|
|
187
|
-
} else if (name.startsWith("status-color")) {
|
|
188
|
-
classes.push(
|
|
189
|
-
`.${prefix}${name.replace("status-color", "c-status")} {color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
190
|
-
`.${prefix}${name.replace("status-color", "bg-status")} {background-color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
191
|
-
);
|
|
192
|
-
if (!name.includes("danger")) {
|
|
193
|
-
classes.push(
|
|
194
|
-
`.${prefix}${name.replace("status-color", "border-color-status")} {border-color: var(--${removeDefaultFromName(name)}, ${value})}`,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
} else if (name.startsWith("border-color")) {
|
|
74
|
+
if (name.startsWith("background-color")) {
|
|
75
|
+
classes.push(
|
|
76
|
+
`.${prefix}${name.replace("background-color", "bg")} {background-color: var(--${cssVar}, ${resolvedValue})}`,
|
|
77
|
+
);
|
|
78
|
+
} else if (name.startsWith("foreground-color")) {
|
|
79
|
+
classes.push(
|
|
80
|
+
`.${prefix}${name.replace("foreground-color", "c")} {color: var(--${cssVar}, ${resolvedValue})}`,
|
|
81
|
+
);
|
|
82
|
+
} else if (name.startsWith("overlay-color")) {
|
|
83
|
+
classes.push(
|
|
84
|
+
`.${prefix}${name.replace("overlay-color", "bg-overlay")} {background-color: var(--${cssVar}, ${resolvedValue})}`,
|
|
85
|
+
);
|
|
86
|
+
} else if (name.startsWith("status-color")) {
|
|
87
|
+
classes.push(
|
|
88
|
+
`.${prefix}${name.replace("status-color", "c-status")} {color: var(--${cssVar}, ${resolvedValue})}`,
|
|
89
|
+
`.${prefix}${name.replace("status-color", "bg-status")} {background-color: var(--${cssVar}, ${resolvedValue})}`,
|
|
90
|
+
);
|
|
91
|
+
if (!name.includes("danger")) {
|
|
198
92
|
classes.push(
|
|
199
|
-
`.${prefix}${name} {border-color: var(--${
|
|
93
|
+
`.${prefix}${name.replace("status-color", "border-color-status")} {border-color: var(--${cssVar}, ${resolvedValue})}`,
|
|
200
94
|
);
|
|
201
95
|
}
|
|
96
|
+
} else if (name.startsWith("border-color")) {
|
|
97
|
+
classes.push(
|
|
98
|
+
`.${prefix}${name} {border-color: var(--${cssVar}, ${resolvedValue})}`,
|
|
99
|
+
);
|
|
202
100
|
}
|
|
203
101
|
|
|
204
102
|
return classes;
|
|
205
103
|
};
|
|
206
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Generates CSS utility classes for typography tokens (font-family, font-weight, font-size).
|
|
107
|
+
* Creates class names with ff-, fw-, fs- prefixes based on the typography property.
|
|
108
|
+
* @param {string} name - The token name
|
|
109
|
+
* @param {string} value - The token value
|
|
110
|
+
* @param {Object} [options] - Generation options
|
|
111
|
+
* @param {string} [options.prefix=''] - CSS class prefix
|
|
112
|
+
* @returns {string[]} Array of CSS class declarations
|
|
113
|
+
* @example
|
|
114
|
+
* generateFontClasses('typography-body-font-family', 'Arial', { prefix: 'a2-' })
|
|
115
|
+
* // Returns: ['.a2-ff-body {font-family: Arial}']
|
|
116
|
+
*/
|
|
207
117
|
const generateFontClasses = (name, value, { prefix = "" } = {}) => {
|
|
208
118
|
const classes = [];
|
|
209
119
|
|
|
@@ -226,7 +136,27 @@ const generateFontClasses = (name, value, { prefix = "" } = {}) => {
|
|
|
226
136
|
return classes;
|
|
227
137
|
};
|
|
228
138
|
|
|
229
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Generates CSS utility classes for spacing/size tokens (margin, padding).
|
|
141
|
+
* Creates classes for all logical property directions (inline-start, inline-end, block-start, etc.).
|
|
142
|
+
* @param {string} name - The token name (e.g., 'size-4')
|
|
143
|
+
* @param {string} value - The token value (e.g., '1rem')
|
|
144
|
+
* @param {Object} [options] - Generation options
|
|
145
|
+
* @param {string} [options.prefix=''] - CSS class prefix
|
|
146
|
+
* @param {string} [options.cssVarPrefix=''] - CSS variable prefix (e.g., 'a2-')
|
|
147
|
+
* @returns {string[]} Array of CSS class declarations for margin and padding utilities
|
|
148
|
+
* @example
|
|
149
|
+
* generateSpacingClasses('size-4', '1rem', { prefix: 'a2-' })
|
|
150
|
+
* // Returns array including:
|
|
151
|
+
* // '.a2-m-inline-start-4 {margin-inline-start: var(--a2-size-4, 1rem)}'
|
|
152
|
+
* // '.a2-p-inline-start-4 {padding-inline-start: var(--a2-size-4, 1rem)}'
|
|
153
|
+
* // ... and more for each direction
|
|
154
|
+
*/
|
|
155
|
+
const generateSpacingClasses = (
|
|
156
|
+
name,
|
|
157
|
+
value,
|
|
158
|
+
{ prefix = "", cssVarPrefix = "" } = {},
|
|
159
|
+
) => {
|
|
230
160
|
const nameWithoutPrefix = name.substring(name.indexOf("-"));
|
|
231
161
|
|
|
232
162
|
const directions = [
|
|
@@ -238,28 +168,27 @@ const generateSpacingClasses = (name, value, { prefix = "" } = {}) => {
|
|
|
238
168
|
"inline",
|
|
239
169
|
];
|
|
240
170
|
const classes = [];
|
|
171
|
+
const cssVar = `${cssVarPrefix}${name}`;
|
|
241
172
|
|
|
242
173
|
directions.forEach((direction) => {
|
|
243
174
|
classes.push(
|
|
244
|
-
`.${prefix}m-${direction}${nameWithoutPrefix} {margin-${direction}: var(--${
|
|
175
|
+
`.${prefix}m-${direction}${nameWithoutPrefix} {margin-${direction}: var(--${cssVar}, ${value})}`,
|
|
245
176
|
);
|
|
246
177
|
classes.push(
|
|
247
|
-
`.${prefix}p-${direction}${nameWithoutPrefix} {padding-${direction}: var(--${
|
|
178
|
+
`.${prefix}p-${direction}${nameWithoutPrefix} {padding-${direction}: var(--${cssVar}, ${value})}`,
|
|
248
179
|
);
|
|
249
180
|
});
|
|
250
181
|
classes.push(
|
|
251
|
-
`.${prefix}m${nameWithoutPrefix} {margin: var(--${
|
|
182
|
+
`.${prefix}m${nameWithoutPrefix} {margin: var(--${cssVar}, ${value})}`,
|
|
252
183
|
);
|
|
253
184
|
classes.push(
|
|
254
|
-
`.${prefix}p${nameWithoutPrefix} {padding: var(--${
|
|
185
|
+
`.${prefix}p${nameWithoutPrefix} {padding: var(--${cssVar}, ${value})}`,
|
|
255
186
|
);
|
|
256
187
|
|
|
257
188
|
return classes;
|
|
258
189
|
};
|
|
259
190
|
|
|
260
191
|
module.exports = {
|
|
261
|
-
cssUtilsFormatter,
|
|
262
|
-
getVarValue,
|
|
263
192
|
generateBorderClasses,
|
|
264
193
|
generateColorClasses,
|
|
265
194
|
generateFontClasses,
|