Upload folder using huggingface_hub
Browse files
5.49.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>
|
5.49.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 type { 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 { LoadingStatus } from "@gradio/statustracker";
|
| 14 |
+
|
| 15 |
+
export let label = "ColorPicker";
|
| 16 |
+
export let info: string | undefined = undefined;
|
| 17 |
+
export let elem_id = "";
|
| 18 |
+
export let elem_classes: string[] = [];
|
| 19 |
+
export let visible: boolean | "hidden" = true;
|
| 20 |
+
export let value: string;
|
| 21 |
+
export let value_is_output = false;
|
| 22 |
+
export let show_label: boolean;
|
| 23 |
+
export let container = true;
|
| 24 |
+
export let scale: number | null = null;
|
| 25 |
+
export let min_width: number | undefined = undefined;
|
| 26 |
+
export let loading_status: LoadingStatus;
|
| 27 |
+
export let gradio: Gradio<{
|
| 28 |
+
change: never;
|
| 29 |
+
input: never;
|
| 30 |
+
submit: never;
|
| 31 |
+
blur: never;
|
| 32 |
+
focus: never;
|
| 33 |
+
clear_status: LoadingStatus;
|
| 34 |
+
}>;
|
| 35 |
+
export let interactive: boolean;
|
| 36 |
+
export let disabled = false;
|
| 37 |
+
</script>
|
| 38 |
+
|
| 39 |
+
<Block {visible} {elem_id} {elem_classes} {container} {scale} {min_width}>
|
| 40 |
+
<StatusTracker
|
| 41 |
+
autoscroll={gradio.autoscroll}
|
| 42 |
+
i18n={gradio.i18n}
|
| 43 |
+
{...loading_status}
|
| 44 |
+
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
| 45 |
+
/>
|
| 46 |
+
|
| 47 |
+
<Colorpicker
|
| 48 |
+
bind:value
|
| 49 |
+
bind:value_is_output
|
| 50 |
+
{label}
|
| 51 |
+
{info}
|
| 52 |
+
{show_label}
|
| 53 |
+
disabled={!interactive || disabled}
|
| 54 |
+
on:change={() => gradio.dispatch("change")}
|
| 55 |
+
on:input={() => gradio.dispatch("input")}
|
| 56 |
+
on:submit={() => gradio.dispatch("submit")}
|
| 57 |
+
on:blur={() => gradio.dispatch("blur")}
|
| 58 |
+
on:focus={() => gradio.dispatch("focus")}
|
| 59 |
+
/>
|
| 60 |
+
</Block>
|
5.49.1/colorpicker/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/colorpicker",
|
| 3 |
+
"version": "0.4.29",
|
| 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": "^4.0.0"
|
| 37 |
+
},
|
| 38 |
+
"repository": {
|
| 39 |
+
"type": "git",
|
| 40 |
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
| 41 |
+
"directory": "js/colorpicker"
|
| 42 |
+
}
|
| 43 |
+
}
|
5.49.1/colorpicker/shared/Colorpicker.svelte
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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atoms";
|
| 5 |
+
import { click_outside } from "./events";
|
| 6 |
+
import { Eyedropper } from "@gradio/icons";
|
| 7 |
+
import { hsva_to_rgba, format_color } from "./utils";
|
| 8 |
+
|
| 9 |
+
export let value = "#000000";
|
| 10 |
+
export let value_is_output = false;
|
| 11 |
+
export let label: string;
|
| 12 |
+
export let info: string | undefined = undefined;
|
| 13 |
+
export let disabled = false;
|
| 14 |
+
export let show_label = true;
|
| 15 |
+
|
| 16 |
+
export let current_mode: "hex" | "rgb" | "hsl" = "hex";
|
| 17 |
+
export let dialog_open = false;
|
| 18 |
+
|
| 19 |
+
let eyedropper_supported = false;
|
| 20 |
+
|
| 21 |
+
let sl_wrap: HTMLDivElement;
|
| 22 |
+
let hue_wrap: HTMLDivElement;
|
| 23 |
+
|
| 24 |
+
const dispatch = createEventDispatcher<{
|
| 25 |
+
change: string;
|
| 26 |
+
click_outside: void;
|
| 27 |
+
input: undefined;
|
| 28 |
+
submit: undefined;
|
| 29 |
+
blur: undefined;
|
| 30 |
+
focus: undefined;
|
| 31 |
+
selected: string;
|
| 32 |
+
close: void;
|
| 33 |
+
}>();
|
| 34 |
+
|
| 35 |
+
let sl_marker_pos = [0, 0];
|
| 36 |
+
let sl_rect: DOMRect | null = null;
|
| 37 |
+
let sl_moving = false;
|
| 38 |
+
let sl = [0, 0];
|
| 39 |
+
|
| 40 |
+
let hue = 0;
|
| 41 |
+
let hue_marker_pos = 0;
|
| 42 |
+
let hue_rect: DOMRect | null = null;
|
| 43 |
+
let hue_moving = false;
|
| 44 |
+
|
| 45 |
+
function handle_hue_down(
|
| 46 |
+
event: MouseEvent & { currentTarget: HTMLDivElement }
|
| 47 |
+
): void {
|
| 48 |
+
hue_rect = event.currentTarget.getBoundingClientRect();
|
| 49 |
+
hue_moving = true;
|
| 50 |
+
update_hue_from_mouse(event.clientX);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function update_hue_from_mouse(x: number): void {
|
| 54 |
+
if (!hue_rect) return;
|
| 55 |
+
const _x = Math.max(0, Math.min(x - hue_rect.left, hue_rect.width)); // Get the x-coordinate relative to the box
|
| 56 |
+
hue_marker_pos = _x;
|
| 57 |
+
const _hue = (_x / hue_rect.width) * 360; // Scale the x position to a hue value (0-360)
|
| 58 |
+
|
| 59 |
+
hue = _hue;
|
| 60 |
+
|
| 61 |
+
value = hsva_to_rgba({ h: _hue, s: sl[0], v: sl[1], a: 1 });
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function update_color_from_mouse(x: number, y: number): void {
|
| 65 |
+
if (!sl_rect) return;
|
| 66 |
+
const _x = Math.max(0, Math.min(x - sl_rect.left, sl_rect.width));
|
| 67 |
+
const _y = Math.max(0, Math.min(y - sl_rect.top, sl_rect.height));
|
| 68 |
+
sl_marker_pos = [_x, _y];
|
| 69 |
+
const _hsva = {
|
| 70 |
+
h: hue * 1,
|
| 71 |
+
s: _x / sl_rect.width,
|
| 72 |
+
v: 1 - _y / sl_rect.height,
|
| 73 |
+
a: 1
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
sl = [_hsva.s, _hsva.v];
|
| 77 |
+
|
| 78 |
+
value = hsva_to_rgba(_hsva);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function handle_sl_down(
|
| 82 |
+
event: MouseEvent & { currentTarget: HTMLDivElement }
|
| 83 |
+
): void {
|
| 84 |
+
sl_moving = true;
|
| 85 |
+
sl_rect = event.currentTarget.getBoundingClientRect();
|
| 86 |
+
update_color_from_mouse(event.clientX, event.clientY);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
function handle_move(event: MouseEvent): void {
|
| 90 |
+
if (sl_moving) update_color_from_mouse(event.clientX, event.clientY);
|
| 91 |
+
if (hue_moving) update_hue_from_mouse(event.clientX);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
function handle_end(): void {
|
| 95 |
+
sl_moving = false;
|
| 96 |
+
hue_moving = false;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
async function update_mouse_from_color(color: string): Promise<void> {
|
| 100 |
+
if (sl_moving || hue_moving) return;
|
| 101 |
+
await tick();
|
| 102 |
+
if (!color) return;
|
| 103 |
+
|
| 104 |
+
if (!sl_rect && sl_wrap) {
|
| 105 |
+
sl_rect = sl_wrap.getBoundingClientRect();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (!hue_rect && hue_wrap) {
|
| 109 |
+
hue_rect = hue_wrap.getBoundingClientRect();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Exit if we still don't have valid rectangles
|
| 113 |
+
if (!sl_rect || !hue_rect) return;
|
| 114 |
+
|
| 115 |
+
const hsva = tinycolor(color).toHsv();
|
| 116 |
+
const _x = hsva.s * sl_rect.width;
|
| 117 |
+
const _y = (1 - hsva.v) * sl_rect.height;
|
| 118 |
+
sl_marker_pos = [_x, _y];
|
| 119 |
+
sl = [hsva.s, hsva.v];
|
| 120 |
+
hue = hsva.h;
|
| 121 |
+
hue_marker_pos = (hsva.h / 360) * hue_rect.width;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function request_eyedropper(): void {
|
| 125 |
+
// @ts-ignore
|
| 126 |
+
const eyeDropper = new EyeDropper();
|
| 127 |
+
|
| 128 |
+
eyeDropper.open().then((result: { sRGBHex: string }) => {
|
| 129 |
+
value = result.sRGBHex;
|
| 130 |
+
});
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
const modes = [
|
| 134 |
+
["Hex", "hex"],
|
| 135 |
+
["RGB", "rgb"],
|
| 136 |
+
["HSL", "hsl"]
|
| 137 |
+
] as const;
|
| 138 |
+
|
| 139 |
+
$: color_string = format_color(value, current_mode);
|
| 140 |
+
$: color_string && dispatch("selected", color_string);
|
| 141 |
+
|
| 142 |
+
onMount(async () => {
|
| 143 |
+
// @ts-ignore
|
| 144 |
+
eyedropper_supported = window !== undefined && !!window.EyeDropper;
|
| 145 |
+
});
|
| 146 |
+
|
| 147 |
+
function handle_click_outside(): void {
|
| 148 |
+
dialog_open = false;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function handle_change(): void {
|
| 152 |
+
dispatch("change", value);
|
| 153 |
+
if (!value_is_output) {
|
| 154 |
+
dispatch("input");
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
afterUpdate(() => {
|
| 159 |
+
value_is_output = false;
|
| 160 |
+
});
|
| 161 |
+
|
| 162 |
+
$: update_mouse_from_color(value);
|
| 163 |
+
$: value, handle_change();
|
| 164 |
+
|
| 165 |
+
function handle_click(): void {
|
| 166 |
+
dispatch("selected", color_string);
|
| 167 |
+
dispatch("close");
|
| 168 |
+
}
|
| 169 |
+
</script>
|
| 170 |
+
|
| 171 |
+
<BlockTitle {show_label} {info}>{label}</BlockTitle>
|
| 172 |
+
<button
|
| 173 |
+
class="dialog-button"
|
| 174 |
+
style:background={value}
|
| 175 |
+
{disabled}
|
| 176 |
+
on:click={() => {
|
| 177 |
+
update_mouse_from_color(value);
|
| 178 |
+
dialog_open = !dialog_open;
|
| 179 |
+
}}
|
| 180 |
+
/>
|
| 181 |
+
|
| 182 |
+
<svelte:window on:mousemove={handle_move} on:mouseup={handle_end} />
|
| 183 |
+
|
| 184 |
+
{#if dialog_open}
|
| 185 |
+
<div
|
| 186 |
+
class="color-picker"
|
| 187 |
+
on:focus
|
| 188 |
+
on:blur
|
| 189 |
+
use:click_outside={handle_click_outside}
|
| 190 |
+
>
|
| 191 |
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 192 |
+
<div
|
| 193 |
+
class="color-gradient"
|
| 194 |
+
on:mousedown={handle_sl_down}
|
| 195 |
+
style="--hue:{hue}"
|
| 196 |
+
bind:this={sl_wrap}
|
| 197 |
+
>
|
| 198 |
+
<div
|
| 199 |
+
class="marker"
|
| 200 |
+
style:transform="translate({sl_marker_pos[0]}px,{sl_marker_pos[1]}px)"
|
| 201 |
+
style:background={value}
|
| 202 |
+
/>
|
| 203 |
+
</div>
|
| 204 |
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
| 205 |
+
<div class="hue-slider" on:mousedown={handle_hue_down} bind:this={hue_wrap}>
|
| 206 |
+
<div
|
| 207 |
+
class="marker"
|
| 208 |
+
style:background={"hsl(" + hue + ", 100%, 50%)"}
|
| 209 |
+
style:transform="translateX({hue_marker_pos}px)"
|
| 210 |
+
/>
|
| 211 |
+
</div>
|
| 212 |
+
|
| 213 |
+
<div class="input">
|
| 214 |
+
<button class="swatch" style:background={value} on:click={handle_click}
|
| 215 |
+
></button>
|
| 216 |
+
<div>
|
| 217 |
+
<div class="input-wrap">
|
| 218 |
+
<input
|
| 219 |
+
type="text"
|
| 220 |
+
bind:value={color_string}
|
| 221 |
+
on:change={(e) => (value = e.currentTarget.value)}
|
| 222 |
+
/>
|
| 223 |
+
<button class="eyedropper" on:click={request_eyedropper}>
|
| 224 |
+
{#if eyedropper_supported}
|
| 225 |
+
<Eyedropper />
|
| 226 |
+
{/if}
|
| 227 |
+
</button>
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<div class="buttons">
|
| 231 |
+
{#each modes as [label, value]}
|
| 232 |
+
<button
|
| 233 |
+
class="button"
|
| 234 |
+
class:active={current_mode === value}
|
| 235 |
+
on:click={() => (current_mode = value)}>{label}</button
|
| 236 |
+
>
|
| 237 |
+
{/each}
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
{/if}
|
| 243 |
+
|
| 244 |
+
<style>
|
| 245 |
+
.dialog-button {
|
| 246 |
+
display: block;
|
| 247 |
+
width: var(--size-10);
|
| 248 |
+
height: var(--size-5);
|
| 249 |
+
border: var(--block-border-width) solid var(--block-border-color);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
.dialog-button:disabled {
|
| 253 |
+
cursor: not-allowed;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
.input {
|
| 257 |
+
display: flex;
|
| 258 |
+
align-items: center;
|
| 259 |
+
padding: 0 10px 15px;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
.input input {
|
| 263 |
+
height: 30px;
|
| 264 |
+
width: 100%;
|
| 265 |
+
flex-shrink: 1;
|
| 266 |
+
border-bottom-left-radius: 0;
|
| 267 |
+
border: 1px solid var(--block-border-color);
|
| 268 |
+
letter-spacing: -0.05rem;
|
| 269 |
+
border-left: none;
|
| 270 |
+
border-right: none;
|
| 271 |
+
font-family: var(--font-mono);
|
| 272 |
+
font-size: var(--scale-000);
|
| 273 |
+
padding-left: 15px;
|
| 274 |
+
padding-right: 0;
|
| 275 |
+
background-color: var(--background-fill-secondary);
|
| 276 |
+
color: var(--block-label-text-color);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
.swatch {
|
| 280 |
+
width: 50px;
|
| 281 |
+
height: 50px;
|
| 282 |
+
border-top-left-radius: 15px;
|
| 283 |
+
border-bottom-left-radius: 15px;
|
| 284 |
+
flex-shrink: 0;
|
| 285 |
+
border: 1px solid var(--block-border-color);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
.color-picker {
|
| 289 |
+
width: 230px;
|
| 290 |
+
background: var(--background-fill-secondary);
|
| 291 |
+
border: 1px solid var(--block-border-color);
|
| 292 |
+
border-radius: var(--block-radius);
|
| 293 |
+
margin: var(--spacing-sm) 0;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.buttons {
|
| 297 |
+
height: 20px;
|
| 298 |
+
display: flex;
|
| 299 |
+
justify-content: stretch;
|
| 300 |
+
gap: 0px;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
.buttons button {
|
| 304 |
+
display: flex;
|
| 305 |
+
align-items: center;
|
| 306 |
+
justify-content: center;
|
| 307 |
+
border: 1px solid var(--block-border-color);
|
| 308 |
+
background: var(--background-fill-secondary);
|
| 309 |
+
padding: 3px 6px;
|
| 310 |
+
font-size: var(--scale-000);
|
| 311 |
+
cursor: pointer;
|
| 312 |
+
border-right: none;
|
| 313 |
+
width: 100%;
|
| 314 |
+
border-top: none;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
.buttons button:first-child {
|
| 318 |
+
border-left: none;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
.buttons button:last-child {
|
| 322 |
+
border-bottom-right-radius: 15px;
|
| 323 |
+
border-right: 1px solid var(--block-border-color);
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
.buttons button:hover {
|
| 327 |
+
background: var(--background-fill-secondary-hover);
|
| 328 |
+
font-weight: var(--weight-bold);
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
.buttons button.active {
|
| 332 |
+
background: var(--background-fill-secondary);
|
| 333 |
+
font-weight: var(--weight-bold);
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
.input-wrap {
|
| 337 |
+
display: flex;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.color-gradient {
|
| 341 |
+
position: relative;
|
| 342 |
+
--hue: white;
|
| 343 |
+
background: linear-gradient(rgba(0, 0, 0, 0), #000),
|
| 344 |
+
linear-gradient(90deg, #fff, hsl(var(--hue), 100%, 50%));
|
| 345 |
+
width: 100%;
|
| 346 |
+
height: 150px;
|
| 347 |
+
border-radius: var(--radius-sm) var(--radius-sm) 0 0;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
.hue-slider {
|
| 351 |
+
position: relative;
|
| 352 |
+
width: 90%;
|
| 353 |
+
margin: 10px auto;
|
| 354 |
+
height: 10px;
|
| 355 |
+
border-radius: 5px;
|
| 356 |
+
background: linear-gradient(
|
| 357 |
+
to right,
|
| 358 |
+
hsl(0, 100%, 50%) 0%,
|
| 359 |
+
#ff0 17%,
|
| 360 |
+
lime 33%,
|
| 361 |
+
cyan 50%,
|
| 362 |
+
blue 67%,
|
| 363 |
+
magenta 83%,
|
| 364 |
+
red 100%
|
| 365 |
+
);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
.swatch {
|
| 369 |
+
width: 50px;
|
| 370 |
+
height: 50px;
|
| 371 |
+
border-top-left-radius: 15px;
|
| 372 |
+
border-bottom-left-radius: 15px;
|
| 373 |
+
flex-shrink: 0;
|
| 374 |
+
border: 1px solid var(--block-border-color);
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
.eyedropper {
|
| 378 |
+
display: flex;
|
| 379 |
+
align-items: center;
|
| 380 |
+
justify-content: center;
|
| 381 |
+
width: 25px;
|
| 382 |
+
height: 30px;
|
| 383 |
+
border-top-right-radius: 15px;
|
| 384 |
+
border: 1px solid var(--block-border-color);
|
| 385 |
+
border-left: none;
|
| 386 |
+
background: var(--background-fill-secondary);
|
| 387 |
+
height: 30px;
|
| 388 |
+
padding: 7px 7px 5px 0px;
|
| 389 |
+
cursor: pointer;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
.marker {
|
| 393 |
+
position: absolute;
|
| 394 |
+
width: 14px;
|
| 395 |
+
height: 14px;
|
| 396 |
+
border-radius: 50%;
|
| 397 |
+
border: 2px solid white;
|
| 398 |
+
top: -2px;
|
| 399 |
+
left: -7px;
|
| 400 |
+
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
|
| 401 |
+
pointer-events: none;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
input {
|
| 405 |
+
width: 100%;
|
| 406 |
+
height: 30px;
|
| 407 |
+
border: 1px solid var(--block-border-color);
|
| 408 |
+
border-radius: var(--radius-sm);
|
| 409 |
+
padding: 0 var(--size-2);
|
| 410 |
+
font-family: var(--font-mono);
|
| 411 |
+
font-size: var(--scale-000);
|
| 412 |
+
color: var(--block-label-text-color);
|
| 413 |
+
background-color: var(--background-fill-primary);
|
| 414 |
+
}
|
| 415 |
+
</style>
|
5.49.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 |
+
}
|
5.49.1/colorpicker/shared/utils.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 `rgba(${red * 255}, ${green * 255}, ${blue * 255}, ${hsva.a})`;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export function format_color(
|
| 28 |
+
color: string,
|
| 29 |
+
mode: "hex" | "rgb" | "hsl"
|
| 30 |
+
): string {
|
| 31 |
+
if (mode === "hex") {
|
| 32 |
+
return tinycolor(color).toHexString();
|
| 33 |
+
} else if (mode === "rgb") {
|
| 34 |
+
return tinycolor(color).toRgbString();
|
| 35 |
+
}
|
| 36 |
+
return tinycolor(color).toHslString();
|
| 37 |
+
}
|