daigram 0.0.0-stage → 0.1.0
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/LICENSE +661 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +11 -0
- package/README.md +788 -2
- package/assets/fonts/CascadiaCode-Regular.ttf +0 -0
- package/assets/fonts/Excalifont-Regular.ttf +0 -0
- package/assets/fonts/LICENSES.md +63 -0
- package/assets/fonts/LiberationSans-Regular.ttf +0 -0
- package/assets/fonts/Virgil-Regular.ttf +0 -0
- package/dist/ai/config.d.ts +11 -0
- package/dist/ai/config.d.ts.map +1 -0
- package/dist/ai/config.js +59 -0
- package/dist/ai/config.js.map +1 -0
- package/dist/ai/providers/anthropic.d.ts +3 -0
- package/dist/ai/providers/anthropic.d.ts.map +1 -0
- package/dist/ai/providers/anthropic.js +71 -0
- package/dist/ai/providers/anthropic.js.map +1 -0
- package/dist/ai/providers/openai-compatible.d.ts +3 -0
- package/dist/ai/providers/openai-compatible.d.ts.map +1 -0
- package/dist/ai/providers/openai-compatible.js +95 -0
- package/dist/ai/providers/openai-compatible.js.map +1 -0
- package/dist/ai/request-settings.d.ts +9 -0
- package/dist/ai/request-settings.d.ts.map +1 -0
- package/dist/ai/request-settings.js +56 -0
- package/dist/ai/request-settings.js.map +1 -0
- package/dist/ai/routes.d.ts +7 -0
- package/dist/ai/routes.d.ts.map +1 -0
- package/dist/ai/routes.js +192 -0
- package/dist/ai/routes.js.map +1 -0
- package/dist/ai/runner.d.ts +19 -0
- package/dist/ai/runner.d.ts.map +1 -0
- package/dist/ai/runner.js +77 -0
- package/dist/ai/runner.js.map +1 -0
- package/dist/ai/sse.d.ts +4 -0
- package/dist/ai/sse.d.ts.map +1 -0
- package/dist/ai/sse.js +53 -0
- package/dist/ai/sse.js.map +1 -0
- package/dist/ai/system.d.ts +2 -0
- package/dist/ai/system.d.ts.map +1 -0
- package/dist/ai/system.js +17 -0
- package/dist/ai/system.js.map +1 -0
- package/dist/ai/tools.d.ts +10 -0
- package/dist/ai/tools.d.ts.map +1 -0
- package/dist/ai/tools.js +134 -0
- package/dist/ai/tools.js.map +1 -0
- package/dist/ai/types.d.ts +72 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +52 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli/args.d.ts +15 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +78 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/commands/ai.d.ts +2 -0
- package/dist/cli/commands/ai.d.ts.map +1 -0
- package/dist/cli/commands/ai.js +45 -0
- package/dist/cli/commands/ai.js.map +1 -0
- package/dist/cli/commands/arrange.d.ts +2 -0
- package/dist/cli/commands/arrange.d.ts.map +1 -0
- package/dist/cli/commands/arrange.js +103 -0
- package/dist/cli/commands/arrange.js.map +1 -0
- package/dist/cli/commands/canvases.d.ts +2 -0
- package/dist/cli/commands/canvases.d.ts.map +1 -0
- package/dist/cli/commands/canvases.js +38 -0
- package/dist/cli/commands/canvases.js.map +1 -0
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +15 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/comment.d.ts +2 -0
- package/dist/cli/commands/comment.d.ts.map +1 -0
- package/dist/cli/commands/comment.js +76 -0
- package/dist/cli/commands/comment.js.map +1 -0
- package/dist/cli/commands/elements.d.ts +8 -0
- package/dist/cli/commands/elements.d.ts.map +1 -0
- package/dist/cli/commands/elements.js +285 -0
- package/dist/cli/commands/elements.js.map +1 -0
- package/dist/cli/commands/frame.d.ts +2 -0
- package/dist/cli/commands/frame.d.ts.map +1 -0
- package/dist/cli/commands/frame.js +58 -0
- package/dist/cli/commands/frame.js.map +1 -0
- package/dist/cli/commands/install-skill.d.ts +2 -0
- package/dist/cli/commands/install-skill.d.ts.map +1 -0
- package/dist/cli/commands/install-skill.js +108 -0
- package/dist/cli/commands/install-skill.js.map +1 -0
- package/dist/cli/commands/layout.d.ts +2 -0
- package/dist/cli/commands/layout.d.ts.map +1 -0
- package/dist/cli/commands/layout.js +15 -0
- package/dist/cli/commands/layout.js.map +1 -0
- package/dist/cli/commands/render.d.ts +2 -0
- package/dist/cli/commands/render.d.ts.map +1 -0
- package/dist/cli/commands/render.js +64 -0
- package/dist/cli/commands/render.js.map +1 -0
- package/dist/cli/commands/scene.d.ts +8 -0
- package/dist/cli/commands/scene.d.ts.map +1 -0
- package/dist/cli/commands/scene.js +147 -0
- package/dist/cli/commands/scene.js.map +1 -0
- package/dist/cli/commands/server.d.ts +4 -0
- package/dist/cli/commands/server.d.ts.map +1 -0
- package/dist/cli/commands/server.js +66 -0
- package/dist/cli/commands/server.js.map +1 -0
- package/dist/cli/commands/snapshot.d.ts +2 -0
- package/dist/cli/commands/snapshot.d.ts.map +1 -0
- package/dist/cli/commands/snapshot.js +41 -0
- package/dist/cli/commands/snapshot.js.map +1 -0
- package/dist/cli/image-options.d.ts +43 -0
- package/dist/cli/image-options.d.ts.map +1 -0
- package/dist/cli/image-options.js +71 -0
- package/dist/cli/image-options.js.map +1 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +115 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/util.d.ts +5 -0
- package/dist/cli/util.d.ts.map +1 -0
- package/dist/cli/util.js +35 -0
- package/dist/cli/util.js.map +1 -0
- package/dist/core/arrow-routing.d.ts +31 -0
- package/dist/core/arrow-routing.d.ts.map +1 -0
- package/dist/core/arrow-routing.js +244 -0
- package/dist/core/arrow-routing.js.map +1 -0
- package/dist/core/bulk-ops.d.ts +55 -0
- package/dist/core/bulk-ops.d.ts.map +1 -0
- package/dist/core/bulk-ops.js +181 -0
- package/dist/core/bulk-ops.js.map +1 -0
- package/dist/core/canvas-client.d.ts +110 -0
- package/dist/core/canvas-client.d.ts.map +1 -0
- package/dist/core/canvas-client.js +416 -0
- package/dist/core/canvas-client.js.map +1 -0
- package/dist/core/canvas-id.d.ts +4 -0
- package/dist/core/canvas-id.d.ts.map +1 -0
- package/dist/core/canvas-id.js +5 -0
- package/dist/core/canvas-id.js.map +1 -0
- package/dist/core/canvas-persistence.d.ts +30 -0
- package/dist/core/canvas-persistence.d.ts.map +1 -0
- package/dist/core/canvas-persistence.js +854 -0
- package/dist/core/canvas-persistence.js.map +1 -0
- package/dist/core/canvas-registry.d.ts +36 -0
- package/dist/core/canvas-registry.d.ts.map +1 -0
- package/dist/core/canvas-registry.js +161 -0
- package/dist/core/canvas-registry.js.map +1 -0
- package/dist/core/canvas-routes.d.ts +5 -0
- package/dist/core/canvas-routes.d.ts.map +1 -0
- package/dist/core/canvas-routes.js +29 -0
- package/dist/core/canvas-routes.js.map +1 -0
- package/dist/core/canvas-state.d.ts +14 -0
- package/dist/core/canvas-state.d.ts.map +1 -0
- package/dist/core/canvas-state.js +20 -0
- package/dist/core/canvas-state.js.map +1 -0
- package/dist/core/canvas.d.ts +13 -0
- package/dist/core/canvas.d.ts.map +1 -0
- package/dist/core/canvas.js +4 -0
- package/dist/core/canvas.js.map +1 -0
- package/dist/core/comment-ops.d.ts +3 -0
- package/dist/core/comment-ops.d.ts.map +1 -0
- package/dist/core/comment-ops.js +36 -0
- package/dist/core/comment-ops.js.map +1 -0
- package/dist/core/comments.d.ts +5 -0
- package/dist/core/comments.d.ts.map +1 -0
- package/dist/core/comments.js +137 -0
- package/dist/core/comments.js.map +1 -0
- package/dist/core/compact.d.ts +13 -0
- package/dist/core/compact.d.ts.map +1 -0
- package/dist/core/compact.js +20 -0
- package/dist/core/compact.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +18 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/describe.d.ts +3 -0
- package/dist/core/describe.d.ts.map +1 -0
- package/dist/core/describe.js +94 -0
- package/dist/core/describe.js.map +1 -0
- package/dist/core/design-guide.d.ts +2 -0
- package/dist/core/design-guide.d.ts.map +1 -0
- package/dist/core/design-guide.js +115 -0
- package/dist/core/design-guide.js.map +1 -0
- package/dist/core/diagram-layout.d.ts +64 -0
- package/dist/core/diagram-layout.d.ts.map +1 -0
- package/dist/core/diagram-layout.js +238 -0
- package/dist/core/diagram-layout.js.map +1 -0
- package/dist/core/diagram-ops.d.ts +165 -0
- package/dist/core/diagram-ops.d.ts.map +1 -0
- package/dist/core/diagram-ops.js +46 -0
- package/dist/core/diagram-ops.js.map +1 -0
- package/dist/core/entry.d.ts +3 -0
- package/dist/core/entry.d.ts.map +1 -0
- package/dist/core/entry.js +35 -0
- package/dist/core/entry.js.map +1 -0
- package/dist/core/expand-elements.d.ts +9 -0
- package/dist/core/expand-elements.d.ts.map +1 -0
- package/dist/core/expand-elements.js +277 -0
- package/dist/core/expand-elements.js.map +1 -0
- package/dist/core/frame-ops.d.ts +60 -0
- package/dist/core/frame-ops.d.ts.map +1 -0
- package/dist/core/frame-ops.js +90 -0
- package/dist/core/frame-ops.js.map +1 -0
- package/dist/core/frames.d.ts +31 -0
- package/dist/core/frames.d.ts.map +1 -0
- package/dist/core/frames.js +95 -0
- package/dist/core/frames.js.map +1 -0
- package/dist/core/geometry.d.ts +30 -0
- package/dist/core/geometry.d.ts.map +1 -0
- package/dist/core/geometry.js +167 -0
- package/dist/core/geometry.js.map +1 -0
- package/dist/core/layout-check.d.ts +30 -0
- package/dist/core/layout-check.d.ts.map +1 -0
- package/dist/core/layout-check.js +181 -0
- package/dist/core/layout-check.js.map +1 -0
- package/dist/core/local-origin.d.ts +4 -0
- package/dist/core/local-origin.d.ts.map +1 -0
- package/dist/core/local-origin.js +27 -0
- package/dist/core/local-origin.js.map +1 -0
- package/dist/core/mcp-dispatch.d.ts +9 -0
- package/dist/core/mcp-dispatch.d.ts.map +1 -0
- package/dist/core/mcp-dispatch.js +741 -0
- package/dist/core/mcp-dispatch.js.map +1 -0
- package/dist/core/mcp-http.d.ts +3 -0
- package/dist/core/mcp-http.d.ts.map +1 -0
- package/dist/core/mcp-http.js +38 -0
- package/dist/core/mcp-http.js.map +1 -0
- package/dist/core/mcp-server.d.ts +19 -0
- package/dist/core/mcp-server.d.ts.map +1 -0
- package/dist/core/mcp-server.js +57 -0
- package/dist/core/mcp-server.js.map +1 -0
- package/dist/core/mcp-tools.d.ts +3 -0
- package/dist/core/mcp-tools.d.ts.map +1 -0
- package/dist/core/mcp-tools.js +723 -0
- package/dist/core/mcp-tools.js.map +1 -0
- package/dist/core/normalize.d.ts +26 -0
- package/dist/core/normalize.d.ts.map +1 -0
- package/dist/core/normalize.js +134 -0
- package/dist/core/normalize.js.map +1 -0
- package/dist/core/obsidian-md.d.ts +4 -0
- package/dist/core/obsidian-md.d.ts.map +1 -0
- package/dist/core/obsidian-md.js +227 -0
- package/dist/core/obsidian-md.js.map +1 -0
- package/dist/core/pidfile.d.ts +5 -0
- package/dist/core/pidfile.d.ts.map +1 -0
- package/dist/core/pidfile.js +51 -0
- package/dist/core/pidfile.js.map +1 -0
- package/dist/core/png-scene.d.ts +4 -0
- package/dist/core/png-scene.d.ts.map +1 -0
- package/dist/core/png-scene.js +176 -0
- package/dist/core/png-scene.js.map +1 -0
- package/dist/core/render/excalidraw-node/dom.d.ts +29 -0
- package/dist/core/render/excalidraw-node/dom.d.ts.map +1 -0
- package/dist/core/render/excalidraw-node/dom.js +132 -0
- package/dist/core/render/excalidraw-node/dom.js.map +1 -0
- package/dist/core/render/excalidraw-node/index.d.ts +11 -0
- package/dist/core/render/excalidraw-node/index.d.ts.map +1 -0
- package/dist/core/render/excalidraw-node/index.js +77 -0
- package/dist/core/render/excalidraw-node/index.js.map +1 -0
- package/dist/core/render/fonts.d.ts +34 -0
- package/dist/core/render/fonts.d.ts.map +1 -0
- package/dist/core/render/fonts.js +133 -0
- package/dist/core/render/fonts.js.map +1 -0
- package/dist/core/render/index.d.ts +40 -0
- package/dist/core/render/index.d.ts.map +1 -0
- package/dist/core/render/index.js +135 -0
- package/dist/core/render/index.js.map +1 -0
- package/dist/core/render/png-worker.d.ts +2 -0
- package/dist/core/render/png-worker.d.ts.map +1 -0
- package/dist/core/render/png-worker.js +65 -0
- package/dist/core/render/png-worker.js.map +1 -0
- package/dist/core/render/png.d.ts +15 -0
- package/dist/core/render/png.d.ts.map +1 -0
- package/dist/core/render/png.js +128 -0
- package/dist/core/render/png.js.map +1 -0
- package/dist/core/render/text-metrics.d.ts +2 -0
- package/dist/core/render/text-metrics.d.ts.map +1 -0
- package/dist/core/render/text-metrics.js +136 -0
- package/dist/core/render/text-metrics.js.map +1 -0
- package/dist/core/request-canvas.d.ts +9 -0
- package/dist/core/request-canvas.d.ts.map +1 -0
- package/dist/core/request-canvas.js +2 -0
- package/dist/core/request-canvas.js.map +1 -0
- package/dist/core/request-headers.d.ts +5 -0
- package/dist/core/request-headers.d.ts.map +1 -0
- package/dist/core/request-headers.js +80 -0
- package/dist/core/request-headers.js.map +1 -0
- package/dist/core/scene-input.d.ts +2 -0
- package/dist/core/scene-input.d.ts.map +1 -0
- package/dist/core/scene-input.js +11 -0
- package/dist/core/scene-input.js.map +1 -0
- package/dist/core/scene-io.d.ts +16 -0
- package/dist/core/scene-io.d.ts.map +1 -0
- package/dist/core/scene-io.js +95 -0
- package/dist/core/scene-io.js.map +1 -0
- package/dist/core/share-url.d.ts +3 -0
- package/dist/core/share-url.d.ts.map +1 -0
- package/dist/core/share-url.js +77 -0
- package/dist/core/share-url.js.map +1 -0
- package/dist/core/spawn.d.ts +41 -0
- package/dist/core/spawn.d.ts.map +1 -0
- package/dist/core/spawn.js +153 -0
- package/dist/core/spawn.js.map +1 -0
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +14 -0
- package/dist/core/version.js.map +1 -0
- package/dist/frontend/assets/Assistant-Bold-gm-uSS1B.woff2 +0 -0
- package/dist/frontend/assets/Assistant-Medium-DrcxCXg3.woff2 +0 -0
- package/dist/frontend/assets/Assistant-Regular-DVxZuzxb.woff2 +0 -0
- package/dist/frontend/assets/Assistant-SemiBold-SCI4bEL9.woff2 +0 -0
- package/dist/frontend/assets/Tableau10-CvOaoHrI.js +1 -0
- package/dist/frontend/assets/_commonjs-dynamic-modules-TDtrdbi3.js +1 -0
- package/dist/frontend/assets/abnfDiagram-VCTEODGH-CO_aNPe5.js +1 -0
- package/dist/frontend/assets/advancedFormat-DE2dNp0u.js +1 -0
- package/dist/frontend/assets/ar-SA-G6X2FPQ2-Bq4yiKbc.js +10 -0
- package/dist/frontend/assets/arc--vhPzIZC.js +1 -0
- package/dist/frontend/assets/architectureDiagram-5GKGNRK7-aHYJQElw.js +36 -0
- package/dist/frontend/assets/array-BKyUJesY.js +1 -0
- package/dist/frontend/assets/az-AZ-76LH7QW2-BB3yat67.js +1 -0
- package/dist/frontend/assets/band-dPffDWoQ.js +1 -0
- package/dist/frontend/assets/bg-BG-XCXSNQG7-DmC2FjQc.js +5 -0
- package/dist/frontend/assets/blockDiagram-68f4deed-Bn83vchM.js +118 -0
- package/dist/frontend/assets/blockDiagram-NRAW4CY4-CxaW-TzC.js +129 -0
- package/dist/frontend/assets/bn-BD-2XOGV67Q-DpCbZMS6.js +5 -0
- package/dist/frontend/assets/c4Diagram-15b5d702-Bq7Ko0Vs.js +10 -0
- package/dist/frontend/assets/c4Diagram-UCG6FXSJ-Dh883fAO.js +38 -0
- package/dist/frontend/assets/ca-ES-6MX7JW3Y-CBOshpbV.js +8 -0
- package/dist/frontend/assets/channel-DYvM7vRx.js +1 -0
- package/dist/frontend/assets/chunk-2Q5K7J3B-DaFhLtFc.js +1 -0
- package/dist/frontend/assets/chunk-5VM5RSS4-CyLfaWw7.js +15 -0
- package/dist/frontend/assets/chunk-F27PBJKO-BHNc-edD.js +1 -0
- package/dist/frontend/assets/chunk-G27WJ6UU-BBKiZxqf.js +231 -0
- package/dist/frontend/assets/chunk-JWPE2WC7-7twsn51D.js +1 -0
- package/dist/frontend/assets/chunk-LCL6LL3I-BTwZuXJ6.js +206 -0
- package/dist/frontend/assets/chunk-POPQ4Y6H-CaHDxqyV.js +1 -0
- package/dist/frontend/assets/chunk-SVP7TREG-B8-zByXy.js +88 -0
- package/dist/frontend/assets/chunk-XXDRQBXY-DQLro-7R.js +1 -0
- package/dist/frontend/assets/classDiagram-DTDB5LWJ-Dpwx6IJK.js +1 -0
- package/dist/frontend/assets/classDiagram-d40c83e7-BPxlcZuc.js +2 -0
- package/dist/frontend/assets/classDiagram-v2-JRS7N3AN-Dpwx6IJK.js +1 -0
- package/dist/frontend/assets/classDiagram-v2-d5a6b087-Cyz34qAK.js +2 -0
- package/dist/frontend/assets/clone-Iw0eB1Cb.js +1 -0
- package/dist/frontend/assets/cose-bilkent-JH36ORCC-C4ZX1Xvi.js +1 -0
- package/dist/frontend/assets/createText-d213de94-CDH1rzxH.js +7 -0
- package/dist/frontend/assets/cs-CZ-2BRQDIVT-CGAN69M4.js +11 -0
- package/dist/frontend/assets/cynefin-OW5HDTMX-B8XT9png.js +178 -0
- package/dist/frontend/assets/cynefinDiagram-5FMLGOSQ-COTZjqlj.js +62 -0
- package/dist/frontend/assets/cytoscape-cose-bilkent-D4yGolDn.js +1 -0
- package/dist/frontend/assets/cytoscape.esm-BjAbmLdb.js +331 -0
- package/dist/frontend/assets/da-DK-5WZEPLOC-FIDoeOAn.js +5 -0
- package/dist/frontend/assets/dagre-3AP2YEHR-v8EtxNwx.js +4 -0
- package/dist/frontend/assets/de-DE-XR44H4JA-Hquyrt1G.js +8 -0
- package/dist/frontend/assets/defaultLocale-C4B-KCzX.js +1 -0
- package/dist/frontend/assets/diagram-S7CK7UJ4-BiwOlZBI.js +30 -0
- package/dist/frontend/assets/diagram-UQ7AKVKN-DIfzNs7s.js +41 -0
- package/dist/frontend/assets/diagram-VSXAHHWV-kKkEHy5z.js +3 -0
- package/dist/frontend/assets/diagram-VX7I27RA-zTp2qGKo.js +24 -0
- package/dist/frontend/assets/diagram-Z3DM3KII-hUxSr-QT.js +24 -0
- package/dist/frontend/assets/directory-open-01563666-DWU9wJ6I.js +1 -0
- package/dist/frontend/assets/directory-open-4ed118d0-CunoC1EB.js +1 -0
- package/dist/frontend/assets/ebnfDiagram-PWID7BFC-CRwXBVzS.js +1 -0
- package/dist/frontend/assets/edges-332bd1c7-CbPhghy3.js +4 -0
- package/dist/frontend/assets/el-GR-BZB4AONW-CWRJJANX.js +10 -0
- package/dist/frontend/assets/erDiagram-880f2ed8-CY1dU-f9.js +51 -0
- package/dist/frontend/assets/erDiagram-SSCWMZ5O-BfDW8Lxf.js +99 -0
- package/dist/frontend/assets/es-ES-U4NZUMDT-BwZWIjT5.js +9 -0
- package/dist/frontend/assets/eu-ES-A7QVB2H4-B9suQ9BE.js +11 -0
- package/dist/frontend/assets/fa-IR-HGAKTJCU-tgrKvE4J.js +8 -0
- package/dist/frontend/assets/fi-FI-Z5N7JZ37-Ddoc7R-q.js +6 -0
- package/dist/frontend/assets/file-open-002ab408-DIuFHtCF.js +1 -0
- package/dist/frontend/assets/file-open-7c801643-684qeFg4.js +1 -0
- package/dist/frontend/assets/file-save-3189631c-C1wFhQhH.js +1 -0
- package/dist/frontend/assets/file-save-745eba88-Bb9F9Kg7.js +1 -0
- package/dist/frontend/assets/flowDb-7c981674-DkYacLUz.js +10 -0
- package/dist/frontend/assets/flowDiagram-A5DVABFB-CCBuG42p.js +168 -0
- package/dist/frontend/assets/flowDiagram-cbd28bf7-DhhBmCsw.js +4 -0
- package/dist/frontend/assets/flowDiagram-v2-ffc7f31a-BICbZ5-w.js +1 -0
- package/dist/frontend/assets/flowchart-elk-definition-36e2d292-BsyTsM2Q.js +139 -0
- package/dist/frontend/assets/fr-FR-RHASNOE6-Bzn_6dcd.js +9 -0
- package/dist/frontend/assets/ganttDiagram-04f9e578-CCKAlfpJ.js +257 -0
- package/dist/frontend/assets/ganttDiagram-EL5Y4UJY-B8CXkutd.js +292 -0
- package/dist/frontend/assets/gitGraphDiagram-21fc4d3e-DBAYEQql.js +70 -0
- package/dist/frontend/assets/gitGraphDiagram-WWUBYQGX-Ge5QWjv2.js +106 -0
- package/dist/frontend/assets/gl-ES-HMX3MZ6V-vcZHbFum.js +10 -0
- package/dist/frontend/assets/graph-87dI2d0Q.js +1 -0
- package/dist/frontend/assets/has-D7z5cd7K.js +1 -0
- package/dist/frontend/assets/he-IL-6SHJWFNN-CK07fY3l.js +10 -0
- package/dist/frontend/assets/hi-IN-IWLTKZ5I-CDZ0p7Jv.js +4 -0
- package/dist/frontend/assets/hu-HU-A5ZG7DT2-FH5SLnWy.js +7 -0
- package/dist/frontend/assets/id-ID-SAP4L64H-MjXIXb2f.js +10 -0
- package/dist/frontend/assets/image-blob-reduce.esm-HwCm7IZ0.js +7 -0
- package/dist/frontend/assets/index-6079d271-DiB2AL6F.js +1 -0
- package/dist/frontend/assets/index-BcAUh2Nm.css +1 -0
- package/dist/frontend/assets/index-Biw8Vgb3.js +320 -0
- package/dist/frontend/assets/index-fTyH8AV3.js +354 -0
- package/dist/frontend/assets/infoDiagram-4a4f5b27-BOdJmCUU.js +7 -0
- package/dist/frontend/assets/infoDiagram-RXCK75RN-CNm06Rxs.js +2 -0
- package/dist/frontend/assets/init-Gi6I4Gst.js +1 -0
- package/dist/frontend/assets/ishikawaDiagram-5VMMS53U-DoLWy3n2.js +70 -0
- package/dist/frontend/assets/it-IT-JPQ66NNP-D3n0iaPa.js +11 -0
- package/dist/frontend/assets/ja-JP-DBVTYXUO-ejSNO7M9.js +8 -0
- package/dist/frontend/assets/journeyDiagram-29694f62-Cm6qVjA9.js +139 -0
- package/dist/frontend/assets/journeyDiagram-EYS64GPL-ByZmvOcj.js +139 -0
- package/dist/frontend/assets/kaa-6HZHGXH3-D8l_gwno.js +1 -0
- package/dist/frontend/assets/kab-KAB-ZGHBKWFO-CCdAUgdW.js +8 -0
- package/dist/frontend/assets/kanban-definition-3QL26DDD-Y5ylzca9.js +89 -0
- package/dist/frontend/assets/katex-C5jXJg4s.js +257 -0
- package/dist/frontend/assets/kk-KZ-P5N5QNE5-DeuZqHeo.js +1 -0
- package/dist/frontend/assets/km-KH-HSX4SM5Z-CiG2k5fk.js +11 -0
- package/dist/frontend/assets/ko-KR-MTYHY66A-KQOGYf_l.js +9 -0
- package/dist/frontend/assets/ku-TR-6OUDTVRD-iPec9Wpx.js +9 -0
- package/dist/frontend/assets/layout-ChryVliD.js +1 -0
- package/dist/frontend/assets/layout-chXYHUIV.js +1 -0
- package/dist/frontend/assets/line-V0o6yOnB.js +1 -0
- package/dist/frontend/assets/linear-BvV3B0Vg.js +1 -0
- package/dist/frontend/assets/lt-LT-XHIRWOB4-CATjC2gQ.js +3 -0
- package/dist/frontend/assets/lv-LV-5QDEKY6T-BsDP-7Dd.js +7 -0
- package/dist/frontend/assets/mindmap-definition-FBJOCRG2-z4KcwRlx.js +96 -0
- package/dist/frontend/assets/mindmap-definition-ac74a2e8-C1QU2vBv.js +95 -0
- package/dist/frontend/assets/mr-IN-CRQNXWMA-DWJhwvxv.js +13 -0
- package/dist/frontend/assets/my-MM-5M5IBNSE-DckXEMN8.js +1 -0
- package/dist/frontend/assets/nb-NO-T6EIAALU-HaOR9ZeX.js +10 -0
- package/dist/frontend/assets/nl-NL-IS3SIHDZ-ef_ywpFu.js +8 -0
- package/dist/frontend/assets/nn-NO-6E72VCQL-Bg7QdVqf.js +8 -0
- package/dist/frontend/assets/oc-FR-POXYY2M6-D5HmBPnC.js +8 -0
- package/dist/frontend/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/frontend/assets/pa-IN-N4M65BXN-BHYM0tZp.js +4 -0
- package/dist/frontend/assets/path-CbwjOpE9.js +1 -0
- package/dist/frontend/assets/pegDiagram-XKGWAZYB-BL0-JiYs.js +1 -0
- package/dist/frontend/assets/pica-CHpl3DYP.js +7 -0
- package/dist/frontend/assets/pie-b97pL0mM.js +1 -0
- package/dist/frontend/assets/pieDiagram-421022e6-DiRybrxD.js +35 -0
- package/dist/frontend/assets/pieDiagram-E7YTZNPT-VybkpWmu.js +39 -0
- package/dist/frontend/assets/pl-PL-T2D74RX3-uZIVDHgu.js +9 -0
- package/dist/frontend/assets/pt-BR-5N22H2LF-dJVfhAeV.js +9 -0
- package/dist/frontend/assets/pt-PT-UZXXM6DQ-DjJzcznP.js +9 -0
- package/dist/frontend/assets/quadrantDiagram-0957ecba-BHJpECv1.js +7 -0
- package/dist/frontend/assets/quadrantDiagram-AXDQQJYC-RAG8nSkZ.js +7 -0
- package/dist/frontend/assets/railroadDiagram-O6MQD6OU-lCMtporN.js +1 -0
- package/dist/frontend/assets/requirementDiagram-23d650b8-mSFTWSrD.js +52 -0
- package/dist/frontend/assets/requirementDiagram-EFPCY7ZU-B8YnTqPO.js +84 -0
- package/dist/frontend/assets/ro-RO-JPDTUUEW-B5X8VOmp.js +11 -0
- package/dist/frontend/assets/roundRect-0PYZxl1G.js +1 -0
- package/dist/frontend/assets/ru-RU-B4JR7IUQ-Czv9kfuz.js +9 -0
- package/dist/frontend/assets/sankeyDiagram-23345273-B3g3P-D1.js +8 -0
- package/dist/frontend/assets/sankeyDiagram-P5KCCOFB-DRm9HHoQ.js +40 -0
- package/dist/frontend/assets/sankeyLinkHorizontal-CgO6js3K.js +1 -0
- package/dist/frontend/assets/sequenceDiagram-17ac3bff-DzZiSttS.js +122 -0
- package/dist/frontend/assets/sequenceDiagram-WJ2MYXX4-BrSDYDx-.js +162 -0
- package/dist/frontend/assets/si-LK-N5RQ5JYF-DFWOZdgD.js +1 -0
- package/dist/frontend/assets/sizeCapture-X5ZJPWSS-CbaN7yeQ.js +1 -0
- package/dist/frontend/assets/sk-SK-C5VTKIMK-B8VlFn2Z.js +6 -0
- package/dist/frontend/assets/sl-SI-NN7IZMDC-CJeSgLEg.js +6 -0
- package/dist/frontend/assets/stateDiagram-9c5f0230-Dzm1fyzw.js +1 -0
- package/dist/frontend/assets/stateDiagram-HBIQ2CUA-B5Nv-PBX.js +1 -0
- package/dist/frontend/assets/stateDiagram-v2-4QOOHH4V-B72hUL6s.js +1 -0
- package/dist/frontend/assets/stateDiagram-v2-51a3dcff-DvLAYBjA.js +1 -0
- package/dist/frontend/assets/styles-2ab5d517-D6473lhT.js +116 -0
- package/dist/frontend/assets/styles-5f03d8d2-CZ5U9u1n.js +160 -0
- package/dist/frontend/assets/styles-edf9a4b0-DzQC88FF.js +207 -0
- package/dist/frontend/assets/subset-shared.chunk.js +84 -0
- package/dist/frontend/assets/subset-worker.chunk.js +1 -0
- package/dist/frontend/assets/sv-SE-XGPEYMSR-BKMKxZWF.js +10 -0
- package/dist/frontend/assets/svgDrawCommon-3ba9043b-CQsuw6x4.js +1 -0
- package/dist/frontend/assets/swimlanes-XN3QIQJK-D6c81JTS.js +1 -0
- package/dist/frontend/assets/swimlanesDiagram-VK2B7HYN-SMIGSMWR.js +8 -0
- package/dist/frontend/assets/ta-IN-2NMHFXQM-BtPPl3RQ.js +9 -0
- package/dist/frontend/assets/th-TH-HPSO5L25-CSjFGi1j.js +2 -0
- package/dist/frontend/assets/timeline-definition-24CTP7MA-DTBgPsOR.js +120 -0
- package/dist/frontend/assets/timeline-definition-7e6b55e7-D44e8lHF.js +61 -0
- package/dist/frontend/assets/tr-TR-DEFEU3FU-BS1kZ0-G.js +7 -0
- package/dist/frontend/assets/uk-UA-QMV73CPH--ucRdDwc.js +6 -0
- package/dist/frontend/assets/union-DI_iry4-.js +1 -0
- package/dist/frontend/assets/vennDiagram-4TSXK5OY-DDIUJU_f.js +34 -0
- package/dist/frontend/assets/vi-VN-M7AON7JQ-BcGYkPOn.js +5 -0
- package/dist/frontend/assets/wardleyDiagram-VM6X3IG4-TfvrOirV.js +78 -0
- package/dist/frontend/assets/xychartDiagram-S5SC5T6Z-DaSdOJbv.js +7 -0
- package/dist/frontend/assets/xychartDiagram-b6496bcd-VIsyqEG1.js +7 -0
- package/dist/frontend/assets/zh-CN-LNUGB5OW-RL4CyEYU.js +10 -0
- package/dist/frontend/assets/zh-HK-E62DVLB3-DKGVR3J1.js +1 -0
- package/dist/frontend/assets/zh-TW-RAJ6MFWO-C7djgh-M.js +9 -0
- package/dist/frontend/assets/zipObject-Bl99JdSU.js +1 -0
- package/dist/frontend/index.html +569 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/render/excalidraw-node.mjs +540 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1684 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +263 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +49 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +63 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +127 -4
- package/skills/excalidraw-skill/SKILL.md +331 -0
- package/skills/excalidraw-skill/evals/evals.json +35 -0
- package/skills/excalidraw-skill/references/cheatsheet.md +217 -0
- package/src/ai/config.ts +58 -0
- package/src/ai/providers/anthropic.ts +62 -0
- package/src/ai/providers/openai-compatible.ts +84 -0
- package/src/ai/request-settings.ts +50 -0
- package/src/ai/routes.ts +157 -0
- package/src/ai/runner.ts +80 -0
- package/src/ai/sse.ts +40 -0
- package/src/ai/system.ts +16 -0
- package/src/ai/tools.ts +130 -0
- package/src/ai/types.ts +48 -0
- package/src/bin.ts +56 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/commands/ai.ts +40 -0
- package/src/cli/commands/arrange.ts +112 -0
- package/src/cli/commands/canvases.ts +37 -0
- package/src/cli/commands/check.ts +15 -0
- package/src/cli/commands/comment.ts +72 -0
- package/src/cli/commands/elements.ts +299 -0
- package/src/cli/commands/frame.ts +55 -0
- package/src/cli/commands/install-skill.ts +116 -0
- package/src/cli/commands/layout.ts +14 -0
- package/src/cli/commands/render.ts +68 -0
- package/src/cli/commands/scene.ts +168 -0
- package/src/cli/commands/server.ts +71 -0
- package/src/cli/commands/snapshot.ts +45 -0
- package/src/cli/image-options.ts +77 -0
- package/src/cli/run.ts +123 -0
- package/src/cli/util.ts +39 -0
- package/src/core/arrow-routing.ts +256 -0
- package/src/core/bulk-ops.ts +183 -0
- package/src/core/canvas-client.ts +525 -0
- package/src/core/canvas-id.ts +8 -0
- package/src/core/canvas-persistence.ts +1067 -0
- package/src/core/canvas-registry.ts +180 -0
- package/src/core/canvas-routes.ts +34 -0
- package/src/core/canvas-state.ts +37 -0
- package/src/core/canvas.ts +18 -0
- package/src/core/comment-ops.ts +36 -0
- package/src/core/comments.ts +142 -0
- package/src/core/compact.ts +21 -0
- package/src/core/config.ts +24 -0
- package/src/core/describe.ts +100 -0
- package/src/core/design-guide.ts +114 -0
- package/src/core/diagram-layout.ts +278 -0
- package/src/core/diagram-ops.ts +48 -0
- package/src/core/entry.ts +37 -0
- package/src/core/expand-elements.ts +316 -0
- package/src/core/frame-ops.ts +112 -0
- package/src/core/frames.ts +113 -0
- package/src/core/geometry.ts +213 -0
- package/src/core/layout-check.ts +200 -0
- package/src/core/local-origin.ts +27 -0
- package/src/core/mcp-dispatch.ts +858 -0
- package/src/core/mcp-http.ts +38 -0
- package/src/core/mcp-server.ts +72 -0
- package/src/core/mcp-tools.ts +725 -0
- package/src/core/normalize.ts +158 -0
- package/src/core/obsidian-md.ts +231 -0
- package/src/core/pidfile.ts +52 -0
- package/src/core/png-scene.ts +177 -0
- package/src/core/render/excalidraw-node/dom.ts +159 -0
- package/src/core/render/excalidraw-node/index.ts +100 -0
- package/src/core/render/fonts.ts +173 -0
- package/src/core/render/index.ts +198 -0
- package/src/core/render/png-worker.ts +75 -0
- package/src/core/render/png.ts +148 -0
- package/src/core/render/text-metrics.ts +141 -0
- package/src/core/request-canvas.ts +10 -0
- package/src/core/request-headers.ts +79 -0
- package/src/core/scene-input.ts +11 -0
- package/src/core/scene-io.ts +125 -0
- package/src/core/share-url.ts +99 -0
- package/src/core/spawn.ts +186 -0
- package/src/core/version.ts +13 -0
- package/src/index.ts +86 -0
- package/src/server.ts +1873 -0
- package/src/types.ts +384 -0
- package/src/utils/logger.ts +77 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// PNG rasterizer worker — runs in a separate process on purpose.
|
|
2
|
+
//
|
|
3
|
+
// @resvg/resvg-js is a native addon. A segfault or abort inside a native
|
|
4
|
+
// module kills the entire Node process, which — when rendering happens
|
|
5
|
+
// in-process — takes down the canvas server and its whole in-memory scene.
|
|
6
|
+
// This worker keeps the risky native call out of the server: the parent
|
|
7
|
+
// (svgToPngIsolated in png.ts) spawns this file, sends one JSON request on
|
|
8
|
+
// stdin, and reads one JSON response line from stdout. If the worker dies
|
|
9
|
+
// (SIGSEGV, SIGABRT, non-zero exit), only the worker dies; the parent turns
|
|
10
|
+
// it into a clean error.
|
|
11
|
+
//
|
|
12
|
+
// Wire format (one JSON document per line):
|
|
13
|
+
// request (stdin): { "svg": string, "options": PngOptions }
|
|
14
|
+
// response (stdout): { "ok": true, "data": <base64 png>, "width": n, "height": n }
|
|
15
|
+
// | { "ok": false, "error": string }
|
|
16
|
+
|
|
17
|
+
import { svgToPng } from './png.js';
|
|
18
|
+
|
|
19
|
+
interface WorkerRequest {
|
|
20
|
+
svg: string;
|
|
21
|
+
options: {
|
|
22
|
+
scale: number;
|
|
23
|
+
fontFiles: string[];
|
|
24
|
+
loadSystemFonts: boolean;
|
|
25
|
+
defaultFontFamily: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function main(): void {
|
|
30
|
+
let input = '';
|
|
31
|
+
process.stdin.setEncoding('utf8');
|
|
32
|
+
process.stdin.on('data', (chunk: string) => { input += chunk; });
|
|
33
|
+
process.stdin.on('end', () => {
|
|
34
|
+
let request: WorkerRequest;
|
|
35
|
+
try {
|
|
36
|
+
request = JSON.parse(input) as WorkerRequest;
|
|
37
|
+
if (!request || typeof request.svg !== 'string' || !request.options) {
|
|
38
|
+
throw new Error('invalid request payload');
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
process.stdout.write(JSON.stringify({ ok: false, error: `bad request: ${(error as Error).message}` }) + '\n');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const png = svgToPng(request.svg, request.options);
|
|
46
|
+
const line = JSON.stringify({
|
|
47
|
+
ok: true,
|
|
48
|
+
data: png.data.toString('base64'),
|
|
49
|
+
width: png.width,
|
|
50
|
+
height: png.height
|
|
51
|
+
}) + '\n';
|
|
52
|
+
// Do NOT process.exit() right after write(): for payloads larger than
|
|
53
|
+
// the pipe buffer the write is asynchronous and exit() truncates it.
|
|
54
|
+
// Exiting from the flush callback guarantees the parent sees the full
|
|
55
|
+
// response. Fall back after 10s in case the stream never drains.
|
|
56
|
+
const killTimer = setTimeout(() => process.exit(0), 10_000);
|
|
57
|
+
killTimer.unref();
|
|
58
|
+
process.stdout.write(line, () => {
|
|
59
|
+
clearTimeout(killTimer);
|
|
60
|
+
process.exit(0);
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const line = JSON.stringify({ ok: false, error: (error as Error).message ?? String(error) }) + '\n';
|
|
64
|
+
process.stdout.write(line, () => process.exit(1));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Never let an unhandled rejection escalate to a worker crash report that
|
|
68
|
+
// masks the real problem — report it like a render failure instead.
|
|
69
|
+
process.on('unhandledRejection', (reason) => {
|
|
70
|
+
process.stdout.write(JSON.stringify({ ok: false, error: `unhandled rejection in PNG worker: ${String(reason)}` }) + '\n');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main();
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
// SVG -> PNG through resvg (native, prebuilt per platform, deterministic
|
|
6
|
+
// output for identical input). Fonts must be passed as TTF paths: resvg does
|
|
7
|
+
// not read @font-face from the SVG and ignores WOFF2 files.
|
|
8
|
+
|
|
9
|
+
export interface PngOptions {
|
|
10
|
+
scale: number;
|
|
11
|
+
fontFiles: string[];
|
|
12
|
+
loadSystemFonts: boolean;
|
|
13
|
+
defaultFontFamily: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PngResult {
|
|
17
|
+
data: Buffer;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Loaded lazily via require: the package is CommonJS with a native addon,
|
|
23
|
+
// and this keeps `import` of the renderer cheap when only SVG is requested.
|
|
24
|
+
let resvgModule: any | null = null;
|
|
25
|
+
function loadResvg(): any {
|
|
26
|
+
if (!resvgModule) {
|
|
27
|
+
const require = createRequire(import.meta.url);
|
|
28
|
+
resvgModule = require('@resvg/resvg-js');
|
|
29
|
+
}
|
|
30
|
+
return resvgModule;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Excalidraw stores each image once as <symbol><image width="100%" .../></symbol>
|
|
34
|
+
// and places it with <use href="#id" width=W height=H>. Browsers size the
|
|
35
|
+
// symbol's content to the <use>; resvg does not and draws nothing. Inline
|
|
36
|
+
// every such <use> as a plain <image> of the placed size, keeping the use's
|
|
37
|
+
// other attributes (opacity, transform for flips, mask for crops).
|
|
38
|
+
export function inlineSymbolImages(svg: string): string {
|
|
39
|
+
const symbols = new Map<string, string>();
|
|
40
|
+
for (const match of svg.matchAll(/<symbol id="([^"]+)">\s*(<image\b[^>]*?)\s*\/?>(?:<\/image>)?\s*<\/symbol>/g)) {
|
|
41
|
+
if (match[1] && match[2]) symbols.set(match[1], match[2]);
|
|
42
|
+
}
|
|
43
|
+
if (symbols.size === 0) return svg;
|
|
44
|
+
return svg.replace(/<use\b([^>]*?)\/?>(?:<\/use>)?/g, (whole, attrs: string) => {
|
|
45
|
+
const id = attrs.match(/\b(?:xlink:)?href="#([^"]+)"/)?.[1];
|
|
46
|
+
const image = id ? symbols.get(id) : undefined;
|
|
47
|
+
if (!image) return whole;
|
|
48
|
+
const width = attrs.match(/\swidth="([^"]+)"/)?.[1];
|
|
49
|
+
const height = attrs.match(/\sheight="([^"]+)"/)?.[1];
|
|
50
|
+
if (!width || !height) return whole;
|
|
51
|
+
const sized = image
|
|
52
|
+
.replace(/\swidth="100%"/, ` width="${width}"`)
|
|
53
|
+
.replace(/\sheight="100%"/, ` height="${height}"`);
|
|
54
|
+
const rest = attrs.replace(/\s(?:xlink:)?href="[^"]*"|\swidth="[^"]*"|\sheight="[^"]*"/g, '');
|
|
55
|
+
return `${sized}${rest}/>`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function svgToPng(svg: string, options: PngOptions): PngResult {
|
|
60
|
+
const { Resvg } = loadResvg();
|
|
61
|
+
const resvg = new Resvg(inlineSymbolImages(svg), {
|
|
62
|
+
fitTo: { mode: 'zoom', value: options.scale },
|
|
63
|
+
font: {
|
|
64
|
+
loadSystemFonts: options.loadSystemFonts,
|
|
65
|
+
fontFiles: options.fontFiles,
|
|
66
|
+
defaultFontFamily: options.defaultFontFamily
|
|
67
|
+
},
|
|
68
|
+
logLevel: 'off'
|
|
69
|
+
});
|
|
70
|
+
const image = resvg.render();
|
|
71
|
+
return { data: image.asPng(), width: image.width, height: image.height };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Rasterize in a child process (png-worker.ts) so a crash inside the native
|
|
75
|
+
// resvg addon cannot take down the caller — most importantly the canvas
|
|
76
|
+
// server, whose in-memory scene would be lost with the process. A dead
|
|
77
|
+
// worker surfaces as an ordinary Error here; the server keeps running.
|
|
78
|
+
const PNG_WORKER_PATH = fileURLToPath(new URL('./png-worker.js', import.meta.url));
|
|
79
|
+
const PNG_WORKER_TIMEOUT_MS = Number(process.env.EXCALIDRAW_PNG_WORKER_TIMEOUT_MS) || 120_000;
|
|
80
|
+
|
|
81
|
+
export async function svgToPngIsolated(svg: string, options: PngOptions): Promise<PngResult> {
|
|
82
|
+
return new Promise<PngResult>((resolve, reject) => {
|
|
83
|
+
const child = spawn(process.execPath, [PNG_WORKER_PATH], {
|
|
84
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
85
|
+
env: process.env
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
let stdout = '';
|
|
89
|
+
let stderr = '';
|
|
90
|
+
let settled = false;
|
|
91
|
+
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
child.kill('SIGKILL');
|
|
94
|
+
finish(new Error(`PNG worker timed out after ${PNG_WORKER_TIMEOUT_MS} ms`));
|
|
95
|
+
}, PNG_WORKER_TIMEOUT_MS);
|
|
96
|
+
|
|
97
|
+
function finish(error?: Error): void {
|
|
98
|
+
if (settled) return;
|
|
99
|
+
settled = true;
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
if (error) reject(error);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
child.stdout.setEncoding('utf8');
|
|
105
|
+
child.stdout.on('data', (chunk: string) => { stdout += chunk; });
|
|
106
|
+
child.stderr.setEncoding('utf8');
|
|
107
|
+
child.stderr.on('data', (chunk: string) => { stderr += chunk; });
|
|
108
|
+
|
|
109
|
+
child.on('error', (error: Error) => {
|
|
110
|
+
finish(new Error(`Failed to start PNG worker: ${error.message}`));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
child.on('close', (code: number | null, signal: NodeJS.Signals | null) => {
|
|
114
|
+
const response = stdout.trim().split('\n').pop();
|
|
115
|
+
if (code === 0 && response) {
|
|
116
|
+
try {
|
|
117
|
+
const parsed = JSON.parse(response) as { ok: boolean; data?: string; width?: number; height?: number; error?: string };
|
|
118
|
+
if (parsed.ok && typeof parsed.data === 'string') {
|
|
119
|
+
finish();
|
|
120
|
+
resolve({
|
|
121
|
+
data: Buffer.from(parsed.data, 'base64'),
|
|
122
|
+
width: parsed.width ?? 0,
|
|
123
|
+
height: parsed.height ?? 0
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
finish(new Error(parsed.error ?? 'PNG worker returned an unknown failure'));
|
|
128
|
+
return;
|
|
129
|
+
} catch {
|
|
130
|
+
// fall through to the crash report below
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const detail = signal
|
|
134
|
+
? `PNG worker terminated by ${signal}`
|
|
135
|
+
: `PNG worker exited with code ${code}`;
|
|
136
|
+
const hint = 'The native resvg addon crashed in an isolated worker; the server is unaffected. Try format "svg", renderer "browser", or reinstall @resvg/resvg-js (a corrupted platform binary can crash like this).';
|
|
137
|
+
const tail = stderr.trim().slice(-300);
|
|
138
|
+
finish(new Error(`${detail}: ${hint}${tail ? ` Worker stderr: ${tail}` : ''}`));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
child.stdin.write(JSON.stringify({ svg, options }) + '\n');
|
|
143
|
+
child.stdin.end();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
finish(new Error(`Failed to send request to PNG worker: ${(error as Error).message}`));
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { fontFilePath, getFontEntryByFamilyName, getFontEntry, DEFAULT_FONT_FAMILY } from './fonts.js';
|
|
3
|
+
|
|
4
|
+
// Text measurement for the headless renderer. jsdom has no canvas, so
|
|
5
|
+
// Excalidraw's measureText (used to size and wrap labels) would otherwise get
|
|
6
|
+
// a guess. Instead we read real glyph advance widths from the bundled TTFs
|
|
7
|
+
// (cmap + hmtx tables), so label wrapping and arrow-label masks match what a
|
|
8
|
+
// browser computes with the same fonts.
|
|
9
|
+
|
|
10
|
+
interface FontMetricsTable {
|
|
11
|
+
unitsPerEm: number;
|
|
12
|
+
advance: (codePoint: number) => number | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const tables = new Map<string, FontMetricsTable | null>();
|
|
16
|
+
|
|
17
|
+
function parseTtf(buffer: Buffer): FontMetricsTable {
|
|
18
|
+
const numTables = buffer.readUInt16BE(4);
|
|
19
|
+
const dir = new Map<string, number>();
|
|
20
|
+
for (let i = 0; i < numTables; i++) {
|
|
21
|
+
const rec = 12 + i * 16;
|
|
22
|
+
dir.set(buffer.toString('latin1', rec, rec + 4), buffer.readUInt32BE(rec + 8));
|
|
23
|
+
}
|
|
24
|
+
const head = dir.get('head');
|
|
25
|
+
const hhea = dir.get('hhea');
|
|
26
|
+
const hmtx = dir.get('hmtx');
|
|
27
|
+
const cmap = dir.get('cmap');
|
|
28
|
+
if (head === undefined || hhea === undefined || hmtx === undefined || cmap === undefined) {
|
|
29
|
+
throw new Error('TTF is missing head/hhea/hmtx/cmap');
|
|
30
|
+
}
|
|
31
|
+
const unitsPerEm = buffer.readUInt16BE(head + 18);
|
|
32
|
+
const numHMetrics = buffer.readUInt16BE(hhea + 34);
|
|
33
|
+
const advanceOfGlyph = (glyph: number): number => {
|
|
34
|
+
const index = Math.min(glyph, numHMetrics - 1);
|
|
35
|
+
return buffer.readUInt16BE(hmtx + index * 4);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Prefer a full-Unicode subtable (format 12), else the BMP one (format 4).
|
|
39
|
+
const subtables = buffer.readUInt16BE(cmap + 2);
|
|
40
|
+
let format4 = -1;
|
|
41
|
+
let format12 = -1;
|
|
42
|
+
for (let i = 0; i < subtables; i++) {
|
|
43
|
+
const rec = cmap + 4 + i * 8;
|
|
44
|
+
const platform = buffer.readUInt16BE(rec);
|
|
45
|
+
const encoding = buffer.readUInt16BE(rec + 2);
|
|
46
|
+
const offset = cmap + buffer.readUInt32BE(rec + 4);
|
|
47
|
+
const format = buffer.readUInt16BE(offset);
|
|
48
|
+
const unicode = platform === 0 || (platform === 3 && (encoding === 1 || encoding === 10));
|
|
49
|
+
if (!unicode) continue;
|
|
50
|
+
if (format === 12) format12 = offset;
|
|
51
|
+
if (format === 4 && format4 === -1) format4 = offset;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const glyphCache = new Map<number, number>();
|
|
55
|
+
const glyphFor = (cp: number): number => {
|
|
56
|
+
const cached = glyphCache.get(cp);
|
|
57
|
+
if (cached !== undefined) return cached;
|
|
58
|
+
let glyph = 0;
|
|
59
|
+
if (format12 !== -1) {
|
|
60
|
+
const groups = buffer.readUInt32BE(format12 + 12);
|
|
61
|
+
for (let g = 0; g < groups; g++) {
|
|
62
|
+
const rec = format12 + 16 + g * 12;
|
|
63
|
+
const start = buffer.readUInt32BE(rec);
|
|
64
|
+
const end = buffer.readUInt32BE(rec + 4);
|
|
65
|
+
if (cp >= start && cp <= end) { glyph = buffer.readUInt32BE(rec + 8) + (cp - start); break; }
|
|
66
|
+
}
|
|
67
|
+
} else if (format4 !== -1 && cp <= 0xffff) {
|
|
68
|
+
const segX2 = buffer.readUInt16BE(format4 + 6);
|
|
69
|
+
const ends = format4 + 14;
|
|
70
|
+
const starts = ends + segX2 + 2;
|
|
71
|
+
const deltas = starts + segX2;
|
|
72
|
+
const rangeOffsets = deltas + segX2;
|
|
73
|
+
for (let s = 0; s < segX2; s += 2) {
|
|
74
|
+
if (cp > buffer.readUInt16BE(ends + s)) continue;
|
|
75
|
+
const start = buffer.readUInt16BE(starts + s);
|
|
76
|
+
if (cp < start) break;
|
|
77
|
+
const delta = buffer.readInt16BE(deltas + s);
|
|
78
|
+
const rangeOffset = buffer.readUInt16BE(rangeOffsets + s);
|
|
79
|
+
if (rangeOffset === 0) {
|
|
80
|
+
glyph = (cp + delta) & 0xffff;
|
|
81
|
+
} else {
|
|
82
|
+
const at = rangeOffsets + s + rangeOffset + (cp - start) * 2;
|
|
83
|
+
const raw = buffer.readUInt16BE(at);
|
|
84
|
+
glyph = raw === 0 ? 0 : (raw + delta) & 0xffff;
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
glyphCache.set(cp, glyph);
|
|
90
|
+
return glyph;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
unitsPerEm,
|
|
95
|
+
advance: (cp: number) => {
|
|
96
|
+
const glyph = glyphFor(cp);
|
|
97
|
+
return glyph === 0 ? undefined : advanceOfGlyph(glyph);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function tableForFile(file: string): FontMetricsTable | null {
|
|
103
|
+
if (!tables.has(file)) {
|
|
104
|
+
try {
|
|
105
|
+
tables.set(file, parseTtf(fs.readFileSync(file)));
|
|
106
|
+
} catch {
|
|
107
|
+
tables.set(file, null);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return tables.get(file) ?? null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Parse a CSS font shorthand as Excalidraw writes it, e.g.
|
|
114
|
+
// "20px Excalifont, Xiaolai, Segoe UI Emoji".
|
|
115
|
+
function parseFont(font: string): { size: number; family: string } {
|
|
116
|
+
const match = font.match(/([\d.]+)px\s+(.+)$/);
|
|
117
|
+
const size = match ? Number(match[1]) : 16;
|
|
118
|
+
const first = (match?.[2] ?? '').split(',')[0]?.trim().replace(/^["']|["']$/g, '') ?? '';
|
|
119
|
+
return { size: Number.isFinite(size) ? size : 16, family: first };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Width in px of `text` (a single line) rendered in `font`.
|
|
123
|
+
export function measureTextWidth(text: string, font: string): number {
|
|
124
|
+
const { size, family } = parseFont(font);
|
|
125
|
+
const entry = getFontEntryByFamilyName(family) ?? getFontEntry(DEFAULT_FONT_FAMILY);
|
|
126
|
+
const table = tableForFile(fontFilePath(entry));
|
|
127
|
+
let units = 0;
|
|
128
|
+
let fallbackEm = 0;
|
|
129
|
+
for (const ch of text) {
|
|
130
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
131
|
+
const advance = table?.advance(cp);
|
|
132
|
+
if (advance !== undefined && table) {
|
|
133
|
+
units += advance / table.unitsPerEm;
|
|
134
|
+
} else {
|
|
135
|
+
// Not in the bundled font (CJK, emoji, ...): the browser would fall back
|
|
136
|
+
// to another face; full-width scripts are ~1em, everything else ~0.6em.
|
|
137
|
+
fallbackEm += cp >= 0x1100 ? 1 : 0.6;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return (units + fallbackEm) * size;
|
|
141
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
|
|
3
|
+
// Optional extra headers for canvas API requests (EXCALIDRAW_HEADERS). Generic: the engine does not know what they are for.
|
|
4
|
+
|
|
5
|
+
const TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
6
|
+
// Tab, space and visible ASCII only.
|
|
7
|
+
const VALUE = /^[\t\x20-\x7e]*$/;
|
|
8
|
+
// Owned by the HTTP client; fetch drops or mishandles these.
|
|
9
|
+
const RESERVED = new Set([
|
|
10
|
+
'host', 'content-length', 'transfer-encoding', 'connection', 'upgrade',
|
|
11
|
+
'te', 'trailer', 'keep-alive', 'proxy-connection',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
export function parseExtraHeaders(raw: string | undefined): Record<string, string> {
|
|
15
|
+
const text = (raw ?? '').trim();
|
|
16
|
+
if (!text) return {};
|
|
17
|
+
let parsed: unknown;
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(text);
|
|
20
|
+
} catch {
|
|
21
|
+
throw new Error('EXCALIDRAW_HEADERS must be a JSON object of header names to string values, e.g. {"X-Name":"value"}');
|
|
22
|
+
}
|
|
23
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
24
|
+
throw new Error('EXCALIDRAW_HEADERS must be a JSON object of header names to string values');
|
|
25
|
+
}
|
|
26
|
+
const out: Record<string, string> = {};
|
|
27
|
+
Object.entries(parsed as Record<string, unknown>).forEach(([name, value], i) => {
|
|
28
|
+
const which = `header #${i + 1}`; // by position: a mistyped name or value may itself be the secret
|
|
29
|
+
if (!TOKEN.test(name)) throw new Error(`EXCALIDRAW_HEADERS: ${which} has an invalid name`);
|
|
30
|
+
if (RESERVED.has(name.toLowerCase())) {
|
|
31
|
+
throw new Error(`EXCALIDRAW_HEADERS: "${name.toLowerCase()}" is managed by the HTTP client and cannot be set`);
|
|
32
|
+
}
|
|
33
|
+
if (typeof value !== 'string') throw new Error(`EXCALIDRAW_HEADERS: ${which} must have a string value`);
|
|
34
|
+
if (!VALUE.test(value)) {
|
|
35
|
+
throw new Error(`EXCALIDRAW_HEADERS: ${which} has a value with control or non-ASCII characters`);
|
|
36
|
+
}
|
|
37
|
+
out[name] = value;
|
|
38
|
+
});
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isLoopbackHost(hostname: string): boolean {
|
|
43
|
+
const h = hostname.replace(/^\[|\]$/g, '').toLowerCase();
|
|
44
|
+
if (h === 'localhost') return true;
|
|
45
|
+
if (net.isIPv4(h)) return h.startsWith('127.');
|
|
46
|
+
if (net.isIPv6(h)) return h === '::1';
|
|
47
|
+
return false; // 127.evil.com and localhost.evil.com are NOT loopback
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function assertExtraHeadersUsable(serverUrl: string, env: NodeJS.ProcessEnv = process.env): Record<string, string> {
|
|
51
|
+
const extra = parseExtraHeaders(env.EXCALIDRAW_HEADERS);
|
|
52
|
+
if (Object.keys(extra).length === 0) return extra;
|
|
53
|
+
const target = new URL(serverUrl);
|
|
54
|
+
if (target.protocol !== 'https:' && !isLoopbackHost(target.hostname) && env.EXCALIDRAW_ALLOW_INSECURE_HEADERS !== '1') {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Refusing to send EXCALIDRAW_HEADERS over plain http to ${target.host}; use https:// ` +
|
|
57
|
+
'(or set EXCALIDRAW_ALLOW_INSECURE_HEADERS=1 on a trusted network)'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return extra;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Not for the /health probe: that runs before the service is verified.
|
|
64
|
+
export async function canvasFetch(url: string, init: RequestInit = {}): Promise<Response> {
|
|
65
|
+
const extra = assertExtraHeadersUsable(url);
|
|
66
|
+
if (Object.keys(extra).length === 0) return fetch(url, init);
|
|
67
|
+
|
|
68
|
+
const headers = new Headers(init.headers);
|
|
69
|
+
for (const [name, value] of Object.entries(extra)) if (!headers.has(name)) headers.set(name, value);
|
|
70
|
+
// Redirects are not followed: fetch strips only Authorization/Cookie cross-origin, so other headers would leak.
|
|
71
|
+
const response = await fetch(url, { ...init, headers, redirect: 'manual' });
|
|
72
|
+
if (response.status >= 300 && response.status < 400 && response.headers.has('location')) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`The canvas server answered with a redirect (HTTP ${response.status}); not following it while EXCALIDRAW_HEADERS ` +
|
|
75
|
+
'is set, so the headers cannot leak to another host. Point EXPRESS_SERVER_URL at the final URL.'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isPng, extractPngScene } from './png-scene.js';
|
|
2
|
+
import { isObsidianExcalidrawMd, extractSceneJsonFromObsidianMd } from './obsidian-md.js';
|
|
3
|
+
|
|
4
|
+
// Decode file bytes before parsing JSON; raw data remains a text-only input.
|
|
5
|
+
export function decodeSceneInput(input: Buffer | string): string {
|
|
6
|
+
if (Buffer.isBuffer(input) && isPng(input)) {
|
|
7
|
+
return extractPngScene(input);
|
|
8
|
+
}
|
|
9
|
+
const text = typeof input === 'string' ? input : input.toString('utf-8');
|
|
10
|
+
return isObsidianExcalidrawMd(text) ? extractSceneJsonFromObsidianMd(text) : text;
|
|
11
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { generateId, ServerElement } from '../types.js';
|
|
3
|
+
import {
|
|
4
|
+
getElements,
|
|
5
|
+
getFiles,
|
|
6
|
+
postFiles,
|
|
7
|
+
isDurableCanvasStateEnabled,
|
|
8
|
+
batchCreateElementsOnCanvas,
|
|
9
|
+
replaceElementsOnCanvas
|
|
10
|
+
} from './canvas-client.js';
|
|
11
|
+
import { sanitizeFilePath, IMPORT_FILE_EXTENSIONS } from './normalize.js';
|
|
12
|
+
import { decodeSceneInput } from './scene-input.js';
|
|
13
|
+
import { expandElementsForExport } from './expand-elements.js';
|
|
14
|
+
|
|
15
|
+
export interface ExportedScene {
|
|
16
|
+
scene: Record<string, any>;
|
|
17
|
+
elementCount: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Build a .excalidraw scene JSON from the current canvas state.
|
|
21
|
+
// Elements are expanded from the agent format (label/start/end) into real
|
|
22
|
+
// Excalidraw elements (bound text pairs, arrow bindings) so the file renders
|
|
23
|
+
// fully on excalidraw.com and in the Obsidian Excalidraw plugin — with
|
|
24
|
+
// deterministic ids/seeds so re-exporting an unchanged scene is byte-stable.
|
|
25
|
+
export async function buildSceneFile(): Promise<ExportedScene> {
|
|
26
|
+
const sceneElements = await getElements();
|
|
27
|
+
const exportElements = expandElementsForExport(sceneElements, { deterministic: true });
|
|
28
|
+
|
|
29
|
+
// Fetch files for image elements
|
|
30
|
+
let sceneFiles: Record<string, any> = {};
|
|
31
|
+
try {
|
|
32
|
+
sceneFiles = await getFiles();
|
|
33
|
+
} catch { /* files endpoint may not exist */ }
|
|
34
|
+
|
|
35
|
+
const excalidrawScene: Record<string, any> = {
|
|
36
|
+
type: 'excalidraw',
|
|
37
|
+
version: 2,
|
|
38
|
+
source: 'daigram',
|
|
39
|
+
elements: exportElements,
|
|
40
|
+
appState: {
|
|
41
|
+
viewBackgroundColor: '#ffffff',
|
|
42
|
+
gridSize: null
|
|
43
|
+
},
|
|
44
|
+
...(Object.keys(sceneFiles).length > 0 ? { files: sceneFiles } : {})
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return { scene: excalidrawScene, elementCount: exportElements.length };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ImportResult {
|
|
51
|
+
count: number;
|
|
52
|
+
fileCount: number;
|
|
53
|
+
mode: 'replace' | 'merge';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Import elements from .excalidraw JSON, Obsidian .excalidraw.md, an embedded
|
|
57
|
+
// PNG scene, or raw JSON data.
|
|
58
|
+
export async function importScene(options: {
|
|
59
|
+
filePath?: string;
|
|
60
|
+
data?: string;
|
|
61
|
+
mode: 'replace' | 'merge';
|
|
62
|
+
}): Promise<ImportResult> {
|
|
63
|
+
let input: Buffer | string;
|
|
64
|
+
if (options.filePath) {
|
|
65
|
+
const safeImportPath = sanitizeFilePath(options.filePath, IMPORT_FILE_EXTENSIONS);
|
|
66
|
+
input = fs.readFileSync(safeImportPath);
|
|
67
|
+
} else if (options.data) {
|
|
68
|
+
input = options.data;
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error('Either filePath or data must be provided');
|
|
71
|
+
}
|
|
72
|
+
const sceneData: any = JSON.parse(decodeSceneInput(input));
|
|
73
|
+
|
|
74
|
+
// Extract elements from .excalidraw format or raw array
|
|
75
|
+
const importElements: ServerElement[] = Array.isArray(sceneData)
|
|
76
|
+
? sceneData
|
|
77
|
+
: (sceneData.elements || []);
|
|
78
|
+
|
|
79
|
+
if (importElements.length === 0) {
|
|
80
|
+
throw new Error('No elements found in the import data');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Batch create the imported elements
|
|
84
|
+
const elementsToCreate = importElements.map(el => ({
|
|
85
|
+
...el,
|
|
86
|
+
id: el.id || generateId(),
|
|
87
|
+
createdAt: new Date().toISOString(),
|
|
88
|
+
updatedAt: new Date().toISOString(),
|
|
89
|
+
version: 1
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
let importedFileCount = 0;
|
|
93
|
+
const importFiles = sceneData.files;
|
|
94
|
+
const fileList = importFiles && typeof importFiles === 'object'
|
|
95
|
+
? Object.values(importFiles)
|
|
96
|
+
: [];
|
|
97
|
+
const durableStateEnabled = fileList.length > 0
|
|
98
|
+
? await isDurableCanvasStateEnabled()
|
|
99
|
+
: false;
|
|
100
|
+
|
|
101
|
+
if (durableStateEnabled) {
|
|
102
|
+
// A durable checkpoint cannot reference an image until its immutable blob
|
|
103
|
+
// is published. File failure therefore aborts before touching elements.
|
|
104
|
+
await postFiles(fileList);
|
|
105
|
+
importedFileCount = fileList.length;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const created = options.mode === 'replace'
|
|
109
|
+
? await replaceElementsOnCanvas(elementsToCreate)
|
|
110
|
+
: await batchCreateElementsOnCanvas(elementsToCreate);
|
|
111
|
+
if (!created) {
|
|
112
|
+
throw new Error('Import failed: canvas rejected the batch create');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!durableStateEnabled && fileList.length > 0) {
|
|
116
|
+
// Keep the original in-memory contract: elements are accepted first and
|
|
117
|
+
// file import remains best effort when persistence is disabled.
|
|
118
|
+
try {
|
|
119
|
+
await postFiles(fileList);
|
|
120
|
+
importedFileCount = fileList.length;
|
|
121
|
+
} catch { /* best effort */ }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { count: elementsToCreate.length, fileCount: importedFileCount, mode: options.mode };
|
|
125
|
+
}
|