@wardic/dom 0.0.0-stage → 1.0.0-rc.2
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 +24 -0
- package/dist/Appear.d.ts.map +1 -0
- package/dist/Appear.js +25 -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/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 +13 -0
- package/dist/DomInput.d.ts.map +1 -0
- package/dist/DomInput.js +15 -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/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/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 +41 -0
- package/dist/ReorderController.d.ts.map +1 -0
- package/dist/ReorderController.js +44 -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 +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -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.d.ts +169 -0
- package/dist/internal/appear.d.ts.map +1 -0
- package/dist/internal/appear.js +499 -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/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 +186 -0
- package/dist/internal/gate.d.ts.map +1 -0
- package/dist/internal/gate.js +453 -0
- package/dist/internal/gate.js.map +1 -0
- package/dist/internal/input.d.ts +41 -0
- package/dist/internal/input.d.ts.map +1 -0
- package/dist/internal/input.js +476 -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/measure.d.ts +150 -0
- package/dist/internal/measure.d.ts.map +1 -0
- package/dist/internal/measure.js +278 -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 +117 -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 +529 -0
- package/dist/internal/projection.d.ts.map +1 -0
- package/dist/internal/projection.js +4990 -0
- package/dist/internal/projection.js.map +1 -0
- package/dist/internal/renderer.d.ts +86 -0
- package/dist/internal/renderer.d.ts.map +1 -0
- package/dist/internal/renderer.js +616 -0
- package/dist/internal/renderer.js.map +1 -0
- package/dist/internal/reorder.d.ts +159 -0
- package/dist/internal/reorder.d.ts.map +1 -0
- package/dist/internal/reorder.js +437 -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 +16 -0
- package/dist/internal/reveal.d.ts.map +1 -0
- package/dist/internal/reveal.js +66 -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 +35 -0
- package/dist/internal/scroll.d.ts.map +1 -0
- package/dist/internal/scroll.js +244 -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 +45 -0
- package/src/Color.ts +24 -0
- package/src/DomAnnouncer.ts +22 -0
- package/src/DomClock.ts +13 -0
- package/src/DomDefaultTransition.ts +16 -0
- package/src/DomInput.ts +22 -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/FlushGate.ts +81 -0
- package/src/MeasuredPair.ts +15 -0
- package/src/OwnValues.ts +19 -0
- package/src/ProjectionSystem.ts +51 -0
- package/src/ReorderController.ts +72 -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 +106 -0
- package/src/internal/announcer.ts +132 -0
- package/src/internal/appear.ts +739 -0
- package/src/internal/auto-scroll.ts +176 -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 +593 -0
- package/src/internal/input.ts +579 -0
- package/src/internal/interpolators.ts +33 -0
- package/src/internal/key-rules.ts +357 -0
- package/src/internal/measure.ts +357 -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 +176 -0
- package/src/internal/projection-defaults.ts +45 -0
- package/src/internal/projection.ts +5999 -0
- package/src/internal/renderer.ts +646 -0
- package/src/internal/reorder.ts +604 -0
- package/src/internal/report.ts +69 -0
- package/src/internal/require-global.ts +46 -0
- package/src/internal/reveal.ts +69 -0
- package/src/internal/runner.ts +64 -0
- package/src/internal/scale-correction.ts +310 -0
- package/src/internal/scroll.ts +356 -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,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM's **Auto-scroll** (ADR-0020, grill decision 16): Motion's
|
|
3
|
+
* (Reorder/utils/auto-scroll.ts at 16c61222c4166bbef5ff6ab0051192faa79fa8c8,
|
|
4
|
+
* https://github.com/motiondivision/motion/blob/16c61222c4166bbef5ff6ab0051192faa79fa8c8/packages/framer-motion/src/components/Reorder/utils/auto-scroll.ts)
|
|
5
|
+
* over core's pure `AutoScroll.step`. While a **Reorder group**'s item is dragged near
|
|
6
|
+
* the visible edge of the group's scroller, moving toward it, each drag update scrolls
|
|
7
|
+
* the scroller; the scroll then moves the held pointer (a synthetic move), whose update
|
|
8
|
+
* scrolls again, so it keeps scrolling while the pointer holds still in the zone.
|
|
9
|
+
*/
|
|
10
|
+
import * as AutoScroll from "@wardic/core/AutoScroll";
|
|
11
|
+
import * as Arr from "effect/Array";
|
|
12
|
+
import * as Bool from "effect/Boolean";
|
|
13
|
+
import * as Equal from "effect/Equal";
|
|
14
|
+
import { constVoid } from "effect/Function";
|
|
15
|
+
import * as Match from "effect/Match";
|
|
16
|
+
import * as Option from "effect/Option";
|
|
17
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
18
|
+
import { heldScrollShift } from "./input.js";
|
|
19
|
+
/** The overflow values Motion's auto-scroll scrolls (auto-scroll.ts:4). */
|
|
20
|
+
const SCROLLS = new Set(["auto", "scroll"]);
|
|
21
|
+
const ZERO = { x: 0, y: 0 };
|
|
22
|
+
/**
|
|
23
|
+
* The nearest ancestor of `group` that scrolls on `axis` (`overflow` `auto | scroll`),
|
|
24
|
+
* or the document once the walk reaches `body` (Motion's `findScrollableAncestor`).
|
|
25
|
+
*/
|
|
26
|
+
const findScroller = (group, axis) => {
|
|
27
|
+
const doc = group.ownerDocument;
|
|
28
|
+
const from = (cur) => Option.flatMap(Option.fromNullOr(cur), (el) => Bool.match(el === doc.body || el === doc.documentElement, {
|
|
29
|
+
onTrue: () => Option.map(Option.fromNullOr(doc.defaultView), (win) => ({ kind: "document", win })),
|
|
30
|
+
onFalse: () => {
|
|
31
|
+
const style = getComputedStyle(el);
|
|
32
|
+
return Bool.match(SCROLLS.has({ x: style.overflowX, y: style.overflowY }[axis]), {
|
|
33
|
+
onTrue: () => Option.some({ kind: "element", el }),
|
|
34
|
+
onFalse: () => from(el.parentElement),
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
return from(group.parentElement);
|
|
39
|
+
};
|
|
40
|
+
/** `scroller`'s extent on `axis`: an element's visible edges are clamped to the viewport, as Motion's `getScrollAmount`. */
|
|
41
|
+
const viewOf = (scroller, axis) => Match.value(scroller).pipe(Match.when({ kind: "document" }, ({ win }) => {
|
|
42
|
+
const root = win.document.documentElement;
|
|
43
|
+
return {
|
|
44
|
+
start: 0,
|
|
45
|
+
end: { x: win.innerWidth, y: win.innerHeight }[axis],
|
|
46
|
+
scroll: { x: win.scrollX, y: win.scrollY }[axis],
|
|
47
|
+
maxScroll: { x: () => root.scrollWidth - win.innerWidth, y: () => root.scrollHeight - win.innerHeight }[axis],
|
|
48
|
+
};
|
|
49
|
+
}), Match.when({ kind: "element" }, ({ el }) => {
|
|
50
|
+
const rect = el.getBoundingClientRect();
|
|
51
|
+
const win = Option.fromNullOr(el.ownerDocument.defaultView);
|
|
52
|
+
const viewport = {
|
|
53
|
+
x: Option.match(win, { onNone: () => rect.right, onSome: (w) => w.innerWidth }),
|
|
54
|
+
y: Option.match(win, { onNone: () => rect.bottom, onSome: (w) => w.innerHeight }),
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
start: Math.max(0, { x: rect.left, y: rect.top }[axis]),
|
|
58
|
+
end: Math.min(viewport[axis], { x: rect.right, y: rect.bottom }[axis]),
|
|
59
|
+
scroll: { x: el.scrollLeft, y: el.scrollTop }[axis],
|
|
60
|
+
maxScroll: { x: () => el.scrollWidth - el.clientWidth, y: () => el.scrollHeight - el.clientHeight }[axis],
|
|
61
|
+
};
|
|
62
|
+
}), Match.exhaustive);
|
|
63
|
+
/** Scroll `scroller` by `amount` on `axis`. */
|
|
64
|
+
const scrollBy = (scroller, axis, amount) => Match.value(scroller).pipe(Match.when({ kind: "document" }, ({ win }) => win.scrollBy({ x: { left: amount }, y: { top: amount } }[axis])), Match.when({ kind: "element" }, ({ el }) => Match.value(axis).pipe(Match.when("x", () => {
|
|
65
|
+
el.scrollLeft += amount;
|
|
66
|
+
}), Match.orElse(() => {
|
|
67
|
+
el.scrollTop += amount;
|
|
68
|
+
}))), Match.exhaustive);
|
|
69
|
+
const edgeOf = (state) => state.edge;
|
|
70
|
+
/**
|
|
71
|
+
* Build the **Auto-scroll** for `group` (the Reorder group's element). The scroller on
|
|
72
|
+
* each axis is found once per gesture, at its first update. Each update reads the
|
|
73
|
+
* scroller's visible edges (clamped to the viewport, as Motion's `getScrollAmount`), runs
|
|
74
|
+
* core's `AutoScroll.step`, and scrolls by its amount. `debug` receives `auto-scroll
|
|
75
|
+
* start` and `auto-scroll stop` { axis, edge } when an edge starts and ends scrolling.
|
|
76
|
+
*/
|
|
77
|
+
export const makeAutoScroller = (group, debug) => {
|
|
78
|
+
const log = UndefinedOr.match(debug, { onUndefined: () => constVoid, onDefined: (d) => d });
|
|
79
|
+
// Each axis's scroller, found at the gesture's first update (`None` when there is none).
|
|
80
|
+
const scrollers = new Map();
|
|
81
|
+
const states = new Map();
|
|
82
|
+
const setState = (axis, next) => {
|
|
83
|
+
const prev = Option.fromUndefinedOr(states.get(axis));
|
|
84
|
+
const edgeChanged = Bool.not(Equal.equals(Option.map(prev, edgeOf), Option.map(next, edgeOf)));
|
|
85
|
+
if (edgeChanged && Option.isSome(prev))
|
|
86
|
+
log("auto-scroll stop", { axis, edge: prev.value.edge });
|
|
87
|
+
Option.match(next, {
|
|
88
|
+
onNone: () => states.delete(axis),
|
|
89
|
+
onSome: (state) => states.set(axis, state),
|
|
90
|
+
});
|
|
91
|
+
if (edgeChanged && Option.isSome(next))
|
|
92
|
+
log("auto-scroll start", { axis, edge: next.value.edge });
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
update: (pointer, axis, velocity, item) => {
|
|
96
|
+
const scroller = Option.getOrElse(Option.fromUndefinedOr(scrollers.get(axis)), () => {
|
|
97
|
+
const found = findScroller(group, axis);
|
|
98
|
+
scrollers.set(axis, found);
|
|
99
|
+
return found;
|
|
100
|
+
});
|
|
101
|
+
if (Option.isNone(scroller))
|
|
102
|
+
return;
|
|
103
|
+
const shift = UndefinedOr.match(item, { onUndefined: () => ZERO, onDefined: heldScrollShift });
|
|
104
|
+
const view = viewOf(scroller.value, axis);
|
|
105
|
+
const step = AutoScroll.step(Option.fromUndefinedOr(states.get(axis)), {
|
|
106
|
+
pointer: pointer[axis] - shift[axis],
|
|
107
|
+
start: view.start,
|
|
108
|
+
end: view.end,
|
|
109
|
+
velocity,
|
|
110
|
+
scroll: view.scroll,
|
|
111
|
+
maxScroll: view.maxScroll,
|
|
112
|
+
});
|
|
113
|
+
setState(axis, step.state);
|
|
114
|
+
if (step.amount === 0)
|
|
115
|
+
return;
|
|
116
|
+
scrollBy(scroller.value, axis, step.amount);
|
|
117
|
+
},
|
|
118
|
+
reset: () => {
|
|
119
|
+
Arr.forEach(Arr.fromIterable(states.keys()), (axis) => setState(axis, Option.none()));
|
|
120
|
+
scrollers.clear();
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=auto-scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-scroll.js","sourceRoot":"","sources":["../../src/internal/auto-scroll.ts"],"names":[],"mappings":"AAAA;;;;;;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I,CAAC,MAAM,CAAC,CAAA;QAC7C,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;YACrF,SAAS,CAAC,KAAK,EAAE,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ClockDomLive` — the browser realization of `Clock` and of the Environment's
|
|
3
|
+
* `RefreshFrameSource` (ADR-0031): `requestAnimationFrame`, whose callbacks are the browser's
|
|
4
|
+
* Refresh frames, as the member, and core's shared `Clock.layer` built from it. The flush gate
|
|
5
|
+
* requests its flushes from the same member, so the Clock and the gate share the browser's
|
|
6
|
+
* frames. Everything else — the ref-counted Refresh frame loop, the `dt` computation and the
|
|
7
|
+
* `wardic.clock` span — lives in core, so every Environment's Clock behaves the same (ADR-0004).
|
|
8
|
+
*/
|
|
9
|
+
import * as Clock from "@wardic/core/Clock";
|
|
10
|
+
import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource";
|
|
11
|
+
import * as Layer from "effect/Layer";
|
|
12
|
+
/**
|
|
13
|
+
* Core's `Clock` and the Environment's `RefreshFrameSource`, from one `requestAnimationFrame`, needing
|
|
14
|
+
* nothing: the frame loop runs in the Layer's own scope. It reads `requestAnimationFrame` when the Layer
|
|
15
|
+
* is built, not when `@wardic/dom` is imported, so a test that stubs it first drives this Clock. Building
|
|
16
|
+
* it on a server fails, with an error that says it's client-only.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ClockDomLive: Layer.Layer<Clock.Clock | RefreshFrameSource.RefreshFrameSource>;
|
|
19
|
+
//# sourceMappingURL=clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/internal/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,kBAAkB,MAAM,iCAAiC,CAAA;AAErE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAwBrC;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,kBAAkB,CAAC,kBAAkB,CAEzF,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ClockDomLive` — the browser realization of `Clock` and of the Environment's
|
|
3
|
+
* `RefreshFrameSource` (ADR-0031): `requestAnimationFrame`, whose callbacks are the browser's
|
|
4
|
+
* Refresh frames, as the member, and core's shared `Clock.layer` built from it. The flush gate
|
|
5
|
+
* requests its flushes from the same member, so the Clock and the gate share the browser's
|
|
6
|
+
* frames. Everything else — the ref-counted Refresh frame loop, the `dt` computation and the
|
|
7
|
+
* `wardic.clock` span — lives in core, so every Environment's Clock behaves the same (ADR-0004).
|
|
8
|
+
*/
|
|
9
|
+
import * as Clock from "@wardic/core/Clock";
|
|
10
|
+
import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import * as Layer from "effect/Layer";
|
|
13
|
+
import * as Predicate from "effect/Predicate";
|
|
14
|
+
import { requireGlobal } from "./require-global.js";
|
|
15
|
+
/**
|
|
16
|
+
* The browser's Refresh frames: `requestAnimationFrame` itself, so the Clock and the gate make
|
|
17
|
+
* the browser's own calls, in the order they make them (ADR-0031, decision 7). `cancelFrame`
|
|
18
|
+
* wraps `cancelAnimationFrame` for the member's `unknown` handle; it runs only on a cancel. Both
|
|
19
|
+
* are read when the Layer builds, after the client-only check.
|
|
20
|
+
*/
|
|
21
|
+
const frames = Layer.effect(RefreshFrameSource.RefreshFrameSource)(requireGlobal("DomClock.layer", "requestAnimationFrame").pipe(Effect.map(() => {
|
|
22
|
+
const cancel = cancelAnimationFrame;
|
|
23
|
+
return {
|
|
24
|
+
requestFrame: requestAnimationFrame,
|
|
25
|
+
cancelFrame: (handle) => {
|
|
26
|
+
if (Predicate.isNumber(handle))
|
|
27
|
+
cancel(handle);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
})));
|
|
31
|
+
/**
|
|
32
|
+
* Core's `Clock` and the Environment's `RefreshFrameSource`, from one `requestAnimationFrame`, needing
|
|
33
|
+
* nothing: the frame loop runs in the Layer's own scope. It reads `requestAnimationFrame` when the Layer
|
|
34
|
+
* is built, not when `@wardic/dom` is imported, so a test that stubs it first drives this Clock. Building
|
|
35
|
+
* it on a server fails, with an error that says it's client-only.
|
|
36
|
+
*/
|
|
37
|
+
// ADR-0021, decision 7: the client-only error.
|
|
38
|
+
export const ClockDomLive = Clock.layer.pipe(Layer.provideMerge(frames));
|
|
39
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/internal/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,kBAAkB,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,GAAuD,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CACpH,aAAa,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,GAAG,CAAC,GAA6B,EAAE;IACxC,MAAM,MAAM,GAAG,oBAAoB,CAAA;IACnC,OAAO;QACL,YAAY,EAAE,qBAAqB;QACnC,WAAW,EAAE,CAAC,MAAe,EAAE,EAAE;YAC/B,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAChD,CAAC;KACF,CAAA;AACH,CAAC,CAAC,CACH,CACF,CAAA;AAED;;;;;GAKG;AACH,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAqE,KAAK,CAAC,KAAK,CAAC,IAAI,CAC5G,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAC3B,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type * as Interpolator from "@wardic/core/Interpolator";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
/** A colour as culori holds it: its colour space (`mode`) and its channels. */
|
|
4
|
+
export type Color = {
|
|
5
|
+
readonly mode: string;
|
|
6
|
+
readonly [channel: string]: number | string | undefined;
|
|
7
|
+
};
|
|
8
|
+
/** A colour string read: a culori colour, or `None` for any other value. A string is a colour when culori reads it, trimmed. */
|
|
9
|
+
export declare const parseColor: (value: unknown) => Option.Option<Color>;
|
|
10
|
+
/**
|
|
11
|
+
* A colour written as `rgb(…)` or `rgba(…)`, as culori's `formatRgb` writes it, so `"#fff"` reads and
|
|
12
|
+
* writes back as `"rgb(255, 255, 255)"`: what a blend's every frame writes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const formatColor: (color: Color) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Registers every CSS colour space beyond sRGB's syntaxes: `lab()`, `lch()`, `oklab()`, `oklch()`,
|
|
17
|
+
* `hwb()`, and `color()`'s `display-p3`, `rec2020`, `a98-rgb`, `prophoto-rgb`, `srgb-linear`, `xyz`,
|
|
18
|
+
* `xyz-d50` and `xyz-d65`. From then on such a string is a colour everywhere on the page; before, it
|
|
19
|
+
* isn't one, and a `lab()` value's numbers blend as written. Calling it again does nothing new.
|
|
20
|
+
*/
|
|
21
|
+
export declare const registerSpaces: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the spaces `registerSpaces` registers are registered on the page: by it, or by culori's own
|
|
24
|
+
* bundle, which registers every space as it loads.
|
|
25
|
+
*/
|
|
26
|
+
export declare const spacesRegistered: () => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Blends colours in the colour space `mode`: `"rgb"` by default, sRGB, as the browser's own animations
|
|
29
|
+
* blend. `"oklch"` or `"lab"` blend perceptually, once `registerSpaces` has registered them. A string is
|
|
30
|
+
* a colour when culori reads it, trimmed, so a keyword like `"auto"` isn't, and named colours and the
|
|
31
|
+
* modern forms culori knows are. Past the end of a blend a colour holds at its target.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* Color.registerSpaces()
|
|
35
|
+
* yield* registry.register(Color.interpolator("oklch")) // colours now blend in OKLCH
|
|
36
|
+
*/
|
|
37
|
+
export declare const color: (mode?: string) => Interpolator.Entry<Color, string>;
|
|
38
|
+
/**
|
|
39
|
+
* A colour inside a longer value: a hex, or an `rgb()`, `rgba()`, `hsl()` or `hsla()`, as Motion's colour
|
|
40
|
+
* token is. A named colour, `red`, isn't one: it stays part of the text around the tokens.
|
|
41
|
+
*/
|
|
42
|
+
export declare const COLOR_TOKEN: RegExp;
|
|
43
|
+
/** The DOM's colours: CSS's colour syntax, blended in sRGB, as the browser's own animations blend. Its registry's colour kind. */
|
|
44
|
+
export declare const cssColor: Interpolator.Entry<Color, string>;
|
|
45
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/internal/colors.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,KAAK,YAAY,MAAM,2BAA2B,CAAA;AAK9D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAKvC,+EAA+E;AAE/E,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAgBtG,gIAAgI;AAGhI,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAG9D,CAAA;AAED;;;GAGG;AAEH,eAAO,MAAM,WAAW,UAAW,KAAK,KAAG,MAA0B,CAAA;AAmBrE;;;;;GAKG;AAGH,eAAO,MAAM,cAAc,QAAO,IAIjC,CAAA;AAED;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,QAAO,OAAqD,CAAA;AAsGzF;;;;;;;;;GASG;AAQH,eAAO,MAAM,KAAK,qBAAmB,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAWnE,CAAA;AAEF;;;GAGG;AAEH,eAAO,MAAM,WAAW,QAAgH,CAAA;AAExI,kIAAkI;AAElI,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAgB,CAAA"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM Environment's colours (ADR-0036; ADR-0026 for the Interpolator's shape): CSS Color syntax,
|
|
3
|
+
* parsed through culori, and blended in sRGB by Wardic's own lerp and format, which write culori's
|
|
4
|
+
* strings (ADR-0026 *Amendment (#156)*). Core names no colour syntax; `@wardic/dom` registers its
|
|
5
|
+
* colour Interpolator in its registry (`interpolators.ts`) and names a colour inside a complex value
|
|
6
|
+
* as a kind of token (`COLOR_TOKEN`, #61).
|
|
7
|
+
*
|
|
8
|
+
* Read through `culori/fn`, which registers no colour space by itself (#511, ADR-0067 decision 5):
|
|
9
|
+
* sRGB's syntaxes, a hex, `rgb()`, `hsl()` and the colour names, are registered here, and every other
|
|
10
|
+
* CSS colour space (`oklch()`, `lab()`, `color(display-p3 …)`, `hwb()` …) by {@link registerSpaces},
|
|
11
|
+
* which the bindings' `colors` Feature calls. culori keeps its spaces in one registry for the page, so
|
|
12
|
+
* a space registered once is read everywhere from then on.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/// <reference path="./culori.d.ts" />
|
|
17
|
+
import { formatRgb, getMode, interpolate as culoriInterpolate, modeA98, modeHsl, modeHwb, modeLab, modeLch, modeLrgb, modeOklab, modeOklch, modeP3, modeProphoto, modeRec2020, modeRgb, modeXyz50, modeXyz65, parse as culoriParse, useMode, } from "culori/fn";
|
|
18
|
+
import * as Scalar from "@wardic/core/Scalar";
|
|
19
|
+
import * as Arr from "effect/Array";
|
|
20
|
+
import * as Bool from "effect/Boolean";
|
|
21
|
+
import { identity } from "effect/Function";
|
|
22
|
+
import * as Option from "effect/Option";
|
|
23
|
+
import * as Predicate from "effect/Predicate";
|
|
24
|
+
import * as Str from "effect/String";
|
|
25
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
26
|
+
/** A culori colour: an object tagged with its colour space. */
|
|
27
|
+
const isColor = (value) => Predicate.hasProperty(value, "mode");
|
|
28
|
+
/**
|
|
29
|
+
* culori's `parse`, with a throw read as no colour. It throws on a CSS function holding a length,
|
|
30
|
+
* `blur(4px)`, `inset(10px)`, `drop-shadow(0px 0px 4px red)`, and the throw escaped the colour's
|
|
31
|
+
* decode at `resolve`, so the leg failed (#154).
|
|
32
|
+
*/
|
|
33
|
+
const culoriParseOption = Option.liftThrowable(culoriParse);
|
|
34
|
+
/** Parse a colour string, trimmed, or `None` when culori rejects it (`"auto"`, `"#zzz"`) or throws on it (`"blur(4px)"`). */
|
|
35
|
+
const parseColorString = (input) => Option.filter(Option.flatMap(culoriParseOption(Str.trim(input)), Option.fromUndefinedOr), isColor);
|
|
36
|
+
/** A colour string read: a culori colour, or `None` for any other value. A string is a colour when culori reads it, trimmed. */
|
|
37
|
+
// ADR-0026; CONTEXT.md's "color string". `Color.parse`, and the colour Interpolator's `parse` (plain
|
|
38
|
+
// functions since #511, where they were a Schema codec, `ColorString`).
|
|
39
|
+
export const parseColor = (value) => {
|
|
40
|
+
if (!Predicate.isString(value))
|
|
41
|
+
return Option.none();
|
|
42
|
+
return parseColorString(value);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A colour written as `rgb(…)` or `rgba(…)`, as culori's `formatRgb` writes it, so `"#fff"` reads and
|
|
46
|
+
* writes back as `"rgb(255, 255, 255)"`: what a blend's every frame writes.
|
|
47
|
+
*/
|
|
48
|
+
// `Color.format`, and the colour Interpolator's `format`.
|
|
49
|
+
export const formatColor = (color) => formatRgb(color);
|
|
50
|
+
// --- sRGB, Wardic's own (#156, ADR-0026 *Amendment (#156)*) ------------------------------------
|
|
51
|
+
//
|
|
52
|
+
// culori's `formatRgb(interpolate([from, to], "rgb")(t))`, string for string, without a colour
|
|
53
|
+
// object per frame. Its path, at culori 4.0.2: `t` clamped to [0, 1]; at `t <= 0` the start as
|
|
54
|
+
// converted; a channel one end lacks (CSS `none`) takes the other end's; an alpha one end lacks is
|
|
55
|
+
// 1 when the other has one (`fixupAlpha`); each channel lerped `a + t * (b - a)` (`Scalar.lerp`'s
|
|
56
|
+
// `a + (b - a) * t`, the same bits: multiplication commutes); then each channel byte is
|
|
57
|
+
// `round(clamp(v || 0) * 255)`, and `rgb()` is written when alpha is absent or exactly 1, else
|
|
58
|
+
// `rgba()` with alpha clamped and rounded to two places, so 0.999 writes `rgba(…, 1)`. A seeded
|
|
59
|
+
// differential test against culori pins it (`colors.node.test.ts`).
|
|
60
|
+
// sRGB's syntaxes, read by every app (#511): `rgb`'s parsers take a hex, `rgb()` and `rgba()`, the
|
|
61
|
+
// colour names and `transparent`; `hsl`'s take `hsl()` and `hsla()`. Registered once, when this module
|
|
62
|
+
// loads, as culori's own bundle registers its spaces.
|
|
63
|
+
const toRgb = useMode(modeRgb);
|
|
64
|
+
useMode(modeHsl);
|
|
65
|
+
/**
|
|
66
|
+
* Registers every CSS colour space beyond sRGB's syntaxes: `lab()`, `lch()`, `oklab()`, `oklch()`,
|
|
67
|
+
* `hwb()`, and `color()`'s `display-p3`, `rec2020`, `a98-rgb`, `prophoto-rgb`, `srgb-linear`, `xyz`,
|
|
68
|
+
* `xyz-d50` and `xyz-d65`. From then on such a string is a colour everywhere on the page; before, it
|
|
69
|
+
* isn't one, and a `lab()` value's numbers blend as written. Calling it again does nothing new.
|
|
70
|
+
*/
|
|
71
|
+
// #511, ADR-0067 decision 5: the spaces culori's `culori/css` registers but for its non-CSS `hsv`, `lab65`
|
|
72
|
+
// and `lch65`. The `colors` Feature's.
|
|
73
|
+
export const registerSpaces = () => {
|
|
74
|
+
Arr.forEach(CSS_SPACES, (mode) => {
|
|
75
|
+
useMode(mode);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Whether the spaces `registerSpaces` registers are registered on the page: by it, or by culori's own
|
|
80
|
+
* bundle, which registers every space as it loads.
|
|
81
|
+
*/
|
|
82
|
+
// Asked of culori's registry, the page's.
|
|
83
|
+
export const spacesRegistered = () => Predicate.isNotUndefined(getMode("oklch"));
|
|
84
|
+
const CSS_SPACES = [modeA98, modeHwb, modeLab, modeLch, modeLrgb, modeOklab, modeOklch, modeP3, modeProphoto, modeRec2020, modeXyz50, modeXyz65];
|
|
85
|
+
/**
|
|
86
|
+
* One channel of a pair, as culori's piecewise interpolator reads it: both ends, or the end that
|
|
87
|
+
* has it, twice. One neither end has is 0 on both: culori leaves it out, and its format writes 0.
|
|
88
|
+
*/
|
|
89
|
+
const channelPair = (a, b) => UndefinedOr.match(a, {
|
|
90
|
+
onUndefined: () => UndefinedOr.match(b, { onUndefined: () => [0, 0], onDefined: (y) => [y, y] }),
|
|
91
|
+
onDefined: (x) => UndefinedOr.match(b, { onUndefined: () => [x, x], onDefined: (y) => [x, y] }),
|
|
92
|
+
});
|
|
93
|
+
/** An alpha one end lacks is 1, culori's `fixupAlpha`; with neither, 1 on both writes `rgb()`, as culori does. */
|
|
94
|
+
const alphaOf = (alpha) => UndefinedOr.match(alpha, { onUndefined: () => 1, onDefined: identity });
|
|
95
|
+
/** A channel's value at 0–1, as culori's format reads it: NaN as 0, then clamped. Per frame: an early return. */
|
|
96
|
+
const unitOf = (value) => {
|
|
97
|
+
if (Number.isNaN(value))
|
|
98
|
+
return 0;
|
|
99
|
+
return Math.max(0, Math.min(1, value));
|
|
100
|
+
};
|
|
101
|
+
/** A channel as a byte, as culori's `formatRgb` writes it. */
|
|
102
|
+
const byteOf = (value) => Math.round(unitOf(value) * 255);
|
|
103
|
+
/** An alpha as culori's `formatRgb` writes it: clamped, two decimal places. */
|
|
104
|
+
const alphaText = (alpha) => Math.round(unitOf(alpha) * 100) / 100;
|
|
105
|
+
/** Four channels as culori's `formatRgb` writes them. Per frame: an early return. */
|
|
106
|
+
const formatChannels = (r, g, b, alpha) => {
|
|
107
|
+
if (alpha === 1)
|
|
108
|
+
return `rgb(${byteOf(r)}, ${byteOf(g)}, ${byteOf(b)})`;
|
|
109
|
+
return `rgba(${byteOf(r)}, ${byteOf(g)}, ${byteOf(b)}, ${alphaText(alpha)})`;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Two colours' blend in sRGB, on the per-frame path (ADR-0025): `t` clamped as culori clamps it,
|
|
113
|
+
* the start as written at `t <= 0`, and the four lerps formatted. Nothing allocated but the string.
|
|
114
|
+
*/
|
|
115
|
+
const blendChannels = (atStart, from, to) => (t) => {
|
|
116
|
+
const at = Math.min(Math.max(0, t), 1);
|
|
117
|
+
if (at <= 0)
|
|
118
|
+
return atStart;
|
|
119
|
+
return formatChannels(Scalar.lerp(from.r, to.r, at), Scalar.lerp(from.g, to.g, at), Scalar.lerp(from.b, to.b, at), Scalar.lerp(from.alpha, to.alpha, at));
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Two ends with the same channels: every `t` past 0 writes one string, since `a + t * (a - a)` is
|
|
123
|
+
* `a` (#156). Per frame: an early return.
|
|
124
|
+
*/
|
|
125
|
+
const holdChannels = (atStart, same) => (t) => {
|
|
126
|
+
if (t <= 0)
|
|
127
|
+
return atStart;
|
|
128
|
+
return same;
|
|
129
|
+
};
|
|
130
|
+
/** Two channels that are the same on both ends. */
|
|
131
|
+
const isSame = ([a, b]) => a === b;
|
|
132
|
+
/**
|
|
133
|
+
* Two colours' sRGB blend, resolved once when a stream is built: each end converted to sRGB by
|
|
134
|
+
* culori, its channels paired as culori pairs them, and the start's own string for `t <= 0`, by
|
|
135
|
+
* culori's `formatRgb` itself. Two ends with the same channels hold one string.
|
|
136
|
+
*/
|
|
137
|
+
const srgb = (from, to) => {
|
|
138
|
+
const a = toRgb(from);
|
|
139
|
+
const b = toRgb(to);
|
|
140
|
+
const pairs = [
|
|
141
|
+
channelPair(a.r, b.r),
|
|
142
|
+
channelPair(a.g, b.g),
|
|
143
|
+
channelPair(a.b, b.b),
|
|
144
|
+
[alphaOf(a.alpha), alphaOf(b.alpha)],
|
|
145
|
+
];
|
|
146
|
+
const [[fr, tr], [fg, tg], [fb, tb], [fa, ta]] = pairs;
|
|
147
|
+
const atStart = formatRgb(a);
|
|
148
|
+
return Bool.match(Arr.every(pairs, isSame), {
|
|
149
|
+
onTrue: () => holdChannels(atStart, formatChannels(fr, fg, fb, fa)),
|
|
150
|
+
onFalse: () => blendChannels(atStart, { r: fr, g: fg, b: fb, alpha: fa }, { r: tr, g: tg, b: tb, alpha: ta }),
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
/** Two colours' blend through culori in `mode`: `interpolate` once, then a colour object and `formatRgb` per frame. */
|
|
154
|
+
const throughCulori = (mode, from, to) => {
|
|
155
|
+
const at = culoriInterpolate([from, to], mode);
|
|
156
|
+
return (t) => formatRgb(at(t));
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Blends colours in the colour space `mode`: `"rgb"` by default, sRGB, as the browser's own animations
|
|
160
|
+
* blend. `"oklch"` or `"lab"` blend perceptually, once `registerSpaces` has registered them. A string is
|
|
161
|
+
* a colour when culori reads it, trimmed, so a keyword like `"auto"` isn't, and named colours and the
|
|
162
|
+
* modern forms culori knows are. Past the end of a blend a colour holds at its target.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* Color.registerSpaces()
|
|
166
|
+
* yield* registry.register(Color.interpolator("oklch")) // colours now blend in OKLCH
|
|
167
|
+
*/
|
|
168
|
+
// ADR-0026. A factory, so an app can register the space it prefers over the one `parseColor` and
|
|
169
|
+
// `formatColor` use; the DOM's registry uses `"rgb"` (`cssColor`). `blend` resolves the pair once, when a
|
|
170
|
+
// stream is built, and the frame writes the string `format` (`formatRgb`) would:
|
|
171
|
+
// - `"rgb"` blends with Wardic's own lerp and format (#156, ADR-0026 *Amendment (#156)*), the strings
|
|
172
|
+
// culori writes, with no colour object per frame; two ends of the same colour write one string.
|
|
173
|
+
// - Any other mode goes through culori's interpolator, which returns a new colour object on each call.
|
|
174
|
+
// Either clamps `t` to [0, 1], as culori does (ADR-0024, decision 5).
|
|
175
|
+
export const color = (mode = "rgb") => ({
|
|
176
|
+
name: `color(${mode})`,
|
|
177
|
+
parse: parseColor,
|
|
178
|
+
format: formatColor,
|
|
179
|
+
blend: (from, to) => Option.some(Bool.match(mode === "rgb", {
|
|
180
|
+
onTrue: () => srgb(from, to),
|
|
181
|
+
onFalse: () => throughCulori(mode, from, to),
|
|
182
|
+
})),
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* A colour inside a longer value: a hex, or an `rgb()`, `rgba()`, `hsl()` or `hsla()`, as Motion's colour
|
|
186
|
+
* token is. A named colour, `red`, isn't one: it stays part of the text around the tokens.
|
|
187
|
+
*/
|
|
188
|
+
// Motion's motion-dom value/types/utils/color-regex.ts at 16c6122; #61.
|
|
189
|
+
export const COLOR_TOKEN = /#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)/;
|
|
190
|
+
/** The DOM's colours: CSS's colour syntax, blended in sRGB, as the browser's own animations blend. Its registry's colour kind. */
|
|
191
|
+
// ADR-0024: as WAAPI blends.
|
|
192
|
+
export const cssColor = color("rgb");
|
|
193
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/internal/colors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,sCAAsC;AACtC,OAAO,EACL,SAAS,EACT,OAAO,EACP,WAAW,IAAI,iBAAiB,EAChC,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,SAAS,EACT,SAAS,EACT,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,IAAI,WAAW,EACpB,OAAO,GACR,MAAM,WAAW,CAAA;AAElB,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AAMjD,+DAA+D;AAC/D,MAAM,OAAO,GAAG,CAAC,KAAc,EAAkB,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAExF;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;AAE3D,6HAA6H;AAC7H,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAwB,E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C,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;QACzB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;KAC7C,CAAC,CACH;CACJ,CAAC,CAAA;AAEF;;;GAGG;AACH,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,6GAA6G,CAAA;AAExI,kIAAkI;AAClI,6BAA6B;AAC7B,MAAM,CAAC,MAAM,QAAQ,GAAsC,KAAK,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM Environment's complex values (ADR-0035 *Amendment (#158)*, ADR-0036): core's complex tier,
|
|
3
|
+
* given CSS's `var()` as a span of text (#158) and a colour as a kind of token (#61, #160). Core
|
|
4
|
+
* names neither.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as Interpolator from "@wardic/core/Interpolator";
|
|
9
|
+
/**
|
|
10
|
+
* A reference to a custom property, `var(--name)`, with a fallback one bracket level deep (Motion's
|
|
11
|
+
* var token, motion-dom value/types/complex/index.ts `complexRegex` at 16c6122). Inside a complex
|
|
12
|
+
* value it's text: the digits in its name (`--gray-500`) are never numbers (#158).
|
|
13
|
+
*/
|
|
14
|
+
export declare const VARIABLE_REFERENCE: RegExp;
|
|
15
|
+
/**
|
|
16
|
+
* Core's complex Interpolator with the DOM's syntax:
|
|
17
|
+
* - a `var()` is text (#158): a lone `var()` isn't a complex value, and two blend only with the same
|
|
18
|
+
* count of `var()`s, the target's written as it stands;
|
|
19
|
+
* - a colour is a token (#61, #160) that blends through `cssColor`, in sRGB, so a shadow's colour
|
|
20
|
+
* fades: two blend only with the same count of colours, the n-th with the n-th, and a lone colour
|
|
21
|
+
* is `cssColor`'s, not a complex value.
|
|
22
|
+
*/
|
|
23
|
+
export declare const cssComplex: Interpolator.Entry<Interpolator.Complex, string>;
|
|
24
|
+
//# sourceMappingURL=complex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complex.d.ts","sourceRoot":"","sources":["../../src/internal/complex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAA;AAGzD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAA2F,CAAA;AAE1H;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAGtE,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM Environment's complex values (ADR-0035 *Amendment (#158)*, ADR-0036): core's complex tier,
|
|
3
|
+
* given CSS's `var()` as a span of text (#158) and a colour as a kind of token (#61, #160). Core
|
|
4
|
+
* names neither.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as Interpolator from "@wardic/core/Interpolator";
|
|
9
|
+
import { COLOR_TOKEN, cssColor } from "./colors.js";
|
|
10
|
+
/**
|
|
11
|
+
* A reference to a custom property, `var(--name)`, with a fallback one bracket level deep (Motion's
|
|
12
|
+
* var token, motion-dom value/types/complex/index.ts `complexRegex` at 16c6122). Inside a complex
|
|
13
|
+
* value it's text: the digits in its name (`--gray-500`) are never numbers (#158).
|
|
14
|
+
*/
|
|
15
|
+
export const VARIABLE_REFERENCE = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)/;
|
|
16
|
+
/**
|
|
17
|
+
* Core's complex Interpolator with the DOM's syntax:
|
|
18
|
+
* - a `var()` is text (#158): a lone `var()` isn't a complex value, and two blend only with the same
|
|
19
|
+
* count of `var()`s, the target's written as it stands;
|
|
20
|
+
* - a colour is a token (#61, #160) that blends through `cssColor`, in sRGB, so a shadow's colour
|
|
21
|
+
* fades: two blend only with the same count of colours, the n-th with the n-th, and a lone colour
|
|
22
|
+
* is `cssColor`'s, not a complex value.
|
|
23
|
+
*/
|
|
24
|
+
export const cssComplex = Interpolator.complexWith({
|
|
25
|
+
text: [VARIABLE_REFERENCE],
|
|
26
|
+
tokens: [{ pattern: COLOR_TOKEN, entry: cssColor }],
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=complex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complex.js","sourceRoot":"","sources":["../../src/internal/complex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,wFAAwF,CAAA;AAE1H;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAqD,YAAY,CAAC,WAAW,CAAC;IACnG,IAAI,EAAE,CAAC,kBAAkB,CAAC;IAC1B,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;CACpD,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Observing and letting go of boxes on one observer, each counted by the reasons it's watched for. */
|
|
2
|
+
export interface Watched {
|
|
3
|
+
readonly observe: (box: Element) => void;
|
|
4
|
+
readonly unobserve: (box: Element) => void;
|
|
5
|
+
}
|
|
6
|
+
/** {@link Watched} over `observer`, every box observed with `options`. */
|
|
7
|
+
export declare const counted: (observer: ResizeObserver, options?: ResizeObserverOptions) => Watched;
|
|
8
|
+
/**
|
|
9
|
+
* Watch `parent`'s direct children on `watched`, kept current by a `MutationObserver` on its child list.
|
|
10
|
+
* `onChildren` runs after each change to the list, its children watched by then. Returns the stop; the
|
|
11
|
+
* observer's own disconnect lets go of the boxes.
|
|
12
|
+
*/
|
|
13
|
+
export declare const watchChildren: (parent: Element, watched: Watched, onChildren: () => void) => (() => void);
|
|
14
|
+
/**
|
|
15
|
+
* Watch the page's content on `watched`: the body and its direct children (a body sized to the window
|
|
16
|
+
* doesn't grow with what overflows it), as {@link watchChildren} watches a container's. None with no
|
|
17
|
+
* body (a server, a document not parsed that far). Returns the stop.
|
|
18
|
+
*/
|
|
19
|
+
export declare const watchPage: (watched: Watched, onChildren: () => void) => (() => void);
|
|
20
|
+
//# sourceMappingURL=content-watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-watch.d.ts","sourceRoot":"","sources":["../../src/internal/content-watch.ts"],"names":[],"mappings":"AAiBA,uGAAuG;AACvG,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAA;IACxC,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAA;CAC3C;AAED,0EAA0E;AAC1E,eAAO,MAAM,OAAO,aAAc,cAAc,YAAY,qBAAqB,KAAG,OAoBnF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,WAAY,OAAO,WAAW,OAAO,cAAc,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAepG,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,YAAa,OAAO,cAAc,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAU7E,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* - `Probe.scroll` 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
|
+
/** {@link Watched} over `observer`, every box observed with `options`. */
|
|
18
|
+
export const counted = (observer, options) => {
|
|
19
|
+
const counts = new Map();
|
|
20
|
+
const countOf = (box) => Option.getOrElse(Option.fromUndefinedOr(counts.get(box)), () => 0);
|
|
21
|
+
return {
|
|
22
|
+
observe: (box) => {
|
|
23
|
+
const count = countOf(box);
|
|
24
|
+
counts.set(box, count + 1);
|
|
25
|
+
if (count === 0)
|
|
26
|
+
observer.observe(box, options);
|
|
27
|
+
},
|
|
28
|
+
unobserve: (box) => {
|
|
29
|
+
const count = countOf(box);
|
|
30
|
+
if (count === 0)
|
|
31
|
+
return;
|
|
32
|
+
if (count > 1) {
|
|
33
|
+
counts.set(box, count - 1);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
counts.delete(box);
|
|
37
|
+
observer.unobserve(box);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Watch `parent`'s direct children on `watched`, kept current by a `MutationObserver` on its child list.
|
|
43
|
+
* `onChildren` runs after each change to the list, its children watched by then. Returns the stop; the
|
|
44
|
+
* observer's own disconnect lets go of the boxes.
|
|
45
|
+
*/
|
|
46
|
+
export const watchChildren = (parent, watched, onChildren) => {
|
|
47
|
+
Arr.forEach(Array.from(parent.children), watched.observe);
|
|
48
|
+
const children = new MutationObserver((records) => {
|
|
49
|
+
Arr.forEach(records, (record) => {
|
|
50
|
+
Arr.forEach(Array.from(record.addedNodes), (node) => {
|
|
51
|
+
if (node instanceof Element)
|
|
52
|
+
watched.observe(node);
|
|
53
|
+
});
|
|
54
|
+
Arr.forEach(Array.from(record.removedNodes), (node) => {
|
|
55
|
+
if (node instanceof Element)
|
|
56
|
+
watched.unobserve(node);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
onChildren();
|
|
60
|
+
});
|
|
61
|
+
children.observe(parent, { childList: true });
|
|
62
|
+
return () => children.disconnect();
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Watch the page's content on `watched`: the body and its direct children (a body sized to the window
|
|
66
|
+
* doesn't grow with what overflows it), as {@link watchChildren} watches a container's. None with no
|
|
67
|
+
* body (a server, a document not parsed that far). Returns the stop.
|
|
68
|
+
*/
|
|
69
|
+
export const watchPage = (watched, onChildren) => Option.match(Option.flatMap(Option.fromUndefinedOr(globalThis.document), (page) => Option.fromNullOr(page.body)), {
|
|
70
|
+
onNone: () => constVoid,
|
|
71
|
+
onSome: (body) => {
|
|
72
|
+
watched.observe(body);
|
|
73
|
+
return watchChildren(body, watched, onChildren);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=content-watch.js.map
|