@wardic/core 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/dist/Arc.d.ts +2 -2
  2. package/dist/Arc.js +1 -1
  3. package/dist/BaseValue.d.ts +11 -10
  4. package/dist/BaseValue.d.ts.map +1 -1
  5. package/dist/BaseValue.js +12 -15
  6. package/dist/BaseValue.js.map +1 -1
  7. package/dist/Batch.d.ts +12 -6
  8. package/dist/Batch.d.ts.map +1 -1
  9. package/dist/Batch.js +374 -30
  10. package/dist/Batch.js.map +1 -1
  11. package/dist/Clock.d.ts +16 -0
  12. package/dist/Clock.d.ts.map +1 -1
  13. package/dist/Clock.js +22 -8
  14. package/dist/Clock.js.map +1 -1
  15. package/dist/DefaultTransition.d.ts +3 -2
  16. package/dist/DefaultTransition.d.ts.map +1 -1
  17. package/dist/DefaultTransition.js +5 -3
  18. package/dist/DefaultTransition.js.map +1 -1
  19. package/dist/Drag.d.ts +24 -9
  20. package/dist/Drag.d.ts.map +1 -1
  21. package/dist/Drag.js +10 -10
  22. package/dist/Drag.js.map +1 -1
  23. package/dist/DragActivity.js +3 -3
  24. package/dist/DragRecognizer.d.ts +14 -8
  25. package/dist/DragRecognizer.d.ts.map +1 -1
  26. package/dist/DragRecognizer.js +93 -34
  27. package/dist/DragRecognizer.js.map +1 -1
  28. package/dist/Easing.d.ts +1 -1
  29. package/dist/Easing.js +1 -1
  30. package/dist/Frame.d.ts.map +1 -1
  31. package/dist/Frame.js +5 -3
  32. package/dist/Frame.js.map +1 -1
  33. package/dist/InputFeed.d.ts +11 -8
  34. package/dist/InputFeed.d.ts.map +1 -1
  35. package/dist/InputFeed.js +18 -37
  36. package/dist/InputFeed.js.map +1 -1
  37. package/dist/InputSource.d.ts +3 -3
  38. package/dist/InputSource.js +2 -2
  39. package/dist/Interpolator.d.ts +2 -2
  40. package/dist/Interpolator.js +2 -2
  41. package/dist/InterpolatorRegistry.d.ts +29 -15
  42. package/dist/InterpolatorRegistry.d.ts.map +1 -1
  43. package/dist/InterpolatorRegistry.js +17 -8
  44. package/dist/InterpolatorRegistry.js.map +1 -1
  45. package/dist/LiveValue.d.ts +16 -9
  46. package/dist/LiveValue.d.ts.map +1 -1
  47. package/dist/LiveValue.js +204 -27
  48. package/dist/LiveValue.js.map +1 -1
  49. package/dist/Machine.d.ts +21 -8
  50. package/dist/Machine.d.ts.map +1 -1
  51. package/dist/Machine.js +184 -60
  52. package/dist/Machine.js.map +1 -1
  53. package/dist/Playback.d.ts.map +1 -1
  54. package/dist/Playback.js +16 -9
  55. package/dist/Playback.js.map +1 -1
  56. package/dist/Projection.d.ts +9 -9
  57. package/dist/Projection.js +2 -2
  58. package/dist/Recognizer.d.ts +2 -2
  59. package/dist/Recognizer.d.ts.map +1 -1
  60. package/dist/Recognizer.js +15 -10
  61. package/dist/Recognizer.js.map +1 -1
  62. package/dist/ReducedMotion.d.ts +4 -4
  63. package/dist/ReducedMotion.js +6 -6
  64. package/dist/Renderer.d.ts +5 -5
  65. package/dist/Renderer.js +6 -6
  66. package/dist/Renderer.js.map +1 -1
  67. package/dist/Reorder.d.ts +1 -1
  68. package/dist/Reorder.d.ts.map +1 -1
  69. package/dist/Reorder.js +2 -1
  70. package/dist/Reorder.js.map +1 -1
  71. package/dist/ScrollSource.d.ts +1 -1
  72. package/dist/ScrollSource.d.ts.map +1 -1
  73. package/dist/Sequence.d.ts +1 -1
  74. package/dist/SharedSource.d.ts +3 -3
  75. package/dist/SharedSource.js +5 -5
  76. package/dist/SharedSource.js.map +1 -1
  77. package/dist/Spring.d.ts.map +1 -1
  78. package/dist/Spring.js +2 -1
  79. package/dist/Spring.js.map +1 -1
  80. package/dist/Values.d.ts +2 -2
  81. package/dist/Values.js +1 -1
  82. package/dist/index.d.ts +1 -1
  83. package/dist/index.js +1 -1
  84. package/dist/internal/carried.d.ts +13 -0
  85. package/dist/internal/carried.d.ts.map +1 -0
  86. package/dist/internal/carried.js +23 -0
  87. package/dist/internal/carried.js.map +1 -0
  88. package/dist/internal/firstSteps.d.ts +66 -0
  89. package/dist/internal/firstSteps.d.ts.map +1 -0
  90. package/dist/internal/firstSteps.js +107 -0
  91. package/dist/internal/firstSteps.js.map +1 -0
  92. package/dist/internal/frameLoop.d.ts +11 -3
  93. package/dist/internal/frameLoop.d.ts.map +1 -1
  94. package/dist/internal/frameLoop.js +190 -39
  95. package/dist/internal/frameLoop.js.map +1 -1
  96. package/dist/internal/guarded.d.ts +16 -0
  97. package/dist/internal/guarded.d.ts.map +1 -0
  98. package/dist/internal/guarded.js +68 -0
  99. package/dist/internal/guarded.js.map +1 -0
  100. package/dist/internal/lerpsNumbers.d.ts +11 -0
  101. package/dist/internal/lerpsNumbers.d.ts.map +1 -0
  102. package/dist/internal/lerpsNumbers.js +38 -0
  103. package/dist/internal/lerpsNumbers.js.map +1 -0
  104. package/dist/internal/options.d.ts +7 -7
  105. package/dist/internal/options.d.ts.map +1 -1
  106. package/dist/internal/options.js +10 -10
  107. package/dist/internal/options.js.map +1 -1
  108. package/dist/internal/stepper.d.ts +21 -4
  109. package/dist/internal/stepper.d.ts.map +1 -1
  110. package/dist/internal/stepper.js +21 -5
  111. package/dist/internal/stepper.js.map +1 -1
  112. package/dist/internal/tracing.d.ts +1 -1
  113. package/dist/internal/tracing.js +1 -1
  114. package/dist/unstable/AnimationControls.d.ts +45 -39
  115. package/dist/unstable/AnimationControls.d.ts.map +1 -1
  116. package/dist/unstable/AnimationControls.js +59 -35
  117. package/dist/unstable/AnimationControls.js.map +1 -1
  118. package/dist/unstable/AppearHandoff.d.ts +11 -5
  119. package/dist/unstable/AppearHandoff.d.ts.map +1 -1
  120. package/dist/unstable/AppearHandoff.js.map +1 -1
  121. package/dist/unstable/BatchCalls.d.ts +2 -2
  122. package/dist/unstable/BatchCalls.js +5 -5
  123. package/dist/unstable/Config.d.ts +21 -17
  124. package/dist/unstable/Config.d.ts.map +1 -1
  125. package/dist/unstable/Config.js.map +1 -1
  126. package/dist/unstable/FirstSteps.d.ts +25 -0
  127. package/dist/unstable/FirstSteps.d.ts.map +1 -0
  128. package/dist/unstable/FirstSteps.js +2 -0
  129. package/dist/unstable/FirstSteps.js.map +1 -0
  130. package/dist/unstable/FlushGate.d.ts +54 -50
  131. package/dist/unstable/FlushGate.d.ts.map +1 -1
  132. package/dist/unstable/FlushGate.js +201 -77
  133. package/dist/unstable/FlushGate.js.map +1 -1
  134. package/dist/unstable/FrameEffects.d.ts +6 -3
  135. package/dist/unstable/FrameEffects.d.ts.map +1 -1
  136. package/dist/unstable/FrameEffects.js +14 -3
  137. package/dist/unstable/FrameEffects.js.map +1 -1
  138. package/dist/unstable/FrameTime.d.ts +1 -1
  139. package/dist/unstable/FrameTime.js +1 -1
  140. package/dist/unstable/Imperative.d.ts +42 -13
  141. package/dist/unstable/Imperative.d.ts.map +1 -1
  142. package/dist/unstable/Imperative.js +279 -88
  143. package/dist/unstable/Imperative.js.map +1 -1
  144. package/dist/unstable/MeasuredPairs.d.ts +6 -2
  145. package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
  146. package/dist/unstable/MeasuredPairs.js.map +1 -1
  147. package/dist/unstable/OwnValues.js +1 -1
  148. package/dist/unstable/PresenceRecord.d.ts +30 -26
  149. package/dist/unstable/PresenceRecord.d.ts.map +1 -1
  150. package/dist/unstable/PresenceRecord.js +8 -8
  151. package/dist/unstable/PresenceRecord.js.map +1 -1
  152. package/dist/unstable/Projector.d.ts +34 -0
  153. package/dist/unstable/Projector.d.ts.map +1 -0
  154. package/dist/unstable/Projector.js +9 -0
  155. package/dist/unstable/Projector.js.map +1 -0
  156. package/dist/unstable/Report.d.ts +8 -1
  157. package/dist/unstable/Report.d.ts.map +1 -1
  158. package/dist/unstable/Report.js +18 -2
  159. package/dist/unstable/Report.js.map +1 -1
  160. package/dist/unstable/RetargetLegs.d.ts +7 -1
  161. package/dist/unstable/RetargetLegs.d.ts.map +1 -1
  162. package/dist/unstable/RetargetLegs.js +24 -8
  163. package/dist/unstable/RetargetLegs.js.map +1 -1
  164. package/dist/unstable/Spine.d.ts +123 -68
  165. package/dist/unstable/Spine.d.ts.map +1 -1
  166. package/dist/unstable/Spine.js +319 -167
  167. package/dist/unstable/Spine.js.map +1 -1
  168. package/dist/unstable/Stops.d.ts +3 -3
  169. package/dist/unstable/Stops.js +4 -4
  170. package/dist/unstable/Subject.d.ts +2 -2
  171. package/dist/unstable/Subject.js +2 -2
  172. package/dist/unstable/Timelines.d.ts +11 -11
  173. package/dist/unstable/Timelines.d.ts.map +1 -1
  174. package/dist/unstable/Timelines.js +3 -3
  175. package/dist/unstable/VariantTarget.d.ts +32 -10
  176. package/dist/unstable/VariantTarget.d.ts.map +1 -1
  177. package/dist/unstable/VariantTarget.js +73 -20
  178. package/dist/unstable/VariantTarget.js.map +1 -1
  179. package/dist/unstable/VariantTree.d.ts +68 -34
  180. package/dist/unstable/VariantTree.d.ts.map +1 -1
  181. package/dist/unstable/VariantTree.js +83 -36
  182. package/dist/unstable/VariantTree.js.map +1 -1
  183. package/dist/unstable/WardicConfigValue.d.ts +13 -13
  184. package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
  185. package/dist/unstable/WardicConfigValue.js +4 -4
  186. package/dist/unstable/WardicConfigValue.js.map +1 -1
  187. package/package.json +1 -1
  188. package/src/Arc.ts +3 -3
  189. package/src/BaseValue.ts +18 -21
  190. package/src/Batch.ts +391 -27
  191. package/src/Clock.ts +29 -8
  192. package/src/DefaultTransition.ts +5 -3
  193. package/src/Drag.ts +32 -14
  194. package/src/DragActivity.ts +3 -3
  195. package/src/DragRecognizer.ts +118 -41
  196. package/src/Easing.ts +1 -1
  197. package/src/Frame.ts +5 -3
  198. package/src/InputFeed.ts +39 -42
  199. package/src/InputSource.ts +5 -5
  200. package/src/Interpolator.ts +3 -3
  201. package/src/InterpolatorRegistry.ts +22 -13
  202. package/src/LiveValue.ts +186 -30
  203. package/src/Machine.ts +252 -81
  204. package/src/Playback.ts +15 -9
  205. package/src/Projection.ts +9 -9
  206. package/src/Recognizer.ts +16 -10
  207. package/src/ReducedMotion.ts +6 -6
  208. package/src/Renderer.ts +6 -6
  209. package/src/Reorder.ts +3 -2
  210. package/src/ScrollSource.ts +1 -1
  211. package/src/Sequence.ts +1 -1
  212. package/src/SharedSource.ts +5 -5
  213. package/src/Spring.ts +2 -1
  214. package/src/Values.ts +2 -2
  215. package/src/index.ts +1 -1
  216. package/src/internal/carried.ts +22 -0
  217. package/src/internal/firstSteps.ts +139 -0
  218. package/src/internal/frameLoop.ts +203 -41
  219. package/src/internal/guarded.ts +69 -0
  220. package/src/internal/lerpsNumbers.ts +53 -0
  221. package/src/internal/options.ts +10 -10
  222. package/src/internal/stepper.ts +33 -6
  223. package/src/internal/tracing.ts +1 -1
  224. package/src/unstable/AnimationControls.ts +88 -57
  225. package/src/unstable/AppearHandoff.ts +13 -6
  226. package/src/unstable/BatchCalls.ts +5 -5
  227. package/src/unstable/Config.ts +23 -17
  228. package/src/unstable/FirstSteps.ts +26 -0
  229. package/src/unstable/FlushGate.ts +250 -108
  230. package/src/unstable/FrameEffects.ts +17 -4
  231. package/src/unstable/FrameTime.ts +1 -1
  232. package/src/unstable/Imperative.ts +342 -101
  233. package/src/unstable/MeasuredPairs.ts +7 -1
  234. package/src/unstable/OwnValues.ts +1 -1
  235. package/src/unstable/PresenceRecord.ts +33 -29
  236. package/src/unstable/Projector.ts +45 -0
  237. package/src/unstable/Report.ts +20 -2
  238. package/src/unstable/RetargetLegs.ts +24 -9
  239. package/src/unstable/Spine.ts +399 -202
  240. package/src/unstable/Stops.ts +6 -6
  241. package/src/unstable/Subject.ts +2 -2
  242. package/src/unstable/Timelines.ts +12 -12
  243. package/src/unstable/VariantTarget.ts +102 -23
  244. package/src/unstable/VariantTree.ts +123 -42
  245. package/src/unstable/WardicConfigValue.ts +13 -13
package/src/Projection.ts CHANGED
@@ -48,7 +48,7 @@ export interface Delta {
48
48
 
49
49
  /**
50
50
  * The key a projection pass writes each node's `Value` under, each frame, for its Environment's renderer
51
- * to draw as one transform with the element's own rotation and skew. Namespaced, `@projection`, so it
51
+ * to draw as one transform with the Subject's own rotation and skew. Namespaced, `@projection`, so it
52
52
  * never collides with an animated key.
53
53
  */
54
54
  // ADR-0009. `@wardic/dom`'s renderer's `project()` reads it in place of its normal transform grouping.
@@ -69,27 +69,27 @@ export interface Value {
69
69
  /** Its ancestors' scale, multiplied together. */
70
70
  readonly treeScale: Point.Point
71
71
  /**
72
- * A twin's Crossfade, from 0 to 1: the element's own opacity is multiplied by it. The lead
72
+ * A twin's Crossfade, from 0 to 1: the Subject's own opacity is multiplied by it. The lead
73
73
  * fades in, the followers fade out. Absent for a plain layout node, so its own opacity shows.
74
74
  */
75
75
  // ADR-0010.
76
76
  readonly opacity?: number
77
77
  /**
78
- * A handover's blended opacity, from 0 to 1: drawn as the element's opacity in place of its own and of
79
- * any crossfade, from the leaving element's opacity to its own over the handover. Absent otherwise.
78
+ * A handover's blended opacity, from 0 to 1: drawn as the Subject's opacity in place of its own and of
79
+ * any crossfade, from the leaving Subject's opacity to its own over the handover. Absent otherwise.
80
80
  */
81
81
  // A Switch's (ADR-0010, *Amendment (#166)*).
82
82
  readonly blendOpacity?: number
83
83
  /**
84
- * A handover's blended rotation, in degrees: drawn in place of the element's own `rotate`, from its
84
+ * A handover's blended rotation, in degrees: drawn in place of the Subject's own `rotate`, from its
85
85
  * twin's to its own over the handover. A follower is drawn with its lead's. Absent otherwise, so the
86
- * element's own `rotate` shows.
86
+ * Subject's own `rotate` shows.
87
87
  */
88
88
  // ADR-0010, *Amendment (#166)*.
89
89
  readonly rotate?: number
90
90
  /**
91
91
  * A raise above its siblings: while it's set, the renderer draws the node above them, as a dragged
92
- * Reorder item is while it's off its place. Absent at rest, so the element's own stacking shows.
92
+ * Reorder item is while it's off its place. Absent at rest, so the Subject's own stacking shows.
93
93
  */
94
94
  // ADR-0016, *Amendment (Reorder)*: Motion's Reorder item, `zIndex: 1`; `@wardic/dom` writes it as
95
95
  // `z-index`.
@@ -97,7 +97,7 @@ export interface Value {
97
97
  /**
98
98
  * Set on a follower: pointer input passes through it to what's beneath, so a follower drawn on its
99
99
  * lead's box never takes the lead's input, fading out or hidden at rest, as Motion's. How a renderer
100
- * lets it through is its Environment's. Absent on a lead, so the element's own value shows.
100
+ * lets it through is its Environment's. Absent on a lead, so the Subject's own value shows.
101
101
  */
102
102
  // ADR-0010, *Amendment (#165)*; `@wardic/dom`'s renderer.
103
103
  readonly passesPointer?: true
@@ -107,7 +107,7 @@ export interface Value {
107
107
  const REST_AXIS: AxisDelta = { translate: 0, scale: 1, origin: 0.5, originPoint: 0 }
108
108
 
109
109
  /**
110
- * A node drawn at its own box: no delta, no ancestors' scale. The renderer draws it with the element's
110
+ * A node drawn at its own box: no delta, no ancestors' scale. The renderer draws it with the Subject's
111
111
  * own rotation, skew and scale, and leaves its own move out, as it draws a layout node at rest. What a
112
112
  * server, which measures nothing, draws a layout node's starting style and mount animation with.
113
113
  */
package/src/Recognizer.ts CHANGED
@@ -32,6 +32,7 @@ import * as InputFeed from "./InputFeed.ts"
32
32
  import * as InputSource from "./InputSource.ts"
33
33
  import * as PressClaims from "./PressClaims.ts"
34
34
  import * as Probe from "./Probe.ts"
35
+ import { contextFor, switchedOn } from "./internal/guarded.ts"
35
36
  import { tracedScoped } from "./internal/tracing.ts"
36
37
  import { amongFeed, streamOf, watchFeed } from "./internal/watch.ts"
37
38
  import type { AmongHandlers } from "./internal/watch.ts"
@@ -124,14 +125,14 @@ const isUnpressedMove: Predicate.Predicate<InputSource.PointerLikeEvent> = /*#__
124
125
  const endsPress: Predicate.Predicate<InputSource.PointerLikeEvent> = /*#__PURE__*/ Predicate.some([ofType("up"), ofType("cancel"), isUnpressedMove])
125
126
 
126
127
  /**
127
- * Hover's fold, after Motion's `hover` (`motion-dom/src/gestures/hover.ts` @ `16c6122`,
128
- * ADR-0019): touch never hovers; an enter while a drag is active (**Drag activity**)
128
+ * Hover's fold, after Motion's `hover`: touch never hovers; an enter while a drag is active (**Drag activity**)
129
129
  * starts nothing; a leave while a pointer that went down on the target is held waits
130
130
  * for that pointer's release, its cancel or its first unpressed move, then ends the
131
131
  * hover unless the pointer came back in first. An enter during a drag doesn't count,
132
- * so a dragged element whose pointer left and came back ends its hover at the release
133
- * (Motion's `hover.ts:78-81, 109-112` do the same).
132
+ * so a dragged Subject whose pointer left and came back ends its hover at the release,
133
+ * as Motion's does.
134
134
  */
135
+ // `motion-dom/src/gestures/hover.ts` @ `16c6122` (ADR-0019); the release, its `hover.ts:78-81, 109-112`.
135
136
  const hoverFold = (activity: DragActivity.Shape): Fold<HoverState, InputSource.PointerLikeEvent> => ({
136
137
  initial: noHover,
137
138
  active: (s) => Bool.or(s.inside, s.deferred),
@@ -187,7 +188,7 @@ export interface HoverHandlers extends InputFeed.Handlers<Edge> {
187
188
  /**
188
189
  * Watches hover on `target` while the Scope is open: `handlers.on` hears each start and end, as
189
190
  * `hoverEvents` tells them, and `handlers.onMove` each move over it while the hover is on, inside the
190
- * pointer event's dispatch. A throw from either goes to `handlers.onDefect`.
191
+ * pointer event's dispatch. A run of throws from either goes to `handlers.onDefect` at its first.
191
192
  *
192
193
  * @example
193
194
  * yield* Recognizer.watchHover(card, {
@@ -214,7 +215,7 @@ export type { AmongHandlers } from "./internal/watch.ts"
214
215
 
215
216
  /**
216
217
  * Each target's state in a watch over many targets: held weakly by a target that's an object, so a
217
- * target gone mid-gesture (an element removed under the pointer, which hears no leave) keeps nothing.
218
+ * target gone mid-gesture (a Subject removed under the pointer, which hears no leave) keeps nothing.
218
219
  */
219
220
  interface TargetStates<S> {
220
221
  readonly get: (target: unknown) => S | undefined
@@ -490,7 +491,7 @@ const keysOnOf = (options: PressOptions | undefined): LazyArg<boolean> => flagNo
490
491
 
491
492
  /**
492
493
  * `handle` for the keys a target's `keys` lets press it now (#712, Q32): a key's down while they're off is
493
- * left to the page, unstepped; a key's up is always stepped, so a press its down started ends.
494
+ * left to the Environment, unstepped; a key's up is always stepped, so a press its down started ends.
494
495
  */
495
496
  const whileKeysOn = (keysOn: LazyArg<boolean>) => (handle: (event: InputSource.KeyboardLikeEvent) => boolean) => (event: InputSource.KeyboardLikeEvent): boolean => {
496
497
  if (event.type !== "down") return handle(event)
@@ -535,7 +536,7 @@ export const pressEvents = (target: unknown, options?: PressOptions): Stream.Str
535
536
  * `handlers.onEnd` is told once every feed it watches has run out.
536
537
  *
537
538
  * Where the Environment says where focus is, its keys are watched only while focus is within the target,
538
- * as Motion's press listens for keys once its element has focus: an element at rest holds only its focus
539
+ * as Motion's press listens for keys once its Subject has focus: a Subject at rest holds only its focus
539
540
  * feed.
540
541
  */
541
542
  // #318, ADR-0055. One fold over the target's pointer, keys and focus, each feed watched with its own
@@ -560,6 +561,8 @@ export const watchPress: (
560
561
  if (told.phase === "start") claims.mark(event, target, Bool.not(propagates()))
561
562
  }
562
563
  const focusWithin = input.focusWithin
564
+ // What its keys' switch reports a throw on with no `onDefect` (#979, row 27): this watch's context.
565
+ const context = yield* contextFor(handlers.onDefect)
563
566
  const state = MutableRef.make(noPress)
564
567
  const feeds = MutableRef.make(feedsWatched(keys, Predicate.isNotUndefined(focusWithin)))
565
568
  // The keys while focus is within the target (#460): made at the first focus, let go with the watches.
@@ -601,7 +604,7 @@ export const watchPress: (
601
604
  }
602
605
  // Keys only while focus is within the target (#460), from a focus, or from now when it already is.
603
606
  const openKeys = (): void => {
604
- if (Predicate.isUndefined(keysNow)) keysNow = InputFeed.switched(input.keyboard(target), onKey(), handlers.onDefect)
607
+ if (Predicate.isUndefined(keysNow)) keysNow = switchedOn(input.keyboard(target), onKey(), handlers.onDefect, context)
605
608
  keysNow.open()
606
609
  }
607
610
  const blurs = onFocus()
@@ -660,6 +663,8 @@ export const watchPressAmong: (
660
663
  const pointer = yield* amongFeed(input.pointerAmong, "pointerAmong")
661
664
  const focusAmong = input.focusAmong
662
665
  const keys = Bool.and(keysPressOf(options), Predicate.isNotUndefined(focusAmong))
666
+ // What each target's keys report a throw on with no `onDefect` (#979, row 27): this watch's context.
667
+ const context = yield* contextFor(handlers.onDefect)
663
668
  const keyed = whileKeysOn(keysOnOf(options))
664
669
  const propagates = propagatesOf(options)
665
670
  // Each target with a press held, and each focused target's keys.
@@ -709,13 +714,14 @@ export const watchPressAmong: (
709
714
  marking(event, told)
710
715
  takeSpace(event, told)
711
716
  }
712
- const keysNow = InputFeed.switched(
717
+ const keysNow = switchedOn(
713
718
  input.keyboard(target),
714
719
  keyed((event) => {
715
720
  stepOn(target, event, keyStep(activity, claims, target), keyPressOf, keyTaken)
716
721
  return true
717
722
  }),
718
723
  handlers.onDefect,
724
+ context,
719
725
  )
720
726
  keysOf.set(target, keysNow)
721
727
  keysNow.open()
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Reduced motion, as Motion does it: under it, a run's positional keys, the transforms and an element's
2
+ * Reduced motion, as Motion does it: under it, a run's positional keys, the transforms and a Subject's
3
3
  * position and size, land where the run would end, and every other key, an opacity or a colour, animates
4
4
  * as ever. `applies` says whether it's on, `split` divides a target by its Environment's
5
5
  * `PositionalKeys`, and `snap` lands the positional ones.
@@ -35,10 +35,10 @@ export type Config = "user" | "always" | "never"
35
35
 
36
36
  /**
37
37
  * Whether reduced motion applies under `config`, given whether the user prefers reduced motion. A binding
38
- * reads it as each element's animation starts.
38
+ * reads it as each Subject's animation starts.
39
39
  */
40
40
  export const applies = (config: Config, prefersReducedMotion: boolean): boolean => {
41
- // Per element at mount (#540): statements.
41
+ // Per Subject at mount (#540): statements.
42
42
  if (config === "always") return true
43
43
  if (config === "never") return false
44
44
  return prefersReducedMotion
@@ -48,9 +48,9 @@ export const applies = (config: Config, prefersReducedMotion: boolean): boolean
48
48
  export const isTransform = (key: string): boolean => Option.isSome(BaseValue.transformIdentity(key))
49
49
 
50
50
  /**
51
- * An Environment's Positional keys: the keys that move or resize its elements, which reduced motion lands
52
- * at once. Core names only the transforms (`transformsOnly`); an Environment adds its own, as `@wardic/dom`
53
- * adds the keys that size and place an element's box.
51
+ * An Environment's Positional keys: the keys that move or resize its Subjects, which reduced motion lands
52
+ * at once. Core names only its transforms (`transformsOnly`); an Environment adds its own, as `@wardic/dom`
53
+ * adds its own transform keys and the keys that size and place a Subject's box.
54
54
  */
55
55
  // CONTEXT.md; ADR-0029, ADR-0036; `@wardic/dom`'s `PositionalKeysDomLive`. A binding reads it
56
56
  // once, as it reads the Probe, and passes it to `split`.
package/src/Renderer.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * The Renderer: how an Environment writes animated values to what it draws, an element, a canvas
3
- * context, a native view. It has two halves: `project`, pure, turns a Frame's values into the
2
+ * The Renderer: how an Environment writes animated values to what it draws, its Subjects, such
3
+ * as a canvas context or a native view. It has two halves: `project`, pure, turns a Frame's values into the
4
4
  * Environment's own `Patch`, grouping keys as it likes; and `commit` writes a patch onto a target, now.
5
- * A binding writes its elements through its flush; `applyTo` writes a Frame stream outside one.
5
+ * A binding writes its Subjects through its flush; `applyTo` writes a Frame stream outside one.
6
6
  *
7
7
  * @example
8
8
  * import * as Renderer from "@wardic/core/Renderer"
@@ -25,11 +25,11 @@ import { traced } from "./internal/tracing.ts"
25
25
  export type Patch = Record<string, unknown>
26
26
 
27
27
  /**
28
- * An Environment's renderer. Both halves are plain functions, not Effects: they run once per element per
28
+ * An Environment's renderer. Both halves are plain functions, not Effects: they run once per Subject per
29
29
  * frame. `target` is the Environment's own, opaque to core.
30
30
  */
31
31
  // ADR-0002. `project` is pure, so the Starting style reuses it and no grouping or unit logic is
32
- // duplicated. The flush gate commits every binding element's patch once per Refresh frame (ADR-0006,
32
+ // duplicated. The flush gate commits every Subject's patch once per Refresh frame (ADR-0006,
33
33
  // ADR-0034); an Effect round trip per call would cost a fiber each (ADR-0034,
34
34
  // docs/agents/effect-first.md). `@wardic/dom`'s renderer takes an element as its target.
35
35
  export class Renderer extends Context.Service<Renderer, {
@@ -42,7 +42,7 @@ export class Renderer extends Context.Service<Renderer, {
42
42
  /**
43
43
  * Writes each Frame of `stream` onto `target`, projecting its values and committing them, one commit per
44
44
  * Frame: for a Frame stream outside a binding, a canvas's, a native view's, a test's. A binding's
45
- * elements go through its flush instead. `stream` gives Frames of a record of values, as
45
+ * Subjects go through its flush instead. `stream` gives Frames of a record of values, as
46
46
  * `Machine.springValues` and `Machine.animateValues` do.
47
47
  *
48
48
  * @example
package/src/Reorder.ts CHANGED
@@ -43,7 +43,7 @@ import { dual } from "./internal/dual.ts"
43
43
  // Motion's Reorder/types.ts @ 16c6122. Tier 2 (ADR-0008): Effect-free, for binding and Environment authors.
44
44
  export type Axis = "x" | "y" | "xy"
45
45
 
46
- /** An item as `check` sees it: its value and its layout box, its place in the list, not where it paints while it's dragged. */
46
+ /** An item as `check` sees it: its value and its layout box, its place in the list, not where it's drawn while it's dragged. */
47
47
  // Motion's `ItemData` (Reorder/types.ts @ 16c6122). Tier 2 (ADR-0008).
48
48
  export interface ItemData<V> {
49
49
  /** The item's value in the list. */
@@ -212,7 +212,8 @@ interface Line<V> {
212
212
  readonly max: number
213
213
  }
214
214
 
215
- /** Motion's `"xy"` branch (check-reorder.ts:17-51 at 16c6122). */
215
+ /** Motion's `"xy"` branch. */
216
+ // `check-reorder.ts:17-51` at 16c6122.
216
217
  const checkReorderXY = <V>(
217
218
  order: ReadonlyArray<ItemData<V>>,
218
219
  index: number,
@@ -45,7 +45,7 @@ export interface Scroll {
45
45
  export interface Options {
46
46
  /** The scroll container: the Environment's own when left out. */
47
47
  readonly container?: unknown
48
- /** An element whose progress through the container `progress` reads, on `axis`. */
48
+ /** A Subject whose progress through the container `progress` reads, on `axis`. */
49
49
  readonly target?: unknown
50
50
  /**
51
51
  * Where on `axis` the target's progress runs, from 0 to 1, in the Environment's own terms, which it
package/src/Sequence.ts CHANGED
@@ -89,7 +89,7 @@ export type Transition =
89
89
  * each key's transition (a key without one runs on a 0.3 s `easeOut` tween), and where it starts.
90
90
  */
91
91
  export interface Segment<S> {
92
- /** What it animates: elements, or anything a binding animates, such as a callback's value. */
92
+ /** What it animates: Subjects, or anything a binding animates, such as a callback's value. */
93
93
  readonly subjects: ReadonlyArray<S>
94
94
  /** Each key's value, or its stops, or a function of each subject's index and count that gives them. */
95
95
  readonly target: Readonly<Record<string, Value>>
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Shared sources, for the Streams an Environment hands out: each hot and counted, so however many
3
3
  * subscribe, one underlying source runs, started by the first subscriber and stopped when the last one
4
- * leaves. `byTarget` keeps one per target, one observer on each element, and `make` one for the whole
4
+ * leaves. `byTarget` keeps one per target, one observer on each Subject, and `make` one for the whole
5
5
  * Environment. An Environment builds its sources with these, as `@wardic/dom` does, and `counted` shares
6
6
  * anything else it opens per target.
7
7
  *
@@ -18,7 +18,7 @@
18
18
  //
19
19
  // One shape under both constructors (#518, ADR-0067 *Amendment (#518)*, decision 3): a target's entry in
20
20
  // a `counted` map holds its subscribers' hearings and, while any subscriber holds it, a pump that runs the
21
- // cold source and hands each element to every hearing, which resumes a waiting subscriber inside the
21
+ // cold source and hands each value to every hearing, which resumes a waiting subscriber inside the
22
22
  // call, as the `PubSub` did. The first subscriber opens the entry and starts the pump; the
23
23
  // last one's release interrupts it, and the cold source's finalizers run (a listener is removed). The
24
24
  // source's end ends every subscriber, and its failure fails them (#618, decision 6). It replaced a
@@ -47,12 +47,12 @@ interface Held<V> {
47
47
  /**
48
48
  * Values shared by key and counted: the first hold of a key opens its value with `open`, later holds
49
49
  * share it, and the last one's release closes it with `close`. A key is held by identity and never
50
- * hashed, so a DOM node is its own key. `open` runs inline, so it mustn't wait.
50
+ * hashed, so a Subject is its own key. `open` runs inline, so it mustn't wait.
51
51
  *
52
52
  * @example
53
53
  * // One listener set per container, however many readers hold it
54
54
  * const containers = SharedSource.counted(
55
- * (container: Element) => ({ remove: listenTo(container) }),
55
+ * (container: object) => ({ remove: listenTo(container) }),
56
56
  * (listening) => Effect.sync(listening.remove),
57
57
  * )
58
58
  * const listening = yield* containers(list) // held until the current Scope closes
@@ -93,7 +93,7 @@ interface Fanned<A> {
93
93
  /** A fresh source's entry, with no subscriber, no pump and no end. */
94
94
  const fanned = <A>(): Fanned<A> => ({ hearings: new Set(), pump: Option.none(), ended: Option.none() })
95
95
 
96
- /** The pump: `acquire`'s source, each element to every subscriber; its end, kept and handed to each. */
96
+ /** The pump: `acquire`'s source, each value to every subscriber; its end, kept and handed to each. */
97
97
  const pumpOf = <A>(entry: Fanned<A>, acquire: Effect.Effect<Stream.Stream<A>, never, Scope.Scope>): Effect.Effect<void> =>
98
98
  Effect.scoped(
99
99
  Effect.flatMap(acquire, (source) => Stream.runForEach(source, (a) => Effect.sync(() => Iter.forEach(entry.hearings, (hearing) => hearing.hear(a))))),
package/src/Spring.ts CHANGED
@@ -178,10 +178,11 @@ const ROOT_ITERATIONS = Arr.range(1, 11)
178
178
 
179
179
  /**
180
180
  * The stiffness and damping (mass 1) of a spring that settles in `duration` seconds with `bounce`:
181
- * Motion's `findSpring`, ported (`motion-dom`'s `spring.ts`, at 16c6122), at velocity 0, as Motion
181
+ * Motion's `findSpring`, ported, at velocity 0, as Motion
182
182
  * solves it, so an inherited velocity can't throw its parameters off. Newton's method from Motion's
183
183
  * first guess, 12 iterations; one that fails (NaN) falls back to Motion's 100 / 10.
184
184
  */
185
+ // `motion-dom`'s `spring.ts`, at 16c6122.
185
186
  const solveDuration = (duration: number, bounce: number): { readonly stiffness: number; readonly damping: number } => {
186
187
  const ratio = ratioOf(bounce)
187
188
  const seconds = within(duration, MIN_DURATION, MAX_DURATION)
package/src/Values.ts CHANGED
@@ -22,7 +22,7 @@ export type Values = Record<string, number | string>
22
22
  /** A named animation state's values. */
23
23
  export type Variant = Record<string, number | string>
24
24
 
25
- /** Named animation states, which the elements of a component tree share by name. */
25
+ /** Named animation states, which the Subjects of a component tree share by name. */
26
26
  export type Variants = Record<string, Variant>
27
27
 
28
28
  /** A bag's keys by kind: its numbers, which a spring moves, and its strings, which are blended by a progress. */
@@ -45,7 +45,7 @@ export const split = (values: Readonly<Values>): Split => ({
45
45
 
46
46
  /**
47
47
  * `self`'s values for the keys `keysFrom` has, leaving out a key `self` lacks or holds `undefined` for:
48
- * where an animation's keys start, from the element's values for the keys it animates to.
48
+ * where an animation's keys start, from the Subject's values for the keys it animates to.
49
49
  *
50
50
  * @example
51
51
  * const from = Values.pick(current, target) // current's values for target's keys
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * `DefaultTransition`) are each `X.X`, with the shared constructors the Environments build on
11
11
  * (`Clock.layer`, `Clock.fromRefreshFrames`, `InputSource.heldPointer`, `InputFeed.byTarget`,
12
12
  * `InterpolatorRegistry.layer`, `FrameLoop.layer`, `DefaultTransition.layerOneSpring`). Each module's
13
- * page is at https://wardic.dev/reference/core.
13
+ * reference is at https://wardic.dev/reference/core.
14
14
  */
15
15
  // A module per data type or CONTEXT.md term: ADR-0028. Primitives as machines, run as Streams or on
16
16
  // the Frame loop: ADR-0001, ADR-0027. Design decisions and the glossary: `docs/adr/` and `CONTEXT.md`.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A value a service carries beside its stable shape, under a key of its own: how core hands Wardic's own code
3
+ * what a stable service doesn't say, with no member added to the service.
4
+ *
5
+ * @internal
6
+ */
7
+ // #1030 (a Renderer's projector, `unstable/Projector.ts`) and #1036 (the registry's number check,
8
+ // `internal/lerpsNumbers.ts`). A spread of the service keeps what it carries: a symbol key is copied too.
9
+ import * as Option from "effect/Option"
10
+ import * as Predicate from "effect/Predicate"
11
+
12
+ /** `self`, carrying `value` under `key`. */
13
+ export const carry = <S extends object>(self: S, key: symbol, value: unknown): S => ({ ...self, [key]: value })
14
+
15
+ /** What `self` carries under `key`, when `is` holds of it; `None` otherwise. */
16
+ export const carriedOf = <A>(self: object, key: symbol, is: Predicate.Refinement<unknown, A>): Option.Option<A> => {
17
+ // Per leg (#460): statements.
18
+ if (!Predicate.hasProperty(self, key)) return Option.none()
19
+ const value = self[key]
20
+ if (!is(value)) return Option.none()
21
+ return Option.some(value)
22
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The late-frame rule for a run's first steps, on plain numbers: a run takes none of a long task's time from
3
+ * before it began. A long task delays a frame, a **Late frame**. Stamped when it was due, the frame is told late
4
+ * by its lag (its callback ran past the line after its timestamp), and the next frame's dt holds the task's time:
5
+ * a run made in the task leaves the frame's lateness out of its second step, and one made in its Late window and
6
+ * first stepped at a later tick, out of its first. Stamped near when it ran, the frame's own gap from the one
7
+ * before holds the task's time, as the gap after a frame told late does: a frame whose gap is more than one and a
8
+ * half of the frames' interval is late by the rest (`lateByGap`), and a run's first step there leaves its
9
+ * lateness out, one interval.
10
+ *
11
+ * A run keeps one number, what it owes (`owed`): `NaN` until its first step, or less than 0 for one made in the
12
+ * Late window of a frame told late by its lag, by the frame's lateness (`madeOwing`); then its first frame's
13
+ * lateness, which its second step leaves out; then 0. A run that owes 0 steps at the tick's dt.
14
+ *
15
+ * @internal
16
+ */
17
+ // #1028 (ADR-0027 *Amendment (#1028)*): #1026's rule, out of the Frame loop's entries, so a Batch's members,
18
+ // on one run, keep it per member. The Frame loop carries a `Reader` of its ticks for them (`internal/carried.ts`).
19
+ // Per frame, for a run or a member that owes: plain math. #1050 (ADR-0027 *Amendment (#1050)*): a frame told late by
20
+ // its gap, in place of #1048's line a run waited past, which missed a run made late in the task: WebKit and Gecko
21
+ // stamp a late frame near when it ran, so its lag never tells it. #1053: "late", where #1050 said "held", which is
22
+ // Foldkit's **Held frame** (CONTEXT.md).
23
+ import * as Option from "effect/Option"
24
+ import * as Predicate from "effect/Predicate"
25
+ import * as Clock from "../Clock.ts"
26
+ import { carriedOf, carry } from "./carried.ts"
27
+
28
+ /** `dt`, less `left` seconds left out of it: `floor` at least, and never more than `dt`. */
29
+ const leavingOut = (dt: number, left: number, floor: number): number => Math.min(dt, Math.max(dt - left, floor))
30
+
31
+ /** A 60 Hz frame, in ms: the Frame loop takes one for a gap it hasn't timed. */
32
+ export const NOMINAL_FRAME_MS = Clock.NOMINAL_DT * 1000
33
+
34
+ /** A 30 Hz frame, in ms: the longest interval `intervalOf` gives, so late frames one after another don't lift it. */
35
+ const SLOWEST_FRAME_MS = 1000 / 30
36
+
37
+ /** The median of `a`, `b` and `c`. */
38
+ const medianOf3 = (a: number, b: number, c: number): number => Math.max(Math.min(a, b), Math.min(Math.max(a, b), c))
39
+
40
+ /**
41
+ * The frames' interval, in ms, from the last five gaps between their timestamps, `gap` and the four before it,
42
+ * newest first: their median, so neither a late frame's long gap nor a short one after it moves it, and a 30 Hz
43
+ * frame at most.
44
+ */
45
+ // The median of five: of the four before, the least and the most can't be it, so it's the median of the two
46
+ // between them and `gap`.
47
+ export const intervalOf = (gap: number, before1: number, before2: number, before3: number, before4: number): number =>
48
+ Math.min(
49
+ medianOf3(Math.max(Math.min(before1, before2), Math.min(before3, before4)), Math.min(Math.max(before1, before2), Math.max(before3, before4)), gap),
50
+ SLOWEST_FRAME_MS,
51
+ )
52
+
53
+ /** How late a frame whose callback ran `lag` ms after its timestamp is by its lag, in ms: all of it, past `line`; else 0. */
54
+ export const lateByLag = (lag: number, line: number): number => {
55
+ if (lag > line) return lag
56
+ return 0
57
+ }
58
+
59
+ /**
60
+ * How late a frame `gap` ms after the one before is by its gap, in ms, on frames `interval` ms apart: what its gap
61
+ * is longer than one interval, once that's more than half of one; else 0.
62
+ */
63
+ export const lateByGap = (gap: number, interval: number): number => {
64
+ const longer = gap - interval
65
+ if (longer > interval / 2) return longer
66
+ return 0
67
+ }
68
+
69
+ /** What a run made now owes: its first step, made in a frame `madeLate` seconds late by its lag, or in one on time. */
70
+ export const madeOwing = (madeLate: number): number => {
71
+ if (madeLate > 0) return -madeLate
72
+ return Number.NaN
73
+ }
74
+
75
+ /**
76
+ * The dt of a step of a run that owes `owed` (not 0), in a frame `lateByGap` seconds late by its gap, on frames
77
+ * `interval` seconds apart: its second, `dt` less its first frame's lateness by its lag; its first, `dt` less its
78
+ * frame's lateness by its gap, or less what it owes of a frame told late by its lag, for one made in that frame's
79
+ * Late window and stepped at a later tick, whichever is more, and one interval at least. That frame's own Late
80
+ * step leaves only `lateByGap` out: its dt doesn't hold the frame's lateness by its lag.
81
+ */
82
+ export const owingDt = (owed: number, dt: number, lateStep: boolean, lateByGap: number, interval: number): number => {
83
+ if (owed > 0) return leavingOut(dt, owed, Clock.NOMINAL_DT)
84
+ return leavingOut(dt, Math.max(lateByGap, owedLateByLag(owed, lateStep)), interval)
85
+ }
86
+
87
+ /**
88
+ * What a run's first step owes of a frame told late by its lag, in seconds: what a run made in its Late window
89
+ * owes, at a later tick; nothing at that frame's own Late step, whose dt doesn't hold it, or for a run that owes
90
+ * `NaN`.
91
+ */
92
+ const owedLateByLag = (owed: number, lateStep: boolean): number => {
93
+ if (owed < 0 && !lateStep) return -owed
94
+ return 0
95
+ }
96
+
97
+ /** What a run that owed `owed` owes after a step in a frame `lateByLag` seconds late by its lag: that, after its first; else nothing. */
98
+ export const owedAfter = (owed: number, lateByLag: number): number => {
99
+ if (owed > 0) return 0
100
+ return lateByLag
101
+ }
102
+
103
+ /**
104
+ * The Frame loop's ticks as the rule reads them, for a run that keeps it per member: what one made now owes,
105
+ * and the dt of a step of one that owes, in the tick or Late step running now. Stateless: it reads the loop.
106
+ */
107
+ export interface Reader {
108
+ /** What a member made now owes (`madeOwing`): 0, nothing, where the loop tells no late frame. */
109
+ readonly madeOwing: () => number
110
+ /**
111
+ * The dt of a step, now, of a member that owes `owed` (not 0): `owingDt`'s. A step in a tick's Late window,
112
+ * after its steps, is a Late step: the loop's own, or one a run takes there itself.
113
+ */
114
+ readonly owingDt: (owed: number, dt: number) => number
115
+ /** What a member that owed `owed` owes after its step now: `owedAfter`'s. */
116
+ readonly owedAfter: (owed: number) => number
117
+ }
118
+
119
+ /** A `Reader` under which nothing owes: for a loop that carries none, so its runs step at the tick's dt. */
120
+ export const owingNothing: Reader = {
121
+ madeOwing: () => 0,
122
+ owingDt: (_owed, dt) => dt,
123
+ owedAfter: () => 0,
124
+ }
125
+
126
+ /** Where the Frame loop carries its `Reader`, under a key no other module can name. */
127
+ const KEY: unique symbol = Symbol("@wardic/core/internal/firstSteps")
128
+
129
+ /** Whether a value is what `carrying` carries. Only `carrying` writes `KEY`, so its fields are read as they are. */
130
+ const isReader = Predicate.and(
131
+ Predicate.hasProperty("madeOwing"),
132
+ Predicate.and(Predicate.hasProperty("owingDt"), Predicate.hasProperty("owedAfter")),
133
+ ) as Predicate.Refinement<unknown, Reader>
134
+
135
+ /** `loop`, carrying `reader`. */
136
+ export const carrying = <L extends object>(loop: L, reader: Reader): L => carry(loop, KEY, reader)
137
+
138
+ /** The `Reader` `loop` carries: `None` for a loop that carries none (one a test makes of its own). */
139
+ export const readerOf = (loop: object): Option.Option<Reader> => carriedOf(loop, KEY, isReader)