gradio-pr-bot commited on
Commit
56dc7fb
·
verified ·
1 Parent(s): 3e0005c

Upload folder using huggingface_hub

Browse files
6.21.1/colorpicker/Example.svelte ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string | null;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ style="background-color: {value ? value : 'black'}"
9
+ class:table={type === "table"}
10
+ class:gallery={type === "gallery"}
11
+ class:selected
12
+ />
13
+
14
+ <style>
15
+ div {
16
+ width: var(--size-10);
17
+ height: var(--size-10);
18
+ }
19
+ .table {
20
+ margin: 0 auto;
21
+ }
22
+ </style>
6.21.1/colorpicker/Index.svelte ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as BaseColorPicker } from "./shared/Colorpicker.svelte";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { Gradio } from "@gradio/utils";
10
+ import Colorpicker from "./shared/Colorpicker.svelte";
11
+ import { Block } from "@gradio/atoms";
12
+ import { StatusTracker } from "@gradio/statustracker";
13
+ import type { ColorPickerProps, ColorPickerEvents } from "./types";
14
+
15
+ let props = $props();
16
+ const gradio = new Gradio<ColorPickerEvents, ColorPickerProps>(props, {
17
+ value: "#000000"
18
+ });
19
+ let old_value = $state(gradio.props.value);
20
+ let label = $derived(
21
+ gradio.shared.label || gradio.i18n("color_picker.color_picker")
22
+ );
23
+
24
+ $effect(() => {
25
+ if (old_value !== gradio.props.value) {
26
+ old_value = gradio.props.value;
27
+ gradio.dispatch("change", gradio.props.value);
28
+ }
29
+ });
30
+ </script>
31
+
32
+ <Block
33
+ visible={gradio.shared.visible}
34
+ elem_id={gradio.shared.elem_id}
35
+ elem_classes={gradio.shared.elem_classes}
36
+ container={gradio.shared.container}
37
+ scale={gradio.shared.scale}
38
+ min_width={gradio.shared.min_width}
39
+ >
40
+ <StatusTracker
41
+ autoscroll={gradio.shared.autoscroll}
42
+ i18n={gradio.i18n}
43
+ {...gradio.shared.loading_status}
44
+ on_clear_status={() =>
45
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
46
+ />
47
+
48
+ <Colorpicker
49
+ bind:value={gradio.props.value}
50
+ {label}
51
+ info={gradio.props.info}
52
+ show_label={gradio.shared.show_label}
53
+ disabled={!gradio.shared.interactive}
54
+ on_input={() => gradio.dispatch("input")}
55
+ on_release={() => gradio.dispatch("release", gradio.props.value)}
56
+ on_submit={() => gradio.dispatch("submit")}
57
+ on_blur={() => gradio.dispatch("blur")}
58
+ on_focus={() => gradio.dispatch("focus")}
59
+ />
60
+ </Block>
6.21.1/colorpicker/package.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/colorpicker",
3
+ "version": "0.5.15",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "./Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "gradio": "./Index.svelte",
14
+ "svelte": "./dist/Index.svelte",
15
+ "types": "./dist/Index.svelte.d.ts"
16
+ },
17
+ "./example": {
18
+ "gradio": "./Example.svelte",
19
+ "svelte": "./dist/Example.svelte",
20
+ "types": "./dist/Example.svelte.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/statustracker": "workspace:^",
27
+ "@gradio/utils": "workspace:^",
28
+ "@gradio/icons": "workspace:^",
29
+ "tinycolor2": "^1.6.0",
30
+ "@types/tinycolor2": "^1.4.6"
31
+ },
32
+ "devDependencies": {
33
+ "@gradio/preview": "workspace:^"
34
+ },
35
+ "peerDependencies": {
36
+ "svelte": "^5.48.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/gradio-app/gradio.git",
41
+ "directory": "js/colorpicker"
42
+ }
43
+ }
6.21.1/colorpicker/shared/Colorpicker.svelte ADDED
@@ -0,0 +1,482 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount, tick } from "svelte";
3
+ import tinycolor from "tinycolor2";
4
+ import { BlockTitle } from "@gradio/atoms";
5
+ import { click_outside } from "./events";
6
+ import { Eyedropper } from "@gradio/icons";
7
+ import { hsva_to_rgba, format_color, normalize_color } from "./utils";
8
+
9
+ let {
10
+ value = $bindable(),
11
+ label,
12
+ info,
13
+ disabled,
14
+ show_label,
15
+ on_input = () => {},
16
+ on_release = () => {},
17
+ on_submit = () => {},
18
+ on_blur = () => {},
19
+ on_focus = () => {}
20
+ }: {
21
+ value: string;
22
+ label: string;
23
+ info?: string;
24
+ disabled: boolean;
25
+ show_label: boolean;
26
+ on_input?: () => void;
27
+ on_release?: () => void;
28
+ on_submit?: () => void;
29
+ on_blur?: () => void;
30
+ on_focus?: () => void;
31
+ } = $props();
32
+
33
+ let dialog_open = $state(false);
34
+ let current_mode: "hex" | "rgb" | "hsl" = $state("hex");
35
+
36
+ let eyedropper_supported = false;
37
+
38
+ let wrapper: HTMLDivElement;
39
+ let dialog_button: HTMLButtonElement;
40
+ let has_focus = false;
41
+
42
+ let sl_wrap: HTMLDivElement;
43
+ let hue_wrap: HTMLDivElement;
44
+
45
+ let sl_marker_pos = [0, 0];
46
+ let sl_rect: DOMRect | null = null;
47
+ let sl_moving = false;
48
+ let sl = [0, 0];
49
+
50
+ let hue = 0;
51
+ let hue_marker_pos = 0;
52
+ let hue_rect: DOMRect | null = null;
53
+ let hue_moving = false;
54
+
55
+ function handle_hue_down(
56
+ event: MouseEvent & { currentTarget: HTMLDivElement }
57
+ ): void {
58
+ hue_rect = event.currentTarget.getBoundingClientRect();
59
+ hue_moving = true;
60
+ update_hue_from_mouse(event.clientX);
61
+ }
62
+
63
+ function update_hue_from_mouse(x: number): void {
64
+ if (!hue_rect) return;
65
+ const _x = Math.max(0, Math.min(x - hue_rect.left, hue_rect.width)); // Get the x-coordinate relative to the box
66
+ hue_marker_pos = _x;
67
+ const _hue = (_x / hue_rect.width) * 360; // Scale the x position to a hue value (0-360)
68
+
69
+ hue = _hue;
70
+
71
+ value = hsva_to_rgba({ h: _hue, s: sl[0], v: sl[1], a: 1 });
72
+ on_input();
73
+ }
74
+
75
+ function update_color_from_mouse(x: number, y: number): void {
76
+ if (!sl_rect) return;
77
+ const _x = Math.max(0, Math.min(x - sl_rect.left, sl_rect.width));
78
+ const _y = Math.max(0, Math.min(y - sl_rect.top, sl_rect.height));
79
+ sl_marker_pos = [_x, _y];
80
+ const _hsva = {
81
+ h: hue * 1,
82
+ s: _x / sl_rect.width,
83
+ v: 1 - _y / sl_rect.height,
84
+ a: 1
85
+ };
86
+
87
+ sl = [_hsva.s, _hsva.v];
88
+
89
+ value = hsva_to_rgba(_hsva);
90
+ on_input();
91
+ }
92
+
93
+ function handle_sl_down(
94
+ event: MouseEvent & { currentTarget: HTMLDivElement }
95
+ ): void {
96
+ sl_moving = true;
97
+ sl_rect = event.currentTarget.getBoundingClientRect();
98
+ update_color_from_mouse(event.clientX, event.clientY);
99
+ }
100
+
101
+ function handle_move(event: MouseEvent): void {
102
+ if (sl_moving) update_color_from_mouse(event.clientX, event.clientY);
103
+ if (hue_moving) update_hue_from_mouse(event.clientX);
104
+ }
105
+
106
+ function handle_end(): void {
107
+ const should_dispatch_release = sl_moving || hue_moving;
108
+ sl_moving = false;
109
+ hue_moving = false;
110
+ if (should_dispatch_release) {
111
+ on_release();
112
+ }
113
+ }
114
+
115
+ async function update_mouse_from_color(color: string): Promise<void> {
116
+ if (sl_moving || hue_moving) return;
117
+ await tick();
118
+ if (!color) return;
119
+
120
+ if (!sl_rect && sl_wrap) {
121
+ sl_rect = sl_wrap.getBoundingClientRect();
122
+ }
123
+
124
+ if (!hue_rect && hue_wrap) {
125
+ hue_rect = hue_wrap.getBoundingClientRect();
126
+ }
127
+
128
+ // Exit if we still don't have valid rectangles
129
+ if (!sl_rect || !hue_rect) return;
130
+
131
+ const hsva = tinycolor(color).toHsv();
132
+ const _x = hsva.s * sl_rect.width;
133
+ const _y = (1 - hsva.v) * sl_rect.height;
134
+ sl_marker_pos = [_x, _y];
135
+ sl = [hsva.s, hsva.v];
136
+ hue = hsva.h;
137
+ hue_marker_pos = (hsva.h / 360) * hue_rect.width;
138
+ }
139
+
140
+ function request_eyedropper(): void {
141
+ // @ts-ignore
142
+ const eyeDropper = new EyeDropper();
143
+
144
+ eyeDropper.open().then((result: { sRGBHex: string }) => {
145
+ value = result.sRGBHex;
146
+ });
147
+ on_input();
148
+ }
149
+
150
+ const modes = [
151
+ ["Hex", "hex"],
152
+ ["RGB", "rgb"],
153
+ ["HSL", "hsl"]
154
+ ] as const;
155
+
156
+ let color_string = $derived.by(() => format_color(value, current_mode));
157
+
158
+ onMount(async () => {
159
+ // @ts-ignore
160
+ eyedropper_supported = window !== undefined && !!window.EyeDropper;
161
+ });
162
+
163
+ function handle_focusin(): void {
164
+ if (!has_focus) {
165
+ has_focus = true;
166
+ on_focus();
167
+ }
168
+ }
169
+
170
+ function handle_focusout(event: FocusEvent): void {
171
+ if (event.relatedTarget && wrapper.contains(event.relatedTarget as Node)) {
172
+ return;
173
+ }
174
+ if (has_focus) {
175
+ has_focus = false;
176
+ on_blur();
177
+ }
178
+ }
179
+
180
+ function handle_click_outside(event: MouseEvent): void {
181
+ // click_outside is bound to the dialog, so the swatch (outside it, but
182
+ // inside the component) triggers this too; let its onclick handle the toggle.
183
+ if (dialog_button.contains(event.target as Node)) {
184
+ return;
185
+ }
186
+ dialog_open = false;
187
+ // The focused element is removed with the dialog, so no focusout fires;
188
+ // dispatch blur here instead.
189
+ if (has_focus) {
190
+ has_focus = false;
191
+ on_blur();
192
+ }
193
+ }
194
+
195
+ $effect(() => {
196
+ update_mouse_from_color(value);
197
+ });
198
+ </script>
199
+
200
+ <BlockTitle {show_label} {info}>{label}</BlockTitle>
201
+
202
+ <svelte:window onmousemove={handle_move} onmouseup={handle_end} />
203
+
204
+ <div
205
+ bind:this={wrapper}
206
+ onfocusin={handle_focusin}
207
+ onfocusout={handle_focusout}
208
+ >
209
+ <button
210
+ class="dialog-button"
211
+ bind:this={dialog_button}
212
+ aria-label={label}
213
+ style:background={value}
214
+ {disabled}
215
+ onclick={() => {
216
+ update_mouse_from_color(value);
217
+ dialog_open = !dialog_open;
218
+ }}
219
+ />
220
+
221
+ {#if dialog_open}
222
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
223
+ <div
224
+ class="color-picker"
225
+ onmousedown={(e) => {
226
+ // Keep focus where it is, as Dropdown does for its options:
227
+ // letting focus fall to body (padding clicks, or button clicks
228
+ // on browsers where buttons don't take focus) fires a premature
229
+ // blur. Only the text input needs mouse focus.
230
+ if (!(e.target instanceof HTMLInputElement)) {
231
+ e.preventDefault();
232
+ }
233
+ }}
234
+ use:click_outside={handle_click_outside}
235
+ >
236
+ <div
237
+ class="color-gradient"
238
+ role="slider"
239
+ aria-label="Saturation and brightness"
240
+ aria-valuetext={value}
241
+ tabindex="0"
242
+ onmousedown={handle_sl_down}
243
+ style="--hue:{hue}"
244
+ bind:this={sl_wrap}
245
+ >
246
+ <div
247
+ class="marker"
248
+ style:transform="translate({sl_marker_pos[0]}px,{sl_marker_pos[1]}px)"
249
+ style:background={value}
250
+ />
251
+ </div>
252
+ <div
253
+ class="hue-slider"
254
+ role="slider"
255
+ aria-label="Hue"
256
+ aria-valuemin={0}
257
+ aria-valuemax={360}
258
+ aria-valuenow={Math.round(hue)}
259
+ tabindex="0"
260
+ onmousedown={handle_hue_down}
261
+ bind:this={hue_wrap}
262
+ >
263
+ <div
264
+ class="marker"
265
+ style:background={"hsl(" + hue + ", 100%, 50%)"}
266
+ style:transform="translateX({hue_marker_pos}px)"
267
+ />
268
+ </div>
269
+
270
+ <div class="input">
271
+ <button class="swatch" style:background={value}></button>
272
+ <div>
273
+ <div class="input-wrap">
274
+ <input
275
+ type="text"
276
+ bind:value={color_string}
277
+ onchange={(e) => {
278
+ value = normalize_color(e.currentTarget.value);
279
+ }}
280
+ onkeydown={(e) => {
281
+ if (e.key === "Enter") {
282
+ on_submit();
283
+ }
284
+ }}
285
+ />
286
+ <button class="eyedropper" onclick={request_eyedropper}>
287
+ {#if eyedropper_supported}
288
+ <Eyedropper />
289
+ {/if}
290
+ </button>
291
+ </div>
292
+
293
+ <div class="buttons">
294
+ {#each modes as [label, value]}
295
+ <button
296
+ class="button"
297
+ class:active={current_mode === value}
298
+ onclick={() => {
299
+ current_mode = value;
300
+ }}>{label}</button
301
+ >
302
+ {/each}
303
+ </div>
304
+ </div>
305
+ </div>
306
+ </div>
307
+ {/if}
308
+ </div>
309
+
310
+ <style>
311
+ .dialog-button {
312
+ display: block;
313
+ width: var(--size-10);
314
+ height: var(--size-5);
315
+ border: var(--block-border-width) solid var(--block-border-color);
316
+ }
317
+
318
+ .dialog-button:disabled {
319
+ cursor: not-allowed;
320
+ }
321
+
322
+ .input {
323
+ display: flex;
324
+ align-items: center;
325
+ padding: 0 10px 15px;
326
+ }
327
+
328
+ .input input {
329
+ height: 30px;
330
+ width: 100%;
331
+ flex-shrink: 1;
332
+ border-bottom-left-radius: 0;
333
+ border: 1px solid var(--block-border-color);
334
+ letter-spacing: -0.05rem;
335
+ border-left: none;
336
+ border-right: none;
337
+ font-family: var(--font-mono);
338
+ font-size: var(--scale-000);
339
+ padding-left: 15px;
340
+ padding-right: 0;
341
+ background-color: var(--background-fill-secondary);
342
+ color: var(--block-label-text-color);
343
+ }
344
+
345
+ .swatch {
346
+ width: 50px;
347
+ height: 50px;
348
+ border-top-left-radius: 15px;
349
+ border-bottom-left-radius: 15px;
350
+ flex-shrink: 0;
351
+ border: 1px solid var(--block-border-color);
352
+ }
353
+
354
+ .color-picker {
355
+ width: 230px;
356
+ background: var(--background-fill-secondary);
357
+ border: 1px solid var(--block-border-color);
358
+ border-radius: var(--block-radius);
359
+ margin: var(--spacing-sm) 0;
360
+ }
361
+
362
+ .buttons {
363
+ height: 20px;
364
+ display: flex;
365
+ justify-content: stretch;
366
+ gap: 0px;
367
+ }
368
+
369
+ .buttons button {
370
+ display: flex;
371
+ align-items: center;
372
+ justify-content: center;
373
+ border: 1px solid var(--block-border-color);
374
+ background: var(--background-fill-secondary);
375
+ padding: 3px 6px;
376
+ font-size: var(--scale-000);
377
+ cursor: pointer;
378
+ border-right: none;
379
+ width: 100%;
380
+ border-top: none;
381
+ }
382
+
383
+ .buttons button:first-child {
384
+ border-left: none;
385
+ }
386
+
387
+ .buttons button:last-child {
388
+ border-bottom-right-radius: 15px;
389
+ border-right: 1px solid var(--block-border-color);
390
+ }
391
+
392
+ .buttons button:hover {
393
+ background: var(--background-fill-secondary-hover);
394
+ font-weight: var(--weight-bold);
395
+ }
396
+
397
+ .buttons button.active {
398
+ background: var(--background-fill-secondary);
399
+ font-weight: var(--weight-bold);
400
+ }
401
+
402
+ .input-wrap {
403
+ display: flex;
404
+ }
405
+
406
+ .color-gradient {
407
+ position: relative;
408
+ --hue: white;
409
+ background:
410
+ linear-gradient(rgba(0, 0, 0, 0), #000),
411
+ linear-gradient(90deg, #fff, hsl(var(--hue), 100%, 50%));
412
+ width: 100%;
413
+ height: 150px;
414
+ border-radius: var(--radius-sm) var(--radius-sm) 0 0;
415
+ }
416
+
417
+ .hue-slider {
418
+ position: relative;
419
+ width: 90%;
420
+ margin: 10px auto;
421
+ height: 10px;
422
+ border-radius: 5px;
423
+ background: linear-gradient(
424
+ to right,
425
+ hsl(0, 100%, 50%) 0%,
426
+ #ff0 17%,
427
+ lime 33%,
428
+ cyan 50%,
429
+ blue 67%,
430
+ magenta 83%,
431
+ red 100%
432
+ );
433
+ }
434
+
435
+ .swatch {
436
+ width: 50px;
437
+ height: 50px;
438
+ border-top-left-radius: 15px;
439
+ border-bottom-left-radius: 15px;
440
+ flex-shrink: 0;
441
+ border: 1px solid var(--block-border-color);
442
+ }
443
+
444
+ .eyedropper {
445
+ display: flex;
446
+ align-items: center;
447
+ justify-content: center;
448
+ width: 25px;
449
+ height: 30px;
450
+ border-top-right-radius: 15px;
451
+ border: 1px solid var(--block-border-color);
452
+ border-left: none;
453
+ background: var(--background-fill-secondary);
454
+ height: 30px;
455
+ padding: 7px 7px 5px 0px;
456
+ cursor: pointer;
457
+ }
458
+
459
+ .marker {
460
+ position: absolute;
461
+ width: 14px;
462
+ height: 14px;
463
+ border-radius: 50%;
464
+ border: 2px solid white;
465
+ top: -2px;
466
+ left: -7px;
467
+ box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
468
+ pointer-events: none;
469
+ }
470
+
471
+ input {
472
+ width: 100%;
473
+ height: 30px;
474
+ border: 1px solid var(--block-border-color);
475
+ border-radius: var(--radius-sm);
476
+ padding: 0 var(--size-2);
477
+ font-family: var(--font-mono);
478
+ font-size: var(--scale-000);
479
+ color: var(--block-label-text-color);
480
+ background-color: var(--background-fill-primary);
481
+ }
482
+ </style>
6.21.1/colorpicker/shared/events.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Svelte action to handle clicks outside of a DOM node
3
+ * @param node DOM node to check the click is outside of
4
+ * @param callback callback function to call if click is outside
5
+ * @returns svelte action return object with destroy method to remove event listener
6
+ */
7
+ export function click_outside(
8
+ node: Node,
9
+ callback: (arg: MouseEvent) => void
10
+ ): any {
11
+ const handle_click = (event: MouseEvent): void => {
12
+ if (
13
+ node &&
14
+ !node.contains(event.target as Node) &&
15
+ !event.defaultPrevented
16
+ ) {
17
+ callback(event);
18
+ }
19
+ };
20
+
21
+ document.addEventListener("mousedown", handle_click, true);
22
+
23
+ return {
24
+ destroy() {
25
+ document.removeEventListener("mousedown", handle_click, true);
26
+ }
27
+ };
28
+ }
6.21.1/colorpicker/shared/utils.ts ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tinycolor from "tinycolor2";
2
+
3
+ export function hsva_to_rgba(hsva: {
4
+ h: number;
5
+ s: number;
6
+ v: number;
7
+ a: number;
8
+ }): string {
9
+ const saturation = hsva.s;
10
+ const value = hsva.v;
11
+ let chroma = saturation * value;
12
+ const hue_by_60 = hsva.h / 60;
13
+ let x = chroma * (1 - Math.abs((hue_by_60 % 2) - 1));
14
+ const m = value - chroma;
15
+
16
+ chroma = chroma + m;
17
+ x = x + m;
18
+
19
+ const index = Math.floor(hue_by_60) % 6;
20
+ const red = [chroma, x, m, m, x, chroma][index];
21
+ const green = [x, chroma, chroma, x, m, m][index];
22
+ const blue = [m, m, x, chroma, chroma, x][index];
23
+
24
+ return tinycolor({
25
+ r: red * 255,
26
+ g: green * 255,
27
+ b: blue * 255,
28
+ a: hsva.a
29
+ }).toHexString();
30
+ }
31
+
32
+ export function normalize_color(color: string): string {
33
+ const tc = tinycolor(color);
34
+ if (tc.isValid()) {
35
+ return tc.toHexString();
36
+ }
37
+ return color;
38
+ }
39
+
40
+ export function format_color(
41
+ color: string,
42
+ mode: "hex" | "rgb" | "hsl"
43
+ ): string {
44
+ if (mode === "hex") {
45
+ return tinycolor(color).toHexString();
46
+ } else if (mode === "rgb") {
47
+ return tinycolor(color).toRgbString();
48
+ }
49
+ return tinycolor(color).toHslString();
50
+ }
6.21.1/colorpicker/types.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export interface ColorPickerProps {
2
+ value: string;
3
+ info: string;
4
+ }
5
+
6
+ export interface ColorPickerEvents {
7
+ change: string;
8
+ input: never;
9
+ release: string;
10
+ submit: never;
11
+ focus: never;
12
+ blur: never;
13
+ clear_status: any;
14
+ }