@treasure-ai/treasure-deck 2026.11.0 → 2026.11.2

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.
@@ -0,0 +1,722 @@
1
+ import { evaluate, withDeckPage } from './chrome.js';
2
+ import { DeckError } from './parse.js';
3
+ /** System UI fonts, which Google Slides draws in Inter: a regex alternation (also used in the page). */
4
+ export const SYSTEM_FONTS = '-apple-system|BlinkMacSystemFont|system-ui|SF Pro|Segoe UI|ui-sans-serif';
5
+ /** Code fonts that join `===`, `->`, … into one glyph, which Slides can't turn off: a regex alternation. */
6
+ export const LIGATURE_FONTS = 'JetBrains Mono|Fira Code|Cascadia Code|Cascadia Mono|Monaspace';
7
+ /** Shared page helpers: `rgb(css)` turns any CSS color, over the slide's background, into sRGB 0–1. */
8
+ const HELPERS = `
9
+ window.__slides ??= (() => {
10
+ const canvas = document.createElement('canvas');
11
+ canvas.width = canvas.height = 1;
12
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
13
+ const probe = document.createElement('span');
14
+ const rgb = (css, over) => {
15
+ ctx.clearRect(0, 0, 1, 1);
16
+ ctx.fillStyle = over || '#fff';
17
+ ctx.fillRect(0, 0, 1, 1);
18
+ ctx.fillStyle = css;
19
+ ctx.fillRect(0, 0, 1, 1);
20
+ const d = ctx.getImageData(0, 0, 1, 1).data;
21
+ return { red: d[0] / 255, green: d[1] / 255, blue: d[2] / 255 };
22
+ };
23
+ // A CSS color through the cascade of an element (var(), relative colors), as the computed color string.
24
+ const resolve = (el, css) => {
25
+ el.appendChild(probe);
26
+ probe.style.color = '';
27
+ probe.style.color = css;
28
+ const c = getComputedStyle(probe).color;
29
+ probe.remove();
30
+ return c;
31
+ };
32
+ return { rgb, resolve };
33
+ })();
34
+ `;
35
+ const STYLE = `(() => {
36
+ ${HELPERS}
37
+ const { rgb, resolve } = window.__slides;
38
+ const slide = document.querySelector('.deck-stage > .slide.layout-content') || document.querySelector('.deck-stage > .slide');
39
+ const cs = getComputedStyle(slide);
40
+ const bg = resolve(slide, 'var(--deck-bg)');
41
+ const color = (css) => rgb(resolve(slide, css), bg);
42
+ const heading = slide.querySelector('.slide-header h1, .slide-header h2');
43
+ const hs = heading && getComputedStyle(heading);
44
+ const clear = (c) => !c || c === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(c);
45
+ return {
46
+ background: rgb(bg),
47
+ text: color('var(--deck-fg)'),
48
+ muted: color('var(--deck-fg-muted, var(--deck-fg))'),
49
+ accent: color('var(--deck-accent)'),
50
+ title: hs && !clear(hs.webkitTextFillColor) && !clear(hs.color) ? rgb(hs.color, bg) : color('var(--deck-accent)'),
51
+ palette: [1, 2, 3, 4, 5, 6].map((n) => resolve(slide, 'var(--deck-series-' + n + ', transparent)')).filter((c) => !clear(c)).map((c) => rgb(c, bg)),
52
+ card: clear(resolve(slide, 'var(--deck-card, transparent)')) ? undefined : color('var(--deck-card)'),
53
+ fonts: {
54
+ display: cs.getPropertyValue('--deck-font-display').trim(),
55
+ body: cs.getPropertyValue('--deck-font-body').trim(),
56
+ mono: cs.getPropertyValue('--deck-font-mono').trim(),
57
+ },
58
+ };
59
+ })()`;
60
+ /**
61
+ * Measure slide i's text, then hide it (so the picture taken next has none): each block's text as runs, positioned
62
+ * by the range of its own text (a list item's nested list is a block of its own).
63
+ */
64
+ const MEASURE = (i) => `(async () => {
65
+ ${HELPERS}
66
+ const { rgb, resolve } = window.__slides;
67
+ const slides = document.querySelectorAll('.deck-stage > .slide');
68
+ slides.forEach((s, k) => s.classList.toggle('active', k === ${i}));
69
+ const slide = slides[${i}];
70
+ // Themes that drift a gradient across the deck draw every slide as the first: slides of a layout share its picture.
71
+ slide.style.setProperty('--deck-progress', '0');
72
+ const origin = slide.getBoundingClientRect();
73
+ // The slide's title, for the title placeholder of its layout.
74
+ const titleEl = slide.querySelector('.slide-header h1, .slide-header h2') || slide.querySelector('.slide-body > h1');
75
+ const bg = resolve(slide, 'var(--deck-bg)');
76
+ const isBlock = (el) => { const d = getComputedStyle(el).display; return d !== 'contents' && !d.startsWith('inline'); };
77
+ const blockOf = (node) => { let el = node.parentElement; while (el !== slide && !isBlock(el)) el = el.parentElement; return el; };
78
+ const visible = (el) => {
79
+ for (let e = el; e && e !== slide; e = e.parentElement) {
80
+ const s = getComputedStyle(e);
81
+ if (s.display === 'none' || s.visibility === 'hidden' || +s.opacity < 0.05) return false;
82
+ }
83
+ return !el.closest('.slide-toc, .deck-progress, aside, .notes, script, style, svg, .mermaid');
84
+ };
85
+ // A gradient clipped to text, as a function of a point on the page: the first linear gradient's angle and stops.
86
+ const gradientOf = (el, block) => {
87
+ for (let e = el; e && e !== block.parentElement; e = e.parentElement) {
88
+ const s = getComputedStyle(e);
89
+ if ((s.webkitBackgroundClip || s.backgroundClip) !== 'text') continue;
90
+ const COLOR = '(?:rgba?|hsla?|oklch|oklab|lab|lch|color)\\\\([^()]*(?:\\\\([^()]*\\\\)[^()]*)*\\\\)';
91
+ const m = s.backgroundImage.match(/linear-gradient\\((.*)\\)/);
92
+ if (!m) return undefined;
93
+ const head = m[1].match(/^\\s*(-?[\\d.]+)deg|^\\s*to ([a-z ]+)/);
94
+ const sides = { top: 0, right: 90, bottom: 180, left: 270, 'top right': 45, 'right top': 45, 'bottom right': 135, 'right bottom': 135, 'bottom left': 225, 'left bottom': 225, 'top left': 315, 'left top': 315 };
95
+ const angle = head ? (head[1] !== undefined ? +head[1] : sides[head[2].trim()] ?? 180) : 180;
96
+ const stops = [...m[1].matchAll(new RegExp('(' + COLOR + ')\\\\s*(-?[\\\\d.]+%)?', 'g'))].map((x) => ({ c: rgb(x[1], bg), at: x[2] ? parseFloat(x[2]) / 100 : undefined }));
97
+ if (!stops.length) return undefined;
98
+ // Stops without a position spread evenly between their neighbors, as CSS does.
99
+ stops[0].at ??= 0;
100
+ stops[stops.length - 1].at ??= 1;
101
+ for (let k = 1; k < stops.length - 1; k++) {
102
+ if (stops[k].at !== undefined) continue;
103
+ let n = k; while (stops[n].at === undefined) n++;
104
+ for (let j = k; j < n; j++) stops[j].at = stops[k - 1].at + ((stops[n].at - stops[k - 1].at) * (j - k + 1)) / (n - k + 1);
105
+ }
106
+ const box = e.getBoundingClientRect();
107
+ const rad = (angle * Math.PI) / 180;
108
+ const sin = Math.sin(rad), cos = Math.cos(rad);
109
+ const length = Math.abs(box.width * sin) + Math.abs(box.height * cos);
110
+ return (x, y) => {
111
+ const t = ((x - (box.left + box.width / 2)) * sin - (y - (box.top + box.height / 2)) * cos) / length + 0.5;
112
+ if (t <= stops[0].at) return stops[0].c;
113
+ for (let k = 1; k < stops.length; k++) {
114
+ if (t > stops[k].at) continue;
115
+ const a = stops[k - 1], b = stops[k];
116
+ const f = b.at > a.at ? (t - a.at) / (b.at - a.at) : 1;
117
+ return { red: a.c.red + (b.c.red - a.c.red) * f, green: a.c.green + (b.c.green - a.c.green) * f, blue: a.c.blue + (b.c.blue - a.c.blue) * f };
118
+ }
119
+ return stops[stops.length - 1].c;
120
+ };
121
+ }
122
+ };
123
+ // What's behind an element's text: the nearest background color (blended down to the slide's), and how much of
124
+ // its own color shows through ancestors' opacity.
125
+ // A background photo (and its dim) under the slide's content, drawn as the page shows it (cover, centered), to
126
+ // sample what's behind translucent text and chips; null where the picture can't be read back.
127
+ const photoEl = slide.querySelector('.slide-bg');
128
+ const photo = await (async () => {
129
+ const m = photoEl && getComputedStyle(photoEl).backgroundImage.match(/url\\(["']?(.*?)["']?\\)/);
130
+ if (!m) return undefined;
131
+ try {
132
+ const img = new Image();
133
+ img.src = m[1];
134
+ await img.decode();
135
+ const box = photoEl.getBoundingClientRect();
136
+ const canvas = document.createElement('canvas');
137
+ canvas.width = Math.max(1, Math.round(box.width));
138
+ canvas.height = Math.max(1, Math.round(box.height));
139
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
140
+ const iw = img.naturalWidth || box.width, ih = img.naturalHeight || box.height;
141
+ const k = Math.max(box.width / iw, box.height / ih);
142
+ ctx.drawImage(img, (box.width - iw * k) / 2, (box.height - ih * k) / 2, iw * k, ih * k);
143
+ const dim = slide.querySelector('.slide-dim');
144
+ if (dim) {
145
+ const ds = getComputedStyle(dim);
146
+ ctx.globalAlpha = +ds.opacity;
147
+ ctx.fillStyle = ds.backgroundColor;
148
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
149
+ ctx.globalAlpha = 1;
150
+ }
151
+ ctx.getImageData(0, 0, 1, 1);
152
+ return { ctx, box };
153
+ } catch {
154
+ return null;
155
+ }
156
+ })();
157
+ // The photo's average color behind an element; unreadable, a dark or light guess from the element's text color.
158
+ const behind = (el) => {
159
+ if (photo === undefined) return undefined;
160
+ if (photo === null) {
161
+ const t = rgb(getComputedStyle(el).color);
162
+ return 0.2126 * t.red + 0.7152 * t.green + 0.0722 * t.blue > 0.5 ? 'rgb(24,24,28)' : 'rgb(240,240,240)';
163
+ }
164
+ const r = el.getBoundingClientRect();
165
+ const x = Math.max(0, Math.floor(r.left - photo.box.left)), y = Math.max(0, Math.floor(r.top - photo.box.top));
166
+ const w = Math.max(1, Math.min(Math.ceil(r.width), photo.ctx.canvas.width - x)), h = Math.max(1, Math.min(Math.ceil(r.height), photo.ctx.canvas.height - y));
167
+ const d = photo.ctx.getImageData(x, y, w, h).data;
168
+ const sum = [0, 0, 0];
169
+ for (let p = 0; p < d.length; p += 4) { sum[0] += d[p]; sum[1] += d[p + 1]; sum[2] += d[p + 2]; }
170
+ const n = d.length / 4;
171
+ return 'rgb(' + sum.map((v) => Math.round(v / n)).join(',') + ')';
172
+ };
173
+ // The background colors between an element and the slide, nearest first, and whether one of them is opaque.
174
+ const chain = (el) => {
175
+ const layers = [];
176
+ // Over a photo, only what's between the element and the photo counts (the slide's own color is under it).
177
+ const stop = photo !== undefined ? photoEl.parentElement : slide.parentElement;
178
+ for (let e = el; e && e !== stop; e = e.parentElement) {
179
+ const c = getComputedStyle(e).backgroundColor;
180
+ if (c && !/rgba\\(.*,\\s*0\\)$/.test(c) && c !== 'transparent') { layers.push(c); if (!/rgba/.test(c)) return { layers, opaque: true }; }
181
+ }
182
+ return { layers, opaque: false };
183
+ };
184
+ const seeThrough = (css) => { const a = rgb(css, '#000'), b = rgb(css, '#fff'); return a.red !== b.red || a.green !== b.green || a.blue !== b.blue; };
185
+ // A color seen through to the theme's own background (a gradient, a glow, ornaments), which CSS can't say: worked
186
+ // out again over the slide's background picture once it's taken (SAMPLE), from what's recorded here.
187
+ const redo = (el, color, alpha, box) => {
188
+ if (photo !== undefined) return undefined;
189
+ const { layers, opaque } = chain(el);
190
+ if (opaque || (alpha >= 1 && !layers.length && !seeThrough(color))) return undefined;
191
+ const r = box.getBoundingClientRect();
192
+ return { layers, color, opacity: alpha, rect: { x: r.left - origin.left, y: r.top - origin.top, w: r.width, h: r.height } };
193
+ };
194
+ const backdrop = (el) => {
195
+ const { layers } = chain(el);
196
+ let under = (!layers.length || /rgba/.test(layers[layers.length - 1]) ? behind(el) : undefined) ?? bg;
197
+ for (const c of layers.reverse()) { const v = rgb(c, under); under = 'rgb(' + [v.red, v.green, v.blue].map((x) => Math.round(x * 255)).join(',') + ')'; }
198
+ return under;
199
+ };
200
+ const opacity = (el) => { let o = 1; for (let e = el; e && e !== slide; e = e.parentElement) o *= +getComputedStyle(e).opacity; return o; };
201
+ const seen = (color, el) => {
202
+ const under = backdrop(el);
203
+ const c = rgb(color, under);
204
+ const o = opacity(el);
205
+ if (o >= 1) return c;
206
+ const b = rgb(under);
207
+ return { red: c.red * o + b.red * (1 - o), green: c.green * o + b.green * (1 - o), blue: c.blue * o + b.blue * (1 - o) };
208
+ };
209
+ const groups = new Map();
210
+ const walker = document.createTreeWalker(slide, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);
211
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
212
+ const isBr = n.nodeType === 1 && n.tagName === 'BR';
213
+ if (n.nodeType === 1 && !isBr) continue;
214
+ if (!isBr && !n.data.trim() && !/^pre/.test(getComputedStyle(n.parentElement).whiteSpace)) {
215
+ // Spaces between inline elements still separate words.
216
+ if (n.data && groups.has(blockOf(n))) groups.get(blockOf(n)).push({ node: n, space: true });
217
+ continue;
218
+ }
219
+ const el = isBr ? n : n.parentElement;
220
+ if (!visible(el)) continue;
221
+ const block = blockOf(n);
222
+ if (!groups.has(block)) groups.set(block, []);
223
+ groups.get(block).push({ node: n, br: isBr });
224
+ }
225
+ const paras = [];
226
+ const inlineBgs = new Set();
227
+ const runsOf = (block, items) => {
228
+ const bs = getComputedStyle(block);
229
+ const pre = /^pre/.test(bs.whiteSpace);
230
+ const runs = [];
231
+ for (const t of items) {
232
+ if (t.br) { runs.push({ text: '\\u000b' }); continue; }
233
+ const el = t.node.parentElement;
234
+ const s = getComputedStyle(el);
235
+ let text = t.node.data;
236
+ text = pre ? text.replace(/\\n/g, '\\u000b') : text.replace(/\\s+/g, ' ');
237
+ if (s.textTransform === 'uppercase') text = text.toUpperCase();
238
+ else if (s.textTransform === 'lowercase') text = text.toLowerCase();
239
+ const fill = s.webkitTextFillColor;
240
+ const transparent = !fill || fill === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(fill);
241
+ const gradient = transparent && gradientOf(el, block);
242
+ const color = gradient ? undefined : seen(transparent ? s.color : fill, el);
243
+ const again = {};
244
+ if (!gradient) again.color = redo(el, transparent ? s.color : fill, opacity(el), el);
245
+ // An inline element with a background (code span, highlight): its color goes on the run, so it follows the text
246
+ // when Slides wraps it differently; the picture loses it.
247
+ let highlight, chip;
248
+ for (let e = el; e && e !== block; e = e.parentElement) {
249
+ const es = getComputedStyle(e);
250
+ if (!es.display.startsWith('inline')) continue;
251
+ const c = es.backgroundColor;
252
+ if (!c || c === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(c)) continue;
253
+ highlight = rgb(c, backdrop(e.parentElement));
254
+ again.highlight = redo(e.parentElement, c, 1, e);
255
+ inlineBgs.add(e);
256
+ chip = e;
257
+ break;
258
+ }
259
+ const deco = (tag) => !!el.closest(tag);
260
+ const a = el.closest('a[href]');
261
+ const look = {
262
+ size: parseFloat(s.fontSize), letterSpacing: s.letterSpacing, weight: +s.fontWeight || 400, italic: s.fontStyle !== 'normal', family: s.fontFamily,
263
+ underline: s.textDecorationLine.includes('underline') || (deco('u, ins') && !a), strike: deco('s, del, strike'),
264
+ link: a && /^(https?:|mailto:)/.test(a.getAttribute('href')) ? a.getAttribute('href') : undefined,
265
+ highlight,
266
+ ligatures: !(s.fontVariantLigatures === 'none' || /["']calt["'] 0|["']liga["'] 0/.test(s.fontFeatureSettings)),
267
+ };
268
+ if (!gradient) { runs.push({ text, color, ...look, ...(again.color || again.highlight ? { redo: again } : {}), chip }); continue; }
269
+ // Gradient text: each character in the gradient's color where it sits (Slides fills text with one color).
270
+ const range = document.createRange();
271
+ const data = t.node.data;
272
+ let k = 0;
273
+ for (const ch of text) {
274
+ // The character's place in the node (spaces collapsed and case changed in \`text\`, so find it by count).
275
+ while (k < data.length && /\\s/.test(data[k]) && ch !== ' ') k++;
276
+ range.setStart(t.node, Math.min(k, data.length));
277
+ range.setEnd(t.node, Math.min(k + ch.length, data.length));
278
+ const q = range.getBoundingClientRect();
279
+ runs.push({ text: ch, color: gradient(q.left + q.width / 2, q.top + q.height / 2), ...look });
280
+ k += ch.length;
281
+ if (ch === ' ') while (k < data.length && /\\s/.test(data[k])) k++;
282
+ }
283
+ }
284
+ // A line break takes the look of the text before it (else after), so it joins that run.
285
+ runs.forEach((r, k) => {
286
+ if (r.family) return;
287
+ const near = runs.slice(0, k).reverse().find((o) => o.family) || runs.slice(k + 1).find((o) => o.family);
288
+ if (near) runs[k] = { ...near, text: r.text };
289
+ });
290
+ // Spaces that start a line after a break don't show on the page.
291
+ if (!pre) runs.forEach((r, k) => { if (k && runs[k - 1].text.endsWith('\\u000b')) r.text = r.text.replace(/^ +/, ''); });
292
+ // A chip's padding (a code span's, a key's): Slides draws a highlight tight around its text, so a space in Inter at
293
+ // each end (U+2004, a third of its size wide; a monospace font's would be a whole cell) sized to the padding, in
294
+ // the chip's color. It keeps the chip's look and its line's width, where the page wraps.
295
+ const padded = [];
296
+ const chips = runs.map((r) => r.chip);
297
+ runs.forEach((r, k) => {
298
+ const chip = chips[k];
299
+ delete r.chip;
300
+ if (!chip) { padded.push(r); return; }
301
+ const cs = getComputedStyle(chip);
302
+ const pad = (side) => {
303
+ const px = parseFloat(cs['padding' + side]) + parseFloat(cs['border' + side + 'Width']);
304
+ return px > 0.5 ? { ...r, text: '\\u2004', family: 'Inter, sans-serif', size: Math.min(r.size, px * 3), ligatures: true, pad: true } : undefined;
305
+ };
306
+ const before = chips[k - 1] !== chip, after = chips[k + 1] !== chip;
307
+ const left = before && pad('Left'), right = after && pad('Right');
308
+ if (left) padded.push(left);
309
+ padded.push(r);
310
+ if (right) padded.push(right);
311
+ });
312
+ runs.splice(0, runs.length, ...padded);
313
+ // Trim the block's leading and trailing spaces; drop runs left empty. A code line keeps its indent; padding stays.
314
+ while (!pre && runs.length && !runs[0].pad && !runs[0].text.trim()) runs.shift();
315
+ while (runs.length && !runs[runs.length - 1].pad && !runs[runs.length - 1].text.trim()) runs.pop();
316
+ if (runs.length) {
317
+ if (!pre) runs[0].text = runs[0].text.replace(/^ +/, '');
318
+ runs[runs.length - 1].text = runs[runs.length - 1].text.replace(/ +$/, '');
319
+ }
320
+ return runs;
321
+ };
322
+ // How much narrower the text must be set in Slides to take the page's width: Slides lacks letter-spacing, and draws
323
+ // a system font in Inter and a ligature code font in Roboto Mono (both loaded for this), which run wider.
324
+ const SYSTEM = /^"?(${SYSTEM_FONTS})/i;
325
+ const LIGATURE = /^"?(${LIGATURE_FONTS})/i;
326
+ const CJK = /[\\u3040-\\u30ff\\u3400-\\u9fff\\uf900-\\ufaff\\uff66-\\uff9f]/;
327
+ const widthScale = (runs) => {
328
+ const probe = document.createElement('div');
329
+ probe.style.cssText = 'position:absolute;left:0;top:0;white-space:pre;visibility:hidden';
330
+ const spans = runs.filter((r) => r.text && r.text !== '\\u000b').map((r) => {
331
+ const span = document.createElement('span');
332
+ span.textContent = r.text;
333
+ span.style.cssText = 'font-family:' + r.family + ';font-size:' + r.size + 'px;font-weight:' + r.weight + ';font-style:' + (r.italic ? 'italic' : 'normal') +
334
+ ';letter-spacing:' + (r.letterSpacing || 'normal') + ';font-variant-ligatures:' + (r.ligatures ? 'normal' : 'none');
335
+ probe.appendChild(span);
336
+ return { span, r };
337
+ });
338
+ document.body.appendChild(probe);
339
+ const page = probe.getBoundingClientRect().width;
340
+ for (const { span, r } of spans) {
341
+ const first = r.family.split(',')[0].trim();
342
+ // Text with Japanese or Chinese characters: in the CJK font Slides gets (see cjkFont in slideslayout.ts).
343
+ if (CJK.test(r.text)) span.style.fontFamily = /Mincho|Serif|Ming|serif$/i.test(r.family) ? '"Noto Serif JP"' : '"Noto Sans JP"';
344
+ else if (SYSTEM.test(first)) span.style.fontFamily = 'Inter';
345
+ else if (!r.ligatures && LIGATURE.test(first)) span.style.fontFamily = '"Roboto Mono"';
346
+ span.style.letterSpacing = 'normal';
347
+ span.style.fontVariantLigatures = 'normal';
348
+ }
349
+ const slides = probe.getBoundingClientRect().width;
350
+ probe.remove();
351
+ return slides > 0 && page > 0 ? Math.min(1.05, Math.max(0.8, page / slides)) : 1;
352
+ };
353
+ // Where a block's text box goes: blocks of one region, stacked, share a text box (a column, card, header, footer,
354
+ // code block); table cells go in a native table.
355
+ const REGION = 'pre, .eyebrow, .slide-footer, .slide-header, .col, .slide-content, .slide-body';
356
+ for (const [block, items] of groups) {
357
+ const texts = items.filter((t) => !t.br && !t.space);
358
+ if (!texts.length) continue;
359
+ const runs = runsOf(block, items);
360
+ if (!runs.length) continue;
361
+ const scale = widthScale(runs);
362
+ const bs = getComputedStyle(block);
363
+ // The block's own text, as laid out: its lines' extent; the block's content box for where lines wrap.
364
+ const range = document.createRange();
365
+ range.setStartBefore(texts[0].node);
366
+ range.setEndAfter(texts[texts.length - 1].node);
367
+ const r = range.getBoundingClientRect();
368
+ const first = [...range.getClientRects()].find((q) => q.height > 0);
369
+ const br = block.getBoundingClientRect();
370
+ const left = br.left + parseFloat(bs.paddingLeft) + parseFloat(bs.borderLeftWidth);
371
+ const right = br.right - parseFloat(bs.paddingRight) - parseFloat(bs.borderRightWidth);
372
+ const align = { center: 'CENTER', right: 'END', end: 'END', justify: 'JUSTIFIED' }[bs.textAlign] || 'START';
373
+ // Left-aligned text starts where its first character is (a badge may center it by flex, not by text-align).
374
+ const x = align === 'START' ? r.left : Math.min(left, r.left);
375
+ const size = parseFloat(bs.fontSize);
376
+ const lineHeight = bs.lineHeight === 'normal' ? size * 1.2 : parseFloat(bs.lineHeight);
377
+ const lineContent = first ? first.height : r.height;
378
+ const cell = block.closest('td, th');
379
+ const region = cell || block.closest(REGION) || slide;
380
+ // A block in a container that draws itself (a quote's rule, a note's panel) gets its own text box, placed on it.
381
+ let boxed = null;
382
+ for (let e = block; e && e !== region; e = e.parentElement) {
383
+ const es = getComputedStyle(e);
384
+ const painted = !/rgba\\(.*,\\s*0\\)$|transparent/.test(es.backgroundColor) || es.backgroundImage !== 'none' || parseFloat(es.borderLeftWidth) > 0 || parseFloat(es.borderTopWidth) > 0;
385
+ if (e.tagName === 'BLOCKQUOTE' || (painted && e !== block && e.tagName !== 'LI' && e.tagName !== 'UL' && e.tagName !== 'OL')) { boxed = e; break; }
386
+ }
387
+ let list;
388
+ if (block.tagName === 'LI' && !cell) {
389
+ let level = 0;
390
+ for (let e = block.parentElement; e && e !== region; e = e.parentElement) if (e.tagName === 'LI') level++;
391
+ // The theme's marker: a drawn ::before (a dot, a diamond: its color, size, and where it sits), else the ::marker.
392
+ const before = getComputedStyle(block, '::before');
393
+ const drawn = before.content !== 'none' && before.position === 'absolute' && (parseFloat(before.width) > 0 || /^["'].+["']$/.test(before.content));
394
+ const lb = block.getBoundingClientRect();
395
+ let marker;
396
+ const glyph = drawn && /^["'].+["']$/.test(before.content);
397
+ if (glyph) {
398
+ // A text marker (—, ·): its own color and font size.
399
+ const gx = lb.left + parseFloat(before.left) - origin.left;
400
+ marker = { color: seen(before.color, block), size: parseFloat(before.fontSize), family: before.fontFamily, weight: +before.fontWeight || 400, x: gx, width: parseFloat(before.width) || parseFloat(before.fontSize) * 0.6 };
401
+ } else if (drawn) {
402
+ // A shape: its fill (a gradient's middle, or a color), else its border or inset shadow (a hollow marker).
403
+ const rotated = /matrix\\(0\\.7/.test(before.transform);
404
+ const clear = (c) => !c || c === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(c);
405
+ const stops = before.backgroundImage.match(/(rgba?|hsla?|oklch|oklab|lab|lch|color)\\([^()]*(\\([^()]*\\)[^()]*)*\\)/g) || [];
406
+ const shadow = before.boxShadow.match(/(rgba?|hsla?|oklch|oklab|lab|lch|color)\\([^()]*\\)/);
407
+ const color = stops.length ? stops[Math.floor(stops.length / 2)]
408
+ : !clear(before.backgroundColor) ? before.backgroundColor
409
+ : parseFloat(before.borderTopWidth) > 0 ? before.borderTopColor
410
+ : shadow ? shadow[0] : before.color;
411
+ const side = Math.max(parseFloat(before.width), parseFloat(before.height));
412
+ marker = {
413
+ color: seen(color, block), height: side * (rotated ? 1.41 : 1), width: side * (rotated ? 1.41 : 1),
414
+ x: lb.left + parseFloat(getComputedStyle(block).borderLeftWidth) + parseFloat(before.left) - origin.left,
415
+ };
416
+ } else {
417
+ const m = getComputedStyle(block, '::marker');
418
+ const size = parseFloat(m.fontSize);
419
+ // An outside ::marker ends a little before the item's text: about its width ("1.") and a space.
420
+ const label = (block.parentElement.tagName === 'OL' ? String([...block.parentElement.children].indexOf(block) + 1) + '.' : '•').length;
421
+ marker = { color: seen(m.color, block), size, family: m.fontFamily, weight: +m.fontWeight || 400, x: lb.left - size * (0.62 * label + 0.5) - origin.left, width: size * 0.62 * label };
422
+ }
423
+ list = { ordered: block.parentElement.tagName === 'OL', level, diamond: drawn && /matrix\\(0\\.7/.test(before.transform), marker };
424
+ block.classList.add('deck-slides-li');
425
+ }
426
+ paras.push({
427
+ region, boxed, cell, list, title: !!titleEl && (block === titleEl || titleEl.contains(block)), align, lineHeight, lineContent, runs, scale,
428
+ x: x - origin.left, right: Math.max(right, r.right) - origin.left, glyphTop: r.top - origin.top, h: r.height,
429
+ });
430
+ // Take the text out of the picture: invisible glyphs, no shadows, no decorations, no gradient behind the text.
431
+ for (const t of texts) {
432
+ const span = document.createElement('span');
433
+ span.className = 'deck-slides-hidden';
434
+ t.node.replaceWith(span);
435
+ span.appendChild(t.node);
436
+ for (let e = span.parentElement; e && e !== block.parentElement; e = e.parentElement) {
437
+ const s = getComputedStyle(e);
438
+ if ((s.webkitBackgroundClip || s.backgroundClip) === 'text') e.style.setProperty('background-image', 'none', 'important');
439
+ e.style.setProperty('text-decoration-color', 'transparent', 'important');
440
+ e.style.setProperty('text-shadow', 'none', 'important');
441
+ }
442
+ }
443
+ }
444
+ // Text boxes: a region's blocks in order, a new box wherever a block isn't below the last one (side by side).
445
+ const frames = [];
446
+ let frame;
447
+ for (const p of paras.filter((p) => !p.cell)) {
448
+ const lines = Math.max(1, Math.round((p.h - p.lineContent) / p.lineHeight) + 1);
449
+ const top = p.glyphTop - (p.lineHeight - p.lineContent) / 2;
450
+ const para = { x: p.x, right: p.right, top, glyphTop: p.glyphTop, lines, lineHeight: p.lineHeight, lineContent: p.lineContent, align: p.align, runs: p.runs, list: p.list, scale: p.scale };
451
+ const last = frame && frame.paragraphs[frame.paragraphs.length - 1];
452
+ const below = last && frame.region === p.region && frame.boxed === p.boxed && !!frame.title === p.title && top >= last.top + last.lines * last.lineHeight - 2 && p.x < frame.right && p.right > frame.x;
453
+ if (below) {
454
+ frame.paragraphs.push(para);
455
+ frame.x = Math.min(frame.x, p.x);
456
+ frame.right = Math.max(frame.right, p.right);
457
+ } else {
458
+ frame = { region: p.region, boxed: p.boxed, title: p.title, x: p.x, right: p.right, paragraphs: [para] };
459
+ frames.push(frame);
460
+ }
461
+ }
462
+ // Tables, cell by cell: sizes, fills, the rule between rows, and each cell's text.
463
+ const fillOf = (el) => {
464
+ for (let e = el; e && e.tagName !== 'TABLE'; e = e.parentElement) {
465
+ const s = getComputedStyle(e);
466
+ const stops = (s.backgroundImage.match(/(rgba?|hsla?|oklch|oklab|lab|lch|color)\\([^()]*(\\([^()]*\\)[^()]*)*\\)/g) || []).map((c) => rgb(c, backdrop(e.parentElement)));
467
+ if (stops.length) {
468
+ const avg = (k) => stops.reduce((a, c) => a + c[k], 0) / stops.length;
469
+ return { red: avg('red'), green: avg('green'), blue: avg('blue') };
470
+ }
471
+ const c = s.backgroundColor;
472
+ if (c && c !== 'transparent' && !/rgba\\(.*,\\s*0\\)$/.test(c)) return rgb(c, backdrop(e.parentElement));
473
+ }
474
+ };
475
+ const tables = [];
476
+ for (const table of slide.querySelectorAll('table')) {
477
+ if (!visible(table)) continue;
478
+ const tr = table.getBoundingClientRect();
479
+ const rows = [...table.rows].filter((row) => row.cells.length);
480
+ if (!rows.length) continue;
481
+ const columns = Math.max(...rows.map((row) => row.cells.length));
482
+ const widths = [...rows.find((row) => row.cells.length === columns).cells].map((c) => c.getBoundingClientRect().width);
483
+ const body = rows.find((row) => row.cells[0]?.tagName === 'TD')?.cells[0];
484
+ const bs = body && getComputedStyle(body);
485
+ const rule = bs && parseFloat(bs.borderBottomWidth) > 0 ? { color: rgb(bs.borderBottomColor, backdrop(body)), width: parseFloat(bs.borderBottomWidth) } : undefined;
486
+ tables.push({
487
+ x: tr.left - origin.left, y: tr.top - origin.top, w: tr.width, h: tr.height, widths, rule,
488
+ rows: rows.map((row) => ({
489
+ height: row.getBoundingClientRect().height,
490
+ cells: [...row.cells].map((c) => {
491
+ const cs = getComputedStyle(c);
492
+ const own = paras.filter((p) => p.cell === c);
493
+ return {
494
+ runs: own.flatMap((p, k) => (k ? [{ ...p.runs[0], text: '\\n' }, ...p.runs] : p.runs)),
495
+ align: own[0]?.align || 'START',
496
+ lineHeight: own[0]?.lineHeight,
497
+ scale: own.length ? Math.min(...own.map((p) => p.scale)) : 1,
498
+ fill: fillOf(c),
499
+ valign: { top: 'TOP', bottom: 'BOTTOM' }[cs.verticalAlign] || 'MIDDLE',
500
+ };
501
+ }),
502
+ })),
503
+ });
504
+ // The native table draws its fills and rules: off the picture.
505
+ for (const e of table.querySelectorAll('thead, tbody, tr, th, td')) {
506
+ for (const [k, v] of [['background', 'none'], ['border-color', 'transparent'], ['box-shadow', 'none']]) e.style.setProperty(k, v, 'important');
507
+ }
508
+ }
509
+ for (const e of inlineBgs) {
510
+ for (const [k, v] of [['background', 'none'], ['border-color', 'transparent'], ['box-shadow', 'none'], ['outline-color', 'transparent']]) e.style.setProperty(k, v, 'important');
511
+ }
512
+ if (!document.getElementById('deck-slides-style')) {
513
+ const style = document.createElement('style');
514
+ style.id = 'deck-slides-style';
515
+ style.textContent = '.deck-slides-hidden { color: transparent !important; -webkit-text-fill-color: transparent !important; text-shadow: none !important; }' +
516
+ ' .deck-slides-li::before { visibility: hidden !important; } .deck-slides-li::marker { color: transparent !important; }';
517
+ document.head.appendChild(style);
518
+ }
519
+ const role = (f) => (f.title ? 'title' : f.region.matches?.('.slide-footer') ? 'footer' : undefined);
520
+ const cols = [...slide.querySelectorAll('.col')].filter((e) => !e.parentElement.closest('.col'));
521
+ const bodies = (cols.length ? cols : [...slide.querySelectorAll('.slide-content')].slice(0, 1))
522
+ .map((e) => { const b = e.getBoundingClientRect(); return { x: b.left - origin.left, y: b.top - origin.top, w: b.width, h: b.height }; })
523
+ .filter((b) => b.w > 1 && b.h > 1);
524
+ const result = { frames: frames.map(({ region, boxed, title, ...f }) => ({ ...f, role: role({ region, title }), w: f.right - f.x })), tables, bodies };
525
+ return new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve(result))));
526
+ })()`;
527
+ /**
528
+ * After MEASURE: where slide i's content (not the theme's chrome) paints anything but its now hidden text — a panel,
529
+ * border, shadow, image, diagram — as rectangles that don't overlap, in px. `hide` then takes them off the page.
530
+ */
531
+ const VISUALS = (i) => `(() => {
532
+ const slide = document.querySelectorAll('.deck-stage > .slide')[${i}];
533
+ const root = slide.querySelector('.slide-body');
534
+ if (!root) return [];
535
+ const origin = slide.getBoundingClientRect();
536
+ const clear = (c) => !c || c === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(c);
537
+ const paints = (s) =>
538
+ !clear(s.backgroundColor) || s.backgroundImage !== 'none' || s.boxShadow !== 'none' ||
539
+ ['Top', 'Right', 'Bottom', 'Left'].some((k) => parseFloat(s['border' + k + 'Width']) > 0 && !clear(s['border' + k + 'Color']) && s['border' + k + 'Style'] !== 'none') ||
540
+ (s.outlineStyle !== 'none' && parseFloat(s.outlineWidth) > 0 && !clear(s.outlineColor));
541
+ // How far a box-shadow reaches past the box.
542
+ const reach = (s) => s.boxShadow === 'none' ? 0 : Math.max(0, ...s.boxShadow.split(/,(?![^()]*\\))/).map((sh) => {
543
+ const n = (sh.replace(/(rgba?|hsla?|oklch|oklab|lab|lch|color)\\([^()]*\\)/g, '').match(/-?[\\d.]+px/g) || []).map(parseFloat);
544
+ return /inset/.test(sh) ? 0 : Math.max(Math.abs(n[0] || 0), Math.abs(n[1] || 0)) + (n[2] || 0) + (n[3] || 0);
545
+ }));
546
+ const boxes = [];
547
+ const add = (r, pad, owner, pseudo) => { if (r.width > 0.5 && r.height > 0.5) boxes.push({ x: r.left - pad, y: r.top - pad, right: r.right + pad, bottom: r.bottom + pad, owner, pseudo }); };
548
+ const visible = (e) => { const s = getComputedStyle(e); return s.display !== 'none' && s.visibility !== 'hidden' && +s.opacity > 0.01; };
549
+ const walk = (el) => {
550
+ for (const e of el.children) {
551
+ if (!visible(e) || e.closest('.slide-toc, aside, .notes, script, style')) continue;
552
+ const s = getComputedStyle(e);
553
+ const r = e.getBoundingClientRect();
554
+ if (/^(IMG|SVG|CANVAS|VIDEO|IFRAME|PICTURE|OBJECT|EMBED)$/i.test(e.tagName) || e.classList.contains('mermaid')) { add(r, reach(s), e); continue; }
555
+ if (paints(s)) add(r, reach(s), e);
556
+ if (!e.classList.contains('deck-slides-li')) {
557
+ for (const which of ['::before', '::after']) {
558
+ const p = getComputedStyle(e, which);
559
+ if (p.content === 'none' || p.content === 'normal' || p.display === 'none' || p.visibility === 'hidden') continue;
560
+ if (!paints(p) && !/^["'].+["']$/.test(p.content)) continue;
561
+ if (p.position === 'absolute' || p.position === 'fixed') {
562
+ const w = parseFloat(p.width) || parseFloat(p.fontSize), h = parseFloat(p.height) || parseFloat(p.fontSize) * 1.3;
563
+ const x = p.left !== 'auto' ? r.left + parseFloat(p.left) : r.right - parseFloat(p.right) - w;
564
+ const y = p.top !== 'auto' ? r.top + parseFloat(p.top) : r.bottom - parseFloat(p.bottom) - h;
565
+ // A rotated or scaled ornament may reach a little past its box.
566
+ const pad = reach(p) + (p.transform !== 'none' ? Math.max(w, h) * 0.25 : 0);
567
+ add({ left: x, top: y, right: x + w, bottom: y + h, width: w, height: h }, pad, e, true);
568
+ } else add(r, reach(p), e, true);
569
+ }
570
+ }
571
+ walk(e);
572
+ }
573
+ };
574
+ walk(root);
575
+ // Overlapping or touching boxes merge, until none do; within the slide, on whole px.
576
+ let out = boxes.map((b) => ({ ...b, owners: [[b.owner, b.pseudo]] }));
577
+ for (let merged = true; merged;) {
578
+ merged = false;
579
+ for (let a = 0; a < out.length && !merged; a++) {
580
+ for (let b = a + 1; b < out.length; b++) {
581
+ const p = out[a], q = out[b];
582
+ if (p.x <= q.right + 2 && q.x <= p.right + 2 && p.y <= q.bottom + 2 && q.y <= p.bottom + 2) {
583
+ out[a] = { x: Math.min(p.x, q.x), y: Math.min(p.y, q.y), right: Math.max(p.right, q.right), bottom: Math.max(p.bottom, q.bottom), owners: [...p.owners, ...q.owners] };
584
+ out.splice(b, 1);
585
+ merged = true;
586
+ break;
587
+ }
588
+ }
589
+ }
590
+ }
591
+ window.__slidesHide = out.flatMap((b) => b.owners);
592
+ return out.map((b) => {
593
+ const x = Math.max(0, Math.floor(b.x - origin.left)), y = Math.max(0, Math.floor(b.y - origin.top));
594
+ const right = Math.min(origin.width, Math.ceil(b.right - origin.left)), bottom = Math.min(origin.height, Math.ceil(b.bottom - origin.top));
595
+ return { x, y, w: right - x, h: bottom - y };
596
+ }).filter((b) => b.w > 1 && b.h > 1);
597
+ })()`;
598
+ /**
599
+ * Colors seen through to the theme's own background, worked out over its picture (taken without the slide's text,
600
+ * panels, and inline backgrounds): each item's backdrop is the picture's average under it, then its layers on top.
601
+ */
602
+ const SAMPLE = (picture, items) => `(async () => {
603
+ const { rgb } = window.__slides;
604
+ const img = new Image();
605
+ img.src = ${JSON.stringify(picture)};
606
+ await img.decode();
607
+ const k = img.naturalWidth / 1280;
608
+ const canvas = document.createElement('canvas');
609
+ canvas.width = img.naturalWidth;
610
+ canvas.height = img.naturalHeight;
611
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
612
+ ctx.drawImage(img, 0, 0);
613
+ const css = (v) => 'rgb(' + [v.red, v.green, v.blue].map((x) => Math.round(x * 255)).join(',') + ')';
614
+ return ${JSON.stringify(items)}.map(({ layers, color, opacity, rect }) => {
615
+ const x = Math.max(0, Math.floor(rect.x * k)), y = Math.max(0, Math.floor(rect.y * k));
616
+ const w = Math.max(1, Math.min(Math.ceil(rect.w * k), canvas.width - x)), h = Math.max(1, Math.min(Math.ceil(rect.h * k), canvas.height - y));
617
+ const d = ctx.getImageData(x, y, w, h).data;
618
+ const sum = [0, 0, 0];
619
+ for (let p = 0; p < d.length; p += 4) { sum[0] += d[p]; sum[1] += d[p + 1]; sum[2] += d[p + 2]; }
620
+ let under = 'rgb(' + sum.map((v) => Math.round(v / (d.length / 4))).join(',') + ')';
621
+ for (const layer of [...layers].reverse()) under = css(rgb(layer, under));
622
+ const c = rgb(color, under);
623
+ if (opacity >= 1) return c;
624
+ const b = rgb(under);
625
+ return { red: c.red * opacity + b.red * (1 - opacity), green: c.green * opacity + b.green * (1 - opacity), blue: c.blue * opacity + b.blue * (1 - opacity) };
626
+ });
627
+ })()`;
628
+ /** Work out the colors MEASURE left to redo over the slide's background picture, and drop the notes. */
629
+ async function redoColors(cdp, sessionId, picture, frames, tables) {
630
+ const runs = [...frames.flatMap((f) => f.paragraphs.flatMap((p) => p.runs)), ...tables.flatMap((t) => t.rows.flatMap((r) => r.cells.flatMap((c) => c.runs)))];
631
+ const todo = [];
632
+ for (const run of runs) {
633
+ for (const key of ['color', 'highlight'])
634
+ if (run.redo?.[key])
635
+ todo.push({ run, key, item: run.redo[key] });
636
+ delete run.redo;
637
+ }
638
+ if (!todo.length)
639
+ return;
640
+ const colors = await evaluate(cdp, sessionId, SAMPLE(`data:image/jpeg;base64,${picture.toString('base64')}`, todo.map((t) => t.item)));
641
+ todo.forEach((t, i) => { t.run[t.key] = colors[i]; });
642
+ }
643
+ /** Take what VISUALS found off the page, leaving the theme's chrome. */
644
+ const HIDE = `(() => {
645
+ if (!document.getElementById('deck-slides-hide')) {
646
+ const style = document.createElement('style');
647
+ style.id = 'deck-slides-hide';
648
+ style.textContent = '.deck-slides-off { opacity: 0 !important; } .deck-slides-pseudo-off::before, .deck-slides-pseudo-off::after { visibility: hidden !important; }';
649
+ document.head.appendChild(style);
650
+ }
651
+ for (const [e, pseudo] of window.__slidesHide || []) e.classList.add(pseudo ? 'deck-slides-pseudo-off' : 'deck-slides-off');
652
+ return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))));
653
+ })()`;
654
+ /** How long reading a deck may take once it has rendered: a deck of 30 slides takes 15 s to 2.5 min. */
655
+ export const CAPTURE_TIMEOUT_MS = 5 * 60_000;
656
+ /**
657
+ * Read a built deck in headless Chrome (needs Chrome; CHROME_PATH overrides). Past `timeoutMs` it gives up, with an
658
+ * error, and closes the page rather than wait on a stalled Chrome.
659
+ */
660
+ export async function captureDeck(html, options = {}) {
661
+ const timeoutMs = options.timeoutMs ?? CAPTURE_TIMEOUT_MS;
662
+ return withDeckPage(html, async (cdp, sessionId) => {
663
+ let timer;
664
+ const deadline = new Promise((_, reject) => {
665
+ timer = setTimeout(() => reject(new DeckError(`reading the deck in Chrome took over ${Math.round(timeoutMs / 1000)} s`)), timeoutMs);
666
+ });
667
+ try {
668
+ return await Promise.race([capture(cdp, sessionId), deadline]);
669
+ }
670
+ finally {
671
+ clearTimeout(timer);
672
+ }
673
+ });
674
+ }
675
+ /**
676
+ * Freeze the page's animations at a fixed point, so a deck captures the same way every time: entrance animations at
677
+ * their end, looping ones (a floating ornament) at the same frame.
678
+ */
679
+ export const FREEZE = `(() => {
680
+ const style = document.createElement('style');
681
+ style.textContent = '*, *::before, *::after { animation-delay: -999s !important; animation-play-state: paused !important; transition: none !important; }';
682
+ document.head.appendChild(style);
683
+ return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))));
684
+ })()`;
685
+ async function capture(cdp, sessionId) {
686
+ await evaluate(cdp, sessionId, FREEZE);
687
+ // The fonts Slides draws in place of the page's, to measure how wide text runs in them (offline: none, scale 1).
688
+ await evaluate(cdp, sessionId, `(async () => {
689
+ const link = document.createElement('link');
690
+ link.rel = 'stylesheet';
691
+ link.href = 'https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,100..900;1,100..900&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&family=Noto+Sans+JP:wght@100..900&family=Noto+Serif+JP:wght@200..900&display=block';
692
+ document.head.appendChild(link);
693
+ await Promise.race([new Promise((r) => { link.onload = link.onerror = r; }), new Promise((r) => setTimeout(r, 5000))]);
694
+ await Promise.race([Promise.all(['400 16px Inter', '700 16px Inter', 'italic 400 16px Inter', '400 16px "Roboto Mono"'].map((f) => document.fonts.load(f))
695
+ // The CJK fonts load by Unicode range: the subsets the page's text needs.
696
+ .concat(['400 16px "Noto Sans JP"', '700 16px "Noto Sans JP"', '400 16px "Noto Serif JP"'].map((f) => document.fonts.load(f, document.body.innerText.slice(0, 20000))))), new Promise((r) => setTimeout(r, 5000))]);
697
+ return true;
698
+ })()`);
699
+ const style = await evaluate(cdp, sessionId, STYLE);
700
+ const count = await evaluate(cdp, sessionId, `document.querySelectorAll('.deck-stage > .slide').length`);
701
+ const slides = [];
702
+ for (let i = 0; i < count; i++) {
703
+ await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 1, mobile: false }, sessionId);
704
+ const { frames, tables, bodies } = await evaluate(cdp, sessionId, MEASURE(i));
705
+ const boxes = await evaluate(cdp, sessionId, VISUALS(i));
706
+ await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 2, mobile: false }, sessionId);
707
+ await evaluate(cdp, sessionId, 'new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))');
708
+ const shot = async (b) => {
709
+ const { data } = await cdp.send('Page.captureScreenshot', { format: 'jpeg', quality: 90, clip: { x: b.x, y: b.y, width: b.w, height: b.h, scale: 1 }, captureBeyondViewport: false }, sessionId);
710
+ return Buffer.from(data, 'base64');
711
+ };
712
+ const visuals = [];
713
+ for (const b of boxes)
714
+ visuals.push({ ...b, image: await shot(b) });
715
+ await evaluate(cdp, sessionId, HIDE);
716
+ const background = await shot({ x: 0, y: 0, w: 1280, h: 720 });
717
+ await redoColors(cdp, sessionId, background, frames, tables);
718
+ slides.push({ background, visuals, frames, tables, bodies });
719
+ }
720
+ return { style, slides };
721
+ }
722
+ //# sourceMappingURL=deckstyle.js.map