@wardic/core 1.0.0-rc.9 → 1.0.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/Batch.d.ts +244 -0
- package/dist/Batch.d.ts.map +1 -0
- package/dist/Batch.js +1862 -0
- package/dist/Batch.js.map +1 -0
- package/dist/DragRecognizer.d.ts +16 -1
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +87 -1
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/InputSource.d.ts +21 -0
- package/dist/InputSource.d.ts.map +1 -1
- package/dist/InputSource.js.map +1 -1
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +4 -67
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +7 -6
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +35 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +211 -16
- package/dist/Recognizer.js.map +1 -1
- package/dist/Reorder.d.ts +7 -5
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +60 -23
- package/dist/Reorder.js.map +1 -1
- package/dist/Sequence.d.ts +7 -2
- package/dist/Sequence.d.ts.map +1 -1
- package/dist/Sequence.js +8 -2
- package/dist/Sequence.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/keyframes.d.ts +40 -0
- package/dist/internal/keyframes.d.ts.map +1 -0
- package/dist/internal/keyframes.js +70 -0
- package/dist/internal/keyframes.js.map +1 -0
- package/dist/internal/playhead.d.ts +16 -0
- package/dist/internal/playhead.d.ts.map +1 -0
- package/dist/internal/playhead.js +6 -0
- package/dist/internal/playhead.js.map +1 -0
- package/dist/internal/stepper.d.ts +6 -0
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -0
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/watch.d.ts +6 -0
- package/dist/internal/watch.d.ts.map +1 -1
- package/dist/internal/watch.js +7 -0
- package/dist/internal/watch.js.map +1 -1
- package/package.json +2 -2
- package/src/Batch.ts +2128 -0
- package/src/DragRecognizer.ts +97 -2
- package/src/InputSource.ts +25 -0
- package/src/Machine.ts +4 -93
- package/src/Playback.ts +7 -13
- package/src/Recognizer.ts +242 -17
- package/src/Reorder.ts +83 -27
- package/src/Sequence.ts +20 -5
- package/src/index.ts +1 -0
- package/src/internal/keyframes.ts +98 -0
- package/src/internal/playhead.ts +19 -0
- package/src/internal/stepper.ts +16 -0
- package/src/internal/watch.ts +15 -0
package/src/DragRecognizer.ts
CHANGED
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
import * as Arr from "effect/Array"
|
|
23
23
|
import * as Bool from "effect/Boolean"
|
|
24
24
|
import * as Effect from "effect/Effect"
|
|
25
|
+
import * as Exit from "effect/Exit"
|
|
25
26
|
import { constant, constTrue, constVoid, identity, type LazyArg } from "effect/Function"
|
|
26
27
|
import * as Match from "effect/Match"
|
|
27
28
|
import * as MutableRef from "effect/MutableRef"
|
|
28
29
|
import * as Option from "effect/Option"
|
|
29
30
|
import * as Predicate from "effect/Predicate"
|
|
30
|
-
import
|
|
31
|
+
import * as Scope from "effect/Scope"
|
|
31
32
|
import * as Stream from "effect/Stream"
|
|
32
33
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
33
34
|
import type * as Drag from "./Drag.ts"
|
|
@@ -37,7 +38,8 @@ import * as InputSource from "./InputSource.ts"
|
|
|
37
38
|
import type * as Point from "./Point.ts"
|
|
38
39
|
import * as Velocity from "./Velocity.ts"
|
|
39
40
|
|
|
40
|
-
import {
|
|
41
|
+
import { tracedScoped } from "./internal/tracing.ts"
|
|
42
|
+
import { type AmongHandlers, amongFeed, streamOf, watchFeed } from "./internal/watch.ts"
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* Movement distance (px) from the down-origin required before a gesture
|
|
@@ -522,6 +524,99 @@ const axisAtOf = (axis: Drag.Axis | LazyArg<Drag.Axis>): LazyArg<Drag.Axis> =>
|
|
|
522
524
|
Match.orElse((read) => read),
|
|
523
525
|
)
|
|
524
526
|
|
|
527
|
+
// A host global in every environment Wardic runs on, which core's own `lib` doesn't declare (Microtask.ts).
|
|
528
|
+
declare const queueMicrotask: (callback: () => void) => void
|
|
529
|
+
|
|
530
|
+
/** A press's release: its pointer let go or cancelled, or a lost release (an unpressed move). */
|
|
531
|
+
const isRelease = (event: InputSource.PointerLikeEvent): boolean =>
|
|
532
|
+
Bool.or(Bool.or(event.type === "up", event.type === "cancel"), Bool.and(event.type === "move", Bool.not(event.pressed)))
|
|
533
|
+
|
|
534
|
+
/** A pressed member's own drag watch: its Scope, the pointer that pressed it, and whether its gesture started. */
|
|
535
|
+
interface PressedMember {
|
|
536
|
+
readonly scope: Scope.Closeable
|
|
537
|
+
pointerId: number
|
|
538
|
+
started: boolean
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Watches drags among many members while the Scope is open, from one feed over them (`pointerAmong`):
|
|
543
|
+
* a member's down starts `watchDrag` on that member alone, handed the down as drag controls hand one
|
|
544
|
+
* (`adoptPointer`), so it drags as its own press would, with the same threshold, claim, samples and
|
|
545
|
+
* velocity. `handlers.on` hears each sample with its member. No member listens until it's pressed.
|
|
546
|
+
* - **A gesture that started** ends its member's watch at its `"end"`, which the member's own feed hears.
|
|
547
|
+
* - **A press that never started** ends it at that pointer's release, a lost one too: there's nothing
|
|
548
|
+
* to tell, and no claim to give back. Another pointer's release on the member ends nothing.
|
|
549
|
+
* - **A down on a member pressed but not started** is handed to its watch, as the gesture's new press.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* yield* DragRecognizer.watchDragAmong(memberOf, { axis: "y" }, { on: (member, sample) => follow(member, sample) })
|
|
553
|
+
*/
|
|
554
|
+
// #712, ADR-0072 decision 7: a Batch Reorder group's members, where a drag watch each would cost a listener
|
|
555
|
+
// set each. Over the feed `watchHoverAmong` and `watchPressAmong` watch (ADR-0055, *Amendment (#665)*).
|
|
556
|
+
// Held strongly, not weakly as their states are: each pressed member's entry is a Scope to close, gone at
|
|
557
|
+
// its gesture's end. A trusted event runs the page's microtasks between its listeners, and this feed's run
|
|
558
|
+
// before the member's own, so a started gesture's watch isn't touched at the release: it ends at its own
|
|
559
|
+
// `"end"`. Tier 2, for bindings.
|
|
560
|
+
export const watchDragAmong: (
|
|
561
|
+
memberOf: (node: unknown) => Option.Option<unknown>,
|
|
562
|
+
options: Omit<DragOptions, "listen" | "adoptable">,
|
|
563
|
+
handlers: AmongHandlers<Drag.Sample>,
|
|
564
|
+
) => Effect.Effect<void, never, Scope.Scope | InputSource.InputSource> = /*#__PURE__*/ Effect.fnUntraced(
|
|
565
|
+
function* (memberOf: (node: unknown) => Option.Option<unknown>, options: Omit<DragOptions, "listen" | "adoptable">, handlers: AmongHandlers<Drag.Sample>) {
|
|
566
|
+
yield* Effect.logDebug("wardic.drag: watch among")
|
|
567
|
+
const input = yield* InputSource.InputSource
|
|
568
|
+
const pointer = yield* amongFeed(input.pointerAmong, "pointerAmong")
|
|
569
|
+
const scope = yield* Effect.scope
|
|
570
|
+
const run = Effect.runSyncWith(yield* Effect.context<InputSource.InputSource>())
|
|
571
|
+
const pressed = new Map<unknown, PressedMember>()
|
|
572
|
+
/** `member`'s watch ended: after this event's dispatch, which its own feed may still be hearing. */
|
|
573
|
+
const end = (member: unknown, own: PressedMember): void => {
|
|
574
|
+
if (pressed.get(member) !== own) return
|
|
575
|
+
pressed.delete(member)
|
|
576
|
+
queueMicrotask(() => run(Scope.close(own.scope, Exit.void)))
|
|
577
|
+
}
|
|
578
|
+
/** `told`'s down handed to `member`'s watch, as drag controls hand one: the event's own platform event, else the event. */
|
|
579
|
+
const hand = (member: unknown, own: PressedMember, told: InputSource.PointerLikeEvent): void => {
|
|
580
|
+
own.pointerId = told.pointerId
|
|
581
|
+
const raw = UndefinedOr.match(told.raw, { onUndefined: () => told, onDefined: identity })
|
|
582
|
+
// A down that isn't a pressed pointer's starts nothing.
|
|
583
|
+
if (Option.isNone(input.adoptPointer(member, raw))) end(member, own)
|
|
584
|
+
}
|
|
585
|
+
/** `member`'s down: handed to its watch while one is open and hasn't started, else to a new one. */
|
|
586
|
+
const press = (member: unknown, told: InputSource.PointerLikeEvent): void => {
|
|
587
|
+
const open = pressed.get(member)
|
|
588
|
+
if (Predicate.isNotUndefined(open)) {
|
|
589
|
+
if (open.started) return
|
|
590
|
+
return hand(member, open, told)
|
|
591
|
+
}
|
|
592
|
+
const own: PressedMember = { scope: Scope.forkUnsafe(scope, "sequential"), pointerId: told.pointerId, started: false }
|
|
593
|
+
pressed.set(member, own)
|
|
594
|
+
const on = (sample: Drag.Sample): void => {
|
|
595
|
+
if (sample.phase === "start") own.started = true
|
|
596
|
+
handlers.on(member, sample)
|
|
597
|
+
if (sample.phase === "end") end(member, own)
|
|
598
|
+
}
|
|
599
|
+
run(watchDrag(member, { ...options, listen: false, adoptable: true }, { on, onDefect: handlers.onDefect }).pipe(Scope.provide(own.scope)))
|
|
600
|
+
hand(member, own, told)
|
|
601
|
+
}
|
|
602
|
+
/** A release by the pointer that pressed `member`, its gesture never started: its watch ends. */
|
|
603
|
+
const released = (member: unknown, told: InputSource.PointerLikeEvent): void => {
|
|
604
|
+
const own = pressed.get(member)
|
|
605
|
+
if (Predicate.isUndefined(own)) return
|
|
606
|
+
if (own.started) return
|
|
607
|
+
if (own.pointerId !== told.pointerId) return
|
|
608
|
+
end(member, own)
|
|
609
|
+
}
|
|
610
|
+
const onPointer = (): ((told: InputSource.TargetEvent<InputSource.PointerLikeEvent>) => boolean) => ({ target, event }) => {
|
|
611
|
+
if (event.type === "down") press(target, event)
|
|
612
|
+
if (isRelease(event)) released(target, event)
|
|
613
|
+
return true
|
|
614
|
+
}
|
|
615
|
+
yield* InputFeed.watchWith(pointer(memberOf), onPointer, { onDefect: handlers.onDefect, onEnd: handlers.onEnd, onStop: handlers.onStop })
|
|
616
|
+
},
|
|
617
|
+
(self) => tracedScoped(self, "wardic.drag"),
|
|
618
|
+
)
|
|
619
|
+
|
|
525
620
|
/**
|
|
526
621
|
* A drag on `target`, as a Stream of samples kept to its `axis`, with `watchDrag`'s rules: each sample
|
|
527
622
|
* arrives inside its pointer event's dispatch, and the Stream ends when the input does, as a test's
|
package/src/InputSource.ts
CHANGED
|
@@ -232,6 +232,14 @@ export interface FocusLikeEvent {
|
|
|
232
232
|
readonly visible?: boolean
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
/** An event, with the target it's for: what a feed over many targets tells, `pointerAmong`'s and `focusAmong`'s. */
|
|
236
|
+
// #665's PR 5 (Q56): a Batch's members' gestures, from one source.
|
|
237
|
+
export interface TargetEvent<A> {
|
|
238
|
+
/** The target it's for, as the feed's `memberOf` named it. */
|
|
239
|
+
readonly target: unknown
|
|
240
|
+
readonly event: A
|
|
241
|
+
}
|
|
242
|
+
|
|
235
243
|
/**
|
|
236
244
|
* Input from the Environment, as Input feeds: each target's pointer, keys and focus, shared by every
|
|
237
245
|
* subscriber to that target, and heard inside the platform's dispatch. A consumer that wants a Stream
|
|
@@ -282,6 +290,23 @@ export class InputSource extends Context.Service<InputSource, {
|
|
|
282
290
|
*/
|
|
283
291
|
// #431: **Drag controls**. An `Option` (#618, A1): a down that may not be there, outside the per-frame path.
|
|
284
292
|
readonly adoptPointer: (target: unknown, raw: unknown) => Option.Option<PointerLikeEvent>
|
|
293
|
+
/**
|
|
294
|
+
* The pointer events over many targets, from one source, each told with the target it's for:
|
|
295
|
+
* `memberOf(node)` names the target a node the pointer hit is, `Option.none()` for none, and each target
|
|
296
|
+
* hears what `pointer(target)` would, its enter and leave, the downs and releases over it, and a held
|
|
297
|
+
* pointer's events wherever they land. For many like targets, a Batch's members, where a feed each
|
|
298
|
+
* would cost a listener set each. Absent: `Recognizer.watchHoverAmong` and `watchPressAmong` fail,
|
|
299
|
+
* naming it.
|
|
300
|
+
*/
|
|
301
|
+
// #665's PR 5 (Q56, Q17's probe: a listener set per member cost 12 ms and 4.6 KB a member per 1,000).
|
|
302
|
+
readonly pointerAmong?: ((memberOf: (node: unknown) => Option.Option<unknown>) => InputFeed.InputFeed<TargetEvent<PointerLikeEvent>>) | undefined
|
|
303
|
+
/**
|
|
304
|
+
* The focus and blur of many targets and of whatever inside each, from one source, each told with the
|
|
305
|
+
* target it's for, as its `memberOf` names it: what `focus(target)` would tell it, and at its start a
|
|
306
|
+
* focus already within one. Absent: no key presses a target among them.
|
|
307
|
+
*/
|
|
308
|
+
// #665's PR 5 (Q57): a **Keyboard press** on a Batch's member.
|
|
309
|
+
readonly focusAmong?: ((memberOf: (node: unknown) => Option.Option<unknown>) => InputFeed.InputFeed<TargetEvent<FocusLikeEvent>>) | undefined
|
|
285
310
|
}>()("@wardic/core/InputSource") {}
|
|
286
311
|
|
|
287
312
|
/**
|
package/src/Machine.ts
CHANGED
|
@@ -51,9 +51,8 @@ import * as Frame from "./Frame.ts"
|
|
|
51
51
|
import * as FrameLoop from "./FrameLoop.ts"
|
|
52
52
|
import * as InterpolatorRegistry from "./InterpolatorRegistry.ts"
|
|
53
53
|
import { sourceOf } from "./internal/driven.ts"
|
|
54
|
-
import {
|
|
54
|
+
import { cachedResolver, checked, finite } from "./internal/options.ts"
|
|
55
55
|
import {
|
|
56
|
-
EaseDefinition,
|
|
57
56
|
initDecay,
|
|
58
57
|
initTween,
|
|
59
58
|
type Pass,
|
|
@@ -66,6 +65,7 @@ import {
|
|
|
66
65
|
runAt,
|
|
67
66
|
intervalAt,
|
|
68
67
|
intervalProgress,
|
|
68
|
+
keyframeAt,
|
|
69
69
|
stepDecay,
|
|
70
70
|
stopTimesOf,
|
|
71
71
|
timeIn,
|
|
@@ -74,11 +74,11 @@ import {
|
|
|
74
74
|
} from "./internal/stepper.ts"
|
|
75
75
|
import * as Inertia from "./Inertia.ts"
|
|
76
76
|
import type * as Point from "./Point.ts"
|
|
77
|
-
import * as Scalar from "./Scalar.ts"
|
|
78
77
|
import * as Spring from "./Spring.ts"
|
|
79
78
|
import type * as Supersede from "./Supersede.ts"
|
|
80
79
|
import type * as Values from "./Values.ts"
|
|
81
80
|
import { dual } from "./internal/dual.ts"
|
|
81
|
+
import { ModifierFields, type ResolvedKeyframes, type ResolvedModifiers, resolvedRunOf, resolveKeyframes } from "./internal/keyframes.ts"
|
|
82
82
|
import { tracedStream } from "./internal/tracing.ts"
|
|
83
83
|
|
|
84
84
|
// --- The data type -----------------------------------------------------------
|
|
@@ -1331,11 +1331,6 @@ export const springValues = (
|
|
|
1331
1331
|
|
|
1332
1332
|
// --- The composites ----------------------------------------------------------
|
|
1333
1333
|
|
|
1334
|
-
const NOT_REPEAT = "Expected a whole number of repeats, 0 or above, or Infinity"
|
|
1335
|
-
|
|
1336
|
-
/** A repeat count: a whole number, 0 or above, or `Infinity` to loop forever. */
|
|
1337
|
-
const Repeat = refine(number, (n) => n === Infinity || (Number.isInteger(n) && n >= 0) || NOT_REPEAT)
|
|
1338
|
-
|
|
1339
1334
|
/** `animate`'s bag, resolved: its run (its tween's `delay` 0), and the rest as given. */
|
|
1340
1335
|
interface ResolvedAnimate extends ResolvedModifiers {
|
|
1341
1336
|
readonly run: ResolvedRun
|
|
@@ -1343,36 +1338,6 @@ interface ResolvedAnimate extends ResolvedModifiers {
|
|
|
1343
1338
|
readonly seconds: number
|
|
1344
1339
|
}
|
|
1345
1340
|
|
|
1346
|
-
/** The {@link Modifiers}, resolved: as given, defaults filled in. */
|
|
1347
|
-
interface ResolvedModifiers {
|
|
1348
|
-
readonly repeat: number
|
|
1349
|
-
readonly repeatDelay: number
|
|
1350
|
-
readonly repeatType: "loop" | "reverse" | "mirror"
|
|
1351
|
-
readonly reverse: boolean
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
/** The {@link Modifiers}' fields (#66): `animate`'s bag and `keyframes`' (#429) add them to a tween's. */
|
|
1355
|
-
const ModifierFields = {
|
|
1356
|
-
repeat: field(Repeat, 0),
|
|
1357
|
-
repeatDelay: field(nonNegative, 0),
|
|
1358
|
-
repeatType: field(literals(["loop", "reverse", "mirror"]), "loop"),
|
|
1359
|
-
reverse: field(boolean, false),
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
/** A decoded bag's run: its tween played `repeat + 1` times, with its tween's `delay` 0 (held outside, by `delay`). */
|
|
1363
|
-
const resolvedRunOf = (tween: ResolvedTween, modifiers: ResolvedModifiers): ResolvedRun => {
|
|
1364
|
-
const cycle = tween.duration + modifiers.repeatDelay
|
|
1365
|
-
return {
|
|
1366
|
-
tween: { ...tween, delay: 0 },
|
|
1367
|
-
repeats: modifiers.repeat,
|
|
1368
|
-
gap: modifiers.repeatDelay,
|
|
1369
|
-
cycle,
|
|
1370
|
-
total: cycle * (modifiers.repeat + 1) - modifiers.repeatDelay,
|
|
1371
|
-
reverses: modifiers.repeatType === "reverse",
|
|
1372
|
-
mirrors: modifiers.repeatType === "mirror",
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
1341
|
/**
|
|
1377
1342
|
* `animate`'s bag (#66, ADR-0025 *Amendment (#66)*): a tween's fields and the repeat modifiers,
|
|
1378
1343
|
* checked once a bag. A fractional or negative `repeat`, a negative `repeatDelay`, or a tween field
|
|
@@ -1443,56 +1408,6 @@ const animateRun = (a: number, b: number, run: ResolvedRun, repeat: number, span
|
|
|
1443
1408
|
})
|
|
1444
1409
|
}
|
|
1445
1410
|
|
|
1446
|
-
/** `keyframes`' bag resolved (#429): its run (its tween's `delay` 0), an easing per Interval, and each stop's place in time. */
|
|
1447
|
-
interface ResolvedKeyframes extends ResolvedModifiers {
|
|
1448
|
-
readonly run: ResolvedRun
|
|
1449
|
-
readonly delay: number
|
|
1450
|
-
readonly seconds: number
|
|
1451
|
-
readonly eases: Arr.NonEmptyReadonlyArray<Easing.Easing>
|
|
1452
|
-
readonly times: ReadonlyArray<number> | undefined
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
/** One `ease` or several (#360): a list is an array whose first item isn't a number, which a bézier's is. */
|
|
1456
|
-
const EaseOrList = union([EaseDefinition, nonEmptyArray(EaseDefinition)])
|
|
1457
|
-
|
|
1458
|
-
/** Whether `times` run from 0 to 1, none before the one ahead of it. */
|
|
1459
|
-
const inOrder = (times: ReadonlyArray<number>): boolean => {
|
|
1460
|
-
// The pairs only once every time is in range (#460, Q8).
|
|
1461
|
-
if (!Arr.every(times, (time) => Bool.and(time >= 0, time <= 1))) return false
|
|
1462
|
-
return Arr.every(Arr.zip(times, Arr.drop(times, 1)), ([before, after]) => after >= before)
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
const NOT_IN_ORDER = "Expected times from 0 to 1, in order"
|
|
1466
|
-
|
|
1467
|
-
/** Each stop's place in time (#429): numbers from 0 to 1, in order. */
|
|
1468
|
-
const Times = refine(array(finite), (times) => inOrder(times) || NOT_IN_ORDER)
|
|
1469
|
-
|
|
1470
|
-
/**
|
|
1471
|
-
* `keyframes`' bag (#66): a tween's fields, its `ease` one Definition or one per Interval (#360), its
|
|
1472
|
-
* `times` and the repeat modifiers (#429), checked once a bag.
|
|
1473
|
-
*/
|
|
1474
|
-
const resolveKeyframes: (options: KeyframesOptions) => ResolvedKeyframes = cachedResolver(
|
|
1475
|
-
{ ...TweenFields, ...ModifierFields, ease: field(EaseOrList, Easing.linear), times: optionalField(Times) },
|
|
1476
|
-
(decoded): ResolvedKeyframes => {
|
|
1477
|
-
const list: Arr.NonEmptyReadonlyArray<Easing.Definition> = Bool.match(Bool.and(Arr.isArray(decoded.ease), Bool.not(Easing.isBezier(decoded.ease))), {
|
|
1478
|
-
onTrue: () => decoded.ease as Arr.NonEmptyReadonlyArray<Easing.Definition>,
|
|
1479
|
-
onFalse: (): Arr.NonEmptyReadonlyArray<Easing.Definition> => [decoded.ease as Easing.Definition],
|
|
1480
|
-
})
|
|
1481
|
-
const tween = resolvedTweenOf({ ...decoded, ease: list[0] })
|
|
1482
|
-
return {
|
|
1483
|
-
run: resolvedRunOf(tween, decoded),
|
|
1484
|
-
delay: tween.delay,
|
|
1485
|
-
seconds: tween.seconds,
|
|
1486
|
-
eases: Arr.map(list, Easing.resolve),
|
|
1487
|
-
times: decoded.times,
|
|
1488
|
-
repeat: decoded.repeat,
|
|
1489
|
-
repeatDelay: decoded.repeatDelay,
|
|
1490
|
-
repeatType: decoded.repeatType,
|
|
1491
|
-
reverse: decoded.reverse,
|
|
1492
|
-
}
|
|
1493
|
-
},
|
|
1494
|
-
)
|
|
1495
|
-
|
|
1496
1411
|
/** Stops a run can go between: a single one twice, so it holds; none, as 0. */
|
|
1497
1412
|
const stopsOf = <A>(stops: ReadonlyArray<A>, none: A): Arr.NonEmptyReadonlyArray<A> =>
|
|
1498
1413
|
Arr.match(stops, {
|
|
@@ -1539,11 +1454,7 @@ export const keyframes = (stops: ReadonlyArray<number>, options: KeyframesOption
|
|
|
1539
1454
|
return (dt): Frame.Frame<number> => {
|
|
1540
1455
|
elapsed += Math.min(dt, MAX_DT)
|
|
1541
1456
|
const done = passAt(elapsed, run, reverse, pass)
|
|
1542
|
-
|
|
1543
|
-
const i = intervalAt(time, stopTimes)
|
|
1544
|
-
const eased = eases[i % eases.length](intervalProgress(time, stopTimes, i))
|
|
1545
|
-
if (pass.flipped) return { value: Scalar.lerp(at[last - i], at[last - i - 1], eased), done }
|
|
1546
|
-
return { value: Scalar.lerp(at[i], at[i + 1], eased), done }
|
|
1457
|
+
return { value: keyframeAt(at, stopTimes, eases, pass, duration), done }
|
|
1547
1458
|
}
|
|
1548
1459
|
},
|
|
1549
1460
|
})
|
package/src/Playback.ts
CHANGED
|
@@ -25,6 +25,7 @@ import * as Frame from "./Frame.ts"
|
|
|
25
25
|
import * as Machine from "./Machine.ts"
|
|
26
26
|
import { measuredAs } from "./internal/driven.ts"
|
|
27
27
|
import { dual } from "./internal/dual.ts"
|
|
28
|
+
import { tickOf, writableOf } from "./internal/playhead.ts"
|
|
28
29
|
|
|
29
30
|
const TypeId = "~@wardic/core/Playback"
|
|
30
31
|
|
|
@@ -44,13 +45,6 @@ export interface Playhead extends Pipeable, Inspectable.Inspectable {
|
|
|
44
45
|
readonly paused: boolean
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
/** A Playhead as the machines and this module's operations write it. */
|
|
48
|
-
interface Writable {
|
|
49
|
-
time: number
|
|
50
|
-
speed: number
|
|
51
|
-
paused: boolean
|
|
52
|
-
}
|
|
53
|
-
|
|
54
48
|
const Proto = {
|
|
55
49
|
[TypeId]: TypeId,
|
|
56
50
|
...Inspectable.BaseProto,
|
|
@@ -131,7 +125,7 @@ export const drive: {
|
|
|
131
125
|
settles: self.settles,
|
|
132
126
|
span: self.span,
|
|
133
127
|
start: () => {
|
|
134
|
-
const writable = head
|
|
128
|
+
const writable = writableOf(head)
|
|
135
129
|
const at = head.time
|
|
136
130
|
let time = at
|
|
137
131
|
let step = runFrom(self, at)
|
|
@@ -153,7 +147,7 @@ export const drive: {
|
|
|
153
147
|
return held
|
|
154
148
|
}
|
|
155
149
|
held = undefined
|
|
156
|
-
const by =
|
|
150
|
+
const by = tickOf(head, dt, Machine.MAX_DT)
|
|
157
151
|
if (by >= 0) {
|
|
158
152
|
time += by
|
|
159
153
|
writable.time = time
|
|
@@ -182,7 +176,7 @@ export const seek: {
|
|
|
182
176
|
(time: number): (head: Playhead) => void
|
|
183
177
|
(head: Playhead, time: number): void
|
|
184
178
|
} = dual(2, (head: Playhead, time: number): void => {
|
|
185
|
-
const writable = head
|
|
179
|
+
const writable = writableOf(head)
|
|
186
180
|
writable.time = Math.max(0, time)
|
|
187
181
|
})
|
|
188
182
|
|
|
@@ -198,20 +192,20 @@ export const setSpeed: {
|
|
|
198
192
|
(speed: number): (head: Playhead) => void
|
|
199
193
|
(head: Playhead, speed: number): void
|
|
200
194
|
} = dual(2, (head: Playhead, speed: number): void => {
|
|
201
|
-
const writable = head
|
|
195
|
+
const writable = writableOf(head)
|
|
202
196
|
writable.speed = speed
|
|
203
197
|
})
|
|
204
198
|
|
|
205
199
|
/** Holds the machines driven through `head` where they are. */
|
|
206
200
|
// #618 (F1).
|
|
207
201
|
export const pause = (head: Playhead): void => {
|
|
208
|
-
const writable = head
|
|
202
|
+
const writable = writableOf(head)
|
|
209
203
|
writable.paused = true
|
|
210
204
|
}
|
|
211
205
|
|
|
212
206
|
/** Plays the machines driven through `head` on from where they're held. */
|
|
213
207
|
// #618 (F1).
|
|
214
208
|
export const play = (head: Playhead): void => {
|
|
215
|
-
const writable = head
|
|
209
|
+
const writable = writableOf(head)
|
|
216
210
|
writable.paused = false
|
|
217
211
|
}
|