@sdxc/ui 2026.11.11 → 2026.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -44
- package/dist/app/app-shell-toggle.d.ts +2 -0
- package/dist/app/app-shell-toggle.js +5 -2
- package/dist/app/app-shell.d.ts +25 -1
- package/dist/app/app-shell.js +73 -38
- package/dist/app/auto-refresh.d.ts +2 -0
- package/dist/app/auto-refresh.js +3 -3
- package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
- package/dist/app/behaviors/refresh-schedule.js +4 -3
- package/dist/app/board.d.ts +123 -0
- package/dist/app/board.js +224 -0
- package/dist/app/chart.d.ts +2 -2
- package/dist/app/chart.js +7 -3
- package/dist/app/check-runs.d.ts +116 -0
- package/dist/app/check-runs.js +201 -0
- package/dist/app/code-view.d.ts +172 -0
- package/dist/app/code-view.js +414 -0
- package/dist/app/command-palette.d.ts +38 -3
- package/dist/app/command-palette.js +53 -5
- package/dist/app/contribution-graph.d.ts +106 -0
- package/dist/app/contribution-graph.js +289 -0
- package/dist/app/detail-sheet.d.ts +7 -0
- package/dist/app/detail-sheet.js +7 -7
- package/dist/app/diff.d.ts +200 -0
- package/dist/app/diff.js +702 -0
- package/dist/app/filter-bar.d.ts +20 -0
- package/dist/app/filter-bar.js +35 -15
- package/dist/app/filter-menu.d.ts +144 -0
- package/dist/app/filter-menu.js +480 -0
- package/dist/app/gantt.d.ts +108 -0
- package/dist/app/gantt.js +420 -0
- package/dist/app/index.d.ts +19 -0
- package/dist/app/index.js +19 -0
- package/dist/app/log-viewer.d.ts +120 -0
- package/dist/app/log-viewer.js +384 -0
- package/dist/app/merge-box.d.ts +97 -0
- package/dist/app/merge-box.js +227 -0
- package/dist/app/mixins/app-shell-controls.d.ts +4 -1
- package/dist/app/mixins/app-shell-controls.js +64 -4
- package/dist/app/mixins/auto-refresh.d.ts +5 -2
- package/dist/app/mixins/auto-refresh.js +9 -3
- package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
- package/dist/app/mixins/close-popover-on-submit.js +32 -0
- package/dist/app/mixins/code-view-selection.d.ts +60 -0
- package/dist/app/mixins/code-view-selection.js +276 -0
- package/dist/app/mixins/command-palette.d.ts +15 -4
- package/dist/app/mixins/command-palette.js +94 -6
- package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
- package/dist/app/mixins/contribution-graph-keys.js +155 -0
- package/dist/app/mixins/diff-interactions.d.ts +72 -0
- package/dist/app/mixins/diff-interactions.js +269 -0
- package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
- package/dist/app/mixins/filter-menu-keys.js +91 -0
- package/dist/app/mixins/gantt-today.d.ts +17 -0
- package/dist/app/mixins/gantt-today.js +50 -0
- package/dist/app/mixins/log-viewer.d.ts +29 -0
- package/dist/app/mixins/log-viewer.js +333 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
- package/dist/app/mixins/save-bar-sync.d.ts +7 -1
- package/dist/app/mixins/save-bar-sync.js +23 -4
- package/dist/app/mixins/save-status-sync.js +23 -1
- package/dist/app/mixins/split-view.js +1 -1
- package/dist/app/mixins/submit-on-close.d.ts +17 -0
- package/dist/app/mixins/submit-on-close.js +52 -0
- package/dist/app/mixins/tree-filter.d.ts +44 -0
- package/dist/app/mixins/tree-filter.js +111 -0
- package/dist/app/mixins/tree-navigation.d.ts +50 -0
- package/dist/app/mixins/tree-navigation.js +216 -0
- package/dist/app/optimistic-toggle.d.ts +8 -0
- package/dist/app/optimistic-toggle.js +3 -2
- package/dist/app/page-header.d.ts +18 -3
- package/dist/app/page-header.js +105 -50
- package/dist/app/review-thread.d.ts +115 -0
- package/dist/app/review-thread.js +116 -0
- package/dist/app/save-bar.d.ts +5 -0
- package/dist/app/save-bar.js +1 -1
- package/dist/app/settings-layout.d.ts +5 -0
- package/dist/app/settings-layout.js +5 -5
- package/dist/app/skeleton.d.ts +9 -0
- package/dist/app/skeleton.js +28 -0
- package/dist/app/split-view.d.ts +4 -0
- package/dist/app/split-view.js +3 -3
- package/dist/app/styles/code-tokens.d.ts +24 -0
- package/dist/app/styles/code-tokens.js +47 -0
- package/dist/app/tab-bar.d.ts +59 -0
- package/dist/app/tab-bar.js +111 -0
- package/dist/app/tree.d.ts +111 -14
- package/dist/app/tree.js +202 -15
- package/dist/app/utils/ansi.d.ts +55 -0
- package/dist/app/utils/ansi.js +157 -0
- package/dist/app/utils/diff-rows.d.ts +82 -0
- package/dist/app/utils/diff-rows.js +209 -0
- package/dist/app/utils/fuzzy-path.d.ts +58 -0
- package/dist/app/utils/fuzzy-path.js +202 -0
- package/dist/app/utils/line-range.d.ts +48 -0
- package/dist/app/utils/line-range.js +61 -0
- package/dist/app/utils/log-lines.d.ts +107 -0
- package/dist/app/utils/log-lines.js +170 -0
- package/dist/app/utils/tree-filter.d.ts +19 -0
- package/dist/app/utils/tree-filter.js +26 -0
- package/dist/app/view-options.d.ts +2 -0
- package/dist/app/view-options.js +2 -2
- package/dist/chat/activity.d.ts +72 -0
- package/dist/chat/activity.js +184 -0
- package/dist/chat/composer-submit.d.ts +38 -0
- package/dist/chat/composer-submit.js +44 -0
- package/dist/chat/composer.d.ts +47 -0
- package/dist/chat/composer.js +100 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mixins/composer-send.d.ts +32 -0
- package/dist/chat/mixins/composer-send.js +121 -0
- package/dist/chat/mixins/reveal-stream.d.ts +68 -0
- package/dist/chat/mixins/reveal-stream.js +184 -0
- package/dist/chat/mixins/stream-target.d.ts +18 -0
- package/dist/chat/mixins/stream-target.js +38 -0
- package/dist/components/button.js +7 -1
- package/dist/components/character-count.d.ts +44 -0
- package/dist/components/character-count.js +68 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/label-chip.d.ts +42 -0
- package/dist/components/label-chip.js +86 -0
- package/dist/components/property-list.d.ts +9 -2
- package/dist/components/property-list.js +11 -6
- package/dist/components/textarea.js +6 -1
- package/dist/components/timeline.d.ts +62 -5
- package/dist/components/timeline.js +124 -5
- package/dist/docs/code-block.js +8 -31
- package/dist/docs/file-tree.js +3 -48
- package/dist/landing/case-study.d.ts +79 -0
- package/dist/landing/case-study.js +162 -0
- package/dist/landing/contributor-wall.d.ts +72 -0
- package/dist/landing/contributor-wall.js +129 -0
- package/dist/landing/countdown.d.ts +88 -0
- package/dist/landing/countdown.js +91 -0
- package/dist/landing/episode-player.d.ts +87 -0
- package/dist/landing/episode-player.js +113 -0
- package/dist/landing/faq-band.d.ts +3 -2
- package/dist/landing/faq-band.js +4 -3
- package/dist/landing/index.d.ts +7 -0
- package/dist/landing/index.js +7 -0
- package/dist/landing/landing-header.js +15 -4
- package/dist/landing/mixins/countdown-tick.d.ts +29 -0
- package/dist/landing/mixins/countdown-tick.js +65 -0
- package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
- package/dist/landing/mixins/usage-estimate-live.js +120 -0
- package/dist/landing/phone-frame.d.ts +2 -1
- package/dist/landing/price-list.d.ts +68 -0
- package/dist/landing/price-list.js +125 -0
- package/dist/landing/scroll-scene.d.ts +59 -0
- package/dist/landing/scroll-scene.js +70 -0
- package/dist/landing/sponsor-wall.d.ts +30 -6
- package/dist/landing/sponsor-wall.js +70 -14
- package/dist/landing/typed-terminal.d.ts +24 -6
- package/dist/landing/typed-terminal.js +22 -14
- package/dist/landing/usage-estimate.d.ts +127 -0
- package/dist/landing/usage-estimate.js +164 -0
- package/dist/landing/utils/countdown.d.ts +33 -0
- package/dist/landing/utils/countdown.js +42 -0
- package/dist/landing/utils/pause-toggle.d.ts +2 -1
- package/dist/mixins/character-count.d.ts +62 -0
- package/dist/mixins/character-count.js +139 -0
- package/dist/mixins/index.d.ts +6 -2
- package/dist/mixins/index.js +6 -2
- package/dist/mixins/invoker-fields.d.ts +18 -0
- package/dist/mixins/invoker-fields.js +60 -0
- package/dist/mixins/media-sync.d.ts +58 -0
- package/dist/mixins/media-sync.js +102 -0
- package/dist/mixins/menu-keys.d.ts +11 -0
- package/dist/mixins/menu-keys.js +79 -70
- package/dist/mixins/sortable.d.ts +96 -0
- package/dist/mixins/sortable.js +433 -0
- package/dist/utils/code-lines.d.ts +26 -0
- package/dist/utils/code-lines.js +29 -0
- package/dist/utils/file-icon.d.ts +31 -0
- package/dist/utils/file-icon.js +60 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/write-cookie.d.ts +15 -15
- package/dist/utils/write-cookie.js +10 -16
- package/dist/video/index.d.ts +11 -0
- package/dist/video/index.js +11 -0
- package/dist/video/mixins/video-player-sync.d.ts +27 -0
- package/dist/video/mixins/video-player-sync.js +413 -0
- package/dist/video/utils/timeline.d.ts +55 -0
- package/dist/video/utils/timeline.js +90 -0
- package/dist/video/video-player.d.ts +261 -0
- package/dist/video/video-player.js +927 -0
- package/package.json +6 -3
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: seeking in place, marking what plays, and a custom control bar all need the media
|
|
3
|
+
* element's API. No-JS baseline: every time is a `#t=` link into the file, and the video
|
|
4
|
+
* keeps the browser's own controls; this mixin swaps them for the bar when it runs.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createMixin } from "remix/component";
|
|
10
|
+
import { installMediaSync, markPlaying } from "../../mixins/media-sync.js";
|
|
11
|
+
import { installMenuKeys } from "../../mixins/menu-keys.js";
|
|
12
|
+
import { formatVideoTime, playedShare } from "../utils/timeline.js";
|
|
13
|
+
/** Items the top level of a settings menu walks: its rows, and none inside a submenu. */
|
|
14
|
+
const MENU_ITEMS = '[data-video-item]:not([data-slot="video-player-submenu-panel"] *)';
|
|
15
|
+
/** The playing-order lists a video player marks: its chapter links and transcript lines. */
|
|
16
|
+
const MARKS = ['[data-slot="video-player-chapters"] a', '[data-slot="video-player-cue"]'];
|
|
17
|
+
/**
|
|
18
|
+
* Fills each scrubber segment to its played share at `time`, and scrolls a newly current
|
|
19
|
+
* transcript line into view inside the transcript alone.
|
|
20
|
+
*/
|
|
21
|
+
function paintTimeline(root, time, changed) {
|
|
22
|
+
for (let bar of root.querySelectorAll('[data-slot="video-player-segment"]')) {
|
|
23
|
+
let share = playedShare(Number(bar.dataset.start), Number(bar.dataset.end), time);
|
|
24
|
+
bar.style.setProperty("--ui-video-player-played", `${share * 100}%`);
|
|
25
|
+
}
|
|
26
|
+
let line = changed.find((item) => item.dataset.slot === "video-player-cue");
|
|
27
|
+
let region = root.querySelector('[data-slot="video-player-transcript"]');
|
|
28
|
+
if (line && region)
|
|
29
|
+
region.scrollTop = line.offsetTop - region.clientHeight / 3;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Brings a player's marks to `time`: the chapter link and transcript line playing then
|
|
33
|
+
* carry `aria-current`, each scrubber segment fills to its played share, and a newly
|
|
34
|
+
* current line scrolls into view inside the transcript alone.
|
|
35
|
+
*
|
|
36
|
+
* @param root The player's `<figure>`.
|
|
37
|
+
* @param time The video's current time in seconds.
|
|
38
|
+
*/
|
|
39
|
+
export function syncVideo(root, time) {
|
|
40
|
+
let changed = MARKS.map((selector) => markPlaying(root.querySelectorAll(selector), time)).filter((item) => item !== undefined);
|
|
41
|
+
paintTimeline(root, time, changed);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The text tracks the captions controls choose between, in document order; a captions
|
|
45
|
+
* track written from an empty transcript is left out.
|
|
46
|
+
*/
|
|
47
|
+
function captionTracks(video) {
|
|
48
|
+
return [...video.querySelectorAll("track")]
|
|
49
|
+
.filter((track) => track.kind === "captions" || track.kind === "subtitles")
|
|
50
|
+
.filter((track) => !track.hasAttribute("data-empty"))
|
|
51
|
+
.map((track) => track.track);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mirrors a menu input's checked state into `aria-checked`, which its menu item role
|
|
55
|
+
* requires; a radio updates every radio of its name.
|
|
56
|
+
*/
|
|
57
|
+
function syncChecked(input) {
|
|
58
|
+
let group = input.type === "radio"
|
|
59
|
+
? input.closest('[role="menu"]')?.querySelectorAll("input[type=radio]")
|
|
60
|
+
: undefined;
|
|
61
|
+
for (let item of group ?? [input])
|
|
62
|
+
item.setAttribute("aria-checked", String(item.checked));
|
|
63
|
+
}
|
|
64
|
+
/** Length of the video: the file's once known, else the timeline's the page declared. */
|
|
65
|
+
function lengthOf(video, progress) {
|
|
66
|
+
if (Number.isFinite(video.duration) && video.duration > 0)
|
|
67
|
+
return video.duration;
|
|
68
|
+
return Number(progress?.max ?? 0);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Wires one player's custom bar, with every handler ending when `signal` aborts: the bar
|
|
72
|
+
* replaces the native controls, buttons drive the video, built-in menu rows set speed,
|
|
73
|
+
* quality and captions, and the settings menu walks its panels by keyboard.
|
|
74
|
+
*/
|
|
75
|
+
class VideoControls {
|
|
76
|
+
root;
|
|
77
|
+
video;
|
|
78
|
+
signal;
|
|
79
|
+
/** The captions track the toggle turns back on, which the last choice decides. */
|
|
80
|
+
lastCaptions = 0;
|
|
81
|
+
constructor(root, video, signal) {
|
|
82
|
+
this.root = root;
|
|
83
|
+
this.video = video;
|
|
84
|
+
this.signal = signal;
|
|
85
|
+
}
|
|
86
|
+
/** Every control of `name` in the player. */
|
|
87
|
+
all(selector) {
|
|
88
|
+
return [...this.root.querySelectorAll(selector)];
|
|
89
|
+
}
|
|
90
|
+
/** Hides the native controls, reveals the bar, and restores both when the signal aborts. */
|
|
91
|
+
install(bar) {
|
|
92
|
+
let { root, signal, video } = this;
|
|
93
|
+
video.controls = false;
|
|
94
|
+
bar.hidden = false;
|
|
95
|
+
signal.addEventListener("abort", () => {
|
|
96
|
+
video.controls = true;
|
|
97
|
+
bar.hidden = true;
|
|
98
|
+
});
|
|
99
|
+
if (!document.fullscreenEnabled) {
|
|
100
|
+
for (let button of this.all('[data-video-action="fullscreen"]'))
|
|
101
|
+
button.hidden = true;
|
|
102
|
+
}
|
|
103
|
+
root.addEventListener("click", (event) => this.onClick(event), { signal });
|
|
104
|
+
root.addEventListener("change", (event) => this.onChange(event), { signal });
|
|
105
|
+
root.addEventListener("input", (event) => this.onInput(event), { signal });
|
|
106
|
+
root.addEventListener("keydown", (event) => this.onKeydown(event), { signal });
|
|
107
|
+
for (let type of ["play", "pause", "ended", "timeupdate", "durationchange", "ratechange"]) {
|
|
108
|
+
video.addEventListener(type, () => this.render(), { signal });
|
|
109
|
+
}
|
|
110
|
+
document.addEventListener("fullscreenchange", () => this.render(), { signal });
|
|
111
|
+
for (let menu of this.all('[data-slot="video-player-settings"]'))
|
|
112
|
+
this.installMenu(menu);
|
|
113
|
+
this.showCaptions(this.checkedCaptions());
|
|
114
|
+
this.render();
|
|
115
|
+
}
|
|
116
|
+
/** Runs the menu keyboard on each panel, and opens the menu on its top level. */
|
|
117
|
+
installMenu(menu) {
|
|
118
|
+
let { signal } = this;
|
|
119
|
+
let main = menu.querySelector('[data-slot="video-player-menu"]');
|
|
120
|
+
if (main)
|
|
121
|
+
installMenuKeys(main, signal, { itemSelector: MENU_ITEMS });
|
|
122
|
+
for (let panel of menu.querySelectorAll('[data-slot="video-player-submenu-panel"]')) {
|
|
123
|
+
installMenuKeys(panel, signal, { itemSelector: "[data-video-item]" });
|
|
124
|
+
}
|
|
125
|
+
menu.addEventListener("toggle", (event) => {
|
|
126
|
+
if (event.newState !== "open")
|
|
127
|
+
return;
|
|
128
|
+
this.closePanels(menu);
|
|
129
|
+
main?.querySelector(MENU_ITEMS)?.focus();
|
|
130
|
+
}, { signal });
|
|
131
|
+
}
|
|
132
|
+
/** Brings every control's state to the video's: playing, time, progress, captions, screen. */
|
|
133
|
+
render() {
|
|
134
|
+
let { root, video } = this;
|
|
135
|
+
let playing = !video.paused && !video.ended;
|
|
136
|
+
root.toggleAttribute("data-playing", playing);
|
|
137
|
+
for (let button of this.all('[data-video-action="play"]')) {
|
|
138
|
+
let label = playing ? button.dataset.labelPause : button.dataset.labelPlay;
|
|
139
|
+
if (label)
|
|
140
|
+
button.setAttribute("aria-label", label);
|
|
141
|
+
}
|
|
142
|
+
let progress = root.querySelector('[data-slot="video-player-progress"]');
|
|
143
|
+
let length = lengthOf(video, progress);
|
|
144
|
+
for (let elapsed of this.all('[data-slot="video-player-elapsed"]')) {
|
|
145
|
+
elapsed.textContent = formatVideoTime(video.currentTime);
|
|
146
|
+
}
|
|
147
|
+
for (let total of this.all('[data-slot="video-player-length"]')) {
|
|
148
|
+
total.textContent = formatVideoTime(length);
|
|
149
|
+
}
|
|
150
|
+
for (let input of this.all('[data-slot="video-player-progress"]')) {
|
|
151
|
+
input.max = String(length);
|
|
152
|
+
input.value = String(video.currentTime);
|
|
153
|
+
input.setAttribute("aria-valuetext", `${formatVideoTime(video.currentTime)} / ${formatVideoTime(length)}`);
|
|
154
|
+
input.style.setProperty("--ui-video-player-progress", `${length > 0 ? (video.currentTime / length) * 100 : 0}%`);
|
|
155
|
+
}
|
|
156
|
+
let screen = root.querySelector('[data-slot="video-player-screen"]');
|
|
157
|
+
let fullscreen = screen !== null && document.fullscreenElement === screen;
|
|
158
|
+
for (let button of this.all('[data-video-action="fullscreen"]')) {
|
|
159
|
+
button.setAttribute("aria-pressed", String(fullscreen));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Runs a bar button, seeks from a time link, or plays and pauses from the picture. */
|
|
163
|
+
onClick(event) {
|
|
164
|
+
let target = event.target;
|
|
165
|
+
let button = target?.closest("[data-video-action]");
|
|
166
|
+
if (button) {
|
|
167
|
+
this.act(button);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (target instanceof HTMLVideoElement && target === this.video)
|
|
171
|
+
this.togglePlay();
|
|
172
|
+
}
|
|
173
|
+
/** What one bar button does. */
|
|
174
|
+
act(button) {
|
|
175
|
+
let { root } = this;
|
|
176
|
+
switch (button.dataset.videoAction) {
|
|
177
|
+
case "play":
|
|
178
|
+
this.togglePlay();
|
|
179
|
+
return;
|
|
180
|
+
case "captions": {
|
|
181
|
+
let showing = captionTracks(this.video).some((track) => track.mode === "showing");
|
|
182
|
+
this.showCaptions(showing ? -1 : this.lastCaptions);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
case "theater": {
|
|
186
|
+
let on = !root.hasAttribute("data-theater");
|
|
187
|
+
root.toggleAttribute("data-theater", on);
|
|
188
|
+
button.setAttribute("aria-pressed", String(on));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
case "fullscreen":
|
|
192
|
+
void this.toggleFullscreen();
|
|
193
|
+
return;
|
|
194
|
+
case "open":
|
|
195
|
+
this.openPanel(button);
|
|
196
|
+
return;
|
|
197
|
+
case "back":
|
|
198
|
+
this.closePanel(button.closest('[data-slot="video-player-submenu-panel"]'));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/** Plays a paused video and pauses a playing one. */
|
|
202
|
+
togglePlay() {
|
|
203
|
+
let { video } = this;
|
|
204
|
+
if (video.paused || video.ended)
|
|
205
|
+
void video.play().catch(() => undefined);
|
|
206
|
+
else
|
|
207
|
+
video.pause();
|
|
208
|
+
}
|
|
209
|
+
/** Puts the player's screen, bar included, in full screen, or takes it out. */
|
|
210
|
+
async toggleFullscreen() {
|
|
211
|
+
let screen = this.root.querySelector('[data-slot="video-player-screen"]');
|
|
212
|
+
if (!screen)
|
|
213
|
+
return;
|
|
214
|
+
if (document.fullscreenElement === screen)
|
|
215
|
+
await document.exitFullscreen();
|
|
216
|
+
else
|
|
217
|
+
await screen.requestFullscreen().catch(() => undefined);
|
|
218
|
+
}
|
|
219
|
+
/** Seeks as the progress slider moves. */
|
|
220
|
+
onInput(event) {
|
|
221
|
+
let input = event.target;
|
|
222
|
+
if (!(input instanceof HTMLInputElement))
|
|
223
|
+
return;
|
|
224
|
+
if (input.dataset.slot !== "video-player-progress")
|
|
225
|
+
return;
|
|
226
|
+
this.video.currentTime = Number(input.value);
|
|
227
|
+
syncVideo(this.root, this.video.currentTime);
|
|
228
|
+
this.render();
|
|
229
|
+
}
|
|
230
|
+
/** Applies a built-in setting, names the choice on its row and returns to the top level. */
|
|
231
|
+
onChange(event) {
|
|
232
|
+
let input = event.target;
|
|
233
|
+
if (!(input instanceof HTMLInputElement) || !input.hasAttribute("data-video-item"))
|
|
234
|
+
return;
|
|
235
|
+
syncChecked(input);
|
|
236
|
+
if (input.type !== "radio")
|
|
237
|
+
return;
|
|
238
|
+
let panel = input.closest('[data-slot="video-player-submenu-panel"]');
|
|
239
|
+
if (!panel)
|
|
240
|
+
return;
|
|
241
|
+
switch (panel.dataset.videoSetting) {
|
|
242
|
+
case "rate":
|
|
243
|
+
this.video.playbackRate = Number(input.value);
|
|
244
|
+
this.video.defaultPlaybackRate = Number(input.value);
|
|
245
|
+
break;
|
|
246
|
+
case "quality":
|
|
247
|
+
this.swapSource(Number(input.value));
|
|
248
|
+
break;
|
|
249
|
+
case "captions":
|
|
250
|
+
this.showCaptions(Number(input.value));
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
this.nameChoice(panel, input);
|
|
254
|
+
this.closePanel(panel);
|
|
255
|
+
}
|
|
256
|
+
/** Copies the checked option's label onto the row that opens its submenu. */
|
|
257
|
+
nameChoice(panel, input) {
|
|
258
|
+
let label = input
|
|
259
|
+
.closest("label")
|
|
260
|
+
?.querySelector('[data-slot="video-player-option-label"]')?.textContent;
|
|
261
|
+
let value = this.root
|
|
262
|
+
.querySelector(`[aria-controls="${panel.id}"]`)
|
|
263
|
+
?.querySelector('[data-slot="video-player-row-value"]');
|
|
264
|
+
if (value && label !== undefined && label !== null)
|
|
265
|
+
value.textContent = label;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The menu keys the shared pattern leaves to the surface: → opens a submenu, ← returns from
|
|
269
|
+
* one, and Enter flips a checkbox or picks a radio the way Space does.
|
|
270
|
+
*/
|
|
271
|
+
onKeydown(event) {
|
|
272
|
+
let target = event.target;
|
|
273
|
+
if (!target?.closest('[data-slot="video-player-settings"]'))
|
|
274
|
+
return;
|
|
275
|
+
let panel = target.closest('[data-slot="video-player-submenu-panel"]');
|
|
276
|
+
if (event.key === "ArrowRight" && target.dataset.videoAction === "open") {
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
this.openPanel(target);
|
|
279
|
+
}
|
|
280
|
+
else if (event.key === "ArrowLeft" && panel) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
this.closePanel(panel);
|
|
283
|
+
}
|
|
284
|
+
else if (event.key === "ArrowRight" && panel) {
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
}
|
|
287
|
+
else if (event.key === "Enter" && target instanceof HTMLInputElement) {
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
target.click();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** Shows the submenu a row opens in place of the top level, focusing its checked option. */
|
|
293
|
+
openPanel(trigger) {
|
|
294
|
+
let id = trigger.getAttribute("aria-controls");
|
|
295
|
+
let panel = id ? document.getElementById(id) : null;
|
|
296
|
+
let main = trigger.closest('[data-slot="video-player-menu"]');
|
|
297
|
+
if (!panel || !main)
|
|
298
|
+
return;
|
|
299
|
+
main.setAttribute("data-submenu", "");
|
|
300
|
+
panel.hidden = false;
|
|
301
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
302
|
+
let checked = panel.querySelector("[data-video-item]:checked");
|
|
303
|
+
(checked ?? panel.querySelector("[data-video-item]"))?.focus();
|
|
304
|
+
}
|
|
305
|
+
/** Returns from a submenu to the top level, focusing the row that opened it. */
|
|
306
|
+
closePanel(panel) {
|
|
307
|
+
if (!panel || panel.hidden)
|
|
308
|
+
return;
|
|
309
|
+
panel.hidden = true;
|
|
310
|
+
let trigger = this.root.querySelector(`[aria-controls="${panel.id}"]`);
|
|
311
|
+
trigger?.setAttribute("aria-expanded", "false");
|
|
312
|
+
trigger?.closest('[data-slot="video-player-menu"]')?.removeAttribute("data-submenu");
|
|
313
|
+
trigger?.focus();
|
|
314
|
+
}
|
|
315
|
+
/** Puts a menu back on its top level, as it opens. */
|
|
316
|
+
closePanels(menu) {
|
|
317
|
+
for (let panel of menu.querySelectorAll('[data-slot="video-player-submenu-panel"]')) {
|
|
318
|
+
panel.hidden = true;
|
|
319
|
+
}
|
|
320
|
+
for (let trigger of menu.querySelectorAll('[data-video-action="open"]')) {
|
|
321
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
322
|
+
}
|
|
323
|
+
menu.querySelector('[data-slot="video-player-menu"]')?.removeAttribute("data-submenu");
|
|
324
|
+
}
|
|
325
|
+
/** The captions option the server rendered checked, `-1` for off. */
|
|
326
|
+
checkedCaptions() {
|
|
327
|
+
let checked = this.root.querySelector('[data-video-setting="captions"] input:checked');
|
|
328
|
+
return checked ? Number(checked.value) : -1;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Shows the captions track at `index` and hides the rest, `-1` hiding them all; the toggle,
|
|
332
|
+
* the captions menu and its row follow.
|
|
333
|
+
*/
|
|
334
|
+
showCaptions(index) {
|
|
335
|
+
let tracks = captionTracks(this.video);
|
|
336
|
+
for (let [position, track] of tracks.entries()) {
|
|
337
|
+
track.mode = position === index ? "showing" : "disabled";
|
|
338
|
+
}
|
|
339
|
+
if (index >= 0)
|
|
340
|
+
this.lastCaptions = index;
|
|
341
|
+
let on = index >= 0 && index < tracks.length;
|
|
342
|
+
for (let button of this.all('[data-video-action="captions"]')) {
|
|
343
|
+
button.setAttribute("aria-pressed", String(on));
|
|
344
|
+
}
|
|
345
|
+
for (let panel of this.all('[data-video-setting="captions"]')) {
|
|
346
|
+
let input = panel.querySelector(`input[value="${on ? index : -1}"]`);
|
|
347
|
+
if (!input)
|
|
348
|
+
continue;
|
|
349
|
+
input.checked = true;
|
|
350
|
+
syncChecked(input);
|
|
351
|
+
this.nameChoice(panel, input);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Plays the source at `index` from the moment the current one reached, keeping its speed and
|
|
356
|
+
* whether it was playing; the settings badges follow the new source's badge.
|
|
357
|
+
*/
|
|
358
|
+
swapSource(index) {
|
|
359
|
+
let { signal, video } = this;
|
|
360
|
+
let source = video.querySelectorAll("source")[index];
|
|
361
|
+
if (!source)
|
|
362
|
+
return;
|
|
363
|
+
let time = video.currentTime;
|
|
364
|
+
let playing = !video.paused;
|
|
365
|
+
video.addEventListener("loadedmetadata", () => {
|
|
366
|
+
video.currentTime = time;
|
|
367
|
+
if (playing)
|
|
368
|
+
void video.play().catch(() => undefined);
|
|
369
|
+
}, { once: true, signal });
|
|
370
|
+
video.src = source.src;
|
|
371
|
+
for (let badge of this.all('[data-slot="video-player-badge"][data-follows-quality]')) {
|
|
372
|
+
badge.textContent = source.dataset.badge ?? "";
|
|
373
|
+
badge.hidden = !source.dataset.badge;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Wires one player until `signal` aborts: time links seek in place, the marks follow the
|
|
379
|
+
* video, and a control bar, when the player has one, replaces the native controls.
|
|
380
|
+
*/
|
|
381
|
+
function wirePlayer(root, video, signal) {
|
|
382
|
+
installMediaSync(root, video, signal, {
|
|
383
|
+
marks: MARKS,
|
|
384
|
+
onTime: (time, changed) => paintTimeline(root, time, changed),
|
|
385
|
+
});
|
|
386
|
+
let bar = root.querySelector('[data-slot="video-player-controls"]');
|
|
387
|
+
if (bar)
|
|
388
|
+
new VideoControls(root, video, signal).install(bar);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Keeps a video player's links, marks, bar and video in step from a node inside its
|
|
392
|
+
* `[data-slot="video-player"]` root. A plain click on a time link seeks and plays; a
|
|
393
|
+
* modified click still opens the file itself.
|
|
394
|
+
*
|
|
395
|
+
* @returns A mixin descriptor for any element inside the player.
|
|
396
|
+
* @example <span hidden mix={[videoPlayerSync()]} />
|
|
397
|
+
*/
|
|
398
|
+
export const videoPlayerSync = createMixin((handle) => {
|
|
399
|
+
let controller;
|
|
400
|
+
handle.addEventListener("insert", (event) => {
|
|
401
|
+
controller?.abort();
|
|
402
|
+
let root = event.node.closest('[data-slot="video-player"]');
|
|
403
|
+
let video = root?.querySelector("video");
|
|
404
|
+
if (!root || !video)
|
|
405
|
+
return;
|
|
406
|
+
controller = new AbortController();
|
|
407
|
+
wirePlayer(root, video, controller.signal);
|
|
408
|
+
});
|
|
409
|
+
handle.addEventListener("remove", () => {
|
|
410
|
+
controller?.abort();
|
|
411
|
+
controller = undefined;
|
|
412
|
+
});
|
|
413
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time arithmetic for a video's timeline: readings as a player prints them, WebVTT files
|
|
3
|
+
* written from timed lines, and which entry of a playing-order list a moment falls in. The
|
|
4
|
+
* server render and the island share it, so both mark the same chapter and line.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** How far, in seconds, a moment may run ahead of a start and still count as reaching it. */
|
|
10
|
+
export declare const SEEK_SLACK = 0.25;
|
|
11
|
+
/**
|
|
12
|
+
* Writes seconds as a player prints them: `m:ss` under an hour and `h:mm:ss` from one.
|
|
13
|
+
*
|
|
14
|
+
* @param seconds Whole or fractional seconds; fractions are dropped.
|
|
15
|
+
* @returns The reading, such as `6:58`.
|
|
16
|
+
* @example formatVideoTime(418.9); // "6:58"
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatVideoTime(seconds: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* The same moment as an ISO 8601 duration, for a `<time dateTime>` attribute.
|
|
21
|
+
*
|
|
22
|
+
* @param seconds Whole or fractional seconds; fractions are dropped.
|
|
23
|
+
* @returns The duration, such as `PT6M58S`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isoDuration(seconds: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Writes timed lines as a WebVTT file in a `data:` URL, each line ending where the next
|
|
28
|
+
* starts and the last at `duration`, so a `<track>` needs no file of its own.
|
|
29
|
+
*
|
|
30
|
+
* @param lines Start times and texts, in playing order.
|
|
31
|
+
* @param duration Length of the video in seconds.
|
|
32
|
+
* @returns A `data:text/vtt` URL.
|
|
33
|
+
* @example <track kind="chapters" src={webVttUrl([{ start: 0, text: "Intro" }], 90)} />
|
|
34
|
+
*/
|
|
35
|
+
export declare function webVttUrl(lines: readonly {
|
|
36
|
+
start: number;
|
|
37
|
+
text: string;
|
|
38
|
+
}[], duration: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Index of the last start at or before `time`, or -1 before the first.
|
|
41
|
+
*
|
|
42
|
+
* @param starts Start times in playing order.
|
|
43
|
+
* @param time The moment asked about, in seconds; `undefined` matches nothing.
|
|
44
|
+
* @returns The index of the entry playing at `time`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function playingIndex(starts: readonly number[], time: number | undefined): number;
|
|
47
|
+
/**
|
|
48
|
+
* Share of a chapter played at `time`, from 0 to 1.
|
|
49
|
+
*
|
|
50
|
+
* @param start The chapter's start in seconds.
|
|
51
|
+
* @param end The chapter's end in seconds.
|
|
52
|
+
* @param time The moment asked about, or `undefined` for none.
|
|
53
|
+
* @returns How much of the chapter lies before `time`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function playedShare(start: number, end: number, time: number | undefined): number;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time arithmetic for a video's timeline: readings as a player prints them, WebVTT files
|
|
3
|
+
* written from timed lines, and which entry of a playing-order list a moment falls in. The
|
|
4
|
+
* server render and the island share it, so both mark the same chapter and line.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** How far, in seconds, a moment may run ahead of a start and still count as reaching it. */
|
|
10
|
+
export const SEEK_SLACK = 0.25;
|
|
11
|
+
/**
|
|
12
|
+
* Writes seconds as a player prints them: `m:ss` under an hour and `h:mm:ss` from one.
|
|
13
|
+
*
|
|
14
|
+
* @param seconds Whole or fractional seconds; fractions are dropped.
|
|
15
|
+
* @returns The reading, such as `6:58`.
|
|
16
|
+
* @example formatVideoTime(418.9); // "6:58"
|
|
17
|
+
*/
|
|
18
|
+
export function formatVideoTime(seconds) {
|
|
19
|
+
let total = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
|
|
20
|
+
let hours = Math.floor(total / 3600);
|
|
21
|
+
let minutes = Math.floor((total % 3600) / 60);
|
|
22
|
+
let rest = String(total % 60).padStart(2, "0");
|
|
23
|
+
if (hours > 0)
|
|
24
|
+
return `${hours}:${String(minutes).padStart(2, "0")}:${rest}`;
|
|
25
|
+
return `${minutes}:${rest}`;
|
|
26
|
+
}
|
|
27
|
+
/** Seconds as a WebVTT timestamp, `hh:mm:ss.mmm`. */
|
|
28
|
+
function vttTime(seconds) {
|
|
29
|
+
let millis = Math.round(Math.max(0, seconds) * 1000);
|
|
30
|
+
let hours = String(Math.floor(millis / 3_600_000)).padStart(2, "0");
|
|
31
|
+
let minutes = String(Math.floor((millis % 3_600_000) / 60_000)).padStart(2, "0");
|
|
32
|
+
let secs = String(Math.floor((millis % 60_000) / 1000)).padStart(2, "0");
|
|
33
|
+
return `${hours}:${minutes}:${secs}.${String(millis % 1000).padStart(3, "0")}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The same moment as an ISO 8601 duration, for a `<time dateTime>` attribute.
|
|
37
|
+
*
|
|
38
|
+
* @param seconds Whole or fractional seconds; fractions are dropped.
|
|
39
|
+
* @returns The duration, such as `PT6M58S`.
|
|
40
|
+
*/
|
|
41
|
+
export function isoDuration(seconds) {
|
|
42
|
+
let total = Math.max(0, Math.floor(seconds));
|
|
43
|
+
return `PT${Math.floor(total / 60)}M${total % 60}S`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Writes timed lines as a WebVTT file in a `data:` URL, each line ending where the next
|
|
47
|
+
* starts and the last at `duration`, so a `<track>` needs no file of its own.
|
|
48
|
+
*
|
|
49
|
+
* @param lines Start times and texts, in playing order.
|
|
50
|
+
* @param duration Length of the video in seconds.
|
|
51
|
+
* @returns A `data:text/vtt` URL.
|
|
52
|
+
* @example <track kind="chapters" src={webVttUrl([{ start: 0, text: "Intro" }], 90)} />
|
|
53
|
+
*/
|
|
54
|
+
export function webVttUrl(lines, duration) {
|
|
55
|
+
let cues = lines.map((line, index) => {
|
|
56
|
+
let end = lines[index + 1]?.start ?? duration;
|
|
57
|
+
let text = line.text.replaceAll("-->", "→").replaceAll(/\n{2,}/g, "\n");
|
|
58
|
+
return `${index + 1}\n${vttTime(line.start)} --> ${vttTime(end)}\n${text}`;
|
|
59
|
+
});
|
|
60
|
+
return `data:text/vtt;charset=utf-8,${encodeURIComponent(`${["WEBVTT", ...cues].join("\n\n")}\n`)}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Index of the last start at or before `time`, or -1 before the first.
|
|
64
|
+
*
|
|
65
|
+
* @param starts Start times in playing order.
|
|
66
|
+
* @param time The moment asked about, in seconds; `undefined` matches nothing.
|
|
67
|
+
* @returns The index of the entry playing at `time`.
|
|
68
|
+
*/
|
|
69
|
+
export function playingIndex(starts, time) {
|
|
70
|
+
if (time === undefined)
|
|
71
|
+
return -1;
|
|
72
|
+
let found = -1;
|
|
73
|
+
for (let [index, start] of starts.entries())
|
|
74
|
+
if (start <= time + SEEK_SLACK)
|
|
75
|
+
found = index;
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Share of a chapter played at `time`, from 0 to 1.
|
|
80
|
+
*
|
|
81
|
+
* @param start The chapter's start in seconds.
|
|
82
|
+
* @param end The chapter's end in seconds.
|
|
83
|
+
* @param time The moment asked about, or `undefined` for none.
|
|
84
|
+
* @returns How much of the chapter lies before `time`.
|
|
85
|
+
*/
|
|
86
|
+
export function playedShare(start, end, time) {
|
|
87
|
+
if (time === undefined || end <= start)
|
|
88
|
+
return 0;
|
|
89
|
+
return Math.min(1, Math.max(0, (time - start) / (end - start)));
|
|
90
|
+
}
|