@oxyhq/bloom 0.35.8 → 0.37.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/lib/commonjs/frosted-icon-button/FrostedIconButton.js +148 -0
- package/lib/commonjs/frosted-icon-button/FrostedIconButton.js.map +1 -0
- package/lib/commonjs/frosted-icon-button/FrostedIconButton.web.js +166 -0
- package/lib/commonjs/frosted-icon-button/FrostedIconButton.web.js.map +1 -0
- package/lib/commonjs/frosted-icon-button/index.js +13 -0
- package/lib/commonjs/frosted-icon-button/index.js.map +1 -0
- package/lib/commonjs/frosted-icon-button/index.web.js +13 -0
- package/lib/commonjs/frosted-icon-button/index.web.js.map +1 -0
- package/lib/commonjs/frosted-icon-button/shared.js +112 -0
- package/lib/commonjs/frosted-icon-button/shared.js.map +1 -0
- package/lib/commonjs/frosted-icon-button/types.js +6 -0
- package/lib/commonjs/frosted-icon-button/types.js.map +1 -0
- package/lib/commonjs/index.js +10 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +46 -37
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/theme/build-theme.js +31 -43
- package/lib/commonjs/theme/build-theme.js.map +1 -1
- package/lib/commonjs/theme/color-engine/cam16.js +161 -0
- package/lib/commonjs/theme/color-engine/cam16.js.map +1 -0
- package/lib/commonjs/theme/color-engine/color-role.js +183 -0
- package/lib/commonjs/theme/color-engine/color-role.js.map +1 -0
- package/lib/commonjs/theme/color-engine/color-roles.js +416 -0
- package/lib/commonjs/theme/color-engine/color-roles.js.map +1 -0
- package/lib/commonjs/theme/color-engine/color-utils.js +157 -0
- package/lib/commonjs/theme/color-engine/color-utils.js.map +1 -0
- package/lib/commonjs/theme/color-engine/contrast-curve.js +32 -0
- package/lib/commonjs/theme/color-engine/contrast-curve.js.map +1 -0
- package/lib/commonjs/theme/color-engine/contrast.js +70 -0
- package/lib/commonjs/theme/color-engine/contrast.js.map +1 -0
- package/lib/commonjs/theme/color-engine/dislike-analyzer.js +26 -0
- package/lib/commonjs/theme/color-engine/dislike-analyzer.js.map +1 -0
- package/lib/commonjs/theme/color-engine/dynamic-scheme.js +70 -0
- package/lib/commonjs/theme/color-engine/dynamic-scheme.js.map +1 -0
- package/lib/commonjs/theme/color-engine/hct-solver.js +236 -0
- package/lib/commonjs/theme/color-engine/hct-solver.js.map +1 -0
- package/lib/commonjs/theme/color-engine/hct.js +67 -0
- package/lib/commonjs/theme/color-engine/hct.js.map +1 -0
- package/lib/commonjs/theme/color-engine/index.js +173 -0
- package/lib/commonjs/theme/color-engine/index.js.map +1 -0
- package/lib/commonjs/theme/color-engine/lab-point-provider.js +32 -0
- package/lib/commonjs/theme/color-engine/lab-point-provider.js.map +1 -0
- package/lib/commonjs/theme/color-engine/math-utils.js +77 -0
- package/lib/commonjs/theme/color-engine/math-utils.js.map +1 -0
- package/lib/commonjs/theme/color-engine/quantizer-map.js +24 -0
- package/lib/commonjs/theme/color-engine/quantizer-map.js.map +1 -0
- package/lib/commonjs/theme/color-engine/quantizer-wu.js +266 -0
- package/lib/commonjs/theme/color-engine/quantizer-wu.js.map +1 -0
- package/lib/commonjs/theme/color-engine/scheme-variants.js +102 -0
- package/lib/commonjs/theme/color-engine/scheme-variants.js.map +1 -0
- package/lib/commonjs/theme/color-engine/score.js +80 -0
- package/lib/commonjs/theme/color-engine/score.js.map +1 -0
- package/lib/commonjs/theme/color-engine/seed-from-image.js +73 -0
- package/lib/commonjs/theme/color-engine/seed-from-image.js.map +1 -0
- package/lib/commonjs/theme/color-engine/tonal-palette.js +95 -0
- package/lib/commonjs/theme/color-engine/tonal-palette.js.map +1 -0
- package/lib/commonjs/theme/color-engine/tone-delta-pair.js +26 -0
- package/lib/commonjs/theme/color-engine/tone-delta-pair.js.map +1 -0
- package/lib/commonjs/theme/color-engine/variant.js +26 -0
- package/lib/commonjs/theme/color-engine/variant.js.map +1 -0
- package/lib/commonjs/theme/color-engine/viewing-conditions.js +61 -0
- package/lib/commonjs/theme/color-engine/viewing-conditions.js.map +1 -0
- package/lib/commonjs/theme/color-presets.js +44 -572
- package/lib/commonjs/theme/color-presets.js.map +1 -1
- package/lib/commonjs/theme/preset-vars.js +64 -47
- package/lib/commonjs/theme/preset-vars.js.map +1 -1
- package/lib/module/frosted-icon-button/FrostedIconButton.js +143 -0
- package/lib/module/frosted-icon-button/FrostedIconButton.js.map +1 -0
- package/lib/module/frosted-icon-button/FrostedIconButton.web.js +161 -0
- package/lib/module/frosted-icon-button/FrostedIconButton.web.js.map +1 -0
- package/lib/module/frosted-icon-button/index.js +4 -0
- package/lib/module/frosted-icon-button/index.js.map +1 -0
- package/lib/module/frosted-icon-button/index.web.js +11 -0
- package/lib/module/frosted-icon-button/index.web.js.map +1 -0
- package/lib/module/frosted-icon-button/shared.js +107 -0
- package/lib/module/frosted-icon-button/shared.js.map +1 -0
- package/lib/module/frosted-icon-button/types.js +4 -0
- package/lib/module/frosted-icon-button/types.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +1 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/theme/build-theme.js +32 -44
- package/lib/module/theme/build-theme.js.map +1 -1
- package/lib/module/theme/color-engine/cam16.js +155 -0
- package/lib/module/theme/color-engine/cam16.js.map +1 -0
- package/lib/module/theme/color-engine/color-role.js +177 -0
- package/lib/module/theme/color-engine/color-role.js.map +1 -0
- package/lib/module/theme/color-engine/color-roles.js +411 -0
- package/lib/module/theme/color-engine/color-roles.js.map +1 -0
- package/lib/module/theme/color-engine/color-utils.js +135 -0
- package/lib/module/theme/color-engine/color-utils.js.map +1 -0
- package/lib/module/theme/color-engine/contrast-curve.js +26 -0
- package/lib/module/theme/color-engine/contrast-curve.js.map +1 -0
- package/lib/module/theme/color-engine/contrast.js +61 -0
- package/lib/module/theme/color-engine/contrast.js.map +1 -0
- package/lib/module/theme/color-engine/dislike-analyzer.js +20 -0
- package/lib/module/theme/color-engine/dislike-analyzer.js.map +1 -0
- package/lib/module/theme/color-engine/dynamic-scheme.js +65 -0
- package/lib/module/theme/color-engine/dynamic-scheme.js.map +1 -0
- package/lib/module/theme/color-engine/hct-solver.js +231 -0
- package/lib/module/theme/color-engine/hct-solver.js.map +1 -0
- package/lib/module/theme/color-engine/hct.js +61 -0
- package/lib/module/theme/color-engine/hct.js.map +1 -0
- package/lib/module/theme/color-engine/index.js +57 -0
- package/lib/module/theme/color-engine/index.js.map +1 -0
- package/lib/module/theme/color-engine/lab-point-provider.js +25 -0
- package/lib/module/theme/color-engine/lab-point-provider.js.map +1 -0
- package/lib/module/theme/color-engine/math-utils.js +65 -0
- package/lib/module/theme/color-engine/math-utils.js.map +1 -0
- package/lib/module/theme/color-engine/quantizer-map.js +20 -0
- package/lib/module/theme/color-engine/quantizer-map.js.map +1 -0
- package/lib/module/theme/color-engine/quantizer-wu.js +261 -0
- package/lib/module/theme/color-engine/quantizer-wu.js.map +1 -0
- package/lib/module/theme/color-engine/scheme-variants.js +93 -0
- package/lib/module/theme/color-engine/scheme-variants.js.map +1 -0
- package/lib/module/theme/color-engine/score.js +75 -0
- package/lib/module/theme/color-engine/score.js.map +1 -0
- package/lib/module/theme/color-engine/seed-from-image.js +67 -0
- package/lib/module/theme/color-engine/seed-from-image.js.map +1 -0
- package/lib/module/theme/color-engine/tonal-palette.js +89 -0
- package/lib/module/theme/color-engine/tonal-palette.js.map +1 -0
- package/lib/module/theme/color-engine/tone-delta-pair.js +21 -0
- package/lib/module/theme/color-engine/tone-delta-pair.js.map +1 -0
- package/lib/module/theme/color-engine/variant.js +22 -0
- package/lib/module/theme/color-engine/variant.js.map +1 -0
- package/lib/module/theme/color-engine/viewing-conditions.js +55 -0
- package/lib/module/theme/color-engine/viewing-conditions.js.map +1 -0
- package/lib/module/theme/color-presets.js +44 -572
- package/lib/module/theme/color-presets.js.map +1 -1
- package/lib/module/theme/preset-vars.js +64 -46
- package/lib/module/theme/preset-vars.js.map +1 -1
- package/lib/typescript/commonjs/frosted-icon-button/FrostedIconButton.d.ts +5 -0
- package/lib/typescript/commonjs/frosted-icon-button/FrostedIconButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/frosted-icon-button/FrostedIconButton.web.d.ts +5 -0
- package/lib/typescript/commonjs/frosted-icon-button/FrostedIconButton.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/frosted-icon-button/index.d.ts +3 -0
- package/lib/typescript/commonjs/frosted-icon-button/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/frosted-icon-button/index.web.d.ts +3 -0
- package/lib/typescript/commonjs/frosted-icon-button/index.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/frosted-icon-button/shared.d.ts +60 -0
- package/lib/typescript/commonjs/frosted-icon-button/shared.d.ts.map +1 -0
- package/lib/typescript/commonjs/frosted-icon-button/types.d.ts +69 -0
- package/lib/typescript/commonjs/frosted-icon-button/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +2 -0
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/build-theme.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-engine/cam16.d.ts +26 -0
- package/lib/typescript/commonjs/theme/color-engine/cam16.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/color-role.d.ts +36 -0
- package/lib/typescript/commonjs/theme/color-engine/color-role.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/color-roles.d.ts +58 -0
- package/lib/typescript/commonjs/theme/color-engine/color-roles.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/color-utils.d.ts +32 -0
- package/lib/typescript/commonjs/theme/color-engine/color-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/contrast-curve.d.ts +9 -0
- package/lib/typescript/commonjs/theme/color-engine/contrast-curve.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/contrast.d.ts +12 -0
- package/lib/typescript/commonjs/theme/color-engine/contrast.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/dislike-analyzer.d.ts +11 -0
- package/lib/typescript/commonjs/theme/color-engine/dislike-analyzer.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/dynamic-scheme.d.ts +47 -0
- package/lib/typescript/commonjs/theme/color-engine/dynamic-scheme.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/hct-solver.d.ts +6 -0
- package/lib/typescript/commonjs/theme/color-engine/hct-solver.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/hct.d.ts +20 -0
- package/lib/typescript/commonjs/theme/color-engine/hct.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/index.d.ts +44 -0
- package/lib/typescript/commonjs/theme/color-engine/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/lab-point-provider.d.ts +6 -0
- package/lib/typescript/commonjs/theme/color-engine/lab-point-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/math-utils.d.ts +46 -0
- package/lib/typescript/commonjs/theme/color-engine/math-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/quantizer-map.d.ts +3 -0
- package/lib/typescript/commonjs/theme/color-engine/quantizer-map.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/quantizer-wu.d.ts +3 -0
- package/lib/typescript/commonjs/theme/color-engine/quantizer-wu.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/scheme-variants.d.ts +23 -0
- package/lib/typescript/commonjs/theme/color-engine/scheme-variants.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/score.d.ts +8 -0
- package/lib/typescript/commonjs/theme/color-engine/score.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/seed-from-image.d.ts +13 -0
- package/lib/typescript/commonjs/theme/color-engine/seed-from-image.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/tonal-palette.d.ts +24 -0
- package/lib/typescript/commonjs/theme/color-engine/tonal-palette.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/tone-delta-pair.d.ts +19 -0
- package/lib/typescript/commonjs/theme/color-engine/tone-delta-pair.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/variant.d.ts +19 -0
- package/lib/typescript/commonjs/theme/color-engine/variant.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-engine/viewing-conditions.d.ts +18 -0
- package/lib/typescript/commonjs/theme/color-engine/viewing-conditions.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-presets.d.ts +25 -20
- package/lib/typescript/commonjs/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/preset-vars.d.ts +16 -12
- package/lib/typescript/commonjs/theme/preset-vars.d.ts.map +1 -1
- package/lib/typescript/module/frosted-icon-button/FrostedIconButton.d.ts +5 -0
- package/lib/typescript/module/frosted-icon-button/FrostedIconButton.d.ts.map +1 -0
- package/lib/typescript/module/frosted-icon-button/FrostedIconButton.web.d.ts +5 -0
- package/lib/typescript/module/frosted-icon-button/FrostedIconButton.web.d.ts.map +1 -0
- package/lib/typescript/module/frosted-icon-button/index.d.ts +3 -0
- package/lib/typescript/module/frosted-icon-button/index.d.ts.map +1 -0
- package/lib/typescript/module/frosted-icon-button/index.web.d.ts +3 -0
- package/lib/typescript/module/frosted-icon-button/index.web.d.ts.map +1 -0
- package/lib/typescript/module/frosted-icon-button/shared.d.ts +60 -0
- package/lib/typescript/module/frosted-icon-button/shared.d.ts.map +1 -0
- package/lib/typescript/module/frosted-icon-button/types.d.ts +69 -0
- package/lib/typescript/module/frosted-icon-button/types.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +2 -0
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/theme/build-theme.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-engine/cam16.d.ts +26 -0
- package/lib/typescript/module/theme/color-engine/cam16.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/color-role.d.ts +36 -0
- package/lib/typescript/module/theme/color-engine/color-role.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/color-roles.d.ts +58 -0
- package/lib/typescript/module/theme/color-engine/color-roles.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/color-utils.d.ts +32 -0
- package/lib/typescript/module/theme/color-engine/color-utils.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/contrast-curve.d.ts +9 -0
- package/lib/typescript/module/theme/color-engine/contrast-curve.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/contrast.d.ts +12 -0
- package/lib/typescript/module/theme/color-engine/contrast.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/dislike-analyzer.d.ts +11 -0
- package/lib/typescript/module/theme/color-engine/dislike-analyzer.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/dynamic-scheme.d.ts +47 -0
- package/lib/typescript/module/theme/color-engine/dynamic-scheme.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/hct-solver.d.ts +6 -0
- package/lib/typescript/module/theme/color-engine/hct-solver.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/hct.d.ts +20 -0
- package/lib/typescript/module/theme/color-engine/hct.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/index.d.ts +44 -0
- package/lib/typescript/module/theme/color-engine/index.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/lab-point-provider.d.ts +6 -0
- package/lib/typescript/module/theme/color-engine/lab-point-provider.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/math-utils.d.ts +46 -0
- package/lib/typescript/module/theme/color-engine/math-utils.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/quantizer-map.d.ts +3 -0
- package/lib/typescript/module/theme/color-engine/quantizer-map.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/quantizer-wu.d.ts +3 -0
- package/lib/typescript/module/theme/color-engine/quantizer-wu.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/scheme-variants.d.ts +23 -0
- package/lib/typescript/module/theme/color-engine/scheme-variants.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/score.d.ts +8 -0
- package/lib/typescript/module/theme/color-engine/score.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/seed-from-image.d.ts +13 -0
- package/lib/typescript/module/theme/color-engine/seed-from-image.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/tonal-palette.d.ts +24 -0
- package/lib/typescript/module/theme/color-engine/tonal-palette.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/tone-delta-pair.d.ts +19 -0
- package/lib/typescript/module/theme/color-engine/tone-delta-pair.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/variant.d.ts +19 -0
- package/lib/typescript/module/theme/color-engine/variant.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-engine/viewing-conditions.d.ts +18 -0
- package/lib/typescript/module/theme/color-engine/viewing-conditions.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-presets.d.ts +25 -20
- package/lib/typescript/module/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/module/theme/preset-vars.d.ts +16 -12
- package/lib/typescript/module/theme/preset-vars.d.ts.map +1 -1
- package/package.json +17 -1
- package/src/__tests__/BloomThemeProvider.test.tsx +9 -4
- package/src/__tests__/FrostedIconButton.test.tsx +137 -0
- package/src/__tests__/FrostedIconButton.web.test.tsx +246 -0
- package/src/__tests__/native-root-vars.test.ts +8 -4
- package/src/__tests__/preset-vars.test.ts +66 -37
- package/src/__tests__/theme.test.ts +20 -12
- package/src/frosted-icon-button/FrostedIconButton.stories.tsx +65 -0
- package/src/frosted-icon-button/FrostedIconButton.tsx +156 -0
- package/src/frosted-icon-button/FrostedIconButton.web.tsx +207 -0
- package/src/frosted-icon-button/index.ts +2 -0
- package/src/frosted-icon-button/index.web.ts +9 -0
- package/src/frosted-icon-button/shared.ts +118 -0
- package/src/frosted-icon-button/types.ts +81 -0
- package/src/index.ts +2 -0
- package/src/index.web.ts +2 -0
- package/src/theme/__tests__/__fixtures__/golden-resolved-tokens.json +509 -509
- package/src/theme/__tests__/__snapshots__/visual-gallery.test.tsx.snap +613 -613
- package/src/theme/__tests__/color-engine-golden.test.ts +81 -0
- package/src/theme/__tests__/fixtures/color-engine-golden.json +1 -0
- package/src/theme/__tests__/golden-tokens.test.ts +6 -7
- package/src/theme/__tests__/runtime-contract.test.ts +8 -8
- package/src/theme/__tests__/theme-colors-parity.test.ts +44 -88
- package/src/theme/build-theme.ts +32 -44
- package/src/theme/color-engine/cam16.ts +179 -0
- package/src/theme/color-engine/color-role.ts +217 -0
- package/src/theme/color-engine/color-roles.ts +435 -0
- package/src/theme/color-engine/color-utils.ts +157 -0
- package/src/theme/color-engine/contrast-curve.ts +25 -0
- package/src/theme/color-engine/contrast.ts +59 -0
- package/src/theme/color-engine/dislike-analyzer.ts +19 -0
- package/src/theme/color-engine/dynamic-scheme.ts +90 -0
- package/src/theme/color-engine/hct-solver.ts +263 -0
- package/src/theme/color-engine/hct.ts +69 -0
- package/src/theme/color-engine/index.ts +73 -0
- package/src/theme/color-engine/lab-point-provider.ts +26 -0
- package/src/theme/color-engine/math-utils.ts +69 -0
- package/src/theme/color-engine/quantizer-map.ts +17 -0
- package/src/theme/color-engine/quantizer-wu.ts +320 -0
- package/src/theme/color-engine/scheme-variants.ts +113 -0
- package/src/theme/color-engine/score.ts +82 -0
- package/src/theme/color-engine/seed-from-image.ts +64 -0
- package/src/theme/color-engine/tonal-palette.ts +94 -0
- package/src/theme/color-engine/tone-delta-pair.ts +21 -0
- package/src/theme/color-engine/variant.ts +18 -0
- package/src/theme/color-engine/viewing-conditions.ts +77 -0
- package/src/theme/color-presets.ts +54 -631
- package/src/theme/preset-vars.ts +65 -49
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.alphaFromArgb = alphaFromArgb;
|
|
7
|
+
exports.argbFromLab = argbFromLab;
|
|
8
|
+
exports.argbFromLinrgb = argbFromLinrgb;
|
|
9
|
+
exports.argbFromLstar = argbFromLstar;
|
|
10
|
+
exports.argbFromRgb = argbFromRgb;
|
|
11
|
+
exports.argbFromXyz = argbFromXyz;
|
|
12
|
+
exports.blueFromArgb = blueFromArgb;
|
|
13
|
+
exports.delinearized = delinearized;
|
|
14
|
+
exports.greenFromArgb = greenFromArgb;
|
|
15
|
+
exports.isOpaque = isOpaque;
|
|
16
|
+
exports.labFromArgb = labFromArgb;
|
|
17
|
+
exports.linearized = linearized;
|
|
18
|
+
exports.lstarFromArgb = lstarFromArgb;
|
|
19
|
+
exports.lstarFromY = lstarFromY;
|
|
20
|
+
exports.redFromArgb = redFromArgb;
|
|
21
|
+
exports.whitePointD65 = whitePointD65;
|
|
22
|
+
exports.xyzFromArgb = xyzFromArgb;
|
|
23
|
+
exports.yFromLstar = yFromLstar;
|
|
24
|
+
var _mathUtils = require("./math-utils.js");
|
|
25
|
+
/**
|
|
26
|
+
* Bloom colour engine — colour-science conversions (non-HCT).
|
|
27
|
+
*
|
|
28
|
+
* ARGB ⇄ XYZ ⇄ L*a*b*, sRGB (de)linearisation, and L*↔Y. Self-contained port of
|
|
29
|
+
* Material Color Utilities' `color_utils` (Apache-2.0) into Bloom's own code —
|
|
30
|
+
* no external colour dependency. Verified byte-for-byte by golden tests.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const SRGB_TO_XYZ = [[0.41233895, 0.35762064, 0.18051042], [0.2126, 0.7152, 0.0722], [0.01932141, 0.11916382, 0.95034478]];
|
|
34
|
+
const XYZ_TO_SRGB = [[3.2413774792388685, -1.5376652402851851, -0.49885366846268053], [-0.9691452513005321, 1.8758853451067872, 0.04156585616912061], [0.05562093689691305, -0.20395524564742123, 1.0571799111220335]];
|
|
35
|
+
const WHITE_POINT_D65 = [95.047, 100.0, 108.883];
|
|
36
|
+
|
|
37
|
+
/** Pack 0–255 R/G/B into an opaque ARGB int. */
|
|
38
|
+
function argbFromRgb(red, green, blue) {
|
|
39
|
+
return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Pack linear-RGB (0–100 per channel) into an opaque ARGB int. */
|
|
43
|
+
function argbFromLinrgb(linrgb) {
|
|
44
|
+
return argbFromRgb(delinearized(linrgb[0]), delinearized(linrgb[1]), delinearized(linrgb[2]));
|
|
45
|
+
}
|
|
46
|
+
function alphaFromArgb(argb) {
|
|
47
|
+
return argb >> 24 & 255;
|
|
48
|
+
}
|
|
49
|
+
function redFromArgb(argb) {
|
|
50
|
+
return argb >> 16 & 255;
|
|
51
|
+
}
|
|
52
|
+
function greenFromArgb(argb) {
|
|
53
|
+
return argb >> 8 & 255;
|
|
54
|
+
}
|
|
55
|
+
function blueFromArgb(argb) {
|
|
56
|
+
return argb & 255;
|
|
57
|
+
}
|
|
58
|
+
function isOpaque(argb) {
|
|
59
|
+
return alphaFromArgb(argb) >= 255;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** XYZ → ARGB. */
|
|
63
|
+
function argbFromXyz(x, y, z) {
|
|
64
|
+
const m = XYZ_TO_SRGB;
|
|
65
|
+
const linearR = m[0][0] * x + m[0][1] * y + m[0][2] * z;
|
|
66
|
+
const linearG = m[1][0] * x + m[1][1] * y + m[1][2] * z;
|
|
67
|
+
const linearB = m[2][0] * x + m[2][1] * y + m[2][2] * z;
|
|
68
|
+
return argbFromRgb(delinearized(linearR), delinearized(linearG), delinearized(linearB));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** ARGB → XYZ. */
|
|
72
|
+
function xyzFromArgb(argb) {
|
|
73
|
+
const r = linearized(redFromArgb(argb));
|
|
74
|
+
const g = linearized(greenFromArgb(argb));
|
|
75
|
+
const b = linearized(blueFromArgb(argb));
|
|
76
|
+
return (0, _mathUtils.matrixMultiply)([r, g, b], SRGB_TO_XYZ);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** L*a*b* → ARGB. */
|
|
80
|
+
function argbFromLab(l, a, b) {
|
|
81
|
+
const wp = WHITE_POINT_D65;
|
|
82
|
+
const fy = (l + 16.0) / 116.0;
|
|
83
|
+
const fx = a / 500.0 + fy;
|
|
84
|
+
const fz = fy - b / 200.0;
|
|
85
|
+
const x = labInvf(fx) * wp[0];
|
|
86
|
+
const y = labInvf(fy) * wp[1];
|
|
87
|
+
const z = labInvf(fz) * wp[2];
|
|
88
|
+
return argbFromXyz(x, y, z);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** ARGB → L*a*b*. */
|
|
92
|
+
function labFromArgb(argb) {
|
|
93
|
+
const linearR = linearized(redFromArgb(argb));
|
|
94
|
+
const linearG = linearized(greenFromArgb(argb));
|
|
95
|
+
const linearB = linearized(blueFromArgb(argb));
|
|
96
|
+
const m = SRGB_TO_XYZ;
|
|
97
|
+
const x = m[0][0] * linearR + m[0][1] * linearG + m[0][2] * linearB;
|
|
98
|
+
const y = m[1][0] * linearR + m[1][1] * linearG + m[1][2] * linearB;
|
|
99
|
+
const z = m[2][0] * linearR + m[2][1] * linearG + m[2][2] * linearB;
|
|
100
|
+
const wp = WHITE_POINT_D65;
|
|
101
|
+
const fx = labF(x / wp[0]);
|
|
102
|
+
const fy = labF(y / wp[1]);
|
|
103
|
+
const fz = labF(z / wp[2]);
|
|
104
|
+
return [116.0 * fy - 16, 500.0 * (fx - fy), 200.0 * (fy - fz)];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** L* → ARGB (a grayscale color with that lightness). */
|
|
108
|
+
function argbFromLstar(lstar) {
|
|
109
|
+
const component = delinearized(yFromLstar(lstar));
|
|
110
|
+
return argbFromRgb(component, component, component);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** ARGB → L*. */
|
|
114
|
+
function lstarFromArgb(argb) {
|
|
115
|
+
const y = xyzFromArgb(argb)[1];
|
|
116
|
+
return 116.0 * labF(y / 100.0) - 16.0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** L* → Y (XYZ luminance). */
|
|
120
|
+
function yFromLstar(lstar) {
|
|
121
|
+
return 100.0 * labInvf((lstar + 16.0) / 116.0);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Y (XYZ luminance) → L*. */
|
|
125
|
+
function lstarFromY(y) {
|
|
126
|
+
return labF(y / 100.0) * 116.0 - 16.0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** sRGB component (0–255) → linear (0–100). */
|
|
130
|
+
function linearized(rgbComponent) {
|
|
131
|
+
const normalized = rgbComponent / 255.0;
|
|
132
|
+
return normalized <= 0.040449936 ? normalized / 12.92 * 100.0 : Math.pow((normalized + 0.055) / 1.055, 2.4) * 100.0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Linear component (0–100) → sRGB (0–255). */
|
|
136
|
+
function delinearized(rgbComponent) {
|
|
137
|
+
const normalized = rgbComponent / 100.0;
|
|
138
|
+
const delin = normalized <= 0.0031308 ? normalized * 12.92 : 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;
|
|
139
|
+
return (0, _mathUtils.clampInt)(0, 255, Math.round(delin * 255.0));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The D65 white point. */
|
|
143
|
+
function whitePointD65() {
|
|
144
|
+
return WHITE_POINT_D65;
|
|
145
|
+
}
|
|
146
|
+
function labF(t) {
|
|
147
|
+
const e = 216.0 / 24389.0;
|
|
148
|
+
const kappa = 24389.0 / 27.0;
|
|
149
|
+
return t > e ? Math.pow(t, 1.0 / 3.0) : (kappa * t + 16) / 116;
|
|
150
|
+
}
|
|
151
|
+
function labInvf(ft) {
|
|
152
|
+
const e = 216.0 / 24389.0;
|
|
153
|
+
const kappa = 24389.0 / 27.0;
|
|
154
|
+
const ft3 = ft * ft * ft;
|
|
155
|
+
return ft3 > e ? ft3 : (116 * ft - 16) / kappa;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=color-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mathUtils","require","SRGB_TO_XYZ","XYZ_TO_SRGB","WHITE_POINT_D65","argbFromRgb","red","green","blue","argbFromLinrgb","linrgb","delinearized","alphaFromArgb","argb","redFromArgb","greenFromArgb","blueFromArgb","isOpaque","argbFromXyz","x","y","z","m","linearR","linearG","linearB","xyzFromArgb","r","linearized","g","b","matrixMultiply","argbFromLab","l","a","wp","fy","fx","fz","labInvf","labFromArgb","labF","argbFromLstar","lstar","component","yFromLstar","lstarFromArgb","lstarFromY","rgbComponent","normalized","Math","pow","delin","clampInt","round","whitePointD65","t","e","kappa","ft","ft3"],"sourceRoot":"../../../../src","sources":["theme/color-engine/color-utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,MAAMC,WAAoB,GAAG,CAC3B,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,EACpC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxB,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CACrC;AAED,MAAMC,WAAoB,GAAG,CAC3B,CAAC,kBAAkB,EAAE,CAAC,kBAAkB,EAAE,CAAC,mBAAmB,CAAC,EAC/D,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,EAC9D,CAAC,mBAAmB,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAChE;AAED,MAAMC,eAAyC,GAAG,CAAC,MAAM,EAAE,KAAK,EA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ContrastCurve = void 0;
|
|
7
|
+
var _mathUtils = require("./math-utils.js");
|
|
8
|
+
/**
|
|
9
|
+
* Bloom colour engine — contrast curve.
|
|
10
|
+
*
|
|
11
|
+
* Faithful port of Material Color Utilities' `ContrastCurve` (Apache-2.0). Maps
|
|
12
|
+
* a scheme's contrast level (−1 low … 0 normal … 1 high) to the target WCAG
|
|
13
|
+
* ratio a role should hit, interpolating between four control points.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class ContrastCurve {
|
|
17
|
+
constructor(low, normal, medium, high) {
|
|
18
|
+
this.low = low;
|
|
19
|
+
this.normal = normal;
|
|
20
|
+
this.medium = medium;
|
|
21
|
+
this.high = high;
|
|
22
|
+
}
|
|
23
|
+
get(contrastLevel) {
|
|
24
|
+
if (contrastLevel <= -1.0) return this.low;
|
|
25
|
+
if (contrastLevel < 0.0) return (0, _mathUtils.lerp)(this.low, this.normal, (contrastLevel - -1) / 1);
|
|
26
|
+
if (contrastLevel < 0.5) return (0, _mathUtils.lerp)(this.normal, this.medium, (contrastLevel - 0) / 0.5);
|
|
27
|
+
if (contrastLevel < 1.0) return (0, _mathUtils.lerp)(this.medium, this.high, (contrastLevel - 0.5) / 0.5);
|
|
28
|
+
return this.high;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ContrastCurve = ContrastCurve;
|
|
32
|
+
//# sourceMappingURL=contrast-curve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mathUtils","require","ContrastCurve","constructor","low","normal","medium","high","get","contrastLevel","lerp","exports"],"sourceRoot":"../../../../src","sources":["theme/color-engine/contrast-curve.ts"],"mappings":";;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGO,MAAMC,aAAa,CAAC;EACzBC,WAAWA,CACAC,GAAW,EACXC,MAAc,EACdC,MAAc,EACdC,IAAY,EACrB;IAAA,KAJSH,GAAW,GAAXA,GAAW;IAAA,KACXC,MAAc,GAAdA,MAAc;IAAA,KACdC,MAAc,GAAdA,MAAc;IAAA,KACdC,IAAY,GAAZA,IAAY;EACpB;EAEHC,GAAGA,CAACC,aAAqB,EAAU;IACjC,IAAIA,aAAa,IAAI,CAAC,GAAG,EAAE,OAAO,IAAI,CAACL,GAAG;IAC1C,IAAIK,aAAa,GAAG,GAAG,EAAE,OAAO,IAAAC,eAAI,EAAC,IAAI,CAACN,GAAG,EAAE,IAAI,CAACC,MAAM,EAAE,CAACI,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACrF,IAAIA,aAAa,GAAG,GAAG,EAAE,OAAO,IAAAC,eAAI,EAAC,IAAI,CAACL,MAAM,EAAE,IAAI,CAACC,MAAM,EAAE,CAACG,aAAa,GAAG,CAAC,IAAI,GAAG,CAAC;IACzF,IAAIA,aAAa,GAAG,GAAG,EAAE,OAAO,IAAAC,eAAI,EAAC,IAAI,CAACJ,MAAM,EAAE,IAAI,CAACC,IAAI,EAAE,CAACE,aAAa,GAAG,GAAG,IAAI,GAAG,CAAC;IACzF,OAAO,IAAI,CAACF,IAAI;EAClB;AACF;AAACI,OAAA,CAAAT,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.darker = darker;
|
|
7
|
+
exports.darkerUnsafe = darkerUnsafe;
|
|
8
|
+
exports.lighter = lighter;
|
|
9
|
+
exports.lighterUnsafe = lighterUnsafe;
|
|
10
|
+
exports.ratioOfTones = ratioOfTones;
|
|
11
|
+
exports.ratioOfYs = ratioOfYs;
|
|
12
|
+
var _mathUtils = require("./math-utils.js");
|
|
13
|
+
var _colorUtils = require("./color-utils.js");
|
|
14
|
+
/**
|
|
15
|
+
* Bloom colour engine — contrast in tone space.
|
|
16
|
+
*
|
|
17
|
+
* Faithful port of Material Color Utilities' `Contrast` (Apache-2.0). Because
|
|
18
|
+
* HCT tone maps to L*, contrast ratios can be computed and *targeted* directly
|
|
19
|
+
* in tone: given a tone and a desired WCAG ratio, find the lighter/darker tone
|
|
20
|
+
* that hits it. Drives every role's on-colour and container legibility.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** WCAG contrast ratio between two tones (L*). */
|
|
24
|
+
function ratioOfTones(toneA, toneB) {
|
|
25
|
+
toneA = (0, _mathUtils.clampDouble)(0.0, 100.0, toneA);
|
|
26
|
+
toneB = (0, _mathUtils.clampDouble)(0.0, 100.0, toneB);
|
|
27
|
+
return ratioOfYs((0, _colorUtils.yFromLstar)(toneA), (0, _colorUtils.yFromLstar)(toneB));
|
|
28
|
+
}
|
|
29
|
+
function ratioOfYs(y1, y2) {
|
|
30
|
+
const lighter = y1 > y2 ? y1 : y2;
|
|
31
|
+
const darker = lighter === y2 ? y1 : y2;
|
|
32
|
+
return (lighter + 5.0) / (darker + 5.0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Lightest tone that hits `ratio` against `tone`, or -1 if impossible. */
|
|
36
|
+
function lighter(tone, ratio) {
|
|
37
|
+
if (tone < 0.0 || tone > 100.0) return -1.0;
|
|
38
|
+
const darkY = (0, _colorUtils.yFromLstar)(tone);
|
|
39
|
+
const lightY = ratio * (darkY + 5.0) - 5.0;
|
|
40
|
+
const realContrast = ratioOfYs(lightY, darkY);
|
|
41
|
+
const delta = Math.abs(realContrast - ratio);
|
|
42
|
+
if (realContrast < ratio && delta > 0.04) return -1;
|
|
43
|
+
const returnValue = (0, _colorUtils.lstarFromY)(lightY) + 0.4;
|
|
44
|
+
return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Darkest tone that hits `ratio` against `tone`, or -1 if impossible. */
|
|
48
|
+
function darker(tone, ratio) {
|
|
49
|
+
if (tone < 0.0 || tone > 100.0) return -1.0;
|
|
50
|
+
const lightY = (0, _colorUtils.yFromLstar)(tone);
|
|
51
|
+
const darkY = (lightY + 5.0) / ratio - 5.0;
|
|
52
|
+
const realContrast = ratioOfYs(lightY, darkY);
|
|
53
|
+
const delta = Math.abs(realContrast - ratio);
|
|
54
|
+
if (realContrast < ratio && delta > 0.04) return -1;
|
|
55
|
+
const returnValue = (0, _colorUtils.lstarFromY)(darkY) - 0.4;
|
|
56
|
+
return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Like {@link lighter} but returns 100 instead of -1 when unattainable. */
|
|
60
|
+
function lighterUnsafe(tone, ratio) {
|
|
61
|
+
const lighterSafe = lighter(tone, ratio);
|
|
62
|
+
return lighterSafe < 0.0 ? 100.0 : lighterSafe;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Like {@link darker} but returns 0 instead of -1 when unattainable. */
|
|
66
|
+
function darkerUnsafe(tone, ratio) {
|
|
67
|
+
const darkerSafe = darker(tone, ratio);
|
|
68
|
+
return darkerSafe < 0.0 ? 0.0 : darkerSafe;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=contrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_mathUtils","require","_colorUtils","ratioOfTones","toneA","toneB","clampDouble","ratioOfYs","yFromLstar","y1","y2","lighter","darker","tone","ratio","darkY","lightY","realContrast","delta","Math","abs","returnValue","lstarFromY","lighterUnsafe","lighterSafe","darkerUnsafe","darkerSafe"],"sourceRoot":"../../../../src","sources":["theme/color-engine/contrast.ts"],"mappings":";;;;;;;;;;;AAQA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AATA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACO,SAASE,YAAYA,CAACC,KAAa,EAAEC,KAAa,EAAU;EACjED,KAAK,GAAG,IAAAE,sBAAW,EAAC,GAAG,EAAE,KA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,GAAG,KAAK,EAAE,OAAO,CAAC,GAAG;EAC3C,MAAMG,MAAM,GAAG,IAAAR,sBAAU,EAACK,IAAI,CAAC;EAC/B,MAAME,KAAK,GAAG,CAACC,MAAM,GAAG,GAAG,IAAIF,KAAK,GAAG,GAAG;EAC1C,MAAMG,YAAY,GAAGV,SAAS,CAACS,MAAM,EAAED,KAAK,CAAC;EAC7C,MAAMG,KAAK,GAAGC,IAAI,CAACC,GAAG,CAACH,YAAY,GAAGH,KAAK,CAAC;EAC5C,IAAIG,YAAY,GAAGH,KAAK,IAAII,KAAK,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;EACnD,MAAMG,WAAW,GAAG,IAAAC,sBAAU,EAACP,KAAK,CAAC,GAAG,GAAG;EAC3C,OAAOM,WAAW,GAAG,CAAC,IAAIA,WAAW,GAAG,GAAG,GAAG,CAAC,CAAC,GAAGA,WAAW;AAChE;;AAEA;AACO,SAASE,aAAaA,CAACV,IAAY,EAAEC,KAAa,EAAU;EACjE,MAAMU,WAAW,GAAGb,OAAO,CAACE,IAAI,EAAEC,KAAK,CAAC;EACxC,OAAOU,WAAW,GAAG,GAAG,GAAG,KAAK,GAAGA,WAAW;AAChD;;AAEA;AACO,SAASC,YAAYA,CAACZ,IAAY,EAAEC,KAAa,EAAU;EAChE,MAAMY,UAAU,GAAGd,MAAM,CAACC,IAAI,EAAEC,KAAK,CAAC;EACtC,OAAOY,UAAU,GAAG,GAAG,GAAG,GAAG,GAAGA,UAAU;AAC5C","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fixIfDisliked = fixIfDisliked;
|
|
7
|
+
exports.isDisliked = isDisliked;
|
|
8
|
+
var _hct = require("./hct.js");
|
|
9
|
+
/**
|
|
10
|
+
* Bloom colour engine — dislike analyzer.
|
|
11
|
+
*
|
|
12
|
+
* Faithful port of Material Color Utilities' `DislikeAnalyzer` (Apache-2.0).
|
|
13
|
+
* Certain dark-yellow-green HCT colours read as "bile"; this nudges their tone
|
|
14
|
+
* up to 70 so generated palettes never land on a universally-disliked colour.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function isDisliked(hct) {
|
|
18
|
+
const huePasses = Math.round(hct.hue) >= 90.0 && Math.round(hct.hue) <= 111.0;
|
|
19
|
+
const chromaPasses = Math.round(hct.chroma) > 16.0;
|
|
20
|
+
const tonePasses = Math.round(hct.tone) < 65.0;
|
|
21
|
+
return huePasses && chromaPasses && tonePasses;
|
|
22
|
+
}
|
|
23
|
+
function fixIfDisliked(hct) {
|
|
24
|
+
return isDisliked(hct) ? _hct.Hct.from(hct.hue, hct.chroma, 70.0) : hct;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=dislike-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_hct","require","isDisliked","hct","huePasses","Math","round","hue","chromaPasses","chroma","tonePasses","tone","fixIfDisliked","Hct","from"],"sourceRoot":"../../../../src","sources":["theme/color-engine/dislike-analyzer.ts"],"mappings":";;;;;;;AAOA,IAAAA,IAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGO,SAASC,UAAUA,CAACC,GAAQ,EAAW;EAC5C,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAACH,GAAG,CAACI,GAAG,CAAC,IAAI,IAAI,IAAIF,IAAI,CAACC,KAAK,CAACH,GAAG,CAACI,GAAG,CAAC,IAAI,KAAK;EAC7E,MAAMC,YAAY,GAAGH,IAAI,CAACC,KAAK,CAACH,GAAG,CAACM,MAAM,CAAC,GAAG,IAAI;EAClD,MAAMC,UAAU,GAAGL,IAAI,CAACC,KAAK,CAACH,GAAG,CAACQ,IAAI,CAAC,GAAG,IAAI;EAC9C,OAAOP,SAAS,IAAII,YAAY,IAAIE,UAAU;AAChD;AAEO,SAASE,aAAaA,CAACT,GAAQ,EAAO;EAC3C,OAAOD,UAAU,CAACC,GAAG,CAAC,GAAGU,QAAG,CAACC,IAAI,CAACX,GAAG,CAACI,GAAG,EAAEJ,GAAG,CAACM,MAAM,EAAE,IAAI,CAAC,GAAGN,GAAG;AACpE","ignoreList":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DynamicScheme = void 0;
|
|
7
|
+
var _hct = require("./hct.js");
|
|
8
|
+
var _mathUtils = require("./math-utils.js");
|
|
9
|
+
var _tonalPalette = require("./tonal-palette.js");
|
|
10
|
+
/**
|
|
11
|
+
* Bloom colour engine — dynamic scheme.
|
|
12
|
+
*
|
|
13
|
+
* Faithful port of Material Color Utilities' `DynamicScheme` core (Apache-2.0).
|
|
14
|
+
* Holds the five tonal palettes (primary/secondary/tertiary/neutral/
|
|
15
|
+
* neutralVariant) + error that a scheme variant derives from the seed, plus the
|
|
16
|
+
* dark/contrast state a `DynamicColor` role reads to resolve into an ARGB. The
|
|
17
|
+
* ~50 convenience role getters from the reference are omitted — Bloom reads
|
|
18
|
+
* roles directly through `materialRoles`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
class DynamicScheme {
|
|
22
|
+
constructor(args) {
|
|
23
|
+
this.sourceColorArgb = args.sourceColorArgb;
|
|
24
|
+
this.variant = args.variant;
|
|
25
|
+
this.contrastLevel = args.contrastLevel;
|
|
26
|
+
this.isDark = args.isDark;
|
|
27
|
+
this.sourceColorHct = _hct.Hct.fromInt(args.sourceColorArgb);
|
|
28
|
+
this.primaryPalette = args.primaryPalette;
|
|
29
|
+
this.secondaryPalette = args.secondaryPalette;
|
|
30
|
+
this.tertiaryPalette = args.tertiaryPalette;
|
|
31
|
+
this.neutralPalette = args.neutralPalette;
|
|
32
|
+
this.neutralVariantPalette = args.neutralVariantPalette;
|
|
33
|
+
this.errorPalette = _tonalPalette.TonalPalette.fromHueAndChroma(25.0, 84.0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Rotate the seed hue by a designer-specified amount that depends on which
|
|
38
|
+
* hue "breakpoint" band the seed falls in.
|
|
39
|
+
*/
|
|
40
|
+
static getRotatedHue(sourceColor, hues, rotations) {
|
|
41
|
+
const sourceHue = sourceColor.hue;
|
|
42
|
+
if (hues.length !== rotations.length) {
|
|
43
|
+
throw new Error(`mismatch between hue length ${hues.length} & rotations ${rotations.length}`);
|
|
44
|
+
}
|
|
45
|
+
if (rotations.length === 1) {
|
|
46
|
+
const firstRotation = rotations[0];
|
|
47
|
+
if (firstRotation === undefined) throw new Error('rotations[0] missing');
|
|
48
|
+
return (0, _mathUtils.sanitizeDegreesDouble)(sourceColor.hue + firstRotation);
|
|
49
|
+
}
|
|
50
|
+
const size = hues.length;
|
|
51
|
+
for (let i = 0; i <= size - 2; i++) {
|
|
52
|
+
const thisHue = hues[i];
|
|
53
|
+
const nextHue = hues[i + 1];
|
|
54
|
+
const rotation = rotations[i];
|
|
55
|
+
if (thisHue === undefined || nextHue === undefined || rotation === undefined) continue;
|
|
56
|
+
if (thisHue < sourceHue && sourceHue < nextHue) {
|
|
57
|
+
return (0, _mathUtils.sanitizeDegreesDouble)(sourceHue + rotation);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return sourceHue;
|
|
61
|
+
}
|
|
62
|
+
getArgb(role) {
|
|
63
|
+
return role.getArgb(this);
|
|
64
|
+
}
|
|
65
|
+
getHct(role) {
|
|
66
|
+
return role.getHct(this);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.DynamicScheme = DynamicScheme;
|
|
70
|
+
//# sourceMappingURL=dynamic-scheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_hct","require","_mathUtils","_tonalPalette","DynamicScheme","constructor","args","sourceColorArgb","variant","contrastLevel","isDark","sourceColorHct","Hct","fromInt","primaryPalette","secondaryPalette","tertiaryPalette","neutralPalette","neutralVariantPalette","errorPalette","TonalPalette","fromHueAndChroma","getRotatedHue","sourceColor","hues","rotations","sourceHue","hue","length","Error","firstRotation","undefined","sanitizeDegreesDouble","size","i","thisHue","nextHue","rotation","getArgb","role","getHct","exports"],"sourceRoot":"../../../../src","sources":["theme/color-engine/dynamic-scheme.ts"],"mappings":";;;;;;AAWA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBO,MAAMG,aAAa,CAAC;EAazBC,WAAWA,CAACC,IAAuB,EAAE;IACnC,IAAI,CAACC,eAAe,GAAGD,IAAI,CAACC,eAAe;IAC3C,IAAI,CAACC,OAAO,GAAGF,IAAI,CAACE,OAAO;IAC3B,IAAI,CAACC,aAAa,GAAGH,IAAI,CAACG,aAAa;IACvC,IAAI,CAACC,MAAM,GAAGJ,IAAI,CAACI,MAAM;IACzB,IAAI,CAACC,cAAc,GAAGC,QAAG,CAACC,OAAO,CAACP,IAAI,CAACC,eAAe,CAAC;IACvD,IAAI,CAACO,cAAc,GAAGR,IAAI,CAACQ,cAAc;IACzC,IAAI,CAACC,gBAAgB,GAAGT,IAAI,CAACS,gBAAgB;IAC7C,IAAI,CAACC,eAAe,GAAGV,IAAI,CAACU,eAAe;IAC3C,IAAI,CAACC,cAAc,GAAGX,IAAI,CAACW,cAAc;IACzC,IAAI,CAACC,qBAAqB,GAAGZ,IAAI,CAACY,qBAAqB;IACvD,IAAI,CAACC,YAAY,GAAGC,0BAAY,CAACC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC;EAC/D;;EAEA;AACF;AACA;AACA;EACE,OAAOC,aAAaA,CAACC,WAAgB,EAAEC,IAAc,EAAEC,SAAmB,EAAU;IAClF,MAAMC,SA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AAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.solveToInt = solveToInt;
|
|
7
|
+
var _colorUtils = require("./color-utils.js");
|
|
8
|
+
var _mathUtils = require("./math-utils.js");
|
|
9
|
+
var _viewingConditions = require("./viewing-conditions.js");
|
|
10
|
+
/**
|
|
11
|
+
* Bloom colour engine — the HCT solver.
|
|
12
|
+
*
|
|
13
|
+
* Faithful port of Material Color Utilities' `HctSolver` (Apache-2.0) into
|
|
14
|
+
* Bloom's own code. Given a desired hue, chroma and tone (L*), it finds the
|
|
15
|
+
* closest sRGB colour — an analytic Newton solve with a geometric bisection
|
|
16
|
+
* fallback that maximises chroma when the exact colour is out of gamut. This is
|
|
17
|
+
* what makes tonal palettes possible. Precision-critical; verified by golden
|
|
18
|
+
* tests. Constants are the reference values verbatim.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const SCALED_DISCOUNT_FROM_LINRGB = [[0.001200833568784504, 0.002389694492170889, 0.0002795742885861124], [0.0005891086651375999, 0.0029785502573438758, 0.0003270666104008398], [0.00010146692491640572, 0.0005364214359186694, 0.0032979401770712076]];
|
|
22
|
+
const LINRGB_FROM_SCALED_DISCOUNT = [[1373.2198709594231, -1100.4251190754821, -7.278681089101213], [-271.815969077903, 559.6580465940733, -32.46047482791194], [1.9622899599665666, -57.173814538844006, 308.7233197812385]];
|
|
23
|
+
const Y_FROM_LINRGB = [0.2126, 0.7152, 0.0722];
|
|
24
|
+
|
|
25
|
+
// prettier-ignore
|
|
26
|
+
const CRITICAL_PLANES = [0.015176349177441876, 0.045529047532325624, 0.07588174588720938, 0.10623444424209313, 0.13658714259697685, 0.16693984095186062, 0.19729253930674434, 0.2276452376616281, 0.2579979360165119, 0.28835063437139563, 0.3188300904430532, 0.350925934958123, 0.3848314933096426, 0.42057480301049466, 0.458183274052838, 0.4976837250274023, 0.5391024159806381, 0.5824650784040898, 0.6277969426914107, 0.6751227633498623, 0.7244668422128921, 0.775853049866786, 0.829304845476233, 0.8848452951698498, 0.942497089126609, 1.0022825574869039, 1.0642236851973577, 1.1283421258858297, 1.1946592148522128, 1.2631959812511864, 1.3339731595349034, 1.407011200216447, 1.4823302800086415, 1.5599503113873272, 1.6398909516233677, 1.7221716113234105, 1.8068114625156377, 1.8938294463134073, 1.9832442801866852, 2.075074464868551, 2.1693382909216234, 2.2660538449872063, 2.36523901573795, 2.4669114995532007, 2.5710888059345764, 2.6777882626779785, 2.7870270208169257, 2.898822059350997, 3.0131901897720907, 3.1301480604002863, 3.2497121605402226, 3.3718988244681087, 3.4967242352587946, 3.624204428461639, 3.754355295633311, 3.887192587735158, 4.022731918402185, 4.160988767090289, 4.301978482107941, 4.445716283538092, 4.592217266055746, 4.741496401646282, 4.893568542229298, 5.048448422192488, 5.20615066083972, 5.3666897647573375, 5.5300801301023865, 5.696336044816294, 5.865471690767354, 6.037501145825082, 6.212438385869475, 6.390297286737924, 6.571091626112461, 6.7548350853498045, 6.941541251256611, 7.131223617812143, 7.323895587840543, 7.5195704746346665, 7.7182615035334345, 7.919981813454504, 8.124744458384042, 8.332562408825165, 8.543448553206703, 8.757415699253682, 8.974476575321063, 9.194643831691977, 9.417930041841839, 9.644347703669503, 9.873909240696694, 10.106627003236781, 10.342513269534024, 10.58158024687427, 10.8238400726681, 11.069304815507364, 11.317986476196008, 11.569896988756009, 11.825048221409341, 12.083451977536606, 12.345119996613247, 12.610063955123938, 12.878295467455942, 13.149826086772048, 13.42466730586372, 13.702830557985108, 13.984327217668513, 14.269168601521828, 14.55736596900856, 14.848930523210871, 15.143873411576273, 15.44220572664832, 15.743938506781891, 16.04908273684337, 16.35764934889634, 16.66964922287304, 16.985093187232053, 17.30399201960269, 17.62635644741625, 17.95219714852476, 18.281524751807332, 18.614349837764564, 18.95068293910138, 19.290534541298456, 19.633915083172692, 19.98083495742689, 20.331304511189067, 20.685334046541502, 21.042933821039977, 21.404114048223256, 21.76888489811322, 22.137256497705877, 22.50923893145328, 22.884842241736916, 23.264076429332462, 23.6469514538663, 24.033477234264016, 24.42366364919083, 24.817520537484558, 25.21505769858089, 25.61628489293138, 26.021211842414342, 26.429848230738664, 26.842203703840827, 27.258287870275353, 27.678110301598522, 28.10168053274597, 28.529008062403893, 28.96010235337422, 29.39497283293396, 29.83362889318845, 30.276079891419332, 30.722335150426627, 31.172403958865512, 31.62629557157785, 32.08401920991837, 32.54558406207592, 33.010999283389665, 33.4802739966603, 33.953417292456834, 34.430438229418264, 34.911345834551085, 35.39614910352207, 35.88485700094671, 36.37747846067349, 36.87402238606382, 37.37449765026789, 37.87891309649659, 38.38727753828926, 38.89959975977785, 39.41588851594697, 39.93615253289054, 40.460400508064545, 40.98864111053629, 41.520882981230194, 42.05713473317016, 42.597404951718396, 43.141702194811224, 43.6900349931913, 44.24241185063697, 44.798841244188324, 45.35933162437017, 45.92389141541209, 46.49252901546552, 47.065252796817916, 47.64207110610409, 48.22299226451468, 48.808024568002054, 49.3971762874833, 49.9904556690408, 50.587870934119984, 51.189430279724725, 51.79514187861014, 52.40501387947288, 53.0190544071392, 53.637271562750364, 54.259673423945976, 54.88626804504493, 55.517063457223934, 56.15206766869424, 56.79128866487574, 57.43473440856916, 58.08241284012621, 58.734331877617365, 59.39049941699807, 60.05092333227251, 60.715611475655585, 61.38457167773311, 62.057811747619894, 62.7353394731159, 63.417162620860914, 64.10328893648692, 64.79372614476921, 65.48848194977529, 66.18756403501224, 66.89098006357258, 67.59873767827808, 68.31084450182222, 69.02730813691093, 69.74813616640164, 70.47333615344107, 71.20291564160104, 71.93688215501312, 72.67524319850172, 73.41800625771542, 74.16517879925733, 74.9167682708136, 75.67278210128072, 76.43322770089146, 77.1981124613393, 77.96744375590167, 78.74122893956174, 79.51947534912904, 80.30219030335869, 81.08938110306934, 81.88105503125999, 82.67721935322541, 83.4778813166706, 84.28304815182372, 85.09272707154808, 85.90692527145302, 86.72564993000343, 87.54890820862819, 88.3767072518277, 89.2090541872801, 90.04595612594655, 90.88742016217518, 91.73345337380438, 92.58406282226491, 93.43925555268066, 94.29903859396902, 95.16341895893969, 96.03240364439274, 96.9059996312159, 97.78421388448044, 98.6670533535366, 99.55452497210776];
|
|
27
|
+
function sanitizeRadians(angle) {
|
|
28
|
+
return (angle + Math.PI * 8) % (Math.PI * 2);
|
|
29
|
+
}
|
|
30
|
+
function trueDelinearized(rgbComponent) {
|
|
31
|
+
const normalized = rgbComponent / 100.0;
|
|
32
|
+
const delin = normalized <= 0.0031308 ? normalized * 12.92 : 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;
|
|
33
|
+
return delin * 255.0;
|
|
34
|
+
}
|
|
35
|
+
function chromaticAdaptation(component) {
|
|
36
|
+
const af = Math.pow(Math.abs(component), 0.42);
|
|
37
|
+
return (0, _mathUtils.signum)(component) * 400.0 * af / (af + 27.13);
|
|
38
|
+
}
|
|
39
|
+
function hueOf(linrgb) {
|
|
40
|
+
const scaledDiscount = (0, _mathUtils.matrixMultiply)(linrgb, SCALED_DISCOUNT_FROM_LINRGB);
|
|
41
|
+
const rA = chromaticAdaptation(scaledDiscount[0]);
|
|
42
|
+
const gA = chromaticAdaptation(scaledDiscount[1]);
|
|
43
|
+
const bA = chromaticAdaptation(scaledDiscount[2]);
|
|
44
|
+
const a = (11.0 * rA + -12.0 * gA + bA) / 11.0;
|
|
45
|
+
const b = (rA + gA - 2.0 * bA) / 9.0;
|
|
46
|
+
return Math.atan2(b, a);
|
|
47
|
+
}
|
|
48
|
+
function areInCyclicOrder(a, b, c) {
|
|
49
|
+
const deltaAB = sanitizeRadians(b - a);
|
|
50
|
+
const deltaAC = sanitizeRadians(c - a);
|
|
51
|
+
return deltaAB < deltaAC;
|
|
52
|
+
}
|
|
53
|
+
function intercept(source, mid, target) {
|
|
54
|
+
return (mid - source) / (target - source);
|
|
55
|
+
}
|
|
56
|
+
function lerpPoint(source, t, target) {
|
|
57
|
+
return [source[0] + (target[0] - source[0]) * t, source[1] + (target[1] - source[1]) * t, source[2] + (target[2] - source[2]) * t];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Read a Vec3 lane by a runtime axis index. The axis is always 0–2 in the
|
|
62
|
+
* callers below; this asserts that invariant honestly under
|
|
63
|
+
* `noUncheckedIndexedAccess` rather than masking it.
|
|
64
|
+
*/
|
|
65
|
+
function coord(v, axis) {
|
|
66
|
+
const value = v[axis];
|
|
67
|
+
if (value === undefined) throw new RangeError(`Vec3 axis ${axis} out of range`);
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function setCoordinate(source, coordinate, target, axis) {
|
|
71
|
+
const t = intercept(coord(source, axis), coordinate, coord(target, axis));
|
|
72
|
+
return lerpPoint(source, t, target);
|
|
73
|
+
}
|
|
74
|
+
function isBounded(x) {
|
|
75
|
+
return 0.0 <= x && x <= 100.0;
|
|
76
|
+
}
|
|
77
|
+
function nthVertex(y, n) {
|
|
78
|
+
const kR = Y_FROM_LINRGB[0];
|
|
79
|
+
const kG = Y_FROM_LINRGB[1];
|
|
80
|
+
const kB = Y_FROM_LINRGB[2];
|
|
81
|
+
const coordA = n % 4 <= 1 ? 0.0 : 100.0;
|
|
82
|
+
const coordB = n % 2 === 0 ? 0.0 : 100.0;
|
|
83
|
+
if (n < 4) {
|
|
84
|
+
const g = coordA;
|
|
85
|
+
const b = coordB;
|
|
86
|
+
const r = (y - g * kG - b * kB) / kR;
|
|
87
|
+
return isBounded(r) ? [r, g, b] : [-1.0, -1.0, -1.0];
|
|
88
|
+
} else if (n < 8) {
|
|
89
|
+
const b = coordA;
|
|
90
|
+
const r = coordB;
|
|
91
|
+
const g = (y - r * kR - b * kB) / kG;
|
|
92
|
+
return isBounded(g) ? [r, g, b] : [-1.0, -1.0, -1.0];
|
|
93
|
+
} else {
|
|
94
|
+
const r = coordA;
|
|
95
|
+
const g = coordB;
|
|
96
|
+
const b = (y - r * kR - g * kG) / kB;
|
|
97
|
+
return isBounded(b) ? [r, g, b] : [-1.0, -1.0, -1.0];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function bisectToSegment(y, targetHue) {
|
|
101
|
+
let left = [-1.0, -1.0, -1.0];
|
|
102
|
+
let right = left;
|
|
103
|
+
let leftHue = 0.0;
|
|
104
|
+
let rightHue = 0.0;
|
|
105
|
+
let initialized = false;
|
|
106
|
+
let uncut = true;
|
|
107
|
+
for (let n = 0; n < 12; n++) {
|
|
108
|
+
const mid = nthVertex(y, n);
|
|
109
|
+
if (mid[0] < 0) continue;
|
|
110
|
+
const midHue = hueOf(mid);
|
|
111
|
+
if (!initialized) {
|
|
112
|
+
left = mid;
|
|
113
|
+
right = mid;
|
|
114
|
+
leftHue = midHue;
|
|
115
|
+
rightHue = midHue;
|
|
116
|
+
initialized = true;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (uncut || areInCyclicOrder(leftHue, midHue, rightHue)) {
|
|
120
|
+
uncut = false;
|
|
121
|
+
if (areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
122
|
+
right = mid;
|
|
123
|
+
rightHue = midHue;
|
|
124
|
+
} else {
|
|
125
|
+
left = mid;
|
|
126
|
+
leftHue = midHue;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [left, right];
|
|
131
|
+
}
|
|
132
|
+
function midpoint(a, b) {
|
|
133
|
+
return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
|
|
134
|
+
}
|
|
135
|
+
const criticalPlaneBelow = x => Math.floor(x - 0.5);
|
|
136
|
+
const criticalPlaneAbove = x => Math.ceil(x - 0.5);
|
|
137
|
+
function bisectToLimit(y, targetHue) {
|
|
138
|
+
const segment = bisectToSegment(y, targetHue);
|
|
139
|
+
let left = segment[0];
|
|
140
|
+
let leftHue = hueOf(left);
|
|
141
|
+
let right = segment[1];
|
|
142
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
143
|
+
const leftAxis = coord(left, axis);
|
|
144
|
+
const rightAxis = coord(right, axis);
|
|
145
|
+
if (leftAxis !== rightAxis) {
|
|
146
|
+
let lPlane = -1;
|
|
147
|
+
let rPlane = 255;
|
|
148
|
+
if (leftAxis < rightAxis) {
|
|
149
|
+
lPlane = criticalPlaneBelow(trueDelinearized(leftAxis));
|
|
150
|
+
rPlane = criticalPlaneAbove(trueDelinearized(rightAxis));
|
|
151
|
+
} else {
|
|
152
|
+
lPlane = criticalPlaneAbove(trueDelinearized(leftAxis));
|
|
153
|
+
rPlane = criticalPlaneBelow(trueDelinearized(rightAxis));
|
|
154
|
+
}
|
|
155
|
+
for (let i = 0; i < 8; i++) {
|
|
156
|
+
if (Math.abs(rPlane - lPlane) <= 1) break;
|
|
157
|
+
const mPlane = Math.floor((lPlane + rPlane) / 2.0);
|
|
158
|
+
const midPlaneCoordinate = CRITICAL_PLANES[mPlane];
|
|
159
|
+
if (midPlaneCoordinate === undefined) throw new RangeError(`critical plane ${mPlane} out of range`);
|
|
160
|
+
const mid = setCoordinate(left, midPlaneCoordinate, right, axis);
|
|
161
|
+
const midHue = hueOf(mid);
|
|
162
|
+
if (areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
163
|
+
right = mid;
|
|
164
|
+
rPlane = mPlane;
|
|
165
|
+
} else {
|
|
166
|
+
left = mid;
|
|
167
|
+
leftHue = midHue;
|
|
168
|
+
lPlane = mPlane;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return midpoint(left, right);
|
|
174
|
+
}
|
|
175
|
+
function inverseChromaticAdaptation(adapted) {
|
|
176
|
+
const adaptedAbs = Math.abs(adapted);
|
|
177
|
+
const base = Math.max(0, 27.13 * adaptedAbs / (400.0 - adaptedAbs));
|
|
178
|
+
return (0, _mathUtils.signum)(adapted) * Math.pow(base, 1.0 / 0.42);
|
|
179
|
+
}
|
|
180
|
+
function findResultByJ(hueRadians, chroma, y) {
|
|
181
|
+
let j = Math.sqrt(y) * 11.0;
|
|
182
|
+
// Read the CAM16 default viewing conditions directly (no magic constants).
|
|
183
|
+
const vc = _viewingConditions.ViewingConditions.DEFAULT;
|
|
184
|
+
const tInnerCoeff = 1 / Math.pow(1.64 - Math.pow(0.29, vc.n), 0.73);
|
|
185
|
+
const eHue = 0.25 * (Math.cos(hueRadians + 2.0) + 3.8);
|
|
186
|
+
const p1 = eHue * (50000.0 / 13.0) * vc.nc * vc.ncb;
|
|
187
|
+
const hSin = Math.sin(hueRadians);
|
|
188
|
+
const hCos = Math.cos(hueRadians);
|
|
189
|
+
for (let iterationRound = 0; iterationRound < 5; iterationRound++) {
|
|
190
|
+
const jNormalized = j / 100.0;
|
|
191
|
+
const alpha = chroma === 0.0 || j === 0.0 ? 0.0 : chroma / Math.sqrt(jNormalized);
|
|
192
|
+
const t = Math.pow(alpha * tInnerCoeff, 1.0 / 0.9);
|
|
193
|
+
const ac = vc.aw * Math.pow(jNormalized, 1.0 / vc.c / vc.z);
|
|
194
|
+
const p2 = ac / vc.nbb;
|
|
195
|
+
const gamma = 23.0 * (p2 + 0.305) * t / (23.0 * p1 + 11 * t * hCos + 108.0 * t * hSin);
|
|
196
|
+
const a = gamma * hCos;
|
|
197
|
+
const b = gamma * hSin;
|
|
198
|
+
const rA = (460.0 * p2 + 451.0 * a + 288.0 * b) / 1403.0;
|
|
199
|
+
const gA = (460.0 * p2 - 891.0 * a - 261.0 * b) / 1403.0;
|
|
200
|
+
const bA = (460.0 * p2 - 220.0 * a - 6300.0 * b) / 1403.0;
|
|
201
|
+
const rCScaled = inverseChromaticAdaptation(rA);
|
|
202
|
+
const gCScaled = inverseChromaticAdaptation(gA);
|
|
203
|
+
const bCScaled = inverseChromaticAdaptation(bA);
|
|
204
|
+
const linrgb = (0, _mathUtils.matrixMultiply)([rCScaled, gCScaled, bCScaled], LINRGB_FROM_SCALED_DISCOUNT);
|
|
205
|
+
if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) return 0;
|
|
206
|
+
const kR = Y_FROM_LINRGB[0];
|
|
207
|
+
const kG = Y_FROM_LINRGB[1];
|
|
208
|
+
const kB = Y_FROM_LINRGB[2];
|
|
209
|
+
const fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
|
|
210
|
+
if (fnj <= 0) return 0;
|
|
211
|
+
if (iterationRound === 4 || Math.abs(fnj - y) < 0.002) {
|
|
212
|
+
if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) return 0;
|
|
213
|
+
return (0, _colorUtils.argbFromLinrgb)(linrgb);
|
|
214
|
+
}
|
|
215
|
+
j = j - (fnj - y) * j / (2 * fnj);
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Find the sRGB ARGB with the given hue (deg), chroma, and L*. When the exact
|
|
222
|
+
* colour is out of gamut, hue + L* are preserved and chroma is maximised.
|
|
223
|
+
*/
|
|
224
|
+
function solveToInt(hueDegrees, chroma, lstar) {
|
|
225
|
+
if (chroma < 0.0001 || lstar < 0.0001 || lstar > 99.9999) {
|
|
226
|
+
return (0, _colorUtils.argbFromLstar)(lstar);
|
|
227
|
+
}
|
|
228
|
+
hueDegrees = (0, _mathUtils.sanitizeDegreesDouble)(hueDegrees);
|
|
229
|
+
const hueRadians = hueDegrees / 180 * Math.PI;
|
|
230
|
+
const y = (0, _colorUtils.yFromLstar)(lstar);
|
|
231
|
+
const exactAnswer = findResultByJ(hueRadians, chroma, y);
|
|
232
|
+
if (exactAnswer !== 0) return exactAnswer;
|
|
233
|
+
const linrgb = bisectToLimit(y, hueRadians);
|
|
234
|
+
return (0, _colorUtils.argbFromLinrgb)(linrgb);
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=hct-solver.js.map
|