@gradio/video 0.20.2 → 0.20.3

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @gradio/video
2
2
 
3
+ ## 0.20.3
4
+
5
+ ### Fixes
6
+
7
+ - [#12830](https://github.com/gradio-app/gradio/pull/12830) [`a2a0078`](https://github.com/gradio-app/gradio/commit/a2a0078de878481752b952f9ed0e759a0e884d0b) - `Video` to Svelte 5. Thanks @dawoodkhan82!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/utils@0.11.3
12
+ - @gradio/atoms@0.22.0
13
+ - @gradio/statustracker@0.12.4
14
+ - @gradio/upload@0.17.6
15
+ - @gradio/image@0.25.3
16
+
3
17
  ## 0.20.2
4
18
 
5
19
  ### Dependency updates
package/Example.svelte CHANGED
@@ -3,13 +3,19 @@
3
3
  import { playable } from "./shared/utils";
4
4
  import { type FileData } from "@gradio/client";
5
5
 
6
- export let type: "gallery" | "table";
7
- export let selected = false;
8
- export let value: null | FileData = null;
9
- export let loop: boolean;
10
- let video: HTMLVideoElement;
6
+ interface Props {
7
+ type: "gallery" | "table";
8
+ selected?: boolean;
9
+ value?: null | FileData;
10
+ loop: boolean;
11
+ }
12
+
13
+ let { type, selected = false, value = null, loop }: Props = $props();
14
+
15
+ let video: HTMLVideoElement | undefined = $state();
11
16
 
12
17
  async function init(): Promise<void> {
18
+ if (!video) return;
13
19
  video.muted = true;
14
20
  video.playsInline = true;
15
21
  video.controls = false;
@@ -32,9 +38,9 @@
32
38
  muted
33
39
  playsinline
34
40
  bind:node={video}
35
- on:loadeddata={init}
36
- on:mouseover={video.play.bind(video)}
37
- on:mouseout={video.pause.bind(video)}
41
+ onloadeddata={init}
42
+ onmouseover={() => video?.play()}
43
+ onmouseout={() => video?.pause()}
38
44
  src={value?.url}
39
45
  is_stream={false}
40
46
  {loop}
package/Index.svelte CHANGED
@@ -50,7 +50,7 @@
50
50
  gradio.props.value = initial_value;
51
51
  };
52
52
 
53
- function handle_change({ detail }: CustomEvent<FileData | null>): void {
53
+ function handle_change(detail: FileData | null): void {
54
54
  if (detail != null) {
55
55
  gradio.props.value = detail as FileData;
56
56
  } else {
@@ -58,7 +58,7 @@
58
58
  }
59
59
  }
60
60
 
61
- function handle_error({ detail }: CustomEvent<string>): void {
61
+ function handle_error(detail: string): void {
62
62
  const [level, status] = detail.includes("Invalid file type")
63
63
  ? ["warning", "complete"]
64
64
  : ["error", "error"];
@@ -105,12 +105,12 @@
105
105
  gradio.dispatch("custom_button_click", { id });
106
106
  }}
107
107
  bind:playback_position={gradio.props.playback_position}
108
- on:play={() => gradio.dispatch("play")}
109
- on:pause={() => gradio.dispatch("pause")}
110
- on:stop={() => gradio.dispatch("stop")}
111
- on:end={() => gradio.dispatch("end")}
112
- on:share={({ detail }) => gradio.dispatch("share", detail)}
113
- on:error={({ detail }) => gradio.dispatch("error", detail)}
108
+ onplay={() => gradio.dispatch("play")}
109
+ onpause={() => gradio.dispatch("pause")}
110
+ onstop={() => gradio.dispatch("stop")}
111
+ onend={() => gradio.dispatch("end")}
112
+ onshare={(detail) => gradio.dispatch("share", detail)}
113
+ onerror={(detail) => gradio.dispatch("error", detail)}
114
114
  i18n={gradio.i18n}
115
115
  upload={(...args) => gradio.shared.client.upload(...args)}
116
116
  />
@@ -144,9 +144,9 @@
144
144
  bind:upload_promise
145
145
  value={gradio.props.value}
146
146
  subtitle={gradio.props.subtitles}
147
- on:change={handle_change}
148
- on:drag={({ detail }) => (dragging = detail)}
149
- on:error={handle_error}
147
+ onchange={handle_change}
148
+ ondrag={(detail) => (dragging = detail)}
149
+ onerror={handle_error}
150
150
  bind:uploading
151
151
  label={gradio.shared.label}
152
152
  show_label={gradio.shared.show_label}
@@ -163,21 +163,21 @@
163
163
  loop={gradio.props.loop}
164
164
  {handle_reset_value}
165
165
  bind:playback_position={gradio.props.playback_position}
166
- on:clear={() => {
166
+ onclear={() => {
167
167
  gradio.props.value = null;
168
168
  gradio.dispatch("clear");
169
169
  gradio.dispatch("input");
170
170
  }}
171
- on:play={() => gradio.dispatch("play")}
172
- on:pause={() => gradio.dispatch("pause")}
173
- on:upload={() => {
171
+ onplay={() => gradio.dispatch("play")}
172
+ onpause={() => gradio.dispatch("pause")}
173
+ onupload={() => {
174
174
  gradio.dispatch("upload");
175
175
  gradio.dispatch("input");
176
176
  }}
177
- on:stop={() => gradio.dispatch("stop")}
178
- on:end={() => gradio.dispatch("end")}
179
- on:start_recording={() => gradio.dispatch("start_recording")}
180
- on:stop_recording={() => gradio.dispatch("stop_recording")}
177
+ onstop={() => gradio.dispatch("stop")}
178
+ onend={() => gradio.dispatch("end")}
179
+ onstart_recording={() => gradio.dispatch("start_recording")}
180
+ onstop_recording={() => gradio.dispatch("stop_recording")}
181
181
  i18n={gradio.i18n}
182
182
  max_file_size={gradio.shared.max_file_size}
183
183
  upload={(...args) => gradio.shared.client.upload(...args)}
@@ -3,13 +3,19 @@
3
3
  import { playable } from "./shared/utils";
4
4
  import { type FileData } from "@gradio/client";
5
5
 
6
- export let type: "gallery" | "table";
7
- export let selected = false;
8
- export let value: null | FileData = null;
9
- export let loop: boolean;
10
- let video: HTMLVideoElement;
6
+ interface Props {
7
+ type: "gallery" | "table";
8
+ selected?: boolean;
9
+ value?: null | FileData;
10
+ loop: boolean;
11
+ }
12
+
13
+ let { type, selected = false, value = null, loop }: Props = $props();
14
+
15
+ let video: HTMLVideoElement | undefined = $state();
11
16
 
12
17
  async function init(): Promise<void> {
18
+ if (!video) return;
13
19
  video.muted = true;
14
20
  video.playsInline = true;
15
21
  video.controls = false;
@@ -32,9 +38,9 @@
32
38
  muted
33
39
  playsinline
34
40
  bind:node={video}
35
- on:loadeddata={init}
36
- on:mouseover={video.play.bind(video)}
37
- on:mouseout={video.pause.bind(video)}
41
+ onloadeddata={init}
42
+ onmouseover={() => video?.play()}
43
+ onmouseout={() => video?.pause()}
38
44
  src={value?.url}
39
45
  is_stream={false}
40
46
  {loop}
@@ -1,24 +1,10 @@
1
1
  import { type FileData } from "@gradio/client";
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;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const Example: $$__sveltets_2_IsomorphicComponent<{
2
+ interface Props {
16
3
  type: "gallery" | "table";
17
4
  selected?: boolean;
18
5
  value?: null | FileData;
19
6
  loop: boolean;
20
- }, {
21
- [evt: string]: CustomEvent<any>;
22
- }, {}, {}, string>;
23
- type Example = InstanceType<typeof Example>;
7
+ }
8
+ declare const Example: import("svelte").Component<Props, {}, "">;
9
+ type Example = ReturnType<typeof Example>;
24
10
  export default Example;
package/dist/Index.svelte CHANGED
@@ -50,7 +50,7 @@
50
50
  gradio.props.value = initial_value;
51
51
  };
52
52
 
53
- function handle_change({ detail }: CustomEvent<FileData | null>): void {
53
+ function handle_change(detail: FileData | null): void {
54
54
  if (detail != null) {
55
55
  gradio.props.value = detail as FileData;
56
56
  } else {
@@ -58,7 +58,7 @@
58
58
  }
59
59
  }
60
60
 
61
- function handle_error({ detail }: CustomEvent<string>): void {
61
+ function handle_error(detail: string): void {
62
62
  const [level, status] = detail.includes("Invalid file type")
63
63
  ? ["warning", "complete"]
64
64
  : ["error", "error"];
@@ -105,12 +105,12 @@
105
105
  gradio.dispatch("custom_button_click", { id });
106
106
  }}
107
107
  bind:playback_position={gradio.props.playback_position}
108
- on:play={() => gradio.dispatch("play")}
109
- on:pause={() => gradio.dispatch("pause")}
110
- on:stop={() => gradio.dispatch("stop")}
111
- on:end={() => gradio.dispatch("end")}
112
- on:share={({ detail }) => gradio.dispatch("share", detail)}
113
- on:error={({ detail }) => gradio.dispatch("error", detail)}
108
+ onplay={() => gradio.dispatch("play")}
109
+ onpause={() => gradio.dispatch("pause")}
110
+ onstop={() => gradio.dispatch("stop")}
111
+ onend={() => gradio.dispatch("end")}
112
+ onshare={(detail) => gradio.dispatch("share", detail)}
113
+ onerror={(detail) => gradio.dispatch("error", detail)}
114
114
  i18n={gradio.i18n}
115
115
  upload={(...args) => gradio.shared.client.upload(...args)}
116
116
  />
@@ -144,9 +144,9 @@
144
144
  bind:upload_promise
145
145
  value={gradio.props.value}
146
146
  subtitle={gradio.props.subtitles}
147
- on:change={handle_change}
148
- on:drag={({ detail }) => (dragging = detail)}
149
- on:error={handle_error}
147
+ onchange={handle_change}
148
+ ondrag={(detail) => (dragging = detail)}
149
+ onerror={handle_error}
150
150
  bind:uploading
151
151
  label={gradio.shared.label}
152
152
  show_label={gradio.shared.show_label}
@@ -163,21 +163,21 @@
163
163
  loop={gradio.props.loop}
164
164
  {handle_reset_value}
165
165
  bind:playback_position={gradio.props.playback_position}
166
- on:clear={() => {
166
+ onclear={() => {
167
167
  gradio.props.value = null;
168
168
  gradio.dispatch("clear");
169
169
  gradio.dispatch("input");
170
170
  }}
171
- on:play={() => gradio.dispatch("play")}
172
- on:pause={() => gradio.dispatch("pause")}
173
- on:upload={() => {
171
+ onplay={() => gradio.dispatch("play")}
172
+ onpause={() => gradio.dispatch("pause")}
173
+ onupload={() => {
174
174
  gradio.dispatch("upload");
175
175
  gradio.dispatch("input");
176
176
  }}
177
- on:stop={() => gradio.dispatch("stop")}
178
- on:end={() => gradio.dispatch("end")}
179
- on:start_recording={() => gradio.dispatch("start_recording")}
180
- on:stop_recording={() => gradio.dispatch("stop_recording")}
177
+ onstop={() => gradio.dispatch("stop")}
178
+ onend={() => gradio.dispatch("end")}
179
+ onstart_recording={() => gradio.dispatch("start_recording")}
180
+ onstop_recording={() => gradio.dispatch("stop_recording")}
181
181
  i18n={gradio.i18n}
182
182
  max_file_size={gradio.shared.max_file_size}
183
183
  upload={(...args) => gradio.shared.client.upload(...args)}
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
- import { createEventDispatcher } from "svelte";
3
- import { Upload, ModifyUpload } from "@gradio/upload";
2
+ import { Upload } from "@gradio/upload";
4
3
  import type { FileData, Client } from "@gradio/client";
5
4
  import { BlockLabel } from "@gradio/atoms";
6
5
  import { Webcam } from "@gradio/image";
@@ -10,72 +9,123 @@
10
9
  import Player from "./Player.svelte";
11
10
  import type { I18nFormatter } from "@gradio/utils";
12
11
  import { SelectSource } from "@gradio/atoms";
12
+ import type { Snippet } from "svelte";
13
13
 
14
- export let value: FileData | null = null;
15
- export let subtitle: FileData | null = null;
16
- export let sources:
17
- | ["webcam"]
18
- | ["upload"]
19
- | ["webcam", "upload"]
20
- | ["upload", "webcam"] = ["webcam", "upload"];
21
- export let label: string | undefined = undefined;
22
- export let show_download_button = false;
23
- export let show_label = true;
24
- export let webcam_options: WebcamOptions;
25
- export let include_audio: boolean;
26
- export let autoplay: boolean;
27
- export let root: string;
28
- export let i18n: I18nFormatter;
29
- export let active_source: "webcam" | "upload" = "webcam";
30
- export let handle_reset_value: () => void = () => {};
31
- export let max_file_size: number | null = null;
32
- export let upload: Client["upload"];
33
- export let stream_handler: Client["stream"];
34
- export let loop: boolean;
35
- export let uploading = false;
36
- export let upload_promise: Promise<any> | null = null;
37
- export let playback_position = 0;
38
-
39
- let has_change_history = false;
40
-
41
- const dispatch = createEventDispatcher<{
42
- change: FileData | null;
43
- clear?: never;
44
- play?: never;
45
- pause?: never;
46
- end?: never;
47
- drag: boolean;
48
- error: string;
49
- upload: FileData;
50
- start_recording?: never;
51
- stop_recording?: never;
52
- }>();
14
+ interface Props {
15
+ value?: FileData | null;
16
+ subtitle?: FileData | null;
17
+ sources?:
18
+ | ["webcam"]
19
+ | ["upload"]
20
+ | ["webcam", "upload"]
21
+ | ["upload", "webcam"];
22
+ label?: string;
23
+ show_download_button?: boolean;
24
+ show_label?: boolean;
25
+ webcam_options: WebcamOptions;
26
+ include_audio: boolean;
27
+ autoplay: boolean;
28
+ root: string;
29
+ i18n: I18nFormatter;
30
+ active_source?: "webcam" | "upload";
31
+ handle_reset_value?: () => void;
32
+ max_file_size?: number | null;
33
+ upload: Client["upload"];
34
+ stream_handler: Client["stream"];
35
+ loop: boolean;
36
+ uploading?: boolean;
37
+ upload_promise?: Promise<any> | null;
38
+ playback_position?: number;
39
+ buttons?: (string | CustomButtonType)[] | null;
40
+ on_custom_button_click?: ((id: number) => void) | null;
41
+ onchange?: (value: FileData | null) => void;
42
+ onclear?: () => void;
43
+ onplay?: () => void;
44
+ onpause?: () => void;
45
+ onend?: () => void;
46
+ ondrag?: (dragging: boolean) => void;
47
+ onerror?: (error: string) => void;
48
+ onupload?: (value: FileData) => void;
49
+ onstart_recording?: () => void;
50
+ onstop_recording?: () => void;
51
+ onstop?: () => void;
52
+ children?: Snippet;
53
+ }
54
+
55
+ import type { CustomButton as CustomButtonType } from "@gradio/utils";
56
+
57
+ let {
58
+ value = $bindable(null),
59
+ subtitle = null,
60
+ sources = ["webcam", "upload"],
61
+ label = undefined,
62
+ show_download_button = false,
63
+ show_label = true,
64
+ webcam_options,
65
+ include_audio,
66
+ autoplay,
67
+ root,
68
+ i18n,
69
+ active_source: initial_active_source = "webcam",
70
+ handle_reset_value = () => {},
71
+ max_file_size = null,
72
+ upload,
73
+ stream_handler,
74
+ loop,
75
+ uploading = $bindable(),
76
+ upload_promise = $bindable(),
77
+ playback_position = $bindable(),
78
+ buttons = null,
79
+ on_custom_button_click = null,
80
+ onchange,
81
+ onclear,
82
+ onplay,
83
+ onpause,
84
+ onend,
85
+ ondrag,
86
+ onerror,
87
+ onupload,
88
+ onstart_recording,
89
+ onstop_recording,
90
+ onstop,
91
+ children
92
+ }: Props = $props();
93
+
94
+ let has_change_history = $state(false);
95
+ let active_source = $derived.by(() => {
96
+ return initial_active_source ?? "webcam";
97
+ });
53
98
 
54
99
  function handle_load(detail: FileData | null): void {
55
100
  value = detail;
56
- dispatch("change", detail);
57
- dispatch("upload", detail!);
101
+ onchange?.(detail);
102
+ if (detail) {
103
+ onupload?.(detail);
104
+ }
58
105
  }
59
106
 
60
107
  function handle_clear(): void {
61
108
  value = null;
62
- dispatch("change", null);
63
- dispatch("clear");
109
+ onchange?.(null);
110
+ onclear?.();
64
111
  }
65
112
 
66
113
  function handle_change(video: FileData): void {
67
114
  has_change_history = true;
68
- dispatch("change", video);
115
+ onchange?.(video);
69
116
  }
70
117
 
71
118
  function handle_capture({
72
119
  detail
73
120
  }: CustomEvent<FileData | any | null>): void {
74
- dispatch("change", detail);
121
+ onchange?.(detail);
75
122
  }
76
123
 
77
- let dragging = false;
78
- $: dispatch("drag", dragging);
124
+ let dragging = $state(false);
125
+
126
+ $effect(() => {
127
+ ondrag?.(dragging);
128
+ });
79
129
  </script>
80
130
 
81
131
  <BlockLabel {show_label} Icon={Video} label={label || "Video"} />
@@ -90,13 +140,15 @@
90
140
  filetype="video/x-m4v,video/*"
91
141
  onload={handle_load}
92
142
  {max_file_size}
93
- onerror={(detail) => dispatch("error", detail)}
143
+ onerror={(detail) => onerror?.(detail)}
94
144
  {root}
95
145
  {upload}
96
146
  {stream_handler}
97
147
  aria_label={i18n("video.drop_to_upload")}
98
148
  >
99
- <slot />
149
+ {#if children}
150
+ {@render children()}
151
+ {/if}
100
152
  </Upload>
101
153
  {:else if active_source === "webcam"}
102
154
  <Webcam
@@ -105,10 +157,10 @@
105
157
  webcam_constraints={webcam_options.constraints}
106
158
  {include_audio}
107
159
  mode="video"
108
- on:error
160
+ on:error={({ detail }) => onerror?.(detail)}
109
161
  on:capture={handle_capture}
110
- on:start_recording
111
- on:stop_recording
162
+ on:start_recording={() => onstart_recording?.()}
163
+ on:stop_recording={() => onstop_recording?.()}
112
164
  {i18n}
113
165
  {upload}
114
166
  stream_every={1}
@@ -125,11 +177,11 @@
125
177
  src={value.url}
126
178
  subtitle={subtitle?.url}
127
179
  is_stream={false}
128
- on:play
129
- on:pause
130
- on:stop
131
- on:end
132
- on:error
180
+ onplay={() => onplay?.()}
181
+ onpause={() => onpause?.()}
182
+ onstop={() => onstop?.()}
183
+ onend={() => onend?.()}
184
+ onerror={(error) => onerror?.(error)}
133
185
  mirror={webcam_options.mirror && active_source === "webcam"}
134
186
  {label}
135
187
  {handle_change}
@@ -1,29 +1,13 @@
1
1
  import type { FileData, Client } from "@gradio/client";
2
2
  import type { WebcamOptions } from "./utils";
3
3
  import type { I18nFormatter } from "@gradio/utils";
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;
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 InteractiveVideo: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
4
+ import type { Snippet } from "svelte";
5
+ import type { CustomButton as CustomButtonType } from "@gradio/utils";
6
+ interface Props {
23
7
  value?: FileData | null;
24
8
  subtitle?: FileData | null;
25
9
  sources?: ["webcam"] | ["upload"] | ["webcam", "upload"] | ["upload", "webcam"];
26
- label?: string | undefined;
10
+ label?: string;
27
11
  show_download_button?: boolean;
28
12
  show_label?: boolean;
29
13
  webcam_options: WebcamOptions;
@@ -40,24 +24,21 @@ declare const InteractiveVideo: $$__sveltets_2_IsomorphicComponent<$$__sveltets_
40
24
  uploading?: boolean;
41
25
  upload_promise?: Promise<any> | null;
42
26
  playback_position?: number;
43
- }, {
44
- default: {};
45
- }>, {
46
- error: CustomEvent<any>;
47
- start_recording: CustomEvent<any>;
48
- stop_recording: CustomEvent<any>;
49
- play: CustomEvent<any>;
50
- pause: CustomEvent<any>;
51
- stop: CustomEvent<undefined>;
52
- end: CustomEvent<any>;
53
- change: CustomEvent<FileData | null>;
54
- clear?: CustomEvent<undefined> | undefined;
55
- drag: CustomEvent<boolean>;
56
- upload: CustomEvent<FileData>;
57
- } & {
58
- [evt: string]: CustomEvent<any>;
59
- }, {
60
- default: {};
61
- }, {}, string>;
62
- type InteractiveVideo = InstanceType<typeof InteractiveVideo>;
27
+ buttons?: (string | CustomButtonType)[] | null;
28
+ on_custom_button_click?: ((id: number) => void) | null;
29
+ onchange?: (value: FileData | null) => void;
30
+ onclear?: () => void;
31
+ onplay?: () => void;
32
+ onpause?: () => void;
33
+ onend?: () => void;
34
+ ondrag?: (dragging: boolean) => void;
35
+ onerror?: (error: string) => void;
36
+ onupload?: (value: FileData) => void;
37
+ onstart_recording?: () => void;
38
+ onstop_recording?: () => void;
39
+ onstop?: () => void;
40
+ children?: Snippet;
41
+ }
42
+ declare const InteractiveVideo: import("svelte").Component<Props, {}, "value" | "uploading" | "upload_promise" | "playback_position">;
43
+ type InteractiveVideo = ReturnType<typeof InteractiveVideo>;
63
44
  export default InteractiveVideo;