@primer/primitives 8.0.0 → 8.1.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.
Files changed (62) hide show
  1. package/dist/css/functional/size/size-coarse.css +0 -7
  2. package/dist/css/functional/size/size-fine.css +0 -7
  3. package/dist/css/functional/themes/dark-colorblind.css +10 -0
  4. package/dist/css/functional/themes/dark-dimmed.css +10 -0
  5. package/dist/css/functional/themes/dark-high-contrast.css +10 -0
  6. package/dist/css/functional/themes/dark-tritanopia.css +10 -0
  7. package/dist/css/functional/themes/dark.css +10 -0
  8. package/dist/css/functional/themes/light-colorblind.css +10 -0
  9. package/dist/css/functional/themes/light-high-contrast.css +10 -0
  10. package/dist/css/functional/themes/light-tritanopia.css +10 -0
  11. package/dist/css/functional/themes/light.css +10 -0
  12. package/dist/css/functional/typography/typography.css +12 -12
  13. package/dist/docs/functional/themes/dark-colorblind.json +145 -0
  14. package/dist/docs/functional/themes/dark-dimmed.json +145 -0
  15. package/dist/docs/functional/themes/dark-high-contrast.json +145 -0
  16. package/dist/docs/functional/themes/dark-tritanopia.json +145 -0
  17. package/dist/docs/functional/themes/dark.json +145 -0
  18. package/dist/docs/functional/themes/light-colorblind.json +145 -0
  19. package/dist/docs/functional/themes/light-high-contrast.json +145 -0
  20. package/dist/docs/functional/themes/light-tritanopia.json +145 -0
  21. package/dist/docs/functional/themes/light.json +145 -0
  22. package/dist/figma/themes/dark-colorblind.json +80 -0
  23. package/dist/figma/themes/dark-dimmed.json +80 -0
  24. package/dist/figma/themes/dark-high-contrast.json +80 -0
  25. package/dist/figma/themes/dark-tritanopia.json +80 -0
  26. package/dist/figma/themes/dark.json +80 -0
  27. package/dist/figma/themes/light-colorblind.json +80 -0
  28. package/dist/figma/themes/light-high-contrast.json +80 -0
  29. package/dist/figma/themes/light-tritanopia.json +80 -0
  30. package/dist/figma/themes/light.json +80 -0
  31. package/dist/figma/typography/typography.json +10 -10
  32. package/dist/internalCss/dark-colorblind.css +10 -0
  33. package/dist/internalCss/dark-dimmed.css +10 -0
  34. package/dist/internalCss/dark-high-contrast.css +10 -0
  35. package/dist/internalCss/dark-tritanopia.css +10 -0
  36. package/dist/internalCss/dark.css +10 -0
  37. package/dist/internalCss/light-colorblind.css +10 -0
  38. package/dist/internalCss/light-high-contrast.css +10 -0
  39. package/dist/internalCss/light-tritanopia.css +10 -0
  40. package/dist/internalCss/light.css +10 -0
  41. package/dist/styleLint/functional/themes/dark-colorblind.json +145 -0
  42. package/dist/styleLint/functional/themes/dark-dimmed.json +145 -0
  43. package/dist/styleLint/functional/themes/dark-high-contrast.json +145 -0
  44. package/dist/styleLint/functional/themes/dark-tritanopia.json +145 -0
  45. package/dist/styleLint/functional/themes/dark.json +145 -0
  46. package/dist/styleLint/functional/themes/light-colorblind.json +145 -0
  47. package/dist/styleLint/functional/themes/light-high-contrast.json +145 -0
  48. package/dist/styleLint/functional/themes/light-tritanopia.json +145 -0
  49. package/dist/styleLint/functional/themes/light.json +145 -0
  50. package/package.json +5 -7
  51. package/src/PrimerStyleDictionary.ts +9 -15
  52. package/src/formats/cssAdvanced.ts +99 -0
  53. package/src/formats/index.ts +1 -3
  54. package/src/platforms/css.ts +25 -17
  55. package/src/platforms/figma.ts +1 -1
  56. package/src/tokens/functional/color/dark/display-dark.json5 +66 -0
  57. package/src/tokens/functional/color/light/display-light.json5 +66 -0
  58. package/src/transformers/floatToPixel.ts +9 -2
  59. package/src/transformers/index.ts +1 -0
  60. package/src/formats/cssThemed.ts +0 -35
  61. package/src/formats/cssVariables.ts +0 -25
  62. package/src/formats/cssWrapMediaQuery.ts +0 -29
@@ -2190,6 +2190,151 @@
2190
2190
  "attributes": {},
2191
2191
  "path": ["display", "red", "borderColor", "emphasis"]
2192
2192
  },
2193
+ "display-coral-bgColor-muted": {
2194
+ "value": "#ffe5db",
2195
+ "$type": "color",
2196
+ "$extensions": {
2197
+ "org.primer.figma": {
2198
+ "collection": "mode",
2199
+ "mode": "light",
2200
+ "group": "component (internal)",
2201
+ "scopes": ["bgColor"]
2202
+ }
2203
+ },
2204
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2205
+ "isSource": true,
2206
+ "original": {
2207
+ "value": "{base.display.color.coral.0}",
2208
+ "$type": "color",
2209
+ "$extensions": {
2210
+ "org.primer.figma": {
2211
+ "collection": "mode",
2212
+ "mode": "light",
2213
+ "group": "component (internal)",
2214
+ "scopes": ["bgColor"]
2215
+ }
2216
+ }
2217
+ },
2218
+ "name": "display-coral-bgColor-muted",
2219
+ "attributes": {},
2220
+ "path": ["display", "coral", "bgColor", "muted"]
2221
+ },
2222
+ "display-coral-bgColor-emphasis": {
2223
+ "value": "#d43511",
2224
+ "$type": "color",
2225
+ "$extensions": {
2226
+ "org.primer.figma": {
2227
+ "collection": "mode",
2228
+ "mode": "light",
2229
+ "group": "component (internal)",
2230
+ "scopes": ["bgColor"]
2231
+ }
2232
+ },
2233
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2234
+ "isSource": true,
2235
+ "original": {
2236
+ "value": "{base.display.color.coral.5}",
2237
+ "$type": "color",
2238
+ "$extensions": {
2239
+ "org.primer.figma": {
2240
+ "collection": "mode",
2241
+ "mode": "light",
2242
+ "group": "component (internal)",
2243
+ "scopes": ["bgColor"]
2244
+ }
2245
+ }
2246
+ },
2247
+ "name": "display-coral-bgColor-emphasis",
2248
+ "attributes": {},
2249
+ "path": ["display", "coral", "bgColor", "emphasis"]
2250
+ },
2251
+ "display-coral-fgColor": {
2252
+ "value": "#ba2e12",
2253
+ "$type": "color",
2254
+ "$extensions": {
2255
+ "org.primer.figma": {
2256
+ "collection": "mode",
2257
+ "mode": "light",
2258
+ "group": "component (internal)",
2259
+ "scopes": ["fgColor"]
2260
+ }
2261
+ },
2262
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2263
+ "isSource": true,
2264
+ "original": {
2265
+ "value": "{base.display.color.coral.6}",
2266
+ "$type": "color",
2267
+ "$extensions": {
2268
+ "org.primer.figma": {
2269
+ "collection": "mode",
2270
+ "mode": "light",
2271
+ "group": "component (internal)",
2272
+ "scopes": ["fgColor"]
2273
+ }
2274
+ }
2275
+ },
2276
+ "name": "display-coral-fgColor",
2277
+ "attributes": {},
2278
+ "path": ["display", "coral", "fgColor"]
2279
+ },
2280
+ "display-coral-borderColor-muted": {
2281
+ "value": "#fecebe",
2282
+ "$type": "color",
2283
+ "$extensions": {
2284
+ "org.primer.figma": {
2285
+ "collection": "mode",
2286
+ "mode": "light",
2287
+ "group": "component (internal)",
2288
+ "scopes": ["borderColor"]
2289
+ }
2290
+ },
2291
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2292
+ "isSource": true,
2293
+ "original": {
2294
+ "value": "{base.display.color.coral.1}",
2295
+ "$type": "color",
2296
+ "$extensions": {
2297
+ "org.primer.figma": {
2298
+ "collection": "mode",
2299
+ "mode": "light",
2300
+ "group": "component (internal)",
2301
+ "scopes": ["borderColor"]
2302
+ }
2303
+ }
2304
+ },
2305
+ "name": "display-coral-borderColor-muted",
2306
+ "attributes": {},
2307
+ "path": ["display", "coral", "borderColor", "muted"]
2308
+ },
2309
+ "display-coral-borderColor-emphasis": {
2310
+ "value": "#d43511",
2311
+ "$type": "color",
2312
+ "$extensions": {
2313
+ "org.primer.figma": {
2314
+ "collection": "mode",
2315
+ "mode": "light",
2316
+ "group": "component (internal)",
2317
+ "scopes": ["borderColor"]
2318
+ }
2319
+ },
2320
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2321
+ "isSource": true,
2322
+ "original": {
2323
+ "value": "{base.display.color.coral.5}",
2324
+ "$type": "color",
2325
+ "$extensions": {
2326
+ "org.primer.figma": {
2327
+ "collection": "mode",
2328
+ "mode": "light",
2329
+ "group": "component (internal)",
2330
+ "scopes": ["borderColor"]
2331
+ }
2332
+ }
2333
+ },
2334
+ "name": "display-coral-borderColor-emphasis",
2335
+ "attributes": {},
2336
+ "path": ["display", "coral", "borderColor", "emphasis"]
2337
+ },
2193
2338
  "display-yellow-bgColor-muted": {
2194
2339
  "value": "#ffec9e",
2195
2340
  "$type": "color",
@@ -2188,6 +2188,151 @@
2188
2188
  "attributes": {},
2189
2189
  "path": ["display", "red", "borderColor", "emphasis"]
2190
2190
  },
2191
+ "display-coral-bgColor-muted": {
2192
+ "value": "#ffe5db",
2193
+ "$type": "color",
2194
+ "$extensions": {
2195
+ "org.primer.figma": {
2196
+ "collection": "mode",
2197
+ "mode": "light",
2198
+ "group": "component (internal)",
2199
+ "scopes": ["bgColor"]
2200
+ }
2201
+ },
2202
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2203
+ "isSource": true,
2204
+ "original": {
2205
+ "value": "{base.display.color.coral.0}",
2206
+ "$type": "color",
2207
+ "$extensions": {
2208
+ "org.primer.figma": {
2209
+ "collection": "mode",
2210
+ "mode": "light",
2211
+ "group": "component (internal)",
2212
+ "scopes": ["bgColor"]
2213
+ }
2214
+ }
2215
+ },
2216
+ "name": "display-coral-bgColor-muted",
2217
+ "attributes": {},
2218
+ "path": ["display", "coral", "bgColor", "muted"]
2219
+ },
2220
+ "display-coral-bgColor-emphasis": {
2221
+ "value": "#d43511",
2222
+ "$type": "color",
2223
+ "$extensions": {
2224
+ "org.primer.figma": {
2225
+ "collection": "mode",
2226
+ "mode": "light",
2227
+ "group": "component (internal)",
2228
+ "scopes": ["bgColor"]
2229
+ }
2230
+ },
2231
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2232
+ "isSource": true,
2233
+ "original": {
2234
+ "value": "{base.display.color.coral.5}",
2235
+ "$type": "color",
2236
+ "$extensions": {
2237
+ "org.primer.figma": {
2238
+ "collection": "mode",
2239
+ "mode": "light",
2240
+ "group": "component (internal)",
2241
+ "scopes": ["bgColor"]
2242
+ }
2243
+ }
2244
+ },
2245
+ "name": "display-coral-bgColor-emphasis",
2246
+ "attributes": {},
2247
+ "path": ["display", "coral", "bgColor", "emphasis"]
2248
+ },
2249
+ "display-coral-fgColor": {
2250
+ "value": "#ba2e12",
2251
+ "$type": "color",
2252
+ "$extensions": {
2253
+ "org.primer.figma": {
2254
+ "collection": "mode",
2255
+ "mode": "light",
2256
+ "group": "component (internal)",
2257
+ "scopes": ["fgColor"]
2258
+ }
2259
+ },
2260
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2261
+ "isSource": true,
2262
+ "original": {
2263
+ "value": "{base.display.color.coral.6}",
2264
+ "$type": "color",
2265
+ "$extensions": {
2266
+ "org.primer.figma": {
2267
+ "collection": "mode",
2268
+ "mode": "light",
2269
+ "group": "component (internal)",
2270
+ "scopes": ["fgColor"]
2271
+ }
2272
+ }
2273
+ },
2274
+ "name": "display-coral-fgColor",
2275
+ "attributes": {},
2276
+ "path": ["display", "coral", "fgColor"]
2277
+ },
2278
+ "display-coral-borderColor-muted": {
2279
+ "value": "#fecebe",
2280
+ "$type": "color",
2281
+ "$extensions": {
2282
+ "org.primer.figma": {
2283
+ "collection": "mode",
2284
+ "mode": "light",
2285
+ "group": "component (internal)",
2286
+ "scopes": ["borderColor"]
2287
+ }
2288
+ },
2289
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2290
+ "isSource": true,
2291
+ "original": {
2292
+ "value": "{base.display.color.coral.1}",
2293
+ "$type": "color",
2294
+ "$extensions": {
2295
+ "org.primer.figma": {
2296
+ "collection": "mode",
2297
+ "mode": "light",
2298
+ "group": "component (internal)",
2299
+ "scopes": ["borderColor"]
2300
+ }
2301
+ }
2302
+ },
2303
+ "name": "display-coral-borderColor-muted",
2304
+ "attributes": {},
2305
+ "path": ["display", "coral", "borderColor", "muted"]
2306
+ },
2307
+ "display-coral-borderColor-emphasis": {
2308
+ "value": "#d43511",
2309
+ "$type": "color",
2310
+ "$extensions": {
2311
+ "org.primer.figma": {
2312
+ "collection": "mode",
2313
+ "mode": "light",
2314
+ "group": "component (internal)",
2315
+ "scopes": ["borderColor"]
2316
+ }
2317
+ },
2318
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2319
+ "isSource": true,
2320
+ "original": {
2321
+ "value": "{base.display.color.coral.5}",
2322
+ "$type": "color",
2323
+ "$extensions": {
2324
+ "org.primer.figma": {
2325
+ "collection": "mode",
2326
+ "mode": "light",
2327
+ "group": "component (internal)",
2328
+ "scopes": ["borderColor"]
2329
+ }
2330
+ }
2331
+ },
2332
+ "name": "display-coral-borderColor-emphasis",
2333
+ "attributes": {},
2334
+ "path": ["display", "coral", "borderColor", "emphasis"]
2335
+ },
2191
2336
  "display-yellow-bgColor-muted": {
2192
2337
  "value": "#ffec9e",
2193
2338
  "$type": "color",
@@ -2188,6 +2188,151 @@
2188
2188
  "attributes": {},
2189
2189
  "path": ["display", "red", "borderColor", "emphasis"]
2190
2190
  },
2191
+ "display-coral-bgColor-muted": {
2192
+ "value": "#ffe5db",
2193
+ "$type": "color",
2194
+ "$extensions": {
2195
+ "org.primer.figma": {
2196
+ "collection": "mode",
2197
+ "mode": "light",
2198
+ "group": "component (internal)",
2199
+ "scopes": ["bgColor"]
2200
+ }
2201
+ },
2202
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2203
+ "isSource": true,
2204
+ "original": {
2205
+ "value": "{base.display.color.coral.0}",
2206
+ "$type": "color",
2207
+ "$extensions": {
2208
+ "org.primer.figma": {
2209
+ "collection": "mode",
2210
+ "mode": "light",
2211
+ "group": "component (internal)",
2212
+ "scopes": ["bgColor"]
2213
+ }
2214
+ }
2215
+ },
2216
+ "name": "display-coral-bgColor-muted",
2217
+ "attributes": {},
2218
+ "path": ["display", "coral", "bgColor", "muted"]
2219
+ },
2220
+ "display-coral-bgColor-emphasis": {
2221
+ "value": "#d43511",
2222
+ "$type": "color",
2223
+ "$extensions": {
2224
+ "org.primer.figma": {
2225
+ "collection": "mode",
2226
+ "mode": "light",
2227
+ "group": "component (internal)",
2228
+ "scopes": ["bgColor"]
2229
+ }
2230
+ },
2231
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2232
+ "isSource": true,
2233
+ "original": {
2234
+ "value": "{base.display.color.coral.5}",
2235
+ "$type": "color",
2236
+ "$extensions": {
2237
+ "org.primer.figma": {
2238
+ "collection": "mode",
2239
+ "mode": "light",
2240
+ "group": "component (internal)",
2241
+ "scopes": ["bgColor"]
2242
+ }
2243
+ }
2244
+ },
2245
+ "name": "display-coral-bgColor-emphasis",
2246
+ "attributes": {},
2247
+ "path": ["display", "coral", "bgColor", "emphasis"]
2248
+ },
2249
+ "display-coral-fgColor": {
2250
+ "value": "#ba2e12",
2251
+ "$type": "color",
2252
+ "$extensions": {
2253
+ "org.primer.figma": {
2254
+ "collection": "mode",
2255
+ "mode": "light",
2256
+ "group": "component (internal)",
2257
+ "scopes": ["fgColor"]
2258
+ }
2259
+ },
2260
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2261
+ "isSource": true,
2262
+ "original": {
2263
+ "value": "{base.display.color.coral.6}",
2264
+ "$type": "color",
2265
+ "$extensions": {
2266
+ "org.primer.figma": {
2267
+ "collection": "mode",
2268
+ "mode": "light",
2269
+ "group": "component (internal)",
2270
+ "scopes": ["fgColor"]
2271
+ }
2272
+ }
2273
+ },
2274
+ "name": "display-coral-fgColor",
2275
+ "attributes": {},
2276
+ "path": ["display", "coral", "fgColor"]
2277
+ },
2278
+ "display-coral-borderColor-muted": {
2279
+ "value": "#fecebe",
2280
+ "$type": "color",
2281
+ "$extensions": {
2282
+ "org.primer.figma": {
2283
+ "collection": "mode",
2284
+ "mode": "light",
2285
+ "group": "component (internal)",
2286
+ "scopes": ["borderColor"]
2287
+ }
2288
+ },
2289
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2290
+ "isSource": true,
2291
+ "original": {
2292
+ "value": "{base.display.color.coral.1}",
2293
+ "$type": "color",
2294
+ "$extensions": {
2295
+ "org.primer.figma": {
2296
+ "collection": "mode",
2297
+ "mode": "light",
2298
+ "group": "component (internal)",
2299
+ "scopes": ["borderColor"]
2300
+ }
2301
+ }
2302
+ },
2303
+ "name": "display-coral-borderColor-muted",
2304
+ "attributes": {},
2305
+ "path": ["display", "coral", "borderColor", "muted"]
2306
+ },
2307
+ "display-coral-borderColor-emphasis": {
2308
+ "value": "#d43511",
2309
+ "$type": "color",
2310
+ "$extensions": {
2311
+ "org.primer.figma": {
2312
+ "collection": "mode",
2313
+ "mode": "light",
2314
+ "group": "component (internal)",
2315
+ "scopes": ["borderColor"]
2316
+ }
2317
+ },
2318
+ "filePath": "src/tokens/functional/color/light/display-light.json5",
2319
+ "isSource": true,
2320
+ "original": {
2321
+ "value": "{base.display.color.coral.5}",
2322
+ "$type": "color",
2323
+ "$extensions": {
2324
+ "org.primer.figma": {
2325
+ "collection": "mode",
2326
+ "mode": "light",
2327
+ "group": "component (internal)",
2328
+ "scopes": ["borderColor"]
2329
+ }
2330
+ }
2331
+ },
2332
+ "name": "display-coral-borderColor-emphasis",
2333
+ "attributes": {},
2334
+ "path": ["display", "coral", "borderColor", "emphasis"]
2335
+ },
2191
2336
  "display-yellow-bgColor-muted": {
2192
2337
  "value": "#ffec9e",
2193
2338
  "$type": "color",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/primitives",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "Typography, spacing, and color primitives for Primer design system",
5
5
  "files": [
6
6
  "dist",
@@ -23,7 +23,8 @@
23
23
  },
24
24
  "homepage": "https://github.com/primer/primitives#readme",
25
25
  "scripts": {
26
- "build:next": "npm run build:v8 && npm run build:fallbacks && npm run build:figma",
26
+ "build": "npm run build:v8 && npm run build:fallbacks && npm run build:figma",
27
+ "build:next": "echo '\\033[31m 🛑 Use npm run build instead of npm run build:next\\033[0m'",
27
28
  "build:v8": "ts-node ./scripts/buildTokens.ts",
28
29
  "build:fallbacks": "ts-node ./scripts/buildFallbacks.ts",
29
30
  "build:figma": "ts-node scripts/buildFigma.ts",
@@ -36,11 +37,9 @@
36
37
  "lint:fix": "eslint '**/*.{js,ts,tsx,md,mdx}' --fix --max-warnings=0 --config .eslintrc.js",
37
38
  "lint:tokens": "ts-node ./scripts/validateTokenJson.ts",
38
39
  "prebuild": "rm -rf dist",
39
- "prebuild:next": "rm -rf dist",
40
- "prepack": "npm run build:next",
41
- "prepare": "husky",
40
+ "prepack": "npm run build",
42
41
  "release": "changeset publish",
43
- "start:storybook": "npm run build:next && cd docs/storybook && npm run storybook",
42
+ "start:storybook": "npm run build && cd docs/storybook && npm run storybook",
44
43
  "test": "jest --verbose --coverage"
45
44
  },
46
45
  "prettier": "@github/prettier-config",
@@ -69,7 +68,6 @@
69
68
  "eslint-plugin-react": "^7.29.4",
70
69
  "eslint-plugin-react-hooks": "^4.4.0",
71
70
  "eslint-plugin-storybook": "^0.6.15",
72
- "husky": "^9.0.11",
73
71
  "jest": "^29.6.1",
74
72
  "json5": "^2.2.1",
75
73
  "markdown-table-ts": "^1.0.3",
@@ -24,18 +24,17 @@ import {
24
24
  typographyToCss,
25
25
  dimensionToRemPxArray,
26
26
  floatToPixel,
27
+ floatToPixelUnitless,
27
28
  } from './transformers'
28
29
  import {
29
30
  javascriptCommonJs,
30
31
  javascriptEsm,
31
32
  typescriptExportDefinition,
32
33
  jsonNestedPrefixed,
33
- cssThemed,
34
34
  cssCustomMedia,
35
35
  jsonOneDimensional,
36
36
  jsonPostCssFallback,
37
- cssWrapMediaQuery,
38
- cssVariables,
37
+ cssAdvanced,
39
38
  jsonFigma,
40
39
  } from './formats'
41
40
 
@@ -50,8 +49,8 @@ StyleDictionary.registerParser(w3cJsonParser)
50
49
  *
51
50
  */
52
51
  StyleDictionary.registerFormat({
53
- name: 'css/themed',
54
- formatter: cssThemed,
52
+ name: 'css/advanced',
53
+ formatter: cssAdvanced,
55
54
  })
56
55
 
57
56
  StyleDictionary.registerFormat({
@@ -59,16 +58,6 @@ StyleDictionary.registerFormat({
59
58
  formatter: cssCustomMedia,
60
59
  })
61
60
 
62
- StyleDictionary.registerFormat({
63
- name: 'css/wrapMediaQuery',
64
- formatter: cssWrapMediaQuery,
65
- })
66
-
67
- StyleDictionary.registerFormat({
68
- name: 'css/variables',
69
- formatter: cssVariables,
70
- })
71
-
72
61
  StyleDictionary.registerFormat({
73
62
  name: 'javascript/esm',
74
63
  formatter: javascriptEsm,
@@ -138,6 +127,11 @@ StyleDictionary.registerTransform({
138
127
  ...floatToPixel,
139
128
  })
140
129
 
130
+ StyleDictionary.registerTransform({
131
+ name: 'float/pixelUnitless',
132
+ ...floatToPixelUnitless,
133
+ })
134
+
141
135
  StyleDictionary.registerTransform({
142
136
  name: 'dimension/rem',
143
137
  ...dimensionToRem,
@@ -0,0 +1,99 @@
1
+ import type {TransformedToken} from 'style-dictionary'
2
+ import StyleDictionary from 'style-dictionary'
3
+ import type {FormatterArguments} from 'style-dictionary/types/Format'
4
+ import {format} from 'prettier'
5
+ import type {LineFormatting} from 'style-dictionary/types/FormatHelpers'
6
+ const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
7
+
8
+ const wrapWithSelector = (css: string, selector: string | false): string => {
9
+ // return without selector
10
+ if (selector === false || selector.trim().length === 0) return css
11
+ // return with selector
12
+ return `${selector} { ${css} }`
13
+ }
14
+
15
+ export const cssAdvanced: StyleDictionary.Formatter = ({
16
+ dictionary: originalDictionary,
17
+ options = {
18
+ queries: [],
19
+ },
20
+ file,
21
+ platform,
22
+ }: FormatterArguments): string => {
23
+ // get options
24
+ const {outputReferences, descriptions} = options
25
+ // selector
26
+ const selector = file.options?.selector !== undefined ? file.options.selector : ':root'
27
+ // query extension property
28
+ const queryExtProp = file.options?.queryExtensionProperty || 'mediaQuery'
29
+ // get queries from file options
30
+ const queries = file.options?.queries || [
31
+ {
32
+ query: undefined,
33
+ matcher: () => true,
34
+ },
35
+ ]
36
+ // set formatting
37
+ const formatting: LineFormatting = {
38
+ commentStyle: descriptions ? 'long' : 'none',
39
+ }
40
+ // clone dictionary
41
+ const dictionary = {...originalDictionary}
42
+ // add prefix to tokens
43
+ if (platform.prefix) {
44
+ dictionary.allTokens = dictionary.allTokens.map(
45
+ token =>
46
+ ({
47
+ ...token,
48
+ name: `${platform.prefix}-${token.name}`,
49
+ path: [platform.prefix, ...token.path],
50
+ } as TransformedToken),
51
+ )
52
+ }
53
+ // get queries from tokens
54
+ for (const designToken of dictionary.allTokens) {
55
+ const query = designToken.$extensions?.[queryExtProp]
56
+ // early abort if query does not exist on token
57
+ if (!query) continue
58
+ // if query exists already from other token
59
+ const currentQueryIndex = queries.findIndex((q: {query: string; matcher: () => boolean}) => q.query === query)
60
+
61
+ // if query exists
62
+ if (currentQueryIndex > -1) {
63
+ queries[currentQueryIndex] = {
64
+ ...queries[currentQueryIndex],
65
+ matcher: (token: TransformedToken) =>
66
+ queries[currentQueryIndex].matcher(token) ||
67
+ token.$extensions[queryExtProp] === queries[currentQueryIndex].query,
68
+ }
69
+ }
70
+ // if query does not exist
71
+ else {
72
+ queries.push({
73
+ query,
74
+ matcher: (token: TransformedToken) => token.$extensions?.[queryExtProp] === query,
75
+ })
76
+ }
77
+ }
78
+ // add file header
79
+ const output = [fileHeader({file})]
80
+ // add single theme css
81
+ for (const query of queries) {
82
+ const {query: queryString, matcher} = query
83
+ // filter tokens to only include the ones that pass the matcher
84
+ const filteredDictionary = {
85
+ ...dictionary,
86
+ allTokens: dictionary.allTokens.filter(matcher || (() => true)),
87
+ }
88
+ // early abort if no matches
89
+ if (!filteredDictionary.allTokens.length) continue
90
+ // add tokens into root
91
+ const css = formattedVariables({format: 'css', dictionary: filteredDictionary, outputReferences, formatting})
92
+ // wrap css
93
+ const cssWithSelector = wrapWithSelector(css, query.selector !== undefined ? query.selector : selector)
94
+ // add css with or without query
95
+ output.push(queryString ? `${queryString} { ${cssWithSelector} }` : cssWithSelector)
96
+ }
97
+ // return prettified
98
+ return format(output.join('\n'), {parser: 'css', printWidth: 500})
99
+ }
@@ -1,7 +1,5 @@
1
- export {cssThemed} from './cssThemed'
2
1
  export {cssCustomMedia} from './cssCustomMedia'
3
- export {cssWrapMediaQuery} from './cssWrapMediaQuery'
4
- export {cssVariables} from './cssVariables'
2
+ export {cssAdvanced} from './cssAdvanced'
5
3
  export {jsonFigma} from './jsonFigma'
6
4
  export {javascriptCommonJs} from './javascriptCommonJs'
7
5
  export {javascriptEsm} from './javascriptEsm'