@wardic/dom 0.0.0-stage → 1.0.0-rc.10

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 (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/Appear.d.ts +30 -0
  5. package/dist/Appear.d.ts.map +1 -0
  6. package/dist/Appear.js +31 -0
  7. package/dist/Appear.js.map +1 -0
  8. package/dist/Color.d.ts +14 -0
  9. package/dist/Color.d.ts.map +1 -0
  10. package/dist/Color.js +16 -0
  11. package/dist/Color.js.map +1 -0
  12. package/dist/DomAnnouncer.d.ts +13 -0
  13. package/dist/DomAnnouncer.d.ts.map +1 -0
  14. package/dist/DomAnnouncer.js +14 -0
  15. package/dist/DomAnnouncer.js.map +1 -0
  16. package/dist/DomBatch.d.ts +20 -0
  17. package/dist/DomBatch.d.ts.map +1 -0
  18. package/dist/DomBatch.js +23 -0
  19. package/dist/DomBatch.js.map +1 -0
  20. package/dist/DomClock.d.ts +11 -0
  21. package/dist/DomClock.d.ts.map +1 -0
  22. package/dist/DomClock.js +12 -0
  23. package/dist/DomClock.js.map +1 -0
  24. package/dist/DomDefaultTransition.d.ts +12 -0
  25. package/dist/DomDefaultTransition.d.ts.map +1 -0
  26. package/dist/DomDefaultTransition.js +13 -0
  27. package/dist/DomDefaultTransition.js.map +1 -0
  28. package/dist/DomInput.d.ts +14 -0
  29. package/dist/DomInput.d.ts.map +1 -0
  30. package/dist/DomInput.js +17 -0
  31. package/dist/DomInput.js.map +1 -0
  32. package/dist/DomInterpolators.d.ts +13 -0
  33. package/dist/DomInterpolators.d.ts.map +1 -0
  34. package/dist/DomInterpolators.js +14 -0
  35. package/dist/DomInterpolators.js.map +1 -0
  36. package/dist/DomKeyRules.d.ts +13 -0
  37. package/dist/DomKeyRules.d.ts.map +1 -0
  38. package/dist/DomKeyRules.js +14 -0
  39. package/dist/DomKeyRules.js.map +1 -0
  40. package/dist/DomPositionalKeys.d.ts +13 -0
  41. package/dist/DomPositionalKeys.d.ts.map +1 -0
  42. package/dist/DomPositionalKeys.js +14 -0
  43. package/dist/DomPositionalKeys.js.map +1 -0
  44. package/dist/DomProbe.d.ts +13 -0
  45. package/dist/DomProbe.d.ts.map +1 -0
  46. package/dist/DomProbe.js +14 -0
  47. package/dist/DomProbe.js.map +1 -0
  48. package/dist/DomProjectionSystem.d.ts +28 -0
  49. package/dist/DomProjectionSystem.d.ts.map +1 -0
  50. package/dist/DomProjectionSystem.js +41 -0
  51. package/dist/DomProjectionSystem.js.map +1 -0
  52. package/dist/DomRenderer.d.ts +13 -0
  53. package/dist/DomRenderer.d.ts.map +1 -0
  54. package/dist/DomRenderer.js +15 -0
  55. package/dist/DomRenderer.js.map +1 -0
  56. package/dist/DomScrollSource.d.ts +14 -0
  57. package/dist/DomScrollSource.d.ts.map +1 -0
  58. package/dist/DomScrollSource.js +15 -0
  59. package/dist/DomScrollSource.js.map +1 -0
  60. package/dist/FlushGate.d.ts +48 -0
  61. package/dist/FlushGate.d.ts.map +1 -0
  62. package/dist/FlushGate.js +62 -0
  63. package/dist/FlushGate.js.map +1 -0
  64. package/dist/KeyboardPress.d.ts +16 -0
  65. package/dist/KeyboardPress.d.ts.map +1 -0
  66. package/dist/KeyboardPress.js +17 -0
  67. package/dist/KeyboardPress.js.map +1 -0
  68. package/dist/MeasuredPair.d.ts +14 -0
  69. package/dist/MeasuredPair.d.ts.map +1 -0
  70. package/dist/MeasuredPair.js +16 -0
  71. package/dist/MeasuredPair.js.map +1 -0
  72. package/dist/OwnValues.d.ts +14 -0
  73. package/dist/OwnValues.d.ts.map +1 -0
  74. package/dist/OwnValues.js +15 -0
  75. package/dist/OwnValues.js.map +1 -0
  76. package/dist/ProjectionSystem.d.ts +34 -0
  77. package/dist/ProjectionSystem.d.ts.map +1 -0
  78. package/dist/ProjectionSystem.js +29 -0
  79. package/dist/ProjectionSystem.js.map +1 -0
  80. package/dist/ReorderController.d.ts +61 -0
  81. package/dist/ReorderController.d.ts.map +1 -0
  82. package/dist/ReorderController.js +78 -0
  83. package/dist/ReorderController.js.map +1 -0
  84. package/dist/Report.d.ts +12 -0
  85. package/dist/Report.d.ts.map +1 -0
  86. package/dist/Report.js +13 -0
  87. package/dist/Report.js.map +1 -0
  88. package/dist/ScrollOffset.d.ts +34 -0
  89. package/dist/ScrollOffset.d.ts.map +1 -0
  90. package/dist/ScrollOffset.js +42 -0
  91. package/dist/ScrollOffset.js.map +1 -0
  92. package/dist/Style.d.ts +15 -0
  93. package/dist/Style.d.ts.map +1 -0
  94. package/dist/Style.js +17 -0
  95. package/dist/Style.js.map +1 -0
  96. package/dist/Svg.d.ts +13 -0
  97. package/dist/Svg.d.ts.map +1 -0
  98. package/dist/Svg.js +14 -0
  99. package/dist/Svg.js.map +1 -0
  100. package/dist/Variables.d.ts +13 -0
  101. package/dist/Variables.d.ts.map +1 -0
  102. package/dist/Variables.js +14 -0
  103. package/dist/Variables.js.map +1 -0
  104. package/dist/index.d.ts +83 -0
  105. package/dist/index.d.ts.map +1 -0
  106. package/dist/index.js +71 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/internal/announcer.d.ts +50 -0
  109. package/dist/internal/announcer.d.ts.map +1 -0
  110. package/dist/internal/announcer.js +115 -0
  111. package/dist/internal/announcer.js.map +1 -0
  112. package/dist/internal/appear-slot.d.ts +23 -0
  113. package/dist/internal/appear-slot.d.ts.map +1 -0
  114. package/dist/internal/appear-slot.js +29 -0
  115. package/dist/internal/appear-slot.js.map +1 -0
  116. package/dist/internal/appear.d.ts +237 -0
  117. package/dist/internal/appear.d.ts.map +1 -0
  118. package/dist/internal/appear.js +740 -0
  119. package/dist/internal/appear.js.map +1 -0
  120. package/dist/internal/auto-scroll.d.ts +24 -0
  121. package/dist/internal/auto-scroll.d.ts.map +1 -0
  122. package/dist/internal/auto-scroll.js +124 -0
  123. package/dist/internal/auto-scroll.js.map +1 -0
  124. package/dist/internal/batch-writer.d.ts +16 -0
  125. package/dist/internal/batch-writer.d.ts.map +1 -0
  126. package/dist/internal/batch-writer.js +77 -0
  127. package/dist/internal/batch-writer.js.map +1 -0
  128. package/dist/internal/clock.d.ts +19 -0
  129. package/dist/internal/clock.d.ts.map +1 -0
  130. package/dist/internal/clock.js +39 -0
  131. package/dist/internal/clock.js.map +1 -0
  132. package/dist/internal/colors.d.ts +45 -0
  133. package/dist/internal/colors.d.ts.map +1 -0
  134. package/dist/internal/colors.js +193 -0
  135. package/dist/internal/colors.js.map +1 -0
  136. package/dist/internal/complex.d.ts +24 -0
  137. package/dist/internal/complex.d.ts.map +1 -0
  138. package/dist/internal/complex.js +28 -0
  139. package/dist/internal/complex.js.map +1 -0
  140. package/dist/internal/content-watch.d.ts +20 -0
  141. package/dist/internal/content-watch.d.ts.map +1 -0
  142. package/dist/internal/content-watch.js +76 -0
  143. package/dist/internal/content-watch.js.map +1 -0
  144. package/dist/internal/default-transition.d.ts +25 -0
  145. package/dist/internal/default-transition.d.ts.map +1 -0
  146. package/dist/internal/default-transition.js +41 -0
  147. package/dist/internal/default-transition.js.map +1 -0
  148. package/dist/internal/drag-defaults.d.ts +18 -0
  149. package/dist/internal/drag-defaults.d.ts.map +1 -0
  150. package/dist/internal/drag-defaults.js +38 -0
  151. package/dist/internal/drag-defaults.js.map +1 -0
  152. package/dist/internal/gate.d.ts +188 -0
  153. package/dist/internal/gate.d.ts.map +1 -0
  154. package/dist/internal/gate.js +458 -0
  155. package/dist/internal/gate.js.map +1 -0
  156. package/dist/internal/input.d.ts +35 -0
  157. package/dist/internal/input.d.ts.map +1 -0
  158. package/dist/internal/input.js +658 -0
  159. package/dist/internal/input.js.map +1 -0
  160. package/dist/internal/interpolators.d.ts +19 -0
  161. package/dist/internal/interpolators.d.ts.map +1 -0
  162. package/dist/internal/interpolators.js +30 -0
  163. package/dist/internal/interpolators.js.map +1 -0
  164. package/dist/internal/key-rules.d.ts +11 -0
  165. package/dist/internal/key-rules.d.ts.map +1 -0
  166. package/dist/internal/key-rules.js +244 -0
  167. package/dist/internal/key-rules.js.map +1 -0
  168. package/dist/internal/keyboard-press.d.ts +7 -0
  169. package/dist/internal/keyboard-press.d.ts.map +1 -0
  170. package/dist/internal/keyboard-press.js +45 -0
  171. package/dist/internal/keyboard-press.js.map +1 -0
  172. package/dist/internal/measure.d.ts +157 -0
  173. package/dist/internal/measure.d.ts.map +1 -0
  174. package/dist/internal/measure.js +296 -0
  175. package/dist/internal/measure.js.map +1 -0
  176. package/dist/internal/measured-pairs.d.ts +38 -0
  177. package/dist/internal/measured-pairs.d.ts.map +1 -0
  178. package/dist/internal/measured-pairs.js +251 -0
  179. package/dist/internal/measured-pairs.js.map +1 -0
  180. package/dist/internal/own-values.d.ts +35 -0
  181. package/dist/internal/own-values.d.ts.map +1 -0
  182. package/dist/internal/own-values.js +117 -0
  183. package/dist/internal/own-values.js.map +1 -0
  184. package/dist/internal/pass-ends.d.ts +21 -0
  185. package/dist/internal/pass-ends.d.ts.map +1 -0
  186. package/dist/internal/pass-ends.js +14 -0
  187. package/dist/internal/pass-ends.js.map +1 -0
  188. package/dist/internal/positional-keys.d.ts +16 -0
  189. package/dist/internal/positional-keys.d.ts.map +1 -0
  190. package/dist/internal/positional-keys.js +21 -0
  191. package/dist/internal/positional-keys.js.map +1 -0
  192. package/dist/internal/probe.d.ts +10 -0
  193. package/dist/internal/probe.d.ts.map +1 -0
  194. package/dist/internal/probe.js +116 -0
  195. package/dist/internal/probe.js.map +1 -0
  196. package/dist/internal/projection-defaults.d.ts +34 -0
  197. package/dist/internal/projection-defaults.d.ts.map +1 -0
  198. package/dist/internal/projection-defaults.js +21 -0
  199. package/dist/internal/projection-defaults.js.map +1 -0
  200. package/dist/internal/projection.d.ts +537 -0
  201. package/dist/internal/projection.d.ts.map +1 -0
  202. package/dist/internal/projection.js +5228 -0
  203. package/dist/internal/projection.js.map +1 -0
  204. package/dist/internal/renderer.d.ts +104 -0
  205. package/dist/internal/renderer.d.ts.map +1 -0
  206. package/dist/internal/renderer.js +618 -0
  207. package/dist/internal/renderer.js.map +1 -0
  208. package/dist/internal/reorder.d.ts +174 -0
  209. package/dist/internal/reorder.d.ts.map +1 -0
  210. package/dist/internal/reorder.js +466 -0
  211. package/dist/internal/reorder.js.map +1 -0
  212. package/dist/internal/report.d.ts +30 -0
  213. package/dist/internal/report.d.ts.map +1 -0
  214. package/dist/internal/report.js +60 -0
  215. package/dist/internal/report.js.map +1 -0
  216. package/dist/internal/require-global.d.ts +11 -0
  217. package/dist/internal/require-global.d.ts.map +1 -0
  218. package/dist/internal/require-global.js +31 -0
  219. package/dist/internal/require-global.js.map +1 -0
  220. package/dist/internal/reveal.d.ts +20 -0
  221. package/dist/internal/reveal.d.ts.map +1 -0
  222. package/dist/internal/reveal.js +71 -0
  223. package/dist/internal/reveal.js.map +1 -0
  224. package/dist/internal/runner.d.ts +21 -0
  225. package/dist/internal/runner.d.ts.map +1 -0
  226. package/dist/internal/runner.js +48 -0
  227. package/dist/internal/runner.js.map +1 -0
  228. package/dist/internal/scale-correction.d.ts +80 -0
  229. package/dist/internal/scale-correction.d.ts.map +1 -0
  230. package/dist/internal/scale-correction.js +227 -0
  231. package/dist/internal/scale-correction.js.map +1 -0
  232. package/dist/internal/scroll.d.ts +37 -0
  233. package/dist/internal/scroll.d.ts.map +1 -0
  234. package/dist/internal/scroll.js +279 -0
  235. package/dist/internal/scroll.js.map +1 -0
  236. package/dist/internal/scrollers.d.ts +35 -0
  237. package/dist/internal/scrollers.d.ts.map +1 -0
  238. package/dist/internal/scrollers.js +38 -0
  239. package/dist/internal/scrollers.js.map +1 -0
  240. package/dist/internal/starting-style.d.ts +141 -0
  241. package/dist/internal/starting-style.d.ts.map +1 -0
  242. package/dist/internal/starting-style.js +300 -0
  243. package/dist/internal/starting-style.js.map +1 -0
  244. package/dist/internal/svg.d.ts +60 -0
  245. package/dist/internal/svg.d.ts.map +1 -0
  246. package/dist/internal/svg.js +257 -0
  247. package/dist/internal/svg.js.map +1 -0
  248. package/dist/internal/variables.d.ts +45 -0
  249. package/dist/internal/variables.d.ts.map +1 -0
  250. package/dist/internal/variables.js +92 -0
  251. package/dist/internal/variables.js.map +1 -0
  252. package/package.json +65 -4
  253. package/src/Appear.ts +54 -0
  254. package/src/Color.ts +24 -0
  255. package/src/DomAnnouncer.ts +22 -0
  256. package/src/DomBatch.ts +22 -0
  257. package/src/DomClock.ts +13 -0
  258. package/src/DomDefaultTransition.ts +16 -0
  259. package/src/DomInput.ts +23 -0
  260. package/src/DomInterpolators.ts +16 -0
  261. package/src/DomKeyRules.ts +17 -0
  262. package/src/DomPositionalKeys.ts +16 -0
  263. package/src/DomProbe.ts +15 -0
  264. package/src/DomProjectionSystem.ts +44 -0
  265. package/src/DomRenderer.ts +26 -0
  266. package/src/DomScrollSource.ts +14 -0
  267. package/src/FlushGate.ts +81 -0
  268. package/src/KeyboardPress.ts +16 -0
  269. package/src/MeasuredPair.ts +15 -0
  270. package/src/OwnValues.ts +19 -0
  271. package/src/ProjectionSystem.ts +51 -0
  272. package/src/ReorderController.ts +122 -0
  273. package/src/Report.ts +17 -0
  274. package/src/ScrollOffset.ts +54 -0
  275. package/src/Style.ts +37 -0
  276. package/src/Svg.ts +21 -0
  277. package/src/Variables.ts +17 -0
  278. package/src/index.ts +120 -0
  279. package/src/internal/announcer.ts +132 -0
  280. package/src/internal/appear-slot.ts +32 -0
  281. package/src/internal/appear.ts +1134 -0
  282. package/src/internal/auto-scroll.ts +176 -0
  283. package/src/internal/batch-writer.ts +95 -0
  284. package/src/internal/clock.ts +45 -0
  285. package/src/internal/colors.ts +258 -0
  286. package/src/internal/complex.ts +29 -0
  287. package/src/internal/content-watch.ts +84 -0
  288. package/src/internal/culori.d.ts +58 -0
  289. package/src/internal/default-transition.ts +50 -0
  290. package/src/internal/drag-defaults.ts +54 -0
  291. package/src/internal/gate.ts +598 -0
  292. package/src/internal/input.ts +763 -0
  293. package/src/internal/interpolators.ts +33 -0
  294. package/src/internal/key-rules.ts +357 -0
  295. package/src/internal/keyboard-press.ts +45 -0
  296. package/src/internal/measure.ts +373 -0
  297. package/src/internal/measured-pairs.ts +297 -0
  298. package/src/internal/own-values.ts +166 -0
  299. package/src/internal/pass-ends.ts +23 -0
  300. package/src/internal/positional-keys.ts +24 -0
  301. package/src/internal/probe.ts +175 -0
  302. package/src/internal/projection-defaults.ts +45 -0
  303. package/src/internal/projection.ts +6233 -0
  304. package/src/internal/renderer.ts +648 -0
  305. package/src/internal/reorder.ts +650 -0
  306. package/src/internal/report.ts +69 -0
  307. package/src/internal/require-global.ts +46 -0
  308. package/src/internal/reveal.ts +75 -0
  309. package/src/internal/runner.ts +64 -0
  310. package/src/internal/scale-correction.ts +310 -0
  311. package/src/internal/scroll.ts +358 -0
  312. package/src/internal/scrollers.ts +51 -0
  313. package/src/internal/starting-style.ts +396 -0
  314. package/src/internal/svg.ts +300 -0
  315. package/src/internal/variables.ts +145 -0
@@ -0,0 +1,648 @@
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
+ import type * as Point from "@wardic/core/Point"
22
+ import * as Projection from "@wardic/core/Projection"
23
+ import * as Renderer from "@wardic/core/Renderer"
24
+ import { dashCase, isSvgInner, setSvgAttrs, splitPatch } from "./svg.ts"
25
+ import * as Bool from "effect/Boolean"
26
+ import * as Layer from "effect/Layer"
27
+ import * as Predicate from "effect/Predicate"
28
+ import * as UndefinedOr from "effect/UndefinedOr"
29
+
30
+ /**
31
+ * CSS transform functions in their canonical emission order: translate group,
32
+ * then scale, then rotate, then skew. `project` walks this list and emits a
33
+ * func for each key that is present in `values` and not at its identity, so the
34
+ * resulting `transform` string is always grouped in this order regardless of
35
+ * input key order.
36
+ *
37
+ * `key` is the property name accepted on engine values (shorthands `x`/`y`/`z`
38
+ * included); `fn` is the CSS function name it renders as; `identity` is core's
39
+ * (ADR-0022), the value at which `project` leaves the key out (ADR-0023).
40
+ */
41
+ // Exported for the Batch writer (#665), which draws a member's transform in the same order.
42
+ export const TRANSFORM_FUNCS: ReadonlyArray<{ readonly key: string; readonly fn: string; readonly identity: number }> = [
43
+ // translate group — shorthands x/y/z map onto translateX/Y/Z
44
+ { key: "x", fn: "translateX" },
45
+ { key: "y", fn: "translateY" },
46
+ { key: "z", fn: "translateZ" },
47
+ { key: "translateX", fn: "translateX" },
48
+ { key: "translateY", fn: "translateY" },
49
+ { key: "translateZ", fn: "translateZ" },
50
+ // scale group — `scale` is uniform scale(v); scaleX/scaleY are per-axis (flip)
51
+ { key: "scale", fn: "scale" },
52
+ { key: "scaleX", fn: "scaleX" },
53
+ { key: "scaleY", fn: "scaleY" },
54
+ // rotate group: a path's turn after the element's own (#438), which `rotate(a) rotate(b)` adds up
55
+ { key: "rotate", fn: "rotate" },
56
+ { key: "pathRotation", fn: "rotate" },
57
+ { key: "rotateX", fn: "rotateX" },
58
+ { key: "rotateY", fn: "rotateY" },
59
+ { key: "rotateZ", fn: "rotateZ" },
60
+ // skew group
61
+ { key: "skewX", fn: "skewX" },
62
+ { key: "skewY", fn: "skewY" },
63
+ ].map((f) => ({ ...f, identity: UndefinedOr.getOrThrow(BaseValue.TRANSFORM_IDENTITY[f.key]) }))
64
+
65
+ /**
66
+ * Whether a transform value is at its identity (ADR-0023), Motion's test
67
+ * (motion-dom build-transform.ts:42-48 at 16c61222c4166bbef5ff6ab0051192faa79fa8c8):
68
+ * a number equal to it, or a string `parseFloat` takes to it (`"0px"`, `"0%"`,
69
+ * `"0deg"`; never `"calc(0px)"` or `"var(--x)"`). Exact: a settled spring lands on
70
+ * its target, and a value next to the identity mid-flight is still written.
71
+ */
72
+ const isIdentity = (value: unknown, identity: number): boolean => {
73
+ if (Predicate.isNumber(value)) return value === identity
74
+ return Predicate.isString(value) && Number.parseFloat(value) === identity
75
+ }
76
+
77
+ /** `value` when it's a number, else `fallback`. Per frame: an early return, no Option. */
78
+ const numberOr = (value: unknown, fallback: number): number => {
79
+ if (Predicate.isNumber(value)) return value
80
+ return fallback
81
+ }
82
+
83
+ /** Default unit appended to a bare numeric transform value, by transform key. */
84
+ type TransformUnit = "px" | "deg" | ""
85
+
86
+ /**
87
+ * Default-unit map for transform values: translate (and the x/y/z shorthands)
88
+ * are lengths → `px`; rotate/skew are angles → `deg`; scale* are unitless.
89
+ * A value that is already a string is used verbatim (explicit units honoured),
90
+ * so this map only drives the formatting of bare numbers.
91
+ */
92
+ const TRANSFORM_UNITS: Record<string, TransformUnit> = {
93
+ x: "px",
94
+ y: "px",
95
+ z: "px",
96
+ translateX: "px",
97
+ translateY: "px",
98
+ translateZ: "px",
99
+ scale: "",
100
+ scaleX: "",
101
+ scaleY: "",
102
+ rotate: "deg",
103
+ pathRotation: "deg",
104
+ rotateX: "deg",
105
+ rotateY: "deg",
106
+ rotateZ: "deg",
107
+ skewX: "deg",
108
+ skewY: "deg",
109
+ }
110
+
111
+ /**
112
+ * Fast membership test for "is this key a transform key?": core's transform keys, the ones
113
+ * it gives an identity (ADR-0022), so the two lists can't drift. Every one has a unit above.
114
+ */
115
+ const TRANSFORM_KEYS: ReadonlySet<string> = new Set(Object.keys(BaseValue.TRANSFORM_IDENTITY))
116
+
117
+ /**
118
+ * The CSS properties a bare number on is a length, drawn in `px`, spelled as Wardic's keys are
119
+ * (`margin-top`): Motion's, and `min-width`, `min-height`, the gaps and `letter-spacing`. The Solid
120
+ * bindings' value types take a number on these and on no other length, so a number never draws CSS a
121
+ * browser drops. `line-height` isn't one: CSS reads its bare number as a multiple. A number on any other
122
+ * key, `opacity`, `z-index`, a custom property, is drawn as it is; a string always is.
123
+ */
124
+ // #522: Motion's `numberValueTypes`' `px` keys; the bindings' `WardicValues`.
125
+ export const LENGTH_KEYS = [
126
+ "border-width",
127
+ "border-top-width",
128
+ "border-right-width",
129
+ "border-bottom-width",
130
+ "border-left-width",
131
+ "border-radius",
132
+ "border-top-left-radius",
133
+ "border-top-right-radius",
134
+ "border-bottom-right-radius",
135
+ "border-bottom-left-radius",
136
+ "width",
137
+ "min-width",
138
+ "max-width",
139
+ "height",
140
+ "min-height",
141
+ "max-height",
142
+ "top",
143
+ "right",
144
+ "bottom",
145
+ "left",
146
+ "inset",
147
+ "inset-block",
148
+ "inset-block-start",
149
+ "inset-block-end",
150
+ "inset-inline",
151
+ "inset-inline-start",
152
+ "inset-inline-end",
153
+ "padding",
154
+ "padding-top",
155
+ "padding-right",
156
+ "padding-bottom",
157
+ "padding-left",
158
+ "padding-block",
159
+ "padding-block-start",
160
+ "padding-block-end",
161
+ "padding-inline",
162
+ "padding-inline-start",
163
+ "padding-inline-end",
164
+ "margin",
165
+ "margin-top",
166
+ "margin-right",
167
+ "margin-bottom",
168
+ "margin-left",
169
+ "margin-block",
170
+ "margin-block-start",
171
+ "margin-block-end",
172
+ "margin-inline",
173
+ "margin-inline-start",
174
+ "margin-inline-end",
175
+ "gap",
176
+ "row-gap",
177
+ "column-gap",
178
+ "font-size",
179
+ "letter-spacing",
180
+ "background-position-x",
181
+ "background-position-y",
182
+ ] as const
183
+
184
+ /** One of `LENGTH_KEYS`: a CSS property a bare number on is drawn in `px`. */
185
+ export type LengthKey = (typeof LENGTH_KEYS)[number]
186
+
187
+ /** {@link LENGTH_KEYS}, for a membership test a frame can make. */
188
+ const LENGTH_KEY_SET: ReadonlySet<string> = new Set(LENGTH_KEYS)
189
+
190
+ /**
191
+ * Format one transform value into its CSS func argument. Strings pass through
192
+ * verbatim (explicit units respected); numbers get the key's default unit.
193
+ */
194
+ const formatTransformValue = (key: string, value: unknown): string => {
195
+ if (Predicate.isString(value)) return value
196
+ if (Predicate.isNumber(value)) return `${value}${unitOf(key)}`
197
+ return String(value)
198
+ }
199
+
200
+ /** A transform key's default unit; none for a key the table doesn't name. */
201
+ // Exported for the Batch writer (#665).
202
+ export const unitOf = (key: string): TransformUnit => {
203
+ const unit: TransformUnit | undefined = TRANSFORM_UNITS[key]
204
+ if (Predicate.isUndefined(unit)) return ""
205
+ return unit
206
+ }
207
+
208
+ /**
209
+ * The unit {@link project} draws a bare number of `key` in: a transform key's (`px`, `deg`, or none
210
+ * for a scale), `px` for a length key, none for the rest. The Appear sampler judges its stops in it
211
+ * (#48, ADR-0044).
212
+ */
213
+ export const drawnUnitOf = (key: string): TransformUnit =>
214
+ Bool.match(LENGTH_KEY_SET.has(key), { onTrue: (): TransformUnit => "px", onFalse: () => unitOf(key) })
215
+
216
+ /**
217
+ * Format one non-transform value. Strings pass through verbatim; numbers on a
218
+ * known length key get `px`; every other number stays raw (unitless).
219
+ */
220
+ const formatStyleValue = (key: string, value: unknown): unknown => {
221
+ if (Predicate.isNumber(value) && LENGTH_KEY_SET.has(key)) return `${value}px`
222
+ return value
223
+ }
224
+
225
+ /**
226
+ * User-animated transform funcs woven INTO a projection transform (ADR-0009,
227
+ * Motion's `buildProjectionTransform`): `rotate`/`skew` compose with a layout
228
+ * projection and are emitted between the inverse-tree-scale and the element
229
+ * scale, each left out at its identity, 0 (ADR-0009 *Amendment (#57)*). The element's own
230
+ * translate is added to the projection's ({@link ownTranslate}, #363), its own
231
+ * `scale`/`scaleX`/`scaleY` multiply the element scale ({@link ownScale}), and `z` is folded
232
+ * into the projection's `translate3d` (handled inline).
233
+ */
234
+ const PROJECTION_WOVEN: ReadonlyArray<{ readonly key: string; readonly fn: string }> = [
235
+ { key: "rotate", fn: "rotate" },
236
+ { key: "pathRotation", fn: "rotate" },
237
+ { key: "rotateX", fn: "rotateX" },
238
+ { key: "rotateY", fn: "rotateY" },
239
+ { key: "rotateZ", fn: "rotateZ" },
240
+ { key: "skewX", fn: "skewX" },
241
+ { key: "skewY", fn: "skewY" },
242
+ ]
243
+
244
+ /**
245
+ * The element's own scale on one axis (ADR-0009 *Amendment (Reorder)*): `scale` times
246
+ * `scaleX` (or `scaleY`), 1 for an absent or non-numeric value. Motion renders a
247
+ * projected node with the delta to its target with the element's own transforms
248
+ * applied (`transformBox(targetWithTransforms, latestValues)`,
249
+ * create-projection-node.ts:1820-1845 at 16c61222c4166bbef5ff6ab0051192faa79fa8c8);
250
+ * scaled about the box centre, that multiplies the element scale by this factor and
251
+ * leaves the translate alone (delta-apply.ts:18-30). So a `whileDrag: { scale }` on a
252
+ * `layout` element shows, and its children scale with it through CSS, as in Motion.
253
+ */
254
+ const ownScale = (latest: Record<string, unknown>, axisKey: "scaleX" | "scaleY"): number =>
255
+ numberOr(latest.scale, 1) * numberOr(latest[axisKey], 1)
256
+
257
+ /**
258
+ * A translate key's pixels on a projected element (#363): a number, or a px string. Another unit
259
+ * (`%`, `rem`) can't be added to the projection's pixel translate without measuring, so it's 0 here,
260
+ * and {@link otherUnitTranslate} draws it as CSS (#594). Per frame.
261
+ */
262
+ const pxOf = (value: unknown): number => {
263
+ if (Predicate.isNumber(value)) return value
264
+ if (!Predicate.isString(value)) return 0
265
+ if (!value.endsWith("px")) return 0
266
+ const px = Number.parseFloat(value)
267
+ if (Number.isFinite(px)) return px
268
+ return 0
269
+ }
270
+
271
+ /**
272
+ * The element's own translate on one axis (#363, ADR-0009 *Amendment (#363)*): `x` plus
273
+ * `translateX` (or `y` plus `translateY`), in page pixels. Motion lays a layout element's own `x`
274
+ * and `y` on its target box (`transformBox(targetWithTransforms, latestValues)`,
275
+ * `applyTransformsToTarget` at 16c6122), so its delta carries them, divided by the tree scale where
276
+ * it's drawn: this is added to the projection's translate the same way. Motion leaves
277
+ * `translateX`/`translateY` out; nothing set on a layout element is dropped here.
278
+ */
279
+ const ownTranslate = (latest: Record<string, unknown>, key: "x" | "y", translateKey: "translateX" | "translateY"): number => pxOf(latest[key]) + pxOf(latest[translateKey])
280
+
281
+ /** A length in another unit than px: `-100%`, `1.5rem`, `50vw`. */
282
+ const OTHER_UNIT = /^-?[\d.]+(?!px$)[a-z%]+$/i
283
+
284
+ /** A translate key's CSS when it's a length in another unit than px (#594), else `0px`: {@link pxOf} reads the rest. */
285
+ const otherUnitOf = (value: unknown): string => {
286
+ if (Predicate.isString(value) && OTHER_UNIT.test(value)) return value
287
+ return "0px"
288
+ }
289
+
290
+ /**
291
+ * One axis pair's CSS translate when either is in another unit than px (#594), else "". The browser
292
+ * resolves it against the element's own box, as it would on a plain element.
293
+ */
294
+ const otherUnitTranslate = (x: unknown, y: unknown): string => {
295
+ const cssX = otherUnitOf(x)
296
+ const cssY = otherUnitOf(y)
297
+ if (cssX === "0px" && cssY === "0px") return ""
298
+ return `translate(${cssX}, ${cssY})`
299
+ }
300
+
301
+ /**
302
+ * An element's own move, from its values: what the renderer draws on top of its projection. A binding
303
+ * hands it to the element's layout node, so a twin, a handover and a follower start from, and are drawn,
304
+ * where it's drawn.
305
+ */
306
+ // `ownTranslate`; #363. Tier 2, for binding authors.
307
+ export const ownTranslateOf = (values: Readonly<Record<string, unknown>>): Point.Point => ({
308
+ x: ownTranslate(values, "x", "translateX"),
309
+ y: ownTranslate(values, "y", "translateY"),
310
+ })
311
+
312
+ /**
313
+ * An element's own scale on each axis, from its values: what the renderer draws on top of its projection.
314
+ * A binding hands it to the element's layout node, so a handover starts from where a twin is drawn, and a
315
+ * follower is drawn where its lead is.
316
+ */
317
+ // `ownScale`; ADR-0010 *Amendment (#8)*. Tier 2, for binding authors.
318
+ export const ownScaleOf = (values: Readonly<Record<string, unknown>>): Point.Point => ({
319
+ x: ownScale(values, "scaleX"),
320
+ y: ownScale(values, "scaleY"),
321
+ })
322
+
323
+ /**
324
+ * An element's own `rotate`, in degrees, from its values: what the renderer weaves into its projection,
325
+ * 0 when it's absent or not a number. A binding hands it to the element's layout node, so a handover
326
+ * blends from a twin's rotation into its own.
327
+ */
328
+ // `ownRotate`; ADR-0010 *Amendment (#166)*. Tier 2, for binding authors.
329
+ export const ownRotateOf = (values: Readonly<Record<string, unknown>>): number => numberOr(values.rotate, 0)
330
+
331
+ /**
332
+ * An element's own opacity, from its values: what the renderer draws, 1 when it's absent or not a
333
+ * number. A binding hands it to the element's layout node, so a handover blends from the leaving
334
+ * element's opacity into it.
335
+ */
336
+ // `ownOpacity`; a Switch (ADR-0010 *Amendment (#166)*). Tier 2, for binding authors.
337
+ export const ownOpacityOf = (values: Readonly<Record<string, unknown>>): number => numberOr(values.opacity, 1)
338
+
339
+ /**
340
+ * Assemble a projection transform string (ADR-0009), ported from Motion's
341
+ * `buildProjectionTransform`: `translate3d` (translation divided by `treeScale`)
342
+ * → inverse tree-scale `scale(1/treeScale)` → woven user `rotate`/`skew` (from
343
+ * `latest`, the element's value-map) → element `scale(delta.scale × treeScale)`.
344
+ * Each term is emitted only when it is non-identity; with nothing to emit the
345
+ * result is `"none"` (an identity projection carrying no woven transform).
346
+ */
347
+ const buildProjectionTransform = (
348
+ delta: Projection.Delta,
349
+ treeScale: Point.Point,
350
+ latest: Readonly<Record<string, unknown>>,
351
+ rotate: number | undefined,
352
+ ): string => {
353
+ const funcs: Array<string> = []
354
+
355
+ // The element's own translate, in page pixels, on the projection's: divided by the tree scale
356
+ // together, as Motion's target box carries it (#363).
357
+ const tx = (delta.x.translate + ownTranslate(latest, "x", "translateX")) / treeScale.x
358
+ const ty = (delta.y.translate + ownTranslate(latest, "y", "translateY")) / treeScale.y
359
+ const z = latest["z"]
360
+ const translateZ = latest["translateZ"]
361
+ if (tx !== 0 || ty !== 0 || (Predicate.isNotUndefined(z) && !isIdentity(z, 0)) || (Predicate.isNotUndefined(translateZ) && !isIdentity(translateZ, 0))) {
362
+ funcs.push(`translate3d(${tx}px, ${ty}px, ${zArgOf(z, translateZ)})`)
363
+ }
364
+
365
+ if (treeScale.x !== 1 || treeScale.y !== 1) {
366
+ funcs.push(`scale(${1 / treeScale.x}, ${1 / treeScale.y})`)
367
+ }
368
+
369
+ for (const { key, fn } of PROJECTION_WOVEN) {
370
+ // A handover's blended rotation stands in for the element's own (ADR-0010, *Amendment (#166)*).
371
+ if (key === "rotate" && Predicate.isNotUndefined(rotate)) {
372
+ if (rotate !== 0) funcs.push(`rotate(${formatTransformValue(key, rotate)})`)
373
+ continue
374
+ }
375
+ if (Object.hasOwn(latest, key) && !isIdentity(latest[key], 0)) funcs.push(`${fn}(${formatTransformValue(key, latest[key])})`)
376
+ }
377
+
378
+ const sx = delta.x.scale * treeScale.x * ownScale(latest, "scaleX")
379
+ const sy = delta.y.scale * treeScale.y * ownScale(latest, "scaleY")
380
+ if (sx !== 1 || sy !== 1) funcs.push(`scale(${sx}, ${sy})`)
381
+
382
+ // An own translate in another unit than px (`x: "-100%"`) can't be added to the projection's pixels,
383
+ // so it's drawn before them, and the browser resolves it against the element's own box (#594). The
384
+ // projection's own math (a handover's start) counts it as 0.
385
+ const ownByUnit = otherUnitTranslate(latest["x"], latest["y"])
386
+ const translateByUnit = otherUnitTranslate(latest["translateX"], latest["translateY"])
387
+ if (translateByUnit !== "") funcs.unshift(translateByUnit)
388
+ if (ownByUnit !== "") funcs.unshift(ownByUnit)
389
+ if (funcs.length === 0) return "none"
390
+ return funcs.join(" ")
391
+ }
392
+
393
+ /**
394
+ * The key an element's transform template rides under in its values, as its projection rides under
395
+ * `Projection.KEY`: `project` calls it for the element's transform. Namespaced, `@transformTemplate`, so
396
+ * it never collides with a CSS property or a value's key.
397
+ */
398
+ // A **Transform template** (#443, Motion's `transformTemplate`). Tier 2, for binding authors.
399
+ export const TEMPLATE_KEY = "@transformTemplate"
400
+
401
+ /**
402
+ * A transform template, as Motion's `transformTemplate`: the element's whole transform, from its values
403
+ * and the transform Wardic would draw (`generated`). `project` calls it:
404
+ * - **at a plain render**, with its transform keys in their units (`x: "10px"`, `rotate: "45deg"`,
405
+ * `scale: 1.5`), and `generated` `""` when every one is at its identity, or it has none;
406
+ * - **while a projection moves it**, with its values as they are (`x: 10`) and the projection's
407
+ * transform; once nothing moves it, as at a plain render;
408
+ * - **held for a measure**, with its values and `""` (`heldTransformOf`).
409
+ *
410
+ * @example
411
+ * const centred: DomRenderer.TransformTemplate = (_values, generated) => `translateX(-50%) ${generated}`
412
+ */
413
+ // A **Transform template** (#443).
414
+ export type TransformTemplate = (values: Readonly<Record<string, string | number>>, generated: string) => string
415
+
416
+ /** `values`' template, or `undefined`: a function under {@link TEMPLATE_KEY}. Per frame: an early return. */
417
+ const templateOf = (values: Record<string, unknown>): TransformTemplate | undefined => {
418
+ const template = values[TEMPLATE_KEY]
419
+ if (Predicate.isFunction(template)) return template as TransformTemplate
420
+ return undefined
421
+ }
422
+
423
+ /**
424
+ * An element's transform keys as a template takes them at a plain render (#443, Motion's
425
+ * `buildTransform`): each one it has, at its identity too, a number in its unit (`x: "10px"`,
426
+ * `rotate: "45deg"`) and a scale's as it is (`1.5`). Not `pathRotation`, which Motion adds to the
427
+ * transform alone (#438). A templated element's, per frame.
428
+ */
429
+ const templateValuesOf = (values: Record<string, unknown>): Record<string, string | number> => {
430
+ const out: Record<string, string | number> = {}
431
+ for (const { key } of TRANSFORM_FUNCS) {
432
+ if (key === "pathRotation" || !Object.hasOwn(values, key)) continue
433
+ const value = values[key]
434
+ out[key] = templateValueOf(key, value)
435
+ }
436
+ return out
437
+ }
438
+
439
+ /** One transform value as a template takes it: a number in its key's unit, a unitless one as it is, a string as it is. */
440
+ const templateValueOf = (key: string, value: unknown): string | number => {
441
+ if (Predicate.isString(value)) return value
442
+ if (!Predicate.isNumber(value)) return String(value)
443
+ const unit = unitOf(key)
444
+ if (unit === "") return value
445
+ return `${value}${unit}`
446
+ }
447
+
448
+ /**
449
+ * An element's values as a template takes them while projected or held (#443, Motion's
450
+ * `latestValues`): every one as it is, but the reserved keys. A templated element's, per frame.
451
+ */
452
+ const rawValuesOf = (values: Record<string, unknown>): Record<string, string | number> => {
453
+ const out: Record<string, string | number> = {}
454
+ for (const key in values) {
455
+ if (key === Projection.KEY || key === TEMPLATE_KEY) continue
456
+ out[key] = values[key] as string | number
457
+ }
458
+ return out
459
+ }
460
+
461
+ /**
462
+ * Whether a projection moves nothing (#443): no delta, no tree scale, no handover's rotation. A
463
+ * templated element it draws is drawn as at a plain render then, as Motion's is once its projection
464
+ * ends (`transformTemplate({}, "")` with no transform key), so a template is never handed `none`.
465
+ */
466
+ const projectsNothing = (projection: Projection.Value): boolean => {
467
+ const { delta, treeScale } = projection
468
+ if (delta.x.translate !== 0 || delta.y.translate !== 0) return false
469
+ if (delta.x.scale !== 1 || delta.y.scale !== 1) return false
470
+ if (treeScale.x !== 1 || treeScale.y !== 1) return false
471
+ return Predicate.isUndefined(projection.rotate)
472
+ }
473
+
474
+ /**
475
+ * The transform keys a plain render draws (ADR-0023): each one present and not at its identity, in
476
+ * the canonical order; `""` when every one present is at its identity; `undefined` with none. Built
477
+ * by concatenation, not an array joined (ADR-0034): this runs per element per frame.
478
+ */
479
+ const plainTransformOf = (values: Record<string, unknown>): string | undefined => {
480
+ let transform = ""
481
+ let separator = ""
482
+ let present = false
483
+ for (const { key, fn, identity } of TRANSFORM_FUNCS) {
484
+ if (!Object.hasOwn(values, key)) continue
485
+ present = true
486
+ const value = values[key]
487
+ if (isIdentity(value, identity)) continue
488
+ transform = `${transform}${separator}${fn}(${formatTransformValue(key, value)})`
489
+ separator = " "
490
+ }
491
+ if (!present) return undefined
492
+ return transform
493
+ }
494
+
495
+ /**
496
+ * The transform an element draws at a plain render, or `undefined` to leave its own: its template's,
497
+ * called with no transform key too, as Motion's is (#443); else its keys', `none` when every one is
498
+ * at its identity (ADR-0023), so a class's transform stays overridden and its last one doesn't stay
499
+ * inline. Per frame: early returns.
500
+ */
501
+ const drawnTransformOf = (values: Record<string, unknown>): string | undefined => {
502
+ const template = templateOf(values)
503
+ if (Predicate.isNotUndefined(template)) return templatedPlain(template, values)
504
+ const transform = plainTransformOf(values)
505
+ if (transform === "") return "none"
506
+ return transform
507
+ }
508
+
509
+ /**
510
+ * A templated element's transform at a plain render (#443): its template's, from its keys and the
511
+ * transform Wardic would draw, `""` when that's nothing.
512
+ */
513
+ const templatedPlain = (template: TransformTemplate, values: Record<string, unknown>): string => {
514
+ const generated = plainTransformOf(values)
515
+ if (Predicate.isUndefined(generated)) return template(templateValuesOf(values), "")
516
+ return template(templateValuesOf(values), generated)
517
+ }
518
+
519
+ /**
520
+ * The transform a projected element draws (ADR-0009): its projection's, through its template while
521
+ * the projection moves it, and as at a plain render once nothing does (#443). Per frame: early returns.
522
+ */
523
+ const projectedTransformOf = (projection: Projection.Value, values: Record<string, unknown>): string => {
524
+ const template = templateOf(values)
525
+ if (Predicate.isUndefined(template)) return buildProjectionTransform(projection.delta, projection.treeScale, values, projection.rotate)
526
+ if (projectsNothing(projection)) return templatedPlain(template, values)
527
+ return template(rawValuesOf(values), buildProjectionTransform(projection.delta, projection.treeScale, values, projection.rotate))
528
+ }
529
+
530
+ /**
531
+ * The transform a measure holds an element at, as Motion's `transformTemplate(values, "")`: its
532
+ * template's, with no transform of Wardic's, so a static part of it, centring say, is in the box
533
+ * measured. `""` for an element with none, which the measure clears it to.
534
+ */
535
+ // A Measure pass (#443). Tier 2, for binding authors.
536
+ export const heldTransformOf = (values: Readonly<Record<string, unknown>>): string => {
537
+ const template = templateOf(values as Record<string, unknown>)
538
+ if (Predicate.isUndefined(template)) return ""
539
+ return template(rawValuesOf(values as Record<string, unknown>), "")
540
+ }
541
+
542
+ /** `translate3d`'s z argument: the element's own `z`, plus its `translateZ` in pixels when it has one (#363), else none. */
543
+ const zArgOf = (z: unknown, translateZ: unknown): string => {
544
+ if (Predicate.isNotUndefined(translateZ)) return `${pxOf(z) + pxOf(translateZ)}px`
545
+ if (Predicate.isUndefined(z)) return "0px"
546
+ return formatTransformValue("z", z)
547
+ }
548
+
549
+ /**
550
+ * The opacity a projection draws, or `undefined` to leave the user's own (ADR-0010): a Switch's
551
+ * blended opacity as it is (*Amendment (#166)*), else the crossfade factor times the user's
552
+ * opacity. Per frame: early returns.
553
+ */
554
+ const projectedOpacity = (projection: Projection.Value, values: Record<string, unknown>): number | undefined => {
555
+ if (Predicate.isNotUndefined(projection.blendOpacity)) return projection.blendOpacity
556
+ if (Predicate.isUndefined(projection.opacity)) return undefined
557
+ return numberOr(values.opacity, 1) * projection.opacity
558
+ }
559
+
560
+ /**
561
+ * A Frame's values as a DOM style patch, pure. The transform keys become one `transform`, each left out
562
+ * at its identity, and `none` when every one is; with no transform key there's no `transform`, so a
563
+ * class's shows. A node's projection, when its values carry one under `Projection.KEY`, becomes its
564
+ * transform instead, with the element's own move, rotation, skew and scale drawn on it. Every other key is
565
+ * copied across, a bare number on a length in `px`. A binding's server render, which builds no runtime,
566
+ * projects with it directly.
567
+ *
568
+ * @example
569
+ * DomRenderer.project({ x: 0, scale: 1, width: 200 }) // { transform: "none", width: "200px" }
570
+ */
571
+ // Two modes. PROJECTION (ADR-0009): the transform is assembled by `buildProjectionTransform` from the
572
+ // node's `delta`/`treeScale`, adding the element's own translate (`x`, `y`, `translate*`, #363), weaving
573
+ // its own animated `rotate`/`skew` and multiplying in its own `scale`/`scaleX`/`scaleY`. NORMAL: the
574
+ // value-spine path, `none` at every identity (ADR-0023). The same function `RendererDomLive` provides
575
+ // (ADR-0021, decision 2). Tier 2, for binding authors.
576
+ export const project = (values: Readonly<Record<string, unknown>>): Renderer.Patch => {
577
+ const patch: Renderer.Patch = {}
578
+
579
+ const projection = values[Projection.KEY] as Projection.Value | undefined
580
+ if (Predicate.isNotUndefined(projection)) {
581
+ // Projection owns the transform; weave this element's rotate/skew from `values`, through its
582
+ // Transform template when it has one (#443).
583
+ patch.transform = projectedTransformOf(projection, values)
584
+ // Copy non-transform style keys (transform keys are consumed by the weave /
585
+ // owned by the projection; the reserved keys never render).
586
+ for (const key in values) {
587
+ if (key === Projection.KEY || key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
588
+ patch[key] = formatStyleValue(key, values[key])
589
+ }
590
+ // Shared-element crossfade (ADR-0010): compose the crossfade factor with the
591
+ // user's opacity — `finalOpacity = (userOpacity ?? 1) × factor`. Pure: both
592
+ // values are already in the value-map (like buildProjectionTransform above).
593
+ // A Switch's blended opacity is drawn as it is (ADR-0010, *Amendment (#166)*).
594
+ const opacity = projectedOpacity(projection, values)
595
+ if (Predicate.isNotUndefined(opacity)) patch.opacity = opacity
596
+ // A dragged node's raise (ADR-0016 *Amendment (Reorder)*): kebab-case, as the
597
+ // scale correctors' keys are, so the commit's `setProperty` takes it.
598
+ if (Predicate.isNotUndefined(projection.raise)) patch["z-index"] = projection.raise
599
+ // A Follower takes no pointer input (`Projection`'s `passesPointer`, ADR-0010, *Amendment
600
+ // (#165)*; Motion's): `pointer-events: none`. A Lead's write leaves the key out, and the gate
601
+ // gives the element its own value back.
602
+ if (projection.passesPointer === true) patch["pointer-events"] = "none"
603
+ return patch
604
+ }
605
+
606
+ // Grouped transform: the present keys in the canonical order, through the Transform template
607
+ // when the element has one (#443).
608
+ const transform = drawnTransformOf(values)
609
+ if (Predicate.isNotUndefined(transform)) patch.transform = transform
610
+
611
+ // Non-transform keys: copy across with default-unit handling.
612
+ for (const key in values) {
613
+ if (key === TEMPLATE_KEY || TRANSFORM_KEYS.has(key)) continue
614
+ patch[key] = formatStyleValue(key, values[key])
615
+ }
616
+
617
+ return patch
618
+ }
619
+
620
+ /**
621
+ * Imperative: write a `Patch` onto `target`, now. The engine treats `target` as
622
+ * opaque; the DOM renderer narrows it to an `HTMLElement`/`SVGElement`. CSS keys go
623
+ * through `setProperty` (dash-cased so `transform-box` etc. apply — `el.style[kebab]=`
624
+ * silently fails). An svg-inner element's patch is routed first (ADR-0014,
625
+ * {@link splitPatch}): its attribute keys via `setAttribute`.
626
+ *
627
+ * On the per-frame path (ADR-0034): an HTML element's patch is written as it is, with no
628
+ * routing objects, and each key's dash-cased name is cached. Quiet — no span/log.
629
+ */
630
+ const commit = (target: unknown, patch: Renderer.Patch): void => {
631
+ const el = target as Element & { style: CSSStyleDeclaration }
632
+ if (isSvgInner(el)) {
633
+ const { style, attrs } = splitPatch(el, patch)
634
+ writeStyle(el.style, style)
635
+ setSvgAttrs(el, attrs)
636
+ return
637
+ }
638
+ writeStyle(el.style, patch)
639
+ }
640
+
641
+ /** Each key of `patch` onto `style`, through `setProperty`. */
642
+ const writeStyle = (style: CSSStyleDeclaration, patch: Record<string, unknown>): void => {
643
+ for (const key in patch) style.setProperty(dashCase(key), String(patch[key]))
644
+ }
645
+
646
+ /** Core's `Renderer` for the DOM: `project` and a `commit` that writes a patch onto an element's style. It needs nothing. */
647
+ // `project` and `commit` have no service dependencies, so this is a plain `Layer.succeed`.
648
+ export const RendererDomLive: Layer.Layer<Renderer.Renderer> = Layer.succeed(Renderer.Renderer, { project, commit })