@ixfx/components 0.4.2 → 0.4.4

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 (225) hide show
  1. package/bundle/index.d.ts +435 -1193
  2. package/bundle/index.d.ts.map +1 -1
  3. package/bundle/index.js +7765 -20670
  4. package/bundle/index.js.map +1 -1
  5. package/dist/ac-text.d.ts +12 -7
  6. package/dist/ac-text.d.ts.map +1 -1
  7. package/dist/ac-text.js +2 -3
  8. package/dist/ac-text.js.map +1 -1
  9. package/dist/{button-C3fLMKUv.js → button-DxYee1ZH.js} +2 -2
  10. package/dist/{button-C3fLMKUv.js.map → button-DxYee1ZH.js.map} +1 -1
  11. package/dist/button.d.ts +1 -2
  12. package/dist/button.d.ts.map +1 -1
  13. package/dist/button.js +1 -2
  14. package/dist/checkbox.d.ts +0 -1
  15. package/dist/checkbox.d.ts.map +1 -1
  16. package/dist/checkbox.js +1 -1
  17. package/dist/checkbox.js.map +1 -1
  18. package/dist/{colour-picker-0sgAha1T.js → colour-picker-BacNRabo.js} +14 -16
  19. package/dist/colour-picker-BacNRabo.js.map +1 -0
  20. package/dist/colour-picker.d.ts +1 -1
  21. package/dist/colour-picker.js +1 -1
  22. package/dist/crumbs.d.ts +5 -2
  23. package/dist/crumbs.d.ts.map +1 -1
  24. package/dist/crumbs.js +45 -20
  25. package/dist/crumbs.js.map +1 -1
  26. package/dist/data-display.d.ts +1 -2
  27. package/dist/data-display.d.ts.map +1 -1
  28. package/dist/data-display.js +25 -23
  29. package/dist/data-display.js.map +1 -1
  30. package/dist/{data-provider-DgI909FP.js → data-provider-35TyWclX.js} +2 -2
  31. package/dist/data-provider-35TyWclX.js.map +1 -0
  32. package/dist/{decorate-DdjvVHS-.js → decorate-VRK8rslU.js} +2 -2
  33. package/dist/{decorate-DdjvVHS-.js.map → decorate-VRK8rslU.js.map} +1 -1
  34. package/dist/editable-label.d.ts +1 -2
  35. package/dist/editable-label.d.ts.map +1 -1
  36. package/dist/editable-label.js +1 -1
  37. package/dist/editable-label.js.map +1 -1
  38. package/dist/{hex-editor-WZrjRtvL.js → hex-editor-Bk6rxhfg.js} +9 -11
  39. package/dist/hex-editor-Bk6rxhfg.js.map +1 -0
  40. package/dist/{hex-editor-CMIxtNgT.d.ts → hex-editor-Caq8vNQk.d.ts} +2 -3
  41. package/dist/hex-editor-Caq8vNQk.d.ts.map +1 -0
  42. package/dist/hex.d.ts +1 -1
  43. package/dist/hex.js +1 -1
  44. package/dist/highlight-B-eQrhhb.js.map +1 -1
  45. package/dist/{icon-Ndo40kNO.js → icon-B22XVlCt.js} +6 -4
  46. package/dist/{icon-Ndo40kNO.js.map → icon-B22XVlCt.js.map} +1 -1
  47. package/dist/{icon-epZd-JIO.d.ts → icon-DpA9x2Ve.d.ts} +3 -4
  48. package/dist/icon-DpA9x2Ve.d.ts.map +1 -0
  49. package/dist/icons.d.ts +2 -2
  50. package/dist/icons.js +1 -1
  51. package/dist/{incr-search-CeERfijK.js → incr-search-2pz21xtR.js} +9 -6
  52. package/dist/incr-search-2pz21xtR.js.map +1 -0
  53. package/dist/incr-search.d.ts +1 -1
  54. package/dist/incr-search.js +1 -1
  55. package/dist/{index-CowKi2mo.d.ts → index-BeuCXtiO.d.ts} +3 -4
  56. package/dist/index-BeuCXtiO.d.ts.map +1 -0
  57. package/dist/{index-D87kRcEs.d.ts → index-BtGFYfaK.d.ts} +2 -1
  58. package/dist/index-BtGFYfaK.d.ts.map +1 -0
  59. package/dist/{index-JuEVfmr-.d.ts → index-CoqtMSd9.d.ts} +6 -4
  60. package/dist/index-CoqtMSd9.d.ts.map +1 -0
  61. package/dist/{index-9fGVAg1d.d.ts → index-Cxwxtj6g.d.ts} +3 -3
  62. package/dist/index-Cxwxtj6g.d.ts.map +1 -0
  63. package/dist/index-D_ftz_IT.d.ts +184 -0
  64. package/dist/index-D_ftz_IT.d.ts.map +1 -0
  65. package/dist/{index-_RTQSKHi.d.ts → index-DfEkTGvT.d.ts} +11 -11
  66. package/dist/index-DfEkTGvT.d.ts.map +1 -0
  67. package/dist/index.d.ts +45 -30
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +304 -3075
  70. package/dist/index.js.map +1 -1
  71. package/dist/keyboard-B5xD7Fz-.js +36 -0
  72. package/dist/keyboard-B5xD7Fz-.js.map +1 -0
  73. package/dist/{labelled-input-base-Cz6qE6Dk.d.ts → labelled-input-base-DiTme1JO.d.ts} +2 -3
  74. package/dist/labelled-input-base-DiTme1JO.d.ts.map +1 -0
  75. package/dist/{labelled-input-base-9K_w3oLj.js → labelled-input-base-hoKGwyKT.js} +2 -2
  76. package/dist/{labelled-input-base-9K_w3oLj.js.map → labelled-input-base-hoKGwyKT.js.map} +1 -1
  77. package/dist/labelled-radial-input.d.ts +6 -5
  78. package/dist/labelled-radial-input.d.ts.map +1 -1
  79. package/dist/labelled-radial-input.js +7 -3
  80. package/dist/labelled-radial-input.js.map +1 -1
  81. package/dist/labelled-range-input.d.ts +1 -1
  82. package/dist/labelled-range-input.js +27 -3
  83. package/dist/labelled-range-input.js.map +1 -1
  84. package/dist/led.d.ts +1 -2
  85. package/dist/led.d.ts.map +1 -1
  86. package/dist/led.js +1 -1
  87. package/dist/led.js.map +1 -1
  88. package/dist/{menu-vjoiHZ13.js → menu-g6yd7ddN.js} +8 -9
  89. package/dist/menu-g6yd7ddN.js.map +1 -0
  90. package/dist/{menu-item-COx-Azgj.d.ts → menu-item-DSyf9f_L.d.ts} +4 -4
  91. package/dist/menu-item-DSyf9f_L.d.ts.map +1 -0
  92. package/dist/{menu-item-BrIuORYD.js → menu-item-NUKwJ4s5.js} +3 -4
  93. package/dist/{menu-item-BrIuORYD.js.map → menu-item-NUKwJ4s5.js.map} +1 -1
  94. package/dist/menu.d.ts +2 -2
  95. package/dist/menu.js +2 -2
  96. package/dist/miller.d.ts +8 -5
  97. package/dist/miller.d.ts.map +1 -1
  98. package/dist/miller.js +22 -24
  99. package/dist/miller.js.map +1 -1
  100. package/dist/narrowed-text.d.ts +7 -3
  101. package/dist/narrowed-text.d.ts.map +1 -1
  102. package/dist/narrowed-text.js +73 -47
  103. package/dist/narrowed-text.js.map +1 -1
  104. package/dist/panel.d.ts +1 -1
  105. package/dist/panel.d.ts.map +1 -1
  106. package/dist/panel.js +2 -2
  107. package/dist/panel.js.map +1 -1
  108. package/dist/plots.d.ts +2 -2
  109. package/dist/plots.js +1 -1
  110. package/dist/polar-pad.d.ts +15 -3
  111. package/dist/polar-pad.d.ts.map +1 -1
  112. package/dist/polar-pad.js +64 -11
  113. package/dist/polar-pad.js.map +1 -1
  114. package/dist/{radial-input-CpQPs1Mp.d.ts → radial-input-DXMN55Nz.d.ts} +6 -4
  115. package/dist/radial-input-DXMN55Nz.d.ts.map +1 -0
  116. package/dist/{radial-input-DZ7eQCcM.js → radial-input-DxCrt_NE.js} +41 -19
  117. package/dist/radial-input-DxCrt_NE.js.map +1 -0
  118. package/dist/radial-input.d.ts +1 -1
  119. package/dist/radial-input.js +1 -1
  120. package/dist/range-input.d.ts +15 -4
  121. package/dist/range-input.d.ts.map +1 -1
  122. package/dist/range-input.js +23 -2
  123. package/dist/range-input.js.map +1 -1
  124. package/dist/range.d.ts +15 -4
  125. package/dist/range.d.ts.map +1 -1
  126. package/dist/range.js +23 -2
  127. package/dist/range.js.map +1 -1
  128. package/dist/selecthorizontal.d.ts +1 -2
  129. package/dist/selecthorizontal.d.ts.map +1 -1
  130. package/dist/selecthorizontal.js +1 -1
  131. package/dist/selecthorizontal.js.map +1 -1
  132. package/dist/slider-input-DFpG23bS.js +1592 -0
  133. package/dist/slider-input-DFpG23bS.js.map +1 -0
  134. package/dist/slider-input-XppH3vcy.d.ts +160 -0
  135. package/dist/slider-input-XppH3vcy.d.ts.map +1 -0
  136. package/dist/slider-input.d.ts +2 -0
  137. package/dist/slider-input.js +2 -0
  138. package/dist/snap-container.d.ts +1 -2
  139. package/dist/snap-container.d.ts.map +1 -1
  140. package/dist/snap-container.js +6 -5
  141. package/dist/snap-container.js.map +1 -1
  142. package/dist/split-layout.d.ts +1 -2
  143. package/dist/split-layout.d.ts.map +1 -1
  144. package/dist/split-layout.js +6 -4
  145. package/dist/split-layout.js.map +1 -1
  146. package/dist/swipe.d.ts +12 -2
  147. package/dist/swipe.d.ts.map +1 -1
  148. package/dist/swipe.js +22 -3
  149. package/dist/swipe.js.map +1 -1
  150. package/dist/{tab-list-DLzb-m-I.d.ts → tab-list-BohmbvqF.d.ts} +14 -5
  151. package/dist/tab-list-BohmbvqF.d.ts.map +1 -0
  152. package/dist/tab-list-DzknpdSo.js +592 -0
  153. package/dist/tab-list-DzknpdSo.js.map +1 -0
  154. package/dist/tabs.d.ts +2 -2
  155. package/dist/tabs.js +1 -208
  156. package/dist/{tickled-controller-BjYCzGrU.d.ts → tickled-controller-BF2Ea0DE.d.ts} +2 -31
  157. package/dist/tickled-controller-BF2Ea0DE.d.ts.map +1 -0
  158. package/dist/tickled-styles-fNDdqf6l.js.map +1 -1
  159. package/dist/{timeline-2OFtN4Ta.js → timeline-B2fgDL4U.js} +37 -1438
  160. package/dist/timeline-B2fgDL4U.js.map +1 -0
  161. package/dist/timeline.d.ts +1 -1
  162. package/dist/timeline.js +1 -1
  163. package/dist/{tooltip-RGVIwHrZ.d.ts → tooltip-BlvBUQxx.d.ts} +3 -3
  164. package/dist/tooltip-BlvBUQxx.d.ts.map +1 -0
  165. package/dist/{tree-D84RUgFC.js → tree-BnvzhsAw.js} +8 -9
  166. package/dist/tree-BnvzhsAw.js.map +1 -0
  167. package/dist/{tree-component-BaCSPWg1.d.ts → tree-component-DCmmKZ4j.d.ts} +8 -124
  168. package/dist/tree-component-DCmmKZ4j.d.ts.map +1 -0
  169. package/dist/tree.d.ts +10 -4
  170. package/dist/tree.d.ts.map +1 -1
  171. package/dist/tree.js +1 -1
  172. package/dist/types-DO3gt5vg.d.ts +130 -0
  173. package/dist/types-DO3gt5vg.d.ts.map +1 -0
  174. package/dist/wheel-nudge-BlSCe_hD.js +86 -0
  175. package/dist/wheel-nudge-BlSCe_hD.js.map +1 -0
  176. package/dist/wheel-nudge-DGrNzWuE.d.ts +29 -0
  177. package/dist/wheel-nudge-DGrNzWuE.d.ts.map +1 -0
  178. package/dist/{xy-axis-CEI7ojks.d.ts → xy-axis-5KhVTNoX.d.ts} +75 -29
  179. package/dist/xy-axis-5KhVTNoX.d.ts.map +1 -0
  180. package/dist/xy-axis-CxHC8z5E.js +1849 -0
  181. package/dist/xy-axis-CxHC8z5E.js.map +1 -0
  182. package/dist/xy-pad.d.ts +13 -2
  183. package/dist/xy-pad.d.ts.map +1 -1
  184. package/dist/xy-pad.js +47 -6
  185. package/dist/xy-pad.js.map +1 -1
  186. package/docs-user/radial-input.md +2 -2
  187. package/package.json +22 -21
  188. package/dist/colour-C3MQIjFJ-vRCdr8W-.js +0 -3732
  189. package/dist/colour-C3MQIjFJ-vRCdr8W-.js.map +0 -1
  190. package/dist/colour-picker-0sgAha1T.js.map +0 -1
  191. package/dist/data-provider-DgI909FP.js.map +0 -1
  192. package/dist/dist-CA13FvMn.js +0 -980
  193. package/dist/dist-CA13FvMn.js.map +0 -1
  194. package/dist/hex-editor-CMIxtNgT.d.ts.map +0 -1
  195. package/dist/hex-editor-WZrjRtvL.js.map +0 -1
  196. package/dist/icon-epZd-JIO.d.ts.map +0 -1
  197. package/dist/incr-search-CeERfijK.js.map +0 -1
  198. package/dist/index-9fGVAg1d.d.ts.map +0 -1
  199. package/dist/index-CowKi2mo.d.ts.map +0 -1
  200. package/dist/index-D87kRcEs.d.ts.map +0 -1
  201. package/dist/index-DgXpCg_G.d.ts +0 -1244
  202. package/dist/index-DgXpCg_G.d.ts.map +0 -1
  203. package/dist/index-JuEVfmr-.d.ts.map +0 -1
  204. package/dist/index-_RTQSKHi.d.ts.map +0 -1
  205. package/dist/keyboard-CimiEskD.js +0 -20
  206. package/dist/keyboard-CimiEskD.js.map +0 -1
  207. package/dist/labelled-input-base-Cz6qE6Dk.d.ts.map +0 -1
  208. package/dist/menu-item-COx-Azgj.d.ts.map +0 -1
  209. package/dist/menu-vjoiHZ13.js.map +0 -1
  210. package/dist/radial-input-CpQPs1Mp.d.ts.map +0 -1
  211. package/dist/radial-input-DZ7eQCcM.js.map +0 -1
  212. package/dist/tab-list-DLzb-m-I.d.ts.map +0 -1
  213. package/dist/tabs.js.map +0 -1
  214. package/dist/tickled-controller-BjYCzGrU.d.ts.map +0 -1
  215. package/dist/timeline-2OFtN4Ta.js.map +0 -1
  216. package/dist/tooltip-RGVIwHrZ.d.ts.map +0 -1
  217. package/dist/tree-D84RUgFC.js.map +0 -1
  218. package/dist/tree-component-BaCSPWg1.d.ts.map +0 -1
  219. package/dist/types-DSfbtHs3.d.ts +0 -8
  220. package/dist/types-DSfbtHs3.d.ts.map +0 -1
  221. package/dist/xy-axis-CEI7ojks.d.ts.map +0 -1
  222. package/dist/xy-axis-DbPezP6A.js +0 -7849
  223. package/dist/xy-axis-DbPezP6A.js.map +0 -1
  224. /package/bundle/{chunk-D7D4PA-g.js → rolldown-runtime-D7D4PA-g.js} +0 -0
  225. /package/dist/{chunk-D7D4PA-g.js → rolldown-runtime-D7D4PA-g.js} +0 -0
@@ -1,3732 +0,0 @@
1
- import { C as resultThrow, S as percentTest, a as movingAverageLight, b as numberInclusiveRangeTest, g as errorResult, i as interpolate, m as pairwise, t as clamp, u as scaleClamped, x as numberTest } from "./dist-CA13FvMn.js";
2
- //#region node_modules/.pnpm/@ixfx+visual@0.56.13/node_modules/@ixfx/visual/dist/chunk-pbuEa-1d.js
3
- var __defProp$1 = Object.defineProperty;
4
- var __exportAll = (all, no_symbols) => {
5
- let target = {};
6
- for (var name in all) __defProp$1(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- if (!no_symbols) __defProp$1(target, Symbol.toStringTag, { value: "Module" });
11
- return target;
12
- };
13
- //#endregion
14
- //#region node_modules/.pnpm/@ixfx+geometry@0.56.13/node_modules/@ixfx/geometry/dist/guard-hlhkAOMZ.js
15
- /**
16
- * Returns true if xy (and z, if present) are _null_.
17
- * @param p
18
- * @returns True if all props are null
19
- */
20
- function isNull(p) {
21
- if (isPoint3d(p)) {
22
- if (p.z !== null) return false;
23
- }
24
- return p.x === null && p.y === null;
25
- }
26
- /***
27
- * Returns true if either x, y, z isNaN.
28
- */
29
- function isNaN(p) {
30
- if (isPoint3d(p)) {
31
- if (!Number.isNaN(p.z)) return false;
32
- }
33
- return Number.isNaN(p.x) || Number.isNaN(p.y);
34
- }
35
- function pointTest(p, name = `Point`, extraInfo = ``) {
36
- if (p === void 0) return errorResult(`'${name}' is undefined. Expected {x,y} got ${JSON.stringify(p)}`, extraInfo);
37
- if (p === null) return errorResult(`'${name}' is null. Expected {x,y} got ${JSON.stringify(p)}`, extraInfo);
38
- if (typeof p !== `object`) return errorResult(`'${name}' is type '${typeof p}'. Expected object.`, extraInfo);
39
- if (p.x === void 0) return errorResult(`'${name}.x' is undefined. Expected {x,y} got ${JSON.stringify(p)}`, extraInfo);
40
- if (p.y === void 0) return errorResult(`'${name}.y' is undefined. Expected {x,y} got ${JSON.stringify(p)}`, extraInfo);
41
- if (typeof p.x !== `number`) return errorResult(`'${name}.x' must be a number. Got ${typeof p.x}`, extraInfo);
42
- if (typeof p.y !== `number`) return errorResult(`'${name}.y' must be a number. Got ${typeof p.y}`, extraInfo);
43
- if (p.z !== void 0) {
44
- if (typeof p.z !== `number`) return errorResult(`${name}.z must be a number. Got: ${typeof p.z}`, extraInfo);
45
- if (Number.isNaN(p.z)) return errorResult(`'${name}.z' is NaN. Got: ${JSON.stringify(p)}`, extraInfo);
46
- }
47
- if (p.x === null) return errorResult(`'${name}.x' is null`, extraInfo);
48
- if (p.y === null) return errorResult(`'${name}.y' is null`, extraInfo);
49
- if (Number.isNaN(p.x)) return errorResult(`'${name}.x' is NaN`, extraInfo);
50
- if (Number.isNaN(p.y)) return errorResult(`'${name}.y' is NaN`, extraInfo);
51
- return {
52
- success: true,
53
- value: p
54
- };
55
- }
56
- /**
57
- * Throws an error if point is invalid
58
- * @param p
59
- * @param name
60
- */
61
- function guard$5(p, name = `Point`, info) {
62
- resultThrow(pointTest(p, name, info));
63
- }
64
- /**
65
- * Throws if parameter is not a valid point, or either x or y is 0
66
- * @param pt
67
- * @returns Throws an error if not a valid point or zero.
68
- */
69
- function guardNonZeroPoint(pt, name = `pt`) {
70
- guard$5(pt, name);
71
- resultThrow(numberTest(pt.x, `nonZero`, `${name}.x`), numberTest(pt.y, `nonZero`, `${name}.y`), () => {
72
- if (typeof pt.z !== `undefined`) return numberTest(pt.z, `nonZero`, `${name}.z`);
73
- });
74
- return true;
75
- }
76
- /**
77
- * Returns _true_ if `p` has x & y properties.
78
- * Returns _false_ if `p` is undefined, null or does not contain properties.
79
- * Use {@link isPoint3d} to check further check for `z`.
80
- * @param p
81
- * @returns True if `p` has x & y props
82
- */
83
- function isPoint(p) {
84
- if (p === void 0) return false;
85
- if (p === null) return false;
86
- if (p.x === void 0) return false;
87
- if (p.y === void 0) return false;
88
- return true;
89
- }
90
- /**
91
- * Returns _true_ if `p` has x, y, & z properties.
92
- * Returns _false_ if `p` is undefined, null or does not contain properties.
93
- * @param p
94
- * @returns _True_ if `p` has x, y, & z props
95
- */
96
- function isPoint3d(p) {
97
- if (p === void 0) return false;
98
- if (p === null) return false;
99
- if (p.x === void 0) return false;
100
- if (p.y === void 0) return false;
101
- if (p.z === void 0) return false;
102
- return true;
103
- }
104
- /**
105
- * Returns true if both xy (and z, if present) are 0.
106
- * Use `Points.Empty` to return an empty point.
107
- * @param p
108
- * @returns _True_ is all props are 0
109
- */
110
- function isEmpty(p) {
111
- if (isPoint3d(p)) {
112
- if (p.z !== 0) return false;
113
- }
114
- return p.x === 0 && p.y === 0;
115
- }
116
- /**
117
- * Returns true if point is a placeholder, where xy (and z, if present)
118
- * are `NaN`.
119
- *
120
- * Use Points.Placeholder to return a placeholder point.
121
- * @param p
122
- * @returns True if all props are NaN
123
- */
124
- function isPlaceholder(p) {
125
- if (isPoint3d(p)) {
126
- if (!Number.isNaN(p.z)) return false;
127
- }
128
- return Number.isNaN(p.x) && Number.isNaN(p.y);
129
- }
130
- //#endregion
131
- //#region node_modules/.pnpm/@ixfx+geometry@0.56.13/node_modules/@ixfx/geometry/dist/angles-BkBEzlEN.js
132
- const piPi = Math.PI * 2;
133
- /**
134
- * Averages a set of points, by default as a 'mean'.
135
- *
136
- * List of points has to all have Z property or none of them -- it's not
137
- * possible to mix 2D and 3D points.
138
- * @param points
139
- * @returns
140
- */
141
- const average$1 = (points, kind = `mean`) => {
142
- let xSum = 0;
143
- let ySum = 0;
144
- let zSum = NaN;
145
- let total = 0;
146
- if (kind !== `mean`) throw new Error(`Unknown averaging kind: '${kind}' expected: 'mean'`);
147
- for (const p of points) {
148
- xSum += p.x;
149
- ySum += p.y;
150
- if (`z` in p && p.z !== void 0) zSum += p.z;
151
- else if (Number.isNaN(zSum)) throw new Error(`List of points should all have Z property, or none`);
152
- total++;
153
- }
154
- xSum /= total;
155
- ySum /= total;
156
- if (Number.isNaN(zSum)) return {
157
- x: xSum,
158
- y: ySum
159
- };
160
- else return {
161
- x: xSum,
162
- y: ySum,
163
- z: zSum / total
164
- };
165
- };
166
- function averager(kind, opts = {}) {
167
- let x;
168
- let y;
169
- let z;
170
- switch (kind) {
171
- case `moving-average-light`: {
172
- const scaling = opts.scaling ?? 3;
173
- x = movingAverageLight(scaling);
174
- y = movingAverageLight(scaling);
175
- z = movingAverageLight(scaling);
176
- break;
177
- }
178
- default: throw new Error(`Unknown averaging kind '${kind}'. Expected: 'moving-average-light'`);
179
- }
180
- return (point) => {
181
- const ax = x(point.x);
182
- const ay = y(point.y);
183
- if (isPoint3d(point)) {
184
- const az = z(point.z);
185
- return Object.freeze({
186
- x: ax,
187
- y: ay,
188
- z: az
189
- });
190
- } else return Object.freeze({
191
- x: ax,
192
- y: ay
193
- });
194
- };
195
- }
196
- function degreeToRadian(angleInDegrees) {
197
- return Array.isArray(angleInDegrees) ? angleInDegrees.map((v) => v * (Math.PI / 180)) : angleInDegrees * (Math.PI / 180);
198
- }
199
- function degreeToGradian(angleInDegrees) {
200
- return angleInDegrees * 1.111111;
201
- }
202
- /**
203
- * Returns the gradian value converted to degrees.
204
- * By default it wraps, so any value 360 or greater wraps around.
205
- * @param angleInGradians
206
- * @param wrap
207
- * @returns Degrees
208
- */
209
- function gradianToDegree(angleInGradians, wrap = true) {
210
- if (wrap) return angleInGradians * .9 % 360;
211
- return angleInGradians * .9;
212
- }
213
- function radianToGradian(angleInRadians) {
214
- return angleInRadians * 63.6619772368;
215
- }
216
- function gradianToRadian(angleInGradian) {
217
- return angleInGradian * .0157079633;
218
- }
219
- function radianToDegree(angleInRadians) {
220
- return Array.isArray(angleInRadians) ? angleInRadians.map((v) => v * 180 / Math.PI) : angleInRadians * 180 / Math.PI;
221
- }
222
- /**
223
- * Parses CSS-style angle strings into an 'Angle' type. By default assumes degrees.
224
- *
225
- * ```js
226
- * angleParse(`100`); // { value: 100, unit: `deg` }
227
- * angleParse(100); // { value: 100, unit: `deg` }
228
- * angleParse(`100deg`); // { value: 100, unit: `deg` }
229
- *
230
- * // More exotic units:
231
- * angleParse(`100rad`); // { value: 100, unit: `rad` }
232
- * angleParse(`100turn`); // { value: 100, unit: `turn` }
233
- * angleParse(`100grad`); // { value: 100, unit: `grad` }
234
- * angleParse(`n`); // { value: 90, unit: `deg` }
235
- * angleParse(`e`); // { value: 0, unit: `deg` }
236
- * angleParse(`s`); // { value: 270, unit: `deg` }
237
- * angleParse(`w`); // { value: 180, unit: `deg` }
238
- * angleParse(`ne`); // ne/nw/se/sw supported
239
- * // Once parsed, use angleConvert to convert to a different unit:
240
- * angleConvert(`100rad`, `deg`); // { value: 5729.57795, unit: `deg` }
241
- * ```
242
- *
243
- * Once parsed in this format, use {@link angleConvert} to convert to
244
- * a different unit.
245
- * @param value
246
- * @returns Angle
247
- */
248
- function angleParse(value) {
249
- if (isAngleType(value)) return value;
250
- if (typeof value === `number`) return {
251
- value,
252
- unit: `deg`
253
- };
254
- value = value.toLowerCase();
255
- let unit = `deg`;
256
- let numberValue = NaN;
257
- if (value.endsWith(`grad`)) {
258
- numberValue = Number.parseFloat(value.substring(0, value.length - 4));
259
- unit = `grad`;
260
- } else if (value.endsWith(`rad`)) {
261
- numberValue = Number.parseFloat(value.substring(0, value.length - 3));
262
- unit = `rad`;
263
- } else if (value.endsWith(`turn`)) {
264
- numberValue = Number.parseFloat(value.substring(0, value.length - 4));
265
- unit = `turn`;
266
- } else if (value.endsWith(`deg`)) {
267
- numberValue = Number.parseFloat(value.substring(0, value.length - 3));
268
- unit = `deg`;
269
- } else numberValue = Number.parseFloat(value);
270
- if (Number.isNaN(numberValue)) if (value === `n`) return {
271
- value: 90,
272
- unit: `deg`
273
- };
274
- else if (value === `e`) return {
275
- value: 0,
276
- unit: `deg`
277
- };
278
- else if (value === `s`) return {
279
- value: 270,
280
- unit: `deg`
281
- };
282
- else if (value === `w`) return {
283
- value: 180,
284
- unit: `deg`
285
- };
286
- else if (value === `ne`) return {
287
- value: 45,
288
- unit: `deg`
289
- };
290
- else if (value === `se`) return {
291
- value: 315,
292
- unit: `deg`
293
- };
294
- else if (value === `sw`) return {
295
- value: 225,
296
- unit: `deg`
297
- };
298
- else if (value === `nw`) return {
299
- value: 135,
300
- unit: `deg`
301
- };
302
- else throw new Error(`Invalid angle (bad value?): '${value}'. If using cardinals, use: 'n', 'se', etc.`);
303
- if (unit.length === 0) throw new Error(`Invalid angle (no unit)`);
304
- return {
305
- value: numberValue,
306
- unit
307
- };
308
- }
309
- function isAngleType(v) {
310
- if (typeof v !== `object`) return false;
311
- if (`unit` in v && `value` in v) {
312
- if (typeof v.unit !== `string`) return false;
313
- if (typeof v.value !== `number`) return false;
314
- return true;
315
- }
316
- return false;
317
- }
318
- /**
319
- * Converts an angle to another representation.
320
- * Input value is assumed degrees unless it's an {@link Angle} type of has the unit.
321
- *
322
- * These are all identical inputs: 100, `100`, `100deg`
323
- * ```js
324
- * angleConvert(100, `rad`); // Converts 100deg to radians
325
- * ```
326
- *
327
- * Other units can be used for string input: `2turn`, `1grad`, `2rad`.
328
- * ```js
329
- * angleConvert(`2rad`, `deg`); // Converts 2radians to degrees
330
- * ```
331
- *
332
- * Can also use an object input:
333
- * ```js
334
- * angleConvert({ value: 10, unit: `deg`}, `rad`);
335
- * ```
336
- * @param angleOrDegrees
337
- * @param destination
338
- * @returns Angle
339
- */
340
- function angleConvert(angleOrDegrees, destination) {
341
- const input = typeof angleOrDegrees === `object` ? angleOrDegrees : angleParse(angleOrDegrees);
342
- switch (destination) {
343
- case `deg`:
344
- if (input.unit === `deg`) return input;
345
- if (input.unit === `rad`) return {
346
- value: radianToDegree(input.value),
347
- unit: `deg`
348
- };
349
- if (input.unit === `grad`) return {
350
- value: gradianToDegree(input.value),
351
- unit: `deg`
352
- };
353
- if (input.unit === `turn`) return {
354
- value: turnToDegree(input.value),
355
- unit: `deg`
356
- };
357
- throw new Error(`Unknown unit: ${input.unit}`);
358
- case `grad`:
359
- if (input.unit === `deg`) return {
360
- value: degreeToGradian(input.value),
361
- unit: `grad`
362
- };
363
- if (input.unit === `rad`) return {
364
- value: radianToGradian(input.value),
365
- unit: `grad`
366
- };
367
- if (input.unit === `grad`) return input;
368
- if (input.unit === `turn`) return {
369
- value: radianToGradian(turnToRadian(input.value)),
370
- unit: `grad`
371
- };
372
- throw new Error(`Unknown unit: ${input.unit}`);
373
- case `rad`:
374
- if (input.unit === `deg`) return {
375
- value: degreeToRadian(input.value),
376
- unit: `rad`
377
- };
378
- if (input.unit === `rad`) return input;
379
- if (input.unit === `grad`) return {
380
- value: gradianToRadian(input.value),
381
- unit: `rad`
382
- };
383
- if (input.unit === `turn`) return {
384
- value: turnToRadian(input.value),
385
- unit: `rad`
386
- };
387
- throw new Error(`Unknown unit: ${input.unit}`);
388
- case `turn`:
389
- if (input.unit === `deg`) return {
390
- value: degreeToTurn(input.value),
391
- unit: `turn`
392
- };
393
- if (input.unit === `rad`) return {
394
- value: radianToTurn(input.value),
395
- unit: `turn`
396
- };
397
- if (input.unit === `grad`) return {
398
- value: radianToTurn(gradianToRadian(input.value)),
399
- unit: `turn`
400
- };
401
- if (input.unit === `turn`) return input;
402
- throw new Error(`Unknown unit: ${input.unit}`);
403
- default: throw new Error(`Destination unit unknown ('${destination}). Expects: deg, grad, rad or turn`);
404
- }
405
- }
406
- /**
407
- * Converts 'turns' to degrees. By defaults wraps the value, so
408
- * turn value of 1 or 2 equal 0deg instead of 360 or 720deg.
409
- * @param turns
410
- * @param wrap
411
- * @returns Degrees
412
- */
413
- function turnToDegree(turns, wrap = true) {
414
- if (wrap) return turns * 360 % 360;
415
- return turns * 360;
416
- }
417
- /**
418
- * Normalise a radian angle to 0..2*PI range
419
- * @param angleRadian
420
- * @returns Normalised angle
421
- */
422
- function radiansNormalise(angleRadian) {
423
- angleRadian %= piPi;
424
- return angleRadian < 0 ? angleRadian + piPi : angleRadian;
425
- }
426
- function turnToRadian(turns) {
427
- return turns * piPi;
428
- }
429
- function degreeToTurn(degrees) {
430
- return degrees / 360;
431
- }
432
- function radianToTurn(radians) {
433
- return radians / piPi;
434
- }
435
- //#endregion
436
- //#region node_modules/.pnpm/@ixfx+visual@0.56.13/node_modules/@ixfx/visual/dist/colour-C3MQIjFJ.js
437
- var __defProp = Object.defineProperty;
438
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
439
- enumerable: true,
440
- configurable: true,
441
- writable: true,
442
- value
443
- }) : obj[key] = value;
444
- var __export = (target, all) => {
445
- for (var name2 in all) __defProp(target, name2, {
446
- get: all[name2],
447
- enumerable: true
448
- });
449
- };
450
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
451
- var COLOR_KEYS = {
452
- hsl: [
453
- "h",
454
- "s",
455
- "l"
456
- ],
457
- oklab: [
458
- "l",
459
- "a",
460
- "b"
461
- ],
462
- oklch: [
463
- "l",
464
- "c",
465
- "h"
466
- ],
467
- rgb: [
468
- "r",
469
- "g",
470
- "b"
471
- ]
472
- };
473
- var COLOR_MODELS = [
474
- "hsl",
475
- "oklab",
476
- "oklch",
477
- "rgb"
478
- ];
479
- var DEG2RAD = Math.PI / 180;
480
- var LAB_TO_LMS = {
481
- l: [.3963377773761749, .2158037573099136],
482
- m: [-.1055613458156586, -.0638541728258133],
483
- s: [-.0894841775298119, -1.2914855480194092]
484
- };
485
- var LRGB_TO_LMS = {
486
- l: [
487
- .4122214708,
488
- .5363325363,
489
- .0514459929
490
- ],
491
- m: [
492
- .2119034982,
493
- .6806995451,
494
- .1073969566
495
- ],
496
- s: [
497
- .0883024619,
498
- .2817188376,
499
- .6299787005
500
- ]
501
- };
502
- var LSM_TO_LAB = {
503
- l: [
504
- .2104542553,
505
- .793617785,
506
- .0040720468
507
- ],
508
- a: [
509
- 1.9779984951,
510
- 2.428592205,
511
- .4505937099
512
- ],
513
- b: [
514
- .0259040371,
515
- .7827717662,
516
- .808675766
517
- ]
518
- };
519
- var LSM_TO_RGB = {
520
- r: [
521
- 4.076741636075958,
522
- -3.307711539258063,
523
- .2309699031821043
524
- ],
525
- g: [
526
- -1.2684379732850315,
527
- 2.609757349287688,
528
- -.341319376002657
529
- ],
530
- b: [
531
- -.0041960761386756,
532
- -.7034186179359362,
533
- 1.7076146940746117
534
- ]
535
- };
536
- var PRECISION = 5;
537
- var RAD2DEG = 180 / Math.PI;
538
- var MESSAGES = {
539
- alpha: "alpha must be a number between 0 and 1",
540
- alphaAdjustment: "alpha must be a number between -1 and 1",
541
- amount: "amount must be a number between 0 and 100",
542
- colorRequired: "color is required",
543
- degreesRange: "degrees must be a number between -360 and 360",
544
- hueArgs: "point, chroma and h are required",
545
- hueRange: "hue must be a number between 0 and 360",
546
- input: "input is required",
547
- inputHex: "input is required and must be a hex",
548
- inputNumber: "input is required and must be a number",
549
- inputString: "input is required and must be a string",
550
- invalid: "invalid input",
551
- invalidColor: "invalid color",
552
- invalidCSS: "invalid CSS string",
553
- invalidHex: "invalid hex",
554
- invalidKey: "invalid key",
555
- invalidModel: "invalid model",
556
- invalidRange: "color value out of range",
557
- left: "left is required and must be a string",
558
- lightnessRange: "lightness must be a number between 0 and 1",
559
- options: "invalid options",
560
- paletteSize: "palette size must be at least 2",
561
- ratioRange: "ratio must be a number between 0 and 1",
562
- right: "right is required and must be a string",
563
- threshold: "threshold must be a number between 0 and 255",
564
- thresholdNormalized: "threshold must be a number between 0 and 1"
565
- };
566
- function invariant(condition, message) {
567
- if (condition) return;
568
- const error = !message ? /* @__PURE__ */ new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.") : new Error(message);
569
- error.name = "colorizr";
570
- throw error;
571
- }
572
- var cssColors = {
573
- aliceblue: "#f0f8ff",
574
- antiquewhite: "#faebd7",
575
- aqua: "#00ffff",
576
- aquamarine: "#7fffd4",
577
- azure: "#f0ffff",
578
- beige: "#f5f5dc",
579
- bisque: "#ffe4c4",
580
- black: "#000000",
581
- blanchedalmond: "#ffebcd",
582
- blue: "#0000ff",
583
- blueviolet: "#8a2be2",
584
- brown: "#a52a2a",
585
- burlywood: "#deb887",
586
- cadetblue: "#5f9ea0",
587
- chartreuse: "#7fff00",
588
- chocolate: "#d2691e",
589
- coral: "#ff7f50",
590
- cornflowerblue: "#6495ed",
591
- cornsilk: "#fff8dc",
592
- crimson: "#dc143c",
593
- cyan: "#00ffff",
594
- darkblue: "#00008b",
595
- darkcyan: "#008b8b",
596
- darkgoldenrod: "#b8860b",
597
- darkgray: "#a9a9a9",
598
- darkgreen: "#006400",
599
- darkkhaki: "#bdb76b",
600
- darkmagenta: "#8b008b",
601
- darkolivegreen: "#556b2f",
602
- darkorange: "#ff8c00",
603
- darkorchid: "#9932cc",
604
- darkred: "#8b0000",
605
- darksalmon: "#e9967a",
606
- darkseagreen: "#8fbc8f",
607
- darkslateblue: "#483d8b",
608
- darkslategray: "#2f4f4f",
609
- darkslategrey: "#2f4f4f",
610
- darkturquoise: "#00ced1",
611
- darkviolet: "#9400d3",
612
- deeppink: "#ff1493",
613
- deepskyblue: "#00bfff",
614
- dimgray: "#696969",
615
- dimgrey: "#696969",
616
- dodgerblue: "#1e90ff",
617
- firebrick: "#b22222",
618
- floralwhite: "#fffaf0",
619
- forestgreen: "#228b22",
620
- fuchsia: "#ff00ff",
621
- gainsboro: "#dcdcdc",
622
- ghostwhite: "#f8f8ff",
623
- gold: "#ffd700",
624
- goldenrod: "#daa520",
625
- gray: "#808080",
626
- grey: "#808080",
627
- green: "#008000",
628
- greenyellow: "#adff2f",
629
- honeydew: "#f0fff0",
630
- hotpink: "#ff69b4",
631
- indianred: "#cd5c5c",
632
- indigo: "#4b0082",
633
- ivory: "#fffff0",
634
- khaki: "#f0e68c",
635
- lavender: "#e6e6fa",
636
- lavenderblush: "#fff0f5",
637
- lawngreen: "#7cfc00",
638
- lemonchiffon: "#fffacd",
639
- lightblue: "#add8e6",
640
- lightcoral: "#f08080",
641
- lightcyan: "#e0ffff",
642
- lightgoldenrodyellow: "#fafad2",
643
- lightgray: "#d3d3d3",
644
- lightgreen: "#90ee90",
645
- lightgrey: "#d3d3d3",
646
- lightpink: "#ffb6c1",
647
- lightsalmon: "#ffa07a",
648
- lightseagreen: "#20b2aa",
649
- lightskyblue: "#87cefa",
650
- lightslategray: "#778899",
651
- lightslategrey: "#778899",
652
- lightsteelblue: "#b0c4de",
653
- lightyellow: "#ffffe0",
654
- lime: "#00ff00",
655
- limegreen: "#32cd32",
656
- linen: "#faf0e6",
657
- magenta: "#ff00ff",
658
- maroon: "#800000",
659
- mediumaquamarine: "#66cdaa",
660
- mediumblue: "#0000cd",
661
- mediumorchid: "#ba55d3",
662
- mediumpurple: "#9370db",
663
- mediumseagreen: "#3cb371",
664
- mediumslateblue: "#7b68ee",
665
- mediumspringgreen: "#00fa9a",
666
- mediumturquoise: "#48d1cc",
667
- mediumvioletred: "#c71585",
668
- midnightblue: "#191970",
669
- mintcream: "#f5fffa",
670
- mistyrose: "#ffe4e1",
671
- moccasin: "#ffe4b5",
672
- navajowhite: "#ffdead",
673
- navy: "#000080",
674
- oldlace: "#fdf5e6",
675
- olive: "#808000",
676
- olivedrab: "#6b8e23",
677
- orange: "#ffa500",
678
- orangered: "#ff4500",
679
- orchid: "#da70d6",
680
- palegoldenrod: "#eee8aa",
681
- palegreen: "#98fb98",
682
- paleturquoise: "#afeeee",
683
- palevioletred: "#db7093",
684
- papayawhip: "#ffefd5",
685
- peachpuff: "#ffdab9",
686
- peru: "#cd853f",
687
- pink: "#ffc0cb",
688
- plum: "#dda0dd",
689
- powderblue: "#b0e0e6",
690
- purple: "#800080",
691
- rebeccapurple: "#663399",
692
- red: "#ff0000",
693
- rosybrown: "#bc8f8f",
694
- royalblue: "#4169e1",
695
- saddlebrown: "#8b4513",
696
- salmon: "#fa8072",
697
- sandybrown: "#f4a460",
698
- seagreen: "#2e8b57",
699
- seashell: "#fff5ee",
700
- sienna: "#a0522d",
701
- silver: "#c0c0c0",
702
- skyblue: "#87ceeb",
703
- slateblue: "#6a5acd",
704
- slategray: "#708090",
705
- slategrey: "#708090",
706
- snow: "#fffafa",
707
- springgreen: "#00ff7f",
708
- steelblue: "#4682b4",
709
- tan: "#d2b48c",
710
- teal: "#008080",
711
- thistle: "#d8bfd8",
712
- tomato: "#ff6347",
713
- turquoise: "#40e0d0",
714
- violet: "#ee82ee",
715
- wheat: "#f5deb3",
716
- white: "#ffffff",
717
- whitesmoke: "#f5f5f5",
718
- yellow: "#ffff00",
719
- yellowgreen: "#9acd32"
720
- };
721
- var hexRegex = /^#(?:[\da-f]{3,4}|[\da-f]{6,8})$/i;
722
- function hasValidMatches(input) {
723
- return Array.isArray(input) && input.length === 6;
724
- }
725
- function isHex(input) {
726
- if (!isString(input)) return false;
727
- return hexRegex.test(input);
728
- }
729
- function isHSL(input) {
730
- if (!isPlainObject(input)) return false;
731
- const entries = Object.entries(input);
732
- return !!entries.length && entries.every(([key, value]) => {
733
- if (key === "h") return value >= 0 && value <= 360;
734
- if (key === "alpha") return value >= 0 && value <= 1;
735
- return COLOR_KEYS.hsl.includes(key) && value >= 0 && value <= 100;
736
- });
737
- }
738
- function isLAB(input) {
739
- if (!isPlainObject(input)) return false;
740
- const entries = Object.entries(input);
741
- return !!entries.length && entries.every(([key, value]) => {
742
- if (key === "l") return value >= 0 && value <= 100;
743
- if (key === "alpha") return value >= 0 && value <= 1;
744
- return COLOR_KEYS.oklab.includes(key) && value >= -1 && value <= 1;
745
- });
746
- }
747
- function isLCH(input) {
748
- if (!isPlainObject(input)) return false;
749
- const entries = Object.entries(input);
750
- return !!entries.length && entries.every(([key, value]) => {
751
- if (key === "l") return value >= 0 && value <= 100;
752
- if (key === "alpha") return value >= 0 && value <= 1;
753
- return COLOR_KEYS.oklch.includes(key) && value >= 0 && value <= (key === "h" ? 360 : 1);
754
- });
755
- }
756
- function isNamedColor(input) {
757
- return isString(input) && Object.keys(cssColors).includes(input.toLowerCase());
758
- }
759
- function isNumber(input) {
760
- return typeof input === "number" && !Number.isNaN(input);
761
- }
762
- function isNumberInRange(input, min, max) {
763
- return isNumber(input) && input >= min && input <= max;
764
- }
765
- function isPlainObject(input) {
766
- if (!input) return false;
767
- const { toString } = Object.prototype;
768
- const prototype = Object.getPrototypeOf(input);
769
- return toString.call(input) === "[object Object]" && (prototype === null || prototype === Object.getPrototypeOf({}));
770
- }
771
- function isRGB(input) {
772
- if (!isPlainObject(input)) return false;
773
- const entries = Object.entries(input);
774
- return !!entries.length && entries.every(([key, value]) => {
775
- if (key === "alpha") return value >= 0 && value <= 1;
776
- return COLOR_KEYS.rgb.includes(key) && value >= 0 && value <= 255;
777
- });
778
- }
779
- function isString(input, validate = true) {
780
- const isValid = typeof input === "string";
781
- if (validate) return isValid && !!input.trim().length;
782
- return isValid;
783
- }
784
- function isValidColorModel(input) {
785
- return isHSL(input) || isRGB(input) || isLAB(input) || isLCH(input);
786
- }
787
- function formatHex(input) {
788
- invariant(isHex(input), MESSAGES.inputHex);
789
- let color = input.replace("#", "");
790
- if (color.length === 3 || color.length === 4) {
791
- const values = [...color];
792
- color = "";
793
- values.forEach((d) => {
794
- color += `${d}${d}`;
795
- });
796
- }
797
- const hex = `#${color}`;
798
- invariant(isHex(hex), MESSAGES.invalidHex);
799
- return hex;
800
- }
801
- function addAlpha(input, alpha) {
802
- invariant(isValidColorModel(input), MESSAGES.invalid);
803
- let value = alpha;
804
- if (value === void 0) return input;
805
- if (value > 1) value /= 100;
806
- if (value === 1) return input;
807
- return {
808
- ...input,
809
- alpha: value
810
- };
811
- }
812
- function clamp$1(value, min = 0, max = 100) {
813
- return Math.min(Math.max(value, min), max);
814
- }
815
- function constrainDegrees(input, amount) {
816
- invariant(isNumber(input), MESSAGES.inputNumber);
817
- let value = input + amount;
818
- if (value > 360) value %= 360;
819
- if (value < 0) value += 360;
820
- return Math.abs(value);
821
- }
822
- function extractAlpha(input) {
823
- if (Array.isArray(input)) return;
824
- return input.alpha;
825
- }
826
- function limit(input, model, key) {
827
- invariant(isNumber(input), MESSAGES.inputNumber);
828
- invariant(COLOR_MODELS.includes(model), `${MESSAGES.invalidModel}${model ? `: ${model}` : ""}`);
829
- invariant(COLOR_KEYS[model].includes(key), `${MESSAGES.invalidKey}${key ? `: ${key}` : ""}`);
830
- switch (model) {
831
- case "hsl":
832
- invariant(COLOR_KEYS.hsl.includes(key), MESSAGES.invalidKey);
833
- if (["l", "s"].includes(key)) return clamp$1(input);
834
- return clamp$1(input, 0, 360);
835
- case "rgb":
836
- invariant(COLOR_KEYS.rgb.includes(key), MESSAGES.invalidKey);
837
- return clamp$1(input, 0, 255);
838
- default: throw new Error("Invalid inputs");
839
- }
840
- }
841
- function parseInput(input, model) {
842
- const keys = COLOR_KEYS[model];
843
- const validator = {
844
- hsl: isHSL,
845
- oklab: isLAB,
846
- oklch: isLCH,
847
- rgb: isRGB
848
- };
849
- invariant(isPlainObject(input) || Array.isArray(input), MESSAGES.invalid);
850
- const value = Array.isArray(input) ? {
851
- [keys[0]]: input[0],
852
- [keys[1]]: input[1],
853
- [keys[2]]: input[2]
854
- } : input;
855
- invariant(validator[model](value), `${MESSAGES.invalidColor}: ${model}`);
856
- return value;
857
- }
858
- function restrictValues(input, precision = PRECISION, forcePrecision = true) {
859
- const output = new Map(Object.entries(input));
860
- for (const [key, value] of output.entries()) output.set(key, round$1(value, precision, forcePrecision));
861
- return Object.fromEntries(output);
862
- }
863
- function round$1(input, precision = 2, forcePrecision = true) {
864
- if (!isNumber(input) || input === 0) return 0;
865
- if (forcePrecision) {
866
- const factor2 = 10 ** precision;
867
- return Math.round(input * factor2) / factor2;
868
- }
869
- let digits = Math.abs(Math.ceil(Math.log(Math.abs(input)) / Math.LN10));
870
- if (digits === 0) digits = 2;
871
- else if (digits > precision) digits = precision;
872
- let exponent = precision - (digits < 0 ? 0 : digits);
873
- if (exponent <= 1 && precision > 1) exponent = 2;
874
- else if (exponent > precision || exponent === 0) exponent = precision;
875
- const factor = 10 ** exponent;
876
- return Math.round(input * factor) / factor;
877
- }
878
- function addAlphaToHex(input, alpha) {
879
- invariant(isHex(input), MESSAGES.inputHex);
880
- invariant(isNumberInRange(alpha, 0, 1), MESSAGES.alpha);
881
- if (alpha >= 1) return removeAlphaFromHex(input);
882
- return `${removeAlphaFromHex(input)}${convertAlphaToHex(alpha)}`;
883
- }
884
- function convertAlphaToHex(input) {
885
- invariant(isNumber(input), MESSAGES.inputNumber);
886
- let alpha = input;
887
- if (input > 1) alpha /= 100;
888
- return Math.round(alpha * 255).toString(16).padStart(2, "0");
889
- }
890
- function extractAlphaFromHex(input) {
891
- invariant(isHex(input), MESSAGES.inputString);
892
- const alpha = input.substring(7, 9);
893
- if (!alpha) return 1;
894
- return round$1(parseInt(alpha, 16) / 255);
895
- }
896
- function removeAlphaFromHex(input) {
897
- invariant(isHex(input), MESSAGES.inputHex);
898
- if (input.length === 5) return input.substring(0, 4);
899
- return input.substring(0, 7);
900
- }
901
- function hex2rgb(input) {
902
- invariant(isHex(input), MESSAGES.inputHex);
903
- const hex = formatHex(input).slice(1);
904
- const alpha = extractAlphaFromHex(input);
905
- return addAlpha({
906
- r: parseInt(hex.charAt(0) + hex.charAt(1), 16),
907
- g: parseInt(hex.charAt(2) + hex.charAt(3), 16),
908
- b: parseInt(hex.charAt(4) + hex.charAt(5), 16)
909
- }, alpha);
910
- }
911
- var converters_exports = {};
912
- __export(converters_exports, {
913
- hex2hsl: () => hex2hsl,
914
- hex2oklab: () => hex2oklab,
915
- hex2oklch: () => hex2oklch,
916
- hex2rgb: () => hex2rgb,
917
- hsl2hex: () => hsl2hex,
918
- hsl2oklab: () => hsl2oklab,
919
- hsl2oklch: () => hsl2oklch,
920
- hsl2rgb: () => hsl2rgb,
921
- oklab2hex: () => oklab2hex,
922
- oklab2hsl: () => oklab2hsl,
923
- oklab2oklch: () => oklab2oklch,
924
- oklab2rgb: () => oklab2rgb,
925
- oklch2hex: () => oklch2hex,
926
- oklch2hsl: () => oklch2hsl,
927
- oklch2oklab: () => oklch2oklab,
928
- oklch2rgb: () => oklch2rgb,
929
- rgb2hex: () => rgb2hex,
930
- rgb2hsl: () => rgb2hsl,
931
- rgb2oklab: () => rgb2oklab,
932
- rgb2oklch: () => rgb2oklch
933
- });
934
- function rgb2hsl(input) {
935
- const value = parseInput(input, "rgb");
936
- const alpha = extractAlpha(input);
937
- const rLimit = limit(value.r, "rgb", "r") / 255;
938
- const gLimit = limit(value.g, "rgb", "g") / 255;
939
- const bLimit = limit(value.b, "rgb", "b") / 255;
940
- const min = Math.min(rLimit, gLimit, bLimit);
941
- const max = Math.max(rLimit, gLimit, bLimit);
942
- const delta = max - min;
943
- let h = 0;
944
- let s;
945
- const l = (max + min) / 2;
946
- let rate;
947
- switch (max) {
948
- case rLimit:
949
- rate = !delta ? 0 : (gLimit - bLimit) / delta;
950
- h = 60 * rate;
951
- break;
952
- case gLimit:
953
- rate = (bLimit - rLimit) / delta;
954
- h = 60 * rate + 120;
955
- break;
956
- case bLimit:
957
- rate = (rLimit - gLimit) / delta;
958
- h = 60 * rate + 240;
959
- break;
960
- default: break;
961
- }
962
- if (h < 0) h = 360 + h;
963
- if (min === max) s = 0;
964
- else s = l < .5 ? delta / (2 * l) : delta / (2 - 2 * l);
965
- return addAlpha({
966
- h: Math.abs(+(h % 360).toFixed(2)),
967
- s: +(s * 100).toFixed(2),
968
- l: +(l * 100).toFixed(2)
969
- }, alpha);
970
- }
971
- function hex2hsl(input) {
972
- invariant(isHex(input), MESSAGES.inputHex);
973
- const alpha = extractAlphaFromHex(input);
974
- return addAlpha(rgb2hsl(hex2rgb(input)), alpha);
975
- }
976
- var { cbrt, sign } = Math;
977
- function rgb2lrgb(input) {
978
- const abs2 = Math.abs(input);
979
- if (abs2 < .04045) return input / 12.92;
980
- return (sign(input) || 1) * ((abs2 + .055) / 1.055) ** 2.4;
981
- }
982
- function rgb2oklab(input, precision = PRECISION) {
983
- const value = parseInput(input, "rgb");
984
- const alpha = extractAlpha(input);
985
- const [lr, lg, lb] = [
986
- rgb2lrgb(value.r / 255),
987
- rgb2lrgb(value.g / 255),
988
- rgb2lrgb(value.b / 255)
989
- ];
990
- const l = cbrt(LRGB_TO_LMS.l[0] * lr + LRGB_TO_LMS.l[1] * lg + LRGB_TO_LMS.l[2] * lb);
991
- const m = cbrt(LRGB_TO_LMS.m[0] * lr + LRGB_TO_LMS.m[1] * lg + LRGB_TO_LMS.m[2] * lb);
992
- const s = cbrt(LRGB_TO_LMS.s[0] * lr + LRGB_TO_LMS.s[1] * lg + LRGB_TO_LMS.s[2] * lb);
993
- return addAlpha(restrictValues({
994
- l: LSM_TO_LAB.l[0] * l + LSM_TO_LAB.l[1] * m - LSM_TO_LAB.l[2] * s,
995
- a: LSM_TO_LAB.a[0] * l - LSM_TO_LAB.a[1] * m + LSM_TO_LAB.a[2] * s,
996
- b: LSM_TO_LAB.b[0] * l + LSM_TO_LAB.b[1] * m - LSM_TO_LAB.b[2] * s
997
- }, precision), alpha);
998
- }
999
- function hex2oklab(input, precision) {
1000
- invariant(isHex(input), MESSAGES.inputHex);
1001
- const alpha = extractAlphaFromHex(input);
1002
- return addAlpha(rgb2oklab(hex2rgb(input), precision), alpha);
1003
- }
1004
- var { atan2, sqrt } = Math;
1005
- function oklab2oklch(input, precision) {
1006
- const { l, a, b } = restrictValues(parseInput(input, "oklab"));
1007
- const alpha = extractAlpha(input);
1008
- const c = sqrt(a ** 2 + b ** 2);
1009
- let h = (atan2(b, a) * RAD2DEG + 360) % 360;
1010
- if (round$1(c * 1e4) === 0) h = 0;
1011
- return addAlpha(restrictValues({
1012
- l,
1013
- c,
1014
- h
1015
- }, precision), alpha);
1016
- }
1017
- function rgb2oklch(input, precision) {
1018
- const value = parseInput(input, "rgb");
1019
- const alpha = extractAlpha(input);
1020
- return addAlpha(oklab2oklch(rgb2oklab(value, precision), precision), alpha);
1021
- }
1022
- function hex2oklch(input, precision) {
1023
- invariant(isHex(input), MESSAGES.inputHex);
1024
- const alpha = extractAlphaFromHex(input);
1025
- return addAlpha(rgb2oklch(hex2rgb(input), precision), alpha);
1026
- }
1027
- function hue2rgb(point, chroma2, h) {
1028
- invariant(isNumber(point) && isNumber(chroma2) && isNumber(h), MESSAGES.hueArgs);
1029
- let hue = h;
1030
- if (hue < 0) hue += 1;
1031
- if (hue > 1) hue -= 1;
1032
- if (hue < 1 / 6) return round$1(point + (chroma2 - point) * 6 * hue, 4);
1033
- if (hue < 1 / 2) return round$1(chroma2, 4);
1034
- if (hue < 2 / 3) return round$1(point + (chroma2 - point) * (2 / 3 - hue) * 6, 4);
1035
- return round$1(point, 4);
1036
- }
1037
- function hsl2rgb(input) {
1038
- const value = parseInput(input, "hsl");
1039
- const alpha = extractAlpha(input);
1040
- const h = round$1(value.h) / 360;
1041
- const s = round$1(value.s) / 100;
1042
- const l = round$1(value.l) / 100;
1043
- let r;
1044
- let g;
1045
- let b;
1046
- let point;
1047
- let chroma2;
1048
- if (s === 0) {
1049
- r = l;
1050
- g = l;
1051
- b = l;
1052
- } else {
1053
- chroma2 = l < .5 ? l * (1 + s) : l + s - l * s;
1054
- point = 2 * l - chroma2;
1055
- r = hue2rgb(point, chroma2, h + 1 / 3);
1056
- g = hue2rgb(point, chroma2, h);
1057
- b = hue2rgb(point, chroma2, h - 1 / 3);
1058
- }
1059
- return addAlpha({
1060
- r: Math.round(r * 255),
1061
- g: Math.round(g * 255),
1062
- b: Math.round(b * 255)
1063
- }, alpha);
1064
- }
1065
- function rgb2hex(input) {
1066
- const rgb = parseInput(input, "rgb");
1067
- const alpha = extractAlpha(input);
1068
- const hex = `#${[
1069
- rgb.r,
1070
- rgb.g,
1071
- rgb.b
1072
- ].map((d) => `0${Math.floor(d).toString(16)}`.slice(-2)).join("")}`;
1073
- return alpha !== void 0 && alpha < 1 ? addAlphaToHex(hex, alpha) : hex;
1074
- }
1075
- function hsl2hex(input) {
1076
- const value = parseInput(input, "hsl");
1077
- const alpha = extractAlpha(input);
1078
- const hex = rgb2hex(hsl2rgb(value));
1079
- return alpha !== void 0 && alpha < 1 ? addAlphaToHex(hex, alpha) : hex;
1080
- }
1081
- function hsl2oklab(input, precision) {
1082
- const value = parseInput(input, "hsl");
1083
- const alpha = extractAlpha(input);
1084
- return addAlpha(rgb2oklab(hsl2rgb(value), precision), alpha);
1085
- }
1086
- function hsl2oklch(input, precision) {
1087
- const value = parseInput(input, "hsl");
1088
- const alpha = extractAlpha(input);
1089
- return addAlpha(rgb2oklch(hsl2rgb(value), precision), alpha);
1090
- }
1091
- var { abs } = Math;
1092
- function lrgb2rgb(input) {
1093
- const absoluteNumber = abs(input);
1094
- const sign2 = input < 0 ? -1 : 1;
1095
- if (absoluteNumber > .0031308) return sign2 * (absoluteNumber ** (1 / 2.4) * 1.055 - .055);
1096
- return input * 12.92;
1097
- }
1098
- function oklab2rgb(input, precision = 0) {
1099
- const { l: L, a: A, b: B } = parseInput(input, "oklab");
1100
- const alpha = extractAlpha(input);
1101
- const l = (L + LAB_TO_LMS.l[0] * A + LAB_TO_LMS.l[1] * B) ** 3;
1102
- const m = (L + LAB_TO_LMS.m[0] * A + LAB_TO_LMS.m[1] * B) ** 3;
1103
- const s = (L + LAB_TO_LMS.s[0] * A + LAB_TO_LMS.s[1] * B) ** 3;
1104
- const r = 255 * lrgb2rgb(LSM_TO_RGB.r[0] * l + LSM_TO_RGB.r[1] * m + LSM_TO_RGB.r[2] * s);
1105
- const g = 255 * lrgb2rgb(LSM_TO_RGB.g[0] * l + LSM_TO_RGB.g[1] * m + LSM_TO_RGB.g[2] * s);
1106
- const b = 255 * lrgb2rgb(LSM_TO_RGB.b[0] * l + LSM_TO_RGB.b[1] * m + LSM_TO_RGB.b[2] * s);
1107
- return addAlpha({
1108
- r: clamp$1(round$1(r, precision), 0, 255),
1109
- g: clamp$1(round$1(g, precision), 0, 255),
1110
- b: clamp$1(round$1(b, precision), 0, 255)
1111
- }, alpha);
1112
- }
1113
- function oklab2hex(input) {
1114
- const value = parseInput(input, "oklab");
1115
- const alpha = extractAlpha(input);
1116
- const hex = rgb2hex(oklab2rgb(value));
1117
- return alpha !== void 0 && alpha < 1 ? addAlphaToHex(hex, alpha) : hex;
1118
- }
1119
- function oklab2hsl(input) {
1120
- const value = parseInput(input, "oklab");
1121
- const alpha = extractAlpha(input);
1122
- return addAlpha(rgb2hsl(oklab2rgb(value)), alpha);
1123
- }
1124
- var { sin, cos } = Math;
1125
- function oklch2oklab(input, precision) {
1126
- let { l, c, h } = parseInput(input, "oklch");
1127
- const alpha = extractAlpha(input);
1128
- if (Number.isNaN(h) || h < 0) h = 0;
1129
- return addAlpha(restrictValues({
1130
- l,
1131
- a: c * cos(h * DEG2RAD),
1132
- b: c * sin(h * DEG2RAD)
1133
- }, precision), alpha);
1134
- }
1135
- function oklch2rgb(input, precision = 0) {
1136
- const value = parseInput(input, "oklch");
1137
- const alpha = extractAlpha(input);
1138
- return addAlpha(oklab2rgb(oklch2oklab(value), precision), alpha);
1139
- }
1140
- function oklch2hex(input) {
1141
- const value = parseInput(input, "oklch");
1142
- const alpha = extractAlpha(input);
1143
- const hex = rgb2hex(oklch2rgb(value));
1144
- return alpha !== void 0 && alpha < 1 ? addAlphaToHex(hex, alpha) : hex;
1145
- }
1146
- function oklch2hsl(input) {
1147
- const value = parseInput(input, "oklch");
1148
- const alpha = extractAlpha(input);
1149
- return addAlpha(rgb2hsl(oklch2rgb(value)), alpha);
1150
- }
1151
- var MODEL = "(rgb|hsl|oklab|oklch)a?";
1152
- var SEP = "(?:\\s*[,/]\\s*|\\s+)";
1153
- var VALUE = "(none|[\\d%.-]+(?:deg|grad|rad|turn)?)";
1154
- var colorRegex = new RegExp(`${MODEL}\\s*\\(\\s*${VALUE}${SEP}${VALUE}${SEP}${VALUE}(?:${SEP}${VALUE})?\\s*\\)`, "i");
1155
- function parseAngle(value) {
1156
- const number_ = parseFloat(value);
1157
- let result;
1158
- if (value.endsWith("grad")) result = number_ * .9;
1159
- else if (value.endsWith("rad")) result = number_ * (180 / Math.PI);
1160
- else if (value.endsWith("turn")) result = number_ * 360;
1161
- else result = number_;
1162
- return Math.round(result * 1e5) / 1e5;
1163
- }
1164
- function extractColorParts(input) {
1165
- invariant(isString(input), MESSAGES.inputString);
1166
- if (isHex(input)) {
1167
- const keys2 = COLOR_KEYS.rgb;
1168
- const { r, g, b } = hex2rgb(input);
1169
- const alpha2 = extractAlphaFromHex(input);
1170
- return {
1171
- model: "rgb",
1172
- [keys2[0]]: r,
1173
- [keys2[1]]: g,
1174
- [keys2[2]]: b,
1175
- alpha: alpha2 < 1 ? alpha2 : void 0
1176
- };
1177
- }
1178
- const matches = colorRegex.exec(input);
1179
- invariant(hasValidMatches(matches), MESSAGES.invalidCSS);
1180
- const model = matches[1];
1181
- const keys = COLOR_KEYS[model];
1182
- let alpha = matches[5] ? parseFloat(matches[5]) : 1;
1183
- if (alpha > 1) alpha /= 100;
1184
- const parseValue = (value, index) => {
1185
- if (value === "none") return 0;
1186
- if (model === "hsl" && index === 0 || model === "oklch" && index === 2) return parseAngle(value);
1187
- const parsedValue = parseFloat(value);
1188
- if (!value.includes("%")) return parsedValue;
1189
- if (model === "oklch") {
1190
- if (index === 1) return parsedValue * .4 / 100;
1191
- } else if (model === "oklab") {
1192
- if (index === 1 || index === 2) return parsedValue * .4 / 100;
1193
- }
1194
- return parsedValue;
1195
- };
1196
- const values = [
1197
- parseValue(matches[2], 0),
1198
- parseValue(matches[3], 1),
1199
- parseValue(matches[4], 2)
1200
- ];
1201
- if (model === "oklab") {
1202
- invariant(values[1] >= -.4 && values[1] <= .4, MESSAGES.invalidRange);
1203
- invariant(values[2] >= -.4 && values[2] <= .4, MESSAGES.invalidRange);
1204
- } else if (model === "oklch") invariant(values[1] >= 0 && values[1] <= .4, MESSAGES.invalidRange);
1205
- return {
1206
- model,
1207
- [keys[0]]: values[0],
1208
- [keys[1]]: values[1],
1209
- [keys[2]]: values[2],
1210
- alpha: alpha < 1 ? alpha : void 0
1211
- };
1212
- }
1213
- var toHslConverters = {
1214
- oklab: oklab2hsl,
1215
- oklch: oklch2hsl,
1216
- rgb: rgb2hsl
1217
- };
1218
- var toOklabConverters = {
1219
- hsl: hsl2oklab,
1220
- oklch: oklch2oklab,
1221
- rgb: rgb2oklab
1222
- };
1223
- var toOklchConverters = {
1224
- hsl: hsl2oklch,
1225
- oklab: oklab2oklch,
1226
- rgb: rgb2oklch
1227
- };
1228
- var toRgbConverters = {
1229
- hsl: hsl2rgb,
1230
- oklab: oklab2rgb,
1231
- oklch: oklch2rgb
1232
- };
1233
- var toHexConverters = {
1234
- hsl: hsl2hex,
1235
- oklab: oklab2hex,
1236
- oklch: oklch2hex,
1237
- rgb: rgb2hex
1238
- };
1239
- var fromHexConverters = {
1240
- hsl: hex2hsl,
1241
- oklab: hex2oklab,
1242
- oklch: hex2oklch,
1243
- rgb: hex2rgb
1244
- };
1245
- var converterTables = {
1246
- hsl: toHslConverters,
1247
- oklab: toOklabConverters,
1248
- oklch: toOklchConverters,
1249
- rgb: toRgbConverters
1250
- };
1251
- function convertFromCSS(value, output) {
1252
- const { alpha, model, ...color } = extractColorParts(value);
1253
- if (["oklab", "oklch"].includes(model) && color.l > 1) color.l = round$1(color.l / 100, PRECISION);
1254
- const colorTuple = Object.values(color);
1255
- if (output === "hex") {
1256
- const alphaPrefix = alpha ? convertAlphaToHex(alpha) : "";
1257
- return `${toHexConverters[model](colorTuple)}${alphaPrefix}`;
1258
- }
1259
- const converter = converterTables[output]?.[model];
1260
- return addAlpha(converter ? converter(colorTuple) : color, alpha);
1261
- }
1262
- function convertFromHex(value, output) {
1263
- const alpha = extractAlphaFromHex(value);
1264
- if (output === "hex") return `${removeAlphaFromHex(value)}${alpha !== 1 ? convertAlphaToHex(alpha) : ""}`;
1265
- return addAlpha(fromHexConverters[output](value), alpha);
1266
- }
1267
- function parseCSS(input, format) {
1268
- invariant(isString(input), MESSAGES.inputString);
1269
- const value = isNamedColor(input) ? cssColors[input.toLowerCase()] : input;
1270
- const output = format ?? (isHex(value) ? "hex" : extractColorParts(value).model);
1271
- if (isHex(value)) return convertFromHex(value, output);
1272
- return convertFromCSS(value, output);
1273
- }
1274
- var mainTRC = 2.4;
1275
- var normBG = .56;
1276
- var normTXT = .57;
1277
- var revBG = .65;
1278
- var revTXT = .62;
1279
- var sRco = .2126729;
1280
- var sGco = .7151522;
1281
- var sBco = .072175;
1282
- var blkThreshold = .022;
1283
- var blkClamp = 1.414;
1284
- var scaleBoW = 1.14;
1285
- var scaleWoB = 1.14;
1286
- var loBoWOffset = .027;
1287
- var loWoBOffset = .027;
1288
- var loClip = .1;
1289
- var deltaYmin = 5e-4;
1290
- function softClamp(Y) {
1291
- return Y > blkThreshold ? Y : Y + (blkThreshold - Y) ** blkClamp;
1292
- }
1293
- function sRGBtoY(r, g, b) {
1294
- return sRco * (r / 255) ** mainTRC + sGco * (g / 255) ** mainTRC + sBco * (b / 255) ** mainTRC;
1295
- }
1296
- function apcaContrast(background, foreground) {
1297
- invariant(isString(background), MESSAGES.inputString);
1298
- invariant(isString(foreground), MESSAGES.inputString);
1299
- const bg = hex2rgb(parseCSS(background, "hex"));
1300
- const fg = hex2rgb(parseCSS(foreground, "hex"));
1301
- const txtY = softClamp(sRGBtoY(fg.r, fg.g, fg.b));
1302
- const bgY = softClamp(sRGBtoY(bg.r, bg.g, bg.b));
1303
- if (Math.abs(bgY - txtY) < deltaYmin) return 0;
1304
- const SAPC = bgY > txtY ? (bgY ** normBG - txtY ** normTXT) * scaleBoW : (bgY ** revBG - txtY ** revTXT) * scaleWoB;
1305
- if (Math.abs(SAPC) < loClip) return 0;
1306
- return round$1(SAPC > 0 ? (SAPC - loBoWOffset) * 100 : (SAPC + loWoBOffset) * 100, 5);
1307
- }
1308
- function brightnessDifference(left, right, precision = PRECISION) {
1309
- invariant(isString(left), MESSAGES.left);
1310
- invariant(isString(right), MESSAGES.right);
1311
- const RGBLeft = parseCSS(left, "rgb");
1312
- const RGBRight = parseCSS(right, "rgb");
1313
- const brightnessLeft = (RGBLeft.r * 299 + RGBLeft.g * 587 + RGBLeft.b * 114) / 1e3;
1314
- const brightnessRight = (RGBRight.r * 299 + RGBRight.g * 587 + RGBRight.b * 114) / 1e3;
1315
- return round$1(Math.abs(brightnessRight - brightnessLeft), precision);
1316
- }
1317
- function chroma(input) {
1318
- invariant(isString(input), MESSAGES.inputString);
1319
- const { r, g, b } = parseCSS(input, "rgb");
1320
- return round$1((Math.max(r, g, b) - Math.min(r, g, b)) / 255, 4);
1321
- }
1322
- function colorDifference(left, right) {
1323
- invariant(isString(left), MESSAGES.left);
1324
- invariant(isString(right), MESSAGES.right);
1325
- const RGBLeft = parseCSS(left, "rgb");
1326
- const RGBRight = parseCSS(right, "rgb");
1327
- return Math.max(RGBLeft.r, RGBRight.r) - Math.min(RGBLeft.r, RGBRight.r) + (Math.max(RGBLeft.g, RGBRight.g) - Math.min(RGBLeft.g, RGBRight.g)) + (Math.max(RGBLeft.b, RGBRight.b) - Math.min(RGBLeft.b, RGBRight.b));
1328
- }
1329
- function luminance(input) {
1330
- invariant(isString(input), MESSAGES.inputString);
1331
- const { r, g, b } = parseCSS(input, "rgb");
1332
- const rgb = [
1333
- r / 255,
1334
- g / 255,
1335
- b / 255
1336
- ];
1337
- for (let index = 0; index < rgb.length; index++) if (rgb[index] <= .04045) rgb[index] /= 12.92;
1338
- else rgb[index] = ((rgb[index] + .055) / 1.055) ** 2.4;
1339
- return round$1(.2126 * rgb[0] + .7152 * rgb[1] + .0722 * rgb[2], 4);
1340
- }
1341
- function contrast(left, right) {
1342
- invariant(isString(left), MESSAGES.left);
1343
- invariant(isString(right), MESSAGES.right);
1344
- const LuminanceLeft = luminance(left);
1345
- const LuminanceRight = luminance(right);
1346
- return round$1(LuminanceLeft >= LuminanceRight ? (LuminanceLeft + .05) / (LuminanceRight + .05) : (LuminanceRight + .05) / (LuminanceLeft + .05));
1347
- }
1348
- function compare(left, right) {
1349
- invariant(isString(left), MESSAGES.left);
1350
- invariant(isString(right), MESSAGES.right);
1351
- const colorThreshold = 500;
1352
- const brightnessThreshold = 125;
1353
- const colorDifference2 = colorDifference(left, right);
1354
- const contrast2 = contrast(left, right);
1355
- const brightnessDifference2 = brightnessDifference(left, right);
1356
- const isBright = brightnessDifference2 >= brightnessThreshold;
1357
- const hasEnoughDifference = colorDifference2 >= colorThreshold;
1358
- let compliant = 0;
1359
- if (isBright && hasEnoughDifference) compliant = 2;
1360
- else if (isBright || hasEnoughDifference) compliant = 1;
1361
- return {
1362
- brightnessDifference: brightnessDifference2,
1363
- colorDifference: colorDifference2,
1364
- compliant,
1365
- contrast: contrast2,
1366
- largeAA: contrast2 >= 3,
1367
- largeAAA: contrast2 >= 4.5,
1368
- normalAA: contrast2 >= 4.5,
1369
- normalAAA: contrast2 >= 7
1370
- };
1371
- }
1372
- function getColorModel(input) {
1373
- if (isHex(input) || isNamedColor(input)) return "hex";
1374
- if (isHSL(input)) return "hsl";
1375
- if (isLAB(input)) return "oklab";
1376
- if (isLCH(input)) return "oklch";
1377
- if (isRGB(input)) return "rgb";
1378
- throw new Error(MESSAGES.invalid);
1379
- }
1380
- function getColorValue(input, output) {
1381
- const value = isNamedColor(input) ? cssColors[input.toLowerCase()] : input;
1382
- const from = getColorModel(value);
1383
- if (from === output) return value;
1384
- const converter = converters_exports[`${from}2${output}`];
1385
- if (!converter) throw new Error(`Converter not found for ${from} to ${output}`);
1386
- return converter(value);
1387
- }
1388
- function formatCSS(input, options = {}) {
1389
- invariant(isHex(input) || isValidColorModel(input), MESSAGES.invalid);
1390
- const { alpha, format = "hex", precision = PRECISION, separator: baseSeparator = " " } = options;
1391
- const opacity2 = alpha && alpha !== 1 ? `${round$1(alpha * 100)}%` : null;
1392
- let params = [];
1393
- let separator = baseSeparator;
1394
- switch (format) {
1395
- case "hsl": {
1396
- const { h, s, l } = getColorValue(input, "hsl");
1397
- params = [
1398
- h,
1399
- `${s}%`,
1400
- `${l}%`
1401
- ];
1402
- break;
1403
- }
1404
- case "oklab": {
1405
- separator = " ";
1406
- const { l, a, b } = restrictValues(getColorValue(input, "oklab"), precision);
1407
- params = [
1408
- `${round$1(l * 100, precision)}%`,
1409
- a,
1410
- b
1411
- ];
1412
- break;
1413
- }
1414
- case "oklch": {
1415
- separator = " ";
1416
- const { l, c, h } = restrictValues(getColorValue(input, "oklch"), precision);
1417
- params = [
1418
- `${round$1(l * 100, precision)}%`,
1419
- c,
1420
- h
1421
- ];
1422
- break;
1423
- }
1424
- case "rgb": {
1425
- const { r, g, b } = getColorValue(input, "rgb");
1426
- params = [
1427
- r,
1428
- g,
1429
- b
1430
- ];
1431
- break;
1432
- }
1433
- default: {
1434
- const hex = removeAlphaFromHex(getColorValue(input, "hex"));
1435
- if (alpha && alpha !== 1) return `${hex}${convertAlphaToHex(alpha)}`;
1436
- return hex;
1437
- }
1438
- }
1439
- return `${format}(${params.join(separator)}${opacity2 ? ` / ${opacity2}` : ""})`;
1440
- }
1441
- function updater(key, operator, format) {
1442
- return (input, amount) => {
1443
- invariant(isString(input), MESSAGES.inputString);
1444
- invariant(isNumberInRange(amount, 0, 100), MESSAGES.amount);
1445
- const color = parseCSS(input, "hsl");
1446
- const output = isHex(input) || isNamedColor(input) ? "hex" : extractColorParts(input).model;
1447
- return formatCSS({
1448
- ...color,
1449
- [key]: clamp$1(color[key] + (operator === "+" ? amount : -amount), 0, 100)
1450
- }, { format: format ?? output });
1451
- };
1452
- }
1453
- function darken(input, amount, format) {
1454
- return updater("l", "-", format)(input, amount);
1455
- }
1456
- function desaturate(input, amount, format) {
1457
- return updater("s", "-", format)(input, amount);
1458
- }
1459
- function grayscale(input, format) {
1460
- invariant(isString(input), MESSAGES.inputString);
1461
- const output = isHex(input) || isNamedColor(input) ? "hex" : extractColorParts(input).model;
1462
- const lch = parseCSS(input, "oklch");
1463
- return formatCSS({
1464
- ...lch,
1465
- c: 0
1466
- }, {
1467
- format: format ?? output,
1468
- alpha: lch.alpha
1469
- });
1470
- }
1471
- function rotate(input, degrees, format) {
1472
- invariant(isString(input), MESSAGES.inputString);
1473
- invariant(isNumberInRange(degrees, -360, 360), MESSAGES.degreesRange);
1474
- const color = parseCSS(input, "hsl");
1475
- const output = isHex(input) || isNamedColor(input) ? "hex" : extractColorParts(input).model;
1476
- return formatCSS({
1477
- ...color,
1478
- h: constrainDegrees(color.h, degrees)
1479
- }, { format: format ?? output });
1480
- }
1481
- function invert(input) {
1482
- invariant(isString(input), MESSAGES.inputString);
1483
- const format = isHex(input) || isNamedColor(input) ? "hex" : extractColorParts(input).model;
1484
- return formatCSS(rotate(parseCSS(input, "hex"), 180), { format });
1485
- }
1486
- function lighten(input, amount, format) {
1487
- return updater("l", "+", format)(input, amount);
1488
- }
1489
- function interpolateHue(h1, h2, c1, c2, ratio) {
1490
- if (c1 < 1e-4) return h2;
1491
- if (c2 < 1e-4) return h1;
1492
- let diff = h2 - h1;
1493
- if (diff > 180) diff -= 360;
1494
- else if (diff < -180) diff += 360;
1495
- let result = h1 + diff * ratio;
1496
- if (result < 0) result += 360;
1497
- else if (result >= 360) result -= 360;
1498
- return result;
1499
- }
1500
- function mix(color1, color2, ratio = .5, format) {
1501
- invariant(isString(color1), MESSAGES.inputString);
1502
- invariant(isString(color2), MESSAGES.inputString);
1503
- invariant(isNumberInRange(ratio, 0, 1), MESSAGES.ratioRange);
1504
- const output = isHex(color1) || isNamedColor(color1) ? "hex" : extractColorParts(color1).model;
1505
- const lch1 = parseCSS(color1, "oklch");
1506
- const lch2 = parseCSS(color2, "oklch");
1507
- const l = lch1.l + (lch2.l - lch1.l) * ratio;
1508
- const c = lch1.c + (lch2.c - lch1.c) * ratio;
1509
- const h = interpolateHue(lch1.h, lch2.h, lch1.c, lch2.c, ratio);
1510
- const alpha1 = lch1.alpha ?? 1;
1511
- const alpha = alpha1 + ((lch2.alpha ?? 1) - alpha1) * ratio;
1512
- return formatCSS({
1513
- l,
1514
- c,
1515
- h
1516
- }, {
1517
- format: format ?? output,
1518
- alpha: alpha < 1 ? alpha : void 0
1519
- });
1520
- }
1521
- function parseColor(color) {
1522
- invariant(!!color, MESSAGES.input);
1523
- const output = {};
1524
- if (isString(color)) {
1525
- const { alpha = 1 } = extractColorParts(color);
1526
- const type = isHex(color) ? "hex" : extractColorParts(color).model;
1527
- output.hex = addAlphaToHex(parseCSS(color, "hex"), alpha);
1528
- output.hsl = addAlpha(parseCSS(color, "hsl"), alpha);
1529
- output.oklab = addAlpha(parseCSS(color, "oklab"), alpha);
1530
- output.oklch = addAlpha(parseCSS(color, "oklch"), alpha);
1531
- output.rgb = addAlpha(parseCSS(color, "rgb"), alpha);
1532
- output.alpha = alpha;
1533
- output.type = type;
1534
- } else if (isPlainObject(color)) {
1535
- const { alpha = 1 } = color;
1536
- if (isHSL(color)) {
1537
- output.hsl = {
1538
- h: limit(color.h, "hsl", "h"),
1539
- s: limit(color.s, "hsl", "s"),
1540
- l: limit(color.l, "hsl", "l")
1541
- };
1542
- output.rgb = hsl2rgb(output.hsl);
1543
- output.oklab = hsl2oklab(output.hsl);
1544
- output.oklch = hsl2oklch(output.hsl);
1545
- output.type = "hsl";
1546
- } else if (isLAB(color)) {
1547
- output.hsl = oklab2hsl(color);
1548
- output.oklab = color;
1549
- output.oklch = oklab2oklch(color);
1550
- output.rgb = oklab2rgb(color);
1551
- output.type = "oklab";
1552
- } else if (isLCH(color)) {
1553
- output.hsl = oklch2hsl(color);
1554
- output.oklab = oklch2oklab(color);
1555
- output.oklch = color;
1556
- output.rgb = oklch2rgb(color);
1557
- output.type = "oklch";
1558
- } else if (isRGB(color)) {
1559
- output.rgb = {
1560
- r: limit(color.r, "rgb", "r"),
1561
- g: limit(color.g, "rgb", "g"),
1562
- b: limit(color.b, "rgb", "b")
1563
- };
1564
- output.hsl = rgb2hsl(output.rgb);
1565
- output.oklab = rgb2oklab(output.rgb);
1566
- output.oklch = rgb2oklch(output.rgb);
1567
- output.type = "rgb";
1568
- } else throw new Error("invalid color");
1569
- output.hex = addAlphaToHex(hsl2hex(output.hsl), alpha);
1570
- output.hsl = addAlpha(output.hsl, alpha);
1571
- output.oklab = addAlpha(output.oklab, alpha);
1572
- output.oklch = addAlpha(output.oklch, alpha);
1573
- output.rgb = addAlpha(output.rgb, alpha);
1574
- output.alpha = alpha;
1575
- } else throw new Error(MESSAGES.input);
1576
- return output;
1577
- }
1578
- function opacify(input, alpha, format) {
1579
- invariant(isString(input), MESSAGES.inputString);
1580
- invariant(isNumberInRange(alpha, 0, 1), MESSAGES.alpha);
1581
- const type = isHex(input) || isNamedColor(input) ? "hex" : extractColorParts(input).model;
1582
- return formatCSS(parseCSS(input, "rgb"), {
1583
- format: format ?? type,
1584
- alpha
1585
- });
1586
- }
1587
- function opacity(input) {
1588
- invariant(isString(input), MESSAGES.inputString);
1589
- if (isHex(input)) return extractAlphaFromHex(input);
1590
- else if (Object.keys(cssColors).includes(input)) return 1;
1591
- const { alpha } = extractColorParts(input);
1592
- if (!alpha) return 1;
1593
- return alpha;
1594
- }
1595
- function pickByContrast(darkContrast, lightContrast, darkColor, lightColor) {
1596
- return darkContrast >= lightContrast ? darkColor : lightColor;
1597
- }
1598
- function readableColor(backgroundColor, options = {}) {
1599
- const { darkColor = "#000000", lightColor = "#ffffff", method = "yiq", threshold } = options;
1600
- invariant(isString(backgroundColor), MESSAGES.inputString);
1601
- switch (method) {
1602
- case "yiq": {
1603
- const yiqThreshold = threshold ?? 128;
1604
- invariant(yiqThreshold >= 0 && yiqThreshold <= 255, MESSAGES.threshold);
1605
- const { r, g, b } = hex2rgb(parseCSS(backgroundColor, "hex"));
1606
- return (r * 299 + g * 587 + b * 114) / 1e3 >= yiqThreshold ? darkColor : lightColor;
1607
- }
1608
- case "wcag": {
1609
- const wcagThreshold = threshold ?? .5;
1610
- invariant(wcagThreshold >= 0 && wcagThreshold <= 1, MESSAGES.thresholdNormalized);
1611
- return luminance(backgroundColor) >= wcagThreshold ? darkColor : lightColor;
1612
- }
1613
- case "contrast": return pickByContrast(contrast(darkColor, backgroundColor), contrast(lightColor, backgroundColor), darkColor, lightColor);
1614
- case "oklab": {
1615
- const oklabThreshold = threshold ?? .5;
1616
- invariant(oklabThreshold >= 0 && oklabThreshold <= 1, MESSAGES.thresholdNormalized);
1617
- const { l } = hex2oklab(parseCSS(backgroundColor, "hex"));
1618
- return l >= oklabThreshold ? darkColor : lightColor;
1619
- }
1620
- case "apca": return pickByContrast(Math.abs(apcaContrast(backgroundColor, darkColor)), Math.abs(apcaContrast(backgroundColor, lightColor)), darkColor, lightColor);
1621
- default: throw new Error(`Unknown method: ${method}`);
1622
- }
1623
- }
1624
- function saturate(input, amount, format) {
1625
- return updater("s", "+", format)(input, amount);
1626
- }
1627
- function transparentize(input, alpha, format) {
1628
- invariant(isString(input), MESSAGES.inputString);
1629
- invariant(isNumberInRange(alpha, -1, 1), MESSAGES.alphaAdjustment);
1630
- return formatCSS(parseCSS(input, "oklab"), {
1631
- format,
1632
- alpha: round$1(clamp$1(opacity(input) - alpha, 0, 1))
1633
- });
1634
- }
1635
- var Colorizr = class {
1636
- constructor(color, options = {}) {
1637
- /** The alpha/opacity value (0-1). */
1638
- __publicField(this, "alpha");
1639
- __publicField(this, "hex");
1640
- __publicField(this, "hsl");
1641
- __publicField(this, "oklab");
1642
- __publicField(this, "oklch");
1643
- __publicField(this, "rgb");
1644
- __publicField(this, "type");
1645
- invariant(!!color, MESSAGES.colorRequired);
1646
- const { alpha, hex, hsl, oklab, oklch, rgb, type } = parseColor(color);
1647
- this.hex = hex;
1648
- this.hsl = hsl;
1649
- this.oklab = oklab;
1650
- this.oklch = oklch;
1651
- this.rgb = rgb;
1652
- this.alpha = alpha;
1653
- this.type = options.format ?? type;
1654
- }
1655
- /**
1656
- * Get CSS string
1657
- */
1658
- get css() {
1659
- return this.currentColor;
1660
- }
1661
- /**
1662
- * Get the red value
1663
- */
1664
- get red() {
1665
- return this.rgb.r;
1666
- }
1667
- /**
1668
- * Get the green value
1669
- */
1670
- get green() {
1671
- return this.rgb.g;
1672
- }
1673
- /**
1674
- * Get the blue value
1675
- */
1676
- get blue() {
1677
- return this.rgb.b;
1678
- }
1679
- /**
1680
- * Get the hue value
1681
- */
1682
- get hue() {
1683
- return this.hsl.h;
1684
- }
1685
- /**
1686
- * Get the saturation value
1687
- */
1688
- get saturation() {
1689
- return this.hsl.s;
1690
- }
1691
- /**
1692
- * Get the lightness value
1693
- */
1694
- get lightness() {
1695
- return this.hsl.l;
1696
- }
1697
- /**
1698
- * Get the luminance value
1699
- */
1700
- get luminance() {
1701
- return luminance(this.currentColor);
1702
- }
1703
- /**
1704
- * Get the chroma value
1705
- */
1706
- get chroma() {
1707
- return chroma(this.currentColor);
1708
- }
1709
- get opacity() {
1710
- return opacity(this.currentColor);
1711
- }
1712
- /**
1713
- * Get the most readable color (light or dark) for this color as a background.
1714
- */
1715
- get readableColor() {
1716
- return readableColor(this.currentColor);
1717
- }
1718
- get currentColor() {
1719
- return formatCSS(this[this.type], {
1720
- format: this.type,
1721
- alpha: this.alpha
1722
- });
1723
- }
1724
- /**
1725
- * Get the brightness difference between this color and another.
1726
- *
1727
- * @param input - The color to compare against.
1728
- * @returns The brightness difference value.
1729
- */
1730
- brightnessDifference(input) {
1731
- return brightnessDifference(this.currentColor, input);
1732
- }
1733
- /**
1734
- * Get the color difference between this color and another.
1735
- *
1736
- * @param input - The color to compare against.
1737
- * @returns The color difference value.
1738
- */
1739
- colorDifference(input) {
1740
- return colorDifference(this.currentColor, input);
1741
- }
1742
- /**
1743
- * Test 2 colors for WCAG compliance.
1744
- *
1745
- * @param input - The color to compare against.
1746
- * @returns Analysis object with compliance information.
1747
- */
1748
- compare(input) {
1749
- return compare(this.currentColor, input);
1750
- }
1751
- /**
1752
- * Get the contrast ratio between this color and another.
1753
- *
1754
- * @param input - The color to compare against.
1755
- * @returns The contrast ratio.
1756
- */
1757
- contrast(input) {
1758
- return contrast(this.currentColor, input);
1759
- }
1760
- /**
1761
- * Format the color to a specific type.
1762
- *
1763
- * @param type - The color format to convert to.
1764
- * @param precision - The decimal precision for the output.
1765
- * @returns The formatted color string.
1766
- */
1767
- format(type, precision) {
1768
- return formatCSS(this.rgb, {
1769
- alpha: this.alpha,
1770
- format: type,
1771
- precision
1772
- });
1773
- }
1774
- /**
1775
- * Increase lightness.
1776
- *
1777
- * @param amount - A number between 0 and 100.
1778
- * @returns The lightened color string.
1779
- */
1780
- lighten(amount) {
1781
- return lighten(this.currentColor, amount);
1782
- }
1783
- /**
1784
- * Decrease lightness.
1785
- *
1786
- * @param amount - A number between 0 and 100.
1787
- * @returns The darkened color string.
1788
- */
1789
- darken(amount) {
1790
- return darken(this.currentColor, amount);
1791
- }
1792
- /**
1793
- * Increase saturation.
1794
- *
1795
- * @param amount - A number between 0 and 100.
1796
- * @returns The saturated color string.
1797
- */
1798
- saturate(amount) {
1799
- return saturate(this.currentColor, amount);
1800
- }
1801
- /**
1802
- * Decrease saturation.
1803
- *
1804
- * @param amount - A number between 0 and 100.
1805
- * @returns The desaturated color string.
1806
- */
1807
- desaturate(amount) {
1808
- return desaturate(this.currentColor, amount);
1809
- }
1810
- /**
1811
- * Convert to grayscale.
1812
- *
1813
- * @returns The grayscale color string.
1814
- */
1815
- grayscale() {
1816
- return grayscale(this.currentColor);
1817
- }
1818
- /**
1819
- * Invert color.
1820
- *
1821
- * @returns The inverted color string.
1822
- */
1823
- invert() {
1824
- return invert(this.currentColor);
1825
- }
1826
- /**
1827
- * Mix with another color.
1828
- *
1829
- * @param color - The color to mix with.
1830
- * @param ratio - A number between 0 and 1 (0 = this color, 1 = input color).
1831
- * @returns The mixed color string.
1832
- */
1833
- mix(color, ratio) {
1834
- return mix(this.currentColor, color, ratio);
1835
- }
1836
- /**
1837
- * Add opacity to the color.
1838
- *
1839
- * @param alpha - A number between 0 and 1.
1840
- * @returns The opacified color string.
1841
- */
1842
- opacify(alpha = .9) {
1843
- return opacify(this.currentColor, alpha, this.type);
1844
- }
1845
- /**
1846
- * Rotate color hue.
1847
- *
1848
- * @param degrees - A number between -360 and 360.
1849
- * @returns The rotated color string.
1850
- */
1851
- rotate(degrees) {
1852
- return rotate(this.currentColor, degrees);
1853
- }
1854
- /**
1855
- * Make the color more transparent.
1856
- *
1857
- * @param alpha - A number between -1 and 1.
1858
- * @returns The transparentized color string.
1859
- */
1860
- transparentize(alpha = .1) {
1861
- return transparentize(this.currentColor, alpha, this.type);
1862
- }
1863
- };
1864
- function convert$1(input, format) {
1865
- return formatCSS(parseCSS(input, format), { format });
1866
- }
1867
- /* v8 ignore next 3 -- @preserve */
1868
- function isHsl(v) {
1869
- if (typeof v !== `object`) return false;
1870
- if (!(`h` in v)) return false;
1871
- if (!(`s` in v)) return false;
1872
- if (!(`l` in v)) return false;
1873
- if (!(`unit` in v)) return false;
1874
- if (!(`space` in v)) return false;
1875
- if (v.space !== `hsl`) return false;
1876
- return true;
1877
- }
1878
- function isRgb(v) {
1879
- if (typeof v !== `object`) return false;
1880
- if (!(`r` in v)) return false;
1881
- if (!(`g` in v)) return false;
1882
- if (!(`b` in v)) return false;
1883
- if (!(`space` in v)) return false;
1884
- if (!(`unit` in v)) return false;
1885
- if (v.space === `srgb`) return true;
1886
- return false;
1887
- }
1888
- /**
1889
- * If the input object has r,g&b properties, it will return a fully-
1890
- * formed Rgb type with `unit` and `space` properties.
1891
- *
1892
- * If it lacks these basic three properties or they are out of range,
1893
- * _undefined_ is returned.
1894
- *
1895
- * If RGB values are less than 1 assumes unit:scalar. Otherwise unit:8bit.
1896
- * If RGB values exceed 255, _undefined_ returned.
1897
- * @param v
1898
- * @returns
1899
- */
1900
- function tryParseObjectToRgb(v) {
1901
- if (typeof v !== `object`) throw new TypeError(`Param 'v' is expected to be an object, got: ${typeof v}`);
1902
- if (!(`r` in v && `g` in v && `b` in v)) return;
1903
- if (!(`unit` in v)) if (v.r <= 1 && v.g <= 1 && v.b <= 1) v.unit = `scalar`;
1904
- else if (v.r > 255 && v.g <= 255 && v.b <= 255) return;
1905
- else v.unit = `8bit`;
1906
- if (!(`space` in v)) v.space = `srgb`;
1907
- return v;
1908
- }
1909
- function tryParseObjectToHsl(v) {
1910
- if (!(`h` in v && `s` in v && `l` in v)) return;
1911
- if (!(`unit` in v)) if (v.s <= 1 && v.l <= 1) v.unit = `scalar`;
1912
- else if (v.s > 100 || v.l > 100) return;
1913
- else v.unit = `absolute`;
1914
- if (!(`space` in v)) v.space = `hsl`;
1915
- return v;
1916
- }
1917
- function isOkLch(v) {
1918
- if (typeof v !== `object`) return false;
1919
- if (!(`l` in v)) return false;
1920
- if (!(`c` in v)) return false;
1921
- if (!(`h` in v)) return false;
1922
- if (!(`unit` in v)) return false;
1923
- if (!(`space` in v)) return false;
1924
- if (v.space === `lch`) return true;
1925
- if (v.space === `oklch`) return true;
1926
- return false;
1927
- }
1928
- function isColourish(v) {
1929
- if (typeof v === `string`) return true;
1930
- if (typeof v !== `object`) return false;
1931
- if (isHsl(v)) return true;
1932
- if (isOkLch(v)) return true;
1933
- if (isRgb(v)) return true;
1934
- return false;
1935
- }
1936
- function calculateHueDistance(a, b, limit = 1) {
1937
- let long = -1;
1938
- let short = -1;
1939
- if (b < a) {
1940
- long = b - a;
1941
- short = limit - (a - b);
1942
- } else {
1943
- long = b - a;
1944
- short = long - limit;
1945
- }
1946
- const forward = short > 0 ? short : long;
1947
- const backward = short > 0 ? long : short;
1948
- if (Math.abs(long) < Math.abs(short)) {
1949
- const t = short;
1950
- short = long;
1951
- long = t;
1952
- }
1953
- return {
1954
- long,
1955
- short,
1956
- forward,
1957
- backward
1958
- };
1959
- }
1960
- function libraryRgbToHexString(rgb) {
1961
- const componentToHex = (c) => {
1962
- const hex = Math.floor(c).toString(16);
1963
- return hex.length === 1 ? `0${hex}` : hex;
1964
- };
1965
- let part = `#${componentToHex(rgb.r)}${componentToHex(rgb.g)}${componentToHex(rgb.b)}`;
1966
- if (typeof rgb.alpha !== `undefined` && rgb.alpha !== 255) part += componentToHex(rgb.alpha);
1967
- return part;
1968
- }
1969
- function wrapScalarHue(value) {
1970
- value = value % 1;
1971
- if (value < 0) return (1 - Math.abs(value)) % 1;
1972
- return value;
1973
- }
1974
- var hsl_exports = /* @__PURE__ */ __exportAll({
1975
- absolute: () => absolute$1,
1976
- changeLightness: () => changeLightness$1,
1977
- fromCss: () => fromCss$3,
1978
- fromHexString: () => fromHexString$3,
1979
- generateScalar: () => generateScalar$1,
1980
- guard: () => guard$4,
1981
- interpolator: () => interpolator$3,
1982
- parseCssHslFunction: () => parseCssHslFunction,
1983
- scalar: () => scalar$3,
1984
- toAbsolute: () => toAbsolute$1,
1985
- toCssString: () => toCssString$2,
1986
- toHexString: () => toHexString$3,
1987
- toLibraryRgb: () => toLibraryRgb,
1988
- toScalar: () => toScalar$3,
1989
- withOpacity: () => withOpacity$3
1990
- });
1991
- /**
1992
- * Scales the opacity value of an input HSL value
1993
- * ```js
1994
- * withOpacity()
1995
- * ```
1996
- * @param value Colour
1997
- * @param fn Function that calcules opacity based on input scalar value
1998
- */
1999
- function withOpacity$3(value, fn) {
2000
- switch (value.unit) {
2001
- case `absolute`: return {
2002
- ...value,
2003
- opacity: fn((value.opacity ?? 100) / 100, value) * 100
2004
- };
2005
- case `scalar`: return {
2006
- ...value,
2007
- opacity: fn(value.opacity ?? 1, value)
2008
- };
2009
- }
2010
- }
2011
- /**
2012
- * Increases or decreases lightness by this percentage, returning new colour
2013
- *
2014
- * Amount to change:
2015
- * 'fixed': a fixed amount
2016
- * 'delta': increase/decrease by this amount
2017
- * 'pdelta': proportion of current value to change by ('percentage delta')
2018
- *
2019
- * ```
2020
- * const colour = { h: 0.5, s: 0.5, l: 0.5, space: `hsl`, unit: `scalar` };
2021
- * changeLightness(colour, { pdelta: 0.1 }); // l: 0.55
2022
- * changeLightness(colour, { delta: 0.1 }); // l: 0.6
2023
- * changeLightness(colour, { fixed: 0.5 }); // l: 0.5
2024
- * ```
2025
- *
2026
- * Keep in mind the numerical value will depend on the unit of `value`. If it's scalar,
2027
- * lightness is 0..1 scale, otherwise 0..100 scale.
2028
- *
2029
- * Use negative values to decrease (does not apply to 'fixed')
2030
- * @param value Hsl colour
2031
- * @param amount Amount to change
2032
- */
2033
- function changeLightness$1(value, amount) {
2034
- let newL = 0;
2035
- if (typeof amount.pdelta !== `undefined`) newL = value.l + value.l * amount.pdelta;
2036
- else if (typeof amount.delta !== `undefined`) newL = amount.delta + value.l;
2037
- else if (typeof amount.fixed !== `undefined`) {
2038
- if (amount.fixed < 0) throw new TypeError(`Cannot use negative value with 'fixed'`);
2039
- newL = amount.fixed;
2040
- } else throw new TypeError(`Parameter 'amount' is missing 'delta/pdelta/fixed' properties`);
2041
- return {
2042
- ...value,
2043
- l: scaleProperty(value, newL, `l`)
2044
- };
2045
- }
2046
- function scaleProperty(hsl, value, property) {
2047
- if (hsl.unit === `scalar`) {
2048
- if (value > 1) value = 1;
2049
- else if (value < 0) value = 0;
2050
- } else if (value > 100) value = 100;
2051
- else if (value < 0) value = 0;
2052
- return value;
2053
- }
2054
- const hslTransparent = Object.freeze({
2055
- h: 0,
2056
- s: 0,
2057
- l: 0,
2058
- opacity: 0,
2059
- unit: `absolute`,
2060
- space: `hsl`
2061
- });
2062
- function fromHexString$3(hexString, options = {}) {
2063
- return fromLibrary$2(hex2hsl(hexString), options);
2064
- }
2065
- function fromCss$3(value, options = {}) {
2066
- value = value.toLowerCase();
2067
- if (value.startsWith(`hsla(`)) throw new Error(`hsla() not supported`);
2068
- if (value.startsWith(`rgba(`)) throw new Error(`rgba() not supported`);
2069
- if (value.startsWith(`#`)) return fromHexString$3(value, options);
2070
- if (value.startsWith(`--`)) try {
2071
- value = resolveCss(value);
2072
- } catch (error) {
2073
- if (typeof options.fallbackString !== `undefined`) value = options.fallbackString;
2074
- if (typeof options.fallbackColour !== `undefined`) return options.fallbackColour;
2075
- throw error;
2076
- }
2077
- if (value === `transparent`) return hslTransparent;
2078
- if (typeof cssDefinedHexColours[value] !== `undefined`) return fromHexString$3(cssDefinedHexColours[value], options);
2079
- if (value.startsWith(`rgb(`)) return fromLibrary$2(toLibraryHsl(value), options);
2080
- if (!value.startsWith(`hsl(`)) try {
2081
- value = convert$1(value, `hsl`);
2082
- } catch (error) {
2083
- if (options.fallbackString) value = options.fallbackString;
2084
- else throw error;
2085
- }
2086
- try {
2087
- const hsl = parseCssHslFunction(value);
2088
- if (options.scalar) return toScalar$3(hsl);
2089
- return toAbsolute$1(hsl);
2090
- } catch (error) {
2091
- if (options.fallbackColour) return options.fallbackColour;
2092
- throw error;
2093
- }
2094
- }
2095
- function toCssString$2(hsl) {
2096
- const abs = toAbsolute$1(hsl);
2097
- let css = `hsl(${abs.h}deg ${abs.s}% ${abs.l}%`;
2098
- if (`opacity` in abs && abs.opacity !== void 0 && abs.opacity < 100) css += ` / ${abs.opacity}%`;
2099
- css += `)`;
2100
- return css;
2101
- }
2102
- function toHexString$3(hsl) {
2103
- return libraryRgbToHexString(toLibraryRgb(hsl));
2104
- }
2105
- function fromLibrary$2(hsl, parsingOptions = {}) {
2106
- if (typeof hsl === `undefined` || hsl === null) {
2107
- if (parsingOptions.fallbackColour) return parsingOptions.fallbackColour;
2108
- }
2109
- const scalarOpt = parsingOptions.scalar ?? true;
2110
- resultThrow(numberInclusiveRangeTest(hsl.h, 0, 360, `h`), numberInclusiveRangeTest(hsl.s, 0, 100, `s`), numberInclusiveRangeTest(hsl.l, 0, 100, `l`), percentTest(hsl.alpha ?? 1, `alpha`));
2111
- if (scalarOpt) return scalar$3(hsl.h / 360, hsl.s / 100, hsl.l / 100, hsl.alpha ?? 1);
2112
- else return absolute$1(hsl.h, hsl.s, hsl.l, (hsl.alpha ?? 1) * 100);
2113
- }
2114
- function toAbsolute$1(hslOrString) {
2115
- if (typeof hslOrString === `string`) return fromCss$3(hslOrString, { scalar: false });
2116
- if (isRgb(hslOrString)) return toAbsolute$1(fromLibrary$2(toLibraryHsl(hslOrString), { scalar: false }));
2117
- const hsl = hslOrString;
2118
- guard$4(hsl);
2119
- if (hsl.unit === `absolute`) return hsl;
2120
- return {
2121
- h: hsl.h * 360,
2122
- s: hsl.s * 100,
2123
- l: hsl.l * 100,
2124
- opacity: (hsl.opacity ?? 1) * 100,
2125
- unit: `absolute`,
2126
- space: `hsl`
2127
- };
2128
- }
2129
- /**
2130
- * Generates a {@link HslScalar} value.
2131
- *
2132
- * ```js
2133
- * generateScaler(10); // 10deg, default to full saturation, half lightness and full opacity
2134
- *
2135
- * // Generate HSL value from radian angle and 50% saturation
2136
- * generateScalar(`10rad`, 0.5);
2137
- *
2138
- * // Generate from numeric CSS variable
2139
- * generateScalar(`--hue`);
2140
- * ```
2141
- * @param absoluteHslOrVariable Hue angle or CSS variable
2142
- * @param saturation
2143
- * @param lightness
2144
- * @param opacity
2145
- */
2146
- function generateScalar$1(absoluteHslOrVariable, saturation = 1, lightness = .5, opacity = 1) {
2147
- if (typeof absoluteHslOrVariable === `string`) {
2148
- if (absoluteHslOrVariable.startsWith(`--`)) absoluteHslOrVariable = getComputedStyle(document.body).getPropertyValue(absoluteHslOrVariable).trim();
2149
- }
2150
- const hue = angleParse(absoluteHslOrVariable);
2151
- if (saturation > 1) throw new TypeError(`Param 'saturation' must be between 0..1`);
2152
- if (lightness > 1) throw new TypeError(`Param 'lightness' must be between 0..1`);
2153
- if (opacity > 1) throw new TypeError(`Param 'opacity' must be between 0..1`);
2154
- return {
2155
- h: angleConvert(hue, `deg`).value / 360,
2156
- s: saturation,
2157
- l: lightness,
2158
- opacity,
2159
- unit: `scalar`,
2160
- space: `hsl`
2161
- };
2162
- }
2163
- /**
2164
- * Converts a {@link Hsl} value to scalar units, or parses a colour string
2165
- * and converts it.
2166
- *
2167
- * ```js
2168
- * toScalar({ h: 100, s: 50, l: 100, unit: `absolute` });
2169
- * toScalar(`red`);
2170
- * ```
2171
- * @param colour
2172
- */
2173
- function toScalar$3(colour) {
2174
- if (typeof colour === `string`) return fromCss$3(colour, { scalar: true });
2175
- if (isRgb(colour)) return toScalar$3(fromLibrary$2(toLibraryHsl(colour), { scalar: true }));
2176
- const hsl = colour;
2177
- guard$4(hsl);
2178
- if (hsl.unit === `scalar`) return hsl;
2179
- return {
2180
- h: hsl.h / 360,
2181
- s: hsl.s / 100,
2182
- l: hsl.l / 100,
2183
- opacity: (hsl.opacity ?? 1) / 100,
2184
- unit: `scalar`,
2185
- space: `hsl`
2186
- };
2187
- }
2188
- function guard$4(hsl) {
2189
- const { h, s, l, opacity, space, unit } = hsl;
2190
- if (space !== `hsl`) throw new Error(`Space is expected to be 'hsl'. Got: ${space}`);
2191
- if (unit === `absolute`) resultThrow(numberTest(h, `finite`, `h`), numberInclusiveRangeTest(s, 0, 100, `s`), numberInclusiveRangeTest(l, 0, 100, `l`), () => {
2192
- if (typeof opacity === `number`) return numberInclusiveRangeTest(opacity, 0, 100, `opacity`);
2193
- });
2194
- else if (unit === `scalar`) resultThrow(numberTest(h, `percentage`, `h`), numberTest(s, `percentage`, `s`), numberTest(l, `percentage`, `l`), () => {
2195
- if (typeof opacity === `number`) return numberTest(opacity, `percentage`, `opacity`);
2196
- });
2197
- else throw new Error(`Unit is expected to be 'absolute' or 'scalar'. Got: ${unit}`);
2198
- }
2199
- function interpolator$3(a, b, direction = `shorter`) {
2200
- a = toScalar$3(a);
2201
- b = toScalar$3(b);
2202
- const aOpacity = a.opacity ?? 1;
2203
- const distanceCalc = calculateHueDistance(a.h, b.h, 1);
2204
- const hueDistance = direction === `longer` ? distanceCalc.long : distanceCalc.short;
2205
- const satDistance = b.s - a.s;
2206
- const lightDistance = b.l - a.l;
2207
- const opacityDistance = (b.opacity ?? 1) - aOpacity;
2208
- return (amount) => {
2209
- amount = clamp(amount);
2210
- let h = interpolate(amount, 0, Math.abs(hueDistance));
2211
- if (hueDistance < 0) h = a.h - h;
2212
- else h = a.h + h;
2213
- const s = interpolate(amount, 0, satDistance);
2214
- const l = interpolate(amount, 0, lightDistance);
2215
- const o = interpolate(amount, 0, opacityDistance);
2216
- return scalar$3(wrapScalarHue(h), s + a.s, l + a.l, o + aOpacity);
2217
- };
2218
- }
2219
- /**
2220
- * Creates a HslScalar value from scalar (0..1) values
2221
- * @param hue
2222
- * @param sat
2223
- * @param lightness
2224
- * @param opacity
2225
- */
2226
- function scalar$3(hue = .5, sat = 1, lightness = .5, opacity = 1) {
2227
- const hsl = {
2228
- unit: `scalar`,
2229
- space: `hsl`,
2230
- h: hue,
2231
- s: sat,
2232
- l: lightness,
2233
- opacity
2234
- };
2235
- guard$4(hsl);
2236
- return hsl;
2237
- }
2238
- function absolute$1(hue = 200, sat = 100, lightness = 50, opacity = 100) {
2239
- const hsl = {
2240
- unit: `absolute`,
2241
- space: `hsl`,
2242
- h: hue,
2243
- s: sat,
2244
- l: lightness,
2245
- opacity
2246
- };
2247
- guard$4(hsl);
2248
- return hsl;
2249
- }
2250
- /**
2251
- * It seems Colorizr can't handle 'deg' units
2252
- * @param value
2253
- */
2254
- function parseCssHslFunction(value) {
2255
- if (value.startsWith(`hsla`)) throw new Error(`hsla() is not supported`);
2256
- if (!value.startsWith(`hsl(`)) throw new Error(`Expected hsl(..) CSS colour`);
2257
- const start = value.indexOf(`(`);
2258
- const end = value.indexOf(`)`);
2259
- if (end < start) throw new Error(`Is hsl() not terminated? Missing ')'`);
2260
- let split = value.substring(start + 1, end).split(/[\s,]+/);
2261
- if (split.length < 3) throw new Error(`Expected three tokens. Got: ${split.length} length`);
2262
- let returnRelative = false;
2263
- if (split[0].endsWith(`%`)) returnRelative = true;
2264
- if (split[1].endsWith(`%`) && split[2].endsWith(`%`)) returnRelative = true;
2265
- const valueAsScalar = (v, pos) => {
2266
- if (v === `none`) return 0;
2267
- if (v.endsWith(`%`)) return Number.parseFloat(v.substring(0, v.length - 1)) / 100;
2268
- if (v.endsWith(`deg`) && pos === 0) v = v.substring(0, v.length - 3);
2269
- const vf = Number.parseFloat(v);
2270
- if (pos === 0) return vf / 360;
2271
- if (pos === 3) return vf;
2272
- return vf / 100;
2273
- };
2274
- const valueAsAbs = (v, pos) => {
2275
- if (v === `none`) return 0;
2276
- if (v.endsWith(`%`)) {
2277
- const vf = Number.parseFloat(v.substring(0, v.length - 1));
2278
- if (pos === 0) return vf * 360;
2279
- return vf;
2280
- }
2281
- if (v.endsWith(`deg`) && pos === 0) return Number.parseFloat(v.substring(0, v.length - 3));
2282
- return Number.parseFloat(v);
2283
- };
2284
- if (split.length > 3) {
2285
- if (split[3] === `/`) split = [
2286
- split[0],
2287
- split[1],
2288
- split[2],
2289
- split[4]
2290
- ];
2291
- }
2292
- if (returnRelative) return scalar$3(valueAsScalar(split[0], 0), valueAsScalar(split[1], 1), valueAsScalar(split[2], 2), valueAsScalar(split[3] ?? `100%`, 3));
2293
- else return absolute$1(valueAsAbs(split[0], 0), valueAsAbs(split[1], 1), valueAsAbs(split[2], 2), valueAsAbs(split[3] ?? `100%`, 3));
2294
- }
2295
- /**
2296
- * Converts a Hsl structure (or CSS string) to Colorizr's RGB format
2297
- * @param hsl HSL colour
2298
- */
2299
- function toLibraryRgb(hsl) {
2300
- if (typeof hsl === `string`) return toLibraryRgb(fromCss$3(hsl, { scalar: false }));
2301
- hsl = toAbsolute$1(hsl);
2302
- return {
2303
- ...hsl2rgb({
2304
- h: hsl.h,
2305
- s: hsl.s,
2306
- l: hsl.l
2307
- }),
2308
- alpha: (hsl.opacity ?? 100) / 100 * 255
2309
- };
2310
- }
2311
- var srgb_exports = /* @__PURE__ */ __exportAll({
2312
- changeLightness: () => changeLightness,
2313
- eightBit: () => eightBit$1,
2314
- fromCss: () => fromCss$2,
2315
- fromHexString: () => fromHexString$2,
2316
- guard: () => guard$3,
2317
- interpolator: () => interpolator$2,
2318
- lightness: () => lightness,
2319
- parseCssRgbFunction: () => parseCssRgbFunction,
2320
- scalar: () => scalar$2,
2321
- to8bit: () => to8bit$1,
2322
- toCssString: () => toCssString$1,
2323
- toHexString: () => toHexString$2,
2324
- toLibraryHsl: () => toLibraryHsl,
2325
- toScalar: () => toScalar$2,
2326
- withOpacity: () => withOpacity$2
2327
- });
2328
- function withOpacity$2(value, fn) {
2329
- switch (value.unit) {
2330
- case `8bit`: return {
2331
- ...value,
2332
- opacity: fn((value.opacity ?? 255) / 255, value) * 255
2333
- };
2334
- case `scalar`: return {
2335
- ...value,
2336
- opacity: fn(value.opacity ?? 1, value)
2337
- };
2338
- }
2339
- }
2340
- function fromHexString$2(hexString, scalar = true) {
2341
- return fromLibrary$1(hex2rgb(hexString), { scalar });
2342
- }
2343
- const srgbTansparent = Object.freeze({
2344
- r: 0,
2345
- g: 0,
2346
- b: 0,
2347
- opacity: 0,
2348
- unit: `8bit`,
2349
- space: `srgb`
2350
- });
2351
- /**
2352
- * Converts a colour in a legal CSS form into Rgb value, by default RgbScalar (0..1) scale.
2353
- * ```js
2354
- * fromCss(`rebeccapurple`);
2355
- * fromCss(`rgb(40% 20% 60%)`);
2356
- *
2357
- * // Get 8bit version on 0..255 scale
2358
- * fromCss(`blue`, { scalar: false });
2359
- * ```
2360
- *
2361
- * @param value
2362
- * @param options
2363
- */
2364
- function fromCss$2(value, options = {}) {
2365
- value = value.toLowerCase();
2366
- if (value.startsWith(`hsla(`)) throw new Error(`hsla() not supported`);
2367
- if (value.startsWith(`rgba(`)) throw new Error(`rgba() not supported`);
2368
- const scalar = options.scalar ?? true;
2369
- if (value.startsWith(`#`)) return fromHexString$2(value, scalar);
2370
- if (value === `transparent`) return srgbTansparent;
2371
- if (typeof cssDefinedHexColours[value] !== `undefined`) return fromHexString$2(cssDefinedHexColours[value], scalar);
2372
- if (value.startsWith(`hsl(`)) return fromLibrary$1(toLibraryRgb(value), options);
2373
- if (!value.startsWith(`rgb(`)) try {
2374
- value = convert$1(value, `rgb`);
2375
- } catch (error) {
2376
- if (options.fallbackString) value = options.fallbackString;
2377
- else throw error;
2378
- }
2379
- try {
2380
- const rgb = parseCssRgbFunction(value);
2381
- if (scalar) return toScalar$2(rgb);
2382
- return to8bit$1(rgb);
2383
- } catch (error) {
2384
- if (options.fallbackColour) return options.fallbackColour;
2385
- throw error;
2386
- }
2387
- }
2388
- function toHexString$2(rgb) {
2389
- return libraryRgbToHexString(toLibrary$1(rgb));
2390
- }
2391
- function toCssString$1(rgb) {
2392
- guard$3(rgb);
2393
- switch (rgb.unit) {
2394
- case `8bit`:
2395
- if (rgb.opacity === void 0 || rgb.opacity === 255) return `rgb(${rgb.r} ${rgb.g} ${rgb.b})`;
2396
- return `rgb(${rgb.r} ${rgb.g} ${rgb.b} / ${(rgb.opacity ?? 255) / 255})`;
2397
- case `scalar`:
2398
- if (rgb.opacity === void 0 || rgb.opacity === 1) return `rgb(${rgb.r * 100}% ${rgb.g * 100}% ${rgb.b * 100}%)`;
2399
- return `rgb(${rgb.r * 100}% ${rgb.g * 100}% ${rgb.b * 100}% / ${(rgb.opacity ?? 1) * 100}%)`;
2400
- default: throw new Error(`Unknown unit: ${rgb.unit}`);
2401
- }
2402
- }
2403
- function toLibrary$1(rgb) {
2404
- const abs = to8bit$1(rgb);
2405
- return {
2406
- r: abs.r,
2407
- g: abs.g,
2408
- b: abs.b,
2409
- alpha: abs.opacity
2410
- };
2411
- }
2412
- function fromLibrary$1(rgb, parsingOptions = {}) {
2413
- if (parsingOptions.scalar) return {
2414
- r: rgb.r / 255,
2415
- g: rgb.g / 255,
2416
- b: rgb.b / 255,
2417
- opacity: rgb.alpha ?? 1,
2418
- unit: `scalar`,
2419
- space: `srgb`
2420
- };
2421
- else return {
2422
- r: rgb.r,
2423
- g: rgb.g,
2424
- b: rgb.b,
2425
- opacity: rgb.alpha ?? 255,
2426
- unit: `8bit`,
2427
- space: `srgb`
2428
- };
2429
- }
2430
- function to8bit$1(rgbOrString) {
2431
- if (typeof rgbOrString === `string`) return fromCss$2(rgbOrString, { scalar: false });
2432
- if (isHsl(rgbOrString)) return to8bit$1(fromLibrary$1(toLibraryRgb(rgbOrString), { scalar: false }));
2433
- guard$3(rgbOrString);
2434
- if (rgbOrString.unit === `8bit`) return rgbOrString;
2435
- return {
2436
- r: rgbOrString.r * 255,
2437
- g: rgbOrString.g * 255,
2438
- b: rgbOrString.b * 255,
2439
- opacity: (rgbOrString.opacity ?? 1) * 255,
2440
- unit: `8bit`,
2441
- space: `srgb`
2442
- };
2443
- }
2444
- function toScalar$2(rgbOrString) {
2445
- if (typeof rgbOrString === `string`) return fromCss$2(rgbOrString, { scalar: true });
2446
- if (isHsl(rgbOrString)) return toScalar$2(fromLibrary$1(toLibraryRgb(rgbOrString), { scalar: true }));
2447
- guard$3(rgbOrString);
2448
- if (rgbOrString.unit === `scalar`) return rgbOrString;
2449
- return {
2450
- r: rgbOrString.r / 255,
2451
- g: rgbOrString.g / 255,
2452
- b: rgbOrString.b / 255,
2453
- opacity: (rgbOrString.opacity ?? 1) / 255,
2454
- unit: `scalar`,
2455
- space: `srgb`
2456
- };
2457
- }
2458
- function guard$3(rgb) {
2459
- const { r, g, b, opacity, space, unit } = rgb;
2460
- if (space !== `srgb`) throw new Error(`Space is expected to be 'srgb'. Got: ${space}`);
2461
- if (unit === `8bit`) resultThrow(numberInclusiveRangeTest(r, 0, 255, `r`), numberInclusiveRangeTest(g, 0, 255, `g`), numberInclusiveRangeTest(b, 0, 255, `b`), () => {
2462
- if (typeof opacity === `number`) return numberInclusiveRangeTest(opacity, 0, 255, `opacity`);
2463
- });
2464
- else if (unit === `scalar`) resultThrow(numberTest(r, `percentage`, `r`), numberTest(g, `percentage`, `g`), numberTest(b, `percentage`, `b`), () => {
2465
- if (typeof opacity === `number`) return numberTest(opacity, `percentage`, `opacity`);
2466
- });
2467
- else throw new Error(`Unit is expected to be '8bit' or 'scalar'. Got: ${unit}`);
2468
- }
2469
- /**
2470
- * Sets the lightness value.
2471
- *
2472
- * Amount to change:
2473
- * 'fixed': a fixed amount
2474
- * 'delta': increase/decrease by this amount
2475
- * 'pdelta': proportion of current value to change by ('percentage delta')
2476
- *
2477
- * Use negative values to decrease
2478
- * @param rgb Colour
2479
- * @param amount Amount to change
2480
- */
2481
- function changeLightness(rgb, amount) {
2482
- let newL = 0;
2483
- const co = new Colorizr(toCssString$1(rgb));
2484
- const scalarUnit = rgb.unit === `scalar`;
2485
- if (typeof amount.pdelta !== `undefined`) newL = co.oklab.l + co.oklab.l * amount.pdelta;
2486
- else if (typeof amount.delta !== `undefined`) newL = co.oklab.l + amount.delta;
2487
- else if (typeof amount.fixed !== `undefined`) {
2488
- if (amount.fixed < 0) throw new TypeError(`Amount cannot be negative when using 'fixed'`);
2489
- newL = amount.fixed;
2490
- } else throw new TypeError(`Parameter 'amount' is missing 'pdelta/delta/fixed' properties`);
2491
- if (newL < 0) newL = 0;
2492
- else if (newL > 1) newL = 1;
2493
- return fromLibrary$1(oklab2rgb({
2494
- a: co.oklab.a,
2495
- b: co.oklab.b,
2496
- l: newL,
2497
- alpha: co.oklab.alpha
2498
- }), { scalar: scalarUnit });
2499
- }
2500
- /**
2501
- * Returns a lightness value (0..1) for an RGB input
2502
- *
2503
- * Calculates lightness by converting to Oklab and using the 'L' value
2504
- * @param rgb
2505
- */
2506
- function lightness(rgb) {
2507
- return new Colorizr(toCssString$1(rgb)).oklab.l;
2508
- }
2509
- /**
2510
- * Creates a Rgb8Bit value from 8bit (0..255) values
2511
- * @param red
2512
- * @param green
2513
- * @param blue
2514
- * @param opacity
2515
- */
2516
- function eightBit$1(red = 100, green = 100, blue = 100, opacity = 255) {
2517
- const rgb = {
2518
- unit: `8bit`,
2519
- space: `srgb`,
2520
- r: red,
2521
- g: green,
2522
- b: blue,
2523
- opacity
2524
- };
2525
- guard$3(rgb);
2526
- return rgb;
2527
- }
2528
- /**
2529
- * Creates a RgbScalar value from scalar (0..1) values
2530
- * @param red
2531
- * @param green
2532
- * @param blue
2533
- * @param opacity
2534
- */
2535
- function scalar$2(red = .5, green = .5, blue = .5, opacity = 1) {
2536
- const rgb = {
2537
- unit: `scalar`,
2538
- space: `srgb`,
2539
- r: red,
2540
- g: green,
2541
- b: blue,
2542
- opacity
2543
- };
2544
- guard$3(rgb);
2545
- return rgb;
2546
- }
2547
- /**
2548
- * It seems Colorizr can't handle % values properly :'(
2549
- * @param value
2550
- */
2551
- function parseCssRgbFunction(value) {
2552
- if (value.startsWith(`rgba`)) throw new Error(`RGBA is not supported`);
2553
- if (!value.startsWith(`rgb(`)) throw new Error(`Expected rgb(..) CSS colour`);
2554
- const start = value.indexOf(`(`);
2555
- const end = value.indexOf(`)`);
2556
- if (end < start) throw new Error(`Is rgb() not terminated? Missing ')'`);
2557
- let split = value.substring(start + 1, end).split(/[\s,]+/);
2558
- if (split.length < 3) throw new Error(`Expected three tokens. Got: ${split.length} length`);
2559
- let relativeCount = 0;
2560
- for (const s of split) if (s.endsWith(`%`)) relativeCount++;
2561
- const valueAsScalar = (v, pos) => {
2562
- if (v.endsWith(`%`)) return Number.parseFloat(v.substring(0, v.length - 1)) / 100;
2563
- if (pos < 3) return Number.parseFloat(v) / 255;
2564
- else return Number.parseFloat(v);
2565
- };
2566
- const valueAs8bit = (v, pos) => {
2567
- if (v.endsWith(`%`)) return Number.parseFloat(v.substring(0, v.length - 1)) / 100 * 255;
2568
- if (pos < 3) return Number.parseFloat(v);
2569
- else return Number.parseFloat(v) * 255;
2570
- };
2571
- if (split.length > 3) {
2572
- if (split[3] === `/`) split = [
2573
- split[0],
2574
- split[1],
2575
- split[2],
2576
- split[4]
2577
- ];
2578
- }
2579
- if (relativeCount > 1) return scalar$2(valueAsScalar(split[0], 0), valueAsScalar(split[1], 1), valueAsScalar(split[2], 2), valueAsScalar(split[3] ?? `1`, 3));
2580
- else return eightBit$1(valueAs8bit(split[0], 0), valueAs8bit(split[1], 1), valueAs8bit(split[2], 2), valueAs8bit(split[3] ?? `1`, 3));
2581
- }
2582
- /**
2583
- * Interpolates colours in Srgb space. Probably
2584
- * really ugly, use OkLch space isntead.
2585
- *
2586
- * ```js
2587
- * const i = interpolator(`red`, `blue`);
2588
- * i(0.5); // Get 50% between these colours
2589
- * ```
2590
- * @param colourA
2591
- * @param colourB
2592
- */
2593
- function interpolator$2(colourA, colourB) {
2594
- const aa = toScalar$2(colourA);
2595
- const bb = toScalar$2(colourB);
2596
- const aOpacity = aa.opacity ?? 1;
2597
- const opacityDistance = (bb.opacity ?? 1) - aOpacity;
2598
- const r = bb.r - aa.r;
2599
- const g = bb.g - aa.g;
2600
- const b = bb.b - aa.b;
2601
- return (amount) => {
2602
- amount = clamp(amount);
2603
- return scalar$2(aa.r + interpolate(amount, 0, r), aa.g + interpolate(amount, 0, g), aa.b + interpolate(amount, 0, b), aOpacity + interpolate(amount, 0, opacityDistance));
2604
- };
2605
- }
2606
- /**
2607
- * Converts a Rgb structure (or CSS string) to Colorizr's HSL format
2608
- * @param rgb
2609
- */
2610
- function toLibraryHsl(rgb) {
2611
- if (typeof rgb === `string`) return toLibraryHsl(fromCss$2(rgb, { scalar: false }));
2612
- rgb = to8bit$1(rgb);
2613
- return {
2614
- ...rgb2hsl({
2615
- r: rgb.r,
2616
- g: rgb.g,
2617
- b: rgb.b
2618
- }),
2619
- alpha: (rgb.opacity ?? 255) / 255
2620
- };
2621
- }
2622
- var oklch_exports = /* @__PURE__ */ __exportAll({
2623
- OKLCH_CHROMA_MAX: () => OKLCH_CHROMA_MAX,
2624
- absolute: () => absolute,
2625
- fromCss: () => fromCss$1,
2626
- fromHexString: () => fromHexString$1,
2627
- fromLibrary: () => fromLibrary,
2628
- generateScalar: () => generateScalar,
2629
- guard: () => guard$2,
2630
- interpolator: () => interpolator$1,
2631
- scalar: () => scalar$1,
2632
- toAbsolute: () => toAbsolute,
2633
- toCssString: () => toCssString,
2634
- toHexString: () => toHexString$1,
2635
- toScalar: () => toScalar$1,
2636
- withOpacity: () => withOpacity$1
2637
- });
2638
- const OKLCH_CHROMA_MAX = .4;
2639
- function guard$2(lch) {
2640
- const { l, c, h, opacity, space, unit } = lch;
2641
- if (space !== `oklch`) throw new Error(`Space is expected to be 'oklch'. Got: ${space}`);
2642
- if (unit === `absolute`) resultThrow(percentTest(l, `l`), () => {
2643
- if (typeof c === `number`) return numberInclusiveRangeTest(c, 0, OKLCH_CHROMA_MAX, `c`);
2644
- }, () => {
2645
- if (typeof h === `number`) return numberInclusiveRangeTest(h, 0, 360, `h`);
2646
- }, percentTest(opacity ?? 1, `opacity`));
2647
- else if (unit === `scalar`) resultThrow(percentTest(l, `l`), percentTest(c, `c`), percentTest(h, `h`), percentTest(lch.opacity ?? 1, `opacity`));
2648
- else throw new Error(`Unit is expected to be 'absolute' or 'scalar'. Got: ${unit}`);
2649
- }
2650
- function fromLibrary(lch, parsingOptions = {}) {
2651
- if (typeof lch === `undefined` || lch === null) {
2652
- if (parsingOptions.fallbackColour) return parsingOptions.fallbackColour;
2653
- }
2654
- const scalarReturn = parsingOptions.scalar ?? true;
2655
- resultThrow(percentTest(lch.l, `l`), percentTest(lch.c, `c`), numberInclusiveRangeTest(lch.h, 0, 360, `h`), percentTest(lch.alpha ?? 1, `alpha`));
2656
- if (scalarReturn) return scalar$1(lch.l, lch.c / OKLCH_CHROMA_MAX, lch.h / 360, lch.alpha ?? 1);
2657
- else return absolute(lch.l, lch.c, lch.h, lch.alpha ?? 1);
2658
- }
2659
- /**
2660
- * Parse a HEX-formatted colour into OkLch structured format
2661
- * @param hexString
2662
- * @param options
2663
- */
2664
- function fromHexString$1(hexString, options = {}) {
2665
- return fromLibrary(hex2oklch(hexString), options);
2666
- }
2667
- const oklchTransparent = Object.freeze({
2668
- l: 0,
2669
- c: 0,
2670
- h: 0,
2671
- opacity: 0,
2672
- unit: `absolute`,
2673
- space: `oklch`
2674
- });
2675
- function fromCss$1(value, options = {}) {
2676
- value = value.toLowerCase();
2677
- if (value.startsWith(`#`)) return fromHexString$1(value, options);
2678
- if (value === `transparent`) return oklchTransparent;
2679
- if (typeof cssDefinedHexColours[value] !== `undefined`) return fromHexString$1(cssDefinedHexColours[value], options);
2680
- if (value.startsWith(`rgb(`)) {
2681
- const rgb = to8bit$1(parseCssRgbFunction(value));
2682
- return fromLibrary(rgb2oklch({
2683
- r: rgb.r,
2684
- g: rgb.g,
2685
- b: rgb.b
2686
- }), options);
2687
- }
2688
- if (!value.startsWith(`hsl(`) && !value.startsWith(`oklch(`)) try {
2689
- value = convert$1(value, `oklch`);
2690
- } catch (error) {
2691
- if (options.fallbackString) value = options.fallbackString;
2692
- else throw error;
2693
- }
2694
- const lch = new Colorizr(value).oklch;
2695
- return fromLibrary(lch, options);
2696
- }
2697
- /**
2698
- * Returns a string or {@link OkLch} value to absolute form.
2699
- *
2700
- * This means ranges are:
2701
- * lightness: 0..1
2702
- * chroma: 0...CHROMA_MAX (0.4)
2703
- * hue: 0..360
2704
- * @param lchOrString
2705
- */
2706
- function toAbsolute(lchOrString) {
2707
- if (typeof lchOrString === `string`) return toAbsolute(fromCss$1(lchOrString, { scalar: true }));
2708
- guard$2(lchOrString);
2709
- if (lchOrString.unit === `absolute`) return lchOrString;
2710
- return {
2711
- space: `oklch`,
2712
- unit: `absolute`,
2713
- l: lchOrString.l,
2714
- c: lchOrString.c * OKLCH_CHROMA_MAX,
2715
- h: lchOrString.h * 360,
2716
- opacity: lchOrString.opacity
2717
- };
2718
- }
2719
- function toScalar$1(lchOrString) {
2720
- if (typeof lchOrString === `string`) return toScalar$1(fromCss$1(lchOrString, { scalar: true }));
2721
- const lch = lchOrString;
2722
- guard$2(lch);
2723
- if (lch.unit === `scalar`) return lch;
2724
- return {
2725
- l: lch.l,
2726
- c: lch.c / OKLCH_CHROMA_MAX,
2727
- h: lch.h / 360,
2728
- opacity: lch.opacity ?? 1,
2729
- unit: `scalar`,
2730
- space: `oklch`
2731
- };
2732
- }
2733
- function toLibrary(lch) {
2734
- const abs = toAbsolute(lch);
2735
- return {
2736
- l: abs.l,
2737
- c: abs.c,
2738
- h: abs.h,
2739
- alpha: abs.opacity
2740
- };
2741
- }
2742
- /**
2743
- * Returns the colour as a CSS colour string: `oklch(l c h / opacity)`.
2744
- *
2745
- * @param lch Colour
2746
- * @param precision Set precision of numbers, defaults to 3
2747
- * @returns CSS colour string
2748
- */
2749
- function toCssString(lch, precision = 3) {
2750
- guard$2(lch);
2751
- const { l, c, h, opacity } = lch;
2752
- let css = ``;
2753
- switch (lch.unit) {
2754
- case `absolute`:
2755
- css = `oklch(${(l * 100).toFixed(precision)}% ${c.toFixed(precision)} ${h.toFixed(precision)}`;
2756
- break;
2757
- case `scalar`:
2758
- css = `oklch(${l.toFixed(precision)} ${(c * OKLCH_CHROMA_MAX).toFixed(precision)} ${(h * 360).toFixed(precision)}`;
2759
- break;
2760
- }
2761
- if (typeof opacity !== `undefined` && opacity !== 1) css += ` / ${opacity.toFixed(precision)}`;
2762
- css += `)`;
2763
- return css;
2764
- }
2765
- function toHexString$1(lch) {
2766
- return libraryRgbToHexString(oklch2rgb(toLibrary(lch)));
2767
- }
2768
- function generateScalar(absoluteHslOrVariable, chroma = 1, lightness = .5, opacity = 1) {
2769
- if (typeof absoluteHslOrVariable === `string`) {
2770
- if (absoluteHslOrVariable.startsWith(`--`)) absoluteHslOrVariable = getComputedStyle(document.body).getPropertyValue(absoluteHslOrVariable).trim();
2771
- }
2772
- if (lightness > 1) throw new TypeError(`Param 'lightness' must be between 0..1`);
2773
- if (chroma > 1) throw new TypeError(`Param 'chroma' must be between 0..1`);
2774
- const hueDeg = angleConvert(angleParse(absoluteHslOrVariable), `deg`).value / 360;
2775
- if (opacity > 1) throw new TypeError(`Param 'opacity' must be between 0..1`);
2776
- return {
2777
- l: lightness,
2778
- c: chroma,
2779
- h: hueDeg,
2780
- opacity,
2781
- unit: `scalar`,
2782
- space: `oklch`
2783
- };
2784
- }
2785
- /**
2786
- * Scales the opacity value of an input Oklch value
2787
- * ```js
2788
- * withOpacity()
2789
- * ```
2790
- * @param value
2791
- * @param fn
2792
- */
2793
- function withOpacity$1(value, fn) {
2794
- switch (value.unit) {
2795
- case `absolute`: return {
2796
- ...value,
2797
- opacity: fn((value.opacity ?? 100) / 100, value) * 100
2798
- };
2799
- case `scalar`: return {
2800
- ...value,
2801
- opacity: fn(value.opacity ?? 1, value)
2802
- };
2803
- }
2804
- }
2805
- function interpolator$1(a, b, direction = `shorter`) {
2806
- a = toScalar$1(a);
2807
- b = toScalar$1(b);
2808
- const aOpacity = a.opacity ?? 1;
2809
- const distanceCalc = calculateHueDistance(a.h, b.h, 1);
2810
- const hueDistance = direction === `longer` ? distanceCalc.long : distanceCalc.short;
2811
- const chromaDistance = b.c - a.c;
2812
- const lightDistance = b.l - a.l;
2813
- const opacityDistance = (b.opacity ?? 1) - aOpacity;
2814
- return (amount) => {
2815
- amount = clamp(amount);
2816
- let h = interpolate(amount, 0, Math.abs(hueDistance));
2817
- if (hueDistance < 0) h = a.h - h;
2818
- else h = a.h + h;
2819
- const c = interpolate(amount, 0, chromaDistance);
2820
- const l = interpolate(amount, 0, lightDistance);
2821
- const o = interpolate(amount, 0, opacityDistance);
2822
- return scalar$1(l + a.l, c + a.c, wrapScalarHue(h), o + aOpacity);
2823
- };
2824
- }
2825
- function scalar$1(lightness = .7, chroma = .1, hue = .5, opacity = 1) {
2826
- const lch = {
2827
- unit: `scalar`,
2828
- space: `oklch`,
2829
- l: lightness,
2830
- c: chroma,
2831
- h: hue,
2832
- opacity
2833
- };
2834
- guard$2(lch);
2835
- return lch;
2836
- }
2837
- /**
2838
- * Create an LCH colour using absolute hue
2839
- * @param l Lightness 0..1
2840
- * @param c Chroma 0..4
2841
- * @param h Hue 0..360
2842
- * @param opacity
2843
- */
2844
- function absolute(l, c, h, opacity = 1) {
2845
- const lch = {
2846
- space: `oklch`,
2847
- unit: `absolute`,
2848
- opacity,
2849
- l,
2850
- c,
2851
- h
2852
- };
2853
- guard$2(lch);
2854
- return lch;
2855
- }
2856
- /**
2857
- * Converts from some kind of colour that is legal in CSS
2858
- * into a structured Colour type.
2859
- *
2860
- * Handles: hex format, CSS variables, colour names
2861
- * ```js
2862
- * fromCssColour(`#ffffff`);
2863
- * fromCssColour(`blue`);
2864
- * fromCssColour(`--some-variable`);
2865
- * fromCssColour(`hsl(50, 50%, 50%)`);
2866
- * fromCssColour(`rgb(50, 100, 100)`);
2867
- * ```
2868
- * @param colour
2869
- * @returns
2870
- */
2871
- const fromCssColour = (colour) => {
2872
- if (colour.startsWith(`#`)) return fromHexString$2(colour, true);
2873
- if (colour.startsWith(`--`)) {
2874
- const fromCss = getComputedStyle(document.body).getPropertyValue(colour).trim();
2875
- if (fromCss.length === 0 || fromCss === null) throw new Error(`Variable missing: ${colour}`);
2876
- return fromCssColour(fromCss);
2877
- }
2878
- const colourLower = colour.toLowerCase();
2879
- if (typeof cssDefinedHexColours[colourLower] !== `undefined`) return fromHexString$2(cssDefinedHexColours[colourLower], true);
2880
- if (colourLower.startsWith(`hsl(`)) return fromCss$3(colour, { scalar: true });
2881
- if (colourLower.startsWith(`rgb(`)) return fromCss$2(colour, { scalar: true });
2882
- if (colourLower.startsWith(`oklch(`)) return fromCss$1(colour, { scalar: true });
2883
- throw new Error(`String colour is not a hex colour, CSS variable nor well-defined colour. Input: '${colour}'`);
2884
- };
2885
- /**
2886
- * Resolves a named colour or CSS variable to a colour string.
2887
- * Doesn't do conversion or parsing.
2888
- *
2889
- * ```js
2890
- * resolveCss(`red`);
2891
- * resolveCss(`my-var`);
2892
- * ```
2893
- * @param colour Colour
2894
- * @param fallback Fallback if CSS variable is missing
2895
- * @returns
2896
- */
2897
- function resolveCss(colour, fallback) {
2898
- if (colour.startsWith(`--`)) {
2899
- const fromCss = getComputedStyle(document.body).getPropertyValue(colour).trim();
2900
- if (fromCss.length === 0 || fromCss === null) {
2901
- if (typeof fallback !== `undefined`) return fallback;
2902
- throw new Error(`CSS variable missing: '${colour}'`);
2903
- }
2904
- return resolveCss(fromCss);
2905
- }
2906
- if (typeof cssDefinedHexColours[colour] !== `undefined`) return cssDefinedHexColours[colour];
2907
- return colour;
2908
- }
2909
- const cssDefinedHexColours = Object.freeze({
2910
- "aliceblue": "#f0f8ff",
2911
- "antiquewhite": "#faebd7",
2912
- "aqua": "#00ffff",
2913
- "aquamarine": "#7fffd4",
2914
- "azure": "#f0ffff",
2915
- "beige": "#f5f5dc",
2916
- "bisque": "#ffe4c4",
2917
- "black": "#000000",
2918
- "blanchedalmond": "#ffebcd",
2919
- "blue": "#0000ff",
2920
- "blueviolet": "#8a2be2",
2921
- "brown": "#a52a2a",
2922
- "burlywood": "#deb887",
2923
- "cadetblue": "#5f9ea0",
2924
- "chartreuse": "#7fff00",
2925
- "chocolate": "#d2691e",
2926
- "coral": "#ff7f50",
2927
- "cornflowerblue": "#6495ed",
2928
- "cornsilk": "#fff8dc",
2929
- "crimson": "#dc143c",
2930
- "cyan": "#00ffff",
2931
- "darkblue": "#00008b",
2932
- "darkcyan": "#008b8b",
2933
- "darkgoldenrod": "#b8860b",
2934
- "darkgray": "#a9a9a9",
2935
- "darkgreen": "#006400",
2936
- "darkkhaki": "#bdb76b",
2937
- "darkmagenta": "#8b008b",
2938
- "darkolivegreen": "#556b2f",
2939
- "darkorange": "#ff8c00",
2940
- "darkorchid": "#9932cc",
2941
- "darkred": "#8b0000",
2942
- "darksalmon": "#e9967a",
2943
- "darkseagreen": "#8fbc8f",
2944
- "darkslateblue": "#483d8b",
2945
- "darkslategray": "#2f4f4f",
2946
- "darkturquoise": "#00ced1",
2947
- "darkviolet": "#9400d3",
2948
- "deeppink": "#ff1493",
2949
- "deepskyblue": "#00bfff",
2950
- "dimgray": "#696969",
2951
- "dodgerblue": "#1e90ff",
2952
- "firebrick": "#b22222",
2953
- "floralwhite": "#fffaf0",
2954
- "forestgreen": "#228b22",
2955
- "fuchsia": "#ff00ff",
2956
- "gainsboro": "#dcdcdc",
2957
- "ghostwhite": "#f8f8ff",
2958
- "gold": "#ffd700",
2959
- "goldenrod": "#daa520",
2960
- "gray": "#808080",
2961
- "green": "#008000",
2962
- "greenyellow": "#adff2f",
2963
- "honeydew": "#f0fff0",
2964
- "hotpink": "#ff69b4",
2965
- "indianred": "#cd5c5c",
2966
- "indigo": "#4b0082",
2967
- "ivory": "#fffff0",
2968
- "khaki": "#f0e68c",
2969
- "lavender": "#e6e6fa",
2970
- "lavenderblush": "#fff0f5",
2971
- "lawngreen": "#7cfc00",
2972
- "lemonchiffon": "#fffacd",
2973
- "lightblue": "#add8e6",
2974
- "lightcoral": "#f08080",
2975
- "lightcyan": "#e0ffff",
2976
- "lightgoldenrodyellow": "#fafad2",
2977
- "lightgray": "#d3d3d3",
2978
- "lightgreen": "#90ee90",
2979
- "lightpink": "#ffb6c1",
2980
- "lightsalmon": "#ffa07a",
2981
- "lightseagreen": "#20b2aa",
2982
- "lightskyblue": "#87cefa",
2983
- "lightslategray": "#778899",
2984
- "lightsteelblue": "#b0c4de",
2985
- "lightyellow": "#ffffe0",
2986
- "lime": "#00ff00",
2987
- "limegreen": "#32cd32",
2988
- "linen": "#faf0e6",
2989
- "magenta": "#ff00ff",
2990
- "maroon": "#800000",
2991
- "mediumaquamarine": "#66cdaa",
2992
- "mediumblue": "#0000cd",
2993
- "mediumorchid": "#ba55d3",
2994
- "mediumpurple": "#9370db",
2995
- "mediumseagreen": "#3cb371",
2996
- "mediumslateblue": "#7b68ee",
2997
- "mediumspringgreen": "#00fa9a",
2998
- "mediumturquoise": "#48d1cc",
2999
- "mediumvioletred": "#c71585",
3000
- "midnightblue": "#191970",
3001
- "mintcream": "#f5fffa",
3002
- "mistyrose": "#ffe4e1",
3003
- "moccasin": "#ffe4b5",
3004
- "navajowhite": "#ffdead",
3005
- "navy": "#000080",
3006
- "oldlace": "#fdf5e6",
3007
- "olive": "#808000",
3008
- "olivedrab": "#6b8e23",
3009
- "orange": "#ffa500",
3010
- "orangered": "#ff4500",
3011
- "orchid": "#da70d6",
3012
- "palegoldenrod": "#eee8aa",
3013
- "palegreen": "#98fb98",
3014
- "paleturquoise": "#afeeee",
3015
- "palevioletred": "#db7093",
3016
- "papayawhip": "#ffefd5",
3017
- "peachpuff": "#ffdab9",
3018
- "peru": "#cd853f",
3019
- "pink": "#ffc0cb",
3020
- "plum": "#dda0dd",
3021
- "powderblue": "#b0e0e6",
3022
- "purple": "#800080",
3023
- "rebeccapurple": "#663399",
3024
- "red": "#ff0000",
3025
- "rosybrown": "#bc8f8f",
3026
- "royalblue": "#4169e1",
3027
- "saddlebrown": "#8b4513",
3028
- "salmon": "#fa8072",
3029
- "sandybrown": "#f4a460",
3030
- "seagreen": "#2e8b57",
3031
- "seashell": "#fff5ee",
3032
- "sienna": "#a0522d",
3033
- "silver": "#c0c0c0",
3034
- "skyblue": "#87ceeb",
3035
- "slateblue": "#6a5acd",
3036
- "slategray": "#708090",
3037
- "snow": "#fffafa",
3038
- "springgreen": "#00ff7f",
3039
- "steelblue": "#4682b4",
3040
- "tan": "#d2b48c",
3041
- "teal": "#008080",
3042
- "thistle": "#d8bfd8",
3043
- "tomato": "#ff6347",
3044
- "turquoise": "#40e0d0",
3045
- "violet": "#ee82ee",
3046
- "wheat": "#f5deb3",
3047
- "white": "#ffffff",
3048
- "whitesmoke": "#f5f5f5",
3049
- "yellow": "#ffff00",
3050
- "yellowgreen": "#9acd32",
3051
- "transparent": "#00000000"
3052
- });
3053
- /**
3054
- * Converts an object or string representation of colour to ixfx's
3055
- * structured colour.
3056
- * Use {@link convertToString} if you want a CSS colour string instead.
3057
- * @param colour
3058
- * @param destination
3059
- */
3060
- function convert(colour, destination) {
3061
- if (destination === `hsl-scalar`) {
3062
- if (typeof colour === `string` || isHsl(colour) || isRgb(colour)) return toScalar$3(colour);
3063
- } else if (destination === `hsl-absolute`) {
3064
- if (typeof colour === `string` || isHsl(colour)) return toAbsolute$1(colour);
3065
- } else if (destination === `oklch-scalar`) {
3066
- if (typeof colour === `string` || isOkLch(colour)) return toScalar$1(colour);
3067
- } else if (destination === `oklch-absolute`) {
3068
- if (typeof colour === `string` || isOkLch(colour)) return toAbsolute(colour);
3069
- } else if (destination === `srgb-8bit`) {
3070
- if (typeof colour === `string` || isRgb(colour)) return to8bit$1(colour);
3071
- } else if (destination === `srgb-scalar`) {
3072
- if (typeof colour === `string` || isRgb(colour)) return toScalar$2(colour);
3073
- } else throw new Error(`Destination '${destination}' not supported for input: ${JSON.stringify(colour)}`);
3074
- return convert(toCssColour(colour), destination);
3075
- }
3076
- /**
3077
- * Like {@link convert}, but result is a CSS colour string
3078
- * @param colour
3079
- * @param destination
3080
- */
3081
- function convertToString(colour, destination) {
3082
- return toCssColour(convert(colour, destination));
3083
- }
3084
- /**
3085
- * Converts some kind of colour into a scalar representation. Supports oklch, hsl and srgb.
3086
- * @param colour Colour to convert
3087
- * @param destination Destination colour format
3088
- */
3089
- function convertScalar(colour, destination) {
3090
- if (destination === `oklch`) return convert(colour, `oklch-scalar`);
3091
- if (destination === `srgb`) return convert(colour, `srgb-scalar`);
3092
- if (destination === `hsl`) return convert(colour, `hsl-scalar`);
3093
- throw new Error(`Unknown destination: '${destination}'`);
3094
- }
3095
- function toCssColour(colour) {
3096
- if (typeof colour === `string`) return colour;
3097
- if (isHsl(colour)) return toCssString$2(colour);
3098
- if (isRgb(colour)) return toCssString$1(colour);
3099
- if (isOkLch(colour)) return toCssString(colour);
3100
- const asRgb = tryParseObjectToRgb(colour);
3101
- if (asRgb) return toCssString$1(asRgb);
3102
- const asHsl = tryParseObjectToHsl(colour);
3103
- if (asHsl) return toCssString$2(asHsl);
3104
- throw new Error(`Unknown colour format: '${JSON.stringify(colour)}'`);
3105
- }
3106
- function toHexColour(colour) {
3107
- if (isHsl(colour)) return toHexString$3(colour);
3108
- if (isRgb(colour)) return toHexString$2(colour);
3109
- if (isOkLch(colour)) return toHexString$1(colour);
3110
- if (typeof colour === `string`) {
3111
- if (colour.startsWith(`#`)) return colour;
3112
- return toHexString$2(convert(colour, `srgb-8bit`));
3113
- }
3114
- const asRgb = tryParseObjectToRgb(colour);
3115
- if (asRgb) return toHexString$2(asRgb);
3116
- const asHsl = tryParseObjectToHsl(colour);
3117
- if (asHsl) return toHexString$3(asHsl);
3118
- throw new Error(`Unknown colour format: '${JSON.stringify(colour)}'`);
3119
- }
3120
- function toLibraryColour(colour) {
3121
- return new Colorizr(toCssColour(colour));
3122
- }
3123
- function guard$1(colour) {
3124
- switch (colour.space) {
3125
- case `hsl`:
3126
- guard$4(colour);
3127
- break;
3128
- case `srgb`:
3129
- guard$3(colour);
3130
- break;
3131
- case `oklch`:
3132
- guard$2(colour);
3133
- break;
3134
- default: throw new Error(`Unsupported colour space: '${colour.space}'`);
3135
- }
3136
- }
3137
- function toColour(colourish) {
3138
- if (!isColourish(colourish)) throw new Error(`Could not parse input. Expected CSS colour string or structured colour {r,g,b}, {h,s,l} etc. Got: ${JSON.stringify(colourish)}`);
3139
- let c;
3140
- if (typeof colourish === `string`) c = fromCssColour(colourish);
3141
- else c = colourish;
3142
- if (c === void 0) throw new Error(`Could not parse input. Expected CSS colour string or structured colour {r,g,b}, {h,s,l} etc.`);
3143
- guard$1(c);
3144
- return c;
3145
- }
3146
- /**
3147
- * Returns a CSS-ready string
3148
- * representation.
3149
- * ```js
3150
- * element.style.backgroundColor = resolveToString(`red`);
3151
- * ```
3152
- *
3153
- * Tries each parameter in turn, returning the value
3154
- * for the first that resolves. This can be useful for
3155
- * having fallback values.
3156
- *
3157
- * ```js
3158
- * // Try a CSS variable, a object property or finally fallback to red.
3159
- * element.style.backgroundColor = toStringFirst('--some-var', opts.background, `red`);
3160
- * ```
3161
- * @param colours Array of colours to resolve
3162
- */
3163
- function toStringFirst(...colours) {
3164
- for (const colour of colours) {
3165
- if (colour === void 0) continue;
3166
- if (colour === null) continue;
3167
- try {
3168
- return toCssColour(toColour(colour));
3169
- } catch {}
3170
- }
3171
- return `rebeccapurple`;
3172
- }
3173
- function rgbToHsl(rgb, scalarResult) {
3174
- let { r, g, b } = rgb;
3175
- const opacity = rgb.opacity ?? 1;
3176
- if (rgb.unit === `8bit`) {
3177
- r /= 255;
3178
- g /= 255;
3179
- b /= 255;
3180
- }
3181
- const max = Math.max(r, g, b);
3182
- const min = Math.min(r, g, b);
3183
- let h = (max + min) / 2;
3184
- let s = h;
3185
- const l = h;
3186
- if (max === min) if (scalarResult) return scalar$3(0, 0, 0, opacity);
3187
- else return absolute$1(0, 0, 0, opacity);
3188
- const d = max - min;
3189
- s = l >= .5 ? d / (2 - (max + min)) : d / (max + min);
3190
- switch (max) {
3191
- case r:
3192
- h = ((g - b) / d + 0) * 60;
3193
- break;
3194
- case g:
3195
- h = ((b - r) / d + 2) * 60;
3196
- break;
3197
- case b:
3198
- h = ((r - g) / d + 4) * 60;
3199
- break;
3200
- }
3201
- if (scalarResult) return scalar$3(h / 360, s, l, opacity);
3202
- else return absolute$1(h, s * 100, l * 100, opacity);
3203
- }
3204
- /**
3205
- * Returns a full HSL colour string (eg `hsl(20,50%,75%)`) based on a index.
3206
- * It's useful for generating perceptually different shades as the index increments.
3207
- *
3208
- * ```
3209
- * el.style.backgroundColor = goldenAgeColour(10);
3210
- * ```
3211
- *
3212
- * Saturation and lightness can be specified, as numeric ranges of 0-1.
3213
- *
3214
- * @param saturation Saturation (0-1), defaults to 0.5
3215
- * @param lightness Lightness (0-1), defaults to 0.75
3216
- * @param alpha Opacity (0-1), defaults to 1.0
3217
- * @returns HSL colour string eg `hsl(20,50%,75%)`
3218
- */
3219
- const goldenAngleColour = (index, saturation = .5, lightness = .75, alpha = 1) => {
3220
- resultThrow(numberTest(index, `positive`, `index`), numberTest(saturation, `percentage`, `saturation`), numberTest(lightness, `percentage`, `lightness`), numberTest(alpha, `percentage`, `alpha`));
3221
- return toCssString$2(scalar$3(index * 137.508 % 360 / 360, saturation, lightness, alpha));
3222
- };
3223
- /**
3224
- * Returns a random hue component (0..359)
3225
- *
3226
- * ```
3227
- * // Generate hue
3228
- * const h = randomHue(); // 0-359
3229
- *
3230
- * // Generate hue and assign as part of a HSL string
3231
- * el.style.backgroundColor = `hsl(${randomHue(), 50%, 75%})`;
3232
- * ```
3233
- * @param rand
3234
- * @returns
3235
- */
3236
- const randomHue = (rand = Math.random) => rand() * 360;
3237
- /**
3238
- * Returns a function to interpolate between colours, with results as a structured {@link Colour} object.
3239
- * ```js
3240
- * const i = interpolator([`orange`, `yellow`, `red`]);
3241
- *
3242
- * // Get a random colour on the above spectrum
3243
- * i(Math.random());
3244
- * ```
3245
- *
3246
- * Results will vary depending on the colour space used, play with the options.
3247
- * When using a hue-based colour space, the `hue` option sets the logic for how hue values wrap.
3248
- *
3249
- * ```js
3250
- * interpolator([`orange`, `yellow`, `red`], { space: `hsl`, hue: `longer })
3251
- * ```
3252
- *
3253
- * Example: Draw the interpolation as a spectrum on a canvas, where each pixel is one step
3254
- * ```js
3255
- * let v = 0;
3256
- * let incrementBy = 0.01;
3257
- * while (v <= 1) {
3258
- * // Get colour at this interpolation point 0..1
3259
- * const colour = fn(v);
3260
- * // Convert to a CSS string
3261
- * ctx.fillStyle = Colour.toCssColour(colour);
3262
- * // Draw a 1px wide rect, and shuffle along to the next x position
3263
- * ctx.fillRect(x, y, 1, h);
3264
- * x += 1;
3265
- * v += incrementBy;
3266
- * }
3267
- * ```
3268
- * @param colours Colours to interpolate between
3269
- * @param opts Options for interpolation
3270
- * @returns Function that interpolates based on an amount, returning a structured Colour
3271
- */
3272
- function interpolator(colours, opts = {}) {
3273
- const direction = opts.direction ?? `shorter`;
3274
- const destination = opts.destination ?? `oklch-scalar`;
3275
- const space = opts.space ?? `oklch`;
3276
- const ranges = interpolateInit(colours, space);
3277
- const rangeInterpolators = ranges.map((range) => interpolatorDual(range[0], range[1], {
3278
- space,
3279
- direction,
3280
- destination
3281
- }));
3282
- const asTargetDestination = colours.map((c) => convert(c, destination));
3283
- return (amt) => {
3284
- if (amt >= 1) return asTargetDestination.at(-1);
3285
- if (amt <= 0) return asTargetDestination.at(0);
3286
- const s = scaleClamped(amt, 0, 1, 0, ranges.length);
3287
- const index = Math.floor(s);
3288
- const amtAdjusted = s - index;
3289
- const ri = rangeInterpolators[index];
3290
- return ri(amtAdjusted);
3291
- };
3292
- }
3293
- /**
3294
- * Returns a set of pairwise colours, convert to the destination colour space in scalar form
3295
- * @param colours
3296
- * @param destination
3297
- * @returns Array of pairwise colours, converted to destination scalar
3298
- */
3299
- function interpolateInit(colours, destination = `hsl`) {
3300
- if (!Array.isArray(colours)) throw new Error(`Param 'colours' is not an array as expected. Got: ${typeof colours}`);
3301
- if (colours.length < 2) throw new Error(`Param 'colours' should be at least two in length. Got: ${colours.length}`);
3302
- return [...pairwise(colours.map((colour) => convertScalar(colour, destination)))];
3303
- }
3304
- /**
3305
- * Returns a CSS `linear-gradient` with stops corresponding to the given list of `colours`.
3306
- * ```js
3307
- * element.style.background = Colour.cssLinearGradient(['red','green','blue']);
3308
- * ```
3309
- * @param colours
3310
- * @returns A 'linear-gradient' string for use in CSS, eg for background.
3311
- */
3312
- function cssLinearGradient(colours) {
3313
- return `linear-gradient(to right, ${colours.map((c) => toCssColour(c)).join(`, `)})`;
3314
- }
3315
- /**
3316
- * Returns a function that interpolates between two colours. Returns string colour values.
3317
- * If you want the result as a structured colour, use {@link interpolatorDual} instead.
3318
- *
3319
- * By default takes a shorter direction and uses the OkLCH colourspace.
3320
- * ```js
3321
- * const i = interpolator(`blue`, `red`);
3322
- * i(0.5); // Get the colour at 50%, as a string.
3323
- * ```
3324
- *
3325
- * To work with structured colour values, use one of the space's `interpolate` functions.
3326
- *
3327
- * If you want to create discrete steps, consider {@link createSteps} or {@link scale}.
3328
- *
3329
- * @param colourA First colour
3330
- * @param colourB Second colour
3331
- * @param options Interpolation options. By default uses shorter direction and OkLCH colour space.
3332
- */
3333
- function interpolatorDualToString(colourA, colourB, options = {}) {
3334
- const f = interpolatorDual(colourA, colourB, options);
3335
- return (amount) => toCssColour(f(amount));
3336
- }
3337
- /**
3338
- * Returns a function that interpolates between two colours. Returns structured colour values.
3339
- * If you want the result as a ready-to-use CSS string, use {@link interpolatorDualToString} instead.
3340
- *
3341
- * By default takes a shorter direction and uses the OkLCH colourspace.
3342
- * ```js
3343
- * const i = interpolator(`blue`, `red`);
3344
- * i(0.5); // Get the colour at 50%, as a Colour structure.
3345
- * ```
3346
- *
3347
- * If you want to create discrete steps, consider {@link createSteps} or {@link scale}.
3348
- * @param colourA First colour
3349
- * @param colourB Second colour
3350
- * @param options Interpolation options. By default uses shorter direction and OkLCH colour space.
3351
- * @returns Function that interpolates between two colours, returning a structured Colour
3352
- */
3353
- function interpolatorDual(colourA, colourB, options = {}) {
3354
- const space = options.space ?? `oklch`;
3355
- const direction = options.direction ?? `shorter`;
3356
- const destination = options.destination ?? `oklch-scalar`;
3357
- let inter;
3358
- switch (space) {
3359
- case `hsl`: {
3360
- const hslInter = interpolator$3(convert(colourA, `hsl-scalar`), convert(colourB, `hsl-scalar`), direction);
3361
- inter = (amount) => {
3362
- return convert(hslInter(amount), destination);
3363
- };
3364
- break;
3365
- }
3366
- case `srgb`: {
3367
- const srgbInter = interpolator$2(convert(colourA, `srgb-scalar`), convert(colourB, `srgb-scalar`));
3368
- inter = (amount) => {
3369
- return convert(srgbInter(amount), destination);
3370
- };
3371
- break;
3372
- }
3373
- default: {
3374
- const oklchInter = interpolator$1(convert(colourA, `oklch-scalar`), convert(colourB, `oklch-scalar`), direction);
3375
- inter = (amount) => {
3376
- return convert(oklchInter(amount), destination);
3377
- };
3378
- }
3379
- }
3380
- return (amount) => inter(amount);
3381
- }
3382
- /**
3383
- * Produces a stepped scale of colours.
3384
- *
3385
- * Builds off {@link createSteps} which can only step between two colours.
3386
- *
3387
- * ```js
3388
- * // A scale of from red to green, with three colours in-between
3389
- * const steps = Colour.scale([ `red`, `green` ], { stepsBetween: 3 });
3390
- * for (const step of steps) {
3391
- * // A CSS colour string
3392
- * }
3393
- * ```
3394
- *
3395
- * {@link cssLinearGradient} can produce a smooth gradient in CSS on the basis
3396
- * of the stepped colours.
3397
- * @param colours
3398
- * @param opts
3399
- * @returns Array of colours in string form
3400
- */
3401
- function scale(colours, opts = {}) {
3402
- const direction = opts.direction ?? `shorter`;
3403
- const space = opts.space ?? `oklch`;
3404
- const pieces = interpolateInit(colours, space);
3405
- let stepsBetween = 0;
3406
- if (typeof opts.stepsBetween === `number`) {
3407
- stepsBetween = opts.stepsBetween;
3408
- if (stepsBetween < 1) throw new Error(`Param 'stepsBetween' must be at least 1`);
3409
- } else if (typeof opts.stepsTotal === `number`) {
3410
- if (opts.stepsTotal <= colours.length) throw new Error(`Param 'stepsTotal' must be greater than number of provided colour stops (${colours.length}) +1 per stop`);
3411
- const totalSteps = opts.stepsTotal - colours.length;
3412
- stepsBetween = Math.floor(totalSteps / pieces.length);
3413
- }
3414
- const steps = pieces.map((piece) => {
3415
- const pieceSteps = createSteps(piece[0], piece[1], {
3416
- steps: stepsBetween,
3417
- space,
3418
- direction,
3419
- exclusive: true
3420
- });
3421
- pieceSteps.push(piece[1]);
3422
- return pieceSteps;
3423
- });
3424
- const firstPiece = pieces[0];
3425
- steps.unshift([firstPiece[0]]);
3426
- return steps.flat().map((c) => toCssColour(c));
3427
- }
3428
- function createSteps(a, b, options = {}) {
3429
- const exclusive = options.exclusive ?? false;
3430
- const steps = options.steps ?? 5;
3431
- const space = options.space ?? `oklch`;
3432
- const direction = options.direction ?? `shorter`;
3433
- if (!exclusive && steps < 2) throw new Error(`Param 'steps' should be at least 2 when 'exclusive' is false`);
3434
- if (exclusive && steps < 1) throw new Error(`Param 'steps' should be at least 1 when 'exlusive' is true`);
3435
- const aa = convertScalar(a, space);
3436
- const bb = convertScalar(b, space);
3437
- let inter;
3438
- switch (space) {
3439
- case `hsl`:
3440
- inter = interpolator$3(aa, bb, direction);
3441
- break;
3442
- case `oklch`:
3443
- inter = interpolator$1(aa, bb, direction);
3444
- break;
3445
- case `srgb`:
3446
- inter = interpolator$2(aa, bb);
3447
- break;
3448
- default: throw new Error(`Colour space '${space}' not supported for interpolation.`);
3449
- }
3450
- if (!inter) throw new Error(`Could not create interpolator for space: ${space}`);
3451
- let stepBy = 0;
3452
- let startAt = 0;
3453
- let endAt = 1;
3454
- if (exclusive) {
3455
- stepBy = 1 / (steps + 1);
3456
- startAt = stepBy;
3457
- endAt = 1 - stepBy;
3458
- } else stepBy = 1 / (steps - 1);
3459
- const results = [];
3460
- for (let interpolateAmount = startAt; interpolateAmount <= endAt; interpolateAmount += stepBy) results.push(inter(interpolateAmount));
3461
- return results;
3462
- }
3463
- /**
3464
- * Multiplies the opacity of a colour by `amount`, returning a computed CSS colour.
3465
- *
3466
- * ```js
3467
- * multiplyOpacity(`red`, 0.5); // Returns a colour string
3468
- * ```
3469
- *
3470
- * For example, to half the opacity, use `amount: 0.5`.
3471
- * Clamps the result to ensure it's between 0..1
3472
- * @param colourish Colour
3473
- * @param amount Amount
3474
- */
3475
- function multiplyOpacity(colourish, amount) {
3476
- return withOpacity(colourish, (o) => clamp(o * amount));
3477
- }
3478
- /**
3479
- * Does a computation with the opacity of a colour, returning colour.
3480
- *
3481
- * Passes operation to `HslSpace` or `SrgbSpace` depending on space of `colourish`.
3482
- * @param colourish Colour
3483
- * @param fn Function that takes original opacity as input and returns output opacity
3484
- */
3485
- function withOpacity(colourish, fn) {
3486
- const colour = toColour(colourish);
3487
- let result;
3488
- switch (colour.space) {
3489
- case `hsl`:
3490
- result = withOpacity$3(colour, fn);
3491
- break;
3492
- case `srgb`:
3493
- result = withOpacity$2(colour, fn);
3494
- break;
3495
- case `oklch`:
3496
- result = withOpacity$1(colour, fn);
3497
- break;
3498
- default: throw new Error(`Unknown space: '${colour.space}'. Expected hsl, srgb, oklch`);
3499
- }
3500
- if (!result) throw new Error(`Is colour in correct form?`);
3501
- if (typeof colourish === `string`) return toCssColour(result);
3502
- return result;
3503
- }
3504
- function setOpacity(colourish, opacity) {
3505
- const colour = toColour(colourish);
3506
- colour.opacity = opacity;
3507
- if (typeof colourish === `string`) return toCssColour(colour);
3508
- return colour;
3509
- }
3510
- /**
3511
- * Encode 8-bit RGB values into a 24-bit value (0...16_777_215)
3512
- *
3513
- * Assumes RGB values are within 0..255 range
3514
- * @param rgb
3515
- * @returns
3516
- */
3517
- function encodeRgbTo24Bit(rgb) {
3518
- return rgb.r << 16 | rgb.g << 8 | rgb.b;
3519
- }
3520
- /**
3521
- * Decode a 24-bit number (0...16_777_215) into 8-bit RGB
3522
- * @param colour
3523
- * @returns
3524
- */
3525
- function decodeRgbFrom24Bit(colour) {
3526
- if (colour > 16777215) throw new TypeError(`Param 'colour' is out of range. Expected max value of 16_777_215, got ${colour}`);
3527
- return {
3528
- r: colour >> 16 & 255,
3529
- g: colour >> 8 & 255,
3530
- b: colour & 255,
3531
- unit: `8bit`,
3532
- space: `srgb`
3533
- };
3534
- }
3535
- /**
3536
- * Encodes 8-bit RGB value into 16-bit RGB565 (0..65_535)
3537
- * 5-bit are used for R & B channels, 6 bits for G
3538
- *
3539
- * Read more: https://rgbcolorpicker.com/565
3540
- * @param rgb
3541
- * @returns
3542
- */
3543
- function encodeRgbTo16Bit565(rgb) {
3544
- const r = rgb.r >> 3 & 31;
3545
- const g = rgb.g >> 2 & 63;
3546
- const b = rgb.b >> 3 & 31;
3547
- return r << 11 | g << 5 | b;
3548
- }
3549
- /**
3550
- * Decodes 8-bit RGB value from a 16-bit RGB565 value (0...65_535)
3551
- * Read more: https://rgbcolorpicker.com/565
3552
- * @param colour
3553
- * @returns
3554
- */
3555
- function decodeRgbFrom16Bit565(colour) {
3556
- if (colour > 65535) throw new TypeError(`Param 'colour' is out of range. Expected max: 65_535. Got: ${colour}`);
3557
- return {
3558
- r: (colour >> 11 & 31) << 3,
3559
- g: (colour >> 5 & 63) << 2,
3560
- b: (colour & 31) << 3,
3561
- unit: `8bit`,
3562
- space: `srgb`
3563
- };
3564
- }
3565
- var ycbcr_exports = /* @__PURE__ */ __exportAll({
3566
- eightBit: () => eightBit,
3567
- fromCss: () => fromCss,
3568
- fromHexString: () => fromHexString,
3569
- fromSrgTo8bit: () => fromSrgTo8bit,
3570
- guard: () => guard,
3571
- scalar: () => scalar,
3572
- to8bit: () => to8bit,
3573
- toHexString: () => toHexString,
3574
- toScalar: () => toScalar,
3575
- toSrgb8bit: () => toSrgb8bit
3576
- });
3577
- /**
3578
- * Creates a YCbCr8bit value from 8bit (0..255) values
3579
- * @param y Luma 0..255
3580
- * @param cb Chroma blue 0..255
3581
- * @param cr Chroma red 0..255
3582
- * @param opacity 0..255
3583
- * @returns YCbCr8bit
3584
- */
3585
- function eightBit(y = 100, cb = 100, cr = 100, opacity = 255) {
3586
- const rgb = {
3587
- unit: `8bit`,
3588
- space: `ycbcr`,
3589
- y,
3590
- cb,
3591
- cr,
3592
- opacity
3593
- };
3594
- guard(rgb);
3595
- return rgb;
3596
- }
3597
- /**
3598
- * Creates a YCbCr8bit value from scalar (0..1) values
3599
- * @param y Luma 0..1
3600
- * @param cb Chroma blue 0..1
3601
- * @param cr Chroma red 0..1
3602
- * @param opacity 0..1
3603
- * @returns YCbCrScalar
3604
- */
3605
- function scalar(y = .5, cb = .5, cr = .5, opacity = 1) {
3606
- const rgb = {
3607
- unit: `scalar`,
3608
- space: `ycbcr`,
3609
- y,
3610
- cb,
3611
- cr,
3612
- opacity
3613
- };
3614
- guard(rgb);
3615
- return rgb;
3616
- }
3617
- /**
3618
- * Converts from scalar or 8bit RGB to YCbCr8bit
3619
- * @param rgb
3620
- * @returns
3621
- */
3622
- function fromSrgTo8bit(rgb) {
3623
- const { r, g, b, opacity } = to8bit$1(rgb);
3624
- return eightBit(.299 * r + .587 * g + .114 * b + 0, -.169 * r + -.331 * g + .5 * b + 128, .5 * r + -.419 * g + -.081 * b + 128, opacity);
3625
- }
3626
- function toSrgb8bit(ycbcr) {
3627
- const { y, cb, cr, opacity } = to8bit(ycbcr);
3628
- return {
3629
- unit: `8bit`,
3630
- space: `srgb`,
3631
- r: 1 * y + 0 * (cb - 128) + 1.4 * (cr - 128),
3632
- g: 1 * y + -.343 * (cb - 128) + -.711 * (cr - 128),
3633
- b: 1 * y + 1.765 * (cb - 128) + 0 * (cr - 128),
3634
- opacity
3635
- };
3636
- }
3637
- /**
3638
- * Returns a YCbCr8bit format from either scalar or 8bit.
3639
- * If the input is already 8bit, it is returned as-is.
3640
- * @param ycbcr 8bit or scalar YCbCr value
3641
- * @returns YCbCr8bit
3642
- */
3643
- function to8bit(ycbcr) {
3644
- guard(ycbcr);
3645
- if (ycbcr.unit === `8bit`) return ycbcr;
3646
- const { y, cb, cr, opacity } = ycbcr;
3647
- return eightBit(y * 255, cb * 255, cr * 255, typeof opacity === `number` ? opacity * 255 : 255);
3648
- }
3649
- function fromHexString(hexString, options = {}) {
3650
- return fromSrgTo8bit(fromHexString$2(hexString, false));
3651
- }
3652
- function fromCss(value, options = {}) {
3653
- const scalar = options.scalar ?? false;
3654
- const rgb = fromCss$2(value, {
3655
- fallbackString: options.fallbackString,
3656
- scalar: false,
3657
- ensureSafe: options.ensureSafe
3658
- });
3659
- if (scalar) return toScalar(fromSrgTo8bit(rgb));
3660
- else return fromSrgTo8bit(rgb);
3661
- }
3662
- function toScalar(colour) {
3663
- if (typeof colour === `string`) return fromCss(colour, { scalar: true });
3664
- if (isHsl(colour) || isRgb(colour)) return toScalar(fromSrgTo8bit(toScalar$2(colour)));
3665
- guard(colour);
3666
- if (colour.unit === `scalar`) return colour;
3667
- const { y, cb, cr, opacity } = colour;
3668
- return scalar(y / 255, cb / 255, cr / 255, typeof opacity === `number` ? opacity / 255 : 1);
3669
- }
3670
- function guard(rgb) {
3671
- const { y, cb, cr, opacity, space, unit } = rgb;
3672
- if (space !== `ycbcr`) throw new Error(`Space is expected to be 'ycbcr'. Got: ${space}`);
3673
- if (unit === `8bit`) resultThrow(numberInclusiveRangeTest(y, 0, 255, `y`), numberInclusiveRangeTest(cb, 0, 255, `cb`), numberInclusiveRangeTest(cr, 0, 255, `cr`), () => {
3674
- if (typeof opacity === `number`) return numberInclusiveRangeTest(opacity, 0, 255, `opacity`);
3675
- });
3676
- else if (unit === `scalar`) resultThrow(numberTest(y, `percentage`, `y`), numberTest(cb, `percentage`, `cb`), numberTest(cr, `percentage`, `cr`), () => {
3677
- if (typeof opacity === `number`) return numberTest(opacity, `percentage`, `opacity`);
3678
- });
3679
- else throw new Error(`Unit is expected to be '8bit' or 'scalar'. Got: ${unit}`);
3680
- }
3681
- /**
3682
- * Converts a YCbCr colour to a RGB hex string.
3683
- * @param ycbcr
3684
- * @returns
3685
- */
3686
- function toHexString(ycbcr) {
3687
- return toHexString$2(toSrgb8bit(ycbcr));
3688
- }
3689
- var colour_exports = /* @__PURE__ */ __exportAll({
3690
- HslSpace: () => hsl_exports,
3691
- OklchSpace: () => oklch_exports,
3692
- SrgbSpace: () => srgb_exports,
3693
- YCbCrSpace: () => ycbcr_exports,
3694
- convert: () => convert,
3695
- convertScalar: () => convertScalar,
3696
- convertToString: () => convertToString,
3697
- createSteps: () => createSteps,
3698
- cssDefinedHexColours: () => cssDefinedHexColours,
3699
- cssLinearGradient: () => cssLinearGradient,
3700
- decodeRgbFrom16Bit565: () => decodeRgbFrom16Bit565,
3701
- decodeRgbFrom24Bit: () => decodeRgbFrom24Bit,
3702
- encodeRgbTo16Bit565: () => encodeRgbTo16Bit565,
3703
- encodeRgbTo24Bit: () => encodeRgbTo24Bit,
3704
- fromCssColour: () => fromCssColour,
3705
- goldenAngleColour: () => goldenAngleColour,
3706
- guard: () => guard$1,
3707
- interpolator: () => interpolator,
3708
- interpolatorDual: () => interpolatorDual,
3709
- interpolatorDualToString: () => interpolatorDualToString,
3710
- isColourish: () => isColourish,
3711
- isHsl: () => isHsl,
3712
- isOkLch: () => isOkLch,
3713
- isRgb: () => isRgb,
3714
- multiplyOpacity: () => multiplyOpacity,
3715
- randomHue: () => randomHue,
3716
- resolveCss: () => resolveCss,
3717
- rgbToHsl: () => rgbToHsl,
3718
- scale: () => scale,
3719
- setOpacity: () => setOpacity,
3720
- toColour: () => toColour,
3721
- toCssColour: () => toCssColour,
3722
- toHexColour: () => toHexColour,
3723
- toLibraryColour: () => toLibraryColour,
3724
- toStringFirst: () => toStringFirst,
3725
- tryParseObjectToHsl: () => tryParseObjectToHsl,
3726
- tryParseObjectToRgb: () => tryParseObjectToRgb,
3727
- withOpacity: () => withOpacity
3728
- });
3729
- //#endregion
3730
- export { radiansNormalise as a, isEmpty as c, isPlaceholder as d, isPoint as f, piPi as i, isNaN as l, pointTest as m, average$1 as n, guard$5 as o, isPoint3d as p, averager as r, guardNonZeroPoint as s, colour_exports as t, isNull as u };
3731
-
3732
- //# sourceMappingURL=colour-C3MQIjFJ-vRCdr8W-.js.map