@graview/pages 0.2.0 → 0.2.1
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/held-element.d.ts +12 -0
- package/dist/held-element.d.ts.map +1 -0
- package/dist/held-element.js +90 -0
- package/dist/held-element.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/one-place-city.d.ts.map +1 -1
- package/dist/one-place-city.js +1125 -193
- package/dist/one-place-city.js.map +1 -1
- package/dist/one-place-control.d.ts +9 -0
- package/dist/one-place-control.d.ts.map +1 -1
- package/dist/one-place-control.js +9 -0
- package/dist/one-place-control.js.map +1 -1
- package/dist/one-place-geometry.d.ts +72 -1
- package/dist/one-place-geometry.d.ts.map +1 -1
- package/dist/one-place-geometry.js +104 -6
- package/dist/one-place-geometry.js.map +1 -1
- package/dist/one-place-signs.d.ts +59 -0
- package/dist/one-place-signs.d.ts.map +1 -0
- package/dist/one-place-signs.js +358 -0
- package/dist/one-place-signs.js.map +1 -0
- package/dist/one-place.d.ts +12 -4
- package/dist/one-place.d.ts.map +1 -1
- package/dist/one-place.js +264 -54
- package/dist/one-place.js.map +1 -1
- package/dist/page-context.d.ts +19 -0
- package/dist/page-context.d.ts.map +1 -1
- package/dist/page-context.js.map +1 -1
- package/dist/page-problems.d.ts.map +1 -1
- package/dist/page-problems.js +18 -6
- package/dist/page-problems.js.map +1 -1
- package/dist/page-record.d.ts.map +1 -1
- package/dist/page-record.js +3 -1
- package/dist/page-record.js.map +1 -1
- package/dist/page-shell.d.ts.map +1 -1
- package/dist/page-shell.js +20 -4
- package/dist/page-shell.js.map +1 -1
- package/dist/page-typography.d.ts.map +1 -1
- package/dist/page-typography.js +3 -2
- package/dist/page-typography.js.map +1 -1
- package/dist/router.d.ts +2 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +57 -5
- package/dist/router.js.map +1 -1
- package/package.json +6 -6
package/dist/one-place-city.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { labelOf, ONE_FACE_LAYERS } from "@graview/core";
|
|
3
|
+
import { RECORD_BOXES_ATTRIBUTE, RECORD_BOXES_MOVED, recordBoxesOf } from "@graview/core/record-boxes";
|
|
3
4
|
import { EMPTY_VIEW, toUrl, withOverview } from "@graview/layout/view";
|
|
4
5
|
import { Scene } from "@graview/react";
|
|
5
|
-
import { useGraview, useNavigation } from "@graview/react/provider";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { useGraview, useNavigation, useViolations } from "@graview/react/provider";
|
|
7
|
+
import { useOneFace } from "./one-place-control.js";
|
|
8
|
+
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
9
|
+
import { aimAt, anchorOf, BOARD_ASPECT, frameSpacingAt, boardFaceWidth, boardLeast, boardMost, boardWidthFor, fitBeside, fitCamera, SIGN_GAP, SIGN_POST, signRoom, cameraBetween, cameraPutting, CITY, cityArea, footOf, leaveFrom, routeLine, LEVEL_LIVE, levelZooms, PAGE, pageBox, PANEL, panelBox, PHONE, project, restingLevel, SHEET_ORIGIN, standingAt, standingCss, unionOf } from "./one-place-geometry.js";
|
|
10
|
+
import { placeSigns } from "./one-place-signs.js";
|
|
11
|
+
import { pluralOf } from "./page-typography.js";
|
|
8
12
|
/*
|
|
9
13
|
* THE CITY UNDER THE PAGE, AND ONE CAMERA OVER BOTH
|
|
10
14
|
* (Graview HQ feature:f-page-zooms-out-to-the-city).
|
|
@@ -40,6 +44,17 @@ import { aimAt, altitudeAt, anchorOf, BOARD_ASPECT, boardWidthFor, fitBeside, SI
|
|
|
40
44
|
* line, not three. A part scrolled out of the page draws none.
|
|
41
45
|
*/
|
|
42
46
|
const RECORD_PARTS = "[data-graview-pick], [data-graview-record], [data-record]";
|
|
47
|
+
/*
|
|
48
|
+
* AND WHAT A VIEW DRAWN WHERE THE PAGE CANNOT READ SAYS IT SHOWS (Graview
|
|
49
|
+
* HQ feature:f-one-face-lines-from-frame-views): a worker view's shadow
|
|
50
|
+
* root, a frame guest's document. The element it is drawn in holds its
|
|
51
|
+
* records' boxes, judged by its host (`RECORD_BOXES`), in its own pixels;
|
|
52
|
+
* each is carried through that element's box in this frame, so a line
|
|
53
|
+
* leaves it as it leaves a part of the page's own. A record page drawn by
|
|
54
|
+
* a view that names none of the records it draws still has its one line,
|
|
55
|
+
* from the view to the record it is about.
|
|
56
|
+
*/
|
|
57
|
+
const VIEW_PARTS = `[${RECORD_BOXES_ATTRIBUTE}]`;
|
|
43
58
|
const recordShownBy = (element) => element.getAttribute("data-graview-pick") ?? element.getAttribute("data-graview-record") ?? element.getAttribute("data-record");
|
|
44
59
|
/*
|
|
45
60
|
* THE CITY ON THIS FACE. The Scene's own zoom and its signs past the edge
|
|
@@ -47,19 +62,33 @@ const recordShownBy = (element) => element.getAttribute("data-graview-pick") ??
|
|
|
47
62
|
* the Scene's lines and words from a chosen record to what it is linked
|
|
48
63
|
* to: the page beside the city says those, and its lines leave from where
|
|
49
64
|
* it says them. The record the page is about stands out from the rest —
|
|
50
|
-
*
|
|
65
|
+
* lit in the accent and outlined, where it stands: lit changes no geometry,
|
|
66
|
+
* so a building pressed keeps its box to the pixel — while what it is linked to
|
|
51
67
|
* stays lit as the Scene lights it, and everything else is quiet.
|
|
52
68
|
*/
|
|
53
69
|
const CITY_CSS = `
|
|
54
70
|
[data-testid="one-place-city"] .graview-zoom, [data-testid="one-place-city"] .graview-edge-sign, [data-testid="one-place-city"] .graview-record-links, [data-testid="one-place-city"] .graview-drive-in { display: none; }
|
|
55
|
-
[data-testid="one-place-city"] .graview-building[data-graview-here] {
|
|
71
|
+
[data-testid="one-place-city"] .graview-building[data-graview-here] polygon { stroke: var(--graview-ink); stroke-width: 1.2; stroke-opacity: 1; }
|
|
56
72
|
[data-testid="one-place-city"] .graview-building[data-graview-here] .graview-iso-roof { fill: var(--graview-accent); }
|
|
57
73
|
[data-testid="one-place-city"] .graview-building[data-graview-here] .graview-iso-left { fill: color-mix(in srgb, var(--graview-accent) 55%, black); }
|
|
58
74
|
[data-testid="one-place-city"] .graview-building[data-graview-here] .graview-iso-right { fill: color-mix(in srgb, var(--graview-accent) 72%, black); }
|
|
75
|
+
[data-testid="one-place-city"] .graview-kind-face { filter: opacity(var(--graview-one-face-plates, 1)); }
|
|
76
|
+
[data-testid="one-place-city"][data-graview-names-said] .graview-kind-face { visibility: hidden !important; pointer-events: none !important; }
|
|
77
|
+
.graview-one-place-district { position: fixed; left: 0; top: 0; display: flex; gap: 4px; align-items: stretch; width: max-content; max-width: none; font-size: 0.75rem; line-height: 1.4; white-space: nowrap; }
|
|
78
|
+
.graview-one-place-district > button { touch-action: none; display: inline-flex; align-items: center; gap: 0.4em; box-sizing: border-box; min-height: 24px; min-width: 24px; margin: 0; padding: 1px 6px 2px; border: 1px solid var(--graview-edge); border-radius: 5px; background: var(--graview-panel, Canvas); color: var(--graview-ink); font: inherit; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,0.25); cursor: pointer; }
|
|
79
|
+
.graview-one-place-district > button:hover { border-color: var(--graview-accent); }
|
|
80
|
+
.graview-one-place-district > button:focus-visible { outline: 2px solid var(--graview-accent); outline-offset: 1px; }
|
|
81
|
+
.graview-one-place-district > [data-graview-district-problems] { color: var(--graview-warn); font-weight: 600; letter-spacing: 0; font-variant-numeric: tabular-nums; }
|
|
82
|
+
.graview-one-place-district [data-graview-district-tag-count] { color: var(--graview-ink-muted); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
|
|
83
|
+
@media (max-width: 600px) { .graview-one-place-district { font-size: 0.5625rem; } .graview-one-place-district > button { padding: 0 4px 1px; letter-spacing: 0.04em; } }
|
|
59
84
|
`;
|
|
60
85
|
const zoomNowOf = (cam) => cam.zoom().toFixed(4);
|
|
61
86
|
/** The most lines drawn from a page's parts: past this a list's lines are a hatch. */
|
|
62
87
|
const MOST_LINES = 40;
|
|
88
|
+
/** As many lines into one district as this, and they are one line into it with their count on it. */
|
|
89
|
+
const GATHER = 4;
|
|
90
|
+
/** What a district's "+n" is kept under among the picture's buildings: never a record's id. */
|
|
91
|
+
const REST_KEY = "\u0000rest:";
|
|
63
92
|
/** How long one level's move takes. A person who asked for less motion is cut straight there. */
|
|
64
93
|
export const MOVE_MS = 560;
|
|
65
94
|
/** A hand that has stopped zooming for this long has let go: the altitude settles to the nearest level. */
|
|
@@ -72,6 +101,10 @@ const keyOf = (where) => (where.type === "record" ? `record:${where.id}` : where
|
|
|
72
101
|
const ease = (t) => (t <= 0 ? 0 : t >= 1 ? 1 : t * t * (3 - 2 * t));
|
|
73
102
|
const level = (live) => Math.abs(live.s - 1) < 1e-4 && Math.abs(live.x) < 0.05 && Math.abs(live.y) < 0.05;
|
|
74
103
|
const clamp01 = (t) => Math.max(0, Math.min(1, t));
|
|
104
|
+
/** The same ids, in the same order. */
|
|
105
|
+
const sameIds = (a, b) => a.length === b.length && a.every((id, at) => id === b[at]);
|
|
106
|
+
/** Whether a point stands inside a box. */
|
|
107
|
+
const inside = (p, box) => p.x >= box.x && p.x <= box.x + box.width && p.y >= box.y && p.y <= box.y + box.height;
|
|
75
108
|
export function OnePlaceCity({ where, out, sheet, connected, boards, current, boardEls, boardLayer, fab, view, lessMotion, resolve, openRecord, openKind, onGround, motion, onAltitude }) {
|
|
76
109
|
const { store } = useGraview();
|
|
77
110
|
const { view: seen, go } = useNavigation();
|
|
@@ -116,11 +149,25 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
116
149
|
latestOut.current = out;
|
|
117
150
|
const latest = useRef({ openRecord, openKind });
|
|
118
151
|
latest.current = { openRecord, openKind };
|
|
119
|
-
|
|
152
|
+
/*
|
|
153
|
+
* NOTHING CHOSEN ON THE SCENE, AFTER A PRESS AS ON A FRESH LOAD. A page
|
|
154
|
+
* opened while the page is out (a building pressed, a link, a pill) says
|
|
155
|
+
* its subject to the provider as the page's choice: the Scene took it for
|
|
156
|
+
* its own, lit that building alone, faded the rest of the city, put the
|
|
157
|
+
* record at the head of its row and wrote its links' words over the city.
|
|
158
|
+
* Out, the Scene keeps nothing chosen — one rule, whichever way the page
|
|
159
|
+
* came — and the page's choice is kept for the page to have back. Read
|
|
160
|
+
* before the frame is painted, so nothing faded is ever drawn.
|
|
161
|
+
*/
|
|
162
|
+
useLayoutEffect(() => {
|
|
120
163
|
// While the page is read the view is the page's own, and none of this is the Scene's.
|
|
121
164
|
if (!latestOut.current || toUrl(seen) === asked.current)
|
|
122
165
|
return;
|
|
123
|
-
|
|
166
|
+
const picked = seen.selection ?? [];
|
|
167
|
+
// What the page chose is the page's — none, too, on a page of no one record — had back when it comes in again.
|
|
168
|
+
if (kept.current && (picked.length > 0 || (kept.current.selection ?? []).length > 0) && !sameIds(picked, kept.current.selection ?? []))
|
|
169
|
+
kept.current = { ...kept.current, selection: picked };
|
|
170
|
+
if (seen.overview && seen.focusId === null && picked.length === 0)
|
|
124
171
|
return;
|
|
125
172
|
const focus = seen.focusId;
|
|
126
173
|
const back = { ...wanted, ...(seen.pan ? { pan: seen.pan } : {}) };
|
|
@@ -136,31 +183,170 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
136
183
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
184
|
}, [seen]);
|
|
138
185
|
/*
|
|
139
|
-
* THE
|
|
140
|
-
*
|
|
141
|
-
*
|
|
186
|
+
* THE PLAZA'S ROOM AT THE TOP: the views of no one kind, in rows, under
|
|
187
|
+
* the bar. A kind's views find their own room beside its district
|
|
188
|
+
* (`placeSigns`), clear of every name the face says there.
|
|
142
189
|
*/
|
|
143
|
-
const roomKey = useMemo(() => {
|
|
144
|
-
const counts = new Map();
|
|
145
|
-
for (const board of boards) {
|
|
146
|
-
const kind = board.where.type === "record" ? null : signKindOf(board.where);
|
|
147
|
-
if (kind)
|
|
148
|
-
counts.set(kind, (counts.get(kind) ?? 0) + 1);
|
|
149
|
-
}
|
|
150
|
-
const width = boardWidthFor(view);
|
|
151
|
-
return JSON.stringify([...counts].sort().map(([kind, count]) => [kind, signRoom(count, width)]));
|
|
152
|
-
}, [boards, view]);
|
|
153
|
-
/* And the plaza's room at the top: the views of no one kind, in rows, under the bar. */
|
|
154
190
|
const plaza = useMemo(() => {
|
|
155
191
|
const count = boards.filter((board) => board.where.type !== "record" && signKindOf(board.where) === null).length;
|
|
156
192
|
return count === 0 ? 0 : Math.ceil(signRoom(count, boardWidthFor(view)).height + 12);
|
|
157
193
|
}, [boards, view]);
|
|
158
|
-
const sceneOptions = useMemo(() => ({
|
|
194
|
+
const sceneOptions = useMemo(() => ({ plaza: plaza + view.top }), [plaza, view.top]);
|
|
195
|
+
/*
|
|
196
|
+
* EACH DISTRICT'S NAME, said by this face: its kind's plural and how many
|
|
197
|
+
* it holds, a size on the screen at every level, placed with the views so
|
|
198
|
+
* nothing stands on it (`placeSigns`). The Scene's own names stand down
|
|
199
|
+
* as these come up: they were laid out for the Scene's own fit, and at
|
|
200
|
+
* this face's City most of them said nothing.
|
|
201
|
+
*/
|
|
202
|
+
const violations = useViolations();
|
|
203
|
+
const face = useOneFace();
|
|
204
|
+
// A district's problems: each broken rule that names one of its records, once.
|
|
205
|
+
const problemsOf = useMemo(() => {
|
|
206
|
+
const out = new Map();
|
|
207
|
+
for (const violation of violations) {
|
|
208
|
+
const kinds = new Set(violation.nodeIds.flatMap((id) => { const node = store.graph.getNode(id); return node ? [node.kind] : []; }));
|
|
209
|
+
for (const kind of kinds)
|
|
210
|
+
out.set(kind, (out.get(kind) ?? 0) + 1);
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}, [violations, store]);
|
|
214
|
+
const districtNames = store.schema.kinds.map((kind) => ({ kind, plural: pluralOf(store, kind), count: store.graph.count(kind), problems: problemsOf.get(kind) ?? 0 }));
|
|
215
|
+
const tagEls = useRef(new Map());
|
|
216
|
+
const tagLayer = useRef(null);
|
|
159
217
|
const state = useRef({ where, out, view, lessMotion, resolve, onAltitude, boards, current });
|
|
160
|
-
|
|
218
|
+
/*
|
|
219
|
+
* WHAT THE FRAME READS IS WHAT IS DRAWN. Written as the render ran, a
|
|
220
|
+
* render React paused part way (a route drawn as a transition) handed the
|
|
221
|
+
* frame a place whose page was not yet on the screen: the move began from
|
|
222
|
+
* the new place's board while the old page still stood there, and the new
|
|
223
|
+
* page came in a long task later, a leap inside the move. Written once the
|
|
224
|
+
* render is committed, the frame moves only what is drawn.
|
|
225
|
+
*/
|
|
226
|
+
useLayoutEffect(() => {
|
|
227
|
+
state.current = { where, out, view, lessMotion, resolve, onAltitude, boards, current };
|
|
228
|
+
});
|
|
161
229
|
useEffect(() => {
|
|
162
230
|
let frame = 0;
|
|
163
|
-
let world = { plots: new Map(), buildings: new Map()
|
|
231
|
+
let world = { plots: new Map(), buildings: new Map() };
|
|
232
|
+
/*
|
|
233
|
+
* NEARBY FRAMES WHAT THE RECORD IS CONNECTED TO (Graview HQ brief
|
|
234
|
+
* b-cloud-2026-11-13-connected-under-a-view): a record's page at Nearby
|
|
235
|
+
* is aimed beside the panel at the level's own zoom, unless the
|
|
236
|
+
* buildings of what it is linked to and what its page shows would fall
|
|
237
|
+
* outside the city's side of the window; then the camera stands back,
|
|
238
|
+
* no further than it must, to take them all in. That zoom is this
|
|
239
|
+
* page's Nearby, so the altitude read from the camera is the level's
|
|
240
|
+
* still, and the move there is the one move, as any level's is.
|
|
241
|
+
*/
|
|
242
|
+
let nearbyZoom = null;
|
|
243
|
+
/* What the last Nearby framing took in; a view that says its records after the move began is framed again, once, from where the camera is. */
|
|
244
|
+
let framedKey = "";
|
|
245
|
+
let reframeAsked = false;
|
|
246
|
+
/*
|
|
247
|
+
* ONCE A MOVE, AND NEVER OVER A HAND: armed as a move to a record's Nearby
|
|
248
|
+
* begins, taken by the first word from a view of what it shows after
|
|
249
|
+
* that, and put away once taken or the moment the person moves the
|
|
250
|
+
* camera themselves. A list a view grows later never takes the camera
|
|
251
|
+
* from where somebody left it.
|
|
252
|
+
*/
|
|
253
|
+
let reframeArmed = false;
|
|
254
|
+
const askReframe = () => {
|
|
255
|
+
if (reframeArmed)
|
|
256
|
+
reframeAsked = true;
|
|
257
|
+
};
|
|
258
|
+
const byHand = () => {
|
|
259
|
+
reframeArmed = false;
|
|
260
|
+
reframeAsked = false;
|
|
261
|
+
};
|
|
262
|
+
const framingKeyNow = (id) => `${id}|${[...new Set([id, ...store.graph.neighbors(id).map((node) => node.id), ...markedOnPage()])].sort().join(" ")}`;
|
|
263
|
+
const zoomsOf = (where, view) => {
|
|
264
|
+
const zooms = levelZooms(where, view);
|
|
265
|
+
return nearbyZoom !== null && where.type === "record" ? [zooms[0], nearbyZoom, zooms[2]] : zooms;
|
|
266
|
+
};
|
|
267
|
+
/** The records a page shows, by what its parts mark and what a view drawn in it says. */
|
|
268
|
+
const markedOnPage = () => {
|
|
269
|
+
const plane = sheet.current;
|
|
270
|
+
if (!plane)
|
|
271
|
+
return [];
|
|
272
|
+
const ids = [];
|
|
273
|
+
for (const part of plane.querySelectorAll(`${RECORD_PARTS}, ${VIEW_PARTS}`)) {
|
|
274
|
+
const view = recordBoxesOf(part);
|
|
275
|
+
if (view)
|
|
276
|
+
ids.push(...view.shows());
|
|
277
|
+
else {
|
|
278
|
+
const named = recordShownBy(part);
|
|
279
|
+
if (named)
|
|
280
|
+
ids.push(named);
|
|
281
|
+
}
|
|
282
|
+
if (ids.length > 400)
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
return ids;
|
|
286
|
+
};
|
|
287
|
+
const nearbyFraming = (id, anchor, most, zoomNow) => {
|
|
288
|
+
const now = state.current;
|
|
289
|
+
const view = now.view;
|
|
290
|
+
const base = cameraPutting(anchor, aimAt(PANEL, view, footRoom()), most);
|
|
291
|
+
const ids = new Set([id, ...store.graph.neighbors(id).map((node) => node.id), ...markedOnPage()]);
|
|
292
|
+
framedKey = `${id}|${[...ids].sort().join(" ")}`;
|
|
293
|
+
const kinds = new Set();
|
|
294
|
+
const boxes = [...ids].flatMap((one) => {
|
|
295
|
+
const building = world.buildings.get(one);
|
|
296
|
+
if (!building)
|
|
297
|
+
return [];
|
|
298
|
+
const kind = store.graph.getNode(one)?.kind;
|
|
299
|
+
if (kind)
|
|
300
|
+
kinds.add(kind);
|
|
301
|
+
return [building];
|
|
302
|
+
});
|
|
303
|
+
// And each of their districts, with its name: a district's marks stay in sight with its buildings.
|
|
304
|
+
const named = [...kinds].flatMap((kind) => {
|
|
305
|
+
const plot = world.plots.get(kind);
|
|
306
|
+
return plot ? [plot] : [];
|
|
307
|
+
});
|
|
308
|
+
const around = boxes.length > 1 ? unionOf([...boxes, ...named]) : null;
|
|
309
|
+
if (!around)
|
|
310
|
+
return base;
|
|
311
|
+
// The city's side of the window at Nearby: beside the panel above what stands at the foot, or above a phone's sheet and the control riding on it.
|
|
312
|
+
const bar = view.top ?? 0;
|
|
313
|
+
const panel = panelBox(view);
|
|
314
|
+
const dock = footNow().rest[0];
|
|
315
|
+
const area = view.width <= PHONE ? { x: 0, y: bar, width: view.width, height: Math.max(1, panel.y - bar - footRoom()) } : { x: 0, y: bar, width: panel.x, height: Math.max(1, (dock ? dock.y : view.height) - bar) };
|
|
316
|
+
const margin = 28;
|
|
317
|
+
/*
|
|
318
|
+
* ALREADY IN SIGHT, THE CAMERA STAYS: a record opened from the city
|
|
319
|
+
* beside the page, where it and everything it is connected to already
|
|
320
|
+
* stand in the city's side as the camera rests, moves no camera.
|
|
321
|
+
*/
|
|
322
|
+
const buildings = unionOf(boxes);
|
|
323
|
+
const inSight = (cam, box) => {
|
|
324
|
+
const lo = project(cam, { x: box.x, y: box.y });
|
|
325
|
+
const hi = project(cam, { x: box.x + box.width, y: box.y + box.height });
|
|
326
|
+
return lo.x >= area.x && lo.y >= area.y && hi.x <= area.x + area.width && hi.y <= area.y + area.height;
|
|
327
|
+
};
|
|
328
|
+
if (rest === PANEL && !move && level(painted) && buildings && inSight(LEVEL_LIVE, buildings))
|
|
329
|
+
return LEVEL_LIVE;
|
|
330
|
+
const a = project(base, { x: around.x, y: around.y });
|
|
331
|
+
const b = project(base, { x: around.x + around.width, y: around.y + around.height });
|
|
332
|
+
if (a.x >= area.x + margin && a.y >= area.y + margin && b.x <= area.x + area.width - margin && b.y <= area.y + area.height - margin)
|
|
333
|
+
return base;
|
|
334
|
+
const fit = fitCamera(around, area, margin, most);
|
|
335
|
+
// Never as far back as the City, nor past what the camera can be written at.
|
|
336
|
+
const least = Math.max(1.02 / zoomNow, (camera.current?.range.min ?? 0) / zoomNow);
|
|
337
|
+
if (fit.s >= least)
|
|
338
|
+
return fit;
|
|
339
|
+
/* More than the least zoom holds: the record's own building first, in the city's side, and as much else around it as fits. */
|
|
340
|
+
const middleOf = { x: around.x + around.width / 2, y: around.y + around.height / 2 };
|
|
341
|
+
const held = cameraPutting(middleOf, project(fit, middleOf), least);
|
|
342
|
+
const own = world.buildings.get(id);
|
|
343
|
+
if (!own)
|
|
344
|
+
return held;
|
|
345
|
+
const lo = project(held, { x: own.x, y: own.y });
|
|
346
|
+
const hi = project(held, { x: own.x + own.width, y: own.y + own.height });
|
|
347
|
+
const shift = (low, high, from, to) => (low < from ? from - low : high > to ? to - high : 0);
|
|
348
|
+
return { s: held.s, x: held.x + shift(lo.x, hi.x, area.x + margin, area.x + area.width - margin), y: held.y + shift(lo.y, hi.y, area.y + margin, area.y + area.height - margin) };
|
|
349
|
+
};
|
|
164
350
|
/** The camera between stops this frame, as painted — the last one seen while the view takes in a move just let go. */
|
|
165
351
|
let painted = LEVEL_LIVE;
|
|
166
352
|
/** The level the camera rests at, and the altitude this frame. */
|
|
@@ -172,8 +358,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
172
358
|
let cityFoot = "";
|
|
173
359
|
/** Where the camera stood when it came to rest at the City: a hand that moved it since keeps it. */
|
|
174
360
|
let cityAt = "";
|
|
175
|
-
/**
|
|
176
|
-
let
|
|
361
|
+
/** The camera at the level rested at as a scrub began: the person's own, kept for the scrub to leave from. */
|
|
362
|
+
let restCam = null;
|
|
177
363
|
/*
|
|
178
364
|
* THE ZOOM THIS FACE LAST LEFT THE CAMERA AT. Only a zoom that differs
|
|
179
365
|
* from it is a hand's: a new address at rest asks the camera for a
|
|
@@ -194,6 +380,62 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
194
380
|
let lastReported = "";
|
|
195
381
|
/* When the camera was last written into the view: the Scene settles what is painted a beat after (its wheel's rule), so nothing new is painted until that beat has passed. */
|
|
196
382
|
let committedAt = -Infinity;
|
|
383
|
+
/** When the last frame was drawn: a move does not count a stall between two as time gone by. */
|
|
384
|
+
let lastTick = 0;
|
|
385
|
+
/*
|
|
386
|
+
* THE PAGE CHOSEN IS DRAWN BEFORE IT MOVES. A new place's page is drawn
|
|
387
|
+
* by its route — on a slow machine, in tasks long enough to stall the
|
|
388
|
+
* frames after it — so a move to another place begins only once two
|
|
389
|
+
* frames running have come quickly (or a while has gone by, whatever the
|
|
390
|
+
* page is still doing): the page's drawing lands before the move, not
|
|
391
|
+
* inside it.
|
|
392
|
+
*/
|
|
393
|
+
let calmRun = 0;
|
|
394
|
+
/** The page a board was last placed for at once: one with no place to stand is not placed again every frame. */
|
|
395
|
+
let placedFor = "";
|
|
396
|
+
let placeSeenAt = 0;
|
|
397
|
+
let placeSeen = "";
|
|
398
|
+
const drawnSince = (placeKey, now) => {
|
|
399
|
+
if (placeKey !== placeSeen) {
|
|
400
|
+
placeSeen = placeKey;
|
|
401
|
+
placeSeenAt = now;
|
|
402
|
+
calmRun = 0;
|
|
403
|
+
}
|
|
404
|
+
return calmRun >= 2 || now - placeSeenAt > 700;
|
|
405
|
+
};
|
|
406
|
+
/*
|
|
407
|
+
* A PLACE READ AGAIN AT REST IS GONE TO, NOT JUMPED TO. Once the camera
|
|
408
|
+
* is written the Scene lays the city out again at that zoom, and a board
|
|
409
|
+
* or a name placed from it may stand a little elsewhere: it goes there
|
|
410
|
+
* over a moment, from where it was drawn.
|
|
411
|
+
*/
|
|
412
|
+
let settle = null;
|
|
413
|
+
/** A camera written in the frame before: what stood where the move ended is carried into the new pixels as this frame begins, the view drawing them now. */
|
|
414
|
+
let rebaseNext = null;
|
|
415
|
+
const SETTLE_MS = 300;
|
|
416
|
+
/*
|
|
417
|
+
* A name's box is carried whole: its size too, which differs between
|
|
418
|
+
* levels (a size on the screen is many times wider in the picture far
|
|
419
|
+
* out). Carried with the size it is going to, a box caught part way —
|
|
420
|
+
* a move begun again when what stands at the foot changed — had its
|
|
421
|
+
* middle moved by half the difference in one frame: a name leapt a
|
|
422
|
+
* hundred pixels sideways.
|
|
423
|
+
*/
|
|
424
|
+
const blend = (from, to, t) => {
|
|
425
|
+
if (!to || !from)
|
|
426
|
+
return to;
|
|
427
|
+
const at = { ...to, x: from.x + (to.x - from.x) * t, y: from.y + (to.y - from.y) * t };
|
|
428
|
+
if ("width" in to && "width" in from && "height" in to && "height" in from) {
|
|
429
|
+
const [a, b] = [from, to];
|
|
430
|
+
return { ...at, width: a.width + (b.width - a.width) * t, height: a.height + (b.height - a.height) * t };
|
|
431
|
+
}
|
|
432
|
+
return at;
|
|
433
|
+
};
|
|
434
|
+
/** How far a move or a settle has gone, this frame: 1 when nothing is under way. */
|
|
435
|
+
const goneAt = (now) => move ? { t: ease(clamp01((now - move.start) / MOVE_MS)), slots: move.slots, names: move.names } : settle && now - settle.start < SETTLE_MS ? { t: ease((now - settle.start) / SETTLE_MS), slots: settle.slots, names: settle.names } : { t: 1, slots: null, names: null };
|
|
436
|
+
/** Every board and name where it is drawn this frame. */
|
|
437
|
+
const drawnSlots = (now) => { const g = goneAt(now); return new Map([...slots].map(([key, at]) => [key, blend(g.slots?.get(key), at, g.t) ?? at])); };
|
|
438
|
+
const drawnNames = (now) => { const g = goneAt(now); return new Map([...names].map(([key, at]) => [key, blend(g.names?.get(key), at, g.t) ?? at])); };
|
|
197
439
|
const QUIET_MS = 220;
|
|
198
440
|
const lines = new Map();
|
|
199
441
|
/** The picture as laid out now, read while nothing is painted over it. */
|
|
@@ -208,20 +450,17 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
208
450
|
const buildings = new Map();
|
|
209
451
|
for (const building of holder.querySelectorAll("[data-graview-building]"))
|
|
210
452
|
buildings.set(building.getAttribute("data-graview-building"), boxOf(building.getBoundingClientRect()));
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
plates.set(kind, box);
|
|
223
|
-
}
|
|
224
|
-
return { plots, buildings, plates, named };
|
|
453
|
+
/*
|
|
454
|
+
* A district's "+n" — the buildings its plot has no room for — is words
|
|
455
|
+
* in the picture, as a building's name is: stood clear of as a building
|
|
456
|
+
* is, so no district's name runs into it ("+43PLANTS 10").
|
|
457
|
+
*/
|
|
458
|
+
holder.querySelectorAll(".graview-village-rest").forEach((rest, i) => {
|
|
459
|
+
const box = boxOf(rest.getBoundingClientRect());
|
|
460
|
+
if (box.width > 0)
|
|
461
|
+
buildings.set(`${REST_KEY}${i}`, box);
|
|
462
|
+
});
|
|
463
|
+
return { plots, buildings };
|
|
225
464
|
};
|
|
226
465
|
/** What a page stands on in the picture as it is laid out. */
|
|
227
466
|
const placeIn = (at, w) => ({
|
|
@@ -231,87 +470,108 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
231
470
|
all: [...w.plots.values()],
|
|
232
471
|
});
|
|
233
472
|
/**
|
|
234
|
-
* WHERE EACH VIEW
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
473
|
+
* WHERE EACH VIEW AND EACH DISTRICT'S NAME STANDS (`placeSigns`): a view
|
|
474
|
+
* of one kind on its district, its post coming down onto its ground, the
|
|
475
|
+
* rest on the plaza at the city's back edge, a record's own page on its
|
|
476
|
+
* building; each district's name beside it or under it. And the box
|
|
238
477
|
* around all of it, which the city's camera fits.
|
|
478
|
+
*
|
|
479
|
+
* PLACED ON THE SCREEN AS THE CAMERA WILL HAVE IT. Names and boards are a
|
|
480
|
+
* size on the screen, so the picture is carried through the camera the
|
|
481
|
+
* level is headed for (`cam`, against the view's own zoom; none at rest)
|
|
482
|
+
* and placed there, in the screen's own pixels, then carried back: the
|
|
483
|
+
* place a move heads for and the place read again once it has arrived
|
|
484
|
+
* are one answer, never a second that the boards then jump to.
|
|
485
|
+
*
|
|
486
|
+
* AND ONCE. The same city, the same window and the same views place the
|
|
487
|
+
* same way: kept, and carried along a pan (a pan moves the camera, not
|
|
488
|
+
* the city) until what is placed changes or the pan has gone far enough
|
|
489
|
+
* to change what is in sight.
|
|
239
490
|
*/
|
|
240
491
|
let slots = new Map();
|
|
492
|
+
let posts = new Map();
|
|
493
|
+
let scales = new Map();
|
|
494
|
+
let names = new Map();
|
|
241
495
|
/** The city and every view standing in it, as last read: what the city's camera fits. */
|
|
242
496
|
let whole = null;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
497
|
+
let kept = null;
|
|
498
|
+
/** A window too small for a board beside every district: a phone, or one turned on its side. */
|
|
499
|
+
const cramped = () => state.current.view.width <= PHONE || state.current.view.height <= 600;
|
|
500
|
+
const standAll = (w, zoomNow, cam, bounds, lvl) => {
|
|
501
|
+
const view = state.current.view;
|
|
502
|
+
const onScreen = (box) => ({ x: box.x * cam.s + cam.x, y: box.y * cam.s + cam.y, width: box.width * cam.s, height: box.height * cam.s });
|
|
503
|
+
const tiles = new Map([...w.plots].map(([kind, box]) => [kind, onScreen(box)]));
|
|
504
|
+
const city = unionOf([...tiles.values()]);
|
|
505
|
+
const origin = city ? { x: city.x, y: city.y } : { x: 0, y: 0 };
|
|
506
|
+
// A size on the screen at most, and on a small window at least: what it says is read.
|
|
507
|
+
const natural = boardWidthFor(view) * zoomNow * cam.s;
|
|
508
|
+
const width = Math.max(Math.min(natural, boardMost(view, state.current.where, zoomNow * cam.s)), boardLeast(view));
|
|
509
|
+
const k = width / Math.max(1e-6, natural);
|
|
510
|
+
const sizes = new Map();
|
|
511
|
+
for (const [kind, el] of tagEls.current) {
|
|
512
|
+
if (!tiles.has(kind) || el.offsetWidth === 0)
|
|
254
513
|
continue;
|
|
255
|
-
}
|
|
256
|
-
const kind = signKindOf(board.where);
|
|
257
|
-
if (kind && w.plots.has(kind))
|
|
258
|
-
byKind.set(kind, [...(byKind.get(kind) ?? []), board.key]);
|
|
259
|
-
else
|
|
260
|
-
plaza.push(board.key);
|
|
514
|
+
sizes.set(kind, { width: el.offsetWidth, height: el.offsetHeight });
|
|
261
515
|
}
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
boxes.push({ x: foot.x - width / 2, y: foot.y - height, width, height: height + SIGN_POST * zoomNow });
|
|
280
|
-
taken.push(signBox(foot));
|
|
281
|
-
}
|
|
516
|
+
const signs = state.current.boards.map((board) => ({
|
|
517
|
+
key: board.key,
|
|
518
|
+
kind: board.where.type === "record" ? board.where.kind : signKindOf(board.where),
|
|
519
|
+
building: board.where.type === "record" && w.buildings.has(board.where.id) ? onScreen(w.buildings.get(board.where.id)) : null,
|
|
520
|
+
}));
|
|
521
|
+
const reserved = footNow().now.map((box) => ({ x: box.x - 6, y: box.y - 6, width: box.width + 12, height: box.height + 12 }));
|
|
522
|
+
const round = (n) => Math.round(n / 2) * 2;
|
|
523
|
+
const rel = (box) => [round(box.x - origin.x), round(box.y - origin.y), round(box.width), round(box.height)];
|
|
524
|
+
const buildingsOnScreen = [...w.buildings.values()].map(onScreen);
|
|
525
|
+
const restsOnScreen = [...w.buildings].filter(([key]) => key.startsWith(REST_KEY)).map(([, box]) => onScreen(box));
|
|
526
|
+
// What decides the placing, the city's own lattice taken from where it stands: a pan of fewer than 24 pixels places nothing again.
|
|
527
|
+
const key = JSON.stringify([lvl, view.width, view.height, round(width), [...tiles].map(([kind, box]) => [kind, ...rel(box)]), buildingsOnScreen.length, buildingsOnScreen.reduce((sum, box) => sum + rel(box)[0] + rel(box)[1] * 3, 0), [...sizes].map(([kind, size]) => [kind, size.width, size.height]), signs.map((one) => [one.key, one.kind, one.building ? rel(one.building) : null]), bounds ? [Math.round((bounds.x - origin.x) / 24), Math.round((bounds.y - origin.y) / 24), Math.round(bounds.width / 24), Math.round(bounds.height / 24)] : null, reserved.map((box) => rel(box).map((n) => Math.round(n / 12)))]);
|
|
528
|
+
let placed;
|
|
529
|
+
let shift = { x: 0, y: 0 };
|
|
530
|
+
if (kept && kept.key === key) {
|
|
531
|
+
placed = kept.placed;
|
|
532
|
+
shift = { x: origin.x - kept.origin.x, y: origin.y - kept.origin.y };
|
|
282
533
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
534
|
+
else {
|
|
535
|
+
placed = placeSigns({
|
|
536
|
+
tiles,
|
|
537
|
+
buildings: buildingsOnScreen,
|
|
538
|
+
names: sizes,
|
|
539
|
+
words: restsOnScreen,
|
|
540
|
+
signs,
|
|
541
|
+
board: { width, height: width / BOARD_ASPECT, post: SIGN_POST * zoomNow * cam.s * k, gap: SIGN_GAP * zoomNow * cam.s * k },
|
|
542
|
+
...(bounds ? { bounds } : {}),
|
|
543
|
+
// Nor under what stands at the foot: the control, the legend over it and the timeline.
|
|
544
|
+
reserved,
|
|
545
|
+
// Beside the page on a small window a board too small to read, or with no clear place on its district, is not drawn: the bar reaches every view.
|
|
546
|
+
// Beside a page a board with no clear place on its district stands nowhere: the City stands every view, on a small window as high over its district as it takes (the City pans there).
|
|
547
|
+
dropCovered: lvl === PANEL,
|
|
548
|
+
// Beside a page on a desk a view's board may stand higher over its own district before it stands nowhere.
|
|
549
|
+
reach: lvl === CITY ? (cramped() ? 30 : 16) : cramped() ? 12 : 24,
|
|
550
|
+
// A board drawn smaller where it must; beside a page as small as its floor (`boardLeast`) before it stands nowhere.
|
|
551
|
+
shrink: lvl === PANEL || !cramped(),
|
|
552
|
+
...(lvl === PANEL ? { least: boardLeast(view) } : {}),
|
|
553
|
+
// Beside the page the plaza is behind the city: only the views that stand on a district stand there.
|
|
554
|
+
plaza: lvl !== PANEL,
|
|
555
|
+
});
|
|
556
|
+
kept = { key, origin, placed };
|
|
557
|
+
}
|
|
558
|
+
// Back into the picture's own pixels, as the view lays it out now.
|
|
559
|
+
const back = (p) => ({ x: (p.x + shift.x - cam.x) / cam.s, y: (p.y + shift.y - cam.y) / cam.s });
|
|
560
|
+
const backBox = (box) => ({ ...back(box), width: box.width / cam.s, height: box.height / cam.s });
|
|
561
|
+
const next = new Map([...placed.feet].map(([one, foot]) => [one, back(foot)]));
|
|
562
|
+
// A record's page whose building is not drawn stands where its district is.
|
|
563
|
+
for (const board of state.current.boards) {
|
|
564
|
+
if (next.has(board.key) || board.where.type !== "record")
|
|
565
|
+
continue;
|
|
566
|
+
const at = footOf(board.where, placeIn(board.where, w));
|
|
567
|
+
if (at)
|
|
568
|
+
next.set(board.key, at);
|
|
312
569
|
}
|
|
313
570
|
slots = next;
|
|
314
|
-
|
|
571
|
+
posts = new Map([...placed.posts].map(([one, length]) => [one, length / cam.s]));
|
|
572
|
+
scales = new Map(placed.scales);
|
|
573
|
+
names = new Map([...placed.names].map(([kind, box]) => [kind, backBox(box)]));
|
|
574
|
+
whole = placed.whole ? backBox(placed.whole) : null;
|
|
315
575
|
};
|
|
316
576
|
/*
|
|
317
577
|
* WHAT STANDS AT THE FOOT: the control, the legend over it when it is
|
|
@@ -336,6 +596,31 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
336
596
|
const dock = rest[0];
|
|
337
597
|
return { now, rest, key: dock ? `${Math.round(dock.x)},${Math.round(dock.y)},${Math.round(dock.width)},${Math.round(dock.height)}` : "" };
|
|
338
598
|
};
|
|
599
|
+
/** The part of the window the City is seen in, at rest there: under the bar, over what stands at the foot. */
|
|
600
|
+
const cityShown = () => {
|
|
601
|
+
const view = state.current.view;
|
|
602
|
+
const top = (view.top ?? 0) + 12;
|
|
603
|
+
const foot = Math.min(view.height, ...footNow().rest.map((box) => box.y)) - 12;
|
|
604
|
+
return { x: 12, y: top, width: view.width - 24, height: Math.max(1, foot - top) };
|
|
605
|
+
};
|
|
606
|
+
/** And the part it is seen in beside the page, at Nearby: left of the panel on a desk, over the sheet on a phone. */
|
|
607
|
+
const nearbyShown = () => {
|
|
608
|
+
const view = state.current.view;
|
|
609
|
+
const panel = panelBox(view);
|
|
610
|
+
const top = (view.top ?? 0) + 8;
|
|
611
|
+
// On a phone the control rides above the sheet at Nearby: the city is seen above both.
|
|
612
|
+
if (view.width <= PHONE)
|
|
613
|
+
return { x: 8, y: top, width: view.width - 16, height: Math.max(1, panel.y - footRoom() - 8 - top) };
|
|
614
|
+
return { x: 8, y: top, width: Math.max(1, panel.x - 16), height: Math.max(1, view.height - 8 - top) };
|
|
615
|
+
};
|
|
616
|
+
/** What everything is placed inside, at a level: at the City on a small window, nothing — the City pans there rather than shrink its words past reading. */
|
|
617
|
+
const shownAt = (lvl) => (lvl === CITY ? (cramped() ? undefined : cityShown()) : lvl === PANEL ? nearbyShown() : undefined);
|
|
618
|
+
/** Placed for where a move ends, through the camera it ends at: the same answer as read again there. */
|
|
619
|
+
const placeFor = (lvl, to, zoomNow) => {
|
|
620
|
+
if (lvl === PAGE)
|
|
621
|
+
return;
|
|
622
|
+
standAll(world, zoomNow, to, shownAt(lvl), lvl);
|
|
623
|
+
};
|
|
339
624
|
/** How much of the window above a phone's sheet the control and the legend keep, at Nearby. */
|
|
340
625
|
const footRoom = () => {
|
|
341
626
|
const dock = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
|
|
@@ -351,7 +636,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
351
636
|
/** The camera a level asks for, against the view's own: how much closer than now, and the place where that level aims it. */
|
|
352
637
|
const cameraFor = (lvl, anchor, zoomNow) => {
|
|
353
638
|
const now = state.current;
|
|
354
|
-
const zooms =
|
|
639
|
+
const zooms = zoomsOf(now.where, now.view);
|
|
355
640
|
const s = zooms[lvl] / zoomNow;
|
|
356
641
|
if (lvl === CITY) {
|
|
357
642
|
/*
|
|
@@ -362,14 +647,71 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
362
647
|
* held: the camera goes straight there and stops.
|
|
363
648
|
*/
|
|
364
649
|
if (whole) {
|
|
365
|
-
|
|
366
|
-
|
|
650
|
+
/*
|
|
651
|
+
* The names are a size on the screen: at the City they take less of
|
|
652
|
+
* the picture than where it was read. Placed again for the City's
|
|
653
|
+
* own scale, and fitted again, until the two agree.
|
|
654
|
+
*/
|
|
655
|
+
let fitted = fitBeside(whole, now.view, footNow().rest, 20, s);
|
|
656
|
+
for (let again = 0; again < 2; again++) {
|
|
657
|
+
standAll(world, zoomNow, fitted, undefined, CITY);
|
|
658
|
+
if (!whole)
|
|
659
|
+
break;
|
|
660
|
+
fitted = fitBeside(whole, now.view, footNow().rest, 20, s);
|
|
661
|
+
}
|
|
662
|
+
if (!whole)
|
|
663
|
+
return fitted;
|
|
367
664
|
// Never past what the camera can be written at: a fit below its reach was painted, then put back up when written — an overshoot.
|
|
368
665
|
const least = (camera.current?.range.min ?? 0) / zoomNow;
|
|
369
666
|
if (fitted.s >= least)
|
|
370
667
|
return fitted;
|
|
371
|
-
|
|
372
|
-
|
|
668
|
+
/*
|
|
669
|
+
* AS FAR OUT AS THE CAMERA GOES, AND EVERYTHING INSIDE WHAT IT SHOWS
|
|
670
|
+
* from there: the city in the middle of the window's part for it,
|
|
671
|
+
* and the names and views placed again inside that part — closer
|
|
672
|
+
* together, rather than past the window's edge (a phone's City).
|
|
673
|
+
*/
|
|
674
|
+
const city = unionOf([...world.plots.values()]) ?? whole;
|
|
675
|
+
const area = cityShown();
|
|
676
|
+
const at = cameraPutting(middle(city), middle(area), least);
|
|
677
|
+
standAll(world, zoomNow, at, shownAt(CITY), CITY);
|
|
678
|
+
return at;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/*
|
|
682
|
+
* THE HOME BESIDE THE CITY: the city framed in the part the page leaves
|
|
683
|
+
* it — left of the panel on a desk, over the sheet on a phone — never
|
|
684
|
+
* the whole window, where the districts nearest the page stood behind it.
|
|
685
|
+
*/
|
|
686
|
+
if (lvl === PANEL && (now.where.type === "home" || now.where.type === "overview")) {
|
|
687
|
+
const city = unionOf([...world.plots.values()]);
|
|
688
|
+
if (city) {
|
|
689
|
+
const shown = nearbyShown();
|
|
690
|
+
const fit = fitCamera(city, shown, 16, s);
|
|
691
|
+
// Never past what the camera can be written at: there the whole city does not fit beside the page, and the districts the home's views show are what stands in the city's side.
|
|
692
|
+
const least = (camera.current?.range.min ?? 0) / zoomNow;
|
|
693
|
+
// Said on the city, for a reader of the page: whether the whole city stands beside the page here.
|
|
694
|
+
box.current?.toggleAttribute("data-graview-nearby-holds-the-city", fit.s >= least);
|
|
695
|
+
if (fit.s >= least)
|
|
696
|
+
return fit;
|
|
697
|
+
const kinds = new Set(markedOnPage().flatMap((id) => {
|
|
698
|
+
const kind = store.graph.getNode(id)?.kind;
|
|
699
|
+
return kind ? [kind] : [];
|
|
700
|
+
}));
|
|
701
|
+
const own = unionOf([...kinds].flatMap((kind) => {
|
|
702
|
+
const plot = world.plots.get(kind);
|
|
703
|
+
return plot ? [plot] : [];
|
|
704
|
+
}));
|
|
705
|
+
const what = own ?? city;
|
|
706
|
+
const close = fitCamera(what, shown, 16, s);
|
|
707
|
+
if (close.s >= least)
|
|
708
|
+
return close;
|
|
709
|
+
// As far out as the camera goes: the city as near the middle of its side as its views' districts let it, they in the side whole.
|
|
710
|
+
const held = cameraPutting(middle(city), middle(shown), least);
|
|
711
|
+
const lo = project(held, { x: what.x, y: what.y });
|
|
712
|
+
const hi = project(held, { x: what.x + what.width, y: what.y + what.height });
|
|
713
|
+
const shift = (low, high, from, to) => (low < from ? from - low : high > to ? to - high : 0);
|
|
714
|
+
return { s: held.s, x: held.x + shift(lo.x, hi.x, shown.x, shown.x + shown.width), y: held.y + shift(lo.y, hi.y, shown.y, shown.y + shown.height) };
|
|
373
715
|
}
|
|
374
716
|
}
|
|
375
717
|
if (lvl === CITY || now.where.type === "home" || now.where.type === "overview") {
|
|
@@ -377,12 +719,56 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
377
719
|
const middleOfCity = city ? middle(city) : anchor;
|
|
378
720
|
return cameraPutting(middleOfCity, aimAt(CITY, now.view), s);
|
|
379
721
|
}
|
|
722
|
+
if (lvl === PANEL && now.where.type === "record") {
|
|
723
|
+
const framed = nearbyFraming(now.where.id, anchor, s, zoomNow);
|
|
724
|
+
nearbyZoom = zoomNow * framed.s;
|
|
725
|
+
return framed;
|
|
726
|
+
}
|
|
727
|
+
if (lvl === PANEL)
|
|
728
|
+
nearbyZoom = null;
|
|
380
729
|
return cameraPutting(anchor, aimAt(lvl === PAGE ? PANEL : lvl, now.view, footRoom()), s);
|
|
381
730
|
};
|
|
382
731
|
/** Start a move of the camera to a level. */
|
|
383
|
-
|
|
732
|
+
/*
|
|
733
|
+
* THE CAMERA WRITTEN, THE PICTURE'S PIXELS ARE NEW: the Scene lays the
|
|
734
|
+
* city out again at the zoom written, and what stood where the move
|
|
735
|
+
* ended — through the camera it ended at — stands there in the new
|
|
736
|
+
* pixels: carried over at once, so the frame after the move draws every
|
|
737
|
+
* board and name where the frame before did.
|
|
738
|
+
*/
|
|
739
|
+
const rebase = (to) => {
|
|
740
|
+
const at = (p) => project(to, p);
|
|
741
|
+
const box = (b) => ({ ...at(b), width: b.width * to.s, height: b.height * to.s });
|
|
742
|
+
slots = new Map([...slots].map(([key, p]) => [key, at(p)]));
|
|
743
|
+
posts = new Map([...posts].map(([key, length]) => [key, length * to.s]));
|
|
744
|
+
names = new Map([...names].map(([key, b]) => [key, box(b)]));
|
|
745
|
+
whole = whole ? box(whole) : null;
|
|
746
|
+
settle = null;
|
|
747
|
+
world = { plots: new Map([...world.plots].map(([key, b]) => [key, box(b)])), buildings: new Map([...world.buildings].map(([key, b]) => [key, box(b)])) };
|
|
748
|
+
};
|
|
749
|
+
const moveTo = (cam, toLevel, anchor, now, arm = true) => {
|
|
750
|
+
reframeArmed = arm && toLevel === PANEL && state.current.where.type === "record";
|
|
384
751
|
const from = painted;
|
|
752
|
+
/*
|
|
753
|
+
* A PAGE CHOSEN AT REST LEAVES FROM WHERE ITS BOARD STANDS THERE. A
|
|
754
|
+
* building pressed at the City makes its record the page, and that page's
|
|
755
|
+
* board was placed nowhere yet: it would have started from where it will
|
|
756
|
+
* stand beside the page, forty pixels from the building pressed. Placed
|
|
757
|
+
* first where the camera rests, so the move carries it from there.
|
|
758
|
+
*/
|
|
759
|
+
// Where everything is drawn now is where it moves from: the page's own board, placed only now, joins them from where it stands at rest.
|
|
760
|
+
const namesFrom = drawnNames(now);
|
|
761
|
+
const slotsFrom = drawnSlots(now);
|
|
762
|
+
const own = state.current.current;
|
|
763
|
+
if (rest !== PAGE && !move && !slots.has(own) && level(painted)) {
|
|
764
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
765
|
+
const at = slots.get(own);
|
|
766
|
+
if (at)
|
|
767
|
+
slotsFrom.set(own, at);
|
|
768
|
+
}
|
|
769
|
+
settle = null;
|
|
385
770
|
const to = cameraFor(toLevel, anchor, cam.zoom());
|
|
771
|
+
placeFor(toLevel, to, cam.zoom());
|
|
386
772
|
const fromAltitude = altitude;
|
|
387
773
|
if (state.current.lessMotion) {
|
|
388
774
|
cam.liveTo(to);
|
|
@@ -391,6 +777,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
391
777
|
rest = toLevel;
|
|
392
778
|
cityFoot = "";
|
|
393
779
|
cam.commit();
|
|
780
|
+
rebaseNext = to;
|
|
394
781
|
committedAt = performance.now();
|
|
395
782
|
ownZoom = cam.zoom();
|
|
396
783
|
return;
|
|
@@ -403,11 +790,14 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
403
790
|
about: anchor,
|
|
404
791
|
start: now,
|
|
405
792
|
foot: footNow().key,
|
|
793
|
+
names: namesFrom,
|
|
794
|
+
slots: slotsFrom,
|
|
406
795
|
done: () => {
|
|
407
796
|
rest = toLevel;
|
|
408
797
|
altitude = toLevel;
|
|
409
798
|
cityFoot = "";
|
|
410
799
|
cam.commit();
|
|
800
|
+
rebaseNext = to;
|
|
411
801
|
committedAt = performance.now();
|
|
412
802
|
ownZoom = null;
|
|
413
803
|
},
|
|
@@ -415,6 +805,27 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
415
805
|
};
|
|
416
806
|
const tick = (now) => {
|
|
417
807
|
frame = requestAnimationFrame(tick);
|
|
808
|
+
/*
|
|
809
|
+
* A STALL IS NOT A LEAP. A move is clocked by the wall, and a frame the
|
|
810
|
+
* page could not draw (a chosen page's route drawn in one long task)
|
|
811
|
+
* left the next to catch the whole stall up at once: the page leapt a
|
|
812
|
+
* third of its way. A gap past 34 ms is taken out of the move's clock,
|
|
813
|
+
* so the move slows through it rather than jumps.
|
|
814
|
+
*/
|
|
815
|
+
if (lastTick > 0 && now - lastTick > 34) {
|
|
816
|
+
// And a settle after a re-read the same way: on a slow machine it goes over as many frames as on a quick one.
|
|
817
|
+
const lost = now - lastTick - 1000 / 60;
|
|
818
|
+
if (move)
|
|
819
|
+
move.start += lost;
|
|
820
|
+
if (settle)
|
|
821
|
+
settle.start += lost;
|
|
822
|
+
}
|
|
823
|
+
calmRun = lastTick > 0 && now - lastTick < 50 ? calmRun + 1 : 0;
|
|
824
|
+
lastTick = now;
|
|
825
|
+
if (rebaseNext) {
|
|
826
|
+
rebase(rebaseNext);
|
|
827
|
+
rebaseNext = null;
|
|
828
|
+
}
|
|
418
829
|
const holder = box.current;
|
|
419
830
|
const plane = sheet.current;
|
|
420
831
|
const cam = camera.current;
|
|
@@ -436,6 +847,9 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
436
847
|
plane.style.transform = "";
|
|
437
848
|
plane.style.opacity = "";
|
|
438
849
|
plane.style.borderRadius = "";
|
|
850
|
+
// A full page's room above and below again: the shell's own (the gutter the frame sets itself).
|
|
851
|
+
plane.style.removeProperty("--graview-frame-top");
|
|
852
|
+
plane.style.removeProperty("--graview-frame-foot");
|
|
439
853
|
draw([], 0);
|
|
440
854
|
}
|
|
441
855
|
return;
|
|
@@ -457,20 +871,46 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
457
871
|
painted = LEVEL_LIVE;
|
|
458
872
|
/*
|
|
459
873
|
* THE CITY READ AGAIN ONLY WHEN IT MAY HAVE MOVED: a camera written,
|
|
460
|
-
* the window or the
|
|
874
|
+
* the window, the views or what stands at the foot changed, or a while gone by (a record added
|
|
461
875
|
* lays its district out again) — never every frame of a page at rest.
|
|
462
876
|
*/
|
|
463
|
-
const readKey = `${at.view.width}x${at.view.height}|${at.boards.length}|${at.current}|${zoomNowOf(cam)}|${holder.querySelector(".graview-plots > g")?.getAttribute("transform") ?? ""}`;
|
|
877
|
+
const readKey = `${at.view.width}x${at.view.height}|${at.boards.length}|${at.current}|${zoomNowOf(cam)}|${holder.querySelector(".graview-plots > g")?.getAttribute("transform") ?? ""}|${footNow().key}`;
|
|
464
878
|
// An empty city is read again every frame until it has laid out; a pan moves the city's own transform, which is in the key.
|
|
465
|
-
|
|
879
|
+
/*
|
|
880
|
+
* NEVER PLACED AGAIN FOR WHERE A MOVE LEFT. The first frame of a move
|
|
881
|
+
* paints the camera it starts from, which is a level's: read again
|
|
882
|
+
* there (a slow machine's frame long past the half-second), the
|
|
883
|
+
* level being left was placed again over the one headed for, without
|
|
884
|
+
* the part beside the page it is placed inside — and the names, slid
|
|
885
|
+
* along to stay in it, leapt sideways. Under way, the city is placed
|
|
886
|
+
* only for where the move ends.
|
|
887
|
+
*/
|
|
888
|
+
if (world.plots.size === 0 || (!move && (readKey !== lastReadKey || committedAt > lastRead || now - lastRead > 500))) {
|
|
466
889
|
world = readWorld(holder);
|
|
467
|
-
|
|
890
|
+
if (move)
|
|
891
|
+
placeFor(move.toAltitude, move.to, cam.zoom());
|
|
892
|
+
else {
|
|
893
|
+
const drawnBefore = { slots: drawnSlots(now), names: drawnNames(now) };
|
|
894
|
+
// At the City everything stands inside what the camera shows; the camera was fitted to it.
|
|
895
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
896
|
+
settle = { ...drawnBefore, start: now };
|
|
897
|
+
}
|
|
468
898
|
lastRead = now;
|
|
469
899
|
lastReadKey = readKey;
|
|
470
900
|
}
|
|
471
901
|
}
|
|
902
|
+
/*
|
|
903
|
+
* A NEW PAGE'S BOARD IS PLACED THE FRAME IT IS DRAWN. Chosen by Find, a
|
|
904
|
+
* link or a building, the page is its own board until it moves — and
|
|
905
|
+
* with no place yet it stood a frame on its district's middle, then on
|
|
906
|
+
* its board: a jump before the move began. Placed at once, where the
|
|
907
|
+
* camera rests.
|
|
908
|
+
*/
|
|
909
|
+
if (world.plots.size > 0 && rest !== PAGE && !move && level(painted) && !slots.has(at.current) && placedFor !== at.current) {
|
|
910
|
+
placedFor = at.current;
|
|
911
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
912
|
+
}
|
|
472
913
|
const anchor = world.plots.size > 0 ? anchorIn(at.where, world) : null;
|
|
473
|
-
const zooms = levelZooms(at.where, at.view);
|
|
474
914
|
const zoomNow = cam.zoom();
|
|
475
915
|
const placeKey = `${keyOf(at.where)}|${at.view.width}x${at.view.height}`;
|
|
476
916
|
/* At the page, the camera waits where stepping out begins: aimed for each place before anything moves. */
|
|
@@ -485,10 +925,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
485
925
|
ready = true;
|
|
486
926
|
}
|
|
487
927
|
/* WHAT IS ASKED: a level (Up, Down, a press), or a scrub of the altitude by a hand on the page. */
|
|
488
|
-
if (ready && calm && anchor && asking.level !== null && !move && !settling) {
|
|
928
|
+
if (ready && calm && anchor && asking.level !== null && !move && !settling && (placeKey === lastPlace || drawnSince(placeKey, now))) {
|
|
489
929
|
const toLevel = asking.level;
|
|
490
930
|
asking.level = null;
|
|
491
|
-
if
|
|
931
|
+
// The level it rests at, asked again: back to that level's framing, if a hand has moved the camera from it.
|
|
932
|
+
const offFraming = () => {
|
|
933
|
+
const want = cameraFor(rest, anchor, zoomNow);
|
|
934
|
+
return Math.hypot(want.x - painted.x, want.y - painted.y) + Math.abs(want.s - painted.s) * 100 > 2;
|
|
935
|
+
};
|
|
936
|
+
if (toLevel !== rest || placeKey !== lastPlace || (rest !== PAGE && offFraming()))
|
|
492
937
|
moveTo(cam, toLevel, anchor, now);
|
|
493
938
|
lastPlace = placeKey;
|
|
494
939
|
}
|
|
@@ -501,7 +946,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
501
946
|
// The cameras of the levels either side, the one rested at as it is (a pan the person made is kept).
|
|
502
947
|
const lower = Math.floor(target);
|
|
503
948
|
const upper = Math.min(CITY, lower + 1);
|
|
504
|
-
|
|
949
|
+
// The level rested at is the camera as the person left it there — a pinch or a pan over the city beside the page kept — so the scrub leaves from where it is, never from a jump back to the framing.
|
|
950
|
+
const camOf = (lvl) => (lvl === rest && rest !== PAGE ? (restCam ??= painted) : cameraFor(lvl, anchor, zoomNow));
|
|
505
951
|
const placed = cameraBetween(camOf(lower), camOf(upper), anchor, target - lower);
|
|
506
952
|
cam.liveTo(placed);
|
|
507
953
|
painted = placed;
|
|
@@ -511,8 +957,17 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
511
957
|
}
|
|
512
958
|
if (asking.scrubbing && !asking.held && now - handSince > LET_GO_MS && !settling && calm) {
|
|
513
959
|
asking.scrubbing = false;
|
|
960
|
+
restCam = null;
|
|
514
961
|
if (anchor)
|
|
515
|
-
moveTo(cam, restingLevel(altitude), anchor, now);
|
|
962
|
+
moveTo(cam, restingLevel(altitude), anchor, now, false);
|
|
963
|
+
}
|
|
964
|
+
/* A VIEW'S RECORDS SAID AFTER NEARBY WAS FRAMED: framed again, the one camera moving there from where it is. */
|
|
965
|
+
if (reframeAsked && !move && !asking.scrubbing && !settling && calm && anchor) {
|
|
966
|
+
reframeAsked = false;
|
|
967
|
+
if (rest === PANEL && at.where.type === "record" && framingKeyNow(at.where.id) !== framedKey) {
|
|
968
|
+
reframeArmed = false;
|
|
969
|
+
moveTo(cam, PANEL, anchor, now, false);
|
|
970
|
+
}
|
|
516
971
|
}
|
|
517
972
|
/* A MOVE UNDER WAY: the camera set from how far it has got. */
|
|
518
973
|
if (move) {
|
|
@@ -529,7 +984,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
529
984
|
move.from = painted;
|
|
530
985
|
move.fromAltitude = altitude;
|
|
531
986
|
move.start = now;
|
|
987
|
+
move.names = drawnNames(now);
|
|
988
|
+
move.slots = drawnSlots(now);
|
|
532
989
|
move.to = cameraFor(move.toAltitude, move.about, cam.zoom());
|
|
990
|
+
placeFor(move.toAltitude, move.to, cam.zoom());
|
|
533
991
|
}
|
|
534
992
|
const t = clamp01((now - move.start) / MOVE_MS);
|
|
535
993
|
const e = ease(t);
|
|
@@ -546,12 +1004,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
546
1004
|
else if (!asking.scrubbing && !settling) {
|
|
547
1005
|
/*
|
|
548
1006
|
* AT REST, OR THE PERSON'S OWN HAND ON THE SCENE: a pinch or a
|
|
549
|
-
* ctrl+wheel over the city zooms its camera
|
|
550
|
-
*
|
|
551
|
-
* nearest level.
|
|
1007
|
+
* ctrl+wheel over the city zooms its camera and moves no level — at
|
|
1008
|
+
* Nearby and the City alike. A level is the page's to step.
|
|
552
1009
|
*/
|
|
553
1010
|
const effective = zoomNow * painted.s;
|
|
554
|
-
const atZoom = altitudeAt(effective, zooms);
|
|
555
1011
|
// The zoom a move just written into the view settles a beat later: it is the face's own once it is still.
|
|
556
1012
|
if (ownZoom === null && calm)
|
|
557
1013
|
ownZoom = effective;
|
|
@@ -586,14 +1042,20 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
586
1042
|
if (ownZoom !== null && Math.abs(Math.log(effective / ownZoom)) > 0.001)
|
|
587
1043
|
ownZoom = effective;
|
|
588
1044
|
}
|
|
589
|
-
else if (rest
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1045
|
+
else if (rest === PANEL) {
|
|
1046
|
+
/*
|
|
1047
|
+
* AT NEARBY THE CAMERA IS FREE TOO (Graview HQ
|
|
1048
|
+
* feature:f-one-face-explore-city-beside-panel). A pinch or a
|
|
1049
|
+
* ctrl+wheel over the city beside the page moves closer to what is
|
|
1050
|
+
* under the hand and back out, a drag or a scroll pans it, and the
|
|
1051
|
+
* page and the level stay where they are: a level is stepped by a
|
|
1052
|
+
* pinch over the page, the control or the keys — and the control
|
|
1053
|
+
* and the keys at Nearby bring the camera back to its framing.
|
|
1054
|
+
*/
|
|
1055
|
+
if (ownZoom !== null && Math.abs(Math.log(effective / ownZoom)) > 0.001)
|
|
1056
|
+
ownZoom = effective;
|
|
1057
|
+
if (placeKey === lastPlace)
|
|
1058
|
+
altitude = PANEL;
|
|
597
1059
|
}
|
|
598
1060
|
else if (!(rest !== PAGE && placeKey !== lastPlace))
|
|
599
1061
|
altitude = rest;
|
|
@@ -622,10 +1084,24 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
622
1084
|
ownZoom = null;
|
|
623
1085
|
}
|
|
624
1086
|
// Moving to another place at a level above the page: the camera flies there and stays at that level.
|
|
625
|
-
if (rest !== PAGE && !move && !asking.scrubbing && anchor && placeKey !== lastPlace && !settling && calm && holder.querySelector("[data-graview-settled]")) {
|
|
1087
|
+
if (rest !== PAGE && !move && !asking.scrubbing && anchor && placeKey !== lastPlace && !settling && calm && holder.querySelector("[data-graview-settled]") && drawnSince(placeKey, now)) {
|
|
626
1088
|
lastPlace = placeKey;
|
|
627
|
-
|
|
628
|
-
|
|
1089
|
+
/*
|
|
1090
|
+
* A RECORD OPENED BESIDE THE CITY WHERE IT IS SEEN IS LIT WHERE IT
|
|
1091
|
+
* STANDS. Pressed at Nearby (or opened by a link or a pill) with its
|
|
1092
|
+
* building in the part of the city the page leaves, the camera does
|
|
1093
|
+
* not move: every building keeps its box to the pixel, and only the
|
|
1094
|
+
* boards and names go over a moment to where they stand for it.
|
|
1095
|
+
*/
|
|
1096
|
+
const building = at.where.type === "record" ? world.buildings.get(at.where.id) : undefined;
|
|
1097
|
+
if (rest === PANEL && building && level(painted) && inside(project(painted, { x: building.x + building.width / 2, y: building.y + building.height / 2 }), nearbyShown())) {
|
|
1098
|
+
settle = { slots: drawnSlots(now), names: drawnNames(now), start: now };
|
|
1099
|
+
standAll(world, zoomNow, LEVEL_LIVE, shownAt(rest), rest);
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
// Chosen at the city — a Find result, a link — a page lands beside the city, as a view chosen there does.
|
|
1103
|
+
moveTo(cam, rest === CITY ? PANEL : rest, anchor, now);
|
|
1104
|
+
}
|
|
629
1105
|
}
|
|
630
1106
|
/* THE PAGE: its box from the altitude, then — past the panel — moved and scaled into its board, as the camera has it this frame. */
|
|
631
1107
|
const a = altitude;
|
|
@@ -641,10 +1117,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
641
1117
|
const panel = panelBox(at.view);
|
|
642
1118
|
const pageAt = pageBox(a, at.view);
|
|
643
1119
|
/* The boards' size this frame: their width in the picture, carried through the camera painted now. */
|
|
644
|
-
|
|
1120
|
+
// A size on the screen at most, as `standAll` placed them: at Nearby the camera is close.
|
|
1121
|
+
const boardWidth = Math.max(Math.min(boardWidthFor(at.view) * zoomNow * painted.s, boardMost(at.view, at.where, zoomNow * painted.s)), boardLeast(at.view));
|
|
645
1122
|
// The view the page goes into is as wide as it will be where the move ends: held, so the page shrinks one way only.
|
|
646
|
-
const intoWidth = move && move.toAltitude >= CITY ? boardWidthFor(at.view) * zoomNow * move.to.s : boardWidth;
|
|
647
|
-
|
|
1123
|
+
const intoWidth = move && move.toAltitude >= CITY ? Math.max(Math.min(boardWidthFor(at.view) * zoomNow * move.to.s, boardMost(at.view, at.where, zoomNow * move.to.s)), boardLeast(at.view)) : boardWidth;
|
|
1124
|
+
// Across a move, each board goes from where it stood to where it will stand, as the names do: the page's own with them, so a page chosen at the City leaves from the board pressed.
|
|
1125
|
+
const gone = goneAt(now);
|
|
1126
|
+
const carried = gone.t;
|
|
1127
|
+
const slotNow = (key) => blend(gone.slots?.get(key), slots.get(key), carried);
|
|
1128
|
+
const ownSlot = slotNow(at.current);
|
|
648
1129
|
const ownFoot = ownSlot ? project(painted, ownSlot) : anchor ? project(painted, anchor) : { x: at.view.width / 2, y: at.view.height / 2 };
|
|
649
1130
|
const standing = away && a > PANEL ? standingAt(a, panel, ownFoot, intoWidth) : null;
|
|
650
1131
|
if (away) {
|
|
@@ -659,6 +1140,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
659
1140
|
plane.style.borderRadius = `${(a >= PANEL ? 10 / (standing?.scale ?? 1) : 10 * a).toFixed(2)}px`;
|
|
660
1141
|
if (standing && plane.scrollTop !== 0 && a > 1.9)
|
|
661
1142
|
plane.scrollTop = 0;
|
|
1143
|
+
// Its gutter and its room above and below, a full page's at the page and a panel's beside the city, every step between drawn (written only when a pixel changes).
|
|
1144
|
+
for (const [name, value] of Object.entries(frameSpacingAt(a)))
|
|
1145
|
+
if (plane.style.getPropertyValue(name) !== value)
|
|
1146
|
+
plane.style.setProperty(name, value);
|
|
662
1147
|
}
|
|
663
1148
|
else {
|
|
664
1149
|
plane.style.transform = "";
|
|
@@ -673,36 +1158,128 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
673
1158
|
list.style.height = `${((inner?.scrollHeight ?? 0) * ease(grown)).toFixed(2)}px`;
|
|
674
1159
|
list.style.opacity = String(ease(grown));
|
|
675
1160
|
}
|
|
676
|
-
/*
|
|
677
|
-
|
|
1161
|
+
/*
|
|
1162
|
+
* THE BOARDS: each on its slot, through this frame's camera, at the
|
|
1163
|
+
* page's own size scaled — a size on the screen at most. The views
|
|
1164
|
+
* stand at Nearby as at the City; the page's own board is the page
|
|
1165
|
+
* itself, and is drawn only once the page has become it.
|
|
1166
|
+
*/
|
|
1167
|
+
const shownBoards = a >= PANEL ? 1 : ease(clamp01((a - 0.6) / 0.4));
|
|
1168
|
+
const shownOwn = ease(clamp01((a - 1.25) / 0.6));
|
|
678
1169
|
const layer = boardLayer.current;
|
|
679
1170
|
if (layer) {
|
|
680
|
-
const reachable = a >
|
|
1171
|
+
const reachable = a > 0.95 && !move;
|
|
681
1172
|
if (layer.inert === reachable)
|
|
682
1173
|
layer.inert = !reachable;
|
|
683
1174
|
layer.setAttribute("data-graview-boards-shown", shownBoards.toFixed(3));
|
|
684
1175
|
}
|
|
1176
|
+
/*
|
|
1177
|
+
* NOTHING OF THE CITY'S UNDER THE BAR, THE PAGE OR THE LEVEL CONTROL —
|
|
1178
|
+
* after a hand's pan too, which carries what was placed with the city
|
|
1179
|
+
* until it is placed again: a board or a district's name that a pan
|
|
1180
|
+
* has brought under one of them is put away (unseen, unreached) until
|
|
1181
|
+
* it comes out again.
|
|
1182
|
+
*/
|
|
1183
|
+
const dockRect = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
|
|
1184
|
+
const keepOut = move
|
|
1185
|
+
? []
|
|
1186
|
+
: [
|
|
1187
|
+
{ x: 0, y: 0, width: at.view.width, height: at.view.top ?? 0 },
|
|
1188
|
+
...(a > 0.5 && a < 1.5 ? [boxOf(plane.getBoundingClientRect())] : []),
|
|
1189
|
+
...(dockRect && dockRect.width > 0 ? [boxOf(dockRect)] : []),
|
|
1190
|
+
];
|
|
1191
|
+
const under = (b) => keepOut.some((k) => Math.min(b.x + b.width, k.x + k.width) - Math.max(b.x, k.x) > 1 && Math.min(b.y + b.height, k.y + k.height) - Math.max(b.y, k.y) > 1);
|
|
1192
|
+
// Every board and name a press reaches this frame: a line's ring under or against one of them is not offered.
|
|
1193
|
+
pressable.length = 0;
|
|
685
1194
|
for (const [key, button] of boardEls.current ?? []) {
|
|
686
|
-
|
|
687
|
-
|
|
1195
|
+
/*
|
|
1196
|
+
* A board that had no place where the move began (its district out
|
|
1197
|
+
* of sight) comes up where it will stand as the move goes on, and one
|
|
1198
|
+
* that will have none goes down where it stood: never one frame from
|
|
1199
|
+
* nowhere to full.
|
|
1200
|
+
*/
|
|
1201
|
+
const goal = slots.get(key);
|
|
1202
|
+
const was = gone.slots?.get(key);
|
|
1203
|
+
const arriving = gone.slots !== null && goal !== undefined && was === undefined ? carried : 1;
|
|
1204
|
+
const leaving = gone.slots !== null && goal === undefined && was !== undefined ? 1 - carried : 1;
|
|
1205
|
+
const slot = goal ? slotNow(key) : gone.slots && was ? was : undefined;
|
|
1206
|
+
const w = boardWidth * (scales.get(key) ?? 1);
|
|
1207
|
+
const h = w / BOARD_ASPECT;
|
|
1208
|
+
const footAt = slot ? project(painted, slot) : null;
|
|
1209
|
+
const covered = key !== at.current && footAt !== null && under({ x: footAt.x - w / 2, y: footAt.y - h, width: w, height: h });
|
|
1210
|
+
// Put away under the bar or the control by a pan (a phone's City is panned to reach it): said, for whoever reads the page.
|
|
1211
|
+
button.toggleAttribute("data-graview-under", covered);
|
|
1212
|
+
const seen = slot && !covered ? (key === at.current ? shownOwn : shownBoards) * arriving * leaving : 0;
|
|
1213
|
+
// Not seen, it is not reached: out of the keyboard's order and the pointer's, as a board going away is.
|
|
1214
|
+
const reached = seen > 0.5 && (key === at.current ? a > 1.5 : a > 0.95) && !move;
|
|
1215
|
+
if (button.inert === reached)
|
|
1216
|
+
button.inert = !reached;
|
|
1217
|
+
if (!slot || seen <= 0.001) {
|
|
688
1218
|
if (button.style.opacity !== "0")
|
|
689
1219
|
button.style.opacity = "0";
|
|
690
1220
|
button.style.pointerEvents = "none";
|
|
691
1221
|
continue;
|
|
692
1222
|
}
|
|
693
|
-
const foot = project(painted, slot);
|
|
694
|
-
const w = boardWidth;
|
|
695
|
-
const h = w / BOARD_ASPECT;
|
|
1223
|
+
const foot = footAt ?? project(painted, slot);
|
|
696
1224
|
button.style.left = `${(foot.x - w / 2).toFixed(2)}px`;
|
|
697
1225
|
button.style.top = `${(foot.y - h).toFixed(2)}px`;
|
|
698
1226
|
button.style.width = `${w.toFixed(2)}px`;
|
|
699
1227
|
button.style.height = `${h.toFixed(2)}px`;
|
|
700
|
-
button.style.opacity = key === at.current ? "1" :
|
|
701
|
-
button.style.setProperty("--graview-sign-post", `${(SIGN_POST * zoomNow * painted.s).toFixed(2)}px`);
|
|
702
|
-
button.style.pointerEvents =
|
|
1228
|
+
button.style.opacity = key === at.current ? (shownOwn > 0.001 ? "1" : "0") : seen.toFixed(3);
|
|
1229
|
+
button.style.setProperty("--graview-sign-post", `${((posts.get(key) ?? SIGN_POST * zoomNow) * painted.s).toFixed(2)}px`);
|
|
1230
|
+
button.style.pointerEvents = reached ? "auto" : "none";
|
|
1231
|
+
if (reached)
|
|
1232
|
+
pressable.push({ x: foot.x - w / 2, y: foot.y - h, width: w, height: h });
|
|
703
1233
|
const face = button.firstElementChild;
|
|
704
1234
|
if (face)
|
|
705
|
-
face.style.transform = `scale(${(w /
|
|
1235
|
+
face.style.transform = `scale(${(w / boardFaceWidth(at.view)).toFixed(5)})`;
|
|
1236
|
+
}
|
|
1237
|
+
/*
|
|
1238
|
+
* THE DISTRICTS' NAMES come up with the views, and the Scene's own
|
|
1239
|
+
* names stand down as they do: one name a district at every altitude.
|
|
1240
|
+
* Each is placed through this frame's camera, a size on the screen.
|
|
1241
|
+
*/
|
|
1242
|
+
const shownNames = a >= PANEL ? 1 : ease(clamp01((a - 0.6) / 0.4));
|
|
1243
|
+
holder.style.setProperty("--graview-one-face-plates", (1 - shownNames).toFixed(3));
|
|
1244
|
+
holder.toggleAttribute("data-graview-names-said", shownNames > 0.999);
|
|
1245
|
+
// Across a move, each name goes from where it stood to where it will stand, as far as the camera has gone: never a jump; one with nowhere to come from comes up where it stands, one going away goes down where it stood.
|
|
1246
|
+
const along = gone.t;
|
|
1247
|
+
for (const [kind, el] of tagEls.current) {
|
|
1248
|
+
const goal = names.get(kind);
|
|
1249
|
+
const from = gone.names?.get(kind);
|
|
1250
|
+
const was = from ?? goal;
|
|
1251
|
+
const fade = gone.names && goal && !from ? along : gone.names && !goal && from ? 1 - along : 1;
|
|
1252
|
+
const place = goal ?? (gone.names ? from : undefined);
|
|
1253
|
+
const seen = place ? shownNames * fade : 0;
|
|
1254
|
+
const reached = seen > 0.95 && !move && a > 0.95;
|
|
1255
|
+
if (el.inert === reached)
|
|
1256
|
+
el.inert = !reached;
|
|
1257
|
+
if (!place || !was || seen <= 0.001) {
|
|
1258
|
+
if (el.style.visibility !== "hidden")
|
|
1259
|
+
el.style.visibility = "hidden";
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
el.style.visibility = "visible";
|
|
1263
|
+
el.style.opacity = seen.toFixed(3);
|
|
1264
|
+
/*
|
|
1265
|
+
* The name's middle goes from where it was to where it will be. Its box
|
|
1266
|
+
* at the end of a move is the size it is in the picture there — a size
|
|
1267
|
+
* on the screen taken through a camera much further out is many times
|
|
1268
|
+
* wider in the picture — so the middle is carried, never the left edge
|
|
1269
|
+
* with the width at the end: that put a name a hundred pixels off in
|
|
1270
|
+
* the first frame of a move to the City.
|
|
1271
|
+
*/
|
|
1272
|
+
const top = project(painted, { x: was.x + was.width / 2 + (place.x + place.width / 2 - (was.x + was.width / 2)) * along, y: was.y + (place.y - was.y) * along });
|
|
1273
|
+
el.style.left = `${(top.x - el.offsetWidth / 2).toFixed(2)}px`;
|
|
1274
|
+
el.style.top = `${top.y.toFixed(2)}px`;
|
|
1275
|
+
const covered = under({ x: top.x - el.offsetWidth / 2, y: top.y, width: el.offsetWidth, height: el.offsetHeight });
|
|
1276
|
+
el.toggleAttribute("data-graview-under", covered);
|
|
1277
|
+
if (!covered && reached)
|
|
1278
|
+
pressable.push({ x: top.x - el.offsetWidth / 2, y: top.y, width: el.offsetWidth, height: el.offsetHeight });
|
|
1279
|
+
if (covered) {
|
|
1280
|
+
el.style.visibility = "hidden";
|
|
1281
|
+
el.inert = true;
|
|
1282
|
+
}
|
|
706
1283
|
}
|
|
707
1284
|
/* The button that moves a level: on a phone it rides above the sheet while the page is one, and comes back to the foot at the city. */
|
|
708
1285
|
const button = fab.current;
|
|
@@ -742,13 +1319,86 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
742
1319
|
const node = store.graph.getNode(target.id);
|
|
743
1320
|
return node ? labelOf(store.schema.tryDefinition(node.kind), node) : target.id;
|
|
744
1321
|
};
|
|
745
|
-
|
|
746
|
-
const
|
|
1322
|
+
/* The page's box in sight, read once a frame for every part on it. */
|
|
1323
|
+
const ports = new Map();
|
|
1324
|
+
const portOf = (element) => {
|
|
1325
|
+
const port = element.closest("[data-graview-one-place]");
|
|
1326
|
+
if (!port)
|
|
1327
|
+
return null;
|
|
1328
|
+
let box = ports.get(port);
|
|
1329
|
+
if (!box)
|
|
1330
|
+
ports.set(port, (box = port.getBoundingClientRect()));
|
|
1331
|
+
return box;
|
|
1332
|
+
};
|
|
1333
|
+
/* One line a record: from where it is shown, in sight on the page, to where it stands — gathered first, routed once every part is known. */
|
|
1334
|
+
const asked = [];
|
|
1335
|
+
/** Every part's box on the page in sight: what a line inside the page goes round. */
|
|
1336
|
+
const words = [];
|
|
1337
|
+
const offer = (target, part, visible, partBox) => {
|
|
1338
|
+
const key = target.type === "record" ? target.id : `kind:${target.kind}`;
|
|
1339
|
+
// Only what is in sight on the page: a part scrolled past, or under the page's own edge, draws none.
|
|
1340
|
+
if (part.x < visible.left || part.x > visible.right || part.y < visible.top || part.y > visible.bottom)
|
|
1341
|
+
return;
|
|
1342
|
+
if (partBox.width > 0 && partBox.height > 0)
|
|
1343
|
+
words.push(partBox);
|
|
1344
|
+
if (taken.has(key))
|
|
1345
|
+
return;
|
|
1346
|
+
const end = endOf(target);
|
|
1347
|
+
if (!end)
|
|
1348
|
+
return;
|
|
1349
|
+
taken.add(key);
|
|
1350
|
+
asked.push({ key, target, part, box: partBox, visible, end });
|
|
1351
|
+
};
|
|
1352
|
+
/* The record page drawn by a view that names no other record: where its one line to the record leaves from. */
|
|
1353
|
+
let aboutPart = null;
|
|
1354
|
+
// The page's own parts first — a link to a record's page, a row that names one, a view's records — then the Connected rows for what the page does not show.
|
|
1355
|
+
const parts = [...plane.querySelectorAll(`a[href], ${RECORD_PARTS}, ${VIEW_PARTS}`)].sort((x, y) => Number(x.closest("[data-graview-connected]") !== null) - Number(y.closest("[data-graview-connected]") !== null));
|
|
747
1356
|
for (const element of parts) {
|
|
748
|
-
if (
|
|
1357
|
+
if (asked.length >= MOST_LINES)
|
|
749
1358
|
break;
|
|
750
1359
|
if (element.closest("nav, header, [role=navigation], [role=banner]"))
|
|
751
1360
|
continue;
|
|
1361
|
+
const visible = portOf(element);
|
|
1362
|
+
if (!visible)
|
|
1363
|
+
continue;
|
|
1364
|
+
const boxes = recordBoxesOf(element);
|
|
1365
|
+
if (boxes) {
|
|
1366
|
+
const rect = element.getBoundingClientRect();
|
|
1367
|
+
if (rect.width < 1 || rect.height < 1)
|
|
1368
|
+
continue;
|
|
1369
|
+
// Its pixels carried through its box as this frame paints it: the page scales as it moves a level.
|
|
1370
|
+
const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
1371
|
+
let named = false;
|
|
1372
|
+
let about = null;
|
|
1373
|
+
for (const box of boxes.boxes()) {
|
|
1374
|
+
if (asked.length >= MOST_LINES)
|
|
1375
|
+
break;
|
|
1376
|
+
if (!store.graph.getNode(box.id))
|
|
1377
|
+
continue;
|
|
1378
|
+
const part = { x: rect.left + (box.x + box.width / 2) * scale, y: rect.top + (box.y + box.height / 2) * scale };
|
|
1379
|
+
const partBox = { x: rect.left + box.x * scale, y: rect.top + box.y * scale, width: box.width * scale, height: box.height * scale };
|
|
1380
|
+
if (box.id === subjectId) {
|
|
1381
|
+
about ??= part;
|
|
1382
|
+
if (partBox.width > 0 && partBox.height > 0)
|
|
1383
|
+
words.push(partBox);
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
named = true;
|
|
1387
|
+
offer({ type: "record", id: box.id }, part, visible, partBox);
|
|
1388
|
+
}
|
|
1389
|
+
if (!named && subjectId !== null && aboutPart === null) {
|
|
1390
|
+
// From the middle of what is in sight of it, or the record's own part where it drew one.
|
|
1391
|
+
const top = Math.max(rect.top, visible.top);
|
|
1392
|
+
const bottom = Math.min(rect.bottom, visible.bottom);
|
|
1393
|
+
const left = Math.max(rect.left, visible.left);
|
|
1394
|
+
const right = Math.min(rect.right, visible.right);
|
|
1395
|
+
if (about)
|
|
1396
|
+
aboutPart = { part: about, visible, box: { ...about, width: 0, height: 0 } };
|
|
1397
|
+
else if (bottom - top >= 1 && right - left >= 1)
|
|
1398
|
+
aboutPart = { part: { x: (left + right) / 2, y: (top + bottom) / 2 }, visible, box: { x: left, y: top, width: right - left, height: bottom - top } };
|
|
1399
|
+
}
|
|
1400
|
+
continue;
|
|
1401
|
+
}
|
|
752
1402
|
const named = recordShownBy(element);
|
|
753
1403
|
let target = null;
|
|
754
1404
|
if (named !== null && store.graph.getNode(named))
|
|
@@ -759,28 +1409,99 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
759
1409
|
}
|
|
760
1410
|
if (!target || (target.type === "record" && target.id === subjectId))
|
|
761
1411
|
continue;
|
|
762
|
-
const key = target.type === "record" ? target.id : `kind:${target.kind}`;
|
|
763
|
-
if (taken.has(key))
|
|
764
|
-
continue;
|
|
765
1412
|
const rect = element.getBoundingClientRect();
|
|
766
1413
|
if (rect.width < 1 || rect.height < 1)
|
|
767
1414
|
continue;
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1415
|
+
offer(target, { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }, visible, boxOf(rect));
|
|
1416
|
+
}
|
|
1417
|
+
if (aboutPart && subjectId !== null && asked.length < MOST_LINES)
|
|
1418
|
+
offer({ type: "record", id: subjectId }, aboutPart.part, aboutPart.visible, aboutPart.box);
|
|
1419
|
+
/*
|
|
1420
|
+
* INSIDE THE PAGE A LINE CROSSES NO ONE ELSE'S WORDS (Graview Cloud's
|
|
1421
|
+
* Deep Time: a row's later pills struck through the earlier ones on
|
|
1422
|
+
* their way to the panel's edge). Each line leaves its own part; where
|
|
1423
|
+
* the straight way to the edge would cross another part, it drops
|
|
1424
|
+
* into the gap above or below its row — the one toward where it is
|
|
1425
|
+
* going first — runs along it to the edge, and goes on from there.
|
|
1426
|
+
* Lines along one gap stand a pixel or two apart.
|
|
1427
|
+
*/
|
|
1428
|
+
const hits = (a, b, own) => words.some((o) => o !== own && Math.max(a.x, b.x) > o.x + 1 && Math.min(a.x, b.x) < o.x + o.width - 1 && Math.max(a.y, b.y) > o.y + 1 && Math.min(a.y, b.y) < o.y + o.height - 1);
|
|
1429
|
+
const edgeX = pageRect.x;
|
|
1430
|
+
const wayIn = (one) => {
|
|
1431
|
+
const b = one.box;
|
|
1432
|
+
const from = leaveFrom(one.part, pageRect, phone);
|
|
1433
|
+
const straight = phone ? { x: one.part.x, y: Math.max(b.y, one.visible.top, from.y) } : { x: Math.max(b.x, one.visible.left, from.x), y: one.part.y };
|
|
1434
|
+
if (phone || !hits(straight, from, b))
|
|
1435
|
+
return { via: [straight, from], gap: null };
|
|
1436
|
+
const beside = words.filter((o) => o !== b && o.x < b.x + b.width && o.x + o.width > edgeX);
|
|
1437
|
+
const above = beside.filter((o) => o.y + o.height <= b.y + 1).reduce((most, o) => Math.max(most, o.y + o.height), -Infinity);
|
|
1438
|
+
const below = beside.filter((o) => o.y >= b.y + b.height - 1).reduce((least, o) => Math.min(least, o.y), Infinity);
|
|
1439
|
+
const gaps = [
|
|
1440
|
+
{ y: Number.isFinite(above) ? (above + b.y) / 2 : b.y - 4, leave: b.y },
|
|
1441
|
+
{ y: Number.isFinite(below) ? (b.y + b.height + below) / 2 : b.y + b.height + 4, leave: b.y + b.height },
|
|
1442
|
+
].filter((g) => g.y > one.visible.top && g.y < one.visible.bottom);
|
|
1443
|
+
// Toward where it is going first: up for a building above the part, down for one below.
|
|
1444
|
+
if (one.end.at.y > one.part.y)
|
|
1445
|
+
gaps.reverse();
|
|
1446
|
+
const x = b.x + Math.min(10, b.width / 2);
|
|
1447
|
+
for (const gap of gaps) {
|
|
1448
|
+
const leave = { x, y: gap.leave };
|
|
1449
|
+
const down = { x, y: gap.y };
|
|
1450
|
+
const out = { x: edgeX, y: gap.y };
|
|
1451
|
+
if (!hits(leave, down, b) && !hits(down, out, b))
|
|
1452
|
+
return { via: [leave, down, out], gap: Math.round(gap.y) };
|
|
1453
|
+
}
|
|
1454
|
+
return { via: [straight, from], gap: null };
|
|
1455
|
+
};
|
|
1456
|
+
const ways = asked.map(wayIn);
|
|
1457
|
+
// Lines along one gap: a pixel and a half apart, about its middle.
|
|
1458
|
+
const along = new Map();
|
|
1459
|
+
ways.forEach((way, at) => {
|
|
1460
|
+
if (way.gap !== null)
|
|
1461
|
+
along.set(way.gap, [...(along.get(way.gap) ?? []), at]);
|
|
1462
|
+
});
|
|
1463
|
+
for (const ats of along.values()) {
|
|
1464
|
+
ats.forEach((at, nth) => {
|
|
1465
|
+
const shift = (nth - (ats.length - 1) / 2) * 1.5;
|
|
1466
|
+
const via = ways[at].via;
|
|
1467
|
+
ways[at] = { ...ways[at], via: [via[0], ...via.slice(1).map((p) => ({ x: p.x, y: p.y + shift }))] };
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
asked.forEach((one, at) => {
|
|
1471
|
+
const via = ways[at].via;
|
|
1472
|
+
const route = routeLine(via[via.length - 1], one.end.at, area, phone, reserved);
|
|
1473
|
+
if (!route)
|
|
1474
|
+
return;
|
|
1475
|
+
found.push({ key: one.key, from: route.from, to: route.to, bend: route.bend, under: route.toward, on: one.end.on, target: one.target, label: labelFor(one.target), part: one.part, start: via[0], via: [...via.slice(0, -1), route.from] });
|
|
1476
|
+
});
|
|
1477
|
+
/*
|
|
1478
|
+
* MANY LINES INTO ONE DISTRICT ARE ONE LINE (Graview HQ, Cloud's test
|
|
1479
|
+
* of Deep Time): each part keeps its own short line to the page's
|
|
1480
|
+
* edge, where they meet, level with the middle of them, and one line
|
|
1481
|
+
* goes on from there into the district with how many it carries.
|
|
1482
|
+
*/
|
|
1483
|
+
const into = new Map();
|
|
1484
|
+
found.forEach((line, at) => {
|
|
1485
|
+
const kind = line.target.type === "record" ? store.graph.getNode(line.target.id)?.kind : line.target.kind;
|
|
1486
|
+
if (kind)
|
|
1487
|
+
into.set(kind, [...(into.get(kind) ?? []), at]);
|
|
1488
|
+
});
|
|
1489
|
+
for (const [kind, ats] of into) {
|
|
1490
|
+
if (ats.length < GATHER)
|
|
773
1491
|
continue;
|
|
774
|
-
|
|
775
|
-
const from = leaveFrom(part, pageRect, phone);
|
|
776
|
-
const end = endOf(target);
|
|
1492
|
+
const end = endOf({ type: "list", kind });
|
|
777
1493
|
if (!end)
|
|
778
1494
|
continue;
|
|
779
|
-
|
|
780
|
-
const
|
|
1495
|
+
const parts = ats.map((at) => found[at].part);
|
|
1496
|
+
const meet = leaveFrom({ x: parts.reduce((sum, p) => sum + p.x, 0) / parts.length, y: parts.reduce((sum, p) => sum + p.y, 0) / parts.length }, pageRect, phone);
|
|
1497
|
+
const route = routeLine(meet, end.at, area, phone, reserved);
|
|
781
1498
|
if (!route)
|
|
782
1499
|
continue;
|
|
783
|
-
|
|
1500
|
+
ats.forEach((at, nth) => {
|
|
1501
|
+
const line = found[at];
|
|
1502
|
+
// Its own way to the page's edge, then along the edge to where they meet.
|
|
1503
|
+
found[at] = { ...line, via: [...line.via, route.from], from: route.from, to: route.to, bend: route.bend, under: route.toward, on: end.on, gathered: { kind, count: ats.length, lead: nth === 0 } };
|
|
1504
|
+
});
|
|
784
1505
|
}
|
|
785
1506
|
}
|
|
786
1507
|
draw(found, shown);
|
|
@@ -801,6 +1522,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
801
1522
|
// The camera's zoom as painted in this frame, for a reader of the move (the harness holds it to going one way).
|
|
802
1523
|
holder.setAttribute("data-graview-camera-zoom", (zoomNow * painted.s).toFixed(4));
|
|
803
1524
|
};
|
|
1525
|
+
/*
|
|
1526
|
+
* A RING IS NEVER UNDER A BOARD OR A NAME, NOR AGAINST ONE: a line's end
|
|
1527
|
+
* that a board or a district's name stands over (or within a fingertip
|
|
1528
|
+
* of) offers no ring of its own — a press there landed on the board, and
|
|
1529
|
+
* one beside it was a small target crowded by a larger one. The line
|
|
1530
|
+
* still ends there; the board or the name is what is pressed.
|
|
1531
|
+
*/
|
|
1532
|
+
const pressable = [];
|
|
1533
|
+
const besidePressable = (to) => pressable.some((b) => to.x > b.x - 20 && to.x < b.x + b.width + 20 && to.y > b.y - 20 && to.y < b.y + b.height + 20);
|
|
804
1534
|
/* The overlay, written in the frame it is measured in: no React state per frame. */
|
|
805
1535
|
const draw = (found, opacity) => {
|
|
806
1536
|
const control = fab.current?.querySelector('[data-graview-one-face-dock]')?.getBoundingClientRect() ?? null;
|
|
@@ -843,28 +1573,58 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
843
1573
|
ring.type = "button";
|
|
844
1574
|
ring.setAttribute("data-testid", "one-place-ring");
|
|
845
1575
|
ring.style.cssText = "position:fixed;width:16px;height:16px;padding:0;border-radius:8px;border:2px solid var(--graview-accent);background:color-mix(in srgb, var(--graview-accent) 18%, transparent);cursor:pointer;";
|
|
846
|
-
const
|
|
847
|
-
ring.addEventListener("click", () =>
|
|
1576
|
+
const key = line.key;
|
|
1577
|
+
ring.addEventListener("click", () => lines.get(key)?.open());
|
|
848
1578
|
ringLayer.append(ring);
|
|
849
|
-
drawn = { g, path, dot, arrow, ring };
|
|
1579
|
+
drawn = { g, path, dot, arrow, ring, open: () => { } };
|
|
850
1580
|
lines.set(line.key, drawn);
|
|
851
1581
|
}
|
|
1582
|
+
const target = line.target;
|
|
1583
|
+
const gathered = line.gathered;
|
|
1584
|
+
drawn.open = gathered ? () => latest.current.openKind(gathered.kind, PANEL) : () => (target.type === "record" ? latest.current.openRecord(target.id, PANEL) : latest.current.openKind(target.kind, PANEL));
|
|
1585
|
+
// Gathered, only the first of them draws the line they share, and its count; the rest draw their own short line to where they meet.
|
|
1586
|
+
const shared = !gathered || gathered.lead;
|
|
852
1587
|
const { from, to } = line;
|
|
853
1588
|
const bend = line.bend;
|
|
854
1589
|
drawn.g.setAttribute("data-graview-line", line.key);
|
|
855
1590
|
drawn.g.setAttribute("data-graview-line-on", line.on);
|
|
856
1591
|
drawn.g.toggleAttribute("data-graview-line-under", line.under !== null);
|
|
857
1592
|
drawn.g.setAttribute("data-graview-line-from", `${from.x.toFixed(2)},${from.y.toFixed(2)}`);
|
|
1593
|
+
drawn.g.setAttribute("data-graview-line-start", `${line.start.x.toFixed(2)},${line.start.y.toFixed(2)}`);
|
|
1594
|
+
if (gathered)
|
|
1595
|
+
drawn.g.setAttribute("data-graview-line-gathered", `kind:${gathered.kind}`);
|
|
1596
|
+
else
|
|
1597
|
+
drawn.g.removeAttribute("data-graview-line-gathered");
|
|
1598
|
+
if (gathered?.lead)
|
|
1599
|
+
drawn.g.setAttribute("data-graview-line-count", String(gathered.count));
|
|
1600
|
+
else
|
|
1601
|
+
drawn.g.removeAttribute("data-graview-line-count");
|
|
1602
|
+
drawn.g.setAttribute("data-graview-line-part", `${line.part.x.toFixed(2)},${line.part.y.toFixed(2)}`);
|
|
858
1603
|
drawn.g.setAttribute("data-graview-line-to", `${to.x.toFixed(2)},${to.y.toFixed(2)}`);
|
|
859
1604
|
drawn.g.setAttribute("data-graview-line-bend", `${bend.x.toFixed(2)},${bend.y.toFixed(2)}`);
|
|
860
1605
|
if (line.under)
|
|
861
1606
|
drawn.g.setAttribute("data-graview-line-toward", `${line.under.x.toFixed(2)},${line.under.y.toFixed(2)}`);
|
|
862
1607
|
else
|
|
863
1608
|
drawn.g.removeAttribute("data-graview-line-toward");
|
|
864
|
-
|
|
865
|
-
drawn.
|
|
866
|
-
drawn.dot.setAttribute("
|
|
867
|
-
|
|
1609
|
+
const leg = line.via.map((p, i) => `${i === 0 ? "M" : "L"}${p.x.toFixed(2)},${p.y.toFixed(2)}`).join(" ");
|
|
1610
|
+
drawn.path.setAttribute("d", shared ? `${leg} Q${bend.x.toFixed(2)},${bend.y.toFixed(2)} ${to.x.toFixed(2)},${to.y.toFixed(2)}` : leg);
|
|
1611
|
+
drawn.dot.setAttribute("cx", line.start.x.toFixed(2));
|
|
1612
|
+
drawn.dot.setAttribute("cy", line.start.y.toFixed(2));
|
|
1613
|
+
// The shared line's marker says how many it carries: wide enough for the number, and a fingertip's size.
|
|
1614
|
+
const size = gathered?.lead ? 22 : 16;
|
|
1615
|
+
const wide = gathered?.lead ? Math.max(22, 10 + 7 * String(gathered.count).length) : 16;
|
|
1616
|
+
drawn.ring.textContent = gathered?.lead ? String(gathered.count) : "";
|
|
1617
|
+
drawn.ring.style.width = `${wide}px`;
|
|
1618
|
+
drawn.ring.style.height = `${size}px`;
|
|
1619
|
+
drawn.ring.style.borderRadius = `${size / 2}px`;
|
|
1620
|
+
drawn.ring.style.font = gathered?.lead ? "600 11px/1 system-ui, sans-serif" : "";
|
|
1621
|
+
drawn.ring.style.color = gathered?.lead ? "var(--graview-ink)" : "";
|
|
1622
|
+
drawn.ring.style.background = gathered?.lead ? "var(--graview-panel, Canvas)" : "color-mix(in srgb, var(--graview-accent) 18%, transparent)";
|
|
1623
|
+
if (!shared) {
|
|
1624
|
+
drawn.arrow.setAttribute("d", "");
|
|
1625
|
+
drawn.ring.style.display = "none";
|
|
1626
|
+
}
|
|
1627
|
+
else if (line.under) {
|
|
868
1628
|
// An arrow at the page's edge, pointing on toward the building under the page.
|
|
869
1629
|
const angle = Math.atan2(line.under.y - to.y, line.under.x - to.x);
|
|
870
1630
|
const tip = { x: to.x + Math.cos(angle) * 7, y: to.y + Math.sin(angle) * 7 };
|
|
@@ -872,32 +1632,65 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
872
1632
|
const right = { x: to.x + Math.cos(angle - 2.4) * 6, y: to.y + Math.sin(angle - 2.4) * 6 };
|
|
873
1633
|
drawn.arrow.setAttribute("d", `M${tip.x.toFixed(2)},${tip.y.toFixed(2)} L${left.x.toFixed(2)},${left.y.toFixed(2)} L${right.x.toFixed(2)},${right.y.toFixed(2)} Z`);
|
|
874
1634
|
// The marker toward a building out of sight is the way to it: its name said, a press flies there.
|
|
875
|
-
const crowded = ringsAt.some((p) => Math.hypot(p.x - to.x, p.y - to.y) < 28);
|
|
1635
|
+
const crowded = ringsAt.some((p) => Math.hypot(p.x - to.x, p.y - to.y) < 28) || besidePressable(to);
|
|
876
1636
|
drawn.ring.style.display = crowded ? "none" : "";
|
|
877
1637
|
if (!crowded)
|
|
878
1638
|
ringsAt.push(to);
|
|
879
|
-
drawn.ring.style.left = `${(to.x -
|
|
880
|
-
drawn.ring.style.top = `${(to.y -
|
|
1639
|
+
drawn.ring.style.left = `${(to.x - wide / 2).toFixed(2)}px`;
|
|
1640
|
+
drawn.ring.style.top = `${(to.y - size / 2).toFixed(2)}px`;
|
|
881
1641
|
}
|
|
882
1642
|
else {
|
|
883
1643
|
drawn.arrow.setAttribute("d", "");
|
|
1644
|
+
/*
|
|
1645
|
+
* A SHARED LINE'S COUNT IS ALWAYS SAID: where its district's middle
|
|
1646
|
+
* has a board or a name beside it (which takes the press there), the
|
|
1647
|
+
* count stands back along the line, at the nearest place clear of them.
|
|
1648
|
+
*/
|
|
1649
|
+
let at = to;
|
|
1650
|
+
if (gathered?.lead && besidePressable(to)) {
|
|
1651
|
+
for (let t = 0.95; t >= 0.4; t -= 0.05) {
|
|
1652
|
+
const p = { x: (1 - t) ** 2 * from.x + 2 * (1 - t) * t * bend.x + t * t * to.x, y: (1 - t) ** 2 * from.y + 2 * (1 - t) * t * bend.y + t * t * to.y };
|
|
1653
|
+
if (!besidePressable(p)) {
|
|
1654
|
+
at = p;
|
|
1655
|
+
break;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
884
1659
|
// An end under the bar, or under the control at the foot, is not offered: they stand over it.
|
|
885
|
-
const under = control &&
|
|
886
|
-
const crowded = ringsAt.some((p) => Math.hypot(p.x -
|
|
887
|
-
drawn.ring.style.display =
|
|
1660
|
+
const under = control && at.x > control.left - 10 && at.x < control.right + 10 && at.y > control.top - 10 && at.y < control.bottom + 10;
|
|
1661
|
+
const crowded = ringsAt.some((p) => Math.hypot(p.x - at.x, p.y - at.y) < 28) || besidePressable(at);
|
|
1662
|
+
drawn.ring.style.display = at.y < (state.current.view.top ?? 0) + 8 || under || crowded ? "none" : "";
|
|
888
1663
|
if (!crowded)
|
|
889
|
-
ringsAt.push(
|
|
890
|
-
drawn.ring.style.left = `${(
|
|
891
|
-
drawn.ring.style.top = `${(
|
|
1664
|
+
ringsAt.push(at);
|
|
1665
|
+
drawn.ring.style.left = `${(at.x - wide / 2).toFixed(2)}px`;
|
|
1666
|
+
drawn.ring.style.top = `${(at.y - size / 2).toFixed(2)}px`;
|
|
1667
|
+
}
|
|
1668
|
+
if (gathered) {
|
|
1669
|
+
const plural = pluralOf(store, gathered.kind);
|
|
1670
|
+
drawn.ring.setAttribute("data-graview-to", `kind:${gathered.kind}`);
|
|
1671
|
+
drawn.ring.setAttribute("aria-label", `${gathered.count} ${plural.toLowerCase()} here: open the ${plural} list`);
|
|
1672
|
+
drawn.ring.title = `${gathered.count} ${plural.toLowerCase()}`;
|
|
1673
|
+
}
|
|
1674
|
+
else {
|
|
1675
|
+
drawn.ring.setAttribute("data-graview-to", line.target.type === "record" ? line.target.id : `kind:${line.target.kind}`);
|
|
1676
|
+
drawn.ring.setAttribute("aria-label", line.target.type === "record" ? `Open ${line.label}` : `Open the ${line.label} list`);
|
|
1677
|
+
drawn.ring.title = line.label;
|
|
892
1678
|
}
|
|
893
|
-
drawn.ring.setAttribute("data-graview-to", line.target.type === "record" ? line.target.id : `kind:${line.target.kind}`);
|
|
894
|
-
drawn.ring.setAttribute("aria-label", line.target.type === "record" ? `Open ${line.label}` : `Open the ${line.label} list`);
|
|
895
|
-
drawn.ring.title = line.label;
|
|
896
1679
|
}
|
|
897
1680
|
};
|
|
898
1681
|
frame = requestAnimationFrame(tick);
|
|
1682
|
+
const said = sheet.current;
|
|
1683
|
+
said?.addEventListener(RECORD_BOXES_MOVED, askReframe);
|
|
1684
|
+
// The person's own hand on the city: a press, a drag, a wheel, a pinch.
|
|
1685
|
+
const city = box.current;
|
|
1686
|
+
const hands = ["pointerdown", "wheel", "touchstart"];
|
|
1687
|
+
for (const type of hands)
|
|
1688
|
+
city?.addEventListener(type, byHand, { capture: true, passive: true });
|
|
899
1689
|
return () => {
|
|
900
1690
|
cancelAnimationFrame(frame);
|
|
1691
|
+
said?.removeEventListener(RECORD_BOXES_MOVED, askReframe);
|
|
1692
|
+
for (const type of hands)
|
|
1693
|
+
city?.removeEventListener(type, byHand, { capture: true });
|
|
901
1694
|
for (const drawn of lines.values()) {
|
|
902
1695
|
drawn.g.remove();
|
|
903
1696
|
drawn.ring.remove();
|
|
@@ -905,6 +1698,140 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
905
1698
|
};
|
|
906
1699
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
907
1700
|
}, []);
|
|
1701
|
+
/*
|
|
1702
|
+
* A HAND ON A SIGN MOVES THE CITY. The boards, the districts' names and
|
|
1703
|
+
* their chips, and the rings at the lines' ends stand over the city in a
|
|
1704
|
+
* layer of their own, so a drag, a wheel or a pinch that began on one of
|
|
1705
|
+
* them reached nothing: the city stalled under the pointer. Begun there, a
|
|
1706
|
+
* drag past a few pixels pans the city's own camera by as far as the hand
|
|
1707
|
+
* goes (and the press that began it opens nothing), two fingers zoom it
|
|
1708
|
+
* about their middle, and the wheel pans or, with ctrl, zooms it — as over
|
|
1709
|
+
* open ground. A press that does not move still opens what it is on.
|
|
1710
|
+
*/
|
|
1711
|
+
useEffect(() => {
|
|
1712
|
+
const layers = [boardLayer.current, tagLayer.current, rings.current].filter((el) => el !== null);
|
|
1713
|
+
const DRAG = 6;
|
|
1714
|
+
const down = new Map();
|
|
1715
|
+
let dragging = false;
|
|
1716
|
+
let pinchFrom = null;
|
|
1717
|
+
let swallow = false;
|
|
1718
|
+
const spread = () => {
|
|
1719
|
+
const [a, b] = [...down.values()];
|
|
1720
|
+
return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
|
|
1721
|
+
};
|
|
1722
|
+
const onDown = (event) => {
|
|
1723
|
+
if (event.pointerType === "mouse" && event.button !== 0)
|
|
1724
|
+
return;
|
|
1725
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1726
|
+
dragging = false;
|
|
1727
|
+
pinchFrom = down.size === 2 ? spread() : null;
|
|
1728
|
+
};
|
|
1729
|
+
const onMove = (event) => {
|
|
1730
|
+
const was = down.get(event.pointerId);
|
|
1731
|
+
const cam = camera.current;
|
|
1732
|
+
if (!was || !cam)
|
|
1733
|
+
return;
|
|
1734
|
+
const dx = event.clientX - was.x;
|
|
1735
|
+
const dy = event.clientY - was.y;
|
|
1736
|
+
if (down.size >= 2) {
|
|
1737
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1738
|
+
const now = spread();
|
|
1739
|
+
if (pinchFrom && now > 0) {
|
|
1740
|
+
const [a, b] = [...down.values()];
|
|
1741
|
+
cam.zoomTo(cam.zoom() * (now / pinchFrom), (a.x + b.x) / 2, (a.y + b.y) / 2);
|
|
1742
|
+
pinchFrom = now;
|
|
1743
|
+
dragging = true;
|
|
1744
|
+
}
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
if (!dragging && Math.hypot(dx, dy) < DRAG)
|
|
1748
|
+
return;
|
|
1749
|
+
if (!dragging) {
|
|
1750
|
+
dragging = true;
|
|
1751
|
+
try {
|
|
1752
|
+
event.target?.setPointerCapture?.(event.pointerId);
|
|
1753
|
+
}
|
|
1754
|
+
catch {
|
|
1755
|
+
// A pointer the page did not see go down keeps no capture; the moves still come here.
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
cam.panBy(dx, dy);
|
|
1759
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1760
|
+
};
|
|
1761
|
+
const onUp = (event) => {
|
|
1762
|
+
if (!down.has(event.pointerId))
|
|
1763
|
+
return;
|
|
1764
|
+
down.delete(event.pointerId);
|
|
1765
|
+
if (dragging)
|
|
1766
|
+
swallow = true;
|
|
1767
|
+
if (down.size === 0) {
|
|
1768
|
+
dragging = false;
|
|
1769
|
+
pinchFrom = null;
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
// The press that ended a drag opens nothing.
|
|
1773
|
+
const onClick = (event) => {
|
|
1774
|
+
if (!swallow)
|
|
1775
|
+
return;
|
|
1776
|
+
swallow = false;
|
|
1777
|
+
event.preventDefault();
|
|
1778
|
+
event.stopPropagation();
|
|
1779
|
+
};
|
|
1780
|
+
const onWheel = (event) => {
|
|
1781
|
+
const cam = camera.current;
|
|
1782
|
+
if (!cam)
|
|
1783
|
+
return;
|
|
1784
|
+
event.preventDefault();
|
|
1785
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
|
|
1786
|
+
if (event.ctrlKey || event.metaKey)
|
|
1787
|
+
cam.zoomTo(cam.zoom() * Math.exp(-event.deltaY * unit * 0.01), event.clientX, event.clientY);
|
|
1788
|
+
else
|
|
1789
|
+
cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
|
|
1790
|
+
};
|
|
1791
|
+
/*
|
|
1792
|
+
* A SCROLL OVER A DISTRICT PANS TOO. The Scene leaves a lens's wheel to
|
|
1793
|
+
* the lens, and a district's plot is a view of its own there, so a
|
|
1794
|
+
* two-finger scroll that happened to start over a district moved
|
|
1795
|
+
* nothing. On this face a district scrolls nothing of its own: the
|
|
1796
|
+
* scroll pans the city, as over open ground. A part that does scroll (a
|
|
1797
|
+
* scroll region, a pane, a worker view drawn there, whose own scroll this
|
|
1798
|
+
* face cannot see into) keeps its own wheel.
|
|
1799
|
+
*/
|
|
1800
|
+
const holder = box.current;
|
|
1801
|
+
const onPlotWheel = (event) => {
|
|
1802
|
+
const target = event.target;
|
|
1803
|
+
if (event.ctrlKey || event.metaKey || !target?.closest("[data-graview-plot]") || target.closest(".graview-scroll, [data-graview-overlay], .graview-zoom, [data-worker-view]"))
|
|
1804
|
+
return;
|
|
1805
|
+
const cam = camera.current;
|
|
1806
|
+
if (!cam)
|
|
1807
|
+
return;
|
|
1808
|
+
event.preventDefault();
|
|
1809
|
+
event.stopPropagation();
|
|
1810
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
|
|
1811
|
+
cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
|
|
1812
|
+
};
|
|
1813
|
+
holder?.addEventListener("wheel", onPlotWheel, { passive: false, capture: true });
|
|
1814
|
+
for (const layer of layers) {
|
|
1815
|
+
layer.addEventListener("pointerdown", onDown, true);
|
|
1816
|
+
layer.addEventListener("pointermove", onMove, true);
|
|
1817
|
+
layer.addEventListener("pointerup", onUp, true);
|
|
1818
|
+
layer.addEventListener("pointercancel", onUp, true);
|
|
1819
|
+
layer.addEventListener("click", onClick, true);
|
|
1820
|
+
layer.addEventListener("wheel", onWheel, { passive: false });
|
|
1821
|
+
}
|
|
1822
|
+
return () => {
|
|
1823
|
+
holder?.removeEventListener("wheel", onPlotWheel, { capture: true });
|
|
1824
|
+
for (const layer of layers) {
|
|
1825
|
+
layer.removeEventListener("pointerdown", onDown, true);
|
|
1826
|
+
layer.removeEventListener("pointermove", onMove, true);
|
|
1827
|
+
layer.removeEventListener("pointerup", onUp, true);
|
|
1828
|
+
layer.removeEventListener("pointercancel", onUp, true);
|
|
1829
|
+
layer.removeEventListener("click", onClick, true);
|
|
1830
|
+
layer.removeEventListener("wheel", onWheel);
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1834
|
+
}, []);
|
|
908
1835
|
/*
|
|
909
1836
|
* A building pressed, above the page: its record, in the panel, the camera
|
|
910
1837
|
* flying to it. The Scene's blocks take no press of their own (their tile
|
|
@@ -947,7 +1874,12 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
947
1874
|
* in the page — and what of it reaches past the window is inside a
|
|
948
1875
|
* box that scrolls, as a phone's sideways row would be.
|
|
949
1876
|
*/
|
|
950
|
-
style: { position: "fixed", inset: 0, zIndex: ONE_FACE_LAYERS.city, display: "none", visibility: "hidden", overflow: "hidden", containerType: "size" }, children: [_jsx("style", { children: CITY_CSS }), _jsx(Scene, { renderer: "dom", blur: false, animate: false, camera: camera, options: sceneOptions, style: { width: "100%", height: "100%" } })] }), _jsx("svg", { ref: overlay, "aria-hidden": "true", "data-testid": "one-place-lines", width: view.width, height: view.height, style: { position: "fixed", left: 0, top: 0, zIndex: ONE_FACE_LAYERS.marks, pointerEvents: "none", overflow: "visible", opacity: 0 } }), _jsx("div", { ref: rings, hidden: true, role: "group", "aria-label": "What this page shows, in the city", style: { position: "fixed", left: 0, top: 0, width: 0, height: 0, zIndex: ONE_FACE_LAYERS.marks, opacity: 0 } })
|
|
1877
|
+
style: { position: "fixed", inset: 0, zIndex: ONE_FACE_LAYERS.city, display: "none", visibility: "hidden", overflow: "hidden", containerType: "size" }, children: [_jsx("style", { children: CITY_CSS }), _jsx(Scene, { renderer: "dom", blur: false, animate: false, camera: camera, options: sceneOptions, style: { width: "100%", height: "100%" } })] }), _jsx("svg", { ref: overlay, "aria-hidden": "true", "data-testid": "one-place-lines", width: view.width, height: view.height, style: { position: "fixed", left: 0, top: 0, zIndex: ONE_FACE_LAYERS.marks, pointerEvents: "none", overflow: "visible", opacity: 0 } }), _jsx("div", { ref: rings, hidden: true, role: "group", "aria-label": "What this page shows, in the city", style: { position: "fixed", left: 0, top: 0, width: 0, height: 0, zIndex: ONE_FACE_LAYERS.marks, opacity: 0 } }), _jsx("div", { ref: tagLayer, role: "region", "aria-label": "The districts", "data-testid": "one-place-names", style: { position: "fixed", left: 0, top: 0, width: 0, height: 0, zIndex: ONE_FACE_LAYERS.marks }, children: districtNames.map((one) => (_jsxs("span", { ref: (el) => {
|
|
1878
|
+
if (el)
|
|
1879
|
+
tagEls.current.set(one.kind, el);
|
|
1880
|
+
else
|
|
1881
|
+
tagEls.current.delete(one.kind);
|
|
1882
|
+
}, "data-graview-district-tag": one.kind, className: "graview-one-place-district", style: { visibility: "hidden" }, children: [_jsxs("button", { type: "button", "data-graview-district-open": one.kind, "aria-label": `${one.plural}, ${one.count === 0 ? "none yet" : one.count.toLocaleString()}: open the list`, title: `${one.plural}, ${one.count}`, onClick: () => openKind(one.kind, PANEL), children: [_jsx("span", { "data-graview-district-tag-name": "", children: one.plural }), " ", _jsx("span", { "data-graview-district-tag-count": "", children: one.count === 0 ? "none yet" : one.count.toLocaleString() })] }), one.problems > 0 ? (_jsxs("button", { type: "button", "data-graview-district-problems": one.kind, "aria-label": `${one.problems} ${one.problems === 1 ? "problem" : "problems"} in ${one.plural}`, title: `${one.problems} ${one.problems === 1 ? "problem" : "problems"} in ${one.plural}: press to see them`, onClick: () => face?.openPath(`/problems?kind=${encodeURIComponent(one.kind)}`, PANEL), children: ["\u26A0 ", one.problems] })) : null] }, one.kind))) })] }));
|
|
951
1883
|
}
|
|
952
1884
|
/** The one kind a view stands on: a kind's list, or a view of one kind; null for the home, a view of several kinds and the connections. */
|
|
953
1885
|
export function signKindOf(where) {
|