castle-web-cli 0.4.237 → 0.4.238

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.
Files changed (216) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +78 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/init.js +2 -1
  15. package/dist/save-deck.js +4 -0
  16. package/kits/base/castle.json +1 -1
  17. package/kits/base/sdk/README.md +47 -0
  18. package/kits/base/sdk/castle.d.ts +3 -1
  19. package/kits/base/sdk/castle.js +1 -0
  20. package/kits/base/sdk/commands.d.ts +25 -1
  21. package/kits/base/sdk/commands.js +29 -1
  22. package/kits/base/sdk/hub.d.ts +17 -0
  23. package/kits/base/sdk/hub.js +33 -9
  24. package/kits/base/sdk/localCache.d.ts +27 -0
  25. package/kits/base/sdk/localCache.js +115 -0
  26. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  27. package/kits/base/sdk/localCacheStore.js +358 -0
  28. package/kits/base/sdk/transport.d.ts +1 -0
  29. package/kits/base/sdk/transport.js +4 -5
  30. package/kits/hub-game/CLAUDE.md +22 -2
  31. package/kits/hub-game/castle.json +4 -1
  32. package/kits/hub-game/code/client/act.js +66 -91
  33. package/kits/hub-game/code/client/actCore.js +134 -0
  34. package/kits/hub-game/code/client/car.js +35 -0
  35. package/kits/hub-game/code/client/chrome.js +207 -381
  36. package/kits/hub-game/code/client/crowdNames.js +2 -2
  37. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  38. package/kits/hub-game/code/client/hats.js +2 -0
  39. package/kits/hub-game/code/client/hookLayer.js +99 -48
  40. package/kits/hub-game/code/client/hostGo.js +77 -0
  41. package/kits/hub-game/code/client/hubControls.js +125 -0
  42. package/kits/hub-game/code/client/hubEntry.js +187 -0
  43. package/kits/hub-game/code/client/hudSurface.js +148 -0
  44. package/kits/hub-game/code/client/hudTree.js +96 -0
  45. package/kits/hub-game/code/client/idle.js +59 -13
  46. package/kits/hub-game/code/client/invites.js +13 -4
  47. package/kits/hub-game/code/client/menuIcons.js +8 -0
  48. package/kits/hub-game/code/client/noTrips.js +38 -0
  49. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  50. package/kits/hub-game/code/client/rehello.js +3 -1
  51. package/kits/hub-game/code/client/riders.js +26 -0
  52. package/kits/hub-game/code/client/role.js +79 -0
  53. package/kits/hub-game/code/client/safeLayout.js +32 -3
  54. package/kits/hub-game/code/client/sound.js +10 -3
  55. package/kits/hub-game/code/client/soundscape.js +2 -2
  56. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  57. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  58. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  59. package/kits/hub-game/code/client/state.js +19 -0
  60. package/kits/hub-game/code/client/stuck.js +2 -1
  61. package/kits/hub-game/code/client/talkSurface.js +178 -0
  62. package/kits/hub-game/code/client/talkTree.js +238 -0
  63. package/kits/hub-game/code/client/tiers.js +8 -5
  64. package/kits/hub-game/code/client/uiDom.js +600 -0
  65. package/kits/hub-game/code/client/uiTree.js +359 -0
  66. package/kits/hub-game/code/client/vehicle.js +154 -0
  67. package/kits/hub-game/code/client/wear.js +27 -5
  68. package/kits/hub-game/code/client/worldLabels.js +3 -2
  69. package/kits/hub-game/code/client/yours.js +10 -3
  70. package/kits/hub-game/code/server/actors.js +4 -3
  71. package/kits/hub-game/code/server/analytics.js +56 -6
  72. package/kits/hub-game/code/server/decor.js +56 -16
  73. package/kits/hub-game/code/server/hub.js +258 -46
  74. package/kits/hub-game/code/server/idle.js +118 -5
  75. package/kits/hub-game/code/server/manifest.js +46 -4
  76. package/kits/hub-game/code/server/npcs.js +4 -2
  77. package/kits/hub-game/code/server/players.js +3 -0
  78. package/kits/hub-game/code/server/role.js +142 -0
  79. package/kits/hub-game/code/server/standing.js +6 -4
  80. package/kits/hub-game/code/server/vehicle.js +126 -0
  81. package/kits/hub-game/code/shared/car.js +52 -0
  82. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  83. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  84. package/kits/hub-game/code/shared/expression.js +9 -0
  85. package/kits/hub-game/code/systems/hub.js +272 -84
  86. package/kits/hub-game/docs/analytics.md +11 -2
  87. package/kits/hub-game/docs/contract.md +352 -14
  88. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  89. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  90. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  91. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  92. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  93. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  94. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  95. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  96. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  97. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  98. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  99. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  100. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  101. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  102. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  103. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  104. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  105. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  106. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  107. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  108. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  109. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  110. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  111. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  112. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  113. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  114. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  115. package/kits/hub-game/package-lock.json +1 -1
  116. package/kits/hub-game/package.json +1 -1
  117. package/kits/hub-game/scripts/check.mjs +7 -4
  118. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  119. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  120. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  121. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  122. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  123. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  124. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  125. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  126. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  127. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  128. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  129. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  130. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  131. package/kits/hub-game/scripts/test-car.mjs +43 -0
  132. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  133. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  134. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  135. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  136. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  137. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  138. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  139. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  140. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  141. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  142. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  143. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  144. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  145. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  146. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  147. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  148. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  149. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  150. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  151. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  152. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  153. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  154. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  155. package/kits/hub-game/scripts/test-role.mjs +350 -0
  156. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  157. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  158. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  159. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  160. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  161. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  162. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  163. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  164. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  165. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  166. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  167. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  168. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  169. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  170. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  171. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  172. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  173. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  174. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  175. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  176. package/kits/multiplayer-3d/castle.json +4 -4
  177. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  178. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  179. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  180. package/kits/multiplayer-3d/package-lock.json +1 -1
  181. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  182. package/kits/physics-3d/CLAUDE.md +1 -1
  183. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  184. package/kits/physics-3d/castle.json +2 -2
  185. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  186. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  187. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  188. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  189. package/kits/physics-3d/engine3d/world3d.js +6 -3
  190. package/kits/physics-3d/package.json +1 -1
  191. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  192. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  193. package/kits/physics-3d/systems/physics3d.js +5 -2
  194. package/kits/real-time/castle.json +2 -2
  195. package/kits/real-time/code/client/messages.js +5 -0
  196. package/kits/real-time/code/server/session.js +28 -1
  197. package/kits/real-time/package-lock.json +1 -1
  198. package/package.json +5 -4
  199. package/vendor/three/LICENSE +21 -0
  200. package/vendor/three/build/three.core.js +58773 -0
  201. package/vendor/three/build/three.module.js +18251 -0
  202. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  203. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  204. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  205. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  206. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  207. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  208. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  209. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  210. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  211. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  212. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  213. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  214. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  215. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  216. package/vendor/three/package.json +134 -0
@@ -1,4 +1,4 @@
1
- import { HUD_COPY_STYLE, firstPromptSentence, promptShift, warnHudCopy } from './hudCopy.js';
1
+ import { promptShift, warnHudCopy } from './hudCopy.js';
2
2
  // The hub's own chrome: DOM drawn by the place, never by a game's content, so a
3
3
  // game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
4
4
  // Back control, the declared HUD, actor labels and speech, the result ribbon,
@@ -31,8 +31,13 @@ import { landscapeViewport, watchViewport } from './landscapeLayout.js';
31
31
  import { loadingCover } from './loadingCover.js';
32
32
 
33
33
  import { makeSafeLayout } from './safeLayout.js';
34
+ import { makeEmoteWheel } from './emoteWheel.js';
34
35
  import { makeWorldLayout } from './worldLabels.js';
35
36
  import { makeLayoutCache, placementCache } from './layoutCache.js';
37
+ import { BARE_TEXT_SHADOW, publishUiRoot, uiTreeDomEnabled } from './uiTree.js';
38
+ import { mountUiTree } from './uiDom.js';
39
+ import { makeHudSurface } from './hudSurface.js';
40
+ import { makeTalkSurface } from './talkSurface.js';
36
41
 
37
42
  export { landscapeViewport } from './landscapeLayout.js';
38
43
 
@@ -45,19 +50,11 @@ function createElement(tag, style, parent = document.body) {
45
50
  return node;
46
51
  }
47
52
 
48
- // White text drawn straight over the world (the HUD, the feed): an outline
49
- // close around each letter as well as the soft drop shadow, so it reads over a
50
- // pale sky as it does over a dark street.
51
- const BARE_TEXT_SHADOW = '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)';
52
-
53
53
  // The character picker's grid: four cells across, each a tap target this wide
54
54
  // (and 62 px tall).
55
55
  const PICKER_COLUMNS = 4;
56
56
  const PICKER_CELL_PX = 64;
57
57
 
58
- // The talk panel's log counts as at its end within this many pixels of it.
59
- const TALK_END_PX = 8;
60
-
61
58
  export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onHeart = () => {}, onLeaveParty = () => {}, onReportChat = () => {}, onBlockChat = () => {}, onChip, safeInsets = false, worldLabelsDefault = false }) {
62
59
  const geometry = makeLayoutCache();
63
60
  const placeActions = placementCache();
@@ -104,23 +101,39 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
104
101
 
105
102
  let coverLine = null;
106
103
 
107
- const back = el('button', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: edge('left', 12), pointerEvents: 'auto', padding: '9px 16px 9px 12px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.35)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
108
- back.textContent = '‹ Town';
109
- back.addEventListener('pointerdown', (event) => {
110
- event.stopPropagation();
111
- onBack();
104
+ // The HUD root (`hudTree.js`): Back, the HUD's title and big line, the
105
+ // prompt pill and the toast. Its state and API are the HUD surface's
106
+ // (`hudSurface.js`, no DOM); each root it builds is drawn here by the UI
107
+ // tree's DOM renderer, and a native host takes the same tree from the sink
108
+ // (`uiTree.js`). Its nodes are made now, hidden, so they keep their place
109
+ // among the chrome's layers; the toast is moved over the ribbon below.
110
+ let hudSurface = null;
111
+ const hudDom = mountUiTree(root, {
112
+ // The page reads the HUD clock at the sim time of the last `setHud`.
113
+ clockNow: () => hudSurface.clockNow(),
114
+ // The Act/Jump pair is drawn by `act.js` in its own layer.
115
+ slots: { actpair: null },
116
+ created(path, node) {
117
+ if (path === 'hud/hud/big') {geometry.register(node, { fit: true });}
118
+ else if (path.split('/').length === 2) {geometry.register(node, { positioned: false });}
119
+ },
120
+ removed: (path, node) => geometry.unregister(node),
112
121
  });
113
-
114
- const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: BARE_TEXT_SHADOW, display: 'none', maxWidth: '70vw' }, root);
115
- const hudTitle = el('div', { ...HUD_COPY_STYLE, fontSize: '13px', maxHeight: '41.8px', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
116
- const hudBig = el('div', { background: HUD_COPY_STYLE.background, 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' }, hud);
117
- const hudText = el('div', { ...HUD_COPY_STYLE, 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', display: 'none', zIndex: '2' }, root);
118
- hudText.dataset.hub = 'hud-prompt';
119
- geometry.register(hudBig, { fit: true });
120
- let hudPromptAsked = false;
121
-
122
- hudTitle.dataset.hubCopy = 'subtitle';
123
- hudText.dataset.hubCopy = 'instruction';
122
+ hudSurface = makeHudSurface({
123
+ landscape: landscapeViewport(),
124
+ safeInsets,
125
+ onBack: () => onBack(),
126
+ // The doors list, or a talk panel's questions, sit over the prompt.
127
+ promptBlocked: () => doorsOpen || Boolean(talkOpen && talkSurface.state.asks),
128
+ draw(tree) {
129
+ if (uiTreeDomEnabled() || !hudDom.nodeFor('hud/back')) {hudDom.render(tree);}
130
+ },
131
+ });
132
+ const back = hudDom.nodeFor('hud/back');
133
+ const hud = hudDom.nodeFor('hud/hud');
134
+ const hudTitle = hudDom.nodeFor('hud/hud/title');
135
+ const hudBig = hudDom.nodeFor('hud/hud/big');
136
+ const hudText = hudDom.nodeFor('hud/prompt');
124
137
 
125
138
  const labels = el('div', { position: 'absolute', inset: '0' }, root);
126
139
  positionLayers.add(labels);
@@ -236,13 +249,13 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
236
249
 
237
250
  const ribbon = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '6px', background: 'linear-gradient(#f2c94c, #d69e2e)', color: '#3b2600', fontSize: '13px', fontWeight: '800', whiteSpace: 'nowrap', boxShadow: '0 2px 6px rgba(0,0,0,0.4)' }, root);
238
251
 
239
- const toast = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', width: 'max-content', maxWidth: 'calc(100vw - 24px)', boxSizing: 'border-box', textAlign: 'center', padding: '8px 14px', borderRadius: '8px', background: 'rgba(20,16,12,0.8)', fontSize: '14px', display: 'none' }, root);
240
- toast.dataset.hub = 'toast';
252
+ // The HUD root's toast, drawn over the ribbon (its layer was always here).
253
+ const toast = hudDom.nodeFor('hud/toast');
254
+ root.insertBefore(toast, null);
241
255
  // Where a phone's toast starts, read in pixels: the safe area's inset has
242
256
  // no other way to be measured.
243
257
  const toastStart = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
244
258
  const actionBottom = el('div', { position: 'absolute', bottom: 'max(132px, calc(env(safe-area-inset-bottom) + 122px))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
245
- let toastWrap = null;
246
259
  let toastChoiceBlocked = false;
247
260
  function syncToastVisibility() {
248
261
  const visibility = toastChoiceBlocked || pickerOpen ? 'hidden' : '';
@@ -285,7 +298,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
285
298
  if (companionLock && companionLockVisibility !== null) {companionLock.style.visibility = companionLockVisibility;}
286
299
  companionLockVisibility = null;
287
300
  }
288
- let pickerFitKey = '';
301
+ let pickerFitKey = '', pickerCompact = false;
289
302
  // The card is a sheet fitted to the viewport: over the right-side lane above
290
303
  // the button, or, on a phone on its side with no room there for the whole
291
304
  // sheet, one strip of whole tiles along the bottom with its own Close. Open,
@@ -301,6 +314,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
301
314
  layPicker(compact);
302
315
  }
303
316
  function layPicker(compact) {
317
+ pickerCompact = compact;
304
318
  Object.assign(pickerCard.style, {
305
319
  position: 'fixed', right: compact ? 'auto' : '10px', left: compact ? '50%' : '', transform: compact ? 'translateX(-50%)' : '', bottom: compact ? 'max(12px, env(safe-area-inset-bottom))' : `max(${64 + lockLift}px, calc(env(safe-area-inset-bottom) + ${64 + lockLift}px))`, flexShrink: '0',
306
320
  });
@@ -455,69 +469,32 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
455
469
 
456
470
  // Talking to an NPC: a button when one is near, and a panel while a
457
471
  // conversation is open. Keys typed here are the panel's, not the game's.
458
- let talkHandlers = { open() {}, send() {}, end() {} };
459
472
  const talkButton = el('button', { position: 'absolute', bottom: 'max(64px, calc(env(safe-area-inset-bottom) + 54px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 18px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
460
473
  overPicker.push(talkButton);
461
474
  talkButton.addEventListener('pointerdown', (event) => {
462
475
  event.stopPropagation();
463
- talkHandlers.open();
476
+ talkSurface.requestOpen();
464
477
  });
465
- const panel = el('div', { position: 'absolute', left: '50%', bottom: 'max(12px, env(safe-area-inset-bottom))', transform: 'translateX(-50%)', width: 'min(92vw, 420px)', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
466
- const panelHead = el('div', { display: 'flex', alignItems: 'baseline', gap: '8px' }, panel);
467
- const panelName = el('div', { fontWeight: '700', flex: '1' }, panelHead);
468
- const panelEnd = el('button', { pointerEvents: 'auto', padding: '4px 10px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.35)', background: 'transparent', color: '#fff', font: '600 13px system-ui, sans-serif', cursor: 'pointer' }, panelHead);
469
- panelEnd.textContent = 'Done';
470
- panelEnd.addEventListener('pointerdown', (event) => {
471
- event.stopPropagation();
472
- talkHandlers.end();
478
+ // The talk panel: the talk root (`talkTree.js`). Its state and the talk
479
+ // API are the talk surface's (`talkSurface.js`, no DOM); each root it
480
+ // builds is drawn here by the UI tree's DOM renderer, the way the panel was
481
+ // drawn by hand. Keys typed in its field are the panel's, not the game's
482
+ // (the renderer stops them). It is made now, hidden, so it keeps its layer.
483
+ let talkOpen = false;
484
+ // A desktop keyboard (a fine pointer and no touch) gets the field focused
485
+ // as it appears; a phone keeps its keyboard down until a tap.
486
+ const autoFocusField = () => Boolean(globalThis.matchMedia?.('(pointer: fine)').matches && !(globalThis.navigator?.maxTouchPoints > 0));
487
+ const talkDom = mountUiTree(root, {
488
+ measure: geometry,
489
+ created(path, node) {
490
+ if (path === 'talk/panel/log') {geometry.register(node, { scroll: true });}
491
+ else if (path === 'talk/panel' || path === 'talk/panel/asks' || path.startsWith('talk/panel/log/l')) {geometry.register(node);}
492
+ },
493
+ removed: (path, node) => geometry.unregister(node),
473
494
  });
474
- const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
475
- geometry.register(panelLog, { scroll: true });
476
- // v1.46: the mind is answering; reduced motion keeps a plain ellipsis.
477
- const typingStyle = el('style', {}, root);
478
- typingStyle.textContent = `
479
- @keyframes hub-npc-dot { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
480
- .hub-npc-typing span { animation: hub-npc-dot 1.2s infinite; }
481
- .hub-npc-typing span:nth-child(2) { animation-delay: .2s; }
482
- .hub-npc-typing span:nth-child(3) { animation-delay: .4s; }
483
- @media (prefers-reduced-motion: reduce) {
484
- .hub-npc-typing span { animation: none; display: none; }
485
- .hub-npc-typing::after { content: '…'; }
486
- }
487
- `;
488
- let panelTyping = null;
489
- let panelMind = false;
490
- let panelOpening = null;
491
- // An under-13 speaker's line under the opening of a mind they cannot type
492
- // to, made only while there is one, like the questions.
493
- let panelHint = null;
494
- const dropHint = () => {
495
- panelHint?.remove();
496
- panelHint = null;
497
- };
498
- const dropTyping = () => {
499
- panelTyping?.remove();
500
- panelTyping = null;
501
- };
502
- // The questions are made only while there are some to offer.
503
- let panelAsks = null;
504
- let panelChildAsks = false;
505
- let asksHandler = null;
506
- // The row is taken out again, not hidden: the panel of a conversation with
507
- // no questions has the nodes it always had.
508
- const dropAsks = () => {
509
- panelAsks?.remove();
510
- panelAsks = null;
511
- panelChildAsks = false;
512
- asksHandler = null;
513
- syncTalkSurfaces();
514
- };
515
- // Not a <form>: castle.xyz plays a deck in a frame sandboxed without
516
- // `allow-forms`, where a form's submission (Enter, or a submit button) is
517
- // blocked before its submit event fires, so nothing would ever be said.
518
- const panelForm = el('div', { display: 'flex', gap: '6px', margin: '0' }, panel);
519
495
  // Chat words, not an account: no autofill or saved suggestions (Chrome
520
- // offered emails on a bare field).
496
+ // offered emails on a bare field). The talk field gets the same from its
497
+ // tree node (`uiDom.js`).
521
498
  const chatField = (input, name) => {
522
499
  input.type = 'text';
523
500
  input.name = name;
@@ -526,108 +503,55 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
526
503
  input.setAttribute('autocapitalize', 'sentences');
527
504
  input.spellcheck = true;
528
505
  };
529
- const panelInput = el('input', { flex: '1', minWidth: '0', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 15px system-ui, sans-serif' }, panelForm);
530
- chatField(panelInput, 'say');
531
- panelInput.maxLength = 280;
532
- panelInput.placeholder = 'Say something…';
533
- panelInput.enterKeyHint = 'send';
534
- const setTalkTyping = (allowed) => {
535
- const wasHidden = panelForm.style.display === 'none';
536
- panelForm.style.display = allowed ? 'flex' : 'none';
537
- if (!allowed) {
538
- panelInput.blur();
539
- if (!panelChildAsks) {dropAsks();}
540
- } else if (wasHidden && globalThis.matchMedia?.('(pointer: fine)').matches && !(globalThis.navigator?.maxTouchPoints > 0)) {
541
- panelInput.focus({ preventScroll: true });
542
- }
543
- };
544
- const panelSend = el('button', { padding: '8px 14px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 14px system-ui, sans-serif', cursor: 'pointer' }, panelForm);
545
- panelSend.type = 'button';
546
- panelSend.textContent = 'Say';
547
- const submitTalk = () => {
548
- const text = panelInput.value;
549
- panelInput.value = '';
550
- talkHandlers.send(text);
551
- };
552
- for (const type of ['keydown', 'keyup', 'keypress']) {
553
- panelInput.addEventListener(type, (event) => event.stopPropagation());
554
- }
555
- panelInput.addEventListener('keydown', (event) => {
556
- // An IME's own Enter (confirm) or Escape (cancel) belongs to the candidate;
557
- // WebKit reports the confirming Enter as keyCode 229 with isComposing false.
558
- if (event.isComposing || event.keyCode === 229) {
559
- return;
560
- }
561
- if (event.key === 'Enter') {
562
- event.preventDefault();
563
- submitTalk();
564
- } else if (event.key === 'Escape') {
565
- event.preventDefault();
566
- talkHandlers.end();
567
- }
568
- });
569
- panel.addEventListener('pointerdown', (event) => event.stopPropagation());
570
- panelSend.addEventListener('click', (event) => {
571
- event.preventDefault();
572
- submitTalk();
506
+ // The field's words as typed: the input itself while the page draws it.
507
+ const panelInput = () => talkDom.nodeFor('talk/panel/form/say');
508
+ const talkSurface = makeTalkSurface({
509
+ view: () => ({ landscape: landscapeViewport(), desktop: desktop(), w: geometry.view().w, safeInsets }),
510
+ autoFocus: autoFocusField,
511
+ onChip,
512
+ draftNow: () => (uiTreeDomEnabled() && panelInput() ? panelInput().value : talkSurface.state.field.value),
513
+ afterChange(what) {
514
+ if (what === 'open' || what === 'close') {
515
+ talkOpen = what === 'open';
516
+ showCompanionBadge();
517
+ } else if (what === 'surfaces') {
518
+ syncTalkSurfaces();
519
+ } else if (what === 'toast') {
520
+ placeToast();
521
+ } else if (what === 'shown') {
522
+ talkButton.style.display = 'none';
523
+ } else if (what === 'layout') {
524
+ layoutLandscapeRail();
525
+ }
526
+ },
527
+ draw(tree) {
528
+ if (uiTreeDomEnabled() || !talkDom.nodeFor('talk/panel')) {talkDom.render(tree);}
529
+ },
573
530
  });
574
- let talkOpen = false;
575
- let followedLine = null, followedScroll = 0, followedSnapshot = null;
576
- function followTalkLine() {
577
- // A player who scrolled back keeps that position when chips arrive.
578
- if (!followedLine?.isConnected) {return;}
579
- const scroll = geometry.scroll(panelLog);
580
- // An in-frame write stores the requested top; a later snapshot has the
581
- // browser's clamped position. This frame's snapshot predates that write.
582
- const expected = followedSnapshot ? Math.max(0, Math.min(followedScroll, scroll.height - scroll.client)) : followedScroll;
583
- if (scroll !== followedSnapshot && Math.abs(scroll.top - expected) > 1) {return;}
584
- const top = geometry.offsets(followedLine).top - geometry.offsets(panelLog).top;
585
- panelLog.scrollTop = top;
586
- followedScroll = geometry.active() ? top : panelLog.scrollTop;
587
- followedSnapshot = geometry.active() ? scroll : null;
588
- }
531
+ const panel = talkDom.nodeFor('talk/panel');
532
+ const panelAsks = () => talkDom.nodeFor('talk/panel/asks');
589
533
 
590
534
  function syncHudPrompt() {
591
- const display = hudPromptAsked && !doorsOpen && !(talkOpen && panelAsks) ? 'block' : 'none';
592
- hudText.style.display = display;
535
+ hudSurface.syncPrompt();
593
536
  }
594
537
  function syncTalkSurfaces() {
595
538
  syncTalkCaption();
596
539
  syncHudPrompt();
597
540
  placeToast();
598
541
  }
599
- const layoutPanel = () => {
600
- const landscape = landscapeViewport();
601
- const wide = desktop();
602
- Object.assign(panel.style, landscape
603
- ? { left: '50%', transform: 'translateX(-50%)', width: geometry.view().w < 740 ? 'min(70vw, 420px)' : 'min(56vw, max(220px, calc(100vw - 344px)), 560px)', maxHeight: 'calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom))', boxSizing: 'border-box', overflow: 'hidden' }
604
- : wide
605
- ? { left: edge('left', 10), transform: 'none', width: '340px' }
606
- : { left: '50%', transform: 'translateX(-50%)', width: 'min(92vw, 420px)' });
607
- if (!landscape) {
608
- panel.style.maxHeight = '';
609
- panel.style.boxSizing = '';
610
- panel.style.overflow = '';
611
- }
612
- panelLog.style.maxHeight = landscape ? 'none' : wide ? 'min(28vh, 220px)' : '28vh';
613
- panelLog.style.minHeight = landscape ? '0' : '';
614
- panelLog.style.flex = landscape ? '1 1 auto' : '';
615
- if (panelAsks) {
616
- panelAsks.style.display = landscape ? 'grid' : 'flex';
617
- panelAsks.style.gridTemplateColumns = landscape ? 'repeat(2, minmax(0, 1fr))' : '';
618
- }
619
- };
620
- layoutPanel();
542
+ // A turned or resized stage: the panel's width, height and log.
543
+ const layoutPanel = () => talkSurface.render();
621
544
  desktopQuery?.addEventListener?.('change', layoutPanel);
622
545
 
623
546
  // Grab / Throw (v1.3): a big thumb button bottom right, above the avatar
624
547
  // picker, shown while there is something to grab or something held.
625
548
  let grabHandler = () => {};
549
+ let hornHandler = null;
626
550
  const grabButton = el('button', { position: 'absolute', right: edge('right', 14), bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))', width: '76px', height: '76px', borderRadius: '38px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.55)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '800 16px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
627
551
  grabButton.addEventListener('pointerdown', (event) => {
628
552
  event.stopPropagation();
629
553
  event.preventDefault();
630
- grabHandler();
554
+ if (hornHandler) {hornHandler();} else {grabHandler();}
631
555
  });
632
556
 
633
557
  // Idle play (v1.6): an emote button above Grab that opens a row of emotes
@@ -643,10 +567,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
643
567
  emoteRow.addEventListener('pointerdown', (event) => event.stopPropagation());
644
568
  let emotesOpen = false;
645
569
  let emotesKey = '';
570
+ let emoteWheel = null, expressionEmotes = null;
646
571
  const setEmotesOpen = (open) => {
647
572
  emotesOpen = open;
648
573
  showCompanionBadge();
649
- emoteRow.style.display = open ? 'flex' : 'none';
574
+ emoteRow.style.display = open && !expressionEmotes ? 'flex' : 'none';
575
+ emoteWheel?.open(open && Boolean(expressionEmotes));
650
576
  };
651
577
  shutRound.push(() => setEmotesOpen(false));
652
578
  emoteButton.addEventListener('pointerdown', (event) => {
@@ -654,6 +580,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
654
580
  event.preventDefault();
655
581
  setEmotesOpen(!emotesOpen);
656
582
  });
583
+ emoteButton.addEventListener('click', (event) => {
584
+ if (expressionEmotes && event.detail === 0) { setEmotesOpen(!emotesOpen); }
585
+ });
657
586
  // Quick reactions and phrases (v1.11): a speech button beside the emote
658
587
  // button opens a small card, a row of emoji over the place's phrases; and
659
588
  // the feed of what was just said, small, above the dock.
@@ -934,7 +863,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
934
863
  const band = toastBand({ desktop: wide, viewW: geometry.view().w, viewH: geometry.view().h, width, height, rects, start: Math.max(12, geometry.offsets(toastStart).top || 0) });
935
864
  // With no free band toastBand clamps into the viewport. Choices win
936
865
  // over transient feedback even when that fallback cannot fit above them.
937
- const choices = talkOpen ? shownRect(panelAsks) : null;
866
+ const choices = talkOpen ? shownRect(panelAsks()) : null;
938
867
  const top = wide ? geometry.view().h - band.bottom - height : band.top;
939
868
  const left = (geometry.view().w - width) / 2;
940
869
  const blocked = choices && left < choices.right && left + width > choices.left && top < choices.bottom && top + height > choices.top;
@@ -1089,7 +1018,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1089
1018
  }
1090
1019
  }
1091
1020
  // What a frame's setters ask to be kept clear of the HUD, by group
1092
- // ("labels", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
1021
+ // ("labels", "roles", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
1093
1022
  // anchor, text] -- `node`, hung from (x, y) by `anchor` (`boxAt`), is moved
1094
1023
  // to just under the HUD's box when it would lie over it, never past the
1095
1024
  // bottom of the view. Nothing is measured or moved as it is asked: the
@@ -1133,7 +1062,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1133
1062
  // is refreshed once before this batch writes clearance positions.
1134
1063
  const box = geometry.size(node);
1135
1064
  const down = pushBelow(boxAt(x, y, box.w, box.h, anchor), rect, undefined, geometry.view().h);
1136
- const up = group === 'labels' || group === 'pointers' ? promptShift(boxAt(x, y + down, box.w, box.h, anchor), prompt) : 0;
1065
+ const up = group === 'labels' || group === 'roles' || group === 'pointers' ? promptShift(boxAt(x, y + down, box.w, box.h, anchor), prompt) : 0;
1137
1066
  if (down + up !== 0) {
1138
1067
  moves.push([node, y + down + up]);
1139
1068
  }
@@ -1248,9 +1177,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1248
1177
  return;
1249
1178
  }
1250
1179
  landscape = next;
1251
- back.style.left = edge('left', landscape ? 76 : 12);
1252
- hud.style.maxWidth = landscape ? 'min(42vw, 420px)' : '70vw';
1253
- toast.style.maxWidth = landscape ? 'min(42vw, 420px)' : 'calc(100vw - 24px)';
1180
+ // Back clears the native exit corner; the HUD and toast narrow.
1181
+ hudSurface.setLandscape(landscape);
1254
1182
  Object.assign(dock.style, landscape
1255
1183
  ? { top: 'max(68px, calc(env(safe-area-inset-top) + 56px))', bottom: '', maxWidth: 'min(24vw, 160px)' }
1256
1184
  : { top: '', bottom: 'max(10px, env(safe-area-inset-bottom))', maxWidth: 'calc(100vw - 130px)' });
@@ -1550,6 +1478,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1550
1478
  syncActionSurfaces();
1551
1479
  },
1552
1480
  interactionRoot: () => root,
1481
+ // The Act/Jump pair's state and handlers (`act.js`), for the HUD root a
1482
+ // native host draws; the page's pair is drawn by `act.js` itself.
1483
+ setActPair(state) {
1484
+ hudSurface.setActPair(state);
1485
+ },
1553
1486
  interactionRail(pair, act, jump) {
1554
1487
  if (actRail) {railNodes.splice(railNodes.indexOf(actRail), 1);}
1555
1488
  actRail = pair;
@@ -1714,11 +1647,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1714
1647
  }
1715
1648
  },
1716
1649
  showBack(show, label = 'Back') {
1717
- back.style.display = show ? 'block' : 'none';
1718
- const text = `‹ ${label}`;
1719
- if (back.textContent !== text) {
1720
- back.textContent = text;
1721
- }
1650
+ hudSurface.showBack(show, label);
1722
1651
  },
1723
1652
  setActions(items, handler, canAct, n, overflow = false, onOverflowOpen = () => {}) {
1724
1653
  if (safeInsets) {overflow = true;}
@@ -1893,25 +1822,20 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1893
1822
  back.style.top = on ? 'auto' : 'max(12px, env(safe-area-inset-top))';
1894
1823
  back.style.bottom = on ? 'max(196px, calc(env(safe-area-inset-bottom) + 186px))' : '';
1895
1824
  },
1896
- setHud(spec, timerSeconds) {
1825
+ // Said every frame: the HUD root is rebuilt only when its words change
1826
+ // (`hudSurface.js`), so a frame that changes nothing writes nothing.
1827
+ // `simNow` (the simulation's ms, `Hub.simNow()`), given with a running
1828
+ // `spec.timer`, makes the big line an absolute `clock`: the root is sent
1829
+ // again only when the timer itself changes (a start, a stop, another
1830
+ // since/until), not ten times a second, and the page ticks it here, each
1831
+ // frame, at `simNow`.
1832
+ setHud(spec, timerSeconds, simNow) {
1897
1833
  if (!spec) {
1898
- hud.style.display = 'none';
1899
- hudPromptAsked = false;
1900
- syncHudPrompt();
1834
+ hudSurface.setHud(null);
1901
1835
  return;
1902
1836
  }
1903
- hud.style.display = 'block';
1904
- const title = spec.title ?? '';
1905
- if (hudTitle.textContent !== title) {hudTitle.textContent = title;}
1906
- const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
1907
- if (hudBig.textContent !== big) {hudBig.textContent = big;}
1908
- const bigDisplay = big ? 'block' : 'none';
1909
- if (hudBig.style.display !== bigDisplay) {hudBig.style.display = bigDisplay;}
1910
- const prompt = firstPromptSentence(spec.text);
1911
- if (hudText.textContent !== prompt) {hudText.textContent = prompt;}
1912
- hudTitle.style.display = hudTitle.textContent ? 'block' : 'none';
1913
- hudPromptAsked = Boolean(hudText.textContent);
1914
- syncHudPrompt();
1837
+ const { big, clock } = hudSurface.setHud(spec, timerSeconds, simNow);
1838
+ if (clock && uiTreeDomEnabled()) {hudDom.tick();}
1915
1839
  if (hudClear) {
1916
1840
  layoutHudClear(big, spec.text ?? '');
1917
1841
  }
@@ -2039,13 +1963,43 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2039
1963
  : node.dataset.hub === 'action-rail' ? [node] : []);
2040
1964
  return [...actionControls, hud, hudText, askCard, back, sound?.button, sound?.card, toast, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard, actionChips, stuckChip, decorButton, cabinet, ribbon].map(shownRect).filter(Boolean);
2041
1965
  },
1966
+ // Roles follow resized tags before crowd selection, then only hide with
1967
+ // rejected names. Repositioned chips must clear the HUD again.
1968
+ syncRoleLabels(items, keepPlayerId = null, position = true) {
1969
+ const shown = new Map(items.map((item) => [item.id, item]));
1970
+ const entries = [];
1971
+ for (const [id, node] of labelNodes) {
1972
+ if (!id.startsWith('role:')) {
1973
+ continue;
1974
+ }
1975
+ const item = shown.get(id);
1976
+ if (!item && id === `role:${keepPlayerId}`) {
1977
+ continue;
1978
+ }
1979
+ if (!item) {
1980
+ node.style.visibility = 'hidden';
1981
+ } else if (position) {
1982
+ node.style.left = `${item.x}px`;
1983
+ node.style.top = `${item.y}px`;
1984
+ node.style.opacity = String(item.opacity ?? 1);
1985
+ entries.push([node, item.x, item.y, 'bottom', item.text]);
1986
+ }
1987
+ }
1988
+ if (entries.length && (hudClear || hudText.style.display !== 'none')) {
1989
+ keepClearOfHud('roles', entries);
1990
+ flushHudClear();
1991
+ }
1992
+ },
2042
1993
  // E crowd names asks only on its opted-in late pass, after setLabels and
2043
1994
  // HUD clearance have put every ordinary DOM label at its final rectangle.
2044
1995
  // The summary from a prior frame has already been removed by setLabels.
2045
1996
  crowdNameLabelBoxes() {
2046
1997
  return [...labelNodes.entries()]
2047
1998
  .filter(([id]) => id !== 'crowd:summary')
2048
- .map(([, node]) => shownRect(node))
1999
+ .map(([id, node]) => {
2000
+ const box = shownRect(node);
2001
+ return box && id.startsWith('role:') ? { ...box, rolePlayerId: id.slice(5) } : box;
2002
+ })
2049
2003
  .filter(Boolean);
2050
2004
  },
2051
2005
  // E's late pass runs after ordinary labels have completed HUD clearance.
@@ -2084,6 +2038,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2084
2038
  node = el('div', { position: 'absolute', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '12px', background: 'rgba(15,12,10,0.7)', whiteSpace: 'nowrap', fontSize: '14px' }, labels);
2085
2039
  labelNodes.set(item.id, node);
2086
2040
  }
2041
+ if (item.id.startsWith('role:')) {
2042
+ node.style.visibility = '';
2043
+ }
2087
2044
  // An NPC's line is kept on screen: a reply over one at the edge of the
2088
2045
  // view would otherwise be cut off mid-sentence. Other labels are
2089
2046
  // placed as they always were.
@@ -2241,22 +2198,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2241
2198
  placeToast();
2242
2199
  },
2243
2200
  setToast(text, { wrap = false } = {}) {
2244
- if (text && wrap) {
2245
- if (!toastWrap) {
2246
- toastWrap = { maxWidth: toast.style.maxWidth, overflowWrap: toast.style.overflowWrap, textAlign: toast.style.textAlign };
2247
- Object.assign(toast.style, { maxWidth: 'min(90vw, 480px)', overflowWrap: 'anywhere', textAlign: 'center' });
2248
- }
2249
- } else if (toastWrap) {
2250
- Object.assign(toast.style, toastWrap);
2251
- toastWrap = null;
2252
- }
2253
- const display = text ? 'block' : 'none';
2254
- if (toast.style.display !== display) {
2255
- toast.style.display = display;
2256
- }
2257
- if (text && toast.textContent !== text) {
2258
- toast.textContent = text;
2259
- }
2201
+ hudSurface.setToast(text, { wrap });
2260
2202
  placeToast();
2261
2203
  },
2262
2204
  showPicker(show, selected, colors, invite = null) {
@@ -2303,7 +2245,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2303
2245
  }
2304
2246
  },
2305
2247
  onTalk(handlers) {
2306
- talkHandlers = handlers;
2248
+ talkSurface.onTalk(handlers);
2307
2249
  },
2308
2250
  onGrab(handler) {
2309
2251
  grabHandler = handler;
@@ -2318,7 +2260,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2318
2260
  sitHandler = handler;
2319
2261
  },
2320
2262
  // `emotes` is [[id, emoji]] to offer, or null to hide the picker.
2321
- setEmotes(emotes) {
2263
+ setEmotes(emotes, expression = null) {
2322
2264
  const show = Array.isArray(emotes) && emotes.length > 0;
2323
2265
  emoteButton.style.display = show ? 'block' : 'none';
2324
2266
  if (!show) {
@@ -2326,6 +2268,21 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2326
2268
  layoutLandscapeRail();
2327
2269
  return;
2328
2270
  }
2271
+ if (expression) {
2272
+ if (!emoteWheel) {
2273
+ emoteWheel = makeEmoteWheel({ root, el, trigger: emoteButton,
2274
+ view: () => safeLayout?.view() ?? { ...geometry.view(), insets: { left: 0, right: 0, top: 0, bottom: 0 } },
2275
+ bands: () => surfaces().filter((entry) => entry.node !== emoteWheel?.node).map((entry) => shownRect(entry.node)).filter(Boolean),
2276
+ pick: (id, ground) => { onChip?.(); emoteHandler(id, ground); }, close: () => { setEmotesOpen(false); emoteButton.focus(); },
2277
+ });
2278
+ }
2279
+ const key = JSON.stringify(expression);
2280
+ expressionEmotes = expression;
2281
+ emoteRow.style.display = 'none';
2282
+ if (key !== emotesKey) { emotesKey = key; emoteWheel.set(expression); }
2283
+ return;
2284
+ }
2285
+ if (expressionEmotes) { expressionEmotes = null; setEmotesOpen(false); emoteWheel?.dispose(); emoteWheel = null; }
2329
2286
  const key = emotes.map(([id]) => id).join('|');
2330
2287
  if (key === emotesKey) {
2331
2288
  return;
@@ -2523,6 +2480,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2523
2480
  },
2524
2481
  // The Grab button's word ("Grab" or "Throw"), or null to hide it.
2525
2482
  grabPrompt(text) {
2483
+ hornHandler = null;
2526
2484
  if (actMode) {text = null;}
2527
2485
  grabButton.style.display = text ? 'block' : 'none';
2528
2486
  if (text && grabButton.textContent !== text) {
@@ -2532,6 +2490,15 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2532
2490
  }
2533
2491
  layoutLandscapeRail();
2534
2492
  },
2493
+ // Vehicle horn reuses the action position and its existing layout rules.
2494
+ hornPrompt(handler) {
2495
+ hornHandler = handler;
2496
+ grabButton.style.display = 'block';
2497
+ grabButton.textContent = 'Horn';
2498
+ grabButton.style.background = 'rgba(20,16,12,0.78)';
2499
+ grabButton.style.color = '#fff';
2500
+ layoutLandscapeRail();
2501
+ },
2535
2502
  // Inline state only: prompt changes wake the Weakest panel pass without a layout read.
2536
2503
  hudPromptSignature() {
2537
2504
  const prompts = [sitButton, grabButton, talkButton, nearButton];
@@ -2616,170 +2583,19 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2616
2583
  }
2617
2584
  layoutLandscapeRail();
2618
2585
  },
2619
- openTalk(name, { mind = false, canType = true } = {}) {
2620
- talkOpen = true;
2621
- showCompanionBadge();
2622
- panelMind = mind;
2623
- panelName.textContent = name;
2624
- dropTyping();
2625
- panelLog.replaceChildren();
2626
- panelOpening = null;
2627
- followedLine = null;
2628
- dropAsks();
2629
- dropHint();
2630
- panelInput.value = '';
2631
- panelInput.placeholder = mind ? `Ask ${name.split(',')[0].trim()} anything…` : 'Say something…';
2632
- panelSend.disabled = false;
2633
- panelSend.style.opacity = '1';
2634
- panelSend.textContent = 'Say';
2635
- panel.style.display = 'flex';
2636
- talkButton.style.display = 'none';
2637
- panelForm.style.display = 'none';
2638
- setTalkTyping(canType);
2639
- layoutLandscapeRail();
2640
- },
2641
- closeTalk() {
2642
- talkOpen = false;
2643
- showCompanionBadge();
2644
- panelOpening = null;
2645
- panel.style.display = 'none';
2646
- panelInput.blur();
2647
- dropAsks();
2648
- dropHint();
2649
- dropTyping();
2650
- layoutLandscapeRail();
2651
- },
2652
- talkTyping: setTalkTyping,
2653
- // Plain muted words under the log (the opening), or null for none: why an
2654
- // under-13 speaker has no field ("Talking with Biscuit is for players 13
2655
- // and up"). Not a button.
2656
- talkHint(text) {
2657
- const words = talkOpen && typeof text === 'string' && text ? text : null;
2658
- if ((panelHint?.textContent ?? null) === words) {
2659
- return;
2660
- }
2661
- if (!words) {
2662
- dropHint();
2663
- } else {
2664
- panelHint ??= el('div', { fontSize: '12px', fontWeight: '500', opacity: '0.7' }, panel);
2665
- panel.insertBefore(panelHint, panelForm);
2666
- panelHint.textContent = words;
2667
- }
2668
- layoutPanel();
2669
- syncTalkSurfaces();
2670
- },
2671
- // A refused re-attach keeps the unsent question for the next open.
2672
- talkDraft(text) {
2673
- if (text !== undefined) {
2674
- panelInput.value = text;
2675
- }
2676
- return panelInput.value;
2677
- },
2678
- // v1.47: replace the opening in place; questions and later lines stay put.
2679
- talkOpening(text) {
2680
- if (talkOpen && panelOpening) {
2681
- panelOpening.textContent = text;
2682
- placeToast();
2683
- }
2684
- },
2685
- // v1.46: a mind's chips sit below its field; an empty list removes them.
2686
- talkAsks(asks, onAsk) {
2687
- const child = Array.isArray(asks) && typeof asks[0]?.id === 'string';
2688
- const list = Array.isArray(asks) ? asks.slice(0, child ? 4 : 3) : [];
2689
- if (!list.length) {
2690
- dropAsks();
2691
- return;
2692
- }
2693
- if (!panelAsks) {
2694
- panelAsks = el('div', { display: 'none', flexWrap: 'wrap', gap: '6px' }, panel);
2695
- geometry.register(panelAsks);
2696
- if (!panelMind) {
2697
- panel.insertBefore(panelAsks, panelForm);
2698
- }
2699
- }
2700
- panelAsks.replaceChildren();
2701
- panelChildAsks = child;
2702
- asksHandler = onAsk;
2703
- if (panelMind && !child) {
2704
- el('span', { fontSize: '12px', opacity: '0.7', flexBasis: '100%', gridColumn: '1 / -1' }, panelAsks).textContent = 'or try:';
2705
- }
2706
- for (const ask of list) {
2707
- const chip = el('button', { pointerEvents: 'auto', maxWidth: '100%', overflowWrap: 'anywhere', padding: '6px 11px', borderRadius: '14px', border: '1px solid rgba(233,196,143,0.7)', background: 'rgba(233,196,143,0.14)', color: '#f5dfbd', font: '600 13px/1.25 system-ui, sans-serif', textAlign: 'left', cursor: 'pointer' }, panelAsks);
2708
- chip.type = 'button';
2709
- chip.textContent = child ? ask.label : ask;
2710
- chip.addEventListener('pointerdown', (event) => {
2711
- event.stopPropagation();
2712
- event.preventDefault();
2713
- if (onChip) {
2714
- onChip();
2715
- }
2716
- asksHandler?.(ask);
2717
- });
2718
- }
2719
- layoutPanel();
2720
- syncTalkSurfaces();
2721
- followTalkLine();
2722
- },
2723
- // `note`, when given, is a small caption under the line (a scripted reply).
2724
- talkLine(who, text, note = null) {
2725
- // v1.35: where the log was before this line: at its end, or scrolled
2726
- // up by the player to read something earlier.
2727
- const scroll = geometry.scroll(panelLog);
2728
- const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
2729
- if (who === 'them') {
2730
- dropTyping();
2731
- }
2732
- const line = el('div', { alignSelf: who === 'me' ? 'flex-end' : 'flex-start', maxWidth: '85%', padding: '5px 9px', borderRadius: '10px', background: who === 'me' ? 'rgba(233,196,143,0.25)' : 'rgba(255,250,240,0.94)', color: who === 'me' ? '#fff' : '#2b2118' }, panelLog);
2733
- geometry.register(line);
2734
- line.textContent = text;
2735
- if (who === 'them' && panelLog.childElementCount === 1) {
2736
- panelOpening = line;
2737
- }
2738
- if (note) {
2739
- el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
2740
- }
2741
- let top = scroll.top;
2742
- if (who === 'me') {
2743
- // The player's own words: they have just sent them, show them.
2744
- // The browser clamps to the live end without reading appended layout.
2745
- top = geometry.active() ? Number.MAX_SAFE_INTEGER : geometry.scroll(panelLog).height;
2746
- panelLog.scrollTop = top;
2747
- } else if (atEnd) {
2748
- // A reply is read from its first word: its top at the top of what
2749
- // shows (the end of the log when the whole reply fits, as the
2750
- // browser stops there). A player reading further up is left there.
2751
- top = geometry.offsets(line).top - geometry.offsets(panelLog).top;
2752
- panelLog.scrollTop = top;
2753
- }
2754
- followedLine = who === 'me' || atEnd ? line : null;
2755
- followedScroll = geometry.active() ? top : panelLog.scrollTop;
2756
- followedSnapshot = geometry.active() ? scroll : null;
2757
- placeToast();
2758
- },
2759
- talkWaiting(waiting) {
2760
- panelSend.disabled = waiting;
2761
- panelSend.style.opacity = waiting ? '0.5' : '1';
2762
- panelSend.textContent = waiting ? '…' : 'Say';
2763
- if (!waiting) {
2764
- dropTyping();
2765
- } else if (talkOpen && panelMind && !panelTyping) {
2766
- const scroll = geometry.scroll(panelLog);
2767
- const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
2768
- panelTyping = el('div', { alignSelf: 'flex-start', display: 'flex', gap: '3px', padding: '5px 9px', borderRadius: '10px', background: 'rgba(255,250,240,0.94)', color: '#2b2118' }, panelLog);
2769
- panelTyping.className = 'hub-npc-typing';
2770
- panelTyping.setAttribute('role', 'status');
2771
- panelTyping.setAttribute('aria-label', `${panelName.textContent} is typing`);
2772
- for (let i = 0; i < 3; i++) {
2773
- el('span', {}, panelTyping).textContent = '•';
2774
- }
2775
- if (atEnd) {
2776
- panelLog.scrollTop = geometry.active() ? Number.MAX_SAFE_INTEGER : geometry.scroll(panelLog).height;
2777
- }
2778
- }
2779
- placeToast();
2780
- },
2586
+ // The talk API (`talkSurface.js`), for `talk.js`.
2587
+ openTalk: talkSurface.openTalk,
2588
+ closeTalk: talkSurface.closeTalk,
2589
+ talkTyping: talkSurface.talkTyping,
2590
+ talkHint: talkSurface.talkHint,
2591
+ talkDraft: talkSurface.talkDraft,
2592
+ talkOpening: talkSurface.talkOpening,
2593
+ talkAsks: talkSurface.talkAsks,
2594
+ talkLine: talkSurface.talkLine,
2595
+ talkWaiting: talkSurface.talkWaiting,
2781
2596
  talkFocused() {
2782
- return document.activeElement === panelInput;
2597
+ const input = panelInput();
2598
+ return uiTreeDomEnabled() && input ? document.activeElement === input : talkSurface.talkFocused();
2783
2599
  },
2784
2600
  // `doors` is [{ id, title }] to offer, or null for none; `goText` is the
2785
2601
  // word on each one's button ("Go", or "Go together" in a party). `stuck`
@@ -3122,6 +2938,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3122
2938
  },
3123
2939
  dispose() {
3124
2940
  api.clearPadContext();
2941
+ emoteWheel?.dispose();
3125
2942
  askLifecycle.abort();
3126
2943
  if (placeMenu) {clearMenu();}
3127
2944
  if (textAsk) {
@@ -3147,6 +2964,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3147
2964
  unguardKeys();
3148
2965
  desktopQuery?.removeEventListener?.('change', layoutPanel);
3149
2966
  for (const node of labelMeasures.values()) {node.remove();}
2967
+ // A sink drops the roots this chrome drew.
2968
+ hudSurface.dispose();
2969
+ talkSurface.dispose();
3150
2970
  root.remove();
3151
2971
  },
3152
2972
  };
@@ -3156,8 +2976,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3156
2976
  surface('hud-prompt', hudText, 'text', false, { bottom: 54 }),
3157
2977
  surface('back', back, 'control', false, { left: landscape ? 76 : 12, top: 12 }),
3158
2978
  { ...surface('character', pickerToggle, 'control', false, { right: landscape ? 12 : 10, bottom: 10 }), stack: 3, stackNode: picker },
3159
- surface('character-card', pickerCard, 'card'),
2979
+ // The landscape strip is fitted by `layPicker`; placing it around the
2980
+ // controls it covers narrowed it and pushed its Close off the screen.
2981
+ { ...surface('character-card', pickerCard, 'card'), pinned: pickerCompact },
3160
2982
  { ...surface('grab', grabButton), stack: 2 }, { ...surface('emote', emoteButton), stack: 1 }, { ...surface('quick-chat', sayButton), stack: 0 },
2983
+ ...(emoteWheel ? [surface('emote-wheel', emoteWheel.node, 'card')] : []),
3161
2984
  surface('emotes', emoteRow, 'card'), surface('quick-chat-card', sayCard, 'card'),
3162
2985
  { ...surface('sit', sitButton), stack: 6 }, { ...surface('talk', talkButton), stack: 7 }, { ...surface('near', nearButton), stack: 8 },
3163
2986
  surface('talk-card', panel, 'card'), surface('doors-card', doorsList, 'card'), surface('people-card', peopleList, 'card'),
@@ -3171,7 +2994,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3171
2994
  surface('toast', toast, 'toast', true, { top: 12 }), surface('ribbon', ribbon, 'ribbon', true),
3172
2995
  surface('cabinet', cabinet, 'card', true), surface('feed', feed, 'text', true, { left: 10 }),
3173
2996
  surface('stats', stats, 'text', true, { right: 8, top: 8 }), surface('stuck', stuckChip, 'pointer', true),
3174
- ...[...labelNodes].map(([id, node]) => surface(`label:${id}`, node, 'label', true)),
2997
+ ...[...labelNodes].map(([id, node]) => ({ ...surface(`label:${id}`, node, 'label', true),
2998
+ // A role chip belongs under its name tag, which is drawn over the viewer's body anyway.
2999
+ ignoreObstacle: id.startsWith('role:') ? worldAvatar : null })),
3175
3000
  ...[...pointerNodes].map(([id, item]) => surface(`pointer:${id}`, item.chip, 'pointer', true)),
3176
3001
  ...externalEntries().map(([id, item]) => ({ ...surface(id, item.node, item.kind, item.kind === 'text'), ...item.placement, ...(id === 'engine-shift-lock' ? { stack: 4 } : {}) })),
3177
3002
  ...(actionOverflow?.surfaces?.() ?? []).map((node, i) => surface(`action-overflow:${i}`, node, 'control')),
@@ -3193,6 +3018,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
3193
3018
  if (safeInsets) {
3194
3019
  safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
3195
3020
  if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.settle();}
3021
+ emoteWheel?.layout();
3196
3022
  } });
3197
3023
  debugLayout = () => { safeLayout.flush(); worldLayout?.flush(); return safeLayout.report(); };
3198
3024
  (globalThis.castleHub ??= {}).layout = debugLayout;