refactoring van de cmap structuren bijna compleet

This commit is contained in:
2026-09-03 16:21:21 +02:00
parent 1abc84489f
commit bd1ef6bed0
75 changed files with 2547 additions and 1967 deletions
+41
View File
@@ -0,0 +1,41 @@
import { DiagramEngine } from "./cmap.js";
/**
* Present a CMap through the bundled drawing engine.
*
* CmapView owns the canvas and concrete cmap.js instance. It creates and
* destroys drawing objects but contains no concept, placement or persistence
* rules; CmapEditor remains responsible for interpreting user interaction.
*/
export class CmapView {
constructor(canvas, onSelection, onActivation, createEngine = null) {
if (!(canvas instanceof Object)) throw new TypeError("A CMap canvas is required");
if (createEngine !== null && typeof createEngine !== "function") {
throw new TypeError("A diagram-engine factory must be a function");
}
this.canvas = canvas;
this.map = createEngine ? createEngine(canvas) : new DiagramEngine(canvas);
this.map.onSelection(onSelection);
this.map.onActivation(onActivation);
}
createNode(attributes) {
return this.map.node(attributes);
}
createConnector(attributes) {
return this.map.link(attributes);
}
setZoom(factor) {
this.map.zoom(factor);
}
surfaceElement() {
return this.canvas.querySelector(":scope > .rw-cmap-surface");
}
destroy() {
if (typeof this.map.destroy === "function") this.map.destroy();
}
}