storybook 10.0.0-beta.1 → 10.0.0-beta.10
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.
- package/assets/server/openBrowser.applescript +94 -0
- package/dist/_browser-chunks/Color-KPLIACXP.js +1569 -0
- package/dist/_browser-chunks/{WithTooltip-ERFLZL6W.js → WithTooltip-SK46ZJ2J.js} +1 -1
- package/dist/_browser-chunks/{chunk-YY5GICNT.js → chunk-6E2SHJSL.js} +175 -32
- package/dist/_browser-chunks/{chunk-EOILZP2R.js → chunk-BOOOPFZF.js} +7 -2
- package/dist/_browser-chunks/{chunk-YWDKX534.js → chunk-FA42P6MO.js} +49 -4
- package/dist/_browser-chunks/chunk-G33S6YM3.js +521 -0
- package/dist/_browser-chunks/{chunk-MZNYTCNT.js → chunk-HMIIJ6UD.js} +6 -6
- package/dist/_browser-chunks/{chunk-4QPX7WIQ.js → chunk-JJZMHC3A.js} +57 -166
- package/dist/_browser-chunks/{chunk-MD2FTHCZ.js → chunk-JVSKG4YS.js} +3 -16
- package/dist/_browser-chunks/{chunk-E7VLET3C.js → chunk-KSCAWCCE.js} +3947 -4291
- package/dist/_browser-chunks/{chunk-PYK5ZTFK.js → chunk-PS3AOQI4.js} +48 -25
- package/dist/_browser-chunks/chunk-QK3L5AXO.js +372 -0
- package/dist/_browser-chunks/chunk-SHR3NNR3.js +5810 -0
- package/dist/_browser-chunks/{chunk-O5R5CGFA.js → chunk-TMDZCWME.js} +1 -2
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +20 -0
- package/dist/_browser-chunks/{chunk-T7RCAJIX.js → chunk-Y3M7TW6K.js} +43 -47
- package/dist/_browser-chunks/{syntaxhighlighter-YYAA4CS4.js → syntaxhighlighter-R46XOLMC.js} +1 -1
- package/dist/_node-chunks/{builder-manager-EXW4ETLN.js → builder-manager-SJGIDEN6.js} +45 -155
- package/dist/_node-chunks/camelcase-VZHWABQV.js +18 -0
- package/dist/_node-chunks/{chunk-F5J33SXQ.js → chunk-6CZW7AGN.js} +7 -7
- package/dist/_node-chunks/{chunk-2G5THETV.js → chunk-6XT5OLNL.js} +12 -12
- package/dist/_node-chunks/{chunk-U45F2NP6.js → chunk-AHRH5RPR.js} +7 -7
- package/dist/_node-chunks/{chunk-ICPKUV5G.js → chunk-AOH6ABSV.js} +7 -7
- package/dist/_node-chunks/chunk-C5V22GP7.js +79 -0
- package/dist/_node-chunks/{chunk-5V6QH7WC.js → chunk-FIROF4DV.js} +7 -7
- package/dist/_node-chunks/{chunk-WDKWVNL2.js → chunk-GUJVZUYI.js} +7 -7
- package/dist/_node-chunks/chunk-IHPLRRAR.js +4741 -0
- package/dist/_node-chunks/{chunk-PMEEE3UE.js → chunk-JMXKCRWR.js} +30 -21
- package/dist/_node-chunks/{chunk-5ZX5SJOP.js → chunk-JUMUXWEV.js} +162 -103
- package/dist/_node-chunks/{chunk-CM3UGTR5.js → chunk-KGX33KXX.js} +7 -7
- package/dist/_node-chunks/{chunk-6CCUFDHU.js → chunk-KLVABNEU.js} +7 -7
- package/dist/_node-chunks/{chunk-EO4S3VXL.js → chunk-OL6DY6BT.js} +653 -775
- package/dist/_node-chunks/{chunk-GVCXNIAA.js → chunk-ONJV3K2L.js} +399 -116
- package/dist/_node-chunks/{chunk-3ZKQWDCG.js → chunk-PTHTD4RO.js} +223 -243
- package/dist/_node-chunks/{chunk-VNLBDN2Z.js → chunk-QQ3Z5KGJ.js} +6 -6
- package/dist/_node-chunks/{chunk-2QZOLZDJ.js → chunk-QRTDDTZJ.js} +9 -9
- package/dist/_node-chunks/chunk-R54K4KSM.js +1540 -0
- package/dist/_node-chunks/{chunk-24TGL6EX.js → chunk-S2LZC6JK.js} +8 -8
- package/dist/_node-chunks/chunk-SFJFSPRT.js +62 -0
- package/dist/_node-chunks/{chunk-SUMFFLGF.js → chunk-SSN5PKIY.js} +6 -6
- package/dist/_node-chunks/{chunk-QC5FE2D7.js → chunk-SXR2DITB.js} +7 -7
- package/dist/_node-chunks/{chunk-FZP2YGG3.js → chunk-TH5QVQRL.js} +7 -7
- package/dist/_node-chunks/chunk-U34NWAU2.js +18 -0
- package/dist/_node-chunks/{chunk-XTSBFCVE.js → chunk-UV3CZ3KS.js} +7 -7
- package/dist/_node-chunks/{chunk-PL2PKDRO.js → chunk-UVUGJDAI.js} +60 -102
- package/dist/_node-chunks/{chunk-EDBXIJN5.js → chunk-VOUNSD2E.js} +7 -7
- package/dist/_node-chunks/{chunk-WP7DV5JT.js → chunk-WFCPBKQJ.js} +583 -180
- package/dist/_node-chunks/{chunk-4WNZYNQY.js → chunk-XHF3WWNP.js} +623 -750
- package/dist/_node-chunks/{chunk-3SGKBLOL.js → chunk-XU45KXNQ.js} +8 -8
- package/dist/_node-chunks/{camelcase-VZZFWA2L.js → chunk-YHO6XR7U.js} +9 -8
- package/dist/_node-chunks/{dist-VZL6D6Y3.js → dist-IIC5PBL7.js} +9 -9
- package/dist/_node-chunks/{globby-GZXJJ4W6.js → globby-CJACC3HJ.js} +17 -13
- package/dist/_node-chunks/{lib-PHT5GCV2.js → lib-ZY4TKSOR.js} +40 -16
- package/dist/_node-chunks/{mdx-N42X6CFJ-EPDIV4A2.js → mdx-N42X6CFJ-3XNW3DFO.js} +8 -8
- package/dist/_node-chunks/{p-limit-AJIFSZTI.js → p-limit-R2OFT5HE.js} +76 -10
- package/dist/_node-chunks/{plugin-3VI56CEF.js → plugin-5XD5R2KD.js} +10 -10
- package/dist/_node-chunks/{plugin-AV4OEKYM.js → plugin-WAWVQMVR.js} +10 -10
- package/dist/_node-chunks/{webpack-inject-mocker-runtime-plugin-E7J5FKLA.js → webpack-inject-mocker-runtime-plugin-SCRGJLIS.js} +1307 -847
- package/dist/_node-chunks/{webpack-mock-plugin-VTYGW7HO.js → webpack-mock-plugin-3VAXEGG2.js} +9 -9
- package/dist/babel/index.d.ts +1 -1
- package/dist/babel/index.js +11 -11
- package/dist/bin/core.js +638 -187
- package/dist/bin/dispatcher.js +11 -11
- package/dist/bin/loader.js +8 -8
- package/dist/cli/index.d.ts +62 -75
- package/dist/cli/index.js +66 -55
- package/dist/common/index.d.ts +3 -1
- package/dist/common/index.js +22 -22
- package/dist/components/index.d.ts +228 -1
- package/dist/components/index.js +74 -5738
- package/dist/core-events/index.d.ts +18 -2
- package/dist/core-events/index.js +7 -1
- package/dist/core-server/index.d.ts +515 -14
- package/dist/core-server/index.js +4647 -4182
- package/dist/core-server/presets/common-manager.js +1570 -1272
- package/dist/core-server/presets/common-override-preset.js +9 -9
- package/dist/core-server/presets/common-preset.js +691 -38
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +9 -9
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +10 -10
- package/dist/csf/index.d.ts +9 -4
- package/dist/csf/index.js +50 -15
- package/dist/csf-tools/index.d.ts +47 -6
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +4 -4
- package/dist/instrumenter/index.js +1 -1
- package/dist/manager/globals-runtime.js +9230 -18109
- package/dist/manager/globals.d.ts +0 -4
- package/dist/manager/globals.js +1 -6
- package/dist/manager/runtime.js +13398 -11573
- package/dist/manager-api/index.d.ts +513 -5
- package/dist/manager-api/index.js +364 -90
- package/dist/manager-errors.d.ts +501 -0
- package/dist/node-logger/index.d.ts +1 -1
- package/dist/node-logger/index.js +1136 -662
- package/dist/preview/globals.js +1 -1
- package/dist/preview/runtime.js +12103 -21579
- package/dist/preview-api/index.d.ts +3 -3
- package/dist/preview-api/index.js +10 -10
- package/dist/preview-errors.d.ts +501 -0
- package/dist/router/index.d.ts +668 -10
- package/dist/router/index.js +2 -2
- package/dist/server-errors.d.ts +501 -0
- package/dist/server-errors.js +10 -10
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +23 -25
- package/dist/test/index.js +1874 -4024
- package/dist/theming/index.d.ts +2 -2
- package/dist/theming/index.js +6 -6
- package/dist/types/index.d.ts +553 -16
- package/dist/viewport/index.d.ts +36 -4
- package/dist/viewport/index.js +1 -1
- package/package.json +9 -46
- package/dist/_browser-chunks/Color-SFYJJKWL.js +0 -605
- package/dist/_browser-chunks/chunk-DHO2SA6L.js +0 -12
- package/dist/_browser-chunks/chunk-WPHPDNUA.js +0 -974
- package/dist/_node-chunks/chunk-32JYCD74.js +0 -80
- package/dist/_node-chunks/chunk-GE6I3YYG.js +0 -62
- package/dist/_node-chunks/chunk-KXCNXWXI.js +0 -18
- package/dist/_node-chunks/chunk-LAUOYAOX.js +0 -87
- package/dist/_node-chunks/chunk-QJTT4OC2.js +0 -266
- package/dist/_node-chunks/chunk-V2ZF4DUD.js +0 -2377
- package/dist/_node-chunks/chunk-ZMV3WY6R.js +0 -9845
- package/dist/_node-chunks/default-browser-id-JNATP42X.js +0 -1719
|
@@ -0,0 +1,1569 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debounce,
|
|
3
|
+
getControlId
|
|
4
|
+
} from "./chunk-KSCAWCCE.js";
|
|
5
|
+
import "./chunk-G33S6YM3.js";
|
|
6
|
+
import "./chunk-QK3L5AXO.js";
|
|
7
|
+
import "./chunk-JJZMHC3A.js";
|
|
8
|
+
import {
|
|
9
|
+
__commonJS,
|
|
10
|
+
__name,
|
|
11
|
+
__toESM
|
|
12
|
+
} from "./chunk-MM7DTO55.js";
|
|
13
|
+
|
|
14
|
+
// ../node_modules/color-name/index.js
|
|
15
|
+
var require_color_name = __commonJS({
|
|
16
|
+
"../node_modules/color-name/index.js"(exports, module) {
|
|
17
|
+
"use strict";
|
|
18
|
+
module.exports = {
|
|
19
|
+
"aliceblue": [240, 248, 255],
|
|
20
|
+
"antiquewhite": [250, 235, 215],
|
|
21
|
+
"aqua": [0, 255, 255],
|
|
22
|
+
"aquamarine": [127, 255, 212],
|
|
23
|
+
"azure": [240, 255, 255],
|
|
24
|
+
"beige": [245, 245, 220],
|
|
25
|
+
"bisque": [255, 228, 196],
|
|
26
|
+
"black": [0, 0, 0],
|
|
27
|
+
"blanchedalmond": [255, 235, 205],
|
|
28
|
+
"blue": [0, 0, 255],
|
|
29
|
+
"blueviolet": [138, 43, 226],
|
|
30
|
+
"brown": [165, 42, 42],
|
|
31
|
+
"burlywood": [222, 184, 135],
|
|
32
|
+
"cadetblue": [95, 158, 160],
|
|
33
|
+
"chartreuse": [127, 255, 0],
|
|
34
|
+
"chocolate": [210, 105, 30],
|
|
35
|
+
"coral": [255, 127, 80],
|
|
36
|
+
"cornflowerblue": [100, 149, 237],
|
|
37
|
+
"cornsilk": [255, 248, 220],
|
|
38
|
+
"crimson": [220, 20, 60],
|
|
39
|
+
"cyan": [0, 255, 255],
|
|
40
|
+
"darkblue": [0, 0, 139],
|
|
41
|
+
"darkcyan": [0, 139, 139],
|
|
42
|
+
"darkgoldenrod": [184, 134, 11],
|
|
43
|
+
"darkgray": [169, 169, 169],
|
|
44
|
+
"darkgreen": [0, 100, 0],
|
|
45
|
+
"darkgrey": [169, 169, 169],
|
|
46
|
+
"darkkhaki": [189, 183, 107],
|
|
47
|
+
"darkmagenta": [139, 0, 139],
|
|
48
|
+
"darkolivegreen": [85, 107, 47],
|
|
49
|
+
"darkorange": [255, 140, 0],
|
|
50
|
+
"darkorchid": [153, 50, 204],
|
|
51
|
+
"darkred": [139, 0, 0],
|
|
52
|
+
"darksalmon": [233, 150, 122],
|
|
53
|
+
"darkseagreen": [143, 188, 143],
|
|
54
|
+
"darkslateblue": [72, 61, 139],
|
|
55
|
+
"darkslategray": [47, 79, 79],
|
|
56
|
+
"darkslategrey": [47, 79, 79],
|
|
57
|
+
"darkturquoise": [0, 206, 209],
|
|
58
|
+
"darkviolet": [148, 0, 211],
|
|
59
|
+
"deeppink": [255, 20, 147],
|
|
60
|
+
"deepskyblue": [0, 191, 255],
|
|
61
|
+
"dimgray": [105, 105, 105],
|
|
62
|
+
"dimgrey": [105, 105, 105],
|
|
63
|
+
"dodgerblue": [30, 144, 255],
|
|
64
|
+
"firebrick": [178, 34, 34],
|
|
65
|
+
"floralwhite": [255, 250, 240],
|
|
66
|
+
"forestgreen": [34, 139, 34],
|
|
67
|
+
"fuchsia": [255, 0, 255],
|
|
68
|
+
"gainsboro": [220, 220, 220],
|
|
69
|
+
"ghostwhite": [248, 248, 255],
|
|
70
|
+
"gold": [255, 215, 0],
|
|
71
|
+
"goldenrod": [218, 165, 32],
|
|
72
|
+
"gray": [128, 128, 128],
|
|
73
|
+
"green": [0, 128, 0],
|
|
74
|
+
"greenyellow": [173, 255, 47],
|
|
75
|
+
"grey": [128, 128, 128],
|
|
76
|
+
"honeydew": [240, 255, 240],
|
|
77
|
+
"hotpink": [255, 105, 180],
|
|
78
|
+
"indianred": [205, 92, 92],
|
|
79
|
+
"indigo": [75, 0, 130],
|
|
80
|
+
"ivory": [255, 255, 240],
|
|
81
|
+
"khaki": [240, 230, 140],
|
|
82
|
+
"lavender": [230, 230, 250],
|
|
83
|
+
"lavenderblush": [255, 240, 245],
|
|
84
|
+
"lawngreen": [124, 252, 0],
|
|
85
|
+
"lemonchiffon": [255, 250, 205],
|
|
86
|
+
"lightblue": [173, 216, 230],
|
|
87
|
+
"lightcoral": [240, 128, 128],
|
|
88
|
+
"lightcyan": [224, 255, 255],
|
|
89
|
+
"lightgoldenrodyellow": [250, 250, 210],
|
|
90
|
+
"lightgray": [211, 211, 211],
|
|
91
|
+
"lightgreen": [144, 238, 144],
|
|
92
|
+
"lightgrey": [211, 211, 211],
|
|
93
|
+
"lightpink": [255, 182, 193],
|
|
94
|
+
"lightsalmon": [255, 160, 122],
|
|
95
|
+
"lightseagreen": [32, 178, 170],
|
|
96
|
+
"lightskyblue": [135, 206, 250],
|
|
97
|
+
"lightslategray": [119, 136, 153],
|
|
98
|
+
"lightslategrey": [119, 136, 153],
|
|
99
|
+
"lightsteelblue": [176, 196, 222],
|
|
100
|
+
"lightyellow": [255, 255, 224],
|
|
101
|
+
"lime": [0, 255, 0],
|
|
102
|
+
"limegreen": [50, 205, 50],
|
|
103
|
+
"linen": [250, 240, 230],
|
|
104
|
+
"magenta": [255, 0, 255],
|
|
105
|
+
"maroon": [128, 0, 0],
|
|
106
|
+
"mediumaquamarine": [102, 205, 170],
|
|
107
|
+
"mediumblue": [0, 0, 205],
|
|
108
|
+
"mediumorchid": [186, 85, 211],
|
|
109
|
+
"mediumpurple": [147, 112, 219],
|
|
110
|
+
"mediumseagreen": [60, 179, 113],
|
|
111
|
+
"mediumslateblue": [123, 104, 238],
|
|
112
|
+
"mediumspringgreen": [0, 250, 154],
|
|
113
|
+
"mediumturquoise": [72, 209, 204],
|
|
114
|
+
"mediumvioletred": [199, 21, 133],
|
|
115
|
+
"midnightblue": [25, 25, 112],
|
|
116
|
+
"mintcream": [245, 255, 250],
|
|
117
|
+
"mistyrose": [255, 228, 225],
|
|
118
|
+
"moccasin": [255, 228, 181],
|
|
119
|
+
"navajowhite": [255, 222, 173],
|
|
120
|
+
"navy": [0, 0, 128],
|
|
121
|
+
"oldlace": [253, 245, 230],
|
|
122
|
+
"olive": [128, 128, 0],
|
|
123
|
+
"olivedrab": [107, 142, 35],
|
|
124
|
+
"orange": [255, 165, 0],
|
|
125
|
+
"orangered": [255, 69, 0],
|
|
126
|
+
"orchid": [218, 112, 214],
|
|
127
|
+
"palegoldenrod": [238, 232, 170],
|
|
128
|
+
"palegreen": [152, 251, 152],
|
|
129
|
+
"paleturquoise": [175, 238, 238],
|
|
130
|
+
"palevioletred": [219, 112, 147],
|
|
131
|
+
"papayawhip": [255, 239, 213],
|
|
132
|
+
"peachpuff": [255, 218, 185],
|
|
133
|
+
"peru": [205, 133, 63],
|
|
134
|
+
"pink": [255, 192, 203],
|
|
135
|
+
"plum": [221, 160, 221],
|
|
136
|
+
"powderblue": [176, 224, 230],
|
|
137
|
+
"purple": [128, 0, 128],
|
|
138
|
+
"rebeccapurple": [102, 51, 153],
|
|
139
|
+
"red": [255, 0, 0],
|
|
140
|
+
"rosybrown": [188, 143, 143],
|
|
141
|
+
"royalblue": [65, 105, 225],
|
|
142
|
+
"saddlebrown": [139, 69, 19],
|
|
143
|
+
"salmon": [250, 128, 114],
|
|
144
|
+
"sandybrown": [244, 164, 96],
|
|
145
|
+
"seagreen": [46, 139, 87],
|
|
146
|
+
"seashell": [255, 245, 238],
|
|
147
|
+
"sienna": [160, 82, 45],
|
|
148
|
+
"silver": [192, 192, 192],
|
|
149
|
+
"skyblue": [135, 206, 235],
|
|
150
|
+
"slateblue": [106, 90, 205],
|
|
151
|
+
"slategray": [112, 128, 144],
|
|
152
|
+
"slategrey": [112, 128, 144],
|
|
153
|
+
"snow": [255, 250, 250],
|
|
154
|
+
"springgreen": [0, 255, 127],
|
|
155
|
+
"steelblue": [70, 130, 180],
|
|
156
|
+
"tan": [210, 180, 140],
|
|
157
|
+
"teal": [0, 128, 128],
|
|
158
|
+
"thistle": [216, 191, 216],
|
|
159
|
+
"tomato": [255, 99, 71],
|
|
160
|
+
"turquoise": [64, 224, 208],
|
|
161
|
+
"violet": [238, 130, 238],
|
|
162
|
+
"wheat": [245, 222, 179],
|
|
163
|
+
"white": [255, 255, 255],
|
|
164
|
+
"whitesmoke": [245, 245, 245],
|
|
165
|
+
"yellow": [255, 255, 0],
|
|
166
|
+
"yellowgreen": [154, 205, 50]
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ../node_modules/color-convert/conversions.js
|
|
172
|
+
var require_conversions = __commonJS({
|
|
173
|
+
"../node_modules/color-convert/conversions.js"(exports, module) {
|
|
174
|
+
var cssKeywords = require_color_name();
|
|
175
|
+
var reverseKeywords = {};
|
|
176
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
177
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
178
|
+
}
|
|
179
|
+
var convert2 = {
|
|
180
|
+
rgb: { channels: 3, labels: "rgb" },
|
|
181
|
+
hsl: { channels: 3, labels: "hsl" },
|
|
182
|
+
hsv: { channels: 3, labels: "hsv" },
|
|
183
|
+
hwb: { channels: 3, labels: "hwb" },
|
|
184
|
+
cmyk: { channels: 4, labels: "cmyk" },
|
|
185
|
+
xyz: { channels: 3, labels: "xyz" },
|
|
186
|
+
lab: { channels: 3, labels: "lab" },
|
|
187
|
+
lch: { channels: 3, labels: "lch" },
|
|
188
|
+
hex: { channels: 1, labels: ["hex"] },
|
|
189
|
+
keyword: { channels: 1, labels: ["keyword"] },
|
|
190
|
+
ansi16: { channels: 1, labels: ["ansi16"] },
|
|
191
|
+
ansi256: { channels: 1, labels: ["ansi256"] },
|
|
192
|
+
hcg: { channels: 3, labels: ["h", "c", "g"] },
|
|
193
|
+
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
194
|
+
gray: { channels: 1, labels: ["gray"] }
|
|
195
|
+
};
|
|
196
|
+
module.exports = convert2;
|
|
197
|
+
for (const model of Object.keys(convert2)) {
|
|
198
|
+
if (!("channels" in convert2[model])) {
|
|
199
|
+
throw new Error("missing channels property: " + model);
|
|
200
|
+
}
|
|
201
|
+
if (!("labels" in convert2[model])) {
|
|
202
|
+
throw new Error("missing channel labels property: " + model);
|
|
203
|
+
}
|
|
204
|
+
if (convert2[model].labels.length !== convert2[model].channels) {
|
|
205
|
+
throw new Error("channel and label counts mismatch: " + model);
|
|
206
|
+
}
|
|
207
|
+
const { channels, labels } = convert2[model];
|
|
208
|
+
delete convert2[model].channels;
|
|
209
|
+
delete convert2[model].labels;
|
|
210
|
+
Object.defineProperty(convert2[model], "channels", { value: channels });
|
|
211
|
+
Object.defineProperty(convert2[model], "labels", { value: labels });
|
|
212
|
+
}
|
|
213
|
+
convert2.rgb.hsl = function(rgb) {
|
|
214
|
+
const r2 = rgb[0] / 255;
|
|
215
|
+
const g2 = rgb[1] / 255;
|
|
216
|
+
const b2 = rgb[2] / 255;
|
|
217
|
+
const min = Math.min(r2, g2, b2);
|
|
218
|
+
const max = Math.max(r2, g2, b2);
|
|
219
|
+
const delta = max - min;
|
|
220
|
+
let h2;
|
|
221
|
+
let s2;
|
|
222
|
+
if (max === min) {
|
|
223
|
+
h2 = 0;
|
|
224
|
+
} else if (r2 === max) {
|
|
225
|
+
h2 = (g2 - b2) / delta;
|
|
226
|
+
} else if (g2 === max) {
|
|
227
|
+
h2 = 2 + (b2 - r2) / delta;
|
|
228
|
+
} else if (b2 === max) {
|
|
229
|
+
h2 = 4 + (r2 - g2) / delta;
|
|
230
|
+
}
|
|
231
|
+
h2 = Math.min(h2 * 60, 360);
|
|
232
|
+
if (h2 < 0) {
|
|
233
|
+
h2 += 360;
|
|
234
|
+
}
|
|
235
|
+
const l2 = (min + max) / 2;
|
|
236
|
+
if (max === min) {
|
|
237
|
+
s2 = 0;
|
|
238
|
+
} else if (l2 <= 0.5) {
|
|
239
|
+
s2 = delta / (max + min);
|
|
240
|
+
} else {
|
|
241
|
+
s2 = delta / (2 - max - min);
|
|
242
|
+
}
|
|
243
|
+
return [h2, s2 * 100, l2 * 100];
|
|
244
|
+
};
|
|
245
|
+
convert2.rgb.hsv = function(rgb) {
|
|
246
|
+
let rdif;
|
|
247
|
+
let gdif;
|
|
248
|
+
let bdif;
|
|
249
|
+
let h2;
|
|
250
|
+
let s2;
|
|
251
|
+
const r2 = rgb[0] / 255;
|
|
252
|
+
const g2 = rgb[1] / 255;
|
|
253
|
+
const b2 = rgb[2] / 255;
|
|
254
|
+
const v2 = Math.max(r2, g2, b2);
|
|
255
|
+
const diff = v2 - Math.min(r2, g2, b2);
|
|
256
|
+
const diffc = /* @__PURE__ */ __name(function(c2) {
|
|
257
|
+
return (v2 - c2) / 6 / diff + 1 / 2;
|
|
258
|
+
}, "diffc");
|
|
259
|
+
if (diff === 0) {
|
|
260
|
+
h2 = 0;
|
|
261
|
+
s2 = 0;
|
|
262
|
+
} else {
|
|
263
|
+
s2 = diff / v2;
|
|
264
|
+
rdif = diffc(r2);
|
|
265
|
+
gdif = diffc(g2);
|
|
266
|
+
bdif = diffc(b2);
|
|
267
|
+
if (r2 === v2) {
|
|
268
|
+
h2 = bdif - gdif;
|
|
269
|
+
} else if (g2 === v2) {
|
|
270
|
+
h2 = 1 / 3 + rdif - bdif;
|
|
271
|
+
} else if (b2 === v2) {
|
|
272
|
+
h2 = 2 / 3 + gdif - rdif;
|
|
273
|
+
}
|
|
274
|
+
if (h2 < 0) {
|
|
275
|
+
h2 += 1;
|
|
276
|
+
} else if (h2 > 1) {
|
|
277
|
+
h2 -= 1;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return [
|
|
281
|
+
h2 * 360,
|
|
282
|
+
s2 * 100,
|
|
283
|
+
v2 * 100
|
|
284
|
+
];
|
|
285
|
+
};
|
|
286
|
+
convert2.rgb.hwb = function(rgb) {
|
|
287
|
+
const r2 = rgb[0];
|
|
288
|
+
const g2 = rgb[1];
|
|
289
|
+
let b2 = rgb[2];
|
|
290
|
+
const h2 = convert2.rgb.hsl(rgb)[0];
|
|
291
|
+
const w2 = 1 / 255 * Math.min(r2, Math.min(g2, b2));
|
|
292
|
+
b2 = 1 - 1 / 255 * Math.max(r2, Math.max(g2, b2));
|
|
293
|
+
return [h2, w2 * 100, b2 * 100];
|
|
294
|
+
};
|
|
295
|
+
convert2.rgb.cmyk = function(rgb) {
|
|
296
|
+
const r2 = rgb[0] / 255;
|
|
297
|
+
const g2 = rgb[1] / 255;
|
|
298
|
+
const b2 = rgb[2] / 255;
|
|
299
|
+
const k2 = Math.min(1 - r2, 1 - g2, 1 - b2);
|
|
300
|
+
const c2 = (1 - r2 - k2) / (1 - k2) || 0;
|
|
301
|
+
const m2 = (1 - g2 - k2) / (1 - k2) || 0;
|
|
302
|
+
const y2 = (1 - b2 - k2) / (1 - k2) || 0;
|
|
303
|
+
return [c2 * 100, m2 * 100, y2 * 100, k2 * 100];
|
|
304
|
+
};
|
|
305
|
+
function comparativeDistance(x2, y2) {
|
|
306
|
+
return (x2[0] - y2[0]) ** 2 + (x2[1] - y2[1]) ** 2 + (x2[2] - y2[2]) ** 2;
|
|
307
|
+
}
|
|
308
|
+
__name(comparativeDistance, "comparativeDistance");
|
|
309
|
+
convert2.rgb.keyword = function(rgb) {
|
|
310
|
+
const reversed = reverseKeywords[rgb];
|
|
311
|
+
if (reversed) {
|
|
312
|
+
return reversed;
|
|
313
|
+
}
|
|
314
|
+
let currentClosestDistance = Infinity;
|
|
315
|
+
let currentClosestKeyword;
|
|
316
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
317
|
+
const value = cssKeywords[keyword];
|
|
318
|
+
const distance = comparativeDistance(rgb, value);
|
|
319
|
+
if (distance < currentClosestDistance) {
|
|
320
|
+
currentClosestDistance = distance;
|
|
321
|
+
currentClosestKeyword = keyword;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return currentClosestKeyword;
|
|
325
|
+
};
|
|
326
|
+
convert2.keyword.rgb = function(keyword) {
|
|
327
|
+
return cssKeywords[keyword];
|
|
328
|
+
};
|
|
329
|
+
convert2.rgb.xyz = function(rgb) {
|
|
330
|
+
let r2 = rgb[0] / 255;
|
|
331
|
+
let g2 = rgb[1] / 255;
|
|
332
|
+
let b2 = rgb[2] / 255;
|
|
333
|
+
r2 = r2 > 0.04045 ? ((r2 + 0.055) / 1.055) ** 2.4 : r2 / 12.92;
|
|
334
|
+
g2 = g2 > 0.04045 ? ((g2 + 0.055) / 1.055) ** 2.4 : g2 / 12.92;
|
|
335
|
+
b2 = b2 > 0.04045 ? ((b2 + 0.055) / 1.055) ** 2.4 : b2 / 12.92;
|
|
336
|
+
const x2 = r2 * 0.4124 + g2 * 0.3576 + b2 * 0.1805;
|
|
337
|
+
const y2 = r2 * 0.2126 + g2 * 0.7152 + b2 * 0.0722;
|
|
338
|
+
const z2 = r2 * 0.0193 + g2 * 0.1192 + b2 * 0.9505;
|
|
339
|
+
return [x2 * 100, y2 * 100, z2 * 100];
|
|
340
|
+
};
|
|
341
|
+
convert2.rgb.lab = function(rgb) {
|
|
342
|
+
const xyz = convert2.rgb.xyz(rgb);
|
|
343
|
+
let x2 = xyz[0];
|
|
344
|
+
let y2 = xyz[1];
|
|
345
|
+
let z2 = xyz[2];
|
|
346
|
+
x2 /= 95.047;
|
|
347
|
+
y2 /= 100;
|
|
348
|
+
z2 /= 108.883;
|
|
349
|
+
x2 = x2 > 8856e-6 ? x2 ** (1 / 3) : 7.787 * x2 + 16 / 116;
|
|
350
|
+
y2 = y2 > 8856e-6 ? y2 ** (1 / 3) : 7.787 * y2 + 16 / 116;
|
|
351
|
+
z2 = z2 > 8856e-6 ? z2 ** (1 / 3) : 7.787 * z2 + 16 / 116;
|
|
352
|
+
const l2 = 116 * y2 - 16;
|
|
353
|
+
const a2 = 500 * (x2 - y2);
|
|
354
|
+
const b2 = 200 * (y2 - z2);
|
|
355
|
+
return [l2, a2, b2];
|
|
356
|
+
};
|
|
357
|
+
convert2.hsl.rgb = function(hsl) {
|
|
358
|
+
const h2 = hsl[0] / 360;
|
|
359
|
+
const s2 = hsl[1] / 100;
|
|
360
|
+
const l2 = hsl[2] / 100;
|
|
361
|
+
let t2;
|
|
362
|
+
let t3;
|
|
363
|
+
let val;
|
|
364
|
+
if (s2 === 0) {
|
|
365
|
+
val = l2 * 255;
|
|
366
|
+
return [val, val, val];
|
|
367
|
+
}
|
|
368
|
+
if (l2 < 0.5) {
|
|
369
|
+
t2 = l2 * (1 + s2);
|
|
370
|
+
} else {
|
|
371
|
+
t2 = l2 + s2 - l2 * s2;
|
|
372
|
+
}
|
|
373
|
+
const t1 = 2 * l2 - t2;
|
|
374
|
+
const rgb = [0, 0, 0];
|
|
375
|
+
for (let i2 = 0; i2 < 3; i2++) {
|
|
376
|
+
t3 = h2 + 1 / 3 * -(i2 - 1);
|
|
377
|
+
if (t3 < 0) {
|
|
378
|
+
t3++;
|
|
379
|
+
}
|
|
380
|
+
if (t3 > 1) {
|
|
381
|
+
t3--;
|
|
382
|
+
}
|
|
383
|
+
if (6 * t3 < 1) {
|
|
384
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
385
|
+
} else if (2 * t3 < 1) {
|
|
386
|
+
val = t2;
|
|
387
|
+
} else if (3 * t3 < 2) {
|
|
388
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
389
|
+
} else {
|
|
390
|
+
val = t1;
|
|
391
|
+
}
|
|
392
|
+
rgb[i2] = val * 255;
|
|
393
|
+
}
|
|
394
|
+
return rgb;
|
|
395
|
+
};
|
|
396
|
+
convert2.hsl.hsv = function(hsl) {
|
|
397
|
+
const h2 = hsl[0];
|
|
398
|
+
let s2 = hsl[1] / 100;
|
|
399
|
+
let l2 = hsl[2] / 100;
|
|
400
|
+
let smin = s2;
|
|
401
|
+
const lmin = Math.max(l2, 0.01);
|
|
402
|
+
l2 *= 2;
|
|
403
|
+
s2 *= l2 <= 1 ? l2 : 2 - l2;
|
|
404
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
405
|
+
const v2 = (l2 + s2) / 2;
|
|
406
|
+
const sv = l2 === 0 ? 2 * smin / (lmin + smin) : 2 * s2 / (l2 + s2);
|
|
407
|
+
return [h2, sv * 100, v2 * 100];
|
|
408
|
+
};
|
|
409
|
+
convert2.hsv.rgb = function(hsv) {
|
|
410
|
+
const h2 = hsv[0] / 60;
|
|
411
|
+
const s2 = hsv[1] / 100;
|
|
412
|
+
let v2 = hsv[2] / 100;
|
|
413
|
+
const hi = Math.floor(h2) % 6;
|
|
414
|
+
const f2 = h2 - Math.floor(h2);
|
|
415
|
+
const p2 = 255 * v2 * (1 - s2);
|
|
416
|
+
const q2 = 255 * v2 * (1 - s2 * f2);
|
|
417
|
+
const t2 = 255 * v2 * (1 - s2 * (1 - f2));
|
|
418
|
+
v2 *= 255;
|
|
419
|
+
switch (hi) {
|
|
420
|
+
case 0:
|
|
421
|
+
return [v2, t2, p2];
|
|
422
|
+
case 1:
|
|
423
|
+
return [q2, v2, p2];
|
|
424
|
+
case 2:
|
|
425
|
+
return [p2, v2, t2];
|
|
426
|
+
case 3:
|
|
427
|
+
return [p2, q2, v2];
|
|
428
|
+
case 4:
|
|
429
|
+
return [t2, p2, v2];
|
|
430
|
+
case 5:
|
|
431
|
+
return [v2, p2, q2];
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
convert2.hsv.hsl = function(hsv) {
|
|
435
|
+
const h2 = hsv[0];
|
|
436
|
+
const s2 = hsv[1] / 100;
|
|
437
|
+
const v2 = hsv[2] / 100;
|
|
438
|
+
const vmin = Math.max(v2, 0.01);
|
|
439
|
+
let sl;
|
|
440
|
+
let l2;
|
|
441
|
+
l2 = (2 - s2) * v2;
|
|
442
|
+
const lmin = (2 - s2) * vmin;
|
|
443
|
+
sl = s2 * vmin;
|
|
444
|
+
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
445
|
+
sl = sl || 0;
|
|
446
|
+
l2 /= 2;
|
|
447
|
+
return [h2, sl * 100, l2 * 100];
|
|
448
|
+
};
|
|
449
|
+
convert2.hwb.rgb = function(hwb) {
|
|
450
|
+
const h2 = hwb[0] / 360;
|
|
451
|
+
let wh = hwb[1] / 100;
|
|
452
|
+
let bl = hwb[2] / 100;
|
|
453
|
+
const ratio = wh + bl;
|
|
454
|
+
let f2;
|
|
455
|
+
if (ratio > 1) {
|
|
456
|
+
wh /= ratio;
|
|
457
|
+
bl /= ratio;
|
|
458
|
+
}
|
|
459
|
+
const i2 = Math.floor(6 * h2);
|
|
460
|
+
const v2 = 1 - bl;
|
|
461
|
+
f2 = 6 * h2 - i2;
|
|
462
|
+
if ((i2 & 1) !== 0) {
|
|
463
|
+
f2 = 1 - f2;
|
|
464
|
+
}
|
|
465
|
+
const n2 = wh + f2 * (v2 - wh);
|
|
466
|
+
let r2;
|
|
467
|
+
let g2;
|
|
468
|
+
let b2;
|
|
469
|
+
switch (i2) {
|
|
470
|
+
default:
|
|
471
|
+
case 6:
|
|
472
|
+
case 0:
|
|
473
|
+
r2 = v2;
|
|
474
|
+
g2 = n2;
|
|
475
|
+
b2 = wh;
|
|
476
|
+
break;
|
|
477
|
+
case 1:
|
|
478
|
+
r2 = n2;
|
|
479
|
+
g2 = v2;
|
|
480
|
+
b2 = wh;
|
|
481
|
+
break;
|
|
482
|
+
case 2:
|
|
483
|
+
r2 = wh;
|
|
484
|
+
g2 = v2;
|
|
485
|
+
b2 = n2;
|
|
486
|
+
break;
|
|
487
|
+
case 3:
|
|
488
|
+
r2 = wh;
|
|
489
|
+
g2 = n2;
|
|
490
|
+
b2 = v2;
|
|
491
|
+
break;
|
|
492
|
+
case 4:
|
|
493
|
+
r2 = n2;
|
|
494
|
+
g2 = wh;
|
|
495
|
+
b2 = v2;
|
|
496
|
+
break;
|
|
497
|
+
case 5:
|
|
498
|
+
r2 = v2;
|
|
499
|
+
g2 = wh;
|
|
500
|
+
b2 = n2;
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
return [r2 * 255, g2 * 255, b2 * 255];
|
|
504
|
+
};
|
|
505
|
+
convert2.cmyk.rgb = function(cmyk) {
|
|
506
|
+
const c2 = cmyk[0] / 100;
|
|
507
|
+
const m2 = cmyk[1] / 100;
|
|
508
|
+
const y2 = cmyk[2] / 100;
|
|
509
|
+
const k2 = cmyk[3] / 100;
|
|
510
|
+
const r2 = 1 - Math.min(1, c2 * (1 - k2) + k2);
|
|
511
|
+
const g2 = 1 - Math.min(1, m2 * (1 - k2) + k2);
|
|
512
|
+
const b2 = 1 - Math.min(1, y2 * (1 - k2) + k2);
|
|
513
|
+
return [r2 * 255, g2 * 255, b2 * 255];
|
|
514
|
+
};
|
|
515
|
+
convert2.xyz.rgb = function(xyz) {
|
|
516
|
+
const x2 = xyz[0] / 100;
|
|
517
|
+
const y2 = xyz[1] / 100;
|
|
518
|
+
const z2 = xyz[2] / 100;
|
|
519
|
+
let r2;
|
|
520
|
+
let g2;
|
|
521
|
+
let b2;
|
|
522
|
+
r2 = x2 * 3.2406 + y2 * -1.5372 + z2 * -0.4986;
|
|
523
|
+
g2 = x2 * -0.9689 + y2 * 1.8758 + z2 * 0.0415;
|
|
524
|
+
b2 = x2 * 0.0557 + y2 * -0.204 + z2 * 1.057;
|
|
525
|
+
r2 = r2 > 31308e-7 ? 1.055 * r2 ** (1 / 2.4) - 0.055 : r2 * 12.92;
|
|
526
|
+
g2 = g2 > 31308e-7 ? 1.055 * g2 ** (1 / 2.4) - 0.055 : g2 * 12.92;
|
|
527
|
+
b2 = b2 > 31308e-7 ? 1.055 * b2 ** (1 / 2.4) - 0.055 : b2 * 12.92;
|
|
528
|
+
r2 = Math.min(Math.max(0, r2), 1);
|
|
529
|
+
g2 = Math.min(Math.max(0, g2), 1);
|
|
530
|
+
b2 = Math.min(Math.max(0, b2), 1);
|
|
531
|
+
return [r2 * 255, g2 * 255, b2 * 255];
|
|
532
|
+
};
|
|
533
|
+
convert2.xyz.lab = function(xyz) {
|
|
534
|
+
let x2 = xyz[0];
|
|
535
|
+
let y2 = xyz[1];
|
|
536
|
+
let z2 = xyz[2];
|
|
537
|
+
x2 /= 95.047;
|
|
538
|
+
y2 /= 100;
|
|
539
|
+
z2 /= 108.883;
|
|
540
|
+
x2 = x2 > 8856e-6 ? x2 ** (1 / 3) : 7.787 * x2 + 16 / 116;
|
|
541
|
+
y2 = y2 > 8856e-6 ? y2 ** (1 / 3) : 7.787 * y2 + 16 / 116;
|
|
542
|
+
z2 = z2 > 8856e-6 ? z2 ** (1 / 3) : 7.787 * z2 + 16 / 116;
|
|
543
|
+
const l2 = 116 * y2 - 16;
|
|
544
|
+
const a2 = 500 * (x2 - y2);
|
|
545
|
+
const b2 = 200 * (y2 - z2);
|
|
546
|
+
return [l2, a2, b2];
|
|
547
|
+
};
|
|
548
|
+
convert2.lab.xyz = function(lab) {
|
|
549
|
+
const l2 = lab[0];
|
|
550
|
+
const a2 = lab[1];
|
|
551
|
+
const b2 = lab[2];
|
|
552
|
+
let x2;
|
|
553
|
+
let y2;
|
|
554
|
+
let z2;
|
|
555
|
+
y2 = (l2 + 16) / 116;
|
|
556
|
+
x2 = a2 / 500 + y2;
|
|
557
|
+
z2 = y2 - b2 / 200;
|
|
558
|
+
const y22 = y2 ** 3;
|
|
559
|
+
const x22 = x2 ** 3;
|
|
560
|
+
const z22 = z2 ** 3;
|
|
561
|
+
y2 = y22 > 8856e-6 ? y22 : (y2 - 16 / 116) / 7.787;
|
|
562
|
+
x2 = x22 > 8856e-6 ? x22 : (x2 - 16 / 116) / 7.787;
|
|
563
|
+
z2 = z22 > 8856e-6 ? z22 : (z2 - 16 / 116) / 7.787;
|
|
564
|
+
x2 *= 95.047;
|
|
565
|
+
y2 *= 100;
|
|
566
|
+
z2 *= 108.883;
|
|
567
|
+
return [x2, y2, z2];
|
|
568
|
+
};
|
|
569
|
+
convert2.lab.lch = function(lab) {
|
|
570
|
+
const l2 = lab[0];
|
|
571
|
+
const a2 = lab[1];
|
|
572
|
+
const b2 = lab[2];
|
|
573
|
+
let h2;
|
|
574
|
+
const hr = Math.atan2(b2, a2);
|
|
575
|
+
h2 = hr * 360 / 2 / Math.PI;
|
|
576
|
+
if (h2 < 0) {
|
|
577
|
+
h2 += 360;
|
|
578
|
+
}
|
|
579
|
+
const c2 = Math.sqrt(a2 * a2 + b2 * b2);
|
|
580
|
+
return [l2, c2, h2];
|
|
581
|
+
};
|
|
582
|
+
convert2.lch.lab = function(lch) {
|
|
583
|
+
const l2 = lch[0];
|
|
584
|
+
const c2 = lch[1];
|
|
585
|
+
const h2 = lch[2];
|
|
586
|
+
const hr = h2 / 360 * 2 * Math.PI;
|
|
587
|
+
const a2 = c2 * Math.cos(hr);
|
|
588
|
+
const b2 = c2 * Math.sin(hr);
|
|
589
|
+
return [l2, a2, b2];
|
|
590
|
+
};
|
|
591
|
+
convert2.rgb.ansi16 = function(args, saturation = null) {
|
|
592
|
+
const [r2, g2, b2] = args;
|
|
593
|
+
let value = saturation === null ? convert2.rgb.hsv(args)[2] : saturation;
|
|
594
|
+
value = Math.round(value / 50);
|
|
595
|
+
if (value === 0) {
|
|
596
|
+
return 30;
|
|
597
|
+
}
|
|
598
|
+
let ansi = 30 + (Math.round(b2 / 255) << 2 | Math.round(g2 / 255) << 1 | Math.round(r2 / 255));
|
|
599
|
+
if (value === 2) {
|
|
600
|
+
ansi += 60;
|
|
601
|
+
}
|
|
602
|
+
return ansi;
|
|
603
|
+
};
|
|
604
|
+
convert2.hsv.ansi16 = function(args) {
|
|
605
|
+
return convert2.rgb.ansi16(convert2.hsv.rgb(args), args[2]);
|
|
606
|
+
};
|
|
607
|
+
convert2.rgb.ansi256 = function(args) {
|
|
608
|
+
const r2 = args[0];
|
|
609
|
+
const g2 = args[1];
|
|
610
|
+
const b2 = args[2];
|
|
611
|
+
if (r2 === g2 && g2 === b2) {
|
|
612
|
+
if (r2 < 8) {
|
|
613
|
+
return 16;
|
|
614
|
+
}
|
|
615
|
+
if (r2 > 248) {
|
|
616
|
+
return 231;
|
|
617
|
+
}
|
|
618
|
+
return Math.round((r2 - 8) / 247 * 24) + 232;
|
|
619
|
+
}
|
|
620
|
+
const ansi = 16 + 36 * Math.round(r2 / 255 * 5) + 6 * Math.round(g2 / 255 * 5) + Math.round(b2 / 255 * 5);
|
|
621
|
+
return ansi;
|
|
622
|
+
};
|
|
623
|
+
convert2.ansi16.rgb = function(args) {
|
|
624
|
+
let color = args % 10;
|
|
625
|
+
if (color === 0 || color === 7) {
|
|
626
|
+
if (args > 50) {
|
|
627
|
+
color += 3.5;
|
|
628
|
+
}
|
|
629
|
+
color = color / 10.5 * 255;
|
|
630
|
+
return [color, color, color];
|
|
631
|
+
}
|
|
632
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
633
|
+
const r2 = (color & 1) * mult * 255;
|
|
634
|
+
const g2 = (color >> 1 & 1) * mult * 255;
|
|
635
|
+
const b2 = (color >> 2 & 1) * mult * 255;
|
|
636
|
+
return [r2, g2, b2];
|
|
637
|
+
};
|
|
638
|
+
convert2.ansi256.rgb = function(args) {
|
|
639
|
+
if (args >= 232) {
|
|
640
|
+
const c2 = (args - 232) * 10 + 8;
|
|
641
|
+
return [c2, c2, c2];
|
|
642
|
+
}
|
|
643
|
+
args -= 16;
|
|
644
|
+
let rem;
|
|
645
|
+
const r2 = Math.floor(args / 36) / 5 * 255;
|
|
646
|
+
const g2 = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
647
|
+
const b2 = rem % 6 / 5 * 255;
|
|
648
|
+
return [r2, g2, b2];
|
|
649
|
+
};
|
|
650
|
+
convert2.rgb.hex = function(args) {
|
|
651
|
+
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
652
|
+
const string = integer.toString(16).toUpperCase();
|
|
653
|
+
return "000000".substring(string.length) + string;
|
|
654
|
+
};
|
|
655
|
+
convert2.hex.rgb = function(args) {
|
|
656
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
657
|
+
if (!match) {
|
|
658
|
+
return [0, 0, 0];
|
|
659
|
+
}
|
|
660
|
+
let colorString = match[0];
|
|
661
|
+
if (match[0].length === 3) {
|
|
662
|
+
colorString = colorString.split("").map((char) => {
|
|
663
|
+
return char + char;
|
|
664
|
+
}).join("");
|
|
665
|
+
}
|
|
666
|
+
const integer = parseInt(colorString, 16);
|
|
667
|
+
const r2 = integer >> 16 & 255;
|
|
668
|
+
const g2 = integer >> 8 & 255;
|
|
669
|
+
const b2 = integer & 255;
|
|
670
|
+
return [r2, g2, b2];
|
|
671
|
+
};
|
|
672
|
+
convert2.rgb.hcg = function(rgb) {
|
|
673
|
+
const r2 = rgb[0] / 255;
|
|
674
|
+
const g2 = rgb[1] / 255;
|
|
675
|
+
const b2 = rgb[2] / 255;
|
|
676
|
+
const max = Math.max(Math.max(r2, g2), b2);
|
|
677
|
+
const min = Math.min(Math.min(r2, g2), b2);
|
|
678
|
+
const chroma = max - min;
|
|
679
|
+
let grayscale;
|
|
680
|
+
let hue;
|
|
681
|
+
if (chroma < 1) {
|
|
682
|
+
grayscale = min / (1 - chroma);
|
|
683
|
+
} else {
|
|
684
|
+
grayscale = 0;
|
|
685
|
+
}
|
|
686
|
+
if (chroma <= 0) {
|
|
687
|
+
hue = 0;
|
|
688
|
+
} else if (max === r2) {
|
|
689
|
+
hue = (g2 - b2) / chroma % 6;
|
|
690
|
+
} else if (max === g2) {
|
|
691
|
+
hue = 2 + (b2 - r2) / chroma;
|
|
692
|
+
} else {
|
|
693
|
+
hue = 4 + (r2 - g2) / chroma;
|
|
694
|
+
}
|
|
695
|
+
hue /= 6;
|
|
696
|
+
hue %= 1;
|
|
697
|
+
return [hue * 360, chroma * 100, grayscale * 100];
|
|
698
|
+
};
|
|
699
|
+
convert2.hsl.hcg = function(hsl) {
|
|
700
|
+
const s2 = hsl[1] / 100;
|
|
701
|
+
const l2 = hsl[2] / 100;
|
|
702
|
+
const c2 = l2 < 0.5 ? 2 * s2 * l2 : 2 * s2 * (1 - l2);
|
|
703
|
+
let f2 = 0;
|
|
704
|
+
if (c2 < 1) {
|
|
705
|
+
f2 = (l2 - 0.5 * c2) / (1 - c2);
|
|
706
|
+
}
|
|
707
|
+
return [hsl[0], c2 * 100, f2 * 100];
|
|
708
|
+
};
|
|
709
|
+
convert2.hsv.hcg = function(hsv) {
|
|
710
|
+
const s2 = hsv[1] / 100;
|
|
711
|
+
const v2 = hsv[2] / 100;
|
|
712
|
+
const c2 = s2 * v2;
|
|
713
|
+
let f2 = 0;
|
|
714
|
+
if (c2 < 1) {
|
|
715
|
+
f2 = (v2 - c2) / (1 - c2);
|
|
716
|
+
}
|
|
717
|
+
return [hsv[0], c2 * 100, f2 * 100];
|
|
718
|
+
};
|
|
719
|
+
convert2.hcg.rgb = function(hcg) {
|
|
720
|
+
const h2 = hcg[0] / 360;
|
|
721
|
+
const c2 = hcg[1] / 100;
|
|
722
|
+
const g2 = hcg[2] / 100;
|
|
723
|
+
if (c2 === 0) {
|
|
724
|
+
return [g2 * 255, g2 * 255, g2 * 255];
|
|
725
|
+
}
|
|
726
|
+
const pure = [0, 0, 0];
|
|
727
|
+
const hi = h2 % 1 * 6;
|
|
728
|
+
const v2 = hi % 1;
|
|
729
|
+
const w2 = 1 - v2;
|
|
730
|
+
let mg = 0;
|
|
731
|
+
switch (Math.floor(hi)) {
|
|
732
|
+
case 0:
|
|
733
|
+
pure[0] = 1;
|
|
734
|
+
pure[1] = v2;
|
|
735
|
+
pure[2] = 0;
|
|
736
|
+
break;
|
|
737
|
+
case 1:
|
|
738
|
+
pure[0] = w2;
|
|
739
|
+
pure[1] = 1;
|
|
740
|
+
pure[2] = 0;
|
|
741
|
+
break;
|
|
742
|
+
case 2:
|
|
743
|
+
pure[0] = 0;
|
|
744
|
+
pure[1] = 1;
|
|
745
|
+
pure[2] = v2;
|
|
746
|
+
break;
|
|
747
|
+
case 3:
|
|
748
|
+
pure[0] = 0;
|
|
749
|
+
pure[1] = w2;
|
|
750
|
+
pure[2] = 1;
|
|
751
|
+
break;
|
|
752
|
+
case 4:
|
|
753
|
+
pure[0] = v2;
|
|
754
|
+
pure[1] = 0;
|
|
755
|
+
pure[2] = 1;
|
|
756
|
+
break;
|
|
757
|
+
default:
|
|
758
|
+
pure[0] = 1;
|
|
759
|
+
pure[1] = 0;
|
|
760
|
+
pure[2] = w2;
|
|
761
|
+
}
|
|
762
|
+
mg = (1 - c2) * g2;
|
|
763
|
+
return [
|
|
764
|
+
(c2 * pure[0] + mg) * 255,
|
|
765
|
+
(c2 * pure[1] + mg) * 255,
|
|
766
|
+
(c2 * pure[2] + mg) * 255
|
|
767
|
+
];
|
|
768
|
+
};
|
|
769
|
+
convert2.hcg.hsv = function(hcg) {
|
|
770
|
+
const c2 = hcg[1] / 100;
|
|
771
|
+
const g2 = hcg[2] / 100;
|
|
772
|
+
const v2 = c2 + g2 * (1 - c2);
|
|
773
|
+
let f2 = 0;
|
|
774
|
+
if (v2 > 0) {
|
|
775
|
+
f2 = c2 / v2;
|
|
776
|
+
}
|
|
777
|
+
return [hcg[0], f2 * 100, v2 * 100];
|
|
778
|
+
};
|
|
779
|
+
convert2.hcg.hsl = function(hcg) {
|
|
780
|
+
const c2 = hcg[1] / 100;
|
|
781
|
+
const g2 = hcg[2] / 100;
|
|
782
|
+
const l2 = g2 * (1 - c2) + 0.5 * c2;
|
|
783
|
+
let s2 = 0;
|
|
784
|
+
if (l2 > 0 && l2 < 0.5) {
|
|
785
|
+
s2 = c2 / (2 * l2);
|
|
786
|
+
} else if (l2 >= 0.5 && l2 < 1) {
|
|
787
|
+
s2 = c2 / (2 * (1 - l2));
|
|
788
|
+
}
|
|
789
|
+
return [hcg[0], s2 * 100, l2 * 100];
|
|
790
|
+
};
|
|
791
|
+
convert2.hcg.hwb = function(hcg) {
|
|
792
|
+
const c2 = hcg[1] / 100;
|
|
793
|
+
const g2 = hcg[2] / 100;
|
|
794
|
+
const v2 = c2 + g2 * (1 - c2);
|
|
795
|
+
return [hcg[0], (v2 - c2) * 100, (1 - v2) * 100];
|
|
796
|
+
};
|
|
797
|
+
convert2.hwb.hcg = function(hwb) {
|
|
798
|
+
const w2 = hwb[1] / 100;
|
|
799
|
+
const b2 = hwb[2] / 100;
|
|
800
|
+
const v2 = 1 - b2;
|
|
801
|
+
const c2 = v2 - w2;
|
|
802
|
+
let g2 = 0;
|
|
803
|
+
if (c2 < 1) {
|
|
804
|
+
g2 = (v2 - c2) / (1 - c2);
|
|
805
|
+
}
|
|
806
|
+
return [hwb[0], c2 * 100, g2 * 100];
|
|
807
|
+
};
|
|
808
|
+
convert2.apple.rgb = function(apple) {
|
|
809
|
+
return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
|
810
|
+
};
|
|
811
|
+
convert2.rgb.apple = function(rgb) {
|
|
812
|
+
return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
|
813
|
+
};
|
|
814
|
+
convert2.gray.rgb = function(args) {
|
|
815
|
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
816
|
+
};
|
|
817
|
+
convert2.gray.hsl = function(args) {
|
|
818
|
+
return [0, 0, args[0]];
|
|
819
|
+
};
|
|
820
|
+
convert2.gray.hsv = convert2.gray.hsl;
|
|
821
|
+
convert2.gray.hwb = function(gray) {
|
|
822
|
+
return [0, 100, gray[0]];
|
|
823
|
+
};
|
|
824
|
+
convert2.gray.cmyk = function(gray) {
|
|
825
|
+
return [0, 0, 0, gray[0]];
|
|
826
|
+
};
|
|
827
|
+
convert2.gray.lab = function(gray) {
|
|
828
|
+
return [gray[0], 0, 0];
|
|
829
|
+
};
|
|
830
|
+
convert2.gray.hex = function(gray) {
|
|
831
|
+
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
832
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
833
|
+
const string = integer.toString(16).toUpperCase();
|
|
834
|
+
return "000000".substring(string.length) + string;
|
|
835
|
+
};
|
|
836
|
+
convert2.rgb.gray = function(rgb) {
|
|
837
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
838
|
+
return [val / 255 * 100];
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
// ../node_modules/color-convert/route.js
|
|
844
|
+
var require_route = __commonJS({
|
|
845
|
+
"../node_modules/color-convert/route.js"(exports, module) {
|
|
846
|
+
var conversions = require_conversions();
|
|
847
|
+
function buildGraph() {
|
|
848
|
+
const graph = {};
|
|
849
|
+
const models = Object.keys(conversions);
|
|
850
|
+
for (let len = models.length, i2 = 0; i2 < len; i2++) {
|
|
851
|
+
graph[models[i2]] = {
|
|
852
|
+
// http://jsperf.com/1-vs-infinity
|
|
853
|
+
// micro-opt, but this is simple.
|
|
854
|
+
distance: -1,
|
|
855
|
+
parent: null
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
return graph;
|
|
859
|
+
}
|
|
860
|
+
__name(buildGraph, "buildGraph");
|
|
861
|
+
function deriveBFS(fromModel) {
|
|
862
|
+
const graph = buildGraph();
|
|
863
|
+
const queue = [fromModel];
|
|
864
|
+
graph[fromModel].distance = 0;
|
|
865
|
+
while (queue.length) {
|
|
866
|
+
const current = queue.pop();
|
|
867
|
+
const adjacents = Object.keys(conversions[current]);
|
|
868
|
+
for (let len = adjacents.length, i2 = 0; i2 < len; i2++) {
|
|
869
|
+
const adjacent = adjacents[i2];
|
|
870
|
+
const node = graph[adjacent];
|
|
871
|
+
if (node.distance === -1) {
|
|
872
|
+
node.distance = graph[current].distance + 1;
|
|
873
|
+
node.parent = current;
|
|
874
|
+
queue.unshift(adjacent);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return graph;
|
|
879
|
+
}
|
|
880
|
+
__name(deriveBFS, "deriveBFS");
|
|
881
|
+
function link(from, to) {
|
|
882
|
+
return function(args) {
|
|
883
|
+
return to(from(args));
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
__name(link, "link");
|
|
887
|
+
function wrapConversion(toModel, graph) {
|
|
888
|
+
const path = [graph[toModel].parent, toModel];
|
|
889
|
+
let fn = conversions[graph[toModel].parent][toModel];
|
|
890
|
+
let cur = graph[toModel].parent;
|
|
891
|
+
while (graph[cur].parent) {
|
|
892
|
+
path.unshift(graph[cur].parent);
|
|
893
|
+
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
894
|
+
cur = graph[cur].parent;
|
|
895
|
+
}
|
|
896
|
+
fn.conversion = path;
|
|
897
|
+
return fn;
|
|
898
|
+
}
|
|
899
|
+
__name(wrapConversion, "wrapConversion");
|
|
900
|
+
module.exports = function(fromModel) {
|
|
901
|
+
const graph = deriveBFS(fromModel);
|
|
902
|
+
const conversion = {};
|
|
903
|
+
const models = Object.keys(graph);
|
|
904
|
+
for (let len = models.length, i2 = 0; i2 < len; i2++) {
|
|
905
|
+
const toModel = models[i2];
|
|
906
|
+
const node = graph[toModel];
|
|
907
|
+
if (node.parent === null) {
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
conversion[toModel] = wrapConversion(toModel, graph);
|
|
911
|
+
}
|
|
912
|
+
return conversion;
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// ../node_modules/color-convert/index.js
|
|
918
|
+
var require_color_convert = __commonJS({
|
|
919
|
+
"../node_modules/color-convert/index.js"(exports, module) {
|
|
920
|
+
var conversions = require_conversions();
|
|
921
|
+
var route = require_route();
|
|
922
|
+
var convert2 = {};
|
|
923
|
+
var models = Object.keys(conversions);
|
|
924
|
+
function wrapRaw(fn) {
|
|
925
|
+
const wrappedFn = /* @__PURE__ */ __name(function(...args) {
|
|
926
|
+
const arg0 = args[0];
|
|
927
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
928
|
+
return arg0;
|
|
929
|
+
}
|
|
930
|
+
if (arg0.length > 1) {
|
|
931
|
+
args = arg0;
|
|
932
|
+
}
|
|
933
|
+
return fn(args);
|
|
934
|
+
}, "wrappedFn");
|
|
935
|
+
if ("conversion" in fn) {
|
|
936
|
+
wrappedFn.conversion = fn.conversion;
|
|
937
|
+
}
|
|
938
|
+
return wrappedFn;
|
|
939
|
+
}
|
|
940
|
+
__name(wrapRaw, "wrapRaw");
|
|
941
|
+
function wrapRounded(fn) {
|
|
942
|
+
const wrappedFn = /* @__PURE__ */ __name(function(...args) {
|
|
943
|
+
const arg0 = args[0];
|
|
944
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
945
|
+
return arg0;
|
|
946
|
+
}
|
|
947
|
+
if (arg0.length > 1) {
|
|
948
|
+
args = arg0;
|
|
949
|
+
}
|
|
950
|
+
const result = fn(args);
|
|
951
|
+
if (typeof result === "object") {
|
|
952
|
+
for (let len = result.length, i2 = 0; i2 < len; i2++) {
|
|
953
|
+
result[i2] = Math.round(result[i2]);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return result;
|
|
957
|
+
}, "wrappedFn");
|
|
958
|
+
if ("conversion" in fn) {
|
|
959
|
+
wrappedFn.conversion = fn.conversion;
|
|
960
|
+
}
|
|
961
|
+
return wrappedFn;
|
|
962
|
+
}
|
|
963
|
+
__name(wrapRounded, "wrapRounded");
|
|
964
|
+
models.forEach((fromModel) => {
|
|
965
|
+
convert2[fromModel] = {};
|
|
966
|
+
Object.defineProperty(convert2[fromModel], "channels", { value: conversions[fromModel].channels });
|
|
967
|
+
Object.defineProperty(convert2[fromModel], "labels", { value: conversions[fromModel].labels });
|
|
968
|
+
const routes = route(fromModel);
|
|
969
|
+
const routeModels = Object.keys(routes);
|
|
970
|
+
routeModels.forEach((toModel) => {
|
|
971
|
+
const fn = routes[toModel];
|
|
972
|
+
convert2[fromModel][toModel] = wrapRounded(fn);
|
|
973
|
+
convert2[fromModel][toModel].raw = wrapRaw(fn);
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
module.exports = convert2;
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
// ../addons/docs/src/blocks/controls/Color.tsx
|
|
981
|
+
var import_color_convert = __toESM(require_color_convert(), 1);
|
|
982
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
983
|
+
import { Form, TooltipNote, WithTooltip } from "storybook/internal/components";
|
|
984
|
+
import { MarkupIcon } from "@storybook/icons";
|
|
985
|
+
|
|
986
|
+
// ../node_modules/react-colorful/dist/index.mjs
|
|
987
|
+
import e, { useRef as r, useMemo as t, useEffect as n, useState as o, useCallback as a, useLayoutEffect as l } from "react";
|
|
988
|
+
function u() {
|
|
989
|
+
return (u = Object.assign || function(e2) {
|
|
990
|
+
for (var r2 = 1; r2 < arguments.length; r2++) {
|
|
991
|
+
var t2 = arguments[r2];
|
|
992
|
+
for (var n2 in t2) Object.prototype.hasOwnProperty.call(t2, n2) && (e2[n2] = t2[n2]);
|
|
993
|
+
}
|
|
994
|
+
return e2;
|
|
995
|
+
}).apply(this, arguments);
|
|
996
|
+
}
|
|
997
|
+
__name(u, "u");
|
|
998
|
+
function c(e2, r2) {
|
|
999
|
+
if (null == e2) return {};
|
|
1000
|
+
var t2, n2, o2 = {}, a2 = Object.keys(e2);
|
|
1001
|
+
for (n2 = 0; n2 < a2.length; n2++) r2.indexOf(t2 = a2[n2]) >= 0 || (o2[t2] = e2[t2]);
|
|
1002
|
+
return o2;
|
|
1003
|
+
}
|
|
1004
|
+
__name(c, "c");
|
|
1005
|
+
function i(e2) {
|
|
1006
|
+
var t2 = r(e2), n2 = r(function(e3) {
|
|
1007
|
+
t2.current && t2.current(e3);
|
|
1008
|
+
});
|
|
1009
|
+
return t2.current = e2, n2.current;
|
|
1010
|
+
}
|
|
1011
|
+
__name(i, "i");
|
|
1012
|
+
var s = /* @__PURE__ */ __name(function(e2, r2, t2) {
|
|
1013
|
+
return void 0 === r2 && (r2 = 0), void 0 === t2 && (t2 = 1), e2 > t2 ? t2 : e2 < r2 ? r2 : e2;
|
|
1014
|
+
}, "s");
|
|
1015
|
+
var f = /* @__PURE__ */ __name(function(e2) {
|
|
1016
|
+
return "touches" in e2;
|
|
1017
|
+
}, "f");
|
|
1018
|
+
var v = /* @__PURE__ */ __name(function(e2) {
|
|
1019
|
+
return e2 && e2.ownerDocument.defaultView || self;
|
|
1020
|
+
}, "v");
|
|
1021
|
+
var d = /* @__PURE__ */ __name(function(e2, r2, t2) {
|
|
1022
|
+
var n2 = e2.getBoundingClientRect(), o2 = f(r2) ? function(e3, r3) {
|
|
1023
|
+
for (var t3 = 0; t3 < e3.length; t3++) if (e3[t3].identifier === r3) return e3[t3];
|
|
1024
|
+
return e3[0];
|
|
1025
|
+
}(r2.touches, t2) : r2;
|
|
1026
|
+
return { left: s((o2.pageX - (n2.left + v(e2).pageXOffset)) / n2.width), top: s((o2.pageY - (n2.top + v(e2).pageYOffset)) / n2.height) };
|
|
1027
|
+
}, "d");
|
|
1028
|
+
var h = /* @__PURE__ */ __name(function(e2) {
|
|
1029
|
+
!f(e2) && e2.preventDefault();
|
|
1030
|
+
}, "h");
|
|
1031
|
+
var m = e.memo(function(o2) {
|
|
1032
|
+
var a2 = o2.onMove, l2 = o2.onKey, s2 = c(o2, ["onMove", "onKey"]), m2 = r(null), g2 = i(a2), p2 = i(l2), b2 = r(null), _2 = r(false), x2 = t(function() {
|
|
1033
|
+
var e2 = /* @__PURE__ */ __name(function(e3) {
|
|
1034
|
+
h(e3), (f(e3) ? e3.touches.length > 0 : e3.buttons > 0) && m2.current ? g2(d(m2.current, e3, b2.current)) : t2(false);
|
|
1035
|
+
}, "e"), r2 = /* @__PURE__ */ __name(function() {
|
|
1036
|
+
return t2(false);
|
|
1037
|
+
}, "r");
|
|
1038
|
+
function t2(t3) {
|
|
1039
|
+
var n2 = _2.current, o3 = v(m2.current), a3 = t3 ? o3.addEventListener : o3.removeEventListener;
|
|
1040
|
+
a3(n2 ? "touchmove" : "mousemove", e2), a3(n2 ? "touchend" : "mouseup", r2);
|
|
1041
|
+
}
|
|
1042
|
+
__name(t2, "t");
|
|
1043
|
+
return [function(e3) {
|
|
1044
|
+
var r3 = e3.nativeEvent, n2 = m2.current;
|
|
1045
|
+
if (n2 && (h(r3), !function(e4, r4) {
|
|
1046
|
+
return r4 && !f(e4);
|
|
1047
|
+
}(r3, _2.current) && n2)) {
|
|
1048
|
+
if (f(r3)) {
|
|
1049
|
+
_2.current = true;
|
|
1050
|
+
var o3 = r3.changedTouches || [];
|
|
1051
|
+
o3.length && (b2.current = o3[0].identifier);
|
|
1052
|
+
}
|
|
1053
|
+
n2.focus(), g2(d(n2, r3, b2.current)), t2(true);
|
|
1054
|
+
}
|
|
1055
|
+
}, function(e3) {
|
|
1056
|
+
var r3 = e3.which || e3.keyCode;
|
|
1057
|
+
r3 < 37 || r3 > 40 || (e3.preventDefault(), p2({ left: 39 === r3 ? 0.05 : 37 === r3 ? -0.05 : 0, top: 40 === r3 ? 0.05 : 38 === r3 ? -0.05 : 0 }));
|
|
1058
|
+
}, t2];
|
|
1059
|
+
}, [p2, g2]), C2 = x2[0], E2 = x2[1], H2 = x2[2];
|
|
1060
|
+
return n(function() {
|
|
1061
|
+
return H2;
|
|
1062
|
+
}, [H2]), e.createElement("div", u({}, s2, { onTouchStart: C2, onMouseDown: C2, className: "react-colorful__interactive", ref: m2, onKeyDown: E2, tabIndex: 0, role: "slider" }));
|
|
1063
|
+
});
|
|
1064
|
+
var g = /* @__PURE__ */ __name(function(e2) {
|
|
1065
|
+
return e2.filter(Boolean).join(" ");
|
|
1066
|
+
}, "g");
|
|
1067
|
+
var p = /* @__PURE__ */ __name(function(r2) {
|
|
1068
|
+
var t2 = r2.color, n2 = r2.left, o2 = r2.top, a2 = void 0 === o2 ? 0.5 : o2, l2 = g(["react-colorful__pointer", r2.className]);
|
|
1069
|
+
return e.createElement("div", { className: l2, style: { top: 100 * a2 + "%", left: 100 * n2 + "%" } }, e.createElement("div", { className: "react-colorful__pointer-fill", style: { backgroundColor: t2 } }));
|
|
1070
|
+
}, "p");
|
|
1071
|
+
var b = /* @__PURE__ */ __name(function(e2, r2, t2) {
|
|
1072
|
+
return void 0 === r2 && (r2 = 0), void 0 === t2 && (t2 = Math.pow(10, r2)), Math.round(t2 * e2) / t2;
|
|
1073
|
+
}, "b");
|
|
1074
|
+
var _ = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
|
|
1075
|
+
var x = /* @__PURE__ */ __name(function(e2) {
|
|
1076
|
+
return L(C(e2));
|
|
1077
|
+
}, "x");
|
|
1078
|
+
var C = /* @__PURE__ */ __name(function(e2) {
|
|
1079
|
+
return "#" === e2[0] && (e2 = e2.substring(1)), e2.length < 6 ? { r: parseInt(e2[0] + e2[0], 16), g: parseInt(e2[1] + e2[1], 16), b: parseInt(e2[2] + e2[2], 16), a: 4 === e2.length ? b(parseInt(e2[3] + e2[3], 16) / 255, 2) : 1 } : { r: parseInt(e2.substring(0, 2), 16), g: parseInt(e2.substring(2, 4), 16), b: parseInt(e2.substring(4, 6), 16), a: 8 === e2.length ? b(parseInt(e2.substring(6, 8), 16) / 255, 2) : 1 };
|
|
1080
|
+
}, "C");
|
|
1081
|
+
var E = /* @__PURE__ */ __name(function(e2, r2) {
|
|
1082
|
+
return void 0 === r2 && (r2 = "deg"), Number(e2) * (_[r2] || 1);
|
|
1083
|
+
}, "E");
|
|
1084
|
+
var H = /* @__PURE__ */ __name(function(e2) {
|
|
1085
|
+
var r2 = /hsla?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i.exec(e2);
|
|
1086
|
+
return r2 ? N({ h: E(r2[1], r2[2]), s: Number(r2[3]), l: Number(r2[4]), a: void 0 === r2[5] ? 1 : Number(r2[5]) / (r2[6] ? 100 : 1) }) : { h: 0, s: 0, v: 0, a: 1 };
|
|
1087
|
+
}, "H");
|
|
1088
|
+
var N = /* @__PURE__ */ __name(function(e2) {
|
|
1089
|
+
var r2 = e2.s, t2 = e2.l;
|
|
1090
|
+
return { h: e2.h, s: (r2 *= (t2 < 50 ? t2 : 100 - t2) / 100) > 0 ? 2 * r2 / (t2 + r2) * 100 : 0, v: t2 + r2, a: e2.a };
|
|
1091
|
+
}, "N");
|
|
1092
|
+
var w = /* @__PURE__ */ __name(function(e2) {
|
|
1093
|
+
return K(I(e2));
|
|
1094
|
+
}, "w");
|
|
1095
|
+
var y = /* @__PURE__ */ __name(function(e2) {
|
|
1096
|
+
var r2 = e2.s, t2 = e2.v, n2 = e2.a, o2 = (200 - r2) * t2 / 100;
|
|
1097
|
+
return { h: b(e2.h), s: b(o2 > 0 && o2 < 200 ? r2 * t2 / 100 / (o2 <= 100 ? o2 : 200 - o2) * 100 : 0), l: b(o2 / 2), a: b(n2, 2) };
|
|
1098
|
+
}, "y");
|
|
1099
|
+
var q = /* @__PURE__ */ __name(function(e2) {
|
|
1100
|
+
var r2 = y(e2);
|
|
1101
|
+
return "hsl(" + r2.h + ", " + r2.s + "%, " + r2.l + "%)";
|
|
1102
|
+
}, "q");
|
|
1103
|
+
var k = /* @__PURE__ */ __name(function(e2) {
|
|
1104
|
+
var r2 = y(e2);
|
|
1105
|
+
return "hsla(" + r2.h + ", " + r2.s + "%, " + r2.l + "%, " + r2.a + ")";
|
|
1106
|
+
}, "k");
|
|
1107
|
+
var I = /* @__PURE__ */ __name(function(e2) {
|
|
1108
|
+
var r2 = e2.h, t2 = e2.s, n2 = e2.v, o2 = e2.a;
|
|
1109
|
+
r2 = r2 / 360 * 6, t2 /= 100, n2 /= 100;
|
|
1110
|
+
var a2 = Math.floor(r2), l2 = n2 * (1 - t2), u2 = n2 * (1 - (r2 - a2) * t2), c2 = n2 * (1 - (1 - r2 + a2) * t2), i2 = a2 % 6;
|
|
1111
|
+
return { r: b(255 * [n2, u2, l2, l2, c2, n2][i2]), g: b(255 * [c2, n2, n2, u2, l2, l2][i2]), b: b(255 * [l2, l2, c2, n2, n2, u2][i2]), a: b(o2, 2) };
|
|
1112
|
+
}, "I");
|
|
1113
|
+
var z = /* @__PURE__ */ __name(function(e2) {
|
|
1114
|
+
var r2 = /rgba?\(?\s*(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i.exec(e2);
|
|
1115
|
+
return r2 ? L({ r: Number(r2[1]) / (r2[2] ? 100 / 255 : 1), g: Number(r2[3]) / (r2[4] ? 100 / 255 : 1), b: Number(r2[5]) / (r2[6] ? 100 / 255 : 1), a: void 0 === r2[7] ? 1 : Number(r2[7]) / (r2[8] ? 100 : 1) }) : { h: 0, s: 0, v: 0, a: 1 };
|
|
1116
|
+
}, "z");
|
|
1117
|
+
var D = /* @__PURE__ */ __name(function(e2) {
|
|
1118
|
+
var r2 = e2.toString(16);
|
|
1119
|
+
return r2.length < 2 ? "0" + r2 : r2;
|
|
1120
|
+
}, "D");
|
|
1121
|
+
var K = /* @__PURE__ */ __name(function(e2) {
|
|
1122
|
+
var r2 = e2.r, t2 = e2.g, n2 = e2.b, o2 = e2.a, a2 = o2 < 1 ? D(b(255 * o2)) : "";
|
|
1123
|
+
return "#" + D(r2) + D(t2) + D(n2) + a2;
|
|
1124
|
+
}, "K");
|
|
1125
|
+
var L = /* @__PURE__ */ __name(function(e2) {
|
|
1126
|
+
var r2 = e2.r, t2 = e2.g, n2 = e2.b, o2 = e2.a, a2 = Math.max(r2, t2, n2), l2 = a2 - Math.min(r2, t2, n2), u2 = l2 ? a2 === r2 ? (t2 - n2) / l2 : a2 === t2 ? 2 + (n2 - r2) / l2 : 4 + (r2 - t2) / l2 : 0;
|
|
1127
|
+
return { h: b(60 * (u2 < 0 ? u2 + 6 : u2)), s: b(a2 ? l2 / a2 * 100 : 0), v: b(a2 / 255 * 100), a: o2 };
|
|
1128
|
+
}, "L");
|
|
1129
|
+
var S = e.memo(function(r2) {
|
|
1130
|
+
var t2 = r2.hue, n2 = r2.onChange, o2 = g(["react-colorful__hue", r2.className]);
|
|
1131
|
+
return e.createElement("div", { className: o2 }, e.createElement(m, { onMove: /* @__PURE__ */ __name(function(e2) {
|
|
1132
|
+
n2({ h: 360 * e2.left });
|
|
1133
|
+
}, "onMove"), onKey: /* @__PURE__ */ __name(function(e2) {
|
|
1134
|
+
n2({ h: s(t2 + 360 * e2.left, 0, 360) });
|
|
1135
|
+
}, "onKey"), "aria-label": "Hue", "aria-valuenow": b(t2), "aria-valuemax": "360", "aria-valuemin": "0" }, e.createElement(p, { className: "react-colorful__hue-pointer", left: t2 / 360, color: q({ h: t2, s: 100, v: 100, a: 1 }) })));
|
|
1136
|
+
});
|
|
1137
|
+
var T = e.memo(function(r2) {
|
|
1138
|
+
var t2 = r2.hsva, n2 = r2.onChange, o2 = { backgroundColor: q({ h: t2.h, s: 100, v: 100, a: 1 }) };
|
|
1139
|
+
return e.createElement("div", { className: "react-colorful__saturation", style: o2 }, e.createElement(m, { onMove: /* @__PURE__ */ __name(function(e2) {
|
|
1140
|
+
n2({ s: 100 * e2.left, v: 100 - 100 * e2.top });
|
|
1141
|
+
}, "onMove"), onKey: /* @__PURE__ */ __name(function(e2) {
|
|
1142
|
+
n2({ s: s(t2.s + 100 * e2.left, 0, 100), v: s(t2.v - 100 * e2.top, 0, 100) });
|
|
1143
|
+
}, "onKey"), "aria-label": "Color", "aria-valuetext": "Saturation " + b(t2.s) + "%, Brightness " + b(t2.v) + "%" }, e.createElement(p, { className: "react-colorful__saturation-pointer", top: 1 - t2.v / 100, left: t2.s / 100, color: q(t2) })));
|
|
1144
|
+
});
|
|
1145
|
+
var F = /* @__PURE__ */ __name(function(e2, r2) {
|
|
1146
|
+
if (e2 === r2) return true;
|
|
1147
|
+
for (var t2 in e2) if (e2[t2] !== r2[t2]) return false;
|
|
1148
|
+
return true;
|
|
1149
|
+
}, "F");
|
|
1150
|
+
var P = /* @__PURE__ */ __name(function(e2, r2) {
|
|
1151
|
+
return e2.replace(/\s/g, "") === r2.replace(/\s/g, "");
|
|
1152
|
+
}, "P");
|
|
1153
|
+
var X = /* @__PURE__ */ __name(function(e2, r2) {
|
|
1154
|
+
return e2.toLowerCase() === r2.toLowerCase() || F(C(e2), C(r2));
|
|
1155
|
+
}, "X");
|
|
1156
|
+
function Y(e2, t2, l2) {
|
|
1157
|
+
var u2 = i(l2), c2 = o(function() {
|
|
1158
|
+
return e2.toHsva(t2);
|
|
1159
|
+
}), s2 = c2[0], f2 = c2[1], v2 = r({ color: t2, hsva: s2 });
|
|
1160
|
+
n(function() {
|
|
1161
|
+
if (!e2.equal(t2, v2.current.color)) {
|
|
1162
|
+
var r2 = e2.toHsva(t2);
|
|
1163
|
+
v2.current = { hsva: r2, color: t2 }, f2(r2);
|
|
1164
|
+
}
|
|
1165
|
+
}, [t2, e2]), n(function() {
|
|
1166
|
+
var r2;
|
|
1167
|
+
F(s2, v2.current.hsva) || e2.equal(r2 = e2.fromHsva(s2), v2.current.color) || (v2.current = { hsva: s2, color: r2 }, u2(r2));
|
|
1168
|
+
}, [s2, e2, u2]);
|
|
1169
|
+
var d2 = a(function(e3) {
|
|
1170
|
+
f2(function(r2) {
|
|
1171
|
+
return Object.assign({}, r2, e3);
|
|
1172
|
+
});
|
|
1173
|
+
}, []);
|
|
1174
|
+
return [s2, d2];
|
|
1175
|
+
}
|
|
1176
|
+
__name(Y, "Y");
|
|
1177
|
+
var R;
|
|
1178
|
+
var V = "undefined" != typeof window ? l : n;
|
|
1179
|
+
var $ = /* @__PURE__ */ __name(function() {
|
|
1180
|
+
return R || ("undefined" != typeof __webpack_nonce__ ? __webpack_nonce__ : void 0);
|
|
1181
|
+
}, "$");
|
|
1182
|
+
var J = /* @__PURE__ */ new Map();
|
|
1183
|
+
var Q = /* @__PURE__ */ __name(function(e2) {
|
|
1184
|
+
V(function() {
|
|
1185
|
+
var r2 = e2.current ? e2.current.ownerDocument : document;
|
|
1186
|
+
if (void 0 !== r2 && !J.has(r2)) {
|
|
1187
|
+
var t2 = r2.createElement("style");
|
|
1188
|
+
t2.innerHTML = `.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`, J.set(r2, t2);
|
|
1189
|
+
var n2 = $();
|
|
1190
|
+
n2 && t2.setAttribute("nonce", n2), r2.head.appendChild(t2);
|
|
1191
|
+
}
|
|
1192
|
+
}, []);
|
|
1193
|
+
}, "Q");
|
|
1194
|
+
var U = /* @__PURE__ */ __name(function(t2) {
|
|
1195
|
+
var n2 = t2.className, o2 = t2.colorModel, a2 = t2.color, l2 = void 0 === a2 ? o2.defaultColor : a2, i2 = t2.onChange, s2 = c(t2, ["className", "colorModel", "color", "onChange"]), f2 = r(null);
|
|
1196
|
+
Q(f2);
|
|
1197
|
+
var v2 = Y(o2, l2, i2), d2 = v2[0], h2 = v2[1], m2 = g(["react-colorful", n2]);
|
|
1198
|
+
return e.createElement("div", u({}, s2, { ref: f2, className: m2 }), e.createElement(T, { hsva: d2, onChange: h2 }), e.createElement(S, { hue: d2.h, onChange: h2, className: "react-colorful__last-control" }));
|
|
1199
|
+
}, "U");
|
|
1200
|
+
var W = { defaultColor: "000", toHsva: x, fromHsva: /* @__PURE__ */ __name(function(e2) {
|
|
1201
|
+
return w({ h: e2.h, s: e2.s, v: e2.v, a: 1 });
|
|
1202
|
+
}, "fromHsva"), equal: X };
|
|
1203
|
+
var Z = /* @__PURE__ */ __name(function(r2) {
|
|
1204
|
+
return e.createElement(U, u({}, r2, { colorModel: W }));
|
|
1205
|
+
}, "Z");
|
|
1206
|
+
var ee = /* @__PURE__ */ __name(function(r2) {
|
|
1207
|
+
var t2 = r2.className, n2 = r2.hsva, o2 = r2.onChange, a2 = { backgroundImage: "linear-gradient(90deg, " + k(Object.assign({}, n2, { a: 0 })) + ", " + k(Object.assign({}, n2, { a: 1 })) + ")" }, l2 = g(["react-colorful__alpha", t2]), u2 = b(100 * n2.a);
|
|
1208
|
+
return e.createElement("div", { className: l2 }, e.createElement("div", { className: "react-colorful__alpha-gradient", style: a2 }), e.createElement(m, { onMove: /* @__PURE__ */ __name(function(e2) {
|
|
1209
|
+
o2({ a: e2.left });
|
|
1210
|
+
}, "onMove"), onKey: /* @__PURE__ */ __name(function(e2) {
|
|
1211
|
+
o2({ a: s(n2.a + e2.left) });
|
|
1212
|
+
}, "onKey"), "aria-label": "Alpha", "aria-valuetext": u2 + "%", "aria-valuenow": u2, "aria-valuemin": "0", "aria-valuemax": "100" }, e.createElement(p, { className: "react-colorful__alpha-pointer", left: n2.a, color: k(n2) })));
|
|
1213
|
+
}, "ee");
|
|
1214
|
+
var re = /* @__PURE__ */ __name(function(t2) {
|
|
1215
|
+
var n2 = t2.className, o2 = t2.colorModel, a2 = t2.color, l2 = void 0 === a2 ? o2.defaultColor : a2, i2 = t2.onChange, s2 = c(t2, ["className", "colorModel", "color", "onChange"]), f2 = r(null);
|
|
1216
|
+
Q(f2);
|
|
1217
|
+
var v2 = Y(o2, l2, i2), d2 = v2[0], h2 = v2[1], m2 = g(["react-colorful", n2]);
|
|
1218
|
+
return e.createElement("div", u({}, s2, { ref: f2, className: m2 }), e.createElement(T, { hsva: d2, onChange: h2 }), e.createElement(S, { hue: d2.h, onChange: h2 }), e.createElement(ee, { hsva: d2, onChange: h2, className: "react-colorful__last-control" }));
|
|
1219
|
+
}, "re");
|
|
1220
|
+
var le = { defaultColor: "hsla(0, 0%, 0%, 1)", toHsva: H, fromHsva: k, equal: P };
|
|
1221
|
+
var ue = /* @__PURE__ */ __name(function(r2) {
|
|
1222
|
+
return e.createElement(re, u({}, r2, { colorModel: le }));
|
|
1223
|
+
}, "ue");
|
|
1224
|
+
var Ee = { defaultColor: "rgba(0, 0, 0, 1)", toHsva: z, fromHsva: /* @__PURE__ */ __name(function(e2) {
|
|
1225
|
+
var r2 = I(e2);
|
|
1226
|
+
return "rgba(" + r2.r + ", " + r2.g + ", " + r2.b + ", " + r2.a + ")";
|
|
1227
|
+
}, "fromHsva"), equal: P };
|
|
1228
|
+
var He = /* @__PURE__ */ __name(function(r2) {
|
|
1229
|
+
return e.createElement(re, u({}, r2, { colorModel: Ee }));
|
|
1230
|
+
}, "He");
|
|
1231
|
+
|
|
1232
|
+
// ../addons/docs/src/blocks/controls/Color.tsx
|
|
1233
|
+
import { styled } from "storybook/theming";
|
|
1234
|
+
var Wrapper = styled.div({
|
|
1235
|
+
position: "relative",
|
|
1236
|
+
maxWidth: 250,
|
|
1237
|
+
'&[aria-readonly="true"]': {
|
|
1238
|
+
opacity: 0.5
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
var PickerTooltip = styled(WithTooltip)({
|
|
1242
|
+
position: "absolute",
|
|
1243
|
+
zIndex: 1,
|
|
1244
|
+
top: 4,
|
|
1245
|
+
left: 4,
|
|
1246
|
+
"[aria-readonly=true] &": {
|
|
1247
|
+
cursor: "not-allowed"
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
var TooltipContent = styled.div({
|
|
1251
|
+
width: 200,
|
|
1252
|
+
margin: 5,
|
|
1253
|
+
".react-colorful__saturation": {
|
|
1254
|
+
borderRadius: "4px 4px 0 0"
|
|
1255
|
+
},
|
|
1256
|
+
".react-colorful__hue": {
|
|
1257
|
+
boxShadow: "inset 0 0 0 1px rgb(0 0 0 / 5%)"
|
|
1258
|
+
},
|
|
1259
|
+
".react-colorful__last-control": {
|
|
1260
|
+
borderRadius: "0 0 4px 4px"
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
var Note = styled(TooltipNote)(({ theme }) => ({
|
|
1264
|
+
fontFamily: theme.typography.fonts.base
|
|
1265
|
+
}));
|
|
1266
|
+
var Swatches = styled.div({
|
|
1267
|
+
display: "grid",
|
|
1268
|
+
gridTemplateColumns: "repeat(9, 16px)",
|
|
1269
|
+
gap: 6,
|
|
1270
|
+
padding: 3,
|
|
1271
|
+
marginTop: 5,
|
|
1272
|
+
width: 200
|
|
1273
|
+
});
|
|
1274
|
+
var SwatchColor = styled.div(({ theme, active }) => ({
|
|
1275
|
+
width: 16,
|
|
1276
|
+
height: 16,
|
|
1277
|
+
boxShadow: active ? `${theme.appBorderColor} 0 0 0 1px inset, ${theme.textMutedColor}50 0 0 0 4px` : `${theme.appBorderColor} 0 0 0 1px inset`,
|
|
1278
|
+
borderRadius: theme.appBorderRadius
|
|
1279
|
+
}));
|
|
1280
|
+
var swatchBackground = `url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')`;
|
|
1281
|
+
var Swatch = /* @__PURE__ */ __name(({ value, style, ...props }) => {
|
|
1282
|
+
const backgroundImage = `linear-gradient(${value}, ${value}), ${swatchBackground}, linear-gradient(#fff, #fff)`;
|
|
1283
|
+
return React.createElement(SwatchColor, { ...props, style: { ...style, backgroundImage } });
|
|
1284
|
+
}, "Swatch");
|
|
1285
|
+
var Input = styled(Form.Input)(({ theme, readOnly }) => ({
|
|
1286
|
+
width: "100%",
|
|
1287
|
+
paddingLeft: 30,
|
|
1288
|
+
paddingRight: 30,
|
|
1289
|
+
boxSizing: "border-box",
|
|
1290
|
+
fontFamily: theme.typography.fonts.base
|
|
1291
|
+
}));
|
|
1292
|
+
var ToggleIcon = styled(MarkupIcon)(({ theme }) => ({
|
|
1293
|
+
position: "absolute",
|
|
1294
|
+
zIndex: 1,
|
|
1295
|
+
top: 6,
|
|
1296
|
+
right: 7,
|
|
1297
|
+
width: 20,
|
|
1298
|
+
height: 20,
|
|
1299
|
+
padding: 4,
|
|
1300
|
+
boxSizing: "border-box",
|
|
1301
|
+
cursor: "pointer",
|
|
1302
|
+
color: theme.input.color
|
|
1303
|
+
}));
|
|
1304
|
+
var ColorSpace = /* @__PURE__ */ ((ColorSpace2) => {
|
|
1305
|
+
ColorSpace2["RGB"] = "rgb";
|
|
1306
|
+
ColorSpace2["HSL"] = "hsl";
|
|
1307
|
+
ColorSpace2["HEX"] = "hex";
|
|
1308
|
+
return ColorSpace2;
|
|
1309
|
+
})(ColorSpace || {});
|
|
1310
|
+
var COLOR_SPACES = Object.values(ColorSpace);
|
|
1311
|
+
var COLOR_REGEXP = /\(([0-9]+),\s*([0-9]+)%?,\s*([0-9]+)%?,?\s*([0-9.]+)?\)/;
|
|
1312
|
+
var RGB_REGEXP = /^\s*rgba?\(([0-9]+),\s*([0-9]+),\s*([0-9]+),?\s*([0-9.]+)?\)\s*$/i;
|
|
1313
|
+
var HSL_REGEXP = /^\s*hsla?\(([0-9]+),\s*([0-9]+)%,\s*([0-9]+)%,?\s*([0-9.]+)?\)\s*$/i;
|
|
1314
|
+
var HEX_REGEXP = /^\s*#?([0-9a-f]{3}|[0-9a-f]{6})\s*$/i;
|
|
1315
|
+
var SHORTHEX_REGEXP = /^\s*#?([0-9a-f]{3})\s*$/i;
|
|
1316
|
+
var ColorPicker = {
|
|
1317
|
+
["hex" /* HEX */]: Z,
|
|
1318
|
+
["rgb" /* RGB */]: He,
|
|
1319
|
+
["hsl" /* HSL */]: ue
|
|
1320
|
+
};
|
|
1321
|
+
var fallbackColor = {
|
|
1322
|
+
["hex" /* HEX */]: "transparent",
|
|
1323
|
+
["rgb" /* RGB */]: "rgba(0, 0, 0, 0)",
|
|
1324
|
+
["hsl" /* HSL */]: "hsla(0, 0%, 0%, 0)"
|
|
1325
|
+
};
|
|
1326
|
+
var stringToArgs = /* @__PURE__ */ __name((value) => {
|
|
1327
|
+
const match = value?.match(COLOR_REGEXP);
|
|
1328
|
+
if (!match) {
|
|
1329
|
+
return [0, 0, 0, 1];
|
|
1330
|
+
}
|
|
1331
|
+
const [, x2, y2, z2, a2 = 1] = match;
|
|
1332
|
+
return [x2, y2, z2, a2].map(Number);
|
|
1333
|
+
}, "stringToArgs");
|
|
1334
|
+
var parseRgb = /* @__PURE__ */ __name((value) => {
|
|
1335
|
+
const [r2, g2, b2, a2] = stringToArgs(value);
|
|
1336
|
+
const [h2, s2, l2] = import_color_convert.default.rgb.hsl([r2, g2, b2]) || [0, 0, 0];
|
|
1337
|
+
return {
|
|
1338
|
+
valid: true,
|
|
1339
|
+
value,
|
|
1340
|
+
keyword: import_color_convert.default.rgb.keyword([r2, g2, b2]),
|
|
1341
|
+
colorSpace: "rgb" /* RGB */,
|
|
1342
|
+
["rgb" /* RGB */]: value,
|
|
1343
|
+
["hsl" /* HSL */]: `hsla(${h2}, ${s2}%, ${l2}%, ${a2})`,
|
|
1344
|
+
["hex" /* HEX */]: `#${import_color_convert.default.rgb.hex([r2, g2, b2]).toLowerCase()}`
|
|
1345
|
+
};
|
|
1346
|
+
}, "parseRgb");
|
|
1347
|
+
var parseHsl = /* @__PURE__ */ __name((value) => {
|
|
1348
|
+
const [h2, s2, l2, a2] = stringToArgs(value);
|
|
1349
|
+
const [r2, g2, b2] = import_color_convert.default.hsl.rgb([h2, s2, l2]) || [0, 0, 0];
|
|
1350
|
+
return {
|
|
1351
|
+
valid: true,
|
|
1352
|
+
value,
|
|
1353
|
+
keyword: import_color_convert.default.hsl.keyword([h2, s2, l2]),
|
|
1354
|
+
colorSpace: "hsl" /* HSL */,
|
|
1355
|
+
["rgb" /* RGB */]: `rgba(${r2}, ${g2}, ${b2}, ${a2})`,
|
|
1356
|
+
["hsl" /* HSL */]: value,
|
|
1357
|
+
["hex" /* HEX */]: `#${import_color_convert.default.hsl.hex([h2, s2, l2]).toLowerCase()}`
|
|
1358
|
+
};
|
|
1359
|
+
}, "parseHsl");
|
|
1360
|
+
var parseHexOrKeyword = /* @__PURE__ */ __name((value) => {
|
|
1361
|
+
const plain = value.replace("#", "");
|
|
1362
|
+
const rgb = import_color_convert.default.keyword.rgb(plain) || import_color_convert.default.hex.rgb(plain);
|
|
1363
|
+
const hsl = import_color_convert.default.rgb.hsl(rgb);
|
|
1364
|
+
let mapped = value;
|
|
1365
|
+
if (/[^#a-f0-9]/i.test(value)) {
|
|
1366
|
+
mapped = plain;
|
|
1367
|
+
} else if (HEX_REGEXP.test(value)) {
|
|
1368
|
+
mapped = `#${plain}`;
|
|
1369
|
+
}
|
|
1370
|
+
let valid = true;
|
|
1371
|
+
if (mapped.startsWith("#")) {
|
|
1372
|
+
valid = HEX_REGEXP.test(mapped);
|
|
1373
|
+
} else {
|
|
1374
|
+
try {
|
|
1375
|
+
import_color_convert.default.keyword.hex(mapped);
|
|
1376
|
+
} catch (e2) {
|
|
1377
|
+
valid = false;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
return {
|
|
1381
|
+
valid,
|
|
1382
|
+
value: mapped,
|
|
1383
|
+
keyword: import_color_convert.default.rgb.keyword(rgb),
|
|
1384
|
+
colorSpace: "hex" /* HEX */,
|
|
1385
|
+
["rgb" /* RGB */]: `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 1)`,
|
|
1386
|
+
["hsl" /* HSL */]: `hsla(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%, 1)`,
|
|
1387
|
+
["hex" /* HEX */]: mapped
|
|
1388
|
+
};
|
|
1389
|
+
}, "parseHexOrKeyword");
|
|
1390
|
+
var parseValue = /* @__PURE__ */ __name((value) => {
|
|
1391
|
+
if (!value) {
|
|
1392
|
+
return void 0;
|
|
1393
|
+
}
|
|
1394
|
+
if (RGB_REGEXP.test(value)) {
|
|
1395
|
+
return parseRgb(value);
|
|
1396
|
+
}
|
|
1397
|
+
if (HSL_REGEXP.test(value)) {
|
|
1398
|
+
return parseHsl(value);
|
|
1399
|
+
}
|
|
1400
|
+
return parseHexOrKeyword(value);
|
|
1401
|
+
}, "parseValue");
|
|
1402
|
+
var getRealValue = /* @__PURE__ */ __name((value, color, colorSpace) => {
|
|
1403
|
+
if (!value || !color?.valid) {
|
|
1404
|
+
return fallbackColor[colorSpace];
|
|
1405
|
+
}
|
|
1406
|
+
if (colorSpace !== "hex" /* HEX */) {
|
|
1407
|
+
return color?.[colorSpace] || fallbackColor[colorSpace];
|
|
1408
|
+
}
|
|
1409
|
+
if (!color.hex.startsWith("#")) {
|
|
1410
|
+
try {
|
|
1411
|
+
return `#${import_color_convert.default.keyword.hex(color.hex)}`;
|
|
1412
|
+
} catch (e2) {
|
|
1413
|
+
return fallbackColor.hex;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
const short = color.hex.match(SHORTHEX_REGEXP);
|
|
1417
|
+
if (!short) {
|
|
1418
|
+
return HEX_REGEXP.test(color.hex) ? color.hex : fallbackColor.hex;
|
|
1419
|
+
}
|
|
1420
|
+
const [r2, g2, b2] = short[1].split("");
|
|
1421
|
+
return `#${r2}${r2}${g2}${g2}${b2}${b2}`;
|
|
1422
|
+
}, "getRealValue");
|
|
1423
|
+
var useColorInput = /* @__PURE__ */ __name((initialValue, onChange) => {
|
|
1424
|
+
const [value, setValue] = useState(initialValue || "");
|
|
1425
|
+
const [color, setColor] = useState(() => parseValue(value));
|
|
1426
|
+
const [colorSpace, setColorSpace] = useState(color?.colorSpace || "hex" /* HEX */);
|
|
1427
|
+
useEffect(() => {
|
|
1428
|
+
const nextValue = initialValue || "";
|
|
1429
|
+
const nextColor = parseValue(nextValue);
|
|
1430
|
+
setValue(nextValue);
|
|
1431
|
+
setColor(nextColor);
|
|
1432
|
+
setColorSpace(nextColor?.colorSpace || "hex" /* HEX */);
|
|
1433
|
+
}, [initialValue]);
|
|
1434
|
+
const realValue = useMemo(
|
|
1435
|
+
() => getRealValue(value, color, colorSpace).toLowerCase(),
|
|
1436
|
+
[value, color, colorSpace]
|
|
1437
|
+
);
|
|
1438
|
+
const updateValue = useCallback(
|
|
1439
|
+
(update) => {
|
|
1440
|
+
const parsed = parseValue(update);
|
|
1441
|
+
const v2 = parsed?.value || update || "";
|
|
1442
|
+
setValue(v2);
|
|
1443
|
+
if (v2 === "") {
|
|
1444
|
+
setColor(void 0);
|
|
1445
|
+
onChange(void 0);
|
|
1446
|
+
}
|
|
1447
|
+
if (!parsed) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
setColor(parsed);
|
|
1451
|
+
setColorSpace(parsed.colorSpace);
|
|
1452
|
+
onChange(parsed.value);
|
|
1453
|
+
},
|
|
1454
|
+
[onChange]
|
|
1455
|
+
);
|
|
1456
|
+
const cycleColorSpace = useCallback(() => {
|
|
1457
|
+
const currentIndex = COLOR_SPACES.indexOf(colorSpace);
|
|
1458
|
+
const nextIndex = (currentIndex + 1) % COLOR_SPACES.length;
|
|
1459
|
+
const nextSpace = COLOR_SPACES[nextIndex];
|
|
1460
|
+
setColorSpace(nextSpace);
|
|
1461
|
+
const updatedValue = color?.[nextSpace] || "";
|
|
1462
|
+
setValue(updatedValue);
|
|
1463
|
+
onChange(updatedValue);
|
|
1464
|
+
}, [color, colorSpace, onChange]);
|
|
1465
|
+
return { value, realValue, updateValue, color, colorSpace, cycleColorSpace };
|
|
1466
|
+
}, "useColorInput");
|
|
1467
|
+
var id = /* @__PURE__ */ __name((value) => value.replace(/\s*/, "").toLowerCase(), "id");
|
|
1468
|
+
var usePresets = /* @__PURE__ */ __name((presetColors, currentColor, colorSpace) => {
|
|
1469
|
+
const [selectedColors, setSelectedColors] = useState(currentColor?.valid ? [currentColor] : []);
|
|
1470
|
+
useEffect(() => {
|
|
1471
|
+
if (currentColor !== void 0) {
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
setSelectedColors([]);
|
|
1475
|
+
}, [currentColor]);
|
|
1476
|
+
const presets = useMemo(() => {
|
|
1477
|
+
const initialPresets = (presetColors || []).map((preset) => {
|
|
1478
|
+
if (typeof preset === "string") {
|
|
1479
|
+
return parseValue(preset);
|
|
1480
|
+
}
|
|
1481
|
+
if (preset.title) {
|
|
1482
|
+
return { ...parseValue(preset.color), keyword: preset.title };
|
|
1483
|
+
}
|
|
1484
|
+
return parseValue(preset.color);
|
|
1485
|
+
});
|
|
1486
|
+
return initialPresets.concat(selectedColors).filter(Boolean).slice(-27);
|
|
1487
|
+
}, [presetColors, selectedColors]);
|
|
1488
|
+
const addPreset = useCallback(
|
|
1489
|
+
(color) => {
|
|
1490
|
+
if (!color?.valid) {
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
if (presets.some(
|
|
1494
|
+
(preset) => preset && preset[colorSpace] && id(preset[colorSpace] || "") === id(color[colorSpace] || "")
|
|
1495
|
+
)) {
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
setSelectedColors((arr) => arr.concat(color));
|
|
1499
|
+
},
|
|
1500
|
+
[colorSpace, presets]
|
|
1501
|
+
);
|
|
1502
|
+
return { presets, addPreset };
|
|
1503
|
+
}, "usePresets");
|
|
1504
|
+
var ColorControl = /* @__PURE__ */ __name(({
|
|
1505
|
+
name,
|
|
1506
|
+
value: initialValue,
|
|
1507
|
+
onChange,
|
|
1508
|
+
onFocus,
|
|
1509
|
+
onBlur,
|
|
1510
|
+
presetColors,
|
|
1511
|
+
startOpen = false,
|
|
1512
|
+
argType
|
|
1513
|
+
}) => {
|
|
1514
|
+
const debouncedOnChange = useCallback(debounce(onChange, 200), [onChange]);
|
|
1515
|
+
const { value, realValue, updateValue, color, colorSpace, cycleColorSpace } = useColorInput(
|
|
1516
|
+
initialValue,
|
|
1517
|
+
debouncedOnChange
|
|
1518
|
+
);
|
|
1519
|
+
const { presets, addPreset } = usePresets(presetColors ?? [], color, colorSpace);
|
|
1520
|
+
const Picker = ColorPicker[colorSpace];
|
|
1521
|
+
const readonly = !!argType?.table?.readonly;
|
|
1522
|
+
return React.createElement(Wrapper, { "aria-readonly": readonly }, React.createElement(
|
|
1523
|
+
PickerTooltip,
|
|
1524
|
+
{
|
|
1525
|
+
startOpen,
|
|
1526
|
+
trigger: readonly ? null : void 0,
|
|
1527
|
+
closeOnOutsideClick: true,
|
|
1528
|
+
onVisibleChange: () => color && addPreset(color),
|
|
1529
|
+
tooltip: React.createElement(TooltipContent, null, React.createElement(
|
|
1530
|
+
Picker,
|
|
1531
|
+
{
|
|
1532
|
+
color: realValue === "transparent" ? "#000000" : realValue,
|
|
1533
|
+
...{ onChange: updateValue, onFocus, onBlur }
|
|
1534
|
+
}
|
|
1535
|
+
), presets.length > 0 && React.createElement(Swatches, null, presets.map((preset, index) => React.createElement(
|
|
1536
|
+
WithTooltip,
|
|
1537
|
+
{
|
|
1538
|
+
key: `${preset?.value || index}-${index}`,
|
|
1539
|
+
hasChrome: false,
|
|
1540
|
+
tooltip: React.createElement(Note, { note: preset?.keyword || preset?.value || "" })
|
|
1541
|
+
},
|
|
1542
|
+
React.createElement(
|
|
1543
|
+
Swatch,
|
|
1544
|
+
{
|
|
1545
|
+
value: preset?.[colorSpace] || "",
|
|
1546
|
+
active: !!(color && preset && preset[colorSpace] && id(preset[colorSpace] || "") === id(color[colorSpace])),
|
|
1547
|
+
onClick: () => preset && updateValue(preset.value || "")
|
|
1548
|
+
}
|
|
1549
|
+
)
|
|
1550
|
+
))))
|
|
1551
|
+
},
|
|
1552
|
+
React.createElement(Swatch, { value: realValue, style: { margin: 4 } })
|
|
1553
|
+
), React.createElement(
|
|
1554
|
+
Input,
|
|
1555
|
+
{
|
|
1556
|
+
id: getControlId(name),
|
|
1557
|
+
value,
|
|
1558
|
+
onChange: (e2) => updateValue(e2.target.value),
|
|
1559
|
+
onFocus: (e2) => e2.target.select(),
|
|
1560
|
+
readOnly: readonly,
|
|
1561
|
+
placeholder: "Choose color..."
|
|
1562
|
+
}
|
|
1563
|
+
), value ? React.createElement(ToggleIcon, { onClick: cycleColorSpace }) : null);
|
|
1564
|
+
}, "ColorControl");
|
|
1565
|
+
var Color_default = ColorControl;
|
|
1566
|
+
export {
|
|
1567
|
+
ColorControl,
|
|
1568
|
+
Color_default as default
|
|
1569
|
+
};
|