castle-web-cli 0.4.229 → 0.4.230

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 (232) hide show
  1. package/dist/agent-prompts.d.ts +2 -0
  2. package/dist/agent-prompts.js +16 -8
  3. package/dist/agent.d.ts +2 -0
  4. package/dist/agent.js +21 -21
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +74 -16
  7. package/dist/castle-host/host.d.ts +91 -0
  8. package/dist/castle-host/host.js +779 -3
  9. package/dist/castleJson.d.ts +44 -0
  10. package/dist/castleJson.js +131 -0
  11. package/dist/check.js +27 -1
  12. package/dist/contentPack.d.ts +49 -0
  13. package/dist/contentPack.js +273 -0
  14. package/dist/devExperiments.d.ts +21 -0
  15. package/dist/devExperiments.js +139 -0
  16. package/dist/devHub.d.ts +55 -0
  17. package/dist/devHub.js +187 -0
  18. package/dist/devSessionChild.js +3 -1
  19. package/dist/devSessionServer.d.ts +14 -1
  20. package/dist/devSessionServer.js +229 -44
  21. package/dist/experimentAssignment.d.ts +15 -0
  22. package/dist/experimentAssignment.js +41 -0
  23. package/dist/importCheckHook.d.ts +40 -0
  24. package/dist/importCheckHook.js +171 -0
  25. package/dist/importRegression.d.ts +15 -0
  26. package/dist/importRegression.js +100 -0
  27. package/dist/importTrust.d.ts +2 -0
  28. package/dist/importTrust.js +27 -0
  29. package/dist/importUpdateHook.d.ts +18 -0
  30. package/dist/importUpdateHook.js +31 -8
  31. package/dist/importUpdateHookRunner.js +19 -7
  32. package/dist/imports.d.ts +16 -0
  33. package/dist/imports.js +141 -31
  34. package/dist/index.js +3 -1
  35. package/dist/init.d.ts +3 -0
  36. package/dist/init.js +125 -8
  37. package/dist/install.js +4 -1
  38. package/dist/localPaths.js +4 -0
  39. package/dist/login.js +2 -2
  40. package/dist/platformDoc.js +3 -8
  41. package/dist/playPagePolicy.js +3 -1
  42. package/dist/remix.js +5 -0
  43. package/dist/routerTaskReport.d.ts +28 -0
  44. package/dist/routerTaskReport.js +56 -0
  45. package/dist/save-deck.d.ts +18 -0
  46. package/dist/save-deck.js +142 -6
  47. package/dist/serve.d.ts +8 -0
  48. package/dist/serve.js +94 -13
  49. package/dist/serverBundle.d.ts +1 -1
  50. package/dist/serverBundle.js +5 -1
  51. package/dist/webSourceSync.d.ts +2 -0
  52. package/dist/webSourceSync.js +2 -0
  53. package/kits/base/CLAUDE.md +2 -3
  54. package/kits/base/castle.json +1 -1
  55. package/kits/base/sdk/README.md +258 -52
  56. package/kits/base/sdk/agent.js +4 -4
  57. package/kits/base/sdk/avatar.d.ts +12 -0
  58. package/kits/base/sdk/avatar.js +23 -0
  59. package/kits/base/sdk/castle.d.ts +5 -0
  60. package/kits/base/sdk/castle.js +3 -0
  61. package/kits/base/sdk/commands.d.ts +208 -0
  62. package/kits/base/sdk/commands.js +16 -0
  63. package/kits/base/sdk/context.d.ts +6 -0
  64. package/kits/base/sdk/experiments.d.ts +15 -0
  65. package/kits/base/sdk/experiments.js +83 -0
  66. package/kits/base/sdk/hub.d.ts +85 -0
  67. package/kits/base/sdk/hub.js +107 -0
  68. package/kits/base/sdk/multiplayer.d.ts +45 -1
  69. package/kits/base/sdk/multiplayer.js +106 -4
  70. package/kits/base/sdk/server/hub.d.ts +169 -0
  71. package/kits/base/sdk/server/hub.js +125 -0
  72. package/kits/base/sdk/server/platformHandle.d.ts +42 -1
  73. package/kits/base/sdk/server/storage.d.ts +55 -2
  74. package/kits/base/sdk/server/wrapper.d.ts +32 -2
  75. package/kits/base/sdk/server/wrapper.js +90 -11
  76. package/kits/base/sdk/transport.d.ts +2 -1
  77. package/kits/base/sdk/transport.js +13 -1
  78. package/kits/hub-game/.prettierrc +5 -0
  79. package/kits/hub-game/CLAUDE.md +146 -0
  80. package/kits/hub-game/blueprints/avatar-0.scene +28 -0
  81. package/kits/hub-game/blueprints/avatar-1.scene +28 -0
  82. package/kits/hub-game/blueprints/avatar-2.scene +28 -0
  83. package/kits/hub-game/blueprints/avatar-3.scene +28 -0
  84. package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
  85. package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
  86. package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
  87. package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
  88. package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
  89. package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
  90. package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
  91. package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
  92. package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
  93. package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
  94. package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
  95. package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
  96. package/kits/hub-game/castle.json +96 -0
  97. package/kits/hub-game/code/client/attention.js +133 -0
  98. package/kits/hub-game/code/client/avatar.js +288 -0
  99. package/kits/hub-game/code/client/cabinets.js +90 -0
  100. package/kits/hub-game/code/client/chat.js +135 -0
  101. package/kits/hub-game/code/client/chrome.js +1001 -0
  102. package/kits/hub-game/code/client/doorFrame.js +15 -0
  103. package/kits/hub-game/code/client/firstJoin.js +14 -0
  104. package/kits/hub-game/code/client/grab.js +241 -0
  105. package/kits/hub-game/code/client/hookLayer.js +230 -0
  106. package/kits/hub-game/code/client/idle.js +326 -0
  107. package/kits/hub-game/code/client/keys.js +48 -0
  108. package/kits/hub-game/code/client/pack.js +232 -0
  109. package/kits/hub-game/code/client/packFormat.js +397 -0
  110. package/kits/hub-game/code/client/say.js +127 -0
  111. package/kits/hub-game/code/client/sha256.js +80 -0
  112. package/kits/hub-game/code/client/sound.js +147 -0
  113. package/kits/hub-game/code/client/state.js +131 -0
  114. package/kits/hub-game/code/client/talk.js +259 -0
  115. package/kits/hub-game/code/client/together.js +365 -0
  116. package/kits/hub-game/code/client/wear.js +149 -0
  117. package/kits/hub-game/code/server/actors.js +627 -0
  118. package/kits/hub-game/code/server/blocks.js +103 -0
  119. package/kits/hub-game/code/server/cabinets.js +309 -0
  120. package/kits/hub-game/code/server/game.js +137 -0
  121. package/kits/hub-game/code/server/grab.js +247 -0
  122. package/kits/hub-game/code/server/history.js +96 -0
  123. package/kits/hub-game/code/server/hub.js +1904 -0
  124. package/kits/hub-game/code/server/idle.js +412 -0
  125. package/kits/hub-game/code/server/index.js +64 -0
  126. package/kits/hub-game/code/server/labels.js +59 -0
  127. package/kits/hub-game/code/server/manifest.js +527 -0
  128. package/kits/hub-game/code/server/npcs.js +745 -0
  129. package/kits/hub-game/code/server/party.js +381 -0
  130. package/kits/hub-game/code/server/place.js +43 -0
  131. package/kits/hub-game/code/server/say.js +83 -0
  132. package/kits/hub-game/code/server/wear.js +142 -0
  133. package/kits/hub-game/code/systems/hub.js +2230 -0
  134. package/kits/hub-game/docs/content-pack.md +151 -0
  135. package/kits/hub-game/docs/contract.md +1139 -0
  136. package/kits/hub-game/docs/style.md +137 -0
  137. package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
  138. package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
  139. package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
  140. package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
  141. package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
  142. package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
  143. package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
  144. package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
  145. package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
  146. package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
  147. package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
  148. package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
  149. package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
  150. package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
  151. package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
  152. package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
  153. package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
  154. package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
  155. package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
  156. package/kits/hub-game/eslint.config.js +20 -0
  157. package/kits/hub-game/fonts.generated.js +9 -0
  158. package/kits/hub-game/index.html +22 -0
  159. package/kits/hub-game/main.jsx +6 -0
  160. package/kits/hub-game/models/avatar-0.pxmodel +21 -0
  161. package/kits/hub-game/models/avatar-1.pxmodel +24 -0
  162. package/kits/hub-game/models/avatar-2.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-3.pxmodel +22 -0
  164. package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
  165. package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
  166. package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
  167. package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
  168. package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
  169. package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
  170. package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
  171. package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
  172. package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
  173. package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
  174. package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
  175. package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
  176. package/kits/hub-game/package-lock.json +365 -0
  177. package/kits/hub-game/package.json +32 -0
  178. package/kits/hub-game/scenes/main.scene +318 -0
  179. package/kits/hub-game/scripts/check.mjs +339 -0
  180. package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
  181. package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
  182. package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
  183. package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
  184. package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
  185. package/kits/hub-game/scripts/pack.mjs +192 -0
  186. package/kits/hub-game/scripts/test-actors.mjs +666 -0
  187. package/kits/hub-game/scripts/test-attention.mjs +103 -0
  188. package/kits/hub-game/scripts/test-avatar.mjs +472 -0
  189. package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
  190. package/kits/hub-game/scripts/test-blocks.mjs +351 -0
  191. package/kits/hub-game/scripts/test-chat.mjs +98 -0
  192. package/kits/hub-game/scripts/test-classic.mjs +590 -0
  193. package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
  194. package/kits/hub-game/scripts/test-door.mjs +56 -0
  195. package/kits/hub-game/scripts/test-grab.mjs +331 -0
  196. package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
  197. package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
  198. package/kits/hub-game/scripts/test-idle.mjs +518 -0
  199. package/kits/hub-game/scripts/test-interest.mjs +413 -0
  200. package/kits/hub-game/scripts/test-keys.mjs +50 -0
  201. package/kits/hub-game/scripts/test-manifest.mjs +224 -0
  202. package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
  203. package/kits/hub-game/scripts/test-npcs.mjs +714 -0
  204. package/kits/hub-game/scripts/test-pack.mjs +424 -0
  205. package/kits/hub-game/scripts/test-party.mjs +286 -0
  206. package/kits/hub-game/scripts/test-say.mjs +149 -0
  207. package/kits/hub-game/scripts/test-together.mjs +183 -0
  208. package/kits/hub-game/theme.style +3 -0
  209. package/kits/multiplayer-3d/castle.json +5 -5
  210. package/kits/multiplayer-3d/code/client/avatars.js +101 -1
  211. package/kits/multiplayer-3d/code/server/players.js +4 -1
  212. package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
  213. package/kits/multiplayer-3d/code/server/world.js +20 -7
  214. package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
  215. package/kits/physics-2d/castle.json +2 -2
  216. package/kits/physics-2d/engine/art.js +13 -0
  217. package/kits/physics-2d/engine/assets.js +4 -2
  218. package/kits/physics-2d/engine/scene.js +25 -5
  219. package/kits/physics-3d/CLAUDE.md +6 -1
  220. package/kits/physics-3d/castle.json +3 -3
  221. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
  222. package/kits/physics-3d/engine3d/artobjects.js +2 -2
  223. package/kits/physics-3d/engine3d/materials.js +29 -1
  224. package/kits/physics-3d/engine3d/world3d.js +65 -1
  225. package/kits/physics-3d/systems/physics3d.js +5 -2
  226. package/kits/real-time/castle.json +2 -2
  227. package/kits/real-time/code/client/connection.js +77 -7
  228. package/kits/real-time/code/client/gameHooks.js +63 -3
  229. package/kits/real-time/code/client/messages.js +7 -0
  230. package/kits/real-time/code/server/gameHooks.js +24 -0
  231. package/kits/real-time/code/server/session.js +390 -22
  232. package/package.json +2 -2
@@ -0,0 +1,1001 @@
1
+ // The hub's own chrome: DOM drawn by the place, never by a game's content, so a
2
+ // game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
3
+ // Back control, the declared HUD, actor labels and speech, the result ribbon,
4
+ // the avatar picker, the NPC talk button and panel, a town's door list (jump
5
+ // to a door), the people here and the player's friends, each friend with
6
+ // where they are and Join, each player with Report (where the host takes
7
+ // reports), the pointers to friends out of sight,
8
+ // the Grab / Throw button (a place with `grab`, v1.3), the emote picker and
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`.
11
+
12
+ import { cardMode, makeCardView, tapCard } from './cabinets.js';
13
+ import { guardScrollKeys } from './keys.js';
14
+
15
+ const Z = 2147480000;
16
+
17
+ function el(tag, style, parent = document.body) {
18
+ const node = document.createElement(tag);
19
+ Object.assign(node.style, style);
20
+ parent.appendChild(node);
21
+ return node;
22
+ }
23
+
24
+ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onLeaveParty = () => {}, onReportChat = () => {} }) {
25
+ const unguardKeys = guardScrollKeys();
26
+ // A desktop stage (a mouse, room to spare): NPC lines are narrower and the
27
+ // talk panel sits in the bottom-left corner, clear of the avatar. Phones
28
+ // and narrow stages keep the layout they were tuned on.
29
+ const desktopQuery = globalThis.matchMedia?.('(pointer: fine) and (min-width: 700px)') ?? null;
30
+ const desktop = () => desktopQuery?.matches === true;
31
+ const root = el('div', { position: 'fixed', inset: '0', pointerEvents: 'none', zIndex: String(Z), font: '600 15px/1.3 system-ui, sans-serif', color: '#fff' });
32
+
33
+ // The door cover: a dark warm field the door animation fades to, with the
34
+ // destination named in it. It sits over everything while a scene swaps.
35
+ 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);
36
+ const coverText = el('div', { opacity: '0.85', letterSpacing: '0.12em', textTransform: 'uppercase', fontSize: '14px', color: '#e9c48f' }, cover);
37
+
38
+ 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);
39
+ back.textContent = '‹ Town';
40
+ back.addEventListener('pointerdown', (event) => {
41
+ event.stopPropagation();
42
+ onBack();
43
+ });
44
+
45
+ const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 1px 3px rgba(0,0,0,0.8)', display: 'none', maxWidth: '70vw' }, root);
46
+ const hudTitle = el('div', { fontSize: '13px', opacity: '0.85', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
47
+ const hudBig = el('div', { fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
48
+ const hudText = el('div', { fontSize: '14px', fontWeight: '500' }, hud);
49
+
50
+ const labels = el('div', { position: 'absolute', inset: '0' }, root);
51
+ const labelNodes = new Map();
52
+
53
+ // An arcade cabinet's card (v1.7). By the cabinet it is a chip: the best
54
+ // score and whose it is (their photo in a circle, their frame drawn over it
55
+ // a little larger, the way classic decks draw an avatar), small enough that
56
+ // the cabinets and the town behind them stay in view. A tap on the chip
57
+ // opens the board: the classic deck's cover, title and label and its top
58
+ // scores. A tap on the board, or walking away, closes it. Over the labels,
59
+ // so a pad's words never cut through a row; it is never drawn during a
60
+ // trip, so the door cover needs not hide it.
61
+ const cabinet = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', boxSizing: 'border-box', background: 'rgba(18,14,24,0.92)', border: '1px solid rgba(255,255,255,0.18)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', font: '600 13px/1.25 system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
62
+ cabinet.dataset.hub = 'cabinet';
63
+ let cabinetKey = '';
64
+ // Whose board this player opened, if any: one at a time (`cabinets.js`).
65
+ const cabinetView = makeCardView();
66
+ cabinet.addEventListener('pointerdown', (event) => {
67
+ event.stopPropagation();
68
+ tapCard(cabinetView);
69
+ });
70
+ const picture = (parent, src, style) => {
71
+ const img = el('img', { display: 'block', objectFit: 'cover', ...style }, parent);
72
+ img.alt = '';
73
+ img.draggable = false;
74
+ img.src = src;
75
+ return img;
76
+ };
77
+ // A player's photo `size` pixels across, their frame over it.
78
+ function faceOf(parent, row, size, imageOf) {
79
+ const px = `${size}px`;
80
+ const face = el('div', { position: 'relative', width: px, height: px, flex: 'none' }, parent);
81
+ const photo = imageOf(row.photo);
82
+ if (photo) {
83
+ picture(face, photo, { width: px, height: px, borderRadius: '50%', background: '#2a2433' });
84
+ } else {
85
+ const blank = el('div', { width: px, height: px, borderRadius: '50%', background: '#4a4458', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: `${Math.round(size * 0.46)}px` }, face);
86
+ blank.textContent = String(row.username ?? '?').slice(0, 1).toUpperCase();
87
+ }
88
+ const frame = imageOf(row.frame);
89
+ if (frame) {
90
+ // The frame sits over the photo and is 30% larger than it.
91
+ picture(face, frame, { position: 'absolute', left: '-15%', top: '-15%', width: '130%', height: '130%', objectFit: 'contain', pointerEvents: 'none' });
92
+ }
93
+ return face;
94
+ }
95
+ // The chip: the best score. False when the cabinet has no score to show,
96
+ // and nothing is drawn (its pad already says what it plays).
97
+ function buildCabinetChip(card, imageOf) {
98
+ cabinet.replaceChildren();
99
+ const best = Array.isArray(card.top) ? card.top[0] : null;
100
+ if (!best) {
101
+ return false;
102
+ }
103
+ Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto' });
104
+ cabinet.setAttribute('role', 'button');
105
+ cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: show the scores`);
106
+ const line = el('div', { display: 'flex', alignItems: 'center', gap: '7px', fontSize: '12px', whiteSpace: 'nowrap' }, cabinet);
107
+ faceOf(line, best, 20, imageOf);
108
+ const score = el('div', { fontWeight: '800', fontVariantNumeric: 'tabular-nums', maxWidth: '84px', overflow: 'hidden', textOverflow: 'ellipsis' }, line);
109
+ score.textContent = String(best.score ?? '');
110
+ const more = el('div', { opacity: '0.6', fontSize: '11px' }, line);
111
+ more.textContent = '▾';
112
+ return true;
113
+ }
114
+ function buildCabinetBoard(card, imageOf) {
115
+ cabinet.replaceChildren();
116
+ Object.assign(cabinet.style, { width: '204px', padding: '10px', borderRadius: '12px', pointerEvents: 'auto' });
117
+ cabinet.setAttribute('role', 'button');
118
+ cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: hide the scores`);
119
+ const head = el('div', { display: 'flex', gap: '10px', alignItems: 'center' }, cabinet);
120
+ const cover = imageOf(card.cover);
121
+ if (cover) {
122
+ picture(head, cover, { width: '54px', height: '76px', borderRadius: '6px', flex: 'none', background: '#2a2433' });
123
+ }
124
+ const words = el('div', { minWidth: '0', flex: '1' }, head);
125
+ const title = el('div', { fontSize: '15px', fontWeight: '800', overflow: 'hidden', display: '-webkit-box', webkitLineClamp: '2', webkitBoxOrient: 'vertical' }, words);
126
+ title.textContent = card.title || 'Arcade';
127
+ if (card.label) {
128
+ const label = el('div', { marginTop: '3px', fontSize: '11px', letterSpacing: '0.08em', textTransform: 'uppercase', color: '#e9c48f' }, words);
129
+ label.textContent = card.label;
130
+ }
131
+ const close = el('div', { alignSelf: 'flex-start', flex: 'none', width: '20px', height: '20px', borderRadius: '10px', background: 'rgba(255,255,255,0.14)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '13px', lineHeight: '1' }, head);
132
+ close.textContent = '×';
133
+ const top = Array.isArray(card.top) ? card.top.slice(0, 5) : [];
134
+ top.forEach((row, i) => {
135
+ const line = el('div', { display: 'flex', alignItems: 'center', gap: '9px', marginTop: i === 0 ? '10px' : '7px' }, cabinet);
136
+ const rank = el('div', { width: '10px', flex: 'none', textAlign: 'right', opacity: '0.6', fontSize: '12px' }, line);
137
+ rank.textContent = String(i + 1);
138
+ faceOf(line, row, 28, imageOf);
139
+ const name = el('div', { flex: '1', minWidth: '0', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, line);
140
+ name.textContent = String(row.username ?? '?');
141
+ const score = el('div', { flex: 'none', fontWeight: '800', fontVariantNumeric: 'tabular-nums' }, line);
142
+ score.textContent = String(row.score ?? '');
143
+ });
144
+ return true;
145
+ }
146
+
147
+ 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);
148
+
149
+ 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);
150
+
151
+ // The avatar picker: one button, "Character", that opens the kit's
152
+ // characters under their own heading. (Four bare numbers read as rooms.)
153
+ 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);
154
+ picker.addEventListener('pointerdown', (event) => event.stopPropagation());
155
+ 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);
156
+ el('div', { fontSize: '12px', opacity: '0.8' }, pickerCard).textContent = 'Your character';
157
+ const pickerRow = el('div', { display: 'flex', gap: '6px' }, pickerCard);
158
+ const pickerButtons = [];
159
+ let pickerOpen = false;
160
+ const setPickerOpen = (open) => {
161
+ pickerOpen = open;
162
+ pickerCard.style.display = open ? 'flex' : 'none';
163
+ };
164
+ for (let i = 0; i < avatarCount; i += 1) {
165
+ 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);
166
+ button.textContent = String(i + 1);
167
+ button.setAttribute('aria-label', `Character ${i + 1}`);
168
+ button.addEventListener('pointerdown', (event) => {
169
+ event.stopPropagation();
170
+ setPickerOpen(false);
171
+ onAvatar(i);
172
+ });
173
+ pickerButtons.push(button);
174
+ }
175
+ 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);
176
+ pickerToggle.textContent = 'Character';
177
+ pickerToggle.addEventListener('pointerdown', (event) => {
178
+ event.stopPropagation();
179
+ setPickerOpen(!pickerOpen);
180
+ });
181
+
182
+ // Talking to an NPC: a button when one is near, and a panel while a
183
+ // conversation is open. Keys typed here are the panel's, not the game's.
184
+ let talkHandlers = { open() {}, send() {}, end() {} };
185
+ 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);
186
+ talkButton.addEventListener('pointerdown', (event) => {
187
+ event.stopPropagation();
188
+ talkHandlers.open();
189
+ });
190
+ const panel = el('div', { position: 'absolute', left: '50%', bottom: 'max(12px, env(safe-area-inset-bottom))', transform: 'translateX(-50%)', width: 'min(92vw, 420px)', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '10px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
191
+ const panelHead = el('div', { display: 'flex', alignItems: 'baseline', gap: '8px' }, panel);
192
+ const panelName = el('div', { fontWeight: '700', flex: '1' }, panelHead);
193
+ const panelEnd = el('button', { pointerEvents: 'auto', padding: '4px 10px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.35)', background: 'transparent', color: '#fff', font: '600 13px system-ui, sans-serif', cursor: 'pointer' }, panelHead);
194
+ panelEnd.textContent = 'Done';
195
+ panelEnd.addEventListener('pointerdown', (event) => {
196
+ event.stopPropagation();
197
+ talkHandlers.end();
198
+ });
199
+ const panelNote = el('div', { fontSize: '11px', opacity: '0.65', fontWeight: '500' }, panel);
200
+ const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
201
+ // Not a <form>: castle.xyz plays a deck in a frame sandboxed without
202
+ // `allow-forms`, where a form's submission (Enter, or a submit button) is
203
+ // blocked before its submit event fires, so nothing would ever be said.
204
+ const panelForm = el('div', { display: 'flex', gap: '6px', margin: '0' }, panel);
205
+ 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);
206
+ panelInput.maxLength = 280;
207
+ panelInput.placeholder = 'Say something…';
208
+ panelInput.enterKeyHint = 'send';
209
+ 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);
210
+ panelSend.type = 'button';
211
+ panelSend.textContent = 'Say';
212
+ const submitTalk = () => {
213
+ const text = panelInput.value;
214
+ panelInput.value = '';
215
+ talkHandlers.send(text);
216
+ };
217
+ for (const type of ['keydown', 'keyup', 'keypress']) {
218
+ panelInput.addEventListener(type, (event) => event.stopPropagation());
219
+ }
220
+ panelInput.addEventListener('keydown', (event) => {
221
+ // An IME's own Enter (confirm) or Escape (cancel) belongs to the candidate;
222
+ // WebKit reports the confirming Enter as keyCode 229 with isComposing false.
223
+ if (event.isComposing || event.keyCode === 229) {
224
+ return;
225
+ }
226
+ if (event.key === 'Enter') {
227
+ event.preventDefault();
228
+ submitTalk();
229
+ } else if (event.key === 'Escape') {
230
+ event.preventDefault();
231
+ talkHandlers.end();
232
+ }
233
+ });
234
+ panel.addEventListener('pointerdown', (event) => event.stopPropagation());
235
+ panelSend.addEventListener('click', (event) => {
236
+ event.preventDefault();
237
+ submitTalk();
238
+ });
239
+ let talkOpen = false;
240
+ const layoutPanel = () => {
241
+ const wide = desktop();
242
+ Object.assign(panel.style, wide
243
+ ? { left: '10px', transform: 'none', width: '340px' }
244
+ : { left: '50%', transform: 'translateX(-50%)', width: 'min(92vw, 420px)' });
245
+ panelLog.style.maxHeight = wide ? 'min(28vh, 220px)' : '28vh';
246
+ };
247
+ layoutPanel();
248
+ desktopQuery?.addEventListener?.('change', layoutPanel);
249
+
250
+ // Grab / Throw (v1.3): a big thumb button bottom right, above the avatar
251
+ // picker, shown while there is something to grab or something held.
252
+ let grabHandler = () => {};
253
+ const grabButton = el('button', { position: 'absolute', right: '14px', bottom: 'max(60px, calc(env(safe-area-inset-bottom) + 50px))', width: '76px', height: '76px', borderRadius: '38px', pointerEvents: 'auto', border: '2px solid rgba(255,255,255,0.55)', background: 'rgba(20,16,12,0.78)', color: '#fff', font: '800 16px system-ui, sans-serif', display: 'none', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
254
+ grabButton.addEventListener('pointerdown', (event) => {
255
+ event.stopPropagation();
256
+ event.preventDefault();
257
+ grabHandler();
258
+ });
259
+
260
+ // Idle play (v1.6): an emote button above Grab that opens a row of emotes
261
+ // to its left, and Sit / Stand at the bottom centre, above Talk.
262
+ let emoteHandler = () => {};
263
+ let sitHandler = () => {};
264
+ const emoteBottom = 'max(146px, calc(env(safe-area-inset-bottom) + 136px))';
265
+ 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);
266
+ emoteButton.textContent = '☺';
267
+ emoteButton.setAttribute('aria-label', 'Emote');
268
+ 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);
269
+ emoteRow.addEventListener('pointerdown', (event) => event.stopPropagation());
270
+ let emotesOpen = false;
271
+ let emotesKey = '';
272
+ const setEmotesOpen = (open) => {
273
+ emotesOpen = open;
274
+ emoteRow.style.display = open ? 'flex' : 'none';
275
+ };
276
+ emoteButton.addEventListener('pointerdown', (event) => {
277
+ event.stopPropagation();
278
+ event.preventDefault();
279
+ setEmotesOpen(!emotesOpen);
280
+ });
281
+ // Quick reactions and phrases (v1.11): a speech button beside the emote
282
+ // button opens a small card, a row of emoji over the place's phrases; and
283
+ // the feed of what was just said, small, above the dock.
284
+ let sayHandler = () => {};
285
+ 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);
286
+ sayButton.textContent = '💬';
287
+ sayButton.setAttribute('aria-label', 'Quick chat');
288
+ 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);
289
+ sayCard.addEventListener('pointerdown', (event) => event.stopPropagation());
290
+ let sayOpen = false;
291
+ let sayKey = '';
292
+ let sayInput = null;
293
+ let sayNote = null;
294
+ const setSayOpen = (open) => {
295
+ sayOpen = open;
296
+ sayCard.style.display = open ? 'flex' : 'none';
297
+ };
298
+ sayButton.addEventListener('pointerdown', (event) => {
299
+ event.stopPropagation();
300
+ event.preventDefault();
301
+ setSayOpen(!sayOpen);
302
+ setEmotesOpen(false);
303
+ });
304
+ const feed = el('div', { position: 'absolute', left: '10px', bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: '0 1px 3px rgba(0,0,0,0.85)', opacity: '0.92' }, root);
305
+ let feedKey = '';
306
+ const sitButton = el('button', { position: 'absolute', bottom: 'max(112px, calc(env(safe-area-inset-bottom) + 102px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 22px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer', touchAction: 'manipulation' }, root);
307
+ sitButton.addEventListener('pointerdown', (event) => {
308
+ event.stopPropagation();
309
+ event.preventDefault();
310
+ sitHandler();
311
+ });
312
+
313
+ // Bottom left: the town's Doors, then People, side by side -- or People
314
+ // above Doors where a narrow screen leaves no room beside the avatar picker.
315
+ const dock = el('div', { position: 'absolute', left: '10px', bottom: 'max(10px, env(safe-area-inset-bottom))', display: 'flex', flexWrap: 'wrap-reverse', alignItems: 'flex-start', gap: '6px', maxWidth: 'calc(100vw - 130px)' }, root);
316
+ // A list opens just above the dock, however tall the dock is.
317
+ const aboveDock = (list) => {
318
+ list.style.bottom = `calc(max(10px, env(safe-area-inset-bottom)) + ${dock.offsetHeight + 6}px)`;
319
+ };
320
+ const doorsButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
321
+ doorsButton.textContent = 'Doors';
322
+ // The town's doors: the list opens above the dock, one list at a time, and
323
+ // Go puts the player in front of that door.
324
+ const doorsList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
325
+ doorsList.addEventListener('pointerdown', (event) => event.stopPropagation());
326
+ let doorsOpen = false;
327
+ let doorsKey = '';
328
+ function closeDoors() {
329
+ doorsOpen = false;
330
+ doorsList.style.display = 'none';
331
+ }
332
+ doorsButton.addEventListener('pointerdown', (event) => {
333
+ event.stopPropagation();
334
+ doorsOpen = !doorsOpen;
335
+ aboveDock(doorsList);
336
+ doorsList.style.display = doorsOpen ? 'flex' : 'none';
337
+ closePeople();
338
+ });
339
+
340
+ // The other players here, each with Report behind a confirm. Hub chrome
341
+ // only: a game's content cannot draw, hide or press it.
342
+ const peopleButton = el('button', { pointerEvents: 'auto', padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer' }, dock);
343
+ const peopleList = el('div', { position: 'absolute', left: '10px', bottom: 'max(56px, calc(env(safe-area-inset-bottom) + 46px))', width: 'min(80vw, 260px)', maxHeight: '40vh', overflowY: 'auto', pointerEvents: 'auto', display: 'none', flexDirection: 'column', gap: '6px', padding: '8px', borderRadius: '12px', background: 'rgba(20,16,12,0.88)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)' }, root);
344
+ peopleList.addEventListener('pointerdown', (event) => event.stopPropagation());
345
+ let peopleOpen = false;
346
+ let peopleKey = '';
347
+ function closePeople() {
348
+ peopleOpen = false;
349
+ peopleList.style.display = 'none';
350
+ }
351
+ peopleButton.addEventListener('pointerdown', (event) => {
352
+ event.stopPropagation();
353
+ peopleOpen = !peopleOpen;
354
+ aboveDock(peopleList);
355
+ peopleList.style.display = peopleOpen ? 'flex' : 'none';
356
+ closeDoors();
357
+ });
358
+ const smallButton = (parent, text, primary) => {
359
+ 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);
360
+ button.textContent = text;
361
+ return button;
362
+ };
363
+ // One row: the name, with where they are under it in a town, and the
364
+ // row's actions (`person.actions`, [{ id, text }]): the first beside the
365
+ // name, the rest behind a "more" button on a line under it. Report asks
366
+ // first: the question, then Report / Cancel. Returns the node its `where`
367
+ // words live in, so they change without the row being rebuilt.
368
+ function personRow(person) {
369
+ const box = el('div', { display: 'flex', flexDirection: 'column', gap: '4px' }, peopleList);
370
+ let whereNode = null;
371
+ let more = false;
372
+ const act = (parent, action, primary) => {
373
+ smallButton(parent, action.text, primary).addEventListener('pointerdown', (event) => {
374
+ event.stopPropagation();
375
+ if (action.id === 'report') {
376
+ draw(true);
377
+ return;
378
+ }
379
+ closePeople();
380
+ onPerson(person, action.id);
381
+ });
382
+ };
383
+ const draw = (confirming) => {
384
+ box.replaceChildren();
385
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, box);
386
+ const words = el('div', { flex: '1', minWidth: '0' }, row);
387
+ const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
388
+ const who = person.username ?? 'this player';
389
+ name.textContent = confirming ? `Report ${who}?` : `${person.mark ?? ''}${who}`;
390
+ whereNode = null;
391
+ if (confirming) {
392
+ smallButton(row, 'Report', true).addEventListener('pointerdown', (event) => {
393
+ event.stopPropagation();
394
+ closePeople();
395
+ draw(false);
396
+ onReport(person);
397
+ });
398
+ smallButton(row, 'Cancel', false).addEventListener('pointerdown', (event) => {
399
+ event.stopPropagation();
400
+ draw(false);
401
+ });
402
+ return;
403
+ }
404
+ if (person.where) {
405
+ whereNode = el('div', { fontSize: '12px', fontWeight: '500', opacity: '0.75', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
406
+ whereNode.textContent = person.where;
407
+ }
408
+ const [first, ...rest] = person.actions ?? [];
409
+ if (first) {
410
+ act(row, first, first.id !== 'report' && first.id !== 'find');
411
+ }
412
+ if (rest.length) {
413
+ const toggle = smallButton(row, '⋯', false);
414
+ toggle.setAttribute('aria-label', `More for ${who}`);
415
+ toggle.style.padding = '5px 8px';
416
+ toggle.addEventListener('pointerdown', (event) => {
417
+ event.stopPropagation();
418
+ more = !more;
419
+ draw(false);
420
+ });
421
+ if (more) {
422
+ const line = el('div', { display: 'flex', justifyContent: 'flex-end', gap: '6px' }, box);
423
+ for (const action of rest) {
424
+ act(line, action, false);
425
+ }
426
+ }
427
+ }
428
+ };
429
+ draw(false);
430
+ return { setWhere: (text) => whereNode && whereNode.textContent !== text && (whereNode.textContent = text) };
431
+ }
432
+ const peopleRows = new Map();
433
+
434
+ // Pointers to friends out of sight (a town): a small chip over a friend far
435
+ // off, or at the screen's edge with an arrow when they are off screen.
436
+ const pointers = el('div', { position: 'absolute', inset: '0' }, root);
437
+ const pointerNodes = new Map();
438
+
439
+ // A question put to the player (v1.10): an invitation to a party, a door
440
+ // their party wants to go through. One at a time, under the HUD.
441
+ 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);
442
+ askCard.addEventListener('pointerdown', (event) => event.stopPropagation());
443
+ let askKey = '';
444
+ let askNow = null;
445
+ // Standing by someone who is not in the player's party: invite them.
446
+ let nearHandler = () => {};
447
+ 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);
448
+ nearButton.addEventListener('pointerdown', (event) => {
449
+ event.stopPropagation();
450
+ event.preventDefault();
451
+ nearHandler();
452
+ });
453
+
454
+ 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);
455
+
456
+ return {
457
+ setCover(alpha, text) {
458
+ cover.style.opacity = String(alpha);
459
+ cover.style.pointerEvents = alpha > 0.05 ? 'auto' : 'none';
460
+ if (text !== undefined && coverText.textContent !== text) {
461
+ coverText.textContent = text;
462
+ }
463
+ },
464
+ showBack(show, label = 'Back') {
465
+ back.style.display = show ? 'block' : 'none';
466
+ const text = `‹ ${label}`;
467
+ if (back.textContent !== text) {
468
+ back.textContent = text;
469
+ }
470
+ },
471
+ setHud(spec, timerSeconds) {
472
+ if (!spec) {
473
+ hud.style.display = 'none';
474
+ return;
475
+ }
476
+ hud.style.display = 'block';
477
+ hudTitle.textContent = spec.title ?? '';
478
+ const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
479
+ hudBig.textContent = big;
480
+ hudBig.style.display = big ? 'block' : 'none';
481
+ hudText.textContent = spec.text ?? '';
482
+ },
483
+ // `items` is [{ id, x, y, text, speech, npc, color }] in CSS pixels (a
484
+ // `color` is a player's mark); anything not
485
+ // listed is removed.
486
+ setLabels(items) {
487
+ const seen = new Set();
488
+ for (const item of items) {
489
+ seen.add(item.id);
490
+ let node = labelNodes.get(item.id);
491
+ if (!node) {
492
+ node = el('div', { position: 'absolute', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '12px', background: 'rgba(15,12,10,0.7)', whiteSpace: 'nowrap', fontSize: '14px' }, labels);
493
+ labelNodes.set(item.id, node);
494
+ }
495
+ // An NPC's line is kept on screen: a reply over one at the edge of the
496
+ // view would otherwise be cut off mid-sentence. Other labels are
497
+ // placed as they always were.
498
+ let x = item.x;
499
+ if (item.npc) {
500
+ const half = node.offsetWidth / 2;
501
+ x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
502
+ }
503
+ node.style.left = `${x}px`;
504
+ node.style.top = `${item.y}px`;
505
+ if (item.speech) {
506
+ node.style.background = 'rgba(255,250,240,0.94)';
507
+ node.style.color = '#2b2118';
508
+ node.style.whiteSpace = 'normal';
509
+ if (item.npc) {
510
+ // Its own width, not what is left of the screen to its right.
511
+ node.style.width = 'max-content';
512
+ }
513
+ node.style.maxWidth = item.npc && desktop() ? 'min(62vw, 320px)' : '62vw';
514
+ node.style.fontSize = '13px';
515
+ node.style.fontWeight = '500';
516
+ }
517
+ if (item.emote && node.dataset.emote !== '1') {
518
+ // An emote's emoji over a player: large, on nothing.
519
+ node.dataset.emote = '1';
520
+ node.style.background = 'transparent';
521
+ node.style.fontSize = '30px';
522
+ node.style.padding = '0';
523
+ node.style.textShadow = '0 2px 4px rgba(0,0,0,0.5)';
524
+ }
525
+ if (item.opacity !== undefined) {
526
+ node.style.opacity = String(item.opacity);
527
+ }
528
+ if (item.color && node.dataset.color !== item.color) {
529
+ // A player's mark: the place's colour, its words in whichever of
530
+ // black or white reads on it.
531
+ node.dataset.color = item.color;
532
+ node.style.background = item.color;
533
+ node.style.color = readableOn(item.color);
534
+ node.style.fontWeight = '700';
535
+ node.style.border = '2px solid rgba(255,255,255,0.85)';
536
+ }
537
+ if (node.textContent !== item.text) {
538
+ node.textContent = item.text;
539
+ }
540
+ }
541
+ for (const [id, node] of labelNodes) {
542
+ if (!seen.has(id)) {
543
+ node.remove();
544
+ labelNodes.delete(id);
545
+ }
546
+ }
547
+ },
548
+ // `item` is { id, rev, card, x, y, opacity } in CSS pixels, or null for no
549
+ // card; `imageOf(value)` is a picture's `src`, or null for none.
550
+ setCabinet(item, imageOf) {
551
+ const open = cardMode(cabinetView, item ? item.id : null) === 'board';
552
+ if (!item) {
553
+ cabinet.style.display = 'none';
554
+ return;
555
+ }
556
+ const key = `${item.id}:${item.rev}:${open ? 'board' : 'chip'}`;
557
+ if (key !== cabinetKey) {
558
+ cabinetKey = key;
559
+ cabinet.dataset.drawn = (open ? buildCabinetBoard : buildCabinetChip)(item.card, imageOf) ? (open ? 'board' : 'chip') : '';
560
+ }
561
+ if (!cabinet.dataset.drawn) {
562
+ cabinet.style.display = 'none';
563
+ return;
564
+ }
565
+ cabinet.style.display = 'block';
566
+ // Kept on screen: a card over a cabinet at the edge of the view.
567
+ const half = cabinet.offsetWidth / 2;
568
+ cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6)}px`;
569
+ cabinet.style.top = `${Math.max(item.y, cabinet.offsetHeight + 6)}px`;
570
+ // A board the player asked for is read whole, wherever they stand by it.
571
+ cabinet.style.opacity = String(open ? 1 : item.opacity);
572
+ },
573
+ setRibbon(pos, text) {
574
+ if (!pos) {
575
+ ribbon.style.display = 'none';
576
+ return;
577
+ }
578
+ ribbon.style.display = 'block';
579
+ ribbon.style.left = `${pos.x}px`;
580
+ ribbon.style.top = `${pos.y}px`;
581
+ if (ribbon.textContent !== text) {
582
+ ribbon.textContent = text;
583
+ }
584
+ },
585
+ setToast(text) {
586
+ toast.style.display = text ? 'block' : 'none';
587
+ if (text && toast.textContent !== text) {
588
+ toast.textContent = text;
589
+ }
590
+ },
591
+ showPicker(show, selected) {
592
+ picker.style.display = show ? 'flex' : 'none';
593
+ if (!show) {
594
+ setPickerOpen(false);
595
+ }
596
+ pickerButtons.forEach((button, i) => {
597
+ button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
598
+ });
599
+ },
600
+ onTalk(handlers) {
601
+ talkHandlers = handlers;
602
+ },
603
+ onGrab(handler) {
604
+ grabHandler = handler;
605
+ },
606
+ onEmote(handler) {
607
+ emoteHandler = handler;
608
+ },
609
+ onSay(handler) {
610
+ sayHandler = handler;
611
+ },
612
+ onSit(handler) {
613
+ sitHandler = handler;
614
+ },
615
+ // `emotes` is [[id, emoji]] to offer, or null to hide the picker.
616
+ setEmotes(emotes) {
617
+ const show = Array.isArray(emotes) && emotes.length > 0;
618
+ emoteButton.style.display = show ? 'block' : 'none';
619
+ if (!show) {
620
+ setEmotesOpen(false);
621
+ return;
622
+ }
623
+ const key = emotes.map(([id]) => id).join('|');
624
+ if (key === emotesKey) {
625
+ return;
626
+ }
627
+ emotesKey = key;
628
+ emoteRow.replaceChildren();
629
+ for (const [id, emoji] of emotes) {
630
+ const button = el('button', { width: '44px', height: '44px', borderRadius: '22px', border: 'none', background: 'transparent', font: '26px system-ui, sans-serif', cursor: 'pointer', padding: '0', touchAction: 'manipulation' }, emoteRow);
631
+ button.textContent = emoji;
632
+ button.setAttribute('aria-label', id);
633
+ button.addEventListener('pointerdown', (event) => {
634
+ event.stopPropagation();
635
+ event.preventDefault();
636
+ setEmotesOpen(false);
637
+ emoteHandler(id);
638
+ });
639
+ }
640
+ },
641
+ // `say` is { reactions: [emoji], phrases: [[id, words]] } to offer, or
642
+ // null to hide the button; a pick calls the handler with { r } or { p }.
643
+ setSay(say) {
644
+ sayButton.style.display = say ? 'block' : 'none';
645
+ if (!say) {
646
+ setSayOpen(false);
647
+ return;
648
+ }
649
+ const chat = say.chat ?? null;
650
+ const key = `${say.reactions.join('')}|${say.phrases.map(([id]) => id).join(',')}|${chat ? (chat.input ? 1 : 0) : '-'}`;
651
+ // Whom chat reaches changes as people come and go: only its words are
652
+ // rewritten, so a line being typed is not lost.
653
+ if (key === sayKey && sayNote && chat && sayNote.textContent !== (chat.note ?? '')) {
654
+ sayNote.textContent = chat.note ?? '';
655
+ }
656
+ if (key === sayKey) {
657
+ return;
658
+ }
659
+ sayKey = key;
660
+ sayCard.replaceChildren();
661
+ const pick = (node, what) =>
662
+ node.addEventListener('pointerdown', (event) => {
663
+ event.stopPropagation();
664
+ event.preventDefault();
665
+ setSayOpen(false);
666
+ sayHandler(what);
667
+ });
668
+ const row = el('div', { display: 'flex', justifyContent: 'space-between' }, sayCard);
669
+ say.reactions.forEach((emoji, r) => {
670
+ const button = el('button', { width: '34px', height: '34px', border: 'none', background: 'transparent', font: '22px system-ui, sans-serif', cursor: 'pointer', padding: '0', touchAction: 'manipulation' }, row);
671
+ button.textContent = emoji;
672
+ button.setAttribute('aria-label', `React ${emoji}`);
673
+ pick(button, { r });
674
+ });
675
+ const lines = el('div', { display: 'flex', flexWrap: 'wrap', gap: '5px' }, sayCard);
676
+ for (const [id, words] of say.phrases) {
677
+ const button = smallButton(lines, words, false);
678
+ button.style.fontWeight = '600';
679
+ pick(button, { p: id });
680
+ }
681
+ // Free-text chat (v1.12), where the host has it: whom it reaches, or
682
+ // why it reaches nobody, and the field. Not a <form> (see the talk panel).
683
+ sayInput = null;
684
+ sayNote = null;
685
+ if (!chat) {
686
+ return;
687
+ }
688
+ sayNote = el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, sayCard);
689
+ sayNote.textContent = chat.note ?? '';
690
+ const line = el('div', { display: 'flex', gap: '6px', opacity: chat.input ? '1' : '0.5' }, sayCard);
691
+ 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);
692
+ input.maxLength = 200;
693
+ input.placeholder = 'Message…';
694
+ // Shown even when it cannot be used, so chat can be found; the note says why.
695
+ input.disabled = !chat.input;
696
+ input.enterKeyHint = 'send';
697
+ sayInput = input;
698
+ const send = () => {
699
+ const text = input.value.trim();
700
+ if (!text) {
701
+ return;
702
+ }
703
+ input.value = '';
704
+ input.blur();
705
+ setSayOpen(false);
706
+ sayHandler({ text });
707
+ };
708
+ for (const type of ['keydown', 'keyup', 'keypress']) {
709
+ input.addEventListener(type, (event) => event.stopPropagation());
710
+ }
711
+ input.addEventListener('keydown', (event) => {
712
+ if (event.isComposing || event.keyCode === 229) {
713
+ return;
714
+ }
715
+ if (event.key === 'Enter') {
716
+ event.preventDefault();
717
+ send();
718
+ } else if (event.key === 'Escape') {
719
+ event.preventDefault();
720
+ input.blur();
721
+ setSayOpen(false);
722
+ }
723
+ });
724
+ const button = el('button', { padding: '7px 12px', borderRadius: '8px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, line);
725
+ button.type = 'button';
726
+ button.textContent = 'Send';
727
+ button.disabled = !chat.input;
728
+ button.addEventListener('click', (event) => {
729
+ event.preventDefault();
730
+ send();
731
+ });
732
+ },
733
+ // Whether the chat field has the keyboard (the game's keys are its own).
734
+ chatFocused: () => sayInput !== null && document.activeElement === sayInput,
735
+ // The lines of what was just said, oldest first; hidden while a list is open.
736
+ // Each is `{ text, id }`; a line with an `id` is another player's chat
737
+ // message: a tap on it asks whether to report it.
738
+ setFeed(lines) {
739
+ const shown = doorsOpen || peopleOpen ? [] : lines;
740
+ const key = shown.map((line) => `${line.id ?? ''}:${line.text}`).join('\n');
741
+ if (key === feedKey) {
742
+ return;
743
+ }
744
+ feedKey = key;
745
+ feed.replaceChildren();
746
+ for (const line of shown) {
747
+ const node = el('div', {}, feed);
748
+ node.textContent = line.text;
749
+ if (!line.id) {
750
+ continue;
751
+ }
752
+ node.style.pointerEvents = 'auto';
753
+ node.style.cursor = 'pointer';
754
+ node.addEventListener('pointerdown', (event) => {
755
+ event.stopPropagation();
756
+ node.replaceChildren();
757
+ node.style.display = 'flex';
758
+ node.style.gap = '6px';
759
+ node.style.alignItems = 'center';
760
+ el('span', {}, node).textContent = 'Report this message?';
761
+ smallButton(node, 'Report', true).addEventListener('pointerdown', (e) => {
762
+ e.stopPropagation();
763
+ node.remove();
764
+ onReportChat(line);
765
+ });
766
+ smallButton(node, 'Cancel', false).addEventListener('pointerdown', (e) => {
767
+ e.stopPropagation();
768
+ feedKey = '';
769
+ });
770
+ }, { once: true });
771
+ }
772
+ },
773
+ // The Sit / Stand button's word, or null to hide it.
774
+ sitPrompt(text) {
775
+ sitButton.style.display = text ? 'block' : 'none';
776
+ if (text && sitButton.textContent !== text) {
777
+ sitButton.textContent = text;
778
+ }
779
+ },
780
+ // The Grab button's word ("Grab" or "Throw"), or null to hide it.
781
+ grabPrompt(text) {
782
+ grabButton.style.display = text ? 'block' : 'none';
783
+ if (text && grabButton.textContent !== text) {
784
+ grabButton.textContent = text;
785
+ grabButton.style.background = text === 'Throw' ? 'rgba(233,196,143,0.92)' : 'rgba(20,16,12,0.78)';
786
+ grabButton.style.color = text === 'Throw' ? '#2b2118' : '#fff';
787
+ }
788
+ },
789
+ // The Talk button, for the NPC named, or hidden.
790
+ talkPrompt(name) {
791
+ const show = Boolean(name) && !talkOpen;
792
+ talkButton.style.display = show ? 'block' : 'none';
793
+ const text = show ? `Talk to ${name}` : '';
794
+ if (show && talkButton.textContent !== text) {
795
+ talkButton.textContent = text;
796
+ }
797
+ },
798
+ openTalk(name, note) {
799
+ talkOpen = true;
800
+ panelName.textContent = name;
801
+ panelNote.textContent = note;
802
+ panelLog.replaceChildren();
803
+ panel.style.display = 'flex';
804
+ talkButton.style.display = 'none';
805
+ // With a keyboard, typing goes straight to the panel; a touch screen
806
+ // waits for a tap on the field rather than throwing up its keyboard.
807
+ if (globalThis.matchMedia?.('(pointer: fine)').matches) {
808
+ panelInput.focus({ preventScroll: true });
809
+ }
810
+ },
811
+ closeTalk() {
812
+ talkOpen = false;
813
+ panel.style.display = 'none';
814
+ panelInput.blur();
815
+ },
816
+ // `note`, when given, is a small caption under the line (a scripted reply).
817
+ talkLine(who, text, note = null) {
818
+ 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);
819
+ line.textContent = text;
820
+ if (note) {
821
+ el('div', { fontSize: '11px', fontStyle: 'italic', opacity: '0.65', marginTop: '2px' }, line).textContent = note;
822
+ }
823
+ panelLog.scrollTop = panelLog.scrollHeight;
824
+ },
825
+ talkWaiting(waiting) {
826
+ panelSend.disabled = waiting;
827
+ panelSend.style.opacity = waiting ? '0.5' : '1';
828
+ panelSend.textContent = waiting ? '…' : 'Say';
829
+ },
830
+ talkFocused() {
831
+ return document.activeElement === panelInput;
832
+ },
833
+ // `doors` is [{ id, title }] to offer, or null for none; `goText` is the
834
+ // word on each one's button ("Go", or "Go together" in a party).
835
+ setDoors(doors, goText = 'Go') {
836
+ const show = Array.isArray(doors) && doors.length > 0;
837
+ doorsButton.style.display = show ? 'block' : 'none';
838
+ if (!show) {
839
+ closeDoors();
840
+ doorsKey = '';
841
+ return;
842
+ }
843
+ const key = `${goText}#${doors.map((d) => `${d.id}:${d.title ?? ''}:${d.featured ? 'f' : ''}${d.solo ? 's' : ''}${d.need ?? ''}`).join('|')}`;
844
+ if (key === doorsKey) {
845
+ return;
846
+ }
847
+ doorsKey = key;
848
+ doorsList.replaceChildren();
849
+ for (const door of doors) {
850
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsList);
851
+ const name = el('div', { flex: '1', minWidth: '0', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, row);
852
+ name.textContent = `${door.featured ? '★ ' : ''}${door.title ?? door.id}`;
853
+ // One short word on what the door takes: a solo game, or how many it needs.
854
+ const takes = door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
855
+ if (takes) {
856
+ el('div', { flex: 'none', fontSize: '11px', fontWeight: '500', opacity: '0.7' }, row).textContent = takes;
857
+ }
858
+ 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);
859
+ // A party cannot go together through a door that takes one player.
860
+ go.textContent = door.solo ? 'Go' : goText;
861
+ go.addEventListener('pointerdown', (event) => {
862
+ event.stopPropagation();
863
+ closeDoors();
864
+ onJumpDoor(door);
865
+ });
866
+ }
867
+ },
868
+
869
+ // `people` is the People list's rows, [{ key, playerId, userId, username,
870
+ // mark, where, actions }] (`mark` a sign before the name, `actions`
871
+ // [{ id, text }], the first drawn beside the name), or null for no People
872
+ // button; `party` is the line over them for a player in a party.
873
+ setPeople(people, party = null) {
874
+ const show = Array.isArray(people) && people.length > 0;
875
+ peopleButton.style.display = show ? 'block' : 'none';
876
+ if (!show) {
877
+ closePeople();
878
+ peopleKey = '';
879
+ return;
880
+ }
881
+ const label = `People · ${people.length}`;
882
+ if (peopleButton.textContent !== label) {
883
+ peopleButton.textContent = label;
884
+ }
885
+ const key = `${party ?? ''}#${people.map((p) => `${p.key}:${p.username ?? ''}:${p.mark ?? ''}:${(p.actions ?? []).map((a) => a.text).join(',')}:${p.door ?? ''}:${p.where ? 1 : 0}`).join('|')}`;
886
+ if (key !== peopleKey) {
887
+ peopleKey = key;
888
+ peopleList.replaceChildren();
889
+ peopleRows.clear();
890
+ if (party) {
891
+ // The player's party: how many, and the way out of it.
892
+ const head = el('div', { display: 'flex', alignItems: 'center', gap: '8px', paddingBottom: '4px', borderBottom: '1px solid rgba(255,255,255,0.18)' }, peopleList);
893
+ el('div', { flex: '1', fontSize: '12px', opacity: '0.8' }, head).textContent = party;
894
+ smallButton(head, 'Leave party', false).addEventListener('pointerdown', (event) => {
895
+ event.stopPropagation();
896
+ onLeaveParty();
897
+ });
898
+ }
899
+ for (const person of people) {
900
+ peopleRows.set(person.key, personRow(person));
901
+ }
902
+ return;
903
+ }
904
+ for (const person of people) {
905
+ if (person.where) {
906
+ peopleRows.get(person.key)?.setWhere(person.where);
907
+ }
908
+ }
909
+ },
910
+ // `items` is [{ id, x, y, text, angle }] in CSS pixels; `angle` (radians
911
+ // on screen) is the way an edge chip's arrow points, null for a chip over
912
+ // the friend themself. Anything not listed is removed.
913
+ setPointers(items) {
914
+ const seen = new Set();
915
+ for (const item of items) {
916
+ seen.add(item.id);
917
+ let node = pointerNodes.get(item.id);
918
+ if (!node) {
919
+ const chip = el('div', { position: 'absolute', display: 'flex', alignItems: 'center', gap: '4px', padding: '2px 8px', borderRadius: '10px', background: 'rgba(233,196,143,0.92)', color: '#2b2118', font: '700 11px/1.3 system-ui, sans-serif', whiteSpace: 'nowrap', boxShadow: '0 1px 4px rgba(0,0,0,0.4)' }, pointers);
920
+ const arrow = el('span', { display: 'inline-block', fontSize: '10px' }, chip);
921
+ arrow.textContent = '➤';
922
+ const words = el('span', {}, chip);
923
+ node = { chip, arrow, words };
924
+ pointerNodes.set(item.id, node);
925
+ }
926
+ const edge = item.angle !== null && item.angle !== undefined;
927
+ node.arrow.style.display = edge ? 'inline-block' : 'none';
928
+ if (edge) {
929
+ node.arrow.style.transform = `rotate(${item.angle}rad)`;
930
+ }
931
+ if (node.words.textContent !== item.text) {
932
+ node.words.textContent = item.text;
933
+ }
934
+ // Kept whole on screen; over a friend it sits above their head.
935
+ const half = node.chip.offsetWidth / 2;
936
+ const x = Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6);
937
+ node.chip.style.transform = edge ? 'translate(-50%, -50%)' : 'translate(-50%, -100%)';
938
+ node.chip.style.left = `${x}px`;
939
+ node.chip.style.top = `${item.y}px`;
940
+ }
941
+ for (const [id, node] of pointerNodes) {
942
+ if (!seen.has(id)) {
943
+ node.chip.remove();
944
+ pointerNodes.delete(id);
945
+ }
946
+ }
947
+ },
948
+ // `ask` is { key, text, yes, no } (the words and the two buttons'), or
949
+ // null for none; an answer goes to `onAsk(ask, true | false)`.
950
+ setAsk(ask) {
951
+ askNow = ask;
952
+ askCard.style.display = ask ? 'flex' : 'none';
953
+ if (!ask || ask.key === askKey) {
954
+ return;
955
+ }
956
+ askKey = ask.key;
957
+ askCard.replaceChildren();
958
+ el('div', { flex: '1', minWidth: '0', fontWeight: '600' }, askCard).textContent = ask.text;
959
+ for (const [text, answer] of [[ask.yes, true], [ask.no, false]]) {
960
+ smallButton(askCard, text, answer).addEventListener('pointerdown', (event) => {
961
+ event.stopPropagation();
962
+ askCard.style.display = 'none';
963
+ onAsk(askNow, answer);
964
+ });
965
+ }
966
+ },
967
+ // The invite button for the player stood beside (`text` its words), or
968
+ // null to hide it; a press calls `handler`.
969
+ nearPrompt(text, handler) {
970
+ // Never over an open card or list: it sits where the speech card's field is.
971
+ const show = Boolean(text) && !sayOpen && !emotesOpen && !peopleOpen && !doorsOpen;
972
+ nearButton.style.display = show ? 'block' : 'none';
973
+ if (text) {
974
+ nearHandler = handler;
975
+ if (nearButton.textContent !== text) {
976
+ nearButton.textContent = text;
977
+ }
978
+ }
979
+ },
980
+ // Whether the People list is open (its rows' places are asked for then).
981
+ peopleOpen: () => peopleOpen,
982
+ setStats(text) {
983
+ stats.style.display = text ? 'block' : 'none';
984
+ if (stats.textContent !== text) {
985
+ stats.textContent = text;
986
+ }
987
+ },
988
+ dispose() {
989
+ unguardKeys();
990
+ desktopQuery?.removeEventListener?.('change', layoutPanel);
991
+ root.remove();
992
+ },
993
+ };
994
+ }
995
+
996
+ // Black or white, whichever reads on a `#rrggbb` background.
997
+ function readableOn(color) {
998
+ const n = parseInt(color.slice(1), 16);
999
+ const lum = 0.299 * ((n >> 16) & 255) + 0.587 * ((n >> 8) & 255) + 0.114 * (n & 255);
1000
+ return lum > 150 ? '#14110f' : '#ffffff';
1001
+ }