@hypersocial/decks-cli 0.9.29 → 0.9.30

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.
@@ -9,7 +9,7 @@ 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 { ASSET_EXTENSIONS, ASSET_KINDS } from "./assetTypes.mjs";
12
+ import { ASSET_EXTENSIONS, ASSET_KINDS, isScriptType } from "./assetTypes.mjs";
13
13
  import { FLIPPABLE, FRAME, alternativesFor } from "./layoutRoutes.mjs";
14
14
  import { embedSiteHint, resolveEmbed, sharedLinkNote } from "./embedSources.mjs";
15
15
  import { MAX_DECK_GIFS, creditLines, hasGiphyCredit, hasUnsplashCredit, stockRefs, stockSource } from "./stockMedia.mjs";
@@ -41,6 +41,8 @@ export const QUESTION_TOKENS = ["--accent", "--accent-2", "--accent-ink", "--car
41
41
  // cap, capCopy, at its largest; a test checks it).
42
42
  export const LONGEST_ANSWER_MESSAGE = "That’s 4, the most you can pick. Tap one to take it off.";
43
43
 
44
+ // Where a phone-stage side's notes have to fit, by what limits its room (aimed-notes.js `by`).
45
+ const noteRoom = (by = []) => (by.includes("title") && by.includes("presenter") ? "between the title and the presenter" : by.includes("title") ? "under the title" : by.includes("presenter") ? "beside the phone, clear of the presenter" : "beside the phone");
44
46
  export const MESSAGES = {
45
47
  unknownTheme: (name) => `<html data-hd-theme="${name}"> is not a theme: pick one of ${THEME_IDS.join(", ")} (hyperdecks theme set <deck-dir> <name>)`,
46
48
  lowContrast: (ground, ratio) => `text on the ${ground} ground is ${ratio.toFixed(1)}:1, under 4.5:1: change the colours in :root (or the brand's) so it reads`,
@@ -127,14 +129,16 @@ export const MESSAGES = {
127
129
  scriptRef: (ref, from) => `${from} names ${ref}, which is not in the deck folder; add the file or fix the path`,
128
130
  // A hosted deck naming relative files in a script, a data-* attribute or a JSON block: there is no folder to serve them from.
129
131
  // `refs` is one path, or several in one folder rolled up.
130
- hostedScriptRef: (refs, slideIds = [], where = "index.html's script") => `${where} names ${refList(refs)}${slideIds.length ? ` (slide ${slideIds.join(", ")})` : ""}: a hosted deck has no folder, so ${refs.length > 1 ? "each file" : "the file"} must be a URL; ${hostedFileRemedy(refs[0], { many: refs.length > 1 })}`,
132
+ // worker: false, "worker" (a Worker or SharedWorker's script) or "service" (a service worker's).
133
+ hostedScriptRef: (refs, slideIds = [], where = "index.html's script", { worker = false } = {}) => `${where} names ${refList(refs)}${slideIds.length ? ` (slide ${slideIds.join(", ")})` : ""}: a hosted deck has no folder, so ${refs.length > 1 ? "each file" : "the file"} must be a URL; ${hostedFileRemedy(refs[0], { many: refs.length > 1, worker })}`,
131
134
  // Hosted versions of the computed-path warnings: writing the paths out would only trade the warning for the error.
132
135
  scriptTemplateHosted: (samples) => `index.html's script builds file paths at runtime (${samples.slice(0, 3).join(", ")}${samples.length > 3 ? ", …" : ""}); a hosted deck has no folder, so any relative path it builds 404s on the link. Build them from URLs instead (upload ${ASSET_KINDS} with upload_deck_asset)`,
133
136
  scriptComputedHosted: (calls) => `index.html's script loads files from computed values (${calls.join(", ")}); a hosted deck has no folder, so a relative path among them 404s on the link. Make each one a URL (upload ${ASSET_KINDS} with upload_deck_asset)`,
134
137
  // asset add: an uploaded script or stylesheet that names files beside it, which nothing rewrites.
135
- assetRefs: (name, refs) => `${name} names ${refs.slice(0, 5).join(", ")}${refs.length > 5 ? `, and ${refs.length - 5} more` : ""}; asset add uploads one file and changes nothing inside it, so ${refs.length > 1 ? "those paths" : "that path"} won't resolve from its URL: upload each file and put its URL in, or zip the folder for \`hyperdecks import <zip>\`, which rewrites them`,
138
+ // workers: [{ ref, worker }] among refs, whose script must come from the deck's own origin.
139
+ assetRefs: (name, refs, workers = []) => `${name} names ${refs.slice(0, 5).join(", ")}${refs.length > 5 ? `, and ${refs.length - 5} more` : ""}; an upload is one file and nothing inside it is rewritten, so ${refs.length > 1 ? "those paths" : "that path"} won't resolve from its URL: upload each file and put its URL in, or zip the folder for \`hyperdecks import <zip>\`, which rewrites them${workers.map((w) => `. ${w.ref}: ${hostedFileRemedy(w.ref, { cli: true, worker: w.worker })}`).join("")}`,
136
140
  // source push: files the deck loads that stayed in the folder, one folder's worth rolled up.
137
- notPushed: (refs, from) => `not pushed: ${refList(refs)} (${from} loads ${refs.length > 1 ? "them" : "it"}); the hosted draft has no folder, so ${hostedFileRemedy(refs[0], { cli: true, many: refs.length > 1 })}`,
141
+ notPushed: (refs, from, { worker = false } = {}) => `not pushed: ${refList(refs)} (${from} loads ${refs.length > 1 ? "them" : "it"}); the hosted draft has no folder, so ${hostedFileRemedy(refs[0], { cli: true, many: refs.length > 1, worker })}`,
138
142
  // Warnings: deliberate sometimes (a path built from a CDN base), so the deck still passes.
139
143
  scriptTemplate: (from, samples) => `${from} builds file paths at runtime (${samples.slice(0, 3).join(", ")}${samples.length > 3 ? ", …" : ""}); release can't see them, so they 404 on the shared link. Write each file out as a quoted path (an object or array of "media/…" strings, in a script or a .json file it fetches) and pick from that`,
140
144
  scriptComputed: (from, calls) => `${from} loads files from computed values (${calls.join(", ")}); release only ships files the deck names literally, so make sure each file it can load is written out as a quoted path in index.html, a script or a .json file the deck loads`,
@@ -176,6 +180,7 @@ export const MESSAGES = {
176
180
  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)`,
177
181
  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`,
178
182
  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`,
183
+ layoutCount: (id, layout, n, what, max) => `slide ${id}: ${n} ${what} on ${layout}, which holds ${max === 2 ? "exactly 2" : `${max} at most`} (one more runs under the presenter on a 360×640 phone, or off the slide): ${max === 2 ? "keep two" : `cut to ${max}`} or split it over two slides (deck_guide topic layouts, ${layout})`,
179
184
  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)`,
180
185
  // A slide whose items have icons on some only (iconSlots.mjs). An empty slot is never warned about: icons are optional.
181
186
  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)`,
@@ -207,6 +212,18 @@ export const MESSAGES = {
207
212
  barsUnchecked: (why) => `pictures and clips were not checked for bars baked into their files (${why})`,
208
213
  pictureBars: (id, what, drawn, sides, content, cover) => `slide ${id}: the ${what} has bars baked into its file (${drawn}: ${sides}; its content is ${content}), so it shows as a box with gaps beside it; upload the file again with \`hyperdecks asset add <slug> <file> --trim\` (or upload_deck_asset with trim=true for a PNG) and use the new URL${cover ? ", or set object-fit: cover (with object-position) on it so its frame crops them away" : ""} (deck_guide topic look)`,
209
214
  pictureCropped: (id, picture, frame, share, better) => `slide ${id}: the frame (${frame}) crops away ${share}% of the picture (${picture}), so its subject may be lost; ${better} (deck_guide topic look)`,
215
+ titleOverText: (id, title, others, where, fix) => `slide ${id} at ${where}: the title ${title} runs over ${others}; shorten the title, or ${fix}`,
216
+ textOverText: (id, pairs, where, unreadable, fix) => `slide ${id} at ${where}: ${pairs.join("; ")} ${pairs.length > 1 ? "are drawn over each other, pair by pair" : "are drawn over each other"}${unreadable ? ", so neither can be read" : ""}; ${fix}`,
217
+ // phone-stage's aimed notes (aimed-notes.js). `by`: what limits the side's room ('title', 'presenter').
218
+ tooManyNotes: (id, side, fit, notes, where, by = []) => `slide ${id} at ${where}: too many notes on the ${side}: ${fit} of ${notes} fit ${noteRoom(by)}${by.includes("title") ? " (keeping room for the title to run a line longer in another browser)" : ""}; cut ${notes - fit}, shorten them${by.includes("presenter") ? `, set data-presenter-size="s" on this slide` : ""}, or move one to the other side`,
219
+ tooManyBends: (id, side, run, fit, where) => `slide ${id} at ${where}: too many notes on the ${side} point away from where they sit: ${run} lines turn beside each other and only ${fit} can be told apart in the gap to the phone; cut a note, aim them nearer where they sit, or move one to the other side`,
220
+ notesJoined: (id, pairs, where) => `slide ${id} at ${where}: ${pairs.join("; ")}: their lines into the phone run together at one height and read as one; aim them further apart (style="--y: …") or move one to the other side`,
221
+ noteFar: (id, notes, where, many, by = []) => `slide ${id} at ${where}: advice: ${many ? "notes" : "note"} ${notes} ${many ? "sit" : "sits"} far from what ${many ? "they point" : "it points"} at (the line runs over 120px); fine when the line reads, or bring ${many ? "them" : "it"} nearer: ${[by.includes("title") ? "shorten the title" : null, by.includes("presenter") ? `set data-presenter-size="s" on this slide` : null, "cut a note", "move one to the other side"].filter(Boolean).join(", ")}`,
222
+ noteAimUnread: (id, notes, where, many) => `slide ${id} at ${where}: ${many ? "notes" : "note"} ${notes} ${many ? "have" : "has"} a --y the browser cannot read, so ${many ? "they are" : "it is"} not placed; give a percent of the screen's height, such as style="--y: 40%"`,
223
+ noteAimOff: (id, notes, where, many, range) => `slide ${id} at ${where}: ${many ? "notes" : "note"} ${notes} ${many ? "aim" : "aims"} off the phone's straight edge (beyond its rounded corner or off the phone), so ${many ? "their lines are" : "its line is"} held at the edge; give a --y${range ? ` between ${range[0]}% and ${range[1]}%` : " inside the phone"}`,
224
+ notesUnderHead: (id, notes, where, many) => `slide ${id} at ${where}: ${many ? "notes" : "note"} ${notes} ${many ? "sit" : "sits"} under the presenter's head; cut a note or shorten them so the list ends above it`,
225
+ presenterOverText: (id, style, texts, where, fix) => `slide ${id} at ${where}: the ${style} presenter would cover ${texts}; ${fix} (deck_guide topic presenter)`,
226
+ textClipped: (id, texts, where) => `slide ${id} at ${where}: ${texts} ${texts.includes('" and "') || texts.includes('", "') ? "are" : "is"} cut off by the slide's edge or its box; shorten it or give it more room`,
210
227
  overlap: (id, style, stage, fix) => `slide ${id}: the ${style} presenter would overlap the title at ${stage}; ${fix} (deck_guide topic presenter)`,
211
228
  // The word layouts' boxes (wordFitWarnings): text that runs past its box.
212
229
  wordFit: (id, text, where) => `slide ${id}${where}: "${text}" runs past the edge of its box; use a shorter word or fewer words there (the layout's detail gives the lengths that fit) (deck_guide topic layouts)`,
@@ -228,7 +245,7 @@ export const MESSAGES = {
228
245
  phoneOverflow: (id, px) => `slide ${id}: its content runs ${px}px past the slide on a ${PHONE.width}×${PHONE.height} phone; a slide must fit one screen without scrolling, so trim it or tighten its @media (max-width: 650px) rules`,
229
246
  };
230
247
 
231
- export const HOSTED_LAYOUT_WHY = "presenter overlap, phone fit and how each picture fits its frame need a browser: run review_deck with draft=true";
248
+ export const HOSTED_LAYOUT_WHY = "presenter overlap, text that collides (the title or a note over other text, the presenter over text), phone fit and how each picture fits its frame need a browser, and are not measured in chat yet: review_deck with draft=true has a reviewer look at every slide";
232
249
  // The framed player's slide card on a phone (player.css): the screen less the
233
250
  // 60px masthead, the 48px dock and 8px gutters.
234
251
  export const PHONE = { width: 390, height: 844, card: { width: 374, height: 736 } };
@@ -753,18 +770,62 @@ const refList = (refs) => refs.length === 1 ? refs[0] : `${refs.length} files in
753
770
  // How a hosted deck gets a file it names by path: upload it (assetTypes.mjs says
754
771
  // what a deck can carry); anything else (.wasm, a model) has no route into a
755
772
  // hosted draft yet, so say so and name the way that hosts it today.
756
- // A folder (an import map's "lib/") holds modules: each one uploads on its own.
757
- export function hostedFileRemedy(path, { cli = false, many = false } = {}) {
773
+ // Two loads an upload can't satisfy as a plain URL: a folder (an import map's "lib/"),
774
+ // whose files each get an unrelated URL, and a worker's script, which must come from
775
+ // the page's own origin while an upload is served from storage.
776
+ export function hostedFileRemedy(path, { cli = false, many = false, worker = false } = {}) {
758
777
  const ext = extOf(path);
759
778
  const [it, url, its] = many ? ["them", "URLs", "they return"] : ["it", "URL", "it returns"];
760
- if (stripQuery(path).endsWith("/") || UPLOADABLE_EXT.includes(ext)) return cli ? `add ${it} with \`hyperdecks asset add\` and use the ${url} ${its}` : `upload ${it} with upload_deck_asset (\`hyperdecks asset add\` from the CLI) and use the ${url} ${its}`;
779
+ const add = cli ? "`hyperdecks asset add`" : "upload_deck_asset (`hyperdecks asset add` from the CLI)";
780
+ if (stripQuery(path).endsWith("/")) return `a folder can't be uploaded: each file in it gets its own unrelated URL, so upload each module with ${add} and give each one its own import-map entry pointing at its URL`;
781
+ if (worker === "service") return `a service worker can't run in a hosted deck: its script must come from the deck's own origin, and the deck is not served from one it controls; drop the registration`;
782
+ if (worker) return `a worker's script must come from the deck's own origin and an upload is served from storage, so upload ${it} with ${add}, fetch the text from the ${url} ${its} and start the worker from a blob: new Worker(URL.createObjectURL(new Blob([text], { type: "text/javascript" })))`;
783
+ if (UPLOADABLE_EXT.includes(ext)) return cli ? `add ${it} with \`hyperdecks asset add\` and use the ${url} ${its}` : `upload ${it} with upload_deck_asset (\`hyperdecks asset add\` from the CLI) and use the ${url} ${its}`;
761
784
  return `a deck that loads its own ${ext ? `.${ext}` : "extensionless"} files can't be released from source yet (upload_deck_asset takes ${ASSET_KINDS}); today the way is to zip the deck folder and bring it in with \`hyperdecks import <zip>\`, which hosts every file but takes the deck off its source draft, so check and release no longer apply`;
762
785
  }
763
786
 
787
+ // The relative files a stylesheet names (url() and @import), which nothing rewrites in an uploaded .css.
788
+ export function cssFileRefs(css) {
789
+ const refs = [];
790
+ for (const m of String(css).replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)'"\s]+))\s*\)|@import\s+(?:"([^"]*)"|'([^']*)')/gi)) {
791
+ const ref = (m[1] ?? m[2] ?? m[3] ?? m[4] ?? m[5]).trim();
792
+ if (ref && !SCHEME.test(ref) && !ref.startsWith("#") && !ref.startsWith("//")) refs.push(ref);
793
+ }
794
+ return [...new Set(refs)];
795
+ }
796
+
797
+ // The relative files an uploaded script or stylesheet names, by its content type; [] for anything else.
798
+ // A type with parameters ("text/css; charset=utf-8") reads as its bare type.
799
+ export const isCssType = (type) => /^text\/css$/i.test(String(type).split(";")[0].trim());
800
+ export const readsFileRefs = (type) => isCssType(type) || isScriptType(type);
801
+ export function uploadedFileRefs(text, contentType) {
802
+ if (isCssType(contentType)) return cssFileRefs(text);
803
+ if (isScriptType(contentType)) return scriptFileRefs(text);
804
+ return [];
805
+ }
806
+ // What asset add and upload_deck_asset say about an uploaded file's own paths: { refs, warning }
807
+ // for a script or stylesheet that names relative files, else {}. Only a script or stylesheet is decoded.
808
+ export function uploadReport(bytes, contentType, name) {
809
+ if (!readsFileRefs(contentType)) return {};
810
+ const text = new TextDecoder().decode(bytes);
811
+ const refs = uploadedFileRefs(text, contentType);
812
+ return refs.length ? { refs, warning: MESSAGES.assetRefs(name, refs, uploadedWorkerRefs(text, contentType)) } : {};
813
+ }
814
+
815
+ // The worker loads in an uploaded script: { ref, worker: "worker" | "service" } for each.
816
+ export function uploadedWorkerRefs(text, contentType) {
817
+ return isScriptType(contentType) ? scriptLoads(text).filter((l) => l.worker) : [];
818
+ }
819
+
764
820
  // Calls whose first string argument is a file the browser fetches, read from
765
821
  // jsStrings' `code` just before the emptied string; a bare name there ("clip.mp3")
766
822
  // is a file at the deck root.
767
- const LOAD_BEFORE = /(?:\bimport\s*\(|\bimport\s+|\bfrom\s*|(?<![\w$.])fetch\s*\(|\bnew\s+(?:Audio|Worker|SharedWorker)\s*\(|\bimportScripts\s*\(|\.src\s*=)\s*$/;
823
+ const LOAD_BEFORE = /(?:\bimport\s*\(|\bimport\s+|\bfrom\s*|(?<![\w$.])fetch\s*\(|\bnew\s+(?:Audio|Worker|SharedWorker)\s*\(|\bimportScripts\s*\(|\bserviceWorker\s*\.\s*register\s*\(|\.src\s*=)\s*$/;
824
+ // The loads whose script must be same-origin with the page (importScripts inside a worker may be cross-origin).
825
+ // new Worker(new URL("./w.js", import.meta.url)) is the bundlers' form of the same load.
826
+ const WORKER_BEFORE = /\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(?:new\s+URL\s*\(\s*)?$/;
827
+ const SERVICE_WORKER_BEFORE = /\bserviceWorker\s*\.\s*register\s*\(\s*(?:new\s+URL\s*\(\s*)?$/;
828
+ const workerKind = (before) => SERVICE_WORKER_BEFORE.test(before) ? "service" : WORKER_BEFORE.test(before) ? "worker" : false;
768
829
  // new URL('x.wasm', import.meta.url) resolves against the page, so it is a load too; with any other base it is not ours.
769
830
  const URL_BEFORE = /\bnew\s+URL\s*\(\s*$/;
770
831
  const URL_AFTER = /^\s*,\s*(?:import\.meta\.url|location\b|document\.baseURI|window\.location\b)/;
@@ -799,6 +860,12 @@ function slideRanges(doc) {
799
860
  // folder in it, or a bare file name a load call takes); `isMapped` skips import-map names.
800
861
  // asset add reads an uploaded module with it too: those paths don't resolve from the asset's URL.
801
862
  export function scriptFileRefs(src, isMapped = () => false) {
863
+ return [...new Set(scriptLoads(src, isMapped).map((l) => l.ref))];
864
+ }
865
+
866
+ // scriptFileRefs with how each file is loaded: `worker` is "worker" when it starts a Worker or
867
+ // SharedWorker, "service" for a service worker (scripts that must come from the page's own origin), else false.
868
+ export function scriptLoads(src, isMapped = () => false) {
802
869
  const { strings, code } = jsStrings(src);
803
870
  const refs = [];
804
871
  // The k-th emptied string in `code` is strings[k]: walk them to read the code around each.
@@ -812,9 +879,9 @@ export function scriptFileRefs(src, isMapped = () => false) {
812
879
  i++;
813
880
  if (!s || s.interpolated || isMapped(s.value) || !isScriptPath(s.value)) continue;
814
881
  const loaded = LOAD_BEFORE.test(before) || (URL_BEFORE.test(before) && URL_AFTER.test(after));
815
- if (s.value.includes("/") || loaded) refs.push(s.value);
882
+ if (s.value.includes("/") || loaded) refs.push({ ref: s.value, worker: workerKind(before) });
816
883
  }
817
- return [...new Set(refs)];
884
+ return refs;
818
885
  }
819
886
 
820
887
  // A hosted deck's relative files outside its src/href attributes (localRefs has
@@ -832,9 +899,10 @@ export function hostedScriptRefs(html) {
832
899
  const ranges = slideRanges(doc);
833
900
  const slideAt = (i) => ranges.filter((r) => r.start <= i && i < r.end).at(-1)?.id;
834
901
  const found = new Map();
835
- const note = (ref, where, at) => {
902
+ const note = (ref, where, at, worker = false) => {
836
903
  const key = deckPath("", ref) ?? ref;
837
- if (!found.has(key)) found.set(key, { ref, where, slides: new Set() });
904
+ if (!found.has(key)) found.set(key, { ref, where, slides: new Set(), worker });
905
+ if (worker) found.get(key).worker = worker;
838
906
  const id = at === undefined ? undefined : slideAt(at);
839
907
  if (id) found.get(key).slides.add(id);
840
908
  };
@@ -862,7 +930,7 @@ export function hostedScriptRefs(html) {
862
930
  continue;
863
931
  }
864
932
  if (type && !JS_TYPE.test(type)) continue; // text/plain, text/template, ld+json, importmap: not run as script
865
- for (const ref of scriptFileRefs(body, isMapped)) note(ref, "index.html's script", m.index);
933
+ for (const l of scriptLoads(body, isMapped)) note(l.ref, "index.html's script", m.index, l.worker);
866
934
  }
867
935
  // data-* values outside scripts: a path a script reads (new Audio(el.dataset.line)).
868
936
  const markup = doc.replace(/<script\b[\s\S]*?<\/script>/gi, (x) => " ".repeat(x.length));
@@ -877,14 +945,14 @@ export function hostedScriptRefs(html) {
877
945
  // Roll up: more than three files in one folder, named from the same place with the same remedy.
878
946
  const groups = new Map();
879
947
  for (const [key, f] of found) {
880
- const g = `${f.where}\n${dirOf(key)}\n${hostedFileRemedy(f.ref)}`;
948
+ const g = `${f.where}\n${dirOf(key)}\n${hostedFileRemedy(f.ref, { worker: f.worker })}`;
881
949
  if (!groups.has(g)) groups.set(g, []);
882
950
  groups.get(g).push(f);
883
951
  }
884
952
  const order = [...found.values()];
885
953
  return [...groups.values()].flatMap((fs) => fs.length <= 3 ? fs.map((f) => [f]) : [fs])
886
954
  .sort((a, b) => order.indexOf(a[0]) - order.indexOf(b[0])) // first appearance
887
- .map((fs) => ({ refs: fs.map((f) => f.ref), slides: [...new Set(fs.flatMap((f) => [...f.slides]))], where: fs[0].where }));
955
+ .map((fs) => ({ refs: fs.map((f) => f.ref), slides: [...new Set(fs.flatMap((f) => [...f.slides]))], where: fs[0].where, ...(fs[0].worker ? { worker: fs[0].worker } : {}) }));
888
956
  }
889
957
 
890
958
  export function phraseList(value) {
@@ -932,6 +1000,10 @@ const PLACEHOLDERS = [
932
1000
  layout: "l-phones", tag: "div", cls: "shot", what: "each phone screen", img: '<img class="shot" src="…" alt="…"> (or <video class="shot" src="…" autoplay muted loop playsinline>) in each card',
933
1001
  how: { hosted: "capture the app at phone size with capture_url (width 390, height 844), or upload a screen recording with upload_deck_asset", cli: "capture the app at phone size with `hyperdecks screenshot <url> --width 390 --height 844`, or add a screen recording with `hyperdecks asset add`" },
934
1002
  },
1003
+ {
1004
+ layout: "l-pictures", tag: "div", cls: "shot", what: "each picture", img: '<img class="shot" src="…" alt="…"> in each frame (or, for a photo, <img class="pic" src="…" alt="…"> in place of the frame)',
1005
+ how: { hosted: "capture the app at phone size with capture_url (width 390, height 844), or upload the real photos with upload_deck_asset", cli: "capture the app at phone size with `hyperdecks screenshot <url> --width 390 --height 844`, or add the real photos with `hyperdecks asset add`" },
1006
+ },
935
1007
  {
936
1008
  layout: "l-phone-stage", tag: "div", cls: "shot", what: "the phone screen", img: '<img class="shot" src="…" alt="…"> (or <video class="shot" src="…" autoplay muted loop playsinline>)',
937
1009
  how: { hosted: "capture the app at phone size with capture_url (width 390, height 844)", cli: "capture the app at phone size with `hyperdecks screenshot <url> --width 390 --height 844`" },
@@ -1330,7 +1402,7 @@ export const PRESENTER_SCALE = { s: 0.7, m: 1, l: 1.3, xl: 1.6 };
1330
1402
  // split and the word shapes, for the stage presenter (closer for glass too; bubble is smaller than stage, so it fits
1331
1403
  // all). A size on the player tag is not seen by a layout's CSS.
1332
1404
  const WORD_ROOM = ["stage", "bubble"];
1333
- export const ROOMY_LAYOUTS = { "l-closer": ["stage", "glass", "bubble"], "l-split": ["stage", "bubble"], "l-sentence": WORD_ROOM, "l-strike": WORD_ROOM, "l-spotlight": WORD_ROOM, "l-funnel": WORD_ROOM, "l-scorecard": WORD_ROOM, "l-bento": WORD_ROOM, "l-two-by-two": WORD_ROOM, "l-staircase": WORD_ROOM, "l-rail": WORD_ROOM, "l-loop": WORD_ROOM, "l-lanes": WORD_ROOM, "l-two-bars": WORD_ROOM, "l-stack": WORD_ROOM };
1405
+ export const ROOMY_LAYOUTS = { "l-closer": ["stage", "glass", "bubble"], "l-split": ["stage", "bubble"], "l-sentence": WORD_ROOM, "l-strike": WORD_ROOM, "l-spotlight": WORD_ROOM, "l-funnel": WORD_ROOM, "l-scorecard": WORD_ROOM, "l-bento": WORD_ROOM, "l-two-by-two": WORD_ROOM, "l-staircase": WORD_ROOM, "l-rail": WORD_ROOM, "l-loop": WORD_ROOM, "l-lanes": WORD_ROOM, "l-two-bars": WORD_ROOM, "l-stack": WORD_ROOM, "l-compare": WORD_ROOM, "l-statement": WORD_ROOM, "l-pictures": ["stage", "bubble"], "l-scale": WORD_ROOM, "l-sieve": WORD_ROOM };
1334
1406
  // What clears an overlap (measureLayout gives the slide's layout, its own data-presenter-size (`sized`) and the size it plays at).
1335
1407
  function overlapFix(m) {
1336
1408
  const big = m.size === "l" || m.size === "xl";
@@ -1338,7 +1410,7 @@ function overlapFix(m) {
1338
1410
  if (m.steps && m.style === "glass") return `set data-presenter-style="glass" on this slide's <section> (the layout does not see a style set in script.md, and then keeps the bottom-right corner for it), or "stage"`;
1339
1411
  // A deck made before its layout made room keeps its old styles: re-copying them is the step that works.
1340
1412
  if (big && ROOMY_LAYOUTS[m.layout]?.includes(m.style) && m.current === false) return `this deck's ${m.layout.slice(2)} styles predate the room for a large presenter: copy the ${m.layout.slice(2)} layout's <style> block from a new deck (\`hyperdecks deck new <slug> "<title>" --layouts ${m.layout.slice(2)}\`) over this deck's and ${m.sized === m.size ? "keep" : "set"} data-presenter-size="${m.size}" on this slide's <section>, or set a smaller size`;
1341
- const styles = ROOMY_LAYOUTS[m.layout];
1413
+ const styles = m.legacy ? undefined : ROOMY_LAYOUTS[m.layout];
1342
1414
  if (big && styles && m.sized !== m.size) return `set data-presenter-size="${m.size}" on this slide's <section>: ${m.layout.slice(2)} makes room for a size set on the slide, not for the deck's default on the player tag`;
1343
1415
  if (big && styles && !styles.includes(m.style)) return `set data-presenter-style="stage" on this slide (this layout makes room for the stage presenter at l and xl), or a smaller data-presenter-size`;
1344
1416
  const smaller = big ? 'set a smaller size on this slide\'s <section> (data-presenter-size="m", or "s")' : m.size === "s" ? null : 'set data-presenter-size="s" on this slide\'s <section>';
@@ -1352,6 +1424,91 @@ export function overlapWarnings(measured, stage = "1600×900") {
1352
1424
  return measured.filter((m) => hit(m.presenter, m.title) || hit(m.caption, m.title)).map((m) => MESSAGES.overlap(m.id, m.style, stage, overlapFix(m)));
1353
1425
  }
1354
1426
 
1427
+ // Text that collides, from measureLayout's `texts` (each drawn text block: the ink of its lines, whether it is the slide's
1428
+ // title, the blocks it sits inside, whether a line is clipped) and `notes` (phone-stage's aimed notes, per side: how many
1429
+ // and how many fit). Returns { errors, warnings }, one message per slide and kind, naming every pair:
1430
+ // - the title over any other text: an error (the first thing a viewer reads, printed over something else);
1431
+ // - other text over text: an error when the two share more than a third of the smaller one's ink (neither can be read),
1432
+ // else a warning;
1433
+ // - more aimed notes on a side than fit there: an error; a note placed over 120px from its aim, or whose --y does not
1434
+ // resolve (so it is not placed): a warning;
1435
+ // - the presenter over any text but the title (overlapWarnings names the title): a warning;
1436
+ // - a line of text cut off by the slide's edge or a box that hides its overflow: a warning.
1437
+ // Two lines collide when their ink shares more than a fifth of the shorter line's height and 4px across. A block is named
1438
+ // by the outermost block around it (a note, not its <b> label), or by itself when both share that outer block.
1439
+ // The presenter is what it draws (drawnPresenter: a stage head, whose caption steps aside from text, bubble-side.js; a
1440
+ // glass panel; a bubble's face and caption; a corner face and caption), else its footprint and caption. A question slide's presenter is left out (the player places
1441
+ // it around the answers). `where` names the size it was measured at; `presenter: false` (the phone pass, where the
1442
+ // presenter is not this footprint, and a deck with none) leaves the presenter out.
1443
+ // Not covered: text over a picture (coverTextWarnings covers the cover's title only), text a script draws or moves.
1444
+ export function collisionFindings(measured, { where = "1600×900", presenter = true } = {}) {
1445
+ const errors = [], warnings = [];
1446
+ const overlap = (a, b) => Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
1447
+ const meet = (a, b) => {
1448
+ const across = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x);
1449
+ const down = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y);
1450
+ return across > 4 && down > Math.max(4, Math.min(a.height, b.height) / 5);
1451
+ };
1452
+ const area = (lines) => lines.reduce((n, l) => n + l.width * l.height, 0);
1453
+ const quote = (t) => `"${t.text.length > 40 ? `${t.text.slice(0, 40)}…` : t.text}"`;
1454
+ const and = (list) => (list.length > 1 ? `${list.slice(0, -1).join(", ")} and ${list.at(-1)}` : list[0]);
1455
+ for (const m of measured) {
1456
+ const texts = m.texts ?? [];
1457
+ const outer = (i) => [i, ...(texts[i].within ?? [])].reduce((o, k) => ((texts[k].within ?? []).length < (texts[o].within ?? []).length ? k : o));
1458
+ const titled = new Map(), unreadable = [], touching = [];
1459
+ for (let i = 0; i < texts.length; i++) {
1460
+ for (let j = i + 1; j < texts.length; j++) {
1461
+ if (texts[i].within?.includes(j) || texts[j].within?.includes(i)) continue;
1462
+ if (!texts[i].lines.some((la) => texts[j].lines.some((lb) => meet(la, lb)))) continue;
1463
+ const same = outer(i) === outer(j);
1464
+ const [a, b] = same ? [texts[i], texts[j]] : [texts[outer(i)], texts[outer(j)]];
1465
+ if (a.heading && b.heading) continue;
1466
+ const [head, other] = a.heading ? [a, b] : b.heading ? [b, a] : [null, null];
1467
+ if (head) { titled.set(quote(head), [...(titled.get(quote(head)) ?? []), quote(other)]); continue; }
1468
+ const shared = texts[i].lines.reduce((n, la) => n + texts[j].lines.reduce((k, lb) => k + overlap(la, lb), 0), 0);
1469
+ const pair = `${quote(a)} and ${quote(b)}`;
1470
+ (shared > Math.min(area(texts[i].lines), area(texts[j].lines)) / 3 ? unreadable : touching).push(pair);
1471
+ }
1472
+ }
1473
+ const fix = textFix(m);
1474
+ for (const [head, others] of titled) errors.push(MESSAGES.titleOverText(m.id, head, and([...new Set(others)]), where, fix));
1475
+ if (unreadable.length) errors.push(MESSAGES.textOverText(m.id, [...new Set(unreadable)], where, true, fix));
1476
+ if (touching.length) warnings.push(MESSAGES.textOverText(m.id, [...new Set(touching)], where, false, fix));
1477
+ const list = (words) => and(words.map((w) => quote({ text: w })));
1478
+ for (const [side, n] of Object.entries(m.notes ?? {})) {
1479
+ if (n.fit < n.notes) errors.push(MESSAGES.tooManyNotes(m.id, side, n.fit, n.notes, where, n.by));
1480
+ else if (n.crowd) errors.push(MESSAGES.tooManyBends(m.id, side, n.crowd.run, n.crowd.fit, where));
1481
+ else if (n.joined?.length) errors.push(MESSAGES.notesJoined(m.id, n.joined.map(([a, b]) => `notes ${quote({ text: a })} and ${quote({ text: b })}`), where));
1482
+ else if (n.far?.length) warnings.push(MESSAGES.noteFar(m.id, list(n.far), where, n.far.length > 1, n.by));
1483
+ if (n.bad?.length) warnings.push(MESSAGES.noteAimUnread(m.id, list(n.bad), where, n.bad.length > 1));
1484
+ if (n.off?.length) warnings.push(MESSAGES.noteAimOff(m.id, list(n.off), where, n.off.length > 1, n.aims));
1485
+ }
1486
+ // On a phone (the phone pass) the presenter's head stands over the card's bottom corner: notes that run under it.
1487
+ if (m.phoneHead && !m.question) {
1488
+ const under = [...new Set(texts.flatMap((t, i) => (t.note && t.lines.some((l) => meet(m.phoneHead, l)) ? [outer(i)] : [])))].map((k) => texts[k].text);
1489
+ if (under.length) warnings.push(MESSAGES.notesUnderHead(m.id, list(under), where, under.length > 1));
1490
+ }
1491
+ if (presenter && !m.question) {
1492
+ const covered = [...new Set(texts.flatMap((t, i) => (!t.heading && t.lines.some((l) => (m.drawnPresenter ?? [m.presenter, m.caption]).some((p) => p && meet(p, l))) ? [outer(i)] : [])))].map((k) => texts[k]).filter((t) => !t.heading);
1493
+ if (covered.length) warnings.push(MESSAGES.presenterOverText(m.id, m.style, and(covered.map(quote)), where, presenterTextFix(m)));
1494
+ }
1495
+ const clipped = [...new Set(texts.flatMap((x, i) => (x.clipped ? [outer(i)] : [])))].map((k) => quote(texts[k]));
1496
+ if (clipped.length) warnings.push(MESSAGES.textClipped(m.id, and(clipped), where));
1497
+ }
1498
+ return { errors: [...new Set(errors)], warnings: [...new Set(warnings)] };
1499
+ }
1500
+ // What clears text from text: on phone-stage, the notes' --y and the layout's own placing.
1501
+ function textFix(m) {
1502
+ return m.layout === "l-phone-stage"
1503
+ ? "aim the notes further apart (style=\"--y: …\"), cut one, or copy phone-stage's <style> block from a new deck (`hyperdecks deck new <slug> \"<title>\" --layouts phone-stage`), whose notes the player keeps clear of the title and each other"
1504
+ : "move one or shorten it";
1505
+ }
1506
+ // What clears text from under the presenter: phone-stage's notes are placed clear of it in a new deck's styles.
1507
+ function presenterTextFix(m) {
1508
+ if (m.layout === "l-phone-stage") return 'copy phone-stage\'s <style> block from a new deck (`hyperdecks deck new <slug> "<title>" --layouts phone-stage`), whose notes the player keeps clear of the presenter, or aim a right-hand note higher (style="--y: …" under about 40%)';
1509
+ return `move it out of the presenter's corner, ${m.size === "s" ? "" : 'set data-presenter-size="s" on this slide\'s <section>, '}or use a layout that keeps the corner free`;
1510
+ }
1511
+
1355
1512
  // Covers whose rendered title lands on their picture, as warnings. Each entry: { id, onPicture }
1356
1513
  // (measureLayout sets onPicture on the first slide and on any slide with a cover layout).
1357
1514
  export function coverTextWarnings(measured) {
@@ -1363,7 +1520,8 @@ export function coverTextWarnings(measured) {
1363
1520
  export const FIT_BOXES = {
1364
1521
  "l-spotlight": ".row > li", "l-funnel": ".stages > li", "l-scorecard": ".rows > li, .rows .state", "l-bento": ".tiles > *",
1365
1522
  "l-two-by-two": ".q b", "l-staircase": ".steps > li", "l-rail": ".track > li", "l-loop": ".ring li", "l-lanes": ".lanes .chip, .lanes .who",
1366
- "l-two-bars": ".bars > li", "l-stack": ".layers > li",
1523
+ "l-two-bars": ".bars > li", "l-stack": ".layers > li", "l-compare": ".rows > li", "l-statement": ".notes p", "l-scale": ".tags > li", "l-sieve": ".list > li",
1524
+ "l-pictures": "figcaption",
1367
1525
  };
1368
1526
  // The rows of boxes that widen to their longest word (min-content tracks): the row must still fit its column.
1369
1527
  export const FIT_ROWS = { "l-staircase": ".steps", "l-rail": ".track", "l-lanes": ".lanes" };
@@ -1375,9 +1533,9 @@ export function wordFitWarnings(measured, { phone = false } = {}) {
1375
1533
  }
1376
1534
 
1377
1535
  // The layouts whose title is the whole statement and shows in full on a phone (no data-title-mobile needed).
1378
- export const FULL_TITLE_LAYOUTS = /(?:^|\s)l-(?:sentence|strike)(?:\s|$)/;
1536
+ export const FULL_TITLE_LAYOUTS = /(?:^|\s)l-(?:sentence|strike|statement)(?:\s|$)/;
1379
1537
  // The word layouts' parts that sit beside the presenter (measureLayout's media.words; their title is measured as every slide's).
1380
- export const WORD_PARTS = { "l-strike": ".old", "l-spotlight": ".row > li", "l-funnel": ".stages > li", "l-scorecard": ".rows > li", "l-bento": ".tiles > *", "l-two-by-two": ".plane", "l-staircase": ".steps > li", "l-rail": ".track > li", "l-loop": ".ring li", "l-lanes": ".lanes", "l-two-bars": ".bars > li", "l-stack": ".layers > li" };
1538
+ export const WORD_PARTS = { "l-strike": ".old", "l-spotlight": ".row > li", "l-funnel": ".stages > li", "l-scorecard": ".rows > li", "l-bento": ".tiles > *", "l-two-by-two": ".plane", "l-staircase": ".steps > li", "l-rail": ".track > li", "l-loop": ".ring li", "l-lanes": ".lanes", "l-two-bars": ".bars > li", "l-stack": ".layers > li", "l-compare": ".table", "l-statement": ".notes", "l-pictures": ".shots", "l-scale": ".rule", "l-sieve": ".list > li" };
1381
1539
  // The media layouts whose presenter must keep off what they show (measureLayout's `media`: boxes by role).
1382
1540
  // zoom: the full screenshot, the lens and its label; video-full: the recording as drawn; picture-full: the presenter stays
1383
1541
  // in the panel's column (the picture's subject is in the right two-thirds).
@@ -1415,7 +1573,7 @@ function stepsWhat(m) {
1415
1573
  }
1416
1574
  // The word layouts make room for an l or xl presenter set on the slide's own <section>, as closer and split do.
1417
1575
  function wordsFix(m, role = "words") {
1418
- const name = m.layout.slice(2), big = m.size === "l" || m.size === "xl";
1576
+ const name = m.layout.slice(2), big = !m.legacy && (m.size === "l" || m.size === "xl");
1419
1577
  if (big && m.current === false) return `this deck's ${name} styles predate the room for a large presenter: copy the ${name} layout's <style> block from a new deck (\`hyperdecks deck new <slug> "<title>" --layouts ${name}\`) over this deck's, or set a smaller size`;
1420
1578
  if (big && m.sized !== m.size) return `set data-presenter-size="${m.size}" on this slide's <section>: ${name} makes room for a size set on the slide, not for the deck's default on the player tag`;
1421
1579
  if (role === "lead") return leadFix(m);
@@ -1839,6 +1997,32 @@ function otherShapes(alts) {
1839
1997
  // closer are not content), and three or more content slides in a row of one layout. A slide with no l-<name> class is
1840
1998
  // counted as content but never as a repeat. Each names the slides and offers two other shapes for each, from
1841
1999
  // what the slide's title says first, then from the table's rows its layout sits in.
2000
+ // The layouts whose guide names a count (its needs line): what fits from a 360×640 phone up, with the presenter's foot
2001
+ // clear, and on a desktop. A container is matched by its class; its <li> (or the slide's <figure>) counted. An old
2002
+ // two-box compare slide (.cols) has no .rows, so it is never counted.
2003
+ const LAYOUT_COUNTS = {
2004
+ compare: { container: "rows", what: "rows", max: 3 },
2005
+ sieve: { container: "list", what: "lines", max: 6 },
2006
+ scale: { container: "tags", what: "items", max: 5 },
2007
+ pictures: { figures: true, what: "pictures", max: 2, exact: true },
2008
+ };
2009
+ export function layoutCountWarnings(all) {
2010
+ const out = [];
2011
+ for (const s of all) {
2012
+ const layout = layoutOf(s), rule = layout && LAYOUT_COUNTS[layout];
2013
+ if (!rule) continue;
2014
+ let n;
2015
+ if (rule.figures) n = (s.body.match(/<figure\b/g) ?? []).length;
2016
+ else {
2017
+ const list = new RegExp(`<(ul|ol)\\b[^>]*\\sclass=["'][^"']*\\b${rule.container}\\b[^"']*["'][^>]*>([\\s\\S]*?)<\\/\\1>`).exec(s.body);
2018
+ if (!list) continue;
2019
+ n = (list[2].match(/<li\b/g) ?? []).length;
2020
+ }
2021
+ if (rule.exact ? n !== rule.max : n > rule.max) out.push(MESSAGES.layoutCount(s.id || "a slide with no id", layout, n, rule.what, rule.max));
2022
+ }
2023
+ return out;
2024
+ }
2025
+
1842
2026
  export function varietyWarnings(all) {
1843
2027
  if (all.length < 5) return [];
1844
2028
  const content = all.map((s) => ({ s, layout: layoutOf(s) })).filter(({ layout }) => !FRAME.has(layout));
@@ -1920,7 +2104,7 @@ export function lookWarnings(html) {
1920
2104
  const choice = deckIconChoice(html);
1921
2105
  if (choice?.problem) out.push(MESSAGES.iconChoice(choice.problem));
1922
2106
  if (sets.size > 1) out.push(MESSAGES.mixedIcons([...sets].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))));
1923
- out.push(...varietyWarnings(all), ...flipWarnings(all));
2107
+ out.push(...varietyWarnings(all), ...flipWarnings(all), ...layoutCountWarnings(all));
1924
2108
  out.push(...textureWarnings(all, html), ...coverFadeWarnings(html));
1925
2109
  out.push(...embedWarnings(all), ...questionWarnings(all));
1926
2110
  return out;
@@ -2082,10 +2266,10 @@ const RETIRED_TEXTURES = {
2082
2266
  };
2083
2267
  const SIGNATURES = ["bg-corner", "bg-mark"];
2084
2268
  export const MAX_SIGNATURE_SLIDES = 3;
2085
- const BUSY_LAYOUTS = ["l-number", "l-features", "l-team", "l-timeline", "l-compare"]; // full-width content: nothing to back
2269
+ const BUSY_LAYOUTS = ["l-number", "l-features", "l-team", "l-timeline", "l-compare", "l-sieve"]; // full-width content: nothing to back
2086
2270
  // The media layouts: the picture or recording is the slide's object and fills its column; no texture backs it.
2087
- 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"];
2088
- 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
2271
+ const MEDIA_LAYOUTS = ["l-pictures", "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"];
2272
+ 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", "l-statement", "l-scale"]; // the word shapes: their words run beside the presenter, nothing to back
2089
2273
  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
2090
2274
  const QUESTION_LAYOUTS = ["l-question-choice", "l-question-text"];
2091
2275
  export const TEXTURE_OFF = {
@@ -2256,7 +2440,7 @@ export async function checkSources({ html, script = "" }, opts = {}, { fetch: fe
2256
2440
  const inAttrs = new Set(localRefs(html).map((r) => deckPath("", r) ?? r));
2257
2441
  for (const r of hostedScriptRefs(html)) {
2258
2442
  const refs = r.refs.filter((ref) => !inAttrs.has(deckPath("", ref) ?? ref));
2259
- if (refs.length) errors.push(MESSAGES.hostedScriptRef(refs, r.slides, r.where));
2443
+ if (refs.length) errors.push(MESSAGES.hostedScriptRef(refs, r.slides, r.where, { worker: r.worker }));
2260
2444
  }
2261
2445
  }
2262
2446
  const ids = slides(html).map((s) => s.id);