@treasure-ai/treasure-deck 2026.11.1 → 2026.11.3
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 +64 -42
- package/dist/cli.js.map +1 -1
- package/dist/deckstyle.d.ts +16 -2
- package/dist/deckstyle.js +232 -44
- package/dist/deckstyle.js.map +1 -1
- package/dist/dev.d.ts +6 -0
- package/dist/dev.js +36 -1
- package/dist/dev.js.map +1 -1
- package/dist/host.d.ts +18 -0
- package/dist/host.js +28 -1
- package/dist/host.js.map +1 -1
- package/dist/import.d.ts +5 -1
- package/dist/import.js +9 -2
- package/dist/import.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 +38 -0
- package/dist/slidesexport.js +51 -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 +5 -2
- 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 +365 -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,42 @@ 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 no-break space in
|
|
293
|
+
// Inter at each end (a monospace font's would be a whole cell) sized to the padding, in the chip's color. It keeps
|
|
294
|
+
// the chip's look and its line's width, where the page wraps; Slides breaks a line before a chip, never inside its
|
|
295
|
+
// padding (a U+2004 there kept Slides from breaking before it, so a chip ran past its box).
|
|
296
|
+
const padded = [];
|
|
297
|
+
const chips = runs.map((r) => r.chip);
|
|
298
|
+
runs.forEach((r, k) => {
|
|
299
|
+
const chip = chips[k];
|
|
300
|
+
delete r.chip;
|
|
301
|
+
if (!chip) { padded.push(r); return; }
|
|
302
|
+
const cs = getComputedStyle(chip);
|
|
303
|
+
const pad = (side) => {
|
|
304
|
+
const px = parseFloat(cs['padding' + side]) + parseFloat(cs['border' + side + 'Width']);
|
|
305
|
+
// Two of Inter's spaces (each 0.27 of its size wide), so the padding's width fits under the chip's text size.
|
|
306
|
+
return px > 0.5 ? { ...r, text: '\\u00a0\\u00a0', family: 'Inter, sans-serif', size: Math.min(r.size, px / 0.54), ligatures: true, pad: true } : undefined;
|
|
307
|
+
};
|
|
308
|
+
const before = chips[k - 1] !== chip, after = chips[k + 1] !== chip;
|
|
309
|
+
const left = before && pad('Left'), right = after && pad('Right');
|
|
310
|
+
if (left) padded.push(left);
|
|
311
|
+
padded.push(r);
|
|
312
|
+
if (right) padded.push(right);
|
|
313
|
+
});
|
|
314
|
+
runs.splice(0, runs.length, ...padded);
|
|
315
|
+
// Trim the block's leading and trailing spaces; drop runs left empty. A code line keeps its indent; padding stays.
|
|
316
|
+
while (!pre && runs.length && !runs[0].pad && !runs[0].text.trim()) runs.shift();
|
|
317
|
+
while (runs.length && !runs[runs.length - 1].pad && !runs[runs.length - 1].text.trim()) runs.pop();
|
|
215
318
|
if (runs.length) {
|
|
216
|
-
runs[0].text = runs[0].text.replace(/^ +/, '');
|
|
319
|
+
if (!pre) runs[0].text = runs[0].text.replace(/^ +/, '');
|
|
217
320
|
runs[runs.length - 1].text = runs[runs.length - 1].text.replace(/ +$/, '');
|
|
218
321
|
}
|
|
219
322
|
return runs;
|
|
@@ -222,6 +325,7 @@ const MEASURE = (i) => `(() => {
|
|
|
222
325
|
// a system font in Inter and a ligature code font in Roboto Mono (both loaded for this), which run wider.
|
|
223
326
|
const SYSTEM = /^"?(${SYSTEM_FONTS})/i;
|
|
224
327
|
const LIGATURE = /^"?(${LIGATURE_FONTS})/i;
|
|
328
|
+
const CJK = /[\\u3040-\\u30ff\\u3400-\\u9fff\\uf900-\\ufaff\\uff66-\\uff9f]/;
|
|
225
329
|
const widthScale = (runs) => {
|
|
226
330
|
const probe = document.createElement('div');
|
|
227
331
|
probe.style.cssText = 'position:absolute;left:0;top:0;white-space:pre;visibility:hidden';
|
|
@@ -237,7 +341,9 @@ const MEASURE = (i) => `(() => {
|
|
|
237
341
|
const page = probe.getBoundingClientRect().width;
|
|
238
342
|
for (const { span, r } of spans) {
|
|
239
343
|
const first = r.family.split(',')[0].trim();
|
|
240
|
-
|
|
344
|
+
// Text with Japanese or Chinese characters: in the CJK font Slides gets (see cjkFont in slideslayout.ts).
|
|
345
|
+
if (CJK.test(r.text)) span.style.fontFamily = /Mincho|Serif|Ming|serif$/i.test(r.family) ? '"Noto Serif JP"' : '"Noto Sans JP"';
|
|
346
|
+
else if (SYSTEM.test(first)) span.style.fontFamily = 'Inter';
|
|
241
347
|
else if (!r.ligatures && LIGATURE.test(first)) span.style.fontFamily = '"Roboto Mono"';
|
|
242
348
|
span.style.letterSpacing = 'normal';
|
|
243
349
|
span.style.fontVariantLigatures = 'normal';
|
|
@@ -413,7 +519,11 @@ const MEASURE = (i) => `(() => {
|
|
|
413
519
|
document.head.appendChild(style);
|
|
414
520
|
}
|
|
415
521
|
const role = (f) => (f.title ? 'title' : f.region.matches?.('.slide-footer') ? 'footer' : undefined);
|
|
416
|
-
const
|
|
522
|
+
const cols = [...slide.querySelectorAll('.col')].filter((e) => !e.parentElement.closest('.col'));
|
|
523
|
+
const bodies = (cols.length ? cols : [...slide.querySelectorAll('.slide-content')].slice(0, 1))
|
|
524
|
+
.map((e) => { const b = e.getBoundingClientRect(); return { x: b.left - origin.left, y: b.top - origin.top, w: b.width, h: b.height }; })
|
|
525
|
+
.filter((b) => b.w > 1 && b.h > 1);
|
|
526
|
+
const result = { frames: frames.map(({ region, boxed, title, ...f }) => ({ ...f, role: role({ region, title }), w: f.right - f.x })), tables, bodies };
|
|
417
527
|
return new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve(result))));
|
|
418
528
|
})()`;
|
|
419
529
|
/**
|
|
@@ -487,6 +597,51 @@ const VISUALS = (i) => `(() => {
|
|
|
487
597
|
return { x, y, w: right - x, h: bottom - y };
|
|
488
598
|
}).filter((b) => b.w > 1 && b.h > 1);
|
|
489
599
|
})()`;
|
|
600
|
+
/**
|
|
601
|
+
* Colors seen through to the theme's own background, worked out over its picture (taken without the slide's text,
|
|
602
|
+
* panels, and inline backgrounds): each item's backdrop is the picture's average under it, then its layers on top.
|
|
603
|
+
*/
|
|
604
|
+
const SAMPLE = (picture, items) => `(async () => {
|
|
605
|
+
const { rgb } = window.__slides;
|
|
606
|
+
const img = new Image();
|
|
607
|
+
img.src = ${JSON.stringify(picture)};
|
|
608
|
+
await img.decode();
|
|
609
|
+
const k = img.naturalWidth / 1280;
|
|
610
|
+
const canvas = document.createElement('canvas');
|
|
611
|
+
canvas.width = img.naturalWidth;
|
|
612
|
+
canvas.height = img.naturalHeight;
|
|
613
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
614
|
+
ctx.drawImage(img, 0, 0);
|
|
615
|
+
const css = (v) => 'rgb(' + [v.red, v.green, v.blue].map((x) => Math.round(x * 255)).join(',') + ')';
|
|
616
|
+
return ${JSON.stringify(items)}.map(({ layers, color, opacity, rect }) => {
|
|
617
|
+
const x = Math.max(0, Math.floor(rect.x * k)), y = Math.max(0, Math.floor(rect.y * k));
|
|
618
|
+
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));
|
|
619
|
+
const d = ctx.getImageData(x, y, w, h).data;
|
|
620
|
+
const sum = [0, 0, 0];
|
|
621
|
+
for (let p = 0; p < d.length; p += 4) { sum[0] += d[p]; sum[1] += d[p + 1]; sum[2] += d[p + 2]; }
|
|
622
|
+
let under = 'rgb(' + sum.map((v) => Math.round(v / (d.length / 4))).join(',') + ')';
|
|
623
|
+
for (const layer of [...layers].reverse()) under = css(rgb(layer, under));
|
|
624
|
+
const c = rgb(color, under);
|
|
625
|
+
if (opacity >= 1) return c;
|
|
626
|
+
const b = rgb(under);
|
|
627
|
+
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) };
|
|
628
|
+
});
|
|
629
|
+
})()`;
|
|
630
|
+
/** Work out the colors MEASURE left to redo over the slide's background picture, and drop the notes. */
|
|
631
|
+
async function redoColors(cdp, sessionId, picture, frames, tables) {
|
|
632
|
+
const runs = [...frames.flatMap((f) => f.paragraphs.flatMap((p) => p.runs)), ...tables.flatMap((t) => t.rows.flatMap((r) => r.cells.flatMap((c) => c.runs)))];
|
|
633
|
+
const todo = [];
|
|
634
|
+
for (const run of runs) {
|
|
635
|
+
for (const key of ['color', 'highlight'])
|
|
636
|
+
if (run.redo?.[key])
|
|
637
|
+
todo.push({ run, key, item: run.redo[key] });
|
|
638
|
+
delete run.redo;
|
|
639
|
+
}
|
|
640
|
+
if (!todo.length)
|
|
641
|
+
return;
|
|
642
|
+
const colors = await evaluate(cdp, sessionId, SAMPLE(`data:image/jpeg;base64,${picture.toString('base64')}`, todo.map((t) => t.item)));
|
|
643
|
+
todo.forEach((t, i) => { t.run[t.key] = colors[i]; });
|
|
644
|
+
}
|
|
490
645
|
/** Take what VISUALS found off the page, leaving the theme's chrome. */
|
|
491
646
|
const HIDE = `(() => {
|
|
492
647
|
if (!document.getElementById('deck-slides-hide')) {
|
|
@@ -498,39 +653,72 @@ const HIDE = `(() => {
|
|
|
498
653
|
for (const [e, pseudo] of window.__slidesHide || []) e.classList.add(pseudo ? 'deck-slides-pseudo-off' : 'deck-slides-off');
|
|
499
654
|
return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))));
|
|
500
655
|
})()`;
|
|
501
|
-
/**
|
|
502
|
-
export
|
|
656
|
+
/** How long reading a deck may take once it has rendered: a deck of 30 slides takes 15 s to 2.5 min. */
|
|
657
|
+
export const CAPTURE_TIMEOUT_MS = 5 * 60_000;
|
|
658
|
+
/**
|
|
659
|
+
* Read a built deck in headless Chrome (needs Chrome; CHROME_PATH overrides). Past `timeoutMs` it gives up, with an
|
|
660
|
+
* error, and closes the page rather than wait on a stalled Chrome.
|
|
661
|
+
*/
|
|
662
|
+
export async function captureDeck(html, options = {}) {
|
|
663
|
+
const timeoutMs = options.timeoutMs ?? CAPTURE_TIMEOUT_MS;
|
|
503
664
|
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 });
|
|
665
|
+
let timer;
|
|
666
|
+
const deadline = new Promise((_, reject) => {
|
|
667
|
+
timer = setTimeout(() => reject(new DeckError(`reading the deck in Chrome took over ${Math.round(timeoutMs / 1000)} s`)), timeoutMs);
|
|
668
|
+
});
|
|
669
|
+
try {
|
|
670
|
+
return await Promise.race([capture(cdp, sessionId), deadline]);
|
|
671
|
+
}
|
|
672
|
+
finally {
|
|
673
|
+
clearTimeout(timer);
|
|
532
674
|
}
|
|
533
|
-
return { style, slides };
|
|
534
675
|
});
|
|
535
676
|
}
|
|
677
|
+
/**
|
|
678
|
+
* Freeze the page's animations at a fixed point, so a deck captures the same way every time: entrance animations at
|
|
679
|
+
* their end, looping ones (a floating ornament) at the same frame.
|
|
680
|
+
*/
|
|
681
|
+
export const FREEZE = `(() => {
|
|
682
|
+
const style = document.createElement('style');
|
|
683
|
+
style.textContent = '*, *::before, *::after { animation-delay: -999s !important; animation-play-state: paused !important; transition: none !important; }';
|
|
684
|
+
document.head.appendChild(style);
|
|
685
|
+
return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))));
|
|
686
|
+
})()`;
|
|
687
|
+
async function capture(cdp, sessionId) {
|
|
688
|
+
await evaluate(cdp, sessionId, FREEZE);
|
|
689
|
+
// The fonts Slides draws in place of the page's, to measure how wide text runs in them (offline: none, scale 1).
|
|
690
|
+
await evaluate(cdp, sessionId, `(async () => {
|
|
691
|
+
const link = document.createElement('link');
|
|
692
|
+
link.rel = 'stylesheet';
|
|
693
|
+
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';
|
|
694
|
+
document.head.appendChild(link);
|
|
695
|
+
await Promise.race([new Promise((r) => { link.onload = link.onerror = r; }), new Promise((r) => setTimeout(r, 5000))]);
|
|
696
|
+
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))
|
|
697
|
+
// The CJK fonts load by Unicode range: the subsets the page's text needs.
|
|
698
|
+
.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))]);
|
|
699
|
+
return true;
|
|
700
|
+
})()`);
|
|
701
|
+
const style = await evaluate(cdp, sessionId, STYLE);
|
|
702
|
+
const count = await evaluate(cdp, sessionId, `document.querySelectorAll('.deck-stage > .slide').length`);
|
|
703
|
+
const slides = [];
|
|
704
|
+
for (let i = 0; i < count; i++) {
|
|
705
|
+
await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 1, mobile: false }, sessionId);
|
|
706
|
+
const { frames, tables, bodies } = await evaluate(cdp, sessionId, MEASURE(i));
|
|
707
|
+
const boxes = await evaluate(cdp, sessionId, VISUALS(i));
|
|
708
|
+
await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 2, mobile: false }, sessionId);
|
|
709
|
+
await evaluate(cdp, sessionId, 'new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))');
|
|
710
|
+
const shot = async (b) => {
|
|
711
|
+
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);
|
|
712
|
+
return Buffer.from(data, 'base64');
|
|
713
|
+
};
|
|
714
|
+
const visuals = [];
|
|
715
|
+
for (const b of boxes)
|
|
716
|
+
visuals.push({ ...b, image: await shot(b) });
|
|
717
|
+
await evaluate(cdp, sessionId, HIDE);
|
|
718
|
+
const background = await shot({ x: 0, y: 0, w: 1280, h: 720 });
|
|
719
|
+
await redoColors(cdp, sessionId, background, frames, tables);
|
|
720
|
+
slides.push({ background, visuals, frames, tables, bodies });
|
|
721
|
+
}
|
|
722
|
+
return { style, slides };
|
|
723
|
+
}
|
|
536
724
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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OAAO,GAA6B,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpE,MAAM,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACrC,MAAM,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,36 @@ 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. A host that exports
|
|
491
|
+
// (Treasure Work, `slides` in DECK_HOST_FEATURES) does it with its own Google token, so the editor never holds one:
|
|
492
|
+
// it is asked for the deck file, and its answer passed on, with its `message` (a notice, or why it failed).
|
|
493
|
+
let toSlides = false;
|
|
494
|
+
const exportToSlides = async (req, res) => {
|
|
495
|
+
if (!sameOrigin(req))
|
|
496
|
+
return json(res, 403, { ok: false, reason: 'cross-origin request' });
|
|
497
|
+
if (toSlides)
|
|
498
|
+
return json(res, 409, { ok: false, reason: 'the deck is already being exported to Google Slides' });
|
|
499
|
+
toSlides = true;
|
|
500
|
+
try {
|
|
501
|
+
if (host?.slides) {
|
|
502
|
+
const r = await host.slides(deckFile);
|
|
503
|
+
if (!r.ok || !r.url)
|
|
504
|
+
return json(res, 200, { ok: false, reason: r.message ?? 'Treasure Work didn\u2019t export the deck' });
|
|
505
|
+
await openUrl(r.url).catch(() => { });
|
|
506
|
+
return json(res, 200, { ok: true, url: r.url, created: r.created === true, plain: r.plain === true, ...(r.message ? { message: r.message } : {}) });
|
|
507
|
+
}
|
|
508
|
+
// A build error, a missing sign-in, or Google's refusal answers 500 with that reason (and what to try).
|
|
509
|
+
const built = buildDeck(file, { theme });
|
|
510
|
+
const { url, created } = await slidesExport(built);
|
|
511
|
+
await openUrl(url).catch(() => { });
|
|
512
|
+
json(res, 200, { ok: true, url, created, slides: built.deck.slides.length });
|
|
513
|
+
}
|
|
514
|
+
finally {
|
|
515
|
+
toSlides = false;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
487
518
|
// POST /__media saves an image or video pasted or dropped into the editor as images/pasted-<time>.<ext> (a video
|
|
488
519
|
// in media/) next to the deck, and answers with its path relative to the deck, for the editor to write into the
|
|
489
520
|
// Markdown (as a patch, so a host applies it). The file is written here even with a host page, which shares this
|
|
@@ -612,6 +643,10 @@ export function startDev(file, options) {
|
|
|
612
643
|
exportPdf(req, res).catch((e) => json(res, 500, { ok: false, reason: e.message }));
|
|
613
644
|
return;
|
|
614
645
|
}
|
|
646
|
+
if (embed && req.url === '/__slides' && req.method === 'POST') {
|
|
647
|
+
exportToSlides(req, res).catch((e) => json(res, 500, { ok: false, reason: e.message }));
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
615
650
|
if (embed && req.url === '/__index' && req.method === 'GET')
|
|
616
651
|
return indexPage(res);
|
|
617
652
|
if (embed && req.url === '/__open-deck' && req.method === 'POST') {
|