@wardic/dom 1.1.4 → 1.3.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/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 +2 -2
- package/dist/unstable/BatchMembers.d.ts.map +1 -1
- package/dist/unstable/BatchMembers.js +32 -271
- package/dist/unstable/BatchMembers.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +13 -136
- 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/PointerValues.d.ts +34 -0
- package/dist/unstable/PointerValues.d.ts.map +1 -0
- package/dist/unstable/PointerValues.js +81 -0
- package/dist/unstable/PointerValues.js.map +1 -0
- package/dist/unstable/PresenceController.d.ts +8 -0
- package/dist/unstable/PresenceController.d.ts.map +1 -1
- package/dist/unstable/PresenceController.js +34 -13
- 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 +35 -270
- package/src/unstable/Imperative.ts +69 -917
- package/src/unstable/PointerValues.ts +115 -0
- package/src/unstable/PresenceController.ts +42 -11
|
@@ -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
|
|
|
@@ -504,15 +505,13 @@ export interface MembersPart {
|
|
|
504
505
|
}
|
|
505
506
|
|
|
506
507
|
/** An element call's part for one element: its index in the list, and what a plain animation of it takes. */
|
|
508
|
+
// `subject`: the shape core's Imperative track takes its plain Subjects' parts in (#882).
|
|
507
509
|
export interface ElementPart<T> {
|
|
508
|
-
readonly
|
|
510
|
+
readonly subject: Element
|
|
509
511
|
readonly index: number
|
|
510
512
|
readonly target: T
|
|
511
513
|
}
|
|
512
514
|
|
|
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
515
|
/** Whether `value` is a Batch's key's two stops through an element: a first stop, and a number. */
|
|
517
516
|
const isElementStops = (value: unknown): value is readonly [number | null, number] => {
|
|
518
517
|
if (!isPair(value)) return false
|
|
@@ -595,41 +594,27 @@ const keysKept = (animation: Sequence.Animation, keep: (key: string) => boolean)
|
|
|
595
594
|
export const sequencePartsOf = <S>(compiled: ReadonlyArray<readonly [S | BatchMemberEntry, Sequence.Animation]>): {
|
|
596
595
|
readonly batches: ReadonlyArray<SequencePart>
|
|
597
596
|
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.
|
|
597
|
+
} =>
|
|
598
|
+
// Core's grouping (#882), a member's keys the Batch doesn't have its element's: a member element's Segment gave them.
|
|
599
|
+
BatchCalls.sequencePartsOf<S, Element>(compiled, (member, animation) => {
|
|
600
|
+
const { binding } = member as BatchMemberEntry
|
|
615
601
|
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
|
-
}
|
|
602
|
+
const element = binding.elementOf(member.member)
|
|
603
|
+
if (Bool.and(Predicate.isNotUndefined(rest), Predicate.isNotUndefined(element))) return [element as Element, rest as Sequence.Animation]
|
|
604
|
+
return undefined
|
|
605
|
+
}) as { readonly batches: ReadonlyArray<SequencePart>; readonly others: ReadonlyArray<readonly [S | Element, Sequence.Animation]> }
|
|
621
606
|
|
|
622
607
|
/**
|
|
623
608
|
* An element call's parts (#665, Q14, Q35): each Batch's member elements as one part, in list order,
|
|
624
609
|
* with the Batch's keys; each element, a member's with the keys left, as one of its own.
|
|
625
610
|
*/
|
|
626
|
-
export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>, target: T): { readonly members: ReadonlyArray<MembersPart>; readonly
|
|
611
|
+
export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>, target: T): { readonly members: ReadonlyArray<MembersPart>; readonly subjects: ReadonlyArray<ElementPart<T>> } => {
|
|
627
612
|
const byBinding = new Map<BatchBinding, { readonly members: Array<number>; readonly split: MembersSplit<T> }>()
|
|
628
613
|
const parts: Array<ElementPart<T>> = []
|
|
629
614
|
Arr.forEach(elements, (element, index) => {
|
|
630
615
|
const entry = MEMBER_ELEMENTS.get(element)
|
|
631
616
|
if (Predicate.isUndefined(entry)) {
|
|
632
|
-
parts.push({ element, index, target })
|
|
617
|
+
parts.push({ subject: element, index, target })
|
|
633
618
|
return
|
|
634
619
|
}
|
|
635
620
|
let part = byBinding.get(entry.binding)
|
|
@@ -640,13 +625,13 @@ export const callPartsOf = <T extends object>(elements: ReadonlyArray<Element>,
|
|
|
640
625
|
part.members.push(entry.member)
|
|
641
626
|
// Its other keys by its place in the list, as a plain element's (Motion's `delay(i, n)`).
|
|
642
627
|
const rest = part.split.rest
|
|
643
|
-
if (Predicate.isNotUndefined(rest)) parts.push({ element, index, target: rest })
|
|
628
|
+
if (Predicate.isNotUndefined(rest)) parts.push({ subject: element, index, target: rest })
|
|
644
629
|
})
|
|
645
630
|
const members = Arr.filter(
|
|
646
631
|
Arr.map(Arr.fromIterable(byBinding), ([binding, part]): MembersPart => ({ binding, members: part.members, target: part.split.batch })),
|
|
647
632
|
(part) => !Rec.isEmptyRecord(part.target as Readonly<Record<string, unknown>>),
|
|
648
633
|
)
|
|
649
|
-
return { members,
|
|
634
|
+
return { members, subjects: parts }
|
|
650
635
|
}
|
|
651
636
|
|
|
652
637
|
/** The props an element gives a member's handle: its own `ref`, and its own `style`, as an object. */
|
|
@@ -706,8 +691,6 @@ const keysFrom = (count: number, targetsAt: (i: number) => Readonly<Record<strin
|
|
|
706
691
|
const keysOf = (config: BatchConfig): ReadonlyArray<string> =>
|
|
707
692
|
keysFrom(config.count, (i) => config.animate(i) as Readonly<Record<string, unknown>>, (i) => initialOf(config, i))
|
|
708
693
|
|
|
709
|
-
/** One change that lands every key at once: `skipAnimations`'. */
|
|
710
|
-
const INSTANT: Batch.Transition = { type: "tween", duration: 0 }
|
|
711
694
|
|
|
712
695
|
/** A key's index, -1 for a key the Batch hasn't. Built once. */
|
|
713
696
|
const keyIndexOr: (k: number | undefined) => number = /*#__PURE__*/ UndefinedOr.match({ onUndefined: (): number => -1, onDefined: (k: number): number => k })
|
|
@@ -715,41 +698,9 @@ const keyIndexOr: (k: number | undefined) => number = /*#__PURE__*/ UndefinedOr.
|
|
|
715
698
|
/** A Batch Reorder group's item in hand's change (#712): its `x` and `y` where it's held, at once. */
|
|
716
699
|
const IN_HAND: Batch.RetargetOptions = { transition: { x: INSTANT, y: INSTANT } }
|
|
717
700
|
|
|
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
|
-
}
|
|
701
|
+
/** A Batch key's value in a sequence (Q38): core's, its error createBatch's. */
|
|
702
|
+
const segmentValueOf = (key: string, value: unknown, memberName: string | undefined): Sequence.Stop | ReadonlyArray<Sequence.Stop> =>
|
|
703
|
+
BatchCalls.segmentValueOf(key, value, memberName, fail)
|
|
753
704
|
|
|
754
705
|
/**
|
|
755
706
|
* An `exit`, `whileHover` or `whileTap` given as an object, values with an optional `transition` (Q48,
|
|
@@ -925,123 +876,10 @@ const layoutOnMember = (element: Element): string =>
|
|
|
925
876
|
/** No values: an exit with none, which moves nothing and lets its element go at once. */
|
|
926
877
|
const NO_VALUES: Readonly<Record<string, unknown>> = {}
|
|
927
878
|
|
|
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
|
-
*/
|
|
879
|
+
/** Each key's plan for a change (#301): core's, its errors createBatch's. */
|
|
1010
880
|
// Once a change, per key.
|
|
1011
881
|
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
|
-
})
|
|
882
|
+
BatchCalls.plannedOf(positional, keys, given, reduced, fail)
|
|
1045
883
|
|
|
1046
884
|
/** The Handoff's module, once it has loaded (#706, Q11): every Batch after the first takes its members over at once. */
|
|
1047
885
|
// Module state (#460, Q7): one module, loaded once for the page.
|
|
@@ -1643,6 +1481,12 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
1643
1481
|
/** A key's Default transition toward `target`. */
|
|
1644
1482
|
const defaultFor = (k: number, target: number): Batch.Transition => env.defaultTransition.transitionFor(keys[k], target) as Batch.Transition
|
|
1645
1483
|
|
|
1484
|
+
/** What core's calls are told of the Batch (#882): its keys now, its Environment's, and createBatch's errors. */
|
|
1485
|
+
const planningNow = (): BatchCalls.Planning => ({ keys, positionalKeys: env.positionalKeys, defaultFor, fail })
|
|
1486
|
+
/** 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. */
|
|
1487
|
+
const bySlot: BatchCalls.Members = { indexOf: (slot) => indexOf[memberOf[slot]], count: () => form.size(), nameOf: (slot) => form.nameOf(memberOf[slot]) }
|
|
1488
|
+
const byMember: BatchCalls.Members = { indexOf: (i) => indexOf[i], count: () => form.size(), nameOf: (i) => form.nameOf(i) }
|
|
1489
|
+
|
|
1646
1490
|
/** The Batch's keys, fixed from now on, and room for every member's targets on them. */
|
|
1647
1491
|
const keysAre = (given: ReadonlyArray<string>): void => {
|
|
1648
1492
|
keys = given
|
|
@@ -2824,14 +2668,6 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2824
2668
|
enter(i, el)
|
|
2825
2669
|
}
|
|
2826
2670
|
|
|
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
2671
|
/** The slots an `animate` call moves: every member's there is, or the members it names, in order, whose elements have arrived. */
|
|
2836
2672
|
const callSlotsOf = (named: ReadonlyArray<number> | undefined): ReadonlyArray<number> =>
|
|
2837
2673
|
UndefinedOr.match(named, {
|
|
@@ -2858,39 +2694,11 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2858
2694
|
const track = (call: BatchCall): BatchTrack => {
|
|
2859
2695
|
if (Predicate.isUndefined(batch)) return landedTrack(call.settled)
|
|
2860
2696
|
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]
|
|
2697
|
+
// Each member's stops by key, its target and its first, `NaN` for none: worked out once, at the call (core's).
|
|
2698
|
+
const { toOf, fromOf } = BatchCalls.callTargets(planningNow(), keyIndex, bySlot, slots, call.target as Readonly<Record<string, unknown>>)
|
|
2891
2699
|
// The groups Wardic elements hold of its members that it moves come back first, from where they've left them (Q54).
|
|
2892
2700
|
retakeFor(slots, givesGroup((slot, k) => !Number.isNaN(toOf(slot, k))))
|
|
2893
|
-
return changeOn(slots, toOf,
|
|
2701
|
+
return changeOn(slots, toOf, fromOf, call)
|
|
2894
2702
|
}
|
|
2895
2703
|
|
|
2896
2704
|
/**
|
|
@@ -2903,25 +2711,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2903
2711
|
targetOf: (slot: number, k: number) => number,
|
|
2904
2712
|
fromOf: ((slot: number, k: number) => number) | undefined,
|
|
2905
2713
|
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
|
-
}
|
|
2714
|
+
): BatchTrack => controlsOf(Batch.animate(made(), slots, targetOf, BatchCalls.animateOptions(planningNow(), call, targetOf, fromOf)))
|
|
2925
2715
|
|
|
2926
2716
|
/** Whether member `i`'s element has arrived. */
|
|
2927
2717
|
const hasArrived = (i: number): boolean => slotOf[i] !== NO_SLOT
|
|
@@ -2934,17 +2724,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2934
2724
|
const segmentOf = (named: ReadonlyArray<number> | undefined, target: Readonly<Record<string, unknown>>): BatchSegment => {
|
|
2935
2725
|
if (Predicate.isUndefined(batch)) return { subjects: [], values: {} }
|
|
2936
2726
|
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
|
-
})
|
|
2727
|
+
const values = BatchCalls.segmentValues(planningNow(), (key) => keyIndex.has(key), byMember, moving, target)
|
|
2948
2728
|
return { subjects: Arr.map(moving, (i) => UndefinedOr.getOrThrow(entries[i])), values }
|
|
2949
2729
|
}
|
|
2950
2730
|
|
|
@@ -2973,23 +2753,8 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
|
|
|
2973
2753
|
})
|
|
2974
2754
|
// The groups Wardic elements hold of its members that it moves come back first (Q54).
|
|
2975
2755
|
retakeFor(slots, givesGroup((slot, k) => Predicate.isNotUndefined(UndefinedOr.getOrThrow(animations[slot]).keyframes[keys[k]])))
|
|
2976
|
-
//
|
|
2977
|
-
const keyframesOf = (
|
|
2978
|
-
const key = keys[k]
|
|
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
|
-
}
|
|
2756
|
+
// Each member's key's stops, once at its first play (core's).
|
|
2757
|
+
const keyframesOf = BatchCalls.keyframesFor(planningNow(), call, (slot) => UndefinedOr.getOrThrow(animations[slot]))
|
|
2993
2758
|
return controlsOf(Batch.keyframes(made(), slots, keyframesOf, { head: call.head, onLanded: call.settled }))
|
|
2994
2759
|
}
|
|
2995
2760
|
|