@wardic/core 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +12 -6
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +374 -30
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +22 -8
- 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 +14 -8
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +93 -34
- 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 +11 -8
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +18 -37
- package/dist/InputFeed.js.map +1 -1
- 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 +16 -9
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +204 -27
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +21 -8
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +184 -60
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +16 -9
- 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 +2 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +15 -10
- 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 +11 -3
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +190 -39
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- 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 +21 -4
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +21 -5
- 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 +45 -39
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +59 -35
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +11 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +21 -17
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.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 +54 -50
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +201 -77
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +6 -3
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +14 -3
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +42 -13
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +279 -88
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +30 -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 +8 -1
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +18 -2
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +7 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +24 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +123 -68
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +319 -167
- 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 +32 -10
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +73 -20
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +68 -34
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +83 -36
- 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 +391 -27
- package/src/Clock.ts +29 -8
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +118 -41
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +39 -42
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +186 -30
- package/src/Machine.ts +252 -81
- package/src/Playback.ts +15 -9
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +16 -10
- 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 +203 -41
- package/src/internal/guarded.ts +69 -0
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +33 -6
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +88 -57
- package/src/unstable/AppearHandoff.ts +13 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +23 -17
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +250 -108
- package/src/unstable/FrameEffects.ts +17 -4
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +342 -101
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +33 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +20 -2
- package/src/unstable/RetargetLegs.ts +24 -9
- package/src/unstable/Spine.ts +399 -202
- 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 +102 -23
- package/src/unstable/VariantTree.ts +123 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
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
|
*
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
// authors; nothing here names a DOM type.
|
|
32
32
|
import * as Arr from "effect/Array"
|
|
33
33
|
import * as Bool from "effect/Boolean"
|
|
34
|
-
import * as Cause from "effect/Cause"
|
|
34
|
+
import type * as Cause from "effect/Cause"
|
|
35
|
+
import type * as Context from "effect/Context"
|
|
35
36
|
import * as Effect from "effect/Effect"
|
|
36
37
|
import { constVoid } from "effect/Function"
|
|
37
38
|
import * as MutableRef from "effect/MutableRef"
|
|
@@ -41,6 +42,7 @@ import * as Queue from "effect/Queue"
|
|
|
41
42
|
import type * as Scope from "effect/Scope"
|
|
42
43
|
import * as Stream from "effect/Stream"
|
|
43
44
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
45
|
+
import { guarded, switchedOn } from "./internal/guarded.ts"
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* A source of events: called with `emit` and `end`, it calls `emit` with each event from then on, and
|
|
@@ -140,10 +142,13 @@ export const byTarget = <A>(lookup: (target: unknown) => InputFeed<A>): ((target
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
|
-
* Where a watch hands
|
|
144
|
-
*
|
|
145
|
+
* Where a watch hands its handler's run of throws, at its first, so a binding can report it its own way:
|
|
146
|
+
* a run lasts from a throw to the next call that returns, and the watch goes on with the next event.
|
|
147
|
+
* With none, the run is reported then, on the context the watch started in, and the watch goes on.
|
|
145
148
|
*/
|
|
146
|
-
// #318, ADR-0055.
|
|
149
|
+
// #318, ADR-0055. With none, core reports the throw itself (#979, row 27; ADR-0030, *Amendment (#979,
|
|
150
|
+
// groups D and G)*): where no binding's fiber is there to see it. Once a run either way (#979 group I,
|
|
151
|
+
// row 26; ADR-0074 decision 3).
|
|
147
152
|
export type OnDefect = (cause: Cause.Cause<never>) => void
|
|
148
153
|
|
|
149
154
|
/** A watch's handlers. */
|
|
@@ -151,7 +156,7 @@ export type OnDefect = (cause: Cause.Cause<never>) => void
|
|
|
151
156
|
export interface Handlers<A> {
|
|
152
157
|
/** Each event or value, inside the event's dispatch. */
|
|
153
158
|
readonly on: (value: A) => void
|
|
154
|
-
/** A
|
|
159
|
+
/** A handler's run of throws, at its first. Without it, the run is reported then, and the watch goes on. */
|
|
155
160
|
readonly onDefect?: OnDefect | undefined
|
|
156
161
|
/** The feed ran out, as a test's script does. */
|
|
157
162
|
readonly onEnd?: (() => void) | undefined
|
|
@@ -162,19 +167,6 @@ export interface Handlers<A> {
|
|
|
162
167
|
readonly onStop?: (() => void) | undefined
|
|
163
168
|
}
|
|
164
169
|
|
|
165
|
-
/** `handle`, a throw from it handed to `onDefect` when there is one. */
|
|
166
|
-
const guarded = <A>(handle: (event: A) => void, onDefect: OnDefect | undefined): ((event: A) => void) =>
|
|
167
|
-
UndefinedOr.match(onDefect, {
|
|
168
|
-
onUndefined: () => handle,
|
|
169
|
-
onDefined: (defect) => (event: A): void => {
|
|
170
|
-
try {
|
|
171
|
-
handle(event)
|
|
172
|
-
} catch (error) {
|
|
173
|
-
defect(Cause.die(error))
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
})
|
|
177
|
-
|
|
178
170
|
/** A subscription its owner opens and closes: `switched`'s. */
|
|
179
171
|
// #460.
|
|
180
172
|
export interface Switch {
|
|
@@ -186,38 +178,39 @@ export interface Switch {
|
|
|
186
178
|
|
|
187
179
|
/**
|
|
188
180
|
* A subscription to `feed` its owner opens and closes, each event handed to `handle` inside its emit, a
|
|
189
|
-
*
|
|
190
|
-
*
|
|
181
|
+
* run of throws to `onDefect` at its first. With none, the run is reported then on Effect's default runtime, as
|
|
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 a Subject at rest holds none. The feed
|
|
191
184
|
* running out ends nothing; its owner closes it when it's done.
|
|
192
185
|
*/
|
|
193
186
|
// #460: a **Keyboard press**.
|
|
194
|
-
export const switched = <A>(feed: InputFeed<A>, handle: (event: A) => void, onDefect?: OnDefect): Switch =>
|
|
195
|
-
const on = guarded(handle, onDefect)
|
|
196
|
-
let stop: (() => void) | undefined
|
|
197
|
-
return {
|
|
198
|
-
open: () => {
|
|
199
|
-
if (Predicate.isUndefined(stop)) stop = feed(on, constVoid)
|
|
200
|
-
},
|
|
201
|
-
close: () => {
|
|
202
|
-
if (Predicate.isUndefined(stop)) return
|
|
203
|
-
const running = stop
|
|
204
|
-
stop = undefined
|
|
205
|
-
running()
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
}
|
|
187
|
+
export const switched = <A>(feed: InputFeed<A>, handle: (event: A) => void, onDefect?: OnDefect): Switch => switchedOn(feed, handle, onDefect, undefined)
|
|
209
188
|
|
|
210
189
|
/**
|
|
211
190
|
* Watches `feed` while the Scope is open, with a handler that can stop: `make` makes this subscription's
|
|
212
191
|
* handler, which hears each event inside its emit and returns whether to go on. `false` stops it, even
|
|
213
|
-
* from inside the feed's start. A
|
|
214
|
-
* the
|
|
192
|
+
* from inside the feed's start. A run of throws from it goes to `handlers.onDefect` at its first, else it's
|
|
193
|
+
* reported then on the context the watch started in, and the watch goes on. `handlers.onEnd` is told if the
|
|
194
|
+
* feed runs out, and closing the Scope stops the feed.
|
|
215
195
|
*/
|
|
216
196
|
// #318, #379: no fiber and no Stream. A recognizer's `once` returns `false`.
|
|
217
197
|
export const watchWith = <A>(
|
|
218
198
|
feed: InputFeed<A>,
|
|
219
199
|
make: () => (event: A) => boolean,
|
|
220
200
|
handlers: Pick<Handlers<never>, "onDefect" | "onEnd" | "onStop">,
|
|
201
|
+
): Effect.Effect<void, never, Scope.Scope> =>
|
|
202
|
+
// The context a throw with no `onDefect` is reported on (#979, row 27), read only for such a watch.
|
|
203
|
+
UndefinedOr.match(handlers.onDefect, {
|
|
204
|
+
onDefined: () => watching(feed, make, handlers, undefined),
|
|
205
|
+
onUndefined: () => Effect.flatMap(Effect.context<never>(), (context) => watching(feed, make, handlers, context)),
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
/** `watchWith`'s watch, a throw with no `onDefect` reported on `context`. */
|
|
209
|
+
const watching = <A>(
|
|
210
|
+
feed: InputFeed<A>,
|
|
211
|
+
make: () => (event: A) => boolean,
|
|
212
|
+
handlers: Pick<Handlers<never>, "onDefect" | "onEnd" | "onStop">,
|
|
213
|
+
context: Context.Context<never> | undefined,
|
|
221
214
|
): Effect.Effect<void, never, Scope.Scope> =>
|
|
222
215
|
Effect.acquireRelease(
|
|
223
216
|
Effect.sync(() => {
|
|
@@ -231,10 +224,14 @@ export const watchWith = <A>(
|
|
|
231
224
|
if (Predicate.isNotUndefined(handlers.onStop)) handlers.onStop()
|
|
232
225
|
}
|
|
233
226
|
const stop = feed(
|
|
234
|
-
guarded(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
227
|
+
guarded(
|
|
228
|
+
(event: A) => {
|
|
229
|
+
if (MutableRef.get(done)) return
|
|
230
|
+
if (Bool.not(handle(event))) finish()
|
|
231
|
+
},
|
|
232
|
+
handlers.onDefect,
|
|
233
|
+
context,
|
|
234
|
+
),
|
|
238
235
|
() => {
|
|
239
236
|
if (MutableRef.get(done)) return
|
|
240
237
|
UndefinedOr.map(handlers.onEnd, (onEnd) => onEnd())
|
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,15 @@ 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
278
|
/**
|
|
279
279
|
* `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
|
|
280
|
+
* one, a drag given drag controls. The plain `pointer` then subscribes to no handing, so a Subject
|
|
281
281
|
* that's only hovered or pressed pays for none. Absent: `pointer` delivers the handed downs itself.
|
|
282
282
|
*/
|
|
283
283
|
// #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>>()
|