2023-07-11 23:56:46 +08:00
|
|
|
<svelte:options accessors={true} />
|
|
|
|
|
2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2023-02-02 20:16:38 +08:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2022-03-08 21:35:42 +08:00
|
|
|
import type { FileData } from "@gradio/upload";
|
2022-04-08 01:18:41 +08:00
|
|
|
import { normalise_file } from "@gradio/upload";
|
2022-04-26 22:48:39 +08:00
|
|
|
import { Block } from "@gradio/atoms";
|
2023-08-04 06:01:18 +08:00
|
|
|
import StaticVideo from "./VideoPreview.svelte";
|
2022-04-26 22:48:39 +08:00
|
|
|
|
2023-08-04 06:01:18 +08:00
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
|
|
|
import type { LoadingStatus } from "@gradio/statustracker/types";
|
2022-03-08 21:35:42 +08:00
|
|
|
import { _ } from "svelte-i18n";
|
2022-02-07 22:34:53 +08:00
|
|
|
|
2023-06-29 02:37:21 +08:00
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
2023-04-12 07:06:48 +08:00
|
|
|
export let value: [FileData, FileData | null] | null = null;
|
|
|
|
let old_value: [FileData, FileData | null] | null = null;
|
2023-02-02 20:16:38 +08:00
|
|
|
|
2022-04-08 01:18:41 +08:00
|
|
|
export let label: string;
|
2023-07-11 23:56:46 +08:00
|
|
|
export let source: "upload" | "webcam";
|
2022-04-12 04:18:42 +08:00
|
|
|
export let root: string;
|
2022-11-04 03:35:56 +08:00
|
|
|
export let root_url: null | string;
|
2022-04-27 18:47:15 +08:00
|
|
|
export let show_label: boolean;
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let height: number | undefined;
|
|
|
|
export let width: number | undefined;
|
2023-08-04 06:01:18 +08:00
|
|
|
|
2023-06-29 02:37:21 +08:00
|
|
|
export let container = false;
|
2023-06-22 03:34:12 +08:00
|
|
|
export let scale: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let min_width: number | undefined = undefined;
|
2022-03-12 00:00:48 +08:00
|
|
|
export let mode: "static" | "dynamic";
|
2023-06-29 02:37:21 +08:00
|
|
|
export let autoplay = false;
|
2023-07-11 23:56:46 +08:00
|
|
|
export let show_share_button = true;
|
2023-06-09 07:27:58 +08:00
|
|
|
|
2023-04-12 07:06:48 +08:00
|
|
|
let _video: FileData | null = null;
|
|
|
|
let _subtitle: FileData | null = null;
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if (value != null) {
|
|
|
|
_video = normalise_file(value[0], root, root_url);
|
|
|
|
_subtitle = normalise_file(value[1], root, root_url);
|
|
|
|
} else {
|
|
|
|
_video = null;
|
|
|
|
_subtitle = null;
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 22:48:39 +08:00
|
|
|
|
|
|
|
let dragging = false;
|
2023-02-02 20:16:38 +08:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
change: undefined;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
$: {
|
2023-04-12 07:06:48 +08:00
|
|
|
if (JSON.stringify(value) !== JSON.stringify(old_value)) {
|
2023-02-02 20:16:38 +08:00
|
|
|
old_value = value;
|
|
|
|
dispatch("change");
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2022-04-26 22:48:39 +08:00
|
|
|
<Block
|
2022-06-17 07:49:54 +08:00
|
|
|
{visible}
|
2022-04-26 22:48:39 +08:00
|
|
|
variant={mode === "dynamic" && value === null && source === "upload"
|
|
|
|
? "dashed"
|
|
|
|
: "solid"}
|
2023-03-07 04:52:31 +08:00
|
|
|
border_mode={dragging ? "focus" : "base"}
|
2022-04-26 22:48:39 +08:00
|
|
|
padding={false}
|
2022-05-12 12:40:41 +08:00
|
|
|
{elem_id}
|
2023-03-16 05:01:53 +08:00
|
|
|
{elem_classes}
|
2023-06-08 09:35:31 +08:00
|
|
|
{height}
|
|
|
|
{width}
|
|
|
|
{container}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
2023-01-21 05:24:24 +08:00
|
|
|
allow_overflow={false}
|
2022-04-26 22:48:39 +08:00
|
|
|
>
|
2022-05-06 03:05:05 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
2022-04-26 22:48:39 +08:00
|
|
|
|
2023-08-04 06:01:18 +08:00
|
|
|
<StaticVideo
|
|
|
|
value={_video}
|
|
|
|
subtitle={_subtitle}
|
|
|
|
{label}
|
|
|
|
{show_label}
|
|
|
|
{autoplay}
|
|
|
|
{show_share_button}
|
|
|
|
on:play
|
|
|
|
on:pause
|
|
|
|
on:stop
|
|
|
|
on:share
|
|
|
|
on:error
|
|
|
|
/>
|
2022-04-26 22:48:39 +08:00
|
|
|
</Block>
|