@signalsafe/slide-editor-react 0.0.0-stage → 0.1.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/RELEASING.md +44 -0
- package/dist/ResponsiveViewport.d.ts +14 -0
- package/dist/ResponsiveViewport.js +20 -0
- package/dist/SlideEditor.d.ts +20 -0
- package/dist/SlideEditor.js +31 -0
- package/dist/SlideInteractions.d.ts +22 -0
- package/dist/SlideInteractions.js +17 -0
- package/dist/SlideOutline.d.ts +16 -0
- package/dist/SlideOutline.js +14 -0
- package/dist/SlideOverview.d.ts +10 -0
- package/dist/SlideOverview.js +34 -0
- package/dist/SlidePlaybackControls.d.ts +10 -0
- package/dist/SlidePlaybackControls.js +22 -0
- package/dist/SlidePlayer.d.ts +13 -0
- package/dist/SlidePlayer.js +26 -0
- package/dist/SpeechControls.d.ts +21 -0
- package/dist/SpeechControls.js +182 -0
- package/dist/deck.d.ts +26 -0
- package/dist/deck.js +47 -0
- package/dist/narration.d.ts +10 -0
- package/dist/narration.js +37 -0
- package/dist/narrationDom.d.ts +3 -0
- package/dist/narrationDom.js +14 -0
- package/dist/slide-editor.css +55 -0
- package/dist/source-manifest.json +21 -0
- package/dist/thumbnailObservers.d.ts +2 -0
- package/dist/thumbnailObservers.js +27 -0
- package/dist/useCanvasOverflow.d.ts +8 -0
- package/dist/useCanvasOverflow.js +51 -0
- package/dist/usePlayback.d.ts +14 -0
- package/dist/usePlayback.js +70 -0
- package/dist/validationIssueRows.d.ts +6 -0
- package/dist/validationIssueRows.js +10 -0
- package/docs/README.md +42 -0
- package/docs/current-state-summary.md +34 -0
- package/package.json +139 -5
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { narrationStart } from './narration.js';
|
|
5
|
+
function narrationStatus(supported, enabled, status) {
|
|
6
|
+
if (!supported)
|
|
7
|
+
return 'Text-to-speech unavailable; playback will run silently.';
|
|
8
|
+
if (!enabled)
|
|
9
|
+
return 'Narration off';
|
|
10
|
+
return status;
|
|
11
|
+
}
|
|
12
|
+
function invalidateChangedNarration(session, synth, resolveText, setSpokenText, onBusyChange) {
|
|
13
|
+
const { current, speechPaused, processed } = session;
|
|
14
|
+
const active = current.current;
|
|
15
|
+
const updatedText = active && resolveText?.(active.segment);
|
|
16
|
+
if (!active || updatedText == null || updatedText === active.utterance.text)
|
|
17
|
+
return;
|
|
18
|
+
current.current = null;
|
|
19
|
+
speechPaused.current = false;
|
|
20
|
+
processed.current -= 1;
|
|
21
|
+
synth.cancel();
|
|
22
|
+
setSpokenText('');
|
|
23
|
+
onBusyChange(false);
|
|
24
|
+
}
|
|
25
|
+
function pauseOrResumeNarration(session, synth, playing, setStatus) {
|
|
26
|
+
const { current, speechPaused } = session;
|
|
27
|
+
if (!playing) {
|
|
28
|
+
if (current.current && !speechPaused.current) {
|
|
29
|
+
synth.pause();
|
|
30
|
+
speechPaused.current = true;
|
|
31
|
+
setStatus('Narration paused');
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (!current.current)
|
|
36
|
+
return false;
|
|
37
|
+
if (speechPaused.current) {
|
|
38
|
+
synth.resume();
|
|
39
|
+
speechPaused.current = false;
|
|
40
|
+
setStatus('Reading slide');
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function nextNarrationSegment(segments, processed, timeMs) {
|
|
45
|
+
let nextIndex = processed.current + 1;
|
|
46
|
+
let segment = segments[nextIndex];
|
|
47
|
+
while (segment && segment.atMs <= timeMs && segment.untilMs !== undefined && timeMs >= segment.untilMs) {
|
|
48
|
+
processed.current = nextIndex;
|
|
49
|
+
nextIndex++;
|
|
50
|
+
segment = segments[nextIndex];
|
|
51
|
+
}
|
|
52
|
+
return { segment, nextIndex };
|
|
53
|
+
}
|
|
54
|
+
function beginNarration(session, synth, next, renderedText, segment, nextIndex, callbacks) {
|
|
55
|
+
const { current, processed } = session;
|
|
56
|
+
const { setSpokenText, setTurn, onBusyChange, setStatus, setError, onError } = callbacks;
|
|
57
|
+
current.current = { utterance: next, segment };
|
|
58
|
+
setSpokenText(renderedText);
|
|
59
|
+
processed.current = nextIndex;
|
|
60
|
+
const fail = (message) => {
|
|
61
|
+
if (current.current?.utterance !== next)
|
|
62
|
+
return;
|
|
63
|
+
current.current = null;
|
|
64
|
+
setSpokenText('');
|
|
65
|
+
processed.current = nextIndex - 1;
|
|
66
|
+
onBusyChange(false);
|
|
67
|
+
const explanation = `Narration could not play: ${message}. Disable Narration to continue silently.`;
|
|
68
|
+
setStatus(explanation);
|
|
69
|
+
setError(explanation);
|
|
70
|
+
onError();
|
|
71
|
+
};
|
|
72
|
+
next.onend = () => {
|
|
73
|
+
if (current.current?.utterance === next) {
|
|
74
|
+
current.current = null;
|
|
75
|
+
setSpokenText('');
|
|
76
|
+
setTurn((value) => value + 1);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
next.onerror = (event) => fail(event.error);
|
|
80
|
+
onBusyChange(true);
|
|
81
|
+
setError('');
|
|
82
|
+
setStatus('Reading slide');
|
|
83
|
+
try {
|
|
84
|
+
synth.speak(next);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
fail('browser speech failed');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function SpeechControls({ settings, onSettingsChange, segments, contextKey, settingsTarget, playing, timeMs, speed, volume, onBusyChange, onError, resolveText, }) {
|
|
91
|
+
const supported = window.speechSynthesis !== undefined &&
|
|
92
|
+
window.SpeechSynthesisUtterance !== undefined;
|
|
93
|
+
const { enabled, voice } = settings;
|
|
94
|
+
const [voices, setVoices] = useState([]);
|
|
95
|
+
const [status, setStatus] = useState('Ready');
|
|
96
|
+
const [error, setError] = useState('');
|
|
97
|
+
const [spokenText, setSpokenText] = useState('');
|
|
98
|
+
const [turn, setTurn] = useState(0);
|
|
99
|
+
const current = useRef(null);
|
|
100
|
+
const speechPaused = useRef(false);
|
|
101
|
+
const processed = useRef(-1);
|
|
102
|
+
const latestTime = useRef(timeMs);
|
|
103
|
+
latestTime.current = timeMs;
|
|
104
|
+
const signature = JSON.stringify(segments);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!supported)
|
|
107
|
+
return;
|
|
108
|
+
const synth = window.speechSynthesis;
|
|
109
|
+
const update = () => setVoices(synth.getVoices());
|
|
110
|
+
update();
|
|
111
|
+
synth.addEventListener('voiceschanged', update);
|
|
112
|
+
return () => synth.removeEventListener('voiceschanged', update);
|
|
113
|
+
}, [supported]);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
current.current = null;
|
|
116
|
+
setSpokenText('');
|
|
117
|
+
speechPaused.current = false;
|
|
118
|
+
processed.current = narrationStart(segments, latestTime.current) - 1;
|
|
119
|
+
if (supported)
|
|
120
|
+
window.speechSynthesis.cancel();
|
|
121
|
+
onBusyChange(false);
|
|
122
|
+
setStatus('Ready');
|
|
123
|
+
setError('');
|
|
124
|
+
return () => {
|
|
125
|
+
current.current = null;
|
|
126
|
+
if (supported)
|
|
127
|
+
window.speechSynthesis.cancel();
|
|
128
|
+
onBusyChange(false);
|
|
129
|
+
};
|
|
130
|
+
}, [contextKey, signature, segments, enabled, voice, speed, volume, supported, onBusyChange]);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!supported || !enabled) {
|
|
133
|
+
onBusyChange(false);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const synth = window.speechSynthesis;
|
|
137
|
+
// Visibility windows control when narration starts, not when active speech stops.
|
|
138
|
+
const session = { current, speechPaused, processed };
|
|
139
|
+
invalidateChangedNarration(session, synth, resolveText, setSpokenText, onBusyChange);
|
|
140
|
+
if (pauseOrResumeNarration(session, synth, playing, setStatus))
|
|
141
|
+
return;
|
|
142
|
+
const { segment, nextIndex } = nextNarrationSegment(segments, processed, timeMs);
|
|
143
|
+
if (!segment || segment.atMs > timeMs) {
|
|
144
|
+
onBusyChange(false);
|
|
145
|
+
setStatus(segment ? 'Waiting for the next text segment' : 'Narration finished');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const renderedText = resolveText ? resolveText(segment) : segment.text;
|
|
149
|
+
if (renderedText === undefined) {
|
|
150
|
+
onBusyChange(false);
|
|
151
|
+
setStatus('Waiting for the selected slide text to appear');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const next = new SpeechSynthesisUtterance(renderedText);
|
|
155
|
+
next.voice = voices.find((item) => item.voiceURI === voice) ?? null;
|
|
156
|
+
next.volume = Math.min(1, Math.max(0, volume));
|
|
157
|
+
next.rate = Math.min(10, Math.max(0.1, speed));
|
|
158
|
+
beginNarration(session, synth, next, renderedText, segment, nextIndex, {
|
|
159
|
+
setSpokenText, setTurn, onBusyChange, setStatus, setError, onError,
|
|
160
|
+
});
|
|
161
|
+
}, [
|
|
162
|
+
playing,
|
|
163
|
+
timeMs,
|
|
164
|
+
speed,
|
|
165
|
+
volume,
|
|
166
|
+
segments,
|
|
167
|
+
enabled,
|
|
168
|
+
voice,
|
|
169
|
+
voices,
|
|
170
|
+
turn,
|
|
171
|
+
supported,
|
|
172
|
+
onBusyChange,
|
|
173
|
+
onError,
|
|
174
|
+
resolveText,
|
|
175
|
+
]);
|
|
176
|
+
return (_jsxs(_Fragment, { children: [settingsTarget &&
|
|
177
|
+
createPortal(_jsxs("fieldset", { className: "narration-settings", children: [_jsx("legend", { children: "Narration" }), _jsxs("label", { className: "editor-checkbox", children: [_jsx("input", { className: "form-check-input", "aria-label": "Narration enabled", type: "checkbox", checked: enabled, disabled: !supported || !onSettingsChange, onChange: (event) => {
|
|
178
|
+
onSettingsChange?.({ enabled: event.target.checked, voice });
|
|
179
|
+
} }), _jsx("span", { children: "Narration enabled" })] }), _jsxs("label", { children: ["Voice", ' ', _jsxs("select", { className: "form-select", "aria-label": "Narrator voice", value: voice, onChange: (event) => {
|
|
180
|
+
onSettingsChange?.({ enabled, voice: event.target.value });
|
|
181
|
+
}, disabled: !supported || playing || !onSettingsChange, children: [_jsx("option", { value: "", children: "Browser default" }), voice && !voices.some((item) => item.voiceURI === voice) && (_jsx("option", { value: voice, disabled: true, children: "Saved voice unavailable (using browser default)" })), voices.map((item) => (_jsxs("option", { value: item.voiceURI, children: [item.name, " (", item.lang, ")"] }, item.voiceURI)))] })] })] }), settingsTarget), error && (_jsx("div", { role: "alert", className: "alert alert-warning mt-2 mb-0", children: error })), _jsx("output", { hidden: true, "data-testid": "narration-status", children: narrationStatus(supported, enabled, status) }), _jsx("div", { hidden: true, "aria-label": "Current narration", children: spokenText || 'No narration playing.' })] }));
|
|
182
|
+
}
|
package/dist/deck.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const slideSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
title: z.ZodString;
|
|
5
|
+
durationMs: z.ZodNumber;
|
|
6
|
+
transition: z.ZodEnum<{
|
|
7
|
+
none: "none";
|
|
8
|
+
fade: "fade";
|
|
9
|
+
slide: "slide";
|
|
10
|
+
zoom: "zoom";
|
|
11
|
+
}>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type Slide = z.infer<typeof slideSchema>;
|
|
14
|
+
/** Content and additional slide metadata are validated by their registered owner. */
|
|
15
|
+
export interface SlideDeck<S extends Slide, Content> {
|
|
16
|
+
slides: S[];
|
|
17
|
+
content: Record<string, Content>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createSlideDeckSchema<S extends Slide, Content>(slide: z.ZodType<S>, content: z.ZodType<Content>): z.ZodObject<{
|
|
20
|
+
slides: z.ZodArray<z.ZodType<S, unknown, z.core.$ZodTypeInternals<S, unknown>>>;
|
|
21
|
+
content: z.ZodRecord<z.ZodString, z.ZodType<Content, unknown, z.core.$ZodTypeInternals<Content, unknown>>>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export declare function replaceSlides<S extends Slide, C>(deck: SlideDeck<S, C>, slides: S[], content?: Record<string, C>): SlideDeck<S, C>;
|
|
24
|
+
export declare function insertSlide<S extends Slide, C>(deck: SlideDeck<S, C>, slide: S, content: C, position?: number): SlideDeck<S, C>;
|
|
25
|
+
export declare function removeSlide<S extends Slide, C>(deck: SlideDeck<S, C>, id: string): SlideDeck<S, C>;
|
|
26
|
+
export declare function reorderSlide<S extends Slide, C>(deck: SlideDeck<S, C>, sourceId: string, targetId: string, after?: boolean): SlideDeck<S, C>;
|
package/dist/deck.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const slideSchema = z.strictObject({
|
|
3
|
+
id: z.string().min(1),
|
|
4
|
+
title: z.string().min(1),
|
|
5
|
+
durationMs: z.number().int().positive(),
|
|
6
|
+
transition: z.enum(['none', 'fade', 'slide', 'zoom']),
|
|
7
|
+
});
|
|
8
|
+
export function createSlideDeckSchema(slide, content) {
|
|
9
|
+
return z.strictObject({ slides: z.array(slide).min(1), content: z.record(z.string(), content) })
|
|
10
|
+
.superRefine((deck, context) => {
|
|
11
|
+
const ids = deck.slides.map(item => item.id);
|
|
12
|
+
if (new Set(ids).size !== ids.length || ids.length !== Object.keys(deck.content).length
|
|
13
|
+
|| ids.some(id => !Object.hasOwn(deck.content, id)))
|
|
14
|
+
context.addIssue({ code: 'custom', message: 'Each slide requires a unique identity and exactly one content document.' });
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function replaceSlides(deck, slides, content = deck.content) {
|
|
18
|
+
const ids = slides.map(slide => slide.id);
|
|
19
|
+
if (!ids.length || new Set(ids).size !== ids.length || ids.length !== Object.keys(content).length
|
|
20
|
+
|| ids.some(id => !Object.hasOwn(content, id)))
|
|
21
|
+
throw new Error('Invalid slide identities or content mapping.');
|
|
22
|
+
return { slides, content };
|
|
23
|
+
}
|
|
24
|
+
export function insertSlide(deck, slide, content, position = deck.slides.length) {
|
|
25
|
+
if (Object.hasOwn(deck.content, slide.id) || !Number.isInteger(position) || position < 0 || position > deck.slides.length)
|
|
26
|
+
throw new Error('Cannot insert this slide.');
|
|
27
|
+
const slides = [...deck.slides];
|
|
28
|
+
slides.splice(position, 0, slide);
|
|
29
|
+
return replaceSlides(deck, slides, { ...deck.content, [slide.id]: content });
|
|
30
|
+
}
|
|
31
|
+
export function removeSlide(deck, id) {
|
|
32
|
+
if (!deck.slides.some(slide => slide.id === id))
|
|
33
|
+
throw new Error('Unknown slide.');
|
|
34
|
+
const content = { ...deck.content };
|
|
35
|
+
delete content[id];
|
|
36
|
+
return replaceSlides(deck, deck.slides.filter(slide => slide.id !== id), content);
|
|
37
|
+
}
|
|
38
|
+
export function reorderSlide(deck, sourceId, targetId, after = false) {
|
|
39
|
+
if (sourceId === targetId)
|
|
40
|
+
return deck;
|
|
41
|
+
const source = deck.slides.find(slide => slide.id === sourceId);
|
|
42
|
+
if (!source || !deck.slides.some(slide => slide.id === targetId))
|
|
43
|
+
throw new Error('Unknown slide reorder target.');
|
|
44
|
+
const slides = deck.slides.filter(slide => slide.id !== sourceId);
|
|
45
|
+
slides.splice(slides.findIndex(slide => slide.id === targetId) + Number(after), 0, source);
|
|
46
|
+
return replaceSlides(deck, slides);
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface NarrationSegment {
|
|
2
|
+
id: string;
|
|
3
|
+
atMs: number;
|
|
4
|
+
untilMs?: number;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
/** Seeking restarts the latest currently visible segment, never a word offset. */
|
|
8
|
+
export declare function narrationStart(segments: readonly NarrationSegment[], timeMs: number): number;
|
|
9
|
+
/** Speech and the timeline share a playback rate, so compare them at normal speed. */
|
|
10
|
+
export declare function narrationTimingWarnings(segments: readonly NarrationSegment[], durationMs: number): string[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { stripHtmlTags, stripMarkdownLinks } from '@signalsafe/content-editor-react/authoringText';
|
|
2
|
+
/** Seeking restarts the latest currently visible segment, never a word offset. */
|
|
3
|
+
export function narrationStart(segments, timeMs) {
|
|
4
|
+
if (timeMs <= 0)
|
|
5
|
+
return 0;
|
|
6
|
+
let start = 0;
|
|
7
|
+
segments.forEach((segment, index) => {
|
|
8
|
+
if (segment.atMs <= timeMs && (segment.untilMs === undefined || timeMs < segment.untilMs))
|
|
9
|
+
start = index;
|
|
10
|
+
});
|
|
11
|
+
return start;
|
|
12
|
+
}
|
|
13
|
+
const ESTIMATED_WORDS_PER_MINUTE = 150;
|
|
14
|
+
const MILLISECONDS_PER_MINUTE = 60_000;
|
|
15
|
+
/** Speech and the timeline share a playback rate, so compare them at normal speed. */
|
|
16
|
+
export function narrationTimingWarnings(segments, durationMs) {
|
|
17
|
+
const warnings = [];
|
|
18
|
+
let finishMs = 0;
|
|
19
|
+
for (const segment of segments) {
|
|
20
|
+
// Count visible prose rather than Markdown link destinations or markup.
|
|
21
|
+
const prose = stripHtmlTags(stripMarkdownLinks(segment.text))
|
|
22
|
+
.replace(/[#*_~`>|]/g, ' ');
|
|
23
|
+
const words = prose.match(/\S+/g)?.length ?? 0;
|
|
24
|
+
if (!words)
|
|
25
|
+
continue;
|
|
26
|
+
const speechMs = (words / ESTIMATED_WORDS_PER_MINUTE) * MILLISECONDS_PER_MINUTE;
|
|
27
|
+
finishMs = Math.max(finishMs, segment.atMs) + speechMs;
|
|
28
|
+
if (segment.untilMs !== undefined && finishMs > segment.untilMs) {
|
|
29
|
+
const visibleSeconds = Math.max(0, segment.untilMs - segment.atMs) / 1000;
|
|
30
|
+
warnings.push(`Callout at ${segment.atMs / 1000}s: narration may take about ${Math.ceil(speechMs / 1000)} seconds, but it is visible for ${visibleSeconds} seconds. It may finish around ${Math.ceil(finishMs / 1000)} seconds including earlier narration. Extend its timing or shorten the text.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (finishMs > durationMs) {
|
|
34
|
+
warnings.push(`Slide narration may finish around ${Math.ceil(finishMs / 1000)} seconds, beyond the ${durationMs / 1000}-second slide. Extend the slide duration or shorten the text.`);
|
|
35
|
+
}
|
|
36
|
+
return warnings;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Read only the selected presentation’s rendered content, never device UI or hidden slides. */
|
|
2
|
+
export function renderedNarrationText(segment, selector = '[data-slide-deck-current]') {
|
|
3
|
+
const roots = document.querySelectorAll(selector);
|
|
4
|
+
const text = Array.from(roots).flatMap((root) => Array.from(root.querySelectorAll('[data-narration-segment]'))
|
|
5
|
+
.filter((node) => !node.closest('[hidden], [data-slide-thumbnail]') &&
|
|
6
|
+
node.getClientRects().length > 0 &&
|
|
7
|
+
(segment.id === 'intro'
|
|
8
|
+
? node.dataset.narrationSegment === 'intro'
|
|
9
|
+
: node.dataset.narrationSegment === 'timed' &&
|
|
10
|
+
(!node.dataset.narrationId || node.dataset.narrationId === segment.id)))
|
|
11
|
+
.map((node) => (node.textContent || '').trim())
|
|
12
|
+
.filter(Boolean));
|
|
13
|
+
return text.length ? text.join('\n\n') : undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
.slide-editor { min-height: 0; }
|
|
2
|
+
.slide-tree-row { position: relative; }
|
|
3
|
+
.slide-editor [data-slide-deck-current] { min-width: 0; }
|
|
4
|
+
.center-playback-footer { flex: 0 0 auto; }
|
|
5
|
+
.center-playback-footer {
|
|
6
|
+
padding: 0.75rem;
|
|
7
|
+
border-top: 1px solid var(--bs-border-color);
|
|
8
|
+
}
|
|
9
|
+
.slide-playback-actions,
|
|
10
|
+
.slide-playback-status,
|
|
11
|
+
.slide-playback-status .form-select {
|
|
12
|
+
min-width: 0;
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
}
|
|
15
|
+
.slide-volume {
|
|
16
|
+
width: 5rem;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
margin: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.slide-overview {
|
|
22
|
+
display: grid;
|
|
23
|
+
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
|
24
|
+
gap: 0.75rem;
|
|
25
|
+
max-height: 70vh;
|
|
26
|
+
overflow: auto;
|
|
27
|
+
}
|
|
28
|
+
.slide-overview-item {
|
|
29
|
+
min-width: 0;
|
|
30
|
+
}
|
|
31
|
+
.slide-overview-item > .lesson-reorder-handle {
|
|
32
|
+
position: absolute;
|
|
33
|
+
right: 0.25rem;
|
|
34
|
+
bottom: 0.25rem;
|
|
35
|
+
}
|
|
36
|
+
.slide-overview-item > button {
|
|
37
|
+
text-transform: none;
|
|
38
|
+
}
|
|
39
|
+
.slide-thumbnail {
|
|
40
|
+
position: relative;
|
|
41
|
+
aspect-ratio: 16 / 9;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
border: 1px solid var(--bs-border-color);
|
|
44
|
+
background: var(--bs-body-bg);
|
|
45
|
+
contain: strict;
|
|
46
|
+
}
|
|
47
|
+
.slide-thumbnail-viewport {
|
|
48
|
+
position: absolute;
|
|
49
|
+
inset: 0;
|
|
50
|
+
transform-origin: 0 0;
|
|
51
|
+
pointer-events: none;
|
|
52
|
+
text-transform: none;
|
|
53
|
+
font: var(--bs-body-font-size) / var(--bs-body-line-height) var(--bs-body-font-family);
|
|
54
|
+
color: var(--bs-body-color);
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"src/ResponsiveViewport.tsx": "f6ebba20cbc95e27a69e1ae98b002d38f21d00f3121822bc104b75815935d654",
|
|
3
|
+
"src/SlideEditor.tsx": "275733cb08c03fe0bd9e0ee2aabf6df754a06c616cb7c25c97dca5a8841ac4d2",
|
|
4
|
+
"src/SlideInteractions.tsx": "f519f643431b0d292d5b42ecf7301c48d1ad40e4a5285035f8be66b2b74fda99",
|
|
5
|
+
"src/SlideOutline.tsx": "e286ac3cf2f049b3dd670e7daefa9bf96f3d243368be0cd39a9904c89d44c09c",
|
|
6
|
+
"src/SlideOverview.tsx": "bc69f5813071ad7d2b4d8fe2b47c19b72556a4a7242897a3ff7f5e9fd10e82aa",
|
|
7
|
+
"src/SlidePlaybackControls.tsx": "d69fdf5646b9b72dc79df3d694c41f02a58b84b05dbf560142c30a8ef53a1eee",
|
|
8
|
+
"src/SlidePlayer.tsx": "8ad893667c8661d2dd805a112f54017d6fd5e3da7f6a170607abae107a8af158",
|
|
9
|
+
"src/SpeechControls.tsx": "20452b7eff7ae1a8dafb279ed7ab113466e17942bf30243d24bc026894f5c21f",
|
|
10
|
+
"src/deck.ts": "116360eaec4fa6dd44d5ffb859e4a3b64c2e85e33e89649fd4c1ab5346885b87",
|
|
11
|
+
"src/narration.ts": "9d299bfb41ddd7fad3a37f75b84229a7e14d21485e61dff8b4f63a2cdb82f4c8",
|
|
12
|
+
"src/narrationDom.ts": "63dc17012fe6208f78a6ad941efc953331a78d4e31dbfbe33a6f3577eafcd000",
|
|
13
|
+
"src/slide-editor.css": "b1783a0bbedd679c05c2cf33fe06ef1098002d6d0b1649dcabca48d156067bdd",
|
|
14
|
+
"src/thumbnailObservers.ts": "07f2e0efb338d0826076bef72963b491b44894c3658d5425cfe0799f73794750",
|
|
15
|
+
"src/useCanvasOverflow.ts": "c7b21df749fb6e2d34072347a0a09f8cf157605f56db200238670551a39f8bc4",
|
|
16
|
+
"src/usePlayback.ts": "eec1453e2803299f1b5cd853487f0e78f5284c5ab5f808b3478ef218b63fc834",
|
|
17
|
+
"src/validationIssueRows.ts": "9aefc967eddbb5878ece976f54c364b346142855e65e4a3c6d8c5c6c6c482c9c",
|
|
18
|
+
"package.json": "66845e17d57c8638d44adefd4455914f1fe33a32537ea19a8fbcb86461e4a122",
|
|
19
|
+
"tsconfig.json": "d0afb06c670b0c2aafbbd4809e34d79bb65a82073561efe96b6e86736fffb71e",
|
|
20
|
+
"scripts/build.mjs": "da7ff4ffb79219b3c8733c92bd714c4f595c8d6fa3b91f455edcf789dac2c532"
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Own the paired subscriptions for an inert, lazily rendered slide thumbnail. */
|
|
2
|
+
export function observeSlideThumbnail(element, onWidth, onVisible) {
|
|
3
|
+
if (!element)
|
|
4
|
+
return;
|
|
5
|
+
element.setAttribute('inert', '');
|
|
6
|
+
const resize = typeof ResizeObserver === 'undefined'
|
|
7
|
+
? undefined
|
|
8
|
+
: new ResizeObserver(() => onWidth(element.clientWidth || 160));
|
|
9
|
+
resize?.observe(element);
|
|
10
|
+
const intersection = observeVisibility(element, onVisible);
|
|
11
|
+
return () => {
|
|
12
|
+
resize?.disconnect();
|
|
13
|
+
intersection?.disconnect();
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function observeVisibility(element, onVisible) {
|
|
17
|
+
if (typeof IntersectionObserver === 'undefined')
|
|
18
|
+
return;
|
|
19
|
+
const observer = new IntersectionObserver((entries) => {
|
|
20
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
21
|
+
onVisible();
|
|
22
|
+
observer.disconnect();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
observer.observe(element);
|
|
26
|
+
return observer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/** Measure authored leaf content, not the intentionally scrollable viewport or device shell. */
|
|
3
|
+
export declare function useCanvasOverflow(canvas: RefObject<HTMLElement | null>, blocks: readonly {
|
|
4
|
+
type: string;
|
|
5
|
+
props: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
}[], enabled: boolean, width: string, onChange?: (ids: string[]) => void): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
/** Measure authored leaf content, not the intentionally scrollable viewport or device shell. */
|
|
3
|
+
export function useCanvasOverflow(canvas, blocks, enabled, width, onChange) {
|
|
4
|
+
const callback = useRef(onChange);
|
|
5
|
+
callback.current = onChange;
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const element = canvas.current;
|
|
8
|
+
if (!enabled || !element) {
|
|
9
|
+
callback.current?.([]);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let frame = 0;
|
|
13
|
+
const measure = () => {
|
|
14
|
+
cancelAnimationFrame(frame);
|
|
15
|
+
frame = requestAnimationFrame(() => {
|
|
16
|
+
const ids = blocks
|
|
17
|
+
.filter((block) => !['Row', 'Column'].includes(block.type))
|
|
18
|
+
.flatMap((block) => blockOverflows(element, block.props.id) ? [block.props.id] : []);
|
|
19
|
+
callback.current?.(ids);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure);
|
|
23
|
+
resize?.observe(element);
|
|
24
|
+
const observer = new MutationObserver(measure);
|
|
25
|
+
observer.observe(element, {
|
|
26
|
+
subtree: true,
|
|
27
|
+
childList: true,
|
|
28
|
+
characterData: true,
|
|
29
|
+
attributes: true,
|
|
30
|
+
attributeFilter: ['style', 'class', 'hidden'],
|
|
31
|
+
});
|
|
32
|
+
element.addEventListener('load', measure, true);
|
|
33
|
+
measure();
|
|
34
|
+
return () => {
|
|
35
|
+
cancelAnimationFrame(frame);
|
|
36
|
+
resize?.disconnect();
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
element.removeEventListener('load', measure, true);
|
|
39
|
+
};
|
|
40
|
+
}, [canvas, blocks, enabled, width]);
|
|
41
|
+
}
|
|
42
|
+
function blockOverflows(element, id) {
|
|
43
|
+
const node = Array.from(element.querySelectorAll('[data-block-id]'))
|
|
44
|
+
.find((item) => item.dataset.blockId === id);
|
|
45
|
+
if (!node || node.querySelector('.content-inline-editor'))
|
|
46
|
+
return false;
|
|
47
|
+
const children = Array.from(node.children)
|
|
48
|
+
.filter((item) => !item.hasAttribute('data-slide-canvas-tools'));
|
|
49
|
+
return children.some((item) => item.clientWidth > 0 &&
|
|
50
|
+
item.scrollWidth > Math.min(item.clientWidth, node.clientWidth) + 2);
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function usePlayback(durationMs: number, slideId: string, narrationBusy?: boolean, onComplete?: () => void): {
|
|
2
|
+
timeMs: number;
|
|
3
|
+
playing: boolean;
|
|
4
|
+
speed: number;
|
|
5
|
+
revision: number;
|
|
6
|
+
pause: () => void;
|
|
7
|
+
seek: (next: number) => void;
|
|
8
|
+
setSpeed: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
9
|
+
play: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** Presentation state supplied to content renderers, including the shared narration volume. */
|
|
12
|
+
export type SlidePlaybackState = ReturnType<typeof usePlayback> & Readonly<{
|
|
13
|
+
volume: number;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
export function usePlayback(durationMs, slideId, narrationBusy = false, onComplete) {
|
|
3
|
+
const [timeMs, setTimeMs] = useState(0);
|
|
4
|
+
const [playing, setPlaying] = useState(false);
|
|
5
|
+
const [speed, setSpeed] = useState(1);
|
|
6
|
+
const [revision, setRevision] = useState(0);
|
|
7
|
+
const complete = useRef(onComplete);
|
|
8
|
+
complete.current = onComplete;
|
|
9
|
+
const anchor = useRef(null);
|
|
10
|
+
const pause = useCallback(() => {
|
|
11
|
+
setPlaying(false);
|
|
12
|
+
anchor.current = null;
|
|
13
|
+
}, []);
|
|
14
|
+
const seek = useCallback((next) => {
|
|
15
|
+
setPlaying(false);
|
|
16
|
+
setTimeMs(Math.max(0, Math.min(durationMs, next)));
|
|
17
|
+
setRevision((current) => current + 1);
|
|
18
|
+
anchor.current = null;
|
|
19
|
+
}, [durationMs]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
seek(0);
|
|
22
|
+
}, [slideId, seek]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const visibility = () => {
|
|
25
|
+
if (document.hidden)
|
|
26
|
+
pause();
|
|
27
|
+
};
|
|
28
|
+
document.addEventListener('visibilitychange', visibility);
|
|
29
|
+
return () => document.removeEventListener('visibilitychange', visibility);
|
|
30
|
+
}, [pause]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!playing)
|
|
33
|
+
return;
|
|
34
|
+
let frame = 0;
|
|
35
|
+
const tick = (now) => {
|
|
36
|
+
const delta = anchor.current === null ? 0 : now - anchor.current;
|
|
37
|
+
anchor.current = now;
|
|
38
|
+
setTimeMs((current) => Math.min(durationMs, current + delta * speed));
|
|
39
|
+
frame = requestAnimationFrame(tick);
|
|
40
|
+
};
|
|
41
|
+
frame = requestAnimationFrame(tick);
|
|
42
|
+
return () => {
|
|
43
|
+
cancelAnimationFrame(frame);
|
|
44
|
+
anchor.current = null;
|
|
45
|
+
};
|
|
46
|
+
}, [durationMs, playing, speed]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (playing && timeMs >= durationMs && !narrationBusy) {
|
|
49
|
+
pause();
|
|
50
|
+
complete.current?.();
|
|
51
|
+
}
|
|
52
|
+
}, [timeMs, durationMs, narrationBusy, playing, pause]);
|
|
53
|
+
const position = useRef({ timeMs, narrationBusy });
|
|
54
|
+
position.current = { timeMs, narrationBusy };
|
|
55
|
+
const play = useCallback(() => {
|
|
56
|
+
if (position.current.timeMs >= durationMs && !position.current.narrationBusy)
|
|
57
|
+
seek(0);
|
|
58
|
+
setPlaying(true);
|
|
59
|
+
}, [durationMs, seek]);
|
|
60
|
+
return {
|
|
61
|
+
timeMs,
|
|
62
|
+
playing,
|
|
63
|
+
speed,
|
|
64
|
+
revision,
|
|
65
|
+
pause,
|
|
66
|
+
seek,
|
|
67
|
+
setSpeed,
|
|
68
|
+
play,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Diagnostics retain DOM identity when a different diagnostic is inserted or removed. */
|
|
2
|
+
export function validationIssueRows(issues) {
|
|
3
|
+
const occurrences = new Map();
|
|
4
|
+
return issues.map((issue) => {
|
|
5
|
+
const identity = JSON.stringify([issue.path, issue.code, issue.message]);
|
|
6
|
+
const occurrence = occurrences.get(identity) ?? 0;
|
|
7
|
+
occurrences.set(identity, occurrence + 1);
|
|
8
|
+
return { issue, key: `${identity}:${occurrence}` };
|
|
9
|
+
});
|
|
10
|
+
}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Slide editor documentation
|
|
2
|
+
|
|
3
|
+
[Package guide](../README.md) · [Current state](current-state-summary.md) ·
|
|
4
|
+
[Release procedure](../RELEASING.md) · [Live demo](https://signalsafesoftware.github.io/slide-editor-react/)
|
|
5
|
+
|
|
6
|
+
## Owners
|
|
7
|
+
|
|
8
|
+
| Responsibility | Owner |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Generic Bootstrap composition, rich text, properties and editor chrome | `@signalsafe/content-editor-react` |
|
|
11
|
+
| Deck identities/content maps, immutable operations, outline/overview, playback, speech, interactions and viewport primitives | `@signalsafe/slide-editor-react` |
|
|
12
|
+
| Lesson format, validation, metadata, templates, draft/review/publication and authenticated providers | DeliveryPlus `frontend/shared/domains/content/lesson-editor` |
|
|
13
|
+
| DeliveryPlus simulator preview/session adapters | DeliveryPlus `frontend/shared/domains/simulator/preview` |
|
|
14
|
+
| Phone screens, device composition and theme | Simulator ecosystem packages |
|
|
15
|
+
|
|
16
|
+
## Model and extension boundaries
|
|
17
|
+
|
|
18
|
+
`Slide` contains id, title, duration and transition. `SlideDeck<S, C>` pairs each
|
|
19
|
+
slide identity with exactly one typed content value. The schema factory accepts
|
|
20
|
+
the caller's slide/content validators. Insertion, removal and reordering retain
|
|
21
|
+
metadata and reject inconsistent identity/content maps.
|
|
22
|
+
|
|
23
|
+
Renderers and factories are typed extension points. They may compose content
|
|
24
|
+
editor controls, custom inspectors, narration and timeline providers. Hosts own
|
|
25
|
+
network access, permissions, identity creation, data limits, history persistence
|
|
26
|
+
and what completion means. No learning or simulator dependency is required.
|
|
27
|
+
|
|
28
|
+
DeliveryPlus projects its existing version 3 lesson envelope into the deck view
|
|
29
|
+
without dropping lesson-wide fields or changing saved JSON names. Its specialized
|
|
30
|
+
lesson compositor uses shared slide primitives while keeping domain behavior in
|
|
31
|
+
the host. The historical lesson npm API is not forwarded by this package.
|
|
32
|
+
|
|
33
|
+
## Supported subpaths
|
|
34
|
+
|
|
35
|
+
`SlideEditor`, `SlidePlayer`, `SlideOutline`, `SlideOverview`, `deck`, `usePlayback`,
|
|
36
|
+
`SlidePlaybackControls`, `SpeechControls`, `narration`, `narrationDom`,
|
|
37
|
+
`SlideInteractions`, `ResponsiveViewport`, `thumbnailObservers`, `useCanvasOverflow`,
|
|
38
|
+
`validationIssueRows` and `styles.css`.
|
|
39
|
+
|
|
40
|
+
The standalone demo is independent of DeliveryPlus and uses synthetic data. It
|
|
41
|
+
exercises controlled editing and read-only player navigation. Real host persistence
|
|
42
|
+
and authenticated acceptance remain host checks.
|