@affino/diagram-vue 0.1.0 → 0.2.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 +15 -0
- package/dist/useDiagramPointerController.d.ts.map +1 -1
- package/dist/useDiagramPointerController.js +4 -1
- package/dist/useDiagramRenderer.d.ts +2 -1
- package/dist/useDiagramRenderer.d.ts.map +1 -1
- package/dist/useDiagramRenderer.js +8 -4
- package/dist/useDiagramViewport.d.ts.map +1 -1
- package/dist/useDiagramViewport.js +6 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -81,3 +81,18 @@ Selected entities are included even when outside the viewport, which keeps handl
|
|
|
81
81
|
## What belongs in core
|
|
82
82
|
|
|
83
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.
|
|
84
|
+
|
|
85
|
+
## Viewport and camera migration
|
|
86
|
+
|
|
87
|
+
`ResizeObserver.contentRect` is CSS pixels. `useDiagramViewport()` converts them to world extent by dividing by the current zoom and ignores `0×0` measurements, so a restored camera is not overwritten by a hidden tab. The SVG viewBox should be `x y width height` from the core viewport—do not divide width or height by zoom again.
|
|
88
|
+
|
|
89
|
+
For DOM overlays call `getDomEntityStyle(entity, viewport.viewport.value)`; text editor positioning already applies the same transform. Use core `zoomViewportAt()` for cursor focus and `zoomViewportCentered()` for toolbar zoom. Minimap dimensions use the world scene bounds and the same camera transform.
|
|
90
|
+
|
|
91
|
+
Preview geometry remains transient until pointerup. Render the interaction preview and its handles from core state; entity IDs are opaque strings and may contain `:`. Use `handle.ownerId`, never parse `handle.id`. Escape/pointercancel cancels without history; pointerup commits one undo operation.
|
|
92
|
+
|
|
93
|
+
### Migration from 0.1.0
|
|
94
|
+
|
|
95
|
+
- Replace `viewBox.width = viewport.width / viewport.zoom` and the corresponding height formula with raw world `viewport.width` and `viewport.height`.
|
|
96
|
+
- Remove application-side ResizeObserver writes of CSS width/height into core; use `useDiagramViewport()`.
|
|
97
|
+
- Replace custom cursor zoom/focus and resize camera math with the exported core helpers.
|
|
98
|
+
- Run initial Fit only for a new document without a persisted viewport; never Fit on every resize or scene restore.
|
|
@@ -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,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;CACt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C,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CA2DxJ"}
|
|
@@ -5,6 +5,9 @@ export function useDiagramPointerController(controller, options = {}) {
|
|
|
5
5
|
const interaction = createDiagramInteractionController(controller.engine, {
|
|
6
6
|
scheduleFrame: (callback) => {
|
|
7
7
|
requestAnimationFrame(() => {
|
|
8
|
+
if (disposed) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
8
11
|
callback();
|
|
9
12
|
refresh();
|
|
10
13
|
});
|
|
@@ -51,7 +54,7 @@ export function useDiagramPointerController(controller, options = {}) {
|
|
|
51
54
|
}
|
|
52
55
|
disposed = true;
|
|
53
56
|
interaction.cancel();
|
|
54
|
-
|
|
57
|
+
state.value = interaction.getSnapshot();
|
|
55
58
|
},
|
|
56
59
|
};
|
|
57
60
|
if (getCurrentScope()) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DiagramRenderEntity } from "./types.js";
|
|
2
|
+
import type { DiagramViewport } from "@affino/diagram-core";
|
|
2
3
|
export type SvgEntityProps = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
3
4
|
export declare function getSvgEntityProps(entity: DiagramRenderEntity): SvgEntityProps;
|
|
4
|
-
export declare function getDomEntityStyle(entity: DiagramRenderEntity): Readonly<Record<string, string>>;
|
|
5
|
+
export declare function getDomEntityStyle(entity: DiagramRenderEntity, viewport?: DiagramViewport): Readonly<Record<string, string>>;
|
|
5
6
|
//# sourceMappingURL=useDiagramRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramRenderer.d.ts","sourceRoot":"","sources":["../src/useDiagramRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"useDiagramRenderer.d.ts","sourceRoot":"","sources":["../src/useDiagramRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,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,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAW3H"}
|
|
@@ -39,12 +39,16 @@ export function getSvgEntityProps(entity) {
|
|
|
39
39
|
}
|
|
40
40
|
return common;
|
|
41
41
|
}
|
|
42
|
-
export function getDomEntityStyle(entity) {
|
|
42
|
+
export function getDomEntityStyle(entity, viewport) {
|
|
43
|
+
var _a;
|
|
43
44
|
const bounds = entity.geometry.bounds;
|
|
45
|
+
const zoom = (_a = viewport === null || viewport === void 0 ? void 0 : viewport.zoom) !== null && _a !== void 0 ? _a : 1;
|
|
46
|
+
const left = viewport ? (bounds.x - viewport.x) * zoom : bounds.x;
|
|
47
|
+
const top = viewport ? (bounds.y - viewport.y) * zoom : bounds.y;
|
|
44
48
|
return Object.freeze({
|
|
45
49
|
position: "absolute",
|
|
46
|
-
transform:
|
|
47
|
-
width:
|
|
48
|
-
height:
|
|
50
|
+
transform: "translate(" + left + "px, " + top + "px)",
|
|
51
|
+
width: bounds.width * zoom + "px",
|
|
52
|
+
height: bounds.height * zoom + "px",
|
|
49
53
|
});
|
|
50
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramViewport.d.ts","sourceRoot":"","sources":["../src/useDiagramViewport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAA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AAK,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,CAmEvI"}
|
|
@@ -9,6 +9,9 @@ export function useDiagramViewport(controller, options = {}) {
|
|
|
9
9
|
viewport.value = scene.viewport;
|
|
10
10
|
});
|
|
11
11
|
const setViewport = (next) => {
|
|
12
|
+
if (disposed) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
12
15
|
controller.dispatch({ type: "setViewport", viewport: next });
|
|
13
16
|
};
|
|
14
17
|
const attachViewportElement = (element) => {
|
|
@@ -28,8 +31,9 @@ export function useDiagramViewport(controller, options = {}) {
|
|
|
28
31
|
observer = new ResizeObserverImpl((entries) => {
|
|
29
32
|
var _a;
|
|
30
33
|
const rect = (_a = entries[0]) === null || _a === void 0 ? void 0 : _a.contentRect;
|
|
31
|
-
if (rect) {
|
|
32
|
-
|
|
34
|
+
if (rect && rect.width > 0 && rect.height > 0) {
|
|
35
|
+
const current = controller.scene.value.viewport;
|
|
36
|
+
setViewport({ width: rect.width / current.zoom, height: rect.height / current.zoom });
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
39
|
observer.observe(element);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affino/diagram-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.
|
|
24
|
+
"@affino/diagram-core": "^0.2.0"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|