@wardic/dom 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,494 @@
1
+ /**
2
+ * **Features** (#511, ADR-0067): what an element pays for only when it needs it, shared by every DOM
3
+ * binding: each binding's `WardicProvider`, `LazyWardic` and elements read them through it.
4
+ *
5
+ * Each Feature is an Effect `Layer` (ADR-0067, *Features are Layers*): its services, built once per
6
+ * provider into the provider's runtime's `MemoMap` (`Layer.buildWithMemoMap`), so a Layer two Features
7
+ * share is built once, and ended with the provider. A Feature that arrives late, loaded lazily, is built
8
+ * the same way when it arrives: the runtime, made once, needn't change. A section of the tree (its
9
+ * `WardicProvider`, each `LazyWardic`) holds the services of the Features it has, a `Context`, joined
10
+ * with its parent's; an element looks a Feature up there.
11
+ *
12
+ * Unstable, for Wardic's own packages: public, with no semver promise.
13
+ *
14
+ * @module
15
+ */
16
+ // Unstable: ADR-0071, decision 5. #672: solid's `feature.ts`, moved to dom with the Features, on a Runner
17
+ // (Q10), naming the Features that add props (Q9).
18
+ import * as Color from "../Color.ts"
19
+ import type * as FlushGate from "../FlushGate.ts"
20
+ import type * as ProjectionSystem from "../ProjectionSystem.ts"
21
+ import * as Arr from "effect/Array"
22
+ import * as Cause from "effect/Cause"
23
+ import * as Context from "effect/Context"
24
+ import * as Effect from "effect/Effect"
25
+ import { constFalse, constVoid, identity } from "effect/Function"
26
+ import * as Layer from "effect/Layer"
27
+ import * as Option from "effect/Option"
28
+ import * as Predicate from "effect/Predicate"
29
+ import * as UndefinedOr from "effect/UndefinedOr"
30
+ import * as OwnerScope from "./OwnerScope.ts"
31
+ import type * as WardConfig from "./WardConfig.ts"
32
+ import type * as Reactivity from "@wardic/core/unstable/Reactivity"
33
+ import type * as WardicServices from "@wardic/core/unstable/WardicServices"
34
+
35
+ /**
36
+ * A **Feature**: its name, the key of the service its Layer gives (what an element looks up),
37
+ * and that Layer, built on the provider's runtime: its Environment, its flush gate and its projection
38
+ * options. `server` is what a server render, which builds no runtime, does with it: the
39
+ * `colors` Feature registers its colour spaces there too, as the render reads colours; the rest do
40
+ * nothing. `N` is its name as a type, by which each binding finds the props it adds.
41
+ */
42
+ // `N`: #516, ADR-0067 *Amendment (#516)*, decision 3. A Feature typed without it adds no props.
43
+ export interface Feature<I = any, S = any, N extends string = string> {
44
+ readonly name: N
45
+ readonly key: Context.Key<I, S>
46
+ readonly layer: Layer.Layer<I, never, ProviderServices>
47
+ readonly server?: (() => void) | undefined
48
+ }
49
+
50
+ /** Features as an app gives them: one, or a list, a preset's nested in it (`[domAnimation, layout]`). */
51
+ export type Features = Feature | ReadonlyArray<Features>
52
+
53
+ /**
54
+ * The names of the Features in `F` (#516): a Feature's own, every one's in a list, nested lists
55
+ * flattened, and what a load resolves to. What a Wardic instance's types find their props by. A
56
+ * Feature typed without its name (`Feature`, whose `N` is `string`) names none: as a member of a
57
+ * union, `string` would swallow every other name.
58
+ */
59
+ // Unconstrained: `F extends Features` would send it down `Features`' own recursion (TS2589).
60
+ export type FeatureNames<F> = F extends ReadonlyArray<infer E>
61
+ ? FeatureNames<E>
62
+ : F extends () => PromiseLike<infer L>
63
+ ? FeatureNames<L>
64
+ : F extends { readonly name: infer N extends string }
65
+ ? string extends N
66
+ ? never
67
+ : N
68
+ : never
69
+
70
+ /**
71
+ * What a prop of a Feature a Wardic instance doesn't have takes: nothing, so giving it is an error
72
+ * naming the Feature, `Type 'boolean' is not assignable to type 'NeedsFeature<"drag">'`.
73
+ */
74
+ // #516, Q15.
75
+ export interface NeedsFeature<N extends string> {
76
+ readonly "needs the Feature": N
77
+ }
78
+
79
+ /** A union's members, intersected. */
80
+ type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (i: infer I) => void ? I : never
81
+
82
+ /** The props `Groups` gives the Features named `N`, a binding's map from a Feature's name to its props (#516). */
83
+ export type GroupsOf<Groups, N extends string> = UnionToIntersection<Groups[N & keyof Groups]>
84
+
85
+ /** Every prop of the Features `Groups` has and `N` doesn't name, each {@link NeedsFeature} its own. */
86
+ export type AbsentGroupsOf<Groups, N extends string> = UnionToIntersection<
87
+ Exclude<keyof Groups, N> extends infer A ? (A extends keyof Groups & string ? { readonly [P in keyof Groups[A]]?: NeedsFeature<A> } : never) : never
88
+ >
89
+
90
+ /**
91
+ * The Features that add props to an element (#516): the gestures and `layout`. `colors` and `scroll`
92
+ * add none. Each binding's props for them are a map over these names.
93
+ */
94
+ // #672 (the build grill's Q9): named here, not as the keys of the DOM's props, so a binding whose props
95
+ // differ (Foldkit's) names the same Features; each binding's map of props satisfies it.
96
+ export type PropFeature = "hover" | "press" | "focus" | "inView" | "pan" | "drag" | "layout"
97
+
98
+ /**
99
+ * The names of those of Features `F` that add props (#516), on any binding. A Wardic instance's
100
+ * types take these, not `F`: every list with each of them is one type, and an error prints names, not
101
+ * each Feature's service.
102
+ */
103
+ export type PropFeatureNames<F> = Extract<FeatureNames<F>, PropFeature>
104
+
105
+ /** Whether `N` names every Feature in `Groups`: a Wardic instance whose props are the binding's plain ones. */
106
+ export type NamesEvery<Groups, N extends string> = [Exclude<keyof Groups, N>] extends [never] ? true : false
107
+
108
+ /** A Wardic instance's layout hooks, `Hooks`, when its Features named `N` include `layout`; else nothing (#516, Q6). */
109
+ export type LayoutHooksFor<N extends string, Hooks> = "layout" extends N ? Hooks : unknown
110
+
111
+ /** Features loaded lazily: `() => import("./features.ts").then((m) => m.domMax)`. */
112
+ export type FeatureLoad = () => Promise<Features>
113
+
114
+ /** Features given to a `WardicProvider` or a `LazyWardic`: at once, or loaded lazily. */
115
+ export type FeaturesProp = Features | FeatureLoad
116
+
117
+ /**
118
+ * `key`'s Layer for a Feature: the Environment's service when it gives one (`@wardic/test`'s `TestLive`),
119
+ * else `layer`, the DOM's, which a provider's `MemoMap` builds once for every Feature standing on it.
120
+ */
121
+ // ADR-0067 decision 14 (the gestures' input) and *Amendment (#518)*, decision 5 (the scroll). A Feature
122
+ // module's call to it is marked pure, so an app that never imports the module drops `layer`.
123
+ export const fromEnvironmentOr = <I, S, R>(key: Context.Key<I, S>, layer: Layer.Layer<I, never, R>): Layer.Layer<I, never, R> =>
124
+ Layer.unwrap(
125
+ Effect.map(
126
+ Effect.serviceOption(key),
127
+ Option.match({
128
+ onSome: (given): Layer.Layer<I, never, R> => Layer.succeed(key)(given),
129
+ onNone: (): Layer.Layer<I, never, R> => layer,
130
+ }),
131
+ ),
132
+ )
133
+
134
+ /** Features as one flat list, each once, in order. */
135
+ export const flatten = (features: Features): ReadonlyArray<Feature> => Arr.dedupeWith(flattenInto(features), (a, b) => a === b)
136
+
137
+ const flattenInto = (features: Features): ReadonlyArray<Feature> => {
138
+ if (isFeature(features)) return [features]
139
+ return Arr.flatMap(features as ReadonlyArray<Features>, flattenInto)
140
+ }
141
+
142
+ const isFeature = (value: Features): value is Feature => Predicate.hasProperty(value, "layer")
143
+
144
+ /** Whether a `features` prop loads lazily: a function, where Features are values. */
145
+ export const isLoad = (prop: FeaturesProp): prop is FeatureLoad => Predicate.isFunction(prop)
146
+
147
+ /**
148
+ * What a Wardic instance is made with (#516, Q8): Features, loads of them, or lists of either, nested
149
+ * (`[domAnimation, () => import("./drag-feature.ts").then((m) => m.drag)]`).
150
+ */
151
+ export type InstanceFeaturesProp = Feature | FeatureLoad | ReadonlyArray<InstanceFeaturesProp>
152
+
153
+ /**
154
+ * A Wardic instance's Features (#516): what its elements and hooks join their section's with, one per
155
+ * provider. Its code is its binding's, which only the binding's `createWardic` imports, so an app with no
156
+ * Wardic instance ships none of it: the spine only calls `own`.
157
+ */
158
+ export interface InstanceFeatures {
159
+ /**
160
+ * Its Features in `registry`'s provider, one per provider: those given at once, built on first need,
161
+ * and each load, started on the client the first time it's asked for and built as it arrives, until
162
+ * the provider ends. A server render builds what's given and loads nothing.
163
+ */
164
+ readonly own: (registry: FeatureRegistry, host: InstanceHost) => Own
165
+ }
166
+
167
+ /** What an element's Features come from (#511, #516): those it brings, a Complete element's every one, or a Wardic instance's. */
168
+ export interface ElementFeatures {
169
+ readonly brings?: ReadonlyArray<Feature> | undefined
170
+ readonly complete?: boolean | undefined
171
+ readonly instance?: InstanceFeatures | undefined
172
+ }
173
+
174
+ /** No Features. */
175
+ export const NONE: Context.Context<never> = Context.empty()
176
+
177
+ /**
178
+ * A section of the tree's Features (#511): a `WardicProvider`'s, a `LazyWardic`'s, or an element's,
179
+ * each its own joined with its parent's. Each binding makes its sections with its own signals.
180
+ */
181
+ export interface FeatureSection {
182
+ /** The services of the Features it has now. Tracked: a lazy one arriving changes it. */
183
+ readonly services: () => Context.Context<never>
184
+ /** Whether a lazy load of its own or a parent's is still on its way: no missing-Feature warning while one is. */
185
+ readonly pending: () => boolean
186
+ /** Whether it, or a section above it, is `strict`: a Complete element under it is an error in development. */
187
+ readonly strict: boolean
188
+ }
189
+
190
+ /** Outside every provider, and above each provider's own: no Features, nothing on its way, not strict. */
191
+ export const ROOT: FeatureSection = { services: () => NONE, pending: constFalse, strict: false }
192
+
193
+ /** What a section takes from its binding: its reactivity, whether it renders on a server, and its owner's cleanup. */
194
+ export interface SectionHost {
195
+ readonly reactivity: Reactivity.Reactivity
196
+ readonly server: boolean
197
+ readonly onCleanup: (fn: () => void) => void
198
+ }
199
+
200
+ /**
201
+ * A section under `parent` with `prop`'s Features (#511):
202
+ * - **Given at once**, they're built on first need, the first time an element in it asks (#51: a
203
+ * provider with no element under it builds nothing); a server render runs their `server` part at
204
+ * once, as its elements may read what it registers.
205
+ * - **Loaded lazily** (decision 8), the load starts now on the client and they're built as they
206
+ * arrive, from then on; `pending` until it settles. A failed load is `report`ed, once. A server
207
+ * render loads nothing: it renders as it would without them.
208
+ *
209
+ * Its services join its own and its parent's, joined again only when either changes.
210
+ */
211
+ export const makeSection = (
212
+ parent: FeatureSection,
213
+ registry: FeatureRegistry,
214
+ prop: FeaturesProp | undefined,
215
+ strict: boolean,
216
+ report: (cause: Cause.Cause<unknown>) => void,
217
+ host: SectionHost,
218
+ ): FeatureSection => {
219
+ const own = ownOf(registry.build, prop, report, host)
220
+ return { ...joinSections(parent, own), strict: strict || parent.strict }
221
+ }
222
+
223
+ /** `parent`'s Features and `own`'s, as a section: `parent`'s `strict`. */
224
+ export const joinSections = (parent: FeatureSection, own: Own): FeatureSection => ({ ...joinOwns(parent, own), strict: parent.strict })
225
+
226
+ /** `a`'s services and `b`'s, joined again only when either changes, and whether either's load is on its way. */
227
+ export const joinOwns = (a: Own, b: Own): Own => {
228
+ let last: { readonly a: Context.Context<never>; readonly b: Context.Context<never>; readonly joined: Context.Context<never> } | undefined
229
+ const services = (): Context.Context<never> => {
230
+ const first = a.services()
231
+ const second = b.services()
232
+ if (Predicate.isNotUndefined(last) && last.a === first && last.b === second) return last.joined
233
+ const joined = Context.merge(first, second)
234
+ last = { a: first, b: second, joined }
235
+ return joined
236
+ }
237
+ return { services, pending: () => b.pending() || a.pending() }
238
+ }
239
+
240
+ /** A section's own Features: their services and whether they're on their way. */
241
+ export interface Own {
242
+ readonly services: () => Context.Context<never>
243
+ readonly pending: () => boolean
244
+ }
245
+
246
+ const NO_OWN: Own = { services: () => NONE, pending: constFalse }
247
+
248
+ export const ownOf = (build: Build, prop: FeaturesProp | undefined, report: (cause: Cause.Cause<unknown>) => void, host: SectionHost): Own => {
249
+ if (Predicate.isUndefined(prop)) return NO_OWN
250
+ if (isLoad(prop)) return loaded(build, prop, report, host)
251
+ const features = flatten(prop)
252
+ if (host.server) build(features)
253
+ let built: Context.Context<never> | undefined
254
+ return {
255
+ services: () =>
256
+ UndefinedOr.match(built, {
257
+ onDefined: identity,
258
+ onUndefined: () => {
259
+ built = build(features)
260
+ return built
261
+ },
262
+ }),
263
+ pending: constFalse,
264
+ }
265
+ }
266
+
267
+ /** What builds Features: a registry's `build`. */
268
+ export type Build = (features: ReadonlyArray<Feature>) => Context.Context<never>
269
+
270
+ /** Features loaded lazily: none until they arrive, which a trigger tells; on the client only. */
271
+ const loaded = (build: Build, load: FeatureLoad, report: (cause: Cause.Cause<unknown>) => void, host: SectionHost): Own => {
272
+ if (host.server) return NO_OWN
273
+ const changed = host.reactivity.trigger()
274
+ let services = NONE
275
+ let pending = true
276
+ let live = true
277
+ host.onCleanup(() => {
278
+ live = false
279
+ })
280
+ load().then(
281
+ (features) => {
282
+ if (!live) return
283
+ services = build(flatten(features))
284
+ pending = false
285
+ changed.notify()
286
+ },
287
+ (error: unknown) => {
288
+ if (!live) return
289
+ pending = false
290
+ changed.notify()
291
+ report(Cause.die(error))
292
+ },
293
+ )
294
+ return {
295
+ services: () => {
296
+ changed.track()
297
+ return services
298
+ },
299
+ pending: () => {
300
+ changed.track()
301
+ return pending
302
+ },
303
+ }
304
+ }
305
+
306
+ /**
307
+ * A provider's Features: each built once, on first need, and every list it's asked for joined once.
308
+ * `build` is synchronous; a Feature's Layer that can't build at once is a defect.
309
+ */
310
+ export interface FeatureRegistry {
311
+ /** The services of `features`, each Feature built the first time it's asked for. */
312
+ readonly build: (features: ReadonlyArray<Feature>) => Context.Context<never>
313
+ /** A section of exactly `features`, nothing on its way: one per list, a Complete element's (#511). */
314
+ readonly section: (features: ReadonlyArray<Feature>) => FeatureSection
315
+ /**
316
+ * The services of every Feature built so far, whichever section asked: what a part of the provider
317
+ * that brings no Feature works with when one is there (the projection system, for a presence).
318
+ */
319
+ readonly built: () => Context.Context<never>
320
+ /** Logs `message` at Warning the first time `feature` is named: development's word on a missing Feature. */
321
+ readonly warnOnce: (feature: string, message: string) => void
322
+ /** Runs `end` as the provider ends, before its Features: what a Wardic instance's loads stop by (#516). */
323
+ readonly onEnd: (end: () => void) => void
324
+ /** Ends every Feature built, the provider's runtime after (a Feature's Layer may stand on it). */
325
+ readonly dispose: () => Promise<void>
326
+ }
327
+
328
+ /**
329
+ * What a Wardic instance's Features take from the binding asking for them (#516): a section's host but
330
+ * its cleanup, which is its provider's (`FeatureRegistry.onEnd`), and what reports a failed load.
331
+ */
332
+ export interface InstanceHost extends Omit<SectionHost, "onCleanup"> {
333
+ readonly report: (cause: Cause.Cause<unknown>) => void
334
+ }
335
+
336
+ /**
337
+ * A registry's sections of exactly a list, one per list; what runs as it ends (`onEnd`, run by `end`);
338
+ * and its warnings, one per Feature.
339
+ */
340
+ const sectionsAndWarnings = (build: Build, warn: (message: string) => void) => {
341
+ const sections = new WeakMap<ReadonlyArray<Feature>, FeatureSection>()
342
+ const ends: Array<() => void> = []
343
+ const warned = new Set<string>()
344
+ return {
345
+ onEnd: (end: () => void): void => {
346
+ ends.push(end)
347
+ },
348
+ end: (): void => Arr.forEach(ends.splice(0), (end) => end()),
349
+ section: (features: ReadonlyArray<Feature>): FeatureSection =>
350
+ UndefinedOr.match(sections.get(features), {
351
+ onDefined: identity,
352
+ onUndefined: () => {
353
+ const services = build(features)
354
+ const section: FeatureSection = { services: () => services, pending: constFalse, strict: false }
355
+ sections.set(features, section)
356
+ return section
357
+ },
358
+ }),
359
+ warnOnce: (feature: string, message: string): void => {
360
+ if (warned.has(feature)) return
361
+ warned.add(feature)
362
+ warn(message)
363
+ },
364
+ }
365
+ }
366
+
367
+ /**
368
+ * What a client provider hands its projection system (#511): whether reduced motion applies now
369
+ * (ADR-0029), and the app's scale correctors (#443). The `layout` Feature's Layer reads it from the
370
+ * provider's runtime, as the projection system is no longer built with it.
371
+ */
372
+ export class ProjectionOptions extends /*#__PURE__*/ Context.Service<ProjectionOptions, ProjectionSystem.Options>()("@wardic/dom/unstable/ProjectionOptions") {}
373
+
374
+ /** What a provider's runtime holds: its Environment, and its flush gate and projection options over it. */
375
+ // #672: out of solid's runtime.ts, with the Features that build on it.
376
+ export type ProviderServices = WardicServices.WardicServices | FlushGate.FlushGate | ProjectionOptions
377
+
378
+ /** What a provider's Features are built on (#672, Q10): its runtime as a Runner, with the MemoMap they share. */
379
+ export type FeatureRuntime = WardicServices.Runner<ProviderServices> & { readonly memoMap: Layer.MemoMap }
380
+
381
+ /**
382
+ * A client provider's Features (#511): built into `runtime`'s `MemoMap` in a Scope of their own, a child
383
+ * of the runtime's that closes before its Layers do, so a Feature ends before the Environment it stands
384
+ * on. A list asked for again (the Complete element's every Feature) is joined once.
385
+ */
386
+ // #618 (decision 4): the Scope was detached, closed by `dispose` before the runtime's, and a failing
387
+ // Feature finalizer skipped the runtime's disposal. A child forked after `ManagedRuntime.make`'s own
388
+ // closes first in its Scope's reverse order. #672 (Q10): it runs on a Runner with its MemoMap, and its
389
+ // binding disposes the runtime (`dispose`), so a Feature reads no binding's runtime type.
390
+ export const clientRegistry = (runtime: FeatureRuntime, dispose: () => Promise<void>): FeatureRegistry => {
391
+ const scope = OwnerScope.open(runtime)
392
+ const built = new Map<Feature, Context.Context<never>>()
393
+ const lists = new WeakMap<ReadonlyArray<Feature>, Context.Context<never>>()
394
+ let all = NONE
395
+ const one = (feature: Feature): Context.Context<never> =>
396
+ UndefinedOr.match(built.get(feature), {
397
+ onDefined: (services) => services,
398
+ onUndefined: () => {
399
+ const services = runtime.runSync(Layer.buildWithMemoMap(feature.layer, runtime.memoMap, scope)) as Context.Context<never>
400
+ built.set(feature, services)
401
+ all = Context.merge(all, services)
402
+ return services
403
+ },
404
+ })
405
+ const build = (features: ReadonlyArray<Feature>): Context.Context<never> =>
406
+ UndefinedOr.match(lists.get(features), {
407
+ onDefined: (services) => services,
408
+ onUndefined: () => {
409
+ const services = Arr.reduce(features, NONE, (joined, feature) => Context.merge(joined, one(feature)))
410
+ lists.set(features, services)
411
+ return services
412
+ },
413
+ })
414
+ const { end, ...rest } = sectionsAndWarnings(build, (message) => {
415
+ runtime.runFork(Effect.logWarning(message))
416
+ })
417
+ return {
418
+ build,
419
+ built: () => all,
420
+ ...rest,
421
+ dispose: () => {
422
+ end()
423
+ return dispose()
424
+ },
425
+ }
426
+ }
427
+
428
+ /**
429
+ * A server render's Features (ADR-0021): none built, as no runtime is; each one's `server` run once,
430
+ * the first time it's asked for. Disposing disposes the unbuilt runtime (`dispose`), as on unmount.
431
+ */
432
+ export const serverRegistry = (dispose: () => Promise<void>): FeatureRegistry => {
433
+ const ran = new Set<Feature>()
434
+ const build = (features: ReadonlyArray<Feature>): Context.Context<never> => {
435
+ Arr.forEach(features, (feature) => {
436
+ if (ran.has(feature)) return
437
+ ran.add(feature)
438
+ UndefinedOr.map(feature.server, (server) => server())
439
+ })
440
+ return NONE
441
+ }
442
+ // A server render says nothing: the client, rendering the same, does.
443
+ const { end, ...rest } = sectionsAndWarnings(build, constVoid)
444
+ return {
445
+ build,
446
+ built: () => NONE,
447
+ ...rest,
448
+ dispose: () => {
449
+ end()
450
+ return dispose()
451
+ },
452
+ }
453
+ }
454
+
455
+ /**
456
+ * A CSS function naming a colour space only the `colors` Feature reads: `oklch()`, `oklab()`, `lab()`,
457
+ * `lch()`, `hwb()`, and `color()` in any space but `srgb`, which the base reads.
458
+ */
459
+ const WIDE_GAMUT = /^\s*(?:(?:oklch|oklab|lab|lch|hwb)\(|color\(\s*(?!srgb\s))/i
460
+
461
+ /**
462
+ * The first of `values` that only the `colors` Feature would read as a colour (#511, decision 7): a
463
+ * string naming a wide-gamut space, while no space beyond sRGB's is registered on the page.
464
+ * `undefined` when there's none. Asked of the page, not of an element's Features: culori's spaces are
465
+ * the page's, so one registered by any provider is read by every element (`features/Colors`).
466
+ */
467
+ export const unreadColorIn = (values: Readonly<Record<string, unknown>>): string | undefined => {
468
+ if (Color.spacesRegistered()) return undefined
469
+ return Arr.findFirst(Object.values(values), (value): value is string => Predicate.isString(value) && WIDE_GAMUT.test(value)).pipe(Option.getOrUndefined)
470
+ }
471
+
472
+ /**
473
+ * Development's word on a Complete element under a `strict` section (#511, ADR-0067 decision 7,
474
+ * Motion's), naming the binding's `complete` forms and the `slim` ones to use.
475
+ */
476
+ export const strictMessage = (complete: string, slim: string): string =>
477
+ `wardic: a Complete element (${complete}) is rendered under a strict WardicProvider or LazyWardic. ` +
478
+ `It brings every Feature's code with it; render the Slim element (${slim}) instead.`
479
+
480
+ /** What development's word on a missing `layout` Feature names (#511): the props that need it. */
481
+ export const LAYOUT_PROPS = "A layout prop (`layout`, `layoutId`, `layoutScroll` or `layoutRoot`)"
482
+
483
+ /** Whether a config makes its element a projection node: `layout` (or a mode), a `layoutId`, `layoutScroll` or `layoutRoot`. */
484
+ export const wantsLayoutNode = (c: WardConfig.WardConfig): boolean =>
485
+ c.layout === true || Predicate.isString(c.layout) || Predicate.isNotUndefined(c.layoutId) || c.layoutScroll === true || c.layoutRoot === true
486
+
487
+ /**
488
+ * Development's word on a missing Feature (#511, ADR-0067 decision 7): what needed it, its import from
489
+ * the binding's `entry`, and where to add it. Not a Complete element, which a `strict` section makes
490
+ * an error (#581).
491
+ */
492
+ export const missingMessage = (feature: string, what: string, entry: string): string =>
493
+ `wardic: ${what} needs the \`${feature}\` Feature, which no WardicProvider or LazyWardic above this element has. ` +
494
+ `Add it: \`import { ${feature} } from "${entry}"\`, then \`<WardicProvider features={[${feature}]}>\` or \`<LazyWardic features={[${feature}]}>\`.`
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What an element reads of its section's gesture Features (#511, ADR-0067 decision 3): each gesture's
3
+ * service, `undefined` without its Feature, the gestures' input a section with one has, and the words
4
+ * development's message on a missing one names. Every binding's; it reaches no Feature's code, only
5
+ * their keys.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #672: solid's `gesture-features.ts`, moved to dom with the Features.
12
+ import * as InputSource from "@wardic/core/InputSource"
13
+ import * as Context from "effect/Context"
14
+ import * as Option from "effect/Option"
15
+
16
+ /** `key`'s service among `services`, or `undefined` when they hold none: its Feature isn't there. */
17
+ export const serviceIn = <I, S>(services: Context.Context<never>, key: Context.Key<I, S>): S | undefined =>
18
+ Option.getOrUndefined(Context.getOption(services as Context.Context<I>, key))
19
+
20
+ /** The gestures' input among `services`: a section with any gesture Feature but `inView` has it. */
21
+ export const inputIn = (services: Context.Context<never>): InputSource.InputSource["Service"] =>
22
+ Context.get(services as Context.Context<InputSource.InputSource>, InputSource.InputSource)
23
+
24
+ /** What development's word on a missing gesture Feature names, by Feature: what the element asked of it. */
25
+ export const GESTURE_WORDS = {
26
+ hover: "Its hover (`whileHover`, or a hover event)",
27
+ press: "Its press (`whileTap`, or a tap event)",
28
+ focus: "Its focus (`whileFocus`)",
29
+ inView: "Its view (`whileInView`, or a viewport event)",
30
+ pan: "Its pan (a pan event)",
31
+ drag: "Its drag (`drag`)",
32
+ } as const
33
+
34
+ /** Whether `services` hold `key`'s service: its Feature is there. */
35
+ export const hasService = <I, S>(services: Context.Context<never>, key: Context.Key<I, S>): boolean => Option.isSome(Context.getOption(services as Context.Context<I>, key))
36
+
37
+ /** `key`'s service among `services`, which hold it: a Feature a hook or component brought. */
38
+ export const serviceOf = <I, S>(services: Context.Context<never>, key: Context.Key<I, S>): S => Context.get(services as Context.Context<I>, key)
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The info a gesture event hands over: Motion's `EventInfo` / `TapInfo` and `PanInfo` (a drag's and a
3
+ * pan's), with the pointer's `point` in the viewport (`clientX` / `clientY`, as
4
+ * `getBoundingClientRect()` measures), not the page as Motion's. Every binding over the DOM builds it
5
+ * here, for its callbacks or its events.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // #257, #273; the viewport point, grilled B on both Solid bindings (ADR-0046, ADR-0047). Unstable:
12
+ // ADR-0071, decision 5. #672: solid's `gesture-info.ts`, moved with `WardConfig`, which names it.
13
+ import type * as Drag from "@wardic/core/Drag"
14
+ import type * as InputSource from "@wardic/core/InputSource"
15
+ import type * as Recognizer from "@wardic/core/Recognizer"
16
+
17
+ /** A point in the viewport. */
18
+ export interface WardicPoint {
19
+ readonly x: number
20
+ readonly y: number
21
+ }
22
+
23
+ /** A hover's or a press's event: where the pointer was, in the viewport. */
24
+ export interface WardicPointInfo {
25
+ readonly point: WardicPoint
26
+ }
27
+
28
+ /**
29
+ * A drag's event: where the pointer was, in the viewport, and the drag's `offset` from its down, its
30
+ * last `delta` and its `velocity` (px/s). A scroll during the drag counts as movement in `offset`, as
31
+ * Motion's does; `point` stays where the pointer is on the screen. A one-axis drag's are zeroed off
32
+ * its axis.
33
+ */
34
+ export interface WardicDragInfo {
35
+ readonly point: WardicPoint
36
+ readonly offset: WardicPoint
37
+ readonly delta: WardicPoint
38
+ readonly velocity: WardicPoint
39
+ }
40
+
41
+ /** How a press was made: by a pointer, or a **Keyboard press**. */
42
+ export type WardicPressInput = "pointer" | "keyboard"
43
+
44
+ /**
45
+ * A press's event: where it was, in the viewport, and how it was made. A **Keyboard
46
+ * press**'s point is its element's centre, measured at the key, so code that places something at a
47
+ * press works for one.
48
+ */
49
+ export interface WardicPressInfo extends WardicPointInfo {
50
+ readonly input: WardicPressInput
51
+ }
52
+
53
+ /**
54
+ * The platform's event a press's callback hears: a pointer's; a **Keyboard press**'s key, or
55
+ * the blur that cancelled it.
56
+ */
57
+ export type WardicPressEvent = PointerEvent | KeyboardEvent | FocusEvent
58
+
59
+ /** A press's info (#427): a pointer's point less the scroll its hold counted into it, or a **Keyboard press**'s element's centre. */
60
+ export const pressInfoOf = (press: Recognizer.PressEvent, element: Element): WardicPressInfo => {
61
+ if (press.input === "pointer") return { point: { x: press.event.x - press.event.scroll.x, y: press.event.y - press.event.scroll.y }, input: "pointer" }
62
+ const box = element.getBoundingClientRect()
63
+ return { point: { x: box.left + box.width / 2, y: box.top + box.height / 2 }, input: "keyboard" }
64
+ }
65
+
66
+ /** A hover's or a press's info: its event's point less the scroll its hold counted into it. */
67
+ export const pointInfoOf = (event: InputSource.PointerLikeEvent): WardicPointInfo => ({
68
+ point: { x: event.x - event.scroll.x, y: event.y - event.scroll.y },
69
+ })
70
+
71
+ /** What a drag's or a pan's sample carries for its info. */
72
+ type Sampled = Pick<Drag.Sample, "point" | "scroll" | "offset" | "delta" | "velocity">
73
+
74
+ /** A drag sample's info: its point less the scroll its hold counted into it, and its own offset, delta and velocity. */
75
+ export const dragInfoOf = (sample: Sampled): WardicDragInfo => ({
76
+ point: { x: sample.point.x - sample.scroll.x, y: sample.point.y - sample.scroll.y },
77
+ offset: sample.offset,
78
+ delta: sample.delta,
79
+ velocity: sample.velocity,
80
+ })
81
+
82
+ /** A sample's point alone, as a hover's or a press's info (a pan's session's start, #273). */
83
+ export const pointOfSample = (sample: Sampled): WardicPointInfo => ({
84
+ point: { x: sample.point.x - sample.scroll.x, y: sample.point.y - sample.scroll.y },
85
+ })