@wardic/dom 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 (253) hide show
  1. package/dist/DomProjectionSystem.js +3 -3
  2. package/dist/DomProjectionSystem.js.map +1 -1
  3. package/dist/FlushGate.d.ts +6 -6
  4. package/dist/FlushGate.d.ts.map +1 -1
  5. package/dist/FlushGate.js +7 -5
  6. package/dist/FlushGate.js.map +1 -1
  7. package/dist/ReorderController.js +3 -3
  8. package/dist/ReorderController.js.map +1 -1
  9. package/dist/Report.d.ts +1 -1
  10. package/dist/Report.d.ts.map +1 -1
  11. package/dist/Report.js +3 -2
  12. package/dist/Report.js.map +1 -1
  13. package/dist/Style.d.ts +2 -1
  14. package/dist/Style.d.ts.map +1 -1
  15. package/dist/Style.js +3 -1
  16. package/dist/Style.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/internal/batch-handoff.d.ts +25 -0
  20. package/dist/internal/batch-handoff.d.ts.map +1 -0
  21. package/dist/internal/batch-handoff.js +64 -0
  22. package/dist/internal/batch-handoff.js.map +1 -0
  23. package/dist/internal/gate-environment.d.ts +4 -0
  24. package/dist/internal/gate-environment.d.ts.map +1 -0
  25. package/dist/internal/gate-environment.js +21 -0
  26. package/dist/internal/gate-environment.js.map +1 -0
  27. package/dist/internal/projection.js +14 -14
  28. package/dist/internal/projection.js.map +1 -1
  29. package/dist/internal/reorder.d.ts +2 -2
  30. package/dist/internal/reorder.d.ts.map +1 -1
  31. package/dist/internal/reorder.js +2 -2
  32. package/dist/internal/reorder.js.map +1 -1
  33. package/dist/internal/starting-style.d.ts +0 -83
  34. package/dist/internal/starting-style.d.ts.map +1 -1
  35. package/dist/internal/starting-style.js +16 -143
  36. package/dist/internal/starting-style.js.map +1 -1
  37. package/dist/unstable/AppearAnimations.d.ts +191 -0
  38. package/dist/unstable/AppearAnimations.d.ts.map +1 -0
  39. package/dist/unstable/AppearAnimations.js +561 -0
  40. package/dist/unstable/AppearAnimations.js.map +1 -0
  41. package/dist/unstable/BatchMembers.d.ts +513 -0
  42. package/dist/unstable/BatchMembers.d.ts.map +1 -0
  43. package/dist/unstable/BatchMembers.js +2490 -0
  44. package/dist/unstable/BatchMembers.js.map +1 -0
  45. package/dist/unstable/DomValues.d.ts +25 -0
  46. package/dist/unstable/DomValues.d.ts.map +1 -0
  47. package/dist/unstable/DomValues.js +45 -0
  48. package/dist/unstable/DomValues.js.map +1 -0
  49. package/dist/unstable/DragConstraints.d.ts +48 -0
  50. package/dist/unstable/DragConstraints.d.ts.map +1 -0
  51. package/dist/unstable/DragConstraints.js +49 -0
  52. package/dist/unstable/DragConstraints.js.map +1 -0
  53. package/dist/unstable/DragControls.d.ts +50 -0
  54. package/dist/unstable/DragControls.d.ts.map +1 -0
  55. package/dist/unstable/DragControls.js +55 -0
  56. package/dist/unstable/DragControls.js.map +1 -0
  57. package/dist/unstable/DragDefaults.d.ts +34 -0
  58. package/dist/unstable/DragDefaults.d.ts.map +1 -0
  59. package/dist/unstable/DragDefaults.js +47 -0
  60. package/dist/unstable/DragDefaults.js.map +1 -0
  61. package/dist/unstable/DragTrack.d.ts +236 -0
  62. package/dist/unstable/DragTrack.d.ts.map +1 -0
  63. package/dist/unstable/DragTrack.js +646 -0
  64. package/dist/unstable/DragTrack.js.map +1 -0
  65. package/dist/unstable/DragTransition.d.ts +22 -0
  66. package/dist/unstable/DragTransition.d.ts.map +1 -0
  67. package/dist/unstable/DragTransition.js +31 -0
  68. package/dist/unstable/DragTransition.js.map +1 -0
  69. package/dist/unstable/ElementSetup.d.ts +144 -0
  70. package/dist/unstable/ElementSetup.d.ts.map +1 -0
  71. package/dist/unstable/ElementSetup.js +297 -0
  72. package/dist/unstable/ElementSetup.js.map +1 -0
  73. package/dist/unstable/Feature.d.ts +221 -0
  74. package/dist/unstable/Feature.d.ts.map +1 -0
  75. package/dist/unstable/Feature.js +281 -0
  76. package/dist/unstable/Feature.js.map +1 -0
  77. package/dist/unstable/GestureFeatures.d.ts +30 -0
  78. package/dist/unstable/GestureFeatures.d.ts.map +1 -0
  79. package/dist/unstable/GestureFeatures.js +32 -0
  80. package/dist/unstable/GestureFeatures.js.map +1 -0
  81. package/dist/unstable/GestureInfo.d.ts +61 -0
  82. package/dist/unstable/GestureInfo.d.ts.map +1 -0
  83. package/dist/unstable/GestureInfo.js +23 -0
  84. package/dist/unstable/GestureInfo.js.map +1 -0
  85. package/dist/unstable/Imperative.d.ts +214 -0
  86. package/dist/unstable/Imperative.d.ts.map +1 -0
  87. package/dist/unstable/Imperative.js +768 -0
  88. package/dist/unstable/Imperative.js.map +1 -0
  89. package/dist/unstable/Instant.d.ts +46 -0
  90. package/dist/unstable/Instant.d.ts.map +1 -0
  91. package/dist/unstable/Instant.js +49 -0
  92. package/dist/unstable/Instant.js.map +1 -0
  93. package/dist/unstable/LayoutGroup.d.ts +14 -0
  94. package/dist/unstable/LayoutGroup.d.ts.map +1 -0
  95. package/dist/unstable/LayoutGroup.js +31 -0
  96. package/dist/unstable/LayoutGroup.js.map +1 -0
  97. package/dist/unstable/LayoutMember.d.ts +127 -0
  98. package/dist/unstable/LayoutMember.d.ts.map +1 -0
  99. package/dist/unstable/LayoutMember.js +176 -0
  100. package/dist/unstable/LayoutMember.js.map +1 -0
  101. package/dist/unstable/LiveStyle.d.ts +171 -0
  102. package/dist/unstable/LiveStyle.d.ts.map +1 -0
  103. package/dist/unstable/LiveStyle.js +329 -0
  104. package/dist/unstable/LiveStyle.js.map +1 -0
  105. package/dist/unstable/MemberHold.d.ts +3 -0
  106. package/dist/unstable/MemberHold.d.ts.map +1 -0
  107. package/dist/unstable/MemberHold.js +223 -0
  108. package/dist/unstable/MemberHold.js.map +1 -0
  109. package/dist/unstable/OwnerScope.d.ts +16 -0
  110. package/dist/unstable/OwnerScope.d.ts.map +1 -0
  111. package/dist/unstable/OwnerScope.js +35 -0
  112. package/dist/unstable/OwnerScope.js.map +1 -0
  113. package/dist/unstable/PresenceController.d.ts +128 -0
  114. package/dist/unstable/PresenceController.d.ts.map +1 -0
  115. package/dist/unstable/PresenceController.js +1427 -0
  116. package/dist/unstable/PresenceController.js.map +1 -0
  117. package/dist/unstable/Press.d.ts +26 -0
  118. package/dist/unstable/Press.d.ts.map +1 -0
  119. package/dist/unstable/Press.js +19 -0
  120. package/dist/unstable/Press.js.map +1 -0
  121. package/dist/unstable/ServerInterpolators.d.ts +17 -0
  122. package/dist/unstable/ServerInterpolators.d.ts.map +1 -0
  123. package/dist/unstable/ServerInterpolators.js +20 -0
  124. package/dist/unstable/ServerInterpolators.js.map +1 -0
  125. package/dist/unstable/WardConfig.d.ts +567 -0
  126. package/dist/unstable/WardConfig.d.ts.map +1 -0
  127. package/dist/unstable/WardConfig.js +2 -0
  128. package/dist/unstable/WardConfig.js.map +1 -0
  129. package/dist/unstable/features/All.d.ts +24 -0
  130. package/dist/unstable/features/All.d.ts.map +1 -0
  131. package/dist/unstable/features/All.js +20 -0
  132. package/dist/unstable/features/All.js.map +1 -0
  133. package/dist/unstable/features/Colors.d.ts +12 -0
  134. package/dist/unstable/features/Colors.d.ts.map +1 -0
  135. package/dist/unstable/features/Colors.js +38 -0
  136. package/dist/unstable/features/Colors.js.map +1 -0
  137. package/dist/unstable/features/DomAnimation.d.ts +16 -0
  138. package/dist/unstable/features/DomAnimation.d.ts.map +1 -0
  139. package/dist/unstable/features/DomAnimation.js +19 -0
  140. package/dist/unstable/features/DomAnimation.js.map +1 -0
  141. package/dist/unstable/features/DomMax.d.ts +12 -0
  142. package/dist/unstable/features/DomMax.d.ts.map +1 -0
  143. package/dist/unstable/features/DomMax.js +14 -0
  144. package/dist/unstable/features/DomMax.js.map +1 -0
  145. package/dist/unstable/features/Drag.d.ts +5 -0
  146. package/dist/unstable/features/Drag.d.ts.map +1 -0
  147. package/dist/unstable/features/Drag.js +32 -0
  148. package/dist/unstable/features/Drag.js.map +1 -0
  149. package/dist/unstable/features/Focus.d.ts +5 -0
  150. package/dist/unstable/features/Focus.d.ts.map +1 -0
  151. package/dist/unstable/features/Focus.js +20 -0
  152. package/dist/unstable/features/Focus.js.map +1 -0
  153. package/dist/unstable/features/Hover.d.ts +5 -0
  154. package/dist/unstable/features/Hover.d.ts.map +1 -0
  155. package/dist/unstable/features/Hover.js +20 -0
  156. package/dist/unstable/features/Hover.js.map +1 -0
  157. package/dist/unstable/features/InView.d.ts +5 -0
  158. package/dist/unstable/features/InView.d.ts.map +1 -0
  159. package/dist/unstable/features/InView.js +20 -0
  160. package/dist/unstable/features/InView.js.map +1 -0
  161. package/dist/unstable/features/Input.d.ts +28 -0
  162. package/dist/unstable/features/Input.d.ts.map +1 -0
  163. package/dist/unstable/features/Input.js +31 -0
  164. package/dist/unstable/features/Input.js.map +1 -0
  165. package/dist/unstable/features/Keys.d.ts +95 -0
  166. package/dist/unstable/features/Keys.d.ts.map +1 -0
  167. package/dist/unstable/features/Keys.js +44 -0
  168. package/dist/unstable/features/Keys.js.map +1 -0
  169. package/dist/unstable/features/Layout.d.ts +43 -0
  170. package/dist/unstable/features/Layout.d.ts.map +1 -0
  171. package/dist/unstable/features/Layout.js +44 -0
  172. package/dist/unstable/features/Layout.js.map +1 -0
  173. package/dist/unstable/features/Pan.d.ts +5 -0
  174. package/dist/unstable/features/Pan.d.ts.map +1 -0
  175. package/dist/unstable/features/Pan.js +20 -0
  176. package/dist/unstable/features/Pan.js.map +1 -0
  177. package/dist/unstable/features/Press.d.ts +13 -0
  178. package/dist/unstable/features/Press.d.ts.map +1 -0
  179. package/dist/unstable/features/Press.js +10 -0
  180. package/dist/unstable/features/Press.js.map +1 -0
  181. package/dist/unstable/features/Scroll.d.ts +20 -0
  182. package/dist/unstable/features/Scroll.d.ts.map +1 -0
  183. package/dist/unstable/features/Scroll.js +34 -0
  184. package/dist/unstable/features/Scroll.js.map +1 -0
  185. package/dist/unstable/features/TimelineKeys.d.ts +7 -0
  186. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -0
  187. package/dist/unstable/features/TimelineKeys.js +103 -0
  188. package/dist/unstable/features/TimelineKeys.js.map +1 -0
  189. package/package.json +4 -3
  190. package/src/DomProjectionSystem.ts +3 -3
  191. package/src/FlushGate.ts +11 -9
  192. package/src/ReorderController.ts +3 -3
  193. package/src/Report.ts +3 -7
  194. package/src/Style.ts +4 -1
  195. package/src/index.ts +1 -1
  196. package/src/internal/batch-handoff.ts +75 -0
  197. package/src/internal/gate-environment.ts +21 -0
  198. package/src/internal/projection.ts +14 -14
  199. package/src/internal/reorder.ts +4 -4
  200. package/src/internal/starting-style.ts +5 -204
  201. package/src/unstable/AppearAnimations.ts +837 -0
  202. package/src/unstable/BatchMembers.ts +3085 -0
  203. package/src/unstable/DomValues.ts +53 -0
  204. package/src/unstable/DragConstraints.ts +107 -0
  205. package/src/unstable/DragControls.ts +98 -0
  206. package/src/unstable/DragDefaults.ts +57 -0
  207. package/src/unstable/DragTrack.ts +959 -0
  208. package/src/unstable/DragTransition.ts +46 -0
  209. package/src/unstable/ElementSetup.ts +411 -0
  210. package/src/unstable/Feature.ts +494 -0
  211. package/src/unstable/GestureFeatures.ts +38 -0
  212. package/src/unstable/GestureInfo.ts +85 -0
  213. package/src/unstable/Imperative.ts +1037 -0
  214. package/src/unstable/Instant.ts +93 -0
  215. package/src/unstable/LayoutGroup.ts +36 -0
  216. package/src/unstable/LayoutMember.ts +319 -0
  217. package/src/unstable/LiveStyle.ts +497 -0
  218. package/src/unstable/MemberHold.ts +211 -0
  219. package/src/unstable/OwnerScope.ts +35 -0
  220. package/src/unstable/PresenceController.ts +1747 -0
  221. package/src/unstable/Press.ts +43 -0
  222. package/src/unstable/ServerInterpolators.ts +39 -0
  223. package/src/unstable/WardConfig.ts +704 -0
  224. package/src/unstable/features/All.ts +39 -0
  225. package/src/unstable/features/Colors.ts +40 -0
  226. package/src/unstable/features/DomAnimation.ts +19 -0
  227. package/src/unstable/features/DomMax.ts +14 -0
  228. package/src/unstable/features/Drag.ts +34 -0
  229. package/src/unstable/features/Focus.ts +21 -0
  230. package/src/unstable/features/Hover.ts +21 -0
  231. package/src/unstable/features/InView.ts +21 -0
  232. package/src/unstable/features/Input.ts +37 -0
  233. package/src/unstable/features/Keys.ts +124 -0
  234. package/src/unstable/features/Layout.ts +75 -0
  235. package/src/unstable/features/Pan.ts +21 -0
  236. package/src/unstable/features/Press.ts +21 -0
  237. package/src/unstable/features/Scroll.ts +35 -0
  238. package/src/unstable/features/TimelineKeys.ts +115 -0
  239. package/dist/internal/gate.d.ts +0 -199
  240. package/dist/internal/gate.d.ts.map +0 -1
  241. package/dist/internal/gate.js +0 -570
  242. package/dist/internal/gate.js.map +0 -1
  243. package/dist/internal/report.d.ts +0 -30
  244. package/dist/internal/report.d.ts.map +0 -1
  245. package/dist/internal/report.js +0 -60
  246. package/dist/internal/report.js.map +0 -1
  247. package/dist/internal/runner.d.ts +0 -22
  248. package/dist/internal/runner.d.ts.map +0 -1
  249. package/dist/internal/runner.js +0 -62
  250. package/dist/internal/runner.js.map +0 -1
  251. package/src/internal/gate.ts +0 -706
  252. package/src/internal/report.ts +0 -69
  253. package/src/internal/runner.ts +0 -78
@@ -0,0 +1,497 @@
1
+ /**
2
+ * Live values in `style` (#130, ADR-0043): which of a user's `style` keys Wardic writes through the
3
+ * flush gate, what each is now, and when one changes.
4
+ *
5
+ * A key is **routed** when its value is live (an `effect/reactivity` Atom, or an accessor: a signal,
6
+ * a memo, `createTransform`'s) or when it's a transform key (`x`, `scale`, `rotate`…), live or not
7
+ * (decisions 2 and 4). A routed key is the key's `style` link, followed while no entry of the
8
+ * Override stack sets it (decision 1), and Wardic writes it: the gate composes the transform keys
9
+ * into `transform` with its own, and commits the rest once a frame. So the binding's `style` never
10
+ * carries one. A user's own `transform` string applies while no transform key is set; with one,
11
+ * the keys win (Motion's rule): the gate holds `transform`, so the binding never writes the string, and a
12
+ * warning is logged once per element.
13
+ *
14
+ * The binding reads its user's style reactively in one place, its element's `style`, so that's
15
+ * where `css` sees each new one. Following starts at mount, or at the first routed key after it
16
+ * (`whenRouted`): from then on, a change of a routed key's value, a new source for it, or its
17
+ * leaving the style, is told to the spine, which writes it while nothing else owns the key. An Atom is subscribed; an accessor gets its own
18
+ * computation, one per key, so a change runs only that.
19
+ *
20
+ * Every DOM binding runs it, each giving its own reactivity as a {@link Reactivity.Reactivity} (#209).
21
+ *
22
+ * Unstable, for Wardic's own packages: public, with no semver promise.
23
+ *
24
+ * @module
25
+ */
26
+ // Unstable: ADR-0071, decision 5. #672 (PR3-Q1): solid's `live-style.ts`, the DOM's `style` prop, moved
27
+ // to dom for every DOM binding; the spine reads it through its LiveRoutes.
28
+ import * as BaseValue from "@wardic/core/BaseValue"
29
+ import type * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
30
+ import * as LiveValue from "@wardic/core/LiveValue"
31
+ import type * as Values from "@wardic/core/Values"
32
+ import type * as OwnValues from "@wardic/core/unstable/OwnValues"
33
+ import * as Stops from "@wardic/core/unstable/Stops"
34
+ import * as Arr from "effect/Array"
35
+ import * as Bool from "effect/Boolean"
36
+ import type * as Effect from "effect/Effect"
37
+ import { constVoid } from "effect/Function"
38
+ import * as Option from "effect/Option"
39
+ import * as Predicate from "effect/Predicate"
40
+ import * as Atom from "effect/reactivity/Atom"
41
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry"
42
+ import * as Rec from "effect/Record"
43
+ import * as UndefinedOr from "effect/UndefinedOr"
44
+ import type * as Config from "@wardic/core/unstable/Config"
45
+ import type * as Reactivity from "@wardic/core/unstable/Reactivity"
46
+ import type * as RetargetLegs from "@wardic/core/unstable/RetargetLegs"
47
+ import type * as WardicServices from "@wardic/core/unstable/WardicServices"
48
+
49
+ /**
50
+ * A live value as a binding takes it: an accessor, such as a signal, a memo or another live value, or an
51
+ * `effect/reactivity` Atom. An element's `style` follows it, and the `create*` live values take it.
52
+ */
53
+ export type LiveSource<A> = Atom.Atom<A> | Reactivity.Accessor<A>
54
+
55
+ /** A `style` value: a plain value, or a live one ({@link LiveSource}), which the element follows. */
56
+ export type Live<A> = A | LiveSource<A>
57
+
58
+ /** A user's style as a binding hands it over: a record, CSS text, or none. */
59
+ type StyleInput = object | string | undefined
60
+
61
+ /** Whether a style value is live: an Atom, or an accessor. */
62
+ export const isLive = (value: unknown): value is LiveSource<unknown> => Bool.or(Atom.isAtom(value), Predicate.isFunction(value))
63
+
64
+ /** Where an accessor keeps the Atom it carries (#209 PR 3's Q2). */
65
+ const CARRIED = Symbol.for("@wardic/dom/carried")
66
+
67
+ /**
68
+ * `accessor`, carrying `atom`: the Atom it reads, so a `style` that's given it follows the Atom
69
+ * itself, set where the Atom is, rather than the accessor through Solid (#209 PR 3's Q2). On Solid
70
+ * 2 an accessor's change shows at Solid's flush, after the gate's write: a value derived from a
71
+ * ward's would paint a frame late. Both must give the same value.
72
+ */
73
+ export const carry = <A>(accessor: Reactivity.Accessor<A>, atom: Atom.Atom<A>): Reactivity.Accessor<A> =>
74
+ Object.defineProperty(accessor, CARRIED, { value: atom })
75
+
76
+ /**
77
+ * `createFollowValue`'s transition, in seconds: a spring (with no `type`), a tween or an inertia, an
78
+ * inertia's `timeConstant` in milliseconds, as a `transition`'s; and `skipInitialAnimation`, to make
79
+ * the source's first change a jump. Motion's `FollowValueOptions`.
80
+ */
81
+ // #441; an inertia's `timeConstant` in milliseconds, as a transition's (#435).
82
+ export type FollowValueOptions = (Exclude<LiveValue.FollowTransition, { readonly type: "inertia" }> | Config.WardicInertia) & LiveValue.FollowSkips
83
+
84
+ /** `options` as core's `LiveValue.follow` takes them: an inertia's `timeConstant` in seconds. */
85
+ export const followOptionsOf = (options: FollowValueOptions): LiveValue.FollowOptions =>
86
+ Bool.match(options.type === "inertia", {
87
+ onTrue: () =>
88
+ ({
89
+ ...options,
90
+ ...UndefinedOr.match((options as Config.WardicInertia).timeConstant, { onUndefined: () => ({}), onDefined: (ms) => ({ timeConstant: ms / 1000 }) }),
91
+ }) as LiveValue.FollowOptions,
92
+ onFalse: () => options as LiveValue.FollowOptions,
93
+ })
94
+
95
+ /**
96
+ * A followed value, as an accessor: a number, or a string with its unit, as its source is. Its `jump`
97
+ * puts it somewhere at once.
98
+ */
99
+ // A Follow value (#441), carrying its Atom; `createSpring`'s since #257 item 7.
100
+ export interface FollowAccessor<A extends number | string = number> extends Reactivity.Accessor<A> {
101
+ /**
102
+ * Set it to `value` at once, not as motion (Motion's `MotionValue.jump`): its run ends there with
103
+ * no velocity, and it rests there until its source next changes, then animates from there. A
104
+ * `createVelocity` of it reads 0 across the jump. A string's number is read as the follow reads
105
+ * its source's, and shown with the follow's unit. On a server, it does nothing.
106
+ */
107
+ // A method, bivariant: one implementation serves the number and the string overloads.
108
+ jump(value: A): void
109
+ }
110
+
111
+ /** `createSpring`'s value: a spring's {@link FollowAccessor}. */
112
+ export type SpringAccessor<A extends number | string = number> = FollowAccessor<A>
113
+
114
+ /** The Atom of numbers each unit follow's Atom of strings shows ({@link withUnit}), for its `jump`. */
115
+ // Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
116
+ const UNIT_NUMBERS = new WeakMap<object, Atom.Atom<number>>()
117
+
118
+ /** A unit string's unit, as Motion's follower reads it (#441): what's left after its digits, `.` and `-`. */
119
+ export const unitOf = (value: string): string => value.replace(/[\d.-]/g, "")
120
+
121
+ /**
122
+ * `numbers`, a follow of a unit string's numbers, shown with `unit` (#441, Motion's follower: the
123
+ * unit its source started with, whatever a later one says). Its `jump` reaches `numbers`.
124
+ */
125
+ export const withUnit =
126
+ (unit: string) =>
127
+ (numbers: Atom.Atom<number>): Atom.Atom<string> => {
128
+ const strings = Atom.map(numbers, (n) => `${n}${unit}`)
129
+ UNIT_NUMBERS.set(strings, numbers)
130
+ return strings
131
+ }
132
+
133
+ /** A value a follow reads: a number as it is, a string as `parseFloat` reads it, as Motion's follower does. */
134
+ export const numberOf = (value: number | string): number =>
135
+ Bool.match(Predicate.isString(value), { onTrue: () => Number.parseFloat(value as string), onFalse: () => value as number })
136
+
137
+ /** `accessor`, carrying a follow's Atom, with `jump` run on `runtime`. */
138
+ export const followAccessorOf = <A extends number | string>(runtime: WardicServices.Runner<WardicServices.WardicServices>, accessor: Reactivity.Accessor<A>): FollowAccessor<A> => {
139
+ const atom = atomOf(accessor) as Atom.Atom<A>
140
+ // A follow's own Atom, by construction: the one kind `jump` takes (#618).
141
+ const numbers = UndefinedOr.match(UNIT_NUMBERS.get(atom), { onUndefined: () => atom, onDefined: (n) => n }) as unknown as LiveValue.Followed
142
+ return Object.assign(accessor, {
143
+ jump: (value: A): void => {
144
+ runtime.runSync(LiveValue.jump(numbers, numberOf(value)))
145
+ },
146
+ })
147
+ }
148
+
149
+ /** A server's follow: `read`, as it is now, and a `jump` that does nothing (ADR-0021). */
150
+ export const serverFollowOf = <A extends number | string>(read: Reactivity.Accessor<A>): FollowAccessor<A> => Object.assign(() => read(), { jump: constVoid })
151
+
152
+ /** The Atom a Live value is, or carries: `undefined` for a plain accessor or a plain value. Per key, per change: guards, no matcher. */
153
+ export const atomOf = (value: unknown): Atom.Atom<unknown> | undefined => {
154
+ if (Atom.isAtom(value)) return value as Atom.Atom<unknown>
155
+ if (Bool.not(Predicate.isFunction(value))) return undefined
156
+ return (value as { readonly [CARRIED]?: Atom.Atom<unknown> })[CARRIED]
157
+ }
158
+
159
+ /**
160
+ * `source` mapped through ranges by core (`LiveValue.transform`), for `createTransform` on an Atom: set
161
+ * where `source` is, and, when `source` derives from a scroll, described so an element runs it as a
162
+ * Timeline value (#240). Typed at `createTransform`'s overloads: numbers and strings through the
163
+ * registry, any type through a `mixer`.
164
+ */
165
+ export const rangesOf = (
166
+ source: Atom.Atom<unknown>,
167
+ input: ReadonlyArray<number>,
168
+ output: ReadonlyArray<unknown>,
169
+ options: LiveValue.TransformOptions<unknown> | undefined,
170
+ ): Effect.Effect<Atom.Atom<unknown>, never, InterpolatorRegistry.InterpolatorRegistry> =>
171
+ LiveValue.transform(source as Atom.Atom<number>, input, output as ReadonlyArray<number | string>, options as LiveValue.TransformOptions | undefined)
172
+
173
+ /** Whether `key` is a transform key, composed into `transform` (`x`, `scale`, `rotate`…). */
174
+ export const isTransformKey = (key: string): boolean => Option.isSome(BaseValue.transformIdentity(key))
175
+
176
+ /** A style value, read now: an Atom (or the one an accessor carries) through `registry`, an accessor untracked, anything else as it is. */
177
+ export const readLive = (value: unknown, registry: () => AtomRegistry.AtomRegistry, untrack: Reactivity.Reactivity["untrack"]): unknown => {
178
+ const atom = atomOf(value)
179
+ if (Predicate.isNotUndefined(atom)) return registry().get(atom)
180
+ if (Predicate.isFunction(value)) return untrack(value as Reactivity.Accessor<unknown>)
181
+ return value
182
+ }
183
+
184
+ /** Whether a style's `key` is routed: its value is live, or it's a transform key with a value. */
185
+ const isRouted = (value: unknown, key: string): boolean =>
186
+ Bool.and(Predicate.isNotNullish(value), Bool.or(isLive(value), isTransformKey(key)))
187
+
188
+ /** A user's style split: what its binding's `style` carries, and the routed keys' sources. */
189
+ export interface Split {
190
+ /** The style without the routed keys. The user's own when nothing is routed. */
191
+ readonly css: StyleInput
192
+ /** Each routed key's value as given: an Atom, an accessor, or a transform key's plain value. */
193
+ readonly routed: Readonly<Record<string, unknown>>
194
+ /** Whether a `transform` string was dropped for the transform keys. */
195
+ readonly droppedTransform: boolean
196
+ }
197
+
198
+ const NOTHING_ROUTED: Readonly<Record<string, unknown>> = {}
199
+ const NO_VALUES: Values.Values = {}
200
+ /** No style: nothing routed. */
201
+ const NO_STYLE: Split = { css: undefined, routed: NOTHING_ROUTED, droppedTransform: false }
202
+
203
+ /** A user's style, split into its binding's part and the routed keys (its text form read by its Environment's `ownValues`). */
204
+ export const split = (user: StyleInput, ownValues: OwnValues.Shape): Split => {
205
+ if (Predicate.isUndefined(user)) return NO_STYLE
206
+ const record = ownValues.recordOf(user)
207
+ const routed = Rec.filter(record, isRouted)
208
+ if (Rec.isEmptyRecord(routed)) return { css: user, routed: NOTHING_ROUTED, droppedTransform: false }
209
+ const droppedTransform = Bool.and(Arr.some(Rec.keys(routed), isTransformKey), Predicate.isNotNullish(record["transform"]))
210
+ // A `transform` string stays: the gate holds `transform` while a transform key is routed, so it's
211
+ // left out of what its binding writes, and shows again once none is.
212
+ const css = Rec.filter(record, (_, key) => Bool.not(Object.hasOwn(routed, key)))
213
+ return { css, routed, droppedTransform }
214
+ }
215
+
216
+ /** The routed keys' values, read now: the numbers and strings among them, as a values map. */
217
+ export const valuesOf = (
218
+ routed: Readonly<Record<string, unknown>>,
219
+ registry: () => AtomRegistry.AtomRegistry,
220
+ untrack: Reactivity.Reactivity["untrack"],
221
+ ): Values.Values =>
222
+ Bool.match(routed === NOTHING_ROUTED, {
223
+ onTrue: () => NO_VALUES,
224
+ onFalse: () => Stops.toValues(Rec.map(routed, (value) => readLive(value, registry, untrack))),
225
+ })
226
+
227
+ /** What the spine hears while it follows. */
228
+ export interface Follower {
229
+ /** A routed key's value changed, or its source did: `value` is its value now. */
230
+ readonly change: (key: string, value: unknown) => void
231
+ /** A routed key left the style. */
232
+ readonly removed: (key: string) => void
233
+ }
234
+
235
+ /** An element's routed `style` keys, seen through its `style` and followed from mount. */
236
+ export interface LiveStyle {
237
+ /** Sees the user's `style` (reconciling the routed keys), and gives the binding's part of it. Called where the binding reads it reactively. */
238
+ readonly css: (user: StyleInput) => StyleInput
239
+ /** The routed keys' values now, as a values map: the Starting style's. */
240
+ readonly values: () => Values.Values
241
+ /** Whether `key` is routed now. */
242
+ readonly routes: (key: string) => boolean
243
+ /** A routed key's value now, `None` when it isn't routed. */
244
+ readonly valueOf: (key: string) => Option.Option<unknown>
245
+ /** Whether a routed key's source is live, so a return to it follows it (decision 6). */
246
+ readonly isLive: (key: string) => boolean
247
+ /** The Atom a routed key's source is or carries, which may describe a Timeline value (#240); `undefined` for none. */
248
+ readonly atomOf: (key: string) => Atom.Atom<unknown> | undefined
249
+ /**
250
+ * Its `willChange`'s turn-on, when its style gives it a `createWillChange` value (#443), as
251
+ * `willChange` or `will-change`; `undefined` otherwise, at once for a style that routes nothing.
252
+ */
253
+ readonly willChange: () => (() => void) | undefined
254
+ /**
255
+ * Told the legs a Retarget starts: turns its element's will-change on (#443, Motion's
256
+ * `addValueToWillChange`) when its style gives it a `createWillChange` value and one of `legs`
257
+ * animates a transform key or another the compositor draws. A key already at its target starts no
258
+ * leg (#448), and a layout animation runs none, so neither does. Per start: a lookup in its routed
259
+ * keys, none for a style that routes nothing.
260
+ */
261
+ // #672 (PR4-Q1): the will-change decision is the DOM's, so the spine, in core, names none of it.
262
+ readonly started: (legs: ReadonlyArray<RetargetLegs.Leg>) => void
263
+ /** A style value read now, live or not. */
264
+ readonly read: (value: unknown) => unknown
265
+ /**
266
+ * Follow, from the first routed key on: `setup` is called once, at once if a key is routed now,
267
+ * else when one first is, and the follower it gives hears every change from then on, until
268
+ * `stop`. Its first call is where the element's routed keys are first written. An element whose
269
+ * `style` never routes a key never calls it.
270
+ */
271
+ readonly whenRouted: (setup: () => Follower) => void
272
+ /** Stop following, and every watch with it. */
273
+ readonly stop: () => void
274
+ }
275
+
276
+ /** What {@link createLiveStyle} reads. */
277
+ export interface LiveStyleOptions {
278
+ /** The registry Atoms are read through: the provider's on a client, a fresh one on a server. */
279
+ readonly registry: () => AtomRegistry.AtomRegistry
280
+ /** Called once, the first time a `transform` string is dropped for the transform keys. */
281
+ readonly onDroppedTransform?: (() => void) | undefined
282
+ /** The binding's reactivity: accessors are read untracked, and watched, through it (#209). */
283
+ readonly reactivity: Reactivity.Reactivity
284
+ /** Its Environment's reads of its Subjects' own values (#672): a `style`'s text form read through them. */
285
+ readonly ownValues: OwnValues.Shape
286
+ }
287
+
288
+ /** A {@link LiveStyle}'s state: one object per element, its methods on {@link Proto}. */
289
+ interface State extends LiveStyle {
290
+ readonly registry: () => AtomRegistry.AtomRegistry
291
+ readonly onDroppedTransform: (() => void) | undefined
292
+ readonly reactivity: Reactivity.Reactivity
293
+ readonly ownValues: OwnValues.Shape
294
+ routed: Readonly<Record<string, unknown>>
295
+ seen: StyleInput
296
+ last: StyleInput
297
+ warned: boolean
298
+ follower: Follower | undefined
299
+ // The follower's setup, until a key is first routed.
300
+ pending: (() => Follower) | undefined
301
+ // While following: each routed key's stop (an Atom's unsubscribe, an accessor's root disposal),
302
+ // made at the first watch: most elements watch none.
303
+ watching: Map<string, () => void> | undefined
304
+ }
305
+
306
+ /**
307
+ * Watch `key`'s live source for `to`: an Atom, or the one an accessor carries, subscribed; any
308
+ * other accessor in a computation of its own.
309
+ */
310
+ const watch = (self: State, key: string, source: unknown, to: Follower): void => {
311
+ if (Bool.not(isLive(source))) return
312
+ if (Predicate.isUndefined(self.watching)) self.watching = new Map()
313
+ const atom = atomOf(source)
314
+ if (Predicate.isNotUndefined(atom)) {
315
+ self.watching.set(key, self.registry().subscribe(atom, (value) => to.change(key, value)))
316
+ return
317
+ }
318
+ self.watching.set(key, self.reactivity.watch(source as Reactivity.Accessor<unknown>, (value) => to.change(key, value)))
319
+ }
320
+
321
+ const unwatch = (self: State, key: string): void => {
322
+ if (Predicate.isUndefined(self.watching)) return
323
+ const stop = self.watching.get(key)
324
+ if (Predicate.isUndefined(stop)) return
325
+ self.watching.delete(key)
326
+ stop()
327
+ }
328
+
329
+ /** Build the follower and watch every routed key. */
330
+ const start = (self: State, setup: () => Follower): void => {
331
+ self.pending = undefined
332
+ const to = setup()
333
+ self.follower = to
334
+ Arr.forEach(Rec.keys(self.routed), (key) => watch(self, key, self.routed[key], to))
335
+ }
336
+
337
+ /** The routed keys now `next`: what left is removed, what's new or changed is watched and told. */
338
+ const reconcile = (self: State, next: Readonly<Record<string, unknown>>): void => {
339
+ const prev = self.routed
340
+ // Nothing routed, as before: the usual style.
341
+ if (next === prev) return
342
+ self.routed = next
343
+ // The first routed key: the follower's setup writes them all.
344
+ if (Bool.and(Predicate.isNotUndefined(self.pending), Bool.not(Rec.isEmptyRecord(next)))) {
345
+ start(self, UndefinedOr.getOrThrow(self.pending))
346
+ return
347
+ }
348
+ const to = self.follower
349
+ if (Predicate.isUndefined(to)) return
350
+ Arr.forEach(Rec.keys(prev), (key) => {
351
+ if (Object.hasOwn(next, key)) return
352
+ unwatch(self, key)
353
+ to.removed(key)
354
+ })
355
+ Arr.forEach(Rec.keys(next), (key) => {
356
+ const source = next[key]
357
+ if (Bool.and(Object.hasOwn(prev, key), prev[key] === source)) return
358
+ unwatch(self, key)
359
+ watch(self, key, source, to)
360
+ to.change(key, readLive(source, self.registry, self.reactivity.untrack))
361
+ })
362
+ }
363
+
364
+ const Proto: Omit<LiveStyle, never> & ThisType<State> = {
365
+ started(legs) {
366
+ const turnOn = this.willChange()
367
+ if (Predicate.isUndefined(turnOn)) return
368
+ if (Arr.some(legs, (leg) => Arr.some(Rec.keys(leg.to), turnsWillChangeOn))) turnOn()
369
+ },
370
+ css(user) {
371
+ // The same style object as last time: the same answer (Solid may read `style` more than once).
372
+ if (Bool.and(user === this.seen, Predicate.isNotUndefined(this.seen))) return this.last
373
+ this.seen = user
374
+ const parts = split(user, this.ownValues)
375
+ if (Bool.and(parts.droppedTransform, Bool.not(this.warned))) {
376
+ this.warned = true
377
+ UndefinedOr.match(this.onDroppedTransform, { onUndefined: constVoid, onDefined: (warn) => warn() })
378
+ }
379
+ this.last = parts.css
380
+ reconcile(this, parts.routed)
381
+ return this.last
382
+ },
383
+ values() {
384
+ return valuesOf(this.routed, this.registry, this.reactivity.untrack)
385
+ },
386
+ routes(key) {
387
+ return Object.hasOwn(this.routed, key)
388
+ },
389
+ valueOf(key) {
390
+ return Option.map(Option.liftPredicate(this.routed, (routed) => Object.hasOwn(routed, key)), (routed) => readLive(routed[key], this.registry, this.reactivity.untrack))
391
+ },
392
+ isLive(key) {
393
+ return Bool.and(Object.hasOwn(this.routed, key), isLive(this.routed[key]))
394
+ },
395
+ atomOf(key) {
396
+ return atomOf(this.routed[key])
397
+ },
398
+ willChange() {
399
+ const routed = this.routed
400
+ if (routed === NOTHING_ROUTED) return undefined
401
+ if (Object.hasOwn(routed, "willChange")) return turnOnOf(routed["willChange"])
402
+ if (Object.hasOwn(routed, "will-change")) return turnOnOf(routed["will-change"])
403
+ return undefined
404
+ },
405
+ read(value) {
406
+ return readLive(value, this.registry, this.reactivity.untrack)
407
+ },
408
+ whenRouted(setup) {
409
+ if (Rec.isEmptyRecord(this.routed)) {
410
+ this.pending = setup
411
+ return
412
+ }
413
+ start(this, setup)
414
+ },
415
+ stop() {
416
+ this.follower = undefined
417
+ this.pending = undefined
418
+ const watching = this.watching
419
+ if (Predicate.isUndefined(watching)) return
420
+ Arr.forEach(Arr.fromIterable(watching.keys()), (key) => unwatch(this, key))
421
+ },
422
+ }
423
+
424
+ /**
425
+ * An element's {@link LiveStyle}: one object, its methods shared, so an element that routes nothing
426
+ * pays for little more than it. Creates computations for accessors while it follows; their roots
427
+ * are its own. Call its methods on it (`live.read(v)`), not detached.
428
+ */
429
+ export const createLiveStyle = (options: LiveStyleOptions): LiveStyle => {
430
+ const state: Omit<State, keyof LiveStyle> = {
431
+ registry: options.registry,
432
+ onDroppedTransform: options.onDroppedTransform,
433
+ reactivity: options.reactivity,
434
+ ownValues: options.ownValues,
435
+ routed: NOTHING_ROUTED,
436
+ seen: undefined,
437
+ last: undefined,
438
+ warned: false,
439
+ follower: undefined,
440
+ pending: undefined,
441
+ watching: undefined,
442
+ }
443
+ return Object.assign(Object.create(Proto), state)
444
+ }
445
+
446
+ /** A `createWillChange` value: `"auto"` until its element animates, then `"transform"`. */
447
+ // #443, Motion's `useWillChange`.
448
+ export type WillChange = "auto" | "transform"
449
+
450
+ /** Each `createWillChange` value's turn-on (#443), by its accessor and by the Atom it carries. */
451
+ // Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
452
+ const WILL_CHANGE = new WeakMap<object, () => void>()
453
+
454
+ /**
455
+ * A `createWillChange` value (#443): its Atom, `"auto"`, held in `registry` until `onCleanup` runs,
456
+ * as an accessor `wrap` makes. Its turn-on sets it to `"transform"`, once, for good, as Motion's
457
+ * `WillChangeMotionValue` stays enabled. The accessor and its Atom are both marked, so a `style` that
458
+ * routes either finds it.
459
+ */
460
+ export const willChangeOf = (
461
+ registry: AtomRegistry.AtomRegistry,
462
+ onCleanup: (fn: () => void) => void,
463
+ wrap: (atom: Atom.Atom<WillChange>) => Reactivity.Accessor<WillChange>,
464
+ ): Reactivity.Accessor<WillChange> => {
465
+ const atom = Atom.make<WillChange>("auto")
466
+ onCleanup(registry.mount(atom))
467
+ let on = false
468
+ const turnOn = (): void => {
469
+ if (on) return
470
+ on = true
471
+ registry.set(atom, "transform")
472
+ }
473
+ const accessor = wrap(atom)
474
+ WILL_CHANGE.set(atom, turnOn)
475
+ WILL_CHANGE.set(accessor, turnOn)
476
+ return accessor
477
+ }
478
+
479
+ /** A style value's will-change turn-on (#443), when it's a `createWillChange` value; `undefined` for anything else. */
480
+ const turnOnOf = (value: unknown): (() => void) | undefined => WILL_CHANGE.get(value as object)
481
+
482
+ /**
483
+ * The keys whose animation turns a will-change value on (#443, Motion's `addValueToWillChange`): the
484
+ * transform keys, and the ones a browser can animate on its compositor (Motion's `acceleratedValues`).
485
+ */
486
+ const ACCELERATED: ReadonlySet<string> = new Set(["transform", "opacity", "clipPath", "clip-path", "filter", "backgroundColor", "background-color"])
487
+
488
+ /** Whether animating `key` turns a will-change value on (#443). */
489
+ export const turnsWillChangeOn = (key: string): boolean => Bool.or(isTransformKey(key), ACCELERATED.has(key))
490
+
491
+ /** A server's registry, made on first need: an Atom read there gives the Atom's first value (ADR-0021). */
492
+ // Module state (#460, Q7): built once, on a server, where no provider's runtime runs.
493
+ let serverRegistry: AtomRegistry.AtomRegistry | undefined
494
+ export const serverRegistryOf = (): AtomRegistry.AtomRegistry => {
495
+ if (Predicate.isUndefined(serverRegistry)) serverRegistry = AtomRegistry.make()
496
+ return serverRegistry
497
+ }