@graphty/graphty-element 2.6.1 → 3.0.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/dist/ai.js +3 -3
- package/dist/catalog.js +53 -54
- package/dist/chunks/{AiManager-4iQpsJW1.js → AiManager-Bhh0rR_p.js} +706 -655
- package/dist/chunks/GraphSession-DPoTaT3b.js +21175 -0
- package/dist/chunks/{GraphtyLogger-B_O67a6c.js → GraphtyLogger-BtcBJQPL.js} +1 -1
- package/dist/chunks/{VoiceInputAdapter-Cc6mHXTI.js → VoiceInputAdapter-CdLsJ_nG.js} +1 -1
- package/dist/chunks/{XRPivotCameraController-BLa89LXn.js → XRPivotCameraController-CiLJ9Gz6.js} +2 -2
- package/dist/chunks/algorithms-qij74zEN.js +6811 -0
- package/dist/chunks/{capability-check-Am2zliFj.js → capability-check-BbgTejS3.js} +1 -1
- package/dist/chunks/definePalette-BYt2Llxs.js +1333 -0
- package/dist/chunks/fields-5uVC1Pll.js +4999 -0
- package/dist/chunks/{format-detection-BHwrAVzW.js → format-detection-FKaDMshR.js} +1 -1
- package/dist/chunks/{index-BkBLbvui.js → index-Cc_6D9hV.js} +6034 -7127
- package/dist/chunks/interpolation-Dk206AhZ.js +105 -0
- package/dist/chunks/paletteRegistry-De3CGdst.js +357 -0
- package/dist/chunks/parse-SVp77JbE.js +669 -0
- package/dist/chunks/{pluginRegistry-Bs8bEkz9.js → pluginRegistry-Ddfl6Mv2.js} +27 -24
- package/dist/chunks/{registry-BdGvyZou.js → registry-CgMqldp4.js} +1 -1
- package/dist/chunks/{DataSource-BL2UzPff.js → sources-BbAJCDIH.js} +279 -108
- package/dist/commands.d.ts +128 -19
- package/dist/commands.js +49 -1
- package/dist/custom-elements.json +1 -1
- package/dist/extend.d.ts +10 -2
- package/dist/extend.js +64 -57
- package/dist/graphty-catalog.json +6 -3
- package/dist/graphty.bundle.js +267177 -240648
- package/dist/graphty.js +84 -78
- package/dist/index.d.ts +4 -0
- package/dist/logging.js +2 -2
- package/dist/schema.js +70 -71
- package/dist/session.d.ts +5 -6
- package/dist/session.js +40 -86
- package/dist/src/Edge.d.ts +31 -67
- package/dist/src/Graph.d.ts +335 -77
- package/dist/src/Node.d.ts +36 -3
- package/dist/src/NodeBehavior.d.ts +28 -0
- package/dist/src/Styles.d.ts +15 -4
- package/dist/src/acceleration/AccelerationController.d.ts +8 -0
- package/dist/src/acceleration/narrow.d.ts +9 -1
- package/dist/src/acceleration/types.d.ts +10 -0
- package/dist/src/ai/AiController.d.ts +12 -0
- package/dist/src/ai/AiManager.d.ts +7 -0
- package/dist/src/ai/commands/AlgorithmCommands.d.ts +1 -1
- package/dist/src/ai/commands/LayoutCommands.d.ts +1 -1
- package/dist/src/ai/commands/StyleCommands.d.ts +1 -1
- package/dist/src/ai/commands/types.d.ts +20 -1
- package/dist/src/algorithms/Algorithm.d.ts +21 -4
- package/dist/src/algorithms/BFSAlgorithm.d.ts +0 -9
- package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +0 -14
- package/dist/src/algorithms/DFSAlgorithm.d.ts +1 -1
- package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +5 -0
- package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +5 -0
- package/dist/src/algorithms/LeidenAlgorithm.d.ts +5 -0
- package/dist/src/algorithms/PageRankAlgorithm.d.ts +1 -1
- package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +1 -1
- package/dist/src/algorithms/metrics/fields.d.ts +23 -1
- package/dist/src/algorithms/utils/graphUtils.d.ts +13 -1
- package/dist/src/catalog/paletteRegistry.d.ts +4 -4
- package/dist/src/catalog/registry.d.ts +3 -2
- package/dist/src/catalog/types.d.ts +18 -1
- package/dist/src/config/GraphStyle.d.ts +1 -1
- package/dist/src/config/StyleTemplate.d.ts +2 -2
- package/dist/src/config/xr-config-schema.d.ts +4 -4
- package/dist/src/data/CSVDataSource.d.ts +77 -22
- package/dist/src/data/ErrorAggregator.d.ts +5 -0
- package/dist/src/data/GEXFDataSource.d.ts +12 -61
- package/dist/src/data/GraphMLDataSource.d.ts +3 -44
- package/dist/src/data/GraphStore.d.ts +322 -15
- package/dist/src/data/JsonDataSource.d.ts +43 -1
- package/dist/src/data/graph-io-import.d.ts +89 -0
- package/dist/src/data/graph-io-records.d.ts +64 -0
- package/dist/src/data/lane.d.ts +23 -0
- package/dist/src/data/positions.d.ts +13 -0
- package/dist/src/data/seedPosition.d.ts +16 -0
- package/dist/src/errors/GraphtyError.d.ts +3 -1
- package/dist/src/errors/codes.d.ts +23 -0
- package/dist/src/events.d.ts +12 -0
- package/dist/src/graphty-element.d.ts +149 -54
- package/dist/src/input/types.d.ts +2 -0
- package/dist/src/layout/D3GraphLayoutEngine.d.ts +17 -3
- package/dist/src/layout/FixedLayoutEngine.d.ts +20 -4
- package/dist/src/layout/KamadaKawaiLayoutEngine.d.ts +6 -0
- package/dist/src/layout/LayoutEngine.d.ts +214 -116
- package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -3
- package/dist/src/layout/SimulationLayoutEngine.d.ts +8 -3
- package/dist/src/managers/AlgorithmManager.d.ts +24 -5
- package/dist/src/managers/DataManager.d.ts +258 -181
- package/dist/src/managers/EventManager.d.ts +5 -2
- package/dist/src/managers/GraphContext.d.ts +7 -0
- package/dist/src/managers/InputManager.d.ts +11 -0
- package/dist/src/managers/LayoutManager.d.ts +129 -50
- package/dist/src/managers/RenderManager.d.ts +14 -1
- package/dist/src/managers/UpdateManager.d.ts +20 -0
- package/dist/src/screenshot/ScreenshotCapture.d.ts +1 -1
- package/dist/src/session/GraphSession.d.ts +83 -6
- package/dist/src/session/commands/algo.d.ts +169 -0
- package/dist/src/session/commands/config.d.ts +45 -0
- package/dist/src/session/commands/data.d.ts +178 -0
- package/dist/src/session/commands/doors.d.ts +93 -0
- package/dist/src/session/commands/index.d.ts +20 -0
- package/dist/src/session/commands/layout.d.ts +104 -0
- package/dist/src/session/commands/positions.d.ts +30 -0
- package/dist/src/session/commands/sets.d.ts +113 -0
- package/dist/src/session/commands/style.d.ts +92 -0
- package/dist/src/session/commands/view.d.ts +57 -0
- package/dist/src/session/commands/visibility.d.ts +41 -0
- package/dist/src/session/data.d.ts +131 -4
- package/dist/src/session/index.d.ts +1 -1
- package/dist/src/session/planning.d.ts +25 -8
- package/dist/src/session/project/Dispatcher.d.ts +905 -0
- package/dist/src/session/project/History.d.ts +382 -0
- package/dist/src/session/project/arrangement.d.ts +247 -0
- package/dist/src/session/project/derive.d.ts +132 -0
- package/dist/src/session/project/digest.d.ts +33 -0
- package/dist/src/session/project/draft.d.ts +194 -0
- package/dist/src/session/project/graphOps.d.ts +304 -0
- package/dist/src/session/project/ingest.d.ts +364 -0
- package/dist/src/session/project/state.d.ts +145 -0
- package/dist/src/session/project/strict.d.ts +68 -0
- package/dist/src/session/results/RunResult.d.ts +48 -0
- package/dist/src/session/results/statistics.d.ts +20 -0
- package/dist/src/session/runs/Run.d.ts +80 -4
- package/dist/src/session/runs/RunsApi.d.ts +23 -6
- package/dist/src/session/runs/types.d.ts +25 -6
- package/dist/src/session/scope/ElementMask.d.ts +14 -0
- package/dist/src/session/scope/ScopeApi.d.ts +3 -22
- package/dist/src/session/scope/spaces.d.ts +29 -0
- package/dist/src/session/sealed.d.ts +22 -0
- package/dist/src/session/selection/SelectionApi.d.ts +14 -4
- package/dist/src/session/sets/SetsApi.d.ts +13 -5
- package/dist/src/session/sets/store.d.ts +54 -53
- package/dist/src/session/sets/types.d.ts +5 -2
- package/dist/src/session/styles/Layer.d.ts +5 -0
- package/dist/src/session/styles/StylesApi.d.ts +68 -17
- package/dist/src/session/styles/autoApply.d.ts +64 -53
- package/dist/src/session/styles/index.d.ts +3 -3
- package/dist/src/session/styles/predicate.d.ts +7 -0
- package/dist/src/session/styles/repaint.d.ts +16 -1
- package/dist/src/session/styles/sources.d.ts +1 -1
- package/dist/src/session/types.d.ts +625 -54
- package/dist/src/session/visibility/VisibilityApi.d.ts +38 -18
- package/dist/src/session/visibility/filter.d.ts +10 -0
- package/dist/src/simple/defineAlgorithm.d.ts +28 -0
- package/dist/src/simple/defineLayout.d.ts +35 -0
- package/dist/src/simple/defineLogDestination.d.ts +31 -0
- package/dist/src/simple/definePalette.d.ts +26 -0
- package/dist/src/simple/definition.d.ts +106 -0
- package/dist/src/simple/options.d.ts +33 -0
- package/dist/src/simple/source.d.ts +49 -0
- package/dist/src/simple/types.d.ts +366 -0
- package/dist/src/simple/view.d.ts +107 -0
- package/dist/webgpu.js +2 -2
- package/package.json +10 -12
- package/dist/chunks/GraphSession-BhuHSXIo.js +0 -12819
- package/dist/chunks/GraphStyle-Cwr55SAE.js +0 -65
- package/dist/chunks/algorithms-BJ6DQMOe.js +0 -3777
- package/dist/chunks/detect-fyuVnlCT.js +0 -88
- package/dist/chunks/interpolation-DY-PNpqX.js +0 -43
- package/dist/chunks/optionsFromZod-CKMYSwTz.js +0 -3636
- package/dist/chunks/paletteRegistry-BCFSwJGK.js +0 -1196
- package/dist/chunks/parse-BMTqt4SS.js +0 -3658
- package/dist/src/data/csv-variant-detection.d.ts +0 -29
- package/dist/src/data/ingest.d.ts +0 -104
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The undo history: recorded steps, a cursor over them, coalescing of repeated edits, and
|
|
3
|
+
* a byte and step budget.
|
|
4
|
+
*
|
|
5
|
+
* `History` does not know how a patch is made or what is inside one. It is handed three
|
|
6
|
+
* functions: apply a patch forward (redo), apply it backward (undo), and merge a newer patch into
|
|
7
|
+
* an older one (coalescing). Steps before the cursor are done; steps from the cursor on are the
|
|
8
|
+
* redo tail. See design/undo/undo-design.md sections 5, 5.2 and 7.
|
|
9
|
+
*
|
|
10
|
+
* It also keeps the arrangement (design section 6.4): each step may hold a before-capture, an
|
|
11
|
+
* after-capture and a row patch, and the arrangement after steps 1..k is
|
|
12
|
+
*
|
|
13
|
+
* A(k) = after(k), if step k has one, with the rows a merged placement wrote over it since;
|
|
14
|
+
* otherwise (before(k) if step k has one, else A(k-1)) with row patch(k) applied.
|
|
15
|
+
* A(0) = the baseline capture.
|
|
16
|
+
*
|
|
17
|
+
* Undoing step k restores before(k) when it has one and A(k-1) otherwise; redoing it restores
|
|
18
|
+
* A(k). Each undo and redo leaves the {@link ArrangementOp}s that do this, which the caller takes.
|
|
19
|
+
*
|
|
20
|
+
* A group that takes a before-arrangement is opened here ({@link History.open}) while it is
|
|
21
|
+
* pending, and a capture sealed meanwhile goes to the newest such group as its provisional
|
|
22
|
+
* after-capture instead of into a step at or below its before (design section 6.4, "The seal
|
|
23
|
+
* target"). A(0) is a private buffer that eviction folds the evicted steps' arrangements into in
|
|
24
|
+
* place (design section 7).
|
|
25
|
+
*/
|
|
26
|
+
import { type ArrangementOp, type RowPatch } from "./arrangement";
|
|
27
|
+
import type { ArrangementCapture } from "./state";
|
|
28
|
+
/** Every step counts this much on top of what its patch retains. */
|
|
29
|
+
export declare const STEP_OVERHEAD_BYTES = 512;
|
|
30
|
+
/** Why the history changed. */
|
|
31
|
+
export type HistoryChangeReason = "record" | "merge" | "undo" | "redo" | "restore" | "evict" | "clear" | "size";
|
|
32
|
+
/** How the history reaches the patches it holds. */
|
|
33
|
+
export interface HistoryOptions<P> {
|
|
34
|
+
/** Redo a patch. */
|
|
35
|
+
forward(patch: P): void;
|
|
36
|
+
/** Undo a patch. */
|
|
37
|
+
backward(patch: P): void;
|
|
38
|
+
/** One patch doing what `older` then `newer` did: the first prior, the last written value. */
|
|
39
|
+
merge(older: P, newer: P): P;
|
|
40
|
+
/** The clock of the coalescing window, in milliseconds. */
|
|
41
|
+
now?: () => number;
|
|
42
|
+
coalesceMs?: number;
|
|
43
|
+
limitBytes?: number;
|
|
44
|
+
limitSteps?: number;
|
|
45
|
+
/** Called after every change, once the version has moved. */
|
|
46
|
+
onChange?: (reason: HistoryChangeReason) => void;
|
|
47
|
+
/** The row patch a patch carries, if any. */
|
|
48
|
+
rows?(patch: P): RowPatch | null;
|
|
49
|
+
/**
|
|
50
|
+
* Whether undoing a step brings rows back at coordinates other than A(k-1), which must then
|
|
51
|
+
* be written over them; without it, a step with no capture and no row patch restores nothing.
|
|
52
|
+
*/
|
|
53
|
+
restoresRows?(id: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a patch added or removed nodes or edges, or changed an edge's weight: a change that
|
|
56
|
+
* sets a running layout moving. Where that layout comes to rest belongs to its step.
|
|
57
|
+
*/
|
|
58
|
+
reshapes?(patch: P): boolean;
|
|
59
|
+
}
|
|
60
|
+
/** What one recorded group contributes to a step. */
|
|
61
|
+
interface RecordInput<P> {
|
|
62
|
+
readonly label: string;
|
|
63
|
+
readonly patch: P;
|
|
64
|
+
/** Steps with equal keys recorded within the coalescing window become one step. */
|
|
65
|
+
readonly key?: string | null;
|
|
66
|
+
/**
|
|
67
|
+
* True when undoable work was dispatched after the top step was recorded and is still
|
|
68
|
+
* pending: the patch then starts a step of its own whatever its key, so that step never
|
|
69
|
+
* reaches back across that work (design section 5.2).
|
|
70
|
+
*/
|
|
71
|
+
readonly pendingSinceTop?: boolean;
|
|
72
|
+
/** The ops of the commands in the patch, in the order they ran. */
|
|
73
|
+
readonly ops?: readonly string[];
|
|
74
|
+
readonly slices?: readonly string[];
|
|
75
|
+
readonly provenance?: Readonly<Record<string, string>>;
|
|
76
|
+
/** What the patch retains while done (for undo) and while undone (for redo). */
|
|
77
|
+
readonly bytes?: {
|
|
78
|
+
readonly done: number;
|
|
79
|
+
readonly undone: number;
|
|
80
|
+
};
|
|
81
|
+
/** The arrangement after the step, when it already has one: a large `positions.set`. */
|
|
82
|
+
readonly after?: ArrangementCapture | null;
|
|
83
|
+
/** The arrangement when the step's group began changing things, if it took one. */
|
|
84
|
+
readonly before?: ArrangementCapture | null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A pending group that took a before-arrangement, from {@link History.open} until
|
|
88
|
+
* {@link History.close}.
|
|
89
|
+
*/
|
|
90
|
+
export interface OpenArrangement {
|
|
91
|
+
/** The arrangement when the group began changing things. */
|
|
92
|
+
readonly before: ArrangementCapture;
|
|
93
|
+
/**
|
|
94
|
+
* Where the lane came to rest since, sealed while the group was the seal target; dropped
|
|
95
|
+
* when a history call restores the lane.
|
|
96
|
+
*/
|
|
97
|
+
readonly provisional: ArrangementCapture | null;
|
|
98
|
+
}
|
|
99
|
+
/** A step as the history publishes it. Frozen. */
|
|
100
|
+
interface HistoryStepView {
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly label: string;
|
|
103
|
+
/** ISO 8601 of the last record or merge. */
|
|
104
|
+
readonly at: string;
|
|
105
|
+
readonly ops: readonly string[];
|
|
106
|
+
readonly slices: readonly string[];
|
|
107
|
+
/** Retained on the side of the cursor the step is on, including the fixed overhead. */
|
|
108
|
+
readonly bytes: number;
|
|
109
|
+
readonly provenance: Readonly<Record<string, string>>;
|
|
110
|
+
}
|
|
111
|
+
/** Undo history over patches of type `P`. */
|
|
112
|
+
export declare class History<P> {
|
|
113
|
+
private readonly options;
|
|
114
|
+
private readonly now;
|
|
115
|
+
private readonly coalesceMs;
|
|
116
|
+
private entries;
|
|
117
|
+
private cursor;
|
|
118
|
+
private total;
|
|
119
|
+
private changes;
|
|
120
|
+
private published;
|
|
121
|
+
private nextId;
|
|
122
|
+
/** Whether the top step may take a merge: false once anything but a record has happened. */
|
|
123
|
+
private mergeable;
|
|
124
|
+
private maxBytes;
|
|
125
|
+
private maxSteps;
|
|
126
|
+
/**
|
|
127
|
+
* A(0): the arrangement before the first step. `owned` when it is a private copy, which
|
|
128
|
+
* eviction folds steps into in place; otherwise a capture shared with others, copied before
|
|
129
|
+
* the first fold.
|
|
130
|
+
*/
|
|
131
|
+
private baseline;
|
|
132
|
+
/** The pending groups holding a before-arrangement, oldest first. */
|
|
133
|
+
private groups;
|
|
134
|
+
/** What the undos and redos since the last take restore, in order. */
|
|
135
|
+
private arrangementOps;
|
|
136
|
+
/** While above zero, a history move is under way and eviction waits for it to land. */
|
|
137
|
+
private moving;
|
|
138
|
+
/**
|
|
139
|
+
* Create an empty history.
|
|
140
|
+
* @param options - How to apply and merge patches, the clock and the limits.
|
|
141
|
+
*/
|
|
142
|
+
constructor(options: HistoryOptions<P>);
|
|
143
|
+
/**
|
|
144
|
+
* Counts changes; moves on every change.
|
|
145
|
+
* @returns The version.
|
|
146
|
+
*/
|
|
147
|
+
get version(): number;
|
|
148
|
+
/**
|
|
149
|
+
* The count of done steps.
|
|
150
|
+
* @returns The cursor.
|
|
151
|
+
*/
|
|
152
|
+
get position(): number;
|
|
153
|
+
/**
|
|
154
|
+
* What the steps retain, each on its side of the cursor.
|
|
155
|
+
* @returns Bytes.
|
|
156
|
+
*/
|
|
157
|
+
get bytes(): number;
|
|
158
|
+
/**
|
|
159
|
+
* Oldest first; `steps[position..]` are undone. The identical array between changes.
|
|
160
|
+
* @returns The frozen steps.
|
|
161
|
+
*/
|
|
162
|
+
get steps(): readonly HistoryStepView[];
|
|
163
|
+
/**
|
|
164
|
+
* The byte limit.
|
|
165
|
+
* @returns Bytes.
|
|
166
|
+
*/
|
|
167
|
+
get limitBytes(): number;
|
|
168
|
+
/** Set the byte limit, evicting at once if it is now exceeded. */
|
|
169
|
+
set limitBytes(value: number);
|
|
170
|
+
/**
|
|
171
|
+
* The step limit.
|
|
172
|
+
* @returns Steps.
|
|
173
|
+
*/
|
|
174
|
+
get limitSteps(): number;
|
|
175
|
+
/** Set the step limit, evicting at once if it is now exceeded. */
|
|
176
|
+
set limitSteps(value: number);
|
|
177
|
+
/**
|
|
178
|
+
* Record a patch that has already been applied: merge it into the top step when it coalesces
|
|
179
|
+
* with it, otherwise discard the redo tail and push a new step.
|
|
180
|
+
* @param input - The patch and what describes it.
|
|
181
|
+
* @returns The id of the step the patch is now in.
|
|
182
|
+
*/
|
|
183
|
+
record(input: RecordInput<P>): string;
|
|
184
|
+
/**
|
|
185
|
+
* Merge a patch into the top step whatever its key and however long ago it was recorded: how
|
|
186
|
+
* work that finishes after its step was recorded (a transaction's deferred member) joins it.
|
|
187
|
+
* @param id - The step the patch belongs to.
|
|
188
|
+
* @param input - The patch and what describes it; its label is ignored.
|
|
189
|
+
* @returns False, merging nothing, when that step is not the top step or is undone.
|
|
190
|
+
*/
|
|
191
|
+
amend(id: string, input: RecordInput<P>): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* What a step keeps as a cache, if anything.
|
|
194
|
+
* @param id - The step.
|
|
195
|
+
* @returns The cached value, or undefined when the step keeps none or is gone.
|
|
196
|
+
*/
|
|
197
|
+
cacheOf(id: string): unknown;
|
|
198
|
+
/**
|
|
199
|
+
* Keep a cache on a step, replacing any it had. It is counted in `bytes` and dropped before
|
|
200
|
+
* any step is evicted.
|
|
201
|
+
* @param id - The step; nothing happens when it is gone.
|
|
202
|
+
* @param value - What to keep.
|
|
203
|
+
* @param bytes - What it costs.
|
|
204
|
+
*/
|
|
205
|
+
setCache(id: string, value: unknown, bytes: number): void;
|
|
206
|
+
/**
|
|
207
|
+
* Re-estimate every step's charge, oldest first, and evict when that puts the history over a
|
|
208
|
+
* limit. Quiet: the caller calls it straight after the change that moved the charges, whose
|
|
209
|
+
* own `history:changed` already tells readers to look again.
|
|
210
|
+
* @param charge - A step's charge from its patch. Called oldest step first, so something
|
|
211
|
+
* counted once is counted against the oldest step that holds it.
|
|
212
|
+
*/
|
|
213
|
+
recharge(charge: (patch: P) => number): void;
|
|
214
|
+
/**
|
|
215
|
+
* Seal a capture of the lane into the seal target: the newest open group's provisional
|
|
216
|
+
* after-capture; else the after-capture of the newest applied step that has to do with the
|
|
217
|
+
* arrangement (it holds a capture or placed rows, or it changed the graph's shape); else the
|
|
218
|
+
* baseline. A step that moved nothing (a setting, a style) is never the target, so undoing it
|
|
219
|
+
* never puts back an arrangement older than the one on screen.
|
|
220
|
+
* @param capture - The capture.
|
|
221
|
+
*/
|
|
222
|
+
seal(capture: ArrangementCapture): void;
|
|
223
|
+
/**
|
|
224
|
+
* A pending group took a before-arrangement: from now until it is closed, it is the seal
|
|
225
|
+
* target.
|
|
226
|
+
* @param before - Its before-arrangement.
|
|
227
|
+
* @returns Its handle; the dispatcher records `before` and `provisional` from it.
|
|
228
|
+
*/
|
|
229
|
+
open(before: ArrangementCapture): OpenArrangement;
|
|
230
|
+
/**
|
|
231
|
+
* A group recorded or rolled back: it stops being a seal target.
|
|
232
|
+
* @param group - Its handle.
|
|
233
|
+
*/
|
|
234
|
+
close(group: OpenArrangement): void;
|
|
235
|
+
/**
|
|
236
|
+
* What the undos and redos since the last call restore, in the order they happened.
|
|
237
|
+
* @returns The ops; the list is emptied.
|
|
238
|
+
*/
|
|
239
|
+
takeArrangement(): ArrangementOp[];
|
|
240
|
+
/**
|
|
241
|
+
* Undo the latest done step.
|
|
242
|
+
* @returns The step undone, or null when there was none.
|
|
243
|
+
*/
|
|
244
|
+
undo(): HistoryStepView | null;
|
|
245
|
+
/**
|
|
246
|
+
* Redo the next undone step.
|
|
247
|
+
* @returns The step redone, or null when there was none.
|
|
248
|
+
*/
|
|
249
|
+
redo(): HistoryStepView | null;
|
|
250
|
+
/**
|
|
251
|
+
* Move to the state just after a step, or to the baseline, as the equivalent sequence of undos
|
|
252
|
+
* or redos.
|
|
253
|
+
* @param id - The step, or null for the baseline.
|
|
254
|
+
* @returns The steps passed, in the order they were undone or redone.
|
|
255
|
+
*/
|
|
256
|
+
restoreTo(id: string | null): readonly HistoryStepView[];
|
|
257
|
+
/**
|
|
258
|
+
* Drop every step: the current state becomes the baseline.
|
|
259
|
+
* @param baseline - The arrangement now, the new A(0).
|
|
260
|
+
*/
|
|
261
|
+
clear(baseline?: ArrangementCapture | null): void;
|
|
262
|
+
/**
|
|
263
|
+
* Merge a patch into a done top step: the first prior, the last written value.
|
|
264
|
+
* @param top - The top step.
|
|
265
|
+
* @param input - The patch and what describes it.
|
|
266
|
+
* @param time - `now()` of the merge.
|
|
267
|
+
* @param at - ISO 8601 of the merge.
|
|
268
|
+
*/
|
|
269
|
+
private mergeInto;
|
|
270
|
+
/**
|
|
271
|
+
* Apply the latest done step backward and move the cursor over it.
|
|
272
|
+
* @returns The step, or null when none was done.
|
|
273
|
+
*/
|
|
274
|
+
private back;
|
|
275
|
+
/**
|
|
276
|
+
* Apply the next undone step forward and move the cursor over it.
|
|
277
|
+
* @returns The step, or null when none was undone.
|
|
278
|
+
*/
|
|
279
|
+
private ahead;
|
|
280
|
+
/**
|
|
281
|
+
* A step changed sides: its size and its view change with it.
|
|
282
|
+
* @param step - The step.
|
|
283
|
+
* @param delta - The change in what it retains.
|
|
284
|
+
*/
|
|
285
|
+
private moved;
|
|
286
|
+
/**
|
|
287
|
+
* What a step retains on one side of the cursor.
|
|
288
|
+
* @param step - The step.
|
|
289
|
+
* @param done - Whether the step is done.
|
|
290
|
+
* @returns Bytes, with the fixed overhead.
|
|
291
|
+
*/
|
|
292
|
+
private size;
|
|
293
|
+
/**
|
|
294
|
+
* Make one history move: the capture sealed before the cursor moves can take the history over
|
|
295
|
+
* its budget, and evicting then could take the very step being moved to. Eviction waits until
|
|
296
|
+
* the cursor has landed, where the step it landed on is protected.
|
|
297
|
+
* @param move - The seal and the move.
|
|
298
|
+
* @returns What `move` returned.
|
|
299
|
+
*/
|
|
300
|
+
moveAs<T>(move: () => T): T;
|
|
301
|
+
/** Evict the oldest done steps, then the farthest redo steps, down to 90% of both limits. */
|
|
302
|
+
private evictIfOver;
|
|
303
|
+
/** A history call restores the lane: what open groups sealed before it no longer holds. */
|
|
304
|
+
private dropProvisionals;
|
|
305
|
+
/**
|
|
306
|
+
* Make a capture A(0), keeping `total` in step.
|
|
307
|
+
* @param capture - The capture.
|
|
308
|
+
* @param owned - Whether it is a private copy nothing else references.
|
|
309
|
+
*/
|
|
310
|
+
private setBaseline;
|
|
311
|
+
/**
|
|
312
|
+
* Fold an evicted step's arrangement into A(0), by the recursion: A(k) is after(k) with the
|
|
313
|
+
* rows written over it since, or else before(k) or A(k-1), with row patch(k) applied. The
|
|
314
|
+
* buffer is written in place while it has the capture's rows; it is copied only when the rows
|
|
315
|
+
* differ, which a graph edit between the two makes them.
|
|
316
|
+
* @param step - The oldest step, being evicted.
|
|
317
|
+
*/
|
|
318
|
+
private fold;
|
|
319
|
+
/**
|
|
320
|
+
* Write a row patch's new values into A(0), in place. A node the baseline does not hold yet (it
|
|
321
|
+
* was added after the baseline was taken) is appended, and then the buffer names no row order.
|
|
322
|
+
* @param rows - The patch.
|
|
323
|
+
*/
|
|
324
|
+
private foldRows;
|
|
325
|
+
/**
|
|
326
|
+
* Whether a step has anything to do with the arrangement, so a rest point may seal into it.
|
|
327
|
+
* @param step - The step.
|
|
328
|
+
* @returns True when it holds a capture or placed rows, or changed the graph's shape.
|
|
329
|
+
*/
|
|
330
|
+
private arranges;
|
|
331
|
+
/**
|
|
332
|
+
* Give a step a new after-capture, replacing the one it had.
|
|
333
|
+
* @param step - The step.
|
|
334
|
+
* @param capture - The capture.
|
|
335
|
+
*/
|
|
336
|
+
private retake;
|
|
337
|
+
/**
|
|
338
|
+
* The row patch of a step, if it has one that counts: an after-capture already holds it.
|
|
339
|
+
* @param step - The step.
|
|
340
|
+
* @returns The patch, or null.
|
|
341
|
+
*/
|
|
342
|
+
private rowsOf;
|
|
343
|
+
/**
|
|
344
|
+
* What undoing the step at `index` restores, given that the lane holds A(index + 1).
|
|
345
|
+
* @param index - The step.
|
|
346
|
+
* @returns The ops: before(k), or A(k-1).
|
|
347
|
+
*/
|
|
348
|
+
private undoOps;
|
|
349
|
+
/**
|
|
350
|
+
* What redoing the step at `index` restores, given that the lane holds A(index).
|
|
351
|
+
* @param index - The step.
|
|
352
|
+
* @returns The ops: A(k).
|
|
353
|
+
*/
|
|
354
|
+
private redoOps;
|
|
355
|
+
/**
|
|
356
|
+
* A(count), the arrangement after the first `count` steps, as ops written over the lane.
|
|
357
|
+
* @param count - How many steps.
|
|
358
|
+
* @returns The ops; without the baseline capture when there is none.
|
|
359
|
+
*/
|
|
360
|
+
private arrangementAt;
|
|
361
|
+
/**
|
|
362
|
+
* One node's coordinates in A(count).
|
|
363
|
+
* @param count - How many steps.
|
|
364
|
+
* @param id - The node.
|
|
365
|
+
* @param hint - The row it is expected at.
|
|
366
|
+
* @returns x, y, z, or null when nothing the history holds places it.
|
|
367
|
+
*/
|
|
368
|
+
private valueAt;
|
|
369
|
+
/**
|
|
370
|
+
* Bump the version, drop the published array and tell the listener.
|
|
371
|
+
* @param reason - Why.
|
|
372
|
+
*/
|
|
373
|
+
private changed;
|
|
374
|
+
/**
|
|
375
|
+
* The published view of a step, built once per change of the step.
|
|
376
|
+
* @param step - The step.
|
|
377
|
+
* @param index - Its index, which says which side of the cursor it is on.
|
|
378
|
+
* @returns The frozen view.
|
|
379
|
+
*/
|
|
380
|
+
private view;
|
|
381
|
+
}
|
|
382
|
+
export {};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The arrangement: where the nodes are, recorded at rest.
|
|
3
|
+
*
|
|
4
|
+
* A running layout moves every unpinned node every frame and most commands do not say where
|
|
5
|
+
* anything goes, so coordinates are not recorded per command. They are recorded as captures of
|
|
6
|
+
* the positions lane, taken when the lane has moved and something needs to know where it is: a
|
|
7
|
+
* rest point (the layout settled or was paused), a history call about to move the cursor, and a
|
|
8
|
+
* `positions.set` about to write. A capture goes into the newest applied step that has to do
|
|
9
|
+
* with the arrangement (it holds a capture or placed rows, or changed the graph's shape), or into
|
|
10
|
+
* the baseline when there is none: a step that moved nothing never takes one. `positions.set` writes only a few rows, so it records a row patch
|
|
11
|
+
* instead: the rows written, with their prior and new values.
|
|
12
|
+
*
|
|
13
|
+
* Undo and redo turn what the steps hold into {@link ArrangementOp}s (`History.ts` holds the
|
|
14
|
+
* rule), and the `arrangement` derivation hook writes them into the lane and hands the lane to
|
|
15
|
+
* the layout engine, which takes it as its own and stays at rest. Pins are the `pins` slice; the
|
|
16
|
+
* `pins` hook writes the lane's pin bytes from it and tells the engine. See
|
|
17
|
+
* design/undo/undo-design.md sections 6.2 and 6.4.
|
|
18
|
+
*
|
|
19
|
+
* Nothing here reaches Babylon.js, Lit or the DOM: the renderer hands in an engine.
|
|
20
|
+
*/
|
|
21
|
+
import { type GraphSnapshot } from "@graphty/graph-format";
|
|
22
|
+
import type { NodeId } from "../../catalog/types";
|
|
23
|
+
import { type ElementPositions } from "../../data/positions";
|
|
24
|
+
import type { PositionEntry } from "../types";
|
|
25
|
+
import type { DerivationLane } from "./derive";
|
|
26
|
+
import type { Draft } from "./draft";
|
|
27
|
+
import { type GraphOps } from "./graphOps";
|
|
28
|
+
import type { ArrangementCapture, ProjectState } from "./state";
|
|
29
|
+
/**
|
|
30
|
+
* The coordinates a few rows were written with, and what they held before. Row indices are
|
|
31
|
+
* hints taken when the rows were written; a row is always checked against its id, and found by
|
|
32
|
+
* id when the rows have moved since.
|
|
33
|
+
*/
|
|
34
|
+
export interface RowPatch {
|
|
35
|
+
readonly ids: readonly NodeId[];
|
|
36
|
+
readonly rows: Uint32Array;
|
|
37
|
+
/** Per row: the prior x, y, z, then the new x, y, z. */
|
|
38
|
+
readonly values: Float32Array;
|
|
39
|
+
}
|
|
40
|
+
/** One thing the `arrangement` hook writes into the lane, in order. */
|
|
41
|
+
export type ArrangementOp = {
|
|
42
|
+
readonly capture: ArrangementCapture;
|
|
43
|
+
}
|
|
44
|
+
/** Each row takes its new value, or its prior one when `forward` is false. */
|
|
45
|
+
| {
|
|
46
|
+
readonly patch: RowPatch;
|
|
47
|
+
readonly forward: boolean;
|
|
48
|
+
};
|
|
49
|
+
/** Where the lane lives: the snapshot its rows follow, and the lane itself. */
|
|
50
|
+
interface LaneSource {
|
|
51
|
+
snapshot(): GraphSnapshot;
|
|
52
|
+
readonly positions: ElementPositions;
|
|
53
|
+
/** Whether the graph holds no node rows, answered without freezing; absent, records decide. */
|
|
54
|
+
holdsNoRows?(): boolean;
|
|
55
|
+
/** Whether the next read of the graph would freeze a snapshot, which a check must not force. */
|
|
56
|
+
readonly stale?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** What moves the lane besides history: the layout engine, as the renderer hands it in. */
|
|
59
|
+
export interface ArrangementEngine {
|
|
60
|
+
/** Stop moving the lane: a history call is about to restore it. */
|
|
61
|
+
suspend(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Take the lane's coordinates as the engine's own, and drop work that was computing from the
|
|
64
|
+
* coordinates it held before.
|
|
65
|
+
* @param restoring - True for undo, redo, a restore or a rollback: the engine is left at rest.
|
|
66
|
+
* False for a forward `positions.set`: the engine keeps running if it was.
|
|
67
|
+
* @param wrote - Whether anything was written into the lane; when nothing was, every row the
|
|
68
|
+
* graph held before holds what it did, and only rows the graph just gained are new.
|
|
69
|
+
*/
|
|
70
|
+
loadArrangement(restoring: boolean, wrote: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* A node was pinned or released; the lane's pin byte is already written.
|
|
73
|
+
* @param id - The node.
|
|
74
|
+
* @param pinned - Whether it is pinned now.
|
|
75
|
+
*/
|
|
76
|
+
pin(id: NodeId, pinned: boolean): void;
|
|
77
|
+
}
|
|
78
|
+
/** Where a capture is sealed: the history's seal target. */
|
|
79
|
+
interface SealTarget {
|
|
80
|
+
seal(capture: ArrangementCapture): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* What a capture retains.
|
|
84
|
+
* @param capture - The capture.
|
|
85
|
+
* @returns Bytes: 12 per row of coordinates and 8 per id.
|
|
86
|
+
*/
|
|
87
|
+
export declare function captureBytes(capture: ArrangementCapture): number;
|
|
88
|
+
/**
|
|
89
|
+
* What a row patch retains.
|
|
90
|
+
* @param patch - The patch.
|
|
91
|
+
* @returns Bytes: 4 for the row, 24 for the values and 8 for the id, per row.
|
|
92
|
+
*/
|
|
93
|
+
export declare function rowPatchBytes(patch: RowPatch): number;
|
|
94
|
+
/**
|
|
95
|
+
* One patch doing what `older` then `newer` did: each row keeps its first prior and takes its last
|
|
96
|
+
* new value.
|
|
97
|
+
* @param older - The patch written first.
|
|
98
|
+
* @param newer - The patch written after it.
|
|
99
|
+
* @returns The merged patch.
|
|
100
|
+
*/
|
|
101
|
+
export declare function mergeRowPatches(older: RowPatch, newer: RowPatch): RowPatch;
|
|
102
|
+
/**
|
|
103
|
+
* A node's coordinates in a capture.
|
|
104
|
+
* @param capture - The capture.
|
|
105
|
+
* @param id - The node.
|
|
106
|
+
* @param hint - The row it is expected at.
|
|
107
|
+
* @returns x, y, z, or null when the capture does not hold the node.
|
|
108
|
+
*/
|
|
109
|
+
export declare function coordsIn(capture: ArrangementCapture, id: NodeId, hint: number): Float32Array | null;
|
|
110
|
+
/**
|
|
111
|
+
* The arrangement of one session: the current capture, the generation of the lane it matches,
|
|
112
|
+
* the `arrangement` and `pins` hooks, and the `positions.*` commands' writes.
|
|
113
|
+
*
|
|
114
|
+
* Its invariant: while the lane's generation equals the one recorded here, the lane holds the
|
|
115
|
+
* arrangement of the history's cursor, A(cursor). A seal, a restore and a `positions.set` keep it;
|
|
116
|
+
* a layout write breaks it until the next seal.
|
|
117
|
+
*/
|
|
118
|
+
export declare class Arrangement {
|
|
119
|
+
private readonly state;
|
|
120
|
+
private readonly lane;
|
|
121
|
+
private readonly history;
|
|
122
|
+
private readonly graph;
|
|
123
|
+
/** The layout engine; the renderer sets it, a test sets a fake. */
|
|
124
|
+
engine: ArrangementEngine | null;
|
|
125
|
+
private source;
|
|
126
|
+
private captured;
|
|
127
|
+
/**
|
|
128
|
+
* The capture the lane holds row for row, while nothing has written it since: what a group's
|
|
129
|
+
* before-arrangement shares instead of copying the lane. Null after a row write.
|
|
130
|
+
*/
|
|
131
|
+
private exact;
|
|
132
|
+
/** Whether a forward `positions.set` wrote the lane since the last pass. */
|
|
133
|
+
private written;
|
|
134
|
+
private readonly ops;
|
|
135
|
+
private readonly strict;
|
|
136
|
+
/**
|
|
137
|
+
* The arrangement over a dispatcher's state, lane and history.
|
|
138
|
+
* @param state - The live project state; this writes its `arrangement` and reads its `graph`.
|
|
139
|
+
* @param lane - The derivation lane: the restoring flag, and where the hooks register.
|
|
140
|
+
* @param history - Where captures are sealed.
|
|
141
|
+
* @param graph - The graph primitives, which write the `pins` slice.
|
|
142
|
+
*/
|
|
143
|
+
constructor(state: ProjectState, lane: DerivationLane, history: SealTarget, graph: GraphOps);
|
|
144
|
+
/**
|
|
145
|
+
* Hand in the lane, or take it away when the session is disposed. From here on the lane as it
|
|
146
|
+
* is counts as unmoved.
|
|
147
|
+
* @param source - The lane, or null.
|
|
148
|
+
*/
|
|
149
|
+
bind(source: LaneSource | null): void;
|
|
150
|
+
/**
|
|
151
|
+
* Whether something has moved the lane since the last capture, restore or `positions.set`.
|
|
152
|
+
* @returns True when it has.
|
|
153
|
+
*/
|
|
154
|
+
get moved(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Copy the lane now. It becomes the current capture.
|
|
157
|
+
* @returns The capture, or null when there is no lane.
|
|
158
|
+
*/
|
|
159
|
+
capture(): ArrangementCapture | null;
|
|
160
|
+
/**
|
|
161
|
+
* Seal the lane into the history's seal target when it has moved, unless a restore is still
|
|
162
|
+
* on its way to the lane: until the `arrangement` hook has run, the lane is not at rest.
|
|
163
|
+
*/
|
|
164
|
+
seal(): void;
|
|
165
|
+
/**
|
|
166
|
+
* The arrangement a group begins from (design section 6.4, "Which groups take a
|
|
167
|
+
* before-arrangement"): the current capture, shared, when nothing has moved the lane since it
|
|
168
|
+
* was taken; otherwise the lane is captured, and that capture is sealed into the seal target
|
|
169
|
+
* first, because it is where the step below the group came to rest.
|
|
170
|
+
* @returns The capture, or null when there is no lane.
|
|
171
|
+
*/
|
|
172
|
+
before(): ArrangementCapture | null;
|
|
173
|
+
/**
|
|
174
|
+
* Copy the lane now, with every restore still queued written into it first: the capture a
|
|
175
|
+
* group seals at its commit.
|
|
176
|
+
* @returns The capture, or null when there is no lane.
|
|
177
|
+
*/
|
|
178
|
+
settledCapture(): ArrangementCapture | null;
|
|
179
|
+
/** A rest point: the layout settled, was paused, or finished a placement pass. */
|
|
180
|
+
rest(): void;
|
|
181
|
+
/** Stop the engine: a history call is about to move the cursor. */
|
|
182
|
+
stop(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Queue what a history call or a rollback restores; the `arrangement` hook writes it and hands
|
|
185
|
+
* the lane to the engine. The engine takes the lane even when nothing is written: the graph
|
|
186
|
+
* under it may have changed, and an engine that recomputed its own arrangement for the new
|
|
187
|
+
* graph would draw over the restored one.
|
|
188
|
+
* @param ops - The ops, in order.
|
|
189
|
+
*/
|
|
190
|
+
restore(ops: readonly ArrangementOp[]): void;
|
|
191
|
+
/**
|
|
192
|
+
* Write every restore still queued into the lane now, before a capture or a write reads it.
|
|
193
|
+
*/
|
|
194
|
+
flush(): void;
|
|
195
|
+
/**
|
|
196
|
+
* `positions.set`: write rows of the lane, and record them in the draft as a row patch. When
|
|
197
|
+
* something has moved the lane since the last capture, that is sealed first, so the rows'
|
|
198
|
+
* prior values are an arrangement the history holds.
|
|
199
|
+
* @param entries - The rows and their coordinates.
|
|
200
|
+
* @param draft - The command's draft.
|
|
201
|
+
*/
|
|
202
|
+
set(entries: readonly PositionEntry[], draft: Draft): void;
|
|
203
|
+
/**
|
|
204
|
+
* Whether a `positions.set` wrote so much of the lane that a capture is cheaper to keep than
|
|
205
|
+
* its row patch: more than a third of the rows.
|
|
206
|
+
* @param patch - What it wrote.
|
|
207
|
+
* @returns True when the step should keep a capture instead.
|
|
208
|
+
*/
|
|
209
|
+
wantsCapture(patch: RowPatch): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* `positions.pin`: pin or release nodes, in the `pins` slice and in the lane's pin bytes. A
|
|
212
|
+
* node the graph does not hold is skipped, as the element's own `pin` always has.
|
|
213
|
+
* @param ids - The nodes.
|
|
214
|
+
* @param pinned - Pin, or release.
|
|
215
|
+
* @param draft - The command's draft.
|
|
216
|
+
*/
|
|
217
|
+
pin(ids: readonly NodeId[], pinned: boolean, draft: Draft): void;
|
|
218
|
+
/**
|
|
219
|
+
* Strict state: the lane's pin bytes agree with the `pins` slice. Asked at every commit and
|
|
220
|
+
* once each history call's pass has run, and not while a restore is on its way to the lane.
|
|
221
|
+
*/
|
|
222
|
+
checkPins(): void;
|
|
223
|
+
/**
|
|
224
|
+
* Record a capture as the current one.
|
|
225
|
+
* @param capture - The capture.
|
|
226
|
+
*/
|
|
227
|
+
private current;
|
|
228
|
+
/**
|
|
229
|
+
* The `arrangement` hook: write the queued ops into the lane, and hand the lane to the engine.
|
|
230
|
+
* @param restoring - Whether a history call or a rollback queued them.
|
|
231
|
+
*/
|
|
232
|
+
private apply;
|
|
233
|
+
/**
|
|
234
|
+
* The `pins` hook: every node whose pin was written gets its lane byte from the slice, and the
|
|
235
|
+
* engine is told. Every dirty node, not only those whose pin differs from the last pass: a pin
|
|
236
|
+
* and its undo in one burst leave the slice as it was, but the pin wrote the byte at once.
|
|
237
|
+
* @param target - The state the picture must show.
|
|
238
|
+
* @param dirty - The pins written, as node keys.
|
|
239
|
+
*/
|
|
240
|
+
private derivePins;
|
|
241
|
+
/**
|
|
242
|
+
* The lane, or the error a positions command gets on a session with none.
|
|
243
|
+
* @returns The lane.
|
|
244
|
+
*/
|
|
245
|
+
private requireSource;
|
|
246
|
+
}
|
|
247
|
+
export {};
|