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