@popcorn245/cornfield 0.46.1 → 0.47.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 (56) hide show
  1. package/explorer/capped.js +3 -2
  2. package/explorer/engine/feedback.js +49 -0
  3. package/explorer/engine/flow-ui.js +39 -0
  4. package/explorer/engine/fly.js +54 -0
  5. package/explorer/engine/hint.js +98 -0
  6. package/explorer/engine/keyboard.js +156 -0
  7. package/explorer/engine/layers.js +280 -0
  8. package/explorer/engine/layout.js +378 -0
  9. package/explorer/engine/map-style.js +552 -0
  10. package/explorer/engine/piece.js +142 -0
  11. package/explorer/engine/render.js +331 -0
  12. package/explorer/engine/search-status.js +59 -0
  13. package/explorer/engine/selection.js +42 -0
  14. package/explorer/engine/sheets.js +417 -0
  15. package/explorer/engine/strings.js +63 -0
  16. package/explorer/feedback.js +11 -45
  17. package/explorer/flow-build.js +88 -0
  18. package/explorer/flow-style.js +28 -0
  19. package/explorer/flows.js +11 -132
  20. package/explorer/fly.js +11 -43
  21. package/explorer/hint.js +15 -88
  22. package/explorer/index.html +40 -82
  23. package/explorer/input.js +197 -177
  24. package/explorer/instance-state.js +172 -0
  25. package/explorer/instance.js +267 -0
  26. package/explorer/keyboard.js +14 -206
  27. package/explorer/labels.js +3 -3
  28. package/explorer/layers.js +34 -445
  29. package/explorer/layout.js +14 -372
  30. package/explorer/main.js +4 -226
  31. package/explorer/map-style.js +27 -525
  32. package/explorer/mockups-model.js +3 -3
  33. package/explorer/page-pieces.js +66 -0
  34. package/explorer/page.js +223 -0
  35. package/explorer/panels.js +29 -409
  36. package/explorer/pieces/adopt-tokens.js +38 -0
  37. package/explorer/pieces/layers.js +325 -0
  38. package/explorer/pieces/map-stage.css +14 -0
  39. package/explorer/pieces/map.js +332 -0
  40. package/explorer/pieces/node-panel.js +536 -0
  41. package/explorer/pieces/search.js +454 -0
  42. package/explorer/proposal-model.js +1 -1
  43. package/explorer/proposal.js +1 -0
  44. package/explorer/render.js +37 -267
  45. package/explorer/renderer-canvas2d.js +4 -4
  46. package/explorer/renderer-webgl.js +21 -8
  47. package/explorer/renderer.js +12 -9
  48. package/explorer/scene.js +3 -2
  49. package/explorer/search-status.js +8 -47
  50. package/explorer/search.js +26 -324
  51. package/explorer/selection-view.js +17 -19
  52. package/explorer/sheets.js +31 -379
  53. package/explorer/state.js +38 -173
  54. package/explorer/strings.js +17 -60
  55. package/explorer/view.js +4 -5
  56. package/package.json +1 -1
package/explorer/input.js CHANGED
@@ -12,216 +12,236 @@
12
12
  * point under the pointer, or between two fingers, still (camera.js).
13
13
  */
14
14
 
15
- import { state, touchScene } from './state.js';
16
- import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom, setHoverNode, labelNodeAt, fitGraphToViewport, fitPadding } from './render.js';
17
15
  import { clusterIds } from './cluster.js';
18
16
  import { LANDMARK_TYPES } from './scene.js';
19
- import { saveFreeformPositions } from './layout.js';
20
- import { selectNode, closeDrawer } from './panels.js';
17
+ import { saveFreeformPositions } from './engine/layout.js';
21
18
  import { hitTestScreen } from './spatial.js';
22
19
  import { zoomAbout, pinchStart, pinchCamera } from './camera.js';
23
- import { stopFlight } from './fly.js';
24
-
25
- let isDragging = false;
26
- let dragNode = null;
27
- let lastPos = { x: 0, y: 0 };
28
- let touchStartPos = { x: 0, y: 0 };
29
- let touchMoved = false;
30
- let pointerDownNode = null;
31
- let lastTapNode = null;
32
- let lastTapTime = 0;
33
- let pinch = null; // the start of a two-finger gesture (camera.js pinchStart)
34
- let downOnCanvas = false; // the press that is ending began on the map: a release elsewhere (a sheet's handle, a panel button) is not a tap on the background
35
-
36
- // What the pointer did since the last frame; applied once per frame by applyMoves
37
- let pendingPos = null;
38
- let pendingPinch = null;
39
- let pendingHover = null;
40
- let hovering = false;
41
- let restCursor = '';
42
-
43
- const canDragNodes = () => state.isFreeform && state.view === 'orbit';
44
-
45
- function getPointerPos(e) {
46
- const rect = state.canvas.getBoundingClientRect();
47
- const point = e.touches ? e.touches[0] : e;
48
- return { x: point.clientX - rect.left, y: point.clientY - rect.top };
49
- }
50
20
 
51
- // The topology node with this id (the grid answers with scene nodes, which are copies of the picture)
52
- let byId = { nodes: null, size: -1, map: null };
53
- function topologyNode(id) {
54
- if (byId.nodes !== state.nodes || byId.size !== state.nodes.length) {
55
- byId = { nodes: state.nodes, size: state.nodes.length, map: new Map(state.nodes.map((n) => [n.id, n])) };
21
+ /**
22
+ * Listens on the instance's map canvas and returns how to stop (`inst.destroy()` also does). What the map cannot do itself it says through the
23
+ * instance, for the page shell (or the host) to answer: `inst.emit('select', node)` (a tap on a node), `inst.emit('background')` (a tap on the bare
24
+ * map: back to the normal view) and `inst.emit('grab')` (a hand takes the camera, so a flight to a match ends where it is).
25
+ * @param {ReturnType<typeof import('./instance.js').createInstance>} inst
26
+ */
27
+ export function bindCanvasInput(inst) {
28
+ const { state } = inst;
29
+ const { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom, setHoverNode, labelNodeAt, fitGraphToViewport, fitPadding } = inst.map;
30
+ const selectNode = (node) => inst.emit('select', node);
31
+ const closeDrawer = () => inst.emit('background');
32
+ const stopFlight = () => inst.emit('grab');
33
+
34
+ let isDragging = false;
35
+ let dragNode = null;
36
+ let lastPos = { x: 0, y: 0 };
37
+ let touchStartPos = { x: 0, y: 0 };
38
+ let touchMoved = false;
39
+ let pointerDownNode = null;
40
+ let lastTapNode = null;
41
+ let lastTapTime = 0;
42
+ let pinch = null; // the start of a two-finger gesture (camera.js pinchStart)
43
+ let downOnCanvas = false; // the press that is ending began on the map: a release elsewhere (a sheet's handle, a panel button) is not a tap on the background
44
+
45
+ // What the pointer did since the last frame; applied once per frame by applyMoves
46
+ let pendingPos = null;
47
+ let pendingPinch = null;
48
+ let pendingHover = null;
49
+ let hovering = false;
50
+ let restCursor = '';
51
+
52
+ const canDragNodes = () => state.isFreeform && state.view === 'orbit';
53
+
54
+ /** Where the pointer is, in the map's own pixels: the canvas's box on the screen may be scaled (a transform or `zoom` on an ancestor in a host's page) */
55
+ function getPointerPos(e) {
56
+ const rect = state.canvas.getBoundingClientRect();
57
+ const point = e.touches ? e.touches[0] : e;
58
+ const sx = rect.width && state.width ? state.width / rect.width : 1;
59
+ const sy = rect.height && state.height ? state.height / rect.height : 1;
60
+ return { x: (point.clientX - rect.left) * sx, y: (point.clientY - rect.top) * sy };
56
61
  }
57
- return byId.map.get(id) || null;
58
- }
59
-
60
- /** The topmost visible node under a screen point (a finger gets a wider reach), or null */
61
- function findNodeAt(screenX, screenY, isTouch) {
62
- const hit = hitTestScreen(getSpatialIndex(), state.camera, screenX, screenY, isTouch);
63
- return hit ? topologyNode(hit.id) : null;
64
- }
65
62
 
66
- const touchDistance = (e) => Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
67
- function touchMid(e) {
68
- const rect = state.canvas.getBoundingClientRect();
69
- return {
70
- x: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
71
- y: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
72
- };
73
- }
74
-
75
- function onPointerDown(e) {
76
- downOnCanvas = true;
77
- stopFlight(); // the hand takes the camera: a flight to a match ends where it is
78
- setHoverNode(null); // a press starts a tap or a drag: the chip that named a node under the pointer goes
79
- if (e.touches && e.touches.length === 2) {
80
- pinch = pinchStart(state.camera, touchDistance(e), touchMid(e));
81
- pendingPos = null;
82
- isDragging = false;
83
- dragNode = null;
84
- pointerDownNode = null;
85
- return;
63
+ // The topology node with this id (the grid answers with scene nodes, which are copies of the picture)
64
+ let byId = { nodes: null, size: -1, map: null };
65
+ function topologyNode(id) {
66
+ if (byId.nodes !== state.nodes || byId.size !== state.nodes.length) {
67
+ byId = { nodes: state.nodes, size: state.nodes.length, map: new Map(state.nodes.map((n) => [n.id, n])) };
68
+ }
69
+ return byId.map.get(id) || null;
86
70
  }
87
- const isTouch = !!(e.touches && e.touches.length > 0);
88
- const p = getPointerPos(e);
89
- touchStartPos = { x: p.x, y: p.y };
90
- touchMoved = false;
91
- pendingPos = null;
92
- pointerDownNode = findNodeAt(p.x, p.y, isTouch);
93
-
94
- if (canDragNodes() && pointerDownNode) {
95
- dragNode = pointerDownNode;
96
- if (e.cancelable) e.preventDefault();
97
- return;
71
+
72
+ /** The topmost visible node under a screen point (a finger gets a wider reach), or null */
73
+ function findNodeAt(screenX, screenY, isTouch) {
74
+ const hit = hitTestScreen(getSpatialIndex(), state.camera, screenX, screenY, isTouch);
75
+ return hit ? topologyNode(hit.id) : null;
98
76
  }
99
- isDragging = true; // otherwise the canvas pans
100
- lastPos = p;
101
- }
102
77
 
103
- /** One frame's worth of pointer movement: the pinch, the node being dragged, or the pan, from the latest position */
104
- function applyMoves() {
105
- if (pendingPinch && pinch) {
106
- Object.assign(state.camera, pinchCamera(pinch, pendingPinch.dist, pendingPinch.mid, getMinZoom()));
78
+ const touchDistance = (e) => Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
79
+ function touchMid(e) {
80
+ const rect = state.canvas.getBoundingClientRect();
81
+ return {
82
+ x: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
83
+ y: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
84
+ };
107
85
  }
108
- pendingPinch = null;
109
-
110
- const p = pendingPos;
111
- pendingPos = null;
112
- if (!p) return;
113
- if (dragNode && canDragNodes()) {
114
- const world = screenToWorld(p.x, p.y);
115
- dragNode.x = world.x;
116
- dragNode.y = world.y;
117
- state.freeformPositions[dragNode.id] = { x: world.x, y: world.y };
118
- touchScene(); // positions changed: the next scene (and so the grid) is built once, from this frame's position
119
- saveFreeformPositions();
120
- } else if (isDragging) {
121
- state.camera.x += p.x - lastPos.x;
122
- state.camera.y += p.y - lastPos.y;
86
+
87
+ function onPointerDown(e) {
88
+ downOnCanvas = true;
89
+ stopFlight(); // the hand takes the camera: a flight to a match ends where it is
90
+ setHoverNode(null); // a press starts a tap or a drag: the chip that named a node under the pointer goes
91
+ if (e.touches && e.touches.length === 2) {
92
+ pinch = pinchStart(state.camera, touchDistance(e), touchMid(e));
93
+ pendingPos = null;
94
+ isDragging = false;
95
+ dragNode = null;
96
+ pointerDownNode = null;
97
+ return;
98
+ }
99
+ const isTouch = !!(e.touches && e.touches.length > 0);
100
+ const p = getPointerPos(e);
101
+ touchStartPos = { x: p.x, y: p.y };
102
+ touchMoved = false;
103
+ pendingPos = null;
104
+ pointerDownNode = findNodeAt(p.x, p.y, isTouch);
105
+
106
+ if (canDragNodes() && pointerDownNode) {
107
+ dragNode = pointerDownNode;
108
+ if (e.cancelable) e.preventDefault();
109
+ return;
110
+ }
111
+ isDragging = true; // otherwise the canvas pans
123
112
  lastPos = p;
124
113
  }
125
- }
126
114
 
127
- /** Hover: a pointer cursor over a node. It changes no picture, so it asks for no draw. */
128
- function applyHover() {
129
- const p = pendingHover;
130
- pendingHover = null;
131
- if (!p || isDragging || dragNode) return;
132
- const over = findNodeAt(p.x, p.y, false);
133
- setHover(!!over);
134
- setHoverNode(over ? over.id : null); // a node with no label is named by a chip (labels.js)
135
- }
136
-
137
- function setHover(over) {
138
- if (over === hovering || !state.canvas) return;
139
- if (over) restCursor = state.canvas.style.cursor;
140
- hovering = over;
141
- state.canvas.style.cursor = over ? 'pointer' : restCursor;
142
- }
115
+ /** One frame's worth of pointer movement: the pinch, the node being dragged, or the pan, from the latest position */
116
+ function applyMoves() {
117
+ if (pendingPinch && pinch) {
118
+ Object.assign(state.camera, pinchCamera(pinch, pendingPinch.dist, pendingPinch.mid, getMinZoom()));
119
+ }
120
+ pendingPinch = null;
143
121
 
144
- function onPointerMove(e) {
145
- if (e.touches && e.touches.length === 2 && pinch) {
146
- if (e.cancelable) e.preventDefault();
147
- pendingPinch = { dist: touchDistance(e), mid: touchMid(e) };
148
- queueFrameWork(applyMoves);
149
- return;
122
+ const p = pendingPos;
123
+ pendingPos = null;
124
+ if (!p) return;
125
+ if (dragNode && canDragNodes()) {
126
+ const world = screenToWorld(p.x, p.y);
127
+ dragNode.x = world.x;
128
+ dragNode.y = world.y;
129
+ state.freeformPositions[dragNode.id] = { x: world.x, y: world.y };
130
+ inst.touchScene(); // positions changed: the next scene (and so the grid) is built once, from this frame's position
131
+ saveFreeformPositions(inst);
132
+ } else if (isDragging) {
133
+ state.camera.x += p.x - lastPos.x;
134
+ state.camera.y += p.y - lastPos.y;
135
+ lastPos = p;
136
+ }
150
137
  }
151
138
 
152
- const p = getPointerPos(e);
153
- if (Math.hypot(p.x - touchStartPos.x, p.y - touchStartPos.y) > 8) touchMoved = true;
139
+ /** Hover: a pointer cursor over a node. It changes no picture, so it asks for no draw. */
140
+ function applyHover() {
141
+ const p = pendingHover;
142
+ pendingHover = null;
143
+ if (!p || isDragging || dragNode) return;
144
+ const over = findNodeAt(p.x, p.y, false);
145
+ setHover(!!over);
146
+ setHoverNode(over ? over.id : null); // a node with no label is named by a chip (labels.js)
147
+ }
154
148
 
155
- if ((dragNode && canDragNodes()) || isDragging) {
156
- if (e.cancelable) e.preventDefault();
157
- pendingPos = p; // the latest position wins; the frame applies it
158
- queueFrameWork(applyMoves);
159
- return;
149
+ function setHover(over) {
150
+ if (over === hovering || !state.canvas) return;
151
+ if (over) restCursor = state.canvas.style.cursor;
152
+ hovering = over;
153
+ state.canvas.style.cursor = over ? 'pointer' : restCursor;
160
154
  }
161
- if (!e.touches) {
162
- pendingHover = p;
163
- queueFrameWork(applyHover, { draw: false });
155
+
156
+ function onPointerMove(e) {
157
+ if (e.touches && e.touches.length === 2 && pinch) {
158
+ if (e.cancelable) e.preventDefault();
159
+ pendingPinch = { dist: touchDistance(e), mid: touchMid(e) };
160
+ queueFrameWork(applyMoves);
161
+ return;
162
+ }
163
+
164
+ const p = getPointerPos(e);
165
+ if (Math.hypot(p.x - touchStartPos.x, p.y - touchStartPos.y) > 8) touchMoved = true;
166
+
167
+ if ((dragNode && canDragNodes()) || isDragging) {
168
+ if (e.cancelable) e.preventDefault();
169
+ pendingPos = p; // the latest position wins; the frame applies it
170
+ queueFrameWork(applyMoves);
171
+ return;
172
+ }
173
+ if (!e.touches) {
174
+ pendingHover = p;
175
+ queueFrameWork(applyHover, { draw: false });
176
+ }
164
177
  }
165
- }
166
178
 
167
- function onPointerUp(e) {
168
- applyMoves(); // the last position the pointer reached counts, even if no frame has run since
169
- const isTouch = !!(e.changedTouches && e.changedTouches.length > 0);
170
- const rect = state.canvas.getBoundingClientRect();
171
- const p = isTouch ? { x: e.changedTouches[0].clientX - rect.left, y: e.changedTouches[0].clientY - rect.top } : getPointerPos(e);
172
-
173
- // Only a touch or click that started and ended on the same node, without dragging, inspects it
174
- if (!touchMoved && downOnCanvas) {
175
- if (pointerDownNode) {
176
- const hitUp = findNodeAt(p.x, p.y, isTouch);
177
- if (hitUp && hitUp.id === pointerDownNode.id) {
178
- if (!canDragNodes()) {
179
- selectNode(pointerDownNode);
180
- } else {
181
- // Freeform: a double tap inspects, so dragging a node does not open the panel
182
- const now = Date.now();
183
- if (lastTapNode && lastTapNode.id === pointerDownNode.id && now - lastTapTime < 380) {
179
+ function onPointerUp(e) {
180
+ applyMoves(); // the last position the pointer reached counts, even if no frame has run since
181
+ const isTouch = !!(e.changedTouches && e.changedTouches.length > 0);
182
+ const rect = state.canvas.getBoundingClientRect();
183
+ const p = isTouch ? { x: e.changedTouches[0].clientX - rect.left, y: e.changedTouches[0].clientY - rect.top } : getPointerPos(e);
184
+
185
+ // Only a touch or click that started and ended on the same node, without dragging, inspects it
186
+ if (!touchMoved && downOnCanvas) {
187
+ if (pointerDownNode) {
188
+ const hitUp = findNodeAt(p.x, p.y, isTouch);
189
+ if (hitUp && hitUp.id === pointerDownNode.id) {
190
+ if (!canDragNodes()) {
184
191
  selectNode(pointerDownNode);
185
- lastTapNode = null;
186
- lastTapTime = 0;
187
192
  } else {
188
- lastTapNode = pointerDownNode;
189
- lastTapTime = now;
193
+ // Freeform: a double tap inspects, so dragging a node does not open the panel
194
+ const now = Date.now();
195
+ if (lastTapNode && lastTapNode.id === pointerDownNode.id && now - lastTapTime < 380) {
196
+ selectNode(pointerDownNode);
197
+ lastTapNode = null;
198
+ lastTapTime = 0;
199
+ } else {
200
+ lastTapNode = pointerDownNode;
201
+ lastTapTime = now;
202
+ }
190
203
  }
191
204
  }
205
+ } else {
206
+ // A cluster's title (its hub's label) is not a node to select: a click on it frames the cluster (spec 0008 D1)
207
+ const titled = topologyNode(labelNodeAt(p.x, p.y));
208
+ if (titled && LANDMARK_TYPES.includes(titled.type) && titled.id !== 'root') fitGraphToViewport(fitPadding(), clusterIds(titled.id, state.edges));
209
+ else if (state.selectedNode) closeDrawer(); // the background was clicked: back to the normal view
192
210
  }
193
- } else {
194
- // A cluster's title (its hub's label) is not a node to select: a click on it frames the cluster (spec 0008 D1)
195
- const titled = topologyNode(labelNodeAt(p.x, p.y));
196
- if (titled && LANDMARK_TYPES.includes(titled.type) && titled.id !== 'root') fitGraphToViewport(fitPadding(), clusterIds(titled.id, state.edges));
197
- else if (state.selectedNode) closeDrawer(); // the background was clicked: back to the normal view
198
211
  }
212
+ isDragging = false;
213
+ dragNode = null;
214
+ pointerDownNode = null;
215
+ pinch = null;
216
+ pendingPinch = null;
217
+ downOnCanvas = false;
199
218
  }
200
- isDragging = false;
201
- dragNode = null;
202
- pointerDownNode = null;
203
- pinch = null;
204
- pendingPinch = null;
205
- downOnCanvas = false;
206
- }
207
-
208
- export function bindCanvasInput() {
209
- const { canvas } = state;
210
- canvas.addEventListener('mousedown', onPointerDown);
211
- canvas.addEventListener('mousemove', onPointerMove);
212
- canvas.addEventListener('mouseleave', () => { pendingHover = null; setHover(false); setHoverNode(null); });
213
- window.addEventListener('mouseup', onPointerUp);
214
219
 
215
- canvas.addEventListener('touchstart', onPointerDown, { passive: false });
216
- canvas.addEventListener('touchmove', onPointerMove, { passive: false });
217
- window.addEventListener('touchend', onPointerUp, { passive: false });
218
- window.addEventListener('touchcancel', onPointerUp, { passive: false });
219
220
 
220
- canvas.addEventListener('wheel', (e) => {
221
+ const { canvas } = state;
222
+ // In another app's page (a root that is not the document) the wheel is the page's until the map is asked for it: the map has the focus
223
+ // (a click or Tab put it there), or Ctrl or Cmd is held (a trackpad's pinch comes so). A pointer passing over the map does not stop the page scrolling.
224
+ const embedded = !(inst.root && inst.root.nodeType === 9);
225
+ const onWheel = (e) => {
226
+ if (embedded && !e.ctrlKey && !e.metaKey && inst.active() !== state.canvas) return;
221
227
  e.preventDefault();
222
228
  stopFlight();
223
229
  const p = getPointerPos(e);
224
230
  Object.assign(state.camera, zoomAbout(state.camera, e.deltaY < 0 ? 1.12 : 0.88, p.x, p.y, getMinZoom()));
225
231
  render(); // a camera change is cheap; the draw is one per frame however many wheel events arrive
226
- }, { passive: false });
232
+ };
233
+ // The press and the drag begin on the canvas; the release can end anywhere, so it is heard on the instance's root
234
+ const root = inst.root || canvas;
235
+ const stops = [
236
+ inst.listen(canvas, 'mousedown', onPointerDown),
237
+ inst.listen(canvas, 'mousemove', onPointerMove),
238
+ inst.listen(canvas, 'mouseleave', () => { pendingHover = null; setHover(false); setHoverNode(null); }),
239
+ inst.listen(root, 'mouseup', onPointerUp),
240
+ inst.listen(canvas, 'touchstart', onPointerDown, { passive: false }),
241
+ inst.listen(canvas, 'touchmove', onPointerMove, { passive: false }),
242
+ inst.listen(root, 'touchend', onPointerUp, { passive: false }),
243
+ inst.listen(root, 'touchcancel', onPointerUp, { passive: false }),
244
+ inst.listen(canvas, 'wheel', onWheel, { passive: false }),
245
+ ];
246
+ return () => stops.forEach((off) => off());
227
247
  }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @module explorer/instance-state
3
+ *
4
+ * What an instance holds: the explorer's state object, one per instance (instance.js `createInstance`). ES module bindings cannot be
5
+ * reassigned from another module, so everything that more than one module reads or writes lives here as a property: the topology,
6
+ * which layers are on, the camera, the selection, the view. cornfield's own page has one (explorer/state.js hands it to the modules
7
+ * that are not yet on an instance).
8
+ */
9
+
10
+ /** A new state object, as the explorer starts: nothing loaded, the default layers on */
11
+ export function createState() {
12
+ return {
13
+ /** The map canvas, and a 2d context used only to measure text (layout.js), set by the page shell before anything draws */
14
+ canvas: /** @type {HTMLCanvasElement|null} */ (null),
15
+ ctx: /** @type {CanvasRenderingContext2D|null} */ (null),
16
+ /** The transparent canvas stacked over `canvas` that draws every label (labels.js); null = no labels */
17
+ labelCanvas: /** @type {HTMLCanvasElement|null} */ (null),
18
+ width: 0,
19
+ height: 0,
20
+ /** Height (px) of the bottom of the map the phone's sheets cover (sheets.js); 0 on a desktop. The fit and the scenario camera leave it out. */
21
+ coveredBottom: 0,
22
+
23
+ /** topology.json: every node has x/y assigned by layout.js (the file stores no positions) */
24
+ nodes: [],
25
+ edges: [],
26
+
27
+ /** 'orbit' (the whole map), 'dataflow' (the preset: browser -> servers -> API -> tables -> services -> outside) or 'house' (the House preset, PHY-11) */
28
+ view: 'orbit',
29
+ /** What the data-flow preset shows, built by flows.js buildDataFlow() when the topology loads */
30
+ flow: null,
31
+ /** The orbital rings layout.js drew the positions on */
32
+ rings: { rings: [], clusters: [] },
33
+
34
+ /** 'dark' or 'light': the ground the map is drawn for (theme.js keeps it, from the system and the toggle); a change must `touchScene()` */
35
+ theme: 'dark',
36
+
37
+ camera: { x: 0, y: 0, zoom: 1 },
38
+ selectedNode: null,
39
+ /** The node panel's "Include its children's lines" switch (spec 0008 D5): off, a selection lights one hop; on, the children's neighbours too. Kept across selections */
40
+ throughChildren: false,
41
+ /** The edge kind the panel chose to light alone (selection-model.js), or null for every kind; a new selection clears it */
42
+ selectedKind: null,
43
+ /** The config's `forge` (`{ type, url, repo, baseBranch? }`), or null: where a node's file is opened (file-url.js) */
44
+ forge: null,
45
+ searchQuery: '',
46
+ /** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
47
+ searchCurrent: null,
48
+ /** The id of the node the pointer is on (input.js): a node with no label is named by a chip while it is */
49
+ hoverNodeId: null,
50
+
51
+ isFreeform: false,
52
+ freeformPositions: {},
53
+
54
+ /**
55
+ * Layer key -> on. The infra layer is its own view, so it starts off, and so do the physical world's
56
+ * (spec 0029): machines, containers, devices, the house and people. Turning one of the live ones on
57
+ * (live-model.js LIVE_LAYERS) is what first loads the live layer.
58
+ */
59
+ activeLayers: {
60
+ app: true, pkg: true, page: true, atom: true, molecule: true, token: true, tool: true,
61
+ flow: true, table: true, rom: true, service: true, cloud: true, web: true, stack: false,
62
+ machine: false, container: false, device: false, house: false, persona: false,
63
+ },
64
+
65
+ /**
66
+ * The project's own layers (spec 0009): `{ key, label, desc?, match }` in `add` order, as the config sent them (core/layers.js); a node is
67
+ * in the first one whose match it meets (explorer/layer-model.js). `layerOrder` is the config's `order`; `layerDefaults` what each layer is
68
+ * when the viewer has not touched it (layers.js `setProjectLayers`). Empty with no `layers` in the config: the menu is then the starting set.
69
+ */
70
+ projectLayers: [],
71
+ layerOrder: [],
72
+ layerDefaults: {},
73
+
74
+ /**
75
+ * The review of the open proposal, which narrows the map to the change (issue #232; explorer/layer-model.js `layersOf`): null with no proposal open,
76
+ * else `{ whole, manual, step, rev }`. `whole`: "Show the whole map" is on, the map is as Diff always was. `manual`: layers the reviewer turned on or
77
+ * off by hand in this review, `step`: the ones a playing scenario turned on (both `{ key: boolean }`). `rev` moves with each change.
78
+ * None of it is the viewer's: `activeLayers` and the saved choices (layers.js) are never written while it is set.
79
+ */
80
+ review: null,
81
+
82
+ /**
83
+ * The map as the last `setMap` (view.js) was handed it, before the live layer is laid in: the base
84
+ * copies, or a proposal applied over them. `nodes` and `edges` are these plus the live ones.
85
+ */
86
+ mapNodes: [],
87
+ mapEdges: [],
88
+
89
+ /**
90
+ * The live layer (live.js, spec 0029 section 4), in memory only and never stored anywhere: the
91
+ * runner's snapshot `{ status, answer, error, lastOkAt }` and what merging it found: `counts`
92
+ * (persona id -> accounts), `other` (accounts no persona counts), `linked` (node id -> its
93
+ * inventory item). null until a live layer is first turned on.
94
+ */
95
+ live: null,
96
+
97
+ /**
98
+ * The House view (house.js, house-model.js, spec 0029 section 7): its settings (`floor`, `phone`, `software`, the
99
+ * rooms opened past their "+N", the plugin's default plan) and what its last layout found (what it shows, its bands
100
+ * and tray, the fit, each thing's floor). null until the view is first opened.
101
+ */
102
+ house: null,
103
+
104
+ /**
105
+ * The map as topology.json holds it: never laid out, never changed. `nodes` and `edges` above are
106
+ * copies of these (or `applyProposal` of them while a proposal is open), which is what makes
107
+ * Before, After and closing a proposal exact.
108
+ */
109
+ baseNodes: [],
110
+ baseEdges: [],
111
+
112
+ /**
113
+ * The proposal open on the map (proposal.js, spec 0012 B2): the parsed file or null. While it is
114
+ * set, `nodes` and `edges` are `applyProposal(base, proposal)`: each carries `mark` (and `before`,
115
+ * `why` when changed or removed). `proposalView` is what scene.js shows of that: 'before' | 'diff' |
116
+ * 'after'. `proposalSource` is where it was found ('checkout' or a worktree name), `proposalSlug` its
117
+ * file name without `.json`, `proposalErrors` what `validateProposal` found against the base.
118
+ */
119
+ proposal: null,
120
+ proposalView: 'diff',
121
+ proposalSource: null,
122
+ /** The open proposal's file as the server sent it, its SHA-256 (X-Proposal-Sha256), or null: a review names it, so a push since is refused (spec 0007) */
123
+ proposalSha256: null,
124
+ proposalSlug: null,
125
+ proposalErrors: [],
126
+ /** Where each of the open proposal's mockups stands with the review, by position: 'approved' | 'changed' | 'unreviewed' | 'missing' (mockups.js; none read yet is empty) */
127
+ mockupStates: {},
128
+ /**
129
+ * The proposal the map is drawn from: `proposal` with what-if edits folded in (whatif.js, TOPO-11), or `proposal` itself
130
+ * when there are none; null with no proposal open. `proposal` is never changed: it is the robot's file.
131
+ */
132
+ effectiveProposal: null,
133
+ /** The maintainer's what-if edits to the open proposal, and what Undo took back (whatif-model.js): `{ edits, undone }` */
134
+ whatIf: { edits: [], undone: [] },
135
+ /** The My edits toggle is off: the map is drawn from the proposal as written, the edits are kept and still go with a review (whatif.js, spec 0007 D5) */
136
+ whatIfOff: false,
137
+ /** A marked edge picked on the map (nodes are `selectedNode`): the panel shows it, the scene does not change */
138
+ selectedEdge: null,
139
+
140
+ /**
141
+ * The scenario being played on the map: the player's snapshot (scenario.js `ScenarioSnapshot`:
142
+ * index, playing, done, visited, current, progress ...) or null. The ROM simulation's walk is one.
143
+ * scenario-ui.js owns it; scene.js lights it, and an outage's `down` its blast radius (outage-model.js).
144
+ */
145
+ scenario: null,
146
+
147
+ /**
148
+ * What the selected pull request lights (forge-panel.js, forge-panel-model.js `litFor`): `{ changed, failing }`, sets of
149
+ * node ids (the nodes its files are; the nodes of the tests a failing check names), or null with none selected.
150
+ */
151
+ forgeLit: null,
152
+
153
+ /**
154
+ * The runs on the map (explorer/runs-map.js): `{ flight: Map<nodeId, runId[]>, collide: Map<nodeId, runId[]>, runs }` for the open runs'
155
+ * nodes, or null when there are none. The map's marks over the nodes are drawn from it.
156
+ */
157
+ runsMap: null,
158
+
159
+ /**
160
+ * Which threads mention which nodes (forge-panel.js, docs/threads.md), for a node's panel: `{ for(nodeId) -> thread[] | null,
161
+ * ensure(), open(number) }`, or null when threads are off or there is no forge. `for` answers null until the list has been
162
+ * read; `ensure` reads it (once) and repaints the panel's "Threads"; `open` shows a thread in the issues and PRs panel.
163
+ */
164
+ threadIndex: null,
165
+
166
+ /**
167
+ * Changes whenever anything the scene is built from changes (scene.js). render.js rebuilds the
168
+ * scene only when this moved: never for a camera change or a packet frame.
169
+ */
170
+ sceneVersion: 0,
171
+ };
172
+ }