@primer/primitives 9.1.2 → 10.0.0-rc.6651a0c1

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 (298) hide show
  1. package/dist/css/functional/themes/dark-colorblind.css +4 -4
  2. package/dist/css/functional/themes/dark-high-contrast.css +20 -20
  3. package/dist/css/functional/themes/light-high-contrast.css +14 -14
  4. package/dist/css/functional/typography/typography.css +20 -20
  5. package/dist/css/primitives.css +20 -20
  6. package/dist/docs/base/size/size.json +76 -76
  7. package/dist/docs/base/typography/typography.json +16 -16
  8. package/dist/docs/functional/motion/motion.json +18 -18
  9. package/dist/docs/functional/size/border.json +56 -56
  10. package/dist/docs/functional/size/breakpoints.json +24 -24
  11. package/dist/docs/functional/size/size-coarse.json +12 -12
  12. package/dist/docs/functional/size/size-fine.json +12 -12
  13. package/dist/docs/functional/size/size.json +264 -264
  14. package/dist/docs/functional/size/viewport.json +24 -24
  15. package/dist/docs/functional/themes/dark-colorblind.json +2310 -3186
  16. package/dist/docs/functional/themes/dark-dimmed.json +2300 -2794
  17. package/dist/docs/functional/themes/dark-high-contrast.json +2520 -5038
  18. package/dist/docs/functional/themes/dark-tritanopia.json +2351 -3003
  19. package/dist/docs/functional/themes/dark.json +2270 -2270
  20. package/dist/docs/functional/themes/light-colorblind.json +2298 -3124
  21. package/dist/docs/functional/themes/light-high-contrast.json +2419 -4645
  22. package/dist/docs/functional/themes/light-tritanopia.json +2330 -2990
  23. package/dist/docs/functional/themes/light.json +2260 -2260
  24. package/dist/docs/functional/typography/typography.json +206 -206
  25. package/dist/figma/dimension/dimension.json +489 -489
  26. package/dist/figma/figma.json +11 -3
  27. package/dist/figma/scales/dark-dimmed.json +38 -38
  28. package/dist/figma/scales/dark-high-constrast.json +38 -38
  29. package/dist/figma/scales/dark.json +35 -35
  30. package/dist/figma/scales/light-high-constrast.json +40 -40
  31. package/dist/figma/scales/light.json +40 -40
  32. package/dist/figma/shadows/dark-colorblind.json +280 -280
  33. package/dist/figma/shadows/dark-dimmed.json +280 -280
  34. package/dist/figma/shadows/dark-high-contrast.json +280 -280
  35. package/dist/figma/shadows/dark-tritanopia.json +280 -280
  36. package/dist/figma/shadows/dark.json +280 -280
  37. package/dist/figma/shadows/light-colorblind.json +281 -281
  38. package/dist/figma/shadows/light-high-contrast.json +281 -281
  39. package/dist/figma/shadows/light-tritanopia.json +281 -281
  40. package/dist/figma/shadows/light.json +281 -281
  41. package/dist/figma/themes/dark-colorblind.json +4991 -5854
  42. package/dist/figma/themes/dark-dimmed.json +5314 -5799
  43. package/dist/figma/themes/dark-high-contrast.json +4210 -6679
  44. package/dist/figma/themes/dark-tritanopia.json +5165 -5817
  45. package/dist/figma/themes/dark.json +5534 -5537
  46. package/dist/figma/themes/light-colorblind.json +4857 -5669
  47. package/dist/figma/themes/light-high-contrast.json +4198 -6372
  48. package/dist/figma/themes/light-tritanopia.json +4901 -5529
  49. package/dist/figma/themes/light.json +5349 -5349
  50. package/dist/figma/typography/typography.json +112 -156
  51. package/dist/internalCss/dark-colorblind.css +4 -4
  52. package/dist/internalCss/dark-high-contrast.css +20 -20
  53. package/dist/internalCss/light-high-contrast.css +14 -14
  54. package/dist/styleLint/base/size/size.json +38 -38
  55. package/dist/styleLint/base/typography/typography.json +8 -8
  56. package/dist/styleLint/functional/motion/motion.json +12 -12
  57. package/dist/styleLint/functional/size/border.json +30 -30
  58. package/dist/styleLint/functional/size/breakpoints.json +12 -12
  59. package/dist/styleLint/functional/size/size-coarse.json +6 -6
  60. package/dist/styleLint/functional/size/size-fine.json +6 -6
  61. package/dist/styleLint/functional/size/size.json +132 -132
  62. package/dist/styleLint/functional/size/viewport.json +12 -12
  63. package/dist/styleLint/functional/themes/dark-colorblind.json +1171 -2047
  64. package/dist/styleLint/functional/themes/dark-dimmed.json +1160 -1654
  65. package/dist/styleLint/functional/themes/dark-high-contrast.json +1307 -3825
  66. package/dist/styleLint/functional/themes/dark-tritanopia.json +1232 -1884
  67. package/dist/styleLint/functional/themes/dark.json +1140 -1140
  68. package/dist/styleLint/functional/themes/light-colorblind.json +1198 -2024
  69. package/dist/styleLint/functional/themes/light-high-contrast.json +1270 -3496
  70. package/dist/styleLint/functional/themes/light-tritanopia.json +1205 -1865
  71. package/dist/styleLint/functional/themes/light.json +1130 -1130
  72. package/dist/styleLint/functional/typography/typography.json +114 -114
  73. package/package.json +18 -10
  74. package/src/tokens/functional/color/dark/overrides/dark.high-contrast.json5 +4 -4
  75. package/src/tokens/functional/color/dark/overrides/dark.protanopia-deuteranopia.json5 +6 -0
  76. package/src/tokens/functional/color/dark/overrides/dark.tritanopia.json5 +21 -3
  77. package/src/tokens/functional/color/dark/primitives-dark.json5 +3 -3
  78. package/src/tokens/functional/color/light/overrides/light.protanopia-deuteranopia.json5 +4 -1
  79. package/src/tokens/functional/color/light/overrides/light.tritanopia.json5 +4 -1
  80. package/src/tokens/functional/color/light/primitives-light.json5 +2 -2
  81. package/dist/build/PrimerStyleDictionary.d.ts +0 -9
  82. package/dist/build/PrimerStyleDictionary.js +0 -92
  83. package/dist/build/filters/index.d.ts +0 -13
  84. package/dist/build/filters/index.js +0 -29
  85. package/dist/build/filters/isBorder.d.ts +0 -7
  86. package/dist/build/filters/isBorder.js +0 -12
  87. package/dist/build/filters/isColor.d.ts +0 -7
  88. package/dist/build/filters/isColor.js +0 -12
  89. package/dist/build/filters/isColorWithAlpha.d.ts +0 -7
  90. package/dist/build/filters/isColorWithAlpha.js +0 -13
  91. package/dist/build/filters/isColorWithMix.d.ts +0 -7
  92. package/dist/build/filters/isColorWithMix.js +0 -28
  93. package/dist/build/filters/isDeprecated.d.ts +0 -7
  94. package/dist/build/filters/isDeprecated.js +0 -12
  95. package/dist/build/filters/isDimension.d.ts +0 -7
  96. package/dist/build/filters/isDimension.js +0 -12
  97. package/dist/build/filters/isDuration.d.ts +0 -7
  98. package/dist/build/filters/isDuration.js +0 -12
  99. package/dist/build/filters/isFontFamily.d.ts +0 -7
  100. package/dist/build/filters/isFontFamily.js +0 -12
  101. package/dist/build/filters/isFontWeight.d.ts +0 -7
  102. package/dist/build/filters/isFontWeight.js +0 -12
  103. package/dist/build/filters/isFromFile.d.ts +0 -8
  104. package/dist/build/filters/isFromFile.js +0 -14
  105. package/dist/build/filters/isNumber.d.ts +0 -7
  106. package/dist/build/filters/isNumber.js +0 -10
  107. package/dist/build/filters/isShadow.d.ts +0 -7
  108. package/dist/build/filters/isShadow.js +0 -12
  109. package/dist/build/filters/isSource.d.ts +0 -7
  110. package/dist/build/filters/isSource.js +0 -12
  111. package/dist/build/filters/isTypography.d.ts +0 -7
  112. package/dist/build/filters/isTypography.js +0 -12
  113. package/dist/build/formats/cssAdvanced.d.ts +0 -2
  114. package/dist/build/formats/cssAdvanced.js +0 -84
  115. package/dist/build/formats/cssCustomMedia.d.ts +0 -7
  116. package/dist/build/formats/cssCustomMedia.js +0 -25
  117. package/dist/build/formats/index.d.ts +0 -9
  118. package/dist/build/formats/index.js +0 -21
  119. package/dist/build/formats/javascriptCommonJs.d.ts +0 -7
  120. package/dist/build/formats/javascriptCommonJs.js +0 -25
  121. package/dist/build/formats/javascriptEsm.d.ts +0 -7
  122. package/dist/build/formats/javascriptEsm.js +0 -25
  123. package/dist/build/formats/jsonFigma.d.ts +0 -7
  124. package/dist/build/formats/jsonFigma.js +0 -116
  125. package/dist/build/formats/jsonNestedPrefixed.d.ts +0 -8
  126. package/dist/build/formats/jsonNestedPrefixed.js +0 -28
  127. package/dist/build/formats/jsonOneDimensional.d.ts +0 -8
  128. package/dist/build/formats/jsonOneDimensional.js +0 -24
  129. package/dist/build/formats/jsonPostCssFallback.d.ts +0 -8
  130. package/dist/build/formats/jsonPostCssFallback.js +0 -21
  131. package/dist/build/formats/typescriptExportDefinition.d.ts +0 -7
  132. package/dist/build/formats/typescriptExportDefinition.js +0 -166
  133. package/dist/build/formats/utilities/jsonToFlat.d.ts +0 -11
  134. package/dist/build/formats/utilities/jsonToFlat.js +0 -12
  135. package/dist/build/formats/utilities/jsonToNestedValue.d.ts +0 -8
  136. package/dist/build/formats/utilities/jsonToNestedValue.js +0 -25
  137. package/dist/build/formats/utilities/prefixTokens.d.ts +0 -8
  138. package/dist/build/formats/utilities/prefixTokens.js +0 -17
  139. package/dist/build/parsers/index.d.ts +0 -1
  140. package/dist/build/parsers/index.js +0 -5
  141. package/dist/build/parsers/w3cJsonParser.d.ts +0 -6
  142. package/dist/build/parsers/w3cJsonParser.js +0 -27
  143. package/dist/build/platforms/css.d.ts +0 -2
  144. package/dist/build/platforms/css.js +0 -87
  145. package/dist/build/platforms/deprecatedJson.d.ts +0 -2
  146. package/dist/build/platforms/deprecatedJson.js +0 -17
  147. package/dist/build/platforms/docJson.d.ts +0 -2
  148. package/dist/build/platforms/docJson.js +0 -34
  149. package/dist/build/platforms/fallbacks.d.ts +0 -2
  150. package/dist/build/platforms/fallbacks.js +0 -34
  151. package/dist/build/platforms/figma.d.ts +0 -2
  152. package/dist/build/platforms/figma.js +0 -53
  153. package/dist/build/platforms/index.d.ts +0 -10
  154. package/dist/build/platforms/index.js +0 -23
  155. package/dist/build/platforms/javascript.d.ts +0 -2
  156. package/dist/build/platforms/javascript.js +0 -30
  157. package/dist/build/platforms/json.d.ts +0 -2
  158. package/dist/build/platforms/json.js +0 -32
  159. package/dist/build/platforms/styleLint.d.ts +0 -2
  160. package/dist/build/platforms/styleLint.js +0 -34
  161. package/dist/build/platforms/typeDefinitions.d.ts +0 -2
  162. package/dist/build/platforms/typeDefinitions.js +0 -30
  163. package/dist/build/platforms/typescript.d.ts +0 -2
  164. package/dist/build/platforms/typescript.js +0 -30
  165. package/dist/build/schemas/alphaValue.d.ts +0 -2
  166. package/dist/build/schemas/alphaValue.js +0 -8
  167. package/dist/build/schemas/baseToken.d.ts +0 -11
  168. package/dist/build/schemas/baseToken.js +0 -10
  169. package/dist/build/schemas/borderToken.d.ts +0 -51
  170. package/dist/build/schemas/borderToken.js +0 -20
  171. package/dist/build/schemas/collections.d.ts +0 -6
  172. package/dist/build/schemas/collections.js +0 -18
  173. package/dist/build/schemas/colorHexValue.d.ts +0 -2
  174. package/dist/build/schemas/colorHexValue.js +0 -12
  175. package/dist/build/schemas/colorToken.d.ts +0 -80
  176. package/dist/build/schemas/colorToken.js +0 -52
  177. package/dist/build/schemas/designToken.d.ts +0 -2
  178. package/dist/build/schemas/designToken.js +0 -37
  179. package/dist/build/schemas/dimensionToken.d.ts +0 -52
  180. package/dist/build/schemas/dimensionToken.js +0 -36
  181. package/dist/build/schemas/dimensionValue.d.ts +0 -2
  182. package/dist/build/schemas/dimensionValue.js +0 -12
  183. package/dist/build/schemas/durationToken.d.ts +0 -18
  184. package/dist/build/schemas/durationToken.js +0 -14
  185. package/dist/build/schemas/durationValue.d.ts +0 -2
  186. package/dist/build/schemas/durationValue.js +0 -8
  187. package/dist/build/schemas/fontFamilyToken.d.ts +0 -52
  188. package/dist/build/schemas/fontFamilyToken.js +0 -23
  189. package/dist/build/schemas/fontWeightToken.d.ts +0 -52
  190. package/dist/build/schemas/fontWeightToken.js +0 -24
  191. package/dist/build/schemas/fontWeightValue.d.ts +0 -2
  192. package/dist/build/schemas/fontWeightValue.js +0 -9
  193. package/dist/build/schemas/numberToken.d.ts +0 -71
  194. package/dist/build/schemas/numberToken.js +0 -30
  195. package/dist/build/schemas/referenceValue.d.ts +0 -2
  196. package/dist/build/schemas/referenceValue.js +0 -8
  197. package/dist/build/schemas/scopes.d.ts +0 -5
  198. package/dist/build/schemas/scopes.js +0 -34
  199. package/dist/build/schemas/shadowToken.d.ts +0 -157
  200. package/dist/build/schemas/shadowToken.js +0 -46
  201. package/dist/build/schemas/stringToken.d.ts +0 -18
  202. package/dist/build/schemas/stringToken.js +0 -13
  203. package/dist/build/schemas/tokenName.d.ts +0 -2
  204. package/dist/build/schemas/tokenName.js +0 -8
  205. package/dist/build/schemas/tokenType.d.ts +0 -3
  206. package/dist/build/schemas/tokenType.js +0 -6
  207. package/dist/build/schemas/typographyToken.d.ts +0 -59
  208. package/dist/build/schemas/typographyToken.js +0 -21
  209. package/dist/build/schemas/validTokenType.d.ts +0 -5
  210. package/dist/build/schemas/validTokenType.js +0 -34
  211. package/dist/build/schemas/viewportRangeToken.d.ts +0 -18
  212. package/dist/build/schemas/viewportRangeToken.js +0 -13
  213. package/dist/build/transformers/borderToCss.d.ts +0 -8
  214. package/dist/build/transformers/borderToCss.js +0 -38
  215. package/dist/build/transformers/colorToHex.d.ts +0 -8
  216. package/dist/build/transformers/colorToHex.js +0 -26
  217. package/dist/build/transformers/colorToHexMix.d.ts +0 -8
  218. package/dist/build/transformers/colorToHexMix.js +0 -25
  219. package/dist/build/transformers/colorToRgbAlpha.d.ts +0 -8
  220. package/dist/build/transformers/colorToRgbAlpha.js +0 -22
  221. package/dist/build/transformers/colorToRgbaFloat.d.ts +0 -8
  222. package/dist/build/transformers/colorToRgbaFloat.js +0 -50
  223. package/dist/build/transformers/dimensionToPixelUnitless.d.ts +0 -8
  224. package/dist/build/transformers/dimensionToPixelUnitless.js +0 -50
  225. package/dist/build/transformers/dimensionToRem.d.ts +0 -8
  226. package/dist/build/transformers/dimensionToRem.js +0 -47
  227. package/dist/build/transformers/dimensionToRemPxArray.d.ts +0 -8
  228. package/dist/build/transformers/dimensionToRemPxArray.js +0 -47
  229. package/dist/build/transformers/durationToCss.d.ts +0 -8
  230. package/dist/build/transformers/durationToCss.js +0 -30
  231. package/dist/build/transformers/figmaAttributes.d.ts +0 -8
  232. package/dist/build/transformers/figmaAttributes.js +0 -57
  233. package/dist/build/transformers/floatToPixel.d.ts +0 -15
  234. package/dist/build/transformers/floatToPixel.js +0 -41
  235. package/dist/build/transformers/fontFamilyToCss.d.ts +0 -14
  236. package/dist/build/transformers/fontFamilyToCss.js +0 -40
  237. package/dist/build/transformers/fontFamilyToFigma.d.ts +0 -14
  238. package/dist/build/transformers/fontFamilyToFigma.js +0 -46
  239. package/dist/build/transformers/fontWeightToNumber.d.ts +0 -9
  240. package/dist/build/transformers/fontWeightToNumber.js +0 -53
  241. package/dist/build/transformers/index.d.ts +0 -24
  242. package/dist/build/transformers/index.js +0 -51
  243. package/dist/build/transformers/jsonDeprecated.d.ts +0 -8
  244. package/dist/build/transformers/jsonDeprecated.js +0 -16
  245. package/dist/build/transformers/namePathToCamelCase.d.ts +0 -8
  246. package/dist/build/transformers/namePathToCamelCase.js +0 -14
  247. package/dist/build/transformers/namePathToDotNotation.d.ts +0 -8
  248. package/dist/build/transformers/namePathToDotNotation.js +0 -33
  249. package/dist/build/transformers/namePathToFigma.d.ts +0 -9
  250. package/dist/build/transformers/namePathToFigma.js +0 -24
  251. package/dist/build/transformers/namePathToKebabCase.d.ts +0 -8
  252. package/dist/build/transformers/namePathToKebabCase.js +0 -18
  253. package/dist/build/transformers/namePathToPascalCase.d.ts +0 -8
  254. package/dist/build/transformers/namePathToPascalCase.js +0 -14
  255. package/dist/build/transformers/namePathToSlashNotation.d.ts +0 -8
  256. package/dist/build/transformers/namePathToSlashNotation.js +0 -18
  257. package/dist/build/transformers/shadowToCss.d.ts +0 -8
  258. package/dist/build/transformers/shadowToCss.js +0 -35
  259. package/dist/build/transformers/typographyToCss.d.ts +0 -8
  260. package/dist/build/transformers/typographyToCss.js +0 -29
  261. package/dist/build/transformers/utilities/alpha.d.ts +0 -9
  262. package/dist/build/transformers/utilities/alpha.js +0 -20
  263. package/dist/build/transformers/utilities/checkRequiredTokenProperties.d.ts +0 -7
  264. package/dist/build/transformers/utilities/checkRequiredTokenProperties.js +0 -17
  265. package/dist/build/transformers/utilities/getTokenValue.d.ts +0 -2
  266. package/dist/build/transformers/utilities/getTokenValue.js +0 -18
  267. package/dist/build/transformers/utilities/hasSpaceInString.d.ts +0 -1
  268. package/dist/build/transformers/utilities/hasSpaceInString.js +0 -10
  269. package/dist/build/transformers/utilities/hexToRgbaFloat.d.ts +0 -2
  270. package/dist/build/transformers/utilities/hexToRgbaFloat.js +0 -33
  271. package/dist/build/transformers/utilities/invalidTokenError.d.ts +0 -7
  272. package/dist/build/transformers/utilities/invalidTokenError.js +0 -26
  273. package/dist/build/transformers/utilities/isRgbaFloat.d.ts +0 -7
  274. package/dist/build/transformers/utilities/isRgbaFloat.js +0 -24
  275. package/dist/build/transformers/utilities/mix.d.ts +0 -5
  276. package/dist/build/transformers/utilities/mix.js +0 -40
  277. package/dist/build/transformers/utilities/rgbaFloatToHex.d.ts +0 -6
  278. package/dist/build/transformers/utilities/rgbaFloatToHex.js +0 -15
  279. package/dist/build/utilities/copyFromDir.d.ts +0 -8
  280. package/dist/build/utilities/copyFromDir.js +0 -34
  281. package/dist/build/utilities/filterStringArray.d.ts +0 -1
  282. package/dist/build/utilities/filterStringArray.js +0 -17
  283. package/dist/build/utilities/getFlag.d.ts +0 -8
  284. package/dist/build/utilities/getFlag.js +0 -16
  285. package/dist/build/utilities/index.d.ts +0 -3
  286. package/dist/build/utilities/index.js +0 -9
  287. package/dist/build/utilities/joinFriendly.d.ts +0 -1
  288. package/dist/build/utilities/joinFriendly.js +0 -5
  289. package/dist/build/utilities/schemaErrorMessage.d.ts +0 -1
  290. package/dist/build/utilities/schemaErrorMessage.js +0 -5
  291. package/dist/build/utilities/toCamelCase.d.ts +0 -1
  292. package/dist/build/utilities/toCamelCase.js +0 -20
  293. package/dist/build/utilities/toPascalCase.d.ts +0 -1
  294. package/dist/build/utilities/toPascalCase.js +0 -17
  295. package/dist/build/utilities/treeWalker.d.ts +0 -8
  296. package/dist/build/utilities/treeWalker.js +0 -27
  297. package/dist/build/utilities/upperCaseFirstCharacter.d.ts +0 -8
  298. package/dist/build/utilities/upperCaseFirstCharacter.js +0 -14
@@ -1,166 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.typescriptExportDefinition = void 0;
7
- const style_dictionary_1 = __importDefault(require("style-dictionary"));
8
- const sync_1 = __importDefault(require("@prettier/sync"));
9
- const fs = require("fs");
10
- const path = require("path");
11
- const treeWalker_1 = require("../utilities/treeWalker");
12
- const prefixTokens_1 = require("./utilities/prefixTokens");
13
- const { fileHeader } = style_dictionary_1.default.formatHelpers;
14
- /**
15
- * unquoteTypes
16
- * @description extract types from designTokenTypes (string with type definitions from file) and replace quoted types "Color" with unquoted Color
17
- * @param output
18
- * @param designTokenTypes
19
- * @returns string with unquoted types
20
- */
21
- const unquoteTypes = (output, designTokenTypes) => {
22
- // join types for replacement
23
- const regex = `"(${['number', 'string', 'any', ...designTokenTypes].join('|')})"`;
24
- // remove strings
25
- return output.replace(new RegExp(regex, 'g'), '$1');
26
- };
27
- /**
28
- * getTokenType
29
- * @description extract content from token files
30
- * @param path string
31
- */
32
- const getTokenType = (tokenTypesPath) => {
33
- try {
34
- const designTokenType = fs.readFileSync(path.resolve(tokenTypesPath), { encoding: 'utf-8' });
35
- return designTokenType;
36
- }
37
- catch (e) {
38
- // eslint-disable-next-line no-console
39
- throw new Error(`Error trying to load design token type from file "${tokenTypesPath}".`);
40
- }
41
- };
42
- /**
43
- * @description throws an error stating the token name, type and invalid value
44
- * @param token w3cTransformedToken
45
- */
46
- const invalidTokenValueError = (token) => {
47
- throw new Error(`Invalid token: "${token.name}" with type "${token.$type}" can not have a value of "${token.value}"`);
48
- };
49
- /**
50
- * convertPropToType
51
- * @description return take type attribute and return correct typescript type as string
52
- * @param type
53
- * @returns
54
- */
55
- const convertPropToType = (tree) => {
56
- if (!Object.prototype.hasOwnProperty.call(tree, 'value')) {
57
- throw new Error(`Invalid token: ${tree}`);
58
- }
59
- switch (tree.$type) {
60
- case 'color':
61
- if (typeof tree.value === 'string' && tree.value[0] === '#') {
62
- return 'ColorHex';
63
- }
64
- return invalidTokenValueError(tree);
65
- case 'dimension':
66
- if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 3) === 'rem')
67
- return 'SizeRem';
68
- if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 2) === 'em')
69
- return 'SizeEm';
70
- if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 2) === 'px')
71
- return 'SizePx';
72
- return invalidTokenValueError(tree);
73
- case 'shadow':
74
- return 'Shadow';
75
- case 'border':
76
- return 'Border';
77
- default:
78
- if (typeof tree.value === 'number')
79
- return 'number';
80
- if (typeof tree.value === 'string')
81
- return 'string';
82
- if (typeof tree.value === 'boolean')
83
- return 'boolean';
84
- return 'any';
85
- }
86
- };
87
- /**
88
- * a valid token node has a `value` property
89
- * @param item object
90
- * @returns boolean
91
- */
92
- const validTokenNode = (item) => {
93
- return typeof item === 'object' && item !== null && 'value' in item;
94
- };
95
- /**
96
- * returns a set with every used token type
97
- * @param item object
98
- * @param validTypes array, all other types will be removed
99
- * @returns set of all used token types
100
- */
101
- const getUsedTokenTypes = (tokens, validTypes) => {
102
- // using a set to assure every value only exists once
103
- const usedTypes = new Set();
104
- // adds type to set
105
- const callback = (tree) => usedTypes.add(convertPropToType(tree));
106
- // tree walker adds to usedTypes
107
- (0, treeWalker_1.treeWalker)(tokens, callback, validTokenNode);
108
- // clean up types
109
- for (const type of usedTypes) {
110
- if (!validTypes.includes(type)) {
111
- usedTypes.delete(type);
112
- }
113
- }
114
- return usedTypes;
115
- };
116
- /**
117
- * returns the entire token object structure but instead of token values each token just has a typescript type
118
- * @param item object
119
- * @returns object
120
- */
121
- const getTokenObjectWithTypes = (tokens) => {
122
- // TODO: FIX typescript issues
123
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
124
- // @ts-ignore
125
- return (0, treeWalker_1.treeWalker)(tokens, convertPropToType, validTokenNode);
126
- };
127
- /**
128
- * getTypeDefinition
129
- * @description returns type definitions as string
130
- * @param tokens
131
- * @param moduleName
132
- * @param tokenTypesPath
133
- * @returns string
134
- */
135
- const getTypeDefinition = (tokens, moduleName, tokenTypesPath) => {
136
- const usedTypes = getUsedTokenTypes(tokens, ['ColorHex', 'Shadow', 'Border', 'SizeEm', 'SizeRem', 'SizePx']);
137
- const tokenObjectWithTypes = getTokenObjectWithTypes(tokens);
138
- // get token type declaration from file
139
- const designTokenTypes = [];
140
- for (const type of usedTypes) {
141
- // path to type files without trailing slash
142
- const typePath = tokenTypesPath.replace(new RegExp(/\/$/, 'g'), '');
143
- designTokenTypes.push(getTokenType(`${typePath}/${type}.d.ts`));
144
- }
145
- // build output
146
- const output = `${designTokenTypes.join('\n')}
147
- export type ${moduleName} = ${JSON.stringify(tokenObjectWithTypes, null, 2)}`;
148
- // JSON stringify will quote strings, because this is a type we need it unquoted.
149
- return unquoteTypes(output, [...usedTypes]);
150
- };
151
- /**
152
- * @description Converts `StyleDictionary.dictionary.tokens` to typescript definition
153
- * @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
154
- * @returns formatted `string`
155
- */
156
- const typescriptExportDefinition = ({ dictionary, file, options = {}, platform, }) => {
157
- // extract options
158
- const { moduleName = `tokens`, tokenTypesPath = `./src/types/` } = options;
159
- // add prefix if defined
160
- const tokens = (0, prefixTokens_1.prefixTokens)(dictionary.tokens, platform);
161
- // add file header and convert output
162
- const output = `${fileHeader({ file })}\n${getTypeDefinition(tokens, moduleName, tokenTypesPath)}\n`;
163
- // return prettified
164
- return sync_1.default.format(output, { parser: 'typescript', printWidth: 500 });
165
- };
166
- exports.typescriptExportDefinition = typescriptExportDefinition;
@@ -1,11 +0,0 @@
1
- import type StyleDictionary from 'style-dictionary';
2
- /**
3
- * jsonToFlat
4
- * @description creates a one dimensional json structure with either a single value or an token object as the value
5
- * @param token StyleDictionary.DesignToken
6
- * @param returnObject - boolean
7
- * @returns flat json three
8
- */
9
- export declare const jsonToFlat: (tokens: StyleDictionary.TransformedToken[], returnObject?: boolean) => {
10
- [k: string]: any;
11
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsonToFlat = void 0;
4
- /**
5
- * jsonToFlat
6
- * @description creates a one dimensional json structure with either a single value or an token object as the value
7
- * @param token StyleDictionary.DesignToken
8
- * @param returnObject - boolean
9
- * @returns flat json three
10
- */
11
- const jsonToFlat = (tokens, returnObject = false) => Object.fromEntries(tokens.map(token => [token.name, returnObject ? token : token.value]));
12
- exports.jsonToFlat = jsonToFlat;
@@ -1,8 +0,0 @@
1
- import type StyleDictionary from 'style-dictionary';
2
- /**
3
- * jsonToNestedValue
4
- * @description creates a nested json tree where every final value is the `.value` prop
5
- * @param token StyleDictionary.DesignToken
6
- * @returns nested json three
7
- */
8
- export declare const jsonToNestedValue: (token: StyleDictionary.DesignToken | Record<string, unknown>) => any;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsonToNestedValue = void 0;
4
- /**
5
- * jsonToNestedValue
6
- * @description creates a nested json tree where every final value is the `.value` prop
7
- * @param token StyleDictionary.DesignToken
8
- * @returns nested json three
9
- */
10
- const jsonToNestedValue = (token) => {
11
- // is non-object value
12
- if (typeof token !== 'object')
13
- return token;
14
- // is design token
15
- if ('value' in token)
16
- return token.value;
17
- // is obj
18
- const nextObj = {};
19
- for (const [prop, value] of Object.entries(token)) {
20
- // @ts-expect-error: can't predict type
21
- nextObj[prop] = (0, exports.jsonToNestedValue)(value);
22
- }
23
- return nextObj;
24
- };
25
- exports.jsonToNestedValue = jsonToNestedValue;
@@ -1,8 +0,0 @@
1
- import type StyleDictionary from 'style-dictionary';
2
- /**
3
- * @description extract prefix from platform and add to tokens array if defined
4
- * @param tokens StyleDictionary.TransformedTokens
5
- * @param platform StyleDictionary.Platform
6
- * @return StyleDictionary.TransformedTokens
7
- */
8
- export declare const prefixTokens: (tokens: StyleDictionary.TransformedTokens, platform?: StyleDictionary.Platform) => StyleDictionary.TransformedTokens;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prefixTokens = void 0;
4
- /**
5
- * @description extract prefix from platform and add to tokens array if defined
6
- * @param tokens StyleDictionary.TransformedTokens
7
- * @param platform StyleDictionary.Platform
8
- * @return StyleDictionary.TransformedTokens
9
- */
10
- const prefixTokens = (tokens, platform = {}) => {
11
- const { prefix } = platform;
12
- if (typeof prefix === 'string') {
13
- tokens = { [prefix]: tokens };
14
- }
15
- return tokens;
16
- };
17
- exports.prefixTokens = prefixTokens;
@@ -1 +0,0 @@
1
- export { w3cJsonParser } from './w3cJsonParser';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.w3cJsonParser = void 0;
4
- var w3cJsonParser_1 = require("./w3cJsonParser");
5
- Object.defineProperty(exports, "w3cJsonParser", { enumerable: true, get: function () { return w3cJsonParser_1.w3cJsonParser; } });
@@ -1,6 +0,0 @@
1
- import type StyleDictionary from 'style-dictionary';
2
- /**
3
- * @description Parses a valid [json5](https://json5.org) file and replaces `$value` with `value` and `$description` with `comment` to make a w3c standard file compatible with style dictionary
4
- * @pattern supported file extensions `.json` or `.json5`
5
- */
6
- export declare const w3cJsonParser: StyleDictionary.Parser;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.w3cJsonParser = void 0;
4
- const json5_1 = require("json5");
5
- /**
6
- * @description Parses a valid [json5](https://json5.org) file and replaces `$value` with `value` and `$description` with `comment` to make a w3c standard file compatible with style dictionary
7
- * @pattern supported file extensions `.json` or `.json5`
8
- */
9
- exports.w3cJsonParser = {
10
- pattern: /\.json5?$/,
11
- parse: ({ filePath, contents }) => {
12
- // replace $value with value so that style dictionary recognizes it
13
- try {
14
- contents = contents
15
- .replace(/["|']?\$value["|']?:/g, '"value":')
16
- // convert $description to comment
17
- .replace(/["|']?\$?description["|']?:/g, '"comment":')
18
- .replace(/["|']?\$?type["|']?:/g, '"$type":')
19
- .replace(/["|']?\$?extensions["|']?:/g, '"$extensions":');
20
- //
21
- return (0, json5_1.parse)(contents);
22
- }
23
- catch (e) {
24
- throw new Error(`Invalid json5 file "${filePath}".`);
25
- }
26
- },
27
- };
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const css: PlatformInitializer;
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.css = void 0;
4
- const filters_1 = require("../filters");
5
- const getCssSelectors = (outputFile) => {
6
- // check for dark in the beginning of the output filename
7
- const lastSlash = outputFile.lastIndexOf('/');
8
- const outputBasename = outputFile.substring(lastSlash + 1, outputFile.indexOf('.'));
9
- const themeName = outputBasename.replace(/-/g, '_');
10
- const mode = outputBasename.substring(0, 4) === 'dark' ? 'dark' : 'light';
11
- return [
12
- {
13
- selector: `[data-color-mode="${mode}"][data-${mode}-theme="${themeName}"], [data-color-mode="${mode}"][data-${mode}-theme="${themeName}"] ::backdrop, [data-color-mode="auto"][data-light-theme="${themeName}"], [data-color-mode="auto"][data-light-theme="${themeName}"] ::backdrop`,
14
- },
15
- {
16
- query: '@media (prefers-color-scheme: dark)',
17
- selector: `[data-color-mode="auto"][data-dark-theme="${themeName}"], [data-color-mode="auto"][data-dark-theme="${themeName}"] ::backdrop`,
18
- },
19
- ];
20
- };
21
- const css = (outputFile, prefix, buildPath, options) => {
22
- return {
23
- prefix,
24
- buildPath,
25
- transforms: [
26
- 'name/pathToKebabCase',
27
- 'color/hex',
28
- 'color/hexMix',
29
- 'dimension/rem',
30
- 'duration/css',
31
- 'shadow/css',
32
- 'border/css',
33
- 'typography/css',
34
- 'fontFamily/css',
35
- 'fontWeight/number',
36
- ],
37
- options: {
38
- basePxFontSize: 16,
39
- },
40
- files: [
41
- {
42
- destination: `${outputFile}`,
43
- format: `css/advanced`,
44
- filter: token => (0, filters_1.isSource)(token) && (options === null || options === void 0 ? void 0 : options.themed) === true,
45
- options: Object.assign({ showFileHeader: false, outputReferences: false, descriptions: false, queries: getCssSelectors(outputFile) }, options === null || options === void 0 ? void 0 : options.options),
46
- },
47
- {
48
- destination: `${outputFile}`,
49
- format: `css/advanced`,
50
- filter: token => (0, filters_1.isSource)(token) && (options === null || options === void 0 ? void 0 : options.themed) !== true,
51
- options: Object.assign({ showFileHeader: false, descriptions: false }, options === null || options === void 0 ? void 0 : options.options),
52
- },
53
- {
54
- destination: `${outputFile}`,
55
- format: `css/customMedia`,
56
- filter: token => (0, filters_1.isSource)(token) && (options === null || options === void 0 ? void 0 : options.themed) !== true && token.$type === 'custom-viewportRange',
57
- options: {
58
- showFileHeader: false,
59
- },
60
- },
61
- {
62
- destination: `${outputFile}`,
63
- format: `css/advanced`,
64
- filter: token => (0, filters_1.isSource)(token) &&
65
- (0, filters_1.isFromFile)(token, [
66
- 'src/tokens/functional/size/size-coarse.json',
67
- 'src/tokens/functional/size/size-fine.json',
68
- ]),
69
- options: {
70
- descriptions: false,
71
- showFileHeader: false,
72
- queries: [
73
- {
74
- query: '@media (pointer: fine)',
75
- matcher: (token) => token.filePath.includes('size-fine'),
76
- },
77
- {
78
- query: '@media (pointer: coarse)',
79
- matcher: (token) => token.filePath.includes('size-coarse'),
80
- },
81
- ],
82
- },
83
- },
84
- ],
85
- };
86
- };
87
- exports.css = css;
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const deprecatedJson: PlatformInitializer;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deprecatedJson = void 0;
4
- const filters_1 = require("../filters");
5
- const deprecatedJson = (outputFile, prefix, buildPath) => ({
6
- prefix,
7
- buildPath,
8
- transforms: ['name/pathToDotNotation', 'json/deprecated'],
9
- files: [
10
- {
11
- destination: outputFile,
12
- format: `json/flat`,
13
- filter: filters_1.isDeprecated,
14
- },
15
- ],
16
- });
17
- exports.deprecatedJson = deprecatedJson;
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const docJson: PlatformInitializer;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.docJson = void 0;
4
- const filters_1 = require("../filters");
5
- const docJson = (outputFile, prefix, buildPath) => ({
6
- prefix,
7
- buildPath,
8
- transforms: [
9
- 'name/pathToKebabCase',
10
- 'color/hex',
11
- 'color/hexMix',
12
- 'dimension/rem',
13
- 'shadow/css',
14
- 'border/css',
15
- 'typography/css',
16
- 'fontFamily/css',
17
- 'fontWeight/number',
18
- ],
19
- options: {
20
- basePxFontSize: 16,
21
- },
22
- files: [
23
- {
24
- destination: outputFile,
25
- format: `json/one-dimensional`,
26
- filter: filters_1.isSource,
27
- options: {
28
- outputReferences: false,
29
- outputVerbose: true,
30
- },
31
- },
32
- ],
33
- });
34
- exports.docJson = docJson;
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const fallbacks: PlatformInitializer;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fallbacks = void 0;
4
- const filters_1 = require("../filters");
5
- const fallbacks = (outputFile, prefix, buildPath) => ({
6
- prefix,
7
- buildPath,
8
- transforms: [
9
- 'name/pathToKebabCase',
10
- 'color/hex',
11
- 'color/hexMix',
12
- 'dimension/rem',
13
- 'shadow/css',
14
- 'border/css',
15
- 'typography/css',
16
- 'fontFamily/css',
17
- 'fontWeight/number',
18
- ],
19
- options: {
20
- basePxFontSize: 16,
21
- },
22
- files: [
23
- {
24
- destination: outputFile,
25
- format: `json/postCss-fallback`,
26
- filter: filters_1.isSource,
27
- options: {
28
- outputReferences: false,
29
- outputVerbose: true,
30
- },
31
- },
32
- ],
33
- });
34
- exports.fallbacks = fallbacks;
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const figma: PlatformInitializer;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.figma = void 0;
4
- const filters_1 = require("../filters");
5
- const validFigmaToken = (token) => {
6
- const validTypes = ['color', 'dimension', 'shadow', 'fontWeight', 'fontFamily', 'number'];
7
- // is a siource token, not an included one
8
- if (!(0, filters_1.isSource)(token))
9
- return false;
10
- if (`${token.value}`.substring(token.value.length - 2) === 'em')
11
- return false;
12
- // has a collection attribute
13
- if (!('$extensions' in token) ||
14
- !('org.primer.figma' in token.$extensions) ||
15
- !('collection' in token.$extensions['org.primer.figma']))
16
- return false;
17
- // is a color or dimension type
18
- return validTypes.includes(token.$type);
19
- };
20
- const figma = (outputFile, prefix, buildPath, options) => ({
21
- prefix,
22
- buildPath,
23
- transforms: [
24
- 'color/rgbaFloat',
25
- 'name/pathToFigma',
26
- // 'name/pathToSlashNotation',
27
- 'figma/attributes',
28
- 'fontFamily/figma',
29
- 'float/pixelUnitless',
30
- 'dimension/pixelUnitless',
31
- // 'border/figma',
32
- // 'typography/figma',
33
- 'fontWeight/number',
34
- ],
35
- options: Object.assign({ basePxFontSize: 16, fontFamilies: {
36
- 'fontStack/system': 'SF Pro Text',
37
- 'fontStack/sansSerif': 'SF Pro Text',
38
- 'fontStack/sansSerifDisplay': 'SF Pro Display',
39
- 'fontStack/monospace': 'SF Mono',
40
- } }, options),
41
- files: [
42
- {
43
- destination: outputFile,
44
- filter: validFigmaToken,
45
- format: `json/figma`,
46
- options: {
47
- outputReferences: true,
48
- mode: options === null || options === void 0 ? void 0 : options.mode,
49
- },
50
- },
51
- ],
52
- });
53
- exports.figma = figma;
@@ -1,10 +0,0 @@
1
- export { css } from './css';
2
- export { deprecatedJson } from './deprecatedJson';
3
- export { docJson } from './docJson';
4
- export { fallbacks } from './fallbacks';
5
- export { figma } from './figma';
6
- export { javascript } from './javascript';
7
- export { json } from './json';
8
- export { styleLint } from './styleLint';
9
- export { typeDefinitions } from './typeDefinitions';
10
- export { typescript } from './typescript';
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typescript = exports.typeDefinitions = exports.styleLint = exports.json = exports.javascript = exports.figma = exports.fallbacks = exports.docJson = exports.deprecatedJson = exports.css = void 0;
4
- var css_1 = require("./css");
5
- Object.defineProperty(exports, "css", { enumerable: true, get: function () { return css_1.css; } });
6
- var deprecatedJson_1 = require("./deprecatedJson");
7
- Object.defineProperty(exports, "deprecatedJson", { enumerable: true, get: function () { return deprecatedJson_1.deprecatedJson; } });
8
- var docJson_1 = require("./docJson");
9
- Object.defineProperty(exports, "docJson", { enumerable: true, get: function () { return docJson_1.docJson; } });
10
- var fallbacks_1 = require("./fallbacks");
11
- Object.defineProperty(exports, "fallbacks", { enumerable: true, get: function () { return fallbacks_1.fallbacks; } });
12
- var figma_1 = require("./figma");
13
- Object.defineProperty(exports, "figma", { enumerable: true, get: function () { return figma_1.figma; } });
14
- var javascript_1 = require("./javascript");
15
- Object.defineProperty(exports, "javascript", { enumerable: true, get: function () { return javascript_1.javascript; } });
16
- var json_1 = require("./json");
17
- Object.defineProperty(exports, "json", { enumerable: true, get: function () { return json_1.json; } });
18
- var styleLint_1 = require("./styleLint");
19
- Object.defineProperty(exports, "styleLint", { enumerable: true, get: function () { return styleLint_1.styleLint; } });
20
- var typeDefinitions_1 = require("./typeDefinitions");
21
- Object.defineProperty(exports, "typeDefinitions", { enumerable: true, get: function () { return typeDefinitions_1.typeDefinitions; } });
22
- var typescript_1 = require("./typescript");
23
- Object.defineProperty(exports, "typescript", { enumerable: true, get: function () { return typescript_1.typescript; } });
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const javascript: PlatformInitializer;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.javascript = void 0;
4
- const filters_1 = require("../filters");
5
- const javascript = (outputFile, prefix, buildPath) => ({
6
- prefix,
7
- buildPath,
8
- transforms: [
9
- 'color/hex',
10
- 'color/hexMix',
11
- 'dimension/rem',
12
- 'shadow/css',
13
- 'border/css',
14
- 'typography/css',
15
- 'fontFamily/css',
16
- 'fontWeight/number',
17
- ],
18
- options: {
19
- showFileHeader: false,
20
- basePxFontSize: 16,
21
- },
22
- files: [
23
- {
24
- format: 'javascript/commonJs',
25
- destination: outputFile,
26
- filter: filters_1.isSource,
27
- },
28
- ],
29
- });
30
- exports.javascript = javascript;
@@ -1,2 +0,0 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer';
2
- export declare const json: PlatformInitializer;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.json = void 0;
4
- const filters_1 = require("../filters");
5
- const json = (outputFile, prefix, buildPath) => ({
6
- prefix,
7
- buildPath,
8
- transforms: [
9
- 'color/hex',
10
- 'color/hexMix',
11
- 'dimension/rem',
12
- 'shadow/css',
13
- 'border/css',
14
- 'typography/css',
15
- 'fontFamily/css',
16
- 'fontWeight/number',
17
- ],
18
- options: {
19
- basePxFontSize: 16,
20
- },
21
- files: [
22
- {
23
- destination: outputFile,
24
- filter: filters_1.isSource,
25
- format: `json/nested-prefixed`,
26
- options: {
27
- outputReferences: false,
28
- },
29
- },
30
- ],
31
- });
32
- exports.json = json;