@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,53 @@
1
+ /**
2
+ * The DOM's reads of its elements' values, as core's ports take them: their own values
3
+ * (`ownValues`), read through `@wardic/dom/OwnValues` and `Style`, and their Measured pairs
4
+ * (`measuredPairs`), through `@wardic/dom/MeasuredPair`, and their Variable values (`variableValues`),
5
+ * through `@wardic/dom/Variables`. A DOM binding's element code falls back to them when its
6
+ * Environment gives none, so only an app that animates an element ships them; `layer` gives them to
7
+ * an Environment that wants them explicit.
8
+ *
9
+ * Unstable, for Wardic's own packages: public, with no semver promise.
10
+ *
11
+ * @module
12
+ */
13
+ // Unstable: ADR-0071, decision 5. #672 (PR2-Q2): the DOM's implementation of core's ports, one module,
14
+ // over dom's Tier 2 modules, which stay as they are.
15
+ import * as MeasuredPairs from "@wardic/core/unstable/MeasuredPairs"
16
+ import * as OwnValues from "@wardic/core/unstable/OwnValues"
17
+ import * as VariableValues from "@wardic/core/unstable/VariableValues"
18
+ import * as Layer from "effect/Layer"
19
+ import * as Rec from "effect/Record"
20
+ import { measure, measured, needs, type Requested } from "../internal/measured-pairs.ts"
21
+ import { styleValueOf, valueLike } from "../internal/own-values.ts"
22
+ import { over } from "../internal/starting-style.ts"
23
+ import { isVariableValue, variableValues as variableRuleOf } from "../internal/variables.ts"
24
+
25
+ /** The DOM's own values: a raw value in a target's shape, a key's value in a `style` (CSS text parsed), a `style` as a record. */
26
+ export const ownValues: OwnValues.Shape = {
27
+ valueLike,
28
+ styleValueOf,
29
+ recordOf: (style) => over(style, undefined),
30
+ }
31
+
32
+ /** A pair `measure` asked, with the read of its result: dom's `MeasuredPair.measured`. */
33
+ // Per Measured pair (#430): one object a pair, a key whose ends' units don't blend.
34
+ const withRead = (pair: Requested): MeasuredPairs.Requested => ({ ...pair, measured: () => measured(pair) })
35
+
36
+ /** The DOM's Measured pairs: a pair whose units don't blend, measured on its element at the end of the task. */
37
+ export const measuredPairs: MeasuredPairs.Shape = {
38
+ needs,
39
+ measure: (subject, pairs, values) => Rec.map(measure(subject as HTMLElement, pairs, values), withRead),
40
+ }
41
+
42
+ /** The DOM's Variable values: a `var(--x)`, resolved on its element as each leg starts. */
43
+ export const variableValues: VariableValues.Shape = {
44
+ isValue: isVariableValue,
45
+ values: (subject) => variableRuleOf(subject as Element),
46
+ }
47
+
48
+ /** The DOM's ports, for an Environment that gives them explicitly: `DomLive` doesn't (PR2-Q4). */
49
+ export const layer: Layer.Layer<OwnValues.OwnValues | MeasuredPairs.MeasuredPairs | VariableValues.VariableValues> = Layer.mergeAll(
50
+ Layer.succeed(OwnValues.OwnValues)(ownValues),
51
+ Layer.succeed(MeasuredPairs.MeasuredPairs)(measuredPairs),
52
+ Layer.succeed(VariableValues.VariableValues)(variableValues),
53
+ )
@@ -0,0 +1,107 @@
1
+ /**
2
+ * A drag's constraints as an app gives them: Motion's bounding box of numbers, or the container its box
3
+ * must stay inside, an accessor read at each measure, with Motion's `onMeasureDragConstraints`. Each
4
+ * binding turns them into the drag track's: core's `Drag.Bounds`, or a container the track measures
5
+ * ({@link DragContainer}).
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // #273, ADR-0047. Unstable: ADR-0071, decision 5. #672: solid's `drag-constraints.ts`, moved with
12
+ // `WardConfig`, which names it.
13
+ import type * as Drag from "@wardic/core/Drag"
14
+ import * as ProjectionSystem from "../ProjectionSystem.ts"
15
+ import * as Predicate from "effect/Predicate"
16
+ import * as UndefinedOr from "effect/UndefinedOr"
17
+ import { constUndefined } from "effect/Function"
18
+ import type * as Config from "@wardic/core/unstable/Config"
19
+
20
+ /** A box's edges, as Motion's `BoundingBox`: on x, `left` and `right`; on y, `top` and `bottom`. */
21
+ export interface WardicBoundingBox {
22
+ readonly top: number
23
+ readonly right: number
24
+ readonly bottom: number
25
+ readonly left: number
26
+ }
27
+
28
+ /**
29
+ * `dragConstraints` (Motion's): the range of the element's x (`left` to `right`) and y
30
+ * (`top` to `bottom`), an edge left out unbounded; the container its box must stay inside, an accessor
31
+ * read at each measure (a drag's start, a resize of either); or `false`, none.
32
+ */
33
+ export type WardicDragConstraints = false | Partial<WardicBoundingBox> | (() => Element | undefined)
34
+
35
+ /** Motion's `onMeasureDragConstraints`: the bounds measured against the container in, its own out, or none to keep them. */
36
+ export type WardicMeasureDragConstraints = (constraints: WardicBoundingBox) => WardicBoundingBox | undefined | void
37
+
38
+ /**
39
+ * An element constraint, as the drag track takes it: its container, read at each measure, and the
40
+ * bounds measured against it, the app's `onMeasureDragConstraints` applied.
41
+ */
42
+ export interface DragContainer {
43
+ readonly element: () => Element | undefined
44
+ readonly bounds: (container: Element) => Drag.Bounds
45
+ }
46
+
47
+ /** An axis range from its two edges, either left out. */
48
+ const rangeOf = (min: number | undefined, max: number | undefined): Drag.AxisRange => ({
49
+ ...UndefinedOr.match(min, { onUndefined: () => ({}), onDefined: (edge) => ({ min: edge }) }),
50
+ ...UndefinedOr.match(max, { onUndefined: () => ({}), onDefined: (edge) => ({ max: edge }) }),
51
+ })
52
+
53
+ /** Motion's box as core's bounds: x from `left` to `right`, y from `top` to `bottom`. */
54
+ export const boundsOfBox = (box: Partial<WardicBoundingBox>): Drag.Bounds => ({ x: rangeOf(box.left, box.right), y: rangeOf(box.top, box.bottom) })
55
+
56
+ /** An edge of measured bounds, which has both. */
57
+ const edge = (value: number | undefined): number => UndefinedOr.match(value, { onUndefined: () => 0, onDefined: (n) => n })
58
+
59
+ /** A measured axis's two edges. */
60
+ const edgesOf = (range: Drag.AxisRange | undefined): readonly [number, number] =>
61
+ UndefinedOr.match(range, { onUndefined: () => [0, 0] as const, onDefined: (r) => [edge(r.min), edge(r.max)] as const })
62
+
63
+ /** Measured bounds as Motion's box, for `onMeasureDragConstraints`. */
64
+ const boxOfBounds = (bounds: Drag.Bounds): WardicBoundingBox => {
65
+ const [left, right] = edgesOf(bounds.x)
66
+ const [top, bottom] = edgesOf(bounds.y)
67
+ return { left, right, top, bottom }
68
+ }
69
+
70
+ /** What a drag track takes from an element's `dragConstraints`. */
71
+ export interface TrackConstraints {
72
+ readonly constraints?: Drag.Bounds | undefined
73
+ readonly container?: DragContainer | undefined
74
+ }
75
+
76
+ const NONE: TrackConstraints = {}
77
+
78
+ /**
79
+ * The drag track's constraints from `dragConstraints`: Motion's box as bounds, or a container measured
80
+ * against `element`, `onMeasure` read at each measure.
81
+ */
82
+ export const trackConstraintsOf = (
83
+ constraints: WardicDragConstraints | undefined,
84
+ element: HTMLElement,
85
+ onMeasure: () => WardicMeasureDragConstraints | undefined,
86
+ mapPoint: () => Config.WardicTransformPoint | undefined = constUndefined,
87
+ ): TrackConstraints => {
88
+ if (Predicate.isUndefined(constraints)) return NONE
89
+ if (constraints === false) return NONE
90
+ if (Predicate.isFunction(constraints)) {
91
+ return {
92
+ container: {
93
+ element: constraints,
94
+ bounds: (container) => {
95
+ // Its boxes through the nearest config's `transformPagePoint` (#443), read at each measure.
96
+ const measured = ProjectionSystem.dragBoundsWithin(element, container, mapPoint())
97
+ return UndefinedOr.match(onMeasure(), {
98
+ onUndefined: () => measured,
99
+ onDefined: (adjust) =>
100
+ UndefinedOr.match(adjust(boxOfBounds(measured)) as WardicBoundingBox | undefined, { onUndefined: () => measured, onDefined: boundsOfBox }),
101
+ })
102
+ },
103
+ },
104
+ }
105
+ }
106
+ return { constraints: boundsOfBox(constraints) }
107
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * **Drag controls** (Motion's `useDragControls`): controls made apart from any element and given to one
3
+ * or more, whose `start(event)` begins each one's drag from a pointer that went down elsewhere, a
4
+ * handle or a track. Each binding exports {@link createDragControls}; each element's drag track
5
+ * subscribes while it's mounted.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // #431 (CONTEXT.md's **Drag controls**). Unstable: ADR-0071, decision 5. #672: solid's
12
+ // `drag-controls.ts`, moved with `WardConfig`, which names it.
13
+ import * as Arr from "effect/Array"
14
+ import { constVoid } from "effect/Function"
15
+ import * as UndefinedOr from "effect/UndefinedOr"
16
+
17
+ /** `controls.start`'s options, as Motion's. */
18
+ export interface WardicDragControlsOptions {
19
+ /** Moves the element so its centre is under the pointer as the drag begins, on the axes it drags. Default `false`. */
20
+ readonly snapToCursor?: boolean | undefined
21
+ /** How far the pointer moves, in pixels, before the drag starts. Default 3. */
22
+ readonly distanceThreshold?: number | undefined
23
+ }
24
+
25
+ /**
26
+ * `createDragControls()`'s controls: give them to elements as `dragControls`, then start, stop or
27
+ * cancel their drags from anywhere.
28
+ */
29
+ // #431, Motion's `DragControls`.
30
+ export interface WardicDragControls {
31
+ /**
32
+ * Starts a drag on each element given these controls, from `event`, a pointer pressed elsewhere: call
33
+ * it from that pointer's `pointerdown`. Each follows the pointer as if it had been pressed itself,
34
+ * once the pointer has moved past the threshold. Of two elements given the same controls on one axis,
35
+ * only the first drags, unless the other has `dragPropagation`. One leaving an `<AnimatePresence>`
36
+ * doesn't start. Give the handle `touch-action: none`, or a touch on it scrolls the page.
37
+ */
38
+ // Each takes its Drag claim as any drag does (Motion's drag lock).
39
+ readonly start: (event: PointerEvent, options?: WardicDragControlsOptions) => void
40
+ /** Ends each drag as letting go of the pointer would: it carries on as released, and `onDragEnd` (Solid 2: `dragEnd`) is called. */
41
+ readonly stop: () => void
42
+ /**
43
+ * Ends each drag where it is: it doesn't carry on, `onDragEnd` isn't called, and `whileDrag` goes off.
44
+ * A `layout` element goes back to its place, as after any drag.
45
+ */
46
+ readonly cancel: () => void
47
+ }
48
+
49
+ /** What an element's drag track gives the controls it's subscribed to. */
50
+ export interface ControlledDrag {
51
+ readonly start: (event: PointerEvent, options: WardicDragControlsOptions) => void
52
+ readonly stop: () => void
53
+ readonly cancel: () => void
54
+ }
55
+
56
+ /** Each controls' subscribed tracks. */
57
+ // Module state (#460, Q7): each controls object's drags, held weakly by it.
58
+ const subscribed = new WeakMap<WardicDragControls, Set<ControlledDrag>>()
59
+
60
+ const NO_OPTIONS: WardicDragControlsOptions = {}
61
+
62
+ /**
63
+ * Makes drag controls, which start an element's drag from somewhere else, such as a handle: give them
64
+ * to each element they drive as `dragControls`, on a `w.*` element, in a ward's config or on a
65
+ * `Reorder.Item`, and add `dragListener={false}` when a press on the element itself shouldn't drag it.
66
+ * Needs no owner. Motion's `useDragControls`.
67
+ *
68
+ * @example
69
+ * const controls = createDragControls()
70
+ * <div onPointerDown={(e) => controls.start(e)} style={{ "touch-action": "none" }}>handle</div>
71
+ * <w.div drag="x" dragControls={controls} dragListener={false} />
72
+ * @see https://wardic.dev/reference/solid/gestures/create-drag-controls
73
+ */
74
+ // #431: made outside the elements they drive; each element's drag track subscribes while it's mounted.
75
+ export const createDragControls = (): WardicDragControls => {
76
+ const tracks = new Set<ControlledDrag>()
77
+ // A track that subscribes or leaves while the controls call each is left out of that call.
78
+ const each = (call: (track: ControlledDrag) => void): void => Arr.forEach(Arr.fromIterable(tracks), call)
79
+ const controls: WardicDragControls = {
80
+ start: (event, options = NO_OPTIONS) => each((track) => track.start(event, options)),
81
+ stop: () => each((track) => track.stop()),
82
+ cancel: () => each((track) => track.cancel()),
83
+ }
84
+ subscribed.set(controls, tracks)
85
+ return controls
86
+ }
87
+
88
+ /** Subscribe a drag track to `controls` (internal): unsubscribed by the function it returns. Controls not made by {@link createDragControls} drive nothing. */
89
+ export const subscribeDragControls = (controls: WardicDragControls, track: ControlledDrag): (() => void) =>
90
+ UndefinedOr.match(subscribed.get(controls), {
91
+ onUndefined: () => constVoid,
92
+ onDefined: (tracks) => {
93
+ tracks.add(track)
94
+ return () => {
95
+ tracks.delete(track)
96
+ }
97
+ },
98
+ })
@@ -0,0 +1,57 @@
1
+ /**
2
+ * A drag element's defaults (ADR-0019 *Amendment (Reorder)*): the drag axis its binding runs its spine
3
+ * with, the styles and attribute a drag element takes, and their write at mount for an element whose
4
+ * props don't carry them.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672 (Q11, PR2-Q3): solid's `drag-defaults.ts`, out of `spine.ts` since
11
+ // PR 2, moved to dom for every DOM binding's drag elements.
12
+ import * as Style from "../Style.ts"
13
+ import * as Arr from "effect/Array"
14
+ import * as Option from "effect/Option"
15
+ import * as Rec from "effect/Record"
16
+ import * as UndefinedOr from "effect/UndefinedOr"
17
+ import type * as WardConfig from "./WardConfig.ts"
18
+
19
+ /** What a `<Reorder>` item adds to an element's drag: its gesture's axis, read at each drag's start. */
20
+ interface DragInternals {
21
+ readonly dragAxis?: (() => boolean | "x" | "y") | undefined
22
+ }
23
+
24
+ /** A plain element's drag internals: none. */
25
+ const NO_DRAG_INTERNALS: DragInternals = {}
26
+
27
+ /**
28
+ * The drag axis a spine runs with: its static `drag` config, else `true` for a
29
+ * `<Reorder>` item (its gesture's axis comes from `dragAxis`), else none.
30
+ */
31
+ export const dragAxisOf = (config: WardConfig.WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): boolean | "x" | "y" | undefined =>
32
+ Option.getOrUndefined(
33
+ Option.orElse(Option.filter(Option.fromUndefinedOr(config.drag), (drag) => drag !== false), () =>
34
+ Option.map(Option.fromUndefinedOr(internal.dragAxis), (): true => true)),
35
+ )
36
+
37
+ /**
38
+ * A drag element's defaults (ADR-0019 *Amendment (Reorder)*): its axis's, unless its own presses don't
39
+ * drag it (`dragListener={false}`, #431), as Motion's come with its listener.
40
+ */
41
+ export const dragDefaultsOf = (config: WardConfig.WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): Style.DragDefaults | undefined => {
42
+ if (config.dragListener === false) return undefined
43
+ return UndefinedOr.map(dragAxisOf(config, internal), Style.dragDefaults)
44
+ }
45
+
46
+ /**
47
+ * Set each of a drag element's defaults its inline style doesn't already set, and
48
+ * `draggable="false"` unless it has the attribute, at mount: for an element whose props don't carry
49
+ * them, a directive's (`use:wardic`, `use:w`) and a `wardic.create(Component)` wrap's, whose
50
+ * component may not pass them on.
51
+ */
52
+ export const applyDragDefaults = (element: HTMLElement, defaults: Style.DragDefaults): void => {
53
+ Arr.forEach(Rec.keys(defaults), (key) => {
54
+ if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(defaults[key]))
55
+ })
56
+ if (!element.hasAttribute("draggable")) element.setAttribute("draggable", Style.DRAG_DEFAULT_ATTRIBUTES.draggable)
57
+ }