castle-web-cli 0.4.239 → 0.4.241

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 (396) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -7,10 +7,20 @@
7
7
  // A device is 'high' (the picture as authored) or 'low'. The low picture was
8
8
  // chosen on real phones (a Galaxy Tab A7 Lite and a Redmi 9A, CPU-bound at 12
9
9
  // fps in the town): no sun shadow, decorative actors not drawn, other scenery
10
- // not drawn past 30 m and NPC bodies past 20 m. The render resolution is left
11
- // alone: a render scale of 1 on a 2x screen bought 2-9% on those phones and
12
- // made Low visibly jagged, while shadows off alone took a TECNO from 32-35 to
13
- // 48.5 fps.
10
+ // not drawn past 30 m and NPC bodies past 20 m. Low does not simply lower the
11
+ // render resolution: a render scale of 1 on a 2x screen bought 2-9% on those
12
+ // phones and made Low visibly jagged, while shadows off alone took a TECNO
13
+ // from 32-35 to 48.5 fps. A fill-bound device is the other way round: an iPad
14
+ // 7th gen (A10) ran the town at 14 fps at pixel ratio 2 and 23 at 1, and
15
+ // shadows made no difference. So auto Low measures it (`scaleStep` in
16
+ // `makeTiers`): when a Low window is still slow, the renderer and composer
17
+ // drop to half their pixel ratio (never under 1) for one window, and the
18
+ // lower ratio stays only if that window's median is at least 20% faster;
19
+ // otherwise both are put back and the visit never tries again. The outcome is
20
+ // remembered beside the low mark, so the next visit within the week starts
21
+ // at the lower ratio, or never tries. A Low or High picked by hand, and a
22
+ // deck with the weakest tier (which has its own resolution rule), never get
23
+ // this step.
14
24
  // "Not drawn" takes the actor's three.js node out of the scene graph, which
15
25
  // saves the traversal and matrix work as well as the draw. Nothing here
16
26
  // touches colliders, physics, the network, labels or anything another player
@@ -32,19 +42,21 @@
32
42
  // existing underground visibility path alone.
33
43
  //
34
44
  // Where a device starts: low if it was found slow here in the last week
35
- // (remembered in localStorage), or its GPU or memory says it is a weak phone;
36
- // otherwise high, and the frame times decide (`makeJudge`). A player may pick
37
- // Low or High by hand (the Graphics row in the Character card), which wins
38
- // over all of it.
45
+ // (remembered on the device: `deviceStorage.js`), or its GPU or memory says
46
+ // it is a weak phone; otherwise high, and the frame times decide
47
+ // (`makeJudge`). A player may pick Low or High by hand (the Graphics row in
48
+ // the Character card), which wins over all of it.
39
49
 
40
50
  import { Box3, Sphere } from 'three';
41
51
  import { classify } from '../shared/quality.js';
42
52
  import { hub, deck } from './state.js';
53
+ import { deviceStorage, primeDeviceStorage } from './deviceStorage.js';
43
54
 
44
55
  export const TIERS = ['low', 'high'];
45
56
  export const MODES = ['auto', 'low', 'high'];
46
- // localStorage: the tier found here (`{ tier: 'low', at }`), and the mode the
47
- // player picked.
57
+ // Kept on the device (`deviceStorage.js`): the tier found here (`{ tier:
58
+ // 'low', at }`, with `scale: 'kept' | 'refused'` once Low's resolution step
59
+ // has been measured), and the mode the player picked.
48
60
  export const TIER_KEY = 'castle.hub.tier';
49
61
  export const MODE_KEY = 'castle.hub.graphics';
50
62
  // A device found slow stays low this long, then is tried from high again.
@@ -64,6 +76,11 @@ export const GAP_MS = 1000;
64
76
  export const SCENERY_NEAR_M = 30;
65
77
  export const NPC_NEAR_M = 20;
66
78
  export const CHECK_EVERY_MS = 500;
79
+ // Low's resolution step: the pixel ratio is multiplied by this (never under
80
+ // 1), and kept only when the trial window's median is at most KEEP_SCALE of
81
+ // the slow window before it.
82
+ export const SCALE_STEP = 0.5;
83
+ export const KEEP_SCALE = 0.8;
67
84
 
68
85
  // GPUs of the phones the low picture is for, by the WebGL renderer string
69
86
  // (`WEBGL_debug_renderer_info`): PowerVR Rogue GE8xxx, Mali-G52 MC1/MC2,
@@ -158,16 +175,14 @@ export function median(values) {
158
175
  // is judged, so the odd long frame (a mesh built, a collection) does not
159
176
  // decide. Returns 'low' once, when a window is slow; the judge then stops: a
160
177
  // visit never moves back up.
161
- export function makeJudge() {
162
- const judge = { done: false, first: true, start: null, frames: [] };
178
+ export function makeJudge({ first = true } = {}) {
179
+ const judge = { done: false, first, start: null, frames: [] };
163
180
  judge.reset = () => {
164
181
  judge.start = null;
165
182
  judge.frames = [];
166
183
  };
167
- judge.feed = (dt, now, counts) => {
168
- if (judge.done) {
169
- return null;
170
- }
184
+ // The window under the judge's rules: its median when one closes, else null.
185
+ judge.window = (dt, now, counts) => {
171
186
  if (!counts || !(dt >= 0) || dt > GAP_MS) {
172
187
  judge.reset();
173
188
  return null;
@@ -181,10 +196,17 @@ export function makeJudge() {
181
196
  if (now - judge.start < (judge.first ? FIRST_WINDOW_MS : WINDOW_MS)) {
182
197
  return null;
183
198
  }
184
- const slow = median(judge.frames) > SLOW_FRAME_MS;
199
+ const m = median(judge.frames);
185
200
  judge.first = false;
186
201
  judge.reset();
187
- if (slow) {
202
+ return m;
203
+ };
204
+ judge.feed = (dt, now, counts) => {
205
+ if (judge.done) {
206
+ return null;
207
+ }
208
+ const m = judge.window(dt, now, counts);
209
+ if (m !== null && m > SLOW_FRAME_MS) {
188
210
  judge.done = true;
189
211
  return 'low';
190
212
  }
@@ -885,17 +907,182 @@ export function gpuOf(renderer) {
885
907
  }
886
908
  }
887
909
 
888
- function pageStorage() {
889
- try {
890
- return globalThis.localStorage ?? null;
891
- } catch {
892
- return null;
893
- }
910
+ // The keys tiers keep, fetched before the first scene load where the device's
911
+ // storage has to fetch them (`qualityEntry.js`), and adopted by `makeTiers`
912
+ // whenever they arrive otherwise.
913
+ export const TIER_KEYS = [TIER_KEY, MODE_KEY];
914
+ export function primeTiers(options) {
915
+ return primeDeviceStorage(TIER_KEYS, options);
916
+ }
917
+
918
+ // The low mark stored here, if it is still within the week.
919
+ function rememberedLow(storage, now) {
920
+ const seen = readJson(storage, TIER_KEY);
921
+ return seen?.tier === 'low' && typeof seen.at === 'number' && now - seen.at >= 0 && now - seen.at < REMEMBER_MS ? seen : null;
922
+ }
923
+
924
+ // Auto Low's resolution step (see the top of this file). `frame(world, dt,
925
+ // now, counts, on)` each frame: `on` is whether the step may run (auto, Low,
926
+ // not a weakest-tier deck). States: 'none' (not run yet), 'baseline' (Low
927
+ // windows measured until one is slow), 'trial' (one window at the lower
928
+ // ratio), 'kept', 'refused' (put back; never tried again this visit), and
929
+ // 'settled' (nothing to step: already at 1, or a renderer or composer it
930
+ // cannot read). Off, or on another renderer, it puts back exactly what it
931
+ // set, and only where the renderer and composer still hold its value.
932
+ function makeScaleStep({ storage, clock }) {
933
+ const step = { state: 'none', baseline: null, trial: null, held: null, place: null, judge: makeJudge({ first: false }) };
934
+
935
+ const usable = (world) => {
936
+ const renderer = world?.renderer;
937
+ const composer = world?.composer;
938
+ try {
939
+ if (
940
+ typeof renderer?.getPixelRatio !== 'function' ||
941
+ typeof renderer.setPixelRatio !== 'function' ||
942
+ typeof composer?.setPixelRatio !== 'function' ||
943
+ !Number.isFinite(composer._pixelRatio)
944
+ ) {
945
+ return null;
946
+ }
947
+ const ratio = renderer.getPixelRatio();
948
+ return Number.isFinite(ratio) && ratio > 0 ? { renderer, composer, ratio } : null;
949
+ } catch {
950
+ return null;
951
+ }
952
+ };
953
+
954
+ // Halves the world's ratio; false when there is nothing to step.
955
+ const lower = (world) => {
956
+ const found = usable(world);
957
+ if (!found || found.ratio <= 1) {
958
+ return false;
959
+ }
960
+ const { renderer, composer, ratio } = found;
961
+ const cheap = Math.max(1, ratio * SCALE_STEP);
962
+ step.held = { renderer, composer, ratio, composerRatio: composer._pixelRatio, cheap };
963
+ try {
964
+ renderer.setPixelRatio(cheap);
965
+ composer.setPixelRatio(cheap);
966
+ } catch {
967
+ // A half-applied change is still put back by `restore`.
968
+ }
969
+ return true;
970
+ };
971
+
972
+ step.restore = () => {
973
+ const held = step.held;
974
+ step.held = null;
975
+ if (!held) {
976
+ return;
977
+ }
978
+ try {
979
+ if (held.renderer.getPixelRatio() === held.cheap) {
980
+ held.renderer.setPixelRatio(held.ratio);
981
+ }
982
+ if (held.composer._pixelRatio === held.cheap) {
983
+ held.composer.setPixelRatio(held.composerRatio);
984
+ }
985
+ } catch {
986
+ // Nothing more can be done for a renderer that throws.
987
+ }
988
+ };
989
+
990
+ const remember = (scale) => {
991
+ const seen = rememberedLow(storage, clock());
992
+ writeJson(storage, TIER_KEY, { tier: 'low', at: seen ? seen.at : clock(), scale });
993
+ };
994
+
995
+ // A trial compares two windows of the same place on the same world; when
996
+ // either changes, or a frame stops counting (a trip, a scene swap, the page
997
+ // hidden), the trial is dropped and the step measures a baseline again.
998
+ const dropTrial = () => {
999
+ if (step.state === 'trial') {
1000
+ step.restore();
1001
+ step.state = 'baseline';
1002
+ step.baseline = null;
1003
+ }
1004
+ };
1005
+
1006
+ step.frame = (world, dt, now, counts, on, place = null) => {
1007
+ if (step.held && (step.held.renderer !== world.renderer || step.held.composer !== world.composer)) {
1008
+ // Another world: what was set belongs to the old one, and frames
1009
+ // measured there say nothing about this one.
1010
+ step.restore();
1011
+ step.judge.reset();
1012
+ dropTrial();
1013
+ }
1014
+ if (place !== step.place) {
1015
+ step.place = place;
1016
+ step.judge.reset();
1017
+ dropTrial();
1018
+ }
1019
+ if (!on) {
1020
+ step.restore();
1021
+ step.judge.reset();
1022
+ dropTrial();
1023
+ return;
1024
+ }
1025
+ if (!counts) {
1026
+ dropTrial();
1027
+ }
1028
+ if (step.state === 'none') {
1029
+ const scale = rememberedLow(storage, clock())?.scale;
1030
+ step.state = scale === 'kept' ? 'kept' : scale === 'refused' ? 'refused' : 'baseline';
1031
+ }
1032
+ if (step.state === 'kept') {
1033
+ if (!step.held && !lower(world)) {
1034
+ step.state = 'settled';
1035
+ }
1036
+ return;
1037
+ }
1038
+ if (step.state !== 'baseline' && step.state !== 'trial') {
1039
+ return;
1040
+ }
1041
+ const m = step.judge.window(dt, now, counts);
1042
+ if (m === null) {
1043
+ return;
1044
+ }
1045
+ if (step.state === 'baseline') {
1046
+ if (m <= SLOW_FRAME_MS) {
1047
+ return;
1048
+ }
1049
+ if (!lower(world)) {
1050
+ step.state = 'settled';
1051
+ return;
1052
+ }
1053
+ step.baseline = m;
1054
+ step.state = 'trial';
1055
+ // The frame after a resize is a stall; the trial window starts after it.
1056
+ step.judge.reset();
1057
+ return;
1058
+ }
1059
+ step.trial = m;
1060
+ if (m <= KEEP_SCALE * step.baseline) {
1061
+ step.state = 'kept';
1062
+ remember('kept');
1063
+ } else {
1064
+ step.restore();
1065
+ step.state = 'refused';
1066
+ remember('refused');
1067
+ }
1068
+ };
1069
+
1070
+ // The low mark came from the device's storage after the step was started
1071
+ // without it: a step still only measuring its baseline reads it again on
1072
+ // its next frame. A trial under way is left to finish and write its own.
1073
+ step.adopt = () => {
1074
+ if (step.state === 'baseline') {
1075
+ step.state = 'none';
1076
+ }
1077
+ };
1078
+
1079
+ step.view = () => ({ state: step.state, ratio: step.held?.cheap ?? null, baseline: step.baseline, trial: step.trial });
1080
+ return step;
894
1081
  }
895
1082
 
896
1083
  // The hub system's tiers: `frame(scene, counts, now)` each frame. `counts` is
897
1084
  // whether this frame says how the device draws the place (see `makeJudge`).
898
- export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), deviceMemory = globalThis.navigator?.deviceMemory ?? null, lowMemory = false, onLayout, levers = makeLevers({ onLayout }), weakest = false } = {}) {
1085
+ export function makeTiers({ storage = deviceStorage(), clock = () => Date.now(), deviceMemory = globalThis.navigator?.deviceMemory ?? null, lowMemory = false, onLayout, levers = makeLevers({ onLayout }), weakest = false } = {}) {
899
1086
  const t = {
900
1087
  mode: readMode(storage, weakest),
901
1088
  auto: null,
@@ -904,6 +1091,7 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
904
1091
  last: null,
905
1092
  weakestDevice: false,
906
1093
  middleDevice: false,
1094
+ scale: makeScaleStep({ storage, clock }),
907
1095
  };
908
1096
 
909
1097
  t.current = () => (t.mode === 'weakest' ? 'low' : t.mode === 'auto' ? (t.auto?.tier ?? 'high') : t.mode);
@@ -922,6 +1110,37 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
922
1110
  return true;
923
1111
  };
924
1112
 
1113
+ // A storage that fetches its values (`deviceStorage.js` in a frame without
1114
+ // localStorage) may hand them over after this was made and picked: the
1115
+ // player's mode is taken as stored, and a low mark from the last week moves
1116
+ // a device still on High by its hints to Low, as `initialTier` would have.
1117
+ // A pick or a slow window here since then wrote its own value, which the
1118
+ // storage keeps over the fetched one, so neither is undone. The chrome's
1119
+ // Graphics row follows `mode` (hub.js `deviceTier`).
1120
+ t.adopt = (adopted) => {
1121
+ const before = t.current();
1122
+ if (adopted.has(MODE_KEY)) {
1123
+ const mode = readMode(storage, weakest);
1124
+ if (mode !== t.mode) {
1125
+ t.mode = mode;
1126
+ t.judge.reset();
1127
+ }
1128
+ }
1129
+ if (adopted.has(TIER_KEY)) {
1130
+ if (t.auto?.tier === 'high' && rememberedLow(storage, clock())) {
1131
+ t.auto = { tier: 'low', reason: 'remembered' };
1132
+ t.judge.reset();
1133
+ }
1134
+ t.scale.adopt();
1135
+ }
1136
+ // Low only now, after a scene may have loaded as High: the quality visit
1137
+ // takes out what that load would have skipped (quality.js `lowerLate`).
1138
+ if (before !== 'low' && t.current() === 'low') {
1139
+ t.lateLow = true;
1140
+ }
1141
+ };
1142
+ storage?.prime?.(TIER_KEYS).then(t.adopt, () => {});
1143
+
925
1144
  // Also used before load by the quality entry; frame timing still starts on frame one.
926
1145
  t.pick = (renderer) => {
927
1146
  // Hints are read once, from the renderer the place is drawn with.
@@ -943,8 +1162,8 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
943
1162
  t.pick(world.renderer);
944
1163
  const dt = t.last === null ? 0 : now - t.last;
945
1164
  t.last = now;
1165
+ const hidden = globalThis.document?.hidden === true;
946
1166
  if (t.mode === 'auto' && t.auto.tier === 'high') {
947
- const hidden = globalThis.document?.hidden === true;
948
1167
  if (t.judge.feed(dt, now, counts && !hidden) === 'low') {
949
1168
  t.auto = { tier: 'low', reason: 'slow' };
950
1169
  writeJson(storage, TIER_KEY, { tier: 'low', at: clock() });
@@ -954,6 +1173,7 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
954
1173
  // for a later window.
955
1174
  t.judge.reset();
956
1175
  }
1176
+ t.scale.frame(world, dt, now, counts && !hidden, !weakest && t.mode === 'auto' && t.current() === 'low', scene.data ?? null);
957
1177
  if (t.current() === 'low') {
958
1178
  levers.apply(world, scene, now, { actors: !scene.content });
959
1179
  } else {
@@ -989,10 +1209,15 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
989
1209
  get cellHidden() {
990
1210
  return levers.cellHidden ?? 0;
991
1211
  },
1212
+ // Auto Low's resolution step: where it is, the ratio it set (null when
1213
+ // none), and the baseline and trial window medians in ms.
1214
+ get scale() {
1215
+ return t.scale.view();
1216
+ },
992
1217
  cells: (on) => levers.setCells?.(on),
993
1218
  set: (mode) => t.set(mode),
994
1219
  };
995
- // Local diagnostics only until the analytics transport preserves quality.
1220
+ // Configured mode for local diagnostics; FPS telemetry includes it only on Low.
996
1221
  if (deck.quality) {Object.defineProperty(t.handle, 'quality', { enumerable: true, get: () => deck.quality?.low.decor });}
997
1222
  if (weakest) { Object.defineProperty(t.handle, 'profile', { enumerable: true, get: () => t.weakest() ? 'weakest' : t.middle() ? 'middle' : t.current() }); }
998
1223
  return t;
@@ -309,8 +309,11 @@ export function makeTogether() {
309
309
  }
310
310
  // Anyone standing on or by a door can be gone to the way Doors > Go
311
311
  // goes: to that door's pad, which is no more than the Doors list offers.
312
+ // Not a door that takes one player (`solo`): its pad sends each who
313
+ // stands there into a game of their own (the Town's House, their own
314
+ // House), never to the one they went to; Find still points the way.
312
315
  const spot = town ? hub.whereAt[playerId] : null;
313
- if (!t?.party && !t?.friend && spot?.door && hub.doors.some((d) => d.id === spot.door)) {
316
+ if (!t?.party && !t?.friend && spot?.door && hub.doors.some((d) => d.id === spot.door && d.solo !== true)) {
314
317
  actions.push({ id: 'door', text: 'Go there' });
315
318
  }
316
319
  if (town && !t?.party) {
@@ -18,7 +18,7 @@
18
18
  // that child to someone else). Children of the root are appended when made
19
19
  // and never moved after, so the host may place them in its own stacking
20
20
  // order.
21
- import { BARE_TEXT_SHADOW, FONTS, SHADOWS, TEXT_SHADOWS, color, keyOf, readClock, segment } from './uiTree.js';
21
+ import { BARE_TEXT_SHADOW, FONTS, SHADOWS, TEXT_SHADOWS, color, keyOf, readClock, segment, sliderValue } from './uiTree.js';
22
22
 
23
23
  const MAX_SCROLL = Number.MAX_SAFE_INTEGER;
24
24
  const EDGE_KEYS = new Set(['top', 'right', 'bottom', 'left', 'transform']);
@@ -74,6 +74,17 @@ export function lenCss(value) {
74
74
  return termCss(value);
75
75
  }
76
76
  const boxCss = (value) => (Array.isArray(value) ? value.map((n) => (typeof n === 'number' ? px(n) : n)).join(' ') : typeof value === 'number' ? px(value) : value);
77
+ // s.pad: the box sides, CSS order. v1.167: a side may be an edge value
78
+ // [min, add] = max(min, safe-area inset + add) on that side; a pad with one is
79
+ // written as four sides.
80
+ const PAD_SIDES = ['t', 'r', 'b', 'l'];
81
+ const fourSides = (list) => [list[0], list[1] ?? list[0], list[2] ?? list[0], list[3] ?? list[1] ?? list[0]];
82
+ function padCss(value) {
83
+ if (!Array.isArray(value) || !value.some(Array.isArray)) {return boxCss(value);}
84
+ return fourSides(value).map((side, i) => edgeCss(side, PAD_SIDES[i])).join(' ');
85
+ }
86
+ // A pad side's least length in px (an edge value's min).
87
+ const sideMin = (side) => (Array.isArray(side) ? Number(side[0]) || 0 : Number(side) || 0);
77
88
  const ALIGN = { start: 'flex-start', end: 'flex-end', center: 'center', stretch: 'stretch', baseline: 'baseline' };
78
89
  const JUSTIFY = { start: 'flex-start', end: 'flex-end', center: 'center', between: 'space-between' };
79
90
  const TALIGN = { start: 'left', center: 'center', end: 'right' };
@@ -85,7 +96,7 @@ function colsCss(cols) {
85
96
  return '';
86
97
  }
87
98
  const isSpanParent = (type) => type === 'row' || type === 'grid';
88
- const tagFor = (node, parentType) => (node.t === 'button' ? 'button' : node.t === 'field' ? 'input' : node.t === 'image' ? 'img'
99
+ const tagFor = (node, parentType) => (node.t === 'button' ? 'button' : node.t === 'field' || node.t === 'slider' ? 'input' : node.t === 'image' ? 'img'
89
100
  : node.t === 'text' && isSpanParent(parentType) && !node.at ? 'span' : 'div');
90
101
  // A first child that is only words is drawn as its parent's own text, the way
91
102
  // the chrome wrote `node.textContent` (a button's label, a talk line).
@@ -100,6 +111,8 @@ export function cssFor(node, parentType, inherited = {}) {
100
111
  const css = {};
101
112
  if (t === 'button' || t === 'field') {css.font = 'inherit';}
102
113
  if (t === 'button') {Object.assign(css, { color: 'inherit', cursor: 'pointer', border: 'none', background: 'transparent', padding: '0' });}
114
+ // The sound card's range input, as chrome.js wrote it.
115
+ if (t === 'slider') {Object.assign(css, { margin: '0', accentColor: color(node.tint ?? 'gold'), cursor: node.disabled ? 'default' : 'pointer' });}
103
116
  if (node.at) {
104
117
  const at = node.at;
105
118
  css.position = 'absolute';
@@ -137,7 +150,7 @@ export function cssFor(node, parentType, inherited = {}) {
137
150
  else {css.alignSelf = ALIGN[s.self];}
138
151
  }
139
152
  if (s.mt && !css.margin) {css.marginTop = px(s.mt);}
140
- if (s.pad !== undefined) {css.padding = boxCss(s.pad);}
153
+ if (s.pad !== undefined) {css.padding = padCss(s.pad);}
141
154
  if (s.gap !== undefined) {css.gap = px(s.gap);}
142
155
  if (s.flex !== undefined) {css.flex = String(s.flex);}
143
156
  if (s.basis === '100%') {Object.assign(css, { flexBasis: '100%', gridColumn: '1 / -1' });}
@@ -149,11 +162,12 @@ export function cssFor(node, parentType, inherited = {}) {
149
162
  if (s.radius !== undefined) {css.borderRadius = boxCss(s.radius);}
150
163
  if (s.border !== undefined) {css.border = s.border === 'none' || !s.border ? 'none' : `${s.border.w}px ${s.border.dash ? 'dashed' : 'solid'} ${color(s.border.c)}`;}
151
164
  if (s.shadow) {css.boxShadow = SHADOWS[s.shadow] ?? s.shadow;}
165
+ if (Number.isFinite(s.aspect) && s.aspect > 0) {css.aspectRatio = String(s.aspect);}
152
166
  if (s.opacity !== undefined) {css.opacity = String(s.opacity);}
153
167
  if (s.gray) {css.filter = 'grayscale(1)';}
154
168
  if (s.clip !== undefined) {css.overflow = s.clip ? 'hidden' : 'visible';}
155
169
  if (s.hidden) {css.visibility = 'hidden';}
156
- const hit = s.hit ?? (t === 'button' || t === 'field' ? 'auto' : undefined);
170
+ const hit = s.hit ?? (t === 'button' || t === 'field' || t === 'slider' ? 'auto' : undefined);
157
171
  if (hit) {css.pointerEvents = hit;}
158
172
  if (t === 'button' && (node.on?.press || node.on?.release)) {Object.assign(css, { touchAction: 'none', userSelect: 'none' });}
159
173
  // Text.
@@ -178,7 +192,7 @@ export function cssFor(node, parentType, inherited = {}) {
178
192
  // n lines of this size and line height, plus the padding: hard clipped.
179
193
  const size = s.size ?? inherited.size ?? 15;
180
194
  const lh = Number(s.lh ?? inherited.lh ?? 1.3) || 1.3;
181
- const pad = Array.isArray(s.pad) ? (s.pad.length === 4 ? s.pad[0] + s.pad[2] : 2 * s.pad[0]) : 2 * (s.pad ?? 0);
195
+ const pad = Array.isArray(s.pad) ? (s.pad.length === 4 ? sideMin(s.pad[0]) + sideMin(s.pad[2]) : 2 * sideMin(s.pad[0])) : 2 * (s.pad ?? 0);
182
196
  Object.assign(css, { maxHeight: px(Number((s.lines * size * lh + pad).toFixed(2))), overflow: 'hidden' });
183
197
  } else if (s.lines > 1) {
184
198
  Object.assign(css, { display: '-webkit-box', webkitLineClamp: String(s.lines), webkitBoxOrient: 'vertical', overflow: 'hidden' });
@@ -200,7 +214,9 @@ const defaultMeasure = {
200
214
  // layout cache, so a rule reads the frame's snapshot like the rest of it).
201
215
  // clockNow: the simulation time, in seconds, every `clock` is read at (its
202
216
  // `t0` is in the same time); a clock's words move on each `tick()`.
203
- export function mountUiTree(container, { slots = {}, created = () => {}, removed = () => {}, measure = defaultMeasure, clockNow = () => 0 } = {}) {
217
+ // passKey(element, event): true lets a key event on a field go on to the page
218
+ // (the game) instead of stopping at the field; the host decides which.
219
+ export function mountUiTree(container, { slots = {}, created = () => {}, removed = () => {}, measure = defaultMeasure, clockNow = () => 0, passKey = () => false } = {}) {
204
220
  const byPath = new Map();
205
221
  // The records drawing a clock, ticked by `tick()`.
206
222
  const clocks = new Set();
@@ -220,6 +236,8 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
220
236
  function drop(rec, path) {
221
237
  for (const [key, kid] of rec.kids) {drop(kid, `${path}/${segment(key)}`);}
222
238
  rec.kids.clear();
239
+ // A slider dropped mid-hold is never let go: its page listeners go too.
240
+ rec.unhold?.();
223
241
  rec.el.remove();
224
242
  clocks.delete(rec);
225
243
  byPath.delete(path);
@@ -274,7 +292,9 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
274
292
  }
275
293
  if (t === 'field') {
276
294
  for (const type of ['keydown', 'keyup', 'keypress']) {
277
- listen(rec, type, (event) => event.stopPropagation?.());
295
+ listen(rec, type, (event) => {
296
+ if (!passKey(rec.el, event)) {event.stopPropagation?.();}
297
+ });
278
298
  }
279
299
  if (rec.listening.has('input')) {return;}
280
300
  rec.el.addEventListener('keydown', (event) => {
@@ -295,6 +315,49 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
295
315
  listen(rec, 'blur', () => fire(rec, 'blur', {}));
296
316
  return;
297
317
  }
318
+ if (t === 'slider') {
319
+ // Let go: once per hold, whether or not the value moved (a press that
320
+ // does not move it fires no `change`). The arrow keys are the
321
+ // avatar's again after.
322
+ const letGo = (byPointer) => {
323
+ rec.holding = false;
324
+ rec.pointerLetGo = byPointer;
325
+ fire(rec, 'release', { value: Number(rec.el.value) });
326
+ rec.el.blur?.();
327
+ };
328
+ // The scene under it never sees the drag. The hold ends wherever the
329
+ // pointer is let go, on the slider or off it.
330
+ listen(rec, 'pointerdown', (event) => {
331
+ event.stopPropagation?.();
332
+ if (rec.holding) {return;}
333
+ rec.holding = true;
334
+ rec.pointerLetGo = false;
335
+ const unhold = () => {
336
+ globalThis.removeEventListener?.('pointerup', end, true);
337
+ globalThis.removeEventListener?.('pointercancel', end, true);
338
+ rec.unhold = null;
339
+ rec.holding = false;
340
+ };
341
+ const end = () => {
342
+ const held = rec.holding;
343
+ unhold();
344
+ if (held) {letGo(true);}
345
+ };
346
+ rec.unhold = unhold;
347
+ globalThis.addEventListener?.('pointerup', end, true);
348
+ globalThis.addEventListener?.('pointercancel', end, true);
349
+ });
350
+ listen(rec, 'input', () => fire(rec, 'input', { value: Number(rec.el.value) }));
351
+ // A keyboard change is let go at once; a pointer's change (fired
352
+ // before or after its pointerup) is that pointerup's release.
353
+ listen(rec, 'keydown', () => {rec.pointerLetGo = false;});
354
+ listen(rec, 'change', () => {
355
+ if (rec.holding) {return;}
356
+ if (rec.pointerLetGo) {rec.pointerLetGo = false; return;}
357
+ letGo(false);
358
+ });
359
+ return;
360
+ }
298
361
  if (node.s?.hit === 'auto') {
299
362
  listen(rec, 'pointerdown', (event) => event.stopPropagation?.());
300
363
  }
@@ -392,6 +455,18 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
392
455
  rec.focus = focus;
393
456
  }
394
457
 
458
+ function patchSlider(rec, node, fresh) {
459
+ const el = rec.el;
460
+ if (fresh) {el.type = 'range';}
461
+ const { min, max, step, value } = sliderValue(node);
462
+ const props = { min: String(min), max: String(max), step: step > 0 ? String(step) : 'any', disabled: Boolean(node.disabled) };
463
+ for (const [name, prop] of Object.entries(props)) {
464
+ if (rec.props[name] !== prop) {el[name] = prop; rec.props[name] = prop;}
465
+ }
466
+ // Not while the player drags it: the value is theirs then.
467
+ if (!rec.holding && document.activeElement !== el && Number(el.value) !== value) {el.value = String(value);}
468
+ }
469
+
395
470
  function patchActivity(rec, node, fresh) {
396
471
  if (!fresh) {return;}
397
472
  ensureActivityStyle();
@@ -495,6 +570,8 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
495
570
  if (rec.el.disabled !== disabled) {rec.el.disabled = disabled;}
496
571
  } else if (node.t === 'field') {
497
572
  patchField(rec, node, fresh);
573
+ } else if (node.t === 'slider') {
574
+ patchSlider(rec, node, fresh);
498
575
  } else if (node.t === 'activity') {
499
576
  patchActivity(rec, node, fresh);
500
577
  } else if (node.t === 'image') {
@@ -532,7 +609,8 @@ export function mountUiTree(container, { slots = {}, created = () => {}, removed
532
609
  });
533
610
  for (const [key, kid] of rec.kids) {
534
611
  const child = wanted.get(key);
535
- if (!child || kid.tag !== tagFor(child, node.t)) {
612
+ // A field and a slider are both inputs, of different types.
613
+ if (!child || kid.tag !== tagFor(child, node.t) || (kid.node.t === 'slider') !== (child.t === 'slider')) {
536
614
  drop(kid, `${path}/${segment(key)}`);
537
615
  rec.kids.delete(key);
538
616
  }
@@ -7,7 +7,7 @@
7
7
  //
8
8
  // A node is { t, k?, s?, at?, on?, c?, ...type fields }:
9
9
  // t the type: column row stack scroll grid text button field image icon
10
- // activity spacer;
10
+ // activity spacer slider;
11
11
  // k its key, unique among its siblings (default `#<index>`); the keys from
12
12
  // the root down, joined with '/', are its path ('%' and '/' in a key are
13
13
  // written %25 and %2F there, so a key 'a/b' is never the path of 'b'
@@ -40,14 +40,32 @@
40
40
  // key appears and the viewer was at the end)
41
41
  // and scroll.refollow (a counter: re-apply the
42
42
  // last alignment if the viewer has not moved).
43
+ //
44
+ // v1.167, opt-in shapes (a tree without them is the same bytes):
45
+ // s.pad side [min, add] an edge value: max(min, the safe-area
46
+ // inset on that side + add); plain numbers
47
+ // stay the default (a bottom sheet's paint
48
+ // reaching under the home bar);
49
+ // s.aspect n width / height (a square menu tile is 1);
50
+ // s.shadow 'glow' 0 0 0 3px rgba(255,216,74,0.5) (a chosen
51
+ // ballot face).
52
+ //
53
+ // v1.198, the slider (a type no earlier tree has, so trees without one are
54
+ // the same bytes; an older native renderer drops it with its subtree):
55
+ // slider a leaf: value, min (0), max (1), step (0: continuous), disabled
56
+ // (false), tint (the track and thumb's colour, a token or a CSS
57
+ // colour; 'gold'). Its value is clamped to [min, max] (`sliderValue`).
58
+ // Events: 'input' { value } on each move while it is dragged,
59
+ // 'release' { value } when it is let go. While the player holds it,
60
+ // a renderer keeps the player's value, not a resent one.
43
61
 
44
- export const TYPES = new Set(['column', 'row', 'stack', 'scroll', 'grid', 'text', 'button', 'field', 'image', 'icon', 'activity', 'spacer']);
62
+ export const TYPES = new Set(['column', 'row', 'stack', 'scroll', 'grid', 'text', 'button', 'field', 'image', 'icon', 'activity', 'spacer', 'slider']);
45
63
  const CONTAINERS = new Set(['column', 'row', 'stack', 'scroll', 'grid', 'button']);
46
64
  export const EVENTS = new Set(['tap', 'press', 'release', 'cancel', 'input', 'submit', 'focus', 'blur']);
47
65
 
48
66
  // The closed style subset. Text keys inherit down the tree, as in CSS.
49
67
  export const STYLE_KEYS = new Set([
50
- 'w', 'h', 'minW', 'minH', 'maxW', 'maxH', 'pad', 'mt', 'gap', 'flex', 'basis', 'align', 'justify', 'wrap', 'self', 'box',
68
+ 'w', 'h', 'minW', 'minH', 'maxW', 'maxH', 'aspect', 'pad', 'mt', 'gap', 'flex', 'basis', 'align', 'justify', 'wrap', 'self', 'box',
51
69
  'bg', 'radius', 'border', 'shadow', 'opacity', 'gray', 'clip', 'gone', 'hidden', 'hit',
52
70
  'color', 'font', 'size', 'weight', 'lh', 'ls', 'italic', 'upper', 'tabular', 'talign', 'lines', 'ellipsis', 'tshadow', 'fit',
53
71
  ]);
@@ -62,8 +80,19 @@ const TYPE_FIELDS = {
62
80
  image: ['src', 'fit'],
63
81
  icon: ['name', 'tint'],
64
82
  activity: ['kind'],
83
+ slider: ['value', 'min', 'max', 'step', 'disabled', 'tint'],
65
84
  };
66
85
 
86
+ // A slider's range and value, defaults filled in: the value clamped to
87
+ // [min, max] (a missing or non-number value is min; max below min is min).
88
+ export function sliderValue(node) {
89
+ const num = (value, fallback) => (typeof value === 'number' && Number.isFinite(value) ? value : fallback);
90
+ const min = num(node?.min, 0);
91
+ const max = Math.max(min, num(node?.max, 1));
92
+ const step = Math.max(0, num(node?.step, 0));
93
+ return { min, max, step, value: Math.min(max, Math.max(min, num(node?.value, min))) };
94
+ }
95
+
67
96
  // Theme tokens: today's literals, byte for byte (schema §4).
68
97
  export const TOKENS = {
69
98
  chip: 'rgba(20,16,12,0.72)',
@@ -93,7 +122,7 @@ export const TOKENS = {
93
122
  // close around each letter as well as the soft drop shadow, so it reads over a
94
123
  // pale sky as it does over a dark street.
95
124
  export 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)';
96
- export const SHADOWS = { card: '0 4px 14px rgba(0,0,0,0.45)', sheet: '0 -4px 18px rgba(0,0,0,0.45)', lift: '0 2px 6px rgba(0,0,0,0.4)', none: 'none' };
125
+ export const SHADOWS = { card: '0 4px 14px rgba(0,0,0,0.45)', sheet: '0 -4px 18px rgba(0,0,0,0.45)', lift: '0 2px 6px rgba(0,0,0,0.4)', glow: '0 0 0 3px rgba(255,216,74,0.5)', none: 'none' };
97
126
  export const TEXT_SHADOWS = { outline: BARE_TEXT_SHADOW, soft: '0 2px 4px rgba(0,0,0,0.5)', none: 'none' };
98
127
  export const FONTS = { ui: 'system-ui, sans-serif', mono: 'ui-monospace, monospace' };
99
128