Skip to content

A self-hosted media server and file management system

feat: derive transcript placement from screensize and player mode

aminnausin09b1582783fd
diff --git a/resources/js/components/panels/TranscriptSidebar.vue b/resources/js/components/panels/TranscriptSidebar.vue
index 166135e5..5c2e1616 100644
--- a/resources/js/components/panels/TranscriptSidebar.vue
+++ b/resources/js/components/panels/TranscriptSidebar.vue
@@ -1,15 +1,15 @@
<script setup lang="ts">
+import { useTranscript } from '@/components/video/transcript/useTranscript';
import { ButtonCorner } from '@/components/cedar-ui/button';
import { useAppStore } from '@/stores/AppStore';
-import { storeToRefs } from 'pinia';
import PlayerTranscript from '@/components/video/transcript/PlayerTranscript.vue';
import SidebarHeader from '@/components/headers/SidebarHeader.vue';
import ProiconsPanelRight from '~icons/proicons/panel-right';
-const { selectedSideBar } = storeToRefs(useAppStore());
const { cycleSideBar } = useAppStore();
+const { placement } = useTranscript();
</script>
<template>
@@ -26,6 +26,6 @@ const { cycleSideBar } = useAppStore();
</SidebarHeader>
<section id="list-content-transcript" class="full-height-sidebar flex flex-col flex-wrap gap-2">
- <PlayerTranscript :is-visible="selectedSideBar === 'transcript'"> </PlayerTranscript>
+ <PlayerTranscript :is-visible="placement === 'sidebar'" />
</section>
</template>
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index 5acc4873..5ba01c1a 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -1339,29 +1339,7 @@ const addJsonLd = () => {
//#region Transcript
-const {
- player: transcriptPlayer,
- playerViewMode: transcriptViewMode,
- subtitleTrack: transcriptSubtitleTrack,
- isShowingTranscript,
- registerTranscriptContext,
- unregisterTranscriptContext,
-} = useTranscript();
-
-watch(
- player,
- (el) => {
- transcriptPlayer.value = el;
- },
- { immediate: true },
-);
-watch(
- () => playerSubtitles.value?.currentSubtitleTrack ?? playerSubtitles.value?.defaultSubtitleTrack,
- (track) => {
- transcriptSubtitleTrack.value = track;
- },
- { immediate: true },
-);
+const { isShowingTranscript, placement: transcriptPlacement, registerTranscriptContext, unregisterTranscriptContext } = useTranscript();
//#endregion
@@ -1374,13 +1352,6 @@ watch(stateVideo, (_, old) => {
initVideoPlayer(old.id);
});
-watch(
- () => viewMode.value,
- async () => {
- transcriptViewMode.value = viewMode.value;
- },
-);
-
watch(isShowingControls, async (visible) => {
if (!visible || !shouldUpdateUI.value || !player.value) return;
handlePlayerTimeUpdate({ target: player.value });
@@ -1418,13 +1389,12 @@ onMounted(() => {
unSub = onSeek(handleManualSeek);
registerTranscriptContext({
+ player,
+ viewMode,
+ subtitleTrack: computed(() => playerSubtitles.value?.currentSubtitleTrack ?? playerSubtitles.value?.defaultSubtitleTrack),
seek: handleManualSeek,
- close: () => {
- isShowingTranscript.value = false;
- },
- generated: (track) => {
- stateVideo.value.subtitles.push(track);
- },
+ close: () => (isShowingTranscript.value = false),
+ generated: (track) => stateVideo.value.subtitles.push(track),
});
});
@@ -1666,7 +1636,7 @@ defineExpose({
>
<!-- Watch Party (Z-7) -->
<VideoPartyPanel :is-showing-party="isShowingParty" />
- <PlayerTranscript :is-visible="isShowingTranscript && selectedSideBar !== 'transcript'" />
+ <PlayerTranscript :is-visible="transcriptPlacement === 'overlay'" />
</div>
</div>
diff --git a/resources/js/components/video/transcript/PlayerTranscript.vue b/resources/js/components/video/transcript/PlayerTranscript.vue
index ef99774d..5fe6caad 100644
--- a/resources/js/components/video/transcript/PlayerTranscript.vue
+++ b/resources/js/components/video/transcript/PlayerTranscript.vue
@@ -1,13 +1,12 @@
<script setup lang="ts">
import type { ComponentPublicInstance } from 'vue';
-import type { SubtitleResource } from '@/contracts/media';
-import { computed, nextTick, onBeforeUnmount, ref, useTemplateRef, watch } from 'vue';
+import { nextTick, onBeforeUnmount, ref, useTemplateRef, watch } from 'vue';
import { ButtonBase, ButtonCorner } from '@/components/cedar-ui/button';
import { useReactiveBreakpoints } from '@/service/breakpoints/useReactiveBreakpoints';
+import { formatTimestamp } from '@/components/video/transcript/transcriptUtil';
import { useTranscript } from '@/components/video/transcript/useTranscript';
import { useAppStore } from '@/stores/AppStore';
-import { storeToRefs } from 'pinia';
import { cn } from '@aminnausin/cedar-ui';
import GenerateTranscript from '@/components/video/transcript/GenerateTranscript.vue';
@@ -16,37 +15,32 @@ import ProiconsPanelRight from '~icons/proicons/panel-right';
import ProiconsCancel from '~icons/proicons/cancel';
const props = defineProps<{ isVisible?: boolean }>();
-const emit = defineEmits<{ seek: [value: number]; close: []; generated: [track: SubtitleResource] }>();
-const { isDesktop } = useReactiveBreakpoints();
-
-const { selectedSideBar } = storeToRefs(useAppStore());
const { cycleSideBar } = useAppStore();
+const { isDesktop } = useReactiveBreakpoints();
-const { player, isNormalView, rawTranscript, parsedTranscript, subtitleTrack, activeIndex, currentTime, loadedTranscriptUrl, loadTranscript, isLoading, generated, seek, close } =
- useTranscript();
+const {
+ player,
+ isNormalView,
+ subtitleTrack,
+ rawTranscript,
+ parsedTranscript,
+ activeIndex,
+ currentTime,
+ loadedTranscriptUrl,
+ loadTranscript,
+ isLoading,
+ generated,
+ seek,
+ close,
+ placement,
+} = useTranscript();
const transcriptContainer = useTemplateRef('transcript-container');
const transcriptLineRefs = ref<(HTMLElement | null)[]>([]);
const isFollowing = ref(true);
-const isTeleported = computed(() => props.isVisible && selectedSideBar.value === 'transcript');
-
-function formatTimestamp(totalSeconds: number): string {
- const duration = player.value?.duration ?? 0;
-
- const h = Math.floor(totalSeconds / 3600);
- const m = Math.floor((totalSeconds % 3600) / 60);
- const s = totalSeconds % 60;
-
- const formattedSeconds = s.toFixed(0).padStart(2, '0');
-
- if (duration >= 3600) return `${h}:${String(m).padStart(2, '0')}:${formattedSeconds}`;
- if (duration >= 600) return `${String(m).padStart(2, '0')}:${formattedSeconds}`;
- return `${m}:${formattedSeconds}`;
-}
-
function setTranscriptLineRef(index: number, el: Element | ComponentPublicInstance | null) {
transcriptLineRefs.value[index] = el as HTMLElement | null;
}
@@ -65,7 +59,7 @@ function scrollToLine(index: number, behavior: ScrollBehavior = 'smooth') {
let target: number | undefined;
if (lineTop < visibleTop) {
- target = lineTop - (isTeleported.value ? 90 : 40);
+ target = lineTop - (placement.value === 'sidebar' ? 90 : 40);
} else if (lineBottom > visibleBottom) {
target = lineBottom - container.clientHeight + 16;
}
@@ -133,116 +127,116 @@ onBeforeUnmount(() => {
</script>
<template>
- <Teleport v-if="isVisible" defer :disabled="!isTeleported" to="#list-content-transcript">
+ <div
+ v-show="isVisible"
+ :class="[
+ 'pointer-events-auto w-full max-w-80 flex-1 overflow-y-auto xl:max-w-120',
+ { 'rounded-xl border border-neutral-700/10 bg-neutral-800/90 p-1.5 text-[10px] backdrop-blur-md sm:text-xs': placement !== 'sidebar' },
+ { 'relative text-xs': placement === 'sidebar' },
+ ]"
+ >
<div
- v-show="isVisible"
- :class="[
- 'pointer-events-auto w-full max-w-80 flex-1 overflow-y-auto xl:max-w-120',
- { 'rounded-xl border border-neutral-700/10 bg-neutral-800/90 p-1.5 text-[10px] backdrop-blur-md sm:text-xs': !isTeleported },
- { 'relative text-xs': isTeleported },
- ]"
+ ref="transcript-container"
+ :class="['scrollbar-minimal scrollbar-dark relative flex h-full flex-col gap-1 overflow-y-auto pe-1', { 'max-h-(--min-page-height-derived)': placement === 'sidebar' }]"
>
<div
- ref="transcript-container"
- :class="['scrollbar-minimal scrollbar-dark relative flex h-full flex-col gap-1 overflow-y-auto pe-1', { 'max-h-(--min-page-height-derived)': isTeleported }]"
+ :class="cn('sticky top-0 z-10 flex items-center justify-between gap-2 rounded-lg bg-neutral-800 px-2 py-1.5 backdrop-blur-xs', { hidden: placement === 'sidebar' })"
>
- <div :class="cn('sticky top-0 z-10 flex items-center justify-between gap-2 rounded-lg bg-neutral-800 px-2 py-1.5 backdrop-blur-xs', { hidden: isTeleported })">
- <p class="text-xs font-medium text-white/90 sm:text-sm">Transcript</p>
- <div class="flex items-center gap-2">
- <ButtonCorner
- v-if="isDesktop && isNormalView"
- @click="
- () => {
- cycleSideBar('transcript', 'list-card');
- }
- "
- title="Move to Sidebar"
- colour-classes="hover:bg-transparent"
- text-classes="text-white/70 hover:text-white"
- position-classes="size-5"
- >
- <template #icon> <ProiconsPanelRight class="size-4" /> </template>
- </ButtonCorner>
- <ButtonCorner
- title="Close Transcript"
- @click="close()"
- colour-classes="hover:bg-transparent"
- text-classes="text-white/70 hover:text-danger-2"
- position-classes="size-5"
- >
- <template #icon> <ProiconsCancel class="size-4" /> </template>
- </ButtonCorner>
- </div>
+ <p class="text-xs font-medium text-white/90 sm:text-sm">Transcript</p>
+ <div class="flex items-center gap-2">
+ <ButtonCorner
+ v-if="isDesktop && isNormalView"
+ @click="
+ () => {
+ cycleSideBar('transcript', 'list-card');
+ }
+ "
+ title="Move to Sidebar"
+ colour-classes="hover:bg-transparent"
+ text-classes="text-white/70 hover:text-white"
+ position-classes="size-5"
+ >
+ <template #icon> <ProiconsPanelRight class="size-4" /> </template>
+ </ButtonCorner>
+ <ButtonCorner
+ title="Close Transcript"
+ @click="close()"
+ colour-classes="hover:bg-transparent"
+ text-classes="text-white/70 hover:text-danger-2"
+ position-classes="size-5"
+ >
+ <template #icon> <ProiconsCancel class="size-4" /> </template>
+ </ButtonCorner>
+ </div>
+ </div>
+ <div class="w-full space-y-1" v-if="isVisible && subtitleTrack">
+ <div v-if="isLoading">
+ <button type="button" :class="['group flex w-full animate-pulse cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-colors']">
+ <span class="shrink-0 rounded-md px-1.5 py-0.5 font-mono text-xs tabular-nums transition-colors" :class="'bg-white/5 text-transparent'"> 00:00 </span>
+ <span class="h-5 w-full rounded-md bg-white/15"></span>
+ </button>
</div>
- <div class="w-full space-y-1" v-if="isVisible && subtitleTrack">
- <div v-if="isLoading">
- <button type="button" :class="['group flex w-full animate-pulse cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-colors']">
- <span class="shrink-0 rounded-md px-1.5 py-0.5 font-mono text-xs tabular-nums transition-colors" :class="'bg-white/5 text-transparent'"> 00:00 </span>
- <span class="h-5 w-full rounded-md bg-white/15"></span>
- </button>
- </div>
- <div class="space-y-0.5" v-else>
- <button
- v-for="line in parsedTranscript"
- :key="line.index"
- :ref="(el) => setTranscriptLineRef(line.index, el)"
- :class="[
- 'content-auto group flex w-full cursor-pointer items-start gap-2 rounded-lg p-1.5 pe-2 text-left transition-colors [contain-intrinsic-size:32px_auto]',
- line.index === activeIndex && line.end >= currentTime ? 'bg-white/12 text-white' : 'text-white/70 hover:bg-white/7 hover:text-white',
- ]"
- :title="`${line.index + 1} of ${parsedTranscript.length}`"
- type="button"
- @click="
- () => {
- isFollowing = true;
- seek(line.start);
- }
+ <div class="space-y-0.5" v-else>
+ <button
+ v-for="line in parsedTranscript"
+ :key="line.index"
+ :ref="(el) => setTranscriptLineRef(line.index, el)"
+ :class="[
+ 'content-auto group flex w-full cursor-pointer items-start gap-2 rounded-lg p-1.5 pe-2 text-left transition-colors [contain-intrinsic-size:32px_auto]',
+ line.index === activeIndex && line.end >= currentTime ? 'bg-white/12 text-white' : 'text-white/70 hover:bg-white/7 hover:text-white',
+ ]"
+ :title="`${line.index + 1} of ${parsedTranscript.length}`"
+ type="button"
+ @click="
+ () => {
+ isFollowing = true;
+ seek(line.start);
+ }
+ "
+ >
+ <div
+ class="shrink-0 rounded-md px-1.5 py-0.5 font-mono text-xs tabular-nums transition-colors"
+ :class="
+ cn({
+ 'bg-white/15 text-white': line.index === activeIndex && line.end >= currentTime,
+ 'bg-white/10 text-white/50 group-hover:text-white/80': line.index === activeIndex && line.end < currentTime,
+ 'bg-white/5 text-white/50 group-hover:text-white/80': line.index !== activeIndex,
+ })
"
>
- <div
- class="shrink-0 rounded-md px-1.5 py-0.5 font-mono text-xs tabular-nums transition-colors"
- :class="
- cn({
- 'bg-white/15 text-white': line.index === activeIndex && line.end >= currentTime,
- 'bg-white/10 text-white/50 group-hover:text-white/80': line.index === activeIndex && line.end < currentTime,
- 'bg-white/5 text-white/50 group-hover:text-white/80': line.index !== activeIndex,
- })
- "
- >
- {{ formatTimestamp(line.start) }}
- </div>
- <span class="font-dm-sans line-clamp-3 leading-5 select-text" role="text" v-html="line.text"></span>
- </button>
- </div>
+ {{ formatTimestamp(line.start, player?.duration) }}
+ </div>
+ <span class="font-dm-sans line-clamp-3 leading-5 select-text" role="text" v-html="line.text"></span>
+ </button>
</div>
- <GenerateTranscript
- v-else-if="!subtitleTrack"
- :class="{ 'py-20': !isTeleported }"
- @generated="
- (data) => {
- generated(data.track);
- }
- "
- />
</div>
- <Transition
- enter-active-class="transition duration-150 ease-out"
- enter-from-class="translate-y-1 opacity-0"
- enter-to-class="translate-y-0 opacity-100"
- leave-active-class="transition duration-100 ease-in"
- leave-from-class="opacity-100"
- leave-to-class="opacity-0"
- >
- <ButtonBase
- v-if="!isFollowing && !isLoading && activeIndex !== -1"
- type="button"
- class="text-foreground-0 dark:text-foreground-i absolute bottom-2 left-1/2 z-20 -translate-x-1/2 rounded-full bg-white px-2 py-1.5 font-medium transition hover:bg-white/90"
- :use-size="false"
- @click="resync"
- >
- Jump to current
- </ButtonBase>
- </Transition>
+ <GenerateTranscript
+ v-else-if="!subtitleTrack"
+ :class="{ 'py-20': placement !== 'sidebar' }"
+ @generated="
+ (data) => {
+ generated(data.track);
+ }
+ "
+ />
</div>
- </Teleport>
+ <Transition
+ enter-active-class="transition duration-150 ease-out"
+ enter-from-class="translate-y-1 opacity-0"
+ enter-to-class="translate-y-0 opacity-100"
+ leave-active-class="transition duration-100 ease-in"
+ leave-from-class="opacity-100"
+ leave-to-class="opacity-0"
+ >
+ <ButtonBase
+ v-if="!isFollowing && !isLoading && activeIndex !== -1"
+ type="button"
+ class="text-foreground-0 dark:text-foreground-i absolute bottom-2 left-1/2 z-20 -translate-x-1/2 rounded-full bg-white px-2 py-1.5 font-medium transition hover:bg-white/90"
+ :use-size="false"
+ @click="resync"
+ >
+ Jump to current
+ </ButtonBase>
+ </Transition>
+ </div>
</template>