@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
package/src/internal/renderer.ts
CHANGED
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
* per-frame hot path, so — exactly like core's `applyTo` per-frame writes and
|
|
18
18
|
* the Clock's `tick` — they stay quiet (no span, no per-call log).
|
|
19
19
|
*/
|
|
20
|
-
import * as BaseValue from "@wardic/core/BaseValue"
|
|
21
20
|
import type * as Point from "@wardic/core/Point"
|
|
22
21
|
import * as Projection from "@wardic/core/Projection"
|
|
23
22
|
import * as Renderer from "@wardic/core/Renderer"
|
|
23
|
+
import * as Projector from "@wardic/core/unstable/Projector"
|
|
24
24
|
import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.ts"
|
|
25
|
+
import { LENGTH_KEY_SET } from "./length-keys.ts"
|
|
26
|
+
import * as TransformKeys from "./transform-keys.ts"
|
|
25
27
|
import * as Arr from "effect/Array"
|
|
26
28
|
import * as Bool from "effect/Boolean"
|
|
27
29
|
import * as Layer from "effect/Layer"
|
|
@@ -29,42 +31,120 @@ import * as Option from "effect/Option"
|
|
|
29
31
|
import * as Predicate from "effect/Predicate"
|
|
30
32
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
31
33
|
|
|
34
|
+
/** Default unit appended to a bare numeric transform value, by transform key. */
|
|
35
|
+
type TransformUnit = "px" | "deg" | ""
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Default-unit map for transform values: translate (and the x/y/z shorthands)
|
|
39
|
+
* are lengths → `px`, as is the element's own depth; rotate/skew are angles → `deg`; scale* are unitless.
|
|
40
|
+
* A value that is already a string is used verbatim (explicit units honoured),
|
|
41
|
+
* so this map only drives the formatting of bare numbers.
|
|
42
|
+
*/
|
|
43
|
+
const TRANSFORM_UNITS: Record<string, TransformUnit> = {
|
|
44
|
+
[TransformKeys.PERSPECTIVE]: "px",
|
|
45
|
+
x: "px",
|
|
46
|
+
y: "px",
|
|
47
|
+
z: "px",
|
|
48
|
+
translateX: "px",
|
|
49
|
+
translateY: "px",
|
|
50
|
+
translateZ: "px",
|
|
51
|
+
scale: "",
|
|
52
|
+
scaleX: "",
|
|
53
|
+
scaleY: "",
|
|
54
|
+
scaleZ: "",
|
|
55
|
+
rotate: "deg",
|
|
56
|
+
pathRotation: "deg",
|
|
57
|
+
rotateX: "deg",
|
|
58
|
+
rotateY: "deg",
|
|
59
|
+
rotateZ: "deg",
|
|
60
|
+
skewX: "deg",
|
|
61
|
+
skewY: "deg",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A transform key's default unit; none for a key the table doesn't name. */
|
|
65
|
+
// Exported for the Batch writer (#665).
|
|
66
|
+
export const unitOf = (key: string): TransformUnit => {
|
|
67
|
+
const unit: TransformUnit | undefined = TRANSFORM_UNITS[key]
|
|
68
|
+
if (Predicate.isUndefined(unit)) return ""
|
|
69
|
+
return unit
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A transform function `project` draws, and the text either side of its value, made once. */
|
|
73
|
+
export interface TransformFunc {
|
|
74
|
+
/** The property name accepted on engine values, shorthands `x`/`y`/`z` included. */
|
|
75
|
+
readonly key: string
|
|
76
|
+
/** The CSS function name it renders as. */
|
|
77
|
+
readonly fn: string
|
|
78
|
+
/** The value at which `project` leaves the key out (ADR-0023). */
|
|
79
|
+
readonly identity: number
|
|
80
|
+
/** What goes before its value as the transform's first function: `translateX(`. */
|
|
81
|
+
readonly open: string
|
|
82
|
+
/** What goes before its value after another function: ` translateX(`. */
|
|
83
|
+
readonly openAfter: string
|
|
84
|
+
/** What goes after a number of it: its unit, and the bracket, `px)`. */
|
|
85
|
+
readonly close: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** `key`'s transform function, drawn as `fn`, with its identity and its text. */
|
|
89
|
+
const funcOf = (key: string, fn: string): TransformFunc => ({
|
|
90
|
+
key,
|
|
91
|
+
fn,
|
|
92
|
+
identity: UndefinedOr.getOrThrow(TransformKeys.TRANSFORM_IDENTITY[key]),
|
|
93
|
+
open: `${fn}(`,
|
|
94
|
+
openAfter: ` ${fn}(`,
|
|
95
|
+
close: `${unitOf(key)})`,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
/** The element's own depth's function, `perspective()`: a plain render, a projection and a Batch draw it first. */
|
|
99
|
+
// Exported for the Batch writer (#665).
|
|
100
|
+
export const DEPTH_FUNC: TransformFunc = funcOf(TransformKeys.PERSPECTIVE, "perspective")
|
|
101
|
+
|
|
32
102
|
/**
|
|
33
|
-
* CSS transform functions in their canonical emission order:
|
|
34
|
-
* then scale, then rotate, then skew. `project` walks this list and emits a
|
|
103
|
+
* CSS transform functions in their canonical emission order: the element's own
|
|
104
|
+
* depth, then the translate group, then scale, then rotate, then skew. `project` walks this list and emits a
|
|
35
105
|
* func for each key that is present in `values` and not at its identity, so the
|
|
36
106
|
* resulting `transform` string is always grouped in this order regardless of
|
|
37
107
|
* input key order.
|
|
38
108
|
*
|
|
39
|
-
* `
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
export const TRANSFORM_FUNCS: ReadonlyArray<
|
|
109
|
+
* `identity` is the DOM's (core's, ADR-0022, and the DOM's own). The element's own depth is left out below it
|
|
110
|
+
* too (`TransformKeys.drawsDepth`).
|
|
111
|
+
*/
|
|
112
|
+
// Exported for the Batch writer (#665), which draws a member's transform in the same order. #1030: each
|
|
113
|
+
// function's text is made here once, so a frame's transform costs its numbers' text and the joins alone.
|
|
114
|
+
export const TRANSFORM_FUNCS: ReadonlyArray<TransformFunc> = [
|
|
115
|
+
// The element's own depth (#887), Motion's `transformPerspective`: first, so it projects what follows.
|
|
116
|
+
DEPTH_FUNC,
|
|
45
117
|
// translate group — shorthands x/y/z map onto translateX/Y/Z
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
118
|
+
funcOf("x", "translateX"),
|
|
119
|
+
funcOf("y", "translateY"),
|
|
120
|
+
funcOf("z", "translateZ"),
|
|
121
|
+
funcOf("translateX", "translateX"),
|
|
122
|
+
funcOf("translateY", "translateY"),
|
|
123
|
+
funcOf("translateZ", "translateZ"),
|
|
52
124
|
// scale group — `scale` is uniform scale(v); scaleX/scaleY are per-axis (flip)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
125
|
+
funcOf("scale", "scale"),
|
|
126
|
+
funcOf("scaleX", "scaleX"),
|
|
127
|
+
funcOf("scaleY", "scaleY"),
|
|
56
128
|
// A scene's third scale (#883), core's transform key since ADR-0069 decision 4: CSS's `scaleZ()`.
|
|
57
|
-
|
|
129
|
+
funcOf("scaleZ", "scaleZ"),
|
|
58
130
|
// rotate group: a path's turn after the element's own (#438), which `rotate(a) rotate(b)` adds up
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
131
|
+
funcOf("rotate", "rotate"),
|
|
132
|
+
funcOf("pathRotation", "rotate"),
|
|
133
|
+
funcOf("rotateX", "rotateX"),
|
|
134
|
+
funcOf("rotateY", "rotateY"),
|
|
135
|
+
funcOf("rotateZ", "rotateZ"),
|
|
64
136
|
// skew group
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
]
|
|
137
|
+
funcOf("skewX", "skewX"),
|
|
138
|
+
funcOf("skewY", "skewY"),
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* What a plain render walks: every transform function but the element's own depth, which it draws ahead
|
|
143
|
+
* of them in a statement of its own.
|
|
144
|
+
*/
|
|
145
|
+
// #887 (ADR-0073, *Amendment (#887)*, Q8): one more step in the walk cost an element at rest 13% in Maglev,
|
|
146
|
+
// 4% in Bun; a read ahead of it, nothing (the cost gate's variants).
|
|
147
|
+
const WALKED_FUNCS = TRANSFORM_FUNCS.filter((f) => f.key !== TransformKeys.PERSPECTIVE)
|
|
68
148
|
|
|
69
149
|
/**
|
|
70
150
|
* Whether a transform value is at its identity (ADR-0023), Motion's test
|
|
@@ -79,14 +159,15 @@ const isIdentity = (value: unknown, identity: number): boolean => {
|
|
|
79
159
|
}
|
|
80
160
|
|
|
81
161
|
/**
|
|
82
|
-
* Whether `key`'s `value` adds to the element's `transform` (#240): a transform key
|
|
162
|
+
* Whether `key`'s `value` adds to the element's `transform` (#240): a transform key it draws, a
|
|
83
163
|
* `transform` string, the projection's value or a Transform template. A Timeline value drawing
|
|
84
164
|
* `transform` runs only while nothing else does. Per frame: statements.
|
|
85
165
|
*/
|
|
86
166
|
export const addsToTransform = (key: string, value: unknown): boolean => {
|
|
87
167
|
if (key === Projection.KEY || key === TEMPLATE_KEY || key === "transform") return true
|
|
88
|
-
const identity =
|
|
168
|
+
const identity = TransformKeys.TRANSFORM_IDENTITY[key]
|
|
89
169
|
if (Predicate.isUndefined(identity)) return false
|
|
170
|
+
if (key === TransformKeys.PERSPECTIVE) return TransformKeys.drawsDepth(value)
|
|
90
171
|
return !isIdentity(value, identity)
|
|
91
172
|
}
|
|
92
173
|
|
|
@@ -96,113 +177,9 @@ const numberOr = (value: unknown, fallback: number): number => {
|
|
|
96
177
|
return fallback
|
|
97
178
|
}
|
|
98
179
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Default-unit map for transform values: translate (and the x/y/z shorthands)
|
|
104
|
-
* are lengths → `px`; rotate/skew are angles → `deg`; scale* are unitless.
|
|
105
|
-
* A value that is already a string is used verbatim (explicit units honoured),
|
|
106
|
-
* so this map only drives the formatting of bare numbers.
|
|
107
|
-
*/
|
|
108
|
-
const TRANSFORM_UNITS: Record<string, TransformUnit> = {
|
|
109
|
-
x: "px",
|
|
110
|
-
y: "px",
|
|
111
|
-
z: "px",
|
|
112
|
-
translateX: "px",
|
|
113
|
-
translateY: "px",
|
|
114
|
-
translateZ: "px",
|
|
115
|
-
scale: "",
|
|
116
|
-
scaleX: "",
|
|
117
|
-
scaleY: "",
|
|
118
|
-
scaleZ: "",
|
|
119
|
-
rotate: "deg",
|
|
120
|
-
pathRotation: "deg",
|
|
121
|
-
rotateX: "deg",
|
|
122
|
-
rotateY: "deg",
|
|
123
|
-
rotateZ: "deg",
|
|
124
|
-
skewX: "deg",
|
|
125
|
-
skewY: "deg",
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Fast membership test for "is this key a transform key?": core's transform keys, the ones
|
|
130
|
-
* it gives an identity (ADR-0022), so the two lists can't drift. Every one has a unit above.
|
|
131
|
-
*/
|
|
132
|
-
const TRANSFORM_KEYS: ReadonlySet<string> = new Set(Object.keys(BaseValue.TRANSFORM_IDENTITY))
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The CSS properties a bare number on is a length, drawn in `px`, spelled as Wardic's keys are
|
|
136
|
-
* (`margin-top`): Motion's, and `min-width`, `min-height`, the gaps and `letter-spacing`. The Solid
|
|
137
|
-
* bindings' value types take a number on these and on no other length, so a number never draws CSS a
|
|
138
|
-
* browser drops. `line-height` isn't one: CSS reads its bare number as a multiple. A number on any other
|
|
139
|
-
* key, `opacity`, `z-index`, a custom property, is drawn as it is; a string always is.
|
|
140
|
-
*/
|
|
141
|
-
// #522: Motion's `numberValueTypes`' `px` keys; the bindings' `WardicValues`.
|
|
142
|
-
export const LENGTH_KEYS = [
|
|
143
|
-
"border-width",
|
|
144
|
-
"border-top-width",
|
|
145
|
-
"border-right-width",
|
|
146
|
-
"border-bottom-width",
|
|
147
|
-
"border-left-width",
|
|
148
|
-
"border-radius",
|
|
149
|
-
"border-top-left-radius",
|
|
150
|
-
"border-top-right-radius",
|
|
151
|
-
"border-bottom-right-radius",
|
|
152
|
-
"border-bottom-left-radius",
|
|
153
|
-
"width",
|
|
154
|
-
"min-width",
|
|
155
|
-
"max-width",
|
|
156
|
-
"height",
|
|
157
|
-
"min-height",
|
|
158
|
-
"max-height",
|
|
159
|
-
"top",
|
|
160
|
-
"right",
|
|
161
|
-
"bottom",
|
|
162
|
-
"left",
|
|
163
|
-
"inset",
|
|
164
|
-
"inset-block",
|
|
165
|
-
"inset-block-start",
|
|
166
|
-
"inset-block-end",
|
|
167
|
-
"inset-inline",
|
|
168
|
-
"inset-inline-start",
|
|
169
|
-
"inset-inline-end",
|
|
170
|
-
"padding",
|
|
171
|
-
"padding-top",
|
|
172
|
-
"padding-right",
|
|
173
|
-
"padding-bottom",
|
|
174
|
-
"padding-left",
|
|
175
|
-
"padding-block",
|
|
176
|
-
"padding-block-start",
|
|
177
|
-
"padding-block-end",
|
|
178
|
-
"padding-inline",
|
|
179
|
-
"padding-inline-start",
|
|
180
|
-
"padding-inline-end",
|
|
181
|
-
"margin",
|
|
182
|
-
"margin-top",
|
|
183
|
-
"margin-right",
|
|
184
|
-
"margin-bottom",
|
|
185
|
-
"margin-left",
|
|
186
|
-
"margin-block",
|
|
187
|
-
"margin-block-start",
|
|
188
|
-
"margin-block-end",
|
|
189
|
-
"margin-inline",
|
|
190
|
-
"margin-inline-start",
|
|
191
|
-
"margin-inline-end",
|
|
192
|
-
"gap",
|
|
193
|
-
"row-gap",
|
|
194
|
-
"column-gap",
|
|
195
|
-
"font-size",
|
|
196
|
-
"letter-spacing",
|
|
197
|
-
"background-position-x",
|
|
198
|
-
"background-position-y",
|
|
199
|
-
] as const
|
|
200
|
-
|
|
201
|
-
/** One of `LENGTH_KEYS`: a CSS property a bare number on is drawn in `px`. */
|
|
202
|
-
export type LengthKey = (typeof LENGTH_KEYS)[number]
|
|
203
|
-
|
|
204
|
-
/** {@link LENGTH_KEYS}, for a membership test a frame can make. */
|
|
205
|
-
const LENGTH_KEY_SET: ReadonlySet<string> = new Set(LENGTH_KEYS)
|
|
180
|
+
// The lengths a bare number on is drawn in px: a module of their own, which `LiveStyle` reads too without
|
|
181
|
+
// bringing the renderer (#887; a three Stage's apps ship `LiveStyle`, not the renderer).
|
|
182
|
+
export { LENGTH_KEYS, type LengthKey } from "./length-keys.ts"
|
|
206
183
|
|
|
207
184
|
/**
|
|
208
185
|
* Format one transform value into its CSS func argument. Strings pass through
|
|
@@ -214,21 +191,39 @@ const formatTransformValue = (key: string, value: unknown): string => {
|
|
|
214
191
|
return String(value)
|
|
215
192
|
}
|
|
216
193
|
|
|
194
|
+
/**
|
|
195
|
+
* `transform` with `func` drawn after it at `value`: a number in the function's unit, a string verbatim, as
|
|
196
|
+
* {@link formatTransformValue} formats it. Per frame: the function's text is its own, made once, so this
|
|
197
|
+
* makes the value's text and the joins alone.
|
|
198
|
+
*/
|
|
199
|
+
// #1030 (Q6): the loop's form, prefix and suffix made once; byte for byte what the template literal drew.
|
|
200
|
+
const withFunction = (transform: string, func: TransformFunc, value: unknown): string => {
|
|
201
|
+
const open = termOf(transform, func.open, func.openAfter)
|
|
202
|
+
if (Predicate.isNumber(value)) return open + value + func.close
|
|
203
|
+
if (Predicate.isString(value)) return open + value + ")"
|
|
204
|
+
return open + String(value) + ")"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** `transform` and `term` after it, with a space between them: either alone when the other is `""`. */
|
|
208
|
+
const spaced = (transform: string, term: string): string => {
|
|
209
|
+
if (term === "") return transform
|
|
210
|
+
if (transform === "") return term
|
|
211
|
+
return transform + " " + term
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** `transform` and what opens a term after it: `first` when it's the first, else `after`, its text with a space ahead. */
|
|
215
|
+
const termOf = (transform: string, first: string, after: string): string => {
|
|
216
|
+
if (transform === "") return first
|
|
217
|
+
return transform + after
|
|
218
|
+
}
|
|
219
|
+
|
|
217
220
|
/**
|
|
218
221
|
* `key`'s own transform function for `value`, drawn even at its identity: a Timeline value's keyframe
|
|
219
222
|
* (#240), so each blends with its neighbours as one function, as the gate's values do. `None` for a key
|
|
220
223
|
* that isn't a transform key.
|
|
221
224
|
*/
|
|
222
225
|
export const transformFunctionOf = (key: string, value: unknown): Option.Option<string> =>
|
|
223
|
-
Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), (
|
|
224
|
-
|
|
225
|
-
/** A transform key's default unit; none for a key the table doesn't name. */
|
|
226
|
-
// Exported for the Batch writer (#665).
|
|
227
|
-
export const unitOf = (key: string): TransformUnit => {
|
|
228
|
-
const unit: TransformUnit | undefined = TRANSFORM_UNITS[key]
|
|
229
|
-
if (Predicate.isUndefined(unit)) return ""
|
|
230
|
-
return unit
|
|
231
|
-
}
|
|
226
|
+
Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), (func) => withFunction("", func, value))
|
|
232
227
|
|
|
233
228
|
/**
|
|
234
229
|
* The unit {@link project} draws a bare number of `key` in: a transform key's (`px`, `deg`, or none
|
|
@@ -247,6 +242,9 @@ const formatStyleValue = (key: string, value: unknown): unknown => {
|
|
|
247
242
|
return value
|
|
248
243
|
}
|
|
249
244
|
|
|
245
|
+
/** The keys {@link PROJECTION_WOVEN} weaves. */
|
|
246
|
+
const WOVEN_KEYS: ReadonlySet<string> = new Set(["rotate", "pathRotation", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"])
|
|
247
|
+
|
|
250
248
|
/**
|
|
251
249
|
* User-animated transform funcs woven INTO a projection transform (ADR-0009,
|
|
252
250
|
* Motion's `buildProjectionTransform`): `rotate`/`skew` compose with a layout
|
|
@@ -256,15 +254,8 @@ const formatStyleValue = (key: string, value: unknown): unknown => {
|
|
|
256
254
|
* `scale`/`scaleX`/`scaleY` multiply the element scale ({@link ownScale}), and `z` is folded
|
|
257
255
|
* into the projection's `translate3d` (handled inline).
|
|
258
256
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
{ key: "pathRotation", fn: "rotate" },
|
|
262
|
-
{ key: "rotateX", fn: "rotateX" },
|
|
263
|
-
{ key: "rotateY", fn: "rotateY" },
|
|
264
|
-
{ key: "rotateZ", fn: "rotateZ" },
|
|
265
|
-
{ key: "skewX", fn: "skewX" },
|
|
266
|
-
{ key: "skewY", fn: "skewY" },
|
|
267
|
-
]
|
|
257
|
+
// The table's own entries, in its order, so each one's text is made once (#1030).
|
|
258
|
+
const PROJECTION_WOVEN: ReadonlyArray<TransformFunc> = Arr.filter(TRANSFORM_FUNCS, (f) => WOVEN_KEYS.has(f.key))
|
|
268
259
|
|
|
269
260
|
/**
|
|
270
261
|
* The element's own scale on one axis (ADR-0009 *Amendment (Reorder)*): `scale` times
|
|
@@ -375,7 +366,18 @@ const buildProjectionTransform = (
|
|
|
375
366
|
latest: Readonly<Record<string, unknown>>,
|
|
376
367
|
rotate: number | undefined,
|
|
377
368
|
): string => {
|
|
378
|
-
|
|
369
|
+
// #1030 (Q10): built term by term in its order, each term's text made once, with no array joined: what
|
|
370
|
+
// `funcs.join(" ")` drew, byte for byte. Per element per frame, while a layout animation moves it.
|
|
371
|
+
let transform = ""
|
|
372
|
+
// The element's own depth heads it all, as Motion's `buildProjectionTransform` puts it, so it projects
|
|
373
|
+
// what follows (#887).
|
|
374
|
+
const depth = latest[TransformKeys.PERSPECTIVE]
|
|
375
|
+
if (Predicate.isNotUndefined(depth) && TransformKeys.drawsDepth(depth)) transform = withFunction(transform, DEPTH_FUNC, depth)
|
|
376
|
+
// An own translate in another unit than px (`x: "-100%"`) can't be added to the projection's pixels,
|
|
377
|
+
// so it's drawn before them, and the browser resolves it against the element's own box (#594). The
|
|
378
|
+
// projection's own math (a handover's start) counts it as 0.
|
|
379
|
+
transform = spaced(transform, otherUnitTranslate(latest["x"], latest["y"]))
|
|
380
|
+
transform = spaced(transform, otherUnitTranslate(latest["translateX"], latest["translateY"]))
|
|
379
381
|
|
|
380
382
|
// The element's own translate, in page pixels, on the projection's: divided by the tree scale
|
|
381
383
|
// together, as Motion's target box carries it (#363).
|
|
@@ -384,35 +386,30 @@ const buildProjectionTransform = (
|
|
|
384
386
|
const z = latest["z"]
|
|
385
387
|
const translateZ = latest["translateZ"]
|
|
386
388
|
if (tx !== 0 || ty !== 0 || (Predicate.isNotUndefined(z) && !isIdentity(z, 0)) || (Predicate.isNotUndefined(translateZ) && !isIdentity(translateZ, 0))) {
|
|
387
|
-
|
|
389
|
+
transform = termOf(transform, "translate3d(", " translate3d(") + tx + "px, " + ty + "px, " + zArgOf(z, translateZ) + ")"
|
|
388
390
|
}
|
|
389
391
|
|
|
390
392
|
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
391
|
-
|
|
393
|
+
transform = termOf(transform, "scale(", " scale(") + 1 / treeScale.x + ", " + 1 / treeScale.y + ")"
|
|
392
394
|
}
|
|
393
395
|
|
|
394
|
-
for (
|
|
396
|
+
for (let i = 0; i < PROJECTION_WOVEN.length; i++) {
|
|
397
|
+
const func = PROJECTION_WOVEN[i]
|
|
398
|
+
const key = func.key
|
|
395
399
|
// A handover's blended rotation stands in for the element's own (ADR-0010, *Amendment (#166)*).
|
|
396
400
|
if (key === "rotate" && Predicate.isNotUndefined(rotate)) {
|
|
397
|
-
if (rotate !== 0)
|
|
401
|
+
if (rotate !== 0) transform = withFunction(transform, func, rotate)
|
|
398
402
|
continue
|
|
399
403
|
}
|
|
400
|
-
if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0))
|
|
404
|
+
if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0)) transform = withFunction(transform, func, latest[key])
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
const sx = delta.x.scale * treeScale.x * ownScale(latest, "scaleX")
|
|
404
408
|
const sy = delta.y.scale * treeScale.y * ownScale(latest, "scaleY")
|
|
405
|
-
if (sx !== 1 || sy !== 1)
|
|
409
|
+
if (sx !== 1 || sy !== 1) transform = termOf(transform, "scale(", " scale(") + sx + ", " + sy + ")"
|
|
406
410
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
// projection's own math (a handover's start) counts it as 0.
|
|
410
|
-
const ownByUnit = otherUnitTranslate(latest["x"], latest["y"])
|
|
411
|
-
const translateByUnit = otherUnitTranslate(latest["translateX"], latest["translateY"])
|
|
412
|
-
if (translateByUnit !== "") funcs.unshift(translateByUnit)
|
|
413
|
-
if (ownByUnit !== "") funcs.unshift(ownByUnit)
|
|
414
|
-
if (funcs.length === 0) return "none"
|
|
415
|
-
return funcs.join(" ")
|
|
411
|
+
if (transform === "") return "none"
|
|
412
|
+
return transform
|
|
416
413
|
}
|
|
417
414
|
|
|
418
415
|
/**
|
|
@@ -498,20 +495,25 @@ const projectsNothing = (projection: Projection.Value): boolean => {
|
|
|
498
495
|
|
|
499
496
|
/**
|
|
500
497
|
* The transform keys a plain render draws (ADR-0023): each one present and not at its identity, in
|
|
501
|
-
* the canonical order; `""` when every one present is at its identity;
|
|
502
|
-
* by concatenation, not an array joined (ADR-0034): this runs per element
|
|
498
|
+
* the canonical order, the element's own depth first; `""` when every one present is at its identity;
|
|
499
|
+
* `undefined` with none. Built by concatenation, not an array joined (ADR-0034): this runs per element
|
|
500
|
+
* per frame.
|
|
503
501
|
*/
|
|
504
502
|
const plainTransformOf = (values: Record<string, unknown>): string | undefined => {
|
|
505
503
|
let transform = ""
|
|
506
|
-
let separator = ""
|
|
507
504
|
let present = false
|
|
508
|
-
|
|
509
|
-
|
|
505
|
+
const depth = values[TransformKeys.PERSPECTIVE]
|
|
506
|
+
if (Predicate.isNotUndefined(depth)) {
|
|
510
507
|
present = true
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
508
|
+
if (TransformKeys.drawsDepth(depth)) transform = withFunction(transform, DEPTH_FUNC, depth)
|
|
509
|
+
}
|
|
510
|
+
for (let i = 0; i < WALKED_FUNCS.length; i++) {
|
|
511
|
+
const func = WALKED_FUNCS[i]
|
|
512
|
+
if (!Object.hasOwn(values, func.key)) continue
|
|
513
|
+
present = true
|
|
514
|
+
const value = values[func.key]
|
|
515
|
+
if (isIdentity(value, func.identity)) continue
|
|
516
|
+
transform = withFunction(transform, func, value)
|
|
515
517
|
}
|
|
516
518
|
if (!present) return undefined
|
|
517
519
|
return transform
|
|
@@ -593,53 +595,121 @@ const projectedOpacity = (projection: Projection.Value, values: Record<string, u
|
|
|
593
595
|
* @example
|
|
594
596
|
* DomRenderer.project({ x: 0, scale: 1, width: 200 }) // { transform: "none", width: "200px" }
|
|
595
597
|
*/
|
|
596
|
-
//
|
|
597
|
-
//
|
|
598
|
-
// its own animated `rotate`/`skew` and multiplying in its own `scale`/`scaleX`/`scaleY`. NORMAL: the
|
|
599
|
-
// value-spine path, `none` at every identity (ADR-0023). The same function `RendererDomLive` provides
|
|
600
|
-
// (ADR-0021, decision 2). Tier 2, for binding authors.
|
|
598
|
+
// The same function `RendererDomLive` provides (ADR-0021, decision 2), with each element's projector for the
|
|
599
|
+
// gate (#1030). Tier 2, for binding authors.
|
|
601
600
|
export const project = (values: Readonly<Record<string, unknown>>): Renderer.Patch => {
|
|
602
601
|
const patch: Renderer.Patch = {}
|
|
602
|
+
drawInto(values, patch, undefined)
|
|
603
|
+
return patch
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* What a projector keeps of its last draw (#1030): the keys it wrote, in order, and how far this draw is
|
|
608
|
+
* through them, so it tells a draw whose keys differ.
|
|
609
|
+
*/
|
|
610
|
+
interface Drawn {
|
|
611
|
+
readonly keys: Array<string>
|
|
612
|
+
at: number
|
|
613
|
+
changed: boolean
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* `value` under `key` in `patch`: as it is for {@link project}; for a projector, a number as its text, and the
|
|
618
|
+
* key checked against its last draw's.
|
|
619
|
+
*/
|
|
620
|
+
const put = (patch: Renderer.Patch, drawn: Drawn | undefined, key: string, value: unknown): void => {
|
|
621
|
+
if (Predicate.isUndefined(drawn)) {
|
|
622
|
+
patch[key] = value
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
patch[key] = textOf(value)
|
|
626
|
+
if (drawn.keys[drawn.at] !== key) {
|
|
627
|
+
drawn.keys[drawn.at] = key
|
|
628
|
+
drawn.changed = true
|
|
629
|
+
}
|
|
630
|
+
drawn.at++
|
|
631
|
+
}
|
|
603
632
|
|
|
633
|
+
/**
|
|
634
|
+
* A projector's patch value (#1030, Q7): a number as its text, which `commit` would write anyway; anything
|
|
635
|
+
* else as it is.
|
|
636
|
+
*/
|
|
637
|
+
const textOf = (value: unknown): unknown => {
|
|
638
|
+
if (Predicate.isNumber(value)) return String(value)
|
|
639
|
+
return value
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** `values` drawn into `patch` as {@link project} draws them, through `drawn` for a projector. */
|
|
643
|
+
// Two modes. PROJECTION (ADR-0009): the transform is assembled by `buildProjectionTransform` from the
|
|
644
|
+
// node's `delta`/`treeScale`, adding the element's own translate (`x`, `y`, `translate*`, #363), weaving
|
|
645
|
+
// its own animated `rotate`/`skew` and multiplying in its own `scale`/`scaleX`/`scaleY`. NORMAL: the
|
|
646
|
+
// value-spine path, `none` at every identity (ADR-0023). Its one call that can throw, a Transform
|
|
647
|
+
// template's, comes before its first write, so a draw that throws leaves a projector's patch as it was.
|
|
648
|
+
const drawInto = (values: Readonly<Record<string, unknown>>, patch: Renderer.Patch, drawn: Drawn | undefined): void => {
|
|
604
649
|
const projection = values[Projection.KEY] as Projection.Value | undefined
|
|
605
650
|
if (Predicate.isNotUndefined(projection)) {
|
|
606
651
|
// Projection owns the transform; weave this element's rotate/skew from `values`, through its
|
|
607
652
|
// Transform template when it has one (#443).
|
|
608
|
-
patch
|
|
653
|
+
put(patch, drawn, "transform", projectedTransformOf(projection, values))
|
|
609
654
|
// Copy non-transform style keys (transform keys are consumed by the weave /
|
|
610
655
|
// owned by the projection; the reserved keys never render).
|
|
611
656
|
for (const key in values) {
|
|
612
|
-
if (key === Projection.KEY || key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
|
|
613
|
-
patch
|
|
657
|
+
if (key === Projection.KEY || key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
|
|
658
|
+
put(patch, drawn, key, formatStyleValue(key, values[key]))
|
|
614
659
|
}
|
|
615
660
|
// Shared-element crossfade (ADR-0010): compose the crossfade factor with the
|
|
616
661
|
// user's opacity — `finalOpacity = (userOpacity ?? 1) × factor`. Pure: both
|
|
617
662
|
// values are already in the value-map (like buildProjectionTransform above).
|
|
618
663
|
// A Switch's blended opacity is drawn as it is (ADR-0010, *Amendment (#166)*).
|
|
619
664
|
const opacity = projectedOpacity(projection, values)
|
|
620
|
-
if (Predicate.isNotUndefined(opacity)) patch
|
|
665
|
+
if (Predicate.isNotUndefined(opacity)) put(patch, drawn, "opacity", opacity)
|
|
621
666
|
// A dragged node's raise (ADR-0016 *Amendment (Reorder)*): kebab-case, as the
|
|
622
667
|
// scale correctors' keys are, so the commit's `setProperty` takes it.
|
|
623
|
-
if (Predicate.isNotUndefined(projection.raise)) patch
|
|
668
|
+
if (Predicate.isNotUndefined(projection.raise)) put(patch, drawn, "z-index", projection.raise)
|
|
624
669
|
// A Follower takes no pointer input (`Projection`'s `passesPointer`, ADR-0010, *Amendment
|
|
625
670
|
// (#165)*; Motion's): `pointer-events: none`. A Lead's write leaves the key out, and the gate
|
|
626
671
|
// gives the element its own value back.
|
|
627
|
-
if (projection.passesPointer === true) patch
|
|
628
|
-
return
|
|
672
|
+
if (projection.passesPointer === true) put(patch, drawn, "pointer-events", "none")
|
|
673
|
+
return
|
|
629
674
|
}
|
|
630
675
|
|
|
631
676
|
// Grouped transform: the present keys in the canonical order, through the Transform template
|
|
632
677
|
// when the element has one (#443).
|
|
633
678
|
const transform = drawnTransformOf(values)
|
|
634
|
-
if (Predicate.isNotUndefined(transform)) patch
|
|
679
|
+
if (Predicate.isNotUndefined(transform)) put(patch, drawn, "transform", transform)
|
|
635
680
|
|
|
636
681
|
// Non-transform keys: copy across with default-unit handling.
|
|
637
682
|
for (const key in values) {
|
|
638
|
-
if (key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
|
|
639
|
-
patch
|
|
683
|
+
if (key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
|
|
684
|
+
put(patch, drawn, key, formatStyleValue(key, values[key]))
|
|
640
685
|
}
|
|
686
|
+
}
|
|
641
687
|
|
|
642
|
-
|
|
688
|
+
/**
|
|
689
|
+
* One element's projector (#1030): its values drawn as {@link project} draws them, each number as the text
|
|
690
|
+
* `commit` writes, into a patch of its own that it rewrites in place at its next call. Its patch stays the
|
|
691
|
+
* same object while the element's keys do; when they change, a new one holds them, so a key that went is
|
|
692
|
+
* never written again. The gate makes one for each element it registers.
|
|
693
|
+
*/
|
|
694
|
+
// ADR-0034, *Amendment (#1030)*. Q8: a new patch, never a `delete` (which takes it to dictionary mode) nor
|
|
695
|
+
// an `undefined` key (which `commit` and the gate would read as written).
|
|
696
|
+
export const makeProjector = (): Projector.Projector => {
|
|
697
|
+
let patch: Renderer.Patch = {}
|
|
698
|
+
const drawn: Drawn = { keys: [], at: 0, changed: false }
|
|
699
|
+
return (values) => {
|
|
700
|
+
const before = drawn.keys.length
|
|
701
|
+
drawn.at = 0
|
|
702
|
+
drawn.changed = false
|
|
703
|
+
drawInto(values, patch, drawn)
|
|
704
|
+
if (!drawn.changed && drawn.at === before) return patch
|
|
705
|
+
drawn.keys.length = drawn.at
|
|
706
|
+
// Its first draw: nothing in its patch that this one didn't write.
|
|
707
|
+
if (before === 0) return patch
|
|
708
|
+
patch = {}
|
|
709
|
+
drawn.at = 0
|
|
710
|
+
drawInto(values, patch, drawn)
|
|
711
|
+
return patch
|
|
712
|
+
}
|
|
643
713
|
}
|
|
644
714
|
|
|
645
715
|
/**
|
|
@@ -668,6 +738,10 @@ const writeStyle = (style: CSSStyleDeclaration, patch: Record<string, unknown>):
|
|
|
668
738
|
for (const key in patch) style.setProperty(dashCase(key), String(patch[key]))
|
|
669
739
|
}
|
|
670
740
|
|
|
671
|
-
/**
|
|
672
|
-
|
|
673
|
-
|
|
741
|
+
/**
|
|
742
|
+
* Core's `Renderer` for the DOM: `project` and a `commit` that writes a patch onto an element's style, with a
|
|
743
|
+
* projector for each element the Flush gate draws. It needs nothing.
|
|
744
|
+
*/
|
|
745
|
+
// `project` and `commit` have no service dependencies, so this is a plain `Layer.succeed`. The projector
|
|
746
|
+
// rides on the value (#1030, core's `unstable/Projector`), so a Renderer provided over this one has none.
|
|
747
|
+
export const RendererDomLive: Layer.Layer<Renderer.Renderer> = Layer.succeed(Renderer.Renderer, Projector.attach({ project, commit }, makeProjector))
|