-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresenter.html
More file actions
323 lines (308 loc) · 14.5 KB
/
Copy pathpresenter.html
File metadata and controls
323 lines (308 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Presenter</title>
<link rel="icon" href="/__dm/brand/icons/32x32.png">
<link rel="stylesheet" href="/__dm/cue.css">
<style>
* { box-sizing:border-box; margin:0; padding:0; }
html, body { height:100%; }
body { background:var(--cue-canvas); color:var(--cue-ink); font-family:var(--cue-sans);
-webkit-font-smoothing:antialiased; display:flex; flex-direction:column; overflow:hidden; }
header { display:flex; align-items:center; gap:18px; padding:12px 18px;
border-bottom:1px solid var(--cue-line); flex-shrink:0; }
.title { font-size:15px; font-weight:550; letter-spacing:-.015em;
white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.spacer { flex:1; }
.clockbox { display:flex; align-items:center; gap:14px;
font-family:var(--cue-mono); font-size:13px; color:var(--cue-ink-3); }
.elapsed { font-size:19px; font-weight:500; color:var(--cue-ink);
min-width:82px; text-align:right; font-variant-numeric:tabular-nums; }
/* header controls share the toolbar treatment */
.tbtn { font-family:var(--cue-sans); font-size:12px; color:var(--cue-ink-2);
background:transparent; border:1px solid var(--cue-line); border-radius:var(--cue-r-md);
padding:7px 11px; cursor:pointer;
transition:color .3s var(--cue-ease), background .3s var(--cue-ease), border-color .3s var(--cue-ease); }
.tbtn:hover { color:var(--cue-ink); background:var(--cue-raised-2); }
.tbtn:focus-visible { outline:2px solid var(--cue-focus); outline-offset:2px; }
.tbtn.primary { color:var(--cue-ink); background:var(--cue-raised-3); }
.tbtn.primary:hover { background:#2C2C31; }
.anngroup { display:flex; gap:6px; padding-right:12px; margin-right:2px;
border-right:1px solid var(--cue-line); }
.tbtn.ann { min-width:34px; padding:7px 9px; }
/* the one place colour is allowed: an armed annotation tool */
.tbtn.ann.on { color:var(--cue-canvas); background:var(--cue-ink); border-color:var(--cue-ink); }
main { flex:1; display:grid; grid-template-columns:minmax(0,1fr) 372px; gap:14px;
padding:14px 18px; min-height:0; }
.cur { display:flex; flex-direction:column; min-width:0; min-height:0; }
.frame { position:relative; background:#000; border:1px solid var(--cue-line);
border-radius:var(--cue-r-md); overflow:hidden; flex:1; min-height:0; }
.frame iframe { width:1920px; height:1080px; border:0; transform-origin:0 0;
position:absolute; pointer-events:none; }
.lab { font-size:12px; color:var(--cue-ink-3); margin:0 0 7px 2px; }
aside { display:flex; flex-direction:column; gap:14px; min-height:0; }
.next .frame { aspect-ratio:16/9; flex:none; }
.notes { flex:1; display:flex; flex-direction:column; min-height:0; }
.notes .body { flex:1; overflow:auto; background:var(--cue-raised);
border:1px solid var(--cue-line); border-radius:var(--cue-r-md);
padding:15px 17px; font-size:16px; line-height:1.6; color:var(--cue-ink);
white-space:pre-wrap; }
.notes .body:empty::before { content:'No notes for this slide.'; color:var(--cue-ink-3); }
footer { display:flex; align-items:center; gap:14px; padding:8px 18px 12px; flex-shrink:0; }
.count { font-family:var(--cue-mono); font-size:14px; color:var(--cue-ink-2);
font-variant-numeric:tabular-nums; }
.hint { font-family:var(--cue-mono); font-size:11px; color:var(--cue-ink-3); }
.navbtn { font-size:16px; width:40px; height:32px; border-radius:var(--cue-r-md);
border:1px solid var(--cue-line); background:var(--cue-raised-2); color:var(--cue-ink);
cursor:pointer; transition:background .3s var(--cue-ease); }
.navbtn:hover { background:var(--cue-raised-3); }
.navbtn:focus-visible { outline:2px solid var(--cue-focus); outline-offset:2px; }
@media (prefers-reduced-motion:reduce){ .tbtn,.navbtn{transition:none} }
@media (max-width:900px){ main{grid-template-columns:1fr; grid-template-rows:1fr auto} }
</style>
</head>
<body>
<header>
<div class="title" id="title">…</div>
<div class="spacer"></div>
<div class="clockbox">
<span id="clock">--:--</span>
<span class="elapsed" id="elapsed">00:00</span>
<button class="tbtn" id="timer-toggle">Start</button>
<button class="tbtn" id="timer-reset">Reset</button>
</div>
<span class="anngroup">
<button class="tbtn ann" id="ann-laser">◉</button>
<button class="tbtn ann" id="ann-pen">✎</button>
<button class="tbtn ann" id="ann-black" title="Black the shared screen (B)">■</button>
<button class="tbtn ann" id="ann-clear" title="Erase the ink on this slide (E)">Erase</button>
</span>
<button class="tbtn primary" id="audience">Play slideshow</button>
</header>
<main>
<div class="cur">
<div class="lab">Current slide</div>
<div class="frame" id="cur-frame"><iframe id="cur"></iframe></div>
</div>
<aside>
<div class="next">
<div class="lab">Next slide</div>
<div class="frame" id="next-frame"><iframe id="next"></iframe></div>
</div>
<div class="notes">
<div class="lab">Notes</div>
<div class="body" id="notes"></div>
</div>
</aside>
</main>
<footer>
<button class="navbtn" id="prev">←</button>
<button class="navbtn" id="next-btn">→</button>
<span class="count"><span id="cur-n">1</span> / <span id="total-n">?</span></span>
<div class="spacer"></div>
<span class="hint">← → SPACE navigate · L laser · P pen · B black · E erase</span>
</footer>
<script>
(async () => {
const params = new URLSearchParams(location.search);
const deckPath = params.get('deck');
if (!deckPath) { document.getElementById('title').textContent = 'No deck specified'; return; }
const deckPathname = '/files/' + deckPath.split('/').map(encodeURIComponent).join('/');
// Slide-position sync goes through the server's SSE bus (same as the deck
// windows) so the presenter, slideshow and editor stay aligned across
// separate browsers and native app windows.
const clientId = Math.random().toString(36).slice(2);
function publish() {
fetch('/api/sync', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ deck: deckPath, index, id: clientId }), keepalive: true,
}).catch(() => {});
}
// --- deck metadata: parse the source file (same origin) for notes/labels
let total = 0, notes = [], labels = [], skipped = new Set();
try {
const doc = new DOMParser().parseFromString(
await (await fetch(deckPathname + '?raw=1')).text(), 'text/html');
let legacy = [];
const legacyTag = doc.getElementById('speaker-notes');
if (legacyTag) { try { legacy = JSON.parse(legacyTag.textContent) || []; } catch {} }
const sections = Array.from(doc.querySelectorAll('deck-stage > section, x-import > section'));
total = sections.length;
sections.forEach((s, i) => {
notes[i] = s.getAttribute('data-speaker-notes') || legacy[i] || '';
labels[i] = s.getAttribute('data-label') || s.getAttribute('data-screen-label') || 'Slide ' + (i + 1);
if (s.hasAttribute('data-deck-skip')) skipped.add(i);
});
const t = doc.querySelector('title');
document.getElementById('title').textContent = (t ? t.textContent : deckPath) + ' — Presenter';
} catch (e) { console.error(e); }
document.getElementById('total-n').textContent = total || '?';
// --- preview iframes (deck pages in follow mode; _snthumb keeps chrome off)
const cur = document.getElementById('cur');
const nxt = document.getElementById('next');
cur.src = deckPathname + '?_snthumb=1&_dmfollow=cur#1';
nxt.src = deckPathname + '?_snthumb=1&_dmfollow=next#2';
let curFit = { left: 0, top: 0, s: 1 };
function fit(frame, holder) {
const w = holder.clientWidth, h = holder.clientHeight;
const s = Math.min(w / 1920, h / 1080);
// transform-origin is 0 0, so scale from the top-left and center by
// offsetting with the *scaled* dimensions (a percentage translate would
// shift by the unscaled 1920×1080 and push the slide out of the frame).
const left = (w - 1920 * s) / 2, top = (h - 1080 * s) / 2;
frame.style.left = left + 'px';
frame.style.top = top + 'px';
frame.style.transform = 'scale(' + s + ')';
if (frame === cur) curFit = { left, top, s };
}
const cf = document.getElementById('cur-frame'), nf = document.getElementById('next-frame');
new ResizeObserver(() => fit(cur, cf)).observe(cf);
new ResizeObserver(() => fit(nxt, nf)).observe(nf);
// --- annotation: drive the shared slideshow window from here --------------
// Ephemeral events go out on /api/cue; the slideshow window renders them.
let annTool = 'off';
const cue = (ev) => fetch('/api/cue', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ deck: deckPath, ev, id: clientId }), keepalive: true,
}).catch(() => {});
const annBtns = {};
function setAnn(t) {
annTool = annTool === t ? 'off' : t;
for (const [k, b] of Object.entries(annBtns)) b.classList.toggle('on', k === annTool);
cf.style.cursor = annTool === 'off' ? '' : 'crosshair';
cue({ t: 'tool', tool: annTool });
}
for (const [key, label, title] of [
['laser', '◉', 'Laser pointer — move over the slide below (L)'],
['pen', '✎', 'Draw — drag over the slide below (P)'],
]) {
const b = document.getElementById('ann-' + key);
annBtns[key] = b;
b.title = title;
b.addEventListener('click', () => setAnn(key));
}
document.getElementById('ann-black').addEventListener('click', function () {
this.classList.toggle('on');
cue({ t: 'blackout', mode: this.classList.contains('on') ? 'black' : null });
});
document.getElementById('ann-clear').addEventListener('click', () => cue({ t: 'clear' }));
// Map a pointer over the current-slide preview to normalized slide coords.
function normFromEvent(e) {
const r = cf.getBoundingClientRect();
const x = (e.clientX - r.left - curFit.left) / (1920 * curFit.s);
const y = (e.clientY - r.top - curFit.top) / (1080 * curFit.s);
return (x >= 0 && x <= 1 && y >= 0 && y <= 1) ? { x, y } : null;
}
let penDown = false, sendAt = 0;
cf.addEventListener('pointermove', (e) => {
if (annTool === 'off') return;
const n = normFromEvent(e);
if (!n) return;
const now = performance.now();
if (now - sendAt < 40) return; // ~25 updates/s is plenty
sendAt = now;
if (annTool === 'pen' && !penDown) return; // pen only paints while held
cue({ t: 'ptr', x: n.x, y: n.y, tool: annTool });
});
cf.addEventListener('pointerdown', (e) => {
if (annTool !== 'pen') return;
const n = normFromEvent(e);
if (!n) return;
penDown = true;
cf.setPointerCapture(e.pointerId);
cue({ t: 'ptr', x: n.x, y: n.y, tool: 'pen', start: true });
});
const penUp = (e) => {
if (!penDown) return;
penDown = false;
const n = normFromEvent(e) || { x: 0, y: 0 };
cue({ t: 'ptr', x: n.x, y: n.y, tool: 'pen', end: true });
};
cf.addEventListener('pointerup', penUp);
cf.addEventListener('pointercancel', penUp);
// --- shared index
let index = 0;
function render() {
document.getElementById('cur-n').textContent = index + 1;
document.getElementById('notes').textContent = notes[index] || '';
}
// The previews are same-origin iframes we created, so we move them by hand.
// They used to follow over the SSE bus, which cost a connection each — see
// the connection-budget note in presenter.js.
function syncPreviews() {
for (const f of [cur, nxt]) {
try { f.contentWindow && f.contentWindow.__cueFollow && f.contentWindow.__cueFollow(index); } catch {}
}
}
function goTo(i) {
index = Math.max(0, Math.min(i, (total || 1) - 1));
render();
syncPreviews(); // the two previews in this window
publish(); // any slideshow window, and the deck's own windows
startTimerOnce();
}
function step(dir) {
let i = index + dir;
while (skipped.has(i) && i > 0 && i < total - 1) i += dir;
goTo(i);
}
// Follow remote navigation (slideshow / editor advancing on their own).
const es = new EventSource('/api/sync?deck=' + encodeURIComponent(deckPath));
es.onmessage = (ev) => {
let m; try { m = JSON.parse(ev.data); } catch { return; }
if (m.id === clientId) return;
if (typeof m.index !== 'number' || !Number.isFinite(m.index)) return; // annotation event
if (m.index !== index) { index = Math.max(0, Math.min(m.index, (total || 1) - 1)); render(); syncPreviews(); startTimerOnce(); }
};
// Re-publish once previews finish loading so late iframes catch up.
cur.addEventListener('load', () => setTimeout(() => { syncPreviews(); publish(); }, 300));
nxt.addEventListener('load', () => setTimeout(() => { syncPreviews(); publish(); }, 300));
// --- controls
document.getElementById('prev').addEventListener('click', () => step(-1));
document.getElementById('next-btn').addEventListener('click', () => step(1));
document.getElementById('audience').addEventListener('click', () => {
// The clean, shareable slideshow window (no rail/overlay/toolbar).
window.open(deckPathname + '?_dmshow=1#' + (index + 1), 'dm-slideshow');
});
window.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === ' ' || e.key === 'PageDown') { e.preventDefault(); step(1); }
else if (e.key === 'ArrowLeft' || e.key === 'PageUp') { e.preventDefault(); step(-1); }
else if (e.key === 'Home') goTo(0);
else if (e.key === 'End') goTo(total - 1);
});
// --- clock + elapsed timer
const clock = document.getElementById('clock');
setInterval(() => {
clock.textContent = new Date().toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
}, 1000);
let t0 = null, acc = 0, tick = null;
const elapsed = document.getElementById('elapsed');
const toggle = document.getElementById('timer-toggle');
function fmt(ms) {
const s = Math.floor(ms / 1000);
const m = Math.floor(s / 60);
return String(m).padStart(2, '0') + ':' + String(s % 60).padStart(2, '0');
}
function startTimer() {
if (tick) return;
t0 = Date.now();
tick = setInterval(() => { elapsed.textContent = fmt(acc + Date.now() - t0); }, 500);
toggle.textContent = 'Pause';
}
function pauseTimer() {
if (!tick) return;
acc += Date.now() - t0;
clearInterval(tick); tick = null;
toggle.textContent = 'Start';
}
function startTimerOnce() { if (!tick && acc === 0) startTimer(); }
toggle.addEventListener('click', () => (tick ? pauseTimer() : startTimer()));
document.getElementById('timer-reset').addEventListener('click', () => {
pauseTimer(); acc = 0; elapsed.textContent = '00:00';
});
render();
})();
</script>
</body>
</html>