@wardic/dom 1.3.1 → 1.4.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/MeasuredPair.d.ts +14 -1
- package/dist/MeasuredPair.d.ts.map +1 -1
- package/dist/MeasuredPair.js +11 -13
- package/dist/MeasuredPair.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/appear.d.ts +6 -0
- package/dist/internal/appear.d.ts.map +1 -1
- package/dist/internal/appear.js +20 -2
- package/dist/internal/appear.js.map +1 -1
- package/dist/internal/batch-handoff.d.ts.map +1 -1
- package/dist/internal/batch-handoff.js +25 -15
- package/dist/internal/batch-handoff.js.map +1 -1
- package/dist/internal/batch-writer.d.ts +1 -1
- package/dist/internal/batch-writer.d.ts.map +1 -1
- package/dist/internal/batch-writer.js +32 -16
- package/dist/internal/batch-writer.js.map +1 -1
- package/dist/internal/clock.d.ts +6 -0
- package/dist/internal/clock.d.ts.map +1 -1
- package/dist/internal/clock.js +27 -0
- package/dist/internal/clock.js.map +1 -1
- package/dist/internal/default-transition.d.ts +3 -2
- package/dist/internal/default-transition.d.ts.map +1 -1
- package/dist/internal/default-transition.js +28 -3
- package/dist/internal/default-transition.js.map +1 -1
- package/dist/internal/failing.d.ts +9 -0
- package/dist/internal/failing.d.ts.map +1 -0
- package/dist/internal/failing.js +33 -0
- package/dist/internal/failing.js.map +1 -0
- package/dist/internal/length-keys.d.ts +19 -0
- package/dist/internal/length-keys.d.ts.map +1 -0
- package/dist/internal/length-keys.js +77 -0
- package/dist/internal/length-keys.js.map +1 -0
- package/dist/internal/measured-pairs.d.ts +3 -2
- package/dist/internal/measured-pairs.d.ts.map +1 -1
- package/dist/internal/measured-pairs.js +60 -23
- package/dist/internal/measured-pairs.js.map +1 -1
- package/dist/internal/own-values.d.ts.map +1 -1
- package/dist/internal/own-values.js +2 -2
- package/dist/internal/own-values.js.map +1 -1
- package/dist/internal/positional-keys.d.ts +1 -1
- package/dist/internal/positional-keys.d.ts.map +1 -1
- package/dist/internal/positional-keys.js +4 -2
- package/dist/internal/positional-keys.js.map +1 -1
- package/dist/internal/projection.d.ts.map +1 -1
- package/dist/internal/projection.js +180 -46
- package/dist/internal/projection.js.map +1 -1
- package/dist/internal/renderer.d.ts +59 -27
- package/dist/internal/renderer.d.ts.map +1 -1
- package/dist/internal/renderer.js +241 -207
- package/dist/internal/renderer.js.map +1 -1
- package/dist/internal/scroll.d.ts.map +1 -1
- package/dist/internal/scroll.js +26 -2
- package/dist/internal/scroll.js.map +1 -1
- package/dist/internal/starting-style.js +5 -5
- package/dist/internal/transform-keys.d.ts +23 -0
- package/dist/internal/transform-keys.d.ts.map +1 -0
- package/dist/internal/transform-keys.js +55 -0
- package/dist/internal/transform-keys.js.map +1 -0
- package/dist/unstable/AppearAnimations.d.ts +2 -1
- package/dist/unstable/AppearAnimations.d.ts.map +1 -1
- package/dist/unstable/AppearAnimations.js +73 -22
- package/dist/unstable/AppearAnimations.js.map +1 -1
- package/dist/unstable/BatchMembers.d.ts +2 -2
- package/dist/unstable/BatchMembers.d.ts.map +1 -1
- package/dist/unstable/BatchMembers.js +30 -7
- package/dist/unstable/BatchMembers.js.map +1 -1
- package/dist/unstable/DomValues.js +1 -1
- package/dist/unstable/DomValues.js.map +1 -1
- package/dist/unstable/DragTrack.d.ts +2 -2
- package/dist/unstable/DragTrack.d.ts.map +1 -1
- package/dist/unstable/DragTrack.js +37 -10
- package/dist/unstable/DragTrack.js.map +1 -1
- package/dist/unstable/ElementSetup.d.ts.map +1 -1
- package/dist/unstable/ElementSetup.js +3 -2
- package/dist/unstable/ElementSetup.js.map +1 -1
- package/dist/unstable/GestureFeatures.d.ts +8 -2
- package/dist/unstable/GestureFeatures.d.ts.map +1 -1
- package/dist/unstable/GestureFeatures.js +26 -40
- 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/LiveStyle.d.ts +28 -2
- package/dist/unstable/LiveStyle.d.ts.map +1 -1
- package/dist/unstable/LiveStyle.js +8 -32
- package/dist/unstable/LiveStyle.js.map +1 -1
- package/dist/unstable/MemberHold.js +3 -3
- package/dist/unstable/MemberHold.js.map +1 -1
- package/dist/unstable/PointerValues.d.ts.map +1 -1
- package/dist/unstable/PointerValues.js +82 -8
- package/dist/unstable/PointerValues.js.map +1 -1
- package/dist/unstable/PresenceController.d.ts +5 -2
- package/dist/unstable/PresenceController.d.ts.map +1 -1
- package/dist/unstable/PresenceController.js +82 -55
- package/dist/unstable/PresenceController.js.map +1 -1
- package/dist/unstable/ReorderInput.d.ts +2 -2
- package/dist/unstable/ReorderInput.js +2 -2
- package/dist/unstable/WardConfig.d.ts +18 -9
- package/dist/unstable/WardConfig.d.ts.map +1 -1
- package/dist/unstable/WardConfig.js.map +1 -1
- package/dist/unstable/features/TimelineKeys.d.ts.map +1 -1
- package/dist/unstable/features/TimelineKeys.js +19 -3
- package/dist/unstable/features/TimelineKeys.js.map +1 -1
- package/package.json +3 -3
- package/src/MeasuredPair.ts +21 -1
- package/src/index.ts +4 -1
- package/src/internal/appear.ts +20 -2
- package/src/internal/batch-handoff.ts +19 -11
- package/src/internal/batch-writer.ts +32 -16
- package/src/internal/clock.ts +28 -0
- package/src/internal/default-transition.ts +28 -4
- package/src/internal/failing.ts +37 -0
- package/src/internal/length-keys.ts +80 -0
- package/src/internal/measured-pairs.ts +58 -22
- package/src/internal/own-values.ts +2 -2
- package/src/internal/positional-keys.ts +4 -2
- package/src/internal/projection.ts +190 -44
- package/src/internal/renderer.ts +272 -198
- package/src/internal/scroll.ts +24 -2
- package/src/internal/starting-style.ts +5 -5
- package/src/internal/transform-keys.ts +59 -0
- package/src/unstable/AppearAnimations.ts +73 -24
- package/src/unstable/BatchMembers.ts +33 -9
- package/src/unstable/DomValues.ts +1 -1
- package/src/unstable/DragTrack.ts +49 -14
- package/src/unstable/ElementSetup.ts +3 -2
- package/src/unstable/GestureFeatures.ts +38 -47
- package/src/unstable/GestureInfo.ts +24 -0
- package/src/unstable/Imperative.ts +1 -0
- package/src/unstable/LiveStyle.ts +12 -8
- package/src/unstable/MemberHold.ts +3 -3
- package/src/unstable/PointerValues.ts +73 -8
- package/src/unstable/PresenceController.ts +80 -54
- package/src/unstable/ReorderInput.ts +2 -2
- package/src/unstable/WardConfig.ts +22 -10
- package/src/unstable/features/TimelineKeys.ts +20 -3
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `RendererDomLive` — the browser realization of `Renderer` (ADR-0002).
|
|
3
|
-
*
|
|
4
|
-
* Split into the two halves the contract mandates:
|
|
5
|
-
*
|
|
6
|
-
* - {@link project} — PURE, synchronous: translates engine values into a DOM
|
|
7
|
-
* `Patch`. Its one piece of real work is grouping the individual transform
|
|
8
|
-
* keys (`x`/`y`/`scale`/`rotate`/…) into a single CSS `transform` string in
|
|
9
|
-
* a canonical order, and applying default units (px/deg) to bare numbers.
|
|
10
|
-
* Reused by the Starting style so this grouping/unit logic isn't duplicated in
|
|
11
|
-
* the binding (ADR-0002). No side effects, no Effect.
|
|
12
|
-
* - {@link commit} — imperative: writes each `Patch` entry onto `target.style`, now.
|
|
13
|
-
* The flush gate calls it once per element per Refresh frame (ADR-0034), and
|
|
14
|
-
* `applyTo` once per Frame.
|
|
15
|
-
*
|
|
16
|
-
* Observability (CONTEXT.md convention): `project` and `commit` are the
|
|
17
|
-
* per-frame hot path, so — exactly like core's `applyTo` per-frame writes and
|
|
18
|
-
* the Clock's `tick` — they stay quiet (no span, no per-call log).
|
|
19
|
-
*/
|
|
20
|
-
import * as BaseValue from "@wardic/core/BaseValue";
|
|
21
1
|
import * as Projection from "@wardic/core/Projection";
|
|
22
2
|
import * as Renderer from "@wardic/core/Renderer";
|
|
3
|
+
import * as Projector from "@wardic/core/unstable/Projector";
|
|
23
4
|
import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.js";
|
|
5
|
+
import { LENGTH_KEY_SET } from "./length-keys.js";
|
|
6
|
+
import * as TransformKeys from "./transform-keys.js";
|
|
24
7
|
import * as Arr from "effect/Array";
|
|
25
8
|
import * as Bool from "effect/Boolean";
|
|
26
9
|
import * as Layer from "effect/Layer";
|
|
@@ -28,41 +11,96 @@ import * as Option from "effect/Option";
|
|
|
28
11
|
import * as Predicate from "effect/Predicate";
|
|
29
12
|
import * as UndefinedOr from "effect/UndefinedOr";
|
|
30
13
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
14
|
+
* Default-unit map for transform values: translate (and the x/y/z shorthands)
|
|
15
|
+
* are lengths → `px`, as is the element's own depth; rotate/skew are angles → `deg`; scale* are unitless.
|
|
16
|
+
* A value that is already a string is used verbatim (explicit units honoured),
|
|
17
|
+
* so this map only drives the formatting of bare numbers.
|
|
18
|
+
*/
|
|
19
|
+
const TRANSFORM_UNITS = {
|
|
20
|
+
[TransformKeys.PERSPECTIVE]: "px",
|
|
21
|
+
x: "px",
|
|
22
|
+
y: "px",
|
|
23
|
+
z: "px",
|
|
24
|
+
translateX: "px",
|
|
25
|
+
translateY: "px",
|
|
26
|
+
translateZ: "px",
|
|
27
|
+
scale: "",
|
|
28
|
+
scaleX: "",
|
|
29
|
+
scaleY: "",
|
|
30
|
+
scaleZ: "",
|
|
31
|
+
rotate: "deg",
|
|
32
|
+
pathRotation: "deg",
|
|
33
|
+
rotateX: "deg",
|
|
34
|
+
rotateY: "deg",
|
|
35
|
+
rotateZ: "deg",
|
|
36
|
+
skewX: "deg",
|
|
37
|
+
skewY: "deg",
|
|
38
|
+
};
|
|
39
|
+
/** A transform key's default unit; none for a key the table doesn't name. */
|
|
40
|
+
// Exported for the Batch writer (#665).
|
|
41
|
+
export const unitOf = (key) => {
|
|
42
|
+
const unit = TRANSFORM_UNITS[key];
|
|
43
|
+
if (Predicate.isUndefined(unit))
|
|
44
|
+
return "";
|
|
45
|
+
return unit;
|
|
46
|
+
};
|
|
47
|
+
/** `key`'s transform function, drawn as `fn`, with its identity and its text. */
|
|
48
|
+
const funcOf = (key, fn) => ({
|
|
49
|
+
key,
|
|
50
|
+
fn,
|
|
51
|
+
identity: UndefinedOr.getOrThrow(TransformKeys.TRANSFORM_IDENTITY[key]),
|
|
52
|
+
open: `${fn}(`,
|
|
53
|
+
openAfter: ` ${fn}(`,
|
|
54
|
+
close: `${unitOf(key)})`,
|
|
55
|
+
});
|
|
56
|
+
/** The element's own depth's function, `perspective()`: a plain render, a projection and a Batch draw it first. */
|
|
57
|
+
// Exported for the Batch writer (#665).
|
|
58
|
+
export const DEPTH_FUNC = funcOf(TransformKeys.PERSPECTIVE, "perspective");
|
|
59
|
+
/**
|
|
60
|
+
* CSS transform functions in their canonical emission order: the element's own
|
|
61
|
+
* depth, then the translate group, then scale, then rotate, then skew. `project` walks this list and emits a
|
|
33
62
|
* func for each key that is present in `values` and not at its identity, so the
|
|
34
63
|
* resulting `transform` string is always grouped in this order regardless of
|
|
35
64
|
* input key order.
|
|
36
65
|
*
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
39
|
-
* (ADR-0022), the value at which `project` leaves the key out (ADR-0023).
|
|
66
|
+
* `identity` is the DOM's (core's, ADR-0022, and the DOM's own). The element's own depth is left out below it
|
|
67
|
+
* too (`TransformKeys.drawsDepth`).
|
|
40
68
|
*/
|
|
41
|
-
// Exported for the Batch writer (#665), which draws a member's transform in the same order.
|
|
69
|
+
// Exported for the Batch writer (#665), which draws a member's transform in the same order. #1030: each
|
|
70
|
+
// function's text is made here once, so a frame's transform costs its numbers' text and the joins alone.
|
|
42
71
|
export const TRANSFORM_FUNCS = [
|
|
72
|
+
// The element's own depth (#887), Motion's `transformPerspective`: first, so it projects what follows.
|
|
73
|
+
DEPTH_FUNC,
|
|
43
74
|
// translate group — shorthands x/y/z map onto translateX/Y/Z
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
funcOf("x", "translateX"),
|
|
76
|
+
funcOf("y", "translateY"),
|
|
77
|
+
funcOf("z", "translateZ"),
|
|
78
|
+
funcOf("translateX", "translateX"),
|
|
79
|
+
funcOf("translateY", "translateY"),
|
|
80
|
+
funcOf("translateZ", "translateZ"),
|
|
50
81
|
// scale group — `scale` is uniform scale(v); scaleX/scaleY are per-axis (flip)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
82
|
+
funcOf("scale", "scale"),
|
|
83
|
+
funcOf("scaleX", "scaleX"),
|
|
84
|
+
funcOf("scaleY", "scaleY"),
|
|
54
85
|
// A scene's third scale (#883), core's transform key since ADR-0069 decision 4: CSS's `scaleZ()`.
|
|
55
|
-
|
|
86
|
+
funcOf("scaleZ", "scaleZ"),
|
|
56
87
|
// rotate group: a path's turn after the element's own (#438), which `rotate(a) rotate(b)` adds up
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
funcOf("rotate", "rotate"),
|
|
89
|
+
funcOf("pathRotation", "rotate"),
|
|
90
|
+
funcOf("rotateX", "rotateX"),
|
|
91
|
+
funcOf("rotateY", "rotateY"),
|
|
92
|
+
funcOf("rotateZ", "rotateZ"),
|
|
62
93
|
// skew group
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
]
|
|
94
|
+
funcOf("skewX", "skewX"),
|
|
95
|
+
funcOf("skewY", "skewY"),
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* What a plain render walks: every transform function but the element's own depth, which it draws ahead
|
|
99
|
+
* of them in a statement of its own.
|
|
100
|
+
*/
|
|
101
|
+
// #887 (ADR-0073, *Amendment (#887)*, Q8): one more step in the walk cost an element at rest 13% in Maglev,
|
|
102
|
+
// 4% in Bun; a read ahead of it, nothing (the cost gate's variants).
|
|
103
|
+
const WALKED_FUNCS = TRANSFORM_FUNCS.filter((f) => f.key !== TransformKeys.PERSPECTIVE);
|
|
66
104
|
/**
|
|
67
105
|
* Whether a transform value is at its identity (ADR-0023), Motion's test
|
|
68
106
|
* (motion-dom build-transform.ts:42-48 at 16c61222c4166bbef5ff6ab0051192faa79fa8c8):
|
|
@@ -76,16 +114,18 @@ const isIdentity = (value, identity) => {
|
|
|
76
114
|
return Predicate.isString(value) && Number.parseFloat(value) === identity;
|
|
77
115
|
};
|
|
78
116
|
/**
|
|
79
|
-
* Whether `key`'s `value` adds to the element's `transform` (#240): a transform key
|
|
117
|
+
* Whether `key`'s `value` adds to the element's `transform` (#240): a transform key it draws, a
|
|
80
118
|
* `transform` string, the projection's value or a Transform template. A Timeline value drawing
|
|
81
119
|
* `transform` runs only while nothing else does. Per frame: statements.
|
|
82
120
|
*/
|
|
83
121
|
export const addsToTransform = (key, value) => {
|
|
84
122
|
if (key === Projection.KEY || key === TEMPLATE_KEY || key === "transform")
|
|
85
123
|
return true;
|
|
86
|
-
const identity =
|
|
124
|
+
const identity = TransformKeys.TRANSFORM_IDENTITY[key];
|
|
87
125
|
if (Predicate.isUndefined(identity))
|
|
88
126
|
return false;
|
|
127
|
+
if (key === TransformKeys.PERSPECTIVE)
|
|
128
|
+
return TransformKeys.drawsDepth(value);
|
|
89
129
|
return !isIdentity(value, identity);
|
|
90
130
|
};
|
|
91
131
|
/** `value` when it's a number, else `fallback`. Per frame: an early return, no Option. */
|
|
@@ -94,104 +134,9 @@ const numberOr = (value, fallback) => {
|
|
|
94
134
|
return value;
|
|
95
135
|
return fallback;
|
|
96
136
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* A value that is already a string is used verbatim (explicit units honoured),
|
|
101
|
-
* so this map only drives the formatting of bare numbers.
|
|
102
|
-
*/
|
|
103
|
-
const TRANSFORM_UNITS = {
|
|
104
|
-
x: "px",
|
|
105
|
-
y: "px",
|
|
106
|
-
z: "px",
|
|
107
|
-
translateX: "px",
|
|
108
|
-
translateY: "px",
|
|
109
|
-
translateZ: "px",
|
|
110
|
-
scale: "",
|
|
111
|
-
scaleX: "",
|
|
112
|
-
scaleY: "",
|
|
113
|
-
scaleZ: "",
|
|
114
|
-
rotate: "deg",
|
|
115
|
-
pathRotation: "deg",
|
|
116
|
-
rotateX: "deg",
|
|
117
|
-
rotateY: "deg",
|
|
118
|
-
rotateZ: "deg",
|
|
119
|
-
skewX: "deg",
|
|
120
|
-
skewY: "deg",
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Fast membership test for "is this key a transform key?": core's transform keys, the ones
|
|
124
|
-
* it gives an identity (ADR-0022), so the two lists can't drift. Every one has a unit above.
|
|
125
|
-
*/
|
|
126
|
-
const TRANSFORM_KEYS = new Set(Object.keys(BaseValue.TRANSFORM_IDENTITY));
|
|
127
|
-
/**
|
|
128
|
-
* The CSS properties a bare number on is a length, drawn in `px`, spelled as Wardic's keys are
|
|
129
|
-
* (`margin-top`): Motion's, and `min-width`, `min-height`, the gaps and `letter-spacing`. The Solid
|
|
130
|
-
* bindings' value types take a number on these and on no other length, so a number never draws CSS a
|
|
131
|
-
* browser drops. `line-height` isn't one: CSS reads its bare number as a multiple. A number on any other
|
|
132
|
-
* key, `opacity`, `z-index`, a custom property, is drawn as it is; a string always is.
|
|
133
|
-
*/
|
|
134
|
-
// #522: Motion's `numberValueTypes`' `px` keys; the bindings' `WardicValues`.
|
|
135
|
-
export const LENGTH_KEYS = [
|
|
136
|
-
"border-width",
|
|
137
|
-
"border-top-width",
|
|
138
|
-
"border-right-width",
|
|
139
|
-
"border-bottom-width",
|
|
140
|
-
"border-left-width",
|
|
141
|
-
"border-radius",
|
|
142
|
-
"border-top-left-radius",
|
|
143
|
-
"border-top-right-radius",
|
|
144
|
-
"border-bottom-right-radius",
|
|
145
|
-
"border-bottom-left-radius",
|
|
146
|
-
"width",
|
|
147
|
-
"min-width",
|
|
148
|
-
"max-width",
|
|
149
|
-
"height",
|
|
150
|
-
"min-height",
|
|
151
|
-
"max-height",
|
|
152
|
-
"top",
|
|
153
|
-
"right",
|
|
154
|
-
"bottom",
|
|
155
|
-
"left",
|
|
156
|
-
"inset",
|
|
157
|
-
"inset-block",
|
|
158
|
-
"inset-block-start",
|
|
159
|
-
"inset-block-end",
|
|
160
|
-
"inset-inline",
|
|
161
|
-
"inset-inline-start",
|
|
162
|
-
"inset-inline-end",
|
|
163
|
-
"padding",
|
|
164
|
-
"padding-top",
|
|
165
|
-
"padding-right",
|
|
166
|
-
"padding-bottom",
|
|
167
|
-
"padding-left",
|
|
168
|
-
"padding-block",
|
|
169
|
-
"padding-block-start",
|
|
170
|
-
"padding-block-end",
|
|
171
|
-
"padding-inline",
|
|
172
|
-
"padding-inline-start",
|
|
173
|
-
"padding-inline-end",
|
|
174
|
-
"margin",
|
|
175
|
-
"margin-top",
|
|
176
|
-
"margin-right",
|
|
177
|
-
"margin-bottom",
|
|
178
|
-
"margin-left",
|
|
179
|
-
"margin-block",
|
|
180
|
-
"margin-block-start",
|
|
181
|
-
"margin-block-end",
|
|
182
|
-
"margin-inline",
|
|
183
|
-
"margin-inline-start",
|
|
184
|
-
"margin-inline-end",
|
|
185
|
-
"gap",
|
|
186
|
-
"row-gap",
|
|
187
|
-
"column-gap",
|
|
188
|
-
"font-size",
|
|
189
|
-
"letter-spacing",
|
|
190
|
-
"background-position-x",
|
|
191
|
-
"background-position-y",
|
|
192
|
-
];
|
|
193
|
-
/** {@link LENGTH_KEYS}, for a membership test a frame can make. */
|
|
194
|
-
const LENGTH_KEY_SET = new Set(LENGTH_KEYS);
|
|
137
|
+
// The lengths a bare number on is drawn in px: a module of their own, which `LiveStyle` reads too without
|
|
138
|
+
// bringing the renderer (#887; a three Stage's apps ship `LiveStyle`, not the renderer).
|
|
139
|
+
export { LENGTH_KEYS } from "./length-keys.js";
|
|
195
140
|
/**
|
|
196
141
|
* Format one transform value into its CSS func argument. Strings pass through
|
|
197
142
|
* verbatim (explicit units respected); numbers get the key's default unit.
|
|
@@ -203,20 +148,40 @@ const formatTransformValue = (key, value) => {
|
|
|
203
148
|
return `${value}${unitOf(key)}`;
|
|
204
149
|
return String(value);
|
|
205
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* `transform` with `func` drawn after it at `value`: a number in the function's unit, a string verbatim, as
|
|
153
|
+
* {@link formatTransformValue} formats it. Per frame: the function's text is its own, made once, so this
|
|
154
|
+
* makes the value's text and the joins alone.
|
|
155
|
+
*/
|
|
156
|
+
// #1030 (Q6): the loop's form, prefix and suffix made once; byte for byte what the template literal drew.
|
|
157
|
+
const withFunction = (transform, func, value) => {
|
|
158
|
+
const open = termOf(transform, func.open, func.openAfter);
|
|
159
|
+
if (Predicate.isNumber(value))
|
|
160
|
+
return open + value + func.close;
|
|
161
|
+
if (Predicate.isString(value))
|
|
162
|
+
return open + value + ")";
|
|
163
|
+
return open + String(value) + ")";
|
|
164
|
+
};
|
|
165
|
+
/** `transform` and `term` after it, with a space between them: either alone when the other is `""`. */
|
|
166
|
+
const spaced = (transform, term) => {
|
|
167
|
+
if (term === "")
|
|
168
|
+
return transform;
|
|
169
|
+
if (transform === "")
|
|
170
|
+
return term;
|
|
171
|
+
return transform + " " + term;
|
|
172
|
+
};
|
|
173
|
+
/** `transform` and what opens a term after it: `first` when it's the first, else `after`, its text with a space ahead. */
|
|
174
|
+
const termOf = (transform, first, after) => {
|
|
175
|
+
if (transform === "")
|
|
176
|
+
return first;
|
|
177
|
+
return transform + after;
|
|
178
|
+
};
|
|
206
179
|
/**
|
|
207
180
|
* `key`'s own transform function for `value`, drawn even at its identity: a Timeline value's keyframe
|
|
208
181
|
* (#240), so each blends with its neighbours as one function, as the gate's values do. `None` for a key
|
|
209
182
|
* that isn't a transform key.
|
|
210
183
|
*/
|
|
211
|
-
export const transformFunctionOf = (key, value) => Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), (
|
|
212
|
-
/** A transform key's default unit; none for a key the table doesn't name. */
|
|
213
|
-
// Exported for the Batch writer (#665).
|
|
214
|
-
export const unitOf = (key) => {
|
|
215
|
-
const unit = TRANSFORM_UNITS[key];
|
|
216
|
-
if (Predicate.isUndefined(unit))
|
|
217
|
-
return "";
|
|
218
|
-
return unit;
|
|
219
|
-
};
|
|
184
|
+
export const transformFunctionOf = (key, value) => Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), (func) => withFunction("", func, value));
|
|
220
185
|
/**
|
|
221
186
|
* The unit {@link project} draws a bare number of `key` in: a transform key's (`px`, `deg`, or none
|
|
222
187
|
* for a scale), `px` for a length key, none for the rest. The Appear sampler judges its stops in it
|
|
@@ -232,6 +197,8 @@ const formatStyleValue = (key, value) => {
|
|
|
232
197
|
return `${value}px`;
|
|
233
198
|
return value;
|
|
234
199
|
};
|
|
200
|
+
/** The keys {@link PROJECTION_WOVEN} weaves. */
|
|
201
|
+
const WOVEN_KEYS = new Set(["rotate", "pathRotation", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"]);
|
|
235
202
|
/**
|
|
236
203
|
* User-animated transform funcs woven INTO a projection transform (ADR-0009,
|
|
237
204
|
* Motion's `buildProjectionTransform`): `rotate`/`skew` compose with a layout
|
|
@@ -241,15 +208,8 @@ const formatStyleValue = (key, value) => {
|
|
|
241
208
|
* `scale`/`scaleX`/`scaleY` multiply the element scale ({@link ownScale}), and `z` is folded
|
|
242
209
|
* into the projection's `translate3d` (handled inline).
|
|
243
210
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
{ key: "pathRotation", fn: "rotate" },
|
|
247
|
-
{ key: "rotateX", fn: "rotateX" },
|
|
248
|
-
{ key: "rotateY", fn: "rotateY" },
|
|
249
|
-
{ key: "rotateZ", fn: "rotateZ" },
|
|
250
|
-
{ key: "skewX", fn: "skewX" },
|
|
251
|
-
{ key: "skewY", fn: "skewY" },
|
|
252
|
-
];
|
|
211
|
+
// The table's own entries, in its order, so each one's text is made once (#1030).
|
|
212
|
+
const PROJECTION_WOVEN = Arr.filter(TRANSFORM_FUNCS, (f) => WOVEN_KEYS.has(f.key));
|
|
253
213
|
/**
|
|
254
214
|
* The element's own scale on one axis (ADR-0009 *Amendment (Reorder)*): `scale` times
|
|
255
215
|
* `scaleX` (or `scaleY`), 1 for an absent or non-numeric value. Motion renders a
|
|
@@ -349,7 +309,19 @@ export const ownOpacityOf = (values) => numberOr(values.opacity, 1);
|
|
|
349
309
|
* result is `"none"` (an identity projection carrying no woven transform).
|
|
350
310
|
*/
|
|
351
311
|
const buildProjectionTransform = (delta, treeScale, latest, rotate) => {
|
|
352
|
-
|
|
312
|
+
// #1030 (Q10): built term by term in its order, each term's text made once, with no array joined: what
|
|
313
|
+
// `funcs.join(" ")` drew, byte for byte. Per element per frame, while a layout animation moves it.
|
|
314
|
+
let transform = "";
|
|
315
|
+
// The element's own depth heads it all, as Motion's `buildProjectionTransform` puts it, so it projects
|
|
316
|
+
// what follows (#887).
|
|
317
|
+
const depth = latest[TransformKeys.PERSPECTIVE];
|
|
318
|
+
if (Predicate.isNotUndefined(depth) && TransformKeys.drawsDepth(depth))
|
|
319
|
+
transform = withFunction(transform, DEPTH_FUNC, depth);
|
|
320
|
+
// An own translate in another unit than px (`x: "-100%"`) can't be added to the projection's pixels,
|
|
321
|
+
// so it's drawn before them, and the browser resolves it against the element's own box (#594). The
|
|
322
|
+
// projection's own math (a handover's start) counts it as 0.
|
|
323
|
+
transform = spaced(transform, otherUnitTranslate(latest["x"], latest["y"]));
|
|
324
|
+
transform = spaced(transform, otherUnitTranslate(latest["translateX"], latest["translateY"]));
|
|
353
325
|
// The element's own translate, in page pixels, on the projection's: divided by the tree scale
|
|
354
326
|
// together, as Motion's target box carries it (#363).
|
|
355
327
|
const tx = (delta.x.translate + ownTranslate(latest, "x", "translateX")) / treeScale.x;
|
|
@@ -357,37 +329,30 @@ const buildProjectionTransform = (delta, treeScale, latest, rotate) => {
|
|
|
357
329
|
const z = latest["z"];
|
|
358
330
|
const translateZ = latest["translateZ"];
|
|
359
331
|
if (tx !== 0 || ty !== 0 || (Predicate.isNotUndefined(z) && !isIdentity(z, 0)) || (Predicate.isNotUndefined(translateZ) && !isIdentity(translateZ, 0))) {
|
|
360
|
-
|
|
332
|
+
transform = termOf(transform, "translate3d(", " translate3d(") + tx + "px, " + ty + "px, " + zArgOf(z, translateZ) + ")";
|
|
361
333
|
}
|
|
362
334
|
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
363
|
-
|
|
335
|
+
transform = termOf(transform, "scale(", " scale(") + 1 / treeScale.x + ", " + 1 / treeScale.y + ")";
|
|
364
336
|
}
|
|
365
|
-
for (
|
|
337
|
+
for (let i = 0; i < PROJECTION_WOVEN.length; i++) {
|
|
338
|
+
const func = PROJECTION_WOVEN[i];
|
|
339
|
+
const key = func.key;
|
|
366
340
|
// A handover's blended rotation stands in for the element's own (ADR-0010, *Amendment (#166)*).
|
|
367
341
|
if (key === "rotate" && Predicate.isNotUndefined(rotate)) {
|
|
368
342
|
if (rotate !== 0)
|
|
369
|
-
|
|
343
|
+
transform = withFunction(transform, func, rotate);
|
|
370
344
|
continue;
|
|
371
345
|
}
|
|
372
346
|
if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0))
|
|
373
|
-
|
|
347
|
+
transform = withFunction(transform, func, latest[key]);
|
|
374
348
|
}
|
|
375
349
|
const sx = delta.x.scale * treeScale.x * ownScale(latest, "scaleX");
|
|
376
350
|
const sy = delta.y.scale * treeScale.y * ownScale(latest, "scaleY");
|
|
377
351
|
if (sx !== 1 || sy !== 1)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
// so it's drawn before them, and the browser resolves it against the element's own box (#594). The
|
|
381
|
-
// projection's own math (a handover's start) counts it as 0.
|
|
382
|
-
const ownByUnit = otherUnitTranslate(latest["x"], latest["y"]);
|
|
383
|
-
const translateByUnit = otherUnitTranslate(latest["translateX"], latest["translateY"]);
|
|
384
|
-
if (translateByUnit !== "")
|
|
385
|
-
funcs.unshift(translateByUnit);
|
|
386
|
-
if (ownByUnit !== "")
|
|
387
|
-
funcs.unshift(ownByUnit);
|
|
388
|
-
if (funcs.length === 0)
|
|
352
|
+
transform = termOf(transform, "scale(", " scale(") + sx + ", " + sy + ")";
|
|
353
|
+
if (transform === "")
|
|
389
354
|
return "none";
|
|
390
|
-
return
|
|
355
|
+
return transform;
|
|
391
356
|
};
|
|
392
357
|
/**
|
|
393
358
|
* The key an element's transform template rides under in its values, as its projection rides under
|
|
@@ -460,22 +425,28 @@ const projectsNothing = (projection) => {
|
|
|
460
425
|
};
|
|
461
426
|
/**
|
|
462
427
|
* The transform keys a plain render draws (ADR-0023): each one present and not at its identity, in
|
|
463
|
-
* the canonical order; `""` when every one present is at its identity;
|
|
464
|
-
* by concatenation, not an array joined (ADR-0034): this runs per element
|
|
428
|
+
* the canonical order, the element's own depth first; `""` when every one present is at its identity;
|
|
429
|
+
* `undefined` with none. Built by concatenation, not an array joined (ADR-0034): this runs per element
|
|
430
|
+
* per frame.
|
|
465
431
|
*/
|
|
466
432
|
const plainTransformOf = (values) => {
|
|
467
433
|
let transform = "";
|
|
468
|
-
let separator = "";
|
|
469
434
|
let present = false;
|
|
470
|
-
|
|
471
|
-
|
|
435
|
+
const depth = values[TransformKeys.PERSPECTIVE];
|
|
436
|
+
if (Predicate.isNotUndefined(depth)) {
|
|
437
|
+
present = true;
|
|
438
|
+
if (TransformKeys.drawsDepth(depth))
|
|
439
|
+
transform = withFunction(transform, DEPTH_FUNC, depth);
|
|
440
|
+
}
|
|
441
|
+
for (let i = 0; i < WALKED_FUNCS.length; i++) {
|
|
442
|
+
const func = WALKED_FUNCS[i];
|
|
443
|
+
if (!Object.hasOwn(values, func.key))
|
|
472
444
|
continue;
|
|
473
445
|
present = true;
|
|
474
|
-
const value = values[key];
|
|
475
|
-
if (isIdentity(value, identity))
|
|
446
|
+
const value = values[func.key];
|
|
447
|
+
if (isIdentity(value, func.identity))
|
|
476
448
|
continue;
|
|
477
|
-
transform =
|
|
478
|
-
separator = " ";
|
|
449
|
+
transform = withFunction(transform, func, value);
|
|
479
450
|
}
|
|
480
451
|
if (!present)
|
|
481
452
|
return undefined;
|
|
@@ -561,24 +532,56 @@ const projectedOpacity = (projection, values) => {
|
|
|
561
532
|
* @example
|
|
562
533
|
* DomRenderer.project({ x: 0, scale: 1, width: 200 }) // { transform: "none", width: "200px" }
|
|
563
534
|
*/
|
|
535
|
+
// The same function `RendererDomLive` provides (ADR-0021, decision 2), with each element's projector for the
|
|
536
|
+
// gate (#1030). Tier 2, for binding authors.
|
|
537
|
+
export const project = (values) => {
|
|
538
|
+
const patch = {};
|
|
539
|
+
drawInto(values, patch, undefined);
|
|
540
|
+
return patch;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* `value` under `key` in `patch`: as it is for {@link project}; for a projector, a number as its text, and the
|
|
544
|
+
* key checked against its last draw's.
|
|
545
|
+
*/
|
|
546
|
+
const put = (patch, drawn, key, value) => {
|
|
547
|
+
if (Predicate.isUndefined(drawn)) {
|
|
548
|
+
patch[key] = value;
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
patch[key] = textOf(value);
|
|
552
|
+
if (drawn.keys[drawn.at] !== key) {
|
|
553
|
+
drawn.keys[drawn.at] = key;
|
|
554
|
+
drawn.changed = true;
|
|
555
|
+
}
|
|
556
|
+
drawn.at++;
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* A projector's patch value (#1030, Q7): a number as its text, which `commit` would write anyway; anything
|
|
560
|
+
* else as it is.
|
|
561
|
+
*/
|
|
562
|
+
const textOf = (value) => {
|
|
563
|
+
if (Predicate.isNumber(value))
|
|
564
|
+
return String(value);
|
|
565
|
+
return value;
|
|
566
|
+
};
|
|
567
|
+
/** `values` drawn into `patch` as {@link project} draws them, through `drawn` for a projector. */
|
|
564
568
|
// Two modes. PROJECTION (ADR-0009): the transform is assembled by `buildProjectionTransform` from the
|
|
565
569
|
// node's `delta`/`treeScale`, adding the element's own translate (`x`, `y`, `translate*`, #363), weaving
|
|
566
570
|
// its own animated `rotate`/`skew` and multiplying in its own `scale`/`scaleX`/`scaleY`. NORMAL: the
|
|
567
|
-
// value-spine path, `none` at every identity (ADR-0023).
|
|
568
|
-
//
|
|
569
|
-
|
|
570
|
-
const patch = {};
|
|
571
|
+
// value-spine path, `none` at every identity (ADR-0023). Its one call that can throw, a Transform
|
|
572
|
+
// template's, comes before its first write, so a draw that throws leaves a projector's patch as it was.
|
|
573
|
+
const drawInto = (values, patch, drawn) => {
|
|
571
574
|
const projection = values[Projection.KEY];
|
|
572
575
|
if (Predicate.isNotUndefined(projection)) {
|
|
573
576
|
// Projection owns the transform; weave this element's rotate/skew from `values`, through its
|
|
574
577
|
// Transform template when it has one (#443).
|
|
575
|
-
patch
|
|
578
|
+
put(patch, drawn, "transform", projectedTransformOf(projection, values));
|
|
576
579
|
// Copy non-transform style keys (transform keys are consumed by the weave /
|
|
577
580
|
// owned by the projection; the reserved keys never render).
|
|
578
581
|
for (const key in values) {
|
|
579
|
-
if (key === Projection.KEY || key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key))
|
|
582
|
+
if (key === Projection.KEY || key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key))
|
|
580
583
|
continue;
|
|
581
|
-
patch
|
|
584
|
+
put(patch, drawn, key, formatStyleValue(key, values[key]));
|
|
582
585
|
}
|
|
583
586
|
// Shared-element crossfade (ADR-0010): compose the crossfade factor with the
|
|
584
587
|
// user's opacity — `finalOpacity = (userOpacity ?? 1) × factor`. Pure: both
|
|
@@ -586,30 +589,57 @@ export const project = (values) => {
|
|
|
586
589
|
// A Switch's blended opacity is drawn as it is (ADR-0010, *Amendment (#166)*).
|
|
587
590
|
const opacity = projectedOpacity(projection, values);
|
|
588
591
|
if (Predicate.isNotUndefined(opacity))
|
|
589
|
-
patch
|
|
592
|
+
put(patch, drawn, "opacity", opacity);
|
|
590
593
|
// A dragged node's raise (ADR-0016 *Amendment (Reorder)*): kebab-case, as the
|
|
591
594
|
// scale correctors' keys are, so the commit's `setProperty` takes it.
|
|
592
595
|
if (Predicate.isNotUndefined(projection.raise))
|
|
593
|
-
patch
|
|
596
|
+
put(patch, drawn, "z-index", projection.raise);
|
|
594
597
|
// A Follower takes no pointer input (`Projection`'s `passesPointer`, ADR-0010, *Amendment
|
|
595
598
|
// (#165)*; Motion's): `pointer-events: none`. A Lead's write leaves the key out, and the gate
|
|
596
599
|
// gives the element its own value back.
|
|
597
600
|
if (projection.passesPointer === true)
|
|
598
|
-
patch
|
|
599
|
-
return
|
|
601
|
+
put(patch, drawn, "pointer-events", "none");
|
|
602
|
+
return;
|
|
600
603
|
}
|
|
601
604
|
// Grouped transform: the present keys in the canonical order, through the Transform template
|
|
602
605
|
// when the element has one (#443).
|
|
603
606
|
const transform = drawnTransformOf(values);
|
|
604
607
|
if (Predicate.isNotUndefined(transform))
|
|
605
|
-
patch
|
|
608
|
+
put(patch, drawn, "transform", transform);
|
|
606
609
|
// Non-transform keys: copy across with default-unit handling.
|
|
607
610
|
for (const key in values) {
|
|
608
|
-
if (key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key))
|
|
611
|
+
if (key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key))
|
|
609
612
|
continue;
|
|
610
|
-
patch
|
|
613
|
+
put(patch, drawn, key, formatStyleValue(key, values[key]));
|
|
611
614
|
}
|
|
612
|
-
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* One element's projector (#1030): its values drawn as {@link project} draws them, each number as the text
|
|
618
|
+
* `commit` writes, into a patch of its own that it rewrites in place at its next call. Its patch stays the
|
|
619
|
+
* same object while the element's keys do; when they change, a new one holds them, so a key that went is
|
|
620
|
+
* never written again. The gate makes one for each element it registers.
|
|
621
|
+
*/
|
|
622
|
+
// ADR-0034, *Amendment (#1030)*. Q8: a new patch, never a `delete` (which takes it to dictionary mode) nor
|
|
623
|
+
// an `undefined` key (which `commit` and the gate would read as written).
|
|
624
|
+
export const makeProjector = () => {
|
|
625
|
+
let patch = {};
|
|
626
|
+
const drawn = { keys: [], at: 0, changed: false };
|
|
627
|
+
return (values) => {
|
|
628
|
+
const before = drawn.keys.length;
|
|
629
|
+
drawn.at = 0;
|
|
630
|
+
drawn.changed = false;
|
|
631
|
+
drawInto(values, patch, drawn);
|
|
632
|
+
if (!drawn.changed && drawn.at === before)
|
|
633
|
+
return patch;
|
|
634
|
+
drawn.keys.length = drawn.at;
|
|
635
|
+
// Its first draw: nothing in its patch that this one didn't write.
|
|
636
|
+
if (before === 0)
|
|
637
|
+
return patch;
|
|
638
|
+
patch = {};
|
|
639
|
+
drawn.at = 0;
|
|
640
|
+
drawInto(values, patch, drawn);
|
|
641
|
+
return patch;
|
|
642
|
+
};
|
|
613
643
|
};
|
|
614
644
|
/**
|
|
615
645
|
* Imperative: write a `Patch` onto `target`, now. The engine treats `target` as
|
|
@@ -636,7 +666,11 @@ const writeStyle = (style, patch) => {
|
|
|
636
666
|
for (const key in patch)
|
|
637
667
|
style.setProperty(dashCase(key), String(patch[key]));
|
|
638
668
|
};
|
|
639
|
-
/**
|
|
640
|
-
|
|
641
|
-
|
|
669
|
+
/**
|
|
670
|
+
* Core's `Renderer` for the DOM: `project` and a `commit` that writes a patch onto an element's style, with a
|
|
671
|
+
* projector for each element the Flush gate draws. It needs nothing.
|
|
672
|
+
*/
|
|
673
|
+
// `project` and `commit` have no service dependencies, so this is a plain `Layer.succeed`. The projector
|
|
674
|
+
// rides on the value (#1030, core's `unstable/Projector`), so a Renderer provided over this one has none.
|
|
675
|
+
export const RendererDomLive = Layer.succeed(Renderer.Renderer, Projector.attach({ project, commit }, makeProjector));
|
|
642
676
|
//# sourceMappingURL=renderer.js.map
|