@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.
- package/CHANGELOG.md +34 -0
- package/codemods/css-to-design-tokens/lib/colors.tsx +3 -8
- package/codemods/css-to-design-tokens/lib/declaration.tsx +3 -13
- package/codemods/css-to-design-tokens/lib/extract-between-parentheses.tsx +4 -0
- package/codemods/css-to-design-tokens/lib/extract-less-var-name.tsx +3 -0
- package/codemods/css-to-design-tokens/lib/get-css-var-meta.tsx +13 -0
- package/codemods/css-to-design-tokens/lib/get-named-color-meta.tsx +5 -0
- package/codemods/css-to-design-tokens/lib/get-raw-color-meta.tsx +11 -0
- package/codemods/css-to-design-tokens/lib/is-css-declaration.tsx +3 -0
- package/codemods/css-to-design-tokens/lib/is-known-css-variable.tsx +5 -0
- package/codemods/css-to-design-tokens/lib/known-named-colors.tsx +150 -0
- package/codemods/css-to-design-tokens/lib/known-raw-colors.tsx +17 -0
- package/codemods/css-to-design-tokens/lib/known-variables.tsx +167 -0
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +3 -336
- package/codemods/css-to-design-tokens/lib/meta.tsx +3 -28
- package/codemods/css-to-design-tokens/lib/split-css-value.tsx +4 -0
- package/codemods/css-to-design-tokens/lib/value.tsx +6 -9
- package/codemods/css-to-design-tokens/transform.tsx +3 -1
- package/dist/cjs/artifacts/generated-pairs.js +2 -2
- package/dist/cjs/artifacts/palettes-raw/palette.js +35 -1
- package/dist/cjs/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +21 -1
- package/dist/cjs/artifacts/token-names.js +21 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +471 -31
- package/dist/cjs/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +471 -31
- package/dist/cjs/entry-points/theme-state-transformer.js +4 -3
- package/dist/cjs/entry-points/token-metadata.codegen.js +196 -16
- package/dist/cjs/get-custom-theme-styles.js +7 -6
- package/dist/cjs/get-global-theme.js +2 -2
- package/dist/cjs/get-theme-html-attrs.js +2 -2
- package/dist/cjs/index.js +4 -3
- package/dist/cjs/is-color-mode.js +9 -0
- package/dist/cjs/is-theme-ids.js +12 -0
- package/dist/cjs/is-theme-kind.js +12 -0
- package/dist/cjs/theme-config.js +8 -44
- package/dist/cjs/theme-object-to-string.js +42 -0
- package/dist/cjs/theme-options-schema.js +1 -0
- package/dist/cjs/theme-state-defaults.js +39 -0
- package/dist/cjs/theme-state.js +5 -0
- package/dist/cjs/theme-string-to-object.js +51 -0
- package/dist/cjs/utils/additional-contrast-checker.js +43 -0
- package/dist/cjs/utils/custom-theme-loading-utils.js +0 -22
- package/dist/cjs/utils/custom-theme-token-contrast-check.js +2 -40
- package/dist/cjs/utils/delta-e.js +26 -0
- package/dist/cjs/utils/generate-colors.js +47 -0
- package/dist/cjs/utils/generate-token-map-with-contrast-check.js +32 -0
- package/dist/cjs/utils/{generate-custom-color-ramp.js → generate-token-map.js} +6 -75
- package/dist/cjs/utils/get-closest-color-index.js +3 -2
- package/dist/cjs/utils/get-contrast-ratio.js +22 -0
- package/dist/cjs/utils/hct-color-utils/alpha-from-argb.js +12 -0
- package/dist/cjs/utils/hct-color-utils/argb-from-linrgb.js +17 -0
- package/dist/cjs/utils/hct-color-utils/argb-from-lstar.js +21 -0
- package/dist/cjs/utils/hct-color-utils/argb-from-rgba.js +24 -0
- package/dist/cjs/utils/hct-color-utils/argb-from-xyz.js +29 -0
- package/dist/cjs/utils/hct-color-utils/blue-from-argb.js +12 -0
- package/dist/cjs/utils/hct-color-utils/clamp-component.js +15 -0
- package/dist/cjs/utils/hct-color-utils/contrast.js +10 -11
- package/dist/cjs/utils/hct-color-utils/green-from-argb.js +12 -0
- package/dist/cjs/utils/hct-color-utils/hct.js +18 -12
- package/dist/cjs/utils/hct-color-utils/index.js +4 -3
- package/dist/cjs/utils/hct-color-utils/lab-f.js +15 -0
- package/dist/cjs/utils/hct-color-utils/lab-invf.js +16 -0
- package/dist/cjs/utils/hct-color-utils/lstar-from-argb.js +34 -0
- package/dist/cjs/utils/hct-color-utils/lstar-from-y.js +21 -0
- package/dist/cjs/utils/hct-color-utils/red-from-argb.js +12 -0
- package/dist/cjs/utils/hct-color-utils/rgba-from-argb.js +28 -0
- package/dist/cjs/utils/hct-color-utils/rgba.js +1 -0
- package/dist/cjs/utils/hct-color-utils/viewing-conditions.js +5 -4
- package/dist/cjs/utils/hct-color-utils/white-point-d65.js +14 -0
- package/dist/cjs/utils/hct-color-utils/y-from-lstar.js +21 -0
- package/dist/cjs/utils/hex-to-hsl.js +52 -0
- package/dist/cjs/utils/hex-to-rgb-a.js +20 -0
- package/dist/cjs/utils/hex-to-rgb.js +19 -0
- package/dist/cjs/utils/is-valid-hex.js +10 -0
- package/dist/cjs/utils/reduce-token-map.js +18 -0
- package/dist/cjs/utils/rgb-to-lab.js +24 -0
- package/dist/es2019/artifacts/generated-pairs.js +2 -2
- package/dist/es2019/artifacts/palettes-raw/palette.js +35 -1
- package/dist/es2019/artifacts/themes/atlassian-dark-increased-contrast.js +21 -1
- package/dist/es2019/artifacts/themes/atlassian-dark.js +21 -1
- package/dist/es2019/artifacts/themes/atlassian-light-increased-contrast.js +21 -1
- package/dist/es2019/artifacts/themes/atlassian-light.js +21 -1
- package/dist/es2019/artifacts/token-default-values.js +21 -1
- package/dist/es2019/artifacts/token-names.js +21 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +471 -31
- package/dist/es2019/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +471 -31
- package/dist/es2019/entry-points/theme-state-transformer.js +2 -1
- package/dist/es2019/entry-points/token-metadata.codegen.js +196 -16
- package/dist/es2019/get-custom-theme-styles.js +3 -2
- package/dist/es2019/get-global-theme.js +1 -1
- package/dist/es2019/get-theme-html-attrs.js +1 -1
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/is-color-mode.js +3 -0
- package/dist/es2019/is-theme-ids.js +4 -0
- package/dist/es2019/is-theme-kind.js +4 -0
- package/dist/es2019/theme-config.js +4 -45
- package/dist/es2019/theme-object-to-string.js +28 -0
- package/dist/es2019/theme-options-schema.js +0 -0
- package/dist/es2019/theme-state-defaults.js +34 -0
- package/dist/es2019/theme-state.js +1 -0
- package/dist/es2019/theme-string-to-object.js +38 -0
- package/dist/es2019/utils/additional-contrast-checker.js +39 -0
- package/dist/es2019/utils/custom-theme-loading-utils.js +1 -11
- package/dist/es2019/utils/custom-theme-token-contrast-check.js +1 -41
- package/dist/es2019/utils/delta-e.js +20 -0
- package/dist/es2019/utils/generate-colors.js +39 -0
- package/dist/es2019/utils/generate-token-map-with-contrast-check.js +21 -0
- package/dist/es2019/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -63
- package/dist/es2019/utils/get-closest-color-index.js +2 -1
- package/dist/es2019/utils/get-contrast-ratio.js +16 -0
- package/dist/es2019/utils/hct-color-utils/alpha-from-argb.js +6 -0
- package/dist/es2019/utils/hct-color-utils/argb-from-linrgb.js +12 -0
- package/dist/es2019/utils/hct-color-utils/argb-from-lstar.js +16 -0
- package/dist/es2019/utils/hct-color-utils/argb-from-rgba.js +19 -0
- package/dist/es2019/utils/hct-color-utils/argb-from-xyz.js +24 -0
- package/dist/es2019/utils/hct-color-utils/blue-from-argb.js +6 -0
- package/dist/es2019/utils/hct-color-utils/clamp-component.js +9 -0
- package/dist/es2019/utils/hct-color-utils/contrast.js +10 -10
- package/dist/es2019/utils/hct-color-utils/green-from-argb.js +6 -0
- package/dist/es2019/utils/hct-color-utils/hct.js +19 -12
- package/dist/es2019/utils/hct-color-utils/index.js +2 -1
- package/dist/es2019/utils/hct-color-utils/lab-f.js +9 -0
- package/dist/es2019/utils/hct-color-utils/lab-invf.js +10 -0
- package/dist/es2019/utils/hct-color-utils/lstar-from-argb.js +28 -0
- package/dist/es2019/utils/hct-color-utils/lstar-from-y.js +16 -0
- package/dist/es2019/utils/hct-color-utils/red-from-argb.js +6 -0
- package/dist/es2019/utils/hct-color-utils/rgba-from-argb.js +22 -0
- package/dist/es2019/utils/hct-color-utils/rgba.js +0 -0
- package/dist/es2019/utils/hct-color-utils/viewing-conditions.js +4 -3
- package/dist/es2019/utils/hct-color-utils/white-point-d65.js +8 -0
- package/dist/es2019/utils/hct-color-utils/y-from-lstar.js +16 -0
- package/dist/es2019/utils/hex-to-hsl.js +46 -0
- package/dist/es2019/utils/hex-to-rgb-a.js +14 -0
- package/dist/es2019/utils/hex-to-rgb.js +13 -0
- package/dist/es2019/utils/is-valid-hex.js +2 -0
- package/dist/es2019/utils/reduce-token-map.js +7 -0
- package/dist/es2019/utils/rgb-to-lab.js +18 -0
- package/dist/esm/artifacts/generated-pairs.js +2 -2
- package/dist/esm/artifacts/palettes-raw/palette.js +35 -1
- package/dist/esm/artifacts/themes/atlassian-dark-increased-contrast.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light-increased-contrast.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +21 -1
- package/dist/esm/artifacts/token-names.js +21 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-dark-increased-contrast.js +471 -31
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +471 -31
- package/dist/esm/artifacts/tokens-raw/atlassian-light-increased-contrast.js +471 -31
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +471 -31
- package/dist/esm/entry-points/theme-state-transformer.js +2 -1
- package/dist/esm/entry-points/token-metadata.codegen.js +196 -16
- package/dist/esm/get-custom-theme-styles.js +3 -2
- package/dist/esm/get-global-theme.js +1 -1
- package/dist/esm/get-theme-html-attrs.js +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-color-mode.js +3 -0
- package/dist/esm/is-theme-ids.js +6 -0
- package/dist/esm/is-theme-kind.js +6 -0
- package/dist/esm/theme-config.js +4 -45
- package/dist/esm/theme-object-to-string.js +35 -0
- package/dist/esm/theme-options-schema.js +0 -0
- package/dist/esm/theme-state-defaults.js +34 -0
- package/dist/esm/theme-state.js +1 -0
- package/dist/esm/theme-string-to-object.js +44 -0
- package/dist/esm/utils/additional-contrast-checker.js +36 -0
- package/dist/esm/utils/custom-theme-loading-utils.js +1 -15
- package/dist/esm/utils/custom-theme-token-contrast-check.js +1 -38
- package/dist/esm/utils/delta-e.js +20 -0
- package/dist/esm/utils/generate-colors.js +40 -0
- package/dist/esm/utils/generate-token-map-with-contrast-check.js +25 -0
- package/dist/esm/utils/{generate-custom-color-ramp.js → generate-token-map.js} +3 -67
- package/dist/esm/utils/get-closest-color-index.js +2 -1
- package/dist/esm/utils/get-contrast-ratio.js +16 -0
- package/dist/esm/utils/hct-color-utils/alpha-from-argb.js +6 -0
- package/dist/esm/utils/hct-color-utils/argb-from-linrgb.js +12 -0
- package/dist/esm/utils/hct-color-utils/argb-from-lstar.js +16 -0
- package/dist/esm/utils/hct-color-utils/argb-from-rgba.js +18 -0
- package/dist/esm/utils/hct-color-utils/argb-from-xyz.js +24 -0
- package/dist/esm/utils/hct-color-utils/blue-from-argb.js +6 -0
- package/dist/esm/utils/hct-color-utils/clamp-component.js +9 -0
- package/dist/esm/utils/hct-color-utils/contrast.js +10 -10
- package/dist/esm/utils/hct-color-utils/green-from-argb.js +6 -0
- package/dist/esm/utils/hct-color-utils/hct.js +19 -12
- package/dist/esm/utils/hct-color-utils/index.js +2 -1
- package/dist/esm/utils/hct-color-utils/lab-f.js +9 -0
- package/dist/esm/utils/hct-color-utils/lab-invf.js +10 -0
- package/dist/esm/utils/hct-color-utils/lstar-from-argb.js +28 -0
- package/dist/esm/utils/hct-color-utils/lstar-from-y.js +16 -0
- package/dist/esm/utils/hct-color-utils/red-from-argb.js +6 -0
- package/dist/esm/utils/hct-color-utils/rgba-from-argb.js +22 -0
- package/dist/esm/utils/hct-color-utils/rgba.js +0 -0
- package/dist/esm/utils/hct-color-utils/viewing-conditions.js +5 -4
- package/dist/esm/utils/hct-color-utils/white-point-d65.js +8 -0
- package/dist/esm/utils/hct-color-utils/y-from-lstar.js +16 -0
- package/dist/esm/utils/hex-to-hsl.js +46 -0
- package/dist/esm/utils/hex-to-rgb-a.js +14 -0
- package/dist/esm/utils/hex-to-rgb.js +13 -0
- package/dist/esm/utils/is-valid-hex.js +4 -0
- package/dist/esm/utils/reduce-token-map.js +11 -0
- package/dist/esm/utils/rgb-to-lab.js +18 -0
- package/dist/types/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types/artifacts/palettes-raw/palette.d.ts +1 -1
- package/dist/types/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +21 -1
- package/dist/types/artifacts/token-names.d.ts +41 -1
- package/dist/types/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/entry-points/css-type-schema.codegen.d.ts +3 -3
- package/dist/types/entry-points/theme-state-transformer.d.ts +2 -1
- package/dist/types/entry-points/token-metadata.codegen.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/is-color-mode.d.ts +2 -0
- package/dist/types/is-theme-ids.d.ts +2 -0
- package/dist/types/is-theme-kind.d.ts +4 -0
- package/dist/types/theme-color-modes.d.ts +1 -0
- package/dist/types/theme-config.d.ts +8 -40
- package/dist/types/theme-ids.d.ts +1 -0
- package/dist/types/theme-object-to-string.d.ts +13 -0
- package/dist/types/theme-options-schema.d.ts +7 -0
- package/dist/types/theme-state-defaults.d.ts +14 -0
- package/dist/types/theme-state.d.ts +17 -0
- package/dist/types/{theme-state-transformer.d.ts → theme-string-to-object.d.ts} +0 -12
- package/dist/types/types.d.ts +75 -15
- package/dist/types/utils/additional-contrast-checker.d.ts +9 -0
- package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -6
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +0 -9
- package/dist/types/utils/delta-e.d.ts +1 -0
- package/dist/types/utils/generate-colors.d.ts +5 -0
- package/dist/types/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -6
- package/dist/types/utils/generate-token-map.d.ts +9 -0
- package/dist/types/utils/get-contrast-ratio.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
- package/dist/types/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
- package/dist/types/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/clamp-component.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/green-from-argb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/index.d.ts +2 -1
- package/dist/types/utils/hct-color-utils/lab-f.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/lab-invf.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
- package/dist/types/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
- package/dist/types/utils/hct-color-utils/red-from-argb.d.ts +4 -0
- package/dist/types/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
- package/dist/types/utils/hct-color-utils/rgba.d.ts +14 -0
- package/dist/types/utils/hct-color-utils/white-point-d65.d.ts +6 -0
- package/dist/types/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
- package/dist/types/utils/hex-to-hsl.d.ts +1 -0
- package/dist/types/utils/hex-to-rgb-a.d.ts +1 -0
- package/dist/types/utils/hex-to-rgb.d.ts +1 -0
- package/dist/types/utils/is-valid-hex.d.ts +1 -0
- package/dist/types/utils/reduce-token-map.d.ts +6 -0
- package/dist/types/utils/rgb-to-lab.d.ts +1 -0
- package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/palettes-raw/palette.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark-increased-contrast.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light-increased-contrast.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +21 -1
- package/dist/types-ts4.5/artifacts/token-names.d.ts +41 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-increased-contrast.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light-increased-contrast.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/css-type-schema.codegen.d.ts +3 -3
- package/dist/types-ts4.5/entry-points/theme-state-transformer.d.ts +2 -1
- package/dist/types-ts4.5/entry-points/token-metadata.codegen.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/is-color-mode.d.ts +2 -0
- package/dist/types-ts4.5/is-theme-ids.d.ts +2 -0
- package/dist/types-ts4.5/is-theme-kind.d.ts +11 -0
- package/dist/types-ts4.5/theme-color-modes.d.ts +1 -0
- package/dist/types-ts4.5/theme-config.d.ts +8 -40
- package/dist/types-ts4.5/theme-ids.d.ts +1 -0
- package/dist/types-ts4.5/theme-object-to-string.d.ts +13 -0
- package/dist/types-ts4.5/theme-options-schema.d.ts +7 -0
- package/dist/types-ts4.5/theme-state-defaults.d.ts +14 -0
- package/dist/types-ts4.5/theme-state.d.ts +17 -0
- package/dist/types-ts4.5/{theme-state-transformer.d.ts → theme-string-to-object.d.ts} +0 -12
- package/dist/types-ts4.5/types.d.ts +75 -15
- package/dist/types-ts4.5/utils/additional-contrast-checker.d.ts +9 -0
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -6
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +0 -9
- package/dist/types-ts4.5/utils/delta-e.d.ts +1 -0
- package/dist/types-ts4.5/utils/generate-colors.d.ts +5 -0
- package/dist/types-ts4.5/utils/{generate-custom-color-ramp.d.ts → generate-token-map-with-contrast-check.d.ts} +1 -8
- package/dist/types-ts4.5/utils/generate-token-map.d.ts +11 -0
- package/dist/types-ts4.5/utils/get-contrast-ratio.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/alpha-from-argb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/argb-from-linrgb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/argb-from-lstar.d.ts +8 -0
- package/dist/types-ts4.5/utils/hct-color-utils/argb-from-rgba.d.ts +8 -0
- package/dist/types-ts4.5/utils/hct-color-utils/argb-from-xyz.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/blue-from-argb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/clamp-component.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/green-from-argb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +2 -1
- package/dist/types-ts4.5/utils/hct-color-utils/lab-f.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/lab-invf.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-argb.d.ts +7 -0
- package/dist/types-ts4.5/utils/hct-color-utils/lstar-from-y.d.ts +12 -0
- package/dist/types-ts4.5/utils/hct-color-utils/red-from-argb.d.ts +4 -0
- package/dist/types-ts4.5/utils/hct-color-utils/rgba-from-argb.d.ts +8 -0
- package/dist/types-ts4.5/utils/hct-color-utils/rgba.d.ts +14 -0
- package/dist/types-ts4.5/utils/hct-color-utils/white-point-d65.d.ts +6 -0
- package/dist/types-ts4.5/utils/hct-color-utils/y-from-lstar.d.ts +12 -0
- package/dist/types-ts4.5/utils/hex-to-hsl.d.ts +5 -0
- package/dist/types-ts4.5/utils/hex-to-rgb-a.d.ts +6 -0
- package/dist/types-ts4.5/utils/hex-to-rgb.d.ts +5 -0
- package/dist/types-ts4.5/utils/is-valid-hex.d.ts +1 -0
- package/dist/types-ts4.5/utils/reduce-token-map.d.ts +6 -0
- package/dist/types-ts4.5/utils/rgb-to-lab.d.ts +5 -0
- package/figma/atlassian-dark-increased-contrast.json +180 -0
- package/figma/atlassian-dark.json +180 -0
- package/figma/atlassian-light-increased-contrast.json +180 -0
- package/figma/atlassian-light.json +180 -0
- package/package.json +7 -7
- package/dist/cjs/theme-state-transformer.js +0 -93
- package/dist/cjs/utils/color-utils.js +0 -176
- package/dist/cjs/utils/hct-color-utils/color-utils.js +0 -279
- package/dist/es2019/theme-state-transformer.js +0 -70
- package/dist/es2019/utils/color-utils.js +0 -136
- package/dist/es2019/utils/hct-color-utils/color-utils.js +0 -249
- package/dist/esm/theme-state-transformer.js +0 -86
- package/dist/esm/utils/color-utils.js +0 -138
- package/dist/esm/utils/hct-color-utils/color-utils.js +0 -248
- package/dist/types/utils/color-utils.d.ts +0 -10
- package/dist/types/utils/hct-color-utils/color-utils.d.ts +0 -88
- package/dist/types-ts4.5/utils/color-utils.d.ts +0 -23
- 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 {
|
|
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 {
|
|
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
|
|
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,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
|
+
}
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
//
|
|
27
27
|
// tslint:disable:class-as-namespace
|
|
28
28
|
|
|
29
|
-
import
|
|
30
|
-
import
|
|
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 =
|
|
53
|
-
toneB =
|
|
54
|
-
return Contrast.ratioOfYs(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
117
|
+
const returnValue = lstarFromY(darkY) - 0.4;
|
|
118
118
|
if (returnValue < 0 || returnValue > 100) {
|
|
119
119
|
return -1;
|
|
120
120
|
}
|
|
@@ -21,9 +21,16 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
21
21
|
* limitations under the License.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import
|
|
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 =
|
|
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 =
|
|
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,
|
|
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 =
|
|
247
|
-
const greenL =
|
|
248
|
-
const blueL =
|
|
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 =
|
|
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
|
|
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
|
|
834
|
+
return argbFromLstar(lstar);
|
|
828
835
|
}
|
|
829
836
|
hueDegrees = math.sanitizeDegreesDouble(hueDegrees);
|
|
830
837
|
const hueRadians = hueDegrees / 180 * Math.PI;
|
|
831
|
-
const y =
|
|
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
|
|
844
|
+
return argbFromLinrgb(linrgb);
|
|
838
845
|
}
|
|
839
846
|
|
|
840
847
|
/**
|
|
@@ -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
|
+
}
|