@servicetitan/hammer-token 2.5.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- 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 +47 -45
- package/build/web/core/css-utils/a2-color.css +443 -227
- package/build/web/core/css-utils/a2-font.css +0 -2
- package/build/web/core/css-utils/a2-spacing.css +476 -478
- package/build/web/core/css-utils/a2-utils.css +992 -772
- package/build/web/core/css-utils/border.css +47 -45
- package/build/web/core/css-utils/color.css +443 -227
- package/build/web/core/css-utils/font.css +0 -2
- package/build/web/core/css-utils/spacing.css +476 -478
- package/build/web/core/css-utils/utils.css +992 -772
- 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/index.js +0 -1
- package/build/web/types.d.ts +17 -0
- package/config.js +121 -497
- 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 +74 -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 +950 -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 +965 -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
package/config.js
CHANGED
|
@@ -1,504 +1,128 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
-
const StyleDictionary = require("style-dictionary");
|
|
3
1
|
const fs = require("fs-extra");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
generateBorderClasses,
|
|
8
|
-
generateColorClasses,
|
|
9
|
-
generateFontClasses,
|
|
10
|
-
generateSpacingClasses,
|
|
11
|
-
} = require("./src/utils/css-utils-format-utils");
|
|
12
|
-
|
|
13
|
-
StyleDictionary.registerFormat({
|
|
14
|
-
name: `custom/SCSSVariable`,
|
|
15
|
-
formatter: function ({ dictionary }) {
|
|
16
|
-
return dictionary.allTokens
|
|
17
|
-
.map((token) => {
|
|
18
|
-
const value = token.value;
|
|
19
|
-
const name = `${token.name.replace("-default", "")}`;
|
|
20
|
-
if (token.name.includes("font-family"))
|
|
21
|
-
return `$${name}: var(--${name}, ${value});`;
|
|
22
|
-
if (token.attributes.appearance) {
|
|
23
|
-
return `$${name}: var(--${name}, ${value});`;
|
|
24
|
-
}
|
|
25
|
-
return `$${name}: ${value};`;
|
|
26
|
-
})
|
|
27
|
-
.join(`\n`);
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const nonColorTokens = [
|
|
32
|
-
"border-radius",
|
|
33
|
-
"font-family",
|
|
34
|
-
"font-weight",
|
|
35
|
-
"size",
|
|
36
|
-
"width",
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
StyleDictionary.registerFormat({
|
|
40
|
-
name: `custom/variables-map`,
|
|
41
|
-
formatter: function ({ dictionary }) {
|
|
42
|
-
const light = dictionary.allTokens
|
|
43
|
-
.filter((token) => {
|
|
44
|
-
let isColor = true;
|
|
45
|
-
nonColorTokens.forEach((t) => {
|
|
46
|
-
if (token.name.includes(t)) {
|
|
47
|
-
isColor = false;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return isColor;
|
|
51
|
-
})
|
|
52
|
-
.map((token) => {
|
|
53
|
-
const value = token.value;
|
|
54
|
-
const name = `${token.name.replace("-default", "")}`;
|
|
55
|
-
return ` ${name}: ${value},`;
|
|
56
|
-
})
|
|
57
|
-
.join(`\n`);
|
|
58
|
-
|
|
59
|
-
const dark = dictionary.allTokens
|
|
60
|
-
.filter((token) => {
|
|
61
|
-
let isColor = true;
|
|
62
|
-
nonColorTokens.forEach((t) => {
|
|
63
|
-
if (token.name.includes(t)) {
|
|
64
|
-
isColor = false;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return isColor;
|
|
68
|
-
})
|
|
69
|
-
.map((token) => {
|
|
70
|
-
const value = token.value;
|
|
71
|
-
const name = `${token.name.replace("-default", "")}`;
|
|
72
|
-
if (token.attributes.appearance) {
|
|
73
|
-
return ` ${name}: ${token.attributes.appearance.dark.value},`;
|
|
74
|
-
}
|
|
75
|
-
return ` ${name}: ${value},`;
|
|
76
|
-
})
|
|
77
|
-
.join(`\n`);
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { registerTransforms } = require("./src/utils/sd-transforms");
|
|
4
|
+
const { registerFormats } = require("./src/utils/sd-formats");
|
|
78
5
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
StyleDictionary
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
})
|
|
137
|
-
.join(`,\n`);
|
|
138
|
-
const dark = dictionary.allTokens
|
|
139
|
-
.filter((token) => !!token.attributes.appearance)
|
|
140
|
-
.map((token) => {
|
|
141
|
-
const value = JSON.stringify(token.attributes.appearance.dark.value);
|
|
142
|
-
const name = token.name.replace("Default", "");
|
|
143
|
-
return `\t${name}: ${value}`;
|
|
144
|
-
})
|
|
145
|
-
.join(`,\n`);
|
|
146
|
-
const common = dictionary.allTokens
|
|
147
|
-
.filter((token) => !token.attributes.appearance)
|
|
148
|
-
.map((token) => {
|
|
149
|
-
const value = JSON.stringify(token.value);
|
|
150
|
-
const name = token.name.replace("Default", "");
|
|
151
|
-
return `\t${name}: ${value}`;
|
|
152
|
-
})
|
|
153
|
-
.join(`,\n`);
|
|
154
|
-
return `export const common = {\n${common}\n}\nexport const light = {\n${light}\n}\nexport const dark = {\n${dark}\n}\n`;
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
StyleDictionary.registerFormat({
|
|
159
|
-
name: `custom/es6Variable`,
|
|
160
|
-
formatter: function ({ dictionary }) {
|
|
161
|
-
return dictionary.allTokens
|
|
162
|
-
.map((token) => {
|
|
163
|
-
const value = token.value;
|
|
164
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
165
|
-
if (token.attributes.appearance) {
|
|
166
|
-
return `export const ${name} = {
|
|
167
|
-
value: "${value}",
|
|
168
|
-
attributes: {
|
|
169
|
-
appearance: {
|
|
6
|
+
// Prefix for CSS variable names (e.g., --a2-border-radius-medium)
|
|
7
|
+
const CSS_VAR_PREFIX = "a2-";
|
|
8
|
+
const {
|
|
9
|
+
createPrimitiveConfig,
|
|
10
|
+
createThemeConfig,
|
|
11
|
+
createComponentConfig,
|
|
12
|
+
} = require("./src/utils/sd-build-configs");
|
|
13
|
+
|
|
14
|
+
// Use dynamic import for Style Dictionary v5 (ESM)
|
|
15
|
+
(async () => {
|
|
16
|
+
const StyleDictionary = (await import("style-dictionary")).default;
|
|
17
|
+
const { resolveReferences, usesReferences } =
|
|
18
|
+
await import("style-dictionary/utils");
|
|
19
|
+
|
|
20
|
+
// Register transforms and formats
|
|
21
|
+
registerTransforms(StyleDictionary);
|
|
22
|
+
registerFormats(
|
|
23
|
+
StyleDictionary,
|
|
24
|
+
usesReferences,
|
|
25
|
+
resolveReferences,
|
|
26
|
+
CSS_VAR_PREFIX,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Build primitive tokens
|
|
30
|
+
const sdPrimitive = new StyleDictionary(createPrimitiveConfig());
|
|
31
|
+
await sdPrimitive.buildAllPlatforms();
|
|
32
|
+
|
|
33
|
+
// Build theme tokens (includes primitives, excludes components)
|
|
34
|
+
const sdTheme = new StyleDictionary(createThemeConfig());
|
|
35
|
+
await sdTheme.buildAllPlatforms();
|
|
36
|
+
|
|
37
|
+
// Build component tokens
|
|
38
|
+
const sdComponent = new StyleDictionary(createComponentConfig());
|
|
39
|
+
await sdComponent.buildAllPlatforms();
|
|
40
|
+
|
|
41
|
+
// Post-build: Generate index files
|
|
42
|
+
const buildWebPath = path.join(process.cwd(), "build/web");
|
|
43
|
+
const buildCorePath = path.join(buildWebPath, "core");
|
|
44
|
+
const indexJsPath = path.join(buildWebPath, "index.js");
|
|
45
|
+
const coreIndexJsPath = path.join(buildCorePath, "index.js");
|
|
46
|
+
|
|
47
|
+
const coreIndexJsContent = `import * as primitive from './primitive';
|
|
48
|
+
import * as semantic from './semantic';
|
|
49
|
+
import * as component from './component';
|
|
50
|
+
const name = 'core';
|
|
51
|
+
export { primitive, semantic, component, name };
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const indexJsContent = `import * as core from './core';
|
|
55
|
+
export { core };
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
// Type definitions
|
|
59
|
+
const typesContent = `export type TokenObj = {
|
|
60
|
+
value: string;
|
|
61
|
+
extensions?: {
|
|
62
|
+
appearance?: {
|
|
170
63
|
dark: {
|
|
171
|
-
value:
|
|
172
|
-
}
|
|
64
|
+
value: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type Token = {
|
|
71
|
+
primitive: any;
|
|
72
|
+
semantic: any;
|
|
73
|
+
component: any;
|
|
74
|
+
name: string;
|
|
75
|
+
};
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const indexDtsContent = `export * from './types';
|
|
79
|
+
import * as core from './core';
|
|
80
|
+
export { core };
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
const coreIndexDtsContent = `export * from '../types';
|
|
84
|
+
import * as primitive from './primitive';
|
|
85
|
+
import * as semantic from './semantic';
|
|
86
|
+
import * as component from './component';
|
|
87
|
+
export declare const name: string;
|
|
88
|
+
export { primitive, semantic, component };
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
await fs.ensureDir(buildWebPath);
|
|
92
|
+
await fs.ensureDir(buildCorePath);
|
|
93
|
+
|
|
94
|
+
await fs.writeFile(coreIndexJsPath, coreIndexJsContent);
|
|
95
|
+
await fs.writeFile(indexJsPath, indexJsContent);
|
|
96
|
+
|
|
97
|
+
// Write type definition files
|
|
98
|
+
await fs.writeFile(path.join(buildWebPath, "types.d.ts"), typesContent);
|
|
99
|
+
await fs.writeFile(path.join(buildWebPath, "index.d.ts"), indexDtsContent);
|
|
100
|
+
await fs.writeFile(
|
|
101
|
+
path.join(buildCorePath, "index.d.ts"),
|
|
102
|
+
coreIndexDtsContent,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Generate .d.ts for each token file based on their .js exports
|
|
106
|
+
const tokenFiles = ["primitive", "semantic", "component"];
|
|
107
|
+
for (const file of tokenFiles) {
|
|
108
|
+
const jsPath = path.join(buildCorePath, `${file}.js`);
|
|
109
|
+
const jsContent = await fs.readFile(jsPath, "utf8");
|
|
110
|
+
|
|
111
|
+
// Extract export names
|
|
112
|
+
const exportRegex = /export const (\w+) = \{/g;
|
|
113
|
+
const exports = [];
|
|
114
|
+
let match;
|
|
115
|
+
while ((match = exportRegex.exec(jsContent)) !== null) {
|
|
116
|
+
exports.push(match[1]);
|
|
173
117
|
}
|
|
174
|
-
}
|
|
175
|
-
};`;
|
|
176
|
-
}
|
|
177
|
-
return `export const ${name} = { value: "${value}" };`;
|
|
178
|
-
})
|
|
179
|
-
.join(`\n`);
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const CSS_UTILS_PREFIXES = ["", "a2-"];
|
|
184
|
-
|
|
185
|
-
for (const prefix of CSS_UTILS_PREFIXES) {
|
|
186
|
-
StyleDictionary.registerFormat({
|
|
187
|
-
name: `custom/CSSUtils/${prefix}All`,
|
|
188
|
-
formatter: function ({ dictionary }) {
|
|
189
|
-
const colorTokens = dictionary.allTokens
|
|
190
|
-
.map((token) => {
|
|
191
|
-
const value = getVarValue(dictionary, token);
|
|
192
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
// name.startsWith("color") || // primitives
|
|
196
|
-
name.startsWith("status-color") ||
|
|
197
|
-
name.startsWith("foreground-color") ||
|
|
198
|
-
name.startsWith("background-color") ||
|
|
199
|
-
name.startsWith("overlay-color")
|
|
200
|
-
) {
|
|
201
|
-
const darkValue = getVarValue(dictionary, token, { isDark: true });
|
|
202
|
-
return generateColorClasses(name, value, { darkValue, prefix });
|
|
203
|
-
}
|
|
204
|
-
if (name.startsWith("border-color")) {
|
|
205
|
-
const darkValue = getVarValue(dictionary, token, { isDark: true });
|
|
206
|
-
return generateBorderClasses(name, value, { darkValue, prefix });
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
209
|
-
})
|
|
210
|
-
.flat()
|
|
211
|
-
.filter((t) => t != null)
|
|
212
|
-
.map((t) => `${t}`)
|
|
213
|
-
.sort((a, b) => a.localeCompare(b))
|
|
214
|
-
.join(`\n`);
|
|
215
|
-
const nonColorTokens = dictionary.allTokens
|
|
216
|
-
.map((token) => {
|
|
217
|
-
const value = getVarValue(dictionary, token);
|
|
218
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
219
|
-
|
|
220
|
-
if (name.startsWith("border")) {
|
|
221
|
-
return generateBorderClasses(name, value, { prefix });
|
|
222
|
-
}
|
|
223
|
-
if (name.startsWith("typography")) {
|
|
224
|
-
return generateFontClasses(name, value, { prefix });
|
|
225
|
-
}
|
|
226
|
-
if (name.startsWith("size")) {
|
|
227
|
-
return generateSpacingClasses(name, value, { prefix });
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
230
|
-
})
|
|
231
|
-
.flat()
|
|
232
|
-
.filter((t) => t != null)
|
|
233
|
-
.map((t) => `${t}`)
|
|
234
|
-
.sort((a, b) => a.localeCompare(b))
|
|
235
|
-
.join(`\n`);
|
|
236
118
|
|
|
237
|
-
|
|
238
|
-
.map((token) => {
|
|
239
|
-
const value = getVarValue(dictionary, token);
|
|
240
|
-
const name = `${token.name.replace("Default", "")}`;
|
|
119
|
+
const dtsContent = `import { TokenObj } from '../types';
|
|
241
120
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
if (name.startsWith("border-color")) {
|
|
251
|
-
return generateBorderClasses(name, value, { prefix });
|
|
252
|
-
}
|
|
253
|
-
return null;
|
|
254
|
-
})
|
|
255
|
-
.flat()
|
|
256
|
-
.filter((t) => t != null)
|
|
257
|
-
.map((t) => `${t}`)
|
|
258
|
-
.sort((a, b) => a.localeCompare(b))
|
|
259
|
-
.join(`\n`);
|
|
260
|
-
|
|
261
|
-
// Manually adding .sr-only
|
|
262
|
-
const withSr = nonColorTokens.concat(
|
|
263
|
-
"\n",
|
|
264
|
-
".sr-only {border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding-block: 0; padding-inline: 0; position: absolute; white-space: nowrap; width: 1px;}",
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
return `@layer starter, reset, base, state, application;
|
|
268
|
-
|
|
269
|
-
${withSr}
|
|
270
|
-
${colorFallbackTokens}
|
|
271
|
-
|
|
272
|
-
@supports (color: light-dark(#fff, #000)) {
|
|
273
|
-
${colorTokens.replaceAll("\n", "\n ")}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
@layer application {
|
|
277
|
-
${withSr.replaceAll("\n", "\n ")}
|
|
278
|
-
${colorFallbackTokens.replaceAll("\n", "\n ")}
|
|
279
|
-
|
|
280
|
-
@supports (color: light-dark(#fff, #000)) {
|
|
281
|
-
${colorTokens.replaceAll("\n", "\n ")}
|
|
282
|
-
}
|
|
283
|
-
}`;
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
StyleDictionary.registerFormat({
|
|
288
|
-
name: `custom/CSSUtils/${prefix}Borders`,
|
|
289
|
-
formatter: function ({ dictionary }) {
|
|
290
|
-
return cssUtilsFormatter(dictionary, generateBorderClasses, {
|
|
291
|
-
hasDark: true,
|
|
292
|
-
prefix,
|
|
293
|
-
});
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
StyleDictionary.registerFormat({
|
|
298
|
-
name: `custom/CSSUtils/${prefix}Colors`,
|
|
299
|
-
formatter: function ({ dictionary }) {
|
|
300
|
-
return cssUtilsFormatter(dictionary, generateColorClasses, {
|
|
301
|
-
hasDark: true,
|
|
302
|
-
prefix,
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
StyleDictionary.registerFormat({
|
|
308
|
-
name: `custom/CSSUtils/${prefix}Fonts`,
|
|
309
|
-
formatter: function ({ dictionary }) {
|
|
310
|
-
return cssUtilsFormatter(dictionary, generateFontClasses, { prefix });
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
StyleDictionary.registerFormat({
|
|
315
|
-
name: `custom/CSSUtils/${prefix}Spacing`,
|
|
316
|
-
formatter: function ({ dictionary }) {
|
|
317
|
-
return cssUtilsFormatter(dictionary, generateSpacingClasses, { prefix });
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const getDirectories = (source) =>
|
|
323
|
-
fs
|
|
324
|
-
.readdirSync(source, { withFileTypes: true })
|
|
325
|
-
.filter((dirent) => dirent.isDirectory())
|
|
326
|
-
.map((dirent) => dirent.name);
|
|
327
|
-
|
|
328
|
-
const themes = getDirectories(`src/theme`);
|
|
329
|
-
|
|
330
|
-
themes.forEach((theme) => {
|
|
331
|
-
StyleDictionary.extend({
|
|
332
|
-
source: [`src/theme/${theme}/*.js`, `src/theme/${theme}/component/*.js`],
|
|
333
|
-
include: ["src/global/primitive/*.js"],
|
|
334
|
-
platforms: {
|
|
335
|
-
css: {
|
|
336
|
-
transformGroup: "css",
|
|
337
|
-
buildPath: `build/web/${theme}/css-utils/`,
|
|
338
|
-
files: CSS_UTILS_PREFIXES.flatMap((prefix) => [
|
|
339
|
-
{
|
|
340
|
-
destination: `${prefix}utils.css`,
|
|
341
|
-
format: `custom/CSSUtils/${prefix}All`,
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
destination: `${prefix}border.css`,
|
|
345
|
-
format: `custom/CSSUtils/${prefix}Borders`,
|
|
346
|
-
filter: function (token) {
|
|
347
|
-
return token.filePath.includes("border");
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
destination: `${prefix}color.css`,
|
|
352
|
-
format: `custom/CSSUtils/${prefix}Colors`,
|
|
353
|
-
filter: function (token) {
|
|
354
|
-
return (
|
|
355
|
-
token.filePath.includes("primitive/color") ||
|
|
356
|
-
token.name.includes("color")
|
|
357
|
-
);
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
destination: `${prefix}font.css`,
|
|
362
|
-
format: `custom/CSSUtils/${prefix}Fonts`,
|
|
363
|
-
filter: function (token) {
|
|
364
|
-
return (
|
|
365
|
-
token.filePath.includes("primitive/font") ||
|
|
366
|
-
token.filePath.includes("typography")
|
|
367
|
-
);
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
destination: `${prefix}spacing.css`,
|
|
372
|
-
format: `custom/CSSUtils/${prefix}Spacing`,
|
|
373
|
-
filter: function (token) {
|
|
374
|
-
return token.filePath.startsWith("src/global/primitive/size");
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
]),
|
|
378
|
-
},
|
|
379
|
-
scss: {
|
|
380
|
-
transformGroup: "scss",
|
|
381
|
-
buildPath: `build/web/${theme}/`,
|
|
382
|
-
files: [
|
|
383
|
-
{
|
|
384
|
-
destination: "primitive.scss",
|
|
385
|
-
format: "custom/SCSSVariable",
|
|
386
|
-
filter: function (token) {
|
|
387
|
-
return token.filePath.startsWith("src/global/primitive");
|
|
388
|
-
},
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
destination: "primitive-variables.scss",
|
|
392
|
-
format: "custom/primitive-variables",
|
|
393
|
-
filter: function (token) {
|
|
394
|
-
return token.filePath.startsWith("src/global/primitive");
|
|
395
|
-
},
|
|
396
|
-
},
|
|
397
|
-
{
|
|
398
|
-
destination: "semantic.scss",
|
|
399
|
-
format: "custom/SCSSVariable",
|
|
400
|
-
filter: function (token) {
|
|
401
|
-
return (
|
|
402
|
-
token.filePath.startsWith(`src/theme/${theme}`) &&
|
|
403
|
-
!token.filePath.startsWith(`src/theme/${theme}/component`)
|
|
404
|
-
);
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
destination: "semantic-variables.scss",
|
|
409
|
-
format: "custom/variables-map",
|
|
410
|
-
filter: function (token) {
|
|
411
|
-
return (
|
|
412
|
-
token.filePath.startsWith(`src/theme/${theme}`) &&
|
|
413
|
-
!token.filePath.startsWith(`src/theme/${theme}/component`)
|
|
414
|
-
);
|
|
415
|
-
},
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
destination: "component.scss",
|
|
419
|
-
format: "custom/SCSSVariable",
|
|
420
|
-
filter: function (token) {
|
|
421
|
-
return token.filePath.startsWith(`src/theme/${theme}/component`);
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
destination: "component-variables.scss",
|
|
426
|
-
format: "custom/variables-map",
|
|
427
|
-
filter: function (token) {
|
|
428
|
-
return token.filePath.startsWith(`src/theme/${theme}/component`);
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
],
|
|
432
|
-
},
|
|
433
|
-
tsLight: {
|
|
434
|
-
transformGroup: "js",
|
|
435
|
-
buildPath: `build/web/${theme}/`,
|
|
436
|
-
files: [
|
|
437
|
-
{
|
|
438
|
-
format: "custom/es6Variable",
|
|
439
|
-
destination: "primitive.js",
|
|
440
|
-
filter: function (token) {
|
|
441
|
-
return token.filePath.startsWith("src/global/primitive");
|
|
442
|
-
},
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
format: "custom/es6",
|
|
446
|
-
destination: "raw.js",
|
|
447
|
-
filter: function (token) {
|
|
448
|
-
return (
|
|
449
|
-
token.filePath.startsWith(`src/theme/${theme}`) &&
|
|
450
|
-
!token.filePath.startsWith(`src/theme/${theme}/component`)
|
|
451
|
-
);
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
format: "custom/es6Variable",
|
|
456
|
-
destination: "semantic.js",
|
|
457
|
-
filter: function (token) {
|
|
458
|
-
return (
|
|
459
|
-
token.filePath.startsWith(`src/theme/${theme}`) &&
|
|
460
|
-
!token.filePath.startsWith(`src/theme/${theme}/component`)
|
|
461
|
-
);
|
|
462
|
-
},
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
format: "custom/es6Variable",
|
|
466
|
-
destination: "component.js",
|
|
467
|
-
filter: function (token) {
|
|
468
|
-
return token.filePath.startsWith(`src/theme/${theme}/component`);
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
],
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
}).buildAllPlatforms();
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
console.log("\n==============================================");
|
|
478
|
-
console.log("Building index files...\n");
|
|
479
|
-
const mainJS = fs.createWriteStream(`build/web/index.js`);
|
|
480
|
-
|
|
481
|
-
const mainType = fs.createWriteStream(`build/web/index.d.ts`);
|
|
482
|
-
mainType.write(`import Token from '../../type/types';\n`);
|
|
483
|
-
|
|
484
|
-
themes.forEach((theme) => {
|
|
485
|
-
const indexJS = fs.createWriteStream(`build/web/${theme}/index.js`);
|
|
486
|
-
indexJS.write(`import * as semantic from './semantic';\n`);
|
|
487
|
-
indexJS.write(`import * as primitive from './primitive';\n`);
|
|
488
|
-
indexJS.write(`import * as component from './component';\n`);
|
|
489
|
-
indexJS.write(`const name = '${theme}';\n`);
|
|
490
|
-
indexJS.write(`export { primitive, semantic, component, name };\n`);
|
|
491
|
-
indexJS.end();
|
|
492
|
-
mainType.write(`declare const ${theme}: Token;\n`);
|
|
493
|
-
mainJS.write(`import * as ${theme} from './${theme}';\n`);
|
|
121
|
+
${exports.map((name) => `export declare const ${name}: TokenObj;`).join("\n")}
|
|
122
|
+
`;
|
|
123
|
+
await fs.writeFile(path.join(buildCorePath, `${file}.d.ts`), dtsContent);
|
|
124
|
+
}
|
|
125
|
+
})().catch((error) => {
|
|
126
|
+
console.error("Error building tokens:", error);
|
|
127
|
+
process.exit(1);
|
|
494
128
|
});
|
|
495
|
-
|
|
496
|
-
mainType.write(`export { Token }\n`);
|
|
497
|
-
mainType.write(`export { ${themes.join(", ")} }\n`);
|
|
498
|
-
mainType.end();
|
|
499
|
-
|
|
500
|
-
mainJS.write(`export * as Token from '../../type/types';\n`);
|
|
501
|
-
mainJS.write(`export { ${themes.join(", ")} };\n`);
|
|
502
|
-
mainJS.end();
|
|
503
|
-
console.log(`Index built!`);
|
|
504
|
-
console.log("==============================================\n");
|
package/eslint.config.mjs
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import baseConfig from "../../eslint.base.config.mjs";
|
|
2
2
|
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
|
3
3
|
|
|
4
|
-
export default [
|
|
4
|
+
export default [
|
|
5
|
+
...baseConfig,
|
|
6
|
+
eslintConfigPrettier,
|
|
7
|
+
{
|
|
8
|
+
// Allow require() in Node.js utility scripts
|
|
9
|
+
files: ["src/utils/**/*.js", "config.js"],
|
|
10
|
+
rules: {
|
|
11
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/hammer-token",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/web/index.js",
|
|
6
6
|
"types": "build/web/index.d.ts",
|
|
@@ -11,15 +11,25 @@
|
|
|
11
11
|
"commander": "^12.1.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
14
15
|
"fs-extra": "^11.2.0",
|
|
15
|
-
"style-dictionary": "^
|
|
16
|
-
"tinycolor2": "^1.6.0"
|
|
16
|
+
"style-dictionary": "^5.1.1",
|
|
17
|
+
"tinycolor2": "^1.6.0",
|
|
18
|
+
"typescript": "^5.0.0",
|
|
19
|
+
"vitest": "^3.2.4"
|
|
17
20
|
},
|
|
18
21
|
"scripts": {
|
|
19
|
-
"build": "node ./config.js",
|
|
22
|
+
"build": "pnpm clean && node ./config.js",
|
|
20
23
|
"dev": "pnpm build && chokidar \"./src\" -c \"pnpm build\"",
|
|
21
24
|
"clean": "rimraf build .turbo",
|
|
22
25
|
"lint": "eslint .",
|
|
23
|
-
"
|
|
26
|
+
"test": "vitest run --coverage.enabled=true --coverage.reporter=text",
|
|
27
|
+
"nuke": "pnpm clean && rimraf node_modules",
|
|
28
|
+
"figma:sync": "node src/utils/figma/sync-main.js sync",
|
|
29
|
+
"figma:sync:file": "node src/utils/figma/sync-main.js file",
|
|
30
|
+
"figma:test": "node src/utils/figma/sync-main.js test",
|
|
31
|
+
"figma:test:file": "node src/utils/figma/sync-main.js test:file",
|
|
32
|
+
"figma:validate": "node src/utils/figma/sync-main.js validate",
|
|
33
|
+
"figma:get-token": "node src/utils/figma/get-token.js"
|
|
24
34
|
}
|
|
25
35
|
}
|