@wardic/dom 1.3.2 → 1.5.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Color.d.ts +2 -1
- package/dist/Color.d.ts.map +1 -1
- package/dist/Color.js +3 -1
- package/dist/Color.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/batch-writer.d.ts.map +1 -1
- package/dist/internal/batch-writer.js +9 -13
- package/dist/internal/batch-writer.js.map +1 -1
- package/dist/internal/clock.d.ts +3 -3
- package/dist/internal/clock.d.ts.map +1 -1
- package/dist/internal/clock.js +25 -7
- package/dist/internal/clock.js.map +1 -1
- package/dist/internal/colorSpaces.d.ts +8 -0
- package/dist/internal/colorSpaces.d.ts.map +1 -0
- package/dist/internal/colorSpaces.js +26 -0
- package/dist/internal/colorSpaces.js.map +1 -0
- package/dist/internal/colors.d.ts +0 -7
- package/dist/internal/colors.d.ts.map +1 -1
- package/dist/internal/colors.js +3 -15
- package/dist/internal/colors.js.map +1 -1
- package/dist/internal/default-transition.d.ts +2 -2
- package/dist/internal/default-transition.d.ts.map +1 -1
- package/dist/internal/default-transition.js +23 -9
- package/dist/internal/default-transition.js.map +1 -1
- package/dist/internal/input.d.ts.map +1 -1
- package/dist/internal/input.js +18 -0
- package/dist/internal/input.js.map +1 -1
- package/dist/internal/layout-box.d.ts +29 -0
- package/dist/internal/layout-box.d.ts.map +1 -0
- package/dist/internal/layout-box.js +48 -0
- package/dist/internal/layout-box.js.map +1 -0
- package/dist/internal/measure.d.ts +1 -19
- package/dist/internal/measure.d.ts.map +1 -1
- package/dist/internal/measure.js +4 -47
- package/dist/internal/measure.js.map +1 -1
- package/dist/internal/projection.d.ts +5 -1
- package/dist/internal/projection.d.ts.map +1 -1
- package/dist/internal/projection.js +45 -10
- package/dist/internal/projection.js.map +1 -1
- package/dist/internal/renderer.d.ts +36 -14
- package/dist/internal/renderer.d.ts.map +1 -1
- package/dist/internal/renderer.js +213 -118
- package/dist/internal/renderer.js.map +1 -1
- package/dist/internal/reorder.d.ts +7 -0
- package/dist/internal/reorder.d.ts.map +1 -1
- package/dist/internal/reorder.js +41 -21
- package/dist/internal/reorder.js.map +1 -1
- package/dist/internal/starting-style.js +5 -5
- package/dist/internal/transform-keys.d.ts +3 -2
- package/dist/internal/transform-keys.d.ts.map +1 -1
- package/dist/internal/transform-keys.js +21 -9
- package/dist/internal/transform-keys.js.map +1 -1
- package/dist/unstable/BatchMembers.js +1 -1
- package/dist/unstable/DragTrack.d.ts +1 -1
- package/dist/unstable/DragTrack.d.ts.map +1 -1
- package/dist/unstable/DragTrack.js +16 -4
- package/dist/unstable/DragTrack.js.map +1 -1
- package/dist/unstable/ElementSetup.js +1 -1
- package/dist/unstable/Feature.d.ts +3 -2
- package/dist/unstable/Feature.d.ts.map +1 -1
- package/dist/unstable/Feature.js +3 -2
- package/dist/unstable/Feature.js.map +1 -1
- package/dist/unstable/GestureFeatures.d.ts +6 -1
- package/dist/unstable/GestureFeatures.d.ts.map +1 -1
- package/dist/unstable/GestureFeatures.js +8 -3
- package/dist/unstable/GestureFeatures.js.map +1 -1
- package/dist/unstable/GestureInfo.d.ts +11 -0
- package/dist/unstable/GestureInfo.d.ts.map +1 -1
- package/dist/unstable/GestureInfo.js +8 -0
- package/dist/unstable/GestureInfo.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +1 -1
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MemberHold.js +1 -1
- package/dist/unstable/MemberHold.js.map +1 -1
- package/dist/unstable/PresenceController.d.ts +36 -0
- package/dist/unstable/PresenceController.d.ts.map +1 -1
- package/dist/unstable/PresenceController.js +41 -17
- package/dist/unstable/PresenceController.js.map +1 -1
- package/dist/unstable/WardConfig.d.ts +5 -5
- package/dist/unstable/WardConfig.d.ts.map +1 -1
- package/dist/unstable/features/TimelineKeys.js +1 -1
- package/package.json +3 -3
- package/src/Color.ts +2 -1
- package/src/index.ts +2 -2
- package/src/internal/batch-writer.ts +9 -14
- package/src/internal/clock.ts +25 -7
- package/src/internal/colorSpaces.ts +27 -0
- package/src/internal/colors.ts +3 -36
- package/src/internal/default-transition.ts +22 -8
- package/src/internal/input.ts +18 -0
- package/src/internal/layout-box.ts +57 -0
- package/src/internal/measure.ts +4 -47
- package/src/internal/projection.ts +58 -12
- package/src/internal/renderer.ts +243 -122
- package/src/internal/reorder.ts +51 -24
- package/src/internal/starting-style.ts +5 -5
- package/src/internal/transform-keys.ts +21 -9
- package/src/unstable/BatchMembers.ts +1 -1
- package/src/unstable/DragTrack.ts +25 -5
- package/src/unstable/ElementSetup.ts +1 -1
- package/src/unstable/Feature.ts +4 -3
- package/src/unstable/GestureFeatures.ts +15 -3
- package/src/unstable/GestureInfo.ts +24 -0
- package/src/unstable/Imperative.ts +1 -0
- package/src/unstable/MemberHold.ts +1 -1
- package/src/unstable/PresenceController.ts +42 -19
- package/src/unstable/WardConfig.ts +5 -5
- package/src/unstable/features/TimelineKeys.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ import * as DomProbe from "./DomProbe.ts"
|
|
|
39
39
|
import * as DomRenderer from "./DomRenderer.ts"
|
|
40
40
|
import { LateFramesDomLive } from "./internal/clock.ts"
|
|
41
41
|
|
|
42
|
-
export const VERSION = "1.
|
|
42
|
+
export const VERSION = "1.5.0-next.0"
|
|
43
43
|
|
|
44
44
|
export * as DomBatch from "./DomBatch.ts"
|
|
45
45
|
export * as DomClock from "./DomClock.ts"
|
|
@@ -124,7 +124,7 @@ export const DomLive: Layer.Layer<
|
|
|
124
124
|
| Announcer.Announcer
|
|
125
125
|
| AtomRegistry.AtomRegistry
|
|
126
126
|
> = FrameLoop.layer.pipe(
|
|
127
|
-
// A frame a long task
|
|
127
|
+
// A frame a long task delayed, told by when its callback ran (#1026): its lateness left out of a new run's first steps.
|
|
128
128
|
Layer.provide(LateFramesDomLive),
|
|
129
129
|
Layer.provideMerge(
|
|
130
130
|
Layer.mergeAll(DomClock.layer, DomRenderer.layer, DomProbe.layer, DomInterpolators.layer, DomPositionalKeys.layer, DomDefaultTransition.layer, DomAnnouncer.layer),
|
|
@@ -13,7 +13,7 @@ import * as Bool from "effect/Boolean"
|
|
|
13
13
|
import * as Option from "effect/Option"
|
|
14
14
|
import * as Predicate from "effect/Predicate"
|
|
15
15
|
import * as Result from "effect/Result"
|
|
16
|
-
import {
|
|
16
|
+
import { DEPTH_FUNC, TRANSFORM_FUNCS } from "./renderer.ts"
|
|
17
17
|
import * as TransformKeys from "./transform-keys.ts"
|
|
18
18
|
|
|
19
19
|
/** A transform function a Batch writes: its key's index in the Batch, what goes either side of its value, and its identity. */
|
|
@@ -24,27 +24,22 @@ interface Part {
|
|
|
24
24
|
readonly identity: number
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The transform functions a member draws, each with what goes either side of its value and its identity: the
|
|
29
|
+
* renderer's, less a path's turn, which an arc's element draws (#438). What `forKeys` and `styleOf` draw.
|
|
30
|
+
*/
|
|
28
31
|
const FUNCS = Arr.filter(TRANSFORM_FUNCS, (func) => func.key !== "pathRotation")
|
|
29
32
|
|
|
30
33
|
/** The keys the DOM's writer draws: those transform keys and `opacity`. */
|
|
31
34
|
const DRAWS: ReadonlySet<string> = new Set([...Arr.map(FUNCS, (func) => func.key), "opacity"])
|
|
32
35
|
|
|
33
|
-
/** Each transform function's key, what goes either side of its value, and its identity, in the renderer's order: what `forKeys` and `styleOf` draw. */
|
|
34
|
-
const FUNC_PARTS: ReadonlyArray<Omit<Part, "k"> & { readonly key: string }> = Arr.map(FUNCS, (func) => ({
|
|
35
|
-
key: func.key,
|
|
36
|
-
open: `${func.fn}(`,
|
|
37
|
-
close: `${unitOf(func.key)})`,
|
|
38
|
-
identity: func.identity,
|
|
39
|
-
}))
|
|
40
|
-
|
|
41
36
|
/** What a member's write walks: every part but the element's own depth, which it writes ahead of them. */
|
|
42
37
|
// #887 (ADR-0073, *Amendment (#887)*, Q8), as the renderer's walk.
|
|
43
|
-
const WALKED_PARTS = Arr.filter(
|
|
38
|
+
const WALKED_PARTS = Arr.filter(FUNCS, (part) => part.key !== TransformKeys.PERSPECTIVE)
|
|
44
39
|
|
|
45
40
|
/** What goes either side of a member's own depth in its write. */
|
|
46
|
-
const DEPTH_OPEN =
|
|
47
|
-
const DEPTH_CLOSE =
|
|
41
|
+
const DEPTH_OPEN = DEPTH_FUNC.open
|
|
42
|
+
const DEPTH_CLOSE = DEPTH_FUNC.close
|
|
48
43
|
|
|
49
44
|
/** A Batch's write, for its keys in their order: built once, when the Batch is made. */
|
|
50
45
|
const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64Array, base: number) => void) => {
|
|
@@ -95,7 +90,7 @@ const forKeys = (keys: ReadonlyArray<string>): ((el: Element, positions: Float64
|
|
|
95
90
|
export const styleOf = (values: Readonly<Record<string, number>>): Readonly<Record<string, string>> => {
|
|
96
91
|
const style: Record<string, string> = {}
|
|
97
92
|
// Once a member on a server: in the renderer's order, as `forKeys`' write.
|
|
98
|
-
const functions = Arr.filterMap(
|
|
93
|
+
const functions = Arr.filterMap(FUNCS, (part) => {
|
|
99
94
|
const value = values[part.key]
|
|
100
95
|
if (Bool.or(Predicate.isUndefined(value), value === part.identity)) return Result.failVoid
|
|
101
96
|
if (part.key === TransformKeys.PERSPECTIVE) {
|
package/src/internal/clock.ts
CHANGED
|
@@ -48,11 +48,29 @@ export const ClockDomLive: Layer.Layer<Clock.Clock | RefreshFrameSource.RefreshF
|
|
|
48
48
|
)
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* The DOM's late frames, for its Frame loop (`Clock.LateFrames
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* The DOM's late frames, for its Frame loop (`Clock.LateFrames`): `requestAnimationFrame`'s timestamps are on
|
|
52
|
+
* `performance.now()`'s timebase, the Clock's `now()`, so a frame whose callback ran more than 25 ms after its
|
|
53
|
+
* timestamp was delayed by a long task.
|
|
54
54
|
*/
|
|
55
|
-
//
|
|
56
|
-
// `resolve-start-time.mjs`)
|
|
57
|
-
//
|
|
58
|
-
|
|
55
|
+
// #1026; 25 ms since #1028 (Q11), 40 before, Motion's line for "main thread work" (`MAX_START_DELAY`,
|
|
56
|
+
// motion-dom 14.6 `resolve-start-time.mjs`). ADR-0027 *Amendment (#1028)* has the sources (Chromium's
|
|
57
|
+
// `time_clamper.cc` and `page_animator.cc`, Firefox's `Performance.cpp` and `nsRFPService.cpp`, Brave's
|
|
58
|
+
// `time_clamper.cc`, Tor Browser's base profile).
|
|
59
|
+
// - On time, a frame's callback reads less than 3 ms after its timestamp in Chrome, Safari and Brave, and in
|
|
60
|
+
// Firefox at its defaults or with its fingerprinting protection. With `privacy.resistFingerprinting` (Tor
|
|
61
|
+
// Browser's), both clocks sit on a 16.7 ms grid with jitter: 16.7 ms often, 33.3 rarely (late, at 25), never
|
|
62
|
+
// 50. Only a 100 ms clamp misreads past 40 (resistFingerprinting before Firefox 102, or a raised
|
|
63
|
+
// `privacy.reduceTimerPrecision.microseconds`), which 40 didn't guard against either.
|
|
64
|
+
// - Why 25: past resistFingerprinting's common 16.7 ms reading, and short of two 60 Hz frames (33.3 ms) by
|
|
65
|
+
// more than a frame's jitter.
|
|
66
|
+
// - What 25 catches (measured in Chromium at 60 Hz): the frame after a held one is stamped at the last vsync
|
|
67
|
+
// the held one ran past. A frame held 33.3–40 ms, past two frames, is followed by one whose dt holds a frame
|
|
68
|
+
// of the task's time, which a new row's fade took at its second frame at 40, 0.06 → 0.17 (Solid's HL3). One
|
|
69
|
+
// held 25–33 ms is followed by one stamped a frame after it, whose dt holds none. Faster displays' two frames
|
|
70
|
+
// are shorter, so there a 25–33 ms hold hitches too, and 25 catches it.
|
|
71
|
+
// - What 25 costs: nothing at 60 Hz or faster, since the rule leaves a step of a 60 Hz frame or less alone.
|
|
72
|
+
// Slower, a misread trims one step of a new run to 1/60 s: no jump, it lands half a frame later. Telling a
|
|
73
|
+
// frame late is the line's one use: since #1050 a frame a long task delayed is told by its gap too (core's
|
|
74
|
+
// `FirstSteps.lateByGap`), which WebKit and Gecko need, stamping a late frame near when it ran, so that it
|
|
75
|
+
// never reads late. Before, the line also trimmed a run that waited past it for its first frame (#1048).
|
|
76
|
+
export const LateFramesDomLive = Layer.succeed(Clock.LateFrames, { ranAfter: 25 })
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every CSS colour space beyond sRGB's syntaxes, in a module of its own (probe: hooks-first), apart
|
|
3
|
+
* from `colors.ts`, which every app loads. A bundler splits by module, not by function: with the
|
|
4
|
+
* spaces in `colors.ts`, a page that might fetch the `colors` Feature later carried all of them in its
|
|
5
|
+
* first chunk, 13 KB minified, since the module they sat in was already there.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/// <reference path="./culori.d.ts" />
|
|
10
|
+
import { modeA98, modeHwb, modeLab, modeLch, modeLrgb, modeOklab, modeOklch, modeP3, modeProphoto, modeRec2020, modeXyz50, modeXyz65, useMode } from "culori/fn"
|
|
11
|
+
import * as Arr from "effect/Array"
|
|
12
|
+
|
|
13
|
+
const CSS_SPACES = [modeA98, modeHwb, modeLab, modeLch, modeLrgb, modeOklab, modeOklch, modeP3, modeProphoto, modeRec2020, modeXyz50, modeXyz65]
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Registers every CSS colour space beyond sRGB's syntaxes: `lab()`, `lch()`, `oklab()`, `oklch()`,
|
|
17
|
+
* `hwb()`, and `color()`'s `display-p3`, `rec2020`, `a98-rgb`, `prophoto-rgb`, `srgb-linear`, `xyz`,
|
|
18
|
+
* `xyz-d50` and `xyz-d65`. From then on such a string is a colour everywhere on the page; before, it
|
|
19
|
+
* isn't one, and a `lab()` value's numbers blend as written. Calling it again does nothing new.
|
|
20
|
+
*/
|
|
21
|
+
// #511, ADR-0067 decision 5: the spaces culori's `culori/css` registers but for its non-CSS `hsv`, `lab65`
|
|
22
|
+
// and `lch65`. The `colors` Feature's.
|
|
23
|
+
export const registerSpaces = (): void => {
|
|
24
|
+
Arr.forEach(CSS_SPACES, (mode) => {
|
|
25
|
+
useMode(mode)
|
|
26
|
+
})
|
|
27
|
+
}
|
package/src/internal/colors.ts
CHANGED
|
@@ -14,27 +14,7 @@
|
|
|
14
14
|
* @module
|
|
15
15
|
*/
|
|
16
16
|
/// <reference path="./culori.d.ts" />
|
|
17
|
-
import {
|
|
18
|
-
formatRgb,
|
|
19
|
-
getMode,
|
|
20
|
-
interpolate as culoriInterpolate,
|
|
21
|
-
modeA98,
|
|
22
|
-
modeHsl,
|
|
23
|
-
modeHwb,
|
|
24
|
-
modeLab,
|
|
25
|
-
modeLch,
|
|
26
|
-
modeLrgb,
|
|
27
|
-
modeOklab,
|
|
28
|
-
modeOklch,
|
|
29
|
-
modeP3,
|
|
30
|
-
modeProphoto,
|
|
31
|
-
modeRec2020,
|
|
32
|
-
modeRgb,
|
|
33
|
-
modeXyz50,
|
|
34
|
-
modeXyz65,
|
|
35
|
-
parse as culoriParse,
|
|
36
|
-
useMode,
|
|
37
|
-
} from "culori/fn"
|
|
17
|
+
import { formatRgb, getMode, interpolate as culoriInterpolate, modeHsl, modeRgb, parse as culoriParse, useMode } from "culori/fn"
|
|
38
18
|
import type * as Interpolator from "@wardic/core/Interpolator"
|
|
39
19
|
import * as Scalar from "@wardic/core/Scalar"
|
|
40
20
|
import * as Arr from "effect/Array"
|
|
@@ -95,19 +75,8 @@ export const formatColor = (color: Color): string => formatRgb(color)
|
|
|
95
75
|
const toRgb = useMode(modeRgb)
|
|
96
76
|
useMode(modeHsl)
|
|
97
77
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* `hwb()`, and `color()`'s `display-p3`, `rec2020`, `a98-rgb`, `prophoto-rgb`, `srgb-linear`, `xyz`,
|
|
101
|
-
* `xyz-d50` and `xyz-d65`. From then on such a string is a colour everywhere on the page; before, it
|
|
102
|
-
* isn't one, and a `lab()` value's numbers blend as written. Calling it again does nothing new.
|
|
103
|
-
*/
|
|
104
|
-
// #511, ADR-0067 decision 5: the spaces culori's `culori/css` registers but for its non-CSS `hsv`, `lab65`
|
|
105
|
-
// and `lch65`. The `colors` Feature's.
|
|
106
|
-
export const registerSpaces = (): void => {
|
|
107
|
-
Arr.forEach(CSS_SPACES, (mode) => {
|
|
108
|
-
useMode(mode)
|
|
109
|
-
})
|
|
110
|
-
}
|
|
78
|
+
// `registerSpaces`, which registers every other CSS colour space, is `colorSpaces.ts`'s (probe:
|
|
79
|
+
// hooks-first): the `colors` Feature's alone, in a module only it loads.
|
|
111
80
|
|
|
112
81
|
/**
|
|
113
82
|
* Whether the spaces `registerSpaces` registers are registered on the page: by it, or by culori's own
|
|
@@ -116,8 +85,6 @@ export const registerSpaces = (): void => {
|
|
|
116
85
|
// Asked of culori's registry, the page's.
|
|
117
86
|
export const spacesRegistered = (): boolean => Predicate.isNotUndefined(getMode("oklch"))
|
|
118
87
|
|
|
119
|
-
const CSS_SPACES = [modeA98, modeHwb, modeLab, modeLch, modeLrgb, modeOklab, modeOklch, modeP3, modeProphoto, modeRec2020, modeXyz50, modeXyz65]
|
|
120
|
-
|
|
121
88
|
/** A colour's four channels, resolved once: what the frame lerps. */
|
|
122
89
|
interface Channels {
|
|
123
90
|
readonly r: number
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* The DOM Environment's Default transition (CONTEXT.md; ADR-0051, #357): Motion's, by value
|
|
3
3
|
* (`.reference/motion` at 16c6122, `motion-dom/src/animation/utils/default-transitions.ts`,
|
|
4
4
|
* `getDefaultTransition`):
|
|
5
|
-
* - a transform but a scale, the
|
|
6
|
-
* 500 / 25, at rest under 10 px/s;
|
|
5
|
+
* - a transform but a scale, the DOM's own among them (`translateX`, `rotate`, `skewX`, the element's
|
|
6
|
+
* own depth `transformPerspective`…): a spring, 500 / 25, at rest under 10 px/s;
|
|
7
7
|
* - `scale`, `scaleX`, `scaleY`: a spring, 550, critically damped toward 0 (2·√550), else 30;
|
|
8
8
|
* - anything else (opacity, colours, a box's size, a filter): a 0.3 s tween on
|
|
9
9
|
* `cubic-bezier(0.25, 0.1, 0.35, 1)`, "a slightly shallower version of the browser's default ease".
|
|
@@ -18,20 +18,34 @@
|
|
|
18
18
|
// #882 (ADR-0073, *Amendment (#882)*, Q2): core's table, `DefaultTransition.byKey`, the same objects.
|
|
19
19
|
import * as DefaultTransition from "@wardic/core/DefaultTransition"
|
|
20
20
|
import * as Layer from "effect/Layer"
|
|
21
|
+
import * as Predicate from "effect/Predicate"
|
|
21
22
|
import * as TransformKeys from "./transform-keys.ts"
|
|
22
23
|
|
|
23
24
|
/** The transition through more than two keyframes, as Motion's `keyframesTransition`: a 0.8 s tween, eased out. */
|
|
24
25
|
export const keyframes: DefaultTransition.KeyframesTransition = DefaultTransition.KEYFRAMES_TWEEN
|
|
25
26
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The key of core's each of the DOM's own transform keys runs as: its twin, a translation's or a turn's.
|
|
29
|
+
* The element's own depth runs as a turn's, so a depth and a turn leaving together decay in step.
|
|
30
|
+
*/
|
|
31
|
+
// #887 (ADR-0073, *Amendment (#887)*, Q10): core's `byKey` knows core's transforms; the DOM's own take a
|
|
32
|
+
// twin's, the same object. #1002 (*Amendment (#1002)*, Q3): the six core named until then.
|
|
33
|
+
const RUNS_AS: ReadonlyMap<string, string> = new Map([
|
|
34
|
+
["translateX", "x"],
|
|
35
|
+
["translateY", "y"],
|
|
36
|
+
["translateZ", "z"],
|
|
37
|
+
["rotate", "rotateZ"],
|
|
38
|
+
["skewX", "rotateZ"],
|
|
39
|
+
["skewY", "rotateZ"],
|
|
40
|
+
[TransformKeys.PERSPECTIVE, "rotateY"],
|
|
41
|
+
])
|
|
28
42
|
|
|
29
43
|
/** The transition `key` runs on toward `target` when its own isn't defined, in the DOM: Motion's. */
|
|
30
|
-
//
|
|
31
|
-
// a turn's, the same object.
|
|
44
|
+
// Per key per Retarget: statements (docs/agents/effect-first.md, the hot path).
|
|
32
45
|
export const transitionFor = (key: string, target: number | string): DefaultTransition.Transition => {
|
|
33
|
-
|
|
34
|
-
return DefaultTransition.byKey(key, target)
|
|
46
|
+
const twin = RUNS_AS.get(key)
|
|
47
|
+
if (Predicate.isUndefined(twin)) return DefaultTransition.byKey(key, target)
|
|
48
|
+
return DefaultTransition.byKey(twin, target)
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
/** The DOM Environment's `DefaultTransition.DefaultTransition`. */
|
package/src/internal/input.ts
CHANGED
|
@@ -504,6 +504,23 @@ const focusWithin = (target: unknown): boolean => {
|
|
|
504
504
|
return (target as Node).contains(active)
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
/**
|
|
508
|
+
* The focus on `target` now, or inside it, as its focus feed would tell it (core's `InputSource.focusNow`):
|
|
509
|
+
* shown as the element focus is on shows it, the target's own when it's that element. `None` while focus
|
|
510
|
+
* is neither on it nor inside it.
|
|
511
|
+
*/
|
|
512
|
+
// Probe: hooks-first, the Reorder round's RF4. As `focusAmongOf` tells a member a focus already within it.
|
|
513
|
+
const focusNow = (target: unknown): Option.Option<InputSource.FocusLikeEvent> => {
|
|
514
|
+
if (Bool.not(focusWithin(target))) return Option.none()
|
|
515
|
+
const win = windowOf(target)
|
|
516
|
+
return Option.map(Option.fromNullOr(deepActiveOf(win.document)), (active): InputSource.FocusLikeEvent => ({
|
|
517
|
+
type: "focus",
|
|
518
|
+
timeStamp: win.performance.now(),
|
|
519
|
+
visible: focusVisible(active),
|
|
520
|
+
fromTarget: active === target,
|
|
521
|
+
}))
|
|
522
|
+
}
|
|
523
|
+
|
|
507
524
|
// --- Feeds over many targets (#665's PR 5, Q56): a Batch's members, from one listener set ------------
|
|
508
525
|
|
|
509
526
|
/**
|
|
@@ -747,6 +764,7 @@ const make = Effect.gen(function* () {
|
|
|
747
764
|
focus,
|
|
748
765
|
keyboard,
|
|
749
766
|
focusWithin,
|
|
767
|
+
focusNow,
|
|
750
768
|
adoptPointer: adoptPointerIn(adopters),
|
|
751
769
|
pointerAmong,
|
|
752
770
|
focusAmong,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two box readers, in a module of their own (probe: hooks-first), apart from `measure.ts`'s other
|
|
3
|
+
* reads. A presence's pop and a binding's `measureLayoutBox` use these in every app; the rest of
|
|
4
|
+
* `measure.ts` is the Projection system's alone. A bundler splits by module, not by function: with
|
|
5
|
+
* all of them in one module, a page that might fetch the layout Feature later carried every read in
|
|
6
|
+
* its first chunk.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type * as Probe from "@wardic/core/Probe"
|
|
11
|
+
import { pending as appearRuns } from "./appear-slot.ts"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Read `el`'s box AS IT CURRENTLY RENDERS — a raw `getBoundingClientRect`, no
|
|
15
|
+
* transform reset. The projection measure pass uses this because it resets the
|
|
16
|
+
* whole tree's transforms in its own WRITE phase first, so by the time it reads,
|
|
17
|
+
* nothing is transformed (see `runMeasurePass`). A lone caller wants
|
|
18
|
+
* {@link measureLayoutBox} instead.
|
|
19
|
+
*/
|
|
20
|
+
export const readLayoutBox = (el: HTMLElement): Probe.Bounds => {
|
|
21
|
+
const r = el.getBoundingClientRect()
|
|
22
|
+
return {
|
|
23
|
+
x: r.x,
|
|
24
|
+
y: r.y,
|
|
25
|
+
width: r.width,
|
|
26
|
+
height: r.height,
|
|
27
|
+
top: r.top,
|
|
28
|
+
right: r.right,
|
|
29
|
+
bottom: r.bottom,
|
|
30
|
+
left: r.left,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Measures `el`'s box where the layout puts it: its own `transform` is cleared for the read and put
|
|
36
|
+
* back, so an animation running on it doesn't move the reading. Its ancestors' transforms still
|
|
37
|
+
* count. The box is in the viewport: `x`, `y`, `width`, `height`, and its edges.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const box = measureLayoutBox(card)
|
|
41
|
+
* @see https://wardic.dev/reference/solid/layout/measure-layout-box
|
|
42
|
+
*/
|
|
43
|
+
// The inline transform is blanked, the rect read, and the exact prior value restored in a `finally`, so
|
|
44
|
+
// a throwing getBoundingClientRect can't leave the element reset. For one element only: inside a tree
|
|
45
|
+
// pass an ancestor's transform pollutes the reading too, and the `finally` restores before the next
|
|
46
|
+
// element is read, which is why the projection pass hoists the reset out to pass level instead.
|
|
47
|
+
export const measureLayoutBox = (el: HTMLElement): Probe.Bounds => {
|
|
48
|
+
const saved = el.style.transform
|
|
49
|
+
el.style.transform = ""
|
|
50
|
+
// An Appear animation not yet handed off (#245): its CSS transform beats an inline one, not an important one.
|
|
51
|
+
if (appearRuns(el)) el.style.setProperty("transform", "none", "important")
|
|
52
|
+
try {
|
|
53
|
+
return readLayoutBox(el)
|
|
54
|
+
} finally {
|
|
55
|
+
el.style.transform = saved
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/internal/measure.ts
CHANGED
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as Drag from "@wardic/core/Drag"
|
|
15
15
|
import type * as Point from "@wardic/core/Point"
|
|
16
|
-
import type * as Probe from "@wardic/core/Probe"
|
|
17
16
|
import * as Arr from "effect/Array"
|
|
18
17
|
import * as Bool from "effect/Boolean"
|
|
19
18
|
import { constVoid } from "effect/Function"
|
|
20
19
|
import * as Option from "effect/Option"
|
|
21
20
|
import * as Predicate from "effect/Predicate"
|
|
22
21
|
import * as Str from "effect/String"
|
|
23
|
-
import {
|
|
22
|
+
import { measureLayoutBox } from "./layout-box.ts"
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* The document timeline's time, in ms. Inside a Refresh frame (its rAF callbacks, their microtasks,
|
|
@@ -38,51 +37,9 @@ export const frameTime = (): number => {
|
|
|
38
37
|
return -1
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* whole tree's transforms in its own WRITE phase first, so by the time it reads,
|
|
45
|
-
* nothing is transformed (see `runMeasurePass`). A lone caller wants
|
|
46
|
-
* {@link measureLayoutBox} instead.
|
|
47
|
-
*/
|
|
48
|
-
export const readLayoutBox = (el: HTMLElement): Probe.Bounds => {
|
|
49
|
-
const r = el.getBoundingClientRect()
|
|
50
|
-
return {
|
|
51
|
-
x: r.x,
|
|
52
|
-
y: r.y,
|
|
53
|
-
width: r.width,
|
|
54
|
-
height: r.height,
|
|
55
|
-
top: r.top,
|
|
56
|
-
right: r.right,
|
|
57
|
-
bottom: r.bottom,
|
|
58
|
-
left: r.left,
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Measures `el`'s box where the layout puts it: its own `transform` is cleared for the read and put
|
|
64
|
-
* back, so an animation running on it doesn't move the reading. Its ancestors' transforms still
|
|
65
|
-
* count. The box is in the viewport: `x`, `y`, `width`, `height`, and its edges.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* const box = measureLayoutBox(card)
|
|
69
|
-
* @see https://wardic.dev/reference/solid/layout/measure-layout-box
|
|
70
|
-
*/
|
|
71
|
-
// The inline transform is blanked, the rect read, and the exact prior value restored in a `finally`, so
|
|
72
|
-
// a throwing getBoundingClientRect can't leave the element reset. For one element only: inside a tree
|
|
73
|
-
// pass an ancestor's transform pollutes the reading too, and the `finally` restores before the next
|
|
74
|
-
// element is read, which is why the projection pass hoists the reset out to pass level instead.
|
|
75
|
-
export const measureLayoutBox = (el: HTMLElement): Probe.Bounds => {
|
|
76
|
-
const saved = el.style.transform
|
|
77
|
-
el.style.transform = ""
|
|
78
|
-
// An Appear animation not yet handed off (#245): its CSS transform beats an inline one, not an important one.
|
|
79
|
-
if (appearRuns(el)) el.style.setProperty("transform", "none", "important")
|
|
80
|
-
try {
|
|
81
|
-
return readLayoutBox(el)
|
|
82
|
-
} finally {
|
|
83
|
-
el.style.transform = saved
|
|
84
|
-
}
|
|
85
|
-
}
|
|
40
|
+
// The two box readers are `layout-box.ts`'s (probe: hooks-first): what every app reads, in a module
|
|
41
|
+
// apart from the rest here, which is the Projection system's alone.
|
|
42
|
+
export { measureLayoutBox, readLayoutBox } from "./layout-box.ts"
|
|
86
43
|
|
|
87
44
|
/**
|
|
88
45
|
* The bounds on `element`'s x/y that keep it inside `container` (Motion's element `dragConstraints`):
|
|
@@ -65,6 +65,7 @@ import * as Box from "@wardic/core/Box"
|
|
|
65
65
|
import * as Clock from "@wardic/core/Clock"
|
|
66
66
|
import type * as Frame from "@wardic/core/Frame"
|
|
67
67
|
import * as FrameLoop from "@wardic/core/FrameLoop"
|
|
68
|
+
import * as FirstSteps from "@wardic/core/unstable/FirstSteps"
|
|
68
69
|
import * as Inertia from "@wardic/core/Inertia"
|
|
69
70
|
import * as Microtask from "@wardic/core/Microtask"
|
|
70
71
|
import type * as Arc from "@wardic/core/Arc"
|
|
@@ -174,6 +175,9 @@ const COORDINATOR_RUNNING: Frame.Frame<void> = { value: undefined, done: false }
|
|
|
174
175
|
const COORDINATOR_SETTLED: Frame.Frame<void> = { value: undefined, done: true }
|
|
175
176
|
const ignoreFrame: FrameLoop.Sink<Frame.Frame<void>> = () => undefined
|
|
176
177
|
|
|
178
|
+
/** The coordinator's run keeps the frame timeline's time: each flight keeps the late-frame rule itself (#1028). */
|
|
179
|
+
const ON_THE_FRAME_TIMELINE: Machine.RunOptions = { onFrameTimeline: true }
|
|
180
|
+
|
|
177
181
|
/** Identity tree-scale (no ancestor scaling). */
|
|
178
182
|
const TREE_SCALE_IDENTITY: Point.Point = { x: 1, y: 1 }
|
|
179
183
|
|
|
@@ -471,6 +475,12 @@ interface Flight {
|
|
|
471
475
|
landed: boolean
|
|
472
476
|
/** Its curve along its Path (#438, ADR-0065), built at its start; `undefined` for a straight flight. */
|
|
473
477
|
readonly curve: FlightCurve | undefined
|
|
478
|
+
/**
|
|
479
|
+
* What it owes of a long task's time (#1028, core's `unstable/FirstSteps`): its first step, until it's taken,
|
|
480
|
+
* then that frame's lateness, which its second step leaves out, then 0. 0 from the start where
|
|
481
|
+
* the Frame loop carries no reader of its ticks.
|
|
482
|
+
*/
|
|
483
|
+
owed: number
|
|
474
484
|
}
|
|
475
485
|
|
|
476
486
|
/** A flight's curve along its Path (#438, ADR-0065). */
|
|
@@ -508,7 +518,17 @@ const timingOf = (transition: LayoutTransition): FlightTiming =>
|
|
|
508
518
|
const LANDED: FlightTiming = springTiming(Spring.resolve({}))
|
|
509
519
|
|
|
510
520
|
/** A flight at 1 on {@link LANDED}: it ends on its first step, the node on its new box. */
|
|
511
|
-
|
|
521
|
+
// It owes nothing (#1028): it lands at its first step, whatever its dt.
|
|
522
|
+
const landedFlight = (): Flight => ({
|
|
523
|
+
position: 1,
|
|
524
|
+
elapsed: 0,
|
|
525
|
+
spring: Spring.init({ from: 1 }),
|
|
526
|
+
timing: LANDED,
|
|
527
|
+
started: false,
|
|
528
|
+
landed: false,
|
|
529
|
+
curve: undefined,
|
|
530
|
+
owed: 0,
|
|
531
|
+
})
|
|
512
532
|
|
|
513
533
|
/** Motion's distance floor for a curved layout animation (#438): a shift shorter than this goes straight. */
|
|
514
534
|
const MIN_CURVE_DISTANCE = 20
|
|
@@ -1086,9 +1106,13 @@ export interface ProjectionSystem extends Inspectable.Inspectable {
|
|
|
1086
1106
|
* handleLeave} declined: each crossfades onto its other twin, following the leaver's own exit.
|
|
1087
1107
|
* `onDone` once every handover has ended; the returned call drops them at once. `None` when it held
|
|
1088
1108
|
* none, so presence runs its exit alone.
|
|
1109
|
+
*
|
|
1110
|
+
* `live` (probe: hooks-first): `el` is a layout node still, where a presence child's has ended by
|
|
1111
|
+
* now. A hook's ward outlives its place on the page and runs its own exit, so a list's row that
|
|
1112
|
+
* lays out is one as it leaves: the twins inside it are handed back all the same.
|
|
1089
1113
|
*/
|
|
1090
1114
|
// ADR-0010 *Amendment (#181)*.
|
|
1091
|
-
readonly handBackWithin: (el: HTMLElement, onDone: () => void) => Option.Option<() => void>
|
|
1115
|
+
readonly handBackWithin: (el: HTMLElement, onDone: () => void, live?: boolean) => Option.Option<() => void>
|
|
1092
1116
|
/**
|
|
1093
1117
|
* A presence child leaving with nobody to take its twins over: the twins it held as it went, inside it
|
|
1094
1118
|
* or it a twin itself, stay a later twin's to take over while it's on the page, until the returned
|
|
@@ -1726,7 +1750,7 @@ export const makeProjectionSystem = (
|
|
|
1726
1750
|
* transition read now, Motion's default with none, its delay held first, and with no velocity
|
|
1727
1751
|
* (Motion's). When reduced motion applies to `node` (ADR-0029), or its animations are skipped
|
|
1728
1752
|
* (#468), at 1 with no delay, so the node lands on its new box at once and the flight ends on its
|
|
1729
|
-
* first step.
|
|
1753
|
+
* first step. Stamped with when it began and what it owes of a long task's time (#1028, `flightDt`).
|
|
1730
1754
|
*/
|
|
1731
1755
|
const startFlight = (node: NodeState): Flight =>
|
|
1732
1756
|
Bool.match(Bool.or(node.skipAnimations(), Bool.and(node.respectReducedMotion(), node.reducedMotion())), {
|
|
@@ -1736,7 +1760,7 @@ export const makeProjectionSystem = (
|
|
|
1736
1760
|
// this one animation: reported, and the node lands, as reduced motion lands it.
|
|
1737
1761
|
try {
|
|
1738
1762
|
const timing = timingOf(Option.getOrElse(node.transition(), () => DEFAULT_LAYOUT_TRANSITION))
|
|
1739
|
-
return { position: 0, elapsed: 0, spring: Spring.init({}), timing, started: false, landed: false, curve: curveOf(node) }
|
|
1763
|
+
return { position: 0, elapsed: 0, spring: Spring.init({}), timing, started: false, landed: false, curve: curveOf(node), owed: ticks.madeOwing() }
|
|
1740
1764
|
} catch (defect) {
|
|
1741
1765
|
runtime.runFork(Report.failure("wardic.projection: layout transition rejected", Cause.die(defect)))
|
|
1742
1766
|
return landedFlight()
|
|
@@ -1853,6 +1877,10 @@ export const makeProjectionSystem = (
|
|
|
1853
1877
|
// The Environment's Frame loop: the coordinator runs on it, the engine's hook is on its ticks, and a
|
|
1854
1878
|
// trigger reads whether its Late window is open (#673, #680).
|
|
1855
1879
|
const loop = runtime.runSync(Effect.service(FrameLoop.FrameLoop))
|
|
1880
|
+
// Its ticks as the late-frame rule reads them (#1028, core's `unstable/FirstSteps`): each flight keeps the
|
|
1881
|
+
// rule, as a Batch's members do, the coordinator's run on the frame timeline. Read once; a loop that
|
|
1882
|
+
// carries no reader (a test's own) is read as one under which nothing owes.
|
|
1883
|
+
const ticks = Option.getOrElse(FirstSteps.readerOf(loop), () => FirstSteps.owingNothing)
|
|
1856
1884
|
// Whether the coordinator's step is running: a stop from inside it settles the run.
|
|
1857
1885
|
let inStep = false
|
|
1858
1886
|
// The turn a turning flight's curve gives at its target just placed (#438), for `derive` to draw:
|
|
@@ -4833,15 +4861,33 @@ export const makeProjectionSystem = (
|
|
|
4833
4861
|
finishSettled(settled)
|
|
4834
4862
|
}
|
|
4835
4863
|
|
|
4864
|
+
// A flight takes none of a long task's time from before it began (#1028, ADR-0027 *Amendment (#1028)*):
|
|
4865
|
+
// #1026's rule, kept per flight, since the coordinator is one run on the Frame loop for every node. A node
|
|
4866
|
+
// already moving catches up, as before.
|
|
4867
|
+
|
|
4868
|
+
/**
|
|
4869
|
+
* The dt `flight` steps at, in a step at the tick's `dt`: that, less what it owes of a long task's time. A
|
|
4870
|
+
* dt-0 step (the coordinator's again, after a Late round) leaves what it owes as it was, as the Frame loop's
|
|
4871
|
+
* own does. Per frame: a field read, and nothing made.
|
|
4872
|
+
*/
|
|
4873
|
+
const flightDt = (flight: Flight, dt: number): number => {
|
|
4874
|
+
const owed = flight.owed
|
|
4875
|
+
if (owed === 0) return dt
|
|
4876
|
+
if (dt === 0) return dt
|
|
4877
|
+
flight.owed = ticks.owedAfter(owed)
|
|
4878
|
+
return ticks.owingDt(owed, dt)
|
|
4879
|
+
}
|
|
4880
|
+
|
|
4836
4881
|
/**
|
|
4837
4882
|
* Step `node`'s layout animation, if one runs; whether it is at rest (ADR-0009 *Amendment (#171)*):
|
|
4838
4883
|
* a spring stepped toward 1 (`Spring.step` holds its delay; `Spring.stepTimed` for one that ends
|
|
4839
|
-
* at its duration, #359), or a tween's eased progress by its time, held at 0 through its delay.
|
|
4840
|
-
* frame: statement `if`s, written in place.
|
|
4884
|
+
* at its duration, #359), or a tween's eased progress by its time, held at 0 through its delay. At
|
|
4885
|
+
* its own dt (`flightDt`). Per frame: statement `if`s, written in place.
|
|
4841
4886
|
*/
|
|
4842
|
-
const stepFlight = (node: NodeState,
|
|
4887
|
+
const stepFlight = (node: NodeState, tickDt: number): boolean => {
|
|
4843
4888
|
const flight = node.flight
|
|
4844
4889
|
if (Predicate.isUndefined(flight)) return true
|
|
4890
|
+
const dt = flightDt(flight, tickDt)
|
|
4845
4891
|
flight.elapsed += dt
|
|
4846
4892
|
const timing = flight.timing
|
|
4847
4893
|
if (timing.kind === "spring") {
|
|
@@ -5288,7 +5334,7 @@ export const makeProjectionSystem = (
|
|
|
5288
5334
|
FiberHandle.setUnsafe(
|
|
5289
5335
|
coordinator,
|
|
5290
5336
|
runtime.runFork(
|
|
5291
|
-
FrameLoop.FrameLoop.use((loop) => loop.runLast(coordinatorMachine(), ignoreFrame)).pipe(
|
|
5337
|
+
FrameLoop.FrameLoop.use((loop) => loop.runLast(coordinatorMachine(), ignoreFrame, ON_THE_FRAME_TIMELINE)).pipe(
|
|
5292
5338
|
Effect.onExit(coordinatorEnded),
|
|
5293
5339
|
Effect.asVoid,
|
|
5294
5340
|
),
|
|
@@ -5692,9 +5738,9 @@ export const makeProjectionSystem = (
|
|
|
5692
5738
|
* once every one's handover has ended; the call returned drops them at once (an interrupted exit).
|
|
5693
5739
|
* `undefined` when it held none.
|
|
5694
5740
|
*/
|
|
5695
|
-
const doHandBackWithin = (el: HTMLElement, onDone: () => void): (() => void) | undefined => {
|
|
5741
|
+
const doHandBackWithin = (el: HTMLElement, onDone: () => void, live: boolean): (() => void) | undefined => {
|
|
5696
5742
|
touchLeavers()
|
|
5697
|
-
if (elementToNode.has(el)) return undefined
|
|
5743
|
+
if (Bool.and(Bool.not(live), elementToNode.has(el))) return undefined
|
|
5698
5744
|
if (isHeldTwin(el)) return undefined
|
|
5699
5745
|
const twins = reintroduceTwinsWithin(el, (held) =>
|
|
5700
5746
|
UndefinedOr.map(held.chain, (chain) =>
|
|
@@ -5733,9 +5779,9 @@ export const makeProjectionSystem = (
|
|
|
5733
5779
|
Effect.sync(() => doHandleLeave(el, onDone)).pipe(Spans.withSpan("wardic.projection.handleLeave")),
|
|
5734
5780
|
)
|
|
5735
5781
|
|
|
5736
|
-
const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone) =>
|
|
5782
|
+
const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone, live) =>
|
|
5737
5783
|
runtime.runSync(
|
|
5738
|
-
Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone))).pipe(
|
|
5784
|
+
Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone, live === true))).pipe(
|
|
5739
5785
|
Spans.withSpan("wardic.projection.handBackWithin"),
|
|
5740
5786
|
),
|
|
5741
5787
|
)
|