@wardic/core 1.3.2 → 1.5.0-next.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.
- 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 +8 -6
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +51 -16
- 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 +9 -3
- package/dist/InputSource.d.ts.map +1 -1
- package/dist/InputSource.js +2 -2
- package/dist/InputSource.js.map +1 -1
- 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 +8 -19
- package/dist/Projection.d.ts.map +1 -1
- package/dist/Projection.js +3 -19
- package/dist/Projection.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +22 -7
- 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 +12 -2
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +65 -37
- 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/projectionRest.d.ts +22 -0
- package/dist/internal/projectionRest.d.ts.map +1 -0
- package/dist/internal/projectionRest.js +20 -0
- package/dist/internal/projectionRest.js.map +1 -0
- 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 +31 -27
- 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 +171 -164
- 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 +43 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +34 -34
- 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 +65 -23
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +12 -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 +10 -28
- package/src/Recognizer.ts +24 -8
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +84 -38
- 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/projectionRest.ts +31 -0
- 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 +34 -30
- 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 +210 -201
- 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 +50 -43
- package/src/unstable/WardicConfigValue.ts +13 -13
package/src/DragActivity.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Drag activity: how many drags are active, and which
|
|
2
|
+
* Drag activity: how many drags are active, and which Subject holds each axis. While a
|
|
3
3
|
* drag is active no hover and no press starts, as Motion's; and a drag that claims an axis another
|
|
4
|
-
*
|
|
4
|
+
* Subject holds is refused, so a nested drag on the same axis doesn't move both. A drag counts in once
|
|
5
5
|
* it's past its threshold, and counts off at its end or when it's interrupted. `DragRecognizer`'s drags
|
|
6
6
|
* keep it; a recognizer of your own reads it, or counts in and claims as a drag does.
|
|
7
7
|
*
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* import * as DragActivity from "@wardic/core/DragActivity"
|
|
13
13
|
*
|
|
14
14
|
* const activity = yield* DragActivity.DragActivity
|
|
15
|
-
* const release = activity.claim(card, "x") // None when another
|
|
15
|
+
* const release = activity.claim(card, "x") // None when another Subject holds x
|
|
16
16
|
* activity.isDragActive() // true until it's released
|
|
17
17
|
*/
|
|
18
18
|
// ADR-0019, decision 3b (Drag activity), and *Amendment (#29)* (Drag claims): Motion's `isDragging`
|
package/src/DragRecognizer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The pointer's drags and pans. `drag` is a Stream of `Drag.Sample`s as a pointer drags `target`, kept
|
|
3
|
-
* to its axis, and refused when another
|
|
3
|
+
* to its axis, and refused when another Subject holds that axis; `pan` gives the same samples with a
|
|
4
4
|
* session's start at each down, moves nothing, and stops no drag. `watchDrag` and `watchPan` call you
|
|
5
5
|
* with each sample inside its pointer event's dispatch while a Scope is open, with no fiber of their own:
|
|
6
6
|
* a binding's drags run on these. They're apart from `Recognizer`'s gestures, so an app that never drags
|
|
@@ -114,6 +114,13 @@ type StaleRule = "unpressed move" | "second down"
|
|
|
114
114
|
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
115
115
|
const staleEnds = /*#__PURE__*/ new WeakMap<Drag.Sample, StaleRule>()
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* The cancels folded in place of a release whose point its mapping couldn't give ({@link standInFor}):
|
|
119
|
+
* a release all the same, which {@link onRelease} ends as one, with its moves' velocity.
|
|
120
|
+
*/
|
|
121
|
+
// Module state (#1042): a mark held weakly by the event it's on, so it goes with it.
|
|
122
|
+
const unmappedReleases = /*#__PURE__*/ new WeakSet<InputSource.PointerLikeEvent>()
|
|
123
|
+
|
|
117
124
|
/** No samples: the event changes nothing a consumer sees. */
|
|
118
125
|
const NO_SAMPLES: ReadonlyArray<Drag.Sample> = []
|
|
119
126
|
|
|
@@ -136,6 +143,7 @@ const staleEnd = (state: DragState, rule: StaleRule, timeStamp: number, raw: unk
|
|
|
136
143
|
scroll: state.lastScroll,
|
|
137
144
|
raw,
|
|
138
145
|
axis: "xy",
|
|
146
|
+
endedBy: "lost",
|
|
139
147
|
}
|
|
140
148
|
staleEnds.set(sample, rule)
|
|
141
149
|
return [sample]
|
|
@@ -207,19 +215,26 @@ const onRelease = (state: DragState, event: InputSource.PointerLikeEvent): Step
|
|
|
207
215
|
onFalse: () => [initState, NO_SAMPLES],
|
|
208
216
|
onTrue: () => {
|
|
209
217
|
// A cancel's coordinates aren't the pointer's (Chromium's pointercancel carries
|
|
210
|
-
// (0, 0)), so it ends at the last move's point,
|
|
211
|
-
//
|
|
218
|
+
// (0, 0)), so it ends at the last move's point, as Motion's pan session does
|
|
219
|
+
// (PanSession.ts:329-333 at 16c6122). With no velocity, where Motion's keeps the
|
|
220
|
+
// moves': a gesture the platform took away doesn't fling, as a lost release doesn't
|
|
221
|
+
// (#1042, ADR-0019's *Amendment (#1042)*).
|
|
222
|
+
// A release its mapping couldn't place comes as a cancel too, and ends at the last point all the
|
|
223
|
+
// same, but it was let go: a release, with its moves' velocity (#1000, #1042).
|
|
212
224
|
const sample: Drag.Sample = Bool.match(event.type === "cancel", {
|
|
213
225
|
onTrue: () => ({
|
|
214
226
|
point: state.last,
|
|
215
227
|
offset: { x: state.last.x - state.origin.x, y: state.last.y - state.origin.y },
|
|
216
228
|
delta: { x: 0, y: 0 },
|
|
217
|
-
velocity: windowVelocity(state.history),
|
|
218
229
|
phase: "end",
|
|
219
230
|
timeStamp: event.timeStamp,
|
|
220
231
|
scroll: state.lastScroll,
|
|
221
232
|
raw: event.raw,
|
|
222
233
|
axis: "xy",
|
|
234
|
+
...Bool.match(unmappedReleases.has(event), {
|
|
235
|
+
onTrue: (): Pick<Drag.Sample, "velocity" | "endedBy"> => ({ velocity: windowVelocity(state.history), endedBy: "release" }),
|
|
236
|
+
onFalse: (): Pick<Drag.Sample, "velocity" | "endedBy"> => ({ velocity: { x: 0, y: 0 }, endedBy: "cancel" }),
|
|
237
|
+
}),
|
|
223
238
|
}),
|
|
224
239
|
onFalse: () => {
|
|
225
240
|
const point = pointOf(event)
|
|
@@ -235,6 +250,7 @@ const onRelease = (state: DragState, event: InputSource.PointerLikeEvent): Step
|
|
|
235
250
|
scroll: event.scroll,
|
|
236
251
|
raw: event.raw,
|
|
237
252
|
axis: "xy",
|
|
253
|
+
endedBy: "release",
|
|
238
254
|
}
|
|
239
255
|
},
|
|
240
256
|
})
|
|
@@ -302,8 +318,9 @@ const onMove = (state: DragState, event: InputSource.PointerLikeEvent, starts: S
|
|
|
302
318
|
/**
|
|
303
319
|
* The gesture ended from outside its pointer (#431, Motion's drag controls): an `"end"` at its last
|
|
304
320
|
* point, with that event's time and platform event, as a cancel's. `stop`'s has the moves' velocity,
|
|
305
|
-
* a release; `cancel`'s none, marked `cancelled`. A gesture that hasn't
|
|
306
|
-
* as a tap does. Either way its pointer's later events are left out,
|
|
321
|
+
* a release; `cancel`'s none, ended by `"controls"` and marked `cancelled`. A gesture that hasn't
|
|
322
|
+
* started resets with no sample, as a tap does. Either way its pointer's later events are left out,
|
|
323
|
+
* until a down claims again.
|
|
307
324
|
*/
|
|
308
325
|
const endedFromOutside = (state: DragState, cancelled: boolean): Step =>
|
|
309
326
|
Bool.match(state.phase === "active", {
|
|
@@ -313,14 +330,17 @@ const endedFromOutside = (state: DragState, cancelled: boolean): Step =>
|
|
|
313
330
|
point: state.last,
|
|
314
331
|
offset: { x: state.last.x - state.origin.x, y: state.last.y - state.origin.y },
|
|
315
332
|
delta: { x: 0, y: 0 },
|
|
316
|
-
velocity: Bool.match(cancelled, { onTrue: () => ({ x: 0, y: 0 }), onFalse: () => windowVelocity(state.history) }),
|
|
317
333
|
phase: "end",
|
|
318
334
|
timeStamp: Option.match(Arr.last(state.history), { onNone: () => 0, onSome: (p) => p.timeStamp }),
|
|
319
335
|
scroll: state.lastScroll,
|
|
320
336
|
raw: state.lastRaw,
|
|
321
337
|
axis: "xy",
|
|
338
|
+
...Bool.match(cancelled, {
|
|
339
|
+
onTrue: (): Pick<Drag.Sample, "velocity" | "endedBy" | "cancelled"> => ({ velocity: { x: 0, y: 0 }, endedBy: "controls", cancelled: true }),
|
|
340
|
+
onFalse: (): Pick<Drag.Sample, "velocity" | "endedBy"> => ({ velocity: windowVelocity(state.history), endedBy: "release" }),
|
|
341
|
+
}),
|
|
322
342
|
}
|
|
323
|
-
return [initState, [
|
|
343
|
+
return [initState, [end]]
|
|
324
344
|
},
|
|
325
345
|
})
|
|
326
346
|
|
|
@@ -389,10 +409,11 @@ export interface DragOptions {
|
|
|
389
409
|
readonly lock?: boolean | undefined
|
|
390
410
|
/**
|
|
391
411
|
* `false`: a press on the target starts no gesture, only a down handed to it does, as Motion's
|
|
392
|
-
* `dragListener={false}` with drag controls. Default `true`: both do.
|
|
412
|
+
* `dragListener={false}` with drag controls. Default `true`: both do. A predicate is asked of each
|
|
413
|
+
* down, which it hears: a target whose presses drag it only where they land, on a part of it.
|
|
393
414
|
*/
|
|
394
|
-
// #431, **Drag controls
|
|
395
|
-
readonly listen?: boolean | undefined
|
|
415
|
+
// #431, **Drag controls**; a predicate: probe: behaviour-runes, a binding's handles inside the target.
|
|
416
|
+
readonly listen?: boolean | ((down: InputSource.PointerLikeEvent) => boolean) | undefined
|
|
396
417
|
/**
|
|
397
418
|
* `true`: the target was given drag controls, so the drag reads the pointer feed that also delivers the
|
|
398
419
|
* downs they hand it (`InputSource.adoptablePointerOf`), and its `WatchedDrag` ends a gesture from
|
|
@@ -417,7 +438,8 @@ export interface DragOptions {
|
|
|
417
438
|
*
|
|
418
439
|
* A mapping that throws is reported through `onDefect`, once a run of throws, and the gesture goes on
|
|
419
440
|
* without that point: a move is left out; a release ends the gesture at its last point, with its moves'
|
|
420
|
-
* velocity,
|
|
441
|
+
* velocity, a release all the same (`endedBy: "release"`); a down starts nothing, and ends a gesture its
|
|
442
|
+
* pointer had left open.
|
|
421
443
|
*/
|
|
422
444
|
// #443; an `Option` (#618, A1). #1000 (ADR-0074): the points mapped, and a throw's.
|
|
423
445
|
readonly mapPoint?: LazyArg<Option.Option<PointMap>> | undefined
|
|
@@ -464,14 +486,18 @@ const mappedEvents = (mapPoint: DragOptions["mapPoint"]): ((event: InputSource.P
|
|
|
464
486
|
|
|
465
487
|
/**
|
|
466
488
|
* The event folded in place of one whose point its mapping can't give, an event whose point isn't read:
|
|
467
|
-
* a release's a cancel, which ends the gesture at its last
|
|
468
|
-
* unpressed move, a lost release, which ends a gesture of its
|
|
469
|
-
* with no velocity, and starts none. None for a move, left out.
|
|
489
|
+
* a release's a cancel marked as a release ({@link unmappedReleases}), which ends the gesture at its last
|
|
490
|
+
* point with its moves' velocity; a down's an unpressed move, a lost release, which ends a gesture of its
|
|
491
|
+
* pointer's still open, at its last point with no velocity, and starts none. None for a move, left out.
|
|
470
492
|
*/
|
|
471
493
|
// #1000 (ADR-0074): a release left out kept its gesture going, active and claimed, until the next press;
|
|
472
494
|
// a down left out kept one a lost release had left open, for good while the mapping threw at each down.
|
|
473
495
|
const standInFor: (event: InputSource.PointerLikeEvent) => Option.Option<InputSource.PointerLikeEvent> = /*#__PURE__*/ Match.type<InputSource.PointerLikeEvent>().pipe(
|
|
474
|
-
Match.when({ type: "up" }, (up) =>
|
|
496
|
+
Match.when({ type: "up" }, (up) => {
|
|
497
|
+
const standIn: InputSource.PointerLikeEvent = { ...up, type: "cancel" }
|
|
498
|
+
unmappedReleases.add(standIn)
|
|
499
|
+
return Option.some(standIn)
|
|
500
|
+
}),
|
|
475
501
|
Match.when({ type: "down" }, (down) => Option.some<InputSource.PointerLikeEvent>({ ...down, type: "move", pressed: false })),
|
|
476
502
|
Match.orElse(() => Option.none()),
|
|
477
503
|
)
|
|
@@ -523,16 +549,32 @@ export interface WatchedDrag {}
|
|
|
523
549
|
export interface AdoptableDrag extends WatchedDrag {
|
|
524
550
|
/** Ends the gesture as its pointer's release would: an `"end"` at its last point, with its moves' velocity. */
|
|
525
551
|
readonly stop: () => void
|
|
526
|
-
/** Ends the gesture where it is: an `"end"` with no velocity,
|
|
552
|
+
/** Ends the gesture where it is: an `"end"` with no velocity, `endedBy: "controls"` (and the deprecated `cancelled`). */
|
|
527
553
|
readonly cancel: () => void
|
|
528
554
|
}
|
|
529
555
|
|
|
530
556
|
/** A plain watch's ends from outside (#539): shared, and doing nothing. */
|
|
531
557
|
const NO_ENDS: AdoptableDrag = { stop: constVoid, cancel: constVoid }
|
|
532
558
|
|
|
559
|
+
/** A drag's `listen`: whether it hears its own presses, or which of them. */
|
|
560
|
+
type Listen = boolean | ((down: InputSource.PointerLikeEvent) => boolean)
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Which downs a drag claims by its `listen` (#431): every one, only those adopted, or those it's asked
|
|
564
|
+
* of and says it hears, and those adopted (probe: behaviour-runes, the hooks' Grips). Built once, at module load.
|
|
565
|
+
*/
|
|
566
|
+
const claimsOf: (listen: Listen) => (down: InputSource.PointerLikeEvent) => boolean = /*#__PURE__*/ Match.type<Listen>().pipe(
|
|
567
|
+
/*#__PURE__*/ Match.when(true, () => constTrue),
|
|
568
|
+
/*#__PURE__*/ Match.when(false, () => isAdopted),
|
|
569
|
+
/*#__PURE__*/ Match.orElse((hears) => (down: InputSource.PointerLikeEvent): boolean => {
|
|
570
|
+
if (hears(down)) return true
|
|
571
|
+
return isAdopted(down)
|
|
572
|
+
}),
|
|
573
|
+
)
|
|
574
|
+
|
|
533
575
|
/** A drag's downs (#431): its own presses unless it doesn't `listen`, and those it adopted; each gesture's threshold its `threshold`'s, else 3. */
|
|
534
|
-
const dragDownsOf = (listen:
|
|
535
|
-
claims:
|
|
576
|
+
const dragDownsOf = (listen: Listen, threshold: DragOptions["threshold"]): Downs => ({
|
|
577
|
+
claims: claimsOf(listen),
|
|
536
578
|
thresholdOf: UndefinedOr.match(threshold, {
|
|
537
579
|
onUndefined: () => () => THRESHOLD,
|
|
538
580
|
onDefined: (of) => (down: InputSource.PointerLikeEvent) => Option.getOrElse(of(down), () => THRESHOLD),
|
|
@@ -547,8 +589,8 @@ const DRAG_FOLD = /*#__PURE__*/ stepOf(pastThreshold, EVERY_DOWN)
|
|
|
547
589
|
const LOCKED_FOLD = /*#__PURE__*/ stepOf(locks, EVERY_DOWN)
|
|
548
590
|
|
|
549
591
|
/** A drag's fold (#431): a shared one for {@link EVERY_DOWN} (#539), else built for its own downs. */
|
|
550
|
-
const dragFoldOf = (lock: boolean, listen:
|
|
551
|
-
Bool.match(Bool.and(listen, Predicate.isUndefined(threshold)), {
|
|
592
|
+
const dragFoldOf = (lock: boolean, listen: Listen, threshold: DragOptions["threshold"]) =>
|
|
593
|
+
Bool.match(Bool.and(listen === true, Predicate.isUndefined(threshold)), {
|
|
552
594
|
onTrue: () => Bool.match(lock, { onTrue: () => LOCKED_FOLD, onFalse: () => DRAG_FOLD }),
|
|
553
595
|
onFalse: () => stepOf(Bool.match(lock, { onTrue: () => locks, onFalse: () => pastThreshold }), dragDownsOf(listen, threshold)),
|
|
554
596
|
})
|
|
@@ -701,7 +743,7 @@ export const drag = (target: unknown, options: DragOptions = {}): Stream.Stream<
|
|
|
701
743
|
* - **It starts** once the pointer has moved `threshold` px, 3 by default, from its down.
|
|
702
744
|
* - **Its axis is claimed** at its `"start"`, before `on` hears it, and counts as an active drag, so no
|
|
703
745
|
* hover or press starts elsewhere while it's on. Every watch on one target shares the claim. When
|
|
704
|
-
* another
|
|
746
|
+
* another Subject holds an axis it needs, the gesture is refused: it tells nothing until its end, as a
|
|
705
747
|
* tap tells nothing, and doesn't retry. Of nested drags, the innermost claims first. With `claim: false`
|
|
706
748
|
* it only counts.
|
|
707
749
|
* - **Its claim is given back** at its `"end"`, before `on` hears it, or when the Scope closes mid-drag,
|
|
@@ -868,7 +910,7 @@ const panStep = (state: DragState, event: InputSource.PointerLikeEvent): PanStep
|
|
|
868
910
|
* A pan claims no axis, so it never stops a drag, nested or not, and no drag stops it. Once started it
|
|
869
911
|
* counts as an active drag until its end, so a press it took over ends as neither a tap nor a cancel,
|
|
870
912
|
* and no hover starts meanwhile: that's Wardic's, not Motion's, whose swipe let go over a tappable
|
|
871
|
-
*
|
|
913
|
+
* Subject taps it too.
|
|
872
914
|
*/
|
|
873
915
|
// #273, ADR-0047: no **Drag claim**; counted in the **Drag activity**. Motion's pan is invisible to its
|
|
874
916
|
// drag lock.
|
package/src/Easing.ts
CHANGED
|
@@ -161,7 +161,7 @@ export const easeInOutBounce: Easing = (t) => {
|
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
163
|
* A cubic Bézier easing through the control points `(x1, y1)` and `(x2, y2)`. An `ease` of
|
|
164
|
-
* `[x1, y1, x2, y2]` is the same. `x1` and `x2` are from 0 to 1,
|
|
164
|
+
* `[x1, y1, x2, y2]` is the same. `x1` and `x2` are from 0 to 1, so the curve is a function of time;
|
|
165
165
|
* `y1` and `y2` may be any finite number, so the curve may overshoot. Anything else throws an
|
|
166
166
|
* `OptionError` naming the point, as an `ease` given in a transition does.
|
|
167
167
|
*
|
package/src/Frame.ts
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* if (Frame.isPhysics(frame)) speed = frame.velocity
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
15
|
-
// CONTEXT.md's Frame; docs/adr/0001-core-stream-contract.md. A plain shape,
|
|
16
|
-
//
|
|
17
|
-
//
|
|
15
|
+
// CONTEXT.md's Frame; docs/adr/0001-core-stream-contract.md. A plain shape, with no methods (ADR-0028,
|
|
16
|
+
// decision 1): a step allocates one every tick, or rewrites one per run in place, as `springValues`', a
|
|
17
|
+
// tween's, the blends' and `keyframesValues`' do (ADR-0030, decision 11 and *Amendments (#895, #1031)*). A
|
|
18
|
+
// tween's is a class's instance, still with no methods, so V8 gives it a hidden class of its own (#1031).
|
|
19
|
+
// Only the physics Primitives (`spring`, `decay`, `chase`)
|
|
18
20
|
// emit `velocity`, the field `isPhysics` narrows on.
|
|
19
21
|
import * as Predicate from "effect/Predicate"
|
|
20
22
|
|
package/src/InputFeed.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* can still prevent the platform's default. `watchWith` is its form for a handler that can stop.
|
|
9
9
|
* - **`toStream`** gives a feed's events as a Stream, still inside the dispatch.
|
|
10
10
|
* - **`byTarget`** shares one target's feed among everyone who subscribes to it, so hover, press and
|
|
11
|
-
* drag on one
|
|
11
|
+
* drag on one Subject start one source, not three.
|
|
12
12
|
* - **`switched`** is a subscription its owner opens and closes, for a feed it needs only some of the
|
|
13
13
|
* time.
|
|
14
14
|
*
|
|
@@ -180,7 +180,7 @@ export interface Switch {
|
|
|
180
180
|
* A subscription to `feed` its owner opens and closes, each event handed to `handle` inside its emit, a
|
|
181
181
|
* run of throws to `onDefect` at its first. With none, the run is reported then on Effect's default runtime, as
|
|
182
182
|
* a subscription has no context of its own, and it goes on. For a feed a watch needs only some of the time: a keyboard
|
|
183
|
-
* press holds its target's keys only while focus is within it, so
|
|
183
|
+
* press holds its target's keys only while focus is within it, so a Subject at rest holds none. The feed
|
|
184
184
|
* running out ends nothing; its owner closes it when it's done.
|
|
185
185
|
*/
|
|
186
186
|
// #460: a **Keyboard press**.
|
package/src/InputSource.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Input from the Environment: the `InputSource` service, which gives each target's pointer, keys and
|
|
3
3
|
* focus as Input feeds, and the events they carry, in core's own terms, so no recognizer reads a
|
|
4
4
|
* platform's events. An Environment provides it, mapping its platform's events onto these, as
|
|
5
|
-
* `@wardic/dom` does. A target is the Environment's own, opaque to core:
|
|
6
|
-
* graph.
|
|
5
|
+
* `@wardic/dom` does. A target is the Environment's own, opaque to core: a Subject, or a part of one,
|
|
6
|
+
* such as a node in a scene graph.
|
|
7
7
|
* `heldPointer` is how an Environment builds a target's pointer feed: once a pointer goes down on the
|
|
8
8
|
* target, its moves and its release keep reaching it wherever they land.
|
|
9
9
|
*
|
|
@@ -269,15 +269,22 @@ export class InputSource extends Context.Service<InputSource, {
|
|
|
269
269
|
readonly focus: (target: unknown) => InputFeed.InputFeed<FocusLikeEvent>
|
|
270
270
|
/**
|
|
271
271
|
* Whether focus is now on `target` or inside it, from an Environment that can say. A keyboard press
|
|
272
|
-
* then holds its target's keys only while it is, as Motion's listens for keys once its
|
|
273
|
-
* focus, so
|
|
272
|
+
* then holds its target's keys only while it is, as Motion's listens for keys once its Subject has
|
|
273
|
+
* focus, so a Subject at rest holds none. Absent: a keyboard press holds the keys throughout, for an
|
|
274
274
|
* Environment whose keys can reach a target without its focus.
|
|
275
275
|
*/
|
|
276
276
|
// #460: a **Keyboard press**.
|
|
277
277
|
readonly focusWithin?: ((target: unknown) => boolean) | undefined
|
|
278
|
+
/**
|
|
279
|
+
* The focus on `target` now, or inside it, as `focus(target)` would tell it, from an Environment that
|
|
280
|
+
* can say; `None` while there's none. A focus watch begun with the focus already there starts from it,
|
|
281
|
+
* where its feed tells only what comes after. Absent: a watch starts with nothing told.
|
|
282
|
+
*/
|
|
283
|
+
// Probe: hooks-first, the Reorder round's RF4.
|
|
284
|
+
readonly focusNow?: ((target: unknown) => Option.Option<FocusLikeEvent>) | undefined
|
|
278
285
|
/**
|
|
279
286
|
* `pointer(target)` with the downs `adoptPointer` hands `target` too: for a target that can be handed
|
|
280
|
-
* one, a drag given drag controls. The plain `pointer` then subscribes to no handing, so
|
|
287
|
+
* one, a drag given drag controls. The plain `pointer` then subscribes to no handing, so a Subject
|
|
281
288
|
* that's only hovered or pressed pays for none. Absent: `pointer` delivers the handed downs itself.
|
|
282
289
|
*/
|
|
283
290
|
// #431, #507: **Drag controls**.
|
package/src/Interpolator.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface Entry<Decoded, Encoded> {
|
|
|
60
60
|
readonly format: (value: Decoded) => Encoded
|
|
61
61
|
/**
|
|
62
62
|
* Two read endpoints' blend: the closure the frame calls with `t`, or `None`. Pure, and so is the
|
|
63
|
-
* closure: a blend is kept and shared, so one pair's closure serves every
|
|
63
|
+
* closure: a blend is kept and shared, so one pair's closure serves every Subject animating it, and
|
|
64
64
|
* state kept between calls would leak from one to the next.
|
|
65
65
|
*/
|
|
66
66
|
readonly blend: (from: Decoded, to: Decoded) => Option.Option<(t: number) => Encoded>
|
|
@@ -122,7 +122,7 @@ const endAt = (to: ReadonlyArray<number>, index: number, fallback: number): numb
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
* Two arrays' blend,
|
|
125
|
+
* Two arrays' blend, item by item, `from`'s length: past `to`'s end an item holds
|
|
126
126
|
* `from`'s. On the per-frame path (ADR-0025): a counted loop into a new array each frame, and no
|
|
127
127
|
* closure per frame.
|
|
128
128
|
*/
|
|
@@ -137,7 +137,7 @@ const blendArrays =
|
|
|
137
137
|
/** An array of numbers, each any number. */
|
|
138
138
|
const isNumberArray = (value: unknown): value is ReadonlyArray<number> => Arr.isArray(value) && Arr.every(value, Predicate.isNumber)
|
|
139
139
|
|
|
140
|
-
/** Interpolates fixed-length numeric arrays
|
|
140
|
+
/** Interpolates fixed-length numeric arrays item by item (e.g. RGB tuples): it reads an array of numbers as it is. */
|
|
141
141
|
export const array: Entry<ReadonlyArray<number>, ReadonlyArray<number>> = {
|
|
142
142
|
name: "array",
|
|
143
143
|
parse: Option.liftPredicate(isNumberArray),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The registry of value kinds: given two values, it finds the kind that blends them and returns the
|
|
3
3
|
* blend each frame calls. An Environment builds one over core's kinds and its own (`make`, or `layer`
|
|
4
4
|
* for core's alone), and adds Key rules, which blend a key by its name, as `@wardic/dom`'s keep a key
|
|
5
|
-
* that hides
|
|
5
|
+
* that hides a Subject at its old value until an animation's last frame. A binding resolves each pair once, as it builds an animation.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
|
|
@@ -22,6 +22,7 @@ import * as Option from "effect/Option"
|
|
|
22
22
|
import * as Predicate from "effect/Predicate"
|
|
23
23
|
import * as Interpolator from "./Interpolator.ts"
|
|
24
24
|
import { dual } from "./internal/dual.ts"
|
|
25
|
+
import * as LerpsNumbers from "./internal/lerpsNumbers.ts"
|
|
25
26
|
|
|
26
27
|
// The registry is heterogeneous by design: its entries are `Interpolator.Entry<any, any>`.
|
|
27
28
|
|
|
@@ -69,7 +70,7 @@ export type ResolveByValue = <From, To>(from: From, to: To) => Effect.Effect<(t:
|
|
|
69
70
|
/**
|
|
70
71
|
* A key's pair as the rules after one rule, then the kinds, blend it: what a rule that rewrites a pair
|
|
71
72
|
* hands it on to, so the rules after it still apply. A rule that reads a value from elsewhere, as
|
|
72
|
-
* `@wardic/dom`'s for
|
|
73
|
+
* `@wardic/dom`'s for a Subject's own variables, resolves it, then blends what it resolved to through
|
|
73
74
|
* `next`, so the key's other rules still apply to it.
|
|
74
75
|
*/
|
|
75
76
|
// ADR-0035, *Amendment (#55)*: its Animatable none.
|
|
@@ -80,9 +81,9 @@ export type KeyBlendOf = (key: string, from: number | string, to: number | strin
|
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
83
|
* An Environment's Key rule: how one key's pair blends, picked by the key's name, as `@wardic/dom`'s keep
|
|
83
|
-
* a key that hides
|
|
84
|
-
* keys need one is the Environment's to know. Most hold for the whole Environment (`make`, `registerKeyRule`); one that reads
|
|
85
|
-
* is added for that
|
|
84
|
+
* a key that hides a Subject at its old value until an animation's last frame. Core holds none: which
|
|
85
|
+
* keys need one is the Environment's to know. Most hold for the whole Environment (`make`, `registerKeyRule`); one that reads a Subject
|
|
86
|
+
* is added for that Subject's animations with `withKeyRules`.
|
|
86
87
|
*/
|
|
87
88
|
// CONTEXT.md, ADR-0035; `@wardic/dom`'s are its `keyRules`. The registry asks every rule for every
|
|
88
89
|
// key of every leg it builds, so a key no rule wants costs what it did with none (ADR-0035, *Amendment
|
|
@@ -192,7 +193,7 @@ const blendDecoded = <From, To>(decoded: DecodedPair, from: From, to: To): Effec
|
|
|
192
193
|
const CACHE_CAPACITY = 1024
|
|
193
194
|
|
|
194
195
|
/**
|
|
195
|
-
* Resolved blends of string pairs, by `from`, then `to` (ADR-0026, decision 9).
|
|
196
|
+
* Resolved blends of string pairs, by `from`, then `to` (ADR-0026, decision 9). Subjects often
|
|
196
197
|
* animate the same pair (a hover state's value, say), so each pair is decoded
|
|
197
198
|
* and built once per registry, and every stream that resolves it shares the closure. That's safe:
|
|
198
199
|
* the closures are pure, and `complex`'s, which reuses one numbers array, rewrites every number and
|
|
@@ -267,6 +268,14 @@ export const make = (
|
|
|
267
268
|
return blendDecoded(decoded.value, from, to)
|
|
268
269
|
}
|
|
269
270
|
|
|
271
|
+
/** Whether a pair of numbers resolves to `Interpolator.number` itself: the first kind that reads it. */
|
|
272
|
+
// Per key, each leg (#460, compose once): statements. #1036: a blend machine computes such a pair in its loop.
|
|
273
|
+
const lerpsNumbers = (from: number, to: number): boolean => {
|
|
274
|
+
const decoded = select(entries, from, to)
|
|
275
|
+
if (Option.isNone(decoded)) return false
|
|
276
|
+
return decoded.value.entry === Interpolator.number
|
|
277
|
+
}
|
|
278
|
+
|
|
270
279
|
/** A pair of strings, from the cache, or resolved and kept. */
|
|
271
280
|
const resolveCached = (from: string, to: string): Effect.Effect<Blend<any, any>> => {
|
|
272
281
|
const kept = cache.get(from, to)
|
|
@@ -282,7 +291,7 @@ export const make = (
|
|
|
282
291
|
|
|
283
292
|
MutableRef.set(chain, chainOf(rules, resolve, noRule))
|
|
284
293
|
|
|
285
|
-
return {
|
|
294
|
+
return LerpsNumbers.attach({
|
|
286
295
|
register: Effect.fnUntraced(function* <Decoded, Encoded>(entry: Interpolator.Entry<Decoded, Encoded>) {
|
|
287
296
|
entries.unshift(entry)
|
|
288
297
|
cache.clear()
|
|
@@ -303,18 +312,18 @@ export const make = (
|
|
|
303
312
|
keyBlendOf: (key: string, from: number | string, to: number | string): Option.Option<Effect.Effect<KeyBlend>> =>
|
|
304
313
|
MutableRef.get(chain)(key, from, to),
|
|
305
314
|
forget: Effect.sync(() => cache.clear()),
|
|
306
|
-
}
|
|
315
|
+
}, lerpsNumbers)
|
|
307
316
|
})
|
|
308
317
|
|
|
309
318
|
/**
|
|
310
319
|
* `self` run with `rules` asked first, ahead of the registry's own Key rules, for that run alone: how a
|
|
311
|
-
* binding adds a rule bound to one
|
|
320
|
+
* binding adds a rule bound to one Subject, as `@wardic/dom`'s for its own variables, to that Subject's
|
|
312
321
|
* animations.
|
|
313
322
|
* Each rule's `next` is the rules after it, then the registry's, then by value. The registry itself is
|
|
314
|
-
* unchanged, so one
|
|
323
|
+
* unchanged, so one Subject's rule never reaches another's.
|
|
315
324
|
*
|
|
316
325
|
* @example
|
|
317
|
-
* yield* buildLegs.pipe(InterpolatorRegistry.withKeyRules([ruleOf(
|
|
326
|
+
* yield* buildLegs.pipe(InterpolatorRegistry.withKeyRules([ruleOf(subject)]))
|
|
318
327
|
*/
|
|
319
328
|
// ADR-0035, *Amendment (#55)*: `@wardic/dom`'s `variableValues(element)`.
|
|
320
329
|
export const withKeyRules: {
|
|
@@ -331,8 +340,8 @@ type Service = InterpolatorRegistry["Service"]
|
|
|
331
340
|
|
|
332
341
|
/**
|
|
333
342
|
* Each rule list's layered registries, by the registry under them: a binding binds one list to an
|
|
334
|
-
*
|
|
335
|
-
* Environment, not per leg. Weak, so
|
|
343
|
+
* Subject and wraps each leg it starts with it, so the chain is built once per Subject and
|
|
344
|
+
* Environment, not per leg. Weak, so a Subject's list goes with it.
|
|
336
345
|
*/
|
|
337
346
|
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
338
347
|
const layered = new WeakMap<ReadonlyArray<KeyRule>, WeakMap<Service, Service>>()
|
package/src/LiveValue.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Live values: values derived from other values as they change, each an `effect/reactivity` Atom an
|
|
3
|
-
*
|
|
3
|
+
* Subject's `style` can follow. `transform` maps one through ranges, `follow` and `spring` follow one on
|
|
4
4
|
* a transition, `velocity` tracks how fast one moves, `scroll` gives a container's scroll, `time` the
|
|
5
5
|
* time since it started, and `eachFrame` calls you every frame. A binding wraps them in its own
|
|
6
6
|
* reactive values, as Solid's `createSpring` and `createTransform` do.
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* const x = yield* LiveValue.spring(pointerX, { stiffness: 300, damping: 30 })
|
|
13
13
|
* const opacity = yield* LiveValue.transform(x, [0, 200], [1, 0])
|
|
14
14
|
*/
|
|
15
|
-
// #130, ADR-0043: a Live value is one the user moves themselves, given in
|
|
16
|
-
// key's `style` link, which the
|
|
15
|
+
// #130, ADR-0043: a Live value is one the user moves themselves, given in a Subject's `style`: the
|
|
16
|
+
// key's `style` link, which the Subject follows while no entry of the Override stack sets it
|
|
17
17
|
// (CONTEXT.md). Its shared form is an Atom, as core's other live data is (`Probe.viewport`). Motion's
|
|
18
18
|
// `useTransform` (with a `mixer`, #440), `interpolate`, `followValue` (#441), `useSpring`,
|
|
19
19
|
// `MotionValue.jump` (#257 item 7), `useScroll` (#234), `useVelocity`, `useTime`, `useAnimationFrame`
|
|
@@ -33,6 +33,7 @@ import * as AtomRegistry from "effect/reactivity/AtomRegistry"
|
|
|
33
33
|
import * as Rec from "effect/Record"
|
|
34
34
|
import type * as Scope from "effect/Scope"
|
|
35
35
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
36
|
+
import * as Clock from "./Clock.ts"
|
|
36
37
|
import * as FrameLoop from "./FrameLoop.ts"
|
|
37
38
|
import * as Easing from "./Easing.ts"
|
|
38
39
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.ts"
|
|
@@ -326,7 +327,8 @@ export const jump: {
|
|
|
326
327
|
}),
|
|
327
328
|
)
|
|
328
329
|
|
|
329
|
-
/** Motion's spring, for the physics a follow's spring leaves out (
|
|
330
|
+
/** Motion's spring, for the physics a follow's spring leaves out (Motion's `springDefaults`). */
|
|
331
|
+
// `motion-dom`'s `springDefaults`.
|
|
330
332
|
const MOTION_PHYSICS = { stiffness: 100, damping: 10, mass: 1 } as const
|
|
331
333
|
|
|
332
334
|
/** Motion's follower's rest thresholds, for those a spring or an inertia leaves out (`follow()`'s). */
|
|
@@ -630,8 +632,8 @@ export interface ScrollTransform {
|
|
|
630
632
|
* How a Live value derives from a container's scroll, in no Environment's terms: the scroll it
|
|
631
633
|
* reads, as `scroll` was given it; whether it reads how far the container is scrolled (`current`) or
|
|
632
634
|
* its progress; on which axis; and each `transform` it went through since, in order. An Environment
|
|
633
|
-
* that can run a scroll-linked value with the scroll itself, as
|
|
634
|
-
*
|
|
635
|
+
* that can run a scroll-linked value with the scroll itself, as `@wardic/dom` can (a **Timeline value**),
|
|
636
|
+
* reads it to decide whether it can, and how.
|
|
635
637
|
*/
|
|
636
638
|
export interface ScrollDerivation {
|
|
637
639
|
/** The scroll's options, as `scroll` was given them. */
|
|
@@ -700,7 +702,7 @@ const derivationNow = (atom: Atom.Atom<unknown>): ScrollDerivation | undefined =
|
|
|
700
702
|
/**
|
|
701
703
|
* Describe `atom` as deriving from a container's scroll as `source` does: for an Atom a binding
|
|
702
704
|
* keeps for a value's life and sets from `source`, made after it, as a `createScroll` does once its
|
|
703
|
-
*
|
|
705
|
+
* Subjects are there. A `transform` made over `atom` before then derives through it too. Called again,
|
|
704
706
|
* it derives as the new `source` does. `source` mustn't derive from `atom`.
|
|
705
707
|
*
|
|
706
708
|
* @example
|
|
@@ -723,8 +725,8 @@ export const derivesAs: {
|
|
|
723
725
|
* How `atom` derives from a container's scroll, now: one of `scroll`'s values, an Atom
|
|
724
726
|
* `derivesAs` one, or a `transform` over either, a `transform` over that, and so on; `None` for any
|
|
725
727
|
* other, a `spring` or a `velocity` of one among them. Read again while nothing it derives from
|
|
726
|
-
* changed, it's the same object. An Environment reads it to run the value
|
|
727
|
-
*
|
|
728
|
+
* changed, it's the same object. An Environment reads it to run the value with the scroll itself where it
|
|
729
|
+
* can, as `@wardic/dom` can (a **Timeline value**).
|
|
728
730
|
*
|
|
729
731
|
* @example
|
|
730
732
|
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
@@ -755,8 +757,10 @@ const numberMachine = (name: string, settles: boolean, start: () => (dt: number)
|
|
|
755
757
|
// tick whose Late step doesn't come (back-to-back frames, or past the Late rounds) takes its first step at
|
|
756
758
|
// the next tick, and would otherwise count two frames' change over one `dt`. Its Late step, at the loop's
|
|
757
759
|
// tick count it started at, reads from the source before the change that started it, since the tick's hook
|
|
758
|
-
// has read past that change by then (#991, ADR-0043 *Amendment (#991)*).
|
|
759
|
-
|
|
760
|
+
// has read past that change by then (#991, ADR-0043 *Amendment (#991)*). A change is over the time it took
|
|
761
|
+
// (#1046): the tick's dt, on the frame timeline, unless the time since the read at the run's own last step,
|
|
762
|
+
// a tick before, differs from it by more than half, a late frame's stamps misstating it either way (below).
|
|
763
|
+
export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<number>, never, Clock.Clock | FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope> = Effect.fnUntraced(
|
|
760
764
|
function* (source: Atom.Atom<number>) {
|
|
761
765
|
const registry = yield* AtomRegistry.AtomRegistry
|
|
762
766
|
// Mounted for the Scope, not kept alive: a kept-alive Atom's node never leaves the registry.
|
|
@@ -779,9 +783,19 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
779
783
|
let startedAt = 0
|
|
780
784
|
let firstDue = false
|
|
781
785
|
const loop = yield* FrameLoop.FrameLoop
|
|
786
|
+
// When `previous` was read, on the Clock's `now()`, and at which tick; and the tick of the run's last
|
|
787
|
+
// step, `-1` before its first. A step right after the run's own last one divides its change by the time
|
|
788
|
+
// since that tick's read, which a late frame's stamps misstate (#1046): a running run keeps the loop
|
|
789
|
+
// ticking every frame, where the loop idles between runs and its tick count skips the frames it missed.
|
|
790
|
+
const clock = yield* Clock.Clock
|
|
791
|
+
let previousAt = 0
|
|
792
|
+
let previousTick = -1
|
|
793
|
+
let stepTick = -1
|
|
782
794
|
yield* loop.afterTick(() => {
|
|
783
795
|
try {
|
|
784
796
|
previous = registry.get(source)
|
|
797
|
+
previousAt = clock.now()
|
|
798
|
+
previousTick = loop.tickCount()
|
|
785
799
|
if (sourceFailing) sourceFailing = false
|
|
786
800
|
} catch (defect) {
|
|
787
801
|
if (!sourceFailing) Report.failureOn(context, SOURCE_FAILED, Cause.die(defect))
|
|
@@ -793,6 +807,7 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
793
807
|
const unhear = onJump(registry, source, (value) => {
|
|
794
808
|
previous = value
|
|
795
809
|
seed = value
|
|
810
|
+
stepTick = -1
|
|
796
811
|
})
|
|
797
812
|
// One token for its lifetime, and one run program, started afresh on the change after a rest:
|
|
798
813
|
// a change while a run goes costs a check, nothing built.
|
|
@@ -807,7 +822,18 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
807
822
|
return previous
|
|
808
823
|
}
|
|
809
824
|
const program = numberMachine("wardic.velocity", true, () => (dt) => {
|
|
810
|
-
|
|
825
|
+
// Over the tick's dt, unless, right after the run's own last step, the time since that tick's read
|
|
826
|
+
// differs from it by more than half: a late frame, whose stamps misstate it (#1046). An on-time frame's
|
|
827
|
+
// reads differ from its dt by their jitter, which the stamps don't have. A run's first step, its Late
|
|
828
|
+
// step among them, has no read of its own a tick before.
|
|
829
|
+
const tick = loop.tickCount()
|
|
830
|
+
let seconds = dt
|
|
831
|
+
if (stepTick === tick - 1 && previousTick === stepTick) {
|
|
832
|
+
const since = (clock.now() - previousAt) / 1000
|
|
833
|
+
if (Math.abs(since - dt) > dt / 2) seconds = since
|
|
834
|
+
}
|
|
835
|
+
stepTick = tick
|
|
836
|
+
const step = Math.min(seconds, Machine.MAX_DT)
|
|
811
837
|
// A tick in no time (never from the Clock) reads as still.
|
|
812
838
|
if (step === 0) return { value: 0, done: true }
|
|
813
839
|
// A check on every later step: the first's alone reads the tick count (#991).
|
|
@@ -835,7 +861,7 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
835
861
|
}
|
|
836
862
|
if (frame.done) running = false
|
|
837
863
|
return undefined
|
|
838
|
-
}, { supersede: token }),
|
|
864
|
+
}, { supersede: token, onFrameTimeline: true }),
|
|
839
865
|
)
|
|
840
866
|
const follow = (): void => {
|
|
841
867
|
if (running) return
|
|
@@ -843,6 +869,7 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
843
869
|
seed = previous
|
|
844
870
|
startedAt = loop.tickCount()
|
|
845
871
|
firstDue = true
|
|
872
|
+
stepTick = -1
|
|
846
873
|
run(program, { onlyIfMissing: true })
|
|
847
874
|
}
|
|
848
875
|
const unsubscribe = registry.subscribe(source, follow)
|
|
@@ -864,7 +891,9 @@ export const velocity: (source: Atom.Atom<number>) => Effect.Effect<Atom.Atom<nu
|
|
|
864
891
|
* @example
|
|
865
892
|
* const rotate = yield* LiveValue.transform(yield* LiveValue.time(), [0, 4000], [0, 360], { clamp: false })
|
|
866
893
|
*/
|
|
867
|
-
// A run on the Frame loop that never settles, adding each tick's `dt` as the Clock gives it, unclamped.
|
|
894
|
+
// A run on the Frame loop that never settles, adding each tick's `dt` as the Clock gives it, unclamped. On
|
|
895
|
+
// the frame timeline (#1046, ADR-0027 *Amendment (#1046)*): it reports the frames' time, so a late first frame's
|
|
896
|
+
// counts whole, where an animation made in a long task leaves it out.
|
|
868
897
|
export const time: () => Effect.Effect<Atom.Atom<number>, never, FrameLoop.FrameLoop | AtomRegistry.AtomRegistry | Scope.Scope> = Effect.fnUntraced(
|
|
869
898
|
function* () {
|
|
870
899
|
const registry = yield* AtomRegistry.AtomRegistry
|
|
@@ -893,7 +922,7 @@ export const time: () => Effect.Effect<Atom.Atom<number>, never, FrameLoop.Frame
|
|
|
893
922
|
failing = true
|
|
894
923
|
}
|
|
895
924
|
return undefined
|
|
896
|
-
}, { supersede: token }),
|
|
925
|
+
}, { supersede: token, onFrameTimeline: true }),
|
|
897
926
|
),
|
|
898
927
|
)
|
|
899
928
|
yield* Effect.addFinalizer(() =>
|
|
@@ -922,7 +951,8 @@ const FRAME_DELTA = { minimum: 1, maximum: 40 } as const
|
|
|
922
951
|
* yield* LiveValue.eachFrame((time) => draw(context, time))
|
|
923
952
|
*/
|
|
924
953
|
// #443. A run's first frame after the Clock wakes is the Clock's nominal frame, 16.7 ms, as Motion's is.
|
|
925
|
-
// A throw is a run's defect (ADR-0027, decision 7).
|
|
954
|
+
// A throw is a run's defect (ADR-0027, decision 7). On the frame timeline (#1046): its time and delta are the
|
|
955
|
+
// frames' own, as Motion's `timestamp - initialTimestamp` is, a late frame's included.
|
|
926
956
|
export const eachFrame: (callback: (time: number, delta: number) => void) => Effect.Effect<void, never, FrameLoop.FrameLoop | Scope.Scope> = Effect.fnUntraced(
|
|
927
957
|
function* (callback: (time: number, delta: number) => void) {
|
|
928
958
|
const run = yield* FiberHandle.makeRuntime<FrameLoop.FrameLoop, never, unknown>()
|
|
@@ -939,7 +969,7 @@ export const eachFrame: (callback: (time: number, delta: number) => void) => Eff
|
|
|
939
969
|
return { value: ms, done: false }
|
|
940
970
|
}
|
|
941
971
|
})
|
|
942
|
-
run(frames.pipe(Machine.run(constUndefined, { supersede: token })))
|
|
972
|
+
run(frames.pipe(Machine.run(constUndefined, { supersede: token, onFrameTimeline: true })))
|
|
943
973
|
yield* Effect.addFinalizer(() => Effect.sync(() => Supersede.end(token)))
|
|
944
974
|
})
|
|
945
975
|
|