viewkitjs 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/package.json +2 -4
- package/views/dist/contract.d.ts +6 -289
- package/views/dist/contract.js +1 -96
- package/views/dist/controls/atoms.d.ts +8 -0
- package/views/dist/controls/atoms.js +8 -0
- package/views/dist/controls/button/tokens.d.ts +351 -0
- package/views/dist/controls/button/tokens.js +90 -0
- package/views/dist/controls/checkbox/checkbox.d.ts +28 -0
- package/views/dist/controls/checkbox/checkbox.js +15 -0
- package/views/dist/controls/checkbox/looks.d.ts +3 -0
- package/views/dist/controls/checkbox/looks.js +8 -0
- package/views/dist/controls/checkbox/map-checkbox.d.ts +2 -0
- package/views/dist/controls/checkbox/map-checkbox.js +5 -0
- package/views/dist/controls/checkbox/tokens.d.ts +131 -0
- package/views/dist/controls/checkbox/tokens.js +35 -0
- package/views/dist/controls/checkbox.css +133 -0
- package/views/dist/controls/controls.d.ts +12 -3
- package/views/dist/controls/controls.js +13 -1
- package/views/dist/controls/field/field.d.ts +94 -0
- package/views/dist/controls/field/field.js +46 -0
- package/views/dist/controls/field/looks.d.ts +13 -0
- package/views/dist/controls/field/looks.js +22 -0
- package/views/dist/controls/field/tokens.d.ts +75 -0
- package/views/dist/controls/field/tokens.js +21 -0
- package/views/dist/controls/field.css +98 -0
- package/views/dist/controls/glass-button/glass-button.d.ts +40 -0
- package/views/dist/controls/glass-button/glass-button.js +16 -0
- package/views/dist/controls/glass-button/looks.d.ts +4 -0
- package/views/dist/controls/glass-button/looks.js +4 -0
- package/views/dist/controls/glass-button/tokens.d.ts +127 -0
- package/views/dist/controls/glass-button/tokens.js +34 -0
- package/views/dist/controls/glass-button.css +111 -0
- package/views/dist/controls/index.d.ts +26 -0
- package/views/dist/controls/index.js +25 -0
- package/views/dist/controls/inline-input/inline-input.d.ts +14 -0
- package/views/dist/controls/inline-input/inline-input.js +10 -0
- package/views/dist/controls/inline-input/looks.d.ts +3 -0
- package/views/dist/controls/inline-input/looks.js +16 -0
- package/views/dist/controls/inline-input/tokens.d.ts +79 -0
- package/views/dist/controls/inline-input/tokens.js +22 -0
- package/views/dist/controls/inline-input.css +78 -0
- package/views/dist/controls/input/autofill.d.ts +25 -0
- package/views/dist/controls/input/autofill.js +17 -0
- package/views/dist/controls/input/input.d.ts +119 -0
- package/views/dist/controls/input/input.js +127 -0
- package/views/dist/controls/input/looks.d.ts +41 -0
- package/views/dist/controls/input/looks.js +48 -0
- package/views/dist/controls/input/map-input.d.ts +2 -0
- package/views/dist/controls/input/map-input.js +5 -0
- package/views/dist/controls/input/tokens.d.ts +171 -0
- package/views/dist/controls/input/tokens.js +45 -0
- package/views/dist/controls/input.css +381 -0
- package/views/dist/controls/internal/anchor.d.ts +16 -0
- package/views/dist/controls/internal/anchor.js +8 -0
- package/views/dist/controls/internal/close-reason.d.ts +5 -0
- package/views/dist/controls/internal/close-reason.js +2 -0
- package/views/dist/controls/internal/popup-host.d.ts +7 -0
- package/views/dist/controls/internal/popup-host.js +10 -0
- package/views/dist/controls/internal/scroll.d.ts +11 -0
- package/views/dist/controls/internal/scroll.js +14 -0
- package/views/dist/controls/kbd/kbd.d.ts +13 -0
- package/views/dist/controls/kbd/kbd.js +10 -0
- package/views/dist/controls/kbd/looks.d.ts +4 -0
- package/views/dist/controls/kbd/looks.js +4 -0
- package/views/dist/controls/kbd/tokens.d.ts +47 -0
- package/views/dist/controls/kbd/tokens.js +14 -0
- package/views/dist/controls/kbd.css +46 -0
- package/views/dist/controls/number-field/number-field.d.ts +48 -0
- package/views/dist/controls/number-field/number-field.js +34 -0
- package/views/dist/controls/number-field/tokens.d.ts +47 -0
- package/views/dist/controls/number-field/tokens.js +14 -0
- package/views/dist/controls/number-field.css +54 -0
- package/views/dist/controls/option/atom-tag.d.ts +6 -0
- package/views/dist/controls/option/atom-tag.js +6 -0
- package/views/dist/controls/option/looks.d.ts +7 -0
- package/views/dist/controls/option/looks.js +21 -0
- package/views/dist/controls/option/option.d.ts +35 -0
- package/views/dist/controls/option/option.js +32 -0
- package/views/dist/controls/option/tokens.d.ts +223 -0
- package/views/dist/controls/option/tokens.js +58 -0
- package/views/dist/controls/option.css +92 -0
- package/views/dist/controls/phone-header/header-bar.d.ts +18 -0
- package/views/dist/controls/phone-header/header-bar.js +9 -0
- package/views/dist/controls/phone-header/looks.d.ts +4 -0
- package/views/dist/controls/phone-header/looks.js +4 -0
- package/views/dist/controls/phone-header/soft-edge.d.ts +5 -0
- package/views/dist/controls/phone-header/soft-edge.js +3 -0
- package/views/dist/controls/phone-header/tokens.d.ts +59 -0
- package/views/dist/controls/phone-header/tokens.js +17 -0
- package/views/dist/controls/phone-header.css +51 -0
- package/views/dist/controls/popover/looks.d.ts +4 -0
- package/views/dist/controls/popover/looks.js +10 -0
- package/views/dist/controls/popover/map-popover.d.ts +3 -0
- package/views/dist/controls/popover/map-popover.js +5 -0
- package/views/dist/controls/popover/popover.d.ts +74 -0
- package/views/dist/controls/popover/popover.js +106 -0
- package/views/dist/controls/popover/tokens.d.ts +83 -0
- package/views/dist/controls/popover/tokens.js +23 -0
- package/views/dist/controls/popover.css +94 -0
- package/views/dist/controls/scrollbar/scrollbar.d.ts +10 -0
- package/views/dist/controls/scrollbar/scrollbar.js +143 -0
- package/views/dist/controls/scrollbar/tokens.d.ts +43 -0
- package/views/dist/controls/scrollbar/tokens.js +13 -0
- package/views/dist/controls/scrollbar.css +47 -0
- package/views/dist/controls/sheet/bottom-sheet.d.ts +98 -0
- package/views/dist/controls/sheet/bottom-sheet.js +372 -0
- package/views/dist/controls/sheet/forms.d.ts +38 -0
- package/views/dist/controls/sheet/forms.js +26 -0
- package/views/dist/controls/sheet/looks.d.ts +4 -0
- package/views/dist/controls/sheet/looks.js +10 -0
- package/views/dist/controls/sheet/map-sheet.d.ts +3 -0
- package/views/dist/controls/sheet/map-sheet.js +12 -0
- package/views/dist/controls/sheet/spring.d.ts +22 -0
- package/views/dist/controls/sheet/spring.js +48 -0
- package/views/dist/controls/sheet/tokens.d.ts +143 -0
- package/views/dist/controls/sheet/tokens.js +38 -0
- package/views/dist/controls/sheet.css +220 -0
- package/views/dist/controls/spinner/tokens.d.ts +55 -0
- package/views/dist/controls/spinner/tokens.js +16 -0
- package/views/dist/controls/status/atom-status-badge.d.ts +10 -0
- package/views/dist/controls/status/atom-status-badge.js +13 -0
- package/views/dist/controls/status/looks.d.ts +4 -0
- package/views/dist/controls/status/looks.js +22 -0
- package/views/dist/controls/status/marks.d.ts +26 -0
- package/views/dist/controls/status/marks.js +73 -0
- package/views/dist/controls/status/status.d.ts +43 -0
- package/views/dist/controls/status/status.js +26 -0
- package/views/dist/controls/status/tokens.d.ts +407 -0
- package/views/dist/controls/status/tokens.js +104 -0
- package/views/dist/controls/status.css +164 -0
- package/views/dist/controls/switch/looks.d.ts +4 -0
- package/views/dist/controls/switch/looks.js +19 -0
- package/views/dist/controls/switch/switch.d.ts +15 -0
- package/views/dist/controls/switch/switch.js +11 -0
- package/views/dist/controls/switch/tokens.d.ts +139 -0
- package/views/dist/controls/switch/tokens.js +37 -0
- package/views/dist/controls/switch.css +169 -0
- package/views/dist/controls/tag/atom-cell-more.d.ts +3 -0
- package/views/dist/controls/tag/atom-cell-more.js +5 -0
- package/views/dist/controls/tag/looks.d.ts +4 -0
- package/views/dist/controls/tag/looks.js +4 -0
- package/views/dist/controls/tag/tag.d.ts +25 -0
- package/views/dist/controls/tag/tag.js +19 -0
- package/views/dist/controls/tag/tokens.d.ts +63 -0
- package/views/dist/controls/tag/tokens.js +18 -0
- package/views/dist/controls/tag.css +81 -0
- package/views/dist/controls/toggle/looks.d.ts +3 -0
- package/views/dist/controls/toggle/looks.js +12 -0
- package/views/dist/controls/toggle/toggle.d.ts +47 -0
- package/views/dist/controls/toggle/toggle.js +23 -0
- package/views/dist/controls/toggle/tokens.d.ts +55 -0
- package/views/dist/controls/toggle/tokens.js +16 -0
- package/views/dist/controls/toggle.css +67 -0
- package/views/dist/controls/tokens.d.ts +16 -0
- package/views/dist/controls/tokens.js +45 -0
- package/views/dist/controls/tooltip/looks.d.ts +4 -0
- package/views/dist/controls/tooltip/looks.js +4 -0
- package/views/dist/controls/tooltip/map-tooltip.d.ts +3 -0
- package/views/dist/controls/tooltip/map-tooltip.js +5 -0
- package/views/dist/controls/tooltip/tokens.d.ts +75 -0
- package/views/dist/controls/tooltip/tokens.js +21 -0
- package/views/dist/controls/tooltip/tooltip.d.ts +54 -0
- package/views/dist/controls/tooltip/tooltip.js +78 -0
- package/views/dist/controls/tooltip.css +94 -0
- package/views/dist/grid/chrome/GridTable.js +21 -19
- package/views/dist/grid/chrome/grid-row-window.js +3 -0
- package/views/dist/grid/chrome/useGridColumnLayout.d.ts +4 -1
- package/views/dist/grid/chrome/useGridColumnLayout.js +17 -2
- package/views/dist/grid/chrome/useGridFittedWidths.d.ts +29 -0
- package/views/dist/grid/chrome/useGridFittedWidths.js +46 -0
- package/views/dist/looks/index.d.ts +15 -0
- package/views/dist/looks/index.js +15 -0
- package/views/dist/looks/pieces.js +36 -2
- package/views/dist/model/column-schema.d.ts +3 -2
- package/views/dist/model/column-state.d.ts +11 -1
- package/views/dist/model/column-state.js +8 -2
- package/views/dist/styles.css +1930 -7
- package/views/dist/styles.unlayered.css +1930 -7
- package/views/docs/contract.md +5 -97
- package/views/docs/controls/button.md +93 -0
- package/views/docs/controls/checkbox.md +38 -0
- package/views/docs/controls/field.md +26 -0
- package/views/docs/controls/glass-button.md +37 -0
- package/views/docs/controls/inline-input.md +27 -0
- package/views/docs/controls/input.md +48 -0
- package/views/docs/controls/kbd.md +17 -0
- package/views/docs/controls/number-field.md +17 -0
- package/views/docs/controls/option.md +61 -0
- package/views/docs/controls/phone-header.md +20 -0
- package/views/docs/controls/popover.md +26 -0
- package/views/docs/controls/scrollbar.md +16 -0
- package/views/docs/controls/sheet.md +41 -0
- package/views/docs/controls/spinner.md +19 -0
- package/views/docs/controls/status.md +107 -0
- package/views/docs/controls/switch.md +40 -0
- package/views/docs/controls/tag.md +21 -0
- package/views/docs/controls/toggle.md +19 -0
- package/views/docs/controls/tooltip.md +24 -0
- package/views/docs/getting-started.md +1 -1
- package/views/docs/reference/controls.md +173 -2
- package/views/docs/reference/looks.md +67 -2
- package/views/docs/reference/views.md +7 -2
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Drawer as Base } from "@base-ui/react/drawer";
|
|
4
|
+
import { cx } from "../../internal/cx.js";
|
|
5
|
+
import { Button } from "../button/button.js";
|
|
6
|
+
import { GlassButton } from "../glass-button/glass-button.js";
|
|
7
|
+
import { closeReasonOf } from "../internal/close-reason.js";
|
|
8
|
+
import { drawnAt, typesInto } from "../internal/scroll.js";
|
|
9
|
+
import { HeaderBar } from "../phone-header/header-bar.js";
|
|
10
|
+
import { Scrollbar } from "../scrollbar/scrollbar.js";
|
|
11
|
+
import { FORMS, markBottom, markStop, offsetOf, pointOf, pointsOf, stopAfterFocus, stopAfterWheel, stopOf } from "./forms.js";
|
|
12
|
+
import { settle, springOf } from "./spring.js";
|
|
13
|
+
const glyph = (paths) => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
|
|
14
|
+
const BACK = ["M5 12l14 0", "M5 12l6 6", "M5 12l6 -6"], X = ["M18 6l-12 12", "M6 6l12 12"];
|
|
15
|
+
const Body = React.createContext({});
|
|
16
|
+
const CloseAll = React.createContext(null);
|
|
17
|
+
const Standing = React.createContext(false);
|
|
18
|
+
export const useSheetCloseAll = () => React.useContext(CloseAll);
|
|
19
|
+
export const SheetClose = ({ children }) => _jsx(Base.Close, { render: children });
|
|
20
|
+
export function SheetButton({ className, kind, children, ...props }) {
|
|
21
|
+
return _jsxs(_Fragment, { children: [_jsx(GlassButton, { ...props, kind: kind, className: cx("o-sheet-glass", className), children: children }), _jsx(Button, { ...props, kind: kind ?? "quiet", shape: children == null ? "icon" : undefined, className: cx("o-sheet-plain", className), children: children })] });
|
|
22
|
+
}
|
|
23
|
+
export function SheetHead({ title, titleAt, description, close = true, onBack, left, right, children }) {
|
|
24
|
+
const sides = left != null || right != null;
|
|
25
|
+
return (_jsx("div", { className: "o-sheet-head", children: _jsx(HeaderBar, { className: "o-sheet-row", titleAt: titleAt, "data-sides": sides ? "" : undefined, left: sides ? left : onBack ? _jsx(SheetButton, { "aria-label": "Back", className: "o-sheet-back", icon: glyph(BACK), onClick: onBack }) : close && _jsx(Base.Close, { render: _jsx(GlassButton, { "aria-label": "Close", className: "o-sheet-glass", icon: glyph(X) }) }), title: _jsx(Base.Title, { className: "o-sheet-title", children: title }), description: description, descriptionRender: _jsx(Base.Description, {}), right: sides ? right : _jsxs(_Fragment, { children: [children, close && _jsx(Base.Close, { render: _jsx(Button, { kind: "quiet", shape: "icon", "aria-label": "Close", className: "o-sheet-plain", icon: glyph(X) }) })] }) }) }));
|
|
26
|
+
}
|
|
27
|
+
export const SheetFoot = ({ children }) => _jsx("div", { className: "o-sheet-foot", children: children });
|
|
28
|
+
export const SheetBody = React.forwardRef(function SheetBody({ onScroll, children }, ref) {
|
|
29
|
+
const { onBodyWheel, onBodyFocus } = React.useContext(Body);
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx(Base.Content, { ref: ref, className: "o-sheet-body", onScroll: onScroll, onWheel: onBodyWheel, onFocusCapture: onBodyFocus, children: _jsx("div", { className: "o-sheet-content", children: children }) }), _jsx(Scrollbar, {})] }));
|
|
31
|
+
});
|
|
32
|
+
export function SheetStep({ step, back, children }) {
|
|
33
|
+
const el = React.useRef(null), was = React.useRef(step);
|
|
34
|
+
React.useLayoutEffect(() => {
|
|
35
|
+
if (was.current === step)
|
|
36
|
+
return;
|
|
37
|
+
was.current = step;
|
|
38
|
+
const body = el.current?.closest(".o-sheet-body");
|
|
39
|
+
if (body)
|
|
40
|
+
body.scrollTop = 0;
|
|
41
|
+
el.current?.focus({ preventScroll: true });
|
|
42
|
+
}, [step]);
|
|
43
|
+
return _jsx("div", { ref: el, tabIndex: -1, className: "o-sheet-step", "data-back": back ? "" : undefined, children: children }, step);
|
|
44
|
+
}
|
|
45
|
+
const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
46
|
+
const CONTROLS = "a, button, input, select, textarea, label, [role='button'], [role='tab'], [role='switch'], [role='checkbox'], [role='combobox'], [role='menuitem']";
|
|
47
|
+
const px = (el, name) => parseFloat(el.style.getPropertyValue(name)) || 0;
|
|
48
|
+
const clamp = (x) => Math.min(1, Math.max(0, x));
|
|
49
|
+
function useFinger(on) {
|
|
50
|
+
const samples = React.useRef([]);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (!on)
|
|
53
|
+
return;
|
|
54
|
+
const add = (y, t) => { const s = samples.current; s.push({ t, y }); while (s.length > 2 && t - s[0].t > 120)
|
|
55
|
+
s.shift(); };
|
|
56
|
+
const touch = (e) => { if (e.type === "touchstart")
|
|
57
|
+
samples.current = []; const p = e.touches[0]; if (p)
|
|
58
|
+
add(p.clientY, e.timeStamp); };
|
|
59
|
+
const pointer = (e) => { if (e.pointerType === "touch")
|
|
60
|
+
return; if (e.type === "pointerdown")
|
|
61
|
+
samples.current = []; if (e.buttons)
|
|
62
|
+
add(e.clientY, e.timeStamp); };
|
|
63
|
+
const opts = { capture: true, passive: true };
|
|
64
|
+
["touchstart", "touchmove"].forEach((n) => window.addEventListener(n, touch, opts));
|
|
65
|
+
["pointerdown", "pointermove"].forEach((n) => window.addEventListener(n, pointer, opts));
|
|
66
|
+
return () => {
|
|
67
|
+
["touchstart", "touchmove"].forEach((n) => window.removeEventListener(n, touch, opts));
|
|
68
|
+
["pointerdown", "pointermove"].forEach((n) => window.removeEventListener(n, pointer, opts));
|
|
69
|
+
};
|
|
70
|
+
}, [on]);
|
|
71
|
+
return React.useCallback((at) => {
|
|
72
|
+
const s = samples.current, last = s[s.length - 1];
|
|
73
|
+
if (!last || s.length < 2 || at - last.t > 80)
|
|
74
|
+
return 0;
|
|
75
|
+
const first = s.find((x) => last.t - x.t <= 80) ?? s[0], dt = last.t - first.t;
|
|
76
|
+
return dt > 0 ? (last.y - first.y) / dt : 0;
|
|
77
|
+
}, []);
|
|
78
|
+
}
|
|
79
|
+
const afterMotion = (els, then) => requestAnimationFrame(() => {
|
|
80
|
+
Promise.all(els.flatMap((el) => (el.isConnected ? el.getAnimations() : [])).map((a) => a.finished.catch(() => { }))).then(then);
|
|
81
|
+
});
|
|
82
|
+
function useSheetMotion({ on, open, form, standing, points, point, popup, viewport, backdrop }) {
|
|
83
|
+
const speed = useFinger(on && open);
|
|
84
|
+
const reach = React.useRef({ offsets: [0], closed: 0, width: 1, height: 1, gap: 0 });
|
|
85
|
+
const leaving = React.useRef(false);
|
|
86
|
+
React.useEffect(() => { if (open)
|
|
87
|
+
leaving.current = false; }, [open]);
|
|
88
|
+
const below = React.useRef(null), colours = React.useRef({ sheet: "", dim: "" });
|
|
89
|
+
const moved = React.useCallback(() => [popup, backdrop.current, below.current], [popup, backdrop]);
|
|
90
|
+
const where = React.useCallback(() => (popup ? px(popup, "--drawer-snap-point-offset") + px(popup, "--drawer-swipe-movement-y") + px(popup, "--sheet-catch") : 0), [popup]);
|
|
91
|
+
const measure = React.useCallback(() => {
|
|
92
|
+
if (!popup || !viewport)
|
|
93
|
+
return;
|
|
94
|
+
const offsets = points.map((p) => offsetOf(p, popup.offsetHeight, viewport.clientHeight)).sort((a, b) => a - b);
|
|
95
|
+
reach.current = { offsets: offsets.length ? offsets : [0], closed: viewport.clientHeight - popup.offsetTop, width: popup.offsetWidth || 1, height: popup.offsetHeight, gap: parseFloat(getComputedStyle(popup).scrollMarginLeft) || 0 };
|
|
96
|
+
}, [popup, viewport, points]);
|
|
97
|
+
const paint = React.useCallback((y) => {
|
|
98
|
+
const { offsets, closed, width, height, gap } = reach.current, top = offsets[0], lowest = offsets[offsets.length - 1];
|
|
99
|
+
const gone = clamp((y - lowest) / Math.max(1, closed - lowest));
|
|
100
|
+
[backdrop.current, below.current].forEach((el) => el?.style.setProperty("--sheet-gone", gone.toFixed(3)));
|
|
101
|
+
popup?.style.setProperty("--sheet-lift", `${Math.max(0, Math.min(y, lowest))}px`);
|
|
102
|
+
if (form !== "blend")
|
|
103
|
+
return;
|
|
104
|
+
const rise = 1 - clamp((y - top) / Math.max(1, (offsets[1] ?? closed) - top)), margin = gap * (1 - rise), scale = (width - 2 * margin) / width;
|
|
105
|
+
popup?.style.setProperty("--sheet-rise", rise.toFixed(3));
|
|
106
|
+
popup?.style.setProperty("--sheet-scale", scale.toFixed(4));
|
|
107
|
+
popup?.style.setProperty("--sheet-cut", `${(height - (height - Math.min(y, lowest) - margin) / scale).toFixed(1)}px`);
|
|
108
|
+
below.current?.style.setProperty("background-color", `color-mix(in srgb, ${colours.current.sheet} ${Math.round(rise * 100)}%, ${colours.current.dim})`);
|
|
109
|
+
}, [popup, backdrop, form]);
|
|
110
|
+
const release = React.useCallback((to, at) => {
|
|
111
|
+
if (!popup || leaving.current)
|
|
112
|
+
return;
|
|
113
|
+
leaving.current = to === "closed";
|
|
114
|
+
const target = to === "closed" ? reach.current.closed : to, y = where();
|
|
115
|
+
popup.style.removeProperty("--sheet-catch");
|
|
116
|
+
if (!reduced()) {
|
|
117
|
+
const css = getComputedStyle(popup), spring = springOf(css.getPropertyValue("--sheet-spring"));
|
|
118
|
+
const v = at === undefined || y < reach.current.offsets[0] ? 0 : speed(at);
|
|
119
|
+
const s = settle(target - y, v, spring, to === "closed" ? { exit: parseFloat(css.getPropertyValue("--sheet-exit")) } : { past: parseFloat(css.getPropertyValue("--sheet-past")) });
|
|
120
|
+
if (s)
|
|
121
|
+
moved().forEach((el) => { el?.style.setProperty("--sheet-ease", s.ease); el?.style.setProperty("--sheet-time", `${s.time}ms`); });
|
|
122
|
+
}
|
|
123
|
+
paint(target);
|
|
124
|
+
}, [popup, moved, where, speed, paint]);
|
|
125
|
+
React.useEffect(() => {
|
|
126
|
+
if (!popup)
|
|
127
|
+
return;
|
|
128
|
+
const done = (e) => { if (e.target === popup && e.propertyName === "transform")
|
|
129
|
+
moved().forEach((el) => { el?.style.removeProperty("--sheet-ease"); el?.style.removeProperty("--sheet-time"); }); };
|
|
130
|
+
popup.addEventListener("transitionend", done);
|
|
131
|
+
return () => popup.removeEventListener("transitionend", done);
|
|
132
|
+
}, [popup, moved]);
|
|
133
|
+
React.useEffect(() => {
|
|
134
|
+
if (!on || !popup || !viewport)
|
|
135
|
+
return;
|
|
136
|
+
const grab = () => {
|
|
137
|
+
if (!popup.getAnimations().some((a) => a.transitionProperty === "transform" && a.playState === "running"))
|
|
138
|
+
return;
|
|
139
|
+
popup.style.setProperty("--sheet-catch", `${new DOMMatrixReadOnly(getComputedStyle(popup).transform).m42 - px(popup, "--drawer-snap-point-offset")}px`);
|
|
140
|
+
};
|
|
141
|
+
const free = () => popup.style.removeProperty("--sheet-catch");
|
|
142
|
+
const opts = { capture: true, passive: true };
|
|
143
|
+
viewport.addEventListener("touchstart", grab, opts);
|
|
144
|
+
viewport.addEventListener("pointerdown", grab, opts);
|
|
145
|
+
["touchend", "touchcancel", "pointerup", "pointercancel"].forEach((n) => window.addEventListener(n, free));
|
|
146
|
+
return () => {
|
|
147
|
+
viewport.removeEventListener("touchstart", grab, opts);
|
|
148
|
+
viewport.removeEventListener("pointerdown", grab, opts);
|
|
149
|
+
["touchend", "touchcancel", "pointerup", "pointercancel"].forEach((n) => window.removeEventListener(n, free));
|
|
150
|
+
};
|
|
151
|
+
}, [on, popup, viewport]);
|
|
152
|
+
React.useEffect(() => {
|
|
153
|
+
if (!on || !popup)
|
|
154
|
+
return;
|
|
155
|
+
let frame = 0;
|
|
156
|
+
const tick = () => { if (!popup.hasAttribute("data-swiping")) {
|
|
157
|
+
frame = 0;
|
|
158
|
+
return;
|
|
159
|
+
} paint(where()); frame = requestAnimationFrame(tick); };
|
|
160
|
+
const watch = new MutationObserver(() => { if (popup.hasAttribute("data-swiping") && !frame) {
|
|
161
|
+
measure();
|
|
162
|
+
frame = requestAnimationFrame(tick);
|
|
163
|
+
} });
|
|
164
|
+
watch.observe(popup, { attributes: true, attributeFilter: ["data-swiping"] });
|
|
165
|
+
return () => { watch.disconnect(); cancelAnimationFrame(frame); };
|
|
166
|
+
}, [on, popup, paint, where, measure]);
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
const frame = on && form === "blend" ? popup?.closest("[data-sheet-margin]") : null;
|
|
169
|
+
if (!frame)
|
|
170
|
+
return;
|
|
171
|
+
const watch = new MutationObserver(() => { measure(); paint(where()); });
|
|
172
|
+
watch.observe(frame, { attributes: true, attributeFilter: ["data-sheet-margin"] });
|
|
173
|
+
return () => watch.disconnect();
|
|
174
|
+
}, [on, form, popup, paint, where, measure]);
|
|
175
|
+
React.useLayoutEffect(() => {
|
|
176
|
+
if (!on || !open || !popup || standing)
|
|
177
|
+
return;
|
|
178
|
+
const doc = popup.ownerDocument, end = doc.createElement("div");
|
|
179
|
+
end.className = "o-sheet-below";
|
|
180
|
+
end.dataset.sheetForm = form;
|
|
181
|
+
end.setAttribute("aria-hidden", "true");
|
|
182
|
+
end.style.top = `${window.scrollY + window.innerHeight}px`;
|
|
183
|
+
colours.current = { sheet: getComputedStyle(popup.querySelector(".o-sheet-cut") ?? popup).backgroundColor, dim: getComputedStyle(backdrop.current ?? popup).backgroundColor };
|
|
184
|
+
end.style.backgroundColor = form === "full" || form === "edge" ? colours.current.sheet : colours.current.dim;
|
|
185
|
+
doc.body.append(end);
|
|
186
|
+
below.current = end;
|
|
187
|
+
return () => { afterMotion([popup], () => { end.remove(); if (below.current === end)
|
|
188
|
+
below.current = null; }); };
|
|
189
|
+
}, [on, open, popup, form, backdrop, standing]);
|
|
190
|
+
React.useLayoutEffect(() => {
|
|
191
|
+
if (!on || !popup || !viewport)
|
|
192
|
+
return;
|
|
193
|
+
measure();
|
|
194
|
+
if (open)
|
|
195
|
+
paint(offsetOf(point, popup.offsetHeight, viewport.clientHeight));
|
|
196
|
+
else
|
|
197
|
+
paint(reach.current.closed);
|
|
198
|
+
}, [on, open, popup, viewport, point, points, measure, paint]);
|
|
199
|
+
return { release };
|
|
200
|
+
}
|
|
201
|
+
function useFit(on, popup, open) {
|
|
202
|
+
React.useLayoutEffect(() => {
|
|
203
|
+
if (!on || !popup || !open)
|
|
204
|
+
return;
|
|
205
|
+
const body = popup.querySelector(".o-sheet-body"), inner = body?.firstElementChild;
|
|
206
|
+
if (!body || !inner)
|
|
207
|
+
return;
|
|
208
|
+
const read = () => {
|
|
209
|
+
const c = getComputedStyle(body), edges = parseFloat(c.paddingTop) + parseFloat(c.paddingBottom);
|
|
210
|
+
popup.style.setProperty("--sheet-fit", `${popup.offsetHeight - body.offsetHeight + inner.offsetHeight + edges}px`);
|
|
211
|
+
};
|
|
212
|
+
read();
|
|
213
|
+
const watch = new ResizeObserver(read);
|
|
214
|
+
watch.observe(inner);
|
|
215
|
+
return () => watch.disconnect();
|
|
216
|
+
}, [on, popup, open]);
|
|
217
|
+
}
|
|
218
|
+
function useKeyboardFoot(popup, on) {
|
|
219
|
+
const [typing, setTyping] = React.useState(false);
|
|
220
|
+
React.useEffect(() => {
|
|
221
|
+
if (!on || !popup) {
|
|
222
|
+
setTyping(false);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const now = popup.ownerDocument.activeElement;
|
|
226
|
+
setTyping(typesInto(now) && popup.contains(now));
|
|
227
|
+
const into = (e) => setTyping(typesInto(e.target));
|
|
228
|
+
const out = (e) => { if (!(typesInto(e.relatedTarget) && popup.contains(e.relatedTarget)))
|
|
229
|
+
setTyping(false); };
|
|
230
|
+
popup.addEventListener("focusin", into);
|
|
231
|
+
popup.addEventListener("focusout", out);
|
|
232
|
+
return () => { popup.removeEventListener("focusin", into); popup.removeEventListener("focusout", out); };
|
|
233
|
+
}, [on, popup]);
|
|
234
|
+
React.useEffect(() => {
|
|
235
|
+
const vv = typeof window === "undefined" ? null : window.visualViewport;
|
|
236
|
+
if (!typing || !popup || !vv)
|
|
237
|
+
return;
|
|
238
|
+
const read = () => popup.style.setProperty("--sheet-keyboard", `${Math.abs(vv.scale - 1) > 0.01 ? 0 : Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop))}px`);
|
|
239
|
+
read();
|
|
240
|
+
vv.addEventListener("resize", read);
|
|
241
|
+
vv.addEventListener("scroll", read);
|
|
242
|
+
return () => { vv.removeEventListener("resize", read); vv.removeEventListener("scroll", read); popup.style.removeProperty("--sheet-keyboard"); };
|
|
243
|
+
}, [typing, popup]);
|
|
244
|
+
}
|
|
245
|
+
export function Sheet({ open, onOpenChange, onOpenChangeComplete, label, form = "full", stops, openAt, stop, onStopChange, mark: marked = "[data-sheet-mark]", container, standing: stands, finalFocus, children }) {
|
|
246
|
+
const closeBelow = React.useContext(CloseAll), stacked = closeBelow !== null;
|
|
247
|
+
const standsBelow = React.useContext(Standing), standing = stands || standsBelow;
|
|
248
|
+
const [armed, setArmed] = React.useState(false);
|
|
249
|
+
React.useEffect(() => setArmed(true), []);
|
|
250
|
+
React.useEffect(() => {
|
|
251
|
+
if (!open || standing || !container)
|
|
252
|
+
return;
|
|
253
|
+
const doc = container.ownerDocument, held = [];
|
|
254
|
+
for (let el = container; el && el !== doc.body && el !== doc.documentElement; el = el.parentElement) {
|
|
255
|
+
const y = getComputedStyle(el).overflowY;
|
|
256
|
+
if ((y === "auto" || y === "scroll") && el.scrollHeight > el.clientHeight) {
|
|
257
|
+
held.push([el, el.style.getPropertyValue("overflow-y")]);
|
|
258
|
+
el.style.setProperty("overflow-y", "hidden");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return () => held.forEach(([el, was]) => { el.style.setProperty("overflow-y", was); });
|
|
262
|
+
}, [open, standing, container]);
|
|
263
|
+
const [popup, setPopup] = React.useState(null), [viewport, setViewport] = React.useState(null);
|
|
264
|
+
const backdrop = React.useRef(null), popupRef = React.useRef(null);
|
|
265
|
+
const bindPopup = React.useCallback((el) => { popupRef.current = el; setPopup(el); }, []);
|
|
266
|
+
const list = stops ?? FORMS[form].stops, first = openAt ?? list[0];
|
|
267
|
+
const [at, setAt] = React.useState(first), [mark, setMark] = React.useState(null);
|
|
268
|
+
const [wasOpen, setWasOpen] = React.useState(open), [coming, setComing] = React.useState(open);
|
|
269
|
+
if (open !== wasOpen) {
|
|
270
|
+
setWasOpen(open);
|
|
271
|
+
if (open) {
|
|
272
|
+
setAt(first);
|
|
273
|
+
setComing(true);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const current = stop ?? at, measured = list.includes("mark");
|
|
277
|
+
React.useLayoutEffect(() => {
|
|
278
|
+
if (!measured || !popup)
|
|
279
|
+
return;
|
|
280
|
+
const body = popup.querySelector(".o-sheet-body");
|
|
281
|
+
const measure = () => {
|
|
282
|
+
if (popup.hasAttribute("data-nested-drawer-open"))
|
|
283
|
+
return;
|
|
284
|
+
const rise = parseFloat(popup.style.getPropertyValue("--sheet-rise") || "0");
|
|
285
|
+
if (rise > 0 && rise < 1)
|
|
286
|
+
return;
|
|
287
|
+
const el = popup.querySelector(marked);
|
|
288
|
+
const bottom = el ? markBottom(el.getBoundingClientRect().bottom, popup.getBoundingClientRect().top, drawnAt(popup), body?.scrollTop ?? 0, popup.querySelector(".o-sheet-foot")?.offsetHeight ?? 0) : null;
|
|
289
|
+
setMark(markStop({ top: 0, height: popup.offsetHeight }, bottom));
|
|
290
|
+
};
|
|
291
|
+
measure();
|
|
292
|
+
const watch = new ResizeObserver(measure);
|
|
293
|
+
if (body)
|
|
294
|
+
for (const child of body.querySelectorAll(".o-sheet-content, .o-sheet-content > *"))
|
|
295
|
+
watch.observe(child);
|
|
296
|
+
window.addEventListener("resize", measure);
|
|
297
|
+
document.fonts.addEventListener("loadingdone", measure);
|
|
298
|
+
return () => { watch.disconnect(); window.removeEventListener("resize", measure); document.fonts.removeEventListener("loadingdone", measure); };
|
|
299
|
+
}, [measured, popup, children, marked]);
|
|
300
|
+
const points = React.useMemo(() => pointsOf(list, mark), [list, mark]), point = pointOf(current, mark);
|
|
301
|
+
const { release } = useSheetMotion({ on: true, open, form, standing, points, point, popup, viewport, backdrop });
|
|
302
|
+
useFit(form === "floating" || form === "edge", popup, open);
|
|
303
|
+
useKeyboardFoot(popup, open && !standing);
|
|
304
|
+
React.useEffect(() => {
|
|
305
|
+
if (form === "full" || form === "edge" || !popup)
|
|
306
|
+
return;
|
|
307
|
+
const press = (e) => { if (!reduced() && !e.target.closest(CONTROLS))
|
|
308
|
+
popup.setAttribute("data-sheet-pressed", ""); };
|
|
309
|
+
const free = () => popup.removeAttribute("data-sheet-pressed");
|
|
310
|
+
const ends = ["pointerup", "pointercancel"];
|
|
311
|
+
popup.addEventListener("pointerdown", press);
|
|
312
|
+
ends.forEach((n) => window.addEventListener(n, free));
|
|
313
|
+
return () => { popup.removeEventListener("pointerdown", press); ends.forEach((n) => window.removeEventListener(n, free)); };
|
|
314
|
+
}, [form, popup]);
|
|
315
|
+
React.useLayoutEffect(() => {
|
|
316
|
+
if (form === "full" || form === "edge" || standing || !popup)
|
|
317
|
+
return;
|
|
318
|
+
const curve = getComputedStyle(popup).getPropertyValue(`--screen-curve-${Math.min(screen.width, screen.height)}x${Math.max(screen.width, screen.height)}`).trim();
|
|
319
|
+
if (curve)
|
|
320
|
+
popup.style.setProperty("--sheet-screen", curve);
|
|
321
|
+
else
|
|
322
|
+
popup.style.removeProperty("--sheet-screen");
|
|
323
|
+
}, [form, standing, popup]);
|
|
324
|
+
const moveTo = (s) => { setAt(s); onStopChange?.(s); };
|
|
325
|
+
const expanded = current === 1;
|
|
326
|
+
React.useEffect(() => { if (!expanded) {
|
|
327
|
+
const b = popup?.querySelector(".o-sheet-body");
|
|
328
|
+
if (b)
|
|
329
|
+
b.scrollTop = 0;
|
|
330
|
+
} }, [expanded, popup]);
|
|
331
|
+
const close = React.useCallback((reason) => onOpenChange(false, { reason }), [onOpenChange]);
|
|
332
|
+
const closeAll = React.useCallback(() => { closeBelow?.(); release("closed"); close("item-press"); }, [closeBelow, release, close]);
|
|
333
|
+
const body = React.useMemo(() => ({
|
|
334
|
+
onBodyWheel: (e) => { const s = stopAfterWheel(current, e.deltaY); if (s !== current)
|
|
335
|
+
moveTo(s); },
|
|
336
|
+
onBodyFocus: (e) => { const s = stopAfterFocus(current, e.target.getBoundingClientRect().bottom, window.visualViewport?.height ?? window.innerHeight); if (s !== current)
|
|
337
|
+
moveTo(s); },
|
|
338
|
+
}), [current]);
|
|
339
|
+
const focusedIn = React.useRef(true);
|
|
340
|
+
React.useEffect(() => {
|
|
341
|
+
if (!open || !standing)
|
|
342
|
+
return;
|
|
343
|
+
focusedIn.current = true;
|
|
344
|
+
const on = (e) => { const t = e.target; if (t instanceof Element && t !== document.body)
|
|
345
|
+
focusedIn.current = !!(container ?? viewport)?.contains(t); };
|
|
346
|
+
document.addEventListener("focusin", on, true);
|
|
347
|
+
return () => document.removeEventListener("focusin", on, true);
|
|
348
|
+
}, [open, standing, container, viewport]);
|
|
349
|
+
return (_jsx(Base.Root, { open: open && armed, onOpenChangeComplete: (o) => { setComing(false); onOpenChangeComplete?.(o); }, swipeDirection: "down", modal: !standing, disablePointerDismissal: standing, onOpenChange: (o, details) => {
|
|
350
|
+
const from = details.event?.target;
|
|
351
|
+
const elsewhere = from instanceof Element && (from === document.body ? !focusedIn.current : !(container ?? viewport)?.contains(from));
|
|
352
|
+
if (!o && standing && details.reason === "escape-key" && elsewhere) {
|
|
353
|
+
details.cancel();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (!o && details.reason !== "swipe")
|
|
357
|
+
release("closed");
|
|
358
|
+
onOpenChange(o, { reason: closeReasonOf(details.reason) });
|
|
359
|
+
}, snapPoints: points, snapPoint: point, snapToSequentialPoints: true, onSnapPointChange: (p, details) => {
|
|
360
|
+
if (p === null) {
|
|
361
|
+
release("closed", details.event?.timeStamp);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (!open || details.reason !== "swipe")
|
|
365
|
+
return;
|
|
366
|
+
release(offsetOf(p, popup.offsetHeight, viewport.clientHeight), details.event?.timeStamp);
|
|
367
|
+
moveTo(stopOf(p === mark ? "mark" : p, list));
|
|
368
|
+
}, children: _jsxs(Base.Portal, { container: container, children: [_jsx(Base.Backdrop, { ref: backdrop, forceRender: stacked, className: "o-sheet-backdrop", "data-stacked": stacked ? "" : undefined }), _jsxs(Base.Viewport, { ref: setViewport, className: "o-sheet-viewport", "data-sheet-form": form, onClick: standing ? (e) => { if (e.target === e.currentTarget) {
|
|
369
|
+
release("closed");
|
|
370
|
+
close("outside-press");
|
|
371
|
+
} } : undefined, children: [_jsx(Base.Popup, { ref: bindPopup, initialFocus: popupRef, finalFocus: finalFocus ? () => finalFocus() ?? true : undefined, className: "o-sheet o-smooth", "data-sheet-form": form, "aria-label": label, "data-kit": "sheet", children: _jsxs("div", { className: "o-sheet-cut", children: [_jsx("div", { className: "o-sheet-handle", "aria-hidden": "true" }), _jsx(Standing.Provider, { value: standing, children: _jsx(Body.Provider, { value: body, children: _jsx(CloseAll.Provider, { value: closeAll, children: children }) }) })] }) }), coming && _jsx("div", { className: "o-sheet-shield", "aria-hidden": "true", "data-sheet-shield": "", onPointerDown: (e) => { e.preventDefault(); e.stopPropagation(); }, onMouseDown: (e) => { e.preventDefault(); e.stopPropagation(); }, onClick: (e) => e.stopPropagation() })] })] }) }));
|
|
372
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** How the sheet looks. Named for that, never for a use: a height is a stop, not a form. */
|
|
2
|
+
export type SheetForm = "full" | "floating" | "blend" | "edge";
|
|
3
|
+
/** A height it rests at, as Base UI reads one: a share of the window up to 1, px above it; 1 is full. "mark" is measured:
|
|
4
|
+
* 16px under the content's mark, so a longer title moves it. */
|
|
5
|
+
export type SheetStop = number | "mark";
|
|
6
|
+
/** The stops a sheet may be given: small and middle for what has no mark; full is 1. */
|
|
7
|
+
export declare const STOPS: {
|
|
8
|
+
readonly small: 0.3;
|
|
9
|
+
readonly middle: 0.55;
|
|
10
|
+
readonly full: 1;
|
|
11
|
+
};
|
|
12
|
+
export declare const FORMS: Record<SheetForm, {
|
|
13
|
+
stops: SheetStop[];
|
|
14
|
+
}>;
|
|
15
|
+
/** px between the content's mark and the measured stop's edge. */
|
|
16
|
+
export declare const MARK_GAP = 16;
|
|
17
|
+
/** The measured stop's height: the sheet shown from its top to 16px under the mark; null with no mark, or when that
|
|
18
|
+
* reaches its full height. */
|
|
19
|
+
export declare function markStop(sheet: {
|
|
20
|
+
top: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}, markBottom: number | null): number | null;
|
|
23
|
+
/** The mark's bottom from the sheet's top, in the sheet's own pixels: both read on screen, so their distance is divided by
|
|
24
|
+
* `k`, the scale the sheet is drawn at, then as if the body were unscrolled (`scrolled`) and clear of the foot
|
|
25
|
+
* that stands over it (`foot`), both its own. */
|
|
26
|
+
export declare function markBottom(markOnScreen: number, sheetTopOnScreen: number, k: number, scrolled: number, foot: number): number;
|
|
27
|
+
/** Base UI's snap points: the stops, the measured one in px, left out until it is known. */
|
|
28
|
+
export declare const pointsOf: (stops: SheetStop[], mark: number | null) => number[];
|
|
29
|
+
/** The snap point for a stop: full when its measure isn't known. */
|
|
30
|
+
export declare const pointOf: (stop: SheetStop, mark: number | null) => number;
|
|
31
|
+
/** Back from Base UI. */
|
|
32
|
+
export declare const stopOf: (point: number | string | null, stops: SheetStop[]) => SheetStop;
|
|
33
|
+
/** The sheet shown at a point, as the offset from its full height, as Base UI places it. */
|
|
34
|
+
export declare function offsetOf(point: number, sheet: number, window: number): number;
|
|
35
|
+
/** A wheel or a scroll down at a lower stop goes to full; nothing else moves. */
|
|
36
|
+
export declare const stopAfterWheel: (stop: SheetStop, deltaY: number) => SheetStop;
|
|
37
|
+
/** Focus on something under the visible part goes to full. */
|
|
38
|
+
export declare const stopAfterFocus: (stop: SheetStop, bottom: number, visible: number) => SheetStop;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const STOPS = { small: 0.3, middle: 0.55, full: 1 };
|
|
2
|
+
export const FORMS = {
|
|
3
|
+
full: { stops: [STOPS.full] },
|
|
4
|
+
floating: { stops: [STOPS.full] },
|
|
5
|
+
blend: { stops: [STOPS.middle, STOPS.full] },
|
|
6
|
+
edge: { stops: [STOPS.full] },
|
|
7
|
+
};
|
|
8
|
+
export const MARK_GAP = 16;
|
|
9
|
+
export function markStop(sheet, markBottom) {
|
|
10
|
+
if (markBottom === null)
|
|
11
|
+
return null;
|
|
12
|
+
const shown = markBottom + MARK_GAP - sheet.top;
|
|
13
|
+
return shown >= sheet.height - 1 ? null : shown;
|
|
14
|
+
}
|
|
15
|
+
export function markBottom(markOnScreen, sheetTopOnScreen, k, scrolled, foot) {
|
|
16
|
+
return (markOnScreen - sheetTopOnScreen) / k + scrolled + foot;
|
|
17
|
+
}
|
|
18
|
+
export const pointsOf = (stops, mark) => stops.flatMap((s) => (s !== "mark" ? [s] : mark === null ? [] : [mark]));
|
|
19
|
+
export const pointOf = (stop, mark) => (stop !== "mark" ? stop : mark ?? 1);
|
|
20
|
+
export const stopOf = (point, stops) => stops.includes(point) ? point : stops.includes("mark") ? "mark" : 1;
|
|
21
|
+
export function offsetOf(point, sheet, window) {
|
|
22
|
+
const height = point <= 1 ? point * window : point;
|
|
23
|
+
return Math.max(0, sheet - Math.min(height, Math.min(sheet, window)));
|
|
24
|
+
}
|
|
25
|
+
export const stopAfterWheel = (stop, deltaY) => (stop !== 1 && deltaY > 0 ? 1 : stop);
|
|
26
|
+
export const stopAfterFocus = (stop, bottom, visible) => (stop !== 1 && bottom > visible ? 1 : stop);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const steps = (ids) => ids.map((id) => ({ id, name: id }));
|
|
2
|
+
const options = [
|
|
3
|
+
{ id: "spring", name: "The sheet's spring", def: "quick", values: [{ id: "smooth", name: "Smooth" }, { id: "quick", name: "Quick" }, { id: "lively", name: "Lively" }] },
|
|
4
|
+
{ id: "corners", name: "Corners", def: "2xl", kind: "steps", values: steps(["lg", "xl", "2xl", "3xl", "4xl", "5xl"]) },
|
|
5
|
+
{ id: "smoothing", name: "Corner smoothing", def: "smooth", values: [{ id: "round", name: "Round" }, { id: "smooth", name: "Smooth" }] },
|
|
6
|
+
{ id: "margin", name: "Floating margins", def: "8", kind: "steps", values: steps(["4", "6", "8", "10", "12"]) },
|
|
7
|
+
{ id: "padding", name: "Side padding", def: "page", values: [{ id: "page", name: "Page" }, ...steps(["12", "16", "20", "24"])] },
|
|
8
|
+
{ id: "dim", name: "The dim", def: "light", values: [{ id: "deep", name: "Dark" }, { id: "light", name: "Light" }] },
|
|
9
|
+
];
|
|
10
|
+
export const SHEET_LOOKS = { id: "sheet", name: "Sheet", options, looks: [] };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useViews } from "../../provider/context.js";
|
|
3
|
+
import { Sheet, SheetBody, SheetButton, SheetHead } from "./bottom-sheet.js";
|
|
4
|
+
export function MapSheet({ open, onOpenChange, label, actions, children }) {
|
|
5
|
+
const { icons } = useViews();
|
|
6
|
+
const name = label ?? "";
|
|
7
|
+
const left = actions?.back ?? actions?.close;
|
|
8
|
+
const Back = icons.back, Close = icons.close, Check = icons.check;
|
|
9
|
+
return (_jsxs(Sheet, { open: open, onOpenChange: (next, d) => onOpenChange(next, { reason: d.reason }), label: name, children: [actions && left
|
|
10
|
+
? _jsx(SheetHead, { title: name, left: _jsx(SheetButton, { "aria-label": left.label, className: actions.back ? "o-sheet-back" : undefined, icon: actions.back ? _jsx(Back, {}) : _jsx(Close, {}), onClick: left.onPress }), right: actions.done ? _jsx(SheetButton, { kind: "primary", "aria-label": actions.done.label, icon: _jsx(Check, {}), onClick: actions.done.onPress }) : _jsx("span", {}) })
|
|
11
|
+
: _jsx(SheetHead, { title: name }), _jsx(SheetBody, { children: children })] }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** A spring as its token holds it: how long it takes (the response, in seconds) and how much it is damped, 1 for none past. */
|
|
2
|
+
export interface Spring {
|
|
3
|
+
response: number;
|
|
4
|
+
damping: number;
|
|
5
|
+
}
|
|
6
|
+
export interface Settle {
|
|
7
|
+
ease: string;
|
|
8
|
+
time: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The settle for a move of `distance` px, leaving at `speed` px/ms along the same axis (a throw the way it is going has
|
|
12
|
+
* the distance's sign). Null when there is nothing to move.
|
|
13
|
+
* - past: how far past rest it may swing, in px; the speed is cut to keep it there.
|
|
14
|
+
* - exit: it is leaving the screen. It ends the moment it arrives, still moving, aiming that many px beyond the edge, so
|
|
15
|
+
* the spring's long tail, which would crawl out of sight, is never played.
|
|
16
|
+
*/
|
|
17
|
+
export declare function settle(distance: number, speed: number, spring: Spring, { past, exit }?: {
|
|
18
|
+
past?: number;
|
|
19
|
+
exit?: number;
|
|
20
|
+
}): Settle | null;
|
|
21
|
+
/** A spring token's value ("500ms 1") as a Spring. */
|
|
22
|
+
export declare function springOf(token: string): Spring;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
function away(t, from, speed, { response, damping }) {
|
|
2
|
+
const w = (2 * Math.PI) / response;
|
|
3
|
+
if (damping >= 1)
|
|
4
|
+
return (from + (speed + w * from) * t) * Math.exp(-w * t);
|
|
5
|
+
const d = w * Math.sqrt(1 - damping * damping);
|
|
6
|
+
return Math.exp(-damping * w * t) * (from * Math.cos(d * t) + ((speed + damping * w * from) / d) * Math.sin(d * t));
|
|
7
|
+
}
|
|
8
|
+
const STEP = 1 / 120, LONGEST = 4;
|
|
9
|
+
function peak(from, speed, spring) {
|
|
10
|
+
let most = 0;
|
|
11
|
+
for (let t = 0; t < LONGEST * spring.response; t += STEP)
|
|
12
|
+
most = Math.max(most, -Math.sign(from) * away(t, from, speed, spring));
|
|
13
|
+
return most;
|
|
14
|
+
}
|
|
15
|
+
export function settle(distance, speed, spring, { past = Infinity, exit } = {}) {
|
|
16
|
+
if (Math.abs(distance) < 0.5)
|
|
17
|
+
return null;
|
|
18
|
+
const rest = exit === undefined ? distance : distance + Math.sign(distance) * exit, from = -rest;
|
|
19
|
+
let v = speed * 1000;
|
|
20
|
+
if (exit === undefined && Number.isFinite(past) && peak(from, v, spring) > past) {
|
|
21
|
+
let low = 0, high = 1;
|
|
22
|
+
for (let i = 0; i < 10; i++) {
|
|
23
|
+
const mid = (low + high) / 2;
|
|
24
|
+
if (peak(from, v * mid, spring) > past)
|
|
25
|
+
high = mid;
|
|
26
|
+
else
|
|
27
|
+
low = mid;
|
|
28
|
+
}
|
|
29
|
+
v *= low;
|
|
30
|
+
}
|
|
31
|
+
const at = (t) => (rest + away(t, from, v, spring)) / distance;
|
|
32
|
+
let time = 0;
|
|
33
|
+
if (exit !== undefined) {
|
|
34
|
+
while (time < LONGEST * spring.response && at(time) < 1)
|
|
35
|
+
time += STEP;
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
for (let t = STEP; t < LONGEST * spring.response; t += STEP)
|
|
39
|
+
if (Math.abs(at(t) - 1) * Math.abs(distance) > 0.5)
|
|
40
|
+
time = t + STEP;
|
|
41
|
+
const points = Math.max(12, Math.min(60, Math.round(time * 60)));
|
|
42
|
+
const ys = Array.from({ length: points + 1 }, (_, i) => (i === points ? 1 : at((i / points) * time)));
|
|
43
|
+
return { ease: `linear(${ys.map((y) => +y.toFixed(4)).join(", ")})`, time: Math.round(time * 1000) };
|
|
44
|
+
}
|
|
45
|
+
export function springOf(token) {
|
|
46
|
+
const [response, damping] = token.trim().split(/\s+/);
|
|
47
|
+
return { response: (parseFloat(response) || 500) / 1000, damping: Number(damping) || 1 };
|
|
48
|
+
}
|