@alulore/kumiko 0.15.1 → 0.17.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/media-viewer/icons.d.ts +4 -0
- package/dist/media-viewer/icons.js +18 -0
- package/dist/media-viewer/index.d.ts +4 -0
- package/dist/media-viewer/index.js +3 -0
- package/dist/media-viewer/media-slide.d.ts +14 -0
- package/dist/media-viewer/media-slide.js +67 -0
- package/dist/media-viewer/media-viewer.css +611 -0
- package/dist/media-viewer/media-viewer.d.ts +17 -0
- package/dist/media-viewer/media-viewer.js +241 -0
- package/dist/media-viewer/pager-drag.d.ts +10 -0
- package/dist/media-viewer/pager-drag.js +53 -0
- package/dist/media-viewer/types.d.ts +58 -0
- package/dist/media-viewer/types.js +17 -0
- package/dist/media-viewer/video-controls.d.ts +3 -0
- package/dist/media-viewer/video-controls.js +62 -0
- package/dist/media-viewer/view-gesture.d.ts +74 -0
- package/dist/media-viewer/view-gesture.js +465 -0
- package/dist/media-viewer/viewer-chrome.d.ts +13 -0
- package/dist/media-viewer/viewer-chrome.js +35 -0
- package/dist/media-viewer/viewer-motion.d.ts +9 -0
- package/dist/media-viewer/viewer-motion.js +126 -0
- package/dist/media-viewer/zoom-pan.d.ts +35 -0
- package/dist/media-viewer/zoom-pan.js +102 -0
- package/dist/shortcuts/bindings.d.ts +44 -0
- package/dist/shortcuts/bindings.js +71 -0
- package/dist/shortcuts/capture.d.ts +7 -0
- package/dist/shortcuts/capture.js +92 -0
- package/dist/shortcuts/guard.d.ts +9 -0
- package/dist/shortcuts/guard.js +48 -0
- package/dist/shortcuts/help.d.ts +25 -0
- package/dist/shortcuts/help.js +26 -0
- package/dist/shortcuts/hints.d.ts +19 -0
- package/dist/shortcuts/hints.js +33 -0
- package/dist/shortcuts/index.d.ts +11 -0
- package/dist/shortcuts/index.js +11 -0
- package/dist/shortcuts/judge.d.ts +42 -0
- package/dist/shortcuts/judge.js +34 -0
- package/dist/shortcuts/keys.d.ts +11 -0
- package/dist/shortcuts/keys.js +89 -0
- package/dist/shortcuts/list.d.ts +16 -0
- package/dist/shortcuts/list.js +43 -0
- package/dist/shortcuts/notes.d.ts +28 -0
- package/dist/shortcuts/notes.js +27 -0
- package/dist/shortcuts/provider.d.ts +98 -0
- package/dist/shortcuts/provider.js +116 -0
- package/dist/shortcuts/rebinder.d.ts +23 -0
- package/dist/shortcuts/rebinder.js +84 -0
- package/dist/shortcuts/registration.d.ts +19 -0
- package/dist/shortcuts/registration.js +84 -0
- package/dist/shortcuts/shortcuts.css +171 -0
- package/dist/stored/index.d.ts +4 -0
- package/dist/stored/index.js +4 -0
- package/dist/stored/storage.d.ts +22 -0
- package/dist/stored/storage.js +10 -0
- package/dist/stored/stored.d.ts +93 -0
- package/dist/stored/stored.js +209 -0
- package/dist/stored/use-stored.d.ts +6 -0
- package/dist/stored/use-stored.js +12 -0
- package/dist/stored/validators.d.ts +6 -0
- package/dist/stored/validators.js +13 -0
- package/dist/titlebar/index.d.ts +2 -0
- package/dist/titlebar/index.js +2 -0
- package/dist/titlebar/titlebar-looks.d.ts +53 -0
- package/dist/titlebar/titlebar-looks.js +26 -0
- package/dist/titlebar/titlebar.css +561 -0
- package/dist/titlebar/titlebar.d.ts +54 -0
- package/dist/titlebar/titlebar.js +68 -0
- package/dist/undo/history.d.ts +62 -0
- package/dist/undo/history.js +151 -0
- package/dist/undo/index.d.ts +10 -0
- package/dist/undo/index.js +10 -0
- package/dist/undo/undo-adapter.d.ts +35 -0
- package/dist/undo/undo-adapter.js +35 -0
- package/dist/undo/undo-feedback.d.ts +28 -0
- package/dist/undo/undo-feedback.js +69 -0
- package/dist/undo/undo-keys.d.ts +32 -0
- package/dist/undo/undo-keys.js +76 -0
- package/dist/undo/undo-options.d.ts +51 -0
- package/dist/undo/undo-options.js +6 -0
- package/dist/undo/undo-panel.d.ts +23 -0
- package/dist/undo/undo-panel.js +56 -0
- package/dist/undo/undo-provider.d.ts +88 -0
- package/dist/undo/undo-provider.js +104 -0
- package/dist/undo/undo-reveal.d.ts +9 -0
- package/dist/undo/undo-reveal.js +45 -0
- package/dist/undo/undo-store.d.ts +89 -0
- package/dist/undo/undo-store.js +243 -0
- package/dist/undo/undo.css +135 -0
- package/dist/undo/use-undo-value.d.ts +43 -0
- package/dist/undo/use-undo-value.js +85 -0
- package/package.json +42 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Carousel, CarouselContent, CarouselItem, CarouselViewport, createCarouselController } from "@ui-sdk/react/carousel";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Dialog, DialogContent } from "../dialog";
|
|
5
|
+
import { MediaSlide } from "./media-slide";
|
|
6
|
+
import { PagerDrag } from "./pager-drag";
|
|
7
|
+
import { behaviourDefaults, lookDefaults } from "./types";
|
|
8
|
+
import { ViewerChrome } from "./viewer-chrome";
|
|
9
|
+
import { closeToThumbnail, useChrome, useOpenFromThumbnail } from "./viewer-motion";
|
|
10
|
+
function defined(value, fallback) {
|
|
11
|
+
return value ?? fallback;
|
|
12
|
+
}
|
|
13
|
+
function settle(props) {
|
|
14
|
+
return {
|
|
15
|
+
wheel: defined(props.wheel, behaviourDefaults.wheel),
|
|
16
|
+
zoomAnchor: defined(props.zoomAnchor, behaviourDefaults.zoomAnchor),
|
|
17
|
+
zoomedDrag: defined(props.zoomedDrag, behaviourDefaults.zoomedDrag),
|
|
18
|
+
swipeDownClose: defined(props.swipeDownClose, behaviourDefaults.swipeDownClose),
|
|
19
|
+
doubleTap: defined(props.doubleTap, behaviourDefaults.doubleTap),
|
|
20
|
+
paging: defined(props.paging, behaviourDefaults.paging),
|
|
21
|
+
loop: defined(props.loop, behaviourDefaults.loop),
|
|
22
|
+
videoControls: defined(props.videoControls, behaviourDefaults.videoControls),
|
|
23
|
+
openMotion: defined(props.openMotion, behaviourDefaults.openMotion),
|
|
24
|
+
indicator: defined(props.indicator, lookDefaults.indicator),
|
|
25
|
+
chrome: defined(props.chrome, lookDefaults.chrome),
|
|
26
|
+
layout: defined(props.layout, lookDefaults.layout),
|
|
27
|
+
background: defined(props.background, lookDefaults.background)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function wordsOf(set) {
|
|
31
|
+
return [
|
|
32
|
+
set.chrome,
|
|
33
|
+
set.indicator,
|
|
34
|
+
set.layout,
|
|
35
|
+
set.background,
|
|
36
|
+
`open-${set.openMotion}`,
|
|
37
|
+
`paging-${set.paging}`
|
|
38
|
+
].join(" ");
|
|
39
|
+
}
|
|
40
|
+
/* Ctrl or Command with plus, minus or zero. */
|
|
41
|
+
function zoomKey(event) {
|
|
42
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (event.key === "=" || event.key === "+") {
|
|
46
|
+
return "in";
|
|
47
|
+
}
|
|
48
|
+
if (event.key === "-" || event.key === "_") {
|
|
49
|
+
return "out";
|
|
50
|
+
}
|
|
51
|
+
return event.key === "0" ? "reset" : null;
|
|
52
|
+
}
|
|
53
|
+
function slideFor(props, item, active) {
|
|
54
|
+
const { set, gestureRef, signals } = props;
|
|
55
|
+
return (_jsx(MediaSlide, { item: item, active: active, signals: signals, gestureRef: gestureRef, videoControls: set.videoControls, options: {
|
|
56
|
+
wheel: set.wheel,
|
|
57
|
+
anchor: set.zoomAnchor,
|
|
58
|
+
zoomedDrag: set.zoomedDrag,
|
|
59
|
+
swipeDownClose: set.swipeDownClose,
|
|
60
|
+
doubleTap: set.doubleTap,
|
|
61
|
+
pagingFollows: set.paging !== "slide",
|
|
62
|
+
zoomable: item.kind !== "video"
|
|
63
|
+
} }));
|
|
64
|
+
}
|
|
65
|
+
/*
|
|
66
|
+
* The slides are a carousel: scroll-snap, loop, keys and a mouse drag are its own. A finger is not,
|
|
67
|
+
* because the stage owns touch (pager-drag.ts). Crossfade and instant show one item at a time.
|
|
68
|
+
*/
|
|
69
|
+
function Pager(props) {
|
|
70
|
+
const { items, index, set, zoomed, controller } = props;
|
|
71
|
+
const slide = (item, active) => slideFor(props, item, active);
|
|
72
|
+
const current = items[index];
|
|
73
|
+
if (set.paging !== "slide") {
|
|
74
|
+
return _jsx("div", { "data-mv-single": "", children: current ? slide(current, true) : null });
|
|
75
|
+
}
|
|
76
|
+
return (_jsx(Carousel, { "aria-label": "Media", page: index + 1, onPageChange: (page, details) => {
|
|
77
|
+
/* The carousel reports the halfway scroll of a finger drag as a swipe; the drag decides the page. */
|
|
78
|
+
if (props.pagerBusy() &&
|
|
79
|
+
(details.reason === "swipe" || details.reason === "scroll")) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
props.onIndexChange(page - 1);
|
|
83
|
+
}, loop: set.loop, drag: !zoomed, controller: controller, children: _jsx(CarouselViewport, { children: _jsx(CarouselContent, { children: items.map((item, at) => (_jsx(CarouselItem, { children: slide(item, at === index) }, item.id))) }) }) }));
|
|
84
|
+
}
|
|
85
|
+
/* Moves to the item before or after this one by index, looping if asked. */
|
|
86
|
+
function useGo(props, set) {
|
|
87
|
+
const { items, index, onIndexChange } = props;
|
|
88
|
+
return useCallback((direction) => {
|
|
89
|
+
const raw = index + direction;
|
|
90
|
+
const wrapped = (raw + items.length) % items.length;
|
|
91
|
+
const next = set.loop ? wrapped : Math.min(items.length - 1, Math.max(0, raw));
|
|
92
|
+
if (next !== index) {
|
|
93
|
+
onIndexChange(next);
|
|
94
|
+
}
|
|
95
|
+
}, [set.loop, items.length, index, onIndexChange]);
|
|
96
|
+
}
|
|
97
|
+
/* Buttons and keys: the carousel scrolls to the next slide, or the other modes swap it. */
|
|
98
|
+
function usePaging(set, controller, go) {
|
|
99
|
+
return useCallback((direction) => {
|
|
100
|
+
if (set.paging !== "slide") {
|
|
101
|
+
go(direction);
|
|
102
|
+
}
|
|
103
|
+
else if (direction === 1) {
|
|
104
|
+
controller.next();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
controller.previous();
|
|
108
|
+
}
|
|
109
|
+
}, [set.paging, controller, go]);
|
|
110
|
+
}
|
|
111
|
+
function useViewerKeys(step, gestureRef) {
|
|
112
|
+
return useCallback((event) => {
|
|
113
|
+
const target = event.target;
|
|
114
|
+
if (target instanceof Element && target.closest("input, video, textarea, select")) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const asked = zoomKey(event);
|
|
118
|
+
if (asked) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
if (asked === "reset") {
|
|
121
|
+
gestureRef.current?.reset();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
gestureRef.current?.zoomBy(asked === "in" ? 1.25 : 1 / 1.25);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const arrow = event.key === "ArrowRight" || event.key === "ArrowLeft";
|
|
129
|
+
const inCarousel = target instanceof Element && target.closest("[data-slot='carousel-viewport']");
|
|
130
|
+
if (!arrow || inCarousel || event.ctrlKey || event.metaKey || event.altKey) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
135
|
+
const right = event.key === "ArrowRight";
|
|
136
|
+
step(right === rtl ? -1 : 1);
|
|
137
|
+
}, [step, gestureRef]);
|
|
138
|
+
}
|
|
139
|
+
function useClosing(props, set, content) {
|
|
140
|
+
const { open, index, onClose, getOrigin } = props;
|
|
141
|
+
const [closing, setClosing] = useState(false);
|
|
142
|
+
const busy = useRef(false);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (open) {
|
|
145
|
+
busy.current = false;
|
|
146
|
+
setClosing(false);
|
|
147
|
+
}
|
|
148
|
+
}, [open]);
|
|
149
|
+
const requestClose = useCallback(() => {
|
|
150
|
+
if (busy.current) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
busy.current = true;
|
|
154
|
+
setClosing(true);
|
|
155
|
+
const arrive = set.openMotion === "thumbnail"
|
|
156
|
+
? closeToThumbnail(content, index, getOrigin)
|
|
157
|
+
: Promise.resolve();
|
|
158
|
+
void arrive.then(onClose);
|
|
159
|
+
}, [set.openMotion, content, index, getOrigin, onClose]);
|
|
160
|
+
return { closing, requestClose };
|
|
161
|
+
}
|
|
162
|
+
function toggleFullscreen(content) {
|
|
163
|
+
if (document.fullscreenElement) {
|
|
164
|
+
void document.exitFullscreen();
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
void content?.requestFullscreen().catch(() => undefined);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/* The state and behaviour the pieces share: what is zoomed, who is closing, how paging works. */
|
|
171
|
+
function useParts(props, set) {
|
|
172
|
+
const [content, setContent] = useState(null);
|
|
173
|
+
const contentRef = useRef(null);
|
|
174
|
+
contentRef.current = content;
|
|
175
|
+
const [zoom, setZoom] = useState(1);
|
|
176
|
+
const [controller] = useState(createCarouselController);
|
|
177
|
+
const gestureRef = useRef(null);
|
|
178
|
+
const go = useGo(props, set);
|
|
179
|
+
const goRef = useRef(go);
|
|
180
|
+
goRef.current = go;
|
|
181
|
+
const step = usePaging(set, controller, go);
|
|
182
|
+
const { closing, requestClose } = useClosing(props, set, content);
|
|
183
|
+
const chrome = useChrome(set.chrome, content);
|
|
184
|
+
useOpenFromThumbnail(content, props.index, set.openMotion, props.getOrigin);
|
|
185
|
+
const onKeyDown = useViewerKeys(step, gestureRef);
|
|
186
|
+
const [pagerDrag] = useState(() => new PagerDrag(() => contentRef.current, (direction) => goRef.current(direction)));
|
|
187
|
+
const signals = {
|
|
188
|
+
dragPager: pagerDrag.drag,
|
|
189
|
+
releasePager: pagerDrag.release,
|
|
190
|
+
onView: (view) => setZoom(Math.round(view.scale * 100) / 100),
|
|
191
|
+
onPage: step,
|
|
192
|
+
onDismissProgress: (progress) => content?.style.setProperty("--mv-dismiss", String(progress)),
|
|
193
|
+
onDismiss: requestClose,
|
|
194
|
+
onTap: chrome.toggle
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
content,
|
|
198
|
+
setContent,
|
|
199
|
+
zoom,
|
|
200
|
+
controller,
|
|
201
|
+
gestureRef,
|
|
202
|
+
step,
|
|
203
|
+
closing,
|
|
204
|
+
requestClose,
|
|
205
|
+
chrome,
|
|
206
|
+
onKeyDown,
|
|
207
|
+
signals,
|
|
208
|
+
pagerBusy: pagerDrag.busy
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function Interior({ props, set, parts }) {
|
|
212
|
+
const { items, index, onIndexChange } = props;
|
|
213
|
+
const { zoom, controller, gestureRef } = parts;
|
|
214
|
+
const item = items[index];
|
|
215
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { "data-mv-body": "", children: _jsx(Pager, { items: items, index: index, set: set, zoomed: zoom > 1.001, 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) })] }));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Shows images and video full screen: zoom and pan, swiping between items, closing.
|
|
219
|
+
* Built on the dialog for the shell, focus trap and Escape, and on the carousel for paging.
|
|
220
|
+
*/
|
|
221
|
+
export function MediaViewer(props) {
|
|
222
|
+
const { open, items, index, getOrigin } = props;
|
|
223
|
+
const set = settle(props);
|
|
224
|
+
const parts = useParts(props, set);
|
|
225
|
+
const { chrome } = parts;
|
|
226
|
+
const item = items[index];
|
|
227
|
+
return (_jsx(Dialog, { open: open && item !== undefined, onOpenChange: (next) => {
|
|
228
|
+
if (!next) {
|
|
229
|
+
parts.requestClose();
|
|
230
|
+
}
|
|
231
|
+
}, children: _jsx(DialogContent, { ref: parts.setContent, className: "media-viewer", "data-kumiko-media-viewer": wordsOf(set), "data-chrome": chrome.hidden ? "hidden" : "shown", "data-closing": parts.closing ? "" : undefined, initialFocus: "content", finalFocus: () => getOrigin?.(index), onKeyDown: parts.onKeyDown, onPointerMove: (event) => {
|
|
232
|
+
if (event.pointerType === "mouse") {
|
|
233
|
+
chrome.poke();
|
|
234
|
+
}
|
|
235
|
+
}, onFocus: (event) => {
|
|
236
|
+
if (event.target instanceof Element &&
|
|
237
|
+
event.target.closest("[data-mv-chrome]")) {
|
|
238
|
+
chrome.poke();
|
|
239
|
+
}
|
|
240
|
+
}, children: _jsx(Interior, { props: props, set: set, parts: parts }) }) }));
|
|
241
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class PagerDrag {
|
|
2
|
+
private held;
|
|
3
|
+
private settlingUntil;
|
|
4
|
+
private readonly content;
|
|
5
|
+
private readonly go;
|
|
6
|
+
constructor(content: () => HTMLElement | null, go: (direction: 1 | -1) => void);
|
|
7
|
+
busy: () => boolean;
|
|
8
|
+
drag: (dx: number) => void;
|
|
9
|
+
release: (direction: 1 | -1 | 0) => void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A finger dragging at fit moves the carousel by hand, because the stage owns every touch (so a
|
|
3
|
+
* second finger can still start a pinch). The viewport scrolls with the finger, and on release the
|
|
4
|
+
* page changes through the viewer's index (the carousel then scrolls to it), or the viewport
|
|
5
|
+
* scrolls back.
|
|
6
|
+
*/
|
|
7
|
+
export class PagerDrag {
|
|
8
|
+
held = null;
|
|
9
|
+
settlingUntil = 0;
|
|
10
|
+
content;
|
|
11
|
+
go;
|
|
12
|
+
constructor(content, go) {
|
|
13
|
+
this.content = content;
|
|
14
|
+
this.go = go;
|
|
15
|
+
}
|
|
16
|
+
/* While a finger drags, and while the carousel finishes the page it was given. */
|
|
17
|
+
busy = () => this.held !== null || performance.now() < this.settlingUntil;
|
|
18
|
+
drag = (dx) => {
|
|
19
|
+
if (!this.held) {
|
|
20
|
+
const viewport = this.content()?.querySelector("[data-slot='carousel-viewport']");
|
|
21
|
+
if (!viewport) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.held = {
|
|
25
|
+
viewport,
|
|
26
|
+
left: viewport.scrollLeft,
|
|
27
|
+
snap: viewport.style.scrollSnapType
|
|
28
|
+
};
|
|
29
|
+
viewport.style.scrollSnapType = "none";
|
|
30
|
+
}
|
|
31
|
+
this.held.viewport.scrollLeft = this.held.left - dx;
|
|
32
|
+
};
|
|
33
|
+
release = (direction) => {
|
|
34
|
+
const held = this.held;
|
|
35
|
+
if (!held) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.held = null;
|
|
39
|
+
this.settlingUntil = performance.now() + 700;
|
|
40
|
+
if (direction === 0) {
|
|
41
|
+
held.viewport.scrollTo({ left: held.left, behavior: "smooth" });
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.go(direction);
|
|
45
|
+
}
|
|
46
|
+
/* The carousel puts its own snapping back when it settles; this only covers a drag that paged nowhere. */
|
|
47
|
+
window.setTimeout(() => {
|
|
48
|
+
if (held.viewport.style.scrollSnapType === "none") {
|
|
49
|
+
held.viewport.style.scrollSnapType = held.snap;
|
|
50
|
+
}
|
|
51
|
+
}, 600);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ZoomAnchor } from "./zoom-pan";
|
|
2
|
+
export interface MediaViewerItem {
|
|
3
|
+
id: string;
|
|
4
|
+
src: string;
|
|
5
|
+
name: string;
|
|
6
|
+
/** Whether it is a picture or a clip. @defaultValue "image" */
|
|
7
|
+
kind?: "image" | "video";
|
|
8
|
+
/** The still shown before a video plays. */
|
|
9
|
+
poster?: string;
|
|
10
|
+
/** A small picture for the thumbnail strip. Defaults to `src` (or `poster`). */
|
|
11
|
+
thumb?: string;
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
}
|
|
15
|
+
export type WheelMode = "zoom" | "page";
|
|
16
|
+
export type ZoomedDrag = "edge-pages" | "pan";
|
|
17
|
+
export type DoubleTap = "point" | "actual";
|
|
18
|
+
export type PagingMotion = "slide" | "fade" | "instant";
|
|
19
|
+
export type OpenMotion = "thumbnail" | "fade" | "none";
|
|
20
|
+
export type VideoControls = "native" | "custom";
|
|
21
|
+
export type Indicator = "counter" | "dots" | "strip" | "none";
|
|
22
|
+
export type Chrome = "always" | "autohide" | "minimal";
|
|
23
|
+
export type Layout = "bars" | "floating";
|
|
24
|
+
export type Background = "solid" | "blur";
|
|
25
|
+
/** What the viewer does. Each one sets a default, and an app can pick another. */
|
|
26
|
+
export interface MediaViewerBehaviour {
|
|
27
|
+
/** What the wheel does. Ctrl and a trackpad pinch zoom either way. @defaultValue "zoom" */
|
|
28
|
+
wheel?: WheelMode;
|
|
29
|
+
/** Where zoom grows from: the pointer or pinch centre, or the middle of the frame. @defaultValue "point" */
|
|
30
|
+
zoomAnchor?: ZoomAnchor;
|
|
31
|
+
/** A drag on a zoomed picture: pan, then page at the edge, or only pan. @defaultValue "edge-pages" */
|
|
32
|
+
zoomedDrag?: ZoomedDrag;
|
|
33
|
+
/** A finger dragging down moves the picture with it and closes the viewer. @defaultValue true */
|
|
34
|
+
swipeDownClose?: boolean;
|
|
35
|
+
/** Double tap or click: 2x at the point, or fit and actual size. @defaultValue "point" */
|
|
36
|
+
doubleTap?: DoubleTap;
|
|
37
|
+
/** How one item gives way to the next by button or key. A swipe always follows the finger, whatever this is. @defaultValue "slide" */
|
|
38
|
+
paging?: PagingMotion;
|
|
39
|
+
/** Paging past the last item goes to the first. @defaultValue true */
|
|
40
|
+
loop?: boolean;
|
|
41
|
+
/** The controls of a video. @defaultValue "custom" */
|
|
42
|
+
videoControls?: VideoControls;
|
|
43
|
+
/** How the viewer opens and closes. @defaultValue "thumbnail" */
|
|
44
|
+
openMotion?: OpenMotion;
|
|
45
|
+
}
|
|
46
|
+
/** How it looks. These become words on the viewer: `data-kumiko-media-viewer="autohide dots"`. */
|
|
47
|
+
export interface MediaViewerLook {
|
|
48
|
+
/** @defaultValue "counter" */
|
|
49
|
+
indicator?: Indicator;
|
|
50
|
+
/** @defaultValue "autohide" */
|
|
51
|
+
chrome?: Chrome;
|
|
52
|
+
/** @defaultValue "floating" */
|
|
53
|
+
layout?: Layout;
|
|
54
|
+
/** @defaultValue "solid" */
|
|
55
|
+
background?: Background;
|
|
56
|
+
}
|
|
57
|
+
export declare const behaviourDefaults: Required<MediaViewerBehaviour>;
|
|
58
|
+
export declare const lookDefaults: Required<MediaViewerLook>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const behaviourDefaults = {
|
|
2
|
+
wheel: "zoom",
|
|
3
|
+
zoomAnchor: "point",
|
|
4
|
+
zoomedDrag: "edge-pages",
|
|
5
|
+
swipeDownClose: true,
|
|
6
|
+
doubleTap: "point",
|
|
7
|
+
paging: "slide",
|
|
8
|
+
loop: true,
|
|
9
|
+
videoControls: "custom",
|
|
10
|
+
openMotion: "thumbnail"
|
|
11
|
+
};
|
|
12
|
+
export const lookDefaults = {
|
|
13
|
+
indicator: "counter",
|
|
14
|
+
chrome: "autohide",
|
|
15
|
+
layout: "floating",
|
|
16
|
+
background: "solid"
|
|
17
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { Icon } from "./icons";
|
|
4
|
+
const CLIP_EVENTS = ["play", "pause", "volumechange", "timeupdate", "loadedmetadata"];
|
|
5
|
+
function useClipState(video) {
|
|
6
|
+
const [state, setState] = useState({
|
|
7
|
+
playing: false,
|
|
8
|
+
muted: false,
|
|
9
|
+
time: 0,
|
|
10
|
+
length: 0
|
|
11
|
+
});
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const el = video.current;
|
|
14
|
+
if (!el) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const read = () => setState({
|
|
18
|
+
playing: !el.paused,
|
|
19
|
+
muted: el.muted,
|
|
20
|
+
time: el.currentTime,
|
|
21
|
+
length: Number.isFinite(el.duration) ? el.duration : 0
|
|
22
|
+
});
|
|
23
|
+
for (const name of CLIP_EVENTS) {
|
|
24
|
+
el.addEventListener(name, read);
|
|
25
|
+
}
|
|
26
|
+
read();
|
|
27
|
+
return () => {
|
|
28
|
+
for (const name of CLIP_EVENTS) {
|
|
29
|
+
el.removeEventListener(name, read);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}, [video]);
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
function clock(seconds) {
|
|
36
|
+
const whole = Math.max(0, Math.floor(seconds));
|
|
37
|
+
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
|
|
38
|
+
}
|
|
39
|
+
function togglePlay(video) {
|
|
40
|
+
if (!video) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (video.paused) {
|
|
44
|
+
void video.play();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
video.pause();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/* A minimal set of video controls: play or pause, a scrubber, and mute. */
|
|
51
|
+
export function VideoControls({ video }) {
|
|
52
|
+
const state = useClipState(video);
|
|
53
|
+
return (_jsxs("div", { "data-mv-control": "", "data-mv-video-controls": "", children: [_jsx("button", { type: "button", "data-mv-button": "", onClick: () => togglePlay(video.current), "aria-label": state.playing ? "Pause" : "Play", children: _jsx(Icon, { name: state.playing ? "pause" : "play" }) }), _jsx("input", { type: "range", "aria-label": "Position", min: 0, max: state.length || 1, step: "any", value: state.time, onChange: (event) => {
|
|
54
|
+
if (video.current) {
|
|
55
|
+
video.current.currentTime = Number(event.target.value);
|
|
56
|
+
}
|
|
57
|
+
} }), _jsx("span", { "aria-hidden": "true", children: clock(state.time) }), _jsx("button", { type: "button", "data-mv-button": "", "aria-label": state.muted ? "Unmute" : "Mute", "aria-pressed": state.muted, onClick: () => {
|
|
58
|
+
if (video.current) {
|
|
59
|
+
video.current.muted = !video.current.muted;
|
|
60
|
+
}
|
|
61
|
+
}, children: _jsx(Icon, { name: state.muted ? "muted" : "sound" }) })] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type Size, type View, type ZoomAnchor } from "./zoom-pan";
|
|
2
|
+
export interface GestureOptions {
|
|
3
|
+
wheel: "zoom" | "page";
|
|
4
|
+
anchor: ZoomAnchor;
|
|
5
|
+
zoomedDrag: "edge-pages" | "pan";
|
|
6
|
+
swipeDownClose: boolean;
|
|
7
|
+
doubleTap: "point" | "actual";
|
|
8
|
+
pagingFollows: boolean;
|
|
9
|
+
zoomable: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface GestureHooks {
|
|
12
|
+
natural: () => Size;
|
|
13
|
+
onView: (view: View) => void;
|
|
14
|
+
onPage: (direction: 1 | -1) => void;
|
|
15
|
+
onDismissProgress: (progress: number) => void;
|
|
16
|
+
onDismiss: () => void;
|
|
17
|
+
onTap: () => void;
|
|
18
|
+
dragPager?: (dx: number) => void;
|
|
19
|
+
releasePager?: (direction: 1 | -1 | 0) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare class ViewGesture {
|
|
22
|
+
private view;
|
|
23
|
+
private mode;
|
|
24
|
+
private down;
|
|
25
|
+
private readonly pointers;
|
|
26
|
+
private readonly vx;
|
|
27
|
+
private readonly vy;
|
|
28
|
+
private pinchStart;
|
|
29
|
+
private frame;
|
|
30
|
+
private lastTap;
|
|
31
|
+
private tapTimer;
|
|
32
|
+
private lastPage;
|
|
33
|
+
private settleTimer;
|
|
34
|
+
private dragX;
|
|
35
|
+
private readonly stage;
|
|
36
|
+
private readonly options;
|
|
37
|
+
private readonly hooks;
|
|
38
|
+
constructor(stage: HTMLElement, options: () => GestureOptions, hooks: () => GestureHooks);
|
|
39
|
+
destroy(): void;
|
|
40
|
+
zoomBy(factor: number): void;
|
|
41
|
+
reset(): void;
|
|
42
|
+
private size;
|
|
43
|
+
private measure;
|
|
44
|
+
private write;
|
|
45
|
+
private writeDrag;
|
|
46
|
+
private settleTo;
|
|
47
|
+
private endSettling;
|
|
48
|
+
private rtl;
|
|
49
|
+
private ignores;
|
|
50
|
+
private readonly onDown;
|
|
51
|
+
private startSingle;
|
|
52
|
+
private startPinch;
|
|
53
|
+
private readonly onMove;
|
|
54
|
+
private route;
|
|
55
|
+
private isDragging;
|
|
56
|
+
private movePinch;
|
|
57
|
+
private movePan;
|
|
58
|
+
private decide;
|
|
59
|
+
private moveDrag;
|
|
60
|
+
private readonly onUp;
|
|
61
|
+
private readonly onCancel;
|
|
62
|
+
private endPinch;
|
|
63
|
+
private finish;
|
|
64
|
+
private releaseDismiss;
|
|
65
|
+
private releasePage;
|
|
66
|
+
private cancelPageDrag;
|
|
67
|
+
private releasePan;
|
|
68
|
+
private inertia;
|
|
69
|
+
private tap;
|
|
70
|
+
private doubleTap;
|
|
71
|
+
private readonly onWheel;
|
|
72
|
+
private wheelZoom;
|
|
73
|
+
private wheelPage;
|
|
74
|
+
}
|