Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix(viewer): preserve selection after export-owned downloads
HengYang6a9568a93a74
diff --git a/archify/assets/template.html b/archify/assets/template.htmlindex 097545ef..36c105f4 100644--- a/archify/assets/template.html+++ b/archify/assets/template.html@@ -6355,7 +6355,9 @@ OTHER DEALINGS IN THE FONT SOFTWARE.var a = document.createElement('a');a.href = url;a.download = filename;- document.body.appendChild(a);+ // Keep the export-owned activation inside its existing control boundary.+ // The synthetic download click must not dismiss the reader selection.+ menu.appendChild(a);a.click();a.remove();setTimeout(function () { URL.revokeObjectURL(url); }, 1000);diff --git a/archify/references/viewer-runtime.md b/archify/references/viewer-runtime.mdindex b3fbb72c..226edb00 100644--- a/archify/references/viewer-runtime.md+++ b/archify/references/viewer-runtime.md@@ -22,6 +22,8 @@ Every rendered diagram enables reader-controlled Live/Still motion by default. IThe export menu can copy/download full-diagram PNG, download JPEG/WebP, download a dual-theme SVG, and record a trace-enabled WebM. Viewer state—Guide, Lens, finder, focus, route, camera, radar, presentation, motion ownership, and temporary overlays—must be removed from canonical export.+Opening, closing, or completing an export preserves the live Focus/Reach selection for continued exploration. Export-owned download activation is not outside dismissal; genuine outside activation and Escape retain their existing behavior. Full-diagram PNG/SVG exports still contain the complete canonical diagram, while the Reach Share Card communicates the active authored closure.+### Route Share CardAfter a real directed Route Probe resolves, the reader may use **Export → Route Share Card**. It reuses the exact ordered route snapshot and the shared Share Card seam: `format=share-card`, `variant=route`. The isolated clone may use only static `data-share-route-*` decoration. It is download-only, fails closed for stale/unreachable/conflicting routes, and never becomes the canonical artifact.diff --git a/examples/archify-repo-grid.html b/examples/archify-repo-grid.htmlindex 6f99fee2..66562f1a 100644--- a/examples/archify-repo-grid.html+++ b/examples/archify-repo-grid.html@@ -6398,7 +6398,9 @@ OTHER DEALINGS IN THE FONT SOFTWARE.var a = document.createElement('a');a.href = url;a.download = filename;- document.body.appendChild(a);+ // Keep the export-owned activation inside its existing control boundary.+ // The synthetic download click must not dismiss the reader selection.+ menu.appendChild(a);a.click();a.remove();setTimeout(function () { URL.revokeObjectURL(url); }, 1000);diff --git a/examples/archify-repo.html b/examples/archify-repo.htmlindex 6de7f664..ac48bb58 100644--- a/examples/archify-repo.html+++ b/examples/archify-repo.html@@ -6466,7 +6466,9 @@ OTHER DEALINGS IN THE FONT SOFTWARE.var a = document.createElement('a');a.href = url;a.download = filename;- document.body.appendChild(a);+ // Keep the export-owned activation inside its existing control boundary.+ // The synthetic download click must not dismiss the reader selection.+ menu.appendChild(a);a.click();a.remove();setTimeout(function () { URL.revokeObjectURL(url); }, 1000);diff --git a/examples/maka-architecture.html b/examples/maka-architecture.htmlindex 5147ad56..1695943e 100644--- a/examples/maka-architecture.html+++ b/examples/maka-architecture.html@@ -6495,7 +6495,9 @@ OTHER DEALINGS IN THE FONT SOFTWARE.var a = document.createElement('a');a.href = url;a.download = filename;- document.body.appendChild(a);+ // Keep the export-owned activation inside its existing control boundary.+ // The synthetic download click must not dismiss the reader selection.+ menu.appendChild(a);a.click();a.remove();setTimeout(function () { URL.revokeObjectURL(url); }, 1000);diff --git a/test/export-selection-browser.test.mjs b/test/export-selection-browser.test.mjsindex e5ca1871..ab354647 100644--- a/test/export-selection-browser.test.mjs+++ b/test/export-selection-browser.test.mjs@@ -17,6 +17,8 @@ test('Export menu preserves authored reach until genuine outside dismissal', {}, async (t) => {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-export-selection-'));t.after(() => fs.rmSync(root, { recursive: true, force: true }));+ const downloads = path.join(root, 'downloads');+ fs.mkdirSync(downloads);const file = path.join(root, 'architecture.html');execFileSync(process.execPath, [path.join(skillRoot, 'renderers/architecture/render-architecture.mjs'),@@ -26,7 +28,9 @@ test('Export menu preserves authored reach until genuine outside dismissal', {const browser = desktopBrowser(chrome);t.after(() => browser.close());const session = await browser.sessionPromise;- await browser.cdp.send('Browser.setDownloadBehavior', { behavior: 'deny' });+ await browser.cdp.send('Browser.setDownloadBehavior', {+ behavior: 'allow', downloadPath: downloads, eventsEnabled: true,+ });const send = (method, params = {}) => browser.cdp.send(method, params, session);await send('Page.addScriptToEvaluateOnNewDocument', { source: 'window.exportAlerts=[];window.alert=message=>exportAlerts.push(String(message));' });await send('Emulation.setFocusEmulationEnabled', { enabled: true });@@ -66,7 +70,10 @@ test('Export menu preserves authored reach until genuine outside dismissal', {window.exportSelectionClick={trusted:event.isTrusted,snapshot:Archify.focus.reachabilitySnapshot()};}}, {capture:true,once:true})`);+ const downloadStarted = browser.cdp.waitFor('Browser.downloadWillBegin', undefined, 5000);await click('#export-menu [data-action="reach-share-card"]');+ const download = await downloadStarted;+ assert.ok(download.suggestedFilename.endsWith('-reach-share-card.png'));assert.deepEqual(await run('exportSelectionClick'), { trusted: true, snapshot: before },`${artifact} passes the snapshot to the trusted menu-item action`);await run(`new Promise((resolve,reject)=>{const start=performance.now();function sample(){@@ -79,8 +86,46 @@ test('Export menu preserves authored reach until genuine outside dismissal', {}sample();})`);assert.deepEqual(await run(`['width','height'].map(key=>Number(document.documentElement.getAttribute('data-last-export-'+key)))`), [1200, 630]);assert.deepEqual(await run('exportAlerts'), []);- assert.equal(await run(`Archify.focus.set(${JSON.stringify(origin)}, {toggle:false}) && Archify.focus.reach('downstream')`), true);- await run(`document.querySelector('.header-row').click()`);+ assert.deepEqual(await run('Archify.focus.reachabilitySnapshot()'), before,+ `${artifact} preserves Reach for continued exploration after export`);+ const downloaded = path.join(downloads, path.basename(download.suggestedFilename));+ for (let attempt = 0; !fs.existsSync(downloaded) && attempt < 100; attempt++) {+ await new Promise(resolve => setTimeout(resolve, 25));+ }+ const png = fs.readFileSync(downloaded);+ assert.equal(png.subarray(0, 8).toString('hex'), '89504e470d0a1a0a');+ assert.deepEqual([png.readUInt32BE(16), png.readUInt32BE(20)], [1200, 630]);+ fs.rmSync(downloaded);+ for (const format of ['png', 'svg']) {+ await click('#btn-export');+ const started = browser.cdp.waitFor('Browser.downloadWillBegin', undefined, 5000);+ await click(`#export-menu [data-format="${format}"]`);+ const ordinaryDownload = await started;+ const output = path.join(downloads, path.basename(ordinaryDownload.suggestedFilename));+ for (let attempt = 0; !fs.existsSync(output) && attempt < 100; attempt++) {+ await new Promise(resolve => setTimeout(resolve, 25));+ }+ const bytes = fs.readFileSync(output);+ assert.equal(await run(`document.documentElement.getAttribute('data-last-export-canonical')`), 'true');+ assert.deepEqual(await run('Archify.focus.reachabilitySnapshot()'), before,+ `${artifact} retains live Reach after the full-diagram ${format} download`);+ if (format === 'svg') {+ const canonical = await run(`(() => {+ const svg = new DOMParser().parseFromString(${JSON.stringify(bytes.toString('utf8'))}, 'image/svg+xml').documentElement;+ return { viewBox: svg.getAttribute('viewBox'), nodes: [...svg.querySelectorAll('[data-node-id]')].map(node=>node.getAttribute('data-node-id')).sort(),+ reach: svg.querySelectorAll('[data-reach-match], [data-reach-origin], [data-share-reach-match]').length };+ })()`);+ assert.deepEqual(canonical, await run(`(() => {+ const svg = document.querySelector('svg');+ return { viewBox: svg.getAttribute('viewBox'), nodes: [...svg.querySelectorAll('[data-node-id]')].map(node=>node.getAttribute('data-node-id')).sort(), reach: 0 };+ })()`));+ } else {+ assert.equal(bytes.subarray(0, 8).toString('hex'), '89504e470d0a1a0a');+ }+ fs.rmSync(output);+ }+ assert.equal(await run(`document.querySelectorAll('#export-menu a[download]').length`), 0);+ await click('.header-row');assert.equal(await run('Archify.focus.reachabilitySnapshot()'), null);assert.equal(await run('Archify.focus.active()'), null);}diff --git a/viewer/export.js b/viewer/export.jsindex a2c667d1..818e0d05 100644--- a/viewer/export.js+++ b/viewer/export.js@@ -429,7 +429,9 @@var a = document.createElement('a');a.href = url;a.download = filename;- document.body.appendChild(a);+ // Keep the export-owned activation inside its existing control boundary.+ // The synthetic download click must not dismiss the reader selection.+ menu.appendChild(a);a.click();a.remove();setTimeout(function () { URL.revokeObjectURL(url); }, 1000);