@hypersocial/decks-cli 0.9.22 → 0.9.24

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.
Files changed (88) hide show
  1. package/package.json +1 -1
  2. package/skills/hyperdecks/SKILL.md +113 -67
  3. package/skills/hyperdecks/chat.md +11 -8
  4. package/skills/hyperdecks/terminal.md +82 -0
  5. package/src/bars.mjs +268 -0
  6. package/src/brand.mjs +51 -8
  7. package/src/check.mjs +311 -15
  8. package/src/checkRules.mjs +616 -27
  9. package/src/commands.mjs +157 -28
  10. package/src/deckSlug.mjs +41 -0
  11. package/src/export-video.mjs +75 -5
  12. package/src/files.mjs +35 -0
  13. package/src/frame-clock.mjs +6 -2
  14. package/src/guide.mjs +91 -13
  15. package/src/hosted.mjs +18 -8
  16. package/src/iconAliasNames.mjs +70 -0
  17. package/src/iconChoice.mjs +97 -0
  18. package/src/iconSets.mjs +89 -0
  19. package/src/iconSlots.mjs +48 -0
  20. package/src/icons.mjs +285 -45
  21. package/src/iconsCli.mjs +76 -0
  22. package/src/layoutRoutes.mjs +92 -0
  23. package/src/layouts.mjs +4 -4
  24. package/src/mediaPreviews.mjs +3 -1
  25. package/src/narrate.mjs +31 -4
  26. package/src/opening.mjs +9 -3
  27. package/src/ops.mjs +49 -0
  28. package/src/photosGuide.mjs +47 -0
  29. package/src/picturesGuide.mjs +53 -0
  30. package/src/play.mjs +3 -2
  31. package/src/presenter.mjs +3 -1
  32. package/src/preview-moment.mjs +10 -2
  33. package/src/release.mjs +13 -5
  34. package/src/runtime.mjs +9 -2
  35. package/src/scaffold.mjs +73 -13
  36. package/src/source.mjs +86 -14
  37. package/src/stockMedia.mjs +299 -0
  38. package/src/themeCli.mjs +41 -0
  39. package/src/themes.mjs +345 -0
  40. package/templates/icons/material.LICENSE +202 -0
  41. package/templates/icons/material.json.gz +0 -0
  42. package/templates/icons/phosphor.LICENSE +21 -0
  43. package/templates/icons/phosphor.json.gz +0 -0
  44. package/templates/icons/tabler.LICENSE +21 -0
  45. package/templates/icons/tabler.json.gz +0 -0
  46. package/templates/layouts/_deck.html +177 -36
  47. package/templates/layouts/bento.html +75 -0
  48. package/templates/layouts/chart.html +6 -4
  49. package/templates/layouts/closer.html +10 -3
  50. package/templates/layouts/compare.html +13 -4
  51. package/templates/layouts/cover-band.html +10 -8
  52. package/templates/layouts/cover-frame.html +9 -7
  53. package/templates/layouts/cover-poster.html +8 -5
  54. package/templates/layouts/cover-split.html +7 -6
  55. package/templates/layouts/cover-type.html +1 -0
  56. package/templates/layouts/features.html +9 -7
  57. package/templates/layouts/funnel.html +60 -0
  58. package/templates/layouts/hero.html +40 -22
  59. package/templates/layouts/lanes.html +63 -0
  60. package/templates/layouts/loop.html +81 -0
  61. package/templates/layouts/number.html +2 -1
  62. package/templates/layouts/phone-stage.html +68 -0
  63. package/templates/layouts/phones.html +1 -0
  64. package/templates/layouts/picture-full.html +48 -0
  65. package/templates/layouts/portrait.html +45 -0
  66. package/templates/layouts/product.html +7 -6
  67. package/templates/layouts/quote.html +2 -1
  68. package/templates/layouts/rail.html +71 -0
  69. package/templates/layouts/scorecard.html +70 -0
  70. package/templates/layouts/screens.html +85 -0
  71. package/templates/layouts/sentence.html +39 -0
  72. package/templates/layouts/split.html +22 -7
  73. package/templates/layouts/spotlight.html +77 -0
  74. package/templates/layouts/stack.html +83 -0
  75. package/templates/layouts/staircase.html +76 -0
  76. package/templates/layouts/strike.html +46 -0
  77. package/templates/layouts/tap-through.html +73 -0
  78. package/templates/layouts/team.html +3 -2
  79. package/templates/layouts/timeline.html +16 -6
  80. package/templates/layouts/two-bars.html +53 -0
  81. package/templates/layouts/two-by-two.html +71 -0
  82. package/templates/layouts/video-beats.html +66 -0
  83. package/templates/layouts/video-full.html +62 -0
  84. package/templates/layouts/wall.html +81 -0
  85. package/templates/layouts/zoom.html +144 -0
  86. package/templates/narrated-deck.html +12 -7
  87. package/templates/script.md +2 -2
  88. /package/templates/icons/{LICENSE → lucide.LICENSE} +0 -0
package/src/check.mjs CHANGED
@@ -8,9 +8,10 @@
8
8
  // every clip's audio and timeline. `fetch` and `exists` are injectable for tests.
9
9
  // The rules themselves live in checkRules.mjs (no Node imports, shared with the
10
10
  // hosted check); this file adds the folder I/O and the Chromium measurements.
11
- import { existsSync, lstatSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
12
- import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
13
- import { COVER_LAYOUTS, PHONE, PRESENTER_FOOTPRINT, checkSources, coverTextWarnings, overlapWarnings, phoneOverflowErrors, slideStyles, stageSize, MESSAGES } from "./checkRules.mjs";
11
+ import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync, realpathSync, writeFileSync } from "node:fs";
12
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
13
+ import { deckSlug } from "./deckSlug.mjs";
14
+ import { CELL_PICTURES, COVER_LAYOUTS, EDGE_PICTURES, PHONE, PHONE_SCREENS, UNMEASURED_PICTURES, WORD_PARTS, ROOMY_LAYOUTS, FIT_BOXES, FIT_ROWS, PRESENTER_FOOTPRINT, PRESENTER_SCALE, barsWarnings, checkSources, coverTextWarnings, lensOffSlideWarnings, lensWarnings, overlapWarnings, phoneOverflowErrors, pictureCornerWarnings, pictureFitWarnings, presenterMediaWarnings, silentWithoutPresenter, wordFitWarnings, slideStyles, stageSize, MESSAGES } from "./checkRules.mjs";
14
15
 
15
16
  import { withLoadingBlock } from "./loadingBlock.mjs";
16
17
 
@@ -21,18 +22,37 @@ export * from "./loadingBlock.mjs";
21
22
  // (no player, no deck scripts), put the style's footprint in its slot, and
22
23
  // measure it against the title's text; on the first slide and any cover, also
23
24
  // whether a line of the title lands on a picture (onPicture, for
24
- // coverTextWarnings). Needs `hyperdecks preview setup`.
25
- export async function measureLayout(deckDir, styles, { width = 1600, height = 900 } = {}) {
26
- return withDeckPage(deckDir, { width, height }, (page) => page.evaluate(({ styles, footprint, width, height, covers }) => {
25
+ // coverTextWarnings); and each framed picture's natural size, frame and fit
26
+ // (pictures, for pictureFitWarnings); what the media layouts keep clear of the presenter (media, for
27
+ // presenterMediaWarnings) and zoom's lens enlargement (lens, for lensWarnings). With `card`, the page is
28
+ // `width`×`height` (a phone) and the slides are laid out in a card of that size with their mobile titles,
29
+ // as the framed player shows them there. Needs `hyperdecks preview setup`.
30
+ export async function measureLayout(deckDir, styles, { width = 1600, height = 900, card = null } = {}) {
31
+ return withDeckPage(deckDir, { width, height }, (page) => page.evaluate(({ styles, words, roomy, fitBoxes, fitRows, footprint, scales, width, height, covers, edges, unmeasured, phoneScreens, cells }) => {
27
32
  const box = (r) => ({ x: r.left, y: r.top, width: r.width, height: r.height });
28
33
  const sections = [...document.querySelectorAll("section.slide")];
34
+ // The deck's own CSS (a deck keeps the layout styles it was made with): does it have this card's rules? The wall's
35
+ // square and wide cells, and the room that closer, split and the word shapes make for an l or xl presenter. check's advice names them only then.
36
+ const css = [...document.styleSheets].flatMap((sheet) => { try { return [...sheet.cssRules].map((r) => r.cssText); } catch { return []; } }).join("\n");
37
+ const hasCells = css.includes(".pics.square") && css.includes(".pics.wide");
38
+ const hasRoom = (layout) => new RegExp(`\\.${layout}[^{]*data-presenter-size="xl"`).test(css);
29
39
  const host = sections[0]?.parentElement ?? document.body;
30
40
  Object.assign(host.style, { position: "relative", width: `${width}px`, height: `${height}px`, overflow: "hidden", margin: "0" });
31
41
  document.body.style.margin = "0";
32
42
  return sections.map((slide, i) => {
33
43
  sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0" }); });
34
- const { id, style } = styles[i] ?? { id: slide.id, style: "bubble" };
35
- const size = footprint[style];
44
+ const { id, style, size: scaleName } = styles[i] ?? { id: slide.id, style: "bubble" };
45
+ // A slide's own --hd-presenter-scale (its CSS) wins over data-presenter-size, as in the player, within its range.
46
+ const fine = parseFloat(getComputedStyle(slide).getPropertyValue("--hd-presenter-scale"));
47
+ const scale = Number.isFinite(fine) && fine > 0 ? Math.min(3, Math.max(0.25, fine)) : scales[scaleName] ?? 1;
48
+ let size = { ...footprint[style], width: footprint[style].width * scale, height: footprint[style].height * scale };
49
+ // A slide that shrinks the stage or glass head in its CSS (below 1; video-full's bar) shrinks only the head (320px at 1):
50
+ // the caption keeps its size (360px wide, two lines) and, with no room above the head, the player sets it beside
51
+ // the head. Its footprint is the two side by side.
52
+ if (Number.isFinite(fine) && fine > 0 && fine < 1 && (style === "stage" || style === "glass")) {
53
+ const head = 320 * scale;
54
+ size = { ...footprint[style], width: head + 16 + 360, height: Math.max(head, 96) };
55
+ }
36
56
  const probe = document.createElement("div");
37
57
  Object.assign(probe.style, { width: `${size.width}px`, height: `${size.height}px`, flex: "none" });
38
58
  const slot = slide.querySelector(".narration-slot");
@@ -77,9 +97,141 @@ export async function measureLayout(deckDir, styles, { width = 1600, height = 90
77
97
  onPicture = lines.some((line) => pictures.some((p) => hit(line, p.getBoundingClientRect()) &&
78
98
  !panels.some((panel) => !panel.contains(p) && hit(line, panel.getBoundingClientRect()))));
79
99
  }
80
- return { id, style, presenter, title, onPicture };
100
+ // Each loaded picture in a layout's frame (an <img class="art">, <img class="shot"> or <img class="pic">,
101
+ // not a laptop frame's shot or zoom's lens) for pictureFitWarnings: its natural shape, its frame's (the content box,
102
+ // from the layout box, so a tilted card or a rotated frame measures as drawn unrotated) and how
103
+ // it fills it. A picture that did not load, or a <video>, is not measured.
104
+ const pictures = [...slide.querySelectorAll("img.art, img.shot, img.pic")].filter((img) => !img.matches(unmeasured) && img.complete && img.naturalWidth && img.naturalHeight).map((img) => {
105
+ const cs = getComputedStyle(img), px = (v) => parseFloat(v) || 0;
106
+ const frame = () => ({ width: img.clientWidth - px(cs.paddingLeft) - px(cs.paddingRight), height: img.clientHeight - px(cs.paddingTop) - px(cs.paddingBottom) });
107
+ const shown = frame(), natural = { width: img.naturalWidth, height: img.naturalHeight };
108
+ // Stray width/height attributes: the frame takes the picture's shape once they are gone.
109
+ let attrSized = false;
110
+ const attrs = ["width", "height"].filter((a) => img.hasAttribute(a)).map((a) => [a, img.getAttribute(a)]);
111
+ if (attrs.length) {
112
+ const loss = (f) => { const ar = natural.width / natural.height, b = f.width / f.height; return 1 - Math.min(ar, b) / Math.max(ar, b); };
113
+ attrs.forEach(([a]) => img.removeAttribute(a));
114
+ const bare = frame();
115
+ attrs.forEach(([a, v]) => img.setAttribute(a, v));
116
+ attrSized = bare.width > 0 && bare.height > 0 && loss(shown) - loss(bare) > 0.1;
117
+ }
118
+ // Its drawn corner (pictureCornerWarnings): the larger radius of any corner, inside its border and padding.
119
+ // A phone screen keeps a phone's corner (0: not measured).
120
+ const inset = (k) => px(cs.getPropertyValue(`border-${k}-width`)) + px(cs.getPropertyValue(`padding-${k}`));
121
+ const corner = img.matches(phoneScreens) ? 0 : Math.max(0, ...[["top", "left"], ["top", "right"], ["bottom", "right"], ["bottom", "left"]].map(([v, x]) => {
122
+ // A percentage is of the border box's width (horizontal radius) and height (vertical).
123
+ const [hx, hy = hx] = cs.getPropertyValue(`border-${v}-${x}-radius`).split(" ");
124
+ const len = (r, size) => (r.endsWith("%") ? (parseFloat(r) / 100) * size : px(r));
125
+ const [rx, ry] = [len(hx, img.offsetWidth), len(hy, img.offsetHeight)];
126
+ return Math.max(rx - inset(x), ry - inset(v));
127
+ }));
128
+ // A wall picture's cells: the class on its .pics (square, wide), else upright ("").
129
+ const wallPics = img.closest(".l-wall .pics"), cells = wallPics ? (["square", "wide"].find((c) => wallPics.classList.contains(c)) ?? "") : null;
130
+ return { natural, frame: shown, fit: cs.objectFit, edge: img.matches(edges), ...(cells != null ? { cells } : {}), shot: img.classList.contains("shot"), pic: img.classList.contains("pic"), art: img.classList.contains("art"), wide: img.classList.contains("wide"), corner, ...(attrSized ? { attrSized } : {}) };
131
+ }).filter((p) => p.frame.width > 0 && p.frame.height > 0);
132
+ // Each picture or clip in a layout's frame (the measured pictures' selectors, and any <video> but a
133
+ // laptop frame's or zoom's), for barsWarnings: its file (a path in the deck folder when served from
134
+ // it, else its URL), the frame it is drawn in and its fit. The CLI reads the file for bars
135
+ // (measureFramedBars): a <video>'s frames are not decoded here (JavaScript is off), and a storage
136
+ // URL is not CORS-readable for a canvas.
137
+ const framed = [...slide.querySelectorAll("img.art, img.shot, img.pic, video")].filter((n) => !n.matches(unmeasured) && !n.closest(".brand-logo, .icon")).flatMap((n) => {
138
+ const raw = n.tagName === "VIDEO" ? (n.getAttribute("src") ? n.src : n.querySelector("source[src]")?.src) : (n.currentSrc || n.src);
139
+ if (!raw || !/^https?:/.test(raw)) return [];
140
+ // The deck is served under a path of its own: a local file is named from the page's folder.
141
+ const url = new URL(raw), base = new URL(".", location.href).pathname, local = url.origin === location.origin && url.pathname.startsWith(base);
142
+ const cs = getComputedStyle(n), px = (v) => parseFloat(v) || 0;
143
+ const frame = { width: n.clientWidth - px(cs.paddingLeft) - px(cs.paddingRight), height: n.clientHeight - px(cs.paddingTop) - px(cs.paddingBottom) };
144
+ if (frame.width <= 0 || frame.height <= 0) return [];
145
+ return [{ src: local ? decodeURIComponent(url.pathname.slice(base.length)) : raw, local, kind: n.tagName === "VIDEO" ? "video" : "image", frame, fit: cs.objectFit, cell: n.matches(cells), ...(n.matches(edges) ? { edge: true } : {}) }];
146
+ });
147
+ // What the presenter keeps clear of on the media layouts (presenterMediaWarnings).
148
+ const boxOf = (sel) => { const n = slide.querySelector(sel); return n ? box(n.getBoundingClientRect()) : null; };
149
+ let media = null;
150
+ if (slide.classList.contains("l-zoom")) media = { shot: boxOf(".full"), lens: boxOf(".lens .ring") ?? boxOf(".lens"), label: boxOf(".lens .pill") ?? boxOf(".side .pill") };
151
+ else if (slide.classList.contains("l-video-full")) {
152
+ // The recording as drawn: a <video>'s picture inside its box (object-fit contain), else the box.
153
+ const clip = slide.querySelector(".clip");
154
+ let b = clip && box(clip.getBoundingClientRect());
155
+ if (clip?.tagName === "VIDEO" && clip.videoWidth && getComputedStyle(clip).objectFit === "contain") {
156
+ const s = Math.min(b.width / clip.videoWidth, b.height / clip.videoHeight), w = clip.videoWidth * s, h = clip.videoHeight * s;
157
+ b = { x: b.x + (b.width - w) / 2, y: b.y + (b.height - h) / 2, width: w, height: h };
158
+ }
159
+ media = { clip: b };
160
+ } else if (slide.classList.contains("l-picture-full")) media = { beyondPanel: boxOf(".panel") };
161
+ else if (slide.classList.contains("l-hero") && slide.querySelector(":scope > img.art")) media = { art: boxOf(":scope > img.art") };
162
+ else {
163
+ // The word layouts: what they set beside the presenter (the title is measured on its own, above).
164
+ const sel = words[[...slide.classList].find((c) => Object.hasOwn(words, c))];
165
+ const parts = sel ? [...slide.querySelectorAll(sel)].map((n) => n.getBoundingClientRect()).filter((r) => r.width && r.height) : [];
166
+ if (parts.length) {
167
+ const [x0, y0] = [Math.min(...parts.map((r) => r.left)), Math.min(...parts.map((r) => r.top))];
168
+ media = { words: { x: x0, y: y0, width: Math.max(...parts.map((r) => r.right)) - x0, height: Math.max(...parts.map((r) => r.bottom)) - y0 } };
169
+ }
170
+ }
171
+ if (media) media = Object.fromEntries(Object.entries(media).filter(([, b]) => b && b.width && b.height));
172
+ // zoom's lens: how many times its picture's own pixels it shows them.
173
+ const lensShot = slide.querySelector(".l-zoom .lens img.shot");
174
+ const lens = lensShot?.complete && lensShot.naturalWidth ? { natural: lensShot.naturalWidth, shown: Math.round(lensShot.getBoundingClientRect().width) } : null;
175
+ // The stage or glass head alone (320px at 1, at the foot of the footprint, centred): what the hero's picture clears.
176
+ const headSize = 320 * scale, head = presenter && (style === "stage" || style === "glass") && size.height >= headSize
177
+ ? { x: presenter.x + (presenter.width - headSize) / 2, y: presenter.y + presenter.height - headSize, width: headSize, height: headSize } : null;
178
+ const layout = [...slide.classList].find((c) => c.startsWith("l-")) ?? null;
179
+ // The word layouts' boxes (wordFitWarnings): any line of text that runs past its box's edge, clipped or not.
180
+ const fit = [], broken = [];
181
+ if (layout && Object.hasOwn(fitBoxes, layout)) {
182
+ for (const boxEl of slide.querySelectorAll(fitBoxes[layout])) {
183
+ const b = boxEl.getBoundingClientRect();
184
+ // A box with words that collapsed to nothing (a layout fault) is as bad as words running out of it.
185
+ if (!b.width || !b.height) {
186
+ const words = (boxEl.innerText || boxEl.textContent).trim().replace(/\s+/g, " ").slice(0, 60);
187
+ if (words && getComputedStyle(boxEl).display !== "none") fit.push(words);
188
+ continue;
189
+ }
190
+ const walker = document.createTreeWalker(boxEl, NodeFilter.SHOW_TEXT);
191
+ for (let t; (t = walker.nextNode());) {
192
+ if (!t.textContent.trim()) continue;
193
+ const range = document.createRange();
194
+ range.selectNodeContents(t);
195
+ // Across, the line must stay inside; up and down a line's glyph box may stand a little past a box with no
196
+ // padding (a font's ascent is taller than its line height), so a third of the font size is allowed there.
197
+ const slack = Math.max(2, (parseFloat(getComputedStyle(t.parentElement).fontSize) || 16) / 3);
198
+ const out = [...range.getClientRects()].some((r) => r.width && (r.left < b.left - 1 || r.right > b.right + 1 || r.top < b.top - slack || r.bottom > b.bottom + slack));
199
+ if (out) fit.push(t.textContent.trim().replace(/\s+/g, " ").slice(0, 60));
200
+ // A word broken across two lines (no hyphen shown): names are sized so their longest word fits, never split.
201
+ // Only where the text's styles let a word break at all (overflow-wrap or word-break); otherwise a line breaks
202
+ // only at its usual places (spaces, dashes, CJK, a zero-width space) and a too-long word overflows instead,
203
+ // which the box check above names. A soft hyphen (&shy;) or a hyphen is a break the author chose. (A word
204
+ // split across two elements, <em>Un</em>questionably, is not seen.)
205
+ const ws = getComputedStyle(t.parentElement);
206
+ const breaks = /anywhere|break-word/.test(ws.overflowWrap) || /break-all|break-word/.test(ws.wordBreak);
207
+ // A word here is a run of letters between the places a line may break anyway: spaces, hyphens and dashes,
208
+ // a slash, an ellipsis, a zero-width space, and every CJK character.
209
+ for (const m of breaks ? t.textContent.matchAll(/[^\s\u00ad\u200b\-\u2010-\u2015\u2026\/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]+/gu) : []) {
210
+ if (m[0].length < 2) continue;
211
+ const w = document.createRange();
212
+ w.setStart(t, m.index);
213
+ w.setEnd(t, m.index + m[0].length);
214
+ const tops = new Set([...w.getClientRects()].filter((r) => r.width > 0.5).map((r) => Math.round(r.top)));
215
+ if (tops.size > 1) broken.push(m[0]);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ // A row of boxes (staircase's steps, rail's stops, lanes' columns) that grew past its column: each word fits its
221
+ // box, but the boxes together are wider than the room the layout keeps (and run under the presenter).
222
+ const rowSel = layout && Object.hasOwn(fitRows, layout) ? fitRows[layout] : null;
223
+ const row = rowSel ? slide.querySelector(rowSel) : null;
224
+ let wide = null;
225
+ if (row && row.scrollWidth > row.clientWidth + 1) {
226
+ // Name the longest word in the row's names: the one that widened its box most.
227
+ const names = [...row.querySelectorAll("b, .chip, .who")].flatMap((n) => n.textContent.split(/\s+/)).filter(Boolean);
228
+ wide = names.sort((a, b) => b.length - a.length)[0] ?? row.textContent.trim().slice(0, 40);
229
+ }
230
+ const fitTexts = [...new Set(fit)]; // a text inside two boxes (scorecard's state in its row) is named once
231
+ const current = layout === "l-wall" ? { current: hasCells } : Object.hasOwn(roomy, layout ?? "") ? { current: hasRoom(layout) } : {};
232
+ return { id, style, ...current, ...(scaleName ? { size: scaleName } : {}), sized: slide.getAttribute("data-presenter-size")?.trim() || null, presenter, ...(head ? { head } : {}), title, onPicture, layout, pictures, framed, ...(media ? { media } : {}), ...(lens ? { lens } : {}), ...(fitTexts.length ? { fit: fitTexts } : {}), ...(broken.length ? { broken: [...new Set(broken)] } : {}), ...(wide ? { wide } : {}), ...(slide.classList.contains("l-zoom") ? { bounds: box(slide.getBoundingClientRect()) } : {}) };
81
233
  });
82
- }, { styles, footprint: PRESENTER_FOOTPRINT, width, height, covers: COVER_LAYOUTS }));
234
+ }, { styles, words: WORD_PARTS, roomy: ROOMY_LAYOUTS, fitBoxes: FIT_BOXES, fitRows: FIT_ROWS, footprint: PRESENTER_FOOTPRINT, scales: PRESENTER_SCALE, width: card?.width ?? width, height: card?.height ?? height, covers: COVER_LAYOUTS, edges: EDGE_PICTURES, unmeasured: UNMEASURED_PICTURES, phoneScreens: PHONE_SCREENS, cells: CELL_PICTURES }), { mobileTitles: !!card });
83
235
  }
84
236
 
85
237
  // Lay each slide out as the framed player shows it on a phone: the deck's own
@@ -100,9 +252,60 @@ export async function measurePhoneFit(deckDir) {
100
252
  }, PHONE.card));
101
253
  }
102
254
 
255
+ // How much of each slide's height holds content on a phone, laid out as
256
+ // measurePhoneFit does: from the top of the first thing drawn (text, a picture,
257
+ // a frame, a card) to the bottom of the last, over the card's height. The
258
+ // presenter's slot and decorations do not count; a picture inside zoom's lens
259
+ // counts as the lens, and a contained <video> as its picture. Returns
260
+ // { id, layout, top, bottom, share, hole } per slide. The free height above the
261
+ // presenter (28 to 566 of 736px) caps share at about 0.73. `hole`: the tallest empty band between two drawn things.
262
+ export async function measurePhoneContent(deckDir) {
263
+ return withDeckPage(deckDir, { width: PHONE.width, height: PHONE.height }, (page) => page.evaluate((card) => {
264
+ for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile;
265
+ const sections = [...document.querySelectorAll("section.slide")];
266
+ const host = sections[0]?.parentElement ?? document.body;
267
+ Object.assign(host.style, { position: "relative", width: `${card.width}px`, height: `${card.height}px`, overflow: "hidden", margin: "0" });
268
+ document.body.style.margin = "0";
269
+ const DRAWN = "img, video, svg, canvas, .shot, .pic, .art, .frame, .clip, .lens, .card, .panel, .pill, .sticker, .face, .avatar, .cta, .figure";
270
+ return sections.map((slide) => {
271
+ sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0", overflow: "hidden" }); });
272
+ const sr = slide.getBoundingClientRect();
273
+ const skip = (n) => !!n.closest(".narration-slot, .deco, [hidden]") || !!n.parentElement?.closest(".lens");
274
+ const rects = [];
275
+ for (const n of slide.querySelectorAll(DRAWN)) {
276
+ if (skip(n) || getComputedStyle(n).display === "none") continue;
277
+ let r = n.getBoundingClientRect();
278
+ if (n.tagName === "VIDEO" && n.videoWidth && getComputedStyle(n).objectFit === "contain") {
279
+ // Its picture inside the box, where object-position puts it (computed as "x% y%" or px).
280
+ const k = Math.min(r.width / n.videoWidth, r.height / n.videoHeight), h = n.videoHeight * k;
281
+ const y = getComputedStyle(n).objectPosition.split(" ")[1] ?? "50%";
282
+ const top = r.top + (y.endsWith("%") ? (r.height - h) * parseFloat(y) / 100 : parseFloat(y) || 0);
283
+ r = { top, bottom: top + h, width: r.width, height: h };
284
+ }
285
+ if (r.width > 2 && r.height > 2) rects.push(r);
286
+ }
287
+ const walker = document.createTreeWalker(slide, NodeFilter.SHOW_TEXT);
288
+ for (let t; (t = walker.nextNode());) {
289
+ if (!t.textContent.trim() || skip(t.parentElement) || t.parentElement.closest("svg")) continue;
290
+ const range = document.createRange();
291
+ range.selectNodeContents(t);
292
+ for (const r of range.getClientRects()) if (r.width && r.height) rects.push(r);
293
+ }
294
+ const seen = rects.filter((r) => r.bottom > sr.top && r.top < sr.bottom);
295
+ const layout = [...slide.classList].find((c) => c.startsWith("l-"))?.slice(2) ?? null;
296
+ if (!seen.length) return { id: slide.id, layout, top: 0, bottom: 0, share: 0, hole: 0 };
297
+ const top = Math.max(sr.top, Math.min(...seen.map((r) => r.top))), bottom = Math.min(sr.bottom, Math.max(...seen.map((r) => r.bottom)));
298
+ // The tallest empty band between two drawn things (a hole in the block).
299
+ let hole = 0, reach = -Infinity;
300
+ for (const r of [...seen].sort((a, b) => a.top - b.top)) { if (reach > -Infinity) hole = Math.max(hole, r.top - reach); reach = Math.max(reach, r.bottom); }
301
+ return { id: slide.id, layout, top: Math.round(top - sr.top), bottom: Math.round(bottom - sr.top), share: (bottom - top) / sr.height, hole: Math.round(hole) };
302
+ });
303
+ }, PHONE.card), { mobileTitles: true });
304
+ }
305
+
103
306
  // Open the deck's index.html in Chromium at `viewport` with JavaScript off and
104
307
  // hand the page to `measure`. Needs `hyperdecks preview setup`.
105
- async function withDeckPage(deckDir, viewport, measure) {
308
+ async function withDeckPage(deckDir, viewport, measure, { mobileTitles = false } = {}) {
106
309
  const { chromium } = await import("playwright");
107
310
  const { serveSource, routeCaptureRequest } = await import("./preview-capture.mjs");
108
311
  const { mkdtemp, rm } = await import("node:fs/promises");
@@ -123,6 +326,7 @@ async function withDeckPage(deckDir, viewport, measure) {
123
326
  const page = await context.newPage();
124
327
  await page.goto(server.url, { waitUntil: "load", timeout: 30000 });
125
328
  await page.evaluate(() => document.fonts.ready);
329
+ if (mobileTitles) await page.evaluate(() => { for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile; });
126
330
  return await measure(page);
127
331
  } finally {
128
332
  await server?.close().catch(() => {});
@@ -131,6 +335,54 @@ async function withDeckPage(deckDir, viewport, measure) {
131
335
  }
132
336
  }
133
337
 
338
+ // The bars (bars.mjs's measureBars) of each file measureLayout found framed, as a Map from its src to
339
+ // barsResult. A deck file is read where it is (only inside the deck folder); a URL is fetched when its
340
+ // host is public (25 MB, no redirects, a real image or video container only). A file that cannot be read is left out: bars are a warning,
341
+ // and a missing file is localRef's error.
342
+ const MAX_BARS_FETCH = 25 * 1024 * 1024, BARS_FETCH_MS = 30_000;
343
+ export async function measureFramedBars(deckDir, measured, { fetch: fetchImpl = globalThis.fetch, ffmpeg = null, allowDestination = null } = {}) {
344
+ const { measureBars } = await import("./bars.mjs");
345
+ allowDestination ??= (await import("./preview-capture.mjs")).allowCaptureDestination;
346
+ const { bundledFfmpeg, knownMedia } = await import("./mediaPreviewMake.mjs");
347
+ const { mkdtemp, rm, writeFile } = await import("node:fs/promises");
348
+ const { tmpdir } = await import("node:os");
349
+ const files = new Map();
350
+ for (const f of measured.flatMap((m) => m.framed ?? [])) if (!files.has(f.src)) files.set(f.src, f);
351
+ const out = new Map();
352
+ if (!files.size) return out;
353
+ const ff = ffmpeg ?? await bundledFfmpeg();
354
+ const root = realpathSync(deckDir);
355
+ const temp = await mkdtemp(join(tmpdir(), "hd-bars-"));
356
+ try {
357
+ let i = 0;
358
+ for (const [src, f] of files) {
359
+ try {
360
+ let input;
361
+ if (f.local) {
362
+ input = realpathSync(resolve(root, src));
363
+ if (!input.startsWith(root + sep)) continue;
364
+ } else {
365
+ // A deck (a hosted draft a chat agent wrote) must not reach this machine's own network:
366
+ // the capture's rule, a public address only, and no redirect to one that is not.
367
+ if (!/^https?:/.test(src) || !(await allowDestination(src, "http://deck.invalid/"))) continue;
368
+ const res = await fetchImpl(src, { redirect: "error", signal: AbortSignal.timeout(BARS_FETCH_MS) });
369
+ if (!res.ok || Number(res.headers.get("content-length")) > MAX_BARS_FETCH) { await res.body?.cancel?.().catch(() => {}); continue; }
370
+ const bytes = new Uint8Array(await res.arrayBuffer());
371
+ if (bytes.byteLength > MAX_BARS_FETCH || !knownMedia(bytes)) continue;
372
+ input = join(temp, `f${i++}`);
373
+ await writeFile(input, bytes);
374
+ }
375
+ out.set(src, await measureBars(ff, input, { video: f.kind === "video" }));
376
+ } catch {
377
+ // unreadable here: no bars warning for it
378
+ }
379
+ }
380
+ } finally {
381
+ await rm(temp, { recursive: true, force: true }).catch(() => {});
382
+ }
383
+ return out;
384
+ }
385
+
134
386
  // "<slug>" means ./decks/<slug> unless it names a folder itself.
135
387
  export function resolveDeckDir(arg, cwd = process.cwd()) {
136
388
  if (!arg) throw new Error("usage: check <slug|deck-dir>");
@@ -179,6 +431,20 @@ export function deckFolder(deckDir) {
179
431
  pathExists: deckPathResolver(deckDir),
180
432
  isDir: deckPathResolver(deckDir, { kind: "dir" }),
181
433
  read: (path) => readFileSync(join(deckDir, path), "utf8"),
434
+ // The first bytes of a file inside the folder (a <video>'s src or poster), for its kind.
435
+ readBytes: (ref) => {
436
+ let path;
437
+ try { path = decodeURIComponent(ref); } catch { path = ref; }
438
+ if (deckPathResolver(deckDir)(path) !== true) throw new Error("not in the deck folder");
439
+ // Only the first bytes: a recording can be large.
440
+ const fd = openSync(isAbsolute(path) ? join(realpathSync(deckDir), path) : resolve(deckDir, path), "r");
441
+ try {
442
+ const head = Buffer.alloc(16);
443
+ return head.subarray(0, readSync(fd, head, 0, 16, 0));
444
+ } finally {
445
+ closeSync(fd);
446
+ }
447
+ },
182
448
  };
183
449
  }
184
450
 
@@ -186,14 +452,44 @@ export function deckFolder(deckDir) {
186
452
  // (the hosted release measures a draft the same way, from a temp folder). A
187
453
  // presenter over the title is a warning, not a failure: only a person can judge
188
454
  // it. A slide that overflows the phone card is an error: the player never
189
- // scrolls a slide. A cover whose title lands on its picture is a warning. No Chromium is a warning, as each measurement is optional.
190
- export async function layoutCheck(deckDir, html, manifest = null, { measure = measureLayout, measureFit = measurePhoneFit } = {}) {
455
+ // scrolls a slide. A cover whose title lands on its picture is a warning, and so is a picture that
456
+ // leaves a band (over a fifth of its frame empty) or is cropped past the limit (pictureFitWarnings), or whose corner cuts into it (pictureCornerWarnings). No Chromium is a warning, as each measurement is optional.
457
+ // The pictures again as a phone shows them (its frames have other shapes).
458
+ const measurePhonePictures = (deckDir, styles) => measureLayout(deckDir, styles, { width: PHONE.width, height: PHONE.height, card: PHONE.card });
459
+ // A caller that injects `measure` and no `measurePhone` gets no phone pass.
460
+ // `readBars` reads the framed files for bars (measureFramedBars; a caller that injects `measure` and no
461
+ // `readBars` gets none).
462
+ export async function layoutCheck(deckDir, html, manifest = null, { measure = measureLayout, measureFit = measurePhoneFit, measurePhone = measure === measureLayout ? measurePhonePictures : null, readBars = measure === measureLayout ? measureFramedBars : null } = {}) {
191
463
  const errors = [], warnings = [];
192
464
  const { width: w, height: h } = stageSize(html);
193
465
  try {
194
466
  const measured = await measure(deckDir, slideStyles(html, manifest), { width: w, height: h });
195
- warnings.push(...overlapWarnings(measured, `${w}×${h}`));
467
+ // A silent deck with no presenter (silentWithoutPresenter) has nothing in the corner to overlap.
468
+ if (!silentWithoutPresenter(html)) {
469
+ warnings.push(...overlapWarnings(measured, `${w}×${h}`));
470
+ warnings.push(...presenterMediaWarnings(measured, `${w}×${h}`));
471
+ }
196
472
  warnings.push(...coverTextWarnings(measured));
473
+ warnings.push(...pictureFitWarnings(measured));
474
+ warnings.push(...pictureCornerWarnings(measured));
475
+ warnings.push(...lensWarnings(measured));
476
+ warnings.push(...lensOffSlideWarnings(measured));
477
+ warnings.push(...wordFitWarnings(measured));
478
+ if (measurePhone) {
479
+ const phone = await measurePhone(deckDir, slideStyles(html, manifest));
480
+ warnings.push(...wordFitWarnings(phone, { phone: true }));
481
+ warnings.push(...pictureFitWarnings(phone, { phone: true }));
482
+ warnings.push(...pictureCornerWarnings(phone, { phone: true }));
483
+ warnings.push(...lensOffSlideWarnings(phone, { phone: true }));
484
+ }
485
+ // Bars need ffmpeg; without it the rest of the layout check still stands.
486
+ if (readBars) {
487
+ try {
488
+ warnings.push(...barsWarnings(measured, await readBars(deckDir, measured)));
489
+ } catch (e) {
490
+ warnings.push(MESSAGES.barsUnchecked(e.message));
491
+ }
492
+ }
197
493
  } catch (e) {
198
494
  warnings.push(MESSAGES.layoutUnchecked(e.message));
199
495
  }
@@ -221,7 +517,7 @@ export async function checkDeck(dirArg, opts = {}, { fetch: fetchImpl = globalTh
221
517
  }
222
518
  return {
223
519
  deckDir,
224
- slug: opts.slug || basename(deckDir),
520
+ slug: deckSlug(deckDir, opts),
225
521
  ...result,
226
522
  passed: errors.length === 0,
227
523
  warnings: [...new Set(warnings)],