@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.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +145 -0
- package/dist/Appear.d.ts +30 -0
- package/dist/Appear.d.ts.map +1 -0
- package/dist/Appear.js +31 -0
- package/dist/Appear.js.map +1 -0
- package/dist/Color.d.ts +14 -0
- package/dist/Color.d.ts.map +1 -0
- package/dist/Color.js +16 -0
- package/dist/Color.js.map +1 -0
- package/dist/DomAnnouncer.d.ts +13 -0
- package/dist/DomAnnouncer.d.ts.map +1 -0
- package/dist/DomAnnouncer.js +14 -0
- package/dist/DomAnnouncer.js.map +1 -0
- package/dist/DomBatch.d.ts +20 -0
- package/dist/DomBatch.d.ts.map +1 -0
- package/dist/DomBatch.js +23 -0
- package/dist/DomBatch.js.map +1 -0
- package/dist/DomClock.d.ts +11 -0
- package/dist/DomClock.d.ts.map +1 -0
- package/dist/DomClock.js +12 -0
- package/dist/DomClock.js.map +1 -0
- package/dist/DomDefaultTransition.d.ts +12 -0
- package/dist/DomDefaultTransition.d.ts.map +1 -0
- package/dist/DomDefaultTransition.js +13 -0
- package/dist/DomDefaultTransition.js.map +1 -0
- package/dist/DomInput.d.ts +14 -0
- package/dist/DomInput.d.ts.map +1 -0
- package/dist/DomInput.js +17 -0
- package/dist/DomInput.js.map +1 -0
- package/dist/DomInterpolators.d.ts +13 -0
- package/dist/DomInterpolators.d.ts.map +1 -0
- package/dist/DomInterpolators.js +14 -0
- package/dist/DomInterpolators.js.map +1 -0
- package/dist/DomKeyRules.d.ts +13 -0
- package/dist/DomKeyRules.d.ts.map +1 -0
- package/dist/DomKeyRules.js +14 -0
- package/dist/DomKeyRules.js.map +1 -0
- package/dist/DomPositionalKeys.d.ts +13 -0
- package/dist/DomPositionalKeys.d.ts.map +1 -0
- package/dist/DomPositionalKeys.js +14 -0
- package/dist/DomPositionalKeys.js.map +1 -0
- package/dist/DomProbe.d.ts +13 -0
- package/dist/DomProbe.d.ts.map +1 -0
- package/dist/DomProbe.js +14 -0
- package/dist/DomProbe.js.map +1 -0
- package/dist/DomProjectionSystem.d.ts +28 -0
- package/dist/DomProjectionSystem.d.ts.map +1 -0
- package/dist/DomProjectionSystem.js +41 -0
- package/dist/DomProjectionSystem.js.map +1 -0
- package/dist/DomRenderer.d.ts +13 -0
- package/dist/DomRenderer.d.ts.map +1 -0
- package/dist/DomRenderer.js +15 -0
- package/dist/DomRenderer.js.map +1 -0
- package/dist/DomScrollSource.d.ts +14 -0
- package/dist/DomScrollSource.d.ts.map +1 -0
- package/dist/DomScrollSource.js +15 -0
- package/dist/DomScrollSource.js.map +1 -0
- package/dist/FlushGate.d.ts +48 -0
- package/dist/FlushGate.d.ts.map +1 -0
- package/dist/FlushGate.js +62 -0
- package/dist/FlushGate.js.map +1 -0
- package/dist/KeyboardPress.d.ts +16 -0
- package/dist/KeyboardPress.d.ts.map +1 -0
- package/dist/KeyboardPress.js +17 -0
- package/dist/KeyboardPress.js.map +1 -0
- package/dist/MeasuredPair.d.ts +14 -0
- package/dist/MeasuredPair.d.ts.map +1 -0
- package/dist/MeasuredPair.js +16 -0
- package/dist/MeasuredPair.js.map +1 -0
- package/dist/OwnValues.d.ts +14 -0
- package/dist/OwnValues.d.ts.map +1 -0
- package/dist/OwnValues.js +15 -0
- package/dist/OwnValues.js.map +1 -0
- package/dist/ProjectionSystem.d.ts +34 -0
- package/dist/ProjectionSystem.d.ts.map +1 -0
- package/dist/ProjectionSystem.js +29 -0
- package/dist/ProjectionSystem.js.map +1 -0
- package/dist/ReorderController.d.ts +61 -0
- package/dist/ReorderController.d.ts.map +1 -0
- package/dist/ReorderController.js +78 -0
- package/dist/ReorderController.js.map +1 -0
- package/dist/Report.d.ts +12 -0
- package/dist/Report.d.ts.map +1 -0
- package/dist/Report.js +13 -0
- package/dist/Report.js.map +1 -0
- package/dist/ScrollOffset.d.ts +34 -0
- package/dist/ScrollOffset.d.ts.map +1 -0
- package/dist/ScrollOffset.js +42 -0
- package/dist/ScrollOffset.js.map +1 -0
- package/dist/Style.d.ts +15 -0
- package/dist/Style.d.ts.map +1 -0
- package/dist/Style.js +17 -0
- package/dist/Style.js.map +1 -0
- package/dist/Svg.d.ts +13 -0
- package/dist/Svg.d.ts.map +1 -0
- package/dist/Svg.js +14 -0
- package/dist/Svg.js.map +1 -0
- package/dist/Variables.d.ts +13 -0
- package/dist/Variables.d.ts.map +1 -0
- package/dist/Variables.js +14 -0
- package/dist/Variables.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/announcer.d.ts +50 -0
- package/dist/internal/announcer.d.ts.map +1 -0
- package/dist/internal/announcer.js +115 -0
- package/dist/internal/announcer.js.map +1 -0
- package/dist/internal/appear-slot.d.ts +23 -0
- package/dist/internal/appear-slot.d.ts.map +1 -0
- package/dist/internal/appear-slot.js +29 -0
- package/dist/internal/appear-slot.js.map +1 -0
- package/dist/internal/appear.d.ts +237 -0
- package/dist/internal/appear.d.ts.map +1 -0
- package/dist/internal/appear.js +740 -0
- package/dist/internal/appear.js.map +1 -0
- package/dist/internal/auto-scroll.d.ts +24 -0
- package/dist/internal/auto-scroll.d.ts.map +1 -0
- package/dist/internal/auto-scroll.js +124 -0
- package/dist/internal/auto-scroll.js.map +1 -0
- package/dist/internal/batch-writer.d.ts +16 -0
- package/dist/internal/batch-writer.d.ts.map +1 -0
- package/dist/internal/batch-writer.js +77 -0
- package/dist/internal/batch-writer.js.map +1 -0
- package/dist/internal/clock.d.ts +19 -0
- package/dist/internal/clock.d.ts.map +1 -0
- package/dist/internal/clock.js +39 -0
- package/dist/internal/clock.js.map +1 -0
- package/dist/internal/colors.d.ts +45 -0
- package/dist/internal/colors.d.ts.map +1 -0
- package/dist/internal/colors.js +193 -0
- package/dist/internal/colors.js.map +1 -0
- package/dist/internal/complex.d.ts +24 -0
- package/dist/internal/complex.d.ts.map +1 -0
- package/dist/internal/complex.js +28 -0
- package/dist/internal/complex.js.map +1 -0
- package/dist/internal/content-watch.d.ts +20 -0
- package/dist/internal/content-watch.d.ts.map +1 -0
- package/dist/internal/content-watch.js +76 -0
- package/dist/internal/content-watch.js.map +1 -0
- package/dist/internal/default-transition.d.ts +25 -0
- package/dist/internal/default-transition.d.ts.map +1 -0
- package/dist/internal/default-transition.js +41 -0
- package/dist/internal/default-transition.js.map +1 -0
- package/dist/internal/drag-defaults.d.ts +18 -0
- package/dist/internal/drag-defaults.d.ts.map +1 -0
- package/dist/internal/drag-defaults.js +38 -0
- package/dist/internal/drag-defaults.js.map +1 -0
- package/dist/internal/gate.d.ts +188 -0
- package/dist/internal/gate.d.ts.map +1 -0
- package/dist/internal/gate.js +458 -0
- package/dist/internal/gate.js.map +1 -0
- package/dist/internal/input.d.ts +35 -0
- package/dist/internal/input.d.ts.map +1 -0
- package/dist/internal/input.js +658 -0
- package/dist/internal/input.js.map +1 -0
- package/dist/internal/interpolators.d.ts +19 -0
- package/dist/internal/interpolators.d.ts.map +1 -0
- package/dist/internal/interpolators.js +30 -0
- package/dist/internal/interpolators.js.map +1 -0
- package/dist/internal/key-rules.d.ts +11 -0
- package/dist/internal/key-rules.d.ts.map +1 -0
- package/dist/internal/key-rules.js +244 -0
- package/dist/internal/key-rules.js.map +1 -0
- package/dist/internal/keyboard-press.d.ts +7 -0
- package/dist/internal/keyboard-press.d.ts.map +1 -0
- package/dist/internal/keyboard-press.js +45 -0
- package/dist/internal/keyboard-press.js.map +1 -0
- package/dist/internal/measure.d.ts +157 -0
- package/dist/internal/measure.d.ts.map +1 -0
- package/dist/internal/measure.js +296 -0
- package/dist/internal/measure.js.map +1 -0
- package/dist/internal/measured-pairs.d.ts +38 -0
- package/dist/internal/measured-pairs.d.ts.map +1 -0
- package/dist/internal/measured-pairs.js +251 -0
- package/dist/internal/measured-pairs.js.map +1 -0
- package/dist/internal/own-values.d.ts +35 -0
- package/dist/internal/own-values.d.ts.map +1 -0
- package/dist/internal/own-values.js +117 -0
- package/dist/internal/own-values.js.map +1 -0
- package/dist/internal/pass-ends.d.ts +21 -0
- package/dist/internal/pass-ends.d.ts.map +1 -0
- package/dist/internal/pass-ends.js +14 -0
- package/dist/internal/pass-ends.js.map +1 -0
- package/dist/internal/positional-keys.d.ts +16 -0
- package/dist/internal/positional-keys.d.ts.map +1 -0
- package/dist/internal/positional-keys.js +21 -0
- package/dist/internal/positional-keys.js.map +1 -0
- package/dist/internal/probe.d.ts +10 -0
- package/dist/internal/probe.d.ts.map +1 -0
- package/dist/internal/probe.js +116 -0
- package/dist/internal/probe.js.map +1 -0
- package/dist/internal/projection-defaults.d.ts +34 -0
- package/dist/internal/projection-defaults.d.ts.map +1 -0
- package/dist/internal/projection-defaults.js +21 -0
- package/dist/internal/projection-defaults.js.map +1 -0
- package/dist/internal/projection.d.ts +537 -0
- package/dist/internal/projection.d.ts.map +1 -0
- package/dist/internal/projection.js +5228 -0
- package/dist/internal/projection.js.map +1 -0
- package/dist/internal/renderer.d.ts +104 -0
- package/dist/internal/renderer.d.ts.map +1 -0
- package/dist/internal/renderer.js +618 -0
- package/dist/internal/renderer.js.map +1 -0
- package/dist/internal/reorder.d.ts +174 -0
- package/dist/internal/reorder.d.ts.map +1 -0
- package/dist/internal/reorder.js +466 -0
- package/dist/internal/reorder.js.map +1 -0
- package/dist/internal/report.d.ts +30 -0
- package/dist/internal/report.d.ts.map +1 -0
- package/dist/internal/report.js +60 -0
- package/dist/internal/report.js.map +1 -0
- package/dist/internal/require-global.d.ts +11 -0
- package/dist/internal/require-global.d.ts.map +1 -0
- package/dist/internal/require-global.js +31 -0
- package/dist/internal/require-global.js.map +1 -0
- package/dist/internal/reveal.d.ts +20 -0
- package/dist/internal/reveal.d.ts.map +1 -0
- package/dist/internal/reveal.js +71 -0
- package/dist/internal/reveal.js.map +1 -0
- package/dist/internal/runner.d.ts +21 -0
- package/dist/internal/runner.d.ts.map +1 -0
- package/dist/internal/runner.js +48 -0
- package/dist/internal/runner.js.map +1 -0
- package/dist/internal/scale-correction.d.ts +80 -0
- package/dist/internal/scale-correction.d.ts.map +1 -0
- package/dist/internal/scale-correction.js +227 -0
- package/dist/internal/scale-correction.js.map +1 -0
- package/dist/internal/scroll.d.ts +37 -0
- package/dist/internal/scroll.d.ts.map +1 -0
- package/dist/internal/scroll.js +279 -0
- package/dist/internal/scroll.js.map +1 -0
- package/dist/internal/scrollers.d.ts +35 -0
- package/dist/internal/scrollers.d.ts.map +1 -0
- package/dist/internal/scrollers.js +38 -0
- package/dist/internal/scrollers.js.map +1 -0
- package/dist/internal/starting-style.d.ts +141 -0
- package/dist/internal/starting-style.d.ts.map +1 -0
- package/dist/internal/starting-style.js +300 -0
- package/dist/internal/starting-style.js.map +1 -0
- package/dist/internal/svg.d.ts +60 -0
- package/dist/internal/svg.d.ts.map +1 -0
- package/dist/internal/svg.js +257 -0
- package/dist/internal/svg.js.map +1 -0
- package/dist/internal/variables.d.ts +45 -0
- package/dist/internal/variables.d.ts.map +1 -0
- package/dist/internal/variables.js +92 -0
- package/dist/internal/variables.js.map +1 -0
- package/package.json +65 -4
- package/src/Appear.ts +54 -0
- package/src/Color.ts +24 -0
- package/src/DomAnnouncer.ts +22 -0
- package/src/DomBatch.ts +22 -0
- package/src/DomClock.ts +13 -0
- package/src/DomDefaultTransition.ts +16 -0
- package/src/DomInput.ts +23 -0
- package/src/DomInterpolators.ts +16 -0
- package/src/DomKeyRules.ts +17 -0
- package/src/DomPositionalKeys.ts +16 -0
- package/src/DomProbe.ts +15 -0
- package/src/DomProjectionSystem.ts +44 -0
- package/src/DomRenderer.ts +26 -0
- package/src/DomScrollSource.ts +14 -0
- package/src/FlushGate.ts +81 -0
- package/src/KeyboardPress.ts +16 -0
- package/src/MeasuredPair.ts +15 -0
- package/src/OwnValues.ts +19 -0
- package/src/ProjectionSystem.ts +51 -0
- package/src/ReorderController.ts +122 -0
- package/src/Report.ts +17 -0
- package/src/ScrollOffset.ts +54 -0
- package/src/Style.ts +37 -0
- package/src/Svg.ts +21 -0
- package/src/Variables.ts +17 -0
- package/src/index.ts +120 -0
- package/src/internal/announcer.ts +132 -0
- package/src/internal/appear-slot.ts +32 -0
- package/src/internal/appear.ts +1134 -0
- package/src/internal/auto-scroll.ts +176 -0
- package/src/internal/batch-writer.ts +95 -0
- package/src/internal/clock.ts +45 -0
- package/src/internal/colors.ts +258 -0
- package/src/internal/complex.ts +29 -0
- package/src/internal/content-watch.ts +84 -0
- package/src/internal/culori.d.ts +58 -0
- package/src/internal/default-transition.ts +50 -0
- package/src/internal/drag-defaults.ts +54 -0
- package/src/internal/gate.ts +598 -0
- package/src/internal/input.ts +763 -0
- package/src/internal/interpolators.ts +33 -0
- package/src/internal/key-rules.ts +357 -0
- package/src/internal/keyboard-press.ts +45 -0
- package/src/internal/measure.ts +373 -0
- package/src/internal/measured-pairs.ts +297 -0
- package/src/internal/own-values.ts +166 -0
- package/src/internal/pass-ends.ts +23 -0
- package/src/internal/positional-keys.ts +24 -0
- package/src/internal/probe.ts +175 -0
- package/src/internal/projection-defaults.ts +45 -0
- package/src/internal/projection.ts +6233 -0
- package/src/internal/renderer.ts +648 -0
- package/src/internal/reorder.ts +650 -0
- package/src/internal/report.ts +69 -0
- package/src/internal/require-global.ts +46 -0
- package/src/internal/reveal.ts +75 -0
- package/src/internal/runner.ts +64 -0
- package/src/internal/scale-correction.ts +310 -0
- package/src/internal/scroll.ts +358 -0
- package/src/internal/scrollers.ts +51 -0
- package/src/internal/starting-style.ts +396 -0
- package/src/internal/svg.ts +300 -0
- 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)
|