Files
obsidian-excalidraw-plugin/scripts/testing/host/svgReloadProbe.mjs
T
zsviczian 5156e39ace Improve SVG-to-Excalidraw conversion fidelity and regression coverage (#3018)
Preserve SVG paint inheritance, transparency, open paths, compound holes, transforms and local reuse in editable native output. Keep synchronous EA workbench imports and atomic failure handling.

Add bounded geometry conversion, localized limitation notices, 51 focused regressions and native corpus/editor validation. Document compositing/stroke limits, geometry costs and the unresolved ResizeObserver runtime notification.
2026-10-27 18:13:16 +01:00

30 lines
1.1 KiB
JavaScript

/** Existing converted drawings must reopen after reload without regeneration/migration. */
export async function probeSvgReload(key, path, expected) {
const c = globalThis[key];
let leaf = app.workspace
.getLeavesOfType("excalidraw")
.find((l) => l.view.file?.path === path);
leaf ??= app.workspace.getLeaf("tab");
await leaf.setViewState({ type: "excalidraw", state: { file: path } });
for (let i = 0; i < 200; i++) {
if (globalThis[key] !== c) throw Error("SVG reload cancelled");
const view = leaf.view;
if (
view.excalidrawAPI &&
view.getViewElements().length === expected.length
) {
for (const snapshot of expected) {
const actual = view.getViewElements().find((e) => e.id === snapshot.id);
if (!actual) throw Error("reload lost native SVG element");
for (const [field, value] of Object.entries(snapshot))
if (JSON.stringify(actual[field]) !== JSON.stringify(value))
throw Error(`reload changed SVG ${field}`);
}
c.reload = true;
return;
}
await new Promise((r) => setTimeout(r, 50));
}
throw Error("SVG reload did not restore drawing");
}