@gradio/imageslider 0.3.1-dev.0 → 0.3.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.
- package/CHANGELOG.md +40 -0
- package/Index.svelte +80 -101
- package/dist/Example.svelte +5 -4
- package/dist/Example.svelte.d.ts +21 -19
- package/dist/Index.svelte +123 -114
- package/dist/Index.svelte.d.ts +3 -151
- package/dist/shared/ClearImage.svelte +6 -4
- package/dist/shared/ClearImage.svelte.d.ts +18 -16
- package/dist/shared/Image.svelte +78 -46
- package/dist/shared/Image.svelte.d.ts +50 -39
- package/dist/shared/ImageEl.svelte +82 -45
- package/dist/shared/ImageEl.svelte.d.ts +32 -30
- package/dist/shared/Slider.svelte +80 -58
- package/dist/shared/Slider.svelte.d.ts +37 -28
- package/dist/shared/SliderPreview.svelte +128 -96
- package/dist/shared/SliderPreview.svelte.d.ts +34 -32
- package/dist/shared/SliderUpload.svelte +20 -13
- package/dist/shared/SliderUpload.svelte.d.ts +58 -68
- package/dist/types.d.ts +29 -0
- package/dist/types.js +1 -0
- package/package.json +9 -9
- package/shared/Image.svelte +3 -0
- package/shared/SliderUpload.svelte +2 -0
- package/types.ts +31 -0
package/dist/Index.svelte.d.ts
CHANGED
|
@@ -1,151 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { LoadingStatus } from "@gradio/statustracker";
|
|
5
|
-
declare const __propDef: {
|
|
6
|
-
props: {
|
|
7
|
-
value_is_output?: boolean;
|
|
8
|
-
elem_id?: string;
|
|
9
|
-
elem_classes?: string[];
|
|
10
|
-
visible?: boolean | "hidden";
|
|
11
|
-
value?: [FileData | null, FileData | null];
|
|
12
|
-
label: string;
|
|
13
|
-
show_label: boolean;
|
|
14
|
-
buttons?: string[] | null;
|
|
15
|
-
root: string;
|
|
16
|
-
height: number | undefined;
|
|
17
|
-
width: number | undefined;
|
|
18
|
-
container?: boolean;
|
|
19
|
-
scale?: number | null;
|
|
20
|
-
min_width?: number | undefined;
|
|
21
|
-
loading_status: LoadingStatus;
|
|
22
|
-
interactive: boolean;
|
|
23
|
-
placeholder?: string | undefined;
|
|
24
|
-
input_ready: boolean;
|
|
25
|
-
slider_position: number;
|
|
26
|
-
upload_count?: number;
|
|
27
|
-
slider_color?: string;
|
|
28
|
-
max_height: number;
|
|
29
|
-
gradio: Gradio<{
|
|
30
|
-
input: never;
|
|
31
|
-
change: never;
|
|
32
|
-
error: string;
|
|
33
|
-
edit: never;
|
|
34
|
-
stream: ValueData;
|
|
35
|
-
drag: never;
|
|
36
|
-
upload: never;
|
|
37
|
-
clear: never;
|
|
38
|
-
select: SelectData;
|
|
39
|
-
share: ShareData;
|
|
40
|
-
clear_status: LoadingStatus;
|
|
41
|
-
close_stream: string;
|
|
42
|
-
}>;
|
|
43
|
-
};
|
|
44
|
-
events: {
|
|
45
|
-
[evt: string]: CustomEvent<any>;
|
|
46
|
-
};
|
|
47
|
-
slots: {};
|
|
48
|
-
exports?: {} | undefined;
|
|
49
|
-
bindings?: string | undefined;
|
|
50
|
-
};
|
|
51
|
-
export type IndexProps = typeof __propDef.props;
|
|
52
|
-
export type IndexEvents = typeof __propDef.events;
|
|
53
|
-
export type IndexSlots = typeof __propDef.slots;
|
|
54
|
-
export default class Index extends SvelteComponent<IndexProps, IndexEvents, IndexSlots> {
|
|
55
|
-
get value_is_output(): boolean | undefined;
|
|
56
|
-
/**accessor*/
|
|
57
|
-
set value_is_output(_: boolean | undefined);
|
|
58
|
-
get elem_id(): string | undefined;
|
|
59
|
-
/**accessor*/
|
|
60
|
-
set elem_id(_: string | undefined);
|
|
61
|
-
get elem_classes(): string[] | undefined;
|
|
62
|
-
/**accessor*/
|
|
63
|
-
set elem_classes(_: string[] | undefined);
|
|
64
|
-
get visible(): boolean | "hidden" | undefined;
|
|
65
|
-
/**accessor*/
|
|
66
|
-
set visible(_: boolean | "hidden" | undefined);
|
|
67
|
-
get value(): [any, any] | undefined;
|
|
68
|
-
/**accessor*/
|
|
69
|
-
set value(_: [any, any] | undefined);
|
|
70
|
-
get label(): string;
|
|
71
|
-
/**accessor*/
|
|
72
|
-
set label(_: string);
|
|
73
|
-
get show_label(): boolean;
|
|
74
|
-
/**accessor*/
|
|
75
|
-
set show_label(_: boolean);
|
|
76
|
-
get buttons(): string[] | null | undefined;
|
|
77
|
-
/**accessor*/
|
|
78
|
-
set buttons(_: string[] | null | undefined);
|
|
79
|
-
get root(): string;
|
|
80
|
-
/**accessor*/
|
|
81
|
-
set root(_: string);
|
|
82
|
-
get height(): number | undefined;
|
|
83
|
-
/**accessor*/
|
|
84
|
-
set height(_: number | undefined);
|
|
85
|
-
get width(): number | undefined;
|
|
86
|
-
/**accessor*/
|
|
87
|
-
set width(_: number | undefined);
|
|
88
|
-
get container(): boolean | undefined;
|
|
89
|
-
/**accessor*/
|
|
90
|
-
set container(_: boolean | undefined);
|
|
91
|
-
get scale(): number | null | undefined;
|
|
92
|
-
/**accessor*/
|
|
93
|
-
set scale(_: number | null | undefined);
|
|
94
|
-
get min_width(): number | undefined;
|
|
95
|
-
/**accessor*/
|
|
96
|
-
set min_width(_: number | undefined);
|
|
97
|
-
get loading_status(): LoadingStatus;
|
|
98
|
-
/**accessor*/
|
|
99
|
-
set loading_status(_: LoadingStatus);
|
|
100
|
-
get interactive(): boolean;
|
|
101
|
-
/**accessor*/
|
|
102
|
-
set interactive(_: boolean);
|
|
103
|
-
get placeholder(): string | undefined;
|
|
104
|
-
/**accessor*/
|
|
105
|
-
set placeholder(_: string | undefined);
|
|
106
|
-
get input_ready(): boolean;
|
|
107
|
-
/**accessor*/
|
|
108
|
-
set input_ready(_: boolean);
|
|
109
|
-
get slider_position(): number;
|
|
110
|
-
/**accessor*/
|
|
111
|
-
set slider_position(_: number);
|
|
112
|
-
get upload_count(): number | undefined;
|
|
113
|
-
/**accessor*/
|
|
114
|
-
set upload_count(_: number | undefined);
|
|
115
|
-
get slider_color(): string | undefined;
|
|
116
|
-
/**accessor*/
|
|
117
|
-
set slider_color(_: string | undefined);
|
|
118
|
-
get max_height(): number;
|
|
119
|
-
/**accessor*/
|
|
120
|
-
set max_height(_: number);
|
|
121
|
-
get gradio(): Gradio<{
|
|
122
|
-
input: never;
|
|
123
|
-
change: never;
|
|
124
|
-
error: string;
|
|
125
|
-
edit: never;
|
|
126
|
-
stream: ValueData;
|
|
127
|
-
drag: never;
|
|
128
|
-
upload: never;
|
|
129
|
-
clear: never;
|
|
130
|
-
select: SelectData;
|
|
131
|
-
share: ShareData;
|
|
132
|
-
clear_status: LoadingStatus;
|
|
133
|
-
close_stream: string;
|
|
134
|
-
}>;
|
|
135
|
-
/**accessor*/
|
|
136
|
-
set gradio(_: Gradio<{
|
|
137
|
-
input: never;
|
|
138
|
-
change: never;
|
|
139
|
-
error: string;
|
|
140
|
-
edit: never;
|
|
141
|
-
stream: ValueData;
|
|
142
|
-
drag: never;
|
|
143
|
-
upload: never;
|
|
144
|
-
clear: never;
|
|
145
|
-
select: SelectData;
|
|
146
|
-
share: ShareData;
|
|
147
|
-
clear_status: LoadingStatus;
|
|
148
|
-
close_stream: string;
|
|
149
|
-
}>);
|
|
150
|
-
}
|
|
151
|
-
export {};
|
|
1
|
+
declare const Index: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
2
|
+
type Index = ReturnType<typeof Index>;
|
|
3
|
+
export default Index;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createEventDispatcher } from "svelte";
|
|
3
|
+
import { IconButton } from "@gradio/atoms";
|
|
4
|
+
import { Clear } from "@gradio/icons";
|
|
5
|
+
|
|
6
|
+
const dispatch = createEventDispatcher();
|
|
5
7
|
</script>
|
|
6
8
|
|
|
7
9
|
<div>
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
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> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
8
11
|
};
|
|
9
|
-
|
|
10
|
-
exports?: {} | undefined;
|
|
11
|
-
bindings?: string | undefined;
|
|
12
|
-
};
|
|
13
|
-
export type ClearImageProps = typeof __propDef.props;
|
|
14
|
-
export type ClearImageEvents = typeof __propDef.events;
|
|
15
|
-
export type ClearImageSlots = typeof __propDef.slots;
|
|
16
|
-
export default class ClearImage extends SvelteComponent<ClearImageProps, ClearImageEvents, ClearImageSlots> {
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
17
13
|
}
|
|
18
|
-
|
|
14
|
+
declare const ClearImage: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
remove_image: CustomEvent<any>;
|
|
16
|
+
} & {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
}, {}, {}, string>;
|
|
19
|
+
type ClearImage = InstanceType<typeof ClearImage>;
|
|
20
|
+
export default ClearImage;
|
package/dist/shared/Image.svelte
CHANGED
|
@@ -1,49 +1,79 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {} from "@gradio/
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export let
|
|
16
|
-
|
|
17
|
-
export let
|
|
18
|
-
export let
|
|
19
|
-
export let
|
|
20
|
-
export let
|
|
21
|
-
export let
|
|
22
|
-
|
|
23
|
-
export let
|
|
24
|
-
let
|
|
25
|
-
let
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Slider from "./Slider.svelte";
|
|
3
|
+
import { createEventDispatcher, tick } from "svelte";
|
|
4
|
+
import { BlockLabel, Empty, IconButton, DownloadLink } from "@gradio/atoms";
|
|
5
|
+
import { Download } from "@gradio/icons";
|
|
6
|
+
import { Image } from "@gradio/icons";
|
|
7
|
+
import { type SelectData, type I18nFormatter } from "@gradio/utils";
|
|
8
|
+
import ClearImage from "./ClearImage.svelte";
|
|
9
|
+
import ImageEl from "./ImageEl.svelte";
|
|
10
|
+
|
|
11
|
+
import { Upload } from "@gradio/upload";
|
|
12
|
+
|
|
13
|
+
import { type FileData, type Client } from "@gradio/client";
|
|
14
|
+
|
|
15
|
+
export let value: [FileData | null, FileData | null];
|
|
16
|
+
|
|
17
|
+
export let label: string | undefined = undefined;
|
|
18
|
+
export let show_label: boolean;
|
|
19
|
+
export let root: string;
|
|
20
|
+
export let position: number;
|
|
21
|
+
export let upload_count = 2;
|
|
22
|
+
|
|
23
|
+
export let show_download_button = true;
|
|
24
|
+
export let slider_color: string;
|
|
25
|
+
export let upload: Client["upload"];
|
|
26
|
+
export let stream_handler: Client["stream"];
|
|
27
|
+
export let max_file_size: number | null = null;
|
|
28
|
+
export let i18n: I18nFormatter;
|
|
29
|
+
export let max_height: number;
|
|
30
|
+
export let upload_promise: Promise<any> | null = null;
|
|
31
|
+
|
|
32
|
+
let value_: [FileData | null, FileData | null] = value || [null, null];
|
|
33
|
+
|
|
34
|
+
let img: HTMLImageElement;
|
|
35
|
+
let el_width: number;
|
|
36
|
+
let el_height: number;
|
|
37
|
+
|
|
38
|
+
async function handle_upload(
|
|
39
|
+
{ detail }: CustomEvent<FileData[]>,
|
|
40
|
+
n: number
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
const new_value = [value[0], value[1]] as [
|
|
43
|
+
FileData | null,
|
|
44
|
+
FileData | null
|
|
45
|
+
];
|
|
46
|
+
if (detail.length > 1) {
|
|
47
|
+
new_value[n] = detail[0];
|
|
48
|
+
} else {
|
|
49
|
+
new_value[n] = detail[n];
|
|
50
|
+
}
|
|
51
|
+
value = new_value;
|
|
52
|
+
await tick();
|
|
53
|
+
|
|
54
|
+
dispatch("upload", new_value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let old_value = "";
|
|
58
|
+
|
|
59
|
+
$: if (JSON.stringify(value) !== old_value) {
|
|
60
|
+
old_value = JSON.stringify(value);
|
|
61
|
+
value_ = value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dispatch = createEventDispatcher<{
|
|
65
|
+
change: string | null;
|
|
66
|
+
stream: string | null;
|
|
67
|
+
edit: undefined;
|
|
68
|
+
clear: undefined;
|
|
69
|
+
drag: boolean;
|
|
70
|
+
upload: [FileData | null, FileData | null];
|
|
71
|
+
select: SelectData;
|
|
72
|
+
}>();
|
|
73
|
+
|
|
74
|
+
export let dragging = false;
|
|
75
|
+
|
|
76
|
+
$: dispatch("drag", dragging);
|
|
47
77
|
</script>
|
|
48
78
|
|
|
49
79
|
<BlockLabel {show_label} Icon={Image} label={label || i18n("image.image")} />
|
|
@@ -88,6 +118,7 @@ $: dispatch("drag", dragging);
|
|
|
88
118
|
{#if !value_?.[0]}
|
|
89
119
|
<div class="wrap" class:half-wrap={upload_count === 1}>
|
|
90
120
|
<Upload
|
|
121
|
+
bind:upload_promise
|
|
91
122
|
bind:dragging
|
|
92
123
|
filetype="image/*"
|
|
93
124
|
on:load={(e) => handle_upload(e, 0)}
|
|
@@ -113,6 +144,7 @@ $: dispatch("drag", dragging);
|
|
|
113
144
|
|
|
114
145
|
{#if !value_?.[1] && upload_count === 2}
|
|
115
146
|
<Upload
|
|
147
|
+
bind:upload_promise
|
|
116
148
|
bind:dragging
|
|
117
149
|
filetype="image/*"
|
|
118
150
|
on:load={(e) => handle_upload(e, 1)}
|
|
@@ -1,43 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Image } from "@gradio/icons";
|
|
2
2
|
import { type SelectData, type I18nFormatter } from "@gradio/utils";
|
|
3
3
|
import { type FileData, type Client } from "@gradio/client";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
upload: Client["upload"];
|
|
15
|
-
stream_handler: Client["stream"];
|
|
16
|
-
max_file_size?: number | null;
|
|
17
|
-
i18n: I18nFormatter;
|
|
18
|
-
max_height: number;
|
|
19
|
-
dragging?: boolean;
|
|
4
|
+
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> {
|
|
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;
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
change: CustomEvent<string | null>;
|
|
23
|
-
stream: CustomEvent<string | null>;
|
|
24
|
-
edit: CustomEvent<undefined>;
|
|
25
|
-
clear: CustomEvent<undefined>;
|
|
26
|
-
drag: CustomEvent<boolean>;
|
|
27
|
-
upload: CustomEvent<[any, any]>;
|
|
28
|
-
select: CustomEvent<SelectData>;
|
|
29
|
-
} & {
|
|
30
|
-
[evt: string]: CustomEvent<any>;
|
|
31
|
-
};
|
|
32
|
-
slots: {
|
|
33
|
-
default: {};
|
|
34
|
-
};
|
|
35
|
-
exports?: {} | undefined;
|
|
36
|
-
bindings?: string | undefined;
|
|
37
|
-
};
|
|
38
|
-
export type ImageProps = typeof __propDef.props;
|
|
39
|
-
export type ImageEvents = typeof __propDef.events;
|
|
40
|
-
export type ImageSlots = typeof __propDef.slots;
|
|
41
|
-
export default class Image extends SvelteComponent<ImageProps, ImageEvents, ImageSlots> {
|
|
15
|
+
z_$$bindings?: Bindings;
|
|
42
16
|
}
|
|
43
|
-
|
|
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;
|
|
25
|
+
show_label: boolean;
|
|
26
|
+
root: string;
|
|
27
|
+
position: number;
|
|
28
|
+
upload_count?: number;
|
|
29
|
+
show_download_button?: boolean;
|
|
30
|
+
slider_color: string;
|
|
31
|
+
upload: Client["upload"];
|
|
32
|
+
stream_handler: Client["stream"];
|
|
33
|
+
max_file_size?: number | null;
|
|
34
|
+
i18n: I18nFormatter;
|
|
35
|
+
max_height: number;
|
|
36
|
+
upload_promise?: Promise<any> | null;
|
|
37
|
+
dragging?: boolean;
|
|
38
|
+
}, {
|
|
39
|
+
default: {};
|
|
40
|
+
}>, {
|
|
41
|
+
change: CustomEvent<string | null>;
|
|
42
|
+
stream: CustomEvent<string | null>;
|
|
43
|
+
edit: CustomEvent<undefined>;
|
|
44
|
+
clear: CustomEvent<undefined>;
|
|
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>;
|
|
54
|
+
export default Image;
|
|
@@ -1,48 +1,85 @@
|
|
|
1
|
-
<script
|
|
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
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLImgAttributes } from "svelte/elements";
|
|
3
|
+
import { createEventDispatcher, onMount, tick } from "svelte";
|
|
4
|
+
interface Props extends HTMLImgAttributes {
|
|
5
|
+
"data-testid"?: string;
|
|
6
|
+
fixed?: boolean;
|
|
7
|
+
transform?: string;
|
|
8
|
+
img_el?: HTMLImageElement;
|
|
9
|
+
hidden?: boolean;
|
|
10
|
+
variant?: "preview" | "upload";
|
|
11
|
+
max_height?: number;
|
|
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: {
|
|
28
|
+
top: number;
|
|
29
|
+
left: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
function get_image_size(img: HTMLImageElement | null): {
|
|
36
|
+
top: number;
|
|
37
|
+
left: number;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
} {
|
|
41
|
+
if (!img) return { top: 0, left: 0, width: 0, height: 0 };
|
|
42
|
+
const container = img.parentElement?.getBoundingClientRect();
|
|
43
|
+
|
|
44
|
+
if (!container) return { top: 0, left: 0, width: 0, height: 0 };
|
|
45
|
+
|
|
46
|
+
const naturalAspect = img.naturalWidth / img.naturalHeight;
|
|
47
|
+
const containerAspect = container.width / container.height;
|
|
48
|
+
let displayedWidth, displayedHeight;
|
|
49
|
+
|
|
50
|
+
if (naturalAspect > containerAspect) {
|
|
51
|
+
displayedWidth = container.width;
|
|
52
|
+
displayedHeight = container.width / naturalAspect;
|
|
53
|
+
} else {
|
|
54
|
+
displayedHeight = container.height;
|
|
55
|
+
displayedWidth = container.height * naturalAspect;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const offsetX = (container.width - displayedWidth) / 2;
|
|
59
|
+
const offsetY = (container.height - displayedHeight) / 2;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
top: offsetY,
|
|
63
|
+
left: offsetX,
|
|
64
|
+
width: displayedWidth,
|
|
65
|
+
height: displayedHeight
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onMount(() => {
|
|
70
|
+
const resizer = new ResizeObserver(async (entries) => {
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
await tick();
|
|
73
|
+
dispatch("load", get_image_size(img_el));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
resizer.observe(img_el!);
|
|
78
|
+
|
|
79
|
+
return () => {
|
|
80
|
+
resizer.disconnect();
|
|
81
|
+
};
|
|
82
|
+
});
|
|
46
83
|
</script>
|
|
47
84
|
|
|
48
85
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import type { HTMLImgAttributes } from "svelte/elements";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
load: CustomEvent<{
|
|
16
|
-
top: number;
|
|
17
|
-
left: number;
|
|
18
|
-
width: number;
|
|
19
|
-
height: number;
|
|
20
|
-
}>;
|
|
21
|
-
} & {
|
|
22
|
-
[evt: string]: CustomEvent<any>;
|
|
23
|
-
};
|
|
24
|
-
slots: {};
|
|
25
|
-
exports?: {} | undefined;
|
|
26
|
-
bindings?: string | undefined;
|
|
27
|
-
};
|
|
28
|
-
export type ImageElProps = typeof __propDef.props;
|
|
29
|
-
export type ImageElEvents = typeof __propDef.events;
|
|
30
|
-
export type ImageElSlots = typeof __propDef.slots;
|
|
31
|
-
export default class ImageEl extends SvelteComponent<ImageElProps, ImageElEvents, ImageElSlots> {
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
32
14
|
}
|
|
33
|
-
|
|
15
|
+
declare const ImageEl: $$__sveltets_2_IsomorphicComponent<HTMLImgAttributes & {
|
|
16
|
+
"data-testid"?: string;
|
|
17
|
+
fixed?: boolean;
|
|
18
|
+
transform?: string;
|
|
19
|
+
img_el?: HTMLImageElement;
|
|
20
|
+
hidden?: boolean;
|
|
21
|
+
variant?: "preview" | "upload";
|
|
22
|
+
max_height?: number;
|
|
23
|
+
fullscreen?: boolean;
|
|
24
|
+
}, {
|
|
25
|
+
load: CustomEvent<{
|
|
26
|
+
top: number;
|
|
27
|
+
left: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
}>;
|
|
31
|
+
} & {
|
|
32
|
+
[evt: string]: CustomEvent<any>;
|
|
33
|
+
}, {}, {}, string>;
|
|
34
|
+
type ImageEl = InstanceType<typeof ImageEl>;
|
|
35
|
+
export default ImageEl;
|