@wardic/foldkit 0.0.0-stage → 1.3.0

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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/AnimationControls.d.ts +37 -0
  5. package/dist/AnimationControls.d.ts.map +1 -0
  6. package/dist/AnimationControls.js +37 -0
  7. package/dist/AnimationControls.js.map +1 -0
  8. package/dist/AnimationScope.d.ts +20 -0
  9. package/dist/AnimationScope.d.ts.map +1 -0
  10. package/dist/AnimationScope.js +20 -0
  11. package/dist/AnimationScope.js.map +1 -0
  12. package/dist/DragControls.d.ts +25 -0
  13. package/dist/DragControls.d.ts.map +1 -0
  14. package/dist/DragControls.js +21 -0
  15. package/dist/DragControls.js.map +1 -0
  16. package/dist/Features.d.ts +36 -0
  17. package/dist/Features.d.ts.map +1 -0
  18. package/dist/Features.js +44 -0
  19. package/dist/Features.js.map +1 -0
  20. package/dist/Ward.d.ts +301 -0
  21. package/dist/Ward.d.ts.map +1 -0
  22. package/dist/Ward.js +6 -0
  23. package/dist/Ward.js.map +1 -0
  24. package/dist/Wardic.d.ts +363 -0
  25. package/dist/Wardic.d.ts.map +1 -0
  26. package/dist/Wardic.js +85 -0
  27. package/dist/Wardic.js.map +1 -0
  28. package/dist/index.d.ts +15 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +20 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/internal/builder.d.ts +8 -0
  33. package/dist/internal/builder.d.ts.map +1 -0
  34. package/dist/internal/builder.js +242 -0
  35. package/dist/internal/builder.js.map +1 -0
  36. package/dist/internal/commands.d.ts +143 -0
  37. package/dist/internal/commands.d.ts.map +1 -0
  38. package/dist/internal/commands.js +242 -0
  39. package/dist/internal/commands.js.map +1 -0
  40. package/dist/internal/delivery.d.ts +44 -0
  41. package/dist/internal/delivery.d.ts.map +1 -0
  42. package/dist/internal/delivery.js +85 -0
  43. package/dist/internal/delivery.js.map +1 -0
  44. package/dist/internal/dev.d.ts +10 -0
  45. package/dist/internal/dev.d.ts.map +1 -0
  46. package/dist/internal/dev.js +10 -0
  47. package/dist/internal/dev.js.map +1 -0
  48. package/dist/internal/dev.production.d.ts +8 -0
  49. package/dist/internal/dev.production.d.ts.map +1 -0
  50. package/dist/internal/dev.production.js +8 -0
  51. package/dist/internal/dev.production.js.map +1 -0
  52. package/dist/internal/drag.d.ts +66 -0
  53. package/dist/internal/drag.d.ts.map +1 -0
  54. package/dist/internal/drag.js +71 -0
  55. package/dist/internal/drag.js.map +1 -0
  56. package/dist/internal/element.d.ts +59 -0
  57. package/dist/internal/element.d.ts.map +1 -0
  58. package/dist/internal/element.js +582 -0
  59. package/dist/internal/element.js.map +1 -0
  60. package/dist/internal/gestures.d.ts +62 -0
  61. package/dist/internal/gestures.d.ts.map +1 -0
  62. package/dist/internal/gestures.js +109 -0
  63. package/dist/internal/gestures.js.map +1 -0
  64. package/dist/internal/hydrate.d.ts +5 -0
  65. package/dist/internal/hydrate.d.ts.map +1 -0
  66. package/dist/internal/hydrate.js +27 -0
  67. package/dist/internal/hydrate.js.map +1 -0
  68. package/dist/internal/keys.d.ts +21 -0
  69. package/dist/internal/keys.d.ts.map +1 -0
  70. package/dist/internal/keys.js +12 -0
  71. package/dist/internal/keys.js.map +1 -0
  72. package/dist/internal/layout.d.ts +29 -0
  73. package/dist/internal/layout.d.ts.map +1 -0
  74. package/dist/internal/layout.js +88 -0
  75. package/dist/internal/layout.js.map +1 -0
  76. package/dist/internal/mount.d.ts +22 -0
  77. package/dist/internal/mount.d.ts.map +1 -0
  78. package/dist/internal/mount.js +152 -0
  79. package/dist/internal/mount.js.map +1 -0
  80. package/dist/internal/presence.d.ts +33 -0
  81. package/dist/internal/presence.d.ts.map +1 -0
  82. package/dist/internal/presence.js +338 -0
  83. package/dist/internal/presence.js.map +1 -0
  84. package/dist/internal/reactivity.d.ts +15 -0
  85. package/dist/internal/reactivity.d.ts.map +1 -0
  86. package/dist/internal/reactivity.js +26 -0
  87. package/dist/internal/reactivity.js.map +1 -0
  88. package/dist/internal/reorder.d.ts +47 -0
  89. package/dist/internal/reorder.d.ts.map +1 -0
  90. package/dist/internal/reorder.js +250 -0
  91. package/dist/internal/reorder.js.map +1 -0
  92. package/dist/internal/scope.d.ts +28 -0
  93. package/dist/internal/scope.d.ts.map +1 -0
  94. package/dist/internal/scope.js +44 -0
  95. package/dist/internal/scope.js.map +1 -0
  96. package/dist/internal/server.d.ts +13 -0
  97. package/dist/internal/server.d.ts.map +1 -0
  98. package/dist/internal/server.js +13 -0
  99. package/dist/internal/server.js.map +1 -0
  100. package/dist/internal/server.node.d.ts +8 -0
  101. package/dist/internal/server.node.d.ts.map +1 -0
  102. package/dist/internal/server.node.js +8 -0
  103. package/dist/internal/server.node.js.map +1 -0
  104. package/dist/internal/services.d.ts +231 -0
  105. package/dist/internal/services.d.ts.map +1 -0
  106. package/dist/internal/services.js +350 -0
  107. package/dist/internal/services.js.map +1 -0
  108. package/dist/internal/tree.d.ts +71 -0
  109. package/dist/internal/tree.d.ts.map +1 -0
  110. package/dist/internal/tree.js +207 -0
  111. package/dist/internal/tree.js.map +1 -0
  112. package/dist/internal/variant-node.d.ts +62 -0
  113. package/dist/internal/variant-node.d.ts.map +1 -0
  114. package/dist/internal/variant-node.js +279 -0
  115. package/dist/internal/variant-node.js.map +1 -0
  116. package/dist/internal/view-transition.d.ts +10 -0
  117. package/dist/internal/view-transition.d.ts.map +1 -0
  118. package/dist/internal/view-transition.js +36 -0
  119. package/dist/internal/view-transition.js.map +1 -0
  120. package/dist/internal/walk.d.ts +26 -0
  121. package/dist/internal/walk.d.ts.map +1 -0
  122. package/dist/internal/walk.js +162 -0
  123. package/dist/internal/walk.js.map +1 -0
  124. package/package.json +99 -4
  125. package/src/AnimationControls.ts +46 -0
  126. package/src/AnimationScope.ts +19 -0
  127. package/src/DragControls.ts +27 -0
  128. package/src/Features.ts +45 -0
  129. package/src/Ward.ts +434 -0
  130. package/src/Wardic.ts +410 -0
  131. package/src/index.ts +20 -0
  132. package/src/internal/builder.ts +262 -0
  133. package/src/internal/commands.ts +359 -0
  134. package/src/internal/delivery.ts +116 -0
  135. package/src/internal/dev.production.ts +7 -0
  136. package/src/internal/dev.ts +9 -0
  137. package/src/internal/drag.ts +136 -0
  138. package/src/internal/element.ts +668 -0
  139. package/src/internal/gestures.ts +184 -0
  140. package/src/internal/hydrate.ts +29 -0
  141. package/src/internal/keys.ts +19 -0
  142. package/src/internal/layout.ts +109 -0
  143. package/src/internal/mount.ts +181 -0
  144. package/src/internal/presence.ts +362 -0
  145. package/src/internal/reactivity.ts +45 -0
  146. package/src/internal/reorder.ts +313 -0
  147. package/src/internal/scope.ts +60 -0
  148. package/src/internal/server.node.ts +7 -0
  149. package/src/internal/server.ts +12 -0
  150. package/src/internal/services.ts +508 -0
  151. package/src/internal/tree.ts +230 -0
  152. package/src/internal/variant-node.ts +352 -0
  153. package/src/internal/view-transition.ts +43 -0
  154. package/src/internal/walk.ts +211 -0
@@ -0,0 +1,262 @@
1
+ /**
2
+ * `wardic.html(h)` (ADR-0071, decision 18): the builder `w`, made once per `h`. It holds `h`'s element
3
+ * factories, `keyed`, and Wardic's attribute factories, and no more (#791, Q5): Foldkit's own
4
+ * attributes stay on `h`. A `w.*` element folds its Wardic attributes into one config, renders one
5
+ * `h.Style` (the user's style with the Starting style on top), one `wardic` property (the Delivery),
6
+ * and one Mount (fused with the user's), and stamps a Foldkit identity (decision 19), so it's never
7
+ * kept where a plain element was (P2).
8
+ *
9
+ * @module
10
+ */
11
+ import * as Appear from "@wardic/dom/Appear"
12
+ import * as Arr from "effect/Array"
13
+ import * as Bool from "effect/Boolean"
14
+ import { constFalse, identity } from "effect/Function"
15
+ import * as Option from "effect/Option"
16
+ import * as Predicate from "effect/Predicate"
17
+ import * as Rec from "effect/Record"
18
+ import * as Str from "effect/String"
19
+ import * as UndefinedOr from "effect/UndefinedOr"
20
+ import { brandViewResult } from "foldkit/brand"
21
+ import type { Attribute, ChildAttribute, Html, HtmlBuilder } from "foldkit/html"
22
+ import type { MountAction } from "foldkit/mount"
23
+ import * as Ward from "../Ward.ts"
24
+ import { propertyOf } from "./delivery.ts"
25
+ import { type Config, startingStyleOf, stringified } from "./element.ts"
26
+ import { mountOf } from "./mount.ts"
27
+ import { noteServerRender, registryOf, snapshotPopLayouts, type State } from "./services.ts"
28
+ import type { AnimationScope } from "./scope.ts"
29
+ import { type ViewNode, walkProvider } from "./walk.ts"
30
+ import { DEV } from "@wardic/foldkit/internal/dev"
31
+ import { IS_SERVER } from "@wardic/foldkit/internal/server"
32
+
33
+ /** The one identity every `w.*` element is stamped with (#791, Q8). */
34
+ const IDENTITY = "@wardic/foldkit"
35
+
36
+ /** Whether a `w.Presence` is a `popLayout` one. */
37
+ const isPopLayout = (presence: Ward.PresenceOptions<unknown> | undefined): boolean => UndefinedOr.match(presence, { onUndefined: constFalse, onDefined: (options) => options.mode === "popLayout" })
38
+
39
+ /** What a `w.*` element takes: Foldkit's attributes and Wardic's. */
40
+ export type Attributes<Message> = ReadonlyArray<Attribute<Message> | ChildAttribute | Ward.Attribute>
41
+
42
+ /** A Wardic attribute for `key`: what `w.Initial(…)` and the rest return. */
43
+ const attribute = (key: Ward.Attribute[Ward.TypeId], value: unknown): Ward.Attribute => ({ [Ward.TypeId]: key, value })
44
+
45
+ /** An element's attributes, folded: its Wardic config, the user's `h.Style`, the user's Mount, `w.Provider()`'s options, and the rest, Foldkit's. */
46
+ interface Folded<Message> {
47
+ config: Ward.Config<Message>
48
+ style: Record<string, string> | undefined
49
+ mount: MountAction<Message> | undefined
50
+ provider: Ward.ProviderOptions | undefined
51
+ readonly rest: Array<Attribute<Message> | ChildAttribute>
52
+ }
53
+
54
+ /** A Foldkit attribute of `_tag`. */
55
+ const tagged = <Message>(attribute: Attribute<Message> | ChildAttribute, tag: string): boolean => Predicate.hasProperty(attribute, "_tag") && attribute._tag === tag
56
+
57
+ /** A function in `w.Style`: a Live value on Foldkit is an Atom (#791, Q4). Development only. */
58
+ const functionInStyle = (key: string): string =>
59
+ `wardic: \`${key}\` in w.Style is a function. A Live value on Foldkit is an Atom (effect/reactivity): make one, and set it from a Command or a Live value helper.`
60
+
61
+ /** `w.Text` beside children: the Atom owns the element's text (#791, Q24). Development only. */
62
+ const TEXT_WITH_CHILDREN = "wardic: a w.* element with w.Text(atom) takes no children: the Atom owns its text. Drop the children, or the Text."
63
+
64
+ /** A key in both the user's `h.Style` and `w.Style`: two writers would own it (#791, Q7). Development only. */
65
+ const overlapping = (key: string): string =>
66
+ `wardic: \`${key}\` is in both h.Style and w.Style on one w.* element. Give a key to one of them: w.Style for what Wardic animates or holds, h.Style for the rest.`
67
+
68
+ /** `attributes`, folded (above). Per element per render. */
69
+ const fold = <Message>(attributes: Attributes<Message>): Folded<Message> => {
70
+ const folded: Folded<Message> = { config: {}, style: undefined, mount: undefined, provider: undefined, rest: [] }
71
+ const config: Record<string, unknown> = {}
72
+ Arr.forEach(attributes, (attribute) => {
73
+ if (Ward.isAttribute(attribute)) {
74
+ if (attribute[Ward.TypeId] === "provider") {
75
+ folded.provider = attribute.value as Ward.ProviderOptions
76
+ return
77
+ }
78
+ config[attribute[Ward.TypeId]] = attribute.value
79
+ return
80
+ }
81
+ if (tagged(attribute, "Style")) {
82
+ folded.style = (attribute as { readonly value: Record<string, string> }).value
83
+ return
84
+ }
85
+ if (tagged(attribute, "OnMount")) {
86
+ folded.mount = (attribute as unknown as { readonly action: MountAction<Message> }).action
87
+ return
88
+ }
89
+ folded.rest.push(attribute)
90
+ })
91
+ // A Reorder item is a layout element (#793, Q17): `true` unless `w.Layout("position")` is beside it.
92
+ if (Bool.and(Predicate.isNotUndefined(config.reorderItem), Predicate.isUndefined(config.layout))) config.layout = true
93
+ folded.config = config as Ward.Config<Message>
94
+ return folded
95
+ }
96
+
97
+ /** The element's config as delivered: its Wardic keys, its `style` the user's `h.Style` under `w.Style`'s base values. */
98
+ const configOf = (folded: Folded<never>): Config => {
99
+ const own = folded.config.style
100
+ if (DEV && Predicate.isNotUndefined(own)) {
101
+ const fn = Arr.findFirst(Rec.keys(own as Record<string, unknown>), (key) => Predicate.isFunction((own as Record<string, unknown>)[key]))
102
+ if (Option.isSome(fn)) throw new Error(functionInStyle(fn.value))
103
+ }
104
+ const user = folded.style
105
+ if (Predicate.isUndefined(user)) return folded.config as unknown as Config
106
+ if (Predicate.isUndefined(own)) return { ...folded.config, style: user } as unknown as Config
107
+ if (DEV) {
108
+ const both = Arr.findFirst(Rec.keys(user), (key) => Object.hasOwn(own, key))
109
+ if (Option.isSome(both)) throw new Error(overlapping(both.value))
110
+ }
111
+ return { ...folded.config, style: { ...user, ...(own as object) } } as unknown as Config
112
+ }
113
+
114
+ /**
115
+ * The attributes a `w.*` element renders for `folded`, after the user's own: its one `h.Style`, the
116
+ * Starting style's SVG attributes, its `wardic` property and its Mount.
117
+ */
118
+ const wardAttributes = <Message>(state: State, h: HtmlBuilder<Message>, tag: string | undefined, folded: Folded<Message>): ReadonlyArray<Attribute<Message> | ChildAttribute> => {
119
+ const config = configOf(folded as Folded<never>)
120
+ const starting = startingStyleOf(tag, config, registryOf(state))
121
+ return [
122
+ ...folded.rest,
123
+ h.Style(stringified(starting)),
124
+ propertyOf(h, config),
125
+ h.OnMount(mountOf(state, { provider: folded.provider, user: folded.mount, presence: Predicate.isNotUndefined(folded.config.presence), reorder: Predicate.isNotUndefined(folded.config.reorderGroup) })),
126
+ ]
127
+ }
128
+
129
+ /** Foldkit's element function, as `h.div` and a `h.keyed(tag)(key, …)` share it. */
130
+ type Make = (attributes: ReadonlyArray<Attribute<never> | ChildAttribute>, children?: ReadonlyArray<Ward.Child>) => Html
131
+
132
+ /** A `w.*` element: folded, rendered through Foldkit's `make`, and stamped. The Provider element walks its subtree once built (#794, Q7). */
133
+ const elementOf = <Message>(state: State, h: HtmlBuilder<Message>, tag: string, make: Make, attributes: Attributes<Message>, children: ReadonlyArray<Ward.Child> | undefined): Html => {
134
+ const folded = fold(attributes)
135
+ if (DEV && Predicate.isNotUndefined(folded.config.text) && Predicate.isNotUndefined(children) && children.length > 0) throw new Error(TEXT_WITH_CHILDREN)
136
+ // A `popLayout` presence rendering (#840): every live one's children measured now, before this render's patch moves a leaver.
137
+ if (!IS_SERVER && isPopLayout(folded.config.presence)) snapshotPopLayouts(state)
138
+ const node = brandViewResult<Html>(make(wardAttributes(state, h, tag, folded) as ReadonlyArray<Attribute<never> | ChildAttribute>, children), IDENTITY)
139
+ if (IS_SERVER && DEV) noteServerRender(state, Predicate.isNotUndefined(folded.provider))
140
+ // The Provider element's subtree exists by now, children before their parent: each Variant child's
141
+ // inherited Starting style goes into its node, for the server's HTML and the hydration render alike,
142
+ // and on a server each element's Appear animation, whose rules the Provider element renders (PR 2).
143
+ // Foldkit's node type isn't an export: the walk reads it by its shape, through `unknown`.
144
+ if (Bool.and(Predicate.isNotUndefined(folded.provider), Predicate.isNotNull(node))) {
145
+ const view = node as unknown as ViewNode
146
+ const css = walkProvider(view, state)
147
+ if (Str.isNonEmpty(css)) prependChunk(h, view, css, state.server.nonce)
148
+ }
149
+ return node
150
+ }
151
+
152
+ /**
153
+ * The chunk `<style>` with the render's Appear rules (ADR-0044 *Amendment (#245)*; #794, Q4), put first
154
+ * among the Provider element's children: Foldkit serialises a `<style>`'s text verbatim, and the
155
+ * client moves the chunk into the head before it hydrates (PR 3). With a `nonce`, it carries it.
156
+ */
157
+ const prependChunk = <Message>(h: HtmlBuilder<Message>, node: ViewNode, css: string, nonce: string | undefined): void => {
158
+ const attributes = [h.Attribute(Appear.CHUNK_ATTRIBUTE, ""), ...UndefinedOr.match(nonce, { onUndefined: () => [], onDefined: (value) => [h.Attribute("nonce", value)] })]
159
+ const chunk = h.style(attributes, [css]) as unknown as ViewNode
160
+ node.children = Arr.prepend(UndefinedOr.match(node.children, { onUndefined: (): ReadonlyArray<ViewNode | string> => [], onDefined: identity }), chunk)
161
+ }
162
+
163
+ /** Whether `key` names one of `h`'s element factories: a lowercase name, a function, and neither `keyed` nor `submodel`. */
164
+ const isTag = (h: object, key: string): boolean => {
165
+ if (key === "keyed") return false
166
+ if (key === "submodel") return false
167
+ if (!Str.isNonEmpty(key)) return false
168
+ if (key.charAt(0) !== key.charAt(0).toLowerCase()) return false
169
+ return Predicate.isFunction((h as Record<string, unknown>)[key])
170
+ }
171
+
172
+ /** The builder `w` for `h` (above). Its type is `Wardic.Html<Message, F>`. */
173
+ export const builderOf = <Message>(state: State, h: HtmlBuilder<Message>): object => {
174
+ const w: Record<string, unknown> = {}
175
+ const factories = h as unknown as Record<string, Make>
176
+ Arr.forEach(Arr.filter(Rec.keys(h), (key) => isTag(h, key)), (tag) => {
177
+ const make = factories[tag] as Make
178
+ w[tag] = (attributes: Attributes<Message>, children?: ReadonlyArray<Ward.Child>) => elementOf(state, h, tag, make, attributes, children)
179
+ })
180
+ w.keyed = (tag: string) => {
181
+ const keyed = (h.keyed as unknown as (tag: string) => (key: string, attributes: ReadonlyArray<Attribute<never> | ChildAttribute>, children?: ReadonlyArray<Ward.Child>) => Html)(tag)
182
+ // The key rides in the element's config (#792, Q4): what a presence pairs a re-entering child with its leaver by.
183
+ return (key: string, attributes: Attributes<Message>, children?: ReadonlyArray<Ward.Child>) => elementOf(state, h, tag, (attrs, kids) => keyed(key, attrs, kids), [...attributes, attribute("key", key)], children)
184
+ }
185
+ w.attributes = (bundle: Ward.Bundle<Message>) => {
186
+ const { mount, ...config } = bundle
187
+ const folded: Folded<Message> = { config, style: undefined, mount, provider: undefined, rest: [] }
188
+ return wardAttributes(state, h, undefined, folded)
189
+ }
190
+ w.Provider = (options: Ward.ProviderOptions = {}) => attribute("provider", options)
191
+ w.Initial = (value: Ward.Config["initial"]) => attribute("initial", value)
192
+ w.Animate = (value: Ward.Config["animate"]) => attribute("animate", value)
193
+ w.Transition = (value: Ward.Config["transition"]) => attribute("transition", value)
194
+ w.Style = (value: Ward.Config["style"]) => attribute("style", value)
195
+ w.Variants = (value: Ward.Config["variants"]) => attribute("variants", value)
196
+ w.Custom = (value: Ward.Config["custom"]) => attribute("custom", value)
197
+ w.Inherit = (value: Ward.Config["inherit"]) => attribute("inherit", value)
198
+ w.Appear = (value: Ward.Config["appear"]) => attribute("appear", value)
199
+ w.Config = (options: Ward.ConfigOptions) => attribute("config", options)
200
+ w.OnAnimationStart = (handler: Ward.Handler<Message, Ward.AnimationDefinition>) => attribute("animationStart", handler)
201
+ w.OnAnimationComplete = (handler: Ward.Handler<Message, Ward.AnimationDefinition>) => attribute("animationComplete", handler)
202
+ w.Text = (atom: Ward.Config["text"]) => attribute("text", atom)
203
+ w.OnUpdate = (atom: Ward.Config["onUpdate"]) => attribute("onUpdate", atom)
204
+ w.TransformTemplate = (template: Ward.Config["transformTemplate"]) => attribute("transformTemplate", template)
205
+ w.Exit = (value: Ward.Config["exit"]) => attribute("exit", value)
206
+ w.Presence = (options: Ward.PresenceOptions<Message> = {}) => attribute("presence", options)
207
+ w.Layout = (value: Ward.Config["layout"] = true) => attribute("layout", value)
208
+ w.LayoutId = (id: Ward.Config["layoutId"]) => attribute("layoutId", id)
209
+ w.LayoutDependency = (value: Ward.Config["layoutDependency"]) => attribute("layoutDependency", value)
210
+ w.LayoutScroll = (value: Ward.Config["layoutScroll"] = true) => attribute("layoutScroll", value)
211
+ w.LayoutRoot = (value: Ward.Config["layoutRoot"] = true) => attribute("layoutRoot", value)
212
+ w.LayoutCrossfade = (value: Ward.Config["layoutCrossfade"] = true) => attribute("layoutCrossfade", value)
213
+ w.LayoutGroup = (options: Ward.LayoutGroupOptions = {}) => attribute("layoutGroup", options)
214
+ w.OnLayoutAnimationStart = (handler: Ward.Handler<Message, void>) => attribute("layoutAnimationStart", handler)
215
+ w.OnLayoutAnimationComplete = (handler: Ward.Handler<Message, void>) => attribute("layoutAnimationComplete", handler)
216
+ w.OnBeforeLayoutMeasure = (fn: Ward.Config["onBeforeLayoutMeasure"]) => attribute("onBeforeLayoutMeasure", fn)
217
+ w.OnLayoutMeasure = (fn: Ward.Config["onLayoutMeasure"]) => attribute("onLayoutMeasure", fn)
218
+ // The gestures (#793, PR 1): each `While*` an entry in the Override stack, each callback a Message (decision 23).
219
+ w.WhileHover = (value: Ward.Config["whileHover"]) => attribute("whileHover", value)
220
+ w.OnHoverStart = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => attribute("onHoverStart", handler)
221
+ w.OnHoverEnd = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => attribute("onHoverEnd", handler)
222
+ w.WhileTap = (value: Ward.Config["whileTap"]) => attribute("whileTap", value)
223
+ w.Propagate = (options: Ward.Config["propagate"]) => attribute("propagate", options)
224
+ w.OnTapStart = (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => attribute("onTapStart", handler)
225
+ w.OnTap = (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => attribute("onTap", handler)
226
+ w.OnTapCancel = (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => attribute("onTapCancel", handler)
227
+ w.WhileFocus = (value: Ward.Config["whileFocus"]) => attribute("whileFocus", value)
228
+ w.WhileInView = (value: Ward.Config["whileInView"]) => attribute("whileInView", value)
229
+ w.Viewport = (options: Ward.ViewportOptions) => attribute("viewport", options)
230
+ w.OnViewportEnter = (handler: Ward.Handler<Message, IntersectionObserverEntry>) => attribute("onViewportEnter", handler)
231
+ w.OnViewportLeave = (handler: Ward.Handler<Message, IntersectionObserverEntry>) => attribute("onViewportLeave", handler)
232
+ // The drag (#793, PR 2; ADR-0004): its options read as its track starts, its callbacks Messages.
233
+ w.Drag = (value: Ward.Config["drag"] = true) => attribute("drag", value)
234
+ w.WhileDrag = (value: Ward.Config["whileDrag"]) => attribute("whileDrag", value)
235
+ w.DragConstraints = (value: Ward.DragConstraints) => attribute("dragConstraints", value)
236
+ w.DragElastic = (value: Ward.Config["dragElastic"]) => attribute("dragElastic", value)
237
+ w.DragMomentum = (value: Ward.Config["dragMomentum"]) => attribute("dragMomentum", value)
238
+ w.DragSnapToOrigin = (value: Ward.Config["dragSnapToOrigin"] = true) => attribute("dragSnapToOrigin", value)
239
+ w.DragTransition = (value: Ward.Config["dragTransition"]) => attribute("dragTransition", value)
240
+ w.DragPropagation = (value: Ward.Config["dragPropagation"] = true) => attribute("dragPropagation", value)
241
+ w.DragDirectionLock = (value: Ward.Config["dragDirectionLock"] = true) => attribute("dragDirectionLock", value)
242
+ w.DragListener = (value: Ward.Config["dragListener"]) => attribute("dragListener", value)
243
+ w.DragControls = (controls: Ward.DragControls) => attribute("dragControls", controls)
244
+ w.StartsDrag = (controls: Ward.DragControls, options?: Ward.StartOptions) => attribute("startsDrag", { controls, options } satisfies Ward.StartsDrag)
245
+ // The Animation scope (#798, Q7): the element a Command's selectors resolve under.
246
+ w.AnimationScope = (scope: AnimationScope) => attribute("animationScope", scope)
247
+ w.OnMeasureDragConstraints = (fn: Ward.Config["onMeasureDragConstraints"]) => attribute("onMeasureDragConstraints", fn)
248
+ w.OnDragStart = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onDragStart", handler)
249
+ w.OnDrag = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onDrag", handler)
250
+ w.OnDragEnd = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onDragEnd", handler)
251
+ w.OnDragTransitionEnd = (handler: Ward.Handler<Message, void>) => attribute("onDragTransitionEnd", handler)
252
+ w.OnDirectionLock = (handler: Ward.Handler<Message, "x" | "y">) => attribute("onDirectionLock", handler)
253
+ // The pan (Q9): each callback a Message.
254
+ w.OnPanSessionStart = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => attribute("onPanSessionStart", handler)
255
+ w.OnPanStart = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onPanStart", handler)
256
+ w.OnPan = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onPan", handler)
257
+ w.OnPanEnd = (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => attribute("onPanEnd", handler)
258
+ // Reorder (#793, PR 3; decision 28): the group's options, and each item's value.
259
+ w.ReorderGroup = (options: Ward.ReorderGroupOptions<Message, unknown>) => attribute("reorderGroup", options)
260
+ w.ReorderItem = (value: unknown) => attribute("reorderItem", { value } satisfies Ward.ReorderItem)
261
+ return w
262
+ }
@@ -0,0 +1,359 @@
1
+ /**
2
+ * How Commands get Wardic's services (ADR-0071, decisions 9, 26 and 31; *Amendment (#791)*, PR 3): the
3
+ * seam that differs on Foldkit's preview. On 0.170, the `Wardic` service is the **Handle**, which
4
+ * `wardic.resources` gives a program's Commands, and the two Effects over it: `animate`, an
5
+ * **Imperative animation** of an element or a **Sequence**, under an **Animation scope** when given
6
+ * (#798), and `provide`, which runs an Effect on the Provider's services. Either builds the Provider when none is live, and counts itself in as a member while it
7
+ * runs, so the Provider doesn't close under it.
8
+ *
9
+ * @module
10
+ */
11
+ import * as LiveValue from "@wardic/core/LiveValue"
12
+ import * as ScrollSource from "@wardic/core/ScrollSource"
13
+ import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue"
14
+ import type * as ProjectionSystem from "@wardic/dom/ProjectionSystem"
15
+ import * as Imperative from "@wardic/dom/unstable/Imperative"
16
+ import * as DomPointer from "@wardic/dom/unstable/PointerValues"
17
+ import * as Arr from "effect/Array"
18
+ import * as Bool from "effect/Boolean"
19
+ import * as Context from "effect/Context"
20
+ import * as Data from "effect/Data"
21
+ import * as Effect from "effect/Effect"
22
+ import { constVoid } from "effect/Function"
23
+ import * as Layer from "effect/Layer"
24
+ import * as MutableRef from "effect/MutableRef"
25
+ import * as Option from "effect/Option"
26
+ import * as Predicate from "effect/Predicate"
27
+ import type * as Scope from "effect/Scope"
28
+ import * as UndefinedOr from "effect/UndefinedOr"
29
+ import * as Render from "foldkit/render"
30
+ import type * as Feature from "@wardic/dom/unstable/Feature"
31
+ import type * as WardConfig from "@wardic/dom/unstable/WardConfig"
32
+ import { hintFrameUnless } from "./delivery.ts"
33
+ import { type Layout, layoutOf } from "./layout.ts"
34
+ import { type AnimationScope, watchOf } from "./scope.ts"
35
+ import { featureIn, joined, providerFor, type Provider, reducedMotionUnder, type State, stateOf } from "./services.ts"
36
+
37
+ /** The mark of a Handle, as the `Wardic` service carries it: what its Effects reach the Handle's state through. */
38
+ export const HANDLE: unique symbol = Symbol.for("@wardic/foldkit/Handle")
39
+
40
+ /** A Handle as the `Wardic` service holds it: a mark, so a Command's Effect types no builder. */
41
+ export interface HandleRef {
42
+ readonly [HANDLE]: true
43
+ }
44
+
45
+ /** The Wardic service: a program's **Handle**, which `wardic.resources` gives its Commands. */
46
+ export class Wardic extends Context.Service<Wardic, HandleRef>()("@wardic/foldkit/Wardic") {}
47
+
48
+ /** The Layer a program's `resources` takes, giving its Commands the Handle (decision 9): read when built, so the Handle can hold it. */
49
+ export const resourcesOf = (handle: () => HandleRef): Layer.Layer<Wardic> => Layer.sync(Wardic)(handle)
50
+
51
+ /** What `animate` ends with: whether every key landed, or a later animation took its keys (#791, Q21). */
52
+ export interface AnimationEnd {
53
+ readonly landed: boolean
54
+ }
55
+
56
+ /** `animate` found nothing to animate: a selector matching no element under the root, or an empty list. */
57
+ export class AnimationFailed extends Data.TaggedError("AnimationFailed")<{
58
+ readonly subject: string
59
+ }> {}
60
+
61
+ /** `animateLayout` found no layout to animate: the Handle has no `layout` Feature (`Features.layout`). */
62
+ export class LayoutFailed extends Data.TaggedError("LayoutFailed")<{
63
+ readonly reason: "no-layout-feature"
64
+ }> {}
65
+
66
+ /** What a Command's Effect is a member of: the Handle's Provider, built when none is live, and the count out. */
67
+ const member: () => Effect.Effect<Member, never, Wardic> = Effect.fnUntraced(function* () {
68
+ const handle = yield* Wardic
69
+ const state = stateOf(handle)
70
+ const provider = yield* providerFor(state, undefined, undefined)
71
+ // A member while it runs: the Provider stays up until it ends.
72
+ return { state, provider, left: joined(state, provider, undefined) }
73
+ })
74
+
75
+ /** What `animateLayout` takes: dom's options, less `onSettled`, which the Effect's success is. */
76
+ export type AnimateLayoutOptions = Omit<ProjectionSystem.AnimateLayoutOptions, "onSettled">
77
+
78
+ /** No options: a change animated from the last pass's boxes. */
79
+ const FROM_LAST_PASS: AnimateLayoutOptions = { from: "lastPass" }
80
+
81
+ /**
82
+ * A **Declared layout change** (ADR-0071, decision 26; ADR-0038; Motion's `animateLayout`): what a
83
+ * Command runs after the Model change that moved the layout elements, under either trigger, and the
84
+ * only trigger beside `w.LayoutDependency` under `layoutTrigger: "declared"`. It waits for the
85
+ * render's commit (Foldkit's `Render.afterCommit`), then asks for a Measure pass from the boxes the
86
+ * last pass kept (`from: "lastPass"`, the default: the change is on the page by then), and succeeds
87
+ * once every layout animation the pass started has ended, at once if none. Fails with
88
+ * {@link LayoutFailed} when the Handle has no `layout` Feature. Wrap it in `Command.define`, with
89
+ * `resources: wardic.resources` on the program.
90
+ */
91
+ export const animateLayout: (options?: AnimateLayoutOptions) => Effect.Effect<void, LayoutFailed, Wardic> = Effect.fnUntraced(function* (options) {
92
+ const { state, provider, left } = yield* member()
93
+ const layout = layoutOf(provider, state)
94
+ if (Predicate.isUndefined(layout)) {
95
+ left()
96
+ return yield* Effect.fail(new LayoutFailed({ reason: "no-layout-feature" }))
97
+ }
98
+ yield* Render.afterCommit
99
+ return yield* settling(state, provider, layout, left, { ...FROM_LAST_PASS, ...options })
100
+ })
101
+
102
+ /** The change's pass, and its settling as the Effect's success; its interruption leaves the member. */
103
+ const settling = (state: State, provider: Provider, layout: Layout, left: () => void, options: AnimateLayoutOptions): Effect.Effect<void> =>
104
+ Effect.callback<void>((resume) => {
105
+ const run = (): void => {
106
+ layout.projection.animateLayout(constVoid, {
107
+ ...options,
108
+ onSettled: () => {
109
+ left()
110
+ resume(Effect.void)
111
+ },
112
+ })
113
+ }
114
+ // A View Transition's render (decision 33): the change lands as an Instant change of the layout, settled at once.
115
+ if (state.transitioning) {
116
+ state.transitioning = false
117
+ layout.projection.instant(run)
118
+ return Effect.sync(left)
119
+ }
120
+ // The pass's first step paints in this frame (decision 32): the Command resumed inside it, after the commit.
121
+ hintFrameUnless(provider.loop, provider.paused)
122
+ run()
123
+ return Effect.sync(left)
124
+ })
125
+
126
+ /** How many elements `subject` names, under `root`: a selector's matches, an element, or a list's members. */
127
+ const countOf = (subject: Imperative.WardicAnimationSubject, root: Element | undefined): number => {
128
+ if (Predicate.isNullish(subject)) return 0
129
+ if (Predicate.isString(subject)) return UndefinedOr.match(root, { onUndefined: () => document, onDefined: (el): ParentNode => el }).querySelectorAll(subject).length
130
+ if (Predicate.hasProperty(subject, "nodeType")) return 1
131
+ if (Predicate.isIterable(subject)) return Arr.fromIterable(subject).length
132
+ return (subject as ArrayLike<Element>).length
133
+ }
134
+
135
+ /** `subject` as an error names it. */
136
+ const nameOf = (subject: Imperative.WardicAnimationSubject): string => {
137
+ if (Predicate.isString(subject)) return subject
138
+ if (Predicate.isNullish(subject)) return String(subject)
139
+ return "an element list"
140
+ }
141
+
142
+ /**
143
+ * What a Command's animations run on: the Provider's services, as a Solid animation scope's, under the
144
+ * Handle's `config` (decision 22): its `reducedMotion` and `skipAnimations`, read as each animation starts.
145
+ */
146
+ const envOf = (state: State, provider: Provider): Imperative.AnimateEnv => ({
147
+ runtime: provider.runtime,
148
+ gate: provider.gate,
149
+ reducedMotion: reducedMotionUnder(provider, state.rootConfig),
150
+ skipAnimations: WardicConfigValue.skipAnimationsOf(state.rootConfig),
151
+ positionalKeys: provider.positionalKeys,
152
+ defaultTransition: provider.defaultTransition,
153
+ ownValues: provider.valueReads.ownValues,
154
+ measuredPairs: provider.valueReads.measuredPairs,
155
+ variableValues: provider.valueReads.variableValues,
156
+ })
157
+
158
+ /** What a Command's animation options carry on Foldkit: the scope the binding's, `onComplete` the Effect's success, so neither reaches dom. */
159
+ // #798, Q8: the scope an option on both forms. `onComplete?: never`, as before: the Effect succeeds in its place.
160
+ interface Scoped {
161
+ readonly onComplete?: never
162
+ readonly scope?: AnimationScope | undefined
163
+ }
164
+
165
+ /** What `animate` takes with a subject: dom's options, less `onComplete`, which the Effect's success is, and the **Animation scope** its selectors resolve under. */
166
+ // An intersection, not an `Omit`: dom's options are a union of transitions, which `Omit` spreads past
167
+ // what TypeScript represents (TS2590).
168
+ export type AnimateOptions = Imperative.WardicAnimateOptions & Scoped
169
+
170
+ /** A sequence (Motion's `animate(sequence)`): Segments of elements, function Segments and labels, laid out in time. No Batch Segment: Foldkit has no Batch. */
171
+ // #798, Q6. dom's sequence less its Batch Segment, which the type says as the doc does.
172
+ export type Sequence = ReadonlyArray<Exclude<Imperative.WardicSegment, Imperative.WardicBatchSegment>>
173
+
174
+ /** What `animate` takes with a sequence: dom's options, less `onComplete`, which the Effect's success is, and the scope. */
175
+ export type SequenceOptions = Imperative.WardicSequenceOptions & Scoped
176
+
177
+ /** `AnimationFailed`'s subject for a sequence none of whose Segments found anything (#798, Q15). */
178
+ const SEQUENCE = "a sequence"
179
+
180
+ /** The scope `options` name, or none. */
181
+ const scopeIn = (options: Scoped | undefined): AnimationScope | undefined => UndefinedOr.map(options, (given) => given.scope)
182
+
183
+ /** `options` as dom takes them: the scope, the binding's own, left out. Typed loosely, since dom's option types are unions `Omit` spreads past what TypeScript represents. */
184
+ const withoutScope = (options: Scoped): Readonly<Record<string, unknown>> => {
185
+ const { scope: _scope, ...rest } = options as Scoped & Readonly<Record<string, unknown>>
186
+ return rest
187
+ }
188
+
189
+ /**
190
+ * Where a Command's selectors resolve (#798, Q8): under the scope's element; with no scope, under the
191
+ * `w.Provider()` element, else the document (`undefined`); none for a scope whose element isn't
192
+ * mounted, which finds nothing before any element is looked at.
193
+ */
194
+ const insideOf = (provider: Provider, scope: AnimationScope | undefined): Option.Option<Element | undefined> =>
195
+ UndefinedOr.match(scope, { onUndefined: () => Option.some(provider.root), onDefined: (given) => Option.fromUndefinedOr(given.element()) })
196
+
197
+ /** What a Command's Effect is a member of: the Handle's state and Provider, and the count out. */
198
+ interface Member {
199
+ readonly state: State
200
+ readonly provider: Provider
201
+ readonly left: () => void
202
+ }
203
+
204
+ /**
205
+ * `animate`'s two forms (Motion's `animate`, as `useAnimate` gives it): a subject to values, or a
206
+ * sequence. Each an Effect for a Command, succeeding once the animation ends with whether it landed,
207
+ * failing with {@link AnimationFailed} when nothing finds anything to animate, and stopped by its
208
+ * fiber's interruption.
209
+ */
210
+ // #798, Q6: one interface, the form told by dom's `isSequence`.
211
+ export interface Animate {
212
+ // ADR-0071, decision 26; #791 Q21; #798 Q8 for the scope.
213
+ /**
214
+ * An **Imperative animation** of `subject`: an element, a selector resolved under `options.scope`'s
215
+ * element, else the `w.Provider()` element, else the document, or a list of elements, to `values` on
216
+ * `options`' transition. A Wardic element animates through its own spine, latest wins, as Motion's; a
217
+ * plain element through a spine of its own. Fails when the subject finds nothing, a scope not mounted
218
+ * included. Wrap it in `Command.define`, with `resources: wardic.resources` on the program.
219
+ */
220
+ (subject: Imperative.WardicAnimationSubject, values: WardConfig.WardicVariant, options?: AnimateOptions): Effect.Effect<AnimationEnd, AnimationFailed, Wardic>
221
+ // #798, Q6 and Q15. Motion's `animate(sequence)`.
222
+ /**
223
+ * A **Sequence**: its Segments laid out in time, labels and `at` among them, played as one animation
224
+ * under `options`. Fails when the whole sequence animates nothing: every Segment of elements found
225
+ * none and no function Segment is in it; a Segment that finds nothing beside ones that do is skipped.
226
+ */
227
+ (sequence: Sequence, options?: SequenceOptions): Effect.Effect<AnimationEnd, AnimationFailed, Wardic>
228
+ }
229
+
230
+ /** `animate` (above): the form told by what it's given, as dom's own `animate` tells it. */
231
+ export const animate: Animate = ((first: Imperative.WardicAnimationSubject | Sequence, second?: WardConfig.WardicVariant | SequenceOptions, third?: AnimateOptions) => {
232
+ if (Imperative.isSequence(first)) {
233
+ const options = second as SequenceOptions | undefined
234
+ return commanded(scopeIn(options), (under) => Arr.some(first, (segment) => Imperative.segmentAnimates(segment, under)), SEQUENCE, (run) =>
235
+ (run as unknown as RunSequence)(first, UndefinedOr.map(options, withoutScope) as Imperative.WardicSequenceOptions | undefined))
236
+ }
237
+ return commanded(scopeIn(third), (under) => countOf(first, under) > 0, nameOf(first), (run) =>
238
+ (run as unknown as RunSubject)(first, second as WardConfig.WardicVariant, UndefinedOr.map(third, withoutScope) as Imperative.WardicAnimateOptions | undefined))
239
+ }) as Animate
240
+
241
+ /**
242
+ * A Command's animation of either form: a member of the Handle's Provider while it runs (a member
243
+ * from before anything is looked at, so a Provider built for one that finds nothing is left again at
244
+ * once), its selectors' root under `scope`, `finds` asked of that root, nothing found failing as
245
+ * `named`, and `start` run on dom's scoped `animate`.
246
+ */
247
+ const commanded: (
248
+ scope: AnimationScope | undefined,
249
+ finds: (under: Element | undefined) => boolean,
250
+ named: string,
251
+ start: (run: Imperative.WardicAnimate) => Imperative.WardicPlaybackControls,
252
+ ) => Effect.Effect<AnimationEnd, AnimationFailed, Wardic> = Effect.fnUntraced(function* (scope, finds, named, start) {
253
+ const held = yield* member()
254
+ const inside = insideOf(held.provider, scope)
255
+ if (Option.isNone(inside)) {
256
+ held.left()
257
+ return yield* Effect.fail(new AnimationFailed({ subject: named }))
258
+ }
259
+ if (Bool.not(finds(inside.value))) {
260
+ held.left()
261
+ return yield* Effect.fail(new AnimationFailed({ subject: named }))
262
+ }
263
+ return yield* running(held, inside.value, scope, start)
264
+ })
265
+
266
+ /** dom's `animate` in its subject form, named plainly: its overloads' union is more than TypeScript represents at a call. */
267
+ type RunSubject = (subject: Imperative.WardicAnimationSubject, target: WardConfig.WardicVariant, options?: Imperative.WardicAnimateOptions) => Imperative.WardicPlaybackControls
268
+
269
+ /** dom's `animate` in its sequence form, named plainly. */
270
+ type RunSequence = (sequence: Sequence, options?: Imperative.WardicSequenceOptions) => Imperative.WardicPlaybackControls
271
+
272
+ /**
273
+ * The animation `start` runs on dom's scoped `animate`, until it ends: its end as the Effect's success,
274
+ * its interruption as its stop. With a `scope`, the scope's watch is told each start and end too
275
+ * (Q7): what its element's release stops, each then ending with `landed: false` (Q19).
276
+ */
277
+ const running = (held: Member, under: Element | undefined, scope: AnimationScope | undefined, start: (run: Imperative.WardicAnimate) => Imperative.WardicPlaybackControls): Effect.Effect<AnimationEnd> =>
278
+ Effect.callback<AnimationEnd>((resume) => {
279
+ const controls = MutableRef.make(Option.none<Imperative.WardicPlaybackControls>())
280
+ const watch = Imperative.alsoTold(
281
+ {
282
+ started: (made) => {
283
+ MutableRef.set(controls, Option.some(made))
284
+ },
285
+ ended: (_made, landed) => {
286
+ held.left()
287
+ resume(Effect.succeed({ landed }))
288
+ },
289
+ },
290
+ UndefinedOr.map(scope, watchOf),
291
+ )
292
+ start(Imperative.scopedAnimate(envOf(held.state, held.provider), () => under, watch))
293
+ return Effect.sync(() => {
294
+ Option.map(MutableRef.get(controls), (made) => made.stop())
295
+ held.left()
296
+ })
297
+ })
298
+
299
+ /**
300
+ * `effect` run on the Provider's services (ADR-0071, the grill's Q23): how a Command makes a derived
301
+ * Live value (`LiveValue.spring`, `follow`, `velocity`, `scroll`). The Scope is the caller's: a
302
+ * `ManagedResource`'s `acquire`, whose Scope Foldkit closes when its Model condition drops, or an
303
+ * `Effect.scoped` that ends with the Command. The Provider is held while that Scope lives.
304
+ */
305
+ export const provide: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Feature.ProviderServices> | Wardic | Scope.Scope> = Effect.fnUntraced(
306
+ function* <A, E, R>(effect: Effect.Effect<A, E, R>) {
307
+ const { provider, left } = yield* member()
308
+ yield* Effect.addFinalizer(() => Effect.sync(left))
309
+ return yield* Effect.provideContext(effect, provider.context)
310
+ },
311
+ )
312
+
313
+ /** `scroll` found no scroll to read: the Handle wasn't given `Features.scroll`, or a load of it hasn't arrived. */
314
+ export class ScrollFailed extends Data.TaggedError("ScrollFailed")<{
315
+ readonly reason: "no-scroll-feature"
316
+ }> {}
317
+
318
+ /** What `scroll` takes: Motion's `useScroll` options, the `container` and `target` as elements. */
319
+ export type ScrollOptions = ScrollSource.Options
320
+
321
+ /**
322
+ * A container's scroll as **Live values** (Motion's `useScroll`): how far it's scrolled on each axis,
323
+ * and the progress through its range, or through the offsets a `target` passes, each an Atom a view
324
+ * binds, set within the scroll's own event. Its listeners are held while the caller's Scope lives, as
325
+ * a Live value made under `provide` is. Fails with {@link ScrollFailed} when the Handle has no `scroll`
326
+ * Feature: name it, `Wardic.make({ env, features: [Features.scroll] })`.
327
+ */
328
+ // #795 (the storefront's part 2): core's `LiveValue.scroll` on the `scroll` Feature's `ScrollSource`, which
329
+ // Solid's `createScroll` brings by itself and a Foldkit Handle names; typed as `animateLayout` is without
330
+ // its Feature (decision 13), not Effect's own missing-service defect.
331
+ export const scroll: (options?: ScrollOptions) => Effect.Effect<LiveValue.ScrollValues, ScrollFailed, Wardic | Scope.Scope> = Effect.fnUntraced(function* (options?: ScrollOptions) {
332
+ const { provider, left } = yield* member()
333
+ const source = featureIn(provider, ScrollSource.ScrollSource)
334
+ if (Predicate.isUndefined(source)) {
335
+ left()
336
+ return yield* Effect.fail(new ScrollFailed({ reason: "no-scroll-feature" }))
337
+ }
338
+ yield* Effect.addFinalizer(() => Effect.sync(left))
339
+ return yield* Effect.provideContext(LiveValue.scroll(options), Context.add(provider.context, ScrollSource.ScrollSource, source))
340
+ })
341
+
342
+ /** What `pointer` takes: the pointer types that count, a mouse and a pen unless given. */
343
+ export type PointerOptions = DomPointer.Options
344
+
345
+ /** What `pointer` gives: the pointer's place in the element's pixels, its progress across the element's box, the box's size, and whether it's inside, each an Atom. */
346
+ export type PointerValues = DomPointer.PointerValues
347
+
348
+ /**
349
+ * The pointer over an element as **Live values**: where it is in the element's pixels, from the box's
350
+ * top left; its progress across the box, from 0 to 1 each way; the box's size; and whether it's
351
+ * inside, each an Atom a view binds, set within the pointer's own events (`pointerenter`,
352
+ * `pointermove`, `pointerdown`, `pointerleave`). A leave keeps the place: what returns to rest with
353
+ * it is a derived Atom over `inside`. Its listeners are held while the caller's Scope lives, as a
354
+ * Live value made under `provide` is. A mouse and a pen count unless `types` says; a finger never
355
+ * hovers. Plain pointer events, not the hover gesture: no Feature to name, nothing to fail.
356
+ */
357
+ // #833 (found as #795's storefront was reviewed): dom's `PointerValues` under `provide`, where the spotlight
358
+ // and the magnifier each listened and did the arithmetic themselves.
359
+ export const pointer = (element: Element, options?: PointerOptions): Effect.Effect<PointerValues, never, Wardic | Scope.Scope> => provide(DomPointer.pointer(element, options))