Capture steps from the screen and walk through a sequence one step at a time (Refs #23)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 12:26:04 -05:00
parent 29f44440ca
commit f089a00b66
6 changed files with 125 additions and 5 deletions

View File

@@ -65,6 +65,7 @@ A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text wit
- **Sub-tabs:** `ops.js` holds the pure logic (`tabsOf`, `entriesInTab`, `moveToTab`, `moveWithin`, `removeSubsection`, `printGroups`). The records stay in one array, and the tab bar filters them. The shown tab is in `state.tabs` (not saved). Up/down moves a record past its nearest neighbour in the same tab. Deleting a tab sends its records to General. Print writes one sub-heading per non-empty tab. - **Sub-tabs:** `ops.js` holds the pure logic (`tabsOf`, `entriesInTab`, `moveToTab`, `moveWithin`, `removeSubsection`, `printGroups`). The records stay in one array, and the tab bar filters them. The shown tab is in `state.tabs` (not saved). Up/down moves a record past its nearest neighbour in the same tab. Deleting a tab sends its records to General. Print writes one sub-heading per non-empty tab.
- **Images:** drag and drop, clipboard paste and file picker all feed `importFiles()`. Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each. - **Images:** drag and drop, clipboard paste and file picker all feed `importFiles()`. Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each.
- **Walkthroughs (issue #23):** a sequence frame may carry `ifStuck` text and a `stop` flag, and a sequence a `captured` date. In Edit, "Capture from screen…" uses `getDisplayMedia` (`startScreenCapture`, `grabScreenFrame`, `stopScreenCapture` in `images.js`; the stream lives in a closure variable in `app.js`, ended when leaving edit mode) and adds frames via `addCapture()` in `ops.js`. In view mode `state.walk` (`{id, k}`, not saved) shows a sequence one step at a time (`walkSequence`).
- **Reset (`?reset=1`):** opening the file with `?reset=1` or `#reset=1` shows a banner after unlock offering to erase every secret-flagged field value and secret frame (`clearSecrets()` in `ops.js`, count from `countSecrets`). Labels, structure and flags stay. It is read live (`resetRequested()`), with a `hashchange` listener to re-offer, and `state.resetOffered` dismisses it. Nothing is written until Save, so make a Backup copy first. It's meant for working on layout on a less safe machine. - **Reset (`?reset=1`):** opening the file with `?reset=1` or `#reset=1` shows a banner after unlock offering to erase every secret-flagged field value and secret frame (`clearSecrets()` in `ops.js`, count from `countSecrets`). Labels, structure and flags stay. It is read live (`resetRequested()`), with a `hashchange` listener to re-offer, and `state.resetOffered` dismisses it. Nothing is written until Save, so make a Backup copy first. It's meant for working on layout on a less safe machine.
**Save.** Uses the File System Access API (`showSaveFilePicker`, handle reused) where available, otherwise a Blob download. `assemble()` rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. "Backup copy" downloads `final-wishes-YYYYMMDD.html`. **Save.** Uses the File System Access API (`showSaveFilePicker`, handle reused) where available, otherwise a Blob download. `assemble()` rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. "Backup copy" downloads `final-wishes-YYYYMMDD.html`.

View File

@@ -160,6 +160,22 @@ not part of a record or item, so it sits exactly where you put it.
- **Secret** (per step) hides both the picture and the text behind Show/Hide - **Secret** (per step) hides both the picture and the text behind Show/Hide
and withholds it from a masked print. Steps are numbered 1, 2, 3… in view and withholds it from a masked print. Steps are numbered 1, 2, 3… in view
and in print, and a step is kept on one page. and in print, and a step is kept on one page.
- **Capture from the screen:** in Edit, **Capture from screen…** asks the
browser to share a window or tab (nothing is recorded or sent anywhere).
Log in to the site yourself, get to the screen you want, come back to this
page and click **Capture step**. Each click adds one step with that picture;
repeat for each screen, then **Stop sharing** (it also stops when you leave
Edit). Account numbers and balances in a screenshot are real data: mark the
step **secret**, or capture a screen before they appear. Works in Chrome,
Edge and Firefox opened from a file. Pasting a screenshot still works too.
- **If it looks different or fails:** each step has an optional note for what
to do when the screen is not what the picture shows (who to call, what to
say). Tick **Stop here** to tell the reader not to go further without help.
Both show in the list, the walkthrough and print, and are hidden with a
secret step.
- **Walkthrough:** in view mode, **Walk through, one step at a time** shows one
step with Back / Next. A sequence made from captures shows its capture date
and a reminder that the site may have changed since.
- Files saved with sequences cannot be opened by older builds; opening an - Files saved with sequences cannot be opened by older builds; opening an
older file in a newer build (see below) still works. **Cancel** and the older file in a newer build (see below) still works. **Cancel** and the
other editing rules work the same as for records. other editing rules work the same as for records.

View File

@@ -13,6 +13,7 @@
pwChanged: false, // passphrase changed since the last save pwChanged: false, // passphrase changed since the last save
tabs: {}, // section id -> id of the sub-tab being shown ('' = General); not saved tabs: {}, // section id -> id of the sub-tab being shown ('' = General); not saved
collapsed: new Set(), // ids of records folded to just their title (view mode only) collapsed: new Set(), // ids of records folded to just their title (view mode only)
walk: null, // { id, k }: the visual sequence shown as a one-step-at-a-time walkthrough (not saved)
revealed: new WeakSet(), // secret field objects currently shown revealed: new WeakSet(), // secret field objects currently shown
blob: null, // encrypted payload taken from a file the user chose to open blob: null, // encrypted payload taken from a file the user chose to open
handle: null, // File System Access handle once the user picked a save location handle: null, // File System Access handle once the user picked a save location
@@ -157,6 +158,35 @@
const allRecords = () => state.doc.sections.flatMap((s) => (s.records || []).filter((r) => !isSequence(r))); const allRecords = () => state.doc.sections.flatMap((s) => (s.records || []).filter((r) => !isSequence(r)));
const addFrameFrom = (seq) => (name, url) => addFrame(seq, url); const addFrameFrom = (seq) => (name, url) => addFrame(seq, url);
// Screen capture while editing a visual sequence. The stream lives here, not in
// the DOM, so it survives render(). { stream, video, seqId } or null.
let capture = null;
function endCapture() { stopScreenCapture(capture); capture = null; }
async function beginCapture(q) {
endCapture();
try {
const cap = await startScreenCapture();
cap.seqId = q.id;
cap.stream.getVideoTracks()[0].onended = () => { if (capture === cap) { capture = null; setStatus('Screen sharing ended.'); render(); } };
capture = cap;
setStatus('Sharing. Get the site to the screen you want, come back here and click Capture step.');
} catch (err) {
setStatus(err.message);
}
render();
}
async function captureStep(q) {
try {
const url = await processImageFile(await grabScreenFrame(capture));
addCapture(q, url);
changed(q); // clears the status, so set it afterwards
setStatus('Step ' + q.frames.length + ' captured.');
} catch (err) {
setStatus(err.message);
}
render();
}
// Add each file as a new image field on `rec`, or put the first into // Add each file as a new image field on `rec`, or put the first into
// `opts.replace` (an existing image field). Per-file problems are reported // `opts.replace` (an existing image field). Per-file problems are reported
// together; the files that worked are still kept. // together; the files that worked are still kept.
@@ -308,14 +338,37 @@
onclick: () => openLightbox(label, f.image), onkeydown: (e) => { if (e.key === 'Enter') openLightbox(label, f.image); } }) onclick: () => openLightbox(label, f.image), onkeydown: (e) => { if (e.key === 'Enter') openLightbox(label, f.image); } })
: h('span', { class: 'muted' }, '(no image)'), : h('span', { class: 'muted' }, '(no image)'),
layout !== 'none' ? h('p', { class: 'ftext' }, f.text) : null, layout !== 'none' ? h('p', { class: 'ftext' }, f.text) : null,
f.stop || String(f.ifStuck || '').trim() ? h('div', { class: 'fnotes' },
f.stop ? h('p', { class: 'fstop' }, h('strong', {}, 'Stop here. Do not go further.')) : null,
String(f.ifStuck || '').trim() ? h('p', { class: 'fstuck' }, h('strong', {}, 'If it looks different or fails: '), f.ifStuck) : null) : null,
f.secret ? btn('Hide', toggle, 'link', { 'aria-label': 'Hide ' + label }) : null]); f.secret ? btn('Hide', toggle, 'link', { 'aria-label': 'Hide ' + label }) : null]);
} }
const capturedNote = (q) => (q.captured ? ' Captured ' + q.captured + '. The site may have changed since.' : '');
// One step at a time, with Back/Next. A secret step stays hidden until shown, as in the list.
function walkSequence(q) {
const n = q.frames.length;
const k = Math.max(0, Math.min(state.walk.k, n - 1));
const go = (to) => () => { state.walk = { id: q.id, k: to }; render(); };
return h('article', { class: 'card seq walk', 'data-seq': q.id },
h('h3', {}, q.title),
viewFrame(q, q.frames[k], k),
h('div', { class: 'row walknav' },
btn('\u2190 Back', go(k - 1), '', { disabled: k === 0 }),
h('span', { class: 'muted', role: 'status' }, 'Step ' + (k + 1) + ' of ' + n),
btn('Next \u2192', go(k + 1), 'primary', { disabled: k === n - 1 }),
btn('Show all steps', () => { state.walk = null; render(); }, 'link')),
h('p', { class: 'muted small' }, 'Updated ' + q.updated + '.' + capturedNote(q)));
}
function viewSequence(q) { function viewSequence(q) {
if (state.walk && state.walk.id === q.id && q.frames.length) return walkSequence(q);
return h('article', { class: 'card seq' }, return h('article', { class: 'card seq' },
h('h3', {}, q.title), h('h3', {}, q.title),
q.frames.length ? btn('Walk through, one step at a time', () => { state.walk = { id: q.id, k: 0 }; render(); }, 'small') : null,
q.frames.length ? h('div', { class: 'frames' }, q.frames.map((f, k) => viewFrame(q, f, k))) : h('p', { class: 'muted' }, '(no steps yet)'), q.frames.length ? h('div', { class: 'frames' }, q.frames.map((f, k) => viewFrame(q, f, k))) : h('p', { class: 'muted' }, '(no steps yet)'),
h('p', { class: 'muted small' }, 'Updated ' + q.updated)); h('p', { class: 'muted small' }, 'Updated ' + q.updated + '.' + capturedNote(q)));
} }
const seqItem = (q) => h('li', { class: 'seqitem' }, viewSequence(q)); const seqItem = (q) => h('li', { class: 'seqitem' }, viewSequence(q));
@@ -467,13 +520,17 @@
function editFrame(q, f, k) { function editFrame(q, f, k) {
const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret step', const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret step',
onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(q); } }); onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(q); } });
const stop = h('input', { type: 'checkbox', checked: !!f.stop, 'aria-label': 'Stop here, step ' + (k + 1),
onchange: () => { f.stop = stop.checked || undefined; if (!f.stop) delete f.stop; changed(q); } });
const layout = h('select', { 'aria-label': 'Text position for step ' + (k + 1), onchange: () => { f.layout = layout.value; changed(q); render(); } }, const layout = h('select', { 'aria-label': 'Text position for step ' + (k + 1), onchange: () => { f.layout = layout.value; changed(q); render(); } },
LAYOUT_LABELS.map(([v, t]) => h('option', { value: v, selected: f.layout === v }, t))); LAYOUT_LABELS.map(([v, t]) => h('option', { value: v, selected: f.layout === v }, t)));
return h('div', { class: 'field imagefield frameedit' }, return h('div', { class: 'field imagefield frameedit' },
h('div', { class: 'row' }, h('strong', {}, 'Step ' + (k + 1)), layout, h('label', { class: 'check' }, secret, ' secret'), rowTools(q.frames, k, 'step', q)), h('div', { class: 'row' }, h('strong', {}, 'Step ' + (k + 1)), layout, h('label', { class: 'check' }, secret, ' secret'), rowTools(q.frames, k, 'step', q)),
imageZone(f, 'image', q.title + ', step ' + (k + 1), { 'data-frame': String(k) }, imageZone(f, 'image', q.title + ', step ' + (k + 1), { 'data-frame': String(k) },
(files) => importFiles(q, files, { key: 'image', replace: f, add: addFrameFrom(q) }), () => changed(q)), (files) => importFiles(q, files, { key: 'image', replace: f, add: addFrameFrom(q) }), () => changed(q)),
f.layout === 'none' ? null : h('label', {}, 'Text', input(f, 'text', { multiline: true, label: 'Text for step ' + (k + 1) }, q))); f.layout === 'none' ? null : h('label', {}, 'Text', input(f, 'text', { multiline: true, label: 'Text for step ' + (k + 1) }, q)),
h('label', {}, 'If it looks different or fails', input(f, 'ifStuck', { multiline: true, label: 'If step ' + (k + 1) + ' looks different or fails' }, q)),
h('label', { class: 'check' }, stop, ' Stop here: the reader must not go further without help'));
} }
function editSequence(list, q, i, s) { function editSequence(list, q, i, s) {
@@ -487,7 +544,10 @@
q.frames.map((f, k) => editFrame(q, f, k)), q.frames.map((f, k) => editFrame(q, f, k)),
h('div', { class: 'row' }, h('div', { class: 'row' },
btn('+ Add step', () => { addFrame(q); changed(q); render(); }, 'small'), btn('+ Add step', () => { addFrame(q); changed(q); render(); }, 'small'),
btn('+ Add images\u2026', () => picker.click(), 'small'), picker)); btn('+ Add images\u2026', () => picker.click(), 'small'), picker,
capture && capture.seqId === q.id
? [btn('Capture step', () => captureStep(q), 'primary small'), btn('Stop sharing', () => { endCapture(); setStatus('Stopped sharing.'); render(); }, 'small')]
: btn('Capture from screen\u2026', () => beginCapture(q), 'small', { title: 'Share the window with the site, then capture each screen you want as a step' })));
} }
const addSeqBtn = (s) => btn('+ Add visual sequence', () => { addSequence(state.doc, s, s.kind === 'records' ? currentTab(s) : ''); markDirty(); render(); }, 'primary'); const addSeqBtn = (s) => btn('+ Add visual sequence', () => { addSequence(state.doc, s, s.kind === 'records' ? currentTab(s) : ''); markDirty(); render(); }, 'primary');
@@ -572,12 +632,15 @@
v.withheld ? h('p', { class: 'psecret' }, '[withheld]') v.withheld ? h('p', { class: 'psecret' }, '[withheld]')
: v.image ? h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) }) : v.image ? h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) })
: h('p', {}, '(no image)'), : h('p', {}, '(no image)'),
v.layout !== 'none' ? h('p', { class: 'pftext' }, v.text) : null); v.layout !== 'none' ? h('p', { class: 'pftext' }, v.text) : null,
v.stop ? h('p', { class: 'pstop' }, h('strong', {}, 'STOP HERE. Do not go further.')) : null,
v.ifStuck ? h('p', { class: 'pftext' }, h('strong', {}, 'If it looks different or fails: '), v.ifStuck) : null);
} }
function printSequence(q, includeSecrets) { function printSequence(q, includeSecrets) {
return h('div', { class: 'pseq' }, return h('div', { class: 'pseq' },
h('h3', {}, q.title), h('h3', {}, q.title),
q.captured ? h('p', { class: 'pftext' }, 'Captured ' + q.captured + '. The site may have changed since.') : null,
q.frames.map((f, k) => printFrame(f, k, includeSecrets))); q.frames.map((f, k) => printFrame(f, k, includeSecrets)));
} }
@@ -782,6 +845,7 @@
} }
function render() { function render() {
if (capture && !state.editing) endCapture(); // sharing only lasts while editing
root.replaceChildren(); root.replaceChildren();
if (!state.doc) return root.append(renderStart()); if (!state.doc) return root.append(renderStart());
const onHeader = state.current === HEADER_ID; const onHeader = state.current === HEADER_ID;

View File

@@ -85,3 +85,37 @@ export async function processImageFile(blob) {
if (bmp.close) bmp.close(); if (bmp.close) bmp.close();
} }
} }
// Browser only. Screen capture for building a walkthrough: the user shares a
// window or tab, then each grab is one frame. Nothing is recorded or sent anywhere.
export async function startScreenCapture() {
if (!navigator.mediaDevices || !navigator.mediaDevices.getDisplayMedia) {
throw new Error('This browser cannot capture the screen. Take a screenshot and paste it instead.');
}
let stream;
try {
stream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: false });
} catch (err) {
throw new Error(err && err.name === 'NotAllowedError' ? 'Screen sharing was cancelled.' : 'Screen sharing could not start.');
}
const video = document.createElement('video');
video.srcObject = stream;
video.muted = true;
await video.play();
return { stream, video };
}
export function stopScreenCapture(cap) {
if (cap && cap.stream) cap.stream.getTracks().forEach((t) => t.stop());
}
// The current picture of a started capture, as a PNG blob.
export function grabScreenFrame(cap) {
const v = cap.video;
if (!v.videoWidth || !v.videoHeight) return Promise.reject(new Error('The shared window has no picture yet. Try again in a moment.'));
const canvas = document.createElement('canvas');
canvas.width = v.videoWidth;
canvas.height = v.videoHeight;
canvas.getContext('2d').drawImage(v, 0, 0);
return new Promise((resolve, reject) => canvas.toBlob((b) => (b ? resolve(b) : reject(new Error('Could not grab the picture.'))), 'image/png'));
}

View File

@@ -58,6 +58,10 @@ textarea { width: 100%; display: block; } label { display: block; margin-top: .5
.frame.right { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } .frame .fimg { margin: 0; } .frame.right { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } .frame .fimg { margin: 0; }
.fnum { font-weight: 700; color: var(--accent); } .ftext { white-space: pre-wrap; margin: 0; } .fnum { font-weight: 700; color: var(--accent); } .ftext { white-space: pre-wrap; margin: 0; }
li.seqitem { display: block; list-style: none; margin-left: -1.4rem; } .frameedit { border-top: 1px dashed var(--line); padding-top: .5rem; } li.seqitem { display: block; list-style: none; margin-left: -1.4rem; } .frameedit { border-top: 1px dashed var(--line); padding-top: .5rem; }
.fnotes { grid-column: 1 / -1; display: grid; gap: .35rem; } .fnotes p { margin: 0; }
.fstop { border: 2px solid var(--danger); color: var(--danger); border-radius: .35rem; padding: .35rem .6rem; }
.fstuck { background: var(--warn-bg); color: var(--warn-fg); border-radius: .35rem; padding: .35rem .6rem; white-space: pre-wrap; }
.walk .fimg { max-height: 28rem; } .walknav { align-items: center; margin-top: .75rem; }
@media (max-width: 700px) { .frame.right { grid-template-columns: minmax(0, 1fr); } } @media (max-width: 700px) { .frame.right { grid-template-columns: minmax(0, 1fr); } }
dialog.lightbox { max-width: 92vw; max-height: 92vh; overflow: auto; } .bigimg { display: block; max-width: 100%; max-height: 75vh; margin: 0 auto .75rem; background: #fff; } dialog.lightbox { max-width: 92vw; max-height: 92vh; overflow: auto; } .bigimg { display: block; max-width: 100%; max-height: 75vh; margin: 0 auto .75rem; background: #fff; }
@@ -101,6 +105,7 @@ dialog.lightbox { max-width: 92vw; max-height: 92vh; overflow: auto; } .bigimg {
.pframe { break-inside: avoid; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3pt 12pt; align-items: start; margin: 0 0 10pt; } .pframe { break-inside: avoid; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3pt 12pt; align-items: start; margin: 0 0 10pt; }
.pframe.right { grid-template-columns: 3.9in minmax(0, 1fr); } .pframe.right .pimg { max-height: 3.4in; } .pframe.right { grid-template-columns: 3.9in minmax(0, 1fr); } .pframe.right .pimg { max-height: 3.4in; }
.pfnum { grid-column: 1 / -1; font: 700 9.5pt system-ui, sans-serif; break-after: avoid; } .pframe p { margin: 0; } .pftext { white-space: pre-wrap; } .pfnum { grid-column: 1 / -1; font: 700 9.5pt system-ui, sans-serif; break-after: avoid; } .pframe p { margin: 0; } .pftext { white-space: pre-wrap; }
.pstop { grid-column: 1 / -1; border: 1.5pt solid #000; padding: 2pt 5pt; }
.psecret { font-family: ui-monospace, Consolas, monospace; } .psecret { font-family: ui-monospace, Consolas, monospace; }
.ptag { font: 700 8pt system-ui, sans-serif; border: 1pt solid #000; padding: 0 4pt; margin-left: 8pt; border-radius: 2pt; vertical-align: middle; } .ptag { font: 700 8pt system-ui, sans-serif; border: 1pt solid #000; padding: 0 4pt; margin-left: 8pt; border-radius: 2pt; vertical-align: middle; }
.pnotes, .pbody, .pintro { white-space: pre-wrap; margin: 4pt 0 0; } .pnotes, .pbody, .pintro { white-space: pre-wrap; margin: 4pt 0 0; }

View File

@@ -2,7 +2,7 @@
// YYMMDD is the date, X the iteration that day (A first, B second, ...). // YYMMDD is the date, X the iteration that day (A first, B second, ...).
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`. // Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
export const APP_VERSION = '261124A'; export const APP_VERSION = '261124B';
const VERSION_RE = /^(\d{6})([A-Z])$/; const VERSION_RE = /^(\d{6})([A-Z])$/;
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v); export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);