@bendyline/squisq-react 2.12.27 → 2.12.28
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/dist/{chunk-3DBHZKBG.js → chunk-3UITZDNL.js} +1 -1
- package/dist/{chunk-OWC7DNGJ.js → chunk-CFJRBRRG.js} +32 -15
- package/dist/{chunk-E7TEWUNF.js → chunk-DRPMS5JK.js} +144 -297
- package/dist/chunk-FXAKS6KU.js +403 -0
- package/dist/{chunk-ZXPSPNO6.js → chunk-M4IUYVXU.js} +1 -1
- package/dist/{chunk-UUGOEH5Q.js → chunk-MNY6M5QG.js} +1 -1
- package/dist/{chunk-GAZHUNKY.js → chunk-NZHL2VKW.js} +84 -72
- package/dist/{chunk-FZNGE23J.js → chunk-Q66DDGKP.js} +3 -3
- package/dist/{chunk-26J5MZBI.js → chunk-RVTMYNVX.js} +1 -1
- package/dist/{chunk-OTYJ4MRH.js → chunk-ZKMBIWAA.js} +6 -2
- package/dist/diagram-pictures/index.js +4 -7
- package/dist/hooks/index.d.ts +6 -228
- package/dist/hooks/index.js +2 -2
- package/dist/hooks-Dxpfol0l.d.ts +233 -0
- package/dist/index.d.ts +87 -7
- package/dist/index.js +30 -12
- package/dist/json-view/index.js +4 -4
- package/dist/layers/index.js +3 -3
- package/dist/markdown/index.js +3 -3
- package/dist/page/index.js +7 -7
- package/dist/player/index.d.ts +1 -1
- package/dist/player/index.js +8 -8
- package/dist/{player-C-k_8OaA.d.ts → player-B-2-utvs.d.ts} +10 -3
- package/dist/squisq-player.full.global.js +472 -471
- package/dist/squisq-player.global.js +94 -93
- package/dist/standalone-player-full.js +1 -1
- package/dist/standalone-source.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-A65WPCGZ.js +0 -67
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
InlineVideoPlayer,
|
|
6
6
|
MarkdownRenderer,
|
|
7
7
|
VideoEmbedFrame
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-CFJRBRRG.js";
|
|
9
9
|
import {
|
|
10
10
|
BlockRenderer
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3UITZDNL.js";
|
|
12
12
|
import {
|
|
13
13
|
svgDataImageSrc,
|
|
14
14
|
useMediaUrl
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ZKMBIWAA.js";
|
|
16
16
|
|
|
17
17
|
// src/page/PageViewContext.ts
|
|
18
18
|
import { createContext, useContext } from "react";
|
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
isSvgImageSource
|
|
68
68
|
} from "@bendyline/squisq/markdown";
|
|
69
69
|
var MediaContext = createContext(null);
|
|
70
|
+
var ProcessedAudioContext = createContext(void 0);
|
|
70
71
|
var ResourcePolicyContext = createContext(
|
|
71
72
|
DEFAULT_INTERACTIVE_RESOURCE_POLICY
|
|
72
73
|
);
|
|
@@ -122,7 +123,7 @@ function useMediaUrl(relativePath, basePath, options = {}) {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
// src/mermaid/mermaidRuntime.ts
|
|
125
|
-
import { buildMermaidThemeVariables } from "@bendyline/squisq/schemas";
|
|
126
|
+
import { buildMermaidThemeCss, buildMermaidThemeVariables } from "@bendyline/squisq/schemas";
|
|
126
127
|
import { DEFAULT_THEME } from "@bendyline/squisq/doc";
|
|
127
128
|
var mermaidPromise = null;
|
|
128
129
|
var MERMAID_BASE_CONFIG = {
|
|
@@ -176,7 +177,8 @@ function renderMermaidSvg(id, source, container, theme = DEFAULT_THEME) {
|
|
|
176
177
|
mermaid.initialize({
|
|
177
178
|
...MERMAID_BASE_CONFIG,
|
|
178
179
|
theme: "base",
|
|
179
|
-
themeVariables: buildMermaidThemeVariables(theme)
|
|
180
|
+
themeVariables: buildMermaidThemeVariables(theme),
|
|
181
|
+
themeCSS: buildMermaidThemeCss(theme)
|
|
180
182
|
});
|
|
181
183
|
const { svg, diagramType } = await withMermaidLabelWrapping(
|
|
182
184
|
() => mermaid.render(id, source, container)
|
|
@@ -192,6 +194,7 @@ function renderMermaidSvgForExport(id, source, theme = DEFAULT_THEME, fontFamily
|
|
|
192
194
|
...MERMAID_BASE_CONFIG,
|
|
193
195
|
theme: "base",
|
|
194
196
|
themeVariables: fontFamily ? { ...themeVariables, fontFamily } : themeVariables,
|
|
197
|
+
themeCSS: buildMermaidThemeCss(theme),
|
|
195
198
|
htmlLabels: false,
|
|
196
199
|
journey: { textPlacement: "tspan" }
|
|
197
200
|
});
|
|
@@ -210,6 +213,7 @@ export {
|
|
|
210
213
|
svgDataImageSrc,
|
|
211
214
|
useSanitizedSvgImage,
|
|
212
215
|
MediaContext,
|
|
216
|
+
ProcessedAudioContext,
|
|
213
217
|
ResourcePolicyContext,
|
|
214
218
|
useResourcePolicy,
|
|
215
219
|
useMediaProvider,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BlockRenderer
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-3UITZDNL.js";
|
|
4
|
+
import "../chunk-DRPMS5JK.js";
|
|
5
|
+
import "../chunk-FXAKS6KU.js";
|
|
6
6
|
import {
|
|
7
7
|
renderMermaidSvgForExport
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-ZKMBIWAA.js";
|
|
9
9
|
|
|
10
10
|
// src/export/diagramPictures.ts
|
|
11
11
|
import { createElement } from "react";
|
|
@@ -89,9 +89,6 @@ async function renderMermaidPicture(source, options = {}) {
|
|
|
89
89
|
if (!svg) throw new Error("Mermaid produced no SVG.");
|
|
90
90
|
const box = parseViewBox(svg);
|
|
91
91
|
if (!box) throw new Error("The Mermaid SVG has no size.");
|
|
92
|
-
const style = document.createElementNS(SVG_NS, "style");
|
|
93
|
-
style.textContent = `.edgeLabel text, .edgeLabel tspan { fill: ${theme.colors.text} !important; }`;
|
|
94
|
-
svg.append(style);
|
|
95
92
|
const width = Math.min(maxWidth, box.width);
|
|
96
93
|
return svgToPng(svg, width, box.height * width / box.width, options);
|
|
97
94
|
}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,228 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import { ResourcePolicy } from '@bendyline/squisq/markdown';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* useAudioSync Hook
|
|
11
|
-
*
|
|
12
|
-
* Synchronizes playback state with an audio element. Provides current
|
|
13
|
-
* playback time, playing state, and methods to control audio playback.
|
|
14
|
-
*
|
|
15
|
-
* Handles multiple audio segments (MP3 files) by tracking which segment
|
|
16
|
-
* is currently playing and calculating the overall timeline position.
|
|
17
|
-
*
|
|
18
|
-
* This is the HTML5 Audio implementation of the AudioController interface.
|
|
19
|
-
* Hosts that drive audio through an external player (e.g. a native shell)
|
|
20
|
-
* can supply their own AudioController to DocPlayer instead of this hook.
|
|
21
|
-
*
|
|
22
|
-
* In `synthetic` mode there is no audio element to follow, so a caller that
|
|
23
|
-
* has no segments passes `syntheticDuration` — the document's own timeline
|
|
24
|
-
* length — and the same segment machinery drives a timer instead.
|
|
25
|
-
*
|
|
26
|
-
* Each segment is downloaded whole and attached as a blob URL, so a segment is
|
|
27
|
-
* only playable once its download finishes. A `play()` that arrives earlier (a
|
|
28
|
-
* listener pressing Play right away, or right after seeking into another
|
|
29
|
-
* segment) is recorded as intent and started by the load path on `canplay`.
|
|
30
|
-
* Playing the element immediately would either start an element with no
|
|
31
|
-
* source, whose pending play the attaching `load()` aborts, or start the
|
|
32
|
-
* previous segment. An `AbortError` from `play()` therefore means "superseded",
|
|
33
|
-
* never "unavailable". Seeks are handled the same way: a seek into a segment
|
|
34
|
-
* that is still loading moves the pending position (a scrub drag keeps
|
|
35
|
-
* seeking after it crosses a chapter boundary), because the element still
|
|
36
|
-
* holds the previous segment. The next segment is downloaded shortly before the
|
|
37
|
-
* current one ends, so chapter boundaries do not stall on a fresh download.
|
|
38
|
-
*
|
|
39
|
-
* A segment whose download fails is retried a few times before the narration
|
|
40
|
-
* is reported unavailable, and the waits only count while the page is visible
|
|
41
|
-
* and online. A phone app in the background can lose its network; the segment
|
|
42
|
-
* that failed there now loads, and plays on, when the listener comes back.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
type AudioSyncMode = 'media' | 'synthetic';
|
|
46
|
-
declare function useAudioSync(audioRef: RefObject<HTMLAudioElement>, track: AudioTrack | undefined, basePath?: string, enabled?: boolean, mode?: AudioSyncMode, syntheticDuration?: number): AudioController;
|
|
47
|
-
|
|
48
|
-
interface ModalDialogOptions {
|
|
49
|
-
/** The backdrop/portal root. Siblings of this branch are made inert. */
|
|
50
|
-
rootRef: RefObject<HTMLElement | null>;
|
|
51
|
-
/** The element with `role="dialog"`; focus is trapped within it. */
|
|
52
|
-
dialogRef: RefObject<HTMLElement | null>;
|
|
53
|
-
initialFocusRef?: RefObject<HTMLElement | null>;
|
|
54
|
-
/** Explicit opener/owner to restore after unmount (important when a child uses autofocus). */
|
|
55
|
-
returnFocusRef?: RefObject<HTMLElement | null>;
|
|
56
|
-
/** Whether Escape requests that the dialog close. Defaults to true. */
|
|
57
|
-
closeOnEscape?: boolean;
|
|
58
|
-
onClose: () => void;
|
|
59
|
-
}
|
|
60
|
-
/** Shared focus, keyboard, background-isolation, and restoration behavior for modal dialogs. */
|
|
61
|
-
declare function useModalDialog({ rootRef, dialogRef, initialFocusRef, returnFocusRef, closeOnEscape, onClose, }: ModalDialogOptions): void;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* useMediaSchedule
|
|
65
|
-
*
|
|
66
|
-
* Pure follower of the playback clock for the media-clip model. Given the
|
|
67
|
-
* resolved {@link ScheduledClip}s and the current time, it returns the clips
|
|
68
|
-
* the player should mount and which of them are active right now.
|
|
69
|
-
* {@link MediaClipLayer} consumes this to drive one hidden `<audio>` /
|
|
70
|
-
* full-bleed `<video>` element per clip. (Annotation-authored clips all render
|
|
71
|
-
* at the player level; template-produced `VideoLayer`s are a separate path and
|
|
72
|
-
* are not part of the schedule.)
|
|
73
|
-
*
|
|
74
|
-
* It owns no clock: `currentTime`/`isPlaying` come from the existing
|
|
75
|
-
* `useAudioSync` provider via `DocPlayer`. With an empty schedule it returns
|
|
76
|
-
* empty lists, so documents without the new media model are unaffected.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
interface MediaScheduleController {
|
|
80
|
-
/** Clips the player mounts (every scheduled clip). */
|
|
81
|
-
renderClips: ScheduledClip[];
|
|
82
|
-
/** Ids of clips whose [absoluteStart, absoluteEnd) contains currentTime. */
|
|
83
|
-
activeIds: Set<string>;
|
|
84
|
-
}
|
|
85
|
-
declare function useMediaSchedule(schedule: ScheduledClip[], currentTime: number): MediaScheduleController;
|
|
86
|
-
|
|
87
|
-
interface PlaybackState {
|
|
88
|
-
/** Currently visible block */
|
|
89
|
-
currentBlock: Block | null;
|
|
90
|
-
/** Index of current block */
|
|
91
|
-
currentBlockIndex: number;
|
|
92
|
-
/** Previous block (for transitions) */
|
|
93
|
-
previousBlock: Block | null;
|
|
94
|
-
/** Whether current block is entering */
|
|
95
|
-
isEntering: boolean;
|
|
96
|
-
/** Whether previous block is exiting */
|
|
97
|
-
isExiting: boolean;
|
|
98
|
-
/** Time relative to current block start */
|
|
99
|
-
blockTime: number;
|
|
100
|
-
/** Progress through current block (0-1) */
|
|
101
|
-
blockProgress: number;
|
|
102
|
-
/** Overall progress through doc (0-1) */
|
|
103
|
-
docProgress: number;
|
|
104
|
-
/** Expanded blocks (templates converted to full blocks with layers) */
|
|
105
|
-
blocks: Block[];
|
|
106
|
-
}
|
|
107
|
-
interface PlaybackActions {
|
|
108
|
-
/** Go to next block */
|
|
109
|
-
nextBlock: () => void;
|
|
110
|
-
/** Go to previous block */
|
|
111
|
-
prevBlock: () => void;
|
|
112
|
-
/** Go to specific block by index */
|
|
113
|
-
goToBlock: (index: number) => void;
|
|
114
|
-
/**
|
|
115
|
-
* Let the identified block enter without remounting the outgoing block.
|
|
116
|
-
* Used when another interaction (such as a swipe) already removed it.
|
|
117
|
-
*/
|
|
118
|
-
suppressOutgoingForNextBlock: (blockId: string) => void;
|
|
119
|
-
}
|
|
120
|
-
interface UseDocPlaybackOptions {
|
|
121
|
-
/** Fallback media root for intrinsic feature metadata. */
|
|
122
|
-
basePath?: string;
|
|
123
|
-
/** Target viewport used to materialize template blocks. */
|
|
124
|
-
viewport?: ViewportConfig;
|
|
125
|
-
/** Active theme used for materialization and transition defaults. */
|
|
126
|
-
theme?: Theme;
|
|
127
|
-
/** Host seek callback used by block navigation actions. */
|
|
128
|
-
onSeek?: (time: number) => void;
|
|
129
|
-
/**
|
|
130
|
-
* Whether real audio-segment timing should reshape the authored block
|
|
131
|
-
* sequence. Synthetic preview tracks are only a playback clock; treating
|
|
132
|
-
* them as narration can merge short authored slides to satisfy narration
|
|
133
|
-
* pacing rules.
|
|
134
|
-
*/
|
|
135
|
-
useAudioSegmentTiming?: boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Derive the outgoing (exiting) block from block order instead of from the
|
|
138
|
-
* block rendered last. Offline capture seeks frames out of order (resume,
|
|
139
|
-
* dedupe, sampling), so the crossfade partner must be a pure function of
|
|
140
|
-
* time. Live playback keeps the render-history path so swipes and manual
|
|
141
|
-
* jumps crossfade from what the viewer actually saw.
|
|
142
|
-
*/
|
|
143
|
-
deterministicTransitions?: boolean;
|
|
144
|
-
/**
|
|
145
|
-
* Motion profile override. Omitted → the doc's own `motion` / frontmatter
|
|
146
|
-
* `squisq-motion`, then the theme's `renderStyle.motionProfile`, then `calm`.
|
|
147
|
-
*/
|
|
148
|
-
motion?: MotionSpec | null;
|
|
149
|
-
}
|
|
150
|
-
declare function useDocPlayback(script: Doc | null, currentTime: number, options?: UseDocPlaybackOptions): PlaybackState & PlaybackActions;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* useViewportOrientation Hook
|
|
154
|
-
*
|
|
155
|
-
* Detects the current viewport orientation and returns the appropriate
|
|
156
|
-
* VIEWPORT_PRESET for rendering docs. Automatically updates when
|
|
157
|
-
* the window is resized.
|
|
158
|
-
*
|
|
159
|
-
* Thresholds:
|
|
160
|
-
* - Portrait: height > width * 1.2 (significantly taller than wide)
|
|
161
|
-
* - Square: width and height within 20% of each other
|
|
162
|
-
* - Landscape: width > height * 1.2 (significantly wider than tall)
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
interface UseViewportOrientationResult {
|
|
166
|
-
/** Current viewport preset configuration */
|
|
167
|
-
viewport: ViewportConfig;
|
|
168
|
-
/** Current orientation name */
|
|
169
|
-
orientation: ViewportOrientation;
|
|
170
|
-
/** Current window dimensions */
|
|
171
|
-
windowSize: {
|
|
172
|
-
width: number;
|
|
173
|
-
height: number;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Hook to detect viewport orientation and return appropriate preset.
|
|
178
|
-
* Updates automatically when window is resized.
|
|
179
|
-
*/
|
|
180
|
-
declare function useViewportOrientation(): UseViewportOrientationResult;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* React context holding the current MediaProvider (or null if none provided).
|
|
184
|
-
*/
|
|
185
|
-
declare const MediaContext: react.Context<MediaProvider | null>;
|
|
186
|
-
/**
|
|
187
|
-
* Policy for document-controlled media URLs. Hosts rendering untrusted
|
|
188
|
-
* documents can provide `LOCAL_ONLY_RESOURCE_POLICY` or an explicit host
|
|
189
|
-
* allow-list without changing their MediaProvider.
|
|
190
|
-
*/
|
|
191
|
-
declare const ResourcePolicyContext: react.Context<ResourcePolicy>;
|
|
192
|
-
declare function useResourcePolicy(): ResourcePolicy;
|
|
193
|
-
/**
|
|
194
|
-
* Hook to access the current MediaProvider from context.
|
|
195
|
-
* Returns null if no provider is set.
|
|
196
|
-
*/
|
|
197
|
-
declare function useMediaProvider(): MediaProvider | null;
|
|
198
|
-
interface UseMediaUrlOptions {
|
|
199
|
-
/** For an SVG image: draw a still (no SMIL/CSS animation), for capture. */
|
|
200
|
-
staticSvg?: boolean;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Hook to resolve a media URL via the MediaProvider (if available).
|
|
204
|
-
* Only provider-less paths use basePath-based resolution; a failed workspace
|
|
205
|
-
* lookup stays unresolved instead of requesting the same path from the page origin.
|
|
206
|
-
*
|
|
207
|
-
* Returns the resolved URL string. Updates when the provider or path changes.
|
|
208
|
-
*
|
|
209
|
-
* An SVG image (`logo.svg`, or an SVG `data:` URL) resolves to core's
|
|
210
|
-
* sanitized re-serialization of it — never the file as written — exactly as
|
|
211
|
-
* an SVG island is shown; see `sanitizedSvgImageUrl`.
|
|
212
|
-
*
|
|
213
|
-
* @param relativePath - Relative media path from the document (e.g., 'hero.jpg')
|
|
214
|
-
* @param basePath - Fallback base path for URL construction
|
|
215
|
-
*/
|
|
216
|
-
declare function useMediaUrl(relativePath: string, basePath: string, options?: UseMediaUrlOptions): string;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Live-track `prefers-color-scheme` and return a stable SurfaceScheme.
|
|
220
|
-
* `enabled: false` short-circuits to LIGHT_SURFACE (callers pass `false`
|
|
221
|
-
* when a static surface was provided so the hook never observes the
|
|
222
|
-
* media query). The `MediaQueryList` and the `subscribe`/`getSnapshot`
|
|
223
|
-
* callbacks are memoized so `useSyncExternalStore` doesn't resubscribe on
|
|
224
|
-
* every parent render.
|
|
225
|
-
*/
|
|
226
|
-
declare function useAutoSurface(enabled: boolean): SurfaceScheme;
|
|
227
|
-
|
|
228
|
-
export { AudioController, MediaContext, type MediaScheduleController, type ModalDialogOptions, ResourcePolicyContext, type UseDocPlaybackOptions, useAudioSync, useAutoSurface, useDocPlayback, useMediaProvider, useMediaSchedule, useMediaUrl, useModalDialog, useResourcePolicy, useViewportOrientation };
|
|
1
|
+
export { M as MediaContext, a as MediaScheduleController, b as ModalDialogOptions, R as ResourcePolicyContext, U as UseDocPlaybackOptions, u as useAudioSync, c as useAutoSurface, d as useDocPlayback, e as useMediaProvider, f as useMediaSchedule, g as useMediaUrl, h as useModalDialog, i as useResourcePolicy, j as useViewportOrientation } from '../hooks-Dxpfol0l.js';
|
|
2
|
+
export { A as AudioActions, a as AudioController, b as AudioState } from '../AudioController-DAwQyEM_.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '@bendyline/squisq/schemas';
|
|
5
|
+
import '@bendyline/squisq/doc';
|
|
6
|
+
import '@bendyline/squisq/markdown';
|
package/dist/hooks/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useDocPlayback,
|
|
7
7
|
useMediaSchedule,
|
|
8
8
|
useViewportOrientation
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-MNY6M5QG.js";
|
|
10
10
|
import {
|
|
11
11
|
useAutoSurface
|
|
12
12
|
} from "../chunk-TT6ENR6T.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
useMediaProvider,
|
|
17
17
|
useMediaUrl,
|
|
18
18
|
useResourcePolicy
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-ZKMBIWAA.js";
|
|
20
20
|
export {
|
|
21
21
|
MediaContext,
|
|
22
22
|
ResourcePolicyContext,
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
import { AudioTrack, ScheduledClip, Theme, MotionSpec, Doc, Block, MediaProvider, MediaClip, SurfaceScheme } from '@bendyline/squisq/schemas';
|
|
4
|
+
import { a as AudioController } from './AudioController-DAwQyEM_.js';
|
|
5
|
+
import { ViewportConfig, ViewportOrientation } from '@bendyline/squisq/doc';
|
|
6
|
+
import { ResourcePolicy } from '@bendyline/squisq/markdown';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* useAudioSync Hook
|
|
10
|
+
*
|
|
11
|
+
* Synchronizes playback state with an audio element. Provides current
|
|
12
|
+
* playback time, playing state, and methods to control audio playback.
|
|
13
|
+
*
|
|
14
|
+
* Handles multiple audio segments (MP3 files) by tracking which segment
|
|
15
|
+
* is currently playing and calculating the overall timeline position.
|
|
16
|
+
*
|
|
17
|
+
* This is the HTML5 Audio implementation of the AudioController interface.
|
|
18
|
+
* Hosts that drive audio through an external player (e.g. a native shell)
|
|
19
|
+
* can supply their own AudioController to DocPlayer instead of this hook.
|
|
20
|
+
*
|
|
21
|
+
* In `synthetic` mode there is no audio element to follow, so a caller that
|
|
22
|
+
* has no segments passes `syntheticDuration` — the document's own timeline
|
|
23
|
+
* length — and the same segment machinery drives a timer instead.
|
|
24
|
+
*
|
|
25
|
+
* Each segment is downloaded whole and attached as a blob URL, so a segment is
|
|
26
|
+
* only playable once its download finishes. A `play()` that arrives earlier (a
|
|
27
|
+
* listener pressing Play right away, or right after seeking into another
|
|
28
|
+
* segment) is recorded as intent and started by the load path on `canplay`.
|
|
29
|
+
* Playing the element immediately would either start an element with no
|
|
30
|
+
* source, whose pending play the attaching `load()` aborts, or start the
|
|
31
|
+
* previous segment. An `AbortError` from `play()` therefore means "superseded",
|
|
32
|
+
* never "unavailable". Seeks are handled the same way: a seek into a segment
|
|
33
|
+
* that is still loading moves the pending position (a scrub drag keeps
|
|
34
|
+
* seeking after it crosses a chapter boundary), because the element still
|
|
35
|
+
* holds the previous segment. The next segment is downloaded shortly before the
|
|
36
|
+
* current one ends, so chapter boundaries do not stall on a fresh download.
|
|
37
|
+
*
|
|
38
|
+
* A segment whose download fails is retried a few times before the narration
|
|
39
|
+
* is reported unavailable, and the waits only count while the page is visible
|
|
40
|
+
* and online. A phone app in the background can lose its network; the segment
|
|
41
|
+
* that failed there now loads, and plays on, when the listener comes back.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
type AudioSyncMode = 'media' | 'synthetic';
|
|
45
|
+
declare function useAudioSync(audioRef: RefObject<HTMLAudioElement>, track: AudioTrack | undefined, basePath?: string, enabled?: boolean, mode?: AudioSyncMode, syntheticDuration?: number): AudioController;
|
|
46
|
+
|
|
47
|
+
interface ModalDialogOptions {
|
|
48
|
+
/** The backdrop/portal root. Siblings of this branch are made inert. */
|
|
49
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
50
|
+
/** The element with `role="dialog"`; focus is trapped within it. */
|
|
51
|
+
dialogRef: RefObject<HTMLElement | null>;
|
|
52
|
+
initialFocusRef?: RefObject<HTMLElement | null>;
|
|
53
|
+
/** Explicit opener/owner to restore after unmount (important when a child uses autofocus). */
|
|
54
|
+
returnFocusRef?: RefObject<HTMLElement | null>;
|
|
55
|
+
/** Whether Escape requests that the dialog close. Defaults to true. */
|
|
56
|
+
closeOnEscape?: boolean;
|
|
57
|
+
onClose: () => void;
|
|
58
|
+
}
|
|
59
|
+
/** Shared focus, keyboard, background-isolation, and restoration behavior for modal dialogs. */
|
|
60
|
+
declare function useModalDialog({ rootRef, dialogRef, initialFocusRef, returnFocusRef, closeOnEscape, onClose, }: ModalDialogOptions): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* useMediaSchedule
|
|
64
|
+
*
|
|
65
|
+
* Pure follower of the playback clock for the media-clip model. Given the
|
|
66
|
+
* resolved {@link ScheduledClip}s and the current time, it returns the clips
|
|
67
|
+
* the player should mount and which of them are active right now.
|
|
68
|
+
* {@link MediaClipLayer} consumes this to drive one hidden `<audio>` /
|
|
69
|
+
* full-bleed `<video>` element per clip. (Annotation-authored clips all render
|
|
70
|
+
* at the player level; template-produced `VideoLayer`s are a separate path and
|
|
71
|
+
* are not part of the schedule.)
|
|
72
|
+
*
|
|
73
|
+
* It owns no clock: `currentTime`/`isPlaying` come from the existing
|
|
74
|
+
* `useAudioSync` provider via `DocPlayer`. With an empty schedule it returns
|
|
75
|
+
* empty lists, so documents without the new media model are unaffected.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
interface MediaScheduleController {
|
|
79
|
+
/** Clips the player mounts (every scheduled clip). */
|
|
80
|
+
renderClips: ScheduledClip[];
|
|
81
|
+
/** Ids of clips whose [absoluteStart, absoluteEnd) contains currentTime. */
|
|
82
|
+
activeIds: Set<string>;
|
|
83
|
+
}
|
|
84
|
+
declare function useMediaSchedule(schedule: ScheduledClip[], currentTime: number): MediaScheduleController;
|
|
85
|
+
|
|
86
|
+
interface PlaybackState {
|
|
87
|
+
/** Currently visible block */
|
|
88
|
+
currentBlock: Block | null;
|
|
89
|
+
/** Index of current block */
|
|
90
|
+
currentBlockIndex: number;
|
|
91
|
+
/** Previous block (for transitions) */
|
|
92
|
+
previousBlock: Block | null;
|
|
93
|
+
/** Whether current block is entering */
|
|
94
|
+
isEntering: boolean;
|
|
95
|
+
/** Whether previous block is exiting */
|
|
96
|
+
isExiting: boolean;
|
|
97
|
+
/** Time relative to current block start */
|
|
98
|
+
blockTime: number;
|
|
99
|
+
/** Progress through current block (0-1) */
|
|
100
|
+
blockProgress: number;
|
|
101
|
+
/** Overall progress through doc (0-1) */
|
|
102
|
+
docProgress: number;
|
|
103
|
+
/** Expanded blocks (templates converted to full blocks with layers) */
|
|
104
|
+
blocks: Block[];
|
|
105
|
+
}
|
|
106
|
+
interface PlaybackActions {
|
|
107
|
+
/** Go to next block */
|
|
108
|
+
nextBlock: () => void;
|
|
109
|
+
/** Go to previous block */
|
|
110
|
+
prevBlock: () => void;
|
|
111
|
+
/** Go to specific block by index */
|
|
112
|
+
goToBlock: (index: number) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Let the identified block enter without remounting the outgoing block.
|
|
115
|
+
* Used when another interaction (such as a swipe) already removed it.
|
|
116
|
+
*/
|
|
117
|
+
suppressOutgoingForNextBlock: (blockId: string) => void;
|
|
118
|
+
}
|
|
119
|
+
interface UseDocPlaybackOptions {
|
|
120
|
+
/** Fallback media root for intrinsic feature metadata. */
|
|
121
|
+
basePath?: string;
|
|
122
|
+
/** Target viewport used to materialize template blocks. */
|
|
123
|
+
viewport?: ViewportConfig;
|
|
124
|
+
/** Active theme used for materialization and transition defaults. */
|
|
125
|
+
theme?: Theme;
|
|
126
|
+
/** Host seek callback used by block navigation actions. */
|
|
127
|
+
onSeek?: (time: number) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Whether real audio-segment timing should reshape the authored block
|
|
130
|
+
* sequence. Synthetic preview tracks are only a playback clock; treating
|
|
131
|
+
* them as narration can merge short authored slides to satisfy narration
|
|
132
|
+
* pacing rules.
|
|
133
|
+
*/
|
|
134
|
+
useAudioSegmentTiming?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Derive the outgoing (exiting) block from block order instead of from the
|
|
137
|
+
* block rendered last. Offline capture seeks frames out of order (resume,
|
|
138
|
+
* dedupe, sampling), so the crossfade partner must be a pure function of
|
|
139
|
+
* time. Live playback keeps the render-history path so swipes and manual
|
|
140
|
+
* jumps crossfade from what the viewer actually saw.
|
|
141
|
+
*/
|
|
142
|
+
deterministicTransitions?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Motion profile override. Omitted → the doc's own `motion` / frontmatter
|
|
145
|
+
* `squisq-motion`, then the theme's `renderStyle.motionProfile`, then `calm`.
|
|
146
|
+
*/
|
|
147
|
+
motion?: MotionSpec | null;
|
|
148
|
+
}
|
|
149
|
+
declare function useDocPlayback(script: Doc | null, currentTime: number, options?: UseDocPlaybackOptions): PlaybackState & PlaybackActions;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* useViewportOrientation Hook
|
|
153
|
+
*
|
|
154
|
+
* Detects the current viewport orientation and returns the appropriate
|
|
155
|
+
* VIEWPORT_PRESET for rendering docs. Automatically updates when
|
|
156
|
+
* the window is resized.
|
|
157
|
+
*
|
|
158
|
+
* Thresholds:
|
|
159
|
+
* - Portrait: height > width * 1.2 (significantly taller than wide)
|
|
160
|
+
* - Square: width and height within 20% of each other
|
|
161
|
+
* - Landscape: width > height * 1.2 (significantly wider than tall)
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
interface UseViewportOrientationResult {
|
|
165
|
+
/** Current viewport preset configuration */
|
|
166
|
+
viewport: ViewportConfig;
|
|
167
|
+
/** Current orientation name */
|
|
168
|
+
orientation: ViewportOrientation;
|
|
169
|
+
/** Current window dimensions */
|
|
170
|
+
windowSize: {
|
|
171
|
+
width: number;
|
|
172
|
+
height: number;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Hook to detect viewport orientation and return appropriate preset.
|
|
177
|
+
* Updates automatically when window is resized.
|
|
178
|
+
*/
|
|
179
|
+
declare function useViewportOrientation(): UseViewportOrientationResult;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* React context holding the current MediaProvider (or null if none provided).
|
|
183
|
+
*/
|
|
184
|
+
declare const MediaContext: react.Context<MediaProvider | null>;
|
|
185
|
+
/**
|
|
186
|
+
* The host's processed-audio lookup (`DocPlayer`'s `processedAudio`), for
|
|
187
|
+
* renderers below the schedule — a video laid out in a slide — that have to
|
|
188
|
+
* find a clip's cleaned-up sound themselves. Undefined when none is wired.
|
|
189
|
+
*/
|
|
190
|
+
declare const ProcessedAudioContext: react.Context<((clip: MediaClip) => string | undefined) | undefined>;
|
|
191
|
+
/**
|
|
192
|
+
* Policy for document-controlled media URLs. Hosts rendering untrusted
|
|
193
|
+
* documents can provide `LOCAL_ONLY_RESOURCE_POLICY` or an explicit host
|
|
194
|
+
* allow-list without changing their MediaProvider.
|
|
195
|
+
*/
|
|
196
|
+
declare const ResourcePolicyContext: react.Context<ResourcePolicy>;
|
|
197
|
+
declare function useResourcePolicy(): ResourcePolicy;
|
|
198
|
+
/**
|
|
199
|
+
* Hook to access the current MediaProvider from context.
|
|
200
|
+
* Returns null if no provider is set.
|
|
201
|
+
*/
|
|
202
|
+
declare function useMediaProvider(): MediaProvider | null;
|
|
203
|
+
interface UseMediaUrlOptions {
|
|
204
|
+
/** For an SVG image: draw a still (no SMIL/CSS animation), for capture. */
|
|
205
|
+
staticSvg?: boolean;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Hook to resolve a media URL via the MediaProvider (if available).
|
|
209
|
+
* Only provider-less paths use basePath-based resolution; a failed workspace
|
|
210
|
+
* lookup stays unresolved instead of requesting the same path from the page origin.
|
|
211
|
+
*
|
|
212
|
+
* Returns the resolved URL string. Updates when the provider or path changes.
|
|
213
|
+
*
|
|
214
|
+
* An SVG image (`logo.svg`, or an SVG `data:` URL) resolves to core's
|
|
215
|
+
* sanitized re-serialization of it — never the file as written — exactly as
|
|
216
|
+
* an SVG island is shown; see `sanitizedSvgImageUrl`.
|
|
217
|
+
*
|
|
218
|
+
* @param relativePath - Relative media path from the document (e.g., 'hero.jpg')
|
|
219
|
+
* @param basePath - Fallback base path for URL construction
|
|
220
|
+
*/
|
|
221
|
+
declare function useMediaUrl(relativePath: string, basePath: string, options?: UseMediaUrlOptions): string;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Live-track `prefers-color-scheme` and return a stable SurfaceScheme.
|
|
225
|
+
* `enabled: false` short-circuits to LIGHT_SURFACE (callers pass `false`
|
|
226
|
+
* when a static surface was provided so the hook never observes the
|
|
227
|
+
* media query). The `MediaQueryList` and the `subscribe`/`getSnapshot`
|
|
228
|
+
* callbacks are memoized so `useSyncExternalStore` doesn't resubscribe on
|
|
229
|
+
* every parent render.
|
|
230
|
+
*/
|
|
231
|
+
declare function useAutoSurface(enabled: boolean): SurfaceScheme;
|
|
232
|
+
|
|
233
|
+
export { MediaContext as M, ProcessedAudioContext as P, ResourcePolicyContext as R, type UseDocPlaybackOptions as U, type MediaScheduleController as a, type ModalDialogOptions as b, useAutoSurface as c, useDocPlayback as d, useMediaProvider as e, useMediaSchedule as f, useMediaUrl as g, useModalDialog as h, useResourcePolicy as i, useViewportOrientation as j, useAudioSync as u };
|