castle-web-cli 0.4.252 → 0.4.254

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.
@@ -27,15 +27,19 @@ export function parseHubEntry(hint) {
27
27
  }
28
28
 
29
29
  const SOLO_KINDS = new Set(['layer', 'exact']);
30
+ // No title to name: the place's Doors rows are where titles come from.
31
+ export const UNKNOWN_DOOR_TOAST = "That place isn't in the Town right now";
30
32
 
31
33
  // What to do for a target, from what the client knows right now:
32
34
  // `listed` the place's Doors rows (`hubDoors`: { id, title, solo?, need? }),
33
35
  // `homes` the ids of its House doors (scene `HubDoor.to === 'deck:house'`),
34
- // nearest first, `host` the host's door rows by id (`Hub.doors()`), or null
36
+ // nearest first, `present` the ids of every `HubDoor` in its scene (listed
37
+ // or not), `host` the host's door rows by id (`Hub.doors()`), or null
35
38
  // where it has none, and `guest` true/false/null (null: not known).
36
39
  // Returns { go: { door, title } } (a trip), { jump: row, toast } (onto the
37
- // door's pad, as the Doors list's Go), { toast } (stay), or null (nothing).
38
- export function planHubEntry(target, { listed = [], homes = [], host = null, guest = null } = {}) {
40
+ // door's pad, as the Doors list's Go), { toast } (stay; also for a door the
41
+ // scene does not have), or null (nothing).
42
+ export function planHubEntry(target, { listed = [], homes = [], present = [], host = null, guest = null } = {}) {
39
43
  const row = (id) => listed.find((d) => d?.id === id) ?? null;
40
44
  const usable = (id) => {
41
45
  const h = host?.get(id);
@@ -59,7 +63,12 @@ export function planHubEntry(target, { listed = [], homes = [], host = null, gue
59
63
  }
60
64
  const door = row(target.door);
61
65
  if (!door) {
62
- return null;
66
+ // A door this place has but does not list (a cabinet, a scheduled door
67
+ // between its events) changes nothing. One its scene lacks altogether
68
+ // cannot be followed, so say so rather than leave the player wondering
69
+ // why they are in the Town: ghost redirects by its door rows, which can
70
+ // name a door the saved scene lacks.
71
+ return present.includes(target.door) ? null : { toast: UNKNOWN_DOOR_TOAST };
63
72
  }
64
73
  if (homes.includes(door.id)) {
65
74
  return house(door.id);
@@ -31,6 +31,19 @@ function anchor(value, box) {
31
31
  const x = /^translateX\(([^)]+)\)$/.exec(value ?? '');
32
32
  return [x ? pixels(x[1], box.width) : 0, 0];
33
33
  }
34
+ // The translate a node is drawn with: safe layout's (`safeStyle.js`, an
35
+ // `!important` rule over `--hub-safe-translate` while the node carries
36
+ // `data-hub-safe-translate`) outranks the inline one. Inline-only reads missed
37
+ // a safe-layout move made after the snapshot, so a moved act pill was read at
38
+ // its old place (review, Nov 19).
39
+ export function drawnTranslate(node) {
40
+ const style = node.style ?? {};
41
+ if (node.hasAttribute?.('data-hub-safe-translate') === true) {
42
+ const safe = style.getPropertyValue?.('--hub-safe-translate')?.trim();
43
+ if (safe && safe !== 'revert') {return safe;}
44
+ }
45
+ return style.translate;
46
+ }
34
47
  function shift(box, before, after, viewport) {
35
48
  const [bx, by = '0'] = (before.translate || '0 0').split(' ');
36
49
  const [ax, ay = '0'] = (after.translate || '0 0').split(' ');
@@ -190,7 +203,7 @@ export function makeLayoutCache() {
190
203
  rect: { left: box.left, right: box.right, top: box.top, bottom: box.bottom, width: box.width, height: box.height },
191
204
  size: { w: shown ? node.offsetWidth : 0, h: shown ? node.offsetHeight : 0 },
192
205
  offsets: { left: shown ? node.offsetLeft ?? 0 : 0, top: shown ? node.offsetTop ?? 0 : 0 },
193
- position: { left: style.left, top: style.top, translate: style.translate, transform: style.transform },
206
+ position: { left: style.left, top: style.top, translate: drawnTranslate(node), transform: style.transform },
194
207
  displayed: shown, frame,
195
208
  layout: !shown ? null : reuse ? previous.layout : layoutState(node),
196
209
  };
@@ -291,11 +304,15 @@ export function makeLayoutCache() {
291
304
  // These owned world layers have no transformed ancestors. Use their
292
305
  // snapshot size at the new pixel position, without another DOM read.
293
306
  if (!measured.displayed) {return measured.rect;}
294
- if (sources.get(node)?.positioned) {return shift(measured.rect, measured.position, node.style, viewport);}
307
+ const translate = drawnTranslate(node);
308
+ if (sources.get(node)?.positioned) {
309
+ const style = node.style ?? {};
310
+ return shift(measured.rect, measured.position, { left: style.left, top: style.top, transform: style.transform, translate }, viewport);
311
+ }
295
312
  // Caption and other surface translations can be restored after the
296
313
  // snapshot too; derive that move without re-reading their layout.
297
- return measured.position.translate !== node.style.translate
298
- ? shift(measured.rect, { translate: measured.position.translate }, { translate: node.style.translate }, viewport)
314
+ return measured.position.translate !== translate
315
+ ? shift(measured.rect, { translate: measured.position.translate }, { translate }, viewport)
299
316
  : measured.rect;
300
317
  },
301
318
  size: (node) => active ? read(node).size : { w: used(node).offsetWidth, h: node.offsetHeight },
@@ -185,6 +185,31 @@ export function besideColumn(placed, view, margin = {}, column = [], minLane = 1
185
185
 
186
186
  // The narrowest lane the HUD is moved into beside the right-edge controls.
187
187
  const HUD_LANE_MIN = 72;
188
+ // The smallest size the HUD's big line is shrunk to so that it keeps clear of
189
+ // the kit Back and the standing prompt, as a 56 px "YOU'RE IT" on a 497x213 frame.
190
+ const HUD_BIG_MIN = 16;
191
+
192
+ // The widest word of a node's text in its own font, or 0 where it cannot be
193
+ // measured (no canvas in the geometry tests' DOM adapters).
194
+ let measureContext;
195
+ const widestWord = (node) => {
196
+ const text = node.textContent?.trim();
197
+ if (!text) {return 0;}
198
+ measureContext ??= globalThis.document?.createElement?.('canvas')?.getContext?.('2d') ?? null;
199
+ const style = globalThis.getComputedStyle?.(node);
200
+ if (!measureContext || !style?.font) {return 0;}
201
+ measureContext.font = style.font;
202
+ const upper = style.textTransform === 'uppercase';
203
+ return Math.max(...text.split(/\s+/).map((word) => measureContext.measureText(upper ? word.toUpperCase() : word).width));
204
+ };
205
+ // A HUD line's words broken inside a word: its widest word does not fit the
206
+ // line's content box.
207
+ const wordBroken = (node) => {
208
+ const style = globalThis.getComputedStyle?.(node);
209
+ const inner = node.clientWidth - (Number.parseFloat(style?.paddingLeft) || 0) - (Number.parseFloat(style?.paddingRight) || 0);
210
+ const widest = widestWord(node);
211
+ return widest > 0 && inner > 0 && widest > inner + 0.5;
212
+ };
188
213
 
189
214
  // The box a node stands in while it is out of sight (visibility), but not
190
215
  // while it is not laid out at all (display).
@@ -406,13 +431,104 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
406
431
  // The standing prompt follows every control, so it can see them all.
407
432
  const standing = (entry) => entry.kind === 'text' && !entry.transient && entry.stack === undefined;
408
433
  const act = (entry) => entry.transient && entry.kind === 'control' && entry.id?.startsWith('act-prompt:');
409
- const priority = (entry) => entry.transient ? 2 : entry.kind === 'card' ? 1 : standing(entry) ? 0.5 : 0;
434
+ // The HUD follows the controls and the standing prompt so it can keep off
435
+ // their final places (the kit Back moved past the host corner on a
436
+ // landscape view, or under it in portrait; a prompt lifted beside a small
437
+ // view's column), and precedes the cards and transient text.
438
+ const priority = (entry) => entry.transient ? 2 : entry.kind === 'card' ? 1 : entry.kind === 'hud' ? 0.75 : standing(entry) ? 0.5 : 0;
410
439
  current.sort((a, b) => priority(a) - priority(b));
411
440
  // Cards and transient text are placed after the prompt and yield to its
412
441
  // old place, exactly as before; a prompt that moves keeps off their
413
442
  // unplaced boxes.
414
443
  const later = current.filter((entry) => !entry.projected && (entry.transient || entry.kind === 'card'))
415
444
  .map((entry) => visibleRect(entry.node)).filter(Boolean);
445
+ // The kit Back's and the standing prompt's final boxes: both are placed
446
+ // before the HUD (`priority`).
447
+ let backBox = null, promptBox = null;
448
+ const promptEntry = current.find((entry) => entry.id === 'hud-prompt' && !entry.projected);
449
+ // The HUD keeps clear of the kit Back, the standing prompt and the small
450
+ // view's right column, all already placed. Its lane is the room beside
451
+ // the Back (mirrored, so a centred HUD stays centred) and left of the
452
+ // column; where that is narrower than HUD_LANE_MIN it is the room left of
453
+ // the column alone, below the Back. Vertically, an obstacle starting at or
454
+ // above the HUD's top is a ceiling it goes below; one starting lower is a
455
+ // floor it ends above, as is the frame's bottom. The big line shrinks
456
+ // (never under HUD_BIG_MIN) until it keeps whole words and the HUD fits;
457
+ // only a HUD still too tall at that size is cut to the room left. Nothing
458
+ // is written for a HUD already clear of everything.
459
+ const clearHud = (node, box, placed, margin) => {
460
+ const at = (b, p) => rect(p.x, p.y, b.width, b.height);
461
+ const edge = Math.max(margin?.left ?? 6, viewport.insets.left);
462
+ const bottom = viewport.h - Math.max(margin?.bottom ?? 6, viewport.insets.bottom);
463
+ const sideBy = (a, b) => a.left < b.right && a.right > b.left;
464
+ const columnLeft = (top, bottomY) => Math.min(viewport.w - edge, ...beside.filter((band) => band.top < bottomY && band.bottom > top).map((band) => band.left - 6));
465
+ const obstacles = [backBox, promptBox, ...beside].filter(Boolean);
466
+ // Down past every ceiling in the way, then the floor below that.
467
+ const settle = (x, y) => {
468
+ for (let moved = true, i = 0; moved && i < obstacles.length + 1; i++) {
469
+ moved = false;
470
+ const drawn = rect(x, y, box.width, box.height);
471
+ for (const band of obstacles) {
472
+ if (band.top <= y && overlaps(drawn, band)) {y = band.bottom + 6; moved = true;}
473
+ }
474
+ }
475
+ const drawn = rect(x, y, box.width, box.height);
476
+ const floor = Math.min(bottom, ...obstacles.filter((band) => band.top > y && sideBy(drawn, band)).map((band) => band.top - 6));
477
+ return { y, floor };
478
+ };
479
+ const bigLine = [...node.children].reduce((best, child) => {
480
+ const px = Number.parseFloat(globalThis.getComputedStyle?.(child)?.fontSize) || 0;
481
+ return px > 24 && (!best || px > best.px) ? { child, px } : best;
482
+ }, null);
483
+ let lane = null;
484
+ let floor = bottom;
485
+ const start = placed.y;
486
+ for (let pass = 0; pass < 16; pass++) {
487
+ const drawn = at(box, placed);
488
+ const hit = obstacles.some((band) => overlaps(drawn, band));
489
+ const tooTall = drawn.bottom > floor;
490
+ const broken = bigLine !== null && wordBroken(bigLine.child);
491
+ if (!hit && !tooTall && !broken) {break;}
492
+ const onBack = backBox !== null && overlaps(drawn, backBox);
493
+ const onColumn = beside.some((band) => overlaps(drawn, band));
494
+ if ((onBack || onColumn) && !lane) {
495
+ const span = [drawn.top, Math.max(drawn.bottom, onBack ? backBox.bottom : 0)];
496
+ const right = columnLeft(...span);
497
+ lane = { left: edge, right, below: onBack };
498
+ if (onBack) {
499
+ const leftSide = backBox.left + backBox.right < viewport.w;
500
+ const inner = leftSide ? backBox.right + 6 : viewport.w - backBox.left + 6;
501
+ const nextTo = { left: Math.max(edge, inner), right: Math.min(viewport.w - inner, right), below: false };
502
+ if (nextTo.right - nextTo.left >= HUD_LANE_MIN) {lane = nextTo;}
503
+ }
504
+ const width = Math.max(HUD_LANE_MIN, lane.right - lane.left);
505
+ write(node, 'boxSizing', 'border-box');
506
+ write(node, 'maxWidth', `${width}px`);
507
+ for (const child of node.children) {write(child, 'maxWidth', `${width}px`);}
508
+ } else if (bigLine && bigLine.px > HUD_BIG_MIN) {
509
+ bigLine.px = Math.max(HUD_BIG_MIN, Math.floor(bigLine.px * 0.88));
510
+ write(bigLine.child, 'fontSize', `${bigLine.px}px`);
511
+ } else {break;}
512
+ const fresh = visibleRect(node);
513
+ if (!fresh) {return null;}
514
+ box = fresh;
515
+ const x = lane ? Math.max(lane.left, Math.min(lane.left + (lane.right - lane.left - box.width) / 2, lane.right - box.width)) : box.left;
516
+ const y0 = lane?.below ? Math.max(start, backBox.bottom + 6) : start;
517
+ const settled = settle(x, y0);
518
+ floor = settled.floor;
519
+ placed = { x, y: settled.y, w: box.width, h: box.height };
520
+ }
521
+ if (placed.y + box.height > floor) {
522
+ write(node, 'boxSizing', 'border-box');
523
+ write(node, 'maxHeight', `${Math.max(0, floor - placed.y)}px`);
524
+ write(node, 'overflowY', 'hidden');
525
+ const fresh = visibleRect(node);
526
+ if (!fresh) {return null;}
527
+ box = fresh;
528
+ placed = { ...placed, w: box.width, h: box.height };
529
+ }
530
+ return { box, placed };
531
+ };
416
532
  for (const entry of current) {
417
533
  if (entry.projected) {continue;}
418
534
  const { node, kind } = entry;
@@ -565,6 +681,9 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
565
681
  if (kind === 'hud') {
566
682
  const lane = hudLane(node, box, placed, margin);
567
683
  if (lane) {({ box, placed } = lane);}
684
+ const clear = clearHud(node, box, placed, margin);
685
+ if (!clear) {return null;}
686
+ ({ box, placed } = clear);
568
687
  }
569
688
  // CSS translate is independent of the renderer's anchoring transform.
570
689
  const dx = placed.x - box.left, dy = placed.y - box.top;
@@ -618,6 +737,7 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
618
737
  };
619
738
  if (final) {promptMoved = final; promptBack = back; promptHeld = old;} else {back();}
620
739
  }
740
+ if (entry === promptEntry) {promptBox = visibleRect(node);}
621
741
  controls.push(old);
622
742
  continue;
623
743
  }
@@ -656,6 +776,8 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
656
776
  if (kind === 'card' || entry.transient) {keepOff(final); actOff(final);}
657
777
  if (final && kind === 'card' && entry.over?.()) {overBox = final;}
658
778
  if (final && !entry.transient && kind !== 'hud' && kind !== 'label' && kind !== 'pointer') {controls.push(final);}
779
+ if (final && entry.id === 'back') {backBox = final;}
780
+ if (final && entry === promptEntry) {promptBox = final;}
659
781
  if (final && entry.transient) {(kind === 'label' || kind === 'pointer' ? floating : transient).push(final);}
660
782
  if (final && clear && entry.transient) {captions.push({ node, pill });}
661
783
  }
@@ -687,6 +809,20 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
687
809
  }
688
810
  }
689
811
  }
812
+ // The invariant this pass ends on: Back and the standing prompt are never
813
+ // hidden, and the HUD never lies over either. Where the prompt ended up
814
+ // over the HUD after all (wrapped taller, moved by the caption's lane
815
+ // rule, or sent back to its old box by the rail just above), the HUD is
816
+ // cut to end above it, or, where the prompt starts at or above the HUD's
817
+ // top, to nothing: such a frame has no room left for it.
818
+ const hudNode = current.find((entry) => entry.kind === 'hud' && !entry.projected)?.node;
819
+ const hudFinal = hudNode && visibleRect(hudNode);
820
+ const promptFinal = promptEntry && visibleRect(promptEntry.node);
821
+ if (hudFinal && promptFinal && overlaps(hudFinal, promptFinal)) {
822
+ write(hudNode, 'boxSizing', 'border-box');
823
+ write(hudNode, 'maxHeight', `${Math.max(0, promptFinal.top > hudFinal.top ? promptFinal.top - 6 - hudFinal.top : 0)}px`);
824
+ write(hudNode, 'overflowY', 'hidden');
825
+ }
690
826
  // The rail settled after transient text chose its lane, and does not
691
827
  // make way for the engine's text: a caption whose words it now covers is
692
828
  // not drawn this pass. The rail's move schedules the next pass, which
@@ -1,6 +1,6 @@
1
1
  // Persistent CSS wins over the renderer's normal inline declarations. The
2
2
  // renderer can keep writing its baseline without a per-frame restore/reapply.
3
- const properties = ['translate', 'boxSizing', 'maxWidth', 'whiteSpace', 'overflowWrap', 'overflow', 'textOverflow', 'webkitLineClamp', 'display', 'maxHeight', 'overflowY', 'overflowX'];
3
+ const properties = ['translate', 'boxSizing', 'maxWidth', 'whiteSpace', 'overflowWrap', 'overflow', 'textOverflow', 'webkitLineClamp', 'display', 'maxHeight', 'overflowY', 'overflowX', 'fontSize'];
4
4
  const cssName = key => key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`).replace(/^webkit-/, '-webkit-');
5
5
  export function makeSafeStyle(root) {
6
6
  const sheet = document.createElement('style');
@@ -61,7 +61,9 @@ export function worldPlacement(pointers, labels, controls, view, around = []) {
61
61
  const inside = (box) => box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
62
62
  const clear = (box, ignore) => !taken.some((other) => other !== ignore && overlaps(box, other));
63
63
  const labelBoxes = labels.map((box) => {
64
- let placed = inside(box) && clear(box, box.ignoreObstacle) ? box : null;
64
+ // An NPC's line always goes through `edgeSlot`, which owns its held far
65
+ // slot (a clear own slot is not taken back from a held far one there).
66
+ let placed = !box.edge && inside(box) && clear(box, box.ignoreObstacle) ? box : null;
65
67
  if (!placed && box.clamp) {
66
68
  const at = clampTo(box, bounds);
67
69
  const w = box.right - box.left, h = box.bottom - box.top;
@@ -73,7 +75,7 @@ export function worldPlacement(pointers, labels, controls, view, around = []) {
73
75
  placed = moves.filter((move) => inside(move) && clear(move, box.ignoreObstacle))
74
76
  .sort((a, b) => Math.hypot(a.left - box.left, a.top - box.top) - Math.hypot(b.left - box.left, b.top - box.top))[0] ?? null;
75
77
  } else if (!placed && box.edge) {
76
- placed = edgeSlot(box, bounds, taken, inside, clear);
78
+ placed = edgeSlot(box, bounds, taken, inside, clear, new Set(safeEdges));
77
79
  }
78
80
  if (placed) {taken.push(placed);}
79
81
  return placed;
@@ -83,33 +85,65 @@ export function worldPlacement(pointers, labels, controls, view, around = []) {
83
85
 
84
86
  // Where an NPC's line goes when its slid box is covered: the nearest clear
85
87
  // slot higher up (above its own Talk prompt, beside a reserved corner as
86
- // well if need be), then the nearest clear slot beside or below, then the same search
87
- // for its first line alone (`box.line` tall; the result carries `line: true`
88
- // and the chrome clips the rest). Slots stand 8 px off what they step around
89
- // and stay within a label's width, and twice its height, of where it was
90
- // slid to. Null when the anchor is off `bounds` or nothing is clear.
91
- function edgeSlot(box, bounds, taken, inside, clear) {
88
+ // well if need be), then the nearest clear slot beside or below, within a
89
+ // label's width, and twice its height, of where it was slid to. Then the
90
+ // nearest clear slot for the whole line anywhere in `bounds`: its words name
91
+ // their speaker, and a line drawn as its first line alone can be no more
92
+ // than that name (a barker's "Tally, the street barker:" on a 390 px phone,
93
+ // door-ui pass Nov 19). That far slot is chosen by distance alone, not
94
+ // above-first: above-first let a 0.2 px move of the anchor flip the line
95
+ // between a close slot below and a far one above (review, Nov 19). And it is
96
+ // held: `box.far` is the last far slot's offset from the slid box, kept while
97
+ // that place is still inside and clear, so a nearer slot opening up by a
98
+ // pixel does not move it either. The result carries `far: { dx, dy }` for
99
+ // the caller to hand back next time. Only then the near search for its first
100
+ // line alone (`box.line` tall; the result carries `line: true` and the
101
+ // chrome clips the rest). Slots stand 8 px off what they step around. Null
102
+ // when the anchor is off `bounds` or nothing is clear.
103
+ // Review round 2: a line in a held far slot stays there while that slot is
104
+ // clear, unless a near slot (its own or the near search's) is clear by
105
+ // FAR_RELEASE_PX on every side of what it would step around (the view's
106
+ // edges aside, which near slots are pinned against). So a line on the
107
+ // boundary does not flip near and far frame to frame: it goes far only when
108
+ // nothing near fits, and comes back only with room to spare.
109
+ const FAR_RELEASE_PX = 8;
110
+ function edgeSlot(box, bounds, taken, inside, clear, edges = new Set()) {
92
111
  const at = clampTo(box, bounds);
93
112
  if (!at) {return null;}
94
- if (inside(at) && clear(at, box.ignoreObstacle)) {return at;}
95
113
  const w = at.right - at.left, h = at.bottom - at.top;
96
- const reach = { left: at.left - w - 8, right: at.right + w + 8, top: at.top - 2 * h - 16, bottom: at.bottom + 2 * h + 16 };
97
- const near = taken.filter((other) => other !== box.ignoreObstacle && overlaps(other, reach));
98
- const lefts = [...new Set([at.left, bounds.left, bounds.right - w, ...near.flatMap((other) => [other.left - 8 - w, other.right + 8])])]
99
- .filter((left) => Math.abs(left - at.left) <= w + 8);
100
- const slot = (height) => {
114
+ const held = box.far && Number.isFinite(box.far.dx) && Number.isFinite(box.far.dy)
115
+ ? { left: at.left + box.far.dx, right: at.right + box.far.dx, top: at.top + box.far.dy, bottom: at.bottom + box.far.dy } : null;
116
+ const heldClear = Boolean(held && inside(held) && clear(held, box.ignoreObstacle));
117
+ const roomy = (move) => {
118
+ const m = FAR_RELEASE_PX;
119
+ const grown = { left: move.left - m, right: move.right + m, top: move.top - m, bottom: move.bottom + m };
120
+ return !taken.some((other) => other !== box.ignoreObstacle && !edges.has(other) && overlaps(grown, other));
121
+ };
122
+ const keepFar = (near) => heldClear && !(near && roomy(near));
123
+ if (inside(at) && clear(at, box.ignoreObstacle)) {
124
+ return keepFar(at) ? { ...held, far: box.far } : at;
125
+ }
126
+ const near = { left: at.left - w - 8, right: at.right + w + 8, top: at.top - 2 * h - 16, bottom: at.bottom + 2 * h + 16 };
127
+ const slot = (height, reach, byDistance = false) => {
128
+ const around = taken.filter((other) => other !== box.ignoreObstacle && overlaps(other, reach));
129
+ const lefts = [...new Set([at.left, bounds.left, bounds.right - w, ...around.flatMap((other) => [other.left - 8 - w, other.right + 8])])]
130
+ .filter((left) => left >= reach.left && left + w <= reach.right);
101
131
  const tops = [...new Set([at.top, at.bottom - height, bounds.top, bounds.bottom - height,
102
- ...near.flatMap((other) => [other.top - 8 - height, other.bottom + 8])])]
132
+ ...around.flatMap((other) => [other.top - 8 - height, other.bottom + 8])])]
103
133
  .filter((top) => top >= reach.top && top + height <= reach.bottom);
104
- const rank = (move) => [move.bottom < at.bottom - 0.5 ? 0 : 1, Math.hypot(move.left - at.left, move.bottom - at.bottom)];
134
+ const rank = (move) => [byDistance || move.bottom < at.bottom - 0.5 ? 0 : 1, Math.hypot(move.left - at.left, move.bottom - at.bottom)];
105
135
  return tops.flatMap((top) => lefts.map((left) => ({ left, right: left + w, top, bottom: top + height })))
106
136
  .filter((move) => inside(move) && clear(move, box.ignoreObstacle))
107
137
  .map((move) => ({ move, key: rank(move) }))
108
138
  .sort((a, b) => a.key[0] - b.key[0] || a.key[1] - b.key[1])[0]?.move ?? null;
109
139
  };
110
- const whole = slot(h);
111
- if (whole || !(box.line > 0 && box.line < h - 0.5)) {return whole;}
112
- const first = slot(box.line);
140
+ const nearWhole = slot(h, near);
141
+ if (keepFar(nearWhole)) {return { ...held, far: box.far };}
142
+ if (nearWhole) {return nearWhole;}
143
+ const far = slot(h, bounds, true);
144
+ if (far) {return { ...far, far: { dx: far.left - at.left, dy: far.top - at.top } };}
145
+ if (!(box.line > 0 && box.line < h - 0.5)) {return null;}
146
+ const first = slot(box.line, near);
113
147
  return first && { ...first, line: true };
114
148
  }
115
149
 
@@ -209,7 +243,8 @@ function surroundings(node, geometry) {
209
243
  }
210
244
 
211
245
  // `held(node)` is the box a control held before safe layout moved or hid it
212
- // (an act prompt): labels and pointers make way for that box, as before.
246
+ // (an act prompt): labels and pointers make way for that box, as before, and
247
+ // for the box it is drawn in now.
213
248
  export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache(), held = () => null) {
214
249
  const hidden = new Set();
215
250
  const shifted = new Map();
@@ -247,6 +282,8 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
247
282
  };
248
283
  // NPC lines drawn as their first line alone: node -> its own clip-path.
249
284
  const clipped = new Map();
285
+ // NPC lines placed in a far slot: node -> its offset from the slid box.
286
+ const farSlots = new WeakMap();
250
287
  function unplace() {
251
288
  for (const node of hidden) {node.style.visibility = '';}
252
289
  for (const [node, value] of shifted) {node.style.translate = value;}
@@ -394,7 +431,10 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
394
431
  const pointers = measured.filter((entry) => entry.kind === 'pointer' && entry.id !== 'stuck')
395
432
  .sort((a, b) => Number(b.id?.startsWith('pointer:goal:') === true) - Number(a.id?.startsWith('pointer:goal:') === true));
396
433
  const labels = measured.filter((entry) => entry.kind === 'label');
397
- const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label' && !held(entry.node)).map((entry) => entry.box)
434
+ // A moved act prompt is made way for twice: at the place it held (as
435
+ // before) and where it is drawn now, since it is painted over any label
436
+ // left under its new lane (Talk to Rowan over a barker's line).
437
+ const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label').map((entry) => entry.box)
398
438
  .concat(surfaces.map((entry) => held(entry.node)).filter(Boolean));
399
439
  const around = obstacles();
400
440
  // An NPC line's one-line form: the slot is its line box and both
@@ -411,7 +451,13 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
411
451
  return top + line + (Number.parseFloat(style.paddingBottom) || 0);
412
452
  };
413
453
  const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ node, box, ignoreObstacle, clamp, edge }) => ignoreObstacle || clamp || edge
414
- ? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle, clamp, edge, ...(edge ? { line: lineOf(node) } : {}) } : box), [...controls, ...around], view(), around);
454
+ ? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle, clamp, edge,
455
+ ...(edge ? { line: lineOf(node), ...(farSlots.has(node) ? { far: farSlots.get(node) } : {}) } : {}) } : box), [...controls, ...around], view(), around);
456
+ // An NPC line's far slot is held across flushes (`edgeSlot`).
457
+ labels.forEach(({ node, edge }, index) => {
458
+ const far = edge ? placements.labels[index]?.far : null;
459
+ if (far) {farSlots.set(node, far);} else {farSlots.delete(node);}
460
+ });
415
461
  for (const [items, boxes] of [[pointers, placements.pointers], [labels, placements.labels]]) {
416
462
  items.forEach(({ node, box }, index) => {
417
463
  const placed = boxes[index];
@@ -1935,15 +1935,19 @@ class HubSystem {
1935
1935
  }
1936
1936
  const me = scene.actorWith('Player')?.components.Transform;
1937
1937
  const homes = [];
1938
+ const present = [];
1938
1939
  for (const actor of allActors(scene)) {
1939
1940
  const door = actor.components?.HubDoor;
1941
+ if (typeof door?.id === 'string') {
1942
+ present.push(door.id);
1943
+ }
1940
1944
  if (door?.to === 'deck:house' && typeof door.id === 'string') {
1941
1945
  const t = actor.components.Transform;
1942
1946
  homes.push({ id: door.id, d: me && t ? Math.hypot(t.x - me.x, t.z - me.z) : Infinity });
1943
1947
  }
1944
1948
  }
1945
1949
  homes.sort((a, b) => a.d - b.d);
1946
- const plan = planHubEntry(target, { listed: Hub.hub.doors, homes: homes.map((h) => h.id), host, guest });
1950
+ const plan = planHubEntry(target, { listed: Hub.hub.doors, homes: homes.map((h) => h.id), present, host, guest });
1947
1951
  console.log(`[hub-entry] ${JSON.stringify({ target, plan: plan ? Object.keys(plan) : null })}`);
1948
1952
  if (plan?.go) {
1949
1953
  this.goHub(scene, { door: plan.go.door, title: plan.go.title });
@@ -5479,6 +5479,7 @@ a deck written before them remains valid.
5479
5479
  | 2026-11-18 (v1.223) | Writer leases (server-only, no wire or manifest change): a lone visit back that arrives while an earlier visit's revalidation is still out checks the claim again once that round settles (on whichever claim it settled), so a check from before another instance's takeover never lets the return proceed only to lose its first save. `resumePose` takes its snapshot through the lease view too, so it reads only once the claim settles and keeps a pose the previous writer saved just before; its 5 s read budget starts once the claim has settled. An older pending round that resumes on a replacement claim a newer arrival is already checking waits for that round and keeps the claim it found; it never inherits a claim that round reopens. A take holds its queue place at once, so an end asked while it waits for the claim runs after it. Without `writerLease` nothing changes. No deck opts in yet. |
5480
5480
  | 2026-11-18 (v1.224) | Writer leases (server-only): `await hub.saves.holds(view)` tells whether the claim a save view writes through is still active and has not been lost, after pending claim checks settle. Unrecognized views and lease-off stores answer true. No manifest or wire change. |
5481
5481
  | 2026-11-19 (v1.229) | §4 optional `away(hub, playerId, { userId, username })` and `back(hub, playerId, { userId, username, awayMs })` hooks: pinned retention tells a place once when it holds a dropped arrived player, and once on the same id's return inside the window (after the pose is restored, before the hello replay and `resume`); otherwise the visit ends with `leave` as before ("Away and back"). The 60 s keep and pose-only places never call them. Hook presence is the opt-in; server-only, no manifest or wire change. |
5482
+ | 2026-11-19 (v1.231) | §5 hub-entry link to a door the place's scene does not have (no `HubDoor` with that id; a door it has but does not list, such as a cabinet or a scheduled door between its events, still changes nothing): instead of changing nothing, the player stays where they are and is told "That place isn't in the Town right now" (no title: the place's Doors rows are where titles come from), guests and accounts not known alike. Ghost redirects by its door rows, which can name a door a saved scene lacks. Unknown slots and hosts without the command still change nothing. Client-only; nothing new sent or kept; no manifest key. Within `hub.contract: 1`. |
5482
5483
  | 2026-11-19 (v1.230) | §1 `resumeWindowSec` may stand beside `resumePose` (still refused beside `result`, `houseResume` and `resumeArrivalPose`): the pinned window holds the same visit and pose, and `resumePose`'s stored pose then places a new id for the same account up to ten minutes after departure, as the Town's places already do ("Door resume window"). Manifest validation only; no runtime or wire change. |
5483
5484
  | 2026-11-18 (v1.226) | Writer leases (server-only, no manifest or wire change): every `set`/`remove`/`increment` through a `hub.saves` view carries the platform writer check of the claim it is bound to, so a stale write is refused atomically instead of after a separate fence (the write-after-fence window is closed for ordinary writes where the platform checks). A refusal loses the claim and is never retried. Where a checked write answers `CAULDRON_STORAGE_UNAVAILABLE` (`castle-web serve`, persistent-world sessions; the details may sit under `extensions`) the session fences and writes unchecked as before; view `transaction`/`conditionalWrite` and root atomic calls keep their fence. Every lone arrival now claims anew and the place reloads (no revalidation of a held claim): queued writes of the previous visit go first for up to 5 s; claims are sent or retried only while a connected visit is here, and a resume picks a waiting claim up again. `holds(view)` also waits for the account's current claim. Without `writerLease` nothing changes. No deck opts in yet. |
5484
5485
  | 2026-11-18 (v1.228) | Writer leases (server-only, no manifest or wire change): `hub.saves.bind(store, view)` returns another store of the account (a `session.storage.playthrough` handle) bound to the claim `view` is bound to: `set`/`remove` carry that claim's writer check and run in account order, reads wait for that claim. The raw store when `view` is not a lease view or the lease is off. The Town conversation saves through it. No deck opts in yet. |
@@ -5520,7 +5521,7 @@ a deck written before them remains valid.
5520
5521
  | 2026-10-20 (v1.158) | Optional `idle.expression`: an emote wheel, five RP motions, sit-anywhere and private visit role-emote grants via `hub.emotesFor` (§6). No key preserves existing UI, behavior and wire bytes. |
5521
5522
  | 2026-10-20 (v1.156) | §4 `hub.noTrips(playerId)`: a client in the app (`CastleEmbed.host === "mobile"`) asks `Hub.doors()` once a page, and a host that refuses it as UNKNOWN_COMMAND (an app from before hub commands, released iOS 1.150 and 1.151) has no door trips: after each hello it sends `hub-no-trips`, and that player is left out of every pad's group, `hub.go` and house visits for the visit, with "Update Castle to play" over a door whose pad they stand on, to them alone. Any other answer (rows, `unavailable`, a timeout) and every web page change nothing. Every deck, no key. Within `hub.contract: 1`. |
5522
5523
  | 2026-10-19 (v1.155) | §5 the host may post a hub Go event (SDK `Hub.onGo`, `{ castleSdk: 1, hub: { type: "go", doorId, owner?, title?, party? } }`): the kit takes the player through the named door like a fired pad (`Hub.go` with `owner` as `ownerUserId`, the door beat, the cover), only once the place is settled and with no trip in flight, and drops it after 60 s, when it arrives during a trip, or for a door this place's Doors list lacks (a cabinet included). An older SDK or kit ignores it. Every deck, no key. Within `hub.contract: 1`. |
5523
- | 2026-10-19 | §5 hub-entry link: on a page load whose first place is a root place (no hub join, no door behind it, not a game), the client reads `Multiplayer.joinHint()` once; `{ routeId: 'hub-entry', slot }` with `slot` `house` sends a signed-in player through the nearest listed House door (`HubDoor.to` `deck:house`) to their own House (`Hub.go` with no owner), and a guest stays with "Sign in to have a House of your own". `door:<id>` of a listed door: a host row placed by `layer`/`exact` needing one player is a trip through it; a pad door (ghost takes only a fired pad's group) or one needing more players is the Doors list's Go onto its pad, the latter saying how many it needs; a House door is the House rule; a disabled row says it is closed; a guest stays for every door, told "<Title> is in the Town · sign in to play". It waits while the player is held, and checks everything again after its door lookup, right before acting. An invite arrival wins; a trip, session swap, re-admission or new player id on the same connection, or 30 s unplaced spends it; unknown slots, unknown doors and hosts without the command change nothing. Every deck, no key; nothing new sent or kept. Within `hub.contract: 1`. |
5524
+ | 2026-10-19 | §5 hub-entry link: on a page load whose first place is a root place (no hub join, no door behind it, not a game), the client reads `Multiplayer.joinHint()` once; `{ routeId: 'hub-entry', slot }` with `slot` `house` sends a signed-in player through the nearest listed House door (`HubDoor.to` `deck:house`) to their own House (`Hub.go` with no owner), and a guest stays with "Sign in to have a House of your own". `door:<id>` of a listed door: a host row placed by `layer`/`exact` needing one player is a trip through it; a pad door (ghost takes only a fired pad's group) or one needing more players is the Doors list's Go onto its pad, the latter saying how many it needs; a House door is the House rule; a disabled row says it is closed; a guest stays for every door, told "<Title> is in the Town · sign in to play". It waits while the player is held, and checks everything again after its door lookup, right before acting. An invite arrival wins; a trip, session swap, re-admission or new player id on the same connection, or 30 s unplaced spends it; unknown slots and hosts without the command change nothing; a door the place's scene does not have says "That place isn't in the Town right now" (v1.231; before it, nothing). Every deck, no key; nothing new sent or kept. Within `hub.contract: 1`. |
5524
5525
  | 2026-10-18 (v1.154) | §5 a door asked within 16 s of this player's arrival in a session (a join, a trip's, a reconnect; ghost's roster lags it by up to 15 s, during which the SDK asks again through `forbidden`) keeps its cover up for the 15 s loading limit counted from that window's end, not the trip's start: a door that answers ok after 14 s of `forbidden` goes through instead of "it took too long". A door that never answers still shuts, by 31 s at most; one asked later keeps 15 s. Every deck, no key. Within `hub.contract: 1`. |
5525
5526
  | 2026-10-17 (v1.147) | §5 a joining player's body without a readable saved pose starts on the scene's spawn itself (its x and z, at the v1.48 standing height), not on the multiplayer spawn ring 1.1 m around it. The client starts its own body at the spawn; on the live Town the first WORLD snapped it to its ring slot, and the kit's arrival row back at the spawn then reached it as a correction under the client's 4 m snap distance, eased a quarter of the way a frame: a 1.1 m glide just after the cover lifted (3 of 5 captures, web and TECNO). Players waiting together share the spot until the arrival row spreads them; the row, the v1.40 settle and every later placement are unchanged. Saved and resumed poses are unchanged. A default in every hub place; no key, nothing new sent. |
5526
5527
  | 2026-10-18 (v1.150) | §12 and §13 authored mind taps also apply in `under13Choices` places: an under-13 speaker receives the place's authored asks ahead of both bundle `childAsks` and the three legacy choices. A matching trimmed `hub-npc-say` is answered through `npcLine` `why: 'authored'`; legacy strings outside those taps are ignored, and mind turns remain refused with `HUB_NPC_CHOICE_REQUIRED`. Mind-less NPCs, minds without authored asks, adults and unknown ages are unchanged. Within `hub.contract: 1`. |
@@ -559,7 +559,7 @@
559
559
  []
560
560
  ]
561
561
  ],
562
- "dom": "7654bf3394dd1aae648fe5c4ea9d5afdb7f6022e294ae4959527b03bf1eef44c",
562
+ "dom": "c81cf6a0669f80bfd4b6b5d1d006433570f4e77138c8a7574a688c62833748e2",
563
563
  "writes": 669
564
564
  },
565
565
  "safeLandscape": {
@@ -620,7 +620,7 @@
620
620
  []
621
621
  ]
622
622
  ],
623
- "dom": "eeb4ce9baed02120776543a83a90893307d1ee677aeccc2b41d8139b55082be1",
623
+ "dom": "9ba1c767ba54260c4436ab6a4bae23ff35e35f99c0ca6dce8ce79efc16e53c3f",
624
624
  "writes": 713
625
625
  },
626
626
  "lateSink": {
@@ -62,7 +62,7 @@ globalThis.__entryHub = {
62
62
  onBack: () => () => {},
63
63
  };
64
64
 
65
- const { parseHubEntry, planHubEntry, makeHubEntry, HUB_ENTRY_WAIT_MS } = await import('../code/client/hubEntry.js');
65
+ const { parseHubEntry, planHubEntry, makeHubEntry, HUB_ENTRY_WAIT_MS, UNKNOWN_DOOR_TOAST } = await import('../code/client/hubEntry.js');
66
66
  const { installSystem } = await import('../code/systems/hub.js');
67
67
  const HubState = await import('../code/client/state.js');
68
68
 
@@ -134,10 +134,12 @@ await test('plan: doors -- pad doors are the Doors list jump, layer/exact solo d
134
134
  { jump: listed[3], toast: 'Duo Dash needs 2 players · wait on the pad for others' }, 'a pair door is never a solo trip');
135
135
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { ...me, host: new Map([['door-plaza', { placementKind: 'layer', enabled: false }]]) }),
136
136
  { toast: 'Plaza is closed right now' });
137
- assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { ...me, host }), null, 'an unknown door is ignored');
137
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { ...me, host }), { toast: UNKNOWN_DOOR_TOAST }, 'an unknown door says it is not here');
138
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, me), { toast: UNKNOWN_DOOR_TOAST }, 'with no host rows too');
139
+ assert.equal(planHubEntry({ kind: 'door', door: 'cab-1' }, { ...me, host, present: ['cab-1', 'door-plaza'] }), null, 'a door the scene has but does not list (a cabinet) changes nothing');
138
140
  });
139
141
 
140
- await test('plan: a guest never trips or jumps for a door link; an unknown account stays quietly', () => {
142
+ await test('plan: a guest never trips or jumps for a door link; an unknown account stays quietly; an unknown door is said', () => {
141
143
  const host = new Map([
142
144
  ['door-prism', { doorId: 'door-prism', placementKind: 'pad', enabled: true }],
143
145
  ['door-plaza', { doorId: 'door-plaza', placementKind: 'layer', enabled: true }],
@@ -145,7 +147,8 @@ await test('plan: a guest never trips or jumps for a door link; an unknown accou
145
147
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: true }), { toast: 'Plaza is in the Town · sign in to play' });
146
148
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-prism' }, { listed, homes, host, guest: true }), { toast: 'Prism is in the Town · sign in to play' });
147
149
  assert.equal(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: null }), null);
148
- assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: true }), null, 'an unknown door is still silent');
150
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: true }), { toast: UNKNOWN_DOOR_TOAST }, 'a guest is told too');
151
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: null }), { toast: UNKNOWN_DOOR_TOAST }, 'and an unknown account');
149
152
  });
150
153
 
151
154
  // ---- the once-per-load state ----
@@ -299,6 +302,7 @@ function setup({ slot = 'house', depth = 0, target = { mode: 'public' } } = {})
299
302
  ['d1', { id: 'd1', components: { HubDoor: { id: 'home-1', to: 'deck:house' }, Transform: { x: 30, z: 0 } } }],
300
303
  ['d2', { id: 'd2', components: { HubDoor: { id: 'home-2', to: 'deck:house' }, Transform: { x: 5, z: 0 } } }],
301
304
  ['d3', { id: 'd3', components: { HubDoor: { id: 'door-prism', to: 'deck:prism' }, Transform: { x: 0, z: 9 } } }],
305
+ ['c1', { id: 'c1', components: { HubDoor: { id: 'cab-1', kind: 'cabinet', to: 'deck:cab' }, Transform: { x: 0, z: -9 } } }],
302
306
  ]);
303
307
  const scene = {
304
308
  persistent: { hubTickets: [], ...(depth ? { hubDepth: depth } : {}) },
@@ -401,8 +405,26 @@ await test('system: not at the root (behind a door, a hub join, a trip already)
401
405
  assert.equal(hints, 0, 'a game is not the Town');
402
406
  });
403
407
 
408
+ await test('system: a door link the place does not list stays in the Town and says so', async () => {
409
+ const { system, frame, sent } = setup({ slot: 'door:door-nope' });
410
+ await frame();
411
+ assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
412
+ assert.equal(sent.length, 0);
413
+ assert.equal(system.trip, null);
414
+ assert.equal(system.toast.text, UNKNOWN_DOOR_TOAST);
415
+ });
416
+
417
+ await test('system: a door link to a scene door the place does not list (a cabinet) changes nothing', async () => {
418
+ const { system, frame, sent } = setup({ slot: 'door:cab-1' });
419
+ await frame();
420
+ assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
421
+ assert.equal(sent.length, 0);
422
+ assert.equal(system.trip, null);
423
+ assert.equal(system.toast.text, '');
424
+ });
425
+
404
426
  await test('system: unknown slots and old hosts change nothing', async () => {
405
- for (const slot of ['garden', 'door:door-nope', null]) {
427
+ for (const slot of ['garden', null]) {
406
428
  const { system, frame, sent } = setup({ slot });
407
429
  await frame();
408
430
  assert.equal(calls.filter((c) => c[0] === 'go').length, 0);