@wardic/solid 2.2.0 → 3.0.0-next.0

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