@react-stately/color 3.9.5 → 3.10.0

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