@flipbook-md/core 0.15.0 → 0.16.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.
- package/index.d.ts +14 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/public/announcer.html +12 -4
- package/public/app.js +366 -4
- package/public/index.html +23 -0
- package/public/styles.css +46 -0
- package/src/sourcemap.js +158 -0
package/index.d.ts
CHANGED
|
@@ -664,3 +664,17 @@ export class ReservedNameError extends Error {
|
|
|
664
664
|
code: "RESERVED_NAME";
|
|
665
665
|
field: "name";
|
|
666
666
|
}
|
|
667
|
+
|
|
668
|
+
// Source map extraction (US-38).
|
|
669
|
+
export type SourceMapBlockKind = "heading" | "paragraph" | "list_item" | "blockquote" | "code";
|
|
670
|
+
export interface SourceMapBlock {
|
|
671
|
+
line: number;
|
|
672
|
+
endLine: number;
|
|
673
|
+
kind: SourceMapBlockKind;
|
|
674
|
+
text: string;
|
|
675
|
+
}
|
|
676
|
+
export interface ExtractSlideSourceMapOptions {
|
|
677
|
+
lineOffset?: number;
|
|
678
|
+
slideIndex?: number;
|
|
679
|
+
}
|
|
680
|
+
export function extractSlideSourceMap(markdown: string, options?: ExtractSlideSourceMapOptions): SourceMapBlock[];
|
package/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./src/group-ops.js";
|
|
|
15
15
|
export * from "./src/presentation.js";
|
|
16
16
|
export * from "./src/server.js";
|
|
17
17
|
export * from "./src/slides.js";
|
|
18
|
+
export * from "./src/sourcemap.js";
|
|
18
19
|
export * from "./src/templates.js";
|
|
19
20
|
export * from "./src/theme.js";
|
|
20
21
|
export * from "./src/writer.js";
|
package/package.json
CHANGED
package/public/announcer.html
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
<span id="wall-clock" class="wall-clock" aria-label="Current time">--:--</span>
|
|
24
24
|
</div>
|
|
25
25
|
<div class="topbar-right">
|
|
26
|
+
<button id="laser-toggle" class="hud-button" type="button" aria-pressed="false" aria-label="Toggle laser pointer" title="Laser pointer (L)">● <span>Laser</span></button>
|
|
26
27
|
<a class="view-link" href="/" target="_blank" rel="noopener noreferrer">Deck</a>
|
|
27
28
|
<button id="fullscreen" class="icon-button" type="button" title="Toggle fullscreen (F)" aria-label="Toggle fullscreen">⛶</button>
|
|
28
29
|
</div>
|
|
@@ -44,15 +45,22 @@
|
|
|
44
45
|
</div>
|
|
45
46
|
</section>
|
|
46
47
|
|
|
47
|
-
<section class="notes-panel" aria-label="Speaker notes">
|
|
48
|
+
<section class="notes-panel" aria-label="Speaker notes and Q&A">
|
|
48
49
|
<div class="notes-header">
|
|
49
|
-
<
|
|
50
|
-
|
|
50
|
+
<div class="sidebar-tabs" role="tablist" aria-label="Presenter sidebar tabs">
|
|
51
|
+
<button id="tab-notes" class="sidebar-tab" type="button" role="tab" aria-selected="true" aria-controls="notes">Notes</button>
|
|
52
|
+
<button id="tab-qa" class="sidebar-tab" type="button" role="tab" aria-selected="false" aria-controls="qa-panel">Q&A <span id="qa-badge" class="qa-badge" hidden>0</span></button>
|
|
53
|
+
</div>
|
|
54
|
+
<div id="notes-scale-controls" class="notes-scale-controls" role="group" aria-label="Notes font size">
|
|
51
55
|
<button id="notes-scale-down" class="hud-button scale-button" type="button" aria-label="Decrease notes font size" title="Decrease notes font size">A-</button>
|
|
52
56
|
<button id="notes-scale-up" class="hud-button scale-button" type="button" aria-label="Increase notes font size" title="Increase notes font size">A+</button>
|
|
53
57
|
</div>
|
|
54
58
|
</div>
|
|
55
|
-
<div id="notes" class="notes-body" aria-live="polite"><p class="notes-empty">No notes for this slide.</p></div>
|
|
59
|
+
<div id="notes" class="notes-body" role="tabpanel" aria-labelledby="tab-notes" aria-live="polite"><p class="notes-empty">No notes for this slide.</p></div>
|
|
60
|
+
<div id="qa-panel" class="qa-panel" role="tabpanel" aria-labelledby="tab-qa" hidden>
|
|
61
|
+
<div id="qa-list" class="qa-list" aria-live="polite"></div>
|
|
62
|
+
<p id="qa-empty" class="qa-empty">No audience questions yet.</p>
|
|
63
|
+
</div>
|
|
56
64
|
</section>
|
|
57
65
|
</aside>
|
|
58
66
|
|
package/public/app.js
CHANGED
|
@@ -19,6 +19,25 @@ const timerDisplay = document.querySelector("#speaker-timer");
|
|
|
19
19
|
const timerToggle = document.querySelector("#timer-toggle");
|
|
20
20
|
const timerReset = document.querySelector("#timer-reset");
|
|
21
21
|
const wallClock = document.querySelector("#wall-clock");
|
|
22
|
+
const laserToggle = document.querySelector("#laser-toggle");
|
|
23
|
+
const laserDot = document.querySelector("#laser-dot");
|
|
24
|
+
const tabNotes = document.querySelector("#tab-notes");
|
|
25
|
+
const tabQa = document.querySelector("#tab-qa");
|
|
26
|
+
const qaBadge = document.querySelector("#qa-badge");
|
|
27
|
+
const notesScaleControls = document.querySelector("#notes-scale-controls");
|
|
28
|
+
const qaPanel = document.querySelector("#qa-panel");
|
|
29
|
+
const qaList = document.querySelector("#qa-list");
|
|
30
|
+
const qaEmpty = document.querySelector("#qa-empty");
|
|
31
|
+
const qaToggle = document.querySelector("#qa-toggle");
|
|
32
|
+
const qaDrawer = document.querySelector("#qa-drawer");
|
|
33
|
+
const qaClose = document.querySelector("#qa-close");
|
|
34
|
+
const qaForm = document.querySelector("#qa-form");
|
|
35
|
+
const qaAuthor = document.querySelector("#qa-author");
|
|
36
|
+
const qaInput = document.querySelector("#qa-input");
|
|
37
|
+
const qaStatus = document.querySelector("#qa-status");
|
|
38
|
+
const qaSpotlight = document.querySelector("#qa-spotlight");
|
|
39
|
+
const qaSpotlightText = document.querySelector("#qa-spotlight-text");
|
|
40
|
+
const qaSpotlightAuthor = document.querySelector("#qa-spotlight-author");
|
|
22
41
|
|
|
23
42
|
const tabId = Math.random().toString(36).slice(2);
|
|
24
43
|
let channel = null;
|
|
@@ -48,6 +67,19 @@ let speakerRunning = false;
|
|
|
48
67
|
let speakerStartedAt = 0;
|
|
49
68
|
let speakerInterval = null;
|
|
50
69
|
|
|
70
|
+
let laserActive = false;
|
|
71
|
+
let lastLaser = null;
|
|
72
|
+
let laserRaf = 0;
|
|
73
|
+
let laserPending = null;
|
|
74
|
+
|
|
75
|
+
let qaItems = [];
|
|
76
|
+
let qaDrawerOpen = false;
|
|
77
|
+
let remoteEventsEnabled = false;
|
|
78
|
+
let remoteQaEnabled = false;
|
|
79
|
+
let eventsUrl = "/api/present-events";
|
|
80
|
+
let qaUrl = "/api/qa";
|
|
81
|
+
let eventSource = null;
|
|
82
|
+
|
|
51
83
|
function mountSlide(host, { live = false } = {}) {
|
|
52
84
|
if (host.shadowRoot) return host.shadowRoot;
|
|
53
85
|
const shadow = host.attachShadow({ mode: "open" });
|
|
@@ -302,19 +334,42 @@ function applyRemote(message) {
|
|
|
302
334
|
remember();
|
|
303
335
|
}
|
|
304
336
|
|
|
305
|
-
|
|
306
|
-
const message = event.data;
|
|
337
|
+
function handleIncomingEvent(message) {
|
|
307
338
|
if (!message || message.tab === tabId) return;
|
|
308
339
|
if (message.type === "hello") {
|
|
309
340
|
if (leader) publish("play");
|
|
341
|
+
if (qaItems.length && document.body.classList.contains("announcer")) {
|
|
342
|
+
channel?.postMessage({ tab: tabId, type: "qa-sync", items: qaItems });
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (message.type === "laser") {
|
|
347
|
+
applyLaserEvent(message);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (message.type === "qa-submit" || message.type === "qa-update") {
|
|
351
|
+
if (message.item) upsertQaItem(message.item);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (message.type === "qa-sync" && Array.isArray(message.items)) {
|
|
355
|
+
message.items.forEach((item) => upsertQaItem(item));
|
|
310
356
|
return;
|
|
311
357
|
}
|
|
312
358
|
applyRemote(message);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
channel?.addEventListener("message", (event) => {
|
|
362
|
+
handleIncomingEvent(event.data);
|
|
313
363
|
});
|
|
314
364
|
|
|
315
365
|
// The tab that runs the timer tells the others to stop when it closes or reloads,
|
|
316
366
|
// so they do not keep showing Pause with nothing advancing.
|
|
317
367
|
window.addEventListener("pagehide", () => {
|
|
368
|
+
if (laserActive) setLaserActive(false);
|
|
369
|
+
if (eventSource) {
|
|
370
|
+
eventSource.close();
|
|
371
|
+
eventSource = null;
|
|
372
|
+
}
|
|
318
373
|
if (!leader || !playing) return;
|
|
319
374
|
clearTimer();
|
|
320
375
|
playing = false;
|
|
@@ -329,7 +384,7 @@ function hudHasFocus() {
|
|
|
329
384
|
|
|
330
385
|
function hideHud() {
|
|
331
386
|
if (!hud) return;
|
|
332
|
-
if (overviewOpen || hudHovered || hudHasFocus()) return;
|
|
387
|
+
if (overviewOpen || qaDrawerOpen || hudHovered || hudHasFocus()) return;
|
|
333
388
|
hud.classList.add("is-hidden");
|
|
334
389
|
}
|
|
335
390
|
|
|
@@ -340,7 +395,7 @@ function showHud() {
|
|
|
340
395
|
clearTimeout(hudHideTimer);
|
|
341
396
|
hudHideTimer = null;
|
|
342
397
|
}
|
|
343
|
-
if (!overviewOpen && !hudHovered && !hudHasFocus()) {
|
|
398
|
+
if (!overviewOpen && !qaDrawerOpen && !hudHovered && !hudHasFocus()) {
|
|
344
399
|
hudHideTimer = setTimeout(hideHud, HUD_IDLE_MS);
|
|
345
400
|
}
|
|
346
401
|
}
|
|
@@ -565,8 +620,302 @@ if (upNextRoot?.parentElement && typeof ResizeObserver !== "undefined") {
|
|
|
565
620
|
|
|
566
621
|
window.addEventListener("resize", () => {
|
|
567
622
|
if (overviewOpen) fitAllOverviewThumbs();
|
|
623
|
+
if (lastLaser?.active) positionLaserDot(lastLaser.x, lastLaser.y);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
/* Synced laser pointer (/announcer -> /) */
|
|
627
|
+
function emitPresentEvent(payload) {
|
|
628
|
+
channel?.postMessage(payload);
|
|
629
|
+
if (!remoteEventsEnabled) return;
|
|
630
|
+
fetch(eventsUrl, {
|
|
631
|
+
method: "POST",
|
|
632
|
+
headers: { "Content-Type": "application/json" },
|
|
633
|
+
body: JSON.stringify(payload)
|
|
634
|
+
}).catch(() => {});
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function positionLaserDot(x, y) {
|
|
638
|
+
if (!laserDot || !slideRoot) return;
|
|
639
|
+
const rect = slideRoot.getBoundingClientRect();
|
|
640
|
+
if (!rect.width || !rect.height) return;
|
|
641
|
+
const cx = Math.max(0, Math.min(1, x));
|
|
642
|
+
const cy = Math.max(0, Math.min(1, y));
|
|
643
|
+
laserDot.style.left = `${rect.left + cx * rect.width}px`;
|
|
644
|
+
laserDot.style.top = `${rect.top + cy * rect.height}px`;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function applyLaserEvent(message) {
|
|
648
|
+
if (!laserDot) return;
|
|
649
|
+
if (!message.active || !Number.isFinite(message.x) || !Number.isFinite(message.y)) {
|
|
650
|
+
lastLaser = null;
|
|
651
|
+
laserDot.hidden = true;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
lastLaser = { active: true, x: message.x, y: message.y };
|
|
655
|
+
positionLaserDot(message.x, message.y);
|
|
656
|
+
laserDot.hidden = false;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function setLaserActive(nextState) {
|
|
660
|
+
laserActive = Boolean(nextState);
|
|
661
|
+
if (laserToggle) laserToggle.setAttribute("aria-pressed", laserActive ? "true" : "false");
|
|
662
|
+
slideRoot?.classList.toggle("is-laser-active", laserActive);
|
|
663
|
+
if (!laserActive) {
|
|
664
|
+
laserPending = null;
|
|
665
|
+
if (laserRaf) {
|
|
666
|
+
cancelAnimationFrame(laserRaf);
|
|
667
|
+
laserRaf = 0;
|
|
668
|
+
}
|
|
669
|
+
emitPresentEvent({ tab: tabId, type: "laser", active: false });
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function sendLaserPointer(event) {
|
|
674
|
+
if (!laserActive || !slideRoot) return;
|
|
675
|
+
const rect = slideRoot.getBoundingClientRect();
|
|
676
|
+
if (!rect.width || !rect.height) return;
|
|
677
|
+
const x = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
|
|
678
|
+
const y = Math.max(0, Math.min(1, (event.clientY - rect.top) / rect.height));
|
|
679
|
+
laserPending = { tab: tabId, type: "laser", active: true, x, y };
|
|
680
|
+
if (!laserRaf) {
|
|
681
|
+
laserRaf = requestAnimationFrame(() => {
|
|
682
|
+
laserRaf = 0;
|
|
683
|
+
if (laserPending && laserActive) {
|
|
684
|
+
emitPresentEvent(laserPending);
|
|
685
|
+
laserPending = null;
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
if (laserToggle && slideRoot) {
|
|
692
|
+
laserToggle.addEventListener("click", () => setLaserActive(!laserActive));
|
|
693
|
+
slideRoot.addEventListener("pointermove", sendLaserPointer);
|
|
694
|
+
slideRoot.addEventListener("pointerdown", sendLaserPointer);
|
|
695
|
+
slideRoot.addEventListener("pointerleave", () => {
|
|
696
|
+
if (laserActive) emitPresentEvent({ tab: tabId, type: "laser", active: false });
|
|
697
|
+
});
|
|
698
|
+
slideRoot.addEventListener("pointercancel", () => {
|
|
699
|
+
if (laserActive) emitPresentEvent({ tab: tabId, type: "laser", active: false });
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/* Live audience Q&A (/ <-> /announcer) */
|
|
704
|
+
function setSidebarTab(tab) {
|
|
705
|
+
if (!tabNotes || !tabQa || !notesRoot || !qaPanel) return;
|
|
706
|
+
const isQa = tab === "qa";
|
|
707
|
+
tabNotes.setAttribute("aria-selected", isQa ? "false" : "true");
|
|
708
|
+
tabQa.setAttribute("aria-selected", isQa ? "true" : "false");
|
|
709
|
+
notesRoot.hidden = isQa;
|
|
710
|
+
if (notesScaleControls) notesScaleControls.hidden = isQa;
|
|
711
|
+
qaPanel.hidden = !isQa;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
tabNotes?.addEventListener("click", () => setSidebarTab("notes"));
|
|
715
|
+
tabQa?.addEventListener("click", () => setSidebarTab("qa"));
|
|
716
|
+
|
|
717
|
+
function renderQaSpotlight() {
|
|
718
|
+
if (!qaSpotlight || !qaSpotlightText || !qaSpotlightAuthor) return;
|
|
719
|
+
const highlighted = qaItems.find((item) => item.status === "highlighted");
|
|
720
|
+
if (!highlighted) {
|
|
721
|
+
qaSpotlight.hidden = true;
|
|
722
|
+
qaSpotlightText.textContent = "";
|
|
723
|
+
qaSpotlightAuthor.textContent = "";
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
qaSpotlightText.textContent = highlighted.text;
|
|
727
|
+
qaSpotlightAuthor.textContent = highlighted.author ? `— ${highlighted.author}` : "";
|
|
728
|
+
qaSpotlight.hidden = false;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function renderQaList() {
|
|
732
|
+
if (!qaList || !qaEmpty) return;
|
|
733
|
+
const visible = qaItems.filter((item) => item.status !== "dismissed");
|
|
734
|
+
const openCount = visible.filter((item) => item.status !== "answered").length;
|
|
735
|
+
if (qaBadge) {
|
|
736
|
+
qaBadge.textContent = String(openCount);
|
|
737
|
+
qaBadge.hidden = openCount === 0;
|
|
738
|
+
}
|
|
739
|
+
qaEmpty.hidden = visible.length > 0;
|
|
740
|
+
const fragment = document.createDocumentFragment();
|
|
741
|
+
visible.forEach((item) => {
|
|
742
|
+
const card = document.createElement("article");
|
|
743
|
+
card.className = "qa-item";
|
|
744
|
+
if (item.status === "highlighted") card.classList.add("is-highlighted");
|
|
745
|
+
if (item.status === "answered") card.classList.add("is-answered");
|
|
746
|
+
card.dataset.qaId = item.id;
|
|
747
|
+
|
|
748
|
+
const meta = document.createElement("div");
|
|
749
|
+
meta.className = "qa-item-meta";
|
|
750
|
+
const author = document.createElement("span");
|
|
751
|
+
author.className = "qa-item-author";
|
|
752
|
+
author.textContent = item.author || "Audience";
|
|
753
|
+
const status = document.createElement("span");
|
|
754
|
+
status.className = "qa-item-status";
|
|
755
|
+
status.textContent = item.status === "open" ? "" : item.status;
|
|
756
|
+
meta.append(author, status);
|
|
757
|
+
|
|
758
|
+
const text = document.createElement("p");
|
|
759
|
+
text.className = "qa-item-text";
|
|
760
|
+
text.textContent = item.text;
|
|
761
|
+
|
|
762
|
+
const actions = document.createElement("div");
|
|
763
|
+
actions.className = "qa-item-actions";
|
|
764
|
+
|
|
765
|
+
const highlightBtn = document.createElement("button");
|
|
766
|
+
highlightBtn.type = "button";
|
|
767
|
+
highlightBtn.className = "qa-action-btn";
|
|
768
|
+
highlightBtn.dataset.action = "highlight";
|
|
769
|
+
highlightBtn.setAttribute("aria-pressed", item.status === "highlighted" ? "true" : "false");
|
|
770
|
+
highlightBtn.textContent = item.status === "highlighted" ? "Unhighlight" : "Highlight";
|
|
771
|
+
highlightBtn.addEventListener("click", () => updateQaStatus(item.id, item.status === "highlighted" ? "open" : "highlighted"));
|
|
772
|
+
|
|
773
|
+
const answerBtn = document.createElement("button");
|
|
774
|
+
answerBtn.type = "button";
|
|
775
|
+
answerBtn.className = "qa-action-btn";
|
|
776
|
+
answerBtn.dataset.action = "answer";
|
|
777
|
+
answerBtn.textContent = "Answer";
|
|
778
|
+
answerBtn.addEventListener("click", () => updateQaStatus(item.id, "answered"));
|
|
779
|
+
|
|
780
|
+
const dismissBtn = document.createElement("button");
|
|
781
|
+
dismissBtn.type = "button";
|
|
782
|
+
dismissBtn.className = "qa-action-btn";
|
|
783
|
+
dismissBtn.dataset.action = "dismiss";
|
|
784
|
+
dismissBtn.textContent = "Dismiss";
|
|
785
|
+
dismissBtn.addEventListener("click", () => updateQaStatus(item.id, "dismissed"));
|
|
786
|
+
|
|
787
|
+
actions.append(highlightBtn, answerBtn, dismissBtn);
|
|
788
|
+
card.append(meta, text, actions);
|
|
789
|
+
fragment.appendChild(card);
|
|
790
|
+
});
|
|
791
|
+
qaList.replaceChildren(fragment);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function upsertQaItem(incoming) {
|
|
795
|
+
if (!incoming || typeof incoming.id !== "string" || typeof incoming.text !== "string") return;
|
|
796
|
+
if (incoming.status === "highlighted") {
|
|
797
|
+
qaItems.forEach((existing) => {
|
|
798
|
+
if (existing.id !== incoming.id && existing.status === "highlighted") existing.status = "open";
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
const idx = qaItems.findIndex((item) => item.id === incoming.id);
|
|
802
|
+
if (idx >= 0) qaItems[idx] = { ...qaItems[idx], ...incoming };
|
|
803
|
+
else qaItems.unshift({ ...incoming });
|
|
804
|
+
renderQaList();
|
|
805
|
+
renderQaSpotlight();
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function emitQaEvent(type, item) {
|
|
809
|
+
channel?.postMessage({ tab: tabId, type, item });
|
|
810
|
+
if (!remoteQaEnabled) return;
|
|
811
|
+
fetch(qaUrl, {
|
|
812
|
+
method: "POST",
|
|
813
|
+
headers: { "Content-Type": "application/json" },
|
|
814
|
+
body: JSON.stringify({ action: type, item })
|
|
815
|
+
}).catch(() => {});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function updateQaStatus(id, nextStatus) {
|
|
819
|
+
const item = qaItems.find((entry) => entry.id === id);
|
|
820
|
+
if (!item) return;
|
|
821
|
+
if (nextStatus === "highlighted") {
|
|
822
|
+
qaItems.forEach((entry) => {
|
|
823
|
+
if (entry.id !== id && entry.status === "highlighted") entry.status = "open";
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
item.status = nextStatus;
|
|
827
|
+
renderQaList();
|
|
828
|
+
renderQaSpotlight();
|
|
829
|
+
emitQaEvent("qa-update", { ...item });
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function openQaDrawer() {
|
|
833
|
+
if (!qaDrawer) return;
|
|
834
|
+
qaDrawerOpen = true;
|
|
835
|
+
qaDrawer.hidden = false;
|
|
836
|
+
qaToggle?.setAttribute("aria-expanded", "true");
|
|
837
|
+
if (qaStatus) qaStatus.textContent = "";
|
|
838
|
+
if (hudHideTimer) {
|
|
839
|
+
clearTimeout(hudHideTimer);
|
|
840
|
+
hudHideTimer = null;
|
|
841
|
+
}
|
|
842
|
+
qaInput?.focus();
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
function closeQaDrawer() {
|
|
846
|
+
if (!qaDrawer || !qaDrawerOpen) return;
|
|
847
|
+
qaDrawerOpen = false;
|
|
848
|
+
qaDrawer.hidden = true;
|
|
849
|
+
qaToggle?.setAttribute("aria-expanded", "false");
|
|
850
|
+
qaToggle?.focus();
|
|
851
|
+
showHud();
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function toggleQaDrawer() {
|
|
855
|
+
if (qaDrawerOpen) closeQaDrawer();
|
|
856
|
+
else openQaDrawer();
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
qaToggle?.addEventListener("click", toggleQaDrawer);
|
|
860
|
+
qaClose?.addEventListener("click", closeQaDrawer);
|
|
861
|
+
|
|
862
|
+
qaForm?.addEventListener("submit", (event) => {
|
|
863
|
+
event.preventDefault();
|
|
864
|
+
const text = qaInput?.value.trim() || "";
|
|
865
|
+
if (!text) return;
|
|
866
|
+
const author = qaAuthor?.value.trim() || "Audience";
|
|
867
|
+
const item = {
|
|
868
|
+
id: `qa-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`,
|
|
869
|
+
author,
|
|
870
|
+
text,
|
|
871
|
+
status: "open",
|
|
872
|
+
createdAt: Date.now()
|
|
873
|
+
};
|
|
874
|
+
upsertQaItem(item);
|
|
875
|
+
emitQaEvent("qa-submit", item);
|
|
876
|
+
if (qaInput) qaInput.value = "";
|
|
877
|
+
if (qaStatus) qaStatus.textContent = "Question sent!";
|
|
568
878
|
});
|
|
569
879
|
|
|
880
|
+
function connectRemoteStream() {
|
|
881
|
+
if (!remoteEventsEnabled || typeof EventSource === "undefined" || eventSource) return;
|
|
882
|
+
try {
|
|
883
|
+
eventSource = new EventSource(eventsUrl);
|
|
884
|
+
eventSource.onmessage = (event) => {
|
|
885
|
+
try {
|
|
886
|
+
handleIncomingEvent(JSON.parse(event.data));
|
|
887
|
+
} catch {
|
|
888
|
+
// Ignore malformed SSE payloads.
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
} catch {
|
|
892
|
+
eventSource = null;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
async function initRemoteBridge() {
|
|
897
|
+
if (presentation?.eventsUrl) eventsUrl = presentation.eventsUrl;
|
|
898
|
+
if (presentation?.qaUrl) qaUrl = presentation.qaUrl;
|
|
899
|
+
if (presentation?.capabilities?.events) remoteEventsEnabled = true;
|
|
900
|
+
if (presentation?.capabilities?.qa) remoteQaEnabled = true;
|
|
901
|
+
if (presentation?.capabilities?.remote !== false) {
|
|
902
|
+
try {
|
|
903
|
+
const res = await fetch(qaUrl);
|
|
904
|
+
if (res.ok) {
|
|
905
|
+
remoteQaEnabled = true;
|
|
906
|
+
if (presentation?.capabilities?.events !== false) remoteEventsEnabled = true;
|
|
907
|
+
const data = await res.json();
|
|
908
|
+
if (Array.isArray(data?.items)) {
|
|
909
|
+
data.items.forEach((item) => upsertQaItem(item));
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
} catch {
|
|
913
|
+
// Local BroadcastChannel-only mode.
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
connectRemoteStream();
|
|
917
|
+
}
|
|
918
|
+
|
|
570
919
|
async function boot() {
|
|
571
920
|
if (notesRoot) applyNotesScale(restoreNotesScale());
|
|
572
921
|
if (timerDisplay) updateTimerDisplay();
|
|
@@ -595,6 +944,7 @@ async function boot() {
|
|
|
595
944
|
render();
|
|
596
945
|
}
|
|
597
946
|
channel?.postMessage({ tab: tabId, type: "hello" });
|
|
947
|
+
initRemoteBridge();
|
|
598
948
|
showHud();
|
|
599
949
|
} catch (error) {
|
|
600
950
|
slideRoot.innerHTML = `<p class="loading">Could not load this presentation: ${escapeHtml(error.message)}</p>`;
|
|
@@ -621,6 +971,12 @@ function moveOverviewFocus(delta) {
|
|
|
621
971
|
}
|
|
622
972
|
|
|
623
973
|
document.addEventListener("keydown", (event) => {
|
|
974
|
+
if (qaDrawerOpen && event.key === "Escape") {
|
|
975
|
+
event.preventDefault();
|
|
976
|
+
event.stopPropagation();
|
|
977
|
+
closeQaDrawer();
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
624
980
|
if (["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement?.tagName)) return;
|
|
625
981
|
if (!presentation?.slides?.length) return;
|
|
626
982
|
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
@@ -673,6 +1029,12 @@ document.addEventListener("keydown", (event) => {
|
|
|
673
1029
|
} else if (event.key.toLowerCase() === "g" && overviewDialog) {
|
|
674
1030
|
event.preventDefault();
|
|
675
1031
|
toggleOverview();
|
|
1032
|
+
} else if (event.key.toLowerCase() === "l" && laserToggle) {
|
|
1033
|
+
event.preventDefault();
|
|
1034
|
+
setLaserActive(!laserActive);
|
|
1035
|
+
} else if (event.key.toLowerCase() === "q" && qaToggle) {
|
|
1036
|
+
event.preventDefault();
|
|
1037
|
+
toggleQaDrawer();
|
|
676
1038
|
}
|
|
677
1039
|
});
|
|
678
1040
|
|
package/public/index.html
CHANGED
|
@@ -13,8 +13,15 @@
|
|
|
13
13
|
<section id="slide" class="slide" aria-live="polite" aria-label="Current slide">
|
|
14
14
|
<p class="loading">Loading your slides…</p>
|
|
15
15
|
</section>
|
|
16
|
+
<div id="laser-dot" class="laser-dot" aria-hidden="true" hidden></div>
|
|
16
17
|
</main>
|
|
17
18
|
|
|
19
|
+
<aside id="qa-spotlight" class="qa-spotlight" aria-live="polite" hidden>
|
|
20
|
+
<div class="qa-spotlight-label">Audience Question</div>
|
|
21
|
+
<p id="qa-spotlight-text" class="qa-spotlight-text"></p>
|
|
22
|
+
<span id="qa-spotlight-author" class="qa-spotlight-author"></span>
|
|
23
|
+
</aside>
|
|
24
|
+
|
|
18
25
|
<nav class="hud" aria-label="Slide navigation">
|
|
19
26
|
<button id="previous" class="hud-button nav-button" type="button" aria-label="Previous slide" title="Previous slide (←)">←</button>
|
|
20
27
|
<div class="slide-meta">
|
|
@@ -25,6 +32,7 @@
|
|
|
25
32
|
<span class="hud-sep" aria-hidden="true"></span>
|
|
26
33
|
<button id="play" class="hud-button nav-button primary" type="button" aria-pressed="false" aria-label="Play" title="Play / Pause (P)">▶ <span>Play</span></button>
|
|
27
34
|
<button id="grid-toggle" class="hud-button nav-button" type="button" aria-expanded="false" aria-controls="overview-grid" aria-label="Slide overview" title="Slide overview (G)">▦ <span>Grid</span></button>
|
|
35
|
+
<button id="qa-toggle" class="hud-button nav-button" type="button" aria-expanded="false" aria-controls="qa-drawer" aria-label="Ask a question" title="Ask a question (Q)">💬 <span>Q&A</span></button>
|
|
28
36
|
<a class="view-link hud-button" href="/announcer" target="_blank" rel="noopener noreferrer" title="Open Presenter View">Presenter</a>
|
|
29
37
|
<button id="fullscreen" class="hud-button icon-button" type="button" title="Toggle fullscreen (F)" aria-label="Toggle fullscreen">⛶</button>
|
|
30
38
|
</nav>
|
|
@@ -36,5 +44,20 @@
|
|
|
36
44
|
</div>
|
|
37
45
|
<div id="overview-cards" class="overview-cards"></div>
|
|
38
46
|
</div>
|
|
47
|
+
|
|
48
|
+
<div id="qa-drawer" class="qa-drawer" role="dialog" aria-modal="true" aria-label="Ask a question" hidden>
|
|
49
|
+
<div class="qa-drawer-header">
|
|
50
|
+
<h2>Ask a question</h2>
|
|
51
|
+
<button id="qa-close" class="hud-button icon-button" type="button" aria-label="Close Q&A" title="Close (Esc)">✕</button>
|
|
52
|
+
</div>
|
|
53
|
+
<form id="qa-form" class="qa-form">
|
|
54
|
+
<input id="qa-author" class="qa-input" type="text" maxlength="60" placeholder="Your name (optional)" aria-label="Your name (optional)">
|
|
55
|
+
<textarea id="qa-input" class="qa-textarea" rows="3" maxlength="280" required placeholder="Type a short question for the speaker…" aria-label="Your question"></textarea>
|
|
56
|
+
<div class="qa-form-actions">
|
|
57
|
+
<span id="qa-status" class="qa-status" aria-live="polite"></span>
|
|
58
|
+
<button id="qa-submit" class="hud-button primary" type="submit">Send</button>
|
|
59
|
+
</div>
|
|
60
|
+
</form>
|
|
61
|
+
</div>
|
|
39
62
|
</body>
|
|
40
63
|
</html>
|
package/public/styles.css
CHANGED
|
@@ -97,6 +97,52 @@ body.announcer #slide{min-height:min(54vh,560px)!important;flex:1}
|
|
|
97
97
|
|
|
98
98
|
.controls{display:flex;align-items:center;gap:.8rem;padding:.35rem .1rem}
|
|
99
99
|
|
|
100
|
+
/* Laser pointer overlay (outside #slide) */
|
|
101
|
+
.laser-dot{position:fixed;z-index:30;width:20px;height:20px;border-radius:999px;background:radial-gradient(circle,rgba(255,95,109,.95) 0%,rgba(255,56,82,.72) 52%,rgba(255,56,82,0) 100%);box-shadow:0 0 16px 4px rgba(255,56,82,.45);transform:translate(-50%,-50%);pointer-events:none;transition:left 40ms linear,top 40ms linear,opacity 120ms ease}
|
|
102
|
+
.laser-dot[hidden]{display:none!important}
|
|
103
|
+
body.announcer #slide.is-laser-active{cursor:crosshair}
|
|
104
|
+
|
|
105
|
+
/* Presenter sidebar tabs & Q&A queue */
|
|
106
|
+
.sidebar-tabs{display:flex;align-items:center;gap:.35rem}
|
|
107
|
+
.sidebar-tab{border:1px solid transparent;background:transparent;color:var(--muted);padding:.26rem .6rem;border-radius:8px;font:inherit;font-size:.74rem;font-weight:700;letter-spacing:.08em;text-transform:uppercase;cursor:pointer;display:inline-flex;align-items:center;gap:.35rem}
|
|
108
|
+
.sidebar-tab:hover{color:var(--text);border-color:var(--line)}
|
|
109
|
+
.sidebar-tab[aria-selected="true"]{background:var(--panel-soft);color:var(--text);border-color:var(--line)}
|
|
110
|
+
.sidebar-tab:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
111
|
+
.qa-badge{display:inline-flex;align-items:center;justify-content:center;min-width:1.2rem;height:1.2rem;padding:0 .3rem;border-radius:999px;background:var(--mint);color:#0b1020;font-size:.68rem;font-weight:800;font-variant-numeric:tabular-nums}
|
|
112
|
+
.qa-badge[hidden]{display:none!important}
|
|
113
|
+
.qa-panel{flex:1;min-height:0;overflow:auto;display:flex;flex-direction:column;gap:.55rem}
|
|
114
|
+
.qa-panel[hidden]{display:none!important}
|
|
115
|
+
.qa-list{display:flex;flex-direction:column;gap:.55rem}
|
|
116
|
+
.qa-empty{margin:0;color:var(--muted);font-size:.9rem}
|
|
117
|
+
.qa-empty[hidden]{display:none!important}
|
|
118
|
+
.qa-item{display:flex;flex-direction:column;gap:.4rem;padding:.65rem .75rem;border-radius:12px;border:1px solid var(--line);background:var(--panel-soft)}
|
|
119
|
+
.qa-item.is-highlighted{border-color:var(--mint);box-shadow:0 0 0 1px var(--mint)}
|
|
120
|
+
.qa-item.is-answered{opacity:.65}
|
|
121
|
+
.qa-item-meta{display:flex;align-items:center;justify-content:space-between;gap:.5rem;font-size:.76rem;color:var(--muted)}
|
|
122
|
+
.qa-item-author{font-weight:700;color:var(--accent)}
|
|
123
|
+
.qa-item-status{font-size:.7rem;text-transform:uppercase;letter-spacing:.06em;color:var(--mint)}
|
|
124
|
+
.qa-item-text{margin:0;font-size:.9rem;line-height:1.4;color:var(--text);word-break:break-word}
|
|
125
|
+
.qa-item-actions{display:flex;flex-wrap:wrap;gap:.35rem}
|
|
126
|
+
.qa-action-btn{border:1px solid var(--line);background:#151e34;color:var(--text);padding:.24rem .55rem;border-radius:7px;font:inherit;font-size:.75rem;cursor:pointer}
|
|
127
|
+
.qa-action-btn:hover{border-color:var(--accent)}
|
|
128
|
+
.qa-action-btn[aria-pressed="true"]{background:var(--mint);color:#0b1020;border-color:var(--mint);font-weight:700}
|
|
129
|
+
|
|
130
|
+
/* Audience Q&A drawer & spotlight (outside #slide) */
|
|
131
|
+
.qa-drawer{position:fixed;right:clamp(.85rem,2.5vw,1.75rem);bottom:5rem;z-index:35;width:min(380px,92vw);padding:1rem;border-radius:16px;background:rgba(15,22,40,.96);backdrop-filter:blur(14px);border:1px solid rgba(255,255,255,.16);box-shadow:0 20px 48px rgba(0,0,0,.6);display:flex;flex-direction:column;gap:.75rem}
|
|
132
|
+
.qa-drawer[hidden]{display:none!important}
|
|
133
|
+
.qa-drawer-header{display:flex;align-items:center;justify-content:space-between;gap:.5rem}
|
|
134
|
+
.qa-drawer-header h2{margin:0;font-size:.95rem;font-weight:700;color:var(--text)}
|
|
135
|
+
.qa-form{display:flex;flex-direction:column;gap:.55rem}
|
|
136
|
+
.qa-input,.qa-textarea{width:100%;padding:.5rem .7rem;border-radius:10px;border:1px solid var(--line);background:var(--code);color:var(--text);font:inherit;font-size:.88rem;resize:vertical}
|
|
137
|
+
.qa-input:focus-visible,.qa-textarea:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
|
|
138
|
+
.qa-form-actions{display:flex;align-items:center;justify-content:space-between;gap:.5rem}
|
|
139
|
+
.qa-status{font-size:.8rem;color:var(--mint);min-height:1.1em}
|
|
140
|
+
.qa-spotlight{position:fixed;left:50%;top:clamp(.75rem,2vh,1.4rem);transform:translateX(-50%);z-index:25;max-width:min(680px,92vw);padding:.65rem 1rem;border-radius:14px;background:rgba(15,22,40,.92);backdrop-filter:blur(12px);border:1px solid var(--mint);box-shadow:0 14px 36px rgba(0,0,0,.5);display:flex;flex-direction:column;gap:.2rem;pointer-events:none}
|
|
141
|
+
.qa-spotlight[hidden]{display:none!important}
|
|
142
|
+
.qa-spotlight-label{font-size:.68rem;letter-spacing:.12em;text-transform:uppercase;color:var(--mint);font-weight:700}
|
|
143
|
+
.qa-spotlight-text{margin:0;font-size:.98rem;line-height:1.35;color:var(--text)}
|
|
144
|
+
.qa-spotlight-author{font-size:.78rem;color:var(--muted)}
|
|
145
|
+
|
|
100
146
|
@media(max-width:900px){
|
|
101
147
|
body.announcer .presenter-main{grid-template-columns:1fr;grid-template-rows:auto auto auto;grid-template-areas:"stage" "sidebar" "bottom"}
|
|
102
148
|
.notes-panel{max-height:30vh}
|
package/src/sourcemap.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { marked } from "marked";
|
|
2
|
+
import { ValidationError } from "./writer.js";
|
|
3
|
+
|
|
4
|
+
const FRONTMATTER = /^---[ \t]*\n(?:([\s\S]*?)\n)?---[ \t]*(?:\n|$)/;
|
|
5
|
+
const NOTES_COMMENT = /<!--\s*notes:[\s\S]*?-->/gi;
|
|
6
|
+
|
|
7
|
+
function countNewlines(text) {
|
|
8
|
+
let count = 0;
|
|
9
|
+
for (let i = 0; i < text.length; i++) {
|
|
10
|
+
if (text.charCodeAt(i) === 10) count++;
|
|
11
|
+
}
|
|
12
|
+
return count;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeText(markdown) {
|
|
16
|
+
if (markdown == null) return "";
|
|
17
|
+
const str = String(markdown);
|
|
18
|
+
const withoutBom = str.startsWith("\uFEFF") ? str.slice(1) : str;
|
|
19
|
+
return withoutBom.replace(/\r\n/g, "\n");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function singleFileSlideSpans(text) {
|
|
23
|
+
const fm = FRONTMATTER.exec(text);
|
|
24
|
+
const start = fm ? fm[0].length : 0;
|
|
25
|
+
const notes = [...text.matchAll(NOTES_COMMENT)].map((match) => [match.index, match.index + match[0].length]);
|
|
26
|
+
const inNotes = (offset) => notes.some(([from, to]) => offset > from && offset < to);
|
|
27
|
+
const spans = [];
|
|
28
|
+
let chunkStart = start;
|
|
29
|
+
let position = start;
|
|
30
|
+
while (position < text.length) {
|
|
31
|
+
const newline = text.indexOf("\n", position);
|
|
32
|
+
const lineEnd = newline === -1 ? text.length : newline;
|
|
33
|
+
const next = newline === -1 ? text.length : newline + 1;
|
|
34
|
+
if (text.slice(position, lineEnd).trim() === "---" && !inNotes(position)) {
|
|
35
|
+
spans.push([chunkStart, position]);
|
|
36
|
+
chunkStart = next;
|
|
37
|
+
}
|
|
38
|
+
position = next;
|
|
39
|
+
}
|
|
40
|
+
spans.push([chunkStart, text.length]);
|
|
41
|
+
return spans.filter(([from, to]) => text.slice(from, to).trim());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function extractInlineText(tokens) {
|
|
45
|
+
let out = "";
|
|
46
|
+
for (const token of tokens ?? []) {
|
|
47
|
+
if (token.type === "image") {
|
|
48
|
+
out += token.text ?? "";
|
|
49
|
+
} else if (token.tokens?.length) {
|
|
50
|
+
out += extractInlineText(token.tokens);
|
|
51
|
+
} else {
|
|
52
|
+
out += token.text ?? "";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function extractBlockText(tokens, fallback = "") {
|
|
59
|
+
const parts = [];
|
|
60
|
+
for (const token of tokens ?? []) {
|
|
61
|
+
if (token.type === "space" || token.type === "hr" || token.type === "html") continue;
|
|
62
|
+
if (token.type === "heading" || token.type === "paragraph") {
|
|
63
|
+
parts.push(extractInlineText(token.tokens));
|
|
64
|
+
} else if (token.type === "text") {
|
|
65
|
+
parts.push(token.tokens?.length ? extractInlineText(token.tokens) : (token.text ?? ""));
|
|
66
|
+
} else if (token.type === "list") {
|
|
67
|
+
for (const item of token.items ?? []) {
|
|
68
|
+
parts.push(extractBlockText(item.tokens, item.text));
|
|
69
|
+
}
|
|
70
|
+
} else if (token.type === "blockquote") {
|
|
71
|
+
parts.push(extractBlockText(token.tokens, token.text));
|
|
72
|
+
} else if (token.type === "code") {
|
|
73
|
+
parts.push(token.text ?? "");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const joined = parts.map((part) => part.trim()).filter(Boolean).join("\n").trim();
|
|
77
|
+
return joined || String(fallback ?? "").trim();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function lineSpan(raw, startLine) {
|
|
81
|
+
const withoutLeading = raw.replace(/^\n+/, "");
|
|
82
|
+
const leading = countNewlines(raw) - countNewlines(withoutLeading);
|
|
83
|
+
const trimmed = withoutLeading.replace(/\n+$/, "");
|
|
84
|
+
const line = startLine + leading;
|
|
85
|
+
const endLine = line + countNewlines(trimmed);
|
|
86
|
+
return { line, endLine };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Extracts 1-based `{ line, endLine, kind, text }` source-map entries for top-level
|
|
91
|
+
* headings, paragraphs, list items, blockquotes, and fenced code blocks in a slide.
|
|
92
|
+
* Accounts for YAML frontmatter, HTML comment directives/notes, and optional
|
|
93
|
+
* `lineOffset` or `slideIndex` (for multi-slide single-file decks).
|
|
94
|
+
*/
|
|
95
|
+
export function extractSlideSourceMap(markdown, options = {}) {
|
|
96
|
+
const lineOffset = options?.lineOffset ?? 0;
|
|
97
|
+
if (!Number.isInteger(lineOffset) || lineOffset < 0) {
|
|
98
|
+
throw new ValidationError("lineOffset must be a non-negative integer.", { field: "lineOffset" });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const normalized = normalizeText(markdown);
|
|
102
|
+
if (!normalized) return [];
|
|
103
|
+
|
|
104
|
+
let body;
|
|
105
|
+
let baseLine;
|
|
106
|
+
if (options?.slideIndex != null) {
|
|
107
|
+
if (!Number.isInteger(options.slideIndex) || options.slideIndex < 0) {
|
|
108
|
+
throw new ValidationError("slideIndex must be a non-negative integer.", { field: "slideIndex" });
|
|
109
|
+
}
|
|
110
|
+
const spans = singleFileSlideSpans(normalized);
|
|
111
|
+
const span = spans[options.slideIndex];
|
|
112
|
+
if (!span) return [];
|
|
113
|
+
body = normalized.slice(span[0], span[1]);
|
|
114
|
+
baseLine = 1 + lineOffset + countNewlines(normalized.slice(0, span[0]));
|
|
115
|
+
} else {
|
|
116
|
+
const fm = FRONTMATTER.exec(normalized);
|
|
117
|
+
const fmLines = fm ? countNewlines(fm[0]) : 0;
|
|
118
|
+
body = fm ? normalized.slice(fm[0].length) : normalized;
|
|
119
|
+
baseLine = 1 + lineOffset + fmLines;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const tokens = marked.lexer(body, { gfm: true, breaks: false });
|
|
123
|
+
const entries = [];
|
|
124
|
+
let currentLine = baseLine;
|
|
125
|
+
|
|
126
|
+
for (const token of tokens) {
|
|
127
|
+
const raw = token.raw ?? "";
|
|
128
|
+
if (token.type === "heading") {
|
|
129
|
+
const { line, endLine } = lineSpan(raw, currentLine);
|
|
130
|
+
const text = (extractInlineText(token.tokens) || token.text || "").trim();
|
|
131
|
+
entries.push({ line, endLine, kind: "heading", text });
|
|
132
|
+
} else if (token.type === "paragraph") {
|
|
133
|
+
const { line, endLine } = lineSpan(raw, currentLine);
|
|
134
|
+
const text = (extractInlineText(token.tokens) || token.text || "").trim();
|
|
135
|
+
entries.push({ line, endLine, kind: "paragraph", text });
|
|
136
|
+
} else if (token.type === "list") {
|
|
137
|
+
let itemLine = currentLine;
|
|
138
|
+
for (const item of token.items ?? []) {
|
|
139
|
+
const itemRaw = item.raw ?? "";
|
|
140
|
+
const { line, endLine } = lineSpan(itemRaw, itemLine);
|
|
141
|
+
const text = extractBlockText(item.tokens, item.text);
|
|
142
|
+
entries.push({ line, endLine, kind: "list_item", text });
|
|
143
|
+
itemLine += countNewlines(itemRaw);
|
|
144
|
+
}
|
|
145
|
+
} else if (token.type === "blockquote") {
|
|
146
|
+
const { line, endLine } = lineSpan(raw, currentLine);
|
|
147
|
+
const text = extractBlockText(token.tokens, token.text);
|
|
148
|
+
entries.push({ line, endLine, kind: "blockquote", text });
|
|
149
|
+
} else if (token.type === "code") {
|
|
150
|
+
const { line, endLine } = lineSpan(raw, currentLine);
|
|
151
|
+
const text = String(token.text ?? "").trim();
|
|
152
|
+
entries.push({ line, endLine, kind: "code", text });
|
|
153
|
+
}
|
|
154
|
+
currentLine += countNewlines(raw);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return entries;
|
|
158
|
+
}
|