@wardic/core 1.3.2 → 1.4.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.
- package/dist/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +15 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +218 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +7 -7
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +17 -16
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +5 -4
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +37 -14
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +1 -1
- package/dist/InputFeed.js +2 -2
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +7 -6
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +45 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +7 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +146 -45
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +6 -1
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +4 -3
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +49 -20
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +102 -81
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +13 -2
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -1
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +37 -38
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +39 -36
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +5 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +19 -19
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +53 -51
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +56 -49
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +2 -2
- package/dist/unstable/FrameEffects.js +2 -2
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +29 -9
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +79 -47
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +26 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +1 -1
- package/dist/unstable/Report.js +1 -1
- package/dist/unstable/RetargetLegs.d.ts +1 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +9 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +81 -72
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +152 -150
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +7 -7
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +11 -11
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +36 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +33 -33
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +236 -22
- package/src/Clock.ts +18 -17
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +41 -16
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +47 -17
- package/src/Machine.ts +199 -61
- package/src/Playback.ts +5 -1
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +69 -38
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +103 -87
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +20 -2
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +59 -56
- package/src/unstable/AppearHandoff.ts +6 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +19 -19
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +92 -82
- package/src/unstable/FrameEffects.ts +2 -2
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +126 -56
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +29 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +1 -1
- package/src/unstable/RetargetLegs.ts +10 -9
- package/src/unstable/Spine.ts +190 -188
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +13 -13
- package/src/unstable/VariantTree.ts +42 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
package/src/Recognizer.ts
CHANGED
|
@@ -125,44 +125,77 @@ const isUnpressedMove: Predicate.Predicate<InputSource.PointerLikeEvent> = /*#__
|
|
|
125
125
|
const endsPress: Predicate.Predicate<InputSource.PointerLikeEvent> = /*#__PURE__*/ Predicate.some([ofType("up"), ofType("cancel"), isUnpressedMove])
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
128
|
+
* A move with no button pressed that lands on the target: the pointer is over it. A held pointer's moves from
|
|
129
|
+
* elsewhere don't land on it, and a pressed one's may land there while it's elsewhere, its pointer captured.
|
|
130
|
+
*/
|
|
131
|
+
const isFreeMoveOnTarget: Predicate.Predicate<InputSource.PointerLikeEvent> = /*#__PURE__*/ Predicate.and(
|
|
132
|
+
ofType("move"),
|
|
133
|
+
(event) => Bool.and(event.onTarget, Bool.not(event.pressed)),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Whether `event` brings the pointer over a target `state` doesn't have it inside: a free move onto it, its
|
|
138
|
+
* enter missed because the watch began after it (a ward given to a Subject the pointer was already over).
|
|
139
|
+
*/
|
|
140
|
+
// Per pointer event: statements.
|
|
141
|
+
const arrivesUnannounced = (state: HoverState, event: InputSource.PointerLikeEvent): boolean => {
|
|
142
|
+
if (state.inside) return false
|
|
143
|
+
return isFreeMoveOnTarget(event)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** `state` once `event` ends its held pointer's press, if it does: nothing held, and no leave waiting on it. */
|
|
147
|
+
// Per pointer event: statements.
|
|
148
|
+
const released = (state: HoverState, event: InputSource.PointerLikeEvent): HoverState => {
|
|
149
|
+
if (event.pointerId !== state.held) return state
|
|
150
|
+
if (Bool.not(endsPress(event))) return state
|
|
151
|
+
return { ...state, held: null, deferred: false }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Hover's fold, after Motion's `hover`: touch never hovers; an enter while a drag is active (**Drag activity**)
|
|
130
156
|
* starts nothing; a leave while a pointer that went down on the target is held waits
|
|
131
157
|
* for that pointer's release, its cancel or its first unpressed move, then ends the
|
|
132
158
|
* hover unless the pointer came back in first. An enter during a drag doesn't count,
|
|
133
|
-
* so a dragged
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
* so a dragged Subject whose pointer left and came back ends its hover at the release,
|
|
160
|
+
* as Motion's does. A move onto the target while the pointer isn't inside comes over as
|
|
161
|
+
* its enter would: the watch began after that enter, so the first move is the hover's start.
|
|
162
|
+
*/
|
|
163
|
+
// `motion-dom/src/gestures/hover.ts` @ `16c6122` (ADR-0019); the release, its `hover.ts:78-81, 109-112`. The
|
|
164
|
+
// unannounced arrival is Wardic's own: Motion's listener is there before the pointer, a hook's ward may not be.
|
|
165
|
+
const hoverFold = (activity: DragActivity.Shape): Fold<HoverState, InputSource.PointerLikeEvent> => {
|
|
166
|
+
/** `state` with the pointer come over the target, as an enter or an unannounced move brings it: nothing while a drag is active. */
|
|
167
|
+
const comesOver = (state: HoverState): HoverState =>
|
|
168
|
+
Bool.match(activity.isDragActive(), { onTrue: () => state, onFalse: () => ({ ...state, inside: true, deferred: false }) })
|
|
169
|
+
return {
|
|
170
|
+
initial: noHover,
|
|
171
|
+
active: (s) => Bool.or(s.inside, s.deferred),
|
|
172
|
+
step: (s, e) =>
|
|
173
|
+
Match.value(e).pipe(
|
|
174
|
+
Match.when({ kind: "touch" }, () => s),
|
|
175
|
+
Match.when({ type: "enter" }, () => comesOver(s)),
|
|
176
|
+
Match.when({ type: "leave" }, () =>
|
|
177
|
+
Bool.match(s.inside, { onTrue: () => ({ ...s, inside: false, deferred: Predicate.isNotNull(s.held) }), onFalse: () => s }),
|
|
178
|
+
),
|
|
179
|
+
// Its enter came before the watch began: this move comes over in its place, and still ends a press it ends.
|
|
180
|
+
Match.when(
|
|
181
|
+
(move) => arrivesUnannounced(s, move),
|
|
182
|
+
(move) => released(comesOver(s), move),
|
|
183
|
+
),
|
|
184
|
+
// An adopted down's pointer went down elsewhere (#431): it holds nothing here.
|
|
185
|
+
Match.when({ adopted: true }, () => s),
|
|
186
|
+
Match.when({ type: "down" }, (down) =>
|
|
187
|
+
Option.match(Option.fromNullOr(s.held), { onNone: () => ({ ...s, held: down.pointerId }), onSome: () => s }),
|
|
188
|
+
),
|
|
189
|
+
Match.orElse((other) => released(s, other)),
|
|
158
190
|
),
|
|
159
|
-
|
|
160
|
-
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
161
193
|
|
|
162
194
|
/**
|
|
163
195
|
* Whether the pointer is over `target`: `true` once it comes over, `false` once it leaves, each change
|
|
164
196
|
* once. A leave while a pointer that pressed `target` is still held waits for its release. A touch never
|
|
165
|
-
* hovers, and no hover starts while a drag is active.
|
|
197
|
+
* hovers, and no hover starts while a drag is active. A pointer already over `target` as the stream
|
|
198
|
+
* begins, its coming over missed, comes over at its first move there with no button pressed.
|
|
166
199
|
*/
|
|
167
200
|
// After Motion's `hover` (ADR-0019).
|
|
168
201
|
export const hover = (target: unknown): Stream.Stream<boolean, never, InputSource.InputSource> =>
|
|
@@ -179,7 +212,7 @@ export interface HoverHandlers extends InputFeed.Handlers<Edge> {
|
|
|
179
212
|
/**
|
|
180
213
|
* Each move of the pointer over the target while the hover is on, which Motion's hover doesn't have. A
|
|
181
214
|
* touch never hovers, and a held pointer whose leave waits for its release isn't over the target, so
|
|
182
|
-
* neither moves it.
|
|
215
|
+
* neither moves it. A move that starts the hover, the pointer's coming over missed, is told after the start.
|
|
183
216
|
*/
|
|
184
217
|
// #397: Wardic's own.
|
|
185
218
|
readonly onMove?: ((event: InputSource.PointerLikeEvent) => void) | undefined
|
|
@@ -215,7 +248,7 @@ export type { AmongHandlers } from "./internal/watch.ts"
|
|
|
215
248
|
|
|
216
249
|
/**
|
|
217
250
|
* Each target's state in a watch over many targets: held weakly by a target that's an object, so a
|
|
218
|
-
* target gone mid-gesture (
|
|
251
|
+
* target gone mid-gesture (a Subject removed under the pointer, which hears no leave) keeps nothing.
|
|
219
252
|
*/
|
|
220
253
|
interface TargetStates<S> {
|
|
221
254
|
readonly get: (target: unknown) => S | undefined
|
|
@@ -307,10 +340,8 @@ const hoverHandleOf =
|
|
|
307
340
|
const next = fold.step(was, event)
|
|
308
341
|
MutableRef.set(state, next)
|
|
309
342
|
const active = fold.active(next)
|
|
310
|
-
if (active !== fold.active(was)) {
|
|
311
|
-
|
|
312
|
-
return true
|
|
313
|
-
}
|
|
343
|
+
if (active !== fold.active(was)) on({ active, event })
|
|
344
|
+
// After its edge: a move that started the hover, its enter missed, is its first move over the target too.
|
|
314
345
|
if (movesOver(next, event)) onMove(event)
|
|
315
346
|
return true
|
|
316
347
|
}
|
|
@@ -491,7 +522,7 @@ const keysOnOf = (options: PressOptions | undefined): LazyArg<boolean> => flagNo
|
|
|
491
522
|
|
|
492
523
|
/**
|
|
493
524
|
* `handle` for the keys a target's `keys` lets press it now (#712, Q32): a key's down while they're off is
|
|
494
|
-
* left to the
|
|
525
|
+
* left to the Environment, unstepped; a key's up is always stepped, so a press its down started ends.
|
|
495
526
|
*/
|
|
496
527
|
const whileKeysOn = (keysOn: LazyArg<boolean>) => (handle: (event: InputSource.KeyboardLikeEvent) => boolean) => (event: InputSource.KeyboardLikeEvent): boolean => {
|
|
497
528
|
if (event.type !== "down") return handle(event)
|
|
@@ -536,7 +567,7 @@ export const pressEvents = (target: unknown, options?: PressOptions): Stream.Str
|
|
|
536
567
|
* `handlers.onEnd` is told once every feed it watches has run out.
|
|
537
568
|
*
|
|
538
569
|
* Where the Environment says where focus is, its keys are watched only while focus is within the target,
|
|
539
|
-
* as Motion's press listens for keys once its
|
|
570
|
+
* as Motion's press listens for keys once its Subject has focus: a Subject at rest holds only its focus
|
|
540
571
|
* feed.
|
|
541
572
|
*/
|
|
542
573
|
// #318, ADR-0055. One fold over the target's pointer, keys and focus, each feed watched with its own
|
package/src/ReducedMotion.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reduced motion, as Motion does it: under it, a run's positional keys, the transforms and
|
|
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
|
|
38
|
+
* reads it as each Subject's animation starts.
|
|
39
39
|
*/
|
|
40
40
|
export const applies = (config: Config, prefersReducedMotion: boolean): boolean => {
|
|
41
|
-
// Per
|
|
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
|
|
52
|
-
* at once. Core names only
|
|
53
|
-
* adds the keys that size and place
|
|
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,
|
|
3
|
-
* context
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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,
|
package/src/ScrollSource.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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:
|
|
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>>
|
package/src/SharedSource.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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)
|