@hypersocial/decks-cli 0.9.28 → 0.9.29

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypersocial/decks-cli",
3
- "version": "0.9.28",
3
+ "version": "0.9.29",
4
4
  "description": "Command-line client for Hypersocial Decks live analytics and share management.",
5
5
  "type": "module",
6
6
  "main": "./src/commands.mjs",
@@ -2,7 +2,7 @@
2
2
  name: hyperdecks
3
3
  description: Use when asked to make, narrate, check or ship a deck ("make me a narrated deck", "turn this into a deck and send it"), or when working with Hypersocial Decks, Hyperdecks CLI, production deck analytics, recipient share links, deck activity, MCP deck tools, or real-world/customer-facing deck checks. Prefer production for real activity and analytics; use development only for local implementation/testing when explicitly requested.
4
4
  metadata:
5
- version: "0.9.28"
5
+ version: "0.9.29"
6
6
  ---
7
7
 
8
8
  # Hyperdecks
@@ -914,6 +914,11 @@ hard-coded gutter (`padding-right: 400px`); override one in
914
914
  - Audio and data files a slide uses itself (a sound effect, a chart's JSON):
915
915
  `hyperdecks asset add` / `upload_deck_asset` take `.mp3`, `.m4a` and
916
916
  `.json` as well as images, video and fonts.
917
+ - A deck's own script files (`.js`, `.mjs`) and stylesheets (`.css`) upload
918
+ the same way, as they are: load a module with `import("<url>")`. Paths
919
+ inside an uploaded file are not rewritten (asset add warns when it names
920
+ one), so upload each file it imports and put that URL in; `import <zip>`
921
+ is the route that rewrites a whole folder.
917
922
  - `voice: dash` narrates with D.A.S.H.'s own robot voice, a synthetic
918
923
  character voice (not a clone of anyone) any account may use, for decks that
919
924
  D.A.S.H. presents. It works once the deployment sets `CHARACTER_VOICE_DASH`.
@@ -1194,7 +1199,7 @@ the hosted MCP (`deck_guide`, `new_deck`, `get_deck_source`, `write_deck_source`
1194
1199
  `upload_deck_asset`, `check_deck`, `release_deck`; see `chat.md`). Move between
1195
1200
  the two with `hyperdecks source pull <slug> [dir]` (the hosted draft into a
1196
1201
  folder) and `hyperdecks source push <slug> [dir]` (a folder's files back to the
1197
- draft), `hyperdecks asset add <slug> <file|url>` for an image, video, audio (.mp3, .m4a), font or JSON file, `hyperdecks guide
1202
+ draft), `hyperdecks asset add <slug> <file|url>` for an image, video, audio (.mp3, .m4a), font, JSON, script (.js, .mjs) or stylesheet (.css), `hyperdecks guide
1198
1203
  [topic]` for these sections, and `--hosted` on `deck new`, `check` and `release`.
1199
1204
 
1200
1205
  ## After you ship: say what cost you
@@ -0,0 +1,35 @@
1
+ // What a deck may carry as a hosted file, by extension: one table for every route
2
+ // that puts a file on a deck. `hyperdecks asset add` (a file from disk), the
3
+ // server's upload_deck_asset / `asset add <url>` (convex/lib/assetImport.ts) and
4
+ // `import <zip>` (importer.mjs) all read it, and the hosted check's remedy
5
+ // (checkRules.mjs hostedFileRemedy) names an upload for exactly these.
6
+ // A page (.html) is never an asset: it is the deck itself, served by the app.
7
+ export const ASSET_TYPES = {
8
+ png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", avif: "image/avif", svg: "image/svg+xml", ico: "image/x-icon",
9
+ mp4: "video/mp4", m4v: "video/x-m4v", webm: "video/webm", mov: "video/quicktime",
10
+ mp3: "audio/mpeg", m4a: "audio/mp4", aac: "audio/aac", wav: "audio/wav", ogg: "audio/ogg", opus: "audio/opus", flac: "audio/flac",
11
+ woff: "font/woff", woff2: "font/woff2", ttf: "font/ttf", otf: "font/otf", eot: "application/vnd.ms-fontobject",
12
+ json: "application/json",
13
+ // A deck's own scripts and styles: uploaded as they are, never rewritten.
14
+ js: "application/javascript", mjs: "application/javascript", css: "text/css",
15
+ };
16
+
17
+ export const ASSET_EXTENSIONS = Object.keys(ASSET_TYPES);
18
+
19
+ // The content type for a path's extension, or undefined when a deck can't carry it.
20
+ export function assetTypeForPath(path) {
21
+ const ext = /\.([a-z0-9]+)$/i.exec(String(path).split(/[?#]/)[0])?.[1]?.toLowerCase();
22
+ return ext && Object.hasOwn(ASSET_TYPES, ext) ? ASSET_TYPES[ext] : undefined;
23
+ }
24
+
25
+ // Content types a server may declare for a file a deck can carry. Anything else
26
+ // (text/html above all) is refused, whatever the URL's extension says.
27
+ export const ALLOWED_ASSET_TYPE = /^(image\/[\w.+-]+|video\/[\w.+-]+|audio\/[\w.+-]+|font\/[\w.+-]+|application\/(json|font-woff2?|x-font-[\w-]+|vnd\.ms-fontobject|(x-)?javascript|ecmascript)|text\/(javascript|ecmascript|css))$/;
28
+
29
+ // A page a browser would render on the storage origin: never filed as an asset on any route.
30
+ export const PAGE_TYPE = /^(text\/html|application\/xhtml\+xml)$/i;
31
+
32
+ export const isScriptType = (type) => /^(application\/(x-)?javascript|application\/ecmascript|text\/(javascript|ecmascript))$/.test(String(type));
33
+
34
+ // The table in words, for every message that says what an upload takes.
35
+ export const ASSET_KINDS = "images, video, audio, fonts, JSON, scripts and stylesheets";
@@ -9,6 +9,7 @@ import { CSS_VALUE, THEME_IDS, contrastRatio, deckTheme, findTheme, groundPairs
9
9
  import { DASH_AVATAR, presenterTagIssue } from "./presenter.mjs";
10
10
  import { deckIconChoice } from "./iconChoice.mjs";
11
11
  import { ICON_SLOTS } from "./iconSlots.mjs";
12
+ import { ASSET_EXTENSIONS, ASSET_KINDS } from "./assetTypes.mjs";
12
13
  import { FLIPPABLE, FRAME, alternativesFor } from "./layoutRoutes.mjs";
13
14
  import { embedSiteHint, resolveEmbed, sharedLinkNote } from "./embedSources.mjs";
14
15
  import { MAX_DECK_GIFS, creditLines, hasGiphyCredit, hasUnsplashCredit, stockRefs, stockSource } from "./stockMedia.mjs";
@@ -100,8 +101,8 @@ export const MESSAGES = {
100
101
  stepNested: (id) => `slide ${id}: a data-step inside a data-steps container's child; the container already steps its children, so the two fight: put data-step on the children themselves, or take data-steps off`,
101
102
  stepQuestion: (id) => `slide ${id}: a question slide has steps (data-step or data-steps); its answers must all show: take them off`,
102
103
  stepCues: (id) => `slide ${id}: it has [reveal] cues in script.md and steps in its HTML (data-step or data-steps); the narration steps by its cues and never hides the HTML steps, and presenting in person uses the HTML steps only when the cues make one part: keep one`,
103
- stepInside: (id) => `slide ${id}: a step sits inside a step with a higher number, so it cannot show before its box does (that Next shows nothing): give the inner one the same or a higher number, or move it out`,
104
- stepReveal: (id) => `slide ${id}: a step also has class "reveal", which only a narration's [reveal] cue shows, so it stays invisible for ever: take class "reveal" off it`,
104
+ stepInside: (id) => `slide ${id}: a step sits inside a step with a higher number, so it cannot show before its box does (the player shows it with its box, at the higher number): give the inner one the same or a higher number, or move it out`,
105
+ stepReveal: (id) => `slide ${id}: a step also has class "reveal", which only a narration's [reveal] cue shows, so it stays invisible for ever (the player gives it no step): take class "reveal" off it`,
105
106
  stepOnSlide: (id) => `slide ${id}: data-step or data-steps on the <section> itself does nothing; put it on the elements (data-step) or the container of the items (data-steps)`,
106
107
  questionMany: (n) => `${n} questions (a batch's items each count): a deck stores answers to its first 20 only`,
107
108
  // Warnings: a deck that declared it has no narration.
@@ -122,8 +123,18 @@ export const MESSAGES = {
122
123
  captionLength: (id, i, text) => `clip ${id}: caption ${i + 1} is ${text.length} characters ("${text}"); captions must be ${CAPTION_MIN_CHARS} to ${CAPTION_MAX_CHARS}`,
123
124
  localRef: (ref) => `local reference does not resolve: ${ref}`,
124
125
  outsideRef: (ref) => `local reference leaves the deck folder: ${ref}`,
125
- hostedRef: (ref) => `local reference ${ref}: a hosted deck has no folder, so every file must be a URL; upload it with upload_deck_asset and use the URL it returns`,
126
+ hostedRef: (ref) => `local reference ${ref}: a hosted deck has no folder, so every file must be a URL; ${hostedFileRemedy(ref)}`,
126
127
  scriptRef: (ref, from) => `${from} names ${ref}, which is not in the deck folder; add the file or fix the path`,
128
+ // A hosted deck naming relative files in a script, a data-* attribute or a JSON block: there is no folder to serve them from.
129
+ // `refs` is one path, or several in one folder rolled up.
130
+ hostedScriptRef: (refs, slideIds = [], where = "index.html's script") => `${where} names ${refList(refs)}${slideIds.length ? ` (slide ${slideIds.join(", ")})` : ""}: a hosted deck has no folder, so ${refs.length > 1 ? "each file" : "the file"} must be a URL; ${hostedFileRemedy(refs[0], { many: refs.length > 1 })}`,
131
+ // Hosted versions of the computed-path warnings: writing the paths out would only trade the warning for the error.
132
+ scriptTemplateHosted: (samples) => `index.html's script builds file paths at runtime (${samples.slice(0, 3).join(", ")}${samples.length > 3 ? ", …" : ""}); a hosted deck has no folder, so any relative path it builds 404s on the link. Build them from URLs instead (upload ${ASSET_KINDS} with upload_deck_asset)`,
133
+ scriptComputedHosted: (calls) => `index.html's script loads files from computed values (${calls.join(", ")}); a hosted deck has no folder, so a relative path among them 404s on the link. Make each one a URL (upload ${ASSET_KINDS} with upload_deck_asset)`,
134
+ // asset add: an uploaded script or stylesheet that names files beside it, which nothing rewrites.
135
+ assetRefs: (name, refs) => `${name} names ${refs.slice(0, 5).join(", ")}${refs.length > 5 ? `, and ${refs.length - 5} more` : ""}; asset add uploads one file and changes nothing inside it, so ${refs.length > 1 ? "those paths" : "that path"} won't resolve from its URL: upload each file and put its URL in, or zip the folder for \`hyperdecks import <zip>\`, which rewrites them`,
136
+ // source push: files the deck loads that stayed in the folder, one folder's worth rolled up.
137
+ notPushed: (refs, from) => `not pushed: ${refList(refs)} (${from} loads ${refs.length > 1 ? "them" : "it"}); the hosted draft has no folder, so ${hostedFileRemedy(refs[0], { cli: true, many: refs.length > 1 })}`,
127
138
  // Warnings: deliberate sometimes (a path built from a CDN base), so the deck still passes.
128
139
  scriptTemplate: (from, samples) => `${from} builds file paths at runtime (${samples.slice(0, 3).join(", ")}${samples.length > 3 ? ", …" : ""}); release can't see them, so they 404 on the shared link. Write each file out as a quoted path (an object or array of "media/…" strings, in a script or a .json file it fetches) and pick from that`,
129
140
  scriptComputed: (from, calls) => `${from} loads files from computed values (${calls.join(", ")}); release only ships files the deck names literally, so make sure each file it can load is written out as a quoted path in index.html, a script or a .json file the deck loads`,
@@ -437,8 +448,9 @@ export const normalizeWords = (text) => text.normalize("NFKD").replace(/\p{Diacr
437
448
 
438
449
  // `<section class="slide …">` blocks in document order: id, the opening tag, the
439
450
  // title (first <h1>/<h2>) and its opening tag.
451
+ const SLIDE_SECTION = /(<section\b[^>]*\sclass="(?:[^"]*\s)?slide(?:\s[^"]*)?"[^>]*>)([\s\S]*?)<\/section>/g;
440
452
  export function slides(html) {
441
- return [...uncommented(html).matchAll(/(<section\b[^>]*\sclass="(?:[^"]*\s)?slide(?:\s[^"]*)?"[^>]*>)([\s\S]*?)<\/section>/g)].map(([, tag, body]) => {
453
+ return [...uncommented(html).matchAll(SLIDE_SECTION)].map(([, tag, body]) => {
442
454
  const heading = /(<h[12]\b[^>]*>)([\s\S]*?)<\/h[12]>/.exec(body);
443
455
  return { id: attr(tag, "id") ?? "", tag, body, title: heading ? textOf(heading[2]) : "", titleTag: heading?.[1] ?? "" };
444
456
  });
@@ -539,7 +551,9 @@ export function stepWarnings(html, script = "") {
539
551
  if (got.some((n, i) => n !== i + 1)) out.push(MESSAGES.stepGap(s.id, got.join(", "), got.map((_, i) => i + 1).join(", ")));
540
552
  if (steps.some((e) => boxes.some((b) => inside(b, e) && !childOf(b, e)))) out.push(MESSAGES.stepNested(s.id));
541
553
  if (numbered.some((x) => numbered.some((y) => y.n > x.n && inside(y.e, x.e)))) out.push(MESSAGES.stepInside(s.id));
542
- if (!cued.has(s.id) && numbered.some((x) => classes(x.e.tag).includes("reveal"))) out.push(MESSAGES.stepReveal(s.id));
554
+ // A tap-through box ([data-hd-steps]) shows its .reveal items on a tap, so a step there does show.
555
+ const tapBox = (e) => hasAttr(e.tag, "data-hd-steps") || els.some((b) => hasAttr(b.tag, "data-hd-steps") && inside(b, e));
556
+ if (!cued.has(s.id) && numbered.some((x) => classes(x.e.tag).includes("reveal") && !tapBox(x.e))) out.push(MESSAGES.stepReveal(s.id));
543
557
  }
544
558
  return out;
545
559
  }
@@ -731,6 +745,148 @@ export function deckFiles(html, { pathExists: exists = () => false, read, isDir
731
745
  return { files: [...files].map(([path, from]) => ({ path, from })), missing, templates, computed };
732
746
  }
733
747
 
748
+ // What a hosted deck can upload (assetTypes.mjs: the table asset add, upload_deck_asset and import share).
749
+ export const UPLOADABLE_EXT = ASSET_EXTENSIONS;
750
+ const extOf = (path) => /\.([a-z0-9]+)$/i.exec(stripQuery(path))?.[1]?.toLowerCase() ?? "";
751
+ const refList = (refs) => refs.length === 1 ? refs[0] : `${refs.length} files in ${dirOf(deckPath("", refs[0]) ?? refs[0]) || "the deck root"} (${refs.slice(0, 2).join(", ")}, …)`;
752
+
753
+ // How a hosted deck gets a file it names by path: upload it (assetTypes.mjs says
754
+ // what a deck can carry); anything else (.wasm, a model) has no route into a
755
+ // hosted draft yet, so say so and name the way that hosts it today.
756
+ // A folder (an import map's "lib/") holds modules: each one uploads on its own.
757
+ export function hostedFileRemedy(path, { cli = false, many = false } = {}) {
758
+ const ext = extOf(path);
759
+ const [it, url, its] = many ? ["them", "URLs", "they return"] : ["it", "URL", "it returns"];
760
+ if (stripQuery(path).endsWith("/") || UPLOADABLE_EXT.includes(ext)) return cli ? `add ${it} with \`hyperdecks asset add\` and use the ${url} ${its}` : `upload ${it} with upload_deck_asset (\`hyperdecks asset add\` from the CLI) and use the ${url} ${its}`;
761
+ return `a deck that loads its own ${ext ? `.${ext}` : "extensionless"} files can't be released from source yet (upload_deck_asset takes ${ASSET_KINDS}); today the way is to zip the deck folder and bring it in with \`hyperdecks import <zip>\`, which hosts every file but takes the deck off its source draft, so check and release no longer apply`;
762
+ }
763
+
764
+ // Calls whose first string argument is a file the browser fetches, read from
765
+ // jsStrings' `code` just before the emptied string; a bare name there ("clip.mp3")
766
+ // is a file at the deck root.
767
+ const LOAD_BEFORE = /(?:\bimport\s*\(|\bimport\s+|\bfrom\s*|(?<![\w$.])fetch\s*\(|\bnew\s+(?:Audio|Worker|SharedWorker)\s*\(|\bimportScripts\s*\(|\.src\s*=)\s*$/;
768
+ // new URL('x.wasm', import.meta.url) resolves against the page, so it is a load too; with any other base it is not ours.
769
+ const URL_BEFORE = /\bnew\s+URL\s*\(\s*$/;
770
+ const URL_AFTER = /^\s*,\s*(?:import\.meta\.url|location\b|document\.baseURI|window\.location\b)/;
771
+ // Run as script: plain JS and modules, and what a shim runs (Babel's text/babel and text/jsx, es-module-shims' module-shim).
772
+ const JS_TYPE = /^(?:module|module-shim|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:babel|jsx))$/i;
773
+ // data-* the player shows as words (player.js: data-note's source line, data-title-mobile's phone title;
774
+ // data-hd-tip's tooltip; embed-frame.js: data-embed-label), so a path in them is text, not a file.
775
+ const TEXT_DATA = new Set(["data-note", "data-title-mobile", "data-hd-tip", "data-embed-label"]);
776
+ const JSON_TYPE_ATTR = /^(?:application|text)\/json$/i;
777
+
778
+ // Each slide's section as offsets into `doc`, nested <section>s counted so an
779
+ // inner one doesn't end the slide.
780
+ function slideRanges(doc) {
781
+ const out = [];
782
+ const open = /<section\b[^>]*\sclass\s*=\s*(?:"(?:[^"]*\s)?slide(?:\s[^"]*)?"|'(?:[^']*\s)?slide(?:\s[^']*)?')[^>]*>/gi;
783
+ for (const m of doc.matchAll(open)) {
784
+ if (out.some((r) => m.index > r.start && m.index < r.end)) continue;
785
+ const tags = /<(\/?)section\b[^>]*>/gi;
786
+ tags.lastIndex = m.index + m[0].length;
787
+ let depth = 1;
788
+ let end = doc.length;
789
+ for (let t; depth && (t = tags.exec(doc));) {
790
+ depth += t[1] ? -1 : 1;
791
+ if (!depth) end = t.index + t[0].length;
792
+ }
793
+ out.push({ id: attr(m[0], "id") ?? "", start: m.index, end });
794
+ }
795
+ return out;
796
+ }
797
+
798
+ // The relative files a script names, by hostedScriptRefs' rule (a path with a
799
+ // folder in it, or a bare file name a load call takes); `isMapped` skips import-map names.
800
+ // asset add reads an uploaded module with it too: those paths don't resolve from the asset's URL.
801
+ export function scriptFileRefs(src, isMapped = () => false) {
802
+ const { strings, code } = jsStrings(src);
803
+ const refs = [];
804
+ // The k-th emptied string in `code` is strings[k]: walk them to read the code around each.
805
+ let k = 0;
806
+ for (let i = 0; i < code.length; i++) {
807
+ const c = code[i];
808
+ if (c !== '"' && c !== "'" && c !== "`") continue;
809
+ const s = strings[k++];
810
+ const before = code.slice(Math.max(0, i - 80), i);
811
+ const after = code.slice(i + 2, i + 80);
812
+ i++;
813
+ if (!s || s.interpolated || isMapped(s.value) || !isScriptPath(s.value)) continue;
814
+ const loaded = LOAD_BEFORE.test(before) || (URL_BEFORE.test(before) && URL_AFTER.test(after));
815
+ if (s.value.includes("/") || loaded) refs.push(s.value);
816
+ }
817
+ return [...new Set(refs)];
818
+ }
819
+
820
+ // A hosted deck's relative files outside its src/href attributes (localRefs has
821
+ // those): paths quoted in inline scripts, data-* attribute values and JSON
822
+ // blocks. A hosted deck has no folder, so each one 404s on the link. A quoted
823
+ // string counts when it starts with ./, ../ or /, has a folder in it, or is a
824
+ // bare file name passed to a load call (import, fetch, new Audio/Worker/URL,
825
+ // importScripts, .src =); any other bare string ("worker.js") could be anything
826
+ // and stays quiet. Import-map names are skipped and their relative targets
827
+ // counted. Built and computed paths get scriptTemplateHosted/scriptComputedHosted.
828
+ // Returns [{ refs, slides, where }]: each normalised path once, and more than
829
+ // three in one folder from the same place rolled into one entry.
830
+ export function hostedScriptRefs(html) {
831
+ const doc = uncommented(html);
832
+ const ranges = slideRanges(doc);
833
+ const slideAt = (i) => ranges.filter((r) => r.start <= i && i < r.end).at(-1)?.id;
834
+ const found = new Map();
835
+ const note = (ref, where, at) => {
836
+ const key = deckPath("", ref) ?? ref;
837
+ if (!found.has(key)) found.set(key, { ref, where, slides: new Set() });
838
+ const id = at === undefined ? undefined : slideAt(at);
839
+ if (id) found.get(key).slides.add(id);
840
+ };
841
+ const pathy = (v) => isScriptPath(v) && v.includes("/"); // ./, ../ and / prefixes included
842
+ const scripts = [...doc.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
843
+ const typeOf = (attrs) => (attr(attrs, "type") ?? "").trim();
844
+ const mapped = [];
845
+ for (const m of scripts.filter(([, attrs]) => /^importmap$/i.test(typeOf(attrs)))) {
846
+ let map;
847
+ try { map = JSON.parse(m[2]); } catch { continue; }
848
+ for (const table of [map?.imports, ...Object.values(map?.scopes ?? {})]) {
849
+ for (const [k, v] of Object.entries(table ?? {})) {
850
+ mapped.push(k);
851
+ if (typeof v === "string" && !SCHEME.test(v) && (isScriptPath(v) || /^\.{0,2}\//.test(v))) note(v, "index.html's import map", m.index);
852
+ }
853
+ }
854
+ }
855
+ const isMapped = (ref) => mapped.some((k) => k === ref || (k.endsWith("/") && ref.startsWith(k)));
856
+ for (const m of scripts) {
857
+ const [, attrs, body] = m;
858
+ if (/\ssrc\s*=/i.test(attrs)) continue;
859
+ const type = typeOf(attrs);
860
+ if (JSON_TYPE_ATTR.test(type)) {
861
+ for (const s of jsStrings(body).strings) if (pathy(s.value)) note(s.value, "index.html's JSON block", m.index);
862
+ continue;
863
+ }
864
+ if (type && !JS_TYPE.test(type)) continue; // text/plain, text/template, ld+json, importmap: not run as script
865
+ for (const ref of scriptFileRefs(body, isMapped)) note(ref, "index.html's script", m.index);
866
+ }
867
+ // data-* values outside scripts: a path a script reads (new Audio(el.dataset.line)).
868
+ const markup = doc.replace(/<script\b[\s\S]*?<\/script>/gi, (x) => " ".repeat(x.length));
869
+ for (const m of markup.matchAll(/<[a-z][\w-]*\b[^>]*>/gi)) {
870
+ for (const a of m[0].matchAll(/\s(data-[\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) {
871
+ const value = decode(a[2] ?? a[3]).trim();
872
+ if (TEXT_DATA.has(a[1].toLowerCase())) continue;
873
+ if (pathy(value)) note(value, `index.html's ${a[1]}`, m.index);
874
+ else if (found.has(deckPath("", value) ?? value)) note(value, "", m.index); // a script's path, carried by this slide too
875
+ }
876
+ }
877
+ // Roll up: more than three files in one folder, named from the same place with the same remedy.
878
+ const groups = new Map();
879
+ for (const [key, f] of found) {
880
+ const g = `${f.where}\n${dirOf(key)}\n${hostedFileRemedy(f.ref)}`;
881
+ if (!groups.has(g)) groups.set(g, []);
882
+ groups.get(g).push(f);
883
+ }
884
+ const order = [...found.values()];
885
+ return [...groups.values()].flatMap((fs) => fs.length <= 3 ? fs.map((f) => [f]) : [fs])
886
+ .sort((a, b) => order.indexOf(a[0]) - order.indexOf(b[0])) // first appearance
887
+ .map((fs) => ({ refs: fs.map((f) => f.ref), slides: [...new Set(fs.flatMap((f) => [...f.slides]))], where: fs[0].where }));
888
+ }
889
+
734
890
  export function phraseList(value) {
735
891
  if (!value) return [];
736
892
  if (typeof value === "string") return value.split(",").map((s) => s.trim()).filter(Boolean);
@@ -2094,6 +2250,15 @@ export async function checkSources({ html, script = "" }, opts = {}, { fetch: fe
2094
2250
  // Without a folder (hosted, or a caller that passes no reader) only the inline scripts are read.
2095
2251
  const walked = deckFiles(html, opts.hosted ? {} : { pathExists: opts.pathExists, read: opts.read, isDir: opts.isDir });
2096
2252
  for (const m of walked.missing) errors.push(MESSAGES.scriptRef(m.ref, m.from));
2253
+ // A hosted deck has nothing to resolve a script's relative path against, so every one is a 404.
2254
+ if (opts.hosted) {
2255
+ // A path the markup's src/href already names is that hostedRef error: list each path once.
2256
+ const inAttrs = new Set(localRefs(html).map((r) => deckPath("", r) ?? r));
2257
+ for (const r of hostedScriptRefs(html)) {
2258
+ const refs = r.refs.filter((ref) => !inAttrs.has(deckPath("", ref) ?? ref));
2259
+ if (refs.length) errors.push(MESSAGES.hostedScriptRef(refs, r.slides, r.where));
2260
+ }
2261
+ }
2097
2262
  const ids = slides(html).map((s) => s.id);
2098
2263
  const player = playerScript(html);
2099
2264
  let manifest = null;
@@ -2174,8 +2339,8 @@ export async function checkSources({ html, script = "" }, opts = {}, { fetch: fe
2174
2339
  : tagIssue.kind === "captions" ? MESSAGES.presenterCaptions()
2175
2340
  : MESSAGES.presenterUnfilled(tagIssue.presenter));
2176
2341
  }
2177
- for (const t of walked.templates) warnings.push(MESSAGES.scriptTemplate(t.from, t.samples));
2178
- for (const c of walked.computed) warnings.push(MESSAGES.scriptComputed(c.from, c.calls));
2342
+ for (const t of walked.templates) warnings.push(opts.hosted ? MESSAGES.scriptTemplateHosted(t.samples) : MESSAGES.scriptTemplate(t.from, t.samples));
2343
+ for (const c of walked.computed) warnings.push(opts.hosted ? MESSAGES.scriptComputedHosted(c.calls) : MESSAGES.scriptComputed(c.from, c.calls));
2179
2344
  if (opts.hosted) {
2180
2345
  for (const url of absoluteRefs(html)) if (!isHostedAsset(url) && !stockSource(url) && /\.(png|jpe?g|gif|webp|avif|svg|mp4|webm|mov)(\?|#|$)/i.test(url)) warnings.push(MESSAGES.hotlink(url));
2181
2346
  warnings.push(MESSAGES.layoutUnchecked(HOSTED_LAYOUT_WHY));
package/src/commands.mjs CHANGED
@@ -760,7 +760,7 @@ ${layoutList()}
760
760
  source pull <slug> [dir] | source push <slug> [dir] [--base-rev N]
761
761
  move a hosted draft (index.html, script.md, evidence.md) to a folder and back
762
762
  asset add <slug> <file|url> [--name n] [--trim]
763
- file an image, video, audio (mp3, m4a), font or JSON under the deck; prints "<file> → <url>" (--json: { url, file, bars, … });
763
+ file an image, video, audio (mp3, m4a), font, JSON, script (js, mjs) or stylesheet (css) under the deck; prints "<file> → <url>" (--json: { url, file, bars, … });
764
764
  a picture or clip with solid bars baked in prints "bars: …", and --trim uploads it cropped to its content
765
765
  guide [workflow|format|script|scripts|design|look|themes|layouts|photos|pictures|embeds|presenter|transitions|check] [<layout> …]
766
766
  the skill, one topic at a time; workflow is the terminal steps; layouts is an index,
package/src/importer.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { strFromU8, strToU8, unzipSync } from "fflate";
2
+ import { assetTypeForPath } from "./assetTypes.mjs";
2
3
 
3
4
  const ZIP_MAGIC = [0x50, 0x4b, 0x03, 0x04];
4
5
  const TEXT_TYPES = new Set([
@@ -28,51 +29,11 @@ export function titleFromFilename(filename) {
28
29
  .replace(/\b\w/g, (m) => m.toUpperCase());
29
30
  }
30
31
 
32
+ // A zip's file types: the deck's page, then what every route takes (assetTypes.mjs);
33
+ // anything else is hosted as bytes.
31
34
  export function inferContentType(path) {
32
- const ext = path.toLowerCase().split(".").pop() || "";
33
- switch (ext) {
34
- case "html":
35
- case "htm":
36
- return "text/html; charset=utf-8";
37
- case "css":
38
- return "text/css";
39
- case "js":
40
- case "mjs":
41
- return "application/javascript";
42
- case "json":
43
- return "application/json";
44
- case "png":
45
- return "image/png";
46
- case "jpg":
47
- case "jpeg":
48
- return "image/jpeg";
49
- case "gif":
50
- return "image/gif";
51
- case "webp":
52
- return "image/webp";
53
- case "svg":
54
- return "image/svg+xml";
55
- case "ico":
56
- return "image/x-icon";
57
- case "mp4":
58
- return "video/mp4";
59
- case "webm":
60
- return "video/webm";
61
- case "mp3":
62
- return "audio/mpeg";
63
- case "wav":
64
- return "audio/wav";
65
- case "woff":
66
- return "font/woff";
67
- case "woff2":
68
- return "font/woff2";
69
- case "ttf":
70
- return "font/ttf";
71
- case "otf":
72
- return "font/otf";
73
- default:
74
- return "application/octet-stream";
75
- }
35
+ if (/\.html?$/i.test(path)) return "text/html; charset=utf-8";
36
+ return assetTypeForPath(path) ?? "application/octet-stream";
76
37
  }
77
38
 
78
39
  export function bytesFromText(text) {
package/src/runtime.mjs CHANGED
@@ -9,7 +9,7 @@ import { ConvexHttpClient } from "convex/browser";
9
9
  import { makeFunctionReference } from "convex/server";
10
10
  import { recordSkillInstall } from "./skillFreshness.mjs";
11
11
 
12
- export const VERSION = "0.9.28";
12
+ export const VERSION = "0.9.29";
13
13
 
14
14
  // Sent on the CLI's calls to our routes and to Convex, so the server can see
15
15
  // which CLI versions are still out there (not used to refuse anything).
package/src/source.mjs CHANGED
@@ -10,8 +10,10 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
10
10
  import { tmpdir } from "node:os";
11
11
  import { basename, extname, join, resolve } from "node:path";
12
12
  import { api, client, uploadBytes } from "./runtime.mjs";
13
- import { HOSTED_LAYOUT_WHY, MESSAGES } from "./checkRules.mjs";
13
+ import { HOSTED_LAYOUT_WHY, MESSAGES, deckFiles, deckPath, hostedFileRemedy, scriptFileRefs } from "./checkRules.mjs";
14
+ import { deckFolder } from "./check.mjs";
14
15
  import { withLoadingBlock } from "./loadingBlock.mjs";
16
+ import { ASSET_KINDS, ASSET_TYPES, isScriptType } from "./assetTypes.mjs";
15
17
  import { TRIMS, barsLine, measureBars, trimFile } from "./bars.mjs";
16
18
  import { SOURCE_FILES, getDeckSource, hostedCheck, hostedRelease, uploadDeckAsset, writeDeckSource } from "./hosted.mjs";
17
19
 
@@ -110,10 +112,39 @@ export async function sourcePush(pos, opts = {}, { log = (line) => console.log(l
110
112
  }
111
113
  for (const f of fixed) log(`✓ the draft fixed ${f}; \`hyperdecks source pull ${slug}\` to bring it into the folder`);
112
114
  log(`✓ pushed ${files.join(", ")} to ${slug}: rev ${rev}`);
113
- return { slug, rev, files };
115
+ // Only the source files go up: say which files the deck loads from the folder,
116
+ // so a release that can't play them isn't a surprise.
117
+ // The push already went through, so a folder the walk can't read is a warning, not a failure.
118
+ let notPushed = [];
119
+ try {
120
+ notPushed = filesLeftBehind(readFileSync(join(/*turbopackIgnore: true*/ dir, "index.html"), "utf8"), dir, files);
121
+ } catch (e) {
122
+ log(` ⚠ could not list the files the deck loads from ${dir}: ${e.message}`);
123
+ }
124
+ const byFolder = new Map();
125
+ for (const f of notPushed) {
126
+ const key = `${f.from}\n${f.path.slice(0, f.path.lastIndexOf("/") + 1)}\n${hostedFileRemedy(f.path)}`; // one folder, one remedy
127
+ if (!byFolder.has(key)) byFolder.set(key, []);
128
+ byFolder.get(key).push(f);
129
+ }
130
+ for (const fs of byFolder.values()) {
131
+ const groups = fs.length > 3 ? [fs] : fs.map((f) => [f]);
132
+ for (const g of groups) log(` ⚠ ${MESSAGES.notPushed(g.map((f) => f.path), g[0].from)}`);
133
+ }
134
+ return { slug, rev, files, notPushed: notPushed.map((f) => f.path) };
114
135
  }
115
136
 
116
- const TYPES = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".avif": "image/avif", ".svg": "image/svg+xml", ".mp4": "video/mp4", ".webm": "video/webm", ".woff2": "font/woff2", ".woff": "font/woff", ".mp3": "audio/mpeg", ".m4a": "audio/mp4", ".json": "application/json" };
137
+ // The files in `dir` the deck loads (not a link's target, not a missing file) that a push of `pushed` left out.
138
+ function filesLeftBehind(html, dir, pushed) {
139
+ const folder = deckFolder(dir);
140
+ const links = new Set([...html.matchAll(/<a\b[^>]*\shref\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)].map((m) => deckPath("", m[1] ?? m[2])).filter(Boolean));
141
+ return deckFiles(html, folder).files
142
+ .filter((f) => !pushed.includes(f.path) && folder.pathExists(f.path) === true && !(f.from === "html" && links.has(f.path)))
143
+ .map((f) => ({ path: f.path, from: f.from === "html" ? "index.html" : f.from }));
144
+ }
145
+
146
+ // asset add takes what every route takes (assetTypes.mjs), keyed here as extname gives it.
147
+ const TYPES = Object.fromEntries(Object.entries(ASSET_TYPES).map(([ext, type]) => [`.${ext}`, type]));
117
148
 
118
149
  // Measured for bars (bars.mjs): pictures ffmpeg reads (not SVG) and clips.
119
150
  const MEASURED = /^(image\/(png|jpeg|gif|webp|avif)|video\/)/;
@@ -163,7 +194,7 @@ export async function assetAdd(pos, opts = {}, { log = (line) => console.log(lin
163
194
  } else {
164
195
  const path = resolve(/*turbopackIgnore: true*/ cwd, from);
165
196
  contentType = TYPES[extname(path).toLowerCase()];
166
- if (!contentType) throw new Error(`${from}: asset add takes images, video, audio, fonts and JSON (${Object.keys(TYPES).join(" ")})`);
197
+ if (!contentType) throw new Error(`${from}: asset add takes ${ASSET_KINDS} (${Object.keys(TYPES).join(" ")})`);
167
198
  bytes = readFileSync(path);
168
199
  if (!name) name = basename(path);
169
200
  }
@@ -202,5 +233,16 @@ export async function assetAdd(pos, opts = {}, { log = (line) => console.log(lin
202
233
  // The file (or URL) it came from beside its new URL, so uploads in a loop stay told apart.
203
234
  out = { ...out, file: from };
204
235
  log(`${from} → ${out.url}`);
236
+ if (isScriptType(out.contentType)) {
237
+ log(` in the deck: import("${out.url}") for a module, <script src="${out.url}"> for a classic script`);
238
+ // Read from disk only: a URL's text stays on the server, which took it as it is.
239
+ if (!isUrl) {
240
+ const refs = scriptFileRefs(readFileSync(resolve(/*turbopackIgnore: true*/ cwd, from), "utf8"));
241
+ if (refs.length) {
242
+ log(` ⚠ ${MESSAGES.assetRefs(basename(from), refs)}`);
243
+ out = { ...out, refs };
244
+ }
245
+ }
246
+ }
205
247
  return out;
206
248
  }