@graview/pages 0.2.0 → 0.2.2
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 +1232 -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 +65 -0
- package/dist/one-place-signs.d.ts.map +1 -0
- package/dist/one-place-signs.js +405 -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,47 @@ 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
|
+
/** How far inside a phone's sheet a line goes up its side to the top edge: in the sheet's own margin, clear of its words. */
|
|
91
|
+
const SHEET_SIDE = 6;
|
|
92
|
+
/**
|
|
93
|
+
* The furthest from its row a line in a view runs along a gap. The page
|
|
94
|
+
* cannot read a view's words, so this is a guess at a row's own spacing (a
|
|
95
|
+
* pill's margin): words set closer under a row than this are crossed.
|
|
96
|
+
*/
|
|
97
|
+
const FRAMED_GAP = 4;
|
|
98
|
+
/** And on a phone's page: a group's label stands a few pixels over its row of pills, and a line along the gap over the row passes under its words. */
|
|
99
|
+
const PHONE_GAP = 2.5;
|
|
100
|
+
/** How far inside the city's side the home keeps its views' districts while bringing the city to the middle: a district's edge never on the window's or the sheet's. */
|
|
101
|
+
const HOME_EDGE = 8;
|
|
102
|
+
/** How far from its own district a name may stand beside a page, edge to edge: a name's height and a little air. Past it, a name reads as another district's. */
|
|
103
|
+
const NAME_REACH = 32;
|
|
104
|
+
/** What a district's "+n" is kept under among the picture's buildings: never a record's id. */
|
|
105
|
+
const REST_KEY = "\u0000rest:";
|
|
63
106
|
/** How long one level's move takes. A person who asked for less motion is cut straight there. */
|
|
64
107
|
export const MOVE_MS = 560;
|
|
65
108
|
/** A hand that has stopped zooming for this long has let go: the altitude settles to the nearest level. */
|
|
@@ -72,6 +115,10 @@ const keyOf = (where) => (where.type === "record" ? `record:${where.id}` : where
|
|
|
72
115
|
const ease = (t) => (t <= 0 ? 0 : t >= 1 ? 1 : t * t * (3 - 2 * t));
|
|
73
116
|
const level = (live) => Math.abs(live.s - 1) < 1e-4 && Math.abs(live.x) < 0.05 && Math.abs(live.y) < 0.05;
|
|
74
117
|
const clamp01 = (t) => Math.max(0, Math.min(1, t));
|
|
118
|
+
/** The same ids, in the same order. */
|
|
119
|
+
const sameIds = (a, b) => a.length === b.length && a.every((id, at) => id === b[at]);
|
|
120
|
+
/** Whether a point stands inside a box. */
|
|
121
|
+
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
122
|
export function OnePlaceCity({ where, out, sheet, connected, boards, current, boardEls, boardLayer, fab, view, lessMotion, resolve, openRecord, openKind, onGround, motion, onAltitude }) {
|
|
76
123
|
const { store } = useGraview();
|
|
77
124
|
const { view: seen, go } = useNavigation();
|
|
@@ -116,11 +163,25 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
116
163
|
latestOut.current = out;
|
|
117
164
|
const latest = useRef({ openRecord, openKind });
|
|
118
165
|
latest.current = { openRecord, openKind };
|
|
119
|
-
|
|
166
|
+
/*
|
|
167
|
+
* NOTHING CHOSEN ON THE SCENE, AFTER A PRESS AS ON A FRESH LOAD. A page
|
|
168
|
+
* opened while the page is out (a building pressed, a link, a pill) says
|
|
169
|
+
* its subject to the provider as the page's choice: the Scene took it for
|
|
170
|
+
* its own, lit that building alone, faded the rest of the city, put the
|
|
171
|
+
* record at the head of its row and wrote its links' words over the city.
|
|
172
|
+
* Out, the Scene keeps nothing chosen — one rule, whichever way the page
|
|
173
|
+
* came — and the page's choice is kept for the page to have back. Read
|
|
174
|
+
* before the frame is painted, so nothing faded is ever drawn.
|
|
175
|
+
*/
|
|
176
|
+
useLayoutEffect(() => {
|
|
120
177
|
// While the page is read the view is the page's own, and none of this is the Scene's.
|
|
121
178
|
if (!latestOut.current || toUrl(seen) === asked.current)
|
|
122
179
|
return;
|
|
123
|
-
|
|
180
|
+
const picked = seen.selection ?? [];
|
|
181
|
+
// What the page chose is the page's — none, too, on a page of no one record — had back when it comes in again.
|
|
182
|
+
if (kept.current && (picked.length > 0 || (kept.current.selection ?? []).length > 0) && !sameIds(picked, kept.current.selection ?? []))
|
|
183
|
+
kept.current = { ...kept.current, selection: picked };
|
|
184
|
+
if (seen.overview && seen.focusId === null && picked.length === 0)
|
|
124
185
|
return;
|
|
125
186
|
const focus = seen.focusId;
|
|
126
187
|
const back = { ...wanted, ...(seen.pan ? { pan: seen.pan } : {}) };
|
|
@@ -136,31 +197,170 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
136
197
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
198
|
}, [seen]);
|
|
138
199
|
/*
|
|
139
|
-
* THE
|
|
140
|
-
*
|
|
141
|
-
*
|
|
200
|
+
* THE PLAZA'S ROOM AT THE TOP: the views of no one kind, in rows, under
|
|
201
|
+
* the bar. A kind's views find their own room beside its district
|
|
202
|
+
* (`placeSigns`), clear of every name the face says there.
|
|
142
203
|
*/
|
|
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
204
|
const plaza = useMemo(() => {
|
|
155
205
|
const count = boards.filter((board) => board.where.type !== "record" && signKindOf(board.where) === null).length;
|
|
156
206
|
return count === 0 ? 0 : Math.ceil(signRoom(count, boardWidthFor(view)).height + 12);
|
|
157
207
|
}, [boards, view]);
|
|
158
|
-
const sceneOptions = useMemo(() => ({
|
|
208
|
+
const sceneOptions = useMemo(() => ({ plaza: plaza + view.top }), [plaza, view.top]);
|
|
209
|
+
/*
|
|
210
|
+
* EACH DISTRICT'S NAME, said by this face: its kind's plural and how many
|
|
211
|
+
* it holds, a size on the screen at every level, placed with the views so
|
|
212
|
+
* nothing stands on it (`placeSigns`). The Scene's own names stand down
|
|
213
|
+
* as these come up: they were laid out for the Scene's own fit, and at
|
|
214
|
+
* this face's City most of them said nothing.
|
|
215
|
+
*/
|
|
216
|
+
const violations = useViolations();
|
|
217
|
+
const face = useOneFace();
|
|
218
|
+
// A district's problems: each broken rule that names one of its records, once.
|
|
219
|
+
const problemsOf = useMemo(() => {
|
|
220
|
+
const out = new Map();
|
|
221
|
+
for (const violation of violations) {
|
|
222
|
+
const kinds = new Set(violation.nodeIds.flatMap((id) => { const node = store.graph.getNode(id); return node ? [node.kind] : []; }));
|
|
223
|
+
for (const kind of kinds)
|
|
224
|
+
out.set(kind, (out.get(kind) ?? 0) + 1);
|
|
225
|
+
}
|
|
226
|
+
return out;
|
|
227
|
+
}, [violations, store]);
|
|
228
|
+
const districtNames = store.schema.kinds.map((kind) => ({ kind, plural: pluralOf(store, kind), count: store.graph.count(kind), problems: problemsOf.get(kind) ?? 0 }));
|
|
229
|
+
const tagEls = useRef(new Map());
|
|
230
|
+
const tagLayer = useRef(null);
|
|
159
231
|
const state = useRef({ where, out, view, lessMotion, resolve, onAltitude, boards, current });
|
|
160
|
-
|
|
232
|
+
/*
|
|
233
|
+
* WHAT THE FRAME READS IS WHAT IS DRAWN. Written as the render ran, a
|
|
234
|
+
* render React paused part way (a route drawn as a transition) handed the
|
|
235
|
+
* frame a place whose page was not yet on the screen: the move began from
|
|
236
|
+
* the new place's board while the old page still stood there, and the new
|
|
237
|
+
* page came in a long task later, a leap inside the move. Written once the
|
|
238
|
+
* render is committed, the frame moves only what is drawn.
|
|
239
|
+
*/
|
|
240
|
+
useLayoutEffect(() => {
|
|
241
|
+
state.current = { where, out, view, lessMotion, resolve, onAltitude, boards, current };
|
|
242
|
+
});
|
|
161
243
|
useEffect(() => {
|
|
162
244
|
let frame = 0;
|
|
163
|
-
let world = { plots: new Map(), buildings: new Map()
|
|
245
|
+
let world = { plots: new Map(), buildings: new Map() };
|
|
246
|
+
/*
|
|
247
|
+
* NEARBY FRAMES WHAT THE RECORD IS CONNECTED TO (Graview HQ brief
|
|
248
|
+
* b-cloud-2026-11-13-connected-under-a-view): a record's page at Nearby
|
|
249
|
+
* is aimed beside the panel at the level's own zoom, unless the
|
|
250
|
+
* buildings of what it is linked to and what its page shows would fall
|
|
251
|
+
* outside the city's side of the window; then the camera stands back,
|
|
252
|
+
* no further than it must, to take them all in. That zoom is this
|
|
253
|
+
* page's Nearby, so the altitude read from the camera is the level's
|
|
254
|
+
* still, and the move there is the one move, as any level's is.
|
|
255
|
+
*/
|
|
256
|
+
let nearbyZoom = null;
|
|
257
|
+
/* 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. */
|
|
258
|
+
let framedKey = "";
|
|
259
|
+
let reframeAsked = false;
|
|
260
|
+
/*
|
|
261
|
+
* ONCE A MOVE, AND NEVER OVER A HAND: armed as a move to a record's Nearby
|
|
262
|
+
* begins, taken by the first word from a view of what it shows after
|
|
263
|
+
* that, and put away once taken or the moment the person moves the
|
|
264
|
+
* camera themselves. A list a view grows later never takes the camera
|
|
265
|
+
* from where somebody left it.
|
|
266
|
+
*/
|
|
267
|
+
let reframeArmed = false;
|
|
268
|
+
const askReframe = () => {
|
|
269
|
+
if (reframeArmed)
|
|
270
|
+
reframeAsked = true;
|
|
271
|
+
};
|
|
272
|
+
const byHand = () => {
|
|
273
|
+
reframeArmed = false;
|
|
274
|
+
reframeAsked = false;
|
|
275
|
+
};
|
|
276
|
+
const framingKeyNow = (id) => `${id}|${[...new Set([id, ...store.graph.neighbors(id).map((node) => node.id), ...markedOnPage()])].sort().join(" ")}`;
|
|
277
|
+
const zoomsOf = (where, view) => {
|
|
278
|
+
const zooms = levelZooms(where, view);
|
|
279
|
+
return nearbyZoom !== null && where.type === "record" ? [zooms[0], nearbyZoom, zooms[2]] : zooms;
|
|
280
|
+
};
|
|
281
|
+
/** The records a page shows, by what its parts mark and what a view drawn in it says. */
|
|
282
|
+
const markedOnPage = () => {
|
|
283
|
+
const plane = sheet.current;
|
|
284
|
+
if (!plane)
|
|
285
|
+
return [];
|
|
286
|
+
const ids = [];
|
|
287
|
+
for (const part of plane.querySelectorAll(`${RECORD_PARTS}, ${VIEW_PARTS}`)) {
|
|
288
|
+
const view = recordBoxesOf(part);
|
|
289
|
+
if (view)
|
|
290
|
+
ids.push(...view.shows());
|
|
291
|
+
else {
|
|
292
|
+
const named = recordShownBy(part);
|
|
293
|
+
if (named)
|
|
294
|
+
ids.push(named);
|
|
295
|
+
}
|
|
296
|
+
if (ids.length > 400)
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
return ids;
|
|
300
|
+
};
|
|
301
|
+
const nearbyFraming = (id, anchor, most, zoomNow) => {
|
|
302
|
+
const now = state.current;
|
|
303
|
+
const view = now.view;
|
|
304
|
+
const base = cameraPutting(anchor, aimAt(PANEL, view, footRoom()), most);
|
|
305
|
+
const ids = new Set([id, ...store.graph.neighbors(id).map((node) => node.id), ...markedOnPage()]);
|
|
306
|
+
framedKey = `${id}|${[...ids].sort().join(" ")}`;
|
|
307
|
+
const kinds = new Set();
|
|
308
|
+
const boxes = [...ids].flatMap((one) => {
|
|
309
|
+
const building = world.buildings.get(one);
|
|
310
|
+
if (!building)
|
|
311
|
+
return [];
|
|
312
|
+
const kind = store.graph.getNode(one)?.kind;
|
|
313
|
+
if (kind)
|
|
314
|
+
kinds.add(kind);
|
|
315
|
+
return [building];
|
|
316
|
+
});
|
|
317
|
+
// And each of their districts, with its name: a district's marks stay in sight with its buildings.
|
|
318
|
+
const named = [...kinds].flatMap((kind) => {
|
|
319
|
+
const plot = world.plots.get(kind);
|
|
320
|
+
return plot ? [plot] : [];
|
|
321
|
+
});
|
|
322
|
+
const around = boxes.length > 1 ? unionOf([...boxes, ...named]) : null;
|
|
323
|
+
if (!around)
|
|
324
|
+
return base;
|
|
325
|
+
// 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.
|
|
326
|
+
const bar = view.top ?? 0;
|
|
327
|
+
const panel = panelBox(view);
|
|
328
|
+
const dock = footNow().rest[0];
|
|
329
|
+
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) };
|
|
330
|
+
const margin = 28;
|
|
331
|
+
/*
|
|
332
|
+
* ALREADY IN SIGHT, THE CAMERA STAYS: a record opened from the city
|
|
333
|
+
* beside the page, where it and everything it is connected to already
|
|
334
|
+
* stand in the city's side as the camera rests, moves no camera.
|
|
335
|
+
*/
|
|
336
|
+
const buildings = unionOf(boxes);
|
|
337
|
+
const inSight = (cam, box) => {
|
|
338
|
+
const lo = project(cam, { x: box.x, y: box.y });
|
|
339
|
+
const hi = project(cam, { x: box.x + box.width, y: box.y + box.height });
|
|
340
|
+
return lo.x >= area.x && lo.y >= area.y && hi.x <= area.x + area.width && hi.y <= area.y + area.height;
|
|
341
|
+
};
|
|
342
|
+
if (rest === PANEL && !move && level(painted) && buildings && inSight(LEVEL_LIVE, buildings))
|
|
343
|
+
return LEVEL_LIVE;
|
|
344
|
+
const a = project(base, { x: around.x, y: around.y });
|
|
345
|
+
const b = project(base, { x: around.x + around.width, y: around.y + around.height });
|
|
346
|
+
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)
|
|
347
|
+
return base;
|
|
348
|
+
const fit = fitCamera(around, area, margin, most);
|
|
349
|
+
// Never as far back as the City, nor past what the camera can be written at.
|
|
350
|
+
const least = Math.max(1.02 / zoomNow, (camera.current?.range.min ?? 0) / zoomNow);
|
|
351
|
+
if (fit.s >= least)
|
|
352
|
+
return fit;
|
|
353
|
+
/* 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. */
|
|
354
|
+
const middleOf = { x: around.x + around.width / 2, y: around.y + around.height / 2 };
|
|
355
|
+
const held = cameraPutting(middleOf, project(fit, middleOf), least);
|
|
356
|
+
const own = world.buildings.get(id);
|
|
357
|
+
if (!own)
|
|
358
|
+
return held;
|
|
359
|
+
const lo = project(held, { x: own.x, y: own.y });
|
|
360
|
+
const hi = project(held, { x: own.x + own.width, y: own.y + own.height });
|
|
361
|
+
const shift = (low, high, from, to) => (low < from ? from - low : high > to ? to - high : 0);
|
|
362
|
+
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) };
|
|
363
|
+
};
|
|
164
364
|
/** The camera between stops this frame, as painted — the last one seen while the view takes in a move just let go. */
|
|
165
365
|
let painted = LEVEL_LIVE;
|
|
166
366
|
/** The level the camera rests at, and the altitude this frame. */
|
|
@@ -172,8 +372,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
172
372
|
let cityFoot = "";
|
|
173
373
|
/** Where the camera stood when it came to rest at the City: a hand that moved it since keeps it. */
|
|
174
374
|
let cityAt = "";
|
|
175
|
-
/**
|
|
176
|
-
let
|
|
375
|
+
/** The camera at the level rested at as a scrub began: the person's own, kept for the scrub to leave from. */
|
|
376
|
+
let restCam = null;
|
|
177
377
|
/*
|
|
178
378
|
* THE ZOOM THIS FACE LAST LEFT THE CAMERA AT. Only a zoom that differs
|
|
179
379
|
* from it is a hand's: a new address at rest asks the camera for a
|
|
@@ -194,6 +394,62 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
194
394
|
let lastReported = "";
|
|
195
395
|
/* 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
396
|
let committedAt = -Infinity;
|
|
397
|
+
/** When the last frame was drawn: a move does not count a stall between two as time gone by. */
|
|
398
|
+
let lastTick = 0;
|
|
399
|
+
/*
|
|
400
|
+
* THE PAGE CHOSEN IS DRAWN BEFORE IT MOVES. A new place's page is drawn
|
|
401
|
+
* by its route — on a slow machine, in tasks long enough to stall the
|
|
402
|
+
* frames after it — so a move to another place begins only once two
|
|
403
|
+
* frames running have come quickly (or a while has gone by, whatever the
|
|
404
|
+
* page is still doing): the page's drawing lands before the move, not
|
|
405
|
+
* inside it.
|
|
406
|
+
*/
|
|
407
|
+
let calmRun = 0;
|
|
408
|
+
/** The page a board was last placed for at once: one with no place to stand is not placed again every frame. */
|
|
409
|
+
let placedFor = "";
|
|
410
|
+
let placeSeenAt = 0;
|
|
411
|
+
let placeSeen = "";
|
|
412
|
+
const drawnSince = (placeKey, now) => {
|
|
413
|
+
if (placeKey !== placeSeen) {
|
|
414
|
+
placeSeen = placeKey;
|
|
415
|
+
placeSeenAt = now;
|
|
416
|
+
calmRun = 0;
|
|
417
|
+
}
|
|
418
|
+
return calmRun >= 2 || now - placeSeenAt > 700;
|
|
419
|
+
};
|
|
420
|
+
/*
|
|
421
|
+
* A PLACE READ AGAIN AT REST IS GONE TO, NOT JUMPED TO. Once the camera
|
|
422
|
+
* is written the Scene lays the city out again at that zoom, and a board
|
|
423
|
+
* or a name placed from it may stand a little elsewhere: it goes there
|
|
424
|
+
* over a moment, from where it was drawn.
|
|
425
|
+
*/
|
|
426
|
+
let settle = null;
|
|
427
|
+
/** 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. */
|
|
428
|
+
let rebaseNext = null;
|
|
429
|
+
const SETTLE_MS = 300;
|
|
430
|
+
/*
|
|
431
|
+
* A name's box is carried whole: its size too, which differs between
|
|
432
|
+
* levels (a size on the screen is many times wider in the picture far
|
|
433
|
+
* out). Carried with the size it is going to, a box caught part way —
|
|
434
|
+
* a move begun again when what stands at the foot changed — had its
|
|
435
|
+
* middle moved by half the difference in one frame: a name leapt a
|
|
436
|
+
* hundred pixels sideways.
|
|
437
|
+
*/
|
|
438
|
+
const blend = (from, to, t) => {
|
|
439
|
+
if (!to || !from)
|
|
440
|
+
return to;
|
|
441
|
+
const at = { ...to, x: from.x + (to.x - from.x) * t, y: from.y + (to.y - from.y) * t };
|
|
442
|
+
if ("width" in to && "width" in from && "height" in to && "height" in from) {
|
|
443
|
+
const [a, b] = [from, to];
|
|
444
|
+
return { ...at, width: a.width + (b.width - a.width) * t, height: a.height + (b.height - a.height) * t };
|
|
445
|
+
}
|
|
446
|
+
return at;
|
|
447
|
+
};
|
|
448
|
+
/** How far a move or a settle has gone, this frame: 1 when nothing is under way. */
|
|
449
|
+
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 };
|
|
450
|
+
/** Every board and name where it is drawn this frame. */
|
|
451
|
+
const drawnSlots = (now) => { const g = goneAt(now); return new Map([...slots].map(([key, at]) => [key, blend(g.slots?.get(key), at, g.t) ?? at])); };
|
|
452
|
+
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
453
|
const QUIET_MS = 220;
|
|
198
454
|
const lines = new Map();
|
|
199
455
|
/** The picture as laid out now, read while nothing is painted over it. */
|
|
@@ -208,20 +464,17 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
208
464
|
const buildings = new Map();
|
|
209
465
|
for (const building of holder.querySelectorAll("[data-graview-building]"))
|
|
210
466
|
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 };
|
|
467
|
+
/*
|
|
468
|
+
* A district's "+n" — the buildings its plot has no room for — is words
|
|
469
|
+
* in the picture, as a building's name is: stood clear of as a building
|
|
470
|
+
* is, so no district's name runs into it ("+43PLANTS 10").
|
|
471
|
+
*/
|
|
472
|
+
holder.querySelectorAll(".graview-village-rest").forEach((rest, i) => {
|
|
473
|
+
const box = boxOf(rest.getBoundingClientRect());
|
|
474
|
+
if (box.width > 0)
|
|
475
|
+
buildings.set(`${REST_KEY}${i}`, box);
|
|
476
|
+
});
|
|
477
|
+
return { plots, buildings };
|
|
225
478
|
};
|
|
226
479
|
/** What a page stands on in the picture as it is laid out. */
|
|
227
480
|
const placeIn = (at, w) => ({
|
|
@@ -231,87 +484,112 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
231
484
|
all: [...w.plots.values()],
|
|
232
485
|
});
|
|
233
486
|
/**
|
|
234
|
-
* WHERE EACH VIEW
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
487
|
+
* WHERE EACH VIEW AND EACH DISTRICT'S NAME STANDS (`placeSigns`): a view
|
|
488
|
+
* of one kind on its district, its post coming down onto its ground, the
|
|
489
|
+
* rest on the plaza at the city's back edge, a record's own page on its
|
|
490
|
+
* building; each district's name beside it or under it. And the box
|
|
238
491
|
* around all of it, which the city's camera fits.
|
|
492
|
+
*
|
|
493
|
+
* PLACED ON THE SCREEN AS THE CAMERA WILL HAVE IT. Names and boards are a
|
|
494
|
+
* size on the screen, so the picture is carried through the camera the
|
|
495
|
+
* level is headed for (`cam`, against the view's own zoom; none at rest)
|
|
496
|
+
* and placed there, in the screen's own pixels, then carried back: the
|
|
497
|
+
* place a move heads for and the place read again once it has arrived
|
|
498
|
+
* are one answer, never a second that the boards then jump to.
|
|
499
|
+
*
|
|
500
|
+
* AND ONCE. The same city, the same window and the same views place the
|
|
501
|
+
* same way: kept, and carried along a pan (a pan moves the camera, not
|
|
502
|
+
* the city) until what is placed changes or the pan has gone far enough
|
|
503
|
+
* to change what is in sight.
|
|
239
504
|
*/
|
|
240
505
|
let slots = new Map();
|
|
506
|
+
let posts = new Map();
|
|
507
|
+
let scales = new Map();
|
|
508
|
+
let names = new Map();
|
|
241
509
|
/** The city and every view standing in it, as last read: what the city's camera fits. */
|
|
242
510
|
let whole = null;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
511
|
+
let kept = null;
|
|
512
|
+
/** A window too small for a board beside every district: a phone, or one turned on its side. */
|
|
513
|
+
const cramped = () => state.current.view.width <= PHONE || state.current.view.height <= 600;
|
|
514
|
+
const standAll = (w, zoomNow, cam, bounds, lvl) => {
|
|
515
|
+
const view = state.current.view;
|
|
516
|
+
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 });
|
|
517
|
+
const tiles = new Map([...w.plots].map(([kind, box]) => [kind, onScreen(box)]));
|
|
518
|
+
const city = unionOf([...tiles.values()]);
|
|
519
|
+
const origin = city ? { x: city.x, y: city.y } : { x: 0, y: 0 };
|
|
520
|
+
// A size on the screen at most, and on a small window at least: what it says is read.
|
|
521
|
+
const natural = boardWidthFor(view) * zoomNow * cam.s;
|
|
522
|
+
const width = Math.max(Math.min(natural, boardMost(view, state.current.where, zoomNow * cam.s)), boardLeast(view));
|
|
523
|
+
const k = width / Math.max(1e-6, natural);
|
|
524
|
+
const sizes = new Map();
|
|
525
|
+
for (const [kind, el] of tagEls.current) {
|
|
526
|
+
if (!tiles.has(kind) || el.offsetWidth === 0)
|
|
254
527
|
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);
|
|
528
|
+
sizes.set(kind, { width: el.offsetWidth, height: el.offsetHeight });
|
|
261
529
|
}
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
//
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
530
|
+
const signs = state.current.boards.map((board) => ({
|
|
531
|
+
key: board.key,
|
|
532
|
+
kind: board.where.type === "record" ? board.where.kind : signKindOf(board.where),
|
|
533
|
+
building: board.where.type === "record" && w.buildings.has(board.where.id) ? onScreen(w.buildings.get(board.where.id)) : null,
|
|
534
|
+
// Beside a page, where the city's side is narrow, the app's views stand before the kinds' own lists: a view whose district is in sight keeps its board. Under the page too, so a move from it to Nearby carries each board from a place in the same order, never a leap halfway.
|
|
535
|
+
first: lvl !== CITY && board.where.type === "place",
|
|
536
|
+
}));
|
|
537
|
+
const reserved = footNow().now.map((box) => ({ x: box.x - 6, y: box.y - 6, width: box.width + 12, height: box.height + 12 }));
|
|
538
|
+
const round = (n) => Math.round(n / 2) * 2;
|
|
539
|
+
const rel = (box) => [round(box.x - origin.x), round(box.y - origin.y), round(box.width), round(box.height)];
|
|
540
|
+
const buildingsOnScreen = [...w.buildings.values()].map(onScreen);
|
|
541
|
+
const restsOnScreen = [...w.buildings].filter(([key]) => key.startsWith(REST_KEY)).map(([, box]) => onScreen(box));
|
|
542
|
+
// What decides the placing, the city's own lattice taken from where it stands: a pan of fewer than 24 pixels places nothing again.
|
|
543
|
+
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)))]);
|
|
544
|
+
let placed;
|
|
545
|
+
let shift = { x: 0, y: 0 };
|
|
546
|
+
if (kept && kept.key === key) {
|
|
547
|
+
placed = kept.placed;
|
|
548
|
+
shift = { x: origin.x - kept.origin.x, y: origin.y - kept.origin.y };
|
|
282
549
|
}
|
|
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
|
-
|
|
550
|
+
else {
|
|
551
|
+
placed = placeSigns({
|
|
552
|
+
tiles,
|
|
553
|
+
buildings: buildingsOnScreen,
|
|
554
|
+
names: sizes,
|
|
555
|
+
words: restsOnScreen,
|
|
556
|
+
signs,
|
|
557
|
+
board: { width, height: width / BOARD_ASPECT, post: SIGN_POST * zoomNow * cam.s * k, gap: SIGN_GAP * zoomNow * cam.s * k },
|
|
558
|
+
...(bounds ? { bounds } : {}),
|
|
559
|
+
// Nor under what stands at the foot: the control, the legend over it and the timeline.
|
|
560
|
+
reserved,
|
|
561
|
+
// 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.
|
|
562
|
+
// 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).
|
|
563
|
+
dropCovered: lvl === PANEL,
|
|
564
|
+
// Beside a page on a desk a view's board may stand higher over its own district before it stands nowhere.
|
|
565
|
+
reach: lvl === CITY ? (cramped() ? 30 : 16) : cramped() ? 12 : 24,
|
|
566
|
+
// A board drawn smaller where it must; beside a page as small as its floor (`boardLeast`) before it stands nowhere.
|
|
567
|
+
shrink: lvl === PANEL || !cramped(),
|
|
568
|
+
...(lvl === PANEL ? { least: boardLeast(view) } : {}),
|
|
569
|
+
// Beside the page the plaza is behind the city: only the views that stand on a district stand there.
|
|
570
|
+
plaza: lvl !== PANEL,
|
|
571
|
+
// Beside a page (and under it, so a move to Nearby carries each name from a place found the same way) each district's name stands right after the views, before the kinds' lists, and beside its own district or nowhere.
|
|
572
|
+
...(lvl !== CITY ? { namesFirst: true, nameReach: NAME_REACH } : {}),
|
|
573
|
+
});
|
|
574
|
+
kept = { key, origin, placed };
|
|
575
|
+
}
|
|
576
|
+
// Back into the picture's own pixels, as the view lays it out now.
|
|
577
|
+
const back = (p) => ({ x: (p.x + shift.x - cam.x) / cam.s, y: (p.y + shift.y - cam.y) / cam.s });
|
|
578
|
+
const backBox = (box) => ({ ...back(box), width: box.width / cam.s, height: box.height / cam.s });
|
|
579
|
+
const next = new Map([...placed.feet].map(([one, foot]) => [one, back(foot)]));
|
|
580
|
+
// A record's page whose building is not drawn stands where its district is.
|
|
581
|
+
for (const board of state.current.boards) {
|
|
582
|
+
if (next.has(board.key) || board.where.type !== "record")
|
|
583
|
+
continue;
|
|
584
|
+
const at = footOf(board.where, placeIn(board.where, w));
|
|
585
|
+
if (at)
|
|
586
|
+
next.set(board.key, at);
|
|
312
587
|
}
|
|
313
588
|
slots = next;
|
|
314
|
-
|
|
589
|
+
posts = new Map([...placed.posts].map(([one, length]) => [one, length / cam.s]));
|
|
590
|
+
scales = new Map(placed.scales);
|
|
591
|
+
names = new Map([...placed.names].map(([kind, box]) => [kind, backBox(box)]));
|
|
592
|
+
whole = placed.whole ? backBox(placed.whole) : null;
|
|
315
593
|
};
|
|
316
594
|
/*
|
|
317
595
|
* WHAT STANDS AT THE FOOT: the control, the legend over it when it is
|
|
@@ -336,6 +614,31 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
336
614
|
const dock = rest[0];
|
|
337
615
|
return { now, rest, key: dock ? `${Math.round(dock.x)},${Math.round(dock.y)},${Math.round(dock.width)},${Math.round(dock.height)}` : "" };
|
|
338
616
|
};
|
|
617
|
+
/** The part of the window the City is seen in, at rest there: under the bar, over what stands at the foot. */
|
|
618
|
+
const cityShown = () => {
|
|
619
|
+
const view = state.current.view;
|
|
620
|
+
const top = (view.top ?? 0) + 12;
|
|
621
|
+
const foot = Math.min(view.height, ...footNow().rest.map((box) => box.y)) - 12;
|
|
622
|
+
return { x: 12, y: top, width: view.width - 24, height: Math.max(1, foot - top) };
|
|
623
|
+
};
|
|
624
|
+
/** 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. */
|
|
625
|
+
const nearbyShown = () => {
|
|
626
|
+
const view = state.current.view;
|
|
627
|
+
const panel = panelBox(view);
|
|
628
|
+
const top = (view.top ?? 0) + 8;
|
|
629
|
+
// On a phone the control rides above the sheet at Nearby: the city is seen above both.
|
|
630
|
+
if (view.width <= PHONE)
|
|
631
|
+
return { x: 8, y: top, width: view.width - 16, height: Math.max(1, panel.y - footRoom() - 8 - top) };
|
|
632
|
+
return { x: 8, y: top, width: Math.max(1, panel.x - 16), height: Math.max(1, view.height - 8 - top) };
|
|
633
|
+
};
|
|
634
|
+
/** 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. */
|
|
635
|
+
const shownAt = (lvl) => (lvl === CITY ? (cramped() ? undefined : cityShown()) : lvl === PANEL ? nearbyShown() : undefined);
|
|
636
|
+
/** Placed for where a move ends, through the camera it ends at: the same answer as read again there. */
|
|
637
|
+
const placeFor = (lvl, to, zoomNow) => {
|
|
638
|
+
if (lvl === PAGE)
|
|
639
|
+
return;
|
|
640
|
+
standAll(world, zoomNow, to, shownAt(lvl), lvl);
|
|
641
|
+
};
|
|
339
642
|
/** How much of the window above a phone's sheet the control and the legend keep, at Nearby. */
|
|
340
643
|
const footRoom = () => {
|
|
341
644
|
const dock = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
|
|
@@ -351,7 +654,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
351
654
|
/** 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
655
|
const cameraFor = (lvl, anchor, zoomNow) => {
|
|
353
656
|
const now = state.current;
|
|
354
|
-
const zooms =
|
|
657
|
+
const zooms = zoomsOf(now.where, now.view);
|
|
355
658
|
const s = zooms[lvl] / zoomNow;
|
|
356
659
|
if (lvl === CITY) {
|
|
357
660
|
/*
|
|
@@ -362,14 +665,77 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
362
665
|
* held: the camera goes straight there and stops.
|
|
363
666
|
*/
|
|
364
667
|
if (whole) {
|
|
365
|
-
|
|
366
|
-
|
|
668
|
+
/*
|
|
669
|
+
* The names are a size on the screen: at the City they take less of
|
|
670
|
+
* the picture than where it was read. Placed again for the City's
|
|
671
|
+
* own scale, and fitted again, until the two agree.
|
|
672
|
+
*/
|
|
673
|
+
let fitted = fitBeside(whole, now.view, footNow().rest, 20, s);
|
|
674
|
+
for (let again = 0; again < 2; again++) {
|
|
675
|
+
standAll(world, zoomNow, fitted, undefined, CITY);
|
|
676
|
+
if (!whole)
|
|
677
|
+
break;
|
|
678
|
+
fitted = fitBeside(whole, now.view, footNow().rest, 20, s);
|
|
679
|
+
}
|
|
680
|
+
if (!whole)
|
|
681
|
+
return fitted;
|
|
367
682
|
// 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
683
|
const least = (camera.current?.range.min ?? 0) / zoomNow;
|
|
369
684
|
if (fitted.s >= least)
|
|
370
685
|
return fitted;
|
|
371
|
-
|
|
372
|
-
|
|
686
|
+
/*
|
|
687
|
+
* AS FAR OUT AS THE CAMERA GOES, AND EVERYTHING INSIDE WHAT IT SHOWS
|
|
688
|
+
* from there: the city in the middle of the window's part for it,
|
|
689
|
+
* and the names and views placed again inside that part — closer
|
|
690
|
+
* together, rather than past the window's edge (a phone's City).
|
|
691
|
+
*/
|
|
692
|
+
const city = unionOf([...world.plots.values()]) ?? whole;
|
|
693
|
+
const area = cityShown();
|
|
694
|
+
const at = cameraPutting(middle(city), middle(area), least);
|
|
695
|
+
standAll(world, zoomNow, at, shownAt(CITY), CITY);
|
|
696
|
+
return at;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
/*
|
|
700
|
+
* THE HOME BESIDE THE CITY: the city framed in the part the page leaves
|
|
701
|
+
* it — left of the panel on a desk, over the sheet on a phone — never
|
|
702
|
+
* the whole window, where the districts nearest the page stood behind it.
|
|
703
|
+
*/
|
|
704
|
+
if (lvl === PANEL && (now.where.type === "home" || now.where.type === "overview")) {
|
|
705
|
+
const city = unionOf([...world.plots.values()]);
|
|
706
|
+
if (city) {
|
|
707
|
+
const shown = nearbyShown();
|
|
708
|
+
const fit = fitCamera(city, shown, 16, s);
|
|
709
|
+
// 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.
|
|
710
|
+
const least = (camera.current?.range.min ?? 0) / zoomNow;
|
|
711
|
+
// Said on the city, for a reader of the page: whether the whole city stands beside the page here.
|
|
712
|
+
box.current?.toggleAttribute("data-graview-nearby-holds-the-city", fit.s >= least);
|
|
713
|
+
if (fit.s >= least)
|
|
714
|
+
return fit;
|
|
715
|
+
const kinds = new Set(markedOnPage().flatMap((id) => {
|
|
716
|
+
const kind = store.graph.getNode(id)?.kind;
|
|
717
|
+
return kind ? [kind] : [];
|
|
718
|
+
}));
|
|
719
|
+
const own = unionOf([...kinds].flatMap((kind) => {
|
|
720
|
+
const plot = world.plots.get(kind);
|
|
721
|
+
return plot ? [plot] : [];
|
|
722
|
+
}));
|
|
723
|
+
const what = own ?? city;
|
|
724
|
+
/*
|
|
725
|
+
* THE CITY AS NEAR THE MIDDLE OF ITS SIDE AS ITS VIEWS' DISTRICTS
|
|
726
|
+
* LET IT, they in the side whole: at the zoom that fits them where
|
|
727
|
+
* they fit on their own (a small phone's strip over the sheet), else
|
|
728
|
+
* as far out as the camera goes. Fitted on them alone, the city stood
|
|
729
|
+
* off to one side of a narrow strip with room to come to its middle.
|
|
730
|
+
*/
|
|
731
|
+
const close = fitCamera(what, shown, 16, s);
|
|
732
|
+
const held = cameraPutting(middle(city), middle(shown), Math.max(close.s, least));
|
|
733
|
+
const lo = project(held, { x: what.x, y: what.y });
|
|
734
|
+
const hi = project(held, { x: what.x + what.width, y: what.y + what.height });
|
|
735
|
+
const shift = (low, high, from, to) => (low < from ? from - low : high > to ? to - high : 0);
|
|
736
|
+
// Kept a little off the side's edge, as the fit is: never so far in that the city could come nearer the middle than it does.
|
|
737
|
+
const keep = HOME_EDGE;
|
|
738
|
+
return { s: held.s, x: held.x + shift(lo.x, hi.x, shown.x + keep, shown.x + shown.width - keep), y: held.y + shift(lo.y, hi.y, shown.y + keep, shown.y + shown.height - keep) };
|
|
373
739
|
}
|
|
374
740
|
}
|
|
375
741
|
if (lvl === CITY || now.where.type === "home" || now.where.type === "overview") {
|
|
@@ -377,12 +743,56 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
377
743
|
const middleOfCity = city ? middle(city) : anchor;
|
|
378
744
|
return cameraPutting(middleOfCity, aimAt(CITY, now.view), s);
|
|
379
745
|
}
|
|
746
|
+
if (lvl === PANEL && now.where.type === "record") {
|
|
747
|
+
const framed = nearbyFraming(now.where.id, anchor, s, zoomNow);
|
|
748
|
+
nearbyZoom = zoomNow * framed.s;
|
|
749
|
+
return framed;
|
|
750
|
+
}
|
|
751
|
+
if (lvl === PANEL)
|
|
752
|
+
nearbyZoom = null;
|
|
380
753
|
return cameraPutting(anchor, aimAt(lvl === PAGE ? PANEL : lvl, now.view, footRoom()), s);
|
|
381
754
|
};
|
|
382
755
|
/** Start a move of the camera to a level. */
|
|
383
|
-
|
|
756
|
+
/*
|
|
757
|
+
* THE CAMERA WRITTEN, THE PICTURE'S PIXELS ARE NEW: the Scene lays the
|
|
758
|
+
* city out again at the zoom written, and what stood where the move
|
|
759
|
+
* ended — through the camera it ended at — stands there in the new
|
|
760
|
+
* pixels: carried over at once, so the frame after the move draws every
|
|
761
|
+
* board and name where the frame before did.
|
|
762
|
+
*/
|
|
763
|
+
const rebase = (to) => {
|
|
764
|
+
const at = (p) => project(to, p);
|
|
765
|
+
const box = (b) => ({ ...at(b), width: b.width * to.s, height: b.height * to.s });
|
|
766
|
+
slots = new Map([...slots].map(([key, p]) => [key, at(p)]));
|
|
767
|
+
posts = new Map([...posts].map(([key, length]) => [key, length * to.s]));
|
|
768
|
+
names = new Map([...names].map(([key, b]) => [key, box(b)]));
|
|
769
|
+
whole = whole ? box(whole) : null;
|
|
770
|
+
settle = null;
|
|
771
|
+
world = { plots: new Map([...world.plots].map(([key, b]) => [key, box(b)])), buildings: new Map([...world.buildings].map(([key, b]) => [key, box(b)])) };
|
|
772
|
+
};
|
|
773
|
+
const moveTo = (cam, toLevel, anchor, now, arm = true) => {
|
|
774
|
+
reframeArmed = arm && toLevel === PANEL && state.current.where.type === "record";
|
|
384
775
|
const from = painted;
|
|
776
|
+
/*
|
|
777
|
+
* A PAGE CHOSEN AT REST LEAVES FROM WHERE ITS BOARD STANDS THERE. A
|
|
778
|
+
* building pressed at the City makes its record the page, and that page's
|
|
779
|
+
* board was placed nowhere yet: it would have started from where it will
|
|
780
|
+
* stand beside the page, forty pixels from the building pressed. Placed
|
|
781
|
+
* first where the camera rests, so the move carries it from there.
|
|
782
|
+
*/
|
|
783
|
+
// 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.
|
|
784
|
+
const namesFrom = drawnNames(now);
|
|
785
|
+
const slotsFrom = drawnSlots(now);
|
|
786
|
+
const own = state.current.current;
|
|
787
|
+
if (rest !== PAGE && !move && !slots.has(own) && level(painted)) {
|
|
788
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
789
|
+
const at = slots.get(own);
|
|
790
|
+
if (at)
|
|
791
|
+
slotsFrom.set(own, at);
|
|
792
|
+
}
|
|
793
|
+
settle = null;
|
|
385
794
|
const to = cameraFor(toLevel, anchor, cam.zoom());
|
|
795
|
+
placeFor(toLevel, to, cam.zoom());
|
|
386
796
|
const fromAltitude = altitude;
|
|
387
797
|
if (state.current.lessMotion) {
|
|
388
798
|
cam.liveTo(to);
|
|
@@ -391,6 +801,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
391
801
|
rest = toLevel;
|
|
392
802
|
cityFoot = "";
|
|
393
803
|
cam.commit();
|
|
804
|
+
rebaseNext = to;
|
|
394
805
|
committedAt = performance.now();
|
|
395
806
|
ownZoom = cam.zoom();
|
|
396
807
|
return;
|
|
@@ -403,11 +814,14 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
403
814
|
about: anchor,
|
|
404
815
|
start: now,
|
|
405
816
|
foot: footNow().key,
|
|
817
|
+
names: namesFrom,
|
|
818
|
+
slots: slotsFrom,
|
|
406
819
|
done: () => {
|
|
407
820
|
rest = toLevel;
|
|
408
821
|
altitude = toLevel;
|
|
409
822
|
cityFoot = "";
|
|
410
823
|
cam.commit();
|
|
824
|
+
rebaseNext = to;
|
|
411
825
|
committedAt = performance.now();
|
|
412
826
|
ownZoom = null;
|
|
413
827
|
},
|
|
@@ -415,6 +829,27 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
415
829
|
};
|
|
416
830
|
const tick = (now) => {
|
|
417
831
|
frame = requestAnimationFrame(tick);
|
|
832
|
+
/*
|
|
833
|
+
* A STALL IS NOT A LEAP. A move is clocked by the wall, and a frame the
|
|
834
|
+
* page could not draw (a chosen page's route drawn in one long task)
|
|
835
|
+
* left the next to catch the whole stall up at once: the page leapt a
|
|
836
|
+
* third of its way. A gap past 34 ms is taken out of the move's clock,
|
|
837
|
+
* so the move slows through it rather than jumps.
|
|
838
|
+
*/
|
|
839
|
+
if (lastTick > 0 && now - lastTick > 34) {
|
|
840
|
+
// 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.
|
|
841
|
+
const lost = now - lastTick - 1000 / 60;
|
|
842
|
+
if (move)
|
|
843
|
+
move.start += lost;
|
|
844
|
+
if (settle)
|
|
845
|
+
settle.start += lost;
|
|
846
|
+
}
|
|
847
|
+
calmRun = lastTick > 0 && now - lastTick < 50 ? calmRun + 1 : 0;
|
|
848
|
+
lastTick = now;
|
|
849
|
+
if (rebaseNext) {
|
|
850
|
+
rebase(rebaseNext);
|
|
851
|
+
rebaseNext = null;
|
|
852
|
+
}
|
|
418
853
|
const holder = box.current;
|
|
419
854
|
const plane = sheet.current;
|
|
420
855
|
const cam = camera.current;
|
|
@@ -436,6 +871,9 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
436
871
|
plane.style.transform = "";
|
|
437
872
|
plane.style.opacity = "";
|
|
438
873
|
plane.style.borderRadius = "";
|
|
874
|
+
// A full page's room above and below again: the shell's own (the gutter the frame sets itself).
|
|
875
|
+
plane.style.removeProperty("--graview-frame-top");
|
|
876
|
+
plane.style.removeProperty("--graview-frame-foot");
|
|
439
877
|
draw([], 0);
|
|
440
878
|
}
|
|
441
879
|
return;
|
|
@@ -457,20 +895,46 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
457
895
|
painted = LEVEL_LIVE;
|
|
458
896
|
/*
|
|
459
897
|
* THE CITY READ AGAIN ONLY WHEN IT MAY HAVE MOVED: a camera written,
|
|
460
|
-
* the window or the
|
|
898
|
+
* the window, the views or what stands at the foot changed, or a while gone by (a record added
|
|
461
899
|
* lays its district out again) — never every frame of a page at rest.
|
|
462
900
|
*/
|
|
463
|
-
const readKey = `${at.view.width}x${at.view.height}|${at.boards.length}|${at.current}|${zoomNowOf(cam)}|${holder.querySelector(".graview-plots > g")?.getAttribute("transform") ?? ""}`;
|
|
901
|
+
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
902
|
// 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
|
-
|
|
903
|
+
/*
|
|
904
|
+
* NEVER PLACED AGAIN FOR WHERE A MOVE LEFT. The first frame of a move
|
|
905
|
+
* paints the camera it starts from, which is a level's: read again
|
|
906
|
+
* there (a slow machine's frame long past the half-second), the
|
|
907
|
+
* level being left was placed again over the one headed for, without
|
|
908
|
+
* the part beside the page it is placed inside — and the names, slid
|
|
909
|
+
* along to stay in it, leapt sideways. Under way, the city is placed
|
|
910
|
+
* only for where the move ends.
|
|
911
|
+
*/
|
|
912
|
+
if (world.plots.size === 0 || (!move && (readKey !== lastReadKey || committedAt > lastRead || now - lastRead > 500))) {
|
|
466
913
|
world = readWorld(holder);
|
|
467
|
-
|
|
914
|
+
if (move)
|
|
915
|
+
placeFor(move.toAltitude, move.to, cam.zoom());
|
|
916
|
+
else {
|
|
917
|
+
const drawnBefore = { slots: drawnSlots(now), names: drawnNames(now) };
|
|
918
|
+
// At the City everything stands inside what the camera shows; the camera was fitted to it.
|
|
919
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
920
|
+
settle = { ...drawnBefore, start: now };
|
|
921
|
+
}
|
|
468
922
|
lastRead = now;
|
|
469
923
|
lastReadKey = readKey;
|
|
470
924
|
}
|
|
471
925
|
}
|
|
926
|
+
/*
|
|
927
|
+
* A NEW PAGE'S BOARD IS PLACED THE FRAME IT IS DRAWN. Chosen by Find, a
|
|
928
|
+
* link or a building, the page is its own board until it moves — and
|
|
929
|
+
* with no place yet it stood a frame on its district's middle, then on
|
|
930
|
+
* its board: a jump before the move began. Placed at once, where the
|
|
931
|
+
* camera rests.
|
|
932
|
+
*/
|
|
933
|
+
if (world.plots.size > 0 && rest !== PAGE && !move && level(painted) && !slots.has(at.current) && placedFor !== at.current) {
|
|
934
|
+
placedFor = at.current;
|
|
935
|
+
standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
|
|
936
|
+
}
|
|
472
937
|
const anchor = world.plots.size > 0 ? anchorIn(at.where, world) : null;
|
|
473
|
-
const zooms = levelZooms(at.where, at.view);
|
|
474
938
|
const zoomNow = cam.zoom();
|
|
475
939
|
const placeKey = `${keyOf(at.where)}|${at.view.width}x${at.view.height}`;
|
|
476
940
|
/* At the page, the camera waits where stepping out begins: aimed for each place before anything moves. */
|
|
@@ -485,10 +949,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
485
949
|
ready = true;
|
|
486
950
|
}
|
|
487
951
|
/* 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) {
|
|
952
|
+
if (ready && calm && anchor && asking.level !== null && !move && !settling && (placeKey === lastPlace || drawnSince(placeKey, now))) {
|
|
489
953
|
const toLevel = asking.level;
|
|
490
954
|
asking.level = null;
|
|
491
|
-
if
|
|
955
|
+
// The level it rests at, asked again: back to that level's framing, if a hand has moved the camera from it.
|
|
956
|
+
const offFraming = () => {
|
|
957
|
+
const want = cameraFor(rest, anchor, zoomNow);
|
|
958
|
+
return Math.hypot(want.x - painted.x, want.y - painted.y) + Math.abs(want.s - painted.s) * 100 > 2;
|
|
959
|
+
};
|
|
960
|
+
if (toLevel !== rest || placeKey !== lastPlace || (rest !== PAGE && offFraming()))
|
|
492
961
|
moveTo(cam, toLevel, anchor, now);
|
|
493
962
|
lastPlace = placeKey;
|
|
494
963
|
}
|
|
@@ -501,7 +970,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
501
970
|
// The cameras of the levels either side, the one rested at as it is (a pan the person made is kept).
|
|
502
971
|
const lower = Math.floor(target);
|
|
503
972
|
const upper = Math.min(CITY, lower + 1);
|
|
504
|
-
|
|
973
|
+
// 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.
|
|
974
|
+
const camOf = (lvl) => (lvl === rest && rest !== PAGE ? (restCam ??= painted) : cameraFor(lvl, anchor, zoomNow));
|
|
505
975
|
const placed = cameraBetween(camOf(lower), camOf(upper), anchor, target - lower);
|
|
506
976
|
cam.liveTo(placed);
|
|
507
977
|
painted = placed;
|
|
@@ -511,8 +981,17 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
511
981
|
}
|
|
512
982
|
if (asking.scrubbing && !asking.held && now - handSince > LET_GO_MS && !settling && calm) {
|
|
513
983
|
asking.scrubbing = false;
|
|
984
|
+
restCam = null;
|
|
514
985
|
if (anchor)
|
|
515
|
-
moveTo(cam, restingLevel(altitude), anchor, now);
|
|
986
|
+
moveTo(cam, restingLevel(altitude), anchor, now, false);
|
|
987
|
+
}
|
|
988
|
+
/* A VIEW'S RECORDS SAID AFTER NEARBY WAS FRAMED: framed again, the one camera moving there from where it is. */
|
|
989
|
+
if (reframeAsked && !move && !asking.scrubbing && !settling && calm && anchor) {
|
|
990
|
+
reframeAsked = false;
|
|
991
|
+
if (rest === PANEL && at.where.type === "record" && framingKeyNow(at.where.id) !== framedKey) {
|
|
992
|
+
reframeArmed = false;
|
|
993
|
+
moveTo(cam, PANEL, anchor, now, false);
|
|
994
|
+
}
|
|
516
995
|
}
|
|
517
996
|
/* A MOVE UNDER WAY: the camera set from how far it has got. */
|
|
518
997
|
if (move) {
|
|
@@ -529,7 +1008,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
529
1008
|
move.from = painted;
|
|
530
1009
|
move.fromAltitude = altitude;
|
|
531
1010
|
move.start = now;
|
|
1011
|
+
move.names = drawnNames(now);
|
|
1012
|
+
move.slots = drawnSlots(now);
|
|
532
1013
|
move.to = cameraFor(move.toAltitude, move.about, cam.zoom());
|
|
1014
|
+
placeFor(move.toAltitude, move.to, cam.zoom());
|
|
533
1015
|
}
|
|
534
1016
|
const t = clamp01((now - move.start) / MOVE_MS);
|
|
535
1017
|
const e = ease(t);
|
|
@@ -546,12 +1028,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
546
1028
|
else if (!asking.scrubbing && !settling) {
|
|
547
1029
|
/*
|
|
548
1030
|
* 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.
|
|
1031
|
+
* ctrl+wheel over the city zooms its camera and moves no level — at
|
|
1032
|
+
* Nearby and the City alike. A level is the page's to step.
|
|
552
1033
|
*/
|
|
553
1034
|
const effective = zoomNow * painted.s;
|
|
554
|
-
const atZoom = altitudeAt(effective, zooms);
|
|
555
1035
|
// The zoom a move just written into the view settles a beat later: it is the face's own once it is still.
|
|
556
1036
|
if (ownZoom === null && calm)
|
|
557
1037
|
ownZoom = effective;
|
|
@@ -586,14 +1066,20 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
586
1066
|
if (ownZoom !== null && Math.abs(Math.log(effective / ownZoom)) > 0.001)
|
|
587
1067
|
ownZoom = effective;
|
|
588
1068
|
}
|
|
589
|
-
else if (rest
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1069
|
+
else if (rest === PANEL) {
|
|
1070
|
+
/*
|
|
1071
|
+
* AT NEARBY THE CAMERA IS FREE TOO (Graview HQ
|
|
1072
|
+
* feature:f-one-face-explore-city-beside-panel). A pinch or a
|
|
1073
|
+
* ctrl+wheel over the city beside the page moves closer to what is
|
|
1074
|
+
* under the hand and back out, a drag or a scroll pans it, and the
|
|
1075
|
+
* page and the level stay where they are: a level is stepped by a
|
|
1076
|
+
* pinch over the page, the control or the keys — and the control
|
|
1077
|
+
* and the keys at Nearby bring the camera back to its framing.
|
|
1078
|
+
*/
|
|
1079
|
+
if (ownZoom !== null && Math.abs(Math.log(effective / ownZoom)) > 0.001)
|
|
1080
|
+
ownZoom = effective;
|
|
1081
|
+
if (placeKey === lastPlace)
|
|
1082
|
+
altitude = PANEL;
|
|
597
1083
|
}
|
|
598
1084
|
else if (!(rest !== PAGE && placeKey !== lastPlace))
|
|
599
1085
|
altitude = rest;
|
|
@@ -622,10 +1108,24 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
622
1108
|
ownZoom = null;
|
|
623
1109
|
}
|
|
624
1110
|
// 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]")) {
|
|
1111
|
+
if (rest !== PAGE && !move && !asking.scrubbing && anchor && placeKey !== lastPlace && !settling && calm && holder.querySelector("[data-graview-settled]") && drawnSince(placeKey, now)) {
|
|
626
1112
|
lastPlace = placeKey;
|
|
627
|
-
|
|
628
|
-
|
|
1113
|
+
/*
|
|
1114
|
+
* A RECORD OPENED BESIDE THE CITY WHERE IT IS SEEN IS LIT WHERE IT
|
|
1115
|
+
* STANDS. Pressed at Nearby (or opened by a link or a pill) with its
|
|
1116
|
+
* building in the part of the city the page leaves, the camera does
|
|
1117
|
+
* not move: every building keeps its box to the pixel, and only the
|
|
1118
|
+
* boards and names go over a moment to where they stand for it.
|
|
1119
|
+
*/
|
|
1120
|
+
const building = at.where.type === "record" ? world.buildings.get(at.where.id) : undefined;
|
|
1121
|
+
if (rest === PANEL && building && level(painted) && inside(project(painted, { x: building.x + building.width / 2, y: building.y + building.height / 2 }), nearbyShown())) {
|
|
1122
|
+
settle = { slots: drawnSlots(now), names: drawnNames(now), start: now };
|
|
1123
|
+
standAll(world, zoomNow, LEVEL_LIVE, shownAt(rest), rest);
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
// Chosen at the city — a Find result, a link — a page lands beside the city, as a view chosen there does.
|
|
1127
|
+
moveTo(cam, rest === CITY ? PANEL : rest, anchor, now);
|
|
1128
|
+
}
|
|
629
1129
|
}
|
|
630
1130
|
/* 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
1131
|
const a = altitude;
|
|
@@ -641,10 +1141,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
641
1141
|
const panel = panelBox(at.view);
|
|
642
1142
|
const pageAt = pageBox(a, at.view);
|
|
643
1143
|
/* The boards' size this frame: their width in the picture, carried through the camera painted now. */
|
|
644
|
-
|
|
1144
|
+
// A size on the screen at most, as `standAll` placed them: at Nearby the camera is close.
|
|
1145
|
+
const boardWidth = Math.max(Math.min(boardWidthFor(at.view) * zoomNow * painted.s, boardMost(at.view, at.where, zoomNow * painted.s)), boardLeast(at.view));
|
|
645
1146
|
// 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
|
-
|
|
1147
|
+
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;
|
|
1148
|
+
// 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.
|
|
1149
|
+
const gone = goneAt(now);
|
|
1150
|
+
const carried = gone.t;
|
|
1151
|
+
const slotNow = (key) => blend(gone.slots?.get(key), slots.get(key), carried);
|
|
1152
|
+
const ownSlot = slotNow(at.current);
|
|
648
1153
|
const ownFoot = ownSlot ? project(painted, ownSlot) : anchor ? project(painted, anchor) : { x: at.view.width / 2, y: at.view.height / 2 };
|
|
649
1154
|
const standing = away && a > PANEL ? standingAt(a, panel, ownFoot, intoWidth) : null;
|
|
650
1155
|
if (away) {
|
|
@@ -659,6 +1164,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
659
1164
|
plane.style.borderRadius = `${(a >= PANEL ? 10 / (standing?.scale ?? 1) : 10 * a).toFixed(2)}px`;
|
|
660
1165
|
if (standing && plane.scrollTop !== 0 && a > 1.9)
|
|
661
1166
|
plane.scrollTop = 0;
|
|
1167
|
+
// 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).
|
|
1168
|
+
for (const [name, value] of Object.entries(frameSpacingAt(a)))
|
|
1169
|
+
if (plane.style.getPropertyValue(name) !== value)
|
|
1170
|
+
plane.style.setProperty(name, value);
|
|
662
1171
|
}
|
|
663
1172
|
else {
|
|
664
1173
|
plane.style.transform = "";
|
|
@@ -673,36 +1182,128 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
673
1182
|
list.style.height = `${((inner?.scrollHeight ?? 0) * ease(grown)).toFixed(2)}px`;
|
|
674
1183
|
list.style.opacity = String(ease(grown));
|
|
675
1184
|
}
|
|
676
|
-
/*
|
|
677
|
-
|
|
1185
|
+
/*
|
|
1186
|
+
* THE BOARDS: each on its slot, through this frame's camera, at the
|
|
1187
|
+
* page's own size scaled — a size on the screen at most. The views
|
|
1188
|
+
* stand at Nearby as at the City; the page's own board is the page
|
|
1189
|
+
* itself, and is drawn only once the page has become it.
|
|
1190
|
+
*/
|
|
1191
|
+
const shownBoards = a >= PANEL ? 1 : ease(clamp01((a - 0.6) / 0.4));
|
|
1192
|
+
const shownOwn = ease(clamp01((a - 1.25) / 0.6));
|
|
678
1193
|
const layer = boardLayer.current;
|
|
679
1194
|
if (layer) {
|
|
680
|
-
const reachable = a >
|
|
1195
|
+
const reachable = a > 0.95 && !move;
|
|
681
1196
|
if (layer.inert === reachable)
|
|
682
1197
|
layer.inert = !reachable;
|
|
683
1198
|
layer.setAttribute("data-graview-boards-shown", shownBoards.toFixed(3));
|
|
684
1199
|
}
|
|
1200
|
+
/*
|
|
1201
|
+
* NOTHING OF THE CITY'S UNDER THE BAR, THE PAGE OR THE LEVEL CONTROL —
|
|
1202
|
+
* after a hand's pan too, which carries what was placed with the city
|
|
1203
|
+
* until it is placed again: a board or a district's name that a pan
|
|
1204
|
+
* has brought under one of them is put away (unseen, unreached) until
|
|
1205
|
+
* it comes out again.
|
|
1206
|
+
*/
|
|
1207
|
+
const dockRect = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
|
|
1208
|
+
const keepOut = move
|
|
1209
|
+
? []
|
|
1210
|
+
: [
|
|
1211
|
+
{ x: 0, y: 0, width: at.view.width, height: at.view.top ?? 0 },
|
|
1212
|
+
...(a > 0.5 && a < 1.5 ? [boxOf(plane.getBoundingClientRect())] : []),
|
|
1213
|
+
...(dockRect && dockRect.width > 0 ? [boxOf(dockRect)] : []),
|
|
1214
|
+
];
|
|
1215
|
+
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);
|
|
1216
|
+
// Every board and name a press reaches this frame: a line's ring under or against one of them is not offered.
|
|
1217
|
+
pressable.length = 0;
|
|
685
1218
|
for (const [key, button] of boardEls.current ?? []) {
|
|
686
|
-
|
|
687
|
-
|
|
1219
|
+
/*
|
|
1220
|
+
* A board that had no place where the move began (its district out
|
|
1221
|
+
* of sight) comes up where it will stand as the move goes on, and one
|
|
1222
|
+
* that will have none goes down where it stood: never one frame from
|
|
1223
|
+
* nowhere to full.
|
|
1224
|
+
*/
|
|
1225
|
+
const goal = slots.get(key);
|
|
1226
|
+
const was = gone.slots?.get(key);
|
|
1227
|
+
const arriving = gone.slots !== null && goal !== undefined && was === undefined ? carried : 1;
|
|
1228
|
+
const leaving = gone.slots !== null && goal === undefined && was !== undefined ? 1 - carried : 1;
|
|
1229
|
+
const slot = goal ? slotNow(key) : gone.slots && was ? was : undefined;
|
|
1230
|
+
const w = boardWidth * (scales.get(key) ?? 1);
|
|
1231
|
+
const h = w / BOARD_ASPECT;
|
|
1232
|
+
const footAt = slot ? project(painted, slot) : null;
|
|
1233
|
+
const covered = key !== at.current && footAt !== null && under({ x: footAt.x - w / 2, y: footAt.y - h, width: w, height: h });
|
|
1234
|
+
// 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.
|
|
1235
|
+
button.toggleAttribute("data-graview-under", covered);
|
|
1236
|
+
const seen = slot && !covered ? (key === at.current ? shownOwn : shownBoards) * arriving * leaving : 0;
|
|
1237
|
+
// Not seen, it is not reached: out of the keyboard's order and the pointer's, as a board going away is.
|
|
1238
|
+
const reached = seen > 0.5 && (key === at.current ? a > 1.5 : a > 0.95) && !move;
|
|
1239
|
+
if (button.inert === reached)
|
|
1240
|
+
button.inert = !reached;
|
|
1241
|
+
if (!slot || seen <= 0.001) {
|
|
688
1242
|
if (button.style.opacity !== "0")
|
|
689
1243
|
button.style.opacity = "0";
|
|
690
1244
|
button.style.pointerEvents = "none";
|
|
691
1245
|
continue;
|
|
692
1246
|
}
|
|
693
|
-
const foot = project(painted, slot);
|
|
694
|
-
const w = boardWidth;
|
|
695
|
-
const h = w / BOARD_ASPECT;
|
|
1247
|
+
const foot = footAt ?? project(painted, slot);
|
|
696
1248
|
button.style.left = `${(foot.x - w / 2).toFixed(2)}px`;
|
|
697
1249
|
button.style.top = `${(foot.y - h).toFixed(2)}px`;
|
|
698
1250
|
button.style.width = `${w.toFixed(2)}px`;
|
|
699
1251
|
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 =
|
|
1252
|
+
button.style.opacity = key === at.current ? (shownOwn > 0.001 ? "1" : "0") : seen.toFixed(3);
|
|
1253
|
+
button.style.setProperty("--graview-sign-post", `${((posts.get(key) ?? SIGN_POST * zoomNow) * painted.s).toFixed(2)}px`);
|
|
1254
|
+
button.style.pointerEvents = reached ? "auto" : "none";
|
|
1255
|
+
if (reached)
|
|
1256
|
+
pressable.push({ x: foot.x - w / 2, y: foot.y - h, width: w, height: h });
|
|
703
1257
|
const face = button.firstElementChild;
|
|
704
1258
|
if (face)
|
|
705
|
-
face.style.transform = `scale(${(w /
|
|
1259
|
+
face.style.transform = `scale(${(w / boardFaceWidth(at.view)).toFixed(5)})`;
|
|
1260
|
+
}
|
|
1261
|
+
/*
|
|
1262
|
+
* THE DISTRICTS' NAMES come up with the views, and the Scene's own
|
|
1263
|
+
* names stand down as they do: one name a district at every altitude.
|
|
1264
|
+
* Each is placed through this frame's camera, a size on the screen.
|
|
1265
|
+
*/
|
|
1266
|
+
const shownNames = a >= PANEL ? 1 : ease(clamp01((a - 0.6) / 0.4));
|
|
1267
|
+
holder.style.setProperty("--graview-one-face-plates", (1 - shownNames).toFixed(3));
|
|
1268
|
+
holder.toggleAttribute("data-graview-names-said", shownNames > 0.999);
|
|
1269
|
+
// 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.
|
|
1270
|
+
const along = gone.t;
|
|
1271
|
+
for (const [kind, el] of tagEls.current) {
|
|
1272
|
+
const goal = names.get(kind);
|
|
1273
|
+
const from = gone.names?.get(kind);
|
|
1274
|
+
const was = from ?? goal;
|
|
1275
|
+
const fade = gone.names && goal && !from ? along : gone.names && !goal && from ? 1 - along : 1;
|
|
1276
|
+
const place = goal ?? (gone.names ? from : undefined);
|
|
1277
|
+
const seen = place ? shownNames * fade : 0;
|
|
1278
|
+
const reached = seen > 0.95 && !move && a > 0.95;
|
|
1279
|
+
if (el.inert === reached)
|
|
1280
|
+
el.inert = !reached;
|
|
1281
|
+
if (!place || !was || seen <= 0.001) {
|
|
1282
|
+
if (el.style.visibility !== "hidden")
|
|
1283
|
+
el.style.visibility = "hidden";
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
el.style.visibility = "visible";
|
|
1287
|
+
el.style.opacity = seen.toFixed(3);
|
|
1288
|
+
/*
|
|
1289
|
+
* The name's middle goes from where it was to where it will be. Its box
|
|
1290
|
+
* at the end of a move is the size it is in the picture there — a size
|
|
1291
|
+
* on the screen taken through a camera much further out is many times
|
|
1292
|
+
* wider in the picture — so the middle is carried, never the left edge
|
|
1293
|
+
* with the width at the end: that put a name a hundred pixels off in
|
|
1294
|
+
* the first frame of a move to the City.
|
|
1295
|
+
*/
|
|
1296
|
+
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 });
|
|
1297
|
+
el.style.left = `${(top.x - el.offsetWidth / 2).toFixed(2)}px`;
|
|
1298
|
+
el.style.top = `${top.y.toFixed(2)}px`;
|
|
1299
|
+
const covered = under({ x: top.x - el.offsetWidth / 2, y: top.y, width: el.offsetWidth, height: el.offsetHeight });
|
|
1300
|
+
el.toggleAttribute("data-graview-under", covered);
|
|
1301
|
+
if (!covered && reached)
|
|
1302
|
+
pressable.push({ x: top.x - el.offsetWidth / 2, y: top.y, width: el.offsetWidth, height: el.offsetHeight });
|
|
1303
|
+
if (covered) {
|
|
1304
|
+
el.style.visibility = "hidden";
|
|
1305
|
+
el.inert = true;
|
|
1306
|
+
}
|
|
706
1307
|
}
|
|
707
1308
|
/* 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
1309
|
const button = fab.current;
|
|
@@ -742,13 +1343,87 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
742
1343
|
const node = store.graph.getNode(target.id);
|
|
743
1344
|
return node ? labelOf(store.schema.tryDefinition(node.kind), node) : target.id;
|
|
744
1345
|
};
|
|
745
|
-
|
|
746
|
-
const
|
|
1346
|
+
/* The page's box in sight, read once a frame for every part on it. */
|
|
1347
|
+
const ports = new Map();
|
|
1348
|
+
const portOf = (element) => {
|
|
1349
|
+
const port = element.closest("[data-graview-one-place]");
|
|
1350
|
+
if (!port)
|
|
1351
|
+
return null;
|
|
1352
|
+
let box = ports.get(port);
|
|
1353
|
+
if (!box)
|
|
1354
|
+
ports.set(port, (box = port.getBoundingClientRect()));
|
|
1355
|
+
return box;
|
|
1356
|
+
};
|
|
1357
|
+
/* 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. */
|
|
1358
|
+
const asked = [];
|
|
1359
|
+
/** Every part's box on the page in sight: what a line inside the page goes round. */
|
|
1360
|
+
const words = [];
|
|
1361
|
+
// `framed`: drawn by a view (a worker view, a frame), whose words between its records the page cannot read.
|
|
1362
|
+
const offer = (target, part, visible, partBox, framed = false) => {
|
|
1363
|
+
const key = target.type === "record" ? target.id : `kind:${target.kind}`;
|
|
1364
|
+
// Only what is in sight on the page: a part scrolled past, or under the page's own edge, draws none.
|
|
1365
|
+
if (part.x < visible.left || part.x > visible.right || part.y < visible.top || part.y > visible.bottom)
|
|
1366
|
+
return;
|
|
1367
|
+
if (partBox.width > 0 && partBox.height > 0)
|
|
1368
|
+
words.push(partBox);
|
|
1369
|
+
if (taken.has(key))
|
|
1370
|
+
return;
|
|
1371
|
+
const end = endOf(target);
|
|
1372
|
+
if (!end)
|
|
1373
|
+
return;
|
|
1374
|
+
taken.add(key);
|
|
1375
|
+
asked.push({ key, target, part, box: partBox, visible, end, framed });
|
|
1376
|
+
};
|
|
1377
|
+
/* The record page drawn by a view that names no other record: where its one line to the record leaves from. */
|
|
1378
|
+
let aboutPart = null;
|
|
1379
|
+
// 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.
|
|
1380
|
+
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
1381
|
for (const element of parts) {
|
|
748
|
-
if (
|
|
1382
|
+
if (asked.length >= MOST_LINES)
|
|
749
1383
|
break;
|
|
750
1384
|
if (element.closest("nav, header, [role=navigation], [role=banner]"))
|
|
751
1385
|
continue;
|
|
1386
|
+
const visible = portOf(element);
|
|
1387
|
+
if (!visible)
|
|
1388
|
+
continue;
|
|
1389
|
+
const boxes = recordBoxesOf(element);
|
|
1390
|
+
if (boxes) {
|
|
1391
|
+
const rect = element.getBoundingClientRect();
|
|
1392
|
+
if (rect.width < 1 || rect.height < 1)
|
|
1393
|
+
continue;
|
|
1394
|
+
// Its pixels carried through its box as this frame paints it: the page scales as it moves a level.
|
|
1395
|
+
const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
1396
|
+
let named = false;
|
|
1397
|
+
let about = null;
|
|
1398
|
+
for (const box of boxes.boxes()) {
|
|
1399
|
+
if (asked.length >= MOST_LINES)
|
|
1400
|
+
break;
|
|
1401
|
+
if (!store.graph.getNode(box.id))
|
|
1402
|
+
continue;
|
|
1403
|
+
const part = { x: rect.left + (box.x + box.width / 2) * scale, y: rect.top + (box.y + box.height / 2) * scale };
|
|
1404
|
+
const partBox = { x: rect.left + box.x * scale, y: rect.top + box.y * scale, width: box.width * scale, height: box.height * scale };
|
|
1405
|
+
if (box.id === subjectId) {
|
|
1406
|
+
about ??= part;
|
|
1407
|
+
if (partBox.width > 0 && partBox.height > 0)
|
|
1408
|
+
words.push(partBox);
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1411
|
+
named = true;
|
|
1412
|
+
offer({ type: "record", id: box.id }, part, visible, partBox, true);
|
|
1413
|
+
}
|
|
1414
|
+
if (!named && subjectId !== null && aboutPart === null) {
|
|
1415
|
+
// From the middle of what is in sight of it, or the record's own part where it drew one.
|
|
1416
|
+
const top = Math.max(rect.top, visible.top);
|
|
1417
|
+
const bottom = Math.min(rect.bottom, visible.bottom);
|
|
1418
|
+
const left = Math.max(rect.left, visible.left);
|
|
1419
|
+
const right = Math.min(rect.right, visible.right);
|
|
1420
|
+
if (about)
|
|
1421
|
+
aboutPart = { part: about, visible, box: { ...about, width: 0, height: 0 } };
|
|
1422
|
+
else if (bottom - top >= 1 && right - left >= 1)
|
|
1423
|
+
aboutPart = { part: { x: (left + right) / 2, y: (top + bottom) / 2 }, visible, box: { x: left, y: top, width: right - left, height: bottom - top } };
|
|
1424
|
+
}
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
752
1427
|
const named = recordShownBy(element);
|
|
753
1428
|
let target = null;
|
|
754
1429
|
if (named !== null && store.graph.getNode(named))
|
|
@@ -759,28 +1434,181 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
759
1434
|
}
|
|
760
1435
|
if (!target || (target.type === "record" && target.id === subjectId))
|
|
761
1436
|
continue;
|
|
762
|
-
const key = target.type === "record" ? target.id : `kind:${target.kind}`;
|
|
763
|
-
if (taken.has(key))
|
|
764
|
-
continue;
|
|
765
1437
|
const rect = element.getBoundingClientRect();
|
|
766
1438
|
if (rect.width < 1 || rect.height < 1)
|
|
767
1439
|
continue;
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1440
|
+
offer(target, { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }, visible, boxOf(rect));
|
|
1441
|
+
}
|
|
1442
|
+
if (aboutPart && subjectId !== null && asked.length < MOST_LINES)
|
|
1443
|
+
offer({ type: "record", id: subjectId }, aboutPart.part, aboutPart.visible, aboutPart.box);
|
|
1444
|
+
/*
|
|
1445
|
+
* INSIDE THE PAGE A LINE CROSSES NO ONE ELSE'S WORDS (Graview Cloud's
|
|
1446
|
+
* Deep Time: a row's later pills struck through the earlier ones on
|
|
1447
|
+
* their way to the panel's edge). Each line leaves its own part; where
|
|
1448
|
+
* the straight way to the edge would cross another part, it drops
|
|
1449
|
+
* into the gap above or below its row — the one toward where it is
|
|
1450
|
+
* going first — runs along it to the edge, and goes on from there.
|
|
1451
|
+
* Lines along one gap stand a pixel or two apart.
|
|
1452
|
+
*
|
|
1453
|
+
* ON A PHONE THE SAME, toward the sheet's top edge: along the gap to
|
|
1454
|
+
* the sheet's side, clear of its words, and up that side to the top —
|
|
1455
|
+
* never straight up across the rows above.
|
|
1456
|
+
*
|
|
1457
|
+
* IN A VIEW (a worker view, a frame) the page cannot read the words
|
|
1458
|
+
* between its records: the middle of a gap between two rows may be a
|
|
1459
|
+
* paragraph (Graview Cloud's Family tree, where the lines from a pill
|
|
1460
|
+
* row rose into the paragraph above it and drew a box through it). A
|
|
1461
|
+
* line there takes the gap below its row first, and keeps to its
|
|
1462
|
+
* row's own edge — never further from it than the rows' own spacing —
|
|
1463
|
+
* so it never runs along a gap that holds words. On a phone it never
|
|
1464
|
+
* goes straight up through them either.
|
|
1465
|
+
*/
|
|
1466
|
+
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);
|
|
1467
|
+
const edgeX = pageRect.x;
|
|
1468
|
+
/** Something standing on the sheet's top edge there (the control riding on it): a line up that side would leave the edge somewhere else. */
|
|
1469
|
+
const standsOnTheEdge = (x) => reserved.some((box) => x >= box.x - 3 && x <= box.x + box.width + 3 && box.y + box.height >= pageRect.y - 43 && box.y - 3 <= pageRect.y);
|
|
1470
|
+
const districtOf = (target) => (target.type === "record" ? (store.graph.getNode(target.id)?.kind ?? null) : target.kind);
|
|
1471
|
+
/*
|
|
1472
|
+
* ON A PHONE, ONE RISER A DISTRICT (Graview Cloud's Deep Time, the
|
|
1473
|
+
* Cretaceous at 390: each row's line rose up the sheet's edge on its
|
|
1474
|
+
* own, ten verticals side by side). Every line into one district runs
|
|
1475
|
+
* along its row to the same place in the sheet's margin and goes up
|
|
1476
|
+
* as one. The district whose lines start lowest goes up outermost, so
|
|
1477
|
+
* no run along a row above crosses another district's riser.
|
|
1478
|
+
*/
|
|
1479
|
+
const risers = new Map();
|
|
1480
|
+
if (phone) {
|
|
1481
|
+
const right = pageRect.x + pageRect.width;
|
|
1482
|
+
const onRight = !standsOnTheEdge(right - SHEET_SIDE) || standsOnTheEdge(pageRect.x + SHEET_SIDE);
|
|
1483
|
+
const lowest = new Map();
|
|
1484
|
+
for (const one of asked) {
|
|
1485
|
+
const kind = districtOf(one.target);
|
|
1486
|
+
if (kind)
|
|
1487
|
+
lowest.set(kind, Math.max(lowest.get(kind) ?? -Infinity, one.part.y));
|
|
1488
|
+
}
|
|
1489
|
+
const order = [...lowest.keys()].sort((p, q) => lowest.get(q) - lowest.get(p));
|
|
1490
|
+
const apart = order.length > 1 ? Math.min(3, (2 * SHEET_SIDE - 2) / (order.length - 1)) : 0;
|
|
1491
|
+
order.forEach((kind, rank) => risers.set(kind, onRight ? right - 2 - rank * apart : pageRect.x + 2 + rank * apart));
|
|
1492
|
+
}
|
|
1493
|
+
const wayIn = (one) => {
|
|
1494
|
+
const b = one.box;
|
|
1495
|
+
const from = leaveFrom(one.part, pageRect, phone);
|
|
1496
|
+
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 };
|
|
1497
|
+
const plain = { via: [straight, from], gap: null };
|
|
1498
|
+
// On a phone never straight up: the page's own words over a row (a group's label, a heading) are not parts it can go round.
|
|
1499
|
+
if (!phone && !hits(straight, from, b))
|
|
1500
|
+
return plain;
|
|
1501
|
+
// The row it stands in: every part level with it and of a row's size, never a view's whole box.
|
|
1502
|
+
const level = words.filter((o) => o !== b && o.height <= b.height * 2 + 8 && o.y < b.y + b.height - 1 && o.y + o.height > b.y + 1);
|
|
1503
|
+
const rowTop = Math.min(b.y, ...level.map((o) => o.y));
|
|
1504
|
+
const rowBottom = Math.max(b.y + b.height, ...level.map((o) => o.y + o.height));
|
|
1505
|
+
const x = b.x + Math.min(10, b.width / 2);
|
|
1506
|
+
const kind = districtOf(one.target);
|
|
1507
|
+
const ends = phone ? [(kind !== null ? risers.get(kind) : undefined) ?? pageRect.x + pageRect.width - 2] : [edgeX];
|
|
1508
|
+
for (const end of ends) {
|
|
1509
|
+
// What stands across the way along the gap: between the part and the edge it runs to.
|
|
1510
|
+
const lo = Math.min(end, b.x);
|
|
1511
|
+
const hi = Math.max(end, b.x + b.width);
|
|
1512
|
+
const beside = words.filter((o) => o !== b && o.x < hi && o.x + o.width > lo);
|
|
1513
|
+
const above = beside.filter((o) => o.y + o.height <= rowTop + 1).reduce((most, o) => Math.max(most, o.y + o.height), -Infinity);
|
|
1514
|
+
const below = beside.filter((o) => o.y >= rowBottom - 1).reduce((least, o) => Math.min(least, o.y), Infinity);
|
|
1515
|
+
// In a view, and on a phone, no further from the row than its own spacing: what lies past that (a view's words, a group's label) the page does not go round.
|
|
1516
|
+
const off = (room) => (one.framed ? Math.min(Number.isFinite(room) ? room / 2 : FRAMED_GAP, FRAMED_GAP) : phone ? Math.min(Number.isFinite(room) ? room / 2 : PHONE_GAP, PHONE_GAP) : Number.isFinite(room) ? room / 2 : 4);
|
|
1517
|
+
const gaps = [
|
|
1518
|
+
{ y: rowTop - off(rowTop - above), leave: b.y },
|
|
1519
|
+
{ y: rowBottom + off(below - rowBottom), leave: b.y + b.height },
|
|
1520
|
+
].filter((g) => g.y > one.visible.top && g.y < one.visible.bottom);
|
|
1521
|
+
// On a phone the gap above first, toward the sheet's top edge; in a view the gap below first; on a desk's page toward where it is going first — up for a building above the part, down for one below.
|
|
1522
|
+
if (one.framed || (!phone && one.end.at.y > one.part.y))
|
|
1523
|
+
gaps.reverse();
|
|
1524
|
+
const wayAlong = (gap) => {
|
|
1525
|
+
const leave = { x, y: gap.leave };
|
|
1526
|
+
const down = { x, y: gap.y };
|
|
1527
|
+
const out = { x: end, y: gap.y };
|
|
1528
|
+
return { via: phone ? [leave, down, out, { x: end, y: pageRect.y }] : [leave, down, out], gap: Math.round(gap.y) };
|
|
1529
|
+
};
|
|
1530
|
+
for (const gap of gaps) {
|
|
1531
|
+
const way = wayAlong(gap);
|
|
1532
|
+
if (!way.via.some((p, i) => i > 0 && hits(way.via[i - 1], p, b)))
|
|
1533
|
+
return way;
|
|
1534
|
+
}
|
|
1535
|
+
// A phone's line goes along its row's gap all the same: across a part there, never up across the words over it.
|
|
1536
|
+
if (phone && gaps.length > 0)
|
|
1537
|
+
return wayAlong(gaps[0]);
|
|
1538
|
+
}
|
|
1539
|
+
return plain;
|
|
1540
|
+
};
|
|
1541
|
+
const ways = asked.map(wayIn);
|
|
1542
|
+
// Lines along one gap: a pixel and a half apart, about its middle. On a phone those into one district run along it as one, into their riser.
|
|
1543
|
+
const along = new Map();
|
|
1544
|
+
ways.forEach((way, at) => {
|
|
1545
|
+
if (way.gap === null)
|
|
1546
|
+
return;
|
|
1547
|
+
const key = phone ? `${way.gap}|${districtOf(asked[at].target) ?? ""}` : String(way.gap);
|
|
1548
|
+
along.set(key, [...(along.get(key) ?? []), at]);
|
|
1549
|
+
});
|
|
1550
|
+
if (phone) {
|
|
1551
|
+
// One shift a district along a gap that several districts' lines share.
|
|
1552
|
+
const byGap = new Map();
|
|
1553
|
+
for (const key of along.keys()) {
|
|
1554
|
+
const [gap] = key.split("|");
|
|
1555
|
+
byGap.set(gap, [...(byGap.get(gap) ?? []), key]);
|
|
1556
|
+
}
|
|
1557
|
+
for (const keys of byGap.values()) {
|
|
1558
|
+
keys.forEach((key, nth) => {
|
|
1559
|
+
const shift = (nth - (keys.length - 1) / 2) * 1;
|
|
1560
|
+
for (const at of along.get(key)) {
|
|
1561
|
+
const via = ways[at].via;
|
|
1562
|
+
ways[at] = { ...ways[at], via: via.map((p, i) => (i === 0 || i === via.length - 1 ? p : { x: p.x, y: p.y + shift })) };
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
along.clear();
|
|
1567
|
+
}
|
|
1568
|
+
for (const ats of along.values()) {
|
|
1569
|
+
ats.forEach((at, nth) => {
|
|
1570
|
+
const shift = (nth - (ats.length - 1) / 2) * 1.5;
|
|
1571
|
+
const via = ways[at].via;
|
|
1572
|
+
ways[at] = { ...ways[at], via: via.map((p, i) => (i === 0 ? p : { x: p.x, y: p.y + shift })) };
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
asked.forEach((one, at) => {
|
|
1576
|
+
const via = ways[at].via;
|
|
1577
|
+
const route = routeLine(via[via.length - 1], one.end.at, area, phone, reserved);
|
|
1578
|
+
if (!route)
|
|
1579
|
+
return;
|
|
1580
|
+
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] });
|
|
1581
|
+
});
|
|
1582
|
+
/*
|
|
1583
|
+
* MANY LINES INTO ONE DISTRICT ARE ONE LINE (Graview HQ, Cloud's test
|
|
1584
|
+
* of Deep Time): each part keeps its own short line to the page's
|
|
1585
|
+
* edge, where they meet, level with the middle of them, and one line
|
|
1586
|
+
* goes on from there into the district with how many it carries.
|
|
1587
|
+
*/
|
|
1588
|
+
const into = new Map();
|
|
1589
|
+
found.forEach((line, at) => {
|
|
1590
|
+
const kind = line.target.type === "record" ? store.graph.getNode(line.target.id)?.kind : line.target.kind;
|
|
1591
|
+
if (kind)
|
|
1592
|
+
into.set(kind, [...(into.get(kind) ?? []), at]);
|
|
1593
|
+
});
|
|
1594
|
+
for (const [kind, ats] of into) {
|
|
1595
|
+
if (ats.length < GATHER)
|
|
773
1596
|
continue;
|
|
774
|
-
|
|
775
|
-
const from = leaveFrom(part, pageRect, phone);
|
|
776
|
-
const end = endOf(target);
|
|
1597
|
+
const end = endOf({ type: "list", kind });
|
|
777
1598
|
if (!end)
|
|
778
1599
|
continue;
|
|
779
|
-
|
|
780
|
-
|
|
1600
|
+
const parts = ats.map((at) => found[at].part);
|
|
1601
|
+
// On a phone they meet where their riser reaches the sheet's top edge.
|
|
1602
|
+
const riser = phone ? risers.get(kind) : undefined;
|
|
1603
|
+
const meet = riser !== undefined ? { x: riser, y: pageRect.y } : 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);
|
|
1604
|
+
const route = routeLine(meet, end.at, area, phone, reserved);
|
|
781
1605
|
if (!route)
|
|
782
1606
|
continue;
|
|
783
|
-
|
|
1607
|
+
ats.forEach((at, nth) => {
|
|
1608
|
+
const line = found[at];
|
|
1609
|
+
// Its own way to the page's edge, then along the edge to where they meet.
|
|
1610
|
+
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 } };
|
|
1611
|
+
});
|
|
784
1612
|
}
|
|
785
1613
|
}
|
|
786
1614
|
draw(found, shown);
|
|
@@ -801,6 +1629,15 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
801
1629
|
// The camera's zoom as painted in this frame, for a reader of the move (the harness holds it to going one way).
|
|
802
1630
|
holder.setAttribute("data-graview-camera-zoom", (zoomNow * painted.s).toFixed(4));
|
|
803
1631
|
};
|
|
1632
|
+
/*
|
|
1633
|
+
* A RING IS NEVER UNDER A BOARD OR A NAME, NOR AGAINST ONE: a line's end
|
|
1634
|
+
* that a board or a district's name stands over (or within a fingertip
|
|
1635
|
+
* of) offers no ring of its own — a press there landed on the board, and
|
|
1636
|
+
* one beside it was a small target crowded by a larger one. The line
|
|
1637
|
+
* still ends there; the board or the name is what is pressed.
|
|
1638
|
+
*/
|
|
1639
|
+
const pressable = [];
|
|
1640
|
+
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
1641
|
/* The overlay, written in the frame it is measured in: no React state per frame. */
|
|
805
1642
|
const draw = (found, opacity) => {
|
|
806
1643
|
const control = fab.current?.querySelector('[data-graview-one-face-dock]')?.getBoundingClientRect() ?? null;
|
|
@@ -843,28 +1680,58 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
843
1680
|
ring.type = "button";
|
|
844
1681
|
ring.setAttribute("data-testid", "one-place-ring");
|
|
845
1682
|
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", () =>
|
|
1683
|
+
const key = line.key;
|
|
1684
|
+
ring.addEventListener("click", () => lines.get(key)?.open());
|
|
848
1685
|
ringLayer.append(ring);
|
|
849
|
-
drawn = { g, path, dot, arrow, ring };
|
|
1686
|
+
drawn = { g, path, dot, arrow, ring, open: () => { } };
|
|
850
1687
|
lines.set(line.key, drawn);
|
|
851
1688
|
}
|
|
1689
|
+
const target = line.target;
|
|
1690
|
+
const gathered = line.gathered;
|
|
1691
|
+
drawn.open = gathered ? () => latest.current.openKind(gathered.kind, PANEL) : () => (target.type === "record" ? latest.current.openRecord(target.id, PANEL) : latest.current.openKind(target.kind, PANEL));
|
|
1692
|
+
// 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.
|
|
1693
|
+
const shared = !gathered || gathered.lead;
|
|
852
1694
|
const { from, to } = line;
|
|
853
1695
|
const bend = line.bend;
|
|
854
1696
|
drawn.g.setAttribute("data-graview-line", line.key);
|
|
855
1697
|
drawn.g.setAttribute("data-graview-line-on", line.on);
|
|
856
1698
|
drawn.g.toggleAttribute("data-graview-line-under", line.under !== null);
|
|
857
1699
|
drawn.g.setAttribute("data-graview-line-from", `${from.x.toFixed(2)},${from.y.toFixed(2)}`);
|
|
1700
|
+
drawn.g.setAttribute("data-graview-line-start", `${line.start.x.toFixed(2)},${line.start.y.toFixed(2)}`);
|
|
1701
|
+
if (gathered)
|
|
1702
|
+
drawn.g.setAttribute("data-graview-line-gathered", `kind:${gathered.kind}`);
|
|
1703
|
+
else
|
|
1704
|
+
drawn.g.removeAttribute("data-graview-line-gathered");
|
|
1705
|
+
if (gathered?.lead)
|
|
1706
|
+
drawn.g.setAttribute("data-graview-line-count", String(gathered.count));
|
|
1707
|
+
else
|
|
1708
|
+
drawn.g.removeAttribute("data-graview-line-count");
|
|
1709
|
+
drawn.g.setAttribute("data-graview-line-part", `${line.part.x.toFixed(2)},${line.part.y.toFixed(2)}`);
|
|
858
1710
|
drawn.g.setAttribute("data-graview-line-to", `${to.x.toFixed(2)},${to.y.toFixed(2)}`);
|
|
859
1711
|
drawn.g.setAttribute("data-graview-line-bend", `${bend.x.toFixed(2)},${bend.y.toFixed(2)}`);
|
|
860
1712
|
if (line.under)
|
|
861
1713
|
drawn.g.setAttribute("data-graview-line-toward", `${line.under.x.toFixed(2)},${line.under.y.toFixed(2)}`);
|
|
862
1714
|
else
|
|
863
1715
|
drawn.g.removeAttribute("data-graview-line-toward");
|
|
864
|
-
|
|
865
|
-
drawn.
|
|
866
|
-
drawn.dot.setAttribute("
|
|
867
|
-
|
|
1716
|
+
const leg = line.via.map((p, i) => `${i === 0 ? "M" : "L"}${p.x.toFixed(2)},${p.y.toFixed(2)}`).join(" ");
|
|
1717
|
+
drawn.path.setAttribute("d", shared ? `${leg} Q${bend.x.toFixed(2)},${bend.y.toFixed(2)} ${to.x.toFixed(2)},${to.y.toFixed(2)}` : leg);
|
|
1718
|
+
drawn.dot.setAttribute("cx", line.start.x.toFixed(2));
|
|
1719
|
+
drawn.dot.setAttribute("cy", line.start.y.toFixed(2));
|
|
1720
|
+
// The shared line's marker says how many it carries: wide enough for the number, and a fingertip's size.
|
|
1721
|
+
const size = gathered?.lead ? 22 : 16;
|
|
1722
|
+
const wide = gathered?.lead ? Math.max(22, 10 + 7 * String(gathered.count).length) : 16;
|
|
1723
|
+
drawn.ring.textContent = gathered?.lead ? String(gathered.count) : "";
|
|
1724
|
+
drawn.ring.style.width = `${wide}px`;
|
|
1725
|
+
drawn.ring.style.height = `${size}px`;
|
|
1726
|
+
drawn.ring.style.borderRadius = `${size / 2}px`;
|
|
1727
|
+
drawn.ring.style.font = gathered?.lead ? "600 11px/1 system-ui, sans-serif" : "";
|
|
1728
|
+
drawn.ring.style.color = gathered?.lead ? "var(--graview-ink)" : "";
|
|
1729
|
+
drawn.ring.style.background = gathered?.lead ? "var(--graview-panel, Canvas)" : "color-mix(in srgb, var(--graview-accent) 18%, transparent)";
|
|
1730
|
+
if (!shared) {
|
|
1731
|
+
drawn.arrow.setAttribute("d", "");
|
|
1732
|
+
drawn.ring.style.display = "none";
|
|
1733
|
+
}
|
|
1734
|
+
else if (line.under) {
|
|
868
1735
|
// An arrow at the page's edge, pointing on toward the building under the page.
|
|
869
1736
|
const angle = Math.atan2(line.under.y - to.y, line.under.x - to.x);
|
|
870
1737
|
const tip = { x: to.x + Math.cos(angle) * 7, y: to.y + Math.sin(angle) * 7 };
|
|
@@ -872,32 +1739,65 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
872
1739
|
const right = { x: to.x + Math.cos(angle - 2.4) * 6, y: to.y + Math.sin(angle - 2.4) * 6 };
|
|
873
1740
|
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
1741
|
// 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);
|
|
1742
|
+
const crowded = ringsAt.some((p) => Math.hypot(p.x - to.x, p.y - to.y) < 28) || besidePressable(to);
|
|
876
1743
|
drawn.ring.style.display = crowded ? "none" : "";
|
|
877
1744
|
if (!crowded)
|
|
878
1745
|
ringsAt.push(to);
|
|
879
|
-
drawn.ring.style.left = `${(to.x -
|
|
880
|
-
drawn.ring.style.top = `${(to.y -
|
|
1746
|
+
drawn.ring.style.left = `${(to.x - wide / 2).toFixed(2)}px`;
|
|
1747
|
+
drawn.ring.style.top = `${(to.y - size / 2).toFixed(2)}px`;
|
|
881
1748
|
}
|
|
882
1749
|
else {
|
|
883
1750
|
drawn.arrow.setAttribute("d", "");
|
|
1751
|
+
/*
|
|
1752
|
+
* A SHARED LINE'S COUNT IS ALWAYS SAID: where its district's middle
|
|
1753
|
+
* has a board or a name beside it (which takes the press there), the
|
|
1754
|
+
* count stands back along the line, at the nearest place clear of them.
|
|
1755
|
+
*/
|
|
1756
|
+
let at = to;
|
|
1757
|
+
if (gathered?.lead && besidePressable(to)) {
|
|
1758
|
+
for (let t = 0.95; t >= 0.4; t -= 0.05) {
|
|
1759
|
+
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 };
|
|
1760
|
+
if (!besidePressable(p)) {
|
|
1761
|
+
at = p;
|
|
1762
|
+
break;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
884
1766
|
// 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 =
|
|
1767
|
+
const under = control && at.x > control.left - 10 && at.x < control.right + 10 && at.y > control.top - 10 && at.y < control.bottom + 10;
|
|
1768
|
+
const crowded = ringsAt.some((p) => Math.hypot(p.x - at.x, p.y - at.y) < 28) || besidePressable(at);
|
|
1769
|
+
drawn.ring.style.display = at.y < (state.current.view.top ?? 0) + 8 || under || crowded ? "none" : "";
|
|
888
1770
|
if (!crowded)
|
|
889
|
-
ringsAt.push(
|
|
890
|
-
drawn.ring.style.left = `${(
|
|
891
|
-
drawn.ring.style.top = `${(
|
|
1771
|
+
ringsAt.push(at);
|
|
1772
|
+
drawn.ring.style.left = `${(at.x - wide / 2).toFixed(2)}px`;
|
|
1773
|
+
drawn.ring.style.top = `${(at.y - size / 2).toFixed(2)}px`;
|
|
1774
|
+
}
|
|
1775
|
+
if (gathered) {
|
|
1776
|
+
const plural = pluralOf(store, gathered.kind);
|
|
1777
|
+
drawn.ring.setAttribute("data-graview-to", `kind:${gathered.kind}`);
|
|
1778
|
+
drawn.ring.setAttribute("aria-label", `${gathered.count} ${plural.toLowerCase()} here: open the ${plural} list`);
|
|
1779
|
+
drawn.ring.title = `${gathered.count} ${plural.toLowerCase()}`;
|
|
1780
|
+
}
|
|
1781
|
+
else {
|
|
1782
|
+
drawn.ring.setAttribute("data-graview-to", line.target.type === "record" ? line.target.id : `kind:${line.target.kind}`);
|
|
1783
|
+
drawn.ring.setAttribute("aria-label", line.target.type === "record" ? `Open ${line.label}` : `Open the ${line.label} list`);
|
|
1784
|
+
drawn.ring.title = line.label;
|
|
892
1785
|
}
|
|
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
1786
|
}
|
|
897
1787
|
};
|
|
898
1788
|
frame = requestAnimationFrame(tick);
|
|
1789
|
+
const said = sheet.current;
|
|
1790
|
+
said?.addEventListener(RECORD_BOXES_MOVED, askReframe);
|
|
1791
|
+
// The person's own hand on the city: a press, a drag, a wheel, a pinch.
|
|
1792
|
+
const city = box.current;
|
|
1793
|
+
const hands = ["pointerdown", "wheel", "touchstart"];
|
|
1794
|
+
for (const type of hands)
|
|
1795
|
+
city?.addEventListener(type, byHand, { capture: true, passive: true });
|
|
899
1796
|
return () => {
|
|
900
1797
|
cancelAnimationFrame(frame);
|
|
1798
|
+
said?.removeEventListener(RECORD_BOXES_MOVED, askReframe);
|
|
1799
|
+
for (const type of hands)
|
|
1800
|
+
city?.removeEventListener(type, byHand, { capture: true });
|
|
901
1801
|
for (const drawn of lines.values()) {
|
|
902
1802
|
drawn.g.remove();
|
|
903
1803
|
drawn.ring.remove();
|
|
@@ -905,6 +1805,140 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
905
1805
|
};
|
|
906
1806
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
907
1807
|
}, []);
|
|
1808
|
+
/*
|
|
1809
|
+
* A HAND ON A SIGN MOVES THE CITY. The boards, the districts' names and
|
|
1810
|
+
* their chips, and the rings at the lines' ends stand over the city in a
|
|
1811
|
+
* layer of their own, so a drag, a wheel or a pinch that began on one of
|
|
1812
|
+
* them reached nothing: the city stalled under the pointer. Begun there, a
|
|
1813
|
+
* drag past a few pixels pans the city's own camera by as far as the hand
|
|
1814
|
+
* goes (and the press that began it opens nothing), two fingers zoom it
|
|
1815
|
+
* about their middle, and the wheel pans or, with ctrl, zooms it — as over
|
|
1816
|
+
* open ground. A press that does not move still opens what it is on.
|
|
1817
|
+
*/
|
|
1818
|
+
useEffect(() => {
|
|
1819
|
+
const layers = [boardLayer.current, tagLayer.current, rings.current].filter((el) => el !== null);
|
|
1820
|
+
const DRAG = 6;
|
|
1821
|
+
const down = new Map();
|
|
1822
|
+
let dragging = false;
|
|
1823
|
+
let pinchFrom = null;
|
|
1824
|
+
let swallow = false;
|
|
1825
|
+
const spread = () => {
|
|
1826
|
+
const [a, b] = [...down.values()];
|
|
1827
|
+
return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
|
|
1828
|
+
};
|
|
1829
|
+
const onDown = (event) => {
|
|
1830
|
+
if (event.pointerType === "mouse" && event.button !== 0)
|
|
1831
|
+
return;
|
|
1832
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1833
|
+
dragging = false;
|
|
1834
|
+
pinchFrom = down.size === 2 ? spread() : null;
|
|
1835
|
+
};
|
|
1836
|
+
const onMove = (event) => {
|
|
1837
|
+
const was = down.get(event.pointerId);
|
|
1838
|
+
const cam = camera.current;
|
|
1839
|
+
if (!was || !cam)
|
|
1840
|
+
return;
|
|
1841
|
+
const dx = event.clientX - was.x;
|
|
1842
|
+
const dy = event.clientY - was.y;
|
|
1843
|
+
if (down.size >= 2) {
|
|
1844
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1845
|
+
const now = spread();
|
|
1846
|
+
if (pinchFrom && now > 0) {
|
|
1847
|
+
const [a, b] = [...down.values()];
|
|
1848
|
+
cam.zoomTo(cam.zoom() * (now / pinchFrom), (a.x + b.x) / 2, (a.y + b.y) / 2);
|
|
1849
|
+
pinchFrom = now;
|
|
1850
|
+
dragging = true;
|
|
1851
|
+
}
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
if (!dragging && Math.hypot(dx, dy) < DRAG)
|
|
1855
|
+
return;
|
|
1856
|
+
if (!dragging) {
|
|
1857
|
+
dragging = true;
|
|
1858
|
+
try {
|
|
1859
|
+
event.target?.setPointerCapture?.(event.pointerId);
|
|
1860
|
+
}
|
|
1861
|
+
catch {
|
|
1862
|
+
// A pointer the page did not see go down keeps no capture; the moves still come here.
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
cam.panBy(dx, dy);
|
|
1866
|
+
down.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1867
|
+
};
|
|
1868
|
+
const onUp = (event) => {
|
|
1869
|
+
if (!down.has(event.pointerId))
|
|
1870
|
+
return;
|
|
1871
|
+
down.delete(event.pointerId);
|
|
1872
|
+
if (dragging)
|
|
1873
|
+
swallow = true;
|
|
1874
|
+
if (down.size === 0) {
|
|
1875
|
+
dragging = false;
|
|
1876
|
+
pinchFrom = null;
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
// The press that ended a drag opens nothing.
|
|
1880
|
+
const onClick = (event) => {
|
|
1881
|
+
if (!swallow)
|
|
1882
|
+
return;
|
|
1883
|
+
swallow = false;
|
|
1884
|
+
event.preventDefault();
|
|
1885
|
+
event.stopPropagation();
|
|
1886
|
+
};
|
|
1887
|
+
const onWheel = (event) => {
|
|
1888
|
+
const cam = camera.current;
|
|
1889
|
+
if (!cam)
|
|
1890
|
+
return;
|
|
1891
|
+
event.preventDefault();
|
|
1892
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
|
|
1893
|
+
if (event.ctrlKey || event.metaKey)
|
|
1894
|
+
cam.zoomTo(cam.zoom() * Math.exp(-event.deltaY * unit * 0.01), event.clientX, event.clientY);
|
|
1895
|
+
else
|
|
1896
|
+
cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
|
|
1897
|
+
};
|
|
1898
|
+
/*
|
|
1899
|
+
* A SCROLL OVER A DISTRICT PANS TOO. The Scene leaves a lens's wheel to
|
|
1900
|
+
* the lens, and a district's plot is a view of its own there, so a
|
|
1901
|
+
* two-finger scroll that happened to start over a district moved
|
|
1902
|
+
* nothing. On this face a district scrolls nothing of its own: the
|
|
1903
|
+
* scroll pans the city, as over open ground. A part that does scroll (a
|
|
1904
|
+
* scroll region, a pane, a worker view drawn there, whose own scroll this
|
|
1905
|
+
* face cannot see into) keeps its own wheel.
|
|
1906
|
+
*/
|
|
1907
|
+
const holder = box.current;
|
|
1908
|
+
const onPlotWheel = (event) => {
|
|
1909
|
+
const target = event.target;
|
|
1910
|
+
if (event.ctrlKey || event.metaKey || !target?.closest("[data-graview-plot]") || target.closest(".graview-scroll, [data-graview-overlay], .graview-zoom, [data-worker-view]"))
|
|
1911
|
+
return;
|
|
1912
|
+
const cam = camera.current;
|
|
1913
|
+
if (!cam)
|
|
1914
|
+
return;
|
|
1915
|
+
event.preventDefault();
|
|
1916
|
+
event.stopPropagation();
|
|
1917
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
|
|
1918
|
+
cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
|
|
1919
|
+
};
|
|
1920
|
+
holder?.addEventListener("wheel", onPlotWheel, { passive: false, capture: true });
|
|
1921
|
+
for (const layer of layers) {
|
|
1922
|
+
layer.addEventListener("pointerdown", onDown, true);
|
|
1923
|
+
layer.addEventListener("pointermove", onMove, true);
|
|
1924
|
+
layer.addEventListener("pointerup", onUp, true);
|
|
1925
|
+
layer.addEventListener("pointercancel", onUp, true);
|
|
1926
|
+
layer.addEventListener("click", onClick, true);
|
|
1927
|
+
layer.addEventListener("wheel", onWheel, { passive: false });
|
|
1928
|
+
}
|
|
1929
|
+
return () => {
|
|
1930
|
+
holder?.removeEventListener("wheel", onPlotWheel, { capture: true });
|
|
1931
|
+
for (const layer of layers) {
|
|
1932
|
+
layer.removeEventListener("pointerdown", onDown, true);
|
|
1933
|
+
layer.removeEventListener("pointermove", onMove, true);
|
|
1934
|
+
layer.removeEventListener("pointerup", onUp, true);
|
|
1935
|
+
layer.removeEventListener("pointercancel", onUp, true);
|
|
1936
|
+
layer.removeEventListener("click", onClick, true);
|
|
1937
|
+
layer.removeEventListener("wheel", onWheel);
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1941
|
+
}, []);
|
|
908
1942
|
/*
|
|
909
1943
|
* A building pressed, above the page: its record, in the panel, the camera
|
|
910
1944
|
* flying to it. The Scene's blocks take no press of their own (their tile
|
|
@@ -947,7 +1981,12 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
|
|
|
947
1981
|
* in the page — and what of it reaches past the window is inside a
|
|
948
1982
|
* box that scrolls, as a phone's sideways row would be.
|
|
949
1983
|
*/
|
|
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 } })
|
|
1984
|
+
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) => {
|
|
1985
|
+
if (el)
|
|
1986
|
+
tagEls.current.set(one.kind, el);
|
|
1987
|
+
else
|
|
1988
|
+
tagEls.current.delete(one.kind);
|
|
1989
|
+
}, "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
1990
|
}
|
|
952
1991
|
/** 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
1992
|
export function signKindOf(where) {
|