@gradio/imageeditor 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/ImageEditor.stories.svelte +1 -0
  3. package/Index.svelte +7 -2
  4. package/dist/Example.svelte +41 -0
  5. package/dist/Example.svelte.d.ts +19 -0
  6. package/dist/Index.svelte +184 -0
  7. package/dist/Index.svelte.d.ts +192 -0
  8. package/dist/shared/Controls.svelte +73 -0
  9. package/dist/shared/Controls.svelte.d.ts +24 -0
  10. package/dist/shared/ImageEditor.svelte +329 -0
  11. package/dist/shared/ImageEditor.svelte.d.ts +79 -0
  12. package/dist/shared/InteractiveImageEditor.svelte +273 -0
  13. package/dist/shared/InteractiveImageEditor.svelte.d.ts +58 -0
  14. package/dist/shared/layers/Layers.svelte +216 -0
  15. package/dist/shared/layers/Layers.svelte.d.ts +18 -0
  16. package/dist/shared/layers/utils.d.ts +69 -0
  17. package/dist/shared/layers/utils.js +131 -0
  18. package/dist/shared/tools/Brush.svelte +208 -0
  19. package/dist/shared/tools/Brush.svelte.d.ts +29 -0
  20. package/dist/shared/tools/BrushOptions.svelte +162 -0
  21. package/dist/shared/tools/BrushOptions.svelte.d.ts +29 -0
  22. package/dist/shared/tools/BrushSize.svelte +60 -0
  23. package/dist/shared/tools/BrushSize.svelte.d.ts +20 -0
  24. package/dist/shared/tools/ColorField.svelte +159 -0
  25. package/dist/shared/tools/ColorField.svelte.d.ts +20 -0
  26. package/dist/shared/tools/ColorPicker.svelte +179 -0
  27. package/dist/shared/tools/ColorPicker.svelte.d.ts +16 -0
  28. package/dist/shared/tools/ColorSwatch.svelte +183 -0
  29. package/dist/shared/tools/ColorSwatch.svelte.d.ts +30 -0
  30. package/dist/shared/tools/Crop.svelte +155 -0
  31. package/dist/shared/tools/Crop.svelte.d.ts +16 -0
  32. package/dist/shared/tools/Cropper.svelte +271 -0
  33. package/dist/shared/tools/Cropper.svelte.d.ts +41 -0
  34. package/dist/shared/tools/Handle.svelte +260 -0
  35. package/dist/shared/tools/Handle.svelte.d.ts +29 -0
  36. package/dist/shared/tools/Sources.svelte +250 -0
  37. package/dist/shared/tools/Sources.svelte.d.ts +32 -0
  38. package/dist/shared/tools/Tools.svelte +101 -0
  39. package/dist/shared/tools/Tools.svelte.d.ts +48 -0
  40. package/dist/shared/tools/brush.d.ts +62 -0
  41. package/dist/shared/tools/brush.js +133 -0
  42. package/dist/shared/tools/crop.d.ts +15 -0
  43. package/dist/shared/tools/crop.js +154 -0
  44. package/dist/shared/tools/index.d.ts +5 -0
  45. package/dist/shared/tools/index.js +5 -0
  46. package/dist/shared/tools/sources.d.ts +40 -0
  47. package/dist/shared/tools/sources.js +69 -0
  48. package/dist/shared/tools/types.d.ts +1 -0
  49. package/dist/shared/tools/types.js +1 -0
  50. package/dist/shared/utils/commands.d.ts +96 -0
  51. package/dist/shared/utils/commands.js +65 -0
  52. package/dist/shared/utils/events.d.ts +7 -0
  53. package/dist/shared/utils/events.js +22 -0
  54. package/dist/shared/utils/parse_placeholder.d.ts +1 -0
  55. package/dist/shared/utils/parse_placeholder.js +19 -0
  56. package/dist/shared/utils/pixi.d.ts +76 -0
  57. package/dist/shared/utils/pixi.js +152 -0
  58. package/package.json +28 -12
  59. package/shared/ImageEditor.svelte +8 -4
  60. package/shared/InteractiveImageEditor.svelte +29 -5
  61. package/shared/tools/Brush.svelte +4 -6
  62. package/shared/tools/BrushOptions.svelte +1 -1
  63. package/shared/tools/Crop.svelte +2 -1
  64. package/shared/utils/parse_placeholder.ts +27 -0
  65. package/shared/utils/pixi.ts +0 -1
@@ -0,0 +1,260 @@
1
+ <script>import { tick, createEventDispatcher } from "svelte";
2
+ export let type = "corner";
3
+ export let location;
4
+ export let x1 = 0;
5
+ export let y1 = 0;
6
+ export let x2 = 0;
7
+ export let y2 = 0;
8
+ let box;
9
+ let y_offset = 0;
10
+ let x_offset = 0;
11
+ const min = 100;
12
+ let active = false;
13
+ const dispatch = createEventDispatcher();
14
+ export let dragging = false;
15
+ let el;
16
+ function handle_mousedown(e) {
17
+ box = el.getBoundingClientRect();
18
+ active = true;
19
+ dragging = true;
20
+ if (["tl", "bl", "l"].includes(location))
21
+ x_offset = e.clientX - box.right;
22
+ if (["tl", "tr", "t"].includes(location))
23
+ y_offset = e.clientY - box.bottom;
24
+ if (["tr", "r", "br"].includes(location))
25
+ x_offset = e.clientX - box.left;
26
+ if (["br", "b", "bl"].includes(location))
27
+ y_offset = e.clientY - box.top;
28
+ }
29
+ function handle_mousemove(e) {
30
+ if (!active)
31
+ return;
32
+ const top_pos = e.clientY - y_offset;
33
+ const bottom_pos = e.clientY - y_offset;
34
+ const left_pos = e.clientX - x_offset;
35
+ const right_pos = e.clientX - x_offset;
36
+ if (["tl", "bl", "l"].includes(location)) {
37
+ x1 = left_pos;
38
+ }
39
+ if (["tl", "tr", "t"].includes(location)) {
40
+ y1 = top_pos;
41
+ }
42
+ if (["tr", "r", "br"].includes(location)) {
43
+ x2 = right_pos;
44
+ }
45
+ if (["br", "b", "bl"].includes(location)) {
46
+ y2 = bottom_pos;
47
+ }
48
+ }
49
+ async function handle_mouseup(e) {
50
+ await tick();
51
+ active = false;
52
+ dragging = false;
53
+ }
54
+ function make_transform(_location, x12, x22, y12, y22) {
55
+ let t = void 0;
56
+ let l = void 0;
57
+ let r = void 0;
58
+ let b = void 0;
59
+ if (box) {
60
+ if (["tl", "l", "bl"].includes(_location)) {
61
+ l = x12;
62
+ }
63
+ if (["tl", "t", "tr"].includes(_location)) {
64
+ t = y12;
65
+ }
66
+ if (["tr", "r", "br"].includes(_location)) {
67
+ r = x22;
68
+ }
69
+ if (["br", "b", "bl"].includes(_location)) {
70
+ b = y22;
71
+ }
72
+ }
73
+ dispatch("change", { top: t, bottom: b, left: l, right: r });
74
+ return "";
75
+ }
76
+ $:
77
+ transform = make_transform(location, x1, x2, y1, y2);
78
+ </script>
79
+
80
+ <svelte:window on:mousemove={handle_mousemove} on:mouseup={handle_mouseup} />
81
+
82
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
83
+ <div class="hitbox {location}" on:mousedown={handle_mousedown} style:transform>
84
+ <div class="handle {type} {location}" bind:this={el}></div>
85
+ </div>
86
+
87
+ <style>
88
+ .hitbox {
89
+ position: absolute;
90
+ width: 50px;
91
+ height: 50px;
92
+ --hitbox-mid-offset: calc(50% - 25px);
93
+ --hitbox-corner-offset: -25px;
94
+ --handle-corner-offset: calc(50% - 5px);
95
+ --handle-mid-offset: calc(50% - 2px);
96
+ z-index: var(--layer-top);
97
+ }
98
+
99
+ /* hitbox positions */
100
+ .hitbox.tl,
101
+ .hitbox.bl,
102
+ .hitbox.l {
103
+ left: var(--hitbox-corner-offset);
104
+ }
105
+
106
+ .hitbox.tr,
107
+ .hitbox.br,
108
+ .hitbox.r {
109
+ right: var(--hitbox-corner-offset);
110
+ }
111
+
112
+ .hitbox.t,
113
+ .hitbox.tr,
114
+ .hitbox.tl {
115
+ top: var(--hitbox-corner-offset);
116
+ }
117
+
118
+ .hitbox.t,
119
+ .hitbox.b {
120
+ left: var(--hitbox-mid-offset);
121
+ }
122
+
123
+ .hitbox.l,
124
+ .hitbox.r {
125
+ top: var(--hitbox-mid-offset);
126
+ }
127
+
128
+ .hitbox.b,
129
+ .hitbox.br,
130
+ .hitbox.bl {
131
+ bottom: var(--hitbox-corner-offset);
132
+ }
133
+
134
+ /* hitbox cursors */
135
+
136
+ .hitbox.tl,
137
+ .hitbox.br {
138
+ cursor: nwse-resize;
139
+ }
140
+
141
+ .hitbox.bl,
142
+ .hitbox.tr {
143
+ cursor: nesw-resize;
144
+ }
145
+
146
+ .hitbox.l,
147
+ .hitbox.r {
148
+ cursor: ew-resize;
149
+ }
150
+
151
+ .hitbox.t,
152
+ .hitbox.b {
153
+ cursor: ns-resize;
154
+ }
155
+
156
+ /* Visual handles */
157
+ .handle {
158
+ position: absolute;
159
+ }
160
+
161
+ /* square to fill in corners */
162
+ .corner {
163
+ width: 4px;
164
+ height: 4px;
165
+ background: black;
166
+ }
167
+
168
+ /* handle segment positions */
169
+ .handle.tl,
170
+ .handle.bl,
171
+ .handle.l {
172
+ left: var(--handle-corner-offset);
173
+ }
174
+
175
+ .handle.tr,
176
+ .handle.r,
177
+ .handle.br {
178
+ right: var(--handle-corner-offset);
179
+ }
180
+
181
+ .handle.tr,
182
+ .handle.t,
183
+ .handle.tl {
184
+ top: var(--handle-corner-offset);
185
+ }
186
+
187
+ .handle.br,
188
+ .handle.b,
189
+ .handle.bl {
190
+ bottom: var(--handle-corner-offset);
191
+ }
192
+
193
+ .handle.l,
194
+ .handle.r {
195
+ bottom: var(--handle-mid-offset);
196
+ }
197
+
198
+ .handle.t,
199
+ .handle.b {
200
+ left: var(--handle-mid-offset);
201
+ }
202
+
203
+ .handle::before {
204
+ position: absolute;
205
+ content: "";
206
+ width: 20px;
207
+ height: 4px;
208
+ background: black;
209
+ }
210
+
211
+ .handle::after {
212
+ position: absolute;
213
+ content: "";
214
+ width: 4px;
215
+ height: 20px;
216
+ background: black;
217
+ }
218
+
219
+ .handle.t::before,
220
+ .handle.b::before {
221
+ width: 30px;
222
+ left: -14px;
223
+ }
224
+
225
+ .handle.r::after,
226
+ .handle.l::after {
227
+ height: 30px;
228
+ top: -13px;
229
+ }
230
+
231
+ .handle.l::before,
232
+ .handle.r::before {
233
+ content: none;
234
+ }
235
+
236
+ .handle.t::after,
237
+ .handle.b::after {
238
+ content: none;
239
+ }
240
+
241
+ .handle.tr::before,
242
+ .handle.br::before {
243
+ right: 4px;
244
+ }
245
+
246
+ .handle.tl::before,
247
+ .handle.bl::before {
248
+ left: 4px;
249
+ }
250
+
251
+ .handle.tl::after,
252
+ .handle.tr::after {
253
+ top: 4px;
254
+ }
255
+
256
+ .handle.bl::after,
257
+ .handle.br::after {
258
+ bottom: 4px;
259
+ }
260
+ </style>
@@ -0,0 +1,29 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ type?: string | undefined;
5
+ location: "tl" | "tr" | "bl" | "br" | "t" | "b" | "l" | "r";
6
+ x1?: number | undefined;
7
+ y1?: number | undefined;
8
+ x2?: number | undefined;
9
+ y2?: number | undefined;
10
+ dragging?: boolean | undefined;
11
+ };
12
+ events: {
13
+ change: CustomEvent<{
14
+ top: number | undefined;
15
+ bottom: number | undefined;
16
+ left: number | undefined;
17
+ right: number | undefined;
18
+ }>;
19
+ } & {
20
+ [evt: string]: CustomEvent<any>;
21
+ };
22
+ slots: {};
23
+ };
24
+ export type HandleProps = typeof __propDef.props;
25
+ export type HandleEvents = typeof __propDef.events;
26
+ export type HandleSlots = typeof __propDef.slots;
27
+ export default class Handle extends SvelteComponent<HandleProps, HandleEvents, HandleSlots> {
28
+ }
29
+ export {};
@@ -0,0 +1,250 @@
1
+ <script>import { getContext, onMount, tick, createEventDispatcher } from "svelte";
2
+ import { TOOL_KEY } from "./Tools.svelte";
3
+ import { EDITOR_KEY } from "../ImageEditor.svelte";
4
+ import {
5
+ Image as ImageIcon,
6
+ Webcam as WebcamIcon,
7
+ ImagePaste
8
+ } from "@gradio/icons";
9
+ import { Upload } from "@gradio/upload";
10
+ import { Webcam } from "@gradio/image";
11
+ import {} from "@gradio/utils";
12
+ import { IconButton } from "@gradio/atoms";
13
+ import {} from "@gradio/client";
14
+ import { add_bg_color, add_bg_image } from "./sources";
15
+ export let background_file;
16
+ export let root;
17
+ export let sources = [
18
+ "upload",
19
+ "webcam",
20
+ "clipboard"
21
+ ];
22
+ export let mirror_webcam = true;
23
+ export let i18n;
24
+ export let upload;
25
+ export let stream_handler;
26
+ export let dragging;
27
+ const { active_tool } = getContext(TOOL_KEY);
28
+ const { pixi, dimensions, register_context, reset, editor_box } = getContext(EDITOR_KEY);
29
+ export let active_mode = null;
30
+ let background;
31
+ const dispatch = createEventDispatcher();
32
+ const sources_meta = {
33
+ upload: {
34
+ icon: ImageIcon,
35
+ label: "Upload",
36
+ order: 0,
37
+ id: "bg_upload",
38
+ cb() {
39
+ upload_component.open_file_upload();
40
+ $active_tool = "bg";
41
+ }
42
+ },
43
+ webcam: {
44
+ icon: WebcamIcon,
45
+ label: "Webcam",
46
+ order: 1,
47
+ id: "bg_webcam",
48
+ cb() {
49
+ active_mode = "webcam";
50
+ $active_tool = "bg";
51
+ }
52
+ },
53
+ clipboard: {
54
+ icon: ImagePaste,
55
+ label: "Paste",
56
+ order: 2,
57
+ id: "bg_clipboard",
58
+ cb() {
59
+ process_clipboard();
60
+ $active_tool = null;
61
+ }
62
+ }
63
+ };
64
+ $:
65
+ sources_list = sources.map((src) => sources_meta[src]).sort((a, b) => a.order - b.order);
66
+ let upload_component;
67
+ async function process_clipboard() {
68
+ const items = await navigator.clipboard.read();
69
+ for (let i = 0; i < items.length; i++) {
70
+ const type = items[i].types.find((t) => t.startsWith("image/"));
71
+ if (type) {
72
+ const blob = await items[i].getType(type);
73
+ background = blob || null;
74
+ }
75
+ }
76
+ }
77
+ function handle_upload(e) {
78
+ const file_data = e.detail;
79
+ background = file_data;
80
+ active_mode = null;
81
+ }
82
+ let should_reset = true;
83
+ async function set_background() {
84
+ if (!$pixi)
85
+ return;
86
+ if (background) {
87
+ const add_image = add_bg_image(
88
+ $pixi.background_container,
89
+ $pixi.renderer,
90
+ background,
91
+ $pixi.resize
92
+ );
93
+ $dimensions = await add_image.start();
94
+ if (should_reset) {
95
+ reset(false, $dimensions);
96
+ }
97
+ add_image.execute();
98
+ should_reset = true;
99
+ await tick();
100
+ bg = true;
101
+ }
102
+ }
103
+ async function process_bg_file(file) {
104
+ if (!file || !file.url)
105
+ return;
106
+ should_reset = false;
107
+ const blob_res = await fetch(file.url);
108
+ const blob = await blob_res.blob();
109
+ background = blob;
110
+ }
111
+ function handle_key(e) {
112
+ if (e.key === "Escape") {
113
+ active_mode = null;
114
+ }
115
+ }
116
+ $:
117
+ background && set_background();
118
+ $:
119
+ process_bg_file(background_file);
120
+ export let bg = false;
121
+ register_context("bg", {
122
+ init_fn: () => {
123
+ if (!$pixi)
124
+ return;
125
+ const add_image = add_bg_color(
126
+ $pixi.background_container,
127
+ $pixi.renderer,
128
+ "black",
129
+ ...$dimensions,
130
+ $pixi.resize
131
+ );
132
+ $dimensions = add_image.start();
133
+ add_image.execute();
134
+ },
135
+ reset_fn: () => {
136
+ }
137
+ });
138
+ </script>
139
+
140
+ <svelte:window on:keydown={handle_key} />
141
+
142
+ {#if sources.length}
143
+ <div class="source-wrap">
144
+ {#each sources_list as { icon, label, id, cb } (id)}
145
+ <IconButton
146
+ Icon={icon}
147
+ size="medium"
148
+ padded={false}
149
+ label={label + " button"}
150
+ hasPopup={true}
151
+ transparent={true}
152
+ on:click={cb}
153
+ />
154
+ {/each}
155
+ <span class="sep"></span>
156
+ </div>
157
+ <div
158
+ class="upload-container"
159
+ class:click-disabled={!!bg ||
160
+ active_mode === "webcam" ||
161
+ $active_tool !== "bg"}
162
+ style:height="{$editor_box.child_height +
163
+ ($editor_box.child_top - $editor_box.parent_top)}px"
164
+ >
165
+ <Upload
166
+ hidden={bg || active_mode === "webcam" || $active_tool !== "bg"}
167
+ bind:this={upload_component}
168
+ filetype="image/*"
169
+ on:load={handle_upload}
170
+ on:error
171
+ bind:dragging
172
+ {root}
173
+ disable_click={!sources.includes("upload")}
174
+ format="blob"
175
+ {upload}
176
+ {stream_handler}
177
+ ></Upload>
178
+ {#if active_mode === "webcam"}
179
+ <div
180
+ class="modal"
181
+ style:max-width="{$editor_box.child_width}px"
182
+ style:max-height="{$editor_box.child_height}px"
183
+ style:top="{$editor_box.child_top - $editor_box.parent_top}px"
184
+ >
185
+ <div class="modal-inner">
186
+ <Webcam
187
+ {upload}
188
+ {root}
189
+ on:capture={handle_upload}
190
+ on:error
191
+ on:drag
192
+ {mirror_webcam}
193
+ streaming={false}
194
+ mode="image"
195
+ include_audio={false}
196
+ {i18n}
197
+ />
198
+ </div>
199
+ </div>
200
+ {/if}
201
+ </div>
202
+ {/if}
203
+
204
+ <style>
205
+ .modal {
206
+ position: absolute;
207
+ height: 100%;
208
+ width: 100%;
209
+ left: 0;
210
+ right: 0;
211
+ margin: auto;
212
+ z-index: var(--layer-top);
213
+ display: flex;
214
+ align-items: center;
215
+ }
216
+
217
+ .modal-inner {
218
+ width: 100%;
219
+ }
220
+
221
+ .sep {
222
+ height: 12px;
223
+ background-color: var(--block-border-color);
224
+ width: 1px;
225
+ display: block;
226
+ margin-left: var(--spacing-xl);
227
+ }
228
+
229
+ .source-wrap {
230
+ display: flex;
231
+ justify-content: center;
232
+ align-items: center;
233
+ margin-left: var(--spacing-lg);
234
+ height: 100%;
235
+ }
236
+
237
+ .upload-container {
238
+ position: absolute;
239
+ height: 100%;
240
+ flex-shrink: 1;
241
+ max-height: 100%;
242
+ width: 100%;
243
+ left: 0;
244
+ top: 0;
245
+ }
246
+
247
+ .upload-container.click-disabled {
248
+ pointer-events: none;
249
+ }
250
+ </style>
@@ -0,0 +1,32 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { type I18nFormatter } from "@gradio/utils";
3
+ import { type Client } from "@gradio/client";
4
+ import type { FileData } from "@gradio/client";
5
+ declare const __propDef: {
6
+ props: {
7
+ background_file: FileData | null;
8
+ root: string;
9
+ sources?: ("upload" | "webcam" | "clipboard")[] | undefined;
10
+ mirror_webcam?: boolean | undefined;
11
+ i18n: I18nFormatter;
12
+ upload: Client["upload"];
13
+ stream_handler: Client["stream"];
14
+ dragging: boolean;
15
+ active_mode?: ("webcam" | "color" | null) | undefined;
16
+ bg?: boolean | undefined;
17
+ };
18
+ events: {
19
+ error: CustomEvent<any> | CustomEvent<string>;
20
+ drag: CustomEvent<any>;
21
+ upload: CustomEvent<never>;
22
+ } & {
23
+ [evt: string]: CustomEvent<any>;
24
+ };
25
+ slots: {};
26
+ };
27
+ export type SourcesProps = typeof __propDef.props;
28
+ export type SourcesEvents = typeof __propDef.events;
29
+ export type SourcesSlots = typeof __propDef.slots;
30
+ export default class Sources extends SvelteComponent<SourcesProps, SourcesEvents, SourcesSlots> {
31
+ }
32
+ export {};
@@ -0,0 +1,101 @@
1
+ <script context="module">export const TOOL_KEY = Symbol("tool");
2
+ </script>
3
+
4
+ <script>import { Toolbar, IconButton } from "@gradio/atoms";
5
+ import { getContext, setContext } from "svelte";
6
+ import { writable } from "svelte/store";
7
+ import { EDITOR_KEY } from "../ImageEditor.svelte";
8
+ import { Image, Crop, Brush, Erase } from "@gradio/icons";
9
+ import {} from "@gradio/utils";
10
+ const { active_tool, toolbar_box, editor_box } = getContext(EDITOR_KEY);
11
+ export let i18n;
12
+ let tools = [];
13
+ const cbs = {};
14
+ let current_color = writable("#000000");
15
+ const tool_context = {
16
+ current_color,
17
+ register_tool: (type, opts) => {
18
+ tools = [...tools, type];
19
+ if (opts?.cb) {
20
+ cbs[type] = opts.cb;
21
+ }
22
+ return () => {
23
+ tools = tools.filter((tool) => tool !== type);
24
+ };
25
+ },
26
+ active_tool: {
27
+ subscribe: active_tool.subscribe,
28
+ set: active_tool.set
29
+ }
30
+ };
31
+ setContext(TOOL_KEY, tool_context);
32
+ const tools_meta = {
33
+ crop: {
34
+ order: 1,
35
+ label: i18n("Transform"),
36
+ icon: Crop
37
+ },
38
+ draw: {
39
+ order: 2,
40
+ label: i18n("Draw"),
41
+ icon: Brush
42
+ },
43
+ erase: {
44
+ order: 2,
45
+ label: i18n("Erase"),
46
+ icon: Erase
47
+ },
48
+ bg: {
49
+ order: 0,
50
+ label: i18n("Background"),
51
+ icon: Image
52
+ }
53
+ };
54
+ let toolbar_width;
55
+ let toolbar_wrap;
56
+ $:
57
+ toolbar_width, $editor_box, get_dimensions();
58
+ function get_dimensions() {
59
+ if (!toolbar_wrap)
60
+ return;
61
+ $toolbar_box = toolbar_wrap.getBoundingClientRect();
62
+ }
63
+ function handle_click(e, tool) {
64
+ e.stopPropagation();
65
+ $active_tool = tool;
66
+ cbs[tool] && cbs[tool]();
67
+ }
68
+ </script>
69
+
70
+ <slot />
71
+
72
+ <div
73
+ class="toolbar-wrap"
74
+ bind:clientWidth={toolbar_width}
75
+ bind:this={toolbar_wrap}
76
+ >
77
+ <Toolbar show_border={false}>
78
+ {#each tools as tool (tool)}
79
+ <IconButton
80
+ highlight={$active_tool === tool}
81
+ on:click={(e) => handle_click(e, tool)}
82
+ Icon={tools_meta[tool].icon}
83
+ size="medium"
84
+ padded={false}
85
+ label={tools_meta[tool].label + " button"}
86
+ transparent={true}
87
+ offset={tool === "draw" ? -2 : tool === "erase" ? -6 : 0}
88
+ />
89
+ {/each}
90
+ </Toolbar>
91
+ </div>
92
+
93
+ <style>
94
+ .toolbar-wrap {
95
+ display: flex;
96
+ justify-content: center;
97
+ align-items: center;
98
+ margin-left: var(--spacing-xl);
99
+ height: 100%;
100
+ }
101
+ </style>
@@ -0,0 +1,48 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Subscriber, Invalidator, Unsubscriber, Writable } from "svelte/store";
3
+ import type { tool } from "../tools/";
4
+ export declare const TOOL_KEY: unique symbol;
5
+ type upload_tool = "bg_webcam" | "bg_upload" | "bg_clipboard" | "bg_color";
6
+ type transform_tool = "crop" | "rotate";
7
+ type brush_tool = "brush_color" | "brush_size";
8
+ type eraser_tool = "eraser_size";
9
+ export interface ToolOptions {
10
+ order: number;
11
+ label: string;
12
+ icon: typeof Image;
13
+ cb: (...args: any[]) => void;
14
+ id: upload_tool | transform_tool | brush_tool | eraser_tool;
15
+ }
16
+ export interface ToolMeta {
17
+ default: upload_tool | transform_tool | brush_tool | eraser_tool | null;
18
+ options: ToolOptions[];
19
+ }
20
+ export interface ToolContext {
21
+ register_tool: (type: tool, opts?: {
22
+ cb: () => void;
23
+ }) => () => void;
24
+ active_tool: {
25
+ set: (tool: tool) => void;
26
+ subscribe(this: void, run: Subscriber<tool | null>, invalidate?: Invalidator<tool | null>): Unsubscriber;
27
+ };
28
+ current_color: Writable<string>;
29
+ }
30
+ import { Image } from "@gradio/icons";
31
+ import { type I18nFormatter } from "@gradio/utils";
32
+ declare const __propDef: {
33
+ props: {
34
+ i18n: I18nFormatter;
35
+ };
36
+ events: {
37
+ [evt: string]: CustomEvent<any>;
38
+ };
39
+ slots: {
40
+ default: {};
41
+ };
42
+ };
43
+ export type ToolsProps = typeof __propDef.props;
44
+ export type ToolsEvents = typeof __propDef.events;
45
+ export type ToolsSlots = typeof __propDef.slots;
46
+ export default class Tools extends SvelteComponent<ToolsProps, ToolsEvents, ToolsSlots> {
47
+ }
48
+ export {};