Skip to content

Commit bdc95b7

Browse files
committed
workign working working
1 parent 67a4d4c commit bdc95b7

6 files changed

Lines changed: 379 additions & 62 deletions

File tree

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<script lang="ts">
2+
import type { WhisperWord } from '$lib/utils/whisper-parser';
3+
import { captionSettings } from '$lib/stores/captionSettings.svelte';
4+
5+
interface Props {
6+
words: WhisperWord[];
7+
currentTime: number;
8+
showCaptions: boolean;
9+
}
10+
11+
let { words, currentTime, showCaptions }: Props = $props();
12+
13+
// Track element ref for measuring word positions
14+
let trackElement = $state<HTMLDivElement | null>(null);
15+
let scrollOffset = $state(0);
16+
17+
// Narration has started (first word spoken)
18+
let hasStarted = $derived(words.length > 0 && currentTime >= words[0].start);
19+
20+
// Narration has ended (past the last word) - start fading out
21+
let isFadingOut = $derived(words.length > 0 && currentTime > words[words.length - 1].end);
22+
23+
// Fully ended (after fade completes)
24+
let hasEnded = $derived(words.length > 0 && currentTime > words[words.length - 1].end + 1.5);
25+
26+
// Find the index of the current word being spoken
27+
let currentWordIndex = $derived(() => {
28+
if (!hasStarted) return -1;
29+
for (let i = words.length - 1; i >= 0; i--) {
30+
if (currentTime >= words[i].start) {
31+
return i;
32+
}
33+
}
34+
return -1;
35+
});
36+
37+
// Should show the caption container
38+
let isVisible = $derived(showCaptions && hasStarted && !hasEnded);
39+
40+
// All words with their state
41+
let allWords = $derived(() => {
42+
const idx = currentWordIndex();
43+
return words.map((word, i) => ({
44+
...word,
45+
index: i,
46+
isCurrent: i === idx,
47+
isSpoken: i < idx,
48+
isUpcoming: i > idx
49+
}));
50+
});
51+
52+
// Update scroll offset when current word changes
53+
$effect(() => {
54+
const idx = currentWordIndex();
55+
if (idx < 0 || !trackElement) return;
56+
57+
const wordElements = trackElement.querySelectorAll('.caption-word');
58+
if (wordElements[idx]) {
59+
const wordEl = wordElements[idx] as HTMLElement;
60+
scrollOffset = wordEl.offsetLeft + (wordEl.offsetWidth / 2);
61+
}
62+
});
63+
64+
// Get CSS custom properties from settings
65+
let cssVars = $derived(`
66+
--caption-highlight: ${captionSettings.highlightColorValue};
67+
--caption-font-size: ${captionSettings.fontSizeValue};
68+
--caption-bg: ${captionSettings.backgroundValue};
69+
`);
70+
</script>
71+
72+
{#if isVisible}
73+
<div class="mobile-caption" class:fading-out={isFadingOut} style={cssVars}>
74+
<div class="caption-track-container">
75+
<div class="fade-mask fade-left"></div>
76+
<div class="fade-mask fade-right"></div>
77+
<div
78+
class="words-track"
79+
bind:this={trackElement}
80+
style="transform: translateX(calc(50% - {scrollOffset}px))"
81+
>
82+
{#each allWords() as word (word.index)}
83+
<span
84+
class="caption-word"
85+
class:current={word.isCurrent}
86+
class:spoken={word.isSpoken}
87+
class:upcoming={word.isUpcoming}
88+
>{word.word}</span>
89+
{/each}
90+
</div>
91+
</div>
92+
</div>
93+
{/if}
94+
95+
<style>
96+
.mobile-caption {
97+
/* Fill the entire slot area */
98+
position: absolute;
99+
top: 0;
100+
left: 0;
101+
right: 0;
102+
bottom: 0;
103+
padding: 0.5rem;
104+
overflow: hidden;
105+
/* User's caption background setting controls transparency of this area */
106+
background: var(--caption-bg, rgba(0, 0, 0, 0.85));
107+
display: flex;
108+
align-items: center;
109+
justify-content: center;
110+
animation: slideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
111+
opacity: 1;
112+
transform: translateY(0);
113+
transition: opacity 0.8s ease-out, transform 0.8s ease-out;
114+
}
115+
116+
.mobile-caption.fading-out {
117+
opacity: 0;
118+
transform: translateY(20px);
119+
}
120+
121+
@keyframes slideIn {
122+
0% {
123+
opacity: 0;
124+
transform: translateY(20px);
125+
}
126+
100% {
127+
opacity: 1;
128+
transform: translateY(0);
129+
}
130+
}
131+
132+
.caption-track-container {
133+
position: relative;
134+
overflow: hidden;
135+
}
136+
137+
.fade-mask {
138+
position: absolute;
139+
top: 0;
140+
bottom: 0;
141+
width: 40px;
142+
z-index: 2;
143+
pointer-events: none;
144+
}
145+
146+
.fade-left {
147+
left: 0;
148+
/* Use user's caption background setting for fade */
149+
background: linear-gradient(to right, var(--caption-bg, rgba(0, 0, 0, 0.85)) 0%, transparent 100%);
150+
}
151+
152+
.fade-right {
153+
right: 0;
154+
/* Use user's caption background setting for fade */
155+
background: linear-gradient(to left, var(--caption-bg, rgba(0, 0, 0, 0.85)) 0%, transparent 100%);
156+
}
157+
158+
.words-track {
159+
display: flex;
160+
align-items: baseline;
161+
gap: 0.35em;
162+
font-size: calc(var(--caption-font-size, 1rem) * 0.85);
163+
line-height: 1.4;
164+
white-space: nowrap;
165+
transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
166+
}
167+
168+
.caption-word {
169+
display: inline-block;
170+
flex-shrink: 0;
171+
transition:
172+
color 0.2s ease-out,
173+
opacity 0.25s ease-out,
174+
transform 0.2s ease-out;
175+
}
176+
177+
.caption-word.current {
178+
color: var(--caption-highlight, #ffd700);
179+
font-weight: 700;
180+
transform: scale(1.05);
181+
opacity: 1;
182+
}
183+
184+
.caption-word.spoken {
185+
color: #ffffff;
186+
opacity: 0.6;
187+
}
188+
189+
.caption-word.upcoming {
190+
color: #ffffff;
191+
opacity: 0.4;
192+
}
193+
</style>

‎src/lib/components/VideoControls.svelte‎

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@
234234
/>
235235

236236
<div class="video-controls" class:danger={variant === 'danger'} class:success={variant === 'success'}>
237+
<!-- Caption slot for mobile - rendered above controls -->
238+
<div class="mobile-caption-slot">
239+
<slot name="captions" />
240+
</div>
241+
237242
<!-- Timeline -->
238243
<div
239244
class="timeline-container"
@@ -449,7 +454,7 @@
449454
</div>
450455
</div>
451456

452-
<div class="settings-section">
457+
<div class="settings-section reset-position-section">
453458
<button class="reset-btn" onclick={() => captionSettings.resetPosition()}>
454459
<i class="fa-solid fa-arrows-to-dot"></i> Reset Caption Position
455460
</button>
@@ -472,6 +477,15 @@
472477
--controls-accent: var(--accent-blue);
473478
}
474479
480+
/* Mobile caption slot - hidden on desktop */
481+
.mobile-caption-slot {
482+
display: none;
483+
}
484+
485+
.mobile-caption-slot:empty {
486+
display: none;
487+
}
488+
475489
.video-controls.danger {
476490
--controls-accent: var(--accent-red);
477491
}
@@ -985,6 +999,39 @@
985999
}
9861000
9871001
/* Mobile Responsive Styles */
1002+
@media (max-width: 1000px) {
1003+
.video-controls {
1004+
position: fixed;
1005+
bottom: 0;
1006+
left: 0;
1007+
right: 0;
1008+
z-index: 900;
1009+
border-radius: 0;
1010+
border-top: 1px solid var(--border);
1011+
box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
1012+
}
1013+
1014+
/* Show caption slot on mobile - positioned above the controls */
1015+
.mobile-caption-slot {
1016+
display: block;
1017+
position: absolute;
1018+
bottom: 100%;
1019+
left: 0;
1020+
right: 0;
1021+
/* Height of the transparent area - user controls opacity via caption background setting */
1022+
min-height: 60px;
1023+
}
1024+
1025+
.mobile-caption-slot:empty {
1026+
display: none;
1027+
}
1028+
1029+
/* Hide reset caption position on mobile - captions aren't draggable */
1030+
.reset-position-section {
1031+
display: none;
1032+
}
1033+
}
1034+
9881035
@media (max-width: 768px) {
9891036
.video-controls {
9901037
padding: 0.5rem;
@@ -1027,9 +1074,17 @@
10271074
font-size: 0.7rem;
10281075
}
10291076
1077+
/* Settings popup - position above the settings icon on mobile */
10301078
.settings-popup {
1031-
right: -60px;
1032-
min-width: 200px;
1079+
position: absolute;
1080+
bottom: 100%;
1081+
right: 0;
1082+
left: auto;
1083+
top: auto;
1084+
transform: none;
1085+
min-width: 220px;
1086+
max-width: 90vw;
1087+
margin-bottom: 0.5rem;
10331088
}
10341089
10351090
.audience-hint {
@@ -1079,24 +1134,25 @@
10791134
max-width: 90px;
10801135
}
10811136
1137+
/* Settings popup - keep above the settings icon */
10821138
.settings-popup {
1083-
position: fixed;
1084-
bottom: auto;
1085-
top: 50%;
1086-
left: 50%;
1087-
right: auto;
1088-
transform: translate(-50%, -50%);
1089-
min-width: 280px;
1139+
position: absolute;
1140+
bottom: 100%;
1141+
right: 0;
1142+
left: auto;
1143+
top: auto;
1144+
transform: none;
1145+
min-width: 220px;
10901146
max-width: 90vw;
1091-
margin-bottom: 0;
1147+
margin-bottom: 0.5rem;
10921148
}
10931149
10941150
.volume-slider-popup {
1095-
position: fixed;
1096-
bottom: auto;
1097-
top: 50%;
1151+
position: absolute;
1152+
bottom: 100%;
10981153
left: 50%;
1099-
transform: translate(-50%, -50%);
1154+
top: auto;
1155+
transform: translateX(-50%);
11001156
}
11011157
11021158
.audience-hint {

‎src/lib/components/WordCaption.svelte‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,15 @@
283283
opacity: 0.4;
284284
}
285285
286-
/* Mobile responsive */
286+
/* Mobile - hide the fixed overlay since captions are in the video controls slot */
287+
@media (max-width: 1000px) {
288+
.word-caption-overlay {
289+
display: none !important;
290+
}
291+
}
292+
287293
@media (max-width: 600px) {
294+
288295
.word-caption-container {
289296
width: 95vw;
290297
max-width: 95vw;
@@ -300,12 +307,6 @@
300307
font-size: calc(var(--caption-font-size, 1.2rem) * 0.85);
301308
gap: 0.35em;
302309
}
303-
304-
.drag-handle {
305-
top: -20px;
306-
padding: 3px 12px;
307-
font-size: 0.65rem;
308-
}
309310
}
310311
311312
@media (max-width: 380px) {

‎src/lib/components/steps/RSCStep.svelte‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
import { whisperToCaptions, extractRSCKeyframeTriggers, getAudioDuration, getAllWords, type WhisperOutput, type WhisperWord } from '$lib/utils/whisper-parser';
1010
import { comprehension, loadWhisperData } from '$lib/stores/comprehension.svelte';
1111
import { onMount, tick } from 'svelte';
12+
import { getRSCScrollTarget, scrollToTarget, resetScrollTracking, type ScrollTarget } from '$lib/utils/autoScroll';
1213
1314
// Loading state for lazy loading
1415
let isLoading = $state(true);
1516
let loadError = $state<string | null>(null);
1617
18+
// Container ref for auto-scrolling on mobile
19+
let animationContainer = $state<HTMLElement | null>(null);
20+
1721
// Current whisper data - loaded lazily
1822
let whisper = $state<WhisperOutput | null>(null);
1923
let captions = $derived(whisper ? whisperToCaptions(whisper) : []);

0 commit comments

Comments
 (0)