@wardic/dom 1.0.1 → 1.1.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/Appear.d.ts +3 -2
- package/dist/Appear.d.ts.map +1 -1
- package/dist/Appear.js +4 -3
- package/dist/Appear.js.map +1 -1
- package/dist/DomProjectionSystem.js +3 -3
- package/dist/DomProjectionSystem.js.map +1 -1
- package/dist/FlushGate.d.ts +6 -6
- package/dist/FlushGate.d.ts.map +1 -1
- package/dist/FlushGate.js +11 -8
- package/dist/FlushGate.js.map +1 -1
- package/dist/ReorderController.js +3 -3
- package/dist/ReorderController.js.map +1 -1
- package/dist/Report.d.ts +1 -1
- package/dist/Report.d.ts.map +1 -1
- package/dist/Report.js +3 -2
- package/dist/Report.js.map +1 -1
- package/dist/Style.d.ts +2 -1
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +3 -1
- package/dist/Style.js.map +1 -1
- package/dist/TimelineValue.d.ts +18 -0
- package/dist/TimelineValue.d.ts.map +1 -0
- package/dist/TimelineValue.js +20 -0
- package/dist/TimelineValue.js.map +1 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/appear.d.ts +10 -4
- package/dist/internal/appear.d.ts.map +1 -1
- package/dist/internal/appear.js +18 -8
- package/dist/internal/appear.js.map +1 -1
- package/dist/internal/batch-handoff.d.ts +25 -0
- package/dist/internal/batch-handoff.d.ts.map +1 -0
- package/dist/internal/batch-handoff.js +64 -0
- package/dist/internal/batch-handoff.js.map +1 -0
- package/dist/internal/drag-defaults.js +4 -1
- package/dist/internal/drag-defaults.js.map +1 -1
- package/dist/internal/gate-environment.d.ts +4 -0
- package/dist/internal/gate-environment.d.ts.map +1 -0
- package/dist/internal/gate-environment.js +21 -0
- package/dist/internal/gate-environment.js.map +1 -0
- package/dist/internal/projection.d.ts.map +1 -1
- package/dist/internal/projection.js +22 -21
- package/dist/internal/projection.js.map +1 -1
- package/dist/internal/renderer.d.ts +13 -0
- package/dist/internal/renderer.d.ts.map +1 -1
- package/dist/internal/renderer.js +21 -0
- package/dist/internal/renderer.js.map +1 -1
- package/dist/internal/reorder.d.ts +2 -2
- package/dist/internal/reorder.d.ts.map +1 -1
- package/dist/internal/reorder.js +2 -2
- package/dist/internal/reorder.js.map +1 -1
- package/dist/internal/scroll.d.ts +17 -0
- package/dist/internal/scroll.d.ts.map +1 -1
- package/dist/internal/scroll.js +23 -15
- package/dist/internal/scroll.js.map +1 -1
- package/dist/internal/starting-style.d.ts +0 -83
- package/dist/internal/starting-style.d.ts.map +1 -1
- package/dist/internal/starting-style.js +16 -143
- package/dist/internal/starting-style.js.map +1 -1
- package/dist/internal/timeline.d.ts +56 -0
- package/dist/internal/timeline.d.ts.map +1 -0
- package/dist/internal/timeline.js +389 -0
- package/dist/internal/timeline.js.map +1 -0
- package/dist/unstable/AppearAnimations.d.ts +191 -0
- package/dist/unstable/AppearAnimations.d.ts.map +1 -0
- package/dist/unstable/AppearAnimations.js +561 -0
- package/dist/unstable/AppearAnimations.js.map +1 -0
- package/dist/unstable/BatchMembers.d.ts +513 -0
- package/dist/unstable/BatchMembers.d.ts.map +1 -0
- package/dist/unstable/BatchMembers.js +2490 -0
- package/dist/unstable/BatchMembers.js.map +1 -0
- package/dist/unstable/DomValues.d.ts +25 -0
- package/dist/unstable/DomValues.d.ts.map +1 -0
- package/dist/unstable/DomValues.js +45 -0
- package/dist/unstable/DomValues.js.map +1 -0
- package/dist/unstable/DragConstraints.d.ts +48 -0
- package/dist/unstable/DragConstraints.d.ts.map +1 -0
- package/dist/unstable/DragConstraints.js +49 -0
- package/dist/unstable/DragConstraints.js.map +1 -0
- package/dist/unstable/DragControls.d.ts +50 -0
- package/dist/unstable/DragControls.d.ts.map +1 -0
- package/dist/unstable/DragControls.js +55 -0
- package/dist/unstable/DragControls.js.map +1 -0
- package/dist/unstable/DragDefaults.d.ts +34 -0
- package/dist/unstable/DragDefaults.d.ts.map +1 -0
- package/dist/unstable/DragDefaults.js +47 -0
- package/dist/unstable/DragDefaults.js.map +1 -0
- package/dist/unstable/DragTrack.d.ts +236 -0
- package/dist/unstable/DragTrack.d.ts.map +1 -0
- package/dist/unstable/DragTrack.js +646 -0
- package/dist/unstable/DragTrack.js.map +1 -0
- package/dist/unstable/DragTransition.d.ts +22 -0
- package/dist/unstable/DragTransition.d.ts.map +1 -0
- package/dist/unstable/DragTransition.js +31 -0
- package/dist/unstable/DragTransition.js.map +1 -0
- package/dist/unstable/ElementSetup.d.ts +144 -0
- package/dist/unstable/ElementSetup.d.ts.map +1 -0
- package/dist/unstable/ElementSetup.js +297 -0
- package/dist/unstable/ElementSetup.js.map +1 -0
- package/dist/unstable/Feature.d.ts +221 -0
- package/dist/unstable/Feature.d.ts.map +1 -0
- package/dist/unstable/Feature.js +281 -0
- package/dist/unstable/Feature.js.map +1 -0
- package/dist/unstable/GestureFeatures.d.ts +30 -0
- package/dist/unstable/GestureFeatures.d.ts.map +1 -0
- package/dist/unstable/GestureFeatures.js +32 -0
- package/dist/unstable/GestureFeatures.js.map +1 -0
- package/dist/unstable/GestureInfo.d.ts +61 -0
- package/dist/unstable/GestureInfo.d.ts.map +1 -0
- package/dist/unstable/GestureInfo.js +23 -0
- package/dist/unstable/GestureInfo.js.map +1 -0
- package/dist/unstable/Imperative.d.ts +214 -0
- package/dist/unstable/Imperative.d.ts.map +1 -0
- package/dist/unstable/Imperative.js +768 -0
- package/dist/unstable/Imperative.js.map +1 -0
- package/dist/unstable/Instant.d.ts +46 -0
- package/dist/unstable/Instant.d.ts.map +1 -0
- package/dist/unstable/Instant.js +49 -0
- package/dist/unstable/Instant.js.map +1 -0
- package/dist/unstable/LayoutGroup.d.ts +14 -0
- package/dist/unstable/LayoutGroup.d.ts.map +1 -0
- package/dist/unstable/LayoutGroup.js +31 -0
- package/dist/unstable/LayoutGroup.js.map +1 -0
- package/dist/unstable/LayoutMember.d.ts +127 -0
- package/dist/unstable/LayoutMember.d.ts.map +1 -0
- package/dist/unstable/LayoutMember.js +176 -0
- package/dist/unstable/LayoutMember.js.map +1 -0
- package/dist/unstable/LiveStyle.d.ts +171 -0
- package/dist/unstable/LiveStyle.d.ts.map +1 -0
- package/dist/unstable/LiveStyle.js +329 -0
- package/dist/unstable/LiveStyle.js.map +1 -0
- package/dist/unstable/MemberHold.d.ts +3 -0
- package/dist/unstable/MemberHold.d.ts.map +1 -0
- package/dist/unstable/MemberHold.js +223 -0
- package/dist/unstable/MemberHold.js.map +1 -0
- package/dist/unstable/OwnerScope.d.ts +16 -0
- package/dist/unstable/OwnerScope.d.ts.map +1 -0
- package/dist/unstable/OwnerScope.js +35 -0
- package/dist/unstable/OwnerScope.js.map +1 -0
- package/dist/unstable/PresenceController.d.ts +128 -0
- package/dist/unstable/PresenceController.d.ts.map +1 -0
- package/dist/unstable/PresenceController.js +1427 -0
- package/dist/unstable/PresenceController.js.map +1 -0
- package/dist/unstable/Press.d.ts +26 -0
- package/dist/unstable/Press.d.ts.map +1 -0
- package/dist/unstable/Press.js +19 -0
- package/dist/unstable/Press.js.map +1 -0
- package/dist/unstable/ServerInterpolators.d.ts +17 -0
- package/dist/unstable/ServerInterpolators.d.ts.map +1 -0
- package/dist/unstable/ServerInterpolators.js +20 -0
- package/dist/unstable/ServerInterpolators.js.map +1 -0
- package/dist/unstable/WardConfig.d.ts +567 -0
- package/dist/unstable/WardConfig.d.ts.map +1 -0
- package/dist/unstable/WardConfig.js +2 -0
- package/dist/unstable/WardConfig.js.map +1 -0
- package/dist/unstable/features/All.d.ts +24 -0
- package/dist/unstable/features/All.d.ts.map +1 -0
- package/dist/unstable/features/All.js +20 -0
- package/dist/unstable/features/All.js.map +1 -0
- package/dist/unstable/features/Colors.d.ts +12 -0
- package/dist/unstable/features/Colors.d.ts.map +1 -0
- package/dist/unstable/features/Colors.js +38 -0
- package/dist/unstable/features/Colors.js.map +1 -0
- package/dist/unstable/features/DomAnimation.d.ts +16 -0
- package/dist/unstable/features/DomAnimation.d.ts.map +1 -0
- package/dist/unstable/features/DomAnimation.js +19 -0
- package/dist/unstable/features/DomAnimation.js.map +1 -0
- package/dist/unstable/features/DomMax.d.ts +12 -0
- package/dist/unstable/features/DomMax.d.ts.map +1 -0
- package/dist/unstable/features/DomMax.js +14 -0
- package/dist/unstable/features/DomMax.js.map +1 -0
- package/dist/unstable/features/Drag.d.ts +5 -0
- package/dist/unstable/features/Drag.d.ts.map +1 -0
- package/dist/unstable/features/Drag.js +32 -0
- package/dist/unstable/features/Drag.js.map +1 -0
- package/dist/unstable/features/Focus.d.ts +5 -0
- package/dist/unstable/features/Focus.d.ts.map +1 -0
- package/dist/unstable/features/Focus.js +20 -0
- package/dist/unstable/features/Focus.js.map +1 -0
- package/dist/unstable/features/Hover.d.ts +5 -0
- package/dist/unstable/features/Hover.d.ts.map +1 -0
- package/dist/unstable/features/Hover.js +20 -0
- package/dist/unstable/features/Hover.js.map +1 -0
- package/dist/unstable/features/InView.d.ts +5 -0
- package/dist/unstable/features/InView.d.ts.map +1 -0
- package/dist/unstable/features/InView.js +20 -0
- package/dist/unstable/features/InView.js.map +1 -0
- package/dist/unstable/features/Input.d.ts +28 -0
- package/dist/unstable/features/Input.d.ts.map +1 -0
- package/dist/unstable/features/Input.js +31 -0
- package/dist/unstable/features/Input.js.map +1 -0
- package/dist/unstable/features/Keys.d.ts +95 -0
- package/dist/unstable/features/Keys.d.ts.map +1 -0
- package/dist/unstable/features/Keys.js +44 -0
- package/dist/unstable/features/Keys.js.map +1 -0
- package/dist/unstable/features/Layout.d.ts +43 -0
- package/dist/unstable/features/Layout.d.ts.map +1 -0
- package/dist/unstable/features/Layout.js +44 -0
- package/dist/unstable/features/Layout.js.map +1 -0
- package/dist/unstable/features/Pan.d.ts +5 -0
- package/dist/unstable/features/Pan.d.ts.map +1 -0
- package/dist/unstable/features/Pan.js +20 -0
- package/dist/unstable/features/Pan.js.map +1 -0
- package/dist/unstable/features/Press.d.ts +13 -0
- package/dist/unstable/features/Press.d.ts.map +1 -0
- package/dist/unstable/features/Press.js +10 -0
- package/dist/unstable/features/Press.js.map +1 -0
- package/dist/unstable/features/Scroll.d.ts +20 -0
- package/dist/unstable/features/Scroll.d.ts.map +1 -0
- package/dist/unstable/features/Scroll.js +34 -0
- package/dist/unstable/features/Scroll.js.map +1 -0
- package/dist/unstable/features/TimelineKeys.d.ts +7 -0
- package/dist/unstable/features/TimelineKeys.d.ts.map +1 -0
- package/dist/unstable/features/TimelineKeys.js +103 -0
- package/dist/unstable/features/TimelineKeys.js.map +1 -0
- package/package.json +4 -3
- package/src/Appear.ts +4 -2
- package/src/DomProjectionSystem.ts +3 -3
- package/src/FlushGate.ts +15 -12
- package/src/ReorderController.ts +3 -3
- package/src/Report.ts +3 -7
- package/src/Style.ts +4 -1
- package/src/TimelineValue.ts +19 -0
- package/src/index.ts +15 -5
- package/src/internal/appear.ts +20 -8
- package/src/internal/batch-handoff.ts +75 -0
- package/src/internal/drag-defaults.ts +4 -4
- package/src/internal/gate-environment.ts +21 -0
- package/src/internal/projection.ts +22 -21
- package/src/internal/renderer.ts +22 -0
- package/src/internal/reorder.ts +4 -4
- package/src/internal/scroll.ts +32 -15
- package/src/internal/starting-style.ts +5 -204
- package/src/internal/timeline.ts +480 -0
- package/src/unstable/AppearAnimations.ts +837 -0
- package/src/unstable/BatchMembers.ts +3085 -0
- package/src/unstable/DomValues.ts +53 -0
- package/src/unstable/DragConstraints.ts +107 -0
- package/src/unstable/DragControls.ts +98 -0
- package/src/unstable/DragDefaults.ts +57 -0
- package/src/unstable/DragTrack.ts +959 -0
- package/src/unstable/DragTransition.ts +46 -0
- package/src/unstable/ElementSetup.ts +411 -0
- package/src/unstable/Feature.ts +494 -0
- package/src/unstable/GestureFeatures.ts +38 -0
- package/src/unstable/GestureInfo.ts +85 -0
- package/src/unstable/Imperative.ts +1037 -0
- package/src/unstable/Instant.ts +93 -0
- package/src/unstable/LayoutGroup.ts +36 -0
- package/src/unstable/LayoutMember.ts +319 -0
- package/src/unstable/LiveStyle.ts +497 -0
- package/src/unstable/MemberHold.ts +211 -0
- package/src/unstable/OwnerScope.ts +35 -0
- package/src/unstable/PresenceController.ts +1747 -0
- package/src/unstable/Press.ts +43 -0
- package/src/unstable/ServerInterpolators.ts +39 -0
- package/src/unstable/WardConfig.ts +704 -0
- package/src/unstable/features/All.ts +39 -0
- package/src/unstable/features/Colors.ts +40 -0
- package/src/unstable/features/DomAnimation.ts +19 -0
- package/src/unstable/features/DomMax.ts +14 -0
- package/src/unstable/features/Drag.ts +34 -0
- package/src/unstable/features/Focus.ts +21 -0
- package/src/unstable/features/Hover.ts +21 -0
- package/src/unstable/features/InView.ts +21 -0
- package/src/unstable/features/Input.ts +37 -0
- package/src/unstable/features/Keys.ts +124 -0
- package/src/unstable/features/Layout.ts +75 -0
- package/src/unstable/features/Pan.ts +21 -0
- package/src/unstable/features/Press.ts +21 -0
- package/src/unstable/features/Scroll.ts +35 -0
- package/src/unstable/features/TimelineKeys.ts +115 -0
- package/dist/internal/gate.d.ts +0 -188
- package/dist/internal/gate.d.ts.map +0 -1
- package/dist/internal/gate.js +0 -458
- package/dist/internal/gate.js.map +0 -1
- package/dist/internal/report.d.ts +0 -30
- package/dist/internal/report.d.ts.map +0 -1
- package/dist/internal/report.js +0 -60
- package/dist/internal/report.js.map +0 -1
- package/dist/internal/runner.d.ts +0 -21
- package/dist/internal/runner.d.ts.map +0 -1
- package/dist/internal/runner.js +0 -48
- package/dist/internal/runner.js.map +0 -1
- package/src/internal/gate.ts +0 -598
- package/src/internal/report.ts +0 -69
- package/src/internal/runner.ts +0 -64
|
@@ -0,0 +1,2490 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createBatch`'s work (#665), for every DOM binding: one core Batch for a collection of elements, its
|
|
3
|
+
* members entered as their elements arrive, and each change of their targets one Retarget of them all.
|
|
4
|
+
* Each binding's `createBatch` builds on it, tracking its config's `animate` with its own framework.
|
|
5
|
+
*
|
|
6
|
+
* - **Its keys** are the ones its members' first targets and starts give: fixed when it's made, as a
|
|
7
|
+
* Batch's are (ADR-0069, decision 10). A key a later `animate` gives is an error naming it.
|
|
8
|
+
* - **A member** is an element given to its handle's `ref`. It starts from `initial`, else at each
|
|
9
|
+
* key's identity, as an element does with no style of its own; with `initial: false`, at its target.
|
|
10
|
+
* An element its framework makes again for the same member carries on where the last one was.
|
|
11
|
+
* - **A change** turns every member toward its targets in one Retarget: a member whose targets are
|
|
12
|
+
* unchanged gets nothing, and `delay: stagger()` counts the members it moves (ADR-0069, *Amendment
|
|
13
|
+
* (#665)*).
|
|
14
|
+
* - **Its transitions** are a Wardic element's, read as each change starts: the config's, else the
|
|
15
|
+
* nearest `WardicConfig`'s; each key's own entry and its `delay`; the Environment's Default
|
|
16
|
+
* transition for a key without one; reduced motion's Snap for a positional key; `skipAnimations`.
|
|
17
|
+
*
|
|
18
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
// Unstable: ADR-0071, decision 5. #672: solid's `batch.ts`, moved to dom for every DOM binding's
|
|
23
|
+
// `createBatch` and `animate`; `BatchMembers`, as core has `Batch`.
|
|
24
|
+
// ADR-0070 decisions 10–15 and *Amendment (#665)*. The DOM's writer, imported here so an app that never
|
|
25
|
+
// makes a Batch ships none of it (ADR-0070, *Amendment (#665)*).
|
|
26
|
+
import * as Batch from "@wardic/core/Batch";
|
|
27
|
+
import * as BaseValue from "@wardic/core/BaseValue";
|
|
28
|
+
import * as Playback from "@wardic/core/Playback";
|
|
29
|
+
import * as ReducedMotion from "@wardic/core/ReducedMotion";
|
|
30
|
+
import * as Appear from "../Appear.js";
|
|
31
|
+
import * as DomBatch from "../DomBatch.js";
|
|
32
|
+
import * as DomDefaultTransition from "../DomDefaultTransition.js";
|
|
33
|
+
import * as DomPositionalKeys from "../DomPositionalKeys.js";
|
|
34
|
+
import * as KeyboardPress from "../KeyboardPress.js";
|
|
35
|
+
import * as Report from "../Report.js";
|
|
36
|
+
import * as Svg from "../Svg.js";
|
|
37
|
+
import * as Arr from "effect/Array";
|
|
38
|
+
import * as Bool from "effect/Boolean";
|
|
39
|
+
import * as Cause from "effect/Cause";
|
|
40
|
+
import { identity } from "effect/Function";
|
|
41
|
+
import * as Iter from "effect/Iterable";
|
|
42
|
+
import * as Option from "effect/Option";
|
|
43
|
+
import * as Predicate from "effect/Predicate";
|
|
44
|
+
import * as Rec from "effect/Record";
|
|
45
|
+
import * as Result from "effect/Result";
|
|
46
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
47
|
+
import * as AppearAnimations from "./AppearAnimations.js";
|
|
48
|
+
import * as PresenceRecord from "@wardic/core/unstable/PresenceRecord";
|
|
49
|
+
import * as RetargetLegs from "@wardic/core/unstable/RetargetLegs";
|
|
50
|
+
import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue";
|
|
51
|
+
/** Whether a Batch's config is the keyed form's. */
|
|
52
|
+
export const isKeyed = (config) => Predicate.hasProperty(config, "each");
|
|
53
|
+
/** The group `key` is drawn in on the DOM: a transform key's `transform`, `opacity`'s own, or none. */
|
|
54
|
+
export const batchGroupOf = (key) => {
|
|
55
|
+
if (key === "opacity")
|
|
56
|
+
return "opacity";
|
|
57
|
+
if (Predicate.isNotUndefined(BaseValue.TRANSFORM_IDENTITY[key]))
|
|
58
|
+
return "transform";
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
61
|
+
/** Each Batch and member handle's entry, so `animate` knows them. */
|
|
62
|
+
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
63
|
+
const SUBJECTS = new WeakMap();
|
|
64
|
+
/** Each member's element's entry, while it's the member's, so `animate` of the element moves the member (Q14). */
|
|
65
|
+
// Module state (#460, Q7): held weakly by the element. Keyed by Subject (#672): the spine's hold, core's,
|
|
66
|
+
// looks its element up as the Subject it holds.
|
|
67
|
+
const MEMBER_ELEMENTS = new WeakMap();
|
|
68
|
+
/** `handle` is `binding`'s Batch, for `animate`. */
|
|
69
|
+
export const registerBatch = (handle, binding) => {
|
|
70
|
+
SUBJECTS.set(handle, { binding, member: undefined });
|
|
71
|
+
};
|
|
72
|
+
/** The binding `subject` is a Batch or member handle of, for `animate`; `undefined` for anything else. */
|
|
73
|
+
export const batchSubjectOf = (subject) => {
|
|
74
|
+
if (!Predicate.isObject(subject))
|
|
75
|
+
return undefined;
|
|
76
|
+
return SUBJECTS.get(subject);
|
|
77
|
+
};
|
|
78
|
+
/** Whether `value` is a Batch's key's first stop through an element: a number, or `null` for where it is. */
|
|
79
|
+
const isFirstStop = /*#__PURE__*/ Predicate.or(Predicate.isNumber, Predicate.isNull);
|
|
80
|
+
/** Whether `value` is a Batch's key's two stops through an element: a first stop, and a number. */
|
|
81
|
+
const isElementStops = (value) => {
|
|
82
|
+
if (!isPair(value))
|
|
83
|
+
return false;
|
|
84
|
+
if (!Predicate.isNumber(value[1]))
|
|
85
|
+
return false;
|
|
86
|
+
return isFirstStop(value[0]);
|
|
87
|
+
};
|
|
88
|
+
/** A Batch's key's stops given through an element (Q34): a number, or two stops, a first `null` where it is. */
|
|
89
|
+
const elementStopsOf = (key, value) => {
|
|
90
|
+
if (Predicate.isNumber(value))
|
|
91
|
+
return value;
|
|
92
|
+
if (!isElementStops(value)) {
|
|
93
|
+
return fail(`an animate call gives a member's element "${key}" as ${JSON.stringify(value)}: the Batch draws "${key}", which takes a number, or two stops, its first and its target`);
|
|
94
|
+
}
|
|
95
|
+
if (Predicate.isNull(value[0]))
|
|
96
|
+
return value[1];
|
|
97
|
+
return value;
|
|
98
|
+
};
|
|
99
|
+
/** What a transform the Batch draws without it says (Q33): its whole `transform` is the Batch's. */
|
|
100
|
+
const drawnKey = (key) => {
|
|
101
|
+
if (key === "transform") {
|
|
102
|
+
return fail(`an animate call gives a member's element "transform": the Batch draws its whole transform from its keys, so give them as keys (x, scale, rotate…) of the Batch`);
|
|
103
|
+
}
|
|
104
|
+
return fail(`an animate call gives a member's element "${key}", a transform the Batch draws without it: make the Batch with "${key}" among its keys, in its \`animate\` or \`initial\``);
|
|
105
|
+
};
|
|
106
|
+
/** `target` split by `routeOf` for a Batch's members' elements; the rest is what a plain element's call would take. */
|
|
107
|
+
const splitFor = (routeOf, target) => {
|
|
108
|
+
const fields = target;
|
|
109
|
+
const batch = {};
|
|
110
|
+
const rest = {};
|
|
111
|
+
let hasRest = false;
|
|
112
|
+
Arr.forEach(Rec.keys(fields), (key) => {
|
|
113
|
+
const route = routeOf(key);
|
|
114
|
+
if (route === "drawn")
|
|
115
|
+
return drawnKey(key);
|
|
116
|
+
if (route === "batch") {
|
|
117
|
+
batch[key] = elementStopsOf(key, fields[key]);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
rest[key] = fields[key];
|
|
121
|
+
hasRest = true;
|
|
122
|
+
});
|
|
123
|
+
return { batch: batch, rest: Bool.match(hasRest, { onTrue: () => rest, onFalse: () => undefined }) };
|
|
124
|
+
};
|
|
125
|
+
/** Whether `element` is a Batch member's element: one WeakMap read, so a call without one keeps the plain path. */
|
|
126
|
+
export const isMemberElement = (element) => MEMBER_ELEMENTS.has(element);
|
|
127
|
+
/** `element`'s member's entry, while it's a Batch member's element: its subject in a sequence (Q40). */
|
|
128
|
+
export const memberEntryOf = (element) => MEMBER_ELEMENTS.get(element);
|
|
129
|
+
/** Whether a sequence's subject is a Batch member's entry. */
|
|
130
|
+
export const isMemberEntry = /*#__PURE__*/ Predicate.and(/*#__PURE__*/ Predicate.hasProperty("binding"), /*#__PURE__*/ Predicate.hasProperty("member"));
|
|
131
|
+
/** `animation` with only the keys `keep` keeps; `undefined` when it keeps none. */
|
|
132
|
+
const keysKept = (animation, keep) => {
|
|
133
|
+
const keyframes = Rec.filter(animation.keyframes, (_, key) => keep(key));
|
|
134
|
+
if (Rec.isEmptyRecord(keyframes))
|
|
135
|
+
return undefined;
|
|
136
|
+
return { keyframes, transition: Rec.filter(animation.transition, (_, key) => keep(key)) };
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* A compiled sequence's parts (Q40): each Batch's members as one part, in the order they first appear,
|
|
140
|
+
* their Batch keys its; each member's other keys as its element's; every other subject as it is.
|
|
141
|
+
*/
|
|
142
|
+
export const sequencePartsOf = (compiled) => {
|
|
143
|
+
const byBinding = new Map();
|
|
144
|
+
const others = [];
|
|
145
|
+
Arr.forEach(compiled, ([subject, animation]) => {
|
|
146
|
+
if (!isMemberEntry(subject)) {
|
|
147
|
+
others.push([subject, animation]);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const { binding, member } = subject;
|
|
151
|
+
let part = byBinding.get(binding);
|
|
152
|
+
if (Predicate.isUndefined(part)) {
|
|
153
|
+
part = { members: [], animations: [] };
|
|
154
|
+
byBinding.set(binding, part);
|
|
155
|
+
}
|
|
156
|
+
part.members.push(member);
|
|
157
|
+
part.animations.push(animation);
|
|
158
|
+
// Its keys the Batch doesn't have, its element's: a member element's Segment gave them.
|
|
159
|
+
const rest = keysKept(animation, (key) => binding.routeOf(key) !== "batch");
|
|
160
|
+
const element = binding.elementOf(member);
|
|
161
|
+
if (Bool.and(Predicate.isNotUndefined(rest), Predicate.isNotUndefined(element)))
|
|
162
|
+
others.push([element, rest]);
|
|
163
|
+
});
|
|
164
|
+
return { batches: Arr.map(Arr.fromIterable(byBinding), ([binding, part]) => ({ binding, ...part })), others };
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* An element call's parts (#665, Q14, Q35): each Batch's member elements as one part, in list order,
|
|
168
|
+
* with the Batch's keys; each element, a member's with the keys left, as one of its own.
|
|
169
|
+
*/
|
|
170
|
+
export const callPartsOf = (elements, target) => {
|
|
171
|
+
const byBinding = new Map();
|
|
172
|
+
const parts = [];
|
|
173
|
+
Arr.forEach(elements, (element, index) => {
|
|
174
|
+
const entry = MEMBER_ELEMENTS.get(element);
|
|
175
|
+
if (Predicate.isUndefined(entry)) {
|
|
176
|
+
parts.push({ element, index, target });
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
let part = byBinding.get(entry.binding);
|
|
180
|
+
if (Predicate.isUndefined(part)) {
|
|
181
|
+
part = { members: [], split: splitFor(entry.binding.routeOf, target) };
|
|
182
|
+
byBinding.set(entry.binding, part);
|
|
183
|
+
}
|
|
184
|
+
part.members.push(entry.member);
|
|
185
|
+
// Its other keys by its place in the list, as a plain element's (Motion's `delay(i, n)`).
|
|
186
|
+
const rest = part.split.rest;
|
|
187
|
+
if (Predicate.isNotUndefined(rest))
|
|
188
|
+
parts.push({ element, index, target: rest });
|
|
189
|
+
});
|
|
190
|
+
const members = Arr.filter(Arr.map(Arr.fromIterable(byBinding), ([binding, part]) => ({ binding, members: part.members, target: part.split.batch })), (part) => !Rec.isEmptyRecord(part.target));
|
|
191
|
+
return { members, elements: parts };
|
|
192
|
+
};
|
|
193
|
+
/** What an error about a Batch says. */
|
|
194
|
+
export const fail = (message) => {
|
|
195
|
+
throw new Error(`createBatch: ${message}`);
|
|
196
|
+
};
|
|
197
|
+
/** Whether `i` is one of `count` members' indices. */
|
|
198
|
+
const isMember = (i, count) => Number.isInteger(i) && i >= 0 && i < count;
|
|
199
|
+
const noMember = (i, count) => fail(`it has no member ${i}: its count is ${count}`);
|
|
200
|
+
/** Each key's identity: a transform's, and `opacity`'s 1, an element's own with no style of its own. */
|
|
201
|
+
// Per member per key at mount (#540): statements.
|
|
202
|
+
export const identityOf = (key) => {
|
|
203
|
+
const identity = BaseValue.TRANSFORM_IDENTITY[key];
|
|
204
|
+
if (Predicate.isUndefined(identity))
|
|
205
|
+
return 1;
|
|
206
|
+
return identity;
|
|
207
|
+
};
|
|
208
|
+
/** An `initial` as values, a function's called by `call`, or `undefined` for none (`false` included). */
|
|
209
|
+
const startGiven = (initial, call) => {
|
|
210
|
+
if (Predicate.isUndefined(initial) || initial === false)
|
|
211
|
+
return undefined;
|
|
212
|
+
if (Predicate.isFunction(initial))
|
|
213
|
+
return call(initial);
|
|
214
|
+
return initial;
|
|
215
|
+
};
|
|
216
|
+
/** `initial` for member `i`, as values, or `undefined` for none. */
|
|
217
|
+
const initialOf = (config, i) => startGiven(config.initial, (made) => made(i));
|
|
218
|
+
/** The keys `count` members give, in the order they first appear: what their first targets and starts name. */
|
|
219
|
+
const keysFrom = (count, targetsAt, startAt) => {
|
|
220
|
+
const seen = new Set();
|
|
221
|
+
// Per member at the Batch's making, once (#665): a loop over its targets' keys and its start's.
|
|
222
|
+
for (let i = 0; i < count; i++) {
|
|
223
|
+
for (const key in targetsAt(i))
|
|
224
|
+
seen.add(key);
|
|
225
|
+
const start = startAt(i);
|
|
226
|
+
if (Predicate.isNotUndefined(start))
|
|
227
|
+
for (const key in start)
|
|
228
|
+
seen.add(key);
|
|
229
|
+
}
|
|
230
|
+
return Arr.fromIterable(seen);
|
|
231
|
+
};
|
|
232
|
+
/** The keys a Batch's members give by index. */
|
|
233
|
+
const keysOf = (config) => keysFrom(config.count, (i) => config.animate(i), (i) => initialOf(config, i));
|
|
234
|
+
/** One change that lands every key at once: `skipAnimations`'. */
|
|
235
|
+
const INSTANT = { type: "tween", duration: 0 };
|
|
236
|
+
/** A key's index, -1 for a key the Batch hasn't. Built once. */
|
|
237
|
+
const keyIndexOr = /*#__PURE__*/ UndefinedOr.match({ onUndefined: () => -1, onDefined: (k) => k });
|
|
238
|
+
/** A Batch Reorder group's item in hand's change (#712): its `x` and `y` where it's held, at once. */
|
|
239
|
+
const IN_HAND = { transition: { x: INSTANT, y: INSTANT } };
|
|
240
|
+
/** A sequence's run that lands a key at once after `delay`: `skipAnimations`', and reduced motion's Snap of a positional key. */
|
|
241
|
+
// Module state (#460, Q7): a cache built once, keyed by what it caches.
|
|
242
|
+
const LANDINGS = new Map();
|
|
243
|
+
const landingAfter = (delay) => {
|
|
244
|
+
const known = LANDINGS.get(delay);
|
|
245
|
+
if (Predicate.isNotUndefined(known))
|
|
246
|
+
return known;
|
|
247
|
+
const made = { duration: 0, delay };
|
|
248
|
+
LANDINGS.set(delay, made);
|
|
249
|
+
return made;
|
|
250
|
+
};
|
|
251
|
+
/** A Batch key's stop in a sequence, as core's Batch takes it: a number, `NaN` for `null`. */
|
|
252
|
+
const stopNumber = (stop) => {
|
|
253
|
+
if (Predicate.isNumber(stop))
|
|
254
|
+
return stop;
|
|
255
|
+
return Number.NaN;
|
|
256
|
+
};
|
|
257
|
+
/** A key's last stop that's a number, `NaN` (where it is) for none: what its `null`s after it hold. */
|
|
258
|
+
const lastNumber = (stops) => Option.getOrElse(Arr.findLast(stops, (stop) => !Number.isNaN(stop)), () => Number.NaN);
|
|
259
|
+
/** Whether `value` is a Batch key's value in a sequence: a number, `null`, or stops of them. */
|
|
260
|
+
const isSegmentStops = (value) => {
|
|
261
|
+
if (isFirstStop(value))
|
|
262
|
+
return true;
|
|
263
|
+
if (!Arr.isArray(value))
|
|
264
|
+
return false;
|
|
265
|
+
return Arr.every(value, isFirstStop);
|
|
266
|
+
};
|
|
267
|
+
/** 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. */
|
|
268
|
+
const segmentValueOf = (key, value, memberName) => {
|
|
269
|
+
if (isSegmentStops(value))
|
|
270
|
+
return value;
|
|
271
|
+
const whose = UndefinedOr.match(memberName, { onUndefined: () => "", onDefined: (name) => `${name}'s ` });
|
|
272
|
+
return fail(`a sequence gives ${whose}"${key}" as ${JSON.stringify(value)}: a Batch's key takes a number, \`null\`, or stops of them`);
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* An `exit`, `whileHover` or `whileTap` given as an object, values with an optional `transition` (Q48,
|
|
276
|
+
* Q58), else `undefined`: a function's values are read as each is needed.
|
|
277
|
+
*/
|
|
278
|
+
export const objectFormOf = (given) => {
|
|
279
|
+
if (Predicate.isFunction(given))
|
|
280
|
+
return undefined;
|
|
281
|
+
return given;
|
|
282
|
+
};
|
|
283
|
+
/** Such an object's values, less its `transition`; none for a function, or for none given. */
|
|
284
|
+
export const objectFormValues = (given) => UndefinedOr.match(objectFormOf(given), {
|
|
285
|
+
onUndefined: () => NO_VALUES,
|
|
286
|
+
onDefined: ({ transition: _transition, ...values }) => values,
|
|
287
|
+
});
|
|
288
|
+
/** A member by index as an error names it. */
|
|
289
|
+
const indexName = (i) => `member ${i}`;
|
|
290
|
+
/** A keyed member as an error names it, by its key. */
|
|
291
|
+
const keyName = (key) => `member ${JSON.stringify(key)}`;
|
|
292
|
+
/**
|
|
293
|
+
* Member `i`'s `values` written as its targets on `keys` into `into` at `base`, `NaN` for a key they
|
|
294
|
+
* leave out: each one of `keys`, and a number, else an error naming it (`nameOf`). The client's at each
|
|
295
|
+
* change, and the server's for a member's start (#665's PR 6).
|
|
296
|
+
*/
|
|
297
|
+
// Per member per key at a change (#665): statements, its name made only for an error.
|
|
298
|
+
const targetsOn = (into, base, keys, keyIndex, values, nameOf, i) => {
|
|
299
|
+
for (let k = 0; k < keys.length; k++)
|
|
300
|
+
into[base + k] = Number.NaN;
|
|
301
|
+
for (const key in values) {
|
|
302
|
+
const k = keyIndex.get(key);
|
|
303
|
+
if (Predicate.isUndefined(k))
|
|
304
|
+
return fail(`${nameOf(i)}'s targets give "${key}", which isn't one of its keys (${keys.join(", ")}): a Batch's keys are fixed when it's made`);
|
|
305
|
+
const value = values[key];
|
|
306
|
+
if (Predicate.isNumber(value)) {
|
|
307
|
+
into[base + k] = value;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (Predicate.isNotUndefined(value))
|
|
311
|
+
fail(`${nameOf(i)}'s "${key}" is ${JSON.stringify(value)}: a Batch's targets are numbers, one each`);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Member `i`'s start on `keys` (Q63): `given`'s value for each key it gives, else its target in `targets`
|
|
316
|
+
* at `base` when it starts at its targets, else the key's identity; a key it gives that isn't one of
|
|
317
|
+
* `keys`, or a value that isn't a number, is an error naming it (`nameOf`). The client's as a member
|
|
318
|
+
* enters, and the server's.
|
|
319
|
+
*/
|
|
320
|
+
// Per member at mount (#540): statements, its name made only for an error.
|
|
321
|
+
const startOn = (keys, keyIndex, given, targets, base, atTargets, nameOf, i) => {
|
|
322
|
+
const start = {};
|
|
323
|
+
if (Predicate.isNotUndefined(given)) {
|
|
324
|
+
for (const key in given) {
|
|
325
|
+
if (!keyIndex.has(key))
|
|
326
|
+
fail(`${nameOf(i)} starts at "${key}", which isn't one of its keys (${keys.join(", ")}): a Batch's keys are fixed when it's made`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
Arr.forEach(keys, (key, k) => {
|
|
330
|
+
const target = targets[base + k];
|
|
331
|
+
let value = identityOf(key);
|
|
332
|
+
if (atTargets && !Number.isNaN(target))
|
|
333
|
+
value = target;
|
|
334
|
+
if (Predicate.isNotUndefined(given)) {
|
|
335
|
+
const own = given[key];
|
|
336
|
+
if (Predicate.isNumber(own))
|
|
337
|
+
value = own;
|
|
338
|
+
if (Predicate.isNotUndefined(own) && !Predicate.isNumber(own))
|
|
339
|
+
fail(`${nameOf(i)}'s "${key}" starts at ${JSON.stringify(own)}: a Batch's values are numbers`);
|
|
340
|
+
}
|
|
341
|
+
start[key] = value;
|
|
342
|
+
});
|
|
343
|
+
return start;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* A Batch's keys: `given`, with those its `exit`, `whileHover` and `whileTap` objects give as values after
|
|
347
|
+
* them (Q48, Q58), and a Batch Reorder group's `whileDrag` (#712), and its function gestures' by
|
|
348
|
+
* `firstGestures`, their values for the list's first item (Q27, Q34); with `keys` given (`fixed`), one
|
|
349
|
+
* outside them is an error naming it.
|
|
350
|
+
*/
|
|
351
|
+
const withConfigKeys = (given, fixed, config, firstGestures = NO_VALUES) => {
|
|
352
|
+
let all = given;
|
|
353
|
+
const more = [
|
|
354
|
+
["exit", objectFormValues(config.exit)],
|
|
355
|
+
["whileHover", objectFormValues(config.whileHover)],
|
|
356
|
+
["whileTap", objectFormValues(config.whileTap)],
|
|
357
|
+
["whileDrag", objectFormValues(config.whileDrag)],
|
|
358
|
+
["function whileHover, whileTap or whileDrag", firstGestures],
|
|
359
|
+
];
|
|
360
|
+
Arr.forEach(more, ([name, values]) => {
|
|
361
|
+
const added = Arr.filter(Rec.keys(values), (key) => !Arr.contains(all, key));
|
|
362
|
+
if (added.length === 0)
|
|
363
|
+
return;
|
|
364
|
+
if (fixed)
|
|
365
|
+
fail(`its \`${name}\` gives "${added[0]}", which isn't one of its \`keys\` (${given.join(", ")})`);
|
|
366
|
+
all = [...all, ...added];
|
|
367
|
+
});
|
|
368
|
+
return all;
|
|
369
|
+
};
|
|
370
|
+
/** The properties a Batch on `keys` draws on its members' elements: `transform`, with a transform key, and `opacity`, with it. */
|
|
371
|
+
const drawnBy = (keys) => new Set([...Arr.filter(["transform"], () => Arr.some(keys, (key) => key !== "opacity")), ...Arr.filter(["opacity"], () => Arr.contains(keys, "opacity"))]);
|
|
372
|
+
/** A member's own `style`, without the properties the Batch draws (`drawn`): a string's an error, its binding writing it over them. */
|
|
373
|
+
const ownStyleOf = (style, drawn) => {
|
|
374
|
+
if (Predicate.isString(style)) {
|
|
375
|
+
return fail(`give a member's own \`style\` as an object: a string is written over what the Batch draws`);
|
|
376
|
+
}
|
|
377
|
+
if (!Predicate.isObject(style))
|
|
378
|
+
return style;
|
|
379
|
+
return Rec.filter(style, (_, name) => !drawn.has(name));
|
|
380
|
+
};
|
|
381
|
+
/** Two items with one key: an error naming both. */
|
|
382
|
+
const twoWithKey = (first, second, key) => fail(`items ${first} and ${second} both have the key ${JSON.stringify(key)}: each item's key is its own`);
|
|
383
|
+
/** A member's slot before its element arrives. */
|
|
384
|
+
const NO_SLOT = -1;
|
|
385
|
+
/** A key a writer draws nothing for: a group a Wardic element holds (#665's PR 4). */
|
|
386
|
+
const UNDRAWN = "~undrawn";
|
|
387
|
+
/** Each group's bit in a held element's mask: the groups a Wardic element on it holds, which its Batch doesn't draw. */
|
|
388
|
+
const GROUP_BITS = { transform: 1, opacity: 2 };
|
|
389
|
+
/** An element as an error names it: its tag, then its `id` and first class, as `div#card.tile`. */
|
|
390
|
+
export const elementName = (el) => {
|
|
391
|
+
let name = el.tagName.toLowerCase();
|
|
392
|
+
if (el.id !== "")
|
|
393
|
+
name = `${name}#${el.id}`;
|
|
394
|
+
const first = el.classList.item(0);
|
|
395
|
+
if (Predicate.isNotNull(first))
|
|
396
|
+
name = `${name}.${first}`;
|
|
397
|
+
return name;
|
|
398
|
+
};
|
|
399
|
+
/** The elements a Wardic element has a layout node on: a Batch member's can have none (Q52). */
|
|
400
|
+
// Module state (#460, Q7): held weakly by the element, so it goes with it.
|
|
401
|
+
const LAYOUT_ELEMENTS = new WeakSet();
|
|
402
|
+
/**
|
|
403
|
+
* `element` given a layout node (#665's PR 4, Q52): an error when it's a Batch member's, whose
|
|
404
|
+
* transform its Batch draws, under which the projection would measure it.
|
|
405
|
+
*/
|
|
406
|
+
export const markLayoutElement = (element) => {
|
|
407
|
+
if (MEMBER_ELEMENTS.has(element))
|
|
408
|
+
return fail(layoutOnMember(element));
|
|
409
|
+
LAYOUT_ELEMENTS.add(element);
|
|
410
|
+
};
|
|
411
|
+
/** The error for a layout node on a Batch member's element. */
|
|
412
|
+
const layoutOnMember = (element) => `a member's element (${elementName(element)}) has \`layout\` or \`layoutId\`: the Batch draws its transform, under which the projection measures it. Give its Wardic element no layout, or leave it out of the Batch`;
|
|
413
|
+
/** No values: an exit with none, which moves nothing and lets its element go at once. */
|
|
414
|
+
const NO_VALUES = {};
|
|
415
|
+
/** Whether `value` is two stops. */
|
|
416
|
+
const isPair = (value) => {
|
|
417
|
+
if (!Arr.isArray(value))
|
|
418
|
+
return false;
|
|
419
|
+
return value.length === 2;
|
|
420
|
+
};
|
|
421
|
+
/** Reduced motion's Snap after `delay`: a 0 s tween, kept by its delay so its keys share one. */
|
|
422
|
+
// Module state (#460, Q7): a cache built once, keyed by what it caches.
|
|
423
|
+
const SNAPS = new Map();
|
|
424
|
+
const snapAfter = (delay) => {
|
|
425
|
+
const known = SNAPS.get(delay);
|
|
426
|
+
if (Predicate.isNotUndefined(known))
|
|
427
|
+
return known;
|
|
428
|
+
const made = { type: "tween", duration: 0, delay };
|
|
429
|
+
SNAPS.set(delay, made);
|
|
430
|
+
return made;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* A Default transition held by a key's own `delay`, as a Wardic element's is when its transition gives
|
|
434
|
+
* only a delay (ADR-0051): one object for each transition and delay, so the members on it share it.
|
|
435
|
+
*/
|
|
436
|
+
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
437
|
+
const DELAYED = new WeakMap();
|
|
438
|
+
const delayedBy = (transition, delay) => {
|
|
439
|
+
if (delay === 0)
|
|
440
|
+
return transition;
|
|
441
|
+
let byDelay = DELAYED.get(transition);
|
|
442
|
+
if (Predicate.isUndefined(byDelay)) {
|
|
443
|
+
byDelay = new Map();
|
|
444
|
+
DELAYED.set(transition, byDelay);
|
|
445
|
+
}
|
|
446
|
+
const known = byDelay.get(delay);
|
|
447
|
+
if (Predicate.isNotUndefined(known))
|
|
448
|
+
return known;
|
|
449
|
+
const made = { ...transition, delay };
|
|
450
|
+
byDelay.set(delay, made);
|
|
451
|
+
return made;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* A transition without a `stagger()` delay, which a change gives each member by its place: one object
|
|
455
|
+
* each. A `delay` in seconds stays, held by the keys the transition's own fields reach, as a Wardic
|
|
456
|
+
* element's top-level delay is.
|
|
457
|
+
*/
|
|
458
|
+
// Module state (#460, Q7): a cache held weakly by the object it's for, so it goes with it.
|
|
459
|
+
const UNSTAGGERED = new WeakMap();
|
|
460
|
+
const unstaggered = (given) => {
|
|
461
|
+
if (!Predicate.isFunction(given.delay))
|
|
462
|
+
return given;
|
|
463
|
+
const known = UNSTAGGERED.get(given);
|
|
464
|
+
if (Predicate.isNotUndefined(known))
|
|
465
|
+
return known;
|
|
466
|
+
const made = { ...given, delay: undefined };
|
|
467
|
+
UNSTAGGERED.set(given, made);
|
|
468
|
+
return made;
|
|
469
|
+
};
|
|
470
|
+
/** A change's `stagger()` delay, for the members it moves; `undefined` for none. */
|
|
471
|
+
const staggerOf = (given) => {
|
|
472
|
+
if (Predicate.isUndefined(given))
|
|
473
|
+
return undefined;
|
|
474
|
+
const delay = given.delay;
|
|
475
|
+
if (Predicate.isFunction(delay))
|
|
476
|
+
return delay;
|
|
477
|
+
return undefined;
|
|
478
|
+
};
|
|
479
|
+
/** A key's transition as a Batch runs it: its run, which can't be an inertia or repeat. */
|
|
480
|
+
const batchRunOf = (run, key) => {
|
|
481
|
+
if (run.type === "inertia")
|
|
482
|
+
fail(`"${key}" has an inertia transition, which a Batch can't run: give it a spring or a tween`);
|
|
483
|
+
if (Predicate.hasProperty(run, "repeat"))
|
|
484
|
+
fail(`"${key}"'s transition repeats, which a Batch can't run`);
|
|
485
|
+
return run;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Each key's plan for a change, by its index, as a Wardic element's keys run (#301): its entry, else
|
|
489
|
+
* `default`, else the transition's own fields; reduced motion's Snap for a positional key that doesn't
|
|
490
|
+
* opt out; its Default transition, held by its own `delay`, for a key whose transition isn't defined.
|
|
491
|
+
*/
|
|
492
|
+
// Once a change, per key.
|
|
493
|
+
const plannedOf = (positional, keys, given, reduced) => Arr.map(keys, (key) => {
|
|
494
|
+
const transition = RetargetLegs.transitionForKey(given, key);
|
|
495
|
+
let delay = 0;
|
|
496
|
+
let respects = true;
|
|
497
|
+
if (Predicate.isNotUndefined(transition)) {
|
|
498
|
+
if (Predicate.isNumber(transition.delay))
|
|
499
|
+
delay = transition.delay;
|
|
500
|
+
respects = transition.respectReducedMotion !== false;
|
|
501
|
+
}
|
|
502
|
+
if (reduced && respects && positional.isPositional(key))
|
|
503
|
+
return { own: snapAfter(delay), delay };
|
|
504
|
+
const run = RetargetLegs.runOf(transition);
|
|
505
|
+
if (Predicate.isUndefined(run))
|
|
506
|
+
return { own: undefined, delay };
|
|
507
|
+
return { own: batchRunOf(run, key), delay };
|
|
508
|
+
});
|
|
509
|
+
/**
|
|
510
|
+
* A member's transitions on `keys` for a change planned as `planned`: each key's own, else its Default
|
|
511
|
+
* transition (`defaultFor`) toward its target there, `targetAt(k)`; every key at once when it's skipped.
|
|
512
|
+
* A server's Appear plan's (#706) and a client's check of it.
|
|
513
|
+
*/
|
|
514
|
+
// Per member per key, at a server's render and at a hydrating client's first change (#706): statements.
|
|
515
|
+
const memberTransitionsOf = (keys, planned, defaultFor, targetAt, skipped) => Arr.map(keys, (key, k) => {
|
|
516
|
+
if (skipped)
|
|
517
|
+
return INSTANT;
|
|
518
|
+
const plan = planned[k];
|
|
519
|
+
if (Predicate.isNotUndefined(plan.own))
|
|
520
|
+
return plan.own;
|
|
521
|
+
return delayedBy(defaultFor(key, targetAt(k)), plan.delay);
|
|
522
|
+
});
|
|
523
|
+
/** The Handoff's module, once it has loaded (#706, Q11): every Batch after the first takes its members over at once. */
|
|
524
|
+
// Module state (#460, Q7): one module, loaded once for the page.
|
|
525
|
+
let handoffModule = undefined;
|
|
526
|
+
// Module state (#460, Q7): its load, settled once, never rejected: a failed load reported, and nothing taken over.
|
|
527
|
+
let loadingHandoff = undefined;
|
|
528
|
+
/** The Handoff's module's load, started at its first need; a failure reported on `runtime`. */
|
|
529
|
+
const loadHandoff = (runtime) => {
|
|
530
|
+
if (Predicate.isUndefined(loadingHandoff)) {
|
|
531
|
+
loadingHandoff = import("../internal/batch-handoff.js").then((module) => {
|
|
532
|
+
handoffModule = module;
|
|
533
|
+
return module;
|
|
534
|
+
}, (error) => {
|
|
535
|
+
// Let a later Batch try again.
|
|
536
|
+
loadingHandoff = undefined;
|
|
537
|
+
runtime.runFork(Report.failure("wardic: a Batch's Handoff code failed to load; its members' Appear animations are let go", Cause.die(error)));
|
|
538
|
+
return undefined;
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
return loadingHandoff;
|
|
542
|
+
};
|
|
543
|
+
// --- A server render's start (#665's PR 6, ADR-0070 decision 14, Q63–Q67) ----------------------------
|
|
544
|
+
/** A keyed member's `initial` for its item and index: values, a function's, or `undefined` for none or `false`. */
|
|
545
|
+
const keyedInitialOf = (config, item, i) => startGiven(config.initial, (given) => given(item, i));
|
|
546
|
+
/**
|
|
547
|
+
* A spread member's handle on a server: no `ref` to run, and its `start` drawn as the DOM writer draws it,
|
|
548
|
+
* over its own `style` less the properties the Batch draws (`drawn`). The client draws the same values as
|
|
549
|
+
* the member arrives, so its element doesn't move at hydration. Its element's own `style` is the handle's:
|
|
550
|
+
* a `style` beside the spread is replaced by the one it carries, as Solid's spread lets the later win.
|
|
551
|
+
*/
|
|
552
|
+
const serverMemberOf = (start, drawn, props, appear = NO_MEMBER_APPEAR) => {
|
|
553
|
+
const own = ownStyleOf(UndefinedOr.map(props, (given) => given.style), drawn);
|
|
554
|
+
const started = UndefinedOr.match(start, { onUndefined: () => NO_STYLE, onDefined: DomBatch.styleOf });
|
|
555
|
+
/** The member's handle, its own style under what the Batch writes. */
|
|
556
|
+
const writing = (written) => {
|
|
557
|
+
if (Bool.and(Predicate.isUndefined(own), Rec.isEmptyRecord(written)))
|
|
558
|
+
return { ref: noop };
|
|
559
|
+
return { ref: noop, style: { ...own, ...written } };
|
|
560
|
+
};
|
|
561
|
+
// Its Appear animation (#706) over its start, unless its own style sets an `animation`, which it keeps
|
|
562
|
+
// (Q4): then its group's rule isn't asked for on its account.
|
|
563
|
+
if (AppearAnimations.setsAnimation(own)) {
|
|
564
|
+
appear.vetoed();
|
|
565
|
+
return writing(started);
|
|
566
|
+
}
|
|
567
|
+
return writing(UndefinedOr.match(appear.style(), { onUndefined: () => started, onDefined: (style) => ({ ...started, ...style }) }));
|
|
568
|
+
};
|
|
569
|
+
/** No Appear animation. */
|
|
570
|
+
const NO_MEMBER_APPEAR = { style: () => undefined, vetoed: () => { } };
|
|
571
|
+
/** No style of the Batch's to write. */
|
|
572
|
+
const NO_STYLE = {};
|
|
573
|
+
/** Its keys checked as the client's `Batch.make` checks them: a key the DOM's writer doesn't draw is its error. */
|
|
574
|
+
const checkedOnServer = (keys) => {
|
|
575
|
+
Batch.make({ keys, writer: DomBatch.writer, transition: { type: "spring" }, capacity: 1 });
|
|
576
|
+
};
|
|
577
|
+
/** `keys` as a server Batch reads them, checked as the client's are. */
|
|
578
|
+
const serverKeysOf = (keys) => {
|
|
579
|
+
checkedOnServer(keys);
|
|
580
|
+
return { keys, keyIndex: new Map(Arr.map(keys, (key, k) => [key, k])), drawn: drawnBy(keys), targets: new Float64Array(keys.length) };
|
|
581
|
+
};
|
|
582
|
+
/** A server Batch's read of its provider's Appear animations and its nearest `WardicConfig` (#706): each binding's hooks give them. */
|
|
583
|
+
export const batchServerAppearOf = (state, config, skipped) => ({
|
|
584
|
+
state,
|
|
585
|
+
setting: WardicConfigValue.settingOf(config),
|
|
586
|
+
skipped,
|
|
587
|
+
configTransition: configTransitionOf(config)(),
|
|
588
|
+
});
|
|
589
|
+
/** No Appear animations: a server render's Batch that's given none. */
|
|
590
|
+
export const NO_SERVER_APPEAR = { state: undefined, setting: undefined, skipped: false, configTransition: undefined };
|
|
591
|
+
/** The DOM's Positional keys, which a server's reduced rule snaps, as an element's (ADR-0029). */
|
|
592
|
+
const SERVER_POSITIONAL = { isPositional: DomPositionalKeys.isPositional };
|
|
593
|
+
/** The DOM's Default transition, which a server samples a key with no transition defined on, as the client runs it (ADR-0051). */
|
|
594
|
+
const serverDefaultFor = (key, target) => DomDefaultTransition.transitionFor(key, target);
|
|
595
|
+
/** `startAt`, as a change's options take it: none without one. */
|
|
596
|
+
const startAtOption = (startAt) => UndefinedOr.match(startAt, { onUndefined: () => ({}), onDefined: (given) => ({ startAt: given }) });
|
|
597
|
+
/** A target, or `start` for a key the targets leave out (`NaN`): a key a change keeps where it is. */
|
|
598
|
+
// Per member per key at a server's render: statements.
|
|
599
|
+
const targetOr = (target, start) => {
|
|
600
|
+
if (Number.isNaN(target))
|
|
601
|
+
return start;
|
|
602
|
+
return target;
|
|
603
|
+
};
|
|
604
|
+
/** A member's values on a server, from its start and its targets as `targetsOn` wrote them into `targets`. */
|
|
605
|
+
const serverMemberValuesOf = (keys, start, targets) => {
|
|
606
|
+
const from = Arr.map(keys, (key) => start[key]);
|
|
607
|
+
return { start, from, to: Arr.map(from, (value, k) => targetOr(targets[k], value)) };
|
|
608
|
+
};
|
|
609
|
+
/** Whether a member moves: some key's start isn't its target. */
|
|
610
|
+
const movesFrom = (member) => Arr.some(member.from, (value, k) => value !== member.to[k]);
|
|
611
|
+
/** Each key's transition, by its name. */
|
|
612
|
+
const byKey = (keys, transitions) => Rec.fromEntries(Arr.map(keys, (key, k) => [key, transitions[k]]));
|
|
613
|
+
/**
|
|
614
|
+
* `batchKeyOf` remembered by its transitions' identities, for one Batch's members at a server's render: a
|
|
615
|
+
* set of transitions' canonical text written once.
|
|
616
|
+
*/
|
|
617
|
+
const ruleKeyMemo = (keys) => {
|
|
618
|
+
const ids = new WeakMap();
|
|
619
|
+
let next = 0;
|
|
620
|
+
const known = new Map();
|
|
621
|
+
/** A transition's number among those seen. */
|
|
622
|
+
const idOf = (transition) => {
|
|
623
|
+
const seen = ids.get(transition);
|
|
624
|
+
if (Predicate.isNotUndefined(seen))
|
|
625
|
+
return seen;
|
|
626
|
+
const made = next;
|
|
627
|
+
next++;
|
|
628
|
+
ids.set(transition, made);
|
|
629
|
+
return made;
|
|
630
|
+
};
|
|
631
|
+
// Per member at a server's render: its transitions' numbers, its key written the first time they come.
|
|
632
|
+
return (transitions, reduced, skipped) => {
|
|
633
|
+
const signature = `${Arr.map(transitions, idOf).join(",")}|${reduced}|${skipped}`;
|
|
634
|
+
const seen = known.get(signature);
|
|
635
|
+
if (Predicate.isNotUndefined(seen))
|
|
636
|
+
return seen;
|
|
637
|
+
const made = AppearAnimations.batchKeyOf(keys, transitions, reduced, skipped);
|
|
638
|
+
known.set(signature, made);
|
|
639
|
+
return made;
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
/** No Appear animation for any member. */
|
|
643
|
+
const NO_STYLES = { styleAt: () => undefined, plays: () => false };
|
|
644
|
+
/**
|
|
645
|
+
* A server Batch's members' Appear styles (#706, Q1–Q6, Q21: with its `appear: true`), by member: its own values, its group's slot and
|
|
646
|
+
* its delay, or `undefined` for one that plays none. Its members on one set of transitions share a rule,
|
|
647
|
+
* planned as the client plans its first change, by its setting: `"never"` the normal one, `"always"` the
|
|
648
|
+
* reduced one, `"user"` both, the reduced under the media query; skipped, every key at once (#468). A
|
|
649
|
+
* group's rules go to the render's sheet as its first member asks, so a Batch none of whose members renders
|
|
650
|
+
* one writes none. Each member's delay is its stagger by its rank among the members that move, as the
|
|
651
|
+
* client counts them. Why it plays none is said when the provider explains (#585).
|
|
652
|
+
*/
|
|
653
|
+
// Once a Batch at a server's render, a loop over its members (#665's per-member site): with it, 1,000
|
|
654
|
+
// members rendered in 5.5 ms, against 1.15 ms without (4.3 µs a member; #706, measured in Node).
|
|
655
|
+
const serverAppearStylesOf = (server, state, config, keys, members) => {
|
|
656
|
+
const name = `a Batch (${keys.join(", ")})`;
|
|
657
|
+
const moving = Arr.map(members, movesFrom);
|
|
658
|
+
const movers = Arr.reduce(moving, 0, (count, moves) => count + Number(moves));
|
|
659
|
+
if (movers === 0) {
|
|
660
|
+
state.waits(name, "no member moves from its start");
|
|
661
|
+
return NO_STYLES;
|
|
662
|
+
}
|
|
663
|
+
let configured = config.transition;
|
|
664
|
+
if (Predicate.isUndefined(configured))
|
|
665
|
+
configured = server.configTransition;
|
|
666
|
+
const skipped = Bool.or(server.skipped, UndefinedOr.map(configured, (given) => given.skipAnimations) === true);
|
|
667
|
+
let setting = server.setting;
|
|
668
|
+
if (Predicate.isUndefined(setting))
|
|
669
|
+
setting = state.reducedMotion;
|
|
670
|
+
const plain = UndefinedOr.map(configured, unstaggered);
|
|
671
|
+
const normal = plannedOf(SERVER_POSITIONAL, keys, plain, false);
|
|
672
|
+
const reduced = plannedOf(SERVER_POSITIONAL, keys, plain, true);
|
|
673
|
+
// The play each member's rule draws, and under `"user"` the reduced one beside it.
|
|
674
|
+
const reducedAlways = Bool.and(setting === "always", Bool.not(skipped));
|
|
675
|
+
let play = normal;
|
|
676
|
+
if (reducedAlways)
|
|
677
|
+
play = reduced;
|
|
678
|
+
const reducedBeside = Bool.and(setting === "user", Bool.not(skipped));
|
|
679
|
+
let stagger = staggerOf(configured);
|
|
680
|
+
if (skipped)
|
|
681
|
+
stagger = undefined;
|
|
682
|
+
// Each member's key by its transitions' identities: members on the same transitions share the objects
|
|
683
|
+
// (`delayedBy`'s, the Default transitions'), so their canonical text is written once, not once a member.
|
|
684
|
+
const ruleKeyOf = ruleKeyMemo(keys);
|
|
685
|
+
const groups = new Map();
|
|
686
|
+
const groupOf = [];
|
|
687
|
+
const indexInGroup = [];
|
|
688
|
+
const delays = [];
|
|
689
|
+
let rank = 0;
|
|
690
|
+
for (let i = 0; i < members.length; i++) {
|
|
691
|
+
if (!moving[i])
|
|
692
|
+
continue;
|
|
693
|
+
const member = members[i];
|
|
694
|
+
const transitions = memberTransitionsOf(keys, play, serverDefaultFor, (k) => member.to[k], skipped);
|
|
695
|
+
const key = ruleKeyOf(transitions, reducedAlways, skipped);
|
|
696
|
+
if (Option.isNone(key)) {
|
|
697
|
+
state.waits(name, "its transition holds a function with no easing name");
|
|
698
|
+
return NO_STYLES;
|
|
699
|
+
}
|
|
700
|
+
let group = groups.get(key.value);
|
|
701
|
+
if (Predicate.isUndefined(group)) {
|
|
702
|
+
let reducedRule = undefined;
|
|
703
|
+
if (reducedBeside) {
|
|
704
|
+
const reducedTransitions = memberTransitionsOf(keys, reduced, serverDefaultFor, (k) => member.to[k], false);
|
|
705
|
+
reducedRule = { key: Option.getOrThrow(AppearAnimations.batchKeyOf(keys, reducedTransitions, true, false)), transitions: byKey(keys, reducedTransitions) };
|
|
706
|
+
}
|
|
707
|
+
group = { key: key.value, transitions: byKey(keys, transitions), reduced: reducedRule, members: [], slot: undefined };
|
|
708
|
+
groups.set(key.value, group);
|
|
709
|
+
}
|
|
710
|
+
groupOf[i] = group;
|
|
711
|
+
indexInGroup[i] = group.members.length;
|
|
712
|
+
group.members.push(i);
|
|
713
|
+
let delay = 0;
|
|
714
|
+
if (Predicate.isNotUndefined(stagger))
|
|
715
|
+
delay = stagger(rank, movers);
|
|
716
|
+
delays[i] = delay;
|
|
717
|
+
rank++;
|
|
718
|
+
}
|
|
719
|
+
/** A group's slot: its rules sampled and registered at its first member's ask, or `None` when one can't be. */
|
|
720
|
+
const slotOf = (group) => {
|
|
721
|
+
if (Predicate.isNotUndefined(group.slot))
|
|
722
|
+
return group.slot;
|
|
723
|
+
const specOf = (key, transitions) => ({
|
|
724
|
+
key,
|
|
725
|
+
keys,
|
|
726
|
+
transition: transitions,
|
|
727
|
+
starts: Arr.map(group.members, (i) => members[i].from),
|
|
728
|
+
targets: Arr.map(group.members, (i) => members[i].to),
|
|
729
|
+
});
|
|
730
|
+
const rule = Appear.batchKeyframes(specOf(group.key, group.transitions));
|
|
731
|
+
const reducedRule = UndefinedOr.map(group.reduced, (r) => Appear.batchKeyframes(specOf(r.key, r.transitions)));
|
|
732
|
+
const failure = Option.orElse(Result.getFailure(rule), () => Option.flatMap(Option.fromUndefinedOr(reducedRule), Result.getFailure));
|
|
733
|
+
if (Option.isSome(failure)) {
|
|
734
|
+
state.waits(name, failure.value);
|
|
735
|
+
group.slot = Option.none();
|
|
736
|
+
return group.slot;
|
|
737
|
+
}
|
|
738
|
+
group.slot = Option.some(state.batch(Result.getOrThrow(rule), UndefinedOr.map(reducedRule, Result.getOrThrow)));
|
|
739
|
+
return group.slot;
|
|
740
|
+
};
|
|
741
|
+
return {
|
|
742
|
+
styleAt: (i) => {
|
|
743
|
+
const group = groupOf[i];
|
|
744
|
+
if (Predicate.isUndefined(group))
|
|
745
|
+
return undefined;
|
|
746
|
+
return Option.getOrUndefined(Option.flatMap(slotOf(group), (slot) => Option.fromUndefinedOr(slot.styleOf(indexInGroup[i], delays[i]))));
|
|
747
|
+
},
|
|
748
|
+
plays: (i) => Predicate.isNotUndefined(groupOf[i]),
|
|
749
|
+
};
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* Each member's Appear animation on a server, by its index: its style, made once, and, when its own style
|
|
753
|
+
* vetoes it, the provider's explanation, once a member (Solid's spread calls a handle once for each prop it
|
|
754
|
+
* reads).
|
|
755
|
+
*/
|
|
756
|
+
const memberAppearsOf = (state, styles, nameOf) => {
|
|
757
|
+
const said = new Set();
|
|
758
|
+
// Each member's style, made once: Solid's spread calls its handle once for each prop it reads.
|
|
759
|
+
const made = new Map();
|
|
760
|
+
const styleOnce = (i) => {
|
|
761
|
+
if (made.has(i))
|
|
762
|
+
return made.get(i);
|
|
763
|
+
const style = styles.styleAt(i);
|
|
764
|
+
made.set(i, style);
|
|
765
|
+
return style;
|
|
766
|
+
};
|
|
767
|
+
return (i) => ({
|
|
768
|
+
style: () => styleOnce(i),
|
|
769
|
+
vetoed: () => {
|
|
770
|
+
if (Bool.or(Bool.not(styles.plays(i)), said.has(i)))
|
|
771
|
+
return;
|
|
772
|
+
said.add(i);
|
|
773
|
+
state.waits(`a Batch's ${nameOf(i)}`, "its own style sets an animation");
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
/**
|
|
778
|
+
* A server Batch's members (#706): with its `appear: true` (Q21) and a render that writes Appear
|
|
779
|
+
* animations, every member read up front, as a rule is its group's and a delay its rank's; else each as
|
|
780
|
+
* its handle asks, and none plays one.
|
|
781
|
+
*/
|
|
782
|
+
const serverMembersOf = (server, config, keys, count, memberAt, nameOf) => {
|
|
783
|
+
const plain = { memberAt, appearOf: () => NO_MEMBER_APPEAR };
|
|
784
|
+
const state = server.state;
|
|
785
|
+
if (Predicate.isUndefined(state))
|
|
786
|
+
return plain;
|
|
787
|
+
if (config.appear !== true)
|
|
788
|
+
return plain;
|
|
789
|
+
const members = Arr.makeBy(count, memberAt);
|
|
790
|
+
return { memberAt: (i) => members[i], appearOf: memberAppearsOf(state, serverAppearStylesOf(server, state, config, keys, members), nameOf) };
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* A server render's handles by index (Q63): each member's start, its `initial`'s values, its targets
|
|
794
|
+
* with `initial: false`, else nothing, on the keys the client makes it with, its checks the client's.
|
|
795
|
+
*/
|
|
796
|
+
export const serverHandlesOf = (config, server = NO_SERVER_APPEAR) => {
|
|
797
|
+
const { keys, keyIndex, drawn, targets } = serverKeysOf(withConfigKeys(keysOf(config), false, config));
|
|
798
|
+
const memberAt = (i) => {
|
|
799
|
+
targetsOn(targets, 0, keys, keyIndex, config.animate(i), indexName, i);
|
|
800
|
+
return serverMemberValuesOf(keys, startOn(keys, keyIndex, initialOf(config, i), targets, 0, config.initial === false, indexName, i), targets);
|
|
801
|
+
};
|
|
802
|
+
const members = serverMembersOf(server, config, keys, config.count, memberAt, indexName);
|
|
803
|
+
return (i, props) => {
|
|
804
|
+
if (!isMember(i, config.count))
|
|
805
|
+
return noMember(i, config.count);
|
|
806
|
+
return serverMemberOf(members.memberAt(i).start, drawn, props, members.appearOf(i));
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* A server render's keyed handles (Q63, Q65): the list read once, each key's member started by its item
|
|
811
|
+
* and its index there, its targets under `<AnimatePresence initial={false}>`; a key the list doesn't have,
|
|
812
|
+
* nothing. Its keys and checks the client's: with `keys` given and no items, its keys as given.
|
|
813
|
+
*/
|
|
814
|
+
export const serverKeyedHandlesOf = (config, presenceOf, server = NO_SERVER_APPEAR) => {
|
|
815
|
+
const items = config.each();
|
|
816
|
+
const reader = keyReaderOf(config);
|
|
817
|
+
const keyAt = [];
|
|
818
|
+
const indexOfKey = new Map();
|
|
819
|
+
Arr.forEach(items, (item, i) => {
|
|
820
|
+
const key = reader(item, i);
|
|
821
|
+
const known = indexOfKey.get(key);
|
|
822
|
+
if (Predicate.isNotUndefined(known))
|
|
823
|
+
twoWithKey(known, i, key);
|
|
824
|
+
indexOfKey.set(key, i);
|
|
825
|
+
keyAt.push(key);
|
|
826
|
+
});
|
|
827
|
+
const nameOf = (i) => keyName(keyAt[i]);
|
|
828
|
+
const values = Arr.map(items, (item, i) => config.animate(item, i));
|
|
829
|
+
const fixed = config.keys;
|
|
830
|
+
const listed = UndefinedOr.match(fixed, { onUndefined: () => keysFrom(items.length, (i) => values[i], (i) => keyedInitialOf(config, items[i], i)), onDefined: identity });
|
|
831
|
+
// As the client's: `keys` given and no items yet makes them as they are.
|
|
832
|
+
let given = listed;
|
|
833
|
+
if (Bool.or(Predicate.isUndefined(fixed), items.length > 0))
|
|
834
|
+
given = withConfigKeys(listed, Predicate.isNotUndefined(fixed), config);
|
|
835
|
+
const { keys, keyIndex, drawn, targets } = serverKeysOf(given);
|
|
836
|
+
/** Item `i`'s values, at its targets when `quiet` or with `initial: false`. */
|
|
837
|
+
const memberAt = (i, quiet) => {
|
|
838
|
+
targetsOn(targets, 0, keys, keyIndex, values[i], nameOf, i);
|
|
839
|
+
let initial = keyedInitialOf(config, items[i], i);
|
|
840
|
+
if (quiet)
|
|
841
|
+
initial = undefined;
|
|
842
|
+
let atTargets = quiet;
|
|
843
|
+
if (config.initial === false)
|
|
844
|
+
atTargets = true;
|
|
845
|
+
return serverMemberValuesOf(keys, startOn(keys, keyIndex, initial, targets, 0, atTargets, nameOf, i), targets);
|
|
846
|
+
};
|
|
847
|
+
// Each from its `initial`: one under `<AnimatePresence initial={false}>`, which its own render tells, plays none.
|
|
848
|
+
const members = serverMembersOf(server, config, keys, items.length, (i) => memberAt(i, false), nameOf);
|
|
849
|
+
return (key, props) => {
|
|
850
|
+
const i = indexOfKey.get(key);
|
|
851
|
+
if (Predicate.isUndefined(i))
|
|
852
|
+
return serverMemberOf(undefined, drawn, props);
|
|
853
|
+
// `<AnimatePresence initial={false}>`'s first render (Q46): at its targets, whatever `initial` says.
|
|
854
|
+
if (PresenceRecord.presenceBlocksInitial(presenceOf()))
|
|
855
|
+
return serverMemberOf(memberAt(i, true).start, drawn, props);
|
|
856
|
+
return serverMemberOf(members.memberAt(i).start, drawn, props, members.appearOf(i));
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
const noop = () => { };
|
|
860
|
+
/** Member handles for `binding`: its `ref`, the element's own `ref` called beside it, and its own `style` kept. */
|
|
861
|
+
export const handlesOf = (binding) => (i, props) => {
|
|
862
|
+
const handle = memberHandleOf(binding, i, props);
|
|
863
|
+
// Known to `animate`, as member `i`'s: its entry made once, so a handle made at each render costs its
|
|
864
|
+
// WeakMap write alone (0.09 ms a 1,000 handles in Node, against 0.16 with an entry made each time; #665).
|
|
865
|
+
SUBJECTS.set(handle, binding.entryOf(i));
|
|
866
|
+
return handle;
|
|
867
|
+
};
|
|
868
|
+
const memberHandleOf = (binding, i, props) => {
|
|
869
|
+
const ref = binding.refOf(i);
|
|
870
|
+
if (Predicate.isUndefined(props))
|
|
871
|
+
return { ref };
|
|
872
|
+
const own = props.ref;
|
|
873
|
+
const both = (el) => {
|
|
874
|
+
ref(el);
|
|
875
|
+
if (Predicate.isNotUndefined(own))
|
|
876
|
+
own(el);
|
|
877
|
+
};
|
|
878
|
+
// No `style` of its own: none on the handle, so a spread keeps a `style` the element gives before it (Solid 2's merge takes an `undefined` one).
|
|
879
|
+
if (Predicate.isUndefined(props.style))
|
|
880
|
+
return { ref: both };
|
|
881
|
+
return { ref: both, style: binding.styleOf(props.style) };
|
|
882
|
+
};
|
|
883
|
+
/** The nearest `WardicConfig`'s transition, read as each change starts, from either binding's config value. */
|
|
884
|
+
export const configTransitionOf = (config) => () => {
|
|
885
|
+
if (Predicate.isUndefined(config))
|
|
886
|
+
return undefined;
|
|
887
|
+
return config.transition();
|
|
888
|
+
};
|
|
889
|
+
/** Keyed member handles for `binding`: as {@link handlesOf}'s, each key's member made at its first handle. */
|
|
890
|
+
export const keyedHandlesOf = (binding, presenceNow) => (key, props) => {
|
|
891
|
+
// The presence it's made under, read as it's made, in its item's render (Q46).
|
|
892
|
+
const member = binding.memberFor(key, presenceNow());
|
|
893
|
+
const handle = memberHandleOf(binding, member, props);
|
|
894
|
+
SUBJECTS.set(handle, binding.entryOf(member));
|
|
895
|
+
return handle;
|
|
896
|
+
};
|
|
897
|
+
/** A keyed member's index before its item is in `each`, or once it has left. */
|
|
898
|
+
const NO_INDEX = -1;
|
|
899
|
+
/** A keyed Batch's members' keys: its config's, by property or function, each checked to give one. */
|
|
900
|
+
const keyReaderOf = (config) => {
|
|
901
|
+
const given = config.key;
|
|
902
|
+
const read = Bool.match(Predicate.isFunction(given), {
|
|
903
|
+
onTrue: () => given,
|
|
904
|
+
onFalse: () => (item) => item[given],
|
|
905
|
+
});
|
|
906
|
+
// Per item at a change (#665): statements.
|
|
907
|
+
return (item, i) => {
|
|
908
|
+
const key = read(item);
|
|
909
|
+
if (Predicate.isNullish(key))
|
|
910
|
+
return fail(`item ${i}'s key is ${String(key)}: give each item a key, by \`key\``);
|
|
911
|
+
return key;
|
|
912
|
+
};
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* A Batch for `config`'s members, under `env`'s provider: its writer the DOM's. The binding tracks
|
|
916
|
+
* {@link BatchBinding.targetsOf} and hands each new value to {@link BatchBinding.apply}.
|
|
917
|
+
*
|
|
918
|
+
* - **By index,** its `count` members are fixed, member `i` its `i`th, and its core Batch is made at once.
|
|
919
|
+
* - **Keyed** (Q42–Q45), each key's member is a number, given at its key's first sight and given back when
|
|
920
|
+
* it leaves, so a long list's churn reuses them. Its core Batch is made at the first change with
|
|
921
|
+
* members, at a handle's first sight of one, or at once when its `keys` are given (Q51).
|
|
922
|
+
*/
|
|
923
|
+
export const bindBatch = (env, config, hooks) => {
|
|
924
|
+
const keyed = isKeyed(config);
|
|
925
|
+
// The keys, and the core Batch: made at once by index, at the first change with members when keyed.
|
|
926
|
+
let keys = [];
|
|
927
|
+
let stride = 0;
|
|
928
|
+
let keyIndex = new Map();
|
|
929
|
+
let batch = undefined;
|
|
930
|
+
let write = noop;
|
|
931
|
+
// The CSS properties the Batch draws, which an element's own `style` leaves to it.
|
|
932
|
+
let drawn = new Set();
|
|
933
|
+
/** The core Batch, once it's made: every caller runs after. */
|
|
934
|
+
const made = () => UndefinedOr.getOrThrow(batch);
|
|
935
|
+
// Each member's slot (`NO_SLOT` before its element arrives), its index in the list (`NO_INDEX` when it
|
|
936
|
+
// has none), and its element, entry and `ref`; each slot's member; and every member's targets, `stride` a member.
|
|
937
|
+
let capacity = 1;
|
|
938
|
+
let slotOf = new Int32Array(capacity).fill(NO_SLOT);
|
|
939
|
+
let indexOf = new Int32Array(capacity).fill(NO_INDEX);
|
|
940
|
+
const elementOf = [];
|
|
941
|
+
const entries = [];
|
|
942
|
+
const refs = [];
|
|
943
|
+
const memberOf = [];
|
|
944
|
+
let current = new Float64Array(0);
|
|
945
|
+
// Each member's gestures on (#665's PR 5), a layer each over `animate`'s targets: its values while it's
|
|
946
|
+
// on, `NaN` for a key it doesn't give; and how many layers are on, so a change with none reads `animate`'s
|
|
947
|
+
// alone. Declared before `targetOf`, which reads them per member per key at a change.
|
|
948
|
+
const hovering = [];
|
|
949
|
+
const pressing = [];
|
|
950
|
+
// A Batch Reorder group's item in hand (#712): its `whileDrag` layer over its press's, and where its
|
|
951
|
+
// `x` and `y` are held, over every layer's, while it's dragged.
|
|
952
|
+
const dragging = [];
|
|
953
|
+
const layers = { hover: hovering, press: pressing, drag: dragging };
|
|
954
|
+
const hands = [];
|
|
955
|
+
// `x`'s and `y`'s key index, once a hand's held: -1 for a Batch without them.
|
|
956
|
+
let handX = -1;
|
|
957
|
+
let handY = -1;
|
|
958
|
+
let gesturing = 0;
|
|
959
|
+
// Where each key only a gesture gives (none of `animate`'s) was as the member's first layer came on:
|
|
960
|
+
// what it returns to as its last goes (decision 12), `NaN` for the rest; kept while a layer is on.
|
|
961
|
+
const bases = [];
|
|
962
|
+
let binding = undefined;
|
|
963
|
+
/** Room for `wanted` members: every member's typed arrays grown to the next power of two times their size that holds it. */
|
|
964
|
+
// Once a growth (#665): typed arrays copied.
|
|
965
|
+
const growMembersTo = (wanted) => {
|
|
966
|
+
if (wanted <= capacity)
|
|
967
|
+
return;
|
|
968
|
+
const grown = capacity * 2 ** Math.ceil(Math.log2(wanted / capacity));
|
|
969
|
+
const slots = new Int32Array(grown).fill(NO_SLOT);
|
|
970
|
+
slots.set(slotOf);
|
|
971
|
+
slotOf = slots;
|
|
972
|
+
const indices = new Int32Array(grown).fill(NO_INDEX);
|
|
973
|
+
indices.set(indexOf);
|
|
974
|
+
indexOf = indices;
|
|
975
|
+
const listings = new Int32Array(grown);
|
|
976
|
+
listings.set(listedIn);
|
|
977
|
+
listedIn = listings;
|
|
978
|
+
const targets = new Float64Array(grown * stride).fill(Number.NaN);
|
|
979
|
+
targets.set(current);
|
|
980
|
+
current = targets;
|
|
981
|
+
capacity = grown;
|
|
982
|
+
};
|
|
983
|
+
/** Member `i`'s `values` written as its targets into `into`, `NaN` for a key they leave out; each one a number. */
|
|
984
|
+
// Per member per key at a change (#665): statements.
|
|
985
|
+
const targetsInto = (into, i, values) => targetsOn(into, i * stride, keys, keyIndex, values, form.nameOf, i);
|
|
986
|
+
const configuredOf = () => {
|
|
987
|
+
const given = config.transition;
|
|
988
|
+
if (Predicate.isNotUndefined(given))
|
|
989
|
+
return given;
|
|
990
|
+
return env.configTransition();
|
|
991
|
+
};
|
|
992
|
+
// Its gestures as given (#665's PR 5): `whileHover` and `whileTap`, an object or a function.
|
|
993
|
+
/** A key's Default transition toward `target`. */
|
|
994
|
+
const defaultFor = (k, target) => env.defaultTransition.transitionFor(keys[k], target);
|
|
995
|
+
/** The Batch's keys, fixed from now on, and room for every member's targets on them. */
|
|
996
|
+
const keysAre = (given) => {
|
|
997
|
+
keys = given;
|
|
998
|
+
stride = given.length;
|
|
999
|
+
keyIndex = new Map(Arr.map(given, (key, k) => [key, k]));
|
|
1000
|
+
current = new Float64Array(capacity * stride).fill(Number.NaN);
|
|
1001
|
+
};
|
|
1002
|
+
/**
|
|
1003
|
+
* The core Batch: its own transitions each key's as it is now, so the members a change gives them step by
|
|
1004
|
+
* one matrix while they share one (ADR-0069, *Amendment (#665)*), the Default transition toward
|
|
1005
|
+
* `firstTarget(k)`, its first member's, for a key without one.
|
|
1006
|
+
*/
|
|
1007
|
+
const makeBatch = (firstTarget) => {
|
|
1008
|
+
const ownPlan = plannedOf(env.positionalKeys, keys, UndefinedOr.map(configuredOf(), unstaggered), false);
|
|
1009
|
+
const own = {};
|
|
1010
|
+
Arr.forEach(keys, (key, k) => {
|
|
1011
|
+
const plan = ownPlan[k];
|
|
1012
|
+
if (Predicate.isNotUndefined(plan.own)) {
|
|
1013
|
+
own[key] = plan.own;
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
let target = firstTarget(k);
|
|
1017
|
+
if (Number.isNaN(target))
|
|
1018
|
+
target = identityOf(key);
|
|
1019
|
+
own[key] = delayedBy(defaultFor(k, target), plan.delay);
|
|
1020
|
+
});
|
|
1021
|
+
// The writer's write for these keys, built once: an arriving element is drawn with it at once. A member
|
|
1022
|
+
// a Wardic element holds a group of is drawn without it (#665's PR 4): one check a member while none is.
|
|
1023
|
+
write = DomBatch.writer.forKeys(keys);
|
|
1024
|
+
const without = (group) => DomBatch.writer.forKeys(Arr.map(keys, (key) => Bool.match(batchGroupOf(key) === group, { onTrue: () => UNDRAWN, onFalse: () => key })));
|
|
1025
|
+
const withoutTransform = without("transform");
|
|
1026
|
+
const withoutOpacity = without("opacity");
|
|
1027
|
+
const full = write;
|
|
1028
|
+
// Per frame, per moving member: a size check, and with a member held, a Map read. A member both of
|
|
1029
|
+
// whose groups are held is drawn by its Wardic element alone: the Batch draws nothing else.
|
|
1030
|
+
const masking = (el, positions, base) => {
|
|
1031
|
+
if (masks.size === 0)
|
|
1032
|
+
return full(el, positions, base);
|
|
1033
|
+
const mask = masks.get(el);
|
|
1034
|
+
if (Predicate.isUndefined(mask))
|
|
1035
|
+
return full(el, positions, base);
|
|
1036
|
+
if (mask === GROUP_BITS.transform)
|
|
1037
|
+
return withoutTransform(el, positions, base);
|
|
1038
|
+
if (mask === GROUP_BITS.opacity)
|
|
1039
|
+
return withoutOpacity(el, positions, base);
|
|
1040
|
+
};
|
|
1041
|
+
groupKs.transform = Arr.filter(Arr.map(keys, (_, k) => k), (k) => batchGroupOf(keys[k]) === "transform");
|
|
1042
|
+
groupKs.opacity = Arr.filter(Arr.map(keys, (_, k) => k), (k) => keys[k] === "opacity");
|
|
1043
|
+
batch = Batch.make({ keys, writer: { writes: DomBatch.writer.writes, forKeys: () => masking }, transition: own, capacity });
|
|
1044
|
+
drawn = drawnBy(keys);
|
|
1045
|
+
};
|
|
1046
|
+
// --- Keyed: a list's items by key (#665, Q42–Q45, Q51) ------------------------------------
|
|
1047
|
+
const byKey = config;
|
|
1048
|
+
const keyReader = Bool.match(keyed, { onTrue: () => keyReaderOf(byKey), onFalse: () => () => undefined });
|
|
1049
|
+
// Each member's key and item, each key's member, the members given back, how many members there have
|
|
1050
|
+
// been, and the list's members in order.
|
|
1051
|
+
const keyOf = [];
|
|
1052
|
+
const itemOf = [];
|
|
1053
|
+
const memberOfKey = new Map();
|
|
1054
|
+
const freeMembers = [];
|
|
1055
|
+
let memberCount = 0;
|
|
1056
|
+
let order = [];
|
|
1057
|
+
// Which listing (a change of the list taken in) last listed each member, to tell a key given twice and the members that left.
|
|
1058
|
+
let listedIn = new Int32Array(capacity);
|
|
1059
|
+
let listings = 0;
|
|
1060
|
+
/** Keyed: member `item`'s `initial` at `i`, as values, or `undefined` for none. */
|
|
1061
|
+
// Keyed: its `exit` as values (an object's, less its `transition`; none for a function's), and that `transition`.
|
|
1062
|
+
const exitObject = objectFormOf(byKey.exit);
|
|
1063
|
+
const exitValues = objectFormValues(byKey.exit);
|
|
1064
|
+
const exitTransition = UndefinedOr.map(exitObject, (given) => given.transition);
|
|
1065
|
+
/** Keyed: the items now, their keys and their targets, as `animate` gives them. A compute: it writes nothing shared. */
|
|
1066
|
+
const keyedTargetsOf = () => {
|
|
1067
|
+
const items = byKey.each();
|
|
1068
|
+
return {
|
|
1069
|
+
items,
|
|
1070
|
+
keys: Arr.map(items, keyReader),
|
|
1071
|
+
values: Arr.map(items, (item, i) => byKey.animate(item, i)),
|
|
1072
|
+
};
|
|
1073
|
+
};
|
|
1074
|
+
/**
|
|
1075
|
+
* Keyed: the core Batch, made on `targets`' keys and its `exit`'s, as values (else the config's `keys`,
|
|
1076
|
+
* which must hold the `exit`'s), when it has members.
|
|
1077
|
+
*/
|
|
1078
|
+
const makeFromList = (targets) => {
|
|
1079
|
+
if (targets.items.length === 0)
|
|
1080
|
+
return;
|
|
1081
|
+
keysAre(withMoreKeys(UndefinedOr.match(byKey.keys, {
|
|
1082
|
+
onUndefined: () => keysFrom(targets.items.length, (i) => targets.values[i], (i) => keyedInitialOf(byKey, targets.items[i], i)),
|
|
1083
|
+
onDefined: identity,
|
|
1084
|
+
}), firstGesturesOf(targets)));
|
|
1085
|
+
makeBatch((k) => {
|
|
1086
|
+
const value = targets.values[0][keys[k]];
|
|
1087
|
+
if (Predicate.isNumber(value))
|
|
1088
|
+
return value;
|
|
1089
|
+
return Number.NaN;
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
/**
|
|
1093
|
+
* `given` keys with those its `exit`, `whileHover` and `whileTap` give as values after them (Q48, Q58);
|
|
1094
|
+
* with `keys` given, one outside them is an error naming it.
|
|
1095
|
+
*/
|
|
1096
|
+
const withMoreKeys = (given, firstGestures = NO_VALUES) => withConfigKeys(given, Predicate.isNotUndefined(byKey.keys), config, firstGestures);
|
|
1097
|
+
/**
|
|
1098
|
+
* Keyed: a Batch Reorder group's function gestures' values for the list's first item (#712, Q27, Q34):
|
|
1099
|
+
* `whileHover`'s, `whileTap`'s and `whileDrag`'s keys join the Batch's, as `animate`'s first targets' do.
|
|
1100
|
+
* None for an object's, or for any other Batch, whose function gestures give keys it has.
|
|
1101
|
+
*/
|
|
1102
|
+
const firstGesturesOf = (targets) => {
|
|
1103
|
+
if (Bool.not(Predicate.hasProperty(config, "gestureKeysFromFirst")))
|
|
1104
|
+
return NO_VALUES;
|
|
1105
|
+
const given = config;
|
|
1106
|
+
const first = (gesture) => Bool.match(Predicate.isFunction(gesture), {
|
|
1107
|
+
onTrue: () => env.untrack(() => gesture(targets.items[0], 0)),
|
|
1108
|
+
onFalse: () => NO_VALUES,
|
|
1109
|
+
});
|
|
1110
|
+
return { ...first(given.whileHover), ...first(given.whileTap), ...first(given.whileDrag) };
|
|
1111
|
+
};
|
|
1112
|
+
/** Keyed: the member for `key`: its member, else a new one. */
|
|
1113
|
+
const memberForKey = (key) => {
|
|
1114
|
+
const known = memberOfKey.get(key);
|
|
1115
|
+
if (Predicate.isNotUndefined(known))
|
|
1116
|
+
return known;
|
|
1117
|
+
return newMember(key);
|
|
1118
|
+
};
|
|
1119
|
+
/** A keyed member for `key`, at its first sight: a member given back, else the next. */
|
|
1120
|
+
const newMember = (key) => {
|
|
1121
|
+
let member = freeMembers.pop();
|
|
1122
|
+
if (Predicate.isUndefined(member)) {
|
|
1123
|
+
member = memberCount;
|
|
1124
|
+
memberCount = memberCount + 1;
|
|
1125
|
+
growMembersTo(memberCount);
|
|
1126
|
+
}
|
|
1127
|
+
const i = member;
|
|
1128
|
+
const entry = { binding: UndefinedOr.getOrThrow(binding), member: i };
|
|
1129
|
+
entries[i] = entry;
|
|
1130
|
+
keyOf[i] = key;
|
|
1131
|
+
indexOf[i] = NO_INDEX;
|
|
1132
|
+
listedIn[i] = 0;
|
|
1133
|
+
memberOfKey.set(key, i);
|
|
1134
|
+
// Its `ref` reaches it only while it's this key's: a handle kept past its leave reaches nothing.
|
|
1135
|
+
refs[i] = (el) => {
|
|
1136
|
+
if (entries[i] === entry)
|
|
1137
|
+
arrive(i, el);
|
|
1138
|
+
};
|
|
1139
|
+
return i;
|
|
1140
|
+
};
|
|
1141
|
+
/**
|
|
1142
|
+
* Keyed: the list now, `targets`, taken in: the core Batch made at its first members, each item's member
|
|
1143
|
+
* (made at its key's first sight) given its index, item and targets, and each member that left the list
|
|
1144
|
+
* leaving the Batch at once (3a: an exit comes with `<AnimatePresence>`, in 3b).
|
|
1145
|
+
*/
|
|
1146
|
+
const takeList = (targets) => {
|
|
1147
|
+
if (Predicate.isUndefined(batch))
|
|
1148
|
+
makeFromList(targets);
|
|
1149
|
+
if (Predicate.isUndefined(batch))
|
|
1150
|
+
return;
|
|
1151
|
+
listings = listings + 1;
|
|
1152
|
+
const next = [];
|
|
1153
|
+
// Per item at a change (#665): statements.
|
|
1154
|
+
Arr.forEach(targets.items, (item, i) => {
|
|
1155
|
+
const key = targets.keys[i];
|
|
1156
|
+
const member = memberForKey(key);
|
|
1157
|
+
if (listedIn[member] === listings)
|
|
1158
|
+
return twoWithKey(indexOf[member], i, key);
|
|
1159
|
+
listedIn[member] = listings;
|
|
1160
|
+
indexOf[member] = i;
|
|
1161
|
+
itemOf[member] = item;
|
|
1162
|
+
targetsInto(current, member, targets.values[i]);
|
|
1163
|
+
next.push(member);
|
|
1164
|
+
// Back in the list mid-exit (Q26): its exit cut short, its element gone at once, uncompleted; its
|
|
1165
|
+
// next element takes its slot over, its values and speed, and this change turns it toward `animate`.
|
|
1166
|
+
if (unlisted.delete(member))
|
|
1167
|
+
cutExit(member);
|
|
1168
|
+
});
|
|
1169
|
+
Arr.forEach(order, (member) => {
|
|
1170
|
+
if (listedIn[member] !== listings)
|
|
1171
|
+
leavesList(member);
|
|
1172
|
+
});
|
|
1173
|
+
order = next;
|
|
1174
|
+
};
|
|
1175
|
+
/**
|
|
1176
|
+
* Keyed: member `i` left the list. Under `<AnimatePresence>` (its element watched), it stays in the
|
|
1177
|
+
* Batch until its exit lands; else it leaves at once.
|
|
1178
|
+
*/
|
|
1179
|
+
const leavesList = (i) => {
|
|
1180
|
+
if (Bool.or(Predicate.isNotUndefined(exits[i]), isWatched(i))) {
|
|
1181
|
+
unlisted.add(i);
|
|
1182
|
+
flushSoon();
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
leaveBatch(i);
|
|
1186
|
+
};
|
|
1187
|
+
/** Keyed: whether member `i`'s element is the one its presence watches. */
|
|
1188
|
+
const isWatched = (i) => {
|
|
1189
|
+
const watched = watchedOn[i];
|
|
1190
|
+
if (Predicate.isUndefined(watched))
|
|
1191
|
+
return false;
|
|
1192
|
+
return watched === elementOf[i];
|
|
1193
|
+
};
|
|
1194
|
+
/** Keyed: member `i`'s exit cut short, its element let go at once, uncompleted (#286's rule). */
|
|
1195
|
+
const cutExit = (i) => {
|
|
1196
|
+
const exit = exits[i];
|
|
1197
|
+
exits[i] = undefined;
|
|
1198
|
+
if (Predicate.isNotUndefined(exit))
|
|
1199
|
+
exit.release(false);
|
|
1200
|
+
};
|
|
1201
|
+
/** Keyed: member `i` leaves the Batch, at once; its number is given back. */
|
|
1202
|
+
const leaveBatch = (i) => {
|
|
1203
|
+
unlisted.delete(i);
|
|
1204
|
+
exits[i] = undefined;
|
|
1205
|
+
presenceOf[i] = undefined;
|
|
1206
|
+
watchedOn[i] = undefined;
|
|
1207
|
+
quietStart.delete(i);
|
|
1208
|
+
unhold(i);
|
|
1209
|
+
const slot = slotOf[i];
|
|
1210
|
+
if (slot !== NO_SLOT)
|
|
1211
|
+
Batch.leave(made(), slot);
|
|
1212
|
+
const el = elementOf[i];
|
|
1213
|
+
if (Predicate.isNotUndefined(el))
|
|
1214
|
+
forget(el, i);
|
|
1215
|
+
memberOfKey.delete(keyOf[i]);
|
|
1216
|
+
keyOf[i] = undefined;
|
|
1217
|
+
itemOf[i] = undefined;
|
|
1218
|
+
entries[i] = undefined;
|
|
1219
|
+
elementOf[i] = undefined;
|
|
1220
|
+
slotOf[i] = NO_SLOT;
|
|
1221
|
+
indexOf[i] = NO_INDEX;
|
|
1222
|
+
reported.delete(i);
|
|
1223
|
+
freeMembers.push(i);
|
|
1224
|
+
};
|
|
1225
|
+
// --- Keyed under `<AnimatePresence>` (#665, PR 3b, Q46–Q48) ------------------------------------
|
|
1226
|
+
// Each member's presence (the one its latest handle was made under) and the element it watches there;
|
|
1227
|
+
// the members that start at their targets (`initial={false}`, its first render); the members out of
|
|
1228
|
+
// the list it holds while they exit; each one's exit while it plays; and the exits starting this task.
|
|
1229
|
+
const presenceOf = [];
|
|
1230
|
+
const watchedOn = [];
|
|
1231
|
+
const quietStart = new Set();
|
|
1232
|
+
const unlisted = new Set();
|
|
1233
|
+
const exits = [];
|
|
1234
|
+
let starting = [];
|
|
1235
|
+
let exitsSoon = false;
|
|
1236
|
+
// Each member's element held off the page by `mode="wait"`, and the call that lets the hold go.
|
|
1237
|
+
const holds = new Map();
|
|
1238
|
+
/** Keyed: whether member `entry` is still member `i`: a member given back and taken by another key isn't. */
|
|
1239
|
+
const isCurrent = (i, entry) => entries[i] === entry;
|
|
1240
|
+
/** Keyed: member `i`'s element `el` watched by its presence, so its leave plays its exit, holding it on the page. */
|
|
1241
|
+
const watchOn = (i, el) => {
|
|
1242
|
+
const presence = presenceOf[i];
|
|
1243
|
+
if (Predicate.isUndefined(presence) || watchedOn[i] === el)
|
|
1244
|
+
return;
|
|
1245
|
+
const watch = presence.watch;
|
|
1246
|
+
if (Predicate.isUndefined(watch))
|
|
1247
|
+
return;
|
|
1248
|
+
watchedOn[i] = el;
|
|
1249
|
+
const entry = entries[i];
|
|
1250
|
+
watch({
|
|
1251
|
+
element: () => el,
|
|
1252
|
+
holds: true,
|
|
1253
|
+
leave: (custom, release) => memberLeft(i, entry, el, custom, release),
|
|
1254
|
+
gone: () => watchGone(i, entry, el),
|
|
1255
|
+
interrupted: () => exitCut(i, entry),
|
|
1256
|
+
});
|
|
1257
|
+
};
|
|
1258
|
+
/**
|
|
1259
|
+
* Keyed: whether the member entering at `slot` is held off the page by its presence's `mode="wait"`,
|
|
1260
|
+
* read at its task's end, once the presence has decided: its move starts as the presence lets it on,
|
|
1261
|
+
* as a Wardic element's does then.
|
|
1262
|
+
*/
|
|
1263
|
+
const heldBack = (slot) => {
|
|
1264
|
+
const i = memberOf[slot];
|
|
1265
|
+
const presence = presenceOf[i];
|
|
1266
|
+
const el = elementOf[i];
|
|
1267
|
+
if (Predicate.isUndefined(presence) || Predicate.isUndefined(el))
|
|
1268
|
+
return false;
|
|
1269
|
+
unhold(i);
|
|
1270
|
+
const entry = entries[i];
|
|
1271
|
+
const cancel = PresenceRecord.presenceHold(presence, el, () => {
|
|
1272
|
+
holds.delete(i);
|
|
1273
|
+
if (Bool.and(isCurrent(i, entry), slotOf[i] === slot))
|
|
1274
|
+
change([slot]);
|
|
1275
|
+
});
|
|
1276
|
+
if (Predicate.isUndefined(cancel))
|
|
1277
|
+
return false;
|
|
1278
|
+
holds.set(i, cancel);
|
|
1279
|
+
return true;
|
|
1280
|
+
};
|
|
1281
|
+
/** Keyed: member `i`'s hold let go, if it had one. */
|
|
1282
|
+
const unhold = (i) => {
|
|
1283
|
+
const cancel = holds.get(i);
|
|
1284
|
+
holds.delete(i);
|
|
1285
|
+
if (Predicate.isNotUndefined(cancel))
|
|
1286
|
+
cancel();
|
|
1287
|
+
};
|
|
1288
|
+
/** Keyed: member `i`'s element left its presence: its exit plays with this task's others', so `stagger()` counts them (Q25). */
|
|
1289
|
+
const memberLeft = (i, entry, el, custom, release) => {
|
|
1290
|
+
// Not the member's element now (made again), or never drawn: nothing to exit on it.
|
|
1291
|
+
if (!isCurrent(i, entry))
|
|
1292
|
+
return release();
|
|
1293
|
+
if (elementOf[i] !== el)
|
|
1294
|
+
return release();
|
|
1295
|
+
if (slotOf[i] === NO_SLOT)
|
|
1296
|
+
return release();
|
|
1297
|
+
exits[i] = { release, custom };
|
|
1298
|
+
starting.push(i);
|
|
1299
|
+
if (exitsSoon)
|
|
1300
|
+
return;
|
|
1301
|
+
exitsSoon = true;
|
|
1302
|
+
queueMicrotask(playExits);
|
|
1303
|
+
};
|
|
1304
|
+
/** Keyed: a leaver's exit values: its `exit` read once, a function's called with its item, last index and `custom`. */
|
|
1305
|
+
const exitValuesOf = (i, custom) => {
|
|
1306
|
+
if (Predicate.isFunction(byKey.exit))
|
|
1307
|
+
return byKey.exit(itemOf[i], indexOf[i], custom);
|
|
1308
|
+
return exitValues;
|
|
1309
|
+
};
|
|
1310
|
+
/** Keyed: this task's exits, one driven change of them all, each member let go as its own lands (Q47). */
|
|
1311
|
+
const playExits = () => {
|
|
1312
|
+
exitsSoon = false;
|
|
1313
|
+
const going = Arr.filter(starting, (i) => Bool.and(Predicate.isNotUndefined(exits[i]), slotOf[i] !== NO_SLOT));
|
|
1314
|
+
starting = [];
|
|
1315
|
+
if (going.length === 0)
|
|
1316
|
+
return;
|
|
1317
|
+
// A Batch disposed since lets its leavers go at once.
|
|
1318
|
+
if (disposed)
|
|
1319
|
+
return Arr.forEach(going, cutExit);
|
|
1320
|
+
const exitTargets = new Float64Array(capacity * stride).fill(Number.NaN);
|
|
1321
|
+
const moving = [];
|
|
1322
|
+
// Per leaver at its exit (#665): statements. An exit that fails is reported, and lets its element go.
|
|
1323
|
+
Arr.forEach(going, (i) => {
|
|
1324
|
+
try {
|
|
1325
|
+
targetsInto(exitTargets, i, exitValuesOf(i, UndefinedOr.getOrThrow(exits[i]).custom));
|
|
1326
|
+
moving.push(i);
|
|
1327
|
+
}
|
|
1328
|
+
catch (defect) {
|
|
1329
|
+
env.runtime.runFork(Report.failure("createBatch: a member's exit failed", Cause.die(defect)));
|
|
1330
|
+
cutExit(i);
|
|
1331
|
+
if (unlisted.has(i))
|
|
1332
|
+
leaveBatch(i);
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
if (moving.length === 0)
|
|
1336
|
+
return;
|
|
1337
|
+
const slots = Arr.map(moving, (i) => slotOf[i]);
|
|
1338
|
+
const exitOf = (slot, k) => exitTargets[memberOf[slot] * stride + k];
|
|
1339
|
+
// The groups Wardic elements hold of the leavers that their exits move come back first (Q54).
|
|
1340
|
+
retakeFor(slots, givesGroup((slot, k) => !Number.isNaN(exitOf(slot, k))));
|
|
1341
|
+
const configured = configuredOf();
|
|
1342
|
+
changeOn(slots, exitOf, undefined, {
|
|
1343
|
+
transition: UndefinedOr.match(exitTransition, { onUndefined: () => configured, onDefined: identity }),
|
|
1344
|
+
reducedMotion: env.reducedMotion(),
|
|
1345
|
+
skipAnimations: skipsNow(configured),
|
|
1346
|
+
head: Playback.make(),
|
|
1347
|
+
settled: noop,
|
|
1348
|
+
onMemberLanded: (slot) => exitLanded(memberOf[slot]),
|
|
1349
|
+
}).run();
|
|
1350
|
+
};
|
|
1351
|
+
/**
|
|
1352
|
+
* Keyed: member `i`'s exit landed: its element let go. Out of the list, the member leaves the Batch; in
|
|
1353
|
+
* it (its element gone with a presence child that left), its slot goes, so its next element enters anew.
|
|
1354
|
+
*/
|
|
1355
|
+
const exitLanded = (i) => {
|
|
1356
|
+
const exit = exits[i];
|
|
1357
|
+
if (Predicate.isUndefined(exit))
|
|
1358
|
+
return;
|
|
1359
|
+
exits[i] = undefined;
|
|
1360
|
+
exit.release();
|
|
1361
|
+
if (unlisted.has(i))
|
|
1362
|
+
return leaveBatch(i);
|
|
1363
|
+
dropSlot(i);
|
|
1364
|
+
};
|
|
1365
|
+
/** Keyed: member `i`, still in the list, out of the Batch's run: its next element enters from `initial`. */
|
|
1366
|
+
const dropSlot = (i) => {
|
|
1367
|
+
const slot = slotOf[i];
|
|
1368
|
+
if (slot === NO_SLOT)
|
|
1369
|
+
return;
|
|
1370
|
+
Batch.leave(made(), slot);
|
|
1371
|
+
slotOf[i] = NO_SLOT;
|
|
1372
|
+
const el = elementOf[i];
|
|
1373
|
+
if (Predicate.isNotUndefined(el))
|
|
1374
|
+
forget(el, i);
|
|
1375
|
+
elementOf[i] = undefined;
|
|
1376
|
+
watchedOn[i] = undefined;
|
|
1377
|
+
};
|
|
1378
|
+
/**
|
|
1379
|
+
* Keyed: member `i`'s exit cut short by its presence (a take-over of the child it's in, the presence
|
|
1380
|
+
* going): out of the list, it leaves the Batch; in it, it turns back toward its targets.
|
|
1381
|
+
*/
|
|
1382
|
+
const exitCut = (i, entry) => {
|
|
1383
|
+
if (!isCurrent(i, entry))
|
|
1384
|
+
return;
|
|
1385
|
+
exits[i] = undefined;
|
|
1386
|
+
if (unlisted.has(i))
|
|
1387
|
+
return leaveBatch(i);
|
|
1388
|
+
const slot = slotOf[i];
|
|
1389
|
+
if (slot !== NO_SLOT)
|
|
1390
|
+
change([slot]);
|
|
1391
|
+
};
|
|
1392
|
+
/** Keyed: member `i`'s watch dropped with no leave: its element left some other way. Out of the list, it leaves the Batch. */
|
|
1393
|
+
const watchGone = (i, entry, el) => {
|
|
1394
|
+
if (!isCurrent(i, entry))
|
|
1395
|
+
return;
|
|
1396
|
+
if (watchedOn[i] !== el)
|
|
1397
|
+
return;
|
|
1398
|
+
watchedOn[i] = undefined;
|
|
1399
|
+
if (Bool.and(unlisted.has(i), Predicate.isUndefined(exits[i])))
|
|
1400
|
+
leaveBatch(i);
|
|
1401
|
+
};
|
|
1402
|
+
/**
|
|
1403
|
+
* Keyed: the members out of the list whose presence didn't take their elements, at a task's end: one
|
|
1404
|
+
* not inside a child the presence keeps, whose element is off the page with no exit, leaves the Batch.
|
|
1405
|
+
*/
|
|
1406
|
+
const settleUnlisted = () => Iter.forEach(unlisted, (i) => {
|
|
1407
|
+
if (Predicate.isNotUndefined(exits[i]))
|
|
1408
|
+
return;
|
|
1409
|
+
const el = elementOf[i];
|
|
1410
|
+
if (Predicate.isUndefined(el))
|
|
1411
|
+
return leaveBatch(i);
|
|
1412
|
+
if (el.isConnected)
|
|
1413
|
+
return;
|
|
1414
|
+
leaveBatch(i);
|
|
1415
|
+
});
|
|
1416
|
+
// Elements whose keys the list didn't have as they arrived, and those reported for still not having them
|
|
1417
|
+
// at a task's end: each enters once a change lists its key (Q45).
|
|
1418
|
+
let waiting = [];
|
|
1419
|
+
const reported = new Set();
|
|
1420
|
+
/** Keyed: the waiting elements whose keys the list has now, entered; the rest wait on. */
|
|
1421
|
+
const enterListed = () => {
|
|
1422
|
+
if (waiting.length === 0 || Predicate.isUndefined(batch))
|
|
1423
|
+
return;
|
|
1424
|
+
const early = waiting;
|
|
1425
|
+
waiting = [];
|
|
1426
|
+
Arr.forEach(early, (i) => {
|
|
1427
|
+
// Gone since, or entered already.
|
|
1428
|
+
if (Predicate.isUndefined(entries[i]) || slotOf[i] !== NO_SLOT)
|
|
1429
|
+
return;
|
|
1430
|
+
if (indexOf[i] === NO_INDEX) {
|
|
1431
|
+
waiting.push(i);
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
reported.delete(i);
|
|
1435
|
+
enter(i, UndefinedOr.getOrThrow(elementOf[i]));
|
|
1436
|
+
});
|
|
1437
|
+
};
|
|
1438
|
+
/** Keyed: the waiting elements at a task's end, the list read again: those it has entered, each other one reported once. */
|
|
1439
|
+
// Found at a task's end, where a throw reaches nothing: reported, and the element waits on.
|
|
1440
|
+
const settleWaiting = () => {
|
|
1441
|
+
if (waiting.length === 0)
|
|
1442
|
+
return;
|
|
1443
|
+
takeList(env.untrack(keyedTargetsOf));
|
|
1444
|
+
enterListed();
|
|
1445
|
+
Arr.forEach(waiting, (i) => {
|
|
1446
|
+
if (reported.has(i))
|
|
1447
|
+
return;
|
|
1448
|
+
reported.add(i);
|
|
1449
|
+
const unlisted = new Error(`createBatch: an element was given ${form.nameOf(i)}'s handle, but no item in \`each\` has that key`);
|
|
1450
|
+
env.runtime.runFork(Report.failure("createBatch: a member's element has no item", Cause.die(unlisted)));
|
|
1451
|
+
});
|
|
1452
|
+
};
|
|
1453
|
+
const keyedForm = {
|
|
1454
|
+
size: () => order.length,
|
|
1455
|
+
nameOf: (i) => keyName(keyOf[i]),
|
|
1456
|
+
targetsOf: keyedTargetsOf,
|
|
1457
|
+
take: (targets) => {
|
|
1458
|
+
takeList(targets);
|
|
1459
|
+
enterListed();
|
|
1460
|
+
},
|
|
1461
|
+
arrivedSlots: () => Arr.filter(Arr.map(order, (i) => slotOf[i]), (slot) => slot !== NO_SLOT),
|
|
1462
|
+
inOrder: () => order,
|
|
1463
|
+
initialOf: (i) => keyedInitialOf(byKey, itemOf[i], indexOf[i]),
|
|
1464
|
+
entersNow: (i) => Bool.and(indexOf[i] !== NO_INDEX, Predicate.isNotUndefined(batch)),
|
|
1465
|
+
entered: noop,
|
|
1466
|
+
refOf: (i) => refs[i],
|
|
1467
|
+
// A member for a key no list has listed stays until a list does: its handle's element may arrive first.
|
|
1468
|
+
// On Solid 2 a spread's compute can make one Solid then throws away, so a key's member is made once.
|
|
1469
|
+
memberFor: (key, presence) => {
|
|
1470
|
+
if (Predicate.isUndefined(batch))
|
|
1471
|
+
makeFromList(env.untrack(keyedTargetsOf));
|
|
1472
|
+
const member = memberForKey(key);
|
|
1473
|
+
if (Predicate.isNotUndefined(presence)) {
|
|
1474
|
+
presenceOf[member] = presence;
|
|
1475
|
+
// Made in the presence's first render with `initial={false}`: it starts at its targets.
|
|
1476
|
+
if (Bool.and(slotOf[member] === NO_SLOT, PresenceRecord.presenceBlocksInitial(presence)))
|
|
1477
|
+
quietStart.add(member);
|
|
1478
|
+
}
|
|
1479
|
+
return member;
|
|
1480
|
+
},
|
|
1481
|
+
};
|
|
1482
|
+
// --- By index: `count` members, fixed --------------------------------------------------
|
|
1483
|
+
const byIndex = config;
|
|
1484
|
+
const count = Bool.match(keyed, { onTrue: () => 0, onFalse: () => byIndex.count });
|
|
1485
|
+
// The slots, in the order their elements arrived.
|
|
1486
|
+
const entered = [];
|
|
1487
|
+
// Every member, by index.
|
|
1488
|
+
const indices = Arr.makeBy(Math.max(1, count), identity).slice(0, count);
|
|
1489
|
+
/** By index: every member's targets now, member by member in key order. */
|
|
1490
|
+
const indexTargetsOf = () => {
|
|
1491
|
+
const targets = new Float64Array(count * stride);
|
|
1492
|
+
// Per member at a change, the Batch's own loop (ADR-0025, *Amendment (#665)*).
|
|
1493
|
+
for (let i = 0; i < count; i++)
|
|
1494
|
+
targetsInto(targets, i, byIndex.animate(i));
|
|
1495
|
+
return targets;
|
|
1496
|
+
};
|
|
1497
|
+
const indexForm = {
|
|
1498
|
+
size: () => count,
|
|
1499
|
+
nameOf: indexName,
|
|
1500
|
+
targetsOf: indexTargetsOf,
|
|
1501
|
+
take: (targets) => {
|
|
1502
|
+
current = targets;
|
|
1503
|
+
},
|
|
1504
|
+
arrivedSlots: () => entered,
|
|
1505
|
+
inOrder: () => indices,
|
|
1506
|
+
initialOf: (i) => initialOf(byIndex, i),
|
|
1507
|
+
entersNow: () => true,
|
|
1508
|
+
entered: (slot) => {
|
|
1509
|
+
entered.push(slot);
|
|
1510
|
+
},
|
|
1511
|
+
refOf: (i) => {
|
|
1512
|
+
if (!isMember(i, count))
|
|
1513
|
+
return noMember(i, count);
|
|
1514
|
+
return refs[i];
|
|
1515
|
+
},
|
|
1516
|
+
memberFor: () => fail(`a Batch by index has no \`member(key)\`: give its members \`at(i)\``),
|
|
1517
|
+
};
|
|
1518
|
+
const form = Bool.match(keyed, { onTrue: () => keyedForm, onFalse: () => indexForm });
|
|
1519
|
+
// --- Its members' moves ----------------------------------------------------------------
|
|
1520
|
+
/** Member `i`'s start: its `initial` over each key's identity, or, with `initial: false`, its targets. */
|
|
1521
|
+
// Per member at mount (#540): statements.
|
|
1522
|
+
const startOf = (i) => {
|
|
1523
|
+
// `<AnimatePresence initial={false}>`'s first render (Q46): at its targets, whatever `initial` says.
|
|
1524
|
+
const quiet = quietStart.delete(i);
|
|
1525
|
+
let given = form.initialOf(i);
|
|
1526
|
+
if (quiet)
|
|
1527
|
+
given = undefined;
|
|
1528
|
+
let atTargets = quiet;
|
|
1529
|
+
if (config.initial === false)
|
|
1530
|
+
atTargets = true;
|
|
1531
|
+
return startOn(keys, keyIndex, given, current, i * stride, atTargets, form.nameOf, i);
|
|
1532
|
+
};
|
|
1533
|
+
// The runs it forked, interrupted when it's disposed; whether a flight is on, and the members it set off.
|
|
1534
|
+
const fibers = new Set();
|
|
1535
|
+
let flying = false;
|
|
1536
|
+
let moved = 0;
|
|
1537
|
+
let disposed = false;
|
|
1538
|
+
/** A flight lands once a run ends with nothing moving: a run forked while one ran ends at once. */
|
|
1539
|
+
const ended = () => {
|
|
1540
|
+
if (disposed)
|
|
1541
|
+
return;
|
|
1542
|
+
if (!flying || Batch.isMoving(made()))
|
|
1543
|
+
return;
|
|
1544
|
+
flying = false;
|
|
1545
|
+
hooks.landed({ moved });
|
|
1546
|
+
};
|
|
1547
|
+
/** After a change: a flight's start, if it set one off, and a run, which does nothing while one runs. */
|
|
1548
|
+
const wake = (setOff) => {
|
|
1549
|
+
if (!Batch.isMoving(made()))
|
|
1550
|
+
return;
|
|
1551
|
+
if (!flying) {
|
|
1552
|
+
flying = true;
|
|
1553
|
+
moved = 0;
|
|
1554
|
+
hooks.started();
|
|
1555
|
+
}
|
|
1556
|
+
moved = moved + setOff;
|
|
1557
|
+
// Heard by an observer, not an `Effect.ensuring`: one primitive fewer at each change (#665's profile).
|
|
1558
|
+
const fiber = env.runtime.runFork(Batch.run(made()));
|
|
1559
|
+
fibers.add(fiber);
|
|
1560
|
+
fiber.addObserver(() => {
|
|
1561
|
+
fibers.delete(fiber);
|
|
1562
|
+
ended();
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
/**
|
|
1566
|
+
* Member `slot`'s target for its `k`th key: its Override stack's (ADR-0070 decision 12, #665's PR 5),
|
|
1567
|
+
* its press's over its hover's over `animate`'s; a Batch Reorder group's item in hand's `x` and `y` where
|
|
1568
|
+
* it's held, over its `whileDrag`'s, over the rest (#712).
|
|
1569
|
+
*/
|
|
1570
|
+
// Per member per key at a change: with no member's gesture on, `animate`'s read alone.
|
|
1571
|
+
const targetOf = (slot, k) => {
|
|
1572
|
+
const i = memberOf[slot];
|
|
1573
|
+
if (gesturing === 0)
|
|
1574
|
+
return current[i * stride + k];
|
|
1575
|
+
const hand = hands[i];
|
|
1576
|
+
if (Predicate.isNotUndefined(hand)) {
|
|
1577
|
+
if (k === handX)
|
|
1578
|
+
return hand[0];
|
|
1579
|
+
if (k === handY)
|
|
1580
|
+
return hand[1];
|
|
1581
|
+
}
|
|
1582
|
+
const dragged = dragging[i];
|
|
1583
|
+
if (Predicate.isNotUndefined(dragged) && !Number.isNaN(dragged[k]))
|
|
1584
|
+
return dragged[k];
|
|
1585
|
+
const pressed = pressing[i];
|
|
1586
|
+
if (Predicate.isNotUndefined(pressed) && !Number.isNaN(pressed[k]))
|
|
1587
|
+
return pressed[k];
|
|
1588
|
+
const hovered = hovering[i];
|
|
1589
|
+
if (Predicate.isNotUndefined(hovered) && !Number.isNaN(hovered[k]))
|
|
1590
|
+
return hovered[k];
|
|
1591
|
+
const target = current[i * stride + k];
|
|
1592
|
+
if (!Number.isNaN(target))
|
|
1593
|
+
return target;
|
|
1594
|
+
const base = bases[i];
|
|
1595
|
+
if (Predicate.isUndefined(base))
|
|
1596
|
+
return target;
|
|
1597
|
+
return base[k];
|
|
1598
|
+
};
|
|
1599
|
+
/**
|
|
1600
|
+
* A change's transitions: one per key, by its name, when every key has its own; else a function of
|
|
1601
|
+
* a member's slot, for the keys on their Default transition, which each member's target decides.
|
|
1602
|
+
*/
|
|
1603
|
+
// A function called per member's key cost a change at 1,000 members a call each (#665's profile).
|
|
1604
|
+
const transitionOf = (planned) => {
|
|
1605
|
+
if (Arr.every(planned, (plan) => Predicate.isNotUndefined(plan.own))) {
|
|
1606
|
+
const byName = {};
|
|
1607
|
+
Arr.forEach(keys, (key, k) => {
|
|
1608
|
+
byName[key] = UndefinedOr.getOrThrow(planned[k].own);
|
|
1609
|
+
});
|
|
1610
|
+
return byName;
|
|
1611
|
+
}
|
|
1612
|
+
return (slot, k) => {
|
|
1613
|
+
const plan = planned[k];
|
|
1614
|
+
if (Predicate.isNotUndefined(plan.own))
|
|
1615
|
+
return plan.own;
|
|
1616
|
+
return delayedBy(defaultFor(k, targetOf(slot, k)), plan.delay);
|
|
1617
|
+
};
|
|
1618
|
+
};
|
|
1619
|
+
/**
|
|
1620
|
+
* `slots` a change moves now: all of them, but those entering this task that `mode="wait"` holds off
|
|
1621
|
+
* the page, which move as they go on (Q46). With none entering, `slots` as they are.
|
|
1622
|
+
*/
|
|
1623
|
+
const movingNow = (slots) => {
|
|
1624
|
+
if (arrived.length === 0)
|
|
1625
|
+
return slots;
|
|
1626
|
+
const entering = new Set(arrived);
|
|
1627
|
+
return Arr.filter(slots, (slot) => Bool.not(Bool.and(entering.has(slot), heldBack(slot))));
|
|
1628
|
+
};
|
|
1629
|
+
/** Whether a change now lands at once: its scope's `skipAnimations`, or its transition's (#468). */
|
|
1630
|
+
const skipsNow = (configured) => {
|
|
1631
|
+
if (env.skipAnimations())
|
|
1632
|
+
return true;
|
|
1633
|
+
return UndefinedOr.map(configured, (given) => given.skipAnimations) === true;
|
|
1634
|
+
};
|
|
1635
|
+
/** The change for `slots` now: their targets, with this moment's transitions. */
|
|
1636
|
+
const change = (slots, starts) => {
|
|
1637
|
+
if (slots.length === 0)
|
|
1638
|
+
return;
|
|
1639
|
+
// The groups Wardic elements hold of these members that it moves come back first (Q54), from where they've left them.
|
|
1640
|
+
const back = UndefinedOr.match(starts, { onUndefined: () => startsOf(takeBack(slots, changesGroup)), onDefined: identity });
|
|
1641
|
+
const configured = configuredOf();
|
|
1642
|
+
turnOn(slots, configured, staggerOf(configured), back);
|
|
1643
|
+
};
|
|
1644
|
+
/**
|
|
1645
|
+
* `slots` turned toward their targets on `configured`, each held by `delay`'s for its rank when given, from
|
|
1646
|
+
* `back`'s starts. The first change after members arrive running their Appear animation, whichever it is
|
|
1647
|
+
* (the arrival's, or a Batch Reorder group's own first), starts each where that has got to (#706).
|
|
1648
|
+
*/
|
|
1649
|
+
const turnOn = (slots, configured, delay, back) => {
|
|
1650
|
+
// Its Appear animations' Handoff (#706): at the page's first, after its code has loaded (Q11), its
|
|
1651
|
+
// members drawn by their CSS meanwhile.
|
|
1652
|
+
const startsHandoff = appearing.size > 0 && Predicate.isUndefined(handoffAt);
|
|
1653
|
+
if (startsHandoff && Predicate.isUndefined(handoffModule))
|
|
1654
|
+
return afterHandoffLoads(() => turnOn(slots, configured, delay, back));
|
|
1655
|
+
const skipped = skipsNow(configured);
|
|
1656
|
+
const reduced = env.reducedMotion();
|
|
1657
|
+
const planned = plannedOf(env.positionalKeys, keys, UndefinedOr.map(configured, unstaggered), reduced);
|
|
1658
|
+
// The first change after members arrive running their Appear animation starts each where that has got
|
|
1659
|
+
// to; every change before its first step starts them the same way, a member arriving then among them.
|
|
1660
|
+
if (startsHandoff)
|
|
1661
|
+
handoffAt = handoffStartAt((slot) => memberRuleKeyOf(slot, planned, reduced, skipped));
|
|
1662
|
+
const startAt = handoffAt;
|
|
1663
|
+
// Skipped, every key at once and no stagger; else this moment's transitions, each member held by its rank's delay.
|
|
1664
|
+
const options = Bool.match(skipped, {
|
|
1665
|
+
onTrue: () => ({ transition: INSTANT, ...back, ...startAtOption(startAt) }),
|
|
1666
|
+
onFalse: () => ({ transition: transitionOf(planned), ...UndefinedOr.match(delay, { onUndefined: () => ({}), onDefined: (given) => ({ delay: given }) }), ...back, ...startAtOption(startAt) }),
|
|
1667
|
+
});
|
|
1668
|
+
wake(Batch.retarget(made(), slots, targetOf, options));
|
|
1669
|
+
// A change that took none of them over: no step reads them, so each is let go now.
|
|
1670
|
+
if (Predicate.isNotUndefined(startAt) && !Batch.isMoving(made()))
|
|
1671
|
+
releaseAppearing();
|
|
1672
|
+
};
|
|
1673
|
+
// --- The Handoff (#706, ADR-0044 *Amendment (#706)*, Q3, Q8, Q9) --------------------------------------
|
|
1674
|
+
// A hydrating Batch's members whose elements run their Appear animation, by slot, as they arrive: what its
|
|
1675
|
+
// arrival change takes over. Read only while it hydrates, and asked for one (Q21; a string read a
|
|
1676
|
+
// member): a client-only Batch never looks, and a member's element running a Wardic element's own Appear
|
|
1677
|
+
// animation, where its Batch didn't ask, stays that element's.
|
|
1678
|
+
let looksForAppear = false;
|
|
1679
|
+
if (env.hydrating === true)
|
|
1680
|
+
looksForAppear = config.appear === true;
|
|
1681
|
+
const appearing = new Set();
|
|
1682
|
+
// The Handoff's `startAt`, while its first change waits for its first step: every change till then takes it.
|
|
1683
|
+
let handoffAt = undefined;
|
|
1684
|
+
/**
|
|
1685
|
+
* A member's rule's key, as the server's rule group named its transitions in this change: what its Appear
|
|
1686
|
+
* animation's name is checked against, in development (`env.appearKeyOf`); `None` otherwise.
|
|
1687
|
+
*/
|
|
1688
|
+
const memberRuleKeyOf = (slot, planned, reduced, skipped) => UndefinedOr.match(env.appearKeyOf, {
|
|
1689
|
+
onUndefined: () => Option.none(),
|
|
1690
|
+
onDefined: (keyOf) => keyOf(keys, memberTransitionsOf(keys, planned, (key, target) => env.defaultTransition.transitionFor(key, target), (k) => targetOr(targetOf(slot, k), Batch.get(made(), slot, keys[k])), skipped), reduced, skipped),
|
|
1691
|
+
});
|
|
1692
|
+
/** What the Handoff's module reads of this Batch's members running their Appear animation. */
|
|
1693
|
+
const handoffMembers = (keyOf) => ({
|
|
1694
|
+
appearing,
|
|
1695
|
+
elementOf: (slot) => elementOf[memberOf[slot]],
|
|
1696
|
+
keyOf: UndefinedOr.map(env.appearKeyOf, () => keyOf),
|
|
1697
|
+
runtime: env.runtime,
|
|
1698
|
+
release: releaseAppearing,
|
|
1699
|
+
});
|
|
1700
|
+
/** The first change's `startAt`, its members' times read at its first step (`batch-handoff.ts`, loaded by now). */
|
|
1701
|
+
const handoffStartAt = (keyOf) => UndefinedOr.getOrThrow(handoffModule).startAtOf(handoffMembers(keyOf));
|
|
1702
|
+
// Changes that wait for the Handoff's code, run in order once it has loaded; none once it's disposed.
|
|
1703
|
+
let waitingForHandoff = undefined;
|
|
1704
|
+
/** `run` once the Handoff's code has loaded, after any change waiting before it; its members let go if it fails to. */
|
|
1705
|
+
const afterHandoffLoads = (run) => {
|
|
1706
|
+
if (Predicate.isNotUndefined(waitingForHandoff)) {
|
|
1707
|
+
waitingForHandoff.push(run);
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
waitingForHandoff = [run];
|
|
1711
|
+
void loadHandoff(env.runtime).then((module) => {
|
|
1712
|
+
const waiting = UndefinedOr.getOrThrow(waitingForHandoff);
|
|
1713
|
+
waitingForHandoff = undefined;
|
|
1714
|
+
if (disposed)
|
|
1715
|
+
return;
|
|
1716
|
+
// Not loaded: each member let go of its animation, and moved from its start.
|
|
1717
|
+
if (Predicate.isUndefined(module))
|
|
1718
|
+
releaseAppearing();
|
|
1719
|
+
Arr.forEach(waiting, (next) => next());
|
|
1720
|
+
});
|
|
1721
|
+
};
|
|
1722
|
+
/**
|
|
1723
|
+
* Every member still running its Appear animation let go of it: once the Handoff's first step has read
|
|
1724
|
+
* them, one a change didn't move among them, or each one the Handoff's code never came for.
|
|
1725
|
+
*/
|
|
1726
|
+
const releaseAppearing = () => {
|
|
1727
|
+
Iter.forEach(appearing, (slot) => UndefinedOr.map(elementOf[memberOf[slot]], Appear.release));
|
|
1728
|
+
appearing.clear();
|
|
1729
|
+
handoffAt = undefined;
|
|
1730
|
+
};
|
|
1731
|
+
// --- Hover and press per member (#665's PR 5, ADR-0070 decision 12, Q56–Q60) ----------------------
|
|
1732
|
+
// Whether the Batch watches its members' hover and presses yet. What lays their layers on and lifts
|
|
1733
|
+
// them is `batch-gestures.ts`', loaded at its first need (Q62).
|
|
1734
|
+
const listening = { hover: false, press: false };
|
|
1735
|
+
/** The member at `slot` turned toward its Override stack's targets on `transition`: one member, never staggered (Q58). */
|
|
1736
|
+
const turnMember = (slot, transition) => turnOn([slot], transition, undefined, startsOf(takeBack([slot], changesGroup)));
|
|
1737
|
+
/**
|
|
1738
|
+
* Member `i`'s gestures dropped with its element (Q59): with its slot kept (its element replaced), back
|
|
1739
|
+
* toward `animate`'s on the Batch's transition, as at a gesture's end; its next one starts afresh.
|
|
1740
|
+
*/
|
|
1741
|
+
const ungesture = (i) => {
|
|
1742
|
+
let on = 0;
|
|
1743
|
+
if (Predicate.isNotUndefined(hovering[i]))
|
|
1744
|
+
on++;
|
|
1745
|
+
if (Predicate.isNotUndefined(pressing[i]))
|
|
1746
|
+
on++;
|
|
1747
|
+
if (Predicate.isNotUndefined(dragging[i]))
|
|
1748
|
+
on++;
|
|
1749
|
+
if (Predicate.isNotUndefined(hands[i]))
|
|
1750
|
+
on++;
|
|
1751
|
+
if (on === 0)
|
|
1752
|
+
return;
|
|
1753
|
+
hovering[i] = undefined;
|
|
1754
|
+
pressing[i] = undefined;
|
|
1755
|
+
dragging[i] = undefined;
|
|
1756
|
+
hands[i] = undefined;
|
|
1757
|
+
const slot = slotOf[i];
|
|
1758
|
+
if (Bool.and(slot !== NO_SLOT, !disposed))
|
|
1759
|
+
turnMember(slot, configuredOf());
|
|
1760
|
+
// Counted until it's turned, so `targetOf` reads its bases.
|
|
1761
|
+
gesturing -= on;
|
|
1762
|
+
bases[i] = undefined;
|
|
1763
|
+
};
|
|
1764
|
+
/** Where member `i`'s keys only `values` give were as they came on, kept for its layers' end. */
|
|
1765
|
+
// Per gesture start, a loop over the Batch's keys (#665).
|
|
1766
|
+
const baseFor = (i, slot, values) => {
|
|
1767
|
+
let base = bases[i];
|
|
1768
|
+
for (let k = 0; k < stride; k++) {
|
|
1769
|
+
if (Number.isNaN(values[k]))
|
|
1770
|
+
continue;
|
|
1771
|
+
if (!Number.isNaN(current[i * stride + k]))
|
|
1772
|
+
continue;
|
|
1773
|
+
if (Predicate.isUndefined(base)) {
|
|
1774
|
+
base = new Float64Array(stride).fill(Number.NaN);
|
|
1775
|
+
bases[i] = base;
|
|
1776
|
+
}
|
|
1777
|
+
// Kept from the first layer that gave it.
|
|
1778
|
+
if (!Number.isNaN(base[k]))
|
|
1779
|
+
continue;
|
|
1780
|
+
base[k] = Batch.get(made(), slot, keys[k]);
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
/** Whether member `i` has no gesture layer on. */
|
|
1784
|
+
const noLayer = (i) => Bool.and(Bool.and(Predicate.isUndefined(hovering[i]), Predicate.isUndefined(pressing[i])), Predicate.isUndefined(dragging[i]));
|
|
1785
|
+
// --- A Batch Reorder group's item in hand (#712, ADR-0072 decision 7) ---------------------------------
|
|
1786
|
+
// The member a hand's change moves, by its place in the Batch's run, reused at each drag sample.
|
|
1787
|
+
const handMovers = [NO_SLOT];
|
|
1788
|
+
// A hand let go: where its `x` and `y` start from, and their speeds, `[x, y, vx, vy]`.
|
|
1789
|
+
const handLetGo = new Float64Array(4);
|
|
1790
|
+
// Per key at the hand's change, core's retarget calling them (the hot path): statements.
|
|
1791
|
+
const letGoFrom = (_, k) => {
|
|
1792
|
+
if (k === handX)
|
|
1793
|
+
return handLetGo[0];
|
|
1794
|
+
if (k === handY)
|
|
1795
|
+
return handLetGo[1];
|
|
1796
|
+
return Number.NaN;
|
|
1797
|
+
};
|
|
1798
|
+
const letGoSpeed = (_, k) => {
|
|
1799
|
+
if (k === handX)
|
|
1800
|
+
return handLetGo[2];
|
|
1801
|
+
if (k === handY)
|
|
1802
|
+
return handLetGo[3];
|
|
1803
|
+
return 0;
|
|
1804
|
+
};
|
|
1805
|
+
const LET_GO = { from: letGoFrom, velocity: letGoSpeed };
|
|
1806
|
+
/** Member `i`'s hand, made as it's first held: counted with its layers, and the Batch's `x` and `y` found. */
|
|
1807
|
+
// A change of one member, batch.ts's site (#665): statements.
|
|
1808
|
+
const handOf = (i) => {
|
|
1809
|
+
const known = hands[i];
|
|
1810
|
+
if (Predicate.isNotUndefined(known))
|
|
1811
|
+
return known;
|
|
1812
|
+
const made = new Float64Array(2);
|
|
1813
|
+
hands[i] = made;
|
|
1814
|
+
gesturing++;
|
|
1815
|
+
handX = keyIndexOr(keyIndex.get("x"));
|
|
1816
|
+
handY = keyIndexOr(keyIndex.get("y"));
|
|
1817
|
+
return made;
|
|
1818
|
+
};
|
|
1819
|
+
/** Member `i` held at (`x`, `y`): its `x` and `y` there at the next frame, with no spring. */
|
|
1820
|
+
const handAt = (i, x, y) => {
|
|
1821
|
+
const slot = slotOf[i];
|
|
1822
|
+
if (Bool.or(slot === NO_SLOT, disposed))
|
|
1823
|
+
return;
|
|
1824
|
+
const hand = handOf(i);
|
|
1825
|
+
hand[0] = x;
|
|
1826
|
+
hand[1] = y;
|
|
1827
|
+
handMovers[0] = slot;
|
|
1828
|
+
wake(Batch.retarget(made(), handMovers, targetOf, IN_HAND));
|
|
1829
|
+
};
|
|
1830
|
+
/** Member `i` let go: from where it was held, at (`vx`, `vy`) a second, toward its Override stack's targets. */
|
|
1831
|
+
const handOff = (i, vx, vy) => {
|
|
1832
|
+
const hand = hands[i];
|
|
1833
|
+
if (Predicate.isUndefined(hand))
|
|
1834
|
+
return;
|
|
1835
|
+
hands[i] = undefined;
|
|
1836
|
+
handLetGo[0] = hand[0];
|
|
1837
|
+
handLetGo[1] = hand[1];
|
|
1838
|
+
handLetGo[2] = vx;
|
|
1839
|
+
handLetGo[3] = vy;
|
|
1840
|
+
const slot = slotOf[i];
|
|
1841
|
+
if (Bool.and(slot !== NO_SLOT, !disposed))
|
|
1842
|
+
turnOn([slot], configuredOf(), undefined, LET_GO);
|
|
1843
|
+
// Counted until it's turned, so `targetOf` read its hand's keys from its stack.
|
|
1844
|
+
gesturing--;
|
|
1845
|
+
};
|
|
1846
|
+
// --- A change that moves the targets under its members (#712) ----------------------------------------
|
|
1847
|
+
// A key's speed as `shiftedFrom` found it, for `shiftedSpeed`, which core reads right after, the same key.
|
|
1848
|
+
let shiftedVelocity = 0;
|
|
1849
|
+
/** Where `slot`'s `k`th key starts as its target moves under it: as far off its new target as off its old; `NaN`, unmoved. */
|
|
1850
|
+
// Per member per key at the change (batch.ts's site, #665): statements.
|
|
1851
|
+
const shiftedFrom = (slot, k) => {
|
|
1852
|
+
const next = targetOf(slot, k);
|
|
1853
|
+
const was = Batch.target(made(), slot, keys[k]);
|
|
1854
|
+
if (Number.isNaN(next) || Number.isNaN(was) || next === was)
|
|
1855
|
+
return Number.NaN;
|
|
1856
|
+
shiftedVelocity = Batch.velocity(made(), slot, keys[k]);
|
|
1857
|
+
return Batch.get(made(), slot, keys[k]) + next - was;
|
|
1858
|
+
};
|
|
1859
|
+
const shiftedSpeed = () => shiftedVelocity;
|
|
1860
|
+
const SHIFTED = { from: shiftedFrom, velocity: shiftedSpeed };
|
|
1861
|
+
/** What its gestures work its members through. */
|
|
1862
|
+
const gestureHost = {
|
|
1863
|
+
memberElementOf: (node) => {
|
|
1864
|
+
if (!Predicate.isObject(node))
|
|
1865
|
+
return Option.none();
|
|
1866
|
+
// Any node's object: a WeakMap read, which an element this Batch drew answers.
|
|
1867
|
+
const entry = MEMBER_ELEMENTS.get(node);
|
|
1868
|
+
if (Predicate.isUndefined(entry))
|
|
1869
|
+
return Option.none();
|
|
1870
|
+
if (entry.binding !== binding)
|
|
1871
|
+
return Option.none();
|
|
1872
|
+
return Option.some(node);
|
|
1873
|
+
},
|
|
1874
|
+
memberAt: (element) => UndefinedOr.map(MEMBER_ELEMENTS.get(element), (entry) => entry.member),
|
|
1875
|
+
layered: (layer, i) => Predicate.isNotUndefined(layers[layer][i]),
|
|
1876
|
+
layer: (layer, i, values, transition) => {
|
|
1877
|
+
const slot = slotOf[i];
|
|
1878
|
+
if (slot === NO_SLOT)
|
|
1879
|
+
return;
|
|
1880
|
+
const was = layers[layer][i];
|
|
1881
|
+
if (Predicate.isNotUndefined(values)) {
|
|
1882
|
+
if (Predicate.isUndefined(was))
|
|
1883
|
+
gesturing++;
|
|
1884
|
+
baseFor(i, slot, values);
|
|
1885
|
+
}
|
|
1886
|
+
layers[layer][i] = values;
|
|
1887
|
+
// A leaver's exit holds its keys (Q47), and lands: its gestures move nothing.
|
|
1888
|
+
if (Predicate.isUndefined(exits[i]))
|
|
1889
|
+
turnMember(slot, transition);
|
|
1890
|
+
if (Predicate.isNotUndefined(values))
|
|
1891
|
+
return;
|
|
1892
|
+
if (Predicate.isUndefined(was))
|
|
1893
|
+
return;
|
|
1894
|
+
// Lifted: counted until it's turned, so `targetOf` read its bases.
|
|
1895
|
+
gesturing--;
|
|
1896
|
+
if (noLayer(i))
|
|
1897
|
+
bases[i] = undefined;
|
|
1898
|
+
},
|
|
1899
|
+
keys: () => keys,
|
|
1900
|
+
nameOf: (i) => form.nameOf(i),
|
|
1901
|
+
indexOf: (i) => indexOf[i],
|
|
1902
|
+
itemOf: (i) => itemOf[i],
|
|
1903
|
+
keyed,
|
|
1904
|
+
untrack: env.untrack,
|
|
1905
|
+
configured: configuredOf,
|
|
1906
|
+
// Read as each gesture starts: a Batch Reorder group's are its props now (#712).
|
|
1907
|
+
get hoverGiven() {
|
|
1908
|
+
return config.whileHover;
|
|
1909
|
+
},
|
|
1910
|
+
get tapGiven() {
|
|
1911
|
+
return config.whileTap;
|
|
1912
|
+
},
|
|
1913
|
+
pressKeys: env.pressKeys,
|
|
1914
|
+
dragGiven: () => config.whileDrag,
|
|
1915
|
+
tell: (told) => UndefinedOr.map(hooks.gesture, (tellIt) => tellIt(told)),
|
|
1916
|
+
handAt,
|
|
1917
|
+
handOff,
|
|
1918
|
+
};
|
|
1919
|
+
/**
|
|
1920
|
+
* Its members' hover, or presses, watched from now on (Q60): once each. Presses start hover first, so a
|
|
1921
|
+
* release off a member tells its hover's end before its press's whatever was asked first, as a Wardic
|
|
1922
|
+
* element's do; and make each pressable member's element focusable (Q57).
|
|
1923
|
+
*/
|
|
1924
|
+
const listen = (gesture) => {
|
|
1925
|
+
const watches = env.gestures;
|
|
1926
|
+
if (Predicate.isUndefined(watches))
|
|
1927
|
+
return;
|
|
1928
|
+
if (disposed)
|
|
1929
|
+
return;
|
|
1930
|
+
if (listening[gesture])
|
|
1931
|
+
return;
|
|
1932
|
+
if (gesture === "press")
|
|
1933
|
+
listen("hover");
|
|
1934
|
+
listening[gesture] = true;
|
|
1935
|
+
if (gesture === "press") {
|
|
1936
|
+
Arr.forEach(elementOf, (el) => {
|
|
1937
|
+
if (Predicate.isNotUndefined(el))
|
|
1938
|
+
KeyboardPress.makeFocusable(el);
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
watches.listen(gesture, gestureHost);
|
|
1942
|
+
};
|
|
1943
|
+
// --- The latest driver (#665's PR 4, ADR-0069 decision 17, Q52–Q54) ---------------------------------
|
|
1944
|
+
// Each member's groups a Wardic element on its element holds; each held element's groups, as bits; and
|
|
1945
|
+
// each group's keys' indices, from `makeBatch`.
|
|
1946
|
+
const heldBy = [];
|
|
1947
|
+
const masks = new Map();
|
|
1948
|
+
const groupKs = { transform: [], opacity: [] };
|
|
1949
|
+
/** Member `i`'s `group` drawn by the Batch again. */
|
|
1950
|
+
const unmask = (i, group) => {
|
|
1951
|
+
const held = heldBy[i];
|
|
1952
|
+
if (Predicate.isUndefined(held))
|
|
1953
|
+
return;
|
|
1954
|
+
held.groups.delete(group);
|
|
1955
|
+
const left = bitsOf(held.el) & ~GROUP_BITS[group];
|
|
1956
|
+
if (left !== 0) {
|
|
1957
|
+
masks.set(held.el, left);
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
masks.delete(held.el);
|
|
1961
|
+
heldBy[i] = undefined;
|
|
1962
|
+
};
|
|
1963
|
+
/** Member `i`'s held groups let go with its element: the Batch draws it no more, or another element now. */
|
|
1964
|
+
const letGo = (i) => {
|
|
1965
|
+
const held = heldBy[i];
|
|
1966
|
+
if (Predicate.isUndefined(held))
|
|
1967
|
+
return;
|
|
1968
|
+
masks.delete(held.el);
|
|
1969
|
+
heldBy[i] = undefined;
|
|
1970
|
+
};
|
|
1971
|
+
/** An element's held groups' bits: 0 for none. */
|
|
1972
|
+
const bitsOf = (el) => UndefinedOr.match(masks.get(el), { onUndefined: () => 0, onDefined: identity });
|
|
1973
|
+
/** Whether a change toward the members' targets moves `slot`'s `group`: a key of it whose target it changes. */
|
|
1974
|
+
// Per held member's group at a change (#665): statements.
|
|
1975
|
+
const changesGroup = (slot, group) => {
|
|
1976
|
+
const ks = groupKs[group];
|
|
1977
|
+
for (let n = 0; n < ks.length; n++) {
|
|
1978
|
+
const k = ks[n];
|
|
1979
|
+
const goal = targetOf(slot, k);
|
|
1980
|
+
if (Number.isNaN(goal))
|
|
1981
|
+
continue;
|
|
1982
|
+
if (goal !== Batch.target(made(), slot, keys[k]))
|
|
1983
|
+
return true;
|
|
1984
|
+
}
|
|
1985
|
+
return false;
|
|
1986
|
+
};
|
|
1987
|
+
/** Whether `given(slot, k)` gives a key of `group`: a driven change's or an exit's, which moves it. */
|
|
1988
|
+
// Per held member's group at a call (#665): statements.
|
|
1989
|
+
const givesGroup = (given) => (slot, group) => {
|
|
1990
|
+
const ks = groupKs[group];
|
|
1991
|
+
for (let n = 0; n < ks.length; n++) {
|
|
1992
|
+
if (given(slot, ks[n]))
|
|
1993
|
+
return true;
|
|
1994
|
+
}
|
|
1995
|
+
return false;
|
|
1996
|
+
};
|
|
1997
|
+
/** A handover's starts, for a change: each handed key's value and speed, `NaN` (and 0) for the rest. */
|
|
1998
|
+
const startsOf = (byMember) => {
|
|
1999
|
+
if (Predicate.isUndefined(byMember))
|
|
2000
|
+
return undefined;
|
|
2001
|
+
// Per member per key at a change (#665): statements.
|
|
2002
|
+
const handed = (slot, k, of, none) => {
|
|
2003
|
+
const back = byMember.get(memberOf[slot]);
|
|
2004
|
+
if (Predicate.isUndefined(back))
|
|
2005
|
+
return none;
|
|
2006
|
+
const value = of(back)[keys[k]];
|
|
2007
|
+
if (Predicate.isUndefined(value))
|
|
2008
|
+
return none;
|
|
2009
|
+
return value;
|
|
2010
|
+
};
|
|
2011
|
+
return {
|
|
2012
|
+
from: (slot, k) => handed(slot, k, (back) => back.values, Number.NaN),
|
|
2013
|
+
velocity: (slot, k) => handed(slot, k, (back) => back.velocities, 0),
|
|
2014
|
+
};
|
|
2015
|
+
};
|
|
2016
|
+
/**
|
|
2017
|
+
* The groups Wardic elements hold of `slots`' members that a change `moves`, taken back for it (Q54):
|
|
2018
|
+
* each from where its holder leaves it, but one its holder keeps through it. Each member's handover,
|
|
2019
|
+
* or `undefined` for none.
|
|
2020
|
+
*/
|
|
2021
|
+
const takeBack = (slots, moves) => {
|
|
2022
|
+
if (masks.size === 0)
|
|
2023
|
+
return undefined;
|
|
2024
|
+
let byMember;
|
|
2025
|
+
// Per held member at a change (#665): statements. Deleting the entry being visited is safe in a Map's iteration.
|
|
2026
|
+
Arr.forEach(slots, (slot) => {
|
|
2027
|
+
const i = memberOf[slot];
|
|
2028
|
+
const held = heldBy[i];
|
|
2029
|
+
if (Predicate.isUndefined(held))
|
|
2030
|
+
return;
|
|
2031
|
+
Iter.forEach(held.groups, ([group, holder]) => {
|
|
2032
|
+
if (!moves(slot, group))
|
|
2033
|
+
return;
|
|
2034
|
+
if (holder.keepsThrough(group))
|
|
2035
|
+
return;
|
|
2036
|
+
const back = holder.surrender(group);
|
|
2037
|
+
unmask(i, group);
|
|
2038
|
+
if (Predicate.isUndefined(back))
|
|
2039
|
+
return;
|
|
2040
|
+
if (Predicate.isUndefined(byMember))
|
|
2041
|
+
byMember = new Map();
|
|
2042
|
+
const was = byMember.get(i);
|
|
2043
|
+
if (Predicate.isUndefined(was)) {
|
|
2044
|
+
byMember.set(i, back);
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
byMember.set(i, { values: { ...was.values, ...back.values }, velocities: { ...was.velocities, ...back.velocities } });
|
|
2048
|
+
});
|
|
2049
|
+
});
|
|
2050
|
+
return byMember;
|
|
2051
|
+
};
|
|
2052
|
+
/**
|
|
2053
|
+
* Before a driven change of `slots` (an `animate` call's, a sequence's, a keyed Batch's exits): the
|
|
2054
|
+
* groups Wardic elements hold of them that it `moves`, taken back, each turned from there toward its
|
|
2055
|
+
* targets, which the change then takes as it plays.
|
|
2056
|
+
*/
|
|
2057
|
+
const retakeFor = (slots, moves) => {
|
|
2058
|
+
const back = takeBack(slots, moves);
|
|
2059
|
+
if (Predicate.isUndefined(back))
|
|
2060
|
+
return;
|
|
2061
|
+
change(Arr.filter(slots, (slot) => back.has(memberOf[slot])), startsOf(back));
|
|
2062
|
+
};
|
|
2063
|
+
/** A Wardic element on member `i`'s element takes its `group` (Q53). */
|
|
2064
|
+
const yieldGroup = (i, group, holder) => {
|
|
2065
|
+
const slot = slotOf[i];
|
|
2066
|
+
if (slot === NO_SLOT)
|
|
2067
|
+
return undefined;
|
|
2068
|
+
const el = elementOf[i];
|
|
2069
|
+
if (Predicate.isUndefined(el))
|
|
2070
|
+
return undefined;
|
|
2071
|
+
const ks = groupKs[group];
|
|
2072
|
+
if (ks.length === 0)
|
|
2073
|
+
return undefined;
|
|
2074
|
+
const inGroup = [];
|
|
2075
|
+
const values = {};
|
|
2076
|
+
const velocities = {};
|
|
2077
|
+
// Per key of a group a Wardic element takes (#665): statements.
|
|
2078
|
+
Arr.forEach(ks, (k) => {
|
|
2079
|
+
const key = keys[k];
|
|
2080
|
+
inGroup.push(key);
|
|
2081
|
+
values[key] = Batch.get(made(), slot, key);
|
|
2082
|
+
velocities[key] = Batch.velocity(made(), slot, key);
|
|
2083
|
+
});
|
|
2084
|
+
let held = heldBy[i];
|
|
2085
|
+
if (Predicate.isUndefined(held)) {
|
|
2086
|
+
held = { el, groups: new Map() };
|
|
2087
|
+
heldBy[i] = held;
|
|
2088
|
+
}
|
|
2089
|
+
held.groups.set(group, holder);
|
|
2090
|
+
masks.set(el, bitsOf(el) | GROUP_BITS[group]);
|
|
2091
|
+
return { keys: inGroup, values, velocities };
|
|
2092
|
+
};
|
|
2093
|
+
/** What member `i`'s `key` is drawn at now: its Batch value, a transform key it hasn't at its identity, or none. */
|
|
2094
|
+
const drawnValueOf = (i, key) => {
|
|
2095
|
+
const group = batchGroupOf(key);
|
|
2096
|
+
if (Predicate.isUndefined(group))
|
|
2097
|
+
return undefined;
|
|
2098
|
+
const slot = slotOf[i];
|
|
2099
|
+
if (slot === NO_SLOT)
|
|
2100
|
+
return undefined;
|
|
2101
|
+
if (keyIndex.has(key))
|
|
2102
|
+
return Batch.get(made(), slot, key);
|
|
2103
|
+
if (groupKs[group].length === 0)
|
|
2104
|
+
return undefined;
|
|
2105
|
+
return identityOf(key);
|
|
2106
|
+
};
|
|
2107
|
+
/**
|
|
2108
|
+
* The Wardic element gives member `i`'s `group` back (Q54): the Batch draws it again, from there, toward
|
|
2109
|
+
* its targets. A leaver mid-exit is drawn where its exit has it, which its element goes as it lands.
|
|
2110
|
+
*/
|
|
2111
|
+
const reclaim = (i, group, back) => {
|
|
2112
|
+
unmask(i, group);
|
|
2113
|
+
if (disposed)
|
|
2114
|
+
return;
|
|
2115
|
+
const slot = slotOf[i];
|
|
2116
|
+
if (slot === NO_SLOT)
|
|
2117
|
+
return;
|
|
2118
|
+
if (Predicate.isNotUndefined(exits[i]))
|
|
2119
|
+
return;
|
|
2120
|
+
change([slot], startsOf(new Map([[i, back]])));
|
|
2121
|
+
};
|
|
2122
|
+
// Elements that arrived this task: entered at once, turned toward their targets together at its end.
|
|
2123
|
+
let arrived = [];
|
|
2124
|
+
let flushing = false;
|
|
2125
|
+
const flushArrivals = () => {
|
|
2126
|
+
flushing = false;
|
|
2127
|
+
if (disposed)
|
|
2128
|
+
return;
|
|
2129
|
+
settleWaiting();
|
|
2130
|
+
settleUnlisted();
|
|
2131
|
+
// An element `mode="wait"` holds off the page moves as it goes on (Q46).
|
|
2132
|
+
const slots = Arr.filter(arrived, (slot) => !heldBack(slot));
|
|
2133
|
+
arrived = [];
|
|
2134
|
+
change(slots);
|
|
2135
|
+
};
|
|
2136
|
+
/** The task's arrivals flushed at its end, once. */
|
|
2137
|
+
const flushSoon = () => {
|
|
2138
|
+
if (flushing)
|
|
2139
|
+
return;
|
|
2140
|
+
flushing = true;
|
|
2141
|
+
queueMicrotask(flushArrivals);
|
|
2142
|
+
};
|
|
2143
|
+
/** `el` drawn now at `values`, one per key, and turned about its own centre inside an `<svg>`, as the renderer's. */
|
|
2144
|
+
const drawNow = (el, values) => {
|
|
2145
|
+
if (Svg.isInner(el)) {
|
|
2146
|
+
const style = el.style;
|
|
2147
|
+
style.setProperty("transform-box", "fill-box");
|
|
2148
|
+
style.setProperty("transform-origin", "50% 50%");
|
|
2149
|
+
}
|
|
2150
|
+
write(el, Float64Array.from(values), 0);
|
|
2151
|
+
};
|
|
2152
|
+
/** `el` no longer known to `animate` as member `i`'s element, unless another member has it now. */
|
|
2153
|
+
const forget = (el, i) => {
|
|
2154
|
+
letGo(i);
|
|
2155
|
+
ungesture(i);
|
|
2156
|
+
if (MEMBER_ELEMENTS.get(el) === entries[i])
|
|
2157
|
+
MEMBER_ELEMENTS.delete(el);
|
|
2158
|
+
};
|
|
2159
|
+
/** Member `i` entered on `el`, drawn at its start now, its move with every member that arrives this task, at its end. */
|
|
2160
|
+
const enter = (i, el) => {
|
|
2161
|
+
const start = startOf(i);
|
|
2162
|
+
const entering = Batch.enter(made(), el, start);
|
|
2163
|
+
slotOf[i] = entering;
|
|
2164
|
+
// Hydrating, its element may run its Appear animation (#706): the arrival change takes it over. A
|
|
2165
|
+
// client-only Batch reads nothing of it. Per member at mount (#540): statements.
|
|
2166
|
+
if (looksForAppear) {
|
|
2167
|
+
if (Appear.pending(el))
|
|
2168
|
+
appearing.add(entering);
|
|
2169
|
+
}
|
|
2170
|
+
memberOf[entering] = i;
|
|
2171
|
+
form.entered(entering);
|
|
2172
|
+
drawNow(el, Arr.map(keys, (key) => start[key]));
|
|
2173
|
+
flushSoon();
|
|
2174
|
+
arrived.push(entering);
|
|
2175
|
+
};
|
|
2176
|
+
/** Whether another Batch draws `el`: it's a member's element there. */
|
|
2177
|
+
const drawnByAnother = (el) => {
|
|
2178
|
+
const other = MEMBER_ELEMENTS.get(el);
|
|
2179
|
+
if (Predicate.isUndefined(other))
|
|
2180
|
+
return false;
|
|
2181
|
+
return other.binding !== binding;
|
|
2182
|
+
};
|
|
2183
|
+
const arrive = (i, el) => {
|
|
2184
|
+
if (disposed)
|
|
2185
|
+
return;
|
|
2186
|
+
if (elementOf[i] === el)
|
|
2187
|
+
return;
|
|
2188
|
+
// One Batch draws an element (Q52): a second's would write over the first's. One with a layout node
|
|
2189
|
+
// can't be a member: the projection measures it under the transform the Batch draws.
|
|
2190
|
+
if (drawnByAnother(el))
|
|
2191
|
+
return fail(`an element (${elementName(el)}) is a member of two Batches: one Batch draws an element's \`transform\` and \`opacity\``);
|
|
2192
|
+
if (LAYOUT_ELEMENTS.has(el))
|
|
2193
|
+
return fail(layoutOnMember(el));
|
|
2194
|
+
const was = elementOf[i];
|
|
2195
|
+
if (Predicate.isNotUndefined(was))
|
|
2196
|
+
forget(was, i);
|
|
2197
|
+
elementOf[i] = el;
|
|
2198
|
+
// Known to `animate`, as member `i`'s element (Q14).
|
|
2199
|
+
MEMBER_ELEMENTS.set(el, UndefinedOr.getOrThrow(entries[i]));
|
|
2200
|
+
// Pressable, it's focusable, so a key can press it (Q57): called here, not through the lazily loaded
|
|
2201
|
+
// gestures, whose route cost a mount more than the check (#709, Q2).
|
|
2202
|
+
if (listening.press)
|
|
2203
|
+
KeyboardPress.makeFocusable(el);
|
|
2204
|
+
// Keyed, under `<AnimatePresence>`: watched there, so its leave plays its exit (Q46).
|
|
2205
|
+
watchOn(i, el);
|
|
2206
|
+
const slot = slotOf[i];
|
|
2207
|
+
// A new element for a member: it takes the member over, its values, speed and delays as they are.
|
|
2208
|
+
if (slot !== NO_SLOT) {
|
|
2209
|
+
Batch.replace(made(), slot, el);
|
|
2210
|
+
drawNow(el, Arr.map(keys, (key) => Batch.get(made(), slot, key)));
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
// Keyed, before the list has its key, or before the Batch is made: at the task's end, or a later change.
|
|
2214
|
+
if (!form.entersNow(i)) {
|
|
2215
|
+
waiting.push(i);
|
|
2216
|
+
flushSoon();
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
enter(i, el);
|
|
2220
|
+
};
|
|
2221
|
+
/** One stop's value for member `i`: a number, or a function's of its index and the count. */
|
|
2222
|
+
const stopAt = (key, stop, i) => {
|
|
2223
|
+
let value = stop;
|
|
2224
|
+
if (Predicate.isFunction(stop))
|
|
2225
|
+
value = stop(indexOf[i], form.size());
|
|
2226
|
+
if (Predicate.isNumber(value))
|
|
2227
|
+
return value;
|
|
2228
|
+
return fail(`an animate call's "${key}" gives ${form.nameOf(i)} ${JSON.stringify(value)}: a Batch takes numbers`);
|
|
2229
|
+
};
|
|
2230
|
+
/** The slots an `animate` call moves: every member's there is, or the members it names, in order, whose elements have arrived. */
|
|
2231
|
+
const callSlotsOf = (named) => UndefinedOr.match(named, {
|
|
2232
|
+
// A copy: the call keeps it, and members arrive after.
|
|
2233
|
+
onUndefined: () => [...form.arrivedSlots()],
|
|
2234
|
+
onDefined: (given) => Arr.filter(Arr.map(given, (i) => slotOf[i]), (slot) => slot !== NO_SLOT),
|
|
2235
|
+
});
|
|
2236
|
+
/** Where an element call's `key` goes for a member's element (Q14, Q33). */
|
|
2237
|
+
const routeOf = (key) => {
|
|
2238
|
+
if (keyIndex.has(key))
|
|
2239
|
+
return "batch";
|
|
2240
|
+
if (!drawn.has("transform"))
|
|
2241
|
+
return "free";
|
|
2242
|
+
if (key === "transform")
|
|
2243
|
+
return "drawn";
|
|
2244
|
+
if (key === "opacity")
|
|
2245
|
+
return "free";
|
|
2246
|
+
if (DomBatch.writer.writes(key))
|
|
2247
|
+
return "drawn";
|
|
2248
|
+
return "free";
|
|
2249
|
+
};
|
|
2250
|
+
/** A track that moves nothing: a call before a keyed Batch has members, which finishes at its play (Q51). */
|
|
2251
|
+
const landedTrack = (settled) => ({ run: settled, stop: noop, cancel: noop, duration: () => 0 });
|
|
2252
|
+
/** An `animate` call's track: its members' targets and first stops by key, its own transitions, its Playhead. */
|
|
2253
|
+
const track = (call) => {
|
|
2254
|
+
if (Predicate.isUndefined(batch))
|
|
2255
|
+
return landedTrack(call.settled);
|
|
2256
|
+
const slots = callSlotsOf(call.members);
|
|
2257
|
+
// Each member's stops by key, its target and its first, `NaN` for none: worked out once, at the call.
|
|
2258
|
+
const tos = new Float64Array(capacity * stride).fill(Number.NaN);
|
|
2259
|
+
const froms = new Float64Array(capacity * stride).fill(Number.NaN);
|
|
2260
|
+
let firsts = false;
|
|
2261
|
+
const given = call.target;
|
|
2262
|
+
Arr.forEach(Rec.keys(given), (key) => {
|
|
2263
|
+
const k = keyIndex.get(key);
|
|
2264
|
+
if (Predicate.isUndefined(k))
|
|
2265
|
+
return fail(`an animate call gives "${key}", which isn't one of the Batch's keys (${keys.join(", ")})`);
|
|
2266
|
+
const value = given[key];
|
|
2267
|
+
// Per member per key at a call (#665): statements.
|
|
2268
|
+
Arr.forEach(slots, (slot) => {
|
|
2269
|
+
const i = memberOf[slot];
|
|
2270
|
+
const at = i * stride + k;
|
|
2271
|
+
let stops = value;
|
|
2272
|
+
if (Predicate.isFunction(value))
|
|
2273
|
+
stops = value(indexOf[i], form.size());
|
|
2274
|
+
if (isPair(stops)) {
|
|
2275
|
+
froms[at] = stopAt(key, stops[0], i);
|
|
2276
|
+
tos[at] = stopAt(key, stops[1], i);
|
|
2277
|
+
firsts = true;
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
if (Predicate.isNumber(stops)) {
|
|
2281
|
+
tos[at] = stops;
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
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`);
|
|
2285
|
+
});
|
|
2286
|
+
});
|
|
2287
|
+
const fromOf = (slot, k) => froms[memberOf[slot] * stride + k];
|
|
2288
|
+
const toOf = (slot, k) => tos[memberOf[slot] * stride + k];
|
|
2289
|
+
// The groups Wardic elements hold of its members that it moves come back first, from where they've left them (Q54).
|
|
2290
|
+
retakeFor(slots, givesGroup((slot, k) => !Number.isNaN(toOf(slot, k))));
|
|
2291
|
+
return changeOn(slots, toOf, Bool.match(firsts, { onTrue: () => fromOf, onFalse: () => undefined }), call);
|
|
2292
|
+
};
|
|
2293
|
+
/**
|
|
2294
|
+
* A driven change of `slots` toward `targetOf`, from `fromOf`'s first stops when it gives them, on its
|
|
2295
|
+
* call's transitions (which the Batch copies for it, so the Playhead driving them reaches its keys
|
|
2296
|
+
* alone), its `stagger()` counting the members it moves: an `animate` call's, or a keyed Batch's exits.
|
|
2297
|
+
*/
|
|
2298
|
+
const changeOn = (slots, targetOf, fromOf, call) => {
|
|
2299
|
+
const transition = Bool.match(call.skipAnimations, {
|
|
2300
|
+
onTrue: () => () => INSTANT,
|
|
2301
|
+
onFalse: () => {
|
|
2302
|
+
const planned = plannedOf(env.positionalKeys, keys, UndefinedOr.map(call.transition, unstaggered), call.reducedMotion);
|
|
2303
|
+
return (slot, k) => {
|
|
2304
|
+
const plan = planned[k];
|
|
2305
|
+
if (Predicate.isNotUndefined(plan.own))
|
|
2306
|
+
return plan.own;
|
|
2307
|
+
return delayedBy(defaultFor(k, targetOf(slot, k)), plan.delay);
|
|
2308
|
+
};
|
|
2309
|
+
},
|
|
2310
|
+
});
|
|
2311
|
+
const options = { head: call.head, transition, onLanded: call.settled };
|
|
2312
|
+
if (Predicate.isNotUndefined(fromOf))
|
|
2313
|
+
options.from = fromOf;
|
|
2314
|
+
if (Predicate.isNotUndefined(call.onMemberLanded))
|
|
2315
|
+
options.onMemberLanded = call.onMemberLanded;
|
|
2316
|
+
const delay = Bool.match(call.skipAnimations, { onTrue: () => undefined, onFalse: () => staggerOf(call.transition) });
|
|
2317
|
+
if (Predicate.isNotUndefined(delay))
|
|
2318
|
+
options.delay = delay;
|
|
2319
|
+
return controlsOf(Batch.animate(made(), slots, targetOf, options));
|
|
2320
|
+
};
|
|
2321
|
+
/** Whether member `i`'s element has arrived. */
|
|
2322
|
+
const hasArrived = (i) => slotOf[i] !== NO_SLOT;
|
|
2323
|
+
/** The members a sequence's Segment moves (Q39): every member whose element has arrived, in the list's order, or those `named` names once theirs have. */
|
|
2324
|
+
const membersOf = (named) => Arr.filter(UndefinedOr.match(named, { onUndefined: form.inOrder, onDefined: identity }), hasArrived);
|
|
2325
|
+
/** A sequence's Segment of the Batch (Q38, Q39): its members, and each key's value, a function's called with a member's index and the count. */
|
|
2326
|
+
const segmentOf = (named, target) => {
|
|
2327
|
+
if (Predicate.isUndefined(batch))
|
|
2328
|
+
return { subjects: [], values: {} };
|
|
2329
|
+
const moving = membersOf(named);
|
|
2330
|
+
const values = {};
|
|
2331
|
+
Arr.forEach(Rec.keys(target), (key) => {
|
|
2332
|
+
const value = target[key];
|
|
2333
|
+
if (Predicate.isUndefined(value))
|
|
2334
|
+
return;
|
|
2335
|
+
if (!keyIndex.has(key))
|
|
2336
|
+
return fail(`a sequence's Segment of a Batch gives "${key}", which isn't one of its keys (${keys.join(", ")})`);
|
|
2337
|
+
if (Predicate.isFunction(value)) {
|
|
2338
|
+
values[key] = (index) => segmentValueOf(key, value(indexOf[moving[index]], form.size()), form.nameOf(moving[index]));
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
values[key] = segmentValueOf(key, value, undefined);
|
|
2342
|
+
});
|
|
2343
|
+
return { subjects: Arr.map(moving, (i) => UndefinedOr.getOrThrow(entries[i])), values };
|
|
2344
|
+
};
|
|
2345
|
+
/** A sequence's Segment of members' elements (Q40): a Batch key's value a number, `null` or stops; no transform the Batch draws without it. */
|
|
2346
|
+
const checkElementSegment = (target) => Arr.forEach(Rec.keys(target), (key) => {
|
|
2347
|
+
const route = routeOf(key);
|
|
2348
|
+
if (route === "drawn")
|
|
2349
|
+
return drawnKey(key);
|
|
2350
|
+
if (route === "batch")
|
|
2351
|
+
segmentValueOf(key, target[key], undefined);
|
|
2352
|
+
});
|
|
2353
|
+
/**
|
|
2354
|
+
* A sequence's track over its members (#665, Q36): each member's Batch keys through the stops and
|
|
2355
|
+
* tween core's Sequence compiled for it; reduced motion's Snap of a positional key, or `skipAnimations`,
|
|
2356
|
+
* landing it at once where its run would end, as an element's.
|
|
2357
|
+
*/
|
|
2358
|
+
const sequenceTrack = (call) => {
|
|
2359
|
+
if (Predicate.isUndefined(batch))
|
|
2360
|
+
return landedTrack(call.settled);
|
|
2361
|
+
const slots = [];
|
|
2362
|
+
const animations = [];
|
|
2363
|
+
Arr.forEach(call.members, (i, n) => {
|
|
2364
|
+
const slot = slotOf[i];
|
|
2365
|
+
if (slot === NO_SLOT)
|
|
2366
|
+
return;
|
|
2367
|
+
slots.push(slot);
|
|
2368
|
+
animations[slot] = call.animations[n];
|
|
2369
|
+
});
|
|
2370
|
+
// The groups Wardic elements hold of its members that it moves come back first (Q54).
|
|
2371
|
+
retakeFor(slots, givesGroup((slot, k) => Predicate.isNotUndefined(UndefinedOr.getOrThrow(animations[slot]).keyframes[keys[k]])));
|
|
2372
|
+
// Per member per key, once at its first play (#665): statements.
|
|
2373
|
+
const keyframesOf = (slot, k) => {
|
|
2374
|
+
const key = keys[k];
|
|
2375
|
+
const animation = UndefinedOr.getOrThrow(animations[slot]);
|
|
2376
|
+
const given = animation.keyframes[key];
|
|
2377
|
+
if (Predicate.isUndefined(given))
|
|
2378
|
+
return undefined;
|
|
2379
|
+
const transition = UndefinedOr.getOrThrow(animation.transition[key]);
|
|
2380
|
+
const stops = Arr.map(given, stopNumber);
|
|
2381
|
+
const snaps = call.reducedMotion && env.positionalKeys.isPositional(key);
|
|
2382
|
+
if (!call.skipAnimations && !snaps)
|
|
2383
|
+
return { stops, transition };
|
|
2384
|
+
// Where its run would end, from where it is: after its delay for reduced motion's Snap, at once when
|
|
2385
|
+
// skipped. Its last stop is its last number: a sequence ends a key with a `null` when its last Segment ends first.
|
|
2386
|
+
const end = ReducedMotion.endOf(stops[0], lastNumber(stops), transition);
|
|
2387
|
+
let delay = 0;
|
|
2388
|
+
if (!call.skipAnimations && Predicate.isNotUndefined(transition.delay))
|
|
2389
|
+
delay = transition.delay;
|
|
2390
|
+
return { stops: [Number.NaN, end], transition: landingAfter(delay) };
|
|
2391
|
+
};
|
|
2392
|
+
return controlsOf(Batch.keyframes(made(), slots, keyframesOf, { head: call.head, onLanded: call.settled }));
|
|
2393
|
+
};
|
|
2394
|
+
/** A driven change's controls, as an `animate` call's track: played, it wakes the Batch's run. */
|
|
2395
|
+
const controlsOf = (animation) => ({
|
|
2396
|
+
run: () => {
|
|
2397
|
+
if (disposed)
|
|
2398
|
+
return;
|
|
2399
|
+
wake(Batch.play(animation));
|
|
2400
|
+
},
|
|
2401
|
+
stop: () => {
|
|
2402
|
+
Batch.stop(animation);
|
|
2403
|
+
wake(0);
|
|
2404
|
+
},
|
|
2405
|
+
cancel: () => {
|
|
2406
|
+
Batch.cancel(animation);
|
|
2407
|
+
wake(0);
|
|
2408
|
+
},
|
|
2409
|
+
duration: () => Batch.durationOf(animation),
|
|
2410
|
+
});
|
|
2411
|
+
const bound = {
|
|
2412
|
+
track,
|
|
2413
|
+
entryOf: (i) => UndefinedOr.getOrThrow(entries[i]),
|
|
2414
|
+
routeOf,
|
|
2415
|
+
segmentOf,
|
|
2416
|
+
checkElementSegment,
|
|
2417
|
+
sequenceTrack,
|
|
2418
|
+
elementOf: (i) => elementOf[i],
|
|
2419
|
+
yieldGroup,
|
|
2420
|
+
reclaim,
|
|
2421
|
+
drawnValueOf,
|
|
2422
|
+
listen,
|
|
2423
|
+
host: gestureHost,
|
|
2424
|
+
targetsOf: () => form.targetsOf(),
|
|
2425
|
+
apply: (targets) => {
|
|
2426
|
+
if (disposed)
|
|
2427
|
+
return;
|
|
2428
|
+
form.take(targets);
|
|
2429
|
+
if (Predicate.isUndefined(batch))
|
|
2430
|
+
return;
|
|
2431
|
+
change(movingNow(form.arrivedSlots()));
|
|
2432
|
+
},
|
|
2433
|
+
applyShifted: (targets) => {
|
|
2434
|
+
if (disposed)
|
|
2435
|
+
return;
|
|
2436
|
+
form.take(targets);
|
|
2437
|
+
if (Predicate.isUndefined(batch))
|
|
2438
|
+
return;
|
|
2439
|
+
turnOn(movingNow(form.arrivedSlots()), configuredOf(), undefined, SHIFTED);
|
|
2440
|
+
Batch.draw(made());
|
|
2441
|
+
},
|
|
2442
|
+
refOf: (i) => form.refOf(i),
|
|
2443
|
+
memberFor: (key, presence) => form.memberFor(key, presence),
|
|
2444
|
+
namedOf: (entry) => {
|
|
2445
|
+
if (Predicate.isUndefined(entry.member))
|
|
2446
|
+
return undefined;
|
|
2447
|
+
// A keyed handle kept past its member's leave names nothing: its number may be another key's now.
|
|
2448
|
+
if (entries[entry.member] !== entry)
|
|
2449
|
+
return [];
|
|
2450
|
+
return [entry.member];
|
|
2451
|
+
},
|
|
2452
|
+
styleOf: (style) => ownStyleOf(style, drawn),
|
|
2453
|
+
dispose: () => {
|
|
2454
|
+
disposed = true;
|
|
2455
|
+
// Its leavers let go at once, uncompleted, and its held elements' holds: a presence waits on them no more.
|
|
2456
|
+
Arr.forEach(Arr.map(exits, (_, i) => i), cutExit);
|
|
2457
|
+
Arr.forEach(Arr.fromIterable(holds.keys()), unhold);
|
|
2458
|
+
Iter.forEach(fibers, (fiber) => fiber.interruptUnsafe());
|
|
2459
|
+
fibers.clear();
|
|
2460
|
+
Arr.forEach(elementOf, (el, i) => {
|
|
2461
|
+
if (Predicate.isNotUndefined(el))
|
|
2462
|
+
forget(el, i);
|
|
2463
|
+
});
|
|
2464
|
+
},
|
|
2465
|
+
};
|
|
2466
|
+
binding = bound;
|
|
2467
|
+
// Keyed: its first list taken in now, read as it was made (its binding calls this untracked); with `keys`
|
|
2468
|
+
// and no items yet, its core Batch made now too. By index: its keys are its members' first targets' and
|
|
2469
|
+
// starts', and its members fixed, each made now.
|
|
2470
|
+
if (keyed) {
|
|
2471
|
+
const first = keyedTargetsOf();
|
|
2472
|
+
if (Predicate.isNotUndefined(byKey.keys) && first.items.length === 0) {
|
|
2473
|
+
keysAre(byKey.keys);
|
|
2474
|
+
makeBatch(() => Number.NaN);
|
|
2475
|
+
}
|
|
2476
|
+
takeList(first);
|
|
2477
|
+
return bound;
|
|
2478
|
+
}
|
|
2479
|
+
growMembersTo(Math.max(1, count));
|
|
2480
|
+
keysAre(withMoreKeys(keysOf(byIndex)));
|
|
2481
|
+
current = indexTargetsOf();
|
|
2482
|
+
makeBatch((k) => current[k]);
|
|
2483
|
+
Arr.forEach(indices, (i) => {
|
|
2484
|
+
entries[i] = { binding: bound, member: i };
|
|
2485
|
+
indexOf[i] = i;
|
|
2486
|
+
refs[i] = (el) => arrive(i, el);
|
|
2487
|
+
});
|
|
2488
|
+
return bound;
|
|
2489
|
+
};
|
|
2490
|
+
//# sourceMappingURL=BatchMembers.js.map
|