@wardic/dom 0.0.0-stage → 1.0.0-rc.10

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 (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/Appear.d.ts +30 -0
  5. package/dist/Appear.d.ts.map +1 -0
  6. package/dist/Appear.js +31 -0
  7. package/dist/Appear.js.map +1 -0
  8. package/dist/Color.d.ts +14 -0
  9. package/dist/Color.d.ts.map +1 -0
  10. package/dist/Color.js +16 -0
  11. package/dist/Color.js.map +1 -0
  12. package/dist/DomAnnouncer.d.ts +13 -0
  13. package/dist/DomAnnouncer.d.ts.map +1 -0
  14. package/dist/DomAnnouncer.js +14 -0
  15. package/dist/DomAnnouncer.js.map +1 -0
  16. package/dist/DomBatch.d.ts +20 -0
  17. package/dist/DomBatch.d.ts.map +1 -0
  18. package/dist/DomBatch.js +23 -0
  19. package/dist/DomBatch.js.map +1 -0
  20. package/dist/DomClock.d.ts +11 -0
  21. package/dist/DomClock.d.ts.map +1 -0
  22. package/dist/DomClock.js +12 -0
  23. package/dist/DomClock.js.map +1 -0
  24. package/dist/DomDefaultTransition.d.ts +12 -0
  25. package/dist/DomDefaultTransition.d.ts.map +1 -0
  26. package/dist/DomDefaultTransition.js +13 -0
  27. package/dist/DomDefaultTransition.js.map +1 -0
  28. package/dist/DomInput.d.ts +14 -0
  29. package/dist/DomInput.d.ts.map +1 -0
  30. package/dist/DomInput.js +17 -0
  31. package/dist/DomInput.js.map +1 -0
  32. package/dist/DomInterpolators.d.ts +13 -0
  33. package/dist/DomInterpolators.d.ts.map +1 -0
  34. package/dist/DomInterpolators.js +14 -0
  35. package/dist/DomInterpolators.js.map +1 -0
  36. package/dist/DomKeyRules.d.ts +13 -0
  37. package/dist/DomKeyRules.d.ts.map +1 -0
  38. package/dist/DomKeyRules.js +14 -0
  39. package/dist/DomKeyRules.js.map +1 -0
  40. package/dist/DomPositionalKeys.d.ts +13 -0
  41. package/dist/DomPositionalKeys.d.ts.map +1 -0
  42. package/dist/DomPositionalKeys.js +14 -0
  43. package/dist/DomPositionalKeys.js.map +1 -0
  44. package/dist/DomProbe.d.ts +13 -0
  45. package/dist/DomProbe.d.ts.map +1 -0
  46. package/dist/DomProbe.js +14 -0
  47. package/dist/DomProbe.js.map +1 -0
  48. package/dist/DomProjectionSystem.d.ts +28 -0
  49. package/dist/DomProjectionSystem.d.ts.map +1 -0
  50. package/dist/DomProjectionSystem.js +41 -0
  51. package/dist/DomProjectionSystem.js.map +1 -0
  52. package/dist/DomRenderer.d.ts +13 -0
  53. package/dist/DomRenderer.d.ts.map +1 -0
  54. package/dist/DomRenderer.js +15 -0
  55. package/dist/DomRenderer.js.map +1 -0
  56. package/dist/DomScrollSource.d.ts +14 -0
  57. package/dist/DomScrollSource.d.ts.map +1 -0
  58. package/dist/DomScrollSource.js +15 -0
  59. package/dist/DomScrollSource.js.map +1 -0
  60. package/dist/FlushGate.d.ts +48 -0
  61. package/dist/FlushGate.d.ts.map +1 -0
  62. package/dist/FlushGate.js +62 -0
  63. package/dist/FlushGate.js.map +1 -0
  64. package/dist/KeyboardPress.d.ts +16 -0
  65. package/dist/KeyboardPress.d.ts.map +1 -0
  66. package/dist/KeyboardPress.js +17 -0
  67. package/dist/KeyboardPress.js.map +1 -0
  68. package/dist/MeasuredPair.d.ts +14 -0
  69. package/dist/MeasuredPair.d.ts.map +1 -0
  70. package/dist/MeasuredPair.js +16 -0
  71. package/dist/MeasuredPair.js.map +1 -0
  72. package/dist/OwnValues.d.ts +14 -0
  73. package/dist/OwnValues.d.ts.map +1 -0
  74. package/dist/OwnValues.js +15 -0
  75. package/dist/OwnValues.js.map +1 -0
  76. package/dist/ProjectionSystem.d.ts +34 -0
  77. package/dist/ProjectionSystem.d.ts.map +1 -0
  78. package/dist/ProjectionSystem.js +29 -0
  79. package/dist/ProjectionSystem.js.map +1 -0
  80. package/dist/ReorderController.d.ts +61 -0
  81. package/dist/ReorderController.d.ts.map +1 -0
  82. package/dist/ReorderController.js +78 -0
  83. package/dist/ReorderController.js.map +1 -0
  84. package/dist/Report.d.ts +12 -0
  85. package/dist/Report.d.ts.map +1 -0
  86. package/dist/Report.js +13 -0
  87. package/dist/Report.js.map +1 -0
  88. package/dist/ScrollOffset.d.ts +34 -0
  89. package/dist/ScrollOffset.d.ts.map +1 -0
  90. package/dist/ScrollOffset.js +42 -0
  91. package/dist/ScrollOffset.js.map +1 -0
  92. package/dist/Style.d.ts +15 -0
  93. package/dist/Style.d.ts.map +1 -0
  94. package/dist/Style.js +17 -0
  95. package/dist/Style.js.map +1 -0
  96. package/dist/Svg.d.ts +13 -0
  97. package/dist/Svg.d.ts.map +1 -0
  98. package/dist/Svg.js +14 -0
  99. package/dist/Svg.js.map +1 -0
  100. package/dist/Variables.d.ts +13 -0
  101. package/dist/Variables.d.ts.map +1 -0
  102. package/dist/Variables.js +14 -0
  103. package/dist/Variables.js.map +1 -0
  104. package/dist/index.d.ts +83 -0
  105. package/dist/index.d.ts.map +1 -0
  106. package/dist/index.js +71 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/internal/announcer.d.ts +50 -0
  109. package/dist/internal/announcer.d.ts.map +1 -0
  110. package/dist/internal/announcer.js +115 -0
  111. package/dist/internal/announcer.js.map +1 -0
  112. package/dist/internal/appear-slot.d.ts +23 -0
  113. package/dist/internal/appear-slot.d.ts.map +1 -0
  114. package/dist/internal/appear-slot.js +29 -0
  115. package/dist/internal/appear-slot.js.map +1 -0
  116. package/dist/internal/appear.d.ts +237 -0
  117. package/dist/internal/appear.d.ts.map +1 -0
  118. package/dist/internal/appear.js +740 -0
  119. package/dist/internal/appear.js.map +1 -0
  120. package/dist/internal/auto-scroll.d.ts +24 -0
  121. package/dist/internal/auto-scroll.d.ts.map +1 -0
  122. package/dist/internal/auto-scroll.js +124 -0
  123. package/dist/internal/auto-scroll.js.map +1 -0
  124. package/dist/internal/batch-writer.d.ts +16 -0
  125. package/dist/internal/batch-writer.d.ts.map +1 -0
  126. package/dist/internal/batch-writer.js +77 -0
  127. package/dist/internal/batch-writer.js.map +1 -0
  128. package/dist/internal/clock.d.ts +19 -0
  129. package/dist/internal/clock.d.ts.map +1 -0
  130. package/dist/internal/clock.js +39 -0
  131. package/dist/internal/clock.js.map +1 -0
  132. package/dist/internal/colors.d.ts +45 -0
  133. package/dist/internal/colors.d.ts.map +1 -0
  134. package/dist/internal/colors.js +193 -0
  135. package/dist/internal/colors.js.map +1 -0
  136. package/dist/internal/complex.d.ts +24 -0
  137. package/dist/internal/complex.d.ts.map +1 -0
  138. package/dist/internal/complex.js +28 -0
  139. package/dist/internal/complex.js.map +1 -0
  140. package/dist/internal/content-watch.d.ts +20 -0
  141. package/dist/internal/content-watch.d.ts.map +1 -0
  142. package/dist/internal/content-watch.js +76 -0
  143. package/dist/internal/content-watch.js.map +1 -0
  144. package/dist/internal/default-transition.d.ts +25 -0
  145. package/dist/internal/default-transition.d.ts.map +1 -0
  146. package/dist/internal/default-transition.js +41 -0
  147. package/dist/internal/default-transition.js.map +1 -0
  148. package/dist/internal/drag-defaults.d.ts +18 -0
  149. package/dist/internal/drag-defaults.d.ts.map +1 -0
  150. package/dist/internal/drag-defaults.js +38 -0
  151. package/dist/internal/drag-defaults.js.map +1 -0
  152. package/dist/internal/gate.d.ts +188 -0
  153. package/dist/internal/gate.d.ts.map +1 -0
  154. package/dist/internal/gate.js +458 -0
  155. package/dist/internal/gate.js.map +1 -0
  156. package/dist/internal/input.d.ts +35 -0
  157. package/dist/internal/input.d.ts.map +1 -0
  158. package/dist/internal/input.js +658 -0
  159. package/dist/internal/input.js.map +1 -0
  160. package/dist/internal/interpolators.d.ts +19 -0
  161. package/dist/internal/interpolators.d.ts.map +1 -0
  162. package/dist/internal/interpolators.js +30 -0
  163. package/dist/internal/interpolators.js.map +1 -0
  164. package/dist/internal/key-rules.d.ts +11 -0
  165. package/dist/internal/key-rules.d.ts.map +1 -0
  166. package/dist/internal/key-rules.js +244 -0
  167. package/dist/internal/key-rules.js.map +1 -0
  168. package/dist/internal/keyboard-press.d.ts +7 -0
  169. package/dist/internal/keyboard-press.d.ts.map +1 -0
  170. package/dist/internal/keyboard-press.js +45 -0
  171. package/dist/internal/keyboard-press.js.map +1 -0
  172. package/dist/internal/measure.d.ts +157 -0
  173. package/dist/internal/measure.d.ts.map +1 -0
  174. package/dist/internal/measure.js +296 -0
  175. package/dist/internal/measure.js.map +1 -0
  176. package/dist/internal/measured-pairs.d.ts +38 -0
  177. package/dist/internal/measured-pairs.d.ts.map +1 -0
  178. package/dist/internal/measured-pairs.js +251 -0
  179. package/dist/internal/measured-pairs.js.map +1 -0
  180. package/dist/internal/own-values.d.ts +35 -0
  181. package/dist/internal/own-values.d.ts.map +1 -0
  182. package/dist/internal/own-values.js +117 -0
  183. package/dist/internal/own-values.js.map +1 -0
  184. package/dist/internal/pass-ends.d.ts +21 -0
  185. package/dist/internal/pass-ends.d.ts.map +1 -0
  186. package/dist/internal/pass-ends.js +14 -0
  187. package/dist/internal/pass-ends.js.map +1 -0
  188. package/dist/internal/positional-keys.d.ts +16 -0
  189. package/dist/internal/positional-keys.d.ts.map +1 -0
  190. package/dist/internal/positional-keys.js +21 -0
  191. package/dist/internal/positional-keys.js.map +1 -0
  192. package/dist/internal/probe.d.ts +10 -0
  193. package/dist/internal/probe.d.ts.map +1 -0
  194. package/dist/internal/probe.js +116 -0
  195. package/dist/internal/probe.js.map +1 -0
  196. package/dist/internal/projection-defaults.d.ts +34 -0
  197. package/dist/internal/projection-defaults.d.ts.map +1 -0
  198. package/dist/internal/projection-defaults.js +21 -0
  199. package/dist/internal/projection-defaults.js.map +1 -0
  200. package/dist/internal/projection.d.ts +537 -0
  201. package/dist/internal/projection.d.ts.map +1 -0
  202. package/dist/internal/projection.js +5228 -0
  203. package/dist/internal/projection.js.map +1 -0
  204. package/dist/internal/renderer.d.ts +104 -0
  205. package/dist/internal/renderer.d.ts.map +1 -0
  206. package/dist/internal/renderer.js +618 -0
  207. package/dist/internal/renderer.js.map +1 -0
  208. package/dist/internal/reorder.d.ts +174 -0
  209. package/dist/internal/reorder.d.ts.map +1 -0
  210. package/dist/internal/reorder.js +466 -0
  211. package/dist/internal/reorder.js.map +1 -0
  212. package/dist/internal/report.d.ts +30 -0
  213. package/dist/internal/report.d.ts.map +1 -0
  214. package/dist/internal/report.js +60 -0
  215. package/dist/internal/report.js.map +1 -0
  216. package/dist/internal/require-global.d.ts +11 -0
  217. package/dist/internal/require-global.d.ts.map +1 -0
  218. package/dist/internal/require-global.js +31 -0
  219. package/dist/internal/require-global.js.map +1 -0
  220. package/dist/internal/reveal.d.ts +20 -0
  221. package/dist/internal/reveal.d.ts.map +1 -0
  222. package/dist/internal/reveal.js +71 -0
  223. package/dist/internal/reveal.js.map +1 -0
  224. package/dist/internal/runner.d.ts +21 -0
  225. package/dist/internal/runner.d.ts.map +1 -0
  226. package/dist/internal/runner.js +48 -0
  227. package/dist/internal/runner.js.map +1 -0
  228. package/dist/internal/scale-correction.d.ts +80 -0
  229. package/dist/internal/scale-correction.d.ts.map +1 -0
  230. package/dist/internal/scale-correction.js +227 -0
  231. package/dist/internal/scale-correction.js.map +1 -0
  232. package/dist/internal/scroll.d.ts +37 -0
  233. package/dist/internal/scroll.d.ts.map +1 -0
  234. package/dist/internal/scroll.js +279 -0
  235. package/dist/internal/scroll.js.map +1 -0
  236. package/dist/internal/scrollers.d.ts +35 -0
  237. package/dist/internal/scrollers.d.ts.map +1 -0
  238. package/dist/internal/scrollers.js +38 -0
  239. package/dist/internal/scrollers.js.map +1 -0
  240. package/dist/internal/starting-style.d.ts +141 -0
  241. package/dist/internal/starting-style.d.ts.map +1 -0
  242. package/dist/internal/starting-style.js +300 -0
  243. package/dist/internal/starting-style.js.map +1 -0
  244. package/dist/internal/svg.d.ts +60 -0
  245. package/dist/internal/svg.d.ts.map +1 -0
  246. package/dist/internal/svg.js +257 -0
  247. package/dist/internal/svg.js.map +1 -0
  248. package/dist/internal/variables.d.ts +45 -0
  249. package/dist/internal/variables.d.ts.map +1 -0
  250. package/dist/internal/variables.js +92 -0
  251. package/dist/internal/variables.js.map +1 -0
  252. package/package.json +65 -4
  253. package/src/Appear.ts +54 -0
  254. package/src/Color.ts +24 -0
  255. package/src/DomAnnouncer.ts +22 -0
  256. package/src/DomBatch.ts +22 -0
  257. package/src/DomClock.ts +13 -0
  258. package/src/DomDefaultTransition.ts +16 -0
  259. package/src/DomInput.ts +23 -0
  260. package/src/DomInterpolators.ts +16 -0
  261. package/src/DomKeyRules.ts +17 -0
  262. package/src/DomPositionalKeys.ts +16 -0
  263. package/src/DomProbe.ts +15 -0
  264. package/src/DomProjectionSystem.ts +44 -0
  265. package/src/DomRenderer.ts +26 -0
  266. package/src/DomScrollSource.ts +14 -0
  267. package/src/FlushGate.ts +81 -0
  268. package/src/KeyboardPress.ts +16 -0
  269. package/src/MeasuredPair.ts +15 -0
  270. package/src/OwnValues.ts +19 -0
  271. package/src/ProjectionSystem.ts +51 -0
  272. package/src/ReorderController.ts +122 -0
  273. package/src/Report.ts +17 -0
  274. package/src/ScrollOffset.ts +54 -0
  275. package/src/Style.ts +37 -0
  276. package/src/Svg.ts +21 -0
  277. package/src/Variables.ts +17 -0
  278. package/src/index.ts +120 -0
  279. package/src/internal/announcer.ts +132 -0
  280. package/src/internal/appear-slot.ts +32 -0
  281. package/src/internal/appear.ts +1134 -0
  282. package/src/internal/auto-scroll.ts +176 -0
  283. package/src/internal/batch-writer.ts +95 -0
  284. package/src/internal/clock.ts +45 -0
  285. package/src/internal/colors.ts +258 -0
  286. package/src/internal/complex.ts +29 -0
  287. package/src/internal/content-watch.ts +84 -0
  288. package/src/internal/culori.d.ts +58 -0
  289. package/src/internal/default-transition.ts +50 -0
  290. package/src/internal/drag-defaults.ts +54 -0
  291. package/src/internal/gate.ts +598 -0
  292. package/src/internal/input.ts +763 -0
  293. package/src/internal/interpolators.ts +33 -0
  294. package/src/internal/key-rules.ts +357 -0
  295. package/src/internal/keyboard-press.ts +45 -0
  296. package/src/internal/measure.ts +373 -0
  297. package/src/internal/measured-pairs.ts +297 -0
  298. package/src/internal/own-values.ts +166 -0
  299. package/src/internal/pass-ends.ts +23 -0
  300. package/src/internal/positional-keys.ts +24 -0
  301. package/src/internal/probe.ts +175 -0
  302. package/src/internal/projection-defaults.ts +45 -0
  303. package/src/internal/projection.ts +6233 -0
  304. package/src/internal/renderer.ts +648 -0
  305. package/src/internal/reorder.ts +650 -0
  306. package/src/internal/report.ts +69 -0
  307. package/src/internal/require-global.ts +46 -0
  308. package/src/internal/reveal.ts +75 -0
  309. package/src/internal/runner.ts +64 -0
  310. package/src/internal/scale-correction.ts +310 -0
  311. package/src/internal/scroll.ts +358 -0
  312. package/src/internal/scrollers.ts +51 -0
  313. package/src/internal/starting-style.ts +396 -0
  314. package/src/internal/svg.ts +300 -0
  315. package/src/internal/variables.ts +145 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Watching a container's content for size changes: its direct children on a `ResizeObserver`, each
3
+ * observed now and as it's added, and let go as it's removed. A deep change counts once it resizes
4
+ * the direct child it sits in.
5
+ *
6
+ * - The DOM's `ScrollSource` watches a container's (the page's: the body's), so its range follows its content
7
+ * (#239, ADR-0043 *Amendment (#239)*).
8
+ * - The Projection system watches the page's, so a node that content elsewhere moved is measured again
9
+ * (#261, ADR-0018 *Amendment (#261)*).
10
+ *
11
+ * The observer is shared by count: a box watched for two reasons (a scroll target that is also a
12
+ * child, a layout node that is also a page box) stays watched until both let go.
13
+ */
14
+ import * as Arr from "effect/Array"
15
+ import { constVoid } from "effect/Function"
16
+ import * as Option from "effect/Option"
17
+
18
+ /** Observing and letting go of boxes on one observer, each counted by the reasons it's watched for. */
19
+ export interface Watched {
20
+ readonly observe: (box: Element) => void
21
+ readonly unobserve: (box: Element) => void
22
+ }
23
+
24
+ /** {@link Watched} over `observer`, every box observed with `options`. */
25
+ export const counted = (observer: ResizeObserver, options?: ResizeObserverOptions): Watched => {
26
+ const counts = new Map<Element, number>()
27
+ const countOf = (box: Element): number => Option.getOrElse(Option.fromUndefinedOr(counts.get(box)), () => 0)
28
+ return {
29
+ observe: (box) => {
30
+ const count = countOf(box)
31
+ counts.set(box, count + 1)
32
+ if (count === 0) observer.observe(box, options)
33
+ },
34
+ unobserve: (box) => {
35
+ const count = countOf(box)
36
+ if (count === 0) return
37
+ if (count > 1) {
38
+ counts.set(box, count - 1)
39
+ return
40
+ }
41
+ counts.delete(box)
42
+ observer.unobserve(box)
43
+ },
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Watch `parent`'s direct children on `watched`, kept current by a `MutationObserver` on its child list.
49
+ * `onChildren` runs after each change to the list, its children watched by then. Returns the stop; the
50
+ * observer's own disconnect lets go of the boxes.
51
+ */
52
+ export const watchChildren = (parent: Element, watched: Watched, onChildren: () => void): (() => void) => {
53
+ Arr.forEach(Array.from(parent.children), watched.observe)
54
+ const children = new MutationObserver((records) => {
55
+ Arr.forEach(records, (record) => {
56
+ Arr.forEach(Array.from(record.addedNodes), (node) => {
57
+ if (node instanceof Element) watched.observe(node)
58
+ })
59
+ Arr.forEach(Array.from(record.removedNodes), (node) => {
60
+ if (node instanceof Element) watched.unobserve(node)
61
+ })
62
+ })
63
+ onChildren()
64
+ })
65
+ children.observe(parent, { childList: true })
66
+ return () => children.disconnect()
67
+ }
68
+
69
+ /**
70
+ * Watch the page's content on `watched`: the body and its direct children (a body sized to the window
71
+ * doesn't grow with what overflows it), as {@link watchChildren} watches a container's. None with no
72
+ * body (a server, a document not parsed that far). Returns the stop.
73
+ */
74
+ export const watchPage = (watched: Watched, onChildren: () => void): (() => void) =>
75
+ Option.match(
76
+ Option.flatMap(Option.fromUndefinedOr((globalThis as { readonly document?: Document }).document), (page) => Option.fromNullOr(page.body)),
77
+ {
78
+ onNone: () => constVoid,
79
+ onSome: (body) => {
80
+ watched.observe(body)
81
+ return watchChildren(body, watched, onChildren)
82
+ },
83
+ },
84
+ )
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Minimal ambient types for the subset of `culori` the color interpolator uses: `culori/fn` (#511),
3
+ * which registers no colour space by itself, and the `culori` bundle the tests compare against.
4
+ * `culori` v4 ships no TypeScript types and `@types/culori` lags its API, so we
5
+ * declare exactly what we touch here. Widen this if we start using more of culori.
6
+ */
7
+ declare module "culori" {
8
+ export type Color = Record<string, number | string | undefined>
9
+
10
+ export function interpolate(
11
+ colors: ReadonlyArray<string | Color>,
12
+ mode?: string,
13
+ overrides?: unknown,
14
+ ): (t: number) => Color
15
+
16
+ export function formatRgb(color: Color | string): string
17
+ export function formatHex(color: Color | string): string
18
+ export function parse(color: string): Color | undefined
19
+ export function converter(mode: string): (color: Color) => Color
20
+ }
21
+
22
+ declare module "culori/fn" {
23
+ export type Color = Record<string, number | string | undefined>
24
+
25
+ /** A colour space's definition, as `useMode` takes it. */
26
+ export interface Mode {
27
+ readonly mode: string
28
+ }
29
+
30
+ export function interpolate(
31
+ colors: ReadonlyArray<string | Color>,
32
+ mode?: string,
33
+ overrides?: unknown,
34
+ ): (t: number) => Color
35
+
36
+ export function formatRgb(color: Color | string): string
37
+ export function parse(color: string): Color | undefined
38
+ export function converter(mode: string): (color: Color) => Color
39
+ /** A registered colour space's definition, or `undefined` for one not registered. */
40
+ export function getMode(mode: string): Mode | undefined
41
+ /** Register a colour space (its parsers, its conversions): a converter to it. */
42
+ export function useMode(mode: Mode): (color: Color) => Color
43
+
44
+ export const modeA98: Mode
45
+ export const modeHsl: Mode
46
+ export const modeHwb: Mode
47
+ export const modeLab: Mode
48
+ export const modeLch: Mode
49
+ export const modeLrgb: Mode
50
+ export const modeOklab: Mode
51
+ export const modeOklch: Mode
52
+ export const modeP3: Mode
53
+ export const modeProphoto: Mode
54
+ export const modeRec2020: Mode
55
+ export const modeRgb: Mode
56
+ export const modeXyz50: Mode
57
+ export const modeXyz65: Mode
58
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The DOM Environment's Default transition (CONTEXT.md; ADR-0051, #357): Motion's, by value
3
+ * (`.reference/motion` at 16c6122, `motion-dom/src/animation/utils/default-transitions.ts`,
4
+ * `getDefaultTransition`):
5
+ * - a transform but a scale: a spring, 500 / 25, at rest under 10 px/s;
6
+ * - `scale`, `scaleX`, `scaleY`: a spring, 550, critically damped toward 0 (2·√550), else 30;
7
+ * - anything else (opacity, colours, a box's size, a filter): a 0.3 s tween on
8
+ * `cubic-bezier(0.25, 0.1, 0.35, 1)`, "a slightly shallower version of the browser's default ease".
9
+ *
10
+ * - more than two keyframes (#429): Motion's `keyframesTransition`, a 0.8 s tween, each Interval on
11
+ * `easeOut`, the `ease` Motion's `animateMotionValue` gives every value before its default.
12
+ *
13
+ * `DomLive` provides the Layer.
14
+ *
15
+ * @module
16
+ */
17
+ import * as DefaultTransition from "@wardic/core/DefaultTransition"
18
+ import * as ReducedMotion from "@wardic/core/ReducedMotion"
19
+ import * as Bool from "effect/Boolean"
20
+ import * as Layer from "effect/Layer"
21
+
22
+ /** A transform's but a scale's: Motion's `underDampedSpring`. */
23
+ const TRANSFORM: DefaultTransition.Transition = { type: "spring", stiffness: 500, damping: 25, restSpeed: 10 }
24
+
25
+ /** A scale's toward 0: Motion's `criticallyDampedSpring`, critically damped, so it doesn't overshoot past 0. */
26
+ const SCALE_TO_ZERO: DefaultTransition.Transition = { type: "spring", stiffness: 550, damping: 2 * Math.sqrt(550), restSpeed: 10 }
27
+
28
+ /** A scale's toward anything else: Motion's `criticallyDampedSpring`, with its damping of 30. */
29
+ const SCALE: DefaultTransition.Transition = { type: "spring", stiffness: 550, damping: 30, restSpeed: 10 }
30
+
31
+ /** Every other key's: Motion's `ease`. */
32
+ const EASE: DefaultTransition.Transition = { type: "tween", duration: 0.3, ease: [0.25, 0.1, 0.35, 1] }
33
+
34
+ /** The transition through more than two keyframes, as Motion's `keyframesTransition`: a 0.8 s tween, eased out. */
35
+ // #429: on its `animateMotionValue`'s `easeOut`.
36
+ export const keyframes: DefaultTransition.KeyframesTransition = { type: "tween", duration: 0.8, ease: "easeOut" }
37
+
38
+ /** A transform's: a scale's, by its target, or the rest's. */
39
+ const transformFor = (key: string, target: number | string): DefaultTransition.Transition =>
40
+ Bool.match(key.startsWith("scale"), {
41
+ onTrue: () => Bool.match(target === 0, { onTrue: () => SCALE_TO_ZERO, onFalse: () => SCALE }),
42
+ onFalse: () => TRANSFORM,
43
+ })
44
+
45
+ /** The transition `key` runs on toward `target` when its own isn't defined, in the DOM: Motion's. */
46
+ export const transitionFor = (key: string, target: number | string): DefaultTransition.Transition =>
47
+ Bool.match(ReducedMotion.isTransform(key), { onTrue: () => transformFor(key, target), onFalse: () => EASE })
48
+
49
+ /** The DOM Environment's `DefaultTransition.DefaultTransition`. */
50
+ export const DefaultTransitionDomLive: Layer.Layer<DefaultTransition.DefaultTransition> = Layer.succeed(DefaultTransition.DefaultTransition, { transitionFor, keyframes })
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The defaults every drag element gets (ADR-0019, *Amendment (Reorder)*, #36), as
3
+ * Motion's draggables do (render/html/use-props.ts:57-73 at
4
+ * 16c61222c4166bbef5ff6ab0051192faa79fa8c8,
5
+ * https://github.com/motiondivision/motion/blob/16c61222c4166bbef5ff6ab0051192faa79fa8c8/packages/framer-motion/src/render/html/use-props.ts#L57-L73):
6
+ * no browser panning on the drag's axes (`touch-action`), so a touch drag isn't taken
7
+ * for a scroll and cancelled; no text selection or iOS callout, so a second drag
8
+ * starting on text the first one selected isn't a native drag; and `draggable="false"`,
9
+ * so an image or link inside doesn't start one. The style maps are kebab-case, for
10
+ * Solid's style objects and the Renderer's `setProperty`. Motion writes them over the
11
+ * user's style; a binding layers them under it, so an app can override one.
12
+ */
13
+ import * as Match from "effect/Match"
14
+
15
+ /** A drag element's default style for its axis. */
16
+ export type DragDefaultStyle = Readonly<Record<string, string>>
17
+
18
+ const styleFor = (touchAction: string): DragDefaultStyle =>
19
+ Object.freeze({
20
+ "touch-action": touchAction,
21
+ "user-select": "none",
22
+ "-webkit-user-select": "none",
23
+ "-webkit-touch-callout": "none",
24
+ })
25
+
26
+ const FREE = styleFor("none")
27
+ // An axis-locked drag keeps the browser's panning on the other axis.
28
+ const X = styleFor("pan-y")
29
+ const Y = styleFor("pan-x")
30
+
31
+ /**
32
+ * The default style of a drag element: `touch-action` `none` for a free drag, `pan-y`
33
+ * for an `x` drag and `pan-x` for a `y` drag, with no text selection or iOS callout.
34
+ * One frozen object per axis.
35
+ */
36
+ export const dragDefaultStyle: (axis: boolean | "x" | "y") => DragDefaultStyle = Match.type<boolean | "x" | "y">().pipe(
37
+ Match.when("x", () => X),
38
+ Match.when("y", () => Y),
39
+ Match.orElse(() => FREE),
40
+ )
41
+
42
+ /**
43
+ * A Reorder group item's `touch-action` for the group's axis: a `y` list keeps sideways panning, an `x`
44
+ * row vertical panning, and a grid none.
45
+ */
46
+ // A **Reorder group**.
47
+ export const reorderTouchAction: (axis: "x" | "y" | "xy") => string = Match.type<"x" | "y" | "xy">().pipe(
48
+ Match.when("y", () => "pan-x"),
49
+ Match.when("x", () => "pan-y"),
50
+ Match.orElse(() => "none"),
51
+ )
52
+
53
+ /** The attribute every drag element gets: no native drag of the element or its content. */
54
+ export const DRAG_DEFAULT_ATTRIBUTES = Object.freeze({ draggable: "false" } as const)