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,159 @@
|
|
|
1
|
+
// Run Excalidraw's exporter in Node by giving it the browser globals it
|
|
2
|
+
// expects. The exporter builds its SVG through document.createElementNS and
|
|
3
|
+
// roughjs's SVG mode, both of which jsdom provides. The remaining gaps are
|
|
4
|
+
// small and stubbed here:
|
|
5
|
+
// - FontFace / document.fonts: Excalidraw constructs FontFace objects when it
|
|
6
|
+
// reads font metrics; with skipInliningFonts nothing is ever fetched.
|
|
7
|
+
// - HTMLCanvasElement#getContext: jsdom has no 2D canvas. Excalidraw measures
|
|
8
|
+
// text to size and wrap labels; the stub answers measureText from the
|
|
9
|
+
// bundled TTFs' real advance widths (see text-metrics.ts).
|
|
10
|
+
// - matchMedia / ResizeObserver: touched at module scope by the editor code
|
|
11
|
+
// that the bundle still contains.
|
|
12
|
+
// Everything is installed once and the bundle is imported once per process.
|
|
13
|
+
|
|
14
|
+
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
15
|
+
import { measureTextWidth } from '../text-metrics.js';
|
|
16
|
+
|
|
17
|
+
export interface ExcalidrawNodeModule {
|
|
18
|
+
exportToSvg: (opts: {
|
|
19
|
+
elements: readonly any[];
|
|
20
|
+
appState?: Record<string, unknown>;
|
|
21
|
+
files: Record<string, any> | null;
|
|
22
|
+
exportPadding?: number;
|
|
23
|
+
renderEmbeddables?: boolean;
|
|
24
|
+
exportingFrame?: any | null;
|
|
25
|
+
skipInliningFonts?: true;
|
|
26
|
+
reuseImages?: boolean;
|
|
27
|
+
}) => Promise<any>;
|
|
28
|
+
restoreElements: (
|
|
29
|
+
elements: readonly any[] | null | undefined,
|
|
30
|
+
localElements: readonly any[] | null | undefined,
|
|
31
|
+
opts?: { refreshDimensions?: boolean; repairBindings?: boolean }
|
|
32
|
+
) => any[];
|
|
33
|
+
getCommonBounds: (elements: readonly any[]) => [number, number, number, number];
|
|
34
|
+
serializeAsJSON: (
|
|
35
|
+
elements: readonly any[], appState: Record<string, any>, files: Record<string, any>, type: 'local'
|
|
36
|
+
) => string;
|
|
37
|
+
elementsOverlappingBBox: (options: {
|
|
38
|
+
elements: readonly any[]; bounds: Record<string, any>; type: 'overlap';
|
|
39
|
+
}) => any[];
|
|
40
|
+
FONT_FAMILY: Record<string, number>;
|
|
41
|
+
// The canvas tab's own scene preparation (frontend/src/utils/scene.ts)
|
|
42
|
+
prepareServerScene: (elements: readonly any[]) => any[];
|
|
43
|
+
cleanElementForExcalidraw: (element: any) => any;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let modulePromise: Promise<ExcalidrawNodeModule> | null = null;
|
|
47
|
+
let domWindow: any | null = null;
|
|
48
|
+
|
|
49
|
+
function installGlobals(): any {
|
|
50
|
+
if (domWindow) return domWindow;
|
|
51
|
+
|
|
52
|
+
// Swallow jsdom's "not implemented" noise; real errors still surface as
|
|
53
|
+
// exceptions from the exporter.
|
|
54
|
+
const virtualConsole = new VirtualConsole();
|
|
55
|
+
const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>', {
|
|
56
|
+
pretendToBeVisual: true,
|
|
57
|
+
url: 'http://127.0.0.1/',
|
|
58
|
+
virtualConsole
|
|
59
|
+
});
|
|
60
|
+
const win: any = dom.window;
|
|
61
|
+
|
|
62
|
+
class FontFaceStub {
|
|
63
|
+
family: string;
|
|
64
|
+
status = 'loaded';
|
|
65
|
+
style: string;
|
|
66
|
+
weight: string;
|
|
67
|
+
unicodeRange: string;
|
|
68
|
+
display: string;
|
|
69
|
+
constructor(family: string, _source: unknown, descriptors: Record<string, string> = {}) {
|
|
70
|
+
this.family = family;
|
|
71
|
+
this.style = descriptors.style ?? 'normal';
|
|
72
|
+
this.weight = descriptors.weight ?? '400';
|
|
73
|
+
this.unicodeRange = descriptors.unicodeRange ?? 'U+0-10FFFF';
|
|
74
|
+
this.display = descriptors.display ?? 'swap';
|
|
75
|
+
}
|
|
76
|
+
load(): Promise<FontFaceStub> { return Promise.resolve(this); }
|
|
77
|
+
}
|
|
78
|
+
const fontSet = {
|
|
79
|
+
has: () => true,
|
|
80
|
+
add: () => fontSet,
|
|
81
|
+
delete: () => true,
|
|
82
|
+
check: () => true,
|
|
83
|
+
load: async () => [],
|
|
84
|
+
ready: Promise.resolve(),
|
|
85
|
+
[Symbol.iterator]: function* () { /* no faces registered */ }
|
|
86
|
+
};
|
|
87
|
+
win.FontFace = FontFaceStub;
|
|
88
|
+
Object.defineProperty(win.document, 'fonts', { value: fontSet, configurable: true });
|
|
89
|
+
|
|
90
|
+
win.HTMLCanvasElement.prototype.getContext = function getContext() {
|
|
91
|
+
let font = '10px sans-serif';
|
|
92
|
+
return {
|
|
93
|
+
get font() { return font; },
|
|
94
|
+
set font(value: string) { font = value; },
|
|
95
|
+
measureText(text: string) {
|
|
96
|
+
return { width: measureTextWidth(text, font) };
|
|
97
|
+
},
|
|
98
|
+
save() {}, restore() {}, scale() {}, translate() {}, rotate() {},
|
|
99
|
+
beginPath() {}, closePath() {}, moveTo() {}, lineTo() {}, stroke() {}, fill() {},
|
|
100
|
+
fillRect() {}, clearRect() {}, drawImage() {}, setTransform() {}, clip() {},
|
|
101
|
+
getImageData() { return { data: new Uint8ClampedArray(4) }; }
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// The shape cache builds a Path2D per freedraw element for canvas hit-testing
|
|
106
|
+
// even during SVG export; the SVG path itself comes from getFreeDrawSvgPath.
|
|
107
|
+
if (!win.Path2D) {
|
|
108
|
+
win.Path2D = class Path2D {
|
|
109
|
+
d: string;
|
|
110
|
+
constructor(d: string | Path2D = '') { this.d = typeof d === 'string' ? d : d.d; }
|
|
111
|
+
addPath() {} moveTo() {} lineTo() {} closePath() {} rect() {} arc() {}
|
|
112
|
+
bezierCurveTo() {} quadraticCurveTo() {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
win.matchMedia = () => ({
|
|
117
|
+
matches: false, media: '', onchange: null,
|
|
118
|
+
addListener() {}, removeListener() {}, addEventListener() {}, removeEventListener() {}, dispatchEvent() { return false; }
|
|
119
|
+
});
|
|
120
|
+
if (!win.ResizeObserver) {
|
|
121
|
+
win.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const g = globalThis as any;
|
|
125
|
+
const expose = [
|
|
126
|
+
'window', 'document', 'navigator', 'location', 'self', 'top', 'parent', 'frames',
|
|
127
|
+
'HTMLElement', 'HTMLCanvasElement', 'HTMLImageElement', 'Image', 'SVGElement', 'SVGSVGElement',
|
|
128
|
+
'Node', 'Element', 'Text', 'Comment', 'DOMParser', 'XMLSerializer', 'FontFace',
|
|
129
|
+
'getComputedStyle', 'requestAnimationFrame', 'cancelAnimationFrame', 'matchMedia', 'ResizeObserver',
|
|
130
|
+
'MutationObserver', 'CustomEvent', 'Event', 'localStorage', 'sessionStorage', 'devicePixelRatio', 'Path2D'
|
|
131
|
+
];
|
|
132
|
+
for (const key of expose) {
|
|
133
|
+
if (key in g) continue;
|
|
134
|
+
const value = ['window', 'self', 'top', 'parent'].includes(key) ? win : win[key];
|
|
135
|
+
if (value === undefined) continue;
|
|
136
|
+
Object.defineProperty(g, key, { value, configurable: true, writable: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
domWindow = win;
|
|
140
|
+
return win;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getDomWindow(): any {
|
|
144
|
+
return installGlobals();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function loadExcalidrawNode(): Promise<ExcalidrawNodeModule> {
|
|
148
|
+
if (!modulePromise) {
|
|
149
|
+
modulePromise = (async () => {
|
|
150
|
+
installGlobals();
|
|
151
|
+
// dist/core/render/excalidraw-node/dom.js -> dist/render/excalidraw-node.mjs
|
|
152
|
+
const bundleUrl = new URL('../../../render/excalidraw-node.mjs', import.meta.url);
|
|
153
|
+
const mod = await import(bundleUrl.href);
|
|
154
|
+
return mod as ExcalidrawNodeModule;
|
|
155
|
+
})();
|
|
156
|
+
modulePromise.catch(() => { modulePromise = null; });
|
|
157
|
+
}
|
|
158
|
+
return modulePromise;
|
|
159
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { loadExcalidrawNode, getDomWindow } from './dom.js';
|
|
2
|
+
import { fnv1a } from '../../expand-elements.js';
|
|
3
|
+
|
|
4
|
+
// Render a scene to SVG with Excalidraw's own exporter running under jsdom.
|
|
5
|
+
|
|
6
|
+
export interface ExcalidrawSvgOptions {
|
|
7
|
+
background: boolean;
|
|
8
|
+
viewBackgroundColor: string;
|
|
9
|
+
dark: boolean;
|
|
10
|
+
padding: number;
|
|
11
|
+
exportingFrame?: Record<string, any> | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const SERVER_ONLY_KEYS = ['createdAt', 'updatedAt', 'syncedAt', 'source', 'syncTimestamp'];
|
|
15
|
+
|
|
16
|
+
// Seeds drive roughjs's hand-drawn jitter. Server elements usually carry
|
|
17
|
+
// none, and Excalidraw would pick random ones — derive them from the id so
|
|
18
|
+
// an unchanged scene renders byte-identically.
|
|
19
|
+
function withDeterministicSeeds(element: Record<string, any>): Record<string, any> {
|
|
20
|
+
const seeded = { ...element };
|
|
21
|
+
for (const key of SERVER_ONLY_KEYS) delete seeded[key];
|
|
22
|
+
if (typeof seeded.seed !== 'number') seeded.seed = (fnv1a(`${seeded.id}:seed`) % 2147483646) + 1;
|
|
23
|
+
if (typeof seeded.versionNonce !== 'number') seeded.versionNonce = (fnv1a(`${seeded.id}:nonce`) % 2147483646) + 1;
|
|
24
|
+
return seeded;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Turn canvas-server elements (agent shorthand like label/start/end) or
|
|
28
|
+
// native Excalidraw elements into the scene the canvas tab would display.
|
|
29
|
+
// This is the tab's own preparation code (frontend/src/utils/scene.ts:
|
|
30
|
+
// convertToExcalidrawElements + bound-text centering + restore), bundled in,
|
|
31
|
+
// so headless renders match what the user sees.
|
|
32
|
+
export async function prepareScene(elements: Record<string, any>[]): Promise<Record<string, any>[]> {
|
|
33
|
+
const mod = await loadExcalidrawNode();
|
|
34
|
+
return mod.prepareServerScene(elements.map(withDeterministicSeeds));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function serializeSceneForPng(
|
|
38
|
+
elements: Record<string, any>[],
|
|
39
|
+
files: Record<string, any>,
|
|
40
|
+
appState: Record<string, any>,
|
|
41
|
+
exportingFrame: Record<string, any> | null,
|
|
42
|
+
sourceElements: Record<string, any>[]
|
|
43
|
+
): Promise<string> {
|
|
44
|
+
const mod = await loadExcalidrawNode();
|
|
45
|
+
// Match Excalidraw's frame export, including ungrouped overlapping elements.
|
|
46
|
+
const scoped = exportingFrame
|
|
47
|
+
? mod.elementsOverlappingBBox({ elements, bounds: exportingFrame, type: 'overlap' })
|
|
48
|
+
.filter(el => !el.frameId || el.frameId === exportingFrame.id)
|
|
49
|
+
: elements;
|
|
50
|
+
// Preparation may bump versions/timestamps and generate random label seeds.
|
|
51
|
+
// Preserve source metadata; use the same stable defaults as JSON scene export.
|
|
52
|
+
const sourceById = new Map(sourceElements.map(el => [el.id, el]));
|
|
53
|
+
const exportedIds = new Set(scoped.map(el => el.id));
|
|
54
|
+
const stable = scoped.map(el => {
|
|
55
|
+
const source = sourceById.get(el.id);
|
|
56
|
+
const timestamp = Date.parse(source?.updatedAt ?? source?.createdAt ?? '');
|
|
57
|
+
return withDeterministicSeeds({
|
|
58
|
+
...el,
|
|
59
|
+
frameId: el.frameId && !exportedIds.has(el.frameId) ? null : el.frameId,
|
|
60
|
+
seed: source?.seed,
|
|
61
|
+
versionNonce: source?.versionNonce,
|
|
62
|
+
version: source?.version ?? 1,
|
|
63
|
+
updated: typeof source?.updated === 'number' ? source.updated : Number.isNaN(timestamp) ? 1 : timestamp
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return mod.serializeAsJSON(stable, appState, files, 'local');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function renderSvgWithExcalidraw(
|
|
70
|
+
preparedElements: Record<string, any>[],
|
|
71
|
+
files: Record<string, any>,
|
|
72
|
+
options: ExcalidrawSvgOptions
|
|
73
|
+
): Promise<string> {
|
|
74
|
+
const mod = await loadExcalidrawNode();
|
|
75
|
+
const win = getDomWindow();
|
|
76
|
+
|
|
77
|
+
const svg = await mod.exportToSvg({
|
|
78
|
+
elements: preparedElements,
|
|
79
|
+
appState: {
|
|
80
|
+
exportBackground: options.background,
|
|
81
|
+
viewBackgroundColor: options.viewBackgroundColor,
|
|
82
|
+
exportWithDarkMode: options.dark,
|
|
83
|
+
exportScale: 1,
|
|
84
|
+
exportEmbedScene: false,
|
|
85
|
+
// Same frame rendering as the live tab
|
|
86
|
+
frameRendering: { enabled: true, name: true, outline: true, clip: true }
|
|
87
|
+
},
|
|
88
|
+
files,
|
|
89
|
+
exportPadding: options.padding,
|
|
90
|
+
exportingFrame: options.exportingFrame ?? null,
|
|
91
|
+
skipInliningFonts: true,
|
|
92
|
+
renderEmbeddables: false
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Excalidraw sets an explicit xmlns attribute; jsdom's serializer also emits
|
|
96
|
+
// the namespace declaration, producing a duplicate attribute that XML
|
|
97
|
+
// parsers reject. Browsers dedupe it, so drop the explicit one here.
|
|
98
|
+
svg.removeAttribute('xmlns');
|
|
99
|
+
return new win.XMLSerializer().serializeToString(svg);
|
|
100
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { normalizeFontFamily } from '../../types.js';
|
|
5
|
+
|
|
6
|
+
// Font registry for the headless renderer.
|
|
7
|
+
//
|
|
8
|
+
// Excalidraw identifies fonts by numeric family id and positions text using
|
|
9
|
+
// per-family metrics (unitsPerEm/ascender/descender/lineHeight). The values
|
|
10
|
+
// below are Excalidraw 0.18's own registry so headless text lands where the
|
|
11
|
+
// canvas puts it. Glyphs come from the TTFs in assets/fonts (built by
|
|
12
|
+
// scripts/build-fonts.mjs); families we do not bundle map onto the closest
|
|
13
|
+
// bundled face and report a warning.
|
|
14
|
+
|
|
15
|
+
export interface FontMetrics {
|
|
16
|
+
unitsPerEm: number;
|
|
17
|
+
ascender: number;
|
|
18
|
+
descender: number;
|
|
19
|
+
lineHeight: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FontEntry {
|
|
23
|
+
id: number;
|
|
24
|
+
// The name Excalidraw writes into `font-family` (and getFontFamilyString).
|
|
25
|
+
family: string;
|
|
26
|
+
// The family name inside the TTF we render with. resvg matches on this, so
|
|
27
|
+
// Excalidraw's "Cascadia" must become "Cascadia Code", "Helvetica" becomes
|
|
28
|
+
// "Liberation Sans" (Excalidraw makes the same substitution server-side).
|
|
29
|
+
renderFamily: string;
|
|
30
|
+
file: string;
|
|
31
|
+
metrics: FontMetrics;
|
|
32
|
+
// Set when the glyphs are a stand-in for a family we do not bundle.
|
|
33
|
+
substituted?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// dist/core/render/fonts.js -> <package root>/assets/fonts
|
|
37
|
+
const FONTS_DIR = fileURLToPath(new URL('../../../assets/fonts/', import.meta.url));
|
|
38
|
+
|
|
39
|
+
const EXCALIFONT = 'Excalifont-Regular.ttf';
|
|
40
|
+
const VIRGIL = 'Virgil-Regular.ttf';
|
|
41
|
+
const CASCADIA = 'CascadiaCode-Regular.ttf';
|
|
42
|
+
const LIBERATION = 'LiberationSans-Regular.ttf';
|
|
43
|
+
|
|
44
|
+
const HAND_DRAWN_METRICS: FontMetrics = { unitsPerEm: 1000, ascender: 886, descender: -374, lineHeight: 1.25 };
|
|
45
|
+
|
|
46
|
+
export const DEFAULT_FONT_FAMILY = 5; // Excalifont, Excalidraw's default
|
|
47
|
+
|
|
48
|
+
const REGISTRY: Record<number, FontEntry> = {
|
|
49
|
+
1: { id: 1, family: 'Virgil', renderFamily: 'Virgil', file: VIRGIL, metrics: HAND_DRAWN_METRICS },
|
|
50
|
+
2: { id: 2, family: 'Helvetica', renderFamily: 'Liberation Sans', file: LIBERATION,
|
|
51
|
+
metrics: { unitsPerEm: 2048, ascender: 1577, descender: -471, lineHeight: 1.15 } },
|
|
52
|
+
3: { id: 3, family: 'Cascadia', renderFamily: 'Cascadia Code', file: CASCADIA,
|
|
53
|
+
metrics: { unitsPerEm: 2048, ascender: 1900, descender: -480, lineHeight: 1.2 } },
|
|
54
|
+
5: { id: 5, family: 'Excalifont', renderFamily: 'Excalifont', file: EXCALIFONT, metrics: HAND_DRAWN_METRICS },
|
|
55
|
+
6: { id: 6, family: 'Nunito', renderFamily: 'Liberation Sans', file: LIBERATION, substituted: true,
|
|
56
|
+
metrics: { unitsPerEm: 1000, ascender: 1011, descender: -353, lineHeight: 1.35 } },
|
|
57
|
+
7: { id: 7, family: 'Lilita One', renderFamily: 'Liberation Sans', file: LIBERATION, substituted: true,
|
|
58
|
+
metrics: { unitsPerEm: 1000, ascender: 923, descender: -220, lineHeight: 1.15 } },
|
|
59
|
+
8: { id: 8, family: 'Comic Shanns', renderFamily: 'Cascadia Code', file: CASCADIA, substituted: true,
|
|
60
|
+
metrics: { unitsPerEm: 1000, ascender: 750, descender: -250, lineHeight: 1.25 } },
|
|
61
|
+
9: { id: 9, family: 'Liberation Sans', renderFamily: 'Liberation Sans', file: LIBERATION,
|
|
62
|
+
metrics: { unitsPerEm: 2048, ascender: 1854, descender: -434, lineHeight: 1.15 } }
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function getFontEntry(fontFamily: number | string | undefined): FontEntry {
|
|
66
|
+
const id = normalizeFontFamily(fontFamily) ?? DEFAULT_FONT_FAMILY;
|
|
67
|
+
return REGISTRY[id] ?? REGISTRY[DEFAULT_FONT_FAMILY]!;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Families as they appear in `font-family` attributes of exporter output
|
|
71
|
+
// (which also includes labels the exporter synthesizes, like frame names).
|
|
72
|
+
export function getFontEntryByFamilyName(family: string): FontEntry | undefined {
|
|
73
|
+
return Object.values(REGISTRY).find(entry => entry.family === family);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function collectFontEntriesFromSvg(svg: string): FontEntry[] {
|
|
77
|
+
const seen = new Map<number, FontEntry>();
|
|
78
|
+
for (const match of svg.matchAll(/font-family="([^",]+)/g)) {
|
|
79
|
+
const entry = getFontEntryByFamilyName((match[1] ?? '').trim());
|
|
80
|
+
if (entry) seen.set(entry.id, entry);
|
|
81
|
+
}
|
|
82
|
+
if (seen.size === 0) seen.set(DEFAULT_FONT_FAMILY, REGISTRY[DEFAULT_FONT_FAMILY]!);
|
|
83
|
+
return [...seen.values()];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function fontFilePath(entry: FontEntry): string {
|
|
87
|
+
return path.join(FONTS_DIR, entry.file);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Excalidraw: lineHeight is a unitless multiplier of fontSize.
|
|
91
|
+
export function getLineHeightInPx(fontSize: number, lineHeight: number): number {
|
|
92
|
+
return fontSize * lineHeight;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Distance from the top of a line box to its alphabetic baseline — the `y`
|
|
96
|
+
// Excalidraw gives each <text> line. Ported from Excalidraw's Fonts.ts.
|
|
97
|
+
export function getVerticalOffset(fontFamily: number | string | undefined, fontSize: number, lineHeightPx: number): number {
|
|
98
|
+
const { unitsPerEm, ascender, descender } = getFontEntry(fontFamily).metrics;
|
|
99
|
+
const fontSizeEm = fontSize / unitsPerEm;
|
|
100
|
+
const lineGap = (lineHeightPx - fontSizeEm * ascender + fontSizeEm * descender) / 2;
|
|
101
|
+
return fontSizeEm * ascender + lineGap;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Collect the families a scene's text uses so we only load/embed those fonts.
|
|
105
|
+
export function collectFontEntries(elements: ReadonlyArray<{ type?: string; fontFamily?: number | string }>): FontEntry[] {
|
|
106
|
+
const seen = new Map<number, FontEntry>();
|
|
107
|
+
for (const el of elements) {
|
|
108
|
+
if (el.type !== 'text') continue;
|
|
109
|
+
const entry = getFontEntry(el.fontFamily);
|
|
110
|
+
seen.set(entry.id, entry);
|
|
111
|
+
}
|
|
112
|
+
if (seen.size === 0) seen.set(DEFAULT_FONT_FAMILY, REGISTRY[DEFAULT_FONT_FAMILY]!);
|
|
113
|
+
return [...seen.values()];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Unique TTF paths for resvg's `font.fontFiles`.
|
|
117
|
+
export function fontFilesFor(entries: FontEntry[]): string[] {
|
|
118
|
+
return [...new Set(entries.map(fontFilePath))];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Rewrite Excalidraw family names to the names inside our TTFs. Applied to the
|
|
122
|
+
// whole SVG text (attribute values only), so it works for both the Excalidraw
|
|
123
|
+
// exporter's output and our own.
|
|
124
|
+
export function rewriteFontFamilies(svg: string, entries: FontEntry[]): string {
|
|
125
|
+
let out = svg;
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
if (entry.family === entry.renderFamily) continue;
|
|
128
|
+
const pattern = new RegExp(`(font-family=["'])${escapeRegExp(entry.family)}(?=[,"'])`, 'g');
|
|
129
|
+
out = out.replace(pattern, `$1${entry.renderFamily}`);
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const base64Cache = new Map<string, string>();
|
|
135
|
+
function fontBase64(file: string): string {
|
|
136
|
+
let cached = base64Cache.get(file);
|
|
137
|
+
if (!cached) {
|
|
138
|
+
cached = fs.readFileSync(file).toString('base64');
|
|
139
|
+
base64Cache.set(file, cached);
|
|
140
|
+
}
|
|
141
|
+
return cached;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// @font-face rules embedding the used TTFs so the SVG renders with the right
|
|
145
|
+
// glyphs anywhere (browsers, editors, GitHub), like the tab's export does.
|
|
146
|
+
export function fontFaceCss(entries: FontEntry[]): string {
|
|
147
|
+
const byRenderFamily = new Map<string, FontEntry>();
|
|
148
|
+
for (const entry of entries) byRenderFamily.set(entry.renderFamily, entry);
|
|
149
|
+
return [...byRenderFamily.values()]
|
|
150
|
+
.map(entry => `@font-face { font-family: "${entry.renderFamily}"; src: url(data:font/ttf;base64,${fontBase64(fontFilePath(entry))}) format("truetype"); }`)
|
|
151
|
+
.join('\n');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Bundled fonts cover Latin scripts. For CJK and other scripts resvg needs
|
|
155
|
+
// the machine's own fonts, at the cost of cross-machine determinism.
|
|
156
|
+
export function needsSystemFonts(elements: ReadonlyArray<{ type?: string; text?: string }>): boolean {
|
|
157
|
+
for (const el of elements) {
|
|
158
|
+
if (el.type !== 'text' || typeof el.text !== 'string') continue;
|
|
159
|
+
for (const ch of el.text) {
|
|
160
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
161
|
+
if (code > 0x024f && !(code >= 0x2000 && code <= 0x206f)) return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function substitutedFamilies(entries: FontEntry[]): string[] {
|
|
168
|
+
return entries.filter(e => e.substituted).map(e => `${e.family} rendered with ${e.renderFamily}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function escapeRegExp(s: string): string {
|
|
172
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
173
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { prepareScene, renderSvgWithExcalidraw, serializeSceneForPng } from './excalidraw-node/index.js';
|
|
2
|
+
import { svgToPngIsolated } from './png.js';
|
|
3
|
+
import { embedPngScene } from '../png-scene.js';
|
|
4
|
+
import {
|
|
5
|
+
collectFontEntriesFromSvg,
|
|
6
|
+
fontFaceCss,
|
|
7
|
+
fontFilesFor,
|
|
8
|
+
needsSystemFonts,
|
|
9
|
+
rewriteFontFamilies,
|
|
10
|
+
substitutedFamilies
|
|
11
|
+
} from './fonts.js';
|
|
12
|
+
|
|
13
|
+
// Headless renderer: expanded Excalidraw scene in, SVG text or PNG out. No
|
|
14
|
+
// browser involved — Excalidraw's own exporter runs under jsdom (see
|
|
15
|
+
// excalidraw-node/) and resvg rasterizes. Used by the canvas server for
|
|
16
|
+
// /api/export/image and by the offline `render` CLI command.
|
|
17
|
+
|
|
18
|
+
export type RenderFormat = 'png' | 'svg';
|
|
19
|
+
export type RendererName = 'auto' | 'node' | 'browser';
|
|
20
|
+
|
|
21
|
+
export interface RenderOptions {
|
|
22
|
+
format: RenderFormat;
|
|
23
|
+
background?: boolean; // default true
|
|
24
|
+
viewBackgroundColor?: string; // default #ffffff
|
|
25
|
+
dark?: boolean; // Excalidraw's dark-mode filter
|
|
26
|
+
scale?: number; // PNG only, 1..4 (clamped by max dimension)
|
|
27
|
+
padding?: number; // px around the scene, default 10
|
|
28
|
+
elementIds?: string[]; // render only these (plus their bound text)
|
|
29
|
+
frameId?: string; // render one frame, clipped to it
|
|
30
|
+
embedFonts?: boolean; // SVG only: inline @font-face, default true
|
|
31
|
+
embedScene?: boolean; // PNG only: include the editable scene, default false
|
|
32
|
+
systemFonts?: boolean; // PNG only: let resvg use machine fonts; default auto (non-Latin text)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RenderableScene {
|
|
36
|
+
// Canvas-server elements (agent shorthand allowed) or native Excalidraw
|
|
37
|
+
// elements; both are prepared the way the canvas tab prepares them.
|
|
38
|
+
elements: Record<string, any>[];
|
|
39
|
+
files: Record<string, any>;
|
|
40
|
+
appState?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface RenderResult {
|
|
44
|
+
format: RenderFormat;
|
|
45
|
+
data: string; // SVG text, or base64 PNG
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
warnings: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class RenderError extends Error {
|
|
52
|
+
status: 400 | 404;
|
|
53
|
+
constructor(message: string, status: 400 | 404 = 400) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.status = status;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const MAX_SCALE = 4;
|
|
60
|
+
export const DEFAULT_PADDING = 10;
|
|
61
|
+
export const DEFAULT_MAX_DIMENSION = 8192;
|
|
62
|
+
|
|
63
|
+
export function maxDimension(): number {
|
|
64
|
+
const raw = Number(process.env.EXCALIDRAW_RENDER_MAX_DIM);
|
|
65
|
+
return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_MAX_DIMENSION;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function validateRenderOptions(options: RenderOptions): Required<Omit<RenderOptions, 'elementIds' | 'frameId' | 'systemFonts'>> & Pick<RenderOptions, 'elementIds' | 'frameId' | 'systemFonts'> {
|
|
69
|
+
if (options.format !== 'png' && options.format !== 'svg') {
|
|
70
|
+
throw new RenderError('format must be "png" or "svg"');
|
|
71
|
+
}
|
|
72
|
+
if (options.embedScene && options.format !== 'png') {
|
|
73
|
+
throw new RenderError('embedScene is only supported for PNG exports');
|
|
74
|
+
}
|
|
75
|
+
const scale = options.scale ?? 1;
|
|
76
|
+
if (!Number.isFinite(scale) || scale < 1 || scale > MAX_SCALE) {
|
|
77
|
+
throw new RenderError(`scale must be a number between 1 and ${MAX_SCALE}`);
|
|
78
|
+
}
|
|
79
|
+
const padding = options.padding ?? DEFAULT_PADDING;
|
|
80
|
+
if (!Number.isFinite(padding) || padding < 0) {
|
|
81
|
+
throw new RenderError('padding must be a non-negative number');
|
|
82
|
+
}
|
|
83
|
+
if (options.elementIds && options.frameId) {
|
|
84
|
+
throw new RenderError('elementIds and frameId are mutually exclusive');
|
|
85
|
+
}
|
|
86
|
+
if (options.elementIds && (!Array.isArray(options.elementIds) || options.elementIds.length === 0)) {
|
|
87
|
+
throw new RenderError('elementIds must be a non-empty array of element ids');
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
format: options.format,
|
|
91
|
+
background: options.background ?? true,
|
|
92
|
+
viewBackgroundColor: options.viewBackgroundColor ?? '#ffffff',
|
|
93
|
+
dark: options.dark ?? false,
|
|
94
|
+
scale,
|
|
95
|
+
padding,
|
|
96
|
+
embedFonts: options.embedFonts ?? true,
|
|
97
|
+
embedScene: options.embedScene ?? false,
|
|
98
|
+
elementIds: options.elementIds,
|
|
99
|
+
frameId: options.frameId,
|
|
100
|
+
systemFonts: options.systemFonts
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Keep the requested elements plus the text bound to them, so a selected
|
|
105
|
+
// shape still shows its label. Arrows bound to selected shapes are not pulled
|
|
106
|
+
// in implicitly — the caller decides what goes in the picture.
|
|
107
|
+
export function selectElements(elements: Record<string, any>[], elementIds: string[]): Record<string, any>[] {
|
|
108
|
+
const wanted = new Set(elementIds);
|
|
109
|
+
const byId = new Map(elements.map(el => [el.id, el]));
|
|
110
|
+
const missing = elementIds.filter(id => !byId.has(id));
|
|
111
|
+
if (missing.length > 0) {
|
|
112
|
+
throw new RenderError(`Unknown element id(s): ${missing.join(', ')}`, 404);
|
|
113
|
+
}
|
|
114
|
+
return elements.filter(el =>
|
|
115
|
+
wanted.has(el.id) || (el.type === 'text' && el.containerId && wanted.has(el.containerId))
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function findFrame(elements: Record<string, any>[], frameId: string): Record<string, any> {
|
|
120
|
+
const frame = elements.find(el => el.id === frameId);
|
|
121
|
+
if (!frame) throw new RenderError(`Unknown frame id: ${frameId}`, 404);
|
|
122
|
+
if (frame.type !== 'frame' && frame.type !== 'magicframe') {
|
|
123
|
+
throw new RenderError(`Element ${frameId} is a ${frame.type}, not a frame`);
|
|
124
|
+
}
|
|
125
|
+
return frame;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function svgDimensions(svg: string): { width: number; height: number } {
|
|
129
|
+
const root = svg.match(/^<svg[^>]*>/)?.[0] ?? '';
|
|
130
|
+
const width = Number(root.match(/\swidth="([\d.]+)"/)?.[1]);
|
|
131
|
+
const height = Number(root.match(/\sheight="([\d.]+)"/)?.[1]);
|
|
132
|
+
return { width: Number.isFinite(width) ? width : 0, height: Number.isFinite(height) ? height : 0 };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function renderScene(scene: RenderableScene, rawOptions: RenderOptions): Promise<RenderResult> {
|
|
136
|
+
const options = validateRenderOptions({
|
|
137
|
+
...rawOptions,
|
|
138
|
+
viewBackgroundColor: rawOptions.viewBackgroundColor ?? scene.appState?.viewBackgroundColor
|
|
139
|
+
});
|
|
140
|
+
const warnings: string[] = [];
|
|
141
|
+
|
|
142
|
+
const live = await prepareScene(scene.elements.filter(el => el && !el.isDeleted));
|
|
143
|
+
const elements = options.elementIds ? selectElements(live, options.elementIds) : live;
|
|
144
|
+
const exportingFrame = options.frameId ? findFrame(live, options.frameId) : null;
|
|
145
|
+
|
|
146
|
+
let svg = await renderSvgWithExcalidraw(elements, scene.files ?? {}, {
|
|
147
|
+
background: options.background,
|
|
148
|
+
viewBackgroundColor: options.viewBackgroundColor,
|
|
149
|
+
dark: options.dark,
|
|
150
|
+
padding: options.padding,
|
|
151
|
+
exportingFrame
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const fontEntries = collectFontEntriesFromSvg(svg);
|
|
155
|
+
svg = rewriteFontFamilies(svg, fontEntries);
|
|
156
|
+
warnings.push(...substitutedFamilies(fontEntries));
|
|
157
|
+
|
|
158
|
+
const { width, height } = svgDimensions(svg);
|
|
159
|
+
|
|
160
|
+
if (options.format === 'svg') {
|
|
161
|
+
if (options.embedFonts) {
|
|
162
|
+
svg = svg.replace(
|
|
163
|
+
/<style class="style-fonts">[\s\S]*?<\/style>/,
|
|
164
|
+
() => `<style class="style-fonts">\n${fontFaceCss(fontEntries)}\n</style>`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return { format: 'svg', data: svg, width, height, warnings };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let scale = options.scale;
|
|
171
|
+
const largest = Math.max(width, height);
|
|
172
|
+
const limit = maxDimension();
|
|
173
|
+
if (largest > 0 && largest * scale > limit) {
|
|
174
|
+
// May go below 1 when the scene itself is larger than the limit; the cap
|
|
175
|
+
// exists to bound memory, so the image shrinks rather than failing.
|
|
176
|
+
scale = Math.max(0.1, Math.floor((limit / largest) * 1000) / 1000);
|
|
177
|
+
warnings.push(`scale reduced to ${scale} so the image stays within ${limit}px`);
|
|
178
|
+
}
|
|
179
|
+
const loadSystemFonts = options.systemFonts ?? needsSystemFonts(elements);
|
|
180
|
+
if (loadSystemFonts && options.systemFonts === undefined) {
|
|
181
|
+
warnings.push('non-Latin text detected: system fonts were used, so output may differ across machines');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const png = await svgToPngIsolated(svg, {
|
|
185
|
+
scale,
|
|
186
|
+
fontFiles: fontFilesFor(fontEntries),
|
|
187
|
+
loadSystemFonts,
|
|
188
|
+
defaultFontFamily: 'Excalifont'
|
|
189
|
+
});
|
|
190
|
+
const data = options.embedScene
|
|
191
|
+
? embedPngScene(png.data, await serializeSceneForPng(elements, scene.files ?? {}, {
|
|
192
|
+
...scene.appState,
|
|
193
|
+
viewBackgroundColor: options.viewBackgroundColor,
|
|
194
|
+
gridSize: scene.appState?.gridSize ?? null
|
|
195
|
+
}, exportingFrame, scene.elements))
|
|
196
|
+
: png.data;
|
|
197
|
+
return { format: 'png', data: data.toString('base64'), width: png.width, height: png.height, warnings };
|
|
198
|
+
}
|