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,158 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { generateId, ServerElement, normalizeFontFamily } from '../types.js';
|
|
4
|
+
import { ALLOWED_EXPORT_DIR } from './config.js';
|
|
5
|
+
|
|
6
|
+
// File types MCP tools may read or write (see sanitizeFilePath)
|
|
7
|
+
export const SCENE_FILE_EXTENSIONS = ['.excalidraw', '.json', '.md'] as const;
|
|
8
|
+
export const IMPORT_FILE_EXTENSIONS = [...SCENE_FILE_EXTENSIONS, '.png'] as const;
|
|
9
|
+
|
|
10
|
+
// Resolve symlinks in the part of `target` that exists; the missing rest
|
|
11
|
+
// cannot be a link. A broken link is refused: writing through it would
|
|
12
|
+
// create its target, wherever that points.
|
|
13
|
+
function realpathOfExisting(target: string): string {
|
|
14
|
+
const missing: string[] = [];
|
|
15
|
+
let current = target;
|
|
16
|
+
for (;;) {
|
|
17
|
+
try {
|
|
18
|
+
return path.join(fs.realpathSync(current), ...missing);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
21
|
+
if (code !== 'ENOENT' && code !== 'ENOTDIR') throw error;
|
|
22
|
+
let isLink = false;
|
|
23
|
+
try { isLink = fs.lstatSync(current).isSymbolicLink(); } catch { /* does not exist */ }
|
|
24
|
+
if (isLink) throw new Error(`Path blocked: "${current}" is a broken symbolic link.`);
|
|
25
|
+
}
|
|
26
|
+
const parent = path.dirname(current);
|
|
27
|
+
if (parent === current) return target;
|
|
28
|
+
missing.unshift(path.basename(current));
|
|
29
|
+
current = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Validate a path an MCP tool reads or writes: it must have one of the
|
|
34
|
+
// allowed extensions and, with symlinks resolved, sit inside the allowed
|
|
35
|
+
// directory. Returns the resolved path, so the file accessed is the one checked.
|
|
36
|
+
export function sanitizeFilePath(filePath: string, allowedExtensions: readonly string[]): string {
|
|
37
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
38
|
+
if (!allowedExtensions.includes(extension)) {
|
|
39
|
+
throw new Error(`File type blocked: "${filePath}" must end in ${allowedExtensions.join(', ')}.`);
|
|
40
|
+
}
|
|
41
|
+
const allowedDir = realpathOfExisting(path.resolve(ALLOWED_EXPORT_DIR));
|
|
42
|
+
const resolved = realpathOfExisting(path.resolve(filePath));
|
|
43
|
+
if (!resolved.startsWith(allowedDir + path.sep)) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Path traversal blocked: "${filePath}" resolves outside the allowed directory "${allowedDir}". ` +
|
|
46
|
+
`Set EXCALIDRAW_EXPORT_DIR to change the allowed base directory.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return resolved;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Normalize points to [x, y] tuple format that Excalidraw expects
|
|
53
|
+
export function normalizePoints(points: Array<{ x: number; y: number } | [number, number]>): [number, number][] {
|
|
54
|
+
return points.map(p => {
|
|
55
|
+
if (Array.isArray(p)) return p as [number, number];
|
|
56
|
+
return [p.x, p.y] as [number, number];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Helper function to convert text property to label format for Excalidraw
|
|
61
|
+
export function convertTextToLabel(element: ServerElement): ServerElement {
|
|
62
|
+
const { text, ...rest } = element;
|
|
63
|
+
if (text) {
|
|
64
|
+
// For standalone text elements, keep text as direct property
|
|
65
|
+
if (element.type === 'text') {
|
|
66
|
+
return element; // Keep text as direct property
|
|
67
|
+
}
|
|
68
|
+
// For other elements (rectangle, ellipse, diamond), convert to label format
|
|
69
|
+
return {
|
|
70
|
+
...rest,
|
|
71
|
+
label: { text }
|
|
72
|
+
} as ServerElement;
|
|
73
|
+
}
|
|
74
|
+
return element;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ElementInput {
|
|
78
|
+
id?: string;
|
|
79
|
+
type: string;
|
|
80
|
+
points?: Array<{ x: number; y: number } | [number, number]>;
|
|
81
|
+
startElementId?: string;
|
|
82
|
+
endElementId?: string;
|
|
83
|
+
fontFamily?: string | number;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Shared element preparation: id generation, arrow binding conversion,
|
|
88
|
+
// fontFamily normalization, default points for bound arrows, timestamps,
|
|
89
|
+
// and text→label conversion. Used by create/batch-create in both the MCP
|
|
90
|
+
// server and the CLI so the two front-ends produce identical elements.
|
|
91
|
+
export function prepareElement(elementData: ElementInput): ServerElement {
|
|
92
|
+
const { startElementId, endElementId, id: customId, ...elementProps } = elementData;
|
|
93
|
+
const id = customId || generateId();
|
|
94
|
+
const element: ServerElement = {
|
|
95
|
+
id,
|
|
96
|
+
...elementProps,
|
|
97
|
+
points: elementProps.points ? normalizePoints(elementProps.points) : undefined,
|
|
98
|
+
// Convert binding IDs to Excalidraw's start/end format
|
|
99
|
+
...(startElementId ? { start: { id: startElementId } } : {}),
|
|
100
|
+
...(endElementId ? { end: { id: endElementId } } : {}),
|
|
101
|
+
createdAt: new Date().toISOString(),
|
|
102
|
+
updatedAt: new Date().toISOString(),
|
|
103
|
+
version: 1
|
|
104
|
+
} as ServerElement;
|
|
105
|
+
|
|
106
|
+
// Normalize fontFamily from string names to numeric values
|
|
107
|
+
if (element.fontFamily !== undefined) {
|
|
108
|
+
element.fontFamily = normalizeFontFamily(element.fontFamily);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// For bound arrows without explicit points, set a default
|
|
112
|
+
if ((startElementId || endElementId) && !elementProps.points) {
|
|
113
|
+
(element as any).points = [[0, 0], [100, 0]];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Convert text to label format for Excalidraw
|
|
117
|
+
return convertTextToLabel(element);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Shared update-payload preparation (points, fontFamily, text→label,
|
|
121
|
+
// updatedAt) — used by the MCP update_element tool and the CLI.
|
|
122
|
+
//
|
|
123
|
+
// `knownType` is the element's actual type as fetched from the canvas.
|
|
124
|
+
// Update payloads usually don't carry `type`, and text→label conversion must
|
|
125
|
+
// only happen for non-text elements — converting a standalone text element's
|
|
126
|
+
// `text` into `label` silently fails to change the visible text.
|
|
127
|
+
export function prepareElementUpdate(
|
|
128
|
+
id: string,
|
|
129
|
+
updates: Record<string, unknown>,
|
|
130
|
+
knownType?: string
|
|
131
|
+
): Partial<ServerElement> & { id: string } {
|
|
132
|
+
const { points: rawPoints, ...rest } = updates as {
|
|
133
|
+
points?: Array<{ x: number; y: number } | [number, number]>;
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const updatePayload: Partial<ServerElement> & { id: string } = {
|
|
138
|
+
id,
|
|
139
|
+
...rest,
|
|
140
|
+
points: rawPoints ? normalizePoints(rawPoints) : undefined,
|
|
141
|
+
updatedAt: new Date().toISOString()
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (updatePayload.fontFamily !== undefined) {
|
|
145
|
+
updatePayload.fontFamily = normalizeFontFamily(updatePayload.fontFamily);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Convert text→label only when the element is known to be a non-text
|
|
149
|
+
// shape. Unknown type keeps `text` as-is (the safe direction for text
|
|
150
|
+
// elements; when the canvas is up, callers always know the type).
|
|
151
|
+
const effectiveType = (updates.type as string | undefined) ?? knownType;
|
|
152
|
+
if (updatePayload.text !== undefined && effectiveType && effectiveType !== 'text') {
|
|
153
|
+
const { text, ...withoutText } = updatePayload;
|
|
154
|
+
return { ...withoutText, label: { text } } as Partial<ServerElement> & { id: string };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return updatePayload;
|
|
158
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Obsidian Excalidraw plugin file format (.excalidraw.md).
|
|
2
|
+
//
|
|
3
|
+
// The Obsidian Excalidraw plugin opens raw .excalidraw JSON only in a limited
|
|
4
|
+
// "compatibility mode" ("Convert to new format for full plugin functionality").
|
|
5
|
+
// Its native format is markdown: frontmatter, a "# Excalidraw Data" section
|
|
6
|
+
// whose "## Text Elements" entries expose each text element as an Obsidian
|
|
7
|
+
// block reference, and the scene JSON in a "## Drawing" code block — either
|
|
8
|
+
// plain ```json or lz-string ```compressed-json (the plugin's default).
|
|
9
|
+
//
|
|
10
|
+
// wrap mirrors the plugin's own id semantics (ExcalidrawData.
|
|
11
|
+
// findNewTextElementsInScene): a text element's block id IS its element id,
|
|
12
|
+
// and ids longer than 8 characters are renamed to a fresh 8-char id with
|
|
13
|
+
// every scene reference rewired — so files we write and files the plugin
|
|
14
|
+
// re-saves stay block-reference-compatible.
|
|
15
|
+
|
|
16
|
+
import { canonicalizeKeys } from './expand-elements.js';
|
|
17
|
+
|
|
18
|
+
const ID_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
19
|
+
// Obsidian block ids are alphanumeric-and-dash only — an id containing "_"
|
|
20
|
+
// would be written as an unresolvable block reference, so rename those too.
|
|
21
|
+
const BLOCK_ID_RE = /^[A-Za-z0-9-]{1,8}$/;
|
|
22
|
+
|
|
23
|
+
export function isObsidianExcalidrawMd(content: string): boolean {
|
|
24
|
+
// Raw scene JSON always starts with { or [ — never treat it as markdown,
|
|
25
|
+
// even when a text element happens to contain the marker strings.
|
|
26
|
+
const head = content.trimStart();
|
|
27
|
+
if (head.startsWith('{') || head.startsWith('[')) return false;
|
|
28
|
+
return content.includes('# Excalidraw Data') || /^---[\s\S]*?excalidraw-plugin:/m.test(content);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// FNV-1a 32-bit hash — stable positive int from a string
|
|
32
|
+
function fnv1a(str: string): number {
|
|
33
|
+
let h = 0x811c9dc5;
|
|
34
|
+
for (let i = 0; i < str.length; i++) {
|
|
35
|
+
h ^= str.charCodeAt(i);
|
|
36
|
+
h = Math.imul(h, 0x01000193);
|
|
37
|
+
}
|
|
38
|
+
return h >>> 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Deterministic 8-char block id derived from the original element id, so
|
|
42
|
+
// re-exporting the same scene produces the same block ids and links from
|
|
43
|
+
// other vault notes stay intact across exports.
|
|
44
|
+
function stableId8(sourceId: string, used: Set<string>): string {
|
|
45
|
+
for (let attempt = 0; ; attempt++) {
|
|
46
|
+
const salted = attempt === 0 ? sourceId : `${sourceId}:${attempt}`;
|
|
47
|
+
let bits = (BigInt(fnv1a(salted)) << 32n) | BigInt(fnv1a(`${salted}#2`));
|
|
48
|
+
let id = '';
|
|
49
|
+
for (let i = 0; i < 8; i++) {
|
|
50
|
+
id += ID_ALPHABET[Number(bits % BigInt(ID_ALPHABET.length))];
|
|
51
|
+
bits /= BigInt(ID_ALPHABET.length);
|
|
52
|
+
}
|
|
53
|
+
if (!used.has(id)) return id;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function renameElementId(elements: any[], oldId: string, newId: string): void {
|
|
58
|
+
for (const el of elements) {
|
|
59
|
+
if (el.id === oldId) el.id = newId;
|
|
60
|
+
if (Array.isArray(el.boundElements)) {
|
|
61
|
+
for (const bound of el.boundElements) {
|
|
62
|
+
if (bound.id === oldId) bound.id = newId;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (el.startBinding?.elementId === oldId) el.startBinding.elementId = newId;
|
|
66
|
+
if (el.endBinding?.elementId === oldId) el.endBinding.elementId = newId;
|
|
67
|
+
if (el.containerId === oldId) el.containerId = newId;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function wrapSceneAsObsidianMd(scene: Record<string, any>): string {
|
|
72
|
+
if (!Array.isArray(scene.elements)) {
|
|
73
|
+
throw new Error('Not an Excalidraw scene: missing elements array');
|
|
74
|
+
}
|
|
75
|
+
const wrapped = structuredClone(scene);
|
|
76
|
+
wrapped.type = 'excalidraw';
|
|
77
|
+
wrapped.version = 2;
|
|
78
|
+
wrapped.files = wrapped.files ?? {};
|
|
79
|
+
|
|
80
|
+
const used = new Set<string>(wrapped.elements.map((el: any) => el.id));
|
|
81
|
+
const entries: string[] = [];
|
|
82
|
+
for (const el of wrapped.elements) {
|
|
83
|
+
if (el.type !== 'text' || el.isDeleted) continue;
|
|
84
|
+
if (!BLOCK_ID_RE.test(el.id)) {
|
|
85
|
+
const newId = stableId8(el.id, used);
|
|
86
|
+
used.add(newId);
|
|
87
|
+
renameElementId(wrapped.elements, el.id, newId);
|
|
88
|
+
}
|
|
89
|
+
el.rawText = el.rawText && el.rawText !== '' ? el.rawText : (el.originalText ?? el.text ?? '');
|
|
90
|
+
if (el.rawText !== '') entries.push(`${el.rawText} ^${el.id}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const textSection = entries.length ? entries.join('\n\n') + '\n' : '';
|
|
94
|
+
return `---
|
|
95
|
+
|
|
96
|
+
excalidraw-plugin: parsed
|
|
97
|
+
tags: [excalidraw]
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# Excalidraw Data
|
|
104
|
+
## Text Elements
|
|
105
|
+
${textSection}
|
|
106
|
+
%%
|
|
107
|
+
## Drawing
|
|
108
|
+
\`\`\`json
|
|
109
|
+
${JSON.stringify(canonicalizeKeys(wrapped), null, '\t')}
|
|
110
|
+
\`\`\`
|
|
111
|
+
%%`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function extractSceneJsonFromObsidianMd(md: string): string {
|
|
115
|
+
// The closing fence must sit at the start of a line: element text can
|
|
116
|
+
// contain ``` inside the JSON strings, but a line of pretty-printed JSON
|
|
117
|
+
// never begins with a backtick (this mirrors the plugin's own DRAWING_REG).
|
|
118
|
+
//
|
|
119
|
+
// Every line break matches `\r?\n`: files authored on Windows (or by the
|
|
120
|
+
// Obsidian plugin there) use CRLF, and requiring a bare `\n` made every
|
|
121
|
+
// such file fail with a misleading "No Drawing block found".
|
|
122
|
+
const compressed = md.match(/\r?\n##? Drawing\r?\n[^`]*```compressed-json\r?\n([\s\S]*?)\r?\n```/);
|
|
123
|
+
if (compressed) {
|
|
124
|
+
const json = decompressFromBase64(compressed[1]!.replace(/\s/g, ''));
|
|
125
|
+
if (!json) throw new Error('Failed to decompress the Drawing block');
|
|
126
|
+
JSON.parse(json);
|
|
127
|
+
return json;
|
|
128
|
+
}
|
|
129
|
+
const plain = md.match(/\r?\n##? Drawing\r?\n[^`]*```json\r?\n([\s\S]*?)\r?\n```/);
|
|
130
|
+
if (plain) {
|
|
131
|
+
JSON.parse(plain[1]!);
|
|
132
|
+
return plain[1]!;
|
|
133
|
+
}
|
|
134
|
+
throw new Error('No Drawing block found — not an .excalidraw.md file?');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// lz-string decompressFromBase64 (pieroxy/lz-string, MIT), inlined to keep
|
|
138
|
+
// the package dependency-free.
|
|
139
|
+
const keyStrBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
140
|
+
const f = String.fromCharCode;
|
|
141
|
+
|
|
142
|
+
function decompressFromBase64(input: string): string | null {
|
|
143
|
+
if (input === '') return null;
|
|
144
|
+
return _decompress(input.length, 32, (index) => keyStrBase64.indexOf(input.charAt(index)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function _decompress(
|
|
148
|
+
length: number,
|
|
149
|
+
resetValue: number,
|
|
150
|
+
getNextValue: (index: number) => number
|
|
151
|
+
): string | null {
|
|
152
|
+
const dictionary: (string | number)[] = [];
|
|
153
|
+
let enlargeIn = 4;
|
|
154
|
+
let dictSize = 4;
|
|
155
|
+
let numBits = 3;
|
|
156
|
+
let entry: string;
|
|
157
|
+
let w: string;
|
|
158
|
+
let c: number;
|
|
159
|
+
const result: string[] = [];
|
|
160
|
+
const data = { val: getNextValue(0), position: resetValue, index: 1 };
|
|
161
|
+
|
|
162
|
+
const readBits = (n: number): number => {
|
|
163
|
+
let bits = 0;
|
|
164
|
+
const maxpower = Math.pow(2, n);
|
|
165
|
+
let power = 1;
|
|
166
|
+
while (power !== maxpower) {
|
|
167
|
+
const resb = data.val & data.position;
|
|
168
|
+
data.position >>= 1;
|
|
169
|
+
if (data.position === 0) {
|
|
170
|
+
data.position = resetValue;
|
|
171
|
+
data.val = getNextValue(data.index++);
|
|
172
|
+
}
|
|
173
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
174
|
+
power <<= 1;
|
|
175
|
+
}
|
|
176
|
+
return bits;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
for (let i = 0; i < 3; i += 1) dictionary[i] = i;
|
|
180
|
+
|
|
181
|
+
let first: string;
|
|
182
|
+
switch (readBits(2)) {
|
|
183
|
+
case 0:
|
|
184
|
+
first = f(readBits(8));
|
|
185
|
+
break;
|
|
186
|
+
case 1:
|
|
187
|
+
first = f(readBits(16));
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
return '';
|
|
191
|
+
}
|
|
192
|
+
dictionary[3] = first;
|
|
193
|
+
w = first;
|
|
194
|
+
result.push(first);
|
|
195
|
+
while (true) {
|
|
196
|
+
if (data.index > length) return '';
|
|
197
|
+
switch ((c = readBits(numBits))) {
|
|
198
|
+
case 0:
|
|
199
|
+
dictionary[dictSize++] = f(readBits(8));
|
|
200
|
+
c = dictSize - 1;
|
|
201
|
+
enlargeIn--;
|
|
202
|
+
break;
|
|
203
|
+
case 1:
|
|
204
|
+
dictionary[dictSize++] = f(readBits(16));
|
|
205
|
+
c = dictSize - 1;
|
|
206
|
+
enlargeIn--;
|
|
207
|
+
break;
|
|
208
|
+
case 2:
|
|
209
|
+
return result.join('');
|
|
210
|
+
}
|
|
211
|
+
if (enlargeIn === 0) {
|
|
212
|
+
enlargeIn = Math.pow(2, numBits);
|
|
213
|
+
numBits++;
|
|
214
|
+
}
|
|
215
|
+
if (dictionary[c] !== undefined) {
|
|
216
|
+
entry = dictionary[c] as string;
|
|
217
|
+
} else if (c === dictSize) {
|
|
218
|
+
entry = w + w.charAt(0);
|
|
219
|
+
} else {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
result.push(entry);
|
|
223
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
224
|
+
enlargeIn--;
|
|
225
|
+
w = entry;
|
|
226
|
+
if (enlargeIn === 0) {
|
|
227
|
+
enlargeIn = Math.pow(2, numBits);
|
|
228
|
+
numBits++;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import logger from '../utils/logger.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Platform-compatible state directory for runtime artifacts (pidfile),
|
|
8
|
+
* mirroring the log-path convention in utils/logger.ts.
|
|
9
|
+
*/
|
|
10
|
+
function stateDir(): string {
|
|
11
|
+
if (process.platform === 'darwin') {
|
|
12
|
+
return path.join(homedir(), 'Library', 'Application Support', 'daigram');
|
|
13
|
+
}
|
|
14
|
+
if (process.platform === 'win32') {
|
|
15
|
+
const base = process.env.LOCALAPPDATA || path.join(homedir(), 'AppData', 'Local');
|
|
16
|
+
return path.join(base, 'Excalidraw-Canvas');
|
|
17
|
+
}
|
|
18
|
+
const xdgState = process.env.XDG_STATE_HOME || path.join(homedir(), '.local', 'state');
|
|
19
|
+
return path.join(xdgState, 'daigram');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function pidFilePath(port: number): string {
|
|
23
|
+
return path.join(stateDir(), `server-${port}.pid`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Written by the canvas server once it is actually listening, so `stop` and
|
|
27
|
+
// stale-process checks work for both auto-spawned and manually started servers.
|
|
28
|
+
export function writePidFile(port: number, pid: number): void {
|
|
29
|
+
try {
|
|
30
|
+
const file = pidFilePath(port);
|
|
31
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
32
|
+
fs.writeFileSync(file, String(pid), 'utf-8');
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger.warn('Failed to write canvas pidfile:', (error as Error).message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readPidFile(port: number): number | null {
|
|
39
|
+
try {
|
|
40
|
+
const raw = fs.readFileSync(pidFilePath(port), 'utf-8').trim();
|
|
41
|
+
const pid = parseInt(raw, 10);
|
|
42
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function removePidFile(port: number): void {
|
|
49
|
+
try {
|
|
50
|
+
fs.unlinkSync(pidFilePath(port));
|
|
51
|
+
} catch { /* already gone */ }
|
|
52
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { deflateSync, inflateSync } from 'node:zlib';
|
|
2
|
+
|
|
3
|
+
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
4
|
+
const SCENE_KEYWORD = Buffer.from('application/vnd.excalidraw+json\0', 'latin1');
|
|
5
|
+
// Match the canvas server's 10mb JSON request limit and bound inflation itself.
|
|
6
|
+
const MAX_SCENE_BYTES = 10 * 1024 * 1024;
|
|
7
|
+
// Allow worst-case JSON byte escaping, plus zlib framing/block overhead.
|
|
8
|
+
const MAX_METADATA_BYTES = MAX_SCENE_BYTES * 6 + 64 * 1024;
|
|
9
|
+
|
|
10
|
+
const CRC_TABLE = new Uint32Array(256);
|
|
11
|
+
for (let byte = 0; byte < CRC_TABLE.length; byte++) {
|
|
12
|
+
let crc = byte;
|
|
13
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
14
|
+
crc = (crc >>> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
|
|
15
|
+
}
|
|
16
|
+
CRC_TABLE[byte] = crc >>> 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface PngChunk {
|
|
20
|
+
type: string;
|
|
21
|
+
start: number;
|
|
22
|
+
end: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function crc32(data: Buffer, start: number, end: number): number {
|
|
26
|
+
let crc = 0xffffffff;
|
|
27
|
+
for (let index = start; index < end; index++) {
|
|
28
|
+
crc = CRC_TABLE[(crc ^ data[index]!) & 0xff]! ^ (crc >>> 8);
|
|
29
|
+
}
|
|
30
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isPng(data: Buffer): boolean {
|
|
34
|
+
return data.length >= PNG_SIGNATURE.length
|
|
35
|
+
&& data.compare(PNG_SIGNATURE, 0, PNG_SIGNATURE.length, 0, PNG_SIGNATURE.length) === 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseChunks(png: Buffer): PngChunk[] {
|
|
39
|
+
if (!isPng(png)) throw new Error('Invalid PNG signature');
|
|
40
|
+
|
|
41
|
+
const chunks: PngChunk[] = [];
|
|
42
|
+
let hasImageData = false;
|
|
43
|
+
let start = PNG_SIGNATURE.length;
|
|
44
|
+
while (start < png.length) {
|
|
45
|
+
if (png.length - start < 12) throw new Error('Truncated PNG chunk');
|
|
46
|
+
const length = png.readUInt32BE(start);
|
|
47
|
+
if (length > 0x7fffffff) throw new Error('Invalid PNG chunk length');
|
|
48
|
+
if (length > png.length - start - 12) throw new Error('Truncated PNG chunk data');
|
|
49
|
+
const end = start + length + 12;
|
|
50
|
+
const type = png.toString('latin1', start + 4, start + 8);
|
|
51
|
+
if (!/^[A-Za-z]{4}$/.test(type)) throw new Error('Invalid PNG chunk type');
|
|
52
|
+
if (crc32(png, start + 4, end - 4) !== png.readUInt32BE(end - 4)) {
|
|
53
|
+
throw new Error(`Invalid PNG CRC for ${type} chunk`);
|
|
54
|
+
}
|
|
55
|
+
if (chunks.length === 0 && (type !== 'IHDR' || length !== 13)) {
|
|
56
|
+
throw new Error('Invalid PNG: expected a 13-byte IHDR chunk first');
|
|
57
|
+
}
|
|
58
|
+
if (chunks.length > 0 && type === 'IHDR') throw new Error('Invalid PNG: duplicate IHDR chunk');
|
|
59
|
+
if (type === 'IDAT') hasImageData = true;
|
|
60
|
+
if (type === 'tEXt') {
|
|
61
|
+
const text = png.subarray(start + 8, end - 4);
|
|
62
|
+
const separator = text.indexOf(0);
|
|
63
|
+
if (separator < 1 || separator > 79 || text.indexOf(0, separator + 1) !== -1) {
|
|
64
|
+
throw new Error('Malformed PNG tEXt chunk');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
chunks.push({ type, start, end });
|
|
68
|
+
if (type === 'IEND') {
|
|
69
|
+
if (length !== 0) throw new Error('Invalid PNG: IEND chunk must be empty');
|
|
70
|
+
if (!hasImageData) throw new Error('Invalid PNG: missing IDAT chunk');
|
|
71
|
+
if (end !== png.length) throw new Error('Invalid PNG: data after IEND chunk');
|
|
72
|
+
return chunks;
|
|
73
|
+
}
|
|
74
|
+
start = end;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Truncated PNG: missing IEND chunk');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isSceneChunk(png: Buffer, chunk: PngChunk): boolean {
|
|
80
|
+
return chunk.type === 'tEXt'
|
|
81
|
+
&& chunk.end - chunk.start - 12 >= SCENE_KEYWORD.length
|
|
82
|
+
&& png.compare(SCENE_KEYWORD, 0, SCENE_KEYWORD.length,
|
|
83
|
+
chunk.start + 8, chunk.start + 8 + SCENE_KEYWORD.length) === 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function embedPngScene(png: Buffer, sceneJson: string): Buffer {
|
|
87
|
+
if (Buffer.byteLength(sceneJson, 'utf8') > MAX_SCENE_BYTES) {
|
|
88
|
+
throw new Error('Embedded Excalidraw scene exceeds the 10 MiB import limit');
|
|
89
|
+
}
|
|
90
|
+
const chunks = parseChunks(png);
|
|
91
|
+
// Excalidraw 0.18.1 data/encode.ts uses a zlib-wrapped UTF-8 deflate stream
|
|
92
|
+
// represented as a binary string, not base64 or raw DEFLATE.
|
|
93
|
+
const envelope = JSON.stringify({
|
|
94
|
+
version: '1',
|
|
95
|
+
encoding: 'bstring',
|
|
96
|
+
compressed: true,
|
|
97
|
+
encoded: deflateSync(sceneJson).toString('latin1')
|
|
98
|
+
});
|
|
99
|
+
const length = SCENE_KEYWORD.length + envelope.length;
|
|
100
|
+
const sceneChunk = Buffer.allocUnsafe(length + 12);
|
|
101
|
+
sceneChunk.writeUInt32BE(length, 0);
|
|
102
|
+
sceneChunk.write('tEXt', 4, 'ascii');
|
|
103
|
+
SCENE_KEYWORD.copy(sceneChunk, 8);
|
|
104
|
+
// JSON.stringify leaves high-byte binary-string characters unescaped.
|
|
105
|
+
// PNG tEXt stores Latin-1: UTF-8 here would corrupt native scene decoding.
|
|
106
|
+
sceneChunk.write(envelope, 8 + SCENE_KEYWORD.length, 'latin1');
|
|
107
|
+
sceneChunk.writeUInt32BE(crc32(sceneChunk, 4, length + 8), length + 8);
|
|
108
|
+
|
|
109
|
+
const parts: Buffer[] = [PNG_SIGNATURE];
|
|
110
|
+
let inserted = false;
|
|
111
|
+
for (const chunk of chunks) {
|
|
112
|
+
// Native getTEXtChunk reads only the first tEXt, regardless of its keyword.
|
|
113
|
+
if (!inserted && (chunk.type === 'tEXt' || chunk.type === 'IEND')) {
|
|
114
|
+
parts.push(sceneChunk);
|
|
115
|
+
inserted = true;
|
|
116
|
+
}
|
|
117
|
+
if (!isSceneChunk(png, chunk)) parts.push(png.subarray(chunk.start, chunk.end));
|
|
118
|
+
}
|
|
119
|
+
return Buffer.concat(parts);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function extractPngScene(png: Buffer): string {
|
|
123
|
+
const chunk = parseChunks(png).find(candidate => isSceneChunk(png, candidate));
|
|
124
|
+
if (!chunk) throw new Error('PNG has no embedded Excalidraw scene metadata');
|
|
125
|
+
|
|
126
|
+
const textStart = chunk.start + 8 + SCENE_KEYWORD.length;
|
|
127
|
+
if (chunk.end - 4 - textStart > MAX_METADATA_BYTES) {
|
|
128
|
+
throw new Error('Embedded Excalidraw metadata exceeds the import size limit');
|
|
129
|
+
}
|
|
130
|
+
const text = png.toString('latin1', textStart, chunk.end - 4);
|
|
131
|
+
let envelope: unknown;
|
|
132
|
+
try {
|
|
133
|
+
envelope = JSON.parse(text);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error('Malformed embedded Excalidraw metadata JSON', { cause: error });
|
|
136
|
+
}
|
|
137
|
+
if (!envelope || typeof envelope !== 'object' || Array.isArray(envelope)) {
|
|
138
|
+
throw new Error('Malformed embedded Excalidraw metadata envelope');
|
|
139
|
+
}
|
|
140
|
+
const data = envelope as Record<string, unknown>;
|
|
141
|
+
if (!('encoded' in data)) {
|
|
142
|
+
// Before the binary-string envelope, native exports stored scene JSON directly.
|
|
143
|
+
if (data.type !== 'excalidraw') throw new Error('Malformed legacy Excalidraw scene metadata');
|
|
144
|
+
if (Buffer.byteLength(text, 'utf8') > MAX_SCENE_BYTES) {
|
|
145
|
+
throw new Error('Embedded Excalidraw scene exceeds the 10 MiB import limit');
|
|
146
|
+
}
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
if (data.version !== '1' || data.encoding !== 'bstring'
|
|
150
|
+
|| typeof data.compressed !== 'boolean' || typeof data.encoded !== 'string') {
|
|
151
|
+
throw new Error('Malformed or unsupported embedded Excalidraw metadata envelope');
|
|
152
|
+
}
|
|
153
|
+
for (let index = 0; index < data.encoded.length; index++) {
|
|
154
|
+
if (data.encoded.charCodeAt(index) > 255) {
|
|
155
|
+
throw new Error('Malformed Excalidraw binary-string metadata');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!data.compressed && data.encoded.length > MAX_SCENE_BYTES) {
|
|
159
|
+
throw new Error('Embedded Excalidraw scene exceeds the 10 MiB import limit');
|
|
160
|
+
}
|
|
161
|
+
let scene: Buffer = Buffer.from(data.encoded, 'latin1');
|
|
162
|
+
if (data.compressed) {
|
|
163
|
+
try {
|
|
164
|
+
scene = inflateSync(scene, { maxOutputLength: MAX_SCENE_BYTES });
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof Error && 'code' in error && error.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
167
|
+
throw new Error('Embedded Excalidraw scene exceeds the 10 MiB import limit', { cause: error });
|
|
168
|
+
}
|
|
169
|
+
throw new Error('Invalid compressed Excalidraw scene metadata', { cause: error });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(scene);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw new Error('Invalid UTF-8 in embedded Excalidraw scene metadata', { cause: error });
|
|
176
|
+
}
|
|
177
|
+
}
|