@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
package/src/index.ts ADDED
@@ -0,0 +1,120 @@
1
+ /**
2
+ * `@wardic/dom`: the browser Environment, and the framework-free pieces a binding builds on. It's for
3
+ * binding authors, Wardic's own and any other, and it's Effect-typed.
4
+ *
5
+ * - **An app** imports {@link DomLive}, the composed Environment it hands its binding,
6
+ * {@link CheckFrames}, to check its Frames in development, and {@link FrameLoopMetrics}, to record the
7
+ * Frame loop's metrics.
8
+ * - **A binding** imports each module by its subpath, as a namespace
9
+ * (`import * as FlushGate from "@wardic/dom/FlushGate"`), and the root re-exports each one:
10
+ * - the DOM's implementations of core's services, each with its `layer` (Effect's platform
11
+ * convention: `DomRenderer`, `DomInput`, `DomProbe`, `DomScrollSource`, `DomClock`, `DomAnnouncer`,
12
+ * `DomInterpolators`, `DomPositionalKeys`, `DomDefaultTransition`), and `DomKeyRules`, the Key
13
+ * rules `DomInterpolators.layer` installs, which has none of its own;
14
+ * - dom's own concepts, by the glossary's names: `FlushGate`, `ProjectionSystem`,
15
+ * `ReorderController`, `Style`, `Svg`, `Color`, `Variables`, `ScrollOffset`, `Appear`, `OwnValues`,
16
+ * `KeyboardPress` and `Report`.
17
+ *
18
+ * Everything under `internal/` is dom's own and not exported.
19
+ */
20
+ // `@wardic/dom` (#132, ADR-0041), Tier 2 (ADR-0008); CheckFrames re-exported for an app (#586), and
21
+ // FrameLoopMetrics (#518).
22
+ import type * as Clock from "@wardic/core/Clock"
23
+ import * as FrameLoop from "@wardic/core/FrameLoop"
24
+ import type * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
25
+ import type * as Announcer from "@wardic/core/Announcer"
26
+ import type * as DefaultTransition from "@wardic/core/DefaultTransition"
27
+ import type * as ReducedMotion from "@wardic/core/ReducedMotion"
28
+ import type * as Probe from "@wardic/core/Probe"
29
+ import type * as RefreshFrameSource from "@wardic/core/RefreshFrameSource"
30
+ import type * as Renderer from "@wardic/core/Renderer"
31
+ import * as Layer from "effect/Layer"
32
+ import * as AtomRegistry from "effect/reactivity/AtomRegistry"
33
+ import * as DomAnnouncer from "./DomAnnouncer.ts"
34
+ import * as DomClock from "./DomClock.ts"
35
+ import * as DomDefaultTransition from "./DomDefaultTransition.ts"
36
+ import * as DomInterpolators from "./DomInterpolators.ts"
37
+ import * as DomPositionalKeys from "./DomPositionalKeys.ts"
38
+ import * as DomProbe from "./DomProbe.ts"
39
+ import * as DomRenderer from "./DomRenderer.ts"
40
+
41
+ export const VERSION = "1.0.0-rc.10"
42
+
43
+ export * as DomBatch from "./DomBatch.ts"
44
+ export * as DomClock from "./DomClock.ts"
45
+ export * as DomInput from "./DomInput.ts"
46
+ export * as DomProbe from "./DomProbe.ts"
47
+ export * as DomScrollSource from "./DomScrollSource.ts"
48
+ export * as DomRenderer from "./DomRenderer.ts"
49
+ export * as DomAnnouncer from "./DomAnnouncer.ts"
50
+ export * as DomInterpolators from "./DomInterpolators.ts"
51
+ export * as DomPositionalKeys from "./DomPositionalKeys.ts"
52
+ export * as DomDefaultTransition from "./DomDefaultTransition.ts"
53
+ export * as DomKeyRules from "./DomKeyRules.ts"
54
+ export * as FlushGate from "./FlushGate.ts"
55
+ export * as ProjectionSystem from "./ProjectionSystem.ts"
56
+ export * as DomProjectionSystem from "./DomProjectionSystem.ts"
57
+ export * as ReorderController from "./ReorderController.ts"
58
+ export * as Style from "./Style.ts"
59
+ export * as Svg from "./Svg.ts"
60
+ export * as Color from "./Color.ts"
61
+ export * as Variables from "./Variables.ts"
62
+ export * as ScrollOffset from "./ScrollOffset.ts"
63
+ export * as Appear from "./Appear.ts"
64
+ export * as OwnValues from "./OwnValues.ts"
65
+ export * as KeyboardPress from "./KeyboardPress.ts"
66
+ export * as Report from "./Report.ts"
67
+
68
+ /**
69
+ * Core's development check for Frames that aren't finite (`FrameLoop.CheckFrames`), here for an app,
70
+ * which installs `@wardic/dom` and not `@wardic/core`. Off by default; merged beside {@link DomLive} as
71
+ * `Layer.succeed(CheckFrames, true)`, it fails an animation whose Frame holds a NaN or an Infinity,
72
+ * naming its key and value, where the page would drop it without a word. It checks every Frame, so
73
+ * it's for development: see https://wardic.dev/guides/observability.
74
+ */
75
+ // ADR-0030 decision 7; re-exported here for an app (#586).
76
+ export { CheckFrames } from "@wardic/core/FrameLoop"
77
+
78
+ /**
79
+ * Core's Frame loop metrics (`FrameLoop.layerMetrics`), here for an app. Merged beside {@link DomLive},
80
+ * the loop records the animations running, the runs that settled or failed, and each tick's ms, for the
81
+ * devtools or an exporter to read. Without it, it records none: see
82
+ * https://wardic.dev/guides/observability.
83
+ */
84
+ // #518, ADR-0067 *Amendment (#518)*, decision 2: opt-in, re-exported here for an app, as `CheckFrames` is.
85
+ export { layerMetrics as FrameLoopMetrics } from "@wardic/core/FrameLoop"
86
+
87
+ /**
88
+ * The browser Environment, composed: the DOM's services, core's interpolators with the DOM's Key
89
+ * rules, and the Frame loop over the DOM's Clock, needing nothing else. Hand it to `WardicProvider`'s
90
+ * `env` to run the engine on the page.
91
+ *
92
+ * It has no input: a binding's gestures build `DomInput.layer` with the first one an app uses, so an
93
+ * app with none ships no input code.
94
+ *
95
+ * Client-only: a server render builds no runtime, and building DomLive on a server fails with an
96
+ * error naming the service and the missing global: see https://wardic.dev/guides/server-rendering.
97
+ */
98
+ // Key rules: ADR-0035. Frame loop: ADR-0027. `DomClock.layer` also provides the `RefreshFrameSource`
99
+ // the flush gate requests its flushes from (ADR-0031). `DomProbe.layer` writes the `viewport` and
100
+ // `prefersReducedMotion` Atoms through the Environment's `AtomRegistry`, and consumers read them
101
+ // through the same registry, so `AtomRegistry` is provided to the Layers with `Layer.provideMerge` and
102
+ // kept in the output, as the headless `testLayer` (packages/test) does: R = never. No InputSource:
103
+ // #511, ADR-0067 decision 14. Client-only: ADR-0021, decision 7.
104
+ export const DomLive: Layer.Layer<
105
+ | Clock.Clock
106
+ | RefreshFrameSource.RefreshFrameSource
107
+ | FrameLoop.FrameLoop
108
+ | Renderer.Renderer
109
+ | Probe.Probe
110
+ | InterpolatorRegistry.InterpolatorRegistry
111
+ | ReducedMotion.PositionalKeys
112
+ | DefaultTransition.DefaultTransition
113
+ | Announcer.Announcer
114
+ | AtomRegistry.AtomRegistry
115
+ > = FrameLoop.layer.pipe(
116
+ Layer.provideMerge(
117
+ Layer.mergeAll(DomClock.layer, DomRenderer.layer, DomProbe.layer, DomInterpolators.layer, DomPositionalKeys.layer, DomDefaultTransition.layer, DomAnnouncer.layer),
118
+ ),
119
+ Layer.provideMerge(AtomRegistry.layer),
120
+ )
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The DOM's **Announcement** channel (ADR-0037): `AnnouncerDomLive`, core's `Announcer.Announcer` as
3
+ * one visually hidden live region per document, `aria-live="assertive"` and `aria-atomic`, shared by
4
+ * every Reorder group on the page. Assertive, because each announcement answers a key just pressed;
5
+ * the caller thins a held arrow's repeats to the last. Each announcement replaces the last, and one
6
+ * that repeats the last (an arrow at an end re-announcing the position) gets a trailing no-break
7
+ * space, so a screen reader sees a change and speaks it again.
8
+ *
9
+ * A screen reader watches a live region from when it's in the page, so the region has to be there
10
+ * before the first announcement: {@link prepareAnnouncer} adds it (a Reorder group's controller calls
11
+ * it when its element attaches), and an announcement adds it too if nothing did.
12
+ *
13
+ * {@link instructionsId} gives the id of a hidden element holding a group's instructions, one per
14
+ * distinct text per document, for its items' `aria-describedby`. {@link instructionsIdOf} gives the
15
+ * id alone, and {@link showInstructions} adds its element.
16
+ *
17
+ * Client-only (ADR-0021, decision 7): building the layer on a server fails with the client-only error.
18
+ *
19
+ * Tier 2 (ADR-0008): for DOM binding authors.
20
+ */
21
+ import * as Announcer from "@wardic/core/Announcer"
22
+ import * as Bool from "effect/Boolean"
23
+ import * as Effect from "effect/Effect"
24
+ import * as Layer from "effect/Layer"
25
+ import * as Option from "effect/Option"
26
+ import * as Predicate from "effect/Predicate"
27
+ import { requireGlobal } from "./require-global.ts"
28
+
29
+ /** The attribute that marks the live region, for a test or a stylesheet to find it. */
30
+ export const ANNOUNCER_ATTRIBUTE = "data-wardic-announcer"
31
+
32
+ /** Hidden from sight, not from assistive technology: the usual visually hidden rule. */
33
+ const VISUALLY_HIDDEN =
34
+ "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap"
35
+
36
+ /** Each document's live region, once added. */
37
+ // Module state (#460, Q7): each document's live region, held weakly by the document.
38
+ const regions = new WeakMap<Document, HTMLElement>()
39
+
40
+ /** `doc`'s live region, added to its body when it has none. */
41
+ const regionOf = (doc: Document): HTMLElement =>
42
+ Option.getOrElse(
43
+ Option.filter(Option.fromUndefinedOr(regions.get(doc)), (region) => region.isConnected),
44
+ () => addRegion(doc),
45
+ )
46
+
47
+ /** Add `doc`'s live region to its body. */
48
+ const addRegion = (doc: Document): HTMLElement => {
49
+ const region = doc.createElement("div")
50
+ region.setAttribute(ANNOUNCER_ATTRIBUTE, "")
51
+ region.setAttribute("aria-live", "assertive")
52
+ region.setAttribute("aria-atomic", "true")
53
+ region.setAttribute("style", VISUALLY_HIDDEN)
54
+ doc.body.appendChild(region)
55
+ regions.set(doc, region)
56
+ return region
57
+ }
58
+
59
+ /**
60
+ * The live document `node` is in: its own when that has a window, else the page's. A Solid ref
61
+ * runs while a new element still belongs to its template's inert document (no window, no body),
62
+ * before it's inserted.
63
+ */
64
+ export const documentOf = (node: Node): Document => {
65
+ const doc = node.ownerDocument
66
+ if (doc === null || doc.defaultView === null) return document
67
+ return doc
68
+ }
69
+
70
+ /** Adds `doc`'s live region now, before its first announcement, so a screen reader is already watching it. */
71
+ export const prepareAnnouncer = (doc: Document): void => {
72
+ regionOf(doc)
73
+ }
74
+
75
+ /**
76
+ * Speaks `message` in `doc`'s live region, replacing the last. A repeat of the last gets a trailing
77
+ * no-break space, so it's read out again.
78
+ */
79
+ export const announceIn = (doc: Document, message: string): void => {
80
+ const region = regionOf(doc)
81
+ region.textContent = Bool.match(region.textContent === message, { onTrue: () => `${message}\u00A0`, onFalse: () => message })
82
+ }
83
+
84
+ /** Each document's instructions ids, by text. */
85
+ // Module state (#460, Q7): each document's instructions, held weakly by the document.
86
+ const instructions = new WeakMap<Document, Map<string, string>>()
87
+ // Module state (#460, Q7): an id counter; an id need only be unique in its document.
88
+ let nextInstructions = 1
89
+
90
+ /**
91
+ * The id of `doc`'s hidden element holding `text`, one per distinct text, for the `aria-describedby` of
92
+ * every item that shows it. Given here, with no element added: a binding works it out as it renders, and
93
+ * adds the element with `showInstructions` in an effect.
94
+ */
95
+ // #320.
96
+ export const instructionsIdOf = (doc: Document, text: string): string => {
97
+ const byText = Option.getOrElse(Option.fromUndefinedOr(instructions.get(doc)), () => {
98
+ const added = new Map<string, string>()
99
+ instructions.set(doc, added)
100
+ return added
101
+ })
102
+ return Option.getOrElse(Option.fromUndefinedOr(byText.get(text)), () => {
103
+ const id = `wardic-instructions-${nextInstructions++}`
104
+ byText.set(text, id)
105
+ return id
106
+ })
107
+ }
108
+
109
+ /** Adds `doc`'s hidden element holding `text`, under `instructionsIdOf`'s id, unless it's there already. */
110
+ export const showInstructions = (doc: Document, text: string): void => {
111
+ const id = instructionsIdOf(doc, text)
112
+ if (Predicate.isNotNull(doc.getElementById(id))) return
113
+ const el = doc.createElement("div")
114
+ el.id = id
115
+ el.hidden = true
116
+ el.textContent = text
117
+ doc.body.appendChild(el)
118
+ }
119
+
120
+ /** `instructionsIdOf`, with its element added now: added again if it was removed. */
121
+ export const instructionsId = (doc: Document, text: string): string => {
122
+ showInstructions(doc, text)
123
+ return instructionsIdOf(doc, text)
124
+ }
125
+
126
+ /** Core's `Announcer`, speaking in the page's `document`'s live region. */
127
+ export const AnnouncerDomLive: Layer.Layer<Announcer.Announcer> = Layer.effect(Announcer.Announcer)(
128
+ Effect.gen(function* () {
129
+ yield* requireGlobal("DomAnnouncer.layer", "document")
130
+ return Announcer.Announcer.of({ announce: (message) => announceIn(document, message) })
131
+ }),
132
+ )
@@ -0,0 +1,32 @@
1
+ /**
2
+ * An Appear animation's slot on its element (#48, ADR-0044), as a page's code reads it before any Handoff:
3
+ * whether the element's animation still runs, and the Handoff's last step, its removal. Kept apart from the
4
+ * sampler and the Handoff's reads (`appear.ts`), so code that only asks, or lets one go, ships neither: a
5
+ * Batch's, whose reads load at its first Handoff (#706, Q11).
6
+ *
7
+ * @module
8
+ */
9
+
10
+ /** The prefix every Appear rule's name starts with. */
11
+ export const PREFIX = "wardic-"
12
+
13
+ /** What a slot's inline `animation` starts with: `var(--wardic-a`. */
14
+ const SLOT_PREFIX = `var(--${PREFIX}a`
15
+
16
+ /**
17
+ * Whether `element`'s Appear animation is running, not yet handed over: its inline style still names its
18
+ * slot, which `release` removes. A layout measure asks it of each node, so a running animation's
19
+ * transform, which beats the inline one, stays out of the box it reads.
20
+ */
21
+ // #245: a Measure pass; a string read, no style resolved.
22
+ export const pending = (element: ElementCSSInlineStyle): boolean => element.style.getPropertyValue("animation").startsWith(SLOT_PREFIX)
23
+
24
+ /**
25
+ * The handover's last step: the element's inline `animation` removed, in the task that writes the
26
+ * engine's first frame, so no paint falls between. While it ran, its value beat the inline style the
27
+ * engine writes; removing it ends the CSS animation at that task's style update.
28
+ */
29
+ // The **Handoff** (ADR-0044, decision 6). A `cancel()` too changed nothing (a mutation, #48's PR 1).
30
+ export const release = (element: ElementCSSInlineStyle): void => {
31
+ element.style.removeProperty("animation")
32
+ }