@wardic/dom 1.2.0 → 1.3.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/default-transition.d.ts +1 -1
- package/dist/internal/default-transition.d.ts.map +1 -1
- package/dist/internal/default-transition.js +4 -20
- package/dist/internal/default-transition.js.map +1 -1
- package/dist/internal/renderer.d.ts.map +1 -1
- package/dist/internal/renderer.js +3 -0
- package/dist/internal/renderer.js.map +1 -1
- package/dist/unstable/BatchMembers.d.ts +6 -2
- package/dist/unstable/BatchMembers.d.ts.map +1 -1
- package/dist/unstable/BatchMembers.js +33 -272
- package/dist/unstable/BatchMembers.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +15 -137
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +59 -721
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/PresenceController.js +4 -4
- package/dist/unstable/PresenceController.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/internal/default-transition.ts +5 -27
- package/src/internal/renderer.ts +3 -0
- package/src/unstable/BatchMembers.ts +41 -272
- package/src/unstable/Imperative.ts +71 -918
- package/src/unstable/PresenceController.ts +4 -4
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
import * as Batch from "@wardic/core/Batch"
|
|
27
27
|
import * as BaseValue from "@wardic/core/BaseValue"
|
|
28
28
|
import type * as DefaultTransition from "@wardic/core/DefaultTransition"
|
|
29
|
-
import type * as Machine from "@wardic/core/Machine"
|
|
30
29
|
import * as Playback from "@wardic/core/Playback"
|
|
31
30
|
import * as ReducedMotion from "@wardic/core/ReducedMotion"
|
|
32
31
|
import type * as Sequence from "@wardic/core/Sequence"
|
|
@@ -54,7 +53,9 @@ import type * as WardConfig from "./WardConfig.ts"
|
|
|
54
53
|
import type * as GestureInfo from "./GestureInfo.ts"
|
|
55
54
|
import type * as PresenceController from "./PresenceController.ts"
|
|
56
55
|
import * as PresenceRecord from "@wardic/core/unstable/PresenceRecord"
|
|
57
|
-
|
|
56
|
+
// #882 (ADR-0073, *Amendment (#882)*, PR 3): the calls' environment-agnostic part, core's, shared with `@wardic/object`.
|
|
57
|
+
import * as BatchCalls from "@wardic/core/unstable/BatchCalls"
|
|
58
|
+
import { delayedBy, INSTANT, isFirstStop, isPair, type KeyPlan, memberTransitionsOf, staggerOf, unstaggered } from "@wardic/core/unstable/BatchCalls"
|
|
58
59
|
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
59
60
|
import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue"
|
|
60
61
|
|
|
@@ -393,6 +394,8 @@ export interface BatchCall {
|
|
|
393
394
|
readonly skipAnimations: boolean
|
|
394
395
|
readonly head: Playback.Playhead
|
|
395
396
|
readonly settled: () => void
|
|
397
|
+
/** It ended with a key a later change took, never landing (#951). */
|
|
398
|
+
readonly taken: () => void
|
|
396
399
|
/** The members it moves, in order: every member when left out. */
|
|
397
400
|
readonly members: ReadonlyArray<number> | undefined
|
|
398
401
|
}
|
|
@@ -411,6 +414,8 @@ export interface BatchSequenceCall {
|
|
|
411
414
|
readonly skipAnimations: boolean
|
|
412
415
|
readonly head: Playback.Playhead
|
|
413
416
|
readonly settled: () => void
|
|
417
|
+
/** It ended with a key a later change took, never landing (#951). */
|
|
418
|
+
readonly taken: () => void
|
|
414
419
|
}
|
|
415
420
|
|
|
416
421
|
/**
|
|
@@ -504,15 +509,13 @@ export interface MembersPart {
|
|
|
504
509
|
}
|
|
505
510
|
|
|
506
511
|
/** An element call's part for one element: its index in the list, and what a plain animation of it takes. */
|
|
512
|
+
// `subject`: the shape core's Imperative track takes its plain Subjects' parts in (#882).
|
|
507
513
|
export interface ElementPart<T> {
|
|
508
|
-
readonly
|
|
514
|
+
readonly subject: Element
|
|
509
515
|
readonly index: number
|
|
510
516
|
readonly target: T
|
|
511
517
|
}
|
|
512
518
|
|
|
513
|
-
/** Whether `value` is a Batch's key's first stop through an element: a number, or `null` for where it is. */
|
|
514
|
-
const isFirstStop: Predicate.Predicate<unknown> = /*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isNull)
|
|
515
|
-
|
|
516
519
|
/** Whether `value` is a Batch's key's two stops through an element: a first stop, and a number. */
|
|
517
520
|
const isElementStops = (value: unknown): value is readonly [number | null, number] => {
|
|
518
521
|
if (!isPair(value)) return false
|
|
@@ -595,41 +598,27 @@ const keysKept = (animation: Sequence.Animation, keep: (key: string) => boolean)
|
|
|
595
598
|
export const sequencePartsOf = <S>(compiled: ReadonlyArray<readonly [S | BatchMemberEntry, Sequence.Animation]>): {
|
|
596
599
|
readonly batches: ReadonlyArray<SequencePart>
|
|
597
600
|
readonly others: ReadonlyArray<readonly [S | Element, Sequence.Animation]>
|
|
598
|
-
} =>
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
if (!isMemberEntry(subject)) {
|
|
603
|
-
others.push([subject as S, animation])
|
|
604
|
-
return
|
|
605
|
-
}
|
|
606
|
-
const { binding, member } = subject
|
|
607
|
-
let part = byBinding.get(binding)
|
|
608
|
-
if (Predicate.isUndefined(part)) {
|
|
609
|
-
part = { members: [], animations: [] }
|
|
610
|
-
byBinding.set(binding, part)
|
|
611
|
-
}
|
|
612
|
-
part.members.push(member)
|
|
613
|
-
part.animations.push(animation)
|
|
614
|
-
// Its keys the Batch doesn't have, its element's: a member element's Segment gave them.
|
|
601
|
+
} =>
|
|
602
|
+
// Core's grouping (#882), a member's keys the Batch doesn't have its element's: a member element's Segment gave them.
|
|
603
|
+
BatchCalls.sequencePartsOf<S, Element>(compiled, (member, animation) => {
|
|
604
|
+
const { binding } = member as BatchMemberEntry
|
|
615
605
|
const rest = keysKept(animation, (key) => binding.routeOf(key) !== "batch")
|
|
616
|
-
const element = binding.elementOf(member)
|
|
617
|
-
if (Bool.and(Predicate.isNotUndefined(rest), Predicate.isNotUndefined(element)))
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
606
|
+
const element = binding.elementOf(member.member)
|
|
607
|
+
if (Bool.and(Predicate.isNotUndefined(rest), Predicate.isNotUndefined(element))) return [element as Element, rest as Sequence.Animation]
|
|
608
|
+
return undefined
|
|
609
|
+
}) as { readonly batches: ReadonlyArray<SequencePart>; readonly others: ReadonlyArray<readonly [S | Element, Sequence.Animation]> }
|
|
621
610
|
|
|
622
611
|
/**
|
|
623
612
|
* An element call's parts (#665, Q14, Q35): each Batch's member elements as one part, in list order,
|
|
624
613
|
* with the Batch's keys; each element, a member's with the keys left, as one of its own.
|
|
625
614
|
*/
|
|
626
|
-
export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>, target: T): { readonly members: ReadonlyArray<MembersPart>; readonly
|
|
615
|
+
export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>, target: T): { readonly members: ReadonlyArray<MembersPart>; readonly subjects: ReadonlyArray<ElementPart<T>> } => {
|
|
627
616
|
const byBinding = new Map<BatchBinding, { readonly members: Array<number>; readonly split: MembersSplit<T> }>()
|
|
628
617
|
const parts: Array<ElementPart<T>> = []
|
|
629
618
|
Arr.forEach(elements, (element, index) => {
|
|
630
619
|
const entry = MEMBER_ELEMENTS.get(element)
|
|
631
620
|
if (Predicate.isUndefined(entry)) {
|
|
632
|
-
parts.push({ element, index, target })
|
|
621
|
+
parts.push({ subject: element, index, target })
|
|
633
622
|
return
|
|
634
623
|
}
|
|
635
624
|
let part = byBinding.get(entry.binding)
|
|
@@ -640,13 +629,13 @@ export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>,
|
|
|
640
629
|
part.members.push(entry.member)
|
|
641
630
|
// Its other keys by its place in the list, as a plain element's (Motion's `delay(i, n)`).
|
|
642
631
|
const rest = part.split.rest
|
|
643
|
-
if (Predicate.isNotUndefined(rest)) parts.push({ element, index, target: rest })
|
|
632
|
+
if (Predicate.isNotUndefined(rest)) parts.push({ subject: element, index, target: rest })
|
|
644
633
|
})
|
|
645
634
|
const members = Arr.filter(
|
|
646
635
|
Arr.map(Arr.fromIterable(byBinding), ([binding, part]): MembersPart => ({ binding, members: part.members, target: part.split.batch })),
|
|
647
636
|
(part) => !Rec.isEmptyRecord(part.target as Readonly<Record<string, unknown>>),
|
|
648
637
|
)
|
|
649
|
-
return { members,
|
|
638
|
+
return { members, subjects: parts }
|
|
650
639
|
}
|
|
651
640
|
|
|
652
641
|
/** The props an element gives a member's handle: its own `ref`, and its own `style`, as an object. */
|
|
@@ -706,8 +695,6 @@ const keysFrom = (count: number, targetsAt: (i: number) => Readonly<Record<strin
|
|
|
706
695
|
const keysOf = (config: BatchConfig): ReadonlyArray<string> =>
|
|
707
696
|
keysFrom(config.count, (i) => config.animate(i) as Readonly<Record<string, unknown>>, (i) => initialOf(config, i))
|
|
708
697
|
|
|
709
|
-
/** One change that lands every key at once: `skipAnimations`'. */
|
|
710
|
-
const INSTANT: Batch.Transition = { type: "tween", duration: 0 }
|
|
711
698
|
|
|
712
699
|
/** A key's index, -1 for a key the Batch hasn't. Built once. */
|
|
713
700
|
const keyIndexOr: (k: number | undefined) => number = /*#__PURE__*/ UndefinedOr.match({ onUndefined: (): number => -1, onDefined: (k: number): number => k })
|
|
@@ -715,41 +702,9 @@ const keyIndexOr: (k: number | undefined) => number = /*#__PURE__*/ UndefinedOr.
|
|
|
715
702
|
/** A Batch Reorder group's item in hand's change (#712): its `x` and `y` where it's held, at once. */
|
|
716
703
|
const IN_HAND: Batch.RetargetOptions = { transition: { x: INSTANT, y: INSTANT } }
|
|
717
704
|
|
|
718
|
-
/** A
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const landingAfter = (delay: number): Machine.KeyframesOptions => {
|
|
723
|
-
const known = LANDINGS.get(delay)
|
|
724
|
-
if (Predicate.isNotUndefined(known)) return known
|
|
725
|
-
const made: Machine.KeyframesOptions = { duration: 0, delay }
|
|
726
|
-
LANDINGS.set(delay, made)
|
|
727
|
-
return made
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
/** A Batch key's stop in a sequence, as core's Batch takes it: a number, `NaN` for `null`. */
|
|
731
|
-
const stopNumber = (stop: Sequence.Stop): number => {
|
|
732
|
-
if (Predicate.isNumber(stop)) return stop
|
|
733
|
-
return Number.NaN
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
/** A key's last stop that's a number, `NaN` (where it is) for none: what its `null`s after it hold. */
|
|
737
|
-
const lastNumber = (stops: ReadonlyArray<number>): number =>
|
|
738
|
-
Option.getOrElse(Arr.findLast(stops, (stop) => !Number.isNaN(stop)), () => Number.NaN)
|
|
739
|
-
|
|
740
|
-
/** Whether `value` is a Batch key's value in a sequence: a number, `null`, or stops of them. */
|
|
741
|
-
const isSegmentStops = (value: unknown): boolean => {
|
|
742
|
-
if (isFirstStop(value)) return true
|
|
743
|
-
if (!Arr.isArray(value)) return false
|
|
744
|
-
return Arr.every(value, isFirstStop)
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
/** A Batch key's value in a sequence (Q38): a number, `null` or stops of them; else an error naming the key, and the member a function gave it. */
|
|
748
|
-
const segmentValueOf = (key: string, value: unknown, memberName: string | undefined): Sequence.Stop | ReadonlyArray<Sequence.Stop> => {
|
|
749
|
-
if (isSegmentStops(value)) return value as Sequence.Stop | ReadonlyArray<Sequence.Stop>
|
|
750
|
-
const whose = UndefinedOr.match(memberName, { onUndefined: () => "", onDefined: (name) => `${name}'s ` })
|
|
751
|
-
return fail(`a sequence gives ${whose}"${key}" as ${JSON.stringify(value)}: a Batch's key takes a number, \`null\`, or stops of them`)
|
|
752
|
-
}
|
|
705
|
+
/** A Batch key's value in a sequence (Q38): core's, its error createBatch's. */
|
|
706
|
+
const segmentValueOf = (key: string, value: unknown, memberName: string | undefined): Sequence.Stop | ReadonlyArray<Sequence.Stop> =>
|
|
707
|
+
BatchCalls.segmentValueOf(key, value, memberName, fail)
|
|
753
708
|
|
|
754
709
|
/**
|
|
755
710
|
* An `exit`, `whileHover` or `whileTap` given as an object, values with an optional `transition` (Q48,
|
|
@@ -925,123 +880,10 @@ const layoutOnMember = (element: Element): string =>
|
|
|
925
880
|
/** No values: an exit with none, which moves nothing and lets its element go at once. */
|
|
926
881
|
const NO_VALUES: Readonly<Record<string, unknown>> = {}
|
|
927
882
|
|
|
928
|
-
/**
|
|
929
|
-
const isPair = (value: unknown): value is readonly [unknown, unknown] => {
|
|
930
|
-
if (!Arr.isArray(value)) return false
|
|
931
|
-
return value.length === 2
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
/** Reduced motion's Snap after `delay`: a 0 s tween, kept by its delay so its keys share one. */
|
|
935
|
-
// Module state (#460, Q7): a cache built once, keyed by what it caches.
|
|
936
|
-
const SNAPS = new Map<number, Batch.Transition>()
|
|
937
|
-
|
|
938
|
-
const snapAfter = (delay: number): Batch.Transition => {
|
|
939
|
-
const known = SNAPS.get(delay)
|
|
940
|
-
if (Predicate.isNotUndefined(known)) return known
|
|
941
|
-
const made: Batch.Transition = { type: "tween", duration: 0, delay }
|
|
942
|
-
SNAPS.set(delay, made)
|
|
943
|
-
return made
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* A Default transition held by a key's own `delay`, as a Wardic element's is when its transition gives
|
|
948
|
-
* only a delay (ADR-0051): one object for each transition and delay, so the members on it share it.
|
|
949
|
-
*/
|
|
950
|
-
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
951
|
-
const DELAYED = new WeakMap<object, Map<number, Batch.Transition>>()
|
|
952
|
-
|
|
953
|
-
const delayedBy = (transition: Batch.Transition, delay: number): Batch.Transition => {
|
|
954
|
-
if (delay === 0) return transition
|
|
955
|
-
let byDelay = DELAYED.get(transition)
|
|
956
|
-
if (Predicate.isUndefined(byDelay)) {
|
|
957
|
-
byDelay = new Map()
|
|
958
|
-
DELAYED.set(transition, byDelay)
|
|
959
|
-
}
|
|
960
|
-
const known = byDelay.get(delay)
|
|
961
|
-
if (Predicate.isNotUndefined(known)) return known
|
|
962
|
-
const made = { ...transition, delay } as Batch.Transition
|
|
963
|
-
byDelay.set(delay, made)
|
|
964
|
-
return made
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* A transition without a `stagger()` delay, which a change gives each member by its place: one object
|
|
969
|
-
* each. A `delay` in seconds stays, held by the keys the transition's own fields reach, as a Wardic
|
|
970
|
-
* element's top-level delay is.
|
|
971
|
-
*/
|
|
972
|
-
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
973
|
-
const UNSTAGGERED = new WeakMap<object, WardConfig.WardicTransition>()
|
|
974
|
-
|
|
975
|
-
const unstaggered = (given: WardicBatchTransition | WardConfig.WardicTransition): WardConfig.WardicTransition => {
|
|
976
|
-
if (!Predicate.isFunction(given.delay)) return given as WardConfig.WardicTransition
|
|
977
|
-
const known = UNSTAGGERED.get(given)
|
|
978
|
-
if (Predicate.isNotUndefined(known)) return known
|
|
979
|
-
const made = { ...given, delay: undefined } as unknown as WardConfig.WardicTransition
|
|
980
|
-
UNSTAGGERED.set(given, made)
|
|
981
|
-
return made
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
/** A change's `stagger()` delay, for the members it moves; `undefined` for none. */
|
|
985
|
-
const staggerOf = (given: WardConfig.WardicTransition | undefined): ((rank: number, n: number) => number) | undefined => {
|
|
986
|
-
if (Predicate.isUndefined(given)) return undefined
|
|
987
|
-
const delay: unknown = given.delay
|
|
988
|
-
if (Predicate.isFunction(delay)) return delay as (rank: number, n: number) => number
|
|
989
|
-
return undefined
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
/** A key's transition as a Batch runs it: its run, which can't be an inertia or repeat. */
|
|
993
|
-
const batchRunOf = (run: RetargetLegs.Run, key: string): Batch.Transition => {
|
|
994
|
-
if (run.type === "inertia") fail(`"${key}" has an inertia transition, which a Batch can't run: give it a spring or a tween`)
|
|
995
|
-
if (Predicate.hasProperty(run, "repeat")) fail(`"${key}"'s transition repeats, which a Batch can't run`)
|
|
996
|
-
return run as Batch.Transition
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
/** A change's plan for one key: its own transition, or `undefined` for its Default transition held by `delay`. */
|
|
1000
|
-
interface KeyPlan {
|
|
1001
|
-
readonly own: Batch.Transition | undefined
|
|
1002
|
-
readonly delay: number
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* Each key's plan for a change, by its index, as a Wardic element's keys run (#301): its entry, else
|
|
1007
|
-
* `default`, else the transition's own fields; reduced motion's Snap for a positional key that doesn't
|
|
1008
|
-
* opt out; its Default transition, held by its own `delay`, for a key whose transition isn't defined.
|
|
1009
|
-
*/
|
|
883
|
+
/** Each key's plan for a change (#301): core's, its errors createBatch's. */
|
|
1010
884
|
// Once a change, per key.
|
|
1011
885
|
const plannedOf = (positional: ReducedMotion.PositionalKeys["Service"], keys: ReadonlyArray<string>, given: WardConfig.WardicTransition | undefined, reduced: boolean): ReadonlyArray<KeyPlan> =>
|
|
1012
|
-
|
|
1013
|
-
const transition = RetargetLegs.transitionForKey(given, key)
|
|
1014
|
-
let delay = 0
|
|
1015
|
-
let respects = true
|
|
1016
|
-
if (Predicate.isNotUndefined(transition)) {
|
|
1017
|
-
if (Predicate.isNumber(transition.delay)) delay = transition.delay
|
|
1018
|
-
respects = transition.respectReducedMotion !== false
|
|
1019
|
-
}
|
|
1020
|
-
if (reduced && respects && positional.isPositional(key)) return { own: snapAfter(delay), delay }
|
|
1021
|
-
const run = RetargetLegs.runOf(transition)
|
|
1022
|
-
if (Predicate.isUndefined(run)) return { own: undefined, delay }
|
|
1023
|
-
return { own: batchRunOf(run, key), delay }
|
|
1024
|
-
})
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* A member's transitions on `keys` for a change planned as `planned`: each key's own, else its Default
|
|
1028
|
-
* transition (`defaultFor`) toward its target there, `targetAt(k)`; every key at once when it's skipped.
|
|
1029
|
-
* A server's Appear plan's (#706) and a client's check of it.
|
|
1030
|
-
*/
|
|
1031
|
-
// Per member per key, at a server's render and at a hydrating client's first change (#706): statements.
|
|
1032
|
-
const memberTransitionsOf = (
|
|
1033
|
-
keys: ReadonlyArray<string>,
|
|
1034
|
-
planned: ReadonlyArray<KeyPlan>,
|
|
1035
|
-
defaultFor: (key: string, target: number) => Batch.Transition,
|
|
1036
|
-
targetAt: (k: number) => number,
|
|
1037
|
-
skipped: boolean,
|
|
1038
|
-
): ReadonlyArray<Batch.Transition> =>
|
|
1039
|
-
Arr.map(keys, (key, k) => {
|
|
1040
|
-
if (skipped) return INSTANT
|
|
1041
|
-
const plan = planned[k] as KeyPlan
|
|
1042
|
-
if (Predicate.isNotUndefined(plan.own)) return plan.own
|
|
1043
|
-
return delayedBy(defaultFor(key, targetAt(k)), plan.delay)
|
|
1044
|
-
})
|
|
886
|
+
BatchCalls.plannedOf(positional, keys, given, reduced, fail)
|
|
1045
887
|
|
|
1046
888
|
/** The Handoff's module, once it has loaded (#706, Q11): every Batch after the first takes its members over at once. */
|
|
1047
889
|
// Module state (#460, Q7): one module, loaded once for the page.
|
|
@@ -1643,6 +1485,12 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
1643
1485
|
/** A key's Default transition toward `target`. */
|
|
1644
1486
|
const defaultFor = (k: number, target: number): Batch.Transition => env.defaultTransition.transitionFor(keys[k], target) as Batch.Transition
|
|
1645
1487
|
|
|
1488
|
+
/** What core's calls are told of the Batch (#882): its keys now, its Environment's, and createBatch's errors. */
|
|
1489
|
+
const planningNow = (): BatchCalls.Planning => ({ keys, positionalKeys: env.positionalKeys, defaultFor, fail })
|
|
1490
|
+
/** Its members as core's calls name them (#882): by slot, a call's, and by number, a Segment's; their place in the list, the count, an error's name. */
|
|
1491
|
+
const bySlot: BatchCalls.Members = { indexOf: (slot) => indexOf[memberOf[slot]], count: () => form.size(), nameOf: (slot) => form.nameOf(memberOf[slot]) }
|
|
1492
|
+
const byMember: BatchCalls.Members = { indexOf: (i) => indexOf[i], count: () => form.size(), nameOf: (i) => form.nameOf(i) }
|
|
1493
|
+
|
|
1646
1494
|
/** The Batch's keys, fixed from now on, and room for every member's targets on them. */
|
|
1647
1495
|
const keysAre = (given: ReadonlyArray<string>): void => {
|
|
1648
1496
|
keys = given
|
|
@@ -2824,14 +2672,6 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2824
2672
|
enter(i, el)
|
|
2825
2673
|
}
|
|
2826
2674
|
|
|
2827
|
-
/** One stop's value for member `i`: a number, or a function's of its index and the count. */
|
|
2828
|
-
const stopAt = (key: string, stop: unknown, i: number): number => {
|
|
2829
|
-
let value = stop
|
|
2830
|
-
if (Predicate.isFunction(stop)) value = stop(indexOf[i], form.size())
|
|
2831
|
-
if (Predicate.isNumber(value)) return value
|
|
2832
|
-
return fail(`an animate call's "${key}" gives ${form.nameOf(i)} ${JSON.stringify(value)}: a Batch takes numbers`)
|
|
2833
|
-
}
|
|
2834
|
-
|
|
2835
2675
|
/** The slots an `animate` call moves: every member's there is, or the members it names, in order, whose elements have arrived. */
|
|
2836
2676
|
const callSlotsOf = (named: ReadonlyArray<number> | undefined): ReadonlyArray<number> =>
|
|
2837
2677
|
UndefinedOr.match(named, {
|
|
@@ -2858,39 +2698,11 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2858
2698
|
const track = (call: BatchCall): BatchTrack => {
|
|
2859
2699
|
if (Predicate.isUndefined(batch)) return landedTrack(call.settled)
|
|
2860
2700
|
const slots = callSlotsOf(call.members)
|
|
2861
|
-
// Each member's stops by key, its target and its first, `NaN` for none: worked out once, at the call.
|
|
2862
|
-
const
|
|
2863
|
-
const froms = new Float64Array(capacity * stride).fill(Number.NaN)
|
|
2864
|
-
let firsts = false
|
|
2865
|
-
const given = call.target as Readonly<Record<string, unknown>>
|
|
2866
|
-
Arr.forEach(Rec.keys(given), (key) => {
|
|
2867
|
-
const k = keyIndex.get(key)
|
|
2868
|
-
if (Predicate.isUndefined(k)) return fail(`an animate call gives "${key}", which isn't one of the Batch's keys (${keys.join(", ")})`)
|
|
2869
|
-
const value = given[key]
|
|
2870
|
-
// Per member per key at a call (#665): statements.
|
|
2871
|
-
Arr.forEach(slots, (slot) => {
|
|
2872
|
-
const i = memberOf[slot]
|
|
2873
|
-
const at = i * stride + k
|
|
2874
|
-
let stops = value
|
|
2875
|
-
if (Predicate.isFunction(value)) stops = value(indexOf[i], form.size())
|
|
2876
|
-
if (isPair(stops)) {
|
|
2877
|
-
froms[at] = stopAt(key, stops[0], i)
|
|
2878
|
-
tos[at] = stopAt(key, stops[1], i)
|
|
2879
|
-
firsts = true
|
|
2880
|
-
return
|
|
2881
|
-
}
|
|
2882
|
-
if (Predicate.isNumber(stops)) {
|
|
2883
|
-
tos[at] = stops
|
|
2884
|
-
return
|
|
2885
|
-
}
|
|
2886
|
-
return fail(`an animate call's "${key}" is ${JSON.stringify(stops)}: a Batch takes a number or two, its first and its target, or a function of a member's index that gives them`)
|
|
2887
|
-
})
|
|
2888
|
-
})
|
|
2889
|
-
const fromOf = (slot: number, k: number): number => froms[memberOf[slot] * stride + k]
|
|
2890
|
-
const toOf = (slot: number, k: number): number => tos[memberOf[slot] * stride + k]
|
|
2701
|
+
// Each member's stops by key, its target and its first, `NaN` for none: worked out once, at the call (core's).
|
|
2702
|
+
const { toOf, fromOf } = BatchCalls.callTargets(planningNow(), keyIndex, bySlot, slots, call.target as Readonly<Record<string, unknown>>)
|
|
2891
2703
|
// The groups Wardic elements hold of its members that it moves come back first, from where they've left them (Q54).
|
|
2892
2704
|
retakeFor(slots, givesGroup((slot, k) => !Number.isNaN(toOf(slot, k))))
|
|
2893
|
-
return changeOn(slots, toOf,
|
|
2705
|
+
return changeOn(slots, toOf, fromOf, call)
|
|
2894
2706
|
}
|
|
2895
2707
|
|
|
2896
2708
|
/**
|
|
@@ -2902,26 +2714,8 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2902
2714
|
slots: ReadonlyArray<number>,
|
|
2903
2715
|
targetOf: (slot: number, k: number) => number,
|
|
2904
2716
|
fromOf: ((slot: number, k: number) => number) | undefined,
|
|
2905
|
-
call: Pick<BatchCall, "transition" | "reducedMotion" | "skipAnimations" | "head" | "settled"> & { readonly onMemberLanded?: (slot: number) => void },
|
|
2906
|
-
): BatchTrack =>
|
|
2907
|
-
const transition = Bool.match(call.skipAnimations, {
|
|
2908
|
-
onTrue: () => (): Batch.Transition => INSTANT,
|
|
2909
|
-
onFalse: () => {
|
|
2910
|
-
const planned = plannedOf(env.positionalKeys, keys, UndefinedOr.map(call.transition, unstaggered), call.reducedMotion)
|
|
2911
|
-
return (slot: number, k: number): Batch.Transition => {
|
|
2912
|
-
const plan = planned[k]
|
|
2913
|
-
if (Predicate.isNotUndefined(plan.own)) return plan.own
|
|
2914
|
-
return delayedBy(defaultFor(k, targetOf(slot, k)), plan.delay)
|
|
2915
|
-
}
|
|
2916
|
-
},
|
|
2917
|
-
})
|
|
2918
|
-
const options: { -readonly [K in keyof Batch.AnimateOptions]: Batch.AnimateOptions[K] } = { head: call.head, transition, onLanded: call.settled }
|
|
2919
|
-
if (Predicate.isNotUndefined(fromOf)) options.from = fromOf
|
|
2920
|
-
if (Predicate.isNotUndefined(call.onMemberLanded)) options.onMemberLanded = call.onMemberLanded
|
|
2921
|
-
const delay = Bool.match(call.skipAnimations, { onTrue: () => undefined, onFalse: () => staggerOf(call.transition) })
|
|
2922
|
-
if (Predicate.isNotUndefined(delay)) options.delay = delay
|
|
2923
|
-
return controlsOf(Batch.animate(made(), slots, targetOf, options))
|
|
2924
|
-
}
|
|
2717
|
+
call: Pick<BatchCall, "transition" | "reducedMotion" | "skipAnimations" | "head" | "settled"> & { readonly taken?: () => void; readonly onMemberLanded?: (slot: number) => void },
|
|
2718
|
+
): BatchTrack => controlsOf(Batch.animate(made(), slots, targetOf, BatchCalls.animateOptions(planningNow(), call, targetOf, fromOf)))
|
|
2925
2719
|
|
|
2926
2720
|
/** Whether member `i`'s element has arrived. */
|
|
2927
2721
|
const hasArrived = (i: number): boolean => slotOf[i] !== NO_SLOT
|
|
@@ -2934,17 +2728,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2934
2728
|
const segmentOf = (named: ReadonlyArray<number> | undefined, target: Readonly<Record<string, unknown>>): BatchSegment => {
|
|
2935
2729
|
if (Predicate.isUndefined(batch)) return { subjects: [], values: {} }
|
|
2936
2730
|
const moving = membersOf(named)
|
|
2937
|
-
const values
|
|
2938
|
-
Arr.forEach(Rec.keys(target), (key) => {
|
|
2939
|
-
const value = target[key]
|
|
2940
|
-
if (Predicate.isUndefined(value)) return
|
|
2941
|
-
if (!keyIndex.has(key)) return fail(`a sequence's Segment of a Batch gives "${key}", which isn't one of its keys (${keys.join(", ")})`)
|
|
2942
|
-
if (Predicate.isFunction(value)) {
|
|
2943
|
-
values[key] = (index: number) => segmentValueOf(key, value(indexOf[moving[index]], form.size()), form.nameOf(moving[index]))
|
|
2944
|
-
return
|
|
2945
|
-
}
|
|
2946
|
-
values[key] = segmentValueOf(key, value, undefined)
|
|
2947
|
-
})
|
|
2731
|
+
const values = BatchCalls.segmentValues(planningNow(), (key) => keyIndex.has(key), byMember, moving, target)
|
|
2948
2732
|
return { subjects: Arr.map(moving, (i) => UndefinedOr.getOrThrow(entries[i])), values }
|
|
2949
2733
|
}
|
|
2950
2734
|
|
|
@@ -2973,24 +2757,9 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2973
2757
|
})
|
|
2974
2758
|
// The groups Wardic elements hold of its members that it moves come back first (Q54).
|
|
2975
2759
|
retakeFor(slots, givesGroup((slot, k) => Predicate.isNotUndefined(UndefinedOr.getOrThrow(animations[slot]).keyframes[keys[k]])))
|
|
2976
|
-
//
|
|
2977
|
-
const keyframesOf = (
|
|
2978
|
-
|
|
2979
|
-
const animation = UndefinedOr.getOrThrow(animations[slot])
|
|
2980
|
-
const given = animation.keyframes[key]
|
|
2981
|
-
if (Predicate.isUndefined(given)) return undefined
|
|
2982
|
-
const transition = UndefinedOr.getOrThrow(animation.transition[key])
|
|
2983
|
-
const stops = Arr.map(given, stopNumber)
|
|
2984
|
-
const snaps = call.reducedMotion && env.positionalKeys.isPositional(key)
|
|
2985
|
-
if (!call.skipAnimations && !snaps) return { stops, transition }
|
|
2986
|
-
// Where its run would end, from where it is: after its delay for reduced motion's Snap, at once when
|
|
2987
|
-
// skipped. Its last stop is its last number: a sequence ends a key with a `null` when its last Segment ends first.
|
|
2988
|
-
const end = ReducedMotion.endOf(stops[0], lastNumber(stops), transition)
|
|
2989
|
-
let delay = 0
|
|
2990
|
-
if (!call.skipAnimations && Predicate.isNotUndefined(transition.delay)) delay = transition.delay
|
|
2991
|
-
return { stops: [Number.NaN, end], transition: landingAfter(delay) }
|
|
2992
|
-
}
|
|
2993
|
-
return controlsOf(Batch.keyframes(made(), slots, keyframesOf, { head: call.head, onLanded: call.settled }))
|
|
2760
|
+
// Each member's key's stops, once at its first play (core's).
|
|
2761
|
+
const keyframesOf = BatchCalls.keyframesFor(planningNow(), call, (slot) => UndefinedOr.getOrThrow(animations[slot]))
|
|
2762
|
+
return controlsOf(Batch.keyframes(made(), slots, keyframesOf, BatchCalls.keyframesOptions(call)))
|
|
2994
2763
|
}
|
|
2995
2764
|
|
|
2996
2765
|
/** A driven change's controls, as an `animate` call's track: played, it wakes the Batch's run. */
|