@hypersocial/decks-cli 0.9.24 → 0.9.25
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/package.json +1 -1
- package/skills/hyperdecks/SKILL.md +13 -2
- package/skills/hyperdecks/terminal.md +3 -2
- package/src/check.mjs +33 -16
- package/src/checkRules.mjs +67 -6
- package/src/commands.mjs +15 -4
- package/src/embedCapture.mjs +126 -0
- package/src/embedSources.mjs +252 -0
- package/src/embedsGuide.mjs +36 -0
- package/src/files.mjs +1 -0
- package/src/guide.mjs +8 -6
- package/src/layoutRoutes.mjs +6 -1
- package/src/layouts.mjs +8 -3
- package/src/ops.mjs +76 -0
- package/src/picturesGuide.mjs +1 -0
- package/src/preview-capture.mjs +70 -1
- package/src/runtime.mjs +2 -2
- package/templates/layouts/_deck.html +61 -12
- package/templates/layouts/bento.html +2 -1
- package/templates/layouts/closer.html +4 -2
- package/templates/layouts/cover-band.html +3 -1
- package/templates/layouts/cover-frame.html +5 -1
- package/templates/layouts/cover-poster.html +2 -1
- package/templates/layouts/cover-split.html +13 -2
- package/templates/layouts/cover-type.html +1 -1
- package/templates/layouts/embed.html +93 -0
- package/templates/layouts/features.html +12 -6
- package/templates/layouts/funnel.html +4 -2
- package/templates/layouts/hero.html +2 -2
- package/templates/layouts/lanes.html +3 -3
- package/templates/layouts/number.html +1 -1
- package/templates/layouts/phone-stage.html +13 -3
- package/templates/layouts/picture-full.html +13 -3
- package/templates/layouts/portrait.html +8 -0
- package/templates/layouts/quote.html +3 -2
- package/templates/layouts/rail.html +7 -4
- package/templates/layouts/scorecard.html +3 -2
- package/templates/layouts/sentence.html +2 -2
- package/templates/layouts/split.html +14 -1
- package/templates/layouts/spotlight.html +4 -1
- package/templates/layouts/stack.html +3 -2
- package/templates/layouts/staircase.html +4 -2
- package/templates/layouts/strike.html +1 -1
- package/templates/layouts/team.html +19 -5
- package/templates/layouts/timeline.html +5 -2
- package/templates/layouts/two-by-two.html +5 -1
- package/templates/layouts/video-full.html +3 -3
- package/templates/layouts/wall.html +39 -11
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: hyperdecks
|
|
3
3
|
description: Use when asked to make, narrate, check or ship a deck ("make me a narrated deck", "turn this into a deck and send it"), or when working with Hypersocial Decks, Hyperdecks CLI, production deck analytics, recipient share links, deck activity, MCP deck tools, or real-world/customer-facing deck checks. Prefer production for real activity and analytics; use development only for local implementation/testing when explicitly requested.
|
|
4
4
|
metadata:
|
|
5
|
-
version: "0.9.
|
|
5
|
+
version: "0.9.25"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Hyperdecks
|
|
@@ -236,6 +236,12 @@ hyperdecks deck new <slug> "<title>" --narrated [--presenter-style stage|bubble|
|
|
|
236
236
|
Both write `decks/<slug>/` and register a draft you own. Prefer `--layouts`:
|
|
237
237
|
pick the layouts from the story (see **Design** below), in order; repeat one
|
|
238
238
|
for more of the same (`number,number` gives slides `number` and `number-2`).
|
|
239
|
+
Alternate sides between neighbours: the side-panel layouts (wall, split,
|
|
240
|
+
cover-split, picture-full, portrait) take `data-flip` on the section, which
|
|
241
|
+
mirrors the slide with its panel and presenter on the other side. When the same
|
|
242
|
+
layout comes twice in a row, the second comes flipped (`wall,wall` gives the
|
|
243
|
+
second `data-flip`), and check warns when two neighbouring slides of one layout
|
|
244
|
+
keep the panel on the same side.
|
|
239
245
|
|
|
240
246
|
Files, all in `decks/<slug>/`:
|
|
241
247
|
|
|
@@ -363,7 +369,8 @@ default): `xl` on a slide with empty space, `s` on a busy product slide. Phones
|
|
|
363
369
|
keep `l`/`xl` at their usual size. `closer` and `split` make room for `l` and `xl`
|
|
364
370
|
set on the slide's own `<section>` (the player tag's default is not seen by a
|
|
365
371
|
layout): the closer's line moves right of the presenter, and split gives it the
|
|
366
|
-
left of the slide with the copy and picture beside it (sized for `stage
|
|
372
|
+
left of the slide with the copy and picture beside it (sized for `stage`; the
|
|
373
|
+
right of the slide on a split with `data-flip`). On
|
|
367
374
|
other layouts a large presenter needs a slide with the corner free; `check
|
|
368
375
|
--layout` warns when it would cover the title and names what clears it (the size
|
|
369
376
|
on the slide, `stage`, or a smaller size). A slide's CSS `--hd-presenter-scale: 1.15`
|
|
@@ -571,6 +578,7 @@ read (`check` warns).
|
|
|
571
578
|
| `picture-full` | one photo, words on a panel |
|
|
572
579
|
| `wall` | 3 to 5 real photos |
|
|
573
580
|
| `portrait` | one tall picture beside the title |
|
|
581
|
+
| `embed` | a map or booking, live |
|
|
574
582
|
| `quote` | a customer in their own words, quoted exactly |
|
|
575
583
|
| `compare` | before/after, them/us, three parallel lines each |
|
|
576
584
|
| `timeline` | four milestones: history, a roadmap, a process |
|
|
@@ -936,6 +944,9 @@ with the player's `hyperdecks.ai` script tag. Messages and what to do:
|
|
|
936
944
|
| `fly is for the deck's one big moment` | keep `fly` on one slide; use drift or push on the others |
|
|
937
945
|
| ⚠ `N kinds of transition besides the default` | use one or two kinds, each for its own job |
|
|
938
946
|
| `slide <id>: its content runs …px past the slide on a 390×844 phone` | trim that slide on phones: smaller type, fewer items, or hide decoration in its `@media (max-width: 650px)` rules (an `#id` rule outranks them; restate it there) |
|
|
947
|
+
| ⚠ `slides <a> and <b> are two <layout> slides in a row with the panel on the same side` | put `data-flip` on the second one's section (or, when both have it, take it off one) so the two alternate |
|
|
948
|
+
| ⚠ `slide <id> has data-flip, but <layout> does not flip` | take `data-flip` off; only wall, split, cover-split, picture-full and portrait flip |
|
|
949
|
+
| ⚠ `slide <id> has data-flip="<value>"` | any value flips: write plain `data-flip`, or take it off |
|
|
939
950
|
| ⚠ `slide <id>: the … presenter would overlap the title` | move that slide's `.narration-slot`, pad the text away from it, or use `corner` |
|
|
940
951
|
|
|
941
952
|
**Review before release (required).** After `check` passes and the deck is
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The steps other topics refer to ("step 5", "step 6"). `<dir>` is the deck's
|
|
4
4
|
folder: any name, anywhere. `deck new` records the slug in `<dir>/.hyperdecks.json`,
|
|
5
5
|
so no command below needs `--slug`. Read a topic before its step:
|
|
6
|
-
`hyperdecks guide format`, `script`, `design`, `look`, `pictures`, `layouts`,
|
|
6
|
+
`hyperdecks guide format`, `script`, `design`, `look`, `pictures`, `embeds`, `layouts`,
|
|
7
7
|
`presenter`, `transitions`, `check`.
|
|
8
8
|
|
|
9
9
|
1. **Ground it.** Collect the user's own material (their site, docs, numbers).
|
|
@@ -38,7 +38,8 @@ so no command below needs `--slug`. Read a topic before its step:
|
|
|
38
38
|
`hyperdecks screenshot <url>`, `hyperdecks asset add <slug> <file>` (prints the
|
|
39
39
|
file name with its URL). Which kind of picture fits which slide, and icons
|
|
40
40
|
for a layout's icon slot (`hyperdecks icons search <word> --for <layout>`):
|
|
41
|
-
`hyperdecks guide pictures`.
|
|
41
|
+
`hyperdecks guide pictures`. A live map, video, Figma file or booking page the
|
|
42
|
+
viewer will use: the embed layout, `hyperdecks guide embeds`.
|
|
42
43
|
|
|
43
44
|
4. **Narrate.**
|
|
44
45
|
|
package/src/check.mjs
CHANGED
|
@@ -229,7 +229,7 @@ export async function measureLayout(deckDir, styles, { width = 1600, height = 90
|
|
|
229
229
|
}
|
|
230
230
|
const fitTexts = [...new Set(fit)]; // a text inside two boxes (scorecard's state in its row) is named once
|
|
231
231
|
const current = layout === "l-wall" ? { current: hasCells } : Object.hasOwn(roomy, layout ?? "") ? { current: hasRoom(layout) } : {};
|
|
232
|
-
return { id, style, ...current, ...(scaleName ? { size: scaleName } : {}), sized: slide.getAttribute("data-presenter-size")?.trim() || null, presenter, ...(head ? { head } : {}), title, onPicture, layout, pictures, framed, ...(media ? { media } : {}), ...(lens ? { lens } : {}), ...(fitTexts.length ? { fit: fitTexts } : {}), ...(broken.length ? { broken: [...new Set(broken)] } : {}), ...(wide ? { wide } : {}), ...(slide.classList.contains("l-zoom") ? { bounds: box(slide.getBoundingClientRect()) } : {}) };
|
|
232
|
+
return { id, style, ...current, ...(scaleName ? { size: scaleName } : {}), sized: slide.getAttribute("data-presenter-size")?.trim() || null, presenter, ...(head ? { head } : {}), title, onPicture, layout, pictures, framed, ...(media ? { media } : {}), ...(lens ? { lens } : {}), ...(fitTexts.length ? { fit: fitTexts } : {}), ...(broken.length ? { broken: [...new Set(broken)] } : {}), ...(wide ? { wide } : {}), ...(slide.classList.contains("l-zoom") ? { bounds: box(slide.getBoundingClientRect()) } : {}), ...(slide.hasAttribute("data-flip") ? { flipped: true } : {}) };
|
|
233
233
|
});
|
|
234
234
|
}, { styles, words: WORD_PARTS, roomy: ROOMY_LAYOUTS, fitBoxes: FIT_BOXES, fitRows: FIT_ROWS, footprint: PRESENTER_FOOTPRINT, scales: PRESENTER_SCALE, width: card?.width ?? width, height: card?.height ?? height, covers: COVER_LAYOUTS, edges: EDGE_PICTURES, unmeasured: UNMEASURED_PICTURES, phoneScreens: PHONE_SCREENS, cells: CELL_PICTURES }), { mobileTitles: !!card });
|
|
235
235
|
}
|
|
@@ -237,9 +237,12 @@ export async function measureLayout(deckDir, styles, { width = 1600, height = 90
|
|
|
237
237
|
// Lay each slide out as the framed player shows it on a phone: the deck's own
|
|
238
238
|
// phone rules at a 390×844 viewport, its mobile titles, inside the card, with
|
|
239
239
|
// JavaScript off. Returns { id, overflow } per slide: how far its content runs
|
|
240
|
-
// past the slide's bottom (≤ 0 when it fits).
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
// past the slide's bottom (≤ 0 when it fits). noPresenter lays it out as the
|
|
241
|
+
// player shows a deck with no presenter (.hd-no-presenter on the root: no foot
|
|
242
|
+
// kept clear), so a silent deck is not held to the presenter's room.
|
|
243
|
+
export async function measurePhoneFit(deckDir, { noPresenter = false } = {}) {
|
|
244
|
+
return withDeckPage(deckDir, { width: PHONE.width, height: PHONE.height }, (page) => page.evaluate(([card, noPresenter]) => {
|
|
245
|
+
if (noPresenter) document.documentElement.classList.add("hd-no-presenter");
|
|
243
246
|
for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile;
|
|
244
247
|
const sections = [...document.querySelectorAll("section.slide")];
|
|
245
248
|
const host = sections[0]?.parentElement ?? document.body;
|
|
@@ -249,7 +252,7 @@ export async function measurePhoneFit(deckDir) {
|
|
|
249
252
|
sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0", overflow: "hidden" }); });
|
|
250
253
|
return { id: slide.id, overflow: slide.scrollHeight - slide.clientHeight };
|
|
251
254
|
});
|
|
252
|
-
}, PHONE.card));
|
|
255
|
+
}, [PHONE.card, noPresenter]));
|
|
253
256
|
}
|
|
254
257
|
|
|
255
258
|
// How much of each slide's height holds content on a phone, laid out as
|
|
@@ -257,8 +260,11 @@ export async function measurePhoneFit(deckDir) {
|
|
|
257
260
|
// a frame, a card) to the bottom of the last, over the card's height. The
|
|
258
261
|
// presenter's slot and decorations do not count; a picture inside zoom's lens
|
|
259
262
|
// counts as the lens, and a contained <video> as its picture. Returns
|
|
260
|
-
// { id, layout, top, bottom, share, hole } per slide. The free height above the
|
|
261
|
-
// presenter (28 to 566 of 736px) caps share at about 0.73. `hole`: the tallest empty band between two drawn things
|
|
263
|
+
// { id, layout, top, bottom, share, hole, start, minFont, clipped } per slide. The free height above the
|
|
264
|
+
// presenter (28 to 566 of 736px) caps share at about 0.73. `hole`: the tallest empty band between two drawn things;
|
|
265
|
+
// `start`: the top of the first thing drawn, a text's top clamped to its element's box (a display title's glyphs reach above
|
|
266
|
+
// its line box by an amount that depends on the font); `minFont`: the smallest font size, in px, of any text shown;
|
|
267
|
+
// `clipped`: how many drawn things and text lines run past the card's edge by more than 1px.
|
|
262
268
|
export async function measurePhoneContent(deckDir) {
|
|
263
269
|
return withDeckPage(deckDir, { width: PHONE.width, height: PHONE.height }, (page) => page.evaluate((card) => {
|
|
264
270
|
for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile;
|
|
@@ -266,13 +272,14 @@ export async function measurePhoneContent(deckDir) {
|
|
|
266
272
|
const host = sections[0]?.parentElement ?? document.body;
|
|
267
273
|
Object.assign(host.style, { position: "relative", width: `${card.width}px`, height: `${card.height}px`, overflow: "hidden", margin: "0" });
|
|
268
274
|
document.body.style.margin = "0";
|
|
269
|
-
const DRAWN = "img, video, svg, canvas, .shot, .pic, .art, .frame, .clip, .lens, .card, .panel, .pill, .sticker, .face, .avatar, .cta, .figure";
|
|
275
|
+
const DRAWN = "img, video, svg, canvas, .shot, .pic, .art, .frame, .clip, .lens, .card, .panel, .pill, .sticker, .face, .avatar, .cta, .figure, .stages > li";
|
|
270
276
|
return sections.map((slide) => {
|
|
271
277
|
sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0", overflow: "hidden" }); });
|
|
272
278
|
const sr = slide.getBoundingClientRect();
|
|
273
279
|
const skip = (n) => !!n.closest(".narration-slot, .deco, [hidden]") || !!n.parentElement?.closest(".lens");
|
|
274
280
|
const rects = [];
|
|
275
|
-
|
|
281
|
+
let start = Infinity;
|
|
282
|
+
for (const n of slide.querySelectorAll(`${DRAWN}, .l-spotlight .row > li`)) {
|
|
276
283
|
if (skip(n) || getComputedStyle(n).display === "none") continue;
|
|
277
284
|
let r = n.getBoundingClientRect();
|
|
278
285
|
if (n.tagName === "VIDEO" && n.videoWidth && getComputedStyle(n).objectFit === "contain") {
|
|
@@ -280,25 +287,30 @@ export async function measurePhoneContent(deckDir) {
|
|
|
280
287
|
const k = Math.min(r.width / n.videoWidth, r.height / n.videoHeight), h = n.videoHeight * k;
|
|
281
288
|
const y = getComputedStyle(n).objectPosition.split(" ")[1] ?? "50%";
|
|
282
289
|
const top = r.top + (y.endsWith("%") ? (r.height - h) * parseFloat(y) / 100 : parseFloat(y) || 0);
|
|
283
|
-
r = { top, bottom: top + h, width: r.width, height: h };
|
|
290
|
+
r = { left: r.left, right: r.right, top, bottom: top + h, width: r.width, height: h };
|
|
284
291
|
}
|
|
285
|
-
if (r.width > 2 && r.height > 2) rects.push(r);
|
|
292
|
+
if (r.width > 2 && r.height > 2) { rects.push(r); if (r.bottom > sr.top && r.top < sr.bottom) start = Math.min(start, r.top); }
|
|
286
293
|
}
|
|
287
294
|
const walker = document.createTreeWalker(slide, NodeFilter.SHOW_TEXT);
|
|
295
|
+
let minFont = Infinity;
|
|
288
296
|
for (let t; (t = walker.nextNode());) {
|
|
289
297
|
if (!t.textContent.trim() || skip(t.parentElement) || t.parentElement.closest("svg")) continue;
|
|
290
298
|
const range = document.createRange();
|
|
291
299
|
range.selectNodeContents(t);
|
|
292
|
-
|
|
300
|
+
let shown = false;
|
|
301
|
+
const box = t.parentElement.getBoundingClientRect().top;
|
|
302
|
+
for (const r of range.getClientRects()) if (r.width && r.height) { rects.push(r); if (r.bottom > sr.top && r.top < sr.bottom) { shown = true; start = Math.min(start, Math.max(r.top, box)); } }
|
|
303
|
+
if (shown) minFont = Math.min(minFont, parseFloat(getComputedStyle(t.parentElement).fontSize));
|
|
293
304
|
}
|
|
294
305
|
const seen = rects.filter((r) => r.bottom > sr.top && r.top < sr.bottom);
|
|
306
|
+
const clipped = rects.filter((r) => r.left < sr.left - 1 || r.right > sr.right + 1 || r.top < sr.top - 1 || r.bottom > sr.bottom + 1).length;
|
|
295
307
|
const layout = [...slide.classList].find((c) => c.startsWith("l-"))?.slice(2) ?? null;
|
|
296
|
-
if (!seen.length) return { id: slide.id, layout, top: 0, bottom: 0, share: 0, hole: 0 };
|
|
308
|
+
if (!seen.length) return { id: slide.id, layout, top: 0, bottom: 0, share: 0, hole: 0, start: 0, minFont: null, clipped };
|
|
297
309
|
const top = Math.max(sr.top, Math.min(...seen.map((r) => r.top))), bottom = Math.min(sr.bottom, Math.max(...seen.map((r) => r.bottom)));
|
|
298
310
|
// The tallest empty band between two drawn things (a hole in the block).
|
|
299
311
|
let hole = 0, reach = -Infinity;
|
|
300
312
|
for (const r of [...seen].sort((a, b) => a.top - b.top)) { if (reach > -Infinity) hole = Math.max(hole, r.top - reach); reach = Math.max(reach, r.bottom); }
|
|
301
|
-
return { id: slide.id, layout, top: Math.round(top - sr.top), bottom: Math.round(bottom - sr.top), share: (bottom - top) / sr.height, hole: Math.round(hole) };
|
|
313
|
+
return { id: slide.id, layout, top: Math.round(top - sr.top), bottom: Math.round(bottom - sr.top), share: (bottom - top) / sr.height, hole: Math.round(hole), start: Math.round(Math.max(sr.top, start) - sr.top), minFont: Number.isFinite(minFont) ? minFont : null, clipped };
|
|
302
314
|
});
|
|
303
315
|
}, PHONE.card), { mobileTitles: true });
|
|
304
316
|
}
|
|
@@ -342,7 +354,8 @@ async function withDeckPage(deckDir, viewport, measure, { mobileTitles = false }
|
|
|
342
354
|
const MAX_BARS_FETCH = 25 * 1024 * 1024, BARS_FETCH_MS = 30_000;
|
|
343
355
|
export async function measureFramedBars(deckDir, measured, { fetch: fetchImpl = globalThis.fetch, ffmpeg = null, allowDestination = null } = {}) {
|
|
344
356
|
const { measureBars } = await import("./bars.mjs");
|
|
345
|
-
|
|
357
|
+
const { allowCaptureDestination, localStaticFile } = await import("./preview-capture.mjs");
|
|
358
|
+
allowDestination ??= allowCaptureDestination;
|
|
346
359
|
const { bundledFfmpeg, knownMedia } = await import("./mediaPreviewMake.mjs");
|
|
347
360
|
const { mkdtemp, rm, writeFile } = await import("node:fs/promises");
|
|
348
361
|
const { tmpdir } = await import("node:os");
|
|
@@ -361,6 +374,10 @@ export async function measureFramedBars(deckDir, measured, { fetch: fetchImpl =
|
|
|
361
374
|
if (f.local) {
|
|
362
375
|
input = realpathSync(resolve(root, src));
|
|
363
376
|
if (!input.startsWith(root + sep)) continue;
|
|
377
|
+
} else if (localStaticFile(src) !== undefined) {
|
|
378
|
+
// From a repo checkout, the app's own stills are the checkout's files, never fetched.
|
|
379
|
+
input = localStaticFile(src);
|
|
380
|
+
if (!input) continue;
|
|
364
381
|
} else {
|
|
365
382
|
// A deck (a hosted draft a chat agent wrote) must not reach this machine's own network:
|
|
366
383
|
// the capture's rule, a public address only, and no redirect to one that is not.
|
|
@@ -494,7 +511,7 @@ export async function layoutCheck(deckDir, html, manifest = null, { measure = me
|
|
|
494
511
|
warnings.push(MESSAGES.layoutUnchecked(e.message));
|
|
495
512
|
}
|
|
496
513
|
try {
|
|
497
|
-
errors.push(...phoneOverflowErrors(await measureFit(deckDir)));
|
|
514
|
+
errors.push(...phoneOverflowErrors(await measureFit(deckDir, { noPresenter: silentWithoutPresenter(html) })));
|
|
498
515
|
} catch (e) {
|
|
499
516
|
warnings.push(MESSAGES.layoutUnchecked(e.message));
|
|
500
517
|
}
|
package/src/checkRules.mjs
CHANGED
|
@@ -9,7 +9,8 @@ import { CSS_VALUE, THEME_IDS, contrastRatio, deckTheme, findTheme, groundPairs
|
|
|
9
9
|
import { DASH_AVATAR, presenterTagIssue } from "./presenter.mjs";
|
|
10
10
|
import { deckIconChoice } from "./iconChoice.mjs";
|
|
11
11
|
import { ICON_SLOTS } from "./iconSlots.mjs";
|
|
12
|
-
import { FRAME, alternativesFor } from "./layoutRoutes.mjs";
|
|
12
|
+
import { FLIPPABLE, FRAME, alternativesFor } from "./layoutRoutes.mjs";
|
|
13
|
+
import { embedSiteHint, resolveEmbed, sharedLinkNote } from "./embedSources.mjs";
|
|
13
14
|
import { MAX_DECK_GIFS, creditLines, hasGiphyCredit, hasUnsplashCredit, stockRefs, stockSource } from "./stockMedia.mjs";
|
|
14
15
|
|
|
15
16
|
export const PLAYER_V1 = "https://hyperdecks.ai/player/v1/player.js";
|
|
@@ -79,6 +80,13 @@ export const MESSAGES = {
|
|
|
79
80
|
morphPair: (id, prev) => `slide ${id}: morph needs an element with the same data-morph="<name>" on this slide and the one before it (${prev})`,
|
|
80
81
|
transitionStale: (where, script, manifest) => `${where}: script.md says transition "${script}" but the manifest has "${manifest}": run \`hyperdecks narrate\` so the player gets it`,
|
|
81
82
|
flyTwice: (ids) => `fly is for the deck's one big moment, but slides ${ids.join(", ")} all use it`,
|
|
83
|
+
// Embeds (deck_guide topic embeds): warnings, so a deck made before the embed layout still passes.
|
|
84
|
+
iframeBare: (id) => `slide ${id}: a bare <iframe> loads its site for every viewer as the deck opens, keeps the narration running while they use it, and shows as an empty box in video and PDF exports and link previews; use the embed layout instead: a still that goes live on tap (deck_guide topic embeds)`,
|
|
85
|
+
embedNoStill: (id) => `slide ${id}: the embed has no still (<img class="still" src="…">), so exports, thumbnails and link previews show an empty frame; capture one with \`hyperdecks screenshot <url> --embed\` (capture_url with embed=true) (deck_guide topic embeds)`,
|
|
86
|
+
embedSiteLink: (id, site, host) => `slide ${id}: ${embedSiteHint(site, host)}; until then the slide shows its still with a link out (deck_guide topic embeds)`,
|
|
87
|
+
embedSharedLink: (id, note) => `slide ${id}: ${note} (deck_guide topic embeds)`,
|
|
88
|
+
embedNotLive: (id, host) => `slide ${id}: ${host} is not one of the embed sources (Google Maps, YouTube, Vimeo, Loom, Figma, Calendly), so the slide shows its still with a link that opens it in a new tab, not a live frame (deck_guide topic embeds)`,
|
|
89
|
+
embedNoUrl: (id, url) => `slide ${id}: data-embed "${url}" is not an https link, so the slide shows its still with no control (deck_guide topic embeds)`,
|
|
82
90
|
// Warnings from the look topic (deck_guide look): the deck passes, but a person should look.
|
|
83
91
|
coverFade: (where, what) => `${where}: the cover ${what}, so the title sits on a mix of picture and colour that is hard to read: prefer cover-frame or cover-split (or hero, cover-band, cover-poster, cover-type), which keep the title on a solid ground (deck_guide topic layouts)`,
|
|
84
92
|
filmUndrawn: (theme) => `the theme asks for a moving film (--film: 1) but this deck's CSS has no film rule (@keyframes hd-film), so no film is drawn: set the theme again to bring it (hyperdecks theme set <deck-dir> ${theme}; a hosted deck: new_deck { theme: "${theme}" })`,
|
|
@@ -87,6 +95,9 @@ export const MESSAGES = {
|
|
|
87
95
|
// Variety (layoutRoutes.mjs): one shape over and over reads as the same slide again. Warnings only: a deliberate
|
|
88
96
|
// repeat is the author's call. `alts` is [[slide id, [layout, layout]], …], other shapes from the guide's table.
|
|
89
97
|
layoutOverused: (layout, ids, total, alts) => `${ids.length} of the ${total} content slides use ${layout} (${ids.join(", ")}), so the deck reads as the same slide again${otherShapes(alts)}. A deliberate repeat (a screens walkthrough, a run of numbers) is yours to keep (deck_guide topic layouts)`,
|
|
98
|
+
layoutSameSide: (layout, a, b, both) => `slides ${a} and ${b} are two ${layout} slides in a row with the panel on the same side, so they read as the same slide twice. ${both ? "Take data-flip off one of them" : `Put data-flip on ${b}'s section to mirror it`} so the two alternate (deck_guide topic layouts)`,
|
|
99
|
+
flipValue: (id, value) => `slide ${id} has data-flip="${value}", but any value still flips it (the layout matches the attribute, not its value). Write plain data-flip to flip it, or take the attribute off`,
|
|
100
|
+
flipIgnored: (id, layout) => `slide ${id} has data-flip, but ${layout} does not flip, so nothing changes. Only ${FLIPPABLE.join(", ")} flip; take it off or pick one of those`,
|
|
90
101
|
layoutRun: (layout, ids, alts) => `slides ${ids.join(", ")} are ${ids.length} ${layout} slides in a row${otherShapes(alts)}. A deliberate run (a screens walkthrough) is yours to keep (deck_guide topic layouts)`,
|
|
91
102
|
// A slide whose items have icons on some only (iconSlots.mjs). An empty slot is never warned about: icons are optional.
|
|
92
103
|
partIconSlot: (id, layout, filled, items) => `slide ${id}: ${filled} of the ${items} items in this ${layout} slide have an icon; give the rest one too, or take them out (deck_guide topic pictures)`,
|
|
@@ -666,6 +677,10 @@ const PLACEHOLDERS = [
|
|
|
666
677
|
layout: "l-video-beats", tag: "div", cls: "clip", what: "the recording", img: '<video class="clip" src="…" autoplay muted loop playsinline>',
|
|
667
678
|
how: { hosted: "upload the screen recording with upload_deck_asset", cli: "add the screen recording with `hyperdecks asset add`" },
|
|
668
679
|
},
|
|
680
|
+
{
|
|
681
|
+
layout: "l-embed", tag: "div", cls: "still", what: "the embed's still", img: '<img class="still" src="…" alt="…" width="…" height="…"> inside the .embed, which keeps its data-embed link',
|
|
682
|
+
how: { hosted: "capture it with capture_url (embed: true), which returns the whole .embed markup", cli: "capture it with `hyperdecks screenshot <url> --embed`, which prints the whole .embed markup" },
|
|
683
|
+
},
|
|
669
684
|
{
|
|
670
685
|
layout: "l-picture-full", tag: "div", cls: "pic", what: "the picture", img: '<img class="pic" src="…" alt="…">',
|
|
671
686
|
how: { hosted: "upload the real photo with upload_deck_asset", cli: "add the real photo with `hyperdecks asset add`" },
|
|
@@ -912,7 +927,7 @@ const MEDIA_CLEAR = {
|
|
|
912
927
|
label: ["the lens's label", "keep the screenshot (and the .pill under its lens) clear of the bottom-right corner, as the layout places it"],
|
|
913
928
|
clip: ["the recording", "keep the bar under (or beside) the recording and the presenter small on it (the layout's --hd-presenter-scale), as the layout places them"],
|
|
914
929
|
art: ["the picture", "keep the picture in hero's frame (420px tall at most), which ends above the presenter's head"],
|
|
915
|
-
beyondPanel: ["the picture beyond the panel", "keep the slide's slot-left so the presenter stands under the panel"],
|
|
930
|
+
beyondPanel: ["the picture beyond the panel", "keep the slide's slot-left so the presenter stands under the panel (on a flipped slide too: there slot-left stands it bottom-right)"],
|
|
916
931
|
words: ["the words", "keep the layout's widths, which end left of the presenter's corner"],
|
|
917
932
|
};
|
|
918
933
|
// The word layouts make room for an l or xl presenter set on the slide's own <section>, as closer and split do.
|
|
@@ -927,8 +942,9 @@ export function presenterMediaWarnings(measured, stage = "1600×900") {
|
|
|
927
942
|
return measured.flatMap((m) => {
|
|
928
943
|
if (!m.presenter || !m.media) return [];
|
|
929
944
|
// The hero's picture is kept clear of the head: the caption moves off pictures on its own (the player).
|
|
945
|
+
// picture-full's presenter stands under the panel: past its right edge, or its left edge on a flipped slide.
|
|
930
946
|
const roles = Object.entries(m.media).filter(([role, box]) => role === "beyondPanel"
|
|
931
|
-
? box && m.presenter.x + m.presenter.width > box.x + box.width + 4
|
|
947
|
+
? box && (m.flipped ? m.presenter.x < box.x - 4 : m.presenter.x + m.presenter.width > box.x + box.width + 4)
|
|
932
948
|
: hit(role === "art" ? m.head ?? m.presenter : m.presenter, box));
|
|
933
949
|
// The layouts are placed for the stage presenter; another style is larger (glass) or ignores the slot (corner).
|
|
934
950
|
const fix = (role) => (m.style === "stage" ? (role === "words" ? wordsFix(m) : MEDIA_CLEAR[role][1]) : `set data-presenter-style="stage" on this slide (the layout leaves room for the stage presenter${m.style === "corner" ? "; the corner one ignores its slot" : ""})`);
|
|
@@ -1312,7 +1328,7 @@ const PICTURE_KIND = {
|
|
|
1312
1328
|
hero: "a photo", "cover-frame": "a photo", "cover-split": "a photo", "cover-band": "a photo", "cover-poster": "a photo",
|
|
1313
1329
|
split: "a screenshot", "picture-full": "a photo", portrait: "their own photo", wall: "photos", team: "their faces",
|
|
1314
1330
|
product: "a screenshot", phones: "screenshots", "phone-stage": "a screenshot", screens: "screenshots", zoom: "a screenshot", "tap-through": "screenshots",
|
|
1315
|
-
"video-full": "a recording", "video-beats": "a recording", number: "a chart", chart: "a chart",
|
|
1331
|
+
"video-full": "a recording", "video-beats": "a recording", embed: "a still of the page", number: "a chart", chart: "a chart",
|
|
1316
1332
|
};
|
|
1317
1333
|
|
|
1318
1334
|
// Slides offered the same shapes are named together: "features-2, features-3: bento or spotlight".
|
|
@@ -1354,6 +1370,24 @@ export function varietyWarnings(all) {
|
|
|
1354
1370
|
return out;
|
|
1355
1371
|
}
|
|
1356
1372
|
|
|
1373
|
+
// Side-panel neighbours (docs/roadmap/mirrored-layouts-side-panel-slides-can-flip-left-right-and-t.md): two slides in a
|
|
1374
|
+
// row of one flippable layout, both flipped or both not, put the panel on the same side; data-flip on a layout that
|
|
1375
|
+
// does not flip does nothing. Warnings only, on any deck size: a pair is the smallest repeat, and each pair of a longer
|
|
1376
|
+
// run on one side is named. The layouts match the attribute, so any value flips: data-flip="false" is flipped, and warned.
|
|
1377
|
+
export function flipWarnings(all) {
|
|
1378
|
+
const flipped = (s) => /\sdata-flip(?=[\s=>])/.test(s.tag);
|
|
1379
|
+
const out = [];
|
|
1380
|
+
for (const [i, s] of all.entries()) {
|
|
1381
|
+
const layout = layoutOf(s), id = s.id || "with no id";
|
|
1382
|
+
const value = attr(s.tag, "data-flip");
|
|
1383
|
+
if (value != null && value !== "" && value !== "data-flip") out.push(MESSAGES.flipValue(id, value));
|
|
1384
|
+
if (flipped(s) && layout && !FLIPPABLE.includes(layout)) out.push(MESSAGES.flipIgnored(id, layout));
|
|
1385
|
+
const prev = all[i - 1];
|
|
1386
|
+
if (prev && layout && FLIPPABLE.includes(layout) && layoutOf(prev) === layout && flipped(prev) === flipped(s)) out.push(MESSAGES.layoutSameSide(layout, prev.id || "with no id", id, flipped(s)));
|
|
1387
|
+
}
|
|
1388
|
+
return out;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1357
1391
|
export function lookWarnings(html) {
|
|
1358
1392
|
const all = slides(html);
|
|
1359
1393
|
const out = [];
|
|
@@ -1390,8 +1424,35 @@ export function lookWarnings(html) {
|
|
|
1390
1424
|
const choice = deckIconChoice(html);
|
|
1391
1425
|
if (choice?.problem) out.push(MESSAGES.iconChoice(choice.problem));
|
|
1392
1426
|
if (sets.size > 1) out.push(MESSAGES.mixedIcons([...sets].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))));
|
|
1393
|
-
out.push(...varietyWarnings(all));
|
|
1427
|
+
out.push(...varietyWarnings(all), ...flipWarnings(all));
|
|
1394
1428
|
out.push(...textureWarnings(all, html), ...coverFadeWarnings(html));
|
|
1429
|
+
out.push(...embedWarnings(all));
|
|
1430
|
+
return out;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// The embed slide (docs/roadmap/embed-slide-a-still-first-live-on-tap-maps-video-figma-booki.md): an <iframe> written
|
|
1434
|
+
// into a slide, and each frame (an element with data-embed) with no still or with a URL that will not go live. A deck
|
|
1435
|
+
// with neither gets no line.
|
|
1436
|
+
export function embedWarnings(all) {
|
|
1437
|
+
const out = [];
|
|
1438
|
+
for (const slide of all) {
|
|
1439
|
+
const id = slide.id || "a slide with no id";
|
|
1440
|
+
const body = uncommented(slide.body);
|
|
1441
|
+
if (/<iframe\b/i.test(body)) out.push(MESSAGES.iframeBare(id));
|
|
1442
|
+
for (const el of slideElements({ tag: slide.tag, body }).slice(1)) {
|
|
1443
|
+
const url = attr(el.tag, "data-embed");
|
|
1444
|
+
if (url == null) continue;
|
|
1445
|
+
const inside = body.slice(el.start, el.end);
|
|
1446
|
+
// A still: an <img class="still"> with a src, or a div.still (the layout's placeholder, which check fails on by itself).
|
|
1447
|
+
const still = [...inside.matchAll(/<(img|div)\b[^>]*>/gi)].some(([tag, name]) => classes(tag).includes("still") && (name.toLowerCase() === "div" || (attr(tag, "src") ?? "").trim()));
|
|
1448
|
+
if (!still) out.push(MESSAGES.embedNoStill(id));
|
|
1449
|
+
// The attribute as the browser reads it: our own markup writes & as &.
|
|
1450
|
+
const resolved = resolveEmbed(decode(url));
|
|
1451
|
+
if (!resolved) out.push(MESSAGES.embedNoUrl(id, url));
|
|
1452
|
+
else if (!resolved.live) out.push(resolved.site ? MESSAGES.embedSiteLink(id, resolved.site, resolved.host) : MESSAGES.embedNotLive(id, resolved.host));
|
|
1453
|
+
else if (sharedLinkNote(resolved)) out.push(MESSAGES.embedSharedLink(id, sharedLinkNote(resolved)));
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1395
1456
|
return out;
|
|
1396
1457
|
}
|
|
1397
1458
|
|
|
@@ -1527,7 +1588,7 @@ const SIGNATURES = ["bg-corner", "bg-mark"];
|
|
|
1527
1588
|
export const MAX_SIGNATURE_SLIDES = 3;
|
|
1528
1589
|
const BUSY_LAYOUTS = ["l-number", "l-features", "l-team", "l-timeline", "l-compare"]; // full-width content: nothing to back
|
|
1529
1590
|
// The media layouts: the picture or recording is the slide's object and fills its column; no texture backs it.
|
|
1530
|
-
const MEDIA_LAYOUTS = ["l-phone-stage", "l-tap-through", "l-screens", "l-zoom", "l-video-full", "l-video-beats", "l-picture-full", "l-wall", "l-portrait"];
|
|
1591
|
+
const MEDIA_LAYOUTS = ["l-phone-stage", "l-tap-through", "l-screens", "l-zoom", "l-video-full", "l-video-beats", "l-picture-full", "l-wall", "l-portrait", "l-embed"];
|
|
1531
1592
|
const WORD_LAYOUTS = ["l-sentence", "l-strike", "l-spotlight", "l-funnel", "l-scorecard", "l-bento", "l-two-by-two", "l-staircase", "l-rail", "l-loop", "l-lanes", "l-two-bars", "l-stack"]; // the word shapes: their words run beside the presenter, nothing to back
|
|
1532
1593
|
const PICTURE_COVERS = ["l-cover-band", "l-cover-poster", "l-cover-split"]; // the picture is the ground (or half of it): a texture would only sit under it
|
|
1533
1594
|
export const TEXTURE_OFF = {
|
package/src/commands.mjs
CHANGED
|
@@ -628,7 +628,7 @@ ${layoutList()}
|
|
|
628
628
|
asset add <slug> <file|url> [--name n] [--trim]
|
|
629
629
|
file an image, video, audio (mp3, m4a), font or JSON under the deck; prints "<file> → <url>" (--json: { url, file, bars, … });
|
|
630
630
|
a picture or clip with solid bars baked in prints "bars: …", and --trim uploads it cropped to its content
|
|
631
|
-
guide [workflow|format|script|scripts|design|look|themes|layouts|photos|pictures|presenter|transitions|check] [<layout> …]
|
|
631
|
+
guide [workflow|format|script|scripts|design|look|themes|layouts|photos|pictures|embeds|presenter|transitions|check] [<layout> …]
|
|
632
632
|
the skill, one topic at a time; workflow is the terminal steps; layouts is an index,
|
|
633
633
|
guide layouts <name> … each named layout's detail
|
|
634
634
|
layouts suggest "<what the slide says>" [--json]
|
|
@@ -667,6 +667,8 @@ ${layoutList()}
|
|
|
667
667
|
out as a WebM + a stacked-alpha MP4 for Safari (prints both URLs and the <video> markup)
|
|
668
668
|
video-job <jobId> [--json]
|
|
669
669
|
screenshot <url> [--width 1440] [--height 900] [--full-page] [--slug <deck>] [--name <name>] [--download <file>]
|
|
670
|
+
--embed: the still for the embed layout (a map, a video, a Figma file, a booking page) and its markup;
|
|
671
|
+
with --embed, --id <slide-id>-embed names the frame and --alt "<what it shows>" its picture
|
|
670
672
|
a PNG of a public web page (private and local addresses are refused)
|
|
671
673
|
chart <spec.json|-> [--slug <deck>] [--name <name>] [--download <file>]
|
|
672
674
|
a branded SVG: { "kind": "bar|line|donut|number", "labels", "series", "values", "value", "palette" }
|
|
@@ -914,7 +916,7 @@ async function videoJob(pos, opts) {
|
|
|
914
916
|
|
|
915
917
|
async function screenshot(pos, opts) {
|
|
916
918
|
const [url] = pos;
|
|
917
|
-
if (!url) throw new Error("usage: screenshot <url> [--width 1440] [--height 900] [--full-page] [--slug <deck>] [--name <name>] [--download <file>]");
|
|
919
|
+
if (!url) throw new Error("usage: screenshot <url> [--embed] [--width 1440] [--height 900] [--full-page] [--slug <deck>] [--name <name>] [--download <file>]");
|
|
918
920
|
const out = await ops.captureUrl(opts, {
|
|
919
921
|
url,
|
|
920
922
|
width: opts.width,
|
|
@@ -922,11 +924,17 @@ async function screenshot(pos, opts) {
|
|
|
922
924
|
fullPage: opts["full-page"],
|
|
923
925
|
slug: opts.slug,
|
|
924
926
|
name: opts.name,
|
|
927
|
+
embed: opts.embed,
|
|
928
|
+
...(opts.embed ? { id: opts.id, alt: opts.alt } : {}),
|
|
925
929
|
});
|
|
926
930
|
// Print the paid asset's URL before downloading, so a failed download never hides it.
|
|
927
931
|
console.log(opts.json ? JSON.stringify(out, null, 2) : out.url);
|
|
932
|
+
if (out.embed && !opts.json) console.log(`${out.embed.live ? `live on tap (${out.embed.source}): the control says "${out.embed.label}"${out.embed.note ? `\n${out.embed.note}` : ""}` : out.embed.note}\n${out.width}x${out.height}${out.phone ? ` (${out.mid ? `${out.mid.width}x${out.mid.height} beside a presenter, ` : ""}${out.phone.width}x${out.phone.height} for phones)` : ""}; ${out.altNote ?? `alt: "${out.alt}"`}\n${out.look}${opts.id ? "" : "\nadd --id <slide-id>-embed to give the frame its slide's id"}\nmarkup for the embed slide:\n${out.markup}`);
|
|
928
933
|
if (out.creditsRemaining != null) process.stderr.write(`credits left: ${out.creditsRemaining}\n`);
|
|
929
934
|
await saveTo(opts.download, out.url);
|
|
935
|
+
// The phone still beside it: <name>-phone.<ext>.
|
|
936
|
+
if (opts.download && out.mid?.url) await saveTo(opts.download.replace(/(\.[a-z0-9]+)?$/i, "-mid$1"), out.mid.url);
|
|
937
|
+
if (opts.download && out.phone?.url) await saveTo(opts.download.replace(/(\.[a-z0-9]+)?$/i, "-phone$1"), out.phone.url);
|
|
930
938
|
}
|
|
931
939
|
|
|
932
940
|
// Found pictures (ops.searchPhotos / addPhoto / searchGifs): free, embedded from
|
|
@@ -1145,8 +1153,11 @@ async function saveTo(file, url) {
|
|
|
1145
1153
|
if (!file || !url) return;
|
|
1146
1154
|
const res = await fetch(url);
|
|
1147
1155
|
if (!res.ok) throw new Error(`download of ${url} failed (${res.status})`);
|
|
1148
|
-
|
|
1149
|
-
|
|
1156
|
+
// The file's name says what it is: a JPEG asked for as x.png is saved as x.jpg.
|
|
1157
|
+
const ext = { "image/jpeg": ".jpg", "image/png": ".png", "image/webp": ".webp", "image/gif": ".gif" }[(res.headers.get("content-type") ?? "").split(";")[0].trim()];
|
|
1158
|
+
const named = ext && !new RegExp(`\\${ext}$|${ext === ".jpg" ? "\\.jpeg$" : "^$"}`, "i").test(file) ? file.replace(/\.[a-z0-9]+$/i, "") + ext : file;
|
|
1159
|
+
writeFileSync(named, Buffer.from(await res.arrayBuffer()));
|
|
1160
|
+
process.stderr.write(`saved to ${named}${named !== file ? ` (the picture is ${ext.slice(1).toUpperCase()}, not what ${file} says)` : ""}\n`);
|
|
1150
1161
|
}
|
|
1151
1162
|
|
|
1152
1163
|
// The command table: "<group> <cmd>" or "<group>" → handler. Exported (via
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// The embed slide's still (docs/roadmap/embed-slide-a-still-first-live-on-tap-maps-video-figma-booki.md), made
|
|
2
|
+
// two ways, and refused loudly rather than saved when it shows an error or a consent banner:
|
|
3
|
+
// - a video or a Figma file: the picture its own site publishes for it (publishedStill), fetched, no browser;
|
|
4
|
+
// - a map, a booking page or any other page: the page as its frame shows it, inside an iframe (framedStill), in
|
|
5
|
+
// this machine's isolated Chromium (`hyperdecks preview setup`) or, without one, on the app's renderer
|
|
6
|
+
// (app/api/render/screenshot, which wraps an embed URL the same way).
|
|
7
|
+
import { PHONE_STILL, STILL_HEIGHT, STILL_WIDTH, embedErrorIn, framePage, framePass, stillSource } from "./embedSources.mjs";
|
|
8
|
+
|
|
9
|
+
const TYPES = { "image/jpeg": "jpg", "image/png": "png", "image/webp": "webp", "image/gif": "gif" };
|
|
10
|
+
|
|
11
|
+
// { bytes, contentType, title } for a source that publishes a picture of itself, null for one that does not
|
|
12
|
+
// (a map, a booking page). Throws with the source's own answer when it will not give one (private, not
|
|
13
|
+
// embeddable, gone), so the author knows the live frame would fail too.
|
|
14
|
+
export async function publishedStill(resolved, { fetchImpl = fetch } = {}) {
|
|
15
|
+
const from = stillSource(resolved);
|
|
16
|
+
if (!from) return null;
|
|
17
|
+
let title = null, images = from.images ?? [];
|
|
18
|
+
if (from.oembed) {
|
|
19
|
+
const res = await fetchImpl(from.oembed, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(15000) });
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
const why = res.status === 401 || res.status === 403 ? "it is private, or its owner does not allow embedding" : res.status === 404 ? "it is not public or does not exist" : `its site answered ${res.status}`;
|
|
22
|
+
throw new Error(`${resolved.name} will not show this link in a frame: ${why}. Share it publicly (anyone with the link) or pick another (${resolved.href})`);
|
|
23
|
+
}
|
|
24
|
+
const info = await res.json();
|
|
25
|
+
title = info.title ?? null;
|
|
26
|
+
if (info.thumbnail_url && !images.length) images = [info.thumbnail_url];
|
|
27
|
+
}
|
|
28
|
+
for (const url of images) {
|
|
29
|
+
const res = await fetchImpl(url, { signal: AbortSignal.timeout(15000) });
|
|
30
|
+
if (!res.ok) continue;
|
|
31
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
32
|
+
// The picture is what its bytes say, not its header (Loom serves a PNG as image/jpeg): its file is named for that.
|
|
33
|
+
const contentType = sniffType(bytes) ?? (res.headers.get("content-type") ?? "").split(";")[0].trim();
|
|
34
|
+
if (!TYPES[contentType]) continue;
|
|
35
|
+
// YouTube answers a missing maxresdefault with a small grey stand-in, not a 404.
|
|
36
|
+
if (resolved.source === "youtube" && bytes.length < 5000) continue;
|
|
37
|
+
return { bytes, contentType, title, ...imageSize(bytes) };
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`${resolved.name} published no picture for this link (${resolved.href}); capture the page instead, or pick another link`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// What a capture must not be saved as: a page that answered an error (`statuses`, the page's or its frame's
|
|
43
|
+
// documents), a frame that said an error, a blank one, or one a consent banner stayed over. Null when it is clean.
|
|
44
|
+
export function stillProblem(frames, name, { statuses = /** @type {number[]} */ ([]) } = {}) {
|
|
45
|
+
const bad = statuses.find((n) => n >= 400);
|
|
46
|
+
if (bad) return `the ${name} page answered ${bad}${bad === 404 ? " (not found)" : ""}, so there is no still to save; check the link`;
|
|
47
|
+
for (const f of frames) {
|
|
48
|
+
const err = embedErrorIn(f.text);
|
|
49
|
+
if (err) return `the ${name} frame showed an error instead of the page ("${(f.text.match(new RegExp(err, "i")) ?? [err])[0]}"), so there is no still to save; check the link is public and can be embedded`;
|
|
50
|
+
}
|
|
51
|
+
const drawn = frames.filter((f) => !f.wrapper);
|
|
52
|
+
if (drawn.length && drawn.every((f) => !String(f.text ?? "").trim() && !f.media)) return `the ${name} page drew nothing (a blank frame), so there is no still to save; check the link opens in a browser`;
|
|
53
|
+
if (frames.some((f) => f.overlay && !f.wrapper)) return `the ${name} page has a banner or panel over more than a quarter of it (a fundraising, newsletter or sign-up appeal), so the still would show it; capture it yourself and upload it with \`hyperdecks asset add\``;
|
|
54
|
+
if (frames.some((f) => f.banner)) return `the ${name} frame kept a cookie or consent banner over the page, so the still would show it; capture it yourself and upload it with \`hyperdecks asset add\``;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// A picture's type from its first bytes (PNG, JPEG, GIF, WebP), or null.
|
|
59
|
+
export function sniffType(b) {
|
|
60
|
+
if (b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4e && b[3] === 0x47) return "image/png";
|
|
61
|
+
if (b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return "image/jpeg";
|
|
62
|
+
if (b[0] === 0x47 && b[1] === 0x49 && b[2] === 0x46) return "image/gif";
|
|
63
|
+
if (b[0] === 0x52 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x46 && b[8] === 0x57 && b[9] === 0x45 && b[10] === 0x42 && b[11] === 0x50) return "image/webp";
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// A picture's pixel size from its first bytes (PNG, JPEG, GIF, WebP), or null.
|
|
68
|
+
export function imageSize(bytes) {
|
|
69
|
+
const b = bytes, u16 = (i) => (b[i] << 8) | b[i + 1], le16 = (i) => b[i] | (b[i + 1] << 8);
|
|
70
|
+
if (b[0] === 0x89 && b[1] === 0x50) return { width: (b[16] << 24 | b[17] << 16 | b[18] << 8 | b[19]) >>> 0, height: (b[20] << 24 | b[21] << 16 | b[22] << 8 | b[23]) >>> 0 };
|
|
71
|
+
if (b[0] === 0x47 && b[1] === 0x49) return { width: le16(6), height: le16(8) };
|
|
72
|
+
if (b[0] === 0x52 && b[8] === 0x57 && b[12] === 0x56 && b[13] === 0x50 && b[14] === 0x38) {
|
|
73
|
+
if (b[15] === 0x20) return { width: le16(26) & 0x3fff, height: le16(28) & 0x3fff };
|
|
74
|
+
if (b[15] === 0x4c) return { width: 1 + (((b[22] & 0x3f) << 8) | b[21]), height: 1 + (((b[24] & 0x0f) << 10) | (b[23] << 2) | ((b[22] & 0xc0) >> 6)) };
|
|
75
|
+
if (b[15] === 0x58) return { width: 1 + (b[24] | b[25] << 8 | b[26] << 16), height: 1 + (b[27] | b[28] << 8 | b[29] << 16) };
|
|
76
|
+
}
|
|
77
|
+
if (b[0] === 0xff && b[1] === 0xd8) {
|
|
78
|
+
for (let i = 2; i + 9 < b.length; ) {
|
|
79
|
+
if (b[i] !== 0xff) { i++; continue; }
|
|
80
|
+
const m = b[i + 1];
|
|
81
|
+
if (m >= 0xc0 && m <= 0xcf && m !== 0xc4 && m !== 0xc8 && m !== 0xcc) return { width: u16(i + 7), height: u16(i + 5) };
|
|
82
|
+
i += 2 + u16(i + 2);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The page as the slide shows it, from this machine's Chromium: { bytes, contentType, title, width, height }, a JPEG at
|
|
89
|
+
// the still's size. A live source's frame URL is loaded inside an iframe (framePage); any other page (`top`), as a
|
|
90
|
+
// page of its own, since many sites refuse to be framed. `chromium`: Playwright's (injected in tests). Throws
|
|
91
|
+
// stillProblem's words for an error answer, an error page, a blank page or a banner.
|
|
92
|
+
export async function framedStill(src, name, { chromium, top = false, phone = false, width = phone ? PHONE_STILL.width : STILL_WIDTH, height = phone ? PHONE_STILL.height : STILL_HEIGHT, settleMs = 5000 } = {}) {
|
|
93
|
+
// Not bundled into the app (the hosted MCP never captures locally): the CLI's own Playwright, loaded when asked.
|
|
94
|
+
chromium ??= (await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ "playwright")).chromium;
|
|
95
|
+
let browser;
|
|
96
|
+
try { browser = await chromium.launch({ headless: true, args: ["--mute-audio"] }); }
|
|
97
|
+
catch (e) { throw Object.assign(new Error(`no local Chromium: ${e?.message ?? e}`), { noLocalBrowser: true }); }
|
|
98
|
+
try {
|
|
99
|
+
// A phone still is a phone: its width, its pixel density, touch and a phone's browser, so a page lays itself out for it.
|
|
100
|
+
const page = await browser.newPage(phone
|
|
101
|
+
? { viewport: { width, height }, deviceScaleFactor: PHONE_STILL.scale, isMobile: true, hasTouch: true, userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1" }
|
|
102
|
+
: { viewport: { width, height }, deviceScaleFactor: 1 });
|
|
103
|
+
const statuses = [];
|
|
104
|
+
page.on("response", (r) => { if (r.request().isNavigationRequest() && (top || r.frame() !== page.mainFrame())) statuses.push(r.status()); });
|
|
105
|
+
if (top) await page.goto(src, { waitUntil: "load", timeout: 30000 });
|
|
106
|
+
else await page.setContent(framePage(src, { width, height }), { waitUntil: "load", timeout: 30000 });
|
|
107
|
+
await page.waitForTimeout(settleMs);
|
|
108
|
+
const pass = () => Promise.all(page.frames().map((f) => f.evaluate(framePass).then((r) => ({ ...r, wrapper: !top && f === page.mainFrame() })).catch(() => ({ text: "", clicked: null, banner: false, media: 0, wrapper: f === page.mainFrame() }))));
|
|
109
|
+
// A consent banner is dismissed, then the page gets a moment to redraw before the picture.
|
|
110
|
+
let frames = await pass();
|
|
111
|
+
if (frames.some((f) => f.clicked)) { await page.waitForTimeout(1500); frames = await pass(); }
|
|
112
|
+
const problem = stillProblem(frames, name, { statuses });
|
|
113
|
+
if (problem) throw new Error(problem);
|
|
114
|
+
const title = frames.find((f) => !f.wrapper && f.title)?.title ?? null;
|
|
115
|
+
const scale = phone ? PHONE_STILL.scale : 1;
|
|
116
|
+
return { bytes: new Uint8Array(await page.screenshot({ type: "jpeg", quality: 85 })), contentType: "image/jpeg", title, width: width * scale, height: height * scale };
|
|
117
|
+
} finally {
|
|
118
|
+
await browser.close().catch(() => {});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The capture could not start a browser here (none installed, or Playwright missing): the app's renderer takes it.
|
|
123
|
+
export const noLocalBrowser = (e) => !!e?.noLocalBrowser || /Cannot find (package|module) 'playwright'|Executable doesn't exist/.test(String(e?.message ?? e));
|
|
124
|
+
|
|
125
|
+
export const stillName = (resolved) => `embed-${(resolved.source ?? resolved.host ?? "page").replace(/[^a-z0-9]+/gi, "-").toLowerCase()}`;
|
|
126
|
+
export const extensionFor = (contentType) => TYPES[contentType] ?? "jpg";
|