@gradio/imageeditor 0.18.2-dev.0 → 0.18.2
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/CHANGELOG.md +43 -0
- package/Index.svelte +122 -159
- package/InteractiveImageEditor.svelte +1 -0
- package/dist/Example.svelte +7 -4
- package/dist/Example.svelte.d.ts +20 -18
- package/dist/Index.svelte +152 -136
- package/dist/Index.svelte.d.ts +18 -202
- package/dist/InteractiveImageEditor.svelte +205 -148
- package/dist/InteractiveImageEditor.svelte.d.ts +55 -51
- package/dist/shared/Anchor.svelte +210 -136
- package/dist/shared/Anchor.svelte.d.ts +18 -16
- package/dist/shared/Controls.svelte +55 -36
- package/dist/shared/Controls.svelte.d.ts +35 -33
- package/dist/shared/IconButton.svelte +19 -17
- package/dist/shared/IconButton.svelte.d.ts +34 -32
- package/dist/shared/ImageEditor.svelte +673 -466
- package/dist/shared/ImageEditor.svelte.d.ts +4 -79
- package/dist/shared/Layers.svelte +52 -30
- package/dist/shared/Layers.svelte.d.ts +39 -36
- package/dist/shared/Resize.svelte +42 -21
- package/dist/shared/Resize.svelte.d.ts +29 -27
- package/dist/shared/SecondaryToolbar.svelte +17 -5
- package/dist/shared/SecondaryToolbar.svelte.d.ts +38 -36
- package/dist/shared/Toolbar.svelte +123 -69
- package/dist/shared/Toolbar.svelte.d.ts +40 -38
- package/dist/shared/brush/BrushOptions.svelte +119 -84
- package/dist/shared/brush/BrushOptions.svelte.d.ts +29 -27
- package/dist/shared/brush/BrushSize.svelte +12 -7
- package/dist/shared/brush/BrushSize.svelte.d.ts +23 -20
- package/dist/shared/brush/ColorField.svelte +49 -33
- package/dist/shared/brush/ColorField.svelte.d.ts +23 -21
- package/dist/shared/brush/ColorPicker.svelte +152 -108
- package/dist/shared/brush/ColorPicker.svelte.d.ts +19 -17
- package/dist/shared/brush/ColorSwatch.svelte +78 -46
- package/dist/shared/brush/ColorSwatch.svelte.d.ts +34 -32
- package/dist/types.d.ts +40 -0
- package/dist/types.js +25 -0
- package/package.json +12 -12
- package/shared/ImageEditor.svelte +1 -3
- package/shared/brush/BrushOptions.svelte +1 -1
- package/shared/brush/ColorPicker.svelte +2 -1
- package/types.ts +74 -0
|
@@ -1,81 +1,6 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
export declare const EDITOR_KEY: unique symbol;
|
|
3
2
|
export type context_type = "bg" | "layers" | "crop" | "draw" | "erase";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { type Brush, type Eraser } from "./brush/types";
|
|
9
|
-
import type { LayerOptions, Source, Transform, WebcamOptions } from "./types";
|
|
10
|
-
import { type ImageBlobs } from "./types";
|
|
11
|
-
declare const __propDef: {
|
|
12
|
-
props: {
|
|
13
|
-
antialias?: true;
|
|
14
|
-
changeable?: boolean;
|
|
15
|
-
sources?: Source[];
|
|
16
|
-
transforms?: Transform[];
|
|
17
|
-
canvas_size: [number, number];
|
|
18
|
-
is_dragging?: boolean;
|
|
19
|
-
background_image?: boolean;
|
|
20
|
-
brush_options: Brush;
|
|
21
|
-
eraser_options: Eraser;
|
|
22
|
-
fixed_canvas?: boolean;
|
|
23
|
-
root: string;
|
|
24
|
-
i18n: I18nFormatter;
|
|
25
|
-
upload: Client["upload"];
|
|
26
|
-
composite: FileData | null;
|
|
27
|
-
layers: FileData[];
|
|
28
|
-
background: FileData | null;
|
|
29
|
-
border_region?: number;
|
|
30
|
-
layer_options: LayerOptions;
|
|
31
|
-
current_tool: ToolbarTool;
|
|
32
|
-
webcam_options: WebcamOptions;
|
|
33
|
-
show_download_button?: boolean;
|
|
34
|
-
theme_mode: "dark" | "light";
|
|
35
|
-
full_history?: CommandNode | null;
|
|
36
|
-
has_drawn?: boolean;
|
|
37
|
-
get_blobs?: () => Promise<ImageBlobs>;
|
|
38
|
-
add_image?: (image: Blob | File) => void;
|
|
39
|
-
add_image_from_url?: (source: string | {
|
|
40
|
-
url: string;
|
|
41
|
-
meta: {
|
|
42
|
-
_type: string;
|
|
43
|
-
};
|
|
44
|
-
} | any) => Promise<void>;
|
|
45
|
-
add_layers_from_url?: (source: FileData[] | any) => Promise<void>;
|
|
46
|
-
can_undo?: boolean;
|
|
47
|
-
};
|
|
48
|
-
events: {
|
|
49
|
-
error: CustomEvent<string>;
|
|
50
|
-
drag: CustomEvent<any>;
|
|
51
|
-
clear?: CustomEvent<undefined> | undefined;
|
|
52
|
-
save: CustomEvent<void>;
|
|
53
|
-
change: CustomEvent<void>;
|
|
54
|
-
upload: CustomEvent<void>;
|
|
55
|
-
input: CustomEvent<void>;
|
|
56
|
-
download_error: CustomEvent<string>;
|
|
57
|
-
} & {
|
|
58
|
-
[evt: string]: CustomEvent<any>;
|
|
59
|
-
};
|
|
60
|
-
slots: {
|
|
61
|
-
default: {};
|
|
62
|
-
};
|
|
63
|
-
exports?: {} | undefined;
|
|
64
|
-
bindings?: string | undefined;
|
|
65
|
-
};
|
|
66
|
-
export type ImageEditorProps = typeof __propDef.props;
|
|
67
|
-
export type ImageEditorEvents = typeof __propDef.events;
|
|
68
|
-
export type ImageEditorSlots = typeof __propDef.slots;
|
|
69
|
-
export default class ImageEditor extends SvelteComponent<ImageEditorProps, ImageEditorEvents, ImageEditorSlots> {
|
|
70
|
-
get antialias(): true;
|
|
71
|
-
get get_blobs(): () => Promise<ImageBlobs>;
|
|
72
|
-
get add_image(): (image: Blob | File) => void;
|
|
73
|
-
get add_image_from_url(): (source: string | {
|
|
74
|
-
url: string;
|
|
75
|
-
meta: {
|
|
76
|
-
_type: string;
|
|
77
|
-
};
|
|
78
|
-
} | any) => Promise<void>;
|
|
79
|
-
get add_layers_from_url(): (source: FileData[] | any) => Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
export {};
|
|
3
|
+
import { ImageEditor } from "./core/editor";
|
|
4
|
+
declare const ImageEditor: any;
|
|
5
|
+
type ImageEditor = InstanceType<typeof ImageEditor>;
|
|
6
|
+
export default ImageEditor;
|
|
@@ -1,33 +1,55 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { click_outside } from "./utils/events";
|
|
3
|
+
import {
|
|
4
|
+
Layers,
|
|
5
|
+
Clear,
|
|
6
|
+
ArrowUp,
|
|
7
|
+
ArrowDown,
|
|
8
|
+
Plus,
|
|
9
|
+
Visibility,
|
|
10
|
+
VisibilityOff
|
|
11
|
+
} from "@gradio/icons";
|
|
12
|
+
import { IconButton } from "@gradio/atoms";
|
|
13
|
+
import { createEventDispatcher } from "svelte";
|
|
14
|
+
import type { Writable } from "svelte/store";
|
|
15
|
+
|
|
16
|
+
const dispatch = createEventDispatcher<{
|
|
17
|
+
new_layer: void;
|
|
18
|
+
change_layer: string;
|
|
19
|
+
move_layer: { id: string; direction: "up" | "down" };
|
|
20
|
+
delete_layer: string;
|
|
21
|
+
toggle_layer_visibility: string;
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
export let layers: Writable<{
|
|
25
|
+
active_layer: string;
|
|
26
|
+
layers: {
|
|
27
|
+
name: string;
|
|
28
|
+
id: string;
|
|
29
|
+
user_created: boolean;
|
|
30
|
+
visible: boolean;
|
|
31
|
+
}[];
|
|
32
|
+
}>;
|
|
33
|
+
export let enable_additional_layers = true;
|
|
34
|
+
export let enable_layers = true;
|
|
35
|
+
export let show_layers = false;
|
|
36
|
+
|
|
37
|
+
function new_layer(): void {
|
|
38
|
+
dispatch("new_layer");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function change_layer(id: string): void {
|
|
42
|
+
dispatch("change_layer", id);
|
|
43
|
+
show_layers = false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function move_layer(id: string, direction: "up" | "down"): void {
|
|
47
|
+
dispatch("move_layer", { id, direction });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function delete_layer(id: string): void {
|
|
51
|
+
dispatch("delete_layer", id);
|
|
52
|
+
}
|
|
31
53
|
</script>
|
|
32
54
|
|
|
33
55
|
{#if enable_layers}
|
|
@@ -1,39 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Layers } from "@gradio/icons";
|
|
2
2
|
import type { Writable } from "svelte/store";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}>;
|
|
14
|
-
enable_additional_layers?: boolean;
|
|
15
|
-
enable_layers?: boolean;
|
|
16
|
-
show_layers?: boolean;
|
|
3
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
4
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
|
+
$$bindings?: Bindings;
|
|
6
|
+
} & Exports;
|
|
7
|
+
(internal: unknown, props: Props & {
|
|
8
|
+
$$events?: Events;
|
|
9
|
+
$$slots?: Slots;
|
|
10
|
+
}): Exports & {
|
|
11
|
+
$set?: any;
|
|
12
|
+
$on?: any;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
new_layer: CustomEvent<void>;
|
|
20
|
-
change_layer: CustomEvent<string>;
|
|
21
|
-
move_layer: CustomEvent<{
|
|
22
|
-
id: string;
|
|
23
|
-
direction: "up" | "down";
|
|
24
|
-
}>;
|
|
25
|
-
delete_layer: CustomEvent<string>;
|
|
26
|
-
toggle_layer_visibility: CustomEvent<string>;
|
|
27
|
-
} & {
|
|
28
|
-
[evt: string]: CustomEvent<any>;
|
|
29
|
-
};
|
|
30
|
-
slots: {};
|
|
31
|
-
exports?: {} | undefined;
|
|
32
|
-
bindings?: string | undefined;
|
|
33
|
-
};
|
|
34
|
-
export type LayersProps = typeof __propDef.props;
|
|
35
|
-
export type LayersEvents = typeof __propDef.events;
|
|
36
|
-
export type LayersSlots = typeof __propDef.slots;
|
|
37
|
-
export default class Layers extends SvelteComponent<LayersProps, LayersEvents, LayersSlots> {
|
|
14
|
+
z_$$bindings?: Bindings;
|
|
38
15
|
}
|
|
39
|
-
|
|
16
|
+
declare const Layers: $$__sveltets_2_IsomorphicComponent<{
|
|
17
|
+
layers: Writable<{
|
|
18
|
+
active_layer: string;
|
|
19
|
+
layers: {
|
|
20
|
+
name: string;
|
|
21
|
+
id: string;
|
|
22
|
+
user_created: boolean;
|
|
23
|
+
visible: boolean;
|
|
24
|
+
}[];
|
|
25
|
+
}>;
|
|
26
|
+
enable_additional_layers?: boolean;
|
|
27
|
+
enable_layers?: boolean;
|
|
28
|
+
show_layers?: boolean;
|
|
29
|
+
}, {
|
|
30
|
+
new_layer: CustomEvent<void>;
|
|
31
|
+
change_layer: CustomEvent<string>;
|
|
32
|
+
move_layer: CustomEvent<{
|
|
33
|
+
id: string;
|
|
34
|
+
direction: "up" | "down";
|
|
35
|
+
}>;
|
|
36
|
+
delete_layer: CustomEvent<string>;
|
|
37
|
+
toggle_layer_visibility: CustomEvent<string>;
|
|
38
|
+
} & {
|
|
39
|
+
[evt: string]: CustomEvent<any>;
|
|
40
|
+
}, {}, {}, string>;
|
|
41
|
+
type Layers = InstanceType<typeof Layers>;
|
|
42
|
+
export default Layers;
|
|
@@ -1,24 +1,45 @@
|
|
|
1
|
-
<script context="module"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
export type Position =
|
|
3
|
+
| "top-left"
|
|
4
|
+
| "top"
|
|
5
|
+
| "top-right"
|
|
6
|
+
| "left"
|
|
7
|
+
| "center"
|
|
8
|
+
| "right"
|
|
9
|
+
| "bottom-left"
|
|
10
|
+
| "bottom"
|
|
11
|
+
| "bottom-right";
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { createEventDispatcher } from "svelte";
|
|
16
|
+
import type { Spring } from "svelte/motion";
|
|
17
|
+
import Anchor from "./Anchor.svelte";
|
|
18
|
+
|
|
19
|
+
export let dimensions: Spring<{ width: number; height: number }>;
|
|
20
|
+
|
|
21
|
+
const dispatch = createEventDispatcher<{
|
|
22
|
+
change: { anchor: Position; scale: boolean; width: number; height: number };
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
let selected_anchor: Position = "center";
|
|
26
|
+
let scale = false;
|
|
27
|
+
|
|
28
|
+
let new_width = $dimensions?.width;
|
|
29
|
+
let new_height = $dimensions?.height;
|
|
30
|
+
|
|
31
|
+
function handle_click(): void {
|
|
32
|
+
dispatch("change", {
|
|
33
|
+
anchor: selected_anchor,
|
|
34
|
+
scale,
|
|
35
|
+
width: new_width,
|
|
36
|
+
height: new_height
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function set_anchor(position: Position): void {
|
|
41
|
+
selected_anchor = position;
|
|
42
|
+
}
|
|
22
43
|
</script>
|
|
23
44
|
|
|
24
45
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
export type Position = "top-left" | "top" | "top-right" | "left" | "center" | "right" | "bottom-left" | "bottom" | "bottom-right";
|
|
3
2
|
import type { Spring } from "svelte/motion";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
4
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
|
+
$$bindings?: Bindings;
|
|
6
|
+
} & Exports;
|
|
7
|
+
(internal: unknown, props: Props & {
|
|
8
|
+
$$events?: Events;
|
|
9
|
+
$$slots?: Slots;
|
|
10
|
+
}): Exports & {
|
|
11
|
+
$set?: any;
|
|
12
|
+
$on?: any;
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
click: MouseEvent;
|
|
13
|
-
change: CustomEvent<{
|
|
14
|
-
anchor: Position;
|
|
15
|
-
scale: boolean;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
}>;
|
|
19
|
-
} & {
|
|
20
|
-
[evt: string]: CustomEvent<any>;
|
|
21
|
-
};
|
|
22
|
-
slots: {};
|
|
23
|
-
exports?: {} | undefined;
|
|
24
|
-
bindings?: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
export type ResizeProps = typeof __propDef.props;
|
|
27
|
-
export type ResizeEvents = typeof __propDef.events;
|
|
28
|
-
export type ResizeSlots = typeof __propDef.slots;
|
|
29
|
-
export default class Resize extends SvelteComponent<ResizeProps, ResizeEvents, ResizeSlots> {
|
|
14
|
+
z_$$bindings?: Bindings;
|
|
30
15
|
}
|
|
31
|
-
|
|
16
|
+
declare const Resize: $$__sveltets_2_IsomorphicComponent<{
|
|
17
|
+
dimensions: Spring<{
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}>;
|
|
21
|
+
}, {
|
|
22
|
+
click: PointerEvent;
|
|
23
|
+
change: CustomEvent<{
|
|
24
|
+
anchor: Position;
|
|
25
|
+
scale: boolean;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}>;
|
|
29
|
+
} & {
|
|
30
|
+
[evt: string]: CustomEvent<any>;
|
|
31
|
+
}, {}, {}, string>;
|
|
32
|
+
type Resize = InstanceType<typeof Resize>;
|
|
33
|
+
export default Resize;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export let
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Layers from "./Layers.svelte";
|
|
3
|
+
import type { Writable } from "svelte/store";
|
|
4
|
+
|
|
5
|
+
export let layers: Writable<{
|
|
6
|
+
active_layer: string;
|
|
7
|
+
layers: {
|
|
8
|
+
name: string;
|
|
9
|
+
id: string;
|
|
10
|
+
user_created: boolean;
|
|
11
|
+
visible: boolean;
|
|
12
|
+
}[];
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export let enable_additional_layers = true;
|
|
16
|
+
export let enable_layers = true;
|
|
17
|
+
export let show_layers = false;
|
|
6
18
|
</script>
|
|
7
19
|
|
|
8
20
|
<div class="toolbar-wrap-wrap">
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import type { Writable } from "svelte/store";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}>;
|
|
14
|
-
enable_additional_layers?: boolean;
|
|
15
|
-
enable_layers?: boolean;
|
|
16
|
-
show_layers?: boolean;
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
new_layer: CustomEvent<void>;
|
|
20
|
-
change_layer: CustomEvent<string>;
|
|
21
|
-
move_layer: CustomEvent<{
|
|
22
|
-
id: string;
|
|
23
|
-
direction: "up" | "down";
|
|
24
|
-
}>;
|
|
25
|
-
delete_layer: CustomEvent<string>;
|
|
26
|
-
toggle_layer_visibility: CustomEvent<string>;
|
|
27
|
-
} & {
|
|
28
|
-
[evt: string]: CustomEvent<any>;
|
|
29
|
-
};
|
|
30
|
-
slots: {};
|
|
31
|
-
exports?: {} | undefined;
|
|
32
|
-
bindings?: string | undefined;
|
|
33
|
-
};
|
|
34
|
-
export type SecondaryToolbarProps = typeof __propDef.props;
|
|
35
|
-
export type SecondaryToolbarEvents = typeof __propDef.events;
|
|
36
|
-
export type SecondaryToolbarSlots = typeof __propDef.slots;
|
|
37
|
-
export default class SecondaryToolbar extends SvelteComponent<SecondaryToolbarProps, SecondaryToolbarEvents, SecondaryToolbarSlots> {
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
38
14
|
}
|
|
39
|
-
|
|
15
|
+
declare const SecondaryToolbar: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
layers: Writable<{
|
|
17
|
+
active_layer: string;
|
|
18
|
+
layers: {
|
|
19
|
+
name: string;
|
|
20
|
+
id: string;
|
|
21
|
+
user_created: boolean;
|
|
22
|
+
visible: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
25
|
+
enable_additional_layers?: boolean;
|
|
26
|
+
enable_layers?: boolean;
|
|
27
|
+
show_layers?: boolean;
|
|
28
|
+
}, {
|
|
29
|
+
new_layer: CustomEvent<void>;
|
|
30
|
+
change_layer: CustomEvent<string>;
|
|
31
|
+
move_layer: CustomEvent<{
|
|
32
|
+
id: string;
|
|
33
|
+
direction: "up" | "down";
|
|
34
|
+
}>;
|
|
35
|
+
delete_layer: CustomEvent<string>;
|
|
36
|
+
toggle_layer_visibility: CustomEvent<string>;
|
|
37
|
+
} & {
|
|
38
|
+
[evt: string]: CustomEvent<any>;
|
|
39
|
+
}, {}, {}, string>;
|
|
40
|
+
type SecondaryToolbar = InstanceType<typeof SecondaryToolbar>;
|
|
41
|
+
export default SecondaryToolbar;
|
|
@@ -1,73 +1,127 @@
|
|
|
1
|
-
<script context="module"
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
export type Tool = "image" | "draw" | "erase" | "pan";
|
|
3
|
+
export type Subtool =
|
|
4
|
+
| "upload"
|
|
5
|
+
| "paste"
|
|
6
|
+
| "webcam"
|
|
7
|
+
| "color"
|
|
8
|
+
| "size"
|
|
9
|
+
| "crop"
|
|
10
|
+
| "remove_background"
|
|
11
|
+
| null;
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { createEventDispatcher } from "svelte";
|
|
16
|
+
import IconButton from "./IconButton.svelte";
|
|
17
|
+
import {
|
|
18
|
+
Image,
|
|
19
|
+
Brush,
|
|
20
|
+
Erase,
|
|
21
|
+
Crop,
|
|
22
|
+
Upload,
|
|
23
|
+
ImagePaste,
|
|
24
|
+
Webcam,
|
|
25
|
+
Circle,
|
|
26
|
+
Resize,
|
|
27
|
+
ColorPickerSolid
|
|
28
|
+
} from "@gradio/icons";
|
|
29
|
+
import BrushOptions from "./brush/BrushOptions.svelte";
|
|
30
|
+
import type { Source, Transform } from "./types";
|
|
31
|
+
import {
|
|
32
|
+
type Brush as BrushType,
|
|
33
|
+
type Eraser as EraserType
|
|
34
|
+
} from "./brush/types";
|
|
35
|
+
import tinycolor from "tinycolor2";
|
|
36
|
+
|
|
37
|
+
export let tool: Tool = "image";
|
|
38
|
+
export let subtool: Subtool = null;
|
|
39
|
+
|
|
40
|
+
export let background = false;
|
|
41
|
+
export let brush_options: BrushType | false;
|
|
42
|
+
export let selected_size =
|
|
43
|
+
brush_options && typeof brush_options.default_size === "number"
|
|
44
|
+
? brush_options.default_size
|
|
45
|
+
: 25;
|
|
46
|
+
export let eraser_options: EraserType;
|
|
47
|
+
export let selected_eraser_size =
|
|
48
|
+
eraser_options && typeof eraser_options.default_size === "number"
|
|
49
|
+
? eraser_options.default_size
|
|
50
|
+
: 25;
|
|
51
|
+
|
|
52
|
+
// Handle default_color including potential color-opacity tuple
|
|
53
|
+
export let selected_color =
|
|
54
|
+
brush_options &&
|
|
55
|
+
(() => {
|
|
56
|
+
const default_color = brush_options.default_color;
|
|
57
|
+
if (Array.isArray(default_color)) {
|
|
58
|
+
return default_color[0];
|
|
59
|
+
}
|
|
60
|
+
return default_color;
|
|
61
|
+
})();
|
|
62
|
+
|
|
63
|
+
// Set default opacity based on default_color if it's a tuple
|
|
64
|
+
export let selected_opacity =
|
|
65
|
+
brush_options &&
|
|
66
|
+
(() => {
|
|
67
|
+
const default_color = brush_options.default_color;
|
|
68
|
+
if (Array.isArray(default_color)) {
|
|
69
|
+
return default_color[1];
|
|
70
|
+
}
|
|
71
|
+
// Check if color string has opacity
|
|
72
|
+
const color = tinycolor(default_color);
|
|
73
|
+
if (color.getAlpha() < 1) {
|
|
74
|
+
return color.getAlpha();
|
|
75
|
+
}
|
|
76
|
+
return 1;
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
export let preview = false;
|
|
80
|
+
export let show_brush_color = false;
|
|
81
|
+
export let show_brush_size = false;
|
|
82
|
+
export let show_eraser_size = false;
|
|
83
|
+
export let sources: Source[];
|
|
84
|
+
export let transforms: Transform[];
|
|
85
|
+
let recent_colors: string[] = [];
|
|
86
|
+
|
|
87
|
+
let enable_layers = true;
|
|
88
|
+
const dispatch = createEventDispatcher<{
|
|
89
|
+
tool_change: { tool: Tool };
|
|
90
|
+
subtool_change: {
|
|
91
|
+
tool: Tool;
|
|
92
|
+
subtool: Subtool;
|
|
93
|
+
};
|
|
94
|
+
}>();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Handles tool click events
|
|
98
|
+
* @param {Tool} _tool - The selected tool
|
|
99
|
+
*/
|
|
100
|
+
function handle_tool_click(e: Event, _tool: Tool): void {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
dispatch("tool_change", { tool: _tool });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Handles subtool click events
|
|
107
|
+
* @param {Event} e - The click event
|
|
108
|
+
* @param {Subtool} _subtool - The selected subtool
|
|
109
|
+
*/
|
|
110
|
+
function handle_subtool_click(e: Event, _subtool: typeof subtool): void {
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
|
|
113
|
+
dispatch("subtool_change", { tool, subtool: _subtool });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
$: show_brush_size = tool === "draw" && subtool === "size";
|
|
117
|
+
$: show_brush_color = tool === "draw" && subtool === "color";
|
|
118
|
+
$: show_eraser_size = tool === "erase" && subtool === "size";
|
|
2
119
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Erase,
|
|
9
|
-
Crop,
|
|
10
|
-
Upload,
|
|
11
|
-
ImagePaste,
|
|
12
|
-
Webcam,
|
|
13
|
-
Circle,
|
|
14
|
-
Resize,
|
|
15
|
-
ColorPickerSolid
|
|
16
|
-
} from "@gradio/icons";
|
|
17
|
-
import BrushOptions from "./brush/BrushOptions.svelte";
|
|
18
|
-
import {
|
|
19
|
-
} from "./brush/types";
|
|
20
|
-
import tinycolor from "tinycolor2";
|
|
21
|
-
export let tool = "image";
|
|
22
|
-
export let subtool = null;
|
|
23
|
-
export let background = false;
|
|
24
|
-
export let brush_options;
|
|
25
|
-
export let selected_size = brush_options && typeof brush_options.default_size === "number" ? brush_options.default_size : 25;
|
|
26
|
-
export let eraser_options;
|
|
27
|
-
export let selected_eraser_size = eraser_options && typeof eraser_options.default_size === "number" ? eraser_options.default_size : 25;
|
|
28
|
-
export let selected_color = brush_options && (() => {
|
|
29
|
-
const default_color = brush_options.default_color;
|
|
30
|
-
if (Array.isArray(default_color)) {
|
|
31
|
-
return default_color[0];
|
|
32
|
-
}
|
|
33
|
-
return default_color;
|
|
34
|
-
})();
|
|
35
|
-
export let selected_opacity = brush_options && (() => {
|
|
36
|
-
const default_color = brush_options.default_color;
|
|
37
|
-
if (Array.isArray(default_color)) {
|
|
38
|
-
return default_color[1];
|
|
39
|
-
}
|
|
40
|
-
const color = tinycolor(default_color);
|
|
41
|
-
if (color.getAlpha() < 1) {
|
|
42
|
-
return color.getAlpha();
|
|
43
|
-
}
|
|
44
|
-
return 1;
|
|
45
|
-
})();
|
|
46
|
-
export let preview = false;
|
|
47
|
-
export let show_brush_color = false;
|
|
48
|
-
export let show_brush_size = false;
|
|
49
|
-
export let show_eraser_size = false;
|
|
50
|
-
export let sources;
|
|
51
|
-
export let transforms;
|
|
52
|
-
let recent_colors = [];
|
|
53
|
-
let enable_layers = true;
|
|
54
|
-
const dispatch = createEventDispatcher();
|
|
55
|
-
function handle_tool_click(e, _tool) {
|
|
56
|
-
e.stopPropagation();
|
|
57
|
-
dispatch("tool_change", { tool: _tool });
|
|
58
|
-
}
|
|
59
|
-
function handle_subtool_click(e, _subtool) {
|
|
60
|
-
e.stopPropagation();
|
|
61
|
-
dispatch("subtool_change", { tool, subtool: _subtool });
|
|
62
|
-
}
|
|
63
|
-
$: show_brush_size = tool === "draw" && subtool === "size";
|
|
64
|
-
$: show_brush_color = tool === "draw" && subtool === "color";
|
|
65
|
-
$: show_eraser_size = tool === "erase" && subtool === "size";
|
|
66
|
-
$: can_crop = transforms.includes("crop");
|
|
67
|
-
$: can_resize = transforms.includes("resize");
|
|
68
|
-
$: can_upload = sources.includes("upload");
|
|
69
|
-
$: can_webcam = sources.includes("webcam");
|
|
70
|
-
$: can_paste = sources.includes("clipboard");
|
|
120
|
+
$: can_crop = transforms.includes("crop");
|
|
121
|
+
$: can_resize = transforms.includes("resize");
|
|
122
|
+
$: can_upload = sources.includes("upload");
|
|
123
|
+
$: can_webcam = sources.includes("webcam");
|
|
124
|
+
$: can_paste = sources.includes("clipboard");
|
|
71
125
|
</script>
|
|
72
126
|
|
|
73
127
|
<div class="toolbar-wrap">
|