// Round seven: the artwork viewer (the desktop's lightbox) from the
// now-playing art and a record page's cover, one layer the back gesture
// peels; and the doc's "not done yet" brought up to date.
const fs = require('fs');
const root = 'F:/Coding/SoulStream/';
let p, s;
const load = (file) => { p = file; s = fs.readFileSync(root + p, 'utf8'); };
const save = () => fs.writeFileSync(root + p, s);
const once = (a) => {
const i = s.indexOf(a);
if (i < 0) throw new Error('missing in ' + p + ': ' + a.slice(0, 90));
if (s.indexOf(a, i + 1) >= 0) throw new Error('ambiguous in ' + p + ': ' + a.slice(0, 90));
return i;
};
const rep = (a, b) => { once(a); s = s.replace(a, () => b); };
const NL = String.fromCharCode(10);
const afterLine = (anchor, text) => { const i = once(anchor); const nl = s.indexOf(NL, i); s = s.slice(0, nl + 1) + text + s.slice(nl + 1); };
// ── nav: the viewer is one more layer the back gesture peels ──
load('src/mobile/nav.svelte.js');
rep(` /* the half sheet: { kind, arg } */
half: null,
});`, ` /* the half sheet: { kind, arg } */
half: null,
/* the artwork viewer, and the art key it shows */
viewer: false,
viewerKey: null,
});`);
rep(`function backables() {
return (nav.sheet ? 1 : 0) + (nav.half ? 1 : 0)`, `function backables() {
return (nav.viewer ? 1 : 0) + (nav.sheet ? 1 : 0) + (nav.half ? 1 : 0)`);
rep(` depth = Math.max(0, depth - 1);
if (nav.sheet) nav.sheet = false;
else if (nav.half) nav.half = null;`, ` depth = Math.max(0, depth - 1);
if (nav.viewer) nav.viewer = false;
else if (nav.sheet) nav.sheet = false;
else if (nav.half) nav.half = null;`);
rep(`export function back() {
if (nav.sheet) nav.sheet = false;
else if (nav.half) nav.half = null;`, `export function back() {
if (nav.viewer) nav.viewer = false;
else if (nav.sheet) nav.sheet = false;
else if (nav.half) nav.half = null;`);
rep(`export function openHalf(kind, arg = null) {`, `export function openViewer(key) {
if (!key) return;
nav.viewerKey = key;
nav.viewer = true;
sync();
}
export function closeViewer() {
if (!nav.viewer) return;
nav.viewer = false;
sync();
}
export function openHalf(kind, arg = null) {`);
save();
// ── the shell renders it ──
load('src/mobile/Mobile.svelte');
rep(` import HalfSheet from "./HalfSheet.svelte";`, ` import HalfSheet from "./HalfSheet.svelte";
import Viewer from "./Viewer.svelte";`);
rep(`