@hypersocial/decks-cli 0.9.23 → 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 +124 -67
- package/skills/hyperdecks/chat.md +11 -8
- package/skills/hyperdecks/terminal.md +83 -0
- package/src/bars.mjs +268 -0
- package/src/brand.mjs +51 -8
- package/src/check.mjs +333 -20
- package/src/checkRules.mjs +677 -27
- package/src/commands.mjs +171 -31
- package/src/deckSlug.mjs +41 -0
- package/src/embedCapture.mjs +126 -0
- package/src/embedSources.mjs +252 -0
- package/src/embedsGuide.mjs +36 -0
- package/src/export-video.mjs +20 -3
- package/src/files.mjs +36 -0
- package/src/guide.mjs +93 -13
- package/src/hosted.mjs +18 -8
- package/src/iconAliasNames.mjs +70 -0
- package/src/iconChoice.mjs +97 -0
- package/src/iconSets.mjs +89 -0
- package/src/iconSlots.mjs +48 -0
- package/src/icons.mjs +285 -45
- package/src/iconsCli.mjs +76 -0
- package/src/layoutRoutes.mjs +97 -0
- package/src/layouts.mjs +9 -4
- package/src/mediaPreviews.mjs +3 -1
- package/src/narrate.mjs +31 -4
- package/src/opening.mjs +9 -3
- package/src/ops.mjs +125 -0
- package/src/photosGuide.mjs +47 -0
- package/src/picturesGuide.mjs +54 -0
- package/src/play.mjs +3 -2
- package/src/presenter.mjs +3 -1
- package/src/preview-capture.mjs +70 -1
- package/src/release.mjs +13 -5
- package/src/runtime.mjs +9 -2
- package/src/scaffold.mjs +73 -13
- package/src/source.mjs +86 -14
- package/src/stockMedia.mjs +299 -0
- package/src/themeCli.mjs +41 -0
- package/src/themes.mjs +345 -0
- package/templates/icons/material.LICENSE +202 -0
- package/templates/icons/material.json.gz +0 -0
- package/templates/icons/phosphor.LICENSE +21 -0
- package/templates/icons/phosphor.json.gz +0 -0
- package/templates/icons/tabler.LICENSE +21 -0
- package/templates/icons/tabler.json.gz +0 -0
- package/templates/layouts/_deck.html +231 -41
- package/templates/layouts/bento.html +76 -0
- package/templates/layouts/chart.html +6 -4
- package/templates/layouts/closer.html +13 -4
- package/templates/layouts/compare.html +13 -4
- package/templates/layouts/cover-band.html +13 -9
- package/templates/layouts/cover-frame.html +13 -7
- package/templates/layouts/cover-poster.html +9 -5
- package/templates/layouts/cover-split.html +19 -7
- package/templates/layouts/cover-type.html +2 -1
- package/templates/layouts/embed.html +93 -0
- package/templates/layouts/features.html +18 -10
- package/templates/layouts/funnel.html +62 -0
- package/templates/layouts/hero.html +41 -23
- package/templates/layouts/lanes.html +63 -0
- package/templates/layouts/loop.html +81 -0
- package/templates/layouts/number.html +3 -2
- package/templates/layouts/phone-stage.html +78 -0
- package/templates/layouts/phones.html +1 -0
- package/templates/layouts/picture-full.html +58 -0
- package/templates/layouts/portrait.html +53 -0
- package/templates/layouts/product.html +7 -6
- package/templates/layouts/quote.html +5 -3
- package/templates/layouts/rail.html +74 -0
- package/templates/layouts/scorecard.html +71 -0
- package/templates/layouts/screens.html +85 -0
- package/templates/layouts/sentence.html +39 -0
- package/templates/layouts/split.html +35 -7
- package/templates/layouts/spotlight.html +80 -0
- package/templates/layouts/stack.html +84 -0
- package/templates/layouts/staircase.html +78 -0
- package/templates/layouts/strike.html +46 -0
- package/templates/layouts/tap-through.html +73 -0
- package/templates/layouts/team.html +21 -6
- package/templates/layouts/timeline.html +21 -8
- package/templates/layouts/two-bars.html +53 -0
- package/templates/layouts/two-by-two.html +75 -0
- package/templates/layouts/video-beats.html +66 -0
- package/templates/layouts/video-full.html +62 -0
- package/templates/layouts/wall.html +109 -0
- package/templates/layouts/zoom.html +144 -0
- package/templates/narrated-deck.html +12 -7
- package/templates/script.md +2 -2
- /package/templates/icons/{LICENSE → lucide.LICENSE} +0 -0
package/src/commands.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { deckSlug } from "./deckSlug.mjs";
|
|
3
4
|
import {
|
|
4
5
|
agentTable,
|
|
5
6
|
backupLinkUrl,
|
|
@@ -17,10 +18,12 @@ import {
|
|
|
17
18
|
import { fetchVersionInfo, updatePreflight } from "./update.mjs";
|
|
18
19
|
import { refreshSkillCopies } from "./skillFreshness.mjs";
|
|
19
20
|
import * as ops from "./ops.mjs";
|
|
21
|
+
import { FOR_HINT } from "./stockMedia.mjs";
|
|
20
22
|
import { MAX_TAGS, normalizeTags } from "./tags.mjs";
|
|
21
23
|
import { sentToLabel, sentToMatch } from "./deckSearch.mjs";
|
|
22
24
|
import { exportVideo } from "./export-video.mjs";
|
|
23
25
|
import { presenterLine } from "./presenter.mjs";
|
|
26
|
+
import { LAYOUTS } from "./layouts.mjs";
|
|
24
27
|
|
|
25
28
|
export const playbackLabel = (p) => p.narrationFinished ? "narration finished"
|
|
26
29
|
: p.narrationStarted ? "narration started"
|
|
@@ -228,7 +231,7 @@ async function deckArchive(pos, opts, archived) {
|
|
|
228
231
|
|
|
229
232
|
async function shareNew(pos, opts) {
|
|
230
233
|
const [slug, recipient] = pos;
|
|
231
|
-
const usage = "usage: share new <slug> <recipient> [--email e] [--note n] [--require-email] [--expires iso] [--limit n] [--qa] [--no-notify] [--allow-forward|--no-forward] [--pace auto|slide|step]";
|
|
234
|
+
const usage = "usage: share new <slug> <recipient> [--email e] [--note n] [--require-email] [--expires iso] [--limit n] [--qa] [--no-notify] [--allow-forward|--no-forward] [--pace auto|slide|step] [--count-on-play]";
|
|
232
235
|
if (!slug || !recipient) throw new Error(usage);
|
|
233
236
|
if (opts["allow-forward"] && opts["no-forward"]) throw new Error("pick one of --allow-forward and --no-forward");
|
|
234
237
|
// The link's own pace; without it the link follows the deck's.
|
|
@@ -243,6 +246,7 @@ async function shareNew(pos, opts) {
|
|
|
243
246
|
notify: opts["no-notify"] ? false : undefined,
|
|
244
247
|
allowForward: opts["allow-forward"] ? true : opts["no-forward"] ? false : undefined,
|
|
245
248
|
pace: opts.pace,
|
|
249
|
+
countOnPlay: opts["count-on-play"] || undefined,
|
|
246
250
|
expires: opts.expires,
|
|
247
251
|
limit: opts.limit,
|
|
248
252
|
});
|
|
@@ -266,7 +270,7 @@ async function shareList(pos, opts) {
|
|
|
266
270
|
// Rows arrive with each link's forwards right after it; indent those.
|
|
267
271
|
for (const r of rows) {
|
|
268
272
|
const who = r.parentToken ? ` ↳ ${r.recipient} via ${r.forwardedBy ?? "?"}` : r.recipient;
|
|
269
|
-
console.log(`${r.enabled ? "on " : "off"}\t${r.token}\t${who}\topens:${r.opens}\tfwd:${r.allowForward ? "on" : "off"}${r.pace ? `\tpace:${r.pace}` : ""}${r.qa ? "\tQA (untracked)" : ""}${r.notify === false ? "\tmuted" : ""}${r.probablyForwarded ? "\tprobably forwarded" : ""}${r.archived ? "\t(archived)" : ""}`);
|
|
273
|
+
console.log(`${r.enabled ? "on " : "off"}\t${r.token}\t${who}\topens:${r.opens}\tfwd:${r.allowForward ? "on" : "off"}${r.pace ? `\tpace:${r.pace}` : ""}${r.countOn === "play" ? "\tcounts on play" : ""}${r.qa ? "\tQA (untracked)" : ""}${r.notify === false ? "\tmuted" : ""}${r.probablyForwarded ? "\tprobably forwarded" : ""}${r.archived ? "\t(archived)" : ""}`);
|
|
270
274
|
}
|
|
271
275
|
if (!rows.length) console.log("(no shares)");
|
|
272
276
|
}
|
|
@@ -294,6 +298,13 @@ async function shareForward(pos, opts) {
|
|
|
294
298
|
console.log(`OK forwarding ${mode === "default" ? "follows the deck default" : mode} for ${token}`);
|
|
295
299
|
}
|
|
296
300
|
|
|
301
|
+
async function shareCount(pos, opts) {
|
|
302
|
+
const [mode, token] = pos;
|
|
303
|
+
if ((mode !== "play" && mode !== "open") || !token) throw new Error("usage: share count play|open <token>");
|
|
304
|
+
await ops.setShareCountOn(opts, token, mode === "play");
|
|
305
|
+
console.log(mode === "play" ? `OK ${token} counts an open (and alerts you) only when the viewer presses play` : `OK ${token} counts an open when the link is opened`);
|
|
306
|
+
}
|
|
307
|
+
|
|
297
308
|
async function deckForward(pos, opts) {
|
|
298
309
|
const [mode, slug] = pos;
|
|
299
310
|
if ((mode !== "on" && mode !== "off") || !slug) throw new Error("usage: deck forward on|off <slug>");
|
|
@@ -540,6 +551,18 @@ async function importDesignDeck(pos, opts) {
|
|
|
540
551
|
}
|
|
541
552
|
}
|
|
542
553
|
|
|
554
|
+
// Every layout deck new --layouts takes, from the library itself, wrapped under the help's indent.
|
|
555
|
+
export function layoutList(indent = " ".repeat(19), width = 118) {
|
|
556
|
+
const lines = [];
|
|
557
|
+
let line = `${indent}layouts:`;
|
|
558
|
+
for (const [i, name] of LAYOUTS.entries()) {
|
|
559
|
+
const word = ` ${name}${i < LAYOUTS.length - 1 ? "," : ""}`;
|
|
560
|
+
if (line.length + word.length > width) { lines.push(line); line = indent + word.slice(1); }
|
|
561
|
+
else line += word;
|
|
562
|
+
}
|
|
563
|
+
return [...lines, line].join("\n");
|
|
564
|
+
}
|
|
565
|
+
|
|
543
566
|
export function help() {
|
|
544
567
|
console.log(`decks ${VERSION}
|
|
545
568
|
|
|
@@ -585,12 +608,15 @@ commands:
|
|
|
585
608
|
how the deck opens in the player (default: as its HTML says, data-view or slides) and
|
|
586
609
|
whether viewers get the slides/scroll toggle (on by default). Every link, next load; no re-release.
|
|
587
610
|
--ai-readable: whether each link + /md serves the deck as markdown for AI assistants (on by default).
|
|
588
|
-
deck new <slug> "<title>" --narrated [--layouts hero,product,number,closer] [--presenter-style stage|bubble|glass|corner] [--no-brand] [--dir <path>] [--tag <tag,...>]
|
|
611
|
+
deck new <slug> "<title>" --narrated [--layouts hero,product,number,closer] [--presenter-style stage|bubble|glass|corner] [--presenter <narrator>] [--theme <name>] [--icons "<set> [weight]"] [--brand|--no-brand] [--dir <path>] [--tag <tag,...>]
|
|
612
|
+
--theme: a built-in theme (hyperdecks theme list; default house). A named theme (house too) keeps
|
|
613
|
+
its own colours and fonts and gets no logo; --brand puts your saved brand on top of it
|
|
614
|
+
--dir: any folder (an empty one is fine); the slug is recorded there, so later commands need no --slug
|
|
615
|
+
--presenter dash: D.A.S.H. presents (default: the account's default narrator; the output says who)
|
|
589
616
|
scaffold decks/<slug>/: index.html (8 slides, or one per layout, player/v1), script.md, evidence.md,
|
|
590
|
-
in your saved brand's colours, fonts and logo (--no-brand: the template's look)
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
check <slug|deck-dir> [--forbid "<phrase>,<phrase>"] [--max-duration <s>] [--layout] [--strict] [--fix] [--json]
|
|
617
|
+
with no --theme, in your saved brand's colours, fonts and logo (--no-brand: the template's look)
|
|
618
|
+
${layoutList()}
|
|
619
|
+
check <slug|deck-dir> [--slug <slug>] [--forbid "<phrase>,<phrase>"] [--max-duration <s>] [--layout] [--strict] [--fix] [--json]
|
|
594
620
|
the narrated-deck gate: slides vs manifest, timing, captions, clip URLs,
|
|
595
621
|
local refs, pinned player, mobile titles. data-silent on the player script: no narration
|
|
596
622
|
(a warning). Missing data-notes warn, and fail on a data-kind="pitch" deck or with --strict.
|
|
@@ -599,17 +625,25 @@ commands:
|
|
|
599
625
|
the same on a hosted draft (no folder, no git: what chat agents use over the remote MCP)
|
|
600
626
|
source pull <slug> [dir] | source push <slug> [dir] [--base-rev N]
|
|
601
627
|
move a hosted draft (index.html, script.md, evidence.md) to a folder and back
|
|
602
|
-
asset add <slug> <file|url> [--name n]
|
|
603
|
-
file an image, video, audio (mp3, m4a), font or JSON under the deck; prints
|
|
604
|
-
|
|
605
|
-
|
|
628
|
+
asset add <slug> <file|url> [--name n] [--trim]
|
|
629
|
+
file an image, video, audio (mp3, m4a), font or JSON under the deck; prints "<file> → <url>" (--json: { url, file, bars, … });
|
|
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|embeds|presenter|transitions|check] [<layout> …]
|
|
632
|
+
the skill, one topic at a time; workflow is the terminal steps; layouts is an index,
|
|
633
|
+
guide layouts <name> … each named layout's detail
|
|
634
|
+
layouts suggest "<what the slide says>" [--json]
|
|
635
|
+
two or three layouts that fit what one slide says (the guide's routing table)
|
|
606
636
|
play <slug|deck-dir> [--voice <the voice it was narrated in>] [--slug <slug>] [--port <n>] [--no-open] [--json]
|
|
607
637
|
play the folder as it is, committed or not, with its real face and voice, on 127.0.0.1
|
|
608
638
|
until Ctrl-C; nothing is written, uploaded or shared, and changed lines need narrate first
|
|
609
|
-
release <slug|deck-dir> [--to "<name>" [--email <e>]]... [--qa] [--no-notify] [--title t] [--voice v] [--captions-only (--hosted)]
|
|
610
|
-
on a committed deck: check → narrate → import → share new per --to
|
|
611
|
-
|
|
612
|
-
|
|
639
|
+
release <slug|deck-dir> [--slug <slug>] [--to "<name>" [--email <e>]]... [--qa] [--no-notify] [--title t] [--voice v] [--captions-only (--hosted)]
|
|
640
|
+
on a committed deck in a git repository: check → narrate → import → share new per --to;
|
|
641
|
+
--qa with no --to prints one QA link for you (untracked, no email)
|
|
642
|
+
share new|list|on|off|forward|count|mute|unmute|rm|url
|
|
643
|
+
share new <slug> <recipient> [--qa] [--no-notify] [--allow-forward|--no-forward] [--pace auto|slide|step] [--count-on-play]
|
|
644
|
+
share count play|open <token>
|
|
645
|
+
play: count an open, and alert you, only when the viewer presses play, for a deck
|
|
646
|
+
embedded in a page (loading the page is not watching); open: on open, the default.
|
|
613
647
|
share forward on|off|default <token>
|
|
614
648
|
let this link's viewer forward it as their own tracked link ("Dana via Peter",
|
|
615
649
|
one hop); default follows the deck. share off on a link also turns off its forwards.
|
|
@@ -622,7 +656,7 @@ commands:
|
|
|
622
656
|
activity [--deck <slug>] [--limit <n>] [--json]
|
|
623
657
|
engagement <recipient|token> [--deck <slug>] [--json]
|
|
624
658
|
what one recipient watched per deck: narration heard, replays, drop-off, visits
|
|
625
|
-
gen-image "<prompt>" [--model gpt-image-2.5|nano-banana-2.1|gpt-image-2] [--transparent] [--image <url>] [--size <
|
|
659
|
+
gen-image "<prompt>" [--model gpt-image-2.5|nano-banana-2.1|gpt-image-2] [--transparent] [--image <url>] [--size <WxH>]
|
|
626
660
|
[--quality <q>] [--count <n>] [--seed <n>] [--brand] [--slug <deck>] [--download <file>]
|
|
627
661
|
default model gpt-image-2.5; --seed applies to nano-banana-2.1;
|
|
628
662
|
--brand adds your brand's colours and "no text, no logos" to the prompt
|
|
@@ -633,11 +667,28 @@ commands:
|
|
|
633
667
|
out as a WebM + a stacked-alpha MP4 for Safari (prints both URLs and the <video> markup)
|
|
634
668
|
video-job <jobId> [--json]
|
|
635
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
|
|
636
672
|
a PNG of a public web page (private and local addresses are refused)
|
|
637
673
|
chart <spec.json|-> [--slug <deck>] [--name <name>] [--download <file>]
|
|
638
674
|
a branded SVG: { "kind": "bar|line|donut|number", "labels", "series", "values", "value", "palette" }
|
|
639
|
-
|
|
640
|
-
|
|
675
|
+
photos search <words...> [--orientation landscape|portrait|squarish] [--limit 10] [--json]
|
|
676
|
+
find a photo on Unsplash for a place, an object or a mood (free); prints each id, shape and photographer
|
|
677
|
+
photos add <id> [--for <layout>] [--json]
|
|
678
|
+
use one: prints the picture markup (from Unsplash's own URL), its credit line for the slide and
|
|
679
|
+
the data-note credit; Unsplash counts it as a download. --for cover-band|split|picture-full|wall|…
|
|
680
|
+
(or a slide id like wall-2) prints the markup that slot takes and what it replaces (guide photos)
|
|
681
|
+
gifs search <words...> [--rating g|pg] [--limit 10] [--for <layout>] [--json]
|
|
682
|
+
find a GIF on GIPHY (G-rated unless --rating pg; free); prints each GIF's markup (a muted looping
|
|
683
|
+
MP4 from GIPHY with "Powered by GIPHY"); one or two in a casual deck at most
|
|
684
|
+
icons search <word...> [--for <layout>] [--set lucide|phosphor|tabler|material|all] [--weight W] [--deck <dir>] [--limit 8] [--stroke-width 2] [--json]
|
|
685
|
+
real icons as inline SVG in currentColor (free, offline), each labelled with its set and
|
|
686
|
+
weight; looks in the deck's recorded set (icons use), else in every set; --for says where it goes
|
|
687
|
+
icons sets [--json]
|
|
688
|
+
the icon sets: weights, character, licence and a sample, to pick one for the deck
|
|
689
|
+
icons use <deck-dir|slug> <set> [weight] [--hosted]
|
|
690
|
+
record the deck's icon set and weight (<meta name="hd-icons">) and put the icons already in it
|
|
691
|
+
(the layouts' own too) in that set; later searches stay in it
|
|
641
692
|
icons <subject...> --preset line|duotone|sticker|clay | --style "<style>" [--palette "#hex,#hex"] [--slug <deck>] [--name <prefix>]
|
|
642
693
|
a style-consistent set of generated (illustrated) icons, one per subject (max 12);
|
|
643
694
|
palette defaults to your brand's colours
|
|
@@ -656,11 +707,16 @@ commands:
|
|
|
656
707
|
undo the last change, or go back to a version from brand history
|
|
657
708
|
brand edit edit design.md (voice, do and don't) in $EDITOR
|
|
658
709
|
brand fonts the curated font pairings (display + body + mono)
|
|
710
|
+
theme [list] the built-in themes (house, longform, blueprint, soft, loud, print, quiet, evening, carousel): shape,
|
|
711
|
+
title style and how photos and charts are drawn; a named theme keeps its colours unless --brand
|
|
712
|
+
theme set <deck-dir|slug> <theme> [--brand|--no-brand]
|
|
713
|
+
put a local deck in another theme, in its own colours and fonts (--brand: your brand's on top);
|
|
714
|
+
a released deck changes when you release it again
|
|
659
715
|
brand clear forget the brand; new decks get the template look
|
|
660
716
|
review <slug> [--script <script.md>] [--json]
|
|
661
717
|
GPT-6 Luna reviews every slide (desktop + phone screenshots) and lists what to fix
|
|
662
718
|
review-job <jobId> [--json]
|
|
663
|
-
export <slug|deck-dir> --pdf [--notes] [--out <file.pdf>] [--share <token>] [--json]
|
|
719
|
+
export <slug|deck-dir> [--slug <slug>] --pdf [--notes] [--out <file.pdf>] [--share <token>] [--json]
|
|
664
720
|
a PDF of the released deck: one 1600x900 page per slide (a script page after each
|
|
665
721
|
with --notes), a footer with the deck's tracked link; kept 30 days
|
|
666
722
|
export <slug|deck-dir> --video [--size 1080p|720p|4k] [--shape 16:9|9:16|1:1] [--no-captions]
|
|
@@ -739,7 +795,7 @@ async function genImage(pos, opts) {
|
|
|
739
795
|
const prompt = pos.join(" ").trim() || opts.prompt;
|
|
740
796
|
if (!prompt) {
|
|
741
797
|
throw new Error(
|
|
742
|
-
'usage: gen-image "<prompt>" [--model gpt-image-2.5|nano-banana-2.1|gpt-image-2] [--image <url>] [--transparent] [--size <
|
|
798
|
+
'usage: gen-image "<prompt>" [--model gpt-image-2.5|nano-banana-2.1|gpt-image-2] [--image <url>] [--transparent] [--size <WxH>, e.g. 1536x1024] [--quality <q>] [--count <n>] [--format png|jpeg|webp] [--seed <n>] [--brand] [--slug <deck>] [--name <name>] [--download <file>]',
|
|
743
799
|
);
|
|
744
800
|
}
|
|
745
801
|
let out = await ops.generateImage(opts, {
|
|
@@ -860,7 +916,7 @@ async function videoJob(pos, opts) {
|
|
|
860
916
|
|
|
861
917
|
async function screenshot(pos, opts) {
|
|
862
918
|
const [url] = pos;
|
|
863
|
-
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>]");
|
|
864
920
|
const out = await ops.captureUrl(opts, {
|
|
865
921
|
url,
|
|
866
922
|
width: opts.width,
|
|
@@ -868,11 +924,60 @@ async function screenshot(pos, opts) {
|
|
|
868
924
|
fullPage: opts["full-page"],
|
|
869
925
|
slug: opts.slug,
|
|
870
926
|
name: opts.name,
|
|
927
|
+
embed: opts.embed,
|
|
928
|
+
...(opts.embed ? { id: opts.id, alt: opts.alt } : {}),
|
|
871
929
|
});
|
|
872
930
|
// Print the paid asset's URL before downloading, so a failed download never hides it.
|
|
873
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}`);
|
|
874
933
|
if (out.creditsRemaining != null) process.stderr.write(`credits left: ${out.creditsRemaining}\n`);
|
|
875
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);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// Found pictures (ops.searchPhotos / addPhoto / searchGifs): free, embedded from
|
|
941
|
+
// the service's own URL with a credit line.
|
|
942
|
+
async function photosSearch(words, opts) {
|
|
943
|
+
if (!words.length) throw new Error("usage: photos search <words...> [--orientation landscape|portrait|squarish] [--limit 10] [--json]");
|
|
944
|
+
const out = await ops.searchPhotos(opts, { query: words.join(" "), orientation: opts.orientation, limit: opts.limit });
|
|
945
|
+
if (opts.json) return console.log(JSON.stringify(out, null, 2));
|
|
946
|
+
if (!out.results.length) return console.log(`no photos for "${out.query}"${out.hint ? `\n${out.hint}` : ""}`);
|
|
947
|
+
for (const r of out.results) console.log(`${r.id} ${r.shape} ${r.width}x${r.height} by ${r.photographer} ${r.description}\n ${r.thumbUrl}`);
|
|
948
|
+
if (out.hint) console.log(`\n${out.hint}`);
|
|
949
|
+
console.log(`\nuse one: hyperdecks photos add <id> --for <layout> (searches are free)`);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
async function photosAdd(pos, opts) {
|
|
953
|
+
if (!pos[0]) throw new Error("usage: photos add <id> [--for <layout>] [--json]");
|
|
954
|
+
const out = await ops.addPhoto(opts, { id: pos[0], for: opts.for });
|
|
955
|
+
if (opts.json) return console.log(JSON.stringify(out, null, 2));
|
|
956
|
+
console.log(`${slotText(out)}\n\ncredit line (once, as the slide's own child; join several credits with " · "):\n${out.creditLine}`);
|
|
957
|
+
console.log(`\ndata-note credit: ${out.note}`);
|
|
958
|
+
console.log(`${out.shape} ${out.width}x${out.height}; check fails without the credit line`);
|
|
959
|
+
if (out.tracked === false) process.stderr.write("Unsplash's download count could not be sent this time; the photo is fine to use\n");
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
async function gifsSearch(words, opts) {
|
|
963
|
+
if (!words.length) throw new Error("usage: gifs search <words...> [--rating g|pg] [--limit 10] [--for <layout>] [--json]");
|
|
964
|
+
const out = await ops.searchGifs(opts, { query: words.join(" "), rating: opts.rating, limit: opts.limit, for: opts.for });
|
|
965
|
+
if (opts.json) return console.log(JSON.stringify(out, null, 2));
|
|
966
|
+
if (!out.results.length) return console.log(`no GIFs for "${out.query}" (rating ${out.rating})`);
|
|
967
|
+
for (const r of out.results) console.log(`${r.id} ${r.shape} ${r.width}x${r.height} ${r.title}\n preview: ${r.previewUrl}\n ${r.markup}\n ${r.creditLine}\n data-note credit: ${r.note}`);
|
|
968
|
+
const slot = out.results[0]?.slot;
|
|
969
|
+
console.log(`\nPowered by GIPHY. Paste one GIF's markup ${slot ? `in place of ${slot.replaces} on the ${slot.slide} slide` : "into the picture slot"} and its credit line once as the slide's own child (searches are free).${slot ? "" : `\n${FOR_HINT}`}`);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// What photos add prints for the picture: the markup and what it replaces
|
|
973
|
+
// (with --for), or the default markup and the flag that fits it to a layout.
|
|
974
|
+
function slotText(out) {
|
|
975
|
+
if (!out.slot) return `picture slot:\n${out.markup}\n(${FOR_HINT})`;
|
|
976
|
+
const { slide, replaces, otherCells, cells } = out.slot;
|
|
977
|
+
const lines = [`on the ${slide} slide, in place of ${replaces}:`, out.markup];
|
|
978
|
+
if (cells) lines.push(`(${cells})`);
|
|
979
|
+
if (otherCells) lines.push(`\nfor ${otherCells.replaces} (no id):`, otherCells.markup);
|
|
980
|
+
return lines.join("\n");
|
|
876
981
|
}
|
|
877
982
|
|
|
878
983
|
async function chart(pos, opts) {
|
|
@@ -954,7 +1059,7 @@ export function exportTarget(arg, opts = {}, cwd = process.cwd()) {
|
|
|
954
1059
|
const dir = [resolve(cwd, arg), join(cwd, "decks", arg)].find((d) => existsSync(join(d, "index.html")));
|
|
955
1060
|
if (!dir) return { slug: arg, script: undefined };
|
|
956
1061
|
const scriptPath = join(dir, "script.md");
|
|
957
|
-
return { slug:
|
|
1062
|
+
return { slug: deckSlug(dir, opts), script: existsSync(scriptPath) ? readFileSync(scriptPath, "utf8") : undefined };
|
|
958
1063
|
}
|
|
959
1064
|
|
|
960
1065
|
export const EXPORT_USAGE = "usage: export <slug|deck-dir> --pdf [--notes] [--out <file.pdf>] [--share <token>]\n" +
|
|
@@ -1048,8 +1153,11 @@ async function saveTo(file, url) {
|
|
|
1048
1153
|
if (!file || !url) return;
|
|
1049
1154
|
const res = await fetch(url);
|
|
1050
1155
|
if (!res.ok) throw new Error(`download of ${url} failed (${res.status})`);
|
|
1051
|
-
|
|
1052
|
-
|
|
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`);
|
|
1053
1161
|
}
|
|
1054
1162
|
|
|
1055
1163
|
// The command table: "<group> <cmd>" or "<group>" → handler. Exported (via
|
|
@@ -1087,17 +1195,27 @@ function commandTable(pos, rest, opts) {
|
|
|
1087
1195
|
const tagFailed = (tagged) => {
|
|
1088
1196
|
if (tagged.tagError) throw Object.assign(new Error(tagged.tagError), { reported: true });
|
|
1089
1197
|
};
|
|
1198
|
+
// --icons "<set> [weight]": the deck's icon set, recorded and its built-in icons put in it, as icons use does.
|
|
1199
|
+
const iconsWanted = opts.icons ? String(opts.icons).trim().split(/[\s:/,]+/) : null;
|
|
1200
|
+
const iconsAfterNew = async (target, hosted) => {
|
|
1201
|
+
if (!iconsWanted) return;
|
|
1202
|
+
const { iconsUse } = await import("./iconsCli.mjs");
|
|
1203
|
+
await iconsUse([target, ...iconsWanted], { ...opts, hosted }, opts.json ? { log: (line) => console.error(line) } : {});
|
|
1204
|
+
};
|
|
1090
1205
|
if (opts.hosted) {
|
|
1091
1206
|
const { hostedNewDeck } = await import("./source.mjs");
|
|
1207
|
+
const { brandAsked } = await import("./brand.mjs");
|
|
1092
1208
|
if (!opts.narrated) throw new Error("the published CLI scaffolds narrated decks only: add --narrated");
|
|
1093
|
-
const created = await hostedNewDeck(opts, { slug: rest[0], title: rest[1], layouts: opts.layouts, presenterStyle: opts["presenter-style"], brand:
|
|
1209
|
+
const created = await hostedNewDeck(opts, { slug: rest[0], title: rest[1], layouts: opts.layouts, presenterStyle: opts["presenter-style"], brand: brandAsked(opts), theme: opts.theme });
|
|
1210
|
+
await iconsAfterNew(created.slug, true);
|
|
1094
1211
|
const tagged = await tagNew(created.slug);
|
|
1095
1212
|
const out = { ...created, ...tagged };
|
|
1096
|
-
console.log(opts.json ? JSON.stringify(out, null, 2) : `✓ created hosted deck "${out.slug}" (rev ${out.rev})${tagged.tags ? `, tagged ${tagged.tags.join(", ")}` : ""}\n preview: ${out.previewUrl}\n edit locally: hyperdecks source pull ${out.slug}`);
|
|
1213
|
+
console.log(opts.json ? JSON.stringify(out, null, 2) : `✓ created hosted deck "${out.slug}" (rev ${out.rev})${tagged.tags ? `, tagged ${tagged.tags.join(", ")}` : ""}\n theme: ${out.theme}\n brand: ${out.brand.note}\n preview: ${out.previewUrl}\n edit locally: hyperdecks source pull ${out.slug}`);
|
|
1097
1214
|
return tagFailed(tagged);
|
|
1098
1215
|
}
|
|
1099
1216
|
const { deckNew } = await import("./scaffold.mjs");
|
|
1100
1217
|
const created = await deckNew(rest, opts, opts.json ? { log: (line) => console.error(line) } : {});
|
|
1218
|
+
await iconsAfterNew(created.dir, false);
|
|
1101
1219
|
const tagged = await tagNew(created.slug);
|
|
1102
1220
|
if (tagged.tags && !opts.json) console.log(`✓ tagged ${created.slug}: ${tagged.tags.join(", ")}`);
|
|
1103
1221
|
if (opts.json) console.log(JSON.stringify({ ...created, ...tagged }, null, 2));
|
|
@@ -1159,6 +1277,11 @@ function commandTable(pos, rest, opts) {
|
|
|
1159
1277
|
const out = await assetAdd(rest, opts, opts.json ? { log: () => {} } : {});
|
|
1160
1278
|
if (opts.json) console.log(JSON.stringify(out, null, 2));
|
|
1161
1279
|
},
|
|
1280
|
+
"layouts suggest": async () => {
|
|
1281
|
+
const { layoutsSuggest } = await import("./guide.mjs");
|
|
1282
|
+
const out = await layoutsSuggest(rest, opts);
|
|
1283
|
+
if (opts.json) console.log(JSON.stringify(out.suggestions, null, 2));
|
|
1284
|
+
},
|
|
1162
1285
|
guide: async () => {
|
|
1163
1286
|
const { guide } = await import("./guide.mjs");
|
|
1164
1287
|
const out = await guide(pos.slice(1), opts);
|
|
@@ -1279,7 +1402,9 @@ function commandTable(pos, rest, opts) {
|
|
|
1279
1402
|
log(`OK ${out.slug} → ${out.narrator} (voice at its next narrate; face in play and the draft link now, on share links at its next release)`);
|
|
1280
1403
|
// The local file names the face too, so the draft opened from disk shows it.
|
|
1281
1404
|
const { writeDraftFace } = await import("./draftFace.mjs");
|
|
1282
|
-
|
|
1405
|
+
// No --dir: the folder you are in when deck new recorded this slug there, else decks/<slug>.
|
|
1406
|
+
const { recordedSlug } = await import("./deckSlug.mjs");
|
|
1407
|
+
const dir = resolve(typeof opts.dir === "string" ? opts.dir : recordedSlug(process.cwd()) === out.slug ? "." : join("decks", out.slug));
|
|
1283
1408
|
let local = { wrote: false };
|
|
1284
1409
|
try {
|
|
1285
1410
|
local = await writeDraftFace(opts, out.slug, join(dir, "index.html"), { log });
|
|
@@ -1312,6 +1437,7 @@ function commandTable(pos, rest, opts) {
|
|
|
1312
1437
|
"share on": () => shareToggle(rest, opts, true),
|
|
1313
1438
|
"share off": () => shareToggle(rest, opts, false),
|
|
1314
1439
|
"share forward": () => shareForward(rest, opts),
|
|
1440
|
+
"share count": () => shareCount(rest, opts),
|
|
1315
1441
|
"share mute": async () => { if (!rest[0]) throw new Error("usage: share mute <token>"); await ops.setShareNotify(opts, rest[0], false); console.log(`OK muted ${rest[0]}`); },
|
|
1316
1442
|
"share unmute": async () => { if (!rest[0]) throw new Error("usage: share unmute <token>"); await ops.setShareNotify(opts, rest[0], true); console.log(`OK notification preference requested for ${rest[0]} (QA links remain muted)`); },
|
|
1317
1443
|
"share rm": () => shareRm(rest, opts),
|
|
@@ -1329,17 +1455,31 @@ function commandTable(pos, rest, opts) {
|
|
|
1329
1455
|
"gen-video": () => genVideo(pos.slice(1), opts),
|
|
1330
1456
|
"video-job": () => videoJob(pos.slice(1), opts),
|
|
1331
1457
|
screenshot: () => screenshot(pos.slice(1), opts),
|
|
1458
|
+
"photos search": () => photosSearch(rest, opts),
|
|
1459
|
+
"photos add": () => photosAdd(rest, opts),
|
|
1460
|
+
"gifs search": () => gifsSearch(rest, opts),
|
|
1332
1461
|
chart: () => chart(pos.slice(1), opts),
|
|
1333
1462
|
icons: () => icons(pos.slice(1), opts),
|
|
1334
|
-
// The icon library (Lucide); `icons search … --style` still generates.
|
|
1463
|
+
// The icon library (Lucide, Phosphor, Tabler, Material Symbols); `icons search … --style` still generates.
|
|
1335
1464
|
"icons search": async () => {
|
|
1336
1465
|
if (opts.style) return icons(pos.slice(1), opts);
|
|
1337
|
-
if (!rest.length) throw new Error("usage: icons search <word...> [--limit N] [--stroke-width N] [--json]");
|
|
1338
|
-
const { icons: searchIcons } = await import("./
|
|
1466
|
+
if (!rest.length) throw new Error("usage: icons search <word...> [--for <layout>] [--set lucide|phosphor|tabler|material|all] [--weight W] [--deck <dir>] [--limit N] [--stroke-width N] [--json]");
|
|
1467
|
+
const { icons: searchIcons } = await import("./iconsCli.mjs");
|
|
1339
1468
|
const out = await searchIcons(rest, opts);
|
|
1340
1469
|
if (opts.json) console.log(JSON.stringify(out, null, 2));
|
|
1341
1470
|
},
|
|
1471
|
+
"icons sets": async () => {
|
|
1472
|
+
const out = (await import("./iconsCli.mjs")).iconSetsCli(opts);
|
|
1473
|
+
if (opts.json) console.log(JSON.stringify(out, null, 2));
|
|
1474
|
+
},
|
|
1475
|
+
"icons use": async () => {
|
|
1476
|
+
const out = await (await import("./iconsCli.mjs")).iconsUse(rest, opts);
|
|
1477
|
+
if (opts.json) console.log(JSON.stringify(out, null, 2));
|
|
1478
|
+
},
|
|
1342
1479
|
brand: async () => (await import("./brandCli.mjs")).brandShow(opts),
|
|
1480
|
+
theme: async () => (await import("./themeCli.mjs")).themeList(opts),
|
|
1481
|
+
"theme list": async () => (await import("./themeCli.mjs")).themeList(opts),
|
|
1482
|
+
"theme set": async () => (await import("./themeCli.mjs")).themeSet(rest, opts),
|
|
1343
1483
|
"brand show": async () => (await import("./brandCli.mjs")).brandShow(opts),
|
|
1344
1484
|
"brand set": async () => (await import("./brandCli.mjs")).brandSet(opts),
|
|
1345
1485
|
"brand edit": async () => (await import("./brandCli.mjs")).brandEdit(opts),
|
package/src/deckSlug.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A deck folder's slug: --slug, else the one `deck new` recorded in the folder
|
|
2
|
+
// (.hyperdecks.json), else the folder's name. The marker lets a deck live in a
|
|
3
|
+
// folder with any name (deck new --dir) and every command still find it. It is
|
|
4
|
+
// never uploaded: release bundles only index.html and the files it references.
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
|
|
8
|
+
export const DECK_MARKER = ".hyperdecks.json";
|
|
9
|
+
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
10
|
+
|
|
11
|
+
// null only when there is no marker: a marker that can't be read must not fall
|
|
12
|
+
// back to the folder's name, which is the wrong deck by design.
|
|
13
|
+
export function recordedSlug(dir) {
|
|
14
|
+
const path = join(dir, DECK_MARKER);
|
|
15
|
+
if (!existsSync(path)) return null;
|
|
16
|
+
let slug;
|
|
17
|
+
try {
|
|
18
|
+
slug = JSON.parse(readFileSync(path, "utf8"))?.slug;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new Error(`${path} is not a valid deck marker (${e.message}); fix it to {"slug": "<slug>"} or pass --slug`);
|
|
21
|
+
}
|
|
22
|
+
if (typeof slug !== "string" || !SLUG.test(slug)) throw new Error(`${path} names no valid slug; fix it to {"slug": "<slug>"} or pass --slug`);
|
|
23
|
+
return slug;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function deckSlug(dir, opts = {}) {
|
|
27
|
+
if ("slug" in opts && opts.slug !== undefined && (typeof opts.slug !== "string" || !opts.slug)) throw new Error("--slug needs a value");
|
|
28
|
+
return opts.slug || recordedSlug(dir) || basename(dir);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// A line to say before acting, when the slug comes from the marker and is not
|
|
32
|
+
// the folder's name (a copied folder keeps the original's marker), else null.
|
|
33
|
+
export function slugNote(dir, opts = {}) {
|
|
34
|
+
if (opts.slug) return null;
|
|
35
|
+
const slug = recordedSlug(dir);
|
|
36
|
+
return slug && slug !== basename(dir) ? `deck ${slug} (from ${join(dir, DECK_MARKER)}; a copied folder keeps the original's: pass --slug to use another)` : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function recordSlug(dir, slug) {
|
|
40
|
+
writeFileSync(join(dir, DECK_MARKER), JSON.stringify({ slug }, null, 2) + "\n");
|
|
41
|
+
}
|
|
@@ -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";
|