@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
package/src/internal/appear.ts
CHANGED
|
@@ -1093,21 +1093,33 @@ export const find = (element: Element): Option.Option<Animation> =>
|
|
|
1093
1093
|
})
|
|
1094
1094
|
|
|
1095
1095
|
/**
|
|
1096
|
-
* A
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1096
|
+
* A page's Appear animations by element, running or finished and filling: one `getAnimations()` for every
|
|
1097
|
+
* element on it, for a Handoff of many elements at once. Each element's first: a member's Batch rule, or
|
|
1098
|
+
* the one `find` gets. The page is a document, or a shadow root: a document's read doesn't reach into its
|
|
1099
|
+
* shadow trees, so an element there is in its own root's (`element.getRootNode()`).
|
|
1099
1100
|
*/
|
|
1100
|
-
// #706
|
|
1101
|
-
//
|
|
1102
|
-
|
|
1101
|
+
// #706 Q3, #724: Chromium's `Element.getAnimations()` costs about a whole document's read each (1,000 Appear
|
|
1102
|
+
// elements in one parent: 5.4 s for all of them, the document's 15 ms). Firefox's and WebKit's are cheaper
|
|
1103
|
+
// than their document's (6.8 against 8.4 ms, 12 against 16), so they pay a little more for one read.
|
|
1104
|
+
export const findAll = (root: Document | ShadowRoot): ReadonlyMap<Element, Animation> => {
|
|
1103
1105
|
const byElement = new Map<Element, Animation>()
|
|
1104
|
-
if (Bool.not(Predicate.hasProperty(
|
|
1106
|
+
if (Bool.not(Predicate.hasProperty(root, "getAnimations"))) return byElement
|
|
1105
1107
|
// Once a Handoff, over the page's animations: the first per element, as `find`'s.
|
|
1106
|
-
Arr.forEach(Arr.filter(
|
|
1108
|
+
Arr.forEach(Arr.filter(root.getAnimations(), isAppearAnimation), (animation) =>
|
|
1107
1109
|
Option.map(Option.filter(targetOf(animation), (target) => Bool.not(byElement.has(target))), (target) => byElement.set(target, animation)))
|
|
1108
1110
|
return byElement
|
|
1109
1111
|
}
|
|
1110
1112
|
|
|
1113
|
+
/**
|
|
1114
|
+
* The element's own Appear animation in a page's read (`findAll`'s): the one `find` gets, with no read of
|
|
1115
|
+
* its own. A Batch's rule on a member's element isn't one.
|
|
1116
|
+
*/
|
|
1117
|
+
// #724: the element Handoff's lookup, every element hydrating in a pass from one read of its page. An
|
|
1118
|
+
// element runs one Appear animation at most, its inline slot's (a member's Batch rule vetoes its own, #706),
|
|
1119
|
+
// so `findAll`'s first is the one `find` would get.
|
|
1120
|
+
export const findIn = (animations: ReadonlyMap<Element, Animation>, element: Element): Option.Option<Animation> =>
|
|
1121
|
+
Option.filter(Option.fromUndefinedOr(animations.get(element)), isElementAppearAnimation)
|
|
1122
|
+
|
|
1111
1123
|
/** Whether `animation` is `spec`'s: the rule the server sampled from the same spec. */
|
|
1112
1124
|
export const matches = (animation: Animation, spec: Pick<Spec, "key" | "tag" | "infinite" | "projected">): boolean =>
|
|
1113
1125
|
Option.exists(nameOfAnimation(animation), (name) => name === nameOf(spec))
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Batch's Handoff (#706, ADR-0044 *Amendment (#706)*): its members' Appear animations read where they've
|
|
3
|
+
* got to, and let go, at the first step of the first change after they arrive. Loaded with `import()` the
|
|
4
|
+
* first time a hydrating Batch has a member running one (Q11), so a Batch that never takes one over ships
|
|
5
|
+
* none of it. Every DOM binding's Batch loads it.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// #672 (PR 5): solid's `batch-handoff.ts`, moved to dom's internal modules with the Batch, its one importer,
|
|
10
|
+
// which loads it at the page's first Handoff.
|
|
11
|
+
import * as Appear from "../Appear.ts"
|
|
12
|
+
import * as Effect from "effect/Effect"
|
|
13
|
+
import * as Iter from "effect/Iterable"
|
|
14
|
+
import * as Option from "effect/Option"
|
|
15
|
+
import * as Predicate from "effect/Predicate"
|
|
16
|
+
import * as AppearAnimations from "../unstable/AppearAnimations.ts"
|
|
17
|
+
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
18
|
+
|
|
19
|
+
/** A Batch's members running their Appear animation, as its Handoff reads them. */
|
|
20
|
+
export interface HandoffMembers {
|
|
21
|
+
/** Their slots: each one's taken over, or let go, at the change's first step. */
|
|
22
|
+
readonly appearing: ReadonlySet<number>
|
|
23
|
+
/** A slot's element, where it has one. */
|
|
24
|
+
readonly elementOf: (slot: number) => Element | undefined
|
|
25
|
+
/** In development, a member's own transitions' key, which its animation's rule is checked against (Q9). */
|
|
26
|
+
readonly keyOf: ((slot: number) => Option.Option<string>) | undefined
|
|
27
|
+
/** Where a rule another set of transitions named is noted, at Debug. */
|
|
28
|
+
readonly runtime: WardicServices.Runner<WardicServices.WardicServices>
|
|
29
|
+
/** Each member let go of its animation, once the step's starts are done: none waits for a step then. */
|
|
30
|
+
readonly release: () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A member's rule sampled from other transitions than the client's (ADR-0044 decision 6): noted, and taken over all the same. */
|
|
34
|
+
const MISMATCH = /*#__PURE__*/ Effect.logDebug("wardic.hydration: a Batch member's Appear animation was sampled from other transitions than the client's; it goes on from the same time")
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The Handoff's `startAt`, every change's until the first one's first step: a member running its Appear
|
|
38
|
+
* animation started where that has got to; any other, `NaN`, from its start. At the first member's first step, in the frame that draws it, every such
|
|
39
|
+
* member's time is read with the page's animations, all before any is let go: a release between two reads
|
|
40
|
+
* would have the second work the page's style out again. They're let go once the step's starts are done,
|
|
41
|
+
* in its task, so no paint falls between. In development, each rule is checked once against the member's
|
|
42
|
+
* own transitions (ADR-0044 decision 6): another is noted, and taken over all the same.
|
|
43
|
+
*/
|
|
44
|
+
export const startAtOf = (members: HandoffMembers): ((slot: number) => number) => {
|
|
45
|
+
let times: Map<number, number> | undefined = undefined
|
|
46
|
+
/** Every such member's time, read at once. */
|
|
47
|
+
const timesNow = (): Map<number, number> => {
|
|
48
|
+
const read = new Map<number, number>()
|
|
49
|
+
const checked = new Set<string>()
|
|
50
|
+
const keyOf = members.keyOf
|
|
51
|
+
// Once a Handoff, over its members (#665's per-member site): reads alone.
|
|
52
|
+
Iter.forEach(members.appearing, (slot) => {
|
|
53
|
+
const el = members.elementOf(slot)
|
|
54
|
+
if (Predicate.isUndefined(el)) return
|
|
55
|
+
const animation = AppearAnimations.pageAnimationsOf(el).get(el)
|
|
56
|
+
if (Predicate.isUndefined(animation)) return
|
|
57
|
+
const name = (animation as Animation & { readonly animationName: string }).animationName
|
|
58
|
+
if (Predicate.isNotUndefined(keyOf) && !checked.has(name)) {
|
|
59
|
+
checked.add(name)
|
|
60
|
+
if (!Option.exists(keyOf(slot), (key) => Appear.matchesBatch(animation, key))) members.runtime.runFork(MISMATCH)
|
|
61
|
+
}
|
|
62
|
+
read.set(slot, Appear.elapsedOf(animation))
|
|
63
|
+
})
|
|
64
|
+
// Every one let go once this step's starts are done, a member it didn't move among them.
|
|
65
|
+
queueMicrotask(members.release)
|
|
66
|
+
return read
|
|
67
|
+
}
|
|
68
|
+
// Per member at the change's first step: statements.
|
|
69
|
+
return (slot) => {
|
|
70
|
+
if (Predicate.isUndefined(times)) times = timesNow()
|
|
71
|
+
const time = times.get(slot)
|
|
72
|
+
if (Predicate.isUndefined(time)) return Number.NaN
|
|
73
|
+
return time
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -44,10 +44,10 @@ export const dragDefaultStyle: (axis: boolean | "x" | "y") => DragDefaultStyle =
|
|
|
44
44
|
* row vertical panning, and a grid none.
|
|
45
45
|
*/
|
|
46
46
|
// A **Reorder group**.
|
|
47
|
-
export const reorderTouchAction: (axis: "x" | "y" | "xy") => string = Match.type<"x" | "y" | "xy">().pipe(
|
|
48
|
-
Match.when("y", () => "pan-x"),
|
|
49
|
-
Match.when("x", () => "pan-y"),
|
|
50
|
-
Match.orElse(() => "none"),
|
|
47
|
+
export const reorderTouchAction: (axis: "x" | "y" | "xy") => string = /*#__PURE__*/ Match.type<"x" | "y" | "xy">().pipe(
|
|
48
|
+
/*#__PURE__*/ Match.when("y", () => "pan-x"),
|
|
49
|
+
/*#__PURE__*/ Match.when("x", () => "pan-y"),
|
|
50
|
+
/*#__PURE__*/ Match.orElse(() => "none"),
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
/** The attribute every drag element gets: no native drag of the element or its content. */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM's edges of the Flush gate (#672): an element's own inline value for a patch key, and the
|
|
3
|
+
* key the DOM's renderer reserves for an element's Transform template. `FlushGate.make` gives them to
|
|
4
|
+
* the gate it builds.
|
|
5
|
+
*/
|
|
6
|
+
// #672 (PR2-Q1): out of `gate.ts`, so the gate reads no DOM and moves to core as it is.
|
|
7
|
+
import * as Predicate from "effect/Predicate"
|
|
8
|
+
import type * as FlushGate from "@wardic/core/unstable/FlushGate"
|
|
9
|
+
import { TEMPLATE_KEY } from "./renderer.ts"
|
|
10
|
+
import { dashCase } from "./svg.ts"
|
|
11
|
+
|
|
12
|
+
/** The element's inline value for a patch key, before the gate writes it (`""` for none, or a target with no style). */
|
|
13
|
+
const valueBeforeOf = (target: unknown, key: string): string => {
|
|
14
|
+
if (Predicate.isNullish(target)) return ""
|
|
15
|
+
const style = (target as { readonly style?: CSSStyleDeclaration }).style
|
|
16
|
+
if (Predicate.isUndefined(style)) return ""
|
|
17
|
+
return style.getPropertyValue(dashCase(key))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The DOM's: its inline style, and its renderer's Transform template key. */
|
|
21
|
+
export const DOM_GATE: FlushGate.GateEnvironment = { valueBeforeOf, templateKey: TEMPLATE_KEY }
|
|
@@ -71,6 +71,7 @@ import type * as Arc from "@wardic/core/Arc"
|
|
|
71
71
|
import type * as Point from "@wardic/core/Point"
|
|
72
72
|
import * as Probe from "@wardic/core/Probe"
|
|
73
73
|
import * as Projection from "@wardic/core/Projection"
|
|
74
|
+
import * as Spans from "@wardic/core/Spans"
|
|
74
75
|
import * as Renderer from "@wardic/core/Renderer"
|
|
75
76
|
import * as Spring from "@wardic/core/Spring"
|
|
76
77
|
import * as Machine from "@wardic/core/Machine"
|
|
@@ -121,7 +122,7 @@ import {
|
|
|
121
122
|
import { DEFAULT_DRAG_TRANSITION, DEFAULT_LAYOUT_TRANSITION, type DragTransition, type LayoutTransition } from "./projection-defaults.ts"
|
|
122
123
|
import { counted, watchPage, type Watched } from "./content-watch.ts"
|
|
123
124
|
import { pending as appearRuns } from "./appear-slot.ts"
|
|
124
|
-
import
|
|
125
|
+
import * as Report from "@wardic/core/unstable/Report"
|
|
125
126
|
import { blendRadius, borderRadiusCorrector, isUnitScale, SCALE_CORRECTORS, type ScaleCorrector, type ScaleCorrectorEntry, scaleRadius, ZERO_RADIUS } from "./scale-correction.ts"
|
|
126
127
|
import { dashCase } from "./svg.ts"
|
|
127
128
|
|
|
@@ -1727,7 +1728,7 @@ export const makeProjectionSystem = (
|
|
|
1727
1728
|
const timing = timingOf(Option.getOrElse(node.transition(), () => DEFAULT_LAYOUT_TRANSITION))
|
|
1728
1729
|
return { position: 0, elapsed: 0, spring: Spring.init({}), timing, started: false, landed: false, curve: curveOf(node) }
|
|
1729
1730
|
} catch (defect) {
|
|
1730
|
-
runtime.runFork(
|
|
1731
|
+
runtime.runFork(Report.failure("wardic.projection: layout transition rejected", Cause.die(defect)))
|
|
1731
1732
|
return landedFlight()
|
|
1732
1733
|
}
|
|
1733
1734
|
},
|
|
@@ -1765,7 +1766,7 @@ export const makeProjectionSystem = (
|
|
|
1765
1766
|
try {
|
|
1766
1767
|
return releaseFrom(offset, velocity, transition)
|
|
1767
1768
|
} catch (defect) {
|
|
1768
|
-
runtime.runFork(
|
|
1769
|
+
runtime.runFork(Report.failure("wardic.projection: drag transition rejected", Cause.die(defect)))
|
|
1769
1770
|
return releaseFrom(ZERO_POINT, ZERO_POINT, DEFAULT_DRAG_TRANSITION)
|
|
1770
1771
|
}
|
|
1771
1772
|
}
|
|
@@ -1901,7 +1902,7 @@ export const makeProjectionSystem = (
|
|
|
1901
1902
|
* the logger is at Debug (observability convention: `wardic.*` + annotated debug
|
|
1902
1903
|
* logs on lifecycle; the per-frame derive/step hot path stays SILENT).
|
|
1903
1904
|
*/
|
|
1904
|
-
const debug = debugOf(runtime, "wardic.projection")
|
|
1905
|
+
const debug = Report.debugOf(runtime, "wardic.projection")
|
|
1905
1906
|
|
|
1906
1907
|
/**
|
|
1907
1908
|
* Run `expire` at the end of the current task — the next microtask checkpoint,
|
|
@@ -1925,9 +1926,9 @@ export const makeProjectionSystem = (
|
|
|
1925
1926
|
Microtask.next.pipe(
|
|
1926
1927
|
Effect.map(expire),
|
|
1927
1928
|
Effect.flatMap((outcome) => Effect.annotateCurrentSpan(outcome)),
|
|
1928
|
-
Effect.tapCause((cause) =>
|
|
1929
|
-
//
|
|
1930
|
-
|
|
1929
|
+
Effect.tapCause((cause) => Report.failure(`wardic.projection: ${span} failed`, cause)),
|
|
1930
|
+
// The app's to give, with no call-site stack (#746; ADR-0040, decision 2).
|
|
1931
|
+
Spans.withSpan(span, { attributes }),
|
|
1931
1932
|
),
|
|
1932
1933
|
),
|
|
1933
1934
|
)
|
|
@@ -3768,7 +3769,7 @@ export const makeProjectionSystem = (
|
|
|
3768
3769
|
try {
|
|
3769
3770
|
hook()
|
|
3770
3771
|
} catch (defect) {
|
|
3771
|
-
runtime.runFork(
|
|
3772
|
+
runtime.runFork(Report.failure(`wardic.projection: an ${name} failed`, Cause.die(defect)))
|
|
3772
3773
|
}
|
|
3773
3774
|
}
|
|
3774
3775
|
|
|
@@ -4328,7 +4329,7 @@ export const makeProjectionSystem = (
|
|
|
4328
4329
|
try {
|
|
4329
4330
|
listener()
|
|
4330
4331
|
} catch (defect) {
|
|
4331
|
-
runtime.runFork(
|
|
4332
|
+
runtime.runFork(Report.failure("wardic.projection: pass-end listener failed", Cause.die(defect)))
|
|
4332
4333
|
}
|
|
4333
4334
|
}
|
|
4334
4335
|
// This task's Declared layout changes settle once the flights this pass started have ended (#191).
|
|
@@ -4349,7 +4350,7 @@ export const makeProjectionSystem = (
|
|
|
4349
4350
|
blocked,
|
|
4350
4351
|
refresh: refreshed,
|
|
4351
4352
|
})
|
|
4352
|
-
}).pipe(
|
|
4353
|
+
}).pipe(Spans.withSpan("wardic.projection.measure"))
|
|
4353
4354
|
|
|
4354
4355
|
/**
|
|
4355
4356
|
* Whether a trigger now comes after its frame's tick and before its paint, known from where it runs
|
|
@@ -4429,7 +4430,7 @@ export const makeProjectionSystem = (
|
|
|
4429
4430
|
runtime.runFork(
|
|
4430
4431
|
Microtask.next.pipe(
|
|
4431
4432
|
Effect.andThen(measurePass),
|
|
4432
|
-
Effect.tapCause((cause) =>
|
|
4433
|
+
Effect.tapCause((cause) => Report.failure("wardic.projection: measure pass failed", cause)),
|
|
4433
4434
|
),
|
|
4434
4435
|
),
|
|
4435
4436
|
)
|
|
@@ -4440,7 +4441,7 @@ export const makeProjectionSystem = (
|
|
|
4440
4441
|
try {
|
|
4441
4442
|
callback()
|
|
4442
4443
|
} catch (defect) {
|
|
4443
|
-
runtime.runFork(
|
|
4444
|
+
runtime.runFork(Report.failure(`wardic.projection: ${name} failed`, Cause.die(defect)))
|
|
4444
4445
|
}
|
|
4445
4446
|
}
|
|
4446
4447
|
|
|
@@ -4527,7 +4528,7 @@ export const makeProjectionSystem = (
|
|
|
4527
4528
|
// A trigger from its flush is the end-of-task pass's, which the call queues.
|
|
4528
4529
|
triggeredDuringPass = false
|
|
4529
4530
|
return Effect.annotateCurrentSpan({ nodes: nodes.size, active: active.size })
|
|
4530
|
-
}).pipe(
|
|
4531
|
+
}).pipe(Spans.withSpan("wardic.projection.declared"))
|
|
4531
4532
|
|
|
4532
4533
|
/**
|
|
4533
4534
|
* The Measurements a task's first **Declared layout change** takes (#4): a Measure pass already due
|
|
@@ -4540,7 +4541,7 @@ export const makeProjectionSystem = (
|
|
|
4540
4541
|
if (resizeBlocked) return
|
|
4541
4542
|
const measure = Bool.match(passQueued, { onTrue: () => measurePass, onFalse: () => declaredMeasure })
|
|
4542
4543
|
const due = passQueued
|
|
4543
|
-
runtime.runSync(measure.pipe(Effect.catchCause((cause) =>
|
|
4544
|
+
runtime.runSync(measure.pipe(Effect.catchCause((cause) => Report.failure("wardic.projection: animateLayout's measure failed", cause))))
|
|
4544
4545
|
// The pass that ran was due at the end of the task: its queued fiber runs that pass now, after the callback.
|
|
4545
4546
|
if (due) passQueued = true
|
|
4546
4547
|
declared = true
|
|
@@ -5027,7 +5028,7 @@ export const makeProjectionSystem = (
|
|
|
5027
5028
|
FiberSet.addUnsafe(
|
|
5028
5029
|
taskFibers,
|
|
5029
5030
|
runtime.runFork(
|
|
5030
|
-
measurePass.pipe(Effect.tapCause((cause) =>
|
|
5031
|
+
measurePass.pipe(Effect.tapCause((cause) => Report.failure("wardic.projection: blocked pass failed", cause))),
|
|
5031
5032
|
),
|
|
5032
5033
|
)
|
|
5033
5034
|
}
|
|
@@ -5156,14 +5157,14 @@ export const makeProjectionSystem = (
|
|
|
5156
5157
|
* The coordinator's end, told apart (ADR-0027, decision 7): a settle, or an
|
|
5157
5158
|
* interruption (a stop outside its step, the system's dispose), is nothing; anything
|
|
5158
5159
|
* else (a step that threw, the Frame loop's own failure) is logged and reported
|
|
5159
|
-
* (`
|
|
5160
|
+
* (`Report.failure`, ADR-0030 decision 4). Its nodes then wait where the last step left
|
|
5160
5161
|
* them, and the next trigger starts a fresh run.
|
|
5161
5162
|
*/
|
|
5162
5163
|
const coordinatorEnded = (exit: Exit.Exit<unknown>): Effect.Effect<void> =>
|
|
5163
5164
|
Exit.match(exit, {
|
|
5164
5165
|
onSuccess: () => Effect.void,
|
|
5165
5166
|
onFailure: (cause) =>
|
|
5166
|
-
|
|
5167
|
+
Report.failure("wardic.projection: coordinator failed", cause).pipe(Effect.annotateLogs({ active: active.size })),
|
|
5167
5168
|
})
|
|
5168
5169
|
|
|
5169
5170
|
/** Whether the coordinator's run is on the Frame loop: its fiber is still in the handle. */
|
|
@@ -5631,13 +5632,13 @@ export const makeProjectionSystem = (
|
|
|
5631
5632
|
*/
|
|
5632
5633
|
const handleLeave: ProjectionSystem["handleLeave"] = (el, onDone) =>
|
|
5633
5634
|
runtime.runSync(
|
|
5634
|
-
Effect.sync(() => doHandleLeave(el, onDone)).pipe(
|
|
5635
|
+
Effect.sync(() => doHandleLeave(el, onDone)).pipe(Spans.withSpan("wardic.projection.handleLeave")),
|
|
5635
5636
|
)
|
|
5636
5637
|
|
|
5637
5638
|
const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone) =>
|
|
5638
5639
|
runtime.runSync(
|
|
5639
5640
|
Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone))).pipe(
|
|
5640
|
-
|
|
5641
|
+
Spans.withSpan("wardic.projection.handBackWithin"),
|
|
5641
5642
|
),
|
|
5642
5643
|
)
|
|
5643
5644
|
|
|
@@ -5683,7 +5684,7 @@ export const makeProjectionSystem = (
|
|
|
5683
5684
|
finishLeaver(node)
|
|
5684
5685
|
return Option.some(fade)
|
|
5685
5686
|
})
|
|
5686
|
-
).pipe(
|
|
5687
|
+
).pipe(Spans.withSpan("wardic.projection.dropLeaver")),
|
|
5687
5688
|
)
|
|
5688
5689
|
|
|
5689
5690
|
/** Whether a page box takes space in the flow (#261): read the first time it's asked, then kept. */
|
|
@@ -5764,7 +5765,7 @@ export const makeProjectionSystem = (
|
|
|
5764
5765
|
if (Bool.some([disposed, inPass, passQueued, resizeBlocked, nodes.size === 0])) return
|
|
5765
5766
|
refreshing = true
|
|
5766
5767
|
refreshResized = resized
|
|
5767
|
-
runtime.runSync(measurePass.pipe(Effect.catchCause((cause) =>
|
|
5768
|
+
runtime.runSync(measurePass.pipe(Effect.catchCause((cause) => Report.failure("wardic.projection: refresh failed", cause))))
|
|
5768
5769
|
}
|
|
5769
5770
|
|
|
5770
5771
|
/**
|
package/src/internal/renderer.ts
CHANGED
|
@@ -22,8 +22,10 @@ import type * as Point from "@wardic/core/Point"
|
|
|
22
22
|
import * as Projection from "@wardic/core/Projection"
|
|
23
23
|
import * as Renderer from "@wardic/core/Renderer"
|
|
24
24
|
import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.ts"
|
|
25
|
+
import * as Arr from "effect/Array"
|
|
25
26
|
import * as Bool from "effect/Boolean"
|
|
26
27
|
import * as Layer from "effect/Layer"
|
|
28
|
+
import * as Option from "effect/Option"
|
|
27
29
|
import * as Predicate from "effect/Predicate"
|
|
28
30
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
29
31
|
|
|
@@ -74,6 +76,18 @@ const isIdentity = (value: unknown, identity: number): boolean => {
|
|
|
74
76
|
return Predicate.isString(value) && Number.parseFloat(value) === identity
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Whether `key`'s `value` adds to the element's `transform` (#240): a transform key off its identity, a
|
|
81
|
+
* `transform` string, the projection's value or a Transform template. A Timeline value drawing
|
|
82
|
+
* `transform` runs only while nothing else does. Per frame: statements.
|
|
83
|
+
*/
|
|
84
|
+
export const addsToTransform = (key: string, value: unknown): boolean => {
|
|
85
|
+
if (key === Projection.KEY || key === TEMPLATE_KEY || key === "transform") return true
|
|
86
|
+
const identity = BaseValue.TRANSFORM_IDENTITY[key]
|
|
87
|
+
if (Predicate.isUndefined(identity)) return false
|
|
88
|
+
return !isIdentity(value, identity)
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
/** `value` when it's a number, else `fallback`. Per frame: an early return, no Option. */
|
|
78
92
|
const numberOr = (value: unknown, fallback: number): number => {
|
|
79
93
|
if (Predicate.isNumber(value)) return value
|
|
@@ -197,6 +211,14 @@ const formatTransformValue = (key: string, value: unknown): string => {
|
|
|
197
211
|
return String(value)
|
|
198
212
|
}
|
|
199
213
|
|
|
214
|
+
/**
|
|
215
|
+
* `key`'s own transform function for `value`, drawn even at its identity: a Timeline value's keyframe
|
|
216
|
+
* (#240), so each blends with its neighbours as one function, as the gate's values do. `None` for a key
|
|
217
|
+
* that isn't a transform key.
|
|
218
|
+
*/
|
|
219
|
+
export const transformFunctionOf = (key: string, value: unknown): Option.Option<string> =>
|
|
220
|
+
Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), ({ fn }) => `${fn}(${formatTransformValue(key, value)})`)
|
|
221
|
+
|
|
200
222
|
/** A transform key's default unit; none for a key the table doesn't name. */
|
|
201
223
|
// Exported for the Batch writer (#665).
|
|
202
224
|
export const unitOf = (key: string): TransformUnit => {
|
package/src/internal/reorder.ts
CHANGED
|
@@ -56,9 +56,9 @@ import * as Str from "effect/String"
|
|
|
56
56
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
57
57
|
import { documentOf, prepareAnnouncer } from "./announcer.ts"
|
|
58
58
|
import { type AutoScroller, makeAutoScroller } from "./auto-scroll.ts"
|
|
59
|
-
import
|
|
59
|
+
import * as Report from "@wardic/core/unstable/Report"
|
|
60
60
|
import { type Rect, revealLayoutOf, revealRectOf } from "./reveal.ts"
|
|
61
|
-
import type
|
|
61
|
+
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* The group element's style: no scroll anchoring, so the browser doesn't shift the
|
|
@@ -75,7 +75,7 @@ export const REORDER_GROUP_STYLE = Object.freeze({ "overflow-anchor": "none" } a
|
|
|
75
75
|
*/
|
|
76
76
|
export interface ReorderControllerWiring {
|
|
77
77
|
/** The runner the controller logs through and waits in. */
|
|
78
|
-
readonly runtime: Runner<never>
|
|
78
|
+
readonly runtime: WardicServices.Runner<never>
|
|
79
79
|
/** The app changed `values`: have the items laid out in it, a Measure pass, or nothing for items the binding places itself. */
|
|
80
80
|
readonly layOut: () => void
|
|
81
81
|
/** Speak an **Announcement**: the Environment's `Announcer`. Left out, nothing is announced. */
|
|
@@ -259,7 +259,7 @@ export interface ReorderController<V> {
|
|
|
259
259
|
/** Build a {@link ReorderController}: a **Reorder group** over `wiring.projection`'s nodes. */
|
|
260
260
|
export const makeReorderController = <V>(wiring: ReorderControllerWiring, options: ReorderControllerOptions<V>): ReorderController<V> => {
|
|
261
261
|
const { runtime, announce } = wiring
|
|
262
|
-
const debug = debugOf(runtime, "wardic.reorder")
|
|
262
|
+
const debug = Report.debugOf(runtime, "wardic.reorder")
|
|
263
263
|
// Speak an Announcement, or nothing without an `announce`.
|
|
264
264
|
const speak = UndefinedOr.match(announce, { onUndefined: () => constVoid, onDefined: identity })
|
|
265
265
|
const keyboardOn = (): boolean => UndefinedOr.match(options.keyboard, { onUndefined: constTrue, onDefined: (on) => on() })
|
package/src/internal/scroll.ts
CHANGED
|
@@ -31,6 +31,7 @@ import * as SharedSource from "@wardic/core/SharedSource"
|
|
|
31
31
|
import * as Arr from "effect/Array"
|
|
32
32
|
import * as Bool from "effect/Boolean"
|
|
33
33
|
import * as Effect from "effect/Effect"
|
|
34
|
+
import { identity } from "effect/Function"
|
|
34
35
|
import * as Iter from "effect/Iterable"
|
|
35
36
|
import * as Layer from "effect/Layer"
|
|
36
37
|
import * as Match from "effect/Match"
|
|
@@ -111,8 +112,8 @@ const pairOf: (stop: ScrollOffset.Stop) => Pair = Match.type<ScrollOffset.Stop>(
|
|
|
111
112
|
Match.orElse((pair) => pair as Pair),
|
|
112
113
|
)
|
|
113
114
|
|
|
114
|
-
/** A stop as a scroll position: where the target's edge meets the container's. */
|
|
115
|
-
const positionOf = (stop: ScrollOffset.Stop, containerLength: number, targetLength: number, targetInset: number): number => {
|
|
115
|
+
/** A stop as a scroll position: where the target's edge meets the container's. A Timeline value probes it for its range (#240). */
|
|
116
|
+
export const positionOf = (stop: ScrollOffset.Stop, containerLength: number, targetLength: number, targetInset: number): number => {
|
|
116
117
|
const [target, container] = pairOf(stop)
|
|
117
118
|
return targetInset + edgeOffset({ edge: target, length: targetLength }) - edgeOffset({ edge: container, length: containerLength })
|
|
118
119
|
}
|
|
@@ -186,7 +187,8 @@ const insetOf = (element: Element | null, container: Element, x: number, y: numb
|
|
|
186
187
|
return { x, y }
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
|
|
190
|
+
/** Whether `u` is an HTML element: what a Timeline value's target must be too (#240). */
|
|
191
|
+
export const isHTMLElement = (u: unknown): u is HTMLElement => u instanceof HTMLElement
|
|
190
192
|
|
|
191
193
|
/**
|
|
192
194
|
* `x`, `y` from `parent`, where the offset chain left `container`, made `container`'s: its own offset
|
|
@@ -219,17 +221,30 @@ const sizeOf = (target: Element): { readonly width: number; readonly height: num
|
|
|
219
221
|
/** A container's progress on one axis with no target or offset: Motion's `progress(0, length, current)`, 1 for no range. */
|
|
220
222
|
const plainProgress = (current: number, length: number): number => Bool.match(length === 0, { onTrue: () => 1, onFalse: () => current / length })
|
|
221
223
|
|
|
224
|
+
/** `options`' offset, the DOM's (core passes it through as the Environment's own): `All` with a target and none. */
|
|
225
|
+
export const offsetOf = (options: ScrollSource.Options): ScrollOffset.ScrollOffset =>
|
|
226
|
+
UndefinedOr.match(options.offset as ScrollOffset.ScrollOffset | undefined, { onUndefined: () => ScrollOffset.All, onDefined: identity })
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Whether `options`' progress on `axis` runs through its offsets: with a target or an offset, on the
|
|
230
|
+
* options' own axis (`"y"` when left out). Else it's the container's plain progress. A Timeline value
|
|
231
|
+
* reads it as a reader does (#240).
|
|
232
|
+
*/
|
|
233
|
+
export const resolvesOn = (options: ScrollSource.Options, axis: "x" | "y"): boolean =>
|
|
234
|
+
Bool.and(
|
|
235
|
+
Bool.or(Predicate.isNotUndefined(options.target), Predicate.isNotUndefined(options.offset)),
|
|
236
|
+
UndefinedOr.match(options.axis, { onUndefined: () => "y", onDefined: identity }) === axis,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
/** An element's client size on `axis`: a container's length, as a reader and a Timeline value read it. */
|
|
240
|
+
export const clientLengthOf = (element: Element, axis: "x" | "y"): number =>
|
|
241
|
+
Bool.match(axis === "y", { onTrue: () => element.clientHeight, onFalse: () => element.clientWidth })
|
|
242
|
+
|
|
222
243
|
/** What a reader measures, for `options` on `element`. Reads layout: called in events, never per frame. */
|
|
223
244
|
const measureOf = (element: Element, options: ScrollSource.Options): (() => ScrollSource.Scroll) => {
|
|
224
245
|
const { axis = "y" } = options
|
|
225
|
-
|
|
226
|
-
const offset = UndefinedOr.match(options.offset as ScrollOffset.ScrollOffset | undefined, {
|
|
227
|
-
onUndefined: () => ScrollOffset.All,
|
|
228
|
-
onDefined: (given) => given,
|
|
229
|
-
})
|
|
246
|
+
const offset = offsetOf(options)
|
|
230
247
|
const target = UndefinedOr.match(options.target as Element | undefined, { onUndefined: () => element, onDefined: (given) => given })
|
|
231
|
-
// A target's progress, or an offset's through the container itself; else the plain one.
|
|
232
|
-
const resolves = Bool.or(Predicate.isNotUndefined(options.target), Predicate.isNotUndefined(options.offset))
|
|
233
248
|
const onAxis = (current: number): number => {
|
|
234
249
|
const own = target === element
|
|
235
250
|
const inset = Bool.match(own, { onTrue: (): Point => ({ x: 0, y: 0 }), onFalse: () => insetOf(target, element, 0, 0) })
|
|
@@ -238,20 +253,22 @@ const measureOf = (element: Element, options: ScrollSource.Options): (() => Scro
|
|
|
238
253
|
onFalse: () => sizeOf(target),
|
|
239
254
|
})
|
|
240
255
|
const y = axis === "y"
|
|
241
|
-
const containerLength =
|
|
256
|
+
const containerLength = clientLengthOf(element, axis)
|
|
242
257
|
const targetLength = Bool.match(y, { onTrue: () => size.height, onFalse: () => size.width })
|
|
243
258
|
const targetInset = Bool.match(y, { onTrue: () => inset.y, onFalse: () => inset.x })
|
|
244
259
|
return progressThrough(Arr.map(offset, (stop) => positionOf(stop, containerLength, targetLength, targetInset)), current)
|
|
245
260
|
}
|
|
261
|
+
// A target's progress, or an offset's through the container itself, on its axis; else the plain one.
|
|
262
|
+
const onX = resolvesOn(options, "x")
|
|
263
|
+
const onY = resolvesOn(options, "y")
|
|
246
264
|
return () => {
|
|
247
265
|
const x = Math.abs(element.scrollLeft)
|
|
248
266
|
const y = Math.abs(element.scrollTop)
|
|
249
267
|
const xLength = element.scrollWidth - element.clientWidth
|
|
250
268
|
const yLength = element.scrollHeight - element.clientHeight
|
|
251
|
-
const resolvesOn = (on: "x" | "y"): boolean => Bool.and(resolves, axis === on)
|
|
252
269
|
return {
|
|
253
|
-
x: { current: x, length: xLength, progress: Bool.match(
|
|
254
|
-
y: { current: y, length: yLength, progress: Bool.match(
|
|
270
|
+
x: { current: x, length: xLength, progress: Bool.match(onX, { onTrue: () => onAxis(x), onFalse: () => plainProgress(x, xLength) }) },
|
|
271
|
+
y: { current: y, length: yLength, progress: Bool.match(onY, { onTrue: () => onAxis(y), onFalse: () => plainProgress(y, yLength) }) },
|
|
255
272
|
}
|
|
256
273
|
}
|
|
257
274
|
}
|
|
@@ -271,7 +288,7 @@ const sameScroll = (a: ScrollSource.Scroll, b: ScrollSource.Scroll): boolean =>
|
|
|
271
288
|
)
|
|
272
289
|
|
|
273
290
|
/** The page's scroller: `document.scrollingElement`, else the root element. */
|
|
274
|
-
const pageOf = (): Element => Option.getOrElse(Option.fromNullOr(document.scrollingElement), () => document.documentElement)
|
|
291
|
+
export const pageOf = (): Element => Option.getOrElse(Option.fromNullOr(document.scrollingElement), () => document.documentElement)
|
|
275
292
|
|
|
276
293
|
/** A container's listener set, opened for its first reader. */
|
|
277
294
|
const open = (element: Element): Container => {
|