@treasure-ai/treasure-deck 2026.11.1 → 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.
- package/dist/build.js +3 -1
- package/dist/build.js.map +1 -1
- package/dist/cli.js +16 -23
- package/dist/cli.js.map +1 -1
- package/dist/deckstyle.d.ts +16 -2
- package/dist/deckstyle.js +230 -44
- package/dist/deckstyle.js.map +1 -1
- package/dist/dev.d.ts +6 -0
- package/dist/dev.js +27 -1
- package/dist/dev.js.map +1 -1
- package/dist/parse.d.ts +6 -0
- package/dist/parse.js +15 -0
- package/dist/parse.js.map +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/render.js +7 -3
- package/dist/render.js.map +1 -1
- package/dist/slides.d.ts +8 -2
- package/dist/slides.js +8 -3
- package/dist/slides.js.map +1 -1
- package/dist/slidesexport.d.ts +32 -0
- package/dist/slidesexport.js +44 -0
- package/dist/slidesexport.js.map +1 -0
- package/dist/slideslayout.d.ts +1 -5
- package/dist/slideslayout.js +148 -37
- package/dist/slideslayout.js.map +1 -1
- package/dist/themecheck.d.ts +1 -1
- package/docs/commands.md +3 -1
- package/docs/editor.md +21 -3
- package/docs/syntax.md +4 -1
- package/docs/themes.md +1 -0
- package/package.json +1 -1
- package/runtime/base.css +12 -8
- package/runtime/edit-core.cjs +58 -0
- package/runtime/embed.js +363 -54
- package/skills/treasure-deck/SKILL.md +3 -3
- package/templates/specimen/specimen.md +2 -0
- package/themes/editorial/theme.css +1 -1
- package/themes/gold/theme.css +2 -2
- package/themes/treasure-ai/theme.css +2 -2
- package/themes/treasure-ai-2026/theme.css +4 -4
- package/themes/wvlet/theme.css +2 -2
package/dist/deckstyle.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { evaluate, withDeckPage } from './chrome.js';
|
|
2
|
+
import { DeckError } from './parse.js';
|
|
2
3
|
/** System UI fonts, which Google Slides draws in Inter: a regex alternation (also used in the page). */
|
|
3
4
|
export const SYSTEM_FONTS = '-apple-system|BlinkMacSystemFont|system-ui|SF Pro|Segoe UI|ui-sans-serif';
|
|
4
5
|
/** Code fonts that join `===`, `->`, … into one glyph, which Slides can't turn off: a regex alternation. */
|
|
@@ -47,6 +48,8 @@ const STYLE = `(() => {
|
|
|
47
48
|
muted: color('var(--deck-fg-muted, var(--deck-fg))'),
|
|
48
49
|
accent: color('var(--deck-accent)'),
|
|
49
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)'),
|
|
50
53
|
fonts: {
|
|
51
54
|
display: cs.getPropertyValue('--deck-font-display').trim(),
|
|
52
55
|
body: cs.getPropertyValue('--deck-font-body').trim(),
|
|
@@ -58,7 +61,7 @@ const STYLE = `(() => {
|
|
|
58
61
|
* Measure slide i's text, then hide it (so the picture taken next has none): each block's text as runs, positioned
|
|
59
62
|
* by the range of its own text (a list item's nested list is a block of its own).
|
|
60
63
|
*/
|
|
61
|
-
const MEASURE = (i) => `(() => {
|
|
64
|
+
const MEASURE = (i) => `(async () => {
|
|
62
65
|
${HELPERS}
|
|
63
66
|
const { rgb, resolve } = window.__slides;
|
|
64
67
|
const slides = document.querySelectorAll('.deck-stage > .slide');
|
|
@@ -119,13 +122,78 @@ const MEASURE = (i) => `(() => {
|
|
|
119
122
|
};
|
|
120
123
|
// What's behind an element's text: the nearest background color (blended down to the slide's), and how much of
|
|
121
124
|
// its own color shows through ancestors' opacity.
|
|
122
|
-
|
|
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) => {
|
|
123
175
|
const layers = [];
|
|
124
|
-
|
|
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) {
|
|
125
179
|
const c = getComputedStyle(e).backgroundColor;
|
|
126
|
-
if (c && !/rgba\\(.*,\\s*0\\)$/.test(c) && c !== 'transparent') { layers.push(c); if (!/rgba/.test(c))
|
|
180
|
+
if (c && !/rgba\\(.*,\\s*0\\)$/.test(c) && c !== 'transparent') { layers.push(c); if (!/rgba/.test(c)) return { layers, opaque: true }; }
|
|
127
181
|
}
|
|
128
|
-
|
|
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;
|
|
129
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(',') + ')'; }
|
|
130
198
|
return under;
|
|
131
199
|
};
|
|
@@ -172,16 +240,20 @@ const MEASURE = (i) => `(() => {
|
|
|
172
240
|
const transparent = !fill || fill === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(fill);
|
|
173
241
|
const gradient = transparent && gradientOf(el, block);
|
|
174
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);
|
|
175
245
|
// An inline element with a background (code span, highlight): its color goes on the run, so it follows the text
|
|
176
246
|
// when Slides wraps it differently; the picture loses it.
|
|
177
|
-
let highlight;
|
|
247
|
+
let highlight, chip;
|
|
178
248
|
for (let e = el; e && e !== block; e = e.parentElement) {
|
|
179
249
|
const es = getComputedStyle(e);
|
|
180
250
|
if (!es.display.startsWith('inline')) continue;
|
|
181
251
|
const c = es.backgroundColor;
|
|
182
252
|
if (!c || c === 'transparent' || /rgba\\(.*,\\s*0\\)$/.test(c)) continue;
|
|
183
253
|
highlight = rgb(c, backdrop(e.parentElement));
|
|
254
|
+
again.highlight = redo(e.parentElement, c, 1, e);
|
|
184
255
|
inlineBgs.add(e);
|
|
256
|
+
chip = e;
|
|
185
257
|
break;
|
|
186
258
|
}
|
|
187
259
|
const deco = (tag) => !!el.closest(tag);
|
|
@@ -193,7 +265,7 @@ const MEASURE = (i) => `(() => {
|
|
|
193
265
|
highlight,
|
|
194
266
|
ligatures: !(s.fontVariantLigatures === 'none' || /["']calt["'] 0|["']liga["'] 0/.test(s.fontFeatureSettings)),
|
|
195
267
|
};
|
|
196
|
-
if (!gradient) { runs.push({ text, color, ...look }); continue; }
|
|
268
|
+
if (!gradient) { runs.push({ text, color, ...look, ...(again.color || again.highlight ? { redo: again } : {}), chip }); continue; }
|
|
197
269
|
// Gradient text: each character in the gradient's color where it sits (Slides fills text with one color).
|
|
198
270
|
const range = document.createRange();
|
|
199
271
|
const data = t.node.data;
|
|
@@ -209,11 +281,40 @@ const MEASURE = (i) => `(() => {
|
|
|
209
281
|
if (ch === ' ') while (k < data.length && /\\s/.test(data[k])) k++;
|
|
210
282
|
}
|
|
211
283
|
}
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
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();
|
|
215
316
|
if (runs.length) {
|
|
216
|
-
runs[0].text = runs[0].text.replace(/^ +/, '');
|
|
317
|
+
if (!pre) runs[0].text = runs[0].text.replace(/^ +/, '');
|
|
217
318
|
runs[runs.length - 1].text = runs[runs.length - 1].text.replace(/ +$/, '');
|
|
218
319
|
}
|
|
219
320
|
return runs;
|
|
@@ -222,6 +323,7 @@ const MEASURE = (i) => `(() => {
|
|
|
222
323
|
// a system font in Inter and a ligature code font in Roboto Mono (both loaded for this), which run wider.
|
|
223
324
|
const SYSTEM = /^"?(${SYSTEM_FONTS})/i;
|
|
224
325
|
const LIGATURE = /^"?(${LIGATURE_FONTS})/i;
|
|
326
|
+
const CJK = /[\\u3040-\\u30ff\\u3400-\\u9fff\\uf900-\\ufaff\\uff66-\\uff9f]/;
|
|
225
327
|
const widthScale = (runs) => {
|
|
226
328
|
const probe = document.createElement('div');
|
|
227
329
|
probe.style.cssText = 'position:absolute;left:0;top:0;white-space:pre;visibility:hidden';
|
|
@@ -237,7 +339,9 @@ const MEASURE = (i) => `(() => {
|
|
|
237
339
|
const page = probe.getBoundingClientRect().width;
|
|
238
340
|
for (const { span, r } of spans) {
|
|
239
341
|
const first = r.family.split(',')[0].trim();
|
|
240
|
-
|
|
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';
|
|
241
345
|
else if (!r.ligatures && LIGATURE.test(first)) span.style.fontFamily = '"Roboto Mono"';
|
|
242
346
|
span.style.letterSpacing = 'normal';
|
|
243
347
|
span.style.fontVariantLigatures = 'normal';
|
|
@@ -413,7 +517,11 @@ const MEASURE = (i) => `(() => {
|
|
|
413
517
|
document.head.appendChild(style);
|
|
414
518
|
}
|
|
415
519
|
const role = (f) => (f.title ? 'title' : f.region.matches?.('.slide-footer') ? 'footer' : undefined);
|
|
416
|
-
const
|
|
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 };
|
|
417
525
|
return new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve(result))));
|
|
418
526
|
})()`;
|
|
419
527
|
/**
|
|
@@ -487,6 +595,51 @@ const VISUALS = (i) => `(() => {
|
|
|
487
595
|
return { x, y, w: right - x, h: bottom - y };
|
|
488
596
|
}).filter((b) => b.w > 1 && b.h > 1);
|
|
489
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
|
+
}
|
|
490
643
|
/** Take what VISUALS found off the page, leaving the theme's chrome. */
|
|
491
644
|
const HIDE = `(() => {
|
|
492
645
|
if (!document.getElementById('deck-slides-hide')) {
|
|
@@ -498,39 +651,72 @@ const HIDE = `(() => {
|
|
|
498
651
|
for (const [e, pseudo] of window.__slidesHide || []) e.classList.add(pseudo ? 'deck-slides-pseudo-off' : 'deck-slides-off');
|
|
499
652
|
return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))));
|
|
500
653
|
})()`;
|
|
501
|
-
/**
|
|
502
|
-
export
|
|
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;
|
|
503
662
|
return withDeckPage(html, async (cdp, sessionId) => {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
})()`);
|
|
514
|
-
const style = await evaluate(cdp, sessionId, STYLE);
|
|
515
|
-
const count = await evaluate(cdp, sessionId, `document.querySelectorAll('.deck-stage > .slide').length`);
|
|
516
|
-
const slides = [];
|
|
517
|
-
for (let i = 0; i < count; i++) {
|
|
518
|
-
await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 1, mobile: false }, sessionId);
|
|
519
|
-
const { frames, tables } = await evaluate(cdp, sessionId, MEASURE(i));
|
|
520
|
-
const boxes = await evaluate(cdp, sessionId, VISUALS(i));
|
|
521
|
-
await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 2, mobile: false }, sessionId);
|
|
522
|
-
await evaluate(cdp, sessionId, 'new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))');
|
|
523
|
-
const shot = async (b) => {
|
|
524
|
-
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);
|
|
525
|
-
return Buffer.from(data, 'base64');
|
|
526
|
-
};
|
|
527
|
-
const visuals = [];
|
|
528
|
-
for (const b of boxes)
|
|
529
|
-
visuals.push({ ...b, image: await shot(b) });
|
|
530
|
-
await evaluate(cdp, sessionId, HIDE);
|
|
531
|
-
slides.push({ background: await shot({ x: 0, y: 0, w: 1280, h: 720 }), visuals, frames, tables });
|
|
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);
|
|
532
672
|
}
|
|
533
|
-
return { style, slides };
|
|
534
673
|
});
|
|
535
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
|
+
}
|
|
536
722
|
//# sourceMappingURL=deckstyle.js.map
|
package/dist/deckstyle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deckstyle.js","sourceRoot":"","sources":["../src/deckstyle.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"deckstyle.js","sourceRoot":"","sources":["../src/deckstyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAmHvC,wGAAwG;AACxG,MAAM,CAAC,MAAM,YAAY,GAAG,0EAA0E,CAAC;AACvG,4GAA4G;AAC5G,MAAM,CAAC,MAAM,cAAc,GAAG,gEAAgE,CAAC;AAE/F,uGAAuG;AACvG,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Bf,CAAC;AAEF,MAAM,KAAK,GAAG;IACV,OAAO;;;;;;;;;;;;;;;;;;;;;;;KAuBN,CAAC;AAEN;;;GAGG;AACH,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC;IAC3B,OAAO;;;gEAGqD,CAAC;yBACxC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+PF,YAAY;0BACV,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAU,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/D,MAAM,UAAU,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Server } from 'node:http';
|
|
2
|
+
import { type BuildResult } from './build.js';
|
|
2
3
|
import type { Host } from './host.js';
|
|
3
4
|
export interface DevOptions {
|
|
4
5
|
/** The port to listen on. Without one, 4300, or the next free port after it when that one is taken. */
|
|
@@ -20,6 +21,11 @@ export interface DevOptions {
|
|
|
20
21
|
* `editorLauncher()`. Without it, and without a host that opens decks, All decks can't open another deck.
|
|
21
22
|
*/
|
|
22
23
|
openEditor?: (file: string) => Promise<string>;
|
|
24
|
+
/** Export a built deck to Google Slides (Export to Google Slides, POST /__slides); `exportDeckSlides` unless given. */
|
|
25
|
+
slidesExport?: (built: BuildResult) => Promise<{
|
|
26
|
+
url: string;
|
|
27
|
+
created: boolean;
|
|
28
|
+
}>;
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
25
31
|
* Starts `deck editor --no-open` on a deck, as a child of this process, and resolves with the URL it prints; a deck
|
package/dist/dev.js
CHANGED
|
@@ -14,6 +14,7 @@ import { escapeHtml, mediaType } from './render.js';
|
|
|
14
14
|
import { hasDiagrams, MERMAID_JS, withMermaid } from './diagrams.js';
|
|
15
15
|
import { applyPatch } from './patch.js';
|
|
16
16
|
import { printPdf } from './pdf.js';
|
|
17
|
+
import { exportDeckSlides } from './slidesexport.js';
|
|
17
18
|
import { ICONS, vendorFile } from './vendor.js';
|
|
18
19
|
import { createServer as createVite } from 'vite';
|
|
19
20
|
/** How long a new editor has to say where it listens before it is stopped. */
|
|
@@ -210,7 +211,7 @@ function sendFile(req, res, file) {
|
|
|
210
211
|
}
|
|
211
212
|
/** Serve a deck with live reload (`deck dev`). */
|
|
212
213
|
export function startDev(file, options) {
|
|
213
|
-
const { port = DEFAULT_PORT, theme, embed = false, open = false, openUrl = systemOpen, openEditor } = options;
|
|
214
|
+
const { port = DEFAULT_PORT, theme, embed = false, open = false, openUrl = systemOpen, openEditor, slidesExport = exportDeckSlides } = options;
|
|
214
215
|
const host = embed ? options.host ?? null : null;
|
|
215
216
|
const deckFile = path.resolve(file);
|
|
216
217
|
const deckDir = path.dirname(deckFile);
|
|
@@ -484,6 +485,27 @@ export function startDev(file, options) {
|
|
|
484
485
|
exporting = false;
|
|
485
486
|
}
|
|
486
487
|
};
|
|
488
|
+
// POST /__slides exports the deck as saved to Google Slides, as `deck slides` does: to the presentation its
|
|
489
|
+
// frontmatter names (`slides:`, replaced in place), else a new one, whose URL the editor then writes there. It opens
|
|
490
|
+
// the presentation and answers with its URL; one export at a time. Same guards as /__pdf.
|
|
491
|
+
let toSlides = false;
|
|
492
|
+
const exportToSlides = async (req, res) => {
|
|
493
|
+
if (!sameOrigin(req))
|
|
494
|
+
return json(res, 403, { ok: false, reason: 'cross-origin request' });
|
|
495
|
+
if (toSlides)
|
|
496
|
+
return json(res, 409, { ok: false, reason: 'the deck is already being exported to Google Slides' });
|
|
497
|
+
toSlides = true;
|
|
498
|
+
try {
|
|
499
|
+
// A build error, a missing sign-in, or Google's refusal answers 500 with that reason (and what to try).
|
|
500
|
+
const built = buildDeck(file, { theme });
|
|
501
|
+
const { url, created } = await slidesExport(built);
|
|
502
|
+
await openUrl(url).catch(() => { });
|
|
503
|
+
json(res, 200, { ok: true, url, created, slides: built.deck.slides.length });
|
|
504
|
+
}
|
|
505
|
+
finally {
|
|
506
|
+
toSlides = false;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
487
509
|
// POST /__media saves an image or video pasted or dropped into the editor as images/pasted-<time>.<ext> (a video
|
|
488
510
|
// in media/) next to the deck, and answers with its path relative to the deck, for the editor to write into the
|
|
489
511
|
// Markdown (as a patch, so a host applies it). The file is written here even with a host page, which shares this
|
|
@@ -612,6 +634,10 @@ export function startDev(file, options) {
|
|
|
612
634
|
exportPdf(req, res).catch((e) => json(res, 500, { ok: false, reason: e.message }));
|
|
613
635
|
return;
|
|
614
636
|
}
|
|
637
|
+
if (embed && req.url === '/__slides' && req.method === 'POST') {
|
|
638
|
+
exportToSlides(req, res).catch((e) => json(res, 500, { ok: false, reason: e.message }));
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
615
641
|
if (embed && req.url === '/__index' && req.method === 'GET')
|
|
616
642
|
return indexPage(res);
|
|
617
643
|
if (embed && req.url === '/__open-deck' && req.method === 'POST') {
|