-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Image.svelte
107 lines (101 loc) 路 2.57 KB
/
Image.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<svelte:options accessors={true} />
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { Image, StaticImage } from "@gradio/image";
import { Block } from "@gradio/atoms";
import { _ } from "svelte-i18n";
import { Component as StatusTracker } from "../StatusTracker/";
import type { LoadingStatus } from "../StatusTracker/types";
import UploadText from "../UploadText.svelte";
export let elem_id = "";
export let elem_classes: string[] = [];
export let visible = true;
export let value: null | string = null;
export let source: "canvas" | "webcam" | "upload" = "upload";
export let tool: "editor" | "select" | "sketch" | "color-sketch" = "editor";
export let label: string;
export let show_label: boolean;
export let show_download_button: boolean;
export let streaming: boolean;
export let pending: boolean;
export let height: number | undefined;
export let width: number | undefined;
export let mirror_webcam: boolean;
export let shape: [number, number];
export let brush_radius: number;
export let selectable = false;
export let container = true;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let mode: "static" | "dynamic";
export let show_share_button = false;
const dispatch = createEventDispatcher<{
change: undefined;
error: string;
}>();
$: value, dispatch("change");
let dragging: boolean;
const FIXED_HEIGHT = 240;
$: value = !value ? null : value;
</script>
<Block
{visible}
variant={mode === "dynamic" && value === null && source === "upload"
? "dashed"
: "solid"}
border_mode={dragging ? "focus" : "base"}
padding={false}
{elem_id}
{elem_classes}
height={height ||
(source === "webcam" || mode === "static" ? undefined : FIXED_HEIGHT)}
{width}
allow_overflow={false}
{container}
{scale}
{min_width}
>
<StatusTracker {...loading_status} />
{#if mode === "static"}
<StaticImage
on:select
on:share
on:error
{value}
{label}
{show_label}
{show_download_button}
{selectable}
{show_share_button}
/>
{:else}
<Image
{brush_radius}
{shape}
bind:value
{source}
{tool}
{selectable}
on:edit
on:clear
on:stream
on:drag={({ detail }) => (dragging = detail)}
on:upload
on:select
on:share
on:error={({ detail }) => {
loading_status = loading_status || {};
loading_status.status = "error";
dispatch("error", detail);
}}
{label}
{show_label}
{pending}
{streaming}
{mirror_webcam}
>
<UploadText type="image" />
</Image>
{/if}
</Block>