@gradio/imageslider 0.5.0 → 0.7.0
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 +45 -0
- package/Example.svelte +11 -4
- package/ImageSlider.test.ts +32 -0
- package/Index.svelte +16 -49
- package/dist/Example.svelte +11 -4
- package/dist/Example.svelte.d.ts +4 -18
- package/dist/Index.svelte +16 -49
- package/dist/shared/ClearImage.svelte +2 -3
- package/dist/shared/ClearImage.svelte.d.ts +5 -19
- package/dist/shared/Image.svelte +67 -45
- package/dist/shared/Image.svelte.d.ts +14 -40
- package/dist/shared/ImageEl.svelte +22 -23
- package/dist/shared/ImageEl.svelte.d.ts +7 -22
- package/dist/shared/Slider.svelte +34 -19
- package/dist/shared/Slider.svelte.d.ts +8 -29
- package/dist/shared/SliderPreview.svelte +85 -47
- package/dist/shared/SliderPreview.svelte.d.ts +8 -23
- package/dist/shared/SliderUpload.svelte +43 -20
- package/dist/shared/SliderUpload.svelte.d.ts +11 -49
- package/dist/types.d.ts +1 -1
- package/package.json +7 -7
- package/shared/ClearImage.svelte +2 -3
- package/shared/Image.svelte +67 -45
- package/shared/ImageEl.svelte +22 -23
- package/shared/Slider.svelte +34 -19
- package/shared/SliderPreview.svelte +85 -47
- package/shared/SliderUpload.svelte +43 -20
- package/types.ts +1 -1
|
@@ -1,30 +1,13 @@
|
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
1
2
|
import { Image } from "@gradio/icons";
|
|
2
|
-
import { type
|
|
3
|
+
import { type I18nFormatter } from "@gradio/utils";
|
|
3
4
|
import { type FileData, type Client } from "@gradio/client";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} & Exports;
|
|
8
|
-
(internal: unknown, props: Props & {
|
|
9
|
-
$$events?: Events;
|
|
10
|
-
$$slots?: Slots;
|
|
11
|
-
}): Exports & {
|
|
12
|
-
$set?: any;
|
|
13
|
-
$on?: any;
|
|
14
|
-
};
|
|
15
|
-
z_$$bindings?: Bindings;
|
|
16
|
-
}
|
|
17
|
-
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
18
|
-
default: any;
|
|
19
|
-
} ? Props extends Record<string, never> ? any : {
|
|
20
|
-
children?: any;
|
|
21
|
-
} : {});
|
|
22
|
-
declare const Image: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
23
|
-
value: [FileData | null, FileData | null];
|
|
24
|
-
label?: string | undefined;
|
|
5
|
+
type $$ComponentProps = {
|
|
6
|
+
value?: [FileData | null, FileData | null];
|
|
7
|
+
label?: string;
|
|
25
8
|
show_label: boolean;
|
|
26
9
|
root: string;
|
|
27
|
-
position
|
|
10
|
+
position?: number;
|
|
28
11
|
upload_count?: number;
|
|
29
12
|
show_download_button?: boolean;
|
|
30
13
|
slider_color: string;
|
|
@@ -33,22 +16,13 @@ declare const Image: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWith
|
|
|
33
16
|
max_file_size?: number | null;
|
|
34
17
|
i18n: I18nFormatter;
|
|
35
18
|
max_height: number;
|
|
36
|
-
upload_promise?: Promise<any
|
|
19
|
+
upload_promise?: Promise<any>;
|
|
37
20
|
dragging?: boolean;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
drag: CustomEvent<boolean>;
|
|
46
|
-
upload: CustomEvent<[FileData | null, FileData | null]>;
|
|
47
|
-
select: CustomEvent<SelectData>;
|
|
48
|
-
} & {
|
|
49
|
-
[evt: string]: CustomEvent<any>;
|
|
50
|
-
}, {
|
|
51
|
-
default: {};
|
|
52
|
-
}, {}, string>;
|
|
53
|
-
type Image = InstanceType<typeof Image>;
|
|
21
|
+
onclear?: () => void;
|
|
22
|
+
ondrag?: (dragging: boolean) => void;
|
|
23
|
+
onupload?: (value: [FileData | null, FileData | null]) => void;
|
|
24
|
+
children?: Snippet;
|
|
25
|
+
};
|
|
26
|
+
declare const Image: import("svelte").Component<$$ComponentProps, {}, "value" | "position" | "dragging" | "upload_promise">;
|
|
27
|
+
type Image = ReturnType<typeof Image>;
|
|
54
28
|
export default Image;
|
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLImgAttributes } from "svelte/elements";
|
|
3
|
-
import {
|
|
4
|
-
interface Props extends HTMLImgAttributes {
|
|
3
|
+
import { onMount, tick } from "svelte";
|
|
4
|
+
interface Props extends Omit<HTMLImgAttributes, "onload"> {
|
|
5
5
|
"data-testid"?: string;
|
|
6
6
|
fixed?: boolean;
|
|
7
7
|
transform?: string;
|
|
8
|
-
img_el?: HTMLImageElement;
|
|
8
|
+
img_el?: HTMLImageElement | null;
|
|
9
9
|
hidden?: boolean;
|
|
10
10
|
variant?: "preview" | "upload";
|
|
11
11
|
max_height?: number;
|
|
12
12
|
fullscreen?: boolean;
|
|
13
|
-
|
|
14
|
-
type $$Props = Props;
|
|
15
|
-
|
|
16
|
-
export let src: HTMLImgAttributes["src"] = undefined;
|
|
17
|
-
export let fullscreen = false;
|
|
18
|
-
|
|
19
|
-
export let fixed = false;
|
|
20
|
-
export let transform = "translate(0px, 0px) scale(1)";
|
|
21
|
-
export let img_el: HTMLImageElement | null = null;
|
|
22
|
-
export let hidden = false;
|
|
23
|
-
export let variant = "upload";
|
|
24
|
-
export let max_height = 500;
|
|
25
|
-
|
|
26
|
-
const dispatch = createEventDispatcher<{
|
|
27
|
-
load: {
|
|
13
|
+
onload?: (size: {
|
|
28
14
|
top: number;
|
|
29
15
|
left: number;
|
|
30
16
|
width: number;
|
|
31
17
|
height: number;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
src = undefined,
|
|
23
|
+
fullscreen = false,
|
|
24
|
+
fixed = false,
|
|
25
|
+
transform = "translate(0px, 0px) scale(1)",
|
|
26
|
+
img_el = $bindable<HTMLImageElement | null>(),
|
|
27
|
+
hidden = false,
|
|
28
|
+
variant = "upload",
|
|
29
|
+
max_height = 500,
|
|
30
|
+
onload,
|
|
31
|
+
...restProps
|
|
32
|
+
}: Props = $props();
|
|
34
33
|
|
|
35
34
|
function get_image_size(img: HTMLImageElement | null): {
|
|
36
35
|
top: number;
|
|
@@ -70,7 +69,7 @@
|
|
|
70
69
|
const resizer = new ResizeObserver(async (entries) => {
|
|
71
70
|
for (const entry of entries) {
|
|
72
71
|
await tick();
|
|
73
|
-
|
|
72
|
+
onload?.(get_image_size(img_el));
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
|
|
@@ -86,7 +85,7 @@
|
|
|
86
85
|
<img
|
|
87
86
|
{src}
|
|
88
87
|
data-testid="imageslider-image"
|
|
89
|
-
{
|
|
88
|
+
{...restProps}
|
|
90
89
|
class:fixed
|
|
91
90
|
style:transform
|
|
92
91
|
bind:this={img_el}
|
|
@@ -96,7 +95,7 @@
|
|
|
96
95
|
style:max-height={max_height && !fullscreen ? `${max_height}px` : null}
|
|
97
96
|
class:fullscreen
|
|
98
97
|
class:small={!fullscreen}
|
|
99
|
-
|
|
98
|
+
onload={() => onload?.(get_image_size(img_el))}
|
|
100
99
|
/>
|
|
101
100
|
|
|
102
101
|
<style>
|
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
import type { HTMLImgAttributes } from "svelte/elements";
|
|
2
|
-
interface
|
|
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;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const ImageEl: $$__sveltets_2_IsomorphicComponent<HTMLImgAttributes & {
|
|
2
|
+
interface Props extends Omit<HTMLImgAttributes, "onload"> {
|
|
16
3
|
"data-testid"?: string;
|
|
17
4
|
fixed?: boolean;
|
|
18
5
|
transform?: string;
|
|
19
|
-
img_el?: HTMLImageElement;
|
|
6
|
+
img_el?: HTMLImageElement | null;
|
|
20
7
|
hidden?: boolean;
|
|
21
8
|
variant?: "preview" | "upload";
|
|
22
9
|
max_height?: number;
|
|
23
10
|
fullscreen?: boolean;
|
|
24
|
-
|
|
25
|
-
load: CustomEvent<{
|
|
11
|
+
onload?: (size: {
|
|
26
12
|
top: number;
|
|
27
13
|
left: number;
|
|
28
14
|
width: number;
|
|
29
15
|
height: number;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type ImageEl = InstanceType<typeof ImageEl>;
|
|
16
|
+
}) => void;
|
|
17
|
+
}
|
|
18
|
+
declare const ImageEl: import("svelte").Component<Props, {}, "img_el">;
|
|
19
|
+
type ImageEl = ReturnType<typeof ImageEl>;
|
|
35
20
|
export default ImageEl;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { onMount } from "svelte";
|
|
2
|
+
import { onMount, type Snippet } from "svelte";
|
|
3
3
|
import { drag } from "d3-drag";
|
|
4
4
|
import { select } from "d3-selection";
|
|
5
5
|
|
|
@@ -7,22 +7,33 @@
|
|
|
7
7
|
return Math.min(Math.max(value, min), max);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let {
|
|
11
|
+
position = $bindable(0.5),
|
|
12
|
+
disabled = false,
|
|
13
|
+
slider_color = "var(--border-color-primary)",
|
|
14
|
+
image_size = { top: 0, left: 0, width: 0, height: 0 },
|
|
15
|
+
el = $bindable<HTMLDivElement | undefined>(undefined),
|
|
16
|
+
parent_el = $bindable<HTMLDivElement | undefined>(undefined),
|
|
17
|
+
children
|
|
18
|
+
}: {
|
|
19
|
+
position?: number;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
slider_color?: string;
|
|
22
|
+
image_size?: {
|
|
23
|
+
top: number;
|
|
24
|
+
left: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
|
28
|
+
el?: HTMLDivElement;
|
|
29
|
+
parent_el?: HTMLDivElement;
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
} = $props();
|
|
12
32
|
|
|
13
|
-
export let slider_color = "var(--border-color-primary)";
|
|
14
|
-
export let image_size: {
|
|
15
|
-
top: number;
|
|
16
|
-
left: number;
|
|
17
|
-
width: number;
|
|
18
|
-
height: number;
|
|
19
|
-
} = { top: 0, left: 0, width: 0, height: 0 };
|
|
20
|
-
export let el: HTMLDivElement | undefined = undefined;
|
|
21
|
-
export let parent_el: HTMLDivElement | undefined = undefined;
|
|
22
33
|
let inner: Element;
|
|
23
|
-
let px = 0;
|
|
24
|
-
let active = false;
|
|
25
|
-
let container_width = 0;
|
|
34
|
+
let px = $state(0);
|
|
35
|
+
let active = $state(false);
|
|
36
|
+
let container_width = $state(0);
|
|
26
37
|
|
|
27
38
|
function set_position(width: number): void {
|
|
28
39
|
container_width = parent_el?.getBoundingClientRect().width || 0;
|
|
@@ -67,8 +78,12 @@
|
|
|
67
78
|
px = clamp(image_size.width * pc + image_size.left, 0, container_width);
|
|
68
79
|
}
|
|
69
80
|
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
$effect(() => {
|
|
82
|
+
set_position(image_size.width);
|
|
83
|
+
});
|
|
84
|
+
$effect(() => {
|
|
85
|
+
update_position_from_pc(position);
|
|
86
|
+
});
|
|
72
87
|
|
|
73
88
|
onMount(() => {
|
|
74
89
|
set_position(image_size.width);
|
|
@@ -80,11 +95,11 @@
|
|
|
80
95
|
});
|
|
81
96
|
</script>
|
|
82
97
|
|
|
83
|
-
<svelte:window
|
|
98
|
+
<svelte:window onresize={() => set_position(image_size.width)} />
|
|
84
99
|
|
|
85
100
|
<div class="wrap" role="none" bind:this={parent_el}>
|
|
86
101
|
<div class="content" bind:this={el}>
|
|
87
|
-
|
|
102
|
+
{#if children}{@render children()}{/if}
|
|
88
103
|
</div>
|
|
89
104
|
<div
|
|
90
105
|
class="outer"
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: Props & {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
15
|
-
default: any;
|
|
16
|
-
} ? Props extends Record<string, never> ? any : {
|
|
17
|
-
children?: any;
|
|
18
|
-
} : {});
|
|
19
|
-
declare const Slider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
1
|
+
import { type Snippet } from "svelte";
|
|
2
|
+
type $$ComponentProps = {
|
|
20
3
|
position?: number;
|
|
21
4
|
disabled?: boolean;
|
|
22
5
|
slider_color?: string;
|
|
@@ -26,14 +9,10 @@ declare const Slider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWit
|
|
|
26
9
|
width: number;
|
|
27
10
|
height: number;
|
|
28
11
|
};
|
|
29
|
-
el?: HTMLDivElement
|
|
30
|
-
parent_el?: HTMLDivElement
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}, {
|
|
36
|
-
default: {};
|
|
37
|
-
}, {}, string>;
|
|
38
|
-
type Slider = InstanceType<typeof Slider>;
|
|
12
|
+
el?: HTMLDivElement;
|
|
13
|
+
parent_el?: HTMLDivElement;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
};
|
|
16
|
+
declare const Slider: import("svelte").Component<$$ComponentProps, {}, "position" | "el" | "parent_el">;
|
|
17
|
+
type Slider = ReturnType<typeof Slider>;
|
|
39
18
|
export default Slider;
|
|
@@ -16,28 +16,49 @@
|
|
|
16
16
|
import { ZoomableImage } from "./zoom";
|
|
17
17
|
import { onMount } from "svelte";
|
|
18
18
|
import { tweened, type Tweened } from "svelte/motion";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
value = $bindable<[null | FileData, null | FileData]>([null, null]),
|
|
22
|
+
label = undefined,
|
|
23
|
+
show_download_button = true,
|
|
24
|
+
show_label,
|
|
25
|
+
i18n,
|
|
26
|
+
position = $bindable(0.5),
|
|
27
|
+
layer_images = true,
|
|
28
|
+
show_single = false,
|
|
29
|
+
slider_color,
|
|
30
|
+
show_fullscreen_button = true,
|
|
31
|
+
fullscreen = $bindable(false),
|
|
32
|
+
buttons = null,
|
|
33
|
+
on_custom_button_click = null,
|
|
34
|
+
el_width = $bindable(0),
|
|
35
|
+
max_height,
|
|
36
|
+
interactive = true,
|
|
37
|
+
onclear,
|
|
38
|
+
onfullscreen
|
|
39
|
+
}: {
|
|
40
|
+
value?: [null | FileData, null | FileData];
|
|
41
|
+
label?: string;
|
|
42
|
+
show_download_button?: boolean;
|
|
43
|
+
show_label: boolean;
|
|
44
|
+
i18n: I18nFormatter;
|
|
45
|
+
position?: number;
|
|
46
|
+
layer_images?: boolean;
|
|
47
|
+
show_single?: boolean;
|
|
48
|
+
slider_color: string;
|
|
49
|
+
show_fullscreen_button?: boolean;
|
|
50
|
+
fullscreen?: boolean;
|
|
51
|
+
buttons?: (string | CustomButtonType)[] | null;
|
|
52
|
+
on_custom_button_click?: ((id: number) => void) | null;
|
|
53
|
+
el_width?: number;
|
|
54
|
+
max_height: number;
|
|
55
|
+
interactive?: boolean;
|
|
56
|
+
onclear?: () => void;
|
|
57
|
+
onfullscreen?: (fullscreen: boolean) => void;
|
|
58
|
+
} = $props();
|
|
59
|
+
|
|
60
|
+
let img = $state<HTMLImageElement>();
|
|
61
|
+
let slider_wrap = $state<HTMLDivElement>();
|
|
41
62
|
let image_container: HTMLDivElement;
|
|
42
63
|
|
|
43
64
|
let transform: Tweened<{ x: number; y: number; z: number }> = tweened(
|
|
@@ -47,18 +68,28 @@
|
|
|
47
68
|
}
|
|
48
69
|
);
|
|
49
70
|
let parent_el: HTMLDivElement;
|
|
71
|
+
let img_width = $state(0);
|
|
72
|
+
let viewport_width = $state(0);
|
|
73
|
+
let image_size = $state<{
|
|
74
|
+
top: number;
|
|
75
|
+
left: number;
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
}>({ top: 0, left: 0, width: 0, height: 0 });
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
let coords_at_viewport = $derived(
|
|
81
|
+
get_coords_at_viewport(
|
|
82
|
+
position,
|
|
83
|
+
viewport_width,
|
|
84
|
+
image_size.width,
|
|
85
|
+
image_size.left,
|
|
86
|
+
$transform.x,
|
|
87
|
+
$transform.z
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
let style = $derived(
|
|
91
|
+
layer_images ? `clip-path: inset(0 0 0 ${coords_at_viewport * 100}%)` : ""
|
|
58
92
|
);
|
|
59
|
-
$: style = layer_images
|
|
60
|
-
? `clip-path: inset(0 0 0 ${coords_at_viewport * 100}%)`
|
|
61
|
-
: "";
|
|
62
93
|
|
|
63
94
|
function get_coords_at_viewport(
|
|
64
95
|
viewport_percent_x: number, // 0-1
|
|
@@ -77,15 +108,12 @@
|
|
|
77
108
|
return percent_position;
|
|
78
109
|
}
|
|
79
110
|
|
|
80
|
-
let img_width = 0;
|
|
81
|
-
let viewport_width = 0;
|
|
82
|
-
|
|
83
111
|
let zoomable_image: ZoomableImage | null = null;
|
|
84
112
|
let observer: ResizeObserver | null = null;
|
|
85
113
|
|
|
86
114
|
function init_image(
|
|
87
|
-
img: HTMLImageElement,
|
|
88
|
-
slider_wrap: HTMLDivElement
|
|
115
|
+
img: HTMLImageElement | undefined,
|
|
116
|
+
slider_wrap: HTMLDivElement | undefined
|
|
89
117
|
): void {
|
|
90
118
|
if (!img || !slider_wrap) return;
|
|
91
119
|
zoomable_image?.destroy();
|
|
@@ -112,7 +140,9 @@
|
|
|
112
140
|
observer.observe(img);
|
|
113
141
|
}
|
|
114
142
|
|
|
115
|
-
|
|
143
|
+
$effect(() => {
|
|
144
|
+
init_image(img, slider_wrap);
|
|
145
|
+
});
|
|
116
146
|
|
|
117
147
|
onMount(() => {
|
|
118
148
|
return () => {
|
|
@@ -123,11 +153,13 @@
|
|
|
123
153
|
|
|
124
154
|
let slider_wrap_parent: HTMLDivElement;
|
|
125
155
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
156
|
+
function handle_image_load(size: {
|
|
157
|
+
top: number;
|
|
158
|
+
left: number;
|
|
159
|
+
width: number;
|
|
160
|
+
height: number;
|
|
161
|
+
}): void {
|
|
162
|
+
image_size = size;
|
|
131
163
|
}
|
|
132
164
|
</script>
|
|
133
165
|
|
|
@@ -144,7 +176,13 @@
|
|
|
144
176
|
onclick={() => zoomable_image?.reset_zoom()}
|
|
145
177
|
/>
|
|
146
178
|
{#if show_fullscreen_button}
|
|
147
|
-
<FullscreenButton
|
|
179
|
+
<FullscreenButton
|
|
180
|
+
{fullscreen}
|
|
181
|
+
onclick={(is_fullscreen) => {
|
|
182
|
+
fullscreen = is_fullscreen;
|
|
183
|
+
onfullscreen?.(is_fullscreen);
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
148
186
|
{/if}
|
|
149
187
|
|
|
150
188
|
{#if show_download_button}
|
|
@@ -161,7 +199,7 @@
|
|
|
161
199
|
label="Remove Image"
|
|
162
200
|
onclick={(event) => {
|
|
163
201
|
value = [null, null];
|
|
164
|
-
|
|
202
|
+
onclear?.();
|
|
165
203
|
event.stopPropagation();
|
|
166
204
|
}}
|
|
167
205
|
/>
|
|
@@ -189,7 +227,7 @@
|
|
|
189
227
|
transform="translate({$transform.x}px, {$transform.y}px) scale({$transform.z})"
|
|
190
228
|
{fullscreen}
|
|
191
229
|
{max_height}
|
|
192
|
-
|
|
230
|
+
onload={handle_image_load}
|
|
193
231
|
/>
|
|
194
232
|
<ImageEl
|
|
195
233
|
variant="preview"
|
|
@@ -202,7 +240,7 @@
|
|
|
202
240
|
transform="translate({$transform.x}px, {$transform.y}px) scale({$transform.z})"
|
|
203
241
|
{fullscreen}
|
|
204
242
|
{max_height}
|
|
205
|
-
|
|
243
|
+
onload={handle_image_load}
|
|
206
244
|
/>
|
|
207
245
|
</Slider>
|
|
208
246
|
</div>
|
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
|
2
2
|
import { type FileData } from "@gradio/client";
|
|
3
3
|
import type { I18nFormatter } from "@gradio/utils";
|
|
4
|
-
|
|
5
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
6
|
-
$$bindings?: Bindings;
|
|
7
|
-
} & Exports;
|
|
8
|
-
(internal: unknown, props: Props & {
|
|
9
|
-
$$events?: Events;
|
|
10
|
-
$$slots?: Slots;
|
|
11
|
-
}): Exports & {
|
|
12
|
-
$set?: any;
|
|
13
|
-
$on?: any;
|
|
14
|
-
};
|
|
15
|
-
z_$$bindings?: Bindings;
|
|
16
|
-
}
|
|
17
|
-
declare const SliderPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
4
|
+
type $$ComponentProps = {
|
|
18
5
|
value?: [null | FileData, null | FileData];
|
|
19
|
-
label?: string
|
|
6
|
+
label?: string;
|
|
20
7
|
show_download_button?: boolean;
|
|
21
8
|
show_label: boolean;
|
|
22
9
|
i18n: I18nFormatter;
|
|
23
|
-
position
|
|
10
|
+
position?: number;
|
|
24
11
|
layer_images?: boolean;
|
|
25
12
|
show_single?: boolean;
|
|
26
13
|
slider_color: string;
|
|
@@ -31,11 +18,9 @@ declare const SliderPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
31
18
|
el_width?: number;
|
|
32
19
|
max_height: number;
|
|
33
20
|
interactive?: boolean;
|
|
34
|
-
|
|
35
|
-
fullscreen:
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}, {}, {}, string>;
|
|
40
|
-
type SliderPreview = InstanceType<typeof SliderPreview>;
|
|
21
|
+
onclear?: () => void;
|
|
22
|
+
onfullscreen?: (fullscreen: boolean) => void;
|
|
23
|
+
};
|
|
24
|
+
declare const SliderPreview: import("svelte").Component<$$ComponentProps, {}, "value" | "position" | "fullscreen" | "el_width">;
|
|
25
|
+
type SliderPreview = ReturnType<typeof SliderPreview>;
|
|
41
26
|
export default SliderPreview;
|
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
<svelte:options accessors={true} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
+
import type { Snippet } from "svelte";
|
|
4
5
|
import type { I18nFormatter } from "@gradio/utils";
|
|
5
6
|
import Image from "./Image.svelte";
|
|
6
7
|
import { type Client } from "@gradio/client";
|
|
7
8
|
|
|
8
9
|
import type { FileData } from "@gradio/client";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
let {
|
|
12
|
+
value = $bindable<[FileData | null, FileData | null]>([null, null]),
|
|
13
|
+
upload,
|
|
14
|
+
stream_handler,
|
|
15
|
+
label,
|
|
16
|
+
show_label,
|
|
17
|
+
i18n,
|
|
18
|
+
root,
|
|
19
|
+
upload_count = 1,
|
|
20
|
+
dragging = $bindable(false),
|
|
21
|
+
max_height,
|
|
22
|
+
max_file_size = null,
|
|
23
|
+
upload_promise = $bindable(),
|
|
24
|
+
onclear,
|
|
25
|
+
ondrag,
|
|
26
|
+
onupload,
|
|
27
|
+
children
|
|
28
|
+
}: {
|
|
29
|
+
value?: [FileData | null, FileData | null];
|
|
30
|
+
upload: Client["upload"];
|
|
31
|
+
stream_handler: Client["stream"];
|
|
32
|
+
label: string;
|
|
33
|
+
show_label: boolean;
|
|
34
|
+
i18n: I18nFormatter;
|
|
35
|
+
root: string;
|
|
36
|
+
upload_count?: number;
|
|
37
|
+
dragging?: boolean;
|
|
38
|
+
max_height: number;
|
|
39
|
+
max_file_size?: number | null;
|
|
40
|
+
upload_promise?: Promise<any>;
|
|
41
|
+
onclear?: () => void;
|
|
42
|
+
ondrag?: (dragging: boolean) => void;
|
|
43
|
+
onupload?: (value: [FileData | null, FileData | null]) => void;
|
|
44
|
+
children?: Snippet;
|
|
45
|
+
} = $props();
|
|
22
46
|
</script>
|
|
23
47
|
|
|
24
48
|
<Image
|
|
@@ -28,13 +52,12 @@
|
|
|
28
52
|
bind:value
|
|
29
53
|
bind:dragging
|
|
30
54
|
{root}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
on:share
|
|
55
|
+
{onclear}
|
|
56
|
+
ondrag={(detail) => {
|
|
57
|
+
dragging = detail;
|
|
58
|
+
ondrag?.(detail);
|
|
59
|
+
}}
|
|
60
|
+
{onupload}
|
|
38
61
|
{label}
|
|
39
62
|
{show_label}
|
|
40
63
|
{upload_count}
|
|
@@ -44,5 +67,5 @@
|
|
|
44
67
|
{max_height}
|
|
45
68
|
{i18n}
|
|
46
69
|
>
|
|
47
|
-
|
|
70
|
+
{#if children}{@render children()}{/if}
|
|
48
71
|
</Image>
|