@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
|
@@ -33,6 +33,13 @@ function flyingCopy(content, src, box) {
|
|
|
33
33
|
content.dataset.flying = "";
|
|
34
34
|
return copy;
|
|
35
35
|
}
|
|
36
|
+
/* A closing flight leaves its copy where it landed, until the viewer is shown again. */
|
|
37
|
+
export function clearFlights(content) {
|
|
38
|
+
for (const copy of content.querySelectorAll("[data-mv-flight]")) {
|
|
39
|
+
copy.remove();
|
|
40
|
+
}
|
|
41
|
+
delete content.dataset.flying;
|
|
42
|
+
}
|
|
36
43
|
function boxOf(rect) {
|
|
37
44
|
return {
|
|
38
45
|
left: `${rect.left}px`,
|
|
@@ -51,6 +58,11 @@ export function useOpenFromThumbnail(content, index, motion, originOf) {
|
|
|
51
58
|
if (!content || motion !== "thumbnail") {
|
|
52
59
|
return undefined;
|
|
53
60
|
}
|
|
61
|
+
let flight = null;
|
|
62
|
+
const land = () => {
|
|
63
|
+
flight?.copy.remove();
|
|
64
|
+
delete content.dataset.flying;
|
|
65
|
+
};
|
|
54
66
|
const frame = requestAnimationFrame(() => {
|
|
55
67
|
const parts = partsOf(content, latest.current.index, latest.current.originOf);
|
|
56
68
|
const { duration, easing } = readMotion(content, "settle");
|
|
@@ -60,14 +72,15 @@ export function useOpenFromThumbnail(content, index, motion, originOf) {
|
|
|
60
72
|
const to = parts.media.getBoundingClientRect();
|
|
61
73
|
const copy = flyingCopy(content, parts.src, to);
|
|
62
74
|
const from = boxOf(parts.origin.getBoundingClientRect());
|
|
63
|
-
copy.animate([from, boxOf(to)], { duration, easing })
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
delete content.dataset.flying;
|
|
67
|
-
})
|
|
68
|
-
.catch(() => undefined);
|
|
75
|
+
const animation = copy.animate([from, boxOf(to)], { duration, easing });
|
|
76
|
+
flight = { copy, animation };
|
|
77
|
+
animation.finished.then(land).catch(land);
|
|
69
78
|
});
|
|
70
|
-
return () =>
|
|
79
|
+
return () => {
|
|
80
|
+
cancelAnimationFrame(frame);
|
|
81
|
+
flight?.animation.cancel();
|
|
82
|
+
land();
|
|
83
|
+
};
|
|
71
84
|
}, [content, motion]);
|
|
72
85
|
}
|
|
73
86
|
/* Closes toward the thumbnail, resolving once the picture has arrived (or at once, with no thumbnail). */
|
|
@@ -14,6 +14,7 @@ export interface View {
|
|
|
14
14
|
export type ZoomAnchor = "point" | "center";
|
|
15
15
|
export declare const FIT: View;
|
|
16
16
|
export declare const MIN_SCALE = 1;
|
|
17
|
+
export declare function middle(a: Point, b: Point): Point;
|
|
17
18
|
export declare function clamp(value: number, low: number, high: number): number;
|
|
18
19
|
export declare function fitSize(natural: Size, frame: Size): Size;
|
|
19
20
|
export declare function actualScale(natural: Size, fit: Size): number;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { rubberBand } from "@ui-sdk/react/gesture";
|
|
2
2
|
export const FIT = { scale: 1, x: 0, y: 0 };
|
|
3
3
|
export const MIN_SCALE = 1;
|
|
4
|
+
export function middle(a, b) {
|
|
5
|
+
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
6
|
+
}
|
|
4
7
|
export function clamp(value, low, high) {
|
|
5
8
|
return Math.min(high, Math.max(low, value));
|
|
6
9
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ZoomStore {
|
|
2
|
+
get: () => number;
|
|
3
|
+
set: (zoom: number) => void;
|
|
4
|
+
subscribe: (listener: () => void) => () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createZoomStore(): ZoomStore;
|
|
7
|
+
export declare function useZoom(store: ZoomStore): number;
|
|
8
|
+
export declare function useZoomed(store: ZoomStore): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
export function createZoomStore() {
|
|
3
|
+
let zoom = 1;
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
return {
|
|
6
|
+
get: () => zoom,
|
|
7
|
+
set: (next) => {
|
|
8
|
+
if (next === zoom) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
zoom = next;
|
|
12
|
+
for (const listener of listeners) {
|
|
13
|
+
listener();
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
subscribe: (listener) => {
|
|
17
|
+
listeners.add(listener);
|
|
18
|
+
return () => {
|
|
19
|
+
listeners.delete(listener);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function useZoom(store) {
|
|
25
|
+
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
26
|
+
}
|
|
27
|
+
/* Whether the picture is past fit: it changes twice per pinch, not on every move. */
|
|
28
|
+
export function useZoomed(store) {
|
|
29
|
+
return useSyncExternalStore(store.subscribe, () => store.get() > 1.001, () => store.get() > 1.001);
|
|
30
|
+
}
|
package/dist/menu/menu.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Menu as SdkMenu, MenuContent as SdkMenuContent } from "@ui-sdk/react/menu";
|
|
3
|
-
import { createContext, use, useEffect, useId, useState } from "react";
|
|
3
|
+
import { createContext, use, useEffect, useId, useMemo, useState } from "react";
|
|
4
4
|
import { useSettledClose } from "../motion/settle-close";
|
|
5
5
|
const open = new Set();
|
|
6
6
|
/** Menus still fading out, each with a way to cut its fade short. */
|
|
@@ -58,7 +58,8 @@ export function Menu({ onOpenChange, onOpenChangeComplete, ...props }) {
|
|
|
58
58
|
// The close may never be reported complete when a closing menu is removed.
|
|
59
59
|
closing.delete(id);
|
|
60
60
|
}, [id]);
|
|
61
|
-
|
|
61
|
+
const value = useMemo(() => ({ on, el }), [on, el]);
|
|
62
|
+
return (_jsx(SwitchContext, { value: value, children: _jsx(SdkMenu, { ...props, onOpenChange: (next, details) => {
|
|
62
63
|
changed(id, next, set);
|
|
63
64
|
onOpenChange?.(next, details);
|
|
64
65
|
}, onOpenChangeComplete: (next) => {
|
|
@@ -84,5 +85,7 @@ function joinRefs(holder, theirs) {
|
|
|
84
85
|
}
|
|
85
86
|
export function MenuContent({ ref, ...props }) {
|
|
86
87
|
const state = use(SwitchContext);
|
|
87
|
-
|
|
88
|
+
const holder = state?.el;
|
|
89
|
+
const joined = useMemo(() => joinRefs(holder, ref), [holder, ref]);
|
|
90
|
+
return (_jsx(SdkMenuContent, { ...props, ref: joined, "data-kumiko-switch": state?.on ? "" : undefined }));
|
|
88
91
|
}
|
package/dist/menu/point-menu.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { createMenuController } from "@ui-sdk/react/menu";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
const inMenu = (el) => el?.closest('[data-slot="menu-content"]') !== null && el !== null;
|
|
4
|
+
/** Calls `run` once focus is outside the menu. Starting again drops the wait before it, so only one is ever pending. */
|
|
5
|
+
function createFocusWait(run) {
|
|
6
|
+
let stopWaiting = null;
|
|
7
|
+
const stop = () => {
|
|
8
|
+
stopWaiting?.();
|
|
9
|
+
stopWaiting = null;
|
|
10
|
+
};
|
|
11
|
+
const start = () => {
|
|
12
|
+
stop();
|
|
13
|
+
if (!inMenu(document.activeElement)) {
|
|
14
|
+
run();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const moved = (event) => {
|
|
18
|
+
if (event.target instanceof Element && !inMenu(event.target)) {
|
|
19
|
+
stop();
|
|
20
|
+
run();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
document.addEventListener("focusin", moved, true);
|
|
24
|
+
stopWaiting = () => {
|
|
25
|
+
document.removeEventListener("focusin", moved, true);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
return { start, stop };
|
|
29
|
+
}
|
|
4
30
|
export function createPointMenu() {
|
|
5
31
|
const controller = createMenuController();
|
|
6
32
|
let queued = null;
|
|
@@ -9,26 +35,20 @@ export function createPointMenu() {
|
|
|
9
35
|
queued = null;
|
|
10
36
|
action?.();
|
|
11
37
|
};
|
|
38
|
+
const wait = createFocusWait(run);
|
|
12
39
|
// Focus comes back just after ui-sdk says the menu closed, so a queued action waits for that.
|
|
13
40
|
const whenFocusLeaves = () => {
|
|
14
|
-
if (
|
|
15
|
-
|
|
41
|
+
if (queued) {
|
|
42
|
+
wait.start();
|
|
16
43
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return;
|
|
44
|
+
else {
|
|
45
|
+
wait.stop();
|
|
20
46
|
}
|
|
21
|
-
const moved = (event) => {
|
|
22
|
-
if (event.target instanceof Element && !inMenu(event.target)) {
|
|
23
|
-
document.removeEventListener("focusin", moved, true);
|
|
24
|
-
run();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
document.addEventListener("focusin", moved, true);
|
|
28
47
|
};
|
|
29
48
|
return {
|
|
30
49
|
controller,
|
|
31
50
|
open(at, payload, options = {}) {
|
|
51
|
+
wait.stop();
|
|
32
52
|
if (controller.isOpen()) {
|
|
33
53
|
controller.close();
|
|
34
54
|
}
|
package/dist/motion/flip.js
CHANGED
|
@@ -35,30 +35,36 @@ function parentOffset(el, moves) {
|
|
|
35
35
|
}
|
|
36
36
|
return undefined;
|
|
37
37
|
}
|
|
38
|
+
/*
|
|
39
|
+
* Each element's running slide, so cancelling it reads nothing. getAnimations()
|
|
40
|
+
* brings style up to date, and after a write that forces a recalc per element.
|
|
41
|
+
*/
|
|
42
|
+
const slides = new WeakMap();
|
|
38
43
|
function cancelFlip(el) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
animation.cancel();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
+
slides.get(el)?.cancel();
|
|
45
|
+
slides.delete(el);
|
|
44
46
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
if (duration === 0 || isStill(offset)) {
|
|
47
|
+
function slide({ el, offset, motion }) {
|
|
48
|
+
if (motion.duration === 0 || isStill(offset)) {
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
cancelFlip(el);
|
|
51
52
|
const keyframes = [{ translate: `${offset.x}px ${offset.y}px` }, { translate: "0 0" }];
|
|
52
|
-
el.animate(keyframes, {
|
|
53
|
+
slides.set(el, el.animate(keyframes, { ...motion, id: FLIP_ID }));
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
+
function readFade(el) {
|
|
55
56
|
const style = getComputedStyle(el);
|
|
56
|
-
|
|
57
|
+
return {
|
|
58
|
+
el,
|
|
59
|
+
duration: parseDuration(style.getPropertyValue("--kumiko-fade-duration")),
|
|
60
|
+
easing: style.getPropertyValue("--kumiko-enter-ease").trim() || "ease-out",
|
|
61
|
+
grows: parseDuration(style.getPropertyValue("--kumiko-move-duration")) > 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function fadeIn({ el, duration, easing, grows }) {
|
|
57
65
|
if (duration === 0) {
|
|
58
66
|
return;
|
|
59
67
|
}
|
|
60
|
-
const easing = style.getPropertyValue("--kumiko-enter-ease").trim() || "ease-out";
|
|
61
|
-
const grows = parseDuration(style.getPropertyValue("--kumiko-move-duration")) > 0;
|
|
62
68
|
const keyframes = grows
|
|
63
69
|
? [
|
|
64
70
|
{ opacity: 0, scale: "0.96" },
|
|
@@ -103,10 +109,13 @@ function movesOf(elements, sources, options) {
|
|
|
103
109
|
}
|
|
104
110
|
return moves;
|
|
105
111
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
/* Reads every slide's timing before the first write, so style is brought up to date once. */
|
|
113
|
+
function slidesOf(moves) {
|
|
114
|
+
return [...moves].map(([el, move]) => ({
|
|
115
|
+
el,
|
|
116
|
+
offset: withoutParent(move.offset, parentOffset(el, moves)),
|
|
117
|
+
motion: readMotion(el, move.kind)
|
|
118
|
+
}));
|
|
110
119
|
}
|
|
111
120
|
/** Adds where items are now to `starts`, keeping each item's first start; a release point always wins. */
|
|
112
121
|
function measured(options, starts) {
|
|
@@ -154,9 +163,13 @@ export function createFlip(options) {
|
|
|
154
163
|
const fallback = structural ? before : null;
|
|
155
164
|
const origin = options.origin?.() ?? VIEWPORT;
|
|
156
165
|
const sources = { origin, from: usable, before: fallback, now: rested };
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
const planned = slidesOf(movesOf(elements, sources, options));
|
|
167
|
+
const fades = entering.map((el) => readFade(el));
|
|
168
|
+
for (const each of planned) {
|
|
169
|
+
slide(each);
|
|
170
|
+
}
|
|
171
|
+
for (const fade of fades) {
|
|
172
|
+
fadeIn(fade);
|
|
160
173
|
}
|
|
161
174
|
};
|
|
162
175
|
const rest = () => {
|
|
@@ -6,7 +6,7 @@ import { PageAction, linkElement } from "./page-action";
|
|
|
6
6
|
import { useInStickyBar, usePageLabels } from "./page-context";
|
|
7
7
|
import { foldedActions } from "./page-fit";
|
|
8
8
|
import { MoreIcon } from "./page-icons";
|
|
9
|
-
import { useMeasuredFit } from "./use-measured-fit";
|
|
9
|
+
import { fitSignature, useMeasuredFit } from "./use-measured-fit";
|
|
10
10
|
/** A guess at the menu button's width, until it has been on screen once. */
|
|
11
11
|
const moreGuess = 40;
|
|
12
12
|
function actionProps(item) {
|
|
@@ -46,6 +46,7 @@ export function PageActions({ children }) {
|
|
|
46
46
|
const { value, rootRef } = useMeasuredFit({
|
|
47
47
|
enabled: !sticky,
|
|
48
48
|
initial: "",
|
|
49
|
+
signature: fitSignature(items),
|
|
49
50
|
decide: (sizes) => foldedActions({
|
|
50
51
|
widths: items.map((_, index) => sizes.widths[index]),
|
|
51
52
|
foldable,
|
|
@@ -4,7 +4,7 @@ import { Menu, MenuContent, MenuItem, MenuTrigger } from "../menu";
|
|
|
4
4
|
import { usePageLabels } from "./page-context";
|
|
5
5
|
import { hiddenCrumbs } from "./page-fit";
|
|
6
6
|
import { MoreIcon } from "./page-icons";
|
|
7
|
-
import { useMeasuredFit } from "./use-measured-fit";
|
|
7
|
+
import { fitSignature, useMeasuredFit } from "./use-measured-fit";
|
|
8
8
|
/** A guess at the "…" button's width, until it has been on screen once. */
|
|
9
9
|
const moreGuess = 48;
|
|
10
10
|
/** One page on the way to this one. It lives in a `PageBreadcrumbs`. */
|
|
@@ -44,6 +44,7 @@ export function PageBreadcrumbs({ children }) {
|
|
|
44
44
|
const { value, rootRef } = useMeasuredFit({
|
|
45
45
|
enabled: true,
|
|
46
46
|
initial: "0",
|
|
47
|
+
signature: fitSignature(crumbs),
|
|
47
48
|
decide: (sizes) => String(hiddenCrumbs({
|
|
48
49
|
widths: crumbs.map((_, index) => sizes.widths[index]),
|
|
49
50
|
room: sizes.room,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
/** What a fitting part reads off the page: its own room, and how wide each item was last seen. */
|
|
2
3
|
export interface Sizes {
|
|
3
4
|
room: number;
|
|
@@ -6,6 +7,8 @@ export interface Sizes {
|
|
|
6
7
|
/** The extra button's width ("More actions", "…"), once seen. */
|
|
7
8
|
extra: number | undefined;
|
|
8
9
|
}
|
|
10
|
+
/** What decides the size of the items: which there are, and what they say. A part measures again when it changes. */
|
|
11
|
+
export declare function fitSignature(items: readonly ReactNode[]): string;
|
|
9
12
|
/**
|
|
10
13
|
* Keeps a part's items sized to the room it has. The items carry `data-fit-index`, and the extra button
|
|
11
14
|
* `data-fit-extra`. Each width is remembered from the last time the item was on screen, so an item that has folded
|
|
@@ -15,6 +18,8 @@ export interface Sizes {
|
|
|
15
18
|
export declare function useMeasuredFit(options: {
|
|
16
19
|
enabled: boolean;
|
|
17
20
|
initial: string;
|
|
21
|
+
/** What the items are and say (`fitSignature`): the part measures again when it changes, and when the room does. */
|
|
22
|
+
signature: string;
|
|
18
23
|
decide: (sizes: Sizes) => string;
|
|
19
24
|
}): {
|
|
20
25
|
value: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
1
|
+
import { Children, isValidElement, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
import { flushSync } from "react-dom";
|
|
3
3
|
/** The width an item needs: an item that is cut short has shrunk, so it needs what its label lost as well. */
|
|
4
4
|
function neededWidth(item) {
|
|
@@ -27,6 +27,49 @@ function readSizes(root, widths, extra) {
|
|
|
27
27
|
extra: extra.current
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
function textOf(node) {
|
|
31
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
32
|
+
return String(node);
|
|
33
|
+
}
|
|
34
|
+
if (!isValidElement(node)) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
const own = Object.entries(node.props)
|
|
38
|
+
.filter(([name]) => name !== "children")
|
|
39
|
+
.map(([name, prop]) => {
|
|
40
|
+
if (isValidElement(prop)) {
|
|
41
|
+
return `${name}=${textOf(prop)}`;
|
|
42
|
+
}
|
|
43
|
+
return ["string", "number", "boolean"].includes(typeof prop)
|
|
44
|
+
? `${name}=${String(prop)}`
|
|
45
|
+
: "";
|
|
46
|
+
});
|
|
47
|
+
const type = typeof node.type === "string" ? node.type : node.type.name;
|
|
48
|
+
const inner = Children.toArray(node.props.children).map((child) => textOf(child));
|
|
49
|
+
return `<${type} ${own.join(" ")}>${inner.join("")}</>`;
|
|
50
|
+
}
|
|
51
|
+
/** What decides the size of the items: which there are, and what they say. A part measures again when it changes. */
|
|
52
|
+
export function fitSignature(items) {
|
|
53
|
+
return items
|
|
54
|
+
.map((item, index) => `${isValidElement(item) ? (item.key ?? index) : index}:${textOf(item)}`)
|
|
55
|
+
.join("|");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Measures after a render only when something that decides the fit changed: the items, the fit itself, or the room
|
|
59
|
+
* the part has. The room is read once; the other reads wait for a change.
|
|
60
|
+
*/
|
|
61
|
+
function useMeasureOnChange(root, measure, key) {
|
|
62
|
+
const seen = useRef(null);
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
const room = root ? root.clientWidth : 0;
|
|
65
|
+
const last = seen.current;
|
|
66
|
+
if (last?.measure === measure && last.key === key && last.room === room) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
seen.current = { measure, key, room };
|
|
70
|
+
measure(false);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
30
73
|
/**
|
|
31
74
|
* Keeps a part's items sized to the room it has. The items carry `data-fit-index`, and the extra button
|
|
32
75
|
* `data-fit-extra`. Each width is remembered from the last time the item was on screen, so an item that has folded
|
|
@@ -34,7 +77,7 @@ function readSizes(root, widths, extra) {
|
|
|
34
77
|
* first paint, and a resize runs it before the next. The server, and any render before the first fit, get `initial`.
|
|
35
78
|
*/
|
|
36
79
|
export function useMeasuredFit(options) {
|
|
37
|
-
const { enabled, initial, decide } = options;
|
|
80
|
+
const { enabled, initial, signature, decide } = options;
|
|
38
81
|
const [value, setValue] = useState(initial);
|
|
39
82
|
const [root, setRoot] = useState(null);
|
|
40
83
|
const current = useRef(initial);
|
|
@@ -60,9 +103,8 @@ export function useMeasuredFit(options) {
|
|
|
60
103
|
setValue(next);
|
|
61
104
|
}
|
|
62
105
|
}, [enabled, root]);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
106
|
+
useMeasureOnChange(root, measure, `${signature}
|
|
107
|
+
${value}`);
|
|
66
108
|
useEffect(() => {
|
|
67
109
|
if (!root || !enabled) {
|
|
68
110
|
return undefined;
|
package/dist/page/use-stuck.js
CHANGED
|
@@ -15,13 +15,23 @@ export function useStuck(enabled, header, holder) {
|
|
|
15
15
|
const update = () => {
|
|
16
16
|
setStuck(head.getBoundingClientRect().bottom <= hold.getBoundingClientRect().top + 0.5);
|
|
17
17
|
};
|
|
18
|
+
let frame = 0;
|
|
19
|
+
const onScroll = () => {
|
|
20
|
+
if (frame === 0) {
|
|
21
|
+
frame = requestAnimationFrame(() => {
|
|
22
|
+
frame = 0;
|
|
23
|
+
update();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
18
27
|
update();
|
|
19
|
-
document.addEventListener("scroll",
|
|
28
|
+
document.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
20
29
|
window.addEventListener("resize", update);
|
|
21
30
|
const observer = new ResizeObserver(update);
|
|
22
31
|
observer.observe(head);
|
|
23
32
|
return () => {
|
|
24
|
-
|
|
33
|
+
cancelAnimationFrame(frame);
|
|
34
|
+
document.removeEventListener("scroll", onScroll, { capture: true });
|
|
25
35
|
window.removeEventListener("resize", update);
|
|
26
36
|
observer.disconnect();
|
|
27
37
|
setStuck(false);
|
|
@@ -7,9 +7,11 @@ export type PaginationFit = 0 | 1 | 2;
|
|
|
7
7
|
export declare function nextFit(current: PaginationFit, needs: readonly (number | undefined)[], room: number): PaginationFit;
|
|
8
8
|
/**
|
|
9
9
|
* Watches the pagination's width and steps it down a level whenever its list of pages overflows, and back up
|
|
10
|
-
* once the room comes back. The server and the first paint get level 0.
|
|
10
|
+
* once the room comes back. The server and the first paint get level 0. The list is measured when it is found
|
|
11
|
+
* and whenever the returned `measure` is called, which what the pagination shows does.
|
|
11
12
|
*/
|
|
12
13
|
export declare function usePaginationFit(enabled: boolean): {
|
|
13
14
|
fit: PaginationFit;
|
|
14
15
|
rootRef: (element: HTMLElement | null) => void;
|
|
16
|
+
measure: () => void;
|
|
15
17
|
};
|
|
@@ -20,7 +20,8 @@ export function nextFit(current, needs, room) {
|
|
|
20
20
|
const listSelector = ':scope > [data-slot="pagination-list"]';
|
|
21
21
|
/**
|
|
22
22
|
* Watches the pagination's width and steps it down a level whenever its list of pages overflows, and back up
|
|
23
|
-
* once the room comes back. The server and the first paint get level 0.
|
|
23
|
+
* once the room comes back. The server and the first paint get level 0. The list is measured when it is found
|
|
24
|
+
* and whenever the returned `measure` is called, which what the pagination shows does.
|
|
24
25
|
*/
|
|
25
26
|
export function usePaginationFit(enabled) {
|
|
26
27
|
const [fit, setFit] = useState(0);
|
|
@@ -39,7 +40,7 @@ export function usePaginationFit(enabled) {
|
|
|
39
40
|
setFit(next);
|
|
40
41
|
}
|
|
41
42
|
}, [enabled, root]);
|
|
42
|
-
useLayoutEffect(measure);
|
|
43
|
+
useLayoutEffect(measure, [measure]);
|
|
43
44
|
useEffect(() => {
|
|
44
45
|
if (!root || !enabled) {
|
|
45
46
|
return undefined;
|
|
@@ -48,5 +49,5 @@ export function usePaginationFit(enabled) {
|
|
|
48
49
|
observer.observe(root);
|
|
49
50
|
return () => observer.disconnect();
|
|
50
51
|
}, [root, enabled, measure]);
|
|
51
|
-
return { fit: enabled ? fit : 0, rootRef: setRoot };
|
|
52
|
+
return { fit: enabled ? fit : 0, rootRef: setRoot, measure };
|
|
52
53
|
}
|
|
@@ -5,7 +5,8 @@ const indicatorSelector = ':scope > [data-slot="pagination-indicator"]';
|
|
|
5
5
|
/**
|
|
6
6
|
* Puts the indicator over the current page's link, measured within the landmark. The link is found by its page,
|
|
7
7
|
* since ui-sdk marks it current only after this runs. Layout offsets ignore the
|
|
8
|
-
* `translate` a sliding page carries, so it goes straight to where the page comes to rest.
|
|
8
|
+
* `translate` a sliding page carries, so it goes straight to where the page comes to rest. Every layout read
|
|
9
|
+
* comes before the first write, so the browser lays out once. With no current link
|
|
9
10
|
* in sight (the simple and compact layouts) it hides.
|
|
10
11
|
*/
|
|
11
12
|
function placeIndicator(list, page, instant) {
|
|
@@ -17,19 +18,25 @@ function placeIndicator(list, page, instant) {
|
|
|
17
18
|
const item = list.querySelector(`:scope > [data-flip-key="${page}"]`);
|
|
18
19
|
const link = item?.firstElementChild;
|
|
19
20
|
const shown = item !== null && link instanceof HTMLElement && link.offsetParent !== null;
|
|
20
|
-
indicator.toggleAttribute("data-hidden", !shown);
|
|
21
|
-
root.toggleAttribute("data-indicator", shown);
|
|
22
21
|
if (!shown) {
|
|
22
|
+
indicator.toggleAttribute("data-hidden", true);
|
|
23
|
+
root.toggleAttribute("data-indicator", false);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
indicator.
|
|
32
|
-
indicator.
|
|
26
|
+
/* A sliding item is the link's offset parent while its translate runs. */
|
|
27
|
+
const gliding = link.offsetParent !== item;
|
|
28
|
+
const x = list.offsetLeft + item.offsetLeft + link.offsetLeft + (gliding ? -item.offsetLeft : 0);
|
|
29
|
+
const y = list.offsetTop + item.offsetTop + link.offsetTop + (gliding ? -item.offsetTop : 0);
|
|
30
|
+
const width = link.offsetWidth;
|
|
31
|
+
const height = link.offsetHeight;
|
|
32
|
+
const unplaced = !Object.hasOwn(indicator.dataset, "placed");
|
|
33
|
+
indicator.toggleAttribute("data-hidden", false);
|
|
34
|
+
root.toggleAttribute("data-indicator", true);
|
|
35
|
+
indicator.toggleAttribute("data-instant", instant || unplaced);
|
|
36
|
+
indicator.style.setProperty("--_x", `${x}px`);
|
|
37
|
+
indicator.style.setProperty("--_y", `${y}px`);
|
|
38
|
+
indicator.style.setProperty("--_w", `${width}px`);
|
|
39
|
+
indicator.style.setProperty("--_ih", `${height}px`);
|
|
33
40
|
indicator.dataset.placed = "";
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
@@ -207,19 +207,41 @@
|
|
|
207
207
|
background: transparent;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
:where(
|
|
210
|
+
:where(
|
|
211
|
+
:is(
|
|
212
|
+
[data-slot="pagination-link"],
|
|
213
|
+
[data-slot="pagination-previous"],
|
|
214
|
+
[data-slot="pagination-next"],
|
|
215
|
+
[data-slot="pagination-first"],
|
|
216
|
+
[data-slot="pagination-last"]
|
|
217
|
+
):is(a, button)
|
|
218
|
+
):focus-visible {
|
|
211
219
|
outline: 2px solid var(--kumiko-pagination-focus-ring);
|
|
212
220
|
outline-offset: 2px;
|
|
213
221
|
z-index: 1;
|
|
214
222
|
}
|
|
215
223
|
|
|
216
|
-
:where(
|
|
224
|
+
:where(
|
|
225
|
+
:is(
|
|
226
|
+
[data-slot="pagination-link"],
|
|
227
|
+
[data-slot="pagination-previous"],
|
|
228
|
+
[data-slot="pagination-next"],
|
|
229
|
+
[data-slot="pagination-first"],
|
|
230
|
+
[data-slot="pagination-last"]
|
|
231
|
+
):is(a, button)[aria-disabled="true"]
|
|
232
|
+
) {
|
|
217
233
|
opacity: var(--kumiko-pagination-disabled-opacity);
|
|
218
234
|
cursor: not-allowed;
|
|
219
235
|
}
|
|
220
236
|
|
|
221
237
|
:where(
|
|
222
|
-
|
|
238
|
+
:is(
|
|
239
|
+
[data-slot="pagination-link"],
|
|
240
|
+
[data-slot="pagination-previous"],
|
|
241
|
+
[data-slot="pagination-next"],
|
|
242
|
+
[data-slot="pagination-first"],
|
|
243
|
+
[data-slot="pagination-last"]
|
|
244
|
+
):is(a, button):not([aria-disabled="true"], [data-current])
|
|
223
245
|
):active {
|
|
224
246
|
scale: var(--kumiko-press-scale);
|
|
225
247
|
transition-duration:
|
|
@@ -232,7 +254,13 @@
|
|
|
232
254
|
|
|
233
255
|
@media (hover: hover) and (pointer: fine) {
|
|
234
256
|
:where(
|
|
235
|
-
|
|
257
|
+
:is(
|
|
258
|
+
[data-slot="pagination-link"],
|
|
259
|
+
[data-slot="pagination-previous"],
|
|
260
|
+
[data-slot="pagination-next"],
|
|
261
|
+
[data-slot="pagination-first"],
|
|
262
|
+
[data-slot="pagination-last"]
|
|
263
|
+
):is(a, button):not([aria-disabled="true"], [data-current])
|
|
236
264
|
):hover {
|
|
237
265
|
background: var(--kumiko-pagination-hover-bg);
|
|
238
266
|
color: var(--kumiko-pagination-hover-fg);
|
|
@@ -256,7 +284,15 @@
|
|
|
256
284
|
|
|
257
285
|
/* A finger gets a full-size target, wider than the button where needed. */
|
|
258
286
|
@media (pointer: coarse) {
|
|
259
|
-
:where(
|
|
287
|
+
:where(
|
|
288
|
+
:is(
|
|
289
|
+
[data-slot="pagination-link"],
|
|
290
|
+
[data-slot="pagination-previous"],
|
|
291
|
+
[data-slot="pagination-next"],
|
|
292
|
+
[data-slot="pagination-first"],
|
|
293
|
+
[data-slot="pagination-last"]
|
|
294
|
+
):is(a, button)
|
|
295
|
+
)::after {
|
|
260
296
|
content: "";
|
|
261
297
|
position: absolute;
|
|
262
298
|
inset: 50% auto auto 50%;
|
|
@@ -447,7 +483,15 @@
|
|
|
447
483
|
color: HighlightText;
|
|
448
484
|
}
|
|
449
485
|
|
|
450
|
-
:where(
|
|
486
|
+
:where(
|
|
487
|
+
:is(
|
|
488
|
+
[data-slot="pagination-link"],
|
|
489
|
+
[data-slot="pagination-previous"],
|
|
490
|
+
[data-slot="pagination-next"],
|
|
491
|
+
[data-slot="pagination-first"],
|
|
492
|
+
[data-slot="pagination-last"]
|
|
493
|
+
):is(a, button)[aria-disabled="true"]
|
|
494
|
+
) {
|
|
451
495
|
color: GrayText;
|
|
452
496
|
opacity: 1;
|
|
453
497
|
}
|