@wardic/solid 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (764) hide show
  1. package/README.md +5 -2
  2. package/dist/browser/animation-controls.js +3 -149
  3. package/dist/browser/animation-controls.js.map +1 -1
  4. package/dist/browser/appear.js +3 -743
  5. package/dist/browser/appear.js.map +1 -1
  6. package/dist/browser/batch-gestures.js.map +1 -1
  7. package/dist/browser/batch-reorder-group.js +40 -11
  8. package/dist/browser/batch-reorder-group.js.map +1 -1
  9. package/dist/browser/batch-reorder-places.js +517 -50
  10. package/dist/browser/batch-reorder-places.js.map +1 -1
  11. package/dist/browser/batch-reorder.js +284 -42
  12. package/dist/browser/batch-reorder.js.map +1 -1
  13. package/dist/browser/batch.js +3 -2511
  14. package/dist/browser/batch.js.map +1 -1
  15. package/dist/browser/config.js +11 -1
  16. package/dist/browser/config.js.map +1 -1
  17. package/dist/browser/create-animate.js +4 -2
  18. package/dist/browser/create-animate.js.map +1 -1
  19. package/dist/browser/create-batch.js +2 -2
  20. package/dist/browser/create-batch.js.map +1 -1
  21. package/dist/browser/create-ward.js +54 -13
  22. package/dist/browser/create-ward.js.map +1 -1
  23. package/dist/browser/create-wardic.js +44 -0
  24. package/dist/browser/create-wardic.js.map +1 -0
  25. package/dist/browser/drag-constraints.js +3 -75
  26. package/dist/browser/drag-constraints.js.map +1 -1
  27. package/dist/browser/drag-controls.js +3 -50
  28. package/dist/browser/drag-controls.js.map +1 -1
  29. package/dist/browser/drag-defaults.js +4 -0
  30. package/dist/browser/drag-defaults.js.map +1 -0
  31. package/dist/browser/drag-track.js +3 -826
  32. package/dist/browser/drag-track.js.map +1 -1
  33. package/dist/browser/drag-transition.js +3 -55
  34. package/dist/browser/drag-transition.js.map +1 -1
  35. package/dist/browser/element-setup.js +4 -0
  36. package/dist/browser/element-setup.js.map +1 -0
  37. package/dist/browser/element.js +12 -3
  38. package/dist/browser/element.js.map +1 -1
  39. package/dist/browser/feature.js +3 -270
  40. package/dist/browser/feature.js.map +1 -1
  41. package/dist/browser/features/all.js +3 -9
  42. package/dist/browser/features/all.js.map +1 -1
  43. package/dist/browser/features/colors.js +3 -32
  44. package/dist/browser/features/colors.js.map +1 -1
  45. package/dist/browser/features/dom-animation.js +3 -6
  46. package/dist/browser/features/dom-animation.js.map +1 -1
  47. package/dist/browser/features/dom-max.js +3 -3
  48. package/dist/browser/features/dom-max.js.map +1 -1
  49. package/dist/browser/features/drag.js +3 -27
  50. package/dist/browser/features/drag.js.map +1 -1
  51. package/dist/browser/features/focus.js +3 -17
  52. package/dist/browser/features/focus.js.map +1 -1
  53. package/dist/browser/features/hover.js +3 -17
  54. package/dist/browser/features/hover.js.map +1 -1
  55. package/dist/browser/features/in-view.js +3 -17
  56. package/dist/browser/features/in-view.js.map +1 -1
  57. package/dist/browser/features/input.js +3 -26
  58. package/dist/browser/features/input.js.map +1 -1
  59. package/dist/browser/features/keys.js +3 -18
  60. package/dist/browser/features/keys.js.map +1 -1
  61. package/dist/browser/features/layout.js +3 -32
  62. package/dist/browser/features/layout.js.map +1 -1
  63. package/dist/browser/features/pan.js +3 -17
  64. package/dist/browser/features/pan.js.map +1 -1
  65. package/dist/browser/features/press.js +3 -11
  66. package/dist/browser/features/press.js.map +1 -1
  67. package/dist/browser/features/scroll.js +3 -20
  68. package/dist/browser/features/scroll.js.map +1 -1
  69. package/dist/browser/gesture-features.js +3 -28
  70. package/dist/browser/gesture-features.js.map +1 -1
  71. package/dist/browser/gesture-info.js +3 -42
  72. package/dist/browser/gesture-info.js.map +1 -1
  73. package/dist/browser/imperative.js +3 -708
  74. package/dist/browser/imperative.js.map +1 -1
  75. package/dist/browser/index.js +2 -1
  76. package/dist/browser/index.js.map +1 -1
  77. package/dist/browser/instance-features.js +66 -0
  78. package/dist/browser/instance-features.js.map +1 -0
  79. package/dist/browser/instant.js +3 -50
  80. package/dist/browser/instant.js.map +1 -1
  81. package/dist/browser/layout-group.js +3 -26
  82. package/dist/browser/layout-group.js.map +1 -1
  83. package/dist/browser/layout-member.js +3 -373
  84. package/dist/browser/layout-member.js.map +1 -1
  85. package/dist/browser/layout-projection.js +8 -1
  86. package/dist/browser/layout-projection.js.map +1 -1
  87. package/dist/browser/layout.js +5 -6
  88. package/dist/browser/layout.js.map +1 -1
  89. package/dist/browser/lazy-batch-gestures.js.map +1 -1
  90. package/dist/browser/live-scroll.js +29 -21
  91. package/dist/browser/live-scroll.js.map +1 -1
  92. package/dist/browser/live-style.js +3 -313
  93. package/dist/browser/live-style.js.map +1 -1
  94. package/dist/browser/live-value.js +11 -2
  95. package/dist/browser/live-value.js.map +1 -1
  96. package/dist/browser/member-hold.js +3 -180
  97. package/dist/browser/member-hold.js.map +1 -1
  98. package/dist/browser/messages.js +20 -0
  99. package/dist/browser/messages.js.map +1 -0
  100. package/dist/browser/owner-scope.js +3 -28
  101. package/dist/browser/owner-scope.js.map +1 -1
  102. package/dist/browser/presence-controller.js +3 -1449
  103. package/dist/browser/presence-controller.js.map +1 -1
  104. package/dist/browser/presence-record.js +9 -24
  105. package/dist/browser/presence-record.js.map +1 -1
  106. package/dist/browser/presence.js.map +1 -1
  107. package/dist/browser/press.js +3 -23
  108. package/dist/browser/press.js.map +1 -1
  109. package/dist/browser/provider.js +65 -11
  110. package/dist/browser/provider.js.map +1 -1
  111. package/dist/browser/reactivity.js +0 -7
  112. package/dist/browser/reactivity.js.map +1 -1
  113. package/dist/browser/reorder.js.map +1 -1
  114. package/dist/browser/retarget-legs.js +3 -1021
  115. package/dist/browser/retarget-legs.js.map +1 -1
  116. package/dist/browser/runtime.js +62 -21
  117. package/dist/browser/runtime.js.map +1 -1
  118. package/dist/browser/scroll-values.js +46 -0
  119. package/dist/browser/scroll-values.js.map +1 -0
  120. package/dist/browser/server-interpolators.js +3 -19
  121. package/dist/browser/server-interpolators.js.map +1 -1
  122. package/dist/browser/spans-check.js +25 -0
  123. package/dist/browser/spans-check.js.map +1 -0
  124. package/dist/browser/spine.js +3 -3043
  125. package/dist/browser/spine.js.map +1 -1
  126. package/dist/browser/timelines.js +4 -0
  127. package/dist/browser/timelines.js.map +1 -0
  128. package/dist/browser/unstable/v2/batch-reorder-group.js +36 -6
  129. package/dist/browser/unstable/v2/batch-reorder-group.js.map +1 -1
  130. package/dist/browser/unstable/v2/create-animate.js +4 -2
  131. package/dist/browser/unstable/v2/create-animate.js.map +1 -1
  132. package/dist/browser/unstable/v2/create-batch.js +2 -2
  133. package/dist/browser/unstable/v2/create-batch.js.map +1 -1
  134. package/dist/browser/unstable/v2/create-wardic.js +45 -0
  135. package/dist/browser/unstable/v2/create-wardic.js.map +1 -0
  136. package/dist/browser/unstable/v2/element.js +12 -2
  137. package/dist/browser/unstable/v2/element.js.map +1 -1
  138. package/dist/browser/unstable/v2/index.js +1 -0
  139. package/dist/browser/unstable/v2/index.js.map +1 -1
  140. package/dist/browser/unstable/v2/lifecycle.js +2 -0
  141. package/dist/browser/unstable/v2/lifecycle.js.map +1 -1
  142. package/dist/browser/unstable/v2/live-scroll.js +22 -13
  143. package/dist/browser/unstable/v2/live-scroll.js.map +1 -1
  144. package/dist/browser/unstable/v2/live-value.js +9 -1
  145. package/dist/browser/unstable/v2/live-value.js.map +1 -1
  146. package/dist/browser/unstable/v2/presence.js.map +1 -1
  147. package/dist/browser/unstable/v2/provider.js +68 -13
  148. package/dist/browser/unstable/v2/provider.js.map +1 -1
  149. package/dist/browser/unstable/v2/reorder.js.map +1 -1
  150. package/dist/browser/unstable/v2/w.js +7 -8
  151. package/dist/browser/unstable/v2/w.js.map +1 -1
  152. package/dist/browser/unstable/v2/ward.js +45 -12
  153. package/dist/browser/unstable/v2/ward.js.map +1 -1
  154. package/dist/browser/unstable/v2/wardic-instance.js +2 -0
  155. package/dist/browser/unstable/v2/wardic-instance.js.map +1 -0
  156. package/dist/browser/variant-target.js +3 -228
  157. package/dist/browser/variant-target.js.map +1 -1
  158. package/dist/browser/variant-tree.js +3 -393
  159. package/dist/browser/variant-tree.js.map +1 -1
  160. package/dist/browser/w.js +8 -9
  161. package/dist/browser/w.js.map +1 -1
  162. package/dist/browser/wardic-config-value.js +3 -90
  163. package/dist/browser/wardic-config-value.js.map +1 -1
  164. package/dist/browser/wardic-instance.js +2 -0
  165. package/dist/browser/wardic-instance.js.map +1 -0
  166. package/dist/server/animation-controls.js +3 -149
  167. package/dist/server/animation-controls.js.map +1 -1
  168. package/dist/server/appear.js +3 -743
  169. package/dist/server/appear.js.map +1 -1
  170. package/dist/server/batch-gestures.js.map +1 -1
  171. package/dist/server/batch-reorder-group.js +40 -11
  172. package/dist/server/batch-reorder-group.js.map +1 -1
  173. package/dist/server/batch-reorder-places.js +517 -50
  174. package/dist/server/batch-reorder-places.js.map +1 -1
  175. package/dist/server/batch-reorder.js +284 -42
  176. package/dist/server/batch-reorder.js.map +1 -1
  177. package/dist/server/batch.js +3 -2511
  178. package/dist/server/batch.js.map +1 -1
  179. package/dist/server/config.js +11 -1
  180. package/dist/server/config.js.map +1 -1
  181. package/dist/server/create-animate.js +4 -2
  182. package/dist/server/create-animate.js.map +1 -1
  183. package/dist/server/create-batch.js +2 -2
  184. package/dist/server/create-batch.js.map +1 -1
  185. package/dist/server/create-ward.js +54 -13
  186. package/dist/server/create-ward.js.map +1 -1
  187. package/dist/server/create-wardic.js +44 -0
  188. package/dist/server/create-wardic.js.map +1 -0
  189. package/dist/server/drag-constraints.js +3 -75
  190. package/dist/server/drag-constraints.js.map +1 -1
  191. package/dist/server/drag-controls.js +3 -50
  192. package/dist/server/drag-controls.js.map +1 -1
  193. package/dist/server/drag-defaults.js +4 -0
  194. package/dist/server/drag-defaults.js.map +1 -0
  195. package/dist/server/drag-track.js +3 -826
  196. package/dist/server/drag-track.js.map +1 -1
  197. package/dist/server/drag-transition.js +3 -55
  198. package/dist/server/drag-transition.js.map +1 -1
  199. package/dist/server/element-setup.js +4 -0
  200. package/dist/server/element-setup.js.map +1 -0
  201. package/dist/server/element.js +12 -3
  202. package/dist/server/element.js.map +1 -1
  203. package/dist/server/feature.js +3 -270
  204. package/dist/server/feature.js.map +1 -1
  205. package/dist/server/features/all.js +3 -9
  206. package/dist/server/features/all.js.map +1 -1
  207. package/dist/server/features/colors.js +3 -32
  208. package/dist/server/features/colors.js.map +1 -1
  209. package/dist/server/features/dom-animation.js +3 -6
  210. package/dist/server/features/dom-animation.js.map +1 -1
  211. package/dist/server/features/dom-max.js +3 -3
  212. package/dist/server/features/dom-max.js.map +1 -1
  213. package/dist/server/features/drag.js +3 -27
  214. package/dist/server/features/drag.js.map +1 -1
  215. package/dist/server/features/focus.js +3 -17
  216. package/dist/server/features/focus.js.map +1 -1
  217. package/dist/server/features/hover.js +3 -17
  218. package/dist/server/features/hover.js.map +1 -1
  219. package/dist/server/features/in-view.js +3 -17
  220. package/dist/server/features/in-view.js.map +1 -1
  221. package/dist/server/features/input.js +3 -26
  222. package/dist/server/features/input.js.map +1 -1
  223. package/dist/server/features/keys.js +3 -18
  224. package/dist/server/features/keys.js.map +1 -1
  225. package/dist/server/features/layout.js +3 -32
  226. package/dist/server/features/layout.js.map +1 -1
  227. package/dist/server/features/pan.js +3 -17
  228. package/dist/server/features/pan.js.map +1 -1
  229. package/dist/server/features/press.js +3 -11
  230. package/dist/server/features/press.js.map +1 -1
  231. package/dist/server/features/scroll.js +3 -20
  232. package/dist/server/features/scroll.js.map +1 -1
  233. package/dist/server/gesture-features.js +3 -28
  234. package/dist/server/gesture-features.js.map +1 -1
  235. package/dist/server/gesture-info.js +3 -42
  236. package/dist/server/gesture-info.js.map +1 -1
  237. package/dist/server/imperative.js +3 -708
  238. package/dist/server/imperative.js.map +1 -1
  239. package/dist/server/index.js +2 -1
  240. package/dist/server/index.js.map +1 -1
  241. package/dist/server/instance-features.js +66 -0
  242. package/dist/server/instance-features.js.map +1 -0
  243. package/dist/server/instant.js +3 -50
  244. package/dist/server/instant.js.map +1 -1
  245. package/dist/server/layout-group.js +3 -26
  246. package/dist/server/layout-group.js.map +1 -1
  247. package/dist/server/layout-member.js +3 -373
  248. package/dist/server/layout-member.js.map +1 -1
  249. package/dist/server/layout-projection.js +8 -1
  250. package/dist/server/layout-projection.js.map +1 -1
  251. package/dist/server/layout.js +5 -6
  252. package/dist/server/layout.js.map +1 -1
  253. package/dist/server/lazy-batch-gestures.js.map +1 -1
  254. package/dist/server/live-scroll.js +29 -21
  255. package/dist/server/live-scroll.js.map +1 -1
  256. package/dist/server/live-style.js +3 -313
  257. package/dist/server/live-style.js.map +1 -1
  258. package/dist/server/live-value.js +11 -2
  259. package/dist/server/live-value.js.map +1 -1
  260. package/dist/server/member-hold.js +3 -180
  261. package/dist/server/member-hold.js.map +1 -1
  262. package/dist/server/messages.js +20 -0
  263. package/dist/server/messages.js.map +1 -0
  264. package/dist/server/owner-scope.js +3 -28
  265. package/dist/server/owner-scope.js.map +1 -1
  266. package/dist/server/presence-controller.js +3 -1449
  267. package/dist/server/presence-controller.js.map +1 -1
  268. package/dist/server/presence-record.js +9 -24
  269. package/dist/server/presence-record.js.map +1 -1
  270. package/dist/server/presence.js.map +1 -1
  271. package/dist/server/press.js +3 -23
  272. package/dist/server/press.js.map +1 -1
  273. package/dist/server/provider.js +65 -11
  274. package/dist/server/provider.js.map +1 -1
  275. package/dist/server/reactivity.js +0 -7
  276. package/dist/server/reactivity.js.map +1 -1
  277. package/dist/server/reorder.js.map +1 -1
  278. package/dist/server/retarget-legs.js +3 -1021
  279. package/dist/server/retarget-legs.js.map +1 -1
  280. package/dist/server/runtime.js +62 -21
  281. package/dist/server/runtime.js.map +1 -1
  282. package/dist/server/scroll-values.js +46 -0
  283. package/dist/server/scroll-values.js.map +1 -0
  284. package/dist/server/server-interpolators.js +3 -19
  285. package/dist/server/server-interpolators.js.map +1 -1
  286. package/dist/server/spans-check.js +25 -0
  287. package/dist/server/spans-check.js.map +1 -0
  288. package/dist/server/spine.js +3 -3043
  289. package/dist/server/spine.js.map +1 -1
  290. package/dist/server/timelines.js +4 -0
  291. package/dist/server/timelines.js.map +1 -0
  292. package/dist/server/unstable/v2/batch-reorder-group.js +36 -6
  293. package/dist/server/unstable/v2/batch-reorder-group.js.map +1 -1
  294. package/dist/server/unstable/v2/create-animate.js +4 -2
  295. package/dist/server/unstable/v2/create-animate.js.map +1 -1
  296. package/dist/server/unstable/v2/create-batch.js +2 -2
  297. package/dist/server/unstable/v2/create-batch.js.map +1 -1
  298. package/dist/server/unstable/v2/create-wardic.js +45 -0
  299. package/dist/server/unstable/v2/create-wardic.js.map +1 -0
  300. package/dist/server/unstable/v2/element.js +12 -2
  301. package/dist/server/unstable/v2/element.js.map +1 -1
  302. package/dist/server/unstable/v2/index.js +1 -0
  303. package/dist/server/unstable/v2/index.js.map +1 -1
  304. package/dist/server/unstable/v2/lifecycle.js +2 -0
  305. package/dist/server/unstable/v2/lifecycle.js.map +1 -1
  306. package/dist/server/unstable/v2/live-scroll.js +22 -13
  307. package/dist/server/unstable/v2/live-scroll.js.map +1 -1
  308. package/dist/server/unstable/v2/live-value.js +9 -1
  309. package/dist/server/unstable/v2/live-value.js.map +1 -1
  310. package/dist/server/unstable/v2/presence.js.map +1 -1
  311. package/dist/server/unstable/v2/provider.js +68 -13
  312. package/dist/server/unstable/v2/provider.js.map +1 -1
  313. package/dist/server/unstable/v2/reorder.js.map +1 -1
  314. package/dist/server/unstable/v2/w.js +7 -8
  315. package/dist/server/unstable/v2/w.js.map +1 -1
  316. package/dist/server/unstable/v2/ward.js +45 -12
  317. package/dist/server/unstable/v2/ward.js.map +1 -1
  318. package/dist/server/unstable/v2/wardic-instance.js +2 -0
  319. package/dist/server/unstable/v2/wardic-instance.js.map +1 -0
  320. package/dist/server/variant-target.js +3 -228
  321. package/dist/server/variant-target.js.map +1 -1
  322. package/dist/server/variant-tree.js +3 -393
  323. package/dist/server/variant-tree.js.map +1 -1
  324. package/dist/server/w.js +8 -9
  325. package/dist/server/w.js.map +1 -1
  326. package/dist/server/wardic-config-value.js +3 -90
  327. package/dist/server/wardic-config-value.js.map +1 -1
  328. package/dist/server/wardic-instance.js +2 -0
  329. package/dist/server/wardic-instance.js.map +1 -0
  330. package/dist/solid/animation-controls.d.ts +1 -102
  331. package/dist/solid/animation-controls.d.ts.map +1 -1
  332. package/dist/solid/animation-controls.js +3 -128
  333. package/dist/solid/animation-controls.js.map +1 -1
  334. package/dist/solid/appear.d.ts +1 -218
  335. package/dist/solid/appear.d.ts.map +1 -1
  336. package/dist/solid/appear.js +3 -529
  337. package/dist/solid/appear.js.map +1 -1
  338. package/dist/solid/batch-gestures.d.ts +2 -2
  339. package/dist/solid/batch-gestures.d.ts.map +1 -1
  340. package/dist/solid/batch-gestures.js.map +1 -1
  341. package/dist/solid/batch-reorder-group.d.ts +17 -15
  342. package/dist/solid/batch-reorder-group.d.ts.map +1 -1
  343. package/dist/solid/batch-reorder-group.jsx +37 -7
  344. package/dist/solid/batch-reorder-group.jsx.map +1 -1
  345. package/dist/solid/batch-reorder-places.d.ts +184 -23
  346. package/dist/solid/batch-reorder-places.d.ts.map +1 -1
  347. package/dist/solid/batch-reorder-places.js +397 -41
  348. package/dist/solid/batch-reorder-places.js.map +1 -1
  349. package/dist/solid/batch-reorder.d.ts +30 -1
  350. package/dist/solid/batch-reorder.d.ts.map +1 -1
  351. package/dist/solid/batch-reorder.js +298 -37
  352. package/dist/solid/batch-reorder.js.map +1 -1
  353. package/dist/solid/batch.d.ts +1 -511
  354. package/dist/solid/batch.d.ts.map +1 -1
  355. package/dist/solid/batch.js +3 -2484
  356. package/dist/solid/batch.js.map +1 -1
  357. package/dist/solid/config.d.ts +2 -690
  358. package/dist/solid/config.d.ts.map +1 -1
  359. package/dist/solid/config.js +11 -1
  360. package/dist/solid/config.js.map +1 -1
  361. package/dist/solid/create-animate.d.ts.map +1 -1
  362. package/dist/solid/create-animate.jsx +3 -1
  363. package/dist/solid/create-animate.jsx.map +1 -1
  364. package/dist/solid/create-batch.jsx +2 -2
  365. package/dist/solid/create-batch.jsx.map +1 -1
  366. package/dist/solid/create-ward.d.ts +8 -3
  367. package/dist/solid/create-ward.d.ts.map +1 -1
  368. package/dist/solid/create-ward.jsx +50 -11
  369. package/dist/solid/create-ward.jsx.map +1 -1
  370. package/dist/solid/create-wardic.d.ts +24 -0
  371. package/dist/solid/create-wardic.d.ts.map +1 -0
  372. package/dist/solid/create-wardic.jsx +42 -0
  373. package/dist/solid/create-wardic.jsx.map +1 -0
  374. package/dist/solid/drag-constraints.d.ts +1 -45
  375. package/dist/solid/drag-constraints.d.ts.map +1 -1
  376. package/dist/solid/drag-constraints.js +3 -48
  377. package/dist/solid/drag-constraints.js.map +1 -1
  378. package/dist/solid/drag-controls.d.ts +1 -49
  379. package/dist/solid/drag-controls.d.ts.map +1 -1
  380. package/dist/solid/drag-controls.js +3 -50
  381. package/dist/solid/drag-controls.js.map +1 -1
  382. package/dist/solid/drag-defaults.d.ts +2 -0
  383. package/dist/solid/drag-defaults.d.ts.map +1 -0
  384. package/dist/solid/drag-defaults.js +4 -0
  385. package/dist/solid/drag-defaults.js.map +1 -0
  386. package/dist/solid/drag-track.d.ts +1 -232
  387. package/dist/solid/drag-track.d.ts.map +1 -1
  388. package/dist/solid/drag-track.js +3 -641
  389. package/dist/solid/drag-track.js.map +1 -1
  390. package/dist/solid/drag-transition.d.ts +1 -19
  391. package/dist/solid/drag-transition.d.ts.map +1 -1
  392. package/dist/solid/drag-transition.js +3 -30
  393. package/dist/solid/drag-transition.js.map +1 -1
  394. package/dist/solid/element-setup.d.ts +2 -0
  395. package/dist/solid/element-setup.d.ts.map +1 -0
  396. package/dist/solid/element-setup.js +4 -0
  397. package/dist/solid/element-setup.js.map +1 -0
  398. package/dist/solid/element.d.ts +27 -8
  399. package/dist/solid/element.d.ts.map +1 -1
  400. package/dist/solid/element.jsx +13 -5
  401. package/dist/solid/element.jsx.map +1 -1
  402. package/dist/solid/feature.d.ts +1 -118
  403. package/dist/solid/feature.d.ts.map +1 -1
  404. package/dist/solid/feature.js +3 -257
  405. package/dist/solid/feature.js.map +1 -1
  406. package/dist/solid/features/all.d.ts +1 -9
  407. package/dist/solid/features/all.d.ts.map +1 -1
  408. package/dist/solid/features/all.js +3 -9
  409. package/dist/solid/features/all.js.map +1 -1
  410. package/dist/solid/features/colors.d.ts +1 -11
  411. package/dist/solid/features/colors.d.ts.map +1 -1
  412. package/dist/solid/features/colors.js +3 -33
  413. package/dist/solid/features/colors.js.map +1 -1
  414. package/dist/solid/features/dom-animation.d.ts +1 -10
  415. package/dist/solid/features/dom-animation.d.ts.map +1 -1
  416. package/dist/solid/features/dom-animation.js +3 -6
  417. package/dist/solid/features/dom-animation.js.map +1 -1
  418. package/dist/solid/features/dom-max.d.ts +1 -9
  419. package/dist/solid/features/dom-max.d.ts.map +1 -1
  420. package/dist/solid/features/dom-max.js +3 -3
  421. package/dist/solid/features/dom-max.js.map +1 -1
  422. package/dist/solid/features/drag.d.ts +1 -4
  423. package/dist/solid/features/drag.d.ts.map +1 -1
  424. package/dist/solid/features/drag.js +3 -27
  425. package/dist/solid/features/drag.js.map +1 -1
  426. package/dist/solid/features/focus.d.ts +1 -4
  427. package/dist/solid/features/focus.d.ts.map +1 -1
  428. package/dist/solid/features/focus.js +3 -15
  429. package/dist/solid/features/focus.js.map +1 -1
  430. package/dist/solid/features/hover.d.ts +1 -4
  431. package/dist/solid/features/hover.d.ts.map +1 -1
  432. package/dist/solid/features/hover.js +3 -15
  433. package/dist/solid/features/hover.js.map +1 -1
  434. package/dist/solid/features/in-view.d.ts +1 -4
  435. package/dist/solid/features/in-view.d.ts.map +1 -1
  436. package/dist/solid/features/in-view.js +3 -15
  437. package/dist/solid/features/in-view.js.map +1 -1
  438. package/dist/solid/features/input.d.ts +1 -25
  439. package/dist/solid/features/input.d.ts.map +1 -1
  440. package/dist/solid/features/input.js +3 -26
  441. package/dist/solid/features/input.js.map +1 -1
  442. package/dist/solid/features/keys.d.ts +1 -69
  443. package/dist/solid/features/keys.d.ts.map +1 -1
  444. package/dist/solid/features/keys.js +3 -25
  445. package/dist/solid/features/keys.js.map +1 -1
  446. package/dist/solid/features/layout.d.ts +1 -31
  447. package/dist/solid/features/layout.d.ts.map +1 -1
  448. package/dist/solid/features/layout.js +3 -33
  449. package/dist/solid/features/layout.js.map +1 -1
  450. package/dist/solid/features/pan.d.ts +1 -4
  451. package/dist/solid/features/pan.d.ts.map +1 -1
  452. package/dist/solid/features/pan.js +3 -15
  453. package/dist/solid/features/pan.js.map +1 -1
  454. package/dist/solid/features/press.d.ts +1 -10
  455. package/dist/solid/features/press.d.ts.map +1 -1
  456. package/dist/solid/features/press.js +3 -9
  457. package/dist/solid/features/press.js.map +1 -1
  458. package/dist/solid/features/scroll.d.ts +1 -15
  459. package/dist/solid/features/scroll.d.ts.map +1 -1
  460. package/dist/solid/features/scroll.js +3 -20
  461. package/dist/solid/features/scroll.js.map +1 -1
  462. package/dist/solid/gesture-features.d.ts +1 -27
  463. package/dist/solid/gesture-features.d.ts.map +1 -1
  464. package/dist/solid/gesture-features.js +3 -28
  465. package/dist/solid/gesture-features.js.map +1 -1
  466. package/dist/solid/gesture-info.d.ts +1 -58
  467. package/dist/solid/gesture-info.d.ts.map +1 -1
  468. package/dist/solid/gesture-info.js +3 -22
  469. package/dist/solid/gesture-info.js.map +1 -1
  470. package/dist/solid/imperative.d.ts +1 -202
  471. package/dist/solid/imperative.d.ts.map +1 -1
  472. package/dist/solid/imperative.js +3 -622
  473. package/dist/solid/imperative.js.map +1 -1
  474. package/dist/solid/index.d.ts +4 -2
  475. package/dist/solid/index.d.ts.map +1 -1
  476. package/dist/solid/index.jsx +2 -1
  477. package/dist/solid/index.jsx.map +1 -1
  478. package/dist/solid/instance-features.d.ts +7 -0
  479. package/dist/solid/instance-features.d.ts.map +1 -0
  480. package/dist/solid/instance-features.js +63 -0
  481. package/dist/solid/instance-features.js.map +1 -0
  482. package/dist/solid/instant.d.ts +1 -43
  483. package/dist/solid/instant.d.ts.map +1 -1
  484. package/dist/solid/instant.js +3 -48
  485. package/dist/solid/instant.js.map +1 -1
  486. package/dist/solid/layout-group.d.ts +1 -13
  487. package/dist/solid/layout-group.d.ts.map +1 -1
  488. package/dist/solid/layout-group.js +3 -26
  489. package/dist/solid/layout-group.js.map +1 -1
  490. package/dist/solid/layout-member.d.ts +1 -126
  491. package/dist/solid/layout-member.d.ts.map +1 -1
  492. package/dist/solid/layout-member.js +3 -177
  493. package/dist/solid/layout-member.js.map +1 -1
  494. package/dist/solid/layout-projection.d.ts +6 -0
  495. package/dist/solid/layout-projection.d.ts.map +1 -1
  496. package/dist/solid/layout-projection.jsx +8 -1
  497. package/dist/solid/layout-projection.jsx.map +1 -1
  498. package/dist/solid/layout.d.ts +4 -3
  499. package/dist/solid/layout.d.ts.map +1 -1
  500. package/dist/solid/layout.jsx +5 -6
  501. package/dist/solid/layout.jsx.map +1 -1
  502. package/dist/solid/lazy-batch-gestures.d.ts +2 -2
  503. package/dist/solid/lazy-batch-gestures.d.ts.map +1 -1
  504. package/dist/solid/lazy-batch-gestures.js.map +1 -1
  505. package/dist/solid/live-scroll.d.ts +4 -0
  506. package/dist/solid/live-scroll.d.ts.map +1 -1
  507. package/dist/solid/live-scroll.jsx +29 -19
  508. package/dist/solid/live-scroll.jsx.map +1 -1
  509. package/dist/solid/live-style.d.ts +1 -147
  510. package/dist/solid/live-style.d.ts.map +1 -1
  511. package/dist/solid/live-style.js +3 -304
  512. package/dist/solid/live-style.js.map +1 -1
  513. package/dist/solid/live-value.d.ts +1 -0
  514. package/dist/solid/live-value.d.ts.map +1 -1
  515. package/dist/solid/live-value.jsx +12 -3
  516. package/dist/solid/live-value.jsx.map +1 -1
  517. package/dist/solid/member-hold.d.ts +1 -46
  518. package/dist/solid/member-hold.d.ts.map +1 -1
  519. package/dist/solid/member-hold.js +3 -188
  520. package/dist/solid/member-hold.js.map +1 -1
  521. package/dist/solid/messages.d.ts +20 -0
  522. package/dist/solid/messages.d.ts.map +1 -0
  523. package/dist/solid/messages.js +22 -0
  524. package/dist/solid/messages.js.map +1 -0
  525. package/dist/solid/owner-scope.d.ts +1 -15
  526. package/dist/solid/owner-scope.d.ts.map +1 -1
  527. package/dist/solid/owner-scope.js +3 -30
  528. package/dist/solid/owner-scope.js.map +1 -1
  529. package/dist/solid/presence-controller.d.ts +1 -121
  530. package/dist/solid/presence-controller.d.ts.map +1 -1
  531. package/dist/solid/presence-controller.js +3 -1335
  532. package/dist/solid/presence-controller.js.map +1 -1
  533. package/dist/solid/presence-record.d.ts +6 -168
  534. package/dist/solid/presence-record.d.ts.map +1 -1
  535. package/dist/solid/presence-record.js +9 -23
  536. package/dist/solid/presence-record.js.map +1 -1
  537. package/dist/solid/presence.d.ts +3 -1
  538. package/dist/solid/presence.d.ts.map +1 -1
  539. package/dist/solid/presence.jsx.map +1 -1
  540. package/dist/solid/press.d.ts +1 -23
  541. package/dist/solid/press.d.ts.map +1 -1
  542. package/dist/solid/press.js +3 -18
  543. package/dist/solid/press.js.map +1 -1
  544. package/dist/solid/provider.d.ts +24 -4
  545. package/dist/solid/provider.d.ts.map +1 -1
  546. package/dist/solid/provider.jsx +63 -7
  547. package/dist/solid/provider.jsx.map +1 -1
  548. package/dist/solid/reactivity.d.ts +1 -20
  549. package/dist/solid/reactivity.d.ts.map +1 -1
  550. package/dist/solid/reactivity.js +0 -7
  551. package/dist/solid/reactivity.js.map +1 -1
  552. package/dist/solid/reorder.d.ts +5 -4
  553. package/dist/solid/reorder.d.ts.map +1 -1
  554. package/dist/solid/reorder.jsx.map +1 -1
  555. package/dist/solid/retarget-legs.d.ts +1 -188
  556. package/dist/solid/retarget-legs.d.ts.map +1 -1
  557. package/dist/solid/retarget-legs.js +3 -825
  558. package/dist/solid/retarget-legs.js.map +1 -1
  559. package/dist/solid/runtime.d.ts +15 -27
  560. package/dist/solid/runtime.d.ts.map +1 -1
  561. package/dist/solid/runtime.js +52 -23
  562. package/dist/solid/runtime.js.map +1 -1
  563. package/dist/solid/scroll-values.d.ts +30 -0
  564. package/dist/solid/scroll-values.d.ts.map +1 -0
  565. package/dist/solid/scroll-values.js +44 -0
  566. package/dist/solid/scroll-values.js.map +1 -0
  567. package/dist/solid/server-interpolators.d.ts +1 -12
  568. package/dist/solid/server-interpolators.d.ts.map +1 -1
  569. package/dist/solid/server-interpolators.js +3 -19
  570. package/dist/solid/server-interpolators.js.map +1 -1
  571. package/dist/solid/spans-check.d.ts +4 -0
  572. package/dist/solid/spans-check.d.ts.map +1 -0
  573. package/dist/solid/spans-check.js +23 -0
  574. package/dist/solid/spans-check.js.map +1 -0
  575. package/dist/solid/spine.d.ts +1 -612
  576. package/dist/solid/spine.d.ts.map +1 -1
  577. package/dist/solid/spine.js +3 -2886
  578. package/dist/solid/spine.js.map +1 -1
  579. package/dist/solid/timelines.d.ts +2 -0
  580. package/dist/solid/timelines.d.ts.map +1 -0
  581. package/dist/solid/timelines.js +4 -0
  582. package/dist/solid/timelines.js.map +1 -0
  583. package/dist/solid/unstable/v2/batch-reorder-group.d.ts +18 -17
  584. package/dist/solid/unstable/v2/batch-reorder-group.d.ts.map +1 -1
  585. package/dist/solid/unstable/v2/batch-reorder-group.jsx +32 -5
  586. package/dist/solid/unstable/v2/batch-reorder-group.jsx.map +1 -1
  587. package/dist/solid/unstable/v2/create-animate.d.ts.map +1 -1
  588. package/dist/solid/unstable/v2/create-animate.jsx +3 -1
  589. package/dist/solid/unstable/v2/create-animate.jsx.map +1 -1
  590. package/dist/solid/unstable/v2/create-batch.jsx +2 -2
  591. package/dist/solid/unstable/v2/create-batch.jsx.map +1 -1
  592. package/dist/solid/unstable/v2/create-wardic.d.ts +25 -0
  593. package/dist/solid/unstable/v2/create-wardic.d.ts.map +1 -0
  594. package/dist/solid/unstable/v2/create-wardic.jsx +43 -0
  595. package/dist/solid/unstable/v2/create-wardic.jsx.map +1 -0
  596. package/dist/solid/unstable/v2/element.d.ts +53 -18
  597. package/dist/solid/unstable/v2/element.d.ts.map +1 -1
  598. package/dist/solid/unstable/v2/element.jsx +13 -4
  599. package/dist/solid/unstable/v2/element.jsx.map +1 -1
  600. package/dist/solid/unstable/v2/index.d.ts +3 -1
  601. package/dist/solid/unstable/v2/index.d.ts.map +1 -1
  602. package/dist/solid/unstable/v2/index.jsx +1 -0
  603. package/dist/solid/unstable/v2/index.jsx.map +1 -1
  604. package/dist/solid/unstable/v2/lifecycle.d.ts +29 -0
  605. package/dist/solid/unstable/v2/lifecycle.d.ts.map +1 -1
  606. package/dist/solid/unstable/v2/lifecycle.js +2 -0
  607. package/dist/solid/unstable/v2/lifecycle.js.map +1 -1
  608. package/dist/solid/unstable/v2/live-scroll.d.ts +4 -0
  609. package/dist/solid/unstable/v2/live-scroll.d.ts.map +1 -1
  610. package/dist/solid/unstable/v2/live-scroll.jsx +22 -11
  611. package/dist/solid/unstable/v2/live-scroll.jsx.map +1 -1
  612. package/dist/solid/unstable/v2/live-value.d.ts +1 -0
  613. package/dist/solid/unstable/v2/live-value.d.ts.map +1 -1
  614. package/dist/solid/unstable/v2/live-value.jsx +10 -1
  615. package/dist/solid/unstable/v2/live-value.jsx.map +1 -1
  616. package/dist/solid/unstable/v2/presence.d.ts +3 -1
  617. package/dist/solid/unstable/v2/presence.d.ts.map +1 -1
  618. package/dist/solid/unstable/v2/presence.jsx.map +1 -1
  619. package/dist/solid/unstable/v2/provider.d.ts +24 -4
  620. package/dist/solid/unstable/v2/provider.d.ts.map +1 -1
  621. package/dist/solid/unstable/v2/provider.jsx +66 -10
  622. package/dist/solid/unstable/v2/provider.jsx.map +1 -1
  623. package/dist/solid/unstable/v2/reorder.d.ts +4 -3
  624. package/dist/solid/unstable/v2/reorder.d.ts.map +1 -1
  625. package/dist/solid/unstable/v2/reorder.jsx.map +1 -1
  626. package/dist/solid/unstable/v2/w.d.ts +42 -10
  627. package/dist/solid/unstable/v2/w.d.ts.map +1 -1
  628. package/dist/solid/unstable/v2/w.jsx +5 -7
  629. package/dist/solid/unstable/v2/w.jsx.map +1 -1
  630. package/dist/solid/unstable/v2/ward.d.ts +17 -9
  631. package/dist/solid/unstable/v2/ward.d.ts.map +1 -1
  632. package/dist/solid/unstable/v2/ward.jsx +40 -10
  633. package/dist/solid/unstable/v2/ward.jsx.map +1 -1
  634. package/dist/solid/unstable/v2/wardic-instance.d.ts +47 -0
  635. package/dist/solid/unstable/v2/wardic-instance.d.ts.map +1 -0
  636. package/dist/solid/unstable/v2/wardic-instance.js +2 -0
  637. package/dist/solid/unstable/v2/wardic-instance.js.map +1 -0
  638. package/dist/solid/variant-target.d.ts +1 -103
  639. package/dist/solid/variant-target.d.ts.map +1 -1
  640. package/dist/solid/variant-target.js +3 -181
  641. package/dist/solid/variant-target.js.map +1 -1
  642. package/dist/solid/variant-tree.d.ts +1 -348
  643. package/dist/solid/variant-tree.d.ts.map +1 -1
  644. package/dist/solid/variant-tree.js +3 -357
  645. package/dist/solid/variant-tree.js.map +1 -1
  646. package/dist/solid/w.d.ts +25 -10
  647. package/dist/solid/w.d.ts.map +1 -1
  648. package/dist/solid/w.jsx +8 -7
  649. package/dist/solid/w.jsx.map +1 -1
  650. package/dist/solid/ward-keys.d.ts +22 -3
  651. package/dist/solid/ward-keys.d.ts.map +1 -1
  652. package/dist/solid/wardic-config-value.d.ts +1 -86
  653. package/dist/solid/wardic-config-value.d.ts.map +1 -1
  654. package/dist/solid/wardic-config-value.js +3 -105
  655. package/dist/solid/wardic-config-value.js.map +1 -1
  656. package/dist/solid/wardic-instance.d.ts +46 -0
  657. package/dist/solid/wardic-instance.d.ts.map +1 -0
  658. package/dist/solid/wardic-instance.js +2 -0
  659. package/dist/solid/wardic-instance.js.map +1 -0
  660. package/package.json +4 -4
  661. package/src/animation-controls.ts +3 -206
  662. package/src/appear.ts +3 -824
  663. package/src/batch-gestures.ts +2 -2
  664. package/src/batch-reorder-group.tsx +47 -21
  665. package/src/batch-reorder-places.ts +566 -54
  666. package/src/batch-reorder.ts +333 -40
  667. package/src/batch.ts +3 -3078
  668. package/src/config.ts +5 -804
  669. package/src/create-animate.tsx +3 -1
  670. package/src/create-batch.tsx +2 -2
  671. package/src/create-ward.tsx +55 -50
  672. package/src/create-wardic.tsx +45 -0
  673. package/src/drag-constraints.ts +3 -103
  674. package/src/drag-controls.ts +3 -94
  675. package/src/drag-defaults.ts +3 -0
  676. package/src/drag-track.ts +3 -955
  677. package/src/drag-transition.ts +3 -43
  678. package/src/element-setup.ts +3 -0
  679. package/src/element.tsx +53 -16
  680. package/src/feature.ts +3 -359
  681. package/src/features/all.ts +3 -18
  682. package/src/features/colors.ts +3 -36
  683. package/src/features/dom-animation.ts +3 -15
  684. package/src/features/dom-max.ts +3 -11
  685. package/src/features/drag.ts +3 -30
  686. package/src/features/focus.ts +3 -17
  687. package/src/features/hover.ts +3 -17
  688. package/src/features/in-view.ts +3 -17
  689. package/src/features/input.ts +3 -34
  690. package/src/features/keys.ts +3 -89
  691. package/src/features/layout.ts +3 -54
  692. package/src/features/pan.ts +3 -17
  693. package/src/features/press.ts +3 -17
  694. package/src/features/scroll.ts +3 -21
  695. package/src/gesture-features.ts +3 -35
  696. package/src/gesture-info.ts +3 -81
  697. package/src/imperative.ts +3 -894
  698. package/src/index.tsx +6 -1
  699. package/src/instance-features.ts +88 -0
  700. package/src/instant.ts +3 -90
  701. package/src/layout-group.ts +3 -32
  702. package/src/layout-member.ts +3 -319
  703. package/src/layout-projection.tsx +10 -1
  704. package/src/layout.tsx +7 -6
  705. package/src/lazy-batch-gestures.ts +3 -3
  706. package/src/live-scroll.tsx +30 -22
  707. package/src/live-style.ts +3 -450
  708. package/src/live-value.tsx +12 -2
  709. package/src/member-hold.ts +3 -222
  710. package/src/messages.ts +27 -0
  711. package/src/owner-scope.ts +3 -31
  712. package/src/presence-controller.ts +3 -1616
  713. package/src/presence-record.ts +8 -192
  714. package/src/presence.tsx +3 -1
  715. package/src/press.ts +3 -40
  716. package/src/provider.tsx +72 -7
  717. package/src/reactivity.ts +3 -23
  718. package/src/reorder.tsx +5 -4
  719. package/src/retarget-legs.ts +3 -1049
  720. package/src/runtime.ts +62 -43
  721. package/src/scroll-values.ts +53 -0
  722. package/src/server-interpolators.ts +3 -33
  723. package/src/spans-check.ts +25 -0
  724. package/src/spine.ts +3 -3508
  725. package/src/timelines.ts +3 -0
  726. package/src/unstable/v2/batch-reorder-group.tsx +42 -18
  727. package/src/unstable/v2/create-animate.tsx +3 -1
  728. package/src/unstable/v2/create-batch.tsx +2 -2
  729. package/src/unstable/v2/create-wardic.tsx +46 -0
  730. package/src/unstable/v2/element.tsx +86 -24
  731. package/src/unstable/v2/index.tsx +5 -0
  732. package/src/unstable/v2/lifecycle.ts +35 -0
  733. package/src/unstable/v2/live-scroll.tsx +22 -11
  734. package/src/unstable/v2/live-value.tsx +10 -0
  735. package/src/unstable/v2/presence.tsx +3 -1
  736. package/src/unstable/v2/provider.tsx +75 -9
  737. package/src/unstable/v2/reorder.tsx +9 -4
  738. package/src/unstable/v2/w.tsx +50 -13
  739. package/src/unstable/v2/ward.tsx +61 -51
  740. package/src/unstable/v2/wardic-instance.ts +50 -0
  741. package/src/variant-target.ts +3 -240
  742. package/src/variant-tree.ts +3 -638
  743. package/src/w.tsx +34 -16
  744. package/src/ward-keys.ts +38 -17
  745. package/src/wardic-config-value.ts +3 -150
  746. package/src/wardic-instance.ts +49 -0
  747. package/dist/browser/batch-handoff.js +0 -72
  748. package/dist/browser/batch-handoff.js.map +0 -1
  749. package/dist/browser/frame-time.js +0 -40
  750. package/dist/browser/frame-time.js.map +0 -1
  751. package/dist/server/batch-handoff.js +0 -72
  752. package/dist/server/batch-handoff.js.map +0 -1
  753. package/dist/server/frame-time.js +0 -40
  754. package/dist/server/frame-time.js.map +0 -1
  755. package/dist/solid/batch-handoff.d.ts +0 -25
  756. package/dist/solid/batch-handoff.d.ts.map +0 -1
  757. package/dist/solid/batch-handoff.js +0 -75
  758. package/dist/solid/batch-handoff.js.map +0 -1
  759. package/dist/solid/frame-time.d.ts +0 -21
  760. package/dist/solid/frame-time.d.ts.map +0 -1
  761. package/dist/solid/frame-time.js +0 -41
  762. package/dist/solid/frame-time.js.map +0 -1
  763. package/src/batch-handoff.ts +0 -87
  764. package/src/frame-time.ts +0 -45
package/src/spine.ts CHANGED
@@ -1,3508 +1,3 @@
1
- /**
2
- * The motion spine's Retarget (ADR-0005), Solid-free (#209): what an element does from its mount on
3
- * when its target changes, for the Solid 1 binding (`create-ward.tsx`'s `runSpine`) and the Solid 2
4
- * one (`unstable/v2/ward.tsx`) alike. A binding mounts the element, resolves its Override stack
5
- * reactively ({@link resolutionOf}), and calls {@link ElementSpine.retarget} on each change, read
6
- * where its Solid doesn't track; everything a Retarget does is here:
7
- *
8
- * end the running legs -> carry the keys no entry sets back to their Base values (ADR-0022) ->
9
- * start each key from its Snapshot (ADR-0024) -> take over an Appear animation (ADR-0044) ->
10
- * build the legs (`retarget-legs.ts`) and run each into the gate -> `gate.write`.
11
- *
12
- * With it, the helpers both bindings' Wards share: the Starting values, the Base values' start links,
13
- * the sink wrappers, and what a server render reads.
14
- *
15
- * @module
16
- */
17
- import * as BaseValue from "@wardic/core/BaseValue"
18
- import type * as DefaultTransition from "@wardic/core/DefaultTransition"
19
- import * as Frame from "@wardic/core/Frame"
20
- import type * as FrameLoop from "@wardic/core/FrameLoop"
21
- import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
22
- import * as Machine from "@wardic/core/Machine"
23
- import * as Override from "@wardic/core/Override"
24
- import * as Playback from "@wardic/core/Playback"
25
- import * as Projection from "@wardic/core/Projection"
26
- import type * as ReducedMotion from "@wardic/core/ReducedMotion"
27
- import type * as Renderer from "@wardic/core/Renderer"
28
- import * as Supersede from "@wardic/core/Supersede"
29
- import * as Values from "@wardic/core/Values"
30
- import * as Appear from "@wardic/dom/Appear"
31
- import * as DomRenderer from "@wardic/dom/DomRenderer"
32
- import type * as FlushGate from "@wardic/dom/FlushGate"
33
- import * as OwnValues from "@wardic/dom/OwnValues"
34
- import * as Report from "@wardic/dom/Report"
35
- import * as MeasuredPair from "@wardic/dom/MeasuredPair"
36
- import * as Style from "@wardic/dom/Style"
37
- import * as Variables from "@wardic/dom/Variables"
38
- import * as Arr from "effect/Array"
39
- import * as Bool from "effect/Boolean"
40
- import * as Cause from "effect/Cause"
41
- import * as Effect from "effect/Effect"
42
- import * as Equivalence from "effect/Equivalence"
43
- import * as Exit from "effect/Exit"
44
- import * as Fiber from "effect/Fiber"
45
- import { constFalse, constUndefined, constVoid, identity } from "effect/Function"
46
- import * as Iter from "effect/Iterable"
47
- import * as Match from "effect/Match"
48
- import * as Option from "effect/Option"
49
- import * as Predicate from "effect/Predicate"
50
- import * as Rec from "effect/Record"
51
- import * as AtomRegistry from "effect/reactivity/AtomRegistry"
52
- import * as UndefinedOr from "effect/UndefinedOr"
53
- import { enterServer, type Handoff, keyOf, type MountAnimation, repeatsForever, type ServerAppear, skippedField, startAtOf } from "./appear.ts"
54
- import type {
55
- WardConfig,
56
- WardicAnimationDefinition,
57
- WardicTransition,
58
- WardicVariant,
59
- WardicVariantLabels,
60
- WardicVariants,
61
- WardicVariantTransition,
62
- } from "./config.ts"
63
- import { type ControlsChange, join, leave } from "./animation-controls.ts"
64
- import { clockNowOf, frameNow, MAX_VELOCITY_DELTA, NOMINAL_FRAME } from "./frame-time.ts"
65
- import { type LiveStyle, serverRegistryOf, turnsWillChangeOn, valuesOf } from "./live-style.ts"
66
- import { type ExitGroup, type PresenceContextValue, type PresenceExit, presenceMade, type PresenceRecord, type PresenceSeed, type PresenceTree } from "./presence-record.ts"
67
- import type { DragTrack } from "./drag-track.ts"
68
- import type { Accessor, Reactivity } from "./reactivity.ts"
69
- import { delayedBy, type Follows, hasManyStops, keyframesFrom, type Leg, legsOf, mapMachine, type MeasuredPairs, startingAt, type StopsByKey, transitionForKey, type Velocities, withPathAxes } from "./retarget-legs.ts"
70
- import { type MemberHold, memberHoldsNow } from "./member-hold.ts"
71
- import type { WardicRuntime, WardicServices } from "./runtime.ts"
72
- import {
73
- changesContext,
74
- hasOwnVariants,
75
- GESTURE_LAYERS,
76
- type GestureLayer,
77
- type GestureNames,
78
- type NameOrchestration,
79
- activeNamesOf,
80
- type GestureHandDown,
81
- gesturesOn,
82
- type GestureStates,
83
- handDownFrom,
84
- handDownOf,
85
- NO_GESTURE_STATES,
86
- NO_HAND_DOWN,
87
- isVariantChild,
88
- nameOf,
89
- NO_GESTURE_NAMES,
90
- ownOrInherited,
91
- sameGestureNames,
92
- type ServerVariantNode,
93
- startingValuesOf,
94
- startsAtAnimate,
95
- startsQuiet,
96
- type WardicVariantContextValue,
97
- } from "./variant-tree.ts"
98
- import { type Entry, type Keyframes, mergedOf, type NamedTarget, NO_VARIANT_STATE, resolveTarget, resolveTargets, sameLabels, type Target, transitionOfTarget, type VariantState } from "./variant-target.ts"
99
-
100
- export { NO_VARIANT_STATE, resolveTarget, type Target, transitionOfTarget, type VariantState } from "./variant-target.ts"
101
-
102
- /** What an element's exit is resolved from (#277): its last config, kept current while it's alive. */
103
- export interface ExitConfig {
104
- readonly exit: WardicVariant | WardicVariantLabels | undefined
105
- readonly variants: WardicVariants | undefined
106
- readonly custom: unknown
107
- /** Its `transition`, or the one it inherits. */
108
- readonly transition: WardicTransition | undefined
109
- }
110
-
111
- /** No exit: an element outside a presence never resolves one. */
112
- export const NO_EXIT_CONFIG: ExitConfig = { exit: undefined, variants: undefined, custom: undefined, transition: undefined }
113
-
114
- /** A record's place in the variant tree (#290), from its config at setup. */
115
- export const presenceTreeOf = (c: WardConfig): PresenceTree => ({
116
- joins: isVariantChild(c),
117
- provides: changesContext(c),
118
- twin: Predicate.isNotUndefined(c.layoutId),
119
- })
120
-
121
- /**
122
- * An element's ref that tells its presence it was made (#286, ADR-0048): its `key`, read once, and
123
- * whether it's a twin. With no presence, `set` itself: nothing is made per element.
124
- */
125
- export const madeWith = <E extends Element>(presence: PresenceContextValue | undefined, set: (el: E) => void, c: WardConfig): ((el: E) => void) => {
126
- if (Predicate.isUndefined(presence)) return set
127
- const key = c.key
128
- const twin = Predicate.isNotUndefined(c.layoutId)
129
- return (el) => {
130
- presenceMade(presence, el, key, twin)
131
- set(el)
132
- }
133
- }
134
-
135
- /** An element's {@link ExitConfig} from its config now. */
136
- export const exitConfigOf = (c: WardConfig, parent: WardicVariantContextValue | undefined): ExitConfig => ({
137
- exit: c.exit,
138
- variants: c.variants,
139
- custom: c.custom,
140
- transition: ownOrInherited(c.transition, parent),
141
- })
142
-
143
- /** An exit resolved (#277): its values, and the transition it runs on. */
144
- export type ExitTarget = PresenceExit
145
-
146
- /**
147
- * Resolve an element's exit as it leaves (#277): with its `<AnimatePresence custom>` when that's
148
- * given (Motion's: the leaving element's own props can't change any more), else its own `custom`; on
149
- * its own transition, else the element's.
150
- */
151
- export const exitTargetOf = (config: ExitConfig, presenceCustom: unknown, state: VariantState, inherited: WardicVariantLabels | undefined): ExitTarget => {
152
- const custom = UndefinedOr.match(presenceCustom, { onUndefined: () => config.custom, onDefined: identity })
153
- // Its own `exit` wins; a Variant child with none exits on the name its provider hands down (#290).
154
- const entry: Entry = UndefinedOr.match(config.exit, { onDefined: identity, onUndefined: (): Entry => inherited })
155
- const name = UndefinedOr.match(nameOf(config.exit), { onDefined: identity, onUndefined: () => inherited })
156
- if (Arr.isArray(entry)) {
157
- // A list (#297): merged, and each name's own keys on its own transition.
158
- const targets = resolveTargets(entry, config.variants, custom, state)
159
- const merged = mergedOf(targets)
160
- return {
161
- values: merged.values,
162
- transition: transitionOfTarget(merged.transition, config.transition),
163
- name,
164
- groups: exitGroupsOf(targets, config.transition),
165
- keyframes: merged.keyframes,
166
- }
167
- }
168
- const target = resolveTarget(entry, config.variants, custom, state)
169
- return { values: target.values, transition: transitionOfTarget(target.transition, config.transition), name, keyframes: target.keyframes }
170
- }
171
-
172
- /** A list's exit groups (#297): each name, with the keys it's the last to set, on its own transition else `element`. */
173
- const exitGroupsOf = (targets: ReadonlyArray<NamedTarget>, element: WardicTransition | undefined): ReadonlyArray<ExitGroup> =>
174
- Arr.map(targets, (target, i) => ({
175
- name: target.name as string,
176
- values: Rec.filter(target.values, (_, key) => Bool.not(Arr.some(Arr.drop(targets, i + 1), (later) => Object.hasOwn(later.values, key)))),
177
- transition: transitionOfTarget(target.transition, element),
178
- }))
179
-
180
- /** A config given as a value or as an accessor, as an accessor. A config is always an object, so a function is the accessor. */
181
- export const accessorOf = <A extends object>(config: A | Accessor<A>): Accessor<A> =>
182
- Bool.match(Predicate.isFunction(config), { onTrue: () => config as Accessor<A>, onFalse: () => () => config as A })
183
-
184
- /**
185
- * `transition` with a stagger delay folded into its own and its entries' (ADR-0007, #301), reused
186
- * while its fields are (#66).
187
- */
188
- const staggeredOf = (
189
- transition: WardicTransition | undefined,
190
- extra: number,
191
- reuse: (transition: WardicTransition) => WardicTransition,
192
- ): WardicTransition | undefined => UndefinedOr.map(delayedBy(transition, extra), reuse)
193
-
194
- /**
195
- * A Retarget's keys by the entry that drives each (#291), when an active entry (the base's included)
196
- * has its own transition: the highest active entry that sets it, and the base for a key none sets (a
197
- * return). `undefined` when none has: one transition for every key.
198
- */
199
- const keysByLayerOf = (
200
- t: Values.Values,
201
- layers: ReadonlyArray<OverrideEntry>,
202
- extraDelay: ((name: string | undefined) => number) | undefined,
203
- extra: number,
204
- listed: boolean,
205
- shut: ReadonlyArray<boolean> | undefined,
206
- ): ReadonlyArray<ReadonlySet<string>> | undefined => {
207
- // Per Retarget (#460): statements.
208
- if (!Arr.some(layers, hasOwnTransition) && !delaysDiffer(layers, extraDelay, extra) && !anyShutOf(shut)) return undefined
209
- // A list's returns in a group of their own, after its entries' (#297).
210
- let returnsAt = 0
211
- if (listed) returnsAt = layers.length
212
- const groups = Arr.makeBy(Math.max(layers.length, returnsAt + 1), () => new Set<string>())
213
- Arr.forEach(Rec.keys(t), (key) => {
214
- // A key only a Transition end sets (#428) is in its entry's group too, as the entry's own.
215
- const at = Option.getOrElse(Arr.findLastIndex(layers, (layer) => Bool.and(layer.active, Bool.or(Object.hasOwn(layer.values, key), Object.hasOwn(layer.ends, key)))), () => returnsAt)
216
- UndefinedOr.map(groups[at], (group) => group.add(key))
217
- })
218
- return groups
219
- }
220
-
221
- /**
222
- * The transition `key` animates on in a Retarget: its group's (#277, #297), else the Retarget's one,
223
- * with no stagger (#448 reads its fields, not its delay).
224
- */
225
- const keyTransitionOf = (
226
- resolution: Resolution,
227
- groups: ReadonlyArray<ReadonlySet<string>> | undefined,
228
- key: string,
229
- transition: WardicTransition | undefined,
230
- element: WardicTransition | undefined,
231
- ): WardicTransition | undefined => {
232
- if (Predicate.isUndefined(groups)) return transition
233
- return groupTransitionOf(resolution, groups, Option.getOrElse(Arr.findFirstIndex(groups, (group) => group.has(key)), () => -1), transition, element, undefined, identity)
234
- }
235
-
236
- /** Whether `given` gives `key` a velocity (#448, Motion's `valueTransition.velocity`): it kicks the key, so it animates though at its target. */
237
- const givesVelocity = (given: WardicTransition | undefined, key: string): boolean => {
238
- const own = transitionForKey(given, key) as { readonly velocity?: unknown } | undefined
239
- if (Predicate.isUndefined(own)) return false
240
- return Bool.and(Predicate.isNumber(own.velocity), own.velocity !== 0)
241
- }
242
-
243
- /** A key's velocity in the Snapshot, 0 with none (#448). Per key, per Retarget: a guard. */
244
- const velocityOf = (snapshot: { readonly velocities: Readonly<Record<string, number>> }, key: string): number => {
245
- const velocity = snapshot.velocities[key]
246
- if (Predicate.isUndefined(velocity)) return 0
247
- return velocity
248
- }
249
-
250
- /** `t`'s keys in the `i`th group, or all of them when there are no groups. */
251
- const pickKeys = (t: Values.Values, groups: ReadonlyArray<ReadonlySet<string>> | undefined, i: number): Values.Values => {
252
- if (Predicate.isUndefined(groups)) return t
253
- const group = groups[i]
254
- if (Predicate.isUndefined(group)) return {}
255
- return Rec.filter(t, (_, key) => group.has(key))
256
- }
257
-
258
- /** A transition's `delay`, 0 without one. */
259
- export const delayOf = (transition: WardicTransition | undefined): number =>
260
- UndefinedOr.match(transition, { onUndefined: () => 0, onDefined: ({ delay = 0 }) => delay })
261
-
262
- /** No keys: what a drag moves on a projected element, or one with no drag. */
263
- const NO_KEYS: ReadonlyArray<string> = []
264
-
265
- /** The keys a drag of `axis` moves directly. Built once, at module load. */
266
- const dragMovesOf: (axis: boolean | "x" | "y") => ReadonlyArray<string> = Match.type<boolean | "x" | "y">().pipe(
267
- Match.when("x", (): ReadonlyArray<string> => ["x"]),
268
- Match.when("y", (): ReadonlyArray<string> => ["y"]),
269
- Match.orElse((): ReadonlyArray<string> => ["x", "y"]),
270
- )
271
-
272
- /** Whether a start link's value takes its target's shape: both numbers, or both strings. */
273
- const isSameKind = (value: number | string, like: number | string): boolean => Predicate.isNumber(value) === Predicate.isNumber(like)
274
-
275
- /** The keys a drag direct-sets (ADR-0004). */
276
- const TRANSLATE_KEYS: ReadonlySet<string> = new Set(["x", "y", "translateX", "translateY"])
277
- const TRANSLATE_KEY_LIST: ReadonlyArray<string> = Arr.fromIterable(TRANSLATE_KEYS)
278
-
279
- /** Whether a value map has any key. */
280
- const hasKeys: Predicate.Predicate<Values.Values> = Predicate.not(Rec.isEmptyRecord)
281
-
282
- /**
283
- * Whether two transitions have the same keys, each holding the same value (`===`), an entry the
284
- * same fields (#301: a stagger makes each entry anew).
285
- */
286
- const sameFields = (a: object, b: object): boolean => {
287
- const ra = a as Readonly<Record<string, unknown>>
288
- const rb = b as Readonly<Record<string, unknown>>
289
- const keys = Rec.keys(ra)
290
- return Bool.and(keys.length === Rec.keys(rb).length, Arr.every(keys, (key) => Bool.and(key in rb, sameField(ra[key], rb[key]))))
291
- }
292
-
293
- /** Whether two fields are the same: `===`, or two entries with the same fields (#301). */
294
- const sameField = (a: unknown, b: unknown): boolean => {
295
- if (a === b) return true
296
- if (Bool.and(Predicate.isObject(a), Predicate.isObject(b))) return sameFields(a as object, b as object)
297
- return false
298
- }
299
-
300
- /** The Override stack resolved: a Retarget's input. */
301
- export interface Resolution {
302
- /** Each key's value from the highest active entry. */
303
- readonly resolved: Values.Values
304
- /** The base entry, the first link of a key's Base value (ADR-0022). */
305
- readonly base: Values.Values
306
- /** Whether a drag holds the translate keys (ADR-0004's strip). */
307
- readonly dragging: boolean
308
- /** The variant name (or list, #297) the base entry resolved: its own `animate`'s, else the one it inherits; none for a values map. */
309
- readonly variant: WardicVariantLabels | undefined
310
- /** The entries it was resolved with (#257): a landing's gestures are the ones its Retarget started with. */
311
- readonly active: Active
312
- /** The base target's own transition (#277): the keys the base entry drives animate on it. */
313
- readonly transition: WardicVariantTransition | undefined
314
- /**
315
- * The Override stack's entries (#291): the base, then each gesture's, lowest first. A Retarget runs
316
- * each key on the own transition of the highest active entry that sets it.
317
- */
318
- readonly layers: ReadonlyArray<OverrideEntry>
319
- /** The names its active gesture layers resolved (#291): its own `while*` names, else those it took. */
320
- readonly names: GestureNames
321
- /**
322
- * Which gesture layers are on and set values or a Transition end (#470); a named one is in `names`.
323
- * One turning on or off is a new target, whatever it resolves, as a Motion type turning active
324
- * animates (`animation-state.ts`).
325
- */
326
- readonly layersOn: GestureStates
327
- /** Its entries' **Transition ends** (#428), when any active one has one. */
328
- readonly ends: Ends | undefined
329
- /** Each key's **Keyframes**, as the entry that drives it gives them (#429), when any active entry has some. */
330
- readonly keyframes: KeyframesNow | undefined
331
- /**
332
- * The **Controls change** in effect (#433): its own controls' latest, else the one its provider is
333
- * in, for a Variant child. A new one is a Retarget, whatever it resolves to.
334
- */
335
- readonly change: ControlsChange | undefined
336
- }
337
-
338
- /**
339
- * A key's **Keyframes** as a Retarget resolves them (#429): their stops, and the entry that drives the
340
- * key, by its place in the Override stack and the variant name it resolved. Two are the same when all
341
- * three are, Motion's rule for when Keyframes play again (`animation-state.ts`): an equal list, stop by
342
- * stop, that a re-render makes runs on, where new stops, another entry driving the key (a hover over it
343
- * ending) or a new name for its entry (`variantDidChange`) plays them again from their first stop.
344
- */
345
- export interface KeyframesAt {
346
- readonly stops: Style.Stops
347
- readonly layer: number
348
- readonly name: string | undefined
349
- }
350
-
351
- /** Each key's {@link KeyframesAt}. */
352
- export type KeyframesNow = Readonly<Record<string, KeyframesAt>>
353
-
354
- /**
355
- * A resolution's **Transition ends** (#428): each key only an entry's Transition end sets, with the
356
- * entry that drives it (the highest active one that sets it, as for any key), and each entry's end
357
- * values for the keys it drives, a key it also animates among them.
358
- */
359
- export interface Ends {
360
- readonly endOnly: ReadonlyMap<string, number>
361
- readonly byLayer: ReadonlyArray<Values.Values | undefined>
362
- }
363
-
364
- /**
365
- * One entry of the Override stack (#291): whether it's on, its values, its target's own transition,
366
- * and the variant name it resolved (#297), `undefined` for a values map. A list of names is an entry
367
- * a name, in order.
368
- */
369
- export interface OverrideEntry {
370
- readonly active: boolean
371
- readonly values: Values.Values
372
- readonly transition: WardicVariantTransition | undefined
373
- readonly name: string | undefined
374
- /** Its target's **Transition end** (#428): its keys are the entry's, set once its animated keys land. */
375
- readonly ends: Values.Values
376
- /** Its target's **Keyframes** (#429): each such key's stops, its value in `values` their last. */
377
- readonly keyframes: Keyframes | undefined
378
- }
379
-
380
- /** A gesture layer that's off: nothing is resolved for it. */
381
- const OFF: OverrideEntry = { active: false, values: {}, transition: undefined, name: undefined, ends: {}, keyframes: undefined }
382
-
383
- /**
384
- * A gesture layer (#291), while it's on (its own, or its provider's): its own `while*` (a target, or
385
- * a variant name), else the label its provider hands down. Off, or with neither, nothing is resolved.
386
- * Whether it set values or a Transition end (#470).
387
- */
388
- const gestureLayersInto = (
389
- layers: Array<OverrideEntry>,
390
- own: Entry,
391
- on: boolean,
392
- label: WardicVariantLabels | undefined,
393
- variants: WardicVariants | undefined,
394
- custom: unknown,
395
- state: VariantState,
396
- ): boolean => {
397
- if (Bool.not(on)) {
398
- layers.push(OFF)
399
- return false
400
- }
401
- const entry = UndefinedOr.match(own, { onDefined: identity, onUndefined: (): Entry => label })
402
- if (Predicate.isUndefined(entry)) {
403
- layers.push(OFF)
404
- return false
405
- }
406
- // A list is an entry a name, in order (#297): the last name that sets a key drives it.
407
- if (Arr.isArray(entry)) {
408
- let sets = false
409
- Arr.forEach(resolveTargets(entry, variants, custom, state), (target) => {
410
- const layer = namedLayerOf(target)
411
- layers.push(layer)
412
- if (setsValues(layer)) sets = true
413
- })
414
- return sets
415
- }
416
- const layer = layerOf(resolveTarget(entry, variants, custom, state), labelOrUndefined(entry))
417
- layers.push(layer)
418
- return setsValues(layer)
419
- }
420
-
421
- /**
422
- * Whether a gesture layer sets values or a Transition end (#470). A values map with none sets
423
- * nothing; a name that resolves none is told by its name (`names`), as Motion animates it.
424
- */
425
- const setsValues = (layer: OverrideEntry): boolean => {
426
- if (hasKeys(layer.values)) return true
427
- return hasKeys(layer.ends)
428
- }
429
-
430
- /** A single entry's name: itself, if a name; `undefined` for a values map. */
431
- const labelOrUndefined = (entry: Entry): string | undefined => Bool.match(Predicate.isString(entry), { onTrue: () => entry as string, onFalse: constUndefined })
432
-
433
- /** Each gesture on: the element's own, or its provider's too when it has one handing any down. */
434
- const gesturesOnOf = (active: Active, above: GestureHandDown): GestureStates => {
435
- if (above === NO_HAND_DOWN) return active
436
- return gesturesOn(active, above.on)
437
- }
438
-
439
- /**
440
- * The name each gesture layer resolves while it's on (#291): its own `while*`, if a name, else the
441
- * label it took. With none on, the shared empty one: nothing made.
442
- */
443
- const activeNamesFor = (c: WardConfig, on: GestureStates, labels: GestureNames): GestureNames => {
444
- if (Bool.not(anyOn(on))) return NO_GESTURE_NAMES
445
- return activeNamesOf(handDownOf(c, on, { on: NO_GESTURE_STATES, names: labels }))
446
- }
447
-
448
- /** Whether any gesture is on: per Retarget, so no closure. */
449
- const anyOn = (on: GestureStates): boolean => on.inView || on.focused || on.hovered || on.pressed || on.dragged
450
-
451
- /**
452
- * Whether an active entry's name delays its keys otherwise than the first entry's (#297): a Variant
453
- * child's names each take their own stagger slot. Never for an element that joins none, nor for one
454
- * entry.
455
- */
456
- const delaysDiffer = (layers: ReadonlyArray<OverrideEntry>, extraDelay: ((name: string | undefined) => number) | undefined, extra: number): boolean => {
457
- if (Bool.or(Predicate.isUndefined(extraDelay), layers.length < 2)) return false
458
- return Arr.some(layers, (layer) => Bool.and(layer.active, extraOf(extraDelay, layer) !== extra))
459
- }
460
-
461
- /** An entry's stagger delay (ADR-0007, #297): its name's, for a Variant child; 0 for any other element. */
462
- const extraOf = (extraDelay: ((name: string | undefined) => number) | undefined, layer: OverrideEntry | undefined): number => {
463
- if (Predicate.isUndefined(extraDelay)) return 0
464
- if (Predicate.isUndefined(layer)) return extraDelay(undefined)
465
- return extraDelay(layer.name)
466
- }
467
-
468
- /**
469
- * The transition a key group runs on (#291, #297): unsplit, the base's (`transition`, its delay
470
- * folded in); split, its entry's own, else the element's, at its name's delay. A list's first
471
- * group carries its returns too, which run on the element's transition, as a list's base has no one
472
- * transition of its own.
473
- */
474
- const groupTransitionOf = (
475
- resolution: Resolution,
476
- groups: ReadonlyArray<ReadonlySet<string>> | undefined,
477
- i: number,
478
- transition: WardicTransition | undefined,
479
- element: WardicTransition | undefined,
480
- extraDelay: ((name: string | undefined) => number) | undefined,
481
- reuse: (transition: WardicTransition) => WardicTransition,
482
- ): WardicTransition | undefined => {
483
- if (Predicate.isUndefined(groups)) return transition
484
- if (Bool.and(i === 0, Bool.not(Arr.isArray(resolution.variant)))) return transition
485
- const layer = resolution.layers[i]
486
- // A list's returns: the element's, at its whole orchestration's delay.
487
- if (Predicate.isUndefined(layer)) return staggeredOf(element, extraOf(extraDelay, undefined), reuse)
488
- return staggeredOf(transitionOfTarget(layer.transition, element), extraOf(extraDelay, layer), reuse)
489
- }
490
-
491
- /** No names. */
492
- const NO_NAMES: ReadonlyArray<string> = []
493
-
494
- /** No legs. */
495
- const NO_LEGS: ReadonlyArray<Leg> = []
496
-
497
- /**
498
- * Where a Retarget's legs land (#257, #325): what each running leg's frames and end are told to.
499
- * The last Retarget's, which every running leg counts toward, the ones it carried included.
500
- */
501
- interface Landing {
502
- /** A leg drew a frame: its last, when `done`. */
503
- readonly report: (done: boolean) => void
504
- /** A leg settled. */
505
- readonly settled: () => void
506
- /** A leg failed (#257 item 4). */
507
- readonly failed: (cause: Cause.Cause<unknown>) => void
508
- }
509
-
510
- /**
511
- * A gated Retarget's landing (ADR-0007 `when`, #325): the legs it carries report the element
512
- * unsettled, as it still owes an animation, and land nothing; the Retarget once the gate opens
513
- * counts them.
514
- */
515
- const gatedLandingOf = (onFrame: ((done: boolean) => void) | undefined): Landing => ({
516
- report: () => {
517
- if (Predicate.isNotUndefined(onFrame)) onFrame(false)
518
- },
519
- settled: constVoid,
520
- failed: constVoid,
521
- })
522
-
523
- /**
524
- * A running leg (#325): the keys it draws, each with the target its Retarget resolved, and the
525
- * landing its frames and end count toward. It's its machines' run options, with its own token
526
- * (#200): a later Retarget that resolves a key to the same target leaves the leg that key, every
527
- * other key is given up, and a leg left with none is ended.
528
- */
529
- interface Running extends Machine.RunOptions {
530
- /** Each key it animates, with the target its Retarget gave it. */
531
- readonly targets: Values.Values
532
- /** The resolution of the Retarget that started it: a `when` gate holds that change's legs. */
533
- readonly resolution: Resolution
534
- /** How many of its keys it still draws. */
535
- count: number
536
- /** A frame's values for the keys it still draws: the frame's own while it draws all of them. */
537
- values: (value: Values.Values) => Values.Values
538
- /** It drew its last frame: its keys landed. */
539
- done: boolean
540
- /** It gave up a key in this Retarget: what it still draws is worked out at the Retarget's end. */
541
- losing: boolean
542
- fiber: Fiber.Fiber<void> | undefined
543
- /** The landing it counts toward: its Retarget's, then the one of each Retarget that carried it. */
544
- landing: Landing
545
- /** A list's names its end is told to (#297), for the Retarget it counts toward. */
546
- names: ((end: unknown) => void) | undefined
547
- /** Its kind (#464): a Blend leg's keys' velocities are its frames', a Snap's none, the rest write their own. */
548
- readonly kind: Leg["_tag"]
549
- /** The frames it has drawn (#464). */
550
- frames: number
551
- /** When it drew its last frame, on {@link frameNow}'s clock; -Infinity before its first (#464). */
552
- lastAt: number
553
- /** A Blend leg's last frame's values, and the ones before them (the Snapshot's, before its first) and when (#464). */
554
- last: Values.Values | undefined
555
- before: Values.Values | undefined
556
- beforeAt: number
557
- /**
558
- * A Numbers leg's last Frame (#663): its keys' velocities are read from it when one is asked for, as
559
- * a Blend leg's are from its frames, by index from a spring's. None before its first frame.
560
- */
561
- physics: Frame.MultiPhysics | undefined
562
- }
563
-
564
- /** No running legs. */
565
- const NO_RUNNING: ReadonlyArray<Running> = []
566
-
567
- /**
568
- * An entry's Transition end waiting for its keys to land (#428, #508): no fiber of its own. Its `running`
569
- * holds the keys only it sets, counts toward its landing and is given up as any leg's; the landing of
570
- * its keys' last leg makes it due, and it's written at the next flush.
571
- */
572
- interface PendingEnd {
573
- readonly running: Running
574
- /** The keys its entry animates, each held by the leg drawing it. */
575
- readonly animated: ReadonlyArray<string>
576
- /** Its Transition end, the keys it also animates among them. */
577
- readonly writes: Values.Values
578
- /**
579
- * An end that owns no key, its values all keys its entry animates: the leg drawing each of
580
- * `animated` as it was made. Nothing gives such an end up, so a key's leg given up or replaced
581
- * before it lands, the target interrupted, drops it (ADR-0057 Q1). Undefined for one that owns keys,
582
- * which an interrupt gives up.
583
- */
584
- readonly legs: ReadonlyArray<Running | undefined> | undefined
585
- state: "waiting" | "due" | "written" | "dropped"
586
- }
587
-
588
- /** An element's waiting Transition ends (#508). */
589
- interface WaitingEnds {
590
- /** An entry's end, waiting for its keys, or due already when they've landed. */
591
- readonly add: (end: PendingEnd) => void
592
- /** A leg landed: each end whose keys now all have is due, written at the next flush. */
593
- readonly land: () => void
594
- /** The end `running` is, dropped, whether it waits or is due: given up, stopped or ended. */
595
- readonly drop: (running: Running) => void
596
- /** The element is gone: none is written. */
597
- readonly dispose: () => void
598
- }
599
-
600
- /**
601
- * The waiting Transition ends of element `id` (#508): made at its first end, so an element with none,
602
- * nearly every one, pays nothing for them. `owners` holds the leg drawing each key.
603
- */
604
- const waitingEndsOf = (owners: Owners, snapshot: Snapshot, gate: FlushGate.Shape, id: string, recordFrame: (value: Values.Values) => void): WaitingEnds => {
605
- const pending: Array<PendingEnd> = []
606
- let disposed = false
607
- /** Whether `key`'s leg has landed: it drew its last frame, or none draws it. */
608
- const keyLanded = (key: string): boolean => ownerLanded(owners.get(key))
609
- /** `end` off the list. */
610
- const remove = (end: PendingEnd): void => {
611
- const at = pending.indexOf(end)
612
- if (at >= 0) pending.splice(at, 1)
613
- }
614
- /**
615
- * An end written, at the flush after its keys landed: the frame its leg's write would have drawn in,
616
- * and Motion's (`frame.update` once its animations resolve). It counts toward its landing as that leg
617
- * did, so the landing's settle, told after the next flush, sees it (ADR-0057 Q4).
618
- */
619
- const write = (end: PendingEnd): void => {
620
- if (Bool.or(disposed, end.state !== "due")) return
621
- end.state = "written"
622
- remove(end)
623
- const running = end.running
624
- const value = running.values(end.writes)
625
- snapshot.values = { ...snapshot.values, ...value }
626
- gate.write(id, value)
627
- recordFrame(value)
628
- drew(running, true, snapshot.now())
629
- running.landing.settled()
630
- const tell = running.names
631
- if (Predicate.isNotUndefined(tell)) tell(undefined)
632
- }
633
- /** Whether a key-less end's target was interrupted: a leg it waits for given up or replaced before it landed. */
634
- const interrupted = (end: PendingEnd): boolean => {
635
- const legs = end.legs
636
- if (Predicate.isUndefined(legs)) return false
637
- return Arr.some(end.animated, (key, i) => {
638
- const leg = legs[i]
639
- if (Predicate.isUndefined(leg)) return false
640
- if (leg.done) return false
641
- return owners.get(key) !== leg
642
- })
643
- }
644
- /** An end due once every key it waits for has landed, written at the next flush; dropped when its target was interrupted. */
645
- const landOne = (end: PendingEnd): void => {
646
- if (end.state !== "waiting") return
647
- if (interrupted(end)) {
648
- end.state = "dropped"
649
- return
650
- }
651
- if (Bool.not(Arr.every(end.animated, keyLanded))) return
652
- end.state = "due"
653
- gate.afterFlush(() => write(end))
654
- }
655
- const dropped = (end: PendingEnd): boolean => end.state === "dropped"
656
- const land = (): void => {
657
- Arr.forEach(pending, landOne)
658
- if (Arr.some(pending, dropped)) {
659
- const kept = Arr.filter(pending, Predicate.not(dropped))
660
- pending.length = 0
661
- pending.push(...kept)
662
- }
663
- }
664
- return {
665
- add: (end) => {
666
- pending.push(end)
667
- land()
668
- },
669
- land,
670
- drop: (running) =>
671
- Option.match(Arr.findFirst(pending, (end) => end.running === running), {
672
- onNone: constVoid,
673
- onSome: (end) => {
674
- end.state = "dropped"
675
- remove(end)
676
- },
677
- }),
678
- dispose: () => {
679
- disposed = true
680
- pending.length = 0
681
- },
682
- }
683
- }
684
-
685
- /** A leg's last frame lands the Transition ends waiting on it (#508); an element with none has nothing to ask. */
686
- const landEndsOf = (waiting: WaitingEnds | undefined): void => {
687
- if (Predicate.isNotUndefined(waiting)) waiting.land()
688
- }
689
-
690
- /**
691
- * The resolution an **Imperative animation**'s legs run under (#433): none of the Override stack's,
692
- * so a Retarget that takes a key back never carries one as its own Keyframes or names.
693
- */
694
- const IMPERATIVE: Resolution = {
695
- resolved: {},
696
- base: {},
697
- dragging: false,
698
- variant: undefined,
699
- active: { inView: false, focused: false, hovered: false, pressed: false, dragged: false, dragging: false },
700
- transition: undefined,
701
- layers: [],
702
- names: NO_GESTURE_NAMES,
703
- layersOn: NO_GESTURE_STATES,
704
- ends: undefined,
705
- keyframes: undefined,
706
- change: undefined,
707
- }
708
-
709
- /** No values: what a spine's Retarget keys are before its first. */
710
- const NO_VALUES: Values.Values = {}
711
-
712
- /** Whether a key's Keyframes stops hold a Variable value (#55). Built once (#460). */
713
- const stopsHoldVariable = (stops: ReadonlyArray<number | string>): boolean => Arr.some(stops, Variables.isValue)
714
-
715
- /**
716
- * Whether a change's starts, targets or Keyframes stops hold a Variable value (#542): only then can
717
- * the element's Key rule, its Variable values (#55), take a pair, so only then is a leg's machine
718
- * built under it. It declines every pair with no `var()` at either end.
719
- */
720
- const holdsVariable = (from: Values.Values, to: Values.Values, stops: StopsByKey | undefined): boolean => {
721
- // Per Retarget (#460): statements, Effect's calls data-first.
722
- if (Rec.some(from, Variables.isValue)) return true
723
- if (Rec.some(to, Variables.isValue)) return true
724
- if (Predicate.isUndefined(stops)) return false
725
- return Rec.some(stops, stopsHoldVariable)
726
- }
727
-
728
- /** A Path's turn (#438, ADR-0065): the reserved key the dom transform adds onto `rotate`. */
729
- const PATH_ROTATION = "pathRotation"
730
-
731
- /** The turn back at 0, written once no leg draws it (#460). */
732
- const TURNED_BACK: Values.Values = { [PATH_ROTATION]: 0 }
733
-
734
- /**
735
- * Each key's Leg (#325): the one that draws it, or the last one that did, landed; `undefined` once
736
- * none does. A key's entry is cleared in place, never deleted: a Retarget that gives up and restarts
737
- * every key would otherwise leave the Map a hole a key each time, and rehash it.
738
- */
739
- type Owners = Map<string, Running | undefined>
740
-
741
- /** A leg over the keys of `to` (#325), counting toward `landing`: the spine gives it the keys. */
742
- const runningOf = (to: Values.Values, resolution: Resolution, landing: Landing, kind: Leg["_tag"]): Running => ({
743
- supersede: Supersede.make(),
744
- targets: to,
745
- resolution,
746
- count: 0,
747
- values: identity,
748
- done: false,
749
- losing: false,
750
- fiber: undefined,
751
- landing,
752
- names: undefined,
753
- kind,
754
- frames: 0,
755
- // Doubles from the start (#464): a field made an integer turns every leg's shape when its first double
756
- // comes, and a read of each leg made before goes the slow way (the bench's unmount, +6%).
757
- lastAt: Number.NEGATIVE_INFINITY,
758
- last: undefined,
759
- before: undefined,
760
- beforeAt: Number.NEGATIVE_INFINITY,
761
- physics: undefined,
762
- })
763
-
764
- /**
765
- * A Blend leg's velocity for `key` (#464, Motion's `getVelocity`): its last two frames' change over
766
- * their time apart, at most `MAX_VELOCITY_DELTA`; none for a string, nor for a Snap, a leg that landed
767
- * on its first frame (a `set`, a `duration: 0`).
768
- */
769
- const blendVelocityOf = (running: Running, key: string): number => {
770
- if (Bool.and(running.done, running.frames < 2)) return 0
771
- // Per key, per Retarget: guards, nothing made.
772
- const lastValues = running.last
773
- const beforeValues = running.before
774
- if (Predicate.isUndefined(lastValues)) return 0
775
- if (Predicate.isUndefined(beforeValues)) return 0
776
- const last = lastValues[key]
777
- const before = beforeValues[key]
778
- if (Bool.not(Predicate.isNumber(last))) return 0
779
- if (Bool.not(Predicate.isNumber(before))) return 0
780
- const apart = Math.min(running.lastAt - running.beforeAt, MAX_VELOCITY_DELTA)
781
- if (apart <= 0) return 0
782
- return (((last as number) - (before as number)) * 1000) / apart
783
- }
784
-
785
- /** A leg's frame drawn (#325) at `now`: its last lands the keys it draws. Per frame: plain calls. */
786
- const drew = (running: Running, done: boolean, now: number): void => {
787
- if (done) running.done = true
788
- running.frames++
789
- running.lastAt = now
790
- running.landing.report(done)
791
- }
792
-
793
- /**
794
- * A frame's values for `kept` alone (#325): a leg a later Retarget took keys from draws only the
795
- * rest. Built once, when it gives them up; each frame copies into the one object it returns.
796
- */
797
- const keepingOnly = <A,>(kept: ReadonlyArray<string>): ((value: Readonly<Record<string, A>>) => Readonly<Record<string, A>>) => {
798
- const out: Record<string, A> = {}
799
- let frame: Readonly<Record<string, A>> = out
800
- const copy = (key: string): void => {
801
- out[key] = frame[key] as A
802
- }
803
- return (value) => {
804
- frame = value
805
- Arr.forEach(kept, copy)
806
- return out
807
- }
808
- }
809
-
810
- /**
811
- * Where `axis` rests when `target` leaves it out (#574): a leg drawing it though its own Retarget
812
- * didn't resolve it, a Path's whose target left it out too (#438) or an Imperative animation's (#433,
813
- * whose legs resolve nothing), was taking it somewhere, and it rests there. `undefined` with none in
814
- * flight.
815
- */
816
- const restOf = (owners: Owners, target: Values.Values, axis: "x" | "y"): number | string | undefined => {
817
- if (Object.hasOwn(target, axis)) return undefined
818
- const owner = owners.get(axis)
819
- if (Predicate.isUndefined(owner)) return undefined
820
- if (owner.done) return undefined
821
- if (Object.hasOwn(owner.resolution.resolved, axis)) return undefined
822
- return owner.targets[axis]
823
- }
824
-
825
- /**
826
- * Where a Path's axes that `target` leaves out rest (#574), read before their legs give them up: a
827
- * new Path ends them there, so a toss caught mid-air curves back to its line. `undefined` for none:
828
- * every element's Retarget asks, nearly always with no Path in flight, so guards, nothing built.
829
- */
830
- const restsOf = (owners: Owners, target: Values.Values): Values.Values | undefined => {
831
- const x = restOf(owners, target, "x")
832
- const y = restOf(owners, target, "y")
833
- if (Bool.and(Predicate.isUndefined(x), Predicate.isUndefined(y))) return undefined
834
- if (Predicate.isUndefined(x)) return { y: UndefinedOr.getOrThrow(y) }
835
- if (Predicate.isUndefined(y)) return { x }
836
- return { x, y }
837
- }
838
-
839
- /** The groups of the keys a carried leg draws (#297, #325): the first alone when the keys aren't split. */
840
- const groupsOfLeg = (running: Running, groups: ReadonlyArray<ReadonlySet<string>> | undefined, owners: Owners): ReadonlyArray<number> => {
841
- if (Predicate.isUndefined(groups)) return [0]
842
- const keys = Arr.filter(Rec.keys(running.targets), (key) => owners.get(key) === running)
843
- return Arr.filter(Arr.makeBy(groups.length, identity), (g) => Arr.some(keys, (key) => UndefinedOr.match(groups[g], { onUndefined: constFalse, onDefined: (group) => group.has(key) })))
844
- }
845
-
846
- /** Each entry's gate shut now (#297's PR 2): a named one whose `when` holds its keys back. */
847
- const shutOf = (layers: ReadonlyArray<OverrideEntry>, byName: NameOrchestration | undefined): ReadonlyArray<boolean> | undefined => {
848
- if (Predicate.isUndefined(byName)) return undefined
849
- return Arr.map(layers, (layer) => {
850
- const name = layer.name
851
- if (Predicate.isUndefined(name)) return false
852
- return Bool.not(byName.mayStart(name))
853
- })
854
- }
855
-
856
- /** Whether any entry's gate is shut (#297's PR 2): none without a list. */
857
- const anyShutOf = (shut: ReadonlyArray<boolean> | undefined): boolean => {
858
- if (Predicate.isUndefined(shut)) return false
859
- return Arr.some(shut, identity)
860
- }
861
-
862
- /** A split Retarget's legs, each key group's (#291, #297), and the group each leg animates. */
863
- interface SplitLegs {
864
- readonly legs: ReadonlyArray<Leg>
865
- readonly tags: ReadonlyArray<number>
866
- }
867
-
868
- /**
869
- * A split Retarget's legs (#291, #297): each key group on its transition, over the keys that start a
870
- * leg (`t`, #325). A group with none of them makes no leg: a list's settles at once as Motion's empty
871
- * variant does, unless keys it drives stay running. A list's returns' Live values follow with its
872
- * returns' group, last; any other's with the first group.
873
- */
874
- const splitLegsOf = (
875
- t: Values.Values,
876
- from: Values.Values,
877
- groups: ReadonlyArray<ReadonlySet<string>>,
878
- resolution: Resolution,
879
- listed: boolean,
880
- transition: WardicTransition | undefined,
881
- element: WardicTransition | undefined,
882
- extraDelay: ((name: string | undefined) => number) | undefined,
883
- reuse: (transition: WardicTransition) => WardicTransition,
884
- reduce: boolean,
885
- skipped: boolean,
886
- positionalKeys: ReducedMotion.PositionalKeys["Service"],
887
- defaultTransition: DefaultTransition.DefaultTransition["Service"],
888
- velocities: Velocities,
889
- follow: Follows | undefined,
890
- stops: StopsByKey | undefined,
891
- measured: MeasuredPairs | undefined,
892
- current: Values.Values,
893
- rests: Values.Values | undefined,
894
- ): SplitLegs => {
895
- let returnsAt = 0
896
- if (listed) returnsAt = resolution.layers.length
897
- const legs: Array<Leg> = []
898
- const tags: Array<number> = []
899
- Arr.forEach(groups, (_, i) => {
900
- // A group whose keys all stay starts none (#325), as one that drives no key.
901
- const picked = pickKeys(t, groups, i)
902
- if (Rec.isEmptyRecord(picked)) return
903
- let followed: Follows | undefined
904
- if (i === returnsAt) followed = follow
905
- const groupLegs = legsOf(from, picked, groupTransitionOf(resolution, groups, i, transition, element, extraDelay, reuse), reduce, skipped, positionalKeys, defaultTransition, velocities, followed, stops, measured, current, rests)
906
- Arr.forEach(groupLegs, (built) => {
907
- legs.push(built)
908
- tags.push(i)
909
- })
910
- })
911
- return { legs, tags }
912
- }
913
-
914
- /** What a list's names make of a Retarget (#297): their settles told, and each shut one's legs' gate. */
915
- interface Listing {
916
- readonly names: NameSettles | undefined
917
- readonly legGates: ReadonlyArray<string | undefined> | undefined
918
- }
919
-
920
- /** What {@link listingOf} reads of a Retarget. */
921
- interface ListingOf {
922
- readonly listed: boolean
923
- readonly told: ToldNames | undefined
924
- readonly byName: NameOrchestration | undefined
925
- readonly resolution: Resolution
926
- readonly groups: ReadonlyArray<ReadonlySet<string>> | undefined
927
- readonly legGroups: ReadonlyArray<number> | undefined
928
- readonly legCount: number
929
- /** For each running leg it carries (#325), the groups of the keys it draws. */
930
- readonly carriedGroups: ReadonlyArray<ReadonlyArray<number>>
931
- readonly shut: ReadonlyArray<boolean> | undefined
932
- /** Write a shut group's keys where they start. */
933
- readonly hold: (group: number) => void
934
- readonly afterFlush: (fn: () => void) => void
935
- readonly config: WardConfig
936
- }
937
-
938
- /**
939
- * A list's names at a Retarget (#297): told settled as the legs of the keys each drives settle, to
940
- * the binding's callbacks (Solid 1's, PR 1) and to its orchestration (PR 2), told moving now; and each
941
- * shut name's legs waiting on its gate (PR 2), its keys held where they start, so another name's first
942
- * commit, which hands the element's style back (ADR-0034), doesn't drop them to their CSS value.
943
- */
944
- const listingOf = (of: ListingOf): Listing => {
945
- const { listed, told, byName, resolution, groups, legGroups, legCount, carriedGroups, shut, config } = of
946
- const listNames = Bool.match(listed, { onTrue: () => resolution.variant as ReadonlyArray<string>, onFalse: () => NO_NAMES })
947
- const orchestrated = Bool.and(listed, Predicate.isNotUndefined(byName))
948
- const toldNames = UndefinedOr.match(told, { onUndefined: () => NO_NAMES, onDefined: (list) => list.names })
949
- let names: NameSettles | undefined
950
- if (Bool.or(orchestrated, Predicate.isNotUndefined(told))) {
951
- if (orchestrated) (byName as NameOrchestration).moving(listNames)
952
- names = nameSettlesOf(Arr.dedupe([...listNames, ...toldNames]), resolution, groups, legGroups, legCount, carriedGroups, (settled) =>
953
- of.afterFlush(() => {
954
- UndefinedOr.map(told, (list) => {
955
- const mine = Arr.filter(settled, (name) => Arr.contains(list.names, name))
956
- if (mine.length > 0) list.tell(mine, config)
957
- })
958
- if (orchestrated) (byName as NameOrchestration).settled(Arr.filter(settled, (name) => Arr.contains(listNames, name)))
959
- }))
960
- }
961
- let legGates: ReadonlyArray<string | undefined> | undefined
962
- if (Bool.and(anyShutOf(shut), Predicate.isNotUndefined(legGroups))) {
963
- const closed = shut as ReadonlyArray<boolean>
964
- legGates = Arr.map(legGroups as ReadonlyArray<number>, (g) => gateNameOf(resolution.layers, closed, g))
965
- Arr.forEach(closed, (isShut, g) => {
966
- if (isShut) of.hold(g)
967
- })
968
- }
969
- return { names, legGates }
970
- }
971
-
972
- /** The name a leg of key group `g` waits for, if its entry's gate is shut (#297's PR 2): a list's returns wait for none. */
973
- const gateNameOf = (layers: ReadonlyArray<OverrideEntry>, shut: ReadonlyArray<boolean>, g: number): string | undefined => {
974
- if (shut[g] !== true) return undefined
975
- return UndefinedOr.match(layers[g], { onUndefined: constUndefined, onDefined: (layer) => layer.name })
976
- }
977
-
978
- /** A gate's wait (#297's PR 2): done once `open()` says so, read each tick. */
979
- const gateWaitOf = (open: () => boolean): Machine.Machine<Frame.Frame<undefined>> =>
980
- Machine.make({ settles: true, span: GATE_SPAN, start: () => () => ({ value: undefined, done: open() }) })
981
-
982
- const GATE_SPAN = { name: "wardic.spine.whenGate", attributes: {} }
983
-
984
- /** Nothing drawn while a gate is waited on. */
985
- const NO_SINK = (): undefined => undefined
986
-
987
- /** Whether a key's leg has landed (#428): its owner's done, or it has none. A guard: asked at each leg's landing while a Transition end waits (#508). */
988
- const ownerLanded = (owner: Running | undefined): boolean => {
989
- if (Predicate.isUndefined(owner)) return true
990
- return owner.done
991
- }
992
-
993
- /** Whether `runtime` keeps a Debug log: read once a runtime, so a log no level keeps forks nothing (#618). */
994
- // Module state (#460, Q7): each runtime's answer, held weakly by the runtime.
995
- const logsDebug = new WeakMap<WardicRuntime, boolean>()
996
- const logsDebugOn = (runtime: WardicRuntime): boolean => {
997
- const known = logsDebug.get(runtime)
998
- if (Predicate.isNotUndefined(known)) return known
999
- const on = runtime.runSync(Report.debugKept)
1000
- logsDebug.set(runtime, on)
1001
- return on
1002
- }
1003
-
1004
- /**
1005
- * No key taken by an Imperative animation (#433): every spine's until its first, shared, so an element
1006
- * none animates holds no map of its own (#460). Never written: a spine sets keys in a map of its own,
1007
- * and deletes only from one that has some.
1008
- */
1009
- // Module state (#460, Q7): a constant: an empty map every spine shares until its first, which none writes.
1010
- const NONE_TAKEN: Map<string, number | string | undefined> = new Map()
1011
-
1012
- /**
1013
- * A leg that waits for its name's gate first (#297's PR 2), as Motion runs a variant's `when` per
1014
- * name: started once the gate opens, on the same token, so a later Retarget ends the wait as it ends
1015
- * a leg. Without a name, the leg as it is.
1016
- */
1017
- const gatedBy = <R,>(
1018
- name: string | undefined,
1019
- byName: NameOrchestration | undefined,
1020
- options: Machine.RunOptions,
1021
- program: Effect.Effect<unknown, never, R>,
1022
- ): Effect.Effect<unknown, never, R | FrameLoop.FrameLoop> => {
1023
- if (Bool.or(Predicate.isUndefined(name), Predicate.isUndefined(byName))) return program
1024
- const orchestration = byName as NameOrchestration
1025
- const gated = name as string
1026
- return gateWaitOf(() => orchestration.mayStart(gated)).pipe(
1027
- Machine.run(NO_SINK, options),
1028
- Effect.flatMap((end) => Bool.match(Supersede.isSuperseded(end), { onTrue: () => Effect.succeed(end as unknown), onFalse: () => program })),
1029
- )
1030
- }
1031
-
1032
- /** Whether an entry is on with its own transition: hoisted, as it's asked per Retarget. */
1033
- const hasOwnTransition = (layer: OverrideEntry): boolean => Bool.and(layer.active, Predicate.isNotUndefined(layer.transition))
1034
-
1035
- /** A target as an active entry, with the name it resolved. */
1036
- const layerOf = (target: Target, name: string | undefined): OverrideEntry => ({
1037
- active: true,
1038
- values: target.values,
1039
- transition: target.transition,
1040
- name,
1041
- ends: endsOfTarget(target),
1042
- keyframes: target.keyframes,
1043
- })
1044
-
1045
- /** A list's target as an active entry (#297). */
1046
- const namedLayerOf = (target: NamedTarget): OverrideEntry => layerOf(target, target.name)
1047
-
1048
- /** A target's Transition end as an entry's (#428): none shared, so the common case allocates nothing. Per entry, per Retarget (#460): a guard. */
1049
- const endsOfTarget = (target: Target): Values.Values => {
1050
- if (Predicate.isUndefined(target.transitionEnd)) return NO_VALUES
1051
- return target.transitionEnd
1052
- }
1053
-
1054
- /** Whether an entry is on with a Transition end (#428). */
1055
- const hasEnds = (layer: OverrideEntry): boolean => Bool.and(layer.active, layer.ends !== NO_VALUES)
1056
-
1057
- /** The highest active entry that sets `key`, in its values or its Transition end (#428). */
1058
- const driverOf = (layers: ReadonlyArray<OverrideEntry>, key: string): number =>
1059
- Option.getOrElse(Arr.findLastIndex(layers, (layer) => Bool.and(layer.active, Bool.or(Object.hasOwn(layer.values, key), Object.hasOwn(layer.ends, key)))), () => -1)
1060
-
1061
- /**
1062
- * The Override stack resolved (#428): `Override.resolve` as before when no active entry has a
1063
- * Transition end; else over each entry's values and Transition end, its values winning a key both set, so
1064
- * a key only an end sets is the entry's (Motion's `{ ...target, ...transitionEnd }`), and the ends
1065
- * each entry drives.
1066
- */
1067
- const resolvedOf = (layers: ReadonlyArray<OverrideEntry>): Resolved => {
1068
- if (!Arr.some(layers, hasEnds)) {
1069
- const resolved = Override.resolve(layers)
1070
- return { resolved, ends: undefined, keyframes: keyframesNowOf(layers, resolved) }
1071
- }
1072
- const merged = Arr.map(layers, (layer): OverrideEntry => Bool.match(hasEnds(layer), { onTrue: () => ({ ...layer, values: { ...layer.ends, ...layer.values } }), onFalse: () => layer }))
1073
- const resolved = Override.resolve(merged)
1074
- const endOnly = new Map<string, number>()
1075
- const byLayer: Array<Record<string, number | string> | undefined> = Arr.makeBy(layers.length, constUndefined)
1076
- Arr.forEach(Rec.keys(resolved), (key) => {
1077
- const at = driverOf(layers, key)
1078
- const layer = layers[at]
1079
- if (Bool.or(Predicate.isUndefined(layer), Bool.not(Object.hasOwn((layer as OverrideEntry).ends, key)))) return
1080
- const driving = layer as OverrideEntry
1081
- if (Bool.not(Object.hasOwn(driving.values, key))) endOnly.set(key, at)
1082
- const into = UndefinedOr.match(byLayer[at], { onUndefined: (): Record<string, number | string> => ({}), onDefined: identity })
1083
- into[key] = driving.ends[key] as number | string
1084
- byLayer[at] = into
1085
- })
1086
- return { resolved, ends: { endOnly, byLayer }, keyframes: keyframesNowOf(layers, resolved) }
1087
- }
1088
-
1089
- /** The Override stack resolved: each key's value, its entries' Transition ends (#428) and Keyframes (#429). */
1090
- interface Resolved {
1091
- readonly resolved: Values.Values
1092
- readonly ends: Ends | undefined
1093
- readonly keyframes: KeyframesNow | undefined
1094
- }
1095
-
1096
- /** Whether an entry is on with Keyframes (#429). Per entry, per Retarget (#452): guards, nothing built. */
1097
- const hasKeyframes = (layer: OverrideEntry): boolean => {
1098
- if (Predicate.isUndefined(layer.keyframes)) return false
1099
- return layer.active
1100
- }
1101
-
1102
- /**
1103
- * Each resolved key's Keyframes (#429): the stops of the entry that drives it, when that entry gives
1104
- * it Keyframes. `undefined`, with nothing made, when no active entry has any: every element's common
1105
- * case.
1106
- */
1107
- const keyframesNowOf = (layers: ReadonlyArray<OverrideEntry>, resolved: Values.Values): KeyframesNow | undefined => {
1108
- if (!Arr.some(layers, hasKeyframes)) return undefined
1109
- const now: Record<string, KeyframesAt> = {}
1110
- Arr.forEach(Rec.keys(resolved), (key) => {
1111
- const at = driverOf(layers, key)
1112
- const layer = layers[at]
1113
- if (Predicate.isUndefined(layer)) return
1114
- const stops = UndefinedOr.map((layer as OverrideEntry).keyframes, (byKey) => byKey[key])
1115
- if (Bool.or(Predicate.isUndefined(stops), Bool.not(Object.hasOwn((layer as OverrideEntry).values, key)))) return
1116
- now[key] = { stops: stops as Style.Stops, layer: at, name: (layer as OverrideEntry).name }
1117
- })
1118
- return Bool.match(Rec.isEmptyRecord(now), { onTrue: constUndefined, onFalse: (): KeyframesNow => now })
1119
- }
1120
-
1121
-
1122
- /** Two values maps with the same keys, each holding the same value. Built once, at module load. */
1123
- const sameValues: Equivalence.Equivalence<Values.Values> = Rec.makeEquivalence(Equivalence.strictEqual<number | string>())
1124
-
1125
- /**
1126
- * Whether two resolutions are the same target (#209, #470): the same values for the same keys, in
1127
- * the base entry and resolved, the same drag, the same variant name, Keyframes and Transition ends,
1128
- * and the same gesture layers on, with the same names. Motion's rule: a config that resolves to the
1129
- * same values doesn't animate (a `transition` change applies from the next change), and a new
1130
- * variant name does, even to the same values, as a gesture turning on or off does. Both bindings'
1131
- * target memos compare with it, so a `style`, `transition` or callback change doesn't Retarget.
1132
- */
1133
- export const sameResolution = (a: Resolution, b: Resolution): boolean =>
1134
- a.dragging === b.dragging && sameLabels(a.variant, b.variant) && a.change === b.change && sameValues(a.resolved, b.resolved) && sameValues(a.base, b.base) &&
1135
- sameKeyframesNow(a.keyframes, b.keyframes) && sameLayersOn(a.layersOn, b.layersOn) && sameNamesOn(a.names, b.names) && sameEnds(a.ends, b.ends)
1136
-
1137
- /** Two resolutions' gesture layers on that set values (#470): none on both, the common case, at once. */
1138
- const sameLayersOn = (a: GestureStates, b: GestureStates): boolean => {
1139
- if (a === b) return true
1140
- return a.inView === b.inView && a.focused === b.focused && a.hovered === b.hovered && a.pressed === b.pressed && a.dragged === b.dragged
1141
- }
1142
-
1143
- /** Two resolutions' active gesture names (#470): a named entry turning on or off, or a new name. None on both, the common case, at once. */
1144
- const sameNamesOn = (a: GestureNames, b: GestureNames): boolean => {
1145
- if (a === b) return true
1146
- return sameGestureNames(a, b)
1147
- }
1148
-
1149
- /**
1150
- * Two resolutions' Transition ends the same (#470), entry by entry: a key an entry both animates and
1151
- * ends resolves to its value, so its end is compared here. `undefined` on both, the common case, at once.
1152
- */
1153
- const sameEnds = (a: Ends | undefined, b: Ends | undefined): boolean => {
1154
- if (a === b) return true
1155
- if (Predicate.isUndefined(a)) return false
1156
- if (Predicate.isUndefined(b)) return false
1157
- const y = b.byLayer
1158
- return Bool.and(a.byLayer.length === y.length, Arr.every(a.byLayer, (ends, i) => sameEndsAt(ends, y[i])))
1159
- }
1160
-
1161
- /** The value `key`'s Transition end sets it to in `ends` (#470): its driving entry's, the one entry that ends it. */
1162
- const endFor = (ends: Ends | undefined, key: string): number | string | undefined => {
1163
- if (Predicate.isUndefined(ends)) return undefined
1164
- return Option.match(Arr.findFirst(ends.byLayer, (values) => endsKey(values, key)), { onNone: constUndefined, onSome: (values) => (values as Values.Values)[key] })
1165
- }
1166
-
1167
- /** Whether an entry's Transition end sets `key`. */
1168
- const endsKey = (values: Values.Values | undefined, key: string): boolean => {
1169
- if (Predicate.isUndefined(values)) return false
1170
- return Object.hasOwn(values, key)
1171
- }
1172
-
1173
- /**
1174
- * Whether `key`'s Transition end changed since the last Retarget (#470): Motion compares a target's
1175
- * `transitionEnd` with its values, so a new end animates its key again. None on either, the common
1176
- * case, at once.
1177
- */
1178
- const endMoved = (last: Resolution | undefined, now: Resolution, key: string): boolean => {
1179
- if (Predicate.isUndefined(last)) return false
1180
- if (last.ends === now.ends) return false
1181
- return endFor(last.ends, key) !== endFor(now.ends, key)
1182
- }
1183
-
1184
- /** An entry's Transition end the same in two resolutions (#470): none on both, or the same values. */
1185
- const sameEndsAt = (a: Values.Values | undefined, b: Values.Values | undefined): boolean => {
1186
- if (a === b) return true
1187
- if (Predicate.isUndefined(a)) return false
1188
- if (Predicate.isUndefined(b)) return false
1189
- return sameValues(a, b)
1190
- }
1191
-
1192
- /** Two lists of stops equal stop by stop (#429, Motion's `shallowCompare`). */
1193
- const sameStops = (a: Style.Stops, b: Style.Stops): boolean => Bool.or(a === b, Bool.and(a.length === b.length, Arr.every(a, (stop, i) => stop === b[i])))
1194
-
1195
- /**
1196
- * Whether a start that can't take its target's shape stays as it is (#430): it makes a Measured pair
1197
- * with it, so its leg measures both ends rather than starting at the target.
1198
- */
1199
- const keepsStart = (key: string, start: number | string | undefined, target: number | string): boolean => {
1200
- if (Predicate.isUndefined(start)) return false
1201
- return MeasuredPair.needs(key, start, target)
1202
- }
1203
-
1204
- /** The keys that may be Measured pairs (#430): those found, and each Keyframes key, its start now its first stop. */
1205
- const measuringOf = (found: ReadonlyArray<string> | undefined, keyframes: KeyframesNow | undefined): ReadonlyArray<string> =>
1206
- Arr.appendAll(UndefinedOr.match(found, { onUndefined: (): ReadonlyArray<string> => [], onDefined: identity }), UndefinedOr.match(keyframes, { onUndefined: (): ReadonlyArray<string> => [], onDefined: Rec.keys }))
1207
-
1208
- /**
1209
- * A Retarget's Measured pairs (#430): each of `keys` whose start and target are one, asked of the
1210
- * end-of-task batch with the values the element draws now, but a key with Keyframes of more than two
1211
- * stops (`many`, #460). `undefined` with none.
1212
- */
1213
- const measuredOf = (element: HTMLElement, keys: ReadonlyArray<string>, from: Values.Values, to: Values.Values, values: Values.Values, many: StopsByKey | undefined): MeasuredPairs | undefined => {
1214
- const pairs: Record<string, { readonly from: number | string; readonly to: number | string }> = {}
1215
- Arr.forEach(keys, (key) => {
1216
- if (hasManyStops(many, key)) return
1217
- const start = from[key]
1218
- const target = to[key]
1219
- if (Bool.or(Predicate.isUndefined(start), Predicate.isUndefined(target))) return
1220
- if (MeasuredPair.needs(key, start as number | string, target as number | string)) pairs[key] = { from: start as number | string, to: target as number | string }
1221
- })
1222
- if (Rec.isEmptyRecord(pairs)) return undefined
1223
- return MeasuredPair.measure(element, pairs, values)
1224
- }
1225
-
1226
- /** A key's Keyframes in `keyframes` (#429): per key, per Retarget, so a guard, nothing made. */
1227
- const keyframesAtOf = (keyframes: KeyframesNow | undefined, key: string): KeyframesAt | undefined => {
1228
- if (Predicate.isUndefined(keyframes)) return undefined
1229
- return keyframes[key]
1230
- }
1231
-
1232
- /** Whether a key's Keyframes are the same (#429, {@link KeyframesAt}): its stops, its entry and that entry's name. */
1233
- export const sameKeyframesAt = (a: KeyframesAt | undefined, b: KeyframesAt | undefined): boolean => {
1234
- // Per key, per Retarget (#452): guards, the common case (neither) first.
1235
- if (a === b) return true
1236
- if (Predicate.isUndefined(a)) return false
1237
- if (Predicate.isUndefined(b)) return false
1238
- return Bool.and(Bool.and(a.layer === b.layer, a.name === b.name), sameStops(a.stops, b.stops))
1239
- }
1240
-
1241
- /** Whether two resolutions' Keyframes are the same, key by key (#429): `undefined` on both, the common case, at once. */
1242
- const sameKeyframesNow = (a: KeyframesNow | undefined, b: KeyframesNow | undefined): boolean => {
1243
- if (Bool.or(Predicate.isUndefined(a), Predicate.isUndefined(b))) return a === b
1244
- const x = a as KeyframesNow
1245
- const y = b as KeyframesNow
1246
- const keys = Rec.keys(x)
1247
- return Bool.and(keys.length === Rec.keys(y).length, Arr.every(keys, (key) => sameKeyframesAt(x[key], y[key])))
1248
- }
1249
-
1250
- /** Whether `resolution` is `last` with only its `dragging` handed back (#340). */
1251
- const handsBackOnly = (resolution: Resolution, last: Resolution | undefined): boolean =>
1252
- UndefinedOr.match(last, { onUndefined: () => false, onDefined: (l) => sameResolution({ ...resolution, dragging: l.dragging }, l) })
1253
-
1254
- /** Motion's `definition` of an animation (#257): a variant name, or its target values. */
1255
- export type AnimationDefinition = WardicVariantLabels | Values.Values
1256
-
1257
- /**
1258
- * A Retarget's `definition`, as Motion's `onAnimationStart` / `onAnimationComplete` hand it over
1259
- * (#257): the variant name its base entry resolved, when that name differs from the last started
1260
- * Retarget's (`previous`), else the target's values. Motion's definition is per animation type: a
1261
- * new `animate` variant animates as its name, and a gesture turning on or off as values (its own,
1262
- * or the keys it leaves falling back), so a variant's name is only told when the variant changed.
1263
- */
1264
- export const definitionOf = (resolution: Resolution, previous: Resolution | undefined): AnimationDefinition => {
1265
- const name = resolution.variant
1266
- // A list is told as a list (#297): a change name by name, as Motion's `checkVariantsDidChange`.
1267
- if (Bool.and(Predicate.isNotUndefined(name), Bool.not(sameLabels(name, UndefinedOr.map(previous, (p) => p.variant))))) return name as WardicVariantLabels
1268
- // A gesture's name that just came on (#291), the highest first, as Motion's names its type's.
1269
- const before = UndefinedOr.match(previous, { onUndefined: () => NO_GESTURE_NAMES, onDefined: (p) => p.names })
1270
- const started = Arr.findFirst(GESTURES_DOWN, (layer) =>
1271
- Bool.and(Predicate.isNotUndefined(resolution.names[layer]), Bool.not(sameLabels(resolution.names[layer], before[layer]))))
1272
- return Option.match(started, { onNone: (): AnimationDefinition => resolution.resolved, onSome: (layer) => resolution.names[layer] as WardicVariantLabels })
1273
- }
1274
-
1275
- /** The gesture layers, highest first. */
1276
- const GESTURES_DOWN: ReadonlyArray<GestureLayer> = Arr.reverse(GESTURE_LAYERS)
1277
-
1278
- /**
1279
- * What a Retarget tells its binding (#257): that it started, and that its last leg settled. Each is
1280
- * handed the Retarget's resolution, the variant name the last started Retarget resolved before it
1281
- * (for {@link definitionOf}), and the config it read.
1282
- */
1283
- export interface AnimationHooks {
1284
- /** A Retarget started its legs (the `when` gate let it); with no leg, it settles at once. */
1285
- readonly started: (resolution: Resolution, previous: Resolution | undefined, config: WardConfig) => void
1286
- /** That Retarget's last leg settled: not for one the next Retarget superseded, nor one a leg's failure cut off. */
1287
- readonly settled: (resolution: Resolution, previous: Resolution | undefined, config: WardConfig) => void
1288
- /**
1289
- * A leg of that Retarget failed (#257 item 4): it can't land. Told once a Retarget, at once (a
1290
- * leg that fails before it writes leaves no flush to wait for), and never before `started`; the
1291
- * failure is logged and reported apart (ADR-0030).
1292
- */
1293
- readonly failed?: ((resolution: Resolution, error: unknown) => void) | undefined
1294
- /**
1295
- * Names of a list that settled (#297): a binding told each name's end on its own (Solid 1's
1296
- * callbacks, Motion's `animateVariant` a name) has it, called as the legs of the keys each drives
1297
- * settle; one with none hears the list's end through `settled` alone.
1298
- */
1299
- readonly namesSettled?: ((names: ReadonlyArray<string>, config: WardConfig) => void) | undefined
1300
- }
1301
-
1302
- /** A list a Retarget tells settled name by name (#297): its names, and what it tells. */
1303
- interface ToldNames {
1304
- readonly names: ReadonlyArray<string>
1305
- readonly tell: (names: ReadonlyArray<string>, config: WardConfig) => void
1306
- }
1307
-
1308
- /** Whether a resolution resolved a list (#297): its base, or an active gesture's. Cheap for the common case. */
1309
- const hasList = (resolution: Resolution): boolean => {
1310
- if (Arr.isArray(resolution.variant)) return true
1311
- if (resolution.names === NO_GESTURE_NAMES) return false
1312
- return Arr.some(GESTURE_LAYERS, (layer) => Arr.isArray(resolution.names[layer]))
1313
- }
1314
-
1315
- /** The list a Retarget tells settled name by name (#297): when its binding is told so, and its definition is a list. */
1316
- const namesToldOf = (animation: AnimationHooks | undefined, resolution: Resolution, previous: Resolution | undefined): ToldNames | undefined => {
1317
- if (Predicate.isUndefined(animation)) return undefined
1318
- const tell = animation.namesSettled
1319
- if (Predicate.isUndefined(tell)) return undefined
1320
- if (Bool.not(hasList(resolution))) return undefined
1321
- const definition = definitionOf(resolution, previous)
1322
- if (Bool.not(Arr.isArray(definition))) return undefined
1323
- return { names: definition as ReadonlyArray<string>, tell }
1324
- }
1325
-
1326
- /**
1327
- * A list's names told settled one by one (#297): what each leg's end is told to, legs started in the
1328
- * Retarget's order, and each running leg it carries (#325), by its place in `carriedGroups`.
1329
- */
1330
- interface NameSettles {
1331
- readonly leg: () => (end: unknown) => void
1332
- readonly carried: (i: number) => (end: unknown) => void
1333
- }
1334
-
1335
- /**
1336
- * A list's names, each told settled with the last leg of the keys it drives (#297): its entry's group,
1337
- * or every leg's when the keys aren't split, the running legs the Retarget carries among them (#325).
1338
- * A name that drives none is told at once.
1339
- */
1340
- const nameSettlesOf = (
1341
- names: ReadonlyArray<string>,
1342
- resolution: Resolution,
1343
- groups: ReadonlyArray<ReadonlySet<string>> | undefined,
1344
- legGroups: ReadonlyArray<number> | undefined,
1345
- legCount: number,
1346
- carriedGroups: ReadonlyArray<ReadonlyArray<number>>,
1347
- tell: (names: ReadonlyArray<string>) => void,
1348
- ): NameSettles => {
1349
- const groupOf = (name: string): number => {
1350
- if (Predicate.isUndefined(groups)) return 0
1351
- return Option.getOrElse(Arr.findFirstIndex(resolution.layers, (layer) => layer.name === name), () => 0)
1352
- }
1353
- // The legs still running in each group.
1354
- const left = new Map<number, number>()
1355
- const add = (g: number): void => {
1356
- left.set(g, Option.getOrElse(Option.fromUndefinedOr(left.get(g)), () => 0) + 1)
1357
- }
1358
- UndefinedOr.match(legGroups, {
1359
- onUndefined: () => {
1360
- if (legCount > 0) left.set(0, legCount)
1361
- },
1362
- onDefined: (tags) => Arr.forEach(tags, add),
1363
- })
1364
- Arr.forEach(carriedGroups, (gs) => Arr.forEach(gs, add))
1365
- const running = (name: string): boolean => left.has(groupOf(name))
1366
- let pending = Arr.filter(names, running)
1367
- const idle = Arr.filter(names, (name) => Bool.not(running(name)))
1368
- if (idle.length > 0) tell(idle)
1369
- // A leg in group `g` ended: the names of that group are told once its last has.
1370
- const endIn = (g: number): void => {
1371
- const n = Option.getOrElse(Option.fromUndefinedOr(left.get(g)), () => 1) - 1
1372
- if (n > 0) {
1373
- left.set(g, n)
1374
- return
1375
- }
1376
- left.delete(g)
1377
- const done = Arr.filter(pending, (name) => groupOf(name) === g)
1378
- pending = Arr.filter(pending, (name) => groupOf(name) !== g)
1379
- if (done.length > 0) tell(done)
1380
- }
1381
- let next = 0
1382
- return {
1383
- leg: () => {
1384
- const g = UndefinedOr.match(legGroups, { onUndefined: () => 0, onDefined: (tags) => Option.getOrElse(Option.fromUndefinedOr(tags[next]), () => 0) })
1385
- next++
1386
- return (end) => {
1387
- // A Superseded leg (#200) settles nothing: the next Retarget's tells.
1388
- if (Supersede.isSuperseded(end)) return
1389
- endIn(g)
1390
- }
1391
- },
1392
- carried: (i) => (end) => {
1393
- if (Supersede.isSuperseded(end)) return
1394
- Arr.forEach(UndefinedOr.match(carriedGroups[i], { onUndefined: (): ReadonlyArray<number> => [], onDefined: identity }), endIn)
1395
- },
1396
- }
1397
- }
1398
-
1399
- /**
1400
- * Solid 1's animation callbacks (#257, Motion's props): each Retarget's start and settle told to the
1401
- * config's `onAnimationStart` / `onAnimationComplete`, with its `definition`, as the Retarget read
1402
- * the config. A callback that throws is reported, and the element animates on. The Solid 2 binding's
1403
- * config has neither: it hands the same facts over as async values.
1404
- */
1405
- export const animationCallbacks = (runtime: WardicRuntime, id: string): AnimationHooks => {
1406
- // Per Retarget, per element: the callback looked up first, and nothing made without one.
1407
- const tell = (name: "onAnimationStart" | "onAnimationComplete", callback: (definition: WardicAnimationDefinition) => void, definition: WardicAnimationDefinition): void => {
1408
- try {
1409
- callback(definition)
1410
- } catch (defect) {
1411
- runtime.runFork(Report.failure(`wardic.spine: ${name} failed`, Cause.die(defect)).pipe(Effect.annotateLogs({ id })))
1412
- }
1413
- }
1414
- return {
1415
- // A list starts as each of its names, in order (#297, Motion's `animateVisualElement` a name).
1416
- started: (resolution, previous, config) => {
1417
- const callback = config.onAnimationStart
1418
- if (Predicate.isUndefined(callback)) return
1419
- const definition = definitionOf(resolution, previous)
1420
- if (Arr.isArray(definition)) {
1421
- Arr.forEach(definition as ReadonlyArray<string>, (name) => tell("onAnimationStart", callback, name))
1422
- return
1423
- }
1424
- tell("onAnimationStart", callback, definition)
1425
- },
1426
- // A list's names were each told as they settled (`namesSettled`).
1427
- settled: (resolution, previous, config) => {
1428
- const callback = config.onAnimationComplete
1429
- if (Predicate.isUndefined(callback)) return
1430
- const definition = definitionOf(resolution, previous)
1431
- if (Arr.isArray(definition)) return
1432
- tell("onAnimationComplete", callback, definition)
1433
- },
1434
- namesSettled: (names, config) => {
1435
- const callback = config.onAnimationComplete
1436
- if (Predicate.isUndefined(callback)) return
1437
- Arr.forEach(names, (name) => tell("onAnimationComplete", callback, name))
1438
- },
1439
- }
1440
- }
1441
-
1442
- /** Which entries of the Override stack are active now, as the binding reads them. */
1443
- export interface Active {
1444
- /** In view (#273): `whileInView` applies. */
1445
- readonly inView: boolean
1446
- /** Focused, as the Environment shows it (`:focus-visible`, #273): `whileFocus` applies. */
1447
- readonly focused: boolean
1448
- readonly hovered: boolean
1449
- readonly pressed: boolean
1450
- /** A drag, or a **Keyboard reorder**'s lift (ADR-0037): `whileDrag` applies. */
1451
- readonly dragged: boolean
1452
- /** A drag: the translate keys are the drag's (ADR-0004). */
1453
- readonly dragging: boolean
1454
- }
1455
-
1456
- /** The variant name an element animates to: its own `animate`'s, else the one its provider hands down. */
1457
- const variantOf = (animate: WardConfig["animate"], parent: WardicVariantContextValue | undefined): WardicVariantLabels | undefined => {
1458
- if (Predicate.isNotUndefined(animate)) return nameOf(animate)
1459
- if (Predicate.isUndefined(parent)) return undefined
1460
- return parent.variant()
1461
- }
1462
-
1463
- /** The base target (ADR-0007): its own `animate`'s, else the inherited name's, else the seeded `initial`. */
1464
- const baseTargetOf = (
1465
- own: Entry | undefined,
1466
- variant: WardicVariantLabels | undefined,
1467
- variants: WardicVariants | undefined,
1468
- custom: unknown,
1469
- state: VariantState,
1470
- initialLink: Values.Values,
1471
- ): Target => {
1472
- if (Predicate.isNotUndefined(own)) return resolveTarget(own, variants, custom, state)
1473
- if (Predicate.isNotUndefined(variant)) return resolveTarget(variant, variants, custom, state)
1474
- return { values: initialLink, transition: undefined, transitionEnd: undefined, keyframes: undefined }
1475
- }
1476
-
1477
- /**
1478
- * The Override stack resolved (ascending priority, Motion's `variantPriorityOrder`): base (animate, or
1479
- * initial when no animate) -> whileInView -> whileFocus -> whileHover -> whileTap -> whileDrag (#273
1480
- * added the first two). `Override.resolve` picks the last active entry per key. Pure:
1481
- * a binding computes it in a memo, so a config change, an inherited variant name's
1482
- * (`parent.variant()`, read only when there's no `animate`) or an entry's drives a Retarget.
1483
- */
1484
- export const resolutionOf = (
1485
- c: WardConfig,
1486
- parent: WardicVariantContextValue | undefined,
1487
- initialLink: Values.Values,
1488
- active: Active,
1489
- state: VariantState,
1490
- own?: ControlsChange | undefined,
1491
- ): Resolution => {
1492
- // The Controls change in effect (#433): its own controls', else its provider's, read here so a new one Retargets.
1493
- const change = changeIn(own, parent)
1494
- const variants = c.variants
1495
- // Base target resolution priority (ADR-0007):
1496
- // (1) local `animate` (a Values map or a variant name) — overrides any
1497
- // inherited variant entirely;
1498
- // (2) else an INHERITED variant name from the parent context, resolved
1499
- // against THIS child's OWN `variants` (a child's "open" != its
1500
- // sibling's "open"); read parent.variant() here so a parent flip
1501
- // recomputes the memo and retargets;
1502
- // (3) else the SSR-seeded `initial`.
1503
- // Per Retarget, per element (#460, compose once): statements.
1504
- const variant = variantOf(c.animate, parent)
1505
- // A list of names (#297, Motion's `VariantLabels`): a base entry a name, in order, so the last name
1506
- // that sets a key drives it. A single name or a values map takes the path below, as before.
1507
- if (Arr.isArray(c.animate) || (Predicate.isUndefined(c.animate) && Arr.isArray(variant))) {
1508
- const targets = resolveTargets(variant as ReadonlyArray<string>, variants, c.custom, state)
1509
- const merged = mergedOf(targets)
1510
- const listLayers: Array<OverrideEntry> = Arr.map(targets, namedLayerOf)
1511
- return withGestures(c, parent, listLayers, merged.values, variant, active, merged.transition, state, change)
1512
- }
1513
- // A dynamic variant resolves with this element's own `custom` (#277), as Motion's each child's.
1514
- // Animation controls never reach here: its binding reads them once, each change its entry (#433).
1515
- const target = baseTargetOf(c.animate as Entry | undefined, variant, variants, c.custom, state, initialLink)
1516
- const base = target.values
1517
- const baseLayer: OverrideEntry = layerOf(target, variant as string | undefined)
1518
- // A Variant child's gestures are on while its provider's are (#291, Motion's `setActive`), each on
1519
- // its own `while*`, else the label the provider hands down. With no provider, its own: nothing made.
1520
- // The common case: nothing handed down and no gesture on. The base entry alone, and nothing else
1521
- // made or called, at every element's mount and Retarget.
1522
- if (handDownFrom(parent) === NO_HAND_DOWN && !anyOn(active)) {
1523
- const alone: ReadonlyArray<OverrideEntry> = [baseLayer]
1524
- const { resolved, ends, keyframes } = resolvedOf(alone)
1525
- return { resolved, base, dragging: active.dragging, variant, active, transition: target.transition, layers: alone, names: NO_GESTURE_NAMES, layersOn: NO_GESTURE_STATES, ends, keyframes, change }
1526
- }
1527
- return withGestures(c, parent, [baseLayer], base, variant, active, target.transition, state, change)
1528
- }
1529
-
1530
- /** The **Controls change** in effect for an element (#433): its own, else its provider's; per Retarget, a guard. */
1531
- const changeIn = (own: ControlsChange | undefined, parent: WardicVariantContextValue | undefined): ControlsChange | undefined => {
1532
- if (Predicate.isNotUndefined(own)) return own
1533
- if (Predicate.isUndefined(parent)) return undefined
1534
- const inherited = parent.change
1535
- if (Predicate.isUndefined(inherited)) return undefined
1536
- return inherited()
1537
- }
1538
-
1539
- /**
1540
- * `resolution` run on its Controls change's override (#433, Motion's `transitionOverride`): its base
1541
- * entries' own transitions beaten by it, its gestures' kept. The first Retarget for the change only.
1542
- */
1543
- const overriddenOf = (resolution: Resolution, override: WardicTransition): Resolution => {
1544
- const variant = resolution.variant
1545
- let base = 1
1546
- if (Arr.isArray(variant)) base = variant.length
1547
- return {
1548
- ...resolution,
1549
- transition: override as WardicVariantTransition,
1550
- layers: Arr.map(resolution.layers, (layer, i) => Bool.match(i < base, { onTrue: (): OverrideEntry => ({ ...layer, transition: override as WardicVariantTransition }), onFalse: () => layer })),
1551
- }
1552
- }
1553
-
1554
- /**
1555
- * A resolution from its base entries (one, or one a name of a list, #297) and its gesture layers on
1556
- * top (#291), each gesture's an entry a name too: the Override stack resolved, and the names its
1557
- * active gestures resolved.
1558
- */
1559
- const withGestures = (
1560
- c: WardConfig,
1561
- parent: WardicVariantContextValue | undefined,
1562
- layers: Array<OverrideEntry>,
1563
- base: Values.Values,
1564
- variant: WardicVariantLabels | undefined,
1565
- active: Active,
1566
- transition: WardicVariantTransition | undefined,
1567
- state: VariantState,
1568
- change: ControlsChange | undefined,
1569
- ): Resolution => {
1570
- const variants = c.variants
1571
- const above = handDownFrom(parent)
1572
- if (Bool.and(above === NO_HAND_DOWN, Bool.not(anyOn(active)))) {
1573
- const { resolved, ends, keyframes } = resolvedOf(layers)
1574
- return { resolved, base, dragging: active.dragging, variant, active, transition, layers, names: NO_GESTURE_NAMES, layersOn: NO_GESTURE_STATES, ends, keyframes, change }
1575
- }
1576
- const on = gesturesOnOf(active, above)
1577
- const labels = above.names
1578
- // In Motion's priority, lowest first: a literal's fields are evaluated in order.
1579
- const layersOn: GestureStates = {
1580
- inView: gestureLayersInto(layers, c.whileInView, on.inView, labels.inView, variants, c.custom, state),
1581
- focused: gestureLayersInto(layers, c.whileFocus, on.focused, labels.focused, variants, c.custom, state),
1582
- hovered: gestureLayersInto(layers, c.whileHover, on.hovered, labels.hovered, variants, c.custom, state),
1583
- pressed: gestureLayersInto(layers, c.whileTap, on.pressed, labels.pressed, variants, c.custom, state),
1584
- // whileDrag sits ABOVE tap (highest priority) — driven by the spring,
1585
- // NOT stripped, so e.g. `scale: 1.1` animates while held and returns
1586
- // after release.
1587
- dragged: gestureLayersInto(layers, c.whileDrag, on.dragged, labels.dragged, variants, c.custom, state),
1588
- }
1589
- const { resolved, ends, keyframes } = resolvedOf(layers)
1590
- const names = activeNamesFor(c, on, labels)
1591
- return { resolved, base, dragging: active.dragging, variant, active, transition, layers, names, layersOn, ends, keyframes, change }
1592
- }
1593
-
1594
- /** The values an element starts from, read once at setup (ADR-0003, #134). */
1595
- export interface Start {
1596
- /** Its Starting style's values: its `initial` (own or inherited, #50), or its `animate` when it starts there. */
1597
- readonly initialValues: Values.Values
1598
- /** Its `initial` link in the Base-value chain and its fallback base entry: none when it started at `animate`. */
1599
- readonly initialLink: Values.Values
1600
- /** When it started at `animate`, those values, which come after `style` (Motion's `baseTarget`, ADR-0022). */
1601
- readonly startedLink: Values.Values
1602
- /**
1603
- * Whether its mount tells nothing (#448, Motion's `animation-state.ts`): it starts at its `animate`
1604
- * (`initial={false}`, or an `<AnimatePresence initial={false}>`'s first render), or its `initial` is
1605
- * the same name, list or values map as its `animate`, each its own or inherited. Its first Retarget,
1606
- * landing with nothing to animate, is told to no one.
1607
- */
1608
- readonly quiet: boolean
1609
- }
1610
-
1611
- /**
1612
- * An element's {@link Start}, from its config read once and the context it inherits from. With
1613
- * `initial={false}` (its own, inherited, or an `<AnimatePresence initial={false}>`'s first render)
1614
- * it starts at its `animate`, and nothing animates at mount (#134).
1615
- */
1616
- export const startOf = (
1617
- config: WardConfig,
1618
- parent: WardicVariantContextValue | undefined,
1619
- presenceBlocks: boolean,
1620
- untrack: Reactivity["untrack"],
1621
- ): Start => {
1622
- const startedAtAnimate = startsAtAnimate(config, parent, presenceBlocks)
1623
- const initialValues = startingValuesOf(config, parent, presenceBlocks, untrack)
1624
- return {
1625
- quiet: startsQuiet(config, parent, presenceBlocks, untrack),
1626
- initialValues,
1627
- initialLink: Bool.match(startedAtAnimate, { onTrue: () => ({}), onFalse: () => initialValues }),
1628
- startedLink: Bool.match(startedAtAnimate, { onTrue: () => initialValues, onFalse: () => ({}) }),
1629
- }
1630
- }
1631
-
1632
- /**
1633
- * The Snapshot: each key's last emitted value, a number or a string, and the numeric velocities.
1634
- * A Retarget starts each key from where it is, with its velocity carried across the seam (ADR-0005,
1635
- * ADR-0024). Plain, not reactive; a drag writes its `x`/`y` into it too (ADR-0004).
1636
- */
1637
- export interface Snapshot {
1638
- values: Values.Values
1639
- /**
1640
- * Each numeric key's velocity (#464, Motion's): a spring's own, a drag's pointer's, or, for a key a
1641
- * leg let go, the one its last two frames gave it. Read through the spine, which takes a running
1642
- * leg's and reads one drawn more than `MAX_VELOCITY_DELTA` ago as 0.
1643
- */
1644
- velocities: Record<string, number>
1645
- /**
1646
- * When each key's velocity here was last drawn, on {@link frameNow}'s clock (#464): the last frame of
1647
- * the leg that let it go, or a drag's or a presence seed's setting.
1648
- */
1649
- drawnAt: Record<string, number>
1650
- /** The leg drawing each key, its spine's (#464): a running leg's velocity is read from it. None before its spine runs. */
1651
- owners: ReadonlyMap<string, Running | undefined> | undefined
1652
- /** The time now, its provider's Clock's once its spine runs (#460, Q7), {@link frameNow} before. */
1653
- now: () => number
1654
- /**
1655
- * Every numeric key's velocity now (#663), given the Snapshot: {@link velocitiesNowOf}, one function
1656
- * every Snapshot shares. A resolver and Animation controls read these: `velocities` doesn't hold a
1657
- * spring leg's. A method, so a Snapshot is a resolver's `VariantState`.
1658
- */
1659
- velocitiesNow(snapshot: Snapshot): Readonly<Record<string, number>>
1660
- }
1661
-
1662
- /** A Snapshot seeded from the Starting values, velocities 0, so frame 1 flows out of the seed (no snap). */
1663
- export const snapshotOf = (start: Start): Snapshot => emptySnapshotOf({ ...start.initialValues })
1664
-
1665
- /** A Snapshot of `values`, nothing moving: read as it is until a spine reads it. */
1666
- export const emptySnapshotOf = (values: Values.Values): Snapshot => ({ values, velocities: {}, drawnAt: {}, owners: undefined, now: frameNow, velocitiesNow: velocitiesNowOf })
1667
-
1668
- // --- Velocities (#464) ---------------------------------------------------------------------------
1669
-
1670
- /** A leg's velocity for `key`: a Blend leg's from its frames, a Snap's none, a spring's or a follow's as it wrote it. */
1671
- const legVelocityOf = (snapshot: Snapshot, running: Running, key: string): number => {
1672
- if (running.kind === "Blend") return blendVelocityOf(running, key)
1673
- if (running.kind === "Snap") return 0
1674
- if (running.kind === "Numbers") return numbersVelocityOf(snapshot, running, key)
1675
- return velocityOf(snapshot, key)
1676
- }
1677
-
1678
- /**
1679
- * A Numbers leg's velocity for `key` (#663): its last Frame's, as it drew it, by index from a spring's
1680
- * (whose velocity record it doesn't write), from the record of an inertia's; the Snapshot's before its
1681
- * first frame, or for a key its Frame doesn't have. Per key, per Retarget: guards.
1682
- */
1683
- const numbersVelocityOf = (snapshot: Snapshot, running: Running, key: string): number => {
1684
- const last = running.physics
1685
- if (Predicate.isUndefined(last)) return velocityOf(snapshot, key)
1686
- if (Frame.isSpringValues(last)) {
1687
- const at = last.keys.indexOf(key)
1688
- if (at < 0) return velocityOf(snapshot, key)
1689
- return UndefinedOr.getOrThrow(last.velocities[at])
1690
- }
1691
- const velocity = last.velocity[key]
1692
- if (Predicate.isUndefined(velocity)) return velocityOf(snapshot, key)
1693
- return velocity
1694
- }
1695
-
1696
- /**
1697
- * `key`'s velocity at `now` (#464, Motion's `getVelocity`): the leg drawing it, once it has drawn a
1698
- * frame, else what the Snapshot holds for it (the last leg to let it go left it, a drag or a seed set
1699
- * it), whichever drew it last; 0 once nothing has moved it for `MAX_VELOCITY_DELTA`. Read only for a
1700
- * key a spring or a follow starts, or one a leg lets go: guards, nothing made.
1701
- */
1702
- const velocityAt = (snapshot: Snapshot, owner: Running | undefined, key: string, now: number): number => {
1703
- const at = snapshot.drawnAt[key]
1704
- // Guards, not `Bool.and`, which reads both sides: a leg that hasn't drawn yet stands for nothing.
1705
- if (Predicate.isNotUndefined(owner)) {
1706
- if (owner.frames > 0) {
1707
- if (Predicate.isUndefined(at) || owner.lastAt >= (at as number)) {
1708
- if (now - owner.lastAt > MAX_VELOCITY_DELTA) return 0
1709
- return legVelocityOf(snapshot, owner, key)
1710
- }
1711
- }
1712
- }
1713
- if (Predicate.isUndefined(at)) return 0
1714
- if (now - at > MAX_VELOCITY_DELTA) return 0
1715
- return velocityOf(snapshot, key)
1716
- }
1717
-
1718
- /**
1719
- * `running` lets `key` go, having drawn it (#464): the velocity it gives the key now (0 once it's drawn
1720
- * nothing for 30 ms) and its last frame's time stay on the Snapshot, as numbers. Keeping the leg itself
1721
- * kept its Retarget's closures alive until the unmount, which paid for them. A string carries none.
1722
- */
1723
- const letGo = (snapshot: Snapshot, key: string, running: Running): void => {
1724
- if (running.frames === 0) return
1725
- if (!Predicate.isNumber(snapshot.values[key])) return
1726
- snapshot.velocities[key] = velocityAt(snapshot, running, key, snapshot.now())
1727
- snapshot.drawnAt[key] = running.lastAt
1728
- }
1729
-
1730
- /** Every numeric key's velocity now (#464): a presence's exit and takeover read it (#286). */
1731
- export const velocitiesNowOf = (snapshot: Snapshot): Readonly<Record<string, number>> => {
1732
- const now = snapshot.now()
1733
- const owners = snapshot.owners
1734
- return Rec.map(Rec.filter(snapshot.values, Predicate.isNumber), (_, key) =>
1735
- velocityAt(snapshot, UndefinedOr.match(owners, { onUndefined: constUndefined, onDefined: (map) => map.get(key) }), key, now))
1736
- }
1737
-
1738
- /**
1739
- * The transition a Retarget runs on (#66): the element's last one when the new one has the same
1740
- * fields, so core's decode cache hits when the object is rebuilt with the same values (a staggered
1741
- * child's, ADR-0007, or one Solid rebuilds as it reads a signal). One per element.
1742
- */
1743
- export const makeReuse = (): ((transition: WardicTransition) => WardicTransition) => {
1744
- let lastTransition: WardicTransition | undefined
1745
- // Per Retarget (#460, compose once): statements.
1746
- return (transition) => {
1747
- if (Predicate.isNotUndefined(lastTransition) && sameFields(lastTransition, transition)) return lastTransition
1748
- lastTransition = transition
1749
- return transition
1750
- }
1751
- }
1752
-
1753
- /**
1754
- * A mounted element's Base-value links (ADR-0022): a key with no value starts from its `style`
1755
- * value, else its Own value. The Own value is read from the element once per key, at first need
1756
- * (D3): after mount, so never on a server (ADR-0021). Each link is coerced to the shape of the
1757
- * key's target (`like`). `styleNow` reads the user's style untracked; a Live value in it is read now.
1758
- */
1759
- export const startLinksOf = (element: HTMLElement, styleNow: (() => object | string | undefined) | undefined, live: LiveStyle | undefined) => {
1760
- const ownValue = OwnValues.of(element)
1761
- // A `style` value read now: a Live value's current value (#130), anything else as it is.
1762
- const readStyle = (raw: unknown): unknown => {
1763
- if (Predicate.isUndefined(live)) return raw
1764
- return live.read(raw)
1765
- }
1766
- const linksFor = (like: number | string) => ({
1767
- style: (key: string) =>
1768
- Option.flatMap(Option.fromUndefinedOr(styleNow), (now) =>
1769
- Option.flatMap(OwnValues.styleValueOf(now(), key), (raw) => OwnValues.valueLike(readStyle(raw), like)),
1770
- ),
1771
- own: (key: string) => Option.flatMap(ownValue(key), (raw) => OwnValues.valueLike(raw, like)),
1772
- })
1773
- const startLinkOf = (key: string, like: number | string) => BaseValue.start(key, linksFor(like))
1774
- return { ownValue, linksFor, startLinkOf }
1775
- }
1776
-
1777
- /** {@link startLinksOf}'s links. */
1778
- export type StartLinks = ReturnType<typeof startLinksOf>
1779
-
1780
- /**
1781
- * An element's presence record (ADR-0007 exit): seeded with its Starting values, so an exit that
1782
- * fires before any frame still has a `from`, and its `exit` ref, which the ward keeps current. An exit key with no value starts
1783
- * from its Base value's start links (ADR-0022), read from the retained node at the exit.
1784
- */
1785
- export const presenceRecordOf = (
1786
- element: HTMLElement,
1787
- start: Start,
1788
- exitOf: (custom: unknown, inherited: WardicVariantLabels | undefined) => ExitTarget,
1789
- links: StartLinks,
1790
- tree: PresenceTree,
1791
- snapshot: Snapshot,
1792
- reducedMotion: () => boolean,
1793
- skipAnimations: () => boolean,
1794
- ): PresenceRecord => ({
1795
- element,
1796
- snapshot: { current: { ...start.initialValues } },
1797
- exitOf,
1798
- tree,
1799
- startOf: (key, like) => Option.getOrUndefined(Option.map(links.startLinkOf(key, like), (s) => s.value)),
1800
- // Its spine's, read when a child back under its key takes over from it (#286): its running legs' too (#464).
1801
- velocities: () => velocitiesNowOf(snapshot),
1802
- // Its own, under its nearest WardicConfig (#434): its exit honours it, not the presence's.
1803
- reducedMotion,
1804
- // Its nearest WardicConfig's (#468): an exit is skipped as its element's animations are.
1805
- skipAnimations,
1806
- })
1807
-
1808
- /**
1809
- * Merge an emitted frame's value-map into a presence record's snapshot (nothing without one). It
1810
- * mirrors what the gate accumulates, so an exit departs from the element's actual resting value-map.
1811
- */
1812
- export const recordFrameOf = (presence: PresenceRecord | undefined): ((value: Values.Values) => void) => (value) => {
1813
- if (Predicate.isNotUndefined(presence)) Object.assign(presence.snapshot.current, value)
1814
- }
1815
-
1816
- /**
1817
- * Turn the element's will-change value on (#443, Motion's `addValueToWillChange`) when its `style`
1818
- * gives it one and one of `legs` animates a transform key or one a browser composites. A key already
1819
- * at its target starts no leg (#448), and a layout animation runs none, so neither does. Per start:
1820
- * a lookup in its routed keys, none for a style that routes nothing.
1821
- */
1822
- const turnWillChangeOn = (live: LiveStyle | undefined, legs: ReadonlyArray<Leg>): void => {
1823
- if (Predicate.isUndefined(live)) return
1824
- const turnOn = live.willChange()
1825
- if (Predicate.isUndefined(turnOn)) return
1826
- if (Arr.some(legs, (leg) => Arr.some(Rec.keys(leg.to), turnsWillChangeOn))) turnOn()
1827
- }
1828
-
1829
- /**
1830
- * Each draggable element's spine's drag hook (#665's PR 4): told `true` as its drag reads where the
1831
- * element rests or writes `x`/`y`, and `false` as it hands them back. A Batch member's takes its
1832
- * transform from its Batch then, and gives it back.
1833
- */
1834
- // Module state (#460, Q7): held weakly by the element, so it goes with it.
1835
- const DRAG_HOOKS = new WeakMap<Element, (on: boolean) => void>()
1836
-
1837
- /** `element`'s drag hook told `on`, when its spine has one. */
1838
- const tellDrag = (element: Element, on: boolean): void => {
1839
- UndefinedOr.map(DRAG_HOOKS.get(element), (tell) => tell(on))
1840
- }
1841
-
1842
- /**
1843
- * A binding's `setDragging`, turning the element's will-change value on as a drag starts (#443,
1844
- * Motion's): `"transform"`, as its drag draws `x` and `y`. Its spine hears each start and end too, for
1845
- * a Batch member's `x` and `y` (#665's PR 4).
1846
- */
1847
- export const draggingWithWillChange = (live: LiveStyle | undefined, setDragging: (on: boolean) => void, element: Element): ((on: boolean) => void) => {
1848
- const set = UndefinedOr.match(live, {
1849
- onUndefined: () => setDragging,
1850
- onDefined: (style) => (on: boolean) => {
1851
- if (on) UndefinedOr.map(style.willChange(), (turnOn) => turnOn())
1852
- setDragging(on)
1853
- },
1854
- })
1855
- return (on) => {
1856
- set(on)
1857
- tellDrag(element, on)
1858
- }
1859
- }
1860
-
1861
- /**
1862
- * A drag track's `claim` for `element` (#665's PR 4): told before the drag reads where the element
1863
- * rests or writes `x`/`y`, so a Batch member's element takes its transform from its Batch first.
1864
- */
1865
- export const claimForDrag = (element: Element): (() => void) => () => tellDrag(element, true)
1866
-
1867
- /** What {@link makeElementSpine} reads. */
1868
- export interface ElementSpineOptions {
1869
- /** The provider runtime the legs fork on. */
1870
- readonly runtime: WardicRuntime
1871
- /** The provider-owned flush gate (ADR-0006). */
1872
- readonly gate: FlushGate.Shape
1873
- /** The element's gate id. */
1874
- readonly id: string
1875
- /** The mounted element. */
1876
- readonly element: HTMLElement
1877
- /** Its tag, for a Handoff's check (SVG's routing): `undefined` when it isn't known. */
1878
- readonly tag: string | undefined
1879
- /** Its config now, read where the binding doesn't track. */
1880
- readonly config: () => WardConfig
1881
- /** The variant context it inherits names and its default transition from (`variant-tree.ts`). */
1882
- readonly parent: WardicVariantContextValue | undefined
1883
- /** Whether a Retarget may start now (ADR-0007 `when`); omitted, always. */
1884
- readonly canStart: (() => boolean) | undefined
1885
- /** Its stagger delay in seconds, read at each Retarget (ADR-0007); omitted, none. */
1886
- readonly extraDelay: ((name: string | undefined) => number) | undefined
1887
- /** Told every frame whether it has settled (ADR-0007 orchestration). */
1888
- readonly onFrame: ((done: boolean) => void) | undefined
1889
- /** Whether reduced motion applies (ADR-0029), read at each Retarget. */
1890
- readonly reducedMotion: () => boolean
1891
- /**
1892
- * Whether its animations are skipped (#468, its nearest `WardicConfig`'s `skipAnimations`), read at
1893
- * each Retarget and each Imperative animation: every key lands at its end on the next tick. Omitted, never.
1894
- */
1895
- readonly skipAnimations?: (() => boolean) | undefined
1896
- /** Which keys reduced motion Snaps (ADR-0036). */
1897
- readonly positionalKeys: ReducedMotion.PositionalKeys["Service"]
1898
- /** What a key with no transition of its own runs on (ADR-0051). */
1899
- readonly defaultTransition: DefaultTransition.DefaultTransition["Service"]
1900
- readonly start: Start
1901
- readonly snapshot: Snapshot
1902
- readonly reuse: (transition: WardicTransition) => WardicTransition
1903
- readonly links: StartLinks
1904
- /** The user's style now, read untracked: a key's `style` link (ADR-0022). */
1905
- readonly styleNow: (() => object | string | undefined) | undefined
1906
- /** Its routed `style` keys (#130, ADR-0043). */
1907
- readonly live: LiveStyle | undefined
1908
- /** Its presence record, under an `<AnimatePresence>`. */
1909
- readonly presence: PresenceRecord | undefined
1910
- /**
1911
- * Whether a projection node owns its translate keys (ADR-0016): its drag drives its layout node. A
1912
- * getter while its track waits for `drag` (#551, #582), so it's read where it's used.
1913
- */
1914
- readonly projected: boolean
1915
- /** Its drag axis, `undefined` without a drag (ADR-0004). */
1916
- readonly dragAxis: boolean | "x" | "y" | undefined
1917
- /** Its drag track, whose release a Retarget may take `x`/`y` from (#340); omitted, the drag holds them while `dragging`. */
1918
- readonly drag?: DragTrack | undefined
1919
- /** Its Appear animation, while hydrating (#48, ADR-0044 decision 6). */
1920
- readonly handoff: Handoff | undefined
1921
- /** Told each Retarget's start and settle (#257); omitted, nothing is told. */
1922
- readonly animation?: AnimationHooks | undefined
1923
- /**
1924
- * A list's names orchestrated each on their own (#297's PR 2): a name's keys start once its gate
1925
- * opens, and its starts and settles are told. Omitted for an element that joins nothing and
1926
- * provides nothing.
1927
- */
1928
- readonly byName?: NameOrchestration | undefined
1929
- }
1930
-
1931
- /** What the follower reads of the element's Override stack and drag, untracked. */
1932
- export interface FollowNow {
1933
- readonly resolved: () => Values.Values
1934
- readonly dragging: () => boolean
1935
- }
1936
-
1937
- /** What an **Imperative animation** tells of its legs on one element (#433). */
1938
- export interface ImperativeHooks {
1939
- /** Every leg it started on the element landed, told after the gate's flush of their last frames. */
1940
- readonly settled: () => void
1941
- /** A leg failed, reported already (ADR-0030). */
1942
- readonly failed: (cause: Cause.Cause<unknown>) => void
1943
- }
1944
-
1945
- /** An **Imperative animation** on one element (#433): its legs, built at the call, run through its Playhead. */
1946
- export interface ImperativeTrack {
1947
- /** Run every leg from the Playhead's time: those running end first, so a seek starts them again there. */
1948
- readonly run: () => void
1949
- /** End every leg where it is: its keys stay there, the animation's. */
1950
- readonly stop: () => void
1951
- /** End every leg, and put its keys back where it started them. */
1952
- readonly cancel: () => void
1953
- /** How long its longest leg runs, in seconds (`Machine.durationOf`, Motion's `duration`). */
1954
- readonly duration: () => number
1955
- }
1956
-
1957
- /** A mounted element's spine. */
1958
- export interface ElementSpine {
1959
- /** A Retarget toward `resolution`: called by the binding on each change of its target, untracked. */
1960
- readonly retarget: (resolution: Resolution) => void
1961
- /** Follow the element's Live values in `style` (#130), from its first routed key on. */
1962
- readonly follow: (now: FollowNow) => void
1963
- /** The element's teardown: following stops, and the legs end. */
1964
- readonly dispose: () => void
1965
- /**
1966
- * Start where a leaver is drawn (#286, ADR-0048), before the first Retarget: each key's value and
1967
- * velocity, drawn now. A key no entry sets returns to its Base value from there, as one a Retarget
1968
- * drove does.
1969
- */
1970
- readonly seed: (from: PresenceSeed) => void
1971
- /**
1972
- * An **Imperative animation** of the element (#433): it takes `target`'s keys from whatever runs
1973
- * them, each noted with the target the Override stack has for it now, so a Retarget leaves it where
1974
- * the animation leaves it until that target changes (Motion's latest-wins). Its legs start where
1975
- * the keys are drawn, with their velocity, on `transition` (a key with none of its own on its
1976
- * Default transition), reduced motion as the provider says, and run through `head` once
1977
- * {@link ImperativeTrack.run} is called.
1978
- */
1979
- readonly animate: (target: Target, transition: WardicTransition | undefined, head: Playback.Playhead, hooks: ImperativeHooks) => ImperativeTrack
1980
- /** End every running leg where it is (#433, **Animation controls**' `stop`): its keys stay there, until the next Retarget. */
1981
- readonly stop: () => void
1982
- }
1983
-
1984
- /**
1985
- * A mounted element's spine: its Retarget, the returns to its Base values, the follower of its
1986
- * Live values, and its legs' lifetime. Every leg is a fiber of its provider's runtime, and joins
1987
- * its Retarget's token: a Retarget ends the token before it starts its own legs, and {@link
1988
- * ElementSpine.dispose} ends every leg's (#542). Both end the legs in the calling task: each leg's
1989
- * run leaves the loop at once, and its fiber ends Superseded, inline (ADR-0027, decision 5,
1990
- * *Amendment (#200)*). A leg the token didn't reach is interrupted (`endLeg`). The runtime's own
1991
- * fiber Scope interrupts what's left when the provider ends.
1992
- */
1993
- export const makeElementSpine = (options: ElementSpineOptions): ElementSpine => {
1994
- const { animation, byName, canStart, config, defaultTransition, element, extraDelay, gate, id, links, live, onFrame, parent, positionalKeys, presence, runtime, snapshot, start, styleNow, tag } = options
1995
- const { initialLink, initialValues, startedLink } = start
1996
- const { linksFor, ownValue, startLinkOf } = links
1997
- let handoff = options.handoff
1998
- // Its mount tells nothing when it starts at its `animate` (#448): on until its first Retarget.
1999
- let quiet = start.quiet
2000
- // Its Variable values (#55, ADR-0035 *Amendment (#55)*): the Key rule bound to this element,
2001
- // added to each leg it starts, so a `var()` end blends what it resolves to here.
2002
- const elementRules = [Variables.values(element)]
2003
- const recordFrame = recordFrameOf(presence)
2004
- // Whether its animations are skipped (#468): never, with nothing given.
2005
- const skipAnimations = UndefinedOr.match(options.skipAnimations, { onUndefined: () => constFalse, onDefined: identity })
2006
-
2007
- // A routed key a return handed back: written by the follower from now on (#130). Set by
2008
- // `follow`; a return settles a tick after it runs at the earliest.
2009
- let handBack: (key: string) => void = constVoid
2010
-
2011
- // The keys a Retarget drove, each with its last target value (its shape), and the
2012
- // ones returning to their Base value until that return settles (ADR-0022). Both are
2013
- // the spine's: a Retarget mid-return carries them again, so a return is never
2014
- // frozen half-way, and a key that settled has left them, so a Retarget of the same
2015
- // target (a `when` gate reopening, ADR-0007) leaves it be. On a drag element, the keys
2016
- // the drag moves leave the return while it runs, so they stay where it dropped them (C9)
2017
- // until an entry sets them again; a projected element's drag moves none, its projection
2018
- // target does (ADR-0016), and its own translate returns as any key does (#363).
2019
- const driven = new Map<string, number | string>()
2020
- let returning = new Map<string, BaseValue.BaseSource>()
2021
- // Read as a drag holds them: `projected` is a getter while the track waits for `drag` (#551), whose
2022
- // track may drive a layout node that arrived with it (#582).
2023
- const dragMoves = (): ReadonlyArray<string> => {
2024
- if (options.projected) return NO_KEYS
2025
- return UndefinedOr.match(options.dragAxis, { onUndefined: () => NO_KEYS, onDefined: dragMovesOf })
2026
- }
2027
-
2028
- // A Retarget's returns have settled (ADR-0022, D4). A key back at its `style` value is
2029
- // handed back to the element's style, so a later style change shows at rest and the
2030
- // next gesture starts from it; any other key rests inline at its Base value and leaves
2031
- // the target. A key a later Retarget took over is left alone. A routed key (#130) stays
2032
- // in the gate, handed to the follower, which writes its value from now on.
2033
- const settleReturns = (returns: ReadonlyArray<readonly [string, BaseValue.BaseSource]>): void => {
2034
- // The returns still this Retarget's: a later one took over the rest.
2035
- const settled = Arr.filter(returns, ([key, source]) => returning.get(key) === source)
2036
- Arr.forEach(settled, ([key]) => {
2037
- returning.delete(key)
2038
- driven.delete(key)
2039
- owners.set(key, undefined)
2040
- })
2041
- const toStyle = Arr.map(Arr.filter(settled, ([, source]) => source === "style"), ([key]) => key)
2042
- const routedNow = (key: string): boolean => UndefinedOr.match(live, { onUndefined: constFalse, onDefined: (routes) => routes.routes(key) })
2043
- Arr.forEach(Arr.filter(toStyle, routedNow), (key) => handBack(key))
2044
- const handedBack = Arr.filter(toStyle, Predicate.not(routedNow))
2045
- if (Arr.isReadonlyArrayEmpty(handedBack)) return
2046
- // The gate writes the user's current value back, as the element's `style` would
2047
- // (ADR-0034). A key gone from the user's style by now is cleared, not restored stale.
2048
- const restore = UndefinedOr.map(styleNow, (now) => {
2049
- const style = now()
2050
- return Object.fromEntries(
2051
- Arr.map(handedBack, (key) => [key, Option.match(OwnValues.styleValueOf(style, key), { onNone: () => "", onSome: (value) => String(value) })]),
2052
- ) as Record<string, string>
2053
- })
2054
- gate.release(id, handedBack, restore)
2055
- Arr.forEach(handedBack, (key) => {
2056
- delete snapshot.values[key]
2057
- delete snapshot.velocities[key]
2058
- if (Predicate.isNotUndefined(presence)) delete presence.snapshot.current[key]
2059
- })
2060
- }
2061
-
2062
- // Cold path: once per Retarget that started a key from its Base value or returned one,
2063
- // run at the head of that Retarget's first leg (no fiber of its own: forking one per
2064
- // element cost 10-20 µs each at a 1000-element mount).
2065
- const baseLog = (started: Record<string, string>, returns: ReadonlyArray<readonly [string, BaseValue.BaseSource]>): Effect.Effect<void> =>
2066
- Effect.logDebug("wardic.base: a key with no value started from, or returned to, its Base value (ADR-0022)").pipe(
2067
- Effect.annotateLogs({ id, started, returned: Object.fromEntries(returns) }),
2068
- )
2069
-
2070
- // Each key's leg (#325, Motion's per-key rule): the running leg that draws it, or the last one that
2071
- // did, landed. A Retarget leaves a key its running leg when it resolves it to the same target, starts
2072
- // none for a key whose last leg landed there, and starts every other key afresh. Each leg has its
2073
- // own token (#200, ADR-0027 *Amendment (#200)*), ended once it has no key left: Superseded, not
2074
- // interrupted, so off the loop at once and its fiber ended normally, at about a sixth of an
2075
- // interrupt's cost.
2076
- const owners: Owners = new Map()
2077
- // The keys an Imperative animation took (#433), each with the target the Override stack had for it
2078
- // then: a Retarget leaves each where the animation leaves it while its target is still that one, and
2079
- // takes it back once it isn't, as a newer animation of Motion's value takes it (latest-wins).
2080
- // Every element reads it, nearly none sets it (#460): the shared empty one until the first key taken.
2081
- let taken: Map<string, number | string | undefined> = NONE_TAKEN
2082
- // The legs that gave up a key in this Retarget: what each still draws is worked out at its end.
2083
- const losing: Array<Running> = []
2084
- // The landing every running leg counts toward: the last Retarget's.
2085
- let current: Landing | undefined
2086
- // A gated Retarget's (ADR-0007 `when`, #325): made at the first.
2087
- let gated: Landing | undefined
2088
- // The variant name the last started Retarget resolved, for its successor's `definition` (#257).
2089
- let lastResolution: Resolution | undefined
2090
- // The Controls change (#433) it last joined, whether it's still counted there (until a landing),
2091
- // and the one its last started Retarget ran for: only the first runs on its override.
2092
- let joined: ControlsChange | undefined
2093
- let counted = false
2094
- let startedChange: ControlsChange | undefined
2095
- /** Its Retargets' change is `change` now: it leaves the last, and joins this one, held or not. */
2096
- const joinChange = (change: ControlsChange | undefined): void => {
2097
- if (counted) leave(joined as ControlsChange)
2098
- joined = change
2099
- counted = Predicate.isNotUndefined(change)
2100
- if (counted) join(change as ControlsChange)
2101
- }
2102
- /** It landed, or can't (a leg failed, its unmount): it leaves its change. */
2103
- const leaveChange = (): void => {
2104
- if (!counted) return
2105
- counted = false
2106
- leave(joined as ControlsChange)
2107
- }
2108
- /** It landed: it leaves its change once the gate has flushed its last frame, unless it joined another meanwhile. */
2109
- const leaveAfterFlush = (): void => {
2110
- if (!counted) return
2111
- const change = joined
2112
- gate.afterFlush(() => {
2113
- if (joined === change) leaveChange()
2114
- })
2115
- }
2116
-
2117
- // The element's waiting Transition ends (#508), made at its first: most elements never have one.
2118
- let waiting: WaitingEnds | undefined
2119
-
2120
- // A leg with no key left ends. Its fiber ends inline (ADR-0027, *Amendment (#200)*); one its token
2121
- // didn't reach, none of its runs on the loop, is interrupted. A Transition end it is (#508) is
2122
- // dropped, written never, as its leg was.
2123
- const endLeg = (running: Running): void => {
2124
- Supersede.end(running.supersede)
2125
- if (Predicate.isNotUndefined(waiting)) waiting.drop(running)
2126
- const fiber = running.fiber
2127
- if (Predicate.isUndefined(fiber)) return
2128
- if (Predicate.isNotUndefined(fiber.pollUnsafe())) return
2129
- // Interrupted here, nothing waiting on its end, as `runCallback`'s interruptor does: a forked
2130
- // `Fiber.interrupt` was a fiber of its own per ended leg (#618, L2).
2131
- fiber.interruptUnsafe()
2132
- }
2133
-
2134
- // A leg takes its keys (#325): each key's owner from now on. One callback a spine, not one a leg.
2135
- let owning: Running | undefined
2136
- const ownKey = (key: string): void => {
2137
- owners.set(key, owning)
2138
- }
2139
- const own = (running: Running): void => {
2140
- const keys = Rec.keys(running.targets)
2141
- running.count = keys.length
2142
- owning = running
2143
- Arr.forEach(keys, ownKey)
2144
- }
2145
-
2146
- // The legs drawing each key: a running leg's velocity is read from it (#464).
2147
- snapshot.owners = owners
2148
- // Its time, its provider's Clock's (#460, Q7).
2149
- snapshot.now = clockNowOf(runtime)
2150
- // Each key's velocity, at the time the Retarget or Imperative animation reading it read (#464).
2151
- let readAt = 0
2152
- const readVelocity: Velocities = (key) => velocityAt(snapshot, owners.get(key), key, readAt)
2153
-
2154
- // `key`'s leg gives it up: a leg ends with its last key, and draws only the rest before.
2155
- const giveUp = (key: string, running: Running): void => {
2156
- letGo(snapshot, key, running)
2157
- owners.set(key, undefined)
2158
- if (running.done) return
2159
- running.count--
2160
- if (running.count === 0) return endLeg(running)
2161
- if (running.losing) return
2162
- running.losing = true
2163
- losing.push(running)
2164
- }
2165
-
2166
- // The keys the Retarget being worked out resolves, for `giveUpUnresolved`: one callback a spine,
2167
- // not one a Retarget.
2168
- let resolvedNow: Values.Values = NO_VALUES
2169
- // Whether `running` is whole: it still draws every key it was started for, each held now, resolved
2170
- // by the Retarget being worked out or taken by its Imperative animation. A key its Retarget didn't
2171
- // resolve, a Path's turn or the axis its target leaves out (#438), is the leg's own: not counted.
2172
- const holdsWhole = (running: Running): boolean =>
2173
- Arr.every(Rec.keys(running.targets), (key) => {
2174
- if (taken.has(key)) return owners.get(key) === running
2175
- if (Bool.not(Object.hasOwn(running.resolution.resolved, key))) return true
2176
- return Bool.and(owners.get(key) === running, Object.hasOwn(resolvedNow, key))
2177
- })
2178
- const giveUpUnresolved = (owner: Running | undefined, key: string): void => {
2179
- if (Predicate.isUndefined(owner)) return
2180
- // An Imperative animation's key (#433) is its own while taken.
2181
- if (taken.has(key)) return
2182
- if (Object.hasOwn(resolvedNow, key)) return
2183
- if (Object.hasOwn(owner.resolution.resolved, key)) return giveUp(key, owner)
2184
- // A key its leg draws though its own Retarget didn't resolve it rides on with that leg while the
2185
- // leg is whole (#460, ADR-0065): a Retarget of another key leaves a Path as it was. Once the leg
2186
- // loses a key, its turn goes back to 0 (`turnBack`) and an axis its target left out stays.
2187
- if (holdsWhole(owner)) return
2188
- giveUp(key, owner)
2189
- }
2190
-
2191
- // A Path's turn goes back to 0 once no leg draws it (#460, ADR-0065 decision 3): after a Retarget
2192
- // whose legs don't turn, a stop, a cancel. Most elements never turn: a guard.
2193
- const turnBack = (): void => {
2194
- const turn = snapshot.values[PATH_ROTATION]
2195
- if (Bool.or(Predicate.isUndefined(turn), turn === 0)) return
2196
- if (Predicate.isNotUndefined(owners.get(PATH_ROTATION))) return
2197
- snapshot.values = { ...snapshot.values, ...TURNED_BACK }
2198
- snapshot.velocities = { ...snapshot.velocities, [PATH_ROTATION]: 0 }
2199
- snapshot.drawnAt[PATH_ROTATION] = snapshot.now()
2200
- gate.write(id, TURNED_BACK)
2201
- recordFrame(TURNED_BACK)
2202
- }
2203
-
2204
- // Each leg that gave up keys draws the ones it kept from now on: once per such leg, a Retarget.
2205
- const keepTheRest = (): void => {
2206
- if (losing.length === 0) return
2207
- Arr.forEach(losing, (running) => {
2208
- running.losing = false
2209
- if (running.count === 0) return
2210
- const kept = Arr.filter(Rec.keys(running.targets), (key) => owners.get(key) === running)
2211
- running.values = keepingOnly(kept)
2212
- })
2213
- losing.length = 0
2214
- }
2215
-
2216
- /**
2217
- * Where `key` starts toward `like` (ADR-0024, D1; ADR-0022, D3): its Snapshot value, coerced to its
2218
- * target's shape; one of another type on a positional key as it is, a Measured pair (#430); else
2219
- * its Base value's start link, read at its first need, noted in `started`; with none, at its target
2220
- * (no motion). Guards, not a match: per key, per Retarget, and a key with a value builds nothing.
2221
- */
2222
- const startKey = (key: string, like: number | string, started: Record<string, string>): void => {
2223
- const coerced = OwnValues.valueLike(snapshot.values[key], like)
2224
- if (Option.isSome(coerced)) snapshot.values[key] = coerced.value
2225
- // A start of another type than its target's, on a positional key, stays as it is: a Measured
2226
- // pair (#430), measured at the end of the task.
2227
- if (Option.isSome(coerced)) return
2228
- if (keepsStart(key, snapshot.values[key], like)) return
2229
- const link = startLinkOf(key, like)
2230
- if (Option.isSome(link) && isSameKind(link.value.value, like)) {
2231
- snapshot.values[key] = link.value.value
2232
- started[key] = link.value.source
2233
- return
2234
- }
2235
- snapshot.values[key] = like
2236
- started[key] = "target"
2237
- }
2238
-
2239
- // A key's leg ended by a failure (#257 item 4): nothing draws its keys, so a later Retarget starts them afresh.
2240
- const forget = (running: Running): void =>
2241
- Arr.forEach(Rec.keys(running.targets), (key) => {
2242
- if (owners.get(key) !== running) return
2243
- letGo(snapshot, key, running)
2244
- owners.set(key, undefined)
2245
- })
2246
-
2247
- /**
2248
- * A leg's run into its sink: one dispatcher, each sink built for the leg that needs it, a
2249
- * Retarget's and an Imperative animation's (#433). A blend's machine is built under the element's
2250
- * Key rules when its change holds a Variable value (`variables`, #542).
2251
- */
2252
- const legProgram = (leg: Leg, running: Running, variables: boolean): Effect.Effect<unknown, never, WardicServices> => {
2253
- if (leg._tag === "Follow") {
2254
- const key = leg.key
2255
- const out: Record<string, number> = { [key]: 0 }
2256
- // Per leg (#460): Machine's calls data-first; per frame, statements.
2257
- return Effect.suspend(() =>
2258
- Machine.run(leg.machine(), (frame) => {
2259
- out[key] = frame.value
2260
- snapshot.values[key] = frame.value
2261
- let velocity = frame.velocity
2262
- if (Predicate.isUndefined(velocity)) velocity = 0
2263
- snapshot.velocities[key] = velocity
2264
- gate.write(id, out)
2265
- recordFrame(out)
2266
- drew(running, frame.done, snapshot.now())
2267
- if (frame.done) landEndsOf(waiting)
2268
- return undefined
2269
- }, running)
2270
- )
2271
- }
2272
- if (leg._tag === "Numbers") {
2273
- return Effect.suspend(() =>
2274
- Machine.run(leg.machine(), (frame) => {
2275
- // MULTI-OWNER MERGE (ADR-0004): merge the spring's keys into the snapshot
2276
- // rather than replacing it, so the drag's direct-set x/y survive alongside the
2277
- // spring's keys (drag owns x/y, spring owns the rest) and the post-drag
2278
- // handoff continues from the rested position. Only the keys it still draws (#325).
2279
- // In place, as the Follow sink writes (#659): a spread made two records per element per
2280
- // frame. The Snapshot's records are always its own (`snapshotOf`, `emptySnapshotOf`), and
2281
- // whatever keeps one copies it or reads it at once.
2282
- const value = running.values(frame.value)
2283
- Object.assign(snapshot.values, value)
2284
- // Its velocities stay on its Frame (#663), read by index when one is asked for: copied into
2285
- // the Snapshot each frame, they cost a boxed number a key a frame that only a Retarget read.
2286
- running.physics = frame
2287
- gate.write(id, value)
2288
- recordFrame(value)
2289
- drew(running, frame.done, snapshot.now())
2290
- if (frame.done) {
2291
- // Landed, its keys are at rest: the Snapshot says so for whatever reads it after it's gone.
2292
- Arr.forEach(Rec.keys(value), (key) => {
2293
- snapshot.velocities[key] = 0
2294
- })
2295
- landEndsOf(waiting)
2296
- }
2297
- return undefined
2298
- }, running)
2299
- )
2300
- }
2301
- // A snap's or a blend's frames: merged into the Snapshot (ADR-0004), as the spring's are. A blend's
2302
- // last two are kept, its keys' velocities read from them (#464): the frame's own values, which a
2303
- // blend makes anew each frame (`values` writes one object for a leg that lost keys).
2304
- const sink = (frame: Frame.Frame<Values.Values>): undefined => {
2305
- const value = running.values(frame.value)
2306
- let before = running.last
2307
- let beforeAt = running.lastAt
2308
- // Its first frame: from the Snapshot's values, a nominal frame before it.
2309
- if (Predicate.isUndefined(before)) {
2310
- before = snapshot.values
2311
- beforeAt = snapshot.now() - NOMINAL_FRAME
2312
- }
2313
- running.before = before
2314
- running.beforeAt = beforeAt
2315
- running.last = frame.value
2316
- snapshot.values = { ...snapshot.values, ...value }
2317
- gate.write(id, value)
2318
- recordFrame(value)
2319
- drew(running, frame.done, snapshot.now())
2320
- if (frame.done) landEndsOf(waiting)
2321
- return undefined
2322
- }
2323
- if (leg._tag === "Snap") {
2324
- // A snapped key comes to rest, so a later spring starts it at rest.
2325
- snapshot.velocities = { ...snapshot.velocities, ...Rec.fromEntries(Arr.map(leg.keys, (key) => [key, 0] as const)) }
2326
- return Effect.suspend(() => Machine.run(leg.machine(), sink, running))
2327
- }
2328
- // Per leg (#460): a statement, Effect's calls data-first.
2329
- let built = Effect.suspend(leg.machine)
2330
- if (variables) built = InterpolatorRegistry.withKeyRules(built, elementRules)
2331
- return Effect.flatMap(built, (machine) => Machine.run(machine, sink, running))
2332
- }
2333
-
2334
- // A leg's end, told its landing: a Retarget's legs' and an Imperative animation's (#433).
2335
- const legEnded = (running: Running) => (exit: Exit.Exit<unknown>): Effect.Effect<void> => {
2336
- // Its fiber has ended, and is let go: a leg kept for its keys' velocity (#464) keeps no fiber alive.
2337
- running.fiber = undefined
2338
- // Per leg (#460): statements.
2339
- if (Exit.isSuccess(exit)) {
2340
- // A Superseded leg (#200) counts toward nothing, nor tells a name: the next Retarget's legs
2341
- // land. Nothing made for it: a Retarget ends its element's legs inline.
2342
- const end = exit.value
2343
- if (Supersede.isSuperseded(end)) return Effect.void
2344
- return Effect.sync(() => {
2345
- running.landing.settled()
2346
- const tell = running.names
2347
- if (Predicate.isNotUndefined(tell)) tell(end)
2348
- })
2349
- }
2350
- // A leg its token didn't reach is interrupted: its keys are given up already, and it isn't a failure.
2351
- const cause = exit.cause
2352
- if (Cause.hasInterruptsOnly(cause)) return Effect.void
2353
- return Report.failure("wardic.spine: a leg failed", cause).pipe(
2354
- Effect.annotateLogs({ id }),
2355
- Effect.andThen(Effect.sync(() => {
2356
- forget(running)
2357
- running.landing.failed(cause)
2358
- })),
2359
- )
2360
- }
2361
-
2362
- // A gated Retarget (ADR-0007 `when`, #325): a running key it resolves to its leg's target runs on,
2363
- // the element reported unsettled meanwhile, when an earlier change started that leg; every other
2364
- // running key freezes where it is. The change the gate holds may have started legs just before
2365
- // it shut (a child Retargets before its provider's effect resets its `beforeChildren` wait; an
2366
- // `afterChildren` provider starts before its children report): those freeze too, as before.
2367
- const hold = (resolution: Resolution): void => {
2368
- if (Predicate.isUndefined(gated)) gated = gatedLandingOf(onFrame)
2369
- const landing = gated
2370
- const resolved = resolution.resolved
2371
- current = landing
2372
- owners.forEach((running, key) => {
2373
- if (Predicate.isUndefined(running)) return
2374
- if (running.done) return
2375
- // An Imperative animation's key (#433) is its own while taken.
2376
- if (taken.has(key)) return
2377
- if (Object.hasOwn(resolved, key) && running.targets[key] === resolved[key] && !sameResolution(running.resolution, resolution)) {
2378
- running.landing = landing
2379
- running.names = undefined
2380
- return
2381
- }
2382
- giveUp(key, running)
2383
- })
2384
- keepTheRest()
2385
- }
2386
-
2387
- // The translate targets of the last Retarget that ran, held or not: what a takeover of the drag's
2388
- // release looks for a change in (#340).
2389
- let lastX: number | string | undefined = undefined
2390
- let lastY: number | string | undefined = undefined
2391
- // A Retarget took `x`/`y` from the release, and the hand-back of `dragging` hasn't come yet.
2392
- let tookRelease = false
2393
- /**
2394
- * Whether the drag holds `x`/`y` for this Retarget (ADR-0004): while its pointer is down and
2395
- * through its release, unless this Retarget gives the release's axis a new target. Then it takes
2396
- * them from the release (#340, ADR-0016 *Amendment (#340)*), as a newer animation of Motion's value
2397
- * stops the one running, and they go on from where the release has them, at its velocity. A key a
2398
- * entry stops setting is no new target: it stays where the drag dropped it (ADR-0022).
2399
- */
2400
- const dragHolds = (resolution: Resolution): boolean => {
2401
- const { x, y } = resolution.resolved
2402
- // Per Retarget (#460, compose once): statements.
2403
- const newX = Predicate.isNotUndefined(x) && x !== lastX
2404
- const newY = Predicate.isNotUndefined(y) && y !== lastY
2405
- lastX = x
2406
- lastY = y
2407
- if (!resolution.dragging) return false
2408
- // From a takeover to the hand-back of `dragging` at the end of its task, the drag holds nothing.
2409
- if (tookRelease) return false
2410
- const drag = options.drag
2411
- if (Predicate.isUndefined(drag)) return true
2412
- if (!newX && !newY) return true
2413
- tookRelease = drag.takeRelease({ x: newX, y: newY })
2414
- return !tookRelease
2415
- }
2416
-
2417
- // --- A Batch member's element (#665's PR 4, ADR-0069 decision 17, Q52–Q54) -----------------------
2418
-
2419
- // Its hold on what it takes from its Batch: made as its element is first found a member's, at a
2420
- // Retarget or a drag. Nearly no element is one: the rest pay a WeakMap read a Retarget.
2421
- let memberHold: MemberHold | undefined
2422
- const holdNow = (): MemberHold | undefined => {
2423
- if (Predicate.isNotUndefined(memberHold)) return memberHold
2424
- // An app with no Batch has no way to make one, nor any member.
2425
- const holds = memberHoldsNow()
2426
- if (Predicate.isUndefined(holds)) return undefined
2427
- if (!holds.isMember(element)) return undefined
2428
- memberHold = holds.make({
2429
- element,
2430
- gate,
2431
- id,
2432
- snapshot,
2433
- // Per held group at a leg's end or a Batch change (#665): statements.
2434
- running: (which) => {
2435
- let runs = false
2436
- Iter.forEach(owners, ([key, running]) => {
2437
- if (Predicate.isUndefined(running)) return
2438
- if (running.done) return
2439
- if (which(key)) runs = true
2440
- })
2441
- return runs
2442
- },
2443
- // Setting a visited key is safe in a Map's iteration.
2444
- giveUp: (which) => {
2445
- Iter.forEach(owners, ([key, running]) => {
2446
- if (Predicate.isUndefined(running)) return
2447
- if (which(key)) giveUp(key, running)
2448
- })
2449
- keepTheRest()
2450
- },
2451
- velocityOf: (key, now) => velocityAt(snapshot, owners.get(key), key, now),
2452
- forget: (key) => {
2453
- driven.delete(key)
2454
- returning.delete(key)
2455
- },
2456
- })
2457
- return memberHold
2458
- }
2459
- // A draggable element's drag tells it as it holds `x`/`y` and hands them back: a member's hold hears.
2460
- if (Predicate.isNotUndefined(options.dragAxis)) {
2461
- DRAG_HOOKS.set(element, (on) => {
2462
- const member = holdNow()
2463
- if (Predicate.isNotUndefined(member)) member.drag(on)
2464
- })
2465
- }
2466
-
2467
- const retarget = (given: Resolution): void => {
2468
- // A Controls change (#433): the element is in it from the Retarget it makes it run, held or not.
2469
- if (given.change !== joined) joinChange(given.change)
2470
-
2471
- // `when` start-gate (ADR-0007): when canStart() is false, the keys whose target changed freeze
2472
- // where they are (#325: the rest run on), and the element waits; the binding retargets once
2473
- // the gate flips true.
2474
- if (Predicate.isNotUndefined(canStart) && !canStart()) {
2475
- hold(given)
2476
- // Report NOT settled: a gated child sits at its snapshot, still
2477
- // owing an animation, so it must not count as settled (afterChildren).
2478
- if (Predicate.isNotUndefined(onFrame)) onFrame(false)
2479
- return
2480
- }
2481
- // The first Retarget a Controls change starts here runs on its override (#433); a later one, a
2482
- // gesture's, on the targets' own.
2483
- let resolution = given
2484
- // On an override, every key starts again on it, a running leg toward the same target too: `set`
2485
- // lands it at once, as Motion's.
2486
- let restarting = false
2487
- if (given.change !== startedChange) {
2488
- startedChange = given.change
2489
- const override = UndefinedOr.map(given.change, (change) => change.override)
2490
- if (Predicate.isNotUndefined(override)) {
2491
- resolution = overriddenOf(given, override)
2492
- restarting = true
2493
- }
2494
- }
2495
- const { resolved, base } = resolution
2496
- // The hand-back of `dragging` after a takeover (#340): the last Retarget already ran with `x`/`y`
2497
- // its own, so one that changes nothing else is no new animation, as Motion's has none. It goes
2498
- // on, and lands and is told as itself.
2499
- if (tookRelease && !resolution.dragging) {
2500
- tookRelease = false
2501
- if (handsBackOnly(resolution, lastResolution)) {
2502
- lastResolution = resolution
2503
- return
2504
- }
2505
- }
2506
- const held = dragHolds(resolution)
2507
- // The keys an Imperative animation took (#433): one whose target here isn't the one it had when
2508
- // taken is the Override stack's again.
2509
- if (taken.size > 0) Iter.forEach(taken, ([key, was]) => {
2510
- if (resolved[key] !== was) taken.delete(key)
2511
- })
2512
-
2513
- // A key a Retarget drove and no entry sets now returns to its Base value
2514
- // (ADR-0022); with none, it stays where it is (as before #47).
2515
- const t: Values.Values = { ...resolved }
2516
- Arr.forEach(Rec.keys(resolved), (key) => {
2517
- driven.set(key, resolved[key])
2518
- })
2519
- if (held) Arr.forEach(dragMoves(), (key) => driven.delete(key))
2520
- returning = new Map()
2521
- // Over the Map itself: copying it into an array first costs ~20 times the walk, per element
2522
- // per Retarget (#69's PR 4). Deleting the entry being visited is safe in a Map's iteration.
2523
- Iter.forEach(driven, ([key, like]) => {
2524
- // A translate key the strip below holds back returns once the drag lets go.
2525
- if (Object.hasOwn(resolved, key) || (held && TRANSLATE_KEYS.has(key))) return
2526
- // One an Imperative animation holds (#433) stays where it leaves it.
2527
- if (taken.has(key)) return
2528
- const back = BaseValue.of(key, { base, initial: initialLink, started: startedLink, ...linksFor(like) })
2529
- if (Option.isNone(back)) {
2530
- driven.delete(key)
2531
- return
2532
- }
2533
- t[key] = back.value.value
2534
- returning.set(key, back.value.source)
2535
- })
2536
- // MULTI-OWNER strip (ADR-0004): while dragging, x/y are DIRECT-SET by the
2537
- // drag track, so strip the translate keys from the spring's target — the
2538
- // spring must never fight the direct-set. Once dragging is false the
2539
- // keys re-enter normally (post-drag handoff: the spring continues x/y only
2540
- // if `animate` sets them, from the snapshot's rested position).
2541
- if (held) Arr.forEach(TRANSLATE_KEY_LIST, (key) => delete t[key])
2542
- // Every key an Imperative animation holds stays where it leaves it (#433).
2543
- if (taken.size > 0) Iter.forEach(taken, ([key]) => {
2544
- delete t[key]
2545
- })
2546
- // A Batch member's element (#665's PR 4, Q53): a group it moves is taken from its Batch first, and a
2547
- // key it'd leave where the Batch draws it stays the Batch's. A drag takes `x` and `y`.
2548
- const member = holdNow()
2549
- if (Predicate.isNotUndefined(member)) member.retarget(t, held)
2550
- // The keys this Retarget returns; once it lands, a key back at its `style` value is
2551
- // handed back to the element's style (D4) and the rest rest inline.
2552
- const returns = [...returning]
2553
- // The transition, read at Retarget time so a change applies to the next Retarget. A child
2554
- // with no local transition inherits the parent context's (ADR-0007).
2555
- const c = config()
2556
-
2557
- // This Retarget's landing (#257, #325): it lands when every leg drawing a key it resolves has
2558
- // settled, its own and the ones it carries. A leg's end, told apart (ADR-0027, decision 7): a
2559
- // settle counts; a Superseded end (a Retarget, an unmount, #200) or an interruption (a leg its
2560
- // token didn't reach) is nothing; anything else (a step or a sink that threw, the Frame loop's
2561
- // own failure) is logged and reported (ADR-0030, decision 4), and doesn't count.
2562
- let legs = 0
2563
- // The variant the Retarget before this one resolved, set once this one starts (#257).
2564
- let previous: Resolution | undefined
2565
- const legDone = (): void => {
2566
- if (current !== landing) return
2567
- // A Batch member's groups go back as their last legs end (Q54), each on its own.
2568
- if (Predicate.isNotUndefined(memberHold)) memberHold.settle()
2569
- if (--legs !== 0) return
2570
- settleReturns(returns)
2571
- // The Retarget settled with its last leg (#257): told once the gate has flushed its last frame,
2572
- // so the element shows where it landed. Its Controls change hears it then too (#433).
2573
- if (Predicate.isNotUndefined(animation)) gate.afterFlush(() => animation.settled(resolution, previous, c))
2574
- leaveAfterFlush()
2575
- }
2576
- // A leg's failure (#257 item 4): the Retarget can't land, so a binding waiting on it is told,
2577
- // once, at once: a leg that fails before it writes leaves no flush to wait for. A leg failing
2578
- // as it's built, before `started` is told, is told right after it.
2579
- let failedTold = false
2580
- let startedTold = false
2581
- let failedEarly: { readonly error: unknown } | undefined
2582
- const tellFailed = (error: unknown): void => {
2583
- const hooks = animation as AnimationHooks
2584
- // Called on its hooks, which may be a class's: not taken off them.
2585
- if (Predicate.isNotUndefined(hooks.failed)) hooks.failed(resolution, error)
2586
- }
2587
- const legFailed = (cause: Cause.Cause<unknown>): void => {
2588
- // It can't land: its Controls change waits for it no longer (#433).
2589
- if (current === landing) leaveChange()
2590
- if (failedTold || Predicate.isUndefined(animation)) return
2591
- failedTold = true
2592
- const error = Cause.squash(cause)
2593
- if (startedTold) return tellFailed(error)
2594
- failedEarly = { error }
2595
- }
2596
- // The element settles with its last leg (ADR-0024, D5): a string leg can outlast the
2597
- // numeric one, so each leg's frames report, and only the last leg's settle reports done.
2598
- let reporting = 0
2599
- let settled = 0
2600
- const report = (done: boolean): void => {
2601
- if (done) settled++
2602
- if (Predicate.isNotUndefined(onFrame)) onFrame(settled === reporting)
2603
- }
2604
- const landing: Landing = { report, settled: legDone, failed: legFailed }
2605
- current = landing
2606
-
2607
- // The Retarget's transitions, read before its keys: a key already there asks its own for a
2608
- // velocity (#448).
2609
- const elementTransition = ownOrInherited(c.transition, parent)
2610
- // The base target's own transition (#277): the keys its entry drives animate on it.
2611
- const baseTransition = transitionOfTarget(resolution.transition, elementTransition)
2612
- // Fold the per-child stagger delay (ADR-0007) into the effective
2613
- // transition.delay = base.delay + computedDelay. extraDelay() is read
2614
- // at Retarget time so a re-snapshot before this start is reflected. Each name's keys take that
2615
- // name's delay (#297): the base's, its first name's.
2616
- const layers = resolution.layers
2617
- const extra = extraOf(extraDelay, layers[0])
2618
- const transition = staggeredOf(baseTransition, extra, options.reuse)
2619
- // With an entry's own transition (#277, #291), each key animates on its entry's: the base's keys
2620
- // on the base target's, each active gesture's on its target's, else the element's, as Motion's
2621
- // each animation type runs on its own.
2622
- // A list's names (#297) split them too, each name's at its own delay; a list's returns run on the
2623
- // element's transition, in a group of their own, last.
2624
- // Guards, not matches: per Retarget, per element. A list's work (#297) is done apart, for a list:
2625
- // the Retarget's other calls keep their inlining (docs/agents/effect-first.md).
2626
- const listed = Arr.isArray(resolution.variant)
2627
- // A list's names each wait for their own `when` (#297's PR 2): the entries whose gate is shut now.
2628
- let shut: ReadonlyArray<boolean> | undefined
2629
- if (listed) shut = shutOf(layers, byName)
2630
- // Every key the Retarget resolves goes in its entry's group, the ones that stay too (#325): a
2631
- // name's settle waits for them.
2632
- const groups = keysByLayerOf(t, layers, extraDelay, extra, listed, shut)
2633
- // Per key (#325, Motion's): a key whose running leg heads where this Retarget resolves it runs
2634
- // on, counted toward this landing; one whose last leg landed there stays; every other's leg
2635
- // gives it up, and it starts from its Snapshot value, coerced to its target's shape (ADR-0024,
2636
- // D1). A key with no value yet, or one whose value can't take that shape, starts from its Base
2637
- // value's start links, read here at its first need (ADR-0022, D3); with none, it starts at its
2638
- // target (no motion).
2639
- //
2640
- // Every key's Own value is read first, at its first need, before anything writes it, so a return
2641
- // later finds the element's value, not Wardic's (ADR-0022, D3). The read is kept: a later need is
2642
- // a lookup. A transform key reads nothing.
2643
- let stays: Set<string> | undefined
2644
- let carried: Array<Running> | undefined
2645
- let there: Record<string, number | string> | undefined
2646
- const started: Record<string, string> = {}
2647
- // Each key's Keyframes (#429), when any entry gives some: a key's carries on only toward the same.
2648
- const keyframesNow = resolution.keyframes
2649
- // The keys whose two ends may be a Measured pair (#430), found in the pass below.
2650
- let measuring: Array<string> | undefined
2651
- // Each key's velocity, read now (#464), for a key a spring starts or one already there.
2652
- readAt = snapshot.now()
2653
- // Where a Path's axis this target leaves out rests (#574), before the pass below gives up its leg.
2654
- const rests = restsOf(owners, t)
2655
- Arr.forEach(Rec.keys(t), (key) => {
2656
- if (!Object.hasOwn(initialValues, key)) ownValue(key)
2657
- const like = t[key]
2658
- const owner = owners.get(key)
2659
- const stops = keyframesAtOf(keyframesNow, key)
2660
- // A leg drawing it toward another target: it's moving, so it's never already there (#448).
2661
- let drawn = false
2662
- if (Predicate.isNotUndefined(owner)) {
2663
- drawn = !owner.done
2664
- // A key whose Transition end changed starts again (#470), as Motion's value does, its end in
2665
- // its resolved values.
2666
- if (owner.targets[key] === like && !restarting && sameKeyframesAt(keyframesAtOf(owner.resolution.keyframes, key), stops) && !endMoved(lastResolution, resolution, key)) {
2667
- if (Predicate.isUndefined(stays)) stays = new Set()
2668
- stays.add(key)
2669
- if (owner.done || owner.landing === landing) return
2670
- owner.landing = landing
2671
- owner.names = undefined
2672
- legs++
2673
- reporting++
2674
- if (Predicate.isUndefined(carried)) carried = []
2675
- carried.push(owner)
2676
- return
2677
- }
2678
- giveUp(key, owner)
2679
- }
2680
- startKey(key, like, started)
2681
- // A Measured pair (#430): its two ends of different types, found in this pass, so a Retarget
2682
- // with none builds nothing for them.
2683
- if (MeasuredPair.needs(key, UndefinedOr.getOrThrow(snapshot.values[key]), like)) {
2684
- if (Predicate.isUndefined(measuring)) measuring = []
2685
- measuring.push(key)
2686
- }
2687
- // Already there (#448, Motion's `visual-element-target.ts`): a key at its target, coerced to its
2688
- // shape, with no leg drawing it, at rest and given no velocity by its transition, starts none.
2689
- // It stays, as a carried key does, and is written once more (below), as Motion sets it on the
2690
- // next frame. One that started at its target had no value to show, so its leg writes it, as
2691
- // Motion's does for a value it has none of. Keyframes are never there (#429): they play.
2692
- // Its velocity read last, for a key there alone (#464): per key, per Retarget.
2693
- let still = !drawn && started[key] !== "target"
2694
- if (still) still = snapshot.values[key] === like
2695
- if (still) still = readVelocity(key) === 0
2696
- // Its transition asked last, for a key already there alone: per key, per Retarget. A quiet
2697
- // mount's never asks (#475): Motion animates nothing at a first render that starts at its
2698
- // `animate`, whatever velocity its transition gives (`animation-state.ts`, `shouldAnimate`).
2699
- if (still && Predicate.isUndefined(stops) && (quiet || !givesVelocity(keyTransitionOf(resolution, groups, key, transition, elementTransition), key))) {
2700
- if (Predicate.isUndefined(stays)) stays = new Set()
2701
- stays.add(key)
2702
- if (Predicate.isUndefined(there)) there = {}
2703
- there[key] = like
2704
- }
2705
- // A quiet mount's Keyframes (#429): Motion animates nothing at a first render that starts at its
2706
- // `animate`, so they stay where they start, `animate`'s last stop with `initial={false}`.
2707
- if (quiet && Predicate.isNotUndefined(stops)) {
2708
- if (Predicate.isUndefined(stays)) stays = new Set()
2709
- stays.add(key)
2710
- if (Predicate.isUndefined(there)) there = {}
2711
- there[key] = UndefinedOr.getOrThrow(snapshot.values[key])
2712
- }
2713
- })
2714
- // A key no longer resolved (one the drag holds, or one with no Base value) is given up: it stays
2715
- // where it is.
2716
- resolvedNow = t
2717
- owners.forEach(giveUpUnresolved)
2718
- keepTheRest()
2719
- // The keys this Retarget starts legs for: all of them, unless some stay.
2720
- let fresh: Values.Values = t
2721
- if (Predicate.isNotUndefined(stays)) {
2722
- const kept = stays
2723
- fresh = Rec.filter(t, (_, key) => !kept.has(key))
2724
- // A Path couples `x` and `y` (#438): either retargeted, the other goes along it to its target.
2725
- fresh = withPathAxes(fresh, t, transition)
2726
- }
2727
- // A mount that starts at its `animate`, with nothing to animate, tells no one (#448, Motion's):
2728
- // no start, no landing, and no list's names. It starts no leg, so it lands at once.
2729
- const silent = quiet && Rec.isEmptyRecord(fresh) && Predicate.isUndefined(carried)
2730
- quiet = false
2731
- // A key only a Transition end sets (#428) starts no leg of its own: its entry's end leg holds it
2732
- // where it is, and sets it once the entry's animated keys land.
2733
- const ends = resolution.ends
2734
- let freshEnds: Values.Values = NO_VALUES
2735
- if (Predicate.isNotUndefined(ends)) {
2736
- const endOnly = ends.endOnly
2737
- freshEnds = Rec.filter(fresh, (_, key) => endOnly.has(key))
2738
- if (hasKeys(freshEnds)) fresh = Rec.filter(fresh, (_, key) => !endOnly.has(key))
2739
- }
2740
- let from: Values.Values = Rec.map(fresh, (_, key) => UndefinedOr.getOrThrow(snapshot.values[key]))
2741
- // Keyframes (#429) start at their first stop, a `null` one where the key is; those of more than
2742
- // two stops run through them.
2743
- let manyStops: StopsByKey | undefined
2744
- if (Predicate.isNotUndefined(keyframesNow)) {
2745
- const begun = keyframesFrom(from, fresh, Rec.map(keyframesNow, (at) => at.stops))
2746
- from = begun.from
2747
- manyStops = begun.stops
2748
- }
2749
- // Each leg: the base-value log at the head of the first, and, once the leg's run
2750
- // settles, a count toward this landing, so the per-frame handlers stay as they were.
2751
- let pendingLog: Effect.Effect<void> | undefined
2752
- if (returns.length > 0 || !Rec.isEmptyRecord(started)) pendingLog = baseLog(started, returns)
2753
- // A list's names told settled one by one (#297, Solid 1's callbacks): each as the legs of the keys
2754
- // it drives settle. Made only for a list with a binding that's told so.
2755
- let names: NameSettles | undefined
2756
- const leg = <R,>(running: Running, program: Effect.Effect<unknown, never, R>): Effect.Effect<void, never, R> => {
2757
- legs++
2758
- const log = pendingLog
2759
- pendingLog = undefined
2760
- // Per leg (#460): statements, Effect's calls data-first.
2761
- let run: Effect.Effect<unknown, never, R> = program
2762
- if (Predicate.isNotUndefined(log)) run = Effect.andThen(log, program)
2763
- if (Predicate.isNotUndefined(names)) running.names = names.leg()
2764
- return Effect.asVoid(Effect.onExit(run, legEnded(running)))
2765
- }
2766
- // Start a leg: forked on the provider's runtime, which runs it inline up to its add on the
2767
- // loop, so every leg started in a task is on the loop by the end of that task and takes its
2768
- // first step at the next tick (ADR-0027 decision 5, ADR-0033). Forked from a `runSync`, a leg
2769
- // would inherit that call's scheduler (ADR-0027, decision 6). The runtime keeps it in its own
2770
- // fiber Scope, which interrupts it if it's still running when the provider ends (#542).
2771
- // The name the leg being started waits for (#297's PR 2), set as each is started; none for most.
2772
- let gateNow: string | undefined
2773
- const runLeg = <R extends WardicServices>(running: Running, program: Effect.Effect<unknown, never, R>): void => {
2774
- let run: Effect.Effect<unknown, never, R | FrameLoop.FrameLoop> = program
2775
- if (Predicate.isNotUndefined(gateNow)) run = gatedBy(gateNow, byName, running, program)
2776
- running.fiber = runtime.runFork(leg(running, run))
2777
- }
2778
- // The legs (#48, ADR-0044 decision 8): one pure builder, which a server render's Appear
2779
- // animation samples too, so the two can't drift. Built here; each leg's machine is built
2780
- // in its own fiber, so a transition core rejects (#66, ADR-0025 *Amendment (#66)*) fails
2781
- // that leg alone, reported as any leg's failure is, while the element's other legs run on.
2782
- // The returns to a moving Live value (#130, ADR-0043 decision 6): a number's follows it,
2783
- // in a leg of its own, and lands on it; the rest return to where it is now. Looked for
2784
- // only when this Retarget returns a key.
2785
- let follow: Follows | undefined
2786
- if (returning.size > 0 && Predicate.isNotUndefined(live)) {
2787
- const routes = live
2788
- follow = { keysOf: (rest) => followingOf(routes, rest, returning), targetOf: (key, start) => liveTargetOf(routes, key, start) }
2789
- }
2790
- const reduce = options.reducedMotion()
2791
- const skipped = skipAnimations()
2792
- // Measured pairs (#430), asked of the end-of-task batch, unless reduced motion snaps them or the
2793
- // animation is skipped (#468): the keys found above, and those Keyframes of two stops start from their first.
2794
- let measured: MeasuredPairs | undefined
2795
- if (!reduce && !skipped && (Predicate.isNotUndefined(measuring) || Predicate.isNotUndefined(keyframesNow))) {
2796
- measured = measuredOf(element, measuringOf(measuring, keyframesNow), from, fresh, snapshot.values, manyStops)
2797
- }
2798
- let told: ToldNames | undefined
2799
- if (!silent) told = namesToldOf(animation, resolution, lastResolution)
2800
- // Every key on one transition when they aren't split, as before; else each group's legs, tagged.
2801
- // A key that stays starts none, and no keys make no leg (#325).
2802
- let retargetLegs: ReadonlyArray<Leg> = NO_LEGS
2803
- let legGroups: ReadonlyArray<number> | undefined
2804
- if (Predicate.isUndefined(groups) && hasKeys(fresh)) {
2805
- // Where every key is now: a Path's axis the target leaves out starts there (#438), and ends where
2806
- // it rests (#574).
2807
- retargetLegs = legsOf(from, fresh, transition, reduce, skipped, positionalKeys, defaultTransition, readVelocity, follow, manyStops, measured, snapshot.values, rests)
2808
- }
2809
- if (Predicate.isNotUndefined(groups)) {
2810
- const split = splitLegsOf(fresh, from, groups, resolution, listed, transition, elementTransition, extraDelay, options.reuse, reduce, skipped, positionalKeys, defaultTransition, readVelocity, follow, manyStops, measured, snapshot.values, rests)
2811
- retargetLegs = split.legs
2812
- legGroups = split.tags
2813
- }
2814
- // The Handoff (#48, ADR-0044 decision 6): the first Retarget that starts picks the Appear
2815
- // animation up as far in as its CSS has got, read at the legs' first tick.
2816
- if (Predicate.isNotUndefined(handoff)) {
2817
- const taken = handoff
2818
- handoff = undefined
2819
- checkHandoff(runtime, id, taken, { tag, from, to: fresh, transition: baseTransition, reduced: reduce, layout: isLayoutNode(c), stops: manyStops, ...skippedField(skipped), ...templateField(c.transformTemplate) })
2820
- const at = startAtOf(taken, baseTransition, delayOf(transition))
2821
- retargetLegs = Arr.map(retargetLegs, (one) => startingAt(one, at))
2822
- }
2823
- reporting += retargetLegs.length
2824
- // A list's names (#297): told settled with the legs of the keys each drives, the ones a key that
2825
- // stays carries too (#325), to the binding's callbacks and its orchestration, and each shut
2826
- // one's legs waiting on its gate (PR 2).
2827
- let legGates: ReadonlyArray<string | undefined> | undefined
2828
- if (listed || Predicate.isNotUndefined(told)) {
2829
- const carriedLegs = UndefinedOr.match(carried, { onUndefined: (): ReadonlyArray<Running> => NO_RUNNING, onDefined: identity })
2830
- const listing = listingOf({
2831
- listed,
2832
- told,
2833
- byName,
2834
- resolution,
2835
- groups,
2836
- legGroups,
2837
- legCount: retargetLegs.length,
2838
- carriedGroups: Arr.map(carriedLegs, (running) => groupsOfLeg(running, groups, owners)),
2839
- shut,
2840
- hold: (g) => {
2841
- const kept = pickKeys(from, groups, g)
2842
- if (Bool.not(Rec.isEmptyRecord(kept))) gate.write(id, kept)
2843
- },
2844
- afterFlush: (fn) => gate.afterFlush(fn),
2845
- config: c,
2846
- })
2847
- names = listing.names
2848
- legGates = listing.legGates
2849
- UndefinedOr.map(names, (settles) =>
2850
- Arr.forEach(carriedLegs, (running, i) => {
2851
- running.names = settles.carried(i)
2852
- }))
2853
- }
2854
- // Its `style`'s will-change value turns on as a leg starts a key Motion's would (#443).
2855
- turnWillChangeOn(live, retargetLegs)
2856
- // The element's Key rules only for a change a Variable value is in (#542).
2857
- const variables = holdsVariable(from, fresh, manyStops)
2858
- // Each leg into its sink, in the builder's order (#69's PR 2: a Retarget is per element). Each
2859
- // leg draws the keys it animates (#325) until a later Retarget takes them.
2860
- Arr.forEach(retargetLegs, (leg: Leg, i): void => {
2861
- if (Predicate.isNotUndefined(legGates)) gateNow = legGates[i]
2862
- const running = runningOf(leg.to, resolution, landing, leg._tag)
2863
- own(running)
2864
- runLeg(running, legProgram(leg, running, variables))
2865
- })
2866
- // Each entry's Transition end (#428): a leg holding the keys only its end sets where they are,
2867
- // waiting for the keys the entry animates to land (the legs drawing them now, this Retarget's or
2868
- // carried), then setting its end values, the keys it also animates among them. It counts toward
2869
- // this landing, so the landing includes it. A later Retarget that resolves its keys to the same
2870
- // values carries it (#325); one that doesn't gives them up, and it never sets them.
2871
- if (Predicate.isNotUndefined(ends)) {
2872
- gateNow = undefined
2873
- Arr.forEach(ends.byLayer, (writes, at) => {
2874
- if (Predicate.isUndefined(writes)) return
2875
- const owned = Rec.filter(freshEnds, (_, key) => ends.endOnly.get(key) === at)
2876
- // Its end starts again when a key it also animates starts again, or its end for one changed
2877
- // (#470, one already there starts none), or a key only it sets does.
2878
- const anew = Bool.or(
2879
- hasKeys(owned),
2880
- Arr.some(Rec.keys(writes), (key) => Bool.and(Bool.not(ends.endOnly.has(key)), Bool.or(Object.hasOwn(fresh, key), endMoved(lastResolution, resolution, key)))),
2881
- )
2882
- if (Bool.not(anew)) return
2883
- const animated = Arr.filter(Rec.keys(resolved), (key) => Bool.and(Bool.not(ends.endOnly.has(key)), driverOf(layers, key) === at))
2884
- // Its keys set at their end, at once: no motion, so no velocity (#464).
2885
- const running = runningOf(owned, resolution, landing, "Snap")
2886
- own(running)
2887
- // Held where they are: a key with nothing to start from (it would start at its target, no
2888
- // motion) is left unset until its end, not set to it now.
2889
- const holding = Rec.map(Rec.filter(owned, (_, key) => started[key] !== "target"), (_, key) => UndefinedOr.getOrThrow(snapshot.values[key]))
2890
- if (hasKeys(holding)) gate.write(id, holding)
2891
- snapshot.velocities = { ...snapshot.velocities, ...Rec.map(owned, () => 0) }
2892
- // Counted toward this landing as a leg is (#508), with no fiber of its own: the landing of its
2893
- // keys' last leg writes it, or the next flush when they've landed already.
2894
- reporting++
2895
- legs++
2896
- const log = pendingLog
2897
- pendingLog = undefined
2898
- // Forked only where a Debug log is kept (#618); a leg's runs inside the leg's own fiber.
2899
- if (Predicate.isNotUndefined(log)) {
2900
- if (logsDebugOn(runtime)) runtime.runFork(log)
2901
- }
2902
- if (Predicate.isNotUndefined(names)) running.names = names.leg()
2903
- // One that owns no key records the legs it waits for: their interrupt drops it (ADR-0057 Q1).
2904
- let waitsOn: ReadonlyArray<Running | undefined> | undefined
2905
- if (Bool.not(hasKeys(owned))) waitsOn = Arr.map(animated, (key) => owners.get(key))
2906
- if (Predicate.isUndefined(waiting)) waiting = waitingEndsOf(owners, snapshot, gate, id, recordFrame)
2907
- waiting.add({ running, animated, writes, legs: waitsOn, state: "waiting" })
2908
- })
2909
- }
2910
- // A turn none of its legs draws now goes back (#460).
2911
- turnBack()
2912
- // The keys already there (#448), written with each key the Retarget moves at where it starts, as
2913
- // its leg's first frame writes it: the element's first commit, which takes its Starting style off,
2914
- // holds every key, whatever frame the legs first draw in (a gated name's draws later).
2915
- if (Predicate.isNotUndefined(there)) {
2916
- const written = { ...from, ...there }
2917
- gate.write(id, written)
2918
- recordFrame(written)
2919
- }
2920
- // The Retarget started, its legs on their way (#257); with none, its own or carried, it landed
2921
- // at once (#325): its returns settle, and the element reports settled at the gate's next flush,
2922
- // after the effects that start its orchestration's wait (ADR-0007).
2923
- previous = lastResolution
2924
- lastResolution = resolution
2925
- const landed = legs === 0
2926
- if (landed) {
2927
- settleReturns(returns)
2928
- if (Predicate.isNotUndefined(memberHold)) memberHold.settle()
2929
- leaveAfterFlush()
2930
- if (Predicate.isNotUndefined(pendingLog)) {
2931
- if (logsDebugOn(runtime)) runtime.runFork(pendingLog)
2932
- }
2933
- if (Predicate.isNotUndefined(onFrame)) {
2934
- const tell = onFrame
2935
- gate.afterFlush(() => {
2936
- if (current === landing) tell(true)
2937
- })
2938
- }
2939
- }
2940
- if (Predicate.isNotUndefined(animation) && !silent) {
2941
- const hooks = animation as AnimationHooks
2942
- hooks.started(resolution, previous, c)
2943
- startedTold = true
2944
- if (landed) hooks.settled(resolution, previous, c)
2945
- if (Predicate.isNotUndefined(failedEarly)) tellFailed(failedEarly.error)
2946
- }
2947
- }
2948
-
2949
- // --- Live values in `style` (#130, ADR-0043) ------------------------------
2950
- // A routed key (a Live value, or a transform key) is its `style` link, live: while no entry of
2951
- // the Override stack sets it, no return is running to it and no drag moves it, the element
2952
- // follows it, written through the gate on every change. A return hands it back here when it
2953
- // settles (`settleReturns`). The Starting style showed each one's value at render; from mount
2954
- // the gate holds them.
2955
- const follow = (now: FollowNow): void => {
2956
- if (Predicate.isUndefined(live)) return
2957
- const routes = live
2958
- // Built at the first routed key, at mount or later: an element whose `style` routes none builds nothing.
2959
- routes.whenRouted(() => {
2960
- // Read at each ask: `projected` is a getter while the track waits for `drag` (#551, #582).
2961
- const dragHolds = (): boolean => Bool.and(Bool.not(options.projected), Predicate.isNotUndefined(options.dragAxis))
2962
- // Whether something other than the follower moves `key` now.
2963
- const owned = (key: string): boolean =>
2964
- Bool.some([
2965
- driven.has(key),
2966
- Object.hasOwn(now.resolved(), key),
2967
- // An Imperative animation's (#433).
2968
- taken.has(key),
2969
- // The drag direct-sets both translate keys while it, and its release, run (ADR-0004).
2970
- Bool.and(dragHolds(), Bool.and(now.dragging(), Bool.or(key === "x", key === "y"))),
2971
- ])
2972
- // Written as any frame is: into the gate, the Snapshot (at rest) and the presence record.
2973
- const put = (values: Values.Values): void => {
2974
- Arr.forEach(Rec.keys(values), (key) => {
2975
- snapshot.values[key] = UndefinedOr.getOrThrow(values[key])
2976
- delete snapshot.velocities[key]
2977
- })
2978
- gate.write(id, values)
2979
- recordFrame(values)
2980
- }
2981
- handBack = (key) => {
2982
- Option.match(Option.filter(routes.valueOf(key), isValue), {
2983
- onNone: constVoid,
2984
- onSome: (value) => put({ [key]: value }),
2985
- })
2986
- }
2987
- // Every routed key nothing owns, with, before anything's committed, the values the Override
2988
- // stack's keys start from, so a held start (a `when` gate) keeps showing them.
2989
- const first = Rec.filter(routes.values(), (_, key) => Bool.not(owned(key)))
2990
- if (hasKeys(first)) put({ ...Values.pick(snapshot.values, now.resolved()), ...first })
2991
- return {
2992
- change: (key, value) => {
2993
- if (Bool.or(owned(key), Bool.not(isValue(value)))) return
2994
- put({ [key]: value as number | string })
2995
- },
2996
- removed: (key) => {
2997
- if (owned(key)) return
2998
- delete snapshot.values[key]
2999
- delete snapshot.velocities[key]
3000
- if (Predicate.isNotUndefined(presence)) delete presence.snapshot.current[key]
3001
- // Gone from `style`: the element's own value comes back, or the key's CSS value now.
3002
- const restore = Option.match(OwnValues.styleValueOf(UndefinedOr.match(styleNow, { onUndefined: constUndefined, onDefined: (style) => style() }), key), {
3003
- onNone: () => "",
3004
- onSome: String,
3005
- })
3006
- gate.release(id, [key], { [key]: restore })
3007
- },
3008
- }
3009
- })
3010
- }
3011
-
3012
- const dispose = (): void => {
3013
- // Unmounted, it lands in no Controls change (#433).
3014
- leaveChange()
3015
- if (Predicate.isNotUndefined(live)) live.stop()
3016
- // The legs end normally first, so closing the Scope has nothing left to interrupt. A Transition
3017
- // end waiting or due writes nothing (#508).
3018
- if (Predicate.isNotUndefined(waiting)) waiting.dispose()
3019
- // Each leg not landed ends as a Retarget ends one (#542): by its token, and interrupted if its
3020
- // token didn't reach it. Nothing else ends them before the provider does.
3021
- owners.forEach((running) => {
3022
- if (Predicate.isUndefined(running)) return
3023
- if (!running.done) endLeg(running)
3024
- })
3025
- // Its Batch member's groups go back to the Batch (#665's PR 4).
3026
- if (Predicate.isNotUndefined(memberHold)) memberHold.dispose()
3027
- }
3028
-
3029
- // A child back under its key (#286): its values and velocities from where the leaver is drawn, a
3030
- // projected element's own translate among them (#363). Drawn at the end of the task, so nothing
3031
- // paints the element at its `initial` first: not in the mount effect it's called in, where the
3032
- // first commit's Starting-style switch would flush Solid 2 inside an effect.
3033
- const seed = (from: PresenceSeed): void => {
3034
- const values = from.values
3035
- Object.assign(snapshot.values, values)
3036
- snapshot.velocities = { ...snapshot.velocities, ...from.velocities }
3037
- // Drawn now, by the leaver (#464).
3038
- const now = snapshot.now()
3039
- Arr.forEach(Rec.keys(from.velocities), (key) => {
3040
- snapshot.drawnAt[key] = now
3041
- })
3042
- if (Predicate.isNotUndefined(presence)) Object.assign(presence.snapshot.current, values)
3043
- Arr.forEach(Rec.keys(values), (key) => {
3044
- driven.set(key, values[key])
3045
- })
3046
- queueMicrotask(() => gate.flushPass(() => gate.write(id, values)))
3047
- }
3048
-
3049
- // --- Imperative animations (#433) -------------------------------------------
3050
- /** A leg of an Imperative animation, forked as a Retarget's are; it lands on its track. */
3051
- // Data-first: a pipe's curried forms are two closures more for every leg (#618, H1).
3052
- const runImperative = (running: Running, program: Effect.Effect<unknown, never, WardicServices>): void => {
3053
- running.fiber = runtime.runFork(Effect.asVoid(Effect.onExit(program, legEnded(running))))
3054
- }
3055
-
3056
- const animate = (target: Target, given: WardicTransition | undefined, head: Playback.Playhead, hooks: ImperativeHooks): ImperativeTrack => {
3057
- const to = target.values
3058
- const before = UndefinedOr.match(lastResolution, { onUndefined: () => NO_VALUES, onDefined: (last) => last.resolved })
3059
- const started: Record<string, string> = {}
3060
- let measuring: Array<string> | undefined
3061
- // Each key taken from whatever runs it, noted with its target now, and started where it's drawn.
3062
- // Its velocity read now (#464), as its legs are built.
3063
- readAt = snapshot.now()
3064
- // Where a Path's axis this target leaves out rests (#574), before its keys are taken below.
3065
- const rests = restsOf(owners, to)
3066
- if (taken === NONE_TAKEN) taken = new Map()
3067
- const takenNow = taken
3068
- Arr.forEach(Rec.keys(to), (key) => {
3069
- takenNow.set(key, before[key])
3070
- returning.delete(key)
3071
- const owner = owners.get(key)
3072
- if (Predicate.isNotUndefined(owner)) giveUp(key, owner)
3073
- if (!Object.hasOwn(initialValues, key)) ownValue(key)
3074
- const like = UndefinedOr.getOrThrow(to[key])
3075
- startKey(key, like, started)
3076
- if (MeasuredPair.needs(key, UndefinedOr.getOrThrow(snapshot.values[key]), like)) {
3077
- if (Predicate.isUndefined(measuring)) measuring = []
3078
- measuring.push(key)
3079
- }
3080
- })
3081
- keepTheRest()
3082
- let from: Values.Values = Rec.map(to, (_, key) => UndefinedOr.getOrThrow(snapshot.values[key]))
3083
- let stops: StopsByKey | undefined
3084
- if (Predicate.isNotUndefined(target.keyframes)) {
3085
- const begun = keyframesFrom(from, to, target.keyframes)
3086
- from = begun.from
3087
- stops = begun.stops
3088
- }
3089
- const reduce = options.reducedMotion()
3090
- const skipped = skipAnimations()
3091
- let measured: MeasuredPairs | undefined
3092
- if (Bool.and(Bool.not(Bool.or(reduce, skipped)), Predicate.isNotUndefined(measuring))) measured = measuredOf(element, UndefinedOr.getOrThrow(measuring), from, to, snapshot.values, stops)
3093
- // Built once: a seek or a replay runs the same legs, from the same start, with the same velocities.
3094
- const built = legsOf(from, to, given, reduce, skipped, positionalKeys, defaultTransition, readVelocity, undefined, stops, measured, snapshot.values, rests)
3095
- const variables = holdsVariable(from, to, stops)
3096
- const legs = Arr.map(built, (leg) => mapMachine(leg, Playback.drive(head)))
3097
- let runnings: ReadonlyArray<Running> = NO_RUNNING
3098
- let left = 0
3099
- const landing: Landing = {
3100
- report: constVoid,
3101
- settled: () => {
3102
- left--
3103
- if (left === 0) gate.afterFlush(hooks.settled)
3104
- },
3105
- failed: hooks.failed,
3106
- }
3107
- // Its legs ended where they are: the keys they draw are drawn by none.
3108
- const end = (): void =>
3109
- Arr.forEach(runnings, (running) => {
3110
- forget(running)
3111
- if (Bool.not(running.done)) endLeg(running)
3112
- })
3113
- const run = (): void => {
3114
- end()
3115
- left = legs.length
3116
- turnWillChangeOn(live, legs)
3117
- runnings = Arr.map(legs, (leg) => {
3118
- const running = runningOf(leg.to, IMPERATIVE, landing, leg._tag)
3119
- own(running)
3120
- runImperative(running, legProgram(leg, running, variables))
3121
- return running
3122
- })
3123
- // A target with no key lands at once.
3124
- if (left === 0) gate.afterFlush(hooks.settled)
3125
- }
3126
- const cancel = (): void => {
3127
- end()
3128
- turnBack()
3129
- snapshot.values = { ...snapshot.values, ...from }
3130
- snapshot.velocities = { ...snapshot.velocities, ...Rec.map(from, () => 0) }
3131
- // Put back at once: at rest, newer than the legs that let them go (#464).
3132
- const now = snapshot.now()
3133
- Arr.forEach(Rec.keys(from), (key) => {
3134
- snapshot.drawnAt[key] = now
3135
- })
3136
- gate.write(id, from)
3137
- recordFrame(from)
3138
- }
3139
- // Each leg's machine, run from its start to rest, apart from the Playhead, which it would move: a
3140
- // blend's built with the element's Key rules.
3141
- const duration = (): number =>
3142
- Arr.reduce(built, 0, (longest, leg) => Math.max(longest, Machine.durationOf(machineOf(leg))))
3143
- const machineOf = (leg: Leg): Machine.Machine<Frame.Frame<unknown>> => {
3144
- if (leg._tag === "Blend") return runtime.runSync(Effect.suspend(leg.machine).pipe(InterpolatorRegistry.withKeyRules(elementRules)))
3145
- return leg.machine() as Machine.Machine<Frame.Frame<unknown>>
3146
- }
3147
- const stop = (): void => {
3148
- end()
3149
- turnBack()
3150
- }
3151
- return { run, stop, cancel, duration }
3152
- }
3153
-
3154
- // **Animation controls**' `stop` (#433): every running leg ends where it is, its keys given up, so
3155
- // the next Retarget starts them from where they're drawn.
3156
- const stop = (): void => {
3157
- owners.forEach((running) => {
3158
- if (Predicate.isUndefined(running)) return
3159
- forget(running)
3160
- if (Bool.not(running.done)) endLeg(running)
3161
- })
3162
- turnBack()
3163
- }
3164
-
3165
- return { retarget, follow, dispose, seed, animate, stop }
3166
- }
3167
-
3168
-
3169
- /**
3170
- * `sink` with an `onCommit` that calls the config's current `onUpdate` (#233), when the config had
3171
- * one at mount; `sink` as it is otherwise. `config` reads it untracked.
3172
- */
3173
- export const withOnUpdate = (sink: FlushGate.Sink, atMount: WardConfig["onUpdate"], config: () => WardConfig): FlushGate.Sink => {
3174
- // Per element at mount: most have none, and pay a check.
3175
- if (Predicate.isUndefined(atMount)) return sink
3176
- return {
3177
- ...sink,
3178
- onCommit: (latest) => {
3179
- const onUpdate = config().onUpdate
3180
- if (Predicate.isNotUndefined(onUpdate)) onUpdate(latest as Readonly<Record<string, number | string>>)
3181
- },
3182
- }
3183
- }
3184
-
3185
- /**
3186
- * `sink`, removing the element's Appear animation in its first commit (#48, ADR-0044 decision 6):
3187
- * in the task that writes the engine's first frame, so no paint falls between. Without one, `sink`.
3188
- */
3189
- export const releasingAppear = (sink: FlushGate.Sink, handoff: Handoff | undefined, element: HTMLElement): FlushGate.Sink => {
3190
- if (Predicate.isUndefined(handoff)) return sink
3191
- const before = sink.beforeFirstCommit
3192
- return {
3193
- ...sink,
3194
- beforeFirstCommit: () => {
3195
- Appear.release(element)
3196
- if (Predicate.isNotUndefined(before)) before()
3197
- },
3198
- }
3199
- }
3200
-
3201
- /**
3202
- * A Handoff whose Appear animation the server sampled from another mount animation than the
3203
- * client's: the app rendered differently on the server, or a function it gave has no easing name.
3204
- * Noted once (cold path, `wardic.hydration`); the client's own animation goes on from the same time.
3205
- */
3206
- const checkHandoff = (runtime: WardicRuntime, id: string, handoff: Handoff, mount: MountAnimation): void => {
3207
- // A templated element's rule is named by its stops (#443), which the client doesn't sample to check.
3208
- if (Predicate.isNotUndefined(mount.template)) return
3209
- const same = Option.exists(keyOf(mount), (key) =>
3210
- Appear.matches(handoff.animation, { key, tag: mount.tag, infinite: repeatsForever(mount.transition), projected: mount.layout }))
3211
- if (same) return
3212
- runtime.runFork(
3213
- Effect.logDebug("wardic.hydration: the server's Appear animation was sampled from another mount animation than this element's; it goes on from the same time").pipe(
3214
- Effect.annotateLogs({ id }),
3215
- ),
3216
- )
3217
- }
3218
-
3219
- /** The keys a Retarget returns to a Live value that's a number: each one's return follows it (#130). */
3220
- const followingOf = (routes: LiveStyle, rest: Values.Values, returning: ReadonlyMap<string, BaseValue.BaseSource>): ReadonlyArray<string> =>
3221
- Arr.filter(Rec.keys(rest), (key) => Bool.and(returning.get(key) === "style", Bool.and(routes.isLive(key), Predicate.isNumber(rest[key]))))
3222
-
3223
- /** Where `key`'s Live value is now, a number; where it last was when it's none (#130). */
3224
- const liveTargetOf = (routes: LiveStyle, key: string, start: number): (() => number) => {
3225
- let last = start
3226
- return () => {
3227
- const now = Option.flatMap(routes.valueOf(key), (raw) => OwnValues.valueLike(raw, last))
3228
- if (Option.isSome(now)) last = now.value as number
3229
- return last
3230
- }
3231
- }
3232
-
3233
- /** Whether a value is one an element can take: a number or a string. */
3234
- const isValue = (value: unknown): value is number | string => Bool.or(Predicate.isNumber(value), Predicate.isString(value))
3235
-
3236
- /**
3237
- * Where `key` rests outside the gate (#130): its `initial`, else its `style` value (a Live value's
3238
- * now), else a transform key's identity, else `undefined`.
3239
- */
3240
- export const restingOf = (key: string, initial: Values.Values, style: object | string | undefined, read: (value: unknown) => unknown): unknown =>
3241
- Option.getOrUndefined(
3242
- Option.fromUndefinedOr(initial[key]).pipe(
3243
- Option.orElse((): Option.Option<unknown> => Option.flatMap(OwnValues.styleValueOf(style, key), (raw) => Option.fromNullishOr(read(raw)))),
3244
- Option.orElse((): Option.Option<unknown> => BaseValue.transformIdentity(key)),
3245
- ),
3246
- )
3247
-
3248
- /** A provider runtime's `AtomRegistry`, read on first need: an element with no Atom never reads it. */
3249
- export const registryOf = (runtime: WardicRuntime): (() => AtomRegistry.AtomRegistry) => {
3250
- let registry: AtomRegistry.AtomRegistry | undefined
3251
- return () => {
3252
- if (Predicate.isUndefined(registry)) registry = runtime.runSync(AtomRegistry.AtomRegistry)
3253
- return registry
3254
- }
3255
- }
3256
-
3257
- /** Log, once per element, that a `transform` string gave way to the transform keys in its `style` (#130). */
3258
- export const warnDroppedTransform = (runtime: WardicRuntime, id: string): void => {
3259
- runtime.runFork(
3260
- Effect.logWarning(
3261
- "wardic.style: a `transform` string is dropped while `style` sets a transform key (x, scale, rotate…); " +
3262
- "the keys win, as Motion's do. Give the transform as keys, or drop them",
3263
- ).pipe(Effect.annotateLogs({ id })),
3264
- )
3265
- }
3266
-
3267
- /**
3268
- * Log, at debug level, the keys whose Starting style the Environment's Renderer projects
3269
- * differently from the DOM's `project`, which rendered the server markup. Hydration keeps
3270
- * the server's values (the Hydration hold); the Renderer's take over at the first frame.
3271
- * Hydration only, once per element. Internal.
3272
- */
3273
- export const flagStartingStyle = (runtime: WardicRuntime, id: string, server: Renderer.Patch, client: Renderer.Patch): void => {
3274
- const keys = Arr.appendAll(
3275
- Arr.filter(Rec.keys(server), (key) => String(server[key]) !== String(client[key])),
3276
- Arr.filter(Rec.keys(client), (key) => Bool.not(key in server)),
3277
- )
3278
- if (Arr.isReadonlyArrayEmpty(keys)) return
3279
- const pick = (patch: Renderer.Patch) => Object.fromEntries(keys.map((key) => [key, patch[key]]))
3280
- runtime.runFork(
3281
- Effect.logDebug(
3282
- "wardic.hydration: the Environment's Renderer projects the Starting style differently from the DOM's; " +
3283
- "hydration keeps the server's until the first frame, and an element that never animates keeps it",
3284
- ).pipe(
3285
- Effect.annotateLogs({ id, keys, server: pick(server), client: pick(client) }),
3286
- ),
3287
- )
3288
- }
3289
-
3290
- /** An element's Appear animation on a server (#48, ADR-0044), as both bindings' server wards and component wraps use it. */
3291
- export interface ServerAppearOf {
3292
- /** Its inline `animation`, under the user's style: none when it plays none. */
3293
- readonly style: { readonly animation: string } | undefined
3294
- /** The context its children read: its variant node's, with its Appear group when it leads one. */
3295
- readonly provided: WardicVariantContextValue | undefined
3296
- /** Rules it out once it has rendered: its user style is read when `ward()` is called. */
3297
- readonly veto: (reason: string) => void
3298
- /**
3299
- * Rendered after the shell (#245): in a late chunk, and its root when no late element is around
3300
- * it, which puts the chunk's `<style>` after itself. `state` is the render's.
3301
- */
3302
- readonly late: boolean
3303
- readonly chunkRoot: boolean
3304
- readonly state: ServerAppear | undefined
3305
- }
3306
-
3307
- /** No Appear animation: a provider with `appear={false}`. */
3308
- const NO_APPEAR_ENTRY = (provided: WardicVariantContextValue | undefined): ServerAppearOf => ({
3309
- style: undefined,
3310
- provided,
3311
- veto: constVoid,
3312
- late: false,
3313
- chunkRoot: false,
3314
- state: undefined,
3315
- })
3316
-
3317
- /**
3318
- * An element's entry in the server render's Appear animations (#48, ADR-0044): its starting
3319
- * values, its targets at mount (`animate`, or an inherited variant name against its `variants`),
3320
- * its transition, its place in its parent's group, and its nearest `WardicConfig`'s reduced motion
3321
- * (#434). `state` is the provider's, `undefined` with `appear={false}`: each binding reads it from its
3322
- * own context.
3323
- */
3324
- export const appearEntryOf = (
3325
- state: ServerAppear | undefined,
3326
- c: WardConfig,
3327
- tag: string | undefined,
3328
- initialValues: Values.Values,
3329
- node: ServerVariantNode,
3330
- quiet: boolean,
3331
- reducedMotion: ReducedMotion.Config | undefined,
3332
- skipAnimations = false,
3333
- ): ServerAppearOf =>
3334
- UndefinedOr.match(state, {
3335
- onUndefined: () => NO_APPEAR_ENTRY(node.provided),
3336
- onDefined: (state) => {
3337
- // The target's own transition (#277) drives its mount animation, and its orchestration.
3338
- const target = serverTargetOf(c, node.inherited)
3339
- const own = Option.getOrUndefined(Option.flatMap(target, (t) => Option.fromUndefinedOr(t.transition)))
3340
- const entered = enterServer(state, {
3341
- appear: c.appear,
3342
- tag,
3343
- initial: initialValues,
3344
- to: Option.map(target, (t) => t.values),
3345
- keyframes: Option.getOrUndefined(Option.flatMap(target, (t) => Option.fromUndefinedOr(t.keyframes))),
3346
- quiet,
3347
- transition: transitionOfTarget(own, ownOrInherited(c.transition, node.inherited)),
3348
- layout: isLayoutNode(c),
3349
- template: c.transformTemplate,
3350
- group: Option.flatMap(Option.fromUndefinedOr(node.inherited), (inherited) => Option.fromUndefinedOr(inherited.appearGroup)),
3351
- leads: hasOwnVariants(c),
3352
- ownTransition: transitionOfTarget(own, c.transition),
3353
- reducedMotion,
3354
- skipAnimations,
3355
- })
3356
- return {
3357
- style: Option.match(entered.animation, { onNone: constUndefined, onSome: (animation) => ({ animation }) }),
3358
- provided: Option.match(entered.group, {
3359
- onNone: () => node.provided,
3360
- onSome: (appearGroup) => UndefinedOr.map(node.provided, (provided): WardicVariantContextValue => ({ ...provided, appearGroup })),
3361
- }),
3362
- veto: entered.veto,
3363
- late: entered.late,
3364
- chunkRoot: entered.chunkRoot,
3365
- state,
3366
- }
3367
- },
3368
- })
3369
-
3370
- /**
3371
- * An element's target at mount on a server: its `animate`, else an inherited variant name resolved
3372
- * against its own `variants`, a dynamic one with its `custom` and no values yet (#277).
3373
- */
3374
- export const serverTargetOf = (c: WardConfig, inherited: WardicVariantContextValue | undefined): Option.Option<Target> =>
3375
- UndefinedOr.match(c.animate as Entry, {
3376
- onDefined: (own) => Option.some(resolveTarget(own, c.variants, c.custom, NO_VARIANT_STATE)),
3377
- onUndefined: () =>
3378
- Option.map(
3379
- Option.flatMap(Option.fromUndefinedOr(inherited), (context) => Option.fromUndefinedOr(context.variant())),
3380
- (name) => resolveTarget(name, c.variants, c.custom, NO_VARIANT_STATE),
3381
- ),
3382
- })
3383
-
3384
- /**
3385
- * A server's Starting style for an element whose `style` has routed keys (#130): the projected
3386
- * `initial` with their values under it. With none, its Starting style as it was.
3387
- */
3388
- export const serverStartingStyle = (
3389
- tag: string | undefined,
3390
- starting: Renderer.Patch,
3391
- initialValues: Values.Values,
3392
- routed: Readonly<Record<string, unknown>>,
3393
- layout: boolean,
3394
- untrack: Reactivity["untrack"],
3395
- template: WardConfig["transformTemplate"],
3396
- ): Renderer.Patch =>
3397
- Bool.match(Rec.isEmptyRecord(routed), {
3398
- onTrue: () => starting,
3399
- onFalse: () => Style.starting(tag, drawnAtRest({ ...valuesOf(routed, serverRegistryOf, untrack), ...initialValues }, layout, template)).style,
3400
- })
3401
-
3402
- /** Whether a config makes its element a layout node: `layout` (or a mode), or a `layoutId`. */
3403
- export const isLayoutNode = (c: WardConfig): boolean =>
3404
- Bool.or(Bool.and(Predicate.isNotUndefined(c.layout), c.layout !== false), Predicate.isNotUndefined(c.layoutId))
3405
-
3406
- /**
3407
- * The values a layout node's Starting style is drawn from (#245, ADR-0044 *Amendment (#245)*):
3408
- * through its projection at rest, as its first commit draws it, its own translate on top (#363).
3409
- * Any other element's, as they are. A templated element's, with its Transform template (#443).
3410
- */
3411
- export const drawnAtRest = (values: Values.Values, layout: boolean, template: WardConfig["transformTemplate"]): Readonly<Record<string, unknown>> => {
3412
- // Per mount (#460): guards, nothing built for an element neither a layout node nor templated.
3413
- if (Bool.not(layout)) return withTemplate(values, template)
3414
- return withTemplate({ ...values, [Projection.KEY]: Projection.AT_REST }, template)
3415
- }
3416
-
3417
- /** `values` with `template` under the renderer's reserved key, as its projection rides (#443); as they are with none. */
3418
- export const withTemplate = <V extends Readonly<Record<string, unknown>>>(values: V, template: WardConfig["transformTemplate"]): V => {
3419
- if (Predicate.isUndefined(template)) return values
3420
- return { ...values, [DomRenderer.TEMPLATE_KEY]: template }
3421
- }
3422
-
3423
- /**
3424
- * What an element registers with in the gate (#443): its Transform template at mount, under the
3425
- * renderer's reserved key, drawn with its first write (a write of its own would take its Starting
3426
- * style off early). Nothing with none.
3427
- */
3428
- export const registeredValuesOf = (template: WardConfig["transformTemplate"]): Readonly<Record<string, unknown>> | undefined => {
3429
- if (Predicate.isUndefined(template)) return undefined
3430
- return { [DomRenderer.TEMPLATE_KEY]: template }
3431
- }
3432
-
3433
- /**
3434
- * What an element's projection node is held at for a Measure pass (#443, Motion's
3435
- * `transformTemplate(values, "")`): its Transform template's, from its values now, when it had one
3436
- * at mount. `undefined` otherwise, so a node without one pays a field read a pass.
3437
- */
3438
- export const heldTransformFor = (
3439
- snapshot: Snapshot,
3440
- atMount: WardConfig["transformTemplate"],
3441
- template: () => WardConfig["transformTemplate"],
3442
- ): (() => string) | undefined => {
3443
- if (Predicate.isUndefined(atMount)) return undefined
3444
- return () => DomRenderer.heldTransformOf(withTemplate(snapshot.values, template()))
3445
- }
3446
-
3447
- /**
3448
- * Follow an element's Transform template after mount (#443): `write` is called with each other one
3449
- * its config gives, and draws it at the next frame. Only for an element with one at mount, as
3450
- * `onUpdate` (#233): its caller asks only then, so another makes nothing (#460). Returns the stop.
3451
- */
3452
- export const followTemplate = (
3453
- atMount: DomRenderer.TransformTemplate,
3454
- template: () => WardConfig["transformTemplate"],
3455
- watch: Reactivity["watch"],
3456
- write: (template: WardConfig["transformTemplate"]) => void,
3457
- ): (() => void) => {
3458
- let last: WardConfig["transformTemplate"] = atMount
3459
- return watch(template, (next) => {
3460
- if (next === last) return
3461
- last = next
3462
- write(next)
3463
- })
3464
- }
3465
-
3466
- /** A mount animation's template field (#443): left out with none, as its key reads it. */
3467
- export const templateField = (template: WardConfig["transformTemplate"]): { readonly template?: DomRenderer.TransformTemplate } =>
3468
- UndefinedOr.match(template, { onUndefined: () => ({}), onDefined: (t) => ({ template: t }) })
3469
-
3470
- /** What a `<Reorder>` item adds to an element's drag: its gesture's axis, read at each drag's start. */
3471
- interface DragInternals {
3472
- readonly dragAxis?: (() => boolean | "x" | "y") | undefined
3473
- }
3474
-
3475
- /** A plain element's drag internals: none. */
3476
- const NO_DRAG_INTERNALS: DragInternals = {}
3477
-
3478
- /**
3479
- * The drag axis a spine runs with: its static `drag` config, else `true` for a
3480
- * `<Reorder>` item (its gesture's axis comes from `dragAxis`), else none.
3481
- */
3482
- export const dragAxisOf = (config: WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): boolean | "x" | "y" | undefined =>
3483
- Option.getOrUndefined(
3484
- Option.orElse(Option.filter(Option.fromUndefinedOr(config.drag), (drag) => drag !== false), () =>
3485
- Option.map(Option.fromUndefinedOr(internal.dragAxis), (): true => true)),
3486
- )
3487
-
3488
- /**
3489
- * A drag element's defaults (ADR-0019 *Amendment (Reorder)*): its axis's, unless its own presses don't
3490
- * drag it (`dragListener={false}`, #431), as Motion's come with its listener.
3491
- */
3492
- export const dragDefaultsOf = (config: WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): Style.DragDefaults | undefined => {
3493
- if (config.dragListener === false) return undefined
3494
- return UndefinedOr.map(dragAxisOf(config, internal), Style.dragDefaults)
3495
- }
3496
-
3497
- /**
3498
- * Set each of a drag element's defaults its inline style doesn't already set, and
3499
- * `draggable="false"` unless it has the attribute, at mount: for an element whose props don't carry
3500
- * them, a directive's (`use:wardic`, `use:w`) and a `wardic.create(Component)` wrap's, whose
3501
- * component may not pass them on.
3502
- */
3503
- export const applyDragDefaults = (element: HTMLElement, defaults: Style.DragDefaults): void => {
3504
- Arr.forEach(Rec.keys(defaults), (key) => {
3505
- if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(defaults[key]))
3506
- })
3507
- if (!element.hasAttribute("draggable")) element.setAttribute("draggable", Style.DRAG_DEFAULT_ATTRIBUTES.draggable)
3508
- }
1
+ // #672: @wardic/core/unstable/Spine since the lift; solid's modules import it through here until each has
2
+ // moved.
3
+ export * from "@wardic/core/unstable/Spine"