create-pmos 0.323.0 → 0.325.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 (35) hide show
  1. package/package.json +1 -1
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-calendar-2-test.js +8 -6
  7. package/workspace/briefing-premium-calendar-3-test.js +7 -4
  8. package/workspace/briefing-premium-calendar-test.js +4 -2
  9. package/workspace/guide/briefing-premium.md +15 -0
  10. package/workspace/package-lock.json +2 -2
  11. package/workspace/package.json +1 -1
  12. package/workspace/premium-vw-item-test.js +128 -0
  13. package/workspace/premium-vw-meet-test.js +210 -0
  14. package/workspace/premium-vw-notes-test.js +161 -0
  15. package/workspace/premium-vw-slides-test.js +269 -0
  16. package/workspace/public/pm/premium-board.js +3 -1
  17. package/workspace/public/pm/premium-deck.js +218 -0
  18. package/workspace/public/pm/premium-initiative.js +7 -2
  19. package/workspace/public/pm/premium-meeting.js +84 -31
  20. package/workspace/public/pm/premium-report-read.js +11 -3
  21. package/workspace/public/pm/premium-shell.js +1 -0
  22. package/workspace/public/pm/premium-vw-item-model.js +58 -0
  23. package/workspace/public/pm/premium-vw-item.css +25 -0
  24. package/workspace/public/pm/premium-vw-item.js +66 -0
  25. package/workspace/public/pm/premium-vw-meet.css +87 -0
  26. package/workspace/public/pm/premium-vw-meet.js +322 -0
  27. package/workspace/public/pm/premium-vw-notes.css +43 -0
  28. package/workspace/public/pm/premium-vw-notes.js +188 -0
  29. package/workspace/public/pm/premium-vw-slides.css +163 -0
  30. package/workspace/public/pm/premium-vw-slides.js +472 -0
  31. package/workspace/public/pm/premium.js +2 -0
  32. package/workspace/test-lists/premium-viewer.json +9 -3
  33. package/workspace/test-lists/premium-vw-item.json +13 -0
  34. package/workspace/test-lists/premium-vw-meet.json +13 -0
  35. package/workspace/test-lists/premium-vw-notes.json +13 -0
@@ -0,0 +1,472 @@
1
+ /* pm/premium-vw-slides.js — the slide editor, a view of the premium viewer (initiative premium-viewer, R-SL1; frame contract
2
+ * /mnt/project-files/premium-viewer-build/frame-contract.md). The PM chose the prototype's full editor (2026-10-19). A deck is a markdown file
3
+ * (pm/premium-deck.js has the format): the editor reads it through GET /api/doc and saves it through POST /api/doc-sheet/edit, which keeps a
4
+ * revision with the PM's why. Nothing else is stored.
5
+ *
6
+ * openSlides({ ws, path, title, readOnly, onSaved }) opens the file as a Slides tab beside the dialog's own detail
7
+ *
8
+ * On the slide: click to select, drag to move (centre guides), the corner handles to resize, double-click to type. The rail reorders by drag
9
+ * (or Move up and Move down), adds a slide from a layout, duplicates and deletes. Undo and redo cover every change. Present opens the presenter
10
+ * view (R-SL2): the slide, the next one, the speaker notes and a timer, with Slides only and an audience window
11
+ * that shows the slide alone. An image is a file already in the workspace, shown through /api/asset; there is no upload. An issued report opens
12
+ * read-only.
13
+ * window.__premiumSlides is the hook for tests. */
14
+ import { vwOpen, vwStyle } from './premium-viewer.js';
15
+ import { pmPost } from './http.js';
16
+ import { toast } from './premium-shell.js';
17
+ import * as D from './premium-deck.js';
18
+
19
+ const esc = D.esc;
20
+ const ICO = { undo: 'M9 14 4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3', redo: 'm15 14 5-5-5-5M20 9H9a5 5 0 0 0 0 10h3', txt: 'M5 6V4h14v2M12 4v16M9 20h6',
21
+ img: 'M4 5h16v14H4zM4 16l5-5 4 4 2-2 5 5M15 9h.01', chart: 'M4 20V4M4 20h16M8 16v-5M12 16V8M16 16v-3', tbl: 'M4 5h16v14H4zM4 10h16M4 15h16M10 5v14',
22
+ shape: 'M5 5h14v14H5z', lay: 'M4 4h16v16H4zM4 9h16M10 9v11', pal: 'M12 3a9 9 0 1 0 0 18c1 0 1.5-.8 1.5-1.6 0-1.3 1-1.9 2-1.9H18a3 3 0 0 0 3-3A9 9 0 0 0 12 3zM7.5 11h.01M10 7h.01M15 7h.01',
23
+ play: 'M8 5v14l11-7z', save: 'M5 4h11l3 3v13H5zM8 4v5h7V4M8 20v-6h8v6', dup: 'M8 8h11v11H8zM5 15V5h10', trash: 'M5 7h14M10 11v6M14 11v6M7 7l1 13h8l1-13M9 7V4h6v3',
24
+ lt: 'm15 6-6 6 6 6', rt: 'm9 6 6 6-6 6', up: 'm6 14 6-6 6 6', down: 'm6 10 6 6 6-6', plus: 'M12 5v14M5 12h14', x: 'M6 6l12 12M18 6 6 18', front: 'M8 8h11v11H8zM5 5h9v2M5 5v9h2', back: 'M5 5h11v11H5zM10 19h9V10',
25
+ al: 'M4 6h16M4 12h10M4 18h14', ac: 'M4 6h16M7 12h10M5 18h14', ar: 'M4 6h16M10 12h10M6 18h14', ul: 'M9 6h11M9 12h11M9 18h11M5 6h.01M5 12h.01M5 18h.01' };
26
+ const I = (k) => `<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="${ICO[k]}"/></svg>`;
27
+ const tb = (c, label, ic, extra = '') => `<button type="button" class="sl-b" data-c="${c}" aria-label="${esc(label)}" title="${esc(label)}"${extra}>${I(ic)}</button>`;
28
+ const tbl = (c, label, ic, extra = '') => `<button type="button" class="sl-b sl-bl" data-c="${c}" title="${esc(label)}"${extra}>${I(ic)}<span>${esc(label)}</span></button>`;
29
+ let NID = 0;
30
+ const nid = () => 'e' + (++NID);
31
+ const asset = (ws, src) => '/api/asset?' + new URLSearchParams({ ...(ws ? { ws } : {}), path: src }).toString();
32
+
33
+ /* ── drawing a slide (geometry goes on through custom properties after the markup is in: see place) ── */
34
+ function chartSvg(e) {
35
+ const w = e.w, h = e.h, B = 34, T = 34, d = e.data.length ? e.data : [['', 0]], mx = Math.max(1, ...d.map((x) => Math.abs(+x[1] || 0))), bw = w / d.length;
36
+ const Y = (v) => h - B - (Math.max(0, v) / mx) * (h - B - T);
37
+ const lab = (x, y, t) => `<text class="sl-lab" x="${x}" y="${y}" text-anchor="middle">${esc(t)}</text>`;
38
+ let g = `<line class="sl-ax" x1="0" x2="${w}" y1="${h - B}" y2="${h - B}"/>`;
39
+ if (e.kind === 'line') {
40
+ const P = d.map((x, i) => [bw * i + bw / 2, Y(+x[1] || 0)]);
41
+ g += `<polyline class="sl-line" points="${P.map((p) => p.join(',')).join(' ')}"/>` + P.map((p, i) => `<circle class="sl-pt" cx="${p[0]}" cy="${p[1]}" r="8"/>${lab(p[0], p[1] - 16, d[i][1])}`).join('');
42
+ } else g += d.map((x, i) => { const y = Y(+x[1] || 0); return `<rect class="sl-bar${i === d.length - 1 ? ' last' : ''}" x="${bw * i + bw * 0.17}" y="${y}" width="${bw * 0.66}" height="${Math.max(0, h - B - y)}" rx="6"/>${lab(bw * i + bw / 2, y - 10, x[1])}`; }).join('');
43
+ g += d.map((x, i) => `<text class="sl-axl" x="${bw * i + bw / 2}" y="${h - 8}" text-anchor="middle">${esc(x[0])}</text>`).join('');
44
+ return `<svg viewBox="0 0 ${w} ${h}" role="img" aria-label="${esc((e.kind === 'line' ? 'Line' : 'Bar') + ' chart: ' + d.map((x) => x[0] + ' ' + x[1]).join(', '))}">${g}</svg>`;
45
+ }
46
+ function elHtml(e, ws, edit) {
47
+ const inner = e.t === 'text' ? `<div class="sl-tx">${e.html}</div>`
48
+ : e.t === 'chart' ? chartSvg(e)
49
+ : e.t === 'table' ? `<table>${e.rows.map((r, i) => `<tr>${r.map((c) => (i ? `<td>${c}</td>` : `<th>${c}</th>`)).join('')}</tr>`).join('')}</table>`
50
+ : e.t === 'img' ? (e.src ? `<img src="${esc(asset(ws, e.src))}" alt="${esc(e.alt || '')}" data-src="${esc(e.src)}">` : `<div class="sl-ph">${I('img')}<span>${edit ? 'Double-click to choose an image' : 'No image'}</span></div>`)
51
+ : `<div class="sl-sh f-${e.fill || 'acc'}${e.round ? ' dot' : ''}"></div>`;
52
+ const cls = `sl-it t-${e.t}${e.role ? ' r-' + e.role : ''}${e.align && e.align !== 'left' ? ' a-' + e.align : ''}${e.color ? ' c-' + e.color : ''}`;
53
+ return `<div class="${cls}" data-id="${e.id || ''}" data-g="${e.x},${e.y},${e.w},${e.h}">${inner}${edit ? ['nw', 'ne', 'sw', 'se'].map((h) => `<i class="sl-hdot h-${h}" data-h="${h}"></i>`).join('') : ''}</div>`;
54
+ }
55
+ export function slideHtml(s, theme, ws, edit) {
56
+ return `<div class="sl-cv${edit ? ' ed' : ''}" data-th="${esc(theme)}">${s.els.map((e) => elHtml(e, ws, edit)).join('')}${edit ? '<i class="sl-guide gv"></i><i class="sl-guide gh"></i>' : ''}</div>`;
57
+ }
58
+ /** Puts each item where its data-g says, and marks an image that does not load. */
59
+ function place(root) {
60
+ root.querySelectorAll('.sl-it[data-g]').forEach((n) => {
61
+ const [x, y, w, h] = n.dataset.g.split(',');
62
+ n.style.setProperty('--bd-x', x + 'px'); n.style.setProperty('--bd-y', y + 'px'); n.style.setProperty('--bd-w', w + 'px'); n.style.setProperty('--bd-h', h + 'px');
63
+ });
64
+ root.querySelectorAll('.sl-it img').forEach((im) => { im.onerror = () => { const p = document.createElement('div'); p.className = 'sl-ph'; p.textContent = 'No image at ' + im.dataset.src; im.replaceWith(p); }; });
65
+ }
66
+ /** Scales a 960 x 540 canvas to the width of its box. */
67
+ function fit(box) { const w = box.clientWidth; if (w) box.style.setProperty('--bd-k', String(w / D.W)); }
68
+
69
+ /* ── Present: the presenter view (the slide, the next one, speaker notes, a timer) or the slides only; an audience window shows the slide alone ── */
70
+ const mmss = (t) => { const m = Math.floor(t / 60); return (m < 10 ? '0' : '') + m + ':' + String(t % 60).padStart(2, '0'); };
71
+ /** Scales the slide in a box to fit both its width and its height. */
72
+ function fitIn(box, slot) { const k = Math.max(0.05, Math.min(slot.clientWidth / D.W, slot.clientHeight / D.H)); box.style.setProperty('--bd-k', String(k)); place(box); }
73
+
74
+ /** present(deck, ws, start, { ro, kind, onNotes(i, text, first), onEnd(i) }). kind is 'pres' (the presenter view, the default) or 'aud' (the
75
+ * slides only). The audience window is a second window of this origin that the presenter view draws into, so the two cannot drift apart. */
76
+ export function present(deck, ws, start, opt = {}) {
77
+ const P = { i: Math.max(0, Math.min(deck.slides.length - 1, start || 0)), kind: opt.kind === 'aud' ? 'aud' : 'pres', t0: Date.now(), win: null, typed: false };
78
+ const n = deck.slides.length;
79
+ const o = document.createElement('div'); o.className = 'sl-pres'; o.dataset.escLayer = ''; o.tabIndex = -1; o.setAttribute('role', 'dialog'); o.setAttribute('aria-label', 'Presenting ' + deck.title);
80
+ const nav = () => `<div class="sl-prn"><button type="button" class="sl-b sl-pd" data-c="prev" aria-label="Previous slide"${P.i ? '' : ' disabled'}>${I('lt')}</button><p class="sl-pn">${P.i + 1} / ${n}<span> · arrow keys to move · Escape to stop</span></p><button type="button" class="sl-b sl-pd" data-c="next" aria-label="Next slide"${P.i < n - 1 ? '' : ' disabled'}>${I('rt')}</button></div>`;
81
+ const draw = () => {
82
+ const s = deck.slides[P.i], nx = deck.slides[P.i + 1];
83
+ const bar = `<div class="sl-prb"><b>${esc(deck.title)}</b><span class="sl-pk" data-pt title="Time since you started">${mmss(Math.floor((Date.now() - P.t0) / 1000))}</span><button type="button" class="sl-b sl-pd" data-c="tm" aria-label="Restart the timer" title="Restart the timer">${I('undo')}</button><span class="sl-gap"></span>`
84
+ + `<button type="button" class="sl-b sl-bl sl-pd" data-c="win" title="A second window with the slide only, to share or put on the room's screen">${I('front')}<span>Audience window</span></button>`
85
+ + `<button type="button" class="sl-b sl-bl sl-pd" data-c="kind" aria-pressed="${P.kind === 'aud'}">${I(P.kind === 'aud' ? 'lay' : 'play')}<span>${P.kind === 'aud' ? 'Presenter view' : 'Slides only'}</span></button>`
86
+ + `<button type="button" class="sl-b sl-pd" data-c="end" aria-label="Stop presenting" title="Stop presenting (Escape)">${I('x')}</button></div>`;
87
+ const cur = `<div class="sl-pslot"><div class="sl-pbox" data-c="adv">${slideHtml(s, deck.theme, ws, false)}</div></div>`;
88
+ o.dataset.k = P.kind;
89
+ o.innerHTML = P.kind === 'aud' ? `${bar}${cur}${nav()}`
90
+ : `${bar}<div class="sl-prg"><div class="sl-prc">${cur}${nav()}</div><aside class="sl-pside"><p class="sl-lbl">Next</p>`
91
+ + (nx ? `<div class="sl-pnx"><div class="sl-pbox">${slideHtml(nx, deck.theme, ws, false)}</div></div>` : '<p class="sl-hint">That was the last slide.</p>')
92
+ + `<label class="sl-lbl" for="slPN">Speaker notes</label><textarea id="slPN" rows="6"${opt.ro ? ' readonly' : ''} placeholder="${opt.ro ? 'No notes on this slide' : 'What you will say on this slide'}">${esc(s.notes || '')}</textarea><p class="sl-hint">Only you see speaker notes. They are not on the slide or in the audience window.</p></aside></div>`;
93
+ lay();
94
+ const t = o.querySelector('#slPN');
95
+ if (t) { t.onfocus = () => { P.typed = false; }; t.oninput = () => { const v = t.value.slice(0, 4000); if (opt.onNotes) opt.onNotes(P.i, v, !P.typed); else s.notes = v; P.typed = true; }; }
96
+ drawWin();
97
+ };
98
+ const lay = () => { o.querySelectorAll('.sl-pslot,.sl-pnx').forEach((slot) => { const b = slot.querySelector('.sl-pbox'); if (b) fitIn(b, slot); }); };
99
+ const drawWin = () => {
100
+ const w = P.win; if (!w || w.closed) return;
101
+ const d = w.document, s = deck.slides[P.i];
102
+ d.body.innerHTML = `<div class="sl-pres" data-k="win"><div class="sl-pslot"><div class="sl-pbox">${slideHtml(s, deck.theme, ws, false)}</div></div></div>`;
103
+ const slot = d.querySelector('.sl-pslot'), b = d.querySelector('.sl-pbox');
104
+ const k = Math.max(0.05, Math.min(w.innerWidth / D.W, w.innerHeight / D.H)); b.style.setProperty('--bd-k', String(k)); place(b);
105
+ if (slot) slot.dataset.i = String(P.i);
106
+ };
107
+ const openWin = () => {
108
+ let w = null;
109
+ try { w = window.open('', 'pmos-slides-audience', 'popup=yes,width=1280,height=720'); } catch { w = null; }
110
+ if (!w || w.closed) { toast('The browser blocked the audience window. Allow pop-ups for PMOS, then press Audience window again.'); return; }
111
+ const d = w.document;
112
+ d.title = 'Audience · ' + deck.title;
113
+ if (!d.querySelector('link[data-sl]')) for (const h of ['/pm/premium.css', '/pm/premium-vw-slides.css']) { const l = d.createElement('link'); l.rel = 'stylesheet'; l.href = location.origin + h; l.dataset.sl = ''; d.head.append(l); }
114
+ d.documentElement.dataset.theme = 'dark'; d.body.className = 'sl-audw';
115
+ w.onkeydown = (e) => key(e); w.onresize = drawWin; w.onclick = () => go(1);
116
+ P.win = w; drawWin(); o.focus();
117
+ };
118
+ const go = (dx) => { const k = Math.max(0, Math.min(n - 1, P.i + dx)); if (k !== P.i) { P.i = k; draw(); } };
119
+ const tick = setInterval(() => { const t = o.querySelector('[data-pt]'); if (t) t.textContent = mmss(Math.floor((Date.now() - P.t0) / 1000)); }, 1000);
120
+ const end = () => {
121
+ clearInterval(tick); o.remove(); removeEventListener('resize', lay); document.removeEventListener('keydown', key, true);
122
+ if (P.win && !P.win.closed) P.win.close();
123
+ if (opt.onEnd) opt.onEnd(P.i);
124
+ };
125
+ function key(e) {
126
+ if (e.target && e.target.tagName === 'TEXTAREA') { if (e.key === 'Escape') { e.preventDefault(); e.stopImmediatePropagation(); o.focus(); } return; }
127
+ if (e.key === 'Escape') { e.preventDefault(); e.stopImmediatePropagation(); end(); return; }
128
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown' || e.key === ' ' || e.key === 'PageDown') { e.preventDefault(); go(1); }
129
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowUp' || e.key === 'PageUp') { e.preventDefault(); go(-1); }
130
+ }
131
+ o.onclick = (e) => {
132
+ const c = e.target.closest('[data-c]'), k = c && c.dataset.c;
133
+ if (k === 'end') return end();
134
+ if (k === 'prev') return go(-1);
135
+ if (k === 'next') return go(1);
136
+ if (k === 'tm') { P.t0 = Date.now(); o.querySelector('[data-pt]').textContent = '00:00'; return; }
137
+ if (k === 'win') return openWin();
138
+ if (k === 'kind') { P.kind = P.kind === 'aud' ? 'pres' : 'aud'; draw(); o.focus(); return; }
139
+ if (k === 'adv') { if (P.i < n - 1) go(1); else if (P.kind === 'aud') end(); }
140
+ };
141
+ document.body.append(o); draw(); o.focus(); addEventListener('resize', lay); document.addEventListener('keydown', key, true);
142
+ return { end, at: () => P.i, go, kind: () => P.kind, win: () => P.win };
143
+ }
144
+
145
+ /* ── the editor ── */
146
+ const OPEN = new Map(); // path -> editor state, so the test hook can read it
147
+
148
+ export async function openSlides({ ws, path, title, readOnly, onSaved } = {}) {
149
+ if (!path) return null;
150
+ vwStyle('slides');
151
+ const S = { ws: ws || '', path, title: title || String(path).split('/').pop(), ro: !!readOnly, onSaved, text: null, deck: null, i: 0, sel: null, editing: null, drag: null, hist: [], fut: [], dirty: false, msg: '', busy: false, pop: null, root: null };
152
+ OPEN.set(path, S);
153
+ const el = vwOpen({ id: 'slides:' + path, title: S.title + ' slides', icon: 'doc', html: '<p class="note">Reading the slides.</p>' });
154
+ S.root = el;
155
+ try {
156
+ const r = await fetch('/api/doc?' + new URLSearchParams({ ...(S.ws ? { ws: S.ws } : {}), path }).toString(), { credentials: 'same-origin' });
157
+ const t = await r.text();
158
+ if (!r.ok) throw new Error(t || 'not found');
159
+ S.text = t;
160
+ } catch (x) { el.innerHTML = `<p class="note">The slides could not be read: ${esc(String((x && x.message) || x))}</p>`; return S; }
161
+ load(S, S.text);
162
+ build(S);
163
+ return S;
164
+ }
165
+ function load(S, text) {
166
+ const d = D.parseDeck(text, S.title);
167
+ d.slides.forEach((s) => s.els.forEach((e) => { e.id = nid(); }));
168
+ S.deck = d; S.i = Math.min(S.i, d.slides.length - 1); S.sel = null; S.editing = null; S.hist = []; S.fut = []; S.dirty = false;
169
+ const ch = d.slides.map((s, k) => (s.changed ? k + 1 : 0)).filter(Boolean);
170
+ S.msg = ch.length ? `The text of slide ${ch.join(', ')} was changed in the file outside the editor, so it now shows the file's text. Its layout is kept.` : (!d.blocks && !S.ro ? 'This document has no slide layout yet. It is shown as a title slide and one slide for each section. Saving adds the layout to the file.' : '');
171
+ }
172
+
173
+ function build(S) {
174
+ const el = S.root, ro = S.ro;
175
+ el.innerHTML = `<div class="sl${ro ? ' ro' : ''}" data-sl>`
176
+ + `<div class="sl-tb" role="toolbar" aria-label="Slides">`
177
+ + (ro ? '' : `${tb('undo', 'Undo', 'undo', ' disabled')}${tb('redo', 'Redo', 'redo', ' disabled')}<span class="sl-sep"></span>${tbl('text', 'Text', 'txt')}${tbl('img', 'Image', 'img')}${tbl('chart', 'Chart', 'chart')}${tbl('table', 'Table', 'tbl')}${tbl('shape', 'Shape', 'shape')}<span class="sl-sep"></span>${tbl('layout', 'Layout', 'lay', ' aria-haspopup="menu"')}${tbl('theme', 'Theme', 'pal', ' aria-haspopup="menu"')}`)
178
+ + `<span class="sl-gap"></span>${tbl('present', 'Present', 'play')}${ro ? '' : `<button type="button" class="sl-b sl-pri" data-c="save">${I('save')}<span>Save</span></button>`}</div>`
179
+ + (ro ? '' : '<div class="sl-ctx" role="toolbar" aria-label="Change the selected item"></div>')
180
+ + `<p class="sl-msg" role="status"></p>`
181
+ + `<div class="sl-body"><nav class="sl-rail" aria-label="Slides"></nav><div class="sl-main"><div class="sl-stage" tabindex="0" aria-label="Slide"></div>`
182
+ + `<label class="sl-notes"><span>Speaker notes</span><textarea rows="3" placeholder="${ro ? 'No notes' : 'What you will say on this slide. Only you see it.'}"${ro ? ' readonly' : ''}></textarea></label></div></div></div>`;
183
+ const $ = (s) => el.querySelector(s);
184
+ S.$ = $;
185
+ const stage = $('.sl-stage'), rail = $('.sl-rail'), notes = $('.sl-notes textarea'), top = $('.sl-tb'), ctx = $('.sl-ctx');
186
+ if (S.ro_obs) S.ro_obs.disconnect();
187
+ S.ro_obs = new ResizeObserver(() => { fit(stage); rail.querySelectorAll('.sl-mini').forEach(fit); });
188
+ S.ro_obs.observe(stage); S.ro_obs.observe(rail);
189
+ drawAll(S);
190
+
191
+ top.onmousedown = (e) => { if (e.target.closest('.sl-b')) e.preventDefault(); };
192
+ top.onclick = (e) => { const b = e.target.closest('[data-c]'); if (b && !b.disabled) onTop(S, b.dataset.c, b); };
193
+ if (ctx) { ctx.onmousedown = (e) => { if (e.target.closest('button')) e.preventDefault(); }; ctx.onclick = (e) => { const b = e.target.closest('[data-c]'); if (b) onCtx(S, b.dataset.c, b.dataset.v, b); }; }
194
+ rail.onclick = (e) => onRail(S, e);
195
+ if (!ro) {
196
+ stage.onpointerdown = (e) => onDown(S, e);
197
+ stage.onpointermove = (e) => onMove(S, e);
198
+ stage.onpointerup = stage.onpointercancel = () => endDrag(S);
199
+ stage.ondblclick = () => { const it = S.sel && find(S, S.sel); if (!it) return; if (it.t === 'text' || it.t === 'table') startEdit(S, it.id); else if (it.t === 'img') pickImg(S, it); else if (it.t === 'chart') editData(S, it); };
200
+ stage.oninput = () => { const it = S.editing && find(S, S.editing), n = it && node(S, it.id); if (n && it.t === 'text') { it.html = D.cleanHtml(n.querySelector('.sl-tx').innerHTML); S.dirty = true; drawThumb(S, S.i); } };
201
+ stage.addEventListener('focusout', (e) => { if (S.editing && !(e.relatedTarget && stage.contains(e.relatedTarget))) setTimeout(() => { if (S.editing && !stage.contains(document.activeElement)) commitEdit(S); }, 0); });
202
+ notes.oninput = () => { cur(S).notes = notes.value.slice(0, 4000); S.dirty = true; drawBar(S); };
203
+ notes.onfocus = () => snap(S);
204
+ let from = null;
205
+ rail.ondragstart = (e) => { const t = e.target.closest('.sl-th'); if (!t) return; from = +t.dataset.k; t.classList.add('drag'); e.dataTransfer.effectAllowed = 'move'; };
206
+ rail.ondragover = (e) => { const t = e.target.closest('.sl-th'); if (from == null || !t) return; e.preventDefault(); rail.querySelectorAll('.sl-th').forEach((x) => x.classList.toggle('over', x === t)); };
207
+ rail.ondrop = (e) => { const t = e.target.closest('.sl-th'); if (from == null || !t) return; e.preventDefault(); move(S, from, +t.dataset.k); from = null; };
208
+ rail.ondragend = () => { from = null; rail.querySelectorAll('.sl-th').forEach((x) => x.classList.remove('over', 'drag')); };
209
+ }
210
+ el.onkeydown = (e) => onKey(S, e);
211
+ }
212
+
213
+ const cur = (S) => S.deck.slides[S.i];
214
+ const find = (S, id) => cur(S).els.find((e) => e.id === id);
215
+ const node = (S, id) => S.root.querySelector(`.sl-stage .sl-it[data-id="${CSS.escape(id)}"]`);
216
+ function snap(S) { S.hist.push(JSON.stringify({ theme: S.deck.theme, slides: S.deck.slides })); if (S.hist.length > 80) S.hist.shift(); S.fut.length = 0; S.dirty = true; }
217
+ function restore(S, s) { const o = JSON.parse(s); S.deck.theme = o.theme; S.deck.slides = o.slides; S.i = Math.min(S.i, S.deck.slides.length - 1); S.sel = null; S.editing = null; delete S.$('.sl-stage').dataset.escLayer; drawAll(S); }
218
+ function undo(S) { commitEdit(S); if (!S.hist.length) return toast('Nothing to undo'); S.fut.push(JSON.stringify({ theme: S.deck.theme, slides: S.deck.slides })); restore(S, S.hist.pop()); }
219
+ function redo(S) { commitEdit(S); if (!S.fut.length) return; S.hist.push(JSON.stringify({ theme: S.deck.theme, slides: S.deck.slides })); restore(S, S.fut.pop()); }
220
+
221
+ function drawAll(S) { drawRail(S); drawStage(S); drawCtx(S); drawBar(S); const n = S.$('.sl-notes textarea'); if (n) n.value = cur(S).notes || ''; }
222
+ function drawBar(S) {
223
+ const u = S.$('[data-c="undo"]'), r = S.$('[data-c="redo"]'), m = S.$('.sl-msg'), sv = S.$('[data-c="save"]');
224
+ if (u) u.disabled = !S.hist.length; if (r) r.disabled = !S.fut.length;
225
+ if (sv) { sv.disabled = S.busy; sv.classList.toggle('on', S.dirty); }
226
+ if (m) { m.textContent = S.ro ? 'This report is issued, so its slides are read-only.' + (S.msg ? ' ' + S.msg : '') : S.msg; m.hidden = !m.textContent; }
227
+ }
228
+ function drawRail(S) {
229
+ const rail = S.$('.sl-rail'), n = S.deck.slides.length;
230
+ rail.innerHTML = S.deck.slides.map((s, k) => `<div class="sl-th" draggable="${!S.ro}" data-k="${k}" aria-current="${k === S.i}"><i class="sl-num">${k + 1}</i>`
231
+ + `<button type="button" class="sl-mini" data-go="${k}" aria-label="Slide ${k + 1}: ${esc(railName(s, k))}">${slideHtml(s, S.deck.theme, S.ws, false)}</button>`
232
+ + (S.ro ? '' : `<span class="sl-tha"><button type="button" class="sl-b" data-up="${k}" aria-label="Move slide ${k + 1} up" title="Move up"${k === 0 ? ' disabled' : ''}>${I('up')}</button><button type="button" class="sl-b" data-dn="${k}" aria-label="Move slide ${k + 1} down" title="Move down"${k === n - 1 ? ' disabled' : ''}>${I('down')}</button><button type="button" class="sl-b" data-dup="${k}" aria-label="Duplicate slide ${k + 1}" title="Duplicate">${I('dup')}</button><button type="button" class="sl-b" data-del="${k}" aria-label="Delete slide ${k + 1}" title="Delete"${n < 2 ? ' disabled' : ''}>${I('trash')}</button></span>`)
233
+ + '</div>').join('') + (S.ro ? '' : `<button type="button" class="sl-b sl-add" data-add aria-haspopup="menu">${I('plus')}<span>Slide</span></button>`);
234
+ rail.querySelectorAll('.sl-mini').forEach((m) => { fit(m); place(m); });
235
+ }
236
+ function drawThumb(S, k) { const m = S.$(`.sl-mini[data-go="${k}"]`); if (m) { m.innerHTML = slideHtml(S.deck.slides[k], S.deck.theme, S.ws, false); fit(m); place(m); } }
237
+ const railName = (s, k) => { const t = s.els.find((e) => e.t === 'text' && e.k === 'title') || s.els.find((e) => e.t === 'text'); return (t && t.html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 60)) || 'Slide ' + (k + 1); };
238
+ function drawStage(S) {
239
+ const st = S.$('.sl-stage');
240
+ st.innerHTML = slideHtml(cur(S), S.deck.theme, S.ws, !S.ro);
241
+ fit(st); place(st);
242
+ if (S.sel) { const n = node(S, S.sel); if (n) n.classList.add('sel'); else S.sel = null; }
243
+ }
244
+ const ROLE_NAME = (r) => (D.ROLES.find((x) => x[0] === r) || D.ROLES[2])[1];
245
+ function drawCtx(S) {
246
+ const ctx = S.$('.sl-ctx'); if (!ctx) return;
247
+ const it = S.sel && find(S, S.sel); let h = '';
248
+ if (!it) h = `<span class="sl-hint">Slide ${S.i + 1} of ${S.deck.slides.length}. Click an item to change it. Double-click text to type.</span>`;
249
+ else if (it.t === 'text') h = `<button type="button" class="sl-b sl-bl" data-c="role" aria-haspopup="menu"><span>${esc(ROLE_NAME(it.role))}</span></button><span class="sl-sep"></span>`
250
+ + `<button type="button" class="sl-b" data-c="bold" aria-label="Bold" title="Bold"><b>B</b></button><button type="button" class="sl-b" data-c="italic" aria-label="Italic" title="Italic"><i>I</i></button><button type="button" class="sl-b" data-c="underline" aria-label="Underline" title="Underline"><u>U</u></button>${tb('list', 'Bulleted list', 'ul')}<span class="sl-sep"></span>`
251
+ + ['left', 'center', 'right'].map((a) => tb('al', 'Align ' + a, 'a' + a[0], ` data-v="${a}" aria-pressed="${(it.align || 'left') === a}"`)).join('') + '<span class="sl-sep"></span>'
252
+ + D.COLORS.map((c) => `<button type="button" class="sl-sw c-${c[0] || 'fg'}" data-c="col" data-v="${c[0]}" aria-label="${c[1]}" title="${c[1]}" aria-pressed="${(it.color || '') === c[0]}"></button>`).join('');
253
+ else if (it.t === 'chart') h = `<span class="sl-seg"><button type="button" data-c="kind" data-v="bar" aria-pressed="${it.kind !== 'line'}">Bars</button><button type="button" data-c="kind" data-v="line" aria-pressed="${it.kind === 'line'}">Line</button></span>${tbl('data', 'Edit data', 'tbl')}`;
254
+ else if (it.t === 'table') h = `<button type="button" class="sl-b sl-bl" data-c="r+">Add row</button><button type="button" class="sl-b sl-bl" data-c="c+">Add column</button><button type="button" class="sl-b sl-bl" data-c="r-"${it.rows.length < 3 ? ' disabled' : ''}>Remove row</button><button type="button" class="sl-b sl-bl" data-c="c-"${it.rows[0].length < 2 ? ' disabled' : ''}>Remove column</button>`;
255
+ else if (it.t === 'img') h = tbl('pick', it.src ? 'Change image' : 'Choose image', 'img');
256
+ else h = D.FILLS.map((c) => `<button type="button" class="sl-sw f-${c[0]}" data-c="fill" data-v="${c[0]}" aria-label="${c[1]}" title="${c[1]}" aria-pressed="${(it.fill || 'acc') === c[0]}"></button>`).join('') + `<button type="button" class="sl-b sl-bl" data-c="round" aria-pressed="${!!it.round}">Round</button>`;
257
+ if (it) h += `<span class="sl-gap"></span>${tb('front', 'Bring to front', 'front')}${tb('back', 'Send to back', 'back')}${tb('dup', 'Duplicate', 'dup')}${tb('del', 'Delete', 'trash')}`;
258
+ ctx.innerHTML = h;
259
+ }
260
+ function go(S, k) { commitEdit(S); closePop(S); S.i = Math.max(0, Math.min(S.deck.slides.length - 1, k)); S.sel = null; drawAll(S); }
261
+ function select(S, id) { S.sel = id; S.root.querySelectorAll('.sl-stage .sl-it').forEach((n) => n.classList.toggle('sel', n.dataset.id === id)); drawCtx(S); }
262
+ function move(S, from, to) {
263
+ if (to === from || to < 0 || to >= S.deck.slides.length) return;
264
+ commitEdit(S); snap(S); const [s] = S.deck.slides.splice(from, 1); S.deck.slides.splice(to, 0, s); S.i = to; S.sel = null; drawAll(S);
265
+ }
266
+
267
+ function startEdit(S, id) {
268
+ const it = find(S, id); if (!it || (it.t !== 'text' && it.t !== 'table')) return;
269
+ snap(S); S.editing = id; select(S, id); const n = node(S, id); n.classList.add('editing'); S.$('.sl-stage').dataset.escLayer = '';
270
+ if (it.t === 'text') { const tx = n.querySelector('.sl-tx'); tx.contentEditable = 'true'; tx.focus(); const r = document.createRange(); r.selectNodeContents(tx); r.collapse(false); const sel = getSelection(); sel.removeAllRanges(); sel.addRange(r); }
271
+ else { n.querySelectorAll('th,td').forEach((c) => { c.contentEditable = 'true'; }); n.querySelector('th,td').focus(); }
272
+ drawBar(S);
273
+ }
274
+ function commitEdit(S) {
275
+ if (!S.editing) return; const it = find(S, S.editing), n = node(S, S.editing); S.editing = null; delete S.$('.sl-stage').dataset.escLayer;
276
+ if (it && n) {
277
+ if (it.t === 'text') it.html = D.cleanHtml(n.querySelector('.sl-tx').innerHTML);
278
+ else it.rows = [...n.querySelectorAll('tr')].map((tr) => [...tr.children].map((c) => D.cleanHtml(c.innerHTML, true)));
279
+ n.classList.remove('editing'); n.querySelectorAll('[contenteditable]').forEach((c) => c.removeAttribute('contenteditable'));
280
+ }
281
+ drawThumb(S, S.i);
282
+ }
283
+ function addEl(S, e) { commitEdit(S); snap(S); e.id = nid(); cur(S).els.push(e); drawStage(S); drawThumb(S, S.i); select(S, e.id); drawBar(S); return e; }
284
+ function dupEl(S) { const it = find(S, S.sel); if (!it) return; const c = JSON.parse(JSON.stringify(it)); delete c.k; c.x += 24; c.y += 24; addEl(S, c); }
285
+ function delEl(S) { if (!S.sel) return; snap(S); cur(S).els = cur(S).els.filter((e) => e.id !== S.sel); S.sel = null; drawStage(S); drawThumb(S, S.i); drawCtx(S); drawBar(S); }
286
+ function applyLayout(S, l) {
287
+ commitEdit(S); snap(S); const c = {};
288
+ cur(S).els.forEach((e) => { if (e.k === 'chart') c.chart = e; else if (e.k === 'img') c.img = e; else if (e.k && e.t === 'text') c[e.k] = e.html; });
289
+ if (l === 'big' && c.title && !c.big) c.big = c.title;
290
+ cur(S).els = D.mkLayout(l, c).map((e) => ({ ...e, id: nid() })).concat(cur(S).els.filter((e) => !e.k));
291
+ cur(S).l = l; S.sel = null; drawAll(S);
292
+ }
293
+
294
+ /* ── small menus inside the view ── */
295
+ function closePop(S) { if (S.pop) { S.pop.remove(); S.pop = null; } }
296
+ function pop(S, anchor, html) {
297
+ closePop(S);
298
+ const p = document.createElement('div'); p.className = 'sl-pop'; p.dataset.escLayer = ''; p.innerHTML = html;
299
+ const root = S.root.querySelector('.sl'), a = anchor.getBoundingClientRect(), r = root.getBoundingClientRect();
300
+ root.append(p);
301
+ const left = Math.max(0, Math.min(a.left - r.left, r.width - p.offsetWidth));
302
+ p.style.setProperty('--bd-px', left + 'px'); p.style.setProperty('--bd-py', (a.bottom - r.top + 6) + 'px');
303
+ S.pop = p;
304
+ const f = p.querySelector('input,button'); if (f) f.focus();
305
+ p.onkeydown = (e) => { if (e.key === 'Escape') { e.stopPropagation(); closePop(S); anchor.focus(); } };
306
+ return p;
307
+ }
308
+ function menu(S, anchor, items, onPick) {
309
+ const p = pop(S, anchor, `<div role="menu">${items.map((x) => `<button type="button" role="menuitem" data-pick="${esc(x[0])}"${x[2] ? ' aria-current="true"' : ''}>${esc(x[1])}</button>`).join('')}</div>`);
310
+ p.onclick = (e) => { const b = e.target.closest('[data-pick]'); if (!b) return; closePop(S); onPick(b.dataset.pick); };
311
+ }
312
+ function editData(S, it) {
313
+ const anchor = S.$('[data-c="data"]') || S.$('.sl-stage');
314
+ snap(S);
315
+ const grid = () => `<p class="sl-ph2">Chart data</p><div class="sl-grid">${it.data.map((d, k) => `<input data-r="${k}" data-i="0" value="${esc(d[0])}" maxlength="40" aria-label="Label ${k + 1}"><input data-r="${k}" data-i="1" type="number" step="any" value="${esc(d[1])}" aria-label="Value ${k + 1}"><button type="button" class="sl-b" data-x="${k}" aria-label="Remove row ${k + 1}"${it.data.length < 2 ? ' disabled' : ''}>${I('x')}</button>`).join('')}</div><button type="button" class="sl-b sl-bl" data-addrow${it.data.length >= 24 ? ' disabled' : ''}>${I('plus')}<span>Add a row</span></button>`;
316
+ const p = pop(S, anchor, grid());
317
+ const live = () => { const n = node(S, it.id); if (n) { n.querySelector('svg').outerHTML = chartSvg(it); } drawThumb(S, S.i); };
318
+ p.oninput = (e) => { const t = e.target; if (t.dataset.r == null) return; it.data[+t.dataset.r][+t.dataset.i] = t.dataset.i === '1' ? (Number.isFinite(+t.value) ? +t.value : 0) : t.value.slice(0, 40); live(); };
319
+ p.onclick = (e) => { const x = e.target.closest('[data-x]'), a = e.target.closest('[data-addrow]'); if (x && !x.disabled) it.data.splice(+x.dataset.x, 1); else if (a && !a.disabled) it.data.push(['', 0]); else return; p.innerHTML = grid(); live(); };
320
+ }
321
+ function pickImg(S, it) {
322
+ const anchor = S.$('[data-c="pick"]') || S.$('.sl-stage');
323
+ const p = pop(S, anchor, `<form class="sl-imgf"><label><span>An image file in this workspace</span><input name="src" placeholder="planning/design/screen.png" value="${esc(it.src || '')}" autocomplete="off" spellcheck="false"></label><label><span>Describe it for someone who cannot see it</span><input name="alt" value="${esc(it.alt || '')}" maxlength="200" autocomplete="off"></label><p class="sl-err" hidden></p><div class="sl-row"><button type="submit" class="sl-b sl-pri">Use this image</button><button type="button" class="sl-b sl-bl" data-cancel>Cancel</button></div></form>`);
324
+ const f = p.querySelector('form');
325
+ p.onclick = (e) => { if (e.target.closest('[data-cancel]')) closePop(S); };
326
+ f.onsubmit = (e) => {
327
+ e.preventDefault();
328
+ const src = f.elements.namedItem('src').value.trim().replace(/^\.?\//, ''), err = p.querySelector('.sl-err');
329
+ if (!D.okSrc(src)) { err.hidden = false; err.textContent = 'Give the path of an image file inside the workspace, such as planning/design/screen.png.'; return; }
330
+ snap(S); it.src = src; it.alt = f.elements.namedItem('alt').value.trim().slice(0, 200); closePop(S); drawStage(S); drawThumb(S, S.i); select(S, it.id); drawCtx(S); drawBar(S);
331
+ };
332
+ }
333
+
334
+ /* ── presses ── */
335
+ function onTop(S, c, b) {
336
+ if (c === 'present') {
337
+ commitEdit(S); closePop(S);
338
+ S.pres = present(S.deck, S.ws, S.i, { ro: S.ro, onNotes: (i, v, first) => { if (first) snap(S); S.deck.slides[i].notes = v; S.dirty = true; drawBar(S); }, onEnd: (i) => { S.pres = null; go(S, i); } });
339
+ return;
340
+ }
341
+ if (S.ro) return;
342
+ if (c === 'undo') return undo(S);
343
+ if (c === 'redo') return redo(S);
344
+ if (c === 'text') { const n = addEl(S, { t: 'text', role: 'body', x: 300, y: 220, w: 360, h: 90, html: '', align: 'left' }); return startEdit(S, n.id); }
345
+ if (c === 'img') { const n = addEl(S, { t: 'img', x: 280, y: 140, w: 400, h: 260, src: '', alt: '' }); return pickImg(S, n); }
346
+ if (c === 'chart') { const n = addEl(S, { t: 'chart', x: 220, y: 130, w: 520, h: 300, kind: 'bar', data: [['', 0]] }); return editData(S, n); }
347
+ if (c === 'table') return addEl(S, { t: 'table', x: 160, y: 170, w: 640, h: 190, rows: [['', '', ''], ['', '', ''], ['', '', '']] });
348
+ if (c === 'shape') return addEl(S, { t: 'shape', x: 400, y: 190, w: 160, h: 160, fill: 'acc' });
349
+ if (c === 'layout') return menu(S, b, D.LAYOUTS.map((l) => [l[0], l[1], cur(S).l === l[0]]), (k) => applyLayout(S, k));
350
+ if (c === 'theme') return menu(S, b, D.THEMES.map((t) => [t[0], t[1], S.deck.theme === t[0]]), (k) => { commitEdit(S); snap(S); S.deck.theme = k; drawAll(S); });
351
+ if (c === 'save') return askSave(S, b);
352
+ }
353
+ function onCtx(S, c, v, b) {
354
+ const it = S.sel && find(S, S.sel); if (!it) return;
355
+ if (['bold', 'italic', 'underline', 'list'].includes(c)) { if (S.editing !== it.id) startEdit(S, it.id); document.execCommand(c === 'list' ? 'insertUnorderedList' : c); const n = node(S, it.id); if (n) it.html = D.cleanHtml(n.querySelector('.sl-tx').innerHTML); return; }
356
+ if (c === 'role') return menu(S, b, D.ROLES.map((x) => [x[0], x[1], it.role === x[0]]), (k) => { commitEdit(S); snap(S); it.role = k; redrawSel(S); });
357
+ if (c === 'data') return editData(S, it);
358
+ if (c === 'pick') return pickImg(S, it);
359
+ if (c === 'dup') return dupEl(S);
360
+ if (c === 'del') return delEl(S);
361
+ if (b.disabled) return;
362
+ commitEdit(S); snap(S);
363
+ if (c === 'al') it.align = v;
364
+ if (c === 'col') { if (v) it.color = v; else delete it.color; }
365
+ if (c === 'kind') it.kind = v;
366
+ if (c === 'fill') it.fill = v;
367
+ if (c === 'round') it.round = !it.round;
368
+ if (c === 'front' || c === 'back') { const a = cur(S).els.filter((x) => x !== it); cur(S).els = c === 'front' ? [...a, it] : [it, ...a]; }
369
+ if (c === 'r+' && it.rows.length < 12) it.rows.push(it.rows[0].map(() => ''));
370
+ if (c === 'c+' && it.rows[0].length < 8) it.rows.forEach((r) => r.push(''));
371
+ if (c === 'r-' && it.rows.length > 2) it.rows.pop();
372
+ if (c === 'c-' && it.rows[0].length > 1) it.rows.forEach((r) => r.pop());
373
+ redrawSel(S);
374
+ }
375
+ function redrawSel(S) { drawStage(S); drawThumb(S, S.i); drawCtx(S); drawBar(S); }
376
+ function onRail(S, e) {
377
+ const t = (s) => e.target.closest(s);
378
+ if (t('[data-go]')) return go(S, +t('[data-go]').dataset.go);
379
+ if (S.ro) return;
380
+ if (t('[data-up]')) return move(S, +t('[data-up]').dataset.up, +t('[data-up]').dataset.up - 1);
381
+ if (t('[data-dn]')) return move(S, +t('[data-dn]').dataset.dn, +t('[data-dn]').dataset.dn + 1);
382
+ if (t('[data-dup]')) { commitEdit(S); snap(S); const k = +t('[data-dup]').dataset.dup, c = JSON.parse(JSON.stringify(S.deck.slides[k])); delete c.h1; delete c.changed; c.els.forEach((x) => { x.id = nid(); }); S.deck.slides.splice(k + 1, 0, c); return go(S, k + 1); }
383
+ if (t('[data-del]')) {
384
+ const k = +t('[data-del]').dataset.del; if (S.deck.slides.length < 2) return;
385
+ commitEdit(S); snap(S); S.deck.slides.splice(k, 1); toast(`Slide ${k + 1} deleted. Undo puts it back.`); return go(S, Math.min(S.i, S.deck.slides.length - 1));
386
+ }
387
+ if (t('[data-add]')) return menu(S, t('[data-add]'), D.LAYOUTS.map((l) => [l[0], l[1]]), (k) => { commitEdit(S); snap(S); S.deck.slides.splice(S.i + 1, 0, { l: k, notes: '', els: D.mkLayout(k).map((x) => ({ ...x, id: nid() })) }); go(S, S.i + 1); });
388
+ }
389
+ const K = (S) => (S.$('.sl-stage').clientWidth || D.W) / D.W;
390
+ function onDown(S, e) {
391
+ const st = S.$('.sl-stage'), se = e.target.closest('.sl-it');
392
+ if (se && se.classList.contains('editing')) return;
393
+ if (S.editing) commitEdit(S);
394
+ closePop(S);
395
+ if (!se) { select(S, null); return; }
396
+ const it = find(S, se.dataset.id); if (!it) return;
397
+ select(S, it.id); const hd = e.target.closest('.sl-hdot');
398
+ S.drag = { id: it.id, h: hd ? hd.dataset.h : null, x0: e.clientX, y0: e.clientY, o: { x: it.x, y: it.y, w: it.w, h: it.h }, moved: false, pid: e.pointerId, st };
399
+ e.preventDefault(); st.focus({ preventScroll: true });
400
+ }
401
+ function onMove(S, e) {
402
+ const g = S.drag; if (!g) return;
403
+ const k = K(S), dx = (e.clientX - g.x0) / k, dy = (e.clientY - g.y0) / k;
404
+ if (!g.moved) { if (Math.abs(dx) + Math.abs(dy) < 3) return; snap(S); g.moved = true; try { g.st.setPointerCapture(g.pid); } catch { /* the pointer is gone */ } }
405
+ const it = find(S, g.id), o = g.o, h = g.h;
406
+ if (!h) {
407
+ let x = Math.round(o.x + dx), y = Math.round(o.y + dy);
408
+ const sv = Math.abs(x + o.w / 2 - D.W / 2) < 10, sh = Math.abs(y + o.h / 2 - D.H / 2) < 10;
409
+ if (sv) x = Math.round(D.W / 2 - o.w / 2); if (sh) y = Math.round(D.H / 2 - o.h / 2);
410
+ it.x = x; it.y = y; g.st.querySelector('.gv').classList.toggle('on', sv); g.st.querySelector('.gh').classList.toggle('on', sh);
411
+ } else {
412
+ let { x, y, w } = o, hh = o.h;
413
+ if (h.includes('e')) w = Math.max(40, o.w + dx); if (h.includes('s')) hh = Math.max(30, o.h + dy);
414
+ if (h.includes('w')) { w = Math.max(40, o.w - dx); x = o.x + o.w - w; } if (h.includes('n')) { hh = Math.max(30, o.h - dy); y = o.y + o.h - hh; }
415
+ Object.assign(it, { x: Math.round(x), y: Math.round(y), w: Math.round(w), h: Math.round(hh) });
416
+ }
417
+ const n = node(S, it.id); n.dataset.g = `${it.x},${it.y},${it.w},${it.h}`; place(n.parentElement);
418
+ if (h && it.t === 'chart') n.querySelector('svg').outerHTML = chartSvg(it);
419
+ }
420
+ function endDrag(S) { const g = S.drag; if (!g) return; S.drag = null; g.st.querySelectorAll('.sl-guide').forEach((x) => x.classList.remove('on')); if (g.moved) { drawThumb(S, S.i); drawBar(S); } }
421
+ function onKey(S, e) {
422
+ if (S.ro) return;
423
+ if (e.target.isContentEditable) { if (e.key === 'Escape') { e.preventDefault(); const id = S.editing; commitEdit(S); select(S, id); S.$('.sl-stage').focus(); } return; }
424
+ if (/^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName) || S.pop) return;
425
+ const mod = e.metaKey || e.ctrlKey;
426
+ if (mod && (e.key === 'z' || e.key === 'Z')) { e.preventDefault(); return e.shiftKey ? redo(S) : undo(S); }
427
+ if (mod && e.key === 'y') { e.preventDefault(); return redo(S); }
428
+ if (!e.target.closest('.sl-stage')) return;
429
+ if (mod && e.key === 'd' && S.sel) { e.preventDefault(); return dupEl(S); }
430
+ const it = S.sel && find(S, S.sel);
431
+ if (!it) { if (e.key === 'ArrowRight' || e.key === 'ArrowDown') { e.preventDefault(); go(S, S.i + 1); } if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') { e.preventDefault(); go(S, S.i - 1); } if (e.key === 'Tab' && !e.shiftKey && cur(S).els.length) { e.preventDefault(); select(S, cur(S).els[0].id); } return; }
432
+ if (e.key === 'Delete' || e.key === 'Backspace') { e.preventDefault(); return delEl(S); }
433
+ if (e.key === 'Enter') { e.preventDefault(); if (it.t === 'text' || it.t === 'table') return startEdit(S, it.id); if (it.t === 'img') return pickImg(S, it); if (it.t === 'chart') return editData(S, it); return; }
434
+ if (e.key === 'Escape') { e.preventDefault(); return select(S, null); }
435
+ if (e.key === 'Tab') { const L = cur(S).els, k = L.indexOf(it), n = k + (e.shiftKey ? -1 : 1); if (n >= 0 && n < L.length) { e.preventDefault(); select(S, L[n].id); } return; }
436
+ const d = e.shiftKey ? 10 : 1, mv = { ArrowLeft: [-d, 0], ArrowRight: [d, 0], ArrowUp: [0, -d], ArrowDown: [0, d] }[e.key];
437
+ if (mv) { e.preventDefault(); snap(S); it.x += mv[0]; it.y += mv[1]; const n = node(S, it.id); n.dataset.g = `${it.x},${it.y},${it.w},${it.h}`; place(n.parentElement); drawThumb(S, S.i); drawBar(S); }
438
+ }
439
+
440
+ /* ── Save: a why, then one write through the document sheet's edit route ── */
441
+ function askSave(S, b) {
442
+ commitEdit(S);
443
+ if (!S.dirty) { toast('Nothing has changed since the slides were opened.'); return; }
444
+ const n = S.deck.slides.length;
445
+ const p = pop(S, b, `<form class="sl-imgf sl-savef"><p class="sl-ph2">Save ${n} slide${n === 1 ? '' : 's'} to ${esc(S.path)}?</p><label><span>Why it changes (kept in the Edit log)</span><input name="why" value="Edited the slides" maxlength="300" autocomplete="off"></label><p class="sl-err" hidden></p><div class="sl-row"><button type="submit" class="sl-b sl-pri">Save</button><button type="button" class="sl-b sl-bl" data-cancel>Cancel</button></div></form>`);
446
+ const f = p.querySelector('form'), err = p.querySelector('.sl-err');
447
+ p.onclick = (e) => { if (e.target.closest('[data-cancel]')) closePop(S); };
448
+ f.onsubmit = async (e) => {
449
+ e.preventDefault();
450
+ const why = f.elements.namedItem('why').value.trim(); if (!why) { err.hidden = false; err.textContent = 'Say in a few words why the slides change.'; return; }
451
+ const r = await save(S, why);
452
+ if (!r.ok) { err.hidden = false; err.textContent = r.error; return; }
453
+ closePop(S);
454
+ };
455
+ }
456
+ async function save(S, why) {
457
+ if (S.busy) return { ok: false, error: 'A save is already running.' };
458
+ S.busy = true; drawBar(S);
459
+ try {
460
+ const now = await fetch('/api/doc?' + new URLSearchParams({ ...(S.ws ? { ws: S.ws } : {}), path: S.path }).toString(), { credentials: 'same-origin' }).then((r) => (r.ok ? r.text() : null)).catch(() => null);
461
+ if (now != null && now !== S.text) return { ok: false, error: 'The file changed since the slides were opened. Close this tab and open the slides again to see the new version. Your changes are still here until you close it.' };
462
+ const text = D.writeDeck(S.deck);
463
+ const res = await pmPost('/api/doc-sheet/edit' + (S.ws ? '?ws=' + encodeURIComponent(S.ws) : ''), { path: S.path, text, why }).catch((x) => ({ ok: false, error: String((x && x.message) || x) }));
464
+ if (!res || res.ok !== true) return { ok: false, error: (res && res.error) || 'The slides could not be saved.' };
465
+ S.text = text; S.dirty = false; S.msg = '';
466
+ toast('Saved. The reason is in the Edit log.');
467
+ if (typeof S.onSaved === 'function') { try { S.onSaved(text); } catch (x) { console.error(x); } }
468
+ return { ok: true };
469
+ } finally { S.busy = false; drawBar(S); }
470
+ }
471
+
472
+ if (typeof window !== 'undefined') window.__premiumSlides = { openSlides, state: (path) => OPEN.get(path) || null, save, present, parse: D.parseDeck, write: D.writeDeck };
@@ -6,6 +6,7 @@ import { pmPost, pmGet } from './http.js';
6
6
  import { startAgent } from './page-agent.js';
7
7
  import { mountMeeting } from './premium-meeting.js';
8
8
  import { mountCalEntry } from './premium-vw-cal.js';
9
+ import { mountNotes } from './premium-vw-notes.js';
9
10
  import { mountFirst } from './premium-first.js';
10
11
  import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
11
12
  import { consoleReads, briefOf, needsListOf } from './premium-brief.js';
@@ -25,6 +26,7 @@ const pinned = new Set();
25
26
  wireRail('brief');
26
27
  const week = mountMeeting({ $, $$, esc, openDlg, toast, pmGet, pmPost, turnA, ptx, kv, H, ws: () => new URLSearchParams(location.search).get('ws'), redraw: () => { if (M) drawTl(); } });
27
28
  mountCalEntry($('#todayCard'), { $, esc, openDlg, turnA, ptx, pmGet, ws: () => new URLSearchParams(location.search).get('ws'), openRow: week.openRow }); // the full calendar: Day, Week and Month in the viewer
29
+ mountNotes({ $, esc, openDlg, toast, pmGet, pmPost, task: week.task });
28
30
 
29
31
  /* ── a day's baseline, kept on this device, so "N of M done" counts rows that cleared since the page first read today ────── */
30
32
  const dayKey = () => { const d = new Date(); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "_comment": "Initiative premium-viewer: the premium dialog's right pane as a viewer with tabs (S1, the frame the view slices build on).",
3
3
  "panels": [
4
- "premium-viewer-test.js"
4
+ "premium-viewer-test.js",
5
+ "premium-vw-slides-test.js"
5
6
  ],
6
7
  "seconds": {
7
- "premium-viewer-test.js": 60
8
- }
8
+ "premium-viewer-test.js": 60,
9
+ "premium-vw-slides.test.js": 1,
10
+ "premium-vw-slides-test.js": 60
11
+ },
12
+ "modules": [
13
+ "premium-vw-slides.test.js"
14
+ ]
9
15
  }
@@ -0,0 +1,13 @@
1
+ {
2
+ "_comment": "Initiative premium-viewer S7: an initiative and its tasks as tabs of the premium dialog viewer (PRD R9).",
3
+ "modules": [
4
+ "premium-vw-item.test.js"
5
+ ],
6
+ "panels": [
7
+ "premium-vw-item-test.js"
8
+ ],
9
+ "seconds": {
10
+ "premium-vw-item.test.js": 1,
11
+ "premium-vw-item-test.js": 45
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "_comment": "Initiative premium-viewer, slice S3: the meeting detail laid out as the console's note sheet (Before, During, After) in the premium meeting dialog.",
3
+ "modules": [
4
+ "premium-vw-meet.test.js"
5
+ ],
6
+ "panels": [
7
+ "premium-vw-meet-test.js"
8
+ ],
9
+ "seconds": {
10
+ "premium-vw-meet.test.js": 2,
11
+ "premium-vw-meet-test.js": 60
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "_comment": "Initiative premium-viewer, R9: the Notes list in the premium dialog, a note opened beside it, and the note sheet's Before, During and After stages other views plug into.",
3
+ "modules": [
4
+ "premium-vw-notes.test.js"
5
+ ],
6
+ "panels": [
7
+ "premium-vw-notes-test.js"
8
+ ],
9
+ "seconds": {
10
+ "premium-vw-notes.test.js": 2,
11
+ "premium-vw-notes-test.js": 60
12
+ }
13
+ }