@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
@@ -1,271 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.argbFromLinrgb = argbFromLinrgb;
8
- exports.argbFromLstar = argbFromLstar;
9
- Object.defineProperty(exports, "argbFromRgb", {
10
- enumerable: true,
11
- get: function get() {
12
- return _argbFromRgb.argbFromRgb;
13
- }
14
- });
15
- exports.argbFromRgba = argbFromRgba;
16
- exports.argbFromXyz = argbFromXyz;
17
- Object.defineProperty(exports, "delinearized", {
18
- enumerable: true,
19
- get: function get() {
20
- return _delinearized.delinearized;
21
- }
22
- });
23
- Object.defineProperty(exports, "linearized", {
24
- enumerable: true,
25
- get: function get() {
26
- return _linearized.linearized;
27
- }
28
- });
29
- exports.lstarFromArgb = lstarFromArgb;
30
- exports.lstarFromY = lstarFromY;
31
- exports.rgbaFromArgb = rgbaFromArgb;
32
- exports.whitePointD65 = whitePointD65;
33
- exports.yFromLstar = yFromLstar;
34
- var _argbFromRgb = require("./argb-from-rgb");
35
- var _delinearized = require("./delinearized");
36
- var _linearized = require("./linearized");
37
- var mathUtils = _interopRequireWildcard(require("./math-utils"));
38
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
39
- /**
40
- * Below lines are copied from @material/material-color-utilities.
41
- * Do not modify it.
42
- */
43
-
44
- /**
45
- * @license
46
- * Copyright 2021 Google LLC
47
- *
48
- * Licensed under the Apache License, Version 2.0 (the "License");
49
- * you may not use this file except in compliance with the License.
50
- * You may obtain a copy of the License at
51
- *
52
- * http://www.apache.org/licenses/LICENSE-2.0
53
- *
54
- * Unless required by applicable law or agreed to in writing, software
55
- * distributed under the License is distributed on an "AS IS" BASIS,
56
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57
- * See the License for the specific language governing permissions and
58
- * limitations under the License.
59
- */
60
-
61
- // This file is automatically generated. Do not modify it.
62
-
63
- /**
64
- * Color science utilities.
65
- *
66
- * Utility methods for color science constants and color space
67
- * conversions that aren't HCT or CAM16.
68
- */
69
-
70
- var SRGB_TO_XYZ = [[0.41233895, 0.35762064, 0.18051042], [0.2126, 0.7152, 0.0722], [0.01932141, 0.11916382, 0.95034478]];
71
- var XYZ_TO_SRGB = [[3.2413774792388685, -1.5376652402851851, -0.49885366846268053], [-0.9691452513005321, 1.8758853451067872, 0.04156585616912061], [0.05562093689691305, -0.20395524564742123, 1.0571799111220335]];
72
- var WHITE_POINT_D65 = [95.047, 100.0, 108.883];
73
-
74
- /**
75
- * Converts a color from linear RGB components to ARGB format.
76
- */
77
- function argbFromLinrgb(linrgb) {
78
- var r = (0, _delinearized.delinearized)(linrgb[0]);
79
- var g = (0, _delinearized.delinearized)(linrgb[1]);
80
- var b = (0, _delinearized.delinearized)(linrgb[2]);
81
- return (0, _argbFromRgb.argbFromRgb)(r, g, b);
82
- }
83
-
84
- /**
85
- * Returns the alpha component of a color in ARGB format.
86
- */
87
- function alphaFromArgb(argb) {
88
- return argb >> 24 & 255;
89
- }
90
-
91
- /**
92
- * Returns the red component of a color in ARGB format.
93
- */
94
- function redFromArgb(argb) {
95
- return argb >> 16 & 255;
96
- }
97
-
98
- /**
99
- * Returns the green component of a color in ARGB format.
100
- */
101
- function greenFromArgb(argb) {
102
- return argb >> 8 & 255;
103
- }
104
-
105
- /**
106
- * Returns the blue component of a color in ARGB format.
107
- */
108
- function blueFromArgb(argb) {
109
- return argb & 255;
110
- }
111
-
112
- /**
113
- * Converts a color from ARGB to XYZ.
114
- */
115
- function argbFromXyz(x, y, z) {
116
- var matrix = XYZ_TO_SRGB;
117
- var linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z;
118
- var linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z;
119
- var linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;
120
- var r = (0, _delinearized.delinearized)(linearR);
121
- var g = (0, _delinearized.delinearized)(linearG);
122
- var b = (0, _delinearized.delinearized)(linearB);
123
- return (0, _argbFromRgb.argbFromRgb)(r, g, b);
124
- }
125
-
126
- /**
127
- * Converts a color from XYZ to ARGB.
128
- */
129
- function xyzFromArgb(argb) {
130
- var r = (0, _linearized.linearized)(redFromArgb(argb));
131
- var g = (0, _linearized.linearized)(greenFromArgb(argb));
132
- var b = (0, _linearized.linearized)(blueFromArgb(argb));
133
- return mathUtils.matrixMultiply([r, g, b], SRGB_TO_XYZ);
134
- }
135
-
136
- /**
137
- * Converts an L* value to an ARGB representation.
138
- *
139
- * @param lstar L* in L*a*b*
140
- * @return ARGB representation of grayscale color with lightness
141
- * matching L*
142
- */
143
- function argbFromLstar(lstar) {
144
- var y = yFromLstar(lstar);
145
- var component = (0, _delinearized.delinearized)(y);
146
- return (0, _argbFromRgb.argbFromRgb)(component, component, component);
147
- }
148
-
149
- /**
150
- * Computes the L* value of a color in ARGB representation.
151
- *
152
- * @param argb ARGB representation of a color
153
- * @return L*, from L*a*b*, coordinate of the color
154
- */
155
- function lstarFromArgb(argb) {
156
- var y = xyzFromArgb(argb)[1];
157
- return 116.0 * labF(y / 100.0) - 16.0;
158
- }
159
-
160
- /**
161
- * Converts an L* value to a Y value.
162
- *
163
- * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
164
- *
165
- * L* measures perceptual luminance, a linear scale. Y in XYZ
166
- * measures relative luminance, a logarithmic scale.
167
- *
168
- * @param lstar L* in L*a*b*
169
- * @return Y in XYZ
170
- */
171
- function yFromLstar(lstar) {
172
- return 100.0 * labInvf((lstar + 16.0) / 116.0);
173
- }
174
-
175
- /**
176
- * Converts a Y value to an L* value.
177
- *
178
- * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
179
- *
180
- * L* measures perceptual luminance, a linear scale. Y in XYZ
181
- * measures relative luminance, a logarithmic scale.
182
- *
183
- * @param y Y in XYZ
184
- * @return L* in L*a*b*
185
- */
186
- function lstarFromY(y) {
187
- return labF(y / 100.0) * 116.0 - 16.0;
188
- }
189
-
190
- /**
191
- * Returns the standard white point; white on a sunny day.
192
- *
193
- * @return The white point
194
- */
195
- function whitePointD65() {
196
- return WHITE_POINT_D65;
197
- }
198
-
199
- /**
200
- * RGBA component
201
- *
202
- * @param r Red value should be between 0-255
203
- * @param g Green value should be between 0-255
204
- * @param b Blue value should be between 0-255
205
- * @param a Alpha value should be between 0-255
206
- */
207
-
208
- /**
209
- * Return RGBA from a given int32 color
210
- *
211
- * @param argb ARGB representation of a int32 color.
212
- * @return RGBA representation of a int32 color.
213
- */
214
- function rgbaFromArgb(argb) {
215
- var r = redFromArgb(argb);
216
- var g = greenFromArgb(argb);
217
- var b = blueFromArgb(argb);
218
- var a = alphaFromArgb(argb);
219
- return {
220
- r: r,
221
- g: g,
222
- b: b,
223
- a: a
224
- };
225
- }
226
-
227
- /**
228
- * Return int32 color from a given RGBA component
229
- *
230
- * @param rgba RGBA representation of a int32 color.
231
- * @returns ARGB representation of a int32 color.
232
- */
233
- function argbFromRgba(_ref) {
234
- var r = _ref.r,
235
- g = _ref.g,
236
- b = _ref.b,
237
- a = _ref.a;
238
- var rValue = clampComponent(r);
239
- var gValue = clampComponent(g);
240
- var bValue = clampComponent(b);
241
- var aValue = clampComponent(a);
242
- return aValue << 24 | rValue << 16 | gValue << 8 | bValue;
243
- }
244
- function clampComponent(value) {
245
- if (value < 0) {
246
- return 0;
247
- }
248
- if (value > 255) {
249
- return 255;
250
- }
251
- return value;
252
- }
253
- function labF(t) {
254
- var e = 216.0 / 24389.0;
255
- var kappa = 24389.0 / 27.0;
256
- if (t > e) {
257
- return Math.pow(t, 1.0 / 3.0);
258
- } else {
259
- return (kappa * t + 16) / 116;
260
- }
261
- }
262
- function labInvf(ft) {
263
- var e = 216.0 / 24389.0;
264
- var kappa = 24389.0 / 27.0;
265
- var ft3 = ft * ft * ft;
266
- if (ft3 > e) {
267
- return ft3;
268
- } else {
269
- return (116 * ft - 16) / kappa;
270
- }
271
- }
@@ -1,69 +0,0 @@
1
- import { themeIds } from './theme-ids';
2
- const themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape', 'motion'];
3
- const customThemeOptions = 'UNSAFE_themeOptions';
4
- const isThemeKind = themeKind => {
5
- return themeKinds.find(kind => kind === themeKind) !== undefined;
6
- };
7
- const isThemeIds = themeId => {
8
- return themeIds.find(id => id === themeId) !== undefined;
9
- };
10
- const isColorMode = modeId => {
11
- return ['light', 'dark', 'auto'].includes(modeId);
12
- };
13
- /**
14
- * Converts a string that is formatted for the `data-theme` HTML attribute
15
- * to an object that can be passed to `setGlobalTheme`.
16
- *
17
- * @param {string} themes The themes that should be applied.
18
- *
19
- * @example
20
- * ```
21
- * themeStringToObject('dark:dark light:light spacing:spacing');
22
- * // returns { dark: 'dark', light: 'light', spacing: 'spacing' }
23
- * ```
24
- */
25
- export const themeStringToObject = themeState => {
26
- return themeState.split(' ')
27
- // @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
28
- .map(theme => theme.split(/:(.*)/s)).reduce((themeObject, [kind, id]) => {
29
- if (kind === 'colorMode' && isColorMode(id)) {
30
- themeObject[kind] = id;
31
- }
32
- if (isThemeKind(kind) && isThemeIds(id)) {
33
- // @ts-expect-error FIXME - this is a valid ts error
34
- themeObject[kind] = id;
35
- }
36
- if (kind === customThemeOptions) {
37
- try {
38
- themeObject[customThemeOptions] = JSON.parse(id);
39
- } catch {
40
- new Error('Invalid custom theme string');
41
- }
42
- }
43
- return themeObject;
44
- }, {});
45
- };
46
-
47
- /**
48
- * Converts a theme object to a string formatted for the `data-theme` HTML attribute.
49
- *
50
- * @param {object} themes The themes that should be applied.
51
- *
52
- * @example
53
- * ```
54
- * themeObjectToString({ dark: 'dark', light: 'light', spacing: 'spacing' });
55
- * // returns 'dark:dark light:light spacing:spacing'
56
- * ```
57
- */
58
- export const themeObjectToString = themeState => Object.entries(themeState).reduce((themeString, [kind, id]) => {
59
- if (
60
- // colorMode theme state
61
- kind === 'colorMode' && typeof id === 'string' && isColorMode(id) ||
62
- // custom theme state
63
- kind === customThemeOptions && typeof id === 'object' ||
64
- // other theme states
65
- isThemeKind(kind) && typeof id === 'string' && isThemeIds(id)) {
66
- return themeString + `${themeString ? ' ' : ''}` + `${kind}:${typeof id === 'object' ? JSON.stringify(id) : id}`;
67
- }
68
- return themeString;
69
- }, '');
@@ -1,128 +0,0 @@
1
- import { getAlpha } from './get-alpha';
2
- import { relativeLuminanceW3C } from './relative-luminance-w3-c';
3
- // valid hex color with 4, 6 or 8 digits
4
- const isValidHex = hex => /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
5
- export function hexToRgbA(hex) {
6
- if (!isValidHex(hex)) {
7
- throw new Error('Invalid HEX');
8
- }
9
- let c;
10
- c = hex.substring(1).split('');
11
- if (c.length === 3) {
12
- c = [c[0], c[0], c[1], c[1], c[2], c[2]];
13
- }
14
- c = '0x' + c.join('');
15
- return [c >> 16 & 255, c >> 8 & 255, c & 255, getAlpha(hex)];
16
- }
17
- export function hexToRgb(hex) {
18
- if (!isValidHex(hex)) {
19
- throw new Error('Invalid HEX');
20
- }
21
- let c;
22
- c = hex.substring(1).split('');
23
- if (c.length === 3) {
24
- c = [c[0], c[0], c[1], c[1], c[2], c[2]];
25
- }
26
- c = '0x' + c.join('');
27
- return [c >> 16 & 255, c >> 8 & 255, c & 255];
28
- }
29
- export function hexToHSL(hex) {
30
- if (!isValidHex(hex)) {
31
- throw new Error('Invalid HEX');
32
- }
33
- let r = 0,
34
- g = 0,
35
- b = 0;
36
- if (hex.length === 4) {
37
- r = '0x' + hex[1] + hex[1];
38
- g = '0x' + hex[2] + hex[2];
39
- b = '0x' + hex[3] + hex[3];
40
- } else if (hex.length === 7) {
41
- r = '0x' + hex[1] + hex[2];
42
- g = '0x' + hex[3] + hex[4];
43
- b = '0x' + hex[5] + hex[6];
44
- }
45
- // Then to HSL
46
- r /= 255;
47
- g /= 255;
48
- b /= 255;
49
- let cmin = Math.min(r, g, b),
50
- cmax = Math.max(r, g, b),
51
- delta = cmax - cmin,
52
- h = 0,
53
- s = 0,
54
- l = 0;
55
- if (delta === 0) {
56
- h = 0;
57
- } else if (cmax === r) {
58
- h = (g - b) / delta % 6;
59
- } else if (cmax === g) {
60
- h = (b - r) / delta + 2;
61
- } else {
62
- h = (r - g) / delta + 4;
63
- }
64
- h = Math.round(h * 60);
65
- if (h < 0) {
66
- h += 360;
67
- }
68
- l = (cmax + cmin) / 2;
69
- s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
70
- s = +(s * 100).toFixed(1);
71
- l = +(l * 100).toFixed(1);
72
- return [h, s, l];
73
- }
74
- export function getContrastRatio(foreground, background) {
75
- if (!isValidHex(foreground) || !isValidHex(background)) {
76
- throw new Error('Invalid HEX');
77
- }
78
- const foregroundRgb = hexToRgb(foreground);
79
- const backgroundRgb = hexToRgb(background);
80
- const foregroundLuminance = relativeLuminanceW3C(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
81
- const backgroundLuminance = relativeLuminanceW3C(backgroundRgb[0], backgroundRgb[1], backgroundRgb[2]);
82
- // calculate the color contrast ratio
83
- var brightest = Math.max(foregroundLuminance, backgroundLuminance);
84
- var darkest = Math.min(foregroundLuminance, backgroundLuminance);
85
- return (brightest + 0.05) / (darkest + 0.05);
86
- }
87
- export function deltaE(rgbA, rgbB) {
88
- let labA = rgbToLab(rgbA);
89
- let labB = rgbToLab(rgbB);
90
- let deltaL = labA[0] - labB[0];
91
- let deltaA = labA[1] - labB[1];
92
- let deltaB = labA[2] - labB[2];
93
- let c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
94
- let c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
95
- let deltaC = c1 - c2;
96
- let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
97
- deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
98
- let sc = 1.0 + 0.045 * c1;
99
- let sh = 1.0 + 0.015 * c1;
100
- let deltaLKlsl = deltaL / 1.0;
101
- let deltaCkcsc = deltaC / sc;
102
- let deltaHkhsh = deltaH / sh;
103
- let i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
104
- return i < 0 ? 0 : Math.sqrt(i);
105
- }
106
- function rgbToLab(rgb) {
107
- let r = rgb[0] / 255,
108
- g = rgb[1] / 255,
109
- b = rgb[2] / 255,
110
- x,
111
- y,
112
- z;
113
- r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
114
- g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
115
- b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
116
- x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
117
- y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.0;
118
- z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
119
- x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
120
- y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
121
- z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
122
- return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
123
- }
124
- export { isValidBrandHex } from './is-valid-brand-hex';
125
- export { rgbToHex } from './rgb-to-hex';
126
- export { getAlpha } from './get-alpha';
127
- export { HSLToRGB } from './hsl-to-rgb';
128
- export { relativeLuminanceW3C } from './relative-luminance-w3-c';
@@ -1,241 +0,0 @@
1
- /**
2
- * Below lines are copied from @material/material-color-utilities.
3
- * Do not modify it.
4
- */
5
-
6
- /**
7
- * @license
8
- * Copyright 2021 Google LLC
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- // This file is automatically generated. Do not modify it.
24
-
25
- import { argbFromRgb } from './argb-from-rgb';
26
- import { delinearized } from './delinearized';
27
- import { linearized } from './linearized';
28
- import * as mathUtils from './math-utils';
29
- /**
30
- * Color science utilities.
31
- *
32
- * Utility methods for color science constants and color space
33
- * conversions that aren't HCT or CAM16.
34
- */
35
-
36
- const SRGB_TO_XYZ = [[0.41233895, 0.35762064, 0.18051042], [0.2126, 0.7152, 0.0722], [0.01932141, 0.11916382, 0.95034478]];
37
- const XYZ_TO_SRGB = [[3.2413774792388685, -1.5376652402851851, -0.49885366846268053], [-0.9691452513005321, 1.8758853451067872, 0.04156585616912061], [0.05562093689691305, -0.20395524564742123, 1.0571799111220335]];
38
- const WHITE_POINT_D65 = [95.047, 100.0, 108.883];
39
-
40
- /**
41
- * Converts a color from linear RGB components to ARGB format.
42
- */
43
- export function argbFromLinrgb(linrgb) {
44
- const r = delinearized(linrgb[0]);
45
- const g = delinearized(linrgb[1]);
46
- const b = delinearized(linrgb[2]);
47
- return argbFromRgb(r, g, b);
48
- }
49
-
50
- /**
51
- * Returns the alpha component of a color in ARGB format.
52
- */
53
- function alphaFromArgb(argb) {
54
- return argb >> 24 & 255;
55
- }
56
-
57
- /**
58
- * Returns the red component of a color in ARGB format.
59
- */
60
- function redFromArgb(argb) {
61
- return argb >> 16 & 255;
62
- }
63
-
64
- /**
65
- * Returns the green component of a color in ARGB format.
66
- */
67
- function greenFromArgb(argb) {
68
- return argb >> 8 & 255;
69
- }
70
-
71
- /**
72
- * Returns the blue component of a color in ARGB format.
73
- */
74
- function blueFromArgb(argb) {
75
- return argb & 255;
76
- }
77
-
78
- /**
79
- * Converts a color from ARGB to XYZ.
80
- */
81
- export function argbFromXyz(x, y, z) {
82
- const matrix = XYZ_TO_SRGB;
83
- const linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z;
84
- const linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z;
85
- const linearB = matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z;
86
- const r = delinearized(linearR);
87
- const g = delinearized(linearG);
88
- const b = delinearized(linearB);
89
- return argbFromRgb(r, g, b);
90
- }
91
-
92
- /**
93
- * Converts a color from XYZ to ARGB.
94
- */
95
- function xyzFromArgb(argb) {
96
- const r = linearized(redFromArgb(argb));
97
- const g = linearized(greenFromArgb(argb));
98
- const b = linearized(blueFromArgb(argb));
99
- return mathUtils.matrixMultiply([r, g, b], SRGB_TO_XYZ);
100
- }
101
-
102
- /**
103
- * Converts an L* value to an ARGB representation.
104
- *
105
- * @param lstar L* in L*a*b*
106
- * @return ARGB representation of grayscale color with lightness
107
- * matching L*
108
- */
109
- export function argbFromLstar(lstar) {
110
- const y = yFromLstar(lstar);
111
- const component = delinearized(y);
112
- return argbFromRgb(component, component, component);
113
- }
114
-
115
- /**
116
- * Computes the L* value of a color in ARGB representation.
117
- *
118
- * @param argb ARGB representation of a color
119
- * @return L*, from L*a*b*, coordinate of the color
120
- */
121
- export function lstarFromArgb(argb) {
122
- const y = xyzFromArgb(argb)[1];
123
- return 116.0 * labF(y / 100.0) - 16.0;
124
- }
125
-
126
- /**
127
- * Converts an L* value to a Y value.
128
- *
129
- * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
130
- *
131
- * L* measures perceptual luminance, a linear scale. Y in XYZ
132
- * measures relative luminance, a logarithmic scale.
133
- *
134
- * @param lstar L* in L*a*b*
135
- * @return Y in XYZ
136
- */
137
- export function yFromLstar(lstar) {
138
- return 100.0 * labInvf((lstar + 16.0) / 116.0);
139
- }
140
-
141
- /**
142
- * Converts a Y value to an L* value.
143
- *
144
- * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
145
- *
146
- * L* measures perceptual luminance, a linear scale. Y in XYZ
147
- * measures relative luminance, a logarithmic scale.
148
- *
149
- * @param y Y in XYZ
150
- * @return L* in L*a*b*
151
- */
152
- export function lstarFromY(y) {
153
- return labF(y / 100.0) * 116.0 - 16.0;
154
- }
155
-
156
- /**
157
- * Returns the standard white point; white on a sunny day.
158
- *
159
- * @return The white point
160
- */
161
- export function whitePointD65() {
162
- return WHITE_POINT_D65;
163
- }
164
-
165
- /**
166
- * RGBA component
167
- *
168
- * @param r Red value should be between 0-255
169
- * @param g Green value should be between 0-255
170
- * @param b Blue value should be between 0-255
171
- * @param a Alpha value should be between 0-255
172
- */
173
-
174
- /**
175
- * Return RGBA from a given int32 color
176
- *
177
- * @param argb ARGB representation of a int32 color.
178
- * @return RGBA representation of a int32 color.
179
- */
180
- export function rgbaFromArgb(argb) {
181
- const r = redFromArgb(argb);
182
- const g = greenFromArgb(argb);
183
- const b = blueFromArgb(argb);
184
- const a = alphaFromArgb(argb);
185
- return {
186
- r,
187
- g,
188
- b,
189
- a
190
- };
191
- }
192
-
193
- /**
194
- * Return int32 color from a given RGBA component
195
- *
196
- * @param rgba RGBA representation of a int32 color.
197
- * @returns ARGB representation of a int32 color.
198
- */
199
- export function argbFromRgba({
200
- r,
201
- g,
202
- b,
203
- a
204
- }) {
205
- const rValue = clampComponent(r);
206
- const gValue = clampComponent(g);
207
- const bValue = clampComponent(b);
208
- const aValue = clampComponent(a);
209
- return aValue << 24 | rValue << 16 | gValue << 8 | bValue;
210
- }
211
- function clampComponent(value) {
212
- if (value < 0) {
213
- return 0;
214
- }
215
- if (value > 255) {
216
- return 255;
217
- }
218
- return value;
219
- }
220
- function labF(t) {
221
- const e = 216.0 / 24389.0;
222
- const kappa = 24389.0 / 27.0;
223
- if (t > e) {
224
- return Math.pow(t, 1.0 / 3.0);
225
- } else {
226
- return (kappa * t + 16) / 116;
227
- }
228
- }
229
- function labInvf(ft) {
230
- const e = 216.0 / 24389.0;
231
- const kappa = 24389.0 / 27.0;
232
- const ft3 = ft * ft * ft;
233
- if (ft3 > e) {
234
- return ft3;
235
- } else {
236
- return (116 * ft - 16) / kappa;
237
- }
238
- }
239
- export { argbFromRgb } from './argb-from-rgb';
240
- export { linearized } from './linearized';
241
- export { delinearized } from './delinearized';