pindeck 3.1.0-beta.1 → 3.2.0

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/lib/pdf.mjs CHANGED
@@ -25,8 +25,24 @@ export const PDF_HEAD_TAG = `<script>window.requestAnimationFrame = function (cb
25
25
  export const PDF_PAGE_TAG = `<style>@media print { * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; } }</style>
26
26
  </body>`;
27
27
 
28
+ // Chrome refuses to run as root with its sandbox (containers, some servers); it says so, and needs --no-sandbox.
29
+ // Without --disable-field-trial-config a headless Chrome can wait forever for its field-trial setup (seen
30
+ // behind a proxy); PinDeck needs none of those experiments.
31
+ export const ROOT_ARGS = ["--disable-field-trial-config", ...(process.getuid?.() === 0 ? ["--no-sandbox"] : [])];
28
32
  const BASE = ["--headless=new", "--disable-gpu", "--no-first-run", "--no-default-browser-check",
29
- "--disable-extensions", "--mute-audio", "--hide-scrollbars"];
33
+ "--disable-extensions", "--mute-audio", "--hide-scrollbars", ...ROOT_ARGS];
34
+
35
+ /* Why Chrome stopped, from what it printed: its last error line (such as "Running as root without
36
+ --no-sandbox is not supported"), without the log prefix. "" if it said nothing useful. */
37
+ export function chromeReason(stderr) {
38
+ // Chrome logs much that is harmless (display links, D-Bus, GPU, fonts): a fatal line first, then a plain reason
39
+ const noise = /CVDisplayLink|dbus|gcm|fontconfig|gpu|viz|gles|egl|vaapi|sandbox_linux|ssl_client_socket/i;
40
+ const lines = String(stderr).split("\n").filter((l) => l.trim() && !noise.test(l)).reverse();
41
+ const clean = (l) => l.replace(/^\[[^\]]*\]\s*/, "").trim().slice(0, 300);
42
+ const fatal = lines.find((l) => /:FATAL:/.test(l)), plain = lines.find((l) => /not supported|cannot|denied|no such|error/i.test(l));
43
+ return fatal ? clean(fatal) : plain ? clean(plain) : "";
44
+ }
45
+ const exited = (what, err) => new Error(`${what}${chromeReason(err) ? `: ${chromeReason(err)}` : "."}`);
30
46
 
31
47
  /* Runs Chrome with args, stops it once done(stdout, stderr) is true (Chrome often lingers). */
32
48
  function chromeRun(chrome, args, profile, done, timeout) {
@@ -47,7 +63,7 @@ function chromeRun(chrome, args, profile, done, timeout) {
47
63
  proc.stderr.on("data", (d) => { err += d; check(); });
48
64
  proc.on("error", (e) => finish(e));
49
65
  // "close", not "exit": at exit Chrome's last output (the line saying the file is written) may still be unread
50
- proc.on("close", () => (done(out, err) ? finish(null, out) : finish(new Error("Chrome exited early."))));
66
+ proc.on("close", () => (done(out, err) ? finish(null, out) : finish(exited("Chrome exited early", err))));
51
67
  });
52
68
  }
53
69
 
@@ -4,8 +4,8 @@ export function createPlatformNoticeServer(platform) {
4
4
  const windows = platform === 'win32';
5
5
  const heading = windows ? 'Windows support is on the roadmap' : 'PinDeck runs on macOS and Linux';
6
6
  const explanation = windows
7
- ? 'PinDeck runs on macOS and, as a beta, on Linux. Windows support is planned for a future version; there is no release date yet.'
8
- : 'This version of PinDeck runs on macOS and, as a beta, on Linux. This operating system is not supported.';
7
+ ? 'PinDeck runs on macOS and Linux. Windows support is planned for a future version; there is no release date yet.'
8
+ : 'This version of PinDeck runs on macOS and Linux. This operating system is not supported.';
9
9
  const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>PinDeck · system not supported</title><style>
10
10
  :root{font-family:system-ui,sans-serif;color:#243348;background:#f4f6f8;color-scheme:light}*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px}main{width:min(100%,620px);padding:40px;background:white;border:1px solid #dde3ea;border-radius:18px;box-shadow:0 12px 40px #20334d0a}.brand{font-weight:700;color:#c36516;margin:0 0 32px}h1{font-size:clamp(26px,5vw,36px);line-height:1.2;margin:0 0 20px}p{line-height:1.65}a{color:#945012}footer{margin-top:28px;font-size:14px;color:#596577}
11
11
  </style></head><body><main><p class="brand">PinDeck</p><h1>${heading}</h1><p>${explanation}</p><p>Your deck has not been opened or changed, and no AI backend has been started.</p><p>You can run PinDeck on a Mac or a Linux machine (and use it from this browser through an SSH tunnel), or follow updates on <a href="https://github.com/ehabets/PinDeck">GitHub</a>.</p><footer>Close this tab and press Ctrl+C in the terminal to stop this notice.</footer></main></body></html>`;
@@ -0,0 +1,91 @@
1
+ /* The PinDecks running for this user, and which one serves a deck: shared by the front, the deck server,
2
+ `pindeck login` and cli.mjs.
3
+
4
+ Each PinDeck process (a front, a deck server on its own, or one behind a front) keeps a file of its own in
5
+ ~/.pindeck-v3/servers/<pid>.json (0600, in a 0700 folder) with its address and token. Several fronts and
6
+ servers can run side by side (another --port, another PINDECK_HOME user, a server started on its own) and
7
+ none overwrites another's file; a file whose process is gone is removed when it is read. */
8
+
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+
12
+ const dirOf = (home) => path.join(home, "servers");
13
+ export const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === "EPERM"; } };
14
+
15
+ /* info: { url, token, front?, key?, deckDir?, behindFront? }. Returns the function that removes the file again
16
+ (only if it is still ours). */
17
+ export function registerServer(home, info) {
18
+ const dir = dirOf(home);
19
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
20
+ // written whole and private from the start: a reader (pindeck login, cli.mjs) never sees half of it
21
+ const file = path.join(dir, `${process.pid}.json`), tmp = path.join(dir, `.${process.pid}.json.tmp`);
22
+ fs.writeFileSync(tmp, JSON.stringify({ ...info, pid: process.pid }, null, 2), { mode: 0o600 });
23
+ fs.chmodSync(tmp, 0o600);
24
+ fs.renameSync(tmp, file);
25
+ return () => { try { if (JSON.parse(fs.readFileSync(file, "utf8")).token === info.token) fs.rmSync(file, { force: true }); } catch {} };
26
+ }
27
+
28
+ /* The running ones, the newest first */
29
+ export function runningServers(home) {
30
+ let names = [];
31
+ try { names = fs.readdirSync(dirOf(home)).filter((f) => /^\d+\.json$/.test(f)); } catch {}
32
+ const out = [];
33
+ for (const name of names) {
34
+ const file = path.join(dirOf(home), name);
35
+ try {
36
+ const info = JSON.parse(fs.readFileSync(file, "utf8"));
37
+ if (alive(info.pid)) { out.push({ ...info, since: fs.statSync(file).mtimeMs }); continue; }
38
+ } catch {}
39
+ try { fs.rmSync(file, { force: true }); } catch {}
40
+ }
41
+ return out.sort((a, b) => b.since - a.since);
42
+ }
43
+
44
+ const ask = async (s, p) => {
45
+ const res = await fetch(`${s.url}${p}`, { headers: { "x-editor-token": s.token }, signal: AbortSignal.timeout(5000) });
46
+ if (!res.ok) throw new Error(String(res.status));
47
+ return res.json();
48
+ };
49
+
50
+ const real = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
51
+
52
+ /* Who serves a deck (a deckTarget): { front, key } a front whose deck list has it (open or not), under that
53
+ front's key for it, and/or { own } its deck server if one runs (on its own, or behind a front). Decks are
54
+ compared by real path: the same folder can be named through a symlink (on macOS a terminal in /var/... is
55
+ in /private/var/...). null: no running PinDeck serves it. */
56
+ export async function serverFor(home, deck) {
57
+ const all = runningServers(home), file = real(path.join(deck.dir, deck.file));
58
+ const own = all.find((s) => !s.front && (s.key === deck.key || real(path.join(s.deckDir, s.deckFile || "index.html")) === file)) || null;
59
+ for (const f of all.filter((s) => s.front)) {
60
+ try {
61
+ const { decks } = await ask(f, "/api/decks");
62
+ const d = decks.find((x) => !x.problem && (x.key === deck.key || real(path.join(x.root, x.rel)) === file));
63
+ if (d) return { front: f, key: d.key, own };
64
+ } catch {}
65
+ }
66
+ return own ? { front: null, key: own.key, own } : null;
67
+ }
68
+
69
+ /* pindeck login [deck]: a new one-time login link, from the PinDeck that serves the deck (the link then opens
70
+ it), or from each PinDeck running when no deck is named. Prints and exits. */
71
+ export async function printLogin(home, deck) {
72
+ let targets;
73
+ if (deck) {
74
+ const found = await serverFor(home, deck);
75
+ const shown = path.join(deck.dir, deck.file);
76
+ if (!found || (!found.front && found.own.behindFront)) {
77
+ console.error(`No running PinDeck serves ${shown}.` + (runningServers(home).length ? " Open it from a running PinDeck's deck menu, or start PinDeck for it." : ""));
78
+ process.exit(1);
79
+ }
80
+ targets = [found.front ? { s: found.front, next: `/d/${found.key}/`, label: shown } : { s: found.own, next: "/", label: shown }];
81
+ } else {
82
+ targets = runningServers(home).filter((s) => !s.behindFront).map((s) => ({ s, next: "/", label: s.deckDir }));
83
+ if (!targets.length) { console.error("No PinDeck is running."); process.exit(1); }
84
+ }
85
+ let ok = true;
86
+ for (const { s, next, label } of targets) {
87
+ try { console.log(`PinDeck (${label}): ${(await ask(s, "/api/login-link?" + new URLSearchParams({ next }))).url}`); }
88
+ catch { ok = false; console.error(`The PinDeck at ${s.url} (${label}) does not answer. Is it still running?`); }
89
+ }
90
+ process.exit(ok ? 0 : 1);
91
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pindeck",
3
- "version": "3.1.0-beta.1",
4
- "description": "PinDeck: an editor for HTML slide decks on macOS, and on Linux (beta) through an SSH tunnel. Pin elements, describe the change, and Claude Code or OpenAI Codex edits the slides.",
3
+ "version": "3.2.0",
4
+ "description": "PinDeck: an editor for HTML slide decks on macOS, and on Linux through an SSH tunnel. Pin elements, describe the change, and Claude Code or OpenAI Codex edits the slides.",
5
5
  "keywords": [
6
6
  "slides",
7
7
  "presentation",
package/public/bridge.js CHANGED
@@ -19,7 +19,17 @@
19
19
  const SLIDE_SEL = deckMeta("slides") || null;
20
20
  const SLIDE = SLIDE_SEL ? `:is(${SLIDE_SEL})` : ".reveal .slides section"; // in CSS and closest()
21
21
  const SLIDE_OF = SLIDE_SEL || "section"; // the slide an element is on
22
- const host = () => (window.parent !== window ? window.parent.__editorHost : null);
22
+ /* The editor, reached by messages: the deck runs sandboxed in an origin of its own (see VIEW in server.mjs),
23
+ so it cannot touch the editor page. Every call answers with a promise of the editor's return value. */
24
+ const PARENT = window.parent !== window ? window.parent : null;
25
+ let callSeq = 0;
26
+ const answers = new Map(); // id -> resolve
27
+ const hostCalls = new Proxy({}, { get: (_, method) => method === "then" ? undefined : (...args) => new Promise((resolve) => {
28
+ const id = ++callSeq;
29
+ answers.set(id, resolve);
30
+ PARENT.postMessage({ pindeck: "host", id, method, args }, "*");
31
+ }) });
32
+ const host = () => (PARENT ? hostCalls : null);
23
33
  let W = 1280, H = 720, deck = null; // deck: reveal.js or a selector deck (see "Decks" below)
24
34
 
25
35
  /* ---- Styles for editor-only overlays ---------------------------------------- */
@@ -128,7 +138,8 @@
128
138
  hasFooter: !!sec.querySelector(".slide-foot"), hidden };
129
139
  }
130
140
  function info() {
131
- return { slides: slides().map((s, i) => slideInfo(s, i)), current: indexOf(deck.current()) };
141
+ // hash: the slide's address in the deck opened on its own (Present), where hidden slides are left out
142
+ return { slides: slides().map((s, i) => ({ ...slideInfo(s, i), hash: deck.hash(i) })), current: indexOf(deck.current()) };
132
143
  }
133
144
 
134
145
  /* ---- Layout measurement ------------------------------------------------------------- */
@@ -801,12 +812,22 @@
801
812
  tail.setStart(r.startContainer, r.startOffset);
802
813
  const subList = [...el.children].find((c) => c.tagName === "UL" || c.tagName === "OL");
803
814
  if (subList) tail.setEndBefore(subList); else tail.setEnd(el, el.childNodes.length);
815
+ // the elements the caret is in (an equation, a <strong>): the split cuts each in two, and extractContents
816
+ // copies them, attributes and all, into the new bullet
817
+ const cut = [];
818
+ for (let n = r.startContainer; n && n !== el; n = n.parentNode) if (n.nodeType === 1) cut.unshift(n);
804
819
  const frag = tail.extractContents();
805
820
  const li = document.createElement("li");
806
821
  const cls = [...el.classList].filter((c) => !c.startsWith("__") && c !== "visible" && c !== "current-fragment").join(" ");
807
822
  if (cls) li.className = cls;
808
823
  li.appendChild(frag);
809
824
  el.after(li);
825
+ // their copies: no id of their own (the server gives new ones), and gone where the split left them
826
+ // empty, on either side (no empty <strong> or equation line left behind)
827
+ const copies = [];
828
+ for (let n = li.firstChild, i = 0; i < cut.length && n?.nodeType === 1 && n.tagName === cut[i].tagName; n = n.firstChild, i++) copies.push(n);
829
+ for (const n of copies) n.removeAttribute("data-eid");
830
+ for (const n of [...cut, ...copies].reverse()) if (n.isConnected && isBlank(n)) n.remove();
810
831
  // no stray spaces at the split
811
832
  const trim = (node, end) => {
812
833
  const w = document.createTreeWalker(node, NodeFilter.SHOW_TEXT);
@@ -825,8 +846,10 @@
825
846
  teardownEdit(ed);
826
847
  host()?.editingChanged(false);
827
848
  chainDirty = true;
828
- host()?.commitSplit({ eid: ed.eid, html, newHtml, newEid, cls, text: textOf(el).slice(0, 200) },
829
- (real) => { if (real && real !== newEid) li.dataset.eid = real; });
849
+ // whole: the bullet's text as typed, offered to copy if the save is refused
850
+ host()?.commitSplit({ eid: ed.eid, html, newHtml, newEid, cls, text: textOf(el).slice(0, 200),
851
+ whole: [textOf(el), textOf(li)].filter((t) => t.trim()).join(" ") })
852
+ .then((real) => { if (real && real !== newEid) li.dataset.eid = real; });
830
853
  startEdit({ el: li, sec: ed.sec, eid: newEid, path: [], isNew: true }, null, null, { src: newHtml, caret: "start" });
831
854
  }
832
855
 
@@ -853,7 +876,19 @@
853
876
  slides: () => Reveal.getSlides(),
854
877
  current: () => Reveal.getCurrentSlide(),
855
878
  goto(index) { if (Reveal.getSlides()[index]) { const i = ix(index); Reveal.slide(i.h, i.v); } },
856
- hash(index) { const i = ix(index); return `#/${i.h}${i.v ? "/" + i.v : ""}`; },
879
+ // counted without hidden slides, which the deck opened on its own leaves out (the editor shows them);
880
+ // a hidden slide opens at the next one shown
881
+ hash(index) {
882
+ const all = Reveal.getSlides(), shown = (s) => s.getAttribute("data-visibility") !== "hidden" &&
883
+ s.parentElement?.closest("section")?.getAttribute("data-visibility") !== "hidden";
884
+ const sec = [...all.slice(index), ...all.slice(0, index).reverse()].find(shown);
885
+ if (!sec) return "";
886
+ const stack = sec.parentElement.closest("section");
887
+ const sections = (el) => [...el.children].filter((c) => c.tagName === "SECTION" && shown(c));
888
+ const h = sections(Reveal.getSlidesElement()).indexOf(stack || sec);
889
+ const v = stack ? sections(stack).indexOf(sec) : 0;
890
+ return `#/${h}${v ? "/" + v : ""}`;
891
+ },
857
892
  size: () => ({ width: Reveal.getConfig().width, height: Reveal.getConfig().height }),
858
893
  scale: () => Reveal.getScale() || 1,
859
894
  on: (ev, fn) => Reveal.on(ev === "slide" ? "slidechanged" : ev, fn),
@@ -1060,7 +1095,16 @@
1060
1095
  return measureSection(slides()[index]);
1061
1096
  },
1062
1097
  };
1063
- window.__editorBridge = api;
1098
+ // the editor's calls: from the parent window only, answered with the result
1099
+ if (PARENT) window.addEventListener("message", async (e) => {
1100
+ const m = e.data;
1101
+ if (e.source !== PARENT || !m || typeof m !== "object") return;
1102
+ if (m.pindeck === "host-answer") { answers.get(m.id)?.(m.value); answers.delete(m.id); return; }
1103
+ if (m.pindeck !== "bridge" || !Object.hasOwn(api, m.method)) return;
1104
+ let value = null;
1105
+ try { value = await api[m.method](...(m.args || [])); } catch (err) { console.error(err); }
1106
+ PARENT.postMessage({ pindeck: "bridge-answer", id: m.id, value: value ?? null }, "*");
1107
+ });
1064
1108
 
1065
1109
  if (MODE === "main") {
1066
1110
  document.addEventListener("pointerdown", onPointerDown, true);
@@ -1129,13 +1173,18 @@
1129
1173
  if (startAt) goto(startAt);
1130
1174
  deck.keys();
1131
1175
  }
1132
- host()?.bridgeReady(MODE, api, window);
1176
+ host()?.bridgeReady(MODE, info());
1133
1177
  }
1134
1178
  if (SLIDE_SEL) {
1135
1179
  deck = selectorDeck();
1136
1180
  deck.ready(() => (MODE === "pdf" ? deck.print() : start()));
1137
1181
  return;
1138
1182
  }
1183
+ if (typeof Reveal === "undefined" && (MODE === "main" || MODE === "measure")) {
1184
+ // nothing to edit: the editor says why, instead of a blank stage (and stops waiting for measurements)
1185
+ host()?.deckFailed(MODE, "reveal.js did not load: the deck's script tag for it points to a file or address that cannot be reached.");
1186
+ return;
1187
+ }
1139
1188
  if (typeof Reveal === "undefined" || MODE === "pdf") return; // reveal.js lays out its own print view
1140
1189
  deck = revealDeck();
1141
1190
  deck.ready(start);
package/public/editor.css CHANGED
@@ -60,12 +60,14 @@ code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background:
60
60
  .toolbar .group { display: flex; align-items: center; gap: 6px; min-width: 0; flex: none; }
61
61
  .toolbar .group:first-child { flex: 1 1 auto; }
62
62
  .toolbar .group:first-child > :not(.deck-wrap) { flex: none; }
63
+ /* narrow: the deck's name is shortened, never hidden (it opens the deck menu) */
63
64
  @container (max-width: 640px) {
64
- .toolbar kbd, .toolbar .deck-wrap { display: none; }
65
+ .toolbar kbd { display: none; }
66
+ .toolbar .deck-wrap { max-width: 9em; }
65
67
  }
66
68
  .pos { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 52px; text-align: center; }
67
69
  /* the deck's name; behind the front (several decks on one port) it opens the deck menu */
68
- .deck-wrap { min-width: 0; margin-left: 2px; }
70
+ .deck-wrap { min-width: 0; max-width: 12em; margin-left: 2px; }
69
71
  .deck-btn { display: flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; padding: 2px 6px;
70
72
  border: 0; background: none; color: inherit; font: inherit; }
71
73
  .deck-btn:hover { background: none; }
@@ -161,6 +163,10 @@ code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background:
161
163
  .stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--stage); }
162
164
  .stage iframe.loading { visibility: hidden; }
163
165
  .stage iframe.measure { inset: auto; left: -20000px; top: 0; width: 1280px; height: 720px; visibility: hidden; }
166
+ /* a deck page that does not start: why, over the empty stage */
167
+ .stage-problem { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; justify-content: center; gap: 8px;
168
+ max-width: 34em; margin: auto; padding: 24px; color: var(--muted, #555); font-size: 14px; line-height: 1.45; text-align: center; }
169
+ .stage-problem b { color: inherit; font-size: 15px; }
164
170
 
165
171
  /* ---- Speaker notes under the slide ---- */
166
172
  .notes-panel { position: relative; flex: none; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line); }