@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +25 -2
  4. package/dist/connect-session-nyEp02_P.js +375 -0
  5. package/dist/connect-session-nyEp02_P.js.map +1 -0
  6. package/dist/connection.d.ts +31 -0
  7. package/dist/connection.js +60 -0
  8. package/dist/connection.js.map +1 -0
  9. package/dist/core-queries-BPNbcM6k.js +452 -0
  10. package/dist/core-queries-BPNbcM6k.js.map +1 -0
  11. package/dist/document-schema-CPK5xkyO.js +369 -0
  12. package/dist/document-schema-CPK5xkyO.js.map +1 -0
  13. package/dist/drag.d.ts +19 -0
  14. package/dist/drag.js +175 -0
  15. package/dist/drag.js.map +1 -0
  16. package/dist/index.d.ts +876 -0
  17. package/dist/index.js +5711 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/keyboard-links-CVaTtlZg.js +8 -0
  20. package/dist/keyboard-links-CVaTtlZg.js.map +1 -0
  21. package/dist/keyboard.d.ts +40 -0
  22. package/dist/keyboard.js +342 -0
  23. package/dist/keyboard.js.map +1 -0
  24. package/dist/minimap.d.ts +26 -0
  25. package/dist/minimap.js +206 -0
  26. package/dist/minimap.js.map +1 -0
  27. package/dist/node-moves-DyWe-4dj.js +36 -0
  28. package/dist/node-moves-DyWe-4dj.js.map +1 -0
  29. package/dist/part-attributes-DuBltA__.js +71 -0
  30. package/dist/part-attributes-DuBltA__.js.map +1 -0
  31. package/dist/path-format-2OU7Eiyy.js +43 -0
  32. package/dist/path-format-2OU7Eiyy.js.map +1 -0
  33. package/dist/reconnection.d.ts +15 -0
  34. package/dist/reconnection.js +138 -0
  35. package/dist/reconnection.js.map +1 -0
  36. package/dist/rect-CmoREaR6.js +92 -0
  37. package/dist/rect-CmoREaR6.js.map +1 -0
  38. package/dist/resize.d.ts +33 -0
  39. package/dist/resize.js +316 -0
  40. package/dist/resize.js.map +1 -0
  41. package/dist/rules-DLOMrPBG.js +102 -0
  42. package/dist/rules-DLOMrPBG.js.map +1 -0
  43. package/dist/selection.d.ts +38 -0
  44. package/dist/selection.js +392 -0
  45. package/dist/selection.js.map +1 -0
  46. package/dist/subflows.d.ts +9 -0
  47. package/dist/subflows.js +237 -0
  48. package/dist/subflows.js.map +1 -0
  49. package/dist/types-CLHcZVCb.d.ts +2660 -0
  50. package/dist/viewport-math-B-9Pn2kN.js +69 -0
  51. package/dist/viewport-math-B-9Pn2kN.js.map +1 -0
  52. package/package.json +94 -3
@@ -0,0 +1,8 @@
1
+ // src/features/keyboard-links.ts
2
+ /** The keyboard links of an engine (one object per engine, made by the first feature that asks). */
3
+ function keyboardLinks(host) {
4
+ return host.shared("keyboard-links", () => ({}));
5
+ }
6
+ export { keyboardLinks as t };
7
+
8
+ //# sourceMappingURL=keyboard-links-CVaTtlZg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard-links-CVaTtlZg.js","names":[],"sources":["../src/features/keyboard-links.ts"],"sourcesContent":["// What `keyboard()` reaches of the other features of one engine, through the host's shared slot\n// (features talk only through keys and the host, never by importing each other): `connection()`\n// offers keyboard connections, `resize()` keyboard resize steps. Each fills its link when its\n// engine side is made; `keyboard()` reads them when a key or a part's attributes ask, so the order\n// of `features` does not matter, and a link left empty means its feature is not installed.\nimport type { XY } from \"../document/types\";\nimport type { FlowHandle } from \"../engine/adapter\";\nimport type { FeatureEngineHost } from \"./types\";\n\n/** A connection drawn with the keyboard, from a handle to the targets the model accepts. */\nexport interface KeyboardConnection {\n /**\n * points at the next (`1`) or the previous (`-1`) target, round the list, its targets read\n * again first\n */\n next(by: 1 | -1): void;\n /** the target pointed at, or nothing */\n target(): FlowHandle | undefined;\n /** adds the edge to the target pointed at (`edge.add`) and ends; without one it cancels */\n connect(): void;\n /** ends with no edge */\n cancel(): void;\n /** whether it has not ended yet */\n open(): boolean;\n}\n\n/** What `connection()` offers the keyboard. */\nexport interface KeyboardConnector {\n /** starts a connection from a focused handle, or nothing when it may not start one */\n start(from: FlowHandle): KeyboardConnection | undefined;\n}\n\n/** What `resize()` offers the keyboard. */\nexport interface KeyboardResizer {\n /**\n * moves the sides a resize handle at `position` moves by `delta` flow units, within the\n * resizer's limits, in one step (`node.resize`); `direction` is the handle's own, over its\n * resizer's; whether the key was the resizer's\n */\n step(\n nodeId: string,\n position: string,\n delta: XY,\n direction?: \"horizontal\" | \"vertical\" | undefined,\n ): boolean;\n}\n\n/** The links of one engine. */\nexport interface KeyboardLinks {\n connect?: KeyboardConnector | undefined;\n resize?: KeyboardResizer | undefined;\n}\n\n/** The keyboard links of an engine (one object per engine, made by the first feature that asks). */\nexport function keyboardLinks(host: FeatureEngineHost): KeyboardLinks {\n return host.shared<KeyboardLinks>(\"keyboard-links\", () => ({}));\n}\n"],"mappings":";;AAsDA,SAAgB,cAAc,MAAwC;CAClE,OAAO,KAAK,OAAsB,yBAAyB,CAAC,EAAE;AAClE"}
@@ -0,0 +1,40 @@
1
+ import { er as FlowEdge, f as FlowFeature, rr as FlowNode } from "./types-CLHcZVCb.js";
2
+ /** What a `beforeDelete` decides: all (`true`), none (`false`), or only some of them. */
3
+ type DeleteDecision = boolean | {
4
+ readonly nodes: readonly FlowNode[];
5
+ readonly edges: readonly FlowEdge[];
6
+ };
7
+ /**
8
+ * Asked before a delete key removes anything, with the nodes and edges it would remove (a removed
9
+ * node's edges among them): its answer, or a promise of it, decides what goes.
10
+ */
11
+ type BeforeDelete = (nodes: readonly FlowNode[], edges: readonly FlowEdge[]) => DeleteDecision | Promise<DeleteDecision>;
12
+ /** Options of {@link keyboard}: read by its engine side. */
13
+ interface KeyboardOptions {
14
+ /**
15
+ * how far an arrow moves a node (or, with `resize()`, a focused resize handle's sides), in
16
+ * flow units; default 5
17
+ */
18
+ readonly step: number;
19
+ /** how far Shift with an arrow moves it (or the sides); default 20 */
20
+ readonly fastStep: number;
21
+ /**
22
+ * the keys that remove the selection (`KeyboardEvent.key` or `.code`); default
23
+ * `["Delete", "Backspace"]`; `[]` for none
24
+ */
25
+ readonly deleteKeys: readonly string[];
26
+ /** a node that takes focus is panned into view when it is not wholly in it; default true */
27
+ readonly panOnFocus: boolean;
28
+ /**
29
+ * asked before a delete key removes anything: `true` removes all, `false` nothing, a
30
+ * `{ nodes, edges }` subset only those; a promise waits (the key is taken at once), and when it
31
+ * settles only what is still there goes; default none: everything goes
32
+ */
33
+ readonly beforeDelete: BeforeDelete | undefined;
34
+ }
35
+ /** The keyboard feature, as `keyboard()` makes it. */
36
+ type KeyboardFeature = FlowFeature<"keyboard", KeyboardOptions>;
37
+ /** Keyboard access to nodes and edges: `features: [keyboard()]` (`@fragiola/flow/keyboard`). */
38
+ export declare function keyboard(options?: Partial<KeyboardOptions>): KeyboardFeature;
39
+ export type { BeforeDelete, DeleteDecision, KeyboardFeature, KeyboardOptions };
40
+ //# sourceMappingURL=keyboard.d.ts.map
@@ -0,0 +1,342 @@
1
+ import { n as movedRoots, r as runMoves } from "./node-moves-DyWe-4dj.js";
2
+ import { t as keyboardLinks } from "./keyboard-links-CVaTtlZg.js";
3
+ import { o as viewRect, t as centeredOn } from "./viewport-math-B-9Pn2kN.js";
4
+ // src/keyboard/keyboard-engine.ts
5
+ const ARROWS = {
6
+ ArrowUp: {
7
+ x: 0,
8
+ y: -1
9
+ },
10
+ ArrowDown: {
11
+ x: 0,
12
+ y: 1
13
+ },
14
+ ArrowLeft: {
15
+ x: -1,
16
+ y: 0
17
+ },
18
+ ArrowRight: {
19
+ x: 1,
20
+ y: 0
21
+ }
22
+ };
23
+ /** The keys that walk a keyboard connection's targets: the next one, or the previous one. */
24
+ const TARGET_STEPS = {
25
+ ArrowRight: 1,
26
+ ArrowDown: 1,
27
+ ArrowLeft: -1,
28
+ ArrowUp: -1
29
+ };
30
+ /** Enter or Space, without a modifier (Shift aside), not a held key's repeat. */
31
+ function activates(event) {
32
+ return (event.key === "Enter" || event.key === " ") && !event.repeat && !event.altKey && !event.ctrlKey && !event.metaKey;
33
+ }
34
+ /** Whether a key event comes from inside `element` (the handle a connection started at). */
35
+ function from(element, event) {
36
+ const target = event.target;
37
+ return element === void 0 || typeof target === "object" && target !== null && element.contains(target);
38
+ }
39
+ /**
40
+ * The gesture of a keyboard connection, given to the engine (it goes on without a press). Only the
41
+ * keys of its source handle are its own: Tab and Shift + Tab or the arrows walk its targets, Enter
42
+ * or Space connect, Escape (the engine's) cancels, as a press anywhere does. It also cancels when
43
+ * focus leaves the handle (a field clicked, a toolbar button) and when its node goes away (a
44
+ * delete key removed it), so a key elsewhere is never taken. Each step hands its target's node to
45
+ * `show` (panned into view, as a focused node is).
46
+ */
47
+ function connectionGesture(connection, source, nodeId, model, show) {
48
+ const stops = [];
49
+ const release = () => {
50
+ for (const stop of stops.splice(0)) stop();
51
+ };
52
+ const cancel = () => {
53
+ release();
54
+ connection.cancel();
55
+ };
56
+ const step = (by) => {
57
+ connection.next(by);
58
+ show(connection.target()?.nodeId);
59
+ return true;
60
+ };
61
+ if (source) {
62
+ const left = () => cancel();
63
+ source.addEventListener("focusout", left);
64
+ stops.push(() => source.removeEventListener("focusout", left));
65
+ }
66
+ stops.push(model.subscribe(() => {
67
+ if (!model.get("node-by", { id: nodeId })) cancel();
68
+ }));
69
+ return {
70
+ kind: "connect",
71
+ move: () => {},
72
+ end: cancel,
73
+ cancel,
74
+ active: () => connection.open(),
75
+ keydown: (event) => {
76
+ if (!from(source, event)) return false;
77
+ if (event.altKey || event.ctrlKey || event.metaKey) return false;
78
+ if (event.key === "Tab") return step(event.shiftKey ? -1 : 1);
79
+ const by = TARGET_STEPS[event.key];
80
+ if (by !== void 0) return step(by);
81
+ if (activates(event)) {
82
+ release();
83
+ connection.connect();
84
+ return true;
85
+ }
86
+ if (event.key === "Enter" || event.key === " ") return event.repeat;
87
+ return false;
88
+ }
89
+ };
90
+ }
91
+ /** The engine side of `keyboard()`. */
92
+ function keyboardEngine(host, options) {
93
+ const { model } = host;
94
+ const links = keyboardLinks(host);
95
+ /** a `beforeDelete` promise is pending: another delete key waits for it */
96
+ let deciding = false;
97
+ let destroyed = false;
98
+ const move = (direction, fast, focused) => {
99
+ const selected = (model.get("selected-nodes") ?? []).map((node) => node.id);
100
+ const ids = selected.length > 0 ? selected : focused === void 0 ? [] : [focused];
101
+ const nodeIds = movedRoots(model, ids.filter((nodeId) => model.is("node-draggable", { nodeId })));
102
+ if (nodeIds.length === 0) return false;
103
+ const distance = fast ? options.fastStep : options.step;
104
+ const moves = nodeIds.flatMap((nodeId) => {
105
+ const node = model.get("node-by", { id: nodeId });
106
+ if (!node) return [];
107
+ return [{
108
+ nodeId,
109
+ position: host.keepInExtent(nodeId, {
110
+ x: node.position.x + direction.x * distance,
111
+ y: node.position.y + direction.y * distance
112
+ })
113
+ }];
114
+ });
115
+ if (!runMoves(model, moves, false)) return false;
116
+ host.emit({
117
+ type: "nodes-move",
118
+ nodeIds,
119
+ source: "keyboard"
120
+ });
121
+ return true;
122
+ };
123
+ /** Pans a node not wholly in view to its centre (`panOnFocus`), the zoom kept. */
124
+ const show = (nodeId) => {
125
+ if (!options.panOnFocus || nodeId === void 0) return;
126
+ const rect = host.measured(nodeId) ? host.nodeRect(nodeId) : void 0;
127
+ const size = host.rootSize();
128
+ if (!rect || size.width <= 0 || size.height <= 0) return;
129
+ const viewport = host.viewport();
130
+ const view = viewRect(viewport, size);
131
+ if (!(rect.x >= view.x && rect.y >= view.y && rect.x + rect.width <= view.x + view.width && rect.y + rect.height <= view.y + view.height)) host.setViewport(centeredOn({
132
+ x: rect.x + rect.width / 2,
133
+ y: rect.y + rect.height / 2
134
+ }, viewport.zoom, size));
135
+ };
136
+ const nodeOf = (id) => model.get("node-by", { id });
137
+ const edgeOf = (id) => model.get("edge-by", { id });
138
+ /** What a delete key would remove now: the selection's, or the focused node's or edge's. */
139
+ const toRemove = (nodeId, edgeId) => {
140
+ const removed = (result) => {
141
+ if (!result.ok) return void 0;
142
+ const { removedNodeIds, removedEdgeIds } = result.value;
143
+ return {
144
+ nodeIds: removedNodeIds,
145
+ edgeIds: removedEdgeIds
146
+ };
147
+ };
148
+ if (model.can("selection.remove", {})) return removed(model.check("selection.remove", {}));
149
+ if (nodeId !== void 0) return removed(model.check("node.remove", { nodeId }));
150
+ if (edgeId !== void 0 && model.can("edge.remove", { edgeId })) return {
151
+ nodeIds: [],
152
+ edgeIds: [edgeId]
153
+ };
154
+ };
155
+ /**
156
+ * Removes the nodes and edges still there among those given, in one step (a node takes its
157
+ * edges and children; one carried by a removed parent is not removed twice), and tells it.
158
+ */
159
+ const removeIds = (nodeIds, edgeIds) => {
160
+ const nodes = nodeIds.filter((id) => nodeOf(id) !== void 0 && model.is("node-deletable", { nodeId: id }));
161
+ const roots = movedRoots(model, nodes);
162
+ const gone = new Set(nodes);
163
+ const commands = [...edgeIds.filter((id) => {
164
+ const edge = edgeOf(id);
165
+ return edge !== void 0 && !gone.has(edge.source) && !gone.has(edge.target) && model.is("edge-deletable", { edgeId: id });
166
+ }).map((id) => ({
167
+ command: "edge.remove",
168
+ payload: { edgeId: id }
169
+ })), ...roots.map((id) => ({
170
+ command: "node.remove",
171
+ payload: { nodeId: id }
172
+ }))];
173
+ if (commands.length === 0) return false;
174
+ const nodesBefore = model.get("all-nodes");
175
+ const edgesBefore = model.get("all-edges");
176
+ const [only] = commands;
177
+ if (!(commands.length === 1 && only ? model.run(only.command, only.payload) : model.run("batch", { commands })).ok) return false;
178
+ const removedNodeIds = nodesBefore.filter((node) => !nodeOf(node.id)).map((node) => node.id);
179
+ const removedEdgeIds = edgesBefore.filter((edge) => !edgeOf(edge.id)).map((edge) => edge.id);
180
+ host.emit({
181
+ type: "remove",
182
+ nodeIds: removedNodeIds,
183
+ edgeIds: removedEdgeIds
184
+ });
185
+ return true;
186
+ };
187
+ /** What a `beforeDelete` answer keeps of the nodes and edges it was asked about. */
188
+ const decided = (decision, asked) => {
189
+ if (decision === true) return asked;
190
+ if (decision === false || typeof decision !== "object") return {
191
+ nodeIds: [],
192
+ edgeIds: []
193
+ };
194
+ const nodes = new Set((decision.nodes ?? []).map((node) => node?.id));
195
+ const edges = new Set((decision.edges ?? []).map((edge) => edge?.id));
196
+ return {
197
+ nodeIds: asked.nodeIds.filter((id) => nodes.has(id)),
198
+ edgeIds: asked.edgeIds.filter((id) => edges.has(id))
199
+ };
200
+ };
201
+ /** A delete key with a `beforeDelete`: asked first, and waited for when it answers later. */
202
+ const removeAsked = (nodeId, edgeId) => {
203
+ const before = options.beforeDelete;
204
+ if (!before) return false;
205
+ if (deciding) return true;
206
+ const asked = toRemove(nodeId, edgeId);
207
+ if (!asked || asked.nodeIds.length + asked.edgeIds.length === 0) return false;
208
+ const answer = before(asked.nodeIds.flatMap((id) => nodeOf(id) ?? []), asked.edgeIds.flatMap((id) => edgeOf(id) ?? []));
209
+ if (typeof answer === "object" && answer !== null && typeof answer.then === "function") {
210
+ deciding = true;
211
+ answer.then((decision) => {
212
+ deciding = false;
213
+ if (destroyed || !host.interactive()) return;
214
+ const kept = decided(decision, asked);
215
+ removeIds(kept.nodeIds, kept.edgeIds);
216
+ }, () => {
217
+ deciding = false;
218
+ });
219
+ return true;
220
+ }
221
+ const kept = decided(answer, asked);
222
+ removeIds(kept.nodeIds, kept.edgeIds);
223
+ return true;
224
+ };
225
+ const remove = (nodeId, edgeId) => {
226
+ if (options.beforeDelete) return removeAsked(nodeId, edgeId);
227
+ if (model.can("selection.remove", {})) {
228
+ const result = model.run("selection.remove", {});
229
+ if (!result.ok) return false;
230
+ const { removedNodeIds, removedEdgeIds } = result.value;
231
+ if (removedNodeIds.length + removedEdgeIds.length === 0) return false;
232
+ host.emit({
233
+ type: "remove",
234
+ nodeIds: removedNodeIds,
235
+ edgeIds: removedEdgeIds
236
+ });
237
+ return true;
238
+ }
239
+ if (nodeId !== void 0) {
240
+ const result = model.run("node.remove", { nodeId });
241
+ if (!result.ok) return false;
242
+ const { removedNodeIds, removedEdgeIds } = result.value;
243
+ host.emit({
244
+ type: "remove",
245
+ nodeIds: removedNodeIds,
246
+ edgeIds: removedEdgeIds
247
+ });
248
+ return true;
249
+ }
250
+ if (edgeId !== void 0 && model.run("edge.remove", { edgeId }).ok) {
251
+ host.emit({
252
+ type: "remove",
253
+ nodeIds: [],
254
+ edgeIds: [edgeId]
255
+ });
256
+ return true;
257
+ }
258
+ return false;
259
+ };
260
+ return {
261
+ is: {
262
+ "node-focusable": (payload) => {
263
+ const node = nodeOf(String(payload.nodeId));
264
+ return node !== void 0 && node.hidden !== true && node.focusable !== false && host.focusable("node");
265
+ },
266
+ "edge-focusable": (payload) => {
267
+ const edge = edgeOf(String(payload.edgeId));
268
+ return edge !== void 0 && edge.hidden !== true && edge.focusable !== false && host.focusable("edge");
269
+ }
270
+ },
271
+ keydown: (event, target) => {
272
+ if (!host.interactive()) return false;
273
+ if (target.kind === "handle" && target.handle !== void 0 && links.connect !== void 0 && activates(event)) {
274
+ const connection = links.connect.start(target.handle);
275
+ if (!connection) return false;
276
+ show(connection.target()?.nodeId);
277
+ return connectionGesture(connection, target.element, target.handle.nodeId, model, show);
278
+ }
279
+ const nodeId = target.kind === "node" ? target.nodeId : void 0;
280
+ const edgeId = target.kind === "edge" ? target.edgeId : void 0;
281
+ const onEntity = nodeId !== void 0 || edgeId !== void 0;
282
+ const direction = ARROWS[event.key];
283
+ if (direction && target.kind === "resize-handle" && target.nodeId !== void 0 && target.position !== void 0 && links.resize !== void 0) {
284
+ if (event.altKey || event.ctrlKey || event.metaKey) return false;
285
+ const distance = event.shiftKey ? options.fastStep : options.step;
286
+ return links.resize.step(target.nodeId, target.position, {
287
+ x: direction.x * distance,
288
+ y: direction.y * distance
289
+ }, target.direction);
290
+ }
291
+ if (direction) {
292
+ if (event.altKey || event.ctrlKey || event.metaKey) return false;
293
+ if (!host.allows("drag")) return false;
294
+ return move(direction, event.shiftKey, nodeId);
295
+ }
296
+ if (options.deleteKeys.some((name) => name === event.key || name === event.code)) return remove(nodeId, edgeId);
297
+ if ((event.key === "Enter" || event.key === " ") && onEntity && host.allows("select")) {
298
+ const mode = event.shiftKey || event.ctrlKey || event.metaKey ? "toggle" : "replace";
299
+ return model.run("selection.set", nodeId !== void 0 ? {
300
+ nodeIds: [nodeId],
301
+ mode
302
+ } : {
303
+ edgeIds: [edgeId],
304
+ mode
305
+ }).ok;
306
+ }
307
+ if (event.key === "Escape") return (model.get("selected-nodes")?.length ?? 0) + (model.get("selected-edges")?.length ?? 0) > 0 && model.run("selection.clear", {}).ok;
308
+ return false;
309
+ },
310
+ attributes: (part, payload, into) => {
311
+ if (part === "handle" && links.connect !== void 0) {
312
+ const nodeId = payload.nodeId;
313
+ if (payload.connectable !== false && payload.connectableStart !== false && host.allows("connect") && typeof nodeId === "string" && model.is("node-connectable", { nodeId })) into.tabindex = "0";
314
+ } else if (part === "resize-handle" && links.resize !== void 0 || part === "nodes-selection") into.tabindex = "0";
315
+ },
316
+ focus: (target) => {
317
+ if (target.kind === "node") show(target.nodeId);
318
+ },
319
+ destroy: () => {
320
+ destroyed = true;
321
+ }
322
+ };
323
+ }
324
+ // src/keyboard/keyboard.ts
325
+ /** Keyboard access to nodes and edges: `features: [keyboard()]` (`@fragiola/flow/keyboard`). */
326
+ function keyboard(options = {}) {
327
+ const resolved = Object.freeze({
328
+ step: options.step ?? 5,
329
+ fastStep: options.fastStep ?? 20,
330
+ deleteKeys: Object.freeze([...options.deleteKeys ?? ["Delete", "Backspace"]]),
331
+ panOnFocus: options.panOnFocus ?? true,
332
+ beforeDelete: options.beforeDelete
333
+ });
334
+ return Object.freeze({
335
+ name: "keyboard",
336
+ options: resolved,
337
+ engine: (host) => keyboardEngine(host, resolved)
338
+ });
339
+ }
340
+ export { keyboard };
341
+
342
+ //# sourceMappingURL=keyboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.js","names":[],"sources":["../src/keyboard/keyboard-engine.ts","../src/keyboard/keyboard.ts"],"sourcesContent":["// The keyboard feature's engine side: nodes and edges take DOM focus (`node-focusable`,\n// `edge-focusable`: the adapter sets `tabindex=\"0\"`, so Tab walks them in drawing order) and a node\n// that takes focus is panned into view. On a focused node or edge:\n// - the arrows move the selected nodes (or the focused node) by `step` flow units, `fastStep`\n// with Shift, kept inside their extents (`node.move`, a `batch` for several: one step);\n// - Enter and Space select it (with Ctrl, ⌘ or Shift they toggle it);\n// - the delete keys (`deleteKeys`: Delete and Backspace by default) remove the selection\n// (`selection.remove`), or without `selection()` the focused node or edge; a `beforeDelete`\n// is asked first and may narrow it, refuse it, or answer later (a promise: what is still there\n// when it settles goes, in one step);\n// - Escape clears the selection (a gesture under way is cancelled by the engine first).\n// With `connection()`, handles take focus too (`tabindex` in their attributes) and Enter or Space\n// on one starts a keyboard connection (Tab, Shift + Tab or the arrows walk the targets the model\n// accepts, nearest first, read again on each step, the node of the one pointed at panned into view\n// as a focused node is; Enter or Space connect; Escape cancels); with `resize()`, resize handles\n// take focus and the arrows move their sides (#40: a handle's own direction over its resizer's).\n// The selection's rectangle (`nodes-selection`) takes focus as well, and its keys are a focused\n// selected node's: the arrows move the selection, the delete keys remove it, Escape clears it. Both are reached through the host's keyboard links,\n// never by importing those features.\nimport type { BatchEntry } from \"../commands/types\";\nimport type { FlowEdge, FlowNode, XY } from \"../document/types\";\nimport { movedRoots, runMoves } from \"../engine/node-moves\";\nimport {\n type KeyboardConnection,\n keyboardLinks,\n} from \"../features/keyboard-links\";\nimport type {\n FeatureEngine,\n FeatureEngineHost,\n FeatureGesture,\n} from \"../features/types\";\nimport { centeredOn, viewRect } from \"../geometry/viewport-math\";\nimport type { DeleteDecision, KeyboardOptions } from \"./keyboard\";\n\nconst ARROWS: Readonly<Record<string, XY>> = {\n ArrowUp: { x: 0, y: -1 },\n ArrowDown: { x: 0, y: 1 },\n ArrowLeft: { x: -1, y: 0 },\n ArrowRight: { x: 1, y: 0 },\n};\n\n/** The keys that walk a keyboard connection's targets: the next one, or the previous one. */\nconst TARGET_STEPS: Readonly<Record<string, 1 | -1>> = {\n ArrowRight: 1,\n ArrowDown: 1,\n ArrowLeft: -1,\n ArrowUp: -1,\n};\n\n/** Enter or Space, without a modifier (Shift aside), not a held key's repeat. */\nfunction activates(event: KeyboardEvent): boolean {\n return (\n (event.key === \"Enter\" || event.key === \" \") &&\n !event.repeat &&\n !event.altKey &&\n !event.ctrlKey &&\n !event.metaKey\n );\n}\n\n/** Whether a key event comes from inside `element` (the handle a connection started at). */\nfunction from(element: Element | undefined, event: KeyboardEvent): boolean {\n const target = event.target;\n return (\n element === undefined ||\n (typeof target === \"object\" &&\n target !== null &&\n element.contains(target as Node))\n );\n}\n\n/**\n * The gesture of a keyboard connection, given to the engine (it goes on without a press). Only the\n * keys of its source handle are its own: Tab and Shift + Tab or the arrows walk its targets, Enter\n * or Space connect, Escape (the engine's) cancels, as a press anywhere does. It also cancels when\n * focus leaves the handle (a field clicked, a toolbar button) and when its node goes away (a\n * delete key removed it), so a key elsewhere is never taken. Each step hands its target's node to\n * `show` (panned into view, as a focused node is).\n */\nfunction connectionGesture(\n connection: KeyboardConnection,\n source: Element | undefined,\n nodeId: string,\n model: FeatureEngineHost[\"model\"],\n show: (nodeId: string | undefined) => void,\n): FeatureGesture {\n const stops: (() => void)[] = [];\n const release = () => {\n for (const stop of stops.splice(0)) stop();\n };\n const cancel = () => {\n release();\n connection.cancel();\n };\n const step = (by: 1 | -1) => {\n connection.next(by);\n show(connection.target()?.nodeId);\n return true;\n };\n if (source) {\n const left = () => cancel();\n source.addEventListener(\"focusout\", left);\n stops.push(() => source.removeEventListener(\"focusout\", left));\n }\n stops.push(\n model.subscribe(() => {\n if (!model.get(\"node-by\", { id: nodeId })) cancel();\n }),\n );\n return {\n kind: \"connect\",\n move: () => {},\n end: cancel,\n cancel,\n active: () => connection.open(),\n keydown: (event) => {\n if (!from(source, event)) return false;\n if (event.altKey || event.ctrlKey || event.metaKey) return false;\n if (event.key === \"Tab\") return step(event.shiftKey ? -1 : 1);\n const by = TARGET_STEPS[event.key];\n if (by !== undefined) return step(by);\n if (activates(event)) {\n release();\n connection.connect();\n return true;\n }\n // a held Enter's repeats neither connect nor reach the page\n if (event.key === \"Enter\" || event.key === \" \") return event.repeat;\n return false;\n },\n };\n}\n\n/** The engine side of `keyboard()`. */\nexport function keyboardEngine(\n host: FeatureEngineHost,\n options: KeyboardOptions,\n): FeatureEngine {\n const { model } = host;\n const links = keyboardLinks(host);\n /** a `beforeDelete` promise is pending: another delete key waits for it */\n let deciding = false;\n let destroyed = false;\n\n const move = (\n direction: XY,\n fast: boolean,\n focused: string | undefined,\n ): boolean => {\n const selected = (\n (model.get(\"selected-nodes\") as readonly FlowNode[] | undefined) ??\n []\n ).map((node) => node.id);\n const ids =\n selected.length > 0\n ? selected\n : focused === undefined\n ? []\n : [focused];\n const nodeIds = movedRoots(\n model,\n ids.filter((nodeId) => model.is(\"node-draggable\", { nodeId })),\n );\n if (nodeIds.length === 0) return false;\n const distance = fast ? options.fastStep : options.step;\n const moves = nodeIds.flatMap((nodeId) => {\n const node = model.get(\"node-by\", { id: nodeId }) as\n | FlowNode\n | undefined;\n if (!node) return [];\n return [\n {\n nodeId,\n position: host.keepInExtent(nodeId, {\n x: node.position.x + direction.x * distance,\n y: node.position.y + direction.y * distance,\n }),\n },\n ];\n });\n if (!runMoves(model, moves, false)) return false;\n host.emit({ type: \"nodes-move\", nodeIds, source: \"keyboard\" });\n return true;\n };\n\n /** Pans a node not wholly in view to its centre (`panOnFocus`), the zoom kept. */\n const show = (nodeId: string | undefined) => {\n if (!options.panOnFocus || nodeId === undefined) return;\n const rect = host.measured(nodeId) ? host.nodeRect(nodeId) : undefined;\n const size = host.rootSize();\n if (!rect || size.width <= 0 || size.height <= 0) return;\n const viewport = host.viewport();\n const view = viewRect(viewport, size);\n const inside =\n rect.x >= view.x &&\n rect.y >= view.y &&\n rect.x + rect.width <= view.x + view.width &&\n rect.y + rect.height <= view.y + view.height;\n if (!inside) {\n host.setViewport(\n centeredOn(\n {\n x: rect.x + rect.width / 2,\n y: rect.y + rect.height / 2,\n },\n viewport.zoom,\n size,\n ),\n );\n }\n };\n\n const nodeOf = (id: string) =>\n model.get(\"node-by\", { id }) as FlowNode | undefined;\n const edgeOf = (id: string) =>\n model.get(\"edge-by\", { id }) as FlowEdge | undefined;\n\n /** What a delete key would remove now: the selection's, or the focused node's or edge's. */\n const toRemove = (\n nodeId: string | undefined,\n edgeId: string | undefined,\n ): { nodeIds: string[]; edgeIds: string[] } | undefined => {\n const removed = (result: { ok: boolean; value?: unknown }) => {\n if (!result.ok) return undefined;\n const { removedNodeIds, removedEdgeIds } = result.value as {\n removedNodeIds: string[];\n removedEdgeIds: string[];\n };\n return { nodeIds: removedNodeIds, edgeIds: removedEdgeIds };\n };\n if (model.can(\"selection.remove\", {}))\n return removed(model.check(\"selection.remove\", {}));\n if (nodeId !== undefined)\n return removed(model.check(\"node.remove\", { nodeId }));\n if (edgeId !== undefined && model.can(\"edge.remove\", { edgeId }))\n return { nodeIds: [], edgeIds: [edgeId] };\n return undefined;\n };\n\n /**\n * Removes the nodes and edges still there among those given, in one step (a node takes its\n * edges and children; one carried by a removed parent is not removed twice), and tells it.\n */\n const removeIds = (\n nodeIds: readonly string[],\n edgeIds: readonly string[],\n ): boolean => {\n const nodes = nodeIds.filter(\n (id) =>\n nodeOf(id) !== undefined &&\n model.is(\"node-deletable\", { nodeId: id }),\n );\n const roots = movedRoots(model, nodes);\n const gone = new Set(nodes);\n const edges = edgeIds.filter((id) => {\n const edge = edgeOf(id);\n return (\n edge !== undefined &&\n !gone.has(edge.source) &&\n !gone.has(edge.target) &&\n model.is(\"edge-deletable\", { edgeId: id })\n );\n });\n const commands: BatchEntry[] = [\n ...edges.map((id) => ({\n command: \"edge.remove\" as const,\n payload: { edgeId: id },\n })),\n ...roots.map((id) => ({\n command: \"node.remove\" as const,\n payload: { nodeId: id },\n })),\n ];\n if (commands.length === 0) return false;\n const nodesBefore = model.get(\"all-nodes\") as readonly FlowNode[];\n const edgesBefore = model.get(\"all-edges\") as readonly FlowEdge[];\n const [only] = commands;\n const result =\n commands.length === 1 && only\n ? model.run(only.command, only.payload as object)\n : model.run(\"batch\", { commands });\n if (!result.ok) return false;\n const removedNodeIds = nodesBefore\n .filter((node) => !nodeOf(node.id))\n .map((node) => node.id);\n const removedEdgeIds = edgesBefore\n .filter((edge) => !edgeOf(edge.id))\n .map((edge) => edge.id);\n host.emit({\n type: \"remove\",\n nodeIds: removedNodeIds,\n edgeIds: removedEdgeIds,\n });\n return true;\n };\n\n /** What a `beforeDelete` answer keeps of the nodes and edges it was asked about. */\n const decided = (\n decision: DeleteDecision,\n asked: { nodeIds: string[]; edgeIds: string[] },\n ): { nodeIds: string[]; edgeIds: string[] } => {\n if (decision === true) return asked;\n if (decision === false || typeof decision !== \"object\")\n return { nodeIds: [], edgeIds: [] };\n // a subset only: what it names that was asked about\n const nodes = new Set((decision.nodes ?? []).map((node) => node?.id));\n const edges = new Set((decision.edges ?? []).map((edge) => edge?.id));\n return {\n nodeIds: asked.nodeIds.filter((id) => nodes.has(id)),\n edgeIds: asked.edgeIds.filter((id) => edges.has(id)),\n };\n };\n\n /** A delete key with a `beforeDelete`: asked first, and waited for when it answers later. */\n const removeAsked = (\n nodeId: string | undefined,\n edgeId: string | undefined,\n ): boolean => {\n const before = options.beforeDelete;\n if (!before) return false;\n // a decision under way: this key waits for it (and is taken)\n if (deciding) return true;\n const asked = toRemove(nodeId, edgeId);\n if (!asked || asked.nodeIds.length + asked.edgeIds.length === 0)\n return false;\n const answer = before(\n asked.nodeIds.flatMap((id) => nodeOf(id) ?? []),\n asked.edgeIds.flatMap((id) => edgeOf(id) ?? []),\n );\n if (\n typeof answer === \"object\" &&\n answer !== null &&\n typeof (answer as Promise<unknown>).then === \"function\"\n ) {\n deciding = true;\n (answer as Promise<DeleteDecision>).then(\n (decision) => {\n deciding = false;\n // the flow locked or gone meanwhile: nothing goes\n if (destroyed || !host.interactive()) return;\n const kept = decided(decision, asked);\n removeIds(kept.nodeIds, kept.edgeIds);\n },\n () => {\n deciding = false;\n },\n );\n return true;\n }\n const kept = decided(answer as DeleteDecision, asked);\n removeIds(kept.nodeIds, kept.edgeIds);\n return true;\n };\n\n const remove = (\n nodeId: string | undefined,\n edgeId: string | undefined,\n ): boolean => {\n if (options.beforeDelete) return removeAsked(nodeId, edgeId);\n if (model.can(\"selection.remove\", {})) {\n const result = model.run(\"selection.remove\", {});\n if (!result.ok) return false;\n const { removedNodeIds, removedEdgeIds } = result.value as {\n removedNodeIds: string[];\n removedEdgeIds: string[];\n };\n if (removedNodeIds.length + removedEdgeIds.length === 0)\n return false;\n host.emit({\n type: \"remove\",\n nodeIds: removedNodeIds,\n edgeIds: removedEdgeIds,\n });\n return true;\n }\n if (nodeId !== undefined) {\n const result = model.run(\"node.remove\", { nodeId });\n if (!result.ok) return false;\n const { removedNodeIds, removedEdgeIds } = result.value as {\n removedNodeIds: string[];\n removedEdgeIds: string[];\n };\n host.emit({\n type: \"remove\",\n nodeIds: removedNodeIds,\n edgeIds: removedEdgeIds,\n });\n return true;\n }\n if (edgeId !== undefined && model.run(\"edge.remove\", { edgeId }).ok) {\n host.emit({ type: \"remove\", nodeIds: [], edgeIds: [edgeId] });\n return true;\n }\n return false;\n };\n\n return {\n is: {\n \"node-focusable\": (payload) => {\n const node = nodeOf(\n String((payload as { nodeId?: unknown }).nodeId),\n );\n return (\n node !== undefined &&\n node.hidden !== true &&\n node.focusable !== false &&\n host.focusable(\"node\")\n );\n },\n \"edge-focusable\": (payload) => {\n const edge = edgeOf(\n String((payload as { edgeId?: unknown }).edgeId),\n );\n return (\n edge !== undefined &&\n edge.hidden !== true &&\n edge.focusable !== false &&\n host.focusable(\"edge\")\n );\n },\n },\n keydown: (event, target) => {\n if (!host.interactive()) return false;\n // Enter or Space on a focused handle starts a keyboard connection (`connection()`)\n if (\n target.kind === \"handle\" &&\n target.handle !== undefined &&\n links.connect !== undefined &&\n activates(event)\n ) {\n const connection = links.connect.start(target.handle);\n if (!connection) return false;\n show(connection.target()?.nodeId);\n return connectionGesture(\n connection,\n target.element,\n target.handle.nodeId,\n model,\n show,\n );\n }\n const nodeId = target.kind === \"node\" ? target.nodeId : undefined;\n const edgeId = target.kind === \"edge\" ? target.edgeId : undefined;\n const onEntity = nodeId !== undefined || edgeId !== undefined;\n const direction = ARROWS[event.key];\n // the arrows on a focused resize handle move its sides (`resize()`)\n if (\n direction &&\n target.kind === \"resize-handle\" &&\n target.nodeId !== undefined &&\n target.position !== undefined &&\n links.resize !== undefined\n ) {\n if (event.altKey || event.ctrlKey || event.metaKey)\n return false;\n const distance = event.shiftKey\n ? options.fastStep\n : options.step;\n return links.resize.step(\n target.nodeId,\n target.position,\n {\n x: direction.x * distance,\n y: direction.y * distance,\n },\n target.direction,\n );\n }\n if (direction) {\n if (event.altKey || event.ctrlKey || event.metaKey)\n return false;\n if (!host.allows(\"drag\")) return false;\n return move(direction, event.shiftKey, nodeId);\n }\n if (\n options.deleteKeys.some(\n (name) => name === event.key || name === event.code,\n )\n ) {\n return remove(nodeId, edgeId);\n }\n if (\n (event.key === \"Enter\" || event.key === \" \") &&\n onEntity &&\n host.allows(\"select\")\n ) {\n const mode =\n event.shiftKey || event.ctrlKey || event.metaKey\n ? \"toggle\"\n : \"replace\";\n return model.run(\n \"selection.set\",\n nodeId !== undefined\n ? { nodeIds: [nodeId], mode }\n : { edgeIds: [edgeId as string], mode },\n ).ok;\n }\n if (event.key === \"Escape\") {\n const any =\n ((\n model.get(\"selected-nodes\") as\n | readonly unknown[]\n | undefined\n )?.length ?? 0) +\n ((\n model.get(\"selected-edges\") as\n | readonly unknown[]\n | undefined\n )?.length ?? 0) >\n 0;\n return any && model.run(\"selection.clear\", {}).ok;\n }\n return false;\n },\n attributes: (part, payload, into) => {\n // a handle takes focus only with `connection()` too, a resize handle with `resize()`:\n // an app without them keeps its tab order\n if (part === \"handle\" && links.connect !== undefined) {\n const nodeId = payload.nodeId;\n if (\n payload.connectable !== false &&\n payload.connectableStart !== false &&\n host.allows(\"connect\") &&\n typeof nodeId === \"string\" &&\n model.is(\"node-connectable\", { nodeId })\n ) {\n into.tabindex = \"0\";\n }\n } else if (\n (part === \"resize-handle\" && links.resize !== undefined) ||\n part === \"nodes-selection\"\n ) {\n // the selection's rectangle takes focus too: the arrows move the selection, the\n // delete keys remove it, Escape clears it (a focused selected node's keys)\n into.tabindex = \"0\";\n }\n },\n focus: (target) => {\n if (target.kind === \"node\") show(target.nodeId);\n },\n destroy: () => {\n destroyed = true;\n },\n };\n}\n","// The keyboard feature (D2, `@fragiola/flow/keyboard`): focus moves through nodes and edges, the\n// arrows move the selected nodes (`node.move`), the delete keys (Delete and Backspace by default)\n// remove the selection (`selection.remove`), Escape ends what is under way. Its model side is the core's and the\n// selection's commands; its engine side (`keyboard-engine.ts`) reads `options`.\nimport type { FlowEdge, FlowNode } from \"../document/types\";\nimport type { FlowFeature } from \"../features/types\";\nimport { keyboardEngine } from \"./keyboard-engine\";\n\n/** What a `beforeDelete` decides: all (`true`), none (`false`), or only some of them. */\nexport type DeleteDecision =\n | boolean\n | {\n readonly nodes: readonly FlowNode[];\n readonly edges: readonly FlowEdge[];\n };\n\n/**\n * Asked before a delete key removes anything, with the nodes and edges it would remove (a removed\n * node's edges among them): its answer, or a promise of it, decides what goes.\n */\nexport type BeforeDelete = (\n nodes: readonly FlowNode[],\n edges: readonly FlowEdge[],\n) => DeleteDecision | Promise<DeleteDecision>;\n\n/** Options of {@link keyboard}: read by its engine side. */\nexport interface KeyboardOptions {\n /**\n * how far an arrow moves a node (or, with `resize()`, a focused resize handle's sides), in\n * flow units; default 5\n */\n readonly step: number;\n /** how far Shift with an arrow moves it (or the sides); default 20 */\n readonly fastStep: number;\n /**\n * the keys that remove the selection (`KeyboardEvent.key` or `.code`); default\n * `[\"Delete\", \"Backspace\"]`; `[]` for none\n */\n readonly deleteKeys: readonly string[];\n /** a node that takes focus is panned into view when it is not wholly in it; default true */\n readonly panOnFocus: boolean;\n /**\n * asked before a delete key removes anything: `true` removes all, `false` nothing, a\n * `{ nodes, edges }` subset only those; a promise waits (the key is taken at once), and when it\n * settles only what is still there goes; default none: everything goes\n */\n readonly beforeDelete: BeforeDelete | undefined;\n}\n\n/** The keyboard feature, as `keyboard()` makes it. */\nexport type KeyboardFeature = FlowFeature<\"keyboard\", KeyboardOptions>;\n\n/** Keyboard access to nodes and edges: `features: [keyboard()]` (`@fragiola/flow/keyboard`). */\nexport function keyboard(\n options: Partial<KeyboardOptions> = {},\n): KeyboardFeature {\n const resolved: KeyboardOptions = Object.freeze({\n step: options.step ?? 5,\n fastStep: options.fastStep ?? 20,\n deleteKeys: Object.freeze([\n ...(options.deleteKeys ?? [\"Delete\", \"Backspace\"]),\n ]),\n panOnFocus: options.panOnFocus ?? true,\n beforeDelete: options.beforeDelete,\n });\n return Object.freeze({\n name: \"keyboard\",\n options: resolved,\n engine: (host) => keyboardEngine(host, resolved),\n } satisfies KeyboardFeature);\n}\n"],"mappings":";;;;AAkCA,MAAM,SAAuC;CACzC,SAAS;EAAE,GAAG;EAAG,GAAG;CAAG;CACvB,WAAW;EAAE,GAAG;EAAG,GAAG;CAAE;CACxB,WAAW;EAAE,GAAG;EAAI,GAAG;CAAE;CACzB,YAAY;EAAE,GAAG;EAAG,GAAG;CAAE;AAC7B;;AAGA,MAAM,eAAiD;CACnD,YAAY;CACZ,WAAW;CACX,WAAW;CACX,SAAS;AACb;;AAGA,SAAS,UAAU,OAA+B;CAC9C,QACK,MAAM,QAAQ,WAAW,MAAM,QAAQ,QACxC,CAAC,MAAM,UACP,CAAC,MAAM,UACP,CAAC,MAAM,WACP,CAAC,MAAM;AAEf;;AAGA,SAAS,KAAK,SAA8B,OAA+B;CACvE,MAAM,SAAS,MAAM;CACrB,OACI,YAAY,KAAA,KACX,OAAO,WAAW,YACf,WAAW,QACX,QAAQ,SAAS,MAAc;AAE3C;;;;;;;;;AAUA,SAAS,kBACL,YACA,QACA,QACA,OACA,MACc;CACd,MAAM,QAAwB,CAAC;CAC/B,MAAM,gBAAgB;EAClB,KAAK,MAA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,IACF,SAAS,mBAAmB,MAAM,WAAW,KAAA,KAC9C,SAAS,mBAIT,KAAK,WAAW;EAExB;EACA,QAAQ,WAAW;GACf,IAAI,OAAO,SAAS,QAAQ,KAAK,OAAO,MAAM;EAClD;EACA,eAAe;GACX,YAAY;EAChB;CACJ;AACJ;;;AC3eA,SAAgB,SACZ,UAAoC,CAAC,GACtB;CACf,MAAM,WAA4B,OAAO,OAAO;EAC5C,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,YAAY,OAAO,OAAO,CACtB,GAAI,QAAQ,cAAc,CAAC,UAAU,WAAW,CACpD,CAAC;EACD,YAAY,QAAQ,cAAc;EAClC,cAAc,QAAQ;CAC1B,CAAC;CACD,OAAO,OAAO,OAAO;EACjB,MAAM;EACN,SAAS;EACT,SAAS,SAAS,eAAe,MAAM,QAAQ;CACnD,CAA2B;AAC/B"}
@@ -0,0 +1,26 @@
1
+ import { f as FlowFeature } from "./types-CLHcZVCb.js";
2
+ /** Options of {@link minimap}: read by its engine side. */
3
+ interface MinimapOptions {
4
+ /** whether a press or a drag on the minimap pans the viewport; default true */
5
+ readonly pannable: boolean;
6
+ /** whether the wheel over the minimap zooms the viewport; default true */
7
+ readonly zoomable: boolean;
8
+ /** the share of the minimap's size kept free around the nodes and the view, on every side; default 0.1 */
9
+ readonly padding: number;
10
+ /**
11
+ * whether a drag on the minimap moves the view the other way from the pointer (as grabbing
12
+ * the flow): a press does not centre the view then; default false
13
+ */
14
+ readonly inversePan: boolean;
15
+ /**
16
+ * how fast the wheel over the minimap zooms: 10 is the flow's own wheel, 20 twice as fast;
17
+ * default 10 (also for a value that is not a finite number above 0)
18
+ */
19
+ readonly zoomStep: number;
20
+ }
21
+ /** The minimap feature, as `minimap()` makes it. */
22
+ type MinimapFeature = FlowFeature<"minimap", MinimapOptions>;
23
+ /** A minimap of the flow: `features: [minimap()]` (`@fragiola/flow/minimap`). */
24
+ export declare function minimap(options?: Partial<MinimapOptions>): MinimapFeature;
25
+ export type { MinimapFeature, MinimapOptions };
26
+ //# sourceMappingURL=minimap.d.ts.map