@wardic/dom 1.3.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/internal/batch-writer.d.ts.map +1 -1
  5. package/dist/internal/batch-writer.js +9 -13
  6. package/dist/internal/batch-writer.js.map +1 -1
  7. package/dist/internal/clock.d.ts +3 -3
  8. package/dist/internal/clock.d.ts.map +1 -1
  9. package/dist/internal/clock.js +25 -7
  10. package/dist/internal/clock.js.map +1 -1
  11. package/dist/internal/default-transition.d.ts +2 -2
  12. package/dist/internal/default-transition.d.ts.map +1 -1
  13. package/dist/internal/default-transition.js +23 -9
  14. package/dist/internal/default-transition.js.map +1 -1
  15. package/dist/internal/projection.d.ts.map +1 -1
  16. package/dist/internal/projection.js +42 -7
  17. package/dist/internal/projection.js.map +1 -1
  18. package/dist/internal/renderer.d.ts +36 -14
  19. package/dist/internal/renderer.d.ts.map +1 -1
  20. package/dist/internal/renderer.js +213 -118
  21. package/dist/internal/renderer.js.map +1 -1
  22. package/dist/internal/starting-style.js +5 -5
  23. package/dist/internal/transform-keys.d.ts +3 -2
  24. package/dist/internal/transform-keys.d.ts.map +1 -1
  25. package/dist/internal/transform-keys.js +21 -9
  26. package/dist/internal/transform-keys.js.map +1 -1
  27. package/dist/unstable/BatchMembers.js +1 -1
  28. package/dist/unstable/DragTrack.d.ts.map +1 -1
  29. package/dist/unstable/DragTrack.js +3 -2
  30. package/dist/unstable/DragTrack.js.map +1 -1
  31. package/dist/unstable/ElementSetup.js +1 -1
  32. package/dist/unstable/GestureFeatures.d.ts +6 -1
  33. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  34. package/dist/unstable/GestureFeatures.js +8 -3
  35. package/dist/unstable/GestureFeatures.js.map +1 -1
  36. package/dist/unstable/GestureInfo.d.ts +11 -0
  37. package/dist/unstable/GestureInfo.d.ts.map +1 -1
  38. package/dist/unstable/GestureInfo.js +8 -0
  39. package/dist/unstable/GestureInfo.js.map +1 -1
  40. package/dist/unstable/Imperative.d.ts +1 -1
  41. package/dist/unstable/Imperative.d.ts.map +1 -1
  42. package/dist/unstable/Imperative.js.map +1 -1
  43. package/dist/unstable/MemberHold.js +1 -1
  44. package/dist/unstable/MemberHold.js.map +1 -1
  45. package/dist/unstable/PresenceController.js +14 -14
  46. package/dist/unstable/WardConfig.d.ts +5 -5
  47. package/dist/unstable/WardConfig.d.ts.map +1 -1
  48. package/dist/unstable/features/TimelineKeys.js +1 -1
  49. package/package.json +3 -3
  50. package/src/index.ts +2 -2
  51. package/src/internal/batch-writer.ts +9 -14
  52. package/src/internal/clock.ts +25 -7
  53. package/src/internal/default-transition.ts +22 -8
  54. package/src/internal/projection.ts +49 -7
  55. package/src/internal/renderer.ts +243 -122
  56. package/src/internal/starting-style.ts +5 -5
  57. package/src/internal/transform-keys.ts +21 -9
  58. package/src/unstable/BatchMembers.ts +1 -1
  59. package/src/unstable/DragTrack.ts +3 -2
  60. package/src/unstable/ElementSetup.ts +1 -1
  61. package/src/unstable/GestureFeatures.ts +15 -3
  62. package/src/unstable/GestureInfo.ts +24 -0
  63. package/src/unstable/Imperative.ts +1 -0
  64. package/src/unstable/MemberHold.ts +1 -1
  65. package/src/unstable/PresenceController.ts +14 -14
  66. package/src/unstable/WardConfig.ts +5 -5
  67. package/src/unstable/features/TimelineKeys.ts +1 -1
@@ -20,6 +20,7 @@
20
20
  import type * as Point from "@wardic/core/Point"
21
21
  import * as Projection from "@wardic/core/Projection"
22
22
  import * as Renderer from "@wardic/core/Renderer"
23
+ import * as Projector from "@wardic/core/unstable/Projector"
23
24
  import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.ts"
24
25
  import { LENGTH_KEY_SET } from "./length-keys.ts"
25
26
  import * as TransformKeys from "./transform-keys.ts"
@@ -30,6 +31,74 @@ import * as Option from "effect/Option"
30
31
  import * as Predicate from "effect/Predicate"
31
32
  import * as UndefinedOr from "effect/UndefinedOr"
32
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
+
33
102
  /**
34
103
  * CSS transform functions in their canonical emission order: the element's own
35
104
  * depth, then the translate group, then scale, then rotate, then skew. `project` walks this list and emits a
@@ -37,38 +106,37 @@ import * as UndefinedOr from "effect/UndefinedOr"
37
106
  * resulting `transform` string is always grouped in this order regardless of
38
107
  * input key order.
39
108
  *
40
- * `key` is the property name accepted on engine values (shorthands `x`/`y`/`z`
41
- * included); `fn` is the CSS function name it renders as; `identity` is the DOM's
42
- * (core's, ADR-0022, and the DOM's own), the value at which `project` leaves the key out (ADR-0023).
43
- * The element's own depth is left out below it too (`TransformKeys.drawsDepth`).
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`).
44
111
  */
45
- // Exported for the Batch writer (#665), which draws a member's transform in the same order.
46
- export const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn: string; readonly identity: number }> = [
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> = [
47
115
  // The element's own depth (#887), Motion's `transformPerspective`: first, so it projects what follows.
48
- { key: TransformKeys.PERSPECTIVE, fn: "perspective" },
116
+ DEPTH_FUNC,
49
117
  // translate group — shorthands x/y/z map onto translateX/Y/Z
50
- { key: "x", fn: "translateX" },
51
- { key: "y", fn: "translateY" },
52
- { key: "z", fn: "translateZ" },
53
- { key: "translateX", fn: "translateX" },
54
- { key: "translateY", fn: "translateY" },
55
- { key: "translateZ", fn: "translateZ" },
118
+ funcOf("x", "translateX"),
119
+ funcOf("y", "translateY"),
120
+ funcOf("z", "translateZ"),
121
+ funcOf("translateX", "translateX"),
122
+ funcOf("translateY", "translateY"),
123
+ funcOf("translateZ", "translateZ"),
56
124
  // scale group — `scale` is uniform scale(v); scaleX/scaleY are per-axis (flip)
57
- { key: "scale", fn: "scale" },
58
- { key: "scaleX", fn: "scaleX" },
59
- { key: "scaleY", fn: "scaleY" },
125
+ funcOf("scale", "scale"),
126
+ funcOf("scaleX", "scaleX"),
127
+ funcOf("scaleY", "scaleY"),
60
128
  // A scene's third scale (#883), core's transform key since ADR-0069 decision 4: CSS's `scaleZ()`.
61
- { key: "scaleZ", fn: "scaleZ" },
129
+ funcOf("scaleZ", "scaleZ"),
62
130
  // rotate group: a path's turn after the element's own (#438), which `rotate(a) rotate(b)` adds up
63
- { key: "rotate", fn: "rotate" },
64
- { key: "pathRotation", fn: "rotate" },
65
- { key: "rotateX", fn: "rotateX" },
66
- { key: "rotateY", fn: "rotateY" },
67
- { key: "rotateZ", fn: "rotateZ" },
131
+ funcOf("rotate", "rotate"),
132
+ funcOf("pathRotation", "rotate"),
133
+ funcOf("rotateX", "rotateX"),
134
+ funcOf("rotateY", "rotateY"),
135
+ funcOf("rotateZ", "rotateZ"),
68
136
  // skew group
69
- { key: "skewX", fn: "skewX" },
70
- { key: "skewY", fn: "skewY" },
71
- ].map((f) => ({ ...f, identity: UndefinedOr.getOrThrow(TransformKeys.TRANSFORM_IDENTITY[f.key]) }))
137
+ funcOf("skewX", "skewX"),
138
+ funcOf("skewY", "skewY"),
139
+ ]
72
140
 
73
141
  /**
74
142
  * What a plain render walks: every transform function but the element's own depth, which it draws ahead
@@ -109,37 +177,6 @@ const numberOr = (value: unknown, fallback: number): number => {
109
177
  return fallback
110
178
  }
111
179
 
112
- /** Default unit appended to a bare numeric transform value, by transform key. */
113
- type TransformUnit = "px" | "deg" | ""
114
-
115
- /**
116
- * Default-unit map for transform values: translate (and the x/y/z shorthands)
117
- * are lengths → `px`, as is the element's own depth; rotate/skew are angles → `deg`; scale* are unitless.
118
- * A value that is already a string is used verbatim (explicit units honoured),
119
- * so this map only drives the formatting of bare numbers.
120
- */
121
- const TRANSFORM_UNITS: Record<string, TransformUnit> = {
122
- [TransformKeys.PERSPECTIVE]: "px",
123
- x: "px",
124
- y: "px",
125
- z: "px",
126
- translateX: "px",
127
- translateY: "px",
128
- translateZ: "px",
129
- scale: "",
130
- scaleX: "",
131
- scaleY: "",
132
- scaleZ: "",
133
- rotate: "deg",
134
- pathRotation: "deg",
135
- rotateX: "deg",
136
- rotateY: "deg",
137
- rotateZ: "deg",
138
- skewX: "deg",
139
- skewY: "deg",
140
- }
141
-
142
-
143
180
  // The lengths a bare number on is drawn in px: a module of their own, which `LiveStyle` reads too without
144
181
  // bringing the renderer (#887; a three Stage's apps ship `LiveStyle`, not the renderer).
145
182
  export { LENGTH_KEYS, type LengthKey } from "./length-keys.ts"
@@ -154,21 +191,39 @@ const formatTransformValue = (key: string, value: unknown): string => {
154
191
  return String(value)
155
192
  }
156
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
+
157
220
  /**
158
221
  * `key`'s own transform function for `value`, drawn even at its identity: a Timeline value's keyframe
159
222
  * (#240), so each blends with its neighbours as one function, as the gate's values do. `None` for a key
160
223
  * that isn't a transform key.
161
224
  */
162
225
  export const transformFunctionOf = (key: string, value: unknown): Option.Option<string> =>
163
- Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), ({ fn }) => `${fn}(${formatTransformValue(key, value)})`)
164
-
165
- /** A transform key's default unit; none for a key the table doesn't name. */
166
- // Exported for the Batch writer (#665).
167
- export const unitOf = (key: string): TransformUnit => {
168
- const unit: TransformUnit | undefined = TRANSFORM_UNITS[key]
169
- if (Predicate.isUndefined(unit)) return ""
170
- return unit
171
- }
226
+ Option.map(Arr.findFirst(TRANSFORM_FUNCS, (f) => f.key === key), (func) => withFunction("", func, value))
172
227
 
173
228
  /**
174
229
  * The unit {@link project} draws a bare number of `key` in: a transform key's (`px`, `deg`, or none
@@ -187,6 +242,9 @@ const formatStyleValue = (key: string, value: unknown): unknown => {
187
242
  return value
188
243
  }
189
244
 
245
+ /** The keys {@link PROJECTION_WOVEN} weaves. */
246
+ const WOVEN_KEYS: ReadonlySet<string> = new Set(["rotate", "pathRotation", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"])
247
+
190
248
  /**
191
249
  * User-animated transform funcs woven INTO a projection transform (ADR-0009,
192
250
  * Motion's `buildProjectionTransform`): `rotate`/`skew` compose with a layout
@@ -196,15 +254,8 @@ const formatStyleValue = (key: string, value: unknown): unknown => {
196
254
  * `scale`/`scaleX`/`scaleY` multiply the element scale ({@link ownScale}), and `z` is folded
197
255
  * into the projection's `translate3d` (handled inline).
198
256
  */
199
- const PROJECTION_WOVEN: ReadonlyArray<{ readonly key: string; readonly fn: string }> = [
200
- { key: "rotate", fn: "rotate" },
201
- { key: "pathRotation", fn: "rotate" },
202
- { key: "rotateX", fn: "rotateX" },
203
- { key: "rotateY", fn: "rotateY" },
204
- { key: "rotateZ", fn: "rotateZ" },
205
- { key: "skewX", fn: "skewX" },
206
- { key: "skewY", fn: "skewY" },
207
- ]
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))
208
259
 
209
260
  /**
210
261
  * The element's own scale on one axis (ADR-0009 *Amendment (Reorder)*): `scale` times
@@ -315,7 +366,18 @@ const buildProjectionTransform = (
315
366
  latest: Readonly<Record<string, unknown>>,
316
367
  rotate: number | undefined,
317
368
  ): string => {
318
- const funcs: Array<string> = []
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"]))
319
381
 
320
382
  // The element's own translate, in page pixels, on the projection's: divided by the tree scale
321
383
  // together, as Motion's target box carries it (#363).
@@ -324,39 +386,30 @@ const buildProjectionTransform = (
324
386
  const z = latest["z"]
325
387
  const translateZ = latest["translateZ"]
326
388
  if (tx !== 0 || ty !== 0 || (Predicate.isNotUndefined(z) && !isIdentity(z, 0)) || (Predicate.isNotUndefined(translateZ) && !isIdentity(translateZ, 0))) {
327
- funcs.push(`translate3d(${tx}px, ${ty}px, ${zArgOf(z, translateZ)})`)
389
+ transform = termOf(transform, "translate3d(", " translate3d(") + tx + "px, " + ty + "px, " + zArgOf(z, translateZ) + ")"
328
390
  }
329
391
 
330
392
  if (treeScale.x !== 1 || treeScale.y !== 1) {
331
- funcs.push(`scale(${1 / treeScale.x}, ${1 / treeScale.y})`)
393
+ transform = termOf(transform, "scale(", " scale(") + 1 / treeScale.x + ", " + 1 / treeScale.y + ")"
332
394
  }
333
395
 
334
- for (const { key, fn } of PROJECTION_WOVEN) {
396
+ for (let i = 0; i < PROJECTION_WOVEN.length; i++) {
397
+ const func = PROJECTION_WOVEN[i]
398
+ const key = func.key
335
399
  // A handover's blended rotation stands in for the element's own (ADR-0010, *Amendment (#166)*).
336
400
  if (key === "rotate" && Predicate.isNotUndefined(rotate)) {
337
- if (rotate !== 0) funcs.push(`rotate(${formatTransformValue(key, rotate)})`)
401
+ if (rotate !== 0) transform = withFunction(transform, func, rotate)
338
402
  continue
339
403
  }
340
- if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0)) funcs.push(`${fn}(${formatTransformValue(key, latest[key])})`)
404
+ if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0)) transform = withFunction(transform, func, latest[key])
341
405
  }
342
406
 
343
407
  const sx = delta.x.scale * treeScale.x * ownScale(latest, "scaleX")
344
408
  const sy = delta.y.scale * treeScale.y * ownScale(latest, "scaleY")
345
- if (sx !== 1 || sy !== 1) funcs.push(`scale(${sx}, ${sy})`)
409
+ if (sx !== 1 || sy !== 1) transform = termOf(transform, "scale(", " scale(") + sx + ", " + sy + ")"
346
410
 
347
- // An own translate in another unit than px (`x: "-100%"`) can't be added to the projection's pixels,
348
- // so it's drawn before them, and the browser resolves it against the element's own box (#594). The
349
- // projection's own math (a handover's start) counts it as 0.
350
- const ownByUnit = otherUnitTranslate(latest["x"], latest["y"])
351
- const translateByUnit = otherUnitTranslate(latest["translateX"], latest["translateY"])
352
- if (translateByUnit !== "") funcs.unshift(translateByUnit)
353
- if (ownByUnit !== "") funcs.unshift(ownByUnit)
354
- // The element's own depth heads it all, as Motion's `buildProjectionTransform` puts it, so it projects
355
- // what follows (#887).
356
- const depth = latest[TransformKeys.PERSPECTIVE]
357
- if (Predicate.isNotUndefined(depth) && TransformKeys.drawsDepth(depth)) funcs.unshift(`perspective(${formatTransformValue(TransformKeys.PERSPECTIVE, depth)})`)
358
- if (funcs.length === 0) return "none"
359
- return funcs.join(" ")
411
+ if (transform === "") return "none"
412
+ return transform
360
413
  }
361
414
 
362
415
  /**
@@ -448,23 +501,19 @@ const projectsNothing = (projection: Projection.Value): boolean => {
448
501
  */
449
502
  const plainTransformOf = (values: Record<string, unknown>): string | undefined => {
450
503
  let transform = ""
451
- let separator = ""
452
504
  let present = false
453
505
  const depth = values[TransformKeys.PERSPECTIVE]
454
506
  if (Predicate.isNotUndefined(depth)) {
455
507
  present = true
456
- if (TransformKeys.drawsDepth(depth)) {
457
- transform = `perspective(${formatTransformValue(TransformKeys.PERSPECTIVE, depth)})`
458
- separator = " "
459
- }
508
+ if (TransformKeys.drawsDepth(depth)) transform = withFunction(transform, DEPTH_FUNC, depth)
460
509
  }
461
- for (const { key, fn, identity } of WALKED_FUNCS) {
462
- if (!Object.hasOwn(values, key)) continue
510
+ for (let i = 0; i < WALKED_FUNCS.length; i++) {
511
+ const func = WALKED_FUNCS[i]
512
+ if (!Object.hasOwn(values, func.key)) continue
463
513
  present = true
464
- const value = values[key]
465
- if (isIdentity(value, identity)) continue
466
- transform = `${transform}${separator}${fn}(${formatTransformValue(key, value)})`
467
- separator = " "
514
+ const value = values[func.key]
515
+ if (isIdentity(value, func.identity)) continue
516
+ transform = withFunction(transform, func, value)
468
517
  }
469
518
  if (!present) return undefined
470
519
  return transform
@@ -546,53 +595,121 @@ const projectedOpacity = (projection: Projection.Value, values: Record<string, u
546
595
  * @example
547
596
  * DomRenderer.project({ x: 0, scale: 1, width: 200 }) // { transform: "none", width: "200px" }
548
597
  */
549
- // Two modes. PROJECTION (ADR-0009): the transform is assembled by `buildProjectionTransform` from the
550
- // node's `delta`/`treeScale`, adding the element's own translate (`x`, `y`, `translate*`, #363), weaving
551
- // its own animated `rotate`/`skew` and multiplying in its own `scale`/`scaleX`/`scaleY`. NORMAL: the
552
- // value-spine path, `none` at every identity (ADR-0023). The same function `RendererDomLive` provides
553
- // (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.
554
600
  export const project = (values: Readonly<Record<string, unknown>>): Renderer.Patch => {
555
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
+ }
556
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 => {
557
649
  const projection = values[Projection.KEY] as Projection.Value | undefined
558
650
  if (Predicate.isNotUndefined(projection)) {
559
651
  // Projection owns the transform; weave this element's rotate/skew from `values`, through its
560
652
  // Transform template when it has one (#443).
561
- patch.transform = projectedTransformOf(projection, values)
653
+ put(patch, drawn, "transform", projectedTransformOf(projection, values))
562
654
  // Copy non-transform style keys (transform keys are consumed by the weave /
563
655
  // owned by the projection; the reserved keys never render).
564
656
  for (const key in values) {
565
657
  if (key === Projection.KEY || key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
566
- patch[key] = formatStyleValue(key, values[key])
658
+ put(patch, drawn, key, formatStyleValue(key, values[key]))
567
659
  }
568
660
  // Shared-element crossfade (ADR-0010): compose the crossfade factor with the
569
661
  // user's opacity — `finalOpacity = (userOpacity ?? 1) × factor`. Pure: both
570
662
  // values are already in the value-map (like buildProjectionTransform above).
571
663
  // A Switch's blended opacity is drawn as it is (ADR-0010, *Amendment (#166)*).
572
664
  const opacity = projectedOpacity(projection, values)
573
- if (Predicate.isNotUndefined(opacity)) patch.opacity = opacity
665
+ if (Predicate.isNotUndefined(opacity)) put(patch, drawn, "opacity", opacity)
574
666
  // A dragged node's raise (ADR-0016 *Amendment (Reorder)*): kebab-case, as the
575
667
  // scale correctors' keys are, so the commit's `setProperty` takes it.
576
- if (Predicate.isNotUndefined(projection.raise)) patch["z-index"] = projection.raise
668
+ if (Predicate.isNotUndefined(projection.raise)) put(patch, drawn, "z-index", projection.raise)
577
669
  // A Follower takes no pointer input (`Projection`'s `passesPointer`, ADR-0010, *Amendment
578
670
  // (#165)*; Motion's): `pointer-events: none`. A Lead's write leaves the key out, and the gate
579
671
  // gives the element its own value back.
580
- if (projection.passesPointer === true) patch["pointer-events"] = "none"
581
- return patch
672
+ if (projection.passesPointer === true) put(patch, drawn, "pointer-events", "none")
673
+ return
582
674
  }
583
675
 
584
676
  // Grouped transform: the present keys in the canonical order, through the Transform template
585
677
  // when the element has one (#443).
586
678
  const transform = drawnTransformOf(values)
587
- if (Predicate.isNotUndefined(transform)) patch.transform = transform
679
+ if (Predicate.isNotUndefined(transform)) put(patch, drawn, "transform", transform)
588
680
 
589
681
  // Non-transform keys: copy across with default-unit handling.
590
682
  for (const key in values) {
591
683
  if (key === TEMPLATE_KEY || TransformKeys.TRANSFORM_KEYS.has(key)) continue
592
- patch[key] = formatStyleValue(key, values[key])
684
+ put(patch, drawn, key, formatStyleValue(key, values[key]))
593
685
  }
686
+ }
594
687
 
595
- return patch
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
+ }
596
713
  }
597
714
 
598
715
  /**
@@ -621,6 +738,10 @@ const writeStyle = (style: CSSStyleDeclaration, patch: Record<string, unknown>):
621
738
  for (const key in patch) style.setProperty(dashCase(key), String(patch[key]))
622
739
  }
623
740
 
624
- /** Core's `Renderer` for the DOM: `project` and a `commit` that writes a patch onto an element's style. It needs nothing. */
625
- // `project` and `commit` have no service dependencies, so this is a plain `Layer.succeed`.
626
- export const RendererDomLive: Layer.Layer<Renderer.Renderer> = Layer.succeed(Renderer.Renderer, { project, commit })
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))
@@ -86,14 +86,14 @@ export type StyleRecord = Readonly<Record<string, unknown>>
86
86
 
87
87
  /** A style given as CSS text, parsed; a record as it is. */
88
88
  const recordOf = (input: object | string): StyleRecord => {
89
- // Per element at mount (#540): statements.
89
+ // Per Subject at mount (#540): statements.
90
90
  if (Predicate.isString(input)) return parseCssText(input)
91
91
  return input as StyleRecord
92
92
  }
93
93
 
94
94
  /** A style given as CSS text, parsed; a record as it is; none, an empty record. */
95
95
  const recordOfInput = (input: StyleInput): StyleRecord => {
96
- // Per element at mount (#540): statements.
96
+ // Per Subject at mount (#540): statements.
97
97
  if (Predicate.isUndefined(input)) return {}
98
98
  return recordOf(input)
99
99
  }
@@ -135,7 +135,7 @@ export const over: {
135
135
  (that: StyleInput): (self: StyleInput) => StyleRecord
136
136
  (self: StyleInput, that: StyleInput): StyleRecord
137
137
  } = dual(2, (self: StyleInput, that: StyleInput): StyleRecord => {
138
- // Per element at mount (#540): statements.
138
+ // Per Subject at mount (#540): statements.
139
139
  if (Predicate.isUndefined(that)) return recordOfInput(self)
140
140
  if (Predicate.isUndefined(self)) return recordOf(that)
141
141
  return layered(recordOf(self), recordOf(that))
@@ -143,7 +143,7 @@ export const over: {
143
143
 
144
144
  /** Whether `key`, a CSS property, is one of the gate's held patch keys: by its name, or its name dash-cased. */
145
145
  const isHeld = (held: ReadonlyArray<string>, key: string): boolean => {
146
- // Per element at mount (#540): a loop.
146
+ // Per Subject at mount (#540): a loop.
147
147
  for (const patchKey of held) {
148
148
  if (patchKey === key || dashCase(patchKey) === key) return true
149
149
  }
@@ -163,7 +163,7 @@ export const without: {
163
163
  (held: ReadonlyArray<string>): (self: StyleInput) => StyleRecord
164
164
  (self: StyleInput, held: ReadonlyArray<string>): StyleRecord
165
165
  } = dual(2, (self: StyleInput, held: ReadonlyArray<string>): StyleRecord => {
166
- // Per element at mount (#540): a loop.
166
+ // Per Subject at mount (#540): a loop.
167
167
  const record = recordOfInput(self)
168
168
  const out: Record<string, unknown> = {}
169
169
  for (const key of Object.keys(record)) {
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * The DOM's transform keys, each with its identity: core's (`BaseValue.TRANSFORM_IDENTITY`), and the DOM's
3
- * own, `transformPerspective`, a depth no other Environment draws. Every DOM reader of a transform key
4
- * reads this table, so the DOM's own keys are transforms to each of them: the renderer, Own values, a
5
- * Batch's members, Appear, reduced motion and the Default transition.
3
+ * own, which no other Environment draws as the DOM does: `translateX`, `translateY` and `translateZ` beside
4
+ * `x`, `y` and `z`, the turn in the page's plane (`rotate`), the skews and the element's own depth
5
+ * (`transformPerspective`). Every DOM reader of a transform key reads this table, so the DOM's own keys
6
+ * are transforms to each of them: the renderer, Own values, a Batch's members, Appear, reduced motion and
7
+ * the Default transition.
6
8
  *
7
9
  * @module
8
10
  */
9
11
  // #887 (ADR-0073, *Amendment (#887)*, Q1): core names no key only the page draws. As `positional-keys.ts`
10
- // adds the box's keys to core's transforms, this adds the DOM's own transform keys to core's. #1002 would
11
- // move here, at a major, the six of core's that only the DOM draws. TK1 pins that no dom source reads
12
- // core's table but this module.
12
+ // adds the box's keys to core's transforms, this adds the DOM's own transform keys to core's: the depth
13
+ // (#887), and the six core named until #1002 (ADR-0073, *Amendment (#1002)*), Motion's names, which came
14
+ // over with its list in #47. TK1 pins that no dom source reads core's table but this module.
13
15
  import * as BaseValue from "@wardic/core/BaseValue"
14
16
  import * as Option from "effect/Option"
15
17
  import * as Predicate from "effect/Predicate"
@@ -19,10 +21,20 @@ import * as Rec from "effect/Record"
19
21
  export const PERSPECTIVE = "transformPerspective"
20
22
 
21
23
  /**
22
- * Each of the DOM's transform keys, with its identity: core's, and {@link PERSPECTIVE}'s 0. That 0 is no
23
- * perspective, not a depth: it's left out of the transform, as Motion's is.
24
+ * Each of the DOM's transform keys, with its identity: core's, and the DOM's own 0s, no translation, turn
25
+ * or skew. {@link PERSPECTIVE}'s 0 is no perspective, not a depth: it's left out of the transform, as
26
+ * Motion's is.
24
27
  */
25
- export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({ ...BaseValue.TRANSFORM_IDENTITY, [PERSPECTIVE]: 0 })
28
+ export const TRANSFORM_IDENTITY: Readonly<Record<string, number>> = Object.freeze({
29
+ ...BaseValue.TRANSFORM_IDENTITY,
30
+ translateX: 0,
31
+ translateY: 0,
32
+ translateZ: 0,
33
+ rotate: 0,
34
+ skewX: 0,
35
+ skewY: 0,
36
+ [PERSPECTIVE]: 0,
37
+ })
26
38
 
27
39
  /** A DOM transform key's identity (see {@link TRANSFORM_IDENTITY}), or `None` for any other key, prototype names included. */
28
40
  export const transformIdentity = (key: string): Option.Option<number> => Rec.get(TRANSFORM_IDENTITY, key)
@@ -1756,7 +1756,7 @@ export const bindBatch = (env: BatchEnv, config: BatchConfig | KeyedBatchConfig<
1756
1756
  watchedOn[i] = el
1757
1757
  const entry = entries[i]
1758
1758
  watch({
1759
- element: () => el,
1759
+ subject: () => el,
1760
1760
  holds: true,
1761
1761
  leave: (custom, release) => memberLeft(i, entry, el, custom, release),
1762
1762
  gone: () => watchGone(i, entry, el),
@@ -878,9 +878,10 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
878
878
  FiberHandle.clear(releasing).pipe(Effect.andThen(measureAtStart), Effect.andThen(Effect.sync(() => follow(sample, state, opts))))),
879
879
  Match.when("move", () =>
880
880
  FiberHandle.clear(releasing).pipe(Effect.andThen(Effect.sync(() => follow(sample, state, opts))))),
881
- // A cancelled end (#431) stays where it is: no release, `x`/`y` handed back.
881
+ // An end drag controls cancelled (#431) stays where it is: no release, `x`/`y` handed back. Any
882
+ // other is released, a pointer's cancel too, which carries no velocity and so doesn't fling (#1042).
882
883
  Match.when("end", () =>
883
- Bool.match(sample.cancelled === true, {
884
+ Bool.match(sample.endedBy === "controls", {
884
885
  onTrue: () => Effect.sync(() => UndefinedOr.match(opts.projection, { onUndefined: () => opts.setDragging(false), onDefined: constVoid })),
885
886
  onFalse: () => releaseFrom(sample),
886
887
  }).pipe(Effect.andThen(Effect.sync(() => reportSample(opts, sample))))),
@@ -239,7 +239,7 @@ const filled = new WeakMap<ValueReads, ElementValueReads>()
239
239
  * nothing.
240
240
  */
241
241
  export const valueReadsOf = (given: ValueReads): ElementValueReads => {
242
- // Per element at mount (#540): statements. `DomLive` gives none: the DOM's, with no lookup.
242
+ // Per Subject at mount (#540): statements. `DomLive` gives none: the DOM's, with no lookup.
243
243
  if (Bool.and(Predicate.isUndefined(given.ownValues), Bool.and(Predicate.isUndefined(given.measuredPairs), Predicate.isUndefined(given.variableValues)))) return DOM_VALUE_READS
244
244
  const kept = filled.get(given)
245
245
  if (Predicate.isNotUndefined(kept)) return kept