@shortfuse/materialdesignweb 0.4.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.
Files changed (452) hide show
  1. package/README.md +155 -79
  2. package/bin/generate-css.js +12 -0
  3. package/components/Badge.css +30 -0
  4. package/components/Badge.js +15 -0
  5. package/components/Body.css +14 -0
  6. package/components/Body.js +7 -0
  7. package/components/BottomAppBar.css +23 -0
  8. package/components/BottomAppBar.js +25 -0
  9. package/components/Box.css +31 -0
  10. package/components/Box.js +24 -0
  11. package/components/Button.css +146 -0
  12. package/components/Button.js +95 -0
  13. package/components/Button.md +61 -0
  14. package/components/Card.css +109 -0
  15. package/components/Card.js +82 -0
  16. package/components/Checkbox.css +77 -0
  17. package/components/Checkbox.js +59 -0
  18. package/components/CheckboxIcon.css +89 -0
  19. package/components/CheckboxIcon.js +41 -0
  20. package/components/Chip.css +35 -0
  21. package/components/Chip.js +22 -0
  22. package/components/Dialog.css +235 -0
  23. package/components/Dialog.js +327 -0
  24. package/components/DialogActions.js +13 -0
  25. package/components/Divider.css +41 -0
  26. package/components/Divider.js +13 -0
  27. package/components/ExtendedFab.css +24 -0
  28. package/components/ExtendedFab.js +11 -0
  29. package/components/Fab.css +23 -0
  30. package/components/Fab.js +26 -0
  31. package/components/FilterChip.css +80 -0
  32. package/components/FilterChip.js +51 -0
  33. package/components/Headline.css +14 -0
  34. package/components/Headline.js +33 -0
  35. package/components/Icon.css +76 -0
  36. package/components/Icon.js +174 -0
  37. package/components/IconButton.css +151 -0
  38. package/components/IconButton.js +65 -0
  39. package/components/Input.js +16 -0
  40. package/components/Label.css +14 -0
  41. package/components/Label.js +7 -0
  42. package/components/Layout.css +19 -0
  43. package/components/Layout.js +12 -0
  44. package/components/List.css +12 -0
  45. package/components/List.js +17 -0
  46. package/components/ListItem.css +224 -0
  47. package/components/ListItem.js +112 -0
  48. package/components/ListOption.css +34 -0
  49. package/components/ListOption.js +122 -0
  50. package/components/ListSelect.css +9 -0
  51. package/components/ListSelect.js +206 -0
  52. package/components/Menu.css +171 -0
  53. package/components/Menu.js +470 -0
  54. package/components/MenuItem.css +53 -0
  55. package/components/MenuItem.js +215 -0
  56. package/components/Nav.css +17 -0
  57. package/components/Nav.js +23 -0
  58. package/components/NavBar.css +34 -0
  59. package/components/NavBar.js +88 -0
  60. package/components/NavBarItem.css +41 -0
  61. package/components/NavBarItem.js +7 -0
  62. package/components/NavDrawer.css +31 -0
  63. package/components/NavDrawer.js +13 -0
  64. package/components/NavDrawerItem.css +42 -0
  65. package/components/NavDrawerItem.js +12 -0
  66. package/components/NavItem.css +181 -0
  67. package/components/NavItem.js +83 -0
  68. package/components/NavRail.css +47 -0
  69. package/components/NavRail.js +17 -0
  70. package/components/NavRailItem.css +25 -0
  71. package/components/NavRailItem.js +7 -0
  72. package/components/Option.js +91 -0
  73. package/components/Outline.css +138 -0
  74. package/components/Pane.css +261 -0
  75. package/components/Pane.js +21 -0
  76. package/components/Progress.css +74 -0
  77. package/components/Progress.js +67 -0
  78. package/components/ProgressCircle.css +226 -0
  79. package/components/ProgressLine.css +155 -0
  80. package/components/Radio.css +83 -0
  81. package/components/Radio.js +42 -0
  82. package/components/RadioIcon.css +73 -0
  83. package/components/RadioIcon.js +37 -0
  84. package/components/Ripple.css +74 -0
  85. package/components/Ripple.js +114 -0
  86. package/components/SegmentedButton.css +94 -0
  87. package/components/SegmentedButton.js +49 -0
  88. package/components/SegmentedButtonGroup.css +12 -0
  89. package/components/SegmentedButtonGroup.js +44 -0
  90. package/components/Select.css +52 -0
  91. package/components/Select.js +71 -0
  92. package/components/Shape.css +132 -0
  93. package/components/Shape.js +25 -0
  94. package/components/Slider.css +306 -0
  95. package/components/Slider.js +206 -0
  96. package/components/Snackbar.css +80 -0
  97. package/components/Snackbar.js +75 -0
  98. package/components/Surface.css +10 -0
  99. package/components/Surface.js +23 -0
  100. package/components/Switch.css +63 -0
  101. package/components/Switch.js +127 -0
  102. package/components/SwitchIcon.css +177 -0
  103. package/components/SwitchIcon.js +89 -0
  104. package/components/SwitchIconAnimations.css +89 -0
  105. package/components/Tab.css +85 -0
  106. package/components/Tab.js +103 -0
  107. package/components/TabContent.js +151 -0
  108. package/components/TabList.css +129 -0
  109. package/components/TabList.js +309 -0
  110. package/components/TabPanel.js +37 -0
  111. package/components/TextArea.css +93 -0
  112. package/components/TextArea.js +229 -0
  113. package/components/Title.css +14 -0
  114. package/components/Title.js +15 -0
  115. package/components/Tooltip.css +40 -0
  116. package/components/Tooltip.js +22 -0
  117. package/components/TopAppBar.css +209 -0
  118. package/components/TopAppBar.js +201 -0
  119. package/core/Composition.js +988 -0
  120. package/core/CustomElement.js +844 -0
  121. package/core/ICustomElement.d.ts +288 -0
  122. package/core/ICustomElement.js +1 -0
  123. package/core/css.js +51 -0
  124. package/core/customTypes.js +125 -0
  125. package/core/dom.js +56 -245
  126. package/core/identify.js +40 -0
  127. package/core/observe.js +410 -0
  128. package/core/template.js +121 -0
  129. package/core/typings.d.ts +135 -0
  130. package/core/typings.js +1 -0
  131. package/mixins/AriaReflectorMixin.js +42 -0
  132. package/mixins/AriaToolbarMixin.js +13 -0
  133. package/mixins/ControlMixin.css +57 -0
  134. package/mixins/ControlMixin.js +212 -0
  135. package/mixins/DensityMixin.css +40 -0
  136. package/mixins/DensityMixin.js +11 -0
  137. package/mixins/FlexableMixin.css +79 -0
  138. package/mixins/FlexableMixin.js +32 -0
  139. package/mixins/FormAssociatedMixin.js +170 -0
  140. package/mixins/InputMixin.js +335 -0
  141. package/mixins/KeyboardNavMixin.js +244 -0
  142. package/mixins/RTLObserverMixin.js +35 -0
  143. package/mixins/ResizeObserverMixin.js +38 -0
  144. package/mixins/RippleMixin.css +12 -0
  145. package/mixins/RippleMixin.js +115 -0
  146. package/mixins/ScrollListenerMixin.js +100 -0
  147. package/mixins/ShapeMixin.css +135 -0
  148. package/mixins/ShapeMixin.js +31 -0
  149. package/mixins/StateMixin.css +82 -0
  150. package/mixins/StateMixin.js +114 -0
  151. package/mixins/SurfaceMixin.css +150 -0
  152. package/mixins/SurfaceMixin.js +32 -0
  153. package/mixins/TextFieldMixin.css +657 -0
  154. package/mixins/TextFieldMixin.js +121 -0
  155. package/mixins/ThemableMixin.css +204 -0
  156. package/mixins/ThemableMixin.js +16 -0
  157. package/mixins/TooltipTriggerMixin.css +27 -0
  158. package/mixins/TooltipTriggerMixin.js +366 -0
  159. package/mixins/TouchTargetMixin.css +26 -0
  160. package/mixins/TouchTargetMixin.js +9 -0
  161. package/package.json +57 -41
  162. package/theming/index.js +594 -0
  163. package/theming/loader.js +24 -0
  164. package/utils/cli.js +11 -0
  165. package/utils/color_keywords.js +151 -0
  166. package/utils/hct/Cam16.js +298 -0
  167. package/utils/hct/CorePalette.js +84 -0
  168. package/utils/hct/Hct.js +172 -0
  169. package/utils/hct/Scheme.js +587 -0
  170. package/utils/hct/TonalPalette.js +68 -0
  171. package/utils/hct/ViewingConditions.js +136 -0
  172. package/utils/hct/blend.js +93 -0
  173. package/utils/hct/colorUtils.js +302 -0
  174. package/utils/hct/hctSolver.js +559 -0
  175. package/utils/hct/helper.js +182 -0
  176. package/utils/hct/mathUtils.js +153 -0
  177. package/utils/jsonMergePatch.js +100 -0
  178. package/utils/jsx-runtime.js +101 -0
  179. package/utils/popup.js +117 -0
  180. package/utils/svg.js +129 -0
  181. package/.browserslistrc +0 -3
  182. package/.eslintrc.json +0 -153
  183. package/.stylelintrc.json +0 -600
  184. package/.vscode/launch.json +0 -31
  185. package/.vscode/settings.json +0 -3
  186. package/.vscode/tasks.json +0 -32
  187. package/CHANGELOG.md +0 -24
  188. package/CODE_OF_CONDUCT.md +0 -46
  189. package/adapters/datatable/column.js +0 -203
  190. package/adapters/datatable/index.js +0 -972
  191. package/adapters/dom/index.js +0 -601
  192. package/adapters/list/index.js +0 -69
  193. package/adapters/search/index.js +0 -521
  194. package/components/appbar/_spec.scss +0 -225
  195. package/components/appbar/_theme.scss +0 -0
  196. package/components/appbar/index.scss +0 -2
  197. package/components/banner/_spec.scss +0 -118
  198. package/components/banner/_theme.scss +0 -0
  199. package/components/banner/index.scss +0 -2
  200. package/components/bottomnav/README.md +0 -85
  201. package/components/bottomnav/_spec.scss +0 -157
  202. package/components/bottomnav/_theme.scss +0 -0
  203. package/components/bottomnav/index.js +0 -122
  204. package/components/bottomnav/index.scss +0 -2
  205. package/components/bottomnav/item.js +0 -89
  206. package/components/button/README.md +0 -61
  207. package/components/button/_spec.scss +0 -161
  208. package/components/button/_theme.scss +0 -65
  209. package/components/button/index.eta +0 -32
  210. package/components/button/index.js +0 -43
  211. package/components/button/index.pug +0 -18
  212. package/components/button/index.scss +0 -2
  213. package/components/card/_spec.scss +0 -249
  214. package/components/card/_theme.scss +0 -0
  215. package/components/card/index.scss +0 -2
  216. package/components/chip/_spec.scss +0 -134
  217. package/components/chip/_theme.scss +0 -177
  218. package/components/chip/index.js +0 -21
  219. package/components/chip/index.scss +0 -2
  220. package/components/chip/item.js +0 -20
  221. package/components/datatable/_spec.scss +0 -288
  222. package/components/datatable/_theme.scss +0 -154
  223. package/components/datatable/cell.js +0 -45
  224. package/components/datatable/columnheader.js +0 -47
  225. package/components/datatable/index.js +0 -388
  226. package/components/datatable/index.scss +0 -2
  227. package/components/datatable/row.js +0 -49
  228. package/components/datatable/rowheader.js +0 -18
  229. package/components/dialog/_spec.scss +0 -213
  230. package/components/dialog/_theme.scss +0 -0
  231. package/components/dialog/index.js +0 -627
  232. package/components/dialog/index.scss +0 -2
  233. package/components/divider/_spec.scss +0 -13
  234. package/components/divider/_theme.scss +0 -0
  235. package/components/divider/index.scss +0 -2
  236. package/components/elevation/_spec.scss +0 -9
  237. package/components/elevation/_theme.scss +0 -0
  238. package/components/elevation/index.scss +0 -2
  239. package/components/fab/_spec.scss +0 -222
  240. package/components/fab/_theme.scss +0 -0
  241. package/components/fab/index.js +0 -103
  242. package/components/fab/index.scss +0 -2
  243. package/components/grid/_spec.scss +0 -312
  244. package/components/grid/_theme.scss +0 -0
  245. package/components/grid/index.scss +0 -2
  246. package/components/layout/_mixins.scss +0 -33
  247. package/components/layout/_spec.scss +0 -1012
  248. package/components/layout/_theme.scss +0 -44
  249. package/components/layout/index.js +0 -464
  250. package/components/layout/index.scss +0 -2
  251. package/components/list/_spec.scss +0 -397
  252. package/components/list/_theme.scss +0 -111
  253. package/components/list/content.js +0 -110
  254. package/components/list/index.js +0 -260
  255. package/components/list/index.scss +0 -2
  256. package/components/list/item.js +0 -170
  257. package/components/list/secondary.js +0 -46
  258. package/components/menu/_spec.scss +0 -362
  259. package/components/menu/_theme.scss +0 -0
  260. package/components/menu/index.js +0 -721
  261. package/components/menu/index.scss +0 -2
  262. package/components/menu/item.js +0 -239
  263. package/components/progress/_spec.scss +0 -147
  264. package/components/progress/_theme.scss +0 -0
  265. package/components/progress/index.js +0 -36
  266. package/components/progress/index.scss +0 -2
  267. package/components/selection/_spec.scss +0 -386
  268. package/components/selection/_theme.scss +0 -166
  269. package/components/selection/index.eta +0 -60
  270. package/components/selection/index.js +0 -76
  271. package/components/selection/index.pug +0 -30
  272. package/components/selection/index.scss +0 -2
  273. package/components/selection/input.js +0 -56
  274. package/components/selection/radiogroup.js +0 -47
  275. package/components/slider/_spec.scss +0 -64
  276. package/components/slider/_theme.scss +0 -0
  277. package/components/slider/index.scss +0 -2
  278. package/components/snackbar/_spec.scss +0 -195
  279. package/components/snackbar/_theme.scss +0 -0
  280. package/components/snackbar/index.js +0 -344
  281. package/components/snackbar/index.scss +0 -2
  282. package/components/tab/_spec.scss +0 -235
  283. package/components/tab/_theme.scss +0 -0
  284. package/components/tab/content.js +0 -205
  285. package/components/tab/index.js +0 -260
  286. package/components/tab/index.scss +0 -2
  287. package/components/tab/item.js +0 -89
  288. package/components/tab/list.js +0 -210
  289. package/components/tab/panel.js +0 -54
  290. package/components/template/_theme.scss +0 -27
  291. package/components/textfield/README.md +0 -179
  292. package/components/textfield/_mixins.scss +0 -52
  293. package/components/textfield/_spec.scss +0 -809
  294. package/components/textfield/_theme.scss +0 -299
  295. package/components/textfield/index.eta +0 -74
  296. package/components/textfield/index.js +0 -168
  297. package/components/textfield/index.pug +0 -30
  298. package/components/textfield/index.scss +0 -2
  299. package/components/tooltip/_spec.scss +0 -188
  300. package/components/tooltip/_theme.scss +0 -0
  301. package/components/tooltip/index.scss +0 -2
  302. package/components/type/_spec.scss +0 -224
  303. package/components/type/_theme.scss +0 -0
  304. package/components/type/index.scss +0 -2
  305. package/core/_breakpoint.scss +0 -189
  306. package/core/_elevation.scss +0 -38
  307. package/core/_length.scss +0 -9
  308. package/core/_motion.scss +0 -31
  309. package/core/_platform.scss +0 -34
  310. package/core/_type.scss +0 -127
  311. package/core/aria/attributes.js +0 -141
  312. package/core/aria/button.js +0 -50
  313. package/core/aria/keyboard.js +0 -93
  314. package/core/aria/rovingtabindex.js +0 -178
  315. package/core/aria/tab.js +0 -60
  316. package/core/color/_spec.scss +0 -0
  317. package/core/color/_theme.scss +0 -390
  318. package/core/color/index.scss +0 -2
  319. package/core/document/index.js +0 -39
  320. package/core/overlay/_spec.scss +0 -31
  321. package/core/overlay/_theme.scss +0 -171
  322. package/core/overlay/index.js +0 -108
  323. package/core/overlay/index.scss +0 -2
  324. package/core/ripple/_spec.scss +0 -197
  325. package/core/ripple/_theme.scss +0 -40
  326. package/core/ripple/index.js +0 -294
  327. package/core/ripple/index.scss +0 -2
  328. package/core/theme/_config.scss +0 -2
  329. package/core/theme/_mixins.scss +0 -172
  330. package/core/theme/_palettes.scss +0 -406
  331. package/core/theme/_variables.scss +0 -24
  332. package/core/theme/index.js +0 -50
  333. package/core/throttler.js +0 -42
  334. package/core/transition/index.js +0 -468
  335. package/docs/_flex.scss +0 -22
  336. package/docs/_menuoptions.js +0 -183
  337. package/docs/_mixins.pug +0 -155
  338. package/docs/_partials/_androidnavbar.eta +0 -5
  339. package/docs/_partials/_androidstatusbar.eta +0 -13
  340. package/docs/_partials/_appbar.eta +0 -29
  341. package/docs/_partials/_buttontest.eta +0 -31
  342. package/docs/_partials/_header.eta +0 -149
  343. package/docs/_partials/_navlistitem.eta +0 -16
  344. package/docs/_partials/_target.eta +0 -1
  345. package/docs/_sample-utils.js +0 -93
  346. package/docs/_storage.js +0 -33
  347. package/docs/docs.scss +0 -295
  348. package/docs/index.eta +0 -16
  349. package/docs/index.js +0 -0
  350. package/docs/pages/appbar.eta +0 -114
  351. package/docs/pages/appbar.js +0 -0
  352. package/docs/pages/appbar.pug +0 -78
  353. package/docs/pages/bottomnav.eta +0 -188
  354. package/docs/pages/bottomnav.js +0 -115
  355. package/docs/pages/bottomnav.pug +0 -137
  356. package/docs/pages/button.eta +0 -124
  357. package/docs/pages/button.js +0 -224
  358. package/docs/pages/button.pug +0 -121
  359. package/docs/pages/card.eta +0 -90
  360. package/docs/pages/card.js +0 -177
  361. package/docs/pages/card.pug +0 -74
  362. package/docs/pages/chip.eta +0 -122
  363. package/docs/pages/chip.js +0 -82
  364. package/docs/pages/chip.pug +0 -91
  365. package/docs/pages/color.eta +0 -143
  366. package/docs/pages/color.js +0 -262
  367. package/docs/pages/color.pug +0 -121
  368. package/docs/pages/datatable.eta +0 -323
  369. package/docs/pages/datatable.js +0 -164
  370. package/docs/pages/datatable.pug +0 -283
  371. package/docs/pages/dialog.eta +0 -186
  372. package/docs/pages/dialog.js +0 -177
  373. package/docs/pages/dialog.pug +0 -132
  374. package/docs/pages/dom.eta +0 -26
  375. package/docs/pages/dom.js +0 -143
  376. package/docs/pages/dom.pug +0 -22
  377. package/docs/pages/elevation.eta +0 -35
  378. package/docs/pages/elevation.js +0 -0
  379. package/docs/pages/elevation.pug +0 -25
  380. package/docs/pages/fab.eta +0 -99
  381. package/docs/pages/fab.js +0 -44
  382. package/docs/pages/fab.pug +0 -66
  383. package/docs/pages/grid.eta +0 -135
  384. package/docs/pages/grid.js +0 -128
  385. package/docs/pages/grid.pug +0 -95
  386. package/docs/pages/layout.eta +0 -8
  387. package/docs/pages/layout.js +0 -0
  388. package/docs/pages/layout.pug +0 -7
  389. package/docs/pages/list.eta +0 -465
  390. package/docs/pages/list.js +0 -9
  391. package/docs/pages/list.pug +0 -326
  392. package/docs/pages/menu.eta +0 -276
  393. package/docs/pages/menu.js +0 -217
  394. package/docs/pages/menu.pug +0 -205
  395. package/docs/pages/overlay.eta +0 -69
  396. package/docs/pages/overlay.js +0 -4
  397. package/docs/pages/overlay.pug +0 -55
  398. package/docs/pages/progress.eta +0 -23
  399. package/docs/pages/progress.js +0 -12
  400. package/docs/pages/progress.pug +0 -16
  401. package/docs/pages/ripple.eta +0 -27
  402. package/docs/pages/ripple.js +0 -4
  403. package/docs/pages/ripple.pug +0 -21
  404. package/docs/pages/search.eta +0 -246
  405. package/docs/pages/search.js +0 -243
  406. package/docs/pages/search.pug +0 -165
  407. package/docs/pages/selection.eta +0 -111
  408. package/docs/pages/selection.js +0 -13
  409. package/docs/pages/selection.pug +0 -74
  410. package/docs/pages/slider.eta +0 -23
  411. package/docs/pages/slider.js +0 -0
  412. package/docs/pages/slider.pug +0 -17
  413. package/docs/pages/snackbar.eta +0 -83
  414. package/docs/pages/snackbar.js +0 -158
  415. package/docs/pages/snackbar.pug +0 -60
  416. package/docs/pages/tab.eta +0 -421
  417. package/docs/pages/tab.js +0 -151
  418. package/docs/pages/tab.pug +0 -304
  419. package/docs/pages/textfield.eta +0 -486
  420. package/docs/pages/textfield.js +0 -254
  421. package/docs/pages/textfield.pug +0 -360
  422. package/docs/pages/tooltip.eta +0 -94
  423. package/docs/pages/tooltip.js +0 -0
  424. package/docs/pages/tooltip.pug +0 -78
  425. package/docs/pages/transition.eta +0 -117
  426. package/docs/pages/transition.js +0 -54
  427. package/docs/pages/transition.pug +0 -76
  428. package/docs/pages/type.eta +0 -31
  429. package/docs/pages/type.js +0 -0
  430. package/docs/pages/type.pug +0 -29
  431. package/docs/postrender.js +0 -39
  432. package/docs/prerender.js +0 -16
  433. package/docs/pwa/_dialogs.eta +0 -143
  434. package/docs/pwa/_dialogs.pug +0 -96
  435. package/docs/pwa/_menus.eta +0 -16
  436. package/docs/pwa/_menus.pug +0 -11
  437. package/docs/pwa/pwa-prerender.js +0 -3
  438. package/docs/pwa/pwa.eta +0 -480
  439. package/docs/pwa/pwa.js +0 -306
  440. package/docs/pwa/pwa.pug +0 -325
  441. package/docs/pwa/pwa.scss +0 -26
  442. package/docs/spec.scss +0 -26
  443. package/docs/themes/_component-themes.scss +0 -26
  444. package/docs/themes/theme-colored-fallbacks.scss +0 -17
  445. package/docs/themes/theme-colored.scss +0 -17
  446. package/docs/themes/theme-default-fallbacks.scss +0 -17
  447. package/docs/themes/theme-default.scss +0 -17
  448. package/jsconfig.json +0 -12
  449. package/scripts/deploy-docs.sh +0 -9
  450. package/templates/index.eta +0 -2
  451. package/templates/index.pug +0 -3
  452. package/webpack.config.cjs +0 -257
@@ -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
+ }