@hypersocial/decks-cli 0.9.28 → 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.
- package/README.md +29 -11
- package/package.json +1 -1
- package/skills/hyperdecks/SKILL.md +81 -23
- package/skills/hyperdecks/terminal.md +1 -1
- package/src/aimedNotes.mjs +165 -0
- package/src/assetTypes.mjs +65 -0
- package/src/check.mjs +156 -12
- package/src/checkRules.mjs +367 -18
- package/src/commands.mjs +166 -20
- package/src/embedSources.mjs +15 -1
- package/src/files.mjs +4 -0
- package/src/guide.mjs +1 -1
- package/src/iconSlots.mjs +1 -1
- package/src/importer.mjs +61 -57
- package/src/init.mjs +14 -2
- package/src/layoutRoutes.mjs +7 -4
- package/src/layouts.mjs +2 -2
- package/src/notices.mjs +145 -0
- package/src/ops.mjs +1 -1
- package/src/runtime.mjs +20 -3
- package/src/skillFreshness.mjs +46 -13
- package/src/source.mjs +57 -9
- package/src/update.mjs +93 -30
- package/templates/layouts/_deck.html +3 -3
- package/templates/layouts/compare.html +50 -25
- package/templates/layouts/features.html +11 -1
- package/templates/layouts/phone-stage.html +20 -4
- package/templates/layouts/pictures.html +86 -0
- package/templates/layouts/scale.html +69 -0
- package/templates/layouts/screens.html +5 -0
- package/templates/layouts/sieve.html +62 -0
- package/templates/layouts/split.html +6 -0
- package/templates/layouts/statement.html +58 -0
- package/templates/layouts/tap-through.html +3 -3
- package/templates/layouts/video-beats.html +1 -1
package/src/checkRules.mjs
CHANGED
|
@@ -9,6 +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, isScriptType } from "./assetTypes.mjs";
|
|
12
13
|
import { FLIPPABLE, FRAME, alternativesFor } from "./layoutRoutes.mjs";
|
|
13
14
|
import { embedSiteHint, resolveEmbed, sharedLinkNote } from "./embedSources.mjs";
|
|
14
15
|
import { MAX_DECK_GIFS, creditLines, hasGiphyCredit, hasUnsplashCredit, stockRefs, stockSource } from "./stockMedia.mjs";
|
|
@@ -40,6 +41,8 @@ export const QUESTION_TOKENS = ["--accent", "--accent-2", "--accent-ink", "--car
|
|
|
40
41
|
// cap, capCopy, at its largest; a test checks it).
|
|
41
42
|
export const LONGEST_ANSWER_MESSAGE = "That’s 4, the most you can pick. Tap one to take it off.";
|
|
42
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");
|
|
43
46
|
export const MESSAGES = {
|
|
44
47
|
unknownTheme: (name) => `<html data-hd-theme="${name}"> is not a theme: pick one of ${THEME_IDS.join(", ")} (hyperdecks theme set <deck-dir> <name>)`,
|
|
45
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`,
|
|
@@ -100,8 +103,8 @@ export const MESSAGES = {
|
|
|
100
103
|
stepNested: (id) => `slide ${id}: a data-step inside a data-steps container's child; the container already steps its children, so the two fight: put data-step on the children themselves, or take data-steps off`,
|
|
101
104
|
stepQuestion: (id) => `slide ${id}: a question slide has steps (data-step or data-steps); its answers must all show: take them off`,
|
|
102
105
|
stepCues: (id) => `slide ${id}: it has [reveal] cues in script.md and steps in its HTML (data-step or data-steps); the narration steps by its cues and never hides the HTML steps, and presenting in person uses the HTML steps only when the cues make one part: keep one`,
|
|
103
|
-
stepInside: (id) => `slide ${id}: a step sits inside a step with a higher number, so it cannot show before its box does (
|
|
104
|
-
stepReveal: (id) => `slide ${id}: a step also has class "reveal", which only a narration's [reveal] cue shows, so it stays invisible for ever: take class "reveal" off it`,
|
|
106
|
+
stepInside: (id) => `slide ${id}: a step sits inside a step with a higher number, so it cannot show before its box does (the player shows it with its box, at the higher number): give the inner one the same or a higher number, or move it out`,
|
|
107
|
+
stepReveal: (id) => `slide ${id}: a step also has class "reveal", which only a narration's [reveal] cue shows, so it stays invisible for ever (the player gives it no step): take class "reveal" off it`,
|
|
105
108
|
stepOnSlide: (id) => `slide ${id}: data-step or data-steps on the <section> itself does nothing; put it on the elements (data-step) or the container of the items (data-steps)`,
|
|
106
109
|
questionMany: (n) => `${n} questions (a batch's items each count): a deck stores answers to its first 20 only`,
|
|
107
110
|
// Warnings: a deck that declared it has no narration.
|
|
@@ -122,8 +125,20 @@ export const MESSAGES = {
|
|
|
122
125
|
captionLength: (id, i, text) => `clip ${id}: caption ${i + 1} is ${text.length} characters ("${text}"); captions must be ${CAPTION_MIN_CHARS} to ${CAPTION_MAX_CHARS}`,
|
|
123
126
|
localRef: (ref) => `local reference does not resolve: ${ref}`,
|
|
124
127
|
outsideRef: (ref) => `local reference leaves the deck folder: ${ref}`,
|
|
125
|
-
hostedRef: (ref) => `local reference ${ref}: a hosted deck has no folder, so every file must be a URL;
|
|
128
|
+
hostedRef: (ref) => `local reference ${ref}: a hosted deck has no folder, so every file must be a URL; ${hostedFileRemedy(ref)}`,
|
|
126
129
|
scriptRef: (ref, from) => `${from} names ${ref}, which is not in the deck folder; add the file or fix the path`,
|
|
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.
|
|
131
|
+
// `refs` is one path, or several in one folder rolled up.
|
|
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 })}`,
|
|
134
|
+
// Hosted versions of the computed-path warnings: writing the paths out would only trade the warning for the error.
|
|
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)`,
|
|
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)`,
|
|
137
|
+
// asset add: an uploaded script or stylesheet that names files beside it, which nothing rewrites.
|
|
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("")}`,
|
|
140
|
+
// source push: files the deck loads that stayed in the folder, one folder's worth rolled up.
|
|
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 })}`,
|
|
127
142
|
// Warnings: deliberate sometimes (a path built from a CDN base), so the deck still passes.
|
|
128
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`,
|
|
129
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`,
|
|
@@ -165,6 +180,7 @@ export const MESSAGES = {
|
|
|
165
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)`,
|
|
166
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`,
|
|
167
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})`,
|
|
168
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)`,
|
|
169
185
|
// A slide whose items have icons on some only (iconSlots.mjs). An empty slot is never warned about: icons are optional.
|
|
170
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)`,
|
|
@@ -196,6 +212,18 @@ export const MESSAGES = {
|
|
|
196
212
|
barsUnchecked: (why) => `pictures and clips were not checked for bars baked into their files (${why})`,
|
|
197
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)`,
|
|
198
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`,
|
|
199
227
|
overlap: (id, style, stage, fix) => `slide ${id}: the ${style} presenter would overlap the title at ${stage}; ${fix} (deck_guide topic presenter)`,
|
|
200
228
|
// The word layouts' boxes (wordFitWarnings): text that runs past its box.
|
|
201
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)`,
|
|
@@ -217,7 +245,7 @@ export const MESSAGES = {
|
|
|
217
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`,
|
|
218
246
|
};
|
|
219
247
|
|
|
220
|
-
export const HOSTED_LAYOUT_WHY = "presenter overlap, phone fit and how each picture fits its frame need a browser:
|
|
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";
|
|
221
249
|
// The framed player's slide card on a phone (player.css): the screen less the
|
|
222
250
|
// 60px masthead, the 48px dock and 8px gutters.
|
|
223
251
|
export const PHONE = { width: 390, height: 844, card: { width: 374, height: 736 } };
|
|
@@ -437,8 +465,9 @@ export const normalizeWords = (text) => text.normalize("NFKD").replace(/\p{Diacr
|
|
|
437
465
|
|
|
438
466
|
// `<section class="slide …">` blocks in document order: id, the opening tag, the
|
|
439
467
|
// title (first <h1>/<h2>) and its opening tag.
|
|
468
|
+
const SLIDE_SECTION = /(<section\b[^>]*\sclass="(?:[^"]*\s)?slide(?:\s[^"]*)?"[^>]*>)([\s\S]*?)<\/section>/g;
|
|
440
469
|
export function slides(html) {
|
|
441
|
-
return [...uncommented(html).matchAll(
|
|
470
|
+
return [...uncommented(html).matchAll(SLIDE_SECTION)].map(([, tag, body]) => {
|
|
442
471
|
const heading = /(<h[12]\b[^>]*>)([\s\S]*?)<\/h[12]>/.exec(body);
|
|
443
472
|
return { id: attr(tag, "id") ?? "", tag, body, title: heading ? textOf(heading[2]) : "", titleTag: heading?.[1] ?? "" };
|
|
444
473
|
});
|
|
@@ -539,7 +568,9 @@ export function stepWarnings(html, script = "") {
|
|
|
539
568
|
if (got.some((n, i) => n !== i + 1)) out.push(MESSAGES.stepGap(s.id, got.join(", "), got.map((_, i) => i + 1).join(", ")));
|
|
540
569
|
if (steps.some((e) => boxes.some((b) => inside(b, e) && !childOf(b, e)))) out.push(MESSAGES.stepNested(s.id));
|
|
541
570
|
if (numbered.some((x) => numbered.some((y) => y.n > x.n && inside(y.e, x.e)))) out.push(MESSAGES.stepInside(s.id));
|
|
542
|
-
|
|
571
|
+
// A tap-through box ([data-hd-steps]) shows its .reveal items on a tap, so a step there does show.
|
|
572
|
+
const tapBox = (e) => hasAttr(e.tag, "data-hd-steps") || els.some((b) => hasAttr(b.tag, "data-hd-steps") && inside(b, e));
|
|
573
|
+
if (!cued.has(s.id) && numbered.some((x) => classes(x.e.tag).includes("reveal") && !tapBox(x.e))) out.push(MESSAGES.stepReveal(s.id));
|
|
543
574
|
}
|
|
544
575
|
return out;
|
|
545
576
|
}
|
|
@@ -731,6 +762,199 @@ export function deckFiles(html, { pathExists: exists = () => false, read, isDir
|
|
|
731
762
|
return { files: [...files].map(([path, from]) => ({ path, from })), missing, templates, computed };
|
|
732
763
|
}
|
|
733
764
|
|
|
765
|
+
// What a hosted deck can upload (assetTypes.mjs: the table asset add, upload_deck_asset and import share).
|
|
766
|
+
export const UPLOADABLE_EXT = ASSET_EXTENSIONS;
|
|
767
|
+
const extOf = (path) => /\.([a-z0-9]+)$/i.exec(stripQuery(path))?.[1]?.toLowerCase() ?? "";
|
|
768
|
+
const refList = (refs) => refs.length === 1 ? refs[0] : `${refs.length} files in ${dirOf(deckPath("", refs[0]) ?? refs[0]) || "the deck root"} (${refs.slice(0, 2).join(", ")}, …)`;
|
|
769
|
+
|
|
770
|
+
// How a hosted deck gets a file it names by path: upload it (assetTypes.mjs says
|
|
771
|
+
// what a deck can carry); anything else (.wasm, a model) has no route into a
|
|
772
|
+
// hosted draft yet, so say so and name the way that hosts it today.
|
|
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 } = {}) {
|
|
777
|
+
const ext = extOf(path);
|
|
778
|
+
const [it, url, its] = many ? ["them", "URLs", "they return"] : ["it", "URL", "it returns"];
|
|
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}`;
|
|
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`;
|
|
785
|
+
}
|
|
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
|
+
|
|
820
|
+
// Calls whose first string argument is a file the browser fetches, read from
|
|
821
|
+
// jsStrings' `code` just before the emptied string; a bare name there ("clip.mp3")
|
|
822
|
+
// is a file at the deck root.
|
|
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;
|
|
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.
|
|
830
|
+
const URL_BEFORE = /\bnew\s+URL\s*\(\s*$/;
|
|
831
|
+
const URL_AFTER = /^\s*,\s*(?:import\.meta\.url|location\b|document\.baseURI|window\.location\b)/;
|
|
832
|
+
// Run as script: plain JS and modules, and what a shim runs (Babel's text/babel and text/jsx, es-module-shims' module-shim).
|
|
833
|
+
const JS_TYPE = /^(?:module|module-shim|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:babel|jsx))$/i;
|
|
834
|
+
// data-* the player shows as words (player.js: data-note's source line, data-title-mobile's phone title;
|
|
835
|
+
// data-hd-tip's tooltip; embed-frame.js: data-embed-label), so a path in them is text, not a file.
|
|
836
|
+
const TEXT_DATA = new Set(["data-note", "data-title-mobile", "data-hd-tip", "data-embed-label"]);
|
|
837
|
+
const JSON_TYPE_ATTR = /^(?:application|text)\/json$/i;
|
|
838
|
+
|
|
839
|
+
// Each slide's section as offsets into `doc`, nested <section>s counted so an
|
|
840
|
+
// inner one doesn't end the slide.
|
|
841
|
+
function slideRanges(doc) {
|
|
842
|
+
const out = [];
|
|
843
|
+
const open = /<section\b[^>]*\sclass\s*=\s*(?:"(?:[^"]*\s)?slide(?:\s[^"]*)?"|'(?:[^']*\s)?slide(?:\s[^']*)?')[^>]*>/gi;
|
|
844
|
+
for (const m of doc.matchAll(open)) {
|
|
845
|
+
if (out.some((r) => m.index > r.start && m.index < r.end)) continue;
|
|
846
|
+
const tags = /<(\/?)section\b[^>]*>/gi;
|
|
847
|
+
tags.lastIndex = m.index + m[0].length;
|
|
848
|
+
let depth = 1;
|
|
849
|
+
let end = doc.length;
|
|
850
|
+
for (let t; depth && (t = tags.exec(doc));) {
|
|
851
|
+
depth += t[1] ? -1 : 1;
|
|
852
|
+
if (!depth) end = t.index + t[0].length;
|
|
853
|
+
}
|
|
854
|
+
out.push({ id: attr(m[0], "id") ?? "", start: m.index, end });
|
|
855
|
+
}
|
|
856
|
+
return out;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// The relative files a script names, by hostedScriptRefs' rule (a path with a
|
|
860
|
+
// folder in it, or a bare file name a load call takes); `isMapped` skips import-map names.
|
|
861
|
+
// asset add reads an uploaded module with it too: those paths don't resolve from the asset's URL.
|
|
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) {
|
|
869
|
+
const { strings, code } = jsStrings(src);
|
|
870
|
+
const refs = [];
|
|
871
|
+
// The k-th emptied string in `code` is strings[k]: walk them to read the code around each.
|
|
872
|
+
let k = 0;
|
|
873
|
+
for (let i = 0; i < code.length; i++) {
|
|
874
|
+
const c = code[i];
|
|
875
|
+
if (c !== '"' && c !== "'" && c !== "`") continue;
|
|
876
|
+
const s = strings[k++];
|
|
877
|
+
const before = code.slice(Math.max(0, i - 80), i);
|
|
878
|
+
const after = code.slice(i + 2, i + 80);
|
|
879
|
+
i++;
|
|
880
|
+
if (!s || s.interpolated || isMapped(s.value) || !isScriptPath(s.value)) continue;
|
|
881
|
+
const loaded = LOAD_BEFORE.test(before) || (URL_BEFORE.test(before) && URL_AFTER.test(after));
|
|
882
|
+
if (s.value.includes("/") || loaded) refs.push({ ref: s.value, worker: workerKind(before) });
|
|
883
|
+
}
|
|
884
|
+
return refs;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// A hosted deck's relative files outside its src/href attributes (localRefs has
|
|
888
|
+
// those): paths quoted in inline scripts, data-* attribute values and JSON
|
|
889
|
+
// blocks. A hosted deck has no folder, so each one 404s on the link. A quoted
|
|
890
|
+
// string counts when it starts with ./, ../ or /, has a folder in it, or is a
|
|
891
|
+
// bare file name passed to a load call (import, fetch, new Audio/Worker/URL,
|
|
892
|
+
// importScripts, .src =); any other bare string ("worker.js") could be anything
|
|
893
|
+
// and stays quiet. Import-map names are skipped and their relative targets
|
|
894
|
+
// counted. Built and computed paths get scriptTemplateHosted/scriptComputedHosted.
|
|
895
|
+
// Returns [{ refs, slides, where }]: each normalised path once, and more than
|
|
896
|
+
// three in one folder from the same place rolled into one entry.
|
|
897
|
+
export function hostedScriptRefs(html) {
|
|
898
|
+
const doc = uncommented(html);
|
|
899
|
+
const ranges = slideRanges(doc);
|
|
900
|
+
const slideAt = (i) => ranges.filter((r) => r.start <= i && i < r.end).at(-1)?.id;
|
|
901
|
+
const found = new Map();
|
|
902
|
+
const note = (ref, where, at, worker = false) => {
|
|
903
|
+
const key = deckPath("", ref) ?? ref;
|
|
904
|
+
if (!found.has(key)) found.set(key, { ref, where, slides: new Set(), worker });
|
|
905
|
+
if (worker) found.get(key).worker = worker;
|
|
906
|
+
const id = at === undefined ? undefined : slideAt(at);
|
|
907
|
+
if (id) found.get(key).slides.add(id);
|
|
908
|
+
};
|
|
909
|
+
const pathy = (v) => isScriptPath(v) && v.includes("/"); // ./, ../ and / prefixes included
|
|
910
|
+
const scripts = [...doc.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
|
|
911
|
+
const typeOf = (attrs) => (attr(attrs, "type") ?? "").trim();
|
|
912
|
+
const mapped = [];
|
|
913
|
+
for (const m of scripts.filter(([, attrs]) => /^importmap$/i.test(typeOf(attrs)))) {
|
|
914
|
+
let map;
|
|
915
|
+
try { map = JSON.parse(m[2]); } catch { continue; }
|
|
916
|
+
for (const table of [map?.imports, ...Object.values(map?.scopes ?? {})]) {
|
|
917
|
+
for (const [k, v] of Object.entries(table ?? {})) {
|
|
918
|
+
mapped.push(k);
|
|
919
|
+
if (typeof v === "string" && !SCHEME.test(v) && (isScriptPath(v) || /^\.{0,2}\//.test(v))) note(v, "index.html's import map", m.index);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const isMapped = (ref) => mapped.some((k) => k === ref || (k.endsWith("/") && ref.startsWith(k)));
|
|
924
|
+
for (const m of scripts) {
|
|
925
|
+
const [, attrs, body] = m;
|
|
926
|
+
if (/\ssrc\s*=/i.test(attrs)) continue;
|
|
927
|
+
const type = typeOf(attrs);
|
|
928
|
+
if (JSON_TYPE_ATTR.test(type)) {
|
|
929
|
+
for (const s of jsStrings(body).strings) if (pathy(s.value)) note(s.value, "index.html's JSON block", m.index);
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
if (type && !JS_TYPE.test(type)) continue; // text/plain, text/template, ld+json, importmap: not run as script
|
|
933
|
+
for (const l of scriptLoads(body, isMapped)) note(l.ref, "index.html's script", m.index, l.worker);
|
|
934
|
+
}
|
|
935
|
+
// data-* values outside scripts: a path a script reads (new Audio(el.dataset.line)).
|
|
936
|
+
const markup = doc.replace(/<script\b[\s\S]*?<\/script>/gi, (x) => " ".repeat(x.length));
|
|
937
|
+
for (const m of markup.matchAll(/<[a-z][\w-]*\b[^>]*>/gi)) {
|
|
938
|
+
for (const a of m[0].matchAll(/\s(data-[\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) {
|
|
939
|
+
const value = decode(a[2] ?? a[3]).trim();
|
|
940
|
+
if (TEXT_DATA.has(a[1].toLowerCase())) continue;
|
|
941
|
+
if (pathy(value)) note(value, `index.html's ${a[1]}`, m.index);
|
|
942
|
+
else if (found.has(deckPath("", value) ?? value)) note(value, "", m.index); // a script's path, carried by this slide too
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
// Roll up: more than three files in one folder, named from the same place with the same remedy.
|
|
946
|
+
const groups = new Map();
|
|
947
|
+
for (const [key, f] of found) {
|
|
948
|
+
const g = `${f.where}\n${dirOf(key)}\n${hostedFileRemedy(f.ref, { worker: f.worker })}`;
|
|
949
|
+
if (!groups.has(g)) groups.set(g, []);
|
|
950
|
+
groups.get(g).push(f);
|
|
951
|
+
}
|
|
952
|
+
const order = [...found.values()];
|
|
953
|
+
return [...groups.values()].flatMap((fs) => fs.length <= 3 ? fs.map((f) => [f]) : [fs])
|
|
954
|
+
.sort((a, b) => order.indexOf(a[0]) - order.indexOf(b[0])) // first appearance
|
|
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 } : {}) }));
|
|
956
|
+
}
|
|
957
|
+
|
|
734
958
|
export function phraseList(value) {
|
|
735
959
|
if (!value) return [];
|
|
736
960
|
if (typeof value === "string") return value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -776,6 +1000,10 @@ const PLACEHOLDERS = [
|
|
|
776
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',
|
|
777
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`" },
|
|
778
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
|
+
},
|
|
779
1007
|
{
|
|
780
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>)',
|
|
781
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`" },
|
|
@@ -1174,7 +1402,7 @@ export const PRESENTER_SCALE = { s: 0.7, m: 1, l: 1.3, xl: 1.6 };
|
|
|
1174
1402
|
// split and the word shapes, for the stage presenter (closer for glass too; bubble is smaller than stage, so it fits
|
|
1175
1403
|
// all). A size on the player tag is not seen by a layout's CSS.
|
|
1176
1404
|
const WORD_ROOM = ["stage", "bubble"];
|
|
1177
|
-
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 };
|
|
1178
1406
|
// What clears an overlap (measureLayout gives the slide's layout, its own data-presenter-size (`sized`) and the size it plays at).
|
|
1179
1407
|
function overlapFix(m) {
|
|
1180
1408
|
const big = m.size === "l" || m.size === "xl";
|
|
@@ -1182,7 +1410,7 @@ function overlapFix(m) {
|
|
|
1182
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"`;
|
|
1183
1411
|
// A deck made before its layout made room keeps its old styles: re-copying them is the step that works.
|
|
1184
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`;
|
|
1185
|
-
const styles = ROOMY_LAYOUTS[m.layout];
|
|
1413
|
+
const styles = m.legacy ? undefined : ROOMY_LAYOUTS[m.layout];
|
|
1186
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`;
|
|
1187
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`;
|
|
1188
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>';
|
|
@@ -1196,6 +1424,91 @@ export function overlapWarnings(measured, stage = "1600×900") {
|
|
|
1196
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)));
|
|
1197
1425
|
}
|
|
1198
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
|
+
|
|
1199
1512
|
// Covers whose rendered title lands on their picture, as warnings. Each entry: { id, onPicture }
|
|
1200
1513
|
// (measureLayout sets onPicture on the first slide and on any slide with a cover layout).
|
|
1201
1514
|
export function coverTextWarnings(measured) {
|
|
@@ -1207,7 +1520,8 @@ export function coverTextWarnings(measured) {
|
|
|
1207
1520
|
export const FIT_BOXES = {
|
|
1208
1521
|
"l-spotlight": ".row > li", "l-funnel": ".stages > li", "l-scorecard": ".rows > li, .rows .state", "l-bento": ".tiles > *",
|
|
1209
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",
|
|
1210
|
-
"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",
|
|
1211
1525
|
};
|
|
1212
1526
|
// The rows of boxes that widen to their longest word (min-content tracks): the row must still fit its column.
|
|
1213
1527
|
export const FIT_ROWS = { "l-staircase": ".steps", "l-rail": ".track", "l-lanes": ".lanes" };
|
|
@@ -1219,9 +1533,9 @@ export function wordFitWarnings(measured, { phone = false } = {}) {
|
|
|
1219
1533
|
}
|
|
1220
1534
|
|
|
1221
1535
|
// The layouts whose title is the whole statement and shows in full on a phone (no data-title-mobile needed).
|
|
1222
|
-
export const FULL_TITLE_LAYOUTS = /(?:^|\s)l-(?:sentence|strike)(?:\s|$)/;
|
|
1536
|
+
export const FULL_TITLE_LAYOUTS = /(?:^|\s)l-(?:sentence|strike|statement)(?:\s|$)/;
|
|
1223
1537
|
// The word layouts' parts that sit beside the presenter (measureLayout's media.words; their title is measured as every slide's).
|
|
1224
|
-
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" };
|
|
1225
1539
|
// The media layouts whose presenter must keep off what they show (measureLayout's `media`: boxes by role).
|
|
1226
1540
|
// zoom: the full screenshot, the lens and its label; video-full: the recording as drawn; picture-full: the presenter stays
|
|
1227
1541
|
// in the panel's column (the picture's subject is in the right two-thirds).
|
|
@@ -1259,7 +1573,7 @@ function stepsWhat(m) {
|
|
|
1259
1573
|
}
|
|
1260
1574
|
// The word layouts make room for an l or xl presenter set on the slide's own <section>, as closer and split do.
|
|
1261
1575
|
function wordsFix(m, role = "words") {
|
|
1262
|
-
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");
|
|
1263
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`;
|
|
1264
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`;
|
|
1265
1579
|
if (role === "lead") return leadFix(m);
|
|
@@ -1683,6 +1997,32 @@ function otherShapes(alts) {
|
|
|
1683
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
|
|
1684
1998
|
// counted as content but never as a repeat. Each names the slides and offers two other shapes for each, from
|
|
1685
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
|
+
|
|
1686
2026
|
export function varietyWarnings(all) {
|
|
1687
2027
|
if (all.length < 5) return [];
|
|
1688
2028
|
const content = all.map((s) => ({ s, layout: layoutOf(s) })).filter(({ layout }) => !FRAME.has(layout));
|
|
@@ -1764,7 +2104,7 @@ export function lookWarnings(html) {
|
|
|
1764
2104
|
const choice = deckIconChoice(html);
|
|
1765
2105
|
if (choice?.problem) out.push(MESSAGES.iconChoice(choice.problem));
|
|
1766
2106
|
if (sets.size > 1) out.push(MESSAGES.mixedIcons([...sets].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))));
|
|
1767
|
-
out.push(...varietyWarnings(all), ...flipWarnings(all));
|
|
2107
|
+
out.push(...varietyWarnings(all), ...flipWarnings(all), ...layoutCountWarnings(all));
|
|
1768
2108
|
out.push(...textureWarnings(all, html), ...coverFadeWarnings(html));
|
|
1769
2109
|
out.push(...embedWarnings(all), ...questionWarnings(all));
|
|
1770
2110
|
return out;
|
|
@@ -1926,10 +2266,10 @@ const RETIRED_TEXTURES = {
|
|
|
1926
2266
|
};
|
|
1927
2267
|
const SIGNATURES = ["bg-corner", "bg-mark"];
|
|
1928
2268
|
export const MAX_SIGNATURE_SLIDES = 3;
|
|
1929
|
-
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
|
|
1930
2270
|
// The media layouts: the picture or recording is the slide's object and fills its column; no texture backs it.
|
|
1931
|
-
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"];
|
|
1932
|
-
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
|
|
1933
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
|
|
1934
2274
|
const QUESTION_LAYOUTS = ["l-question-choice", "l-question-text"];
|
|
1935
2275
|
export const TEXTURE_OFF = {
|
|
@@ -2094,6 +2434,15 @@ export async function checkSources({ html, script = "" }, opts = {}, { fetch: fe
|
|
|
2094
2434
|
// Without a folder (hosted, or a caller that passes no reader) only the inline scripts are read.
|
|
2095
2435
|
const walked = deckFiles(html, opts.hosted ? {} : { pathExists: opts.pathExists, read: opts.read, isDir: opts.isDir });
|
|
2096
2436
|
for (const m of walked.missing) errors.push(MESSAGES.scriptRef(m.ref, m.from));
|
|
2437
|
+
// A hosted deck has nothing to resolve a script's relative path against, so every one is a 404.
|
|
2438
|
+
if (opts.hosted) {
|
|
2439
|
+
// A path the markup's src/href already names is that hostedRef error: list each path once.
|
|
2440
|
+
const inAttrs = new Set(localRefs(html).map((r) => deckPath("", r) ?? r));
|
|
2441
|
+
for (const r of hostedScriptRefs(html)) {
|
|
2442
|
+
const refs = r.refs.filter((ref) => !inAttrs.has(deckPath("", ref) ?? ref));
|
|
2443
|
+
if (refs.length) errors.push(MESSAGES.hostedScriptRef(refs, r.slides, r.where, { worker: r.worker }));
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2097
2446
|
const ids = slides(html).map((s) => s.id);
|
|
2098
2447
|
const player = playerScript(html);
|
|
2099
2448
|
let manifest = null;
|
|
@@ -2174,8 +2523,8 @@ export async function checkSources({ html, script = "" }, opts = {}, { fetch: fe
|
|
|
2174
2523
|
: tagIssue.kind === "captions" ? MESSAGES.presenterCaptions()
|
|
2175
2524
|
: MESSAGES.presenterUnfilled(tagIssue.presenter));
|
|
2176
2525
|
}
|
|
2177
|
-
for (const t of walked.templates) warnings.push(MESSAGES.scriptTemplate(t.from, t.samples));
|
|
2178
|
-
for (const c of walked.computed) warnings.push(MESSAGES.scriptComputed(c.from, c.calls));
|
|
2526
|
+
for (const t of walked.templates) warnings.push(opts.hosted ? MESSAGES.scriptTemplateHosted(t.samples) : MESSAGES.scriptTemplate(t.from, t.samples));
|
|
2527
|
+
for (const c of walked.computed) warnings.push(opts.hosted ? MESSAGES.scriptComputedHosted(c.calls) : MESSAGES.scriptComputed(c.from, c.calls));
|
|
2179
2528
|
if (opts.hosted) {
|
|
2180
2529
|
for (const url of absoluteRefs(html)) if (!isHostedAsset(url) && !stockSource(url) && /\.(png|jpe?g|gif|webp|avif|svg|mp4|webm|mov)(\?|#|$)/i.test(url)) warnings.push(MESSAGES.hotlink(url));
|
|
2181
2530
|
warnings.push(MESSAGES.layoutUnchecked(HOSTED_LAYOUT_WHY));
|