@wardic/foldkit 0.0.0-stage → 1.2.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 +100 -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 +222 -0
  105. package/dist/internal/services.d.ts.map +1 -0
  106. package/dist/internal/services.js +338 -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 +124 -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 +486 -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
package/src/Wardic.ts ADDED
@@ -0,0 +1,410 @@
1
+ /**
2
+ * Wardic for Foldkit (ADR-0071, #561): a **Handle** made once per program with {@link make}, whose
3
+ * `html(h)` gives a view the builder `w`. A `w.*` element takes Foldkit's attributes and Wardic's
4
+ * (`w.Initial`, `w.Animate`, `w.Transition`, `w.Style`), animates its `Animate` target from `Initial`
5
+ * as it mounts, Retargets on a render that changes its target and holds through one that doesn't. The
6
+ * first `w.*` element to mount builds Wardic's services on the Handle's `env`, which every element
7
+ * shares until the last has left; `w.Provider(options)` on the `w.*` element at the top names the root
8
+ * the subtree options hang on.
9
+ *
10
+ * @example
11
+ * // src/lib/wardic.ts
12
+ * import { DomLive } from "@wardic/dom"
13
+ * import * as Wardic from "@wardic/foldkit/Wardic"
14
+ *
15
+ * export const wardic = Wardic.make({ env: DomLive })
16
+ *
17
+ * // src/view.ts
18
+ * const view = (model: Model, h: HtmlBuilder<Message>): Html => {
19
+ * const w = wardic.html(h)
20
+ * return w.div([h.Class("app")], [
21
+ * w.div([h.Class("card"), w.Initial({ opacity: 0, y: 8 }), w.Animate({ opacity: 1, y: 0 }), w.Transition({ duration: 0.3 })], [model.title]),
22
+ * ])
23
+ * }
24
+ *
25
+ * @module
26
+ */
27
+ import * as Arc from "@wardic/core/Arc"
28
+ import * as Stagger from "@wardic/core/Stagger"
29
+ import type * as WardicServices from "@wardic/core/unstable/WardicServices"
30
+ import type * as Feature from "@wardic/dom/unstable/Feature"
31
+ import type * as WardConfig from "@wardic/dom/unstable/WardConfig"
32
+ import type * as Layer from "effect/Layer"
33
+ import type * as FoldkitHtml from "foldkit/html"
34
+ import type { MountAction } from "foldkit/mount"
35
+ import type * as FoldkitRuntime from "foldkit/runtime"
36
+ import * as Predicate from "effect/Predicate"
37
+ import type * as AnimationScope from "./AnimationScope.ts"
38
+ import type * as Ward from "./Ward.ts"
39
+ import { type Attributes, builderOf } from "./internal/builder.ts"
40
+ import { HANDLE, resourcesOf, type Wardic as WardicTag } from "./internal/commands.ts"
41
+ import { hydrateOf } from "./internal/hydrate.ts"
42
+ import { mountOf } from "./internal/mount.ts"
43
+ import { makeState, remember, type State } from "./internal/services.ts"
44
+ import { viewTransitionOf } from "./internal/view-transition.ts"
45
+
46
+ export { animate, animateLayout, type AnimateLayoutOptions, type AnimateOptions, AnimationFailed, type AnimationEnd, LayoutFailed, pointer, type PointerOptions, type PointerValues, provide, scroll, ScrollFailed, type ScrollOptions, type Sequence, type SequenceOptions, Wardic } from "./internal/commands.ts"
47
+
48
+ /** What {@link make} takes. */
49
+ export interface MakeOptions<F> {
50
+ /** Wardic's Environment: `@wardic/dom`'s `DomLive` in a browser. Required, as a Solid provider's `env` is (#791, Q1). */
51
+ readonly env: WardicServices.WardicEnv
52
+ /**
53
+ * The **Features** its elements have (#511, ADR-0067 *Amendment (#516)*): given at once, or loads
54
+ * (`() => import(…)`), as Solid's `createWardic` takes them. Without any, the base props alone: a
55
+ * gesture or layout attribute is then a type error naming its Feature (from slice 3 on).
56
+ */
57
+ readonly features?: F | undefined
58
+ /** The app-wide settings (ADR-0062; ADR-0071 decision 22): what `w.Config(…)` takes, under every subtree's. */
59
+ readonly config?: Ward.ConfigOptions | undefined
60
+ /**
61
+ * What runs a Measure pass (decision 30; #792, Q10 and Q17): `"patch"` (the default), a pass after
62
+ * every patch that changed the DOM, found by a `MutationObserver` on the `w.Provider()` element, else
63
+ * the document's body; `"declared"`, only a `w.LayoutDependency` change and `Wardic.animateLayout`.
64
+ */
65
+ readonly layoutTrigger?: "patch" | "declared" | undefined
66
+ /** Attributes the observer watches beside `class` and `hidden` (decision 30): those the app's CSS lays out by. */
67
+ readonly layoutAttributes?: ReadonlyArray<string> | undefined
68
+ // ADR-0044; #794, Q3; "explain": #585. Solid's `<WardicProvider appear>`.
69
+ /**
70
+ * **Appear animations** on a server: on by default, under `w.Provider()`, whose element renders their
71
+ * rules; `false` renders none; `"explain"` says, at Warning, why each element that doesn't play waits
72
+ * for the JavaScript.
73
+ */
74
+ readonly appear?: boolean | "explain" | undefined
75
+ // #618; #794, Q13. Solid's `<WardicProvider nonce>`.
76
+ /** The nonce the page's Content Security Policy gives inline styles: the rules' `<style>` carries it. */
77
+ readonly nonce?: string | undefined
78
+ }
79
+
80
+ /** A `w.*` element's function: `h.div`'s shape, taking Wardic's attributes too. */
81
+ export type ElementFunction<Message> = (attributes: Attributes<Message>, children?: ReadonlyArray<Ward.Child>) => FoldkitHtml.Html
82
+
83
+ /** The phantom that carries a Handle's Features on its builder. */
84
+ declare const FEATURES: unique symbol
85
+
86
+ /**
87
+ * A Feature's attribute factory on a builder whose Handle has Features `F` (ADR-0071 *Amendment
88
+ * (#516)*; #793, Q11): the factory when `F` names the Feature `N`; else what names the missing one, so
89
+ * calling it is a type error reading `NeedsFeature<"hover">`.
90
+ */
91
+ type Needs<F, N extends Feature.PropFeature, Factory> = N extends Feature.PropFeatureNames<F> ? Factory : Feature.NeedsFeature<N>
92
+
93
+ /**
94
+ * The builder `w` of `wardic.html(h)`: `h`'s element factories, each taking Wardic's attributes beside
95
+ * Foldkit's; `keyed`; the `attributes` bundle, for an element `w` doesn't make (a custom element, a
96
+ * component library's); and Wardic's attribute factories. Foldkit's own attributes stay on `h`.
97
+ */
98
+ export type Html<Message, F = never> = { readonly [Tag in FoldkitHtml.TagName]: ElementFunction<Message> } & Readonly<{
99
+ readonly [FEATURES]?: F
100
+ /** `w.keyed(tag)(key, attributes, children)`: a keyed `w.*` element, as `h.keyed`'s. */
101
+ keyed: (tag: FoldkitHtml.TagName) => (key: string, attributes: Attributes<Message>, children?: ReadonlyArray<Ward.Child>) => FoldkitHtml.Html
102
+ /**
103
+ * The **Bundle** (ADR-0071, decision 18): a Ward's attributes for any element, `h.div([...w.attributes({ … })])`.
104
+ * It takes the element's own Mount and fuses it with Wardic's, since one element has one `OnMount`.
105
+ * An element it's on isn't stamped, so key such an element (P2).
106
+ */
107
+ attributes: (bundle: Ward.Bundle<Message>) => ReadonlyArray<FoldkitHtml.Attribute<Message> | FoldkitHtml.ChildAttribute>
108
+ /**
109
+ * The **Provider attribute** (decision 9, *Amendment (#791)*): on the `w.*` element at the top of the
110
+ * view, when the subtree options (slice 2's) are wanted: that element is the root they hang on. With
111
+ * none, the first `w.*` element to mount builds Wardic's services, shared until the last has left.
112
+ */
113
+ Provider: (options?: Ward.ProviderOptions) => Ward.Attribute
114
+ /**
115
+ * Where the element starts: values, or `false` to start at `Animate` (Motion's `initial`). Read once,
116
+ * at mount, as Motion reads it: give the same `Initial` on every render, since a view renders it as
117
+ * the element's Starting style, and a changed one would be written over what Wardic draws.
118
+ */
119
+ Initial: (value: Ward.Config["initial"]) => Ward.Attribute
120
+ /** Where the element animates to (Motion's `animate`): a change Retargets it from wherever it is. */
121
+ Animate: (value: Ward.Config["animate"]) => Ward.Attribute
122
+ /** How it gets there (Motion's `transition`). */
123
+ Transition: (value: Ward.Config["transition"]) => Ward.Attribute
124
+ /**
125
+ * The element's `style` as Wardic sees it (Motion's `style`): its base values, where a key returns
126
+ * when nothing animates it. A key in both `w.Style` and `h.Style` is an error in development.
127
+ */
128
+ Style: (value: Ward.Config["style"]) => Ward.Attribute
129
+ /**
130
+ * Named targets `Initial`, `Animate` and the rest can name (Motion's `variants`). A child with
131
+ * `Variants` and no `Animate` of its own follows the name its nearest Wardic ancestor hands down,
132
+ * staggered by that ancestor's `Transition`.
133
+ */
134
+ Variants: (value: Ward.Config["variants"]) => Ward.Attribute
135
+ /** What the element's dynamic variants resolve with (Motion's `custom`). */
136
+ Custom: (value: Ward.Config["custom"]) => Ward.Attribute
137
+ /** `false` keeps the element out of its ancestor's variants (Motion's `inherit`). */
138
+ Inherit: (value: Ward.Config["inherit"]) => Ward.Attribute
139
+ // ADR-0044; #794, Q3: dom's `appear` key, Motion's `appear` prop.
140
+ /** `false` keeps the element's mount animation off a server render's **Appear animations**: it starts when the script runs. */
141
+ Appear: (value: Ward.Config["appear"]) => Ward.Attribute
142
+ /** The subtree's settings (Motion's `MotionConfig`), this element's included, over the nearest ancestor's and the Handle's. */
143
+ Config: (options: Ward.ConfigOptions) => Ward.Attribute
144
+ // #433; #798, Q7 and Q19. Motion's `useAnimate` scope, as the element's attribute.
145
+ /**
146
+ * The **Animation scope** this element is (`AnimationScope.make()`'s): a Command's `Wardic.animate(…, {
147
+ * scope })` looks its selectors up inside it, and the element's release stops the animations started
148
+ * in the scope where they are.
149
+ */
150
+ AnimationScope: (scope: AnimationScope.AnimationScope) => Ward.Attribute
151
+ /** Sent as an animation of the element starts, with what it animates to (Motion's `onAnimationStart`). */
152
+ OnAnimationStart: (handler: Ward.Handler<Message, Ward.AnimationDefinition>) => Ward.Attribute
153
+ /** Sent as that animation lands (Motion's `onAnimationComplete`); not for one a new target interrupted. */
154
+ OnAnimationComplete: (handler: Ward.Handler<Message, Ward.AnimationDefinition>) => Ward.Attribute
155
+ /**
156
+ * The element's text, from an Atom, written outside the patch as it changes (a **Live value**, decision
157
+ * 16): the element takes no children from the view, an error in development. Format with a derived Atom.
158
+ */
159
+ Text: (atom: Ward.Config["text"]) => Ward.Attribute
160
+ /** The element's values each committed frame, set on a writable Atom (Motion's `onUpdate`): a copy per frame. */
161
+ OnUpdate: (atom: Ward.Config["onUpdate"]) => Ward.Attribute
162
+ /** The element's transform from its values and the generated string (Motion's `transformTemplate`). Hoist the function. */
163
+ TransformTemplate: (template: Ward.Config["transformTemplate"]) => Ward.Attribute
164
+ /**
165
+ * Where the element animates to as it leaves, under a `w.Presence` above it (Motion's `exit`): values,
166
+ * a variant name, or a dynamic variant resolved with the presence's `custom`. Its presence keeps it on
167
+ * the page, in its place, until it lands.
168
+ */
169
+ Exit: (value: Ward.Config["exit"]) => Ward.Attribute
170
+ /**
171
+ * The **Presence** (ADR-0007; decision 29), on the leavers' parent: each child Foldkit removes stays
172
+ * where it was while its `Exit` plays, in Motion's order through the patches that follow, and one that
173
+ * comes back under its key mid-exit takes over from where the leaver is. Needs `Features.presence`.
174
+ * Give it on the element's first render.
175
+ */
176
+ Presence: (options?: Ward.PresenceOptions<Message>) => Ward.Attribute
177
+ /**
178
+ * The element is a **Projection node** (ADR-0009; Motion's `layout`): it animates from where it was
179
+ * to where a patch put it, measured by a **Measure pass** after every patch that changed the DOM
180
+ * (decision 30). `true` (the default), or a Layout mode: `"position"`, `"size"`, `"preserve-aspect"`.
181
+ * Needs `Features.layout`.
182
+ */
183
+ Layout: Needs<F, "layout", (value?: Ward.Config["layout"]) => Ward.Attribute>
184
+ /** A **Shared layout** id (ADR-0010; Motion's `layoutId`): an element with the same one, mounting as this leaves, flies from it. */
185
+ LayoutId: Needs<F, "layout", (id: Ward.Config["layoutId"]) => Ward.Attribute>
186
+ /** A value whose change asks for a Measure pass (Motion's `layoutDependency`): the trigger under `layoutTrigger: "declared"`. */
187
+ LayoutDependency: Needs<F, "layout", (value: Ward.Config["layoutDependency"]) => Ward.Attribute>
188
+ /** The element scrolls, and its scroll isn't read as its children moving (Motion's `layoutScroll`). */
189
+ LayoutScroll: Needs<F, "layout", (value?: Ward.Config["layoutScroll"]) => Ward.Attribute>
190
+ /** A stable sub-root of the projection tree (ADR-0013; Motion's `layoutRoot`): the layout animations inside it anchor to it, and it never animates its own. */
191
+ LayoutRoot: Needs<F, "layout", (value?: Ward.Config["layoutRoot"]) => Ward.Attribute>
192
+ // #442; #795. Motion's `layoutCrossfade`, read by the twin that becomes the Lead, as each handover begins.
193
+ /**
194
+ * Whether a `LayoutId` handover onto this element crossfades the two (Motion's `layoutCrossfade`):
195
+ * `false` hides the twin it takes over from as the handover starts, and it moves at its own opacity,
196
+ * one element flying rather than two blending.
197
+ */
198
+ LayoutCrossfade: Needs<F, "layout", (value?: Ward.Config["layoutCrossfade"]) => Ward.Attribute>
199
+ /** A **Layout group** (#432; Motion's `LayoutGroup`): the namespace of the `LayoutId`s under the element, read once. */
200
+ LayoutGroup: Needs<F, "layout", (options?: Ward.LayoutGroupOptions) => Ward.Attribute>
201
+ /** Sent at the frame a layout animation's first step is painted (Motion's `onLayoutAnimationStart`). */
202
+ OnLayoutAnimationStart: Needs<F, "layout", (handler: Ward.Handler<Message, void>) => Ward.Attribute>
203
+ /** Sent once it has landed (Motion's `onLayoutAnimationComplete`). */
204
+ OnLayoutAnimationComplete: Needs<F, "layout", (handler: Ward.Handler<Message, void>) => Ward.Attribute>
205
+ /** Called as each measure of the element begins (Motion's `onBeforeLayoutMeasure`): a plain function, which can't send (decision 24). */
206
+ OnBeforeLayoutMeasure: Needs<F, "layout", (fn: Ward.Config["onBeforeLayoutMeasure"]) => Ward.Attribute>
207
+ /** Called with the element's box after each measure, and the one before (Motion's `onLayoutMeasure`): a plain function (decision 24). */
208
+ OnLayoutMeasure: Needs<F, "layout", (fn: Ward.Config["onLayoutMeasure"]) => Ward.Attribute>
209
+ /**
210
+ * A **Reorder group** (ADR-0020; decision 28; #793, Q11): the element's keyed `w.ReorderItem` children
211
+ * are put in order by dragging them, or from the keyboard (ADR-0037). The order lives in the Model:
212
+ * `values` is its, and `onReorder` sends a Message with each new order; each item is a layout element
213
+ * dragged on the group's axis and raised while it's in hand. Needs `Features.layout` and `Features.drag`.
214
+ */
215
+ ReorderGroup: Needs<F, "layout", Needs<F, "drag", <V>(options: Ward.ReorderGroupOptions<Message, V>) => Ward.Attribute>>
216
+ /**
217
+ * An item of the group above it, with its `value` in the group's `values`, read once: on a keyed element
218
+ * (`w.keyed("li")(key, …)`), which a render reorders by its key. `w.Layout("position")` beside it moves
219
+ * its place alone, as Motion's `Reorder.Item` takes.
220
+ */
221
+ ReorderItem: Needs<F, "layout", Needs<F, "drag", (value: unknown) => Ward.Attribute>>
222
+ /**
223
+ * Where the element animates while the pointer is over it, and back when it leaves (Motion's
224
+ * `whileHover`): values or a variant name, which Variant children follow too. Needs `Features.hover`.
225
+ */
226
+ WhileHover: Needs<F, "hover", (value: Ward.Config["whileHover"]) => Ward.Attribute>
227
+ /** Sent as the pointer comes over the element, with the DOM's event and its viewport point (Motion's `onHoverStart`). A touch never hovers. */
228
+ OnHoverStart: Needs<F, "hover", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => Ward.Attribute>
229
+ /** Sent as the pointer leaves the element (Motion's `onHoverEnd`). */
230
+ OnHoverEnd: Needs<F, "hover", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => Ward.Attribute>
231
+ /**
232
+ * Where the element animates while it's pressed, by a pointer or by Enter or Space while it has
233
+ * focus (Motion's `whileTap`; a **Keyboard press**). An element that can't take focus is made
234
+ * focusable. Needs `Features.press`.
235
+ */
236
+ WhileTap: Needs<F, "press", (value: Ward.Config["whileTap"]) => Ward.Attribute>
237
+ /** `{ tap: false }` keeps a press to this element (a **Press claim**): a pressable ancestor neither plays its `WhileTap` nor hears the tap (Motion's `propagate`). */
238
+ Propagate: Needs<F, "press", (options: Ward.Config["propagate"]) => Ward.Attribute>
239
+ /** Sent as a press begins: a pointer going down, or Enter or Space while focused (`info.input` says which; Motion's `onTapStart`). */
240
+ OnTapStart: Needs<F, "press", (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => Ward.Attribute>
241
+ /** Sent as that press ends on the element, or its key comes up (Motion's `onTap`). */
242
+ OnTap: Needs<F, "press", (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => Ward.Attribute>
243
+ /** Sent as that press ends elsewhere, or is cancelled; a press a drag took over is neither (Motion's `onTapCancel`). */
244
+ OnTapCancel: Needs<F, "press", (handler: Ward.GestureHandler<Message, Ward.PressEvent, Ward.PressInfo>) => Ward.Attribute>
245
+ /** Where the element animates while it has the keyboard's focus, as `:focus-visible` shows it, not a click's (Motion's `whileFocus`). Needs `Features.focus`. */
246
+ WhileFocus: Needs<F, "focus", (value: Ward.Config["whileFocus"]) => Ward.Attribute>
247
+ /** Where the element animates while it's in view, as `Viewport` defines it (Motion's `whileInView`). Needs `Features.inView`. */
248
+ WhileInView: Needs<F, "inView", (value: Ward.Config["whileInView"]) => Ward.Attribute>
249
+ /** What "in view" means (Motion's `viewport`): `once`, `margin`, `amount`, and `root` as `"parent"` or a selector. */
250
+ Viewport: Needs<F, "inView", (options: Ward.ViewportOptions) => Ward.Attribute>
251
+ /** Sent as the element comes into view, with the browser's `IntersectionObserverEntry` (Motion's `onViewportEnter`). */
252
+ OnViewportEnter: Needs<F, "inView", (handler: Ward.Handler<Message, IntersectionObserverEntry>) => Ward.Attribute>
253
+ /** Sent as it leaves the view; never after the first entry under `once` (Motion's `onViewportLeave`). */
254
+ OnViewportLeave: Needs<F, "inView", (handler: Ward.Handler<Message, IntersectionObserverEntry>) => Ward.Attribute>
255
+ /**
256
+ * The element drags (ADR-0004; Motion's `drag`): `true` (the default) on both axes, `"x"` or `"y"` on
257
+ * one. On release it carries on at the speed it was let go, a Fling, and slows to a stop. It gets
258
+ * `touch-action`, `user-select: none` and `draggable="false"` as its drag starts, under its own
259
+ * `h.Style`. The drag's options (`Drag` to `DragListener`, `DragControls`) are read as its track starts,
260
+ * at the first render that gives `Drag`, and kept: give a changed one on a new key. Needs `Features.drag`.
261
+ */
262
+ Drag: Needs<F, "drag", (value?: Ward.Config["drag"]) => Ward.Attribute>
263
+ /** Where the element animates while it's dragged, and back once it's let go (Motion's `whileDrag`); a name reaches its Variant children. */
264
+ WhileDrag: Needs<F, "drag", (value: Ward.Config["whileDrag"]) => Ward.Attribute>
265
+ /** Where it can be dragged to (Motion's `dragConstraints`): a box of pixels, `"parent"`, a selector resolved under the view at each measure, or `false`. */
266
+ DragConstraints: Needs<F, "drag", (value: Ward.DragConstraints) => Ward.Attribute>
267
+ /** How far past `DragConstraints` it can be pulled, 0 to 1: 0 stops it at the edge; 0.35 by default (Motion's `dragElastic`). */
268
+ DragElastic: Needs<F, "drag", (value: Ward.Config["dragElastic"]) => Ward.Attribute>
269
+ /** `false` stops the element where it's let go, instead of carrying on at the speed it was let go (Motion's `dragMomentum`). */
270
+ DragMomentum: Needs<F, "drag", (value: Ward.Config["dragMomentum"]) => Ward.Attribute>
271
+ /** Springs the element back to where it started when it's let go (Motion's `dragSnapToOrigin`). */
272
+ DragSnapToOrigin: Needs<F, "drag", (value?: Ward.Config["dragSnapToOrigin"]) => Ward.Attribute>
273
+ /** How it carries on after it's let go: Motion's inertia options (`power`, `timeConstant`, `bounceStiffness`, …), over Motion's defaults (`dragTransition`). */
274
+ DragTransition: Needs<F, "drag", (value: Ward.Config["dragTransition"]) => Ward.Attribute>
275
+ /** Lets a draggable ancestor drag along with this element, instead of only the innermost dragging (Motion's `dragPropagation`; a **Drag claim** not taken). */
276
+ DragPropagation: Needs<F, "drag", (value?: Ward.Config["dragPropagation"]) => Ward.Attribute>
277
+ /** Waits until a drag has moved 10 px, then keeps it to the axis it moved on; `OnDirectionLock` says which (Motion's `dragDirectionLock`). */
278
+ DragDirectionLock: Needs<F, "drag", (value?: Ward.Config["dragDirectionLock"]) => Ward.Attribute>
279
+ /** `false`: pressing the element itself doesn't drag it, only its `DragControls` do, and it gets none of the drag's styles (Motion's `dragListener`). */
280
+ DragListener: Needs<F, "drag", (value: Ward.Config["dragListener"]) => Ward.Attribute>
281
+ /** The **Drag controls** that start this element's drag from elsewhere: `DragControls.make()`'s (Motion's `dragControls`). */
282
+ DragControls: Needs<F, "drag", (controls: Ward.DragControls) => Ward.Attribute>
283
+ /**
284
+ * The `StartsDrag` element (#793, Q8): a pointer pressed on it starts the drags of every element given
285
+ * `controls`, with `options` (`snapToCursor`, `distanceThreshold`). Give it `touch-action: none`, or a
286
+ * touch on it scrolls the page.
287
+ */
288
+ StartsDrag: Needs<F, "drag", (controls: Ward.DragControls, options?: Ward.StartOptions) => Ward.Attribute>
289
+ /** With a container in `DragConstraints`: called with the bounds measured against it at each measure; return other bounds to use them (a plain function, decision 24; Motion's `onMeasureDragConstraints`). */
290
+ OnMeasureDragConstraints: Needs<F, "drag", (fn: Ward.Config["onMeasureDragConstraints"]) => Ward.Attribute>
291
+ /** Sent as a drag of the element starts, with the DOM's event and the drag's info (Motion's `onDragStart`). */
292
+ OnDragStart: Needs<F, "drag", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
293
+ /** Sent as the drag moves: at its start, and each move after (Motion's `onDrag`). */
294
+ OnDrag: Needs<F, "drag", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
295
+ /** Sent as the drag is let go; not for one its controls cancelled (Motion's `onDragEnd`). */
296
+ OnDragEnd: Needs<F, "drag", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
297
+ /** Sent as the element comes to rest after it's let go; not when a new grab stops it (Motion's `onDragTransitionEnd`). */
298
+ OnDragTransitionEnd: Needs<F, "drag", (handler: Ward.Handler<Message, void>) => Ward.Attribute>
299
+ /** With `DragDirectionLock`: sent with the axis a drag locked to, before `OnDragStart` (Motion's `onDirectionLock`). */
300
+ OnDirectionLock: Needs<F, "drag", (handler: Ward.Handler<Message, "x" | "y">) => Ward.Attribute>
301
+ /**
302
+ * Sent as a pointer goes down on the element, ready to pan, with its point (Motion's `onPanSessionStart`).
303
+ * A pan moves nothing itself: read its offset and velocity in `OnPan`. On a touch screen, give the
304
+ * element a `touch-action`, such as `pan-y` for a sideways pan, or the page's scroll takes the gesture.
305
+ * Needs `Features.pan`.
306
+ */
307
+ OnPanSessionStart: Needs<F, "pan", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.PointInfo>) => Ward.Attribute>
308
+ /** Sent as a pan starts, past its threshold, with the DOM's event and the pan's info (Motion's `onPanStart`). */
309
+ OnPanStart: Needs<F, "pan", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
310
+ /** Sent as the pan moves: at its start, and each move after (Motion's `onPan`). */
311
+ OnPan: Needs<F, "pan", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
312
+ /** Sent as a pan that started ends, or is cancelled (Motion's `onPanEnd`). */
313
+ OnPanEnd: Needs<F, "pan", (handler: Ward.GestureHandler<Message, PointerEvent, Ward.DragInfo>) => Ward.Attribute>
314
+ }>
315
+
316
+ /**
317
+ * A **Handle**: one Wardic runtime inside a Foldkit program (ADR-0071, decision 9), typed by its
318
+ * Features `F`. Made once, at module scope.
319
+ */
320
+ export interface Handle<F = never> {
321
+ /** The Handle's mark: what the `Wardic` service carries. */
322
+ readonly [HANDLE]: true
323
+ /** The builder `w` for a view's `h`, made once per `h`. */
324
+ readonly html: <Message>(h: FoldkitHtml.HtmlBuilder<Message>) => Html<Message, F>
325
+ /** The provider's raw Mount, for a Scene test to resolve by name (decision 36): `Scene.Mount.resolve(wardic.Provider, Done())`. */
326
+ readonly Provider: MountAction<never>
327
+ /** An element's raw Mount, for a Scene test to resolve by name (decision 36): one per `w.*` element in the view. */
328
+ readonly Element: MountAction<never>
329
+ /** A `w.Presence` element's raw Mount, for a Scene test to resolve by name (#792, Q19). */
330
+ readonly Presence: MountAction<never>
331
+ /** A `w.ReorderGroup` element's raw Mount, for a Scene test to resolve by name (#793, Q18); its items stay `Element`. */
332
+ readonly Reorder: MountAction<never>
333
+ /**
334
+ * The Layer a program's `resources` takes (decision 9): its Commands then run `Wardic.animate`,
335
+ * `Wardic.animateLayout` and `Wardic.provide`, which need the `Wardic` service, this Handle.
336
+ */
337
+ readonly resources: Layer.Layer<WardicTag>
338
+ /**
339
+ * The app's `viewTransition` predicate, wrapped (decision 33): `Runtime.makeElement({ viewTransition:
340
+ * wardic.viewTransition(decide) })`. In a render `decide` transitions, layout moves and `layoutId`
341
+ * handovers land at once, for the View Transition's morph to carry; the decision passes through
342
+ * unchanged, and where the document has no `startViewTransition` Wardic animates them itself.
343
+ */
344
+ readonly viewTransition: <Model, Message>(decide: FoldkitRuntime.ViewTransitionConfig<Model, Message>) => FoldkitRuntime.ViewTransitionConfig<Model, Message>
345
+ // ADR-0044; #794, Q10 and Q17. What Solid's `<WardicProvider>` does as it hydrates.
346
+ /**
347
+ * Foldkit's `Runtime.hydrate`, for a page its `experimental/server`'s `renderToString` rendered: the
348
+ * client entry calls this instead. It moves the **Appear animations**' rules the Provider element
349
+ * rendered into the head, and has the hydration render keep each element's running animation, which
350
+ * its mount takes over where the CSS has got (the **Handoff**); then Foldkit adopts the page.
351
+ */
352
+ readonly hydrate: typeof FoldkitRuntime.hydrate
353
+ }
354
+
355
+ /**
356
+ * Makes a Handle on `env`, with `features` (above). One per program, at module scope: a second
357
+ * `w.Provider()` for it while the first's element is mounted is reported and ignored.
358
+ */
359
+ export const make = <const F extends Feature.InstanceFeaturesProp = never>(options: MakeOptions<F>): Handle<F> => {
360
+ const state: State = makeState(options)
361
+ // Made once per `h` (decision 18): as `===`-stable as `h` is, for `createLazy`.
362
+ const builders = new WeakMap<object, object>()
363
+ const html = <Message>(h: FoldkitHtml.HtmlBuilder<Message>): Html<Message, F> => {
364
+ const known = builders.get(h)
365
+ if (Predicate.isNotUndefined(known)) return known as Html<Message, F>
366
+ const made = builderOf(state, h)
367
+ builders.set(h, made)
368
+ return made as Html<Message, F>
369
+ }
370
+ const handle: Handle<F> = {
371
+ [HANDLE]: true,
372
+ html,
373
+ Provider: mountOf<never>(state, { provider: {}, user: undefined, presence: false, reorder: false }),
374
+ Element: mountOf<never>(state, { provider: undefined, user: undefined, presence: false, reorder: false }),
375
+ Presence: mountOf<never>(state, { provider: undefined, user: undefined, presence: true, reorder: false }),
376
+ Reorder: mountOf<never>(state, { provider: undefined, user: undefined, presence: false, reorder: true }),
377
+ resources: resourcesOf(() => handle),
378
+ viewTransition: viewTransitionOf(state),
379
+ hydrate: hydrateOf(state),
380
+ }
381
+ remember(handle, state)
382
+ return handle
383
+ }
384
+
385
+ /** `stagger(duration, options)`'s options (#436, Motion's `stagger`): `startDelay`, `from` and `ease`, core's. */
386
+ export type StaggerOptions = Stagger.Options
387
+
388
+ /**
389
+ * A stagger for a transition's `delayChildren`, or an `animate`'s `delay` (Motion's `stagger`): `duration`
390
+ * seconds between children, from `options.from`, after `options.startDelay`.
391
+ */
392
+ export const stagger = (duration = 0.1, options: StaggerOptions = {}): WardConfig.WardicStagger => Stagger.make(duration, options)
393
+
394
+ /** `arc()`'s options (Motion's `ArcOptions`): `strength`, `peak`, `direction` and `rotate`, core's. */
395
+ export type ArcOptions = Arc.Options
396
+
397
+ // #438; #795. Solid's `arc`, so an app imports nothing from `@wardic/core` for it (#791, Q13).
398
+ /**
399
+ * A curved path for a transition's `path` (Motion's `arc()`): `x` and `y` travel along a curve between
400
+ * where they start and their target, on `x`'s transition, in place of two straight lines. Make it once,
401
+ * at module scope: with no `direction`, it remembers which side of the screen it bulged to.
402
+ *
403
+ * @example
404
+ * const toss = arc({ strength: 0.4 })
405
+ * w.img([w.LayoutId("photo"), w.Transition({ layout: { type: "tween", duration: 0.6, path: toss } })])
406
+ */
407
+ export const arc = (options: ArcOptions = {}): WardConfig.WardicPath => Arc.make(options)
408
+
409
+ // #443; #795. dom's, for Solid's `correctParentTransform` and `transformViewBoxPoint` on Foldkit, which has no refs: an element is given as a selector.
410
+ export { correctParentTransform, type ElementGiven, transformViewBoxPoint } from "@wardic/dom/unstable/PagePoint"
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @wardic/foldkit — Wardic for Foldkit (ADR-0071, #561): Motion's animations on Foldkit's views, as
3
+ * Effect. `Wardic.make({ env })` makes a Handle once per program; `wardic.html(h)` gives a view its
4
+ * `w.*` elements. Shipped from 1.2 (#561).
5
+ */
6
+ export const VERSION = "1.2.0"
7
+
8
+ export * as Wardic from "./Wardic.ts"
9
+ export * as Ward from "./Ward.ts"
10
+ // The Features a Handle takes (#792, Q16): dom's, and the binding's own `presence`.
11
+ export * as Features from "./Features.ts"
12
+ // Drag controls (#431; #793, Q8): made apart from the elements they drive.
13
+ export * as DragControls from "./DragControls.ts"
14
+ // Animation controls (#433; #798): made apart from the elements they drive, started from a Command.
15
+ export * as AnimationControls from "./AnimationControls.ts"
16
+ // Animation scopes (#433; #798): what a Command's selectors resolve under, and whose element's release stops its animations.
17
+ export * as AnimationScope from "./AnimationScope.ts"
18
+ // Core's Live values (ADR-0043) and the helpers Solid's root has, so an app imports nothing from `@wardic/core` or `@wardic/dom` (#791, Q13; #795).
19
+ export * as LiveValue from "@wardic/core/LiveValue"
20
+ export { arc, correctParentTransform, stagger, transformViewBoxPoint } from "./Wardic.ts"