summaryrefslogtreecommitdiff
path: root/src/apps/video.tsx
diff options
context:
space:
mode:
authordarkuss <darkussdelta@gmail.com>2026-08-22 01:58:37 +0200
committerdarkuss <darkussdelta@gmail.com>2026-08-22 01:58:37 +0200
commit8f32fd58cafe677c07d9ed9fff84f6e255156d37 (patch)
treea5de06ffb2c0a8b878c8a563ec8cee692efc98ac /src/apps/video.tsx
parent5ac62cc1a4d9a5f50ea26d5bc1afb0fbf95da23c (diff)
holy shit i'm finally done
Diffstat (limited to 'src/apps/video.tsx')
-rw-r--r--src/apps/video.tsx61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/apps/video.tsx b/src/apps/video.tsx
new file mode 100644
index 0000000..4b556af
--- /dev/null
+++ b/src/apps/video.tsx
@@ -0,0 +1,61 @@
+import { effect, Signal, useSignalEffect } from "@preact/signals"
+import { Address } from "$/apps/source";
+import { memo, Ref, useRef } from "preact/compat";
+
+const filenameRegex = /.*\/(.*)$/;
+
+export const Video = memo(function Video({ source, title, contentReady, sizingFinished }: Video.Props) {
+ useSignalEffect(() => {
+ const filename = decodeURIComponent(source.value.link.pathname.match(filenameRegex)?.[1] ?? source.value.link.toString());
+ title.value = `${filename} - media player`;
+ })
+
+ const videoRef: Ref<HTMLVideoElement> = useRef(null);
+
+ return <video controls src={source.value.link.toString()} ref={video => {
+ videoRef.current = video
+ const id = setInterval(() => {
+ if (video && video.videoWidth) {
+ clearInterval(id)
+ contentReady.value = true
+ const vw = Math.max(document.documentElement.clientWidth, window.innerWidth)
+ const vh = Math.max(document.documentElement.clientHeight, window.innerHeight)
+
+ const maxImageSize = Math.min(vw, vh) * 0.4;
+ const smallestImageAxis = Math.min(video.videoHeight, video.videoWidth);
+
+ const aspectRatio = video.videoWidth / video.videoHeight
+ if (smallestImageAxis > maxImageSize) {
+ if (video.videoWidth > video.videoHeight) {
+ video.style.height = `${maxImageSize / aspectRatio}px`
+ video.style.width = `${maxImageSize}px`
+ } else {
+ video.style.height = `${maxImageSize}px`
+ video.style.width = `${maxImageSize * aspectRatio}px`
+ }
+
+ effect(() => {
+ if (sizingFinished.value) {
+ video!.style.setProperty("height", null)
+ video!.style.setProperty("width", null)
+ }
+ })
+ }
+ }
+ }, 50)
+
+ return () => {
+ clearInterval(id)
+ videoRef.current = null
+ }
+ }}/>
+})
+
+namespace Video {
+ export type Props = {
+ source: Signal<Address>,
+ title: Signal<string | undefined>,
+ contentReady: Signal<boolean>,
+ sizingFinished: Signal<boolean>
+ }
+}