castle-web-cli 0.4.237 → 0.4.239

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 (239) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +133 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +21 -0
  14. package/dist/init.js +2 -1
  15. package/dist/multiplayerDoc.d.ts +1 -1
  16. package/dist/multiplayerDoc.js +9 -0
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.d.ts +1 -0
  19. package/dist/playPagePolicy.js +8 -3
  20. package/dist/roomLogs.d.ts +39 -0
  21. package/dist/roomLogs.js +166 -0
  22. package/dist/save-deck.js +4 -0
  23. package/kits/base/CLAUDE.md +1 -0
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +113 -2
  26. package/kits/base/sdk/castle.d.ts +6 -2
  27. package/kits/base/sdk/castle.js +2 -0
  28. package/kits/base/sdk/commands.d.ts +56 -1
  29. package/kits/base/sdk/commands.js +29 -1
  30. package/kits/base/sdk/hub.d.ts +17 -0
  31. package/kits/base/sdk/hub.js +33 -9
  32. package/kits/base/sdk/localCache.d.ts +27 -0
  33. package/kits/base/sdk/localCache.js +115 -0
  34. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  35. package/kits/base/sdk/localCacheStore.js +358 -0
  36. package/kits/base/sdk/multiplayer.js +30 -0
  37. package/kits/base/sdk/rooms.d.ts +11 -0
  38. package/kits/base/sdk/rooms.js +22 -0
  39. package/kits/base/sdk/store.d.ts +8 -2
  40. package/kits/base/sdk/store.js +5 -1
  41. package/kits/base/sdk/transport.d.ts +1 -0
  42. package/kits/base/sdk/transport.js +4 -5
  43. package/kits/hub-game/CLAUDE.md +22 -2
  44. package/kits/hub-game/castle.json +8 -5
  45. package/kits/hub-game/code/client/act.js +66 -91
  46. package/kits/hub-game/code/client/actCore.js +134 -0
  47. package/kits/hub-game/code/client/car.js +35 -0
  48. package/kits/hub-game/code/client/chrome.js +208 -381
  49. package/kits/hub-game/code/client/crowdNames.js +2 -2
  50. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  51. package/kits/hub-game/code/client/hats.js +2 -0
  52. package/kits/hub-game/code/client/hookLayer.js +99 -48
  53. package/kits/hub-game/code/client/hostGo.js +77 -0
  54. package/kits/hub-game/code/client/hubControls.js +125 -0
  55. package/kits/hub-game/code/client/hubEntry.js +187 -0
  56. package/kits/hub-game/code/client/hudSurface.js +148 -0
  57. package/kits/hub-game/code/client/hudTree.js +96 -0
  58. package/kits/hub-game/code/client/idle.js +59 -13
  59. package/kits/hub-game/code/client/invites.js +13 -4
  60. package/kits/hub-game/code/client/menuIcons.js +8 -0
  61. package/kits/hub-game/code/client/menuRows.js +8 -2
  62. package/kits/hub-game/code/client/noTrips.js +38 -0
  63. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  64. package/kits/hub-game/code/client/rehello.js +3 -1
  65. package/kits/hub-game/code/client/riders.js +26 -0
  66. package/kits/hub-game/code/client/role.js +79 -0
  67. package/kits/hub-game/code/client/safeLayout.js +32 -3
  68. package/kits/hub-game/code/client/sound.js +10 -3
  69. package/kits/hub-game/code/client/soundscape.js +2 -2
  70. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  71. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  72. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  73. package/kits/hub-game/code/client/state.js +19 -0
  74. package/kits/hub-game/code/client/stuck.js +2 -1
  75. package/kits/hub-game/code/client/talkSurface.js +178 -0
  76. package/kits/hub-game/code/client/talkTree.js +238 -0
  77. package/kits/hub-game/code/client/tiers.js +8 -5
  78. package/kits/hub-game/code/client/uiDom.js +600 -0
  79. package/kits/hub-game/code/client/uiTree.js +359 -0
  80. package/kits/hub-game/code/client/vehicle.js +156 -0
  81. package/kits/hub-game/code/client/wear.js +27 -5
  82. package/kits/hub-game/code/client/worldLabels.js +13 -3
  83. package/kits/hub-game/code/client/yours.js +10 -3
  84. package/kits/hub-game/code/server/actors.js +4 -3
  85. package/kits/hub-game/code/server/analytics.js +61 -18
  86. package/kits/hub-game/code/server/decor.js +56 -16
  87. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  88. package/kits/hub-game/code/server/hub.js +261 -46
  89. package/kits/hub-game/code/server/idle.js +118 -5
  90. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  91. package/kits/hub-game/code/server/manifest.js +46 -4
  92. package/kits/hub-game/code/server/npcs.js +4 -2
  93. package/kits/hub-game/code/server/players.js +3 -0
  94. package/kits/hub-game/code/server/role.js +142 -0
  95. package/kits/hub-game/code/server/standing.js +6 -4
  96. package/kits/hub-game/code/server/trackQueue.js +29 -0
  97. package/kits/hub-game/code/server/vehicle.js +126 -0
  98. package/kits/hub-game/code/shared/car.js +52 -0
  99. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  100. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  101. package/kits/hub-game/code/shared/expression.js +9 -0
  102. package/kits/hub-game/code/systems/hub.js +281 -86
  103. package/kits/hub-game/docs/analytics.md +15 -3
  104. package/kits/hub-game/docs/contract.md +352 -14
  105. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  106. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  107. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  108. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  109. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  110. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  111. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  112. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  113. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  114. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  115. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  116. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  117. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  118. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  119. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  120. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  121. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  122. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  123. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  124. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  125. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  126. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  127. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  128. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  129. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  130. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  131. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  132. package/kits/hub-game/package-lock.json +1 -1
  133. package/kits/hub-game/package.json +1 -1
  134. package/kits/hub-game/scripts/check.mjs +7 -4
  135. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  136. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  137. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  138. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  139. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  140. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  141. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  142. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  143. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  144. package/kits/hub-game/scripts/test-analytics.mjs +100 -6
  145. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  146. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  147. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  148. package/kits/hub-game/scripts/test-car.mjs +43 -0
  149. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  150. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  151. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  152. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  153. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  154. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  155. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  156. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  157. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  158. package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
  159. package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
  160. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  161. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  162. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  163. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  164. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  165. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  166. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  167. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  168. package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
  169. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  170. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  171. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  172. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  173. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  174. package/kits/hub-game/scripts/test-resync.mjs +196 -0
  175. package/kits/hub-game/scripts/test-role-client.mjs +427 -0
  176. package/kits/hub-game/scripts/test-role.mjs +350 -0
  177. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  178. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  179. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  180. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  181. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  182. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  183. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  184. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  185. package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
  186. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  187. package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
  188. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  189. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  190. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  191. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  192. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  193. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
  194. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  195. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  196. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  197. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  198. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
  199. package/kits/multiplayer-3d/castle.json +4 -4
  200. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  201. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  202. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  203. package/kits/multiplayer-3d/package-lock.json +1 -1
  204. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  205. package/kits/physics-3d/CLAUDE.md +1 -1
  206. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  207. package/kits/physics-3d/castle.json +2 -2
  208. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  209. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  210. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  211. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  212. package/kits/physics-3d/engine3d/world3d.js +6 -3
  213. package/kits/physics-3d/package.json +1 -1
  214. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  215. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  216. package/kits/physics-3d/systems/physics3d.js +5 -2
  217. package/kits/real-time/castle.json +2 -2
  218. package/kits/real-time/code/client/messages.js +5 -0
  219. package/kits/real-time/code/server/session.js +28 -1
  220. package/kits/real-time/package-lock.json +1 -1
  221. package/package.json +5 -4
  222. package/vendor/three/LICENSE +21 -0
  223. package/vendor/three/build/three.core.js +58773 -0
  224. package/vendor/three/build/three.module.js +18251 -0
  225. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  226. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  227. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  228. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  229. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  230. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  231. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  232. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  233. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  234. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  235. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  236. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  237. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  238. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  239. package/vendor/three/package.json +134 -0
@@ -0,0 +1,600 @@
1
+ // The web renderer of the hub UI tree (`uiTree.js`): mounts a root's tree
2
+ // into a DOM container and patches it in place. It is keyed: an element is
3
+ // kept for as long as its node keeps its path, so focus, a caret, a scroll
4
+ // position and listeners survive every rebuild, and only what changed is
5
+ // written. Each node's style is turned into the same inline declarations the
6
+ // chrome always wrote (schema §13), so a web page drawn from a tree looks the
7
+ // way it did before trees.
8
+ //
9
+ // Writes are diffed against what this renderer last wrote for a node, not
10
+ // against the element: other code that places a surface by measuring it
11
+ // (`placeToast`, the landscape rail, safeLayout's `!important` overrides, the
12
+ // clear HUD's fitting) keeps its writes until the tree itself changes that
13
+ // declaration. Edges of a node placed with `at.avoid` or `at.rail` are written
14
+ // once, when the node is made, and then left to that code.
15
+ //
16
+ // A root's own node is not drawn: its children go into the container (or into
17
+ // `slots[key]`: an element to mount that child into instead, or null to leave
18
+ // that child to someone else). Children of the root are appended when made
19
+ // and never moved after, so the host may place them in its own stacking
20
+ // order.
21
+ import { BARE_TEXT_SHADOW, FONTS, SHADOWS, TEXT_SHADOWS, color, keyOf, readClock, segment } from './uiTree.js';
22
+
23
+ const MAX_SCROLL = Number.MAX_SAFE_INTEGER;
24
+ const EDGE_KEYS = new Set(['top', 'right', 'bottom', 'left', 'transform']);
25
+ const BLOCK_TYPES = new Set(['text', 'column', 'row', 'stack', 'spacer', 'scroll', 'grid']);
26
+ // The typing dots' keyframes (v1.46); reduced motion keeps a plain ellipsis.
27
+ const ACTIVITY_CSS = `
28
+ @keyframes hub-npc-dot { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
29
+ .hub-npc-typing span { animation: hub-npc-dot 1.2s infinite; }
30
+ .hub-npc-typing span:nth-child(2) { animation-delay: .2s; }
31
+ .hub-npc-typing span:nth-child(3) { animation-delay: .4s; }
32
+ @media (prefers-reduced-motion: reduce) {
33
+ .hub-npc-typing span { animation: none; display: none; }
34
+ .hub-npc-typing::after { content: '…'; }
35
+ }
36
+ `;
37
+
38
+ const px = (n) => (n === 0 ? '0' : `${n}px`);
39
+ const SIDES = { t: 'top', r: 'right', b: 'bottom', l: 'left' };
40
+ const env = (side) => `env(safe-area-inset-${SIDES[side] ?? side})`;
41
+
42
+ // An edge E: n px from the view's edge, or [min, add] = max(min, inset + add).
43
+ export function edgeCss(value, side) {
44
+ if (Array.isArray(value)) {
45
+ const [min, add = 0] = value;
46
+ return add ? `max(${min}px, calc(${env(side)} + ${add}px))` : `max(${min}px, ${env(side)})`;
47
+ }
48
+ return typeof value === 'number' ? px(value) : String(value);
49
+ }
50
+ // A Len term: { vw?, vh?, dvh?, px?, safe?: 'tblr', sub?: { l: 16 } } or
51
+ // { max: [terms] }; a Len is a number, a term, or an array whose minimum is
52
+ // taken. One term is written bare.
53
+ function termCss(term) {
54
+ if (typeof term === 'number') {return px(term);}
55
+ if (typeof term === 'string') {return term;}
56
+ if (Array.isArray(term.max)) {return `max(${term.max.map(termCss).join(', ')})`;}
57
+ const parts = [];
58
+ for (const unit of ['vw', 'vh', 'dvh']) {
59
+ if (term[unit]) {parts.push(`${term[unit]}${unit}`);}
60
+ }
61
+ const minus = [];
62
+ if (term.px) {(term.px < 0 ? minus : parts).push(px(Math.abs(term.px)));}
63
+ for (const side of String(term.safe ?? '')) {minus.push(env(side));}
64
+ for (const [side, min] of Object.entries(term.sub ?? {})) {minus.push(`max(${min}px, ${env(side)})`);}
65
+ if (!parts.length && !minus.length) {return '0px';}
66
+ if (parts.length === 1 && !minus.length) {return parts[0];}
67
+ return `calc(${[parts.join(' + ') || '0px', ...minus].join(' - ')})`;
68
+ }
69
+ export function lenCss(value) {
70
+ if (value === 'fill') {return '100%';}
71
+ if (value === 'wrap') {return 'max-content';}
72
+ if (typeof value === 'string') {return value;}
73
+ if (Array.isArray(value)) {return value.length === 1 ? termCss(value[0]) : `min(${value.map(termCss).join(', ')})`;}
74
+ return termCss(value);
75
+ }
76
+ const boxCss = (value) => (Array.isArray(value) ? value.map((n) => (typeof n === 'number' ? px(n) : n)).join(' ') : typeof value === 'number' ? px(value) : value);
77
+ const ALIGN = { start: 'flex-start', end: 'flex-end', center: 'center', stretch: 'stretch', baseline: 'baseline' };
78
+ const JUSTIFY = { start: 'flex-start', end: 'flex-end', center: 'center', between: 'space-between' };
79
+ const TALIGN = { start: 'left', center: 'center', end: 'right' };
80
+ function colsCss(cols) {
81
+ if (typeof cols === 'number') {return `repeat(${cols}, minmax(0, 1fr))`;}
82
+ if (Array.isArray(cols)) {return cols.map((c) => (typeof c === 'number' ? `minmax(0, ${c}fr)` : c)).join(' ');}
83
+ if (cols?.px) {return `repeat(${cols.n}, ${cols.px}px)`;}
84
+ if (cols?.min) {return `repeat(auto-fill, minmax(${cols.min}px, 1fr))`;}
85
+ return '';
86
+ }
87
+ const isSpanParent = (type) => type === 'row' || type === 'grid';
88
+ const tagFor = (node, parentType) => (node.t === 'button' ? 'button' : node.t === 'field' ? 'input' : node.t === 'image' ? 'img'
89
+ : node.t === 'text' && isSpanParent(parentType) && !node.at ? 'span' : 'div');
90
+ // A first child that is only words is drawn as its parent's own text, the way
91
+ // the chrome wrote `node.textContent` (a button's label, a talk line).
92
+ const bare = (node) => node?.t === 'text' && !node.s && !node.at && !node.hub && !node.label && !node.role && !node.data && !node.on && !node.clock;
93
+
94
+ // The declarations for one node, in write order (a `font` shorthand first).
95
+ // `inherited` carries the text size and line height from above, for the
96
+ // two-line clip.
97
+ export function cssFor(node, parentType, inherited = {}) {
98
+ const s = node.s ?? {};
99
+ const t = node.t;
100
+ const css = {};
101
+ if (t === 'button' || t === 'field') {css.font = 'inherit';}
102
+ if (t === 'button') {Object.assign(css, { color: 'inherit', cursor: 'pointer', border: 'none', background: 'transparent', padding: '0' });}
103
+ if (node.at) {
104
+ const at = node.at;
105
+ css.position = 'absolute';
106
+ for (const side of ['top', 'right', 'bottom', 'left']) {
107
+ if (at[side] !== undefined && at[side] !== null) {css[side] = edgeCss(at[side], side);}
108
+ }
109
+ const centred = ['top', 'bottom', 'center'].includes(at.anchor) && (at.left === undefined || at.right === undefined);
110
+ if (centred) {
111
+ css.left = '50%';
112
+ css.transform = at.anchor === 'center' ? 'translate(-50%, -50%)' : 'translateX(-50%)';
113
+ }
114
+ if (at.anchor === 'fill') {css.inset = '0';}
115
+ if (at.z) {css.zIndex = String(at.z);}
116
+ } else if (t === 'stack') {
117
+ css.position = 'relative';
118
+ }
119
+ // A column with no gap or alignment of its own, holding only block
120
+ // nodes, stacks them the same way as a block box: it is drawn as one, as
121
+ // the chrome's HUD block always was.
122
+ const blockColumn = t === 'column' && s.gap === undefined && !s.align && !s.justify &&
123
+ (node.c ?? []).every((child) => BLOCK_TYPES.has(child.t));
124
+ const flexBox = blockColumn ? undefined : { column: 'flex', row: 'flex', scroll: 'flex', grid: 'grid', activity: 'flex' }[t];
125
+ if (s.gone) {css.display = 'none';}
126
+ else if (flexBox) {css.display = flexBox;}
127
+ else if (blockColumn || (t === 'text' && !isSpanParent(parentType)) || t === 'stack' || t === 'spacer' || (t === 'button' && node.at)) {css.display = 'block';}
128
+ if ((t === 'column' && !blockColumn) || (t === 'scroll' && node.axis !== 'x')) {css.flexDirection = 'column';}
129
+ if (t === 'scroll') {css[node.axis === 'x' ? 'overflowX' : 'overflowY'] = 'auto';}
130
+ if (t === 'grid') {css.gridTemplateColumns = colsCss(node.cols);}
131
+ if (s.box) {css.boxSizing = s.box === 'border' ? 'border-box' : 'content-box';}
132
+ for (const [key, prop] of [['w', 'width'], ['h', 'height'], ['minW', 'minWidth'], ['minH', 'minHeight'], ['maxW', 'maxWidth'], ['maxH', 'maxHeight']]) {
133
+ if (s[key] !== undefined) {css[prop] = lenCss(s[key]);}
134
+ }
135
+ if (s.self) {
136
+ if (s.self === 'center' && s.w === 'wrap') {css.margin = `${s.mt ? px(s.mt) : '0'} auto${s.mt ? ' 0' : ''}`;}
137
+ else {css.alignSelf = ALIGN[s.self];}
138
+ }
139
+ if (s.mt && !css.margin) {css.marginTop = px(s.mt);}
140
+ if (s.pad !== undefined) {css.padding = boxCss(s.pad);}
141
+ if (s.gap !== undefined) {css.gap = px(s.gap);}
142
+ if (s.flex !== undefined) {css.flex = String(s.flex);}
143
+ if (s.basis === '100%') {Object.assign(css, { flexBasis: '100%', gridColumn: '1 / -1' });}
144
+ if (s.align) {css.alignItems = ALIGN[s.align];}
145
+ if (s.justify) {css.justifyContent = JUSTIFY[s.justify];}
146
+ if (s.wrap === true) {css.flexWrap = 'wrap';}
147
+ // Paint.
148
+ if (s.bg !== undefined) {css.background = color(s.bg);}
149
+ if (s.radius !== undefined) {css.borderRadius = boxCss(s.radius);}
150
+ 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
+ if (s.shadow) {css.boxShadow = SHADOWS[s.shadow] ?? s.shadow;}
152
+ if (s.opacity !== undefined) {css.opacity = String(s.opacity);}
153
+ if (s.gray) {css.filter = 'grayscale(1)';}
154
+ if (s.clip !== undefined) {css.overflow = s.clip ? 'hidden' : 'visible';}
155
+ if (s.hidden) {css.visibility = 'hidden';}
156
+ const hit = s.hit ?? (t === 'button' || t === 'field' ? 'auto' : undefined);
157
+ if (hit) {css.pointerEvents = hit;}
158
+ if (t === 'button' && (node.on?.press || node.on?.release)) {Object.assign(css, { touchAction: 'none', userSelect: 'none' });}
159
+ // Text.
160
+ if (s.color !== undefined) {css.color = color(s.color);}
161
+ if (s.font) {css.fontFamily = FONTS[s.font] ?? s.font;}
162
+ if (s.size !== undefined) {css.fontSize = px(s.size);}
163
+ if (s.weight !== undefined) {css.fontWeight = String(s.weight);}
164
+ if (s.lh !== undefined) {css.lineHeight = String(s.lh);}
165
+ if (s.ls !== undefined) {css.letterSpacing = `${s.ls}em`;}
166
+ if (s.italic) {css.fontStyle = 'italic';}
167
+ if (s.upper) {css.textTransform = 'uppercase';}
168
+ if (s.tabular) {css.fontVariantNumeric = 'tabular-nums';}
169
+ if (s.talign) {css.textAlign = TALIGN[s.talign] ?? s.talign;}
170
+ for (const wrap of [].concat(s.wrap ?? [])) {
171
+ if (wrap === 'anywhere') {css.overflowWrap = 'anywhere';}
172
+ else if (wrap === 'none') {css.whiteSpace = 'nowrap';}
173
+ else if (wrap === 'word') {css.whiteSpace = 'normal';}
174
+ }
175
+ if (s.tshadow) {css.textShadow = s.tshadow === 'outline' ? BARE_TEXT_SHADOW : TEXT_SHADOWS[s.tshadow] ?? s.tshadow;}
176
+ if (s.lines === 1 && s.ellipsis !== false) {Object.assign(css, { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' });}
177
+ else if (s.lines > 0 && s.ellipsis === false) {
178
+ // n lines of this size and line height, plus the padding: hard clipped.
179
+ const size = s.size ?? inherited.size ?? 15;
180
+ 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);
182
+ Object.assign(css, { maxHeight: px(Number((s.lines * size * lh + pad).toFixed(2))), overflow: 'hidden' });
183
+ } else if (s.lines > 1) {
184
+ Object.assign(css, { display: '-webkit-box', webkitLineClamp: String(s.lines), webkitBoxOrient: 'vertical', overflow: 'hidden' });
185
+ }
186
+ return css;
187
+ }
188
+
189
+ const defaultMeasure = {
190
+ scroll: (el) => ({ height: el.scrollHeight, top: el.scrollTop, client: el.clientHeight }),
191
+ offsets: (el) => ({ left: el.offsetLeft ?? 0, top: el.offsetTop ?? 0 }),
192
+ active: () => false,
193
+ };
194
+
195
+ // container: where the root's children go. slots: { key: Element | null }.
196
+ // created(path, element, node) / removed(path, element): the host's hooks,
197
+ // called once a node and its children are drawn / once it is taken out
198
+ // (the chrome registers its layout geometry there). measure: { scroll,
199
+ // offsets, active } for the scroll rules (the chrome passes its per-frame
200
+ // layout cache, so a rule reads the frame's snapshot like the rest of it).
201
+ // clockNow: the simulation time, in seconds, every `clock` is read at (its
202
+ // `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 } = {}) {
204
+ const byPath = new Map();
205
+ // The records drawing a clock, ticked by `tick()`.
206
+ const clocks = new Set();
207
+ const top = { kids: new Map(), el: container, root: true };
208
+ let styled = null;
209
+ // Work that waits for the whole root: the scroll rules.
210
+ let after = [];
211
+ let rootPath = '';
212
+
213
+ function ensureActivityStyle() {
214
+ if (styled) {return;}
215
+ styled = document.createElement('style');
216
+ styled.textContent = ACTIVITY_CSS;
217
+ container.appendChild(styled);
218
+ }
219
+
220
+ function drop(rec, path) {
221
+ for (const [key, kid] of rec.kids) {drop(kid, `${path}/${segment(key)}`);}
222
+ rec.kids.clear();
223
+ rec.el.remove();
224
+ clocks.delete(rec);
225
+ byPath.delete(path);
226
+ removed(path, rec.el);
227
+ }
228
+
229
+ function listen(rec, type, fn) {
230
+ if (rec.listening.has(type)) {return;}
231
+ rec.listening.add(type);
232
+ rec.el.addEventListener(type, fn);
233
+ }
234
+ const fire = (rec, event, payload) => {
235
+ const fn = rec.node.on?.[event];
236
+ if (typeof fn === 'function') {fn(payload);}
237
+ };
238
+
239
+ function wireEvents(rec, node) {
240
+ const on = node.on ?? {};
241
+ const t = node.t;
242
+ if (t === 'button') {
243
+ // Touch is always the button's: the scene under it never sees the press.
244
+ listen(rec, 'pointerdown', (event) => {
245
+ const current = rec.node;
246
+ const holds = current.on?.press || current.on?.release;
247
+ if (holds || current.keepFocus) {event.preventDefault?.();}
248
+ event.stopPropagation?.();
249
+ if (holds) {
250
+ rec.el.setPointerCapture?.(event.pointerId);
251
+ fire(rec, 'press', { pointerId: event.pointerId });
252
+ } else if (current.fire === 'down' && !current.disabled) {
253
+ fire(rec, 'tap', {});
254
+ }
255
+ });
256
+ if (on.press || on.release || on.cancel) {
257
+ for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
258
+ listen(rec, type, (event) => {
259
+ if (!(rec.node.on?.press || rec.node.on?.release)) {return;}
260
+ event.preventDefault?.();
261
+ event.stopPropagation?.();
262
+ fire(rec, type === 'pointerup' ? 'release' : 'cancel', { pointerId: event.pointerId });
263
+ });
264
+ }
265
+ }
266
+ if (on.tap && node.fire !== 'down') {
267
+ listen(rec, 'click', (event) => {
268
+ if (rec.node.fire === 'down') {return;}
269
+ event.preventDefault?.();
270
+ fire(rec, 'tap', {});
271
+ });
272
+ }
273
+ return;
274
+ }
275
+ if (t === 'field') {
276
+ for (const type of ['keydown', 'keyup', 'keypress']) {
277
+ listen(rec, type, (event) => event.stopPropagation?.());
278
+ }
279
+ if (rec.listening.has('input')) {return;}
280
+ rec.el.addEventListener('keydown', (event) => {
281
+ // An IME's own Enter (confirm) or Escape (cancel) belongs to the
282
+ // candidate; WebKit reports the confirming Enter as keyCode 229 with
283
+ // isComposing false.
284
+ if (event.isComposing || event.keyCode === 229) {return;}
285
+ if (event.key === 'Enter') {
286
+ event.preventDefault?.();
287
+ fire(rec, 'submit', { text: rec.el.value, base: rec.ver });
288
+ } else if (event.key === 'Escape') {
289
+ event.preventDefault?.();
290
+ fire(rec, 'cancel', {});
291
+ }
292
+ });
293
+ listen(rec, 'input', (event) => fire(rec, 'input', { text: rec.el.value, base: rec.ver, composing: Boolean(event?.isComposing) }));
294
+ listen(rec, 'focus', () => fire(rec, 'focus', {}));
295
+ listen(rec, 'blur', () => fire(rec, 'blur', {}));
296
+ return;
297
+ }
298
+ if (node.s?.hit === 'auto') {
299
+ listen(rec, 'pointerdown', (event) => event.stopPropagation?.());
300
+ }
301
+ }
302
+
303
+ // A declaration someone else wrote over this renderer's (a measured
304
+ // placement, a test's prior value) is kept aside when the tree moves away
305
+ // from the value it overrode, and put back when the tree returns to it, as
306
+ // the chrome's temporary styles (a wrapping toast) always restored them.
307
+ function writeStyle(rec, key, value) {
308
+ const style = rec.el.style;
309
+ const mine = rec.css[key] ?? '';
310
+ const current = style[key] ?? '';
311
+ const aside = rec.foreign[key];
312
+ if (aside && aside.base === (value ?? '')) {
313
+ style[key] = aside.value;
314
+ delete rec.foreign[key];
315
+ return;
316
+ }
317
+ if (current !== mine && !aside) {rec.foreign[key] = { value: current, base: mine };}
318
+ style[key] = value ?? '';
319
+ }
320
+ function writeStyles(rec, css, fresh) {
321
+ const keepEdges = !fresh && (rec.node.at?.avoid || rec.node.at?.rail);
322
+ for (const [key, value] of Object.entries(css)) {
323
+ if (keepEdges && EDGE_KEYS.has(key)) {continue;}
324
+ if (rec.css[key] !== value) {writeStyle(rec, key, value);}
325
+ }
326
+ for (const key of Object.keys(rec.css)) {
327
+ if (!(key in css) && !(keepEdges && EDGE_KEYS.has(key))) {writeStyle(rec, key, '');}
328
+ }
329
+ rec.css = keepEdges ? { ...css, ...Object.fromEntries(Object.entries(rec.css).filter(([key]) => EDGE_KEYS.has(key))) } : css;
330
+ }
331
+
332
+ function writeAttrs(rec, node) {
333
+ const el = rec.el;
334
+ const attrs = { 'aria-label': node.label, role: node.role, 'aria-pressed': node.pressed === undefined ? undefined : String(node.pressed) };
335
+ for (const [name, value] of Object.entries(attrs)) {
336
+ if (rec.attrs[name] === value) {continue;}
337
+ if (value === undefined || value === null) {el.removeAttribute?.(name);} else {el.setAttribute(name, value);}
338
+ rec.attrs[name] = value;
339
+ }
340
+ const data = { ...(node.hub ? { hub: node.hub } : {}), ...node.data };
341
+ for (const [name, value] of Object.entries(data)) {
342
+ if (el.dataset[name] !== value) {el.dataset[name] = value;}
343
+ }
344
+ for (const name of Object.keys(rec.data)) {
345
+ if (!(name in data)) {delete el.dataset[name];}
346
+ }
347
+ rec.data = data;
348
+ }
349
+
350
+ function setText(el, value, hasElements) {
351
+ if (!hasElements) {
352
+ if (el.textContent !== value) {el.textContent = value;}
353
+ return;
354
+ }
355
+ const first = el.firstChild;
356
+ if (first && first.nodeType === 3) {
357
+ if (first.data !== value) {first.data = value;}
358
+ } else if (typeof document.createTextNode === 'function') {
359
+ if (value) {el.insertBefore(document.createTextNode(value), first ?? null);}
360
+ } else if (el.textContent !== value) {
361
+ // Stand-in DOMs keep their text apart from their children.
362
+ el.textContent = value;
363
+ }
364
+ }
365
+
366
+ function patchField(rec, node, fresh) {
367
+ const el = rec.el;
368
+ if (fresh) {
369
+ el.type = 'text';
370
+ el.autocomplete = 'off';
371
+ el.inputMode = 'text';
372
+ }
373
+ const props = { name: node.name, maxLength: node.max, placeholder: node.ph, enterKeyHint: node.enter, disabled: Boolean(node.disabled), spellcheck: node.spell };
374
+ for (const [name, value] of Object.entries(props)) {
375
+ if (value !== undefined && rec.props[name] !== value) {el[name] = value; rec.props[name] = value;}
376
+ }
377
+ if (node.cap && rec.props.cap !== node.cap) {el.setAttribute('autocapitalize', node.cap); rec.props.cap = node.cap;}
378
+ if (node.correct === false && rec.props.correct !== false) {el.setAttribute('autocorrect', 'off'); rec.props.correct = false;}
379
+ // Controlled, with a version: the value is adopted only when the version
380
+ // moves, so a rebuild never moves the caret or drops a composing word.
381
+ const ver = Number(node.ver ?? 0);
382
+ if (fresh || ver > rec.ver) {
383
+ if (el.value !== (node.value ?? '')) {el.value = node.value ?? '';}
384
+ rec.ver = ver;
385
+ }
386
+ // Focus is a request counter: up focuses, a negative count blurs.
387
+ const focus = Number(node.focus ?? 0);
388
+ if (!fresh && focus !== rec.focus) {
389
+ if (focus > 0 && focus > rec.focus) {el.focus?.({ preventScroll: true });}
390
+ else if (focus < 0) {el.blur?.();}
391
+ }
392
+ rec.focus = focus;
393
+ }
394
+
395
+ function patchActivity(rec, node, fresh) {
396
+ if (!fresh) {return;}
397
+ ensureActivityStyle();
398
+ if (node.kind === 'spinner') {
399
+ rec.el.className = 'hub-loading-spin';
400
+ return;
401
+ }
402
+ rec.el.className = 'hub-npc-typing';
403
+ for (let i = 0; i < 3; i += 1) {
404
+ const dot = document.createElement('span');
405
+ dot.textContent = '•';
406
+ rec.el.appendChild(dot);
407
+ }
408
+ }
409
+
410
+ // The scroll rules: a key's first appearance can scroll to the end, or put
411
+ // that child's top at the top when the viewer was at the end ('top'), or
412
+ // keep a viewer at the end at the end ('stick'). A viewer who scrolled up
413
+ // is left there. `refollow` re-applies the last alignment when the viewer
414
+ // has not moved since (chips arriving under a reply).
415
+ function followScroll(rec, node, before, made) {
416
+ const el = rec.el;
417
+ const follow = rec.follow ??= { line: null, scroll: 0, snapshot: null };
418
+ for (const rule of [].concat(node.follow ?? [])) {
419
+ const kid = rec.kids.get(rule.key);
420
+ if (!kid || !made.has(rule.key)) {continue;}
421
+ const atEnd = before.height - before.top - before.client <= (rule.endPx ?? 8);
422
+ if (rule.mode === 'stick') {
423
+ if (atEnd) {el.scrollTop = measure.active() ? MAX_SCROLL : measure.scroll(el).height;}
424
+ continue;
425
+ }
426
+ let top = before.top;
427
+ if (rule.mode === 'end') {
428
+ top = measure.active() ? MAX_SCROLL : measure.scroll(el).height;
429
+ el.scrollTop = top;
430
+ } else if (atEnd) {
431
+ top = measure.offsets(kid.el).top - measure.offsets(el).top;
432
+ el.scrollTop = top;
433
+ }
434
+ follow.line = rule.mode === 'end' || atEnd ? kid.el : null;
435
+ follow.scroll = measure.active() ? top : el.scrollTop;
436
+ follow.snapshot = measure.active() ? before : null;
437
+ }
438
+ if (node.refollow !== undefined && rec.refollow !== undefined && node.refollow !== rec.refollow) {
439
+ refollow(rec);
440
+ }
441
+ rec.refollow = node.refollow;
442
+ }
443
+ function refollow(rec) {
444
+ const el = rec.el;
445
+ const follow = rec.follow;
446
+ if (!follow?.line?.isConnected) {return;}
447
+ const scroll = measure.scroll(el);
448
+ // An in-frame write stores the requested top; a later snapshot has the
449
+ // browser's clamped position. This frame's snapshot predates that write.
450
+ const expected = follow.snapshot ? Math.max(0, Math.min(follow.scroll, scroll.height - scroll.client)) : follow.scroll;
451
+ if (scroll !== follow.snapshot && Math.abs(scroll.top - expected) > 1) {return;}
452
+ const top = measure.offsets(follow.line).top - measure.offsets(el).top;
453
+ el.scrollTop = top;
454
+ follow.scroll = measure.active() ? top : el.scrollTop;
455
+ follow.snapshot = measure.active() ? scroll : null;
456
+ }
457
+
458
+ // A clock's node as drawn now: below its warning mark, the warning's style
459
+ // over the node's own.
460
+ const clockNode = (node, warn) => (warn ? { ...node, s: { ...node.s, ...node.clock.warn.s } } : node);
461
+ // A text with a clock: read at the simulation time now. Clocks are
462
+ // absolute, so nothing about when it was drawn is kept.
463
+ function startClock(rec, clock) {
464
+ const read = readClock(clock, clockNow());
465
+ rec.clock = { spec: clock, warn: read.warn };
466
+ clocks.add(rec);
467
+ return read;
468
+ }
469
+ function tickClock(rec) {
470
+ const read = readClock(rec.clock.spec, clockNow());
471
+ setText(rec.el, read.text, false);
472
+ if (read.warn !== rec.clock.warn) {
473
+ rec.clock.warn = read.warn;
474
+ writeStyles(rec, cssFor(clockNode(rec.node, read.warn), rec.parentType, rec.inherited), false);
475
+ }
476
+ }
477
+
478
+ // Patch one record to its node, then its children.
479
+ function patch(rec, node, path, parentType, inherited, fresh) {
480
+ rec.node = node;
481
+ rec.parentType = parentType;
482
+ rec.inherited = inherited;
483
+ const clock = node.t === 'text' && node.clock ? startClock(rec, node.clock) : null;
484
+ if (!clock && rec.clock) {
485
+ rec.clock = null;
486
+ clocks.delete(rec);
487
+ }
488
+ const css = cssFor(clock ? clockNode(node, clock.warn) : node, parentType, inherited);
489
+ writeStyles(rec, css, fresh);
490
+ writeAttrs(rec, node);
491
+ wireEvents(rec, node);
492
+ if (node.t === 'button') {
493
+ if (fresh) {rec.el.type = 'button';}
494
+ const disabled = Boolean(node.disabled);
495
+ if (rec.el.disabled !== disabled) {rec.el.disabled = disabled;}
496
+ } else if (node.t === 'field') {
497
+ patchField(rec, node, fresh);
498
+ } else if (node.t === 'activity') {
499
+ patchActivity(rec, node, fresh);
500
+ } else if (node.t === 'image') {
501
+ if (fresh) {rec.el.alt = ''; rec.el.draggable = false;}
502
+ if (rec.el.src !== node.src) {rec.el.src = node.src;}
503
+ } else if (node.t === 'text') {
504
+ setText(rec.el, clock ? clock.text : String(node.text ?? ''), false);
505
+ }
506
+ const s = node.s ?? {};
507
+ const scope = { size: s.size ?? inherited.size, lh: s.lh ?? inherited.lh };
508
+ if (node.t === 'scroll') {
509
+ // Read before the children change; scroll once the whole root is
510
+ // drawn (chips under the log change its height after it).
511
+ const before = node.follow || node.refollow !== undefined ? measure.scroll(rec.el) : null;
512
+ const made = children(rec, node, path, scope);
513
+ if (before) {after.push(() => followScroll(rec, node, before, made));}
514
+ } else if (['column', 'row', 'stack', 'grid', 'button'].includes(node.t)) {
515
+ children(rec, node, path, scope);
516
+ }
517
+ }
518
+
519
+ // Reconcile a record's children with a node's: keyed, removed when gone,
520
+ // reordered only when out of order. Returns the keys made this time.
521
+ function children(rec, node, path, inherited) {
522
+ const list = node.c ?? [];
523
+ const lead = !rec.root && bare(list[0]) ? list[0] : null;
524
+ const made = new Set();
525
+ const wanted = new Map();
526
+ const order = [];
527
+ list.forEach((child, i) => {
528
+ if (i === 0 && lead) {return;}
529
+ const key = keyOf(child, i);
530
+ wanted.set(key, child);
531
+ order.push(key);
532
+ });
533
+ for (const [key, kid] of rec.kids) {
534
+ const child = wanted.get(key);
535
+ if (!child || kid.tag !== tagFor(child, node.t)) {
536
+ drop(kid, `${path}/${segment(key)}`);
537
+ rec.kids.delete(key);
538
+ }
539
+ }
540
+ for (const key of order) {
541
+ const child = wanted.get(key);
542
+ const childPath = `${path}/${segment(key)}`;
543
+ let kid = rec.kids.get(key);
544
+ const fresh = !kid;
545
+ if (fresh) {
546
+ const tag = tagFor(child, node.t);
547
+ const target = rec.root ? (Object.hasOwn(slots, key) ? slots[key] : container) : rec.el;
548
+ if (target === null) {continue;}
549
+ kid = { el: document.createElement(tag), tag, kids: new Map(), css: {}, foreign: {}, attrs: {}, data: {}, props: {}, listening: new Set(), ver: -Infinity, focus: 0, node: child };
550
+ rec.kids.set(key, kid);
551
+ byPath.set(childPath, kid);
552
+ target.appendChild(kid.el);
553
+ made.add(key);
554
+ }
555
+ patch(kid, child, childPath, node.t, inherited, fresh);
556
+ if (fresh) {created(childPath, kid.el, child);}
557
+ }
558
+ if (!rec.root) {
559
+ setText(rec.el, lead ? String(lead.text ?? '') : '', order.length > 0);
560
+ // Elements in the wanted order; only misplaced ones move.
561
+ let at = 0;
562
+ for (const key of order) {
563
+ const kid = rec.kids.get(key);
564
+ if (!kid) {continue;}
565
+ const current = rec.el.children[at];
566
+ if (current !== kid.el) {rec.el.insertBefore(kid.el, current ?? null);}
567
+ at += 1;
568
+ }
569
+ }
570
+ return made;
571
+ }
572
+
573
+ return {
574
+ // Draw `tree` (a root node, or null for nothing).
575
+ render(tree) {
576
+ const inherited = { size: tree?.s?.size, lh: tree?.s?.lh };
577
+ rootPath = tree ? segment(keyOf(tree, 0)) : rootPath;
578
+ children(top, tree ?? { t: 'stack', c: [] }, rootPath, inherited);
579
+ const jobs = after;
580
+ after = [];
581
+ for (const job of jobs) {job();}
582
+ },
583
+ // Move every clock on to `clockNow()`: its words, and its warning style
584
+ // as it crosses the mark. The host calls it at its own cadence (the
585
+ // chrome, each HUD frame, as the timer text was always written).
586
+ tick() {
587
+ for (const rec of clocks) {tickClock(rec);}
588
+ },
589
+ // The element drawn for a path (`talk/panel/log`), or null.
590
+ nodeFor: (path) => byPath.get(path)?.el ?? null,
591
+ dispose() {
592
+ for (const [key, kid] of top.kids) {drop(kid, `${rootPath}/${segment(key)}`);}
593
+ top.kids.clear();
594
+ byPath.clear();
595
+ clocks.clear();
596
+ styled?.remove();
597
+ styled = null;
598
+ },
599
+ };
600
+ }