@wardic/dom 1.1.0 → 1.1.2

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 (253) hide show
  1. package/dist/DomProjectionSystem.js +3 -3
  2. package/dist/DomProjectionSystem.js.map +1 -1
  3. package/dist/FlushGate.d.ts +6 -6
  4. package/dist/FlushGate.d.ts.map +1 -1
  5. package/dist/FlushGate.js +7 -5
  6. package/dist/FlushGate.js.map +1 -1
  7. package/dist/ReorderController.js +3 -3
  8. package/dist/ReorderController.js.map +1 -1
  9. package/dist/Report.d.ts +1 -1
  10. package/dist/Report.d.ts.map +1 -1
  11. package/dist/Report.js +3 -2
  12. package/dist/Report.js.map +1 -1
  13. package/dist/Style.d.ts +2 -1
  14. package/dist/Style.d.ts.map +1 -1
  15. package/dist/Style.js +3 -1
  16. package/dist/Style.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/internal/batch-handoff.d.ts +25 -0
  20. package/dist/internal/batch-handoff.d.ts.map +1 -0
  21. package/dist/internal/batch-handoff.js +64 -0
  22. package/dist/internal/batch-handoff.js.map +1 -0
  23. package/dist/internal/gate-environment.d.ts +4 -0
  24. package/dist/internal/gate-environment.d.ts.map +1 -0
  25. package/dist/internal/gate-environment.js +21 -0
  26. package/dist/internal/gate-environment.js.map +1 -0
  27. package/dist/internal/projection.js +14 -14
  28. package/dist/internal/projection.js.map +1 -1
  29. package/dist/internal/reorder.d.ts +2 -2
  30. package/dist/internal/reorder.d.ts.map +1 -1
  31. package/dist/internal/reorder.js +2 -2
  32. package/dist/internal/reorder.js.map +1 -1
  33. package/dist/internal/starting-style.d.ts +0 -83
  34. package/dist/internal/starting-style.d.ts.map +1 -1
  35. package/dist/internal/starting-style.js +16 -143
  36. package/dist/internal/starting-style.js.map +1 -1
  37. package/dist/unstable/AppearAnimations.d.ts +191 -0
  38. package/dist/unstable/AppearAnimations.d.ts.map +1 -0
  39. package/dist/unstable/AppearAnimations.js +561 -0
  40. package/dist/unstable/AppearAnimations.js.map +1 -0
  41. package/dist/unstable/BatchMembers.d.ts +513 -0
  42. package/dist/unstable/BatchMembers.d.ts.map +1 -0
  43. package/dist/unstable/BatchMembers.js +2490 -0
  44. package/dist/unstable/BatchMembers.js.map +1 -0
  45. package/dist/unstable/DomValues.d.ts +25 -0
  46. package/dist/unstable/DomValues.d.ts.map +1 -0
  47. package/dist/unstable/DomValues.js +45 -0
  48. package/dist/unstable/DomValues.js.map +1 -0
  49. package/dist/unstable/DragConstraints.d.ts +48 -0
  50. package/dist/unstable/DragConstraints.d.ts.map +1 -0
  51. package/dist/unstable/DragConstraints.js +49 -0
  52. package/dist/unstable/DragConstraints.js.map +1 -0
  53. package/dist/unstable/DragControls.d.ts +50 -0
  54. package/dist/unstable/DragControls.d.ts.map +1 -0
  55. package/dist/unstable/DragControls.js +55 -0
  56. package/dist/unstable/DragControls.js.map +1 -0
  57. package/dist/unstable/DragDefaults.d.ts +34 -0
  58. package/dist/unstable/DragDefaults.d.ts.map +1 -0
  59. package/dist/unstable/DragDefaults.js +47 -0
  60. package/dist/unstable/DragDefaults.js.map +1 -0
  61. package/dist/unstable/DragTrack.d.ts +236 -0
  62. package/dist/unstable/DragTrack.d.ts.map +1 -0
  63. package/dist/unstable/DragTrack.js +646 -0
  64. package/dist/unstable/DragTrack.js.map +1 -0
  65. package/dist/unstable/DragTransition.d.ts +22 -0
  66. package/dist/unstable/DragTransition.d.ts.map +1 -0
  67. package/dist/unstable/DragTransition.js +31 -0
  68. package/dist/unstable/DragTransition.js.map +1 -0
  69. package/dist/unstable/ElementSetup.d.ts +144 -0
  70. package/dist/unstable/ElementSetup.d.ts.map +1 -0
  71. package/dist/unstable/ElementSetup.js +297 -0
  72. package/dist/unstable/ElementSetup.js.map +1 -0
  73. package/dist/unstable/Feature.d.ts +221 -0
  74. package/dist/unstable/Feature.d.ts.map +1 -0
  75. package/dist/unstable/Feature.js +281 -0
  76. package/dist/unstable/Feature.js.map +1 -0
  77. package/dist/unstable/GestureFeatures.d.ts +30 -0
  78. package/dist/unstable/GestureFeatures.d.ts.map +1 -0
  79. package/dist/unstable/GestureFeatures.js +32 -0
  80. package/dist/unstable/GestureFeatures.js.map +1 -0
  81. package/dist/unstable/GestureInfo.d.ts +61 -0
  82. package/dist/unstable/GestureInfo.d.ts.map +1 -0
  83. package/dist/unstable/GestureInfo.js +23 -0
  84. package/dist/unstable/GestureInfo.js.map +1 -0
  85. package/dist/unstable/Imperative.d.ts +214 -0
  86. package/dist/unstable/Imperative.d.ts.map +1 -0
  87. package/dist/unstable/Imperative.js +768 -0
  88. package/dist/unstable/Imperative.js.map +1 -0
  89. package/dist/unstable/Instant.d.ts +46 -0
  90. package/dist/unstable/Instant.d.ts.map +1 -0
  91. package/dist/unstable/Instant.js +49 -0
  92. package/dist/unstable/Instant.js.map +1 -0
  93. package/dist/unstable/LayoutGroup.d.ts +14 -0
  94. package/dist/unstable/LayoutGroup.d.ts.map +1 -0
  95. package/dist/unstable/LayoutGroup.js +31 -0
  96. package/dist/unstable/LayoutGroup.js.map +1 -0
  97. package/dist/unstable/LayoutMember.d.ts +127 -0
  98. package/dist/unstable/LayoutMember.d.ts.map +1 -0
  99. package/dist/unstable/LayoutMember.js +176 -0
  100. package/dist/unstable/LayoutMember.js.map +1 -0
  101. package/dist/unstable/LiveStyle.d.ts +171 -0
  102. package/dist/unstable/LiveStyle.d.ts.map +1 -0
  103. package/dist/unstable/LiveStyle.js +329 -0
  104. package/dist/unstable/LiveStyle.js.map +1 -0
  105. package/dist/unstable/MemberHold.d.ts +3 -0
  106. package/dist/unstable/MemberHold.d.ts.map +1 -0
  107. package/dist/unstable/MemberHold.js +223 -0
  108. package/dist/unstable/MemberHold.js.map +1 -0
  109. package/dist/unstable/OwnerScope.d.ts +16 -0
  110. package/dist/unstable/OwnerScope.d.ts.map +1 -0
  111. package/dist/unstable/OwnerScope.js +35 -0
  112. package/dist/unstable/OwnerScope.js.map +1 -0
  113. package/dist/unstable/PresenceController.d.ts +128 -0
  114. package/dist/unstable/PresenceController.d.ts.map +1 -0
  115. package/dist/unstable/PresenceController.js +1427 -0
  116. package/dist/unstable/PresenceController.js.map +1 -0
  117. package/dist/unstable/Press.d.ts +26 -0
  118. package/dist/unstable/Press.d.ts.map +1 -0
  119. package/dist/unstable/Press.js +19 -0
  120. package/dist/unstable/Press.js.map +1 -0
  121. package/dist/unstable/ServerInterpolators.d.ts +17 -0
  122. package/dist/unstable/ServerInterpolators.d.ts.map +1 -0
  123. package/dist/unstable/ServerInterpolators.js +20 -0
  124. package/dist/unstable/ServerInterpolators.js.map +1 -0
  125. package/dist/unstable/WardConfig.d.ts +567 -0
  126. package/dist/unstable/WardConfig.d.ts.map +1 -0
  127. package/dist/unstable/WardConfig.js +2 -0
  128. package/dist/unstable/WardConfig.js.map +1 -0
  129. package/dist/unstable/features/All.d.ts +24 -0
  130. package/dist/unstable/features/All.d.ts.map +1 -0
  131. package/dist/unstable/features/All.js +20 -0
  132. package/dist/unstable/features/All.js.map +1 -0
  133. package/dist/unstable/features/Colors.d.ts +12 -0
  134. package/dist/unstable/features/Colors.d.ts.map +1 -0
  135. package/dist/unstable/features/Colors.js +38 -0
  136. package/dist/unstable/features/Colors.js.map +1 -0
  137. package/dist/unstable/features/DomAnimation.d.ts +16 -0
  138. package/dist/unstable/features/DomAnimation.d.ts.map +1 -0
  139. package/dist/unstable/features/DomAnimation.js +19 -0
  140. package/dist/unstable/features/DomAnimation.js.map +1 -0
  141. package/dist/unstable/features/DomMax.d.ts +12 -0
  142. package/dist/unstable/features/DomMax.d.ts.map +1 -0
  143. package/dist/unstable/features/DomMax.js +14 -0
  144. package/dist/unstable/features/DomMax.js.map +1 -0
  145. package/dist/unstable/features/Drag.d.ts +5 -0
  146. package/dist/unstable/features/Drag.d.ts.map +1 -0
  147. package/dist/unstable/features/Drag.js +32 -0
  148. package/dist/unstable/features/Drag.js.map +1 -0
  149. package/dist/unstable/features/Focus.d.ts +5 -0
  150. package/dist/unstable/features/Focus.d.ts.map +1 -0
  151. package/dist/unstable/features/Focus.js +20 -0
  152. package/dist/unstable/features/Focus.js.map +1 -0
  153. package/dist/unstable/features/Hover.d.ts +5 -0
  154. package/dist/unstable/features/Hover.d.ts.map +1 -0
  155. package/dist/unstable/features/Hover.js +20 -0
  156. package/dist/unstable/features/Hover.js.map +1 -0
  157. package/dist/unstable/features/InView.d.ts +5 -0
  158. package/dist/unstable/features/InView.d.ts.map +1 -0
  159. package/dist/unstable/features/InView.js +20 -0
  160. package/dist/unstable/features/InView.js.map +1 -0
  161. package/dist/unstable/features/Input.d.ts +28 -0
  162. package/dist/unstable/features/Input.d.ts.map +1 -0
  163. package/dist/unstable/features/Input.js +31 -0
  164. package/dist/unstable/features/Input.js.map +1 -0
  165. package/dist/unstable/features/Keys.d.ts +95 -0
  166. package/dist/unstable/features/Keys.d.ts.map +1 -0
  167. package/dist/unstable/features/Keys.js +44 -0
  168. package/dist/unstable/features/Keys.js.map +1 -0
  169. package/dist/unstable/features/Layout.d.ts +43 -0
  170. package/dist/unstable/features/Layout.d.ts.map +1 -0
  171. package/dist/unstable/features/Layout.js +44 -0
  172. package/dist/unstable/features/Layout.js.map +1 -0
  173. package/dist/unstable/features/Pan.d.ts +5 -0
  174. package/dist/unstable/features/Pan.d.ts.map +1 -0
  175. package/dist/unstable/features/Pan.js +20 -0
  176. package/dist/unstable/features/Pan.js.map +1 -0
  177. package/dist/unstable/features/Press.d.ts +13 -0
  178. package/dist/unstable/features/Press.d.ts.map +1 -0
  179. package/dist/unstable/features/Press.js +10 -0
  180. package/dist/unstable/features/Press.js.map +1 -0
  181. package/dist/unstable/features/Scroll.d.ts +20 -0
  182. package/dist/unstable/features/Scroll.d.ts.map +1 -0
  183. package/dist/unstable/features/Scroll.js +34 -0
  184. package/dist/unstable/features/Scroll.js.map +1 -0
  185. package/dist/unstable/features/TimelineKeys.d.ts +7 -0
  186. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -0
  187. package/dist/unstable/features/TimelineKeys.js +103 -0
  188. package/dist/unstable/features/TimelineKeys.js.map +1 -0
  189. package/package.json +4 -3
  190. package/src/DomProjectionSystem.ts +3 -3
  191. package/src/FlushGate.ts +11 -9
  192. package/src/ReorderController.ts +3 -3
  193. package/src/Report.ts +3 -7
  194. package/src/Style.ts +4 -1
  195. package/src/index.ts +1 -1
  196. package/src/internal/batch-handoff.ts +75 -0
  197. package/src/internal/gate-environment.ts +21 -0
  198. package/src/internal/projection.ts +14 -14
  199. package/src/internal/reorder.ts +4 -4
  200. package/src/internal/starting-style.ts +5 -204
  201. package/src/unstable/AppearAnimations.ts +837 -0
  202. package/src/unstable/BatchMembers.ts +3085 -0
  203. package/src/unstable/DomValues.ts +53 -0
  204. package/src/unstable/DragConstraints.ts +107 -0
  205. package/src/unstable/DragControls.ts +98 -0
  206. package/src/unstable/DragDefaults.ts +57 -0
  207. package/src/unstable/DragTrack.ts +959 -0
  208. package/src/unstable/DragTransition.ts +46 -0
  209. package/src/unstable/ElementSetup.ts +411 -0
  210. package/src/unstable/Feature.ts +494 -0
  211. package/src/unstable/GestureFeatures.ts +38 -0
  212. package/src/unstable/GestureInfo.ts +85 -0
  213. package/src/unstable/Imperative.ts +1037 -0
  214. package/src/unstable/Instant.ts +93 -0
  215. package/src/unstable/LayoutGroup.ts +36 -0
  216. package/src/unstable/LayoutMember.ts +319 -0
  217. package/src/unstable/LiveStyle.ts +497 -0
  218. package/src/unstable/MemberHold.ts +211 -0
  219. package/src/unstable/OwnerScope.ts +35 -0
  220. package/src/unstable/PresenceController.ts +1747 -0
  221. package/src/unstable/Press.ts +43 -0
  222. package/src/unstable/ServerInterpolators.ts +39 -0
  223. package/src/unstable/WardConfig.ts +704 -0
  224. package/src/unstable/features/All.ts +39 -0
  225. package/src/unstable/features/Colors.ts +40 -0
  226. package/src/unstable/features/DomAnimation.ts +19 -0
  227. package/src/unstable/features/DomMax.ts +14 -0
  228. package/src/unstable/features/Drag.ts +34 -0
  229. package/src/unstable/features/Focus.ts +21 -0
  230. package/src/unstable/features/Hover.ts +21 -0
  231. package/src/unstable/features/InView.ts +21 -0
  232. package/src/unstable/features/Input.ts +37 -0
  233. package/src/unstable/features/Keys.ts +124 -0
  234. package/src/unstable/features/Layout.ts +75 -0
  235. package/src/unstable/features/Pan.ts +21 -0
  236. package/src/unstable/features/Press.ts +21 -0
  237. package/src/unstable/features/Scroll.ts +35 -0
  238. package/src/unstable/features/TimelineKeys.ts +115 -0
  239. package/dist/internal/gate.d.ts +0 -199
  240. package/dist/internal/gate.d.ts.map +0 -1
  241. package/dist/internal/gate.js +0 -570
  242. package/dist/internal/gate.js.map +0 -1
  243. package/dist/internal/report.d.ts +0 -30
  244. package/dist/internal/report.d.ts.map +0 -1
  245. package/dist/internal/report.js +0 -60
  246. package/dist/internal/report.js.map +0 -1
  247. package/dist/internal/runner.d.ts +0 -22
  248. package/dist/internal/runner.d.ts.map +0 -1
  249. package/dist/internal/runner.js +0 -62
  250. package/dist/internal/runner.js.map +0 -1
  251. package/src/internal/gate.ts +0 -706
  252. package/src/internal/report.ts +0 -69
  253. package/src/internal/runner.ts +0 -78
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Every **Feature** (#511, ADR-0067 decision 2): what a **Complete element** has, and so what its forms
3
+ * (`wardic.*`, `wardic.create`, `createWard`, `use:wardic`, Solid 2's `ward()`) import. A Slim element's
4
+ * forms never do.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/all.ts`, moved to dom with the Features, for
11
+ // every DOM binding.
12
+ import type * as Feature from "../Feature.ts"
13
+ import * as Colors from "./Colors.ts"
14
+ import * as Drag from "./Drag.ts"
15
+ import * as Focus from "./Focus.ts"
16
+ import * as Hover from "./Hover.ts"
17
+ import * as InView from "./InView.ts"
18
+ import * as Layout from "./Layout.ts"
19
+ import * as Pan from "./Pan.ts"
20
+ import * as Press from "./Press.ts"
21
+
22
+ // A tuple, so a Wardic instance's types keep each Feature's name (#516).
23
+ export const ALL: readonly [typeof Colors.colors, typeof Layout.layout, typeof Hover.hover, typeof Press.press, typeof Focus.focus, typeof InView.inView, typeof Pan.pan, typeof Drag.drag] = [
24
+ Colors.colors,
25
+ Layout.layout,
26
+ Hover.hover,
27
+ Press.press,
28
+ Focus.focus,
29
+ InView.inView,
30
+ Pan.pan,
31
+ Drag.drag,
32
+ ]
33
+
34
+ /** Every Feature: what an element has unless it's a Wardic instance's (#516). */
35
+ // #672 (the build grill's Q9): with ALL, so the Feature module imports none of the Features.
36
+ export type EveryFeature = typeof ALL
37
+
38
+ /** The names of every Feature that adds props (#516): what an element has unless it's a Wardic instance's. */
39
+ export type EveryFeatureName = Feature.PropFeatureNames<EveryFeature>
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The **`colors` Feature** (#511, ADR-0067 decision 5), in a module of its own: an app that never
3
+ * imports it ships none of its colour spaces. Its top-level calls are marked pure: without the marks,
4
+ * Rollup kept `registerSpaces` and every space's definition for the callback `Effect.sync` is given,
5
+ * though nothing of the module's was emitted (1 KB gzipped on a Slim element's app).
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/colors.ts`, moved to dom with the Features, for
12
+ // every DOM binding.
13
+ import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
14
+ import * as Color from "../../Color.ts"
15
+ import * as Effect from "effect/Effect"
16
+ import * as Layer from "effect/Layer"
17
+ import type * as Feature from "../Feature.ts"
18
+ import * as Keys from "./Keys.ts"
19
+
20
+ /**
21
+ * Every CSS colour space beyond a hex, `rgb()`, `hsl()` and the colour names, which every element
22
+ * reads: `oklch()`, `lab()`, `lch()`, `oklab()`, `hwb()` and `color()`'s spaces (`display-p3`,
23
+ * `rec2020` …). Blends don't change: every colour blends in sRGB. culori
24
+ * keeps its spaces in one registry for the page, so once one provider, or a server render, registers
25
+ * them, every element on the page reads them; a pair another provider resolved before stays as it
26
+ * was resolved there.
27
+ */
28
+ export const colors: Feature.Feature<Keys.Colors, true, "colors"> = {
29
+ name: "colors",
30
+ key: Keys.Colors,
31
+ // The provider's registry forgets the pairs it resolved before: one with a wide-gamut colour read as
32
+ // a complex value then is a colour from now on (decision 8, "from then on").
33
+ layer: /*#__PURE__*/ Layer.effect(Keys.Colors)(
34
+ /*#__PURE__*/ Effect.flatMap(InterpolatorRegistry.InterpolatorRegistry, (registry) => {
35
+ Color.registerSpaces()
36
+ return Effect.as(registry.forget, true as const)
37
+ }),
38
+ ),
39
+ server: Color.registerSpaces,
40
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Motion's `domAnimation` bundle (#511, ADR-0067 decision 3), as a list of Features: give it where a
3
+ * list goes (`features={domAnimation}`, or nested, `features={[domAnimation, layout]}`). In a module
4
+ * apart from `domMax` (#548), so a page given `domAnimation` never ships `domMax`'s Features with it.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/dom-animation.ts`, moved to dom with the Features, for
11
+ // every DOM binding.
12
+ import * as Focus from "./Focus.ts"
13
+ import * as Hover from "./Hover.ts"
14
+ import * as InView from "./InView.ts"
15
+ import * as Press from "./Press.ts"
16
+
17
+ /** Motion's `domAnimation`: the gestures an element animates on without dragging, `hover`, `press`, `focus` and `inView`. */
18
+ // A tuple, so a Wardic instance's types keep each Feature's name (#516).
19
+ export const domAnimation: readonly [typeof Hover.hover, typeof Press.press, typeof Focus.focus, typeof InView.inView] = [Hover.hover, Press.press, Focus.focus, InView.inView]
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Motion's `domMax` bundle (#511, ADR-0067 decision 3), as a list of Features: every one, as a Complete
3
+ * element has. In a module apart from `domAnimation` (#548).
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/dom-max.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import * as All from "./All.ts"
12
+
13
+ /** Motion's `domMax`: every Feature, `pan`, `drag`, `layout` and `colors` beside `domAnimation`'s, as a Complete element has. */
14
+ export const domMax: typeof All.ALL = All.ALL
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The **`drag` Feature** (#511, ADR-0067 decision 3): an element's drag (`drag`, `dragControls`, its
3
+ * constraints, its release's inertia; Solid 2's `"drag"` events), in a module of its own, so an app that
4
+ * never imports it ships none of it: the drag track (`DragTrack`), core's `Drag` and `Inertia`. Its
5
+ * top-level calls are marked pure, as every Feature module's are.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/drag.ts`, moved to dom with the Features, for
12
+ // every DOM binding.
13
+ import * as InputSource from "@wardic/core/InputSource"
14
+ import * as Effect from "effect/Effect"
15
+ import * as DragConstraints from "../DragConstraints.ts"
16
+ import * as DragTrack from "../DragTrack.ts"
17
+ import type * as Feature from "../Feature.ts"
18
+ import * as Keys from "./Keys.ts"
19
+ import * as Input from "./Input.ts"
20
+
21
+ /** Drag gestures: `drag`, `dragControls`, the drag callbacks, and what a `Reorder` item drags with. */
22
+ export const drag: Feature.Feature<Keys.DragGesture, Keys.DragGesture["Service"], "drag"> = {
23
+ name: "drag",
24
+ key: Keys.DragGesture,
25
+ layer: /*#__PURE__*/ Input.gestureLayer(Keys.DragGesture, (source) => ({
26
+ drive: (run) =>
27
+ DragTrack.driveDragTrack({
28
+ ...run,
29
+ watch: (track) => run.watch((onDefect) => Effect.provideService(track(onDefect), InputSource.InputSource, source)),
30
+ fork: (response) => run.fork(Effect.provideService(response, InputSource.InputSource, source)),
31
+ }),
32
+ constraintsOf: DragConstraints.trackConstraintsOf,
33
+ })),
34
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The **`focus` Feature** (#511, ADR-0067 decision 3): an element's focus as the browser shows it (`whileFocus`), in a module of its own, so an app that
3
+ * never imports it ships none of it. Its top-level calls are marked pure, as every Feature module's are.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/focus.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import * as Recognizer from "@wardic/core/Recognizer"
12
+ import type * as Feature from "../Feature.ts"
13
+ import * as Keys from "./Keys.ts"
14
+ import * as Input from "./Input.ts"
15
+
16
+ /** Focus gestures: `whileFocus`. */
17
+ export const focus: Feature.Feature<Keys.FocusGesture, Keys.FocusGesture["Service"], "focus"> = {
18
+ name: "focus",
19
+ key: Keys.FocusGesture,
20
+ layer: /*#__PURE__*/ Input.gestureLayer(Keys.FocusGesture, (source) => ({ watch: Input.withInput(source, Recognizer.watchFocus) })),
21
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The **`hover` Feature** (#511, ADR-0067 decision 3): an element's hover (`whileHover`, `onHoverStart`, `onHoverEnd`; Solid 2's `"hover"` events), in a module of its own, so an app that
3
+ * never imports it ships none of it. Its top-level calls are marked pure, as every Feature module's are.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/hover.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import * as Recognizer from "@wardic/core/Recognizer"
12
+ import type * as Feature from "../Feature.ts"
13
+ import * as Keys from "./Keys.ts"
14
+ import * as Input from "./Input.ts"
15
+
16
+ /** Hover gestures: `whileHover` and the hover callbacks. */
17
+ export const hover: Feature.Feature<Keys.HoverGesture, Keys.HoverGesture["Service"], "hover"> = {
18
+ name: "hover",
19
+ key: Keys.HoverGesture,
20
+ layer: /*#__PURE__*/ Input.gestureLayer(Keys.HoverGesture, (source) => ({ watch: Input.withInput(source, Recognizer.watchHover) })),
21
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The **`inView` Feature** (#511, ADR-0067 decision 3): an element's place in its viewport (`whileInView`, `onViewportEnter`, `onViewportLeave`, `viewport`), in a module of its own, so an app that
3
+ * never imports it ships none of it. Its top-level calls are marked pure, as every Feature module's are.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/in-view.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import * as Recognizer from "@wardic/core/Recognizer"
12
+ import * as Layer from "effect/Layer"
13
+ import type * as Feature from "../Feature.ts"
14
+ import * as Keys from "./Keys.ts"
15
+
16
+ /** In-view gestures: `whileInView` and the viewport callbacks. It reads no input: the Probe's intersections. */
17
+ export const inView: Feature.Feature<Keys.InViewGesture, Keys.InViewGesture["Service"], "inView"> = {
18
+ name: "inView",
19
+ key: Keys.InViewGesture,
20
+ layer: /*#__PURE__*/ Layer.succeed(Keys.InViewGesture)({ watch: Recognizer.watchInView }),
21
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The gestures' input (#511, ADR-0067 decision 14): what every gesture Feature but `inView` stands on,
3
+ * in a module of its own. `DomLive` no longer builds the DOM's `InputSource`, so an app with no gesture
4
+ * ships none of it. Its top-level calls are marked pure, as every Feature module's are.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/input.ts`, moved to dom with the Features, for
11
+ // every DOM binding.
12
+ import * as InputSource from "@wardic/core/InputSource"
13
+ import * as DomInput from "../../DomInput.ts"
14
+ import * as Context from "effect/Context"
15
+ import * as Effect from "effect/Effect"
16
+ import * as Layer from "effect/Layer"
17
+ import * as Feature from "../Feature.ts"
18
+
19
+ /**
20
+ * The gestures' `InputSource`: the Environment's when it gives one (`@wardic/test`'s `TestLive`, a
21
+ * test's pushed input), else the DOM's, built over the page's `document`. One Layer, so a provider's
22
+ * `MemoMap` builds it once for every gesture Feature it has.
23
+ */
24
+ export const input: Layer.Layer<InputSource.InputSource> = /*#__PURE__*/ Feature.fromEnvironmentOr(InputSource.InputSource, DomInput.layer)
25
+
26
+ /** `watch` with the gestures' input given: what a gesture Feature hands its elements, which run it on their provider. */
27
+ export const withInput =
28
+ <Args extends ReadonlyArray<unknown>, A, E, R>(source: InputSource.InputSource["Service"], watch: (...args: Args) => Effect.Effect<A, E, R>) =>
29
+ (...args: Args): Effect.Effect<A, E, Exclude<R, InputSource.InputSource>> =>
30
+ Effect.provideService(watch(...args), InputSource.InputSource, source)
31
+
32
+ /**
33
+ * A gesture Feature's Layer: its service, made over the gestures' input, which it gives beside it, so
34
+ * a section with the Feature has the input too (a `Reorder` item's keys, a `createPress`).
35
+ */
36
+ export const gestureLayer = <I, S>(key: Context.Key<I, S>, make: (source: InputSource.InputSource["Service"]) => S): Layer.Layer<I | InputSource.InputSource, never, Feature.ProviderServices> =>
37
+ Layer.effect(key)(Effect.map(InputSource.InputSource, make)).pipe(Layer.provideMerge(input))
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Every Feature's key (#548, ADR-0067 *Amendment (#548)*): the services an element's code looks up,
3
+ * apart from the Features themselves, whose Layers bring a gesture's or the colour spaces' code. Every
4
+ * page's elements import these; only a page whose section has a Feature imports its module. The
5
+ * `layout` Feature's key is dom's `ProjectionSystem`, beside {@link ProjectionNodes}, its element code's.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/keys.ts`, moved to dom with the Features, for
12
+ // every DOM binding.
13
+ import type * as DragRecognizer from "@wardic/core/DragRecognizer"
14
+ import type * as InputFeed from "@wardic/core/InputFeed"
15
+ import type * as Probe from "@wardic/core/Probe"
16
+ import type * as Recognizer from "@wardic/core/Recognizer"
17
+ import * as ProjectionSystem from "../../ProjectionSystem.ts"
18
+ import * as Context from "effect/Context"
19
+ import type * as Effect from "effect/Effect"
20
+ import * as Option from "effect/Option"
21
+ import type { LazyArg } from "effect/Function"
22
+ import type * as Scope from "effect/Scope"
23
+ import type * as DragConstraints from "../DragConstraints.ts"
24
+ import type * as DragTrack from "../DragTrack.ts"
25
+ import type * as LayoutMember from "../LayoutMember.ts"
26
+ import type * as WardicServices from "@wardic/core/unstable/WardicServices"
27
+
28
+ /** The `hover` Feature's service: an element's hover watched, over the gestures' input. */
29
+ export class HoverGesture extends /*#__PURE__*/ Context.Service<
30
+ HoverGesture,
31
+ { readonly watch: (target: unknown, handlers: Recognizer.HoverHandlers) => Effect.Effect<void, never, Scope.Scope> }
32
+ >()("@wardic/dom/unstable/HoverGesture") {}
33
+
34
+ /** The `press` Feature's service: an element's presses watched (`Press`), over the gestures' input. */
35
+ export class PressGesture extends /*#__PURE__*/ Context.Service<
36
+ PressGesture,
37
+ {
38
+ readonly watch: (
39
+ element: unknown,
40
+ handlers: InputFeed.Handlers<Recognizer.PressEvent>,
41
+ keysTaken?: boolean,
42
+ propagates?: LazyArg<boolean>,
43
+ ) => Effect.Effect<void, never, Scope.Scope>
44
+ }
45
+ >()("@wardic/dom/unstable/PressGesture") {}
46
+
47
+ /** The `focus` Feature's service: an element's focus watched, over the gestures' input. */
48
+ export class FocusGesture extends /*#__PURE__*/ Context.Service<
49
+ FocusGesture,
50
+ { readonly watch: (target: unknown, options: Recognizer.FocusOptions, handlers: InputFeed.Handlers<boolean>) => Effect.Effect<void, never, Scope.Scope> }
51
+ >()("@wardic/dom/unstable/FocusGesture") {}
52
+
53
+ /** The `inView` Feature's service: an element's intersections watched, over the Environment's Probe. */
54
+ export class InViewGesture extends /*#__PURE__*/ Context.Service<
55
+ InViewGesture,
56
+ {
57
+ readonly watch: (
58
+ target: unknown,
59
+ options: Recognizer.InViewOptions,
60
+ handlers: InputFeed.Handlers<Recognizer.ViewEdge>,
61
+ ) => Effect.Effect<void, never, Scope.Scope | Probe.Probe>
62
+ }
63
+ >()("@wardic/dom/unstable/InViewGesture") {}
64
+
65
+ /** The `pan` Feature's service: an element's pans watched, over the gestures' input. */
66
+ export class PanGesture extends /*#__PURE__*/ Context.Service<
67
+ PanGesture,
68
+ {
69
+ readonly watch: (
70
+ target: unknown,
71
+ handlers: InputFeed.Handlers<DragRecognizer.PanSample>,
72
+ options?: DragRecognizer.PanOptions,
73
+ ) => Effect.Effect<void, never, Scope.Scope>
74
+ }
75
+ >()("@wardic/dom/unstable/PanGesture") {}
76
+
77
+ /** What an element hands the drag Feature: the track's options, its watches and responses run on its provider. */
78
+ export interface DragRun extends Omit<DragTrack.DragTrackOptions, "watch" | "fork"> {
79
+ readonly watch: (track: (onDefect: InputFeed.OnDefect) => Effect.Effect<void, never, Scope.Scope | WardicServices.WardicServices>) => void
80
+ readonly fork: (response: Effect.Effect<void, never, WardicServices.WardicServices>) => void
81
+ }
82
+
83
+ /**
84
+ * The `drag` Feature's service: an element's drag track driven over the gestures' input, and its
85
+ * `dragConstraints` read (a box, or a container measured against the element).
86
+ */
87
+ export class DragGesture extends /*#__PURE__*/ Context.Service<
88
+ DragGesture,
89
+ {
90
+ readonly drive: (run: DragRun) => DragTrack.DragTrack
91
+ readonly constraintsOf: typeof DragConstraints.trackConstraintsOf
92
+ }
93
+ >()("@wardic/dom/unstable/DragGesture") {}
94
+
95
+ /** The `colors` Feature's service: that the page reads every CSS colour space. */
96
+ export class Colors extends /*#__PURE__*/ Context.Service<Colors, true>()("@wardic/dom/unstable/Colors") {}
97
+
98
+ /**
99
+ * The `layout` Feature's element code (#746, ADR-0067 *Amendment (#746)*, decision 9), beside the
100
+ * projection system it builds: what makes a Wardic element's **Projection node**, its options from its
101
+ * config and its registration, so an app without `layout` ships neither.
102
+ */
103
+ export class ProjectionNodes extends /*#__PURE__*/ Context.Service<
104
+ ProjectionNodes,
105
+ {
106
+ /** A ward's node options, from its config (`LayoutMember`'s `layoutOptionsOf`). */
107
+ readonly optionsOf: (ward: LayoutMember.WardLayout) => LayoutMember.CreateProjectionNodeOptions
108
+ /** What its node registers with the projection system (`LayoutMember`'s `registrationOf`). */
109
+ readonly registrationOf: (opts: LayoutMember.CreateProjectionNodeOptions) => ProjectionSystem.RegisterNodeOptions
110
+ }
111
+ >()("@wardic/dom/unstable/ProjectionNodes") {}
112
+
113
+ // #672: the readers of a section's layout services, out of solid's runtime.ts, with the keys they read.
114
+ /** The projection system among `services`, the `layout` Feature's (#511), or `undefined` when they hold none. */
115
+ export const projectionIn = (services: Context.Context<never>): ProjectionSystem.Shape | undefined =>
116
+ Option.getOrUndefined(Context.getOption(services as Context.Context<ProjectionSystem.ProjectionSystem>, ProjectionSystem.ProjectionSystem))
117
+
118
+ /**
119
+ * The `layout` Feature's element code in `services` (#746): what makes a Wardic element's node on its
120
+ * projection system. Read where an element makes its node, from Features {@link projectionIn} found
121
+ * `layout` in, which give both.
122
+ */
123
+ export const projectionNodesIn = (services: Context.Context<never>): ProjectionNodes["Service"] =>
124
+ Context.get(services as Context.Context<ProjectionNodes>, ProjectionNodes)
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The **`layout` Feature** (#511, ADR-0067 decisions 3 and 15): the projection system (ADR-0009), in a
3
+ * module of its own, so an app that never imports it ships none of it. It's what a Slim element's
4
+ * `layout`, `layoutId` and `layoutScroll` need, and the shared-element crossfades and Switches between
5
+ * `layoutId` twins (ADR-0010). Its top-level calls are marked pure, as `colors`' are.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/layout.ts`, moved to dom with the Features, for
12
+ // every DOM binding.
13
+ import type * as Announcer from "@wardic/core/Announcer"
14
+ import * as DomProjectionSystem from "../../DomProjectionSystem.ts"
15
+ import * as FlushGate from "../../FlushGate.ts"
16
+ import * as ProjectionSystem from "../../ProjectionSystem.ts"
17
+ import type * as ReorderController from "../../ReorderController.ts"
18
+ import type * as Context from "effect/Context"
19
+ import * as Effect from "effect/Effect"
20
+ import * as Layer from "effect/Layer"
21
+ import * as UndefinedOr from "effect/UndefinedOr"
22
+ import * as Feature from "../Feature.ts"
23
+ import * as LayoutMember from "../LayoutMember.ts"
24
+ import * as Keys from "./Keys.ts"
25
+
26
+ /**
27
+ * Layout animations: a provider's projection system, built once for the provider, over its
28
+ * flush gate and with its reduced motion and scale correctors. Every section with it shares it, as the
29
+ * projection tree is the page's: a `layoutId` pair in two sections still crossfades.
30
+ */
31
+ export const layout: Feature.Feature<ProjectionSystem.ProjectionSystem, ProjectionSystem.Shape, "layout"> = {
32
+ name: "layout",
33
+ key: ProjectionSystem.ProjectionSystem,
34
+ // The engine, and what its Reorder controllers hear each Measure pass by, beside it (#618); and the
35
+ // code that makes a Wardic element's node on it, here so the base ships none (#746).
36
+ layer: /*#__PURE__*/ Layer.merge(
37
+ /*#__PURE__*/ Layer.effectContext(
38
+ /*#__PURE__*/ Effect.flatMap(FlushGate.FlushGate, (gate) => Effect.flatMap(Feature.ProjectionOptions, (options) => DomProjectionSystem.make(gate, options))),
39
+ ),
40
+ /*#__PURE__*/ Layer.succeed(Keys.ProjectionNodes, { optionsOf: LayoutMember.layoutOptionsOf, registrationOf: LayoutMember.registrationOf }),
41
+ ),
42
+ }
43
+
44
+ /** What `layout` brings: the projection system, and what a Reorder controller over it takes beside it. */
45
+ export type LayoutServices = Exclude<ReorderController.Services, Announcer.Announcer>
46
+
47
+ /** What a component that brings `layout` asks its provider for: one list, so the provider joins it once. */
48
+ const BRINGS: ReadonlyArray<Feature.Feature> = [layout]
49
+
50
+ /** What the layout Feature's helpers read of a provider (Q15): its Features, built as they're asked for. */
51
+ // #672: named here, so the layout Feature reads no binding's provider record; each binding's meets it.
52
+ export interface BringsFeatures {
53
+ readonly features: Pick<Feature.FeatureRegistry, "build">
54
+ }
55
+
56
+ /**
57
+ * The projection system of `value`'s provider, its `layout` Feature built now if nothing has built it
58
+ * yet (#511, decision 12): what a component that brings it works with (`LayoutGroup`, `Reorder`,
59
+ * `createProjectionNode`), whatever its section has. A clear error during a server render, which builds
60
+ * none (ADR-0021).
61
+ */
62
+ export const projectionBrought = (value: BringsFeatures): ProjectionSystem.Shape =>
63
+ UndefinedOr.getOrThrowWith(Keys.projectionIn(value.features.build(BRINGS)), () => new Error("useWardicProjection: there is no projection system during a server render (ADR-0021)"))
64
+
65
+ /**
66
+ * The `layout` Feature's element code (#746), brought as {@link projectionBrought} brings the projection
67
+ * system, whose call comes first and gives a server render's error: what `createProjectionNode` registers through.
68
+ */
69
+ export const projectionNodesBrought = (value: BringsFeatures): Keys.ProjectionNodes["Service"] => Keys.projectionNodesIn(value.features.build(BRINGS))
70
+
71
+ /** {@link projectionBrought}'s services, all of them: what a Reorder controller is built with (#618). */
72
+ export const layoutBrought = (value: BringsFeatures): Context.Context<LayoutServices> => {
73
+ projectionBrought(value)
74
+ return value.features.build(BRINGS) as Context.Context<LayoutServices>
75
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The **`pan` Feature** (#511, ADR-0067 decision 3): an element's pan (`onPan`, `onPanStart`, `onPanSessionStart`, `onPanEnd`; Solid 2's `"pan"` events), in a module of its own, so an app that
3
+ * never imports it ships none of it. Its top-level calls are marked pure, as every Feature module's are.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/pan.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import * as DragRecognizer from "@wardic/core/DragRecognizer"
12
+ import type * as Feature from "../Feature.ts"
13
+ import * as Keys from "./Keys.ts"
14
+ import * as Input from "./Input.ts"
15
+
16
+ /** Pan gestures: the pan callbacks. */
17
+ export const pan: Feature.Feature<Keys.PanGesture, Keys.PanGesture["Service"], "pan"> = {
18
+ name: "pan",
19
+ key: Keys.PanGesture,
20
+ layer: /*#__PURE__*/ Input.gestureLayer(Keys.PanGesture, (source) => ({ watch: Input.withInput(source, DragRecognizer.watchPan) })),
21
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The **`press` Feature** (#511, ADR-0067 decision 3): an element's press, its Keyboard presses included (`whileTap`, `onTap…`; Solid 2's `"tap"` events), in a module of its own, so an app that
3
+ * never imports it ships none of it. Its top-level calls are marked pure, as every Feature module's are.
4
+ *
5
+ * Unstable, for Wardic's own packages: public, with no semver promise.
6
+ *
7
+ * @module
8
+ */
9
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/press.ts`, moved to dom with the Features, for
10
+ // every DOM binding.
11
+ import type * as Feature from "../Feature.ts"
12
+ import * as Keys from "./Keys.ts"
13
+ import * as Press from "../Press.ts"
14
+ import * as Input from "./Input.ts"
15
+
16
+ /** Press gestures, a pointer's and the keyboard's: `whileTap` and the tap callbacks. */
17
+ export const press: Feature.Feature<Keys.PressGesture, Keys.PressGesture["Service"], "press"> = {
18
+ name: "press",
19
+ key: Keys.PressGesture,
20
+ layer: /*#__PURE__*/ Input.gestureLayer(Keys.PressGesture, (source) => ({ watch: Input.withInput(source, Press.watchPressOn) })),
21
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The **`scroll` Feature** (#518, ADR-0067 *Amendment (#518)*, decision 5), in a module of its own: a
3
+ * container's scroll, which `createScroll` brings, so an app that reads no scroll ships none of the
4
+ * Environment's scroll code. With it, the Timeline values (#240): a value derived from the scroll by
5
+ * ranges alone, drawn by the browser with the scroll. Its top-level calls are marked pure, as every
6
+ * Feature module's are.
7
+ *
8
+ * Unstable, for Wardic's own packages: public, with no semver promise.
9
+ *
10
+ * @module
11
+ */
12
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/scroll.ts`, moved to dom with the Features, for
13
+ // every DOM binding.
14
+ import * as ScrollSource from "@wardic/core/ScrollSource"
15
+ import * as DomScrollSource from "../../DomScrollSource.ts"
16
+ import * as Layer from "effect/Layer"
17
+ import * as Feature from "../Feature.ts"
18
+ import * as Timelines from "@wardic/core/unstable/Timelines"
19
+ import * as TimelineKeys from "./TimelineKeys.ts"
20
+
21
+ /**
22
+ * A container's scroll, live, for the scroll-linked values. `createScroll` brings it, so an app doesn't
23
+ * give it. The Environment's `ScrollSource` when it gives one (`@wardic/test`'s `TestLive`), else the
24
+ * DOM's, built once per provider. Its Timeline values run where the browser has native scroll timelines.
25
+ */
26
+ // #240 (ADR-0043 *Amendment (#240)*, decision 4): the `Timelines` service, which an element's spine finds
27
+ // among the provider's built Features.
28
+ export const scroll: Feature.Feature<ScrollSource.ScrollSource, ScrollSource.ScrollSource["Service"], "scroll"> = {
29
+ name: "scroll",
30
+ key: ScrollSource.ScrollSource,
31
+ layer: /*#__PURE__*/ Layer.merge(
32
+ /*#__PURE__*/ Feature.fromEnvironmentOr(ScrollSource.ScrollSource, DomScrollSource.layer),
33
+ /*#__PURE__*/ Layer.sync(Timelines.Timelines)(TimelineKeys.makeTimelines),
34
+ ),
35
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * An element's **Timeline values** (#240, ADR-0043 *Amendment (#240)*), the `scroll` Feature's: a routed
3
+ * `style` key whose Live value core describes as derived from a container's scroll
4
+ * (`LiveValue.scrollDerivationOf`) gets the DOM's `TimelineValue`, handed to the gate while the key shows
5
+ * its Live value and taken back from it while anything else draws the key. Made again when what the key
6
+ * derives from changes: a new source in its `style`, or a `createScroll`'s new container.
7
+ *
8
+ * Unstable, for Wardic's own packages: public, with no semver promise.
9
+ *
10
+ * @module
11
+ */
12
+ // Unstable: ADR-0071, decision 5. #672 (PR6-Q1): solid's `features/timeline-keys.ts`, moved to dom with the Features, for
13
+ // every DOM binding.
14
+ import * as LiveValue from "@wardic/core/LiveValue"
15
+ import * as TimelineValue from "../../TimelineValue.ts"
16
+ import * as Bool from "effect/Boolean"
17
+ import * as Option from "effect/Option"
18
+ import * as Predicate from "effect/Predicate"
19
+ import type * as Atom from "effect/reactivity/Atom"
20
+ import type * as Timelines from "@wardic/core/unstable/Timelines"
21
+
22
+ /** A key's Timeline value as last made: the derivation it was made from, and the value, `undefined` where the gate draws the key. */
23
+ interface Made {
24
+ readonly derivation: LiveValue.ScrollDerivation
25
+ readonly timeline: TimelineValue.TimelineValue | undefined
26
+ }
27
+
28
+ /** An element's {@link Timelines.TimelineKeys}, and what its provider's `described` tells it. */
29
+ interface ElementKeys extends Timelines.TimelineKeys {
30
+ /** Find each key it shows its Timeline value again: what it derives from may have been described since. */
31
+ readonly recheck: () => void
32
+ }
33
+
34
+ /**
35
+ * A provider's {@link Timelines.Timelines}: each mounted element's keys, told again when a `createScroll`
36
+ * describes its values.
37
+ */
38
+ export const makeTimelines = (): Timelines.Timelines["Service"] => {
39
+ const mounted = new Set<ElementKeys>()
40
+ return {
41
+ keysOf: (options) => {
42
+ const keys = elementKeysOf(options, () => mounted.delete(keys))
43
+ mounted.add(keys)
44
+ return keys
45
+ },
46
+ described: () => {
47
+ mounted.forEach((keys) => keys.recheck())
48
+ },
49
+ }
50
+ }
51
+
52
+ /**
53
+ * An element's keys. `shown` runs at each write of a key's Live value, so per frame while it moves: a key
54
+ * shown already from the same source is left as it is, with nothing read but its source, statements and
55
+ * nothing made. What it derives from changes only where it's described anew, which `recheck` hears.
56
+ */
57
+ const elementKeysOf = (options: Timelines.TimelineKeysOptions, unmounted: () => void): ElementKeys => {
58
+ const { runtime, gate, id, live } = options
59
+ // #672: the spine hands its Subject; a DOM binding's is its element, which a Timeline value follows.
60
+ const element = options.element as Element
61
+ const made = new Map<string, Made>()
62
+ // The keys that show their Live value, whatever runs them, each with the Atom it was shown from (none
63
+ // for a plain accessor's): the ones `recheck` looks at again.
64
+ const showing = new Map<string, Atom.Atom<unknown> | undefined>()
65
+ // The keys whose Timeline value the gate has, each with it.
66
+ const running = new Map<string, TimelineValue.TimelineValue>()
67
+
68
+ /** `key`'s Timeline value now, made again when its derivation changed; `undefined` for none. */
69
+ const timelineOf = (key: string): TimelineValue.TimelineValue | undefined => {
70
+ const atom = live.atomOf(key)
71
+ if (Predicate.isUndefined(atom)) return undefined
72
+ const derivation = Option.getOrUndefined(LiveValue.scrollDerivationOf(atom))
73
+ if (Predicate.isUndefined(derivation)) return undefined
74
+ const last = made.get(key)
75
+ if (Predicate.isNotUndefined(last)) {
76
+ if (last.derivation === derivation) return last.timeline
77
+ }
78
+ const timeline = Option.getOrUndefined(runtime.runSync(TimelineValue.make(derivation, element, key)))
79
+ made.set(key, { derivation, timeline })
80
+ return timeline
81
+ }
82
+
83
+ /** The gate runs `key`'s Timeline value now, or none. */
84
+ const run = (key: string): void => {
85
+ const timeline = timelineOf(key)
86
+ if (running.get(key) === timeline) return
87
+ gate.timeline(id, key, timeline)
88
+ if (Predicate.isUndefined(timeline)) {
89
+ running.delete(key)
90
+ return
91
+ }
92
+ running.set(key, timeline)
93
+ }
94
+
95
+ return {
96
+ shown: (key) => {
97
+ const atom = live.atomOf(key)
98
+ if (showing.has(key)) {
99
+ if (showing.get(key) === atom) return
100
+ }
101
+ showing.set(key, atom)
102
+ run(key)
103
+ },
104
+ taken: (key) => {
105
+ showing.delete(key)
106
+ if (Bool.not(running.has(key))) return
107
+ running.delete(key)
108
+ gate.timeline(id, key, undefined)
109
+ },
110
+ recheck: () => {
111
+ showing.forEach((_, key) => run(key))
112
+ },
113
+ dispose: unmounted,
114
+ }
115
+ }