castle-web-cli 0.4.232 → 0.4.233

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 (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -7,13 +7,22 @@
7
7
  // reports), the pointers to friends out of sight,
8
8
  // the Grab / Throw button (a place with `grab`, v1.3), the emote picker and
9
9
  // the Sit / Stand button (a place with `idle`, v1.6), an arcade cabinet's
10
- // board card (v1.7), and the frame-rate readout behind `?hubstats`. In a place
10
+ // board card (v1.7), the "Stuck?" chip and Doors row (a deck with `hub.stuck`,
11
+ // v1.33), the sound control (a deck with `hub.soundscape`), and the frame-rate
12
+ // readout behind `?hubstats`. In a place
11
13
  // that asks (`hud.clear`, v1.26) the HUD is kept short and what is drawn over
12
14
  // the world is kept out from under it (`hudClear.js`).
13
15
 
16
+ import * as Colors from './avatarColors.js';
17
+ import { AVATAR_FACES } from './avatarFaces.js';
14
18
  import { cardMode, makeCardView, tapCard } from './cabinets.js';
15
19
  import { boxAt, fitPx, hudLayout, pushBelow } from './hudClear.js';
16
- import { guardScrollKeys } from './keys.js';
20
+ import { chipShift } from './stuck.js';
21
+ import { toastBand } from './toastBand.js';
22
+ import { emoteBubbleShift, placeEmoteBubble } from './emoteBubble.js';
23
+ import { guardScrollKeys, takeKeys } from './keys.js';
24
+ import { validPrivateText } from '../privateText.js';
25
+ import { menuIcon } from './menuIcons.js';
17
26
 
18
27
  const Z = 2147480000;
19
28
 
@@ -29,8 +38,17 @@ function el(tag, style, parent = document.body) {
29
38
  // pale sky as it does over a dark street.
30
39
  const BARE_TEXT_SHADOW = '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)';
31
40
 
32
- export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onLeaveParty = () => {}, onReportChat = () => {} }) {
41
+ // The character picker's grid: four cells across, each a tap target this wide
42
+ // (and 62 px tall).
43
+ const PICKER_COLUMNS = 4;
44
+ const PICKER_CELL_PX = 64;
45
+
46
+ // The talk panel's log counts as at its end within this many pixels of it.
47
+ const TALK_END_PX = 8;
48
+
49
+ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onHeart = () => {}, onLeaveParty = () => {}, onReportChat = () => {}, onChip }) {
33
50
  const unguardKeys = guardScrollKeys();
51
+ takeKeys();
34
52
  // A desktop stage (a mouse, room to spare): NPC lines are narrower and the
35
53
  // talk panel sits in the bottom-left corner, clear of the avatar. Phones
36
54
  // and narrow stages keep the layout they were tuned on.
@@ -43,6 +61,8 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
43
61
  const cover = el('div', { position: 'absolute', inset: '0', opacity: '0', background: 'radial-gradient(ellipse at center, #2a1d14 0%, #0b0806 70%)', display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'none' }, root);
44
62
  const coverText = el('div', { opacity: '0.85', letterSpacing: '0.12em', textTransform: 'uppercase', fontSize: '14px', color: '#e9c48f' }, cover);
45
63
 
64
+ let coverLine = null;
65
+
46
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);
47
67
  back.textContent = '‹ Town';
48
68
  back.addEventListener('pointerdown', (event) => {
@@ -56,7 +76,22 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
56
76
  const hudText = el('div', { fontSize: '14px', fontWeight: '500' }, hud);
57
77
 
58
78
  const labels = el('div', { position: 'absolute', inset: '0' }, root);
79
+ // v1.43 `measureLabel`: nothing until a deck that keeps its labels apart asks.
80
+ let labelMeasure = null;
81
+ const labelSizes = new Map();
82
+ // Pointers to friends out of sight (a town) and to a place's goals: a small
83
+ // chip over one far off, or at the screen's edge with an arrow when it is
84
+ // off screen. v1.34: made here, with the labels, so every panel, card and
85
+ // button made after them is drawn over a pointer (they were made after the
86
+ // talk panel, and a goal's arrow sat on the words of the NPC being read).
87
+ // v1.38: and put UNDER the labels, so an NPC's speech bubble is read over a
88
+ // chip (a goal's chip over an NPC cut through the words it was saying).
89
+ const pointers = el('div', { position: 'absolute', inset: '0' }, root);
90
+ root.insertBefore(pointers, labels);
91
+ const pointerNodes = new Map();
59
92
  const labelNodes = new Map();
93
+ // An emote's emoji -> its drawn size `{ w, h }` (`setLabels`).
94
+ const emoteSizes = new Map();
60
95
 
61
96
  // An arcade cabinet's card (v1.7). By the cabinet it is a chip: the best
62
97
  // score and whose it is (their photo in a circle, their frame drawn over it
@@ -154,32 +189,128 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
154
189
 
155
190
  const ribbon = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '6px', background: 'linear-gradient(#f2c94c, #d69e2e)', color: '#3b2600', fontSize: '13px', fontWeight: '800', whiteSpace: 'nowrap', boxShadow: '0 2px 6px rgba(0,0,0,0.4)' }, root);
156
191
 
157
- const toast = el('div', { position: 'absolute', bottom: '64px', left: '50%', transform: 'translateX(-50%)', padding: '8px 14px', borderRadius: '8px', background: 'rgba(20,16,12,0.8)', fontSize: '14px', display: 'none' }, root);
192
+ const toast = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', width: 'max-content', maxWidth: 'calc(100vw - 24px)', boxSizing: 'border-box', textAlign: 'center', padding: '8px 14px', borderRadius: '8px', background: 'rgba(20,16,12,0.8)', fontSize: '14px', display: 'none' }, root);
193
+ toast.dataset.hub = 'toast';
194
+ // Where a phone's toast starts, read in pixels: the safe area's inset has
195
+ // no other way to be measured.
196
+ const toastStart = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '0', width: '0', height: '0', visibility: 'hidden' }, root);
197
+ let toastWrap = null;
158
198
 
159
199
  // The avatar picker: one button, "Character", that opens the kit's
160
- // characters under their own heading. (Four bare numbers read as rooms.)
200
+ // characters under their own heading: a grid, four across, each cell the
201
+ // character's face and name (`avatarFaces.js`, written with the models) and
202
+ // 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
205
+ // on `click`, not on the press, so a finger that scrolls the card picks
206
+ // nothing.
207
+ const overPicker = [];
208
+ const shutRound = [];
161
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);
162
210
  picker.addEventListener('pointerdown', (event) => event.stopPropagation());
163
- 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)' }, picker);
211
+ 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
+ // What is left over the button and its margins; `dvh` where the browser has
213
+ // it (a phone's toolbars), `vh` where it does not.
214
+ for (const unit of ['vh', 'dvh']) {
215
+ pickerCard.style.maxHeight = `calc(100${unit} - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom))`;
216
+ }
164
217
  el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard).textContent = 'Your character';
165
- const pickerRow = el('div', { display: 'flex', gap: '6px' }, pickerCard);
218
+ const pickerRow = el('div', { display: 'grid', gridTemplateColumns: `repeat(${PICKER_COLUMNS}, ${PICKER_CELL_PX}px)`, gap: '6px' }, pickerCard);
166
219
  const pickerButtons = [];
167
220
  let pickerOpen = false;
221
+ let pickerSelected = null;
168
222
  const setPickerOpen = (open) => {
169
223
  pickerOpen = open;
224
+ showCompanionBadge();
225
+ 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)`;
229
+ }
230
+ // Open, the card lies under the round buttons up the right edge and the
231
+ // talk button along the bottom, which would take its taps; they are out
232
+ // of sight until it shuts, and what a round one had open shuts with it.
233
+ for (const button of overPicker) {
234
+ button.style.visibility = open ? 'hidden' : '';
235
+ }
236
+ if (open) {
237
+ for (const shut of shutRound) {
238
+ shut();
239
+ }
240
+ }
170
241
  pickerCard.style.display = open ? 'flex' : 'none';
171
242
  };
172
243
  for (let i = 0; i < avatarCount; i += 1) {
173
- const button = el('button', { width: '34px', height: '34px', borderRadius: '17px', border: '2px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '700 13px system-ui', cursor: 'pointer' }, pickerRow);
174
- button.textContent = String(i + 1);
175
- button.setAttribute('aria-label', `Character ${i + 1}`);
176
- button.addEventListener('pointerdown', (event) => {
244
+ // A character this kit has no face for is a number, as all of them were.
245
+ const [name, face] = AVATAR_FACES[i] ?? [`Character ${i + 1}`, null];
246
+ const button = el('button', { width: `${PICKER_CELL_PX}px`, minHeight: '62px', boxSizing: 'border-box', padding: '4px 0 3px', borderRadius: '12px', border: '2px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 11px/1.2 system-ui, sans-serif', cursor: 'pointer', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '2px', touchAction: 'pan-y', overflow: 'hidden' }, pickerRow);
247
+ if (face) {
248
+ el('div', { width: '36px', height: '36px', flex: 'none', pointerEvents: 'none' }, button).innerHTML = `<svg viewBox="0 0 24 24" width="36" height="36" stroke="#241a2e" stroke-width="1.3" stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">${face}</svg>`;
249
+ }
250
+ el('div', { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', pointerEvents: 'none', fontSize: face ? '11px' : '13px' }, button).textContent = face ? name : String(i + 1);
251
+ button.setAttribute('aria-label', face ? `Character: ${name}` : name);
252
+ button.setAttribute('aria-pressed', 'false');
253
+ button.addEventListener('click', (event) => {
177
254
  event.stopPropagation();
178
255
  setPickerOpen(false);
179
256
  onAvatar(i);
180
257
  });
181
258
  pickerButtons.push(button);
182
259
  }
260
+ let colorRow = null;
261
+ let colorKey = null;
262
+ const colorButtons = [];
263
+ function showColors(selected, { available = false, style = 'toon', color = 0, files = null, model = null } = {}) {
264
+ const palette = Colors.AVATAR_COLORS[selected];
265
+ if (!available || style !== 'toon' || !palette) {
266
+ if (colorRow) {
267
+ colorRow.style.display = 'none';
268
+ }
269
+ colorKey = null;
270
+ return;
271
+ }
272
+ const wornColor = Colors.known(selected, color);
273
+ const key = `${selected}:${wornColor}`;
274
+ if (colorKey === key) {
275
+ return;
276
+ }
277
+ // Dot zero is read from the model's named main part, never a face colour.
278
+ let original;
279
+ try {
280
+ const data = JSON.parse(files?.[model]);
281
+ original = data.parts?.find((part) => palette.main.includes(part.id))?.color;
282
+ } catch {
283
+ // A pack still loading has no original colour to show yet.
284
+ }
285
+ if (!original) {
286
+ if (colorRow) {
287
+ colorRow.style.display = 'none';
288
+ }
289
+ colorKey = null;
290
+ return;
291
+ }
292
+ if (!colorRow) {
293
+ colorRow = document.createElement('div');
294
+ Object.assign(colorRow.style, { display: 'flex', gap: '4px', justifyContent: 'center' });
295
+ pickerCard.insertBefore(colorRow, pickerRow.nextSibling ?? pickerCard.children[2] ?? null);
296
+ for (let c = 0; c < Colors.COLORS; c += 1) {
297
+ 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
+ button.setAttribute('aria-label', `Colour: ${c + 1}`);
299
+ button.addEventListener('click', (event) => {
300
+ event.stopPropagation();
301
+ onColor(c);
302
+ });
303
+ colorButtons.push(button);
304
+ }
305
+ }
306
+ colorRow.style.display = 'flex';
307
+ colorButtons.forEach((button, c) => {
308
+ button.style.background = c === 0 ? original : palette.colors[c - 1][0];
309
+ button.style.borderColor = c === wornColor ? '#f2c94c' : 'rgba(255,255,255,0.4)';
310
+ button.setAttribute('aria-pressed', String(c === wornColor));
311
+ });
312
+ colorKey = key;
313
+ }
183
314
  const pickerToggle = el('button', { 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', cursor: 'pointer' }, picker);
184
315
  pickerToggle.textContent = 'Character';
185
316
  // Graphics: Auto / Low / High, under the characters, in a deck that has
@@ -211,6 +342,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
211
342
  // conversation is open. Keys typed here are the panel's, not the game's.
212
343
  let talkHandlers = { open() {}, send() {}, end() {} };
213
344
  const talkButton = el('button', { position: 'absolute', bottom: 'max(64px, calc(env(safe-area-inset-bottom) + 54px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 18px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, root);
345
+ overPicker.push(talkButton);
214
346
  talkButton.addEventListener('pointerdown', (event) => {
215
347
  event.stopPropagation();
216
348
  talkHandlers.open();
@@ -225,14 +357,64 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
225
357
  talkHandlers.end();
226
358
  });
227
359
  const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
360
+ // v1.46: the mind is answering; reduced motion keeps a plain ellipsis.
361
+ const typingStyle = el('style', {}, root);
362
+ typingStyle.textContent = `
363
+ @keyframes hub-npc-dot { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
364
+ .hub-npc-typing span { animation: hub-npc-dot 1.2s infinite; }
365
+ .hub-npc-typing span:nth-child(2) { animation-delay: .2s; }
366
+ .hub-npc-typing span:nth-child(3) { animation-delay: .4s; }
367
+ @media (prefers-reduced-motion: reduce) {
368
+ .hub-npc-typing span { animation: none; display: none; }
369
+ .hub-npc-typing::after { content: '…'; }
370
+ }
371
+ `;
372
+ let panelTyping = null;
373
+ let panelMind = false;
374
+ let panelOpening = null;
375
+ const dropTyping = () => {
376
+ panelTyping?.remove();
377
+ panelTyping = null;
378
+ };
379
+ // The questions are made only while there are some to offer.
380
+ let panelAsks = null;
381
+ let asksHandler = null;
382
+ // The row is taken out again, not hidden: the panel of a conversation with
383
+ // no questions has the nodes it always had.
384
+ const dropAsks = () => {
385
+ panelAsks?.remove();
386
+ panelAsks = null;
387
+ asksHandler = null;
388
+ };
228
389
  // Not a <form>: castle.xyz plays a deck in a frame sandboxed without
229
390
  // `allow-forms`, where a form's submission (Enter, or a submit button) is
230
391
  // blocked before its submit event fires, so nothing would ever be said.
231
392
  const panelForm = el('div', { display: 'flex', gap: '6px', margin: '0' }, panel);
393
+ // Chat words, not an account: no autofill or saved suggestions (Chrome
394
+ // offered emails on a bare field).
395
+ const chatField = (input, name) => {
396
+ input.type = 'text';
397
+ input.name = name;
398
+ input.autocomplete = 'off';
399
+ input.inputMode = 'text';
400
+ input.setAttribute('autocapitalize', 'sentences');
401
+ input.spellcheck = true;
402
+ };
232
403
  const panelInput = el('input', { flex: '1', minWidth: '0', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 15px system-ui, sans-serif' }, panelForm);
404
+ chatField(panelInput, 'say');
233
405
  panelInput.maxLength = 280;
234
406
  panelInput.placeholder = 'Say something…';
235
407
  panelInput.enterKeyHint = 'send';
408
+ const setTalkTyping = (allowed) => {
409
+ const wasHidden = panelForm.style.display === 'none';
410
+ panelForm.style.display = allowed ? 'flex' : 'none';
411
+ if (!allowed) {
412
+ panelInput.blur();
413
+ dropAsks();
414
+ } else if (wasHidden && globalThis.matchMedia?.('(pointer: fine)').matches && !(globalThis.navigator?.maxTouchPoints > 0)) {
415
+ panelInput.focus({ preventScroll: true });
416
+ }
417
+ };
236
418
  const panelSend = el('button', { padding: '8px 14px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 14px system-ui, sans-serif', cursor: 'pointer' }, panelForm);
237
419
  panelSend.type = 'button';
238
420
  panelSend.textContent = 'Say';
@@ -290,6 +472,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
290
472
  let sitHandler = () => {};
291
473
  const emoteBottom = 'max(146px, calc(env(safe-area-inset-bottom) + 136px))';
292
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);
475
+ overPicker.push(emoteButton);
293
476
  emoteButton.textContent = '☺';
294
477
  emoteButton.setAttribute('aria-label', 'Emote');
295
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);
@@ -298,8 +481,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
298
481
  let emotesKey = '';
299
482
  const setEmotesOpen = (open) => {
300
483
  emotesOpen = open;
484
+ showCompanionBadge();
301
485
  emoteRow.style.display = open ? 'flex' : 'none';
302
486
  };
487
+ shutRound.push(() => setEmotesOpen(false));
303
488
  emoteButton.addEventListener('pointerdown', (event) => {
304
489
  event.stopPropagation();
305
490
  event.preventDefault();
@@ -310,6 +495,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
310
495
  // the feed of what was just said, small, above the dock.
311
496
  let sayHandler = () => {};
312
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);
498
+ overPicker.push(sayButton);
313
499
  sayButton.textContent = '💬';
314
500
  sayButton.setAttribute('aria-label', 'Quick chat');
315
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);
@@ -320,8 +506,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
320
506
  let sayNote = null;
321
507
  const setSayOpen = (open) => {
322
508
  sayOpen = open;
509
+ showCompanionBadge();
323
510
  sayCard.style.display = open ? 'flex' : 'none';
324
511
  };
512
+ shutRound.push(() => setSayOpen(false));
325
513
  sayButton.addEventListener('pointerdown', (event) => {
326
514
  event.stopPropagation();
327
515
  event.preventDefault();
@@ -352,13 +540,17 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
352
540
  doorsList.addEventListener('pointerdown', (event) => event.stopPropagation());
353
541
  let doorsOpen = false;
354
542
  let doorsKey = '';
543
+ // The "Stuck?" row's press (v1.33); never called in a deck without it.
544
+ let stuckRowPick = () => {};
355
545
  function closeDoors() {
356
546
  doorsOpen = false;
547
+ showCompanionBadge();
357
548
  doorsList.style.display = 'none';
358
549
  }
359
550
  doorsButton.addEventListener('pointerdown', (event) => {
360
551
  event.stopPropagation();
361
552
  doorsOpen = !doorsOpen;
553
+ showCompanionBadge();
362
554
  aboveDock(doorsList);
363
555
  doorsList.style.display = doorsOpen ? 'flex' : 'none';
364
556
  closePeople();
@@ -373,15 +565,24 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
373
565
  let peopleKey = '';
374
566
  function closePeople() {
375
567
  peopleOpen = false;
568
+ showCompanionBadge();
376
569
  peopleList.style.display = 'none';
377
570
  }
378
571
  peopleButton.addEventListener('pointerdown', (event) => {
379
572
  event.stopPropagation();
380
573
  peopleOpen = !peopleOpen;
574
+ showCompanionBadge();
381
575
  aboveDock(peopleList);
382
576
  peopleList.style.display = peopleOpen ? 'flex' : 'none';
383
577
  closeDoors();
384
578
  });
579
+ let companionBadge = null;
580
+ function showCompanionBadge() {
581
+ if (companionBadge) {companionBadge.style.display = talkOpen || pickerOpen || peopleOpen || doorsOpen || sayOpen || emotesOpen ? 'none' : 'block';}
582
+ }
583
+ let lockLift = 0;
584
+ const cornerBottoms = new Map([picker, grabButton, emoteButton, emoteRow, sayButton, sayCard].map((node) => [node, node.style.bottom]));
585
+
385
586
  const smallButton = (parent, text, primary) => {
386
587
  const button = el('button', { padding: '5px 12px', borderRadius: '12px', border: primary ? 'none' : '1px solid rgba(255,255,255,0.35)', background: primary ? '#e9c48f' : 'transparent', color: primary ? '#2b2118' : '#fff', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, parent);
387
588
  button.textContent = text;
@@ -458,17 +659,22 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
458
659
  }
459
660
  const peopleRows = new Map();
460
661
 
461
- // Pointers to friends out of sight (a town): a small chip over a friend far
462
- // off, or at the screen's edge with an arrow when they are off screen.
463
- const pointers = el('div', { position: 'absolute', inset: '0' }, root);
464
- const pointerNodes = new Map();
465
-
466
662
  // A question put to the player (v1.10): an invitation to a party, a door
467
663
  // their party wants to go through. One at a time, under the HUD.
468
664
  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);
469
665
  askCard.addEventListener('pointerdown', (event) => event.stopPropagation());
470
666
  let askKey = '';
471
667
  let askNow = null;
668
+ function heartButton(parent, door, hearted) {
669
+ const button = smallButton(parent, hearted ? '♥' : '♡', false);
670
+ button.style.flex = 'none';
671
+ button.setAttribute('aria-label', hearted ? 'Remove heart' : 'Heart this game');
672
+ button.setAttribute('aria-pressed', String(hearted));
673
+ button.addEventListener('pointerdown', (event) => {
674
+ event.stopPropagation();
675
+ onHeart(door);
676
+ });
677
+ }
472
678
  // Standing by someone who is not in the player's party: invite them.
473
679
  let nearHandler = () => {};
474
680
  const nearButton = el('button', { position: 'absolute', bottom: 'max(160px, calc(env(safe-area-inset-bottom) + 150px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '6px 14px', borderRadius: '16px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '600 13px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', maxWidth: '80vw', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, root);
@@ -478,6 +684,134 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
478
684
  nearHandler();
479
685
  });
480
686
 
687
+ // "Stuck?" (v1.33, `stuck.js`): a chip at the bottom centre, over the invite
688
+ // button's row, between the dock on the left and the round buttons on the
689
+ // right (never wider than leaves them clear: its words wrap). That is where
690
+ // it hangs; where it is drawn is `placeStuckChip`'s. Built on the first
691
+ // `stuckPrompt` with words, so a deck without `hub.stuck` has no node of it.
692
+ let stuckChip = null;
693
+ let stuckHandler = () => {};
694
+ let stuckShift = 'translateX(-50%)';
695
+ // Where the chip hangs while it is asked for (null otherwise): the room a
696
+ // toast leaves it, whether or not it could be drawn this frame.
697
+ let stuckSpot = null;
698
+ const shownRect = (node) => {
699
+ if (!node || node.style.display === 'none') {
700
+ return null;
701
+ }
702
+ const r = node.getBoundingClientRect();
703
+ return r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
704
+ };
705
+ // Measured only while a toast is up, on every setToast (said each frame, so
706
+ // a resize or a turned stage is met by the next one) and again after the
707
+ // chip is asked for. Everything a player taps is in its way, wherever it
708
+ // hangs (`toastBand`); the chip by the spot it is asked for at
709
+ // (`stuckSpot`), drawn this frame or not, so the two never chase each
710
+ // other's last box. The boxes are read before either inset is written,
711
+ // and a phone's toast starts under the safe area (`toastStart`).
712
+ function placeToast() {
713
+ if (toast.style.display === 'none') {
714
+ return;
715
+ }
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);
720
+ if (stuckSpot) {
721
+ rects.push(stuckSpot);
722
+ }
723
+ const band = toastBand({ desktop: wide, viewW: window.innerWidth, viewH: window.innerHeight, width, height, rects, start: Math.max(12, toastStart.offsetTop || 0) });
724
+ const nextTop = wide ? '' : `${band.top}px`;
725
+ const nextBottom = wide ? `${band.bottom}px` : '';
726
+ if (toast.style.top !== nextTop) {
727
+ toast.style.top = nextTop;
728
+ }
729
+ if (toast.style.bottom !== nextBottom) {
730
+ toast.style.bottom = nextBottom;
731
+ }
732
+ }
733
+ // The chip is kept out from under the HUD and a question the way a clear
734
+ // HUD keeps labels out from under itself (`hudClear.js`): moved to just
735
+ // under them, never off the view -- in any place, not only one that asks
736
+ // for `hud.clear`, since on a short view (a phone on its side) where it
737
+ // hangs is where they are. Where that leaves it over another control, or
738
+ // no room at all, it is not drawn (`chipShift`): the Doors row is still
739
+ // there. The toast reserves room for an asked-for chip on desktop; the
740
+ // chip otherwise yields to what a player taps or reads as a card. A
741
+ // cabinet's card and the ribbon are read where a clear HUD's flush left them, so this runs after
742
+ // `flushHudClear` in a frame. What is hung on the world -- labels, speech,
743
+ // pointers -- is not in its way: it passes under the chip as under every
744
+ // other button (their layers are made before it, so it is drawn over them),
745
+ // and a bubble drifting across never takes the chip down. Everything is
746
+ // read first, then the one style is written. Only while the chip is asked
747
+ // for; false when it cannot be drawn.
748
+ function placeStuckChip() {
749
+ const w = stuckChip.offsetWidth;
750
+ const h = stuckChip.offsetHeight;
751
+ const left = stuckChip.offsetLeft - w / 2;
752
+ const top = stuckChip.offsetTop;
753
+ 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);
756
+ if (down === null) {
757
+ return false;
758
+ }
759
+ const shift = down > 0 ? `translate(-50%, ${down}px)` : 'translateX(-50%)';
760
+ if (shift !== stuckShift) {
761
+ stuckShift = shift;
762
+ stuckChip.style.transform = shift;
763
+ }
764
+ return true;
765
+ }
766
+ function buildStuckChip() {
767
+ const chip = el('button', { position: 'absolute', bottom: 'max(202px, calc(env(safe-area-inset-bottom) + 192px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '9px 12px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: '600 12px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', boxSizing: 'border-box', width: 'max-content', maxWidth: 'calc(100vw - 170px)', textAlign: 'center' }, root);
768
+ chip.dataset.hub = 'stuck';
769
+ chip.addEventListener('pointerdown', (event) => {
770
+ event.stopPropagation();
771
+ event.preventDefault();
772
+ stuckHandler();
773
+ });
774
+ return chip;
775
+ }
776
+
777
+ // 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
779
+ // the column of round buttons at the bottom right; a tap opens a card under
780
+ // it with Mute and a volume slider. Built on the first `soundControl`, so a
781
+ // deck without the key has no node of it.
782
+ let sound = null;
783
+ 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);
786
+ 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);
788
+ card.dataset.hub = 'sound-card';
789
+ card.addEventListener('pointerdown', (event) => event.stopPropagation());
790
+ 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);
791
+ const slider = el('input', { flex: '1', minWidth: '0', height: '28px', margin: '0', accentColor: '#e9c48f', cursor: 'pointer' }, card);
792
+ slider.type = 'range';
793
+ slider.min = '0';
794
+ slider.max = '100';
795
+ slider.step = '1';
796
+ slider.setAttribute('aria-label', 'Volume');
797
+ const made = { button, card, mute, slider, open: false, key: '', handlers: { onVolume() {}, onMuted() {} }, muted: false };
798
+ button.addEventListener('pointerdown', (event) => {
799
+ event.stopPropagation();
800
+ event.preventDefault();
801
+ made.open = !made.open;
802
+ card.style.display = made.open ? 'flex' : 'none';
803
+ });
804
+ mute.addEventListener('pointerdown', (event) => {
805
+ event.stopPropagation();
806
+ event.preventDefault();
807
+ made.handlers.onMuted(!made.muted);
808
+ });
809
+ slider.addEventListener('input', () => made.handlers.onVolume(Number(slider.value) / 100));
810
+ // The arrow keys are the avatar's again once the slider is let go.
811
+ slider.addEventListener('change', () => slider.blur?.());
812
+ return made;
813
+ }
814
+
481
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);
482
816
 
483
817
  // A clear HUD (v1.26, `hudClear.js`), in a place whose manifest asks for it
@@ -607,8 +941,258 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
607
941
  }
608
942
  }
609
943
 
944
+ // v1.74: made only when an opted-in place offers chips.
945
+ let actionChips = null, actionKey = '', actionHandler = null, actionListeners = null;
946
+ function clearActions() {
947
+ actionListeners?.abort();
948
+ actionChips?.remove();
949
+ actionChips = actionListeners = actionHandler = null;
950
+ actionKey = '';
951
+ }
952
+
953
+ // v1.75: only allocated for an opted-in prompt. The field is the only
954
+ // DOM node that ever holds an answer, and it is wiped on every close.
955
+ let textAsk = null;
956
+ function closeTextAsk() {
957
+ if (!textAsk?.card) {
958
+ return;
959
+ }
960
+ textAsk.listeners.abort();
961
+ textAsk.input.value = '';
962
+ textAsk.input.blur();
963
+ textAsk.shield.remove();
964
+ textAsk.card = textAsk.shield = textAsk.input = textAsk.listeners = null;
965
+ textAsk.onOpen?.(false);
966
+ textAsk.onOpen = textAsk.cancel = null;
967
+ }
968
+ function clearTextAsk() {
969
+ closeTextAsk();
970
+ textAsk = null;
971
+ }
972
+
973
+ // v1.79: only an opted-in offer creates this bottom sheet or its CSS.
974
+ let placeMenu = null;
975
+ function closeMenu() {
976
+ if (!placeMenu?.sheet) {return;}
977
+ placeMenu.listeners.abort();
978
+ for (const timer of placeMenu.timers) { clearTimeout(timer); }
979
+ placeMenu.sheet.remove();
980
+ placeMenu.css.remove();
981
+ placeMenu.sheet = placeMenu.css = placeMenu.listeners = null;
982
+ placeMenu.onOpen?.(false);
983
+ placeMenu.onOpen = placeMenu.cancel = null;
984
+ }
985
+ function clearMenu() {
986
+ closeMenu();
987
+ placeMenu = null;
988
+ }
989
+ function setMenu(offer, handler, onOpen) {
990
+ if (!offer) { closeMenu(); return; }
991
+ if (placeMenu && offer.n <= placeMenu.n) {return;}
992
+ closeMenu();
993
+ placeMenu = { n: offer.n };
994
+ const spec = offer.spec;
995
+ if (!spec) {return;}
996
+ if (Object.hasOwn(spec, 'face')) {placeMenu.face = spec.face;}
997
+ const height = Object.hasOwn(spec, 'face') ? 40 : 55;
998
+ const listeners = new AbortController(), signal = listeners.signal, timers = new Set();
999
+ // The same column, padding, corners and shadow as the Doors/chat panels.
1000
+ // 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);
1002
+ sheet.className = 'hub-menu-sheet';
1003
+ sheet.dataset.hub = 'menu';
1004
+ sheet.setAttribute('role', 'dialog');
1005
+ sheet.setAttribute('aria-label', spec.title);
1006
+ const css = el('style', {}, sheet);
1007
+ css.textContent = `
1008
+ .hub-menu-tile { color: inherit; font: inherit; border: 1px solid var(--castle-border-2, rgba(255,255,255,.4)); background: var(--castle-surface-4, rgba(255,255,255,.1)); border-radius: 8px; }
1009
+ .hub-menu-tile:not(:disabled) { cursor: pointer; }
1010
+ .hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { background: var(--castle-surface-5, rgba(255,255,255,.18)); transform: scale(.96); }
1011
+ @media (hover: hover) { .hub-menu-tile:not(:disabled):hover { border-color: var(--castle-text-primary, #fff); } }
1012
+ @media (prefers-reduced-motion: reduce) { .hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { transform: none; } }
1013
+ @media (max-width: 600px) { .hub-menu-grid { grid-template-columns: repeat(4, minmax(64px, 1fr)) !important; } }
1014
+ @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
+ `;
1017
+ for (const type of ['pointerdown', 'pointermove', 'pointerup', 'mousedown', 'wheel', 'contextmenu', 'keydown', 'keyup']) {
1018
+ sheet.addEventListener(type, (event) => event.stopPropagation(), { signal });
1019
+ }
1020
+ const cancel = () => {
1021
+ if (!placeMenu?.sheet) {return;}
1022
+ closeMenu();
1023
+ handler('close', offer.n);
1024
+ };
1025
+ globalThis.addEventListener?.('keydown', (event) => {
1026
+ if (event.key === 'Escape' || event.key === 'BrowserBack') {
1027
+ event.preventDefault(); event.stopImmediatePropagation(); cancel();
1028
+ }
1029
+ }, { capture: true, signal });
1030
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px', flexShrink: '0' }, sheet);
1031
+ el('div', { flex: '1', overflowWrap: 'anywhere' }, row).textContent = spec.title;
1032
+ const close = smallButton(row, '×', false);
1033
+ close.type = 'button';
1034
+ Object.assign(close.style, { minWidth: '44px', minHeight: '44px', touchAction: 'manipulation' });
1035
+ close.setAttribute('aria-label', 'Close');
1036
+ close.addEventListener('pointerdown', (event) => event.preventDefault(), { signal });
1037
+ close.addEventListener('click', () => { close.blur(); cancel(); }, { signal });
1038
+ if (spec.note) {el('div', { fontSize: '13px', color: 'var(--castle-text-secondary, #fff)', overflowWrap: 'anywhere', flexShrink: '0' }, sheet).textContent = spec.note;}
1039
+ const scroll = el('div', { overflowY: 'auto', minHeight: '0', overscrollBehavior: 'contain', touchAction: 'pan-y' }, sheet);
1040
+ for (const section of spec.sections) {
1041
+ el('div', { fontSize: '13px', margin: '8px 0', color: 'var(--castle-text-secondary, #fff)' }, scroll).textContent = section.title;
1042
+ const grid = el('div', { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(64px, 1fr))', gap: '8px' }, scroll);
1043
+ grid.className = 'hub-menu-grid';
1044
+ for (const item of section.items) {
1045
+ const tile = el('button', { position: 'relative', aspectRatio: '1', minWidth: '64px', minHeight: '64px', padding: '6px', overflow: 'hidden', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '4px', touchAction: 'manipulation', overflowWrap: 'anywhere' }, grid);
1046
+ tile.className = 'hub-menu-tile'; tile.type = 'button'; tile.disabled = spec.readOnly === true;
1047
+ tile.dataset.id = item.id;
1048
+ tile.setAttribute('aria-label', item.label);
1049
+ tile.setAttribute('aria-pressed', item.on === true ? 'true' : 'false');
1050
+ if (item.on) {
1051
+ tile.style.outline = '2px solid var(--castle-text-primary, #fff)';
1052
+ tile.style.outlineOffset = '-3px';
1053
+ el('span', { position: 'absolute', top: '2px', right: '4px', fontSize: '12px' }, tile).textContent = '✓';
1054
+ }
1055
+ const swatch = el('span', { width: '28px', height: '28px', flexShrink: '0', borderRadius: item.icon ? '0' : '6px', background: item.color ?? 'var(--castle-text-primary, #fff)' }, tile);
1056
+ if (item.icon) {
1057
+ swatch.style.maskImage = swatch.style.webkitMaskImage = menuIcon(item.icon);
1058
+ swatch.style.maskSize = swatch.style.webkitMaskSize = 'contain';
1059
+ swatch.style.maskRepeat = swatch.style.webkitMaskRepeat = 'no-repeat';
1060
+ }
1061
+ swatch.setAttribute('aria-hidden', 'true');
1062
+ el('span', { fontSize: '12px', lineHeight: '1.15', maxHeight: '2.3em', overflow: 'hidden' }, tile).textContent = item.label;
1063
+ if (!tile.disabled) {
1064
+ tile.addEventListener('pointerdown', (event) => event.preventDefault(), { signal });
1065
+ tile.addEventListener('click', () => {
1066
+ if (!placeMenu?.sheet) {return;}
1067
+ tile.blur();
1068
+ tile.className = 'hub-menu-tile is-pressed';
1069
+ const timer = setTimeout(() => { tile.className = 'hub-menu-tile'; timers.delete(timer); }, 120);
1070
+ timers.add(timer);
1071
+ handler(item.id, offer.n);
1072
+ }, { signal });
1073
+ }
1074
+ }
1075
+ }
1076
+ Object.assign(placeMenu, { sheet, css, listeners, timers, onOpen, cancel });
1077
+ onOpen?.(true);
1078
+ }
1079
+
610
1080
  return {
611
- setCover(alpha, text) {
1081
+ setMenu, clearMenu,
1082
+ cancelMenu: () => placeMenu?.cancel?.(),
1083
+ menuOpen: () => !!placeMenu?.sheet,
1084
+ menuFace: () => placeMenu?.sheet ? placeMenu.face : undefined,
1085
+ setTextAsk(spec, handler, onOpen) {
1086
+ if (!spec) {
1087
+ closeTextAsk();
1088
+ return;
1089
+ }
1090
+ if (textAsk && spec.n <= textAsk.n) {
1091
+ return;
1092
+ }
1093
+ closeTextAsk();
1094
+ textAsk = { n: spec.n };
1095
+ if (spec.id === null) {
1096
+ return;
1097
+ }
1098
+ const listeners = new AbortController(), signal = listeners.signal;
1099
+ // Like the decor panel's world surface: gestures belong to the card,
1100
+ // never the canvas underneath it. No surface exists while it is closed.
1101
+ // It is drawn over every other control of the chrome, dimmed, so nothing
1102
+ // sits on the card or looks tappable through it.
1103
+ const shield = el('div', { position: 'absolute', inset: '0', zIndex: '10', background: 'rgba(0,0,0,0.35)', pointerEvents: 'auto', touchAction: 'none' }, root);
1104
+ for (const type of ['pointerdown', 'pointermove', 'pointerup', 'wheel', 'contextmenu', 'keydown', 'keyup', 'keypress']) {
1105
+ shield.addEventListener(type, (event) => {
1106
+ event.stopPropagation();
1107
+ if (event.target === shield) {
1108
+ event.preventDefault();
1109
+ }
1110
+ }, { signal, passive: false });
1111
+ }
1112
+ const card = el('div', { position: 'fixed', left: '50%', transform: 'translateX(-50%)', width: 'min(90vw, 320px)', boxSizing: 'border-box', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '10px', padding: '14px', borderRadius: '12px', background: '#17120e', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', fontSize: '14px' }, shield);
1113
+ card.setAttribute('role', 'dialog');
1114
+ card.setAttribute('aria-label', spec.title);
1115
+ const place = () => {
1116
+ const view = window.visualViewport;
1117
+ // Stay in the visible viewport as the phone keyboard rises.
1118
+ const bottom = view ? window.innerHeight - view.height - view.offsetTop : 0;
1119
+ card.style.bottom = `max(${bottom + 24}px, calc(env(safe-area-inset-bottom) + 24px))`;
1120
+ };
1121
+ place();
1122
+ window.visualViewport?.addEventListener('resize', place, { signal });
1123
+ window.visualViewport?.addEventListener('scroll', place, { signal });
1124
+ for (const type of ['pointerdown', 'mousedown', 'keydown', 'keyup']) {
1125
+ card.addEventListener(type, (event) => event.stopPropagation(), { signal });
1126
+ }
1127
+ el('div', { fontWeight: '600' }, card).textContent = spec.title;
1128
+ const input = el('input', { width: '100%', boxSizing: 'border-box', minHeight: '44px', padding: '8px 10px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.35)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '16px system-ui, sans-serif' }, card);
1129
+ input.type = 'text';
1130
+ // DOM maxlength counts UTF-16 units; the input handler limits code points.
1131
+ input.maxLength = 2 * spec.max;
1132
+ input.autocomplete = 'off';
1133
+ input.setAttribute('autocorrect', 'off');
1134
+ input.spellcheck = false;
1135
+ input.setAttribute('autocapitalize', 'words');
1136
+ input.setAttribute('aria-label', spec.title);
1137
+ const row = el('div', { display: 'flex', justifyContent: 'flex-end', gap: '8px' }, card);
1138
+ const ok = smallButton(row, 'OK', true), cancel = smallButton(row, 'Cancel', false);
1139
+ for (const button of [ok, cancel]) {
1140
+ button.type = 'button';
1141
+ button.style.minHeight = '44px';
1142
+ button.style.minWidth = '64px';
1143
+ button.style.touchAction = 'manipulation';
1144
+ }
1145
+ ok.disabled = true;
1146
+ ok.style.opacity = '0.45';
1147
+ const changed = () => {
1148
+ if (!input.composing) {
1149
+ input.value = Array.from(input.value).slice(0, spec.max).join('');
1150
+ }
1151
+ ok.disabled = input.composing || !validPrivateText(input.value, spec.max);
1152
+ ok.style.opacity = ok.disabled ? '0.45' : '';
1153
+ };
1154
+ input.addEventListener('compositionstart', () => { input.composing = true; ok.disabled = true; ok.style.opacity = '0.45'; }, { signal });
1155
+ input.addEventListener('compositionend', () => { input.composing = false; changed(); }, { signal });
1156
+ input.addEventListener('input', changed, { signal });
1157
+ const answer = (cancelled) => {
1158
+ if (!textAsk?.card || (!cancelled && (input.composing || !validPrivateText(input.value, spec.max)))) {
1159
+ return;
1160
+ }
1161
+ const text = cancelled ? null : input.value;
1162
+ closeTextAsk();
1163
+ handler(spec.id, spec.n, text);
1164
+ };
1165
+ ok.addEventListener('click', () => answer(false), { signal });
1166
+ cancel.addEventListener('click', () => answer(true), { signal });
1167
+ input.addEventListener('keydown', (event) => {
1168
+ event.stopPropagation();
1169
+ if (event.isComposing || event.keyCode === 229) {
1170
+ return;
1171
+ }
1172
+ if (event.key === 'Enter') {
1173
+ event.preventDefault();
1174
+ answer(false);
1175
+ }
1176
+ }, { signal });
1177
+ Object.assign(textAsk, { card, shield, input, listeners, onOpen, cancel: () => answer(true) });
1178
+ onOpen?.(true);
1179
+ input.focus();
1180
+ },
1181
+ clearTextAsk,
1182
+ cancelTextAsk: () => textAsk?.cancel?.(),
1183
+ textAskOpen: () => !!textAsk?.card,
1184
+ textAskPending: (spec) => !!spec && spec.id !== null && (!textAsk || spec.n > textAsk.n),
1185
+ setCover(alpha, text, line = '') {
1186
+ if (line && !coverLine) {
1187
+ coverLine = el('div', { marginTop: '12px', width: 'min(84vw, 420px)', textAlign: 'center', overflowWrap: 'anywhere', fontSize: '12px', lineHeight: '1.5', color: '#e9c48f', opacity: '0.85' }, cover);
1188
+ }
1189
+ if (coverLine) {
1190
+ if (coverLine.textContent !== line) {
1191
+ coverLine.textContent = line;
1192
+ }
1193
+ coverLine.style.display = line ? 'block' : 'none';
1194
+ cover.style.flexDirection = line ? 'column' : '';
1195
+ }
612
1196
  cover.style.opacity = String(alpha);
613
1197
  cover.style.pointerEvents = alpha > 0.05 ? 'auto' : 'none';
614
1198
  if (text !== undefined && coverText.textContent !== text) {
@@ -622,6 +1206,104 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
622
1206
  back.textContent = text;
623
1207
  }
624
1208
  },
1209
+ setActions(items, handler, canAct, n) {
1210
+ if (!items?.length) {
1211
+ clearActions();
1212
+ return;
1213
+ }
1214
+ actionHandler = handler;
1215
+ const key = JSON.stringify([items, n]);
1216
+ if (key !== actionKey) {
1217
+ clearActions();
1218
+ actionHandler = handler;
1219
+ actionKey = key;
1220
+ 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);
1222
+ actionChips.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: actionListeners.signal });
1223
+ for (const item of items.slice(0, 3)) {
1224
+ 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);
1225
+ chip.type = 'button';
1226
+ chip.tabIndex = -1;
1227
+ chip.textContent = item.label;
1228
+ const pointer = (event) => {
1229
+ event.preventDefault();
1230
+ event.stopPropagation();
1231
+ };
1232
+ chip.addEventListener('pointerdown', pointer, { signal: actionListeners.signal });
1233
+ chip.addEventListener('mousedown', pointer, { signal: actionListeners.signal });
1234
+ for (const type of ['keydown', 'keyup']) {
1235
+ chip.addEventListener(type, pointer, { signal: actionListeners.signal });
1236
+ }
1237
+ chip.addEventListener('click', (event) => {
1238
+ event.stopPropagation();
1239
+ chip.blur();
1240
+ if (actionChips && actionChips.style.display !== 'none') {
1241
+ onChip?.();
1242
+ actionHandler?.(item.id, n);
1243
+ }
1244
+ }, { signal: actionListeners.signal });
1245
+ }
1246
+ }
1247
+ const show = canAct && !pickerOpen && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen && !talkOpen;
1248
+ actionChips.style.display = show ? 'flex' : 'none';
1249
+ if (!show) {
1250
+ return;
1251
+ }
1252
+ // Decor mounts a z=3 layer here, with its entry button first. Measure
1253
+ // that button only when its layer is drawn, never the full-view layer.
1254
+ const decor = [...root.children].find((node) => node.style.zIndex === '3');
1255
+ 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
+ }
1275
+ }
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;
1289
+ }
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';
1294
+ },
1295
+ clearActions,
1296
+ // v1.67: called only in a decor place; the tray uses the same chrome root.
1297
+ decorRoot() {
1298
+ return root;
1299
+ },
1300
+ setDecorating(on) {
1301
+ hud.style.visibility = on ? 'hidden' : '';
1302
+ picker.style.visibility = on ? 'hidden' : '';
1303
+ back.style.zIndex = on ? '4' : '';
1304
+ back.style.top = on ? 'auto' : 'max(12px, env(safe-area-inset-top))';
1305
+ back.style.bottom = on ? 'max(196px, calc(env(safe-area-inset-bottom) + 186px))' : '';
1306
+ },
625
1307
  setHud(spec, timerSeconds) {
626
1308
  if (!spec) {
627
1309
  hud.style.display = 'none';
@@ -655,8 +1337,43 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
655
1337
  // `items` is [{ id, x, y, text, speech, npc, color }] in CSS pixels (a
656
1338
  // `color` is a player's mark); anything not
657
1339
  // listed is removed.
1340
+ // The HUD's box that this frame's flush will move labels out from under
1341
+ // (v1.26), or null when nothing will be moved: no clear HUD asked for, or
1342
+ // none drawn. For v1.43's rule, which must judge where labels end up.
1343
+ hudClearBox() {
1344
+ return hudClear && hud.style.display !== 'none' ? hudClearRect : null;
1345
+ },
1346
+ // How big a label with these words is drawn, `{ w, h }` in CSS pixels
1347
+ // (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);
1367
+ }
1368
+ return size;
1369
+ },
658
1370
  setLabels(items) {
659
1371
  const seen = new Set();
1372
+ // The top chrome an emote's emoji is kept from under (`emoteBubble.js`),
1373
+ // read once a call and only when an emote is drawn.
1374
+ let bands = null;
1375
+ // An emote put on its head: id -> the bottom it was put at.
1376
+ const emoteAt = new Map();
660
1377
  for (const item of items) {
661
1378
  seen.add(item.id);
662
1379
  let node = labelNodes.get(item.id);
@@ -667,19 +1384,27 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
667
1384
  // An NPC's line is kept on screen: a reply over one at the edge of the
668
1385
  // view would otherwise be cut off mid-sentence. Other labels are
669
1386
  // placed as they always were.
1387
+ // v1.43: an item that comes with its `box` (`labelsNear.js` `labelBox`:
1388
+ // measured for these words, kept on the screen, moved from under a
1389
+ // clear HUD) is put exactly there and moved by nothing after, so what
1390
+ // is drawn is what the rule judged. No other item has one.
670
1391
  let x = item.x;
671
- if (item.npc) {
1392
+ if (item.box) {
1393
+ x = (item.box.left + item.box.right) / 2;
1394
+ } else if (item.npc) {
672
1395
  const half = node.offsetWidth / 2;
673
1396
  x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
674
1397
  }
675
1398
  node.style.left = `${x}px`;
676
- node.style.top = `${item.y}px`;
1399
+ node.style.top = `${item.box ? item.box.bottom : item.y}px`;
677
1400
  if (item.speech) {
678
1401
  node.style.background = 'rgba(255,250,240,0.94)';
679
1402
  node.style.color = '#2b2118';
680
1403
  node.style.whiteSpace = 'normal';
681
- if (item.npc) {
682
- // Its own width, not what is left of the screen to its right.
1404
+ if (item.npc || item.box) {
1405
+ // Its own width, not what is left of the screen to its right
1406
+ // (v1.43: so is any line that comes with its box, which was
1407
+ // measured that way).
683
1408
  node.style.width = 'max-content';
684
1409
  }
685
1410
  node.style.maxWidth = item.npc && desktop() ? 'min(62vw, 320px)' : '62vw';
@@ -690,7 +1415,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
690
1415
  // An emote's emoji over a player: large, on nothing.
691
1416
  node.dataset.emote = '1';
692
1417
  node.style.background = 'transparent';
693
- node.style.fontSize = '30px';
1418
+ node.style.fontSize = '42px';
1419
+ // The glyph's own box, so it sits on the head it was put over.
1420
+ node.style.lineHeight = '1';
694
1421
  node.style.padding = '0';
695
1422
  node.style.textShadow = '0 2px 4px rgba(0,0,0,0.5)';
696
1423
  }
@@ -709,6 +1436,38 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
709
1436
  if (node.textContent !== item.text) {
710
1437
  node.textContent = item.text;
711
1438
  }
1439
+ if (item.emote && !item.box) {
1440
+ // An emote's emoji sits on its head (`emoteBubble.js`): just above
1441
+ // it, or beside it where above is off the view or under the top
1442
+ // chrome, and never under the top chrome. A clear HUD moves what is
1443
+ // 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
+ }
1452
+ const { w, h } = size;
1453
+ let placed = null;
1454
+ if (item.head) {
1455
+ placed = placeEmoteBubble(item.head, { w, h }, hudClear ? [] : bands, { w: window.innerWidth, h: window.innerHeight }, item.lift ?? 0);
1456
+ } 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);
1458
+ 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
+ }
1460
+ // A head off the view: no bubble. Any other is shown again.
1461
+ const visibility = item.head && !placed ? 'hidden' : '';
1462
+ if ((node.style.visibility || '') !== visibility) {
1463
+ node.style.visibility = visibility;
1464
+ }
1465
+ if (placed) {
1466
+ node.style.left = `${(placed.left + placed.right) / 2}px`;
1467
+ node.style.top = `${placed.bottom}px`;
1468
+ emoteAt.set(item.id, placed.bottom);
1469
+ }
1470
+ }
712
1471
  }
713
1472
  for (const [id, node] of labelNodes) {
714
1473
  if (!seen.has(id)) {
@@ -719,9 +1478,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
719
1478
  if (hudClear) {
720
1479
  keepClearOfHud(
721
1480
  'labels',
722
- items.map((item) => {
1481
+ // One with its `box` is already where it stays.
1482
+ items.filter((item) => !item.box).map((item) => {
723
1483
  const node = labelNodes.get(item.id);
724
- return [node, parseFloat(node.style.left), item.y, 'bottom', item.text];
1484
+ return [node, parseFloat(node.style.left), emoteAt.get(item.id) ?? item.y, 'bottom', item.text];
725
1485
  }),
726
1486
  );
727
1487
  }
@@ -769,20 +1529,40 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
769
1529
  keepClearOfHud('ribbon', [[ribbon, pos.x, pos.y, 'bottom', text]]);
770
1530
  }
771
1531
  },
772
- setToast(text) {
773
- toast.style.display = text ? 'block' : 'none';
1532
+ setToast(text, { wrap = false } = {}) {
1533
+ if (text && wrap) {
1534
+ if (!toastWrap) {
1535
+ toastWrap = { maxWidth: toast.style.maxWidth, overflowWrap: toast.style.overflowWrap, textAlign: toast.style.textAlign };
1536
+ Object.assign(toast.style, { maxWidth: 'min(90vw, 480px)', overflowWrap: 'anywhere', textAlign: 'center' });
1537
+ }
1538
+ } else if (toastWrap) {
1539
+ Object.assign(toast.style, toastWrap);
1540
+ toastWrap = null;
1541
+ }
1542
+ const display = text ? 'block' : 'none';
1543
+ if (toast.style.display !== display) {
1544
+ toast.style.display = display;
1545
+ }
774
1546
  if (text && toast.textContent !== text) {
775
1547
  toast.textContent = text;
776
1548
  }
1549
+ placeToast();
777
1550
  },
778
- showPicker(show, selected) {
1551
+ showPicker(show, selected, colors) {
1552
+ showColors(selected, colors);
779
1553
  picker.style.display = show ? 'flex' : 'none';
780
1554
  if (!show) {
781
1555
  setPickerOpen(false);
782
1556
  }
783
- pickerButtons.forEach((button, i) => {
784
- button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
785
- });
1557
+ // Asked every frame: written only when the character worn changes.
1558
+ if (selected !== pickerSelected) {
1559
+ pickerSelected = selected;
1560
+ pickerButtons.forEach((button, i) => {
1561
+ button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
1562
+ button.style.background = i === selected ? 'rgba(242,201,76,0.22)' : 'rgba(20,16,12,0.7)';
1563
+ button.setAttribute('aria-pressed', String(i === selected));
1564
+ });
1565
+ }
786
1566
  },
787
1567
  // The Graphics row: `mode` is the one picked ('auto', 'low' or 'high').
788
1568
  setGraphics(mode, onPick) {
@@ -830,6 +1610,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
830
1610
  event.stopPropagation();
831
1611
  event.preventDefault();
832
1612
  setEmotesOpen(false);
1613
+ if (onChip) {
1614
+ onChip();
1615
+ }
833
1616
  emoteHandler(id);
834
1617
  });
835
1618
  }
@@ -865,6 +1648,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
865
1648
  event.stopPropagation();
866
1649
  event.preventDefault();
867
1650
  setSayOpen(false);
1651
+ if (onChip) {
1652
+ onChip();
1653
+ }
868
1654
  sayHandler(what);
869
1655
  });
870
1656
  const row = el('div', { display: 'flex', justifyContent: 'space-between' }, sayCard);
@@ -891,6 +1677,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
891
1677
  sayNote.textContent = chat.note ?? '';
892
1678
  const line = el('div', { display: 'flex', gap: '6px', opacity: chat.input ? '1' : '0.5' }, sayCard);
893
1679
  const input = el('input', { flex: '1', minWidth: '0', padding: '7px 9px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 14px system-ui, sans-serif' }, line);
1680
+ chatField(input, 'message');
894
1681
  input.maxLength = 200;
895
1682
  input.placeholder = chat.placeholder ?? 'Message…';
896
1683
  if (chat.placeholder) {
@@ -991,52 +1778,201 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
991
1778
  grabButton.style.color = text === 'Throw' ? '#2b2118' : '#fff';
992
1779
  }
993
1780
  },
1781
+ talkRect: () => shownRect(panel),
1782
+ // Only companion places call this layout pass; keyless decks keep their CSS.
1783
+ layoutCompanion(parent) {
1784
+ const lock = parent?.querySelector?.('button[aria-label^="Shift lock"]');
1785
+ const rect = shownRect(lock);
1786
+ const lift = rect && lock.style.visibility !== 'hidden' ? rect.bottom - rect.top + 8 : 0;
1787
+ if (lift === lockLift) {return;}
1788
+ 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))`;}
1791
+ },
1792
+ setCompanionBadge(show, name, onOpen) {
1793
+ if (!show) {
1794
+ companionBadge?.remove();
1795
+ companionBadge = null;
1796
+ delete this.companionBadge;
1797
+ return;
1798
+ }
1799
+ if (!companionBadge) {
1800
+ 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);
1801
+ 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
+ companionBadge.addEventListener('pointerdown', (event) => {
1803
+ event.stopPropagation();
1804
+ companionBadge.openCompanion?.();
1805
+ });
1806
+ this.companionBadge = companionBadge;
1807
+ }
1808
+ companionBadge.openCompanion = onOpen;
1809
+ companionBadge.setAttribute('aria-label', `Chat with ${name}`);
1810
+ showCompanionBadge();
1811
+ },
1812
+ // A 44 px hit area over the private follower; created only for chat.
1813
+ setCompanionTalk(screen, name, onOpen) {
1814
+ if (!screen || talkOpen || pickerOpen || peopleOpen || doorsOpen || sayOpen || emotesOpen) {
1815
+ this.companionTalkButton?.remove();
1816
+ delete this.companionTalkButton;
1817
+ return;
1818
+ }
1819
+ if (!this.companionTalkButton) {
1820
+ const button = el('button', { position: 'absolute', width: '44px', height: '44px', transform: 'translate(-50%, -50%)', pointerEvents: 'auto', background: 'transparent', border: 'none', padding: '0', cursor: 'pointer' }, root);
1821
+ button.addEventListener('pointerdown', (event) => {
1822
+ event.stopPropagation();
1823
+ button.openCompanion?.();
1824
+ });
1825
+ this.companionTalkButton = button;
1826
+ }
1827
+ this.companionTalkButton.openCompanion = onOpen;
1828
+ this.companionTalkButton.style.left = `${screen.x}px`;
1829
+ this.companionTalkButton.style.top = `${screen.y}px`;
1830
+ this.companionTalkButton.setAttribute('aria-label', `Chat with ${name}`);
1831
+ // 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);
1833
+ 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
+ this.companionTalkButton.style.display = covers ? 'none' : 'block';
1835
+ },
994
1836
  // The Talk button, for the NPC named, or hidden.
995
- talkPrompt(name) {
1837
+ talkPrompt(name, mind = false) {
996
1838
  const show = Boolean(name) && !talkOpen;
997
1839
  talkButton.style.display = show ? 'block' : 'none';
998
- const text = show ? `Talk to ${name}` : '';
1840
+ // A mind's button names it by first name: "Chat with Biscuit", not the
1841
+ // whole "Biscuit, the puppy" in three lines on a phone.
1842
+ const text = show ? (mind ? `Chat with ${name.split(',')[0].trim() || name}` : `Talk to ${name}`) : '';
999
1843
  if (show && talkButton.textContent !== text) {
1000
1844
  talkButton.textContent = text;
1001
1845
  }
1002
1846
  },
1003
- openTalk(name) {
1847
+ openTalk(name, { mind = false, canType = true } = {}) {
1004
1848
  talkOpen = true;
1849
+ showCompanionBadge();
1850
+ panelMind = mind;
1005
1851
  panelName.textContent = name;
1852
+ dropTyping();
1006
1853
  panelLog.replaceChildren();
1854
+ panelOpening = null;
1855
+ dropAsks();
1856
+ panelInput.value = '';
1857
+ panelInput.placeholder = mind ? `Ask ${name.split(',')[0].trim()} anything…` : 'Say something…';
1858
+ panelSend.disabled = false;
1859
+ panelSend.style.opacity = '1';
1860
+ panelSend.textContent = 'Say';
1007
1861
  panel.style.display = 'flex';
1008
1862
  talkButton.style.display = 'none';
1009
- // With a keyboard, typing goes straight to the panel; a touch screen
1010
- // waits for a tap on the field rather than throwing up its keyboard.
1011
- if (globalThis.matchMedia?.('(pointer: fine)').matches) {
1012
- panelInput.focus({ preventScroll: true });
1013
- }
1863
+ panelForm.style.display = 'none';
1864
+ setTalkTyping(canType);
1014
1865
  },
1015
1866
  closeTalk() {
1016
1867
  talkOpen = false;
1868
+ showCompanionBadge();
1869
+ panelOpening = null;
1017
1870
  panel.style.display = 'none';
1018
1871
  panelInput.blur();
1872
+ dropAsks();
1873
+ dropTyping();
1874
+ },
1875
+ talkTyping: setTalkTyping,
1876
+ // A refused re-attach keeps the unsent question for the next open.
1877
+ talkDraft(text) {
1878
+ if (text !== undefined) {
1879
+ panelInput.value = text;
1880
+ }
1881
+ return panelInput.value;
1882
+ },
1883
+ // v1.47: replace the opening in place; questions and later lines stay put.
1884
+ talkOpening(text) {
1885
+ if (talkOpen && panelOpening) {
1886
+ panelOpening.textContent = text;
1887
+ }
1888
+ },
1889
+ // v1.46: a mind's chips sit below its field; an empty list removes them.
1890
+ talkAsks(asks, onAsk) {
1891
+ const list = Array.isArray(asks) ? asks.slice(0, 3) : [];
1892
+ if (!list.length) {
1893
+ dropAsks();
1894
+ return;
1895
+ }
1896
+ if (!panelAsks) {
1897
+ panelAsks = el('div', { display: 'none', flexWrap: 'wrap', gap: '6px' }, panel);
1898
+ if (!panelMind) {
1899
+ panel.insertBefore(panelAsks, panelForm);
1900
+ }
1901
+ }
1902
+ panelAsks.replaceChildren();
1903
+ asksHandler = onAsk;
1904
+ if (panelMind) {
1905
+ el('span', { fontSize: '12px', opacity: '0.7', flexBasis: '100%' }, panelAsks).textContent = 'or try:';
1906
+ }
1907
+ for (const ask of list) {
1908
+ 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
+ chip.type = 'button';
1910
+ chip.textContent = ask;
1911
+ chip.addEventListener('pointerdown', (event) => {
1912
+ event.stopPropagation();
1913
+ event.preventDefault();
1914
+ if (onChip) {
1915
+ onChip();
1916
+ }
1917
+ asksHandler?.(ask);
1918
+ });
1919
+ }
1920
+ panelAsks.style.display = 'flex';
1019
1921
  },
1020
1922
  // `note`, when given, is a small caption under the line (a scripted reply).
1021
1923
  talkLine(who, text, note = null) {
1924
+ // v1.35: where the log was before this line: at its end, or scrolled
1925
+ // up by the player to read something earlier.
1926
+ const atEnd = panelLog.scrollHeight - panelLog.scrollTop - panelLog.clientHeight <= TALK_END_PX;
1927
+ if (who === 'them') {
1928
+ dropTyping();
1929
+ }
1022
1930
  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);
1023
1931
  line.textContent = text;
1932
+ if (who === 'them' && panelLog.childElementCount === 1) {
1933
+ panelOpening = line;
1934
+ }
1024
1935
  if (note) {
1025
1936
  el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
1026
1937
  }
1027
- panelLog.scrollTop = panelLog.scrollHeight;
1938
+ if (who === 'me') {
1939
+ // The player's own words: they have just sent them, show them.
1940
+ panelLog.scrollTop = panelLog.scrollHeight;
1941
+ } else if (atEnd) {
1942
+ // A reply is read from its first word: its top at the top of what
1943
+ // shows (the end of the log when the whole reply fits, as the
1944
+ // browser stops there). A player reading further up is left there.
1945
+ panelLog.scrollTop = line.offsetTop - panelLog.offsetTop;
1946
+ }
1028
1947
  },
1029
1948
  talkWaiting(waiting) {
1030
1949
  panelSend.disabled = waiting;
1031
1950
  panelSend.style.opacity = waiting ? '0.5' : '1';
1032
1951
  panelSend.textContent = waiting ? '…' : 'Say';
1952
+ if (!waiting) {
1953
+ dropTyping();
1954
+ } else if (talkOpen && panelMind && !panelTyping) {
1955
+ const atEnd = panelLog.scrollHeight - panelLog.scrollTop - panelLog.clientHeight <= TALK_END_PX;
1956
+ 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
+ panelTyping.className = 'hub-npc-typing';
1958
+ panelTyping.setAttribute('role', 'status');
1959
+ panelTyping.setAttribute('aria-label', `${panelName.textContent} is typing`);
1960
+ for (let i = 0; i < 3; i++) {
1961
+ el('span', {}, panelTyping).textContent = '•';
1962
+ }
1963
+ if (atEnd) {
1964
+ panelLog.scrollTop = panelLog.scrollHeight;
1965
+ }
1966
+ }
1033
1967
  },
1034
1968
  talkFocused() {
1035
1969
  return document.activeElement === panelInput;
1036
1970
  },
1037
1971
  // `doors` is [{ id, title }] to offer, or null for none; `goText` is the
1038
- // word on each one's button ("Go", or "Go together" in a party).
1039
- setDoors(doors, goText = 'Go') {
1972
+ // word on each one's button ("Go", or "Go together" in a party). `stuck`
1973
+ // (v1.33, a deck with `hub.stuck`) is `{ where, onPick }`, a "Stuck?" row
1974
+ // over the doors that goes back to the place's arrival; null for none.
1975
+ setDoors(doors, goText = 'Go', stuck = null, yours = null) {
1040
1976
  const show = Array.isArray(doors) && doors.length > 0;
1041
1977
  doorsButton.style.display = show ? 'block' : 'none';
1042
1978
  if (!show) {
@@ -1044,23 +1980,53 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1044
1980
  doorsKey = '';
1045
1981
  return;
1046
1982
  }
1047
- const key = `${goText}#${doors.map((d) => `${d.id}:${d.title ?? ''}:${d.featured ? 'f' : ''}${d.solo ? 's' : ''}${d.need ?? ''}`).join('|')}`;
1983
+ const yourRows = yours?.rows?.slice(0, desktop() ? 5 : 3) ?? [];
1984
+ const yourKey = yours ? JSON.stringify([yourRows, yours.hearts ?? null]) : '';
1985
+ const key = `${yourKey}${goText}#${doors.map((d) => `${d.id}:${d.title ?? ''}:${d.featured ? 'f' : ''}${d.solo ? 's' : ''}${d.need ?? ''}`).join('|')}${stuck ? `#stuck:${stuck.where}` : ''}`;
1986
+ if (stuck) {
1987
+ stuckRowPick = stuck.onPick;
1988
+ }
1048
1989
  if (key === doorsKey) {
1049
1990
  return;
1050
1991
  }
1051
1992
  doorsKey = key;
1052
1993
  doorsList.replaceChildren();
1053
- for (const door of doors) {
1994
+ 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);
1996
+ row.dataset.hub = 'stuck-row';
1997
+ const words = el('div', { flex: '1', minWidth: '0' }, row);
1998
+ el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = 'Stuck?';
1999
+ el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = stuck.where;
2000
+ const go = smallButton(row, 'Go', false);
2001
+ go.style.flex = 'none';
2002
+ go.setAttribute('aria-label', `Stuck? ${stuck.where}`);
2003
+ go.addEventListener('pointerdown', (event) => {
2004
+ event.stopPropagation();
2005
+ closeDoors();
2006
+ stuckRowPick();
2007
+ });
2008
+ }
2009
+ if (yourRows.length) {
2010
+ el('div', { fontSize: '13px', opacity: '0.8' }, doorsList).textContent = 'Your games';
2011
+ }
2012
+ const listed = [...yourRows.map((r) => ({ ...doors.find((d) => d.id === r.door), title: r.title, line: r.line, yours: true })), ...doors];
2013
+ for (const [index, door] of listed.entries()) {
2014
+ 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';
2016
+ }
1054
2017
  const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsList);
1055
2018
  // The title on a line of its own, with one short word under it on what
1056
2019
  // the door takes (a solo game, how many it needs): beside the button
1057
2020
  // they squeezed the title to a few letters.
1058
2021
  const words = el('div', { flex: '1', minWidth: '0' }, row);
1059
2022
  const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
1060
- name.textContent = `${door.featured ? '★ ' : ''}${door.title ?? door.id}`;
1061
- const takes = door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
2023
+ name.textContent = `${door.featured && !door.yours ? '★ ' : ''}${door.title ?? door.id}`;
2024
+ const takes = door.yours ? door.line : door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
1062
2025
  if (takes) {
1063
- el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, words).textContent = takes;
2026
+ el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', ...(door.yours ? { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } : {}) }, words).textContent = takes;
2027
+ }
2028
+ if (yours?.hearts) {
2029
+ heartButton(row, door.id, yours.hearts.includes(door.id));
1064
2030
  }
1065
2031
  const go = el('button', { padding: '5px 12px', borderRadius: '12px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, row);
1066
2032
  // A party cannot go together through a door that takes one player.
@@ -1069,6 +2035,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1069
2035
  go.addEventListener('pointerdown', (event) => {
1070
2036
  event.stopPropagation();
1071
2037
  closeDoors();
2038
+ if (onChip) {
2039
+ onChip();
2040
+ }
1072
2041
  onJumpDoor(door);
1073
2042
  });
1074
2043
  }
@@ -1123,6 +2092,12 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1123
2092
  // the friend themself. Anything not listed is removed.
1124
2093
  setPointers(items) {
1125
2094
  const seen = new Set();
2095
+ // The round buttons an edge chip is kept beside, never under (v1.38: a
2096
+ // chip at the right edge had half its words under the chat button).
2097
+ // Read once a call, and only when there is an edge chip.
2098
+ const buttons = items.some((item) => item.angle !== null && item.angle !== undefined)
2099
+ ? [sayButton, emoteButton, grabButton, sound?.button].map(shownRect).filter(Boolean)
2100
+ : [];
1126
2101
  for (const item of items) {
1127
2102
  seen.add(item.id);
1128
2103
  let node = pointerNodes.get(item.id);
@@ -1144,10 +2119,30 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1144
2119
  }
1145
2120
  // Kept whole on screen; over a friend it sits above their head.
1146
2121
  const half = node.chip.offsetWidth / 2;
1147
- const x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
2122
+ let x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
2123
+ let y = item.y;
2124
+ if (edge && buttons.length) {
2125
+ // The buttons stand in a column at the edge. A chip over any of them
2126
+ // goes to the left of them all; one too wide for that goes over the
2127
+ // whole column it lies across, or under it with no room over. So no
2128
+ // move away from one button can put it on another.
2129
+ const tall = node.chip.offsetHeight / 2;
2130
+ const across = (r) => x + half > r.left - 4 && x - half < r.right + 4;
2131
+ if (buttons.some((r) => across(r) && y + tall > r.top && y - tall < r.bottom)) {
2132
+ const left = Math.min(...buttons.map((r) => r.left)) - 6 - half;
2133
+ if (left >= half + 6) {
2134
+ x = left;
2135
+ } else {
2136
+ const column = buttons.filter(across);
2137
+ const over = Math.min(...column.map((r) => r.top)) - 6 - tall;
2138
+ y = over >= tall + 6 ? over : Math.max(...column.map((r) => r.bottom)) + 6 + tall;
2139
+ }
2140
+ }
2141
+ }
1148
2142
  node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
1149
2143
  node.chip.style.left = `${x}px`;
1150
- node.chip.style.top = `${item.y}px`;
2144
+ node.chip.style.top = `${y}px`;
2145
+ node.y = y;
1151
2146
  }
1152
2147
  for (const [id, node] of pointerNodes) {
1153
2148
  if (!seen.has(id)) {
@@ -1161,7 +2156,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1161
2156
  items.map((item) => {
1162
2157
  const chip = pointerNodes.get(item.id).chip;
1163
2158
  const edge = item.angle !== null && item.angle !== undefined;
1164
- return [chip, parseFloat(chip.style.left), item.y, edge ? 'center' : 'bottom', `${edge ? '>' : ''}${item.text}`];
2159
+ return [chip, parseFloat(chip.style.left), pointerNodes.get(item.id).y, edge ? 'center' : 'bottom', `${edge ? '>' : ''}${item.text}`];
1165
2160
  }),
1166
2161
  );
1167
2162
  }
@@ -1176,7 +2171,21 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1176
2171
  }
1177
2172
  askKey = ask.key;
1178
2173
  askCard.replaceChildren();
1179
- el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
2174
+ if (ask.kind === 'yours') {
2175
+ askCard.style.width = 'min(94vw, 420px)';
2176
+ } else if (askCard.style.width !== 'min(86vw, 320px)') {
2177
+ askCard.style.width = 'min(86vw, 320px)';
2178
+ }
2179
+ if (ask.kind === 'yours') {
2180
+ const words = el('div', { flex: '1', minWidth: '0', fontWeight: '600', overflow: 'hidden' }, askCard);
2181
+ el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.text;
2182
+ el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words).textContent = ask.line;
2183
+ if (typeof ask.heart === 'boolean') {
2184
+ heartButton(askCard, ask.door, ask.heart);
2185
+ }
2186
+ } else {
2187
+ el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
2188
+ }
1180
2189
  for (const [text, answer] of [[ask.yes, true], [ask.no, false]]) {
1181
2190
  smallButton(askCard, text, answer).addEventListener('pointerdown', (event) => {
1182
2191
  event.stopPropagation();
@@ -1198,6 +2207,83 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1198
2207
  }
1199
2208
  }
1200
2209
  },
2210
+ // The "Stuck?" chip (v1.33): its words, or null to hide it; a press calls
2211
+ // `handler`. Never over an open card or list, like the invite button, and
2212
+ // never over the HUD, a question, another control, a cabinet's card or
2213
+ // the ribbon (`placeStuckChip`). Said last in a frame: after the other
2214
+ // setters and after `flushHudClear`, whose final boxes it is placed by.
2215
+ stuckPrompt(text, handler) {
2216
+ if (!text && !stuckChip) {
2217
+ return;
2218
+ }
2219
+ stuckChip ??= buildStuckChip();
2220
+ if (text) {
2221
+ stuckHandler = handler;
2222
+ if (stuckChip.textContent !== text) {
2223
+ stuckChip.textContent = text;
2224
+ }
2225
+ }
2226
+ const show = Boolean(text) && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen && !talkOpen;
2227
+ if (show && stuckChip.style.display !== 'block') {
2228
+ // Laid out before it is measured; nothing is painted in between.
2229
+ stuckChip.style.display = 'block';
2230
+ }
2231
+ // The toast leaves the chip's spot clear before the chip looks for the
2232
+ // toast, by where it hangs and not by whether it is drawn.
2233
+ const was = stuckSpot;
2234
+ if (show) {
2235
+ const w = stuckChip.offsetWidth;
2236
+ const x = stuckChip.offsetLeft;
2237
+ const y = stuckChip.offsetTop;
2238
+ const h = stuckChip.offsetHeight;
2239
+ 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
+ } else {
2241
+ stuckSpot = null;
2242
+ }
2243
+ if (stuckSpot !== was) {
2244
+ placeToast();
2245
+ }
2246
+ if (!show || !placeStuckChip()) {
2247
+ stuckChip.style.display = 'none';
2248
+ }
2249
+ },
2250
+ // The sound control (a deck with `hub.soundscape`): `show` whether the
2251
+ // button is up, `state` `{ volume, muted }` (0 to 1), `handlers`
2252
+ // `{ onVolume(0..1), onMuted(bool) }`. Never called in a deck without the
2253
+ // key, and nothing of it exists until it is.
2254
+ soundControl(show, state, handlers) {
2255
+ if (!show && !sound) {
2256
+ return;
2257
+ }
2258
+ sound ??= buildSound();
2259
+ sound.handlers = handlers ?? sound.handlers;
2260
+ const percent = Math.round((state?.volume ?? 0) * 100);
2261
+ const muted = state?.muted === true;
2262
+ const key = `${show ? 1 : 0}|${muted ? 1 : 0}|${percent}|${stats.textContent ? 1 : 0}`;
2263
+ if (key === sound.key) {
2264
+ return;
2265
+ }
2266
+ sound.key = key;
2267
+ sound.muted = muted;
2268
+ if (!show) {
2269
+ sound.open = false;
2270
+ sound.card.style.display = 'none';
2271
+ }
2272
+ sound.button.style.display = show ? 'block' : 'none';
2273
+ // 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))';
2275
+ sound.button.style.top = top;
2276
+ sound.card.style.top = `calc(${top} + 46px)`;
2277
+ const quiet = muted || percent === 0;
2278
+ sound.button.textContent = quiet ? '🔇' : '🔊';
2279
+ sound.button.setAttribute('aria-label', quiet ? 'Sound: off' : `Sound: ${percent}%`);
2280
+ sound.mute.textContent = muted ? 'Unmute' : 'Mute';
2281
+ sound.slider.style.opacity = muted ? '0.5' : '1';
2282
+ // Not while the player drags it: the value is theirs then.
2283
+ if (document.activeElement !== sound.slider && sound.slider.value !== String(percent)) {
2284
+ sound.slider.value = String(percent);
2285
+ }
2286
+ },
1201
2287
  // Whether the People list is open (its rows' places are asked for then).
1202
2288
  peopleOpen: () => peopleOpen,
1203
2289
  setStats(text) {
@@ -1207,11 +2293,19 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
1207
2293
  }
1208
2294
  },
1209
2295
  dispose() {
2296
+ if (placeMenu) {clearMenu();}
2297
+ if (textAsk) {
2298
+ clearTextAsk();
2299
+ }
2300
+ if (actionChips) {
2301
+ clearActions();
2302
+ }
1210
2303
  if (hudClearDrawn) {
1211
2304
  restoreHudClear();
1212
2305
  }
1213
2306
  unguardKeys();
1214
2307
  desktopQuery?.removeEventListener?.('change', layoutPanel);
2308
+ labelMeasure?.remove();
1215
2309
  root.remove();
1216
2310
  },
1217
2311
  };