@affino/diagram-vue 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/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @affino/diagram-vue
2
+
3
+ Vue adapter for `@affino/diagram-core`. The package owns Vue refs, lifecycle cleanup, DOM pointer bridging, viewport resize bridging, and render projections. Diagram rules stay in core.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @affino/diagram-core @affino/diagram-vue vue
9
+ ```
10
+
11
+ ## Basic setup
12
+
13
+ ```ts
14
+ import { useDiagramEngine, useDiagramSelection, useDiagramVisibleEntities } from "@affino/diagram-vue"
15
+
16
+ const diagram = useDiagramEngine({
17
+ nodes: [{ id: "bay-a", kind: "node", x: 0, y: 0, width: 160, height: 80 }],
18
+ ports: [{ id: "bay-a-out", kind: "port", nodeId: "bay-a", x: 160, y: 40 }],
19
+ viewport: { x: 0, y: 0, width: 900, height: 600, zoom: 1 },
20
+ })
21
+ const selection = useDiagramSelection(diagram)
22
+ const visible = useDiagramVisibleEntities(diagram)
23
+
24
+ selection.setSelection(["bay-a"], "bay-a")
25
+ ```
26
+
27
+ ## SVG-first rendering
28
+
29
+ Render static diagram text as SVG `<text>`/`<tspan>` elements in world space. Use DOM only for the single active text editor overlay and floating UI such as context menus, toolbars, popovers, and form-like controls. The adapter returns render lists from `engine.queryVisible()`, so Vue code does not scan the whole scene on pan.
30
+
31
+ ```vue
32
+ <script setup lang="ts">
33
+ import { getSvgEntityProps, useDiagramEngine, useDiagramPointerController, useDiagramTextEditor, useDiagramVisibleEntities } from "@affino/diagram-vue"
34
+
35
+ const diagram = useDiagramEngine(initialScene)
36
+ const visible = useDiagramVisibleEntities(diagram, { overscan: 200 })
37
+ const pointer = useDiagramPointerController(diagram)
38
+ const textEditor = useDiagramTextEditor(diagram)
39
+ </script>
40
+
41
+ <template>
42
+ <div class="diagram-stage">
43
+ <svg class="diagram-svg" v-bind="pointer.getSvgPointerProps()">
44
+ <polyline v-for="edge in visible.projection.value.edges" :key="edge.id" v-bind="getSvgEntityProps(edge)" />
45
+ <rect v-for="node in visible.projection.value.nodes" :key="node.id" v-bind="getSvgEntityProps(node)" />
46
+ <circle v-for="port in visible.projection.value.ports" :key="port.id" v-bind="getSvgEntityProps(port)" />
47
+ <text v-for="text in visible.projection.value.texts" :key="text.id" v-bind="getSvgEntityProps(text)">
48
+ {{ diagram.scene.value.entities.textsById.get(text.id)?.text }}
49
+ </text>
50
+ </svg>
51
+ <textarea v-if="textEditor.activeEditor.value" :style="textEditor.activeEditor.value.style" :value="textEditor.activeEditor.value.text" />
52
+ </div>
53
+ </template>
54
+ ```
55
+
56
+ ## Viewport resize
57
+
58
+ `useDiagramViewport()` can attach a viewport element and write width/height changes into core through `setViewport` commands.
59
+
60
+ ```ts
61
+ import { shallowRef } from "vue"
62
+ import { useDiagramEngine, useDiagramViewport } from "@affino/diagram-vue"
63
+
64
+ const stage = shallowRef<HTMLElement | null>(null)
65
+ const diagram = useDiagramEngine(initialScene)
66
+ const viewport = useDiagramViewport(diagram, { element: stage })
67
+
68
+ viewport.setViewport({ x: 120, y: 40, zoom: 1.25 })
69
+ ```
70
+
71
+ ## Projection contract
72
+
73
+ `useDiagramVisibleEntities()` exposes:
74
+
75
+ - `nodes`, `edges`, `ports`, `shapes`, and `texts` for SVG rendering;
76
+ - `activeHandles` for selected resize/port handles;
77
+ - `overlayAnchors` for context menus and toolbars.
78
+
79
+ Selected entities are included even when outside the viewport, which keeps handles and overlays stable during keyboard or programmatic selection changes. `useDiagramTextEditor()` owns one shared DOM editor overlay for the active text entity; it reads bounds from core, positions through the viewport transform, and commits through the `editText` command.
80
+
81
+ ## What belongs in core
82
+
83
+ Do not put domain rules, snapping decisions, hit testing, undo/redo, or geometry math in Vue components. Route those through `@affino/diagram-core` commands and queries, then render the projection here.
@@ -0,0 +1,16 @@
1
+ export { useDiagramEngine } from "./useDiagramEngine.js";
2
+ export { useDiagramViewport } from "./useDiagramViewport.js";
3
+ export { useDiagramSelection } from "./useDiagramSelection.js";
4
+ export { useDiagramVisibleEntities } from "./useDiagramVisibleEntities.js";
5
+ export { useDiagramPointerController } from "./useDiagramPointerController.js";
6
+ export { useDiagramTextEditor } from "./useDiagramTextEditor.js";
7
+ export { getDomEntityStyle, getSvgEntityProps } from "./useDiagramRenderer.js";
8
+ export type * from "./types.js";
9
+ export type * from "./useDiagramEngine.js";
10
+ export type * from "./useDiagramViewport.js";
11
+ export type * from "./useDiagramSelection.js";
12
+ export type * from "./useDiagramVisibleEntities.js";
13
+ export type * from "./useDiagramPointerController.js";
14
+ export type * from "./useDiagramTextEditor.js";
15
+ export type * from "./useDiagramRenderer.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,yBAAyB,CAAA;AAC5C,mBAAmB,0BAA0B,CAAA;AAC7C,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,yBAAyB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { useDiagramEngine } from "./useDiagramEngine.js";
2
+ export { useDiagramViewport } from "./useDiagramViewport.js";
3
+ export { useDiagramSelection } from "./useDiagramSelection.js";
4
+ export { useDiagramVisibleEntities } from "./useDiagramVisibleEntities.js";
5
+ export { useDiagramPointerController } from "./useDiagramPointerController.js";
6
+ export { useDiagramTextEditor } from "./useDiagramTextEditor.js";
7
+ export { getDomEntityStyle, getSvgEntityProps } from "./useDiagramRenderer.js";
@@ -0,0 +1,31 @@
1
+ import type { DiagramEntityKind, DiagramGeometry, DiagramId, DiagramPoint, DiagramRect } from "@affino/diagram-core";
2
+ export type DiagramRenderLayer = "svg" | "dom";
3
+ export type DiagramRenderEntity = Readonly<{
4
+ id: DiagramId;
5
+ kind: DiagramEntityKind;
6
+ layer: DiagramRenderLayer;
7
+ geometry: DiagramGeometry;
8
+ selected: boolean;
9
+ }>;
10
+ export type DiagramHandle = Readonly<{
11
+ id: string;
12
+ ownerId: DiagramId;
13
+ kind: "resize" | "port" | "edge-endpoint";
14
+ point: DiagramPoint;
15
+ }>;
16
+ export type DiagramOverlayAnchor = Readonly<{
17
+ id: DiagramId;
18
+ kind: DiagramEntityKind;
19
+ rect: DiagramRect;
20
+ }>;
21
+ export type DiagramVisibleProjection = Readonly<{
22
+ ids: ReadonlyArray<DiagramId>;
23
+ nodes: ReadonlyArray<DiagramRenderEntity>;
24
+ edges: ReadonlyArray<DiagramRenderEntity>;
25
+ texts: ReadonlyArray<DiagramRenderEntity>;
26
+ shapes: ReadonlyArray<DiagramRenderEntity>;
27
+ ports: ReadonlyArray<DiagramRenderEntity>;
28
+ activeHandles: ReadonlyArray<DiagramHandle>;
29
+ overlayAnchors: ReadonlyArray<DiagramOverlayAnchor>;
30
+ }>;
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEpH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,KAAK,CAAA;AAE9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,KAAK,EAAE,kBAAkB,CAAA;IACzB,QAAQ,EAAE,eAAe,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAC,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,SAAS,CAAA;IAClB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,eAAe,CAAA;IACzC,KAAK,EAAE,YAAY,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;CAClB,CAAC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IAC1C,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,aAAa,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IAC3C,cAAc,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAA;CACpD,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { ShallowRef } from "vue";
2
+ import { type DiagramChange, type DiagramCommand, type DiagramCommandResult, type DiagramEngine, type DiagramScene, type DiagramSceneInput } from "@affino/diagram-core";
3
+ export type DiagramEngineController = Readonly<{
4
+ engine: DiagramEngine;
5
+ scene: ShallowRef<DiagramScene>;
6
+ change: ShallowRef<DiagramChange>;
7
+ dispatch: (command: DiagramCommand) => DiagramCommandResult;
8
+ dispose: () => void;
9
+ }>;
10
+ export type DiagramEngineOptions = Readonly<{
11
+ engine?: DiagramEngine;
12
+ initialScene?: DiagramSceneInput;
13
+ }>;
14
+ export declare function useDiagramEngine(options?: DiagramEngineOptions | DiagramSceneInput): DiagramEngineController;
15
+ //# sourceMappingURL=useDiagramEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramEngine.d.ts","sourceRoot":"","sources":["../src/useDiagramEngine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7L,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;IAC/B,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IACjC,QAAQ,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,oBAAoB,CAAA;IAC3D,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,YAAY,CAAC,EAAE,iBAAiB,CAAA;CACjC,CAAC,CAAA;AAEF,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,oBAAoB,GAAG,iBAAsB,GAAG,uBAAuB,CA2BhH"}
@@ -0,0 +1,34 @@
1
+ import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
2
+ import { createDiagramEngine } from "@affino/diagram-core";
3
+ export function useDiagramEngine(options = {}) {
4
+ var _a, _b;
5
+ const normalized = isEngineOptions(options) ? options : { initialScene: options };
6
+ const engine = (_a = normalized.engine) !== null && _a !== void 0 ? _a : createDiagramEngine((_b = normalized.initialScene) !== null && _b !== void 0 ? _b : {});
7
+ const scene = shallowRef(engine.getScene());
8
+ const change = shallowRef(engine.getLastChange());
9
+ const subscription = engine.subscribe((nextScene, nextChange) => {
10
+ scene.value = nextScene;
11
+ change.value = nextChange;
12
+ });
13
+ let disposed = false;
14
+ const dispose = () => {
15
+ if (disposed) {
16
+ return;
17
+ }
18
+ disposed = true;
19
+ subscription.unsubscribe();
20
+ };
21
+ if (getCurrentScope()) {
22
+ onScopeDispose(dispose);
23
+ }
24
+ return {
25
+ engine,
26
+ scene,
27
+ change,
28
+ dispatch: (command) => engine.dispatch(command),
29
+ dispose,
30
+ };
31
+ }
32
+ function isEngineOptions(value) {
33
+ return "engine" in value || "initialScene" in value;
34
+ }
@@ -0,0 +1,22 @@
1
+ import type { ShallowRef } from "vue";
2
+ import { type DiagramInteractionController, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint } from "@affino/diagram-core";
3
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
4
+ export type DiagramPointerController = Readonly<{
5
+ interaction: DiagramInteractionController;
6
+ state: ShallowRef<DiagramInteractionSnapshot>;
7
+ setTool: (tool: DiagramInteractionTool) => void;
8
+ getSvgPointerProps: () => {
9
+ onPointerdown: (event: PointerEvent) => void;
10
+ onPointermove: (event: PointerEvent) => void;
11
+ onPointerup: (event: PointerEvent) => void;
12
+ onPointercancel: () => void;
13
+ };
14
+ dispose: () => void;
15
+ }>;
16
+ export type DiagramPointerControllerOptions = Readonly<{
17
+ toWorldPoint?: (event: PointerEvent) => DiagramPoint;
18
+ setPointerCapture?: (event: PointerEvent) => void;
19
+ releasePointerCapture?: (event: PointerEvent) => void;
20
+ }>;
21
+ export declare function useDiagramPointerController(controller: DiagramEngineController, options?: DiagramPointerControllerOptions): DiagramPointerController;
22
+ //# sourceMappingURL=useDiagramPointerController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramPointerController.d.ts","sourceRoot":"","sources":["../src/useDiagramPointerController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAsC,KAAK,4BAA4B,EAAE,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC7L,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,WAAW,EAAE,4BAA4B,CAAA;IACzC,KAAK,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAA;IAC7C,OAAO,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAA;IAC/C,kBAAkB,EAAE,MAAM;QACxB,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,WAAW,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC1C,eAAe,EAAE,MAAM,IAAI,CAAA;KAC5B,CAAA;IACD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC;IACrD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,CAAA;IACpD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACjD,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CACtD,CAAC,CAAA;AAEF,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CAwDxJ"}
@@ -0,0 +1,67 @@
1
+ import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
2
+ import { createDiagramInteractionController } from "@affino/diagram-core";
3
+ export function useDiagramPointerController(controller, options = {}) {
4
+ let refresh = () => { };
5
+ const interaction = createDiagramInteractionController(controller.engine, {
6
+ scheduleFrame: (callback) => {
7
+ requestAnimationFrame(() => {
8
+ callback();
9
+ refresh();
10
+ });
11
+ },
12
+ });
13
+ const state = shallowRef(interaction.getSnapshot());
14
+ let disposed = false;
15
+ refresh = () => {
16
+ state.value = interaction.getSnapshot();
17
+ };
18
+ const toEvent = (event) => ({ id: event.pointerId, point: toWorldPoint(event, options.toWorldPoint), shiftKey: event.shiftKey });
19
+ const api = {
20
+ interaction,
21
+ state,
22
+ setTool: (tool) => {
23
+ interaction.setTool(tool);
24
+ refresh();
25
+ },
26
+ getSvgPointerProps: () => ({
27
+ onPointerdown: (event) => {
28
+ var _a;
29
+ (_a = options.setPointerCapture) === null || _a === void 0 ? void 0 : _a.call(options, event);
30
+ interaction.pointerDown(toEvent(event));
31
+ refresh();
32
+ },
33
+ onPointermove: (event) => {
34
+ interaction.pointerMove(toEvent(event));
35
+ refresh();
36
+ },
37
+ onPointerup: (event) => {
38
+ var _a;
39
+ interaction.pointerUp(toEvent(event));
40
+ (_a = options.releasePointerCapture) === null || _a === void 0 ? void 0 : _a.call(options, event);
41
+ refresh();
42
+ },
43
+ onPointercancel: () => {
44
+ interaction.cancel();
45
+ refresh();
46
+ },
47
+ }),
48
+ dispose: () => {
49
+ if (disposed) {
50
+ return;
51
+ }
52
+ disposed = true;
53
+ interaction.cancel();
54
+ refresh();
55
+ },
56
+ };
57
+ if (getCurrentScope()) {
58
+ onScopeDispose(api.dispose);
59
+ }
60
+ return api;
61
+ }
62
+ function toWorldPoint(event, mapper) {
63
+ if (mapper) {
64
+ return mapper(event);
65
+ }
66
+ return { x: event.clientX, y: event.clientY };
67
+ }
@@ -0,0 +1,5 @@
1
+ import type { DiagramRenderEntity } from "./types.js";
2
+ export type SvgEntityProps = Readonly<Record<string, string | number | boolean | undefined>>;
3
+ export declare function getSvgEntityProps(entity: DiagramRenderEntity): SvgEntityProps;
4
+ export declare function getDomEntityStyle(entity: DiagramRenderEntity): Readonly<Record<string, string>>;
5
+ //# sourceMappingURL=useDiagramRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramRenderer.d.ts","sourceRoot":"","sources":["../src/useDiagramRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,CAAA;AAE5F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CAuC7E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQ/F"}
@@ -0,0 +1,50 @@
1
+ export function getSvgEntityProps(entity) {
2
+ var _a, _b, _c;
3
+ const { geometry } = entity;
4
+ const common = {
5
+ "data-diagram-id": entity.id,
6
+ "data-diagram-kind": entity.kind,
7
+ "data-selected": entity.selected || undefined,
8
+ };
9
+ if (entity.kind === "edge") {
10
+ return {
11
+ ...common,
12
+ points: (_b = (_a = geometry.path) === null || _a === void 0 ? void 0 : _a.map((point) => `${point.x},${point.y}`).join(" ")) !== null && _b !== void 0 ? _b : "",
13
+ };
14
+ }
15
+ if (entity.kind === "port") {
16
+ const point = (_c = geometry.point) !== null && _c !== void 0 ? _c : { x: geometry.bounds.x, y: geometry.bounds.y };
17
+ return {
18
+ ...common,
19
+ cx: point.x,
20
+ cy: point.y,
21
+ r: geometry.bounds.width / 2,
22
+ };
23
+ }
24
+ if (entity.kind === "shape" || entity.kind === "node") {
25
+ return {
26
+ ...common,
27
+ x: geometry.bounds.x,
28
+ y: geometry.bounds.y,
29
+ width: geometry.bounds.width,
30
+ height: geometry.bounds.height,
31
+ };
32
+ }
33
+ if (entity.kind === "text") {
34
+ return {
35
+ ...common,
36
+ x: geometry.bounds.x,
37
+ y: geometry.bounds.y,
38
+ };
39
+ }
40
+ return common;
41
+ }
42
+ export function getDomEntityStyle(entity) {
43
+ const bounds = entity.geometry.bounds;
44
+ return Object.freeze({
45
+ position: "absolute",
46
+ transform: `translate(${bounds.x}px, ${bounds.y}px)`,
47
+ width: `${bounds.width}px`,
48
+ height: `${bounds.height}px`,
49
+ });
50
+ }
@@ -0,0 +1,12 @@
1
+ import type { ComputedRef } from "vue";
2
+ import type { DiagramId, DiagramSelection } from "@affino/diagram-core";
3
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
4
+ export type DiagramSelectionController = Readonly<{
5
+ selection: ComputedRef<DiagramSelection>;
6
+ selectedIds: ComputedRef<ReadonlySet<DiagramId>>;
7
+ setSelection: (ids: ReadonlyArray<DiagramId>, primaryId?: DiagramId | null) => void;
8
+ clearSelection: () => void;
9
+ isSelected: (id: DiagramId) => boolean;
10
+ }>;
11
+ export declare function useDiagramSelection(controller: DiagramEngineController): DiagramSelectionController;
12
+ //# sourceMappingURL=useDiagramSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramSelection.d.ts","sourceRoot":"","sources":["../src/useDiagramSelection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IACxC,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAA;IAChD,YAAY,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAA;IACnF,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAA;CACvC,CAAC,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,uBAAuB,GAAG,0BAA0B,CAUnG"}
@@ -0,0 +1,12 @@
1
+ import { computed } from "vue";
2
+ export function useDiagramSelection(controller) {
3
+ const selection = computed(() => controller.scene.value.selection);
4
+ const selectedIds = computed(() => new Set(selection.value.ids));
5
+ return {
6
+ selection,
7
+ selectedIds,
8
+ setSelection: (ids, primaryId) => { var _a; if (primaryId === void 0) { primaryId = (_a = ids[0]) !== null && _a !== void 0 ? _a : null; } return controller.dispatch({ type: "setSelection", selection: { ids, primaryId } }); },
9
+ clearSelection: () => controller.dispatch({ type: "setSelection", selection: { ids: [], primaryId: null } }),
10
+ isSelected: (id) => selectedIds.value.has(id),
11
+ };
12
+ }
@@ -0,0 +1,24 @@
1
+ import type { ShallowRef } from "vue";
2
+ import { type DiagramId, type DiagramRect, type DiagramViewport } from "@affino/diagram-core";
3
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
4
+ export type DiagramTextEditorOverlay = Readonly<{
5
+ id: DiagramId;
6
+ text: string;
7
+ bounds: DiagramRect;
8
+ style: Readonly<Record<string, string>>;
9
+ }>;
10
+ export type DiagramTextEditorController = Readonly<{
11
+ activeEditor: ShallowRef<DiagramTextEditorOverlay | null>;
12
+ beginTextEdit: (id: DiagramId) => boolean;
13
+ updateText: (text: string) => void;
14
+ commitTextEdit: (text?: string) => boolean;
15
+ cancelTextEdit: () => void;
16
+ dispose: () => void;
17
+ }>;
18
+ export type DiagramTextEditorOptions = Readonly<{
19
+ viewport?: Readonly<{
20
+ value: DiagramViewport;
21
+ }>;
22
+ }>;
23
+ export declare function useDiagramTextEditor(controller: DiagramEngineController, options?: DiagramTextEditorOptions): DiagramTextEditorController;
24
+ //# sourceMappingURL=useDiagramTextEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramTextEditor.d.ts","sourceRoot":"","sources":["../src/useDiagramTextEditor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAwB,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACnH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACxC,CAAC,CAAA;AAEF,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,YAAY,EAAE,UAAU,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAA;IACzD,aAAa,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAA;IACzC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;IAC1C,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE,CAAC,CAAA;CAChD,CAAC,CAAA;AAEF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,wBAA6B,GAAG,2BAA2B,CA8E7I"}
@@ -0,0 +1,82 @@
1
+ import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
2
+ import { createEntityGeometry } from "@affino/diagram-core";
3
+ export function useDiagramTextEditor(controller, options = {}) {
4
+ const activeEditor = shallowRef(null);
5
+ let disposed = false;
6
+ const buildOverlay = (id, textOverride) => {
7
+ var _a, _b;
8
+ const scene = controller.scene.value;
9
+ const entity = scene.entities.textsById.get(id);
10
+ if (!entity) {
11
+ return null;
12
+ }
13
+ const geometry = createEntityGeometry(id, scene.entities);
14
+ if (!geometry) {
15
+ return null;
16
+ }
17
+ return Object.freeze({
18
+ id,
19
+ text: textOverride !== null && textOverride !== void 0 ? textOverride : entity.text,
20
+ bounds: geometry.bounds,
21
+ style: Object.freeze(editorStyle(geometry.bounds, (_b = (_a = options.viewport) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : scene.viewport)),
22
+ });
23
+ };
24
+ const refreshActive = () => {
25
+ const current = activeEditor.value;
26
+ if (!current) {
27
+ return;
28
+ }
29
+ activeEditor.value = buildOverlay(current.id, current.text);
30
+ };
31
+ const subscription = controller.engine.subscribe(() => refreshActive());
32
+ const beginTextEdit = (id) => {
33
+ const overlay = buildOverlay(id);
34
+ if (!overlay) {
35
+ return false;
36
+ }
37
+ activeEditor.value = overlay;
38
+ return true;
39
+ };
40
+ const updateText = (text) => {
41
+ const current = activeEditor.value;
42
+ if (!current) {
43
+ return;
44
+ }
45
+ activeEditor.value = buildOverlay(current.id, text);
46
+ };
47
+ const commitTextEdit = (text) => {
48
+ const current = activeEditor.value;
49
+ if (!current) {
50
+ return false;
51
+ }
52
+ const nextText = text !== null && text !== void 0 ? text : current.text;
53
+ const result = controller.dispatch({ type: "editText", id: current.id, text: nextText });
54
+ activeEditor.value = null;
55
+ return result.changed;
56
+ };
57
+ const cancelTextEdit = () => {
58
+ activeEditor.value = null;
59
+ };
60
+ const dispose = () => {
61
+ if (disposed) {
62
+ return;
63
+ }
64
+ disposed = true;
65
+ activeEditor.value = null;
66
+ subscription.unsubscribe();
67
+ };
68
+ if (getCurrentScope()) {
69
+ onScopeDispose(dispose);
70
+ }
71
+ return { activeEditor, beginTextEdit, updateText, commitTextEdit, cancelTextEdit, dispose };
72
+ }
73
+ function editorStyle(bounds, viewport) {
74
+ const zoom = viewport.zoom || 1;
75
+ return {
76
+ position: "absolute",
77
+ left: `${(bounds.x - viewport.x) * zoom}px`,
78
+ top: `${(bounds.y - viewport.y) * zoom}px`,
79
+ width: `${bounds.width * zoom}px`,
80
+ height: `${bounds.height * zoom}px`,
81
+ };
82
+ }
@@ -0,0 +1,26 @@
1
+ import type { Ref, ShallowRef } from "vue";
2
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
3
+ import type { DiagramViewport } from "@affino/diagram-core";
4
+ export type DiagramViewportController = Readonly<{
5
+ viewport: ShallowRef<DiagramViewport>;
6
+ setViewport: (viewport: Partial<DiagramViewport>) => void;
7
+ attachViewportElement: (element: Element | null) => void;
8
+ dispose: () => void;
9
+ }>;
10
+ type ResizeObserverLike = {
11
+ observe: (element: Element) => void;
12
+ disconnect: () => void;
13
+ };
14
+ type ResizeObserverCtor = new (callback: (entries: ReadonlyArray<{
15
+ contentRect: {
16
+ width: number;
17
+ height: number;
18
+ };
19
+ }>) => void) => ResizeObserverLike;
20
+ export type DiagramViewportOptions = Readonly<{
21
+ element?: Ref<Element | null> | Element | null;
22
+ resizeObserver?: ResizeObserverCtor;
23
+ }>;
24
+ export declare function useDiagramViewport(controller: DiagramEngineController, options?: DiagramViewportOptions): DiagramViewportController;
25
+ export {};
26
+ //# sourceMappingURL=useDiagramViewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramViewport.d.ts","sourceRoot":"","sources":["../src/useDiagramViewport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,QAAQ,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACzD,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACxD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACnC,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AAED,KAAK,kBAAkB,GAAG,KAAK,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;IAAE,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,KAAK,IAAI,KAAK,kBAAkB,CAAA;AAEpJ,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAA;IAC9C,cAAc,CAAC,EAAE,kBAAkB,CAAA;CACpC,CAAC,CAAA;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,sBAA2B,GAAG,yBAAyB,CA+DvI"}
@@ -0,0 +1,71 @@
1
+ import { getCurrentScope, isRef, onScopeDispose, shallowRef, watch } from "vue";
2
+ export function useDiagramViewport(controller, options = {}) {
3
+ const viewport = shallowRef(controller.scene.value.viewport);
4
+ let observer = null;
5
+ let attachedElement = null;
6
+ let disposed = false;
7
+ let stopElementWatch = null;
8
+ const subscription = controller.engine.subscribe((scene) => {
9
+ viewport.value = scene.viewport;
10
+ });
11
+ const setViewport = (next) => {
12
+ controller.dispatch({ type: "setViewport", viewport: next });
13
+ };
14
+ const attachViewportElement = (element) => {
15
+ var _a;
16
+ if (observer) {
17
+ observer.disconnect();
18
+ observer = null;
19
+ }
20
+ attachedElement = element;
21
+ if (!element || disposed) {
22
+ return;
23
+ }
24
+ const ResizeObserverImpl = ((_a = options.resizeObserver) !== null && _a !== void 0 ? _a : globalThis.ResizeObserver);
25
+ if (!ResizeObserverImpl) {
26
+ return;
27
+ }
28
+ observer = new ResizeObserverImpl((entries) => {
29
+ var _a;
30
+ const rect = (_a = entries[0]) === null || _a === void 0 ? void 0 : _a.contentRect;
31
+ if (rect) {
32
+ setViewport({ width: rect.width, height: rect.height });
33
+ }
34
+ });
35
+ observer.observe(element);
36
+ };
37
+ const dispose = () => {
38
+ if (disposed) {
39
+ return;
40
+ }
41
+ disposed = true;
42
+ subscription.unsubscribe();
43
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
44
+ observer = null;
45
+ stopElementWatch === null || stopElementWatch === void 0 ? void 0 : stopElementWatch();
46
+ stopElementWatch = null;
47
+ attachedElement = null;
48
+ };
49
+ if (getCurrentScope()) {
50
+ onScopeDispose(dispose);
51
+ }
52
+ if (isRef(options.element)) {
53
+ stopElementWatch = watch(options.element, attachViewportElement, { immediate: true });
54
+ }
55
+ else {
56
+ const initialElement = unwrapElement(options.element);
57
+ if (initialElement) {
58
+ attachViewportElement(initialElement);
59
+ }
60
+ }
61
+ return { viewport, setViewport, attachViewportElement, dispose };
62
+ }
63
+ function unwrapElement(value) {
64
+ if (!value) {
65
+ return null;
66
+ }
67
+ if ("value" in value) {
68
+ return value.value;
69
+ }
70
+ return value;
71
+ }
@@ -0,0 +1,15 @@
1
+ import type { ShallowRef } from "vue";
2
+ import { type DiagramRect } from "@affino/diagram-core";
3
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
4
+ import type { DiagramVisibleProjection } from "./types.js";
5
+ export type DiagramVisibleEntitiesOptions = Readonly<{
6
+ overscan?: number;
7
+ includeSelection?: boolean;
8
+ }>;
9
+ export type DiagramVisibleEntitiesController = Readonly<{
10
+ projection: ShallowRef<DiagramVisibleProjection>;
11
+ refreshVisible: (bounds?: DiagramRect) => void;
12
+ dispose: () => void;
13
+ }>;
14
+ export declare function useDiagramVisibleEntities(controller: DiagramEngineController, options?: DiagramVisibleEntitiesOptions): DiagramVisibleEntitiesController;
15
+ //# sourceMappingURL=useDiagramVisibleEntities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiagramVisibleEntities.d.ts","sourceRoot":"","sources":["../src/useDiagramVisibleEntities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAA8D,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAA4D,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAEpH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,gCAAgC,GAAG,QAAQ,CAAC;IACtD,UAAU,EAAE,UAAU,CAAC,wBAAwB,CAAC,CAAA;IAChD,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAaF,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,6BAAkC,GAAG,gCAAgC,CAoB5J"}
@@ -0,0 +1,123 @@
1
+ import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
2
+ import { createEntityGeometry } from "@affino/diagram-core";
3
+ const EMPTY_PROJECTION = Object.freeze({
4
+ ids: Object.freeze([]),
5
+ nodes: Object.freeze([]),
6
+ edges: Object.freeze([]),
7
+ texts: Object.freeze([]),
8
+ shapes: Object.freeze([]),
9
+ ports: Object.freeze([]),
10
+ activeHandles: Object.freeze([]),
11
+ overlayAnchors: Object.freeze([]),
12
+ });
13
+ export function useDiagramVisibleEntities(controller, options = {}) {
14
+ const projection = shallowRef(EMPTY_PROJECTION);
15
+ const refreshVisible = (bounds) => {
16
+ var _a, _b;
17
+ const viewportBounds = bounds !== null && bounds !== void 0 ? bounds : controller.scene.value.viewport;
18
+ projection.value = buildProjection(controller, inflate(viewportBounds, (_a = options.overscan) !== null && _a !== void 0 ? _a : 0), (_b = options.includeSelection) !== null && _b !== void 0 ? _b : true);
19
+ };
20
+ const subscription = controller.engine.subscribe(() => refreshVisible());
21
+ let disposed = false;
22
+ const dispose = () => {
23
+ if (disposed) {
24
+ return;
25
+ }
26
+ disposed = true;
27
+ subscription.unsubscribe();
28
+ };
29
+ refreshVisible();
30
+ if (getCurrentScope()) {
31
+ onScopeDispose(dispose);
32
+ }
33
+ return { projection, refreshVisible, dispose };
34
+ }
35
+ function buildProjection(controller, bounds, includeSelection) {
36
+ const scene = controller.scene.value;
37
+ const ids = new Set(controller.engine.queryVisible(bounds));
38
+ if (includeSelection) {
39
+ for (const id of scene.selection.ids) {
40
+ ids.add(id);
41
+ }
42
+ }
43
+ const selected = new Set(scene.selection.ids);
44
+ const entities = [];
45
+ for (const id of ids) {
46
+ const geometry = createEntityGeometry(id, scene.entities);
47
+ if (!geometry) {
48
+ continue;
49
+ }
50
+ entities.push(Object.freeze({ id, kind: geometry.kind, layer: "svg", geometry, selected: selected.has(id) }));
51
+ }
52
+ const activeGeometries = entities.filter((entity) => entity.selected).map((entity) => entity.geometry);
53
+ const anchorGeometries = activeGeometries.filter((geometry) => geometry.kind !== "edge");
54
+ const activeHandles = anchorGeometries.length > 1 ? createGroupHandles(anchorGeometries) : activeGeometries.flatMap(createHandles);
55
+ return Object.freeze({
56
+ ids: Object.freeze(entities.map((entity) => entity.id)),
57
+ nodes: freezeKind(entities, "node"),
58
+ edges: freezeKind(entities, "edge"),
59
+ texts: freezeKind(entities, "text"),
60
+ shapes: freezeKind(entities, "shape"),
61
+ ports: freezeKind(entities, "port"),
62
+ activeHandles: Object.freeze(activeHandles),
63
+ overlayAnchors: Object.freeze(anchorGeometries.map(createOverlayAnchor)),
64
+ });
65
+ }
66
+ const SELECTION_OWNER_ID = "__selection__";
67
+ function freezeKind(entities, kind) {
68
+ return Object.freeze(entities.filter((entity) => entity.kind === kind));
69
+ }
70
+ function createHandles(geometry) {
71
+ var _a, _b, _c;
72
+ if (geometry.kind === "edge") {
73
+ return [];
74
+ }
75
+ const rect = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
76
+ if (geometry.kind === "port") {
77
+ return [{ id: `${geometry.id}:port`, ownerId: geometry.id, kind: "port", point: (_b = geometry.point) !== null && _b !== void 0 ? _b : { x: rect.x, y: rect.y } }];
78
+ }
79
+ const corners = (_c = geometry.corners) !== null && _c !== void 0 ? _c : [
80
+ { x: rect.x, y: rect.y },
81
+ { x: rect.x + rect.width, y: rect.y },
82
+ { x: rect.x + rect.width, y: rect.y + rect.height },
83
+ { x: rect.x, y: rect.y + rect.height },
84
+ ];
85
+ return [
86
+ { id: `${geometry.id}:nw`, ownerId: geometry.id, kind: "resize", point: corners[0] },
87
+ { id: `${geometry.id}:ne`, ownerId: geometry.id, kind: "resize", point: corners[1] },
88
+ { id: `${geometry.id}:se`, ownerId: geometry.id, kind: "resize", point: corners[2] },
89
+ { id: `${geometry.id}:sw`, ownerId: geometry.id, kind: "resize", point: corners[3] },
90
+ ];
91
+ }
92
+ function createGroupHandles(geometries) {
93
+ const rect = unionRects(geometries.map((geometry) => geometry.bounds));
94
+ if (!rect)
95
+ return [];
96
+ return [
97
+ { id: `${SELECTION_OWNER_ID}:nw`, ownerId: SELECTION_OWNER_ID, kind: "resize", point: { x: rect.x, y: rect.y } },
98
+ { id: `${SELECTION_OWNER_ID}:ne`, ownerId: SELECTION_OWNER_ID, kind: "resize", point: { x: rect.x + rect.width, y: rect.y } },
99
+ { id: `${SELECTION_OWNER_ID}:se`, ownerId: SELECTION_OWNER_ID, kind: "resize", point: { x: rect.x + rect.width, y: rect.y + rect.height } },
100
+ { id: `${SELECTION_OWNER_ID}:sw`, ownerId: SELECTION_OWNER_ID, kind: "resize", point: { x: rect.x, y: rect.y + rect.height } },
101
+ ];
102
+ }
103
+ function unionRects(rects) {
104
+ if (!rects.length)
105
+ return null;
106
+ let minX = Number.POSITIVE_INFINITY;
107
+ let minY = Number.POSITIVE_INFINITY;
108
+ let maxX = Number.NEGATIVE_INFINITY;
109
+ let maxY = Number.NEGATIVE_INFINITY;
110
+ for (const rect of rects) {
111
+ minX = Math.min(minX, rect.x);
112
+ minY = Math.min(minY, rect.y);
113
+ maxX = Math.max(maxX, rect.x + rect.width);
114
+ maxY = Math.max(maxY, rect.y + rect.height);
115
+ }
116
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
117
+ }
118
+ function createOverlayAnchor(geometry) {
119
+ return { id: geometry.id, kind: geometry.kind, rect: geometry.hitBounds };
120
+ }
121
+ function inflate(rect, amount) {
122
+ return { x: rect.x - amount, y: rect.y - amount, width: rect.width + amount * 2, height: rect.height + amount * 2 };
123
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@affino/diagram-vue",
3
+ "version": "0.1.0",
4
+ "author": "Anton Pavlov <a.pavlov@affino.dev>",
5
+ "type": "module",
6
+ "description": "Vue adapter for @affino/diagram-core",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "!dist/__tests__"
18
+ ],
19
+ "sideEffects": false,
20
+ "peerDependencies": {
21
+ "vue": "^3.3.0"
22
+ },
23
+ "dependencies": {
24
+ "@affino/diagram-core": "^0.1.0"
25
+ },
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "vue": "^3.4.0",
29
+ "vitest": "^4.0.18"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/affinio/affinio.git",
34
+ "directory": "packages/diagram-vue"
35
+ },
36
+ "homepage": "https://github.com/affinio/affinio/tree/main/packages/diagram-vue#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/affinio/affinio/issues"
39
+ },
40
+ "keywords": [
41
+ "affino",
42
+ "vue",
43
+ "vue3",
44
+ "diagram",
45
+ "headless"
46
+ ],
47
+ "module": "dist/index.js",
48
+ "scripts": {
49
+ "build": "tsc --build tsconfig.json",
50
+ "test": "vitest run"
51
+ }
52
+ }