@atlaskit/tokens 13.0.4 → 13.1.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 (343) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/codemods/css-to-design-tokens/lib/colors.tsx +3 -8
  3. package/codemods/css-to-design-tokens/lib/declaration.tsx +3 -13
  4. package/codemods/css-to-design-tokens/lib/extract-between-parentheses.tsx +4 -0
  5. package/codemods/css-to-design-tokens/lib/extract-less-var-name.tsx +3 -0
  6. package/codemods/css-to-design-tokens/lib/get-css-var-meta.tsx +13 -0
  7. package/codemods/css-to-design-tokens/lib/get-named-color-meta.tsx +5 -0
  8. package/codemods/css-to-design-tokens/lib/get-raw-color-meta.tsx +11 -0
  9. package/codemods/css-to-design-tokens/lib/is-css-declaration.tsx +3 -0
  10. package/codemods/css-to-design-tokens/lib/is-known-css-variable.tsx +5 -0
  11. package/codemods/css-to-design-tokens/lib/known-named-colors.tsx +150 -0
  12. package/codemods/css-to-design-tokens/lib/known-raw-colors.tsx +17 -0
  13. package/codemods/css-to-design-tokens/lib/known-variables.tsx +167 -0
  14. package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +3 -335
  15. package/codemods/css-to-design-tokens/lib/meta.tsx +3 -28
  16. package/codemods/css-to-design-tokens/lib/split-css-value.tsx +4 -0
  17. package/codemods/css-to-design-tokens/lib/value.tsx +6 -9
  18. package/codemods/css-to-design-tokens/transform.tsx +3 -1
  19. package/dist/cjs/artifacts/palettes-raw/palette.js +35 -1
  20. package/dist/cjs/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
  21. package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
  22. package/dist/cjs/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
  23. package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
  24. package/dist/cjs/artifacts/token-default-values.js +2 -2
  25. package/dist/cjs/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
  26. package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +3 -3
  27. package/dist/cjs/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
  28. package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +3 -3
  29. package/dist/cjs/constants.js +1 -0
  30. package/dist/cjs/entry-points/theme-state-transformer.js +4 -3
  31. package/dist/cjs/entry-points/token-metadata.codegen.js +2 -2
  32. package/dist/cjs/get-custom-theme-styles.js +7 -6
  33. package/dist/cjs/get-global-theme.js +2 -2
  34. package/dist/cjs/get-theme-html-attrs.js +2 -2
  35. package/dist/cjs/get-theme-styles.js +27 -27
  36. package/dist/cjs/index.js +4 -3
  37. package/dist/cjs/is-color-mode.js +9 -0
  38. package/dist/cjs/is-theme-ids.js +12 -0
  39. package/dist/cjs/is-theme-kind.js +12 -0
  40. package/dist/cjs/set-global-theme.js +32 -31
  41. package/dist/cjs/theme-config.js +9 -43
  42. package/dist/cjs/theme-object-to-string.js +42 -0
  43. package/dist/cjs/theme-options-schema.js +1 -0
  44. package/dist/cjs/theme-state-defaults.js +39 -0
  45. package/dist/cjs/theme-state.js +5 -0
  46. package/dist/cjs/theme-string-to-object.js +51 -0
  47. package/dist/cjs/utils/additional-contrast-checker.js +43 -0
  48. package/dist/cjs/utils/custom-theme-loading-utils.js +0 -20
  49. package/dist/cjs/utils/custom-theme-token-contrast-check.js +2 -38
  50. package/dist/cjs/utils/delta-e.js +26 -0
  51. package/dist/cjs/utils/generate-colors.js +47 -0
  52. package/dist/cjs/utils/generate-token-map-with-contrast-check.js +32 -0
  53. package/dist/cjs/utils/{generate-custom-color-ramp.js → generate-token-map.js} +6 -71
  54. package/dist/cjs/utils/get-closest-color-index.js +3 -2
  55. package/dist/cjs/utils/get-contrast-ratio.js +22 -0
  56. package/dist/cjs/utils/hct-color-utils/alpha-from-argb.js +12 -0
  57. package/dist/cjs/utils/hct-color-utils/argb-from-linrgb.js +17 -0
  58. package/dist/cjs/utils/hct-color-utils/argb-from-lstar.js +21 -0
  59. package/dist/cjs/utils/hct-color-utils/argb-from-rgba.js +24 -0
  60. package/dist/cjs/utils/hct-color-utils/argb-from-xyz.js +29 -0
  61. package/dist/cjs/utils/hct-color-utils/blue-from-argb.js +12 -0
  62. package/dist/cjs/utils/hct-color-utils/clamp-component.js +15 -0
  63. package/dist/cjs/utils/hct-color-utils/contrast.js +10 -11
  64. package/dist/cjs/utils/hct-color-utils/green-from-argb.js +12 -0
  65. package/dist/cjs/utils/hct-color-utils/hct.js +18 -12
  66. package/dist/cjs/utils/hct-color-utils/index.js +4 -3
  67. package/dist/cjs/utils/hct-color-utils/lab-f.js +15 -0
  68. package/dist/cjs/utils/hct-color-utils/lab-invf.js +16 -0
  69. package/dist/cjs/utils/hct-color-utils/lstar-from-argb.js +34 -0
  70. package/dist/cjs/utils/hct-color-utils/lstar-from-y.js +21 -0
  71. package/dist/cjs/utils/hct-color-utils/red-from-argb.js +12 -0
  72. package/dist/cjs/utils/hct-color-utils/rgba-from-argb.js +28 -0
  73. package/dist/cjs/utils/hct-color-utils/rgba.js +1 -0
  74. package/dist/cjs/utils/hct-color-utils/viewing-conditions.js +5 -4
  75. package/dist/cjs/utils/hct-color-utils/white-point-d65.js +14 -0
  76. package/dist/cjs/utils/hct-color-utils/y-from-lstar.js +21 -0
  77. package/dist/cjs/utils/hex-to-hsl.js +52 -0
  78. package/dist/cjs/utils/hex-to-rgb-a.js +20 -0
  79. package/dist/cjs/utils/hex-to-rgb.js +19 -0
  80. package/dist/cjs/utils/is-valid-hex.js +10 -0
  81. package/dist/cjs/utils/load-theme-css.js +4 -4
  82. package/dist/cjs/utils/reduce-token-map.js +18 -0
  83. package/dist/cjs/utils/rgb-to-lab.js +24 -0
  84. package/dist/cjs/utils/theme-loading.js +8 -8
  85. package/dist/es2019/artifacts/palettes-raw/palette.js +35 -1
  86. package/dist/es2019/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
  87. package/dist/es2019/artifacts/themes/atlassian-dark.js +2 -2
  88. package/dist/es2019/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
  89. package/dist/es2019/artifacts/themes/atlassian-light.js +2 -2
  90. package/dist/es2019/artifacts/token-default-values.js +2 -2
  91. package/dist/es2019/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
  92. package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +3 -3
  93. package/dist/es2019/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
  94. package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +3 -3
  95. package/dist/es2019/constants.js +1 -0
  96. package/dist/es2019/entry-points/theme-state-transformer.js +2 -1
  97. package/dist/es2019/entry-points/token-metadata.codegen.js +2 -2
  98. package/dist/es2019/get-custom-theme-styles.js +3 -2
  99. package/dist/es2019/get-global-theme.js +1 -1
  100. package/dist/es2019/get-theme-html-attrs.js +1 -1
  101. package/dist/es2019/index.js +2 -1
  102. package/dist/es2019/is-color-mode.js +3 -0
  103. package/dist/es2019/is-theme-ids.js +4 -0
  104. package/dist/es2019/is-theme-kind.js +4 -0
  105. package/dist/es2019/theme-config.js +5 -44
  106. package/dist/es2019/theme-object-to-string.js +28 -0
  107. package/dist/es2019/theme-options-schema.js +0 -0
  108. package/dist/es2019/theme-state-defaults.js +34 -0
  109. package/dist/es2019/theme-state.js +1 -0
  110. package/dist/es2019/theme-string-to-object.js +38 -0
  111. package/dist/es2019/utils/additional-contrast-checker.js +39 -0
  112. package/dist/es2019/utils/custom-theme-loading-utils.js +1 -9
  113. package/dist/es2019/utils/custom-theme-token-contrast-check.js +1 -39
  114. package/dist/es2019/utils/delta-e.js +20 -0
  115. package/dist/es2019/utils/generate-colors.js +39 -0
  116. package/dist/es2019/utils/generate-token-map-with-contrast-check.js +21 -0
  117. package/dist/es2019/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -59
  118. package/dist/es2019/utils/get-closest-color-index.js +2 -1
  119. package/dist/es2019/utils/get-contrast-ratio.js +16 -0
  120. package/dist/es2019/utils/hct-color-utils/alpha-from-argb.js +6 -0
  121. package/dist/es2019/utils/hct-color-utils/argb-from-linrgb.js +12 -0
  122. package/dist/es2019/utils/hct-color-utils/argb-from-lstar.js +16 -0
  123. package/dist/es2019/utils/hct-color-utils/argb-from-rgba.js +19 -0
  124. package/dist/es2019/utils/hct-color-utils/argb-from-xyz.js +24 -0
  125. package/dist/es2019/utils/hct-color-utils/blue-from-argb.js +6 -0
  126. package/dist/es2019/utils/hct-color-utils/clamp-component.js +9 -0
  127. package/dist/es2019/utils/hct-color-utils/contrast.js +10 -10
  128. package/dist/es2019/utils/hct-color-utils/green-from-argb.js +6 -0
  129. package/dist/es2019/utils/hct-color-utils/hct.js +19 -12
  130. package/dist/es2019/utils/hct-color-utils/index.js +2 -1
  131. package/dist/es2019/utils/hct-color-utils/lab-f.js +9 -0
  132. package/dist/es2019/utils/hct-color-utils/lab-invf.js +10 -0
  133. package/dist/es2019/utils/hct-color-utils/lstar-from-argb.js +28 -0
  134. package/dist/es2019/utils/hct-color-utils/lstar-from-y.js +16 -0
  135. package/dist/es2019/utils/hct-color-utils/red-from-argb.js +6 -0
  136. package/dist/es2019/utils/hct-color-utils/rgba-from-argb.js +22 -0
  137. package/dist/es2019/utils/hct-color-utils/rgba.js +0 -0
  138. package/dist/es2019/utils/hct-color-utils/viewing-conditions.js +4 -3
  139. package/dist/es2019/utils/hct-color-utils/white-point-d65.js +8 -0
  140. package/dist/es2019/utils/hct-color-utils/y-from-lstar.js +16 -0
  141. package/dist/es2019/utils/hex-to-hsl.js +46 -0
  142. package/dist/es2019/utils/hex-to-rgb-a.js +14 -0
  143. package/dist/es2019/utils/hex-to-rgb.js +13 -0
  144. package/dist/es2019/utils/is-valid-hex.js +2 -0
  145. package/dist/es2019/utils/reduce-token-map.js +7 -0
  146. package/dist/es2019/utils/rgb-to-lab.js +18 -0
  147. package/dist/esm/artifacts/palettes-raw/palette.js +35 -1
  148. package/dist/esm/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
  149. package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
  150. package/dist/esm/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
  151. package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
  152. package/dist/esm/artifacts/token-default-values.js +2 -2
  153. package/dist/esm/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +3 -3
  154. package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +3 -3
  155. package/dist/esm/artifacts/tokens-raw/atlassian-light-increased-contrast.js +3 -3
  156. package/dist/esm/artifacts/tokens-raw/atlassian-light.js +3 -3
  157. package/dist/esm/constants.js +1 -0
  158. package/dist/esm/entry-points/theme-state-transformer.js +2 -1
  159. package/dist/esm/entry-points/token-metadata.codegen.js +2 -2
  160. package/dist/esm/get-custom-theme-styles.js +3 -2
  161. package/dist/esm/get-global-theme.js +1 -1
  162. package/dist/esm/get-theme-html-attrs.js +1 -1
  163. package/dist/esm/get-theme-styles.js +26 -26
  164. package/dist/esm/index.js +2 -1
  165. package/dist/esm/is-color-mode.js +3 -0
  166. package/dist/esm/is-theme-ids.js +6 -0
  167. package/dist/esm/is-theme-kind.js +6 -0
  168. package/dist/esm/set-global-theme.js +31 -30
  169. package/dist/esm/theme-config.js +5 -44
  170. package/dist/esm/theme-object-to-string.js +35 -0
  171. package/dist/esm/theme-options-schema.js +0 -0
  172. package/dist/esm/theme-state-defaults.js +34 -0
  173. package/dist/esm/theme-state.js +1 -0
  174. package/dist/esm/theme-string-to-object.js +44 -0
  175. package/dist/esm/utils/additional-contrast-checker.js +36 -0
  176. package/dist/esm/utils/custom-theme-loading-utils.js +1 -13
  177. package/dist/esm/utils/custom-theme-token-contrast-check.js +1 -36
  178. package/dist/esm/utils/delta-e.js +20 -0
  179. package/dist/esm/utils/generate-colors.js +40 -0
  180. package/dist/esm/utils/generate-token-map-with-contrast-check.js +25 -0
  181. package/dist/esm/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -63
  182. package/dist/esm/utils/get-closest-color-index.js +2 -1
  183. package/dist/esm/utils/get-contrast-ratio.js +16 -0
  184. package/dist/esm/utils/hct-color-utils/alpha-from-argb.js +6 -0
  185. package/dist/esm/utils/hct-color-utils/argb-from-linrgb.js +12 -0
  186. package/dist/esm/utils/hct-color-utils/argb-from-lstar.js +16 -0
  187. package/dist/esm/utils/hct-color-utils/argb-from-rgba.js +18 -0
  188. package/dist/esm/utils/hct-color-utils/argb-from-xyz.js +24 -0
  189. package/dist/esm/utils/hct-color-utils/blue-from-argb.js +6 -0
  190. package/dist/esm/utils/hct-color-utils/clamp-component.js +9 -0
  191. package/dist/esm/utils/hct-color-utils/contrast.js +10 -10
  192. package/dist/esm/utils/hct-color-utils/green-from-argb.js +6 -0
  193. package/dist/esm/utils/hct-color-utils/hct.js +19 -12
  194. package/dist/esm/utils/hct-color-utils/index.js +2 -1
  195. package/dist/esm/utils/hct-color-utils/lab-f.js +9 -0
  196. package/dist/esm/utils/hct-color-utils/lab-invf.js +10 -0
  197. package/dist/esm/utils/hct-color-utils/lstar-from-argb.js +28 -0
  198. package/dist/esm/utils/hct-color-utils/lstar-from-y.js +16 -0
  199. package/dist/esm/utils/hct-color-utils/red-from-argb.js +6 -0
  200. package/dist/esm/utils/hct-color-utils/rgba-from-argb.js +22 -0
  201. package/dist/esm/utils/hct-color-utils/rgba.js +0 -0
  202. package/dist/esm/utils/hct-color-utils/viewing-conditions.js +5 -4
  203. package/dist/esm/utils/hct-color-utils/white-point-d65.js +8 -0
  204. package/dist/esm/utils/hct-color-utils/y-from-lstar.js +16 -0
  205. package/dist/esm/utils/hex-to-hsl.js +46 -0
  206. package/dist/esm/utils/hex-to-rgb-a.js +14 -0
  207. package/dist/esm/utils/hex-to-rgb.js +13 -0
  208. package/dist/esm/utils/is-valid-hex.js +4 -0
  209. package/dist/esm/utils/load-theme-css.js +4 -4
  210. package/dist/esm/utils/reduce-token-map.js +11 -0
  211. package/dist/esm/utils/rgb-to-lab.js +18 -0
  212. package/dist/esm/utils/theme-loading.js +8 -8
  213. package/dist/types/artifacts/palettes-raw/palette.d.ts +1 -1
  214. package/dist/types/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
  215. package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
  216. package/dist/types/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
  217. package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
  218. package/dist/types/artifacts/token-default-values.d.ts +2 -2
  219. package/dist/types/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
  220. package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
  221. package/dist/types/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
  222. package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
  223. package/dist/types/entry-points/theme-state-transformer.d.ts +2 -1
  224. package/dist/types/entry-points/token-metadata.codegen.d.ts +1 -1
  225. package/dist/types/index.d.ts +2 -1
  226. package/dist/types/is-color-mode.d.ts +2 -0
  227. package/dist/types/is-theme-ids.d.ts +2 -0
  228. package/dist/types/is-theme-kind.d.ts +4 -0
  229. package/dist/types/theme-color-modes.d.ts +1 -0
  230. package/dist/types/theme-config.d.ts +8 -40
  231. package/dist/types/theme-ids.d.ts +1 -0
  232. package/dist/types/theme-object-to-string.d.ts +13 -0
  233. package/dist/types/theme-options-schema.d.ts +7 -0
  234. package/dist/types/theme-state-defaults.d.ts +14 -0
  235. package/dist/types/theme-state.d.ts +17 -0
  236. package/dist/types/{theme-state-transformer.d.ts → theme-string-to-object.d.ts} +0 -12
  237. package/dist/types/utils/additional-contrast-checker.d.ts +9 -0
  238. package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -6
  239. package/dist/types/utils/custom-theme-token-contrast-check.d.ts +0 -9
  240. package/dist/types/utils/delta-e.d.ts +1 -0
  241. package/dist/types/utils/generate-colors.d.ts +5 -0
  242. package/dist/types/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -6
  243. package/dist/types/utils/generate-token-map.d.ts +9 -0
  244. package/dist/types/utils/get-contrast-ratio.d.ts +1 -0
  245. package/dist/types/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
  246. package/dist/types/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
  247. package/dist/types/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
  248. package/dist/types/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
  249. package/dist/types/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
  250. package/dist/types/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
  251. package/dist/types/utils/hct-color-utils/clamp-component.d.ts +1 -0
  252. package/dist/types/utils/hct-color-utils/green-from-argb.d.ts +4 -0
  253. package/dist/types/utils/hct-color-utils/index.d.ts +2 -1
  254. package/dist/types/utils/hct-color-utils/lab-f.d.ts +1 -0
  255. package/dist/types/utils/hct-color-utils/lab-invf.d.ts +1 -0
  256. package/dist/types/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
  257. package/dist/types/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
  258. package/dist/types/utils/hct-color-utils/red-from-argb.d.ts +4 -0
  259. package/dist/types/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
  260. package/dist/types/utils/hct-color-utils/rgba.d.ts +14 -0
  261. package/dist/types/utils/hct-color-utils/white-point-d65.d.ts +6 -0
  262. package/dist/types/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
  263. package/dist/types/utils/hex-to-hsl.d.ts +1 -0
  264. package/dist/types/utils/hex-to-rgb-a.d.ts +1 -0
  265. package/dist/types/utils/hex-to-rgb.d.ts +1 -0
  266. package/dist/types/utils/is-valid-hex.d.ts +1 -0
  267. package/dist/types/utils/reduce-token-map.d.ts +6 -0
  268. package/dist/types/utils/rgb-to-lab.d.ts +1 -0
  269. package/dist/types-ts4.5/artifacts/palettes-raw/palette.d.ts +1 -1
  270. package/dist/types-ts4.5/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
  271. package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
  272. package/dist/types-ts4.5/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
  273. package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
  274. package/dist/types-ts4.5/artifacts/token-default-values.d.ts +2 -2
  275. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
  276. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
  277. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
  278. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
  279. package/dist/types-ts4.5/entry-points/theme-state-transformer.d.ts +2 -1
  280. package/dist/types-ts4.5/entry-points/token-metadata.codegen.d.ts +1 -1
  281. package/dist/types-ts4.5/index.d.ts +2 -1
  282. package/dist/types-ts4.5/is-color-mode.d.ts +2 -0
  283. package/dist/types-ts4.5/is-theme-ids.d.ts +2 -0
  284. package/dist/types-ts4.5/is-theme-kind.d.ts +11 -0
  285. package/dist/types-ts4.5/theme-color-modes.d.ts +1 -0
  286. package/dist/types-ts4.5/theme-config.d.ts +8 -40
  287. package/dist/types-ts4.5/theme-ids.d.ts +1 -0
  288. package/dist/types-ts4.5/theme-object-to-string.d.ts +13 -0
  289. package/dist/types-ts4.5/theme-options-schema.d.ts +7 -0
  290. package/dist/types-ts4.5/theme-state-defaults.d.ts +14 -0
  291. package/dist/types-ts4.5/theme-state.d.ts +17 -0
  292. package/dist/types-ts4.5/{theme-state-transformer.d.ts → theme-string-to-object.d.ts} +0 -12
  293. package/dist/types-ts4.5/utils/additional-contrast-checker.d.ts +9 -0
  294. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -6
  295. package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +0 -9
  296. package/dist/types-ts4.5/utils/delta-e.d.ts +1 -0
  297. package/dist/types-ts4.5/utils/generate-colors.d.ts +5 -0
  298. package/dist/types-ts4.5/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -8
  299. package/dist/types-ts4.5/utils/generate-token-map.d.ts +11 -0
  300. package/dist/types-ts4.5/utils/get-contrast-ratio.d.ts +1 -0
  301. package/dist/types-ts4.5/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
  302. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
  303. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
  304. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
  305. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
  306. package/dist/types-ts4.5/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
  307. package/dist/types-ts4.5/utils/hct-color-utils/clamp-component.d.ts +1 -0
  308. package/dist/types-ts4.5/utils/hct-color-utils/green-from-argb.d.ts +4 -0
  309. package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +2 -1
  310. package/dist/types-ts4.5/utils/hct-color-utils/lab-f.d.ts +1 -0
  311. package/dist/types-ts4.5/utils/hct-color-utils/lab-invf.d.ts +1 -0
  312. package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
  313. package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
  314. package/dist/types-ts4.5/utils/hct-color-utils/red-from-argb.d.ts +4 -0
  315. package/dist/types-ts4.5/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
  316. package/dist/types-ts4.5/utils/hct-color-utils/rgba.d.ts +14 -0
  317. package/dist/types-ts4.5/utils/hct-color-utils/white-point-d65.d.ts +6 -0
  318. package/dist/types-ts4.5/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
  319. package/dist/types-ts4.5/utils/hex-to-hsl.d.ts +5 -0
  320. package/dist/types-ts4.5/utils/hex-to-rgb-a.d.ts +6 -0
  321. package/dist/types-ts4.5/utils/hex-to-rgb.d.ts +5 -0
  322. package/dist/types-ts4.5/utils/is-valid-hex.d.ts +1 -0
  323. package/dist/types-ts4.5/utils/reduce-token-map.d.ts +6 -0
  324. package/dist/types-ts4.5/utils/rgb-to-lab.d.ts +5 -0
  325. package/figma/atlassian-dark-increased-contrast.json +1 -1
  326. package/figma/atlassian-dark.json +1 -1
  327. package/figma/atlassian-light-increased-contrast.json +1 -1
  328. package/figma/atlassian-light.json +1 -1
  329. package/package.json +12 -12
  330. package/tokens.docs.tsx +48 -46
  331. package/dist/cjs/theme-state-transformer.js +0 -92
  332. package/dist/cjs/utils/color-utils.js +0 -168
  333. package/dist/cjs/utils/hct-color-utils/color-utils.js +0 -271
  334. package/dist/es2019/theme-state-transformer.js +0 -69
  335. package/dist/es2019/utils/color-utils.js +0 -128
  336. package/dist/es2019/utils/hct-color-utils/color-utils.js +0 -241
  337. package/dist/esm/theme-state-transformer.js +0 -85
  338. package/dist/esm/utils/color-utils.js +0 -130
  339. package/dist/esm/utils/hct-color-utils/color-utils.js +0 -240
  340. package/dist/types/utils/color-utils.d.ts +0 -10
  341. package/dist/types/utils/hct-color-utils/color-utils.d.ts +0 -88
  342. package/dist/types-ts4.5/utils/color-utils.d.ts +0 -23
  343. package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +0 -88
@@ -0,0 +1,6 @@
1
+ var themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape', 'motion'];
2
+ export var isThemeKind = function isThemeKind(themeKind) {
3
+ return themeKinds.find(function (kind) {
4
+ return kind === themeKind;
5
+ }) !== undefined;
6
+ };
@@ -72,8 +72,9 @@ var setGlobalTheme = /*#__PURE__*/function () {
72
72
  _step,
73
73
  themeId,
74
74
  autoUnbind,
75
- _args3 = arguments;
76
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
75
+ _args3 = arguments,
76
+ _t;
77
+ return _regeneratorRuntime.wrap(function (_context3) {
77
78
  while (1) switch (_context3.prev = _context3.next) {
78
79
  case 0:
79
80
  nextThemeState = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
@@ -107,14 +108,14 @@ var setGlobalTheme = /*#__PURE__*/function () {
107
108
  loadingStrategy = themeLoader ? themeLoader : loadAndAppendThemeCss; // Load standard themes
108
109
  loadingTasks = themePreferences.map( /*#__PURE__*/function () {
109
110
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(themeId) {
110
- return _regeneratorRuntime.wrap(function _callee$(_context) {
111
+ return _regeneratorRuntime.wrap(function (_context) {
111
112
  while (1) switch (_context.prev = _context.next) {
112
113
  case 0:
113
- _context.next = 2;
114
+ _context.next = 1;
114
115
  return loadingStrategy(themeId);
115
- case 2:
116
+ case 1:
116
117
  return _context.abrupt("return", _context.sent);
117
- case 3:
118
+ case 2:
118
119
  case "end":
119
120
  return _context.stop();
120
121
  }
@@ -131,13 +132,13 @@ var setGlobalTheme = /*#__PURE__*/function () {
131
132
  // Load custom theme styles
132
133
  loadingTasks.push(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
133
134
  var _yield$import, loadAndAppendCustomThemeCss;
134
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
135
+ return _regeneratorRuntime.wrap(function (_context2) {
135
136
  while (1) switch (_context2.prev = _context2.next) {
136
137
  case 0:
137
- _context2.next = 2;
138
+ _context2.next = 1;
138
139
  return import( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
139
140
  './custom-theme');
140
- case 2:
141
+ case 1:
141
142
  _yield$import = _context2.sent;
142
143
  loadAndAppendCustomThemeCss = _yield$import.loadAndAppendCustomThemeCss;
143
144
  loadAndAppendCustomThemeCss({
@@ -146,7 +147,7 @@ var setGlobalTheme = /*#__PURE__*/function () {
146
147
  attrOfMissingCustomStyles[0],
147
148
  UNSAFE_themeOptions: UNSAFE_themeOptions
148
149
  });
149
- case 5:
150
+ case 2:
150
151
  case "end":
151
152
  return _context2.stop();
152
153
  }
@@ -154,44 +155,44 @@ var setGlobalTheme = /*#__PURE__*/function () {
154
155
  }))());
155
156
  }
156
157
  }
157
- _context3.next = 11;
158
+ _context3.next = 1;
158
159
  return Promise.all(loadingTasks);
159
- case 11:
160
+ case 1:
160
161
  // Load override themes after standard themes
161
162
  themeOverridePreferences = getThemeOverridePreferences(themeState);
162
163
  _iterator = _createForOfIteratorHelper(themeOverridePreferences);
163
- _context3.prev = 13;
164
+ _context3.prev = 2;
164
165
  _iterator.s();
165
- case 15:
166
+ case 3:
166
167
  if ((_step = _iterator.n()).done) {
167
- _context3.next = 21;
168
+ _context3.next = 5;
168
169
  break;
169
170
  }
170
171
  themeId = _step.value;
171
- _context3.next = 19;
172
+ _context3.next = 4;
172
173
  return loadingStrategy(themeId);
173
- case 19:
174
- _context3.next = 15;
174
+ case 4:
175
+ _context3.next = 3;
175
176
  break;
176
- case 21:
177
- _context3.next = 26;
177
+ case 5:
178
+ _context3.next = 7;
178
179
  break;
179
- case 23:
180
- _context3.prev = 23;
181
- _context3.t0 = _context3["catch"](13);
182
- _iterator.e(_context3.t0);
183
- case 26:
184
- _context3.prev = 26;
180
+ case 6:
181
+ _context3.prev = 6;
182
+ _t = _context3["catch"](2);
183
+ _iterator.e(_t);
184
+ case 7:
185
+ _context3.prev = 7;
185
186
  _iterator.f();
186
- return _context3.finish(26);
187
- case 29:
187
+ return _context3.finish(7);
188
+ case 8:
188
189
  autoUnbind = configurePage(themeState);
189
190
  return _context3.abrupt("return", autoUnbind);
190
- case 31:
191
+ case 9:
191
192
  case "end":
192
193
  return _context3.stop();
193
194
  }
194
- }, _callee3, null, [[13, 23, 26, 29]]);
195
+ }, _callee3, null, [[2, 6, 7, 8]]);
195
196
  }));
196
197
  return function setGlobalTheme() {
197
198
  return _ref.apply(this, arguments);
@@ -1,10 +1,10 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { fg } from '@atlaskit/platform-feature-flags';
3
- import { themeIds } from './theme-ids';
4
2
  /**
5
3
  * This file contains the source of truth for themes and all associated meta data.
6
4
  */
7
5
 
6
+ import { themeIds } from './theme-ids';
7
+
8
8
  /**
9
9
  * Themes: The internal identifier of a theme.
10
10
  * These ids are what the actual theme files/folders are called.
@@ -147,52 +147,13 @@ var themeConfig = {
147
147
  }
148
148
  };
149
149
 
150
- /**
151
- * ThemeOptionsSchema: additional configuration options used to customize Atlassian's themes
152
- */
153
-
154
- /**
155
- * ThemeState: the standard representation of an app's current theme and preferences
156
- */
157
-
158
- /**
159
- * Can't evaluate typography feature flags at the module level,
160
- * it will always resolve to false when server side rendered or when flags are loaded async.
161
- */
162
-
163
- function getShapeDefault() {
164
- if (fg('platform-dst-shape-theme-default')) {
165
- return 'shape';
166
- }
167
- return undefined;
168
- }
169
- function getMotionDefault() {
170
- if (fg('platform-dst-motion-theme-default')) {
171
- return 'motion';
172
- }
173
- return undefined;
174
- }
175
-
176
- /**
177
- * themeStateDefaults: the default values for ThemeState used by theming utilities
178
- */
179
- export var themeStateDefaults = {
180
- colorMode: 'auto',
181
- contrastMode: 'auto',
182
- dark: 'dark',
183
- light: 'light',
184
- shape: getShapeDefault,
185
- spacing: 'spacing',
186
- typography: 'typography',
187
- motion: getMotionDefault,
188
- UNSAFE_themeOptions: undefined
189
- };
190
-
191
150
  /**
192
151
  * Represents theme state once mounted to the page
193
152
  * (the page doesn't have an "auto" color mode, it's either light or dark)
194
153
  */
195
154
 
155
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
196
156
  export default themeConfig;
197
157
  export { themeColorModes } from './theme-color-modes';
198
- export { themeIds } from './theme-ids';
158
+ export { themeIds } from './theme-ids';
159
+ export { themeStateDefaults } from './theme-state-defaults';
@@ -0,0 +1,35 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import { isColorMode } from './is-color-mode';
4
+ import { isThemeIds } from './is-theme-ids';
5
+ import { isThemeKind } from './is-theme-kind';
6
+ var customThemeOptions = 'UNSAFE_themeOptions';
7
+
8
+ /**
9
+ * Converts a theme object to a string formatted for the `data-theme` HTML attribute.
10
+ *
11
+ * @param {object} themes The themes that should be applied.
12
+ *
13
+ * @example
14
+ * ```
15
+ * themeObjectToString({ dark: 'dark', light: 'light', spacing: 'spacing' });
16
+ * // returns 'dark:dark light:light spacing:spacing'
17
+ * ```
18
+ */
19
+ export var themeObjectToString = function themeObjectToString(themeState) {
20
+ return Object.entries(themeState).reduce(function (themeString, _ref) {
21
+ var _ref2 = _slicedToArray(_ref, 2),
22
+ kind = _ref2[0],
23
+ id = _ref2[1];
24
+ if (
25
+ // colorMode theme state
26
+ kind === 'colorMode' && typeof id === 'string' && isColorMode(id) ||
27
+ // custom theme state
28
+ kind === customThemeOptions && _typeof(id) === 'object' ||
29
+ // other theme states
30
+ isThemeKind(kind) && typeof id === 'string' && isThemeIds(id)) {
31
+ return themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(_typeof(id) === 'object' ? JSON.stringify(id) : id);
32
+ }
33
+ return themeString;
34
+ }, '');
35
+ };
File without changes
@@ -0,0 +1,34 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+
3
+ /**
4
+ * Can't evaluate typography feature flags at the module level,
5
+ * it will always resolve to false when server side rendered or when flags are loaded async.
6
+ */
7
+
8
+ function getShapeDefault() {
9
+ if (fg('platform-dst-shape-theme-default')) {
10
+ return 'shape';
11
+ }
12
+ return undefined;
13
+ }
14
+ function getMotionDefault() {
15
+ if (fg('platform-dst-motion-theme-default')) {
16
+ return 'motion';
17
+ }
18
+ return undefined;
19
+ }
20
+
21
+ /**
22
+ * themeStateDefaults: the default values for ThemeState used by theming utilities
23
+ */
24
+ export var themeStateDefaults = {
25
+ colorMode: 'auto',
26
+ contrastMode: 'auto',
27
+ dark: 'dark',
28
+ light: 'light',
29
+ shape: getShapeDefault,
30
+ spacing: 'spacing',
31
+ typography: 'typography',
32
+ motion: getMotionDefault,
33
+ UNSAFE_themeOptions: undefined
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { isColorMode } from './is-color-mode';
3
+ import { isThemeIds } from './is-theme-ids';
4
+ import { isThemeKind } from './is-theme-kind';
5
+ var customThemeOptions = 'UNSAFE_themeOptions';
6
+
7
+ /**
8
+ * Converts a string that is formatted for the `data-theme` HTML attribute
9
+ * to an object that can be passed to `setGlobalTheme`.
10
+ *
11
+ * @param {string} themes The themes that should be applied.
12
+ *
13
+ * @example
14
+ * ```
15
+ * themeStringToObject('dark:dark light:light spacing:spacing');
16
+ * // returns { dark: 'dark', light: 'light', spacing: 'spacing' }
17
+ * ```
18
+ */
19
+ export var themeStringToObject = function themeStringToObject(themeState) {
20
+ return themeState.split(' ')
21
+ // @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
22
+ .map(function (theme) {
23
+ return theme.split(/:([^]*)/);
24
+ }).reduce(function (themeObject, _ref) {
25
+ var _ref2 = _slicedToArray(_ref, 2),
26
+ kind = _ref2[0],
27
+ id = _ref2[1];
28
+ if (kind === 'colorMode' && isColorMode(id)) {
29
+ themeObject[kind] = id;
30
+ }
31
+ if (isThemeKind(kind) && isThemeIds(id)) {
32
+ // @ts-expect-error FIXME - this is a valid ts error
33
+ themeObject[kind] = id;
34
+ }
35
+ if (kind === customThemeOptions) {
36
+ try {
37
+ themeObject[customThemeOptions] = JSON.parse(id);
38
+ } catch (_unused) {
39
+ new Error('Invalid custom theme string');
40
+ }
41
+ }
42
+ return themeObject;
43
+ }, {});
44
+ };
@@ -0,0 +1,36 @@
1
+ import tokenValuesDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
2
+ import tokenValuesLight from '../artifacts/atlassian-light-token-value-for-contrast-check';
3
+ import { additionalChecks } from './custom-theme-token-contrast-check';
4
+ import { getContrastRatio } from './get-contrast-ratio';
5
+ var getColorFromTokenRaw = function getColorFromTokenRaw(tokenName, mode) {
6
+ return mode === 'light' ? tokenValuesLight[tokenName] : tokenValuesDark[tokenName];
7
+ };
8
+ export var additionalContrastChecker = function additionalContrastChecker(_ref) {
9
+ var customThemeTokenMap = _ref.customThemeTokenMap,
10
+ mode = _ref.mode,
11
+ themeRamp = _ref.themeRamp;
12
+ var updatedCustomThemeTokenMap = {};
13
+ var brandTokens = Object.keys(customThemeTokenMap);
14
+ additionalChecks.forEach(function (pairing) {
15
+ var backgroundLight = pairing.backgroundLight,
16
+ backgroundDark = pairing.backgroundDark,
17
+ foreground = pairing.foreground,
18
+ desiredContrast = pairing.desiredContrast,
19
+ updatedTokens = pairing.updatedTokens;
20
+ var background = mode === 'light' ? backgroundLight : backgroundDark;
21
+ var foregroundTokenValue = customThemeTokenMap[foreground];
22
+ var backgroundTokenValue = customThemeTokenMap[background];
23
+ var foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
24
+ var backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
25
+ var contrast = getContrastRatio(foregroundColor, backgroundColor);
26
+ if (contrast <= desiredContrast) {
27
+ updatedTokens.forEach(function (token) {
28
+ var rampValue = customThemeTokenMap[token];
29
+ if (typeof rampValue === 'number') {
30
+ updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
31
+ }
32
+ });
33
+ }
34
+ });
35
+ return updatedCustomThemeTokenMap;
36
+ };
@@ -1,5 +1,3 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import tokens from '../artifacts/token-names';
3
1
  import { CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from '../constants';
4
2
  import { hash } from './hash';
5
3
  export function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
@@ -16,14 +14,4 @@ export function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
16
14
  }
17
15
  });
18
16
  return attrOfMissingCustomStyles;
19
- }
20
- export function reduceTokenMap(tokenMap, themeRamp) {
21
- return Object.entries(tokenMap).reduce(function (acc, _ref) {
22
- var _ref2 = _slicedToArray(_ref, 2),
23
- key = _ref2[0],
24
- value = _ref2[1];
25
- var cssVar = tokens[key];
26
- return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(typeof value === 'string' ? value : themeRamp[value], ";") : acc;
27
- }, '');
28
- }
29
- export { limitSizeOfCustomStyleElements } from './limit-size-of-custom-style-elements';
17
+ }
@@ -1,6 +1,3 @@
1
- import tokenValuesDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
2
- import tokenValuesLight from '../artifacts/atlassian-light-token-value-for-contrast-check';
3
- import { getContrastRatio } from './color-utils';
4
1
  export var additionalChecks = [{
5
2
  foreground: 'color.text.brand',
6
3
  backgroundLight: 'elevation.surface.sunken',
@@ -42,36 +39,4 @@ export var additionalChecks = [{
42
39
  // In light mode: darken the following tokens by one base token
43
40
  // In dark mode: lighten the following tokens by one base token
44
41
  updatedTokens: ['color.chart.brand', 'color.chart.brand.hovered']
45
- }];
46
- var getColorFromTokenRaw = function getColorFromTokenRaw(tokenName, mode) {
47
- return mode === 'light' ? tokenValuesLight[tokenName] : tokenValuesDark[tokenName];
48
- };
49
- export var additionalContrastChecker = function additionalContrastChecker(_ref) {
50
- var customThemeTokenMap = _ref.customThemeTokenMap,
51
- mode = _ref.mode,
52
- themeRamp = _ref.themeRamp;
53
- var updatedCustomThemeTokenMap = {};
54
- var brandTokens = Object.keys(customThemeTokenMap);
55
- additionalChecks.forEach(function (pairing) {
56
- var backgroundLight = pairing.backgroundLight,
57
- backgroundDark = pairing.backgroundDark,
58
- foreground = pairing.foreground,
59
- desiredContrast = pairing.desiredContrast,
60
- updatedTokens = pairing.updatedTokens;
61
- var background = mode === 'light' ? backgroundLight : backgroundDark;
62
- var foregroundTokenValue = customThemeTokenMap[foreground];
63
- var backgroundTokenValue = customThemeTokenMap[background];
64
- var foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
65
- var backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
66
- var contrast = getContrastRatio(foregroundColor, backgroundColor);
67
- if (contrast <= desiredContrast) {
68
- updatedTokens.forEach(function (token) {
69
- var rampValue = customThemeTokenMap[token];
70
- if (typeof rampValue === 'number') {
71
- updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
72
- }
73
- });
74
- }
75
- });
76
- return updatedCustomThemeTokenMap;
77
- };
42
+ }];
@@ -0,0 +1,20 @@
1
+ import { rgbToLab } from './rgb-to-lab';
2
+ export function deltaE(rgbA, rgbB) {
3
+ var labA = rgbToLab(rgbA);
4
+ var labB = rgbToLab(rgbB);
5
+ var deltaL = labA[0] - labB[0];
6
+ var deltaA = labA[1] - labB[1];
7
+ var deltaB = labA[2] - labB[2];
8
+ var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
9
+ var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
10
+ var deltaC = c1 - c2;
11
+ var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
12
+ deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
13
+ var sc = 1.0 + 0.045 * c1;
14
+ var sh = 1.0 + 0.015 * c1;
15
+ var deltaLKlsl = deltaL / 1.0;
16
+ var deltaCkcsc = deltaC / sc;
17
+ var deltaHkhsh = deltaH / sh;
18
+ var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
19
+ return i < 0 ? 0 : Math.sqrt(i);
20
+ }
@@ -0,0 +1,40 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { getClosestColorIndex } from './get-closest-color-index';
3
+ import { argbFromRgba, Contrast, Hct, rgbaFromArgb } from './hct-color-utils';
4
+ import { hexToHSL } from './hex-to-hsl';
5
+ import { hexToRgbA } from './hex-to-rgb-a';
6
+ import { HSLToRGB } from './hsl-to-rgb';
7
+ import { relativeLuminanceW3C } from './relative-luminance-w3-c';
8
+ import { rgbToHex } from './rgb-to-hex';
9
+ var lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
10
+ var highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
11
+ export var generateColors = function generateColors(brandColor) {
12
+ // Determine luminance
13
+ var HSLBrandColorHue = hexToHSL(brandColor)[0];
14
+ var baseRgb = HSLToRGB(HSLBrandColorHue, 100, 60);
15
+ var isLowLuminance = relativeLuminanceW3C(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
16
+ // Choose right palette
17
+ var themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
18
+ var brandRgba = hexToRgbA(brandColor);
19
+ var hctColor = Hct.fromInt(argbFromRgba({
20
+ r: brandRgba[0],
21
+ g: brandRgba[1],
22
+ b: brandRgba[2],
23
+ a: brandRgba[3]
24
+ }));
25
+ var themeRamp = themeRatios.map(function (contrast) {
26
+ var rgbaColor = rgbaFromArgb(Hct.from(hctColor.hue, hctColor.chroma, Contrast.darker(100, contrast) + 0.25 // Material's utils provide an offset
27
+ ).toInt());
28
+ return rgbToHex(rgbaColor.r, rgbaColor.g, rgbaColor.b);
29
+ });
30
+ var closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
31
+
32
+ // Replace closet color with brandColor
33
+ var updatedThemeRamp = _toConsumableArray(themeRamp);
34
+ updatedThemeRamp[closestColorIndex] = brandColor;
35
+ return {
36
+ ramp: updatedThemeRamp,
37
+ // add the replaced color into the result
38
+ replacedColor: themeRamp[closestColorIndex]
39
+ };
40
+ };
@@ -0,0 +1,25 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ import { additionalContrastChecker } from './additional-contrast-checker';
6
+ import { generateColors } from './generate-colors';
7
+ import { generateTokenMap } from './generate-token-map';
8
+ export var generateTokenMapWithContrastCheck = function generateTokenMapWithContrastCheck(brandColor, mode, themeRamp) {
9
+ var colors = themeRamp || generateColors(brandColor).ramp;
10
+ var tokenMaps = generateTokenMap(brandColor, mode, colors);
11
+ var result = {};
12
+ Object.entries(tokenMaps).forEach(function (_ref) {
13
+ var _ref2 = _slicedToArray(_ref, 2),
14
+ mode = _ref2[0],
15
+ map = _ref2[1];
16
+ if (mode === 'light' || mode === 'dark') {
17
+ result[mode] = _objectSpread(_objectSpread({}, map), additionalContrastChecker({
18
+ customThemeTokenMap: map,
19
+ mode: mode,
20
+ themeRamp: colors
21
+ }));
22
+ }
23
+ });
24
+ return result;
25
+ };
@@ -1,49 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
2
  import rawTokensDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
7
- import { getContrastRatio, hexToHSL, hexToRgbA } from './color-utils';
8
- import { additionalContrastChecker } from './custom-theme-token-contrast-check';
3
+ import { generateColors } from './generate-colors';
9
4
  import { getClosestColorIndex } from './get-closest-color-index';
10
- import { argbFromRgba, Contrast, Hct, rgbaFromArgb } from './hct-color-utils';
11
- import { HSLToRGB } from './hsl-to-rgb';
12
- import { relativeLuminanceW3C } from './relative-luminance-w3-c';
13
- import { rgbToHex } from './rgb-to-hex';
14
- var lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
15
- var highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
16
- export var generateColors = function generateColors(brandColor) {
17
- // Determine luminance
18
- var HSLBrandColorHue = hexToHSL(brandColor)[0];
19
- var baseRgb = HSLToRGB(HSLBrandColorHue, 100, 60);
20
- var isLowLuminance = relativeLuminanceW3C(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
21
- // Choose right palette
22
- var themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
23
- var brandRgba = hexToRgbA(brandColor);
24
- var hctColor = Hct.fromInt(argbFromRgba({
25
- r: brandRgba[0],
26
- g: brandRgba[1],
27
- b: brandRgba[2],
28
- a: brandRgba[3]
29
- }));
30
- var themeRamp = themeRatios.map(function (contrast) {
31
- var rgbaColor = rgbaFromArgb(Hct.from(hctColor.hue, hctColor.chroma, Contrast.darker(100, contrast) + 0.25 // Material's utils provide an offset
32
- ).toInt());
33
- return rgbToHex(rgbaColor.r, rgbaColor.g, rgbaColor.b);
34
- });
35
- var closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
36
-
37
- // Replace closet color with brandColor
38
- var updatedThemeRamp = _toConsumableArray(themeRamp);
39
- updatedThemeRamp[closestColorIndex] = brandColor;
40
- return {
41
- ramp: updatedThemeRamp,
42
- // add the replaced color into the result
43
- replacedColor: themeRamp[closestColorIndex]
44
- };
45
- };
46
-
5
+ import { getContrastRatio } from './get-contrast-ratio';
47
6
  /**
48
7
  * Return the interaction tokens for a color, given its ramp position and the number of
49
8
  * needed interaction states. Use higher-indexed colors (i.e. darker colors) if possible;
@@ -201,23 +160,4 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
201
160
  light: customThemeTokenMapLight,
202
161
  dark: customThemeTokenMapDark
203
162
  };
204
- };
205
- export var generateTokenMapWithContrastCheck = function generateTokenMapWithContrastCheck(brandColor, mode, themeRamp) {
206
- var colors = themeRamp || generateColors(brandColor).ramp;
207
- var tokenMaps = generateTokenMap(brandColor, mode, colors);
208
- var result = {};
209
- Object.entries(tokenMaps).forEach(function (_ref3) {
210
- var _ref4 = _slicedToArray(_ref3, 2),
211
- mode = _ref4[0],
212
- map = _ref4[1];
213
- if (mode === 'light' || mode === 'dark') {
214
- result[mode] = _objectSpread(_objectSpread({}, map), additionalContrastChecker({
215
- customThemeTokenMap: map,
216
- mode: mode,
217
- themeRamp: colors
218
- }));
219
- }
220
- });
221
- return result;
222
- };
223
- export { getClosestColorIndex } from './get-closest-color-index';
163
+ };
@@ -1,4 +1,5 @@
1
- import { deltaE, hexToRgb } from './color-utils';
1
+ import { deltaE } from './delta-e';
2
+ import { hexToRgb } from './hex-to-rgb';
2
3
  export var getClosestColorIndex = function getClosestColorIndex(themeRamp, brandColor) {
3
4
  // Iterate over themeRamp and find whichever color is closest to brandColor
4
5
  var closestColorIndex = 0;
@@ -0,0 +1,16 @@
1
+ import { hexToRgb } from './hex-to-rgb';
2
+ import { isValidHex } from './is-valid-hex';
3
+ import { relativeLuminanceW3C } from './relative-luminance-w3-c';
4
+ export function getContrastRatio(foreground, background) {
5
+ if (!isValidHex(foreground) || !isValidHex(background)) {
6
+ throw new Error('Invalid HEX');
7
+ }
8
+ var foregroundRgb = hexToRgb(foreground);
9
+ var backgroundRgb = hexToRgb(background);
10
+ var foregroundLuminance = relativeLuminanceW3C(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
11
+ var backgroundLuminance = relativeLuminanceW3C(backgroundRgb[0], backgroundRgb[1], backgroundRgb[2]);
12
+ // calculate the color contrast ratio
13
+ var brightest = Math.max(foregroundLuminance, backgroundLuminance);
14
+ var darkest = Math.min(foregroundLuminance, backgroundLuminance);
15
+ return (brightest + 0.05) / (darkest + 0.05);
16
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the alpha component of a color in ARGB format.
3
+ */
4
+ export function alphaFromArgb(argb) {
5
+ return argb >> 24 & 255;
6
+ }
@@ -0,0 +1,12 @@
1
+ import { argbFromRgb } from './argb-from-rgb';
2
+ import { delinearized } from './delinearized';
3
+
4
+ /**
5
+ * Converts a color from linear RGB components to ARGB format.
6
+ */
7
+ export function argbFromLinrgb(linrgb) {
8
+ var r = delinearized(linrgb[0]);
9
+ var g = delinearized(linrgb[1]);
10
+ var b = delinearized(linrgb[2]);
11
+ return argbFromRgb(r, g, b);
12
+ }
@@ -0,0 +1,16 @@
1
+ import { argbFromRgb } from './argb-from-rgb';
2
+ import { delinearized } from './delinearized';
3
+ import { yFromLstar } from './y-from-lstar';
4
+
5
+ /**
6
+ * Converts an L* value to an ARGB representation.
7
+ *
8
+ * @param lstar L* in L*a*b*
9
+ * @return ARGB representation of grayscale color with lightness
10
+ * matching L*
11
+ */
12
+ export function argbFromLstar(lstar) {
13
+ var y = yFromLstar(lstar);
14
+ var component = delinearized(y);
15
+ return argbFromRgb(component, component, component);
16
+ }