@graview/pages 0.2.3 → 0.2.5

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.
@@ -7,7 +7,7 @@ import { sceneCss } from "@graview/primitives/scene";
7
7
  import { useGraview, useNavigation, useViolations } from "@graview/react/provider";
8
8
  import { useOneFace } from "./one-place-control.js";
9
9
  import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
10
- 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 { aimAt, anchorOf, BOARD_ASPECT, carriedBetween, carriedThrough, frameSpacingAt, boardFaceWidth, framedTogether, homeReadableZoom, 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, wordOnScreen } from "./one-place-geometry.js";
11
11
  import { placeSigns } from "./one-place-signs.js";
12
12
  import { pluralOf } from "./page-typography.js";
13
13
  /*
@@ -236,6 +236,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
236
236
  const districtNames = store.schema.kinds.map((kind) => ({ kind, plural: pluralOf(store, kind), count: store.graph.count(kind), problems: problemsOf.get(kind) ?? 0 }));
237
237
  const tagEls = useRef(new Map());
238
238
  const tagLayer = useRef(null);
239
+ /** A hand panned the city through this face's own layers (a drag begun on a board, a scroll over a district) since the city was last read. */
240
+ const nudged = useRef(false);
239
241
  const state = useRef({ where, out, view, lessMotion, resolve, onAltitude, boards, current });
240
242
  /*
241
243
  * WHAT THE FRAME READS IS WHAT IS DRAWN. Written as the render ran, a
@@ -395,6 +397,16 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
395
397
  let lastPanel = "";
396
398
  /** When the city was last read, and what it was read for. */
397
399
  let lastRead = -Infinity;
400
+ /*
401
+ * When the city was last read moved by a hand: a scroll's or a drag's
402
+ * last step can reach the picture a frame after the read that took the
403
+ * hand's word for it (the face's layers pan the camera, the Scene
404
+ * paints it next frame). Read within the let-go time of one, the move
405
+ * is still the hand's. (Not `handAt` below, which says when a hand last
406
+ * moved the city at all — a settle, a pinch — and holds back placing a
407
+ * zoom it wrote.)
408
+ */
409
+ let handReadAt = -Infinity;
398
410
  let lastReadKey = "";
399
411
  let resized = false;
400
412
  let handSince = 0;
@@ -415,6 +427,11 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
415
427
  let calmRun = 0;
416
428
  /** The page a board was last placed for at once: one with no place to stand is not placed again every frame. */
417
429
  let placedFor = "";
430
+ /** A zoom the hand wrote, carried and not yet placed for; and when a hand last moved the city. */
431
+ let regrow = false;
432
+ /** What a pan holds was stopped half-way through a settle: two held on each other are placed afresh. */
433
+ let heldHalfWay = false;
434
+ let handAt = -Infinity;
418
435
  let placeSeenAt = 0;
419
436
  let placeSeen = "";
420
437
  const drawnSince = (placeKey, now) => {
@@ -434,6 +451,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
434
451
  let settle = null;
435
452
  /** 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. */
436
453
  let rebaseNext = null;
454
+ /** The camera the last frame drew the city through, between stops, until the view has taken it (or the face rebased onto it). */
455
+ let drawnThrough = null;
437
456
  const SETTLE_MS = 300;
438
457
  /*
439
458
  * A name's box is carried whole: its size too, which differs between
@@ -454,9 +473,20 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
454
473
  return at;
455
474
  };
456
475
  /** How far a move or a settle has gone, this frame: 1 when nothing is under way. */
457
- 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 };
476
+ const goneAt = (now) => move ? { t: ease(clamp01((now - move.start) / MOVE_MS)), slots: move.slots, names: move.names, scales: move.scales } : settle && now - settle.start < SETTLE_MS ? { t: ease((now - settle.start) / SETTLE_MS), slots: settle.slots, names: settle.names, scales: settle.scales } : { t: 1, slots: null, names: null, scales: null };
458
477
  /** Every board and name where it is drawn this frame. */
459
478
  const drawnSlots = (now) => { const g = goneAt(now); return new Map([...slots].map(([key, at]) => [key, blend(g.slots?.get(key), at, g.t) ?? at])); };
479
+ /*
480
+ * And each board's size as drawn: a board placed again a little smaller
481
+ * (or back to its full size) goes there over the same moment as its foot,
482
+ * never one frame from one size to the other.
483
+ */
484
+ const scaleFrom = (g, key) => {
485
+ const to = scales.get(key) ?? 1;
486
+ const from = g.scales?.get(key);
487
+ return from === undefined || !slots.has(key) || !g.slots?.has(key) ? to : from + (to - from) * g.t;
488
+ };
489
+ const drawnScales = (now) => { const g = goneAt(now); return new Map([...slots.keys()].map((key) => [key, scaleFrom(g, key)])); };
460
490
  const drawnNames = (now) => { const g = goneAt(now); return new Map([...names].map(([key, at]) => [key, blend(g.names?.get(key), at, g.t) ?? at])); };
461
491
  const QUIET_MS = 220;
462
492
  const lines = new Map();
@@ -517,9 +547,43 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
517
547
  /** The city and every view standing in it, as last read: what the city's camera fits. */
518
548
  let whole = null;
519
549
  let kept = null;
550
+ /** Whether a board or a name placed round what was held stands on one of them. */
551
+ const standsOnHeld = (placed, holds, width) => {
552
+ const across = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > 1 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > 1;
553
+ const cardOf = (key, foot) => {
554
+ const w = width * (placed.scales.get(key) ?? 1);
555
+ const h = w / BOARD_ASPECT;
556
+ return { x: foot.x - w / 2, y: foot.y - h, width: w, height: h };
557
+ };
558
+ const all = [...[...placed.feet].map(([key, foot]) => ({ key, box: cardOf(key, foot) })), ...[...placed.names].map(([kind, box]) => ({ key: `name:${kind}`, box }))];
559
+ const standing = all.filter((one) => holds.has(one.key));
560
+ // And held where a settle stopped half-way, one held on another: never kept so.
561
+ if (heldHalfWay && standing.some((one, at) => standing.some((other, then) => then > at && across(one.box, other.box))))
562
+ return true;
563
+ return all.some((one) => !holds.has(one.key) && standing.some((other) => across(one.box, other.box)));
564
+ };
565
+ /** What nothing of the city's is drawn under at rest: the bar, the page beside the city, the level control. */
566
+ const keptOutNow = () => {
567
+ const view = state.current.view;
568
+ const plane = sheet.current;
569
+ const dockRect = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
570
+ return [
571
+ { x: 0, y: 0, width: view.width, height: view.top ?? 0 },
572
+ ...(plane && altitude > 0.5 && altitude < 1.5 ? [boxOf(plane.getBoundingClientRect())] : []),
573
+ ...(dockRect && dockRect.width > 0 ? [boxOf(dockRect)] : []),
574
+ ];
575
+ };
520
576
  /** A window too small for a board beside every district: a phone, or one turned on its side. */
521
577
  const cramped = () => state.current.view.width <= PHONE || state.current.view.height <= 600;
522
- const standAll = (w, zoomNow, cam, bounds, lvl) => {
578
+ /**
579
+ * `held`: every board's foot and name's box where the last frame drew
580
+ * them, carried into the picture as it is laid out now — a pan let go
581
+ * of. Where the pan changed nothing but what is in sight, they stay
582
+ * there, and only what had no place is placed round them.
583
+ */
584
+ const standAll = (w, zoomNow, cam, bounds, lvl, held) => {
585
+ /** What was held where it stood: boards by key, names by kind. */
586
+ const holds = new Set();
523
587
  const view = state.current.view;
524
588
  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 });
525
589
  const tiles = new Map([...w.plots].map(([kind, box]) => [kind, onScreen(box)]));
@@ -545,10 +609,56 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
545
609
  const reserved = footNow().now.map((box) => ({ x: box.x - 6, y: box.y - 6, width: box.width + 12, height: box.height + 12 }));
546
610
  const round = (n) => Math.round(n / 2) * 2;
547
611
  const rel = (box) => [round(box.x - origin.x), round(box.y - origin.y), round(box.width), round(box.height)];
548
- const buildingsOnScreen = [...w.buildings.values()].map(onScreen);
549
- const restsOnScreen = [...w.buildings].filter(([key]) => key.startsWith(REST_KEY)).map(([, box]) => onScreen(box));
612
+ // A district's "+n" keeps its size on the screen as the picture zooms (`wordOnScreen`); a building grows with it.
613
+ const buildingsOnScreen = [...w.buildings].map(([key, box]) => (key.startsWith(REST_KEY) ? wordOnScreen(cam, box) : onScreen(box)));
614
+ const restsOnScreen = [...w.buildings].filter(([key]) => key.startsWith(REST_KEY)).map(([, box]) => wordOnScreen(cam, box));
550
615
  // What decides the placing, the city's own lattice taken from where it stands: a pan of fewer than 24 pixels places nothing again.
616
+ /*
617
+ * What a pan leaves as it was — the level, the window, the boards'
618
+ * size, the districts, the names and the views — beside where the city
619
+ * stands against what the window shows and keeps clear, which it moves.
620
+ */
621
+ const body = JSON.stringify([lvl, view.width, view.height, round(width), [...tiles.keys()], buildingsOnScreen.length, [...sizes].map(([kind, size]) => [kind, size.width, size.height]), signs.map((one) => [one.key, one.kind, one.building !== null])]);
551
622
  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)))]);
623
+ /*
624
+ * A PAN LET GO OF PLACES NOTHING AGAIN (Graview HQ
625
+ * feature:f-one-face-pan-stops-still): the same city, the same window
626
+ * and the same views, only panned against what the window shows. What
627
+ * is seen stays where the last frame drew it; one the pan took out of
628
+ * the window or under the bar, the page or the control is placed
629
+ * again, as is a board or a name with no place yet.
630
+ */
631
+ const holding = held && kept && kept.key !== key && kept.body === body;
632
+ /*
633
+ * Only what is seen is held: one the pan took out of the window, or
634
+ * under the bar, the page or the control, is not drawn, and is placed
635
+ * again — coming up where it lands — as it was before a pan held
636
+ * anything.
637
+ */
638
+ const out = keptOutNow();
639
+ const win = { x: 0, y: 0, width: view.width, height: view.height };
640
+ const across = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > 1 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > 1;
641
+ const seenAt = (box) => across(box, win) && !out.some((k) => across(box, k));
642
+ const heldFeet = new Map();
643
+ const heldNames = new Map();
644
+ if (holding) {
645
+ for (const [one, p] of held.slots) {
646
+ const foot = project(cam, p);
647
+ const scale = held.scales.get(one) ?? 1;
648
+ const cardWidth = width * scale;
649
+ if (one === state.current.current || seenAt({ x: foot.x - cardWidth / 2, y: foot.y - (cardWidth / BOARD_ASPECT), width: cardWidth, height: cardWidth / BOARD_ASPECT }))
650
+ heldFeet.set(one, foot);
651
+ }
652
+ for (const [kind, b] of held.names) {
653
+ const box = { ...project(cam, b), width: b.width * cam.s, height: b.height * cam.s };
654
+ if (seenAt(box))
655
+ heldNames.set(kind, box);
656
+ }
657
+ for (const one of heldFeet.keys())
658
+ holds.add(one);
659
+ for (const kind of heldNames.keys())
660
+ holds.add(`name:${kind}`);
661
+ }
552
662
  let placed;
553
663
  let shift = { x: 0, y: 0 };
554
664
  if (kept && kept.key === key) {
@@ -556,7 +666,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
556
666
  shift = { x: origin.x - kept.origin.x, y: origin.y - kept.origin.y };
557
667
  }
558
668
  else {
559
- placed = placeSigns({
669
+ const asked = {
560
670
  tiles,
561
671
  buildings: buildingsOnScreen,
562
672
  names: sizes,
@@ -578,8 +688,23 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
578
688
  plaza: lvl !== PANEL,
579
689
  // 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.
580
690
  ...(lvl !== CITY ? { namesFirst: true, nameReach: NAME_REACH } : {}),
581
- });
582
- kept = { key, origin, placed };
691
+ };
692
+ placed = holding ? placeSigns({ ...asked, held: { feet: heldFeet, posts: new Map([...posts].map(([one, length]) => [one, length * cam.s])), scales: held.scales, names: heldNames } }) : placeSigns(asked);
693
+ /*
694
+ * HELD, NOTHING PLACED ON IT. Placed round what stands, one that came
695
+ * into sight may find no clear room and take the place that covers
696
+ * least — on a board or a name that stands. Neither one control over
697
+ * another nor a view with no board (kept so, it stood nowhere until
698
+ * the window or the level changed): the city is placed afresh, as it
699
+ * was before a pan held anything, and everything goes there from
700
+ * where the last frame drew it. The page says so, for a reader of it.
701
+ */
702
+ if (holding && standsOnHeld(placed, holds, width)) {
703
+ placed = placeSigns(asked);
704
+ holds.clear();
705
+ box.current?.setAttribute("data-graview-placed-afresh-after-a-pan", String(Number(box.current.getAttribute("data-graview-placed-afresh-after-a-pan") ?? 0) + 1));
706
+ }
707
+ kept = { key, body, origin, placed };
583
708
  }
584
709
  // Back into the picture's own pixels, as the view lays it out now.
585
710
  const back = (p) => ({ x: (p.x + shift.x - cam.x) / cam.s, y: (p.y + shift.y - cam.y) / cam.s });
@@ -598,6 +723,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
598
723
  scales = new Map(placed.scales);
599
724
  names = new Map([...placed.names].map(([kind, box]) => [kind, backBox(box)]));
600
725
  whole = placed.whole ? backBox(placed.whole) : null;
726
+ return holds;
601
727
  };
602
728
  /*
603
729
  * WHAT STANDS AT THE FOOT: the control, the legend over it when it is
@@ -708,33 +834,45 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
708
834
  * THE HOME BESIDE THE CITY: the city framed in the part the page leaves
709
835
  * it — left of the panel on a desk, over the sheet on a phone — never
710
836
  * the whole window, where the districts nearest the page stood behind it.
837
+ *
838
+ * AND READ AT A SIZE (Graview HQ feature:f-one-face-home-nearby-reads-at-size):
839
+ * never further out than `homeReadableZoom`. Where the whole city
840
+ * stands beside the page at that zoom or closer, it is framed whole;
841
+ * where it does not, the districts the home's views show are framed,
842
+ * and the rest of the city is a pan away. Fitted whole at any zoom the
843
+ * camera reaches, a rich app's plots were drawn at three fifths of a
844
+ * record page's, and its boards could not be read.
711
845
  */
712
846
  if (lvl === PANEL && (now.where.type === "home" || now.where.type === "overview")) {
713
847
  const city = unionOf([...world.plots.values()]);
714
848
  if (city) {
715
849
  const shown = nearbyShown();
716
850
  const fit = fitCamera(city, shown, 16, s);
717
- // 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.
718
- const least = (camera.current?.range.min ?? 0) / zoomNow;
851
+ const least = Math.max(homeReadableZoom(now.view), camera.current?.range.min ?? 0) / zoomNow;
719
852
  // Said on the city, for a reader of the page: whether the whole city stands beside the page here.
720
853
  box.current?.toggleAttribute("data-graview-nearby-holds-the-city", fit.s >= least);
721
854
  if (fit.s >= least)
722
855
  return fit;
723
- const kinds = new Set(markedOnPage().flatMap((id) => {
724
- const kind = store.graph.getNode(id)?.kind;
725
- return kind ? [kind] : [];
726
- }));
727
- const own = unionOf([...kinds].flatMap((kind) => {
856
+ // The districts the home's views show, in the order the page shows them.
857
+ const kinds = [...new Set(markedOnPage().flatMap((id) => {
858
+ const kind = store.graph.getNode(id)?.kind;
859
+ return kind ? [kind] : [];
860
+ }))];
861
+ const plots = kinds.flatMap((kind) => {
728
862
  const plot = world.plots.get(kind);
729
863
  return plot ? [plot] : [];
730
- }));
731
- const what = own ?? city;
864
+ });
865
+ // As many of them as stand beside the page together at the least zoom: the first the page shows first.
866
+ const what = framedTogether(plots, shown, least);
867
+ // A page that shows no records: the city's middle in the middle of its side, the rest a pan away.
868
+ if (!what)
869
+ return cameraPutting(middle(city), middle(shown), least);
732
870
  /*
733
871
  * THE CITY AS NEAR THE MIDDLE OF ITS SIDE AS ITS VIEWS' DISTRICTS
734
872
  * LET IT, they in the side whole: at the zoom that fits them where
735
- * they fit on their own (a small phone's strip over the sheet), else
736
- * as far out as the camera goes. Fitted on them alone, the city stood
737
- * off to one side of a narrow strip with room to come to its middle.
873
+ * they fit closer (never closer than the home's Nearby), else at the
874
+ * least. Fitted on them alone, the city stood off to one side of a
875
+ * narrow strip with room to come to its middle.
738
876
  */
739
877
  const close = fitCamera(what, shown, 16, s);
740
878
  const held = cameraPutting(middle(city), middle(shown), Math.max(close.s, least));
@@ -776,9 +914,12 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
776
914
  names = new Map([...names].map(([key, b]) => [key, box(b)]));
777
915
  whole = whole ? box(whole) : null;
778
916
  settle = null;
779
- world = { plots: new Map([...world.plots].map(([key, b]) => [key, box(b)])), buildings: new Map([...world.buildings].map(([key, b]) => [key, box(b)])) };
917
+ drawnThrough = null;
918
+ handReadAt = -Infinity;
919
+ world = { plots: new Map([...world.plots].map(([key, b]) => [key, box(b)])), buildings: new Map([...world.buildings].map(([key, b]) => [key, key.startsWith(REST_KEY) ? wordOnScreen(to, b) : box(b)])) };
780
920
  };
781
921
  const moveTo = (cam, toLevel, anchor, now, arm = true) => {
922
+ regrow = false;
782
923
  reframeArmed = arm && toLevel === PANEL && state.current.where.type === "record";
783
924
  const from = painted;
784
925
  /*
@@ -791,6 +932,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
791
932
  // 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.
792
933
  const namesFrom = drawnNames(now);
793
934
  const slotsFrom = drawnSlots(now);
935
+ const scalesFrom = drawnScales(now);
794
936
  const own = state.current.current;
795
937
  if (rest !== PAGE && !move && !slots.has(own) && level(painted)) {
796
938
  standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
@@ -824,6 +966,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
824
966
  foot: footNow().key,
825
967
  names: namesFrom,
826
968
  slots: slotsFrom,
969
+ scales: scalesFrom,
827
970
  done: () => {
828
971
  rest = toLevel;
829
972
  altitude = toLevel;
@@ -897,8 +1040,27 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
897
1040
  const settling = cam.moving() && !between;
898
1041
  // Written too recently for a new move to be painted safely: the Scene settles what is painted a beat after a commit.
899
1042
  const calm = now - committedAt >= QUIET_MS;
900
- if (between)
1043
+ if (between) {
1044
+ /*
1045
+ * A HAND ON THE CITY MID-SETTLE: what was going over to a new place
1046
+ * stops where it is drawn, fastened to the ground the hand moves —
1047
+ * a settle carried on under a pan slid every board and name across
1048
+ * the ground while the hand had it (Graview HQ
1049
+ * feature:f-one-face-pinch-and-pan-together-holds). The pan let go
1050
+ * of holds them there, as any pan does — unless, stopped half-way
1051
+ * between two placings, two stand on each other: then the city is
1052
+ * placed afresh, each going on from where it is drawn.
1053
+ */
1054
+ if (!move && !asking.scrubbing && settle && now - settle.start < SETTLE_MS) {
1055
+ slots = drawnSlots(now);
1056
+ names = drawnNames(now);
1057
+ scales = drawnScales(now);
1058
+ settle = null;
1059
+ heldHalfWay = true;
1060
+ }
901
1061
  painted = live;
1062
+ drawnThrough = live;
1063
+ }
902
1064
  else if (!settling) {
903
1065
  painted = LEVEL_LIVE;
904
1066
  /*
@@ -918,14 +1080,80 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
918
1080
  * only for where the move ends.
919
1081
  */
920
1082
  if (world.plots.size === 0 || (!move && (readKey !== lastReadKey || committedAt > lastRead || now - lastRead > 500))) {
1083
+ const before = world;
921
1084
  world = readWorld(holder);
922
1085
  if (move)
923
1086
  placeFor(move.toAltitude, move.to, cam.zoom());
924
1087
  else {
925
- const drawnBefore = { slots: drawnSlots(now), names: drawnNames(now) };
1088
+ /*
1089
+ * LETTING GO OF A PAN, NOTHING MOVES (Graview HQ
1090
+ * feature:f-one-face-pan-stops-still). What was drawn was placed
1091
+ * in the picture's pixels as last read; a pan or a zoom written
1092
+ * into the view since (the hand's, let go of; a drag begun on a
1093
+ * board, a scroll) has laid the city out again elsewhere, and
1094
+ * the old numbers drawn now stood where the pan began — every
1095
+ * board and name snapped back and slid over. Carried by what
1096
+ * the districts say moved, they stand where the last frame drew
1097
+ * them, and settle from there.
1098
+ */
1099
+ // Where the districts disagree (one grew under a record added as the hand panned), the camera the last frame drew through says it.
1100
+ const carry = carriedBetween(before.plots, world.plots) ?? drawnThrough;
1101
+ const drawnBefore = carry ? { slots: carriedThrough(carry, drawnSlots(now)), names: carriedThrough(carry, drawnNames(now)), scales: drawnScales(now) } : { slots: drawnSlots(now), names: drawnNames(now), scales: drawnScales(now) };
926
1102
  // At the City everything stands inside what the camera shows; the camera was fitted to it.
927
- standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
928
- settle = { ...drawnBefore, start: now };
1103
+ // A pan, not a zoom: a name is a size on the screen, and at another zoom it is placed again for it.
1104
+ /*
1105
+ * A HAND'S PAN, not the city moved another way: the Scene's hand
1106
+ * painted between stops (`drawnThrough`), or this face's layers
1107
+ * panned the view. After a level move the face rebased onto its
1108
+ * own camera, and the city settling a pixel or two from it after
1109
+ * is placed fresh for the level, as it always was.
1110
+ */
1111
+ const byHand = drawnThrough !== null || nudged.current || now - handReadAt < LET_GO_MS;
1112
+ if (drawnThrough !== null || nudged.current)
1113
+ handReadAt = now;
1114
+ nudged.current = false;
1115
+ // A hand that writes each move into the view (a drag begun on a sign) is a hand on the city too.
1116
+ if (byHand)
1117
+ handAt = now;
1118
+ const panned = byHand && carry !== null && carry !== LEVEL_LIVE && Math.abs(carry.s - 1) < 1e-3;
1119
+ /*
1120
+ * What is held is where each stands, not where a settle caught part
1121
+ * way had it: two boards half-way between two placings may stand on
1122
+ * each other, and held there they would stay so. A settle a hand
1123
+ * came on in the middle of stopped where it was drawn: held there,
1124
+ * unless two stand on each other (`heldHalfWay`).
1125
+ */
1126
+ /*
1127
+ * A HAND'S ZOOM WRITTEN WHILE THE HAND IS STILL ON (Graview HQ
1128
+ * feature:f-one-face-pinch-and-pan-together-holds): a pinch a
1129
+ * beat still, a wheel's zoom with a pan straight after, two
1130
+ * fingers let go of and one put down again. Placed again for the
1131
+ * new zoom there and then, the boards and names went off over a
1132
+ * settle while the hand moved the ground on under them. Carried
1133
+ * by the zoom instead — where the last frame drew them, fastened
1134
+ * to the ground — and placed again for the zoom only once the
1135
+ * hand has been off the city a moment (`regrow`); a zoom written
1136
+ * before that is carried the same.
1137
+ */
1138
+ if (byHand && carry !== null && carry !== LEVEL_LIVE && (!panned || regrow)) {
1139
+ slots = new Map(drawnBefore.slots);
1140
+ names = new Map(drawnBefore.names);
1141
+ scales = new Map(drawnBefore.scales);
1142
+ posts = new Map([...posts].map(([one, length]) => [one, length * carry.s]));
1143
+ whole = whole ? { ...project(carry, whole), width: whole.width * carry.s, height: whole.height * carry.s } : null;
1144
+ settle = null;
1145
+ regrow = true;
1146
+ }
1147
+ else {
1148
+ const goals = { slots: carriedThrough(carry ?? LEVEL_LIVE, slots), names: carriedThrough(carry ?? LEVEL_LIVE, names), scales: new Map(scales) };
1149
+ const holds = standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest, panned ? goals : undefined);
1150
+ // What a pan let go of put away and placed again comes up where it lands, as one placed for the first time does: it was not seen where it stood.
1151
+ const from = panned && holds.size > 0 ? { slots: new Map([...drawnBefore.slots].filter(([one]) => holds.has(one))), names: new Map([...drawnBefore.names].filter(([kind]) => holds.has(`name:${kind}`))), scales: drawnBefore.scales } : drawnBefore;
1152
+ settle = { ...from, start: now };
1153
+ regrow = false;
1154
+ }
1155
+ heldHalfWay = false;
1156
+ drawnThrough = null;
929
1157
  }
930
1158
  lastRead = now;
931
1159
  lastReadKey = readKey;
@@ -938,6 +1166,19 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
938
1166
  * its board: a jump before the move began. Placed at once, where the
939
1167
  * camera rests.
940
1168
  */
1169
+ /*
1170
+ * THE HAND OFF THE CITY A MOMENT, a zoom it wrote is placed for: each
1171
+ * board and name goes from where it is drawn to where it stands at the
1172
+ * new zoom, as a zoom let go of always did — once nothing is moving
1173
+ * the ground under them.
1174
+ */
1175
+ if (between || settling || cam.pinching())
1176
+ handAt = now;
1177
+ if (regrow && world.plots.size > 0 && rest !== PAGE && !move && !asking.scrubbing && level(painted) && now - handAt >= LET_GO_MS) {
1178
+ regrow = false;
1179
+ settle = { slots: drawnSlots(now), names: drawnNames(now), scales: drawnScales(now), start: now };
1180
+ standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
1181
+ }
941
1182
  if (world.plots.size > 0 && rest !== PAGE && !move && level(painted) && !slots.has(at.current) && placedFor !== at.current) {
942
1183
  placedFor = at.current;
943
1184
  standAll(world, cam.zoom(), LEVEL_LIVE, shownAt(rest), rest);
@@ -1018,6 +1259,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1018
1259
  move.start = now;
1019
1260
  move.names = drawnNames(now);
1020
1261
  move.slots = drawnSlots(now);
1262
+ move.scales = drawnScales(now);
1021
1263
  move.to = cameraFor(move.toAltitude, move.about, cam.zoom());
1022
1264
  placeFor(move.toAltitude, move.to, cam.zoom());
1023
1265
  }
@@ -1112,6 +1354,9 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1112
1354
  if (resized && !asking.resizing && !move && rest === PANEL) {
1113
1355
  resized = false;
1114
1356
  cam.commit();
1357
+ // A panel sized by hand is not a hand's pan of the city: what it leaves beside the page is placed afresh for it, as the districts say it moved.
1358
+ drawnThrough = null;
1359
+ handReadAt = -Infinity;
1115
1360
  committedAt = performance.now();
1116
1361
  ownZoom = null;
1117
1362
  }
@@ -1127,7 +1372,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1127
1372
  */
1128
1373
  const building = at.where.type === "record" ? world.buildings.get(at.where.id) : undefined;
1129
1374
  if (rest === PANEL && building && level(painted) && inside(project(painted, { x: building.x + building.width / 2, y: building.y + building.height / 2 }), nearbyShown())) {
1130
- settle = { slots: drawnSlots(now), names: drawnNames(now), start: now };
1375
+ settle = { slots: drawnSlots(now), names: drawnNames(now), scales: drawnScales(now), start: now };
1131
1376
  standAll(world, zoomNow, LEVEL_LIVE, shownAt(rest), rest);
1132
1377
  }
1133
1378
  else {
@@ -1212,14 +1457,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1212
1457
  * has brought under one of them is put away (unseen, unreached) until
1213
1458
  * it comes out again.
1214
1459
  */
1215
- const dockRect = fab.current?.querySelector("[data-graview-one-face-dock]")?.getBoundingClientRect();
1216
- const keepOut = move
1217
- ? []
1218
- : [
1219
- { x: 0, y: 0, width: at.view.width, height: at.view.top ?? 0 },
1220
- ...(a > 0.5 && a < 1.5 ? [boxOf(plane.getBoundingClientRect())] : []),
1221
- ...(dockRect && dockRect.width > 0 ? [boxOf(dockRect)] : []),
1222
- ];
1460
+ const keepOut = move ? [] : keptOutNow();
1223
1461
  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);
1224
1462
  // Every board and name a press reaches this frame: a line's ring under or against one of them is not offered.
1225
1463
  pressable.length = 0;
@@ -1235,7 +1473,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1235
1473
  const arriving = gone.slots !== null && goal !== undefined && was === undefined ? carried : 1;
1236
1474
  const leaving = gone.slots !== null && goal === undefined && was !== undefined ? 1 - carried : 1;
1237
1475
  const slot = goal ? slotNow(key) : gone.slots && was ? was : undefined;
1238
- const w = boardWidth * (scales.get(key) ?? 1);
1476
+ const w = boardWidth * scaleFrom(gone, key);
1239
1477
  const h = w / BOARD_ASPECT;
1240
1478
  const footAt = slot ? project(painted, slot) : null;
1241
1479
  const covered = key !== at.current && footAt !== null && under({ x: footAt.x - w / 2, y: footAt.y - h, width: w, height: h });
@@ -1834,10 +2072,35 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1834
2072
  const [a, b] = [...down.values()];
1835
2073
  return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
1836
2074
  };
2075
+ /*
2076
+ * A FINGER ON A SIGN IS ONE OF THE HAND'S (Graview HQ
2077
+ * feature:f-one-face-pinch-and-pan-together-holds). Two fingers, one on
2078
+ * a board and one on the ground beside it, were two gestures: the one on
2079
+ * the board panned the city's view, a layout a move, the one on the
2080
+ * ground dragged its picture, and nothing zoomed — the boards and names,
2081
+ * placed through the picture, stood still while the view moved the
2082
+ * ground under them. Every touch here is handed to the Scene's own hand,
2083
+ * read with those on the ground: two fingers anywhere over the city are
2084
+ * one pinch, which zooms and pans the picture together, and the boards
2085
+ * and names are drawn through it every frame. One finger alone on a sign
2086
+ * still drags the city from here.
2087
+ */
2088
+ const handed = (event) => {
2089
+ const cam = camera.current;
2090
+ if (event.pointerType !== "touch" || !cam)
2091
+ return false;
2092
+ cam.finger(event);
2093
+ return cam.pinching();
2094
+ };
1837
2095
  const onDown = (event) => {
1838
2096
  if (event.pointerType === "mouse" && event.button !== 0)
1839
2097
  return;
1840
2098
  down.set(event.pointerId, { x: event.clientX, y: event.clientY });
2099
+ if (handed(event)) {
2100
+ dragging = true;
2101
+ pinchFrom = null;
2102
+ return;
2103
+ }
1841
2104
  dragging = false;
1842
2105
  pinchFrom = down.size === 2 ? spread() : null;
1843
2106
  };
@@ -1846,6 +2109,12 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1846
2109
  const cam = camera.current;
1847
2110
  if (!was || !cam)
1848
2111
  return;
2112
+ // Two fingers over the city are the Scene's pinch: it zooms and pans the picture, and nothing here moves the view.
2113
+ if (handed(event)) {
2114
+ dragging = true;
2115
+ down.set(event.pointerId, { x: event.clientX, y: event.clientY });
2116
+ return;
2117
+ }
1849
2118
  const dx = event.clientX - was.x;
1850
2119
  const dy = event.clientY - was.y;
1851
2120
  if (down.size >= 2) {
@@ -1870,12 +2139,14 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1870
2139
  // A pointer the page did not see go down keeps no capture; the moves still come here.
1871
2140
  }
1872
2141
  }
2142
+ nudged.current = true;
1873
2143
  cam.panBy(dx, dy);
1874
2144
  down.set(event.pointerId, { x: event.clientX, y: event.clientY });
1875
2145
  };
1876
2146
  const onUp = (event) => {
1877
2147
  if (!down.has(event.pointerId))
1878
2148
  return;
2149
+ handed(event);
1879
2150
  down.delete(event.pointerId);
1880
2151
  if (dragging)
1881
2152
  swallow = true;
@@ -1900,8 +2171,10 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1900
2171
  const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
1901
2172
  if (event.ctrlKey || event.metaKey)
1902
2173
  cam.zoomTo(cam.zoom() * Math.exp(-event.deltaY * unit * 0.01), event.clientX, event.clientY);
1903
- else
2174
+ else {
2175
+ nudged.current = true;
1904
2176
  cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
2177
+ }
1905
2178
  };
1906
2179
  /*
1907
2180
  * A SCROLL OVER A DISTRICT PANS TOO. The Scene leaves a lens's wheel to
@@ -1923,6 +2196,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1923
2196
  event.preventDefault();
1924
2197
  event.stopPropagation();
1925
2198
  const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
2199
+ nudged.current = true;
1926
2200
  cam.panBy(-event.deltaX * unit, -event.deltaY * unit);
1927
2201
  };
1928
2202
  holder?.addEventListener("wheel", onPlotWheel, { passive: false, capture: true });
@@ -1989,7 +2263,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1989
2263
  * in the page — and what of it reaches past the window is inside a
1990
2264
  * box that scrolls, as a phone's sideways row would be.
1991
2265
  */
1992
- style: { position: "fixed", inset: 0, zIndex: ONE_FACE_LAYERS.city, display: "none", visibility: "hidden", overflow: "hidden", containerType: "size" }, children: [sceneSheet === null ? null : _jsx("style", { children: sceneSheet }), _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) => {
2266
+ style: { position: "fixed", inset: 0, zIndex: ONE_FACE_LAYERS.city, display: "none", visibility: "hidden", overflow: "hidden", containerType: "size" }, children: [sceneSheet === null ? null : _jsx("style", { children: sceneSheet }), _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, on the map", 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) => {
1993
2267
  if (el)
1994
2268
  tagEls.current.set(one.kind, el);
1995
2269
  else