2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
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-03-08 21:35:42 +08:00
|
|
|
import { playable } from "../utils/helpers";
|
2022-02-07 22:34:53 +08:00
|
|
|
|
2022-03-08 21:35:42 +08:00
|
|
|
import { Video } from "@gradio/video";
|
|
|
|
import { _ } from "svelte-i18n";
|
2022-02-07 22:34:53 +08:00
|
|
|
|
2022-04-08 01:18:41 +08:00
|
|
|
export let value: FileData | null | string = null;
|
|
|
|
export let label: string;
|
2022-03-29 21:10:35 +08:00
|
|
|
export let default_value: FileData | null;
|
2022-04-08 01:18:41 +08:00
|
|
|
export let style: string = "";
|
2022-02-07 22:34:53 +08:00
|
|
|
export let source: string;
|
2022-04-12 04:18:42 +08:00
|
|
|
export let root: string;
|
2022-02-07 22:34:53 +08:00
|
|
|
|
2022-03-12 00:00:48 +08:00
|
|
|
export let mode: "static" | "dynamic";
|
2022-03-29 21:10:35 +08:00
|
|
|
|
|
|
|
if (default_value) value = default_value;
|
2022-04-08 01:18:41 +08:00
|
|
|
|
|
|
|
let _value: null | FileData;
|
2022-04-12 04:18:42 +08:00
|
|
|
$: _value = normalise_file(value, root);
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2022-04-08 01:18:41 +08:00
|
|
|
{#if mode === "static" && _value}
|
2022-03-08 21:35:42 +08:00
|
|
|
<div
|
|
|
|
class="output-video w-full h-60 flex justify-center items-center bg-gray-200 dark:bg-gray-600 relative"
|
|
|
|
>
|
2022-04-08 01:18:41 +08:00
|
|
|
{#if playable(_value.data)}
|
2022-02-01 23:46:50 +08:00
|
|
|
<!-- svelte-ignore a11y-media-has-caption -->
|
|
|
|
<video
|
2022-03-08 21:35:42 +08:00
|
|
|
class="video_preview w-full h-full object-contain"
|
2022-02-01 23:46:50 +08:00
|
|
|
controls
|
|
|
|
playsInline
|
2022-02-07 22:34:53 +08:00
|
|
|
preload="auto"
|
2022-04-08 01:18:41 +08:00
|
|
|
src={_value.data}
|
2022-02-01 23:46:50 +08:00
|
|
|
/>
|
|
|
|
{:else}
|
2022-03-08 21:35:42 +08:00
|
|
|
<a
|
2022-04-08 01:18:41 +08:00
|
|
|
href={_value.data}
|
|
|
|
download={_value.name}
|
2022-03-08 21:35:42 +08:00
|
|
|
class="file-preview h-60 w-full flex flex-col justify-center items-center relative"
|
|
|
|
>
|
2022-04-08 01:18:41 +08:00
|
|
|
<div class="file-name text-4xl p-6 break-all">{_value.name}</div>
|
2022-03-08 21:35:42 +08:00
|
|
|
</a>
|
2022-02-01 23:46:50 +08:00
|
|
|
{/if}
|
2022-03-08 21:35:42 +08:00
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<Video
|
2022-04-08 01:18:41 +08:00
|
|
|
value={_value}
|
|
|
|
on:change={({ detail }) => (value = detail)}
|
|
|
|
{label}
|
2022-03-23 06:40:36 +08:00
|
|
|
{style}
|
2022-03-08 21:35:42 +08:00
|
|
|
{source}
|
|
|
|
drop_text={$_("interface.drop_video")}
|
2022-04-09 02:46:00 +08:00
|
|
|
or_text={$_("or")}
|
2022-03-08 21:35:42 +08:00
|
|
|
upload_text={$_("interface.click_to_upload")}
|
|
|
|
on:change
|
2022-03-17 00:34:30 +08:00
|
|
|
on:clear
|
|
|
|
on:play
|
|
|
|
on:pause
|
2022-03-08 21:35:42 +08:00
|
|
|
/>
|
|
|
|
{/if}
|