castle-web-cli 0.4.233 → 0.4.235

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 (383) hide show
  1. package/dist/api.d.ts +11 -0
  2. package/dist/api.js +43 -0
  3. package/dist/bundle.d.ts +64 -0
  4. package/dist/bundle.js +558 -2
  5. package/dist/castle-host/host.d.ts +17 -2
  6. package/dist/castle-host/host.js +793 -36
  7. package/dist/castleJson.d.ts +20 -1
  8. package/dist/castleJson.js +44 -2
  9. package/dist/check.js +9 -2
  10. package/dist/chunkLoader.d.ts +3 -0
  11. package/dist/chunkLoader.js +111 -0
  12. package/dist/devParty.d.ts +26 -0
  13. package/dist/devParty.js +231 -0
  14. package/dist/devSaveStorage.js +4 -0
  15. package/dist/devSessionStorage.js +3 -1
  16. package/dist/devSocial.d.ts +24 -0
  17. package/dist/devSocial.js +70 -0
  18. package/dist/ide.d.ts +2 -0
  19. package/dist/ide.js +119 -15
  20. package/dist/index.js +8 -2
  21. package/dist/init.js +1 -1
  22. package/dist/save-deck.d.ts +20 -1
  23. package/dist/save-deck.js +141 -5
  24. package/dist/serve.js +29 -11
  25. package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
  26. package/dist/shell/index.html +1 -1
  27. package/dist/vitePlugins.d.ts +2 -1
  28. package/dist/vitePlugins.js +13 -0
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +266 -3
  31. package/kits/base/sdk/castle.d.ts +7 -3
  32. package/kits/base/sdk/castle.js +2 -0
  33. package/kits/base/sdk/commands.d.ts +162 -1
  34. package/kits/base/sdk/commands.js +3 -0
  35. package/kits/base/sdk/display.d.ts +3 -0
  36. package/kits/base/sdk/display.js +9 -3
  37. package/kits/base/sdk/hub.d.ts +33 -6
  38. package/kits/base/sdk/hub.js +68 -5
  39. package/kits/base/sdk/hubRejoin.d.ts +4 -0
  40. package/kits/base/sdk/hubRejoin.js +15 -0
  41. package/kits/base/sdk/multiplayer.d.ts +7 -1
  42. package/kits/base/sdk/multiplayer.js +147 -40
  43. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  44. package/kits/base/sdk/party.d.ts +23 -0
  45. package/kits/base/sdk/party.js +91 -0
  46. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  47. package/kits/base/sdk/reconnectBudget.js +96 -0
  48. package/kits/base/sdk/save.d.ts +38 -1
  49. package/kits/base/sdk/save.js +79 -6
  50. package/kits/base/sdk/server/hub.d.ts +31 -1
  51. package/kits/base/sdk/server/hub.js +50 -3
  52. package/kits/base/sdk/server/platformHandle.d.ts +13 -1
  53. package/kits/base/sdk/server/storage.d.ts +4 -0
  54. package/kits/base/sdk/server/storage.js +19 -3
  55. package/kits/base/sdk/server/wrapper.d.ts +7 -1
  56. package/kits/base/sdk/server/wrapper.js +10 -1
  57. package/kits/base/sdk/social.d.ts +9 -0
  58. package/kits/base/sdk/social.js +5 -0
  59. package/kits/hub-game/CLAUDE.md +123 -3
  60. package/kits/hub-game/README.md +63 -0
  61. package/kits/hub-game/castle.json +5 -5
  62. package/kits/hub-game/code/client/act.js +312 -0
  63. package/kits/hub-game/code/client/actionLayout.js +147 -0
  64. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  65. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  66. package/kits/hub-game/code/client/askSlot.js +117 -0
  67. package/kits/hub-game/code/client/avatar.js +4 -2
  68. package/kits/hub-game/code/client/avatarShare.js +2 -0
  69. package/kits/hub-game/code/client/backVisibility.js +13 -0
  70. package/kits/hub-game/code/client/ballot.js +15 -10
  71. package/kits/hub-game/code/client/build.js +16 -0
  72. package/kits/hub-game/code/client/chat.js +41 -5
  73. package/kits/hub-game/code/client/chatModeration.js +5 -0
  74. package/kits/hub-game/code/client/chrome.js +1148 -258
  75. package/kits/hub-game/code/client/crowdNames.js +241 -0
  76. package/kits/hub-game/code/client/decor.js +10 -4
  77. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  78. package/kits/hub-game/code/client/doorErrors.js +39 -0
  79. package/kits/hub-game/code/client/fall.js +18 -0
  80. package/kits/hub-game/code/client/farAvatars.js +233 -0
  81. package/kits/hub-game/code/client/firstJoin.js +9 -2
  82. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  83. package/kits/hub-game/code/client/frameBatch.js +5 -0
  84. package/kits/hub-game/code/client/grab.js +31 -11
  85. package/kits/hub-game/code/client/hookLayer.js +87 -8
  86. package/kits/hub-game/code/client/hudCopy.js +51 -0
  87. package/kits/hub-game/code/client/hudRate.js +20 -0
  88. package/kits/hub-game/code/client/idle.js +14 -2
  89. package/kits/hub-game/code/client/invites.js +231 -0
  90. package/kits/hub-game/code/client/joinError.js +9 -0
  91. package/kits/hub-game/code/client/labelsNear.js +31 -2
  92. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  93. package/kits/hub-game/code/client/layoutCache.js +264 -0
  94. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  95. package/kits/hub-game/code/client/loadingCover.js +148 -0
  96. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  97. package/kits/hub-game/code/client/menuRows.js +43 -0
  98. package/kits/hub-game/code/client/modelReady.js +7 -0
  99. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  100. package/kits/hub-game/code/client/padCues.js +112 -0
  101. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  102. package/kits/hub-game/code/client/padReadability.js +26 -0
  103. package/kits/hub-game/code/client/padRings.js +69 -0
  104. package/kits/hub-game/code/client/pushVisit.js +14 -0
  105. package/kits/hub-game/code/client/quality.js +205 -0
  106. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  107. package/kits/hub-game/code/client/safeLayout.js +338 -0
  108. package/kits/hub-game/code/client/safeStyle.js +42 -0
  109. package/kits/hub-game/code/client/say.js +12 -3
  110. package/kits/hub-game/code/client/shot.js +64 -10
  111. package/kits/hub-game/code/client/shotFit.js +56 -0
  112. package/kits/hub-game/code/client/signIn.js +28 -0
  113. package/kits/hub-game/code/client/state.js +53 -0
  114. package/kits/hub-game/code/client/talk.js +209 -45
  115. package/kits/hub-game/code/client/tiers.js +68 -66
  116. package/kits/hub-game/code/client/together.js +7 -2
  117. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  118. package/kits/hub-game/code/client/weakestTier.js +295 -0
  119. package/kits/hub-game/code/client/worldLabels.js +241 -0
  120. package/kits/hub-game/code/client/yours.js +10 -9
  121. package/kits/hub-game/code/npcDisplayText.js +55 -0
  122. package/kits/hub-game/code/server/act.js +124 -0
  123. package/kits/hub-game/code/server/actions.js +6 -1
  124. package/kits/hub-game/code/server/actors.js +2 -1
  125. package/kits/hub-game/code/server/analytics.js +83 -0
  126. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  127. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  128. package/kits/hub-game/code/server/companion.js +28 -3
  129. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  130. package/kits/hub-game/code/server/earned.js +22 -5
  131. package/kits/hub-game/code/server/frameBatch.js +183 -0
  132. package/kits/hub-game/code/server/friendsAmong.js +49 -9
  133. package/kits/hub-game/code/server/history.js +2 -0
  134. package/kits/hub-game/code/server/hub.js +1306 -95
  135. package/kits/hub-game/code/server/idle.js +30 -1
  136. package/kits/hub-game/code/server/index.js +26 -4
  137. package/kits/hub-game/code/server/invites.js +19 -0
  138. package/kits/hub-game/code/server/labels.js +9 -1
  139. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  140. package/kits/hub-game/code/server/manifest.js +211 -3
  141. package/kits/hub-game/code/server/menu.js +31 -3
  142. package/kits/hub-game/code/server/npcs.js +226 -64
  143. package/kits/hub-game/code/server/observe.js +408 -0
  144. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  145. package/kits/hub-game/code/server/players.js +9 -1
  146. package/kits/hub-game/code/server/resumePose.js +152 -0
  147. package/kits/hub-game/code/server/say.js +1 -1
  148. package/kits/hub-game/code/server/standing.js +4 -5
  149. package/kits/hub-game/code/server/storageLimit.js +187 -0
  150. package/kits/hub-game/code/server/vis.js +67 -5
  151. package/kits/hub-game/code/shared/act.js +35 -0
  152. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  153. package/kits/hub-game/code/shared/loadStages.js +12 -0
  154. package/kits/hub-game/code/shared/quality.js +74 -0
  155. package/kits/hub-game/code/shared/say.js +2 -0
  156. package/kits/hub-game/code/shared/shot.js +35 -1
  157. package/kits/hub-game/code/systems/hub.js +970 -169
  158. package/kits/hub-game/docs/analytics.md +279 -0
  159. package/kits/hub-game/docs/contract.md +1259 -42
  160. package/kits/hub-game/docs/home-pieces.md +9 -2
  161. package/kits/hub-game/docs/observed-progress.md +252 -0
  162. package/kits/hub-game/main.jsx +2 -0
  163. package/kits/hub-game/package-lock.json +10 -3
  164. package/kits/hub-game/package.json +6 -3
  165. package/kits/hub-game/play/player.js +142 -0
  166. package/kits/hub-game/play/registry.js +47 -0
  167. package/kits/hub-game/play.jsx +37 -0
  168. package/kits/hub-game/scripts/check.mjs +39 -5
  169. package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
  170. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
  171. package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
  172. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
  173. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
  174. package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
  175. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
  176. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  177. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  178. package/kits/hub-game/scripts/test-act.mjs +171 -0
  179. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  180. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  181. package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
  182. package/kits/hub-game/scripts/test-actors.mjs +20 -7
  183. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  184. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  185. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  186. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  187. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  188. package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
  189. package/kits/hub-game/scripts/test-avatar.mjs +44 -0
  190. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  191. package/kits/hub-game/scripts/test-ballot.mjs +11 -4
  192. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  193. package/kits/hub-game/scripts/test-build.mjs +20 -2
  194. package/kits/hub-game/scripts/test-chat.mjs +206 -5
  195. package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
  196. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  197. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  198. package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
  199. package/kits/hub-game/scripts/test-decor.mjs +7 -0
  200. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  201. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  202. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  203. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  204. package/kits/hub-game/scripts/test-earned.mjs +33 -3
  205. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  206. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  207. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  208. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  209. package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
  210. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  211. package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
  212. package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
  213. package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
  214. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  215. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  216. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  217. package/kits/hub-game/scripts/test-idle.mjs +66 -0
  218. package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
  219. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  220. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  221. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  222. package/kits/hub-game/scripts/test-labels.mjs +71 -3
  223. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  224. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  225. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  226. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  227. package/kits/hub-game/scripts/test-manifest.mjs +265 -0
  228. package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
  229. package/kits/hub-game/scripts/test-menu.mjs +23 -0
  230. package/kits/hub-game/scripts/test-npcs.mjs +917 -10
  231. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  232. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  233. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  234. package/kits/hub-game/scripts/test-picker.mjs +234 -7
  235. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  236. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  237. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  238. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  239. package/kits/hub-game/scripts/test-rehello.mjs +699 -5
  240. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  241. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  242. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  243. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  244. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  245. package/kits/hub-game/scripts/test-say.mjs +1 -1
  246. package/kits/hub-game/scripts/test-shot.mjs +145 -0
  247. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  248. package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
  249. package/kits/hub-game/scripts/test-standing.mjs +35 -2
  250. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  251. package/kits/hub-game/scripts/test-stuck.mjs +5 -4
  252. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  253. package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
  254. package/kits/hub-game/scripts/test-tiers.mjs +7 -8
  255. package/kits/hub-game/scripts/test-vis.mjs +433 -6
  256. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  257. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  258. package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
  259. package/kits/hub-game/scripts/test-yours.mjs +39 -8
  260. package/kits/multiplayer-3d/castle.json +5 -5
  261. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  262. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  263. package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
  264. package/kits/multiplayer-3d/package-lock.json +8 -1
  265. package/kits/multiplayer-3d/package.json +2 -1
  266. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  267. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  268. package/kits/physics-2d/CLAUDE.md +10 -1
  269. package/kits/physics-2d/castle.json +2 -2
  270. package/kits/physics-2d/engine/frozenActors.js +233 -0
  271. package/kits/physics-2d/engine/scene.js +87 -5
  272. package/kits/physics-2d/eslint.config.js +1 -1
  273. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  274. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  275. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  276. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  277. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  278. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  279. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  280. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  281. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  282. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  283. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  284. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  285. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  286. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  287. package/kits/physics-3d/CLAUDE.md +25 -1651
  288. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  289. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  290. package/kits/physics-3d/behaviors/Player.jsx +35 -18
  291. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  292. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  293. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  294. package/kits/physics-3d/castle.json +3 -3
  295. package/kits/physics-3d/docs/engine-camera.md +542 -0
  296. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  297. package/kits/physics-3d/docs/engine-load.md +149 -0
  298. package/kits/physics-3d/docs/engine-look.md +114 -0
  299. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  300. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  301. package/kits/physics-3d/docs/engine-sky.md +198 -0
  302. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  303. package/kits/physics-3d/docs/engine-view.md +37 -0
  304. package/kits/physics-3d/docs/pxmodel-format.md +1 -1
  305. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  306. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
  307. package/kits/physics-3d/engine3d/actornode.js +1 -0
  308. package/kits/physics-3d/engine3d/branches.js +3 -13
  309. package/kits/physics-3d/engine3d/cage.js +2 -7
  310. package/kits/physics-3d/engine3d/cageops.js +2 -17
  311. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  312. package/kits/physics-3d/engine3d/framecap.js +4 -1
  313. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  314. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  315. package/kits/physics-3d/engine3d/gait.js +8 -0
  316. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  317. package/kits/physics-3d/engine3d/look.js +7 -0
  318. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  319. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  320. package/kits/physics-3d/engine3d/modelready.js +16 -0
  321. package/kits/physics-3d/engine3d/motion.js +3 -3
  322. package/kits/physics-3d/engine3d/nearshadows.js +77 -10
  323. package/kits/physics-3d/engine3d/orbitinput.js +59 -25
  324. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  325. package/kits/physics-3d/engine3d/paths.js +1 -9
  326. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  327. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  328. package/kits/physics-3d/engine3d/pxmodel.js +3 -3
  329. package/kits/physics-3d/engine3d/rapier.js +27 -0
  330. package/kits/physics-3d/engine3d/scatter.js +1 -11
  331. package/kits/physics-3d/engine3d/shadowfade.js +23 -15
  332. package/kits/physics-3d/engine3d/sky.js +1 -1
  333. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  334. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  335. package/kits/physics-3d/engine3d/sweep.js +1 -25
  336. package/kits/physics-3d/engine3d/world3d.js +468 -18
  337. package/kits/physics-3d/eslint.config.js +2 -1
  338. package/kits/physics-3d/main.jsx +6 -3
  339. package/kits/physics-3d/package-lock.json +7 -0
  340. package/kits/physics-3d/package.json +5 -1
  341. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  342. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  343. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  344. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  345. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  346. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  347. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  348. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  349. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  350. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  351. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  352. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  353. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  354. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  355. package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
  356. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  357. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  358. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
  359. package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  361. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  362. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  363. package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
  364. package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
  365. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
  366. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
  367. package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
  368. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  369. package/kits/physics-3d/scripts/test-sky.mjs +1 -1
  370. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  371. package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
  372. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  373. package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
  374. package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
  375. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  376. package/kits/physics-3d/systems/physics3d.js +37 -4
  377. package/kits/real-time/castle.json +2 -2
  378. package/kits/real-time/code/client/connection.js +33 -10
  379. package/kits/real-time/code/client/gameHooks.js +2 -0
  380. package/kits/real-time/code/client/joinOverlay.js +9 -4
  381. package/kits/real-time/code/server/session.js +6 -4
  382. package/kits/real-time/package-lock.json +1 -1
  383. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { HUD_COPY_STYLE, firstPromptSentence, promptShift, warnHudCopy } from './hudCopy.js';
1
2
  // The hub's own chrome: DOM drawn by the place, never by a game's content, so a
2
3
  // game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
3
4
  // Back control, the declared HUD, actor labels and speech, the result ribbon,
@@ -20,13 +21,24 @@ import { boxAt, fitPx, hudLayout, pushBelow } from './hudClear.js';
20
21
  import { chipShift } from './stuck.js';
21
22
  import { toastBand } from './toastBand.js';
22
23
  import { emoteBubbleShift, placeEmoteBubble } from './emoteBubble.js';
24
+ import { makeActionOverflow } from './actionOverflow.js';
25
+ import { actionLayout } from './actionLayout.js';
23
26
  import { guardScrollKeys, takeKeys } from './keys.js';
24
27
  import { validPrivateText } from '../privateText.js';
25
28
  import { menuIcon } from './menuIcons.js';
29
+ import { drawMenuRows } from './menuRows.js';
30
+ import { landscapeViewport, watchViewport } from './landscapeLayout.js';
31
+ import { loadingCover } from './loadingCover.js';
32
+
33
+ import { makeSafeLayout } from './safeLayout.js';
34
+ import { makeWorldLayout } from './worldLabels.js';
35
+ import { makeLayoutCache, placementCache } from './layoutCache.js';
36
+
37
+ export { landscapeViewport } from './landscapeLayout.js';
26
38
 
27
39
  const Z = 2147480000;
28
40
 
29
- function el(tag, style, parent = document.body) {
41
+ function createElement(tag, style, parent = document.body) {
30
42
  const node = document.createElement(tag);
31
43
  Object.assign(node.style, style);
32
44
  parent.appendChild(node);
@@ -46,7 +58,35 @@ const PICKER_CELL_PX = 64;
46
58
  // The talk panel's log counts as at its end within this many pixels of it.
47
59
  const TALK_END_PX = 8;
48
60
 
49
- export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onHeart = () => {}, onLeaveParty = () => {}, onReportChat = () => {}, onChip }) {
61
+ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onHeart = () => {}, onLeaveParty = () => {}, onReportChat = () => {}, onBlockChat = () => {}, onChip, safeInsets = false, worldLabelsDefault = false }) {
62
+ const geometry = makeLayoutCache();
63
+ const placeActions = placementCache();
64
+ const positionLayers = new WeakSet();
65
+ function el(tag, style, parent = document.body) {
66
+ const node = createElement(tag, style, parent);
67
+ if (style.position === 'absolute' || style.position === 'fixed') {
68
+ geometry.register(node, { positioned: positionLayers.has(parent) || style.transform === 'translate(-50%, -100%)' });
69
+ }
70
+ const remove = node.remove.bind(node);
71
+ node.remove = () => {geometry.unregister(node); remove();};
72
+ const replace = node.replaceChildren?.bind(node);
73
+ if (replace) {node.replaceChildren = (...children) => {
74
+ for (const child of node.children) {geometry.unregister(child);}
75
+ replace(...children);
76
+ };}
77
+ return node;
78
+ }
79
+ let canvasSource = null;
80
+ let safeLayout = null;
81
+ let worldLayout = null;
82
+ let worldViewport = null;
83
+ let worldAvatar = null;
84
+ // The avatar box snapped outward to 16 px, so a walking player does not
85
+ // re-solve or shuffle the action rail every frame.
86
+ let avatarReserve = null;
87
+ const worldObstacles = () => worldAvatar ? [worldAvatar] : [];
88
+ const worldView = () => ({ ...(safeLayout?.view() ?? { w: geometry.view().w, h: geometry.view().h }), ...(worldViewport ? { world: worldViewport } : {}) });
89
+ const edge = (side, px) => safeInsets ? `max(${px}px, env(safe-area-inset-${side}))` : `${px}px`;
50
90
  const unguardKeys = guardScrollKeys();
51
91
  takeKeys();
52
92
  // A desktop stage (a mouse, room to spare): NPC lines are narrower and the
@@ -55,6 +95,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
55
95
  const desktopQuery = globalThis.matchMedia?.('(pointer: fine) and (min-width: 700px)') ?? null;
56
96
  const desktop = () => desktopQuery?.matches === true;
57
97
  const root = el('div', { position: 'fixed', inset: '0', pointerEvents: 'none', zIndex: String(Z), font: '600 15px/1.3 system-ui, sans-serif', color: '#fff' });
98
+ if (loadingCover) { root.setAttribute('data-hub-loading-chrome', ''); }
58
99
 
59
100
  // The door cover: a dark warm field the door animation fades to, with the
60
101
  // destination named in it. It sits over everything while a scene swaps.
@@ -63,7 +104,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
63
104
 
64
105
  let coverLine = null;
65
106
 
66
- const back = el('button', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '12px', 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);
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);
67
108
  back.textContent = '‹ Town';
68
109
  back.addEventListener('pointerdown', (event) => {
69
110
  event.stopPropagation();
@@ -71,14 +112,21 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
71
112
  });
72
113
 
73
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);
74
- const hudTitle = el('div', { fontSize: '13px', opacity: '0.85', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
75
- const hudBig = el('div', { fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
76
- const hudText = el('div', { fontSize: '14px', fontWeight: '500' }, hud);
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';
77
124
 
78
125
  const labels = el('div', { position: 'absolute', inset: '0' }, root);
126
+ positionLayers.add(labels);
79
127
  // v1.43 `measureLabel`: nothing until a deck that keeps its labels apart asks.
80
- let labelMeasure = null;
81
- const labelSizes = new Map();
128
+ const labelMeasures = new Map();
129
+ const usedLabelMeasures = new Set();
82
130
  // Pointers to friends out of sight (a town) and to a place's goals: a small
83
131
  // chip over one far off, or at the screen's edge with an arrow when it is
84
132
  // off screen. v1.34: made here, with the labels, so every panel, card and
@@ -87,11 +135,10 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
87
135
  // v1.38: and put UNDER the labels, so an NPC's speech bubble is read over a
88
136
  // chip (a goal's chip over an NPC cut through the words it was saying).
89
137
  const pointers = el('div', { position: 'absolute', inset: '0' }, root);
138
+ positionLayers.add(pointers);
90
139
  root.insertBefore(pointers, labels);
91
140
  const pointerNodes = new Map();
92
141
  const labelNodes = new Map();
93
- // An emote's emoji -> its drawn size `{ w, h }` (`setLabels`).
94
- const emoteSizes = new Map();
95
142
 
96
143
  // An arcade cabinet's card (v1.7). By the cabinet it is a chip: the best
97
144
  // score and whose it is (their photo in a circle, their frame drawn over it
@@ -194,19 +241,25 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
194
241
  // Where a phone's toast starts, read in pixels: the safe area's inset has
195
242
  // no other way to be measured.
196
243
  const toastStart = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
244
+ 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);
197
245
  let toastWrap = null;
246
+ let toastChoiceBlocked = false;
247
+ function syncToastVisibility() {
248
+ const visibility = toastChoiceBlocked || pickerOpen ? 'hidden' : '';
249
+ if (toast.style.visibility !== visibility) {toast.style.visibility = visibility;}
250
+ }
198
251
 
199
252
  // The avatar picker: one button, "Character", that opens the kit's
200
253
  // characters under their own heading: a grid, four across, each cell the
201
254
  // character's face and name (`avatarFaces.js`, written with the models) and
202
255
  // the one worn ringed in gold. The card never stands taller than the screen
203
- // has room for over the button, and scrolls inside itself where it would;
204
- // a phone on its side lays the grid eight across instead. A cell is picked
256
+ // has room for over the button, and scrolls inside itself where it would
257
+ // (`fitPicker`). A cell is picked
205
258
  // on `click`, not on the press, so a finger that scrolls the card picks
206
259
  // nothing.
207
260
  const overPicker = [];
208
261
  const shutRound = [];
209
- const picker = el('div', { position: 'absolute', right: '10px', bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: '6px', pointerEvents: 'auto' }, root);
262
+ const picker = el('div', { position: 'absolute', right: edge('right', 10), bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: '6px', pointerEvents: 'auto' }, root);
210
263
  picker.addEventListener('pointerdown', (event) => event.stopPropagation());
211
264
  const pickerCard = el('div', { display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', boxSizing: 'border-box', maxWidth: 'calc(100vw - 20px)', overflowY: 'auto', overscrollBehavior: 'contain', touchAction: 'pan-y' }, picker);
212
265
  // What is left over the button and its margins; `dvh` where the browser has
@@ -214,18 +267,77 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
214
267
  for (const unit of ['vh', 'dvh']) {
215
268
  pickerCard.style.maxHeight = `calc(100${unit} - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
216
269
  }
217
- el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard).textContent = 'Your character';
270
+ const pickerHeading = el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard);
271
+ pickerHeading.textContent = 'Your character';
218
272
  const pickerRow = el('div', { display: 'grid', gridTemplateColumns: `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`, gap: '6px' }, pickerCard);
219
273
  const pickerButtons = [];
220
274
  let pickerOpen = false;
221
275
  let pickerSelected = null;
276
+ let inviteRow = null, invitePick = null;
277
+ const pickerHandle = el('div', { width: '32px', height: '4px', borderRadius: '2px', background: 'rgba(255,255,255,0.5)', margin: '2px auto 6px', pointerEvents: 'none' }, pickerCard);
278
+ pickerHandle.dataset.hub = 'picker-handle';
279
+ pickerCard.insertBefore(pickerHandle, pickerHeading);
280
+ const pickerClose = el('button', { minHeight: '44px', padding: '8px 12px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: 'inherit', cursor: 'pointer', display: 'none' }, pickerCard);
281
+ pickerClose.type = 'button'; pickerClose.textContent = 'Close'; pickerClose.setAttribute('aria-label', 'Close character sheet');
282
+ pickerCard.insertBefore(pickerClose, pickerHeading);
283
+ let companionLock = null, companionLockVisibility = null;
284
+ function restoreCompanionLock() {
285
+ if (companionLock && companionLockVisibility !== null) {companionLock.style.visibility = companionLockVisibility;}
286
+ companionLockVisibility = null;
287
+ }
288
+ let pickerFitKey = '';
289
+ // The card is a sheet fitted to the viewport: over the right-side lane above
290
+ // the button, or, on a phone on its side with no room there for the whole
291
+ // sheet, one strip of whole tiles along the bottom with its own Close. Open,
292
+ // it covers the rail, so the rail's buttons are out of sight until it shuts.
293
+ function fitPicker(force = false) {
294
+ const { w, h } = geometry.view();
295
+ const key = `${landscape}:${pickerOpen}:${lockLift}:${pickerCard.children.length}:${inviteRow?.style.display}:${colorRow?.style.display}:${w}:${h}`;
296
+ if (!force && key === pickerFitKey) {return;}
297
+ pickerFitKey = key;
298
+ // Measured once per change of what decides it: a landscape sheet that
299
+ // would scroll in the lane cuts its last row, so it becomes the strip.
300
+ const compact = landscape && (h < 300 || pickerOpen && (layPicker(false), pickerCard.scrollHeight > pickerCard.clientHeight + 1));
301
+ layPicker(compact);
302
+ }
303
+ function layPicker(compact) {
304
+ Object.assign(pickerCard.style, {
305
+ 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
+ });
307
+ for (const unit of ['vh', 'dvh']) {pickerCard.style.maxHeight = `calc(100${unit} - ${compact ? 24 : 80 + lockLift}px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;}
308
+ const tiles = Math.max(1, Math.floor((geometry.view().w - 26) / (PICKER_CELL_PX + 6)));
309
+ const stripWidth = tiles * (PICKER_CELL_PX + 6) - 6;
310
+ Object.assign(pickerCard.style, { width: compact ? `${stripWidth + 8}px` : '', padding: compact ? '4px' : '8px 8px 24px', gap: compact ? '2px' : '6px', overflowY: compact ? 'hidden' : 'auto', gridTemplateColumns: compact ? '1fr auto' : '', touchAction: compact ? 'pan-x' : 'pan-y' });
311
+ pickerCard.style.display = pickerOpen ? compact ? 'grid' : 'flex' : 'none';
312
+ for (const child of pickerCard.children) {
313
+ child.style.flexShrink = '0';
314
+ // Close keeps the right-hand column with or without Invite beside it.
315
+ child.style.gridColumn = !compact ? '' : child === pickerClose ? '2' : child === inviteRow ? '1' : '1 / -1';
316
+ }
317
+ pickerHandle.style.display = compact ? 'none' : 'block';
318
+ pickerClose.style.display = compact ? '' : 'none';
319
+ pickerHeading.style.display = compact ? 'none' : '';
320
+ Object.assign(pickerRow.style, { gridTemplateColumns: compact ? 'none' : `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`, gridAutoFlow: compact ? 'column' : '', gridAutoColumns: compact ? `${PICKER_CELL_PX}px` : '', width: compact ? `${stripWidth}px` : '', overflowX: compact ? 'auto' : '', overflowY: compact ? 'hidden' : '', scrollSnapType: compact ? 'x mandatory' : '', scrollbarWidth: compact ? 'none' : '', touchAction: compact ? 'pan-x' : '' });
321
+ for (const button of pickerButtons) {
322
+ Object.assign(button.style, { scrollSnapAlign: compact ? 'start' : '', scrollSnapStop: compact ? 'always' : '', touchAction: compact ? 'pan-x' : 'pan-y' });
323
+ }
324
+ pickerToggle.style.visibility = compact && pickerOpen ? 'hidden' : '';
325
+ dock.style.visibility = compact && pickerOpen ? 'hidden' : '';
326
+ if (compact && pickerOpen && companionLock) {
327
+ if (companionLockVisibility === null) {companionLockVisibility = companionLock.style.visibility ?? '';}
328
+ companionLock.style.visibility = 'hidden';
329
+ } else {restoreCompanionLock();}
330
+ for (const node of railNodes) {
331
+ if (node !== picker && !overPicker.includes(node)) {node.style.visibility = pickerOpen ? 'hidden' : '';}
332
+ }
333
+ syncToastVisibility();
334
+ }
222
335
  const setPickerOpen = (open) => {
223
336
  pickerOpen = open;
337
+ picker.style.zIndex = open ? '4' : '';
224
338
  showCompanionBadge();
225
339
  if (open) {
226
- // A short, wide screen (a phone on its side) has room for two rows of eight.
227
- const wide = window.innerHeight < 440 && window.innerWidth >= 8 * (PICKER_CELL_PX + 6) + 30;
228
- pickerRow.style.gridTemplateColumns = `repeat(${wide ? PICKER_COLUMNS * 2 : PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`;
340
+ pickerRow.style.gridTemplateColumns = `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`;
229
341
  }
230
342
  // Open, the card lies under the round buttons up the right edge and the
231
343
  // talk button along the bottom, which would take its taps; they are out
@@ -238,8 +350,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
238
350
  shut();
239
351
  }
240
352
  }
241
- pickerCard.style.display = open ? 'flex' : 'none';
353
+ fitPicker();
242
354
  };
355
+ pickerClose.addEventListener('click', (event) => {event.stopPropagation(); setPickerOpen(false);});
243
356
  for (let i = 0; i < avatarCount; i += 1) {
244
357
  // A character this kit has no face for is a number, as all of them were.
245
358
  const [name, face] = AVATAR_FACES[i] ?? [`Character ${i + 1}`, null];
@@ -292,7 +405,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
292
405
  if (!colorRow) {
293
406
  colorRow = document.createElement('div');
294
407
  Object.assign(colorRow.style, { display: 'flex', gap: '4px', justifyContent: 'center' });
295
- pickerCard.insertBefore(colorRow, pickerRow.nextSibling ?? pickerCard.children[2] ?? null);
408
+ pickerCard.insertBefore(colorRow, pickerRow.nextSibling ?? [...pickerCard.children][[...pickerCard.children].indexOf(pickerRow) + 1] ?? null);
296
409
  for (let c = 0; c < Colors.COLORS; c += 1) {
297
410
  const button = el('button', { width: '44px', height: '44px', boxSizing: 'border-box', flex: 'none', padding: '6px', borderRadius: '50%', border: '2px solid transparent', cursor: 'pointer', touchAction: 'pan-y' }, colorRow);
298
411
  button.setAttribute('aria-label', `Colour: ${c + 1}`);
@@ -317,11 +430,13 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
317
430
  // device tiers (`tiers.js`). Built on the first `setGraphics`, so a deck
318
431
  // without them draws the card as it always was.
319
432
  let graphics = null;
320
- function buildGraphics() {
433
+ function buildGraphics(weakest = false) {
321
434
  const row = el('div', { display: 'flex', alignItems: 'center', gap: '6px', marginTop: '2px' }, pickerCard);
322
435
  el('div', { fontSize: '12px', opacity: '0.8', flex: '1' }, row).textContent = 'Graphics';
323
436
  const buttons = new Map();
324
- for (const [mode, text] of [['auto', 'Auto'], ['low', 'Low'], ['high', 'High']]) {
437
+ const modes = [['auto', 'Auto'], ['low', 'Low'], ['high', 'High']];
438
+ if (weakest) { modes.splice(2, 0, ['weakest', 'Weakest']); }
439
+ for (const [mode, text] of modes) {
325
440
  const button = el('button', { padding: '4px 9px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 12px system-ui, sans-serif', cursor: 'pointer' }, row);
326
441
  button.textContent = text;
327
442
  button.setAttribute('aria-label', `Graphics: ${text}`);
@@ -357,6 +472,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
357
472
  talkHandlers.end();
358
473
  });
359
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 });
360
476
  // v1.46: the mind is answering; reduced motion keeps a plain ellipsis.
361
477
  const typingStyle = el('style', {}, root);
362
478
  typingStyle.textContent = `
@@ -372,19 +488,29 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
372
488
  let panelTyping = null;
373
489
  let panelMind = false;
374
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
+ };
375
498
  const dropTyping = () => {
376
499
  panelTyping?.remove();
377
500
  panelTyping = null;
378
501
  };
379
502
  // The questions are made only while there are some to offer.
380
503
  let panelAsks = null;
504
+ let panelChildAsks = false;
381
505
  let asksHandler = null;
382
506
  // The row is taken out again, not hidden: the panel of a conversation with
383
507
  // no questions has the nodes it always had.
384
508
  const dropAsks = () => {
385
509
  panelAsks?.remove();
386
510
  panelAsks = null;
511
+ panelChildAsks = false;
387
512
  asksHandler = null;
513
+ syncTalkSurfaces();
388
514
  };
389
515
  // Not a <form>: castle.xyz plays a deck in a frame sandboxed without
390
516
  // `allow-forms`, where a form's submission (Enter, or a submit button) is
@@ -410,7 +536,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
410
536
  panelForm.style.display = allowed ? 'flex' : 'none';
411
537
  if (!allowed) {
412
538
  panelInput.blur();
413
- dropAsks();
539
+ if (!panelChildAsks) {dropAsks();}
414
540
  } else if (wasHidden && globalThis.matchMedia?.('(pointer: fine)').matches && !(globalThis.navigator?.maxTouchPoints > 0)) {
415
541
  panelInput.focus({ preventScroll: true });
416
542
  }
@@ -446,12 +572,50 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
446
572
  submitTalk();
447
573
  });
448
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
+ }
589
+
590
+ function syncHudPrompt() {
591
+ const display = hudPromptAsked && !doorsOpen && !(talkOpen && panelAsks) ? 'block' : 'none';
592
+ hudText.style.display = display;
593
+ }
594
+ function syncTalkSurfaces() {
595
+ syncTalkCaption();
596
+ syncHudPrompt();
597
+ placeToast();
598
+ }
449
599
  const layoutPanel = () => {
600
+ const landscape = landscapeViewport();
450
601
  const wide = desktop();
451
- Object.assign(panel.style, wide
452
- ? { left: '10px', transform: 'none', width: '340px' }
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' }
453
606
  : { left: '50%', transform: 'translateX(-50%)', width: 'min(92vw, 420px)' });
454
- panelLog.style.maxHeight = wide ? 'min(28vh, 220px)' : '28vh';
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
+ }
455
619
  };
456
620
  layoutPanel();
457
621
  desktopQuery?.addEventListener?.('change', layoutPanel);
@@ -459,7 +623,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
459
623
  // Grab / Throw (v1.3): a big thumb button bottom right, above the avatar
460
624
  // picker, shown while there is something to grab or something held.
461
625
  let grabHandler = () => {};
462
- const grabButton = el('button', { position: 'absolute', right: '14px', 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);
626
+ 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);
463
627
  grabButton.addEventListener('pointerdown', (event) => {
464
628
  event.stopPropagation();
465
629
  event.preventDefault();
@@ -471,11 +635,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
471
635
  let emoteHandler = () => {};
472
636
  let sitHandler = () => {};
473
637
  const emoteBottom = 'max(146px, calc(env(safe-area-inset-bottom) + 136px))';
474
- const emoteButton = el('button', { position: 'absolute', right: '20px', bottom: emoteBottom, width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '24px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
638
+ const emoteButton = el('button', { position: 'absolute', right: edge('right', 20), bottom: emoteBottom, width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '24px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
475
639
  overPicker.push(emoteButton);
476
640
  emoteButton.textContent = '☺';
477
641
  emoteButton.setAttribute('aria-label', 'Emote');
478
- const emoteRow = el('div', { position: 'absolute', right: '80px', bottom: emoteBottom, display: 'none', gap: '6px', pointerEvents: 'auto', padding: '4px', borderRadius: '28px', background: 'rgba(20,16,12,0.78)' }, root);
642
+ const emoteRow = el('div', { position: 'absolute', right: edge('right', 80), bottom: emoteBottom, display: 'none', gap: '6px', pointerEvents: 'auto', padding: '4px', borderRadius: '28px', background: 'rgba(20,16,12,0.78)' }, root);
479
643
  emoteRow.addEventListener('pointerdown', (event) => event.stopPropagation());
480
644
  let emotesOpen = false;
481
645
  let emotesKey = '';
@@ -494,11 +658,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
494
658
  // button opens a small card, a row of emoji over the place's phrases; and
495
659
  // the feed of what was just said, small, above the dock.
496
660
  let sayHandler = () => {};
497
- const sayButton = el('button', { position: 'absolute', right: '20px', bottom: 'max(206px, calc(env(safe-area-inset-bottom) + 196px))', width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '22px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
661
+ const sayButton = el('button', { position: 'absolute', right: edge('right', 20), bottom: 'max(206px, calc(env(safe-area-inset-bottom) + 196px))', width: '52px', height: '52px', borderRadius: '26px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.5)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '22px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
498
662
  overPicker.push(sayButton);
499
663
  sayButton.textContent = '💬';
500
664
  sayButton.setAttribute('aria-label', 'Quick chat');
501
- const sayCard = el('div', { position: 'absolute', right: '80px', bottom: 'max(146px, calc(env(safe-area-inset-bottom) + 136px))', width: 'min(70vw, 236px)', display: 'none', flexDirection: 'column', gap: '6px', pointerEvents: 'auto', padding: '8px', borderRadius: '14px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
665
+ const sayCard = el('div', { position: 'absolute', right: edge('right', 80), bottom: 'max(146px, calc(env(safe-area-inset-bottom) + 136px))', width: 'min(70vw, 236px)', display: 'none', flexDirection: 'column', gap: '6px', pointerEvents: 'auto', padding: '8px', borderRadius: '14px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
502
666
  sayCard.addEventListener('pointerdown', (event) => event.stopPropagation());
503
667
  let sayOpen = false;
504
668
  let sayKey = '';
@@ -516,8 +680,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
516
680
  setSayOpen(!sayOpen);
517
681
  setEmotesOpen(false);
518
682
  });
519
- const feed = el('div', { position: 'absolute', left: '10px', bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: BARE_TEXT_SHADOW, opacity: '0.92' }, root);
683
+ const feed = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: BARE_TEXT_SHADOW, opacity: '0.92' }, root);
520
684
  let feedKey = '';
685
+ let chatModeration = false;
521
686
  const sitButton = el('button', { position: 'absolute', bottom: 'max(112px, calc(env(safe-area-inset-bottom) + 102px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 22px', 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', touchAction: 'manipulation' }, root);
522
687
  sitButton.addEventListener('pointerdown', (event) => {
523
688
  event.stopPropagation();
@@ -527,16 +692,28 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
527
692
 
528
693
  // Bottom left: the town's Doors, then People, side by side -- or People
529
694
  // above Doors where a narrow screen leaves no room beside the avatar picker.
530
- const dock = el('div', { position: 'absolute', left: '10px', bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'flex', flexWrap: 'wrap-reverse', alignItems: 'flex-start', gap: '6px', maxWidth: 'calc(100vw - 130px)' }, root);
695
+ const dock = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'flex', flexWrap: 'wrap-reverse', alignItems: 'flex-start', gap: '6px', maxWidth: 'calc(100vw - 130px)' }, root);
531
696
  // A list opens just above the dock, however tall the dock is.
532
697
  const aboveDock = (list) => {
533
- list.style.bottom = `calc(max(10px, env(safe-area-inset-bottom)) + ${dock.offsetHeight + 6}px)`;
698
+ if (landscapeViewport()) {
699
+ list.style.bottom = '';
700
+ const top = `max(68px, env(safe-area-inset-top) + 56px) + ${geometry.size(dock).h + 6}px`;
701
+ list.style.top = `calc(${top})`;
702
+ list.style.maxHeight = `calc(100dvh - (${top}) - max(12px, env(safe-area-inset-bottom)))`;
703
+ return;
704
+ }
705
+ list.style.top = '';
706
+ const bottom = `max(10px, env(safe-area-inset-bottom)) + ${geometry.size(dock).h + 6}px`;
707
+ list.style.bottom = `calc(${bottom})`;
708
+ list.style.maxHeight = `min(40vh, calc(100dvh - (${bottom}) - max(68px, env(safe-area-inset-top) + 56px)))`;
534
709
  };
535
710
  const doorsButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
711
+ geometry.register(doorsButton);
536
712
  doorsButton.textContent = 'Doors';
537
713
  // The town's doors: the list opens above the dock, one list at a time, and
538
714
  // Go puts the player in front of that door.
539
- const doorsList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
715
+ const doorsList = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', touchAction: 'pan-y', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', flexDirection: 'column', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
716
+ const doorsBody = el('div', { display: 'flex', flexDirection: 'column', gap: '6px', flexShrink: '0', paddingBottom: '8px' }, doorsList);
540
717
  doorsList.addEventListener('pointerdown', (event) => event.stopPropagation());
541
718
  let doorsOpen = false;
542
719
  let doorsKey = '';
@@ -546,6 +723,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
546
723
  doorsOpen = false;
547
724
  showCompanionBadge();
548
725
  doorsList.style.display = 'none';
726
+ syncHudPrompt();
549
727
  }
550
728
  doorsButton.addEventListener('pointerdown', (event) => {
551
729
  event.stopPropagation();
@@ -553,13 +731,16 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
553
731
  showCompanionBadge();
554
732
  aboveDock(doorsList);
555
733
  doorsList.style.display = doorsOpen ? 'flex' : 'none';
734
+ syncHudPrompt();
556
735
  closePeople();
557
736
  });
558
737
 
559
738
  // The other players here, each with Report behind a confirm. Hub chrome
560
739
  // only: a game's content cannot draw, hide or press it.
561
740
  const peopleButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
562
- const peopleList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
741
+ geometry.register(peopleButton);
742
+ const peopleList = el('div', { position: 'absolute', left: edge('left', 10), bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', touchAction: 'pan-y', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', flexDirection: 'column', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
743
+ const peopleBody = el('div', { display: 'flex', flexDirection: 'column', gap: '6px', flexShrink: '0', paddingBottom: '8px' }, peopleList);
563
744
  peopleList.addEventListener('pointerdown', (event) => event.stopPropagation());
564
745
  let peopleOpen = false;
565
746
  let peopleKey = '';
@@ -594,7 +775,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
594
775
  // first: the question, then Report / Cancel. Returns the node its `where`
595
776
  // words live in, so they change without the row being rebuilt.
596
777
  function personRow(person) {
597
- const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' }, peopleList);
778
+ const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' }, peopleBody);
598
779
  let whereNode = null;
599
780
  let more = false;
600
781
  const act = (parent, action, primary) => {
@@ -663,16 +844,44 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
663
844
  // their party wants to go through. One at a time, under the HUD.
664
845
  const askCard = el('div', { position: 'absolute', top: 'max(92px, calc(env(safe-area-inset-top) + 80px))', left: '50%', transform: 'translateX(-50%)', width: 'min(86vw, 320px)', boxSizing: 'border-box', pointerEvents: 'auto', display: 'none', alignItems: 'center', gap: '8px', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.9)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', fontSize: '14px' }, root);
665
846
  askCard.addEventListener('pointerdown', (event) => event.stopPropagation());
847
+ // A suspended page can foreground before its first engine frame. Hide the
848
+ // old DOM at the lifecycle boundary so an overdue card cannot flash while
849
+ // that frame ages its existing lease. Keep its key and payload: a short
850
+ // absence may show the same still-live occurrence again on the next frame.
851
+ const askLifecycle = new AbortController();
852
+ let askAway = document.visibilityState === 'hidden' || document.hidden === true;
853
+ const hideAsk = () => {
854
+ askAway = true;
855
+ askCard.style.display = 'none';
856
+ };
857
+ const resumeAskFrames = () => { askAway = false; };
858
+ const askHidden = () => askAway || document.visibilityState === 'hidden' || document.hidden === true;
859
+ document.addEventListener?.('visibilitychange', () => {
860
+ if (document.visibilityState === 'hidden' || document.hidden === true) {
861
+ hideAsk();
862
+ } else {
863
+ resumeAskFrames();
864
+ }
865
+ }, { signal: askLifecycle.signal });
866
+ globalThis.window?.addEventListener?.('pagehide', hideAsk, { signal: askLifecycle.signal });
867
+ globalThis.window?.addEventListener?.('pageshow', resumeAskFrames, { signal: askLifecycle.signal });
666
868
  let askKey = '';
667
869
  let askNow = null;
668
- function heartButton(parent, door, hearted) {
870
+ // `fromAsk`: the button is on the ask card, so the tap carries the card it
871
+ // was drawn for (`onHeart(door, ask)`) for the lease to validate. A Doors
872
+ // list heart is `onHeart(door)`.
873
+ function heartButton(parent, door, hearted, fromAsk = false) {
669
874
  const button = smallButton(parent, hearted ? '♥' : '♡', false);
670
875
  button.style.flex = 'none';
671
876
  button.setAttribute('aria-label', hearted ? 'Remove heart' : 'Heart this game');
672
877
  button.setAttribute('aria-pressed', String(hearted));
673
878
  button.addEventListener('pointerdown', (event) => {
674
879
  event.stopPropagation();
675
- onHeart(door);
880
+ if (fromAsk) {
881
+ onHeart(door, askNow);
882
+ } else {
883
+ onHeart(door);
884
+ }
676
885
  });
677
886
  }
678
887
  // Standing by someone who is not in the player's party: invite them.
@@ -699,7 +908,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
699
908
  if (!node || node.style.display === 'none') {
700
909
  return null;
701
910
  }
702
- const r = node.getBoundingClientRect();
911
+ const r = geometry.rect(node);
703
912
  return r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
704
913
  };
705
914
  // Measured only while a toast is up, on every setToast (said each frame, so
@@ -713,14 +922,24 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
713
922
  if (toast.style.display === 'none') {
714
923
  return;
715
924
  }
716
- const wide = desktop();
717
- const width = toast.offsetWidth;
718
- const height = toast.offsetHeight;
719
- const rects = [hud, askCard, back, sound?.button, sound?.card, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard].map(shownRect).filter(Boolean);
925
+ // A landscape viewport keeps transient words in the top-centre band even
926
+ // with a mouse attached; this is the same visual lane on phones/tablets.
927
+ const wide = desktop() && !landscapeViewport();
928
+ const width = geometry.size(toast).w;
929
+ const height = geometry.size(toast).h;
930
+ const rects = [hud, hudText, ribbon, askCard, back, sound?.button, sound?.card, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard].map(shownRect).filter(Boolean);
720
931
  if (stuckSpot) {
721
932
  rects.push(stuckSpot);
722
933
  }
723
- const band = toastBand({ desktop: wide, viewW: window.innerWidth, viewH: window.innerHeight, width, height, rects, start: Math.max(12, toastStart.offsetTop || 0) });
934
+ 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
+ // With no free band toastBand clamps into the viewport. Choices win
936
+ // over transient feedback even when that fallback cannot fit above them.
937
+ const choices = talkOpen ? shownRect(panelAsks) : null;
938
+ const top = wide ? geometry.view().h - band.bottom - height : band.top;
939
+ const left = (geometry.view().w - width) / 2;
940
+ const blocked = choices && left < choices.right && left + width > choices.left && top < choices.bottom && top + height > choices.top;
941
+ toastChoiceBlocked = Boolean(blocked);
942
+ syncToastVisibility();
724
943
  const nextTop = wide ? '' : `${band.top}px`;
725
944
  const nextBottom = wide ? `${band.bottom}px` : '';
726
945
  if (toast.style.top !== nextTop) {
@@ -746,13 +965,13 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
746
965
  // read first, then the one style is written. Only while the chip is asked
747
966
  // for; false when it cannot be drawn.
748
967
  function placeStuckChip() {
749
- const w = stuckChip.offsetWidth;
750
- const h = stuckChip.offsetHeight;
751
- const left = stuckChip.offsetLeft - w / 2;
752
- const top = stuckChip.offsetTop;
968
+ const w = geometry.size(stuckChip).w;
969
+ const h = geometry.size(stuckChip).h;
970
+ const left = geometry.offsets(stuckChip).left - w / 2;
971
+ const top = geometry.offsets(stuckChip).top;
753
972
  const above = [hud, askCard].map(shownRect).filter(Boolean);
754
- const others = [back, toast, picker, talkButton, grabButton, emoteButton, emoteRow, sayButton, sayCard, feed, sitButton, dock, nearButton, stats, cabinet, ribbon, sound?.button, sound?.card].map(shownRect).filter(Boolean);
755
- const down = chipShift({ left, right: left + w, top, bottom: top + h }, above, others, window.innerHeight);
973
+ const others = [hudText, back, toast, picker, talkButton, grabButton, emoteButton, emoteRow, sayButton, sayCard, feed, sitButton, dock, nearButton, stats, cabinet, ribbon, sound?.button, sound?.card].map(shownRect).filter(Boolean);
974
+ const down = chipShift({ left, right: left + w, top, bottom: top + h }, above, others, geometry.view().h);
756
975
  if (down === null) {
757
976
  return false;
758
977
  }
@@ -775,16 +994,17 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
775
994
  }
776
995
 
777
996
  // The sound control (a deck with `hub.soundscape`, `soundscape.js`): a small
778
- // speaker button in the top right corner, clear of the HUD's 70vw and of
997
+ // speaker button below the native camera corner, clear of the HUD and of
779
998
  // the column of round buttons at the bottom right; a tap opens a card under
780
999
  // it with Mute and a volume slider. Built on the first `soundControl`, so a
781
1000
  // deck without the key has no node of it.
782
1001
  let sound = null;
1002
+ const soundTop = 'max(64px, calc(env(safe-area-inset-top) + 64px))';
783
1003
  function buildSound() {
784
- const top = 'max(12px, env(safe-area-inset-top))';
785
- const button = el('button', { position: 'absolute', top, right: '12px', width: '40px', height: '40px', borderRadius: '20px', pointerEvents: 'auto', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: '18px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
1004
+ const top = soundTop;
1005
+ const button = el('button', { position: 'absolute', top, right: edge('right', 12), width: '40px', height: '40px', borderRadius: '20px', pointerEvents: 'auto', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: '18px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none', padding: '0' }, root);
786
1006
  button.dataset.hub = 'sound';
787
- const card = el('div', { position: 'absolute', top: `calc(${top} + 46px)`, right: '12px', width: 'min(70vw, 208px)', boxSizing: 'border-box', display: 'none', alignItems: 'center', gap: '8px', pointerEvents: 'auto', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
1007
+ const card = el('div', { position: 'absolute', top: `calc(${top} + 46px)`, right: edge('right', 12), width: 'min(70vw, 208px)', boxSizing: 'border-box', display: 'none', alignItems: 'center', gap: '8px', pointerEvents: 'auto', padding: '8px 10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
788
1008
  card.dataset.hub = 'sound-card';
789
1009
  card.addEventListener('pointerdown', (event) => event.stopPropagation());
790
1010
  const mute = el('button', { flex: 'none', padding: '5px 10px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.35)', background: 'transparent', color: '#fff', font: '700 13px system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation' }, card);
@@ -800,6 +1020,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
800
1020
  event.preventDefault();
801
1021
  made.open = !made.open;
802
1022
  card.style.display = made.open ? 'flex' : 'none';
1023
+ layoutLandscapeRail();
803
1024
  });
804
1025
  mute.addEventListener('pointerdown', (event) => {
805
1026
  event.stopPropagation();
@@ -812,7 +1033,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
812
1033
  return made;
813
1034
  }
814
1035
 
815
- const stats = el('div', { position: 'absolute', right: '8px', top: 'max(8px, env(safe-area-inset-top))', font: '11px/1.3 ui-monospace, monospace', opacity: '0.7', textAlign: 'right', whiteSpace: 'pre' }, root);
1036
+ const stats = el('div', { position: 'absolute', right: edge('right', 8), top: 'max(8px, env(safe-area-inset-top))', font: '11px/1.3 ui-monospace, monospace', opacity: '0.7', textAlign: 'right', whiteSpace: 'pre' }, root);
816
1037
 
817
1038
  // A clear HUD (v1.26, `hudClear.js`), in a place whose manifest asks for it
818
1039
  // (`setHudClear`). Everything below runs only then, or once as the option
@@ -821,64 +1042,51 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
821
1042
  let hudClear = false;
822
1043
  let hudClearDrawn = false;
823
1044
  let hudClearKey = '';
824
- let hudClearRect = null;
825
- const hudClearSizes = new WeakMap();
826
1045
  // The place before asked and this one does not: the styles of old, put
827
1046
  // back the moment the option goes, whether or not a HUD is drawn after.
828
1047
  function restoreHudClear() {
829
1048
  hudBig.style.fontSize = '56px';
830
- for (const key of ['whiteSpace', 'overflow', 'textOverflow', 'maxWidth', 'marginLeft', 'marginRight']) {
1049
+ for (const key of ['whiteSpace', 'overflow', 'textOverflow']) {
831
1050
  hudBig.style[key] = '';
832
1051
  }
833
- for (const key of ['display', 'overflow', 'webkitLineClamp', 'webkitBoxOrient']) {
834
- hudText.style[key] = '';
835
- }
1052
+ hudBig.style.maxWidth = '100%';
836
1053
  hud.style.maxHeight = '';
837
1054
  hud.style.overflow = '';
838
1055
  hudClearDrawn = false;
839
1056
  hudClearKey = '';
840
- hudClearRect = null;
841
1057
  hudClearPending.clear();
842
1058
  }
843
1059
  function layoutHudClear(big, text) {
844
1060
  hudClearDrawn = true;
845
1061
  const backShown = back.style.display !== 'none';
846
- const key = [hudTitle.textContent, big, text, window.innerWidth, window.innerHeight, backShown ? back.textContent : ''].join('\u0001');
847
- if (key === hudClearKey) {
848
- return;
849
- }
850
- hudClearKey = key;
1062
+ const backBox = geometry.rect(back);
1063
+ const key = [hudTitle.textContent, big, text, geometry.view().w, geometry.view().h, backShown ? back.textContent : '', backBox.left, backBox.right].join('\u0001');
851
1064
  const layout = hudLayout({
852
1065
  big,
853
1066
  text,
854
- viewW: window.innerWidth,
855
- viewH: window.innerHeight,
1067
+ viewW: geometry.view().w,
1068
+ viewH: geometry.view().h,
856
1069
  // The big line's row is the Back button's: it keeps out of its way.
857
- reserve: backShown ? back.offsetLeft + back.offsetWidth + 8 : 0,
1070
+ reserve: backShown ? geometry.offsets(back).left + geometry.size(back).w + 8 : 0,
858
1071
  });
859
- hudBig.style.fontSize = `${layout.bigPx}px`;
860
- hudBig.style.whiteSpace = layout.bigOneLine ? 'nowrap' : '';
861
- hudBig.style.overflow = layout.bigOneLine ? 'hidden' : '';
862
- hudBig.style.textOverflow = layout.bigOneLine ? 'ellipsis' : '';
863
- hudBig.style.maxWidth = layout.bigMaxWidth === null ? '' : `${layout.bigMaxWidth}px`;
864
- hudBig.style.marginLeft = layout.bigMaxWidth === null ? '' : 'auto';
865
- hudBig.style.marginRight = layout.bigMaxWidth === null ? '' : 'auto';
866
- hudText.style.display = layout.textLines === null ? '' : '-webkit-box';
867
- hudText.style.overflow = layout.textLines === null ? '' : 'hidden';
868
- hudText.style.webkitLineClamp = layout.textLines === null ? '' : String(layout.textLines);
869
- hudText.style.webkitBoxOrient = layout.textLines === null ? '' : 'vertical';
870
- hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
871
- hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
1072
+ if (key !== hudClearKey) {
1073
+ hudClearKey = key;
1074
+ hudBig.style.fontSize = `${layout.bigPx}px`;
1075
+ hudBig.style.whiteSpace = layout.bigOneLine ? 'nowrap' : '';
1076
+ hudBig.style.overflow = layout.bigOneLine ? 'hidden' : '';
1077
+ hudBig.style.textOverflow = layout.bigOneLine ? 'ellipsis' : '';
1078
+ hudBig.style.maxWidth = layout.bigMaxWidth === null ? '100%' : `${layout.bigMaxWidth}px`;
1079
+ hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
1080
+ hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
1081
+ }
872
1082
  if (layout.bigOneLine) {
873
- // The estimate fell short of this face: shrink to what was drawn.
874
- const px = fitPx(layout.bigPx, hudBig.clientWidth, hudBig.scrollWidth);
875
- if (px !== layout.bigPx) {
876
- hudBig.style.fontSize = `${px}px`;
1083
+ const fit = geometry.fit(hudBig);
1084
+ if (!geometry.active() || (fit.text === String(big) && fit.fontSize === hudBig.style.fontSize)) {
1085
+ const base = Number.parseFloat(fit.fontSize) || layout.bigPx;
1086
+ const px = fitPx(base, fit.client, fit.scroll);
1087
+ if (px < base) {hudBig.style.fontSize = `${px}px`;}
877
1088
  }
878
1089
  }
879
- // The box as it is drawn now; it changes only with what the key holds.
880
- const r = hud.getBoundingClientRect();
881
- hudClearRect = r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
882
1090
  }
883
1091
  // What a frame's setters ask to be kept clear of the HUD, by group
884
1092
  // ("labels", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
@@ -907,32 +1115,27 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
907
1115
  if (!hudClearPending.size) {
908
1116
  return;
909
1117
  }
910
- const groups = [...hudClearPending.values()];
1118
+ const groups = [...hudClearPending.entries()];
911
1119
  hudClearPending.clear();
912
- const rect = hudClear && hud.style.display !== 'none' ? hudClearRect : null;
913
- if (!rect) {
1120
+ const rect = hudClear && hud.style.display !== 'none' ? shownRect(hud) : null;
1121
+ const prompt = shownRect(hudText);
1122
+ if (!rect && !prompt) {
914
1123
  return;
915
1124
  }
916
1125
  const moves = [];
917
- for (const entries of groups) {
918
- for (const [node, x, y, anchor, text] of entries) {
1126
+ for (const [group, entries] of groups) {
1127
+ for (const [node, x, y, anchor] of entries) {
919
1128
  // One since hidden or taken away is left alone.
920
1129
  if (!node || node.style.display === 'none' || !Number.isFinite(x) || !Number.isFinite(y)) {
921
1130
  continue;
922
1131
  }
923
- // Its size is measured once for each `text` it shows -- and, for a
924
- // bubble that wraps by the room to its right (speech with no width
925
- // of its own), again whenever it moves sideways.
926
- const wraps = node.style.whiteSpace === 'normal' && node.style.width !== 'max-content';
927
- const key = [text, node.style.fontSize, node.style.maxWidth, node.style.padding, window.innerWidth, wraps ? node.style.left : ''].join('\u0001');
928
- let box = hudClearSizes.get(node);
929
- if (!box || box.key !== key) {
930
- box = { key, w: node.offsetWidth, h: node.offsetHeight };
931
- hudClearSizes.set(node, box);
932
- }
933
- const down = pushBelow(boxAt(x, y, box.w, box.h, anchor), rect, undefined, window.innerHeight);
934
- if (down > 0) {
935
- moves.push([node, y + down]);
1132
+ // Unchanged labels use their snapshot size; changed copy or wrapping
1133
+ // is refreshed once before this batch writes clearance positions.
1134
+ const box = geometry.size(node);
1135
+ 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;
1137
+ if (down + up !== 0) {
1138
+ moves.push([node, y + down + up]);
936
1139
  }
937
1140
  }
938
1141
  }
@@ -943,16 +1146,162 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
943
1146
 
944
1147
  // v1.74: made only when an opted-in place offers chips.
945
1148
  let actionChips = null, actionKey = '', actionHandler = null, actionListeners = null;
946
- function clearActions() {
1149
+ let actionIdentity = 0;
1150
+ let actionOverflow = null, actionOverflowOpen = null, actionOverflowObstacles = null;
1151
+ const actionSize = (node) => {
1152
+ const box = geometry.rect(node), size = geometry.size(node);
1153
+ return { w: box.width || size.w, h: box.height || size.h };
1154
+ };
1155
+ let overflowSources = new Set();
1156
+ function syncOverflowSources() {
1157
+ const nodes = new Set(actionOverflow?.surfaces?.() ?? []);
1158
+ for (const node of overflowSources) {if (!nodes.has(node)) {geometry.unregister(node);}}
1159
+ for (const node of nodes) {if (!overflowSources.has(node)) {geometry.register(node);}}
1160
+ overflowSources = nodes;
1161
+ }
1162
+ function clearLegacyActions() {
947
1163
  actionListeners?.abort();
948
1164
  actionChips?.remove();
949
1165
  actionChips = actionListeners = actionHandler = null;
950
1166
  actionKey = '';
951
1167
  }
1168
+ function clearActions() {
1169
+ clearLegacyActions();
1170
+ actionOverflow?.dispose();
1171
+ actionOverflow = null;
1172
+ syncOverflowSources();
1173
+ actionOverflowOpen = actionOverflowObstacles = null;
1174
+ }
1175
+
1176
+ // A turned phone reserves its lower-left half for the engine's drag stick.
1177
+ // Hub actions form one compact rail on the right; town navigation moves to
1178
+ // the upper-left, below the native 64 x 56 exit exclusion and the kit Back
1179
+ // button. Portrait values below are the original values byte-for-byte.
1180
+ let landscape = landscapeViewport();
1181
+ let textAsk = null;
1182
+ let placeMenu = null;
1183
+ // The nodes a row sheet covers (`coverControls`).
1184
+ const menuCovered = new Set();
1185
+ const railNodes = [picker, grabButton, emoteButton, sayButton, sitButton, talkButton, nearButton];
1186
+ const railHeight = (node) => Number.parseFloat(node.style.height) || geometry.size(node).h;
1187
+ function layoutLandscapeRail() {
1188
+ if (safeInsets) {return;}
1189
+ if (!landscape) {
1190
+ return;
1191
+ }
1192
+ const baseBottom = 10 + lockLift;
1193
+ let bottom = baseBottom;
1194
+ let right = 12;
1195
+ let columnWidth = 0;
1196
+ const placed = new Map();
1197
+ const ceiling = Math.max(
1198
+ safeInsets ? 108 + (safeLayout?.view().insets.top ?? 0) : Math.max(64, Math.min(geometry.view().h - 44, 76)),
1199
+ shownRect(sound?.button)?.bottom + 6 || 0,
1200
+ shownRect(sound?.card)?.bottom + 6 || 0,
1201
+ );
1202
+ for (const node of railNodes) {
1203
+ if (node.style.display === 'none' || node.style.visibility === 'hidden') {
1204
+ continue;
1205
+ }
1206
+ const height = railHeight(node);
1207
+ if (bottom > baseBottom && geometry.view().h - bottom - height < ceiling) {
1208
+ right += columnWidth + 6;
1209
+ bottom = baseBottom;
1210
+ columnWidth = 0;
1211
+ }
1212
+ node.style.right = safeInsets ? `calc(max(12px, env(safe-area-inset-right)) + ${right - 12}px)` : `${right}px`;
1213
+ node.style.bottom = `max(${bottom}px, calc(env(safe-area-inset-bottom) + ${Math.max(0, bottom - 10)}px))`;
1214
+ const width = geometry.size(node).w;
1215
+ placed.set(node, { right, bottom, width });
1216
+ columnWidth = Math.max(columnWidth, width);
1217
+ bottom += height + 6;
1218
+ }
1219
+ // Open pickers sit immediately left of the button that owns them, even
1220
+ // when the dense rail wrapped that button into its second column.
1221
+ for (const [card, button] of [[emoteRow, emoteButton], [sayCard, sayButton]]) {
1222
+ const at = placed.get(button);
1223
+ if (!at) {continue;}
1224
+ // Clear the whole action lane even when this card belongs to a narrower
1225
+ // round button beside a 160px text action.
1226
+ card.style.right = safeInsets ? `calc(max(12px, env(safe-area-inset-right)) + ${Math.max(184, at.right + at.width + 6) - 12}px)` : `${Math.max(184, at.right + at.width + 6)}px`;
1227
+ card.style.bottom = button.style.bottom;
1228
+ card.style.maxHeight = `calc(100dvh - ${at.bottom + 12}px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
1229
+ card.style.overflowY = 'auto';
1230
+ }
1231
+ }
1232
+ function layoutOpenOverlays() {
1233
+ const width = 'min(56vw, max(220px, calc(100vw - 344px)), 560px)';
1234
+ if (placeMenu?.sheet) {
1235
+ placeMenu.sheet.style.width = placeMenu.rows ? 'min(calc(100% - 24px), 720px)' : landscape ? width : 'min(100%, 720px)';
1236
+ }
1237
+ if (textAsk?.card) {
1238
+ textAsk.card.style.width = landscape ? width : 'min(90vw, 320px)';
1239
+ textAsk.card.style.maxHeight = landscape ? 'calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom))' : '';
1240
+ textAsk.card.style.overflowY = landscape ? 'auto' : '';
1241
+ }
1242
+ }
1243
+ function applyViewportLayout(force = false) {
1244
+ const next = landscapeViewport();
1245
+ if (!force && next === landscape) {
1246
+ for (const list of [doorsList, peopleList]) {aboveDock(list);}
1247
+ if (next) {layoutLandscapeRail();}
1248
+ return;
1249
+ }
1250
+ 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)';
1254
+ Object.assign(dock.style, landscape
1255
+ ? { top: 'max(68px, calc(env(safe-area-inset-top) + 56px))', bottom: '', maxWidth: 'min(24vw, 160px)' }
1256
+ : { top: '', bottom: 'max(10px, env(safe-area-inset-bottom))', maxWidth: 'calc(100vw - 130px)' });
1257
+ for (const list of [doorsList, peopleList]) {aboveDock(list);}
1258
+ const centred = landscape
1259
+ ? { left: 'auto', right: edge('right', 12), transform: 'none', maxWidth: 'min(38vw, 160px)' }
1260
+ : { left: '50%', right: '', transform: 'translateX(-50%)', maxWidth: '' };
1261
+ Object.assign(talkButton.style, centred);
1262
+ Object.assign(sitButton.style, centred);
1263
+ Object.assign(nearButton.style, landscape ? centred : { ...centred, maxWidth: '80vw' });
1264
+ Object.assign(grabButton.style, landscape
1265
+ ? { right: edge('right', 14), width: '56px', height: '56px', borderRadius: '28px' }
1266
+ : { right: edge('right', 14), width: '76px', height: '76px', borderRadius: '38px' });
1267
+ for (const node of [emoteButton, sayButton]) {
1268
+ Object.assign(node.style, landscape
1269
+ ? { right: edge('right', 18), width: '44px', height: '44px', borderRadius: '22px' }
1270
+ : { right: edge('right', 20), width: '52px', height: '52px', borderRadius: '26px' });
1271
+ }
1272
+ Object.assign(emoteRow.style, landscape
1273
+ ? { right: edge('right', 68), maxWidth: 'calc(100vw - 156px)', overflowX: 'auto' }
1274
+ : { right: edge('right', 80), maxWidth: '', maxHeight: '', overflowX: '', overflowY: '' });
1275
+ Object.assign(sayCard.style, landscape
1276
+ ? { right: edge('right', 68), maxHeight: 'calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom))', overflowY: 'auto' }
1277
+ : { right: edge('right', 80), maxHeight: '', overflowY: '' });
1278
+ if (!landscape) {
1279
+ picker.style.right = edge('right', 10);
1280
+ picker.style.bottom = lockLift ? `calc(${cornerBottoms.get(picker)} + ${lockLift}px)` : cornerBottoms.get(picker);
1281
+ grabButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(grabButton)} + ${lockLift}px)` : cornerBottoms.get(grabButton);
1282
+ emoteButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(emoteButton)} + ${lockLift}px)` : cornerBottoms.get(emoteButton);
1283
+ emoteRow.style.bottom = lockLift ? `calc(${cornerBottoms.get(emoteRow)} + ${lockLift}px)` : cornerBottoms.get(emoteRow);
1284
+ sayButton.style.bottom = lockLift ? `calc(${cornerBottoms.get(sayButton)} + ${lockLift}px)` : cornerBottoms.get(sayButton);
1285
+ sayCard.style.bottom = lockLift ? `calc(${cornerBottoms.get(sayCard)} + ${lockLift}px)` : cornerBottoms.get(sayCard);
1286
+ sitButton.style.bottom = 'max(112px, calc(env(safe-area-inset-bottom) + 102px))';
1287
+ talkButton.style.bottom = 'max(64px, calc(env(safe-area-inset-bottom) + 54px))';
1288
+ nearButton.style.bottom = 'max(160px, calc(env(safe-area-inset-bottom) + 150px))';
1289
+ }
1290
+ layoutPanel();
1291
+ layoutLandscapeRail();
1292
+ layoutOpenOverlays();
1293
+ placeToast();
1294
+ }
1295
+ const viewportChanged = () => {applyViewportLayout(); fitPicker(true);};
1296
+ const unwatchViewport = watchViewport(viewportChanged);
1297
+ // Avoid extra portrait writes: existing portrait snapshots remain a proof
1298
+ // of the untouched baseline, while an initially-landscape view is laid out.
1299
+ if (landscape) {
1300
+ applyViewportLayout(true);
1301
+ }
952
1302
 
953
1303
  // v1.75: only allocated for an opted-in prompt. The field is the only
954
1304
  // DOM node that ever holds an answer, and it is wiped on every close.
955
- let textAsk = null;
956
1305
  function closeTextAsk() {
957
1306
  if (!textAsk?.card) {
958
1307
  return;
@@ -971,13 +1320,14 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
971
1320
  }
972
1321
 
973
1322
  // v1.79: only an opted-in offer creates this bottom sheet or its CSS.
974
- let placeMenu = null;
975
1323
  function closeMenu() {
976
1324
  if (!placeMenu?.sheet) {return;}
977
1325
  placeMenu.listeners.abort();
978
1326
  for (const timer of placeMenu.timers) { clearTimeout(timer); }
979
1327
  placeMenu.sheet.remove();
980
1328
  placeMenu.css.remove();
1329
+ placeMenu.restoreHud?.();
1330
+ uncoverControls();
981
1331
  placeMenu.sheet = placeMenu.css = placeMenu.listeners = null;
982
1332
  placeMenu.onOpen?.(false);
983
1333
  placeMenu.onOpen = placeMenu.cancel = null;
@@ -986,6 +1336,38 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
986
1336
  closeMenu();
987
1337
  placeMenu = null;
988
1338
  }
1339
+ // A row sheet without `face` reaches to 24px under the top of the view, so
1340
+ // the controls drawn under it (Doors and People, the direction chips, the
1341
+ // character, chat, emoji and sound buttons, Shift lock, action chips and
1342
+ // rails) are hidden while it is open. The mask is a marker attribute and
1343
+ // one `!important` rule in the sheet's own style element: it never reads
1344
+ // or writes a control's style.visibility, so the visibility the kit gives a
1345
+ // control under the sheet is the one it has once the sheet closes. Asked
1346
+ // again every frame, so a control made while the sheet is open is covered
1347
+ // too.
1348
+ const MENU_COVERED_RULE = '[data-hub-menu-covered] { visibility: hidden !important; }';
1349
+ function menuCoveredNodes() {
1350
+ return [
1351
+ dock, doorsList, peopleList, pointers, picker, sayButton, sayCard, emoteButton, emoteRow,
1352
+ sound?.button, sound?.card, grabButton, talkButton, sitButton, nearButton, stuckChip,
1353
+ actionChips, actRail, padContext?.node, companionLock,
1354
+ ...[...root.children].filter((node) => node.dataset?.hub === 'action-rail'),
1355
+ ...[...extraSurfaces.values()].filter((item) => item.kind === 'control').map((item) => item.node),
1356
+ ].filter((node) => node?.dataset);
1357
+ }
1358
+ function coverControls() {
1359
+ if (!placeMenu?.covers) {return;}
1360
+ for (const node of menuCoveredNodes()) {
1361
+ if (menuCovered.has(node) && node.dataset.hubMenuCovered !== undefined) {continue;}
1362
+ node.dataset.hubMenuCovered = '';
1363
+ menuCovered.add(node);
1364
+ }
1365
+ }
1366
+ function uncoverControls() {
1367
+ if (!menuCovered.size) {return;}
1368
+ for (const node of menuCovered) {delete node.dataset.hubMenuCovered;}
1369
+ menuCovered.clear();
1370
+ }
989
1371
  function setMenu(offer, handler, onOpen) {
990
1372
  if (!offer) { closeMenu(); return; }
991
1373
  if (placeMenu && offer.n <= placeMenu.n) {return;}
@@ -993,12 +1375,20 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
993
1375
  placeMenu = { n: offer.n };
994
1376
  const spec = offer.spec;
995
1377
  if (!spec) {return;}
1378
+ const rows = spec.presentation === 'rows';
1379
+ placeMenu.rows = rows;
1380
+ if (rows) {
1381
+ const visibility = hud.style.visibility, promptVisibility = hudText.style.visibility;
1382
+ hud.style.visibility = hudText.style.visibility = 'hidden';
1383
+ placeMenu.restoreHud = () => { hud.style.visibility = visibility; hudText.style.visibility = promptVisibility; };
1384
+ }
1385
+ placeMenu.covers = rows && !Object.hasOwn(spec, 'face');
996
1386
  if (Object.hasOwn(spec, 'face')) {placeMenu.face = spec.face;}
997
1387
  const height = Object.hasOwn(spec, 'face') ? 40 : 55;
998
1388
  const listeners = new AbortController(), signal = listeners.signal, timers = new Set();
999
1389
  // The same column, padding, corners and shadow as the Doors/chat panels.
1000
1390
  // Token fallbacks use their existing palette when no tokens are installed.
1001
- const sheet = el('div', { position: 'absolute', left: '50%', bottom: '0', transform: 'translateX(-50%)', width: 'min(100%, 720px)', maxHeight: `${height}vh`, boxSizing: 'border-box', overflow: 'hidden', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '6px', padding: '12px', paddingBottom: 'max(12px, env(safe-area-inset-bottom))', borderRadius: '12px 12px 0 0', background: 'var(--castle-surface-3, rgba(20,16,12,0.88))', color: 'var(--castle-text-primary, #fff)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', zIndex: '9' }, root);
1391
+ const sheet = el('div', { position: 'absolute', left: '50%', bottom: '0', transform: 'translateX(-50%)', width: 'min(100%, 720px)', maxHeight: rows && !Object.hasOwn(spec, 'face') ? 'calc(100vh - 24px)' : `${height}vh`, boxSizing: 'border-box', overflow: 'hidden', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '6px', padding: '12px', paddingBottom: 'max(12px, env(safe-area-inset-bottom))', borderRadius: '12px 12px 0 0', background: 'var(--castle-surface-3, rgba(20,16,12,0.88))', color: 'var(--castle-text-primary, #fff)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', zIndex: '9' }, root);
1002
1392
  sheet.className = 'hub-menu-sheet';
1003
1393
  sheet.dataset.hub = 'menu';
1004
1394
  sheet.setAttribute('role', 'dialog');
@@ -1012,8 +1402,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1012
1402
  @media (prefers-reduced-motion: reduce) { .hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { transform: none; } }
1013
1403
  @media (max-width: 600px) { .hub-menu-grid { grid-template-columns: repeat(4, minmax(64px, 1fr)) !important; } }
1014
1404
  @media (max-width: 340px) { .hub-menu-grid { grid-template-columns: repeat(3, minmax(64px, 1fr)) !important; } }
1015
- @supports (height: 1dvh) { .hub-menu-sheet { max-height: ${height}dvh !important; } }
1016
- `;
1405
+ @supports (height: 1dvh) { .hub-menu-sheet { max-height: ${rows && !Object.hasOwn(spec, 'face') ? 'calc(100dvh - 24px)' : `${height}dvh`} !important; } }
1406
+ ` + (placeMenu.covers ? ` ${MENU_COVERED_RULE}\n ` : '');
1017
1407
  for (const type of ['pointerdown', 'pointermove', 'pointerup', 'mousedown', 'wheel', 'contextmenu', 'keydown', 'keyup']) {
1018
1408
  sheet.addEventListener(type, (event) => event.stopPropagation(), { signal });
1019
1409
  }
@@ -1037,6 +1427,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1037
1427
  close.addEventListener('click', () => { close.blur(); cancel(); }, { signal });
1038
1428
  if (spec.note) {el('div', { fontSize: '13px', color: 'var(--castle-text-secondary, #fff)', overflowWrap: 'anywhere', flexShrink: '0' }, sheet).textContent = spec.note;}
1039
1429
  const scroll = el('div', { overflowY: 'auto', minHeight: '0', overscrollBehavior: 'contain', touchAction: 'pan-y' }, sheet);
1430
+ if (rows) {
1431
+ Object.assign(scroll.style, { flex: '1 1 auto', scrollbarGutter: 'stable' });
1432
+ drawMenuRows({ el, sheet, scroll, spec, signal, pick: (id) => { if (placeMenu?.sheet) { handler(id, offer.n); } } });
1433
+ }
1434
+ if (!rows) {
1040
1435
  for (const section of spec.sections) {
1041
1436
  el('div', { fontSize: '13px', margin: '8px 0', color: 'var(--castle-text-secondary, #fff)' }, scroll).textContent = section.title;
1042
1437
  const grid = el('div', { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(64px, 1fr))', gap: '8px' }, scroll);
@@ -1073,11 +1468,129 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1073
1468
  }
1074
1469
  }
1075
1470
  }
1471
+ }
1076
1472
  Object.assign(placeMenu, { sheet, css, listeners, timers, onOpen, cancel });
1473
+ coverControls();
1474
+ layoutOpenOverlays();
1077
1475
  onOpen?.(true);
1078
1476
  }
1079
1477
 
1080
- return {
1478
+ let actMode = false, actRail = null;
1479
+ let debugLayout = null;
1480
+ const extraSurfaces = new Map();
1481
+ let talkCaption = null;
1482
+ let padContext = null;
1483
+ const placePadContext = placementCache();
1484
+ function syncTalkCaption() {
1485
+ const node = extraSurfaces.get('engine-look')?.node;
1486
+ if (talkCaption && (!talkOpen || talkCaption.node !== node)) {
1487
+ talkCaption.node.style.visibility = talkCaption.visibility;
1488
+ talkCaption = null;
1489
+ }
1490
+ if (talkOpen && node && !talkCaption) {
1491
+ talkCaption = { node, visibility: node.style.visibility };
1492
+ node.style.visibility = 'hidden';
1493
+ }
1494
+ }
1495
+ // This same registry feeds safe placement, More/Actions obstacles, and its
1496
+ // observer membership. No independent additive external-node watch list.
1497
+ function externalEntries() {
1498
+ for (const [id, item] of extraSurfaces) {
1499
+ if (item.node.isConnected === false) {geometry.unregister(item.node); extraSurfaces.delete(id);}
1500
+ }
1501
+ return [...extraSurfaces];
1502
+ }
1503
+ function syncActionSurfaces() {
1504
+ if (safeInsets) {safeLayout?.schedule(); return;}
1505
+ if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles());}
1506
+ }
1507
+ const api = {
1508
+ beginLayoutFrame(canvas) {
1509
+ if (canvasSource !== canvas) {
1510
+ geometry.unregister(canvasSource); canvasSource = canvas; geometry.register(canvas);
1511
+ }
1512
+ geometry.beginFrame();
1513
+ if (stuckSpot && stuckChip) {
1514
+ const { w, h } = geometry.size(stuckChip), { left, top } = geometry.offsets(stuckChip);
1515
+ stuckSpot = { left: left - w / 2, right: left + w / 2, top, bottom: top + h };
1516
+ }
1517
+ const rect = canvas?.getBoundingClientRect ? geometry.rect(canvas) : null;
1518
+ if (worldViewport) {worldViewport = rect?.width > 0 && rect.height > 0 ? rect : null;}
1519
+ return rect;
1520
+ },
1521
+ endLayoutFrame() {
1522
+ // Setters late in the frame may have queued HUD clearance; place it by
1523
+ // this frame's snapshot before the snapshot ends.
1524
+ flushHudClear();
1525
+ if (placeMenu?.sheet) {coverControls();}
1526
+ geometry.endFrame();
1527
+ for (const [key, node] of labelMeasures) {
1528
+ if (!usedLabelMeasures.has(key)) {node.remove(); labelMeasures.delete(key);}
1529
+ }
1530
+ usedLabelMeasures.clear();
1531
+ },
1532
+ layoutGeometry: () => geometry,
1533
+ ...(safeInsets ? {
1534
+ layout: () => safeLayout.report(),
1535
+ beginSafeInsets: () => safeLayout.begin(),
1536
+ flushSafeInsets: () => safeLayout.flush(),
1537
+ frameSafeInsets: () => safeLayout.frame(),
1538
+ } : {}),
1539
+ // Surface ownership is independent of safe-inset control placement. Door
1540
+ // text still yields to external cards when that optional placement is off.
1541
+ safeSurface(id, node, kind = 'card', placement = null) {
1542
+ const previous = extraSurfaces.get(id);
1543
+ if (previous?.node === node && previous?.kind === kind && previous?.placement === placement) {return;}
1544
+ if (previous?.node && previous.node !== node) {geometry.unregister(previous.node);}
1545
+ geometry.register(node, { positioned: placement?.transient === true });
1546
+ if (node) {extraSurfaces.set(id, { node, kind, placement });} else {extraSurfaces.delete(id);}
1547
+ syncTalkCaption();
1548
+ safeLayout?.watch(node);
1549
+ safeLayout?.schedule();
1550
+ syncActionSurfaces();
1551
+ },
1552
+ interactionRoot: () => root,
1553
+ interactionRail(pair, act, jump) {
1554
+ if (actRail) {railNodes.splice(railNodes.indexOf(actRail), 1);}
1555
+ actRail = pair;
1556
+ if (pair) {railNodes.splice(1, 0, pair);}
1557
+ api.safeSurface?.('act-pair', pair, 'control', pair ? {
1558
+ stack: 2,
1559
+ reportNodes: () => [{ id: 'act', node: act, kind: 'control' }, { id: 'jump', node: jump, kind: 'control' }],
1560
+ } : null);
1561
+ layoutLandscapeRail();
1562
+ },
1563
+ layoutInteractionRail() {
1564
+ if (!actRail) {return;}
1565
+ if (landscape) {layoutLandscapeRail();}
1566
+ else {Object.assign(actRail.style, { left: '', right: edge('right', 14), top: '', bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))' });}
1567
+ },
1568
+ setActMode: value => {
1569
+ actMode = value;
1570
+ if (value) {for (const node of [sitButton, grabButton, talkButton]) {node.style.display = 'none';}}
1571
+ },
1572
+ interactionObstacles: () => [back, hud, toast, askCard, sound?.button, sound?.card, picker, pickerCard, panel, emoteButton, emoteRow, sayButton, sayCard, feed, dock, doorsList, peopleList, nearButton, stuckChip, cabinet, ribbon].filter(node => node && node.style.display !== 'none' && node.style.visibility !== 'hidden'),
1573
+ setWorldLabelFocus(on) {
1574
+ if (worldLabelsDefault === on && worldLayout) {return;}
1575
+ worldLayout?.begin();
1576
+ worldLabelsDefault = on;
1577
+ // The root town retains its explicit near selection; its selected text
1578
+ // still needs the same final HUD/control/avatar clearance as doors.
1579
+ worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry);
1580
+ },
1581
+ // An avatar crossing the camera's near plane has no reliable screen box
1582
+ // (and may be hidden by the renderer's first-person view).
1583
+ setWorldAvatar: (box) => {
1584
+ worldAvatar = box && [box.left, box.right, box.top, box.bottom].every(Number.isFinite) ? box : null;
1585
+ const snapped = worldAvatar && { left: Math.floor(worldAvatar.left / 16) * 16, right: Math.ceil(worldAvatar.right / 16) * 16,
1586
+ top: Math.floor(worldAvatar.top / 16) * 16, bottom: Math.ceil(worldAvatar.bottom / 16) * 16 };
1587
+ const same = snapped && avatarReserve ? ['left', 'right', 'top', 'bottom'].every((key) => snapped[key] === avatarReserve[key]) : snapped === avatarReserve;
1588
+ if (!same) {avatarReserve = snapped; if (safeInsets) {actionOverflow?.invalidate();}}
1589
+ },
1590
+ worldAvatar: () => worldAvatar,
1591
+ setWorldViewport: (area) => {worldViewport = area;},
1592
+ beginWorldLabels: () => worldLayout?.begin(),
1593
+ flushWorldLabels: () => worldLayout?.flush(),
1081
1594
  setMenu, clearMenu,
1082
1595
  cancelMenu: () => placeMenu?.cancel?.(),
1083
1596
  menuOpen: () => !!placeMenu?.sheet,
@@ -1115,7 +1628,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1115
1628
  const place = () => {
1116
1629
  const view = window.visualViewport;
1117
1630
  // Stay in the visible viewport as the phone keyboard rises.
1118
- const bottom = view ? window.innerHeight - view.height - view.offsetTop : 0;
1631
+ const bottom = view ? geometry.view().h - view.height - view.offsetTop : 0;
1119
1632
  card.style.bottom = `max(${bottom + 24}px, calc(env(safe-area-inset-bottom) + 24px))`;
1120
1633
  };
1121
1634
  place();
@@ -1175,6 +1688,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1175
1688
  }
1176
1689
  }, { signal });
1177
1690
  Object.assign(textAsk, { card, shield, input, listeners, onOpen, cancel: () => answer(true) });
1691
+ layoutOpenOverlays();
1178
1692
  onOpen?.(true);
1179
1693
  input.focus();
1180
1694
  },
@@ -1206,22 +1720,75 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1206
1720
  back.textContent = text;
1207
1721
  }
1208
1722
  },
1209
- setActions(items, handler, canAct, n) {
1723
+ setActions(items, handler, canAct, n, overflow = false, onOverflowOpen = () => {}) {
1724
+ if (safeInsets) {overflow = true;}
1725
+ if (overflow) {
1726
+ clearLegacyActions();
1727
+ actionOverflowOpen = onOverflowOpen;
1728
+ if (!actionOverflow) {
1729
+ actionOverflowObstacles = () => {
1730
+ // Decor mounts a z=3 layer here, with its entry button first. Its
1731
+ // full-view layer is never an obstacle; the entry button is.
1732
+ const decor = [...root.children].find((node) => node.style.zIndex === '3');
1733
+ const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
1734
+ return [
1735
+ back, hud, hudText, toast, askCard, sound?.button, sound?.card, stats,
1736
+ picker, pickerCard, talkButton, panel, grabButton, emoteButton, emoteRow,
1737
+ sayButton, sayCard, feed, sitButton, dock, doorsList, peopleList,
1738
+ nearButton, stuckChip, cabinet, ribbon, decorButton,
1739
+ ].filter(Boolean).concat(externalEntries().map(([, item]) => item).filter((item) => item.kind !== 'text').map((item) => item.node));
1740
+ };
1741
+ actionOverflow = makeActionOverflow({
1742
+ root,
1743
+ ...(safeInsets ? { edgeMax: true, readSafeInsets: () => safeLayout.view().insets } : {}),
1744
+ obstacles: actionOverflowObstacles,
1745
+ reserved: ({ w, h, safe }) => [
1746
+ // The native exit target lives outside this document's DOM.
1747
+ { left: safe.left, right: safe.left + 64, top: safe.top, bottom: safe.top + 56 },
1748
+ { left: w - safe.right - 64, right: w - safe.right, top: safe.top, bottom: safe.top + 56 },
1749
+ // Landscape gives its lower-left half to the movement stick.
1750
+ // Portrait retains twice playerRun's 56 px stick radius.
1751
+ landscapeViewport()
1752
+ ? { left: safe.left, right: w / 2, top: h / 2, bottom: h - safe.bottom }
1753
+ : { left: safe.left, right: Math.min(w - safe.right, safe.left + 112), top: Math.max(safe.top, h - safe.bottom - 112), bottom: h - safe.bottom },
1754
+ // Safe-inset offers stay off the player's own avatar (last
1755
+ // drawn frame); the legacy overflow lane is unchanged.
1756
+ ...(safeInsets && avatarReserve ? [avatarReserve] : []),
1757
+ ],
1758
+ onOpen: (open) => actionOverflowOpen?.(open),
1759
+ focusFallback: () => [back, ...dock.children, picker, grabButton, emoteButton, sayButton]
1760
+ .find((node) => shownRect(node) && typeof node.focus === 'function') ?? null,
1761
+ });
1762
+ }
1763
+ syncActionSurfaces();
1764
+ actionOverflow.set(items, handler, canAct, n);
1765
+ syncOverflowSources();
1766
+ return;
1767
+ }
1768
+ if (actionOverflow) {
1769
+ actionOverflow.dispose();
1770
+ actionOverflow = null;
1771
+ syncOverflowSources();
1772
+ actionOverflowOpen = actionOverflowObstacles = null;
1773
+ }
1210
1774
  if (!items?.length) {
1211
- clearActions();
1775
+ clearLegacyActions();
1212
1776
  return;
1213
1777
  }
1214
1778
  actionHandler = handler;
1215
- const key = JSON.stringify([items, n]);
1216
- if (key !== actionKey) {
1217
- clearActions();
1779
+ let created = false;
1780
+ const key = [n, ...items.flatMap(({ id, label }) => [id, label])];
1781
+ if (!Array.isArray(actionKey) || key.length !== actionKey.length || key.some((value, i) => value !== actionKey[i])) {
1782
+ clearLegacyActions();
1218
1783
  actionHandler = handler;
1219
1784
  actionKey = key;
1220
1785
  actionListeners = new AbortController();
1221
- actionChips = el('div', { position: 'absolute', right: '12px', display: 'none', flexDirection: 'column-reverse', alignItems: 'flex-end', gap: '6px', maxWidth: 'calc(100vw - 24px)', pointerEvents: 'none' }, root);
1786
+ actionChips = el('div', { position: 'absolute', right: edge('right', 12), bottom: 'max(132px, calc(env(safe-area-inset-bottom) + 122px))', display: 'none', flexDirection: 'column-reverse', alignItems: 'flex-end', gap: '6px', maxWidth: 'calc(100vw - 24px)', pointerEvents: 'none' }, root);
1787
+ actionIdentity += 1; created = true;
1222
1788
  actionChips.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: actionListeners.signal });
1223
1789
  for (const item of items.slice(0, 3)) {
1224
1790
  const chip = el('button', { border: '0', borderRadius: '22px', minHeight: '44px', padding: '12px 20px', font: '600 16px/1.2 system-ui, sans-serif', color: '#26222b', background: '#f4c66c', cursor: 'pointer', touchAction: 'manipulation', pointerEvents: 'auto', maxWidth: '100%', overflowWrap: 'anywhere' }, actionChips);
1791
+ geometry.register(chip);
1225
1792
  chip.type = 'button';
1226
1793
  chip.tabIndex = -1;
1227
1794
  chip.textContent = item.label;
@@ -1245,60 +1812,82 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1245
1812
  }
1246
1813
  }
1247
1814
  const show = canAct && !pickerOpen && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen && !talkOpen;
1248
- actionChips.style.display = show ? 'flex' : 'none';
1249
1815
  if (!show) {
1816
+ if (actionChips.style.display !== 'none') {actionChips.style.display = 'none';}
1817
+ placeActions(['hidden', actionKey], () => {});
1250
1818
  return;
1251
1819
  }
1252
1820
  // Decor mounts a z=3 layer here, with its entry button first. Measure
1253
1821
  // that button only when its layer is drawn, never the full-view layer.
1254
1822
  const decor = [...root.children].find((node) => node.style.zIndex === '3');
1255
1823
  const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
1256
- const column = [grabButton, emoteButton, sayButton, sitButton].map(shownRect).filter(Boolean);
1257
- const controls = [picker, talkButton, dock, nearButton, stuckChip, decorButton].map(shownRect).filter(Boolean).concat(column);
1258
- const above = [hud, askCard, back, sound?.button, sound?.card].map(shownRect).filter(Boolean);
1259
- const overlaps = (a, b) => a.left < b.right && a.right > b.left;
1260
- const chips = [...actionChips.children];
1261
- // Restore chips trimmed by a previous frame before trying both positions.
1262
- for (const chip of chips) {
1263
- chip.style.display = '';
1264
- }
1265
- const place = (right, initialBottom) => {
1266
- actionChips.style.right = `${right}px`;
1267
- actionChips.style.maxWidth = `${Math.max(0, window.innerWidth - right - 12)}px`;
1268
- actionChips.style.bottom = initialBottom;
1269
- const box = actionChips.getBoundingClientRect();
1270
- let bottom = window.innerHeight - box.bottom;
1271
- for (const r of controls) {
1272
- if (overlaps(r, box)) {
1273
- bottom = Math.max(bottom, window.innerHeight - r.top + 12);
1274
- }
1824
+ const inputs = [grabButton, emoteButton, sayButton, sitButton, picker, talkButton, dock, nearButton,
1825
+ stuckChip, decorButton, hud, askCard, back, sound?.button, sound?.card];
1826
+ if (actionChips.style.display === 'none' && (!geometry.active() || created)) {actionChips.style.display = 'flex';}
1827
+ // Placement depends only on this frame's numbers and offer identity/copy.
1828
+ placeActions([actionIdentity, actionKey, show, geometry.view().w, geometry.view().h,
1829
+ geometry.rect(actionBottom).bottom, inputs.map((node) => node ? shownRect(node) : null),
1830
+ [...actionChips.children].map((chip) => [chip.textContent, actionSize(chip)])], () => {
1831
+ const column = [grabButton, emoteButton, sayButton, sitButton].map(shownRect).filter(Boolean);
1832
+ const controls = [picker, talkButton, dock, nearButton, stuckChip, decorButton].map(shownRect).filter(Boolean).concat(column);
1833
+ const above = [hud, askCard, back, sound?.button, sound?.card].map(shownRect).filter(Boolean);
1834
+ const overlaps = (a, b) => a.left < b.right && a.right > b.left;
1835
+ actionChips.style.display = 'flex';
1836
+ const chips = [...actionChips.children];
1837
+ // Restore trimmed chips and sample any first shown this frame before
1838
+ // trying both positions.
1839
+ for (const chip of chips) {
1840
+ chip.style.display = '';
1841
+ geometry.size(chip);
1275
1842
  }
1276
- actionChips.style.bottom = `${bottom}px`;
1277
- const placed = actionChips.getBoundingClientRect();
1278
- return placed.left >= 12 && placed.top >= 12 && placed.bottom <= window.innerHeight - 12
1279
- && !above.some((r) => overlaps(r, placed) && r.bottom + 12 > placed.top);
1280
- };
1281
- // Identity determines which controls bound the stack from above, even
1282
- // when a short frame puts speech or Grab in the top half of the view.
1283
- const right = window.innerWidth - Math.min(window.innerWidth - 12, ...column.map((r) => r.left)) + 12;
1284
- for (let count = chips.length; count > 0; count -= 1) {
1285
- // Trimming can narrow the stack enough to clear a HUD or decor
1286
- // obstacle in the right column, so retry it before the fallback.
1287
- if (place(12, 'max(132px, calc(env(safe-area-inset-bottom) + 122px))') || place(right, '12px')) {
1288
- return;
1843
+ const edgeRight = 12, edgeLeft = 12;
1844
+ const place = (right, initialBottom) => {
1845
+ right = Math.max(right, edgeRight);
1846
+ actionChips.style.right = `${right}px`;
1847
+ actionChips.style.maxWidth = `${Math.max(0, geometry.view().w - right - edgeLeft)}px`;
1848
+ actionChips.style.bottom = initialBottom;
1849
+ // Candidates change maxWidth and can wrap chips differently. This
1850
+ // rare solve needs fresh layout; unchanged placement stays cached.
1851
+ const box = actionChips.getBoundingClientRect();
1852
+ let bottom = geometry.view().h - box.bottom;
1853
+ for (const r of controls) {
1854
+ if (overlaps(r, box)) {
1855
+ bottom = Math.max(bottom, geometry.view().h - r.top + 12);
1856
+ }
1857
+ }
1858
+ actionChips.style.bottom = `${bottom}px`;
1859
+ const placed = geometry.active()
1860
+ ? { left: box.left, right: box.right, width: box.width, height: box.height,
1861
+ top: geometry.view().h - bottom - box.height, bottom: geometry.view().h - bottom }
1862
+ : geometry.rect(actionChips);
1863
+ return placed.left >= edgeLeft && placed.top >= 12 && placed.bottom <= geometry.view().h - 12
1864
+ && !above.some((r) => overlaps(r, placed) && r.bottom + 12 > placed.top);
1865
+ };
1866
+ // Identity determines which controls bound the stack from above, even
1867
+ // when a short frame puts speech or Grab in the top half of the view.
1868
+ const right = geometry.view().w - Math.min(geometry.view().w - edgeRight, ...column.map((r) => r.left)) + 12;
1869
+ for (let count = chips.length; count > 0; count -= 1) {
1870
+ // Trimming can narrow the stack enough to clear a HUD or decor
1871
+ // obstacle in the right column, so retry it before the fallback.
1872
+ if (place(edgeRight, 'max(132px, calc(env(safe-area-inset-bottom) + 122px))') || place(right, '12px')) {
1873
+ return;
1874
+ }
1875
+ // column-reverse puts the first offer at the bottom: trim from the top.
1876
+ chips[count - 1].style.display = 'none';
1289
1877
  }
1290
- // column-reverse puts the first offer at the bottom: trim from the top.
1291
- chips[count - 1].style.display = 'none';
1292
- }
1293
- actionChips.style.display = 'none';
1878
+ actionChips.style.display = 'none';
1879
+ });
1294
1880
  },
1295
1881
  clearActions,
1882
+ cancelActionOverflow: () => actionOverflow?.cancel?.() ?? false,
1883
+ actionOverflowOpen: () => actionOverflow?.isOpen?.() === true,
1296
1884
  // v1.67: called only in a decor place; the tray uses the same chrome root.
1297
1885
  decorRoot() {
1298
1886
  return root;
1299
1887
  },
1300
1888
  setDecorating(on) {
1301
1889
  hud.style.visibility = on ? 'hidden' : '';
1890
+ hudText.style.visibility = on ? 'hidden' : '';
1302
1891
  picker.style.visibility = on ? 'hidden' : '';
1303
1892
  back.style.zIndex = on ? '4' : '';
1304
1893
  back.style.top = on ? 'auto' : 'max(12px, env(safe-area-inset-top))';
@@ -1307,17 +1896,29 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1307
1896
  setHud(spec, timerSeconds) {
1308
1897
  if (!spec) {
1309
1898
  hud.style.display = 'none';
1899
+ hudPromptAsked = false;
1900
+ syncHudPrompt();
1310
1901
  return;
1311
1902
  }
1312
1903
  hud.style.display = 'block';
1313
- hudTitle.textContent = spec.title ?? '';
1904
+ const title = spec.title ?? '';
1905
+ if (hudTitle.textContent !== title) {hudTitle.textContent = title;}
1314
1906
  const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
1315
- hudBig.textContent = big;
1316
- hudBig.style.display = big ? 'block' : 'none';
1317
- hudText.textContent = spec.text ?? '';
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();
1318
1915
  if (hudClear) {
1319
1916
  layoutHudClear(big, spec.text ?? '');
1320
1917
  }
1918
+ if (import.meta.env?.DEV) {
1919
+ warnHudCopy(hudTitle, 'subtitle');
1920
+ warnHudCopy(hudText, 'prompt', 1);
1921
+ }
1321
1922
  },
1322
1923
  // Whether this place asks for a clear HUD (`hud.clear`, v1.26). Said each
1323
1924
  // frame before `setHud`; never said true, nothing of it is drawn.
@@ -1340,34 +1941,136 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1340
1941
  // The HUD's box that this frame's flush will move labels out from under
1341
1942
  // (v1.26), or null when nothing will be moved: no clear HUD asked for, or
1342
1943
  // none drawn. For v1.43's rule, which must judge where labels end up.
1944
+ // v1.131: labels avoid this bottom pill separately from the top band.
1945
+ hudPromptBox() {
1946
+ return shownRect(hudText);
1947
+ },
1343
1948
  hudClearBox() {
1344
- return hudClear && hud.style.display !== 'none' ? hudClearRect : null;
1949
+ return hudClear && hud.style.display !== 'none' ? shownRect(hud) : null;
1345
1950
  },
1346
1951
  // How big a label with these words is drawn, `{ w, h }` in CSS pixels
1347
1952
  // (v1.43, for a deck whose labels are kept apart: `labelsNear.js`).
1348
- // Measured once for each text in a node of its own outside the chrome's
1349
- // root, made on the first call: a deck that never asks has no such node.
1350
- measureLabel(text, speech = false, npc = false) {
1351
- const key = `${speech ? (npc ? 'n' : 's') : 'l'}${desktop() ? 'd' : 'm'}${window.innerWidth}|${text}`;
1352
- let size = labelSizes.get(key);
1353
- if (!size) {
1354
- labelMeasure ??= el('div', { position: 'fixed', left: '-10000px', top: '0', visibility: 'hidden', pointerEvents: 'none', font: '600 15px/1.3 system-ui, sans-serif', padding: '4px 10px', whiteSpace: 'nowrap', fontSize: '14px' });
1355
- const m = labelMeasure.style;
1356
- m.whiteSpace = speech ? 'normal' : 'nowrap';
1357
- m.width = speech ? 'max-content' : 'auto';
1358
- m.maxWidth = !speech ? 'none' : npc && desktop() ? 'min(62vw, 320px)' : '62vw';
1359
- m.fontSize = speech ? '13px' : '14px';
1360
- m.fontWeight = speech ? '500' : '600';
1361
- labelMeasure.textContent = text;
1362
- size = { w: labelMeasure.offsetWidth, h: labelMeasure.offsetHeight };
1363
- if (labelSizes.size > 400) {
1364
- labelSizes.clear();
1365
- }
1366
- labelSizes.set(key, size);
1953
+ // Keep a source node for each requested copy/style, not cached sizes.
1954
+ // Sources are sampled every frame and removed when no longer requested.
1955
+ measureLabel(text, speech = false, npc = false, padOccupancy = false) {
1956
+ const key = `${padOccupancy}:${speech}:${npc}:${desktop()}:${text}`;
1957
+ usedLabelMeasures.add(key);
1958
+ let node = labelMeasures.get(key);
1959
+ if (!node) {
1960
+ node = el('div', { position: 'fixed', left: '-10000px', top: '0', visibility: 'hidden', pointerEvents: 'none',
1961
+ font: '600 15px/1.3 system-ui, sans-serif', padding: '4px 10px',
1962
+ whiteSpace: padOccupancy ? 'pre-line' : speech ? 'normal' : 'nowrap', width: speech ? 'max-content' : 'auto',
1963
+ maxWidth: padOccupancy ? 'min(70vw, 320px)' : !speech ? 'none' : npc && desktop() ? 'min(62vw, 320px)' : '62vw',
1964
+ fontSize: speech ? '13px' : '14px', fontWeight: speech ? '500' : '600' });
1965
+ node.textContent = text;
1966
+ labelMeasures.set(key, node);
1967
+ }
1968
+ return geometry.size(node);
1969
+ },
1970
+ // A owns only this lazy, noninteractive caption. The projected surface
1971
+ // participates in the shared registry but is placed last, yielding to
1972
+ // every final control/card/label box rather than moving any of them.
1973
+ setPadContext(item) {
1974
+ const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
1975
+ !!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
1976
+ externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node));
1977
+ if (!item || blocked) {
1978
+ if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
1979
+ return;
1980
+ }
1981
+ if (!padContext) {
1982
+ const node = el('div', { position: 'absolute', left: '0px', top: '0px', width: 'max-content', maxWidth: 'min(70vw, 320px)',
1983
+ boxSizing: 'border-box', padding: '7px 12px', borderRadius: '12px', background: 'rgba(20,16,12,0.86)',
1984
+ pointerEvents: 'none', textAlign: 'center', visibility: 'hidden' }, root);
1985
+ node.dataset.hub = 'pad-context';
1986
+ const title = el('div', { fontSize: '16px', lineHeight: '1.25', overflowWrap: 'anywhere', overflow: 'hidden',
1987
+ display: '-webkit-box', webkitLineClamp: '2', webkitBoxOrient: 'vertical', textOverflow: 'ellipsis' }, node);
1988
+ const secondary = el('div', { fontSize: '13px', lineHeight: '1.3', fontWeight: '500' }, node);
1989
+ const probe = el('div', { position: 'fixed', inset: '0', visibility: 'hidden', pointerEvents: 'none',
1990
+ paddingTop: 'env(safe-area-inset-top)', paddingRight: 'env(safe-area-inset-right)',
1991
+ paddingBottom: 'env(safe-area-inset-bottom)', paddingLeft: 'env(safe-area-inset-left)' }, root);
1992
+ geometry.register(probe, { padding: true });
1993
+ padContext = { node, title, secondary, probe, id: null, text: null, line: null };
1994
+ api.safeSurface('pad-context', node, 'text', { projected: true, transient: true });
1995
+ }
1996
+ const { node, title, secondary, probe } = padContext;
1997
+ if (padContext.id !== item.id || padContext.text !== item.title || padContext.line !== item.secondary) {
1998
+ title.textContent = item.title;
1999
+ secondary.textContent = item.secondary;
2000
+ secondary.style.display = item.secondary ? 'block' : 'none';
2001
+ node.setAttribute('aria-label', item.title);
2002
+ node.setAttribute('title', item.title);
2003
+ padContext.id = item.id; padContext.text = item.title; padContext.line = item.secondary;
2004
+ }
2005
+ const view = geometry.view();
2006
+ const safe = safeLayout?.view().insets ?? geometry.padding(probe);
2007
+ const size = geometry.size(node);
2008
+ // The stuck chip is placed earlier this frame; read its new rect, not
2009
+ // the cached one from before it was shown or moved.
2010
+ if (stuckChip && stuckChip.style.display !== 'none') {geometry.invalidate(stuckChip);}
2011
+ const obstacles = surfaces().filter((entry) => entry.node !== node && entry.node !== probe).map((entry) => shownRect(entry.node)).filter(Boolean);
2012
+ if (worldAvatar) {obstacles.push(worldAvatar);}
2013
+ const reserved = [
2014
+ { left: safe.left, right: safe.left + 64, top: safe.top, bottom: safe.top + 56 },
2015
+ { left: view.w - safe.right - 64, right: view.w - safe.right, top: safe.top, bottom: safe.top + 56 },
2016
+ landscapeViewport()
2017
+ ? { left: safe.left, right: view.w / 2, top: view.h / 2, bottom: view.h - safe.bottom }
2018
+ : { left: safe.left, right: safe.left + 112, top: view.h - safe.bottom - 112, bottom: view.h - safe.bottom },
2019
+ ];
2020
+ const at = placePadContext([item, view, safe, size, obstacles, reserved], () => actionLayout({ view, safe, offers: [size], obstacles, reserved }));
2021
+ if (at) {
2022
+ const left = `${at.rect.left}px`, top = `${at.rect.top}px`;
2023
+ if (node.style.left !== left) {node.style.left = left;}
2024
+ if (node.style.top !== top) {node.style.top = top;}
2025
+ }
2026
+ const visibility = at ? '' : 'hidden';
2027
+ if (node.style.visibility !== visibility) {node.style.visibility = visibility;}
2028
+ },
2029
+ clearPadContext() {
2030
+ if (!padContext) {return;}
2031
+ api.safeSurface('pad-context', null);
2032
+ padContext.node.remove(); padContext.probe.remove(); padContext = null;
2033
+ },
2034
+ padOccupancyControls() {
2035
+ const decor = [...root.children].find((node) => node.style.zIndex === '3');
2036
+ const decorButton = decor?.style.display !== 'none' ? decor?.children[0] : null;
2037
+ const actionControls = [...root.children].flatMap((node) => node.dataset.hub === 'action-backdrop'
2038
+ ? [...node.children].filter((child) => child.dataset.hub === 'action-sheet')
2039
+ : node.dataset.hub === 'action-rail' ? [node] : []);
2040
+ 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
+ },
2042
+ // E crowd names asks only on its opted-in late pass, after setLabels and
2043
+ // HUD clearance have put every ordinary DOM label at its final rectangle.
2044
+ // The summary from a prior frame has already been removed by setLabels.
2045
+ crowdNameLabelBoxes() {
2046
+ return [...labelNodes.entries()]
2047
+ .filter(([id]) => id !== 'crowd:summary')
2048
+ .map(([, node]) => shownRect(node))
2049
+ .filter(Boolean);
2050
+ },
2051
+ // E's late pass runs after ordinary labels have completed HUD clearance.
2052
+ // Touch only its one boxed summary so those final positions stay final.
2053
+ setCrowdNameSummary(item) {
2054
+ const id = 'crowd:summary';
2055
+ let node = labelNodes.get(id);
2056
+ if (!item) {
2057
+ node?.remove();
2058
+ labelNodes.delete(id);
2059
+ worldLayout?.flush();
2060
+ return;
2061
+ }
2062
+ if (!node) {
2063
+ 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);
2064
+ labelNodes.set(id, node);
1367
2065
  }
1368
- return size;
2066
+ node.style.left = `${(item.box.left + item.box.right) / 2}px`;
2067
+ node.style.top = `${item.box.bottom}px`;
2068
+ if (node.textContent !== item.text) {
2069
+ node.textContent = item.text;
2070
+ }
2071
+ worldLayout?.flush();
1369
2072
  },
1370
- setLabels(items) {
2073
+ setLabels(items, preserveCrowdSummary = false) {
1371
2074
  const seen = new Set();
1372
2075
  // The top chrome an emote's emoji is kept from under (`emoteBubble.js`),
1373
2076
  // read once a call and only when an emote is drawn.
@@ -1388,15 +2091,6 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1388
2091
  // measured for these words, kept on the screen, moved from under a
1389
2092
  // clear HUD) is put exactly there and moved by nothing after, so what
1390
2093
  // is drawn is what the rule judged. No other item has one.
1391
- let x = item.x;
1392
- if (item.box) {
1393
- x = (item.box.left + item.box.right) / 2;
1394
- } else if (item.npc) {
1395
- const half = node.offsetWidth / 2;
1396
- x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
1397
- }
1398
- node.style.left = `${x}px`;
1399
- node.style.top = `${item.box ? item.box.bottom : item.y}px`;
1400
2094
  if (item.speech) {
1401
2095
  node.style.background = 'rgba(255,250,240,0.94)';
1402
2096
  node.style.color = '#2b2118';
@@ -1411,6 +2105,17 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1411
2105
  node.style.fontSize = '13px';
1412
2106
  node.style.fontWeight = '500';
1413
2107
  }
2108
+ if (item.padOccupancy) {
2109
+ node.dataset.padOccupancy = '1';
2110
+ node.style.whiteSpace = 'pre-line';
2111
+ node.style.width = 'max-content';
2112
+ node.style.maxWidth = 'min(70vw, 320px)';
2113
+ } else if (node.dataset.padOccupancy === '1') {
2114
+ delete node.dataset.padOccupancy;
2115
+ node.style.whiteSpace = item.speech ? 'normal' : 'nowrap';
2116
+ node.style.width = item.speech ? 'max-content' : '';
2117
+ node.style.maxWidth = item.speech ? '62vw' : '';
2118
+ }
1414
2119
  if (item.emote && node.dataset.emote !== '1') {
1415
2120
  // An emote's emoji over a player: large, on nothing.
1416
2121
  node.dataset.emote = '1';
@@ -1436,25 +2141,28 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1436
2141
  if (node.textContent !== item.text) {
1437
2142
  node.textContent = item.text;
1438
2143
  }
2144
+ let x = item.box ? (item.box.left + item.box.right) / 2 : item.x;
2145
+ node.style.left = `${x}px`;
2146
+ node.style.top = `${item.box ? item.box.bottom : item.y}px`;
2147
+ if (!item.box && item.npc) {
2148
+ const half = geometry.size(node).w / 2;
2149
+ x = Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6);
2150
+ node.style.left = `${x}px`;
2151
+ }
1439
2152
  if (item.emote && !item.box) {
1440
2153
  // An emote's emoji sits on its head (`emoteBubble.js`): just above
1441
2154
  // it, or beside it where above is off the view or under the top
1442
2155
  // chrome, and never under the top chrome. A clear HUD moves what is
1443
2156
  // under its own box (`keepClearOfHud` below).
1444
- bands ??= [hud, askCard, back, sound?.button].map(shownRect).filter(Boolean);
1445
- // An emoji's size is its glyph's at a fixed font size: measured once
1446
- // per emoji, not read back after this frame's writes.
1447
- let size = emoteSizes.get(item.text);
1448
- if (!size) {
1449
- size = { w: node.offsetWidth, h: node.offsetHeight };
1450
- emoteSizes.set(item.text, size);
1451
- }
2157
+ bands ??= [hud, hudText, askCard, back, sound?.button].map(shownRect).filter(Boolean);
2158
+ // Use this frame's sampled glyph size, including for repeated emoji.
2159
+ const size = geometry.size(node);
1452
2160
  const { w, h } = size;
1453
2161
  let placed = null;
1454
2162
  if (item.head) {
1455
- placed = placeEmoteBubble(item.head, { w, h }, hudClear ? [] : bands, { w: window.innerWidth, h: window.innerHeight }, item.lift ?? 0);
2163
+ placed = placeEmoteBubble(item.head, { w, h }, hudClear ? [] : bands, { w: geometry.view().w, h: geometry.view().h }, item.lift ?? 0);
1456
2164
  } else if (!hudClear && bands.length) {
1457
- const { dx, dy } = emoteBubbleShift({ left: x - w / 2, right: x + w / 2, top: item.y - h, bottom: item.y }, bands, window.innerWidth);
2165
+ const { dx, dy } = emoteBubbleShift({ left: x - w / 2, right: x + w / 2, top: item.y - h, bottom: item.y }, bands, geometry.view().w);
1458
2166
  placed = dx !== 0 || dy !== 0 ? { left: x - w / 2 + dx, right: x + w / 2 + dx, top: item.y - h + dy, bottom: item.y + dy } : null;
1459
2167
  }
1460
2168
  // A head off the view: no bubble. Any other is shown again.
@@ -1470,18 +2178,19 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1470
2178
  }
1471
2179
  }
1472
2180
  for (const [id, node] of labelNodes) {
1473
- if (!seen.has(id)) {
2181
+ if (!seen.has(id) && !(preserveCrowdSummary && id === 'crowd:summary')) {
1474
2182
  node.remove();
1475
2183
  labelNodes.delete(id);
1476
2184
  }
1477
2185
  }
1478
- if (hudClear) {
2186
+ if (hudClear || hudText.style.display !== 'none') {
1479
2187
  keepClearOfHud(
1480
2188
  'labels',
1481
- // One with its `box` is already where it stays.
2189
+ // Preplaced labels already clear the top band; the bottom pill
2190
+ // is reserved by this shared pass too.
1482
2191
  items.filter((item) => !item.box).map((item) => {
1483
2192
  const node = labelNodes.get(item.id);
1484
- return [node, parseFloat(node.style.left), emoteAt.get(item.id) ?? item.y, 'bottom', item.text];
2193
+ return [node, parseFloat(node.style.left), emoteAt.get(item.id) ?? item.box?.bottom ?? item.y, 'bottom', item.text];
1485
2194
  }),
1486
2195
  );
1487
2196
  }
@@ -1505,9 +2214,10 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1505
2214
  }
1506
2215
  cabinet.style.display = 'block';
1507
2216
  // Kept on screen: a card over a cabinet at the edge of the view.
1508
- const half = cabinet.offsetWidth / 2;
1509
- cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6)}px`;
1510
- cabinet.style.top = `${Math.max(item.y, cabinet.offsetHeight + 6)}px`;
2217
+ const cabinetSize = geometry.size(cabinet);
2218
+ const half = cabinetSize.w / 2;
2219
+ cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6)}px`;
2220
+ cabinet.style.top = `${Math.max(item.y, geometry.size(cabinet).h + 6)}px`;
1511
2221
  if (hudClear) {
1512
2222
  keepClearOfHud('cabinet', [[cabinet, parseFloat(cabinet.style.left), parseFloat(cabinet.style.top), 'bottom', cabinetKey]]);
1513
2223
  }
@@ -1528,6 +2238,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1528
2238
  if (hudClear) {
1529
2239
  keepClearOfHud('ribbon', [[ribbon, pos.x, pos.y, 'bottom', text]]);
1530
2240
  }
2241
+ placeToast();
1531
2242
  },
1532
2243
  setToast(text, { wrap = false } = {}) {
1533
2244
  if (text && wrap) {
@@ -1548,7 +2259,23 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1548
2259
  }
1549
2260
  placeToast();
1550
2261
  },
1551
- showPicker(show, selected, colors) {
2262
+ showPicker(show, selected, colors, invite = null) {
2263
+ invitePick = show ? invite?.onPick ?? null : null;
2264
+ if (invitePick && !inviteRow) {
2265
+ inviteRow = document.createElement('button');
2266
+ Object.assign(inviteRow.style, { minHeight: '44px', padding: '8px 12px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: 'inherit', cursor: 'pointer', flex: 'none' });
2267
+ pickerCard.insertBefore(inviteRow, pickerClose);
2268
+ inviteRow.textContent = 'Invite a friend';
2269
+ inviteRow.type = 'button';
2270
+ inviteRow.addEventListener('click', (event) => {
2271
+ event.stopPropagation();
2272
+ if (!pickerOpen || !invitePick) {return;}
2273
+ const pick = invitePick;
2274
+ setPickerOpen(false);
2275
+ pick();
2276
+ });
2277
+ }
2278
+ if (inviteRow) {inviteRow.style.display = invitePick ? '' : 'none';}
1552
2279
  showColors(selected, colors);
1553
2280
  picker.style.display = show ? 'flex' : 'none';
1554
2281
  if (!show) {
@@ -1563,10 +2290,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1563
2290
  button.setAttribute('aria-pressed', String(i === selected));
1564
2291
  });
1565
2292
  }
2293
+ layoutLandscapeRail();
2294
+ fitPicker();
1566
2295
  },
1567
2296
  // The Graphics row: `mode` is the one picked ('auto', 'low' or 'high').
1568
- setGraphics(mode, onPick) {
1569
- graphics ??= buildGraphics();
2297
+ setGraphics(mode, onPick, weakest = false) {
2298
+ graphics ??= buildGraphics(weakest);
1570
2299
  graphics.onPick = onPick;
1571
2300
  for (const [m, button] of graphics.buttons) {
1572
2301
  button.style.borderColor = m === mode ? '#f2c94c' : 'rgba(255,255,255,0.4)';
@@ -1594,6 +2323,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1594
2323
  emoteButton.style.display = show ? 'block' : 'none';
1595
2324
  if (!show) {
1596
2325
  setEmotesOpen(false);
2326
+ layoutLandscapeRail();
1597
2327
  return;
1598
2328
  }
1599
2329
  const key = emotes.map(([id]) => id).join('|');
@@ -1616,6 +2346,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1616
2346
  emoteHandler(id);
1617
2347
  });
1618
2348
  }
2349
+ layoutLandscapeRail();
1619
2350
  },
1620
2351
  // `say` is { reactions: [emoji], phrases: [[id, words]] } to offer, or
1621
2352
  // null to hide the button; a pick calls the handler with { r } or { p }.
@@ -1623,6 +2354,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1623
2354
  sayButton.style.display = say ? 'block' : 'none';
1624
2355
  if (!say) {
1625
2356
  setSayOpen(false);
2357
+ layoutLandscapeRail();
1626
2358
  return;
1627
2359
  }
1628
2360
  const chat = say.chat ?? null;
@@ -1633,12 +2365,18 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1633
2365
  sayNote.textContent = chat.note ?? '';
1634
2366
  }
1635
2367
  // The field's own words (a deck with cues, v1.23): rewritten in place
1636
- // too. A chat part that names none keeps 'Message…'.
1637
- if (key === sayKey && sayInput && chat?.placeholder && sayInput.placeholder !== chat.placeholder) {
1638
- sayInput.placeholder = chat.placeholder;
1639
- sayInput.setAttribute('aria-label', chat.label ?? chat.placeholder);
2368
+ // too. A chat part that names none reads 'Message…', as a field built
2369
+ // without them does.
2370
+ if (key === sayKey && sayInput && chat && sayInput.placeholder !== (chat.placeholder ?? 'Message…')) {
2371
+ sayInput.placeholder = chat.placeholder ?? 'Message…';
2372
+ if (chat.placeholder) {
2373
+ sayInput.setAttribute('aria-label', chat.label ?? chat.placeholder);
2374
+ } else {
2375
+ sayInput.removeAttribute('aria-label');
2376
+ }
1640
2377
  }
1641
2378
  if (key === sayKey) {
2379
+ layoutLandscapeRail();
1642
2380
  return;
1643
2381
  }
1644
2382
  sayKey = key;
@@ -1671,6 +2409,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1671
2409
  sayInput = null;
1672
2410
  sayNote = null;
1673
2411
  if (!chat) {
2412
+ layoutLandscapeRail();
1674
2413
  return;
1675
2414
  }
1676
2415
  sayNote = el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, sayCard);
@@ -1721,15 +2460,19 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1721
2460
  event.preventDefault();
1722
2461
  send();
1723
2462
  });
2463
+ layoutLandscapeRail();
1724
2464
  },
1725
2465
  // Whether the chat field has the keyboard (the game's keys are its own).
1726
2466
  chatFocused: () => sayInput !== null && document.activeElement === sayInput,
1727
2467
  // The lines of what was just said, oldest first; hidden while a list is open.
1728
2468
  // Each is `{ text, id }`; a line with an `id` is another player's chat
1729
2469
  // message: a tap on it asks whether to report it.
2470
+ setChatModeration(enabled) {
2471
+ chatModeration = enabled === true;
2472
+ },
1730
2473
  setFeed(lines) {
1731
2474
  const shown = doorsOpen || peopleOpen ? [] : lines;
1732
- const key = shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
2475
+ const key = `${chatModeration}:` + shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
1733
2476
  if (key === feedKey) {
1734
2477
  return;
1735
2478
  }
@@ -1747,6 +2490,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1747
2490
  event.stopPropagation();
1748
2491
  node.replaceChildren();
1749
2492
  node.style.display = 'flex';
2493
+ node.style.flexWrap = 'wrap';
1750
2494
  node.style.gap = '6px';
1751
2495
  node.style.alignItems = 'center';
1752
2496
  el('span', {}, node).textContent = 'Report this message?';
@@ -1755,6 +2499,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1755
2499
  node.remove();
1756
2500
  onReportChat(line);
1757
2501
  });
2502
+ if (chatModeration && line.userId) {
2503
+ smallButton(node, 'Report & block', true).addEventListener('pointerdown', (e) => {
2504
+ e.stopPropagation();
2505
+ onBlockChat(line);
2506
+ });
2507
+ }
1758
2508
  smallButton(node, 'Cancel', false).addEventListener('pointerdown', (e) => {
1759
2509
  e.stopPropagation();
1760
2510
  feedKey = '';
@@ -1764,30 +2514,49 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1764
2514
  },
1765
2515
  // The Sit / Stand button's word, or null to hide it.
1766
2516
  sitPrompt(text) {
2517
+ if (actMode) {text = null;}
1767
2518
  sitButton.style.display = text ? 'block' : 'none';
1768
2519
  if (text && sitButton.textContent !== text) {
1769
2520
  sitButton.textContent = text;
1770
2521
  }
2522
+ layoutLandscapeRail();
1771
2523
  },
1772
2524
  // The Grab button's word ("Grab" or "Throw"), or null to hide it.
1773
2525
  grabPrompt(text) {
2526
+ if (actMode) {text = null;}
1774
2527
  grabButton.style.display = text ? 'block' : 'none';
1775
2528
  if (text && grabButton.textContent !== text) {
1776
2529
  grabButton.textContent = text;
1777
2530
  grabButton.style.background = text === 'Throw' ? 'rgba(233,196,143,0.92)' : 'rgba(20,16,12,0.78)';
1778
2531
  grabButton.style.color = text === 'Throw' ? '#2b2118' : '#fff';
1779
2532
  }
2533
+ layoutLandscapeRail();
2534
+ },
2535
+ // Inline state only: prompt changes wake the Weakest panel pass without a layout read.
2536
+ hudPromptSignature() {
2537
+ const prompts = [sitButton, grabButton, talkButton, nearButton];
2538
+ const act = [...extraSurfaces].filter(([id]) => id.startsWith('act-prompt:'));
2539
+ return JSON.stringify([talkOpen, pickerOpen, sayOpen, emotesOpen, peopleOpen, doorsOpen, Boolean(placeMenu?.sheet), Boolean(textAsk?.card),
2540
+ prompts.map(node => [node.style.display, node.textContent]), askNow?.key, askNow?.text,
2541
+ act.map(([id, { node }]) => [id, node.textContent, node.getAttribute('aria-label'), node.style.opacity])]);
1780
2542
  },
1781
2543
  talkRect: () => shownRect(panel),
1782
- // Only companion places call this layout pass; keyless decks keep their CSS.
2544
+ // Every place clears the engine's Shift lock, independently of Chirp.
1783
2545
  layoutCompanion(parent) {
1784
2546
  const lock = parent?.querySelector?.('button[aria-label^="Shift lock"]');
2547
+ if (lock !== companionLock) {restoreCompanionLock(); companionLock = lock; fitPicker(true);}
1785
2548
  const rect = shownRect(lock);
1786
- const lift = rect && lock.style.visibility !== 'hidden' ? rect.bottom - rect.top + 8 : 0;
2549
+ // A lock the strip hid keeps its reserve, or the sheet would then fit
2550
+ // the lane, show the lock, and turn back into the strip next frame.
2551
+ const lift = rect && (lock.style.visibility !== 'hidden' || companionLockVisibility !== null) ? rect.bottom - rect.top + 8 : 0;
1787
2552
  if (lift === lockLift) {return;}
1788
2553
  lockLift = lift;
1789
- for (const [node, bottom] of cornerBottoms) {node.style.bottom = lift ? `calc(${bottom} + ${lift}px)` : bottom;}
1790
- for (const unit of ['vh', 'dvh']) {pickerCard.style.maxHeight = `calc(100${unit} - ${76 + lift}px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;}
2554
+ if (landscape) {
2555
+ layoutLandscapeRail();
2556
+ } else {
2557
+ for (const [node, bottom] of cornerBottoms) {node.style.bottom = lift ? `calc(${bottom} + ${lift}px)` : bottom;}
2558
+ }
2559
+ fitPicker(true);
1791
2560
  },
1792
2561
  setCompanionBadge(show, name, onOpen) {
1793
2562
  if (!show) {
@@ -1798,6 +2567,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1798
2567
  }
1799
2568
  if (!companionBadge) {
1800
2569
  companionBadge = el('button', { width: '44px', height: '44px', flex: '0 0 44px', boxSizing: 'border-box', padding: '8px', borderRadius: '50%', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', cursor: 'pointer', pointerEvents: 'auto', touchAction: 'manipulation' }, dock);
2570
+ geometry.register(companionBadge);
1801
2571
  companionBadge.innerHTML = '<svg viewBox="0 0 28 28" width="26" height="26" aria-hidden="true"><path fill="#fff6e6" d="M3 6l11 5L24 3l-5 13-7 6-2-8z"/><path fill="#e8743b" d="M14 11l5 5-7 6 2-11zM19 16l7 1-6 3z"/></svg>';
1802
2572
  companionBadge.addEventListener('pointerdown', (event) => {
1803
2573
  event.stopPropagation();
@@ -1829,12 +2599,13 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1829
2599
  this.companionTalkButton.style.top = `${screen.y}px`;
1830
2600
  this.companionTalkButton.setAttribute('aria-label', `Chat with ${name}`);
1831
2601
  // Never over a control: a tap there is the control's.
1832
- const controls = [picker, grabButton, emoteButton, sayButton, talkButton, sitButton, sound?.button, back, hud, askCard, actionChips].map(shownRect).filter(Boolean);
2602
+ const controls = [picker, grabButton, emoteButton, sayButton, talkButton, sitButton, sound?.button, back, hud, hudText, askCard, actionChips].map(shownRect).filter(Boolean);
1833
2603
  const covers = controls.some((r) => r.left < screen.x + 22 && r.right > screen.x - 22 && r.top < screen.y + 22 && r.bottom > screen.y - 22);
1834
2604
  this.companionTalkButton.style.display = covers ? 'none' : 'block';
1835
2605
  },
1836
2606
  // The Talk button, for the NPC named, or hidden.
1837
2607
  talkPrompt(name, mind = false) {
2608
+ if (actMode) {name = null;}
1838
2609
  const show = Boolean(name) && !talkOpen;
1839
2610
  talkButton.style.display = show ? 'block' : 'none';
1840
2611
  // A mind's button names it by first name: "Chat with Biscuit", not the
@@ -1843,6 +2614,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1843
2614
  if (show && talkButton.textContent !== text) {
1844
2615
  talkButton.textContent = text;
1845
2616
  }
2617
+ layoutLandscapeRail();
1846
2618
  },
1847
2619
  openTalk(name, { mind = false, canType = true } = {}) {
1848
2620
  talkOpen = true;
@@ -1852,7 +2624,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1852
2624
  dropTyping();
1853
2625
  panelLog.replaceChildren();
1854
2626
  panelOpening = null;
2627
+ followedLine = null;
1855
2628
  dropAsks();
2629
+ dropHint();
1856
2630
  panelInput.value = '';
1857
2631
  panelInput.placeholder = mind ? `Ask ${name.split(',')[0].trim()} anything…` : 'Say something…';
1858
2632
  panelSend.disabled = false;
@@ -1862,6 +2636,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1862
2636
  talkButton.style.display = 'none';
1863
2637
  panelForm.style.display = 'none';
1864
2638
  setTalkTyping(canType);
2639
+ layoutLandscapeRail();
1865
2640
  },
1866
2641
  closeTalk() {
1867
2642
  talkOpen = false;
@@ -1870,9 +2645,29 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1870
2645
  panel.style.display = 'none';
1871
2646
  panelInput.blur();
1872
2647
  dropAsks();
2648
+ dropHint();
1873
2649
  dropTyping();
2650
+ layoutLandscapeRail();
1874
2651
  },
1875
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
+ },
1876
2671
  // A refused re-attach keeps the unsent question for the next open.
1877
2672
  talkDraft(text) {
1878
2673
  if (text !== undefined) {
@@ -1884,30 +2679,34 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1884
2679
  talkOpening(text) {
1885
2680
  if (talkOpen && panelOpening) {
1886
2681
  panelOpening.textContent = text;
2682
+ placeToast();
1887
2683
  }
1888
2684
  },
1889
2685
  // v1.46: a mind's chips sit below its field; an empty list removes them.
1890
2686
  talkAsks(asks, onAsk) {
1891
- const list = Array.isArray(asks) ? asks.slice(0, 3) : [];
2687
+ const child = Array.isArray(asks) && typeof asks[0]?.id === 'string';
2688
+ const list = Array.isArray(asks) ? asks.slice(0, child ? 4 : 3) : [];
1892
2689
  if (!list.length) {
1893
2690
  dropAsks();
1894
2691
  return;
1895
2692
  }
1896
2693
  if (!panelAsks) {
1897
2694
  panelAsks = el('div', { display: 'none', flexWrap: 'wrap', gap: '6px' }, panel);
2695
+ geometry.register(panelAsks);
1898
2696
  if (!panelMind) {
1899
2697
  panel.insertBefore(panelAsks, panelForm);
1900
2698
  }
1901
2699
  }
1902
2700
  panelAsks.replaceChildren();
2701
+ panelChildAsks = child;
1903
2702
  asksHandler = onAsk;
1904
- if (panelMind) {
1905
- el('span', { fontSize: '12px', opacity: '0.7', flexBasis: '100%' }, panelAsks).textContent = 'or try:';
2703
+ if (panelMind && !child) {
2704
+ el('span', { fontSize: '12px', opacity: '0.7', flexBasis: '100%', gridColumn: '1 / -1' }, panelAsks).textContent = 'or try:';
1906
2705
  }
1907
2706
  for (const ask of list) {
1908
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);
1909
2708
  chip.type = 'button';
1910
- chip.textContent = ask;
2709
+ chip.textContent = child ? ask.label : ask;
1911
2710
  chip.addEventListener('pointerdown', (event) => {
1912
2711
  event.stopPropagation();
1913
2712
  event.preventDefault();
@@ -1917,17 +2716,21 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1917
2716
  asksHandler?.(ask);
1918
2717
  });
1919
2718
  }
1920
- panelAsks.style.display = 'flex';
2719
+ layoutPanel();
2720
+ syncTalkSurfaces();
2721
+ followTalkLine();
1921
2722
  },
1922
2723
  // `note`, when given, is a small caption under the line (a scripted reply).
1923
2724
  talkLine(who, text, note = null) {
1924
2725
  // v1.35: where the log was before this line: at its end, or scrolled
1925
2726
  // up by the player to read something earlier.
1926
- const atEnd = panelLog.scrollHeight - panelLog.scrollTop - panelLog.clientHeight <= TALK_END_PX;
2727
+ const scroll = geometry.scroll(panelLog);
2728
+ const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
1927
2729
  if (who === 'them') {
1928
2730
  dropTyping();
1929
2731
  }
1930
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);
1931
2734
  line.textContent = text;
1932
2735
  if (who === 'them' && panelLog.childElementCount === 1) {
1933
2736
  panelOpening = line;
@@ -1935,15 +2738,23 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1935
2738
  if (note) {
1936
2739
  el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
1937
2740
  }
2741
+ let top = scroll.top;
1938
2742
  if (who === 'me') {
1939
2743
  // The player's own words: they have just sent them, show them.
1940
- panelLog.scrollTop = panelLog.scrollHeight;
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;
1941
2747
  } else if (atEnd) {
1942
2748
  // A reply is read from its first word: its top at the top of what
1943
2749
  // shows (the end of the log when the whole reply fits, as the
1944
2750
  // browser stops there). A player reading further up is left there.
1945
- panelLog.scrollTop = line.offsetTop - panelLog.offsetTop;
2751
+ top = geometry.offsets(line).top - geometry.offsets(panelLog).top;
2752
+ panelLog.scrollTop = top;
1946
2753
  }
2754
+ followedLine = who === 'me' || atEnd ? line : null;
2755
+ followedScroll = geometry.active() ? top : panelLog.scrollTop;
2756
+ followedSnapshot = geometry.active() ? scroll : null;
2757
+ placeToast();
1947
2758
  },
1948
2759
  talkWaiting(waiting) {
1949
2760
  panelSend.disabled = waiting;
@@ -1952,7 +2763,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1952
2763
  if (!waiting) {
1953
2764
  dropTyping();
1954
2765
  } else if (talkOpen && panelMind && !panelTyping) {
1955
- const atEnd = panelLog.scrollHeight - panelLog.scrollTop - panelLog.clientHeight <= TALK_END_PX;
2766
+ const scroll = geometry.scroll(panelLog);
2767
+ const atEnd = scroll.height - scroll.top - scroll.client <= TALK_END_PX;
1956
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);
1957
2769
  panelTyping.className = 'hub-npc-typing';
1958
2770
  panelTyping.setAttribute('role', 'status');
@@ -1961,9 +2773,10 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1961
2773
  el('span', {}, panelTyping).textContent = '•';
1962
2774
  }
1963
2775
  if (atEnd) {
1964
- panelLog.scrollTop = panelLog.scrollHeight;
2776
+ panelLog.scrollTop = geometry.active() ? Number.MAX_SAFE_INTEGER : geometry.scroll(panelLog).height;
1965
2777
  }
1966
2778
  }
2779
+ placeToast();
1967
2780
  },
1968
2781
  talkFocused() {
1969
2782
  return document.activeElement === panelInput;
@@ -1990,9 +2803,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
1990
2803
  return;
1991
2804
  }
1992
2805
  doorsKey = key;
1993
- doorsList.replaceChildren();
2806
+ doorsBody.replaceChildren();
1994
2807
  if (stuck) {
1995
- const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '6px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, doorsList);
2808
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '6px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, doorsBody);
1996
2809
  row.dataset.hub = 'stuck-row';
1997
2810
  const words = el('div', { flex: '1', minWidth: '0' }, row);
1998
2811
  el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = 'Stuck?';
@@ -2007,14 +2820,14 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2007
2820
  });
2008
2821
  }
2009
2822
  if (yourRows.length) {
2010
- el('div', { fontSize: '13px', opacity: '0.8' }, doorsList).textContent = 'Your games';
2823
+ el('div', { fontSize: '13px', opacity: '0.8' }, doorsBody).textContent = 'Your games';
2011
2824
  }
2012
2825
  const listed = [...yourRows.map((r) => ({ ...doors.find((d) => d.id === r.door), title: r.title, line: r.line, yours: true })), ...doors];
2013
2826
  for (const [index, door] of listed.entries()) {
2014
2827
  if (index === yourRows.length && yourRows.length) {
2015
- el('div', { fontSize: '13px', opacity: '0.8', borderTop: '1px solid rgba(255,255,255,0.18)', paddingTop: '8px' }, doorsList).textContent = 'All doors';
2828
+ el('div', { fontSize: '13px', opacity: '0.8', borderTop: '1px solid rgba(255,255,255,0.18)', paddingTop: '8px' }, doorsBody).textContent = 'All doors';
2016
2829
  }
2017
- const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsList);
2830
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsBody);
2018
2831
  // The title on a line of its own, with one short word under it on what
2019
2832
  // the door takes (a solo game, how many it needs): beside the button
2020
2833
  // they squeezed the title to a few letters.
@@ -2065,11 +2878,11 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2065
2878
  const key = `${party ?? ''}#${people.map((p) => `${p.key}:${p.username ?? ''}:${p.mark ?? ''}:${(p.actions ?? []).map((a) => a.text).join(',')}:${p.door ?? ''}:${p.where ? 1 : 0}`).join('|')}`;
2066
2879
  if (key !== peopleKey) {
2067
2880
  peopleKey = key;
2068
- peopleList.replaceChildren();
2881
+ peopleBody.replaceChildren();
2069
2882
  peopleRows.clear();
2070
2883
  if (party) {
2071
2884
  // The player's party: how many, and the way out of it.
2072
- const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, peopleList);
2885
+ const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, peopleBody);
2073
2886
  el('div', { flex: '1', fontSize: '12px', opacity: '0.8' }, head).textContent = party;
2074
2887
  smallButton(head, 'Leave party', false).addEventListener('pointerdown', (event) => {
2075
2888
  event.stopPropagation();
@@ -2110,23 +2923,30 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2110
2923
  pointerNodes.set(item.id, node);
2111
2924
  }
2112
2925
  const edge = item.angle !== null && item.angle !== undefined;
2113
- node.arrow.style.display = edge ? 'inline-block' : 'none';
2926
+ const display = edge ? 'inline-block' : 'none';
2927
+ if (node.arrow.style.display !== display) {
2928
+ node.arrow.style.display = display;
2929
+ }
2114
2930
  if (edge) {
2115
2931
  node.arrow.style.transform = `rotate(${item.angle}rad)`;
2116
2932
  }
2117
2933
  if (node.words.textContent !== item.text) {
2118
2934
  node.words.textContent = item.text;
2119
2935
  }
2936
+ node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
2937
+ node.chip.style.left = `${item.x}px`;
2938
+ node.chip.style.top = `${item.y}px`;
2120
2939
  // Kept whole on screen; over a friend it sits above their head.
2121
- const half = node.chip.offsetWidth / 2;
2122
- let x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
2940
+ const size = geometry.size(node.chip);
2941
+ const half = size.w / 2;
2942
+ let x = Math.min(Math.max(item.x, half + 6), geometry.view().w - half - 6);
2123
2943
  let y = item.y;
2124
2944
  if (edge && buttons.length) {
2125
2945
  // The buttons stand in a column at the edge. A chip over any of them
2126
2946
  // goes to the left of them all; one too wide for that goes over the
2127
2947
  // whole column it lies across, or under it with no room over. So no
2128
2948
  // move away from one button can put it on another.
2129
- const tall = node.chip.offsetHeight / 2;
2949
+ const tall = size.h / 2;
2130
2950
  const across = (r) => x + half > r.left - 4 && x - half < r.right + 4;
2131
2951
  if (buttons.some((r) => across(r) && y + tall > r.top && y - tall < r.bottom)) {
2132
2952
  const left = Math.min(...buttons.map((r) => r.left)) - 6 - half;
@@ -2139,9 +2959,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2139
2959
  }
2140
2960
  }
2141
2961
  }
2142
- node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
2143
- node.chip.style.left = `${x}px`;
2144
- node.chip.style.top = `${y}px`;
2962
+ if (node.chip.style.left !== `${x}px`) {node.chip.style.left = `${x}px`;}
2963
+ if (node.chip.style.top !== `${y}px`) {node.chip.style.top = `${y}px`;}
2145
2964
  node.y = y;
2146
2965
  }
2147
2966
  for (const [id, node] of pointerNodes) {
@@ -2150,7 +2969,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2150
2969
  pointerNodes.delete(id);
2151
2970
  }
2152
2971
  }
2153
- if (hudClear) {
2972
+ if (hudClear || hudText.style.display !== 'none') {
2154
2973
  keepClearOfHud(
2155
2974
  'pointers',
2156
2975
  items.map((item) => {
@@ -2161,11 +2980,17 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2161
2980
  );
2162
2981
  }
2163
2982
  },
2983
+ // Whether a card given to `setAsk` now would actually be displayed: not
2984
+ // while the page is hidden or between pagehide and pageshow. The hub
2985
+ // starts no ask lease while this is false.
2986
+ askShowable() {
2987
+ return !askHidden();
2988
+ },
2164
2989
  // `ask` is { key, text, yes, no } (the words and the two buttons'), or
2165
2990
  // null for none; an answer goes to `onAsk(ask, true | false)`.
2166
2991
  setAsk(ask) {
2167
2992
  askNow = ask;
2168
- askCard.style.display = ask ? 'flex' : 'none';
2993
+ askCard.style.display = ask && !askHidden() ? 'flex' : 'none';
2169
2994
  if (!ask || ask.key === askKey) {
2170
2995
  return;
2171
2996
  }
@@ -2181,7 +3006,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2181
3006
  el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.text;
2182
3007
  el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.line;
2183
3008
  if (typeof ask.heart === 'boolean') {
2184
- heartButton(askCard, ask.door, ask.heart);
3009
+ heartButton(askCard, ask.door, ask.heart, true);
2185
3010
  }
2186
3011
  } else {
2187
3012
  el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
@@ -2206,6 +3031,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2206
3031
  nearButton.textContent = text;
2207
3032
  }
2208
3033
  }
3034
+ layoutLandscapeRail();
2209
3035
  },
2210
3036
  // The "Stuck?" chip (v1.33): its words, or null to hide it; a press calls
2211
3037
  // `handler`. Never over an open card or list, like the invite button, and
@@ -2232,10 +3058,10 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2232
3058
  // toast, by where it hangs and not by whether it is drawn.
2233
3059
  const was = stuckSpot;
2234
3060
  if (show) {
2235
- const w = stuckChip.offsetWidth;
2236
- const x = stuckChip.offsetLeft;
2237
- const y = stuckChip.offsetTop;
2238
- const h = stuckChip.offsetHeight;
3061
+ const w = geometry.size(stuckChip).w;
3062
+ const x = geometry.offsets(stuckChip).left;
3063
+ const y = geometry.offsets(stuckChip).top;
3064
+ const h = geometry.size(stuckChip).h;
2239
3065
  stuckSpot = was && was.left === x - w / 2 && was.right === x + w / 2 && was.top === y && was.bottom === y + h ? was : { left: x - w / 2, right: x + w / 2, top: y, bottom: y + h };
2240
3066
  } else {
2241
3067
  stuckSpot = null;
@@ -2271,9 +3097,10 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2271
3097
  }
2272
3098
  sound.button.style.display = show ? 'block' : 'none';
2273
3099
  // Under the frame-rate readout where that is up (`?hubstats`).
2274
- const top = stats.textContent ? `${stats.offsetTop + stats.offsetHeight + 6}px` : 'max(12px, env(safe-area-inset-top))';
3100
+ const top = stats.textContent ? `max(${geometry.offsets(stats).top + geometry.size(stats).h + 6}px, ${soundTop})` : soundTop;
2275
3101
  sound.button.style.top = top;
2276
3102
  sound.card.style.top = `calc(${top} + 46px)`;
3103
+ layoutLandscapeRail();
2277
3104
  const quiet = muted || percent === 0;
2278
3105
  sound.button.textContent = quiet ? '🔇' : '🔊';
2279
3106
  sound.button.setAttribute('aria-label', quiet ? 'Sound: off' : `Sound: ${percent}%`);
@@ -2286,6 +3113,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2286
3113
  },
2287
3114
  // Whether the People list is open (its rows' places are asked for then).
2288
3115
  peopleOpen: () => peopleOpen,
3116
+ pickerSheetOpen: () => pickerOpen,
2289
3117
  setStats(text) {
2290
3118
  stats.style.display = text ? 'block' : 'none';
2291
3119
  if (stats.textContent !== text) {
@@ -2293,22 +3121,84 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2293
3121
  }
2294
3122
  },
2295
3123
  dispose() {
3124
+ api.clearPadContext();
3125
+ askLifecycle.abort();
2296
3126
  if (placeMenu) {clearMenu();}
2297
3127
  if (textAsk) {
2298
3128
  clearTextAsk();
2299
3129
  }
2300
- if (actionChips) {
3130
+ if (actionChips || actionOverflow) {
2301
3131
  clearActions();
2302
3132
  }
2303
3133
  if (hudClearDrawn) {
2304
3134
  restoreHudClear();
2305
3135
  }
3136
+ worldLayout?.begin();
3137
+ safeLayout?.dispose();
3138
+ if (debugLayout && globalThis.castleHub?.layout === debugLayout) {
3139
+ delete globalThis.castleHub.layout;
3140
+ if (!Object.keys(globalThis.castleHub).length) {delete globalThis.castleHub;}
3141
+ }
3142
+ restoreCompanionLock();
3143
+ talkOpen = false;
3144
+ syncTalkCaption();
3145
+ geometry.dispose();
3146
+ unwatchViewport();
2306
3147
  unguardKeys();
2307
3148
  desktopQuery?.removeEventListener?.('change', layoutPanel);
2308
- labelMeasure?.remove();
3149
+ for (const node of labelMeasures.values()) {node.remove();}
2309
3150
  root.remove();
2310
3151
  },
2311
3152
  };
3153
+ const surface = (id, node, kind = 'control', transient = false, margin) => ({ id, node, kind, transient, margin, projected: Boolean(worldLayout) && (kind === 'label' || (kind === 'pointer' && id !== 'stuck')) });
3154
+ const surfaces = () => [
3155
+ surface('hud', hud, 'hud', false, { top: 12 }),
3156
+ surface('hud-prompt', hudText, 'text', false, { bottom: 54 }),
3157
+ surface('back', back, 'control', false, { left: landscape ? 76 : 12, top: 12 }),
3158
+ { ...surface('character', pickerToggle, 'control', false, { right: landscape ? 12 : 10, bottom: 10 }), stack: 3, stackNode: picker },
3159
+ surface('character-card', pickerCard, 'card'),
3160
+ { ...surface('grab', grabButton), stack: 2 }, { ...surface('emote', emoteButton), stack: 1 }, { ...surface('quick-chat', sayButton), stack: 0 },
3161
+ surface('emotes', emoteRow, 'card'), surface('quick-chat-card', sayCard, 'card'),
3162
+ { ...surface('sit', sitButton), stack: 6 }, { ...surface('talk', talkButton), stack: 7 }, { ...surface('near', nearButton), stack: 8 },
3163
+ surface('talk-card', panel, 'card'), surface('doors-card', doorsList, 'card'), surface('people-card', peopleList, 'card'),
3164
+ { ...surface('navigation', dock, 'control', false, { left: 10, bottom: 10 }), reportNodes: () => [
3165
+ { id: 'doors', kind: 'control', node: doorsButton }, { id: 'people', kind: 'control', node: peopleButton },
3166
+ { id: 'companion-badge', kind: 'control', node: companionBadge },
3167
+ ] },
3168
+ surface('sound', sound?.button, 'control', false, { right: 12, top: 64 }), surface('sound-card', sound?.card, 'card'),
3169
+ surface('actions', actionChips), surface('ask-card', askCard, 'card'),
3170
+ surface('menu', placeMenu?.sheet, 'card'), surface('text-ask', textAsk?.card, 'card'),
3171
+ surface('toast', toast, 'toast', true, { top: 12 }), surface('ribbon', ribbon, 'ribbon', true),
3172
+ surface('cabinet', cabinet, 'card', true), surface('feed', feed, 'text', true, { left: 10 }),
3173
+ 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)),
3175
+ ...[...pointerNodes].map(([id, item]) => surface(`pointer:${id}`, item.chip, 'pointer', true)),
3176
+ ...externalEntries().map(([id, item]) => ({ ...surface(id, item.node, item.kind, item.kind === 'text'), ...item.placement, ...(id === 'engine-shift-lock' ? { stack: 4 } : {}) })),
3177
+ ...(actionOverflow?.surfaces?.() ?? []).map((node, i) => surface(`action-overflow:${i}`, node, 'control')),
3178
+ ...[...root.children].filter((node) => node.style.zIndex === '3').flatMap((node) => [...node.children]
3179
+ .map((child, i) => ({ child, i }))
3180
+ // Decorating's full-view world input layer is not a chrome box.
3181
+ .filter(({ child }) => !['0', '0px'].includes(child.style.inset) && (child.tagName === 'BUTTON' || child.style.pointerEvents === 'auto'))
3182
+ .map(({ child, i }) => ({ ...surface(`decor:${i}`, child, i === 0 ? 'control' : 'card'), ...(i === 0 ? { stack: 5 } : {}) }))),
3183
+ ];
3184
+ // Register the static sources once, including flow controls reported by
3185
+ // a compound surface. Lazy elements register as they are constructed.
3186
+ for (const entry of surfaces()) {
3187
+ geometry.register(entry.node); geometry.register(entry.stackNode);
3188
+ for (const child of entry.reportNodes?.() ?? []) {geometry.register(child.node);}
3189
+ }
3190
+ if (worldLabelsDefault) {
3191
+ worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry);
3192
+ }
3193
+ if (safeInsets) {
3194
+ safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
3195
+ if (actionOverflow && actionOverflowObstacles) {actionOverflow.reconcileWatch(actionOverflowObstacles()); actionOverflow.invalidate();}
3196
+ } });
3197
+ debugLayout = () => { safeLayout.flush(); worldLayout?.flush(); return safeLayout.report(); };
3198
+ (globalThis.castleHub ??= {}).layout = debugLayout;
3199
+ safeLayout.flush();
3200
+ }
3201
+ return api;
2312
3202
  }
2313
3203
 
2314
3204
  // Black or white, whichever reads on a `#rrggbb` background.