@shortfuse/materialdesignweb 0.5.0 → 0.7.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/README.md +155 -77
- package/bin/generate-css.js +12 -0
- package/components/Badge.css +30 -0
- package/components/Badge.js +15 -0
- package/components/Body.css +14 -0
- package/components/Body.js +7 -0
- package/components/BottomAppBar.css +23 -0
- package/components/BottomAppBar.js +25 -0
- package/components/Box.css +31 -0
- package/components/Box.js +24 -0
- package/components/Button.css +146 -0
- package/components/Button.js +95 -0
- package/components/Button.md +61 -0
- package/components/Card.css +109 -0
- package/components/Card.js +82 -0
- package/components/Checkbox.css +77 -0
- package/components/Checkbox.js +59 -0
- package/components/CheckboxIcon.css +89 -0
- package/components/CheckboxIcon.js +41 -0
- package/components/Chip.css +35 -0
- package/components/Chip.js +22 -0
- package/components/Dialog.css +235 -0
- package/components/Dialog.js +327 -0
- package/components/DialogActions.js +13 -0
- package/components/Divider.css +41 -0
- package/components/Divider.js +13 -0
- package/components/ExtendedFab.css +24 -0
- package/components/ExtendedFab.js +11 -0
- package/components/Fab.css +23 -0
- package/components/Fab.js +26 -0
- package/components/FilterChip.css +80 -0
- package/components/FilterChip.js +51 -0
- package/components/Headline.css +14 -0
- package/components/Headline.js +33 -0
- package/components/Icon.css +76 -0
- package/components/Icon.js +174 -0
- package/components/IconButton.css +151 -0
- package/components/IconButton.js +65 -0
- package/components/Input.js +16 -0
- package/components/Label.css +14 -0
- package/components/Label.js +7 -0
- package/components/Layout.css +19 -0
- package/components/Layout.js +12 -0
- package/components/List.css +12 -0
- package/components/List.js +17 -0
- package/components/ListItem.css +224 -0
- package/components/ListItem.js +112 -0
- package/components/ListOption.css +34 -0
- package/components/ListOption.js +122 -0
- package/components/ListSelect.css +9 -0
- package/components/ListSelect.js +206 -0
- package/components/Menu.css +171 -0
- package/components/Menu.js +470 -0
- package/components/MenuItem.css +53 -0
- package/components/MenuItem.js +215 -0
- package/components/Nav.css +17 -0
- package/components/Nav.js +23 -0
- package/components/NavBar.css +34 -0
- package/components/NavBar.js +88 -0
- package/components/NavBarItem.css +41 -0
- package/components/NavBarItem.js +7 -0
- package/components/NavDrawer.css +31 -0
- package/components/NavDrawer.js +13 -0
- package/components/NavDrawerItem.css +42 -0
- package/components/NavDrawerItem.js +12 -0
- package/components/NavItem.css +181 -0
- package/components/NavItem.js +83 -0
- package/components/NavRail.css +47 -0
- package/components/NavRail.js +17 -0
- package/components/NavRailItem.css +25 -0
- package/components/NavRailItem.js +7 -0
- package/components/Option.js +91 -0
- package/components/Outline.css +138 -0
- package/components/Pane.css +261 -0
- package/components/Pane.js +21 -0
- package/components/Progress.css +74 -0
- package/components/Progress.js +67 -0
- package/components/ProgressCircle.css +226 -0
- package/components/ProgressLine.css +155 -0
- package/components/Radio.css +83 -0
- package/components/Radio.js +42 -0
- package/components/RadioIcon.css +73 -0
- package/components/RadioIcon.js +37 -0
- package/components/Ripple.css +74 -0
- package/components/Ripple.js +114 -0
- package/components/SegmentedButton.css +94 -0
- package/components/SegmentedButton.js +49 -0
- package/components/SegmentedButtonGroup.css +12 -0
- package/components/SegmentedButtonGroup.js +44 -0
- package/components/Select.css +52 -0
- package/components/Select.js +71 -0
- package/components/Shape.css +132 -0
- package/components/Shape.js +25 -0
- package/components/Slider.css +306 -0
- package/components/Slider.js +206 -0
- package/components/Snackbar.css +80 -0
- package/components/Snackbar.js +75 -0
- package/components/Surface.css +10 -0
- package/components/Surface.js +23 -0
- package/components/Switch.css +63 -0
- package/components/Switch.js +127 -0
- package/components/SwitchIcon.css +177 -0
- package/components/SwitchIcon.js +89 -0
- package/components/SwitchIconAnimations.css +89 -0
- package/components/Tab.css +85 -0
- package/components/Tab.js +103 -0
- package/components/TabContent.js +151 -0
- package/components/TabList.css +129 -0
- package/components/TabList.js +309 -0
- package/components/TabPanel.js +37 -0
- package/components/TextArea.css +93 -0
- package/components/TextArea.js +229 -0
- package/components/Title.css +14 -0
- package/components/Title.js +15 -0
- package/components/Tooltip.css +40 -0
- package/components/Tooltip.js +22 -0
- package/components/TopAppBar.css +209 -0
- package/components/TopAppBar.js +201 -0
- package/core/Composition.js +988 -0
- package/core/CustomElement.js +844 -0
- package/core/ICustomElement.d.ts +288 -0
- package/core/ICustomElement.js +1 -0
- package/core/css.js +51 -0
- package/core/customTypes.js +125 -0
- package/core/dom.js +56 -154
- package/core/identify.js +40 -0
- package/core/observe.js +410 -0
- package/core/template.js +121 -0
- package/core/typings.d.ts +135 -0
- package/core/typings.js +1 -0
- package/mixins/AriaReflectorMixin.js +42 -0
- package/mixins/AriaToolbarMixin.js +13 -0
- package/mixins/ControlMixin.css +57 -0
- package/mixins/ControlMixin.js +212 -0
- package/mixins/DensityMixin.css +40 -0
- package/mixins/DensityMixin.js +11 -0
- package/mixins/FlexableMixin.css +79 -0
- package/mixins/FlexableMixin.js +32 -0
- package/mixins/FormAssociatedMixin.js +170 -0
- package/mixins/InputMixin.js +335 -0
- package/mixins/KeyboardNavMixin.js +244 -0
- package/mixins/RTLObserverMixin.js +35 -0
- package/mixins/ResizeObserverMixin.js +38 -0
- package/mixins/RippleMixin.css +12 -0
- package/mixins/RippleMixin.js +115 -0
- package/mixins/ScrollListenerMixin.js +100 -0
- package/mixins/ShapeMixin.css +135 -0
- package/mixins/ShapeMixin.js +31 -0
- package/mixins/StateMixin.css +82 -0
- package/mixins/StateMixin.js +114 -0
- package/mixins/SurfaceMixin.css +150 -0
- package/mixins/SurfaceMixin.js +32 -0
- package/mixins/TextFieldMixin.css +657 -0
- package/mixins/TextFieldMixin.js +121 -0
- package/mixins/ThemableMixin.css +204 -0
- package/mixins/ThemableMixin.js +16 -0
- package/mixins/TooltipTriggerMixin.css +27 -0
- package/mixins/TooltipTriggerMixin.js +366 -0
- package/mixins/TouchTargetMixin.css +26 -0
- package/mixins/TouchTargetMixin.js +9 -0
- package/package.json +54 -49
- package/theming/index.js +594 -0
- package/theming/loader.js +24 -0
- package/utils/cli.js +11 -0
- package/utils/color_keywords.js +151 -0
- package/utils/hct/Cam16.js +298 -0
- package/utils/hct/CorePalette.js +84 -0
- package/utils/hct/Hct.js +172 -0
- package/utils/hct/Scheme.js +587 -0
- package/utils/hct/TonalPalette.js +68 -0
- package/utils/hct/ViewingConditions.js +136 -0
- package/utils/hct/blend.js +93 -0
- package/utils/hct/colorUtils.js +302 -0
- package/utils/hct/hctSolver.js +559 -0
- package/utils/hct/helper.js +182 -0
- package/utils/hct/mathUtils.js +153 -0
- package/utils/jsonMergePatch.js +100 -0
- package/utils/jsx-runtime.js +101 -0
- package/utils/popup.js +117 -0
- package/utils/svg.js +129 -0
- package/.browserslistrc +0 -4
- package/.eslintrc.json +0 -204
- package/.stylelintrc.json +0 -645
- package/.vscode/launch.json +0 -31
- package/.vscode/settings.json +0 -3
- package/.vscode/tasks.json +0 -32
- package/CHANGELOG.md +0 -36
- package/CODE_OF_CONDUCT.md +0 -46
- package/adapters/datatable/column.js +0 -176
- package/adapters/datatable/index.js +0 -960
- package/adapters/dom/index.js +0 -586
- package/adapters/list/index.js +0 -69
- package/adapters/search/index.js +0 -495
- package/components/appbar/_spec.scss +0 -165
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +0 -2
- package/components/banner/_spec.scss +0 -83
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +0 -2
- package/components/bottomnav/README.md +0 -85
- package/components/bottomnav/_spec.scss +0 -149
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +0 -117
- package/components/bottomnav/index.scss +0 -2
- package/components/bottomnav/item.js +0 -88
- package/components/button/README.md +0 -61
- package/components/button/_spec.scss +0 -162
- package/components/button/_theme.scss +0 -42
- package/components/button/index.eta +0 -32
- package/components/button/index.js +0 -43
- package/components/button/index.pug +0 -18
- package/components/button/index.scss +0 -2
- package/components/card/_spec.scss +0 -241
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +0 -2
- package/components/chip/_spec.scss +0 -111
- package/components/chip/_theme.scss +0 -105
- package/components/chip/index.js +0 -23
- package/components/chip/index.scss +0 -2
- package/components/chip/item.js +0 -20
- package/components/datatable/_spec.scss +0 -225
- package/components/datatable/_theme.scss +0 -128
- package/components/datatable/cell.js +0 -44
- package/components/datatable/columnheader.js +0 -46
- package/components/datatable/index.js +0 -374
- package/components/datatable/index.scss +0 -2
- package/components/datatable/row.js +0 -48
- package/components/datatable/rowheader.js +0 -18
- package/components/dialog/_spec.scss +0 -203
- package/components/dialog/_theme.scss +0 -7
- package/components/dialog/index.js +0 -601
- package/components/dialog/index.scss +0 -2
- package/components/divider/_spec.scss +0 -11
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +0 -2
- package/components/elevation/_spec.scss +0 -9
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +0 -2
- package/components/fab/_spec.scss +0 -210
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +0 -99
- package/components/fab/index.scss +0 -2
- package/components/grid/_spec.scss +0 -169
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +0 -2
- package/components/layout/_mixins.scss +0 -11
- package/components/layout/_spec.scss +0 -916
- package/components/layout/_theme.scss +0 -19
- package/components/layout/index.js +0 -454
- package/components/layout/index.scss +0 -2
- package/components/list/_spec.scss +0 -363
- package/components/list/_theme.scss +0 -102
- package/components/list/content.js +0 -106
- package/components/list/index.js +0 -256
- package/components/list/index.scss +0 -2
- package/components/list/item.js +0 -167
- package/components/list/secondary.js +0 -45
- package/components/menu/_spec.scss +0 -329
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +0 -705
- package/components/menu/index.scss +0 -2
- package/components/menu/item.js +0 -231
- package/components/progress/_spec.scss +0 -156
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +0 -36
- package/components/progress/index.scss +0 -2
- package/components/selection/_spec.scss +0 -376
- package/components/selection/_theme.scss +0 -134
- package/components/selection/index.eta +0 -60
- package/components/selection/index.js +0 -70
- package/components/selection/index.pug +0 -30
- package/components/selection/index.scss +0 -2
- package/components/selection/input.js +0 -54
- package/components/selection/radiogroup.js +0 -40
- package/components/slider/_spec.scss +0 -59
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +0 -2
- package/components/snackbar/_spec.scss +0 -150
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +0 -338
- package/components/snackbar/index.scss +0 -2
- package/components/tab/_spec.scss +0 -220
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +0 -210
- package/components/tab/index.js +0 -257
- package/components/tab/index.scss +0 -2
- package/components/tab/item.js +0 -88
- package/components/tab/list.js +0 -196
- package/components/tab/panel.js +0 -54
- package/components/textfield/README.md +0 -179
- package/components/textfield/_spec.scss +0 -763
- package/components/textfield/_theme.scss +0 -264
- package/components/textfield/index.eta +0 -74
- package/components/textfield/index.js +0 -160
- package/components/textfield/index.pug +0 -30
- package/components/textfield/index.scss +0 -2
- package/components/tooltip/_spec.scss +0 -185
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +0 -2
- package/components/type/_spec.scss +0 -227
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +0 -2
- package/core/_breakpoint.scss +0 -189
- package/core/_elevation.scss +0 -78
- package/core/_length.scss +0 -8
- package/core/_motion.scss +0 -31
- package/core/_platform.scss +0 -12
- package/core/_type.scss +0 -128
- package/core/aria/attributes.js +0 -141
- package/core/aria/button.js +0 -49
- package/core/aria/keyboard.js +0 -92
- package/core/aria/rovingtabindex.js +0 -175
- package/core/aria/tab.js +0 -59
- package/core/document/index.js +0 -39
- package/core/overlay/_spec.scss +0 -28
- package/core/overlay/_theme.scss +0 -147
- package/core/overlay/index.js +0 -95
- package/core/overlay/index.scss +0 -2
- package/core/ripple/_spec.scss +0 -196
- package/core/ripple/_theme.scss +0 -20
- package/core/ripple/index.js +0 -286
- package/core/ripple/index.scss +0 -2
- package/core/theme/_aliases.scss +0 -15
- package/core/theme/_config.scss +0 -8
- package/core/theme/_functions.scss +0 -22
- package/core/theme/_palettes.scss +0 -405
- package/core/theme/_spec.scss +0 -0
- package/core/theme/_theme.scss +0 -268
- package/core/theme/index.js +0 -50
- package/core/theme/index.scss +0 -4
- package/core/throttler.js +0 -42
- package/core/transition/index.js +0 -465
- package/docs/_flex.scss +0 -28
- package/docs/_menuoptions.js +0 -183
- package/docs/_partials/_androidnavbar.eta +0 -5
- package/docs/_partials/_androidstatusbar.eta +0 -13
- package/docs/_partials/_appbar.eta +0 -27
- package/docs/_partials/_buttontest.eta +0 -31
- package/docs/_partials/_header.eta +0 -146
- package/docs/_partials/_navlistitem.eta +0 -16
- package/docs/_partials/_target.eta +0 -1
- package/docs/_sample-utils.js +0 -88
- package/docs/_storage.js +0 -33
- package/docs/docs.scss +0 -331
- package/docs/framework.scss +0 -26
- package/docs/index.eta +0 -12
- package/docs/index.js +0 -7
- package/docs/pages/appbar.eta +0 -108
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/bottomnav.eta +0 -188
- package/docs/pages/bottomnav.js +0 -118
- package/docs/pages/button.eta +0 -124
- package/docs/pages/button.js +0 -224
- package/docs/pages/card.eta +0 -90
- package/docs/pages/card.js +0 -175
- package/docs/pages/chip.eta +0 -122
- package/docs/pages/chip.js +0 -80
- package/docs/pages/color.eta +0 -143
- package/docs/pages/color.js +0 -261
- package/docs/pages/datatable.eta +0 -323
- package/docs/pages/datatable.js +0 -160
- package/docs/pages/dialog.eta +0 -184
- package/docs/pages/dialog.js +0 -174
- package/docs/pages/dom.eta +0 -26
- package/docs/pages/dom.js +0 -140
- package/docs/pages/elevation.eta +0 -35
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/fab.eta +0 -99
- package/docs/pages/fab.js +0 -43
- package/docs/pages/grid.eta +0 -135
- package/docs/pages/grid.js +0 -128
- package/docs/pages/layout.eta +0 -8
- package/docs/pages/layout.js +0 -0
- package/docs/pages/list.eta +0 -465
- package/docs/pages/list.js +0 -8
- package/docs/pages/menu.eta +0 -274
- package/docs/pages/menu.js +0 -213
- package/docs/pages/overlay.eta +0 -69
- package/docs/pages/overlay.js +0 -3
- package/docs/pages/progress.eta +0 -23
- package/docs/pages/progress.js +0 -12
- package/docs/pages/ripple.eta +0 -27
- package/docs/pages/ripple.js +0 -3
- package/docs/pages/search.eta +0 -242
- package/docs/pages/search.js +0 -226
- package/docs/pages/selection.eta +0 -107
- package/docs/pages/selection.js +0 -12
- package/docs/pages/slider.eta +0 -23
- package/docs/pages/slider.js +0 -0
- package/docs/pages/snackbar.eta +0 -83
- package/docs/pages/snackbar.js +0 -157
- package/docs/pages/tab.eta +0 -407
- package/docs/pages/tab.js +0 -152
- package/docs/pages/textfield.eta +0 -487
- package/docs/pages/textfield.js +0 -257
- package/docs/pages/tooltip.eta +0 -92
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/transition.eta +0 -117
- package/docs/pages/transition.js +0 -52
- package/docs/pages/type.eta +0 -31
- package/docs/pages/type.js +0 -0
- package/docs/postrender.js +0 -41
- package/docs/prerender.js +0 -16
- package/docs/pwa/_dialogs.eta +0 -143
- package/docs/pwa/_menus.eta +0 -16
- package/docs/pwa/pwa-prerender.js +0 -3
- package/docs/pwa/pwa.eta +0 -478
- package/docs/pwa/pwa.js +0 -298
- package/docs/pwa/pwa.scss +0 -31
- package/docs/themes/theme-colored.scss +0 -15
- package/docs/themes/theme-default.scss +0 -3
- package/index.scss +0 -27
- package/jsconfig.json +0 -16
- package/scripts/deploy-docs.sh +0 -9
- package/templates/index.eta +0 -2
- package/templates/index.pug +0 -3
- package/tsconfig.json +0 -16
- package/webpack.config.js +0 -304
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import Cam16 from './Cam16.js';
|
|
19
|
+
import ViewingConditions from './ViewingConditions.js';
|
|
20
|
+
import * as colorUtils from './colorUtils.js';
|
|
21
|
+
import * as mathUtils from './mathUtils.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A class that solves the HCT equation.
|
|
25
|
+
*/
|
|
26
|
+
// libmonet is designed to have a consistent API across platforms
|
|
27
|
+
// and modular components that can be moved around easily. Using a class as a
|
|
28
|
+
// namespace facilitates this.
|
|
29
|
+
//
|
|
30
|
+
// tslint:disable-next-line:class-as-namespace
|
|
31
|
+
|
|
32
|
+
export const SCALED_DISCOUNT_FROM_LINRGB = [
|
|
33
|
+
[
|
|
34
|
+
0.001_200_833_568_784_504,
|
|
35
|
+
0.002_389_694_492_170_889,
|
|
36
|
+
0.000_279_574_288_586_112_4,
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
0.000_589_108_665_137_599_9,
|
|
40
|
+
0.002_978_550_257_343_875_8,
|
|
41
|
+
0.000_327_066_610_400_839_8,
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
0.000_101_466_924_916_405_72,
|
|
45
|
+
0.000_536_421_435_918_669_4,
|
|
46
|
+
0.003_297_940_177_071_207_6,
|
|
47
|
+
],
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export const LINRGB_FROM_SCALED_DISCOUNT = [
|
|
51
|
+
[
|
|
52
|
+
1373.219_870_959_423_1,
|
|
53
|
+
-1100.425_119_075_482_1,
|
|
54
|
+
-7.278_681_089_101_213,
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
-271.815_969_077_903,
|
|
58
|
+
559.658_046_594_073_3,
|
|
59
|
+
-32.460_474_827_911_94,
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
1.962_289_959_966_566_6,
|
|
63
|
+
-57.173_814_538_844_006,
|
|
64
|
+
308.723_319_781_238_5,
|
|
65
|
+
],
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
export const Y_FROM_LINRGB = [0.2126, 0.7152, 0.0722];
|
|
69
|
+
|
|
70
|
+
export const CRITICAL_PLANES = [
|
|
71
|
+
0.015_176_349_177_441_876, 0.045_529_047_532_325_624, 0.075_881_745_887_209_38,
|
|
72
|
+
0.106_234_444_242_093_13, 0.136_587_142_596_976_85, 0.166_939_840_951_860_62,
|
|
73
|
+
0.197_292_539_306_744_34, 0.227_645_237_661_628_1, 0.257_997_936_016_511_9,
|
|
74
|
+
0.288_350_634_371_395_63, 0.318_830_090_443_053_2, 0.350_925_934_958_123,
|
|
75
|
+
0.384_831_493_309_642_6, 0.420_574_803_010_494_66, 0.458_183_274_052_838,
|
|
76
|
+
0.497_683_725_027_402_3, 0.539_102_415_980_638_1, 0.582_465_078_404_089_8,
|
|
77
|
+
0.627_796_942_691_410_7, 0.675_122_763_349_862_3, 0.724_466_842_212_892_1,
|
|
78
|
+
0.775_853_049_866_786, 0.829_304_845_476_233, 0.884_845_295_169_849_8,
|
|
79
|
+
0.942_497_089_126_609, 1.002_282_557_486_903_9, 1.064_223_685_197_357_7,
|
|
80
|
+
1.128_342_125_885_829_7, 1.194_659_214_852_212_8, 1.263_195_981_251_186_4,
|
|
81
|
+
1.333_973_159_534_903_4, 1.407_011_200_216_447, 1.482_330_280_008_641_5,
|
|
82
|
+
1.559_950_311_387_327_2, 1.639_890_951_623_367_7, 1.722_171_611_323_410_5,
|
|
83
|
+
1.806_811_462_515_637_7, 1.893_829_446_313_407_3, 1.983_244_280_186_685_2,
|
|
84
|
+
2.075_074_464_868_551, 2.169_338_290_921_623_4, 2.266_053_844_987_206_3,
|
|
85
|
+
2.365_239_015_737_95, 2.466_911_499_553_200_7, 2.571_088_805_934_576_4,
|
|
86
|
+
2.677_788_262_677_978_5, 2.787_027_020_816_925_7, 2.898_822_059_350_997,
|
|
87
|
+
3.013_190_189_772_090_7, 3.130_148_060_400_286_3, 3.249_712_160_540_222_6,
|
|
88
|
+
3.371_898_824_468_108_7, 3.496_724_235_258_794_6, 3.624_204_428_461_639,
|
|
89
|
+
3.754_355_295_633_311, 3.887_192_587_735_158, 4.022_731_918_402_185,
|
|
90
|
+
4.160_988_767_090_289, 4.301_978_482_107_941, 4.445_716_283_538_092,
|
|
91
|
+
4.592_217_266_055_746, 4.741_496_401_646_282, 4.893_568_542_229_298,
|
|
92
|
+
5.048_448_422_192_488, 5.206_150_660_839_72, 5.366_689_764_757_337_5,
|
|
93
|
+
5.530_080_130_102_386_5, 5.696_336_044_816_294, 5.865_471_690_767_354,
|
|
94
|
+
6.037_501_145_825_082, 6.212_438_385_869_475, 6.390_297_286_737_924,
|
|
95
|
+
6.571_091_626_112_461, 6.754_835_085_349_804_5, 6.941_541_251_256_611,
|
|
96
|
+
7.131_223_617_812_143, 7.323_895_587_840_543, 7.519_570_474_634_666_5,
|
|
97
|
+
7.718_261_503_533_434_5, 7.919_981_813_454_504, 8.124_744_458_384_042,
|
|
98
|
+
8.332_562_408_825_165, 8.543_448_553_206_703, 8.757_415_699_253_682,
|
|
99
|
+
8.974_476_575_321_063, 9.194_643_831_691_977, 9.417_930_041_841_839,
|
|
100
|
+
9.644_347_703_669_503, 9.873_909_240_696_694, 10.106_627_003_236_781,
|
|
101
|
+
10.342_513_269_534_024, 10.581_580_246_874_27, 10.823_840_072_668_1,
|
|
102
|
+
11.069_304_815_507_364, 11.317_986_476_196_008, 11.569_896_988_756_009,
|
|
103
|
+
11.825_048_221_409_341, 12.083_451_977_536_606, 12.345_119_996_613_247,
|
|
104
|
+
12.610_063_955_123_938, 12.878_295_467_455_942, 13.149_826_086_772_048,
|
|
105
|
+
13.424_667_305_863_72, 13.702_830_557_985_108, 13.984_327_217_668_513,
|
|
106
|
+
14.269_168_601_521_828, 14.557_365_969_008_56, 14.848_930_523_210_871,
|
|
107
|
+
15.143_873_411_576_273, 15.442_205_726_648_32, 15.743_938_506_781_891,
|
|
108
|
+
16.049_082_736_843_37, 16.357_649_348_896_34, 16.669_649_222_873_04,
|
|
109
|
+
16.985_093_187_232_053, 17.303_992_019_602_69, 17.626_356_447_416_25,
|
|
110
|
+
17.952_197_148_524_76, 18.281_524_751_807_332, 18.614_349_837_764_564,
|
|
111
|
+
18.950_682_939_101_38, 19.290_534_541_298_456, 19.633_915_083_172_692,
|
|
112
|
+
19.980_834_957_426_89, 20.331_304_511_189_067, 20.685_334_046_541_502,
|
|
113
|
+
21.042_933_821_039_977, 21.404_114_048_223_256, 21.768_884_898_113_22,
|
|
114
|
+
22.137_256_497_705_877, 22.509_238_931_453_28, 22.884_842_241_736_916,
|
|
115
|
+
23.264_076_429_332_462, 23.646_951_453_866_3, 24.033_477_234_264_016,
|
|
116
|
+
24.423_663_649_190_83, 24.817_520_537_484_558, 25.215_057_698_580_89,
|
|
117
|
+
25.616_284_892_931_38, 26.021_211_842_414_342, 26.429_848_230_738_664,
|
|
118
|
+
26.842_203_703_840_827, 27.258_287_870_275_353, 27.678_110_301_598_522,
|
|
119
|
+
28.101_680_532_745_97, 28.529_008_062_403_893, 28.960_102_353_374_22,
|
|
120
|
+
29.394_972_832_933_96, 29.833_628_893_188_45, 30.276_079_891_419_332,
|
|
121
|
+
30.722_335_150_426_627, 31.172_403_958_865_512, 31.626_295_571_577_85,
|
|
122
|
+
32.084_019_209_918_37, 32.545_584_062_075_92, 33.010_999_283_389_665,
|
|
123
|
+
33.480_273_996_660_3, 33.953_417_292_456_834, 34.430_438_229_418_264,
|
|
124
|
+
34.911_345_834_551_085, 35.396_149_103_522_07, 35.884_857_000_946_71,
|
|
125
|
+
36.377_478_460_673_49, 36.874_022_386_063_82, 37.374_497_650_267_89,
|
|
126
|
+
37.878_913_096_496_59, 38.387_277_538_289_26, 38.899_599_759_777_85,
|
|
127
|
+
39.415_888_515_946_97, 39.936_152_532_890_54, 40.460_400_508_064_545,
|
|
128
|
+
40.988_641_110_536_29, 41.520_882_981_230_194, 42.057_134_733_170_16,
|
|
129
|
+
42.597_404_951_718_396, 43.141_702_194_811_224, 43.690_034_993_191_3,
|
|
130
|
+
44.242_411_850_636_97, 44.798_841_244_188_324, 45.359_331_624_370_17,
|
|
131
|
+
45.923_891_415_412_09, 46.492_529_015_465_52, 47.065_252_796_817_916,
|
|
132
|
+
47.642_071_106_104_09, 48.222_992_264_514_68, 48.808_024_568_002_054,
|
|
133
|
+
49.397_176_287_483_3, 49.990_455_669_040_8, 50.587_870_934_119_984,
|
|
134
|
+
51.189_430_279_724_725, 51.795_141_878_610_14, 52.405_013_879_472_88,
|
|
135
|
+
53.019_054_407_139_2, 53.637_271_562_750_364, 54.259_673_423_945_976,
|
|
136
|
+
54.886_268_045_044_93, 55.517_063_457_223_934, 56.152_067_668_694_24,
|
|
137
|
+
56.791_288_664_875_74, 57.434_734_408_569_16, 58.082_412_840_126_21,
|
|
138
|
+
58.734_331_877_617_365, 59.390_499_416_998_07, 60.050_923_332_272_51,
|
|
139
|
+
60.715_611_475_655_585, 61.384_571_677_733_11, 62.057_811_747_619_894,
|
|
140
|
+
62.735_339_473_115_9, 63.417_162_620_860_914, 64.103_288_936_486_92,
|
|
141
|
+
64.793_726_144_769_21, 65.488_481_949_775_29, 66.187_564_035_012_24,
|
|
142
|
+
66.890_980_063_572_58, 67.598_737_678_278_08, 68.310_844_501_822_22,
|
|
143
|
+
69.027_308_136_910_93, 69.748_136_166_401_64, 70.473_336_153_441_07,
|
|
144
|
+
71.202_915_641_601_04, 71.936_882_155_013_12, 72.675_243_198_501_72,
|
|
145
|
+
73.418_006_257_715_42, 74.165_178_799_257_33, 74.916_768_270_813_6,
|
|
146
|
+
75.672_782_101_280_72, 76.433_227_700_891_46, 77.198_112_461_339_3,
|
|
147
|
+
77.967_443_755_901_67, 78.741_228_939_561_74, 79.519_475_349_129_04,
|
|
148
|
+
80.302_190_303_358_69, 81.089_381_103_069_34, 81.881_055_031_259_99,
|
|
149
|
+
82.677_219_353_225_41, 83.477_881_316_670_6, 84.283_048_151_823_72,
|
|
150
|
+
85.092_727_071_548_08, 85.906_925_271_453_02, 86.725_649_930_003_43,
|
|
151
|
+
87.548_908_208_628_19, 88.376_707_251_827_7, 89.209_054_187_280_1,
|
|
152
|
+
90.045_956_125_946_55, 90.887_420_162_175_18, 91.733_453_373_804_38,
|
|
153
|
+
92.584_062_822_264_91, 93.439_255_552_680_66, 94.299_038_593_969_02,
|
|
154
|
+
95.163_418_958_939_69, 96.032_403_644_392_74, 96.905_999_631_215_9,
|
|
155
|
+
97.784_213_884_480_44, 98.667_053_353_536_6, 99.554_524_972_107_76,
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Sanitizes a small enough angle in radians.
|
|
160
|
+
* @param {number} angle An angle in radians; must not deviate too much
|
|
161
|
+
* from 0.
|
|
162
|
+
* @return {number} A coterminal angle between 0 and 2pi.
|
|
163
|
+
*/
|
|
164
|
+
function sanitizeRadians(angle) {
|
|
165
|
+
return (angle + Math.PI * 8) % (Math.PI * 2);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Delinearizes an RGB component, returning a floating-point
|
|
170
|
+
* number.
|
|
171
|
+
* @param {number} rgbComponent 0.0 <= rgb_component <= 100.0, represents
|
|
172
|
+
* linear R/G/B channel
|
|
173
|
+
* @return {number} 0.0 <= output <= 255.0, color channel converted to
|
|
174
|
+
* regular RGB space
|
|
175
|
+
*/
|
|
176
|
+
function trueDelinearized(rgbComponent) {
|
|
177
|
+
const normalized = rgbComponent / 100;
|
|
178
|
+
let delinearized = 0;
|
|
179
|
+
delinearized = normalized <= 0.003_130_8 ? normalized * 12.92 : 1.055 * normalized ** (1 / 2.4) - 0.055;
|
|
180
|
+
return delinearized * 255;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {number} component
|
|
185
|
+
* @return {number}
|
|
186
|
+
*/
|
|
187
|
+
function chromaticAdaptation(component) {
|
|
188
|
+
const af = Math.abs(component) ** 0.42;
|
|
189
|
+
return mathUtils.signum(component) * 400 * af / (af + 27.13);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Returns the hue of a linear RGB color in CAM16.
|
|
194
|
+
* @param {number[]} linrgb The linear RGB coordinates of a color.
|
|
195
|
+
* @return {number} The hue of the color in CAM16, in radians.
|
|
196
|
+
*/
|
|
197
|
+
function hueOf(linrgb) {
|
|
198
|
+
const scaledDiscount = mathUtils.matrixMultiply(linrgb, SCALED_DISCOUNT_FROM_LINRGB);
|
|
199
|
+
const rA = chromaticAdaptation(scaledDiscount[0]);
|
|
200
|
+
const gA = chromaticAdaptation(scaledDiscount[1]);
|
|
201
|
+
const bA = chromaticAdaptation(scaledDiscount[2]);
|
|
202
|
+
// redness-greenness
|
|
203
|
+
const a = (11 * rA + -12 * gA + bA) / 11;
|
|
204
|
+
// yellowness-blueness
|
|
205
|
+
const b = (rA + gA - 2 * bA) / 9;
|
|
206
|
+
return Math.atan2(b, a);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
* @param {number} a
|
|
212
|
+
* @param {number} b
|
|
213
|
+
* @param {number} c
|
|
214
|
+
* @return {boolean}
|
|
215
|
+
*/
|
|
216
|
+
function areInCyclicOrder(a, b, c) {
|
|
217
|
+
const deltaAB = sanitizeRadians(b - a);
|
|
218
|
+
const deltaAC = sanitizeRadians(c - a);
|
|
219
|
+
return deltaAB < deltaAC;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Solves the lerp equation.
|
|
224
|
+
* @param {number} source The starting number.
|
|
225
|
+
* @param {number} mid The number in the middle.
|
|
226
|
+
* @param {number} target The ending number.
|
|
227
|
+
* @return {number} A number t such that lerp(source, target, t) = mid.
|
|
228
|
+
*/
|
|
229
|
+
function intercept(source, mid, target) {
|
|
230
|
+
return (mid - source) / (target - source);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param {number[]} source
|
|
236
|
+
* @param {number} t
|
|
237
|
+
* @param {number[]} target
|
|
238
|
+
* @return {[number,number,number]}
|
|
239
|
+
*/
|
|
240
|
+
function lerpPoint(source, t, target) {
|
|
241
|
+
return [
|
|
242
|
+
source[0] + (target[0] - source[0]) * t,
|
|
243
|
+
source[1] + (target[1] - source[1]) * t,
|
|
244
|
+
source[2] + (target[2] - source[2]) * t,
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Intersects a segment with a plane.
|
|
250
|
+
* @param {number[]} source The coordinates of point A.
|
|
251
|
+
* @param {number} coordinate The R-, G-, or B-coordinate of the plane.
|
|
252
|
+
* @param {number[]} target The coordinates of point B.
|
|
253
|
+
* @param {number} axis The axis the plane is perpendicular with. (0: R, 1:
|
|
254
|
+
* G, 2: B)
|
|
255
|
+
* @return {number[]} The intersection point of the segment AB with the plane
|
|
256
|
+
* R=coordinate, G=coordinate, or B=coordinate
|
|
257
|
+
*/
|
|
258
|
+
function setCoordinate(source, coordinate, target, axis) {
|
|
259
|
+
const t = intercept(source[axis], coordinate, target[axis]);
|
|
260
|
+
return lerpPoint(source, t, target);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @param {number} x
|
|
265
|
+
* @return {boolean}
|
|
266
|
+
*/
|
|
267
|
+
function isBounded(x) {
|
|
268
|
+
return x >= 0 && x <= 100;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns the nth possible vertex of the polygonal intersection.
|
|
273
|
+
* @param {number} y The Y value of the plane
|
|
274
|
+
* @param {number} n The zero-based index of the point. 0 <= n <= 11.
|
|
275
|
+
* @return {number[]} The nth possible vertex of the polygonal intersection
|
|
276
|
+
* of the y plane and the RGB cube, in linear RGB coordinates, if
|
|
277
|
+
* it exists. If this possible vertex lies outside of the cube,
|
|
278
|
+
* [-1.0, -1.0, -1.0] is returned.
|
|
279
|
+
*/
|
|
280
|
+
function nthVertex(y, n) {
|
|
281
|
+
const kR = Y_FROM_LINRGB[0];
|
|
282
|
+
const kG = Y_FROM_LINRGB[1];
|
|
283
|
+
const kB = Y_FROM_LINRGB[2];
|
|
284
|
+
const coordA = n % 4 <= 1 ? 0 : 100;
|
|
285
|
+
const coordB = n % 2 === 0 ? 0 : 100;
|
|
286
|
+
if (n < 4) {
|
|
287
|
+
const g = coordA;
|
|
288
|
+
const b = coordB;
|
|
289
|
+
const r = (y - g * kG - b * kB) / kR;
|
|
290
|
+
if (isBounded(r)) {
|
|
291
|
+
return [r, g, b];
|
|
292
|
+
}
|
|
293
|
+
return [-1, -1, -1];
|
|
294
|
+
}
|
|
295
|
+
if (n < 8) {
|
|
296
|
+
const b = coordA;
|
|
297
|
+
const r = coordB;
|
|
298
|
+
const g = (y - r * kR - b * kB) / kG;
|
|
299
|
+
if (isBounded(g)) {
|
|
300
|
+
return [r, g, b];
|
|
301
|
+
}
|
|
302
|
+
return [-1, -1, -1];
|
|
303
|
+
}
|
|
304
|
+
const r = coordA;
|
|
305
|
+
const g = coordB;
|
|
306
|
+
const b = (y - r * kR - g * kG) / kB;
|
|
307
|
+
if (isBounded(b)) {
|
|
308
|
+
return [r, g, b];
|
|
309
|
+
}
|
|
310
|
+
return [-1, -1, -1];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Finds the segment containing the desired color.
|
|
315
|
+
* @param {number} y The Y value of the color.
|
|
316
|
+
* @param {number} targetHue The hue of the color.
|
|
317
|
+
* @return {[number[], number[]]} A list of two sets of linear RGB coordinates, each
|
|
318
|
+
* corresponding to an endpoint of the segment containing the
|
|
319
|
+
* desired color.
|
|
320
|
+
*/
|
|
321
|
+
function bisectToSegment(y, targetHue) {
|
|
322
|
+
let left = [-1, -1, -1];
|
|
323
|
+
let right = left;
|
|
324
|
+
let leftHue = 0;
|
|
325
|
+
let rightHue = 0;
|
|
326
|
+
let initialized = false;
|
|
327
|
+
let uncut = true;
|
|
328
|
+
|
|
329
|
+
for (let n = 0; n < 12; n++) {
|
|
330
|
+
const mid = nthVertex(y, n);
|
|
331
|
+
if (mid[0] < 0) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const midHue = hueOf(mid);
|
|
335
|
+
if (!initialized) {
|
|
336
|
+
left = mid;
|
|
337
|
+
right = mid;
|
|
338
|
+
leftHue = midHue;
|
|
339
|
+
rightHue = midHue;
|
|
340
|
+
initialized = true;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (uncut || areInCyclicOrder(leftHue, midHue, rightHue)) {
|
|
344
|
+
uncut = false;
|
|
345
|
+
if (areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
346
|
+
right = mid;
|
|
347
|
+
rightHue = midHue;
|
|
348
|
+
} else {
|
|
349
|
+
left = mid;
|
|
350
|
+
leftHue = midHue;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return [left, right];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
*
|
|
359
|
+
* @param {number[]} a
|
|
360
|
+
* @param {number[]} b
|
|
361
|
+
* @return {number[]}
|
|
362
|
+
*/
|
|
363
|
+
function midpoint(a, b) {
|
|
364
|
+
return [
|
|
365
|
+
(a[0] + b[0]) / 2,
|
|
366
|
+
(a[1] + b[1]) / 2,
|
|
367
|
+
(a[2] + b[2]) / 2,
|
|
368
|
+
];
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @param {number} x
|
|
373
|
+
* @return {number}
|
|
374
|
+
*/
|
|
375
|
+
function criticalPlaneBelow(x) {
|
|
376
|
+
return Math.floor(x - 0.5);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @param {number} x
|
|
381
|
+
* @return {number}
|
|
382
|
+
*/
|
|
383
|
+
function criticalPlaneAbove(x) {
|
|
384
|
+
return Math.ceil(x - 0.5);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Finds a color with the given Y and hue on the boundary of the
|
|
389
|
+
* cube.
|
|
390
|
+
* @param {number} y The Y value of the color.
|
|
391
|
+
* @param {number} targetHue The hue of the color.
|
|
392
|
+
* @return {number[]} The desired color, in linear RGB coordinates.
|
|
393
|
+
*/
|
|
394
|
+
function bisectToLimit(y, targetHue) {
|
|
395
|
+
const segment = bisectToSegment(y, targetHue);
|
|
396
|
+
let left = segment[0];
|
|
397
|
+
let leftHue = hueOf(left);
|
|
398
|
+
let right = segment[1];
|
|
399
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
400
|
+
if (left[axis] !== right[axis]) {
|
|
401
|
+
let lPlane = -1;
|
|
402
|
+
let rPlane = 255;
|
|
403
|
+
if (left[axis] < right[axis]) {
|
|
404
|
+
lPlane = criticalPlaneBelow(
|
|
405
|
+
trueDelinearized(left[axis]),
|
|
406
|
+
);
|
|
407
|
+
rPlane = criticalPlaneAbove(
|
|
408
|
+
trueDelinearized(right[axis]),
|
|
409
|
+
);
|
|
410
|
+
} else {
|
|
411
|
+
lPlane = criticalPlaneAbove(
|
|
412
|
+
trueDelinearized(left[axis]),
|
|
413
|
+
);
|
|
414
|
+
rPlane = criticalPlaneBelow(
|
|
415
|
+
trueDelinearized(right[axis]),
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
for (let i = 0; i < 8; i++) {
|
|
419
|
+
if (Math.abs(rPlane - lPlane) <= 1) {
|
|
420
|
+
break;
|
|
421
|
+
} else {
|
|
422
|
+
const mPlane = Math.floor((lPlane + rPlane) / 2);
|
|
423
|
+
const midPlaneCoordinate = CRITICAL_PLANES[mPlane];
|
|
424
|
+
const mid = setCoordinate(left, midPlaneCoordinate, right, axis);
|
|
425
|
+
const midHue = hueOf(mid);
|
|
426
|
+
if (areInCyclicOrder(leftHue, targetHue, midHue)) {
|
|
427
|
+
right = mid;
|
|
428
|
+
rPlane = mPlane;
|
|
429
|
+
} else {
|
|
430
|
+
left = mid;
|
|
431
|
+
leftHue = midHue;
|
|
432
|
+
lPlane = mPlane;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return midpoint(left, right);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* @param {number} adapted
|
|
443
|
+
* @return {number}
|
|
444
|
+
*/
|
|
445
|
+
function inverseChromaticAdaptation(adapted) {
|
|
446
|
+
const adaptedAbs = Math.abs(adapted);
|
|
447
|
+
const base = Math.max(0, 27.13 * adaptedAbs / (400 - adaptedAbs));
|
|
448
|
+
return mathUtils.signum(adapted) * base ** (1 / 0.42);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Finds a color with the given hue, chroma, and Y.
|
|
453
|
+
* @param {number} hueRadians The desired hue in radians.
|
|
454
|
+
* @param {number} chroma The desired chroma.
|
|
455
|
+
* @param {number} y The desired Y.
|
|
456
|
+
* @return {number} The desired color as a hexadecimal integer, if found; 0
|
|
457
|
+
* otherwise.
|
|
458
|
+
*/
|
|
459
|
+
function findResultByJ(hueRadians, chroma, y) {
|
|
460
|
+
// Initial estimate of j.
|
|
461
|
+
let j = Math.sqrt(y) * 11;
|
|
462
|
+
// ===========================================================
|
|
463
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
464
|
+
// ===========================================================
|
|
465
|
+
const viewingConditions = ViewingConditions.DEFAULT;
|
|
466
|
+
const tInnerCoeff = 1 / (1.64 - 0.29 ** viewingConditions.n) ** 0.73;
|
|
467
|
+
const eHue = 0.25 * (Math.cos(hueRadians + 2) + 3.8);
|
|
468
|
+
const p1 = eHue * (50_000 / 13) * viewingConditions.nc * viewingConditions.ncb;
|
|
469
|
+
const hSin = Math.sin(hueRadians);
|
|
470
|
+
const hCos = Math.cos(hueRadians);
|
|
471
|
+
for (let iterationRound = 0; iterationRound < 5; iterationRound++) {
|
|
472
|
+
// ===========================================================
|
|
473
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
474
|
+
// ===========================================================
|
|
475
|
+
const jNormalized = j / 100;
|
|
476
|
+
const alpha = chroma === 0 || j === 0 ? 0 : chroma / Math.sqrt(jNormalized);
|
|
477
|
+
const t = (alpha * tInnerCoeff) ** (1 / 0.9);
|
|
478
|
+
const ac = viewingConditions.aw
|
|
479
|
+
* jNormalized ** (1 / viewingConditions.c / viewingConditions.z);
|
|
480
|
+
const p2 = ac / viewingConditions.nbb;
|
|
481
|
+
const gamma = 23 * (p2 + 0.305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin);
|
|
482
|
+
const a = gamma * hCos;
|
|
483
|
+
const b = gamma * hSin;
|
|
484
|
+
const rA = (460 * p2 + 451 * a + 288 * b) / 1403;
|
|
485
|
+
const gA = (460 * p2 - 891 * a - 261 * b) / 1403;
|
|
486
|
+
const bA = (460 * p2 - 220 * a - 6300 * b) / 1403;
|
|
487
|
+
const rCScaled = inverseChromaticAdaptation(rA);
|
|
488
|
+
const gCScaled = inverseChromaticAdaptation(gA);
|
|
489
|
+
const bCScaled = inverseChromaticAdaptation(bA);
|
|
490
|
+
const linrgb = mathUtils.matrixMultiply(
|
|
491
|
+
[rCScaled, gCScaled, bCScaled],
|
|
492
|
+
LINRGB_FROM_SCALED_DISCOUNT,
|
|
493
|
+
);
|
|
494
|
+
// ===========================================================
|
|
495
|
+
// Operations inlined from Cam16 to avoid repeated calculation
|
|
496
|
+
// ===========================================================
|
|
497
|
+
if (linrgb[0] < 0 || linrgb[1] < 0 || linrgb[2] < 0) {
|
|
498
|
+
return 0;
|
|
499
|
+
}
|
|
500
|
+
const kR = Y_FROM_LINRGB[0];
|
|
501
|
+
const kG = Y_FROM_LINRGB[1];
|
|
502
|
+
const kB = Y_FROM_LINRGB[2];
|
|
503
|
+
const fnj = kR * linrgb[0] + kG * linrgb[1] + kB * linrgb[2];
|
|
504
|
+
if (fnj <= 0) {
|
|
505
|
+
return 0;
|
|
506
|
+
}
|
|
507
|
+
if (iterationRound === 4 || Math.abs(fnj - y) < 0.002) {
|
|
508
|
+
if (linrgb[0] > 100.01 || linrgb[1] > 100.01 || linrgb[2] > 100.01) {
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
return colorUtils.argbFromLinrgb(linrgb);
|
|
512
|
+
}
|
|
513
|
+
// Iterates with Newton method,
|
|
514
|
+
// Using 2 * fn(j) / j as the approximation of fn'(j)
|
|
515
|
+
j -= (fnj - y) * j / (2 * fnj);
|
|
516
|
+
}
|
|
517
|
+
return 0;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Finds an sRGB color with the given hue, chroma, and L*, if
|
|
522
|
+
* possible.
|
|
523
|
+
* @param {number} hueDegrees The desired hue, in degrees.
|
|
524
|
+
* @param {number} chroma The desired chroma.
|
|
525
|
+
* @param {number} lstar The desired L*.
|
|
526
|
+
* @return {number} A hexadecimal representing the sRGB color. The color
|
|
527
|
+
* has sufficiently close hue, chroma, and L* to the desired
|
|
528
|
+
* values, if possible; otherwise, the hue and L* will be
|
|
529
|
+
* sufficiently close, and chroma will be maximized.
|
|
530
|
+
*/
|
|
531
|
+
export function solveToInt(hueDegrees, chroma, lstar) {
|
|
532
|
+
if (chroma < 0.0001 || lstar < 0.0001 || lstar > 99.9999) {
|
|
533
|
+
return colorUtils.argbFromLstar(lstar);
|
|
534
|
+
}
|
|
535
|
+
hueDegrees = mathUtils.sanitizeDegreesDouble(hueDegrees);
|
|
536
|
+
const hueRadians = hueDegrees / 180 * Math.PI;
|
|
537
|
+
const y = colorUtils.yFromLstar(lstar);
|
|
538
|
+
const exactAnswer = findResultByJ(hueRadians, chroma, y);
|
|
539
|
+
if (exactAnswer !== 0) {
|
|
540
|
+
return exactAnswer;
|
|
541
|
+
}
|
|
542
|
+
const linrgb = bisectToLimit(y, hueRadians);
|
|
543
|
+
return colorUtils.argbFromLinrgb(linrgb);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Finds an sRGB color with the given hue, chroma, and L*, if
|
|
548
|
+
* possible.
|
|
549
|
+
* @param {number} hueDegrees The desired hue, in degrees.
|
|
550
|
+
* @param {number} chroma The desired chroma.
|
|
551
|
+
* @param {number} lstar The desired L*.
|
|
552
|
+
* @return {Cam16} An CAM16 object representing the sRGB color. The color
|
|
553
|
+
* has sufficiently close hue, chroma, and L* to the desired
|
|
554
|
+
* values, if possible; otherwise, the hue and L* will be
|
|
555
|
+
* sufficiently close, and chroma will be maximized.
|
|
556
|
+
*/
|
|
557
|
+
export function solveToCam(hueDegrees, chroma, lstar) {
|
|
558
|
+
return Cam16.fromInt(solveToInt(hueDegrees, chroma, lstar));
|
|
559
|
+
}
|