@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/icons.mjs CHANGED
@@ -1,66 +1,306 @@
1
- // hyperdecks icons search <word> [--limit N] [--stroke-width N]
1
+ // hyperdecks icons search <word> [--for <layout>] [--set lucide|phosphor|tabler|material|all] [--weight W] [--deck <dir>]
2
+ // hyperdecks icons sets · hyperdecks icons use <deck-dir> <set> [weight]
2
3
  //
3
- // The icon library: Lucide's open-source line icons (ISC licence, vendored in
4
- // templates/icons/lucide.json by scripts/sync-icons.mjs). A search returns
5
- // inline SVG stroked in currentColor, so a pasted icon takes the colour of the
6
- // text around it, i.e. the deck's palette. No network and no credits; for
7
- // illustrated icons in a style of your own, `hyperdecks icons <subject...>
8
- // --style` (generate_icon_set) still draws them.
9
- import { packageText } from "./files.mjs";
4
+ // The icon library: four open-source sets vendored in templates/icons/ by
5
+ // scripts/sync-icons.mjs (iconSets.mjs): Lucide line icons (ISC), Phosphor in
6
+ // six weights (MIT), Tabler outline and fill (MIT), Material Symbols outline
7
+ // and fill (Apache-2.0). A search returns inline SVG in currentColor, so a
8
+ // pasted icon takes the colour of the text around it, i.e. the deck's palette,
9
+ // and in a layout's icon slot the theme draws it (size, tile, line weight).
10
+ // It looks in the deck's recorded set and weight (<meta name="hd-icons">) when
11
+ // there is one, else in every set, each result labelled with its set and
12
+ // weight. No network and no credits; for illustrated icons in a style of your
13
+ // own, `hyperdecks icons <subject...> --style` (generate_icon_set) still draws them.
14
+ // The CLI commands (reading a local deck folder) live in iconsCli.mjs, out of the hosted route's bundle.
15
+ import { ICON_ALIAS_NAMES } from "./iconAliasNames.mjs";
16
+ import { ICON_SET_IDS, deckIconChoice, loadIconSet, nearestWeight, recordIconChoice, renderIcon, setWeight } from "./iconSets.mjs";
17
+ import { ICON_SLOT_LAYOUTS, iconSlot } from "./iconSlots.mjs";
18
+
19
+ export { ICON_SET_IDS, deckIconChoice, iconChoiceTag, listIconSets, recordIconChoice } from "./iconSets.mjs";
20
+ export { ICON_SLOTS, ICON_SLOT_LAYOUTS, fillIconSlots, iconSlot } from "./iconSlots.mjs";
10
21
 
11
22
  export const MAX_ICON_RESULTS = 24;
12
23
  const DEFAULT_RESULTS = 8;
13
- let library;
14
- const lib = () => (library ??= JSON.parse(packageText("templates/icons/lucide.json")));
15
24
 
16
- export function iconSvg(name, { strokeWidth = 2 } = {}) {
17
- const icon = lib().icons[name];
18
- if (!icon) return null;
19
- const sw = Number(strokeWidth);
20
- const width = Number.isFinite(sw) && sw > 0 && sw <= 4 ? sw : 2;
21
- return `<svg class="icon lucide-${name}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${icon[0]}</svg>`;
25
+ export function iconSvg(name, { strokeWidth = 2, set = "lucide", weight } = {}) {
26
+ return renderIcon(set, name, { weight, strokeWidth });
27
+ }
28
+
29
+ // The plain words an agent tries that Lucide's names and tags miss or rank badly ("customer", "revenue",
30
+ // "hire"), each with the icons that fit it, best first. Measured on the 50 everyday concepts in
31
+ // lib/deckIcons.test.ts: before this table 28 of 50 had a fitting icon in the top three, after it 50. A second,
32
+ // held-out list of 50 (verbs and abstract nouns included): 14 before, 15 with whole-word matching and plain forms alone,
33
+ // 50 once the second half of the table was written from its misses. A third list of 30, written before that half and
34
+ // not used to write it, is the honest score: see the roadmap spec.
35
+ export const ICON_ALIASES = {
36
+ money: ["banknote", "coins", "wallet"], revenue: ["trending-up", "chart-line", "banknote"], cost: ["receipt", "wallet", "coins"],
37
+ price: ["tag", "circle-dollar-sign"], sell: ["tag", "store"], buy: ["shopping-cart", "credit-card"], payment: ["credit-card", "banknote"],
38
+ saving: ["piggy-bank", "hand-coins"], grow: ["trending-up", "sprout"], growth: ["trending-up", "sprout", "chart-line"],
39
+ safety: ["shield", "shield-check"], security: ["shield", "lock", "shield-check"], privacy: ["lock", "eye-off"], trust: ["shield-check", "handshake"],
40
+ team: ["users"], people: ["users"], customer: ["user", "users"], user: ["user"], family: ["users", "house"], hire: ["user-plus", "briefcase"],
41
+ job: ["briefcase"], work: ["briefcase"], speed: ["zap", "gauge"], fast: ["zap", "gauge"], time: ["clock", "timer"],
42
+ home: ["house"], email: ["mail"], mobile: ["smartphone"], app: ["smartphone", "layout-grid"], launch: ["rocket"], start: ["rocket", "play", "flag"],
43
+ win: ["trophy", "medal"], goal: ["target", "goal"], idea: ["lightbulb"], ai: ["sparkles", "bot", "brain"], automation: ["workflow", "bot"],
44
+ developer: ["code", "terminal"], tools: ["wrench", "hammer"], fix: ["wrench"], build: ["hammer", "blocks"], design: ["palette", "pen-tool"],
45
+ brand: ["sparkles", "palette"], art: ["palette", "brush"], quality: ["badge-check", "award"], done: ["circle-check", "check"], review: ["star", "message-square"],
46
+ feedback: ["message-square", "thumbs-up"], risk: ["triangle-alert"], problem: ["circle-alert", "triangle-alert"], solution: ["lightbulb", "puzzle"],
47
+ plan: ["map", "list-checks", "route"], strategy: ["target", "compass", "map"], meeting: ["users", "calendar", "presentation"], partner: ["handshake"],
48
+ deal: ["handshake"], contract: ["signature", "file-text"], legal: ["scale", "gavel"], travel: ["plane", "luggage", "map"], flight: ["plane"],
49
+ climate: ["leaf", "thermometer"], green: ["leaf"], planet: ["earth", "globe"], global: ["globe", "earth"], world: ["globe", "earth"],
50
+ health: ["heart-pulse", "stethoscope"], kid: ["baby"], child: ["baby"], learn: ["graduation-cap", "book-open"], education: ["graduation-cap", "book-open"],
51
+ data: ["database", "chart-column"], analytics: ["chart-column", "chart-line"], insight: ["eye", "lightbulb"], finish: ["flag", "circle-check"],
52
+ location: ["map-pin"], place: ["map-pin"], night: ["moon"], weather: ["cloud-sun"], shop: ["store", "shopping-bag"], delivery: ["truck", "package"],
53
+ community: ["users", "heart-handshake"], support: ["life-buoy", "headset"], help: ["life-buoy", "circle-question-mark"], voice: ["mic", "audio-lines"],
54
+ share: ["share-2", "send"], send: ["send"], connect: ["link", "plug"], integration: ["plug", "puzzle"], scale: ["layers", "trending-up"],
55
+ // Everyday verbs and abstract nouns (the held-out list in lib/deckIcons.test.ts and words like them).
56
+ neighbour: ["users", "house"], neighbor: ["users", "house"], yes: ["check", "circle-check", "thumbs-up"], no: ["x", "circle-x", "ban"],
57
+ allow: ["circle-check", "check"], allowed: ["circle-check", "check"], forbid: ["ban"], forbidden: ["ban"], ban: ["ban"],
58
+ celebrate: ["party-popper", "sparkles"], party: ["party-popper"], ask: ["message-circle-question-mark", "hand"],
59
+ talk: ["message-circle", "messages-square"], speak: ["message-circle", "mic"], discuss: ["messages-square"], conversation: ["messages-square", "message-circle"],
60
+ turn: ["refresh-cw", "rotate-cw"], rotate: ["rotate-cw", "refresh-cw"], stop: ["octagon-x", "hand", "circle-stop"],
61
+ bin: ["trash"], trash: ["trash"], rubbish: ["trash"], garbage: ["trash"], waste: ["trash", "recycle"],
62
+ garden: ["sprout", "flower-2", "shovel"], compost: ["sprout", "leaf", "recycle"], volunteer: ["hand-heart", "hand-helping"],
63
+ agree: ["thumbs-up", "handshake"], decide: ["signpost", "split"], decision: ["signpost", "split"], choice: ["signpost", "list-checks"], choose: ["list-checks", "signpost"],
64
+ warn: ["triangle-alert"], explain: ["message-square-text", "presentation"], listen: ["ear", "headphones"], question: ["circle-question-mark"],
65
+ answer: ["message-square-reply", "reply"], reply: ["reply", "message-square-reply"], thanks: ["heart", "hand-heart"], thank: ["heart", "hand-heart"], gratitude: ["heart", "hand-heart"],
66
+ welcome: ["door-open", "hand"], invite: ["mail-plus", "user-plus"], join: ["user-plus", "log-in"], signup: ["user-plus"], wait: ["hourglass", "clock"],
67
+ change: ["refresh-cw", "arrow-left-right"], improve: ["trending-up", "sparkles"], better: ["trending-up", "sparkles"], protect: ["shield", "shield-check"],
68
+ rule: ["scroll-text", "list-checks"], policy: ["scroll-text", "file-text"], schedule: ["calendar-clock", "calendar"], daily: ["calendar-days", "calendar"],
69
+ weekly: ["calendar-days", "calendar"], monthly: ["calendar-days", "calendar"], free: ["gift"], together: ["users", "handshake"],
70
+ street: ["route", "map-pin", "house"], road: ["route"], tree: ["tree-deciduous", "trees"], water: ["droplet", "droplets"], clean: ["sparkles", "spray-can"],
71
+ smell: ["wind", "flower"], progress: ["trending-up", "chart-line"], success: ["trophy", "circle-check"], failure: ["circle-x", "triangle-alert"], fail: ["circle-x"],
72
+ mistake: ["circle-x", "triangle-alert"], fun: ["party-popper"], happy: ["face-grinning", "face-slightly-smiling"], joy: ["face-grinning", "party-popper"],
73
+ calendar: ["calendar", "calendar-days"], recycle: ["recycle"], vote: ["vote"],
74
+ // A clinic deck's words (the Director's test deck, 2026-11-28), and phrases matched whole (a key with a space).
75
+ booking: ["calendar-check", "calendar"], appointment: ["calendar-check", "calendar-clock"], form: ["clipboard-list", "file-text"],
76
+ arrive: ["map-pin", "door-open"], arrival: ["map-pin", "door-open"], medication: ["pill", "pill-bottle"], medicine: ["pill", "pill-bottle"],
77
+ sms: ["message-square-text"], identity: ["id-card"], checkin: ["clipboard-check", "log-in"],
78
+ "check in": ["clipboard-check", "log-in"], "follow up": ["calendar-clock", "message-circle"], "text message": ["message-square-text", "smartphone"],
79
+ "id card": ["id-card"], "sign up": ["user-plus"], "log in": ["log-in"],
80
+ sad: ["face-slightly-frowning"], kind: ["heart", "hand-heart"], kindness: ["heart", "hand-heart"], care: ["heart", "hand-heart"], food: ["utensils", "salad", "apple"], meal: ["utensils"],
81
+ };
82
+
83
+ // The alias table names Lucide icons; in another set each name is the set's icon of that name, else its stand-in
84
+ // (iconAliasNames.mjs), else nothing. word -> the set's icon names, best first.
85
+ const setAliases = new Map();
86
+ function aliasesIn(id, word) {
87
+ // Own keys only: a query like "constructor" is not an alias.
88
+ if (!Object.hasOwn(ICON_ALIASES, word)) return undefined;
89
+ if (id === "lucide") return ICON_ALIASES[word];
90
+ if (!setAliases.has(id)) {
91
+ const icons = loadIconSet(id).icons;
92
+ const own = ICON_ALIAS_NAMES[id] ?? {};
93
+ const table = {};
94
+ for (const [w, names] of Object.entries(ICON_ALIASES)) table[w] = [...new Set(names.map((n) => (icons.has(n) ? n : Object.hasOwn(own, n) ? own[n] : null)).filter(Boolean))];
95
+ setAliases.set(id, table);
96
+ }
97
+ return setAliases.get(id)[word];
98
+ }
99
+
100
+ // A word's plain forms: the word, and with a plural, -ing or -ed taken off (neighbours → neighbour, gardening → garden).
101
+ function forms(w) {
102
+ const out = [w];
103
+ if (w.length > 4 && w.endsWith("ies")) out.push(`${w.slice(0, -3)}y`);
104
+ else if (w.length > 3 && w.endsWith("s") && !w.endsWith("ss")) out.push(w.slice(0, -1));
105
+ if (w.length > 5 && w.endsWith("ing")) out.push(w.slice(0, -3), `${w.slice(0, -3)}e`);
106
+ if (w.length > 4 && w.endsWith("ed")) out.push(w.slice(0, -2), w.slice(0, -1));
107
+ return out;
108
+ }
109
+ // How well one word (in one of its forms) names an icon. A word under four letters matches only whole (a name part or
110
+ // a tag word: "no" never finds chart-no-axes, "bin" never binary); a longer one may also start a part or sit in a tag.
111
+ function wordScore(w, name, parts, tags, aliases) {
112
+ const alias = aliases(w)?.indexOf(name) ?? -1;
113
+ let score = alias === -1 ? 0 : 40 - alias;
114
+ const short = w.length < 4;
115
+ if (parts[0] === w) score += short ? 8 : 12;
116
+ // A short word in the middle of a name is usually a qualifier, not the subject (no in chart-no-axes).
117
+ else if (!short && parts.includes(w)) score += 10;
118
+ // Only a word of five letters or more may start a longer part (rocket in rocket-launch): a four-letter one finds the
119
+ // wrong word too often (sing in single, read in reader, rest in restart).
120
+ else if (w.length >= 5 && parts.some((p) => p.startsWith(w))) score += 6;
121
+ else if (tags.includes(w)) score += 5;
122
+ else if (tags.some((t) => t.split(" ").includes(w))) score += 3;
123
+ else if (!short && tags.some((t) => t.includes(w))) score += 1;
124
+ return score;
22
125
  }
23
126
 
24
- // Best matches first: the exact name, a name starting with or containing a
25
- // word, then an exact tag, then a tag containing a word. Several words rank by
26
- // how many of them match.
27
- export function searchIcons({ query, limit, strokeWidth } = {}) {
127
+ // Which sets, and which weight in each, a search looks in: the set asked for, else the deck's recorded choice,
128
+ // else all of them (each in the weight asked for, or its nearest, or its first).
129
+ function searchPlan({ set, weight, deck }) {
130
+ const asked = set == null || set === "" ? null : String(set).toLowerCase();
131
+ if (asked && asked !== "all" && !ICON_SET_IDS.includes(asked)) throw new Error(`unknown icon set "${set}"; one of ${ICON_SET_IDS.join(", ")} or all`);
132
+ if (asked && asked !== "all") return { from: "set", plan: [[asked, setWeight(asked, weight)]] };
133
+ if (!asked && deck?.set) {
134
+ try {
135
+ return { from: "deck", plan: [[deck.set, weight ? setWeight(deck.set, weight) : deck.weight]] };
136
+ } catch (e) {
137
+ throw new Error(`${e.message} (the deck records ${deck.set} ${deck.weight}; pass set to search another set, or all)`);
138
+ }
139
+ }
140
+ const plan = ICON_SET_IDS.map((id) => [id, nearestWeight(id, weight)]).filter(([, w]) => w);
141
+ if (!plan.length) throw new Error(`no set has a ${weight} weight`);
142
+ return { from: "all", plan, skipped: ICON_SET_IDS.filter((id) => !plan.some(([p]) => p === id)) };
143
+ }
144
+
145
+ // One result as the answer gives it. A slot that is not a tile (the closer's button arrow) takes the icon bare: no
146
+ // class "icon", so the theme draws it as the text it sits in, not on a tile.
147
+ function drawn({ set: id, weight: w, name, tags, close }, strokeWidth, slot) {
148
+ const svg = renderIcon(id, name, { weight: w, strokeWidth });
149
+ return { name, set: id, weight: w, tags, close, svg: slot?.bare ? bareIcon(svg) : svg };
150
+ }
151
+ export const bareIcon = (svg) => svg.replace(/^<svg class="icon /, '<svg class="');
152
+
153
+ // Best matches first: the exact name, a name starting with or containing a word, then an exact tag, then a tag
154
+ // holding a word (wordScore); several words rank by how many match. Set order breaks ties across sets (Lucide first,
155
+ // as it always was the default).
156
+ export function searchIcons({ query, limit, strokeWidth, set, weight, deck, for: target } = {}) {
157
+ const slot = target ? iconSlot(target) : null;
28
158
  const words = String(query ?? "").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
29
159
  if (!words.length) throw new Error("search needs a word, e.g. rocket");
30
160
  const n = Math.min(Math.max(Number(limit) || DEFAULT_RESULTS, 1), MAX_ICON_RESULTS);
31
161
  const phrase = words.join("-");
162
+ const { from, plan, skipped = [] } = searchPlan({ set, weight, deck });
32
163
  const scored = [];
33
- for (const [name, [, tagText]] of Object.entries(lib().icons)) {
34
- const parts = name.split("-");
35
- const tags = tagText ? tagText.split(",") : [];
36
- let score = name === phrase ? 100 : 0;
37
- for (const w of words) {
38
- if (parts[0] === w) score += 12;
39
- else if (parts.includes(w)) score += 10;
40
- else if (name.includes(w)) score += 6;
41
- else if (tags.includes(w)) score += 5;
42
- else if (tags.some((t) => t.split(" ").includes(w))) score += 3;
43
- else if (tags.some((t) => t.includes(w))) score += 1;
164
+ plan.forEach(([id, w], order) => {
165
+ const lib = loadIconSet(id);
166
+ const at = Object.keys(lib.weights).indexOf(w);
167
+ const aliases = (word) => aliasesIn(id, word);
168
+ // A Lucide name typed as the query (mic, trending-up) finds the set's own icon for it (microphone, trend-up).
169
+ const stand = id === "lucide" || !Object.hasOwn(ICON_ALIAS_NAMES[id] ?? {}, phrase) ? null : ICON_ALIAS_NAMES[id][phrase];
170
+ // A phrase in the alias table ("check in", "text message") is matched whole, not word by word.
171
+ const phraseAlias = words.length > 1 ? aliases(words.join(" ")) : undefined;
172
+ for (const [name, [tags, marks]] of lib.icons) {
173
+ if (!marks[at]) continue;
174
+ const parts = name.split("-");
175
+ let score = name === phrase || name === stand ? 100 : 0;
176
+ const whole = phraseAlias?.indexOf(name) ?? -1;
177
+ if (whole !== -1) score += 40 * words.length - whole;
178
+ for (const word of words) score += Math.max(...forms(word).map((f) => wordScore(f, name, parts, tags, aliases)));
179
+ if (!score) continue;
180
+ // Close: the icon is named by what was asked, not by some of its words or a tag that contains one. One word: in
181
+ // the name, an alias or an exact tag; a phrase: whole (name, phrase alias, tag), or every word in the name or
182
+ // an alias ("text message" is not typography, which is tagged text and message apart).
183
+ const named = (word, tagsToo) => forms(word).some((f) => parts.includes(f) || parts.includes(`${f}s`) || aliases(f)?.includes(name) || (tagsToo && tags.includes(f)));
184
+ const close = score >= 100 || whole !== -1 || tags.includes(words.join(" ")) || (words.length === 1 ? named(words[0], true) : words.every((word) => named(word, false)));
185
+ // Plainer icons first among equals: rocket before rocket-launch.
186
+ scored.push({ set: id, weight: w, name, tags, score: score - parts.length * 0.1, order, close });
44
187
  }
45
- // Plainer icons first among equals: rocket before rocket-launch.
46
- if (score) scored.push({ name, tags, score: score - parts.length * 0.1 });
188
+ });
189
+ scored.sort((a, b) => b.score - a.score || a.order - b.order || a.name.localeCompare(b.name));
190
+ const ids = plan.map(([id]) => id);
191
+ // Nothing found: no spelling neighbours (taco -> tack, borrow -> barrow: near in letters, nowhere near in meaning). The
192
+ // answer says what was searched and how to ask again.
193
+ const none = scored.length ? null : `No icon for "${words.join(" ")}" in ${plan.map(([id, w]) => `${id} ${w}`).join(", ")}. Ask for what the picture would show in a plainer word (a taco is food: utensils; borrowing is a hand passing coins: hand coins)${from === "all" ? "" : ", or search every set (set all)"}, or leave the icon out: icons are optional.`;
194
+ // One set (asked for, or the deck's) with no close match: the closest from the other sets, each in its plainest or
195
+ // nearest weight, so the author sees what else there is without asking (--set all).
196
+ let elsewhere = null;
197
+ if (from !== "all" && !scored.slice(0, 3).some((i) => i.close)) {
198
+ const others = searchIcons({ query, limit: MAX_ICON_RESULTS, strokeWidth, set: "all", weight: weight ?? deck?.weight, for: target });
199
+ const found = others.icons.filter((i) => i.close && !ids.includes(i.set)).slice(0, 3);
200
+ if (found.length) elsewhere = found;
47
201
  }
48
- scored.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
202
+ const libs = ids.map((id) => loadIconSet(id));
49
203
  return {
50
204
  query: words.join(" "),
51
- library: lib().source,
52
- license: lib().license,
205
+ sets: plan.map(([id, w]) => `${id} ${w}`),
206
+ from,
207
+ library: libs.map((l) => l.source).join(", "),
208
+ license: libs.map((l) => `${l.name}: ${l.license}`).join("; "),
53
209
  total: scored.length,
54
- icons: scored.slice(0, n).map(({ name, tags }) => ({ name, tags, svg: iconSvg(name, { strokeWidth }) })),
55
- usage: "Paste svg inline (e.g. in .l-features .card). It is stroked in currentColor: set `color` on it or its parent to put it in the deck's palette.",
210
+ icons: scored.slice(0, n).map((i) => drawn(i, strokeWidth, slot)),
211
+ ...(elsewhere ? { elsewhere } : {}),
212
+ ...(none ? { none } : {}),
213
+ ...(slot ? { slot } : {}),
214
+ usage:
215
+ (slot
216
+ ? `For ${slot.layout}: paste one svg ${slot.where}. ${slot.oneSet}`
217
+ : `Paste svg inline in a layout's icon slot; name the layout with ${"`for`"} (${ICON_SLOT_LAYOUTS.join(", ")}) to be told where it goes. It is drawn in currentColor (line icons stroked, filled ones filled, a duotone's second tone lighter) and the theme draws it (size, tile, line weight).`) +
218
+ (from === "all" ? " Keep one set and weight per deck: record it (icons sets says how) and later searches stay in it." : "") +
219
+ (elsewhere ? ` No close match in ${plan.map(([id, w]) => `${id} ${w}`).join(", ")}; elsewhere has the closest from the other sets (set all). Using one means a second set in the deck: weigh it against a plainer word in this one.` : "") +
220
+ (skipped.length ? ` Not searched: ${skipped.join(", ")} (no ${weight} weight).` : ""),
221
+ // The deck's hand-written tag did not read (an unknown set or weight): say so rather than pass it off as its choice.
222
+ ...(deck?.problem ? { deckProblem: deck.problem } : {}),
56
223
  };
57
224
  }
58
225
 
59
- export async function icons(pos, opts = {}, { log = (line) => console.log(line) } = {}) {
60
- const out = searchIcons({ query: pos.join(" "), limit: opts.limit, strokeWidth: opts["stroke-width"] });
61
- if (opts.json) return out;
62
- if (!out.icons.length) log(`no icons match "${out.query}"; try a plainer word (e.g. chart, user, lock)`);
63
- for (const icon of out.icons) log(`${icon.name}${icon.tags.length ? ` (${icon.tags.slice(0, 5).join(", ")})` : ""}\n${icon.svg}\n`);
64
- if (out.icons.length) log(`${out.icons.length} of ${out.total} from ${out.library}. ${out.usage}`);
65
- return out;
226
+ // search_icons on both MCP servers: with a slug, the hosted draft's recorded set and weight are the default
227
+ // (readDeckHtml reads its index.html, as get_deck_source does, so only a deck you can read answers).
228
+ export async function searchDeckIcons({ slug, ...args } = {}, readDeckHtml) {
229
+ let deck = null;
230
+ // A deck whose draft cannot be read here (an imported deck stored as a file, a local-only deck) still gets a
231
+ // search, across all sets, with the reason it could not use the deck's choice.
232
+ if (slug) {
233
+ try {
234
+ deck = deckIconChoice(await readDeckHtml(String(slug)));
235
+ } catch (e) {
236
+ deck = { problem: `could not read ${slug}'s draft for its icon set (${e instanceof Error ? e.message : String(e)}); searched all sets` };
237
+ }
238
+ }
239
+ // icons: the set and weight searched as the deck's; null when it records none or names no set (deckProblem says which).
240
+ return { ...searchIcons({ ...args, deck }), ...(slug ? { deck: { slug, icons: deck?.set ? `${deck.set} ${deck.weight}` : null } } : {}) };
241
+ }
242
+
243
+ // The icon a deck's library icon becomes in another set: the same name, else the stand-in the alias table gives (both
244
+ // ways, through Lucide), else the closest close match a search finds there; null when there is none.
245
+ function iconIn(from, name, to, weight) {
246
+ const icons = loadIconSet(to).icons;
247
+ const has = (n) => n && icons.has(n) && icons.get(n)[1][Object.keys(loadIconSet(to).weights).indexOf(weight)];
248
+ if (has(name)) return name;
249
+ const lucide = from === "lucide" ? name : Object.entries(ICON_ALIAS_NAMES[from] ?? {}).find(([, v]) => v === name)?.[0];
250
+ if (lucide && to === "lucide" && has(lucide)) return lucide;
251
+ const stand = lucide && Object.hasOwn(ICON_ALIAS_NAMES[to] ?? {}, lucide) ? ICON_ALIAS_NAMES[to][lucide] : null;
252
+ if (has(stand)) return stand;
253
+ const hit = searchIcons({ query: (lucide ?? name).replace(/-/g, " "), set: to, weight, limit: 1 }).icons[0];
254
+ return hit?.close ? hit.name : null;
255
+ }
256
+
257
+ // Put every library icon in a deck (the scaffold's own: features' three, split's sticker, the closer's arrow; and any
258
+ // an author pasted) into one set and weight, keeping each one's place, its other classes and whether it is an item
259
+ // icon (class "icon": the theme tiles it) or a bare glyph (the closer's arrow). An icon with no match in the set stays
260
+ // as it is and is named, so check's mix warning points at something the author can choose about.
261
+ // Only an <svg> whose own tag says it is a library icon: a comment that mentions <svg class="icon"> is not one, and must
262
+ // not swallow the icon after it.
263
+ const LIBRARY_SVG = /<svg\b(?=[^>]*(?:\bdata-icon="|\bclass="[^"]*\blucide-))[^>]*>[\s\S]*?<\/svg>/g;
264
+ export function swapDeckIcons(html, set, weight) {
265
+ const w = setWeight(set, weight);
266
+ const swapped = [];
267
+ const kept = [];
268
+ const out = html.replace(LIBRARY_SVG, (svg) => {
269
+ const open = svg.slice(0, svg.indexOf(">") + 1);
270
+ const classes = (/\bclass="([^"]*)"/.exec(open)?.[1] ?? "").split(/\s+/).filter(Boolean);
271
+ const tag = /\bdata-icon="([a-z]+) ([a-z]+)"/.exec(open);
272
+ const from = tag ? tag[1] : classes.some((c) => c.startsWith("lucide-")) ? "lucide" : null;
273
+ if (!from || !ICON_SET_IDS.includes(from)) return svg;
274
+ const name = classes.find((c) => c.startsWith(`${from}-`))?.slice(from.length + 1);
275
+ if (!name || (from === set && (tag?.[2] ?? "line") === w)) return svg;
276
+ const to = iconIn(from, name, set, w);
277
+ if (!to) {
278
+ kept.push(`${from} ${name}`);
279
+ return svg;
280
+ }
281
+ const stroke = /\bstroke-width="([\d.]+)"/.exec(open)?.[1];
282
+ const drawn = renderIcon(set, to, { weight: w, strokeWidth: stroke });
283
+ const own = classes.filter((c) => c !== "icon" && !ICON_SET_IDS.some((id) => c.startsWith(`${id}-`)));
284
+ const cls = [...(classes.includes("icon") ? ["icon"] : []), `${set}-${to}`, ...own].join(" ");
285
+ swapped.push(`${from} ${name} → ${set} ${to}`);
286
+ return drawn.replace(/^<svg class="[^"]*"/, `<svg class="${cls}"`);
287
+ });
288
+ return { html: out, set, weight: w, swapped, kept };
289
+ }
290
+
291
+ // `icons use` and use_icon_set: record the deck's set and weight and put the icons already in it into that set.
292
+ export function applyIconSet(html, set, weight) {
293
+ const id = String(set ?? "").toLowerCase();
294
+ if (!ICON_SET_IDS.includes(id)) throw new Error(`unknown icon set "${set}"; one of ${ICON_SET_IDS.join(", ")}`);
295
+ const done = swapDeckIcons(html, id, weight);
296
+ return { ...done, html: recordIconChoice(done.html, id, done.weight) };
297
+ }
298
+
299
+ // use_icon_set on both MCP servers: the hosted draft's index.html, read and written back at the rev it was read.
300
+ export async function applyDeckIconSet({ slug, set, weight } = {}, { read, write }) {
301
+ if (!slug) throw new Error("use_icon_set needs the deck's slug");
302
+ const got = await read(String(slug));
303
+ const done = applyIconSet(got.html, set, weight);
304
+ const written = await write(String(slug), done.html, got.rev);
305
+ return { slug, icons: `${done.set} ${done.weight}`, swapped: done.swapped, kept: done.kept, rev: written?.rev, note: `Recorded ${done.set} ${done.weight} (<meta name="hd-icons">); search_icons with this slug now looks in it.${done.kept.length ? ` Kept as they were (no close match in ${done.set}): ${done.kept.join(", ")}.` : ""}` };
66
306
  }
@@ -0,0 +1,76 @@
1
+ // The CLI side of the icon library: icons search, icons sets, icons use. Kept apart from icons.mjs, which the
2
+ // hosted MCP route bundles, because it reads local deck folders through check.mjs (Node and Playwright imports
3
+ // the route's bundle cannot resolve).
4
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { resolveDeckDir } from "./check.mjs";
7
+ import { ICON_SET_IDS, deckIconChoice, listIconSets, setWeight } from "./iconSets.mjs";
8
+ import { searchIcons, applyDeckIconSet, applyIconSet } from "./icons.mjs";
9
+
10
+ // The deck a CLI search reads its recorded set from: --deck <dir|slug>, else the current directory when it is a
11
+ // deck (has an index.html). Returns { dir, choice } or null.
12
+ async function deckChoiceFor(opts, cwd) {
13
+ const arg = opts.deck;
14
+ let dir;
15
+ if (arg) dir = resolveDeckDir(String(arg), cwd);
16
+ else if (existsSync(join(cwd, "index.html"))) dir = cwd;
17
+ else return null;
18
+ const path = join(dir, "index.html");
19
+ if (!existsSync(path)) throw new Error(`no index.html in ${dir}`);
20
+ return { dir, choice: deckIconChoice(readFileSync(path, "utf8")) };
21
+ }
22
+
23
+ export async function icons(pos, opts = {}, { log = (line) => console.log(line), cwd = process.cwd() } = {}) {
24
+ const deck = await deckChoiceFor(opts, cwd);
25
+ const out = searchIcons({ query: pos.join(" "), limit: opts.limit, strokeWidth: opts["stroke-width"], set: opts.set, weight: opts.weight, deck: deck?.choice, for: opts.for });
26
+ if (opts.json) return out;
27
+ if (out.deckProblem) log(`⚠ ${out.deckProblem} (fix it with: hyperdecks icons use <deck-dir> <set> [weight])`);
28
+ if (!out.icons.length) log(out.none);
29
+ for (const icon of out.icons) log(`${icon.name} · ${icon.set} ${icon.weight}${icon.tags.length ? ` (${icon.tags.slice(0, 5).join(", ")})` : ""}\n${icon.svg}\n`);
30
+ if (out.elsewhere) {
31
+ log(`No close match in ${out.sets.join(", ")}. Closest in the other sets (a second set in the deck if you use one):`);
32
+ for (const icon of out.elsewhere) log(`${icon.name} · ${icon.set} ${icon.weight}\n${icon.svg}\n`);
33
+ }
34
+ const where = out.from === "deck" ? `the deck's set (${out.sets[0]}; --set all to look wider)` : out.sets.join(", ");
35
+ if (out.icons.length) log(`${out.icons.length} of ${out.total} from ${where}. ${out.usage}`);
36
+ return out;
37
+ }
38
+
39
+ export function iconSetsCli(opts = {}, { log = (line) => console.log(line) } = {}) {
40
+ const out = listIconSets();
41
+ if (opts.json) return out;
42
+ for (const s of out.sets) {
43
+ log(`${s.id} · ${s.name}, ${s.icons} icons, weights: ${s.weights.join(", ")}\n ${s.character}\n ${s.license}\n sample: ${s.sample.map((x) => x.name).join(", ")}`);
44
+ }
45
+ log(`\nA start per theme (a suggestion): ${Object.entries(out.pairings).map(([t, p]) => `${t} ${p}`).join(", ")}.\n${out.record}`);
46
+ return out;
47
+ }
48
+
49
+ export async function iconsUse(pos, opts = {}, { log = (line) => console.log(line), cwd = process.cwd() } = {}) {
50
+ const [dirArg, set, weight] = pos;
51
+ if (!dirArg || !set) throw new Error("usage: icons use <deck-dir|slug> <set> [weight] [--hosted] (sets: hyperdecks icons sets)");
52
+ const id = String(set).toLowerCase();
53
+ if (!ICON_SET_IDS.includes(id)) throw new Error(`unknown icon set "${set}"; one of ${ICON_SET_IDS.join(", ")}`);
54
+ const w = setWeight(id, weight ?? opts.weight);
55
+ const say = (where, done) => {
56
+ log(`✓ ${where} draws its icons from ${id} ${w}; icons search there looks in it (--set all to look wider).`);
57
+ if (done.swapped.length) log(` put in ${id} ${w}: ${done.swapped.join("; ")}`);
58
+ if (done.kept.length) log(` ⚠ no close match in ${id} ${w}, left as they were (check will name them): ${done.kept.join(", ")}`);
59
+ };
60
+ // A hosted draft: read and written back at the rev read, as use_icon_set does.
61
+ if (opts.hosted) {
62
+ const { getDeckSource, writeDeckSource } = await import("./hosted.mjs");
63
+ const out = await applyDeckIconSet({ slug: dirArg, set: id, weight: w }, {
64
+ read: async (slug) => { const got = await getDeckSource(opts, { slug, file: "index.html" }); return { html: got.files["index.html"], rev: got.rev }; },
65
+ write: (slug, html, baseRev) => writeDeckSource(opts, { slug, file: "index.html", content: html, baseRev }),
66
+ });
67
+ say(`hosted ${dirArg}`, out);
68
+ return { ...out, set: id, weight: w };
69
+ }
70
+ const dir = resolveDeckDir(dirArg, cwd);
71
+ const path = join(dir, "index.html");
72
+ const done = applyIconSet(readFileSync(path, "utf8"), id, w);
73
+ writeFileSync(path, done.html);
74
+ say(dir, done);
75
+ return { dir, set: id, weight: w, swapped: done.swapped, kept: done.kept };
76
+ }
@@ -0,0 +1,92 @@
1
+ // Which layout fits which kind of idea: one table, read three ways. The guide prints it
2
+ // at the top of the layouts index (deck_guide topic layouts), `hyperdecks layouts suggest`
3
+ // matches a slide's words against each row's keywords, and check's variety warnings offer
4
+ // a row's other shapes for a slide whose layout repeats. Every layout is in at least one
5
+ // row (lib/deckGuide.test.ts holds it to LAYOUTS). Keywords are lower case and matched as
6
+ // whole words (a trailing * matches any ending), so no model call is needed.
7
+ export const ROUTES = [
8
+ { kind: "the opening", layouts: ["hero", "cover-frame", "cover-split", "cover-poster", "cover-type"], why: "a cover: a picture beside or behind a solid ground, or type alone", words: ["cover", "title", "opening", "welcome", "intro*"] },
9
+ { kind: "a process in order", layouts: ["rail", "staircase", "timeline"], why: "stops on one line; steps that build; dated", words: ["step*", "process", "how it works", "first", "then", "stage*", "onboarding", "path", "journey", "sequence", "pipeline"] },
10
+ { kind: "dates, a roadmap", layouts: ["timeline", "rail"], why: "milestones on a line", words: ["roadmap", "history", "milestone*", "years", "quarter*", "month*", "since", "launch*", "q1", "q2", "q3", "q4"] },
11
+ { kind: "a cycle", layouts: ["loop", "rail", "staircase"], why: "what feeds back into itself", words: ["cycle", "loop", "flywheel", "repeat*", "feeds back", "compound*", "virtuous"] },
12
+ { kind: "who does what", layouts: ["lanes", "rail", "team"], why: "one row per actor over the same steps", words: ["who does what", "who", "role*", "handoff", "hands off", "hand off", "owner*", "responsib*"] },
13
+ { kind: "one claim", layouts: ["sentence", "number", "quote"], why: "one line, set large", words: ["claim", "thesis", "believe", "the point", "one thing", "the idea", "bet", "insight"] },
14
+ { kind: "a correction", layouts: ["strike", "compare", "sentence"], why: "the wrong line struck, the right one under it", words: ["myth*", "wrong", "misconception*", "actually", "not really", "people think", "instead", "correct*", "rewrite"] },
15
+ { kind: "a choice among options", layouts: ["spotlight", "two-by-two"], why: "the options, the pick lit", words: ["choose", "chose", "pick*", "option*", "which one", "alternative*", "plans", "tier*", "pricing"] },
16
+ { kind: "a ranking or drop-off", layouts: ["funnel", "two-bars", "chart"], why: "each stage narrower than the last", words: ["funnel", "drop", "drops", "drop-off", "conversion", "convert*", "leads", "rank*", "churn", "signups", "sign-ups"] },
17
+ { kind: "status", layouts: ["scorecard", "number", "chart"], why: "measures against plan, a state each: scorecard; one figure: number", words: ["status", "on track", "goal*", "kpi*", "okr*", "progress", "checklist", "health", "where we stand", "monthly update"] },
18
+ { kind: "a problem or a miss, and its causes", layouts: ["bento", "features", "scorecard"], why: "the main cause big, two factors beside it; strike only for a belief that was wrong", words: ["missed", "miss", "why we", "didn't work", "did not work", "went wrong", "problem*", "failed", "fell short", "behind plan", "root cause", "causes", "lessons"] },
19
+ { kind: "one main reason and two backers", layouts: ["bento", "features"], why: "one big tile, two small", words: ["main reason", "above all", "most important", "biggest", "mainly", "headline", "and also"] },
20
+ { kind: "positioning", layouts: ["two-by-two", "compare"], why: "two axes, us in our corner", words: ["position*", "quadrant", "matrix", "competitor*", "landscape", "market map", "versus the market", "axes"] },
21
+ { kind: "two quantities", layouts: ["two-bars", "number"], why: "two bars, the gap is the point", words: ["vs", "versus", "faster", "cheaper", "slower", "times", "half", "double", "compared to", "more than", "less than"] },
22
+ { kind: "layers", layouts: ["stack", "staircase", "features"], why: "what sits on what", words: ["layer*", "stack", "built on", "architecture", "platform", "underneath", "infrastructure", "foundation"] },
23
+ { kind: "three equal things", layouts: ["features", "bento", "spotlight"], why: "three cards, none bigger (bento when one leads, spotlight when one is the pick)", words: ["three", "feature*", "reason*", "pillar*", "benefit*", "parts", "what you get"] },
24
+ { kind: "before and after", layouts: ["compare", "strike"], why: "two columns, the new one lit", words: ["before", "after", "today", "used to", "old way", "new way", "them and us", "change*"] },
25
+ { kind: "allowed and not allowed", layouts: ["compare", "strike"], why: "compare: the allowed items in the highlighted right column, both columns labelled; strike: one rule and the right way", words: ["do and don't", "dos and don'ts", "do's", "don'ts", "allowed", "not allowed", "goes in", "stays out", "never", "always", "rules", "include*", "exclude*", "avoid", "accept*", "reject*"] },
26
+ { kind: "the product", layouts: ["product", "split", "zoom", "screens"], why: "a real screenshot, framed", words: ["product", "app", "screen*", "screenshot*", "dashboard", "interface", "ui", "website", "feature", "demo", "tool"] },
27
+ { kind: "the product on a phone", layouts: ["phone-stage", "phones", "tap-through"], why: "one phone, a row of them, or one to tap", words: ["phone*", "mobile", "iphone", "ios", "android", "tap", "taps"] },
28
+ { kind: "a walk through a flow", layouts: ["screens", "tap-through", "video-beats"], why: "the screens in order, or a recording paused at each", words: ["walkthrough", "walk through", "flow", "flows", "tour", "click*", "sign up flow", "checkout"] },
29
+ { kind: "motion", layouts: ["video-full", "video-beats", "product"], why: "a recording, whole or in beats", words: ["video", "clip", "recording", "watch", "motion", "film", "footage"] },
30
+ { kind: "a place or mood", layouts: ["picture-full", "wall", "split", "cover-band"], why: "a real photo, whole, as a wall, or beside the words", words: ["place", "where", "photo*", "mood", "scene", "city", "field", "kitchen", "garden", "store", "outside", "picture*"] },
31
+ { kind: "a person", layouts: ["portrait", "quote", "team"], why: "their face and their words", words: ["person", "customer*", "said", "says", "quote", "meet", "user story", "interview*"] },
32
+ { kind: "the team", layouts: ["team", "portrait"], why: "the faces, a name and a role each", words: ["team", "founders", "who we are", "people", "hire*", "hiring"] },
33
+ { kind: "numbers", layouts: ["chart", "number", "two-bars"], why: "a trend: chart; one figure: number; two side by side: two-bars", words: ["growth", "revenue", "number*", "trend", "percent", "%", "users", "million*", "billion*", "data", "metric*", "grew", "arr", "mrr"] },
34
+ { kind: "the close or the ask", layouts: ["closer", "sentence"], why: "one ask, one way to act", words: ["ask", "next step*", "thank*", "contact", "get in touch", "try it", "call to action", "join", "invest*", "raise", "raising"] },
35
+ ];
36
+
37
+ // The table as markdown, for the layouts index.
38
+ export function routesMarkdown() {
39
+ const rows = ROUTES.map((r) => `| ${r.kind} | ${r.layouts.map((n) => `\`${n}\``).join(", ")} | ${r.why} |`);
40
+ return ["| The slide carries | Shapes, first choice first | Why |", "|---|---|---|", ...rows].join("\n");
41
+ }
42
+
43
+ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
44
+ // A keyword as a whole-word pattern: "step*" is step, steps, stepped; "%" anywhere.
45
+ const keyword = (w) => (/^\W+$/.test(w) ? new RegExp(escapeRe(w)) : new RegExp(`(?:^|[^a-z0-9'])${escapeRe(w.replace(/\*$/, "")).replace(/ /g, "\\s+")}${w.endsWith("*") ? "[a-z'-]*" : ""}(?![a-z0-9'])`));
46
+ const KEYWORDS = ROUTES.map((r) => r.words.map((w) => [w, keyword(w)]));
47
+
48
+ // The rows a slide's words match, most matches first (a longer keyword counts more: "who does what" over "who").
49
+ export function matchRoutes(text) {
50
+ const t = ` ${String(text).toLowerCase().replace(/[‘’]/g, "'")} `;
51
+ return ROUTES.map((route, i) => {
52
+ const hits = KEYWORDS[i].filter(([, re]) => re.test(t)).map(([w]) => w);
53
+ return { route, hits, score: hits.reduce((n, w) => n + w.split(" ").length, 0) };
54
+ }).filter((m) => m.score > 0).sort((a, b) => b.score - a.score);
55
+ }
56
+
57
+ // Two or three layouts for what a slide says, each with the row it came from and why.
58
+ // Empty when no keyword matches: then the table is the answer.
59
+ export function suggestLayouts(text, { limit = 3 } = {}) {
60
+ // Each matched row's first choice, best row first, then each one's second, and so on: two kinds of idea
61
+ // in one line ("a phone flow") give a shape for each rather than three of one.
62
+ const matches = matchRoutes(text);
63
+ const out = [];
64
+ for (let i = 0; out.length < limit && matches.some((m) => m.route.layouts[i]); i++) {
65
+ for (const { route, hits } of matches) {
66
+ const layout = route.layouts[i];
67
+ if (layout && out.length < limit && !out.some((s) => s.layout === layout)) out.push({ layout, kind: route.kind, why: route.why, matched: hits });
68
+ }
69
+ }
70
+ return out;
71
+ }
72
+
73
+ // Other shapes for a slide that uses `layout`: from what its words say first, then from the rows
74
+ // `layout` sits in. Never `layout` itself, nor anything in `avoid` (a layout the deck already repeats).
75
+ export function alternativesFor(layout, text = "", { avoid = [], limit = 2 } = {}) {
76
+ const skip = new Set([layout, ...avoid]);
77
+ const fromWords = matchRoutes(text).flatMap((m) => m.route.layouts);
78
+ const fromRows = ROUTES.filter((r) => r.layouts.includes(layout)).flatMap((r) => r.layouts);
79
+ const all = [...new Set([...fromWords, ...fromRows])].filter((n) => !skip.has(n) && !COVERS.has(n));
80
+ // A picture slide keeps its picture: picture layouts first, word shapes after (stable otherwise).
81
+ const ranked = PICTURE_LAYOUTS.has(layout) ? [...all.filter((n) => PICTURE_LAYOUTS.has(n)), ...all.filter((n) => !PICTURE_LAYOUTS.has(n))] : all;
82
+ return ranked.slice(0, limit);
83
+ }
84
+
85
+ // The layouts that show a picture (a screenshot, a recording, a photo, a chart). Where a row offers one of these
86
+ // and a word shape, the picture layout comes first when the material exists, so a picture slide is offered
87
+ // picture layouts before word ones (the guide wants a real picture on about every other slide).
88
+ export const PICTURE_LAYOUTS = new Set(["product", "split", "phones", "phone-stage", "tap-through", "screens", "zoom", "video-full", "video-beats", "picture-full", "wall", "portrait", "team", "chart"]);
89
+
90
+ // The covers and the closer frame a deck; they are not counted as its content.
91
+ export const COVERS = new Set(ROUTES[0].layouts.concat("cover-band"));
92
+ export const FRAME = new Set([...COVERS, "closer"]);
package/src/layouts.mjs CHANGED
@@ -6,8 +6,8 @@ import { packageText } from "./files.mjs";
6
6
  export const NARRATED_FILES = { "index.html": "narrated-deck.html", "script.md": "script.md", "evidence.md": "evidence.md" };
7
7
  // The library: the six covers first (hero is the default; a deck opens on one; the
8
8
  // clean picture covers cover-frame and cover-split next), then the rest in a sensible deck order. `--layouts` takes any order and repeats.
9
- export const LAYOUTS = ["hero", "cover-frame", "cover-split", "cover-band", "cover-poster", "cover-type", "number", "product", "split", "phones", "quote", "compare", "timeline", "features", "chart", "team", "closer"];
10
- const LAYOUT_ALIASES = { "big-number": "number", "product-shot": "product", "phone-row": "phones", comparison: "compare", "three-up": "features", "image-copy": "split", "image-text": "split" };
9
+ export const LAYOUTS = ["hero", "cover-frame", "cover-split", "cover-band", "cover-poster", "cover-type", "number", "product", "split", "phones", "phone-stage", "tap-through", "screens", "zoom", "video-full", "video-beats", "picture-full", "wall", "portrait", "quote", "compare", "timeline", "features", "sentence", "strike", "spotlight", "funnel", "scorecard", "bento", "two-by-two", "staircase", "rail", "loop", "lanes", "two-bars", "stack", "chart", "team", "closer"];
10
+ const LAYOUT_ALIASES = { "big-number": "number", "product-shot": "product", "phone-row": "phones", comparison: "compare", "three-up": "features", "image-copy": "split", "image-text": "split", "phone-centre": "phone-stage", "phone-center": "phone-stage", prototype: "tap-through", "click-through": "tap-through", "picture-strip": "screens", storyboard: "screens", flow: "screens", "detail-zoom": "zoom", video: "video-full", "full-video": "video-full", "video-moments": "video-beats", "full-picture": "picture-full", "photo-full": "picture-full", "picture-wall": "wall", "photo-wall": "wall", "portrait-line": "portrait", "one-sentence": "sentence", statement: "sentence", "big-line": "sentence", "strike-and-rewrite": "strike", "strike-rewrite": "strike", myth: "strike", rewrite: "strike", "pick-one": "spotlight", highlight: "spotlight", "one-of-many": "spotlight", pipeline: "funnel", conversion: "funnel", "score-card": "scorecard", status: "scorecard", "one-big-two-small": "bento", "big-and-small": "bento", "two-x-two": "two-by-two", "2x2": "two-by-two", quadrant: "two-by-two", matrix: "two-by-two", stairs: "staircase", "step-up": "staircase", "process-line": "rail", stops: "rail", cycle: "loop", flywheel: "loop", swimlanes: "lanes", "who-does-what": "lanes", "two-bar": "two-bars", "bar-pair": "two-bars", layers: "stack", "layer-cake": "stack" };
11
11
 
12
12
  const escapeHtml = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13
13
 
@@ -21,7 +21,7 @@ export function fillTemplate(file, { slug, title, presenterStyle }) {
21
21
  }
22
22
 
23
23
  // One layout file: a leading comment of `key: value` lines (layout, summary,
24
- // use, slot, presenter, nopresenter, cues, script), its <style> and its <section>.
24
+ // says, needs, use, slot, presenter, nopresenter, cues, script), its <style> and its <section>.
25
25
  export function readLayout(name) {
26
26
  const text = packageText(`templates/layouts/${name}.html`);
27
27
  const head = /^<!--([\s\S]*?)-->/.exec(text);
@@ -58,7 +58,7 @@ export function assembleLayoutDeck({ slug, title, presenterStyle, layouts }) {
58
58
  const fill = (text, id, t) => text.split("__ID__").join(id).split("__SLUG__").join(slug).split("__TITLE__").join(t);
59
59
  const sections = slides.map(({ layout, id }, i) => {
60
60
  let html = fill(layout.section, id, escapeHtml(title));
61
- if (i === 0 && !/\sdata-intro=/.test(html.slice(0, html.indexOf(">")))) html = html.replace("<section ", '<section data-intro="Hi! Press play." ');
61
+ if (i === 0 && !/\sdata-intro=/.test(html.slice(0, html.indexOf(">")))) html = html.replace("<section ", '<section data-intro="Welcome! Press play." ');
62
62
  return `<!-- layout: ${layout.name}. ${layout.meta.summary ?? ""} -->\n${html}`;
63
63
  });
64
64
  const styles = [...new Set(names)].map((name) => `<!-- layout: ${name} -->\n${readLayout(name).style}`);
@@ -133,7 +133,9 @@ export function withMediaPreviews(page, previews) {
133
133
  if (!p) return whole;
134
134
  count++;
135
135
  const poster = hasAttr(open, "poster") ? null : p.poster ?? null;
136
- return annotate(open, p, { ratio: !(hasAttr(open, "width") && hasAttr(open, "height")), poster }) + whole.slice(open.length);
136
+ // A video always gets its clip's shape, width/height or not: layouts choose their arrangement by it (video-full
137
+ // reads --hd-ar), and where one side is left auto the clip's own ratio wins once it loads, so --hd-ar only states it early.
138
+ return annotate(open, p, { poster }) + whole.slice(open.length);
137
139
  });
138
140
  out = out.replace(STYLED, (tag) => {
139
141
  if (/^<(img|video)\b/i.test(tag) || done(tag)) return tag;