@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
package/dist/module.js CHANGED
@@ -1,882 +1,8 @@
1
- import $2d805fd52bb48883$exports from "./ar-AE.module.js";
2
- import $6c28468dc1df643c$exports from "./bg-BG.module.js";
3
- import $807554f8230db0ed$exports from "./cs-CZ.module.js";
4
- import $7097f64386f1761c$exports from "./da-DK.module.js";
5
- import $bdd847d8beb08799$exports from "./de-DE.module.js";
6
- import $a53e00b683950971$exports from "./el-GR.module.js";
7
- import $21cdd87e84f28d89$exports from "./en-US.module.js";
8
- import $92fee9698e4d675a$exports from "./es-ES.module.js";
9
- import $7ea012e91a5ad3ee$exports from "./et-EE.module.js";
10
- import $8460c13bb2d75345$exports from "./fi-FI.module.js";
11
- import $2a2d5dc14e680587$exports from "./fr-FR.module.js";
12
- import $9a3f292371bb0589$exports from "./he-IL.module.js";
13
- import $4742231a685fa068$exports from "./hr-HR.module.js";
14
- import $05e247fd2960981e$exports from "./hu-HU.module.js";
15
- import $a67524a79ccbe190$exports from "./it-IT.module.js";
16
- import $a9eefe9d6c8cb7d5$exports from "./ja-JP.module.js";
17
- import $4a6b836d4f1bfaba$exports from "./ko-KR.module.js";
18
- import $c950e4b1c482abde$exports from "./lt-LT.module.js";
19
- import $d10d6b60dc50b438$exports from "./lv-LV.module.js";
20
- import $371a732b2494f452$exports from "./nb-NO.module.js";
21
- import $6d042cae6243464b$exports from "./nl-NL.module.js";
22
- import $d9ab5c2611e0bcd3$exports from "./pl-PL.module.js";
23
- import $73f77c9902e29ca6$exports from "./pt-BR.module.js";
24
- import $4f461eb266a95c10$exports from "./pt-PT.module.js";
25
- import $dc46bea2f2597899$exports from "./ro-RO.module.js";
26
- import $622bbd6719cc95af$exports from "./ru-RU.module.js";
27
- import $4da03c1ecd9a9c7d$exports from "./sk-SK.module.js";
28
- import $edb6b2fe456ed4e8$exports from "./sl-SI.module.js";
29
- import $264cd81c52b30815$exports from "./sr-SP.module.js";
30
- import $6f80afde0270dda7$exports from "./sv-SE.module.js";
31
- import $23a92651c6957668$exports from "./tr-TR.module.js";
32
- import $0f9b1074d04f4954$exports from "./uk-UA.module.js";
33
- import $a9cedf75b94e4916$exports from "./zh-CN.module.js";
34
- import $37cff576474bc8d4$exports from "./zh-TW.module.js";
35
- import {clamp as $cBgAy$clamp, toFixedNumber as $cBgAy$toFixedNumber, useControlledState as $cBgAy$useControlledState, snapValueToStep as $cBgAy$snapValueToStep} from "@react-stately/utils";
36
- import {LocalizedStringDictionary as $cBgAy$LocalizedStringDictionary, LocalizedStringFormatter as $cBgAy$LocalizedStringFormatter} from "@internationalized/string";
37
- import {NumberFormatter as $cBgAy$NumberFormatter} from "@internationalized/number";
38
- import {useRef as $cBgAy$useRef, useMemo as $cBgAy$useMemo, useState as $cBgAy$useState} from "react";
39
- import {useSliderState as $cBgAy$useSliderState} from "@react-stately/slider";
40
- import {useFormValidationState as $cBgAy$useFormValidationState} from "@react-stately/form";
41
-
42
-
43
- function $parcel$interopDefault(a) {
44
- return a && a.__esModule ? a.default : a;
45
- }
46
- /*
47
- * Copyright 2020 Adobe. All rights reserved.
48
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
49
- * you may not use this file except in compliance with the License. You may obtain a copy
50
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
51
- *
52
- * Unless required by applicable law or agreed to in writing, software distributed under
53
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
54
- * OF ANY KIND, either express or implied. See the License for the specific language
55
- * governing permissions and limitations under the License.
56
- */ /*
57
- * Copyright 2020 Adobe. All rights reserved.
58
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
59
- * you may not use this file except in compliance with the License. You may obtain a copy
60
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
61
- *
62
- * Unless required by applicable law or agreed to in writing, software distributed under
63
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
64
- * OF ANY KIND, either express or implied. See the License for the specific language
65
- * governing permissions and limitations under the License.
66
- */
67
- var $f98dad178a72c00d$exports = {};
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
- $f98dad178a72c00d$exports = {
103
- "ar-AE": $2d805fd52bb48883$exports,
104
- "bg-BG": $6c28468dc1df643c$exports,
105
- "cs-CZ": $807554f8230db0ed$exports,
106
- "da-DK": $7097f64386f1761c$exports,
107
- "de-DE": $bdd847d8beb08799$exports,
108
- "el-GR": $a53e00b683950971$exports,
109
- "en-US": $21cdd87e84f28d89$exports,
110
- "es-ES": $92fee9698e4d675a$exports,
111
- "et-EE": $7ea012e91a5ad3ee$exports,
112
- "fi-FI": $8460c13bb2d75345$exports,
113
- "fr-FR": $2a2d5dc14e680587$exports,
114
- "he-IL": $9a3f292371bb0589$exports,
115
- "hr-HR": $4742231a685fa068$exports,
116
- "hu-HU": $05e247fd2960981e$exports,
117
- "it-IT": $a67524a79ccbe190$exports,
118
- "ja-JP": $a9eefe9d6c8cb7d5$exports,
119
- "ko-KR": $4a6b836d4f1bfaba$exports,
120
- "lt-LT": $c950e4b1c482abde$exports,
121
- "lv-LV": $d10d6b60dc50b438$exports,
122
- "nb-NO": $371a732b2494f452$exports,
123
- "nl-NL": $6d042cae6243464b$exports,
124
- "pl-PL": $d9ab5c2611e0bcd3$exports,
125
- "pt-BR": $73f77c9902e29ca6$exports,
126
- "pt-PT": $4f461eb266a95c10$exports,
127
- "ro-RO": $dc46bea2f2597899$exports,
128
- "ru-RU": $622bbd6719cc95af$exports,
129
- "sk-SK": $4da03c1ecd9a9c7d$exports,
130
- "sl-SI": $edb6b2fe456ed4e8$exports,
131
- "sr-SP": $264cd81c52b30815$exports,
132
- "sv-SE": $6f80afde0270dda7$exports,
133
- "tr-TR": $23a92651c6957668$exports,
134
- "uk-UA": $0f9b1074d04f4954$exports,
135
- "zh-CN": $a9cedf75b94e4916$exports,
136
- "zh-TW": $37cff576474bc8d4$exports
137
- };
138
-
139
-
140
-
141
-
142
- let $799cddbef784668f$var$dictionary = new (0, $cBgAy$LocalizedStringDictionary)((0, (/*@__PURE__*/$parcel$interopDefault($f98dad178a72c00d$exports))));
143
- function $799cddbef784668f$export$6e865ea70d7724f(value) {
144
- let res = $799cddbef784668f$var$RGBColor.parse(value) || $799cddbef784668f$var$HSBColor.parse(value) || $799cddbef784668f$var$HSLColor.parse(value);
145
- if (res) return res;
146
- throw new Error("Invalid color value: " + value);
147
- }
148
- function $799cddbef784668f$export$4cde5df63f53f473(v) {
149
- if (typeof v === "string") return $799cddbef784668f$export$6e865ea70d7724f(v);
150
- else return v;
151
- }
152
- // Lightness threshold between orange and brown.
153
- const $799cddbef784668f$var$ORANGE_LIGHTNESS_THRESHOLD = 0.68;
154
- // Lightness threshold between pure yellow and "yellow green".
155
- const $799cddbef784668f$var$YELLOW_GREEN_LIGHTNESS_THRESHOLD = 0.85;
156
- // The maximum lightness considered to be "dark".
157
- const $799cddbef784668f$var$MAX_DARK_LIGHTNESS = 0.55;
158
- // The chroma threshold between gray and color.
159
- const $799cddbef784668f$var$GRAY_THRESHOLD = 0.001;
160
- const $799cddbef784668f$var$OKLCH_HUES = [
161
- [
162
- 0,
163
- "pink"
164
- ],
165
- [
166
- 15,
167
- "red"
168
- ],
169
- [
170
- 48,
171
- "orange"
172
- ],
173
- [
174
- 94,
175
- "yellow"
176
- ],
177
- [
178
- 135,
179
- "green"
180
- ],
181
- [
182
- 175,
183
- "cyan"
184
- ],
185
- [
186
- 264,
187
- "blue"
188
- ],
189
- [
190
- 284,
191
- "purple"
192
- ],
193
- [
194
- 320,
195
- "magenta"
196
- ],
197
- [
198
- 349,
199
- "pink"
200
- ]
201
- ];
202
- class $799cddbef784668f$var$Color {
203
- toHexInt() {
204
- return this.toFormat("rgb").toHexInt();
205
- }
206
- getChannelValue(channel) {
207
- if (channel in this) return this[channel];
208
- throw new Error("Unsupported color channel: " + channel);
209
- }
210
- withChannelValue(channel, value) {
211
- if (channel in this) {
212
- let x = this.clone();
213
- x[channel] = value;
214
- return x;
215
- }
216
- throw new Error("Unsupported color channel: " + channel);
217
- }
218
- getChannelName(channel, locale) {
219
- let strings = (0, $cBgAy$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $799cddbef784668f$var$dictionary;
220
- return strings.getStringForLocale(channel, locale);
221
- }
222
- getColorSpaceAxes(xyChannels) {
223
- let { xChannel: xChannel, yChannel: yChannel } = xyChannels;
224
- let xCh = xChannel || this.getColorChannels().find((c)=>c !== yChannel);
225
- let yCh = yChannel || this.getColorChannels().find((c)=>c !== xCh);
226
- let zCh = this.getColorChannels().find((c)=>c !== xCh && c !== yCh);
227
- return {
228
- xChannel: xCh,
229
- yChannel: yCh,
230
- zChannel: zCh
231
- };
232
- }
233
- getColorName(locale) {
234
- // Convert to oklch color space, which has perceptually uniform lightness across all hues.
235
- let [l, c, h] = $799cddbef784668f$var$toOKLCH(this);
236
- let strings = (0, $cBgAy$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $799cddbef784668f$var$dictionary;
237
- if (l > 0.999) return strings.getStringForLocale("white", locale);
238
- if (l < 0.001) return strings.getStringForLocale("black", locale);
239
- let hue;
240
- [hue, l] = this.getOklchHue(l, c, h, locale);
241
- let lightness = "";
242
- let chroma = "";
243
- if (c <= 0.1 && c >= $799cddbef784668f$var$GRAY_THRESHOLD) {
244
- if (l >= 0.7) chroma = "pale";
245
- else chroma = "grayish";
246
- } else if (c >= 0.15) chroma = "vibrant";
247
- if (l < 0.3) lightness = "very dark";
248
- else if (l < $799cddbef784668f$var$MAX_DARK_LIGHTNESS) lightness = "dark";
249
- else if (l < 0.7) ;
250
- else if (l < 0.85) lightness = "light";
251
- else lightness = "very light";
252
- if (chroma) chroma = strings.getStringForLocale(chroma, locale);
253
- if (lightness) lightness = strings.getStringForLocale(lightness, locale);
254
- let alpha = this.getChannelValue("alpha");
255
- let formatter = new (0, $cBgAy$LocalizedStringFormatter)(locale, strings);
256
- let transparency = "";
257
- if (alpha < 1) {
258
- let percent = new (0, $cBgAy$NumberFormatter)(locale, {
259
- style: "percent"
260
- }).format(1 - alpha);
261
- transparency = formatter.format("transparency", {
262
- percent: percent
263
- });
264
- }
265
- return formatter.format("colorName", {
266
- lightness: lightness,
267
- chroma: chroma,
268
- hue: hue,
269
- transparency: transparency
270
- }).replace(/\s+/g, " ").trim();
271
- }
272
- getOklchHue(l, c, h, locale) {
273
- let strings = (0, $cBgAy$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/color") || $799cddbef784668f$var$dictionary;
274
- if (c < $799cddbef784668f$var$GRAY_THRESHOLD) return [
275
- strings.getStringForLocale("gray", locale),
276
- l
277
- ];
278
- for(let i = 0; i < $799cddbef784668f$var$OKLCH_HUES.length; i++){
279
- let [hue, hueName] = $799cddbef784668f$var$OKLCH_HUES[i];
280
- let [nextHue, nextHueName] = $799cddbef784668f$var$OKLCH_HUES[i + 1] || [
281
- 360,
282
- "pink"
283
- ];
284
- if (h >= hue && h < nextHue) {
285
- // Split orange hue into brown/orange depending on lightness.
286
- if (hueName === "orange") {
287
- if (l < $799cddbef784668f$var$ORANGE_LIGHTNESS_THRESHOLD) hueName = "brown";
288
- else // Adjust lightness.
289
- l = l - $799cddbef784668f$var$ORANGE_LIGHTNESS_THRESHOLD + $799cddbef784668f$var$MAX_DARK_LIGHTNESS;
290
- }
291
- // If the hue is at least halfway to the next hue, add the next hue name as well.
292
- if (h > hue + (nextHue - hue) / 2 && hueName !== nextHueName) hueName = `${hueName} ${nextHueName}`;
293
- else if (hueName === "yellow" && l < $799cddbef784668f$var$YELLOW_GREEN_LIGHTNESS_THRESHOLD) // Yellow shifts toward green at lower lightnesses.
294
- hueName = "yellow green";
295
- let name = strings.getStringForLocale(hueName, locale).toLocaleLowerCase(locale);
296
- return [
297
- name,
298
- l
299
- ];
300
- }
301
- }
302
- throw new Error("Unexpected hue");
303
- }
304
- getHueName(locale) {
305
- let [l, c, h] = $799cddbef784668f$var$toOKLCH(this);
306
- let [name] = this.getOklchHue(l, c, h, locale);
307
- return name;
308
- }
309
- }
310
- class $799cddbef784668f$var$RGBColor extends $799cddbef784668f$var$Color {
311
- static parse(value) {
312
- let colors = [];
313
- // matching #rgb, #rgba, #rrggbb, #rrggbbaa
314
- if (/^#[\da-f]+$/i.test(value) && [
315
- 4,
316
- 5,
317
- 7,
318
- 9
319
- ].includes(value.length)) {
320
- const values = (value.length < 6 ? value.replace(/[^#]/gi, "$&$&") : value).slice(1).split("");
321
- while(values.length > 0)colors.push(parseInt(values.splice(0, 2).join(""), 16));
322
- colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;
323
- }
324
- // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)
325
- const match = value.match(/^rgba?\((.*)\)$/);
326
- if (match === null || match === void 0 ? void 0 : match[1]) {
327
- colors = match[1].split(",").map((value)=>Number(value.trim()));
328
- colors = colors.map((num, i)=>(0, $cBgAy$clamp)(num, 0, i < 3 ? 255 : 1));
329
- }
330
- var _colors_;
331
- return colors.length < 3 ? undefined : new $799cddbef784668f$var$RGBColor(colors[0], colors[1], colors[2], (_colors_ = colors[3]) !== null && _colors_ !== void 0 ? _colors_ : 1);
332
- }
333
- toString(format) {
334
- switch(format){
335
- case "hex":
336
- return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
337
- case "hexa":
338
- 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();
339
- case "rgb":
340
- return `rgb(${this.red}, ${this.green}, ${this.blue})`;
341
- case "css":
342
- case "rgba":
343
- return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
344
- default:
345
- return this.toFormat(format).toString(format);
346
- }
347
- }
348
- toFormat(format) {
349
- switch(format){
350
- case "hex":
351
- case "hexa":
352
- case "rgb":
353
- case "rgba":
354
- return this;
355
- case "hsb":
356
- case "hsba":
357
- return this.toHSB();
358
- case "hsl":
359
- case "hsla":
360
- return this.toHSL();
361
- default:
362
- throw new Error("Unsupported color conversion: rgb -> " + format);
363
- }
364
- }
365
- toHexInt() {
366
- return this.red << 16 | this.green << 8 | this.blue;
367
- }
368
- /**
369
- * Converts an RGB color value to HSB.
370
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
371
- * @returns An HSBColor object.
372
- */ toHSB() {
373
- const red = this.red / 255;
374
- const green = this.green / 255;
375
- const blue = this.blue / 255;
376
- const min = Math.min(red, green, blue);
377
- const brightness = Math.max(red, green, blue);
378
- const chroma = brightness - min;
379
- const saturation = brightness === 0 ? 0 : chroma / brightness;
380
- let hue = 0; // achromatic
381
- if (chroma !== 0) {
382
- switch(brightness){
383
- case red:
384
- hue = (green - blue) / chroma + (green < blue ? 6 : 0);
385
- break;
386
- case green:
387
- hue = (blue - red) / chroma + 2;
388
- break;
389
- case blue:
390
- hue = (red - green) / chroma + 4;
391
- break;
392
- }
393
- hue /= 6;
394
- }
395
- return new $799cddbef784668f$var$HSBColor((0, $cBgAy$toFixedNumber)(hue * 360, 2), (0, $cBgAy$toFixedNumber)(saturation * 100, 2), (0, $cBgAy$toFixedNumber)(brightness * 100, 2), this.alpha);
396
- }
397
- /**
398
- * Converts an RGB color value to HSL.
399
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
400
- * @returns An HSLColor object.
401
- */ toHSL() {
402
- const red = this.red / 255;
403
- const green = this.green / 255;
404
- const blue = this.blue / 255;
405
- const min = Math.min(red, green, blue);
406
- const max = Math.max(red, green, blue);
407
- const lightness = (max + min) / 2;
408
- const chroma = max - min;
409
- let hue;
410
- let saturation;
411
- if (chroma === 0) hue = saturation = 0; // achromatic
412
- else {
413
- saturation = chroma / (lightness < .5 ? max + min : 2 - max - min);
414
- switch(max){
415
- case red:
416
- hue = (green - blue) / chroma + (green < blue ? 6 : 0);
417
- break;
418
- case green:
419
- hue = (blue - red) / chroma + 2;
420
- break;
421
- case blue:
422
- hue = (red - green) / chroma + 4;
423
- break;
424
- }
425
- hue /= 6;
426
- }
427
- return new $799cddbef784668f$var$HSLColor((0, $cBgAy$toFixedNumber)(hue * 360, 2), (0, $cBgAy$toFixedNumber)(saturation * 100, 2), (0, $cBgAy$toFixedNumber)(lightness * 100, 2), this.alpha);
428
- }
429
- clone() {
430
- return new $799cddbef784668f$var$RGBColor(this.red, this.green, this.blue, this.alpha);
431
- }
432
- getChannelRange(channel) {
433
- switch(channel){
434
- case "red":
435
- case "green":
436
- case "blue":
437
- return {
438
- minValue: 0x0,
439
- maxValue: 0xFF,
440
- step: 0x1,
441
- pageSize: 0x11
442
- };
443
- case "alpha":
444
- return {
445
- minValue: 0,
446
- maxValue: 1,
447
- step: 0.01,
448
- pageSize: 0.1
449
- };
450
- default:
451
- throw new Error("Unknown color channel: " + channel);
452
- }
453
- }
454
- formatChannelValue(channel, locale) {
455
- let options;
456
- let value = this.getChannelValue(channel);
457
- switch(channel){
458
- case "red":
459
- case "green":
460
- case "blue":
461
- options = {
462
- style: "decimal"
463
- };
464
- break;
465
- case "alpha":
466
- options = {
467
- style: "percent"
468
- };
469
- break;
470
- default:
471
- throw new Error("Unknown color channel: " + channel);
472
- }
473
- return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
474
- }
475
- getColorSpace() {
476
- return "rgb";
477
- }
478
- getColorChannels() {
479
- return $799cddbef784668f$var$RGBColor.colorChannels;
480
- }
481
- constructor(red, green, blue, alpha){
482
- super();
483
- this.red = red;
484
- this.green = green;
485
- this.blue = blue;
486
- this.alpha = alpha;
487
- }
488
- }
489
- $799cddbef784668f$var$RGBColor.colorChannels = [
490
- "red",
491
- "green",
492
- "blue"
493
- ];
494
- // X = <negative/positive number with/without decimal places>
495
- // before/after a comma, 0 or more whitespaces are allowed
496
- // - hsb(X, X%, X%)
497
- // - hsba(X, X%, X%, X)
498
- const $799cddbef784668f$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+)?)\)/;
499
- class $799cddbef784668f$var$HSBColor extends $799cddbef784668f$var$Color {
500
- static parse(value) {
501
- let m;
502
- if (m = value.match($799cddbef784668f$var$HSB_REGEX)) {
503
- var _m_;
504
- const [h, s, b, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
505
- return new $799cddbef784668f$var$HSBColor($799cddbef784668f$var$mod(h, 360), (0, $cBgAy$clamp)(s, 0, 100), (0, $cBgAy$clamp)(b, 0, 100), (0, $cBgAy$clamp)(a !== null && a !== void 0 ? a : 1, 0, 1));
506
- }
507
- }
508
- toString(format) {
509
- switch(format){
510
- case "css":
511
- return this.toHSL().toString("css");
512
- case "hex":
513
- return this.toRGB().toString("hex");
514
- case "hexa":
515
- return this.toRGB().toString("hexa");
516
- case "hsb":
517
- return `hsb(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.brightness, 2)}%)`;
518
- case "hsba":
519
- return `hsba(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
520
- default:
521
- return this.toFormat(format).toString(format);
522
- }
523
- }
524
- toFormat(format) {
525
- switch(format){
526
- case "hsb":
527
- case "hsba":
528
- return this;
529
- case "hsl":
530
- case "hsla":
531
- return this.toHSL();
532
- case "rgb":
533
- case "rgba":
534
- return this.toRGB();
535
- default:
536
- throw new Error("Unsupported color conversion: hsb -> " + format);
537
- }
538
- }
539
- /**
540
- * Converts a HSB color to HSL.
541
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
542
- * @returns An HSLColor object.
543
- */ toHSL() {
544
- let saturation = this.saturation / 100;
545
- let brightness = this.brightness / 100;
546
- let lightness = brightness * (1 - saturation / 2);
547
- saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
548
- return new $799cddbef784668f$var$HSLColor((0, $cBgAy$toFixedNumber)(this.hue, 2), (0, $cBgAy$toFixedNumber)(saturation * 100, 2), (0, $cBgAy$toFixedNumber)(lightness * 100, 2), this.alpha);
549
- }
550
- /**
551
- * Converts a HSV color value to RGB.
552
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
553
- * @returns An RGBColor object.
554
- */ toRGB() {
555
- let hue = this.hue;
556
- let saturation = this.saturation / 100;
557
- let brightness = this.brightness / 100;
558
- let fn = (n, k = (n + hue / 60) % 6)=>brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
559
- return new $799cddbef784668f$var$RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha);
560
- }
561
- clone() {
562
- return new $799cddbef784668f$var$HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
563
- }
564
- getChannelRange(channel) {
565
- switch(channel){
566
- case "hue":
567
- return {
568
- minValue: 0,
569
- maxValue: 360,
570
- step: 1,
571
- pageSize: 15
572
- };
573
- case "saturation":
574
- case "brightness":
575
- return {
576
- minValue: 0,
577
- maxValue: 100,
578
- step: 1,
579
- pageSize: 10
580
- };
581
- case "alpha":
582
- return {
583
- minValue: 0,
584
- maxValue: 1,
585
- step: 0.01,
586
- pageSize: 0.1
587
- };
588
- default:
589
- throw new Error("Unknown color channel: " + channel);
590
- }
591
- }
592
- formatChannelValue(channel, locale) {
593
- let options;
594
- let value = this.getChannelValue(channel);
595
- switch(channel){
596
- case "hue":
597
- options = {
598
- style: "unit",
599
- unit: "degree",
600
- unitDisplay: "narrow"
601
- };
602
- break;
603
- case "saturation":
604
- case "brightness":
605
- options = {
606
- style: "percent"
607
- };
608
- value /= 100;
609
- break;
610
- case "alpha":
611
- options = {
612
- style: "percent"
613
- };
614
- break;
615
- default:
616
- throw new Error("Unknown color channel: " + channel);
617
- }
618
- return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
619
- }
620
- getColorSpace() {
621
- return "hsb";
622
- }
623
- getColorChannels() {
624
- return $799cddbef784668f$var$HSBColor.colorChannels;
625
- }
626
- constructor(hue, saturation, brightness, alpha){
627
- super();
628
- this.hue = hue;
629
- this.saturation = saturation;
630
- this.brightness = brightness;
631
- this.alpha = alpha;
632
- }
633
- }
634
- $799cddbef784668f$var$HSBColor.colorChannels = [
635
- "hue",
636
- "saturation",
637
- "brightness"
638
- ];
639
- // X = <negative/positive number with/without decimal places>
640
- // before/after a comma, 0 or more whitespaces are allowed
641
- // - hsl(X, X%, X%)
642
- // - hsla(X, X%, X%, X)
643
- const $799cddbef784668f$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+)?)\)/;
644
- function $799cddbef784668f$var$mod(n, m) {
645
- return (n % m + m) % m;
646
- }
647
- class $799cddbef784668f$var$HSLColor extends $799cddbef784668f$var$Color {
648
- static parse(value) {
649
- let m;
650
- if (m = value.match($799cddbef784668f$var$HSL_REGEX)) {
651
- var _m_;
652
- const [h, s, l, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
653
- return new $799cddbef784668f$var$HSLColor($799cddbef784668f$var$mod(h, 360), (0, $cBgAy$clamp)(s, 0, 100), (0, $cBgAy$clamp)(l, 0, 100), (0, $cBgAy$clamp)(a !== null && a !== void 0 ? a : 1, 0, 1));
654
- }
655
- }
656
- toString(format) {
657
- switch(format){
658
- case "hex":
659
- return this.toRGB().toString("hex");
660
- case "hexa":
661
- return this.toRGB().toString("hexa");
662
- case "hsl":
663
- return `hsl(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.lightness, 2)}%)`;
664
- case "css":
665
- case "hsla":
666
- return `hsla(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.lightness, 2)}%, ${this.alpha})`;
667
- default:
668
- return this.toFormat(format).toString(format);
669
- }
670
- }
671
- toFormat(format) {
672
- switch(format){
673
- case "hsl":
674
- case "hsla":
675
- return this;
676
- case "hsb":
677
- case "hsba":
678
- return this.toHSB();
679
- case "rgb":
680
- case "rgba":
681
- return this.toRGB();
682
- default:
683
- throw new Error("Unsupported color conversion: hsl -> " + format);
684
- }
685
- }
686
- /**
687
- * Converts a HSL color to HSB.
688
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
689
- * @returns An HSBColor object.
690
- */ toHSB() {
691
- let saturation = this.saturation / 100;
692
- let lightness = this.lightness / 100;
693
- let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
694
- saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
695
- return new $799cddbef784668f$var$HSBColor((0, $cBgAy$toFixedNumber)(this.hue, 2), (0, $cBgAy$toFixedNumber)(saturation * 100, 2), (0, $cBgAy$toFixedNumber)(brightness * 100, 2), this.alpha);
696
- }
697
- /**
698
- * Converts a HSL color to RGB.
699
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
700
- * @returns An RGBColor object.
701
- */ toRGB() {
702
- let hue = this.hue;
703
- let saturation = this.saturation / 100;
704
- let lightness = this.lightness / 100;
705
- let a = saturation * Math.min(lightness, 1 - lightness);
706
- let fn = (n, k = (n + hue / 30) % 12)=>lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
707
- return new $799cddbef784668f$var$RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha);
708
- }
709
- clone() {
710
- return new $799cddbef784668f$var$HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
711
- }
712
- getChannelRange(channel) {
713
- switch(channel){
714
- case "hue":
715
- return {
716
- minValue: 0,
717
- maxValue: 360,
718
- step: 1,
719
- pageSize: 15
720
- };
721
- case "saturation":
722
- case "lightness":
723
- return {
724
- minValue: 0,
725
- maxValue: 100,
726
- step: 1,
727
- pageSize: 10
728
- };
729
- case "alpha":
730
- return {
731
- minValue: 0,
732
- maxValue: 1,
733
- step: 0.01,
734
- pageSize: 0.1
735
- };
736
- default:
737
- throw new Error("Unknown color channel: " + channel);
738
- }
739
- }
740
- formatChannelValue(channel, locale) {
741
- let options;
742
- let value = this.getChannelValue(channel);
743
- switch(channel){
744
- case "hue":
745
- options = {
746
- style: "unit",
747
- unit: "degree",
748
- unitDisplay: "narrow"
749
- };
750
- break;
751
- case "saturation":
752
- case "lightness":
753
- options = {
754
- style: "percent"
755
- };
756
- value /= 100;
757
- break;
758
- case "alpha":
759
- options = {
760
- style: "percent"
761
- };
762
- break;
763
- default:
764
- throw new Error("Unknown color channel: " + channel);
765
- }
766
- return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
767
- }
768
- getColorSpace() {
769
- return "hsl";
770
- }
771
- getColorChannels() {
772
- return $799cddbef784668f$var$HSLColor.colorChannels;
773
- }
774
- constructor(hue, saturation, lightness, alpha){
775
- super();
776
- this.hue = hue;
777
- this.saturation = saturation;
778
- this.lightness = lightness;
779
- this.alpha = alpha;
780
- }
781
- }
782
- $799cddbef784668f$var$HSLColor.colorChannels = [
783
- "hue",
784
- "saturation",
785
- "lightness"
786
- ];
787
- // https://www.w3.org/TR/css-color-4/#color-conversion-code
788
- function $799cddbef784668f$var$toOKLCH(color) {
789
- let rgb = color.toFormat("rgb");
790
- let red = rgb.getChannelValue("red") / 255;
791
- let green = rgb.getChannelValue("green") / 255;
792
- let blue = rgb.getChannelValue("blue") / 255;
793
- [red, green, blue] = $799cddbef784668f$var$lin_sRGB(red, green, blue);
794
- let [x, y, z] = $799cddbef784668f$var$lin_sRGB_to_XYZ(red, green, blue);
795
- let [l, a, b] = $799cddbef784668f$var$XYZ_to_OKLab(x, y, z);
796
- return $799cddbef784668f$var$OKLab_to_OKLCH(l, a, b);
797
- }
798
- function $799cddbef784668f$var$OKLab_to_OKLCH(l, a, b) {
799
- var hue = Math.atan2(b, a) * 180 / Math.PI;
800
- return [
801
- l,
802
- Math.sqrt(a ** 2 + b ** 2),
803
- hue >= 0 ? hue : hue + 360 // Hue, in degrees [0 to 360)
804
- ];
805
- }
806
- function $799cddbef784668f$var$lin_sRGB(r, g, b) {
807
- // convert an array of sRGB values
808
- // where in-gamut values are in the range [0 - 1]
809
- // to linear light (un-companded) form.
810
- // https://en.wikipedia.org/wiki/SRGB
811
- // Extended transfer function:
812
- // for negative values, linear portion is extended on reflection of axis,
813
- // then reflected power function is used.
814
- return [
815
- $799cddbef784668f$var$lin_sRGB_component(r),
816
- $799cddbef784668f$var$lin_sRGB_component(g),
817
- $799cddbef784668f$var$lin_sRGB_component(b)
818
- ];
819
- }
820
- function $799cddbef784668f$var$lin_sRGB_component(val) {
821
- let sign = val < 0 ? -1 : 1;
822
- let abs = Math.abs(val);
823
- if (abs <= 0.04045) return val / 12.92;
824
- return sign * Math.pow((abs + 0.055) / 1.055, 2.4);
825
- }
826
- function $799cddbef784668f$var$lin_sRGB_to_XYZ(r, g, b) {
827
- // convert an array of linear-light sRGB values to CIE XYZ
828
- // using sRGB's own white, D65 (no chromatic adaptation)
829
- const M = [
830
- 506752 / 1228815,
831
- 87881 / 245763,
832
- 12673 / 70218,
833
- 87098 / 409605,
834
- 175762 / 245763,
835
- 12673 / 175545,
836
- 7918 / 409605,
837
- 87881 / 737289,
838
- 1001167 / 1053270
839
- ];
840
- return $799cddbef784668f$var$multiplyMatrix(M, r, g, b);
841
- }
842
- function $799cddbef784668f$var$XYZ_to_OKLab(x, y, z) {
843
- // Given XYZ relative to D65, convert to OKLab
844
- const XYZtoLMS = [
845
- 0.8190224379967030,
846
- 0.3619062600528904,
847
- -0.1288737815209879,
848
- 0.0329836539323885,
849
- 0.9292868615863434,
850
- 0.0361446663506424,
851
- 0.0481771893596242,
852
- 0.2642395317527308,
853
- 0.6335478284694309
854
- ];
855
- const LMStoOKLab = [
856
- 0.2104542683093140,
857
- 0.7936177747023054,
858
- -0.0040720430116193,
859
- 1.9779985324311684,
860
- -2.42859224204858,
861
- 0.4505937096174110,
862
- 0.0259040424655478,
863
- 0.7827717124575296,
864
- -0.8086757549230774
865
- ];
866
- let [a, b, c] = $799cddbef784668f$var$multiplyMatrix(XYZtoLMS, x, y, z);
867
- return $799cddbef784668f$var$multiplyMatrix(LMStoOKLab, Math.cbrt(a), Math.cbrt(b), Math.cbrt(c));
868
- }
869
- function $799cddbef784668f$var$multiplyMatrix(m, x, y, z) {
870
- let a = m[0] * x + m[1] * y + m[2] * z;
871
- let b = m[3] * x + m[4] * y + m[5] * z;
872
- let c = m[6] * x + m[7] * y + m[8] * z;
873
- return [
874
- a,
875
- b,
876
- c
877
- ];
878
- }
879
-
1
+ import {parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.module.js";
2
+ import {useColorAreaState as $6e14a98a7f67141d$export$6df7f0e2cabc7eef} from "./useColorAreaState.module.js";
3
+ import {useColorSliderState as $25a25ac0d1624665$export$57bc203e1c9c6d44} from "./useColorSliderState.module.js";
4
+ import {useColorWheelState as $ee4262c74a467b07$export$f4301076d9336137} from "./useColorWheelState.module.js";
5
+ import {useColorFieldState as $b335ada08155d9c0$export$d52a01683abdfcd6} from "./useColorFieldState.module.js";
880
6
 
881
7
  /*
882
8
  * Copyright 2020 Adobe. All rights reserved.
@@ -891,430 +17,6 @@ function $799cddbef784668f$var$multiplyMatrix(m, x, y, z) {
891
17
  */
892
18
 
893
19
 
894
- const $6e14a98a7f67141d$var$DEFAULT_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#ffffff");
895
- function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
896
- let { value: value, defaultValue: defaultValue, xChannel: xChannel, yChannel: yChannel, onChange: onChange, onChangeEnd: onChangeEnd } = props;
897
- if (!value && !defaultValue) defaultValue = $6e14a98a7f67141d$var$DEFAULT_COLOR;
898
- let [color, setColorState] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
899
- let valueRef = (0, $cBgAy$useRef)(color);
900
- let setColor = (color)=>{
901
- valueRef.current = color;
902
- setColorState(color);
903
- };
904
- let channels = (0, $cBgAy$useMemo)(()=>color.getColorSpaceAxes({
905
- xChannel: xChannel,
906
- yChannel: yChannel
907
- }), [
908
- color,
909
- xChannel,
910
- yChannel
911
- ]);
912
- let xChannelRange = color.getChannelRange(channels.xChannel);
913
- let yChannelRange = color.getChannelRange(channels.yChannel);
914
- let { minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX } = xChannelRange;
915
- let { minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY } = yChannelRange;
916
- let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
917
- let isDraggingRef = (0, $cBgAy$useRef)(false);
918
- let xValue = color.getChannelValue(channels.xChannel);
919
- let yValue = color.getChannelValue(channels.yChannel);
920
- let setXValue = (v)=>{
921
- if (v === xValue) return;
922
- let newColor = color.withChannelValue(channels.xChannel, v);
923
- setColor(newColor);
924
- };
925
- let setYValue = (v)=>{
926
- if (v === yValue) return;
927
- let newColor = color.withChannelValue(channels.yChannel, v);
928
- setColor(newColor);
929
- };
930
- return {
931
- channels: channels,
932
- xChannelStep: stepX,
933
- yChannelStep: stepY,
934
- xChannelPageStep: pageSizeX,
935
- yChannelPageStep: pageSizeY,
936
- value: color,
937
- setValue (value) {
938
- setColor((0, $799cddbef784668f$export$4cde5df63f53f473)(value));
939
- },
940
- xValue: xValue,
941
- setXValue: setXValue,
942
- yValue: yValue,
943
- setYValue: setYValue,
944
- setColorFromPoint (x, y) {
945
- let newXValue = minValueX + (0, $cBgAy$clamp)(x, 0, 1) * (maxValueX - minValueX);
946
- let newYValue = minValueY + (1 - (0, $cBgAy$clamp)(y, 0, 1)) * (maxValueY - minValueY);
947
- let newColor;
948
- if (newXValue !== xValue) {
949
- // Round new value to multiple of step, clamp value between min and max
950
- newXValue = (0, $cBgAy$snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
951
- newColor = color.withChannelValue(channels.xChannel, newXValue);
952
- }
953
- if (newYValue !== yValue) {
954
- // Round new value to multiple of step, clamp value between min and max
955
- newYValue = (0, $cBgAy$snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
956
- newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
957
- }
958
- if (newColor) setColor(newColor);
959
- },
960
- getThumbPosition () {
961
- let x = (xValue - minValueX) / (maxValueX - minValueX);
962
- let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
963
- return {
964
- x: x,
965
- y: y
966
- };
967
- },
968
- incrementX (stepSize) {
969
- setXValue(xValue + stepSize > maxValueX ? maxValueX : (0, $cBgAy$snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX));
970
- },
971
- incrementY (stepSize) {
972
- setYValue(yValue + stepSize > maxValueY ? maxValueY : (0, $cBgAy$snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY));
973
- },
974
- decrementX (stepSize) {
975
- setXValue((0, $cBgAy$snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX));
976
- },
977
- decrementY (stepSize) {
978
- setYValue((0, $cBgAy$snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY));
979
- },
980
- setDragging (isDragging) {
981
- let wasDragging = isDraggingRef.current;
982
- isDraggingRef.current = isDragging;
983
- if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
984
- setDragging(isDragging);
985
- },
986
- isDragging: isDragging,
987
- getDisplayColor () {
988
- return color.withChannelValue("alpha", 1);
989
- }
990
- };
991
- }
992
-
993
-
994
- /*
995
- * Copyright 2020 Adobe. All rights reserved.
996
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
997
- * you may not use this file except in compliance with the License. You may obtain a copy
998
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
999
- *
1000
- * Unless required by applicable law or agreed to in writing, software distributed under
1001
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1002
- * OF ANY KIND, either express or implied. See the License for the specific language
1003
- * governing permissions and limitations under the License.
1004
- */
1005
-
1006
-
1007
- function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
1008
- let { channel: channel, value: value, defaultValue: defaultValue, onChange: onChange, locale: locale, ...otherProps } = props;
1009
- if (value == null && defaultValue == null) throw new Error("useColorSliderState requires a value or defaultValue");
1010
- let [color, setColor] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1011
- let sliderState = (0, $cBgAy$useSliderState)({
1012
- ...color.getChannelRange(channel),
1013
- ...otherProps,
1014
- // Unused except in getThumbValueLabel, which is overridden below. null to appease TypeScript.
1015
- numberFormatter: null,
1016
- value: color.getChannelValue(channel),
1017
- onChange (v) {
1018
- setColor(color.withChannelValue(channel, v));
1019
- },
1020
- onChangeEnd (v) {
1021
- // onChange will have already been called with the right value, this is just to trigger onChangeEnd
1022
- if (props.onChangeEnd) props.onChangeEnd(color.withChannelValue(channel, v));
1023
- }
1024
- });
1025
- let { step: step, pageSize: pageSize } = color.getChannelRange(channel);
1026
- return {
1027
- ...sliderState,
1028
- value: color,
1029
- setValue (value) {
1030
- setColor((0, $799cddbef784668f$export$4cde5df63f53f473)(value));
1031
- },
1032
- getDisplayColor () {
1033
- switch(channel){
1034
- case "hue":
1035
- return (0, $799cddbef784668f$export$6e865ea70d7724f)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
1036
- case "lightness":
1037
- case "brightness":
1038
- case "saturation":
1039
- case "red":
1040
- case "green":
1041
- case "blue":
1042
- return color.withChannelValue("alpha", 1);
1043
- case "alpha":
1044
- return color;
1045
- default:
1046
- throw new Error("Unknown color channel: " + channel);
1047
- }
1048
- },
1049
- getThumbValueLabel () {
1050
- return color.formatChannelValue(channel, locale);
1051
- },
1052
- step: step,
1053
- pageSize: pageSize
1054
- };
1055
- }
1056
-
1057
-
1058
- /*
1059
- * Copyright 2020 Adobe. All rights reserved.
1060
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1061
- * you may not use this file except in compliance with the License. You may obtain a copy
1062
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1063
- *
1064
- * Unless required by applicable law or agreed to in writing, software distributed under
1065
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1066
- * OF ANY KIND, either express or implied. See the License for the specific language
1067
- * governing permissions and limitations under the License.
1068
- */
1069
-
1070
-
1071
- const $ee4262c74a467b07$var$DEFAULT_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("hsl(0, 100%, 50%)");
1072
- function $ee4262c74a467b07$var$roundToStep(value, step) {
1073
- return Math.round(value / step) * step;
1074
- }
1075
- function $ee4262c74a467b07$var$mod(n, m) {
1076
- return (n % m + m) % m;
1077
- }
1078
- function $ee4262c74a467b07$var$roundDown(v) {
1079
- let r = Math.floor(v);
1080
- if (r === v) return v - 1;
1081
- else return r;
1082
- }
1083
- function $ee4262c74a467b07$var$degToRad(deg) {
1084
- return deg * Math.PI / 180;
1085
- }
1086
- function $ee4262c74a467b07$var$radToDeg(rad) {
1087
- return rad * 180 / Math.PI;
1088
- }
1089
- // 0deg = 3 o'clock. increases clockwise
1090
- function $ee4262c74a467b07$var$angleToCartesian(angle, radius) {
1091
- let rad = $ee4262c74a467b07$var$degToRad(360 - angle + 90);
1092
- let x = Math.sin(rad) * radius;
1093
- let y = Math.cos(rad) * radius;
1094
- return {
1095
- x: x,
1096
- y: y
1097
- };
1098
- }
1099
- function $ee4262c74a467b07$var$cartesianToAngle(x, y, radius) {
1100
- let deg = $ee4262c74a467b07$var$radToDeg(Math.atan2(y / radius, x / radius));
1101
- return (deg + 360) % 360;
1102
- }
1103
- function $ee4262c74a467b07$export$f4301076d9336137(props) {
1104
- let { defaultValue: defaultValue, onChange: onChange, onChangeEnd: onChangeEnd } = props;
1105
- if (!props.value && !defaultValue) defaultValue = $ee4262c74a467b07$var$DEFAULT_COLOR;
1106
- let [value, setValueState] = (0, $cBgAy$useControlledState)((0, $799cddbef784668f$export$4cde5df63f53f473)(props.value), (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1107
- let valueRef = (0, $cBgAy$useRef)(value);
1108
- let setValue = (value)=>{
1109
- valueRef.current = value;
1110
- setValueState(value);
1111
- };
1112
- let channelRange = value.getChannelRange("hue");
1113
- let { minValue: minValueX, maxValue: maxValueX, step: step, pageSize: pageStep } = channelRange;
1114
- let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
1115
- let isDraggingRef = (0, $cBgAy$useRef)(false);
1116
- let hue = value.getChannelValue("hue");
1117
- function setHue(v) {
1118
- if (v > 360) // Make sure you can always get back to 0.
1119
- v = 0;
1120
- v = $ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(v, 360), step);
1121
- if (hue !== v) {
1122
- let color = value.withChannelValue("hue", v);
1123
- setValue(color);
1124
- }
1125
- }
1126
- return {
1127
- value: value,
1128
- step: step,
1129
- pageStep: pageStep,
1130
- setValue (v) {
1131
- let color = (0, $799cddbef784668f$export$4cde5df63f53f473)(v);
1132
- setValue(color);
1133
- },
1134
- hue: hue,
1135
- setHue: setHue,
1136
- setHueFromPoint (x, y, radius) {
1137
- setHue($ee4262c74a467b07$var$cartesianToAngle(x, y, radius));
1138
- },
1139
- getThumbPosition (radius) {
1140
- return $ee4262c74a467b07$var$angleToCartesian(value.getChannelValue("hue"), radius);
1141
- },
1142
- increment (stepSize = 1) {
1143
- let s = Math.max(stepSize, step);
1144
- let newValue = hue + s;
1145
- if (newValue >= maxValueX) // Make sure you can always get back to 0.
1146
- newValue = minValueX;
1147
- setHue($ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(newValue, 360), s));
1148
- },
1149
- decrement (stepSize = 1) {
1150
- let s = Math.max(stepSize, step);
1151
- if (hue === 0) // We can't just subtract step because this might be the case:
1152
- // |(previous step) - 0| < step size
1153
- setHue($ee4262c74a467b07$var$roundDown(360 / s) * s);
1154
- else setHue($ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(hue - s, 360), s));
1155
- },
1156
- setDragging (isDragging) {
1157
- let wasDragging = isDraggingRef.current;
1158
- isDraggingRef.current = isDragging;
1159
- if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1160
- setDragging(isDragging);
1161
- },
1162
- isDragging: isDragging,
1163
- getDisplayColor () {
1164
- return value.toFormat("hsl").withChannelValue("saturation", 100).withChannelValue("lightness", 50).withChannelValue("alpha", 1);
1165
- }
1166
- };
1167
- }
1168
-
1169
-
1170
- /*
1171
- * Copyright 2020 Adobe. All rights reserved.
1172
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1173
- * you may not use this file except in compliance with the License. You may obtain a copy
1174
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1175
- *
1176
- * Unless required by applicable law or agreed to in writing, software distributed under
1177
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1178
- * OF ANY KIND, either express or implied. See the License for the specific language
1179
- * governing permissions and limitations under the License.
1180
- */
1181
-
1182
- /*
1183
- * Copyright 2020 Adobe. All rights reserved.
1184
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1185
- * you may not use this file except in compliance with the License. You may obtain a copy
1186
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1187
- *
1188
- * Unless required by applicable law or agreed to in writing, software distributed under
1189
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1190
- * OF ANY KIND, either express or implied. See the License for the specific language
1191
- * governing permissions and limitations under the License.
1192
- */
1193
-
1194
- function $aa90ad8b2b1d015f$export$5aadd9c0606af5c2(value) {
1195
- return (0, $cBgAy$useMemo)(()=>{
1196
- if (typeof value === "string") try {
1197
- return (0, $799cddbef784668f$export$6e865ea70d7724f)(value);
1198
- } catch (err) {
1199
- return undefined;
1200
- }
1201
- return value;
1202
- }, [
1203
- value
1204
- ]);
1205
- }
1206
-
1207
-
1208
-
1209
-
1210
- const $b335ada08155d9c0$var$MIN_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#000000");
1211
- const $b335ada08155d9c0$var$MAX_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#FFFFFF");
1212
- const $b335ada08155d9c0$var$MIN_COLOR_INT = $b335ada08155d9c0$var$MIN_COLOR.toHexInt();
1213
- const $b335ada08155d9c0$var$MAX_COLOR_INT = $b335ada08155d9c0$var$MAX_COLOR.toHexInt();
1214
- function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1215
- let { value: value, defaultValue: defaultValue, onChange: onChange } = props;
1216
- let { step: step } = $b335ada08155d9c0$var$MIN_COLOR.getChannelRange("red");
1217
- let initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value);
1218
- let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
1219
- let [colorValue, setColorValue] = (0, $cBgAy$useControlledState)(initialValue, initialDefaultValue, onChange);
1220
- let [inputValue, setInputValue] = (0, $cBgAy$useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString("hex") : "");
1221
- let validation = (0, $cBgAy$useFormValidationState)({
1222
- ...props,
1223
- value: colorValue
1224
- });
1225
- let safelySetColorValue = (newColor)=>{
1226
- if (!colorValue || !newColor) {
1227
- setColorValue(newColor);
1228
- return;
1229
- }
1230
- if (newColor.toHexInt() !== colorValue.toHexInt()) {
1231
- setColorValue(newColor);
1232
- return;
1233
- }
1234
- };
1235
- let [prevValue, setPrevValue] = (0, $cBgAy$useState)(colorValue);
1236
- if (prevValue !== colorValue) {
1237
- setInputValue(colorValue ? colorValue.toString("hex") : "");
1238
- setPrevValue(colorValue);
1239
- }
1240
- let parsedValue = (0, $cBgAy$useMemo)(()=>{
1241
- let color;
1242
- try {
1243
- color = (0, $799cddbef784668f$export$6e865ea70d7724f)(inputValue.startsWith("#") ? inputValue : `#${inputValue}`);
1244
- } catch (err) {
1245
- color = null;
1246
- }
1247
- return color;
1248
- }, [
1249
- inputValue
1250
- ]);
1251
- let commit = ()=>{
1252
- // Set to empty state if input value is empty
1253
- if (!inputValue.length) {
1254
- safelySetColorValue(null);
1255
- setInputValue(value === undefined ? "" : colorValue.toString("hex"));
1256
- return;
1257
- }
1258
- // if it failed to parse, then reset input to formatted version of current number
1259
- if (parsedValue == null) {
1260
- setInputValue(colorValue ? colorValue.toString("hex") : "");
1261
- return;
1262
- }
1263
- safelySetColorValue(parsedValue);
1264
- // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
1265
- let newColorValue = "";
1266
- if (colorValue) newColorValue = colorValue.toString("hex");
1267
- setInputValue(newColorValue);
1268
- };
1269
- let increment = ()=>{
1270
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
1271
- // if we've arrived at the same value that was previously in the state, the
1272
- // input value should be updated to match
1273
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
1274
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
1275
- if (newValue === colorValue) setInputValue(newValue.toString("hex"));
1276
- safelySetColorValue(newValue);
1277
- validation.commitValidation();
1278
- };
1279
- let decrement = ()=>{
1280
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
1281
- // if we've arrived at the same value that was previously in the state, the
1282
- // input value should be updated to match
1283
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
1284
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
1285
- if (newValue === colorValue) setInputValue(newValue.toString("hex"));
1286
- safelySetColorValue(newValue);
1287
- validation.commitValidation();
1288
- };
1289
- let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
1290
- let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
1291
- let validate = (value)=>{
1292
- var _value_match;
1293
- return value === "" || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
1294
- };
1295
- return {
1296
- ...validation,
1297
- validate: validate,
1298
- colorValue: colorValue,
1299
- inputValue: inputValue,
1300
- setInputValue: setInputValue,
1301
- commit: commit,
1302
- increment: increment,
1303
- incrementToMax: incrementToMax,
1304
- decrement: decrement,
1305
- decrementToMin: decrementToMin
1306
- };
1307
- }
1308
- function $b335ada08155d9c0$var$addColorValue(color, step) {
1309
- let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
1310
- let colorInt = newColor.toHexInt();
1311
- let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
1312
- if (clampInt !== colorInt) {
1313
- let newColorString = `#${clampInt.toString(16).padStart(6, "0").toUpperCase()}`;
1314
- newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
1315
- }
1316
- return newColor;
1317
- }
1318
20
 
1319
21
 
1320
22