castle-web-cli 0.4.255 → 0.4.256

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.
@@ -978,8 +978,8 @@
978
978
  []
979
979
  ]
980
980
  ],
981
- "dom": "23554a25f3dd538d75080f458d2c2d21021ed4f25687d4b383bf34942f90dd3c",
982
- "writes": 1074
981
+ "dom": "ceaf89d63e3d2a1279d7b0085bbfe3e77ebfdf9edaa15c2ccf93ceba15273f88",
982
+ "writes": 1075
983
983
  },
984
984
  "host:portrait": {
985
985
  "record": [
@@ -2942,8 +2942,8 @@
2942
2942
  []
2943
2943
  ]
2944
2944
  ],
2945
- "dom": "0ec95af2826de9e516d3c44de64bbe87f9a77bcfebd94e97a9e66c1b8e4cc605",
2946
- "writes": 1129
2945
+ "dom": "1c760990373ee7c67daad59a423e73793b67312c7f13a0bfec4fe61b7dd601f1",
2946
+ "writes": 1130
2947
2947
  },
2948
2948
  "host:landscape": {
2949
2949
  "record": [
@@ -614,19 +614,29 @@ test('frame wiring only draws in opted-in places and clears once on keyless trav
614
614
  parent: null,
615
615
  matrixWorldAutoUpdate: true,
616
616
  updateMatrixWorld() {
617
- assert(!Object.hasOwn(system, 'crowdFrame'), 'E updates the root camera before capturing shared projection geometry');
617
+ if (scene.data.engine.hubCrowdNames) {
618
+ assert(!Object.hasOwn(system, 'crowdFrame'), 'the root camera updates before capturing shared projection geometry');
619
+ }
618
620
  cameraUpdates += 1;
619
621
  },
620
622
  };
621
623
  scene.three = { camera };
622
624
  scene.data.engine.hubCrowdNames = true;
623
625
  system.afterBehaviors(scene, 0.05);
624
- assert.equal(cameraUpdates, 1, 'E mirrors the renderer root-camera update once');
626
+ assert.equal(cameraUpdates, 1, 'the frame mirrors the renderer root-camera update once');
625
627
  assert.equal(system.crowdFrame.camera, camera, 'the synchronized camera is captured for the late pass');
626
628
  scene.data.engine.hubCrowdNames = false;
627
629
  system.afterBehaviors(scene, 0.05);
628
- assert.equal(cameraUpdates, 1, 'OFF does no camera synchronization work');
630
+ // Ordinary labels also compare depths with names projected in the late pass.
631
+ assert.equal(cameraUpdates, 2, 'OFF synchronizes the camera before projecting world labels too');
629
632
  system.fadeNames(scene);
633
+ camera.parent = {};
634
+ camera.updateWorldMatrix = (...args) => {
635
+ assert.deepEqual(args, [true, false], 'a parented camera updates its ancestors too');
636
+ cameraUpdates += 1;
637
+ };
638
+ system.afterBehaviors(scene, 0.05);
639
+ assert.equal(cameraUpdates, 3, 'the full camera API also synchronizes without crowd names');
630
640
  delete scene.three;
631
641
  hook.state({}, { hubPlace: { id: 'main', title: 'Town', scene: 'scenes/main.scene', result: null } });
632
642
  assert(!Object.hasOwn(State.hub, 'actions'));
@@ -231,7 +231,7 @@ const rows = to => [['p', 'look', to]];
231
231
  const roles = new Map([['p', { label: 'Role', color: '#00ff00' }]]);
232
232
  assert.deepEqual(roleItems(scene, local, {}, {}, roles, project), []);
233
233
  const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
234
- const a = source.indexOf(' markItems(scene, local, cam, view) {'), b = source.indexOf(' measure(', a);
234
+ const a = source.indexOf(' markItems(scene, local, cam, view'), b = source.indexOf(' measure(', a);
235
235
  const marks = Function('Hub', 'disguiseTags', 'project', 'return ({' + source.slice(a, b) + '});');
236
236
  const { disguiseTags } = await import('../code/client/disguise.js');
237
237
  hub.marks = { p: { text: 'Mark' } };
@@ -383,9 +383,9 @@ const tree = (node) => ({ id: node.id, text: node.children.length ? undefined :
383
383
  // The HUD as it is today, written here so a change to the default shows.
384
384
  const COPY = { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '4px 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '0 auto', lineHeight: '1.3', whiteSpace: 'normal', overflowWrap: 'anywhere', overflow: 'hidden', display: 'block' };
385
385
  const TODAY = {
386
- hud: { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)', display: 'block', maxWidth: '70vw' },
386
+ hud: { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', width: 'max-content', textAlign: 'center', textShadow: '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)', display: 'block', maxWidth: '70vw' },
387
387
  title: { ...COPY, fontSize: '13px', maxHeight: '41.8px', letterSpacing: '0.06em', textTransform: 'uppercase' },
388
- big: { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '0 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '4px auto 0', overflowWrap: 'anywhere', fontSize: '56px', fontWeight: '800', lineHeight: '1.05', display: 'block' },
388
+ big: { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '0 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '4px auto 0', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', fontVariantNumeric: 'tabular-nums', fontSize: '56px', fontWeight: '800', lineHeight: '1.05', display: 'block' },
389
389
  text: { ...COPY, position: 'absolute', left: 'max(16px, env(safe-area-inset-left))', right: 'max(16px, env(safe-area-inset-right))', bottom: 'max(54px, calc(env(safe-area-inset-bottom) + 48px))', fontSize: '14px', overflow: 'visible', maxWidth: 'min(60vw, 560px, calc(100vw - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))))', fontWeight: '500', textAlign: 'center', zIndex: '2' },
390
390
  };
391
391
 
@@ -403,10 +403,9 @@ test('never told: the HUD, labels and pointers are styled and placed as today',
403
403
  const top = Object.fromEntries(r.labels.children.map((c) => [c.textContent, c.styles.top]));
404
404
  assert.deepEqual(top, { 'Start here': '90px', 'Take the lantern to the well.': '60px', IT: '80px', Well: '400px', '👋': '138px' });
405
405
  assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['84px', '95px', '500px']);
406
- // Nothing of a clear HUD was written anywhere.
407
- for (const node of [r.hud, r.hudBig]) {
408
- assert.ok(!r.log.some((line) => line.startsWith(`${node.id} `) && /overflow=|maxHeight|webkit|textOverflow|whiteSpace/.test(line)), node.id);
409
- }
406
+ // Numeric nowrap/ellipsis are baseline styles, with no clear-HUD height cap.
407
+ assert.equal(r.hud.styles.maxHeight ?? '', '');
408
+ assert.equal(r.hudBig.styles.maxWidth, '100%');
410
409
  });
411
410
 
412
411
  test('told no: the same writes in the same order as never told', () => {
@@ -582,9 +581,13 @@ test('after a place that asked, a place that does not is drawn as never told', (
582
581
  assert.deepEqual(styleOf(after.hudBig), TODAY.big);
583
582
  assert.deepEqual(styleOf(after.hudText), TODAY.text);
584
583
  assert.deepEqual(styleOf(after.hud), view.viewW > view.viewH ? { ...TODAY.hud, maxWidth: 'min(42vw, 420px)' } : TODAY.hud);
585
- // And after the one frame that put it back, nothing of it is written.
586
- const putBack = after.log.slice(mark).filter((line) => /maxHeight|webkit|textOverflow/.test(line));
587
- assert.equal(putBack.length, 2, 'put back once, in the first frame');
584
+ // Numeric/text changes own their ellipsis styles even without hud.clear.
585
+ // The clear-HUD height cap is restored only once.
586
+ const putBack = after.log.slice(mark).filter((line) => /maxHeight/.test(line));
587
+ assert.equal(putBack.length, 1, 'height cap put back once, in the first frame');
588
+ const restored = after.log.length;
589
+ after.chrome.setHudClear(false);
590
+ assert.equal(after.log.length, restored, 'an already disabled clear HUD writes nothing');
588
591
  }
589
592
  });
590
593
 
@@ -759,7 +762,10 @@ test('asked, then not, with no HUD drawn: put back at once, and written to as ne
759
762
  // root is drawn by a renderer that skips them, and the client never told
760
763
  // still had a HUD up when its later frames began).
761
764
  frames(after, () => undefined, later);
762
- const told = after.log.slice(mark), untold = never.log.slice(neverMark);
765
+ // A restored numeric fit may measure again. Compare mutations here,
766
+ // while placement-cache tests own the read-before-write invariant.
767
+ const told = after.log.slice(mark).filter((line) => !line.endsWith(' read'));
768
+ const untold = never.log.slice(neverMark).filter((line) => !line.endsWith(' read'));
763
769
  let at = 0;
764
770
  for (const line of told) {
765
771
  at = untold.indexOf(line, at);
@@ -15,6 +15,65 @@ try {
15
15
  assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
16
16
  await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
17
17
  });
18
+ await page.setViewportSize({ width: 390, height: 844 });
19
+ await page.goto('http://hud.test/');
20
+ const portrait = await page.evaluate(async () => {
21
+ const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
22
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
23
+ const spec = { title: 'Vault · Deliver your treasures to the team entrance', timer: { since: 0 } };
24
+ const title = document.querySelector('[data-hub-copy="subtitle"]');
25
+ const big = title.nextElementSibling;
26
+ const sample = seconds => {
27
+ chrome.beginLayoutFrame();
28
+ chrome.setHud(spec, seconds, seconds * 1000);
29
+ chrome.endLayoutFrame();
30
+ const line = node => {
31
+ const range = document.createRange();
32
+ range.selectNodeContents(node);
33
+ const style = getComputedStyle(node);
34
+ return { rows: new Set([...range.getClientRects()].map((rect) => Math.round(rect.top))).size, whitespace: style.whiteSpace,
35
+ width: node.clientWidth, scroll: node.scrollWidth, font: parseFloat(style.fontSize), tabular: style.fontVariantNumeric, ellipsis: style.textOverflow, text: node.textContent, height: node.clientHeight, scrollHeight: node.scrollHeight };
36
+ };
37
+ return { text: big.textContent, title: line(title), expectedTitle: spec.title, big: line(big) };
38
+ };
39
+ const normal = sample(83.4);
40
+ spec.title = 'Vault'; // Keep the title short in this artificial clock lane.
41
+ big.parentElement.style.maxWidth = '105px';
42
+ sample(83.5); // This frame detects the width change.
43
+ const narrow = sample(83.6);
44
+ const next = sample(83.7);
45
+ // A clear HUD's title changes must retain the fit through every tick.
46
+ chrome.setHudClear(true);
47
+ const clearA = sample(83.8);
48
+ spec.title = 'Crew';
49
+ const clearB = sample(83.9);
50
+ const clearC = sample(84.0);
51
+ chrome.dispose();
52
+ return { normal, narrow, next, clearA, clearB, clearC };
53
+ });
54
+ for (const result of Object.values(portrait)) {
55
+ assert.equal(result.big.rows, 1);
56
+ assert.equal(result.big.whitespace, 'nowrap');
57
+ assert.equal(result.big.tabular, 'tabular-nums');
58
+ assert(result.big.scroll <= result.big.width, 'the full number fits');
59
+ assert(result.title.rows <= 2, 'title keeps to two rows');
60
+ assert.equal(result.title.text, result.expectedTitle, 'all title words are present');
61
+ assert.equal(result.title.whitespace, 'normal');
62
+ assert.notEqual(result.title.ellipsis, 'ellipsis');
63
+ assert(result.title.scrollHeight <= result.title.height + 1, 'all title words fit in the two rows');
64
+ }
65
+ assert.equal(portrait.normal.text, '83.4');
66
+ assert.equal(portrait.normal.big.font, 56);
67
+ assert(portrait.normal.title.width > 195, 'centered title uses the HUD width cap instead of half the viewport');
68
+ assert(portrait.narrow.big.font < portrait.normal.big.font, 'a constrained clock shrinks');
69
+ assert.equal(portrait.narrow.text, '83.6');
70
+ assert.equal(portrait.next.text, '83.7');
71
+ assert.equal(portrait.next.big.width, portrait.narrow.big.width, 'digit changes keep the same width');
72
+ assert.equal(portrait.clearB.text, '83.9');
73
+ assert.equal(portrait.clearC.text, '84.0');
74
+ assert.equal(portrait.clearB.big.font, portrait.clearA.big.font, 'a title change retains the fitted clock');
75
+ assert.equal(portrait.clearC.big.font, portrait.clearB.big.font, 'the next tick retains the fitted clock');
76
+ console.log('390x844: clock stays on one line and shrinks in a constrained lane');
18
77
  for (const [width, height] of [[412, 870], [844, 390]]) {
19
78
  await page.setViewportSize({ width, height });
20
79
  await page.goto('http://hud.test/');
@@ -3,10 +3,9 @@
3
3
  // scripted sequence below is played through the web chrome on the stand-in
4
4
  // DOM and recorded: every `hud` root the sink is sent (its bytes, rev and sim
5
5
  // time), every time sync, every event handled, and a digest of every DOM
6
- // write. The recording in `fixtures/hud-surface.json` was made from the
7
- // chrome as it was before the HUD state moved out of it; the chrome must
8
- // still produce it byte for byte, and the surface alone (no DOM at all) must
9
- // send the host the same roots. `RECORD=1` writes the recording anew.
6
+ // write. The chrome must match `fixtures/hud-surface.json` byte for byte,
7
+ // and the surface alone (no DOM at all) must send the host the same roots.
8
+ // `RECORD=1` writes the recording anew.
10
9
  import assert from 'node:assert/strict';
11
10
  import { createHash } from 'node:crypto';
12
11
  import { readFileSync, writeFileSync } from 'node:fs';
@@ -268,5 +267,33 @@ if (RECORD) {
268
267
  assert.deepEqual(hudInputs({ hud: null, hudMe: undefined }, 5_000), { spec: null, timer: null });
269
268
  assert.deepEqual(hudInputs({}, 5_000), { spec: undefined, timer: null });
270
269
  passed += 1;
270
+
271
+ const dom = fakeDom({ viewW: 390, viewH: 844 });
272
+ const { makeChrome } = await import('../code/client/chrome.js');
273
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
274
+ const clock = { title: 'Vault', timer: { since: 0 } };
275
+ chrome.setHud(clock, 83.4, 83_400);
276
+ const big = dom.made.find(node => node.textContent === '83.4');
277
+ const title = dom.made.find(node => node.dataset.hubCopy === 'subtitle');
278
+ assert.equal(title.style.whiteSpace, 'normal');
279
+ assert.equal(title.style.textOverflow, '');
280
+ assert.equal(big.style.whiteSpace, 'nowrap');
281
+ assert.equal(big.style.fontVariantNumeric, 'tabular-nums');
282
+ assert.equal(big.style.fontSize, '56px');
283
+ title.parent.style.maxWidth = '105px';
284
+ big.client = 105; big.scroll = 137;
285
+ chrome.setHud(clock, 83.5, 83_500);
286
+ chrome.setHud(clock, 83.6, 83_600);
287
+ assert(Number.parseFloat(big.style.fontSize) < 56);
288
+ const fitted = big.style.fontSize;
289
+ chrome.setHud(clock, 75.3, 75_300);
290
+ assert.equal(big.textContent, '75.3');
291
+ assert.equal(big.style.fontSize, fitted);
292
+ title.parent.style.maxWidth = '70vw';
293
+ big.client = big.scroll;
294
+ chrome.setHud(clock, 75.3, 75_300);
295
+ assert.equal(big.style.fontSize, '56px');
296
+ chrome.dispose();
297
+ passed += 1;
271
298
  console.log(`hud surface: ${passed} checks passed`);
272
299
  }
@@ -496,6 +496,93 @@ assert.deepEqual(hudContents(scene, self, self.components.Transform, 0), { remai
496
496
  chrome.endLayoutFrame(); chrome.dispose();
497
497
  }
498
498
 
499
+ // A numeric fit survives clear-HUD relayouts and clock ticks without first
500
+ // returning to the layout font or reading fresh geometry after writes.
501
+ {
502
+ const dom = fakeDom({ viewW: 390, viewH: 844 });
503
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
504
+ const spec = { title: 'Vault', timer: { since: 0 } };
505
+ chrome.setHud(spec, 83.4, 83_400);
506
+ const big = dom.made.find((node) => node.textContent === '83.4');
507
+ big.parent.style.maxWidth = '105px';
508
+ big.client = 105;
509
+ Object.defineProperty(big, 'scrollWidth', { get() {
510
+ dom.log.push('clock scroll read');
511
+ return Math.max(105, 16 + Number.parseFloat(big.style.fontSize) * 2.3);
512
+ } });
513
+ chrome.setHudClear(true);
514
+ chrome.showBack(true);
515
+ const back = dom.made.find((node) => node.tag === 'button' && node.textContent === '‹ Back');
516
+ const frame = (seconds) => {
517
+ chrome.beginLayoutFrame();
518
+ const start = dom.log.length;
519
+ chrome.setHud(spec, seconds, seconds * 1000);
520
+ const firstWrite = dom.log.findIndex((line, i) => i >= start && line.includes(' style.'));
521
+ assert(!dom.log.slice(firstWrite < 0 ? dom.log.length : firstWrite).some((line) => line.endsWith(' read')));
522
+ chrome.endLayoutFrame();
523
+ };
524
+ frame(83.5);
525
+ frame(83.6);
526
+ const fitted = big.style.fontSize;
527
+ assert(Number.parseFloat(fitted) < 56, 'a clock that advances every frame fits the lane');
528
+ assert(big.scrollWidth <= big.clientWidth, 'the full clock fits');
529
+ for (let i = 0; i < 5; i += 1) {
530
+ spec.title = `Vault ${i}`;
531
+ back.rect = { left: i, right: 70 + i, top: 12, bottom: 50 };
532
+ const start = dom.log.length;
533
+ frame(83.7 + i / 10);
534
+ assert.equal(big.style.fontSize, fitted, 'title/Back changes retain the fitted clock size');
535
+ assert(!dom.log.slice(start).includes(`${big.id} style.fontSize=56px`), 'relayout never resets the fitted font');
536
+ }
537
+ chrome.dispose();
538
+ }
539
+
540
+ // The lane can narrow after the current frame sampled a wider number.
541
+ {
542
+ const dom = fakeDom({ viewW: 390, viewH: 844 });
543
+ const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
544
+ chrome.setEmotes([['wave', '👋']]);
545
+ chrome.setSay({ reactions: [], phrases: [] });
546
+ const emote = dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
547
+ const say = dom.made.find((node) => node.attrs['aria-label'] === 'Quick chat');
548
+ emote.rect = { left: 176, right: 228, top: 45, bottom: 97 };
549
+ say.rect = { left: 121, right: 173, top: 80, bottom: 132 };
550
+ const spec = { title: 'Vault', big: '83.4' };
551
+ chrome.setHud(spec, null);
552
+ const big = dom.made.find((node) => node.textContent === spec.big);
553
+ const hud = big.parent;
554
+ const laneWidth = () => hud.style.maxWidth.endsWith('px') ? parseFloat(hud.style.maxWidth) : 240;
555
+ const numberWidth = () => Math.ceil(16 + parseFloat(big.style.fontSize) * 2.3);
556
+ let hudBottom = 70;
557
+ Object.defineProperty(hud, 'rect', { get() {
558
+ const width = laneWidth();
559
+ return { left: (390 - width) / 2, right: (390 + width) / 2, top: 12, bottom: hudBottom };
560
+ } });
561
+ Object.defineProperties(big, {
562
+ clientWidth: { get: () => Math.min(laneWidth(), numberWidth()) },
563
+ scrollWidth: { get: numberWidth },
564
+ });
565
+ const frame = () => {
566
+ chrome.beginLayoutFrame();
567
+ chrome.setHud(spec, null);
568
+ chrome.endLayoutFrame();
569
+ };
570
+ frame();
571
+ frame();
572
+ assert.equal(hud.style.maxWidth, '160px');
573
+ assert.equal(big.style.fontSize, '56px');
574
+ hudBottom = 110; // The HUD now hits the second control, inside the first lane.
575
+ frame();
576
+ assert.equal(hud.style.maxWidth, '105px');
577
+ frame();
578
+ assert(Number.parseFloat(big.style.fontSize) < 56, 'the next frame fits the narrower lane');
579
+ assert(big.scrollWidth <= big.clientWidth, 'the full number fits after the lane narrows');
580
+ const fitted = big.style.fontSize;
581
+ frame();
582
+ assert.equal(big.style.fontSize, fitted, 'the new fit stays in place');
583
+ chrome.dispose();
584
+ }
585
+
499
586
  // A dock can stay display:flex with an empty box while all its buttons hide.
500
587
  // Showing a descendant must update the dock on N+1, without invalidation.
501
588
  {
@@ -447,7 +447,7 @@ function tagFrameFixture() {
447
447
  const b = source.indexOf(' worldLabelCount = labels.length;', a);
448
448
  const c = source.indexOf(' if (qualityTagItems) {', b);
449
449
  const d = source.indexOf(' labels.push(...this.idle', c);
450
- const m = source.indexOf(' markItems(scene, local, cam, view) {');
450
+ const m = source.indexOf(' markItems(scene, local, cam, view');
451
451
  const markItems = source.slice(m, source.indexOf('\n measure(', m)).trim();
452
452
  assert.ok(a > 0 && b > a && c > b && d > c && m > 0);
453
453
  const project = (_cam, x, y, z) => ({ x: 100 + x * 10, y: 300 - y * 10 + z });
@@ -35,6 +35,7 @@ register(`data:text/javascript,${encodeURIComponent(hooks)}`);
35
35
  const THREE = await import('three');
36
36
  const Avatar = await import('../code/client/avatar.js');
37
37
  const Role = await import('../code/client/role.js');
38
+ const { disguiseTags } = await import('../code/client/disguise.js');
38
39
  const HoldShow = await import('../code/client/holdShow.js');
39
40
  const State = await import('../code/client/state.js');
40
41
  const hooksLayer = (await import('../code/client/hookLayer.js')).default;
@@ -45,6 +46,7 @@ const Hats = await import('./gen-hats.mjs');
45
46
  const { makeChrome } = await import('../code/client/chrome.js');
46
47
  const { fakeDom } = await import('./fixtures/fake-dom.mjs');
47
48
  const { crowdNamesFor, layoutCrowdNames, makeCrowdNames, readableSpriteBox, spriteBox } = await import('../code/client/crowdNames.js');
49
+ const { projectNameTag } = await import('../code/client/nameTagLayout.js');
48
50
  const { placeLabels } = await import('../code/client/padOccupancy.js');
49
51
  const police = { id: 'police', label: 'Police', color: '#22335a', hat: 'police-cap', top: 'vest', tool: 'torch' };
50
52
  const doctor = { id: 'doctor', label: 'Doctor', color: '#42a6c0', hat: 'nurse-cap', top: 'scrubs', tool: 'bag' };
@@ -228,11 +230,79 @@ test('role chip uses final name height and remote name visibility while keeping
228
230
  const nodes = new Map([['role:me', { style: {} }], ['role:p2', { style: {} }], ['mark:p2', { style: {} }]]);
229
231
  const sync = new Function('labelNodes', 'hudClear', 'hudText', `return ({${method}}).syncRoleLabels`)(nodes, false, { style: { display: 'none' } });
230
232
  sync([items[0]]);
231
- assert.equal(nodes.get('role:p2').style.visibility, 'hidden');
233
+ assert.equal(nodes.get('role:p2').style.display, 'none');
232
234
  assert.equal(nodes.get('role:me').style.top, `${items[0].y}px`);
233
235
  assert.deepEqual(nodes.get('mark:p2').style, {});
234
236
  });
235
237
 
238
+ test('IT sits four pixels above a tall, distance-scaled name and follows its opacity', () => {
239
+ const scene = sceneOf();
240
+ const camera = new THREE.PerspectiveCamera(55, 390 / 844, 0.1, 100);
241
+ camera.position.set(0, 5, 9); camera.lookAt(0, 1, 0); camera.updateMatrixWorld();
242
+ const view = { w: 390, h: 844 };
243
+ const project = (cam, x, y, z, { w, h }) => {
244
+ const p = new THREE.Vector3(x, y, z).project(cam);
245
+ return { x: (p.x + 1) * w / 2, y: (1 - p.y) * h / 2 };
246
+ };
247
+ const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ opacity: 0.6 }));
248
+ sprite.position.set(1.6, 4, 0); sprite.scale.set(0.9, 0.45, 1);
249
+ scene.multiplayer.avatars.tags = new Map([['p2', { sprite }]]);
250
+ const source = read('code/systems/hub.js');
251
+ const start = source.indexOf(' markItems(scene, local, cam, view');
252
+ const method = source.slice(start, source.indexOf('\n }\n', start) + 4);
253
+ const hub = { marks: { p2: { text: 'IT', color: '#cc0000' } }, roles: new Map() };
254
+ const marks = new Function('Hub', 'disguiseTags', 'project', `return ({${method}}).markItems`)({ hub }, disguiseTags, project);
255
+ const draw = () => marks(scene, scene.local, camera, view);
256
+ const [item] = draw();
257
+ const name = spriteBox(sprite, camera, view, project);
258
+ assert.ok(Math.abs(item.x - (name.left + name.right) / 2) < 1e-9);
259
+ assert.ok(Math.abs(item.y - (name.top - 4)) < 1e-9);
260
+ assert.equal(item.opacity, 0.6);
261
+ sprite.visible = false;
262
+ assert.deepEqual(draw(), []);
263
+ sprite.visible = true; sprite.material.opacity = 0;
264
+ assert.deepEqual(draw(), []);
265
+
266
+ const methods = source.slice(source.indexOf(' playerNameBox('), source.indexOf(' invalidateCrowdNames('));
267
+ const owner = new Function('Hub', 'projectNameTag', `return new (class {${methods}})()`)({ hub }, projectNameTag);
268
+ scene.three.camera = camera; scene.actorWith = () => scene.local;
269
+ owner.nameTagFrame = { scene, view, idle: true };
270
+ owner.markItems = marks;
271
+ let chips, boxes;
272
+ owner.chrome = { syncRoleLabels: (items) => {chips = items;}, setWorldNameTags: (tags) => {boxes = tags;} };
273
+ sprite.material.opacity = 0.6;
274
+ sprite.position.set(0.99, 0, 0.97).unproject(camera);
275
+ owner.finishNameLabels(scene);
276
+ const clamped = boxes.get('p2');
277
+ assert.ok(clamped.right <= view.w - 8 + 1e-9, 'the late pass clamps the name before positioning the mark');
278
+ assert.ok(Math.abs(chips[0].x - (clamped.left + clamped.right) / 2) < 1e-9);
279
+ assert.ok(Math.abs(chips[0].y - (clamped.top - 4)) < 1e-9);
280
+ scene.multiplayer.avatars.tags.clear();
281
+ assert.equal(draw()[0].y, project(camera, 2, 2.95, 0, view).y);
282
+
283
+ // The viewer's own mark sits where its hidden name is drawn: over this
284
+ // frame's body at the own-tag height, sized by the own sprite. A sprite
285
+ // multiplayer stopped placing does not move it; with no sprite at all it
286
+ // still sits at the name's height, not 1.95 m up.
287
+ hub.marks = { me: { text: 'IT', color: '#cc0000' } };
288
+ const own = new THREE.Sprite(new THREE.SpriteMaterial());
289
+ own.visible = false;
290
+ own.position.set(0, 2.25, 0); own.scale.set(0.9, 0.45, 1);
291
+ scene.multiplayer.avatars.tags.set('self', { sprite: own });
292
+ const ownName = spriteBox(own, camera, view, project);
293
+ const [mine] = draw();
294
+ assert.equal(mine.id, 'mark:me');
295
+ assert.ok(Math.abs(mine.x - (ownName.left + ownName.right) / 2) < 1e-9);
296
+ assert.ok(Math.abs(mine.y - (ownName.top - 4)) < 1e-9);
297
+ assert.equal(mine.opacity, 1);
298
+ assert.ok(mine.y > project(camera, 0, 2.95, 0, view).y, 'lower than the old fixed 1.95 m');
299
+ own.position.set(5, 7, 0);
300
+ assert.deepEqual(draw()[0], mine, 'a stale own sprite does not move the mark');
301
+ assert.deepEqual(marks(scene, scene.local, camera, view, false)[0], mine, 'the early pass agrees with the late one');
302
+ scene.multiplayer.avatars.tags.delete('self');
303
+ assert.ok(Math.abs(draw()[0].y - (project(camera, 0, 2.25, 0, view).y - 4)) < 1e-9);
304
+ });
305
+
236
306
  test('role chips may overlap the viewer body but still clear HUD and controls; ordinary labels yield', () => {
237
307
  for (const focused of [true, false]) {
238
308
  const dom = fakeDom({ viewW: 574, viewH: 246 });
@@ -366,7 +436,7 @@ test('crowd selection reanchors roles after name resizing and excludes only thei
366
436
  const deps = { Hub: { hub: State.hub }, AvatarCap: { shown: () => 1 }, roleItems: Role.roleItems,
367
437
  project, crowdNamesFor, layoutCrowdNames, readableSpriteBox, spriteBox, placeLabels, sceneKeyOf: () => 'main' };
368
438
  const layout = new Function(...Object.keys(deps), `return ({${method}}).layoutCrowdNames`)(...Object.values(deps));
369
- const system = { chrome, crowdNamesReady: () => true, friendsAll: null,
439
+ const system = { chrome, crowdNamesReady: () => true, playerNameBox: () => null, friendsAll: null,
370
440
  crowdFrame: { view, controls: [], local: scene.local.components.Transform } };
371
441
  const labelBoxes = chrome.crowdNameLabelBoxes.bind(chrome);
372
442
  chrome.crowdNameLabelBoxes = () => {
@@ -378,14 +448,20 @@ test('crowd selection reanchors roles after name resizing and excludes only thei
378
448
  assert.equal(sprite.visible, true, 'role chip never suppresses its name');
379
449
  assert.notEqual(chip.style.visibility, 'hidden');
380
450
  const ownBox = labelBoxes()[0];
381
- assert.equal(ownBox.rolePlayerId, 'p2');
451
+ assert.equal(ownBox.tagPlayerId, 'p2');
382
452
  const candidate = { id: 'p2', distance: 1, at: { x: 2, z: 0 }, box: ownBox };
383
453
  const state = makeCrowdNames();
384
- const run = (now, rolePlayerId) => layoutCrowdNames(state, [candidate], { now, view, obstacles: [{ ...ownBox, rolePlayerId }] });
454
+ const run = (now, tagPlayerId) => layoutCrowdNames(state, [candidate], { now, view, obstacles: [{ ...ownBox, tagPlayerId }] });
385
455
  assert.ok(run(0, 'p2').visible.has('p2'), 'own chip is exempt even when clearance overlaps its name');
386
456
  assert.equal(run(1, 'other').visible.size, 0, 'other players chips remain obstacles');
387
457
  assert.equal(run(2, 'p2').visible.size, 0);
388
458
  assert.ok(run(252, 'p2').visible.has('p2'), 'own chip cannot prevent hysteresis restoration');
459
+ chrome.setLabels([{ id: 'mark:p2', text: 'IT', x: 220, y: 299, color: '#cc0000' }]);
460
+ dom.made.find((node) => node.textContent === 'IT').rect = ownBox;
461
+ assert.equal(labelBoxes.call(chrome)[0].tagPlayerId, 'p2', 'IT has the same crowd clearance exemption as a role');
462
+ candidate.box = { ...candidate.box, depth: 0.6 };
463
+ const sign = { ...candidate.box, tagPlayerId: undefined, depth: 0.8 };
464
+ assert.ok(layoutCrowdNames(state, [candidate], { now: 253, view, obstacles: [sign] }).visible.has('p2'), 'a farther sign yields to the name');
389
465
  chrome.dispose(); State.clear();
390
466
  });
391
467
  test('a chip whose name the crowd pass rejects stays hidden after the summary flush', () => {
@@ -411,7 +487,7 @@ test('a chip whose name the crowd pass rejects stays hidden after the summary fl
411
487
  project, crowdNamesFor, layoutCrowdNames, readableSpriteBox, spriteBox, placeLabels, sceneKeyOf: () => 'main' };
412
488
  const layout = new Function(...Object.keys(deps), `return ({${method}}).layoutCrowdNames`)(...Object.values(deps));
413
489
  // A control over the whole view rejects every name.
414
- const system = { chrome, crowdNamesReady: () => true, friendsAll: null,
490
+ const system = { chrome, crowdNamesReady: () => true, playerNameBox: () => null, friendsAll: null,
415
491
  crowdFrame: { view, controls: [{ left: 0, right: 400, top: 0, bottom: 800 }], local: scene.local.components.Transform } };
416
492
  // The summary's world-layout flush restores labels layout hid, so the
417
493
  // late role pass (position false) must come after it.
@@ -422,7 +498,7 @@ test('a chip whose name the crowd pass rejects stays hidden after the summary fl
422
498
  layout.call(system, scene, 0);
423
499
  assert.equal(sprite.visible, false, 'the name was rejected');
424
500
  assert.deepEqual(order, ['roles', 'summary', 'roles-late']);
425
- assert.equal(chip.style.visibility, 'hidden', 'its role chip is hidden with it, after the summary flush');
501
+ assert.equal(chip.style.display, 'none', 'its role chip is hidden with it, after the summary flush');
426
502
  chrome.dispose(); State.clear();
427
503
  });
428
504
  console.log(`test-role-client: ${n} passed`);
@@ -20,6 +20,9 @@
20
20
  // it rides above the keyboard on every renderer (as the text ask's and
21
21
  // quick chat's cards do), not only where the view's inset holds the
22
22
  // keyboard. Nothing else in a root moves, and the DOM writes are unchanged.
23
+ // A third: the HUD column is drawn as wide as its content (a clock's
24
+ // number stays on one line), one more style write in each DOM run; the
25
+ // talk roots are unchanged.
23
26
  // `RECORD=1` writes the recording anew.
24
27
  import assert from 'node:assert/strict';
25
28
  import { createHash } from 'node:crypto';
@@ -5,6 +5,8 @@ import { pathToFileURL } from 'node:url';
5
5
  import { makeNear } from '../code/client/labelsNear.js';
6
6
  import { relevantLabels, worldPlacement, makeWorldLayout, worldLabelFocus, mapWorldPoint, offsetWorldPoint } from '../code/client/worldLabels.js';
7
7
  import { makeLayoutCache } from '../code/client/layoutCache.js';
8
+ import { nameTagShift, projectNameTag } from '../code/client/nameTagLayout.js';
9
+ import { PerspectiveCamera, Sprite, Vector3 } from 'three';
8
10
 
9
11
  assert.equal(worldLabelFocus(true, false, false), false, 'explicit near town unchanged');
10
12
  assert.equal(worldLabelFocus(true, true, true), true, 'host town policy does not exempt games');
@@ -46,6 +48,43 @@ assert.equal(worldLabelFocus(false, false, false), true, 'keyless standalone pla
46
48
  }
47
49
 
48
50
  const box = (left, top, w = 100, h = 26) => ({ left, top, right: left + w, bottom: top + h });
51
+ {
52
+ const area = { ...box(15, 20, 360, 800), width: 360, height: 800 };
53
+ assert.equal(nameTagShift(box(-10, 200, 80), area), 33);
54
+ assert.equal(nameTagShift(box(330, 200, 80), area), -43);
55
+ assert.equal(nameTagShift(box(50, 200, 80), area), 0);
56
+ assert.equal(nameTagShift(box(-35, 200, 80), area), 58, 'a cut name whose centre is past the left edge slides in');
57
+ assert.equal(nameTagShift(box(370, 200, 80), area), -83, 'and past the right edge');
58
+ assert.equal(nameTagShift(box(-65, 200, 80), area), 0, 'a name wholly left of the view stays out');
59
+ assert.equal(nameTagShift(box(375, 200, 80), area), 0, 'a name wholly right of the view stays out');
60
+ assert.equal(nameTagShift(box(-10, -20, 80), area), 0, 'top anchor off screen');
61
+ assert.equal(nameTagShift(box(-5, 200, 400), area), 0, 'a tag wider than the view cannot fit');
62
+
63
+ const cam = new PerspectiveCamera(55, area.width / area.height, 0.1, 100);
64
+ cam.position.set(1, 4, 10); cam.lookAt(0, 0, 0); cam.updateMatrixWorld();
65
+ const tag = new Sprite();
66
+ tag.scale.set(1, 0.4, 1);
67
+ tag.position.set(-0.98, 0, 0.97).unproject(cam);
68
+ const anchor = tag.position.clone().project(cam);
69
+ const projected = projectNameTag(tag, cam, area, new Vector3(), {});
70
+ const moved = tag.position.clone().project(cam);
71
+ assert(Math.abs(projected.left - (area.left + 8)) < 1e-10);
72
+ assert(moved.x > anchor.x);
73
+ assert(Math.abs(moved.z - anchor.z) < 1e-10, 'clamp preserves camera depth');
74
+ assert(Math.abs(moved.y - anchor.y) < 1e-10, 'clamp moves only along camera right');
75
+ // Centre just past the left edge, part of the name still in view: slides in.
76
+ tag.position.set(-1.02, 0, 0.97).unproject(cam);
77
+ assert(Math.abs(projectNameTag(tag, cam, area, new Vector3(), {}).left - (area.left + 8)) < 1e-9);
78
+ // Wholly outside the view: left where it is.
79
+ tag.position.set(-2, 0, 0.97).unproject(cam);
80
+ const offscreen = tag.position.clone();
81
+ assert(projectNameTag(tag, cam, area, new Vector3(), {}).right < area.left);
82
+ assert(tag.position.equals(offscreen));
83
+ tag.position.set(0, 0, 1).applyMatrix4(cam.matrixWorld);
84
+ const behind = tag.position.clone();
85
+ assert.equal(projectNameTag(tag, cam, area, new Vector3(), {}), null);
86
+ assert(tag.position.equals(behind));
87
+ }
49
88
  for (const view of [{ w: 844, h: 390 }, { w: 1440, h: 900 }]) {
50
89
  const items = Array.from({ length: 20 }, (_, i) => ({ id: `tag${i}`, d: i + 1, box: box(200 + i * 110, 200) }));
51
90
  const state = makeNear();
@@ -83,6 +122,48 @@ assert.equal(label.style.visibility, '', 'label returns when pointer leaves');
83
122
  layout.begin();
84
123
  console.log('world labels: bounded nearest tags, objective precedence, HUD/columns/corners, collision collapse and frame restoration passed');
85
124
 
125
+ {
126
+ const view = { w: 390, h: 844 };
127
+ const names = new Map([['p2', { ...box(110, 240, 100, 24), depth: 0.8 }]]);
128
+ const caption = { ...box(130, 246, 80, 30), depth: 0.9 };
129
+ assert.deepEqual(worldPlacement([], [caption], [], view, [], names).labels, [null]);
130
+ const nearer = { ...caption, depth: 0.7 };
131
+ assert.deepEqual(worldPlacement([], [nearer], [], view, [], names).labels, [nearer]);
132
+ const mark = { ...box(135, 208, 50, 28), tagPlayerId: 'p2' };
133
+ const role = { ...box(128, 268, 64, 28), tagPlayerId: 'p2' };
134
+ for (const chip of [mark, role]) {
135
+ const sign = { ...chip, tagPlayerId: undefined, depth: 0.9 };
136
+ assert.deepEqual(worldPlacement([], [sign, chip], [], view, [], names).labels, [null, chip], 'the anchored chip wins against a farther sign');
137
+ const blocked = worldPlacement([], [sign, chip], [box(135, chip.top - 10, 10, 20)], view, [], names);
138
+ assert.deepEqual(blocked.labels, [null, null], 'controls still have priority');
139
+ }
140
+ // The viewer's own mark under a turned phone's HUD steps down just clear of
141
+ // it, over its own body if need be, rather than vanishing; another
142
+ // player's mark there is still dropped, and no step lands on a control.
143
+ {
144
+ const turned = { w: 844, h: 390 };
145
+ const hud = box(282, 12, 280, 88);
146
+ const body = box(390, 160, 70, 120);
147
+ const own = { ...box(403, 91, 38, 30), drop: true, ignoreObstacle: body, tagPlayerId: 'me' };
148
+ assert.deepEqual(worldPlacement([], [own], [hud, body], turned).labels, [box(403, 104, 38, 30)]);
149
+ assert.deepEqual(worldPlacement([], [{ ...own, drop: undefined }], [hud, body], turned).labels, [null], 'another mark is dropped as before');
150
+ const lower = box(380, 100, 80, 40);
151
+ assert.deepEqual(worldPlacement([], [own], [hud, lower, body], turned).labels, [box(403, 144, 38, 30)], 'steps past each control in turn');
152
+ assert.deepEqual(worldPlacement([], [own], [hud, box(0, 100, 844, 290)], turned).labels, [null], 'nothing clear below');
153
+ assert.deepEqual(worldPlacement([], [{ ...own, top: -40, bottom: -10 }], [], turned).labels, [box(403, 6, 38, 30)], 'above the view it comes down onto it');
154
+ }
155
+ const slidesIntoName = { ...box(-8, 248, 48, 22), depth: 0.9, clamp: true };
156
+ const clipped = node(slidesIntoName);
157
+ const tagAtEdge = new Map([['p2', { ...box(41, 240, 20, 24), depth: 0.8 }]]);
158
+ const pass = makeWorldLayout(() => [{ kind: 'label', node: clipped, depth: slidesIntoName.depth, clamp: true }],
159
+ () => view, undefined, undefined, undefined, () => tagAtEdge);
160
+ pass.flush();
161
+ assert.equal(clipped.style.visibility, 'hidden', 'depth uses the final box after sliding');
162
+ tagAtEdge.clear();
163
+ pass.flush();
164
+ assert.equal(clipped.style.visibility, '', 'a hidden name no longer occludes');
165
+ }
166
+
86
167
  // Caption reflow is a deliberate late measurement. It survives the deferred
87
168
  // reset, and restoring its width invalidates a snapshot taken while narrowed.
88
169
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.255",
3
+ "version": "0.4.256",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"