@react-stately/color 3.5.4-nightly.4552 → 3.5.4-nightly.4558

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 (212) hide show
  1. package/dist/Color.main.js +770 -0
  2. package/dist/Color.main.js.map +1 -0
  3. package/dist/Color.mjs +764 -0
  4. package/dist/Color.module.js +764 -0
  5. package/dist/Color.module.js.map +1 -0
  6. package/dist/ar-AE.main.js +2 -2
  7. package/dist/ar-AE.main.js.map +1 -1
  8. package/dist/ar-AE.mjs +3 -3
  9. package/dist/ar-AE.module.js +2 -2
  10. package/dist/ar-AE.module.js.map +1 -1
  11. package/dist/bg-BG.main.js +2 -2
  12. package/dist/bg-BG.main.js.map +1 -1
  13. package/dist/bg-BG.mjs +3 -3
  14. package/dist/bg-BG.module.js +2 -2
  15. package/dist/bg-BG.module.js.map +1 -1
  16. package/dist/cs-CZ.main.js +2 -2
  17. package/dist/cs-CZ.main.js.map +1 -1
  18. package/dist/cs-CZ.mjs +3 -3
  19. package/dist/cs-CZ.module.js +2 -2
  20. package/dist/cs-CZ.module.js.map +1 -1
  21. package/dist/da-DK.main.js +2 -2
  22. package/dist/da-DK.main.js.map +1 -1
  23. package/dist/da-DK.mjs +3 -3
  24. package/dist/da-DK.module.js +2 -2
  25. package/dist/da-DK.module.js.map +1 -1
  26. package/dist/de-DE.main.js +2 -2
  27. package/dist/de-DE.main.js.map +1 -1
  28. package/dist/de-DE.mjs +3 -3
  29. package/dist/de-DE.module.js +2 -2
  30. package/dist/de-DE.module.js.map +1 -1
  31. package/dist/el-GR.main.js +2 -2
  32. package/dist/el-GR.main.js.map +1 -1
  33. package/dist/el-GR.mjs +3 -3
  34. package/dist/el-GR.module.js +2 -2
  35. package/dist/el-GR.module.js.map +1 -1
  36. package/dist/en-US.main.js +2 -2
  37. package/dist/en-US.main.js.map +1 -1
  38. package/dist/en-US.mjs +3 -3
  39. package/dist/en-US.module.js +2 -2
  40. package/dist/en-US.module.js.map +1 -1
  41. package/dist/es-ES.main.js +2 -2
  42. package/dist/es-ES.main.js.map +1 -1
  43. package/dist/es-ES.mjs +3 -3
  44. package/dist/es-ES.module.js +2 -2
  45. package/dist/es-ES.module.js.map +1 -1
  46. package/dist/et-EE.main.js +2 -2
  47. package/dist/et-EE.main.js.map +1 -1
  48. package/dist/et-EE.mjs +3 -3
  49. package/dist/et-EE.module.js +2 -2
  50. package/dist/et-EE.module.js.map +1 -1
  51. package/dist/fi-FI.main.js +2 -2
  52. package/dist/fi-FI.main.js.map +1 -1
  53. package/dist/fi-FI.mjs +3 -3
  54. package/dist/fi-FI.module.js +2 -2
  55. package/dist/fi-FI.module.js.map +1 -1
  56. package/dist/fr-FR.main.js +2 -2
  57. package/dist/fr-FR.main.js.map +1 -1
  58. package/dist/fr-FR.mjs +3 -3
  59. package/dist/fr-FR.module.js +2 -2
  60. package/dist/fr-FR.module.js.map +1 -1
  61. package/dist/he-IL.main.js +2 -2
  62. package/dist/he-IL.main.js.map +1 -1
  63. package/dist/he-IL.mjs +3 -3
  64. package/dist/he-IL.module.js +2 -2
  65. package/dist/he-IL.module.js.map +1 -1
  66. package/dist/hr-HR.main.js +2 -2
  67. package/dist/hr-HR.main.js.map +1 -1
  68. package/dist/hr-HR.mjs +3 -3
  69. package/dist/hr-HR.module.js +2 -2
  70. package/dist/hr-HR.module.js.map +1 -1
  71. package/dist/hu-HU.main.js +2 -2
  72. package/dist/hu-HU.main.js.map +1 -1
  73. package/dist/hu-HU.mjs +3 -3
  74. package/dist/hu-HU.module.js +2 -2
  75. package/dist/hu-HU.module.js.map +1 -1
  76. package/dist/import.mjs +5 -1303
  77. package/dist/intlStrings.main.js +108 -0
  78. package/dist/intlStrings.main.js.map +1 -0
  79. package/dist/intlStrings.mjs +110 -0
  80. package/dist/intlStrings.module.js +110 -0
  81. package/dist/intlStrings.module.js.map +1 -0
  82. package/dist/it-IT.main.js +2 -2
  83. package/dist/it-IT.main.js.map +1 -1
  84. package/dist/it-IT.mjs +3 -3
  85. package/dist/it-IT.module.js +2 -2
  86. package/dist/it-IT.module.js.map +1 -1
  87. package/dist/ja-JP.main.js +2 -2
  88. package/dist/ja-JP.main.js.map +1 -1
  89. package/dist/ja-JP.mjs +3 -3
  90. package/dist/ja-JP.module.js +2 -2
  91. package/dist/ja-JP.module.js.map +1 -1
  92. package/dist/ko-KR.main.js +2 -2
  93. package/dist/ko-KR.main.js.map +1 -1
  94. package/dist/ko-KR.mjs +3 -3
  95. package/dist/ko-KR.module.js +2 -2
  96. package/dist/ko-KR.module.js.map +1 -1
  97. package/dist/lt-LT.main.js +2 -2
  98. package/dist/lt-LT.main.js.map +1 -1
  99. package/dist/lt-LT.mjs +3 -3
  100. package/dist/lt-LT.module.js +2 -2
  101. package/dist/lt-LT.module.js.map +1 -1
  102. package/dist/lv-LV.main.js +2 -2
  103. package/dist/lv-LV.main.js.map +1 -1
  104. package/dist/lv-LV.mjs +3 -3
  105. package/dist/lv-LV.module.js +2 -2
  106. package/dist/lv-LV.module.js.map +1 -1
  107. package/dist/main.js +10 -1308
  108. package/dist/main.js.map +1 -1
  109. package/dist/module.js +5 -1303
  110. package/dist/module.js.map +1 -1
  111. package/dist/nb-NO.main.js +2 -2
  112. package/dist/nb-NO.main.js.map +1 -1
  113. package/dist/nb-NO.mjs +3 -3
  114. package/dist/nb-NO.module.js +2 -2
  115. package/dist/nb-NO.module.js.map +1 -1
  116. package/dist/nl-NL.main.js +2 -2
  117. package/dist/nl-NL.main.js.map +1 -1
  118. package/dist/nl-NL.mjs +3 -3
  119. package/dist/nl-NL.module.js +2 -2
  120. package/dist/nl-NL.module.js.map +1 -1
  121. package/dist/pl-PL.main.js +2 -2
  122. package/dist/pl-PL.main.js.map +1 -1
  123. package/dist/pl-PL.mjs +3 -3
  124. package/dist/pl-PL.module.js +2 -2
  125. package/dist/pl-PL.module.js.map +1 -1
  126. package/dist/pt-BR.main.js +2 -2
  127. package/dist/pt-BR.main.js.map +1 -1
  128. package/dist/pt-BR.mjs +3 -3
  129. package/dist/pt-BR.module.js +2 -2
  130. package/dist/pt-BR.module.js.map +1 -1
  131. package/dist/pt-PT.main.js +2 -2
  132. package/dist/pt-PT.main.js.map +1 -1
  133. package/dist/pt-PT.mjs +3 -3
  134. package/dist/pt-PT.module.js +2 -2
  135. package/dist/pt-PT.module.js.map +1 -1
  136. package/dist/ro-RO.main.js +2 -2
  137. package/dist/ro-RO.main.js.map +1 -1
  138. package/dist/ro-RO.mjs +3 -3
  139. package/dist/ro-RO.module.js +2 -2
  140. package/dist/ro-RO.module.js.map +1 -1
  141. package/dist/ru-RU.main.js +2 -2
  142. package/dist/ru-RU.main.js.map +1 -1
  143. package/dist/ru-RU.mjs +3 -3
  144. package/dist/ru-RU.module.js +2 -2
  145. package/dist/ru-RU.module.js.map +1 -1
  146. package/dist/sk-SK.main.js +2 -2
  147. package/dist/sk-SK.main.js.map +1 -1
  148. package/dist/sk-SK.mjs +3 -3
  149. package/dist/sk-SK.module.js +2 -2
  150. package/dist/sk-SK.module.js.map +1 -1
  151. package/dist/sl-SI.main.js +2 -2
  152. package/dist/sl-SI.main.js.map +1 -1
  153. package/dist/sl-SI.mjs +3 -3
  154. package/dist/sl-SI.module.js +2 -2
  155. package/dist/sl-SI.module.js.map +1 -1
  156. package/dist/sr-SP.main.js +2 -2
  157. package/dist/sr-SP.main.js.map +1 -1
  158. package/dist/sr-SP.mjs +3 -3
  159. package/dist/sr-SP.module.js +2 -2
  160. package/dist/sr-SP.module.js.map +1 -1
  161. package/dist/sv-SE.main.js +2 -2
  162. package/dist/sv-SE.main.js.map +1 -1
  163. package/dist/sv-SE.mjs +3 -3
  164. package/dist/sv-SE.module.js +2 -2
  165. package/dist/sv-SE.module.js.map +1 -1
  166. package/dist/tr-TR.main.js +2 -2
  167. package/dist/tr-TR.main.js.map +1 -1
  168. package/dist/tr-TR.mjs +3 -3
  169. package/dist/tr-TR.module.js +2 -2
  170. package/dist/tr-TR.module.js.map +1 -1
  171. package/dist/uk-UA.main.js +2 -2
  172. package/dist/uk-UA.main.js.map +1 -1
  173. package/dist/uk-UA.mjs +3 -3
  174. package/dist/uk-UA.module.js +2 -2
  175. package/dist/uk-UA.module.js.map +1 -1
  176. package/dist/useColor.main.js +36 -0
  177. package/dist/useColor.main.js.map +1 -0
  178. package/dist/useColor.mjs +31 -0
  179. package/dist/useColor.module.js +31 -0
  180. package/dist/useColor.module.js.map +1 -0
  181. package/dist/useColorAreaState.main.js +124 -0
  182. package/dist/useColorAreaState.main.js.map +1 -0
  183. package/dist/useColorAreaState.mjs +119 -0
  184. package/dist/useColorAreaState.module.js +119 -0
  185. package/dist/useColorAreaState.module.js.map +1 -0
  186. package/dist/useColorFieldState.main.js +138 -0
  187. package/dist/useColorFieldState.main.js.map +1 -0
  188. package/dist/useColorFieldState.mjs +133 -0
  189. package/dist/useColorFieldState.module.js +133 -0
  190. package/dist/useColorFieldState.module.js.map +1 -0
  191. package/dist/useColorSliderState.main.js +75 -0
  192. package/dist/useColorSliderState.main.js.map +1 -0
  193. package/dist/useColorSliderState.mjs +70 -0
  194. package/dist/useColorSliderState.module.js +70 -0
  195. package/dist/useColorSliderState.module.js.map +1 -0
  196. package/dist/useColorWheelState.main.js +123 -0
  197. package/dist/useColorWheelState.main.js.map +1 -0
  198. package/dist/useColorWheelState.mjs +118 -0
  199. package/dist/useColorWheelState.module.js +118 -0
  200. package/dist/useColorWheelState.module.js.map +1 -0
  201. package/dist/zh-CN.main.js +2 -2
  202. package/dist/zh-CN.main.js.map +1 -1
  203. package/dist/zh-CN.mjs +3 -3
  204. package/dist/zh-CN.module.js +2 -2
  205. package/dist/zh-CN.module.js.map +1 -1
  206. package/dist/zh-TW.main.js +2 -2
  207. package/dist/zh-TW.main.js.map +1 -1
  208. package/dist/zh-TW.mjs +3 -3
  209. package/dist/zh-TW.module.js +2 -2
  210. package/dist/zh-TW.module.js.map +1 -1
  211. package/package.json +9 -9
  212. package/src/Color.ts +13 -10
@@ -0,0 +1,770 @@
1
+ var $097dc310d9980f22$exports = require("./intlStrings.main.js");
2
+ var $5BFmN$reactstatelyutils = require("@react-stately/utils");
3
+ var $5BFmN$internationalizedstring = require("@internationalized/string");
4
+ var $5BFmN$internationalizednumber = require("@internationalized/number");
5
+
6
+
7
+ function $parcel$interopDefault(a) {
8
+ return a && a.__esModule ? a.default : a;
9
+ }
10
+
11
+ function $parcel$export(e, n, v, s) {
12
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
13
+ }
14
+
15
+ $parcel$export(module.exports, "parseColor", () => $83fe1a57d631223b$export$6e865ea70d7724f);
16
+ $parcel$export(module.exports, "normalizeColor", () => $83fe1a57d631223b$export$4cde5df63f53f473);
17
+ /*
18
+ * Copyright 2020 Adobe. All rights reserved.
19
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License. You may obtain a copy
21
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software distributed under
24
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
25
+ * OF ANY KIND, either express or implied. See the License for the specific language
26
+ * governing permissions and limitations under the License.
27
+ */
28
+
29
+
30
+
31
+ let $83fe1a57d631223b$var$dictionary = new (0, $5BFmN$internationalizedstring.LocalizedStringDictionary)((0, ($parcel$interopDefault($097dc310d9980f22$exports))));
32
+ function $83fe1a57d631223b$export$6e865ea70d7724f(value) {
33
+ let res = $83fe1a57d631223b$var$RGBColor.parse(value) || $83fe1a57d631223b$var$HSBColor.parse(value) || $83fe1a57d631223b$var$HSLColor.parse(value);
34
+ if (res) return res;
35
+ throw new Error("Invalid color value: " + value);
36
+ }
37
+ function $83fe1a57d631223b$export$4cde5df63f53f473(v) {
38
+ if (typeof v === "string") return $83fe1a57d631223b$export$6e865ea70d7724f(v);
39
+ else return v;
40
+ }
41
+ // Lightness threshold between orange and brown.
42
+ const $83fe1a57d631223b$var$ORANGE_LIGHTNESS_THRESHOLD = 0.68;
43
+ // Lightness threshold between pure yellow and "yellow green".
44
+ const $83fe1a57d631223b$var$YELLOW_GREEN_LIGHTNESS_THRESHOLD = 0.85;
45
+ // The maximum lightness considered to be "dark".
46
+ const $83fe1a57d631223b$var$MAX_DARK_LIGHTNESS = 0.55;
47
+ // The chroma threshold between gray and color.
48
+ const $83fe1a57d631223b$var$GRAY_THRESHOLD = 0.001;
49
+ const $83fe1a57d631223b$var$OKLCH_HUES = [
50
+ [
51
+ 0,
52
+ "pink"
53
+ ],
54
+ [
55
+ 15,
56
+ "red"
57
+ ],
58
+ [
59
+ 48,
60
+ "orange"
61
+ ],
62
+ [
63
+ 94,
64
+ "yellow"
65
+ ],
66
+ [
67
+ 135,
68
+ "green"
69
+ ],
70
+ [
71
+ 175,
72
+ "cyan"
73
+ ],
74
+ [
75
+ 264,
76
+ "blue"
77
+ ],
78
+ [
79
+ 284,
80
+ "purple"
81
+ ],
82
+ [
83
+ 320,
84
+ "magenta"
85
+ ],
86
+ [
87
+ 349,
88
+ "pink"
89
+ ]
90
+ ];
91
+ class $83fe1a57d631223b$var$Color {
92
+ toHexInt() {
93
+ return this.toFormat("rgb").toHexInt();
94
+ }
95
+ getChannelValue(channel) {
96
+ if (channel in this) return this[channel];
97
+ throw new Error("Unsupported color channel: " + channel);
98
+ }
99
+ withChannelValue(channel, value) {
100
+ if (channel in this) {
101
+ let x = this.clone();
102
+ x[channel] = value;
103
+ return x;
104
+ }
105
+ throw new Error("Unsupported color channel: " + channel);
106
+ }
107
+ getChannelName(channel, locale) {
108
+ let strings = (0, $5BFmN$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $83fe1a57d631223b$var$dictionary;
109
+ return strings.getStringForLocale(channel, locale);
110
+ }
111
+ getColorSpaceAxes(xyChannels) {
112
+ let { xChannel: xChannel, yChannel: yChannel } = xyChannels;
113
+ let xCh = xChannel || this.getColorChannels().find((c)=>c !== yChannel);
114
+ let yCh = yChannel || this.getColorChannels().find((c)=>c !== xCh);
115
+ let zCh = this.getColorChannels().find((c)=>c !== xCh && c !== yCh);
116
+ return {
117
+ xChannel: xCh,
118
+ yChannel: yCh,
119
+ zChannel: zCh
120
+ };
121
+ }
122
+ getColorName(locale) {
123
+ // Convert to oklch color space, which has perceptually uniform lightness across all hues.
124
+ let [l, c, h] = $83fe1a57d631223b$var$toOKLCH(this);
125
+ let strings = (0, $5BFmN$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $83fe1a57d631223b$var$dictionary;
126
+ if (l > 0.999) return strings.getStringForLocale("white", locale);
127
+ if (l < 0.001) return strings.getStringForLocale("black", locale);
128
+ let hue;
129
+ [hue, l] = this.getOklchHue(l, c, h, locale);
130
+ let lightness = "";
131
+ let chroma = "";
132
+ if (c <= 0.1 && c >= $83fe1a57d631223b$var$GRAY_THRESHOLD) {
133
+ if (l >= 0.7) chroma = "pale";
134
+ else chroma = "grayish";
135
+ } else if (c >= 0.15) chroma = "vibrant";
136
+ if (l < 0.3) lightness = "very dark";
137
+ else if (l < $83fe1a57d631223b$var$MAX_DARK_LIGHTNESS) lightness = "dark";
138
+ else if (l < 0.7) ;
139
+ else if (l < 0.85) lightness = "light";
140
+ else lightness = "very light";
141
+ if (chroma) chroma = strings.getStringForLocale(chroma, locale);
142
+ if (lightness) lightness = strings.getStringForLocale(lightness, locale);
143
+ let alpha = this.getChannelValue("alpha");
144
+ let formatter = new (0, $5BFmN$internationalizedstring.LocalizedStringFormatter)(locale, strings);
145
+ if (alpha < 1) {
146
+ let percentTransparent = new (0, $5BFmN$internationalizednumber.NumberFormatter)(locale, {
147
+ style: "percent"
148
+ }).format(1 - alpha);
149
+ return formatter.format("transparentColorName", {
150
+ lightness: lightness,
151
+ chroma: chroma,
152
+ hue: hue,
153
+ percentTransparent: percentTransparent
154
+ }).replace(/\s+/g, " ").trim();
155
+ } else return formatter.format("colorName", {
156
+ lightness: lightness,
157
+ chroma: chroma,
158
+ hue: hue
159
+ }).replace(/\s+/g, " ").trim();
160
+ }
161
+ getOklchHue(l, c, h, locale) {
162
+ let strings = (0, $5BFmN$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $83fe1a57d631223b$var$dictionary;
163
+ if (c < $83fe1a57d631223b$var$GRAY_THRESHOLD) return [
164
+ strings.getStringForLocale("gray", locale),
165
+ l
166
+ ];
167
+ for(let i = 0; i < $83fe1a57d631223b$var$OKLCH_HUES.length; i++){
168
+ let [hue, hueName] = $83fe1a57d631223b$var$OKLCH_HUES[i];
169
+ let [nextHue, nextHueName] = $83fe1a57d631223b$var$OKLCH_HUES[i + 1] || [
170
+ 360,
171
+ "pink"
172
+ ];
173
+ if (h >= hue && h < nextHue) {
174
+ // Split orange hue into brown/orange depending on lightness.
175
+ if (hueName === "orange") {
176
+ if (l < $83fe1a57d631223b$var$ORANGE_LIGHTNESS_THRESHOLD) hueName = "brown";
177
+ else // Adjust lightness.
178
+ l = l - $83fe1a57d631223b$var$ORANGE_LIGHTNESS_THRESHOLD + $83fe1a57d631223b$var$MAX_DARK_LIGHTNESS;
179
+ }
180
+ // If the hue is at least halfway to the next hue, add the next hue name as well.
181
+ if (h > hue + (nextHue - hue) / 2 && hueName !== nextHueName) hueName = `${hueName} ${nextHueName}`;
182
+ else if (hueName === "yellow" && l < $83fe1a57d631223b$var$YELLOW_GREEN_LIGHTNESS_THRESHOLD) // Yellow shifts toward green at lower lightnesses.
183
+ hueName = "yellow green";
184
+ let name = strings.getStringForLocale(hueName, locale).toLocaleLowerCase(locale);
185
+ return [
186
+ name,
187
+ l
188
+ ];
189
+ }
190
+ }
191
+ throw new Error("Unexpected hue");
192
+ }
193
+ getHueName(locale) {
194
+ let [l, c, h] = $83fe1a57d631223b$var$toOKLCH(this);
195
+ let [name] = this.getOklchHue(l, c, h, locale);
196
+ return name;
197
+ }
198
+ }
199
+ class $83fe1a57d631223b$var$RGBColor extends $83fe1a57d631223b$var$Color {
200
+ static parse(value) {
201
+ let colors = [];
202
+ // matching #rgb, #rgba, #rrggbb, #rrggbbaa
203
+ if (/^#[\da-f]+$/i.test(value) && [
204
+ 4,
205
+ 5,
206
+ 7,
207
+ 9
208
+ ].includes(value.length)) {
209
+ const values = (value.length < 6 ? value.replace(/[^#]/gi, "$&$&") : value).slice(1).split("");
210
+ while(values.length > 0)colors.push(parseInt(values.splice(0, 2).join(""), 16));
211
+ colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;
212
+ }
213
+ // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)
214
+ const match = value.match(/^rgba?\((.*)\)$/);
215
+ if (match === null || match === void 0 ? void 0 : match[1]) {
216
+ colors = match[1].split(",").map((value)=>Number(value.trim()));
217
+ colors = colors.map((num, i)=>(0, $5BFmN$reactstatelyutils.clamp)(num, 0, i < 3 ? 255 : 1));
218
+ }
219
+ var _colors_;
220
+ return colors.length < 3 ? undefined : new $83fe1a57d631223b$var$RGBColor(colors[0], colors[1], colors[2], (_colors_ = colors[3]) !== null && _colors_ !== void 0 ? _colors_ : 1);
221
+ }
222
+ toString(format) {
223
+ switch(format){
224
+ case "hex":
225
+ return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
226
+ case "hexa":
227
+ return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0") + Math.round(this.alpha * 255).toString(16).padStart(2, "0")).toUpperCase();
228
+ case "rgb":
229
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
230
+ case "css":
231
+ case "rgba":
232
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
233
+ default:
234
+ return this.toFormat(format).toString(format);
235
+ }
236
+ }
237
+ toFormat(format) {
238
+ switch(format){
239
+ case "hex":
240
+ case "hexa":
241
+ case "rgb":
242
+ case "rgba":
243
+ return this;
244
+ case "hsb":
245
+ case "hsba":
246
+ return this.toHSB();
247
+ case "hsl":
248
+ case "hsla":
249
+ return this.toHSL();
250
+ default:
251
+ throw new Error("Unsupported color conversion: rgb -> " + format);
252
+ }
253
+ }
254
+ toHexInt() {
255
+ return this.red << 16 | this.green << 8 | this.blue;
256
+ }
257
+ /**
258
+ * Converts an RGB color value to HSB.
259
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
260
+ * @returns An HSBColor object.
261
+ */ toHSB() {
262
+ const red = this.red / 255;
263
+ const green = this.green / 255;
264
+ const blue = this.blue / 255;
265
+ const min = Math.min(red, green, blue);
266
+ const brightness = Math.max(red, green, blue);
267
+ const chroma = brightness - min;
268
+ const saturation = brightness === 0 ? 0 : chroma / brightness;
269
+ let hue = 0; // achromatic
270
+ if (chroma !== 0) {
271
+ switch(brightness){
272
+ case red:
273
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
274
+ break;
275
+ case green:
276
+ hue = (blue - red) / chroma + 2;
277
+ break;
278
+ case blue:
279
+ hue = (red - green) / chroma + 4;
280
+ break;
281
+ }
282
+ hue /= 6;
283
+ }
284
+ return new $83fe1a57d631223b$var$HSBColor((0, $5BFmN$reactstatelyutils.toFixedNumber)(hue * 360, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(saturation * 100, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(brightness * 100, 2), this.alpha);
285
+ }
286
+ /**
287
+ * Converts an RGB color value to HSL.
288
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
289
+ * @returns An HSLColor object.
290
+ */ toHSL() {
291
+ const red = this.red / 255;
292
+ const green = this.green / 255;
293
+ const blue = this.blue / 255;
294
+ const min = Math.min(red, green, blue);
295
+ const max = Math.max(red, green, blue);
296
+ const lightness = (max + min) / 2;
297
+ const chroma = max - min;
298
+ let hue;
299
+ let saturation;
300
+ if (chroma === 0) hue = saturation = 0; // achromatic
301
+ else {
302
+ saturation = chroma / (lightness < .5 ? max + min : 2 - max - min);
303
+ switch(max){
304
+ case red:
305
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
306
+ break;
307
+ case green:
308
+ hue = (blue - red) / chroma + 2;
309
+ break;
310
+ case blue:
311
+ hue = (red - green) / chroma + 4;
312
+ break;
313
+ }
314
+ hue /= 6;
315
+ }
316
+ return new $83fe1a57d631223b$var$HSLColor((0, $5BFmN$reactstatelyutils.toFixedNumber)(hue * 360, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(saturation * 100, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(lightness * 100, 2), this.alpha);
317
+ }
318
+ clone() {
319
+ return new $83fe1a57d631223b$var$RGBColor(this.red, this.green, this.blue, this.alpha);
320
+ }
321
+ getChannelRange(channel) {
322
+ switch(channel){
323
+ case "red":
324
+ case "green":
325
+ case "blue":
326
+ return {
327
+ minValue: 0x0,
328
+ maxValue: 0xFF,
329
+ step: 0x1,
330
+ pageSize: 0x11
331
+ };
332
+ case "alpha":
333
+ return {
334
+ minValue: 0,
335
+ maxValue: 1,
336
+ step: 0.01,
337
+ pageSize: 0.1
338
+ };
339
+ default:
340
+ throw new Error("Unknown color channel: " + channel);
341
+ }
342
+ }
343
+ formatChannelValue(channel, locale) {
344
+ let options;
345
+ let value = this.getChannelValue(channel);
346
+ switch(channel){
347
+ case "red":
348
+ case "green":
349
+ case "blue":
350
+ options = {
351
+ style: "decimal"
352
+ };
353
+ break;
354
+ case "alpha":
355
+ options = {
356
+ style: "percent"
357
+ };
358
+ break;
359
+ default:
360
+ throw new Error("Unknown color channel: " + channel);
361
+ }
362
+ return new (0, $5BFmN$internationalizednumber.NumberFormatter)(locale, options).format(value);
363
+ }
364
+ getColorSpace() {
365
+ return "rgb";
366
+ }
367
+ getColorChannels() {
368
+ return $83fe1a57d631223b$var$RGBColor.colorChannels;
369
+ }
370
+ constructor(red, green, blue, alpha){
371
+ super();
372
+ this.red = red;
373
+ this.green = green;
374
+ this.blue = blue;
375
+ this.alpha = alpha;
376
+ }
377
+ }
378
+ $83fe1a57d631223b$var$RGBColor.colorChannels = [
379
+ "red",
380
+ "green",
381
+ "blue"
382
+ ];
383
+ // X = <negative/positive number with/without decimal places>
384
+ // before/after a comma, 0 or more whitespaces are allowed
385
+ // - hsb(X, X%, X%)
386
+ // - hsba(X, X%, X%, X)
387
+ const $83fe1a57d631223b$var$HSB_REGEX = /hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
388
+ class $83fe1a57d631223b$var$HSBColor extends $83fe1a57d631223b$var$Color {
389
+ static parse(value) {
390
+ let m;
391
+ if (m = value.match($83fe1a57d631223b$var$HSB_REGEX)) {
392
+ var _m_;
393
+ const [h, s, b, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
394
+ return new $83fe1a57d631223b$var$HSBColor($83fe1a57d631223b$var$mod(h, 360), (0, $5BFmN$reactstatelyutils.clamp)(s, 0, 100), (0, $5BFmN$reactstatelyutils.clamp)(b, 0, 100), (0, $5BFmN$reactstatelyutils.clamp)(a !== null && a !== void 0 ? a : 1, 0, 1));
395
+ }
396
+ }
397
+ toString(format) {
398
+ switch(format){
399
+ case "css":
400
+ return this.toHSL().toString("css");
401
+ case "hex":
402
+ return this.toRGB().toString("hex");
403
+ case "hexa":
404
+ return this.toRGB().toString("hexa");
405
+ case "hsb":
406
+ return `hsb(${this.hue}, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.saturation, 2)}%, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.brightness, 2)}%)`;
407
+ case "hsba":
408
+ return `hsba(${this.hue}, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.saturation, 2)}%, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
409
+ default:
410
+ return this.toFormat(format).toString(format);
411
+ }
412
+ }
413
+ toFormat(format) {
414
+ switch(format){
415
+ case "hsb":
416
+ case "hsba":
417
+ return this;
418
+ case "hsl":
419
+ case "hsla":
420
+ return this.toHSL();
421
+ case "rgb":
422
+ case "rgba":
423
+ return this.toRGB();
424
+ default:
425
+ throw new Error("Unsupported color conversion: hsb -> " + format);
426
+ }
427
+ }
428
+ /**
429
+ * Converts a HSB color to HSL.
430
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
431
+ * @returns An HSLColor object.
432
+ */ toHSL() {
433
+ let saturation = this.saturation / 100;
434
+ let brightness = this.brightness / 100;
435
+ let lightness = brightness * (1 - saturation / 2);
436
+ saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
437
+ return new $83fe1a57d631223b$var$HSLColor((0, $5BFmN$reactstatelyutils.toFixedNumber)(this.hue, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(saturation * 100, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(lightness * 100, 2), this.alpha);
438
+ }
439
+ /**
440
+ * Converts a HSV color value to RGB.
441
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
442
+ * @returns An RGBColor object.
443
+ */ toRGB() {
444
+ let hue = this.hue;
445
+ let saturation = this.saturation / 100;
446
+ let brightness = this.brightness / 100;
447
+ let fn = (n, k = (n + hue / 60) % 6)=>brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
448
+ return new $83fe1a57d631223b$var$RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha);
449
+ }
450
+ clone() {
451
+ return new $83fe1a57d631223b$var$HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
452
+ }
453
+ getChannelRange(channel) {
454
+ switch(channel){
455
+ case "hue":
456
+ return {
457
+ minValue: 0,
458
+ maxValue: 360,
459
+ step: 1,
460
+ pageSize: 15
461
+ };
462
+ case "saturation":
463
+ case "brightness":
464
+ return {
465
+ minValue: 0,
466
+ maxValue: 100,
467
+ step: 1,
468
+ pageSize: 10
469
+ };
470
+ case "alpha":
471
+ return {
472
+ minValue: 0,
473
+ maxValue: 1,
474
+ step: 0.01,
475
+ pageSize: 0.1
476
+ };
477
+ default:
478
+ throw new Error("Unknown color channel: " + channel);
479
+ }
480
+ }
481
+ formatChannelValue(channel, locale) {
482
+ let options;
483
+ let value = this.getChannelValue(channel);
484
+ switch(channel){
485
+ case "hue":
486
+ options = {
487
+ style: "unit",
488
+ unit: "degree",
489
+ unitDisplay: "narrow"
490
+ };
491
+ break;
492
+ case "saturation":
493
+ case "brightness":
494
+ options = {
495
+ style: "percent"
496
+ };
497
+ value /= 100;
498
+ break;
499
+ case "alpha":
500
+ options = {
501
+ style: "percent"
502
+ };
503
+ break;
504
+ default:
505
+ throw new Error("Unknown color channel: " + channel);
506
+ }
507
+ return new (0, $5BFmN$internationalizednumber.NumberFormatter)(locale, options).format(value);
508
+ }
509
+ getColorSpace() {
510
+ return "hsb";
511
+ }
512
+ getColorChannels() {
513
+ return $83fe1a57d631223b$var$HSBColor.colorChannels;
514
+ }
515
+ constructor(hue, saturation, brightness, alpha){
516
+ super();
517
+ this.hue = hue;
518
+ this.saturation = saturation;
519
+ this.brightness = brightness;
520
+ this.alpha = alpha;
521
+ }
522
+ }
523
+ $83fe1a57d631223b$var$HSBColor.colorChannels = [
524
+ "hue",
525
+ "saturation",
526
+ "brightness"
527
+ ];
528
+ // X = <negative/positive number with/without decimal places>
529
+ // before/after a comma, 0 or more whitespaces are allowed
530
+ // - hsl(X, X%, X%)
531
+ // - hsla(X, X%, X%, X)
532
+ const $83fe1a57d631223b$var$HSL_REGEX = /hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
533
+ function $83fe1a57d631223b$var$mod(n, m) {
534
+ return (n % m + m) % m;
535
+ }
536
+ class $83fe1a57d631223b$var$HSLColor extends $83fe1a57d631223b$var$Color {
537
+ static parse(value) {
538
+ let m;
539
+ if (m = value.match($83fe1a57d631223b$var$HSL_REGEX)) {
540
+ var _m_;
541
+ const [h, s, l, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
542
+ return new $83fe1a57d631223b$var$HSLColor($83fe1a57d631223b$var$mod(h, 360), (0, $5BFmN$reactstatelyutils.clamp)(s, 0, 100), (0, $5BFmN$reactstatelyutils.clamp)(l, 0, 100), (0, $5BFmN$reactstatelyutils.clamp)(a !== null && a !== void 0 ? a : 1, 0, 1));
543
+ }
544
+ }
545
+ toString(format) {
546
+ switch(format){
547
+ case "hex":
548
+ return this.toRGB().toString("hex");
549
+ case "hexa":
550
+ return this.toRGB().toString("hexa");
551
+ case "hsl":
552
+ return `hsl(${this.hue}, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.saturation, 2)}%, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.lightness, 2)}%)`;
553
+ case "css":
554
+ case "hsla":
555
+ return `hsla(${this.hue}, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.saturation, 2)}%, ${(0, $5BFmN$reactstatelyutils.toFixedNumber)(this.lightness, 2)}%, ${this.alpha})`;
556
+ default:
557
+ return this.toFormat(format).toString(format);
558
+ }
559
+ }
560
+ toFormat(format) {
561
+ switch(format){
562
+ case "hsl":
563
+ case "hsla":
564
+ return this;
565
+ case "hsb":
566
+ case "hsba":
567
+ return this.toHSB();
568
+ case "rgb":
569
+ case "rgba":
570
+ return this.toRGB();
571
+ default:
572
+ throw new Error("Unsupported color conversion: hsl -> " + format);
573
+ }
574
+ }
575
+ /**
576
+ * Converts a HSL color to HSB.
577
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
578
+ * @returns An HSBColor object.
579
+ */ toHSB() {
580
+ let saturation = this.saturation / 100;
581
+ let lightness = this.lightness / 100;
582
+ let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
583
+ saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
584
+ return new $83fe1a57d631223b$var$HSBColor((0, $5BFmN$reactstatelyutils.toFixedNumber)(this.hue, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(saturation * 100, 2), (0, $5BFmN$reactstatelyutils.toFixedNumber)(brightness * 100, 2), this.alpha);
585
+ }
586
+ /**
587
+ * Converts a HSL color to RGB.
588
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
589
+ * @returns An RGBColor object.
590
+ */ toRGB() {
591
+ let hue = this.hue;
592
+ let saturation = this.saturation / 100;
593
+ let lightness = this.lightness / 100;
594
+ let a = saturation * Math.min(lightness, 1 - lightness);
595
+ let fn = (n, k = (n + hue / 30) % 12)=>lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
596
+ return new $83fe1a57d631223b$var$RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha);
597
+ }
598
+ clone() {
599
+ return new $83fe1a57d631223b$var$HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
600
+ }
601
+ getChannelRange(channel) {
602
+ switch(channel){
603
+ case "hue":
604
+ return {
605
+ minValue: 0,
606
+ maxValue: 360,
607
+ step: 1,
608
+ pageSize: 15
609
+ };
610
+ case "saturation":
611
+ case "lightness":
612
+ return {
613
+ minValue: 0,
614
+ maxValue: 100,
615
+ step: 1,
616
+ pageSize: 10
617
+ };
618
+ case "alpha":
619
+ return {
620
+ minValue: 0,
621
+ maxValue: 1,
622
+ step: 0.01,
623
+ pageSize: 0.1
624
+ };
625
+ default:
626
+ throw new Error("Unknown color channel: " + channel);
627
+ }
628
+ }
629
+ formatChannelValue(channel, locale) {
630
+ let options;
631
+ let value = this.getChannelValue(channel);
632
+ switch(channel){
633
+ case "hue":
634
+ options = {
635
+ style: "unit",
636
+ unit: "degree",
637
+ unitDisplay: "narrow"
638
+ };
639
+ break;
640
+ case "saturation":
641
+ case "lightness":
642
+ options = {
643
+ style: "percent"
644
+ };
645
+ value /= 100;
646
+ break;
647
+ case "alpha":
648
+ options = {
649
+ style: "percent"
650
+ };
651
+ break;
652
+ default:
653
+ throw new Error("Unknown color channel: " + channel);
654
+ }
655
+ return new (0, $5BFmN$internationalizednumber.NumberFormatter)(locale, options).format(value);
656
+ }
657
+ getColorSpace() {
658
+ return "hsl";
659
+ }
660
+ getColorChannels() {
661
+ return $83fe1a57d631223b$var$HSLColor.colorChannels;
662
+ }
663
+ constructor(hue, saturation, lightness, alpha){
664
+ super();
665
+ this.hue = hue;
666
+ this.saturation = saturation;
667
+ this.lightness = lightness;
668
+ this.alpha = alpha;
669
+ }
670
+ }
671
+ $83fe1a57d631223b$var$HSLColor.colorChannels = [
672
+ "hue",
673
+ "saturation",
674
+ "lightness"
675
+ ];
676
+ // https://www.w3.org/TR/css-color-4/#color-conversion-code
677
+ function $83fe1a57d631223b$var$toOKLCH(color) {
678
+ let rgb = color.toFormat("rgb");
679
+ let red = rgb.getChannelValue("red") / 255;
680
+ let green = rgb.getChannelValue("green") / 255;
681
+ let blue = rgb.getChannelValue("blue") / 255;
682
+ [red, green, blue] = $83fe1a57d631223b$var$lin_sRGB(red, green, blue);
683
+ let [x, y, z] = $83fe1a57d631223b$var$lin_sRGB_to_XYZ(red, green, blue);
684
+ let [l, a, b] = $83fe1a57d631223b$var$XYZ_to_OKLab(x, y, z);
685
+ return $83fe1a57d631223b$var$OKLab_to_OKLCH(l, a, b);
686
+ }
687
+ function $83fe1a57d631223b$var$OKLab_to_OKLCH(l, a, b) {
688
+ var hue = Math.atan2(b, a) * 180 / Math.PI;
689
+ return [
690
+ l,
691
+ Math.sqrt(a ** 2 + b ** 2),
692
+ hue >= 0 ? hue : hue + 360 // Hue, in degrees [0 to 360)
693
+ ];
694
+ }
695
+ function $83fe1a57d631223b$var$lin_sRGB(r, g, b) {
696
+ // convert an array of sRGB values
697
+ // where in-gamut values are in the range [0 - 1]
698
+ // to linear light (un-companded) form.
699
+ // https://en.wikipedia.org/wiki/SRGB
700
+ // Extended transfer function:
701
+ // for negative values, linear portion is extended on reflection of axis,
702
+ // then reflected power function is used.
703
+ return [
704
+ $83fe1a57d631223b$var$lin_sRGB_component(r),
705
+ $83fe1a57d631223b$var$lin_sRGB_component(g),
706
+ $83fe1a57d631223b$var$lin_sRGB_component(b)
707
+ ];
708
+ }
709
+ function $83fe1a57d631223b$var$lin_sRGB_component(val) {
710
+ let sign = val < 0 ? -1 : 1;
711
+ let abs = Math.abs(val);
712
+ if (abs <= 0.04045) return val / 12.92;
713
+ return sign * Math.pow((abs + 0.055) / 1.055, 2.4);
714
+ }
715
+ function $83fe1a57d631223b$var$lin_sRGB_to_XYZ(r, g, b) {
716
+ // convert an array of linear-light sRGB values to CIE XYZ
717
+ // using sRGB's own white, D65 (no chromatic adaptation)
718
+ const M = [
719
+ 506752 / 1228815,
720
+ 87881 / 245763,
721
+ 12673 / 70218,
722
+ 87098 / 409605,
723
+ 175762 / 245763,
724
+ 12673 / 175545,
725
+ 7918 / 409605,
726
+ 87881 / 737289,
727
+ 1001167 / 1053270
728
+ ];
729
+ return $83fe1a57d631223b$var$multiplyMatrix(M, r, g, b);
730
+ }
731
+ function $83fe1a57d631223b$var$XYZ_to_OKLab(x, y, z) {
732
+ // Given XYZ relative to D65, convert to OKLab
733
+ const XYZtoLMS = [
734
+ 0.8190224379967030,
735
+ 0.3619062600528904,
736
+ -0.1288737815209879,
737
+ 0.0329836539323885,
738
+ 0.9292868615863434,
739
+ 0.0361446663506424,
740
+ 0.0481771893596242,
741
+ 0.2642395317527308,
742
+ 0.6335478284694309
743
+ ];
744
+ const LMStoOKLab = [
745
+ 0.2104542683093140,
746
+ 0.7936177747023054,
747
+ -0.0040720430116193,
748
+ 1.9779985324311684,
749
+ -2.42859224204858,
750
+ 0.4505937096174110,
751
+ 0.0259040424655478,
752
+ 0.7827717124575296,
753
+ -0.8086757549230774
754
+ ];
755
+ let [a, b, c] = $83fe1a57d631223b$var$multiplyMatrix(XYZtoLMS, x, y, z);
756
+ return $83fe1a57d631223b$var$multiplyMatrix(LMStoOKLab, Math.cbrt(a), Math.cbrt(b), Math.cbrt(c));
757
+ }
758
+ function $83fe1a57d631223b$var$multiplyMatrix(m, x, y, z) {
759
+ let a = m[0] * x + m[1] * y + m[2] * z;
760
+ let b = m[3] * x + m[4] * y + m[5] * z;
761
+ let c = m[6] * x + m[7] * y + m[8] * z;
762
+ return [
763
+ a,
764
+ b,
765
+ c
766
+ ];
767
+ }
768
+
769
+
770
+ //# sourceMappingURL=Color.main.js.map