@delurio/cli 0.5.1 → 0.5.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  While the version is 0.x, a release that can judge the same graphs differently (a new check, a stricter schema) bumps the minor; a fix that judges nothing differently bumps the patch.
4
4
 
5
+ ## 0.5.3 (2026-11-06)
6
+
7
+ - `page`: the `flow.mmd` it writes now reads whole in Mermaid. Mermaid ends a statement at a `;`, even inside a transition's label, so a label with one lost its rest: those words were drawn as stray states, or, when a `-` or `{` came after the `;`, the diagram did not render at all ("Parse error on line …", QAuth's sign-in in an editor's preview). A `;` in a label is now written as a comma. A transition never taken and with no label of its own now carries "(never taken)" as its label: before, those two words were drawn as two more states. Of the 106 flow diagrams of QAuth, Medaris and delurio, 86 were drawn wrong (36 did not render, 50 had stray states) and none is now, in Mermaid 10.9 and 12.3; their 5 navigation diagrams were right before and are unchanged. `index.html` draws its own diagram and was not affected. Nothing is judged differently.
8
+
9
+ ## 0.5.2 (2026-11-03)
10
+
11
+ - `page`: the flow's diagram opens fitted to a box as wide as the window, and moves like a design tool's canvas: drag it to move (the hand), Ctrl or ⌘ with the wheel, or a pinch, to zoom at the pointer, and the wheel alone to move it until its edge, after which the page scrolls on. Buttons and keys: − and + (zoom), the zoom level (click: 100%, Shift+0), Fit (Shift+1), Full window (F; Esc leaves it); arrows move it. A click that does not drag still opens a step's screen. Before, a large flow was shrunk into the page's column (QAuth's consent flow to 7%) or scrolled sideways at full size. Without scripts the page keeps the old diagram. Nothing is judged differently.
12
+
5
13
  ## 0.5.1 (2026-11-03)
6
14
 
7
15
  - `check`, `diff` and `page` explore a large flow about four times faster and in a third of the memory, and judge every graph exactly as before: the same situations in the same order, the same shortest paths and the same findings. On QAuth's consent flow (5.4 million situations from 580,608 starts) `check` took 122 s and 2.9 GB, and now takes 34 s and 1 GB. A situation is kept as a number instead of a string; guards, assertions and effects are read once instead of at every situation; and an assertion is not tested in the states where the state alone rules it out.
package/README.md CHANGED
@@ -56,7 +56,7 @@ npx @delurio/cli check graphs --strict
56
56
  npx @delurio/cli page examples/qauth-authorize --out viz/qauth-authorize
57
57
  ```
58
58
 
59
- The page shows the flow in words: its main story, every way it ends, its guarantees and whether they hold, its screens as wireframes, and its diagram. `examples/qauth-authorize` is a small graph to try it on.
59
+ The page shows the flow in words: its main story, every way it ends, its guarantees and whether they hold, its screens as wireframes, and its diagram, which opens fitted to the window and moves like a design tool's canvas (drag to move, Ctrl or ⌘ + scroll or a pinch to zoom, Shift+1 to fit). `examples/qauth-authorize` is a small graph to try it on.
60
60
 
61
61
  Given a folder of graphs instead, it writes the page of every graph under it, each at its own path, and `index.html` listing them all with what their check found:
62
62
 
package/dist/html.js CHANGED
@@ -3,6 +3,7 @@ import { identifiers, parseExpr } from './expr.js';
3
3
  import { collectEdges, exitLine, kindOf, pressLabel, responseLine } from './edges.js';
4
4
  import { narrate, stepsTo } from './story.js';
5
5
  import { kitCss } from './kit.js';
6
+ import { PAN_CSS, PAN_SCRIPT } from './pan.js';
6
7
  const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
7
8
  const code = (s) => `<code>${esc(s)}</code>`;
8
9
  export const CSS = `
@@ -172,7 +173,7 @@ export function renderPage(p) {
172
173
  const heading = g.flow.title ?? humanize(g.flow.id);
173
174
  const out = [];
174
175
  out.push('<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">');
175
- out.push(`<title>${esc(heading)}</title><style>${CSS}${kit === null ? '' : kitCss(kit, 'page')}</style></head><body><main>`);
176
+ out.push(`<title>${esc(heading)}</title><style>${CSS}${PAN_CSS}${kit === null ? '' : kitCss(kit, 'page')}</style></head><body><main>`);
176
177
  out.push(`<p class="eyebrow">${g.flow.status === undefined ? '' : `<span class="tag">${esc(g.flow.status)}</span> `}<span class="mono">${esc(g.flow.id)}</span></p>`);
177
178
  out.push(`<h1>${esc(heading)}</h1>`);
178
179
  if (g.flow.summary !== undefined)
@@ -196,8 +197,8 @@ export function renderPage(p) {
196
197
  out.push(`</ol><p class="result">Result: ${esc(main.result)}.</p></section>`);
197
198
  }
198
199
  out.push('<h2>The flow</h2>');
199
- out.push('<div class="views"><input type="checkbox" id="show-all"><label for="show-all">Show failure paths and “the user closes the page” <span class="muted">(wider: scrolls sideways)</span></label>');
200
- out.push(`<div class="scroll panel-main">${p.spineMain}</div><div class="scroll panel-full">${p.spineFull}</div></div>`);
200
+ out.push('<div class="views pz-host"><input type="checkbox" id="show-all"><label for="show-all">Show failure paths and “the user closes the page”</label>');
201
+ out.push(`<div class="scroll panel-main pz">${p.spineMain}</div><div class="scroll panel-full pz">${p.spineFull}</div></div>`);
201
202
  out.push(legend(g, ex, main !== null));
202
203
  const covers = Object.entries(g.flow.states).filter(([, s]) => (s.includes ?? []).length > 0);
203
204
  if (covers.length > 0) {
@@ -279,6 +280,6 @@ export function renderPage(p) {
279
280
  out.push(`<details><summary>All transitions (${Object.values(g.flow.states).reduce((n, s) => n + (s.always?.length ?? 0) + Object.values(s.on ?? {}).reduce((k, spec) => k + alternatives(spec).length, 0), 0)})</summary>${transitionsTable(g, ex)}</details>`);
280
281
  const from = g.ui.absent === true ? 'flow.yaml (it has no screens)' : `flow.yaml, ui.yaml${kit === null ? ' and the catalog' : `, the catalog and the kit ${esc(kit.id)}`}`;
281
282
  out.push(`<footer>delurio graph-viz · generated from ${from} · no AI, no network: the same input gives the same bytes.</footer>`);
282
- out.push('</main></body></html>');
283
+ out.push(`</main>${PAN_SCRIPT}</body></html>`);
283
284
  return out.join('\n') + '\n';
284
285
  }
package/dist/mermaid.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { collectEdges, exitLine, kindOf } from './edges.js';
2
2
  import { titleOf } from './graph.js';
3
- const clean = (s) => s.replace(/"/g, "'").replace(/:/g, ' -');
3
+ // Mermaid ends a statement at `;` even inside a transition's label: the rest of the label became stray states,
4
+ // or, with a `-` or `{` after it, a parse error. A label keeps its words with a comma in its place.
5
+ const clean = (s) => s.replace(/"/g, "'").replace(/:/g, ' -').replace(/;/g, ',');
4
6
  // Mermaid's ids, which take no dot: an exit named `<error>.<cause>` is written `<error>__<cause>`
5
7
  function mermaidIds(names) {
6
8
  const ids = new Map();
@@ -30,8 +32,10 @@ export function renderMermaid(g, ex) {
30
32
  }
31
33
  lines.push(` [*] --> ${id(g.flow.initial)}`);
32
34
  for (const e of collectEdges(g, ex)) {
33
- const label = e.labels.map(clean).join(', ');
34
- lines.push(` ${id(e.from)} --> ${id(e.to)}${label === '' ? '' : `: ${label}`}${e.unused ? ' (never taken)' : ''}`);
35
+ // "never taken" belongs in the label: after an arrow with no `:` Mermaid read its words as two more states
36
+ const said = e.labels.map(clean).join(', ');
37
+ const label = e.unused ? `${said} (never taken)`.trim() : said;
38
+ lines.push(` ${id(e.from)} --> ${id(e.to)}${label === '' ? '' : `: ${label}`}`);
35
39
  }
36
40
  lines.push(' classDef server fill:#eeeeec,stroke:#6b6560,stroke-dasharray:4 3');
37
41
  lines.push(' classDef screen fill:#ffffff,stroke:#1c1917,stroke-width:2px');
package/dist/pan.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const PAN_CSS = "\n.pz-on { position: relative; height: 78vh; min-height: 360px; overflow: hidden; margin-left: calc(50% - 50vw + 24px); margin-right: calc(50% - 50vw + 24px); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }\n.pz-on.pz-grabbing, .pz-on.pz-grabbing a { cursor: grabbing; }\n.pz-on:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }\n.pz-on svg.spine { width: 100%; height: 100%; max-width: none; padding: 0; margin: 0; }\n.pz-on a { cursor: pointer; -webkit-user-drag: none; }\n.pz-bar { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; cursor: default; }\n.pz-bar button { font: 13px system-ui, sans-serif; min-width: 32px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }\n.pz-bar button:hover { border-color: var(--muted); } .pz-bar button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pz-bar .pz-pct { min-width: 58px; font-variant-numeric: tabular-nums; }\n.pz-hint { position: absolute; left: 10px; bottom: 10px; margin: 0; padding: 2px 8px; border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 12px; pointer-events: none; }\nhtml.pz-lock, html.pz-lock body { overflow: hidden; }\n.pz-host.pz-full { position: fixed; inset: 0; z-index: 100; margin: 0; padding: 10px 12px 12px; background: var(--bg); display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto minmax(0, 1fr); align-items: center; }\n.pz-host.pz-full { row-gap: 10px; } .pz-host.pz-full > label { margin: 0; }\n.pz-host.pz-full > .pz-on { grid-column: 1 / -1; grid-row: 2; align-self: stretch; height: auto; min-height: 0; margin: 0; }\n.pz-on.pz-full { position: fixed; inset: 0; z-index: 100; height: auto; min-height: 0; margin: 0; border-radius: 0; }\n";
2
+ export declare const PAN_SCRIPT = "<script>(() => {\n const PAD = 24, MAX = 4;\n for (const box of document.querySelectorAll('.pz')) {\n const svg = box.querySelector('svg.spine');\n if (!svg || !svg.viewBox.baseVal || !svg.viewBox.baseVal.width) continue;\n const W = svg.viewBox.baseVal.width, H = svg.viewBox.baseVal.height;\n const host = box.closest('.pz-host') || box;\n svg.removeAttribute('style');\n box.classList.add('pz-on');\n box.tabIndex = 0;\n\n let s = 1, x = 0, y = 0, vw = 0, vh = 0, fitted = true;\n const bar = document.createElement('div');\n bar.className = 'pz-bar';\n const button = (text, title, act) => {\n const b = document.createElement('button');\n b.type = 'button';\n b.textContent = text;\n b.title = title;\n b.addEventListener('click', act);\n bar.append(b);\n return b;\n };\n const fitScale = () => Math.max(Math.min((vw - 2 * PAD) / W, (vh - 2 * PAD) / H), 0.001);\n const minScale = () => Math.min(fitScale(), 1) / 2;\n // where the box's top left may be on an axis, in the diagram's units. Snug: centred when the diagram fits on it,\n // else from PAD before its start to PAD past its end. The hand may go further, until the diagram's edge reaches\n // the middle of the box, so it is never lost.\n const snug = (len, view) => {\n const p = PAD / s;\n return len + 2 * p <= view ? [(len - view) / 2, (len - view) / 2] : [-p, len + p - view];\n };\n const free = (len, view) => {\n const [lo, hi] = snug(len, view);\n return [Math.min(lo, -view / 2), Math.max(hi, len - view / 2)];\n };\n const within = (v, [lo, hi]) => Math.min(Math.max(v, lo), hi);\n const clamp = () => {\n x = within(x, free(W, vw / s));\n y = within(y, free(H, vh / s));\n };\n const draw = () => {\n clamp();\n svg.setAttribute('viewBox', x + ' ' + y + ' ' + vw / s + ' ' + vh / s);\n pct.textContent = Math.round(s * 100) + '%';\n };\n const zoomAt = (px, py, factor) => {\n const ns = Math.min(MAX, Math.max(minScale(), s * factor));\n const dx = x + px / s, dy = y + py / s;\n s = ns;\n x = dx - px / s;\n y = dy - py / s;\n fitted = false;\n draw();\n };\n const fit = () => {\n s = fitScale();\n x = (W - vw / s) / 2;\n y = (H - vh / s) / 2;\n fitted = true;\n draw();\n };\n const actual = () => zoomAt(vw / 2, vh / 2, 1 / s);\n const setFull = (on) => {\n host.classList.toggle('pz-full', on);\n document.documentElement.classList.toggle('pz-lock', on);\n for (const b of host.querySelectorAll('.pz-fs')) b.textContent = on ? 'Exit full window' : 'Full window';\n if (on) box.focus({ preventScroll: true });\n };\n\n button('\\u2212', 'Zoom out (\\u2212)', () => zoomAt(vw / 2, vh / 2, 0.8));\n const pct = button('100%', 'Show at 100% (Shift+0)', actual);\n pct.className = 'pz-pct';\n button('+', 'Zoom in (+)', () => zoomAt(vw / 2, vh / 2, 1.25));\n button('Fit', 'Fit the whole diagram (Shift+1)', fit);\n button('Full window', 'Give the diagram the whole window (F; Esc leaves it)', () => setFull(!host.classList.contains('pz-full'))).className = 'pz-fs';\n const hint = document.createElement('p');\n hint.className = 'pz-hint';\n hint.textContent = 'Drag to move \\u00b7 Ctrl or \\u2318 + scroll, or pinch, to zoom \\u00b7 Shift+1 fits';\n box.append(bar, hint);\n\n // a new size keeps a fitted diagram fitted, and keeps the centre of one zoomed by hand; a hidden box (the other\n // view) keeps its place for when it shows again\n new ResizeObserver(() => {\n const nw = box.clientWidth, nh = box.clientHeight;\n if (!nw || !nh) return;\n const first = !vw, cx = x + vw / (2 * s), cy = y + vh / (2 * s);\n vw = nw;\n vh = nh;\n if (first || fitted) return fit();\n x = cx - vw / (2 * s);\n y = cy - vh / (2 * s);\n draw();\n }).observe(box);\n\n let gesture = false;\n box.addEventListener('wheel', (e) => {\n if (!vw) return;\n const r = box.getBoundingClientRect();\n const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? vh : 1;\n if (e.ctrlKey || e.metaKey) {\n e.preventDefault();\n if (gesture) return;\n const d = Math.max(-50, Math.min(50, e.deltaY * unit));\n zoomAt(e.clientX - r.left, e.clientY - r.top, Math.exp(-d * 0.006));\n return;\n }\n let dx = e.deltaX * unit, dy = e.deltaY * unit;\n if (e.shiftKey && dx === 0) { dx = dy; dy = 0; }\n // the wheel moves the diagram only within its snug range (or back toward it); at the end of that range, or on a\n // diagram that fits, it scrolls the page instead\n const [xl, xh] = snug(W, vw / s), [yl, yh] = snug(H, vh / s);\n const nx = within(x + dx / s, [Math.min(xl, x), Math.max(xh, x)]);\n const ny = within(y + dy / s, [Math.min(yl, y), Math.max(yh, y)]);\n if (Math.abs(nx - x) * s < 0.5 && Math.abs(ny - y) * s < 0.5) return;\n e.preventDefault();\n x = nx;\n y = ny;\n fitted = false;\n draw();\n }, { passive: false });\n // Safari's pinch on a trackpad\n box.addEventListener('gesturestart', (e) => { e.preventDefault(); gesture = true; box.dataset.g = '1'; });\n box.addEventListener('gesturechange', (e) => {\n e.preventDefault();\n const r = box.getBoundingClientRect();\n zoomAt(e.clientX - r.left, e.clientY - r.top, e.scale / Number(box.dataset.g));\n box.dataset.g = String(e.scale);\n });\n box.addEventListener('gestureend', (e) => { e.preventDefault(); gesture = false; });\n\n // one pointer moves the diagram, two (a pinch on a touch screen) zoom it; a press that does not move is a click\n const pts = new Map();\n let drag = null, pinch = null, moved = false;\n const capture = (id) => {\n try { if (!box.hasPointerCapture(id)) box.setPointerCapture(id); } catch { /* the pointer is already gone */ }\n };\n const two = () => {\n const [a, b] = [...pts.values()];\n return { mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2, d: Math.hypot(a.x - b.x, a.y - b.y) || 1 };\n };\n box.addEventListener('pointerdown', (e) => {\n if (e.target.closest('.pz-bar')) return;\n if (e.pointerType === 'mouse' && e.button !== 0 && e.button !== 1) return;\n if (e.button === 1) e.preventDefault();\n pts.set(e.pointerId, { x: e.clientX, y: e.clientY });\n if (pts.size === 1) {\n drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, x, y };\n moved = false;\n } else if (pts.size === 2) {\n pinch = two();\n drag = null;\n moved = true;\n for (const id of pts.keys()) capture(id);\n }\n });\n box.addEventListener('pointermove', (e) => {\n const p = pts.get(e.pointerId);\n if (!p) return;\n p.x = e.clientX;\n p.y = e.clientY;\n if (pinch && pts.size >= 2) {\n const n = two(), r = box.getBoundingClientRect();\n x -= (n.mx - pinch.mx) / s;\n y -= (n.my - pinch.my) / s;\n zoomAt(n.mx - r.left, n.my - r.top, n.d / pinch.d);\n pinch = n;\n return;\n }\n if (!drag || drag.id !== e.pointerId) return;\n const dx = e.clientX - drag.sx, dy = e.clientY - drag.sy;\n if (!moved && Math.hypot(dx, dy) < 4) return;\n if (!moved) {\n moved = true;\n capture(e.pointerId);\n box.classList.add('pz-grabbing');\n }\n x = drag.x - dx / s;\n y = drag.y - dy / s;\n fitted = false;\n draw();\n });\n const up = (e) => {\n if (!pts.delete(e.pointerId)) return;\n if (pts.size < 2) pinch = null;\n if (pts.size === 1) {\n // the finger left on the screen after a pinch carries on moving, from where it is now\n const [[id, p]] = [...pts];\n drag = { id, sx: p.x, sy: p.y, x, y };\n } else if (pts.size === 0) {\n drag = null;\n box.classList.remove('pz-grabbing');\n }\n };\n box.addEventListener('pointerup', up);\n box.addEventListener('pointercancel', up);\n box.addEventListener('dragstart', (e) => e.preventDefault());\n box.addEventListener('click', (e) => {\n if (moved) {\n e.preventDefault();\n e.stopPropagation();\n moved = false;\n return;\n }\n // a step's link leads to its section further down the page, which the full window would hide\n if (e.target.closest('a') && host.classList.contains('pz-full')) setFull(false);\n }, true);\n\n box.addEventListener('keydown', (e) => {\n moved = false;\n if (e.altKey || e.ctrlKey || e.metaKey || e.target.closest('.pz-bar') && (e.key === 'Enter' || e.key === ' ')) return;\n const step = e.shiftKey ? 240 : 60;\n if (e.shiftKey && e.code === 'Digit1') fit();\n else if (e.shiftKey && e.code === 'Digit0') actual();\n else if (e.key === '+' || e.key === '=') zoomAt(vw / 2, vh / 2, 1.25);\n else if (e.key === '-' || e.key === '_') zoomAt(vw / 2, vh / 2, 0.8);\n else if (e.key === 'ArrowLeft') { x -= step / s; fitted = false; draw(); }\n else if (e.key === 'ArrowRight') { x += step / s; fitted = false; draw(); }\n else if (e.key === 'ArrowUp') { y -= step / s; fitted = false; draw(); }\n else if (e.key === 'ArrowDown') { y += step / s; fitted = false; draw(); }\n else if (e.key === 'f' || e.key === 'F') setFull(!host.classList.contains('pz-full'));\n else if (e.key === 'Escape' && host.classList.contains('pz-full')) setFull(false);\n else return;\n e.preventDefault();\n });\n document.addEventListener('keydown', (e) => {\n if (e.key === 'Escape' && host.classList.contains('pz-full') && !box.contains(document.activeElement)) setFull(false);\n });\n }\n})();</script>";
package/dist/pan.js ADDED
@@ -0,0 +1,252 @@
1
+ // The diagram as a canvas to move around, as in a design tool: it opens fitted to its box, a drag moves it (the hand),
2
+ // Ctrl or ⌘ with the wheel, or a pinch, zooms at the pointer, and the wheel alone moves it until an edge, after which
3
+ // the page scrolls on. Shift+1 fits it again, Shift+0 shows it at 100%, and "Full window" gives it the whole window.
4
+ // Without scripts the page keeps its plain diagram, which scrolls sideways.
5
+ export const PAN_CSS = `
6
+ .pz-on { position: relative; height: 78vh; min-height: 360px; overflow: hidden; margin-left: calc(50% - 50vw + 24px); margin-right: calc(50% - 50vw + 24px); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
7
+ .pz-on.pz-grabbing, .pz-on.pz-grabbing a { cursor: grabbing; }
8
+ .pz-on:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
9
+ .pz-on svg.spine { width: 100%; height: 100%; max-width: none; padding: 0; margin: 0; }
10
+ .pz-on a { cursor: pointer; -webkit-user-drag: none; }
11
+ .pz-bar { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; cursor: default; }
12
+ .pz-bar button { font: 13px system-ui, sans-serif; min-width: 32px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
13
+ .pz-bar button:hover { border-color: var(--muted); } .pz-bar button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
14
+ .pz-bar .pz-pct { min-width: 58px; font-variant-numeric: tabular-nums; }
15
+ .pz-hint { position: absolute; left: 10px; bottom: 10px; margin: 0; padding: 2px 8px; border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 12px; pointer-events: none; }
16
+ html.pz-lock, html.pz-lock body { overflow: hidden; }
17
+ .pz-host.pz-full { position: fixed; inset: 0; z-index: 100; margin: 0; padding: 10px 12px 12px; background: var(--bg); display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto minmax(0, 1fr); align-items: center; }
18
+ .pz-host.pz-full { row-gap: 10px; } .pz-host.pz-full > label { margin: 0; }
19
+ .pz-host.pz-full > .pz-on { grid-column: 1 / -1; grid-row: 2; align-self: stretch; height: auto; min-height: 0; margin: 0; }
20
+ .pz-on.pz-full { position: fixed; inset: 0; z-index: 100; height: auto; min-height: 0; margin: 0; border-radius: 0; }
21
+ `;
22
+ // plain JavaScript, run as the page loads; it reads no data and sends nothing
23
+ export const PAN_SCRIPT = `<script>(() => {
24
+ const PAD = 24, MAX = 4;
25
+ for (const box of document.querySelectorAll('.pz')) {
26
+ const svg = box.querySelector('svg.spine');
27
+ if (!svg || !svg.viewBox.baseVal || !svg.viewBox.baseVal.width) continue;
28
+ const W = svg.viewBox.baseVal.width, H = svg.viewBox.baseVal.height;
29
+ const host = box.closest('.pz-host') || box;
30
+ svg.removeAttribute('style');
31
+ box.classList.add('pz-on');
32
+ box.tabIndex = 0;
33
+
34
+ let s = 1, x = 0, y = 0, vw = 0, vh = 0, fitted = true;
35
+ const bar = document.createElement('div');
36
+ bar.className = 'pz-bar';
37
+ const button = (text, title, act) => {
38
+ const b = document.createElement('button');
39
+ b.type = 'button';
40
+ b.textContent = text;
41
+ b.title = title;
42
+ b.addEventListener('click', act);
43
+ bar.append(b);
44
+ return b;
45
+ };
46
+ const fitScale = () => Math.max(Math.min((vw - 2 * PAD) / W, (vh - 2 * PAD) / H), 0.001);
47
+ const minScale = () => Math.min(fitScale(), 1) / 2;
48
+ // where the box's top left may be on an axis, in the diagram's units. Snug: centred when the diagram fits on it,
49
+ // else from PAD before its start to PAD past its end. The hand may go further, until the diagram's edge reaches
50
+ // the middle of the box, so it is never lost.
51
+ const snug = (len, view) => {
52
+ const p = PAD / s;
53
+ return len + 2 * p <= view ? [(len - view) / 2, (len - view) / 2] : [-p, len + p - view];
54
+ };
55
+ const free = (len, view) => {
56
+ const [lo, hi] = snug(len, view);
57
+ return [Math.min(lo, -view / 2), Math.max(hi, len - view / 2)];
58
+ };
59
+ const within = (v, [lo, hi]) => Math.min(Math.max(v, lo), hi);
60
+ const clamp = () => {
61
+ x = within(x, free(W, vw / s));
62
+ y = within(y, free(H, vh / s));
63
+ };
64
+ const draw = () => {
65
+ clamp();
66
+ svg.setAttribute('viewBox', x + ' ' + y + ' ' + vw / s + ' ' + vh / s);
67
+ pct.textContent = Math.round(s * 100) + '%';
68
+ };
69
+ const zoomAt = (px, py, factor) => {
70
+ const ns = Math.min(MAX, Math.max(minScale(), s * factor));
71
+ const dx = x + px / s, dy = y + py / s;
72
+ s = ns;
73
+ x = dx - px / s;
74
+ y = dy - py / s;
75
+ fitted = false;
76
+ draw();
77
+ };
78
+ const fit = () => {
79
+ s = fitScale();
80
+ x = (W - vw / s) / 2;
81
+ y = (H - vh / s) / 2;
82
+ fitted = true;
83
+ draw();
84
+ };
85
+ const actual = () => zoomAt(vw / 2, vh / 2, 1 / s);
86
+ const setFull = (on) => {
87
+ host.classList.toggle('pz-full', on);
88
+ document.documentElement.classList.toggle('pz-lock', on);
89
+ for (const b of host.querySelectorAll('.pz-fs')) b.textContent = on ? 'Exit full window' : 'Full window';
90
+ if (on) box.focus({ preventScroll: true });
91
+ };
92
+
93
+ button('\\u2212', 'Zoom out (\\u2212)', () => zoomAt(vw / 2, vh / 2, 0.8));
94
+ const pct = button('100%', 'Show at 100% (Shift+0)', actual);
95
+ pct.className = 'pz-pct';
96
+ button('+', 'Zoom in (+)', () => zoomAt(vw / 2, vh / 2, 1.25));
97
+ button('Fit', 'Fit the whole diagram (Shift+1)', fit);
98
+ button('Full window', 'Give the diagram the whole window (F; Esc leaves it)', () => setFull(!host.classList.contains('pz-full'))).className = 'pz-fs';
99
+ const hint = document.createElement('p');
100
+ hint.className = 'pz-hint';
101
+ hint.textContent = 'Drag to move \\u00b7 Ctrl or \\u2318 + scroll, or pinch, to zoom \\u00b7 Shift+1 fits';
102
+ box.append(bar, hint);
103
+
104
+ // a new size keeps a fitted diagram fitted, and keeps the centre of one zoomed by hand; a hidden box (the other
105
+ // view) keeps its place for when it shows again
106
+ new ResizeObserver(() => {
107
+ const nw = box.clientWidth, nh = box.clientHeight;
108
+ if (!nw || !nh) return;
109
+ const first = !vw, cx = x + vw / (2 * s), cy = y + vh / (2 * s);
110
+ vw = nw;
111
+ vh = nh;
112
+ if (first || fitted) return fit();
113
+ x = cx - vw / (2 * s);
114
+ y = cy - vh / (2 * s);
115
+ draw();
116
+ }).observe(box);
117
+
118
+ let gesture = false;
119
+ box.addEventListener('wheel', (e) => {
120
+ if (!vw) return;
121
+ const r = box.getBoundingClientRect();
122
+ const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? vh : 1;
123
+ if (e.ctrlKey || e.metaKey) {
124
+ e.preventDefault();
125
+ if (gesture) return;
126
+ const d = Math.max(-50, Math.min(50, e.deltaY * unit));
127
+ zoomAt(e.clientX - r.left, e.clientY - r.top, Math.exp(-d * 0.006));
128
+ return;
129
+ }
130
+ let dx = e.deltaX * unit, dy = e.deltaY * unit;
131
+ if (e.shiftKey && dx === 0) { dx = dy; dy = 0; }
132
+ // the wheel moves the diagram only within its snug range (or back toward it); at the end of that range, or on a
133
+ // diagram that fits, it scrolls the page instead
134
+ const [xl, xh] = snug(W, vw / s), [yl, yh] = snug(H, vh / s);
135
+ const nx = within(x + dx / s, [Math.min(xl, x), Math.max(xh, x)]);
136
+ const ny = within(y + dy / s, [Math.min(yl, y), Math.max(yh, y)]);
137
+ if (Math.abs(nx - x) * s < 0.5 && Math.abs(ny - y) * s < 0.5) return;
138
+ e.preventDefault();
139
+ x = nx;
140
+ y = ny;
141
+ fitted = false;
142
+ draw();
143
+ }, { passive: false });
144
+ // Safari's pinch on a trackpad
145
+ box.addEventListener('gesturestart', (e) => { e.preventDefault(); gesture = true; box.dataset.g = '1'; });
146
+ box.addEventListener('gesturechange', (e) => {
147
+ e.preventDefault();
148
+ const r = box.getBoundingClientRect();
149
+ zoomAt(e.clientX - r.left, e.clientY - r.top, e.scale / Number(box.dataset.g));
150
+ box.dataset.g = String(e.scale);
151
+ });
152
+ box.addEventListener('gestureend', (e) => { e.preventDefault(); gesture = false; });
153
+
154
+ // one pointer moves the diagram, two (a pinch on a touch screen) zoom it; a press that does not move is a click
155
+ const pts = new Map();
156
+ let drag = null, pinch = null, moved = false;
157
+ const capture = (id) => {
158
+ try { if (!box.hasPointerCapture(id)) box.setPointerCapture(id); } catch { /* the pointer is already gone */ }
159
+ };
160
+ const two = () => {
161
+ const [a, b] = [...pts.values()];
162
+ return { mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2, d: Math.hypot(a.x - b.x, a.y - b.y) || 1 };
163
+ };
164
+ box.addEventListener('pointerdown', (e) => {
165
+ if (e.target.closest('.pz-bar')) return;
166
+ if (e.pointerType === 'mouse' && e.button !== 0 && e.button !== 1) return;
167
+ if (e.button === 1) e.preventDefault();
168
+ pts.set(e.pointerId, { x: e.clientX, y: e.clientY });
169
+ if (pts.size === 1) {
170
+ drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, x, y };
171
+ moved = false;
172
+ } else if (pts.size === 2) {
173
+ pinch = two();
174
+ drag = null;
175
+ moved = true;
176
+ for (const id of pts.keys()) capture(id);
177
+ }
178
+ });
179
+ box.addEventListener('pointermove', (e) => {
180
+ const p = pts.get(e.pointerId);
181
+ if (!p) return;
182
+ p.x = e.clientX;
183
+ p.y = e.clientY;
184
+ if (pinch && pts.size >= 2) {
185
+ const n = two(), r = box.getBoundingClientRect();
186
+ x -= (n.mx - pinch.mx) / s;
187
+ y -= (n.my - pinch.my) / s;
188
+ zoomAt(n.mx - r.left, n.my - r.top, n.d / pinch.d);
189
+ pinch = n;
190
+ return;
191
+ }
192
+ if (!drag || drag.id !== e.pointerId) return;
193
+ const dx = e.clientX - drag.sx, dy = e.clientY - drag.sy;
194
+ if (!moved && Math.hypot(dx, dy) < 4) return;
195
+ if (!moved) {
196
+ moved = true;
197
+ capture(e.pointerId);
198
+ box.classList.add('pz-grabbing');
199
+ }
200
+ x = drag.x - dx / s;
201
+ y = drag.y - dy / s;
202
+ fitted = false;
203
+ draw();
204
+ });
205
+ const up = (e) => {
206
+ if (!pts.delete(e.pointerId)) return;
207
+ if (pts.size < 2) pinch = null;
208
+ if (pts.size === 1) {
209
+ // the finger left on the screen after a pinch carries on moving, from where it is now
210
+ const [[id, p]] = [...pts];
211
+ drag = { id, sx: p.x, sy: p.y, x, y };
212
+ } else if (pts.size === 0) {
213
+ drag = null;
214
+ box.classList.remove('pz-grabbing');
215
+ }
216
+ };
217
+ box.addEventListener('pointerup', up);
218
+ box.addEventListener('pointercancel', up);
219
+ box.addEventListener('dragstart', (e) => e.preventDefault());
220
+ box.addEventListener('click', (e) => {
221
+ if (moved) {
222
+ e.preventDefault();
223
+ e.stopPropagation();
224
+ moved = false;
225
+ return;
226
+ }
227
+ // a step's link leads to its section further down the page, which the full window would hide
228
+ if (e.target.closest('a') && host.classList.contains('pz-full')) setFull(false);
229
+ }, true);
230
+
231
+ box.addEventListener('keydown', (e) => {
232
+ moved = false;
233
+ if (e.altKey || e.ctrlKey || e.metaKey || e.target.closest('.pz-bar') && (e.key === 'Enter' || e.key === ' ')) return;
234
+ const step = e.shiftKey ? 240 : 60;
235
+ if (e.shiftKey && e.code === 'Digit1') fit();
236
+ else if (e.shiftKey && e.code === 'Digit0') actual();
237
+ else if (e.key === '+' || e.key === '=') zoomAt(vw / 2, vh / 2, 1.25);
238
+ else if (e.key === '-' || e.key === '_') zoomAt(vw / 2, vh / 2, 0.8);
239
+ else if (e.key === 'ArrowLeft') { x -= step / s; fitted = false; draw(); }
240
+ else if (e.key === 'ArrowRight') { x += step / s; fitted = false; draw(); }
241
+ else if (e.key === 'ArrowUp') { y -= step / s; fitted = false; draw(); }
242
+ else if (e.key === 'ArrowDown') { y += step / s; fitted = false; draw(); }
243
+ else if (e.key === 'f' || e.key === 'F') setFull(!host.classList.contains('pz-full'));
244
+ else if (e.key === 'Escape' && host.classList.contains('pz-full')) setFull(false);
245
+ else return;
246
+ e.preventDefault();
247
+ });
248
+ document.addEventListener('keydown', (e) => {
249
+ if (e.key === 'Escape' && host.classList.contains('pz-full') && !box.contains(document.activeElement)) setFull(false);
250
+ });
251
+ }
252
+ })();</script>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delurio/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "The open checker and page of delurio-graph/0: check every graph in a project's own CI, offline, with GNU error lines and SARIF.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",