2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2022-03-23 06:40:36 +08:00
|
|
|
import { playable } from "../../utils/helpers";
|
2022-05-25 04:08:08 +08:00
|
|
|
import { onMount } from "svelte";
|
2022-02-01 21:45:55 +08:00
|
|
|
|
2023-01-18 04:47:40 +08:00
|
|
|
export let type: "gallery" | "table";
|
|
|
|
export let selected: boolean = false;
|
2022-02-07 22:34:53 +08:00
|
|
|
export let value: string;
|
2022-03-25 12:00:30 +08:00
|
|
|
export let samples_dir: string;
|
2022-02-07 22:34:53 +08:00
|
|
|
let video: HTMLVideoElement;
|
2022-05-25 04:08:08 +08:00
|
|
|
|
2023-02-04 01:36:31 +08:00
|
|
|
async function init() {
|
2022-05-25 04:08:08 +08:00
|
|
|
video.muted = true;
|
|
|
|
video.playsInline = true;
|
|
|
|
video.controls = false;
|
|
|
|
video.setAttribute("muted", "");
|
2023-02-04 01:36:31 +08:00
|
|
|
|
|
|
|
await video.play();
|
2022-05-25 04:08:08 +08:00
|
|
|
video.pause();
|
2023-02-04 01:36:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
init();
|
2022-05-25 04:08:08 +08:00
|
|
|
});
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- svelte-ignore a11y-media-has-caption -->
|
|
|
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
2022-07-22 02:12:46 +08:00
|
|
|
{#if playable()}
|
2022-02-01 23:46:50 +08:00
|
|
|
<video
|
2022-05-25 04:08:08 +08:00
|
|
|
muted
|
|
|
|
playsinline
|
2022-02-01 23:46:50 +08:00
|
|
|
bind:this={video}
|
2023-01-18 04:47:40 +08:00
|
|
|
class:table={type === "table"}
|
|
|
|
class:gallery={type === "gallery"}
|
|
|
|
class:selected
|
2022-02-01 23:46:50 +08:00
|
|
|
on:mouseover={video.play}
|
|
|
|
on:mouseout={video.pause}
|
2022-03-25 12:00:30 +08:00
|
|
|
src={samples_dir + value}
|
2022-02-01 23:46:50 +08:00
|
|
|
/>
|
2022-02-01 21:45:55 +08:00
|
|
|
{:else}
|
2023-01-18 04:47:40 +08:00
|
|
|
<div>{value}</div>
|
2022-02-01 21:45:55 +08:00
|
|
|
{/if}
|
2023-01-18 04:47:40 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
video {
|
|
|
|
flex: none;
|
|
|
|
border: 2px solid var(--color-border-primary);
|
|
|
|
border-radius: var(--radius-lg);
|
|
|
|
max-width: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
video:hover,
|
|
|
|
video.selected {
|
2023-03-07 04:52:31 +08:00
|
|
|
border-color: var(--color-border-accent);
|
2023-01-18 04:47:40 +08:00
|
|
|
}
|
|
|
|
.table {
|
2023-03-07 04:52:31 +08:00
|
|
|
margin: 0 auto;
|
2023-01-18 04:47:40 +08:00
|
|
|
width: var(--size-20);
|
|
|
|
height: var(--size-20);
|
|
|
|
object-fit: cover;
|
|
|
|
}
|
|
|
|
|
|
|
|
.gallery {
|
|
|
|
max-height: var(--size-20);
|
|
|
|
object-fit: cover;
|
|
|
|
}
|
|
|
|
</style>
|