@hypersocial/decks-cli 0.9.23 → 0.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/hyperdecks/SKILL.md +124 -67
- package/skills/hyperdecks/chat.md +11 -8
- package/skills/hyperdecks/terminal.md +83 -0
- package/src/bars.mjs +268 -0
- package/src/brand.mjs +51 -8
- package/src/check.mjs +333 -20
- package/src/checkRules.mjs +677 -27
- package/src/commands.mjs +171 -31
- package/src/deckSlug.mjs +41 -0
- package/src/embedCapture.mjs +126 -0
- package/src/embedSources.mjs +252 -0
- package/src/embedsGuide.mjs +36 -0
- package/src/export-video.mjs +20 -3
- package/src/files.mjs +36 -0
- package/src/guide.mjs +93 -13
- package/src/hosted.mjs +18 -8
- package/src/iconAliasNames.mjs +70 -0
- package/src/iconChoice.mjs +97 -0
- package/src/iconSets.mjs +89 -0
- package/src/iconSlots.mjs +48 -0
- package/src/icons.mjs +285 -45
- package/src/iconsCli.mjs +76 -0
- package/src/layoutRoutes.mjs +97 -0
- package/src/layouts.mjs +9 -4
- package/src/mediaPreviews.mjs +3 -1
- package/src/narrate.mjs +31 -4
- package/src/opening.mjs +9 -3
- package/src/ops.mjs +125 -0
- package/src/photosGuide.mjs +47 -0
- package/src/picturesGuide.mjs +54 -0
- package/src/play.mjs +3 -2
- package/src/presenter.mjs +3 -1
- package/src/preview-capture.mjs +70 -1
- package/src/release.mjs +13 -5
- package/src/runtime.mjs +9 -2
- package/src/scaffold.mjs +73 -13
- package/src/source.mjs +86 -14
- package/src/stockMedia.mjs +299 -0
- package/src/themeCli.mjs +41 -0
- package/src/themes.mjs +345 -0
- package/templates/icons/material.LICENSE +202 -0
- package/templates/icons/material.json.gz +0 -0
- package/templates/icons/phosphor.LICENSE +21 -0
- package/templates/icons/phosphor.json.gz +0 -0
- package/templates/icons/tabler.LICENSE +21 -0
- package/templates/icons/tabler.json.gz +0 -0
- package/templates/layouts/_deck.html +231 -41
- package/templates/layouts/bento.html +76 -0
- package/templates/layouts/chart.html +6 -4
- package/templates/layouts/closer.html +13 -4
- package/templates/layouts/compare.html +13 -4
- package/templates/layouts/cover-band.html +13 -9
- package/templates/layouts/cover-frame.html +13 -7
- package/templates/layouts/cover-poster.html +9 -5
- package/templates/layouts/cover-split.html +19 -7
- package/templates/layouts/cover-type.html +2 -1
- package/templates/layouts/embed.html +93 -0
- package/templates/layouts/features.html +18 -10
- package/templates/layouts/funnel.html +62 -0
- package/templates/layouts/hero.html +41 -23
- package/templates/layouts/lanes.html +63 -0
- package/templates/layouts/loop.html +81 -0
- package/templates/layouts/number.html +3 -2
- package/templates/layouts/phone-stage.html +78 -0
- package/templates/layouts/phones.html +1 -0
- package/templates/layouts/picture-full.html +58 -0
- package/templates/layouts/portrait.html +53 -0
- package/templates/layouts/product.html +7 -6
- package/templates/layouts/quote.html +5 -3
- package/templates/layouts/rail.html +74 -0
- package/templates/layouts/scorecard.html +71 -0
- package/templates/layouts/screens.html +85 -0
- package/templates/layouts/sentence.html +39 -0
- package/templates/layouts/split.html +35 -7
- package/templates/layouts/spotlight.html +80 -0
- package/templates/layouts/stack.html +84 -0
- package/templates/layouts/staircase.html +78 -0
- package/templates/layouts/strike.html +46 -0
- package/templates/layouts/tap-through.html +73 -0
- package/templates/layouts/team.html +21 -6
- package/templates/layouts/timeline.html +21 -8
- package/templates/layouts/two-bars.html +53 -0
- package/templates/layouts/two-by-two.html +75 -0
- package/templates/layouts/video-beats.html +66 -0
- package/templates/layouts/video-full.html +62 -0
- package/templates/layouts/wall.html +109 -0
- package/templates/layouts/zoom.html +144 -0
- package/templates/narrated-deck.html +12 -7
- package/templates/script.md +2 -2
- /package/templates/icons/{LICENSE → lucide.LICENSE} +0 -0
package/src/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 {
|
|
13
|
-
import {
|
|
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)
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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,17 +97,152 @@ 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
|
-
|
|
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 (­) 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()) } : {}), ...(slide.hasAttribute("data-flip") ? { flipped: true } : {}) };
|
|
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
|
|
86
238
|
// phone rules at a 390×844 viewport, its mobile titles, inside the card, with
|
|
87
239
|
// JavaScript off. Returns { id, overflow } per slide: how far its content runs
|
|
88
|
-
// past the slide's bottom (≤ 0 when it fits).
|
|
89
|
-
|
|
90
|
-
|
|
240
|
+
// past the slide's bottom (≤ 0 when it fits). noPresenter lays it out as the
|
|
241
|
+
// player shows a deck with no presenter (.hd-no-presenter on the root: no foot
|
|
242
|
+
// kept clear), so a silent deck is not held to the presenter's room.
|
|
243
|
+
export async function measurePhoneFit(deckDir, { noPresenter = false } = {}) {
|
|
244
|
+
return withDeckPage(deckDir, { width: PHONE.width, height: PHONE.height }, (page) => page.evaluate(([card, noPresenter]) => {
|
|
245
|
+
if (noPresenter) document.documentElement.classList.add("hd-no-presenter");
|
|
91
246
|
for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile;
|
|
92
247
|
const sections = [...document.querySelectorAll("section.slide")];
|
|
93
248
|
const host = sections[0]?.parentElement ?? document.body;
|
|
@@ -97,12 +252,72 @@ export async function measurePhoneFit(deckDir) {
|
|
|
97
252
|
sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0", overflow: "hidden" }); });
|
|
98
253
|
return { id: slide.id, overflow: slide.scrollHeight - slide.clientHeight };
|
|
99
254
|
});
|
|
100
|
-
}, PHONE.card));
|
|
255
|
+
}, [PHONE.card, noPresenter]));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// How much of each slide's height holds content on a phone, laid out as
|
|
259
|
+
// measurePhoneFit does: from the top of the first thing drawn (text, a picture,
|
|
260
|
+
// a frame, a card) to the bottom of the last, over the card's height. The
|
|
261
|
+
// presenter's slot and decorations do not count; a picture inside zoom's lens
|
|
262
|
+
// counts as the lens, and a contained <video> as its picture. Returns
|
|
263
|
+
// { id, layout, top, bottom, share, hole, start, minFont, clipped } per slide. The free height above the
|
|
264
|
+
// presenter (28 to 566 of 736px) caps share at about 0.73. `hole`: the tallest empty band between two drawn things;
|
|
265
|
+
// `start`: the top of the first thing drawn, a text's top clamped to its element's box (a display title's glyphs reach above
|
|
266
|
+
// its line box by an amount that depends on the font); `minFont`: the smallest font size, in px, of any text shown;
|
|
267
|
+
// `clipped`: how many drawn things and text lines run past the card's edge by more than 1px.
|
|
268
|
+
export async function measurePhoneContent(deckDir) {
|
|
269
|
+
return withDeckPage(deckDir, { width: PHONE.width, height: PHONE.height }, (page) => page.evaluate((card) => {
|
|
270
|
+
for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile;
|
|
271
|
+
const sections = [...document.querySelectorAll("section.slide")];
|
|
272
|
+
const host = sections[0]?.parentElement ?? document.body;
|
|
273
|
+
Object.assign(host.style, { position: "relative", width: `${card.width}px`, height: `${card.height}px`, overflow: "hidden", margin: "0" });
|
|
274
|
+
document.body.style.margin = "0";
|
|
275
|
+
const DRAWN = "img, video, svg, canvas, .shot, .pic, .art, .frame, .clip, .lens, .card, .panel, .pill, .sticker, .face, .avatar, .cta, .figure, .stages > li";
|
|
276
|
+
return sections.map((slide) => {
|
|
277
|
+
sections.forEach((s) => { s.style.display = s === slide ? "" : "none"; Object.assign(s.style, { position: "absolute", inset: "0", overflow: "hidden" }); });
|
|
278
|
+
const sr = slide.getBoundingClientRect();
|
|
279
|
+
const skip = (n) => !!n.closest(".narration-slot, .deco, [hidden]") || !!n.parentElement?.closest(".lens");
|
|
280
|
+
const rects = [];
|
|
281
|
+
let start = Infinity;
|
|
282
|
+
for (const n of slide.querySelectorAll(`${DRAWN}, .l-spotlight .row > li`)) {
|
|
283
|
+
if (skip(n) || getComputedStyle(n).display === "none") continue;
|
|
284
|
+
let r = n.getBoundingClientRect();
|
|
285
|
+
if (n.tagName === "VIDEO" && n.videoWidth && getComputedStyle(n).objectFit === "contain") {
|
|
286
|
+
// Its picture inside the box, where object-position puts it (computed as "x% y%" or px).
|
|
287
|
+
const k = Math.min(r.width / n.videoWidth, r.height / n.videoHeight), h = n.videoHeight * k;
|
|
288
|
+
const y = getComputedStyle(n).objectPosition.split(" ")[1] ?? "50%";
|
|
289
|
+
const top = r.top + (y.endsWith("%") ? (r.height - h) * parseFloat(y) / 100 : parseFloat(y) || 0);
|
|
290
|
+
r = { left: r.left, right: r.right, top, bottom: top + h, width: r.width, height: h };
|
|
291
|
+
}
|
|
292
|
+
if (r.width > 2 && r.height > 2) { rects.push(r); if (r.bottom > sr.top && r.top < sr.bottom) start = Math.min(start, r.top); }
|
|
293
|
+
}
|
|
294
|
+
const walker = document.createTreeWalker(slide, NodeFilter.SHOW_TEXT);
|
|
295
|
+
let minFont = Infinity;
|
|
296
|
+
for (let t; (t = walker.nextNode());) {
|
|
297
|
+
if (!t.textContent.trim() || skip(t.parentElement) || t.parentElement.closest("svg")) continue;
|
|
298
|
+
const range = document.createRange();
|
|
299
|
+
range.selectNodeContents(t);
|
|
300
|
+
let shown = false;
|
|
301
|
+
const box = t.parentElement.getBoundingClientRect().top;
|
|
302
|
+
for (const r of range.getClientRects()) if (r.width && r.height) { rects.push(r); if (r.bottom > sr.top && r.top < sr.bottom) { shown = true; start = Math.min(start, Math.max(r.top, box)); } }
|
|
303
|
+
if (shown) minFont = Math.min(minFont, parseFloat(getComputedStyle(t.parentElement).fontSize));
|
|
304
|
+
}
|
|
305
|
+
const seen = rects.filter((r) => r.bottom > sr.top && r.top < sr.bottom);
|
|
306
|
+
const clipped = rects.filter((r) => r.left < sr.left - 1 || r.right > sr.right + 1 || r.top < sr.top - 1 || r.bottom > sr.bottom + 1).length;
|
|
307
|
+
const layout = [...slide.classList].find((c) => c.startsWith("l-"))?.slice(2) ?? null;
|
|
308
|
+
if (!seen.length) return { id: slide.id, layout, top: 0, bottom: 0, share: 0, hole: 0, start: 0, minFont: null, clipped };
|
|
309
|
+
const top = Math.max(sr.top, Math.min(...seen.map((r) => r.top))), bottom = Math.min(sr.bottom, Math.max(...seen.map((r) => r.bottom)));
|
|
310
|
+
// The tallest empty band between two drawn things (a hole in the block).
|
|
311
|
+
let hole = 0, reach = -Infinity;
|
|
312
|
+
for (const r of [...seen].sort((a, b) => a.top - b.top)) { if (reach > -Infinity) hole = Math.max(hole, r.top - reach); reach = Math.max(reach, r.bottom); }
|
|
313
|
+
return { id: slide.id, layout, top: Math.round(top - sr.top), bottom: Math.round(bottom - sr.top), share: (bottom - top) / sr.height, hole: Math.round(hole), start: Math.round(Math.max(sr.top, start) - sr.top), minFont: Number.isFinite(minFont) ? minFont : null, clipped };
|
|
314
|
+
});
|
|
315
|
+
}, PHONE.card), { mobileTitles: true });
|
|
101
316
|
}
|
|
102
317
|
|
|
103
318
|
// Open the deck's index.html in Chromium at `viewport` with JavaScript off and
|
|
104
319
|
// hand the page to `measure`. Needs `hyperdecks preview setup`.
|
|
105
|
-
async function withDeckPage(deckDir, viewport, measure) {
|
|
320
|
+
async function withDeckPage(deckDir, viewport, measure, { mobileTitles = false } = {}) {
|
|
106
321
|
const { chromium } = await import("playwright");
|
|
107
322
|
const { serveSource, routeCaptureRequest } = await import("./preview-capture.mjs");
|
|
108
323
|
const { mkdtemp, rm } = await import("node:fs/promises");
|
|
@@ -123,6 +338,7 @@ async function withDeckPage(deckDir, viewport, measure) {
|
|
|
123
338
|
const page = await context.newPage();
|
|
124
339
|
await page.goto(server.url, { waitUntil: "load", timeout: 30000 });
|
|
125
340
|
await page.evaluate(() => document.fonts.ready);
|
|
341
|
+
if (mobileTitles) await page.evaluate(() => { for (const n of document.querySelectorAll("[data-title-mobile]")) n.textContent = n.dataset.titleMobile; });
|
|
126
342
|
return await measure(page);
|
|
127
343
|
} finally {
|
|
128
344
|
await server?.close().catch(() => {});
|
|
@@ -131,6 +347,59 @@ async function withDeckPage(deckDir, viewport, measure) {
|
|
|
131
347
|
}
|
|
132
348
|
}
|
|
133
349
|
|
|
350
|
+
// The bars (bars.mjs's measureBars) of each file measureLayout found framed, as a Map from its src to
|
|
351
|
+
// barsResult. A deck file is read where it is (only inside the deck folder); a URL is fetched when its
|
|
352
|
+
// 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,
|
|
353
|
+
// and a missing file is localRef's error.
|
|
354
|
+
const MAX_BARS_FETCH = 25 * 1024 * 1024, BARS_FETCH_MS = 30_000;
|
|
355
|
+
export async function measureFramedBars(deckDir, measured, { fetch: fetchImpl = globalThis.fetch, ffmpeg = null, allowDestination = null } = {}) {
|
|
356
|
+
const { measureBars } = await import("./bars.mjs");
|
|
357
|
+
const { allowCaptureDestination, localStaticFile } = await import("./preview-capture.mjs");
|
|
358
|
+
allowDestination ??= allowCaptureDestination;
|
|
359
|
+
const { bundledFfmpeg, knownMedia } = await import("./mediaPreviewMake.mjs");
|
|
360
|
+
const { mkdtemp, rm, writeFile } = await import("node:fs/promises");
|
|
361
|
+
const { tmpdir } = await import("node:os");
|
|
362
|
+
const files = new Map();
|
|
363
|
+
for (const f of measured.flatMap((m) => m.framed ?? [])) if (!files.has(f.src)) files.set(f.src, f);
|
|
364
|
+
const out = new Map();
|
|
365
|
+
if (!files.size) return out;
|
|
366
|
+
const ff = ffmpeg ?? await bundledFfmpeg();
|
|
367
|
+
const root = realpathSync(deckDir);
|
|
368
|
+
const temp = await mkdtemp(join(tmpdir(), "hd-bars-"));
|
|
369
|
+
try {
|
|
370
|
+
let i = 0;
|
|
371
|
+
for (const [src, f] of files) {
|
|
372
|
+
try {
|
|
373
|
+
let input;
|
|
374
|
+
if (f.local) {
|
|
375
|
+
input = realpathSync(resolve(root, src));
|
|
376
|
+
if (!input.startsWith(root + sep)) continue;
|
|
377
|
+
} else if (localStaticFile(src) !== undefined) {
|
|
378
|
+
// From a repo checkout, the app's own stills are the checkout's files, never fetched.
|
|
379
|
+
input = localStaticFile(src);
|
|
380
|
+
if (!input) continue;
|
|
381
|
+
} else {
|
|
382
|
+
// A deck (a hosted draft a chat agent wrote) must not reach this machine's own network:
|
|
383
|
+
// the capture's rule, a public address only, and no redirect to one that is not.
|
|
384
|
+
if (!/^https?:/.test(src) || !(await allowDestination(src, "http://deck.invalid/"))) continue;
|
|
385
|
+
const res = await fetchImpl(src, { redirect: "error", signal: AbortSignal.timeout(BARS_FETCH_MS) });
|
|
386
|
+
if (!res.ok || Number(res.headers.get("content-length")) > MAX_BARS_FETCH) { await res.body?.cancel?.().catch(() => {}); continue; }
|
|
387
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
388
|
+
if (bytes.byteLength > MAX_BARS_FETCH || !knownMedia(bytes)) continue;
|
|
389
|
+
input = join(temp, `f${i++}`);
|
|
390
|
+
await writeFile(input, bytes);
|
|
391
|
+
}
|
|
392
|
+
out.set(src, await measureBars(ff, input, { video: f.kind === "video" }));
|
|
393
|
+
} catch {
|
|
394
|
+
// unreadable here: no bars warning for it
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} finally {
|
|
398
|
+
await rm(temp, { recursive: true, force: true }).catch(() => {});
|
|
399
|
+
}
|
|
400
|
+
return out;
|
|
401
|
+
}
|
|
402
|
+
|
|
134
403
|
// "<slug>" means ./decks/<slug> unless it names a folder itself.
|
|
135
404
|
export function resolveDeckDir(arg, cwd = process.cwd()) {
|
|
136
405
|
if (!arg) throw new Error("usage: check <slug|deck-dir>");
|
|
@@ -179,6 +448,20 @@ export function deckFolder(deckDir) {
|
|
|
179
448
|
pathExists: deckPathResolver(deckDir),
|
|
180
449
|
isDir: deckPathResolver(deckDir, { kind: "dir" }),
|
|
181
450
|
read: (path) => readFileSync(join(deckDir, path), "utf8"),
|
|
451
|
+
// The first bytes of a file inside the folder (a <video>'s src or poster), for its kind.
|
|
452
|
+
readBytes: (ref) => {
|
|
453
|
+
let path;
|
|
454
|
+
try { path = decodeURIComponent(ref); } catch { path = ref; }
|
|
455
|
+
if (deckPathResolver(deckDir)(path) !== true) throw new Error("not in the deck folder");
|
|
456
|
+
// Only the first bytes: a recording can be large.
|
|
457
|
+
const fd = openSync(isAbsolute(path) ? join(realpathSync(deckDir), path) : resolve(deckDir, path), "r");
|
|
458
|
+
try {
|
|
459
|
+
const head = Buffer.alloc(16);
|
|
460
|
+
return head.subarray(0, readSync(fd, head, 0, 16, 0));
|
|
461
|
+
} finally {
|
|
462
|
+
closeSync(fd);
|
|
463
|
+
}
|
|
464
|
+
},
|
|
182
465
|
};
|
|
183
466
|
}
|
|
184
467
|
|
|
@@ -186,19 +469,49 @@ export function deckFolder(deckDir) {
|
|
|
186
469
|
// (the hosted release measures a draft the same way, from a temp folder). A
|
|
187
470
|
// presenter over the title is a warning, not a failure: only a person can judge
|
|
188
471
|
// 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
|
|
190
|
-
|
|
472
|
+
// scrolls a slide. A cover whose title lands on its picture is a warning, and so is a picture that
|
|
473
|
+
// 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.
|
|
474
|
+
// The pictures again as a phone shows them (its frames have other shapes).
|
|
475
|
+
const measurePhonePictures = (deckDir, styles) => measureLayout(deckDir, styles, { width: PHONE.width, height: PHONE.height, card: PHONE.card });
|
|
476
|
+
// A caller that injects `measure` and no `measurePhone` gets no phone pass.
|
|
477
|
+
// `readBars` reads the framed files for bars (measureFramedBars; a caller that injects `measure` and no
|
|
478
|
+
// `readBars` gets none).
|
|
479
|
+
export async function layoutCheck(deckDir, html, manifest = null, { measure = measureLayout, measureFit = measurePhoneFit, measurePhone = measure === measureLayout ? measurePhonePictures : null, readBars = measure === measureLayout ? measureFramedBars : null } = {}) {
|
|
191
480
|
const errors = [], warnings = [];
|
|
192
481
|
const { width: w, height: h } = stageSize(html);
|
|
193
482
|
try {
|
|
194
483
|
const measured = await measure(deckDir, slideStyles(html, manifest), { width: w, height: h });
|
|
195
|
-
|
|
484
|
+
// A silent deck with no presenter (silentWithoutPresenter) has nothing in the corner to overlap.
|
|
485
|
+
if (!silentWithoutPresenter(html)) {
|
|
486
|
+
warnings.push(...overlapWarnings(measured, `${w}×${h}`));
|
|
487
|
+
warnings.push(...presenterMediaWarnings(measured, `${w}×${h}`));
|
|
488
|
+
}
|
|
196
489
|
warnings.push(...coverTextWarnings(measured));
|
|
490
|
+
warnings.push(...pictureFitWarnings(measured));
|
|
491
|
+
warnings.push(...pictureCornerWarnings(measured));
|
|
492
|
+
warnings.push(...lensWarnings(measured));
|
|
493
|
+
warnings.push(...lensOffSlideWarnings(measured));
|
|
494
|
+
warnings.push(...wordFitWarnings(measured));
|
|
495
|
+
if (measurePhone) {
|
|
496
|
+
const phone = await measurePhone(deckDir, slideStyles(html, manifest));
|
|
497
|
+
warnings.push(...wordFitWarnings(phone, { phone: true }));
|
|
498
|
+
warnings.push(...pictureFitWarnings(phone, { phone: true }));
|
|
499
|
+
warnings.push(...pictureCornerWarnings(phone, { phone: true }));
|
|
500
|
+
warnings.push(...lensOffSlideWarnings(phone, { phone: true }));
|
|
501
|
+
}
|
|
502
|
+
// Bars need ffmpeg; without it the rest of the layout check still stands.
|
|
503
|
+
if (readBars) {
|
|
504
|
+
try {
|
|
505
|
+
warnings.push(...barsWarnings(measured, await readBars(deckDir, measured)));
|
|
506
|
+
} catch (e) {
|
|
507
|
+
warnings.push(MESSAGES.barsUnchecked(e.message));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
197
510
|
} catch (e) {
|
|
198
511
|
warnings.push(MESSAGES.layoutUnchecked(e.message));
|
|
199
512
|
}
|
|
200
513
|
try {
|
|
201
|
-
errors.push(...phoneOverflowErrors(await measureFit(deckDir)));
|
|
514
|
+
errors.push(...phoneOverflowErrors(await measureFit(deckDir, { noPresenter: silentWithoutPresenter(html) })));
|
|
202
515
|
} catch (e) {
|
|
203
516
|
warnings.push(MESSAGES.layoutUnchecked(e.message));
|
|
204
517
|
}
|
|
@@ -221,7 +534,7 @@ export async function checkDeck(dirArg, opts = {}, { fetch: fetchImpl = globalTh
|
|
|
221
534
|
}
|
|
222
535
|
return {
|
|
223
536
|
deckDir,
|
|
224
|
-
slug:
|
|
537
|
+
slug: deckSlug(deckDir, opts),
|
|
225
538
|
...result,
|
|
226
539
|
passed: errors.length === 0,
|
|
227
540
|
warnings: [...new Set(warnings)],
|