castle-web-cli 0.4.235 → 0.4.236

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.
@@ -533,6 +533,16 @@ export function makeActionOverflow({ root, edgeMax = false, readSafeInsets = nul
533
533
  },
534
534
  watch,
535
535
  invalidate: schedule,
536
+ // v1.152: the safe-layout pass has just placed the controls the rail
537
+ // avoids (Act/Jump arriving restacks the column). Place the rail against
538
+ // those final boxes in the same pass, so neither the next frame nor a
539
+ // debug report shows it over them; layout() falls back to More/Actions or
540
+ // hides it when nothing clears. An unchanged layout key costs one read.
541
+ settle() {
542
+ if (disposed || !canAct || !items.length) {return;}
543
+ if (open) {schedule(); return;}
544
+ layout();
545
+ },
536
546
  cancel: () => closeSheet(),
537
547
  isOpen: () => open,
538
548
  dispose() {
@@ -3192,7 +3192,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3192
3192
  }
3193
3193
  if (safeInsets) {
3194
3194
  safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
3195
- if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.invalidate();}
3195
+ if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.settle();}
3196
3196
  } });
3197
3197
  debugLayout = () => { safeLayout.flush(); worldLayout?.flush(); return safeLayout.report(); };
3198
3198
  (globalThis.castleHub ??= {}).layout = debugLayout;
@@ -256,15 +256,6 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
256
256
  if (final && !entry.transient && kind !== 'hud' && kind !== 'label' && kind !== 'pointer') {controls.push(final);}
257
257
  if (final && entry.transient) {transient.push(final);}
258
258
  }
259
- const boxes = [];
260
- for (const entry of current) {
261
- const reported = entry.reportNodes?.() ?? [{ node: entry.node, id: entry.id, kind: entry.kind }];
262
- for (const item of reported) {
263
- const box = visibleRect(item.node);
264
- if (box) {boxes.push({ id: item.id, kind: item.kind, x: box.left, y: box.top, w: box.width, h: box.height });}
265
- }
266
- }
267
- last = { view: viewport, reserved, boxes };
268
259
  sizes?.disconnect();
269
260
  sizes?.observe(root);
270
261
  sizes?.observe(probe);
@@ -278,7 +269,18 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
278
269
  else {observer.observe(node, { subtree: true, childList: true, attributes: true, characterData: true, attributeOldValue: true, characterDataOldValue: true });}
279
270
  }
280
271
 
272
+ // v1.152: the action rail settles against the final controls here, so
273
+ // the report is read after it.
281
274
  onLayout();
275
+ const boxes = [];
276
+ for (const entry of current) {
277
+ const reported = entry.reportNodes?.() ?? [{ node: entry.node, id: entry.id, kind: entry.kind }];
278
+ for (const item of reported) {
279
+ const box = visibleRect(item.node);
280
+ if (box) {boxes.push({ id: item.id, kind: item.kind, x: box.left, y: box.top, w: box.width, h: box.height });}
281
+ }
282
+ }
283
+ last = { view: viewport, reserved, boxes };
282
284
  return last;
283
285
  }
284
286
  watch(root);
@@ -1631,7 +1631,10 @@ Safe placement persists through CSS custom properties; animation frames do not
1631
1631
  restore, measure or reapply it. Insets are read on initialization and viewport
1632
1632
  resize/orientation/visual-viewport events. DOM changes coalesce into keep-out
1633
1633
  passes at most twice per second. Loading-cover changes settle before paint;
1634
- explicit debug reports still measure synchronously.
1634
+ explicit debug reports still measure synchronously. v1.152: the action rail is
1635
+ placed in the same pass, against the controls' final boxes, so a column that
1636
+ restacks (Act/Jump arriving) never leaves the rail over it for a frame or a
1637
+ report.
1635
1638
 
1636
1639
  1. Edge-anchored chrome keeps `max(its existing margin, env(safe-area-inset-*))`
1637
1640
  on that edge. This includes People/Doors, Character, the action column and
@@ -0,0 +1,118 @@
1
+ // Real CSS geometry for the safe-inset action rail in a crowded Town HUD:
2
+ // a five-item Today checklist wrapping to two lines, Invite/Market offers, a
3
+ // partner's talk prompt beside the player and the snapped avatar reserve, all
4
+ // under hub.act. When Act/Jump arrive (a talk or trip ends) the column
5
+ // restacks, and a layout report taken at once must already show the rail
6
+ // clear of them, labels readable (v1.152). Run with CHROME pointing to the QA
7
+ // browser (and BROWSER_WS when using a remote GPU browser).
8
+ import assert from 'node:assert/strict';
9
+ import { readFile } from 'node:fs/promises';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { chromium } from 'playwright-core';
12
+ import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
13
+
14
+ const root = new URL('../../../', import.meta.url);
15
+ const source = await readFile(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
16
+ const setup = source.slice(source.indexOf(' this.chrome.setWorldLabelFocus'), source.indexOf(' Avatar.load(scene);'));
17
+ const OFFERS = [
18
+ { id: 'invite-friend', label: 'Invite a friend' }, { id: 'market-looks', label: 'Market looks' },
19
+ ];
20
+ const PROMPT = ['Play Gem Rush', 'Stamp your card (0/4)', 'Water the garden', 'Game with a friend (extra)', 'Sit with a friend (extra)']
21
+ .map(item => `○\u00a0${item.replaceAll(' ', '\u00a0')}`).join(' ');
22
+ const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
23
+ try {
24
+ const page = await browser.newPage();
25
+ await page.route('http://layout.test/**', async route => {
26
+ const path = new URL(route.request().url()).pathname;
27
+ if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<script type="importmap">{"imports":{"three":"/node_modules/three/build/three.module.js"}}</script><body style="margin:0"></body>' });
28
+ const url = new URL(`.${path}`, root);
29
+ assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
30
+ await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
31
+ });
32
+ for (const [width, height] of [[844, 390], [390, 844], [1440, 900]]) {
33
+ await page.setViewportSize({ width, height });
34
+ await page.goto('http://layout.test/');
35
+ await logRenderer(page, 'action rail crowded');
36
+ const result = await page.evaluate(async ({ setup, OFFERS, PROMPT }) => {
37
+ const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
38
+ const { overlaps } = await import('/kits/hub-game/code/client/safeLayout.js');
39
+ const { makeAct } = await import('/kits/hub-game/code/client/act.js');
40
+ const { hub } = await import('/kits/hub-game/code/client/state.js');
41
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, safeInsets: true });
42
+ chrome.soundControl(true, { volume: 0.7, muted: false }, { onMuted() {}, onVolume() {} });
43
+ chrome.showPicker(true, 0);
44
+ chrome.setEmotes([['wave', '👋']]); chrome.setSay({ reactions: [], phrases: [] });
45
+ const scene = { persistent: {}, three: { renderer: { domElement: { parentElement: document.body } } } };
46
+ const Hub = { deck: { safeInsets: false, act: true }, hub: {} };
47
+ const context = { chrome };
48
+ hub.place = { id: 'main', act: true };
49
+ hub.prompts = [{ id: 'partner', verb: 'Talk to Juniper about the shared garden plot' }];
50
+ const partner = { id: 'partner', components: { HubNpc: { name: 'Juniper' }, Transform: { x: 0.6, y: 1, z: 0 } } };
51
+ const act = makeAct(chrome, { perform() {} }, { prepare() {} });
52
+ Object.assign(scene, { getActors: () => [partner], getActor: () => partner, moveInput: { consumeJump() {} } });
53
+ scene.three.camera = { position: { clone: () => ({ set() { return this; }, project: () => ({ x: 0.08, y: -0.1, z: 0 }) }) } };
54
+ const local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
55
+ // The player stands just right of centre, as with a partner beside them.
56
+ let avatar = { left: innerWidth * 0.5 - 30, right: innerWidth * 0.5 + 40, top: innerHeight * 0.3, bottom: innerHeight * 0.62 };
57
+ let can = false, canAct = true;
58
+ const draw = () => {
59
+ new Function('Hub', 'scene', 'worldLabelFocus', setup).call(context, Hub, scene, () => false);
60
+ chrome.setHud({ title: 'Town', text: PROMPT }, null);
61
+ chrome.grabPrompt(null); chrome.sitPrompt(null); chrome.talkPrompt(null);
62
+ chrome.setWorldAvatar(avatar);
63
+ act.frame(scene, { net: { selfId: () => 'p', send() {} } }, local, can);
64
+ chrome.layoutInteractionRail();
65
+ chrome.setActions(OFFERS, () => {}, canAct, 1, true);
66
+ chrome.frameSafeInsets?.();
67
+ };
68
+ // The engine's cached cadence: frames, observer delivery and the rail's
69
+ // own 500 ms throttle, with no forced debug flush before measuring.
70
+ const paint = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
71
+ const settle = async () => {
72
+ for (let round = 0; round < 3; round++) {
73
+ for (let frame = 0; frame < 4; frame++) {draw(); await paint();}
74
+ await new Promise(resolve => setTimeout(resolve, 550));
75
+ }
76
+ for (let frame = 0; frame < 6; frame++) {draw(); await paint();}
77
+ };
78
+ await settle();
79
+ // The Act pair arrives (a talk or trip ends) and the QA capture asks
80
+ // for the layout report at once, then reads the frame: the rail must
81
+ // already clear the pair's final place.
82
+ can = true; draw(); await paint();
83
+ // chrome.layout() is a single flush; castleHub.layout() flushes twice.
84
+ const report = chrome.layout();
85
+ const shown = node => node && node.getBoundingClientRect().width > 0 && getComputedStyle(node).display !== 'none' && getComputedStyle(node).visibility !== 'hidden';
86
+ const box = node => { const r = node.getBoundingClientRect(); return { left: r.left, right: r.right, top: r.top, bottom: r.bottom }; };
87
+ const rail = [...document.querySelectorAll('[data-hub="action-rail"] button')].filter(shown).map(node => ({ name: node.textContent, ...box(node) }));
88
+ const pair = ['act', 'jump'].map(kind => document.querySelector(`[data-hub-act="${kind}"]`)).filter(shown);
89
+ const controls = pair.map(node => ({ name: node.textContent, ...box(node),
90
+ // The label is readable when its own centre takes the tap.
91
+ reachable: node.contains(document.elementFromPoint((box(node).left + box(node).right) / 2, (box(node).top + box(node).bottom) / 2)) }));
92
+ const hits = [];
93
+ for (const offer of rail) for (const control of controls) if (overlaps(offer, control)) hits.push([offer.name, control.name]);
94
+ const prompt = document.querySelector('[data-hub="hud-prompt"]');
95
+ const promptHits = rail.filter(offer => overlaps(offer, box(prompt))).map(offer => offer.name);
96
+ // The report the capture reads agrees with the frame.
97
+ const reported = id => report.boxes.filter(b => b.id === id || b.id.startsWith(`${id}:`)).map(b => ({ name: b.id, left: b.x, top: b.y, right: b.x + b.w, bottom: b.y + b.h }));
98
+ const reportRail = reported('action-overflow');
99
+ const reportHits = [];
100
+ for (const offer of reportRail) for (const control of [...reported('act'), ...reported('jump')]) if (overlaps(offer, control)) reportHits.push([offer.name, control.name]);
101
+ const reportStale = reportRail.some(r => Math.abs(r.top - box(document.querySelector('[data-hub="action-rail"]')).top) > 0.5);
102
+ const outside = rail.filter(r => r.left < 0 || r.top < 0 || r.right > innerWidth || r.bottom > innerHeight).map(r => r.name);
103
+ act.dispose?.(); chrome.dispose();
104
+ return { rail, controls, hits, promptHits, outside, reportHits, reportStale, reportRail: reportRail.length };
105
+ }, { setup, OFFERS, PROMPT });
106
+ const label = `${width}x${height}`;
107
+ assert(result.rail.length > 0, `${label}: the rail shows at least one entry`);
108
+ assert.equal(result.controls.length, 2, `${label}: Act and Jump measured`);
109
+ assert.deepEqual(result.hits, [], `${label}: rail clears Act and Jump`);
110
+ assert(result.controls.every(control => control.reachable), `${label}: Act and Jump labels take their own taps`);
111
+ assert(result.reportRail > 0, `${label}: the report lists the rail`);
112
+ assert.deepEqual(result.reportHits, [], `${label}: reported rail clears Act and Jump`);
113
+ assert.equal(result.reportStale, false, `${label}: report matches the drawn rail`);
114
+ assert.deepEqual(result.promptHits, [], `${label}: rail clears the HUD prompt`);
115
+ assert.deepEqual(result.outside, [], `${label}: rail inside the viewport`);
116
+ console.log(`${label}: rail ${result.rail.map(r => `${r.name}@${Math.round(r.left)},${Math.round(r.top)}`).join(' ')}; act/jump clear`);
117
+ }
118
+ } finally { await browser.close(); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.235",
3
+ "version": "0.4.236",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"