@affino/diagram-vue 0.11.1 → 0.13.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 CHANGED
@@ -30,6 +30,8 @@ Render static diagram text as SVG `<text>`/`<tspan>` elements in world space. Us
30
30
 
31
31
  Core `flipEntities` commands are reflected by `getSvgEntityProps()` and `getDomEntityStyle()` through the geometry's `flipX`/`flipY` flags. The built-in table view mirrors its cell layout and keeps toolbar and active input controls readable.
32
32
 
33
+ Core group rotation publishes updated member geometry and selection bounds through the existing scene controller. `getSvgEntityProps()` and `DiagramTableView` apply the resulting rotation, so Vue toolbar capability checks based on `engine.canRotate(selection.ids)` and group selection overlays react to the command.
34
+
33
35
  ```vue
34
36
  <script setup lang="ts">
35
37
  import { getSvgEntityProps, useDiagramEngine, useDiagramPointerController, useDiagramTextEditor, useDiagramVisibleEntities } from "@affino/diagram-vue"
@@ -90,11 +92,14 @@ import { useDiagramEngine, useDiagramViewport } from "@affino/diagram-vue"
90
92
 
91
93
  const stage = shallowRef<HTMLElement | null>(null)
92
94
  const diagram = useDiagramEngine(initialScene)
93
- const viewport = useDiagramViewport(diagram, { element: stage })
95
+ const pageConstraints = { bounds: { x: 0, y: 0, width: 794, height: 1123 }, margin: 80 }
96
+ const viewport = useDiagramViewport(diagram, { element: stage, viewportConstraints: pageConstraints })
94
97
 
95
98
  viewport.setViewport({ x: 120, y: 40, zoom: 1.25 })
96
99
  ```
97
100
 
101
+ Pass the same `viewportConstraints` to `useDiagramPointerController()` to constrain pan gesture preview and commit. `useDiagramViewport()` clamps restored state, programmatic `setViewport()` calls, and resize updates only when this option is provided; without it, the existing unbounded behavior is preserved. Bounds and margin use world units, and a visible world area larger than the page plus margin centers the page on that axis.
102
+
98
103
  ## Projection contract
99
104
 
100
105
  `useDiagramVisibleEntities()` exposes:
@@ -1 +1 @@
1
- {"version":3,"file":"DiagramTableView.d.ts","sourceRoot":"","sources":["../src/DiagramTableView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,KAAK,CAAA;AAE/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAIhF,qGAAqG;AACrG,eAAO,MAAM,gBAAgB;;cAGK,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;;;cAHzC,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;MAmIzE,CAAA"}
1
+ {"version":3,"file":"DiagramTableView.d.ts","sourceRoot":"","sources":["../src/DiagramTableView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,KAAK,CAAA;AAG/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAIhF,qGAAqG;AACrG,eAAO,MAAM,gBAAgB;;cAGK,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;;;cAHzC,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;MAkIzE,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { computed, defineComponent, h, nextTick, ref, watch } from "vue";
2
+ import { rectFromPoints, rotatePoint } from "@affino/diagram-core";
2
3
  import { svgTransform } from "./useDiagramRenderer.js";
3
4
  import { useDiagramTable } from "./useDiagramTable.js";
4
5
  /** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
@@ -82,7 +83,7 @@ export const DiagramTableView = defineComponent({
82
83
  h("span", { style: visuallyHiddenStyle }, label), h("input", { type: "number", "aria-label": label, value, min, step: 1, onPointerdown: stopToolbarEvent, onChange: (event) => { event.stopPropagation(); update(Number(event.target.value)); }, style: inputStyle }),
83
84
  ]);
84
85
  return () => {
85
- var _a, _b, _c, _d, _e, _f;
86
+ var _a, _b, _c, _d, _e, _f, _g;
86
87
  const table = projectedTable.value;
87
88
  if (!table)
88
89
  return null;
@@ -118,7 +119,7 @@ export const DiagramTableView = defineComponent({
118
119
  }
119
120
  if (style.border.visible)
120
121
  children.push(h("rect", { x: table.x + style.border.stroke.width / 2, y: table.y + style.border.stroke.width / 2, width: Math.max(0, table.width - style.border.stroke.width), height: Math.max(0, table.height - style.border.stroke.width), rx: style.border.radius, fill: "none", stroke: style.border.stroke.color, "stroke-width": style.border.stroke.width, "stroke-dasharray": dash(style.border.stroke.style), "vector-effect": "non-scaling-stroke", "pointer-events": "none" }));
121
- const tableTransform = svgTransform(0, table.flipX === true, table.flipY === true, table);
122
+ const tableTransform = svgTransform((_g = table.rotation) !== null && _g !== void 0 ? _g : 0, table.flipX === true, table.flipY === true, table);
122
123
  const visualChildren = children.splice(0, children.length);
123
124
  children.push(h("style", tableCellFocusStyles), h("g", { transform: tableTransform }, visualChildren));
124
125
  const activeEdit = editing.value;
@@ -127,9 +128,8 @@ export const DiagramTableView = defineComponent({
127
128
  const cellY = rowOffsets[activeEdit.row];
128
129
  const width = table.columnWidths[activeEdit.column];
129
130
  const height = table.rowHeights[activeEdit.row];
130
- const x = table.flipX ? table.x + table.width - (cellX - table.x) - width : cellX;
131
- const y = table.flipY ? table.y + table.height - (cellY - table.y) - height : cellY;
132
- children.push(h("foreignObject", { x, y, width, height }, [h("input", {
131
+ const editorBounds = projectTableCellBounds(table, { x: cellX, y: cellY, width, height });
132
+ children.push(h("foreignObject", editorBounds, [h("input", {
133
133
  ref: input, value: activeEdit.text, "aria-label": `Edit row ${activeEdit.row + 1}, column ${activeEdit.column + 1}`,
134
134
  onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent,
135
135
  onInput: (event) => { if (editing.value)
@@ -226,6 +226,20 @@ function isPrintableCellInput(event) {
226
226
  && Array.from(event.key).length === 1;
227
227
  }
228
228
  function currentCellValue(table, cell) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = table.cells) === null || _a === void 0 ? void 0 : _a[cell.row]) === null || _b === void 0 ? void 0 : _b[cell.column]) !== null && _c !== void 0 ? _c : table.defaultCell) !== null && _d !== void 0 ? _d : { text: "" }; }
229
+ function projectTableCellBounds(table, cell) {
230
+ const center = { x: table.x + table.width / 2, y: table.y + table.height / 2 };
231
+ const project = (point) => {
232
+ var _a;
233
+ const local = { x: center.x + (point.x - center.x) * (table.flipX ? -1 : 1), y: center.y + (point.y - center.y) * (table.flipY ? -1 : 1) };
234
+ return rotatePoint(local, center, (_a = table.rotation) !== null && _a !== void 0 ? _a : 0);
235
+ };
236
+ return rectFromPoints([
237
+ project({ x: cell.x, y: cell.y }),
238
+ project({ x: cell.x + cell.width, y: cell.y }),
239
+ project({ x: cell.x + cell.width, y: cell.y + cell.height }),
240
+ project({ x: cell.x, y: cell.y + cell.height }),
241
+ ]);
242
+ }
229
243
  function offsets(sizes, start) { const result = [start]; for (const size of sizes)
230
244
  result.push(result[result.length - 1] + size); return result; }
231
245
  function dash(style) { return style === "dashed" ? "6 4" : style === "dotted" ? "1 3" : undefined; }
@@ -1,5 +1,5 @@
1
1
  import type { ShallowRef } from "vue";
2
- import { type DiagramInteractionController, type DiagramInteractionSnapOptions, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint } from "@affino/diagram-core";
2
+ import { type DiagramInteractionController, type DiagramInteractionSnapOptions, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint, type DiagramViewportConstraints } from "@affino/diagram-core";
3
3
  import type { DiagramEngineController } from "./useDiagramEngine.js";
4
4
  export type DiagramPointerController = Readonly<{
5
5
  interaction: DiagramInteractionController;
@@ -18,6 +18,7 @@ export type DiagramPointerControllerOptions = Readonly<{
18
18
  setPointerCapture?: (event: PointerEvent) => void;
19
19
  releasePointerCapture?: (event: PointerEvent) => void;
20
20
  snap?: DiagramInteractionSnapOptions;
21
+ viewportConstraints?: DiagramViewportConstraints;
21
22
  }>;
22
23
  export declare function useDiagramPointerController(controller: DiagramEngineController, options?: DiagramPointerControllerOptions): DiagramPointerController;
23
24
  //# sourceMappingURL=useDiagramPointerController.d.ts.map
@@ -1 +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,6BAA6B,EAAE,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACjO,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,QA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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;IACrD,IAAI,CAAC,EAAE,6BAA6B,CAAA;IACpC,mBAAmB,CAAC,EAAE,0BAA0B,CAAA;CACjD,CAAC,CAAA;AAEF,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CAsExJ"}
@@ -4,6 +4,7 @@ export function useDiagramPointerController(controller, options = {}) {
4
4
  let refresh = () => { };
5
5
  const interaction = createDiagramInteractionController(controller.engine, {
6
6
  snap: options.snap,
7
+ viewportConstraints: options.viewportConstraints,
7
8
  scheduleFrame: (callback) => {
8
9
  const schedule = typeof globalThis.requestAnimationFrame === "function"
9
10
  ? globalThis.requestAnimationFrame.bind(globalThis)
@@ -1,6 +1,6 @@
1
1
  import type { Ref, ShallowRef } from "vue";
2
2
  import type { DiagramEngineController } from "./useDiagramEngine.js";
3
- import type { DiagramViewport } from "@affino/diagram-core";
3
+ import type { DiagramViewport, DiagramViewportConstraints } from "@affino/diagram-core";
4
4
  export type DiagramViewportController = Readonly<{
5
5
  viewport: ShallowRef<DiagramViewport>;
6
6
  setViewport: (viewport: Partial<DiagramViewport>) => void;
@@ -20,6 +20,7 @@ type ResizeObserverCtor = new (callback: (entries: ReadonlyArray<{
20
20
  export type DiagramViewportOptions = Readonly<{
21
21
  element?: Ref<Element | null> | Element | null;
22
22
  resizeObserver?: ResizeObserverCtor;
23
+ viewportConstraints?: DiagramViewportConstraints;
23
24
  }>;
24
25
  export declare function useDiagramViewport(controller: DiagramEngineController, options?: DiagramViewportOptions): DiagramViewportController;
25
26
  export {};
@@ -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AAG,yBAAyB,CA0EvI"}
@@ -1,4 +1,5 @@
1
1
  import { getCurrentScope, isRef, onScopeDispose, shallowRef, watch } from "vue";
2
+ import { clampViewportToBounds } from "@affino/diagram-core";
2
3
  export function useDiagramViewport(controller, options = {}) {
3
4
  const viewport = shallowRef(controller.scene.value.viewport);
4
5
  let observer = null;
@@ -12,6 +13,11 @@ export function useDiagramViewport(controller, options = {}) {
12
13
  if (disposed) {
13
14
  return;
14
15
  }
16
+ if (options.viewportConstraints) {
17
+ const constrained = clampViewportToBounds({ ...controller.scene.value.viewport, ...next }, options.viewportConstraints);
18
+ controller.dispatch({ type: "setViewport", viewport: constrained });
19
+ return;
20
+ }
15
21
  controller.dispatch({ type: "setViewport", viewport: next });
16
22
  };
17
23
  const attachViewportElement = (element) => {
@@ -62,6 +68,8 @@ export function useDiagramViewport(controller, options = {}) {
62
68
  attachViewportElement(initialElement);
63
69
  }
64
70
  }
71
+ if (options.viewportConstraints)
72
+ setViewport(controller.scene.value.viewport);
65
73
  return { viewport, setViewport, attachViewportElement, dispose };
66
74
  }
67
75
  function unwrapElement(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affino/diagram-vue",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "author": "Anton Pavlov <a.pavlov@affino.dev>",
5
5
  "type": "module",
6
6
  "description": "Vue adapter for @affino/diagram-core",
@@ -21,7 +21,7 @@
21
21
  "vue": "^3.3.0"
22
22
  },
23
23
  "dependencies": {
24
- "@affino/diagram-core": "^0.12.0"
24
+ "@affino/diagram-core": "^0.14.0"
25
25
  },
26
26
  "license": "MIT",
27
27
  "devDependencies": {