@fragiola/flow 0.0.0-stage → 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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/connect-session-nyEp02_P.js +375 -0
- package/dist/connect-session-nyEp02_P.js.map +1 -0
- package/dist/connection.d.ts +31 -0
- package/dist/connection.js +60 -0
- package/dist/connection.js.map +1 -0
- package/dist/core-queries-BPNbcM6k.js +452 -0
- package/dist/core-queries-BPNbcM6k.js.map +1 -0
- package/dist/document-schema-CPK5xkyO.js +369 -0
- package/dist/document-schema-CPK5xkyO.js.map +1 -0
- package/dist/drag.d.ts +19 -0
- package/dist/drag.js +175 -0
- package/dist/drag.js.map +1 -0
- package/dist/index.d.ts +876 -0
- package/dist/index.js +5711 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard-links-CVaTtlZg.js +8 -0
- package/dist/keyboard-links-CVaTtlZg.js.map +1 -0
- package/dist/keyboard.d.ts +40 -0
- package/dist/keyboard.js +342 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/minimap.d.ts +26 -0
- package/dist/minimap.js +206 -0
- package/dist/minimap.js.map +1 -0
- package/dist/node-moves-DyWe-4dj.js +36 -0
- package/dist/node-moves-DyWe-4dj.js.map +1 -0
- package/dist/part-attributes-DuBltA__.js +71 -0
- package/dist/part-attributes-DuBltA__.js.map +1 -0
- package/dist/path-format-2OU7Eiyy.js +43 -0
- package/dist/path-format-2OU7Eiyy.js.map +1 -0
- package/dist/reconnection.d.ts +15 -0
- package/dist/reconnection.js +138 -0
- package/dist/reconnection.js.map +1 -0
- package/dist/rect-CmoREaR6.js +92 -0
- package/dist/rect-CmoREaR6.js.map +1 -0
- package/dist/resize.d.ts +33 -0
- package/dist/resize.js +316 -0
- package/dist/resize.js.map +1 -0
- package/dist/rules-DLOMrPBG.js +102 -0
- package/dist/rules-DLOMrPBG.js.map +1 -0
- package/dist/selection.d.ts +38 -0
- package/dist/selection.js +392 -0
- package/dist/selection.js.map +1 -0
- package/dist/subflows.d.ts +9 -0
- package/dist/subflows.js +237 -0
- package/dist/subflows.js.map +1 -0
- package/dist/types-CLHcZVCb.d.ts +2660 -0
- package/dist/viewport-math-B-9Pn2kN.js +69 -0
- package/dist/viewport-math-B-9Pn2kN.js.map +1 -0
- package/package.json +94 -3
package/dist/minimap.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { c as PART_ATTRIBUTE } from "./part-attributes-DuBltA__.js";
|
|
2
|
+
import { t as formatNumber } from "./path-format-2OU7Eiyy.js";
|
|
3
|
+
import { t as boundsOf } from "./rect-CmoREaR6.js";
|
|
4
|
+
import { n as clampZoom, o as viewRect, s as zoomAround, t as centeredOn } from "./viewport-math-B-9Pn2kN.js";
|
|
5
|
+
// src/minimap/minimap-engine.ts
|
|
6
|
+
/** A rectangle as a closed polygon of absolute points. */
|
|
7
|
+
function polygonOf(rect) {
|
|
8
|
+
const f = formatNumber;
|
|
9
|
+
const left = f(rect.x);
|
|
10
|
+
const top = f(rect.y);
|
|
11
|
+
const right = f(rect.x + rect.width);
|
|
12
|
+
const bottom = f(rect.y + rect.height);
|
|
13
|
+
return `M${left},${top} L${right},${top} L${right},${bottom} L${left},${bottom} Z`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The minimap's geometry for one size (in pixels): the flow units a pixel stands for are the
|
|
17
|
+
* fewest that fit the nodes and the view in the minimap less its padding (a share of its size on
|
|
18
|
+
* every side), and the view box is the whole minimap at that scale, centred on them.
|
|
19
|
+
*/
|
|
20
|
+
function minimapView(host, width, height, padding) {
|
|
21
|
+
const { model } = host;
|
|
22
|
+
const nodes = model.get("all-nodes").flatMap((node) => {
|
|
23
|
+
if (node.hidden === true || !host.measured(node.id)) return [];
|
|
24
|
+
const rect = host.nodeRect(node.id);
|
|
25
|
+
return rect ? [{
|
|
26
|
+
nodeId: node.id,
|
|
27
|
+
...rect
|
|
28
|
+
}] : [];
|
|
29
|
+
});
|
|
30
|
+
const size = host.rootSize();
|
|
31
|
+
const view = size.width > 0 && size.height > 0 ? viewRect(host.viewport(), size) : {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
width: 0,
|
|
35
|
+
height: 0
|
|
36
|
+
};
|
|
37
|
+
const shown = boundsOf([...nodes, view]) ?? view;
|
|
38
|
+
const pixels = {
|
|
39
|
+
width: Math.max(1, width),
|
|
40
|
+
height: Math.max(1, height)
|
|
41
|
+
};
|
|
42
|
+
const inner = Math.max(.01, 1 - 2 * Math.min(Math.max(padding, 0), .49));
|
|
43
|
+
const unitsPerPixel = Math.max(shown.width / (pixels.width * inner), shown.height / (pixels.height * inner)) || 1;
|
|
44
|
+
const center = {
|
|
45
|
+
x: shown.x + shown.width / 2,
|
|
46
|
+
y: shown.y + shown.height / 2
|
|
47
|
+
};
|
|
48
|
+
const viewBox = {
|
|
49
|
+
x: center.x - pixels.width * unitsPerPixel / 2,
|
|
50
|
+
y: center.y - pixels.height * unitsPerPixel / 2,
|
|
51
|
+
width: pixels.width * unitsPerPixel,
|
|
52
|
+
height: pixels.height * unitsPerPixel
|
|
53
|
+
};
|
|
54
|
+
const f = formatNumber;
|
|
55
|
+
return {
|
|
56
|
+
viewBox,
|
|
57
|
+
viewBoxAttribute: `${f(viewBox.x)} ${f(viewBox.y)} ${f(viewBox.width)} ${f(viewBox.height)}`,
|
|
58
|
+
scale: unitsPerPixel,
|
|
59
|
+
nodes,
|
|
60
|
+
view,
|
|
61
|
+
maskPath: `${polygonOf(viewBox)} ${polygonOf(view)}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** A client point on a minimap element of `box` as a flow point, through its view box. */
|
|
65
|
+
function pointOn(box, viewBox, client) {
|
|
66
|
+
return {
|
|
67
|
+
x: viewBox.x + (client.x - box.left) / box.width * viewBox.width,
|
|
68
|
+
y: viewBox.y + (client.y - box.top) / box.height * viewBox.height
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Whether a client point lies in an element's box. */
|
|
72
|
+
function contains(box, client) {
|
|
73
|
+
return client.x >= box.left && client.x <= box.left + box.width && client.y >= box.top && client.y <= box.top + box.height;
|
|
74
|
+
}
|
|
75
|
+
/** A zoom step that is a finite number above 0 as given, anything else as none. */
|
|
76
|
+
function zoomStepOf(value) {
|
|
77
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The options a minimap part gave (`engine.adapter.setPartOptions("minimap", "", { inversePan,
|
|
81
|
+
* zoomStep })`: the `MiniMap` primitive's props) over the feature's: one set for the root's
|
|
82
|
+
* minimaps.
|
|
83
|
+
*/
|
|
84
|
+
function effective(host, options) {
|
|
85
|
+
const own = host.partOptions("minimap", "") ?? {};
|
|
86
|
+
return {
|
|
87
|
+
inversePan: typeof own.inversePan === "boolean" ? own.inversePan : options.inversePan,
|
|
88
|
+
zoomStep: zoomStepOf(own.zoomStep) ?? options.zoomStep
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** The engine side of `minimap()`. */
|
|
92
|
+
function minimapEngine(host, options) {
|
|
93
|
+
let root;
|
|
94
|
+
return {
|
|
95
|
+
attached: (element) => {
|
|
96
|
+
root = element;
|
|
97
|
+
},
|
|
98
|
+
detached: () => {
|
|
99
|
+
root = void 0;
|
|
100
|
+
},
|
|
101
|
+
get: {
|
|
102
|
+
"minimap-point-to-flow": (payload) => {
|
|
103
|
+
const { client } = payload ?? {};
|
|
104
|
+
if (!root || typeof client?.x !== "number" || typeof client?.y !== "number") return void 0;
|
|
105
|
+
const boxes = [...root.querySelectorAll(`[${PART_ATTRIBUTE}="minimap"]`)].map((element) => element.getBoundingClientRect()).filter((box) => box.width > 0 && box.height > 0);
|
|
106
|
+
const box = boxes.find((each) => contains(each, client)) ?? boxes[0];
|
|
107
|
+
if (!box) return void 0;
|
|
108
|
+
const { viewBox } = minimapView(host, box.width, box.height, options.padding);
|
|
109
|
+
return pointOn(box, viewBox, client);
|
|
110
|
+
},
|
|
111
|
+
"minimap-view": (payload) => {
|
|
112
|
+
const { width, height } = payload;
|
|
113
|
+
return minimapView(host, typeof width === "number" ? width : 200, typeof height === "number" ? height : 150, options.padding);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
pointerdown: (event, target) => {
|
|
117
|
+
const element = target.kind === "minimap" ? target.element : void 0;
|
|
118
|
+
if (!element) return void 0;
|
|
119
|
+
const box = element.getBoundingClientRect();
|
|
120
|
+
if (box.width <= 0 || box.height <= 0) return void 0;
|
|
121
|
+
const { inversePan } = effective(host, options);
|
|
122
|
+
const { viewBox } = minimapView(host, box.width, box.height, options.padding);
|
|
123
|
+
const origin = host.viewport();
|
|
124
|
+
const size = host.rootSize();
|
|
125
|
+
const pressed = pointOn(box, viewBox, {
|
|
126
|
+
x: event.clientX,
|
|
127
|
+
y: event.clientY
|
|
128
|
+
});
|
|
129
|
+
const start = {
|
|
130
|
+
x: (size.width / 2 - origin.x) / origin.zoom,
|
|
131
|
+
y: (size.height / 2 - origin.y) / origin.zoom
|
|
132
|
+
};
|
|
133
|
+
const centre = (clientX, clientY) => {
|
|
134
|
+
const point = pointOn(box, viewBox, {
|
|
135
|
+
x: clientX,
|
|
136
|
+
y: clientY
|
|
137
|
+
});
|
|
138
|
+
const target = inversePan ? {
|
|
139
|
+
x: start.x - (point.x - pressed.x),
|
|
140
|
+
y: start.y - (point.y - pressed.y)
|
|
141
|
+
} : point;
|
|
142
|
+
const viewport = host.viewport();
|
|
143
|
+
host.setViewport(centeredOn(target, viewport.zoom, host.rootSize()));
|
|
144
|
+
};
|
|
145
|
+
if (options.pannable && !inversePan) centre(event.clientX, event.clientY);
|
|
146
|
+
let moved = false;
|
|
147
|
+
return {
|
|
148
|
+
move: (moving) => {
|
|
149
|
+
if (!options.pannable) return;
|
|
150
|
+
moved = true;
|
|
151
|
+
centre(moving.clientX, moving.clientY);
|
|
152
|
+
},
|
|
153
|
+
end: (released) => {
|
|
154
|
+
if (Math.hypot(released.clientX - event.clientX, released.clientY - event.clientY) > host.tapDistance("node")) return;
|
|
155
|
+
const client = {
|
|
156
|
+
x: released.clientX,
|
|
157
|
+
y: released.clientY
|
|
158
|
+
};
|
|
159
|
+
host.emit({
|
|
160
|
+
type: "minimap-click",
|
|
161
|
+
element,
|
|
162
|
+
point: pointOn(box, viewBox, client),
|
|
163
|
+
client,
|
|
164
|
+
event: released
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
cancel: () => {
|
|
168
|
+
if (options.pannable) host.setViewport(origin);
|
|
169
|
+
},
|
|
170
|
+
active: () => moved
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
wheel: (event, target) => {
|
|
174
|
+
if (target.kind !== "minimap") return false;
|
|
175
|
+
if (!options.zoomable) return true;
|
|
176
|
+
const viewport = host.viewport();
|
|
177
|
+
const size = host.rootSize();
|
|
178
|
+
const scale = event.deltaMode === 1 ? 16 : 1;
|
|
179
|
+
const zoom = viewport.zoom * Math.exp(-event.deltaY * scale * effective(host, options).zoomStep / 6e3);
|
|
180
|
+
host.setViewport(zoomAround(viewport, clampZoom(zoom, host.zoomLimits().min, host.zoomLimits().max), {
|
|
181
|
+
x: size.width / 2,
|
|
182
|
+
y: size.height / 2
|
|
183
|
+
}));
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// src/minimap/minimap.ts
|
|
189
|
+
/** A minimap of the flow: `features: [minimap()]` (`@fragiola/flow/minimap`). */
|
|
190
|
+
function minimap(options = {}) {
|
|
191
|
+
const resolved = Object.freeze({
|
|
192
|
+
pannable: options.pannable ?? true,
|
|
193
|
+
zoomable: options.zoomable ?? true,
|
|
194
|
+
padding: options.padding ?? .1,
|
|
195
|
+
inversePan: options.inversePan ?? false,
|
|
196
|
+
zoomStep: zoomStepOf(options.zoomStep) ?? 10
|
|
197
|
+
});
|
|
198
|
+
return Object.freeze({
|
|
199
|
+
name: "minimap",
|
|
200
|
+
options: resolved,
|
|
201
|
+
engine: (host) => minimapEngine(host, resolved)
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
export { minimap };
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=minimap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimap.js","names":[],"sources":["../src/minimap/minimap-engine.ts","../src/minimap/minimap.ts"],"sourcesContent":["// The minimap feature's engine side: the geometry a minimap of a given size draws\n// (`minimap-view`: the nodes, what the root shows, and the mask around it, in a view box fitted to\n// the minimap's aspect), a press or a drag on it that centres the view on the pressed point\n// (`pannable`), and the wheel over it that zooms the flow around the root's centre (`zoomable`).\nimport { PART_ATTRIBUTE } from \"../attributes/part-attributes\";\nimport type { FlowNode, XY } from \"../document/types\";\nimport type { MinimapView } from \"../engine/verbs\";\nimport { WHEEL_RATE } from \"../engine/wheel-rate\";\nimport type { FeatureEngine, FeatureEngineHost } from \"../features/types\";\nimport { formatNumber } from \"../geometry/path-format\";\nimport { boundsOf } from \"../geometry/rect\";\nimport type { Rect } from \"../geometry/types\";\nimport {\n centeredOn,\n clampZoom,\n viewRect,\n zoomAround,\n} from \"../geometry/viewport-math\";\nimport type { MinimapOptions } from \"./minimap\";\n\n/** A rectangle as a closed polygon of absolute points. */\nfunction polygonOf(rect: Rect): string {\n const f = formatNumber;\n const left = f(rect.x);\n const top = f(rect.y);\n const right = f(rect.x + rect.width);\n const bottom = f(rect.y + rect.height);\n return `M${left},${top} L${right},${top} L${right},${bottom} L${left},${bottom} Z`;\n}\n\n/**\n * The minimap's geometry for one size (in pixels): the flow units a pixel stands for are the\n * fewest that fit the nodes and the view in the minimap less its padding (a share of its size on\n * every side), and the view box is the whole minimap at that scale, centred on them.\n */\nexport function minimapView(\n host: FeatureEngineHost,\n width: number,\n height: number,\n padding: number,\n): MinimapView {\n const { model } = host;\n const nodes = (model.get(\"all-nodes\") as readonly FlowNode[]).flatMap(\n (node) => {\n if (node.hidden === true || !host.measured(node.id)) return [];\n const rect = host.nodeRect(node.id);\n return rect ? [{ nodeId: node.id, ...rect }] : [];\n },\n );\n const size = host.rootSize();\n const view =\n size.width > 0 && size.height > 0\n ? viewRect(host.viewport(), size)\n : { x: 0, y: 0, width: 0, height: 0 };\n const shown = boundsOf([...nodes, view]) ?? view;\n const pixels = { width: Math.max(1, width), height: Math.max(1, height) };\n const inner = Math.max(0.01, 1 - 2 * Math.min(Math.max(padding, 0), 0.49));\n const unitsPerPixel =\n Math.max(\n shown.width / (pixels.width * inner),\n shown.height / (pixels.height * inner),\n ) || 1;\n const center = {\n x: shown.x + shown.width / 2,\n y: shown.y + shown.height / 2,\n };\n const viewBox = {\n x: center.x - (pixels.width * unitsPerPixel) / 2,\n y: center.y - (pixels.height * unitsPerPixel) / 2,\n width: pixels.width * unitsPerPixel,\n height: pixels.height * unitsPerPixel,\n };\n const f = formatNumber;\n return {\n viewBox,\n viewBoxAttribute: `${f(viewBox.x)} ${f(viewBox.y)} ${f(viewBox.width)} ${f(viewBox.height)}`,\n scale: unitsPerPixel,\n nodes,\n view,\n maskPath: `${polygonOf(viewBox)} ${polygonOf(view)}`,\n };\n}\n\n/** A client point on a minimap element of `box` as a flow point, through its view box. */\nfunction pointOn(box: DOMRect, viewBox: Rect, client: XY): XY {\n return {\n x: viewBox.x + ((client.x - box.left) / box.width) * viewBox.width,\n y: viewBox.y + ((client.y - box.top) / box.height) * viewBox.height,\n };\n}\n\n/** Whether a client point lies in an element's box. */\nfunction contains(box: DOMRect, client: XY): boolean {\n return (\n client.x >= box.left &&\n client.x <= box.left + box.width &&\n client.y >= box.top &&\n client.y <= box.top + box.height\n );\n}\n\n/** A zoom step that is a finite number above 0 as given, anything else as none. */\nexport function zoomStepOf(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) && value > 0\n ? value\n : undefined;\n}\n\n/**\n * The options a minimap part gave (`engine.adapter.setPartOptions(\"minimap\", \"\", { inversePan,\n * zoomStep })`: the `MiniMap` primitive's props) over the feature's: one set for the root's\n * minimaps.\n */\nfunction effective(\n host: FeatureEngineHost,\n options: MinimapOptions,\n): { inversePan: boolean; zoomStep: number } {\n const own = host.partOptions(\"minimap\", \"\") ?? {};\n return {\n inversePan:\n typeof own.inversePan === \"boolean\"\n ? own.inversePan\n : options.inversePan,\n zoomStep: zoomStepOf(own.zoomStep) ?? options.zoomStep,\n };\n}\n\n/** The engine side of `minimap()`. */\nexport function minimapEngine(\n host: FeatureEngineHost,\n options: MinimapOptions,\n): FeatureEngine {\n let root: Element | undefined;\n return {\n attached: (element) => {\n root = element;\n },\n detached: () => {\n root = undefined;\n },\n get: {\n \"minimap-point-to-flow\": (payload) => {\n const { client } = (payload ?? {}) as { client?: XY };\n if (\n !root ||\n typeof client?.x !== \"number\" ||\n typeof client?.y !== \"number\"\n )\n return undefined;\n // the minimap under the point (an app may draw several), else the first\n const boxes = [\n ...root.querySelectorAll(`[${PART_ATTRIBUTE}=\"minimap\"]`),\n ]\n .map((element) => element.getBoundingClientRect())\n .filter((box) => box.width > 0 && box.height > 0);\n const box =\n boxes.find((each) => contains(each, client)) ?? boxes[0];\n if (!box) return undefined;\n const { viewBox } = minimapView(\n host,\n box.width,\n box.height,\n options.padding,\n );\n return pointOn(box, viewBox, client);\n },\n \"minimap-view\": (payload) => {\n const { width, height } = payload as {\n width?: unknown;\n height?: unknown;\n };\n return minimapView(\n host,\n typeof width === \"number\" ? width : 200,\n typeof height === \"number\" ? height : 150,\n options.padding,\n );\n },\n },\n pointerdown: (event, target) => {\n const element =\n target.kind === \"minimap\" ? target.element : undefined;\n if (!element) return undefined;\n const box = element.getBoundingClientRect();\n if (box.width <= 0 || box.height <= 0) return undefined;\n const { inversePan } = effective(host, options);\n // the view box at the press: a drag keeps it, though the view it shows moves\n const { viewBox } = minimapView(\n host,\n box.width,\n box.height,\n options.padding,\n );\n const origin = host.viewport();\n const size = host.rootSize();\n const pressed = pointOn(box, viewBox, {\n x: event.clientX,\n y: event.clientY,\n });\n // the view's centre at the press, which an inverse drag moves away from\n const start = {\n x: (size.width / 2 - origin.x) / origin.zoom,\n y: (size.height / 2 - origin.y) / origin.zoom,\n };\n const centre = (clientX: number, clientY: number) => {\n const point = pointOn(box, viewBox, {\n x: clientX,\n y: clientY,\n });\n const target = inversePan\n ? {\n x: start.x - (point.x - pressed.x),\n y: start.y - (point.y - pressed.y),\n }\n : point;\n const viewport = host.viewport();\n host.setViewport(\n centeredOn(target, viewport.zoom, host.rootSize()),\n );\n };\n // an inverse pan grabs the minimap: the press keeps the view where it is\n if (options.pannable && !inversePan) {\n centre(event.clientX, event.clientY);\n }\n let moved = false;\n return {\n move: (moving) => {\n if (!options.pannable) return;\n moved = true;\n centre(moving.clientX, moving.clientY);\n },\n end: (released) => {\n // a tap (within the tap distance): `minimap-click` at the point under it on\n // the pressed minimap, which it names (each minimap keeps only its own taps)\n const distance = Math.hypot(\n released.clientX - event.clientX,\n released.clientY - event.clientY,\n );\n if (distance > host.tapDistance(\"node\")) return;\n const client = { x: released.clientX, y: released.clientY };\n host.emit({\n type: \"minimap-click\",\n element,\n point: pointOn(box, viewBox, client),\n client,\n event: released,\n });\n },\n cancel: () => {\n if (options.pannable) host.setViewport(origin);\n },\n active: () => moved,\n };\n },\n wheel: (event, target) => {\n if (target.kind !== \"minimap\") return false;\n // a minimap that does not zoom keeps the wheel from zooming the flow under it\n if (!options.zoomable) return true;\n const viewport = host.viewport();\n const size = host.rootSize();\n const scale = event.deltaMode === 1 ? 16 : 1;\n const zoom =\n viewport.zoom *\n Math.exp(\n (-event.deltaY *\n scale *\n effective(host, options).zoomStep) /\n (10 * WHEEL_RATE),\n );\n host.setViewport(\n zoomAround(\n viewport,\n clampZoom(\n zoom,\n host.zoomLimits().min,\n host.zoomLimits().max,\n ),\n {\n x: size.width / 2,\n y: size.height / 2,\n },\n ),\n );\n return true;\n },\n };\n}\n","// The minimap feature (D2, `@fragiola/flow/minimap`): a small view of the whole flow and of what\n// the viewport shows, which pans and zooms the viewport. It has no model side: its geometry (the\n// `minimap-view` engine key) and its gestures are its engine side (`minimap-engine.ts`), reading\n// `options`.\nimport type { FlowFeature } from \"../features/types\";\nimport { minimapEngine, zoomStepOf } from \"./minimap-engine\";\n\n/** Options of {@link minimap}: read by its engine side. */\nexport interface MinimapOptions {\n /** whether a press or a drag on the minimap pans the viewport; default true */\n readonly pannable: boolean;\n /** whether the wheel over the minimap zooms the viewport; default true */\n readonly zoomable: boolean;\n /** the share of the minimap's size kept free around the nodes and the view, on every side; default 0.1 */\n readonly padding: number;\n /**\n * whether a drag on the minimap moves the view the other way from the pointer (as grabbing\n * the flow): a press does not centre the view then; default false\n */\n readonly inversePan: boolean;\n /**\n * how fast the wheel over the minimap zooms: 10 is the flow's own wheel, 20 twice as fast;\n * default 10 (also for a value that is not a finite number above 0)\n */\n readonly zoomStep: number;\n}\n\n/** The minimap feature, as `minimap()` makes it. */\nexport type MinimapFeature = FlowFeature<\"minimap\", MinimapOptions>;\n\n/** A minimap of the flow: `features: [minimap()]` (`@fragiola/flow/minimap`). */\nexport function minimap(options: Partial<MinimapOptions> = {}): MinimapFeature {\n const resolved: MinimapOptions = Object.freeze({\n pannable: options.pannable ?? true,\n zoomable: options.zoomable ?? true,\n padding: options.padding ?? 0.1,\n inversePan: options.inversePan ?? false,\n zoomStep: zoomStepOf(options.zoomStep) ?? 10,\n });\n return Object.freeze({\n name: \"minimap\",\n options: resolved,\n engine: (host) => minimapEngine(host, resolved),\n } satisfies MinimapFeature);\n}\n"],"mappings":";;;;;;AAqBA,SAAS,UAAU,MAAoB;CACnC,MAAM,IAAI;CACV,MAAM,OAAO,EAAE,KAAK,CAAC;CACrB,MAAM,MAAM,EAAE,KAAK,CAAC;CACpB,MAAM,QAAQ,EAAE,KAAK,IAAI,KAAK,KAAK;CACnC,MAAM,SAAS,EAAE,KAAK,IAAI,KAAK,MAAM;CACrC,OAAO,IAAI,KAAK,GAAG,IAAI,IAAI,M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;GACrB,CACJ,CACJ;GACA,OAAO;EACX;CACJ;AACJ;;;AC/PA,SAAgB,QAAQ,UAAmC,CAAC,GAAmB;CAC3E,MAAM,WAA2B,OAAO,OAAO;EAC3C,UAAU,QAAQ,YAAY;EAC9B,UAAU,QAAQ,YAAY;EAC9B,SAAS,QAAQ,WAAW;EAC5B,YAAY,QAAQ,cAAc;EAClC,UAAU,WAAW,QAAQ,QAAQ,KAAK;CAC9C,CAAC;CACD,OAAO,OAAO,OAAO;EACjB,MAAM;EACN,SAAS;EACT,SAAS,SAAS,cAAc,MAAM,QAAQ;CAClD,CAA0B;AAC9B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/engine/node-moves.ts
|
|
2
|
+
/** The nodes a move of `nodeIds` moves: those without an ancestor among them, in their order. */
|
|
3
|
+
function movedRoots(model, nodeIds) {
|
|
4
|
+
const set = new Set(nodeIds);
|
|
5
|
+
return nodeIds.filter((nodeId) => {
|
|
6
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7
|
+
let parentId = model.get("node-by", { id: nodeId })?.parentId;
|
|
8
|
+
while (parentId !== void 0 && !seen.has(parentId)) {
|
|
9
|
+
if (set.has(parentId)) return false;
|
|
10
|
+
seen.add(parentId);
|
|
11
|
+
parentId = model.get("node-by", { id: parentId })?.parentId;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** The nodes a move that starts on `nodeId` carries: the selection's draggable nodes when it is selected. */
|
|
17
|
+
function carriedBy(model, nodeId) {
|
|
18
|
+
if (!model.is("node-selected", { nodeId })) return [nodeId];
|
|
19
|
+
return movedRoots(model, (model.get("selected-nodes") ?? []).filter((node) => model.is("node-draggable", { nodeId: node.id })).map((node) => node.id));
|
|
20
|
+
}
|
|
21
|
+
/** Runs moves as one step: one `node.move`, or a `batch` of them. */
|
|
22
|
+
function runMoves(model, moves, transient) {
|
|
23
|
+
if (moves.length === 0) return false;
|
|
24
|
+
if (moves.length === 1) {
|
|
25
|
+
const [move] = moves;
|
|
26
|
+
return model.run("node.move", move, { transient }).ok;
|
|
27
|
+
}
|
|
28
|
+
const commands = moves.map((payload) => ({
|
|
29
|
+
command: "node.move",
|
|
30
|
+
payload
|
|
31
|
+
}));
|
|
32
|
+
return model.run("batch", { commands }, { transient }).ok;
|
|
33
|
+
}
|
|
34
|
+
export { movedRoots as n, runMoves as r, carriedBy as t };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=node-moves-DyWe-4dj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-moves-DyWe-4dj.js","names":[],"sources":["../src/engine/node-moves.ts"],"sourcesContent":["// What every gesture or key that moves nodes shares: the nodes a move carries (a selected node\n// carries the selection; a node whose parent moves too is carried by it) and the commands that move\n// them (one `node.move`, or a `batch` of them).\nimport type { BatchEntry } from \"../commands/types\";\nimport type { FlowNode, XY } from \"../document/types\";\nimport type { FeatureModel } from \"../features/types\";\n\n/** The nodes a move of `nodeIds` moves: those without an ancestor among them, in their order. */\nexport function movedRoots(\n model: FeatureModel,\n nodeIds: readonly string[],\n): string[] {\n const set = new Set(nodeIds);\n return nodeIds.filter((nodeId) => {\n const seen = new Set<string>();\n let parentId = (\n model.get(\"node-by\", { id: nodeId }) as FlowNode | undefined\n )?.parentId;\n while (parentId !== undefined && !seen.has(parentId)) {\n if (set.has(parentId)) return false;\n seen.add(parentId);\n parentId = (\n model.get(\"node-by\", { id: parentId }) as FlowNode | undefined\n )?.parentId;\n }\n return true;\n });\n}\n\n/** The nodes a move that starts on `nodeId` carries: the selection's draggable nodes when it is selected. */\nexport function carriedBy(model: FeatureModel, nodeId: string): string[] {\n if (!model.is(\"node-selected\", { nodeId })) return [nodeId];\n const selected =\n (model.get(\"selected-nodes\") as readonly FlowNode[] | undefined) ?? [];\n return movedRoots(\n model,\n selected\n .filter((node) => model.is(\"node-draggable\", { nodeId: node.id }))\n .map((node) => node.id),\n );\n}\n\n/** Runs moves as one step: one `node.move`, or a `batch` of them. */\nexport function runMoves(\n model: FeatureModel,\n moves: readonly { nodeId: string; position: XY }[],\n transient: boolean,\n): boolean {\n if (moves.length === 0) return false;\n if (moves.length === 1) {\n const [move] = moves as [{ nodeId: string; position: XY }];\n return model.run(\"node.move\", move, { transient }).ok;\n }\n const commands: BatchEntry[] = moves.map((payload) => ({\n command: \"node.move\",\n payload,\n }));\n return model.run(\"batch\", { commands }, { transient }).ok;\n}\n"],"mappings":";;AAQA,SAAgB,WACZ,OACA,SACQ;CACR,MAAM,MAAM,IAAI,IAAI,OAAO;CAC3B,OAAO,QAAQ,QAAQ,WAAW;EAC9B,MAAM,uBAAO,IAAI,IAAY;EAC7B,IAAI,WACA,MAAM,IAAI,WAAW,EAAE,IAAI,OAAO,CAAC,CAAC,EACrC;EACH,OAAO,aAAa,KAAA,KAAa,CAAC,KAAK,IAAI,QAAQ,GAAG;GAClD,IAAI,IAAI,IAAI,QAAQ,GAAG,OAAO;GAC9B,KAAK,IAAI,QAAQ;GACjB,WACI,MAAM,IAAI,WAAW,EAAE,IAAI,SAAS,CAAC,CAAC,EACvC;EACP;EACA,OAAO;CACX,CAAC;AACL;;AAGA,SAAgB,UAAU,OAAqB,QAA0B;CACrE,IAAI,CAAC,MAAM,GAAG,iBAAiB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM;CAG1D,OAAO,WACH,QAFC,MAAM,IAAI,gBAAgB,KAAyC,CAAC,EAAA,CAIhE,QAAQ,SAAS,MAAM,GAAG,kBAAkB,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,CACjE,KAAK,SAAS,KAAK,EAAE,CAC9B;AACJ;;AAGA,SAAgB,SACZ,OACA,OACA,WACO;CACP,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,MAAM,WAAW,GAAG;EACpB,MAAM,CAAC,QAAQ;EACf,OAAO,MAAM,IAAI,aAAa,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACvD;CACA,MAAM,WAAyB,MAAM,KAAK,aAAa;EACnD,SAAS;EACT;CACJ,EAAE;CACF,OAAO,MAAM,IAAI,SAAS,EAAE,SAAS,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC;AAC3D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/attributes/part-attributes.ts
|
|
2
|
+
/** The attribute naming an element's part. */
|
|
3
|
+
const PART_ATTRIBUTE = "data-flow-part";
|
|
4
|
+
/** The attribute holding the id of the entity a part stands for. */
|
|
5
|
+
const ID_ATTRIBUTE = "data-flow-id";
|
|
6
|
+
/** The attribute a resize handle carries: which corner or side of its node it moves. */
|
|
7
|
+
const POSITION_ATTRIBUTE = "data-position";
|
|
8
|
+
/**
|
|
9
|
+
* The attribute a resize handle given its own direction carries (`horizontal`, `vertical`): the
|
|
10
|
+
* sides it moves, over its resizer's `direction`, read when a press or a key on it starts.
|
|
11
|
+
*/
|
|
12
|
+
const DIRECTION_ATTRIBUTE = "data-direction";
|
|
13
|
+
/** The attribute a resize handle carries: how it is drawn (`handle`, `line`), for the app's styles. */
|
|
14
|
+
const VARIANT_ATTRIBUTE = "data-variant";
|
|
15
|
+
/** The attribute a reconnect anchor carries: which end of its edge it moves (`source`, `target`). */
|
|
16
|
+
const END_ATTRIBUTE = "data-end";
|
|
17
|
+
/** The attribute an edges layer carries: its render level (`render-layers`), 0 the lowest. */
|
|
18
|
+
const LEVEL_ATTRIBUTE = "data-level";
|
|
19
|
+
/** A subtree inside a node that starts no gesture when pressed (a slider, a text field). */
|
|
20
|
+
const NO_GESTURE_ATTRIBUTE = "data-flow-no-gesture";
|
|
21
|
+
/**
|
|
22
|
+
* An element inside a node that is its drag handle: a node holding one is dragged only from it (a
|
|
23
|
+
* press elsewhere on it still selects it).
|
|
24
|
+
*/
|
|
25
|
+
const DRAG_HANDLE_ATTRIBUTE = "data-flow-drag-handle";
|
|
26
|
+
/** A subtree inside the flow where the wheel scrolls its content instead of zooming the flow. */
|
|
27
|
+
const NO_WHEEL_ATTRIBUTE = "data-flow-no-wheel";
|
|
28
|
+
/** A boolean state attribute's value: present (`""`) or absent. */
|
|
29
|
+
function flag(on) {
|
|
30
|
+
return on ? "" : void 0;
|
|
31
|
+
}
|
|
32
|
+
/** The static attributes of a part: its name and, for an entity, its id. */
|
|
33
|
+
function partAttributes(part, id) {
|
|
34
|
+
return id === void 0 ? { [PART_ATTRIBUTE]: part } : {
|
|
35
|
+
[PART_ATTRIBUTE]: part,
|
|
36
|
+
[ID_ATTRIBUTE]: id
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The attributes of one render level's edges layer (`edges-layer`, with several levels): its part
|
|
41
|
+
* and its `data-level`. Static: the same with or without an engine.
|
|
42
|
+
*/
|
|
43
|
+
function edgesLayerAttributes(level) {
|
|
44
|
+
return {
|
|
45
|
+
[PART_ATTRIBUTE]: "edges-layer",
|
|
46
|
+
[LEVEL_ATTRIBUTE]: String(level)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const SIDES = /* @__PURE__ */ new Set([
|
|
50
|
+
"top",
|
|
51
|
+
"right",
|
|
52
|
+
"bottom",
|
|
53
|
+
"left"
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* The static attributes of a resize handle (the engine's record adds its state): its part,
|
|
57
|
+
* `data-position`, `data-variant` (`line` only on a side, else `handle`) and `data-direction` when
|
|
58
|
+
* it has a valid one of its own.
|
|
59
|
+
*/
|
|
60
|
+
function resizeHandleAttributes(position, options = {}) {
|
|
61
|
+
const { direction, variant } = options;
|
|
62
|
+
return {
|
|
63
|
+
[PART_ATTRIBUTE]: "resize-handle",
|
|
64
|
+
[POSITION_ATTRIBUTE]: position,
|
|
65
|
+
[VARIANT_ATTRIBUTE]: variant === "line" && position !== void 0 && SIDES.has(position) ? "line" : "handle",
|
|
66
|
+
[DIRECTION_ATTRIBUTE]: direction === "horizontal" || direction === "vertical" ? direction : void 0
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export { LEVEL_ATTRIBUTE as a, PART_ATTRIBUTE as c, edgesLayerAttributes as d, flag as f, ID_ATTRIBUTE as i, POSITION_ATTRIBUTE as l, resizeHandleAttributes as m, DRAG_HANDLE_ATTRIBUTE as n, NO_GESTURE_ATTRIBUTE as o, partAttributes as p, END_ATTRIBUTE as r, NO_WHEEL_ATTRIBUTE as s, DIRECTION_ATTRIBUTE as t, VARIANT_ATTRIBUTE as u };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=part-attributes-DuBltA__.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part-attributes-DuBltA__.js","names":[],"sources":["../src/attributes/part-attributes.ts"],"sourcesContent":["// The part attributes (D11): every element of every primitive carries `data-flow-part` (its part\n// name) and, when it stands for an entity, `data-flow-id` (the node's, edge's or handle's id). The\n// state attributes are booleans (present as `\"\"`, absent otherwise: `data-selected`,\n// `data-dragging`, `data-connecting`, `data-valid` / `data-invalid`, …) or values (`data-handle-type`,\n// `data-side`, `data-position`). The engine computes them (`engine.adapter.attributes(part, …)`),\n// so every adapter spreads the same record; `partAttributes` gives the static ones without an\n// engine (a server render, a part with no state).\n\n/** The attribute naming an element's part. */\nexport const PART_ATTRIBUTE = \"data-flow-part\";\n\n/** The attribute holding the id of the entity a part stands for. */\nexport const ID_ATTRIBUTE = \"data-flow-id\";\n\n/** The attribute a resize handle carries: which corner or side of its node it moves. */\nexport const POSITION_ATTRIBUTE = \"data-position\";\n\n/**\n * The attribute a resize handle given its own direction carries (`horizontal`, `vertical`): the\n * sides it moves, over its resizer's `direction`, read when a press or a key on it starts.\n */\nexport const DIRECTION_ATTRIBUTE = \"data-direction\";\n\n/** The attribute a resize handle carries: how it is drawn (`handle`, `line`), for the app's styles. */\nexport const VARIANT_ATTRIBUTE = \"data-variant\";\n\n/** The attribute a reconnect anchor carries: which end of its edge it moves (`source`, `target`). */\nexport const END_ATTRIBUTE = \"data-end\";\n\n/** The attribute an edges layer carries: its render level (`render-layers`), 0 the lowest. */\nexport const LEVEL_ATTRIBUTE = \"data-level\";\n\n/** A subtree inside a node that starts no gesture when pressed (a slider, a text field). */\nexport const NO_GESTURE_ATTRIBUTE = \"data-flow-no-gesture\";\n\n/**\n * An element inside a node that is its drag handle: a node holding one is dragged only from it (a\n * press elsewhere on it still selects it).\n */\nexport const DRAG_HANDLE_ATTRIBUTE = \"data-flow-drag-handle\";\n\n/** A subtree inside the flow where the wheel scrolls its content instead of zooming the flow. */\nexport const NO_WHEEL_ATTRIBUTE = \"data-flow-no-wheel\";\n\n/** The parts of the flow's primitives (an adapter may use others: `toolbar`, `panel`, …). */\nexport type FlowPart =\n | \"root\"\n | \"viewport\"\n | \"nodes\"\n | \"node\"\n | \"edges\"\n | \"edges-layer\"\n | \"edge\"\n | \"edge-path\"\n | \"edge-label\"\n | \"reconnect-anchor\"\n | \"handle\"\n | \"connection-line\"\n | \"selection-box\"\n | \"nodes-selection\"\n | \"background\"\n | \"controls\"\n | \"minimap\"\n | \"minimap-node\"\n | \"minimap-mask\"\n | \"resizer\"\n | \"resize-handle\"\n | \"toolbar\"\n | \"panel\";\n\n/** A part's attributes: names to values, `undefined` for an attribute the element does not have. */\nexport type PartAttributes = Readonly<Record<string, string | undefined>>;\n\n/** A writable attribute record, as the engine and its features fill it. */\nexport type MutablePartAttributes = Record<string, string | undefined>;\n\n/** A boolean state attribute's value: present (`\"\"`) or absent. */\nexport function flag(on: boolean): string | undefined {\n return on ? \"\" : undefined;\n}\n\n/** The static attributes of a part: its name and, for an entity, its id. */\nexport function partAttributes(part: string, id?: string): PartAttributes {\n return id === undefined\n ? { [PART_ATTRIBUTE]: part }\n : { [PART_ATTRIBUTE]: part, [ID_ATTRIBUTE]: id };\n}\n\n/**\n * The attributes of one render level's edges layer (`edges-layer`, with several levels): its part\n * and its `data-level`. Static: the same with or without an engine.\n */\nexport function edgesLayerAttributes(level: number): PartAttributes {\n return {\n [PART_ATTRIBUTE]: \"edges-layer\",\n [LEVEL_ATTRIBUTE]: String(level),\n };\n}\n\n/** The sides a resize handle moves, over its resizer's direction. */\nexport type ResizeHandleDirection = \"horizontal\" | \"vertical\";\n\n/**\n * How a resize handle is drawn: `handle` (a grab area on its corner or side) or `line` (a side's\n * whole length, a marker the app styles thin); a corner is always a `handle`.\n */\nexport type ResizeHandleVariant = \"handle\" | \"line\";\n\n/** What a resize handle's attributes are made of (`resizeHandleAttributes`). */\nexport interface ResizeHandleAttributeOptions {\n /** the sides it moves, over its resizer's; anything else: the resizer's */\n readonly direction?: string | undefined;\n /** how it is drawn; default `handle`, and a corner's `line` is ignored */\n readonly variant?: string | undefined;\n}\n\nconst SIDES = new Set([\"top\", \"right\", \"bottom\", \"left\"]);\n\n/**\n * The static attributes of a resize handle (the engine's record adds its state): its part,\n * `data-position`, `data-variant` (`line` only on a side, else `handle`) and `data-direction` when\n * it has a valid one of its own.\n */\nexport function resizeHandleAttributes(\n position: string | undefined,\n options: ResizeHandleAttributeOptions = {},\n): PartAttributes {\n const { direction, variant } = options;\n return {\n [PART_ATTRIBUTE]: \"resize-handle\",\n [POSITION_ATTRIBUTE]: position,\n [VARIANT_ATTRIBUTE]:\n variant === \"line\" && position !== undefined && SIDES.has(position)\n ? \"line\"\n : \"handle\",\n [DIRECTION_ATTRIBUTE]:\n direction === \"horizontal\" || direction === \"vertical\"\n ? direction\n : undefined,\n };\n}\n"],"mappings":";;AASA,MAAa,iBAAiB;;AAG9B,MAAa,eAAe;;AAG5B,MAAa,qBAAqB;;;;;AAMlC,MAAa,sBAAsB;;AAGnC,MAAa,oBAAoB;;AAGjC,MAAa,gBAAgB;;AAG7B,MAAa,kBAAkB;;AAG/B,MAAa,uBAAuB;;;;;AAMpC,MAAa,wBAAwB;;AAGrC,MAAa,qBAAqB;;AAmClC,SAAgB,KAAK,IAAiC;CAClD,OAAO,KAAK,KAAK,KAAA;AACrB;;AAGA,SAAgB,eAAe,MAAc,IAA6B;CACtE,OAAO,OAAO,KAAA,IACR,GAAG,iBAAiB,KAAK,IACzB;GAAG,iBAAiB;GAAO,eAAe;CAAG;AACvD;;;;;AAMA,SAAgB,qBAAqB,OAA+B;CAChE,OAAO;GACF,iBAAiB;GACjB,kBAAkB,OAAO,KAAK;CACnC;AACJ;AAmBA,MAAM,wBAAQ,IAAI,IAAI;CAAC;CAAO;CAAS;CAAU;AAAM,CAAC;;;;;;AAOxD,SAAgB,uBACZ,UACA,UAAwC,CAAC,GAC3B;CACd,MAAM,EAAE,WAAW,YAAY;CAC/B,OAAO;GACF,iBAAiB;GACjB,qBAAqB;GACrB,oBACG,YAAY,UAAU,aAAa,KAAA,KAAa,MAAM,IAAI,QAAQ,IAC5D,SACA;GACT,sBACG,cAAc,gBAAgB,cAAc,aACtC,YACA,KAAA;CACd;AACJ"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/geometry/path-format.ts
|
|
2
|
+
/** A number as path data writes it. */
|
|
3
|
+
function formatNumber(value) {
|
|
4
|
+
const rounded = Math.round(value * 100) / 100;
|
|
5
|
+
return String(Object.is(rounded, -0) ? 0 : rounded);
|
|
6
|
+
}
|
|
7
|
+
/** A point as path data writes it (`x,y`). */
|
|
8
|
+
function formatPoint(point) {
|
|
9
|
+
return `${formatNumber(point.x)},${formatNumber(point.y)}`;
|
|
10
|
+
}
|
|
11
|
+
/** The unit vector a side points to: an edge leaves a handle on that side in that direction. */
|
|
12
|
+
function sideDirection(side) {
|
|
13
|
+
switch (side) {
|
|
14
|
+
case "top": return {
|
|
15
|
+
x: 0,
|
|
16
|
+
y: -1
|
|
17
|
+
};
|
|
18
|
+
case "right": return {
|
|
19
|
+
x: 1,
|
|
20
|
+
y: 0
|
|
21
|
+
};
|
|
22
|
+
case "bottom": return {
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 1
|
|
25
|
+
};
|
|
26
|
+
case "left": return {
|
|
27
|
+
x: -1,
|
|
28
|
+
y: 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The side opposite another. */
|
|
33
|
+
function oppositeSide(side) {
|
|
34
|
+
switch (side) {
|
|
35
|
+
case "top": return "bottom";
|
|
36
|
+
case "right": return "left";
|
|
37
|
+
case "bottom": return "top";
|
|
38
|
+
case "left": return "right";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export { sideDirection as i, formatPoint as n, oppositeSide as r, formatNumber as t };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=path-format-2OU7Eiyy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-format-2OU7Eiyy.js","names":[],"sources":["../src/geometry/path-format.ts"],"sourcesContent":["// How the path helpers write numbers and points into SVG path data: at most two decimals, never\n// `-0`, so the same geometry always gives the same string.\nimport type { XY } from \"../document/types\";\nimport type { HandleSide } from \"./types\";\n\n/** A number as path data writes it. */\nexport function formatNumber(value: number): string {\n const rounded = Math.round(value * 100) / 100;\n return String(Object.is(rounded, -0) ? 0 : rounded);\n}\n\n/** A point as path data writes it (`x,y`). */\nexport function formatPoint(point: XY): string {\n return `${formatNumber(point.x)},${formatNumber(point.y)}`;\n}\n\n/** The unit vector a side points to: an edge leaves a handle on that side in that direction. */\nexport function sideDirection(side: HandleSide): XY {\n switch (side) {\n case \"top\":\n return { x: 0, y: -1 };\n case \"right\":\n return { x: 1, y: 0 };\n case \"bottom\":\n return { x: 0, y: 1 };\n case \"left\":\n return { x: -1, y: 0 };\n }\n}\n\n/** The side opposite another. */\nexport function oppositeSide(side: HandleSide): HandleSide {\n switch (side) {\n case \"top\":\n return \"bottom\";\n case \"right\":\n return \"left\";\n case \"bottom\":\n return \"top\";\n case \"left\":\n return \"right\";\n }\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,OAAuB;CAChD,MAAM,UAAU,KAAK,MAAM,QAAQ,GAAG,IAAI;CAC1C,OAAO,OAAO,OAAO,GAAG,SAAS,EAAE,IAAI,IAAI,OAAO;AACtD;;AAGA,SAAgB,YAAY,OAAmB;CAC3C,OAAO,GAAG,aAAa,MAAM,CAAC,EAAE,GAAG,aAAa,MAAM,CAAC;AAC3D;;AAGA,SAAgB,cAAc,MAAsB;CAChD,QAAQ,MAAR;EACI,KAAK,OACD,OAAO;GAAE,GAAG;GAAG,GAAG;EAAG;EACzB,KAAK,SACD,OAAO;GAAE,GAAG;GAAG,GAAG;EAAE;EACxB,KAAK,UACD,OAAO;GAAE,GAAG;GAAG,GAAG;EAAE;EACxB,KAAK,QACD,OAAO;GAAE,GAAG;GAAI,GAAG;EAAE;CAC7B;AACJ;;AAGA,SAAgB,aAAa,MAA8B;CACvD,QAAQ,MAAR;EACI,KAAK,OACD,OAAO;EACX,KAAK,SACD,OAAO;EACX,KAAK,UACD,OAAO;EACX,KAAK,QACD,OAAO;CACf;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { f as FlowFeature } from "./types-CLHcZVCb.js";
|
|
2
|
+
/** Options of {@link reconnection}: read by its engine side. */
|
|
3
|
+
interface ReconnectionOptions {
|
|
4
|
+
/** how near (in pixels) to an edge's end a press must be to grab it; default 10 */
|
|
5
|
+
readonly radius: number;
|
|
6
|
+
}
|
|
7
|
+
/** The reconnection feature, as `reconnection()` makes it. */
|
|
8
|
+
type ReconnectionFeature = FlowFeature<"reconnection", ReconnectionOptions>;
|
|
9
|
+
/**
|
|
10
|
+
* Moving an edge's ends: `features: [connection(), reconnection()]`
|
|
11
|
+
* (`@fragiola/flow/reconnection`; it requires `connection()`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function reconnection(options?: Partial<ReconnectionOptions>): ReconnectionFeature;
|
|
14
|
+
export type { ReconnectionFeature, ReconnectionOptions };
|
|
15
|
+
//# sourceMappingURL=reconnection.d.ts.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { d as fail, i as isFailure, l as reconnectableEnd, n as findEdge, p as ok, s as edgeFlag, t as connectionProblem, u as defineCommand } from "./rules-DLOMrPBG.js";
|
|
2
|
+
import { n as edgeSchema } from "./document-schema-CPK5xkyO.js";
|
|
3
|
+
import { t as connectSessionOf } from "./connect-session-nyEp02_P.js";
|
|
4
|
+
import { a as toScreen } from "./viewport-math-B-9Pn2kN.js";
|
|
5
|
+
// src/reconnection/commands.ts
|
|
6
|
+
const { source, target, sourceHandle, targetHandle } = edgeSchema.properties;
|
|
7
|
+
const edgeId = {
|
|
8
|
+
type: "string",
|
|
9
|
+
minLength: 1,
|
|
10
|
+
description: "the edge's id"
|
|
11
|
+
};
|
|
12
|
+
const edgeReconnect = defineCommand({
|
|
13
|
+
name: "edge.reconnect",
|
|
14
|
+
description: "Moves an edge's ends: its new source and target nodes and, optionally, handles (a handle left out is none). Its id, type and data stay. Refused when the edge is not reconnectable (or an end it moves is not: `reconnectable` \"source\" or \"target\"), a node is not connectable, or another edge already joins the same handles.",
|
|
15
|
+
payloadSchema: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
edgeId,
|
|
19
|
+
source,
|
|
20
|
+
target,
|
|
21
|
+
sourceHandle,
|
|
22
|
+
targetHandle
|
|
23
|
+
},
|
|
24
|
+
required: [
|
|
25
|
+
"edgeId",
|
|
26
|
+
"source",
|
|
27
|
+
"target"
|
|
28
|
+
],
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
},
|
|
31
|
+
resultSchema: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: { edgeId },
|
|
34
|
+
required: ["edgeId"],
|
|
35
|
+
additionalProperties: false
|
|
36
|
+
},
|
|
37
|
+
transient: false,
|
|
38
|
+
reduce: ({ edgeId, ...ends }, { draft }) => {
|
|
39
|
+
const edge = findEdge(draft, edgeId, "/edgeId");
|
|
40
|
+
if (isFailure(edge)) return edge;
|
|
41
|
+
if (!edgeFlag(edge, "reconnectable")) return fail("refused", `edge "${edgeId}" is not reconnectable`, "/edgeId");
|
|
42
|
+
for (const end of ["source", "target"]) {
|
|
43
|
+
const handle = end === "source" ? "sourceHandle" : "targetHandle";
|
|
44
|
+
if ((ends[end] !== edge[end] || ends[handle] !== edge[handle]) && !reconnectableEnd(edge, end)) return fail("refused", `edge "${edgeId}"'s ${end} end is not reconnectable`, `/${end}`);
|
|
45
|
+
}
|
|
46
|
+
const problem = connectionProblem(draft, ends, edgeId);
|
|
47
|
+
if (problem) return problem;
|
|
48
|
+
const { sourceHandle: _sourceHandle, targetHandle: _targetHandle, ...kept } = edge;
|
|
49
|
+
draft.putEdge({
|
|
50
|
+
...kept,
|
|
51
|
+
...ends
|
|
52
|
+
});
|
|
53
|
+
return ok({ edgeId });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// src/reconnection/reconnection-engine.ts
|
|
57
|
+
/** The engine side of `reconnection()`. */
|
|
58
|
+
function reconnectionEngine(host, options) {
|
|
59
|
+
const session = connectSessionOf(host);
|
|
60
|
+
/** The handle the fixed end of an edge is at (registered, or as its path draws it). */
|
|
61
|
+
const fixedEnd = (edge, end) => {
|
|
62
|
+
const path = host.edgePath(edge.id);
|
|
63
|
+
if (!path) return void 0;
|
|
64
|
+
const fixed = end === "source" ? "target" : "source";
|
|
65
|
+
const nodeId = fixed === "source" ? edge.source : edge.target;
|
|
66
|
+
const handleId = fixed === "source" ? edge.sourceHandle : edge.targetHandle;
|
|
67
|
+
const candidates = host.handles().filter((handle) => handle.nodeId === nodeId && handle.handleId === handleId && handle.center !== void 0);
|
|
68
|
+
return candidates.find((handle) => handle.type === fixed) ?? candidates[0] ?? {
|
|
69
|
+
nodeId,
|
|
70
|
+
handleId,
|
|
71
|
+
type: fixed,
|
|
72
|
+
side: fixed === "source" ? path.sourceSide : path.targetSide,
|
|
73
|
+
connectable: true,
|
|
74
|
+
connectableStart: true,
|
|
75
|
+
connectableEnd: true,
|
|
76
|
+
center: fixed === "source" ? path.source : path.target,
|
|
77
|
+
bounds: void 0
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
is: { "edge-reconnecting": (payload) => session.current()?.reconnecting?.edgeId === payload.edgeId },
|
|
82
|
+
pointerdown: (event, target) => {
|
|
83
|
+
if (target.kind !== "edge" || target.edgeId === void 0 || !host.allows("reconnect") || !host.allows("connect") || session.current() !== null || !host.model.is("edge-reconnectable", { edgeId: target.edgeId })) return;
|
|
84
|
+
const edge = host.model.get("edge-by", { id: target.edgeId });
|
|
85
|
+
const path = edge && host.edgePath(edge.id);
|
|
86
|
+
if (!edge || !path) return void 0;
|
|
87
|
+
const pointer = host.toRoot({
|
|
88
|
+
x: event.clientX,
|
|
89
|
+
y: event.clientY
|
|
90
|
+
});
|
|
91
|
+
const near = (point) => {
|
|
92
|
+
const screen = toScreen(host.viewport(), point);
|
|
93
|
+
return Math.hypot(screen.x - pointer.x, screen.y - pointer.y);
|
|
94
|
+
};
|
|
95
|
+
const movable = (which) => host.model.is("edge-reconnectable", {
|
|
96
|
+
edgeId: edge.id,
|
|
97
|
+
end: which
|
|
98
|
+
});
|
|
99
|
+
let end = target.end;
|
|
100
|
+
if (end === void 0) {
|
|
101
|
+
const toTarget = movable("target") ? near(path.target) : Number.POSITIVE_INFINITY;
|
|
102
|
+
const toSource = movable("source") ? near(path.source) : Number.POSITIVE_INFINITY;
|
|
103
|
+
if (Math.min(toTarget, toSource) > options.radius) return void 0;
|
|
104
|
+
end = toTarget <= toSource ? "target" : "source";
|
|
105
|
+
} else if (!movable(end)) return;
|
|
106
|
+
const from = fixedEnd(edge, end);
|
|
107
|
+
if (!from) return void 0;
|
|
108
|
+
return session.gesture({
|
|
109
|
+
from,
|
|
110
|
+
reconnecting: {
|
|
111
|
+
edgeId: edge.id,
|
|
112
|
+
end
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
x: event.clientX,
|
|
116
|
+
y: event.clientY
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// src/reconnection/reconnection.ts
|
|
122
|
+
/**
|
|
123
|
+
* Moving an edge's ends: `features: [connection(), reconnection()]`
|
|
124
|
+
* (`@fragiola/flow/reconnection`; it requires `connection()`).
|
|
125
|
+
*/
|
|
126
|
+
function reconnection(options = {}) {
|
|
127
|
+
const resolved = Object.freeze({ radius: options.radius ?? 10 });
|
|
128
|
+
return Object.freeze({
|
|
129
|
+
name: "reconnection",
|
|
130
|
+
requires: Object.freeze(["connection"]),
|
|
131
|
+
options: resolved,
|
|
132
|
+
commands: [edgeReconnect],
|
|
133
|
+
engine: (host) => reconnectionEngine(host, resolved)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export { reconnection };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=reconnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnection.js","names":[],"sources":["../src/reconnection/commands.ts","../src/reconnection/reconnection-engine.ts","../src/reconnection/reconnection.ts"],"sourcesContent":["// `edge.reconnect` (D6, the reconnection feature): moves one or both ends of an edge to other\n// nodes or handles, keeping its id, type and data. The same rules as `edge.add` (both nodes exist\n// and are connectable, no second edge between the same handles), and the edge's own\n// `reconnectable` flag; a middleware's veto refuses it (D7: `model.can(\"edge.reconnect\", …)` is a\n// reconnection's validity).\nimport { defineCommand, fail, ok } from \"../commands/define\";\nimport { connectionProblem, findEdge, isFailure } from \"../commands/rules\";\nimport { edgeSchema } from \"../document/document-schema\";\nimport { edgeFlag, reconnectableEnd } from \"../document/flags\";\n\nconst { source, target, sourceHandle, targetHandle } = edgeSchema.properties;\nconst edgeId = {\n type: \"string\",\n minLength: 1,\n description: \"the edge's id\",\n} as const;\n\nexport const edgeReconnect = defineCommand({\n name: \"edge.reconnect\",\n description:\n 'Moves an edge\\'s ends: its new source and target nodes and, optionally, handles (a handle left out is none). Its id, type and data stay. Refused when the edge is not reconnectable (or an end it moves is not: `reconnectable` \"source\" or \"target\"), a node is not connectable, or another edge already joins the same handles.',\n payloadSchema: {\n type: \"object\",\n properties: { edgeId, source, target, sourceHandle, targetHandle },\n required: [\"edgeId\", \"source\", \"target\"],\n additionalProperties: false,\n },\n resultSchema: {\n type: \"object\",\n properties: { edgeId },\n required: [\"edgeId\"],\n additionalProperties: false,\n },\n transient: false,\n reduce: ({ edgeId, ...ends }, { draft }) => {\n const edge = findEdge(draft, edgeId, \"/edgeId\");\n if (isFailure(edge)) {\n return edge;\n }\n if (!edgeFlag(edge, \"reconnectable\")) {\n return fail(\n \"refused\",\n `edge \"${edgeId}\" is not reconnectable`,\n \"/edgeId\",\n );\n }\n // `reconnectable: \"source\"` (or `\"target\"`): the other end stays where it is\n for (const end of [\"source\", \"target\"] as const) {\n const handle = end === \"source\" ? \"sourceHandle\" : \"targetHandle\";\n const moves =\n ends[end] !== edge[end] || ends[handle] !== edge[handle];\n if (moves && !reconnectableEnd(edge, end)) {\n return fail(\n \"refused\",\n `edge \"${edgeId}\"'s ${end} end is not reconnectable`,\n `/${end}`,\n );\n }\n }\n const problem = connectionProblem(draft, ends, edgeId);\n if (problem) {\n return problem;\n }\n const {\n sourceHandle: _sourceHandle,\n targetHandle: _targetHandle,\n ...kept\n } = edge;\n draft.putEdge({ ...kept, ...ends });\n return ok({ edgeId });\n },\n});\n","// The reconnection feature's engine side: a press on an edge's reconnect anchor (the part\n// `reconnect-anchor`, `data-end`), or on the edge within `radius` pixels of one of its ends, drags\n// that end; the connection line runs from the edge's other end (the session of\n// `connection()`, shared through the host), valid when `model.can(\"edge.reconnect\", …)`, and a\n// drop there reconnects the edge. An edge whose `reconnectable` names one end moves that end only:\n// a press near its other end, or on that end's anchor, is not taken.\nimport { connectSessionOf } from \"../connect-session/connect-session\";\nimport type { FlowEdge } from \"../document/types\";\nimport type { FlowHandle } from \"../engine/adapter\";\nimport type { FeatureEngine, FeatureEngineHost } from \"../features/types\";\nimport { toScreen } from \"../geometry/viewport-math\";\nimport type { ReconnectionOptions } from \"./reconnection\";\n\n/** The engine side of `reconnection()`. */\nexport function reconnectionEngine(\n host: FeatureEngineHost,\n options: ReconnectionOptions,\n): FeatureEngine {\n const session = connectSessionOf(host);\n /** The handle the fixed end of an edge is at (registered, or as its path draws it). */\n const fixedEnd = (\n edge: FlowEdge,\n end: \"source\" | \"target\",\n ): FlowHandle | undefined => {\n const path = host.edgePath(edge.id);\n if (!path) return undefined;\n const fixed = end === \"source\" ? \"target\" : \"source\";\n const nodeId = fixed === \"source\" ? edge.source : edge.target;\n const handleId =\n fixed === \"source\" ? edge.sourceHandle : edge.targetHandle;\n const candidates = host\n .handles()\n .filter(\n (handle) =>\n handle.nodeId === nodeId &&\n handle.handleId === handleId &&\n handle.center !== undefined,\n );\n const registered =\n candidates.find((handle) => handle.type === fixed) ?? candidates[0];\n return (\n registered ?? {\n nodeId,\n handleId,\n type: fixed,\n side: fixed === \"source\" ? path.sourceSide : path.targetSide,\n connectable: true,\n connectableStart: true,\n connectableEnd: true,\n center: fixed === \"source\" ? path.source : path.target,\n bounds: undefined,\n }\n );\n };\n return {\n is: {\n \"edge-reconnecting\": (payload) =>\n session.current()?.reconnecting?.edgeId ===\n (payload as { edgeId?: unknown }).edgeId,\n },\n pointerdown: (event, target) => {\n if (\n target.kind !== \"edge\" ||\n target.edgeId === undefined ||\n // moving an end connects it anew: the lock's `connect: false` stops it too\n !host.allows(\"reconnect\") ||\n !host.allows(\"connect\") ||\n session.current() !== null ||\n !host.model.is(\"edge-reconnectable\", { edgeId: target.edgeId })\n ) {\n return undefined;\n }\n const edge = host.model.get(\"edge-by\", { id: target.edgeId }) as\n | FlowEdge\n | undefined;\n const path = edge && host.edgePath(edge.id);\n if (!edge || !path) return undefined;\n const pointer = host.toRoot({ x: event.clientX, y: event.clientY });\n const near = (point: { x: number; y: number }) => {\n const screen = toScreen(host.viewport(), point);\n return Math.hypot(screen.x - pointer.x, screen.y - pointer.y);\n };\n const movable = (which: \"source\" | \"target\") =>\n host.model.is(\"edge-reconnectable\", {\n edgeId: edge.id,\n end: which,\n });\n // a reconnect anchor names its end; a press on the edge itself must be near one (an\n // end that may move)\n let end = target.end;\n if (end === undefined) {\n const toTarget = movable(\"target\")\n ? near(path.target)\n : Number.POSITIVE_INFINITY;\n const toSource = movable(\"source\")\n ? near(path.source)\n : Number.POSITIVE_INFINITY;\n if (Math.min(toTarget, toSource) > options.radius)\n return undefined;\n end = toTarget <= toSource ? \"target\" : \"source\";\n } else if (!movable(end)) {\n return undefined;\n }\n const from = fixedEnd(edge, end);\n if (!from) return undefined;\n return session.gesture(\n { from, reconnecting: { edgeId: edge.id, end } },\n { x: event.clientX, y: event.clientY },\n );\n },\n };\n}\n","// The reconnection feature (D2, `@fragiola/flow/reconnection`, requires `connection()`): dragging\n// an edge's end to another handle moves it. Its model side is `edge.reconnect`; its engine side\n// (`reconnection-engine.ts`: the gesture from an edge's end, validity through\n// `model.can(\"edge.reconnect\", …)`) reads `options`.\nimport type { FlowFeature } from \"../features/types\";\nimport { edgeReconnect } from \"./commands\";\nimport { reconnectionEngine } from \"./reconnection-engine\";\n\n/** Options of {@link reconnection}: read by its engine side. */\nexport interface ReconnectionOptions {\n /** how near (in pixels) to an edge's end a press must be to grab it; default 10 */\n readonly radius: number;\n}\n\n/** The reconnection feature, as `reconnection()` makes it. */\nexport type ReconnectionFeature = FlowFeature<\n \"reconnection\",\n ReconnectionOptions\n>;\n\n/**\n * Moving an edge's ends: `features: [connection(), reconnection()]`\n * (`@fragiola/flow/reconnection`; it requires `connection()`).\n */\nexport function reconnection(\n options: Partial<ReconnectionOptions> = {},\n): ReconnectionFeature {\n const resolved: ReconnectionOptions = Object.freeze({\n radius: options.radius ?? 10,\n });\n return Object.freeze({\n name: \"reconnection\",\n requires: Object.freeze([\"connection\"] as const),\n options: resolved,\n commands: [edgeReconnect],\n engine: (host) => reconnectionEngine(host, resolved),\n } satisfies ReconnectionFeature);\n}\n"],"mappings":";;;;;AAUA,MAAM,EAAE,QAAQ,QAAQ,cAAc,iBAAiB,WAAW;AAClE,MAAM,SAAS;CACX,MAAM;CACN,WAAW;CACX,aAAa;AACjB;AAEA,MAAa,gBAAgB,cAAc;CACvC,MAAM;CACN,aACI;CACJ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