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:
72
src/app.js
72
src/app.js
@@ -13,6 +13,7 @@
|
||||
pwChanged: false, // passphrase changed since the last save
|
||||
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)
|
||||
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
|
||||
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
|
||||
@@ -157,6 +158,35 @@
|
||||
const allRecords = () => state.doc.sections.flatMap((s) => (s.records || []).filter((r) => !isSequence(r)));
|
||||
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
|
||||
// `opts.replace` (an existing image field). Per-file problems are reported
|
||||
// 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); } })
|
||||
: h('span', { class: 'muted' }, '(no image)'),
|
||||
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]);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (state.walk && state.walk.id === q.id && q.frames.length) return walkSequence(q);
|
||||
return h('article', { class: 'card seq' },
|
||||
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)'),
|
||||
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));
|
||||
|
||||
@@ -467,13 +520,17 @@
|
||||
function editFrame(q, f, k) {
|
||||
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); } });
|
||||
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(); } },
|
||||
LAYOUT_LABELS.map(([v, t]) => h('option', { value: v, selected: f.layout === v }, t)));
|
||||
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)),
|
||||
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)),
|
||||
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) {
|
||||
@@ -487,7 +544,10 @@
|
||||
q.frames.map((f, k) => editFrame(q, f, k)),
|
||||
h('div', { class: 'row' },
|
||||
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');
|
||||
|
||||
@@ -572,12 +632,15 @@
|
||||
v.withheld ? h('p', { class: 'psecret' }, '[withheld]')
|
||||
: v.image ? h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) })
|
||||
: 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) {
|
||||
return h('div', { class: 'pseq' },
|
||||
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)));
|
||||
}
|
||||
|
||||
@@ -782,6 +845,7 @@
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (capture && !state.editing) endCapture(); // sharing only lasts while editing
|
||||
root.replaceChildren();
|
||||
if (!state.doc) return root.append(renderStart());
|
||||
const onHeader = state.current === HEADER_ID;
|
||||
|
||||
Reference in New Issue
Block a user