@sdxc/ui 2026.11.10 → 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.
Files changed (196) hide show
  1. package/README.md +92 -45
  2. package/dist/app/app-shell-toggle.d.ts +2 -0
  3. package/dist/app/app-shell-toggle.js +5 -2
  4. package/dist/app/app-shell.d.ts +25 -1
  5. package/dist/app/app-shell.js +73 -38
  6. package/dist/app/auto-refresh.d.ts +2 -0
  7. package/dist/app/auto-refresh.js +3 -3
  8. package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
  9. package/dist/app/behaviors/refresh-schedule.js +4 -3
  10. package/dist/app/board.d.ts +123 -0
  11. package/dist/app/board.js +224 -0
  12. package/dist/app/chart.d.ts +2 -2
  13. package/dist/app/chart.js +7 -3
  14. package/dist/app/check-runs.d.ts +116 -0
  15. package/dist/app/check-runs.js +201 -0
  16. package/dist/app/code-view.d.ts +172 -0
  17. package/dist/app/code-view.js +414 -0
  18. package/dist/app/command-palette.d.ts +38 -3
  19. package/dist/app/command-palette.js +53 -5
  20. package/dist/app/contribution-graph.d.ts +106 -0
  21. package/dist/app/contribution-graph.js +289 -0
  22. package/dist/app/detail-sheet.d.ts +7 -0
  23. package/dist/app/detail-sheet.js +7 -7
  24. package/dist/app/diff.d.ts +200 -0
  25. package/dist/app/diff.js +702 -0
  26. package/dist/app/filter-bar.d.ts +20 -0
  27. package/dist/app/filter-bar.js +35 -15
  28. package/dist/app/filter-menu.d.ts +144 -0
  29. package/dist/app/filter-menu.js +480 -0
  30. package/dist/app/gantt.d.ts +108 -0
  31. package/dist/app/gantt.js +420 -0
  32. package/dist/app/index.d.ts +19 -0
  33. package/dist/app/index.js +19 -0
  34. package/dist/app/log-viewer.d.ts +120 -0
  35. package/dist/app/log-viewer.js +384 -0
  36. package/dist/app/merge-box.d.ts +97 -0
  37. package/dist/app/merge-box.js +227 -0
  38. package/dist/app/mixins/app-shell-controls.d.ts +4 -1
  39. package/dist/app/mixins/app-shell-controls.js +64 -4
  40. package/dist/app/mixins/auto-refresh.d.ts +5 -2
  41. package/dist/app/mixins/auto-refresh.js +9 -3
  42. package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
  43. package/dist/app/mixins/close-popover-on-submit.js +32 -0
  44. package/dist/app/mixins/code-view-selection.d.ts +60 -0
  45. package/dist/app/mixins/code-view-selection.js +276 -0
  46. package/dist/app/mixins/command-palette.d.ts +15 -4
  47. package/dist/app/mixins/command-palette.js +94 -6
  48. package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
  49. package/dist/app/mixins/contribution-graph-keys.js +155 -0
  50. package/dist/app/mixins/diff-interactions.d.ts +72 -0
  51. package/dist/app/mixins/diff-interactions.js +269 -0
  52. package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
  53. package/dist/app/mixins/filter-menu-keys.js +91 -0
  54. package/dist/app/mixins/gantt-today.d.ts +17 -0
  55. package/dist/app/mixins/gantt-today.js +50 -0
  56. package/dist/app/mixins/log-viewer.d.ts +29 -0
  57. package/dist/app/mixins/log-viewer.js +333 -0
  58. package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
  59. package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
  60. package/dist/app/mixins/save-bar-sync.d.ts +7 -1
  61. package/dist/app/mixins/save-bar-sync.js +23 -4
  62. package/dist/app/mixins/save-status-sync.js +23 -1
  63. package/dist/app/mixins/split-view.js +1 -1
  64. package/dist/app/mixins/submit-on-close.d.ts +17 -0
  65. package/dist/app/mixins/submit-on-close.js +52 -0
  66. package/dist/app/mixins/tree-filter.d.ts +44 -0
  67. package/dist/app/mixins/tree-filter.js +111 -0
  68. package/dist/app/mixins/tree-navigation.d.ts +50 -0
  69. package/dist/app/mixins/tree-navigation.js +216 -0
  70. package/dist/app/optimistic-toggle.d.ts +8 -0
  71. package/dist/app/optimistic-toggle.js +3 -2
  72. package/dist/app/page-header.d.ts +18 -3
  73. package/dist/app/page-header.js +105 -50
  74. package/dist/app/review-thread.d.ts +115 -0
  75. package/dist/app/review-thread.js +116 -0
  76. package/dist/app/save-bar.d.ts +5 -0
  77. package/dist/app/save-bar.js +1 -1
  78. package/dist/app/settings-layout.d.ts +5 -0
  79. package/dist/app/settings-layout.js +5 -5
  80. package/dist/app/skeleton.d.ts +9 -0
  81. package/dist/app/skeleton.js +28 -0
  82. package/dist/app/split-view.d.ts +4 -0
  83. package/dist/app/split-view.js +3 -3
  84. package/dist/app/styles/code-tokens.d.ts +24 -0
  85. package/dist/app/styles/code-tokens.js +47 -0
  86. package/dist/app/tab-bar.d.ts +59 -0
  87. package/dist/app/tab-bar.js +111 -0
  88. package/dist/app/tree.d.ts +111 -14
  89. package/dist/app/tree.js +202 -15
  90. package/dist/app/utils/ansi.d.ts +55 -0
  91. package/dist/app/utils/ansi.js +157 -0
  92. package/dist/app/utils/diff-rows.d.ts +82 -0
  93. package/dist/app/utils/diff-rows.js +209 -0
  94. package/dist/app/utils/fuzzy-path.d.ts +58 -0
  95. package/dist/app/utils/fuzzy-path.js +202 -0
  96. package/dist/app/utils/line-range.d.ts +48 -0
  97. package/dist/app/utils/line-range.js +61 -0
  98. package/dist/app/utils/log-lines.d.ts +107 -0
  99. package/dist/app/utils/log-lines.js +170 -0
  100. package/dist/app/utils/tree-filter.d.ts +19 -0
  101. package/dist/app/utils/tree-filter.js +26 -0
  102. package/dist/app/view-options.d.ts +2 -0
  103. package/dist/app/view-options.js +2 -2
  104. package/dist/chat/activity.d.ts +72 -0
  105. package/dist/chat/activity.js +184 -0
  106. package/dist/chat/composer-submit.d.ts +38 -0
  107. package/dist/chat/composer-submit.js +44 -0
  108. package/dist/chat/composer.d.ts +47 -0
  109. package/dist/chat/composer.js +100 -0
  110. package/dist/chat/index.d.ts +6 -0
  111. package/dist/chat/index.js +6 -0
  112. package/dist/chat/mixins/composer-send.d.ts +32 -0
  113. package/dist/chat/mixins/composer-send.js +121 -0
  114. package/dist/chat/mixins/reveal-stream.d.ts +68 -0
  115. package/dist/chat/mixins/reveal-stream.js +184 -0
  116. package/dist/chat/mixins/stream-target.d.ts +18 -0
  117. package/dist/chat/mixins/stream-target.js +38 -0
  118. package/dist/components/button.js +7 -1
  119. package/dist/components/character-count.d.ts +44 -0
  120. package/dist/components/character-count.js +68 -0
  121. package/dist/components/index.d.ts +2 -0
  122. package/dist/components/index.js +2 -0
  123. package/dist/components/label-chip.d.ts +42 -0
  124. package/dist/components/label-chip.js +86 -0
  125. package/dist/components/property-list.d.ts +9 -2
  126. package/dist/components/property-list.js +11 -6
  127. package/dist/components/textarea.js +6 -1
  128. package/dist/components/timeline.d.ts +62 -5
  129. package/dist/components/timeline.js +124 -5
  130. package/dist/docs/code-block.js +8 -31
  131. package/dist/docs/file-tree.js +3 -48
  132. package/dist/landing/case-study.d.ts +79 -0
  133. package/dist/landing/case-study.js +162 -0
  134. package/dist/landing/contributor-wall.d.ts +72 -0
  135. package/dist/landing/contributor-wall.js +129 -0
  136. package/dist/landing/countdown.d.ts +88 -0
  137. package/dist/landing/countdown.js +91 -0
  138. package/dist/landing/episode-player.d.ts +87 -0
  139. package/dist/landing/episode-player.js +113 -0
  140. package/dist/landing/faq-band.d.ts +3 -2
  141. package/dist/landing/faq-band.js +4 -3
  142. package/dist/landing/feature-band.d.ts +8 -0
  143. package/dist/landing/feature-band.js +9 -3
  144. package/dist/landing/index.d.ts +9 -0
  145. package/dist/landing/index.js +9 -0
  146. package/dist/landing/landing-header.js +15 -4
  147. package/dist/landing/mixins/countdown-tick.d.ts +29 -0
  148. package/dist/landing/mixins/countdown-tick.js +65 -0
  149. package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
  150. package/dist/landing/mixins/usage-estimate-live.js +120 -0
  151. package/dist/landing/phone-fan.d.ts +38 -0
  152. package/dist/landing/phone-fan.js +89 -0
  153. package/dist/landing/phone-frame.d.ts +48 -0
  154. package/dist/landing/phone-frame.js +41 -0
  155. package/dist/landing/price-list.d.ts +68 -0
  156. package/dist/landing/price-list.js +125 -0
  157. package/dist/landing/scroll-scene.d.ts +59 -0
  158. package/dist/landing/scroll-scene.js +70 -0
  159. package/dist/landing/sponsor-wall.d.ts +30 -6
  160. package/dist/landing/sponsor-wall.js +70 -14
  161. package/dist/landing/typed-terminal.d.ts +24 -6
  162. package/dist/landing/typed-terminal.js +22 -14
  163. package/dist/landing/usage-estimate.d.ts +127 -0
  164. package/dist/landing/usage-estimate.js +164 -0
  165. package/dist/landing/utils/countdown.d.ts +33 -0
  166. package/dist/landing/utils/countdown.js +42 -0
  167. package/dist/landing/utils/pause-toggle.d.ts +2 -1
  168. package/dist/mixins/character-count.d.ts +62 -0
  169. package/dist/mixins/character-count.js +139 -0
  170. package/dist/mixins/index.d.ts +6 -2
  171. package/dist/mixins/index.js +6 -2
  172. package/dist/mixins/invoker-fields.d.ts +18 -0
  173. package/dist/mixins/invoker-fields.js +60 -0
  174. package/dist/mixins/media-sync.d.ts +58 -0
  175. package/dist/mixins/media-sync.js +102 -0
  176. package/dist/mixins/menu-keys.d.ts +11 -0
  177. package/dist/mixins/menu-keys.js +79 -70
  178. package/dist/mixins/sortable.d.ts +96 -0
  179. package/dist/mixins/sortable.js +433 -0
  180. package/dist/utils/code-lines.d.ts +26 -0
  181. package/dist/utils/code-lines.js +29 -0
  182. package/dist/utils/file-icon.d.ts +31 -0
  183. package/dist/utils/file-icon.js +60 -0
  184. package/dist/utils/index.d.ts +2 -0
  185. package/dist/utils/index.js +2 -0
  186. package/dist/utils/write-cookie.d.ts +15 -15
  187. package/dist/utils/write-cookie.js +10 -16
  188. package/dist/video/index.d.ts +11 -0
  189. package/dist/video/index.js +11 -0
  190. package/dist/video/mixins/video-player-sync.d.ts +27 -0
  191. package/dist/video/mixins/video-player-sync.js +413 -0
  192. package/dist/video/utils/timeline.d.ts +55 -0
  193. package/dist/video/utils/timeline.js +90 -0
  194. package/dist/video/video-player.d.ts +261 -0
  195. package/dist/video/video-player.js +927 -0
  196. package/package.json +6 -3
@@ -15,23 +15,17 @@
15
15
  */
16
16
  export const ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
17
17
  /**
18
- * Writes `value` under `name` into a `path=/`, `samesite=lax` cookie, so the
19
- * next full navigation's server render can read it back and start already in
20
- * the same state, ahead of hydration ever running.
18
+ * Writes `value` under `name` into a `samesite=lax` cookie, so the next full navigation's server
19
+ * render can read it back and start already in the same state, ahead of hydration ever running.
21
20
  *
22
21
  * @param name Cookie name to write the value under.
23
- * @param value Value to persist — interpolated directly into the cookie
24
- * string, so a boolean persists as `"true"`/`"false"` and a string persists
25
- * as-is.
26
- * @param maxAgeSeconds Seconds the cookie stays valid before a browser drops
27
- * it. Defaults to {@link ONE_YEAR_SECONDS}.
28
- * @example
29
- * writeCookie("app-sidebar:collapsed", true);
30
- * @example
31
- * writeCookie("ui:theme", "dark");
32
- * @example
33
- * writeCookie("ui:announcement-dismissed", true, 60 * 60 * 24 * 7);
22
+ * @param value Value to persist, interpolated as is, so a boolean persists as `"true"`/`"false"`.
23
+ * @param options How long the cookie lasts and which path it is sent under.
24
+ * @example writeCookie("app-sidebar:collapsed", true);
25
+ * @example writeCookie("ui:announcement-dismissed", true, { maxAgeSeconds: 60 * 60 * 24 * 7 });
26
+ * @example writeCookie("crm-sidebar", false, { path: "/crm" });
34
27
  */
35
- export function writeCookie(name, value, maxAgeSeconds = ONE_YEAR_SECONDS) {
36
- document.cookie = `${name}=${value}; path=/; max-age=${maxAgeSeconds}; samesite=lax`;
28
+ export function writeCookie(name, value, options = {}) {
29
+ let { maxAgeSeconds = ONE_YEAR_SECONDS, path = "/" } = options;
30
+ document.cookie = `${name}=${value}; path=${path}; max-age=${maxAgeSeconds}; samesite=lax`;
37
31
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Barrel for `@sdxc/ui/video`: a video player and its parts, from the screen and the
3
+ * chapter list to the control bar and its settings menu, with the helpers only they use.
4
+ * The player also imports on its own as `@sdxc/ui/video/video-player`.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ export * from "./mixins/video-player-sync.js";
10
+ export * from "./utils/timeline.js";
11
+ export * from "./video-player.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Barrel for `@sdxc/ui/video`: a video player and its parts, from the screen and the
3
+ * chapter list to the control bar and its settings menu, with the helpers only they use.
4
+ * The player also imports on its own as `@sdxc/ui/video/video-player`.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ export * from "./mixins/video-player-sync.js";
10
+ export * from "./utils/timeline.js";
11
+ export * from "./video-player.js";
@@ -0,0 +1,27 @@
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 type { ElementProps, MixinFactory } from "remix/component";
10
+ /**
11
+ * Brings a player's marks to `time`: the chapter link and transcript line playing then
12
+ * carry `aria-current`, each scrubber segment fills to its played share, and a newly
13
+ * current line scrolls into view inside the transcript alone.
14
+ *
15
+ * @param root The player's `<figure>`.
16
+ * @param time The video's current time in seconds.
17
+ */
18
+ export declare function syncVideo(root: HTMLElement, time: number): void;
19
+ /**
20
+ * Keeps a video player's links, marks, bar and video in step from a node inside its
21
+ * `[data-slot="video-player"]` root. A plain click on a time link seeks and plays; a
22
+ * modified click still opens the file itself.
23
+ *
24
+ * @returns A mixin descriptor for any element inside the player.
25
+ * @example <span hidden mix={[videoPlayerSync()]} />
26
+ */
27
+ export declare const videoPlayerSync: MixinFactory<HTMLElement, [], ElementProps>;
@@ -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
+ }