@alulore/kumiko 0.20.1 → 0.21.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/dist/avatar/avatar.js +1 -1
- package/dist/badge/badge.css +41 -3
- package/dist/badge/badge.js +11 -4
- package/dist/board/board-slots.js +2 -1
- package/dist/board/scrollbar-gutter.js +26 -2
- package/dist/button/button.css +21 -7
- package/dist/card/card.css +3 -2
- package/dist/card/item-card.d.ts +1 -1
- package/dist/card/item-card.js +3 -2
- package/dist/chip/chip.css +6 -10
- package/dist/chip/chip.js +1 -1
- package/dist/form/error-line.js +4 -3
- package/dist/input/input.css +99 -114
- package/dist/list-row/list-row-motion.js +29 -10
- package/dist/media-viewer/gesture-press.d.ts +1 -0
- package/dist/media-viewer/gesture-press.js +12 -0
- package/dist/media-viewer/media-slide.d.ts +3 -1
- package/dist/media-viewer/media-slide.js +3 -2
- package/dist/media-viewer/media-viewer.css +5 -1
- package/dist/media-viewer/media-viewer.js +41 -23
- package/dist/media-viewer/stage-rect.d.ts +16 -0
- package/dist/media-viewer/stage-rect.js +56 -0
- package/dist/media-viewer/view-gesture.d.ts +1 -2
- package/dist/media-viewer/view-gesture.js +39 -44
- package/dist/media-viewer/viewer-chrome.d.ts +2 -1
- package/dist/media-viewer/viewer-chrome.js +3 -1
- package/dist/media-viewer/viewer-motion.d.ts +1 -0
- package/dist/media-viewer/viewer-motion.js +20 -7
- package/dist/media-viewer/zoom-pan.d.ts +1 -0
- package/dist/media-viewer/zoom-pan.js +3 -0
- package/dist/media-viewer/zoom-store.d.ts +8 -0
- package/dist/media-viewer/zoom-store.js +30 -0
- package/dist/menu/menu.js +6 -3
- package/dist/menu/point-menu.js +32 -12
- package/dist/motion/flip.js +33 -20
- package/dist/page/page-actions.js +2 -1
- package/dist/page/page-breadcrumbs.js +2 -1
- package/dist/page/use-measured-fit.d.ts +5 -0
- package/dist/page/use-measured-fit.js +47 -5
- package/dist/page/use-stuck.js +12 -2
- package/dist/pagination/pagination-fit.d.ts +3 -1
- package/dist/pagination/pagination-fit.js +4 -3
- package/dist/pagination/pagination-motion.js +18 -11
- package/dist/pagination/pagination.css +50 -6
- package/dist/pagination/pagination.js +20 -3
- package/dist/progress/progress.css +3 -2
- package/dist/progress/progress.js +15 -3
- package/dist/select/select-labels.d.ts +2 -0
- package/dist/select/select-labels.js +5 -1
- package/dist/select/select.css +7 -11
- package/dist/select/select.d.ts +1 -1
- package/dist/select/select.js +12 -6
- package/dist/shortcuts/hints.js +10 -4
- package/dist/shortcuts/provider.d.ts +4 -2
- package/dist/shortcuts/provider.js +14 -17
- package/dist/skeleton/skeleton.css +22 -9
- package/dist/slider/slider-feel.js +18 -6
- package/dist/slider/slider.css +9 -10
- package/dist/slider/slider.js +13 -10
- package/dist/smooth-caret/caret-controller.js +18 -6
- package/dist/smooth-caret/caret-geometry.js +18 -7
- package/dist/smooth-caret/caret-glide.js +3 -2
- package/dist/smooth-caret/remote-carets.js +20 -3
- package/dist/smooth-caret/smooth-caret.css +1 -1
- package/dist/switch/switch-gesture.d.ts +4 -4
- package/dist/switch/switch-gesture.js +52 -14
- package/dist/switch/switch.css +12 -13
- package/dist/switch/switch.d.ts +2 -1
- package/dist/switch/switch.js +4 -6
- package/dist/table/data-table.js +32 -12
- package/dist/table/table-cells.d.ts +20 -8
- package/dist/table/table-cells.js +18 -20
- package/dist/table/table-model.d.ts +0 -2
- package/dist/table/table-model.js +15 -9
- package/dist/table/table-search.d.ts +12 -0
- package/dist/table/table-search.js +34 -0
- package/dist/table/table-sections.d.ts +3 -2
- package/dist/table/table-sections.js +16 -13
- package/dist/table/table.css +2 -14
- package/dist/table/use-latest.d.ts +6 -0
- package/dist/table/use-latest.js +22 -0
- package/dist/table/use-table-view.js +36 -24
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useLayoutEffect } from "react";
|
|
1
|
+
import { useLayoutEffect, useRef } from "react";
|
|
2
2
|
/* The rows a person can reach: not static, not disabled. */
|
|
3
3
|
export const ROW = '[data-slot="list-row"]:not([data-static]):not(:disabled)';
|
|
4
4
|
const OWNER = '[data-kumiko-list-row~="roving"], [data-kumiko-list-row~="no-roving"]';
|
|
@@ -7,6 +7,10 @@ export function isRoving(list) {
|
|
|
7
7
|
const owner = list.closest(OWNER);
|
|
8
8
|
return owner === null || !owner.dataset.kumikoListRow?.split(" ").includes("no-roving");
|
|
9
9
|
}
|
|
10
|
+
/* A glider only shows, and so only needs placing, under a container that glides. */
|
|
11
|
+
function isGliding(glider) {
|
|
12
|
+
return glider !== null && glider.matches('[data-kumiko-list-row~="glide"] *');
|
|
13
|
+
}
|
|
10
14
|
/* Puts a glider over a row and copies the row's look onto it. */
|
|
11
15
|
function place(glider, row) {
|
|
12
16
|
const style = glider.style;
|
|
@@ -74,6 +78,12 @@ export function targetRow(list, row, key) {
|
|
|
74
78
|
]).get(key);
|
|
75
79
|
return to === undefined ? null : (rows[to] ?? null);
|
|
76
80
|
}
|
|
81
|
+
/* Moves the hover wash to a row, but only when it glides: otherwise it never shows, so placing it is wasted layout. */
|
|
82
|
+
function hoverAt(glider, row) {
|
|
83
|
+
if (isGliding(glider)) {
|
|
84
|
+
show(glider, row);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
/* The list's own handlers: the hover wash follows the mouse, focus moves the Tab stop and the arrows move focus. Each also calls the app's handler first. */
|
|
78
88
|
export function useListHandlers(app, list, hoverGlide, stop) {
|
|
79
89
|
const rowOf = (target) => {
|
|
@@ -84,7 +94,7 @@ export function useListHandlers(app, list, hoverGlide, stop) {
|
|
|
84
94
|
onPointerOver: (event) => {
|
|
85
95
|
app.onPointerOver?.(event);
|
|
86
96
|
if (event.pointerType === "mouse") {
|
|
87
|
-
|
|
97
|
+
hoverAt(hoverGlide.current, rowOf(event.target));
|
|
88
98
|
}
|
|
89
99
|
},
|
|
90
100
|
onPointerLeave: (event) => {
|
|
@@ -115,28 +125,37 @@ export function useListHandlers(app, list, hoverGlide, stop) {
|
|
|
115
125
|
}
|
|
116
126
|
/* After every render and every change of the rows: place the current glider and set the Tab stop. */
|
|
117
127
|
export function useListSync(list, glider, stop) {
|
|
128
|
+
const sync = () => {
|
|
129
|
+
const element = list.current;
|
|
130
|
+
if (!element) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
show(glider.current, element.querySelector("[data-current]"));
|
|
134
|
+
syncRoving(element, stop.current);
|
|
135
|
+
};
|
|
136
|
+
const latest = useRef(sync);
|
|
137
|
+
useLayoutEffect(() => {
|
|
138
|
+
latest.current = sync;
|
|
139
|
+
sync();
|
|
140
|
+
});
|
|
118
141
|
useLayoutEffect(() => {
|
|
119
142
|
const element = list.current;
|
|
120
143
|
if (!element) {
|
|
121
144
|
return undefined;
|
|
122
145
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
syncRoving(element, stop.current);
|
|
126
|
-
};
|
|
127
|
-
sync();
|
|
128
|
-
const mutations = new MutationObserver(sync);
|
|
146
|
+
const run = () => latest.current();
|
|
147
|
+
const mutations = new MutationObserver(run);
|
|
129
148
|
mutations.observe(element, {
|
|
130
149
|
subtree: true,
|
|
131
150
|
childList: true,
|
|
132
151
|
attributes: true,
|
|
133
152
|
attributeFilter: ["data-current", "disabled"]
|
|
134
153
|
});
|
|
135
|
-
const sizes = new ResizeObserver(
|
|
154
|
+
const sizes = new ResizeObserver(run);
|
|
136
155
|
sizes.observe(element);
|
|
137
156
|
return () => {
|
|
138
157
|
mutations.disconnect();
|
|
139
158
|
sizes.disconnect();
|
|
140
159
|
};
|
|
141
|
-
});
|
|
160
|
+
}, [list]);
|
|
142
161
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pressIsForSomethingElse(event: PointerEvent): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Whether a press belongs to something else: a control, a link, a field, the browser's own video bar, or a button other than the main one. */
|
|
2
|
+
export function pressIsForSomethingElse(event) {
|
|
3
|
+
const target = event.target;
|
|
4
|
+
if (target instanceof Element && target.closest("button, a, input, [data-mv-control]")) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (target instanceof HTMLVideoElement && target.controls) {
|
|
8
|
+
/* The browser's own bar sits along the bottom of the video, and keeps its touches. */
|
|
9
|
+
return event.clientY > target.getBoundingClientRect().bottom - 56;
|
|
10
|
+
}
|
|
11
|
+
return event.pointerType === "mouse" && event.button !== 0;
|
|
12
|
+
}
|
|
@@ -11,4 +11,6 @@ export interface MediaSlideProps {
|
|
|
11
11
|
/** Receives the slide's gesture while it is active, so buttons and keys can zoom it. */
|
|
12
12
|
gestureRef: React.RefObject<ViewGesture | null>;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
declare function Slide(props: MediaSlideProps): React.JSX.Element;
|
|
15
|
+
export declare const MediaSlide: import("react").MemoExoticComponent<typeof Slide>;
|
|
16
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { memo, useEffect, useRef } from "react";
|
|
3
3
|
import { VideoControls } from "./video-controls";
|
|
4
4
|
import { ViewGesture } from "./view-gesture";
|
|
5
5
|
function naturalOf(item, media) {
|
|
@@ -55,7 +55,7 @@ function Clip({ item, video, controls }) {
|
|
|
55
55
|
const style = { "--mv-ratio": String(ratio) };
|
|
56
56
|
return (_jsxs("div", { "data-mv-clip": "", style: style, children: [_jsx("video", { ref: video, "data-mv-media": "", src: item.src, poster: item.poster, "aria-label": item.name, controls: controls === "native", playsInline: true, loop: true, preload: "metadata" }), controls === "custom" ? _jsx(VideoControls, { video: video }) : null] }));
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
function Slide(props) {
|
|
59
59
|
const { item, active, videoControls } = props;
|
|
60
60
|
const stage = useRef(null);
|
|
61
61
|
const image = useRef(null);
|
|
@@ -65,3 +65,4 @@ export function MediaSlide(props) {
|
|
|
65
65
|
useVideoPause(video, active);
|
|
66
66
|
return (_jsx("div", { ref: stage, "data-mv-stage": "", "data-active": active ? "" : undefined, "data-kind": isVideo ? "video" : "image", "data-native-controls": isVideo && videoControls === "native" ? "" : undefined, children: isVideo ? (_jsx(Clip, { item: item, video: video, controls: videoControls })) : (_jsx(Picture, { item: item, media: image })) }));
|
|
67
67
|
}
|
|
68
|
+
export const MediaSlide = memo(Slide);
|
|
@@ -205,10 +205,14 @@
|
|
|
205
205
|
max-block-size: 100%;
|
|
206
206
|
transform: translate(var(--mv-x, 0px), var(--mv-y, 0px)) scale(var(--mv-scale, 1));
|
|
207
207
|
transform-origin: center;
|
|
208
|
-
will-change: transform;
|
|
209
208
|
-webkit-user-drag: none;
|
|
210
209
|
}
|
|
211
210
|
|
|
211
|
+
/* Only the slide in view zooms and pans, so only its picture gets a layer of its own. */
|
|
212
|
+
[data-mv-stage][data-kind="image"][data-active] [data-mv-media] {
|
|
213
|
+
will-change: transform;
|
|
214
|
+
}
|
|
215
|
+
|
|
212
216
|
/* A clip fills a box of its own shape that fits the frame, so its controls sit on the video. */
|
|
213
217
|
[data-mv-clip] {
|
|
214
218
|
position: relative;
|
|
@@ -7,7 +7,8 @@ import { MediaSlide } from "./media-slide";
|
|
|
7
7
|
import { PagerDrag } from "./pager-drag";
|
|
8
8
|
import { behaviourDefaults, lookDefaults } from "./types";
|
|
9
9
|
import { ViewerChrome } from "./viewer-chrome";
|
|
10
|
-
import { closeToThumbnail, useChrome, useOpenFromThumbnail } from "./viewer-motion";
|
|
10
|
+
import { clearFlights, closeToThumbnail, useChrome, useOpenFromThumbnail } from "./viewer-motion";
|
|
11
|
+
import { createZoomStore, useZoomed } from "./zoom-store";
|
|
11
12
|
function defined(value, fallback) {
|
|
12
13
|
return value ?? fallback;
|
|
13
14
|
}
|
|
@@ -51,25 +52,37 @@ function zoomKey(event) {
|
|
|
51
52
|
}
|
|
52
53
|
return event.key === "0" ? "reset" : null;
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
/* One options object per kind of item, so a slide gets the same one on every render. */
|
|
56
|
+
function useSlideOptions(set) {
|
|
57
|
+
const { wheel, zoomAnchor, zoomedDrag, swipeDownClose, doubleTap, paging } = set;
|
|
58
|
+
return useMemo(() => {
|
|
59
|
+
const shared = {
|
|
60
|
+
wheel,
|
|
61
|
+
anchor: zoomAnchor,
|
|
62
|
+
zoomedDrag,
|
|
63
|
+
swipeDownClose,
|
|
64
|
+
doubleTap,
|
|
65
|
+
pagingFollows: paging !== "slide"
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
still: { ...shared, zoomable: true },
|
|
69
|
+
clip: { ...shared, zoomable: false }
|
|
70
|
+
};
|
|
71
|
+
}, [wheel, zoomAnchor, zoomedDrag, swipeDownClose, doubleTap, paging]);
|
|
72
|
+
}
|
|
73
|
+
function slideFor(props, options, item, active) {
|
|
55
74
|
const { set, gestureRef, signals } = props;
|
|
56
|
-
return (_jsx(MediaSlide, { item: item, active: active, signals: signals, gestureRef: gestureRef, videoControls: set.videoControls, options:
|
|
57
|
-
wheel: set.wheel,
|
|
58
|
-
anchor: set.zoomAnchor,
|
|
59
|
-
zoomedDrag: set.zoomedDrag,
|
|
60
|
-
swipeDownClose: set.swipeDownClose,
|
|
61
|
-
doubleTap: set.doubleTap,
|
|
62
|
-
pagingFollows: set.paging !== "slide",
|
|
63
|
-
zoomable: item.kind !== "video"
|
|
64
|
-
} }));
|
|
75
|
+
return (_jsx(MediaSlide, { item: item, active: active, signals: signals, gestureRef: gestureRef, videoControls: set.videoControls, options: item.kind === "video" ? options.clip : options.still }));
|
|
65
76
|
}
|
|
66
77
|
/*
|
|
67
78
|
* The slides are a carousel: scroll-snap, loop, keys and a mouse drag are its own. A finger is not,
|
|
68
79
|
* because the stage owns touch (pager-drag.ts). Crossfade and instant show one item at a time.
|
|
69
80
|
*/
|
|
70
81
|
function Pager(props) {
|
|
71
|
-
const { items, index, set,
|
|
72
|
-
const
|
|
82
|
+
const { items, index, set, zoom, controller } = props;
|
|
83
|
+
const zoomed = useZoomed(zoom);
|
|
84
|
+
const options = useSlideOptions(set);
|
|
85
|
+
const slide = (item, active) => slideFor(props, options, item, active);
|
|
73
86
|
const current = items[index];
|
|
74
87
|
const labels = useLabels();
|
|
75
88
|
if (set.paging !== "slide") {
|
|
@@ -146,8 +159,11 @@ function useClosing(props, set, content) {
|
|
|
146
159
|
if (open) {
|
|
147
160
|
busy.current = false;
|
|
148
161
|
setClosing(false);
|
|
162
|
+
if (content) {
|
|
163
|
+
clearFlights(content);
|
|
164
|
+
}
|
|
149
165
|
}
|
|
150
|
-
}, [open]);
|
|
166
|
+
}, [open, content]);
|
|
151
167
|
const requestClose = useCallback(() => {
|
|
152
168
|
if (busy.current) {
|
|
153
169
|
return;
|
|
@@ -174,7 +190,7 @@ function useParts(props, set) {
|
|
|
174
190
|
const [content, setContent] = useState(null);
|
|
175
191
|
const contentRef = useRef(null);
|
|
176
192
|
contentRef.current = content;
|
|
177
|
-
const [zoom
|
|
193
|
+
const [zoom] = useState(createZoomStore);
|
|
178
194
|
const [controller] = useState(createCarouselController);
|
|
179
195
|
const gestureRef = useRef(null);
|
|
180
196
|
const go = useGo(props, set);
|
|
@@ -186,15 +202,17 @@ function useParts(props, set) {
|
|
|
186
202
|
useOpenFromThumbnail(content, props.index, set.openMotion, props.getOrigin);
|
|
187
203
|
const onKeyDown = useViewerKeys(step, gestureRef);
|
|
188
204
|
const [pagerDrag] = useState(() => new PagerDrag(() => contentRef.current, (direction) => goRef.current(direction)));
|
|
189
|
-
const
|
|
205
|
+
const latest = useRef({ step, requestClose, toggle: chrome.toggle });
|
|
206
|
+
latest.current = { step, requestClose, toggle: chrome.toggle };
|
|
207
|
+
const [signals] = useState(() => ({
|
|
190
208
|
dragPager: pagerDrag.drag,
|
|
191
209
|
releasePager: pagerDrag.release,
|
|
192
|
-
onView: (view) =>
|
|
193
|
-
onPage: step,
|
|
194
|
-
onDismissProgress: (progress) =>
|
|
195
|
-
onDismiss: requestClose,
|
|
196
|
-
onTap:
|
|
197
|
-
};
|
|
210
|
+
onView: (view) => zoom.set(Math.round(view.scale * 100) / 100),
|
|
211
|
+
onPage: (direction) => latest.current.step(direction),
|
|
212
|
+
onDismissProgress: (progress) => contentRef.current?.style.setProperty("--mv-dismiss", String(progress)),
|
|
213
|
+
onDismiss: () => latest.current.requestClose(),
|
|
214
|
+
onTap: () => latest.current.toggle()
|
|
215
|
+
}));
|
|
198
216
|
return {
|
|
199
217
|
content,
|
|
200
218
|
setContent,
|
|
@@ -214,7 +232,7 @@ function Interior({ props, set, parts }) {
|
|
|
214
232
|
const { items, index, onIndexChange } = props;
|
|
215
233
|
const { zoom, controller, gestureRef } = parts;
|
|
216
234
|
const item = items[index];
|
|
217
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { "data-mv-body": "", children: _jsx(Pager, { items: items, index: index, set: set,
|
|
235
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { "data-mv-body": "", children: _jsx(Pager, { items: items, index: index, set: set, zoom: zoom, controller: controller, gestureRef: gestureRef, signals: parts.signals, onIndexChange: onIndexChange, pagerBusy: parts.pagerBusy }) }), _jsx(ViewerChrome, { items: items, index: index, zoom: zoom, zoomable: item?.kind !== "video", onGo: (at) => set.paging === "slide" ? controller.setPage(at + 1) : onIndexChange(at), onStep: parts.step, onZoom: (factor) => gestureRef.current?.zoomBy(factor), onFit: () => gestureRef.current?.reset(), onFullscreen: () => toggleFullscreen(parts.content) })] }));
|
|
218
236
|
}
|
|
219
237
|
/**
|
|
220
238
|
* Shows images and video full screen: zoom and pan, swiping between items, closing.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Point, Size } from "./zoom-pan";
|
|
2
|
+
export declare function centreOf(rect: DOMRect, x: number, y: number): Point;
|
|
3
|
+
export declare class StageRect {
|
|
4
|
+
dragScale: number;
|
|
5
|
+
private held;
|
|
6
|
+
private heldAt;
|
|
7
|
+
private readonly stage;
|
|
8
|
+
private readonly observer;
|
|
9
|
+
constructor(stage: HTMLElement);
|
|
10
|
+
read(): DOMRect;
|
|
11
|
+
size(): Size;
|
|
12
|
+
hold(): void;
|
|
13
|
+
release(): void;
|
|
14
|
+
within<Result>(run: () => Result): Result;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export function centreOf(rect, x, y) {
|
|
2
|
+
return { x: x - rect.left - rect.width / 2, y: y - rect.top - rect.height / 2 };
|
|
3
|
+
}
|
|
4
|
+
/*
|
|
5
|
+
* The stage's box, read once for a whole gesture or step instead of after every style write, which would force a
|
|
6
|
+
* layout each time. A gesture holds it from the first press to the last release and a resize reads it again.
|
|
7
|
+
*/
|
|
8
|
+
export class StageRect {
|
|
9
|
+
/* The scale a swipe down puts on the stage: a box read before it is unscaled, one read live is not. */
|
|
10
|
+
dragScale = 1;
|
|
11
|
+
held = null;
|
|
12
|
+
heldAt = 1;
|
|
13
|
+
stage;
|
|
14
|
+
observer;
|
|
15
|
+
constructor(stage) {
|
|
16
|
+
this.stage = stage;
|
|
17
|
+
this.observer = new ResizeObserver(() => {
|
|
18
|
+
if (this.held) {
|
|
19
|
+
this.hold();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
this.observer.observe(stage);
|
|
23
|
+
}
|
|
24
|
+
read() {
|
|
25
|
+
return this.held ?? this.stage.getBoundingClientRect();
|
|
26
|
+
}
|
|
27
|
+
size() {
|
|
28
|
+
const rect = this.read();
|
|
29
|
+
const scale = this.held ? this.dragScale / this.heldAt : 1;
|
|
30
|
+
return { w: rect.width * scale, h: rect.height * scale };
|
|
31
|
+
}
|
|
32
|
+
hold() {
|
|
33
|
+
this.heldAt = this.dragScale;
|
|
34
|
+
this.held = this.stage.getBoundingClientRect();
|
|
35
|
+
}
|
|
36
|
+
release() {
|
|
37
|
+
this.held = null;
|
|
38
|
+
}
|
|
39
|
+
/* Runs a step with the box read once, unless a gesture already holds it. */
|
|
40
|
+
within(run) {
|
|
41
|
+
if (this.held) {
|
|
42
|
+
return run();
|
|
43
|
+
}
|
|
44
|
+
this.hold();
|
|
45
|
+
try {
|
|
46
|
+
return run();
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
this.release();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
destroy() {
|
|
53
|
+
this.observer.disconnect();
|
|
54
|
+
this.held = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -32,6 +32,7 @@ export declare class ViewGesture {
|
|
|
32
32
|
private lastPage;
|
|
33
33
|
private settleTimer;
|
|
34
34
|
private dragX;
|
|
35
|
+
private readonly box;
|
|
35
36
|
private readonly stage;
|
|
36
37
|
private readonly options;
|
|
37
38
|
private readonly hooks;
|
|
@@ -39,14 +40,12 @@ export declare class ViewGesture {
|
|
|
39
40
|
destroy(): void;
|
|
40
41
|
zoomBy(factor: number): void;
|
|
41
42
|
reset(): void;
|
|
42
|
-
private size;
|
|
43
43
|
private measure;
|
|
44
44
|
private write;
|
|
45
45
|
private writeDrag;
|
|
46
46
|
private settleTo;
|
|
47
47
|
private endSettling;
|
|
48
48
|
private rtl;
|
|
49
|
-
private ignores;
|
|
50
49
|
private readonly onDown;
|
|
51
50
|
private startSingle;
|
|
52
51
|
private startPinch;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { createVelocityTracker } from "@ui-sdk/react/gesture";
|
|
2
2
|
import { readMotion } from "../motion/flip";
|
|
3
|
-
import {
|
|
3
|
+
import { pressIsForSomethingElse } from "./gesture-press";
|
|
4
|
+
import { centreOf, StageRect } from "./stage-rect";
|
|
5
|
+
import { FIT, actualScale, clamp, clampPan, coast, doubleTapScale, fitSize, middle, maxScale, overshoot, panLimits, pinchView, shouldPage, softPan, wheelFactor, zoomTo } from "./zoom-pan";
|
|
4
6
|
const SLOP = 8;
|
|
5
7
|
const DOUBLE_MS = 300;
|
|
6
8
|
const PAGE_COOLDOWN = 420;
|
|
7
9
|
const EDGE_PAGE_PX = 70;
|
|
8
10
|
const FRICTION = 0.995;
|
|
9
11
|
const ORIGIN = { x: 0, y: 0 };
|
|
10
|
-
function centreOf(rect, x, y) {
|
|
11
|
-
return { x: x - rect.left - rect.width / 2, y: y - rect.top - rect.height / 2 };
|
|
12
|
-
}
|
|
13
|
-
function middle(a, b) {
|
|
14
|
-
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
15
|
-
}
|
|
16
12
|
/*
|
|
17
13
|
* Drives one slide's stage with pointers, wheel and taps: pinch, drag, inertia, double tap,
|
|
18
14
|
* swipe down to close and (without a carousel) swipe to page. It writes the view as CSS
|
|
@@ -32,6 +28,7 @@ export class ViewGesture {
|
|
|
32
28
|
lastPage = 0;
|
|
33
29
|
settleTimer = 0;
|
|
34
30
|
dragX = 0;
|
|
31
|
+
box;
|
|
35
32
|
stage;
|
|
36
33
|
options;
|
|
37
34
|
hooks;
|
|
@@ -39,6 +36,7 @@ export class ViewGesture {
|
|
|
39
36
|
this.stage = stage;
|
|
40
37
|
this.options = options;
|
|
41
38
|
this.hooks = hooks;
|
|
39
|
+
this.box = new StageRect(stage);
|
|
42
40
|
stage.addEventListener("pointerdown", this.onDown);
|
|
43
41
|
stage.addEventListener("pointermove", this.onMove);
|
|
44
42
|
stage.addEventListener("pointerup", this.onUp);
|
|
@@ -52,31 +50,30 @@ export class ViewGesture {
|
|
|
52
50
|
this.stage.removeEventListener("pointerup", this.onUp);
|
|
53
51
|
this.stage.removeEventListener("pointercancel", this.onCancel);
|
|
54
52
|
this.stage.removeEventListener("wheel", this.onWheel);
|
|
53
|
+
this.box.destroy();
|
|
55
54
|
cancelAnimationFrame(this.frame);
|
|
56
55
|
window.clearTimeout(this.tapTimer);
|
|
57
56
|
window.clearTimeout(this.settleTimer);
|
|
58
57
|
}
|
|
59
58
|
/* A zoom step from a button or a key, around the centre of the frame. */
|
|
60
59
|
zoomBy(factor) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
this.box.within(() => {
|
|
61
|
+
const { fit, max } = this.measure();
|
|
62
|
+
const scale = clamp(this.view.scale * factor, 1, max);
|
|
63
|
+
const grown = zoomTo(this.view, scale, ORIGIN, "center");
|
|
64
|
+
this.settleTo(scale <= 1.01 ? FIT : clampPan(grown, panLimits(fit, this.box.size(), scale)));
|
|
65
|
+
});
|
|
65
66
|
}
|
|
66
67
|
reset() {
|
|
67
68
|
this.settleTo(FIT);
|
|
68
69
|
}
|
|
69
|
-
size() {
|
|
70
|
-
const rect = this.stage.getBoundingClientRect();
|
|
71
|
-
return { w: rect.width, h: rect.height };
|
|
72
|
-
}
|
|
73
70
|
measure() {
|
|
74
71
|
const natural = this.hooks().natural();
|
|
75
|
-
const fit = fitSize(natural, this.size());
|
|
72
|
+
const fit = fitSize(natural, this.box.size());
|
|
76
73
|
return {
|
|
77
74
|
fit,
|
|
78
75
|
max: maxScale(natural, fit),
|
|
79
|
-
limits: panLimits(fit, this.size(), this.view.scale)
|
|
76
|
+
limits: panLimits(fit, this.box.size(), this.view.scale)
|
|
80
77
|
};
|
|
81
78
|
}
|
|
82
79
|
write(view) {
|
|
@@ -98,6 +95,7 @@ export class ViewGesture {
|
|
|
98
95
|
style.setProperty("--mv-drag-x", `${x}px`);
|
|
99
96
|
style.setProperty("--mv-drag-y", `${y}px`);
|
|
100
97
|
style.setProperty("--mv-drag-scale", String(scale));
|
|
98
|
+
this.box.dragScale = scale;
|
|
101
99
|
}
|
|
102
100
|
/* Moves to a view with the settle transition on, and drops any drag offset. */
|
|
103
101
|
settleTo(view) {
|
|
@@ -116,25 +114,16 @@ export class ViewGesture {
|
|
|
116
114
|
rtl() {
|
|
117
115
|
return getComputedStyle(this.stage).direction === "rtl";
|
|
118
116
|
}
|
|
119
|
-
ignores(event) {
|
|
120
|
-
const target = event.target;
|
|
121
|
-
if (target instanceof Element && target.closest("button, a, input, [data-mv-control]")) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
if (target instanceof HTMLVideoElement && target.controls) {
|
|
125
|
-
/* The browser's own bar sits along the bottom of the video, and keeps its touches. */
|
|
126
|
-
return event.clientY > target.getBoundingClientRect().bottom - 56;
|
|
127
|
-
}
|
|
128
|
-
return event.pointerType === "mouse" && event.button !== 0;
|
|
129
|
-
}
|
|
130
117
|
onDown = (event) => {
|
|
131
|
-
if (
|
|
118
|
+
if (pressIsForSomethingElse(event)) {
|
|
132
119
|
return;
|
|
133
120
|
}
|
|
134
121
|
cancelAnimationFrame(this.frame);
|
|
135
122
|
this.endSettling();
|
|
136
|
-
|
|
137
|
-
|
|
123
|
+
if (this.pointers.size === 0) {
|
|
124
|
+
this.box.hold();
|
|
125
|
+
}
|
|
126
|
+
this.pointers.set(event.pointerId, centreOf(this.box.read(), event.clientX, event.clientY));
|
|
138
127
|
if (this.pointers.size === 2 && this.options().zoomable) {
|
|
139
128
|
if (this.mode === "page") {
|
|
140
129
|
this.dragX = 0;
|
|
@@ -181,7 +170,7 @@ export class ViewGesture {
|
|
|
181
170
|
if (!previous || this.mode === "idle") {
|
|
182
171
|
return;
|
|
183
172
|
}
|
|
184
|
-
const now = centreOf(this.
|
|
173
|
+
const now = centreOf(this.box.read(), event.clientX, event.clientY);
|
|
185
174
|
this.pointers.set(event.pointerId, now);
|
|
186
175
|
this.vx.add(event.timeStamp, event.clientX);
|
|
187
176
|
this.vy.add(event.timeStamp, event.clientY);
|
|
@@ -228,7 +217,7 @@ export class ViewGesture {
|
|
|
228
217
|
movePan(dx, dy) {
|
|
229
218
|
const { limits } = this.measure();
|
|
230
219
|
const moved = { scale: this.view.scale, x: this.view.x + dx, y: this.view.y + dy };
|
|
231
|
-
this.write(softPan(moved, limits, this.size()));
|
|
220
|
+
this.write(softPan(moved, limits, this.box.size()));
|
|
232
221
|
}
|
|
233
222
|
/* The first move past the slop picks what the gesture is, once, so it never flips mid-drag. */
|
|
234
223
|
decide(event) {
|
|
@@ -271,7 +260,7 @@ export class ViewGesture {
|
|
|
271
260
|
}
|
|
272
261
|
return;
|
|
273
262
|
}
|
|
274
|
-
const progress = clamp(Math.max(0, dy) / (this.size().h * 0.45), 0, 1);
|
|
263
|
+
const progress = clamp(Math.max(0, dy) / (this.box.size().h * 0.45), 0, 1);
|
|
275
264
|
this.writeDrag(dx * 0.4, Math.max(0, dy), 1 - progress * 0.25);
|
|
276
265
|
this.hooks().onDismissProgress(progress);
|
|
277
266
|
}
|
|
@@ -286,6 +275,9 @@ export class ViewGesture {
|
|
|
286
275
|
else if (this.pointers.size === 0) {
|
|
287
276
|
this.finish(event, this.mode);
|
|
288
277
|
}
|
|
278
|
+
if (this.pointers.size === 0) {
|
|
279
|
+
this.box.release();
|
|
280
|
+
}
|
|
289
281
|
};
|
|
290
282
|
onCancel = (event) => {
|
|
291
283
|
this.pointers.delete(event.pointerId);
|
|
@@ -297,13 +289,14 @@ export class ViewGesture {
|
|
|
297
289
|
this.cancelPageDrag();
|
|
298
290
|
}
|
|
299
291
|
this.settleTo(this.view);
|
|
292
|
+
this.box.release();
|
|
300
293
|
}
|
|
301
294
|
};
|
|
302
295
|
endPinch() {
|
|
303
296
|
const { fit, max } = this.measure();
|
|
304
297
|
const scale = clamp(this.view.scale, 1, max);
|
|
305
298
|
const grown = zoomTo(this.view, scale, ORIGIN, "center");
|
|
306
|
-
const limits = panLimits(fit, this.size(), scale);
|
|
299
|
+
const limits = panLimits(fit, this.box.size(), scale);
|
|
307
300
|
this.settleTo(scale <= 1.02 ? FIT : clampPan(grown, limits));
|
|
308
301
|
this.pinchStart = null;
|
|
309
302
|
this.mode = this.pointers.size === 0 ? "idle" : "ignored";
|
|
@@ -326,7 +319,7 @@ export class ViewGesture {
|
|
|
326
319
|
}
|
|
327
320
|
releaseDismiss(event) {
|
|
328
321
|
const dy = this.down ? event.clientY - this.down.point.y : 0;
|
|
329
|
-
if (dy > this.size().h * 0.2 || this.vy.velocity(event.timeStamp) > 0.7) {
|
|
322
|
+
if (dy > this.box.size().h * 0.2 || this.vy.velocity(event.timeStamp) > 0.7) {
|
|
330
323
|
this.hooks().onDismiss();
|
|
331
324
|
return;
|
|
332
325
|
}
|
|
@@ -336,7 +329,7 @@ export class ViewGesture {
|
|
|
336
329
|
const dx = this.dragX;
|
|
337
330
|
this.dragX = 0;
|
|
338
331
|
const quick = Math.abs(velocity) > 0.4 && Math.abs(dx) > 16;
|
|
339
|
-
if (Math.abs(dx) > this.size().w * 0.25 || quick) {
|
|
332
|
+
if (Math.abs(dx) > this.box.size().w * 0.25 || quick) {
|
|
340
333
|
const forward = dx < 0 !== this.rtl();
|
|
341
334
|
this.writeDrag(0, 0, 1);
|
|
342
335
|
const direction = forward ? 1 : -1;
|
|
@@ -413,7 +406,7 @@ export class ViewGesture {
|
|
|
413
406
|
window.clearTimeout(this.tapTimer);
|
|
414
407
|
if (near && event.timeStamp - last.time < DOUBLE_MS && this.options().zoomable) {
|
|
415
408
|
this.lastTap = null;
|
|
416
|
-
this.doubleTap(centreOf(this.
|
|
409
|
+
this.box.within(() => this.doubleTap(centreOf(this.box.read(), point.x, point.y)));
|
|
417
410
|
return;
|
|
418
411
|
}
|
|
419
412
|
this.lastTap = { time: event.timeStamp, point };
|
|
@@ -426,7 +419,7 @@ export class ViewGesture {
|
|
|
426
419
|
const target = this.options().doubleTap === "actual" ? Math.min(max, actual) : 2;
|
|
427
420
|
const scale = doubleTapScale(this.view.scale, target);
|
|
428
421
|
const grown = zoomTo(this.view, scale, at, "point");
|
|
429
|
-
this.settleTo(scale === 1 ? FIT : clampPan(grown, panLimits(fit, this.size(), scale)));
|
|
422
|
+
this.settleTo(scale === 1 ? FIT : clampPan(grown, panLimits(fit, this.box.size(), scale)));
|
|
430
423
|
}
|
|
431
424
|
onWheel = (event) => {
|
|
432
425
|
const options = this.options();
|
|
@@ -449,11 +442,13 @@ export class ViewGesture {
|
|
|
449
442
|
};
|
|
450
443
|
wheelZoom(event) {
|
|
451
444
|
this.endSettling();
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
445
|
+
this.box.within(() => {
|
|
446
|
+
const { fit, max } = this.measure();
|
|
447
|
+
const scale = clamp(this.view.scale * wheelFactor(event.deltaY, event.ctrlKey), 1, max);
|
|
448
|
+
const at = centreOf(this.box.read(), event.clientX, event.clientY);
|
|
449
|
+
const grown = zoomTo(this.view, scale, at, this.options().anchor);
|
|
450
|
+
this.write(scale <= 1.001 ? FIT : clampPan(grown, panLimits(fit, this.box.size(), scale)));
|
|
451
|
+
});
|
|
457
452
|
}
|
|
458
453
|
wheelPage(event) {
|
|
459
454
|
if (event.timeStamp - this.lastPage < PAGE_COOLDOWN || Math.abs(event.deltaY) < 4) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { MediaViewerItem } from "./types";
|
|
2
|
+
import { type ZoomStore } from "./zoom-store";
|
|
2
3
|
export interface ChromeProps {
|
|
3
4
|
items: MediaViewerItem[];
|
|
4
5
|
index: number;
|
|
5
|
-
zoom:
|
|
6
|
+
zoom: ZoomStore;
|
|
6
7
|
zoomable: boolean;
|
|
7
8
|
onGo: (index: number) => void;
|
|
8
9
|
onStep: (direction: 1 | -1) => void;
|
|
@@ -2,6 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { DialogClose, DialogTitle } from "../dialog";
|
|
3
3
|
import { Icon } from "./icons";
|
|
4
4
|
import { useLabels } from "./labels";
|
|
5
|
+
import { useZoom } from "./zoom-store";
|
|
5
6
|
function Button({ label, icon, onClick, disabled }) {
|
|
6
7
|
return (_jsx("button", { type: "button", "data-mv-button": "", "aria-label": label, disabled: disabled, onClick: onClick, children: _jsx(Icon, { name: icon }) }));
|
|
7
8
|
}
|
|
@@ -15,7 +16,8 @@ function Strip({ items, index, onGo }) {
|
|
|
15
16
|
}
|
|
16
17
|
function Zoom({ zoom, zoomable, onZoom, onFit }) {
|
|
17
18
|
const labels = useLabels();
|
|
18
|
-
|
|
19
|
+
const zoomed = useZoom(zoom);
|
|
20
|
+
return (_jsxs("div", { "data-mv-zoom": "", role: "group", "aria-label": labels.zoom, children: [_jsx(Button, { label: labels.zoomOut, icon: "minus", disabled: !zoomable, onClick: () => onZoom(1 / 1.25) }), _jsxs("span", { "data-mv-percent": "", "aria-live": "off", children: [Math.round(zoomed * 100), "%"] }), _jsx(Button, { label: labels.zoomIn, icon: "plus", disabled: !zoomable, onClick: () => onZoom(1.25) }), _jsx("button", { type: "button", "data-mv-button": "", "data-mv-fit": "", disabled: !zoomable, onClick: onFit, children: labels.fit })] }));
|
|
19
21
|
}
|
|
20
22
|
function Heading({ item, index, count }) {
|
|
21
23
|
const size = item.width && item.height ? `${item.width} × ${item.height}` : "";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Chrome, OpenMotion } from "./types";
|
|
2
2
|
export type OriginOf = (index: number) => HTMLElement | null | undefined;
|
|
3
|
+
export declare function clearFlights(content: HTMLElement): void;
|
|
3
4
|
export declare function useOpenFromThumbnail(content: HTMLElement | null, index: number, motion: OpenMotion, originOf: OriginOf | undefined): void;
|
|
4
5
|
export declare function closeToThumbnail(content: HTMLElement | null, index: number, originOf: OriginOf | undefined): Promise<void>;
|
|
5
6
|
export declare function useChrome(mode: Chrome, content: HTMLElement | null): {
|