@react-stately/color 3.2.3-nightly.3698 → 3.2.3-nightly.3705

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 (2) hide show
  1. package/dist/import.mjs +1469 -0
  2. package/package.json +14 -9
@@ -0,0 +1,1469 @@
1
+ import $cBgAy$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
2
+ import {clamp as $cBgAy$clamp, toFixedNumber as $cBgAy$toFixedNumber, useControlledState as $cBgAy$useControlledState, snapValueToStep as $cBgAy$snapValueToStep} from "@react-stately/utils";
3
+ import {LocalizedStringDictionary as $cBgAy$LocalizedStringDictionary} from "@internationalized/string";
4
+ import {NumberFormatter as $cBgAy$NumberFormatter} from "@internationalized/number";
5
+ import {useRef as $cBgAy$useRef, useMemo as $cBgAy$useMemo, useState as $cBgAy$useState} from "react";
6
+ import {useSliderState as $cBgAy$useSliderState} from "@react-stately/slider";
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */ /*
22
+ * Copyright 2020 Adobe. All rights reserved.
23
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
24
+ * you may not use this file except in compliance with the License. You may obtain a copy
25
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software distributed under
28
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
29
+ * OF ANY KIND, either express or implied. See the License for the specific language
30
+ * governing permissions and limitations under the License.
31
+ */
32
+
33
+ var $7a451c0c6841e6b9$exports = {};
34
+ var $2d805fd52bb48883$exports = {};
35
+ $2d805fd52bb48883$exports = {
36
+ "alpha": `ألفا`,
37
+ "blue": `أزرق`,
38
+ "brightness": `السطوع`,
39
+ "green": `أخضر`,
40
+ "hue": `درجة اللون`,
41
+ "lightness": `الإضاءة`,
42
+ "red": `أحمر`,
43
+ "saturation": `التشبع`
44
+ };
45
+
46
+
47
+ var $6c28468dc1df643c$exports = {};
48
+ $6c28468dc1df643c$exports = {
49
+ "alpha": `Алфа`,
50
+ "blue": `Синьо`,
51
+ "brightness": `Яркост`,
52
+ "green": `Зелено`,
53
+ "hue": `Оттенък`,
54
+ "lightness": `Лекота`,
55
+ "red": `Червено`,
56
+ "saturation": `Наситеност`
57
+ };
58
+
59
+
60
+ var $807554f8230db0ed$exports = {};
61
+ $807554f8230db0ed$exports = {
62
+ "alpha": `Alfa`,
63
+ "blue": `Modrá`,
64
+ "brightness": `Jas`,
65
+ "green": `Zelená`,
66
+ "hue": `Odstín`,
67
+ "lightness": `Světlost`,
68
+ "red": `Červená`,
69
+ "saturation": `Sytost`
70
+ };
71
+
72
+
73
+ var $7097f64386f1761c$exports = {};
74
+ $7097f64386f1761c$exports = {
75
+ "alpha": `Alfa`,
76
+ "blue": `Blå`,
77
+ "brightness": `Lysstyrke`,
78
+ "green": `Grøn`,
79
+ "hue": `Tone`,
80
+ "lightness": `Lyshed`,
81
+ "red": `Rød`,
82
+ "saturation": `Farvemætning`
83
+ };
84
+
85
+
86
+ var $bdd847d8beb08799$exports = {};
87
+ $bdd847d8beb08799$exports = {
88
+ "alpha": `Alpha`,
89
+ "blue": `Blau`,
90
+ "brightness": `Helligkeit`,
91
+ "green": `Grün`,
92
+ "hue": `Farbton`,
93
+ "lightness": `Leuchtkraft`,
94
+ "red": `Rot`,
95
+ "saturation": `Sättigung`
96
+ };
97
+
98
+
99
+ var $a53e00b683950971$exports = {};
100
+ $a53e00b683950971$exports = {
101
+ "alpha": `Άλφα`,
102
+ "blue": `Μπλε`,
103
+ "brightness": `Φωτεινότητα`,
104
+ "green": `Πράσινο`,
105
+ "hue": `Τόνος`,
106
+ "lightness": `Φωτεινότητα`,
107
+ "red": `Κόκκινο`,
108
+ "saturation": `Κορεσμός`
109
+ };
110
+
111
+
112
+ var $21cdd87e84f28d89$exports = {};
113
+ $21cdd87e84f28d89$exports = {
114
+ "hue": `Hue`,
115
+ "saturation": `Saturation`,
116
+ "lightness": `Lightness`,
117
+ "brightness": `Brightness`,
118
+ "red": `Red`,
119
+ "green": `Green`,
120
+ "blue": `Blue`,
121
+ "alpha": `Alpha`
122
+ };
123
+
124
+
125
+ var $92fee9698e4d675a$exports = {};
126
+ $92fee9698e4d675a$exports = {
127
+ "alpha": `Alpha`,
128
+ "blue": `Azul`,
129
+ "brightness": `Brillo`,
130
+ "green": `Verde`,
131
+ "hue": `Tono`,
132
+ "lightness": `Luminosidad`,
133
+ "red": `Rojo`,
134
+ "saturation": `Saturación`
135
+ };
136
+
137
+
138
+ var $7ea012e91a5ad3ee$exports = {};
139
+ $7ea012e91a5ad3ee$exports = {
140
+ "alpha": `Alfa`,
141
+ "blue": `Sinine`,
142
+ "brightness": `Heledus`,
143
+ "green": `Roheline`,
144
+ "hue": `Värv`,
145
+ "lightness": `Valgus`,
146
+ "red": `Punane`,
147
+ "saturation": `Küllastus`
148
+ };
149
+
150
+
151
+ var $8460c13bb2d75345$exports = {};
152
+ $8460c13bb2d75345$exports = {
153
+ "alpha": `Alpha`,
154
+ "blue": `Sininen`,
155
+ "brightness": `Kirkkaus`,
156
+ "green": `Vihreä`,
157
+ "hue": `Sävy`,
158
+ "lightness": `Valomäärä`,
159
+ "red": `Punainen`,
160
+ "saturation": `Värikylläisyys`
161
+ };
162
+
163
+
164
+ var $2a2d5dc14e680587$exports = {};
165
+ $2a2d5dc14e680587$exports = {
166
+ "alpha": `Alpha`,
167
+ "blue": `Bleu`,
168
+ "brightness": `Luminosité`,
169
+ "green": `Vert`,
170
+ "hue": `Teinte`,
171
+ "lightness": `Luminosité`,
172
+ "red": `Rouge`,
173
+ "saturation": `Saturation`
174
+ };
175
+
176
+
177
+ var $9a3f292371bb0589$exports = {};
178
+ $9a3f292371bb0589$exports = {
179
+ "alpha": `אלפא`,
180
+ "blue": `כחול`,
181
+ "brightness": `בהירות`,
182
+ "green": `ירוק`,
183
+ "hue": `גוון`,
184
+ "lightness": `כמות אור`,
185
+ "red": `אדום`,
186
+ "saturation": `רוויה`
187
+ };
188
+
189
+
190
+ var $4742231a685fa068$exports = {};
191
+ $4742231a685fa068$exports = {
192
+ "alpha": `Alfa`,
193
+ "blue": `Plava`,
194
+ "brightness": `Svjetlina`,
195
+ "green": `Zelena`,
196
+ "hue": `Nijansa`,
197
+ "lightness": `Osvijetljenost`,
198
+ "red": `Crvena`,
199
+ "saturation": `Zasićenost`
200
+ };
201
+
202
+
203
+ var $05e247fd2960981e$exports = {};
204
+ $05e247fd2960981e$exports = {
205
+ "alpha": `Alfa`,
206
+ "blue": `Kék`,
207
+ "brightness": `Fényesség`,
208
+ "green": `Zöld`,
209
+ "hue": `Színárnyalat`,
210
+ "lightness": `Világosság`,
211
+ "red": `Piros`,
212
+ "saturation": `Telítettség`
213
+ };
214
+
215
+
216
+ var $a67524a79ccbe190$exports = {};
217
+ $a67524a79ccbe190$exports = {
218
+ "alpha": `Alfa`,
219
+ "blue": `Blu`,
220
+ "brightness": `Luminosità`,
221
+ "green": `Verde`,
222
+ "hue": `Tonalità`,
223
+ "lightness": `Luminosità`,
224
+ "red": `Rosso`,
225
+ "saturation": `Saturazione`
226
+ };
227
+
228
+
229
+ var $a9eefe9d6c8cb7d5$exports = {};
230
+ $a9eefe9d6c8cb7d5$exports = {
231
+ "alpha": `アルファ`,
232
+ "blue": `青`,
233
+ "brightness": `明るさ`,
234
+ "green": `緑`,
235
+ "hue": `色相`,
236
+ "lightness": `明度`,
237
+ "red": `赤`,
238
+ "saturation": `彩度`
239
+ };
240
+
241
+
242
+ var $4a6b836d4f1bfaba$exports = {};
243
+ $4a6b836d4f1bfaba$exports = {
244
+ "alpha": `알파`,
245
+ "blue": `파랑`,
246
+ "brightness": `명도`,
247
+ "green": `초록`,
248
+ "hue": `색조`,
249
+ "lightness": `밝기`,
250
+ "red": `빨강`,
251
+ "saturation": `채도`
252
+ };
253
+
254
+
255
+ var $c950e4b1c482abde$exports = {};
256
+ $c950e4b1c482abde$exports = {
257
+ "alpha": `Alfa`,
258
+ "blue": `Mėlyna`,
259
+ "brightness": `Ryškumas`,
260
+ "green": `Žalia`,
261
+ "hue": `Atspalvis`,
262
+ "lightness": `Šviesumas`,
263
+ "red": `Raudona`,
264
+ "saturation": `Įsotinimas`
265
+ };
266
+
267
+
268
+ var $d10d6b60dc50b438$exports = {};
269
+ $d10d6b60dc50b438$exports = {
270
+ "alpha": `Alfa`,
271
+ "blue": `Zila`,
272
+ "brightness": `Spilgtums`,
273
+ "green": `Zaļa`,
274
+ "hue": `Nokrāsa`,
275
+ "lightness": `Gaišums`,
276
+ "red": `Sarkana`,
277
+ "saturation": `Piesātinājums`
278
+ };
279
+
280
+
281
+ var $371a732b2494f452$exports = {};
282
+ $371a732b2494f452$exports = {
283
+ "alpha": `Alfa`,
284
+ "blue": `Blå`,
285
+ "brightness": `Lysstyrke`,
286
+ "green": `Grønn`,
287
+ "hue": `Fargetone`,
288
+ "lightness": `Lyshet`,
289
+ "red": `Rød`,
290
+ "saturation": `Metning`
291
+ };
292
+
293
+
294
+ var $6d042cae6243464b$exports = {};
295
+ $6d042cae6243464b$exports = {
296
+ "alpha": `Alfa`,
297
+ "blue": `Blauw`,
298
+ "brightness": `Helderheid`,
299
+ "green": `Groen`,
300
+ "hue": `Kleurtoon`,
301
+ "lightness": `Lichtsterkte`,
302
+ "red": `Rood`,
303
+ "saturation": `Verzadiging`
304
+ };
305
+
306
+
307
+ var $d9ab5c2611e0bcd3$exports = {};
308
+ $d9ab5c2611e0bcd3$exports = {
309
+ "alpha": `Alfa`,
310
+ "blue": `Niebieski`,
311
+ "brightness": `Jasność`,
312
+ "green": `Zielony`,
313
+ "hue": `Odcień`,
314
+ "lightness": `Jaskrawość`,
315
+ "red": `Czerwony`,
316
+ "saturation": `Nasycenie`
317
+ };
318
+
319
+
320
+ var $73f77c9902e29ca6$exports = {};
321
+ $73f77c9902e29ca6$exports = {
322
+ "alpha": `Alfa`,
323
+ "blue": `Azul`,
324
+ "brightness": `Brilho`,
325
+ "green": `Verde`,
326
+ "hue": `Matiz`,
327
+ "lightness": `Luminosidade`,
328
+ "red": `Vermelho`,
329
+ "saturation": `Saturação`
330
+ };
331
+
332
+
333
+ var $4f461eb266a95c10$exports = {};
334
+ $4f461eb266a95c10$exports = {
335
+ "alpha": `Alfa`,
336
+ "blue": `Azul`,
337
+ "brightness": `Luminosidade`,
338
+ "green": `Verde`,
339
+ "hue": `Tonalidade`,
340
+ "lightness": `Claridade`,
341
+ "red": `Vermelho`,
342
+ "saturation": `Saturação`
343
+ };
344
+
345
+
346
+ var $dc46bea2f2597899$exports = {};
347
+ $dc46bea2f2597899$exports = {
348
+ "alpha": `Alfa`,
349
+ "blue": `Albastru`,
350
+ "brightness": `Luminozitate`,
351
+ "green": `Verde`,
352
+ "hue": `Nuanță`,
353
+ "lightness": `Luminozitate`,
354
+ "red": `Roșu`,
355
+ "saturation": `Saturație`
356
+ };
357
+
358
+
359
+ var $622bbd6719cc95af$exports = {};
360
+ $622bbd6719cc95af$exports = {
361
+ "alpha": `Альфа`,
362
+ "blue": `Синий`,
363
+ "brightness": `Яркость`,
364
+ "green": `Зеленый`,
365
+ "hue": `Оттенок`,
366
+ "lightness": `Освещенность`,
367
+ "red": `Красный`,
368
+ "saturation": `Насыщенность`
369
+ };
370
+
371
+
372
+ var $4da03c1ecd9a9c7d$exports = {};
373
+ $4da03c1ecd9a9c7d$exports = {
374
+ "alpha": `Alfa`,
375
+ "blue": `Modrá`,
376
+ "brightness": `Jas`,
377
+ "green": `Zelená`,
378
+ "hue": `Odtieň`,
379
+ "lightness": `Svetlosť`,
380
+ "red": `Červená`,
381
+ "saturation": `Sýtosť`
382
+ };
383
+
384
+
385
+ var $edb6b2fe456ed4e8$exports = {};
386
+ $edb6b2fe456ed4e8$exports = {
387
+ "alpha": `Alfa`,
388
+ "blue": `Modra`,
389
+ "brightness": `Svetlost`,
390
+ "green": `Zelena`,
391
+ "hue": `Barva`,
392
+ "lightness": `Lahkost`,
393
+ "red": `Rdeča`,
394
+ "saturation": `Nasičenost`
395
+ };
396
+
397
+
398
+ var $264cd81c52b30815$exports = {};
399
+ $264cd81c52b30815$exports = {
400
+ "alpha": `Alfa`,
401
+ "blue": `Plava`,
402
+ "brightness": `Osvetljenost`,
403
+ "green": `Zelena`,
404
+ "hue": `Nijansa`,
405
+ "lightness": `Osvetljenje`,
406
+ "red": `Crvena`,
407
+ "saturation": `Zasićenje`
408
+ };
409
+
410
+
411
+ var $6f80afde0270dda7$exports = {};
412
+ $6f80afde0270dda7$exports = {
413
+ "alpha": `Alfa`,
414
+ "blue": `Blått`,
415
+ "brightness": `Ljusstyrka`,
416
+ "green": `Grönt`,
417
+ "hue": `Nyans`,
418
+ "lightness": `Ljushet`,
419
+ "red": `Rött`,
420
+ "saturation": `Mättnad`
421
+ };
422
+
423
+
424
+ var $23a92651c6957668$exports = {};
425
+ $23a92651c6957668$exports = {
426
+ "alpha": `Alfa`,
427
+ "blue": `Mavi`,
428
+ "brightness": `Parlaklık`,
429
+ "green": `Yeşil`,
430
+ "hue": `Ton`,
431
+ "lightness": `Canlılık`,
432
+ "red": `Kırmızı`,
433
+ "saturation": `Doygunluk`
434
+ };
435
+
436
+
437
+ var $0f9b1074d04f4954$exports = {};
438
+ $0f9b1074d04f4954$exports = {
439
+ "alpha": `Альфа`,
440
+ "blue": `Синій`,
441
+ "brightness": `Яскравість`,
442
+ "green": `Зелений`,
443
+ "hue": `Тон`,
444
+ "lightness": `Освітленість`,
445
+ "red": `Червоний`,
446
+ "saturation": `Насиченість`
447
+ };
448
+
449
+
450
+ var $a9cedf75b94e4916$exports = {};
451
+ $a9cedf75b94e4916$exports = {
452
+ "alpha": `Alpha`,
453
+ "blue": `蓝色`,
454
+ "brightness": `亮度`,
455
+ "green": `绿色`,
456
+ "hue": `色相`,
457
+ "lightness": `明亮度`,
458
+ "red": `红色`,
459
+ "saturation": `饱和度`
460
+ };
461
+
462
+
463
+ var $37cff576474bc8d4$exports = {};
464
+ $37cff576474bc8d4$exports = {
465
+ "alpha": `Alpha`,
466
+ "blue": `藍色`,
467
+ "brightness": `亮度`,
468
+ "green": `綠色`,
469
+ "hue": `色相`,
470
+ "lightness": `明亮`,
471
+ "red": `紅色`,
472
+ "saturation": `飽和度`
473
+ };
474
+
475
+
476
+ $7a451c0c6841e6b9$exports = {
477
+ "ar-AE": $2d805fd52bb48883$exports,
478
+ "bg-BG": $6c28468dc1df643c$exports,
479
+ "cs-CZ": $807554f8230db0ed$exports,
480
+ "da-DK": $7097f64386f1761c$exports,
481
+ "de-DE": $bdd847d8beb08799$exports,
482
+ "el-GR": $a53e00b683950971$exports,
483
+ "en-US": $21cdd87e84f28d89$exports,
484
+ "es-ES": $92fee9698e4d675a$exports,
485
+ "et-EE": $7ea012e91a5ad3ee$exports,
486
+ "fi-FI": $8460c13bb2d75345$exports,
487
+ "fr-FR": $2a2d5dc14e680587$exports,
488
+ "he-IL": $9a3f292371bb0589$exports,
489
+ "hr-HR": $4742231a685fa068$exports,
490
+ "hu-HU": $05e247fd2960981e$exports,
491
+ "it-IT": $a67524a79ccbe190$exports,
492
+ "ja-JP": $a9eefe9d6c8cb7d5$exports,
493
+ "ko-KR": $4a6b836d4f1bfaba$exports,
494
+ "lt-LT": $c950e4b1c482abde$exports,
495
+ "lv-LV": $d10d6b60dc50b438$exports,
496
+ "nb-NO": $371a732b2494f452$exports,
497
+ "nl-NL": $6d042cae6243464b$exports,
498
+ "pl-PL": $d9ab5c2611e0bcd3$exports,
499
+ "pt-BR": $73f77c9902e29ca6$exports,
500
+ "pt-PT": $4f461eb266a95c10$exports,
501
+ "ro-RO": $dc46bea2f2597899$exports,
502
+ "ru-RU": $622bbd6719cc95af$exports,
503
+ "sk-SK": $4da03c1ecd9a9c7d$exports,
504
+ "sl-SI": $edb6b2fe456ed4e8$exports,
505
+ "sr-SP": $264cd81c52b30815$exports,
506
+ "sv-SE": $6f80afde0270dda7$exports,
507
+ "tr-TR": $23a92651c6957668$exports,
508
+ "uk-UA": $0f9b1074d04f4954$exports,
509
+ "zh-CN": $a9cedf75b94e4916$exports,
510
+ "zh-TW": $37cff576474bc8d4$exports
511
+ };
512
+
513
+
514
+
515
+
516
+ const $799cddbef784668f$var$strings = new (0, $cBgAy$LocalizedStringDictionary)((0, (/*@__PURE__*/$parcel$interopDefault($7a451c0c6841e6b9$exports))));
517
+ function $799cddbef784668f$export$6e865ea70d7724f(value) {
518
+ let res = $799cddbef784668f$var$RGBColor.parse(value) || $799cddbef784668f$var$HSBColor.parse(value) || $799cddbef784668f$var$HSLColor.parse(value);
519
+ if (res) return res;
520
+ throw new Error("Invalid color value: " + value);
521
+ }
522
+ function $799cddbef784668f$export$4cde5df63f53f473(v) {
523
+ if (typeof v === "string") return $799cddbef784668f$export$6e865ea70d7724f(v);
524
+ else return v;
525
+ }
526
+ class $799cddbef784668f$var$Color {
527
+ toHexInt() {
528
+ return this.toFormat("rgb").toHexInt();
529
+ }
530
+ getChannelValue(channel) {
531
+ if (channel in this) return this[channel];
532
+ throw new Error("Unsupported color channel: " + channel);
533
+ }
534
+ withChannelValue(channel, value) {
535
+ if (channel in this) {
536
+ let x = this.clone();
537
+ x[channel] = value;
538
+ return x;
539
+ }
540
+ throw new Error("Unsupported color channel: " + channel);
541
+ }
542
+ getChannelName(channel, locale) {
543
+ return $799cddbef784668f$var$strings.getStringForLocale(channel, locale);
544
+ }
545
+ getColorSpaceAxes(xyChannels) {
546
+ let { xChannel: xChannel , yChannel: yChannel } = xyChannels;
547
+ let xCh = xChannel || this.getColorChannels().find((c)=>c !== yChannel);
548
+ let yCh = yChannel || this.getColorChannels().find((c)=>c !== xCh);
549
+ let zCh = this.getColorChannels().find((c)=>c !== xCh && c !== yCh);
550
+ return {
551
+ xChannel: xCh,
552
+ yChannel: yCh,
553
+ zChannel: zCh
554
+ };
555
+ }
556
+ }
557
+ class $799cddbef784668f$var$RGBColor extends $799cddbef784668f$var$Color {
558
+ static parse(value) {
559
+ let colors = [];
560
+ // matching #rgb, #rgba, #rrggbb, #rrggbbaa
561
+ if (/^#[\da-f]+$/i.test(value) && [
562
+ 4,
563
+ 5,
564
+ 7,
565
+ 9
566
+ ].includes(value.length)) {
567
+ const values = (value.length < 6 ? value.replace(/[^#]/gi, "$&$&") : value).slice(1).split("");
568
+ while(values.length > 0)colors.push(parseInt(values.splice(0, 2).join(""), 16));
569
+ colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;
570
+ }
571
+ // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)
572
+ const match = value.match(/^rgba?\((.*)\)$/);
573
+ if (match === null || match === void 0 ? void 0 : match[1]) {
574
+ colors = match[1].split(",").map((value)=>Number(value.trim()));
575
+ colors = colors.map((num, i)=>(0, $cBgAy$clamp)(num, 0, i < 3 ? 255 : 1));
576
+ }
577
+ var _colors_;
578
+ return colors.length < 3 ? undefined : new $799cddbef784668f$var$RGBColor(colors[0], colors[1], colors[2], (_colors_ = colors[3]) !== null && _colors_ !== void 0 ? _colors_ : 1);
579
+ }
580
+ toString(format) {
581
+ switch(format){
582
+ case "hex":
583
+ return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
584
+ case "hexa":
585
+ 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();
586
+ case "rgb":
587
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
588
+ case "css":
589
+ case "rgba":
590
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
591
+ default:
592
+ return this.toFormat(format).toString(format);
593
+ }
594
+ }
595
+ toFormat(format) {
596
+ switch(format){
597
+ case "hex":
598
+ case "hexa":
599
+ case "rgb":
600
+ case "rgba":
601
+ return this;
602
+ case "hsb":
603
+ case "hsba":
604
+ return this.toHSB();
605
+ case "hsl":
606
+ case "hsla":
607
+ return this.toHSL();
608
+ default:
609
+ throw new Error("Unsupported color conversion: rgb -> " + format);
610
+ }
611
+ }
612
+ toHexInt() {
613
+ return this.red << 16 | this.green << 8 | this.blue;
614
+ }
615
+ /**
616
+ * Converts an RGB color value to HSB.
617
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
618
+ * @returns An HSBColor object.
619
+ */ toHSB() {
620
+ const red = this.red / 255;
621
+ const green = this.green / 255;
622
+ const blue = this.blue / 255;
623
+ const min = Math.min(red, green, blue);
624
+ const brightness = Math.max(red, green, blue);
625
+ const chroma = brightness - min;
626
+ const saturation = brightness === 0 ? 0 : chroma / brightness;
627
+ let hue = 0; // achromatic
628
+ if (chroma !== 0) {
629
+ switch(brightness){
630
+ case red:
631
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
632
+ break;
633
+ case green:
634
+ hue = (blue - red) / chroma + 2;
635
+ break;
636
+ case blue:
637
+ hue = (red - green) / chroma + 4;
638
+ break;
639
+ }
640
+ hue /= 6;
641
+ }
642
+ 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);
643
+ }
644
+ /**
645
+ * Converts an RGB color value to HSL.
646
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
647
+ * @returns An HSLColor object.
648
+ */ toHSL() {
649
+ const red = this.red / 255;
650
+ const green = this.green / 255;
651
+ const blue = this.blue / 255;
652
+ const min = Math.min(red, green, blue);
653
+ const max = Math.max(red, green, blue);
654
+ const lightness = (max + min) / 2;
655
+ const chroma = max - min;
656
+ let hue;
657
+ let saturation;
658
+ if (chroma === 0) hue = saturation = 0; // achromatic
659
+ else {
660
+ saturation = chroma / (lightness < .5 ? max + min : 2 - max - min);
661
+ switch(max){
662
+ case red:
663
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
664
+ break;
665
+ case green:
666
+ hue = (blue - red) / chroma + 2;
667
+ break;
668
+ case blue:
669
+ hue = (red - green) / chroma + 4;
670
+ break;
671
+ }
672
+ hue /= 6;
673
+ }
674
+ 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);
675
+ }
676
+ clone() {
677
+ return new $799cddbef784668f$var$RGBColor(this.red, this.green, this.blue, this.alpha);
678
+ }
679
+ getChannelRange(channel) {
680
+ switch(channel){
681
+ case "red":
682
+ case "green":
683
+ case "blue":
684
+ return {
685
+ minValue: 0x0,
686
+ maxValue: 0xFF,
687
+ step: 0x1,
688
+ pageSize: 0x11
689
+ };
690
+ case "alpha":
691
+ return {
692
+ minValue: 0,
693
+ maxValue: 1,
694
+ step: 0.01,
695
+ pageSize: 0.1
696
+ };
697
+ default:
698
+ throw new Error("Unknown color channel: " + channel);
699
+ }
700
+ }
701
+ formatChannelValue(channel, locale) {
702
+ let options;
703
+ let value = this.getChannelValue(channel);
704
+ switch(channel){
705
+ case "red":
706
+ case "green":
707
+ case "blue":
708
+ options = {
709
+ style: "decimal"
710
+ };
711
+ break;
712
+ case "alpha":
713
+ options = {
714
+ style: "percent"
715
+ };
716
+ break;
717
+ default:
718
+ throw new Error("Unknown color channel: " + channel);
719
+ }
720
+ return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
721
+ }
722
+ getColorSpace() {
723
+ return "rgb";
724
+ }
725
+ getColorChannels() {
726
+ return $799cddbef784668f$var$RGBColor.colorChannels;
727
+ }
728
+ constructor(red, green, blue, alpha){
729
+ super();
730
+ this.red = red;
731
+ this.green = green;
732
+ this.blue = blue;
733
+ this.alpha = alpha;
734
+ }
735
+ }
736
+ (0, $cBgAy$swchelperssrc_define_propertymjs)($799cddbef784668f$var$RGBColor, "colorChannels", [
737
+ "red",
738
+ "green",
739
+ "blue"
740
+ ]);
741
+ // X = <negative/positive number with/without decimal places>
742
+ // before/after a comma, 0 or more whitespaces are allowed
743
+ // - hsb(X, X%, X%)
744
+ // - hsba(X, X%, X%, X)
745
+ 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+)?)\)/;
746
+ class $799cddbef784668f$var$HSBColor extends $799cddbef784668f$var$Color {
747
+ static parse(value) {
748
+ let m;
749
+ if (m = value.match($799cddbef784668f$var$HSB_REGEX)) {
750
+ var _m_;
751
+ const [h, s, b, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
752
+ 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));
753
+ }
754
+ }
755
+ toString(format) {
756
+ switch(format){
757
+ case "css":
758
+ return this.toHSL().toString("css");
759
+ case "hex":
760
+ return this.toRGB().toString("hex");
761
+ case "hexa":
762
+ return this.toRGB().toString("hexa");
763
+ case "hsb":
764
+ return `hsb(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.brightness, 2)}%)`;
765
+ case "hsba":
766
+ return `hsba(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
767
+ default:
768
+ return this.toFormat(format).toString(format);
769
+ }
770
+ }
771
+ toFormat(format) {
772
+ switch(format){
773
+ case "hsb":
774
+ case "hsba":
775
+ return this;
776
+ case "hsl":
777
+ case "hsla":
778
+ return this.toHSL();
779
+ case "rgb":
780
+ case "rgba":
781
+ return this.toRGB();
782
+ default:
783
+ throw new Error("Unsupported color conversion: hsb -> " + format);
784
+ }
785
+ }
786
+ /**
787
+ * Converts a HSB color to HSL.
788
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
789
+ * @returns An HSLColor object.
790
+ */ toHSL() {
791
+ let saturation = this.saturation / 100;
792
+ let brightness = this.brightness / 100;
793
+ let lightness = brightness * (1 - saturation / 2);
794
+ saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
795
+ 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);
796
+ }
797
+ /**
798
+ * Converts a HSV color value to RGB.
799
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
800
+ * @returns An RGBColor object.
801
+ */ toRGB() {
802
+ let hue = this.hue;
803
+ let saturation = this.saturation / 100;
804
+ let brightness = this.brightness / 100;
805
+ let fn = (n, k = (n + hue / 60) % 6)=>brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
806
+ return new $799cddbef784668f$var$RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha);
807
+ }
808
+ clone() {
809
+ return new $799cddbef784668f$var$HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
810
+ }
811
+ getChannelRange(channel) {
812
+ switch(channel){
813
+ case "hue":
814
+ return {
815
+ minValue: 0,
816
+ maxValue: 360,
817
+ step: 1,
818
+ pageSize: 15
819
+ };
820
+ case "saturation":
821
+ case "brightness":
822
+ return {
823
+ minValue: 0,
824
+ maxValue: 100,
825
+ step: 1,
826
+ pageSize: 10
827
+ };
828
+ case "alpha":
829
+ return {
830
+ minValue: 0,
831
+ maxValue: 1,
832
+ step: 0.01,
833
+ pageSize: 0.1
834
+ };
835
+ default:
836
+ throw new Error("Unknown color channel: " + channel);
837
+ }
838
+ }
839
+ formatChannelValue(channel, locale) {
840
+ let options;
841
+ let value = this.getChannelValue(channel);
842
+ switch(channel){
843
+ case "hue":
844
+ options = {
845
+ style: "unit",
846
+ unit: "degree",
847
+ unitDisplay: "narrow"
848
+ };
849
+ break;
850
+ case "saturation":
851
+ case "brightness":
852
+ options = {
853
+ style: "percent"
854
+ };
855
+ value /= 100;
856
+ break;
857
+ case "alpha":
858
+ options = {
859
+ style: "percent"
860
+ };
861
+ break;
862
+ default:
863
+ throw new Error("Unknown color channel: " + channel);
864
+ }
865
+ return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
866
+ }
867
+ getColorSpace() {
868
+ return "hsb";
869
+ }
870
+ getColorChannels() {
871
+ return $799cddbef784668f$var$HSBColor.colorChannels;
872
+ }
873
+ constructor(hue, saturation, brightness, alpha){
874
+ super();
875
+ this.hue = hue;
876
+ this.saturation = saturation;
877
+ this.brightness = brightness;
878
+ this.alpha = alpha;
879
+ }
880
+ }
881
+ (0, $cBgAy$swchelperssrc_define_propertymjs)($799cddbef784668f$var$HSBColor, "colorChannels", [
882
+ "hue",
883
+ "saturation",
884
+ "brightness"
885
+ ]);
886
+ // X = <negative/positive number with/without decimal places>
887
+ // before/after a comma, 0 or more whitespaces are allowed
888
+ // - hsl(X, X%, X%)
889
+ // - hsla(X, X%, X%, X)
890
+ 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+)?)\)/;
891
+ function $799cddbef784668f$var$mod(n, m) {
892
+ return (n % m + m) % m;
893
+ }
894
+ class $799cddbef784668f$var$HSLColor extends $799cddbef784668f$var$Color {
895
+ static parse(value) {
896
+ let m;
897
+ if (m = value.match($799cddbef784668f$var$HSL_REGEX)) {
898
+ var _m_;
899
+ const [h, s, l, a] = ((_m_ = m[1]) !== null && _m_ !== void 0 ? _m_ : m[2]).split(",").map((n)=>Number(n.trim().replace("%", "")));
900
+ 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));
901
+ }
902
+ }
903
+ toString(format) {
904
+ switch(format){
905
+ case "hex":
906
+ return this.toRGB().toString("hex");
907
+ case "hexa":
908
+ return this.toRGB().toString("hexa");
909
+ case "hsl":
910
+ return `hsl(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.lightness, 2)}%)`;
911
+ case "css":
912
+ case "hsla":
913
+ return `hsla(${this.hue}, ${(0, $cBgAy$toFixedNumber)(this.saturation, 2)}%, ${(0, $cBgAy$toFixedNumber)(this.lightness, 2)}%, ${this.alpha})`;
914
+ default:
915
+ return this.toFormat(format).toString(format);
916
+ }
917
+ }
918
+ toFormat(format) {
919
+ switch(format){
920
+ case "hsl":
921
+ case "hsla":
922
+ return this;
923
+ case "hsb":
924
+ case "hsba":
925
+ return this.toHSB();
926
+ case "rgb":
927
+ case "rgba":
928
+ return this.toRGB();
929
+ default:
930
+ throw new Error("Unsupported color conversion: hsl -> " + format);
931
+ }
932
+ }
933
+ /**
934
+ * Converts a HSL color to HSB.
935
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
936
+ * @returns An HSBColor object.
937
+ */ toHSB() {
938
+ let saturation = this.saturation / 100;
939
+ let lightness = this.lightness / 100;
940
+ let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
941
+ saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
942
+ 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);
943
+ }
944
+ /**
945
+ * Converts a HSL color to RGB.
946
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
947
+ * @returns An RGBColor object.
948
+ */ toRGB() {
949
+ let hue = this.hue;
950
+ let saturation = this.saturation / 100;
951
+ let lightness = this.lightness / 100;
952
+ let a = saturation * Math.min(lightness, 1 - lightness);
953
+ let fn = (n, k = (n + hue / 30) % 12)=>lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
954
+ return new $799cddbef784668f$var$RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha);
955
+ }
956
+ clone() {
957
+ return new $799cddbef784668f$var$HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
958
+ }
959
+ getChannelRange(channel) {
960
+ switch(channel){
961
+ case "hue":
962
+ return {
963
+ minValue: 0,
964
+ maxValue: 360,
965
+ step: 1,
966
+ pageSize: 15
967
+ };
968
+ case "saturation":
969
+ case "lightness":
970
+ return {
971
+ minValue: 0,
972
+ maxValue: 100,
973
+ step: 1,
974
+ pageSize: 10
975
+ };
976
+ case "alpha":
977
+ return {
978
+ minValue: 0,
979
+ maxValue: 1,
980
+ step: 0.01,
981
+ pageSize: 0.1
982
+ };
983
+ default:
984
+ throw new Error("Unknown color channel: " + channel);
985
+ }
986
+ }
987
+ formatChannelValue(channel, locale) {
988
+ let options;
989
+ let value = this.getChannelValue(channel);
990
+ switch(channel){
991
+ case "hue":
992
+ options = {
993
+ style: "unit",
994
+ unit: "degree",
995
+ unitDisplay: "narrow"
996
+ };
997
+ break;
998
+ case "saturation":
999
+ case "lightness":
1000
+ options = {
1001
+ style: "percent"
1002
+ };
1003
+ value /= 100;
1004
+ break;
1005
+ case "alpha":
1006
+ options = {
1007
+ style: "percent"
1008
+ };
1009
+ break;
1010
+ default:
1011
+ throw new Error("Unknown color channel: " + channel);
1012
+ }
1013
+ return new (0, $cBgAy$NumberFormatter)(locale, options).format(value);
1014
+ }
1015
+ getColorSpace() {
1016
+ return "hsl";
1017
+ }
1018
+ getColorChannels() {
1019
+ return $799cddbef784668f$var$HSLColor.colorChannels;
1020
+ }
1021
+ constructor(hue, saturation, lightness, alpha){
1022
+ super();
1023
+ this.hue = hue;
1024
+ this.saturation = saturation;
1025
+ this.lightness = lightness;
1026
+ this.alpha = alpha;
1027
+ }
1028
+ }
1029
+ (0, $cBgAy$swchelperssrc_define_propertymjs)($799cddbef784668f$var$HSLColor, "colorChannels", [
1030
+ "hue",
1031
+ "saturation",
1032
+ "lightness"
1033
+ ]);
1034
+
1035
+
1036
+ /*
1037
+ * Copyright 2020 Adobe. All rights reserved.
1038
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1039
+ * you may not use this file except in compliance with the License. You may obtain a copy
1040
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1041
+ *
1042
+ * Unless required by applicable law or agreed to in writing, software distributed under
1043
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1044
+ * OF ANY KIND, either express or implied. See the License for the specific language
1045
+ * governing permissions and limitations under the License.
1046
+ */
1047
+
1048
+
1049
+ const $6e14a98a7f67141d$var$DEFAULT_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#ffffff");
1050
+ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
1051
+ let { value: value , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1052
+ if (!value && !defaultValue) defaultValue = $6e14a98a7f67141d$var$DEFAULT_COLOR;
1053
+ let [color, setColor] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1054
+ let valueRef = (0, $cBgAy$useRef)(color);
1055
+ valueRef.current = color;
1056
+ let channels = (0, $cBgAy$useMemo)(()=>valueRef.current.getColorSpaceAxes({
1057
+ xChannel: xChannel,
1058
+ yChannel: yChannel
1059
+ }), [
1060
+ xChannel,
1061
+ yChannel
1062
+ ]);
1063
+ let xChannelRange = color.getChannelRange(channels.xChannel);
1064
+ let yChannelRange = color.getChannelRange(channels.yChannel);
1065
+ let { minValue: minValueX , maxValue: maxValueX , step: stepX , pageSize: pageSizeX } = xChannelRange;
1066
+ let { minValue: minValueY , maxValue: maxValueY , step: stepY , pageSize: pageSizeY } = yChannelRange;
1067
+ let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
1068
+ let isDraggingRef = (0, $cBgAy$useRef)(false).current;
1069
+ let xValue = color.getChannelValue(channels.xChannel);
1070
+ let yValue = color.getChannelValue(channels.yChannel);
1071
+ let setXValue = (v)=>{
1072
+ if (v === xValue) return;
1073
+ valueRef.current = color.withChannelValue(channels.xChannel, v);
1074
+ setColor(valueRef.current);
1075
+ };
1076
+ let setYValue = (v)=>{
1077
+ if (v === yValue) return;
1078
+ valueRef.current = color.withChannelValue(channels.yChannel, v);
1079
+ setColor(valueRef.current);
1080
+ };
1081
+ return {
1082
+ channels: channels,
1083
+ xChannelStep: stepX,
1084
+ yChannelStep: stepY,
1085
+ xChannelPageStep: pageSizeX,
1086
+ yChannelPageStep: pageSizeY,
1087
+ value: color,
1088
+ setValue (value) {
1089
+ let c = (0, $799cddbef784668f$export$4cde5df63f53f473)(value);
1090
+ valueRef.current = c;
1091
+ setColor(c);
1092
+ },
1093
+ xValue: xValue,
1094
+ setXValue: setXValue,
1095
+ yValue: yValue,
1096
+ setYValue: setYValue,
1097
+ setColorFromPoint (x, y) {
1098
+ let newXValue = minValueX + (0, $cBgAy$clamp)(x, 0, 1) * (maxValueX - minValueX);
1099
+ let newYValue = minValueY + (1 - (0, $cBgAy$clamp)(y, 0, 1)) * (maxValueY - minValueY);
1100
+ let newColor;
1101
+ if (newXValue !== xValue) {
1102
+ // Round new value to multiple of step, clamp value between min and max
1103
+ newXValue = (0, $cBgAy$snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
1104
+ newColor = color.withChannelValue(channels.xChannel, newXValue);
1105
+ }
1106
+ if (newYValue !== yValue) {
1107
+ // Round new value to multiple of step, clamp value between min and max
1108
+ newYValue = (0, $cBgAy$snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
1109
+ newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
1110
+ }
1111
+ if (newColor) setColor(newColor);
1112
+ },
1113
+ getThumbPosition () {
1114
+ let x = (xValue - minValueX) / (maxValueX - minValueX);
1115
+ let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
1116
+ return {
1117
+ x: x,
1118
+ y: y
1119
+ };
1120
+ },
1121
+ incrementX (stepSize) {
1122
+ setXValue(xValue + stepSize > maxValueX ? maxValueX : (0, $cBgAy$snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX));
1123
+ },
1124
+ incrementY (stepSize) {
1125
+ setYValue(yValue + stepSize > maxValueY ? maxValueY : (0, $cBgAy$snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY));
1126
+ },
1127
+ decrementX (stepSize) {
1128
+ setXValue((0, $cBgAy$snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX));
1129
+ },
1130
+ decrementY (stepSize) {
1131
+ setYValue((0, $cBgAy$snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY));
1132
+ },
1133
+ setDragging (isDragging) {
1134
+ let wasDragging = isDraggingRef;
1135
+ isDraggingRef = isDragging;
1136
+ if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1137
+ setDragging(isDragging);
1138
+ },
1139
+ isDragging: isDragging,
1140
+ getDisplayColor () {
1141
+ return color.withChannelValue("alpha", 1);
1142
+ }
1143
+ };
1144
+ }
1145
+
1146
+
1147
+ /*
1148
+ * Copyright 2020 Adobe. All rights reserved.
1149
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1150
+ * you may not use this file except in compliance with the License. You may obtain a copy
1151
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1152
+ *
1153
+ * Unless required by applicable law or agreed to in writing, software distributed under
1154
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1155
+ * OF ANY KIND, either express or implied. See the License for the specific language
1156
+ * governing permissions and limitations under the License.
1157
+ */
1158
+
1159
+
1160
+ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
1161
+ let { channel: channel , value: value , defaultValue: defaultValue , onChange: onChange , locale: locale , ...otherProps } = props;
1162
+ if (value == null && defaultValue == null) throw new Error("useColorSliderState requires a value or defaultValue");
1163
+ let [color, setColor] = (0, $cBgAy$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1164
+ let sliderState = (0, $cBgAy$useSliderState)({
1165
+ ...color.getChannelRange(channel),
1166
+ ...otherProps,
1167
+ // Unused except in getThumbValueLabel, which is overridden below. null to appease TypeScript.
1168
+ numberFormatter: null,
1169
+ value: color.getChannelValue(channel),
1170
+ onChange (v) {
1171
+ setColor(color.withChannelValue(channel, v));
1172
+ },
1173
+ onChangeEnd (v) {
1174
+ // onChange will have already been called with the right value, this is just to trigger onChangeEnd
1175
+ if (props.onChangeEnd) props.onChangeEnd(color.withChannelValue(channel, v));
1176
+ }
1177
+ });
1178
+ let { step: step , pageSize: pageSize } = color.getChannelRange(channel);
1179
+ return {
1180
+ ...sliderState,
1181
+ value: color,
1182
+ setValue (value) {
1183
+ setColor((0, $799cddbef784668f$export$4cde5df63f53f473)(value));
1184
+ },
1185
+ getDisplayColor () {
1186
+ switch(channel){
1187
+ case "hue":
1188
+ return (0, $799cddbef784668f$export$6e865ea70d7724f)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
1189
+ case "lightness":
1190
+ case "brightness":
1191
+ case "saturation":
1192
+ case "red":
1193
+ case "green":
1194
+ case "blue":
1195
+ return color.withChannelValue("alpha", 1);
1196
+ case "alpha":
1197
+ return color;
1198
+ default:
1199
+ throw new Error("Unknown color channel: " + channel);
1200
+ }
1201
+ },
1202
+ getThumbValueLabel () {
1203
+ return color.formatChannelValue(channel, locale);
1204
+ },
1205
+ step: step,
1206
+ pageSize: pageSize
1207
+ };
1208
+ }
1209
+
1210
+
1211
+ /*
1212
+ * Copyright 2020 Adobe. All rights reserved.
1213
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1214
+ * you may not use this file except in compliance with the License. You may obtain a copy
1215
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1216
+ *
1217
+ * Unless required by applicable law or agreed to in writing, software distributed under
1218
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1219
+ * OF ANY KIND, either express or implied. See the License for the specific language
1220
+ * governing permissions and limitations under the License.
1221
+ */
1222
+
1223
+
1224
+ const $ee4262c74a467b07$var$DEFAULT_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("hsl(0, 100%, 50%)");
1225
+ function $ee4262c74a467b07$var$roundToStep(value, step) {
1226
+ return Math.round(value / step) * step;
1227
+ }
1228
+ function $ee4262c74a467b07$var$mod(n, m) {
1229
+ return (n % m + m) % m;
1230
+ }
1231
+ function $ee4262c74a467b07$var$roundDown(v) {
1232
+ let r = Math.floor(v);
1233
+ if (r === v) return v - 1;
1234
+ else return r;
1235
+ }
1236
+ function $ee4262c74a467b07$var$degToRad(deg) {
1237
+ return deg * Math.PI / 180;
1238
+ }
1239
+ function $ee4262c74a467b07$var$radToDeg(rad) {
1240
+ return rad * 180 / Math.PI;
1241
+ }
1242
+ // 0deg = 3 o'clock. increases clockwise
1243
+ function $ee4262c74a467b07$var$angleToCartesian(angle, radius) {
1244
+ let rad = $ee4262c74a467b07$var$degToRad(360 - angle + 90);
1245
+ let x = Math.sin(rad) * radius;
1246
+ let y = Math.cos(rad) * radius;
1247
+ return {
1248
+ x: x,
1249
+ y: y
1250
+ };
1251
+ }
1252
+ function $ee4262c74a467b07$var$cartesianToAngle(x, y, radius) {
1253
+ let deg = $ee4262c74a467b07$var$radToDeg(Math.atan2(y / radius, x / radius));
1254
+ return (deg + 360) % 360;
1255
+ }
1256
+ function $ee4262c74a467b07$export$f4301076d9336137(props) {
1257
+ let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd } = props;
1258
+ if (!props.value && !defaultValue) defaultValue = $ee4262c74a467b07$var$DEFAULT_COLOR;
1259
+ let [value, setValue] = (0, $cBgAy$useControlledState)((0, $799cddbef784668f$export$4cde5df63f53f473)(props.value), (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
1260
+ let valueRef = (0, $cBgAy$useRef)(value);
1261
+ valueRef.current = value;
1262
+ let channelRange = value.getChannelRange("hue");
1263
+ let { minValue: minValueX , maxValue: maxValueX , step: step , pageSize: pageStep } = channelRange;
1264
+ let [isDragging, setDragging] = (0, $cBgAy$useState)(false);
1265
+ let isDraggingRef = (0, $cBgAy$useRef)(false).current;
1266
+ let hue = value.getChannelValue("hue");
1267
+ function setHue(v) {
1268
+ if (v > 360) // Make sure you can always get back to 0.
1269
+ v = 0;
1270
+ v = $ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(v, 360), step);
1271
+ if (hue !== v) {
1272
+ let color = value.withChannelValue("hue", v);
1273
+ valueRef.current = color;
1274
+ setValue(color);
1275
+ }
1276
+ }
1277
+ return {
1278
+ value: value,
1279
+ step: step,
1280
+ pageStep: pageStep,
1281
+ setValue (v) {
1282
+ let color = (0, $799cddbef784668f$export$4cde5df63f53f473)(v);
1283
+ valueRef.current = color;
1284
+ setValue(color);
1285
+ },
1286
+ hue: hue,
1287
+ setHue: setHue,
1288
+ setHueFromPoint (x, y, radius) {
1289
+ setHue($ee4262c74a467b07$var$cartesianToAngle(x, y, radius));
1290
+ },
1291
+ getThumbPosition (radius) {
1292
+ return $ee4262c74a467b07$var$angleToCartesian(value.getChannelValue("hue"), radius);
1293
+ },
1294
+ increment (stepSize = 1) {
1295
+ let s = Math.max(stepSize, step);
1296
+ let newValue = hue + s;
1297
+ if (newValue >= maxValueX) // Make sure you can always get back to 0.
1298
+ newValue = minValueX;
1299
+ setHue($ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(newValue, 360), s));
1300
+ },
1301
+ decrement (stepSize = 1) {
1302
+ let s = Math.max(stepSize, step);
1303
+ if (hue === 0) // We can't just subtract step because this might be the case:
1304
+ // |(previous step) - 0| < step size
1305
+ setHue($ee4262c74a467b07$var$roundDown(360 / s) * s);
1306
+ else setHue($ee4262c74a467b07$var$roundToStep($ee4262c74a467b07$var$mod(hue - s, 360), s));
1307
+ },
1308
+ setDragging (isDragging) {
1309
+ let wasDragging = isDraggingRef;
1310
+ isDraggingRef = isDragging;
1311
+ if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
1312
+ setDragging(isDragging);
1313
+ },
1314
+ isDragging: isDragging,
1315
+ getDisplayColor () {
1316
+ return value.toFormat("hsl").withChannelValue("saturation", 100).withChannelValue("lightness", 50).withChannelValue("alpha", 1);
1317
+ }
1318
+ };
1319
+ }
1320
+
1321
+
1322
+ /*
1323
+ * Copyright 2020 Adobe. All rights reserved.
1324
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1325
+ * you may not use this file except in compliance with the License. You may obtain a copy
1326
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1327
+ *
1328
+ * Unless required by applicable law or agreed to in writing, software distributed under
1329
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1330
+ * OF ANY KIND, either express or implied. See the License for the specific language
1331
+ * governing permissions and limitations under the License.
1332
+ */
1333
+ /*
1334
+ * Copyright 2020 Adobe. All rights reserved.
1335
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1336
+ * you may not use this file except in compliance with the License. You may obtain a copy
1337
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1338
+ *
1339
+ * Unless required by applicable law or agreed to in writing, software distributed under
1340
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1341
+ * OF ANY KIND, either express or implied. See the License for the specific language
1342
+ * governing permissions and limitations under the License.
1343
+ */
1344
+
1345
+ function $aa90ad8b2b1d015f$export$5aadd9c0606af5c2(value) {
1346
+ return (0, $cBgAy$useMemo)(()=>{
1347
+ if (typeof value === "string") try {
1348
+ return (0, $799cddbef784668f$export$6e865ea70d7724f)(value);
1349
+ } catch (err) {
1350
+ return undefined;
1351
+ }
1352
+ return value;
1353
+ }, [
1354
+ value
1355
+ ]);
1356
+ }
1357
+
1358
+
1359
+
1360
+
1361
+ const $b335ada08155d9c0$var$MIN_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#000000");
1362
+ const $b335ada08155d9c0$var$MAX_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)("#FFFFFF");
1363
+ const $b335ada08155d9c0$var$MIN_COLOR_INT = $b335ada08155d9c0$var$MIN_COLOR.toHexInt();
1364
+ const $b335ada08155d9c0$var$MAX_COLOR_INT = $b335ada08155d9c0$var$MAX_COLOR.toHexInt();
1365
+ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
1366
+ let { value: value , defaultValue: defaultValue , onChange: onChange } = props;
1367
+ let { step: step } = $b335ada08155d9c0$var$MIN_COLOR.getChannelRange("red");
1368
+ let initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value);
1369
+ let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
1370
+ let [colorValue, setColorValue] = (0, $cBgAy$useControlledState)(initialValue, initialDefaultValue, onChange);
1371
+ let [inputValue, setInputValue] = (0, $cBgAy$useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString("hex") : "");
1372
+ let safelySetColorValue = (newColor)=>{
1373
+ if (!colorValue || !newColor) {
1374
+ setColorValue(newColor);
1375
+ return;
1376
+ }
1377
+ if (newColor.toHexInt() !== colorValue.toHexInt()) {
1378
+ setColorValue(newColor);
1379
+ return;
1380
+ }
1381
+ };
1382
+ let prevValue = (0, $cBgAy$useRef)(colorValue);
1383
+ if (prevValue.current !== colorValue) {
1384
+ setInputValue(colorValue ? colorValue.toString("hex") : "");
1385
+ prevValue.current = colorValue;
1386
+ }
1387
+ let parsedValue = (0, $cBgAy$useMemo)(()=>{
1388
+ let color;
1389
+ try {
1390
+ color = (0, $799cddbef784668f$export$6e865ea70d7724f)(inputValue.startsWith("#") ? inputValue : `#${inputValue}`);
1391
+ } catch (err) {
1392
+ color = null;
1393
+ }
1394
+ return color;
1395
+ }, [
1396
+ inputValue
1397
+ ]);
1398
+ let parsed = (0, $cBgAy$useRef)(null);
1399
+ parsed.current = parsedValue;
1400
+ let commit = ()=>{
1401
+ // Set to empty state if input value is empty
1402
+ if (!inputValue.length) {
1403
+ safelySetColorValue(null);
1404
+ setInputValue(value === undefined ? "" : colorValue.toString("hex"));
1405
+ return;
1406
+ }
1407
+ // if it failed to parse, then reset input to formatted version of current number
1408
+ if (parsed.current == null) {
1409
+ setInputValue(colorValue ? colorValue.toString("hex") : "");
1410
+ return;
1411
+ }
1412
+ safelySetColorValue(parsed.current);
1413
+ // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
1414
+ let newColorValue = "";
1415
+ if (colorValue) newColorValue = colorValue.toString("hex");
1416
+ setInputValue(newColorValue);
1417
+ };
1418
+ let increment = ()=>{
1419
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsed.current, step);
1420
+ // if we've arrived at the same value that was previously in the state, the
1421
+ // input value should be updated to match
1422
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
1423
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
1424
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
1425
+ safelySetColorValue(newValue);
1426
+ };
1427
+ let decrement = ()=>{
1428
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsed.current, -step);
1429
+ // if we've arrived at the same value that was previously in the state, the
1430
+ // input value should be updated to match
1431
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
1432
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
1433
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
1434
+ safelySetColorValue(newValue);
1435
+ };
1436
+ let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
1437
+ let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
1438
+ let validate = (value)=>{
1439
+ var _value_match;
1440
+ return value === "" || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
1441
+ };
1442
+ return {
1443
+ validate: validate,
1444
+ colorValue: colorValue,
1445
+ inputValue: inputValue,
1446
+ setInputValue: setInputValue,
1447
+ commit: commit,
1448
+ increment: increment,
1449
+ incrementToMax: incrementToMax,
1450
+ decrement: decrement,
1451
+ decrementToMin: decrementToMin
1452
+ };
1453
+ }
1454
+ function $b335ada08155d9c0$var$addColorValue(color, step) {
1455
+ let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
1456
+ let colorInt = newColor.toHexInt();
1457
+ let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
1458
+ if (clampInt !== colorInt) {
1459
+ let newColorString = `#${clampInt.toString(16).padStart(6, "0").toUpperCase()}`;
1460
+ newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
1461
+ }
1462
+ return newColor;
1463
+ }
1464
+
1465
+
1466
+
1467
+
1468
+ export {$799cddbef784668f$export$6e865ea70d7724f as parseColor, $6e14a98a7f67141d$export$6df7f0e2cabc7eef as useColorAreaState, $25a25ac0d1624665$export$57bc203e1c9c6d44 as useColorSliderState, $ee4262c74a467b07$export$f4301076d9336137 as useColorWheelState, $b335ada08155d9c0$export$d52a01683abdfcd6 as useColorFieldState};
1469
+ //# sourceMappingURL=module.js.map