gradio/ui/packages/app/src/components/Video/Video.svelte

63 lines
1.5 KiB
Svelte
Raw Normal View History

<script lang="ts">
2022-03-08 21:35:42 +08:00
import type { FileData } from "@gradio/upload";
import { normalise_file } from "@gradio/upload";
2022-03-08 21:35:42 +08:00
import { playable } from "../utils/helpers";
2022-03-08 21:35:42 +08:00
import { Video } from "@gradio/video";
import { _ } from "svelte-i18n";
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;
export let style: string = "";
export let source: string;
export let root: string;
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;
let _value: null | FileData;
$: _value = normalise_file(value, root);
</script>
{#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"
>
{#if playable(_value.data)}
<!-- svelte-ignore a11y-media-has-caption -->
<video
2022-03-08 21:35:42 +08:00
class="video_preview w-full h-full object-contain"
controls
playsInline
preload="auto"
src={_value.data}
/>
{:else}
2022-03-08 21:35:42 +08:00
<a
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"
>
<div class="file-name text-4xl p-6 break-all">{_value.name}</div>
2022-03-08 21:35:42 +08:00
</a>
{/if}
2022-03-08 21:35:42 +08:00
</div>
{:else}
<Video
value={_value}
on:change={({ detail }) => (value = detail)}
{label}
{style}
2022-03-08 21:35:42 +08:00
{source}
drop_text={$_("interface.drop_video")}
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}