@wardic/solid 2.2.0 → 3.0.0-next.1

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 (541) hide show
  1. package/README.md +39 -18
  2. package/dist/browser/animation-frame.js +1 -1
  3. package/dist/browser/animation-frame.js.map +1 -1
  4. package/dist/browser/config-view.js +35 -6
  5. package/dist/browser/config-view.js.map +1 -1
  6. package/dist/browser/create-batch.js +1 -1
  7. package/dist/browser/diagnostic-codes.js +216 -0
  8. package/dist/browser/diagnostic-codes.js.map +1 -0
  9. package/dist/browser/diagnostics.js +79 -0
  10. package/dist/browser/diagnostics.js.map +1 -0
  11. package/dist/browser/element-style.js +61 -7
  12. package/dist/browser/element-style.js.map +1 -1
  13. package/dist/browser/element.js +24 -6
  14. package/dist/browser/element.js.map +1 -1
  15. package/dist/browser/feature-section.js +5 -13
  16. package/dist/browser/feature-section.js.map +1 -1
  17. package/dist/browser/frame-effect.js +1 -1
  18. package/dist/browser/frame-effect.js.map +1 -1
  19. package/dist/browser/gesture-callbacks.js +1 -1
  20. package/dist/browser/gesture-callbacks.js.map +1 -1
  21. package/dist/browser/hooks/auto.js +270 -0
  22. package/dist/browser/hooks/auto.js.map +1 -0
  23. package/dist/browser/hooks/config-scope.js +120 -0
  24. package/dist/browser/hooks/config-scope.js.map +1 -0
  25. package/dist/browser/hooks/config.js +37 -0
  26. package/dist/browser/hooks/config.js.map +1 -0
  27. package/dist/browser/hooks/drag.js +633 -0
  28. package/dist/browser/hooks/drag.js.map +1 -0
  29. package/dist/browser/hooks/elements.js +183 -0
  30. package/dist/browser/hooks/elements.js.map +1 -0
  31. package/dist/browser/hooks/group.js +28 -0
  32. package/dist/browser/hooks/group.js.map +1 -0
  33. package/dist/browser/hooks/index.js +10 -0
  34. package/dist/browser/hooks/index.js.map +1 -0
  35. package/dist/browser/hooks/kept.js +32 -0
  36. package/dist/browser/hooks/kept.js.map +1 -0
  37. package/dist/browser/hooks/layout-group-of.js +39 -0
  38. package/dist/browser/hooks/layout-group-of.js.map +1 -0
  39. package/dist/browser/hooks/layout-group.js +92 -0
  40. package/dist/browser/hooks/layout-group.js.map +1 -0
  41. package/dist/browser/hooks/make-ward.js +157 -0
  42. package/dist/browser/hooks/make-ward.js.map +1 -0
  43. package/dist/browser/hooks/presence-scope.js +88 -0
  44. package/dist/browser/hooks/presence-scope.js.map +1 -0
  45. package/dist/browser/hooks/presence.js +24 -0
  46. package/dist/browser/hooks/presence.js.map +1 -0
  47. package/dist/browser/hooks/props.js +148 -0
  48. package/dist/browser/hooks/props.js.map +1 -0
  49. package/dist/browser/hooks/reads.js +241 -0
  50. package/dist/browser/hooks/reads.js.map +1 -0
  51. package/dist/browser/hooks/refs.js +87 -0
  52. package/dist/browser/hooks/refs.js.map +1 -0
  53. package/dist/browser/hooks/reorder-elements.js +269 -0
  54. package/dist/browser/hooks/reorder-elements.js.map +1 -0
  55. package/dist/browser/hooks/reorder.js +176 -0
  56. package/dist/browser/hooks/reorder.js.map +1 -0
  57. package/dist/browser/hooks/rune.js +800 -0
  58. package/dist/browser/hooks/rune.js.map +1 -0
  59. package/dist/browser/hooks/server-features.client.js +2 -0
  60. package/dist/browser/hooks/server-features.client.js.map +1 -0
  61. package/dist/browser/hooks/server-features.js +13 -0
  62. package/dist/browser/hooks/server-features.js.map +1 -0
  63. package/dist/browser/hooks/settings.js +29 -0
  64. package/dist/browser/hooks/settings.js.map +1 -0
  65. package/dist/browser/hooks/setup.js +154 -0
  66. package/dist/browser/hooks/setup.js.map +1 -0
  67. package/dist/browser/hooks/stage.js +117 -0
  68. package/dist/browser/hooks/stage.js.map +1 -0
  69. package/dist/browser/hooks/ward.js +2212 -0
  70. package/dist/browser/hooks/ward.js.map +1 -0
  71. package/dist/browser/hooks/wardic-provider.js +29 -0
  72. package/dist/browser/hooks/wardic-provider.js.map +1 -0
  73. package/dist/browser/hooks/wardic-scope.js +68 -0
  74. package/dist/browser/hooks/wardic-scope.js.map +1 -0
  75. package/dist/browser/hooks/wards.js +563 -0
  76. package/dist/browser/hooks/wards.js.map +1 -0
  77. package/dist/browser/index.js +23 -11
  78. package/dist/browser/index.js.map +1 -1
  79. package/dist/browser/layout.js +7 -58
  80. package/dist/browser/layout.js.map +1 -1
  81. package/dist/browser/lazy-batch-gestures.js +1 -1
  82. package/dist/browser/lifecycle.js +37 -0
  83. package/dist/browser/lifecycle.js.map +1 -1
  84. package/dist/browser/presence-handle.js +28 -12
  85. package/dist/browser/presence-handle.js.map +1 -1
  86. package/dist/browser/presence.js +3 -1
  87. package/dist/browser/presence.js.map +1 -1
  88. package/dist/browser/provider.js +124 -90
  89. package/dist/browser/provider.js.map +1 -1
  90. package/dist/browser/reorder-components.js +50 -0
  91. package/dist/browser/reorder-components.js.map +1 -0
  92. package/dist/browser/reorder.js +51 -278
  93. package/dist/browser/reorder.js.map +1 -1
  94. package/dist/browser/runtime.js +26 -15
  95. package/dist/browser/runtime.js.map +1 -1
  96. package/dist/browser/spans-check.js +8 -3
  97. package/dist/browser/spans-check.js.map +1 -1
  98. package/dist/browser/stage.js.map +1 -1
  99. package/dist/browser/unstable/v2/index.js +0 -8
  100. package/dist/browser/unstable/v2/index.js.map +1 -1
  101. package/dist/browser/v1/index.js +1 -1
  102. package/dist/browser/v1/index.js.map +1 -1
  103. package/dist/browser/variant-node.js +4 -2
  104. package/dist/browser/variant-node.js.map +1 -1
  105. package/dist/browser/w.js +33 -3
  106. package/dist/browser/w.js.map +1 -1
  107. package/dist/browser/ward.js +594 -61
  108. package/dist/browser/ward.js.map +1 -1
  109. package/dist/browser/wardic-config.js +62 -29
  110. package/dist/browser/wardic-config.js.map +1 -1
  111. package/dist/browser/wardic-context.js +23 -0
  112. package/dist/browser/wardic-context.js.map +1 -0
  113. package/dist/browser/wardic.js +3 -0
  114. package/dist/browser/wardic.js.map +1 -1
  115. package/dist/server/animation-frame.js +1 -1
  116. package/dist/server/animation-frame.js.map +1 -1
  117. package/dist/server/config-view.js +35 -6
  118. package/dist/server/config-view.js.map +1 -1
  119. package/dist/server/create-batch.js +1 -1
  120. package/dist/server/diagnostic-codes.js +216 -0
  121. package/dist/server/diagnostic-codes.js.map +1 -0
  122. package/dist/server/diagnostics.js +79 -0
  123. package/dist/server/diagnostics.js.map +1 -0
  124. package/dist/server/element-style.js +61 -7
  125. package/dist/server/element-style.js.map +1 -1
  126. package/dist/server/element.js +24 -6
  127. package/dist/server/element.js.map +1 -1
  128. package/dist/server/feature-section.js +5 -13
  129. package/dist/server/feature-section.js.map +1 -1
  130. package/dist/server/frame-effect.js +1 -1
  131. package/dist/server/frame-effect.js.map +1 -1
  132. package/dist/server/gesture-callbacks.js +1 -1
  133. package/dist/server/gesture-callbacks.js.map +1 -1
  134. package/dist/server/hooks/auto.js +270 -0
  135. package/dist/server/hooks/auto.js.map +1 -0
  136. package/dist/server/hooks/config-scope.js +120 -0
  137. package/dist/server/hooks/config-scope.js.map +1 -0
  138. package/dist/server/hooks/config.js +37 -0
  139. package/dist/server/hooks/config.js.map +1 -0
  140. package/dist/server/hooks/drag.js +633 -0
  141. package/dist/server/hooks/drag.js.map +1 -0
  142. package/dist/server/hooks/elements.js +192 -0
  143. package/dist/server/hooks/elements.js.map +1 -0
  144. package/dist/server/hooks/group.js +28 -0
  145. package/dist/server/hooks/group.js.map +1 -0
  146. package/dist/server/hooks/index.js +10 -0
  147. package/dist/server/hooks/index.js.map +1 -0
  148. package/dist/server/hooks/kept.js +32 -0
  149. package/dist/server/hooks/kept.js.map +1 -0
  150. package/dist/server/hooks/layout-group-of.js +39 -0
  151. package/dist/server/hooks/layout-group-of.js.map +1 -0
  152. package/dist/server/hooks/layout-group.js +109 -0
  153. package/dist/server/hooks/layout-group.js.map +1 -0
  154. package/dist/server/hooks/make-ward.js +157 -0
  155. package/dist/server/hooks/make-ward.js.map +1 -0
  156. package/dist/server/hooks/presence-scope.js +87 -0
  157. package/dist/server/hooks/presence-scope.js.map +1 -0
  158. package/dist/server/hooks/presence.js +24 -0
  159. package/dist/server/hooks/presence.js.map +1 -0
  160. package/dist/server/hooks/props.js +148 -0
  161. package/dist/server/hooks/props.js.map +1 -0
  162. package/dist/server/hooks/reads.js +241 -0
  163. package/dist/server/hooks/reads.js.map +1 -0
  164. package/dist/server/hooks/refs.js +87 -0
  165. package/dist/server/hooks/refs.js.map +1 -0
  166. package/dist/server/hooks/reorder-elements.js +309 -0
  167. package/dist/server/hooks/reorder-elements.js.map +1 -0
  168. package/dist/server/hooks/reorder.js +176 -0
  169. package/dist/server/hooks/reorder.js.map +1 -0
  170. package/dist/server/hooks/rune.js +800 -0
  171. package/dist/server/hooks/rune.js.map +1 -0
  172. package/dist/server/hooks/server-features.client.js +2 -0
  173. package/dist/server/hooks/server-features.client.js.map +1 -0
  174. package/dist/server/hooks/server-features.js +13 -0
  175. package/dist/server/hooks/server-features.js.map +1 -0
  176. package/dist/server/hooks/settings.js +29 -0
  177. package/dist/server/hooks/settings.js.map +1 -0
  178. package/dist/server/hooks/setup.js +154 -0
  179. package/dist/server/hooks/setup.js.map +1 -0
  180. package/dist/server/hooks/stage.js +117 -0
  181. package/dist/server/hooks/stage.js.map +1 -0
  182. package/dist/server/hooks/ward.js +2212 -0
  183. package/dist/server/hooks/ward.js.map +1 -0
  184. package/dist/server/hooks/wardic-provider.js +29 -0
  185. package/dist/server/hooks/wardic-provider.js.map +1 -0
  186. package/dist/server/hooks/wardic-scope.js +68 -0
  187. package/dist/server/hooks/wardic-scope.js.map +1 -0
  188. package/dist/server/hooks/wards.js +563 -0
  189. package/dist/server/hooks/wards.js.map +1 -0
  190. package/dist/server/index.js +23 -11
  191. package/dist/server/index.js.map +1 -1
  192. package/dist/server/layout.js +7 -75
  193. package/dist/server/layout.js.map +1 -1
  194. package/dist/server/lazy-batch-gestures.js +1 -1
  195. package/dist/server/lifecycle.js +37 -0
  196. package/dist/server/lifecycle.js.map +1 -1
  197. package/dist/server/presence-handle.js +28 -12
  198. package/dist/server/presence-handle.js.map +1 -1
  199. package/dist/server/presence.js +3 -1
  200. package/dist/server/presence.js.map +1 -1
  201. package/dist/server/provider.js +125 -100
  202. package/dist/server/provider.js.map +1 -1
  203. package/dist/server/reorder-components.js +50 -0
  204. package/dist/server/reorder-components.js.map +1 -0
  205. package/dist/server/reorder.js +51 -348
  206. package/dist/server/reorder.js.map +1 -1
  207. package/dist/server/runtime.js +26 -15
  208. package/dist/server/runtime.js.map +1 -1
  209. package/dist/server/spans-check.js +8 -3
  210. package/dist/server/spans-check.js.map +1 -1
  211. package/dist/server/stage.js.map +1 -1
  212. package/dist/server/unstable/v2/index.js +0 -8
  213. package/dist/server/unstable/v2/index.js.map +1 -1
  214. package/dist/server/v1/index.js +1 -1
  215. package/dist/server/v1/index.js.map +1 -1
  216. package/dist/server/variant-node.js +4 -2
  217. package/dist/server/variant-node.js.map +1 -1
  218. package/dist/server/w.js +33 -3
  219. package/dist/server/w.js.map +1 -1
  220. package/dist/server/ward.js +594 -61
  221. package/dist/server/ward.js.map +1 -1
  222. package/dist/server/wardic-config.js +63 -30
  223. package/dist/server/wardic-config.js.map +1 -1
  224. package/dist/server/wardic-context.js +23 -0
  225. package/dist/server/wardic-context.js.map +1 -0
  226. package/dist/server/wardic.js +3 -0
  227. package/dist/server/wardic.js.map +1 -1
  228. package/dist/solid/animation-frame.js +1 -1
  229. package/dist/solid/animation-frame.js.map +1 -1
  230. package/dist/solid/batch-reorder-group.d.ts +1 -1
  231. package/dist/solid/batch-reorder.d.ts +1 -1
  232. package/dist/solid/batch-reorder.d.ts.map +1 -1
  233. package/dist/solid/config-view.d.ts +11 -0
  234. package/dist/solid/config-view.d.ts.map +1 -1
  235. package/dist/solid/config-view.js +31 -7
  236. package/dist/solid/config-view.js.map +1 -1
  237. package/dist/solid/create-batch.jsx +1 -1
  238. package/dist/solid/diagnostic-codes.d.ts +10 -0
  239. package/dist/solid/diagnostic-codes.d.ts.map +1 -0
  240. package/dist/solid/diagnostic-codes.js +246 -0
  241. package/dist/solid/diagnostic-codes.js.map +1 -0
  242. package/dist/solid/diagnostics.d.ts +33 -0
  243. package/dist/solid/diagnostics.d.ts.map +1 -0
  244. package/dist/solid/diagnostics.js +76 -0
  245. package/dist/solid/diagnostics.js.map +1 -0
  246. package/dist/solid/element-style.d.ts +16 -2
  247. package/dist/solid/element-style.d.ts.map +1 -1
  248. package/dist/solid/element-style.js +61 -7
  249. package/dist/solid/element-style.js.map +1 -1
  250. package/dist/solid/element.d.ts +3 -1
  251. package/dist/solid/element.d.ts.map +1 -1
  252. package/dist/solid/element.jsx +27 -8
  253. package/dist/solid/element.jsx.map +1 -1
  254. package/dist/solid/feature-section.d.ts +0 -7
  255. package/dist/solid/feature-section.d.ts.map +1 -1
  256. package/dist/solid/feature-section.js +5 -13
  257. package/dist/solid/feature-section.js.map +1 -1
  258. package/dist/solid/frame-effect.jsx +1 -1
  259. package/dist/solid/frame-effect.jsx.map +1 -1
  260. package/dist/solid/gesture-callbacks.js +1 -1
  261. package/dist/solid/gesture-callbacks.js.map +1 -1
  262. package/dist/solid/hooks/auto.d.ts +44 -0
  263. package/dist/solid/hooks/auto.d.ts.map +1 -0
  264. package/dist/solid/hooks/auto.js +269 -0
  265. package/dist/solid/hooks/auto.js.map +1 -0
  266. package/dist/solid/hooks/config-scope.d.ts +84 -0
  267. package/dist/solid/hooks/config-scope.d.ts.map +1 -0
  268. package/dist/solid/hooks/config-scope.jsx +128 -0
  269. package/dist/solid/hooks/config-scope.jsx.map +1 -0
  270. package/dist/solid/hooks/config.d.ts +28 -0
  271. package/dist/solid/hooks/config.d.ts.map +1 -0
  272. package/dist/solid/hooks/config.jsx +37 -0
  273. package/dist/solid/hooks/config.jsx.map +1 -0
  274. package/dist/solid/hooks/drag.d.ts +220 -0
  275. package/dist/solid/hooks/drag.d.ts.map +1 -0
  276. package/dist/solid/hooks/drag.js +586 -0
  277. package/dist/solid/hooks/drag.js.map +1 -0
  278. package/dist/solid/hooks/elements.d.ts +11 -0
  279. package/dist/solid/hooks/elements.d.ts.map +1 -0
  280. package/dist/solid/hooks/elements.jsx +218 -0
  281. package/dist/solid/hooks/elements.jsx.map +1 -0
  282. package/dist/solid/hooks/group.d.ts +46 -0
  283. package/dist/solid/hooks/group.d.ts.map +1 -0
  284. package/dist/solid/hooks/group.jsx +25 -0
  285. package/dist/solid/hooks/group.jsx.map +1 -0
  286. package/dist/solid/hooks/index.d.ts +28 -0
  287. package/dist/solid/hooks/index.d.ts.map +1 -0
  288. package/dist/solid/hooks/index.js +10 -0
  289. package/dist/solid/hooks/index.js.map +1 -0
  290. package/dist/solid/hooks/kept.d.ts +60 -0
  291. package/dist/solid/hooks/kept.d.ts.map +1 -0
  292. package/dist/solid/hooks/kept.js +33 -0
  293. package/dist/solid/hooks/kept.js.map +1 -0
  294. package/dist/solid/hooks/layout-group-of.d.ts +27 -0
  295. package/dist/solid/hooks/layout-group-of.d.ts.map +1 -0
  296. package/dist/solid/hooks/layout-group-of.js +39 -0
  297. package/dist/solid/hooks/layout-group-of.js.map +1 -0
  298. package/dist/solid/hooks/layout-group.d.ts +60 -0
  299. package/dist/solid/hooks/layout-group.d.ts.map +1 -0
  300. package/dist/solid/hooks/layout-group.jsx +80 -0
  301. package/dist/solid/hooks/layout-group.jsx.map +1 -0
  302. package/dist/solid/hooks/make-ward.d.ts +123 -0
  303. package/dist/solid/hooks/make-ward.d.ts.map +1 -0
  304. package/dist/solid/hooks/make-ward.js +147 -0
  305. package/dist/solid/hooks/make-ward.js.map +1 -0
  306. package/dist/solid/hooks/presence-scope.d.ts +84 -0
  307. package/dist/solid/hooks/presence-scope.d.ts.map +1 -0
  308. package/dist/solid/hooks/presence-scope.jsx +63 -0
  309. package/dist/solid/hooks/presence-scope.jsx.map +1 -0
  310. package/dist/solid/hooks/presence.d.ts +51 -0
  311. package/dist/solid/hooks/presence.d.ts.map +1 -0
  312. package/dist/solid/hooks/presence.jsx +26 -0
  313. package/dist/solid/hooks/presence.jsx.map +1 -0
  314. package/dist/solid/hooks/props.d.ts +52 -0
  315. package/dist/solid/hooks/props.d.ts.map +1 -0
  316. package/dist/solid/hooks/props.js +140 -0
  317. package/dist/solid/hooks/props.js.map +1 -0
  318. package/dist/solid/hooks/reads.d.ts +38 -0
  319. package/dist/solid/hooks/reads.d.ts.map +1 -0
  320. package/dist/solid/hooks/reads.js +218 -0
  321. package/dist/solid/hooks/reads.js.map +1 -0
  322. package/dist/solid/hooks/refs.d.ts +25 -0
  323. package/dist/solid/hooks/refs.d.ts.map +1 -0
  324. package/dist/solid/hooks/refs.js +89 -0
  325. package/dist/solid/hooks/refs.js.map +1 -0
  326. package/dist/solid/hooks/reorder-elements.d.ts +23 -0
  327. package/dist/solid/hooks/reorder-elements.d.ts.map +1 -0
  328. package/dist/solid/hooks/reorder-elements.jsx +274 -0
  329. package/dist/solid/hooks/reorder-elements.jsx.map +1 -0
  330. package/dist/solid/hooks/reorder.d.ts +55 -0
  331. package/dist/solid/hooks/reorder.d.ts.map +1 -0
  332. package/dist/solid/hooks/reorder.js +152 -0
  333. package/dist/solid/hooks/reorder.js.map +1 -0
  334. package/dist/solid/hooks/rune.d.ts +885 -0
  335. package/dist/solid/hooks/rune.d.ts.map +1 -0
  336. package/dist/solid/hooks/rune.js +817 -0
  337. package/dist/solid/hooks/rune.js.map +1 -0
  338. package/dist/solid/hooks/server-features.client.d.ts +10 -0
  339. package/dist/solid/hooks/server-features.client.d.ts.map +1 -0
  340. package/dist/solid/hooks/server-features.client.js +2 -0
  341. package/dist/solid/hooks/server-features.client.js.map +1 -0
  342. package/dist/solid/hooks/server-features.d.ts +10 -0
  343. package/dist/solid/hooks/server-features.d.ts.map +1 -0
  344. package/dist/solid/hooks/server-features.js +13 -0
  345. package/dist/solid/hooks/server-features.js.map +1 -0
  346. package/dist/solid/hooks/settings.d.ts +11 -0
  347. package/dist/solid/hooks/settings.d.ts.map +1 -0
  348. package/dist/solid/hooks/settings.js +31 -0
  349. package/dist/solid/hooks/settings.js.map +1 -0
  350. package/dist/solid/hooks/setup.d.ts +31 -0
  351. package/dist/solid/hooks/setup.d.ts.map +1 -0
  352. package/dist/solid/hooks/setup.js +155 -0
  353. package/dist/solid/hooks/setup.js.map +1 -0
  354. package/dist/solid/hooks/stage.d.ts +187 -0
  355. package/dist/solid/hooks/stage.d.ts.map +1 -0
  356. package/dist/solid/hooks/stage.js +117 -0
  357. package/dist/solid/hooks/stage.js.map +1 -0
  358. package/dist/solid/hooks/ward.d.ts +394 -0
  359. package/dist/solid/hooks/ward.d.ts.map +1 -0
  360. package/dist/solid/hooks/ward.js +2258 -0
  361. package/dist/solid/hooks/ward.js.map +1 -0
  362. package/dist/solid/hooks/wardic-provider.d.ts +32 -0
  363. package/dist/solid/hooks/wardic-provider.d.ts.map +1 -0
  364. package/dist/solid/hooks/wardic-provider.jsx +29 -0
  365. package/dist/solid/hooks/wardic-provider.jsx.map +1 -0
  366. package/dist/solid/hooks/wardic-scope.d.ts +49 -0
  367. package/dist/solid/hooks/wardic-scope.d.ts.map +1 -0
  368. package/dist/solid/hooks/wardic-scope.jsx +63 -0
  369. package/dist/solid/hooks/wardic-scope.jsx.map +1 -0
  370. package/dist/solid/hooks/wards.d.ts +157 -0
  371. package/dist/solid/hooks/wards.d.ts.map +1 -0
  372. package/dist/solid/hooks/wards.js +523 -0
  373. package/dist/solid/hooks/wards.js.map +1 -0
  374. package/dist/solid/index.d.ts +21 -14
  375. package/dist/solid/index.d.ts.map +1 -1
  376. package/dist/solid/index.jsx +23 -11
  377. package/dist/solid/index.jsx.map +1 -1
  378. package/dist/solid/layout.d.ts +2 -44
  379. package/dist/solid/layout.d.ts.map +1 -1
  380. package/dist/solid/layout.jsx +7 -49
  381. package/dist/solid/layout.jsx.map +1 -1
  382. package/dist/solid/lazy-batch-gestures.js +1 -1
  383. package/dist/solid/lazy-batch-gestures.js.map +1 -1
  384. package/dist/solid/lifecycle.d.ts +19 -0
  385. package/dist/solid/lifecycle.d.ts.map +1 -1
  386. package/dist/solid/lifecycle.js +40 -0
  387. package/dist/solid/lifecycle.js.map +1 -1
  388. package/dist/solid/presence-handle.d.ts +13 -6
  389. package/dist/solid/presence-handle.d.ts.map +1 -1
  390. package/dist/solid/presence-handle.js +30 -12
  391. package/dist/solid/presence-handle.js.map +1 -1
  392. package/dist/solid/presence.d.ts +3 -1
  393. package/dist/solid/presence.d.ts.map +1 -1
  394. package/dist/solid/presence.jsx +3 -1
  395. package/dist/solid/presence.jsx.map +1 -1
  396. package/dist/solid/provider.d.ts +25 -32
  397. package/dist/solid/provider.d.ts.map +1 -1
  398. package/dist/solid/provider.jsx +126 -82
  399. package/dist/solid/provider.jsx.map +1 -1
  400. package/dist/solid/reorder-components.d.ts +32 -0
  401. package/dist/solid/reorder-components.d.ts.map +1 -0
  402. package/dist/solid/reorder-components.jsx +49 -0
  403. package/dist/solid/reorder-components.jsx.map +1 -0
  404. package/dist/solid/reorder.d.ts +50 -76
  405. package/dist/solid/reorder.d.ts.map +1 -1
  406. package/dist/solid/reorder.jsx +45 -206
  407. package/dist/solid/reorder.jsx.map +1 -1
  408. package/dist/solid/runtime.d.ts +20 -7
  409. package/dist/solid/runtime.d.ts.map +1 -1
  410. package/dist/solid/runtime.js +25 -14
  411. package/dist/solid/runtime.js.map +1 -1
  412. package/dist/solid/spans-check.d.ts +5 -1
  413. package/dist/solid/spans-check.d.ts.map +1 -1
  414. package/dist/solid/spans-check.js +8 -3
  415. package/dist/solid/spans-check.js.map +1 -1
  416. package/dist/solid/stage.d.ts +14 -0
  417. package/dist/solid/stage.d.ts.map +1 -1
  418. package/dist/solid/stage.js.map +1 -1
  419. package/dist/solid/unstable/v2/index.d.ts +2 -26
  420. package/dist/solid/unstable/v2/index.d.ts.map +1 -1
  421. package/dist/solid/unstable/v2/index.jsx +0 -16
  422. package/dist/solid/unstable/v2/index.jsx.map +1 -1
  423. package/dist/solid/v1/index.d.ts +1 -1
  424. package/dist/solid/v1/index.d.ts.map +1 -1
  425. package/dist/solid/v1/index.jsx +1 -1
  426. package/dist/solid/v1/index.jsx.map +1 -1
  427. package/dist/solid/variant-node.d.ts +6 -0
  428. package/dist/solid/variant-node.d.ts.map +1 -1
  429. package/dist/solid/variant-node.js +2 -0
  430. package/dist/solid/variant-node.js.map +1 -1
  431. package/dist/solid/w.d.ts +9 -3
  432. package/dist/solid/w.d.ts.map +1 -1
  433. package/dist/solid/w.jsx +36 -3
  434. package/dist/solid/w.jsx.map +1 -1
  435. package/dist/solid/ward.d.ts +134 -7
  436. package/dist/solid/ward.d.ts.map +1 -1
  437. package/dist/solid/ward.jsx +564 -60
  438. package/dist/solid/ward.jsx.map +1 -1
  439. package/dist/solid/wardic-config.d.ts +17 -12
  440. package/dist/solid/wardic-config.d.ts.map +1 -1
  441. package/dist/solid/wardic-config.jsx +68 -22
  442. package/dist/solid/wardic-config.jsx.map +1 -1
  443. package/dist/solid/wardic-context.d.ts +15 -0
  444. package/dist/solid/wardic-context.d.ts.map +1 -0
  445. package/dist/solid/wardic-context.js +23 -0
  446. package/dist/solid/wardic-context.js.map +1 -0
  447. package/dist/solid/wardic-instance.d.ts +6 -4
  448. package/dist/solid/wardic-instance.d.ts.map +1 -1
  449. package/dist/solid/wardic.d.ts +3 -0
  450. package/dist/solid/wardic.d.ts.map +1 -1
  451. package/dist/solid/wardic.jsx +3 -0
  452. package/dist/solid/wardic.jsx.map +1 -1
  453. package/package.json +29 -7
  454. package/skills/wardic-diagnostics/SKILL.md +472 -0
  455. package/skills/wardic-migrate/SKILL.md +204 -0
  456. package/skills/wardic-solid/SKILL.md +60 -0
  457. package/skills/wardic-solid/events.md +70 -0
  458. package/skills/wardic-solid/from-motion.md +59 -0
  459. package/skills/wardic-solid/lists-and-presence.md +110 -0
  460. package/skills/wardic-solid/reorder-and-grips.md +88 -0
  461. package/skills/wardic-solid/runes.md +151 -0
  462. package/skills/wardic-solid/scopes-and-settings.md +75 -0
  463. package/src/animation-frame.ts +1 -1
  464. package/src/batch-reorder-group.tsx +1 -1
  465. package/src/batch-reorder.ts +1 -1
  466. package/src/config-view.ts +35 -7
  467. package/src/create-batch.tsx +1 -1
  468. package/src/diagnostic-codes.ts +254 -0
  469. package/src/diagnostics.ts +88 -0
  470. package/src/element-style.ts +77 -9
  471. package/src/element.tsx +36 -12
  472. package/src/feature-section.ts +5 -15
  473. package/src/frame-effect.tsx +1 -1
  474. package/src/gesture-callbacks.ts +1 -1
  475. package/src/hooks/auto.ts +303 -0
  476. package/src/hooks/config-scope.tsx +215 -0
  477. package/src/hooks/config.tsx +54 -0
  478. package/src/hooks/drag.ts +741 -0
  479. package/src/hooks/elements.tsx +234 -0
  480. package/src/hooks/group.tsx +55 -0
  481. package/src/hooks/index.ts +41 -0
  482. package/src/hooks/kept.ts +89 -0
  483. package/src/hooks/layout-group-of.ts +46 -0
  484. package/src/hooks/layout-group.tsx +111 -0
  485. package/src/hooks/make-ward.ts +218 -0
  486. package/src/hooks/presence-scope.tsx +156 -0
  487. package/src/hooks/presence.tsx +67 -0
  488. package/src/hooks/props.ts +190 -0
  489. package/src/hooks/reads.ts +258 -0
  490. package/src/hooks/refs.ts +114 -0
  491. package/src/hooks/reorder-elements.tsx +323 -0
  492. package/src/hooks/reorder.ts +205 -0
  493. package/src/hooks/rune.ts +1756 -0
  494. package/src/hooks/server-features.client.ts +10 -0
  495. package/src/hooks/server-features.ts +12 -0
  496. package/src/hooks/settings.ts +44 -0
  497. package/src/hooks/setup.ts +184 -0
  498. package/src/hooks/stage.ts +359 -0
  499. package/src/hooks/ward.ts +2587 -0
  500. package/src/hooks/wardic-provider.tsx +51 -0
  501. package/src/hooks/wardic-scope.tsx +112 -0
  502. package/src/hooks/wards.ts +681 -0
  503. package/src/index.tsx +27 -15
  504. package/src/layout.tsx +7 -74
  505. package/src/lazy-batch-gestures.ts +1 -1
  506. package/src/lifecycle.ts +40 -0
  507. package/src/presence-handle.ts +39 -20
  508. package/src/presence.tsx +3 -1
  509. package/src/provider.tsx +136 -88
  510. package/src/reorder-components.tsx +61 -0
  511. package/src/reorder.tsx +89 -307
  512. package/src/runtime.ts +43 -13
  513. package/src/spans-check.ts +12 -3
  514. package/src/stage.ts +15 -0
  515. package/src/unstable/v2/index.tsx +2 -26
  516. package/src/v1/index.tsx +1 -1
  517. package/src/variant-node.ts +8 -0
  518. package/src/w.tsx +38 -5
  519. package/src/ward.tsx +694 -60
  520. package/src/wardic-config.tsx +68 -21
  521. package/src/wardic-context.ts +26 -0
  522. package/src/wardic-instance.ts +6 -4
  523. package/src/wardic.tsx +3 -0
  524. package/dist/browser/create-wardic.js +0 -36
  525. package/dist/browser/create-wardic.js.map +0 -1
  526. package/dist/browser/presence-hooks.js +0 -144
  527. package/dist/browser/presence-hooks.js.map +0 -1
  528. package/dist/server/create-wardic.js +0 -36
  529. package/dist/server/create-wardic.js.map +0 -1
  530. package/dist/server/presence-hooks.js +0 -144
  531. package/dist/server/presence-hooks.js.map +0 -1
  532. package/dist/solid/create-wardic.d.ts +0 -25
  533. package/dist/solid/create-wardic.d.ts.map +0 -1
  534. package/dist/solid/create-wardic.jsx +0 -34
  535. package/dist/solid/create-wardic.jsx.map +0 -1
  536. package/dist/solid/presence-hooks.d.ts +0 -53
  537. package/dist/solid/presence-hooks.d.ts.map +0 -1
  538. package/dist/solid/presence-hooks.jsx +0 -117
  539. package/dist/solid/presence-hooks.jsx.map +0 -1
  540. package/src/create-wardic.tsx +0 -46
  541. package/src/presence-hooks.tsx +0 -159
@@ -0,0 +1,2587 @@
1
+ /**
2
+ * `createWard(...runes)` (probe: hooks-first): one element's motion, made of runes, with `follow` and
3
+ * `show` as keys of its config. A new function beside `ward(config, options)`, which it leaves as it is.
4
+ *
5
+ * - **One plain rune** with none of the hooks' keys is today's ward on that config, with nothing
6
+ * between: what `ward(config)` costs.
7
+ * - **Runes join** into one config (`rune.ts`). A `createRune(fn)` is handed a ward before the finished one
8
+ * exists: a holder (`holderWard`, the ward split), which the finished ward then drives, as a component
9
+ * given a `wardRef` does (#349), so the rune's `when`, `next` and `read` are the finished ward's.
10
+ * - **`follow`** is the ward's variant parent (`ward(config, { parent })`).
11
+ * - **`show`** (an accessor): shown, it animates to `animate` from `initial`; not shown, it animates to
12
+ * its `exit` (its `initial`, with none; `exit: false` leaves at once), then sets `display: none`.
13
+ * `mounted()` stays true until that exit has landed, and its followers', for a `<Show>` that removes
14
+ * it instead. It's the ward's own Retarget, run while it lives: no `<AnimatePresence>`.
15
+ * - **`pop`** takes a `show` ward out of the flow as it starts to leave, pinned where it was with the
16
+ * presence's own measure (dom's `popBoxOf` and `pin`), by its top left or the corner it names, and
17
+ * puts it back when it's shown again. Whatever its mode, the layout projection is told as it comes, pops and goes, so a `layout`
18
+ * element beside it animates into or out of the space.
19
+ *
20
+ * - **A presence takes the ward itself** (`createPresence(ward, value)`, `wards.ts`): the one ward leaves
21
+ * and comes back, on a new element for each value. A ward `createWard` hands out is made ready for
22
+ * one: its `animate` is read through a wiring that does nothing until a presence takes it, and then
23
+ * is `show`'s, the presence's word in `show`'s place. One with a `show` of its own, or a row's, isn't.
24
+ *
25
+ * Throwaway code: `show` is wired through the config (`animate` and `style` read through it), where a
26
+ * real one would Retarget its spine itself, as a Scene object's exit does (`stage-ward.tsx`).
27
+ *
28
+ * @module
29
+ */
30
+ import { isServer, spread } from "@solidjs/web"
31
+ import * as Arr from "effect/Array"
32
+ import * as Cause from "effect/Cause"
33
+ import * as Bool from "effect/Boolean"
34
+ import { constFalse, constUndefined, constVoid, identity } from "effect/Function"
35
+ import * as UndefinedOr from "effect/UndefinedOr"
36
+ import * as Iter from "effect/Iterable"
37
+ import * as Option from "effect/Option"
38
+ import * as Predicate from "effect/Predicate"
39
+ import { type Accessor, createEffect, createMemo, createRoot, createSignal, DEV, getOwner, onCleanup, type Owner, runWithOwner, untrack } from "solid-js"
40
+ import * as Report from "@wardic/dom/Report"
41
+ import type * as Feature from "@wardic/dom/unstable/Feature"
42
+ import { pin, type PopAnchors, type PopBox, popBoxOf } from "@wardic/dom/unstable/PresenceController"
43
+ import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource"
44
+ import { useBuiltProjection, useInstanceFeatures, useWardicRuntime } from "../provider.tsx"
45
+ import { useWardicConfig } from "../wardic-config.tsx"
46
+ import { layoutGroupIn } from "./layout-group-of.ts"
47
+ import { givesSettings, runeGivesSettings, settingsOver } from "./settings.ts"
48
+ import type { PresenceEvent, PresenceEvents } from "../presence-handle.ts"
49
+ import { eachOf, Waiters, whenOf } from "../waiters.ts"
50
+ import { CLIENT_ONLY, onSettledClientOnly } from "../solid-reactivity.ts"
51
+ import type { WardElement } from "../lifecycle.ts"
52
+ import type * as PresenceRecord from "@wardic/core/unstable/PresenceRecord"
53
+ import { misuse, report } from "../diagnostics.ts"
54
+ import { fixLater, GESTURE_KEYS, holderFinished, holderWard, internalsOf, keepsState, sensedOf, sharedMember, shareMembers, shareOf, SLIM, targetAgain, type Ward, type WardConfig, type WardInternals, wardWith } from "../ward.tsx"
55
+ import { asking, type AutoFeature, colorsOnceLoaded, featureOfEvent, wantedBy } from "./auto.ts"
56
+ import { bothHandles, dragAccessorOf, dragAxisAt, dragAxisOf, givesDrag, isDragOnly, keysRuneOf, liftedOf, makeSite, raiseOf, runeWardOf, siteIfAny, siteInternalsOf, siteKeptFor, warnIfUndragged, withDrag, withGrips } from "./drag.ts"
57
+ import { asReadOf, type DragsGiven, type ElementOf, fixedRunes, functionOf, hasOwnVariants, isFunctionRune, isPlainRune, joined, joinedOver, type Joined, namesNothing, type PageRunesGiven, type ReadByKey, type ReadThrough, readThroughOf, type Rune, type RuneConfig, type RuneWard, SEEN, type Shown, type TagGiven, wiredOf } from "./rune.ts"
58
+ import { ALWAYS, type Kept, keptFor, keptOf, type Listening } from "./kept.ts"
59
+ import { drivenBy, onOf, READS, type WardReads } from "./reads.ts"
60
+ import { addedTo, carrying, isOneOf, type PropKeys, propKeysOf, runePropsOf, settingOn, withCarrying } from "./props.ts"
61
+ import { type AnyRef, type Attended, attending, refsRun, runeRefsOf } from "./refs.ts"
62
+
63
+ /**
64
+ * What a ward's exits resolve to, by name, a presence handle's two: `exitStart`, as it starts to
65
+ * leave, and `exitComplete`, once it has gone. Both `undefined`.
66
+ */
67
+ export type ExitEvents = PresenceEvents
68
+
69
+ /** The names of a ward's exits. */
70
+ export type ExitEvent = PresenceEvent
71
+
72
+ /** A ward made of runes: a ward, with `mounted`, its exits, `ready`, and its reads ({@link WardReads}). */
73
+ export type HookWard = Ward & WardReads & {
74
+ /**
75
+ * Whether it's leaving: true from the moment it starts to leave until it has gone, or is shown
76
+ * again. Always false for a ward no hook shows.
77
+ */
78
+ readonly exiting: Accessor<boolean>
79
+ /**
80
+ * Its own exits, beside a ward's other events, for a ward a hook shows (`show`, a list's row, a
81
+ * `createPresence`'s): the ward is made where its element's owner is, and outlives the element.
82
+ *
83
+ * - `"exitStart"`: it started to leave.
84
+ * - `"exitComplete"`: it has gone, its followers landed and the twins inside it flown home. An exit
85
+ * it turned round from doesn't complete; one with nowhere to leave to starts and completes at once.
86
+ *
87
+ * ```tsx
88
+ * const frame = createWard({ initial: "closed", animate: "open" })
89
+ * const showing = createPresence(frame, open)
90
+ * createEffect(frame.when("exitComplete"), () => trigger.focus())
91
+ * ```
92
+ *
93
+ * A ward made inside what a presence component takes away never hears its own: it ends as its exit
94
+ * starts. Those are the boundary's to tell. Not told on a Stage in this probe.
95
+ */
96
+ next<E extends ExitEvent>(name: E): Promise<ExitEvents[E]>
97
+ /** Every `name` of its exits from the call on, for a `for await`. */
98
+ each<E extends ExitEvent>(name: E): AsyncIterable<ExitEvents[E]>
99
+ /** Every `name` of its exits, as a memo for an effect. */
100
+ when<E extends ExitEvent>(name: E): Accessor<ExitEvents[E]>
101
+ /**
102
+ * `"ready"`: every Feature its own config uses is on the page, so its gestures, its drag and its
103
+ * layout work from here on. Each Feature is loaded the first time a ward asks for it, and a ward
104
+ * made before one has arrived does nothing of that Feature's until it has.
105
+ *
106
+ * ```tsx
107
+ * const piece = createWard({ drag: true })
108
+ * createEffect(piece.when("ready"), () => setHint("Drag a piece to move it."))
109
+ * ```
110
+ *
111
+ * It happens once, so it's kept, where a ward's other events are heard from the call on: asked for
112
+ * after it, `next("ready")` is resolved already, and an effect over `when("ready")` runs at once. A
113
+ * ward that asks for no Feature is ready as it's made. A load that fails is reported, and counts.
114
+ *
115
+ * Nothing is told on a server. Not told for a `createReorder`'s rows or on a Stage in this probe.
116
+ */
117
+ next(name: "ready"): Promise<undefined>
118
+ /** `"ready"`, as a memo for an effect: pending until it is, so the effect runs then and never before. */
119
+ when(name: "ready"): Accessor<undefined>
120
+ /**
121
+ * Whether its element belongs on the page: true while it's shown, and until its exit has landed.
122
+ * Always true for a ward with no `show`. For a `<Show when={card.mounted()}>` around its element.
123
+ */
124
+ readonly mounted: Accessor<boolean>
125
+ /**
126
+ * Whether it's shown: its `show`, false from the moment it starts to leave (Motion's `useIsPresent`).
127
+ * Always true for a ward with no `show`. For what a leaving ward's own content should do meanwhile.
128
+ */
129
+ readonly shown: Accessor<boolean>
130
+ /**
131
+ * Holds the leave under way: the ward stays on the page, its exit landed or not, until the release
132
+ * it hands back is called; then it goes, and its `exitComplete` is told. For what isn't Wardic's to
133
+ * run: a save, a CSS transition, another library's exit (Motion's `usePresence`'s `safeToRemove`).
134
+ *
135
+ * ```tsx
136
+ * createEffect(card.when("exitStart"), () => {
137
+ * const release = card.hold()
138
+ * saveDraft().then(release)
139
+ * })
140
+ * ```
141
+ *
142
+ * A hold is the leave's it's taken in: one taken while it isn't leaving holds nothing, and once it's
143
+ * shown again, a release from before does nothing. Releasing twice is releasing once.
144
+ */
145
+ hold(): () => void
146
+ }
147
+
148
+ /**
149
+ * A ward whose Subject is the element `Tag` names (the gap grill's Q22): its spread's `ref` takes that
150
+ * Subject, so it spreads there. Still a {@link HookWard}, which whatever takes a ward takes. Any HTML
151
+ * element where there's no tag, as every ward's was.
152
+ */
153
+ export type TaggedWard<Tag> = [Tag] extends [undefined] ? HookWard : HookWard & { readonly ref: (element: ElementOf<Tag>) => void }
154
+
155
+ /**
156
+ * `createWard(...runes)`: each rune checked as a ward on the page takes one, a function rune as it is
157
+ * and a config key by key, so one written for a Stage with a key that's only a Stage's is an error here.
158
+ * A rune that names its Subject's `tag` has its own `ref` and `props` typed for that element, and the
159
+ * ward's spread is.
160
+ */
161
+ export type HookWardOf = <P extends ReadonlyArray<object>>(...runes: PageRunesGiven<P>) => TaggedWard<TagGiven<P>> & DragsGiven<P>
162
+
163
+ /** What makes a ward of runes, before its type names its tag and its drag: {@link HookWardOf}'s body. */
164
+ export type WardMaker = <P extends ReadonlyArray<object>>(...runes: PageRunesGiven<P>) => HookWard
165
+
166
+ const NO_CONFIG: WardConfig = {}
167
+ /** What a behaviour that reads `ward.drag` asks for (probe: behaviour-runes, Q5). */
168
+ const DRAG_WANTED: ReadonlyArray<AutoFeature> = ["drag"]
169
+
170
+ /**
171
+ * Whether a ward drags, and so has grips (probe: behaviour-runes, Q14): a `drag` given as an accessor,
172
+ * or one that's on. The accessor first: the value is read only where there's none.
173
+ */
174
+ const drags = (axisAt: Accessor<unknown> | undefined, dragRead: Accessor<unknown>): boolean => {
175
+ if (Predicate.isNotUndefined(axisAt)) return true
176
+ return dragAxisAt(dragRead)() !== false
177
+ }
178
+ const NEVER: Accessor<boolean> = () => false
179
+ const AT_ONCE = (count: () => void): void => count()
180
+ const NO_EXIT = (): undefined => undefined
181
+ const NO_TURN = (): number => 0
182
+ /** A hold with nothing to hold: a ward no hook shows, or one not leaving. */
183
+ const NO_HOLD = (): (() => void) => constVoid
184
+ const NAME = "createWard(...runes)"
185
+
186
+ const isPlain = (value: unknown): value is Readonly<Record<string, unknown>> => Predicate.isObject(value) && !Array.isArray(value) && !Predicate.isFunction(value)
187
+
188
+ /**
189
+ * `ward` with `mounted`, `shown` and `exiting`, and its reads (`reads.ts`). A client's ward shares
190
+ * them with every other ({@link SHARED}) and is only told whether it's mounted and shown (`kept.ts`).
191
+ * A ward with no state of its own, a server's or a Stage's, is given each as a property of its
192
+ * own, not enumerable, so a spread never sees them.
193
+ */
194
+ export const withMounted = (ward: Ward, mounted: Accessor<boolean>, shown: Accessor<boolean>): HookWard => {
195
+ if (!keepsState(ward)) {
196
+ return Object.defineProperties(ward, { mounted: { value: mounted }, shown: { value: shown }, exiting: { value: () => !shown() && mounted() }, hold: { value: NO_HOLD }, ...READS }) as HookWard
197
+ }
198
+ const kept = keptOf(ward)
199
+ kept.mounted = mounted
200
+ kept.shown = shown
201
+ return ward as HookWard
202
+ }
203
+
204
+ /** A `show` ward's state: what its config reads through, and what the finished ward tells it. */
205
+ export interface ShowState {
206
+ /** Whether it's shown, as a memo of its `show`: what changes only when the answer does. */
207
+ shown: Accessor<boolean>
208
+ mounted: Accessor<boolean>
209
+ /**
210
+ * Whether it stays to leave: it has an exit of its own ({@link exits}), or something it waits for
211
+ * ({@link waits}). With neither, it's gone at once, and nothing is popped.
212
+ */
213
+ leaves: Accessor<boolean>
214
+ /** Whether it has an exit of its own to leave by: its `exit`, else its `initial`. */
215
+ exits: Accessor<boolean>
216
+ /**
217
+ * Whether, with no exit of its own, it waits as it leaves (the code review of the gap grill's work):
218
+ * the wards inside a row's or a presence value's Subject that leave by their own exits (Q20), and a
219
+ * leader's followers with an exit of their own (Q12). It stays, moving nothing itself, until theirs
220
+ * have landed. Asked as it's hidden, of what's on the page then: not reactive.
221
+ */
222
+ waits: () => boolean
223
+ /** Whether its followers have all landed: the finished ward's, once it's made. */
224
+ followersLanded: Accessor<boolean>
225
+ /**
226
+ * How its landing is counted: at once, or a frame on for a ward that hands its variants' names down,
227
+ * whose followers are told to leave in the flush it lands in. The Environment's frame (ADR-0031).
228
+ */
229
+ counted: (count: () => void) => void
230
+ /** Told at each of the ward's landings. */
231
+ landed: () => void
232
+ /**
233
+ * How many things keep it on the page beside its own exit: the handover of the `layoutId` twins it
234
+ * gave back as it started to leave. Not reactive: it's read as a landing or a release is told.
235
+ */
236
+ holds: number
237
+ /** Told as one of those lets go. */
238
+ released: () => void
239
+ /** Which leave it's in: its `show`'s changes so far. A hold is the leave's it was taken in ({@link holdOn}). */
240
+ turn: () => number
241
+ /**
242
+ * Whether the wards inside its element leave with it (the gap grill's Q20): a list's row, or a
243
+ * presence's value, which stays on the page as it leaves with what's inside it still alive. Not a
244
+ * `show` ward's, which hides.
245
+ */
246
+ sweeps: boolean
247
+ /**
248
+ * Whether its coming and going tells the layout projection, so a `layout` element beside it moves
249
+ * into the space by animation, as a presence's `presenceAffectsLayout` has it. False for a list's row
250
+ * or a presence's ward whose list or presence says `affectsLayout: false` (the gap grill's Q14): what's
251
+ * beside it moves at once. Not reactive: read each time the projection would be told.
252
+ */
253
+ affectsLayout: boolean
254
+ /**
255
+ * Whether its mount pushes what's beside it, and so is told to the layout projection as it goes on
256
+ * the page: a list's row that comes after the list's first rows, as a presence tells it of a child
257
+ * entering. A `layout` element after it moves out of its way by animation. The list's first rows are
258
+ * laid out with the page, as any ward's mount is. Read once, at its mount.
259
+ */
260
+ mountMoves: boolean
261
+ /**
262
+ * Whether this leave can't be turned round: what it held as it left has ended, the wards of the
263
+ * twins it handed home. A presence then has its value wait and come back on a new element. Not
264
+ * reactive: read when its value comes back.
265
+ */
266
+ committed: boolean
267
+ /** Told once it's gone: its exit has landed and nothing holds it. A presence's cue for its next value. */
268
+ gone: () => void
269
+ /**
270
+ * Told that what it handed on holds it no more: a list's row whose item has a row of its own, with
271
+ * twins of its own. The handovers go on, the projection's to draw; it leaves by its own exit alone.
272
+ */
273
+ letGo: () => void
274
+ /**
275
+ * Told once it has gone, its `mounted` false, after its place in the layout and its exits have
276
+ * been seen to, in the one effect they share ({@link popping}). What a list does with a row then
277
+ * ({@link whenLeft}).
278
+ */
279
+ left: () => void
280
+ /**
281
+ * Whether its ward ends as it goes, never to be shown again: a list's row whose item has left the
282
+ * list ({@link whenLeft}). It has nowhere to rest while hidden, then, and isn't hidden. Asked as its
283
+ * `animate` and its `style` are read, after whoever made it has said how: a row hidden with its
284
+ * item still in the list doesn't end, and rests and is hidden as any `show` ward is.
285
+ */
286
+ ends: () => boolean
287
+ /**
288
+ * What's on the page, by identity: another once what was there has gone. Whether it's mounted, for a
289
+ * `show` ward; a presence's value, which one value takes over from another with nothing between.
290
+ * What its exits' ends are told by ({@link tellingExits}).
291
+ */
292
+ onPage: Accessor<unknown>
293
+ /**
294
+ * Whether what says it's shown may still arrive: a `show` a rune hasn't given yet, a presence that
295
+ * hasn't taken it. A read of `shown` or `mounted` made meanwhile is told when it does
296
+ * ({@link hearing}). Not reactive: read as each of those is.
297
+ */
298
+ awaited: boolean
299
+ /** The signal that tells those reads, made at the first of them: none for a ward nothing read early. */
300
+ told: readonly [get: Accessor<number>, set: (turn: (now: number) => number) => void] | undefined
301
+ /** A `show` wired before a function rune ran ({@link showingEarly}): the accessor a plain rune gave, and its memo. */
302
+ early: { readonly given: Accessor<boolean>; readonly shows: Shows } | undefined
303
+ }
304
+
305
+ /** A ward's state before any `show` is wired: always shown, always there. */
306
+ export const showState = (): ShowState => {
307
+ const state: ShowState = {
308
+ shown: ALWAYS,
309
+ mounted: ALWAYS,
310
+ leaves: ALWAYS,
311
+ exits: ALWAYS,
312
+ waits: constFalse,
313
+ followersLanded: ALWAYS,
314
+ counted: AT_ONCE,
315
+ landed: constVoid,
316
+ holds: 0,
317
+ released: constVoid,
318
+ turn: NO_TURN,
319
+ sweeps: false,
320
+ affectsLayout: true,
321
+ mountMoves: false,
322
+ committed: false,
323
+ gone: constVoid,
324
+ letGo: constVoid,
325
+ left: constVoid,
326
+ ends: NEVER,
327
+ // Read late: `show`'s wiring gives it its `mounted`.
328
+ onPage: () => state.mounted(),
329
+ awaited: true,
330
+ told: undefined,
331
+ early: undefined,
332
+ }
333
+ return state
334
+ }
335
+
336
+ /**
337
+ * Read with a ward's `shown` and `mounted`, and with what a presence says of it, where they're
338
+ * tracked: has what reads them told once the ward's word arrives, if it hasn't yet ({@link tell}).
339
+ *
340
+ * A ward says whether it's shown by its `show`, or by a presence that takes it, and both can come
341
+ * after something has read it. A function rune's body runs before its ward's config is known, and an
342
+ * effect or a memo made there runs at once; a presence takes a ward after `createWard` has handed it
343
+ * out, and after the ward's own target has read its `animate`. What read then read a ward with
344
+ * nothing wired, always shown, and followed nothing: it never heard the `show` or the presence that
345
+ * came after.
346
+ *
347
+ * So such a read follows one signal of its ward's, made at the first of them, and written at most
348
+ * once: as the page settles after the word has arrived, which is where Solid 2 allows the write (none
349
+ * while a component's body runs). The read runs again and finds what's wired by then. Nothing is
350
+ * made for a ward read only after its word is settled, which is every read made as it's rendered.
351
+ */
352
+ const hearing = (state: ShowState): void => {
353
+ // A server reads as it renders, after every ward of the page is made, and nothing settles there.
354
+ if (isServer) return
355
+ if (!state.awaited) return
356
+ if (Predicate.isUndefined(state.told)) state.told = createSignal(0)
357
+ state.told[0]()
358
+ }
359
+
360
+ /**
361
+ * Says `state`'s word has arrived, or that none ever will: reads from here on make nothing more, and
362
+ * whoever read before is told once the page has settled ({@link hearing}). Called under the owner
363
+ * the ward was made under, or the presence's.
364
+ */
365
+ const tell = (state: ShowState): void => {
366
+ state.awaited = false
367
+ const told = state.told
368
+ if (isServer) return
369
+ if (Predicate.isUndefined(told)) return
370
+ // Taken by a leaving row or value, nothing is settling: told now, from outside any computation.
371
+ if (takingLate) {
372
+ told[1]((turn) => turn + 1)
373
+ return
374
+ }
375
+ // The one write, where Solid 2 has one made. `void`: what a settle returns is its cleanup.
376
+ onSettledClientOnly(() => void told[1]((turn) => turn + 1))
377
+ }
378
+
379
+ // Module state (#460, Q7): whether a ward is being taken late, by a leaving row or value (`takenInside`),
380
+ // with no component being made and nothing settling. Set and reset in one synchronous call.
381
+ let takingLate = false
382
+
383
+ /** A ward's `show` through a memo, with how many times its answer has changed. */
384
+ interface Shows {
385
+ readonly show: Accessor<boolean>
386
+ /**
387
+ * The changes of `show` so far: what an exit's landing is checked against, so a later change makes
388
+ * an earlier landing stale with nothing to reset. From the same memo as `show`, where it was a
389
+ * memo of its own over it, a ward.
390
+ */
391
+ readonly turns: Accessor<number>
392
+ }
393
+
394
+ /**
395
+ * A `show` memo's next value from the one before: twice the changes so far, with one added while
396
+ * it's shown. The same value while the answer is the same, so what reads it runs again only when
397
+ * the answer changes. Worked out from the value before and nothing else: nothing is written from
398
+ * inside the memo.
399
+ */
400
+ const countedNext = (before: number | undefined, shown: boolean): number => {
401
+ if (Predicate.isUndefined(before)) return Number(shown)
402
+ const was = before % 2
403
+ if (was === Number(shown)) return before
404
+ return before - was + 2 + Number(shown)
405
+ }
406
+
407
+ /** `given` as a ward's `show` is read, through a memo: only a new answer is a change, and each one is counted. */
408
+ const shownBy = (given: Accessor<boolean>): Shows => {
409
+ const counted = createMemo<number>((before) => countedNext(before, given() === true))
410
+ return { show: () => counted() % 2 === 1, turns: () => (counted() - (counted() % 2)) / 2 }
411
+ }
412
+
413
+ /**
414
+ * A plain rune's `show` wired before any function rune of the ward runs, so what one reads of its
415
+ * ward in its own body is right from that first read: `shown()` is the memo `show`'s wiring then
416
+ * takes for its own ({@link showing}), and `mounted()` the same until that wiring makes its own, the
417
+ * two agreeing until the ward first leaves. A read made here follows the memo, runs again as `show`
418
+ * changes, and finds the wired `mounted` then.
419
+ */
420
+ const showingEarly = (state: ShowState, given: Accessor<boolean>): void => {
421
+ const shows = shownBy(given)
422
+ state.early = { given, shows }
423
+ state.shown = shows.show
424
+ state.mounted = shows.show
425
+ }
426
+
427
+ /** The memo wired early for `given`: none where no `show` was wired early, or another was. */
428
+ const wiredEarlyFor = (state: ShowState, given: Accessor<boolean> | undefined): Shows | undefined => {
429
+ const early = state.early
430
+ if (Predicate.isUndefined(early)) return undefined
431
+ if (early.given !== given) return undefined
432
+ return early.shows
433
+ }
434
+
435
+ /** `given` through a memo, as a ward's `show` is read: the one made early for it, where there is one. */
436
+ const showMemoOf = (state: ShowState, given: Accessor<boolean>): Shows => {
437
+ const early = wiredEarlyFor(state, given)
438
+ if (Predicate.isUndefined(early)) return shownBy(given)
439
+ return early
440
+ }
441
+
442
+ /** What a ward's exits are told by: whether it's shown, and what's on the page. */
443
+ interface Seen {
444
+ readonly shown: boolean
445
+ readonly on: unknown
446
+ }
447
+
448
+ /** Whether `on` is something on the page: a presence's value, or a `show` ward that's mounted. */
449
+ const isOn = (on: unknown): boolean => Predicate.isNotUndefined(on) && on !== false
450
+
451
+ /** Where a ward a hook shows keeps what brings its exits up to date, when it has no state to keep it by. */
452
+ const EXITS = Symbol("wardic.hooks.exits")
453
+
454
+ /**
455
+ * Something the hooks keep of `ward`: `of` what they keep of a client's (`kept.ts`), none where
456
+ * they've kept nothing of it; `own` for a ward with no state of its own, which carries it itself.
457
+ */
458
+ const keptElse = <A,>(ward: object, of: (kept: Kept) => A | undefined, own: () => A | undefined): A | undefined => {
459
+ if (!keepsState(ward)) return own()
460
+ const kept = keptFor(ward)
461
+ if (Predicate.isUndefined(kept)) return undefined
462
+ return of(kept)
463
+ }
464
+
465
+ /**
466
+ * Tells `ward` of its own exits, as a hook shows it and takes it away: `exitStart` as it starts to
467
+ * leave, `exitComplete` once what was on the page has gone. They're told to the ward's lifecycle, so
468
+ * its own `next`, `each` and `when` hear them, a `createRune(fn)`'s ward among them, and they end as
469
+ * every other wait of the ward's does.
470
+ *
471
+ * - **It turned round:** shown again, with what was on the page still there. Nothing completes.
472
+ * - **Nowhere to leave to:** it's gone in the flush it left in, so its start and its end are told together.
473
+ * - **One value after another** (a presence): the first has gone as the next takes its place.
474
+ *
475
+ * One effect a ward, over `state` as it's read then: called once its `shown` and `onPage` are the ones
476
+ * it goes by, after a presence has given its own. Throwaway: a real one tells them from the leave it
477
+ * already tracks, with no effect of its own.
478
+ */
479
+ export const tellingExits = (ward: Ward, state: ShowState): void => {
480
+ const settle = exitsOf(ward)
481
+ const seen = (): Seen => ({ shown: state.shown(), on: state.onPage() })
482
+ createEffect(seen, settle)
483
+ exitsBy(ward, () => settle(untrack(seen)))
484
+ }
485
+
486
+ /**
487
+ * What tells `ward` of its own exits, given where it is each time it's shown, hidden or gone
488
+ * ({@link tellingExits}'s rules). With no effect of its own: {@link tellingExits} gives it one, and a
489
+ * ward with a `show` of its own has it called from the one its place in the layout has ({@link popping}).
490
+ */
491
+ const exitsOf = (ward: Ward): ((now: Seen) => void) => {
492
+ const sensed = sensedOf(ward)
493
+ let was: Seen | undefined
494
+ let leaving = false
495
+ const tell = (name: ExitEvent): void => {
496
+ // A server's ward has no lifecycle, and nothing leaves there.
497
+ if (Predicate.isUndefined(sensed)) return
498
+ sensed.lifecycle.exited(name)
499
+ }
500
+ const settle = (now: Seen): void => {
501
+ const before = was
502
+ was = now
503
+ const leavingNow = !now.shown && isOn(now.on)
504
+ // Its first run: where it starts from, with nothing to tell.
505
+ if (Predicate.isUndefined(before)) {
506
+ leaving = leavingNow
507
+ return
508
+ }
509
+ // What was on the page has gone: its exit is complete, begun just now if it had nowhere to leave to.
510
+ if (now.on !== before.on && isOn(before.on)) {
511
+ if (!leaving) tell("exitStart")
512
+ leaving = false
513
+ tell("exitComplete")
514
+ }
515
+ if (leavingNow && !leaving) tell("exitStart")
516
+ leaving = leavingNow
517
+ }
518
+ return settle
519
+ }
520
+
521
+ /**
522
+ * Keeps `sync` as what brings `ward`'s exits up to date now ({@link exitsNow}): of a client's ward
523
+ * (`kept.ts`); its own property on one with no state to keep it by, not enumerable, so a spread
524
+ * never sees it.
525
+ */
526
+ const exitsBy = (ward: Ward, sync: () => void): void => {
527
+ if (keepsState(ward)) {
528
+ keptOf(ward).exits = sync
529
+ return
530
+ }
531
+ Object.defineProperty(ward, EXITS, { value: sync })
532
+ }
533
+
534
+ /**
535
+ * Brings `ward`'s exits up to date now, where it's about to be ended: a list's row is disposed in the
536
+ * flush its exit lands in, and its end is told first. Nothing for a ward whose exits aren't told.
537
+ */
538
+ export const exitsNow = (ward: object): void => {
539
+ const sync = keptElse(ward, (kept) => kept.exits, () => (ward as { readonly [EXITS]?: () => void })[EXITS])
540
+ if (Predicate.isUndefined(sync)) return
541
+ sync()
542
+ }
543
+
544
+ /** The leave a `show` ward's exit counts as landed in as it's made: none yet for one shown, the first for one hidden. */
545
+ const exitedAtFirst = (shown: boolean): number => {
546
+ if (shown) return -1
547
+ return 0
548
+ }
549
+
550
+ /** The wiring of `show` over `runes`, and its state in `state`; none without a `show`. */
551
+ export const showing =
552
+ (state: ShowState) =>
553
+ (runes: Joined): Shown | undefined => {
554
+ const given = runes.show
555
+ if (Predicate.isUndefined(given)) return undefined
556
+ // Its value, through a memo: an accessor such as `() => open().has(id)` runs again whenever what
557
+ // it reads changes, with the same answer most times, and only a new answer is a change here.
558
+ // The memo made early for it, where a function rune ran before this (`showingEarly`).
559
+ const shows = showMemoOf(state, given)
560
+ const show = shows.show
561
+ state.shown = show
562
+ // `show`'s changes so far, and each exit records the count it landed in: a later change of `show`
563
+ // makes an earlier landing stale with nothing to reset (as @solid-primitives/presence does).
564
+ const turnsNow = (): number => untrack(shows.turns)
565
+ // Written as its exit lands: from an effect's callback, or a frame or a handover's end after it.
566
+ const [exitedIn, setExitedIn] = createSignal<number>(exitedAtFirst(untrack(show)))
567
+ /** Where it goes to leave: its `exit`, else its `initial`; none with `exit: false`, or with neither. */
568
+ const exit = (): unknown => {
569
+ const own = runes.value("exit")
570
+ if (own === false) return undefined
571
+ if (Predicate.isNotUndefined(own)) return own
572
+ const initial = runes.value("initial")
573
+ if (initial === false) return undefined
574
+ return initial
575
+ }
576
+ /** Where it rests while hidden, to enter from: its `initial`, at once, when its `exit` went elsewhere. */
577
+ const rest = (leaving: unknown): unknown => {
578
+ if (Predicate.isUndefined(runes.value("exit"))) return leaving
579
+ const initial = runes.value("initial")
580
+ if (isPlain(initial)) return { ...initial, transition: { duration: 0 } }
581
+ if (Predicate.isUndefined(initial) || initial === false) return leaving
582
+ return initial
583
+ }
584
+ const exits = (): boolean => Predicate.isNotUndefined(exit())
585
+ // With no exit of its own, whether what's inside it or following it holds it, asked as it's
586
+ // hidden, of the page as it is then: untracked, a plain walk, with nothing written.
587
+ const waits = (): boolean => untrack(state.waits)
588
+ const mounted = createMemo<boolean>(() => {
589
+ if (show()) return true
590
+ if (!exits() && !waits()) return false
591
+ if (exitedIn() !== shows.turns()) return true
592
+ return !state.followersLanded()
593
+ })
594
+ state.mounted = mounted
595
+ state.turn = turnsNow
596
+ state.exits = exits
597
+ state.leaves = () => exits() || waits()
598
+ // The change of `show` its exit last landed in: it's gone once that's this one, and nothing holds it.
599
+ let landedIn = -1
600
+ const finish = (): void => {
601
+ if (untrack(show)) return
602
+ const now = turnsNow()
603
+ if (landedIn !== now) return
604
+ if (state.holds > 0) return
605
+ setExitedIn(now)
606
+ // Read as it's told: a presence that took the ward says what follows, in this same write.
607
+ state.gone()
608
+ }
609
+ state.landed = () => {
610
+ if (untrack(show)) return
611
+ landedIn = turnsNow()
612
+ // A leader's landing counts a frame on. One with nothing of its own to animate lands as it's told
613
+ // to leave, in the flush its followers are told in, before any of them reads as moving: counted
614
+ // then, it was gone with its followers' exits not yet begun, some runs and not others.
615
+ state.counted(finish)
616
+ }
617
+ state.released = finish
618
+ return {
619
+ animate: (shown) => {
620
+ if (show()) return shown
621
+ const leaving = exit()
622
+ if (Predicate.isUndefined(leaving)) return shown
623
+ // A ward that ends as it goes has nowhere to rest: it stays where it left to, and whether
624
+ // it's mounted isn't read for it, so nothing is worked out again as it goes.
625
+ if (state.ends()) return leaving
626
+ if (mounted()) return leaving
627
+ return rest(leaving)
628
+ },
629
+ style: (style) => {
630
+ // Nor is it hidden: it's off the page in the flush it goes in.
631
+ if (state.ends()) return style
632
+ if (mounted()) return style
633
+ if (Predicate.isString(style)) return `${style};display:none`
634
+ if (isPlain(style)) return { ...style, display: "none" }
635
+ return { display: "none" }
636
+ },
637
+ // Its exit is this wiring's to run, through `animate` above: none is left in the ward's own config.
638
+ exit: NO_EXIT,
639
+ custom: customAtLeave(runes, show),
640
+ }
641
+ }
642
+
643
+ /**
644
+ * `custom` as a ward that leaves reads it: the runes' own while it's shown, and the one it started to
645
+ * leave with from then until it's shown again. None for a ward whose runes give no `custom`.
646
+ *
647
+ * A presence reads its `custom` as each child leaves, since a child that has left takes nothing new.
648
+ * A hook's ward is still there as it leaves, and went on reading: a photo sliding off to the left
649
+ * turned back across the stage when the next change went the other way.
650
+ */
651
+ const customAtLeave = (runes: Joined, show: Accessor<boolean>): Shown["custom"] => {
652
+ if (!runes.has("custom")) return undefined
653
+ // Made again only as `show` changes: read once as it starts to leave, and not followed after.
654
+ const leftWith = createMemo<unknown>(() => {
655
+ if (show()) return undefined
656
+ return untrack(() => runes.value("custom"))
657
+ })
658
+ return (own) => {
659
+ if (show()) return own()
660
+ return leftWith()
661
+ }
662
+ }
663
+
664
+ /** The layout projection told that what's on the page has changed. */
665
+ const notified = (projection: { readonly notify: () => void }): void => projection.notify()
666
+
667
+ /** Where a list measured a row before the change, asked now. */
668
+ const boxNow = (box: () => PopBox | undefined): PopBox | undefined => box()
669
+
670
+ /** What `pin` sets on a popped element, taken off again when it comes back or has gone. */
671
+ const PINNED = ["position", "width", "height", "top", "bottom", "left", "right", "pointer-events"] as const
672
+
673
+ /** A popped element back in the flow: every property its pin set, removed. */
674
+ const unpin = (el: HTMLElement): void => Arr.forEach(PINNED, (property) => void el.style.removeProperty(property))
675
+
676
+ /** The edges a `pop` pins by, a ward's or a `<Presence>`'s: its top left for `true`, the corner it names, and none without one. */
677
+ export const popAnchorsOf = (pop: unknown): PopAnchors | undefined => {
678
+ if (pop === true || pop === "top-left") return { x: "left", y: "top" }
679
+ if (pop === "top-right") return { x: "right", y: "top" }
680
+ if (pop === "bottom-left") return { x: "left", y: "bottom" }
681
+ if (pop === "bottom-right") return { x: "right", y: "bottom" }
682
+ return undefined
683
+ }
684
+
685
+ // Module state (#460, Q7): each popping ward's anchors, held weakly by the ward, for a list to measure it by.
686
+ const POPS = new WeakMap<object, PopAnchors>()
687
+
688
+ /** A hook ward that has a `layoutId`: where its element is, and how to end it while that element stays. */
689
+ interface Twin {
690
+ readonly element: () => HTMLElement | undefined
691
+ readonly end: () => void
692
+ }
693
+
694
+ // Module state (#460, Q7): each hook ward that has a `layoutId`, kept while its owner lives. A leaving ward finds the twins inside its own element among them.
695
+ const TWINS = new Set<Twin>()
696
+
697
+ // Module state (#460, Q7): each twin's ward, held weakly. A leaving row leaves it to its own way of
698
+ // leaving (Q20): its handback.
699
+ const TWIN_WARDS = new WeakSet<object>()
700
+ // Module state (#460, Q7): each ward that follows another, held weakly. A leaving row leaves it to its
701
+ // own way of leaving (Q20): its leader's.
702
+ const FOLLOWING = new WeakSet<object>()
703
+
704
+ // Module state (#460, Q7; the gap grill's Q20): the ward each element was last handed to, held weakly by
705
+ // the element. Kept by the hooks alone (the code review of the gap grill's work): a component's ward isn't told.
706
+ const WARD_ON = new WeakMap<Element, Ward>()
707
+
708
+ // Module state (#460, Q7; the code review of the gap grill's work): the presence each hook ward was made
709
+ // under, held weakly by the ward, kept only for one made under a presence.
710
+ const PRESENCE_ON = new WeakMap<object, PresenceRecord.PresenceContextValue<Element>>()
711
+
712
+ /** The ward `el` was last handed to, if the hooks made it: how a leaving row or presence value finds the wards inside its element (Q20). */
713
+ const wardOn = (el: Element): Ward | undefined => WARD_ON.get(el)
714
+
715
+ /** The presence `ward` was made under, if any: what it watches its child's leave by ({@link watchedUnder}). */
716
+ const presenceOn = (ward: object): PresenceRecord.PresenceContextValue<Element> | undefined => PRESENCE_ON.get(ward)
717
+
718
+ // Module state (#460, Q7; the gap grill's Q29): in development, each hook ward whose `style` an element's
719
+ // props have read, held weakly. Nothing is added to it in a production build.
720
+ const STYLE_READ = new WeakSet<object>()
721
+ // Module state (#460, Q7; the gap grill's Q29, DW4): in development, each hook ward its `ref` has handed an
722
+ // element, as it's handed it, held weakly: what the warning below goes by. Its element itself is a signal's,
723
+ // and a hydration's writes land only after the ward's owner has settled. Nothing is added in a production build.
724
+ const HANDED = new WeakSet<object>()
725
+
726
+ /**
727
+ * What every ward the hooks make tells them, through its internals: each element it's handed, the
728
+ * presence it's made under, and, in development, that an element's props read its `style`. And what it
729
+ * tells the base ward: it carries its variants whatever its runes set (the follow grill's Q1), so a ward
730
+ * that follows it joins it however it names its states. One object, shared by every hook ward's internals.
731
+ */
732
+ export const HOOK_TOLD: Pick<WardInternals, "handed" | "madeUnder" | "styled" | "carries"> = {
733
+ handed: (element, ward) => {
734
+ WARD_ON.set(element, ward)
735
+ if (DEV) HANDED.add(ward)
736
+ },
737
+ madeUnder: (ward, presence) => void PRESENCE_ON.set(ward, presence),
738
+ styled: (ward) => void STYLE_READ.add(ward),
739
+ carries: true,
740
+ }
741
+
742
+ /**
743
+ * In development, a warning for a ward spread on a component that never calls its `ref` (the gap
744
+ * grill's Q29): an element's props read its `style`, so it was spread, and its `ref` hasn't been handed
745
+ * an element by the time its owner has settled. Asked of the `ref` itself, not of the element it set: a
746
+ * hydrated page's writes, that one's among them, land after its owners settle (DW4). Today's
747
+ * `create(Component)` fails such a component; a hook ward spread on it would otherwise move nothing, and
748
+ * say nothing. One whose `style` no element has read yet, a closed dialog's, isn't warned of. And the other
749
+ * way round (step 2 of the skill grill's order, Q20): its `ref` handed an element whose props read none of its
750
+ * `style`, a `style` beside the spread having replaced it. Nothing on a server, where no `ref` is called.
751
+ */
752
+ const warnsOfItsSpread = (ward: Ward): void => {
753
+ if (Predicate.isNull(getOwner())) return
754
+ onSettledClientOnly(() => {
755
+ const read = STYLE_READ.has(ward)
756
+ const handed = HANDED.has(ward)
757
+ if (Bool.and(read, Bool.not(handed))) report("WARDIC_REF_NOT_CALLED", UNFORWARDED)
758
+ // Its `ref` called and its `style` read by nothing: a `style` beside the spread replaced it (step 2, Q20).
759
+ if (Bool.and(handed, Bool.not(read))) report("WARDIC_STYLE_BESIDE_SPREAD", STYLE_BESIDE)
760
+ })
761
+ }
762
+
763
+ /** `ward`, made, with the warnings above for it in development, in a browser: every hook ward's make path ends here. */
764
+ const checked = (ward: Ward): Ward => {
765
+ if (DEV && !isServer) warnsOfItsSpread(ward)
766
+ return ward
767
+ }
768
+
769
+ const STYLE_BESIDE =
770
+ "createWard: the ward's `style` was replaced: a `style` beside its spread (`<div {...ward} style={…}>`), or a component that doesn't pass `props.style` on. Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`."
771
+
772
+ const UNFORWARDED =
773
+ "createWard: a ward was spread on a component that never called its `ref`, so no element is its and nothing it says will move. The component must pass `props.ref` to the element it renders (`<div ref={props.ref}>`), or spread its props on that element whole."
774
+
775
+ /** A ward that follows another, and whether its runes give it an `exit` of its own. */
776
+ interface Follower {
777
+ readonly ward: Ward
778
+ readonly exits: boolean
779
+ }
780
+
781
+ // Module state (#460, Q7): each leader's followers, held weakly by the leader, each one dropped as its
782
+ // owner ends. What a leader that leaves takes with it (the gap grill's Q12).
783
+ const FOLLOWERS = new WeakMap<object, Set<Follower>>()
784
+
785
+ /** Notes `follower` as one of `leader`'s, until the owner it's made under ends. */
786
+ const followsOf = (leader: object, follower: Follower): void => {
787
+ let all = FOLLOWERS.get(leader)
788
+ if (Predicate.isUndefined(all)) {
789
+ all = new Set()
790
+ FOLLOWERS.set(leader, all)
791
+ }
792
+ const kept = all
793
+ kept.add(follower)
794
+ if (Predicate.isNotNull(getOwner())) onCleanup(() => void kept.delete(follower))
795
+ }
796
+
797
+ /** Whether any of a ward's configs gives it a `layoutId`: a twin, which a leaving ward that holds it hands to its other. */
798
+ const hasLayoutId = (configs: ReadonlyArray<RuneConfig>): boolean => Arr.some(configs, (config) => "layoutId" in config)
799
+
800
+ /** The element `ward` is on now, read once and not followed. */
801
+ const elementOf = (ward: Ward): HTMLElement | undefined => {
802
+ const sensed = sensedOf(ward)
803
+ if (Predicate.isUndefined(sensed)) return undefined
804
+ return untrack(() => sensed.element())
805
+ }
806
+
807
+ /**
808
+ * The element `ward` is on while it's on show, followed: none while it's hidden or gone, by
809
+ * `mounted`, the same element again once it's shown again, and another as the ward moves to one. What
810
+ * its runes' `ref`s go by (`refs.ts`).
811
+ */
812
+ const elementOnShow =
813
+ (ward: Ward, mounted: Accessor<boolean>) =>
814
+ (): HTMLElement | undefined => {
815
+ if (!mounted()) return undefined
816
+ const sensed = sensedOf(ward)
817
+ if (Predicate.isUndefined(sensed)) return undefined
818
+ return sensed.element()
819
+ }
820
+
821
+ /**
822
+ * `refs` at work on `ward` (`refs.ts`): each handed the element it's on while `mounted` says that's on
823
+ * show. A `show` ward's, a ward's a presence took before it was on the page, and one's a presence takes
824
+ * after ({@link refsTaken}).
825
+ *
826
+ * Begun once the page has settled, where Solid has what needs an element on the page begin
827
+ * (`onSettled`), under the owner the ward was made under. Not as the ward is made: a presence gives a
828
+ * ward a `mounted` of its own after that, later in the same component's body, and what followed the
829
+ * first one had nothing to read the next by. A ward given its element as its `subject` and then
830
+ * taken by a presence was never undone. A signal written as the ward is taken had it read again,
831
+ * and was a write in a component's body, which Solid 2 doesn't allow; begun at the settle, the
832
+ * `mounted` it reads is already the one the ward goes by, and nothing is written.
833
+ */
834
+ const refsAtWork = (refs: ReadonlyArray<AnyRef>, ward: Ward, mounted: Accessor<boolean>): void => {
835
+ const owner = getOwner()
836
+ onSettledClientOnly(() => {
837
+ runWithOwner(owner, () => attending(refs, elementOnShow(ward, mounted), Option.none()))
838
+ })
839
+ }
840
+
841
+ /**
842
+ * The cheap `ref` (probe: behaviour-runes): a ward with no `show` has its runes' `ref`s run by its
843
+ * binding, as it mounts an element and as it lets it go (`afterMount`), and nothing of their own made
844
+ * for them. Nothing hides such a ward where it is, so the element it's mounted is its element on show,
845
+ * until a presence takes it: a presence's `createPresence`, or a leaving row that takes what's inside
846
+ * it (the gap grill's Q20). Its refs go by that presence's word from then on ({@link refsTaken}).
847
+ *
848
+ * They run as the binding's mount does, in the flush, where a `show` ward's run once it has settled:
849
+ * in the order their wards are mounted among themselves, before any of those (the owner's yes, 2026-11-30).
850
+ */
851
+ interface MountedRefs {
852
+ readonly refs: ReadonlyArray<AnyRef>
853
+ readonly mounted: Accessor<boolean>
854
+ /** The owner its binding was made under, set as it's made: a `layoutId` twin's root, else its ward's. */
855
+ owner: Owner | null
856
+ /** The element its refs are on, and what undoes them: none while they're on none. */
857
+ attended: Attended<HTMLElement> | undefined
858
+ /** Whether a presence has taken its ward, whose word they go by from then on. */
859
+ taken: boolean
860
+ }
861
+
862
+ /** Its runes' `ref`s, where it has any: none on a server, where nothing is on show. */
863
+ const refsIn = (seen: number | undefined, configs: ReadonlyArray<RuneConfig>): ReadonlyArray<AnyRef> | undefined => {
864
+ if (isServer) return undefined
865
+ if (!sawOf(seen, SEEN.ref)) return undefined
866
+ const refs = runeRefsOf(configs)
867
+ if (Arr.isReadonlyArrayEmpty(refs)) return undefined
868
+ return refs
869
+ }
870
+
871
+ /**
872
+ * `refs` for its binding to run, none run yet: a ward's with no `show` (the cheap `ref`). None for a
873
+ * ward with none, or with a `show`, whose `refs` go by it ({@link refsAtWork}).
874
+ */
875
+ const mountedRefsFor = (refs: ReadonlyArray<AnyRef> | undefined, show: unknown, mounted: Accessor<boolean>): MountedRefs | undefined => {
876
+ if (Predicate.isUndefined(refs)) return undefined
877
+ if (Predicate.isNotUndefined(show)) return undefined
878
+ return { refs, mounted, owner: null, attended: undefined, taken: false }
879
+ }
880
+
881
+ /** What the binding tells of each element it mounts (`afterMount`): `at`'s refs run on it, and undone as it goes. */
882
+ const afterMountOf =
883
+ (at: MountedRefs) =>
884
+ (element: HTMLElement): (() => void) => {
885
+ if (at.taken) return constVoid
886
+ const attended: Attended<HTMLElement> = { subject: element, undo: refsRun(at.refs, element) }
887
+ at.attended = attended
888
+ return () => {
889
+ // Handed to a presence's word since: that undoes them now.
890
+ if (at.attended !== attended) return
891
+ at.attended = undefined
892
+ attended.undo()
893
+ }
894
+ }
895
+
896
+ /**
897
+ * `ward`, whose refs `at` are, taken by a presence: they go by that presence's word from now, as a
898
+ * `show` ward's do. Once: a presence takes a ward once (`takenOf`, `takenLate`).
899
+ */
900
+ const refsTaken = (at: MountedRefs, ward: Ward): void => {
901
+ at.taken = true
902
+ const attended = at.attended
903
+ at.attended = undefined
904
+ runWithOwner(at.owner, () => refsByPresence(at, ward, attended))
905
+ }
906
+
907
+ /**
908
+ * Where `at`'s refs go by its presence's word from: on an element already, they're handed over as they
909
+ * are, not run again there, and undone once it says the element has gone. On none, taken before its
910
+ * binding mounted anything (`createPresence` in the body that made it), they begin at the settle, as a
911
+ * `show` ward's; taken late, as nothing settles (a leaving row's, held as its mount was), at once.
912
+ */
913
+ const refsByPresence = (at: MountedRefs, ward: Ward, attended: Attended<HTMLElement> | undefined): void =>
914
+ UndefinedOr.match(attended, {
915
+ onDefined: (already) => attending(at.refs, elementOnShow(ward, at.mounted), Option.some(already)),
916
+ onUndefined: () =>
917
+ Bool.match(takingLate, {
918
+ onTrue: () => attending(at.refs, elementOnShow(ward, at.mounted), Option.none()),
919
+ onFalse: () => refsAtWork(at.refs, ward, at.mounted),
920
+ }),
921
+ })
922
+
923
+ /**
924
+ * A twin's ward, made by `make` under a root of its own, so a leaving ward that holds it can end it
925
+ * while its element stays: what a framework does to a presence's leaving child, before the presence
926
+ * hands that child's twins back. Its root ends with the owner it's made under, if not sooner.
927
+ *
928
+ * The root is made on a server as in a browser, so both count the same hydration ids; only a browser
929
+ * keeps it among the twins, since nothing leaves on a server.
930
+ */
931
+ const twinOf = (make: () => Ward): Ward => {
932
+ let dispose: () => void = constVoid
933
+ const ward = createRoot((end) => {
934
+ dispose = end
935
+ return make()
936
+ })
937
+ // Handed home as a leaving ward starts to leave: not one a leaving row takes as well (Q20).
938
+ TWIN_WARDS.add(ward)
939
+ let ended = false
940
+ const twin: Twin = {
941
+ element: () => elementOf(ward),
942
+ end: () => {
943
+ if (ended) return
944
+ ended = true
945
+ TWINS.delete(twin)
946
+ dispose()
947
+ },
948
+ }
949
+ if (!isServer) TWINS.add(twin)
950
+ onCleanup(twin.end)
951
+ return ward
952
+ }
953
+
954
+ const NOT_ONE_ELEMENT = "createWard(...runes): its `subject` on the page is one element, or what resolves to one. Give it an element of its own, or spread the ward on one."
955
+
956
+ const isHtmlElement = (node: unknown): node is HTMLElement => node instanceof HTMLElement
957
+ const isSvgElement = (node: unknown): node is SVGElement => node instanceof SVGElement
958
+
959
+ /** Whether `node` is an element a ward moves: an HTML element, or an SVG one (the gap grill's Q23). */
960
+ const isWardElement: Predicate.Refinement<unknown, WardElement> = /*#__PURE__*/ Predicate.or(isHtmlElement, isSvgElement)
961
+
962
+ /** The one element `subject` is: itself, an accessor's, or the only one among a resolved child's nodes. */
963
+ const elementIn = (subject: unknown): WardElement | undefined => {
964
+ if (isWardElement(subject)) return subject
965
+ if (Predicate.isFunction(subject)) return elementIn(untrack(subject as () => unknown))
966
+ if (!Array.isArray(subject)) return undefined
967
+ const elements = Arr.filter(subject as ReadonlyArray<unknown>, isWardElement)
968
+ if (elements.length !== 1) return undefined
969
+ return elements[0]
970
+ }
971
+
972
+ /**
973
+ * The Subject a ward is given (a rune's `subject`), as the one element it is, found as the ward is made,
974
+ * before the base ward is: so an SVG element's own tag routes its keys from its first frame (Q23). In a
975
+ * browser alone: a server's markup is whoever rendered it.
976
+ */
977
+ const subjectElementOf = (subject: unknown): WardElement => {
978
+ const el = elementIn(subject)
979
+ if (Predicate.isUndefined(el)) throw misuse("WARDIC_SUBJECT_NOT_ONE_ELEMENT", NOT_ONE_ELEMENT)
980
+ return el
981
+ }
982
+
983
+ /** `internal` with `el`'s own tag where it's an SVG element, whose attribute keys render as attributes: as it is for an HTML one. */
984
+ const elementTagged = (internal: WardInternals, el: WardElement): WardInternals => {
985
+ if (!(el instanceof SVGElement)) return internal
986
+ return { ...internal, tag: el.localName }
987
+ }
988
+
989
+ /**
990
+ * `ward` put on the Subject it's given (a rune's `subject`): an element the hooks' caller didn't spread
991
+ * it on, another's to render, as a router's page is its layout's to move. What a spread of the ward on
992
+ * that element does, its `ref`, its `style` and its attributes, is done here.
993
+ *
994
+ * In a browser alone. A server's markup is whoever rendered the element's, so a ward given its Subject
995
+ * has no Starting style there: what's on the page as it opens should have no entrance (`enter: false`,
996
+ * or a list's `initial: false`).
997
+ *
998
+ * But for `propKeys`, the names its runes' `props` set there: those the hooks write themselves
999
+ * (`settingOn`, `props.ts`), a spread writing no attribute on a server's element as the page
1000
+ * hydrates, and the element getting back what it had under each once the ward's owner ends.
1001
+ */
1002
+ const putOn = (ward: Ward, el: WardElement, propKeys: PropKeys): void => {
1003
+ settingOn(el, propKeys)
1004
+ spread(el, ward, true, isOneOf(propKeys))
1005
+ }
1006
+
1007
+ /**
1008
+ * Whether a pass over a ward's runes saw `what` among them (`SEEN`, `rune.ts`). Yes where there was
1009
+ * no such pass, for runes that are joined: it's to be looked for then, as it was.
1010
+ */
1011
+ const sawOf = (seen: number | undefined, what: number): boolean => {
1012
+ if (Predicate.isUndefined(seen)) return true
1013
+ return (seen & what) !== 0
1014
+ }
1015
+
1016
+ /** No rune's `props`: most wards'. */
1017
+ const NO_PROP_KEYS: PropKeys = {}
1018
+
1019
+ /** `make`'s ward: a twin's under its own root, when any of `configs` gives it a `layoutId`, which `seen` says where it's known. */
1020
+ const wardFor = (configs: ReadonlyArray<RuneConfig>, make: () => Ward, seen?: number): Ward => {
1021
+ if (!sawOf(seen, SEEN.layoutId)) return make()
1022
+ if (hasLayoutId(configs)) return twinOf(make)
1023
+ return make()
1024
+ }
1025
+
1026
+ /** Whether `twin`'s element is inside `el`, and not `el` itself. */
1027
+ const within =
1028
+ (el: HTMLElement) =>
1029
+ (twin: Twin): boolean => {
1030
+ const other = twin.element()
1031
+ if (Predicate.isUndefined(other)) return false
1032
+ if (other === el) return false
1033
+ return el.contains(other)
1034
+ }
1035
+
1036
+ /** The edges `ward` is pinned by as it leaves, when it pops: what `createWards` measures a leaving row with. */
1037
+ export const popAnchorsFor = (ward: object): PopAnchors | undefined => POPS.get(ward)
1038
+
1039
+ /** One ward to pop: its element, its anchors, and what pins it and tells the projection once it's measured. */
1040
+ interface Pop {
1041
+ readonly el: HTMLElement
1042
+ readonly anchors: PopAnchors
1043
+ readonly pinAt: (box: PopBox | undefined) => void
1044
+ readonly told: () => void
1045
+ }
1046
+
1047
+ // Module state (#460, Q7): the wards leaving in this flush, popped together once its effects have run.
1048
+ const leavingNow: Array<Pop> = []
1049
+
1050
+ /**
1051
+ * Pops every ward that asked in this flush, in two passes: each one measured where it is, then each
1052
+ * one pinned. One at a time, a pin takes its ward out of the flow before the next is measured, which
1053
+ * then reads as having moved into its place: several leaving together all ended where the first was.
1054
+ */
1055
+ const popAll = (): void => {
1056
+ const pops = leavingNow.splice(0)
1057
+ const boxes = pops.map((pop) => popBoxOf(pop.el, pop.anchors, undefined))
1058
+ pops.forEach((pop, at) => {
1059
+ pop.pinAt(boxes[at])
1060
+ pop.told()
1061
+ })
1062
+ }
1063
+
1064
+ /** `pop`, with whatever else leaves in this flush: after its effects, before the browser paints. */
1065
+ const popTogether = (pop: Pop): void => {
1066
+ if (leavingNow.length === 0) queueMicrotask(popAll)
1067
+ leavingNow.push(pop)
1068
+ }
1069
+
1070
+ /**
1071
+ * A `show` ward's place in the layout: popped out of the flow as it starts to leave, when its `pop`
1072
+ * says so, and the layout projection told as it comes, pops and goes (a presence tells it the same,
1073
+ * `PresenceController`'s `projection.notify()`). Nothing with no `layout` Feature built, or on a server.
1074
+ */
1075
+ const popping = (ward: Ward, made: Joined, state: ShowState, exits: ((now: Seen) => void) | undefined): void => {
1076
+ if (Predicate.isUndefined(made.show)) return
1077
+ const show = state.shown
1078
+ const mounted = state.mounted
1079
+ const projection = useBuiltProjection()
1080
+ const anchors = popAnchorsOf(made.own("pop"))
1081
+ if (Predicate.isNotUndefined(anchors)) POPS.set(ward, anchors)
1082
+ state.waits = () => waitsAsItLeaves(ward, state)
1083
+ // What it does as it's hidden, shown again, gone or let go, made the first time one of those
1084
+ // happens: a ward that only ever mounts makes none of it. Every `show` ward made all of it as it
1085
+ // was wired, a dozen closures a ward, a list's row among them.
1086
+ let done: Popped | undefined
1087
+ const popped = (): Popped => {
1088
+ if (Predicate.isNotUndefined(done)) return done
1089
+ const now = poppedOf(ward, made, state, show, projection, anchors)
1090
+ done = now
1091
+ return now
1092
+ }
1093
+ onCleanup(() => {
1094
+ if (Predicate.isNotUndefined(done)) done.ended()
1095
+ })
1096
+ state.letGo = () => popped().letGo()
1097
+ let wasShown: boolean | undefined
1098
+ const shownIs = (shown: boolean): void => {
1099
+ const before = wasShown
1100
+ wasShown = shown
1101
+ // Its first run is its mount, which a `layout` node of its own measures as it registers. A row that
1102
+ // comes after its list's first pushes what's after it, which nothing else would tell the projection.
1103
+ if (Predicate.isUndefined(before)) {
1104
+ if (shown && state.mountMoves && state.affectsLayout) {
1105
+ const system = projection()
1106
+ if (Predicate.isNotUndefined(system)) system.notify()
1107
+ }
1108
+ return
1109
+ }
1110
+ if (before === shown) return
1111
+ popped().shown(shown)
1112
+ }
1113
+ let wasMounted = untrack(mounted)
1114
+ /** Whether it has just gone. */
1115
+ const mountedIs = (now: boolean): boolean => {
1116
+ if (now === wasMounted) return false
1117
+ wasMounted = now
1118
+ if (now) return false
1119
+ popped().gone()
1120
+ return true
1121
+ }
1122
+ // One effect for whether it's shown and whether it's mounted, where there were two, and its exits
1123
+ // told from it too where they go by the same two (`exits`: a ward with a `show` of its own, a
1124
+ // list's row), where that was a third. In the order the three ran in: shown, mounted, its exits.
1125
+ createEffect(
1126
+ () => Number(show()) + 2 * Number(mounted()),
1127
+ (now) => {
1128
+ const shown = now % 2 === 1
1129
+ const on = now >= 2
1130
+ shownIs(shown)
1131
+ const went = mountedIs(on)
1132
+ if (Predicate.isNotUndefined(exits)) exits({ shown, on })
1133
+ // Last, as a list's own effect over its row came last: its row is dropped, and its ward ended.
1134
+ if (went) state.left()
1135
+ },
1136
+ )
1137
+ }
1138
+
1139
+ /** What a `show` ward's place in the layout does, as each thing happens to it ({@link popping}). */
1140
+ interface Popped {
1141
+ /** It's shown again, or hidden: after its mount. */
1142
+ readonly shown: (shown: boolean) => void
1143
+ /** It's gone: hidden by its `style`. */
1144
+ readonly gone: () => void
1145
+ /** What it handed on holds it no more ({@link ShowState.letGo}). */
1146
+ readonly letGo: () => void
1147
+ /** Its ward has ended. */
1148
+ readonly ended: () => void
1149
+ }
1150
+
1151
+ /**
1152
+ * What a `show` ward's place in the layout does ({@link Popped}), made the first time something
1153
+ * happens to it past its mount: it's hidden, shown again, let go of or ended. A ward that's shown
1154
+ * from its mount to its end makes none of it.
1155
+ */
1156
+ const poppedOf = (
1157
+ ward: Ward,
1158
+ made: Joined,
1159
+ state: ShowState,
1160
+ show: Accessor<boolean>,
1161
+ projection: ReturnType<typeof useBuiltProjection>,
1162
+ anchors: PopAnchors | undefined,
1163
+ ): Popped => {
1164
+ const sensed = sensedOf(ward)
1165
+ const told = (): void => {
1166
+ if (!state.affectsLayout) return
1167
+ UndefinedOr.map(projection(), notified)
1168
+ }
1169
+ let pinned: HTMLElement | undefined
1170
+ const back = (): void => {
1171
+ if (Predicate.isUndefined(pinned)) return
1172
+ unpin(pinned)
1173
+ pinned = undefined
1174
+ }
1175
+ // The `layoutId` twins inside its element, handed to their other twins as it starts to leave, in a
1176
+ // presence's own order (ADR-0010 *Amendment (#181)*): each twin's ward ends, its element kept, as a
1177
+ // framework disposes a presence's leaving child; then the projection brings them back as leaving
1178
+ // Followers of their Leads (`handBackWithin`), which fly home. It stays on the page until every
1179
+ // handover has ended, as until its own exit lands.
1180
+ //
1181
+ // Telling the projection of each twin while its ward lived (`handleLeave`'s live branch) was tried
1182
+ // first: a twin still flying to its place as the leave began kept that flight running underneath,
1183
+ // and as it ended the element was drawn at rest for a frame, the view flashing open as it closed.
1184
+ let leaves = 0
1185
+ const handBack = (el: HTMLElement): void => {
1186
+ const system = projection()
1187
+ if (Predicate.isUndefined(system)) return
1188
+ const inside = Arr.filter(Arr.fromIterable(TWINS), within(el))
1189
+ leaves += 1
1190
+ const leave = leaves
1191
+ Arr.forEach(inside, (twin) => twin.end())
1192
+ // With twins of its own ended, there's no turning round: a presence has its value come back afresh.
1193
+ if (!Arr.isArrayEmpty(inside)) state.committed = true
1194
+ // Asked whether it ended any or none: a page its router has just disposed holds twins the same
1195
+ // way, their wards ended by the navigation and not by it.
1196
+ const ask = (): void => {
1197
+ if (leave !== leaves) return
1198
+ // Its own layout node, if it has one, lives on while it leaves (`live`): a row that lays out.
1199
+ const drop = system.handBackWithin(
1200
+ el,
1201
+ () => {
1202
+ // A handover from a leave it has since turned round from: nothing of this one to let go.
1203
+ if (leave !== leaves) return
1204
+ state.holds -= 1
1205
+ state.released()
1206
+ },
1207
+ true,
1208
+ )
1209
+ if (Option.isSome(drop)) {
1210
+ state.holds += 1
1211
+ dropHeld = drop.value
1212
+ }
1213
+ // What it still holds with no other to take it stays a later twin's to take while it's on the
1214
+ // page (ADR-0010 *Amendment (#402)*), and one that does holds it for that handover. Kept this way
1215
+ // so it can be ended as the element goes: left to a task's end, a twin nobody took kept its record
1216
+ // for as long as nothing asked, and a card made much later flew in from where it had been.
1217
+ forget = system.keepLeaving(el, () => {
1218
+ // Taken after it let go, or turned round: not this leave's to hold for.
1219
+ if (leave !== leaves) return constVoid
1220
+ state.holds += 1
1221
+ return () => {
1222
+ if (leave !== leaves) return
1223
+ state.holds -= 1
1224
+ state.released()
1225
+ }
1226
+ })
1227
+ }
1228
+ // A twin it holds with no other on the page yet: that one may come later in this update, a page
1229
+ // the router is still mounting, so it's asked at the task's end, as a presence decides (#482).
1230
+ if (system.awaitsTwin(el)) {
1231
+ queueMicrotask(ask)
1232
+ return
1233
+ }
1234
+ ask()
1235
+ }
1236
+ // What the projection keeps of it while it leaves, ended as it goes or comes back.
1237
+ let forget: (() => void) | undefined
1238
+ const forgetKept = (): void => {
1239
+ const end = forget
1240
+ if (Predicate.isUndefined(end)) return
1241
+ forget = undefined
1242
+ end()
1243
+ }
1244
+ // The handovers of what it handed back, dropped at once: as its ward ends with any still running.
1245
+ let dropHeld: (() => void) | undefined
1246
+ const ended = (): void => {
1247
+ // A leave still to be asked about at its task's end is nobody's once its ward has ended.
1248
+ leaves += 1
1249
+ const drop = dropHeld
1250
+ dropHeld = undefined
1251
+ if (Predicate.isNotUndefined(drop)) drop()
1252
+ forgetKept()
1253
+ }
1254
+ // What it handed on holds it no more (a list's row whose item has a row of its own): the handovers
1255
+ // run on, hidden or drawn by the projection, until its ward ends; a twin that comes later isn't its
1256
+ // to wait for; and it's gone as its own exit lands, or now if that has.
1257
+ const letGo = (): void => {
1258
+ leaves += 1
1259
+ state.holds = 0
1260
+ forgetKept()
1261
+ state.released()
1262
+ }
1263
+ /**
1264
+ * It's shown again: what still held it lets go. A presence's ward that handed twins home is shown
1265
+ * again only on a new element, with twins of its own; a `show` ward's turns round where it is, its
1266
+ * twins' wards ended and not coming back.
1267
+ */
1268
+ const takeBack = (): void => {
1269
+ leaves += 1
1270
+ state.holds = 0
1271
+ state.committed = false
1272
+ forgetKept()
1273
+ }
1274
+ /** The element it's on now, read where it's used and not followed: an effect's callback doesn't track. */
1275
+ const elementNow = (): HTMLElement | undefined => {
1276
+ if (Predicate.isUndefined(sensed)) return undefined
1277
+ return untrack(() => sensed.element())
1278
+ }
1279
+ // What it has taken to leave with it, held for at each of its leaves until their exits land: the
1280
+ // wards inside a row's or a presence value's element (Q20), and its followers with an exit of their own (Q12).
1281
+ const swept: Array<ShowState> = []
1282
+ /**
1283
+ * Its leave, for what leaves with it. A row's or a presence value's element: the wards inside it,
1284
+ * still alive as it stays to leave (Q20). Any leader's followers with an `exit` of their own, which
1285
+ * they'd never run by its variant names alone (Q12). Taken a microtask on, out of the effect phase,
1286
+ * where Solid makes nothing even under an owner given it; it stays until each one's exit has landed.
1287
+ */
1288
+ const leaveWithIt = (el: HTMLElement): void => {
1289
+ queueMicrotask(() => {
1290
+ if (untrack(state.shown)) return
1291
+ if (state.sweeps) sweepInside(el, ward, state.shown, swept)
1292
+ followersLeaving(ward, state.shown, swept)
1293
+ Arr.forEach(swept, (inner) => {
1294
+ if (!untrack(inner.leaves)) return
1295
+ inner.gone = holdOn(state)()
1296
+ })
1297
+ // With no exit of its own, it has nothing to land: its leave is landed now, and it's gone once
1298
+ // what it took has let it go, or at once if it took nothing that leaves.
1299
+ if (!untrack(state.exits)) state.landed()
1300
+ })
1301
+ }
1302
+ const shownTo = (shown: boolean): void => {
1303
+ if (shown) takeBack()
1304
+ if (!shown && untrack(state.leaves)) {
1305
+ const leaving = elementNow()
1306
+ // The projection reads each twin's options as it hands it over, once, as at a mount: untracked, so said.
1307
+ if (Predicate.isNotUndefined(leaving)) {
1308
+ untrack(() => handBack(leaving))
1309
+ leaveWithIt(leaving)
1310
+ }
1311
+ }
1312
+ if (shown) {
1313
+ back()
1314
+ told()
1315
+ return
1316
+ }
1317
+ if (Predicate.isNotUndefined(anchors) && untrack(state.leaves)) popOut(anchors)
1318
+ told()
1319
+ }
1320
+ /** It pops as it leaves (`pop`), by `anchors`: its element, where it's on one, pinned where it is. */
1321
+ const popOut = (anchors: PopAnchors): void => {
1322
+ const el = elementNow()
1323
+ if (Predicate.isUndefined(el)) return
1324
+ // Where it was before the change, when a list measured it then (`createWards`); else where it is,
1325
+ // measured with every other ward leaving in this flush, before any of them is pinned.
1326
+ const ahead = UndefinedOr.map(made.own("popBox") as (() => PopBox | undefined) | undefined, boxNow)
1327
+ const pinAt = (box: PopBox | undefined): void => {
1328
+ if (Predicate.isUndefined(box)) return
1329
+ if (untrack(show)) return
1330
+ pin(box)
1331
+ pinned = el
1332
+ }
1333
+ UndefinedOr.match(ahead, { onDefined: pinAt, onUndefined: () => popTogether({ el, anchors, pinAt, told }) })
1334
+ }
1335
+ // Gone: hidden by its `style`, so its pin comes off, and what's beside it closes up if it wasn't popped.
1336
+ const gone = (): void => {
1337
+ back()
1338
+ forgetKept()
1339
+ told()
1340
+ }
1341
+ return { shown: shownTo, gone, letGo, ended }
1342
+ }
1343
+
1344
+ /** A rune that's a config as it's written: not a `createRune(fn)`, whose config isn't known until it has run. */
1345
+ const isWrittenConfig = (rune: Rune): rune is RuneConfig => !isFunctionRune(rune)
1346
+
1347
+ /**
1348
+ * `key` as the runes written as configs give it, the last of them that gives one, as a later rune's
1349
+ * wins when they join: what's known of it before a `createRune(fn)` among them has run, whose ward is
1350
+ * made before its config is known.
1351
+ */
1352
+ const knownBeforeFunctionRunes = <K extends "follow" | "show">(runes: ReadonlyArray<Rune>, key: K): RuneConfig[K] | undefined =>
1353
+ // Found from the last rune back, with no list made on the way. Read untracked, as the ward's made:
1354
+ // a getter's is read for what it is now, not followed.
1355
+ untrack(() =>
1356
+ Option.getOrUndefined(
1357
+ Option.map(
1358
+ Arr.findLast(runes, (rune): rune is RuneConfig => isWrittenConfig(rune) && Predicate.isNotUndefined(rune[key])),
1359
+ (rune) => rune[key],
1360
+ ),
1361
+ ),
1362
+ )
1363
+
1364
+ /**
1365
+ * `internal` with the tag the last of `configs` to name one gives (a function rune's among them, run
1366
+ * by now), so an SVG element's attribute keys render as attributes: as it is where none names one.
1367
+ * Read untracked, as the ward's made.
1368
+ */
1369
+ const taggedOf = (internal: WardInternals, configs: ReadonlyArray<RuneConfig>): WardInternals => {
1370
+ const tag = untrack(() => Option.getOrUndefined(Option.map(Arr.findLast(configs, (config) => Predicate.isNotUndefined(config.tag)), (config) => config.tag)))
1371
+ if (Predicate.isUndefined(tag)) return internal
1372
+ return { ...internal, tag }
1373
+ }
1374
+
1375
+ /**
1376
+ * `internal`, told its ward can never want a gesture where `has` gives none of `GESTURE_KEYS` (#525's
1377
+ * `gestureless`, as today's elements tell it). A ward's keys are fixed as it's made, so one that names
1378
+ * no gesture watches for one only from a first want through its lifecycle (a `when("hover")`), and
1379
+ * makes no computation for gestures until then: a hook ward made one every time (the gap grill's
1380
+ * Q27, the utility `w.div`'s computation more than today's). Its factory's `kind` told so is kept, so a
1381
+ * ward made with it as it is makes no internals of its own.
1382
+ */
1383
+ const gesturesTold = (internal: WardInternals, kind: WardInternals, has: (key: string) => boolean): WardInternals => {
1384
+ if (internal.gestureless === true) return internal
1385
+ // One sharing another's lifecycle, a function rune's (`share`), is told its wants through that
1386
+ // one's: what reads `hovering` there wants its gesture, and only its own watch would start it here.
1387
+ if (Predicate.isNotUndefined(internal.share)) return internal
1388
+ if (Arr.some(GESTURE_KEYS, (key) => has(key))) return internal
1389
+ if (internal === kind) return gesturelessKind(kind)
1390
+ return { ...internal, gestureless: true }
1391
+ }
1392
+
1393
+ /**
1394
+ * Each factory's internals, told gestureless: made as a factory's are first asked for, by `gesturelessKind`.
1395
+ *
1396
+ * Module state (#460, Q7): held weakly by the internals it's for, so it goes with them.
1397
+ */
1398
+ const GESTURELESS = new WeakMap<WardInternals, WardInternals>()
1399
+
1400
+ /** `kind`, a factory's internals, told gestureless, kept for the next ward it makes. */
1401
+ const gesturelessKind = (kind: WardInternals): WardInternals => {
1402
+ const kept = GESTURELESS.get(kind)
1403
+ if (Predicate.isNotUndefined(kept)) return kept
1404
+ const told: WardInternals = { ...kind, gestureless: true }
1405
+ GESTURELESS.set(kind, told)
1406
+ return told
1407
+ }
1408
+
1409
+ /** The ward's `follow`, as the runes written as configs give it: a function rune's ward is made under it. */
1410
+ const followOf = (runes: ReadonlyArray<Rune>): RuneConfig["follow"] => knownBeforeFunctionRunes(runes, "follow")
1411
+
1412
+ /** A follower's options: the ward it follows, its variant parent. */
1413
+ const parentOptions = <P>(parent: P): { readonly parent: P } => ({ parent })
1414
+
1415
+ /**
1416
+ * Where one ward's Features come from: its internals, what's told its config before it's made, and
1417
+ * what's done to each ward made with them.
1418
+ */
1419
+ export interface Begun {
1420
+ readonly kind: WardInternals
1421
+ /** Told its config before it's made, as its keys read then: asked for only by one whose Features are found by it. */
1422
+ readonly config: (config: () => ReadByKey) => void
1423
+ readonly made: (ward: Ward) => Ward
1424
+ /** Asks for more Features before its ward is made: a behaviour's drag, where its Features are found by its config. */
1425
+ readonly want?: ((names: ReadonlyArray<AutoFeature>) => void) | undefined
1426
+ /**
1427
+ * What makes the binding's ward of a config, where it isn't a plain ward: a Reorder group's item
1428
+ * (`reorder.ts`). Left out, `wardWith`. Handed the names its runes' `props` set too (`props.ts`),
1429
+ * for one whose binding sets some of them itself and takes its own config's for those.
1430
+ */
1431
+ readonly make?: ((config: WardConfig, internal: WardInternals, propKeys: PropKeys) => Ward) | undefined
1432
+ }
1433
+
1434
+ /** The binding's ward of `config`: `begun`'s own maker's, else a plain ward. */
1435
+ const bindingWardOf = (begun: Begun, config: WardConfig, internal: WardInternals, propKeys: PropKeys): Ward => {
1436
+ const make = begun.make
1437
+ if (Predicate.isUndefined(make)) return wardWith(config, internal)
1438
+ return make(config, internal, propKeys)
1439
+ }
1440
+
1441
+ /** A ward's readiness, as its `next` and its `when` give it. */
1442
+ export interface Ready {
1443
+ readonly next: () => Promise<undefined>
1444
+ readonly when: () => Accessor<undefined>
1445
+ }
1446
+
1447
+ /**
1448
+ * `"ready"` for a ward whose Features are `instance`'s (probe: hooks-first): one promise, made the
1449
+ * first time it's asked for and kept, resolved once none of them is still on its way. So it can't be
1450
+ * missed: asked for after the last has arrived, it's resolved already.
1451
+ *
1452
+ * Nothing is made for a ward nobody asks: what follows its Features is one effect, under the owner the
1453
+ * ward was made under, started at the first ask.
1454
+ */
1455
+ const readyOf = (instance: Feature.InstanceFeatures, owner: Owner | null): Ready => {
1456
+ let arrived: Promise<undefined> | undefined
1457
+ const next = (): Promise<undefined> => {
1458
+ if (Predicate.isNotUndefined(arrived)) return arrived
1459
+ const landing = new Promise<undefined>((resolve) => {
1460
+ runWithOwner(owner, () => {
1461
+ // The ward's own Features on this page: the loads its elements started, or start now.
1462
+ const own = useInstanceFeatures(instance)
1463
+ createEffect(
1464
+ () => own.pending(),
1465
+ (pending) => {
1466
+ if (!pending) resolve(undefined)
1467
+ },
1468
+ CLIENT_ONLY,
1469
+ )
1470
+ })
1471
+ })
1472
+ arrived = landing
1473
+ return landing
1474
+ }
1475
+ return {
1476
+ next,
1477
+ // Its promise is made here, where it's asked for, and only read in the memo: a promise made
1478
+ // inside a computation while the page hydrates is one that never settles.
1479
+ when: () => {
1480
+ const landing = next()
1481
+ return createMemo<undefined>(() => landing, { equals: false })
1482
+ },
1483
+ }
1484
+ }
1485
+
1486
+ const READY = "ready"
1487
+
1488
+ /**
1489
+ * A ward's own `when`, `next` and `each`, over the ones every ward shares. A gesture's event asks for
1490
+ * its Feature as it's first listened to (`ask`), and `"ready"` is the hooks' to tell ({@link readyOf}),
1491
+ * of the Features `instance` brings.
1492
+ */
1493
+ const withOwnEvents = (ward: Ward, ask: (name: AutoFeature) => void, instance: Feature.InstanceFeatures): Ward => {
1494
+ // Told what they go by, and no more: its `when`, `next` and `each` are every ward's ({@link SHARED}),
1495
+ // each made for this ward the first time it's read. What its reads go by too (`reads.ts`).
1496
+ const kept = keptOf(ward)
1497
+ kept.ask = ask
1498
+ kept.instance = instance
1499
+ kept.owner = getOwner()
1500
+ return ward
1501
+ }
1502
+
1503
+ /** `kept`'s ward's readiness, made the first time it's asked for. */
1504
+ const readinessOf = (kept: Kept, instance: Feature.InstanceFeatures): Ready => {
1505
+ const known = kept.ready
1506
+ if (Predicate.isNotUndefined(known)) return known
1507
+ const made = readyOf(instance, kept.owner)
1508
+ kept.ready = made
1509
+ return made
1510
+ }
1511
+
1512
+ /** The members every ward shares as they were, before the hooks' own took their place: what a ward the hooks didn't make still reads, and what theirs listen through. */
1513
+ const SHARED_BEFORE = { when: sharedMember("when"), next: sharedMember("next"), each: sharedMember("each") }
1514
+
1515
+ /**
1516
+ * One of a hooks ward's `when`, `next` and `each`, for `kept`'s ward: `shared` with a gesture's
1517
+ * Feature asked for as its event is first listened to, and `"ready"` told by the hooks. `each` has
1518
+ * no `"ready"`: it's a moment, not a stream.
1519
+ */
1520
+ const listening = (member: "when" | "next" | "each", kept: Kept, ask: (name: AutoFeature) => void, instance: Feature.InstanceFeatures, shared: Listening): Listening => {
1521
+ const through = (event: string): unknown => {
1522
+ const feature = featureOfEvent(event)
1523
+ if (Predicate.isNotUndefined(feature)) ask(feature)
1524
+ return shared(event)
1525
+ }
1526
+ if (member === "each") return through
1527
+ return (event) => {
1528
+ if (event === READY) return readinessOf(kept, instance)[member]()
1529
+ return through(event)
1530
+ }
1531
+ }
1532
+
1533
+ /** A ward's own exits: what one made under a presence hears of its own waiters ({@link Watched}). */
1534
+ const EXIT_NAMES: ReadonlySet<string> = new Set<string>(["exitStart", "exitComplete"])
1535
+
1536
+ /** `member` of `watched`'s exits, for one of their names. */
1537
+ const watchedExit = (member: "when" | "next" | "each", watched: Watched, event: PresenceEvent): unknown => {
1538
+ if (member === "next") return watched.waiters.wait(event)
1539
+ if (member === "each") return eachOf<PresenceEvents, PresenceEvent>(watched.waiters, event)
1540
+ return whenOf<PresenceEvents, PresenceEvent>(watched.waiters, event)
1541
+ }
1542
+
1543
+ /** `base`, its exits heard of `watched` where the ward was made under a presence. */
1544
+ const watchedListening = (member: "when" | "next" | "each", watched: Watched, base: Listening): Listening => (event) => {
1545
+ if (EXIT_NAMES.has(event)) return watchedExit(member, watched, event as PresenceEvent)
1546
+ return base(event)
1547
+ }
1548
+
1549
+ /**
1550
+ * `member` as every ward shares it: the hooks' own for a ward with Features of its own, and its exits
1551
+ * its own waiters' for one made under a presence, made at its first read and kept; as it was for any other.
1552
+ */
1553
+ const sharedListening = (member: "when" | "next" | "each"): PropertyDescriptor => ({
1554
+ configurable: true,
1555
+ get(this: object): Listening {
1556
+ const shared = SHARED_BEFORE[member].call(this)
1557
+ const kept = keptFor(this)
1558
+ if (Predicate.isUndefined(kept)) return shared
1559
+ const made = kept[member]
1560
+ if (Predicate.isNotUndefined(made)) return made
1561
+ const ask = kept.ask
1562
+ const instance = kept.instance
1563
+ let base = shared
1564
+ if (Predicate.isNotUndefined(ask) && Predicate.isNotUndefined(instance)) base = listening(member, kept, ask, instance, shared)
1565
+ const watched = kept.watched
1566
+ let own = base
1567
+ if (Predicate.isNotUndefined(watched)) own = watchedListening(member, watched, base)
1568
+ if (own === shared) return shared
1569
+ kept[member] = own
1570
+ return own
1571
+ },
1572
+ })
1573
+
1574
+ /**
1575
+ * What the hooks give every client ward to share (`shareMembers`, `ward.tsx`), once, as they load:
1576
+ * whether it's mounted, shown and leaving, its six reads, and their own `when`, `next` and `each`.
1577
+ * Each reads what the hooks keep of the ward it's read on (`kept.ts`), so a ward carries nothing
1578
+ * for them. A ward the hooks didn't make reads as one with no `show`: on the page, shown, not leaving.
1579
+ */
1580
+ const SHARED: PropertyDescriptorMap = {
1581
+ mounted: {
1582
+ configurable: true,
1583
+ get(this: object): Accessor<boolean> {
1584
+ const kept = keptFor(this)
1585
+ if (Predicate.isUndefined(kept)) return ALWAYS
1586
+ return kept.mounted
1587
+ },
1588
+ },
1589
+ shown: {
1590
+ configurable: true,
1591
+ get(this: object): Accessor<boolean> {
1592
+ const kept = keptFor(this)
1593
+ if (Predicate.isUndefined(kept)) return ALWAYS
1594
+ return kept.shown
1595
+ },
1596
+ },
1597
+ exiting: {
1598
+ configurable: true,
1599
+ get(this: object): Accessor<boolean> {
1600
+ const kept = keptFor(this)
1601
+ if (Predicate.isUndefined(kept)) return NEVER
1602
+ const made = kept.exiting
1603
+ if (Predicate.isNotUndefined(made)) return made
1604
+ const exiting = (): boolean => !kept.shown() && kept.mounted()
1605
+ kept.exiting = exiting
1606
+ return exiting
1607
+ },
1608
+ },
1609
+ hold: {
1610
+ configurable: true,
1611
+ get(this: object): () => () => void {
1612
+ // A function rune's ward holds the leave of the ward it's part of.
1613
+ const kept = keptFor(onOf(this as Ward))
1614
+ if (Predicate.isUndefined(kept)) return NO_HOLD
1615
+ const made = kept.hold
1616
+ if (Predicate.isNotUndefined(made)) return made
1617
+ const state = leavingOf(kept)
1618
+ const watched = kept.watched
1619
+ if (Predicate.isUndefined(state)) return NO_HOLD
1620
+ let hold = holdOn(state)
1621
+ // Made under a presence: its leave is that presence's to hold, unless one of the hooks' took it.
1622
+ if (Predicate.isNotUndefined(watched)) hold = heldBy(kept, watched, hold)
1623
+ kept.hold = hold
1624
+ return hold
1625
+ },
1626
+ },
1627
+ ...READS,
1628
+ when: sharedListening("when"),
1629
+ next: sharedListening("next"),
1630
+ each: sharedListening("each"),
1631
+ }
1632
+
1633
+ /**
1634
+ * `ward.hold()` for a ward made under a presence ({@link watchedUnder}): the presence's hold on the leave
1635
+ * under way, from its leave to its end; nothing before or after. `own`, where a presence of the hooks'
1636
+ * has taken it since, and its leave is that one's.
1637
+ */
1638
+ const heldBy =
1639
+ (kept: Kept, watched: Watched, own: () => () => void) =>
1640
+ (): (() => void) => {
1641
+ if (takenNow(kept)) return own()
1642
+ const late = watched.late
1643
+ if (Predicate.isUndefined(late)) return constVoid
1644
+ return late()
1645
+ }
1646
+
1647
+ /** The state a ward leaves by, where a hook shows it: its `show`'s or a list row's, or a presence's that may take it. */
1648
+ const leavingOf = (kept: Kept): ShowState | undefined => {
1649
+ const show = kept.show
1650
+ if (Predicate.isNotUndefined(show)) return show
1651
+ const take = kept.take
1652
+ if (Predicate.isUndefined(take)) return undefined
1653
+ return take.state
1654
+ }
1655
+
1656
+ /**
1657
+ * `ward.hold()` for a ward that leaves by `state` (Q15): one more thing keeping it on the page, as the
1658
+ * `layoutId` handovers it gave back do ({@link ShowState.holds}), until the release it hands back.
1659
+ * Nothing, where it isn't leaving. Its turn round lets every hold go (`takeBack`), so a release from
1660
+ * an earlier leave does nothing.
1661
+ */
1662
+ const holdOn =
1663
+ (state: ShowState) =>
1664
+ (): (() => void) => {
1665
+ if (untrack(state.shown) || !untrack(state.mounted)) return constVoid
1666
+ const turn = state.turn()
1667
+ state.holds += 1
1668
+ let released = false
1669
+ return () => {
1670
+ if (released) return
1671
+ released = true
1672
+ if (state.turn() !== turn) return
1673
+ state.holds -= 1
1674
+ state.released()
1675
+ }
1676
+ }
1677
+ // Module state (#460, Q7): the one prototype every client ward shares has the hooks' members added
1678
+ // to it, once, as this module loads. Nothing a ward made before it reads differently: the members
1679
+ // here are the hooks' own, and the three that take a base member's place answer as it did for a
1680
+ // ward the hooks keep nothing of.
1681
+ shareMembers(SHARED)
1682
+
1683
+ /** A ward's Features from `kind`, the same for every ward: a `makeWard` given its Features. */
1684
+ export const fixed = (kind: WardInternals): (() => Begun) => {
1685
+ const instance = kind.instance
1686
+ // A server's ward hears nothing, and one with no Features of its own (a Reorder's row) is left as it is.
1687
+ const made = (ward: Ward): Ward => {
1688
+ if (isServer) return ward
1689
+ if (Predicate.isUndefined(instance)) return ward
1690
+ return withOwnEvents(ward, constVoid, instance)
1691
+ }
1692
+ // Once for every ward made with them: whether an element enters afresh is asked of the ward itself.
1693
+ const begun: Begun = { kind: { ...kind, ...HOOK_TOLD, entersFresh: saidFresh }, config: constVoid, made }
1694
+ return () => begun
1695
+ }
1696
+
1697
+ /** A ward's Features read from its own config (`auto.ts`): each loaded the first time one is asked for. */
1698
+ export const auto = (): Begun => {
1699
+ const features = asking()
1700
+ return {
1701
+ kind: { ...SLIM, ...HOOK_TOLD, instance: features.instance, entersFresh: saidFresh, targeted: features.targeted },
1702
+ config: (config) => {
1703
+ // A key still loading as the ward is made is left out, and followed until it lands (`auto.ts`).
1704
+ const pending: Array<string> = []
1705
+ features.want(wantedBy(config(), pending))
1706
+ if (pending.length > 0) colorsOnceLoaded(config, pending, features.ask)
1707
+ },
1708
+ want: (names) => void features.want(names),
1709
+ // A server's ward hears nothing: its `when` is left as it is.
1710
+ made: (ward) => {
1711
+ if (isServer) return ward
1712
+ return withOwnEvents(ward, features.ask, features.instance)
1713
+ },
1714
+ }
1715
+ }
1716
+
1717
+ /**
1718
+ * Whether the next element `ward` is given enters afresh, from its `initial`: its presence said so
1719
+ * ({@link Taken.fresh}). The one function every hooks ward's internals carry (`entersFresh`), asked
1720
+ * of the ward itself, so nothing is made for it ward by ward.
1721
+ */
1722
+ const saidFresh = (ward: object): boolean => {
1723
+ const kept = keptFor(ward)
1724
+ if (Predicate.isUndefined(kept)) return false
1725
+ return kept.fresh
1726
+ }
1727
+
1728
+ /**
1729
+ * What a presence takes a ward by (`createPresence(ward, value)`): how it gives the ward its word on
1730
+ * whether its value is on the page, and the ward's state as a `show` ward's. The ward is the one
1731
+ * `createWard` made, driven where it is: a sensor or a listener made on it hears every value's element.
1732
+ */
1733
+ export interface Taken {
1734
+ /**
1735
+ * Gives the ward its presence's word, an accessor: called once, as the presence is made. The word is
1736
+ * derived, and nothing is written as it's made: what read the ward before its presence was hears of
1737
+ * it once the page has settled, by the ward's one write ({@link tell}).
1738
+ */
1739
+ readonly drive: (shown: Accessor<boolean>) => void
1740
+ /** The ward's state: whether it's shown, whether it leaves by an exit, and what's told as that lands. */
1741
+ readonly state: ShowState
1742
+ /** Says that the next element it's given enters from its `initial`: its value came after the page opened. */
1743
+ readonly fresh: () => void
1744
+ }
1745
+
1746
+ /** Where a ward `createWard` made keeps how a presence takes it. */
1747
+ const TAKE = Symbol("wardic.hooks.take")
1748
+
1749
+ const TAKEN_TWICE = "createPresence(ward, value): this ward already has a presence. Make a ward for each."
1750
+
1751
+ /**
1752
+ * What a presence takes a ward `createWard` made by: the ward, its `show` state, and its runes as one
1753
+ * config, where it has an `animate` to leave by (none: it leaves at once). Data alone, as the ward is
1754
+ * made: what taking does with it is {@link takenOf}'s, so an app that never makes a presence ships
1755
+ * none of it (`takenLater`, `fixLater`, `targetAgain` and Solid's `refresh`: 0.3 to 0.5 KB, gzip).
1756
+ */
1757
+ export interface Takeable {
1758
+ readonly ward: Ward
1759
+ readonly state: ShowState
1760
+ readonly runes: (() => Joined) | undefined
1761
+ /** Its runes' `ref`s, where its binding runs them (the cheap `ref`): a presence that takes it has them go by its word. */
1762
+ readonly refs: MountedRefs | undefined
1763
+ /** Whether a presence has taken it: one may, once. */
1764
+ taken: boolean
1765
+ }
1766
+
1767
+ /**
1768
+ * Takes `ward` for a presence, once: `undefined` for a ward that isn't one `createWard` handed out (a
1769
+ * row's, another library's), or that has a `show` of its own and comes and goes by that.
1770
+ */
1771
+ export const takenOf = (ward: object): Taken | undefined => {
1772
+ const take = keptElse(ward, (kept) => kept.take, () => (ward as { readonly [TAKE]?: Takeable })[TAKE])
1773
+ if (Predicate.isUndefined(take)) return undefined
1774
+ if (take.taken) throw misuse("WARDIC_PRESENCE_WARD_TAKEN", TAKEN_TWICE)
1775
+ take.taken = true
1776
+ return takenBy(take)
1777
+ }
1778
+
1779
+ /** How `take`'s ward is taken: at once, with nowhere to leave to, else by its runes. Its refs go by its presence's word from then. */
1780
+ const takenBy = (take: Takeable): Taken => {
1781
+ const taken = UndefinedOr.match(take.runes, {
1782
+ onUndefined: () => takenAtOnce(take.state)(),
1783
+ onDefined: (runes) => takenLater(take.ward, take.state, runes)(),
1784
+ })
1785
+ UndefinedOr.map(take.refs, (refs) => refsTaken(refs, take.ward))
1786
+ return taken
1787
+ }
1788
+
1789
+ /** Whether a ward comes and goes by a `show` or a presence of its own: a row, a `show` ward, a presence's ward. */
1790
+ const ownsItsLeave = (kept: Kept): boolean => {
1791
+ if (Predicate.isNotUndefined(kept.show)) return true
1792
+ const take = kept.take
1793
+ return Predicate.isNotUndefined(take) && take.taken
1794
+ }
1795
+
1796
+ /**
1797
+ * `found`, a ward inside a leaving row or presence value (the gap grill's Q20), taken by it as it first
1798
+ * leaves: its presence's word is whether that one is `shown`, so it leaves and comes back with it, and
1799
+ * as it leaves it sweeps what's inside its own element. Its leaving state; none where it isn't the
1800
+ * row's to take: a follower, one a presence may not take, or one made under no owner. Taken late, as
1801
+ * nothing is settling and no component is being made: what's told at a settle is told now, and it's
1802
+ * aimed again outside any owner.
1803
+ */
1804
+ const takenInside = (found: Ward, kept: Kept, shown: Accessor<boolean>): ShowState | undefined => {
1805
+ if (FOLLOWING.has(found)) return undefined
1806
+ return takenLate(found, kept, shown)
1807
+ }
1808
+
1809
+ /**
1810
+ * `found` taken late by something that leaves, as a leaving row takes what's inside it (Q20) and a
1811
+ * leader its followers with an exit of their own (Q12): its presence's word is whether that one is
1812
+ * `shown`. Its leaving state; none for one a presence may not take, one taken already, or one made
1813
+ * under no owner.
1814
+ */
1815
+ const takenLate = (found: Ward, kept: Kept, shown: Accessor<boolean>): ShowState | undefined => {
1816
+ const take = kept.take
1817
+ if (Predicate.isUndefined(take) || take.taken) return undefined
1818
+ const owner = kept.owner
1819
+ if (Predicate.isNull(owner)) return undefined
1820
+ take.taken = true
1821
+ takingLate = true
1822
+ try {
1823
+ runWithOwner(owner, () => takenBy(take)).drive(shown)
1824
+ } finally {
1825
+ takingLate = false
1826
+ }
1827
+ // It ends with what took it, unless that comes back: it stays where its exit left it, as a list's
1828
+ // leaving row does, where it rested at its `initial`, and showed, its spread's `style` not read again.
1829
+ take.state.ends = () => !untrack(shown)
1830
+ targetAgain(found)
1831
+ return take.state
1832
+ }
1833
+
1834
+ /** `leader`'s followers with an `exit` of their own, each taken by it as it first leaves (Q12), each one's leaving state added to `into`. */
1835
+ const followersLeaving = (leader: Ward, shown: Accessor<boolean>, into: Array<ShowState>): void => {
1836
+ const all = FOLLOWERS.get(leader)
1837
+ if (Predicate.isUndefined(all)) return
1838
+ Iter.forEach(all, (follower) => {
1839
+ if (!follower.exits) return
1840
+ const kept = keptFor(follower.ward)
1841
+ if (Predicate.isUndefined(kept)) return
1842
+ const taken = takenLate(follower.ward, kept, shown)
1843
+ if (Predicate.isNotUndefined(taken)) into.push(taken)
1844
+ })
1845
+ }
1846
+
1847
+ /**
1848
+ * What `self`, a leaving row or presence value, takes inside `el` (Q20), depth first, each one's
1849
+ * leaving state added to `into`. A ward with a leave of its own (a row, a `show` ward, a presence's)
1850
+ * keeps what's inside it, and so does a twin, its handback's; one it takes sweeps its own inside as it
1851
+ * leaves; past any other element it looks further in.
1852
+ */
1853
+ const sweepInside = (el: Element, self: Ward, shown: Accessor<boolean>, into: Array<ShowState>): void =>
1854
+ Iter.forEach(el.children, (child) => {
1855
+ const found = wardOn(child)
1856
+ if (Predicate.isNotUndefined(found) && found !== self) {
1857
+ const kept = keptFor(found)
1858
+ if (Predicate.isNotUndefined(kept)) {
1859
+ if (ownsItsLeave(kept) || TWIN_WARDS.has(found)) return
1860
+ const taken = takenInside(found, kept, shown)
1861
+ if (Predicate.isNotUndefined(taken)) {
1862
+ into.push(taken)
1863
+ return
1864
+ }
1865
+ }
1866
+ }
1867
+ sweepInside(child, self, shown, into)
1868
+ })
1869
+
1870
+ /**
1871
+ * What a ward made under a presence hears of its child's leave ({@link watchedUnder}), kept past its
1872
+ * owner's end: its exits, on waiters that end then no more, and the presence's hold on the leave under way.
1873
+ */
1874
+ export interface Watched {
1875
+ /** Its exits, as its `next`, `each` and `when` hear them: ended once it has gone, not with its owner. */
1876
+ readonly waiters: Waiters<PresenceEvents>
1877
+ /** The presence's hold on the leave under way, from the leave to its end: none before or after. */
1878
+ late: (() => () => void) | undefined
1879
+ }
1880
+
1881
+ const WATCHED_GONE = "The ward went before its next exit."
1882
+
1883
+ /** Whether a presence of the hooks' has taken `kept`'s ward (`createPresence`), which then says when it leaves. */
1884
+ const takenNow = (kept: Kept): boolean => Predicate.isNotUndefined(kept.take) && kept.take.taken
1885
+
1886
+ /**
1887
+ * A ward made under a presence (`<Presence>`, `<AnimatePresence>`) with no leave of its own hears its
1888
+ * child's leave from that presence, by a watch of its own, as the deleted `usePresence` did (the code review of the
1889
+ * gap grill's work). Its owner has ended by then, with the child's: what still runs, an event handler, a
1890
+ * timer, the code after an `await`, reads it leaving, `exiting()` and not `shown()`, and its `next`,
1891
+ * `each` and `when` of its exits hear them on waiters its owner's end doesn't end. Its `hold()` holds the
1892
+ * leave under way. In a browser alone, and only under a presence.
1893
+ */
1894
+ const watchedUnder = (made: HookWard, ward: Ward, state: ShowState): void => {
1895
+ const presence = presenceOn(ward)
1896
+ if (Predicate.isUndefined(presence)) return
1897
+ const register = presence.watch
1898
+ if (Predicate.isUndefined(register)) return
1899
+ const [present, setPresent] = createSignal(true)
1900
+ const [ended, setEnded] = createSignal(false)
1901
+ const watched: Watched = { waiters: new Waiters<PresenceEvents>(WATCHED_GONE), late: undefined }
1902
+ state.shown = present
1903
+ // eslint-disable-next-line solid/reactivity -- an accessor, read where the ward's `mounted` is, which tracks it
1904
+ state.mounted = () => !ended()
1905
+ const kept = keptOf(made)
1906
+ kept.watched = watched
1907
+ const end = (): void => {
1908
+ watched.late = undefined
1909
+ watched.waiters.dispose()
1910
+ }
1911
+ register({
1912
+ subject: () => elementOf(ward),
1913
+ holds: false,
1914
+ leave: (_custom, _release, hold) => {
1915
+ // A presence of the hooks' that took it since says when it leaves.
1916
+ if (takenNow(kept)) return
1917
+ watched.late = hold
1918
+ setPresent(false)
1919
+ watched.waiters.tell("exitStart", constUndefined)
1920
+ },
1921
+ gone: end,
1922
+ interrupted: () => {
1923
+ setEnded(true)
1924
+ end()
1925
+ },
1926
+ ended: () => {
1927
+ setEnded(true)
1928
+ watched.waiters.tell("exitComplete", constUndefined)
1929
+ end()
1930
+ },
1931
+ })
1932
+ }
1933
+
1934
+ /** Whether `leader` has a follower with an `exit` of its own, which it takes as it leaves (Q12). */
1935
+ const followerWithExit = (leader: object): boolean => {
1936
+ const all = FOLLOWERS.get(leader)
1937
+ if (Predicate.isUndefined(all)) return false
1938
+ return Iter.some(all, (follower) => follower.exits)
1939
+ }
1940
+
1941
+ /**
1942
+ * Whether `self`, a leaving row or presence value, has a ward inside `el` it would take to leave by
1943
+ * that ward's own exit ({@link sweepInside}, read and not taken): one a presence may take, with an
1944
+ * `animate` or an `exit`, not taken yet, made under an owner, and following nothing. One with only an
1945
+ * `animate` is taken and then lets it go, a microtask on.
1946
+ */
1947
+ const leavesInside = (el: Element, self: Ward): boolean =>
1948
+ Iter.some(el.children, (child) => {
1949
+ const found = wardOn(child)
1950
+ if (Predicate.isNotUndefined(found) && found !== self) {
1951
+ const kept = keptFor(found)
1952
+ if (Predicate.isNotUndefined(kept)) {
1953
+ if (ownsItsLeave(kept) || TWIN_WARDS.has(found)) return false
1954
+ if (takesInside(found, kept)) return true
1955
+ }
1956
+ }
1957
+ return leavesInside(child, self)
1958
+ })
1959
+
1960
+ /** Whether {@link takenInside} would take `found`: what {@link takenLate} asks, before taking it. */
1961
+ const takesInside = (found: Ward, kept: Kept): boolean => {
1962
+ if (FOLLOWING.has(found)) return false
1963
+ const take = kept.take
1964
+ if (Predicate.isUndefined(take) || take.taken || Predicate.isUndefined(take.runes)) return false
1965
+ return Predicate.isNotNull(kept.owner)
1966
+ }
1967
+
1968
+ /** What `ward` waits for as it leaves with no exit of its own ({@link ShowState.waits}): its followers with an exit, and what's inside a row or a presence value. */
1969
+ const waitsAsItLeaves = (ward: Ward, state: ShowState): boolean => {
1970
+ if (followerWithExit(ward)) return true
1971
+ if (!state.sweeps) return false
1972
+ const el = elementOf(ward)
1973
+ if (Predicate.isUndefined(el)) return false
1974
+ return leavesInside(el, ward)
1975
+ }
1976
+
1977
+ /**
1978
+ * Whether `ward` stays to leave ({@link ShowState.leaves}), asked untracked: a list's, of a row whose
1979
+ * item has left, so one with nowhere to leave to and nothing to wait for is left out in that same
1980
+ * change, where its own effect dropping it tore the list. Yes for a ward the hooks keep no state of
1981
+ * (a Stage's), which the list watches for itself.
1982
+ */
1983
+ export const leavesNow = (ward: object): boolean => {
1984
+ const state = showOf(ward)
1985
+ if (Predicate.isUndefined(state)) return true
1986
+ return untrack(state.leaves)
1987
+ }
1988
+
1989
+ /**
1990
+ * `ward` with what a presence takes it by ({@link Takeable}). Kept of a client's ward (`kept.ts`); its
1991
+ * own property on one with no state to keep it by, not enumerable, so a spread never sees it.
1992
+ */
1993
+ const takeable = (made: HookWard, ward: Ward, state: ShowState, runes: (() => Joined) | undefined, refs: MountedRefs | undefined): HookWard => {
1994
+ const take: Takeable = { ward, state, runes, refs, taken: false }
1995
+ if (!keepsState(made)) return Object.defineProperty(made, TAKE, { value: take })
1996
+ const kept = keptOf(made)
1997
+ kept.take = take
1998
+ // Where a leaving row takes it later (Q20), its wiring made under the owner it was made under.
1999
+ if (Predicate.isNull(kept.owner)) kept.owner = getOwner()
2000
+ return made
2001
+ }
2002
+
2003
+ /** A ward with nowhere to leave to, taken: on the page while its presence says so, and gone at once. */
2004
+ const takenAtOnce = (state: ShowState) => (): Taken => {
2005
+ state.leaves = NEVER
2006
+ return {
2007
+ // Nothing of its own reads its presence's word, so it's given at once, with nothing written. What
2008
+ // read the ward before this presence had it is told at the settle (`hearing`).
2009
+ drive: (shown) => {
2010
+ state.shown = shown
2011
+ state.mounted = shown
2012
+ tell(state)
2013
+ },
2014
+ state,
2015
+ fresh: constVoid,
2016
+ }
2017
+ }
2018
+
2019
+ /** What `ward` hands the wards that follow it, where it leads any: whether they've all landed is read of it. */
2020
+ const providedBy = (ward: Ward): NonNullable<ReturnType<typeof shareOf>>["provided"] => {
2021
+ const share = shareOf(ward)
2022
+ if (Predicate.isUndefined(share)) return undefined
2023
+ return share.provided
2024
+ }
2025
+
2026
+ /**
2027
+ * `show`'s other half, once its ward is made: its followers' landings and its own, and its place in
2028
+ * the layout. Made where its `show` is wired: as the ward is made, or as a presence takes it. Its
2029
+ * exits are told from here too where `exits` is given ({@link exitsOf}): a ward with a `show` of its
2030
+ * own. A presence's ward has them told once that presence's word and value are its state's
2031
+ * ({@link tellingExits}).
2032
+ */
2033
+ const wiredFor = (ward: Ward, state: ShowState, runes: Joined, exits: ((now: Seen) => void) | undefined): void => {
2034
+ const provided = providedBy(ward)
2035
+ if (Predicate.isNotUndefined(provided)) {
2036
+ state.followersLanded = provided.allChildrenSettled
2037
+ // In a browser alone: nothing lands on a server.
2038
+ if (!isServer) {
2039
+ const runtime = useWardicRuntime()
2040
+ state.counted = (count) => {
2041
+ // Called detached, as core calls it: the web's is `requestAnimationFrame` itself.
2042
+ const { requestFrame } = runtime.runSync(RefreshFrameSource.RefreshFrameSource)
2043
+ // Two frames on. A follower says it's moving as its spine is stepped, the frame after it's
2044
+ // told to leave, and this frame's own callback may come before that step: one frame on, a
2045
+ // view closed from rest read its followers as landed and went before any had moved.
2046
+ requestFrame(() => requestFrame(count))
2047
+ }
2048
+ }
2049
+ }
2050
+ // Each landing, told by its lifecycle to the one listener the hooks have there: not an effect over
2051
+ // `ward.when("settled")`, a memo that pends until the first, with an error of Solid's made for
2052
+ // each; and not a listener for `settled`, which had the ward make its waits and read every
2053
+ // landing for a wiring that reads none. Read at each landing: a presence that takes the ward adds
2054
+ // what it's told to. A server's ward has no lifecycle, and nothing lands there.
2055
+ const sensed = sensedOf(ward)
2056
+ if (Predicate.isNotUndefined(sensed)) onCleanup(sensed.lifecycle.landingsHeardBy({ next: () => state.landed(), error: landingFailed(getOwner()) }))
2057
+ popping(ward, runes, state, exits)
2058
+ }
2059
+
2060
+ /** `show`'s wiring as a presence's ward reads it: its `animate`, `exit` and `custom`, and whether an element enters afresh. Not its `style`: a presence takes its element off the page itself. */
2061
+ const takenWiring = (built: Shown | undefined, kept: Kept): Shown | undefined => {
2062
+ if (Predicate.isUndefined(built)) return undefined
2063
+ return { animate: built.animate, exit: built.exit, custom: built.custom, reenters: () => kept.fresh }
2064
+ }
2065
+
2066
+ /**
2067
+ * How a presence takes a ward that has an `animate` to leave by and no `show` of its own
2068
+ * (`createPresence(ward, value)`): `show`'s wiring over its `runes`, made as the presence takes it
2069
+ * and where the presence is, its `show` the presence's word.
2070
+ *
2071
+ * Nothing is set up for this as a ward is made, so a ward no presence takes carries none of it.
2072
+ * Every animated ward used to: its `animate` read through a wrapper that followed a signal of its
2073
+ * own, in case. The keys the wiring reads are fixed over the ward's config now (`fixLater`), and
2074
+ * its target is worked out again once the page has settled (`targetAgain`): it read its `animate`
2075
+ * as the ward was made, before any presence was, and follows nothing that says one has it.
2076
+ */
2077
+ const takenLater =
2078
+ (ward: Ward, state: ShowState, runes: () => Joined) =>
2079
+ (): Taken => {
2080
+ // Its presence's word, given in `drive`: on the page until then. Not reactive itself, so what
2081
+ // read it before it was given is told at the settle (`hearing`).
2082
+ let by: Accessor<boolean> | undefined
2083
+ const present = (): boolean => {
2084
+ hearing(state)
2085
+ if (Predicate.isUndefined(by)) return true
2086
+ return by()
2087
+ }
2088
+ const made = runes()
2089
+ const driven: Joined = { ...made, show: present }
2090
+ // What's inside its element leaves with it (Q20): a presence's value stays on the page as it leaves.
2091
+ state.sweeps = true
2092
+ const built = showing(state)(driven)
2093
+ wiredFor(ward, state, driven, undefined)
2094
+ // A server's ward animates nothing and stays as it was made: it has no state to fix more over.
2095
+ if (keepsState(ward)) {
2096
+ fixLater(ward, wiredOf(takenWiring(built, keptOf(ward)), made.unentered, made.value, made.has))
2097
+ // Taken late by a leaving row or value (`takenInside`), nothing is settling: it's aimed again by
2098
+ // whoever took it, outside any owner, since `refresh` is refused in one.
2099
+ if (!takingLate) onSettledClientOnly(() => targetAgain(ward))
2100
+ }
2101
+ return {
2102
+ // Its presence's word. What read the ward before this presence had it is told of it at the
2103
+ // settle (`hearing`). In a browser alone: a server's ward animates nothing, and what's told at
2104
+ // a settle is client-only code's, which takes a hydration id on a server and none in a browser.
2105
+ drive: (shown) => {
2106
+ tell(state)
2107
+ if (isServer) return
2108
+ by = shown
2109
+ },
2110
+ state,
2111
+ fresh: () => {
2112
+ if (keepsState(ward)) keptOf(ward).fresh = true
2113
+ },
2114
+ }
2115
+ }
2116
+
2117
+ // Module state (#460, Q7): the `show` state of each ward with no state of its own to keep it by (a
2118
+ // server's), held weakly by the ward, for the list that made it to read. A client's is kept of the ward (`kept.ts`).
2119
+ const SHOWN = new WeakMap<object, ShowState>()
2120
+
2121
+ /** `ward`'s `show` state, where it has one: what the list that made it reads. */
2122
+ const showOf = (ward: object): ShowState | undefined => keptElse(ward, (kept) => kept.show, () => SHOWN.get(ward))
2123
+
2124
+ /** Keeps `state` as `ward`'s `show` state. */
2125
+ const showIs = (ward: object, state: ShowState): void => {
2126
+ if (!keepsState(ward)) {
2127
+ SHOWN.set(ward, state)
2128
+ return
2129
+ }
2130
+ keptOf(ward).show = state
2131
+ }
2132
+
2133
+ /**
2134
+ * Whether `ward`'s leave can't be turned round: the wards of the twins it handed home as it left have
2135
+ * ended ({@link ShowState.committed}). A list reads it of a row whose item has come back: that row
2136
+ * goes on leaving, and the item has a row of its own, on a new element. False for any other ward.
2137
+ */
2138
+ export const leaveCommitted = (ward: object): boolean => {
2139
+ const state = showOf(ward)
2140
+ if (Predicate.isUndefined(state)) return false
2141
+ return state.committed
2142
+ }
2143
+
2144
+ /**
2145
+ * `ward` leaves by its own exit alone from here on ({@link ShowState.letGo}): a list tells it of a row
2146
+ * whose item has come back to a row of its own. Nothing for any other ward.
2147
+ */
2148
+ export const letGo = (ward: object): void => {
2149
+ const state = showOf(ward)
2150
+ if (Predicate.isUndefined(state)) return
2151
+ state.letGo()
2152
+ }
2153
+
2154
+ /**
2155
+ * How a list's row reaches the layout around it: its mount told to the projection when it comes after
2156
+ * the list's first rows (`later`, {@link ShowState.mountMoves}), and nothing told at all where its list
2157
+ * says `affectsLayout: false` ({@link ShowState.affectsLayout}). Nothing for a ward with no `show`.
2158
+ */
2159
+ export const rowInLayout = (ward: object, later: boolean, affects: boolean): void => {
2160
+ const state = showOf(ward)
2161
+ if (Predicate.isUndefined(state)) return
2162
+ state.mountMoves = later
2163
+ state.affectsLayout = affects
2164
+ }
2165
+
2166
+ /**
2167
+ * Has `then` called once `ward` has gone ({@link ShowState.left}): a list's, for its row, which is
2168
+ * dropped then and its ward ended where `ends` says so as it goes ({@link ShowState.ends}). False
2169
+ * for a ward that tells no such thing, which the list watches for itself: a Stage's.
2170
+ */
2171
+ export const whenLeft = (ward: object, then: () => void, ends: () => boolean): boolean => {
2172
+ const state = showOf(ward)
2173
+ if (Predicate.isUndefined(state)) return false
2174
+ state.left = then
2175
+ state.ends = ends
2176
+ // What's inside its element leaves with it (Q20): a list keeps a leaving row on the page.
2177
+ state.sweeps = true
2178
+ return true
2179
+ }
2180
+
2181
+ /**
2182
+ * `configs` as one ward's config, its wired keys read through `wired`: runes written plain are read
2183
+ * through as they are (`joinedOver`), one of them the config itself and the rest fixed over it. A
2184
+ * rune that follows, times its followers or carries timing in its variants is joined, key by key.
2185
+ */
2186
+ const joinedOf = (begun: Begun, runes: ReadonlyArray<Rune>, configs: ReadonlyArray<RuneConfig>, wired: (all: Joined) => Shown | undefined): Joined =>
2187
+ madeBy(throughOf(begun, runes, Arr.some(runes, isFunctionRune)), configs, wired)
2188
+
2189
+ /** A ward's runes as its one config: read through as they're written where they were found to be (`through`), else joined key by key. */
2190
+ const madeBy = (through: ReadThrough | undefined, configs: ReadonlyArray<RuneConfig>, wired: (all: Joined) => Shown | undefined): Joined => {
2191
+ if (Predicate.isUndefined(through)) return joined(configs, wired)
2192
+ return joinedOver(through, wired)
2193
+ }
2194
+
2195
+ /**
2196
+ * `runes` read through as they're written, where they can be (`readThroughOf`). Not with a function
2197
+ * rune among them, whose config is made as it's called: a ward of those is read through once they've
2198
+ * been called, from the configs they gave (probe: behaviour-runes). Nor for a binding that makes the ward itself:
2199
+ * it adds to the config it's given (a Reorder row's `value`), so that's a config of its own, and not
2200
+ * the rune.
2201
+ */
2202
+ const throughOf = (begun: Begun, runes: ReadonlyArray<Rune>, anyFunction: boolean): ReadThrough | undefined => {
2203
+ if (anyFunction) return undefined
2204
+ if (Predicate.isNotUndefined(begun.make)) return undefined
2205
+ return readThroughOf(runes as ReadonlyArray<RuneConfig>)
2206
+ }
2207
+
2208
+ /**
2209
+ * A landing that failed, reported as the binding reports any failure. An effect over
2210
+ * `ward.when("settled")` had Solid log it; heard from the lifecycle, it's the listener's to report.
2211
+ * Its runtime is found then, under the `owner` the ward was wired under: nothing is read for it for
2212
+ * a ward whose landings never fail.
2213
+ */
2214
+ const landingFailed =
2215
+ (owner: Owner | null) =>
2216
+ (error: unknown): void => {
2217
+ // Uncoded: a leg that failed is Wardic's own failure; an app's function that made it fail is coded where it ran.
2218
+ runWithOwner(owner, () => void useWardicRuntime().runFork(Report.failure("wardic.createWard: a landing failed", Cause.die(error))))
2219
+ }
2220
+
2221
+ /** `internal` with a rune's `wired` keys fixed over its config (`joinedOver`), over what its kind fixes already. */
2222
+ const wiredOver = (internal: WardInternals, wired: Joined["wired"]): WardInternals => {
2223
+ if (Predicate.isUndefined(wired)) return internal
2224
+ const fixed = internal.fixed
2225
+ // Its kind fixes nothing, most do: what's wired is what's fixed, as it is. Nothing writes to either.
2226
+ if (Predicate.isUndefined(fixed)) return { ...internal, fixed: wired as WardInternals["fixed"] }
2227
+ return { ...internal, fixed: { ...fixed, ...wired } as WardInternals["fixed"] }
2228
+ }
2229
+
2230
+ /** The key a ward's exit is told through: with none in its runes, it leaves at once, and nothing is wired. */
2231
+ const animates = (configs: ReadonlyArray<RuneConfig>): boolean => Arr.some(configs, (config) => "animate" in config)
2232
+
2233
+ /**
2234
+ * One plain rune's keys, for its ward's Features to be found by. As they read, an accessor's as its
2235
+ * result, for a ward a presence may take by its `animate`: such a ward was joined in case one did,
2236
+ * and its Features found that way, so a colour only `colors` reads was found in an `animate` that's
2237
+ * an accessor (HY6). Any other is read as it's written, as it was.
2238
+ */
2239
+ const featureKeysOf =
2240
+ (only: RuneConfig, open: boolean) =>
2241
+ (): ReadByKey => {
2242
+ if (open && animates([only])) return asReadOf(only)
2243
+ return only as ReadByKey
2244
+ }
2245
+
2246
+ /** Whether a ward's runes give it an `exit` to leave to. */
2247
+ const exits = (configs: ReadonlyArray<RuneConfig>): boolean => Arr.some(configs, (config) => "exit" in config)
2248
+
2249
+ /** Whether an `exit` is one to leave to: given, and not `false`, which is no exit as `show`'s wiring reads it, though the key's type doesn't name it. */
2250
+ const isAnExit: Predicate.Predicate<unknown> = /*#__PURE__*/ Predicate.and(Predicate.isNotUndefined, (exit: unknown) => exit !== false)
2251
+
2252
+ /** Whether a rune written as a config gives an `exit` of its own: a follower's that its leader runs (Q12). */
2253
+ const ownExit = (rune: Rune): boolean => {
2254
+ if (isFunctionRune(rune)) return false
2255
+ return isAnExit((rune as RuneConfig).exit)
2256
+ }
2257
+
2258
+ /**
2259
+ * The runes a presence takes a ward by (`takenLater`), given when it does: none for a ward with
2260
+ * neither an `animate` to leave from nor an `exit` to leave to, which leaves at once. One with an
2261
+ * `exit` alone leaves by it (Q16): it was dropped at once, its exit never run.
2262
+ */
2263
+ const takingOf = (configs: ReadonlyArray<RuneConfig>, joinedNow: () => Joined): (() => Joined) | undefined => {
2264
+ if (!animates(configs) && !exits(configs)) return undefined
2265
+ return joinedNow
2266
+ }
2267
+
2268
+ // Module state (#460, Q7): in development, each ward whose runes name no state as they're written (the
2269
+ // follow grill's Q2), held weakly: what a ward that follows one is warned of. A ward is its own request's.
2270
+ const NAMING_NOTHING = new WeakSet<object>()
2271
+
2272
+ // Module state (#460, Q7): in development, each leader a follower has been warned of already, held weakly:
2273
+ // once a leader, however many follow it (Q6). A ward is its own request's.
2274
+ const WARNED_OF = new WeakSet<object>()
2275
+
2276
+ /** Development's word for a ward that follows one naming no state (Q2): it's made, and follows nothing. */
2277
+ const FOLLOWS_NOTHING =
2278
+ "createWard({ follow }): the ward it follows names no states, so there's nothing to follow; give it `variants`, or name its states in `animate`."
2279
+
2280
+ /** In development, the word for a ward following `leader` where `leader` names no state: once for that leader (Q2, Q6). */
2281
+ const warnIfFollowingNothing = (leader: object | undefined): void => {
2282
+ if (Predicate.isUndefined(leader)) return
2283
+ if (!NAMING_NOTHING.has(leader)) return
2284
+ if (WARNED_OF.has(leader)) return
2285
+ WARNED_OF.add(leader)
2286
+ report("WARDIC_FOLLOW_LEADER_UNNAMED", FOLLOWS_NOTHING)
2287
+ }
2288
+
2289
+ /**
2290
+ * `make`, warning in development when a ward with variants of its own follows one that names no state,
2291
+ * once for that leader (the follow grill's Q2, Q6 and Q12), on a server too. A leader is judged by its runes
2292
+ * as they're written: one that names its states through a function, a getter or a function rune may name
2293
+ * them, and is never warned of; a follower with no variants follows only to leave with it, and isn't. In a
2294
+ * production build, `make` as it is.
2295
+ */
2296
+ const warnsFollowingNothing = (make: WardMaker): WardMaker => {
2297
+ if (!DEV) return make
2298
+ return ((...written: ReadonlyArray<Rune>) => {
2299
+ // A follower with variants of its own, none of which can be chosen (Q12): one with none follows only to leave with it.
2300
+ if (hasOwnVariants(written)) warnIfFollowingNothing(knownBeforeFunctionRunes(written, "follow"))
2301
+ const ward = (make as (...runes: ReadonlyArray<Rune>) => HookWard)(...written)
2302
+ if (namesNothing(written)) NAMING_NOTHING.add(ward)
2303
+ return ward
2304
+ }) as WardMaker
2305
+ }
2306
+
2307
+ /** `internal`, its ward in `group` where a rune gives it one: as it is where none does. */
2308
+ const groupedIn = (internal: WardInternals, group: WardInternals["layoutGroup"]): WardInternals => {
2309
+ if (Predicate.isUndefined(group)) return internal
2310
+ return { ...internal, layoutGroup: group }
2311
+ }
2312
+
2313
+ /** `createWard(...runes)`, each ward's Features from `begin`; `open` for one a presence may take. */
2314
+ const wardOf = (begin: () => Begun, open: boolean): WardMaker => ownerChecked(warnsFollowingNothing(wardMakerOf(begin, open)))
2315
+
2316
+ /**
2317
+ * `make`, refusing in development a ward made with no owner, outside a component or a root (step 2 of the
2318
+ * skill grill's order, Q20): it fails then anyway, on Solid's own error, which names neither the call nor
2319
+ * the fix. In a production build, `make` as it is.
2320
+ */
2321
+ const ownerChecked = (make: WardMaker): WardMaker => {
2322
+ if (!DEV) return make
2323
+ return ((...runes: ReadonlyArray<Rune>) => {
2324
+ if (Predicate.isNull(getOwner())) throw misuse("WARDIC_WARD_WITHOUT_OWNER", WITHOUT_OWNER)
2325
+ return (make as (...given: ReadonlyArray<Rune>) => HookWard)(...runes)
2326
+ }) as WardMaker
2327
+ }
2328
+
2329
+ const WITHOUT_OWNER =
2330
+ "createWard: a ward was made with no owner, outside a component or a root, where nothing would end it. Make it in the component that draws its Subject."
2331
+
2332
+ /** {@link wardOf}'s maker, without development's word on a ward following one that names nothing. */
2333
+ const wardMakerOf =
2334
+ (begin: () => Begun, open: boolean): WardMaker =>
2335
+ (...written) => {
2336
+ // Each rune fixed as the ward is made of it (`fixedRunes`): its keys are the ones it has now,
2337
+ // and a plain value in it can't change. One `createRune` made is fixed already. Plain runes from
2338
+ // here: a tag types its runes' `ref` and `props` for its caller alone.
2339
+ const runes = fixedRunes(written as ReadonlyArray<Rune>)
2340
+ // The Layout group it's in, where a rune is one (the scopes round's Q44): found among its runes as
2341
+ // they're written, as fixing one copies it, and joined to the group around it here, where it's made.
2342
+ const group = layoutGroupIn(written)
2343
+ const begun = begin()
2344
+ const kind = begun.kind
2345
+ const state = showState()
2346
+ // Read late: a presence that takes the ward gives it a state of its own. And heard, by whatever
2347
+ // reads before the ward's word has arrived: a function rune's body, a read made before a presence.
2348
+ const mounted = (): boolean => {
2349
+ hearing(state)
2350
+ return state.mounted()
2351
+ }
2352
+ const shown = (): boolean => {
2353
+ hearing(state)
2354
+ return state.shown()
2355
+ }
2356
+ /**
2357
+ * A ward with no `show`, as it's handed out. One a presence may take is taken by `taking`'s
2358
+ * runes, where it has an `animate` to leave by (`takenLater`); with none, it leaves at once. Its
2359
+ * runes' `ref`s, where its binding runs them, go by that presence's word once it does (`refs`).
2360
+ */
2361
+ const plain = (ward: Ward, taking: (() => Joined) | undefined, refs: MountedRefs | undefined): HookWard => {
2362
+ const made = withMounted(ward, mounted, shown)
2363
+ if (!open) {
2364
+ // No presence takes it, and it has no `show`: nothing more is to come.
2365
+ tell(state)
2366
+ return made
2367
+ }
2368
+ // A follower leaves with its leader, and isn't one a leaving row takes as well (Q20); one with an
2369
+ // `exit` of its own is taken by its leader as it leaves, to run it (Q12).
2370
+ const leader = knownBeforeFunctionRunes(runes, "follow")
2371
+ if (Predicate.isNotUndefined(leader)) {
2372
+ FOLLOWING.add(made)
2373
+ followsOf(leader, { ward: made, exits: Arr.some(runes, ownExit) })
2374
+ }
2375
+ // Made under a presence: it hears its child's leave from it, its owner ended by then.
2376
+ if (!isServer) watchedUnder(made, ward, state)
2377
+ // What a presence would take it by, and nothing of how: that's `takenOf`'s.
2378
+ return takeable(made, ward, state, taking, refs)
2379
+ }
2380
+ // The two fast paths are a plain ward's: one its kind makes itself (a Reorder list's row, `reorder.ts`)
2381
+ // goes the way below, as `throughOf` sends it, so its maker makes it (the Reorder round's utilities: a
2382
+ // row of no rune, or of one plain rune, was made a plain ward).
2383
+ const plainKind = Predicate.isUndefined(begun.make)
2384
+ // No runes, no keys: it names no gesture.
2385
+ if (runes.length === 0 && plainKind) return plain(begun.made(checked(wardWith(NO_CONFIG, gesturelessKind(kind)))), undefined, undefined)
2386
+ // One plain rune is the ward's config as it is.
2387
+ if (runes.length === 1 && plainKind) {
2388
+ const only = runes[0] as Rune
2389
+ // Its runes are joined only if a presence takes it.
2390
+ // One that drags goes the way below, which gives it grips (probe: behaviour-runes).
2391
+ // One that gives settings of its own goes that way too, which lays them over the config around it,
2392
+ // and a layout group, which puts the ward in it.
2393
+ if (!isFunctionRune(only) && isPlainRune(only) && Bool.not(givesDrag(only as RuneConfig)) && Bool.not(runeGivesSettings(only)) && Predicate.isUndefined(group)) {
2394
+ begun.config(featureKeysOf(only, open))
2395
+ // Its runes are its one config: the list of them is the one it was called with.
2396
+ const configs = runes as ReadonlyArray<RuneConfig>
2397
+ const told = gesturesTold(kind, kind, (key) => key in only)
2398
+ const ward = begun.made(wardFor(configs, () => checked(wardWith(only as WardConfig, told))))
2399
+ return plain(ward, takingOf(configs, () => joinedOf(begun, runes, configs, constUndefined)), undefined)
2400
+ }
2401
+ }
2402
+ // Whether any is a `createRune(fn)`: asked once here, where each step below asked it of them all.
2403
+ const anyFunction = Arr.some(runes, isFunctionRune)
2404
+ // Runes written plainly are read through as they're written, found in the one pass that reads
2405
+ // them. What else that pass saw of them (`seen`) says which of the steps below this ward needs:
2406
+ // each looked across the runes for itself, for every ward, and most wards need none of them.
2407
+ const through = throughOf(begun, runes, anyFunction)
2408
+ let seen: number | undefined
2409
+ if (Predicate.isNotUndefined(through)) seen = through.seen
2410
+ // A rune read through follows nothing: one that follows is joined.
2411
+ let follow: RuneConfig["follow"]
2412
+ if (Predicate.isUndefined(through)) follow = followOf(runes)
2413
+ const options = UndefinedOr.map(follow, parentOptions)
2414
+ // Whether it's shown, where a plain rune says so, before any function rune reads it.
2415
+ if (anyFunction) {
2416
+ const known = knownBeforeFunctionRunes(runes, "show")
2417
+ if (Predicate.isNotUndefined(known)) showingEarly(state, known)
2418
+ }
2419
+ // A createRune(fn)'s ward (probe: behaviour-runes, the ward split's Q6, Q8 and Q12): a holder, made
2420
+ // now, under this owner, before any rune runs. The finished ward adopts its lifecycle and drives it, so
2421
+ // its events, reads and gestures are that ward's, and it's no binding ward of its own: a second
2422
+ // `wardWith` a row was half of what a Reorder row allocated. Whether it's shown, mounted and leaving are
2423
+ // the finished ward's own accessors; its `drag`, `ward.drag`, is made at its first read. Gestureless,
2424
+ // as it never mounts an element of its own. Where every function rune reads nothing but its `drag`
2425
+ // (`dragOnly`, Wardic's `list.item`), a stand-in instead, which costs a row less than a holder (Q12):
2426
+ // anything else read of it is a holder's, made then, or the finished ward's once that's made.
2427
+ let handle: RuneWard | undefined
2428
+ let holder: Ward | undefined
2429
+ let finished: Ward | undefined
2430
+ const holderNow = (): Ward => {
2431
+ if (Predicate.isUndefined(holder)) holder = withMounted(begun.made(holderWard(groupedIn(gesturelessKind(internalsOf(options, kind)), group))), mounted, shown)
2432
+ return holder
2433
+ }
2434
+ let configs = runes as ReadonlyArray<RuneConfig>
2435
+ if (anyFunction) {
2436
+ const standIn = Arr.every(runes, (rune) => Bool.or(Bool.not(isFunctionRune(rune)), isDragOnly(rune)))
2437
+ const given = Bool.match(standIn, {
2438
+ onTrue: () => runeWardOf(() => UndefinedOr.match(finished, { onUndefined: holderNow, onDefined: identity })),
2439
+ onFalse: () => withDrag(holderNow()) as RuneWard,
2440
+ })
2441
+ handle = given
2442
+ configs = runes.map((each) => {
2443
+ if (!isFunctionRune(each)) return each
2444
+ // Its config fixed once it's made, as a rune written as one is.
2445
+ return fixedRunes([functionOf(each)(given)])[0] as RuneConfig
2446
+ })
2447
+ }
2448
+ // A `drag` given as an accessor by the last rune to give one: its gestures' axis, read at each one's
2449
+ // start (probe: behaviour-runes, Q6), and a later rune's `drag` the ward's (Q7).
2450
+ const axisAt = dragAccessorOf(configs)
2451
+ // What its runes heard of its drag, a behaviour's (probe: behaviour-runes): its keys make it a tab
2452
+ // stop, by a rune after its own that reads theirs, so an app's own `tabindex` wins and its ids come first.
2453
+ const behaviour = UndefinedOr.match(handle, { onUndefined: constUndefined, onDefined: siteIfAny })
2454
+ let site = behaviour
2455
+ if (Predicate.isNotUndefined(site)) {
2456
+ const keys = keysRuneOf(site, configs)
2457
+ if (Predicate.isNotUndefined(keys)) configs = [...configs, keys]
2458
+ }
2459
+ // A function rune's config, once it's called, is fixed as a plain rune's is: read through as one, where
2460
+ // the ward's runes can be (probe: behaviour-runes, the speed step: the join was a behaviour's row's
2461
+ // largest cost left). What has to be joined is joined as a plain rune's is (`readThroughOf`): one that
2462
+ // follows or times its followers, whose variants need joining, or that gives a callback beside the source.
2463
+ let readThrough = through
2464
+ if (Bool.and(anyFunction, plainKind)) {
2465
+ readThrough = readThroughOf(configs)
2466
+ if (Predicate.isNotUndefined(readThrough)) seen = readThrough.seen
2467
+ }
2468
+ // Wired for its own `show` alone. A ward a presence takes is wired as it's taken (`takenLater`).
2469
+ const made = madeBy(readThrough, configs, showing(state))
2470
+ begun.config(made.asRead)
2471
+ // A behaviour that reads `ward.drag` asks for the drag Feature, whose input its keys are heard by (Q5).
2472
+ if (Predicate.isNotUndefined(behaviour)) UndefinedOr.map(begun.want, (want) => want(DRAG_WANTED))
2473
+ let internal = internalsOf(options, kind)
2474
+ // Driving its function runes' holder, where it has one: that holder's lifecycle is this one's.
2475
+ if (Predicate.isNotUndefined(holder)) internal = { ...kind, name: NAME, share: shareOf(holder) }
2476
+ // In the layout group a rune gives it, where one does: a holder's is that group too.
2477
+ internal = groupedIn(internal, group)
2478
+ // A behaviour's drag (probe: behaviour-runes): its samples, its node and its input heard; its
2479
+ // `lifted` raising it (Q9); its axis read per gesture (Q6); development's word on no drag (Q19). A
2480
+ // ward that drags has grips (Q14), its site made for them where no behaviour made one.
2481
+ // Its `drag` as its runes join it, whichever gives it: read through, the config is the source rune alone,
2482
+ // whose `drag` isn't another rune's (the speed step's review).
2483
+ const dragRead = UndefinedOr.match(axisAt, { onUndefined: () => (): unknown => made.value("drag"), onDefined: identity })
2484
+ if (drags(axisAt, dragRead)) {
2485
+ if (Predicate.isUndefined(site)) site = makeSite()
2486
+ withGrips(site, dragAxisOf(dragRead))
2487
+ }
2488
+ if (Predicate.isNotUndefined(site)) internal = { ...internal, ...siteInternalsOf(site) }
2489
+ // At its first settle (Q19), so a listener its runes add later is counted too. In a browser alone: a
2490
+ // server's settled effect takes a hydration id the client's doesn't (KH9).
2491
+ if (DEV && !isServer && Predicate.isNotUndefined(behaviour)) onSettledClientOnly(() => warnIfUndragged(behaviour, made.has("drag")))
2492
+ const lifted = liftedOf(made.own("lifted"))
2493
+ if (Predicate.isNotUndefined(lifted)) internal = { ...internal, lifted, raiseWhileDragged: true, onLayoutHandle: bothHandles(internal.onLayoutHandle, raiseOf(lifted)) }
2494
+ if (Predicate.isNotUndefined(axisAt)) internal = { ...internal, dragAxis: dragAxisAt(axisAt) }
2495
+ // A follower that names a gesture of its own: a Variant child by its own word, which core is told (Q26).
2496
+ if (made.variantChild) internal = { ...internal, variantChild: true }
2497
+ // Its own settings, where its runes give any (the scopes round's Q10): laid over the config around it,
2498
+ // and read by the base ward in that config's place.
2499
+ if (givesSettings(made.has)) internal = { ...internal, wardicConfig: settingsOver(useWardicConfig(), made.value) }
2500
+ // A rune read through as it's written: its wired keys are fixed over it.
2501
+ internal = wiredOver(internal, made.wired)
2502
+ // Naming no gesture, it makes nothing to watch for one until a first want (#525's `gestureless`).
2503
+ internal = gesturesTold(internal, kind, made.has)
2504
+ // Its Subject's tag, where a rune names it (the gap grill's Q22): what its attribute keys render by.
2505
+ if (sawOf(seen, SEEN.tag)) internal = taggedOf(internal, configs)
2506
+ // Given its Subject: the one element it is, whose own tag it's routed by (Q23). In a browser alone.
2507
+ let onto: WardElement | undefined
2508
+ if (!isServer && sawOf(seen, SEEN.subject)) {
2509
+ const subject = made.own("subject")
2510
+ if (Predicate.isNotUndefined(subject)) {
2511
+ onto = subjectElementOf(subject)
2512
+ internal = elementTagged(internal, onto)
2513
+ }
2514
+ }
2515
+ // What its runes' `props` set on its Subject, name by name (`props.ts`): none where no rune has any.
2516
+ let given: PropKeys = NO_PROP_KEYS
2517
+ if (sawOf(seen, SEEN.props)) given = propKeysOf(runePropsOf(configs))
2518
+ // Each rune's `ref`, handed its Subject, the element it's on, while that's on show. With no `show`,
2519
+ // its binding runs them as it mounts that element and lets it go (the cheap `ref`), until a
2520
+ // presence takes it; a `show` ward's go by its `show`.
2521
+ const refs = refsIn(seen, configs)
2522
+ const atMount = mountedRefsFor(refs, made.show, mounted)
2523
+ if (Predicate.isNotUndefined(atMount)) internal = { ...internal, afterMount: afterMountOf(atMount) }
2524
+ const ward = begun.made(
2525
+ wardFor(
2526
+ configs,
2527
+ () => {
2528
+ const bound = bindingWardOf(begun, made.config, internal, given)
2529
+ // Made with the ward, under its own root where it has one (a `layoutId` twin's), so they're
2530
+ // undone as the ward ends: a twin's as the leaving ward that holds it ends it, its element
2531
+ // still there.
2532
+ if (Predicate.isNotUndefined(refs)) {
2533
+ UndefinedOr.match(atMount, {
2534
+ onUndefined: () => refsAtWork(refs, bound, mounted),
2535
+ onDefined: (at) => {
2536
+ at.owner = getOwner()
2537
+ },
2538
+ })
2539
+ }
2540
+ return checked(bound)
2541
+ },
2542
+ seen,
2543
+ ),
2544
+ )
2545
+ // Its function runes' holder reads this one's element for its focus (`reads.ts`), and hands on to it
2546
+ // what only this one has; a stand-in reads it from here on.
2547
+ finished = ward
2548
+ if (Predicate.isNotUndefined(holder)) {
2549
+ drivenBy(holder, ward)
2550
+ holderFinished(holder, ward)
2551
+ }
2552
+ // Its site kept by the ward it hands back, for `createGrip(ward)` (probe: behaviour-runes).
2553
+ if (Predicate.isNotUndefined(site)) siteKeptFor(ward, site)
2554
+ // Those of them the binding doesn't set itself are carried on its spread, a server's too, and by
2555
+ // what `ward.with()` gives. Before anything spreads it.
2556
+ let propKeys = given
2557
+ if (given !== NO_PROP_KEYS) {
2558
+ propKeys = addedTo(ward, given)
2559
+ withCarrying(carrying(ward, propKeys), propKeys)
2560
+ }
2561
+ // Given its Subject, it's put on that element here: nothing spreads it.
2562
+ if (Predicate.isNotUndefined(onto)) putOn(ward, onto, propKeys)
2563
+ if (Predicate.isNotUndefined(made.show)) {
2564
+ // Its exits are told by the one effect its place in the layout has: they go by the same two
2565
+ // things, whether it's shown and whether it's mounted.
2566
+ const settle = exitsOf(ward)
2567
+ wiredFor(ward, state, made, settle)
2568
+ exitsBy(ward, () => settle({ shown: untrack(state.shown), on: untrack(state.onPage) }))
2569
+ showIs(ward, state)
2570
+ // Its word is its `show`, here now. What a function rune read before it is told, unless what
2571
+ // it read was this `show` already, wired early: that read was right, and follows it.
2572
+ if (Predicate.isUndefined(wiredEarlyFor(state, made.show))) tell(state)
2573
+ state.awaited = false
2574
+ return withMounted(ward, mounted, shown)
2575
+ }
2576
+ // No `show` of its own: a presence may take it, by the runes it was made of, where one gives it
2577
+ // an `animate` to leave from or an `exit` to leave to.
2578
+ let taking: (() => Joined) | undefined
2579
+ if (sawOf(seen, SEEN.animate | SEEN.exit)) taking = takingOf(configs, () => made)
2580
+ return plain(ward, taking, atMount)
2581
+ }
2582
+
2583
+ /** `createWard(...runes)` as a list's rows are made, each ward's Features from `begin`: {@link fixed}'s, or {@link auto}. */
2584
+ export const rawWardOf = (begin: () => Begun): HookWardOf => wardOf(begin, false) as HookWardOf
2585
+
2586
+ /** `createWard(...runes)` as an app calls it: a ward a `createPresence` may be given. */
2587
+ export const hookWardOf = (begin: () => Begun): HookWardOf => wardOf(begin, true) as HookWardOf