@servicetitan/hammer-token 2.3.0 → 2.5.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/config.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
1
+ /* eslint-disable @typescript-eslint/no-require-imports */
2
2
  const StyleDictionary = require("style-dictionary");
3
3
  const fs = require("fs-extra");
4
4
  const {
@@ -15,8 +15,8 @@ StyleDictionary.registerFormat({
15
15
  formatter: function ({ dictionary }) {
16
16
  return dictionary.allTokens
17
17
  .map((token) => {
18
- let value = token.value;
19
- let name = `${token.name.replace("-default", "")}`;
18
+ const value = token.value;
19
+ const name = `${token.name.replace("-default", "")}`;
20
20
  if (token.name.includes("font-family"))
21
21
  return `$${name}: var(--${name}, ${value});`;
22
22
  if (token.attributes.appearance) {
@@ -50,8 +50,8 @@ StyleDictionary.registerFormat({
50
50
  return isColor;
51
51
  })
52
52
  .map((token) => {
53
- let value = token.value;
54
- let name = `${token.name.replace("-default", "")}`;
53
+ const value = token.value;
54
+ const name = `${token.name.replace("-default", "")}`;
55
55
  return ` ${name}: ${value},`;
56
56
  })
57
57
  .join(`\n`);
@@ -67,8 +67,8 @@ StyleDictionary.registerFormat({
67
67
  return isColor;
68
68
  })
69
69
  .map((token) => {
70
- let value = token.value;
71
- let name = `${token.name.replace("-default", "")}`;
70
+ const value = token.value;
71
+ const name = `${token.name.replace("-default", "")}`;
72
72
  if (token.attributes.appearance) {
73
73
  return ` ${name}: ${token.attributes.appearance.dark.value},`;
74
74
  }
@@ -87,8 +87,8 @@ StyleDictionary.registerFormat({
87
87
  return !isColor;
88
88
  })
89
89
  .map((token) => {
90
- let value = token.value;
91
- let name = `${token.name.replace("-default", "")}`;
90
+ const value = token.value;
91
+ const name = `${token.name.replace("-default", "")}`;
92
92
  if (token.name.includes("font-family")) return ` ${name}: "${value}",`;
93
93
  return ` ${name}: ${value},`;
94
94
  })
@@ -113,8 +113,8 @@ StyleDictionary.registerFormat({
113
113
  formatter: function ({ dictionary }) {
114
114
  const vars = dictionary.allTokens
115
115
  .map((token) => {
116
- let value = token.value;
117
- let name = `${token.name.replace("-default", "")}`;
116
+ const value = token.value;
117
+ const name = `${token.name.replace("-default", "")}`;
118
118
  if (token.name.includes("font-family")) return ` ${name}: "${value}",`;
119
119
  return ` ${name}: ${value},`;
120
120
  })
@@ -130,24 +130,24 @@ StyleDictionary.registerFormat({
130
130
  const light = dictionary.allTokens
131
131
  .filter((token) => !!token.attributes.appearance)
132
132
  .map((token) => {
133
- let value = JSON.stringify(token.value);
134
- let name = token.name.replace("Default", "");
133
+ const value = JSON.stringify(token.value);
134
+ const name = token.name.replace("Default", "");
135
135
  return `\t${name}: ${value}`;
136
136
  })
137
137
  .join(`,\n`);
138
138
  const dark = dictionary.allTokens
139
139
  .filter((token) => !!token.attributes.appearance)
140
140
  .map((token) => {
141
- let value = JSON.stringify(token.attributes.appearance.dark.value);
142
- let name = token.name.replace("Default", "");
141
+ const value = JSON.stringify(token.attributes.appearance.dark.value);
142
+ const name = token.name.replace("Default", "");
143
143
  return `\t${name}: ${value}`;
144
144
  })
145
145
  .join(`,\n`);
146
146
  const common = dictionary.allTokens
147
147
  .filter((token) => !token.attributes.appearance)
148
148
  .map((token) => {
149
- let value = JSON.stringify(token.value);
150
- let name = token.name.replace("Default", "");
149
+ const value = JSON.stringify(token.value);
150
+ const name = token.name.replace("Default", "");
151
151
  return `\t${name}: ${value}`;
152
152
  })
153
153
  .join(`,\n`);
@@ -160,8 +160,8 @@ StyleDictionary.registerFormat({
160
160
  formatter: function ({ dictionary }) {
161
161
  return dictionary.allTokens
162
162
  .map((token) => {
163
- let value = token.value;
164
- let name = `${token.name.replace("Default", "")}`;
163
+ const value = token.value;
164
+ const name = `${token.name.replace("Default", "")}`;
165
165
  if (token.attributes.appearance) {
166
166
  return `export const ${name} = {
167
167
  value: "${value}",
@@ -180,88 +180,91 @@ StyleDictionary.registerFormat({
180
180
  },
181
181
  });
182
182
 
183
- StyleDictionary.registerFormat({
184
- name: `custom/CSSUtils/All`,
185
- formatter: function ({ dictionary }) {
186
- const colorTokens = dictionary.allTokens
187
- .map((token) => {
188
- let value = getVarValue(dictionary, token);
189
- let name = `${token.name.replace("Default", "")}`;
190
-
191
- if (
192
- // name.startsWith("color") || // primitives
193
- name.startsWith("status-color") ||
194
- name.startsWith("foreground-color") ||
195
- name.startsWith("background-color") ||
196
- name.startsWith("overlay-color")
197
- ) {
198
- let darkValue = getVarValue(dictionary, token, true);
199
- return generateColorClasses(name, value, darkValue);
200
- }
201
- if (name.startsWith("border-color")) {
202
- let darkValue = getVarValue(dictionary, token, true);
203
- return generateBorderClasses(name, value, darkValue);
204
- }
205
- return null;
206
- })
207
- .flat()
208
- .filter((t) => t != null)
209
- .map((t) => `${t}`)
210
- .sort((a, b) => a.localeCompare(b))
211
- .join(`\n`);
212
- const nonColorTokens = dictionary.allTokens
213
- .map((token) => {
214
- let value = getVarValue(dictionary, token);
215
- let name = `${token.name.replace("Default", "")}`;
216
-
217
- if (name.startsWith("border")) {
218
- return generateBorderClasses(name, value);
219
- }
220
- if (name.startsWith("typography")) {
221
- return generateFontClasses(name, value);
222
- }
223
- if (name.startsWith("size")) {
224
- return generateSpacingClasses(name, value);
225
- }
226
- return null;
227
- })
228
- .flat()
229
- .filter((t) => t != null)
230
- .map((t) => `${t}`)
231
- .sort((a, b) => a.localeCompare(b))
232
- .join(`\n`);
233
-
234
- const colorFallbackTokens = dictionary.allTokens
235
- .map((token) => {
236
- let value = getVarValue(dictionary, token);
237
- let name = `${token.name.replace("Default", "")}`;
238
-
239
- if (
240
- name.startsWith("status-color") ||
241
- name.startsWith("foreground-color") ||
242
- name.startsWith("background-color") ||
243
- name.startsWith("overlay-color")
244
- ) {
245
- return generateColorClasses(name, value);
246
- }
247
- if (name.startsWith("border-color")) {
248
- return generateBorderClasses(name, value);
249
- }
250
- return null;
251
- })
252
- .flat()
253
- .filter((t) => t != null)
254
- .map((t) => `${t}`)
255
- .sort((a, b) => a.localeCompare(b))
256
- .join(`\n`);
257
-
258
- // Manually adding .sr-only
259
- const withSr = nonColorTokens.concat(
260
- "\n",
261
- ".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;}",
262
- );
263
-
264
- return `@layer starter, reset, base, state, application;
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
+
237
+ const colorFallbackTokens = dictionary.allTokens
238
+ .map((token) => {
239
+ const value = getVarValue(dictionary, token);
240
+ const name = `${token.name.replace("Default", "")}`;
241
+
242
+ if (
243
+ name.startsWith("status-color") ||
244
+ name.startsWith("foreground-color") ||
245
+ name.startsWith("background-color") ||
246
+ name.startsWith("overlay-color")
247
+ ) {
248
+ return generateColorClasses(name, value, { prefix });
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;
265
268
 
266
269
  ${withSr}
267
270
  ${colorFallbackTokens}
@@ -278,36 +281,43 @@ ${colorFallbackTokens}
278
281
  ${colorTokens.replaceAll("\n", "\n ")}
279
282
  }
280
283
  }`;
281
- },
282
- });
283
-
284
- StyleDictionary.registerFormat({
285
- name: `custom/CSSUtils/Borders`,
286
- formatter: function ({ dictionary }) {
287
- return cssUtilsFormatter(dictionary, generateBorderClasses, true);
288
- },
289
- });
290
-
291
- StyleDictionary.registerFormat({
292
- name: `custom/CSSUtils/Colors`,
293
- formatter: function ({ dictionary }) {
294
- return cssUtilsFormatter(dictionary, generateColorClasses, true);
295
- },
296
- });
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
+ });
297
306
 
298
- StyleDictionary.registerFormat({
299
- name: `custom/CSSUtils/Fonts`,
300
- formatter: function ({ dictionary }) {
301
- return cssUtilsFormatter(dictionary, generateFontClasses);
302
- },
303
- });
307
+ StyleDictionary.registerFormat({
308
+ name: `custom/CSSUtils/${prefix}Fonts`,
309
+ formatter: function ({ dictionary }) {
310
+ return cssUtilsFormatter(dictionary, generateFontClasses, { prefix });
311
+ },
312
+ });
304
313
 
305
- StyleDictionary.registerFormat({
306
- name: `custom/CSSUtils/Spacing`,
307
- formatter: function ({ dictionary }) {
308
- return cssUtilsFormatter(dictionary, generateSpacingClasses);
309
- },
310
- });
314
+ StyleDictionary.registerFormat({
315
+ name: `custom/CSSUtils/${prefix}Spacing`,
316
+ formatter: function ({ dictionary }) {
317
+ return cssUtilsFormatter(dictionary, generateSpacingClasses, { prefix });
318
+ },
319
+ });
320
+ }
311
321
 
312
322
  const getDirectories = (source) =>
313
323
  fs
@@ -325,21 +335,21 @@ themes.forEach((theme) => {
325
335
  css: {
326
336
  transformGroup: "css",
327
337
  buildPath: `build/web/${theme}/css-utils/`,
328
- files: [
338
+ files: CSS_UTILS_PREFIXES.flatMap((prefix) => [
329
339
  {
330
- destination: "utils.css",
331
- format: "custom/CSSUtils/All",
340
+ destination: `${prefix}utils.css`,
341
+ format: `custom/CSSUtils/${prefix}All`,
332
342
  },
333
343
  {
334
- destination: "border.css",
335
- format: "custom/CSSUtils/Borders",
344
+ destination: `${prefix}border.css`,
345
+ format: `custom/CSSUtils/${prefix}Borders`,
336
346
  filter: function (token) {
337
347
  return token.filePath.includes("border");
338
348
  },
339
349
  },
340
350
  {
341
- destination: "color.css",
342
- format: "custom/CSSUtils/Colors",
351
+ destination: `${prefix}color.css`,
352
+ format: `custom/CSSUtils/${prefix}Colors`,
343
353
  filter: function (token) {
344
354
  return (
345
355
  token.filePath.includes("primitive/color") ||
@@ -348,8 +358,8 @@ themes.forEach((theme) => {
348
358
  },
349
359
  },
350
360
  {
351
- destination: "font.css",
352
- format: "custom/CSSUtils/Fonts",
361
+ destination: `${prefix}font.css`,
362
+ format: `custom/CSSUtils/${prefix}Fonts`,
353
363
  filter: function (token) {
354
364
  return (
355
365
  token.filePath.includes("primitive/font") ||
@@ -358,13 +368,13 @@ themes.forEach((theme) => {
358
368
  },
359
369
  },
360
370
  {
361
- destination: "spacing.css",
362
- format: "custom/CSSUtils/Spacing",
371
+ destination: `${prefix}spacing.css`,
372
+ format: `custom/CSSUtils/${prefix}Spacing`,
363
373
  filter: function (token) {
364
374
  return token.filePath.startsWith("src/global/primitive/size");
365
375
  },
366
376
  },
367
- ],
377
+ ]),
368
378
  },
369
379
  scss: {
370
380
  transformGroup: "scss",
@@ -0,0 +1,4 @@
1
+ import baseConfig from "../../eslint.base.config.mjs";
2
+ import eslintConfigPrettier from "eslint-config-prettier/flat";
3
+
4
+ export default [...baseConfig, eslintConfigPrettier];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/hammer-token",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "",
5
5
  "main": "build/web/index.js",
6
6
  "types": "build/web/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "build": "node ./config.js",
20
20
  "dev": "pnpm build && chokidar \"./src\" -c \"pnpm build\"",
21
21
  "clean": "rimraf build .turbo",
22
- "lint": "eslint",
22
+ "lint": "eslint .",
23
23
  "nuke": "pnpm clean && rimraf node_modules"
24
24
  }
25
25
  }
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
1
+ /* eslint-disable @typescript-eslint/no-require-imports */
2
2
  const { color } = require("../../global/primitive/color");
3
3
  const { status } = require("./status");
4
4
 
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
1
+ /* eslint-disable @typescript-eslint/no-require-imports */
2
2
  const { color } = require("../../global/primitive/color");
3
3
  const { size } = require("../../global/primitive/size");
4
4
  const { radius } = require("../../global/primitive/radius");