2021-12-30 18:09:24 +01:00
|
|
|
import { css, html, LitElement, TemplateResult } from "lit";
|
2022-01-02 15:11:05 +01:00
|
|
|
import {
|
|
|
|
customElement,
|
|
|
|
property,
|
|
|
|
queryAssignedNodes,
|
|
|
|
state,
|
|
|
|
} from "lit/decorators.js";
|
2021-12-30 18:09:24 +01:00
|
|
|
import { styleMap } from "lit/directives/style-map.js";
|
|
|
|
|
|
|
|
enum VideoFormats {
|
|
|
|
Landscape = "landscape",
|
|
|
|
Portrait = "portrait",
|
|
|
|
Squared = "squared",
|
|
|
|
}
|
|
|
|
|
|
|
|
const formatMap = {
|
|
|
|
[VideoFormats.Landscape]: "16/9",
|
|
|
|
[VideoFormats.Portrait]: "9/16",
|
|
|
|
[VideoFormats.Squared]: "1/1",
|
|
|
|
};
|
|
|
|
|
|
|
|
@customElement("video-clip-previewer")
|
|
|
|
export class VideoClipPreviewer extends LitElement {
|
|
|
|
@queryAssignedNodes("preview_image", true)
|
2022-01-02 15:11:05 +01:00
|
|
|
_image!: NodeListOf<HTMLImageElement>;
|
2021-12-30 18:09:24 +01:00
|
|
|
|
|
|
|
@property()
|
2022-01-02 15:11:05 +01:00
|
|
|
title = "";
|
2021-12-30 18:09:24 +01:00
|
|
|
|
|
|
|
@property()
|
2022-01-02 15:11:05 +01:00
|
|
|
format: VideoFormats = VideoFormats.Portrait;
|
|
|
|
|
|
|
|
@property()
|
|
|
|
theme = "173 44% 96%";
|
|
|
|
|
|
|
|
@property({ type: Number })
|
|
|
|
duration!: number;
|
|
|
|
|
|
|
|
@state()
|
|
|
|
_previewImage!: HTMLImageElement;
|
|
|
|
|
|
|
|
protected firstUpdated(): void {
|
|
|
|
this._previewImage = this._image[0].cloneNode(true) as HTMLImageElement;
|
|
|
|
this._previewImage.classList.add("preview-bg");
|
|
|
|
}
|
|
|
|
|
|
|
|
private secondsToHHMMSS(seconds: number) {
|
|
|
|
// Adapted from https://stackoverflow.com/a/34841026
|
|
|
|
const h = Math.floor(seconds / 3600);
|
|
|
|
const min = Math.floor(seconds / 60) % 60;
|
|
|
|
const s = seconds % 60;
|
|
|
|
|
|
|
|
return [h, min, s]
|
|
|
|
.map((v) => (v < 10 ? "0" + v : v))
|
|
|
|
.filter((v, i) => v !== "00" || i > 0)
|
|
|
|
.join(":");
|
|
|
|
}
|
2021-12-30 18:09:24 +01:00
|
|
|
|
|
|
|
static styles = css`
|
2022-01-02 15:11:05 +01:00
|
|
|
.metadata {
|
|
|
|
position: absolute;
|
|
|
|
top: 1rem;
|
|
|
|
left: 1.5rem;
|
|
|
|
color: #ffffff;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
|
|
|
font-family: "Kumbh Sans";
|
|
|
|
font-weight: 900;
|
|
|
|
font-size: 1.5rem;
|
|
|
|
text-shadow: 2px 3px 5px rgba(0, 0, 0, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
.duration {
|
|
|
|
font-family: "Inter";
|
|
|
|
font-weight: 600;
|
|
|
|
}
|
|
|
|
|
|
|
|
.preview-bg {
|
|
|
|
position: absolute;
|
|
|
|
background-color: red;
|
|
|
|
width: 100%;
|
|
|
|
object-fit: cover;
|
|
|
|
filter: blur(30px);
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
|
2021-12-30 18:09:24 +01:00
|
|
|
.video-background {
|
2022-01-02 15:11:05 +01:00
|
|
|
position: relative;
|
2021-12-30 18:09:24 +01:00
|
|
|
display: grid;
|
|
|
|
justify-items: center;
|
|
|
|
align-items: center;
|
|
|
|
background-color: black;
|
|
|
|
width: 100%;
|
|
|
|
aspect-ratio: 16 / 9;
|
2022-01-02 15:11:05 +01:00
|
|
|
border-radius: 0.75rem 0.75rem 0 0;
|
|
|
|
overflow: hidden;
|
2021-12-30 18:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.video-format {
|
2022-01-02 15:11:05 +01:00
|
|
|
z-index: 10;
|
2021-12-30 18:09:24 +01:00
|
|
|
display: grid;
|
|
|
|
align-items: center;
|
|
|
|
justify-items: center;
|
|
|
|
height: 100%;
|
2022-01-02 15:11:05 +01:00
|
|
|
border: 4px solid hsl(0 0% 100% / 0.5);
|
|
|
|
transition: 300ms ease-in-out aspect-ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
::slotted(img) {
|
|
|
|
border-radius: 0.5rem;
|
|
|
|
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1),
|
|
|
|
0 2px 4px -2px rgb(0 0 0 / 0.1);
|
2021-12-30 18:09:24 +01:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
render(): TemplateResult<1> {
|
|
|
|
const styles = {
|
|
|
|
aspectRatio: formatMap[this.format],
|
2022-01-02 15:11:05 +01:00
|
|
|
backgroundColor: `hsl(${this.theme})`,
|
2021-12-30 18:09:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return html`<div class="video-background">
|
2022-01-02 15:11:05 +01:00
|
|
|
${this._previewImage}
|
2021-12-30 18:09:24 +01:00
|
|
|
<div class="video-format" style=${styleMap(styles)}>
|
2022-01-02 15:11:05 +01:00
|
|
|
<div class="metadata">
|
|
|
|
<span class="title">${this.title}</span>
|
|
|
|
<time datetime="PT${this.duration}S" class="duration"
|
|
|
|
>${this.secondsToHHMMSS(Math.floor(this.duration))}</time
|
|
|
|
>
|
|
|
|
</div>
|
2021-12-30 18:09:24 +01:00
|
|
|
<slot name="preview_image"></slot>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
}
|