* feat: enhance Excalidraw MCP with advanced canvas toolkit features - Rename skill to `excalidraw-skill` with expanded playbook and cheatsheet. - Add new MCP tools for iterative refinement: `describe_scene` and `get_canvas_screenshot`. - Implement layout tools (`align_elements`, `distribute_elements`) and `duplicate_elements`. - Add file I/O support for `.excalidraw` JSON and image export (PNG/SVG). - Introduce named snapshots for canvas state management. - Add server-side element CRUD and WebSocket handlers for real-time sync. - Normalize `points` format for arrows and lines. * docs: update README with v2.0 features and official MCP comparison * feat: implement arrow binding and edge-to-edge routing * fix: enhance security with path sanitization and improve export error handling * feat: add viewport control, design guide, and excalidraw.com URL export * feat: enhance excalidraw.com export with proper scene formatting and labels
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
|
|
const fs = require("node:fs");
|
|
|
|
const DEFAULT_URL = process.env.EXPRESS_SERVER_URL || "http://localhost:3000";
|
|
|
|
function usage() {
|
|
console.error(
|
|
[
|
|
"Usage:",
|
|
" node scripts/create-element.cjs (--data <json> | --file <path>) [--url <canvasUrl>]",
|
|
"",
|
|
"Examples:",
|
|
' node scripts/create-element.cjs --data \'{"type":"rectangle","x":100,"y":100,"width":300,"height":200}\'',
|
|
" node scripts/create-element.cjs --file element.json",
|
|
].join("\n"),
|
|
);
|
|
process.exit(2);
|
|
}
|
|
|
|
function parseArgs(argv) {
|
|
const out = { url: DEFAULT_URL, data: null, file: null };
|
|
for (let i = 0; i < argv.length; i++) {
|
|
const a = argv[i];
|
|
if (a === "--url") out.url = argv[++i];
|
|
else if (a === "--data") out.data = argv[++i];
|
|
else if (a === "--file") out.file = argv[++i];
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function readJson({ data, file }) {
|
|
if (data) return JSON.parse(data);
|
|
if (file) return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
usage();
|
|
}
|
|
|
|
async function main() {
|
|
if (typeof fetch !== "function") {
|
|
throw new Error("This script requires Node 18+ (global fetch).");
|
|
}
|
|
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const payload = readJson(args);
|
|
|
|
const baseUrl = args.url.replace(/\/$/, "");
|
|
const res = await fetch(`${baseUrl}/api/elements`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
|
|
const json = await res.json().catch(() => null);
|
|
if (!res.ok || !json || json.success !== true) {
|
|
throw new Error(
|
|
`Failed to create element: ${res.status} ${res.statusText} ${json?.error ? `- ${json.error}` : ""}`,
|
|
);
|
|
}
|
|
|
|
process.stdout.write(JSON.stringify(json.element, null, 2) + "\n");
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err?.stack || String(err));
|
|
process.exit(1);
|
|
});
|
|
|