@atlaskit/tokens 13.1.0 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. package/CHANGELOG.md +34 -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 -336
  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/generated-pairs.js +2 -2
  20. package/dist/cjs/artifacts/palettes-raw/palette.js +35 -1
  21. package/dist/cjs/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
  22. package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
  23. package/dist/cjs/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
  24. package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
  25. package/dist/cjs/artifacts/token-default-values.js +21 -1
  26. package/dist/cjs/artifacts/token-names.js +21 -1
  27. package/dist/cjs/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
  28. package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +471 -31
  29. package/dist/cjs/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
  30. package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +471 -31
  31. package/dist/cjs/entry-points/theme-state-transformer.js +4 -3
  32. package/dist/cjs/entry-points/token-metadata.codegen.js +196 -16
  33. package/dist/cjs/get-custom-theme-styles.js +7 -6
  34. package/dist/cjs/get-global-theme.js +2 -2
  35. package/dist/cjs/get-theme-html-attrs.js +2 -2
  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/theme-config.js +8 -44
  41. package/dist/cjs/theme-object-to-string.js +42 -0
  42. package/dist/cjs/theme-options-schema.js +1 -0
  43. package/dist/cjs/theme-state-defaults.js +39 -0
  44. package/dist/cjs/theme-state.js +5 -0
  45. package/dist/cjs/theme-string-to-object.js +51 -0
  46. package/dist/cjs/utils/additional-contrast-checker.js +43 -0
  47. package/dist/cjs/utils/custom-theme-loading-utils.js +0 -22
  48. package/dist/cjs/utils/custom-theme-token-contrast-check.js +2 -40
  49. package/dist/cjs/utils/delta-e.js +26 -0
  50. package/dist/cjs/utils/generate-colors.js +47 -0
  51. package/dist/cjs/utils/generate-token-map-with-contrast-check.js +32 -0
  52. package/dist/cjs/utils/{generate-custom-color-ramp.js → generate-token-map.js} +6 -75
  53. package/dist/cjs/utils/get-closest-color-index.js +3 -2
  54. package/dist/cjs/utils/get-contrast-ratio.js +22 -0
  55. package/dist/cjs/utils/hct-color-utils/alpha-from-argb.js +12 -0
  56. package/dist/cjs/utils/hct-color-utils/argb-from-linrgb.js +17 -0
  57. package/dist/cjs/utils/hct-color-utils/argb-from-lstar.js +21 -0
  58. package/dist/cjs/utils/hct-color-utils/argb-from-rgba.js +24 -0
  59. package/dist/cjs/utils/hct-color-utils/argb-from-xyz.js +29 -0
  60. package/dist/cjs/utils/hct-color-utils/blue-from-argb.js +12 -0
  61. package/dist/cjs/utils/hct-color-utils/clamp-component.js +15 -0
  62. package/dist/cjs/utils/hct-color-utils/contrast.js +10 -11
  63. package/dist/cjs/utils/hct-color-utils/green-from-argb.js +12 -0
  64. package/dist/cjs/utils/hct-color-utils/hct.js +18 -12
  65. package/dist/cjs/utils/hct-color-utils/index.js +4 -3
  66. package/dist/cjs/utils/hct-color-utils/lab-f.js +15 -0
  67. package/dist/cjs/utils/hct-color-utils/lab-invf.js +16 -0
  68. package/dist/cjs/utils/hct-color-utils/lstar-from-argb.js +34 -0
  69. package/dist/cjs/utils/hct-color-utils/lstar-from-y.js +21 -0
  70. package/dist/cjs/utils/hct-color-utils/red-from-argb.js +12 -0
  71. package/dist/cjs/utils/hct-color-utils/rgba-from-argb.js +28 -0
  72. package/dist/cjs/utils/hct-color-utils/rgba.js +1 -0
  73. package/dist/cjs/utils/hct-color-utils/viewing-conditions.js +5 -4
  74. package/dist/cjs/utils/hct-color-utils/white-point-d65.js +14 -0
  75. package/dist/cjs/utils/hct-color-utils/y-from-lstar.js +21 -0
  76. package/dist/cjs/utils/hex-to-hsl.js +52 -0
  77. package/dist/cjs/utils/hex-to-rgb-a.js +20 -0
  78. package/dist/cjs/utils/hex-to-rgb.js +19 -0
  79. package/dist/cjs/utils/is-valid-hex.js +10 -0
  80. package/dist/cjs/utils/reduce-token-map.js +18 -0
  81. package/dist/cjs/utils/rgb-to-lab.js +24 -0
  82. package/dist/es2019/artifacts/generated-pairs.js +2 -2
  83. package/dist/es2019/artifacts/palettes-raw/palette.js +35 -1
  84. package/dist/es2019/artifacts/themes/atlassian-dark-increased-contrast.js +21 -1
  85. package/dist/es2019/artifacts/themes/atlassian-dark.js +21 -1
  86. package/dist/es2019/artifacts/themes/atlassian-light-increased-contrast.js +21 -1
  87. package/dist/es2019/artifacts/themes/atlassian-light.js +21 -1
  88. package/dist/es2019/artifacts/token-default-values.js +21 -1
  89. package/dist/es2019/artifacts/token-names.js +21 -1
  90. package/dist/es2019/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
  91. package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +471 -31
  92. package/dist/es2019/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
  93. package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +471 -31
  94. package/dist/es2019/entry-points/theme-state-transformer.js +2 -1
  95. package/dist/es2019/entry-points/token-metadata.codegen.js +196 -16
  96. package/dist/es2019/get-custom-theme-styles.js +3 -2
  97. package/dist/es2019/get-global-theme.js +1 -1
  98. package/dist/es2019/get-theme-html-attrs.js +1 -1
  99. package/dist/es2019/index.js +2 -1
  100. package/dist/es2019/is-color-mode.js +3 -0
  101. package/dist/es2019/is-theme-ids.js +4 -0
  102. package/dist/es2019/is-theme-kind.js +4 -0
  103. package/dist/es2019/theme-config.js +4 -45
  104. package/dist/es2019/theme-object-to-string.js +28 -0
  105. package/dist/es2019/theme-options-schema.js +0 -0
  106. package/dist/es2019/theme-state-defaults.js +34 -0
  107. package/dist/es2019/theme-state.js +1 -0
  108. package/dist/es2019/theme-string-to-object.js +38 -0
  109. package/dist/es2019/utils/additional-contrast-checker.js +39 -0
  110. package/dist/es2019/utils/custom-theme-loading-utils.js +1 -11
  111. package/dist/es2019/utils/custom-theme-token-contrast-check.js +1 -41
  112. package/dist/es2019/utils/delta-e.js +20 -0
  113. package/dist/es2019/utils/generate-colors.js +39 -0
  114. package/dist/es2019/utils/generate-token-map-with-contrast-check.js +21 -0
  115. package/dist/es2019/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -63
  116. package/dist/es2019/utils/get-closest-color-index.js +2 -1
  117. package/dist/es2019/utils/get-contrast-ratio.js +16 -0
  118. package/dist/es2019/utils/hct-color-utils/alpha-from-argb.js +6 -0
  119. package/dist/es2019/utils/hct-color-utils/argb-from-linrgb.js +12 -0
  120. package/dist/es2019/utils/hct-color-utils/argb-from-lstar.js +16 -0
  121. package/dist/es2019/utils/hct-color-utils/argb-from-rgba.js +19 -0
  122. package/dist/es2019/utils/hct-color-utils/argb-from-xyz.js +24 -0
  123. package/dist/es2019/utils/hct-color-utils/blue-from-argb.js +6 -0
  124. package/dist/es2019/utils/hct-color-utils/clamp-component.js +9 -0
  125. package/dist/es2019/utils/hct-color-utils/contrast.js +10 -10
  126. package/dist/es2019/utils/hct-color-utils/green-from-argb.js +6 -0
  127. package/dist/es2019/utils/hct-color-utils/hct.js +19 -12
  128. package/dist/es2019/utils/hct-color-utils/index.js +2 -1
  129. package/dist/es2019/utils/hct-color-utils/lab-f.js +9 -0
  130. package/dist/es2019/utils/hct-color-utils/lab-invf.js +10 -0
  131. package/dist/es2019/utils/hct-color-utils/lstar-from-argb.js +28 -0
  132. package/dist/es2019/utils/hct-color-utils/lstar-from-y.js +16 -0
  133. package/dist/es2019/utils/hct-color-utils/red-from-argb.js +6 -0
  134. package/dist/es2019/utils/hct-color-utils/rgba-from-argb.js +22 -0
  135. package/dist/es2019/utils/hct-color-utils/rgba.js +0 -0
  136. package/dist/es2019/utils/hct-color-utils/viewing-conditions.js +4 -3
  137. package/dist/es2019/utils/hct-color-utils/white-point-d65.js +8 -0
  138. package/dist/es2019/utils/hct-color-utils/y-from-lstar.js +16 -0
  139. package/dist/es2019/utils/hex-to-hsl.js +46 -0
  140. package/dist/es2019/utils/hex-to-rgb-a.js +14 -0
  141. package/dist/es2019/utils/hex-to-rgb.js +13 -0
  142. package/dist/es2019/utils/is-valid-hex.js +2 -0
  143. package/dist/es2019/utils/reduce-token-map.js +7 -0
  144. package/dist/es2019/utils/rgb-to-lab.js +18 -0
  145. package/dist/esm/artifacts/generated-pairs.js +2 -2
  146. package/dist/esm/artifacts/palettes-raw/palette.js +35 -1
  147. package/dist/esm/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
  148. package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
  149. package/dist/esm/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
  150. package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
  151. package/dist/esm/artifacts/token-default-values.js +21 -1
  152. package/dist/esm/artifacts/token-names.js +21 -1
  153. package/dist/esm/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
  154. package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +471 -31
  155. package/dist/esm/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
  156. package/dist/esm/artifacts/tokens-raw/atlassian-light.js +471 -31
  157. package/dist/esm/entry-points/theme-state-transformer.js +2 -1
  158. package/dist/esm/entry-points/token-metadata.codegen.js +196 -16
  159. package/dist/esm/get-custom-theme-styles.js +3 -2
  160. package/dist/esm/get-global-theme.js +1 -1
  161. package/dist/esm/get-theme-html-attrs.js +1 -1
  162. package/dist/esm/index.js +2 -1
  163. package/dist/esm/is-color-mode.js +3 -0
  164. package/dist/esm/is-theme-ids.js +6 -0
  165. package/dist/esm/is-theme-kind.js +6 -0
  166. package/dist/esm/theme-config.js +4 -45
  167. package/dist/esm/theme-object-to-string.js +35 -0
  168. package/dist/esm/theme-options-schema.js +0 -0
  169. package/dist/esm/theme-state-defaults.js +34 -0
  170. package/dist/esm/theme-state.js +1 -0
  171. package/dist/esm/theme-string-to-object.js +44 -0
  172. package/dist/esm/utils/additional-contrast-checker.js +36 -0
  173. package/dist/esm/utils/custom-theme-loading-utils.js +1 -15
  174. package/dist/esm/utils/custom-theme-token-contrast-check.js +1 -38
  175. package/dist/esm/utils/delta-e.js +20 -0
  176. package/dist/esm/utils/generate-colors.js +40 -0
  177. package/dist/esm/utils/generate-token-map-with-contrast-check.js +25 -0
  178. package/dist/esm/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -67
  179. package/dist/esm/utils/get-closest-color-index.js +2 -1
  180. package/dist/esm/utils/get-contrast-ratio.js +16 -0
  181. package/dist/esm/utils/hct-color-utils/alpha-from-argb.js +6 -0
  182. package/dist/esm/utils/hct-color-utils/argb-from-linrgb.js +12 -0
  183. package/dist/esm/utils/hct-color-utils/argb-from-lstar.js +16 -0
  184. package/dist/esm/utils/hct-color-utils/argb-from-rgba.js +18 -0
  185. package/dist/esm/utils/hct-color-utils/argb-from-xyz.js +24 -0
  186. package/dist/esm/utils/hct-color-utils/blue-from-argb.js +6 -0
  187. package/dist/esm/utils/hct-color-utils/clamp-component.js +9 -0
  188. package/dist/esm/utils/hct-color-utils/contrast.js +10 -10
  189. package/dist/esm/utils/hct-color-utils/green-from-argb.js +6 -0
  190. package/dist/esm/utils/hct-color-utils/hct.js +19 -12
  191. package/dist/esm/utils/hct-color-utils/index.js +2 -1
  192. package/dist/esm/utils/hct-color-utils/lab-f.js +9 -0
  193. package/dist/esm/utils/hct-color-utils/lab-invf.js +10 -0
  194. package/dist/esm/utils/hct-color-utils/lstar-from-argb.js +28 -0
  195. package/dist/esm/utils/hct-color-utils/lstar-from-y.js +16 -0
  196. package/dist/esm/utils/hct-color-utils/red-from-argb.js +6 -0
  197. package/dist/esm/utils/hct-color-utils/rgba-from-argb.js +22 -0
  198. package/dist/esm/utils/hct-color-utils/rgba.js +0 -0
  199. package/dist/esm/utils/hct-color-utils/viewing-conditions.js +5 -4
  200. package/dist/esm/utils/hct-color-utils/white-point-d65.js +8 -0
  201. package/dist/esm/utils/hct-color-utils/y-from-lstar.js +16 -0
  202. package/dist/esm/utils/hex-to-hsl.js +46 -0
  203. package/dist/esm/utils/hex-to-rgb-a.js +14 -0
  204. package/dist/esm/utils/hex-to-rgb.js +13 -0
  205. package/dist/esm/utils/is-valid-hex.js +4 -0
  206. package/dist/esm/utils/reduce-token-map.js +11 -0
  207. package/dist/esm/utils/rgb-to-lab.js +18 -0
  208. package/dist/types/artifacts/generated-pairs.d.ts +1 -1
  209. package/dist/types/artifacts/palettes-raw/palette.d.ts +1 -1
  210. package/dist/types/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
  211. package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
  212. package/dist/types/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
  213. package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
  214. package/dist/types/artifacts/token-default-values.d.ts +21 -1
  215. package/dist/types/artifacts/token-names.d.ts +41 -1
  216. package/dist/types/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
  217. package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
  218. package/dist/types/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
  219. package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
  220. package/dist/types/artifacts/types-internal.d.ts +2 -2
  221. package/dist/types/artifacts/types.d.ts +2 -2
  222. package/dist/types/entry-points/css-type-schema.codegen.d.ts +3 -3
  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/types.d.ts +75 -15
  238. package/dist/types/utils/additional-contrast-checker.d.ts +9 -0
  239. package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -6
  240. package/dist/types/utils/custom-theme-token-contrast-check.d.ts +0 -9
  241. package/dist/types/utils/delta-e.d.ts +1 -0
  242. package/dist/types/utils/generate-colors.d.ts +5 -0
  243. package/dist/types/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -6
  244. package/dist/types/utils/generate-token-map.d.ts +9 -0
  245. package/dist/types/utils/get-contrast-ratio.d.ts +1 -0
  246. package/dist/types/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
  247. package/dist/types/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
  248. package/dist/types/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
  249. package/dist/types/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
  250. package/dist/types/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
  251. package/dist/types/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
  252. package/dist/types/utils/hct-color-utils/clamp-component.d.ts +1 -0
  253. package/dist/types/utils/hct-color-utils/green-from-argb.d.ts +4 -0
  254. package/dist/types/utils/hct-color-utils/index.d.ts +2 -1
  255. package/dist/types/utils/hct-color-utils/lab-f.d.ts +1 -0
  256. package/dist/types/utils/hct-color-utils/lab-invf.d.ts +1 -0
  257. package/dist/types/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
  258. package/dist/types/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
  259. package/dist/types/utils/hct-color-utils/red-from-argb.d.ts +4 -0
  260. package/dist/types/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
  261. package/dist/types/utils/hct-color-utils/rgba.d.ts +14 -0
  262. package/dist/types/utils/hct-color-utils/white-point-d65.d.ts +6 -0
  263. package/dist/types/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
  264. package/dist/types/utils/hex-to-hsl.d.ts +1 -0
  265. package/dist/types/utils/hex-to-rgb-a.d.ts +1 -0
  266. package/dist/types/utils/hex-to-rgb.d.ts +1 -0
  267. package/dist/types/utils/is-valid-hex.d.ts +1 -0
  268. package/dist/types/utils/reduce-token-map.d.ts +6 -0
  269. package/dist/types/utils/rgb-to-lab.d.ts +1 -0
  270. package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
  271. package/dist/types-ts4.5/artifacts/palettes-raw/palette.d.ts +1 -1
  272. package/dist/types-ts4.5/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
  273. package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
  274. package/dist/types-ts4.5/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
  275. package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
  276. package/dist/types-ts4.5/artifacts/token-default-values.d.ts +21 -1
  277. package/dist/types-ts4.5/artifacts/token-names.d.ts +41 -1
  278. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
  279. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
  280. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
  281. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
  282. package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
  283. package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
  284. package/dist/types-ts4.5/entry-points/css-type-schema.codegen.d.ts +3 -3
  285. package/dist/types-ts4.5/entry-points/theme-state-transformer.d.ts +2 -1
  286. package/dist/types-ts4.5/entry-points/token-metadata.codegen.d.ts +1 -1
  287. package/dist/types-ts4.5/index.d.ts +2 -1
  288. package/dist/types-ts4.5/is-color-mode.d.ts +2 -0
  289. package/dist/types-ts4.5/is-theme-ids.d.ts +2 -0
  290. package/dist/types-ts4.5/is-theme-kind.d.ts +11 -0
  291. package/dist/types-ts4.5/theme-color-modes.d.ts +1 -0
  292. package/dist/types-ts4.5/theme-config.d.ts +8 -40
  293. package/dist/types-ts4.5/theme-ids.d.ts +1 -0
  294. package/dist/types-ts4.5/theme-object-to-string.d.ts +13 -0
  295. package/dist/types-ts4.5/theme-options-schema.d.ts +7 -0
  296. package/dist/types-ts4.5/theme-state-defaults.d.ts +14 -0
  297. package/dist/types-ts4.5/theme-state.d.ts +17 -0
  298. package/dist/types-ts4.5/{theme-state-transformer.d.ts → theme-string-to-object.d.ts} +0 -12
  299. package/dist/types-ts4.5/types.d.ts +75 -15
  300. package/dist/types-ts4.5/utils/additional-contrast-checker.d.ts +9 -0
  301. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -6
  302. package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +0 -9
  303. package/dist/types-ts4.5/utils/delta-e.d.ts +1 -0
  304. package/dist/types-ts4.5/utils/generate-colors.d.ts +5 -0
  305. package/dist/types-ts4.5/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -8
  306. package/dist/types-ts4.5/utils/generate-token-map.d.ts +11 -0
  307. package/dist/types-ts4.5/utils/get-contrast-ratio.d.ts +1 -0
  308. package/dist/types-ts4.5/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
  309. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
  310. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
  311. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
  312. package/dist/types-ts4.5/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
  313. package/dist/types-ts4.5/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
  314. package/dist/types-ts4.5/utils/hct-color-utils/clamp-component.d.ts +1 -0
  315. package/dist/types-ts4.5/utils/hct-color-utils/green-from-argb.d.ts +4 -0
  316. package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +2 -1
  317. package/dist/types-ts4.5/utils/hct-color-utils/lab-f.d.ts +1 -0
  318. package/dist/types-ts4.5/utils/hct-color-utils/lab-invf.d.ts +1 -0
  319. package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
  320. package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
  321. package/dist/types-ts4.5/utils/hct-color-utils/red-from-argb.d.ts +4 -0
  322. package/dist/types-ts4.5/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
  323. package/dist/types-ts4.5/utils/hct-color-utils/rgba.d.ts +14 -0
  324. package/dist/types-ts4.5/utils/hct-color-utils/white-point-d65.d.ts +6 -0
  325. package/dist/types-ts4.5/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
  326. package/dist/types-ts4.5/utils/hex-to-hsl.d.ts +5 -0
  327. package/dist/types-ts4.5/utils/hex-to-rgb-a.d.ts +6 -0
  328. package/dist/types-ts4.5/utils/hex-to-rgb.d.ts +5 -0
  329. package/dist/types-ts4.5/utils/is-valid-hex.d.ts +1 -0
  330. package/dist/types-ts4.5/utils/reduce-token-map.d.ts +6 -0
  331. package/dist/types-ts4.5/utils/rgb-to-lab.d.ts +5 -0
  332. package/figma/atlassian-dark-increased-contrast.json +180 -0
  333. package/figma/atlassian-dark.json +180 -0
  334. package/figma/atlassian-light-increased-contrast.json +180 -0
  335. package/figma/atlassian-light.json +180 -0
  336. package/package.json +7 -7
  337. package/dist/cjs/theme-state-transformer.js +0 -93
  338. package/dist/cjs/utils/color-utils.js +0 -176
  339. package/dist/cjs/utils/hct-color-utils/color-utils.js +0 -279
  340. package/dist/es2019/theme-state-transformer.js +0 -70
  341. package/dist/es2019/utils/color-utils.js +0 -136
  342. package/dist/es2019/utils/hct-color-utils/color-utils.js +0 -249
  343. package/dist/esm/theme-state-transformer.js +0 -86
  344. package/dist/esm/utils/color-utils.js +0 -138
  345. package/dist/esm/utils/hct-color-utils/color-utils.js +0 -248
  346. package/dist/types/utils/color-utils.d.ts +0 -10
  347. package/dist/types/utils/hct-color-utils/color-utils.d.ts +0 -88
  348. package/dist/types-ts4.5/utils/color-utils.d.ts +0 -23
  349. package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +0 -88
@@ -0,0 +1,39 @@
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
+ const getColorFromTokenRaw = (tokenName, mode) => {
6
+ return mode === 'light' ? tokenValuesLight[tokenName] : tokenValuesDark[tokenName];
7
+ };
8
+ export const additionalContrastChecker = ({
9
+ customThemeTokenMap,
10
+ mode,
11
+ themeRamp
12
+ }) => {
13
+ const updatedCustomThemeTokenMap = {};
14
+ const brandTokens = Object.keys(customThemeTokenMap);
15
+ additionalChecks.forEach(pairing => {
16
+ const {
17
+ backgroundLight,
18
+ backgroundDark,
19
+ foreground,
20
+ desiredContrast,
21
+ updatedTokens
22
+ } = pairing;
23
+ const background = mode === 'light' ? backgroundLight : backgroundDark;
24
+ const foregroundTokenValue = customThemeTokenMap[foreground];
25
+ const backgroundTokenValue = customThemeTokenMap[background];
26
+ const foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
27
+ const backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
28
+ const contrast = getContrastRatio(foregroundColor, backgroundColor);
29
+ if (contrast <= desiredContrast) {
30
+ updatedTokens.forEach(token => {
31
+ const rampValue = customThemeTokenMap[token];
32
+ if (typeof rampValue === 'number') {
33
+ updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
34
+ }
35
+ });
36
+ }
37
+ });
38
+ return updatedCustomThemeTokenMap;
39
+ };
@@ -1,4 +1,3 @@
1
- import tokens from '../artifacts/token-names';
2
1
  import { CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from '../constants';
3
2
  import { hash } from './hash';
4
3
  export function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
@@ -15,13 +14,4 @@ export function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
15
14
  }
16
15
  });
17
16
  return attrOfMissingCustomStyles;
18
- }
19
-
20
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
21
- export function reduceTokenMap(tokenMap, themeRamp) {
22
- return Object.entries(tokenMap).reduce((acc, [key, value]) => {
23
- const cssVar = tokens[key];
24
- return cssVar ? `${acc}\n ${cssVar}: ${typeof value === 'string' ? value : themeRamp[value]};` : acc;
25
- }, '');
26
- }
27
- 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 const additionalChecks = [{
5
2
  foreground: 'color.text.brand',
6
3
  backgroundLight: 'elevation.surface.sunken',
@@ -42,41 +39,4 @@ export const 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
- const getColorFromTokenRaw = (tokenName, mode) => {
47
- return mode === 'light' ? tokenValuesLight[tokenName] : tokenValuesDark[tokenName];
48
- };
49
-
50
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
51
- export const additionalContrastChecker = ({
52
- customThemeTokenMap,
53
- mode,
54
- themeRamp
55
- }) => {
56
- const updatedCustomThemeTokenMap = {};
57
- const brandTokens = Object.keys(customThemeTokenMap);
58
- additionalChecks.forEach(pairing => {
59
- const {
60
- backgroundLight,
61
- backgroundDark,
62
- foreground,
63
- desiredContrast,
64
- updatedTokens
65
- } = pairing;
66
- const background = mode === 'light' ? backgroundLight : backgroundDark;
67
- const foregroundTokenValue = customThemeTokenMap[foreground];
68
- const backgroundTokenValue = customThemeTokenMap[background];
69
- const foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
70
- const backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
71
- const contrast = getContrastRatio(foregroundColor, backgroundColor);
72
- if (contrast <= desiredContrast) {
73
- updatedTokens.forEach(token => {
74
- const rampValue = customThemeTokenMap[token];
75
- if (typeof rampValue === 'number') {
76
- updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
77
- }
78
- });
79
- }
80
- });
81
- return updatedCustomThemeTokenMap;
82
- };
42
+ }];
@@ -0,0 +1,20 @@
1
+ import { rgbToLab } from './rgb-to-lab';
2
+ export function deltaE(rgbA, rgbB) {
3
+ let labA = rgbToLab(rgbA);
4
+ let labB = rgbToLab(rgbB);
5
+ let deltaL = labA[0] - labB[0];
6
+ let deltaA = labA[1] - labB[1];
7
+ let deltaB = labA[2] - labB[2];
8
+ let c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
9
+ let c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
10
+ let deltaC = c1 - c2;
11
+ let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
12
+ deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
13
+ let sc = 1.0 + 0.045 * c1;
14
+ let sh = 1.0 + 0.015 * c1;
15
+ let deltaLKlsl = deltaL / 1.0;
16
+ let deltaCkcsc = deltaC / sc;
17
+ let deltaHkhsh = deltaH / sh;
18
+ let i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
19
+ return i < 0 ? 0 : Math.sqrt(i);
20
+ }
@@ -0,0 +1,39 @@
1
+ import { getClosestColorIndex } from './get-closest-color-index';
2
+ import { argbFromRgba, Contrast, Hct, rgbaFromArgb } from './hct-color-utils';
3
+ import { hexToHSL } from './hex-to-hsl';
4
+ import { hexToRgbA } from './hex-to-rgb-a';
5
+ import { HSLToRGB } from './hsl-to-rgb';
6
+ import { relativeLuminanceW3C } from './relative-luminance-w3-c';
7
+ import { rgbToHex } from './rgb-to-hex';
8
+ const lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
9
+ const highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
10
+ export const generateColors = brandColor => {
11
+ // Determine luminance
12
+ const HSLBrandColorHue = hexToHSL(brandColor)[0];
13
+ const baseRgb = HSLToRGB(HSLBrandColorHue, 100, 60);
14
+ const isLowLuminance = relativeLuminanceW3C(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
15
+ // Choose right palette
16
+ const themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
17
+ const brandRgba = hexToRgbA(brandColor);
18
+ const hctColor = Hct.fromInt(argbFromRgba({
19
+ r: brandRgba[0],
20
+ g: brandRgba[1],
21
+ b: brandRgba[2],
22
+ a: brandRgba[3]
23
+ }));
24
+ const themeRamp = themeRatios.map(contrast => {
25
+ const rgbaColor = rgbaFromArgb(Hct.from(hctColor.hue, hctColor.chroma, Contrast.darker(100, contrast) + 0.25 // Material's utils provide an offset
26
+ ).toInt());
27
+ return rgbToHex(rgbaColor.r, rgbaColor.g, rgbaColor.b);
28
+ });
29
+ const closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
30
+
31
+ // Replace closet color with brandColor
32
+ const updatedThemeRamp = [...themeRamp];
33
+ updatedThemeRamp[closestColorIndex] = brandColor;
34
+ return {
35
+ ramp: updatedThemeRamp,
36
+ // add the replaced color into the result
37
+ replacedColor: themeRamp[closestColorIndex]
38
+ };
39
+ };
@@ -0,0 +1,21 @@
1
+ import { additionalContrastChecker } from './additional-contrast-checker';
2
+ import { generateColors } from './generate-colors';
3
+ import { generateTokenMap } from './generate-token-map';
4
+ export const generateTokenMapWithContrastCheck = (brandColor, mode, themeRamp) => {
5
+ const colors = themeRamp || generateColors(brandColor).ramp;
6
+ const tokenMaps = generateTokenMap(brandColor, mode, colors);
7
+ const result = {};
8
+ Object.entries(tokenMaps).forEach(([mode, map]) => {
9
+ if (mode === 'light' || mode === 'dark') {
10
+ result[mode] = {
11
+ ...map,
12
+ ...additionalContrastChecker({
13
+ customThemeTokenMap: map,
14
+ mode,
15
+ themeRamp: colors
16
+ })
17
+ };
18
+ }
19
+ });
20
+ return result;
21
+ };
@@ -1,44 +1,7 @@
1
1
  import rawTokensDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
2
- import { getContrastRatio, hexToHSL, hexToRgbA } from './color-utils';
3
- import { additionalContrastChecker } from './custom-theme-token-contrast-check';
2
+ import { generateColors } from './generate-colors';
4
3
  import { getClosestColorIndex } from './get-closest-color-index';
5
- import { argbFromRgba, Contrast, Hct, rgbaFromArgb } from './hct-color-utils';
6
- import { HSLToRGB } from './hsl-to-rgb';
7
- import { relativeLuminanceW3C } from './relative-luminance-w3-c';
8
- import { rgbToHex } from './rgb-to-hex';
9
- const lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
10
- const highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
11
- export const generateColors = brandColor => {
12
- // Determine luminance
13
- const HSLBrandColorHue = hexToHSL(brandColor)[0];
14
- const baseRgb = HSLToRGB(HSLBrandColorHue, 100, 60);
15
- const isLowLuminance = relativeLuminanceW3C(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
16
- // Choose right palette
17
- const themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
18
- const brandRgba = hexToRgbA(brandColor);
19
- const hctColor = Hct.fromInt(argbFromRgba({
20
- r: brandRgba[0],
21
- g: brandRgba[1],
22
- b: brandRgba[2],
23
- a: brandRgba[3]
24
- }));
25
- const themeRamp = themeRatios.map(contrast => {
26
- const 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
- const closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
31
-
32
- // Replace closet color with brandColor
33
- const updatedThemeRamp = [...themeRamp];
34
- updatedThemeRamp[closestColorIndex] = brandColor;
35
- return {
36
- ramp: updatedThemeRamp,
37
- // add the replaced color into the result
38
- replacedColor: themeRamp[closestColorIndex]
39
- };
40
- };
41
-
4
+ import { getContrastRatio } from './get-contrast-ratio';
42
5
  /**
43
6
  * Return the interaction tokens for a color, given its ramp position and the number of
44
7
  * needed interaction states. Use higher-indexed colors (i.e. darker colors) if possible;
@@ -58,8 +21,6 @@ function getInteractionStates(rampPosition, number, colors) {
58
21
  }
59
22
  return result;
60
23
  }
61
-
62
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
63
24
  export const generateTokenMap = (brandColor, mode, themeRamp) => {
64
25
  const {
65
26
  ramp,
@@ -191,25 +152,4 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
191
152
  light: customThemeTokenMapLight,
192
153
  dark: customThemeTokenMapDark
193
154
  };
194
- };
195
-
196
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
197
- export const generateTokenMapWithContrastCheck = (brandColor, mode, themeRamp) => {
198
- const colors = themeRamp || generateColors(brandColor).ramp;
199
- const tokenMaps = generateTokenMap(brandColor, mode, colors);
200
- const result = {};
201
- Object.entries(tokenMaps).forEach(([mode, map]) => {
202
- if (mode === 'light' || mode === 'dark') {
203
- result[mode] = {
204
- ...map,
205
- ...additionalContrastChecker({
206
- customThemeTokenMap: map,
207
- mode,
208
- themeRamp: colors
209
- })
210
- };
211
- }
212
- });
213
- return result;
214
- };
215
- export { getClosestColorIndex } from './get-closest-color-index';
155
+ };
@@ -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 const getClosestColorIndex = (themeRamp, brandColor) => {
3
4
  // Iterate over themeRamp and find whichever color is closest to brandColor
4
5
  let 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
+ const foregroundRgb = hexToRgb(foreground);
9
+ const backgroundRgb = hexToRgb(background);
10
+ const foregroundLuminance = relativeLuminanceW3C(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
11
+ const 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
+ const r = delinearized(linrgb[0]);
9
+ const g = delinearized(linrgb[1]);
10
+ const 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
+ const y = yFromLstar(lstar);
14
+ const component = delinearized(y);
15
+ return argbFromRgb(component, component, component);
16
+ }
@@ -0,0 +1,19 @@
1
+ import { clampComponent } from './clamp-component';
2
+ /**
3
+ * Return int32 color from a given RGBA component
4
+ *
5
+ * @param rgba RGBA representation of a int32 color.
6
+ * @returns ARGB representation of a int32 color.
7
+ */
8
+ export function argbFromRgba({
9
+ r,
10
+ g,
11
+ b,
12
+ a
13
+ }) {
14
+ const rValue = clampComponent(r);
15
+ const gValue = clampComponent(g);
16
+ const bValue = clampComponent(b);
17
+ const aValue = clampComponent(a);
18
+ return aValue << 24 | rValue << 16 | gValue << 8 | bValue;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { argbFromRgb } from './argb-from-rgb';
2
+ import { delinearized } from './delinearized';
3
+
4
+ /**
5
+ * Color science utilities.
6
+ *
7
+ * Utility methods for color science constants and color space
8
+ * conversions that aren't HCT or CAM16.
9
+ */
10
+ const XYZ_TO_SRGB = [[3.2413774792388685, -1.5376652402851851, -0.49885366846268053], [-0.9691452513005321, 1.8758853451067872, 0.04156585616912061], [0.05562093689691305, -0.20395524564742123, 1.0571799111220335]];
11
+
12
+ /**
13
+ * Converts a color from ARGB to XYZ.
14
+ */
15
+ export function argbFromXyz(x, y, z) {
16
+ const matrix = XYZ_TO_SRGB;
17
+ const linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z;
18
+ const linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z;
19
+ const linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;
20
+ const r = delinearized(linearR);
21
+ const g = delinearized(linearG);
22
+ const b = delinearized(linearB);
23
+ return argbFromRgb(r, g, b);
24
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the blue component of a color in ARGB format.
3
+ */
4
+ export function blueFromArgb(argb) {
5
+ return argb & 255;
6
+ }
@@ -0,0 +1,9 @@
1
+ export function clampComponent(value) {
2
+ if (value < 0) {
3
+ return 0;
4
+ }
5
+ if (value > 255) {
6
+ return 255;
7
+ }
8
+ return value;
9
+ }
@@ -26,9 +26,9 @@
26
26
  //
27
27
  // tslint:disable:class-as-namespace
28
28
 
29
- import * as utils from './color-utils';
30
- import * as math from './math-utils';
31
-
29
+ import { clampDouble } from './clamp-double';
30
+ import { lstarFromY } from './lstar-from-y';
31
+ import { yFromLstar } from './y-from-lstar';
32
32
  /**
33
33
  * Utility methods for calculating contrast given two colors, or calculating a
34
34
  * color given one color and a contrast ratio.
@@ -49,9 +49,9 @@ export class Contrast {
49
49
  * @param toneB Tone between 0 and 100. Values outside will be clamped.
50
50
  */
51
51
  static ratioOfTones(toneA, toneB) {
52
- toneA = math.clampDouble(0.0, 100.0, toneA);
53
- toneB = math.clampDouble(0.0, 100.0, toneB);
54
- return Contrast.ratioOfYs(utils.yFromLstar(toneA), utils.yFromLstar(toneB));
52
+ toneA = clampDouble(0.0, 100.0, toneA);
53
+ toneB = clampDouble(0.0, 100.0, toneB);
54
+ return Contrast.ratioOfYs(yFromLstar(toneA), yFromLstar(toneB));
55
55
  }
56
56
  static ratioOfYs(y1, y2) {
57
57
  const lighter = y1 > y2 ? y1 : y2;
@@ -73,7 +73,7 @@ export class Contrast {
73
73
  if (tone < 0.0 || tone > 100.0) {
74
74
  return -1.0;
75
75
  }
76
- const darkY = utils.yFromLstar(tone);
76
+ const darkY = yFromLstar(tone);
77
77
  const lightY = ratio * (darkY + 5.0) - 5.0;
78
78
  const realContrast = Contrast.ratioOfYs(lightY, darkY);
79
79
  const delta = Math.abs(realContrast - ratio);
@@ -83,7 +83,7 @@ export class Contrast {
83
83
 
84
84
  // Ensure gamut mapping, which requires a 'range' on tone, will still result
85
85
  // the correct ratio by darkening slightly.
86
- const returnValue = utils.lstarFromY(lightY) + 0.4;
86
+ const returnValue = lstarFromY(lightY) + 0.4;
87
87
  if (returnValue < 0 || returnValue > 100) {
88
88
  return -1;
89
89
  }
@@ -104,7 +104,7 @@ export class Contrast {
104
104
  if (tone < 0.0 || tone > 100.0) {
105
105
  return -1.0;
106
106
  }
107
- const lightY = utils.yFromLstar(tone);
107
+ const lightY = yFromLstar(tone);
108
108
  const darkY = (lightY + 5.0) / ratio - 5.0;
109
109
  const realContrast = Contrast.ratioOfYs(lightY, darkY);
110
110
  const delta = Math.abs(realContrast - ratio);
@@ -114,7 +114,7 @@ export class Contrast {
114
114
 
115
115
  // Ensure gamut mapping, which requires a 'range' on tone, will still result
116
116
  // the correct ratio by darkening slightly.
117
- const returnValue = utils.lstarFromY(darkY) - 0.4;
117
+ const returnValue = lstarFromY(darkY) - 0.4;
118
118
  if (returnValue < 0 || returnValue > 100) {
119
119
  return -1;
120
120
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the green component of a color in ARGB format.
3
+ */
4
+ export function greenFromArgb(argb) {
5
+ return argb >> 8 & 255;
6
+ }
@@ -21,9 +21,16 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
21
21
  * limitations under the License.
22
22
  */
23
23
 
24
- import * as utils from './color-utils';
24
+ import { argbFromLinrgb } from './argb-from-linrgb';
25
+ import { argbFromLstar } from './argb-from-lstar';
26
+ import { argbFromXyz } from './argb-from-xyz';
27
+ import { linearized } from './linearized';
28
+ import { lstarFromArgb } from './lstar-from-argb';
29
+ import { lstarFromY } from './lstar-from-y';
25
30
  import * as math from './math-utils';
26
31
  import { ViewingConditions } from './viewing-conditions';
32
+ import { yFromLstar } from './y-from-lstar';
33
+
27
34
  /**
28
35
  * A color system built using CAM16 hue and chroma, and L* from
29
36
  * L*a*b*.
@@ -119,13 +126,13 @@ export class Hct {
119
126
  const cam = Cam16.fromInt(argb);
120
127
  this.internalHue = cam.hue;
121
128
  this.internalChroma = cam.chroma;
122
- this.internalTone = utils.lstarFromArgb(argb);
129
+ this.internalTone = lstarFromArgb(argb);
123
130
  }
124
131
  setInternalState(argb) {
125
132
  const cam = Cam16.fromInt(argb);
126
133
  this.internalHue = cam.hue;
127
134
  this.internalChroma = cam.chroma;
128
- this.internalTone = utils.lstarFromArgb(argb);
135
+ this.internalTone = lstarFromArgb(argb);
129
136
  this.argb = argb;
130
137
  }
131
138
 
@@ -154,7 +161,7 @@ export class Hct {
154
161
  // 3. Create HCT from:
155
162
  // - CAM16 using default VC with XYZ coordinates in specified VC.
156
163
  // - L* converted from Y in XYZ coordinates in specified VC.
157
- const recastHct = Hct.from(recastInVc.hue, recastInVc.chroma, utils.lstarFromY(viewedInVc[1]));
164
+ const recastHct = Hct.from(recastInVc.hue, recastInVc.chroma, lstarFromY(viewedInVc[1]));
158
165
  return recastHct;
159
166
  }
160
167
  }
@@ -243,9 +250,9 @@ class Cam16 {
243
250
  const red = (argb & 0x00ff0000) >> 16;
244
251
  const green = (argb & 0x0000ff00) >> 8;
245
252
  const blue = argb & 0x000000ff;
246
- const redL = utils.linearized(red);
247
- const greenL = utils.linearized(green);
248
- const blueL = utils.linearized(blue);
253
+ const redL = linearized(red);
254
+ const greenL = linearized(green);
255
+ const blueL = linearized(blue);
249
256
  const x = 0.41233895 * redL + 0.35762064 * greenL + 0.18051042 * blueL;
250
257
  const y = 0.2126 * redL + 0.7152 * greenL + 0.0722 * blueL;
251
258
  const z = 0.01932141 * redL + 0.11916382 * greenL + 0.95034478 * blueL;
@@ -392,7 +399,7 @@ class Cam16 {
392
399
  const x = 1.86206786 * rF - 1.01125463 * gF + 0.14918677 * bF;
393
400
  const y = 0.38752654 * rF + 0.62144744 * gF - 0.00897398 * bF;
394
401
  const z = -0.0158415 * rF - 0.03412294 * gF + 1.04996444 * bF;
395
- const argb = utils.argbFromXyz(x, y, z);
402
+ const argb = argbFromXyz(x, y, z);
396
403
  return argb;
397
404
  }
398
405
 
@@ -801,7 +808,7 @@ class HctSolver {
801
808
  if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) {
802
809
  return 0;
803
810
  }
804
- return utils.argbFromLinrgb(linrgb);
811
+ return argbFromLinrgb(linrgb);
805
812
  }
806
813
  // Iterates with Newton method,
807
814
  // Using 2 * fn(j) / j as the approximation of fn'(j)
@@ -824,17 +831,17 @@ class HctSolver {
824
831
  */
825
832
  static solveToInt(hueDegrees, chroma, lstar) {
826
833
  if (chroma < 0.0001 || lstar < 0.0001 || lstar > 99.9999) {
827
- return utils.argbFromLstar(lstar);
834
+ return argbFromLstar(lstar);
828
835
  }
829
836
  hueDegrees = math.sanitizeDegreesDouble(hueDegrees);
830
837
  const hueRadians = hueDegrees / 180 * Math.PI;
831
- const y = utils.yFromLstar(lstar);
838
+ const y = yFromLstar(lstar);
832
839
  const exactAnswer = HctSolver.findResultByJ(hueRadians, chroma, y);
833
840
  if (exactAnswer !== 0) {
834
841
  return exactAnswer;
835
842
  }
836
843
  const linrgb = HctSolver.bisectToLimit(y, hueRadians);
837
- return utils.argbFromLinrgb(linrgb);
844
+ return argbFromLinrgb(linrgb);
838
845
  }
839
846
 
840
847
  /**
@@ -1,3 +1,4 @@
1
1
  export { Hct } from './hct';
2
2
  export { Contrast } from './contrast';
3
- export { argbFromRgba, rgbaFromArgb } from './color-utils';
3
+ export { argbFromRgba } from './argb-from-rgba';
4
+ export { rgbaFromArgb } from './rgba-from-argb';
@@ -0,0 +1,9 @@
1
+ export function labF(t) {
2
+ const e = 216.0 / 24389.0;
3
+ const kappa = 24389.0 / 27.0;
4
+ if (t > e) {
5
+ return Math.pow(t, 1.0 / 3.0);
6
+ } else {
7
+ return (kappa * t + 16) / 116;
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ export function labInvf(ft) {
2
+ const e = 216.0 / 24389.0;
3
+ const kappa = 24389.0 / 27.0;
4
+ const ft3 = ft * ft * ft;
5
+ if (ft3 > e) {
6
+ return ft3;
7
+ } else {
8
+ return (116 * ft - 16) / kappa;
9
+ }
10
+ }
@@ -0,0 +1,28 @@
1
+ import { blueFromArgb } from './blue-from-argb';
2
+ import { greenFromArgb } from './green-from-argb';
3
+ import { labF } from './lab-f';
4
+ import { linearized } from './linearized';
5
+ import { matrixMultiply } from './matrix-multiply';
6
+ import { redFromArgb } from './red-from-argb';
7
+ const SRGB_TO_XYZ = [[0.41233895, 0.35762064, 0.18051042], [0.2126, 0.7152, 0.0722], [0.01932141, 0.11916382, 0.95034478]];
8
+
9
+ /**
10
+ * Converts a color from XYZ to ARGB.
11
+ */
12
+ function xyzFromArgb(argb) {
13
+ const r = linearized(redFromArgb(argb));
14
+ const g = linearized(greenFromArgb(argb));
15
+ const b = linearized(blueFromArgb(argb));
16
+ return matrixMultiply([r, g, b], SRGB_TO_XYZ);
17
+ }
18
+
19
+ /**
20
+ * Computes the L* value of a color in ARGB representation.
21
+ *
22
+ * @param argb ARGB representation of a color
23
+ * @return L*, from L*a*b*, coordinate of the color
24
+ */
25
+ export function lstarFromArgb(argb) {
26
+ const y = xyzFromArgb(argb)[1];
27
+ return 116.0 * labF(y / 100.0) - 16.0;
28
+ }
@@ -0,0 +1,16 @@
1
+ import { labF } from './lab-f';
2
+
3
+ /**
4
+ * Converts a Y value to an L* value.
5
+ *
6
+ * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
7
+ *
8
+ * L* measures perceptual luminance, a linear scale. Y in XYZ
9
+ * measures relative luminance, a logarithmic scale.
10
+ *
11
+ * @param y Y in XYZ
12
+ * @return L* in L*a*b*
13
+ */
14
+ export function lstarFromY(y) {
15
+ return labF(y / 100.0) * 116.0 - 16.0;
16
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the red component of a color in ARGB format.
3
+ */
4
+ export function redFromArgb(argb) {
5
+ return argb >> 16 & 255;
6
+ }