create-pmos 0.402.0 → 0.403.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 (103) hide show
  1. package/package.json +13 -13
  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/board-programs-test.js +6 -5
  7. package/workspace/briefing-premium-adddoc-test.js +28 -22
  8. package/workspace/briefing-premium-board-test.js +91 -73
  9. package/workspace/briefing-premium-calendar-2-test.js +23 -10
  10. package/workspace/briefing-premium-calendar-3-test.js +23 -19
  11. package/workspace/briefing-premium-calendar-test.js +19 -17
  12. package/workspace/briefing-premium-initiative-test.js +25 -12
  13. package/workspace/briefing-premium-insights-test.js +31 -18
  14. package/workspace/briefing-premium-metrics-test.js +8 -8
  15. package/workspace/briefing-premium-test.js +4 -3
  16. package/workspace/changelog.json +12 -0
  17. package/workspace/fixtures/premium-viewer-fixtures.js +24 -2
  18. package/workspace/guide/jira.md +38 -6
  19. package/workspace/home-rows-test.js +184 -0
  20. package/workspace/lib/calendar-layers.js +8 -4
  21. package/workspace/lib/initiative-layout.js +4 -3
  22. package/workspace/lib/jira-cli.js +17 -12
  23. package/workspace/lib/jira-status.js +1 -1
  24. package/workspace/lib/jira-tickets.js +126 -24
  25. package/workspace/lib/meeting-files.js +58 -0
  26. package/workspace/lib/meeting-learn.js +139 -0
  27. package/workspace/lib/meeting-material.js +12 -5
  28. package/workspace/lib/notes.js +3 -0
  29. package/workspace/lib/routes-brief-page.js +8 -1
  30. package/workspace/lib/routes-calendar-views.js +24 -3
  31. package/workspace/lib/routes-meeting-material.js +38 -0
  32. package/workspace/lib/routes-meeting-points.js +23 -3
  33. package/workspace/package-lock.json +2 -2
  34. package/workspace/package.json +1 -1
  35. package/workspace/premium-board-actions-test.js +30 -24
  36. package/workspace/premium-chat-context-test.js +1 -1
  37. package/workspace/premium-chat-goal-view-test.js +1 -1
  38. package/workspace/premium-chat-viewer-test.js +1 -1
  39. package/workspace/premium-core-doc-issue-test.js +13 -7
  40. package/workspace/premium-discuss-landing-test.js +83 -0
  41. package/workspace/premium-link-suggest-test.js +103 -0
  42. package/workspace/premium-report-read-test.js +86 -82
  43. package/workspace/premium-vw-backlog-test.js +6 -5
  44. package/workspace/premium-vw-cal-test.js +46 -23
  45. package/workspace/premium-vw-item-test.js +8 -6
  46. package/workspace/premium-vw-jira-test.js +3 -2
  47. package/workspace/premium-vw-meet-test.js +122 -66
  48. package/workspace/premium-vw-notes-test.js +7 -6
  49. package/workspace/premium-vw-rec-test.js +14 -13
  50. package/workspace/premium-vw-slides-test.js +11 -5
  51. package/workspace/program-panel-test.js +64 -55
  52. package/workspace/public/pm/bd-acts.js +1 -1
  53. package/workspace/public/pm/bd-asks.js +22 -7
  54. package/workspace/public/pm/bd-ini-panel.js +229 -0
  55. package/workspace/public/pm/bd-pop.js +2 -2
  56. package/workspace/public/pm/bd-prog-panel.js +176 -191
  57. package/workspace/public/pm/cozy-board.css +5 -28
  58. package/workspace/public/pm/cozy-evui.js +4 -2
  59. package/workspace/public/pm/cozy-home-rows.css +54 -0
  60. package/workspace/public/pm/cozy-home.css +9 -0
  61. package/workspace/public/pm/cozy-insights.css +1 -2
  62. package/workspace/public/pm/cozy-mtg-present.css +160 -0
  63. package/workspace/public/pm/cozy-panel.css +11 -34
  64. package/workspace/public/pm/cozy-rec-pill.css +12 -0
  65. package/workspace/public/pm/cozy-rec-pill.js +46 -0
  66. package/workspace/public/pm/cozy-viewer.js +307 -43
  67. package/workspace/public/pm/cozy-vw-mtg.css +96 -94
  68. package/workspace/public/pm/cozy-vw-rp.css +40 -25
  69. package/workspace/public/pm/cozy-vw-shell.css +127 -0
  70. package/workspace/public/pm/cozy-xv.css +51 -0
  71. package/workspace/public/pm/cozy-xv.js +34 -0
  72. package/workspace/public/pm/home-app.js +122 -58
  73. package/workspace/public/pm/home-chat.js +11 -2
  74. package/workspace/public/pm/home-day.js +64 -0
  75. package/workspace/public/pm/home-ini-model.js +1 -1
  76. package/workspace/public/pm/home-ini.js +197 -54
  77. package/workspace/public/pm/home-list.js +6 -14
  78. package/workspace/public/pm/home-mentions.js +187 -0
  79. package/workspace/public/pm/home-rec-row.js +67 -0
  80. package/workspace/public/pm/home-review.js +20 -10
  81. package/workspace/public/pm/home-task.js +19 -18
  82. package/workspace/public/pm/home-today.js +3 -3
  83. package/workspace/public/pm/premium-board.js +73 -235
  84. package/workspace/public/pm/premium-insights.js +118 -82
  85. package/workspace/public/pm/premium-mtg-present.js +408 -100
  86. package/workspace/public/pm/premium-mtg-replay.js +70 -10
  87. package/workspace/public/pm/premium-report-read.js +118 -63
  88. package/workspace/public/pm/premium-vw-cal.js +62 -34
  89. package/workspace/public/pm/premium-vw-mtg.js +348 -192
  90. package/workspace/public/pm/rec-state.js +63 -0
  91. package/workspace/public/pm/rp-parts.js +33 -8
  92. package/workspace/public/pm/tk-draft.js +107 -0
  93. package/workspace/public/pm/tk-model.js +134 -0
  94. package/workspace/public/pm/tk-send.js +124 -0
  95. package/workspace/public/pm/tk-tasks.css +120 -0
  96. package/workspace/public/premium-board.html +0 -1
  97. package/workspace/server.js +4 -2
  98. package/workspace/skills/jira-push.skill +3 -3
  99. package/workspace/test-lists/prd-to-jira.json +6 -0
  100. package/workspace/test-lists/viewer-home-rows.json +9 -0
  101. package/workspace/test-lists/viewer-meetings.json +9 -0
  102. package/workspace/test-lists/viewer-shell-a.json +15 -0
  103. package/workspace/tk-tasks-test.js +199 -0
@@ -1,138 +1,446 @@
1
- /* pm/premium-mtg-present.js — the presenter view of a meeting's deck (initiative premium-uncovered-features, area meetings; MtPresent.dc.html).
2
- * Focus's Material has Present on a PMOS deck. It covers the page with the presenter view:
3
- * Top the recording dot (when the note records), "<meeting> · presenting", "<deck> · slide N of M", "Audience sees: slide N" (or
4
- * "Audience sees: nothing" while blanked), Share the audience window, Stop presenting.
5
- * Left the slide, then ‹ the thumbnails › and "← → to move · B to blank the audience screen".
6
- * Right the time since you started and how long the current topic has left, a bar of the meeting's time used, the next slide, your
7
- * notes for this slide (the deck's speaker notes), and From the room: the newest open question PMOS caught, with Keep as a question.
8
- * "Only you see this window. The audience window shows the slide alone, and you share that window in the call."
9
- * The audience window is a second window of this origin that this view draws into, so the two cannot drift apart (as premium-vw-slides.js
10
- * present does). B blanks it; B again shows the slide.
11
- * DATA: the deck is the markdown file of the material (GET /api/doc, read with premium-deck.js parseDeck). The meeting's time and the topic
12
- * come from the meeting card (GET /api/meeting-focus and the agenda minutes); the question from the same answer. Keep as a question adds a
13
- * line "Question: …" to your notes on the meeting (POST /api/notes/save), the one write here, and only on a press.
14
- * presentModel(deck, i, M, now) → the view model (pure) presentHtml(V) → the view (pure)
15
- * presentDeck({ ws, path, title, meeting }) → { end, go, at, blank } */
1
+ /* pm/premium-mtg-present.js — presenting a meeting's material (Viewer kit, meetings: XvAPresent, XvAPresentDoc, XvAPresentImg, XvAPresentWeb,
2
+ * XvAPresentSwitch, XvAAudience, XvAAudienceWeb; canvas note xvPresent).
3
+ *
4
+ * ONE presenter window for every kind of material. The top bar, Stop and the side never change; only the stage and its stops do.
5
+ * Top the recording dot (when the note records), "<meeting> · presenting", the material (a button that opens the list when the
6
+ * meeting has more than one), where you are in it ("slide 3 of 6"), the clock and the topic's time, then the share spot and
7
+ * Stop: an icon (×) that says "Stop presenting (Esc)". A thin line under the bar fills with the meeting's time used.
8
+ * Stage slides one slide at a time; stops = the slides (thumbnails, ‹ ›)
9
+ * document a PMOS document or report: the page, one section lit and the rest dimmed; stops = its sections; the audience
10
+ * window follows the lit section, or your scroll when F is on
11
+ * image zoom and pan (scroll zooms, drag pans, − %, +); the audience sees your zoom
12
+ * live a link, a Google Doc or Slides, an HTML or PDF file: the page opens in the audience window itself and stays live.
13
+ * You click and type there; that window is what the call sees. The stage says so and brings it forward.
14
+ * none a PowerPoint file: PMOS cannot draw one; the stage says so and offers the file to open in its own app
15
+ * Side Next stop (the next slide drawn small, else the next stop's name), Your notes (a slide's speaker notes) and From the room
16
+ * (the newest open question PMOS caught, with + to keep it as a question). An empty card is left out.
17
+ * Foot "Only you see this window." and the keys for the kind.
18
+ * The audience window opens when Present is pressed, so pressing Present already shares: it shows the stage only (no stops, notes or
19
+ * flags) and a quiet line with the meeting and the place. PMOS cannot put a window in a call app by itself, so the share spot is the one
20
+ * action "Pick the window in Zoom’s Share" (the call app the meeting records from; "in the call" when none is known). It brings the
21
+ * audience window forward; the call app's own Share lists it as "Audience · <meeting>".
22
+ * Switching: the material name (or M) opens the list; 1–9 jump straight there; each material opens where you left it. A link pasted at the
23
+ * foot of the list is added to the meeting and shown at once. B blanks the audience window; B again shows it. Esc stops.
24
+ * DATA: a PMOS deck, document or report is the markdown file of the material (GET /api/doc); an uploaded file is GET
25
+ * /api/meeting-material/file. The meeting's time and topic come from the meeting card (getMeeting). Writes: Keep as a question
26
+ * (onKeep → POST /api/notes/save) and Add a link (onAddLink → POST /api/meeting-material), each on a press.
27
+ *
28
+ * matOf(x) → { id, title, kind, src, ws, url, sub } a meeting-material row as the presenter reads it (pure)
29
+ * docSections(md, title) → { title, sections: [{ head, blocks }] } (pure)
30
+ * presentModel(S, now) → the view model (pure) presentHtml(V) → the presenter (pure) audienceFoot(V) → text (pure)
31
+ * openAudience() → the window (call it inside the press, before anything is awaited, so the browser allows it)
32
+ * presentMaterial({ mats, start, ws, meeting, getMeeting, onKeep, onAddLink, onEnd, app, win }) → { ok, end, go, at, cur, blank }
33
+ * previewMaterial(body, item, { ws, at, onAt, onPresent }) → draws the material for the PM only (XvAMaterialPreview) */
16
34
  import * as D from './premium-deck.js';
35
+ import { parseMd, toDom } from './cozy-md.js';
17
36
 
18
37
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
19
38
  const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1) + '…' : t; };
20
39
  const pad = (n) => String(n).padStart(2, '0');
21
- const mmss = (ms) => { const s = Math.max(0, Math.floor(ms / 1000)); return pad(Math.floor(s / 60)) + ':' + pad(s % 60); };
22
- export const ONLY_YOU = 'Only you see this window. The audience window shows the slide alone, and you share that window in the call.';
23
- export const KEYS_HINT = '← → to move · B to blank the audience screen';
24
- const ICO = { prev: 'M15 6l-6 6 6 6', next: 'M9 6l6 6-6 6', plus: 'M12 5v14M5 12h14' };
40
+ export const mmss = (ms) => { const s = Math.max(0, Math.floor(ms / 1000)); return pad(Math.floor(s / 60)) + ':' + pad(s % 60); };
41
+ export const ONLY_YOU = 'Only you see this window.';
42
+ export const AUDIENCE_NAME = 'pmos-meeting-audience';
43
+ const HINT = {
44
+ slides: '← → move · B blanks the audience screen · M switches material',
45
+ doc: 'The up and down keys move the highlight · F follows your scroll · B blanks · M switches',
46
+ image: 'Scroll zooms · drag pans · the audience sees your zoom · M switches',
47
+ live: 'It stays live: click and type in the audience window; the call sees the same · M switches',
48
+ none: 'M switches material',
49
+ };
50
+ const ICO = { prev: 'M15 6l-6 6 6 6', next: 'M9 6l6 6-6 6', plus: 'M12 5v14M5 12h14', minus: 'M5 12h14', x: 'M6 6l12 12M18 6L6 18', chev: 'M7 10l5 5 5-5',
51
+ deck: 'M4 5h16v11H4zM12 16v4M8 20h8', doc: 'M7 3h7l5 5v13H7zM14 3v5h5', image: 'M4 4.5h16v15H4zM9 10a1.6 1.6 0 1 0 0-.01M20 16l-5-5-8 8',
52
+ link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1', share: 'M3 4h18v12H3zM10 8.5l4 2.5-4 2.5zM8 20h8M12 16v4', file: 'M7 3h7l5 5v13H7zM14 3v5h5' };
25
53
  const ic = (k, w = 18) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24"><path d="${ICO[k]}"/></svg>`;
54
+ const KIND_ICON = { slides: 'deck', doc: 'doc', image: 'image', live: 'link', none: 'file' };
26
55
 
27
- /** The view model. M = { title, rec, startedAt (ms), at, end (ISO), topic: { n, of, text, left (ms) } | null, question: text | '' } */
28
- export function presentModel(deck, i, M = {}, now = Date.now(), o = {}) {
29
- const n = deck.slides.length, k = Math.max(0, Math.min(n - 1, i)), s = deck.slides[k], nx = deck.slides[k + 1] || null;
30
- const head = (sl) => { const t = sl ? D.slideText(sl) : null; return t ? clip(t.head, 80) : ''; };
56
+ /** A meeting-material row (premium-vw-mtg.js meetModel material, or GET /api/meeting-material items) as the presenter reads it. */
57
+ export function matOf(x) {
58
+ const k = x.mkind || x.kind || '', title = clip(x.title || x.ref || x.url || 'Material', 120);
59
+ const file = x.file || (k === 'file' ? fileKind(x.ref) : '');
60
+ const fileUrl = k === 'file' && x.ref ? '/api/meeting-material/file?name=' + encodeURIComponent(x.ref) : '';
61
+ let kind = 'live', src = '', url = x.url || '';
62
+ if (k === 'pmos-deck') { kind = 'slides'; src = x.ref; }
63
+ else if (k === 'pmos-doc' || k === 'report') { kind = 'doc'; src = x.ref; }
64
+ else if (k === 'file') { kind = file === 'image' ? 'image' : file === 'pptx' ? 'none' : 'live'; url = fileUrl; }
65
+ const sub = { slides: 'Slides', doc: k === 'report' ? 'Report' : 'Document', image: 'Image', live: k === 'slides' ? 'Google Slides · live' : k === 'gdoc' ? 'Google Doc · live' : file === 'pdf' ? 'PDF · live' : file === 'html' ? 'HTML file · live' : 'Website · live', none: 'PowerPoint file' }[kind];
66
+ return { id: x.id || k + '|' + (x.ref || x.url || title), title, kind, src, ws: x.ws || '', url, sub, host: hostOf(url) };
67
+ }
68
+ const fileKind = (name) => { const e = (/\.([a-z0-9]+)$/i.exec(String(name || '')) || [])[1]; return !e ? '' : /^(png|jpe?g|gif|webp)$/i.test(e) ? 'image' : /^pdf$/i.test(e) ? 'pdf' : /^html?$/i.test(e) ? 'html' : /^pptx$/i.test(e) ? 'pptx' : ''; };
69
+ const hostOf = (u) => { try { return u && /^https?:/.test(u) ? new URL(u).hostname.replace(/^www\./, '') + new URL(u).pathname.replace(/\/$/, '') : ''; } catch { return ''; } };
70
+
71
+ /** A document as stops: the blocks before the first second-level heading are the Summary; each `##` starts a section. */
72
+ export function docSections(md, fallback = '') {
73
+ const blocks = parseMd(String(md || '').replace(/^\uFEFF?---\r?\n[\s\S]*?\r?\n---\r?\n/, '')); // the frontmatter is not shown
74
+ let title = fallback;
75
+ const h1 = blocks.findIndex((b) => b.t === 'h' && b.level === 1);
76
+ if (h1 >= 0) title = flat(blocks[h1].c) || fallback;
77
+ const out = [];
78
+ for (const [i, b] of blocks.entries()) {
79
+ if (i === h1) continue;
80
+ if (b.t === 'h' && b.level <= 2) out.push({ head: flat(b.c) || 'Section', blocks: [b] });
81
+ else { if (!out.length) out.push({ head: 'Summary', blocks: [] }); out[out.length - 1].blocks.push(b); }
82
+ }
83
+ return { title, sections: out.filter((s) => s.blocks.length) };
84
+ }
85
+ const flat = (c) => (Array.isArray(c) ? c.map((x) => (typeof x === 'string' ? x : x && (x.s || x.text || flat(x.c)) || '')).join('') : String(c || '')).replace(/\s+/g, ' ').trim();
86
+
87
+ /** The stops of the material shown: [{ label }] and the one you are on. */
88
+ function stopsOf(m, L, pos) {
89
+ if (m.kind === 'slides' && L && L.deck) return L.deck.slides.map((s, i) => ({ label: (D.slideText(s).head || 'Slide ' + (i + 1)) }));
90
+ if (m.kind === 'doc' && L && L.doc) return L.doc.sections.map((s) => ({ label: s.head }));
91
+ if (m.kind === 'image') return [{ label: 'Whole image' }];
92
+ return [];
93
+ }
94
+
95
+ /** The view model. S = { mats, cur, pos: { [id]: n }, loaded: { [id]: { deck | doc | error } }, M (meeting), blank, zoom, share, menu, follow } */
96
+ export function presentModel(S, now = Date.now()) {
97
+ const mats = S.mats || [], m = mats[S.cur] || mats[0] || null, L = m ? (S.loaded || {})[m.id] : null, M = S.M || {};
98
+ const stops = m ? stopsOf(m, L, 0) : [];
99
+ const i = Math.max(0, Math.min(Math.max(0, stops.length - 1), (S.pos || {})[m && m.id] || 0));
100
+ const unit = m && m.kind === 'slides' ? 'slide' : m && m.kind === 'doc' ? 'stop' : '';
101
+ const where = !m ? '' : L && L.error ? 'could not be read' : stops.length > 1 && unit ? unit + ' ' + (i + 1) + ' of ' + stops.length : m.kind === 'live' ? m.sub : m.kind === 'image' ? Math.round((S.zoom || 1) * 100) + '%' : '';
31
102
  const at = Date.parse(M.at), end = Date.parse(M.end);
32
103
  const used = Number.isFinite(at) && Number.isFinite(end) && end > at ? Math.max(0, Math.min(1, (now - at) / (end - at))) : null;
33
104
  const tl = M.topic && Number.isFinite(M.topic.left) ? M.topic.left : null;
105
+ const topicLine = M.topic ? (tl == null ? 'topic ' + M.topic.n + ' of ' + M.topic.of : tl > 0 ? 'topic ' + M.topic.n + ' ends in ' + Math.max(1, Math.round(tl / 60000)) + ' min' : 'topic ' + M.topic.n + ' is over its time') : '';
106
+ const slide = m && m.kind === 'slides' && L && L.deck ? L.deck.slides[i] : null;
107
+ const notes = String((slide && slide.notes) || '').split('\n').map((x) => x.replace(/^\s*[-*•]\s*/, '').trim()).filter(Boolean).slice(0, 8);
108
+ const nx = stops[i + 1] || null;
109
+ const app = clip(S.app || '', 30);
34
110
  return {
35
- i: k, n, title: clip(deck.title, 80), meeting: clip(M.title || 'Meeting', 80), rec: !!M.rec, blank: !!o.blank,
36
- elapsed: mmss(now - (M.startedAt || now)),
37
- topicLine: M.topic ? (tl == null ? 'topic ' + M.topic.n + ' of ' + M.topic.of : tl > 0 ? 'topic ' + M.topic.n + ' ends in ' + Math.max(1, Math.round(tl / 60000)) + ' min' : 'topic ' + M.topic.n + ' is over its time') : '',
38
- used, late: tl != null && tl <= 3 * 60000,
39
- next: nx ? { n: k + 2, head: head(nx) || 'Slide ' + (k + 2) } : null,
40
- notes: String((s && s.notes) || '').split('\n').map((x) => x.replace(/^\s*[-*•]\s*/, '').trim()).filter(Boolean).slice(0, 8),
111
+ meeting: clip(M.title || 'Meeting', 80), rec: !!M.rec, blank: !!S.blank, menu: !!S.menu, follow: !!S.follow,
112
+ m, i, n: stops.length, stops, where, error: L && L.error ? L.error : '', loading: !!m && !L && (m.kind === 'slides' || m.kind === 'doc'),
113
+ elapsed: mmss(now - (M.startedAt || now)), topicLine, used, late: tl != null && tl <= 3 * 60000,
114
+ next: nx ? { label: clip(nx.label, 80), n: i + 2, slide: m.kind === 'slides' } : null,
115
+ notes, notesLabel: m && m.kind === 'slides' ? 'Your notes for this slide' : 'Your notes here',
41
116
  question: clip(M.question, 200), asker: clip(M.asker, 30),
117
+ share: S.share || 'open', shareText: S.share === 'blocked' ? 'Allow pop-ups, then press here' : 'Pick the window in ' + (app ? app + '’s' : 'the call’s') + ' Share',
118
+ mats: mats.map((x, k) => ({ title: x.title, sub: x.sub + (k === S.cur ? '' : (S.pos || {})[x.id] ? ' · left at ' + ((S.pos || {})[x.id] + 1) : ''), icon: KIND_ICON[x.kind], on: k === S.cur, key: k < 9 ? String(k + 1) : '' })),
119
+ hint: HINT[m ? m.kind : 'none'], zoom: S.zoom || 1, addErr: S.addErr || '',
42
120
  };
43
121
  }
44
122
 
45
- /** The view (pure). slideHtml draws one slide (premium-vw-slides.js, loaded by the page half so this module also loads without a page); the
46
- * geometry is set after the markup is in. */
47
- export function presentHtml(V, deck, ws, slideHtml = () => '') {
48
- const thumbs = deck.slides.map((s, k) => `<button type="button" class="vzx-tb${k === V.i ? ' on' : ''}" data-x="go" data-i="${k}" aria-label="Slide ${k + 1}${k === V.i ? ', showing' : ''}" aria-current="${k === V.i}"><span class="vzx-mini" aria-hidden="true">${slideHtml(s, deck.theme, ws, false)}</span><b>${k + 1}</b></button>`).join('');
49
- return `<div class="vzx-top"><span class="vzx-rec"${V.rec ? '' : ' hidden'} aria-hidden="true"></span><b>${esc(V.meeting)} · presenting</b><span class="vzx-mut">${esc(V.title + ' · slide ' + (V.i + 1) + ' of ' + V.n)}</span><span class="vzx-sp"></span>`
50
- + `<span class="vzx-pill" data-k="${V.blank ? 'w' : 'ok'}" role="status">Audience sees: ${V.blank ? 'nothing' : 'slide ' + (V.i + 1)}</span><button type="button" class="vzx-btn" data-x="win">Share the audience window</button><button type="button" class="vzx-btn vzx-dark" data-x="end">Stop presenting</button></div>`
51
- + `<div class="vzx-main"><section class="vzx-left"><div class="vzx-slot"><div class="vzx-box" data-x="adv">${slideHtml(deck.slides[V.i], deck.theme, ws, false)}</div></div>`
52
- + `<div class="vzx-nav"><button type="button" class="vzx-ib" data-x="prev" aria-label="Previous slide"${V.i ? '' : ' disabled'}>${ic('prev')}</button><div class="vzx-ths">${thumbs}</div><button type="button" class="vzx-ib" data-x="next" aria-label="Next slide"${V.i < V.n - 1 ? '' : ' disabled'}>${ic('next')}</button><span class="vzx-mut vzx-keys">${esc(KEYS_HINT)}</span></div></section>`
53
- + `<aside class="vzx-side"><div class="vzx-clock"><b data-x-clock>${V.elapsed}</b><span class="vzx-mut">elapsed${V.topicLine ? ' · ' + esc(V.topicLine) : ''}</span></div>`
54
- + (V.used != null ? `<div class="vzx-bar" role="img" aria-label="${Math.round(V.used * 100)}% of the meeting's time is used"><svg width="100%" height="8" aria-hidden="true"><rect width="100%" height="8" rx="4" class="vzx-bg"/><rect width="${(V.used * 100).toFixed(1)}%" height="8" rx="4" class="vzx-fg${V.late ? ' late' : ''}"/></svg></div>` : '')
55
- + `<p class="vzx-lbl">${V.next ? 'Next · slide ' + V.next.n : 'Next'}</p>${V.next ? `<div class="vzx-nx"><div class="vzx-box">${slideHtml(deck.slides[V.i + 1], deck.theme, ws, false)}</div></div>` : '<p class="vzx-mut">That was the last slide.</p>'}`
56
- + `<p class="vzx-lbl">Your notes for this slide</p><div class="vzx-notes">${V.notes.length ? V.notes.map((x) => `<span>${esc(x)}</span>`).join('') : '<span class="vzx-mut">No notes on this slide. Add them in the deck’s speaker notes.</span>'}</div>`
57
- + `<p class="vzx-lbl">From the room</p>${V.question ? `<div class="vzx-need"><span>${V.asker ? `<b>${esc(V.asker)}:</b> ` : ''}“${esc(V.question)}” Not answered yet.</span><button type="button" class="vzx-ib vzx-sm" data-x="keepq" aria-label="Keep as a question">${ic('plus', 14)}</button></div>` : '<p class="vzx-mut">No open question from the room yet.</p>'}`
58
- + `<p class="vzx-mut vzx-foot">${esc(ONLY_YOU)}</p></aside></div>`;
123
+ /** The audience window's quiet line: the meeting, then where it is. */
124
+ export function audienceFoot(V) {
125
+ const right = !V.m ? '' : V.m.kind === 'live' ? (V.m.host || V.m.title) + ' · live' : V.n > 1 ? (V.i + 1) + ' / ' + V.n : V.m.title;
126
+ return { left: V.meeting, right };
127
+ }
128
+
129
+ /* ── html (pure) ── */
130
+ function stageHtml(V, slideHtml) {
131
+ const m = V.m;
132
+ if (!m) return '<div class="vzx-card"><p>No material is linked to this meeting.</p></div>';
133
+ if (V.error) return `<div class="vzx-card"><p><b>${esc(m.title)}</b> could not be read: ${esc(V.error)}</p></div>`;
134
+ if (V.loading) return `<div class="vzx-card"><p>Reading ${esc(m.title)}.</p></div>`;
135
+ if (m.kind === 'slides') return `<div class="vzx-slot"><div class="vzx-box" data-x="adv" data-slide="${V.i}"></div></div>`;
136
+ if (m.kind === 'doc') return '<div class="vzx-doc" data-x-doc tabindex="0"></div>';
137
+ if (m.kind === 'image') return `<div class="vzx-imv" data-x-img><img alt="${esc(m.title)}" src="${esc(m.url)}" draggable="false"><div class="vzx-zm"><button type="button" class="vzx-ib" data-x="zout" aria-label="Zoom out">${ic('minus', 15)}</button><span>${Math.round(V.zoom * 100)}%</span><button type="button" class="vzx-ib" data-x="zin" aria-label="Zoom in">${ic('plus', 15)}</button></div></div>`;
138
+ if (m.kind === 'live') return `<div class="vzx-card vzx-live"><span class="vzx-url">${ic('link', 15)}<b>${esc(m.host || m.title)}</b><i>Live</i></span><p>It is open in the audience window, live. Click, hover and type there; the call sees that window, pointer and all.</p><button type="button" class="vzx-btn" data-x="front">Bring it forward</button></div>`;
139
+ return `<div class="vzx-card"><p>PMOS cannot draw a PowerPoint file. Open it in PowerPoint or Keynote and share that window, or switch to other material.</p>${m.url ? `<a class="vzx-btn" href="${esc(m.url)}" download>Open the file</a>` : ''}</div>`;
140
+ }
141
+ function stopsHtml(V, slideHtml, deck) {
142
+ if (!V.m || V.error || V.loading) return '';
143
+ if (V.m.kind === 'slides' && deck) {
144
+ const th = deck.slides.map((s, k) => `<button type="button" class="vzx-tb${k === V.i ? ' on' : k < V.i ? ' done' : ''}" data-x="go" data-i="${k}" aria-label="Slide ${k + 1}${k === V.i ? ', showing' : ''}" aria-current="${k === V.i}"><span class="vzx-mini" aria-hidden="true">${slideHtml(s, deck.theme, '', false)}</span></button>`).join('');
145
+ return `<div class="vzx-nav"><button type="button" class="vzx-ib vzx-soft" data-x="prev" aria-label="Previous slide"${V.i ? '' : ' disabled'}>${ic('prev', 16)}</button><div class="vzx-ths">${th}</div><button type="button" class="vzx-ib vzx-soft" data-x="next" aria-label="Next slide"${V.i < V.n - 1 ? '' : ' disabled'}>${ic('next', 16)}</button></div>`;
146
+ }
147
+ if (V.stops.length > 1 || V.m.kind === 'image') return `<div class="vzx-stops">${V.stops.map((s, k) => `<button type="button" class="${k === V.i ? 'on' : k < V.i ? 'done' : ''}" data-x="go" data-i="${k}" aria-current="${k === V.i}">${esc(clip(s.label, 40))}</button>`).join('')}${V.m.kind === 'doc' ? `<span class="vzx-sp"></span><button type="button" class="vzx-chip${V.follow ? ' on' : ''}" data-x="follow" aria-pressed="${V.follow}">Follow my scroll</button>` : ''}</div>`;
148
+ return '';
149
+ }
150
+ function sideHtml(V, slideHtml, deck) {
151
+ const h = [];
152
+ if (V.next) h.push(`<div class="vzx-c2"><h4>${V.next.slide ? 'Next · slide ' + V.next.n : 'Next stop'}</h4>${V.next.slide && deck ? `<div class="vzx-nx"><div class="vzx-box" data-slide="${V.i + 1}"></div></div>` : `<p><b>${esc(V.next.label)}</b></p>`}</div>`);
153
+ if (V.notes.length) h.push(`<div class="vzx-c2"><h4>${esc(V.notesLabel)}</h4>${V.notes.map((x) => `<p>${esc(x)}</p>`).join('')}</div>`);
154
+ if (V.question) h.push(`<div class="vzx-c2 vzx-room"><h4>From the room</h4><div class="vzx-r"><p>${V.asker ? `<b>${esc(V.asker)}:</b> ` : ''}“${esc(V.question)}” Not answered yet.</p><button type="button" class="vzx-ib vzx-soft" data-x="keepq" aria-label="Keep as a question" title="Keep as a question">${ic('plus', 14)}</button></div></div>`);
155
+ return h.join('');
156
+ }
157
+ function menuHtml(V) {
158
+ if (!V.menu) return '';
159
+ return `<div class="vzx-swm" role="menu" aria-label="Switch material">${V.mats.map((x, k) => `<button type="button" role="menuitem" class="${x.on ? 'on' : ''}" data-x="mat" data-i="${k}"><span class="vzx-fi">${ic(x.icon, 15)}</span><span class="vzx-w">${esc(x.title)}<span>${esc(x.sub)}</span></span>${x.key ? `<span class="vzx-k">${x.key}</span>` : ''}</button>`).join('')}`
160
+ + `<hr><label class="vzx-add">${ic('plus', 15)}<input data-x="addlink" type="url" placeholder="Paste a link to add it" aria-label="Paste a link to add it as material"></label>${V.addErr ? `<p class="vzx-err" role="alert">${esc(V.addErr)}</p>` : ''}</div>`;
161
+ }
162
+ /** The presenter (pure). slideHtml draws one slide (premium-vw-slides.js); deck is the loaded deck of the material shown. */
163
+ export function presentHtml(V, slideHtml = () => '', deck = null) {
164
+ const m = V.m;
165
+ const mat = !m ? '' : V.mats.length > 1
166
+ ? `<button type="button" class="vzx-matb" data-x="menu" aria-haspopup="menu" aria-expanded="${V.menu}" title="Switch material (M)">${ic(KIND_ICON[m.kind], 15)}${esc(m.title)}${V.where ? ` <span class="vzx-c">${esc(V.where)}</span>` : ''}${ic('chev', 14)}</button>`
167
+ : `<span class="vzx-mut">${esc(m.title)}${V.where ? ' · ' + esc(V.where) : ''}</span>`;
168
+ const meta = [V.elapsed, V.topicLine, V.blank ? 'the audience sees nothing (B)' : ''].filter(Boolean).join(' · ');
169
+ const share = `<button type="button" class="vzx-share" data-x="share" data-k="${esc(V.share)}" title="PMOS opened a window with the stage only. Your call app shares it: press Share there and pick “Audience · ${esc(V.meeting)}”.">${ic('share', 15)}${esc(V.shareText)}</button>`;
170
+ const bar = V.used != null ? `<svg class="vzx-used" aria-hidden="true" width="100%" height="3"><rect width="100%" height="3" class="vzx-bg"/><rect width="${(V.used * 100).toFixed(1)}%" height="3" class="vzx-fg${V.late ? ' late' : ''}"/></svg>` : '';
171
+ return `<div class="vzx-top"><span class="vzx-rec"${V.rec ? '' : ' hidden'} aria-hidden="true"></span><b>${esc(V.meeting)} · presenting</b>${mat}<span class="vzx-mut" data-x-clock>${esc(meta)}</span><span class="vzx-sp"></span>${share}`
172
+ + `<button type="button" class="vzx-stop" data-x="end" aria-label="Stop presenting (Esc)" title="Stop presenting (Esc)">${ic('x', 17)}</button>${bar}</div>`
173
+ + `<section class="vzx-stage" data-kind="${m ? m.kind : 'none'}">${stageHtml(V, slideHtml)}${stopsHtml(V, slideHtml, deck)}</section>`
174
+ + `<aside class="vzx-side">${sideHtml(V, slideHtml, deck)}</aside>`
175
+ + `<p class="vzx-foot">${esc(ONLY_YOU)} ${esc(V.hint)}</p>${menuHtml(V)}`;
59
176
  }
60
177
 
61
178
  /* ── the page half ── */
62
- const CSS = ['/pm/premium-vw-slides.css', '/pm/cozy-vw-mtg.css'];
63
- function sheets(doc) { for (const h of CSS) if (!doc.querySelector(`link[href="${h}"]`)) { const l = doc.createElement('link'); l.rel = 'stylesheet'; l.href = h; doc.head.append(l); } }
64
- /** Puts each slide item where its data-g says, and scales each box to its slot (premium-vw-slides.js place and fitIn, for this view). */
179
+ const CSS = ['/pm/premium-vw-slides.css', '/pm/cozy-mtg-present.css'];
180
+ function sheets(doc, abs, again) {
181
+ if (abs) return copySheets(doc, again);
182
+ for (const h of CSS) if (!doc.querySelector(`link[href="${h}"]`)) { const l = doc.createElement('link'); l.rel = 'stylesheet'; l.href = h; doc.head.append(l); }
183
+ }
184
+ /** The audience window is about:blank: a stylesheet linked into it is not fetched there, so it gets this page's rules as text. A sheet
185
+ * this page is still fetching is copied when it arrives (again() draws the window once more). */
186
+ function copySheets(doc, again) {
187
+ let st = doc.getElementById('vzxAudCss');
188
+ if (st && st.dataset.full === '1') return;
189
+ const want = CSS.concat(['/pm/cozy.css']).map((h) => h.replace(/^\/pm\//, '/'));
190
+ const text = [], got = new Set();
191
+ for (const sh of document.styleSheets) {
192
+ const w = sh.href && want.find((x) => sh.href.split('?')[0].endsWith(x)); if (!w) continue;
193
+ let rules = null; try { rules = sh.cssRules; } catch { rules = null; }
194
+ if (!rules) continue;
195
+ got.add(w);
196
+ for (const r of rules) text.push(r.cssText.replace(/url\("?([^")]+)"?\)/g, (m, u) => { try { return 'url("' + new URL(u, sh.href).href + '")'; } catch { return m; } })); // a font's address, against its sheet
197
+ }
198
+ if (!st) { st = doc.createElement('style'); st.id = 'vzxAudCss'; doc.head.append(st); }
199
+ st.textContent = text.join('\n'); st.dataset.full = got.size === want.length ? '1' : '';
200
+ if (got.size < want.length && again) for (const l of document.querySelectorAll('link[rel="stylesheet"]')) if (!l.sheet && want.some((x) => l.href.split('?')[0].endsWith(x))) l.addEventListener('load', again, { once: true });
201
+ }
65
202
  function place(root) {
66
203
  root.querySelectorAll('.sl-it[data-g]').forEach((n) => { const [x, y, w, h] = n.dataset.g.split(','); 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'); });
67
204
  }
68
205
  function fit(box, slot) { const k = Math.max(0.03, Math.min(slot.clientWidth / D.W, slot.clientHeight / D.H)); box.style.setProperty('--bd-k', String(k)); }
69
206
 
70
- /** Opens the presenter view. meeting = { title, rec, at, end, topic, question, asker, noteId, notesBody } */
71
- export async function presentDeck({ ws = '', path, title = '', meeting = {}, getMeeting = null, onKeep = null } = {}) {
72
- if (!path) return null;
73
- let text = '';
74
- try {
75
- const r = await fetch('/api/doc?' + new URLSearchParams({ ...(ws ? { ws } : {}), path }).toString(), { credentials: 'same-origin' });
76
- text = await r.text(); if (!r.ok) throw new Error(text || 'not found');
77
- } catch (x) { return { ok: false, error: 'The deck could not be read: ' + String((x && x.message) || x) }; }
78
- const deck = D.parseDeck(text, title || String(path).split('/').pop());
207
+ /** Opens the audience window. Call it in the press itself (before an await), so the browser counts it as the PM's own. */
208
+ export function openAudience() {
209
+ try { const w = window.open('about:blank', AUDIENCE_NAME, 'popup=yes,width=1280,height=720'); return w && !w.closed ? w : null; } catch { return null; }
210
+ }
211
+ const reach = (w) => { try { return !!(w && !w.closed && w.document && w.document.body); } catch { return false; } };
212
+
213
+ export async function readDoc(ws, ref) {
214
+ const r = await fetch('/api/doc?' + new URLSearchParams({ ...(ws ? { ws } : {}), path: ref }).toString(), { credentials: 'same-origin' });
215
+ const text = await r.text(); if (!r.ok) throw new Error(text || 'not found');
216
+ return text;
217
+ }
218
+
219
+ /** Presents. mats: material rows (matOf reads them); start: the index to begin with; pos: where each starts { [id]: n }. */
220
+ export async function presentMaterial({ mats = [], start = 0, pos = {}, ws = '', meeting = {}, getMeeting = null, onKeep = null, onAddLink = null, onEnd = null, app = '', win = null } = {}) {
221
+ const list = mats.map((x) => (x && x.kind && ['slides', 'doc', 'image', 'live', 'none'].includes(x.kind) && 'sub' in x ? x : matOf(x)));
222
+ if (!list.length) return { ok: false, error: 'No material is linked to this meeting.' };
79
223
  const { slideHtml } = await import('./premium-vw-slides.js');
80
- if (!deck.slides.length) return { ok: false, error: 'The deck has no slides.' };
81
224
  sheets(document);
82
- const P = { i: 0, blank: false, win: null, t0: Date.now(), M: { ...meeting, startedAt: Date.now() } };
225
+ const S = { mats: list, cur: Math.max(0, Math.min(list.length - 1, start)), pos: { ...pos }, loaded: {}, M: { ...meeting, startedAt: Date.now() }, blank: false, zoom: 1, pan: [0, 0], share: 'open', menu: false, follow: false, app, addErr: '' };
226
+ let W = reach(win) ? win : null, live = null; // live: the address the audience window shows itself
227
+ if (!W) S.share = 'blocked';
83
228
  const o = document.createElement('div');
84
- o.className = 'vzx cz'; o.tabIndex = -1; o.setAttribute('role', 'dialog'); o.setAttribute('aria-label', 'Presenting ' + deck.title); o.dataset.escLayer = '';
85
- const draw = () => {
86
- if (getMeeting) { try { P.M = { ...P.M, ...getMeeting() }; } catch { /* the meeting card is gone: keep the last */ } }
87
- const V = presentModel(deck, P.i, P.M, Date.now(), { blank: P.blank });
88
- o.innerHTML = presentHtml(V, deck, ws, slideHtml);
89
- lay(); drawWin();
90
- };
91
- const lay = () => {
92
- o.querySelectorAll('.vzx-slot,.vzx-nx').forEach((slot) => { const b = slot.querySelector('.vzx-box'); if (b) { fit(b, slot); place(b); } });
93
- o.querySelectorAll('.vzx-mini').forEach((m) => { const c = m.querySelector('.sl-cv'); if (c) { m.style.setProperty('--bd-k', String(m.clientWidth / D.W)); place(m); } });
94
- };
95
- const drawWin = () => {
96
- const w = P.win; if (!w || w.closed) return;
97
- const d = w.document;
98
- d.body.innerHTML = P.blank ? '<div class="vzx-aud"></div>' : `<div class="vzx-aud"><div class="vzx-box">${slideHtml(deck.slides[P.i], deck.theme, ws, false)}</div></div>`;
229
+ o.className = 'vzx cz'; o.tabIndex = -1; o.setAttribute('role', 'dialog'); o.setAttribute('aria-label', 'Presenting'); o.dataset.escLayer = '';
230
+ const mat = () => S.mats[S.cur];
231
+ const L = () => S.loaded[mat().id];
232
+ async function load(m) {
233
+ if (S.loaded[m.id] || (m.kind !== 'slides' && m.kind !== 'doc')) return;
234
+ try {
235
+ const text = await readDoc(m.ws || ws, m.src);
236
+ S.loaded[m.id] = m.kind === 'slides' ? { deck: D.parseDeck(text, m.title) } : { doc: docSections(text, m.title) };
237
+ if (m.kind === 'slides' && !S.loaded[m.id].deck.slides.length) S.loaded[m.id] = { error: 'the deck has no slides' };
238
+ } catch (x) { S.loaded[m.id] = { error: String((x && x.message) || x).slice(0, 160) }; }
239
+ }
240
+ const model = () => { if (getMeeting) { try { S.M = { ...S.M, ...getMeeting(), startedAt: S.M.startedAt }; } catch { /* the meeting card is gone: keep the last */ } } return presentModel(S, Date.now()); };
241
+ function draw() {
242
+ const V = model(), m = V.m, l = m ? L() : null, deck = l && l.deck ? l.deck : null;
243
+ o.innerHTML = presentHtml(V, slideHtml, deck);
244
+ if (deck) {
245
+ o.querySelectorAll('.vzx-box[data-slide]').forEach((b) => { b.innerHTML = slideHtml(deck.slides[+b.dataset.slide], deck.theme, m.ws || ws, false); fit(b, b.parentElement); place(b); });
246
+ o.querySelectorAll('.vzx-mini').forEach((x) => { x.style.setProperty('--bd-k', String(x.clientWidth / D.W)); place(x); });
247
+ }
248
+ if (m && m.kind === 'doc' && l && l.doc) drawDoc(o.querySelector('[data-x-doc]'), l.doc, V.i, document, false);
249
+ if (m && m.kind === 'image') drawImg(o.querySelector('[data-x-img] img'));
250
+ const mb = o.querySelector('.vzx-matb'), sw = o.querySelector('.vzx-swm');
251
+ if (mb && sw) { const r = mb.getBoundingClientRect(); sw.style.setProperty('--bd-x', Math.max(16, Math.min(r.left, innerWidth - sw.offsetWidth - 16)) + 'px'); sw.style.setProperty('--bd-y', (r.bottom + 6) + 'px'); }
252
+ const add = o.querySelector('[data-x="addlink"]'); if (add && S.focusAdd) { add.focus(); S.focusAdd = false; }
253
+ drawWin(V);
254
+ }
255
+ function drawDoc(host, doc, at, d, aud) {
256
+ if (!host) return;
257
+ host.textContent = '';
258
+ const page = d.createElement('div'); page.className = 'vzx-page';
259
+ if (doc.title) { const h = d.createElement('h3'); h.textContent = doc.title; page.append(h); }
260
+ doc.sections.forEach((s, k) => { const sec = d.createElement('div'); sec.className = 'vzx-sec' + (k === at ? ' spot' : ' dim'); sec.dataset.k = String(k); sec.append(...toDom(s.blocks, d)); page.append(sec); });
261
+ host.append(page);
262
+ const spot = page.querySelector('.vzx-sec.spot');
263
+ if (!aud && spot && !S.follow) spot.scrollIntoView({ block: 'center' });
264
+ if (!aud) host.onscroll = () => { if (S.follow) followScroll(host); };
265
+ }
266
+ function followScroll(host) {
267
+ if (!reach(W) || live) return;
268
+ const t = W.document.querySelector('.vzx-doc'); if (!t) return;
269
+ const r = host.scrollTop / Math.max(1, host.scrollHeight - host.clientHeight);
270
+ t.scrollTop = r * Math.max(0, t.scrollHeight - t.clientHeight);
271
+ }
272
+ function drawImg(img) { if (img) { img.style.setProperty('--bd-px', S.pan[0] + 'px'); img.style.setProperty('--bd-py', S.pan[1] + 'px'); img.style.setProperty('--bd-z', String(S.zoom)); } }
273
+ /* the audience window: the stage only, drawn here, or the live page itself */
274
+ function drawWin(V) {
275
+ if (!W || W.closed) { W = null; return; }
276
+ const m = V.m;
277
+ if (m && m.kind === 'live' && m.url && !S.blank) {
278
+ if (live !== m.url) { live = m.url; try { W.location.href = m.url; } catch { /* the window is gone */ } }
279
+ return;
280
+ }
281
+ if (live) { live = null; try { W.location.href = 'about:blank'; } catch { /* gone */ } setTimeout(() => { if (!reach(W)) { try { W.close(); } catch { /* gone */ } W = openAudience(); S.share = W ? S.share : 'blocked'; } drawWin(model()); }, 300); return; }
282
+ if (!reach(W)) return;
283
+ const d = W.document;
284
+ sheets(d, true, () => drawWin(model()));
285
+ if (!d.body.classList.contains('vzx-audw')) { d.body.className = 'cz vzx-audw'; W.onkeydown = (e) => key(e); W.onresize = () => drawWin(model()); }
286
+ d.title = 'Audience · ' + V.meeting;
287
+ const f = audienceFoot(V);
288
+ const l = m ? S.loaded[m.id] : null;
289
+ let stage = '';
290
+ if (S.blank || !m) stage = '';
291
+ else if (m.kind === 'slides' && l && l.deck) stage = `<div class="vzx-slot"><div class="vzx-box">${slideHtml(l.deck.slides[V.i], l.deck.theme, m.ws || ws, false)}</div></div>`;
292
+ else if (m.kind === 'image') stage = `<div class="vzx-imv"><img alt="" src="${esc(location.origin + m.url)}" draggable="false"></div>`;
293
+ else if (m.kind === 'doc') stage = '<div class="vzx-doc"></div>';
294
+ else if (m.kind === 'none') stage = '';
295
+ d.body.innerHTML = `<div class="vzx-aud" data-kind="${m ? m.kind : ''}">${stage}</div>${S.blank ? '' : `<div class="vzx-ft"><span>${esc(f.left)}</span><span>${esc(f.right)}</span></div>`}`;
99
296
  const b = d.querySelector('.vzx-box');
100
- if (b) { b.style.setProperty('--bd-k', String(Math.max(0.05, Math.min(w.innerWidth / D.W, w.innerHeight / D.H)))); place(b); }
101
- };
297
+ if (b) { b.style.setProperty('--bd-k', String(Math.max(0.05, Math.min(W.innerWidth / D.W, (W.innerHeight - 48) / D.H)))); place(b); }
298
+ if (m && m.kind === 'doc' && l && l.doc) { drawDoc(d.querySelector('.vzx-doc'), l.doc, V.i, d, true); const sp = d.querySelector('.vzx-sec.spot'); if (sp && !S.follow) sp.scrollIntoView({ block: 'center' }); }
299
+ if (m && m.kind === 'image') drawImg(d.querySelector('.vzx-imv img'));
300
+ }
102
301
  const say = (t) => { try { if (window.pmToast) window.pmToast(t); } catch { /* no toast on this page */ } };
103
- const openWin = () => {
104
- let w = null;
105
- try { w = window.open('', 'pmos-meeting-audience', 'popup=yes,width=1280,height=720'); } catch { w = null; }
106
- if (!w || w.closed) { say('The browser blocked the audience window. Allow pop-ups for PMOS, then press Share the audience window again.'); return; }
107
- const d = w.document; d.title = 'Audience · ' + deck.title;
108
- for (const h of ['/pm/cozy.css', ...CSS]) if (!d.querySelector(`link[href="${location.origin + h}"]`)) { const l = d.createElement('link'); l.rel = 'stylesheet'; l.href = location.origin + h; d.head.append(l); }
109
- d.body.className = 'cz vzx-audw';
110
- w.onkeydown = (e) => key(e); w.onresize = drawWin;
111
- P.win = w; drawWin(); o.focus();
112
- };
113
- const go = (k) => { const j = Math.max(0, Math.min(deck.slides.length - 1, k)); if (j !== P.i) { P.i = j; draw(); } };
114
- const tick = setInterval(() => { const c = o.querySelector('[data-x-clock]'); if (c) c.textContent = mmss(Date.now() - P.M.startedAt); }, 1000);
115
- const slow = setInterval(draw, 30000); // the topic's time left and the room's question
302
+ function share() {
303
+ if (!W || W.closed) { W = openAudience(); live = null; S.share = W ? 'open' : 'blocked'; draw(); }
304
+ if (W) { try { W.focus(); } catch { /* the browser keeps it behind */ } }
305
+ }
306
+ async function switchTo(k) {
307
+ if (k < 0 || k >= S.mats.length) return;
308
+ S.cur = k; S.menu = false; S.zoom = 1; S.pan = [0, 0];
309
+ draw(); await load(mat()); if (S.cur === k) draw();
310
+ }
311
+ const go = (k) => { const n = model().n; const j = Math.max(0, Math.min(Math.max(0, n - 1), k)); if (j !== (S.pos[mat().id] || 0)) { S.pos[mat().id] = j; draw(); } };
312
+ const at = () => S.pos[mat().id] || 0;
313
+ const zoom = (f) => { S.zoom = Math.max(0.25, Math.min(8, S.zoom * f)); if (S.zoom === 1) S.pan = [0, 0]; draw(); };
314
+ const tick = setInterval(() => { const c = o.querySelector('[data-x-clock]'); if (c) { const V = model(); c.textContent = [V.elapsed, V.topicLine, V.blank ? 'the audience sees nothing (B)' : ''].filter(Boolean).join(' · '); } }, 1000);
315
+ const slow = setInterval(() => { if (!o.contains(document.activeElement) || document.activeElement === o) draw(); }, 30000); // the topic's time left and the room's question
116
316
  function end() {
117
- clearInterval(tick); clearInterval(slow); o.remove(); removeEventListener('resize', lay); document.removeEventListener('keydown', key, true);
118
- if (P.win && !P.win.closed) P.win.close();
317
+ clearInterval(tick); clearInterval(slow); o.remove(); removeEventListener('resize', onResize); document.removeEventListener('keydown', key, true); document.removeEventListener('pointerdown', panStart);
318
+ if (W && !W.closed) { try { W.close(); } catch { /* gone */ } }
319
+ ended = true;
320
+ if (onEnd) { try { onEnd({ ...S.pos }); } catch { /* the caller's own */ } }
119
321
  }
322
+ let ended = false;
323
+ const onResize = () => draw();
120
324
  function key(e) {
121
- if (e.key === 'Escape') { e.preventDefault(); e.stopImmediatePropagation(); end(); return; }
122
- if (e.key === 'ArrowRight' || e.key === 'ArrowDown' || e.key === 'PageDown' || e.key === ' ') { e.preventDefault(); go(P.i + 1); }
123
- if (e.key === 'ArrowLeft' || e.key === 'ArrowUp' || e.key === 'PageUp') { e.preventDefault(); go(P.i - 1); }
124
- if (e.key === 'b' || e.key === 'B') { e.preventDefault(); P.blank = !P.blank; draw(); }
325
+ const typing = e.target && /^(INPUT|TEXTAREA)$/.test(e.target.tagName);
326
+ if (e.key === 'Escape') { e.preventDefault(); e.stopImmediatePropagation(); if (S.menu) { S.menu = false; draw(); o.focus(); return; } end(); return; }
327
+ if (typing) { if (e.key === 'Enter' && e.target.dataset.x === 'addlink') { e.preventDefault(); addLink(e.target.value); } return; }
328
+ const kind = mat() ? mat().kind : '';
329
+ if (e.key === 'ArrowRight' || e.key === 'PageDown' || e.key === ' ' || (kind !== 'image' && e.key === 'ArrowDown')) { e.preventDefault(); go(at() + 1); return; }
330
+ if (e.key === 'ArrowLeft' || e.key === 'PageUp' || (kind !== 'image' && e.key === 'ArrowUp')) { e.preventDefault(); go(at() - 1); return; }
331
+ if (e.key === 'b' || e.key === 'B') { e.preventDefault(); S.blank = !S.blank; draw(); return; }
332
+ if (e.key === 'm' || e.key === 'M') { e.preventDefault(); S.menu = !S.menu; draw(); return; }
333
+ if ((e.key === 'f' || e.key === 'F') && kind === 'doc') { e.preventDefault(); S.follow = !S.follow; draw(); return; }
334
+ if (kind === 'image' && (e.key === '+' || e.key === '=')) { e.preventDefault(); zoom(1.25); return; }
335
+ if (kind === 'image' && e.key === '-') { e.preventDefault(); zoom(0.8); return; }
336
+ if (/^[1-9]$/.test(e.key) && +e.key <= S.mats.length) { e.preventDefault(); switchTo(+e.key - 1); }
337
+ }
338
+ async function addLink(v) {
339
+ if (!onAddLink) return;
340
+ let u = null; try { u = new URL(String(v).trim()); } catch { u = null; }
341
+ if (!u || u.protocol !== 'https:') { S.addErr = 'Only an https link can be added.'; S.focusAdd = true; return draw(); }
342
+ const r = await onAddLink(u.href);
343
+ if (!r || !r.ok) { S.addErr = 'Not added: ' + ((r && r.error) || 'no answer'); S.focusAdd = true; return draw(); }
344
+ S.addErr = '';
345
+ const added = matOf(r.item || { kind: 'link', url: u.href, title: u.hostname });
346
+ S.mats.push(added); switchTo(S.mats.length - 1);
125
347
  }
126
348
  o.onclick = async (e) => {
127
- const t = e.target.closest('[data-x]'); if (!t || t.disabled) return;
349
+ const t = e.target.closest('[data-x]');
350
+ if (!t) { if (S.menu && !e.target.closest('.vzx-swm')) { S.menu = false; draw(); } return; }
351
+ if (t.disabled) return;
128
352
  const k = t.dataset.x;
129
353
  if (k === 'end') return end();
130
- if (k === 'prev') return go(P.i - 1);
131
- if (k === 'next' || k === 'adv') return go(P.i + 1);
354
+ if (k === 'prev') return go(at() - 1);
355
+ if (k === 'next' || k === 'adv') return go(at() + 1);
356
+ if (k === 'go') return go(+t.dataset.i);
357
+ if (k === 'share' || k === 'front') return share();
358
+ if (k === 'menu') { S.menu = !S.menu; return draw(); }
359
+ if (k === 'mat') return switchTo(+t.dataset.i);
360
+ if (k === 'follow') { S.follow = !S.follow; return draw(); }
361
+ if (k === 'zin') return zoom(1.25);
362
+ if (k === 'zout') return zoom(0.8);
363
+ if (k === 'keepq' && onKeep) { t.disabled = true; const r = await onKeep(S.M.question); say(r && r.ok ? 'Kept in your notes as a question.' : 'Not kept: ' + ((r && r.error) || 'no answer')); }
364
+ };
365
+ /* image: scroll zooms, drag pans */
366
+ o.addEventListener('wheel', (e) => { if (!e.target.closest('[data-x-img]')) return; e.preventDefault(); zoom(e.deltaY < 0 ? 1.1 : 0.9); }, { passive: false });
367
+ /* the drag is read on the document (the image is no control: the zoom presses and the keys are its keyboard way) */
368
+ const panStart = (e) => {
369
+ const box = e.target.closest && e.target.closest('.vzx [data-x-img]'); if (!box || e.target.closest('button')) return;
370
+ const x0 = e.clientX, y0 = e.clientY, p0 = S.pan.slice();
371
+ const mv = (ev) => { S.pan = [p0[0] + ev.clientX - x0, p0[1] + ev.clientY - y0]; drawImg(o.querySelector('[data-x-img] img')); if (reach(W)) drawImg(W.document.querySelector('.vzx-imv img')); };
372
+ const up = () => { removeEventListener('pointermove', mv); removeEventListener('pointerup', up); };
373
+ addEventListener('pointermove', mv); addEventListener('pointerup', up);
374
+ };
375
+ document.addEventListener('pointerdown', panStart);
376
+ document.body.append(o); draw(); o.focus(); addEventListener('resize', onResize); document.addEventListener('keydown', key, true);
377
+ if (!W) say('The browser blocked the audience window. Allow pop-ups for PMOS, then press the share spot.');
378
+ await load(mat()); if (!ended) draw();
379
+ return { ok: true, end, go, at, cur: () => S.cur, blank: () => S.blank, win: () => W, switchTo, state: () => S };
380
+ }
381
+
382
+ /* ── the preview (XvAMaterialPreview): the material for the PM only, before it is shown. Present starts where the preview is. ── */
383
+ export const PREVIEW_LINE = 'only you see this. The meeting does not.';
384
+ /** The preview's markup (pure). P = { m (matOf), deck, doc, error, at, n } */
385
+ export function previewHtml(P, slideHtml = () => '') {
386
+ const m = P.m, at = P.at || 0;
387
+ const pres = `<button type="button" class="vzx-pvp" data-x="present" aria-label="Present${m.kind === 'slides' || m.kind === 'doc' ? ' from here' : ''}" title="Present">${ic('share', 18)}</button>`;
388
+ const count = P.deck ? P.deck.slides.length + ' slides' : P.doc ? P.doc.sections.length + ' sections' : '';
389
+ const head = `<div class="vzx-pvh"><p class="vzx-pvl">${esc([m.sub.replace(/ · live$/, ''), count, PREVIEW_LINE].filter(Boolean).join(' · '))}</p>${pres}</div>`;
390
+ let body;
391
+ if (P.error) body = `<div class="vzx-card"><p><b>${esc(m.title)}</b> could not be read: ${esc(P.error)}</p></div>`;
392
+ else if (m.kind === 'slides' && !P.deck) body = `<div class="vzx-card"><p>Reading ${esc(m.title)}.</p></div>`;
393
+ else if (m.kind === 'slides') {
394
+ const n = P.deck.slides.length;
395
+ body = `<div class="vzx-pvs"><div class="vzx-box" data-slide="${at}"></div></div>`
396
+ + `<div class="vzx-nav"><button type="button" class="vzx-ib" data-x="prev" aria-label="Previous slide"${at ? '' : ' disabled'}>${ic('prev', 16)}</button><div class="vzx-ths">${P.deck.slides.map((s, k) => `<button type="button" class="vzx-tb${k === at ? ' on' : ''}" data-x="go" data-i="${k}" aria-label="Slide ${k + 1}" aria-current="${k === at}"><span class="vzx-mini" aria-hidden="true">${slideHtml(s, P.deck.theme, '', false)}</span></button>`).join('')}</div><button type="button" class="vzx-ib" data-x="next" aria-label="Next slide"${at < n - 1 ? '' : ' disabled'}>${ic('next', 16)}</button></div>`
397
+ + `<p class="vzx-pvn">${at + 1} of ${n} · Present starts from here</p>`;
398
+ } else if (m.kind === 'doc' && !P.doc) body = `<div class="vzx-card"><p>Reading ${esc(m.title)}.</p></div>`;
399
+ else if (m.kind === 'doc') {
400
+ body = `<div class="vzx-stops">${P.doc.sections.map((s, k) => `<button type="button" class="${k === at ? 'on' : ''}" data-x="go" data-i="${k}" aria-current="${k === at}">${esc(clip(s.head, 40))}</button>`).join('')}</div>`
401
+ + '<div class="vzx-doc vzx-pvd" data-x-doc></div>'
402
+ + `<p class="vzx-pvn">Present starts from “${esc(clip(P.doc.sections[at] ? P.doc.sections[at].head : '', 60))}”</p>`;
403
+ } else if (m.kind === 'image') body = `<div class="vzx-pvi"><img alt="${esc(m.title)}" src="${esc(m.url)}"></div>`;
404
+ else if (m.kind === 'live' && /^\/api\/meeting-material\/file/.test(m.url)) body = `<iframe class="vzx-pvf" src="${esc(m.url)}" title="${esc(m.title)}"${/HTML/.test(m.sub) ? ' sandbox="allow-scripts allow-forms"' : ''}></iframe>`;
405
+ else if (m.kind === 'live') body = `<div class="vzx-card"><span class="vzx-url">${ic('link', 15)}<b>${esc(m.host || m.title)}</b></span><p>Present opens it live in the audience window, where you click and type and the call sees the same. Many sites cannot be shown inside PMOS, so look at it in its own tab first.</p><a class="vzx-btn" href="${esc(m.url)}" target="_blank" rel="noopener">Open in a new tab</a></div>`;
406
+ else body = `<div class="vzx-card"><p>PMOS cannot draw a PowerPoint file. Open it in PowerPoint or Keynote; to show it, share that app's window.</p>${m.url ? `<a class="vzx-btn" href="${esc(m.url)}" download>Download the file</a>` : ''}</div>`;
407
+ return `<div class="vzx-pv" data-kind="${m.kind}">${head}${body}</div>`;
408
+ }
409
+ export async function previewMaterial(body, item, { ws = '', at = 0, onAt = null, onPresent = null } = {}) {
410
+ const m = matOf(item);
411
+ sheets(document);
412
+ const { slideHtml } = await import('./premium-vw-slides.js');
413
+ const P = { m, deck: null, doc: null, error: '', at: Math.max(0, at || 0) };
414
+ const draw = () => {
415
+ if (!body.isConnected) return;
416
+ body.innerHTML = previewHtml(P, slideHtml);
417
+ const b = body.querySelector('.vzx-box[data-slide]');
418
+ if (b && P.deck) { b.innerHTML = slideHtml(P.deck.slides[P.at], P.deck.theme, m.ws || ws, false); fit(b, b.parentElement); place(b); }
419
+ body.querySelectorAll('.vzx-mini').forEach((x) => { x.style.setProperty('--bd-k', String(x.clientWidth / D.W)); place(x); });
420
+ const host = body.querySelector('[data-x-doc]');
421
+ if (host && P.doc) {
422
+ const page = document.createElement('div'); page.className = 'vzx-page';
423
+ P.doc.sections.forEach((s, k) => { const sec = document.createElement('div'); sec.className = 'vzx-sec' + (k === P.at ? ' spot' : ''); sec.append(...toDom(s.blocks, document)); page.append(sec); });
424
+ host.append(page); const sp = page.querySelector('.spot'); if (sp && sp.scrollIntoView) sp.scrollIntoView({ block: 'nearest' });
425
+ }
426
+ };
427
+ const n = () => (P.deck ? P.deck.slides.length : P.doc ? P.doc.sections.length : 1);
428
+ const go = (k) => { const j = Math.max(0, Math.min(n() - 1, k)); if (j !== P.at) { P.at = j; if (onAt) onAt(j); draw(); } };
429
+ body.onclick = (e) => {
430
+ const t = e.target.closest('[data-x]'); if (!t || t.disabled) return;
431
+ const k = t.dataset.x;
432
+ if (k === 'present') { if (onPresent) onPresent(P.at); return; }
433
+ if (k === 'prev') return go(P.at - 1);
434
+ if (k === 'next') return go(P.at + 1);
132
435
  if (k === 'go') return go(+t.dataset.i);
133
- if (k === 'win') return openWin();
134
- if (k === 'keepq' && onKeep) { t.disabled = true; const r = await onKeep(P.M.question); say(r && r.ok ? 'Kept in your notes as a question.' : 'Not kept: ' + ((r && r.error) || 'no answer')); }
135
436
  };
136
- document.body.append(o); draw(); o.focus(); addEventListener('resize', lay); document.addEventListener('keydown', key, true);
137
- return { ok: true, end, go, at: () => P.i, blank: () => P.blank, win: () => P.win };
437
+ draw();
438
+ if (m.kind === 'slides' || m.kind === 'doc') {
439
+ try { const text = await readDoc(m.ws || ws, m.src); if (m.kind === 'slides') P.deck = D.parseDeck(text, m.title); else P.doc = docSections(text, m.title); }
440
+ catch (x) { P.error = String((x && x.message) || x).slice(0, 160); }
441
+ if (P.deck && !P.deck.slides.length) P.error = 'the deck has no slides';
442
+ P.at = Math.min(P.at, Math.max(0, n() - 1));
443
+ draw();
444
+ }
445
+ return { ok: true, at: () => P.at };
138
446
  }