diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/index-node.ts | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/index-node.ts')
| -rw-r--r-- | packages/excalidraw/index-node.ts | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/packages/excalidraw/index-node.ts b/packages/excalidraw/index-node.ts new file mode 100644 index 0000000..e966b1d --- /dev/null +++ b/packages/excalidraw/index-node.ts @@ -0,0 +1,83 @@ +import { exportToCanvas } from "./scene/export"; +import { getDefaultAppState } from "./appState"; + +const { registerFont, createCanvas } = require("canvas"); + +const elements = [ + { + id: "eVzaxG3YnHhqjEmD7NdYo", + type: "diamond", + x: 519, + y: 199, + width: 113, + height: 115, + strokeColor: "#000000", + backgroundColor: "transparent", + fillStyle: "hachure", + strokeWidth: 1, + roughness: 1, + opacity: 100, + seed: 749612521, + }, + { + id: "7W-iw5pEBPTU3eaCaLtFo", + type: "ellipse", + x: 552, + y: 238, + width: 49, + height: 44, + strokeColor: "#000000", + backgroundColor: "transparent", + fillStyle: "hachure", + strokeWidth: 1, + roughness: 1, + opacity: 100, + seed: 952056308, + }, + { + id: "kqKI231mvTrcsYo2DkUsR", + type: "text", + x: 557.5, + y: 317.5, + width: 43, + height: 31, + strokeColor: "#000000", + backgroundColor: "transparent", + fillStyle: "hachure", + strokeWidth: 1, + roughness: 1, + opacity: 100, + seed: 1683771448, + text: "test", + font: "20px Virgil", + baseline: 22, + }, +]; + +registerFont("./public/Virgil.woff2", { family: "Virgil" }); +registerFont("./public/Cascadia.woff2", { family: "Cascadia" }); + +const canvas = exportToCanvas( + elements as any, + { + ...getDefaultAppState(), + offsetTop: 0, + offsetLeft: 0, + width: 0, + height: 0, + }, + {}, // files + { + exportBackground: true, + viewBackgroundColor: "#ffffff", + }, + createCanvas, +); + +const fs = require("fs"); +const out = fs.createWriteStream("test.png"); +const stream = (canvas as any).createPNGStream(); +stream.pipe(out); +out.on("finish", () => { + console.info("test.png was created."); +}); |
