@trippnology/mixshell 0.0.0-stage → 0.7.0

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +294 -2
  3. package/assets/mixshell-screenshot.png +0 -0
  4. package/package.json +73 -5
  5. package/src/alsa-pulse.conf +20 -0
  6. package/src/alsa-setup.js +15 -0
  7. package/src/components/browser.js +193 -0
  8. package/src/components/config.js +168 -0
  9. package/src/components/durations.js +151 -0
  10. package/src/components/library.js +679 -0
  11. package/src/components/mediakeys.js +222 -0
  12. package/src/components/mpris.js +309 -0
  13. package/src/components/player.js +412 -0
  14. package/src/components/playlist.js +335 -0
  15. package/src/components/session.js +96 -0
  16. package/src/constants.js +164 -0
  17. package/src/engines/ffmpeg.js +601 -0
  18. package/src/engines/index.js +14 -0
  19. package/src/engines/webaudio.js +317 -0
  20. package/src/index.js +188 -0
  21. package/src/mediakeys/macos-nowplaying.js +227 -0
  22. package/src/ui/app.js +56 -0
  23. package/src/ui/artPane.js +314 -0
  24. package/src/ui/confirmPrompt.js +34 -0
  25. package/src/ui/constants.js +133 -0
  26. package/src/ui/controller.js +1641 -0
  27. package/src/ui/dom.js +9 -0
  28. package/src/ui/goToPrompt.js +105 -0
  29. package/src/ui/index.html +78 -0
  30. package/src/ui/libraryPanel.js +415 -0
  31. package/src/ui/listView.js +209 -0
  32. package/src/ui/onboarding.js +353 -0
  33. package/src/ui/playlistPanel.js +207 -0
  34. package/src/ui/settingsPanel.js +473 -0
  35. package/src/ui/shortcuts.js +30 -0
  36. package/src/ui/splash.js +302 -0
  37. package/src/ui/style.css +532 -0
  38. package/src/ui/subtabs.js +31 -0
  39. package/src/ui/visualizer/bars.js +74 -0
  40. package/src/ui/visualizer/circles.js +64 -0
  41. package/src/ui/visualizer/color.js +61 -0
  42. package/src/ui/visualizer/cube.js +105 -0
  43. package/src/ui/visualizer/grid.js +68 -0
  44. package/src/ui/visualizer/index.js +65 -0
  45. package/src/ui/visualizer/onset.js +130 -0
  46. package/src/ui/visualizer/spectrum.js +34 -0
  47. package/src/ui/visualizer/vu.js +71 -0
  48. package/src/ui/visualizer/waveform.js +58 -0
  49. package/src/utils/audioAnalyzer.js +362 -0
  50. package/src/utils/audioDevices.js +222 -0
  51. package/src/utils/cellart.js +75 -0
  52. package/src/utils/debug.js +7 -0
  53. package/src/utils/durationProbe.js +48 -0
  54. package/src/utils/folderArt.js +46 -0
  55. package/src/utils/format.js +20 -0
  56. package/src/utils/id3.js +84 -0
  57. package/src/utils/pathInput.js +76 -0
  58. package/src/utils/playlistIO.js +176 -0
  59. package/src/utils/terminalGraphics.js +47 -0
@@ -0,0 +1,209 @@
1
+ import { EDGE, OVERSCAN } from './constants.js';
2
+ import { makeEl } from './dom.js';
3
+
4
+ // Windowed lists: only a slice of rows lives in the DOM; two spacers
5
+ // (px height == rows) keep the active panel (the engine scroll container)
6
+ // at the full list height so element scrollTop clamping and edge reveals
7
+ // behave as with a fully rendered list. Selection renders re-derive the
8
+ // window and reveal via scrollIntoView; each panel's scroll listener
9
+ // re-derives the window from the panel's scrollTop and never writes it
10
+ // (no loop).
11
+ export function createListView({
12
+ document,
13
+ getCursor,
14
+ setCursor,
15
+ onSelectionChange,
16
+ onActivate,
17
+ activeContainer,
18
+ getViewportBase,
19
+ }) {
20
+ const el = makeEl(document);
21
+ const listWindows = new Map(); // container -> { first, top, scroll, items, selRow }
22
+
23
+ // Viewport budget in rows for a list container. Every panel spends its
24
+ // top rows on chrome that sits above the scroll port — the pinned
25
+ // .panel-title breadcrumb and, in the sub-screen panels (library,
26
+ // settings — issues/024), the sub-tab row. Measured, not assumed,
27
+ // because the view labels can wrap on narrow terminals (px == rows in
28
+ // the engine). Each pinned chrome row costs its height plus one margin
29
+ // row.
30
+ function viewportRows(container) {
31
+ let chrome = 0;
32
+ const panel = container.closest('.panel');
33
+ for (const selector of ['.subtabs', ':scope > .panel-title']) {
34
+ const pinned = panel?.querySelector(selector);
35
+ if (pinned) {
36
+ chrome += Math.round(pinned.getBoundingClientRect().height) + 1;
37
+ }
38
+ }
39
+ return Math.max(8, getViewportBase() - chrome);
40
+ }
41
+
42
+ function listStateFor(container) {
43
+ let st = listWindows.get(container);
44
+ if (!st) {
45
+ st = { first: 0, top: 0, scroll: 0, items: null, selRow: null };
46
+ listWindows.set(container, st);
47
+ }
48
+ return st;
49
+ }
50
+
51
+ // Rebuild the visible window into `container`. No scrollTop writes.
52
+ function paintWindow(container, items, first) {
53
+ const len = items.length;
54
+ const capacity = viewportRows(container);
55
+ const st = listStateFor(container);
56
+ const stop = Math.min(len, first + capacity + OVERSCAN);
57
+
58
+ const topSpacer = el('div', 'list-spacer');
59
+ topSpacer.style.height = `${first}px`;
60
+ container.replaceChildren(topSpacer);
61
+ let firstRow = null;
62
+ let selRow = null;
63
+ for (let i = first; i < stop; i++) {
64
+ const item = items[i];
65
+ const row = el('div', 'list-item');
66
+ if (i === getCursor()) {
67
+ row.classList.add('selected');
68
+ selRow = row;
69
+ }
70
+ if (item.current) row.classList.add('current');
71
+ if (item.audio) row.classList.add('audio');
72
+ row.appendChild(el('span', 'icon', item.icon || ''));
73
+ row.appendChild(el('span', 'text', item.text));
74
+ // Optional trailing detail (playlist lengths, issues/046) — its
75
+ // own span so themes keep it at the default text colour while
76
+ // the row paints current/audio green.
77
+ if (item.suffix) row.appendChild(el('span', 'suffix', item.suffix));
78
+ row.addEventListener('click', () => {
79
+ if (getCursor() === i) return;
80
+ setCursor(i);
81
+ onSelectionChange();
82
+ });
83
+ // Double-click (issues/044): termdom synthesizes dblclick from the
84
+ // terminal's mouse reports (same point, same button, 500ms), carrying
85
+ // the SGR modifier bits for the Alt+double-click queue variants.
86
+ row.addEventListener('dblclick', (e) => {
87
+ onActivate(e);
88
+ });
89
+ container.appendChild(row);
90
+ if (!firstRow) firstRow = row;
91
+ }
92
+ const bottomSpacer = el('div', 'list-spacer');
93
+ bottomSpacer.style.height = `${Math.max(0, len - stop)}px`;
94
+ container.appendChild(bottomSpacer);
95
+
96
+ st.first = first;
97
+ st.items = items; // scroll reslicing reuses this (no per-event re-map)
98
+ st.selRow = selRow;
99
+ // Layout flushes on demand in TermDOM, so this reads fresh geometry.
100
+ // The selected row sits at list offset `selected` regardless of the
101
+ // window (topSpacer stands in for the rows above), so list offset ==
102
+ // item index; `top` anchors the list inside its scrolling panel.
103
+ const scroller = container.parentElement;
104
+ const anchor = firstRow || topSpacer.nextSibling || container;
105
+ st.top =
106
+ anchor.getBoundingClientRect().top -
107
+ scroller.getBoundingClientRect().top +
108
+ scroller.scrollTop -
109
+ first;
110
+ // Baseline the scroll listener measures movement from.
111
+ st.scroll = scroller.scrollTop;
112
+ }
113
+
114
+ // Window start for a scroll offset, decode-style: OVERSCAN rows above
115
+ // the port top, clamped to the list. Shared by the scroll listener and
116
+ // render's post-reveal clamp.
117
+ function windowForScroll(st, container, scroll) {
118
+ const maxFirst = Math.max(0, st.items.length - viewportRows(container));
119
+ return Math.max(
120
+ 0,
121
+ Math.min(maxFirst, Math.floor(scroll - st.top) - OVERSCAN),
122
+ );
123
+ }
124
+
125
+ // Selection-driven render: keep the selection at least EDGE rows inside
126
+ // the window, then let the engine reveal the row in the panel scroller.
127
+ function render(container, items) {
128
+ const selected = getCursor();
129
+ const capacity = viewportRows(container);
130
+ const len = items.length;
131
+ const st = listStateFor(container);
132
+ const maxFirst = Math.max(0, len - capacity);
133
+ let first = Math.min(st.first, maxFirst);
134
+ if (len > capacity) {
135
+ if (selected < first + EDGE) {
136
+ first = Math.max(0, selected - EDGE);
137
+ } else if (selected > first + capacity - 1 - EDGE) {
138
+ first = Math.min(maxFirst, selected - capacity + 1 + EDGE);
139
+ }
140
+ }
141
+ paintWindow(container, items, first);
142
+ st.selRow?.scrollIntoView({ block: 'nearest' });
143
+ // The edge logic counts from the window, the reveal from the port:
144
+ // with the cursor pinned at the port bottom the engine will not
145
+ // scroll as far as the window grew, leaving rows [scrollTop, first)
146
+ // unpainted. The reveal's own offset is final (sync scrollTop
147
+ // setter, read after write), so re-derive the window from it, as the
148
+ // scroll listener would have.
149
+ const revealed = container.parentElement.scrollTop;
150
+ if (first > revealed) {
151
+ paintWindow(container, items, windowForScroll(st, container, revealed));
152
+ }
153
+ // The reveal scrolls; re-settle so it isn't read as user movement.
154
+ st.scroll = container.parentElement.scrollTop;
155
+ }
156
+
157
+ // Scroll-driven render. The engine applies the offset synchronously in the
158
+ // scrollTop setter and dispatches scroll after the paint, so scrollTop is
159
+ // final here — no microtask. Element scroll does not bubble (only the
160
+ // document's), hence one listener per scroll container; the .panel-scroll
161
+ // wrappers are static markup, so nothing rebinds on tab switch. Reads
162
+ // scrollTop only. Items come from the last paintWindow; data changes go
163
+ // through render(). The listener reads the list's parent as the
164
+ // scroller, which is the .panel-scroll wrapper in every list-bearing
165
+ // panel.
166
+ document.querySelectorAll('.panel-scroll').forEach((scrollEl) => {
167
+ scrollEl.addEventListener('scroll', () => {
168
+ const container = activeContainer();
169
+ if (!container) return;
170
+ const st = listWindows.get(container);
171
+ if (!st?.items) return;
172
+ const scroller = container.parentElement;
173
+ if (scroller.scrollTop === st.scroll) return;
174
+ st.scroll = scroller.scrollTop; // settle even without a repaint
175
+ const first = windowForScroll(st, container, scroller.scrollTop);
176
+ if (first !== st.first) {
177
+ paintWindow(container, st.items, first);
178
+ }
179
+ });
180
+ });
181
+
182
+ // Cursor-only navigation reuses the rows painted by the last render.
183
+ // Panel renderers (Library) build rows from SQLite; rebuilding them on
184
+ // every held arrow key stalls the TUI and the audio thread (issues/053
185
+ // follow-up). Data changes still go through render(), which refreshes
186
+ // these items.
187
+ function activeList() {
188
+ const container = activeContainer();
189
+ const st = container && listWindows.get(container);
190
+ return st?.items ? { container, st } : null;
191
+ }
192
+
193
+ function selectBy(delta) {
194
+ const hit = activeList();
195
+ if (!hit || hit.st.items.length === 0) return;
196
+ const len = hit.st.items.length;
197
+ setCursor((getCursor() + delta + len) % len);
198
+ render(hit.container, hit.st.items);
199
+ }
200
+
201
+ function selectAt(index) {
202
+ const hit = activeList();
203
+ if (!hit || hit.st.items.length === 0) return;
204
+ setCursor(Math.min(Math.max(0, index), hit.st.items.length - 1));
205
+ render(hit.container, hit.st.items);
206
+ }
207
+
208
+ return { render, selectBy, selectAt };
209
+ }
@@ -0,0 +1,353 @@
1
+ import { homedir } from 'node:os';
2
+
3
+ import { Browser } from '../components/browser.js';
4
+ import { listOutputDevices, resetDeviceProbe } from '../utils/audioDevices.js';
5
+ import { resolveDirectoryInput } from '../utils/pathInput.js';
6
+ import { createGoToPrompt } from './goToPrompt.js';
7
+
8
+ // Rows visible in the picker window (issues/041): the dialog paints
9
+ // centered over the app; longer listings scroll inside this window.
10
+ const LIST_ROWS = 9;
11
+
12
+ // First-run onboarding (issues/041): a real top-layer <dialog> — termdom
13
+ // 0.2.6 implements showModal/close with an inert page behind (hit-testing
14
+ // and focus skip the panels while it is up), so no bespoke key-capture
15
+ // mode is needed. Steps: pick the music directory (a private Browser
16
+ // rooted at $HOME), offer the initial scan, offer the output-device
17
+ // picker when more than one device is detected (single-device machines
18
+ // skip it silently). Esc skips only the first step; on later steps it
19
+ // finishes with the answers already applied (issues/056). Both routes
20
+ // persist `onboarded: true` so the flow never nags again.
21
+ export function createOnboarding({
22
+ document,
23
+ el,
24
+ config,
25
+ log,
26
+ onFinished,
27
+ startDirectory,
28
+ home = homedir(),
29
+ resolve = resolveDirectoryInput,
30
+ listDevices = listOutputDevices,
31
+ }) {
32
+ const dialog = document.createElement('dialog');
33
+ dialog.className = 'onboard';
34
+ const title = el('div', 'onboard-title');
35
+ const sub = el('div', 'onboard-dir');
36
+ const body = el('div', 'onboard-body');
37
+ const hint = el('div', 'onboard-hint');
38
+ dialog.append(title, sub, body, hint);
39
+ document.body.appendChild(dialog);
40
+
41
+ const state = {
42
+ open: false,
43
+ // 'pick' → 'scan' → 'device'.
44
+ step: 'pick',
45
+ dir: null,
46
+ scan: false,
47
+ cursor: 0,
48
+ windowStart: 0,
49
+ browser: null,
50
+ // Enumeration kicked off at start(); resolved when the flow reaches
51
+ // the device step — the user can get there before the probes finish
52
+ // and sees a "listing" line until then.
53
+ devicesPromise: null,
54
+ devices: null,
55
+ // Picker's own go-to prompt; base is the directory being shown.
56
+ goTo: createGoToPrompt(),
57
+ // Set only when the launch directory is unusable; cleared on the
58
+ // first navigation (issues/051).
59
+ notice: null,
60
+ };
61
+
62
+ function start() {
63
+ if (state.open) return;
64
+ state.open = true;
65
+ state.step = 'pick';
66
+ state.dir = null;
67
+ state.scan = false;
68
+ state.cursor = 0;
69
+ const candidate = startDirectory ?? config.get('mediaDirectory');
70
+ const resolved = candidate
71
+ ? resolve(candidate, { base: process.cwd(), home })
72
+ : null;
73
+ const usable = resolved && !resolved.error;
74
+ state.browser = new Browser(usable ? resolved.path : home);
75
+ state.notice =
76
+ candidate && !usable
77
+ ? `${resolved?.error ?? `${candidate} is not a directory`} — showing ${home}`
78
+ : null;
79
+ state.devices = null;
80
+ state.devicesPromise = listDevices();
81
+ dialog.showModal();
82
+ log('Onboarding started');
83
+ render();
84
+ }
85
+
86
+ function close() {
87
+ state.open = false;
88
+ state.devices = null;
89
+ if (dialog.hasAttribute('open')) dialog.close();
90
+ }
91
+
92
+ // Completion persists the flag either way — skipping must not nag on
93
+ // every launch (issues/041: dismissable, never blocking).
94
+ function end(message, callback) {
95
+ config.set('onboarded', true);
96
+ config.save();
97
+ close();
98
+ log(message);
99
+ if (callback) callback({ dir: state.dir, scan: state.scan });
100
+ }
101
+
102
+ // Every completion route — last question, auto-skip of the device step,
103
+ // and Esc after a choice — shares this call, so the app's follow-up
104
+ // (browser reload, optional scan, post-onboarding advice) cannot drift.
105
+ function finish() {
106
+ end('Onboarding complete', onFinished);
107
+ }
108
+
109
+ // --- Steps ---------------------------------------------------------------
110
+
111
+ function confirmDir(dir) {
112
+ state.dir = dir;
113
+ config.set('mediaDirectory', dir);
114
+ state.step = 'scan';
115
+ state.cursor = 0;
116
+ render();
117
+ }
118
+
119
+ function answerScan(yes) {
120
+ if (yes) {
121
+ state.scan = true;
122
+ config.set('libraryDirs', [state.dir]);
123
+ config.set('libraryScanOnStart', true);
124
+ }
125
+ enterDeviceStep();
126
+ }
127
+
128
+ function enterDeviceStep() {
129
+ state.step = 'device';
130
+ state.cursor = 0;
131
+ render(); // "Listing output devices…" while the probes run
132
+ state.devicesPromise.then((devices) => {
133
+ if (!state.open || state.step !== 'device') return;
134
+ state.devices = devices;
135
+ // Single-device machines skip the step silently (issues/041).
136
+ if (devices.length > 1) render();
137
+ else finish();
138
+ });
139
+ }
140
+
141
+ function pickDevice() {
142
+ if (!state.devices) return; // enumeration still running
143
+ const id = state.cursor === 0 ? null : state.devices[state.cursor - 1].id;
144
+ if (id) {
145
+ config.set('audioDevice', id);
146
+ // Same heal as the settings re-pick (issues/047): a fresh choice
147
+ // clears any poisoned probe verdict.
148
+ resetDeviceProbe(id);
149
+ }
150
+ finish();
151
+ }
152
+
153
+ function activate() {
154
+ if (state.step === 'pick') {
155
+ // Row 0 is synthetic "This folder" (issues/051): Enter confirms
156
+ // the directory currently shown, wherever navigation took us.
157
+ if (state.cursor === 0) {
158
+ confirmDir(state.browser.currentDirectory);
159
+ return;
160
+ }
161
+ const entry = state.browser.entries[state.cursor - 1];
162
+ if (!entry) return;
163
+ // Enter on a directory confirms the choice (issues/041); `..`
164
+ // stays a navigation row — confirming the parent is nonsense.
165
+ if (entry.isDirectory && entry.name !== '..') confirmDir(entry.path);
166
+ else if (entry.isDirectory) loadDir(entry.path);
167
+ } else if (state.step === 'scan') {
168
+ answerScan(state.cursor === 0);
169
+ } else if (state.step === 'device') {
170
+ pickDevice();
171
+ }
172
+ }
173
+
174
+ // --- Browser navigation ---------------------------------------------------
175
+
176
+ function loadDir(dirPath) {
177
+ // Picker owns its own notice slot — no toast behind the modal.
178
+ if (!state.browser.loadDirectory(dirPath)) {
179
+ state.notice = state.browser.lastError.error;
180
+ return; // cursor stays on the entry, listing stays intact
181
+ }
182
+ state.cursor = state.browser.selectedIndex + 1; // row 0 is "This folder"
183
+ state.notice = null;
184
+ }
185
+
186
+ function drill() {
187
+ if (state.cursor === 0) return;
188
+ const entry = state.browser.entries[state.cursor - 1];
189
+ if (entry?.isDirectory) loadDir(entry.path);
190
+ }
191
+
192
+ function ascend() {
193
+ // Browser.goBack() now climbs to the parent with empty history too.
194
+ if (state.browser.goBack()) {
195
+ state.cursor = state.browser.selectedIndex + 1;
196
+ state.notice = null;
197
+ }
198
+ }
199
+
200
+ // --- Keys -----------------------------------------------------------------
201
+ // The controller routes every key here while the dialog is open (the
202
+ // page behind is inert anyway); true = consumed.
203
+
204
+ function move(delta, count) {
205
+ if (count <= 0) return;
206
+ state.cursor = (((state.cursor + delta) % count) + count) % count;
207
+ }
208
+
209
+ function key(e) {
210
+ if (!state.open) return false;
211
+ // Prompt owns every key while open (invariant 5): typed paths may
212
+ // contain q/s/n/p/m/Space/digits without firing shortcuts.
213
+ if (state.goTo.key(e)) {
214
+ render();
215
+ return true;
216
+ }
217
+ const key = e.key;
218
+ if (key === 'Escape') {
219
+ // Only the pick step skips: later steps already applied their
220
+ // answers to config (issues/056), so finish through the same
221
+ // path as a completed run and let onFinished apply them.
222
+ if (state.step === 'pick')
223
+ end('Onboarding skipped — defaults kept', onFinished);
224
+ else finish();
225
+ return true;
226
+ }
227
+ if (state.step === 'pick' && key === 'g') {
228
+ state.goTo.start({
229
+ base: state.browser.currentDirectory,
230
+ onConfirm: (dir) => confirmDir(dir),
231
+ });
232
+ render();
233
+ return true;
234
+ }
235
+ const count =
236
+ state.step === 'pick'
237
+ ? state.browser.entries.length + 1
238
+ : state.step === 'scan'
239
+ ? 2
240
+ : deviceRows().length;
241
+ if (count > 0) {
242
+ if (key === 'ArrowDown') move(1, count);
243
+ else if (key === 'ArrowUp') move(-1, count);
244
+ else if (key === 'PageDown')
245
+ move(state.step === 'pick' ? LIST_ROWS : 1, count);
246
+ else if (key === 'PageUp')
247
+ move(state.step === 'pick' ? -LIST_ROWS : -1, count);
248
+ else if (key === 'Home') state.cursor = 0;
249
+ else if (key === 'End') state.cursor = count - 1;
250
+ else if (state.step === 'pick' && (key === 'ArrowRight' || key === 'l'))
251
+ drill();
252
+ else if (state.step === 'pick' && (key === 'ArrowLeft' || key === 'h'))
253
+ ascend();
254
+ else if (key === 'Enter' && !e.altKey && !e.ctrlKey && !e.metaKey)
255
+ activate();
256
+ else if (state.step === 'scan' && (key === 'y' || key === 'Y'))
257
+ answerScan(true);
258
+ else if (state.step === 'scan' && (key === 'n' || key === 'N'))
259
+ answerScan(false);
260
+ }
261
+ render();
262
+ return true;
263
+ }
264
+
265
+ // --- Rendering ------------------------------------------------------------
266
+
267
+ function stepRows() {
268
+ if (state.step === 'pick') {
269
+ return [
270
+ { icon: '▸', text: 'This folder/' },
271
+ ...state.browser.entries.map((entry) => ({
272
+ icon: entry.isDirectory
273
+ ? '▸'
274
+ : entry.isPlaylist
275
+ ? '≡'
276
+ : entry.isAudio
277
+ ? '♪'
278
+ : '·',
279
+ text: entry.isDirectory ? `${entry.name}/` : entry.name,
280
+ })),
281
+ ];
282
+ }
283
+ if (state.step === 'scan') {
284
+ return [
285
+ { icon: ' ', text: 'Y — Scan music into the library now' },
286
+ { icon: ' ', text: 'N — Just use it as the media directory' },
287
+ ];
288
+ }
289
+ return deviceRows();
290
+ }
291
+
292
+ function deviceRows() {
293
+ if (!state.devices) {
294
+ return [{ icon: ' ', text: 'Listing output devices…' }];
295
+ }
296
+ return [
297
+ { icon: ' ', text: 'Default (system output)' },
298
+ ...state.devices.map((device) => ({
299
+ icon: ' ',
300
+ text: device.name || device.id,
301
+ })),
302
+ ];
303
+ }
304
+
305
+ // Keep the cursor inside the visible window (plain offset windowing —
306
+ // the dialog list is not a virtualized panel scroller). This is the only
307
+ // writer of windowStart: every render re-derives it from the cursor.
308
+ function clampWindow(length) {
309
+ if (state.cursor < state.windowStart) state.windowStart = state.cursor;
310
+ if (state.cursor >= state.windowStart + LIST_ROWS) {
311
+ state.windowStart = state.cursor - LIST_ROWS + 1;
312
+ }
313
+ state.windowStart = Math.max(
314
+ 0,
315
+ Math.min(state.windowStart, Math.max(0, length - LIST_ROWS)),
316
+ );
317
+ }
318
+
319
+ function paintRows(rows) {
320
+ clampWindow(rows.length);
321
+ body.replaceChildren();
322
+ const stop = Math.min(rows.length, state.windowStart + LIST_ROWS);
323
+ for (let i = state.windowStart; i < stop; i++) {
324
+ const row = el('div', 'list-item');
325
+ if (i === state.cursor) row.classList.add('selected');
326
+ row.appendChild(el('span', 'icon', rows[i].icon));
327
+ row.appendChild(el('span', 'text', rows[i].text));
328
+ body.appendChild(row);
329
+ }
330
+ }
331
+
332
+ function render() {
333
+ if (!state.open) return;
334
+ if (state.step === 'pick') {
335
+ title.textContent = 'Welcome to MixShell — where is your music?';
336
+ sub.textContent = `${state.notice ?? state.browser.currentDirectory}${state.goTo.suffix()}`;
337
+ hint.textContent = state.goTo.isOpen()
338
+ ? 'Enter confirm · Esc cancel'
339
+ : '↑↓ move · → open · ← Back/up · g Go to · Enter choose · Esc skip';
340
+ } else if (state.step === 'scan') {
341
+ title.textContent = 'Scan into the library?';
342
+ sub.textContent = state.dir;
343
+ hint.textContent = '↑↓ choose · Enter confirm · Esc finish (no scan)';
344
+ } else {
345
+ title.textContent = 'Choose output device';
346
+ sub.textContent = 'Applies from the next play';
347
+ hint.textContent = '↑↓ choose · Enter confirm · Esc finish';
348
+ }
349
+ paintRows(stepRows());
350
+ }
351
+
352
+ return { start, key, isOpen: () => state.open };
353
+ }