11<script setup lang="ts">
22import type { SubtitleResource } from ' @/types/resources' ;
3- import { cn , type PopoverItem } from ' @aminnausin/cedar-ui' ;
3+ import type { PopoverItem } from ' @aminnausin/cedar-ui' ;
44import type { Ref } from ' vue' ;
55
66import { computed , inject , ref , useTemplateRef } from ' vue' ;
77import { useContentStore } from ' @/stores/ContentStore' ;
88import { storeToRefs } from ' pinia' ;
9+ import { round } from ' lodash-es' ;
10+ import { cn } from ' @aminnausin/cedar-ui' ;
911
12+ import VideoPopoverSlider from ' @/components/video/VideoPopoverSlider.vue' ;
1013import VideoPopoverItem from ' @/components/video/VideoPopoverItem.vue' ;
1114import VideoPopover from ' @/components/video/VideoPopover.vue' ;
1215
16+ import ProiconsTextFontSize from ' ~icons/proicons/text-font-size' ;
1317import ProiconsCheckmark from ' ~icons/proicons/checkmark' ;
1418import LucideCaptionsOff from ' ~icons/lucide/captions-off' ;
1519import LucideCaptions from ' ~icons/lucide/captions' ;
@@ -28,6 +32,10 @@ const props = defineProps<PlayerSubtitlesProps>();
2832// #region Local State
2933const currentSubtitleTrack = ref <SubtitleResource >();
3034const isShowingSubtitles = ref (false );
35+ const subtitleSizeMultiplier = ref (1 );
36+ const subtitleSizeMin = 0.5 ;
37+ const subtitleSizeMax = 2 ;
38+ const subtitleSizeDelta = 0.1 ;
3139
3240const subtitlesPopover = useTemplateRef (' subtitles-popover' );
3341const playerSubtitleItems = computed (() => {
@@ -70,6 +78,19 @@ const defaultSubtitleTrack = computed<SubtitleResource | undefined>(() => {
7078
7179 return subtitles .find ((s ) => s .is_default ) ?? subtitles [0 ];
7280});
81+
82+ const handleSizeChange = (_ : Event , dir : number = 0 ) => {
83+ if (dir ) {
84+ subtitleSizeMultiplier .value = round (Math .max (Math .min (parseFloat (` ${subtitleSizeMultiplier .value } ` ) + subtitleSizeDelta * dir , subtitleSizeMax ), subtitleSizeMin ), 2 );
85+ }
86+ };
87+
88+ const handleSizeWheel = (event : WheelEvent ) => {
89+ event .preventDefault ();
90+
91+ handleSizeChange (new Event (' SizeChange' ), event .deltaY < 0 ? 1 : - 1 );
92+ };
93+
7394// #endregion
7495
7596// #region Functions
@@ -116,14 +137,16 @@ defineExpose({
116137 isShowingSubtitles ,
117138 currentSubtitleTrack ,
118139 defaultSubtitleTrack ,
140+ subtitleSizeMultiplier ,
141+ subtitlesPopover ,
119142});
120143 </script >
121144<template >
122145 <VideoPopover
123146 ref="subtitles-popover"
124147 :margin =" 80 "
125148 :player =" player "
126- :popoverClass =" cn (' max-w-40! rounded-lg md:h-fit' , { ' h-18 ' : playerSubtitleItems .length > 1 }, { ' right-0!' : usingPlayerModernUI })"
149+ :popoverClass =" cn (' max-w-40! rounded-lg md:h-fit' , { ' h-28 ' : playerSubtitleItems .length > 1 }, { ' right-0!' : usingPlayerModernUI })"
127150 :button-attributes =" {
128151 ' target-element' : player ,
129152 ' use-tooltip' : true ,
@@ -136,7 +159,20 @@ defineExpose({
136159 <LucideCaptionsOff v-else class="size-4" />
137160 </template >
138161 <template #content >
139- <section :class =" ['scrollbar-minimal flex max-h-28 flex-col overflow-y-auto transition-transform md:h-fit', { 'h-14': playerSubtitleItems.length > 1 }]" >
162+ <section :class =" ['scrollbar-minimal flex max-h-32 flex-col overflow-y-auto transition-transform md:h-fit', { 'h-25 pe-0.5': playerSubtitleItems.length > 1 }]" >
163+ <VideoPopoverSlider
164+ v-if =" playerSubtitleItems .length > 1 "
165+ v-model =" subtitleSizeMultiplier "
166+ :text =" ` Font Size ` "
167+ :shortcut =" ` ${Math .round (subtitleSizeMultiplier * 100 )}% ` "
168+ :icon =" ProiconsTextFontSize "
169+ :min =" 0.5 "
170+ :max =" 2 "
171+ :step =" 0.1 "
172+ :action =" handleSizeChange "
173+ :wheel-action =" handleSizeWheel "
174+ :title =" ' Change Subtitle Font Size' "
175+ />
140176 <VideoPopoverItem v-for =" (item , index ) in playerSubtitleItems " :key =" index " v-bind =" item " class="capitalize" />
141177 </section >
142178 </template >
0 commit comments