@openpresentation/opf-render 0.31.0 → 0.32.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/README.md +15 -3
- package/dist/chart-options.js +10 -10
- package/dist/charts.js +419 -127
- package/dist/deck-runtime.js +102 -25
- package/dist/element.d.ts +11 -1
- package/dist/element.js +63 -23
- package/dist/font-manifest.js +8 -8
- package/dist/fonts-browser.js +8 -2
- package/dist/fonts.d.ts +3 -2
- package/dist/index.d.ts +46 -1
- package/dist/index.js +2 -0
- package/dist/measure-pictures-node.js +22 -0
- package/dist/measure-pictures.js +185 -0
- package/dist/player.d.ts +22 -4
- package/dist/player.js +48 -33
- package/dist/svg.d.ts +46 -1
- package/dist/svg.js +219 -47
- package/package.json +12 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RenderFonts, ScriptFonts } from "./fonts.js";
|
|
2
2
|
import type { Catalog, Finding, SlideSelection, UnresolvedReferenceDiagnostic } from "@openpresentation/opf";
|
|
3
3
|
export type { SlideSelection } from "@openpresentation/opf";
|
|
4
|
-
import type { SlideComposition, LayoutDiagnostic, TextMeasurement } from "@openpresentation/opf/composition";
|
|
4
|
+
import type { SlideComposition, LayoutDiagnostic, TextMeasurement, PictureLuminance } from "@openpresentation/opf/composition";
|
|
5
5
|
export declare const packageName = "@openpresentation/opf-render";
|
|
6
6
|
|
|
7
7
|
export declare const releaseLane: Readonly<{
|
|
@@ -28,6 +28,11 @@ export declare const engineDefaults: Readonly<{
|
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
|
+
/** LH-145: a picture background could not be read or decoded by `measurePictures`; its scrim is sized for any picture. */
|
|
32
|
+
code: "picture-not-measured";
|
|
33
|
+
path: string;
|
|
34
|
+
message: string;
|
|
35
|
+
} | {
|
|
31
36
|
/** A run stays text because its face cannot safely be written as outlines. */
|
|
32
37
|
code: "text-as-paths-fallback";
|
|
33
38
|
reason: "colour-font" | "restricted" | "shaping";
|
|
@@ -101,6 +106,12 @@ export interface ToSvgOptions {
|
|
|
101
106
|
glyphFallback?: "chain" | "none";
|
|
102
107
|
/** Unscaled reference-pixel clearance around supplied vector text outlines; default 1. */
|
|
103
108
|
textRasterPadding?: number;
|
|
109
|
+
/**
|
|
110
|
+
* LH-02: the luminance grid of a picture (WCAG relative luminance per cell, row order over the whole picture), when the host can read
|
|
111
|
+
* its pixels: the automatic scrim under text on a picture background is then sized for the picture under the text, not for any
|
|
112
|
+
* picture (core `ComposeSlideOptions.pictureLuminance`). Pass the same function to the PPTX export, so both draw the same scrim.
|
|
113
|
+
*/
|
|
114
|
+
pictureLuminance?: (src: string) => PictureLuminance | undefined;
|
|
104
115
|
strictAssets?: boolean;
|
|
105
116
|
imageResolver?: (src: string | undefined, context: { asset: unknown; path: string }) => string | null | undefined;
|
|
106
117
|
onDiagnostic?: (diagnostic: RenderDiagnostic) => void;
|
|
@@ -301,6 +312,40 @@ export declare class OPFRenderError extends Error {
|
|
|
301
312
|
*/
|
|
302
313
|
export declare function resolvePresentation(input: unknown, options?: ToSvgOptions, select?: { slides?: number[] }): ResolvedPresentation;
|
|
303
314
|
|
|
315
|
+
/** The sampler `measurePictures` returns: core's `pictureLuminance` option, plus what it measured. */
|
|
316
|
+
export interface PictureSampler {
|
|
317
|
+
/** The luminance grid of the picture whose authored source is `src`, or undefined when it was not measured (core then sizes the scrim for any picture). */
|
|
318
|
+
(src: string): PictureLuminance | undefined;
|
|
319
|
+
/** The authored sources of the deck's picture backgrounds (slide, deck and theme). */
|
|
320
|
+
readonly sources: readonly string[];
|
|
321
|
+
/** How many of them were measured. */
|
|
322
|
+
readonly measured: number;
|
|
323
|
+
}
|
|
324
|
+
/** The decoded pixels of a picture: 8-bit sRGB in row order, `channels` bytes each (3, or 4 with alpha). */
|
|
325
|
+
export interface DecodedPicture { width: number; height: number; data: ArrayLike<number>; channels: 3 | 4 }
|
|
326
|
+
export interface MeasurePicturesOptions {
|
|
327
|
+
/** The same resolver `toSvg` takes: turns a source (after `asset:` references) into a data URI, bytes or `{ data, mediaType }`. May be async. */
|
|
328
|
+
imageResolver?: (src: string | undefined, context: { asset: unknown; path: string }) => unknown;
|
|
329
|
+
/** Catalogs a theme reference resolves in (its background may be a picture). */
|
|
330
|
+
catalogs?: readonly Catalog[];
|
|
331
|
+
/** Reads a resolved `http:`, `https:` or `blob:` address (`fetch`). Without it only data URIs, bytes and resolver results are read, and nothing is fetched. */
|
|
332
|
+
fetch?: (url: string) => Promise<{ ok?: boolean; status?: number; headers?: { get(name: string): string | null }; arrayBuffer(): Promise<ArrayBuffer> }>;
|
|
333
|
+
/** A Map the host keeps between calls: each resolved picture is decoded once, however often the deck changes. */
|
|
334
|
+
cache?: Map<unknown, Promise<PictureLuminance | null>>;
|
|
335
|
+
/** Decodes picture bytes to at most `maxSide` pixels on the longest side. Default: sharp in Node (the optional peer, loaded on first use), the canvas in a browser. */
|
|
336
|
+
decode?: (bytes: Uint8Array, mediaType: string | undefined, limits: { maxSide: number }) => Promise<DecodedPicture>;
|
|
337
|
+
/** The longest side a picture is decoded at (default 1024). */
|
|
338
|
+
maxSide?: number;
|
|
339
|
+
/** Called with `picture-not-measured` for a picture that could not be read or decoded; its scrim keeps the worst case. */
|
|
340
|
+
onDiagnostic?: (diagnostic: RenderDiagnostic) => void;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* LH-145: the luminance sampler of a deck's picture backgrounds, each decoded once. Pass the result as `pictureLuminance` to `toSvg` and to the
|
|
344
|
+
* PPTX export, so the automatic scrim is sized for the picture under the text in both. Never rejects for a picture it cannot read.
|
|
345
|
+
*/
|
|
346
|
+
export declare function measurePictures(deck: unknown, options?: MeasurePicturesOptions): Promise<PictureSampler>;
|
|
347
|
+
|
|
348
|
+
|
|
304
349
|
/** An SVG slide the renderer drew: its text, or its bytes. */
|
|
305
350
|
export type SvgSlide = string | Uint8Array;
|
|
306
351
|
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// LH-145: the Node entry's `measurePictures` (the browser entries have the canvas version of ./measure-pictures.js). The same function
|
|
2
|
+
// with a decoder that works without a DOM: sharp, an optional peer loaded the first time a picture is measured, as for PNG output
|
|
3
|
+
// (RR-63). Without sharp installed, or for a picture it cannot read, nothing is measured and the scrim keeps its worst case.
|
|
4
|
+
import { loadConverter } from "./converters.js";
|
|
5
|
+
import { measurePictures as measureWith } from "./measure-pictures.js";
|
|
6
|
+
|
|
7
|
+
/** Decodes any picture sharp reads (PNG, JPEG, WebP, GIF, SVG) to at most `maxSide` pixels, upright, as 8-bit sRGB with alpha. */
|
|
8
|
+
export async function decodeWithSharp(bytes, _mediaType, { maxSide }) {
|
|
9
|
+
const { default: sharp } = await loadConverter("sharp");
|
|
10
|
+
const { data, info } = await sharp(bytes, { limitInputPixels: 40_000_000, animated: false })
|
|
11
|
+
.autoOrient()
|
|
12
|
+
.resize({ width: maxSide, height: maxSide, fit: "inside", withoutEnlargement: true })
|
|
13
|
+
.toColourspace("srgb")
|
|
14
|
+
.ensureAlpha()
|
|
15
|
+
.raw()
|
|
16
|
+
.toBuffer({ resolveWithObject: true });
|
|
17
|
+
return { width: info.width, height: info.height, data, channels: info.channels };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function measurePictures(deck, options = {}) {
|
|
21
|
+
return measureWith(deck, { ...options, decode: options.decode ?? decodeWithSharp });
|
|
22
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// LH-145: `measurePictures(deck)` reads the pixels of a deck's picture backgrounds once each and returns the `pictureLuminance` sampler
|
|
2
|
+
// that core composition (`ComposeSlideOptions.pictureLuminance`) and both engines accept, so the automatic scrim of LH-02 is sized for
|
|
3
|
+
// the picture under the text (none on a dark photo under light text) instead of for any picture from black to white.
|
|
4
|
+
//
|
|
5
|
+
// This module is edge-safe: it imports no converter and no Node module, so the browser entries (`/svg`, the editor) can reach it. It
|
|
6
|
+
// reads sources, decodes them with `options.decode` (the Node entry's default is sharp, loaded lazily; the default here is the
|
|
7
|
+
// browser's canvas) and builds each grid with core's `luminanceGrid`. A picture that cannot be read or decoded is left out and
|
|
8
|
+
// reported (`picture-not-measured`): its slide keeps the worst-case scrim, which is always safe.
|
|
9
|
+
import { resolveDesignRecords } from "@openpresentation/opf";
|
|
10
|
+
import { imageBackground, luminanceGrid } from "@openpresentation/opf/composition";
|
|
11
|
+
|
|
12
|
+
/** The longest side a picture is decoded at. A cell of the 32 x 18 grid still spans tens of pixels, and the cost stays flat for any photo. */
|
|
13
|
+
export const MEASURE_MAX_SIDE = 1024;
|
|
14
|
+
/** The largest picture file read (bytes). */
|
|
15
|
+
const MAX_BYTES = 64 * 1024 * 1024;
|
|
16
|
+
|
|
17
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The luminance sampler of a deck's picture backgrounds (slide, deck and theme), measured once each.
|
|
21
|
+
*
|
|
22
|
+
* `deck` is a parsed OPF deck (a JSON string or bytes also work). Sources are followed as the renderer follows them: an `asset:` reference
|
|
23
|
+
* through `deck.assets`, then `options.imageResolver` (the same function `toSvg` takes; it may be async and may return a data URI, bytes or
|
|
24
|
+
* `{ data, mediaType }`). A data URI is decoded as it is; any other string is fetched only when `options.fetch` is given. Nothing else is read.
|
|
25
|
+
* `options.cache` (a Map the host keeps) holds the work per resolved source, so editing a deck decodes a picture once, not on every change; a
|
|
26
|
+
* picture that failed stays failed in it (and is reported once), so a broken file is not decoded again on every edit.
|
|
27
|
+
*/
|
|
28
|
+
export async function measurePictures(deck, options = {}) {
|
|
29
|
+
const presentation = parseDeck(deck);
|
|
30
|
+
const found = backgroundSources(presentation, options.catalogs);
|
|
31
|
+
const cache = options.cache instanceof Map ? options.cache : new Map();
|
|
32
|
+
const decode = options.decode ?? decodeWithCanvas;
|
|
33
|
+
const grids = new Map(), used = new Set();
|
|
34
|
+
await Promise.all(found.map(async ({ src, path }) => {
|
|
35
|
+
try {
|
|
36
|
+
const picture = await readPicture(presentation, src, path, options);
|
|
37
|
+
if (!picture) return;
|
|
38
|
+
used.add(picture.key);
|
|
39
|
+
if (!cache.has(picture.key)) cache.set(picture.key, measure(picture, decode, options.maxSide ?? MEASURE_MAX_SIDE).catch((error) => { note(options, path, error); return null; }));
|
|
40
|
+
const grid = await cache.get(picture.key);
|
|
41
|
+
if (grid) grids.set(src, grid);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
note(options, path, error);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
// A host cache that outlives many edits drops the pictures this deck no longer uses once it holds more than a few.
|
|
47
|
+
if (cache.size > 16) for (const key of [...cache.keys()]) if (!used.has(key)) cache.delete(key);
|
|
48
|
+
const sampler = (src) => grids.get(src);
|
|
49
|
+
Object.defineProperties(sampler, {
|
|
50
|
+
sources: { value: Object.freeze(found.map((entry) => entry.src)), enumerable: true },
|
|
51
|
+
measured: { get: () => grids.size, enumerable: true },
|
|
52
|
+
});
|
|
53
|
+
return sampler;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseDeck(input) {
|
|
57
|
+
const value = input instanceof Uint8Array ? new TextDecoder().decode(input) : input;
|
|
58
|
+
const deck = typeof value === "string" ? JSON.parse(value) : value;
|
|
59
|
+
if (!isRecord(deck)) throw new TypeError("measurePictures needs an OPF deck: a parsed object, a JSON string or bytes.");
|
|
60
|
+
return deck;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Every picture a slide can show as its background: the slide's own, the deck's and the theme's (core composes with the first that is set).
|
|
64
|
+
function backgroundSources(deck, catalogs) {
|
|
65
|
+
const found = new Map();
|
|
66
|
+
const add = (value, path) => {
|
|
67
|
+
const background = imageBackground(value);
|
|
68
|
+
if (background && !found.has(background.src)) found.set(background.src, { src: background.src, path });
|
|
69
|
+
};
|
|
70
|
+
add(isRecord(deck.design) ? deck.design.background : undefined, "design.background");
|
|
71
|
+
const slides = Array.isArray(deck.slides) ? deck.slides : [];
|
|
72
|
+
const themes = new Set();
|
|
73
|
+
slides.forEach((slide, index) => {
|
|
74
|
+
const design = isRecord(slide) && isRecord(slide.design) ? slide.design : {};
|
|
75
|
+
add(design.background, `slides.${index}.design.background`);
|
|
76
|
+
const reference = design.theme ?? (isRecord(deck.design) ? deck.design.theme : undefined);
|
|
77
|
+
const key = typeof reference === "string" ? reference : "";
|
|
78
|
+
if (themes.has(key)) return;
|
|
79
|
+
themes.add(key);
|
|
80
|
+
try { add(resolveDesignRecords(deck, index, catalogs === undefined ? {} : { catalogs }).theme.background, "theme"); } catch { /* an unresolved theme draws the engine default, which has no picture */ }
|
|
81
|
+
});
|
|
82
|
+
return [...found.values()];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The drawable source of a background, as the renderer resolves it (render's resolveImageSource): `asset:` references, then the host's resolver.
|
|
86
|
+
async function readPicture(deck, raw, path, options) {
|
|
87
|
+
const assets = isRecord(deck.assets) ? deck.assets : {};
|
|
88
|
+
const named = (value) => (typeof value === "string" ? { src: value } : isRecord(value) ? value : { src: "" });
|
|
89
|
+
let asset = { src: raw };
|
|
90
|
+
const seen = new Set();
|
|
91
|
+
while (typeof asset.src === "string" && asset.src.startsWith("asset:")) {
|
|
92
|
+
const id = asset.src.slice(6);
|
|
93
|
+
if (seen.has(id) || !Object.hasOwn(assets, id)) return undefined;
|
|
94
|
+
seen.add(id);
|
|
95
|
+
const { src: _source, ...overrides } = asset;
|
|
96
|
+
asset = { ...named(assets[id]), ...overrides };
|
|
97
|
+
}
|
|
98
|
+
if (typeof asset.src !== "string" || !asset.src) return undefined;
|
|
99
|
+
const resolved = (await options.imageResolver?.(asset.src, { asset, path })) ?? asset.src;
|
|
100
|
+
if (typeof resolved === "string") {
|
|
101
|
+
if (/^data:/i.test(resolved)) return { key: resolved, bytes: () => dataUriBytes(resolved) };
|
|
102
|
+
if (typeof options.fetch === "function" && /^(?:https?|blob):/i.test(resolved)) return { key: resolved, bytes: () => fetchBytes(resolved, options.fetch) };
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
if (resolved instanceof Uint8Array) return { key: resolved, bytes: () => ({ bytes: resolved, mediaType: undefined }) };
|
|
106
|
+
if (isRecord(resolved) && resolved.data instanceof Uint8Array) return { key: resolved.data, bytes: () => ({ bytes: resolved.data, mediaType: typeof resolved.mediaType === "string" ? resolved.mediaType : undefined }) };
|
|
107
|
+
if (isRecord(resolved) && typeof resolved.data === "string" && /^data:/i.test(resolved.data)) return { key: resolved.data, bytes: () => dataUriBytes(resolved.data) };
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function dataUriBytes(uri) {
|
|
112
|
+
const comma = uri.indexOf(",");
|
|
113
|
+
const header = uri.slice(5, comma), payload = uri.slice(comma + 1);
|
|
114
|
+
const mediaType = header.split(";")[0].trim().toLowerCase() || undefined;
|
|
115
|
+
let bytes;
|
|
116
|
+
if (/;base64$/i.test(header)) {
|
|
117
|
+
const binary = atob(decodeURIComponent(payload).replace(/\s+/g, ""));
|
|
118
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
119
|
+
} else bytes = new TextEncoder().encode(decodeURIComponent(payload));
|
|
120
|
+
return { bytes, mediaType };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function fetchBytes(url, fetcher) {
|
|
124
|
+
const response = await fetcher(url);
|
|
125
|
+
if (response.ok === false) throw new Error(`The picture could not be fetched (${response.status}).`);
|
|
126
|
+
return { bytes: new Uint8Array(await response.arrayBuffer()), mediaType: response.headers?.get?.("content-type")?.split(";")[0].trim().toLowerCase() || undefined };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const startsWith = (bytes, signature, offset = 0) => signature.every((value, index) => bytes[offset + index] === value);
|
|
130
|
+
/** The media type of picture bytes: what the bytes are, else what the source said. */
|
|
131
|
+
export function sniffMediaType(bytes, declared) {
|
|
132
|
+
if (startsWith(bytes, [0x89, 0x50, 0x4e, 0x47])) return "image/png";
|
|
133
|
+
if (startsWith(bytes, [0xff, 0xd8, 0xff])) return "image/jpeg";
|
|
134
|
+
if (startsWith(bytes, [0x47, 0x49, 0x46, 0x38])) return "image/gif";
|
|
135
|
+
if (startsWith(bytes, [0x52, 0x49, 0x46, 0x46]) && startsWith(bytes, [0x57, 0x45, 0x42, 0x50], 8)) return "image/webp";
|
|
136
|
+
if (/<svg[\s>]/i.test(new TextDecoder().decode(bytes.subarray(0, 4096)))) return "image/svg+xml";
|
|
137
|
+
return declared;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function measure(picture, decode, maxSide) {
|
|
141
|
+
const { bytes, mediaType } = await picture.bytes();
|
|
142
|
+
if (bytes.length > MAX_BYTES) throw new Error(`The picture is larger than ${MAX_BYTES / 1024 / 1024} MB.`);
|
|
143
|
+
const pixels = await decode(bytes, sniffMediaType(bytes, mediaType), { maxSide });
|
|
144
|
+
return luminanceGrid(pixels.data, pixels.width, pixels.height, { channels: pixels.channels });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const note = (options, path, error) => options.onDiagnostic?.({
|
|
148
|
+
code: "picture-not-measured",
|
|
149
|
+
path,
|
|
150
|
+
message: `The picture could not be measured, so its scrim is sized for any picture from black to white: ${error instanceof Error ? error.message : String(error)}`,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The browser decoder: the picture drawn on a canvas at most `maxSide` pixels on its longest side. Rejects where there is no canvas
|
|
155
|
+
* (a Node host passes `decode`, as the Node entry does with sharp).
|
|
156
|
+
*/
|
|
157
|
+
export async function decodeWithCanvas(bytes, mediaType, { maxSide }) {
|
|
158
|
+
const blob = new Blob([bytes], mediaType ? { type: mediaType } : {});
|
|
159
|
+
let source, width, height, release;
|
|
160
|
+
if (mediaType !== "image/svg+xml" && typeof createImageBitmap === "function") {
|
|
161
|
+
source = await createImageBitmap(blob);
|
|
162
|
+
({ width, height } = source);
|
|
163
|
+
release = () => source.close?.();
|
|
164
|
+
} else if (typeof Image === "function" && typeof URL?.createObjectURL === "function") {
|
|
165
|
+
const url = URL.createObjectURL(blob);
|
|
166
|
+
source = new Image();
|
|
167
|
+
source.src = url;
|
|
168
|
+
try { await source.decode(); } finally { URL.revokeObjectURL(url); }
|
|
169
|
+
({ naturalWidth: width, naturalHeight: height } = source);
|
|
170
|
+
} else throw new Error("This host cannot decode pictures: pass options.decode.");
|
|
171
|
+
try {
|
|
172
|
+
if (!(width > 0 && height > 0)) throw new Error("The picture has no size.");
|
|
173
|
+
const factor = Math.min(1, maxSide / Math.max(width, height));
|
|
174
|
+
const w = Math.max(1, Math.round(width * factor)), h = Math.max(1, Math.round(height * factor));
|
|
175
|
+
const canvas = typeof OffscreenCanvas === "function" ? new OffscreenCanvas(w, h) : Object.assign(document.createElement("canvas"), { width: w, height: h });
|
|
176
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
177
|
+
if (!context) throw new Error("This host has no 2D canvas.");
|
|
178
|
+
context.imageSmoothingQuality = "high";
|
|
179
|
+
context.drawImage(source, 0, 0, w, h);
|
|
180
|
+
const { data } = context.getImageData(0, 0, w, h);
|
|
181
|
+
return { width: w, height: h, data, channels: 4 };
|
|
182
|
+
} finally {
|
|
183
|
+
release?.();
|
|
184
|
+
}
|
|
185
|
+
}
|
package/dist/player.d.ts
CHANGED
|
@@ -11,8 +11,12 @@ export declare class DeckError extends Error {
|
|
|
11
11
|
constructor(code: string, message: string, options?: { cause?: unknown; source?: string; status?: number; contentType?: string });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The slide that is showing, in the sequence that plays (hidden slides are not counted). `notes` is plain text. LH-99: `page` (from 1)
|
|
16
|
+
* and `pages` say which page of a slide the export continues is showing; the pages are steps after their slide, and `slide` and
|
|
17
|
+
* `index` keep naming the source slide. Every step fires the event, a page step included.
|
|
18
|
+
*/
|
|
19
|
+
export interface PlayerSlideChange { slide: number; total: number; index: number; page: number; pages: number; id?: string; title: string; notes: string; section?: string }
|
|
16
20
|
|
|
17
21
|
export type BlankMode = "none" | "black" | "white";
|
|
18
22
|
|
|
@@ -23,6 +27,13 @@ export interface PresentOptions {
|
|
|
23
27
|
renderOptions?: Partial<ToSvgOptions>;
|
|
24
28
|
/** 1-based slide to start on, in the sequence that plays. Default 1. */
|
|
25
29
|
startSlide?: number;
|
|
30
|
+
/** LH-99: the 1-based page of `startSlide` to start on, for a slide the export continues. Default 1. */
|
|
31
|
+
startPage?: number;
|
|
32
|
+
/**
|
|
33
|
+
* LH-99: show an overfull slide as the pages the export continues it on (`continueOverfull`, LH-90), as steps after the slide.
|
|
34
|
+
* Default true; `false` draws every slide as written.
|
|
35
|
+
*/
|
|
36
|
+
continuation?: boolean;
|
|
26
37
|
/** Play hidden slides too. Default false. */
|
|
27
38
|
includeHidden?: boolean;
|
|
28
39
|
/** Ask for full screen (needs a user gesture). Default true. */
|
|
@@ -44,18 +55,25 @@ export interface PresentOptions {
|
|
|
44
55
|
store?: unknown;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
/** A running slideshow. Events: `slidechange` (PlayerSlideChange), `blank` ({ mode }), `presenterview` ({ open }), `close` ({ slide, index }). */
|
|
58
|
+
/** A running slideshow. Events: `slidechange` (PlayerSlideChange), `blank` ({ mode }), `presenterview` ({ open }), `close` ({ slide, index, page }). */
|
|
48
59
|
export declare class PlayerSession extends EventTarget {
|
|
49
60
|
/** The 1-based number of the showing slide. */
|
|
50
61
|
readonly slide: number;
|
|
51
62
|
readonly total: number;
|
|
63
|
+
/** LH-99: the 1-based page of the showing slide, and how many pages it draws on (2 or more for a slide the export continues). */
|
|
64
|
+
readonly page: number;
|
|
65
|
+
readonly pages: number;
|
|
52
66
|
readonly blankMode: BlankMode;
|
|
53
67
|
readonly closed: boolean;
|
|
54
68
|
readonly presenterViewOpen: boolean;
|
|
69
|
+
/** The next step: the next page of a continued slide, else the next slide. */
|
|
55
70
|
next(): boolean;
|
|
71
|
+
/** The previous step: the previous page, else the last page of the slide before. */
|
|
56
72
|
previous(): boolean;
|
|
57
73
|
first(): boolean;
|
|
74
|
+
/** The last page of the last slide. */
|
|
58
75
|
last(): boolean;
|
|
76
|
+
/** The source slide with this 1-based number, on its first page. */
|
|
59
77
|
goto(number: number): boolean;
|
|
60
78
|
blank(mode?: BlankMode): boolean;
|
|
61
79
|
toggleFullscreen(): void;
|
|
@@ -67,7 +85,7 @@ export declare class PlayerSession extends EventTarget {
|
|
|
67
85
|
addEventListener(type: "slidechange", listener: (event: CustomEvent<PlayerSlideChange>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
68
86
|
addEventListener(type: "blank", listener: (event: CustomEvent<{ mode: BlankMode }>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
69
87
|
addEventListener(type: "presenterview", listener: (event: CustomEvent<{ open: boolean }>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
70
|
-
addEventListener(type: "close", listener: (event: CustomEvent<{ slide: number; index?: number }>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
88
|
+
addEventListener(type: "close", listener: (event: CustomEvent<{ slide: number; index?: number; page?: number }>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
71
89
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
72
90
|
}
|
|
73
91
|
|
package/dist/player.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// shows the renderer's own SVG; windows of one deck follow each other over a BroadcastChannel (same origin). Hidden
|
|
4
4
|
// slides are skipped. No transitions or builds (deferred, opf#250) and no rich notes (opf#251): notes are plain text.
|
|
5
5
|
import {
|
|
6
|
-
DeckError, createCursor, createDeckStore, createSync, createTimer, deckChannelName, formatDuration, localIsoDate, newSurfaceId,
|
|
6
|
+
DeckError, counterText, createCursor, createDeckStore, createSync, createTimer, deckChannelName, formatDuration, localIsoDate, newSurfaceId,
|
|
7
7
|
parseDeckDocument, plainText, presentableIndexes, prepareSlideSvg, sanitizeSvgTree, slideLabel, stateWins, svgDimensions,
|
|
8
8
|
} from "./deck-runtime.js";
|
|
9
9
|
import { loadPreviewFonts } from "./preview-fonts.js";
|
|
@@ -157,7 +157,8 @@ class Surface {
|
|
|
157
157
|
this.digitTimer = undefined;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
// LH-99: the page of a slide the export continues travels with the slide, so every window shows the same step.
|
|
161
|
+
state() { return { index: this.cursor.index, page: this.cursor.page, blank: this.blank, rev: this.rev }; }
|
|
161
162
|
|
|
162
163
|
/** Say hello: the other windows of the show answer with where it is, and this window takes the first answer. */
|
|
163
164
|
join() { this.joining = true; this.sync.hello(); }
|
|
@@ -172,8 +173,8 @@ class Surface {
|
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
/** Move to a state. `broadcast` is false for a state that came from another window. */
|
|
175
|
-
apply({ index, blank }, { broadcast = true } = {}) {
|
|
176
|
-
const moved = index !== undefined ? this.cursor.gotoIndex(index) : false;
|
|
176
|
+
apply({ index, page, blank }, { broadcast = true } = {}) {
|
|
177
|
+
const moved = index !== undefined ? this.cursor.gotoIndex(index, page ?? 0) : false;
|
|
177
178
|
const blankChanged = blank !== undefined && blank !== this.blank;
|
|
178
179
|
if (blankChanged) this.blank = blank;
|
|
179
180
|
if (!moved && !blankChanged) return false;
|
|
@@ -189,16 +190,19 @@ class Surface {
|
|
|
189
190
|
return true;
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
/** A slide by its sequence position, on its first page (or `page`). */
|
|
194
|
+
navigate(position, page = 0) {
|
|
193
195
|
const sequence = this.cursor.sequence;
|
|
194
196
|
const target = Math.min(Math.max(position, 0), sequence.length - 1);
|
|
195
|
-
if (target === this.cursor.position) return false;
|
|
196
|
-
return this.apply({ index: sequence[target] });
|
|
197
|
+
if (target === this.cursor.position && page === this.cursor.page) return false;
|
|
198
|
+
return this.apply({ index: sequence[target], page });
|
|
197
199
|
}
|
|
198
|
-
next()
|
|
199
|
-
|
|
200
|
+
/** One step: the next or previous page of a continued slide (LH-99), else the next or previous slide. */
|
|
201
|
+
step(delta) { const target = this.cursor.peek(delta); return target ? this.apply({ index: target.index, page: target.page }) : false; }
|
|
202
|
+
next() { return this.step(1); }
|
|
203
|
+
previous() { return this.step(-1); }
|
|
200
204
|
first() { return this.navigate(0); }
|
|
201
|
-
last() { return this.navigate(this.cursor.
|
|
205
|
+
last() { const position = this.cursor.total - 1; return this.navigate(position, this.store.pages(this.cursor.sequence[position]) - 1); }
|
|
202
206
|
goto(number) { return this.navigate(number - 1); }
|
|
203
207
|
setBlank(mode) { return this.apply({ blank: this.blank === mode ? "none" : mode }); }
|
|
204
208
|
|
|
@@ -283,24 +287,24 @@ function mountAudience({ doc, win, container, session }) {
|
|
|
283
287
|
const { cursor, store } = surface;
|
|
284
288
|
const info = store.info(cursor.index);
|
|
285
289
|
let svg;
|
|
286
|
-
try { svg = store.svg(cursor.index); } catch (error) { view.failed(error.message); return; }
|
|
290
|
+
try { svg = store.svg(cursor.index, cursor.page); } catch (error) { view.failed(error.message); return; }
|
|
287
291
|
parts.message.hidden = true;
|
|
288
292
|
const { width, height } = drawInto(parts.slide, svg, doc);
|
|
289
293
|
parts.frame.style.setProperty("--ratio", `${width} / ${height}`);
|
|
290
294
|
parts.frame.style.setProperty("--ratio-n", String(width / height));
|
|
291
|
-
const label = slideLabel(info, cursor.number, cursor.total);
|
|
295
|
+
const label = slideLabel(info, cursor.number, cursor.total, cursor.page + 1, cursor.pages);
|
|
292
296
|
parts.slide.setAttribute("aria-label", label);
|
|
293
|
-
parts.counterText.textContent =
|
|
294
|
-
parts.prev.setAttribute("aria-disabled", String(cursor.
|
|
295
|
-
parts.next.setAttribute("aria-disabled", String(cursor.
|
|
297
|
+
parts.counterText.textContent = counterText(cursor.number, cursor.total, cursor.page + 1, cursor.pages);
|
|
298
|
+
parts.prev.setAttribute("aria-disabled", String(cursor.atStart));
|
|
299
|
+
parts.next.setAttribute("aria-disabled", String(cursor.atEnd));
|
|
296
300
|
parts.blank.hidden = surface.blank === "none";
|
|
297
301
|
parts.blank.className = `blank ${surface.blank === "white" ? "white" : "black"}`;
|
|
298
302
|
// Announce a new slide, and a blank screen; not the first draw.
|
|
299
303
|
if (view.drawn) parts.live.textContent = surface.blank !== "none" ? `${surface.blank === "white" ? "White" : "Black"} screen` : label;
|
|
300
304
|
view.drawn = true;
|
|
301
305
|
this.renderDigits(surface);
|
|
302
|
-
const next = cursor.
|
|
303
|
-
if (next
|
|
306
|
+
const next = cursor.peek(1);
|
|
307
|
+
if (next) win.setTimeout(() => { try { store.svg(next.index, next.page); } catch { /* shown (and reported) when reached */ } }, 0);
|
|
304
308
|
},
|
|
305
309
|
renderDigits(surface) {
|
|
306
310
|
parts.goto.hidden = !surface.digits;
|
|
@@ -430,25 +434,27 @@ function mountPresenter({ doc, win, name, session, now, duration, parent, target
|
|
|
430
434
|
const { cursor, store } = surface;
|
|
431
435
|
const info = store.info(cursor.index);
|
|
432
436
|
let svg;
|
|
433
|
-
try { svg = store.svg(cursor.index); } catch (error) { parts.currentSlide.textContent = error.message; return; }
|
|
437
|
+
try { svg = store.svg(cursor.index, cursor.page); } catch (error) { parts.currentSlide.textContent = error.message; return; }
|
|
434
438
|
const { width, height } = drawInto(parts.currentSlide, svg, doc);
|
|
435
439
|
parts.root.style.setProperty("--ratio", `${width} / ${height}`);
|
|
436
|
-
|
|
437
|
-
parts.
|
|
440
|
+
const label = slideLabel(info, cursor.number, cursor.total, cursor.page + 1, cursor.pages);
|
|
441
|
+
parts.currentSlide.setAttribute("aria-label", label);
|
|
442
|
+
parts.position.textContent = `Slide ${cursor.number} of ${cursor.total}${cursor.pages > 1 ? `, page ${cursor.page + 1} of ${cursor.pages}` : ""}`;
|
|
438
443
|
parts.section.textContent = info.section ? `Section: ${info.section}` : "";
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
// The next step: the next page of a continued slide (LH-99), else the next slide.
|
|
445
|
+
const next = cursor.peek(1);
|
|
446
|
+
parts.end.hidden = next !== undefined;
|
|
447
|
+
if (next) { try { drawInto(parts.nextSlide, store.svg(next.index, next.page), doc, { aria: "hidden" }); } catch { parts.nextSlide.replaceChildren(); } }
|
|
442
448
|
else parts.nextSlide.replaceChildren();
|
|
443
449
|
// Plain text only: notes are never parsed as markup.
|
|
444
450
|
parts.notes.textContent = info.notes || "No notes for this slide.";
|
|
445
451
|
parts.notes.style.color = info.notes ? "" : "#aab2bd";
|
|
446
452
|
parts.notes.scrollTop = 0;
|
|
447
|
-
parts.prev.setAttribute("aria-disabled", String(cursor.
|
|
448
|
-
parts.next.setAttribute("aria-disabled", String(cursor.
|
|
453
|
+
parts.prev.setAttribute("aria-disabled", String(cursor.atStart));
|
|
454
|
+
parts.next.setAttribute("aria-disabled", String(cursor.atEnd));
|
|
449
455
|
parts.black.setAttribute("aria-pressed", String(surface.blank === "black"));
|
|
450
456
|
parts.white.setAttribute("aria-pressed", String(surface.blank === "white"));
|
|
451
|
-
if (view.drawn) parts.live.textContent =
|
|
457
|
+
if (view.drawn) parts.live.textContent = label;
|
|
452
458
|
view.drawn = true;
|
|
453
459
|
this.renderDigits(surface);
|
|
454
460
|
view.tick();
|
|
@@ -514,6 +520,9 @@ export class PlayerSession extends EventTarget {
|
|
|
514
520
|
/** The 1-based number of the showing slide, in the sequence that plays (hidden slides are not counted). */
|
|
515
521
|
get slide() { return this.primary?.cursor.number ?? 0; }
|
|
516
522
|
get total() { return this.primary?.cursor.total ?? 0; }
|
|
523
|
+
/** LH-99: the 1-based page of the showing slide, and how many pages it draws on (2 or more for a slide the export continues). */
|
|
524
|
+
get page() { return this.primary ? this.primary.cursor.page + 1 : 0; }
|
|
525
|
+
get pages() { return this.primary?.cursor.pages ?? 0; }
|
|
517
526
|
/** `"none"`, `"black"` or `"white"`. */
|
|
518
527
|
get blankMode() { return this.primary?.blank ?? "none"; }
|
|
519
528
|
/** Whether the speaker view window is open. */
|
|
@@ -532,7 +541,7 @@ export class PlayerSession extends EventTarget {
|
|
|
532
541
|
if (this.closed || surface !== this.primary) return;
|
|
533
542
|
if (moved) {
|
|
534
543
|
const info = surface.store.info(surface.cursor.index);
|
|
535
|
-
this.dispatchEvent(new CustomEvent("slidechange", { detail: { slide: surface.cursor.number, total: surface.cursor.total, index: info.index, id: info.id, title: info.title, notes: info.notes, section: info.section } }));
|
|
544
|
+
this.dispatchEvent(new CustomEvent("slidechange", { detail: { slide: surface.cursor.number, total: surface.cursor.total, index: info.index, page: surface.cursor.page + 1, pages: surface.cursor.pages, id: info.id, title: info.title, notes: info.notes, section: info.section } }));
|
|
536
545
|
}
|
|
537
546
|
if (blankChanged) this.dispatchEvent(new CustomEvent("blank", { detail: { mode: surface.blank } }));
|
|
538
547
|
}
|
|
@@ -571,7 +580,10 @@ export class PlayerSession extends EventTarget {
|
|
|
571
580
|
const doc = win.document;
|
|
572
581
|
doc.open(); doc.write('<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>'); doc.close();
|
|
573
582
|
const view = mountPresenter({ doc, win, name: this.name, session: this, now: this.now, duration: this.duration, parent: this.doc, target: doc.body, styleTarget: doc.head, setTitle: true });
|
|
574
|
-
const
|
|
583
|
+
const store = this.primary.store;
|
|
584
|
+
const cursor = createCursor(this.primary.cursor.sequence, this.primary.cursor.position, { pagesOf: (index) => store.pages(index) });
|
|
585
|
+
cursor.set(this.primary.cursor.position, this.primary.cursor.page);
|
|
586
|
+
const surface = new Surface({ role: "presenter", doc, win, store, cursor, session: this, view, channelName: this.channelName });
|
|
575
587
|
view.surface = surface;
|
|
576
588
|
surface.blank = this.primary.blank;
|
|
577
589
|
this.surfaces.add(surface);
|
|
@@ -601,7 +613,7 @@ export class PlayerSession extends EventTarget {
|
|
|
601
613
|
/** End the slideshow: leave full screen, close the speaker view, give focus back. Fires `close`. Safe to call twice. */
|
|
602
614
|
close() {
|
|
603
615
|
if (this.closed) return;
|
|
604
|
-
const slide = this.slide, index = this.primary?.cursor.index;
|
|
616
|
+
const slide = this.slide, index = this.primary?.cursor.index, page = this.page;
|
|
605
617
|
this.closePresenterView();
|
|
606
618
|
this.closed = true;
|
|
607
619
|
this.doc.removeEventListener("fullscreenchange", this.onFullscreen);
|
|
@@ -611,7 +623,7 @@ export class PlayerSession extends EventTarget {
|
|
|
611
623
|
this.surfaces.clear();
|
|
612
624
|
this.abort?.abort();
|
|
613
625
|
if (this.doc.fullscreenElement && this.enteredFullscreen) this.doc.exitFullscreen?.()?.catch?.(() => {});
|
|
614
|
-
this.dispatchEvent(new CustomEvent("close", { detail: { slide, index } }));
|
|
626
|
+
this.dispatchEvent(new CustomEvent("close", { detail: { slide, index, page } }));
|
|
615
627
|
}
|
|
616
628
|
}
|
|
617
629
|
|
|
@@ -676,16 +688,19 @@ export async function present(source, options = {}) {
|
|
|
676
688
|
let fonts = options.fonts;
|
|
677
689
|
if (typeof fonts === "string") { try { fonts = await loadPreviewFonts(fonts, { signal: abort.signal }); } catch { fonts = undefined; } }
|
|
678
690
|
const date = options.renderOptions?.date ?? localIsoDate();
|
|
679
|
-
|
|
691
|
+
const continuation = options.continuation !== false;
|
|
692
|
+
store = options.store ?? createDeckStore({ document: deck, fonts, renderOptions: options.renderOptions ?? {}, date, continuation });
|
|
680
693
|
try { await store.ready(abort.signal); } catch (error) {
|
|
681
694
|
if (!fonts || options.store) throw error;
|
|
682
|
-
store = createDeckStore({ document: deck, renderOptions: options.renderOptions ?? {}, date });
|
|
695
|
+
store = createDeckStore({ document: deck, renderOptions: options.renderOptions ?? {}, date, continuation });
|
|
683
696
|
}
|
|
684
697
|
abort.signal.throwIfAborted?.();
|
|
685
698
|
session.name = plainText(deck.name) || "Presentation";
|
|
686
699
|
session.duration = Number(deck.duration);
|
|
687
700
|
session.channelName = options.channel === false ? "" : (options.channel ?? deckChannelName(deck));
|
|
688
|
-
const
|
|
701
|
+
const drawn = store;
|
|
702
|
+
const cursor = createCursor(sequence, Number.isInteger(options.startSlide) ? options.startSlide - 1 : 0, { pagesOf: (index) => drawn.pages(index) });
|
|
703
|
+
if (Number.isInteger(options.startPage)) cursor.set(cursor.position, options.startPage - 1);
|
|
689
704
|
if (!view) {
|
|
690
705
|
// The speaker view in this window (a second tab or window of the host page): its own shadow root over the page.
|
|
691
706
|
const host = doc.createElement("div");
|
package/dist/svg.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RenderFonts, ScriptFonts } from "./fonts.js";
|
|
2
2
|
import type { Catalog, Finding, SlideSelection, UnresolvedReferenceDiagnostic } from "@openpresentation/opf";
|
|
3
3
|
export type { SlideSelection } from "@openpresentation/opf";
|
|
4
|
-
import type { SlideComposition, LayoutDiagnostic, TextMeasurement } from "@openpresentation/opf/composition";
|
|
4
|
+
import type { SlideComposition, LayoutDiagnostic, TextMeasurement, PictureLuminance } from "@openpresentation/opf/composition";
|
|
5
5
|
export declare const packageName = "@openpresentation/opf-render";
|
|
6
6
|
|
|
7
7
|
export declare const releaseLane: Readonly<{
|
|
@@ -28,6 +28,11 @@ export declare const engineDefaults: Readonly<{
|
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
|
+
/** LH-145: a picture background could not be read or decoded by `measurePictures`; its scrim is sized for any picture. */
|
|
32
|
+
code: "picture-not-measured";
|
|
33
|
+
path: string;
|
|
34
|
+
message: string;
|
|
35
|
+
} | {
|
|
31
36
|
/** A run stays text because its face cannot safely be written as outlines. */
|
|
32
37
|
code: "text-as-paths-fallback";
|
|
33
38
|
reason: "colour-font" | "restricted" | "shaping";
|
|
@@ -101,6 +106,12 @@ export interface ToSvgOptions {
|
|
|
101
106
|
glyphFallback?: "chain" | "none";
|
|
102
107
|
/** Unscaled reference-pixel clearance around supplied vector text outlines; default 1. */
|
|
103
108
|
textRasterPadding?: number;
|
|
109
|
+
/**
|
|
110
|
+
* LH-02: the luminance grid of a picture (WCAG relative luminance per cell, row order over the whole picture), when the host can read
|
|
111
|
+
* its pixels: the automatic scrim under text on a picture background is then sized for the picture under the text, not for any
|
|
112
|
+
* picture (core `ComposeSlideOptions.pictureLuminance`). Pass the same function to the PPTX export, so both draw the same scrim.
|
|
113
|
+
*/
|
|
114
|
+
pictureLuminance?: (src: string) => PictureLuminance | undefined;
|
|
104
115
|
strictAssets?: boolean;
|
|
105
116
|
imageResolver?: (src: string | undefined, context: { asset: unknown; path: string }) => string | null | undefined;
|
|
106
117
|
onDiagnostic?: (diagnostic: RenderDiagnostic) => void;
|
|
@@ -196,6 +207,40 @@ export declare class OPFRenderError extends Error {
|
|
|
196
207
|
*/
|
|
197
208
|
export declare function resolvePresentation(input: unknown, options?: ToSvgOptions, select?: { slides?: number[] }): ResolvedPresentation;
|
|
198
209
|
|
|
210
|
+
/** The sampler `measurePictures` returns: core's `pictureLuminance` option, plus what it measured. */
|
|
211
|
+
export interface PictureSampler {
|
|
212
|
+
/** The luminance grid of the picture whose authored source is `src`, or undefined when it was not measured (core then sizes the scrim for any picture). */
|
|
213
|
+
(src: string): PictureLuminance | undefined;
|
|
214
|
+
/** The authored sources of the deck's picture backgrounds (slide, deck and theme). */
|
|
215
|
+
readonly sources: readonly string[];
|
|
216
|
+
/** How many of them were measured. */
|
|
217
|
+
readonly measured: number;
|
|
218
|
+
}
|
|
219
|
+
/** The decoded pixels of a picture: 8-bit sRGB in row order, `channels` bytes each (3, or 4 with alpha). */
|
|
220
|
+
export interface DecodedPicture { width: number; height: number; data: ArrayLike<number>; channels: 3 | 4 }
|
|
221
|
+
export interface MeasurePicturesOptions {
|
|
222
|
+
/** The same resolver `toSvg` takes: turns a source (after `asset:` references) into a data URI, bytes or `{ data, mediaType }`. May be async. */
|
|
223
|
+
imageResolver?: (src: string | undefined, context: { asset: unknown; path: string }) => unknown;
|
|
224
|
+
/** Catalogs a theme reference resolves in (its background may be a picture). */
|
|
225
|
+
catalogs?: readonly Catalog[];
|
|
226
|
+
/** Reads a resolved `http:`, `https:` or `blob:` address (`fetch`). Without it only data URIs, bytes and resolver results are read, and nothing is fetched. */
|
|
227
|
+
fetch?: (url: string) => Promise<{ ok?: boolean; status?: number; headers?: { get(name: string): string | null }; arrayBuffer(): Promise<ArrayBuffer> }>;
|
|
228
|
+
/** A Map the host keeps between calls: each resolved picture is decoded once, however often the deck changes. */
|
|
229
|
+
cache?: Map<unknown, Promise<PictureLuminance | null>>;
|
|
230
|
+
/** Decodes picture bytes to at most `maxSide` pixels on the longest side. Default: sharp in Node (the optional peer, loaded on first use), the canvas in a browser. */
|
|
231
|
+
decode?: (bytes: Uint8Array, mediaType: string | undefined, limits: { maxSide: number }) => Promise<DecodedPicture>;
|
|
232
|
+
/** The longest side a picture is decoded at (default 1024). */
|
|
233
|
+
maxSide?: number;
|
|
234
|
+
/** Called with `picture-not-measured` for a picture that could not be read or decoded; its scrim keeps the worst case. */
|
|
235
|
+
onDiagnostic?: (diagnostic: RenderDiagnostic) => void;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* LH-145: the luminance sampler of a deck's picture backgrounds, each decoded once. Pass the result as `pictureLuminance` to `toSvg` and to the
|
|
239
|
+
* PPTX export, so the automatic scrim is sized for the picture under the text in both. Never rejects for a picture it cannot read.
|
|
240
|
+
*/
|
|
241
|
+
export declare function measurePictures(deck: unknown, options?: MeasurePicturesOptions): Promise<PictureSampler>;
|
|
242
|
+
|
|
243
|
+
|
|
199
244
|
/** An SVG slide the renderer drew: its text, or its bytes. */
|
|
200
245
|
export type SvgSlide = string | Uint8Array;
|
|
201
246
|
|