@servicetitan/hammer-token 0.0.0-themeprovider-refactor.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 (37) hide show
  1. package/.turbo/turbo-build.log +28 -0
  2. package/.turbo/turbo-lint.log +4 -0
  3. package/CHANGELOG.md +260 -0
  4. package/build/web/core/css-utils/border.css +13 -0
  5. package/build/web/core/css-utils/color.css +89 -0
  6. package/build/web/core/css-utils/font.css +21 -0
  7. package/build/web/core/css-utils/spacing.css +204 -0
  8. package/build/web/core/css-utils/utils.css +322 -0
  9. package/build/web/core/index.js +4 -0
  10. package/build/web/core/primitive.js +115 -0
  11. package/build/web/core/primitive.scss +115 -0
  12. package/build/web/core/raw.js +125 -0
  13. package/build/web/core/semantic-variables.scss +150 -0
  14. package/build/web/core/semantic.js +463 -0
  15. package/build/web/core/semantic.scss +76 -0
  16. package/build/web/index.d.ts +4 -0
  17. package/build/web/index.js +3 -0
  18. package/config.js +345 -0
  19. package/package.json +25 -0
  20. package/src/global/primitive/breakpoint.json +19 -0
  21. package/src/global/primitive/color.json +231 -0
  22. package/src/global/primitive/duration.json +16 -0
  23. package/src/global/primitive/font.json +60 -0
  24. package/src/global/primitive/size.json +55 -0
  25. package/src/global/primitive/transition.json +16 -0
  26. package/src/theme/core/background.json +144 -0
  27. package/src/theme/core/border.json +84 -0
  28. package/src/theme/core/focus.json +31 -0
  29. package/src/theme/core/foreground.json +88 -0
  30. package/src/theme/core/overlay.json +134 -0
  31. package/src/theme/core/shadow.json +25 -0
  32. package/src/theme/core/status.json +46 -0
  33. package/src/theme/core/typography.json +79 -0
  34. package/src/utils/copy-css-utils-cli.js +49 -0
  35. package/src/utils/css-utils-format-utils.js +185 -0
  36. package/test.txt +1 -0
  37. package/type/types.ts +215 -0
package/config.js ADDED
@@ -0,0 +1,345 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const StyleDictionary = require("style-dictionary");
3
+ const fs = require("fs-extra");
4
+ const {
5
+ cssUtilsFormatter,
6
+ getVarValue,
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
+ let value = token.value;
19
+ let name = `${token.name.replace("-default", "")}`;
20
+ if (token.attributes.appearance) {
21
+ return `$${name}: var(--${name}, ${value});`;
22
+ }
23
+ return `$${name}: ${value};`;
24
+ })
25
+ .join(`\n`);
26
+ },
27
+ });
28
+
29
+ StyleDictionary.registerFormat({
30
+ name: `custom/semantic-variables`,
31
+ formatter: function ({ dictionary }) {
32
+ const light = dictionary.allTokens
33
+ .filter((token) => !token.name.includes("font-family"))
34
+ .map((token) => {
35
+ let value = token.value;
36
+ let name = `${token.name.replace("-default", "")}`;
37
+ if (token.attributes.appearance) {
38
+ return ` ${name}: ${value},`;
39
+ }
40
+ return ` ${name}: ${value},`;
41
+ })
42
+ .join(`\n`);
43
+ const dark = dictionary.allTokens
44
+ .filter((token) => !token.name.includes("font-family"))
45
+ .map((token) => {
46
+ let value = token.value;
47
+ let name = `${token.name.replace("-default", "")}`;
48
+ if (token.attributes.appearance) {
49
+ return ` ${name}: ${token.attributes.appearance.dark.value},`;
50
+ }
51
+ return ` ${name}: ${value},`;
52
+ })
53
+ .join(`\n`);
54
+
55
+ return [`$light: (`, light, `);`, `$dark: (`, dark, `);`].join(`\n`);
56
+ },
57
+ });
58
+
59
+ // StyleDictionary.registerFormat({
60
+ // name: `custom/semantic-dark`,
61
+ // formatter: function ({ dictionary }) {
62
+ // const variables = dictionary.allTokens
63
+ // .filter((token) => !token.name.includes("font-family"))
64
+ // .map((token) => {
65
+ // let value = token.value;
66
+ // let name = `${token.name.replace("-default", "")}`;
67
+ // if (token.attributes.appearance) {
68
+ // return ` ${name}: ${token.attributes.appearance.dark.value},`;
69
+ // }
70
+ // return ` ${name}: ${value},`;
71
+ // })
72
+ // .join(`\n`);
73
+ // return [`$variables: (`, variables, `);`].join(`\n`);
74
+ // },
75
+ // });
76
+
77
+ StyleDictionary.registerFormat({
78
+ name: `custom/es6`,
79
+ formatter: function ({ dictionary }) {
80
+ const light = dictionary.allTokens
81
+ .filter((token) => !!token.attributes.appearance)
82
+ .map((token) => {
83
+ let value = JSON.stringify(token.value);
84
+ let name = token.name.replace("Default", "");
85
+ return `\t${name}: ${value}`;
86
+ })
87
+ .join(`,\n`);
88
+ const dark = dictionary.allTokens
89
+ .filter((token) => !!token.attributes.appearance)
90
+ .map((token) => {
91
+ let value = JSON.stringify(token.attributes.appearance.dark.value);
92
+ let name = token.name.replace("Default", "");
93
+ return `\t${name}: ${value}`;
94
+ })
95
+ .join(`,\n`);
96
+ const common = dictionary.allTokens
97
+ .filter((token) => !token.attributes.appearance)
98
+ .map((token) => {
99
+ let value = JSON.stringify(token.value);
100
+ let name = token.name.replace("Default", "");
101
+ return `\t${name}: ${value}`;
102
+ })
103
+ .join(`,\n`);
104
+ return `export const common = {\n${common}\n}\nexport const light = {\n${light}\n}\nexport const dark = {\n${dark}\n}\n`;
105
+ },
106
+ });
107
+
108
+ StyleDictionary.registerFormat({
109
+ name: `custom/es6Variable`,
110
+ formatter: function ({ dictionary }) {
111
+ return dictionary.allTokens
112
+ .map((token) => {
113
+ let value = token.value;
114
+ let name = `${token.name.replace("Default", "")}`;
115
+ if (token.attributes.appearance) {
116
+ return `export const ${name} = {
117
+ value: "${value}",
118
+ attributes: {
119
+ appearance: {
120
+ dark: {
121
+ value: "${token.attributes.appearance.dark.value}"
122
+ }
123
+ }
124
+ }
125
+ };`;
126
+ }
127
+ return `export const ${name} = { value: "${value}" };`;
128
+ })
129
+ .join(`\n`);
130
+ },
131
+ });
132
+
133
+ StyleDictionary.registerFormat({
134
+ name: `custom/CSSUtils/All`,
135
+ formatter: function ({ dictionary }) {
136
+ return dictionary.allTokens
137
+ .map((token) => {
138
+ let value = getVarValue(dictionary, token);
139
+ let name = `${token.name.replace("Default", "")}`;
140
+
141
+ if (
142
+ // name.startsWith("color") || // primitives
143
+ name.startsWith("status-color") ||
144
+ name.startsWith("foreground-color") ||
145
+ name.startsWith("background-color") ||
146
+ name.startsWith("overlay-color")
147
+ ) {
148
+ let darkValue = getVarValue(dictionary, token, true);
149
+ return generateColorClasses(name, value, darkValue);
150
+ }
151
+ if (name.startsWith("border")) {
152
+ return generateBorderClasses(name, value);
153
+ }
154
+ if (name.startsWith("typography")) {
155
+ return generateFontClasses(name, value);
156
+ }
157
+ if (name.startsWith("size")) {
158
+ return generateSpacingClasses(name, value);
159
+ }
160
+ return null;
161
+ })
162
+ .flat()
163
+ .filter((t) => t != null)
164
+ .map((t) => `${t}`)
165
+ .sort((a, b) => a.localeCompare(b))
166
+ .join(`\n`);
167
+ },
168
+ });
169
+
170
+ StyleDictionary.registerFormat({
171
+ name: `custom/CSSUtils/Borders`,
172
+ formatter: function ({ dictionary }) {
173
+ return cssUtilsFormatter(dictionary, generateBorderClasses);
174
+ },
175
+ });
176
+
177
+ StyleDictionary.registerFormat({
178
+ name: `custom/CSSUtils/Colors`,
179
+ formatter: function ({ dictionary }) {
180
+ return cssUtilsFormatter(dictionary, generateColorClasses, true);
181
+ },
182
+ });
183
+
184
+ StyleDictionary.registerFormat({
185
+ name: `custom/CSSUtils/Fonts`,
186
+ formatter: function ({ dictionary }) {
187
+ return cssUtilsFormatter(dictionary, generateFontClasses);
188
+ },
189
+ });
190
+
191
+ StyleDictionary.registerFormat({
192
+ name: `custom/CSSUtils/Spacing`,
193
+ formatter: function ({ dictionary }) {
194
+ return cssUtilsFormatter(dictionary, generateSpacingClasses);
195
+ },
196
+ });
197
+
198
+ const getDirectories = (source) =>
199
+ fs
200
+ .readdirSync(source, { withFileTypes: true })
201
+ .filter((dirent) => dirent.isDirectory())
202
+ .map((dirent) => dirent.name);
203
+
204
+ const themes = getDirectories(`src/theme`);
205
+
206
+ themes.forEach((theme) => {
207
+ StyleDictionary.extend({
208
+ source: [`src/theme/${theme}/*.json`],
209
+ include: ["src/global/primitive/*.json"],
210
+ platforms: {
211
+ css: {
212
+ transformGroup: "css",
213
+ buildPath: `build/web/${theme}/css-utils/`,
214
+ files: [
215
+ {
216
+ destination: "utils.css",
217
+ format: "custom/CSSUtils/All",
218
+ },
219
+ {
220
+ destination: "border.css",
221
+ format: "custom/CSSUtils/Borders",
222
+ filter: function (token) {
223
+ return (
224
+ token.filePath.includes("border") ||
225
+ // referenced tokens
226
+ token.filePath.includes("primitive/color") ||
227
+ token.filePath.includes("primitive/size") ||
228
+ token.filePath.includes("status")
229
+ );
230
+ },
231
+ },
232
+ {
233
+ destination: "color.css",
234
+ format: "custom/CSSUtils/Colors",
235
+ filter: function (token) {
236
+ return (
237
+ token.filePath.includes("primitive/color") ||
238
+ token.name.includes("color")
239
+ );
240
+ },
241
+ },
242
+ {
243
+ destination: "font.css",
244
+ format: "custom/CSSUtils/Fonts",
245
+ filter: function (token) {
246
+ return (
247
+ token.filePath.includes("primitive/font") ||
248
+ token.filePath.includes("typography")
249
+ );
250
+ },
251
+ },
252
+ {
253
+ destination: "spacing.css",
254
+ format: "custom/CSSUtils/Spacing",
255
+ filter: function (token) {
256
+ return token.filePath.includes("primitive/size");
257
+ },
258
+ },
259
+ ],
260
+ },
261
+ scss: {
262
+ transformGroup: "scss",
263
+ buildPath: `build/web/${theme}/`,
264
+ files: [
265
+ {
266
+ destination: "primitive.scss",
267
+ format: "custom/SCSSVariable",
268
+ filter: function (token) {
269
+ return token.filePath.startsWith("src/global/primitive");
270
+ },
271
+ },
272
+ {
273
+ destination: "semantic.scss",
274
+ format: "custom/SCSSVariable",
275
+ filter: function (token) {
276
+ return token.filePath.startsWith(`src/theme/${theme}`);
277
+ },
278
+ },
279
+ {
280
+ destination: "semantic-variables.scss",
281
+ format: "custom/semantic-variables",
282
+ filter: function (token) {
283
+ return token.filePath.startsWith(`src/theme/${theme}`);
284
+ },
285
+ },
286
+ ],
287
+ },
288
+ tsLight: {
289
+ transformGroup: "js",
290
+ buildPath: `build/web/${theme}/`,
291
+ files: [
292
+ {
293
+ format: "custom/es6Variable",
294
+ destination: "primitive.js",
295
+ filter: function (token) {
296
+ return token.filePath.startsWith("src/global/primitive");
297
+ },
298
+ },
299
+ {
300
+ format: "custom/es6",
301
+ destination: "raw.js",
302
+ filter: function (token) {
303
+ return token.filePath.startsWith(`src/theme/${theme}`);
304
+ },
305
+ },
306
+ {
307
+ format: "custom/es6Variable",
308
+ destination: "semantic.js",
309
+ filter: function (token) {
310
+ return token.filePath.startsWith(`src/theme/${theme}`);
311
+ },
312
+ },
313
+ ],
314
+ },
315
+ },
316
+ }).buildAllPlatforms();
317
+ });
318
+
319
+ console.log("\n==============================================");
320
+ console.log("Building index files...\n");
321
+ const mainJS = fs.createWriteStream(`build/web/index.js`);
322
+
323
+ const mainType = fs.createWriteStream(`build/web/index.d.ts`);
324
+ mainType.write(`import Token from '../../type/types';\n`);
325
+
326
+ themes.forEach((theme) => {
327
+ const indexJS = fs.createWriteStream(`build/web/${theme}/index.js`);
328
+ indexJS.write(`import * as semantic from './semantic';\n`);
329
+ indexJS.write(`import * as primitive from './primitive';\n`);
330
+ indexJS.write(`const name = '${theme}';\n`);
331
+ indexJS.write(`export { primitive, semantic, name };\n`);
332
+ indexJS.end();
333
+ mainType.write(`declare const ${theme}: Token;\n`);
334
+ mainJS.write(`import * as ${theme} from './${theme}';\n`);
335
+ });
336
+
337
+ mainType.write(`export { Token }\n`);
338
+ mainType.write(`export { ${themes.join(", ")} }\n`);
339
+ mainType.end();
340
+
341
+ mainJS.write(`export * as Token from '../../type/types';\n`);
342
+ mainJS.write(`export { ${themes.join(", ")} };\n`);
343
+ mainJS.end();
344
+ console.log(`Index built!`);
345
+ console.log("==============================================\n");
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@servicetitan/hammer-token",
3
+ "version": "0.0.0-themeprovider-refactor.1",
4
+ "description": "",
5
+ "main": "build/web/index.js",
6
+ "types": "build/web/index.d.ts",
7
+ "bin": {
8
+ "hammer-token": "./src/utils/copy-css-utils-cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "node ./config.js",
12
+ "dev": "pnpm build && chokidar \"./src\" -c \"pnpm build\"",
13
+ "clean": "rimraf build .turbo",
14
+ "lint": "eslint",
15
+ "nuke": "pnpm clean && rimraf node_modules"
16
+ },
17
+ "optionalDependencies": {
18
+ "commander": "^12.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "fs-extra": "^11.2.0",
22
+ "style-dictionary": "^3"
23
+ },
24
+ "gitHead": "373bb117186c3e3a3c41e44bcabd26aaf27fc414"
25
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "breakpoint": {
3
+ "sm": {
4
+ "value": "640px"
5
+ },
6
+ "md": {
7
+ "value": "768px"
8
+ },
9
+ "lg": {
10
+ "value": "1024px"
11
+ },
12
+ "xl": {
13
+ "value": "1280px"
14
+ },
15
+ "xxl": {
16
+ "value": "1536px"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,231 @@
1
+ {
2
+ "color": {
3
+ "blue": {
4
+ "100": {
5
+ "value": "#E0F2FF"
6
+ },
7
+ "200": {
8
+ "value": "#B5DEFF"
9
+ },
10
+ "300": {
11
+ "value": "#78BBFA"
12
+ },
13
+ "400": {
14
+ "value": "#3892F3"
15
+ },
16
+ "500": {
17
+ "value": "#0265DC"
18
+ },
19
+ "600": {
20
+ "value": "#004491"
21
+ }
22
+ },
23
+ "neutral": {
24
+ "0": {
25
+ "value": "#ffffff"
26
+ },
27
+ "10": {
28
+ "value": "#fcfcfc"
29
+ },
30
+ "20": {
31
+ "value": "#fafafa"
32
+ },
33
+ "30": {
34
+ "value": "#f7f7f7"
35
+ },
36
+ "40": {
37
+ "value": "#f5f5f5"
38
+ },
39
+ "50": {
40
+ "value": "#eeeeee"
41
+ },
42
+ "60": {
43
+ "value": "#dfe0e1"
44
+ },
45
+ "70": {
46
+ "value": "#bcbcbd"
47
+ },
48
+ "80": {
49
+ "value": "#949596"
50
+ },
51
+ "90": {
52
+ "value": "#737475"
53
+ },
54
+ "100": {
55
+ "value": "#606162"
56
+ },
57
+ "200": {
58
+ "value": "#444445"
59
+ },
60
+ "300": {
61
+ "value": "#2d2e31"
62
+ },
63
+ "400": {
64
+ "value": "#141414"
65
+ },
66
+ "500": {
67
+ "value": "#040404"
68
+ }
69
+ },
70
+ "blue-grey": {
71
+ "100": {
72
+ "value": "#eaeff2"
73
+ },
74
+ "200": {
75
+ "value": "#d0d8dd"
76
+ },
77
+ "300": {
78
+ "value": "#b4c1c8"
79
+ },
80
+ "400": {
81
+ "value": "#8c9ca5"
82
+ },
83
+ "500": {
84
+ "value": "#6a7a85"
85
+ },
86
+ "600": {
87
+ "value": "#576671"
88
+ }
89
+ },
90
+ "orange": {
91
+ "100": {
92
+ "value": "#ffeccc"
93
+ },
94
+ "200": {
95
+ "value": "#fdd291"
96
+ },
97
+ "300": {
98
+ "value": "#ffa037"
99
+ },
100
+ "400": {
101
+ "value": "#e46f00"
102
+ },
103
+ "500": {
104
+ "value": "#b14c00"
105
+ },
106
+ "600": {
107
+ "value": "#7a2f00"
108
+ }
109
+ },
110
+ "yellow": {
111
+ "100": {
112
+ "value": "#fff9e2"
113
+ },
114
+ "200": {
115
+ "value": "#fff0b1"
116
+ },
117
+ "300": {
118
+ "value": "#ffe278"
119
+ },
120
+ "400": {
121
+ "value": "#ffc902"
122
+ },
123
+ "500": {
124
+ "value": "#ffbe00"
125
+ },
126
+ "600": {
127
+ "value": "#de9500"
128
+ }
129
+ },
130
+ "green": {
131
+ "100": {
132
+ "value": "#CEF8E0"
133
+ },
134
+ "200": {
135
+ "value": "#89ECBC"
136
+ },
137
+ "300": {
138
+ "value": "#49CC93"
139
+ },
140
+ "400": {
141
+ "value": "#15A46E"
142
+ },
143
+ "500": {
144
+ "value": "#007A4D"
145
+ },
146
+ "600": {
147
+ "value": "#005132"
148
+ }
149
+ },
150
+ "cyan": {
151
+ "100": {
152
+ "value": "#e3fcff"
153
+ },
154
+ "200": {
155
+ "value": "#b1f3fa"
156
+ },
157
+ "300": {
158
+ "value": "#13ceea"
159
+ },
160
+ "400": {
161
+ "value": "#08bfdf"
162
+ },
163
+ "500": {
164
+ "value": "#0ca5c0"
165
+ },
166
+ "600": {
167
+ "value": "#038299"
168
+ }
169
+ },
170
+ "purple": {
171
+ "100": {
172
+ "value": "#f1edff"
173
+ },
174
+ "200": {
175
+ "value": "#c1b6f2"
176
+ },
177
+ "300": {
178
+ "value": "#8772e5"
179
+ },
180
+ "400": {
181
+ "value": "#6954c0"
182
+ },
183
+ "500": {
184
+ "value": "#4f3a9e"
185
+ },
186
+ "600": {
187
+ "value": "#422799"
188
+ }
189
+ },
190
+ "red": {
191
+ "100": {
192
+ "value": "#ffece9"
193
+ },
194
+ "200": {
195
+ "value": "#ffb2a0"
196
+ },
197
+ "300": {
198
+ "value": "#ff745f"
199
+ },
200
+ "400": {
201
+ "value": "#f94d32"
202
+ },
203
+ "500": {
204
+ "value": "#e13212"
205
+ },
206
+ "600": {
207
+ "value": "#bf2a00"
208
+ }
209
+ },
210
+ "magenta": {
211
+ "100": {
212
+ "value": "#fbeaf5"
213
+ },
214
+ "200": {
215
+ "value": "#faafe2"
216
+ },
217
+ "300": {
218
+ "value": "#d949a9"
219
+ },
220
+ "400": {
221
+ "value": "#b52d88"
222
+ },
223
+ "500": {
224
+ "value": "#982071"
225
+ },
226
+ "600": {
227
+ "value": "#7d165b"
228
+ }
229
+ }
230
+ }
231
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "duration": {
3
+ "default": {
4
+ "value": "200ms"
5
+ },
6
+ "instant": {
7
+ "value": "0ms"
8
+ },
9
+ "fast": {
10
+ "value": "100ms"
11
+ },
12
+ "slow": {
13
+ "value": "300ms"
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "font": {
3
+ "family": {
4
+ "base": {
5
+ "value": "'Nunito Sans', sans-serif"
6
+ },
7
+ "display": {
8
+ "value": "'Sofia Pro', SofiaPro, sans-serif"
9
+ }
10
+ },
11
+ "line-height": {
12
+ "base": {
13
+ "value": 1.5
14
+ },
15
+ "display": {
16
+ "value": 1.25
17
+ }
18
+ },
19
+ "weight": {
20
+ "normal": {
21
+ "value": 400
22
+ },
23
+ "semibold": {
24
+ "value": 600
25
+ },
26
+ "bold": {
27
+ "value": 700
28
+ }
29
+ },
30
+ "size": {
31
+ "100": {
32
+ "value": "0.625rem"
33
+ },
34
+ "200": {
35
+ "value": "0.75rem"
36
+ },
37
+ "300": {
38
+ "value": "0.875rem"
39
+ },
40
+ "400": {
41
+ "value": "1rem"
42
+ },
43
+ "500": {
44
+ "value": "1.25rem"
45
+ },
46
+ "600": {
47
+ "value": "1.5rem"
48
+ },
49
+ "700": {
50
+ "value": "1.75rem"
51
+ },
52
+ "800": {
53
+ "value": "2rem"
54
+ },
55
+ "900": {
56
+ "value": "2.25rem"
57
+ }
58
+ }
59
+ }
60
+ }