@robert-stackflow/oneui 0.6.29 → 0.6.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -0
- package/components/Lightbox.d.ts +38 -0
- package/components/Lightbox.js +249 -0
- package/components/Lightbox.module.css +40 -0
- package/components/TableOfContents.d.ts +4 -1
- package/components/TableOfContents.js +15 -11
- package/components/TableOfContents.module.css +10 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +2 -0
- package/package.json +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.6.31
|
|
2
|
+
|
|
3
|
+
- Add a controlled Lightbox with source-image Hero motion, captions, thumbnails, bounded zoom/pan and pinch/swipe gestures, keyboard navigation, retry and return-to-document callbacks. Shared modal focus, scroll locking and motion remain consistent with OneUI surfaces.
|
|
4
|
+
|
|
5
|
+
## 0.6.30
|
|
6
|
+
|
|
7
|
+
- Add an optional compact full hierarchy for immersive TableOfContents rail popups, stable anchoring, outward placement and a shared animated arrow. Existing flat previews keep their defaults.
|
|
8
|
+
|
|
1
9
|
## 0.6.29
|
|
2
10
|
|
|
3
11
|
- Keep one password visibility control in Edge by suppressing the duplicate native reveal button inside PasswordField.
|
package/README.md
CHANGED
|
@@ -283,3 +283,11 @@ AccountItem 接受标题、图标、描述、元数据及操作。PasskeyItem
|
|
|
283
283
|
验证:`npm run test:sidebar-navigation`、`npm run test:visual-foundations`、`npm run test:account-forms`、`npm run test:modal-pagination`、`npm run test:package`。新增回归覆盖 React 间距覆盖、正文颜色、表格圆角与文字按钮、现有 Combobox 键盘筛选、日期标签和窄屏溢出。
|
|
284
284
|
|
|
285
285
|
Menu 支持 iconOnly:`<Menu iconOnly label="更多操作" items={items} />` 复用 IconButton,默认显示更多图标;trigger 可替换图标,variant 可设置按钮类型。
|
|
286
|
+
|
|
287
|
+
`TableOfContents` 的沉浸式完整目录使用 `railLayout="outline"`:沿用树形层级、当前章节高亮和自动滚动,浮窗锚定整条 rail 并使用共享箭头。`popoverSide="right"` 向外侧留白展开,空间不足时由 Popover 翻转避让;默认 preview 与左侧展开保持兼容。完整目录限高60dvh,可独立滚动。
|
|
288
|
+
|
|
289
|
+
### Lightbox
|
|
290
|
+
|
|
291
|
+
`Lightbox` is a controlled image viewer: pass `open`, `items`, `index`, `onIndexChange` and `onClose`. Each item has a stable `id`, `src`, `alt` and optional `caption`, `thumbnailSrc`, `width` and `height`. The optional `sourceElement(item)` resolves the original image for Hero motion; `onLocate(item)` runs after exit and scroll unlocking. Supply `labels` for localization.
|
|
292
|
+
|
|
293
|
+
The viewer supports captions, thumbnail navigation, non-wrapping previous/next, arrow keys, Escape, original-size zoom, bounded dragging, touch pinch/swipe and manual retry of the original URL. A single image hides navigation. Only adjacent full images are preloaded. It uses native modal isolation and shared OneUI focus, scroll lock and motion; reduced motion and missing/offscreen source elements use a quiet fallback. Keep the component mounted through exit and retain the selected index. Resolve resource permissions and document anchors in the host, not inside OneUI.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type LightboxItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
src: string;
|
|
5
|
+
thumbnailSrc?: string;
|
|
6
|
+
alt: string;
|
|
7
|
+
caption?: ReactNode;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
};
|
|
11
|
+
export type LightboxLabels = {
|
|
12
|
+
title: string;
|
|
13
|
+
close: string;
|
|
14
|
+
previous: string;
|
|
15
|
+
next: string;
|
|
16
|
+
zoomIn: string;
|
|
17
|
+
zoomOut: string;
|
|
18
|
+
locate: string;
|
|
19
|
+
loading: string;
|
|
20
|
+
error: string;
|
|
21
|
+
retry: string;
|
|
22
|
+
thumbnails: string;
|
|
23
|
+
image: string;
|
|
24
|
+
};
|
|
25
|
+
export type LightboxProps = {
|
|
26
|
+
open: boolean;
|
|
27
|
+
items: readonly LightboxItem[];
|
|
28
|
+
index: number;
|
|
29
|
+
onIndexChange(index: number): void;
|
|
30
|
+
onClose(): void;
|
|
31
|
+
/** Resolve the current source image for Hero motion; never store document routes in the viewer. */
|
|
32
|
+
sourceElement?(item: LightboxItem): HTMLElement | null;
|
|
33
|
+
/** Runs after exit motion and scroll unlocking, when the reader explicitly requests it. */
|
|
34
|
+
onLocate?(item: LightboxItem): void;
|
|
35
|
+
labels?: Partial<LightboxLabels>;
|
|
36
|
+
};
|
|
37
|
+
/** A controlled, accessible image viewer with shared modal lifecycle and source-image Hero motion. */
|
|
38
|
+
export declare function Lightbox(props: LightboxProps): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { X, ChevronLeft, ChevronRight, ZoomIn, ZoomOut, LocateFixed, RotateCw } from "lucide-react";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { Skeleton } from "./Skeleton.js";
|
|
8
|
+
import { usePortalRoot } from "./usePortalRoot.js";
|
|
9
|
+
import { useModalScrollLock } from "./useModalScrollLock.js";
|
|
10
|
+
import { useModalFocus } from "./useModalFocus.js";
|
|
11
|
+
import { SurfacePortalContext, useSurfaceHost, useSurfacePortal } from "./surfacePortal.js";
|
|
12
|
+
import { cancelMotion, motionDuration, reducedMotion, surfaceMotion } from "./motion.js";
|
|
13
|
+
import s from "./Lightbox.module.css";
|
|
14
|
+
const defaults = {
|
|
15
|
+
title: "Image viewer",
|
|
16
|
+
close: "Close",
|
|
17
|
+
previous: "Previous image",
|
|
18
|
+
next: "Next image",
|
|
19
|
+
zoomIn: "Original size",
|
|
20
|
+
zoomOut: "Fit image",
|
|
21
|
+
locate: "Locate in document",
|
|
22
|
+
loading: "Loading image",
|
|
23
|
+
error: "Image unavailable",
|
|
24
|
+
retry: "Retry image",
|
|
25
|
+
thumbnails: "Image thumbnails",
|
|
26
|
+
image: "Image"
|
|
27
|
+
};
|
|
28
|
+
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
29
|
+
function Lightbox(props) {
|
|
30
|
+
const portal = usePortalRoot(), owner = useSurfacePortal();
|
|
31
|
+
const { ref, host, setRef } = useSurfaceHost();
|
|
32
|
+
const imageRef = useRef(null), stageRef = useRef(null), closeRef = useRef(null);
|
|
33
|
+
const titleId = useId(), captionId = useId();
|
|
34
|
+
const live = useRef(props);
|
|
35
|
+
live.current = props;
|
|
36
|
+
const lastItems = useRef(props.items);
|
|
37
|
+
if (props.items.length) lastItems.current = props.items;
|
|
38
|
+
const items = props.items.length ? props.items : lastItems.current;
|
|
39
|
+
const index = clamp(props.index, 0, Math.max(0, items.length - 1)), item = items[index];
|
|
40
|
+
const open = props.open && props.items.length > 0 && owner?.active !== false;
|
|
41
|
+
const opened = useRef(open);
|
|
42
|
+
opened.current = open;
|
|
43
|
+
const [closing, setClosing] = useState(false), [status, setStatus] = useState("loading");
|
|
44
|
+
const [zoom, setZoom] = useState(1), [pan, setPan] = useState({ x: 0, y: 0 });
|
|
45
|
+
const pointers = useRef(/* @__PURE__ */ new Map());
|
|
46
|
+
const gesture = useRef({ x: 0, y: 0, panX: 0, panY: 0, distance: 0, scale: 1, multi: false });
|
|
47
|
+
const locate = useRef(null), heroPending = useRef(false), hero = useRef(null);
|
|
48
|
+
const { rememberFocus, restoreFocus } = useModalFocus(ref);
|
|
49
|
+
const t = { ...defaults, ...props.labels };
|
|
50
|
+
useModalScrollLock(open || closing);
|
|
51
|
+
const move = (next) => {
|
|
52
|
+
if (next < 0 || next >= items.length) return;
|
|
53
|
+
live.current.onIndexChange(next);
|
|
54
|
+
};
|
|
55
|
+
const bounds = (x, y, scale) => {
|
|
56
|
+
const img = imageRef.current, stage = stageRef.current;
|
|
57
|
+
if (!img || !stage) return { x: 0, y: 0 };
|
|
58
|
+
const maxX = Math.max(0, (img.offsetWidth * scale - stage.clientWidth) / 2), maxY = Math.max(0, (img.offsetHeight * scale - stage.clientHeight) / 2);
|
|
59
|
+
return { x: clamp(x, -maxX, maxX), y: clamp(y, -maxY, maxY) };
|
|
60
|
+
};
|
|
61
|
+
const animateImage = (exit) => {
|
|
62
|
+
const img = imageRef.current, current = items[clamp(live.current.index, 0, items.length - 1)];
|
|
63
|
+
const origin = current ? live.current.sourceElement?.(current) : null;
|
|
64
|
+
if (!img || !origin?.isConnected || !img.complete || !img.naturalWidth || reducedMotion()) return Promise.resolve();
|
|
65
|
+
const from = origin.getBoundingClientRect(), to = img.getBoundingClientRect();
|
|
66
|
+
if (!from.width || !to.width || from.bottom <= 0 || from.top >= innerHeight || from.right <= 0 || from.left >= innerWidth) return Promise.resolve();
|
|
67
|
+
const scale = Math.max(from.width / to.width, from.height / to.height);
|
|
68
|
+
const transform = `translate(${from.left + from.width / 2 - to.left - to.width / 2}px, ${from.top + from.height / 2 - to.top - to.height / 2}px) scale(${scale})`;
|
|
69
|
+
const clipPath = `inset(${Math.max(0, (to.height - from.height / scale) / 2)}px ${Math.max(0, (to.width - from.width / scale) / 2)}px)`;
|
|
70
|
+
hero.current?.cancel();
|
|
71
|
+
const animation = img.animate(exit ? [{ transform: "none", clipPath: "inset(0px)", opacity: 1 }, { transform, clipPath, opacity: 0.3 }] : [{ transform, clipPath, opacity: 0.3 }, { transform: "none", clipPath: "inset(0px)", opacity: 1 }], { duration: motionDuration(exit ? "--popup-exit" : "--popup-enter", 180), easing: "cubic-bezier(.2,.7,.2,1)" });
|
|
72
|
+
hero.current = animation;
|
|
73
|
+
return animation.finished.then(() => {
|
|
74
|
+
}, () => {
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const onLoaded = () => {
|
|
78
|
+
setStatus("loaded");
|
|
79
|
+
if (heroPending.current && opened.current) {
|
|
80
|
+
heroPending.current = false;
|
|
81
|
+
void animateImage(false);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!open) return;
|
|
86
|
+
setStatus("loading");
|
|
87
|
+
setZoom(1);
|
|
88
|
+
setPan({ x: 0, y: 0 });
|
|
89
|
+
pointers.current.clear();
|
|
90
|
+
const img = imageRef.current;
|
|
91
|
+
if (img?.complete && img.naturalWidth) onLoaded();
|
|
92
|
+
}, [open, item?.id, item?.src]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!open) return;
|
|
95
|
+
const thumb = ref.current?.querySelector('[aria-current="true"]');
|
|
96
|
+
thumb?.scrollIntoView({ block: "nearest", inline: "nearest", behavior: reducedMotion() ? "instant" : "smooth" });
|
|
97
|
+
const preload = [items[index - 1], items[index + 1]].filter(Boolean).map((entry) => {
|
|
98
|
+
const img = new Image();
|
|
99
|
+
img.src = entry.src;
|
|
100
|
+
return img;
|
|
101
|
+
});
|
|
102
|
+
return () => preload.forEach((img) => img.removeAttribute("src"));
|
|
103
|
+
}, [open, index, items]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (props.open && owner?.active === false) props.onClose();
|
|
106
|
+
}, [props.open, owner?.active, props.onClose]);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const element = ref.current;
|
|
109
|
+
const resize = () => {
|
|
110
|
+
setZoom(1);
|
|
111
|
+
setPan({ x: 0, y: 0 });
|
|
112
|
+
};
|
|
113
|
+
window.addEventListener("resize", resize);
|
|
114
|
+
return () => {
|
|
115
|
+
window.removeEventListener("resize", resize);
|
|
116
|
+
if (element) cancelMotion(element);
|
|
117
|
+
hero.current?.cancel();
|
|
118
|
+
};
|
|
119
|
+
}, [portal]);
|
|
120
|
+
useLayoutEffect(() => {
|
|
121
|
+
const dialog = ref.current;
|
|
122
|
+
if (!dialog) return;
|
|
123
|
+
if (open) {
|
|
124
|
+
dialog.inert = false;
|
|
125
|
+
setClosing(false);
|
|
126
|
+
if (!dialog.open) {
|
|
127
|
+
rememberFocus();
|
|
128
|
+
dialog.showModal();
|
|
129
|
+
closeRef.current?.focus({ preventScroll: true });
|
|
130
|
+
heroPending.current = true;
|
|
131
|
+
if (imageRef.current?.complete && imageRef.current.naturalWidth) {
|
|
132
|
+
heroPending.current = false;
|
|
133
|
+
void animateImage(false);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
void surfaceMotion(dialog, "enter", "0 0");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!dialog.open) return;
|
|
140
|
+
dialog.inert = true;
|
|
141
|
+
setClosing(true);
|
|
142
|
+
const imageExit = zoom === 1 ? animateImage(true) : Promise.resolve();
|
|
143
|
+
void Promise.all([surfaceMotion(dialog, "exit", "0 0"), imageExit]).then(([done]) => {
|
|
144
|
+
if (!done || opened.current) return;
|
|
145
|
+
dialog.close();
|
|
146
|
+
restoreFocus();
|
|
147
|
+
setClosing(false);
|
|
148
|
+
const target = locate.current;
|
|
149
|
+
locate.current = null;
|
|
150
|
+
if (target) requestAnimationFrame(() => live.current.onLocate?.(target));
|
|
151
|
+
});
|
|
152
|
+
}, [open, portal, rememberFocus, restoreFocus]);
|
|
153
|
+
if (!portal || !item) return null;
|
|
154
|
+
const toggleZoom = () => {
|
|
155
|
+
const img = imageRef.current;
|
|
156
|
+
setZoom(zoom === 1 ? clamp(img ? img.naturalWidth / Math.max(1, img.offsetWidth) : 2, 1.5, 8) : 1);
|
|
157
|
+
setPan({ x: 0, y: 0 });
|
|
158
|
+
};
|
|
159
|
+
const pointerDown = (event) => {
|
|
160
|
+
if (event.button !== 0 || status !== "loaded") return;
|
|
161
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
162
|
+
pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
163
|
+
const points = [...pointers.current.values()];
|
|
164
|
+
gesture.current = { x: event.clientX, y: event.clientY, panX: pan.x, panY: pan.y, scale: zoom, distance: points.length === 2 ? Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y) : 0, multi: points.length > 1 };
|
|
165
|
+
};
|
|
166
|
+
const pointerMove = (event) => {
|
|
167
|
+
if (!pointers.current.has(event.pointerId)) return;
|
|
168
|
+
pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
169
|
+
const points = [...pointers.current.values()], start = gesture.current;
|
|
170
|
+
if (points.length === 2 && start.distance) {
|
|
171
|
+
const scale = clamp(start.scale * Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y) / start.distance, 1, 8);
|
|
172
|
+
setZoom(scale);
|
|
173
|
+
setPan(bounds(pan.x, pan.y, scale));
|
|
174
|
+
} else if (zoom > 1 && !start.multi) setPan(bounds(start.panX + event.clientX - start.x, start.panY + event.clientY - start.y, zoom));
|
|
175
|
+
};
|
|
176
|
+
const pointerEnd = (event) => {
|
|
177
|
+
const start = gesture.current, dx = event.clientX - start.x, dy = event.clientY - start.y;
|
|
178
|
+
pointers.current.delete(event.pointerId);
|
|
179
|
+
if (event.type !== "pointercancel" && !start.multi && zoom === 1 && Math.abs(dx) > 64 && Math.abs(dx) > Math.abs(dy) * 1.2) move(index + (dx < 0 ? 1 : -1));
|
|
180
|
+
};
|
|
181
|
+
return createPortal(
|
|
182
|
+
/* @__PURE__ */ jsx(SurfacePortalContext, { value: { host, active: open }, children: /* @__PURE__ */ jsxs(
|
|
183
|
+
"dialog",
|
|
184
|
+
{
|
|
185
|
+
ref: setRef,
|
|
186
|
+
className: s.lightbox,
|
|
187
|
+
"aria-labelledby": titleId,
|
|
188
|
+
"aria-describedby": item.caption ? captionId : void 0,
|
|
189
|
+
"aria-modal": "true",
|
|
190
|
+
onCancel: (event) => {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
props.onClose();
|
|
193
|
+
},
|
|
194
|
+
onKeyDown: (event) => {
|
|
195
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
move(index + (event.key === "ArrowRight" ? 1 : -1));
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
children: [
|
|
201
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, className: s.srOnly, children: t.title }),
|
|
202
|
+
/* @__PURE__ */ jsxs("header", { className: s.header, children: [
|
|
203
|
+
/* @__PURE__ */ jsxs("span", { className: s.counter, role: "status", "aria-live": "polite", children: [
|
|
204
|
+
index + 1,
|
|
205
|
+
" / ",
|
|
206
|
+
items.length
|
|
207
|
+
] }),
|
|
208
|
+
/* @__PURE__ */ jsxs("div", { className: s.actions, children: [
|
|
209
|
+
/* @__PURE__ */ jsx(IconButton, { label: zoom > 1 ? t.zoomOut : t.zoomIn, disabled: status !== "loaded", onClick: toggleZoom, children: zoom > 1 ? /* @__PURE__ */ jsx(ZoomOut, { size: 19 }) : /* @__PURE__ */ jsx(ZoomIn, { size: 19 }) }),
|
|
210
|
+
props.onLocate && /* @__PURE__ */ jsx(IconButton, { label: t.locate, onClick: () => {
|
|
211
|
+
locate.current = item;
|
|
212
|
+
props.onClose();
|
|
213
|
+
}, children: /* @__PURE__ */ jsx(LocateFixed, { size: 19 }) }),
|
|
214
|
+
/* @__PURE__ */ jsx(IconButton, { ref: closeRef, label: t.close, onClick: props.onClose, children: /* @__PURE__ */ jsx(X, { size: 20 }) })
|
|
215
|
+
] })
|
|
216
|
+
] }),
|
|
217
|
+
/* @__PURE__ */ jsxs("div", { className: s.canvas, children: [
|
|
218
|
+
items.length > 1 && /* @__PURE__ */ jsx(IconButton, { className: s.previous, label: t.previous, disabled: index === 0, onClick: () => move(index - 1), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 24 }) }),
|
|
219
|
+
/* @__PURE__ */ jsxs("div", { ref: stageRef, className: s.stage, "data-zoomed": zoom > 1 || void 0, onPointerDown: pointerDown, onPointerMove: pointerMove, onPointerUp: pointerEnd, onPointerCancel: pointerEnd, onDoubleClick: toggleZoom, children: [
|
|
220
|
+
/* @__PURE__ */ jsx("img", { ref: imageRef, src: open || closing ? item.src : void 0, alt: item.alt, width: item.width, height: item.height, draggable: false, onLoad: onLoaded, onError: () => setStatus("error"), className: s.image, style: { opacity: status === "loaded" ? 1 : 0, transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})` } }, item.id + item.src),
|
|
221
|
+
status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: /* @__PURE__ */ jsx(Skeleton, { width: "min(55vw, 560px)", height: "min(45vh, 360px)", rounded: true }) }),
|
|
222
|
+
status === "error" && /* @__PURE__ */ jsxs("div", { className: s.feedback, role: "status", children: [
|
|
223
|
+
/* @__PURE__ */ jsx("span", { children: t.error }),
|
|
224
|
+
/* @__PURE__ */ jsx(IconButton, { label: t.retry, onClick: () => {
|
|
225
|
+
closeRef.current?.focus({ preventScroll: true });
|
|
226
|
+
setStatus("loading");
|
|
227
|
+
const img = imageRef.current;
|
|
228
|
+
if (img) {
|
|
229
|
+
img.removeAttribute("src");
|
|
230
|
+
queueMicrotask(() => {
|
|
231
|
+
if (img.isConnected) img.src = item.src;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}, children: /* @__PURE__ */ jsx(RotateCw, { size: 18 }) })
|
|
235
|
+
] })
|
|
236
|
+
] }),
|
|
237
|
+
items.length > 1 && /* @__PURE__ */ jsx(IconButton, { className: s.next, label: t.next, disabled: index === items.length - 1, onClick: () => move(index + 1), children: /* @__PURE__ */ jsx(ChevronRight, { size: 24 }) })
|
|
238
|
+
] }),
|
|
239
|
+
item.caption && /* @__PURE__ */ jsx("div", { id: captionId, className: s.caption, children: item.caption }),
|
|
240
|
+
items.length > 1 && /* @__PURE__ */ jsx("nav", { className: s.thumbnails, "aria-label": t.thumbnails, children: items.map((entry, i) => /* @__PURE__ */ jsx("button", { type: "button", "aria-label": `${t.image} ${i + 1}`, "aria-current": i === index ? "true" : void 0, onClick: () => move(i), children: /* @__PURE__ */ jsx("img", { src: open || closing ? entry.thumbnailSrc || entry.src : void 0, alt: "", loading: "lazy", draggable: false }) }, entry.id)) })
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
) }),
|
|
244
|
+
portal
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
export {
|
|
248
|
+
Lightbox
|
|
249
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.lightbox {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100dvh;
|
|
6
|
+
max-width: none;
|
|
7
|
+
max-height: none;
|
|
8
|
+
margin: 0;
|
|
9
|
+
border: 0;
|
|
10
|
+
padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
|
|
11
|
+
background: color-mix(in srgb, var(--bg) 97%, transparent);
|
|
12
|
+
color: var(--fg);
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
.lightbox[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 12px; }
|
|
16
|
+
.lightbox::backdrop { background: var(--bg); }
|
|
17
|
+
.header { display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
|
|
18
|
+
.counter { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding-inline: 8px; }
|
|
19
|
+
.actions { display: flex; gap: 4px; align-items: center; }
|
|
20
|
+
.canvas { position: relative; min-height: 0; display: flex; justify-content: center; align-items: stretch; }
|
|
21
|
+
.stage { flex: 1; min-width: 0; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; user-select: none; }
|
|
22
|
+
.stage[data-zoomed] { cursor: grab; }
|
|
23
|
+
.stage[data-zoomed]:active { cursor: grabbing; }
|
|
24
|
+
.image { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; border-radius: 2px; flex-shrink: 0; }
|
|
25
|
+
.previous, .next { position: absolute; top: calc(50% - 20px); z-index: 1; border-radius: 50%; background: color-mix(in srgb, var(--surface) 90%, transparent); }
|
|
26
|
+
.previous { left: 0; }
|
|
27
|
+
.next { right: 0; }
|
|
28
|
+
.feedback { position: absolute; inset: 0; display: flex; gap: 12px; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
|
|
29
|
+
.caption { justify-self: center; max-width: min(760px, 90vw); max-height: 15dvh; overflow: auto; font-size: 13px; line-height: 1.6; text-align: center; overflow-wrap: anywhere; }
|
|
30
|
+
.thumbnails { display: flex; gap: 8px; max-width: 100%; margin-inline: auto; overflow-x: auto; padding: 4px; }
|
|
31
|
+
.thumbnails button { flex: 0 0 56px; width: 56px; height: 44px; padding: 2px; border: 1px solid transparent; border-radius: var(--radius); background: transparent; cursor: pointer; opacity: .55; transition: opacity var(--motion-hover), border-color var(--motion-hover); }
|
|
32
|
+
.thumbnails button:hover, .thumbnails button[aria-current='true'] { opacity: 1; }
|
|
33
|
+
.thumbnails button[aria-current='true'] { border-color: var(--fg); }
|
|
34
|
+
.thumbnails img { width: 100%; height: 100%; object-fit: cover; border-radius: calc(var(--radius) - 3px); display: block; }
|
|
35
|
+
.srOnly { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
36
|
+
@media (min-width: 800px) { .stage { margin-inline: 48px; } }
|
|
37
|
+
@media (prefers-reduced-motion: reduce) { .thumbnails button { transition: none; } }
|
|
38
|
+
|
|
39
|
+
.actions button, .canvas > button { width: 40px; height: 40px; }
|
|
40
|
+
@media (pointer: coarse) { .actions button, .canvas > button { width: 44px; height: 44px; } }
|
|
@@ -10,6 +10,9 @@ export type TableOfContentsProps = {
|
|
|
10
10
|
contentRef?: RefObject<HTMLElement | null>;
|
|
11
11
|
variant?: "tree" | "rail";
|
|
12
12
|
hoverMode?: "single" | "nearby" | "all";
|
|
13
|
+
/** Display the full compact hierarchy in a rail popup. */
|
|
14
|
+
railLayout?: "preview" | "outline";
|
|
15
|
+
popoverSide?: "left" | "right";
|
|
13
16
|
previewCount?: number;
|
|
14
17
|
depthBasedLength?: boolean;
|
|
15
18
|
label?: string;
|
|
@@ -19,4 +22,4 @@ export type TableOfContentsProps = {
|
|
|
19
22
|
scrollOffset?: number;
|
|
20
23
|
className?: string;
|
|
21
24
|
};
|
|
22
|
-
export declare function TableOfContents({ items, contentRef, variant, hoverMode, previewCount, depthBasedLength, label, activeId, onActiveChange, maxLevel, scrollOffset, className, }: TableOfContentsProps): import("react").JSX.Element | null;
|
|
25
|
+
export declare function TableOfContents({ items, contentRef, variant, hoverMode, railLayout, popoverSide, previewCount, depthBasedLength, label, activeId, onActiveChange, maxLevel, scrollOffset, className, }: TableOfContentsProps): import("react").JSX.Element | null;
|
|
@@ -22,6 +22,8 @@ function TableOfContents({
|
|
|
22
22
|
contentRef,
|
|
23
23
|
variant = "tree",
|
|
24
24
|
hoverMode = "nearby",
|
|
25
|
+
railLayout = "preview",
|
|
26
|
+
popoverSide = "left",
|
|
25
27
|
previewCount = 5,
|
|
26
28
|
depthBasedLength = false,
|
|
27
29
|
label = "\u672C\u9875\u76EE\u5F55",
|
|
@@ -58,9 +60,9 @@ function TableOfContents({
|
|
|
58
60
|
);
|
|
59
61
|
const popupAnchor = useMemo(
|
|
60
62
|
() => ({
|
|
61
|
-
current: lineNodes.current.get(entries[previewIndex]?.id ?? "") ?? railRoot.current
|
|
63
|
+
current: railLayout === "outline" ? railRoot.current : lineNodes.current.get(entries[previewIndex]?.id ?? "") ?? railRoot.current
|
|
62
64
|
}),
|
|
63
|
-
[previewIndex, entries, open]
|
|
65
|
+
[previewIndex, entries, open, railLayout]
|
|
64
66
|
);
|
|
65
67
|
const count = Number.isFinite(previewCount) ? Math.max(1, Math.floor(previewCount)) : 5;
|
|
66
68
|
const windowStart = Math.max(
|
|
@@ -156,7 +158,7 @@ function TableOfContents({
|
|
|
156
158
|
}, [entries, scrollOffset]);
|
|
157
159
|
useLayoutEffect(() => {
|
|
158
160
|
const node = list.current;
|
|
159
|
-
if (!node || variant === "rail") return;
|
|
161
|
+
if (!node || variant === "rail" && railLayout === "preview") return;
|
|
160
162
|
const measure = () => {
|
|
161
163
|
const links = [...node.querySelectorAll("a")];
|
|
162
164
|
if (!links.length || !node.offsetWidth) return;
|
|
@@ -197,7 +199,7 @@ function TableOfContents({
|
|
|
197
199
|
const observer = new ResizeObserver(measure);
|
|
198
200
|
observer.observe(node);
|
|
199
201
|
return () => observer.disconnect();
|
|
200
|
-
}, [entries, open, variant]);
|
|
202
|
+
}, [entries, open, variant, railLayout]);
|
|
201
203
|
const indices = entries.flatMap(
|
|
202
204
|
(entry, index) => active.includes(entry.id) ? [index] : []
|
|
203
205
|
);
|
|
@@ -207,14 +209,15 @@ function TableOfContents({
|
|
|
207
209
|
const distance = first && last ? up ? first.distance : last.distance + last.bottom - last.top : 0;
|
|
208
210
|
useLayoutEffect(() => {
|
|
209
211
|
const node = list.current;
|
|
210
|
-
if (!node || variant !== "tree" || !diagram.path)
|
|
212
|
+
if (!node || variant !== "tree" && railLayout !== "outline" || !diagram.path)
|
|
213
|
+
return;
|
|
211
214
|
if (!node.dataset.ready || measuredPath.current !== diagram.path) {
|
|
212
215
|
node.dataset.ready = "false";
|
|
213
216
|
node.getBoundingClientRect();
|
|
214
217
|
node.dataset.ready = "true";
|
|
215
218
|
measuredPath.current = diagram.path;
|
|
216
219
|
}
|
|
217
|
-
}, [diagram.path, variant]);
|
|
220
|
+
}, [diagram.path, variant, railLayout]);
|
|
218
221
|
useLayoutEffect(() => {
|
|
219
222
|
const node = list.current, viewport = node?.parentElement;
|
|
220
223
|
if (!viewport || !first || !last || !open && variant === "rail") return;
|
|
@@ -230,7 +233,7 @@ function TableOfContents({
|
|
|
230
233
|
});
|
|
231
234
|
}, [first, last, open, variant]);
|
|
232
235
|
useLayoutEffect(() => {
|
|
233
|
-
if (variant !== "rail" || !open) return;
|
|
236
|
+
if (variant !== "rail" || railLayout !== "preview" || !open) return;
|
|
234
237
|
const node = list.current, viewport = node?.parentElement;
|
|
235
238
|
const selected = node?.querySelector(
|
|
236
239
|
'[data-preview-target="true"]'
|
|
@@ -240,7 +243,7 @@ function TableOfContents({
|
|
|
240
243
|
viewport.scrollTop = selected.offsetTop;
|
|
241
244
|
else if (selected.offsetTop + selected.offsetHeight > viewport.scrollTop + viewport.clientHeight)
|
|
242
245
|
viewport.scrollTop = selected.offsetTop + selected.offsetHeight - viewport.clientHeight;
|
|
243
|
-
}, [current, open, variant, previewIndex, hoverMode]);
|
|
246
|
+
}, [current, open, variant, previewIndex, hoverMode, railLayout]);
|
|
244
247
|
useEffect(() => () => clearTimeout(timer.current), []);
|
|
245
248
|
const keepOpen = () => clearTimeout(timer.current);
|
|
246
249
|
const closeSoon = () => {
|
|
@@ -261,7 +264,7 @@ function TableOfContents({
|
|
|
261
264
|
});
|
|
262
265
|
setOpen(false);
|
|
263
266
|
};
|
|
264
|
-
const contents = () => variant === "rail" ? /* @__PURE__ */ jsxs(
|
|
267
|
+
const contents = () => variant === "rail" && railLayout === "preview" ? /* @__PURE__ */ jsxs(
|
|
265
268
|
"nav",
|
|
266
269
|
{
|
|
267
270
|
className: s.flatMenu,
|
|
@@ -295,7 +298,7 @@ function TableOfContents({
|
|
|
295
298
|
) : /* @__PURE__ */ jsxs(
|
|
296
299
|
"nav",
|
|
297
300
|
{
|
|
298
|
-
className: `${s.tree} ${variant === "tree" ? className : ""}`,
|
|
301
|
+
className: `${s.tree} ${railLayout === "outline" && variant === "rail" ? s.outlineTree : ""} ${variant === "tree" ? className : ""}`,
|
|
299
302
|
"aria-label": label,
|
|
300
303
|
children: [
|
|
301
304
|
/* @__PURE__ */ jsxs("div", { className: s.title, children: [
|
|
@@ -430,7 +433,7 @@ function TableOfContents({
|
|
|
430
433
|
});
|
|
431
434
|
},
|
|
432
435
|
anchor: popupAnchor,
|
|
433
|
-
side:
|
|
436
|
+
side: popoverSide,
|
|
434
437
|
align: "start",
|
|
435
438
|
label,
|
|
436
439
|
width: hoverMode === "single" ? 320 : 290,
|
|
@@ -438,6 +441,7 @@ function TableOfContents({
|
|
|
438
441
|
maxHeight: Infinity,
|
|
439
442
|
scrollable: false,
|
|
440
443
|
autoFocus: false,
|
|
444
|
+
arrow: railLayout === "outline",
|
|
441
445
|
children: /* @__PURE__ */ jsx(
|
|
442
446
|
"div",
|
|
443
447
|
{
|
|
@@ -130,6 +130,16 @@
|
|
|
130
130
|
.card .scroll {
|
|
131
131
|
max-height: min(440px, calc(100dvh - 110px));
|
|
132
132
|
}
|
|
133
|
+
.outlineTree .scroll {
|
|
134
|
+
max-height: min(480px, 60dvh, calc(100dvh - 96px));
|
|
135
|
+
}
|
|
136
|
+
.outlineTree .title {
|
|
137
|
+
margin-bottom: 6px;
|
|
138
|
+
}
|
|
139
|
+
.outlineTree .link {
|
|
140
|
+
line-height: 1.5;
|
|
141
|
+
min-height: 32px;
|
|
142
|
+
}
|
|
133
143
|
@media (prefers-reduced-motion: reduce) {
|
|
134
144
|
.activeGuide,
|
|
135
145
|
.thumb,
|
package/components/index.d.ts
CHANGED
|
@@ -191,3 +191,4 @@ export { EditableHeading } from "./EditableHeading";
|
|
|
191
191
|
export type { EditableHeadingProps } from "./EditableHeading";
|
|
192
192
|
export type { TableOfContentsProps, TableOfContentsItem, } from "./TableOfContents";
|
|
193
193
|
export type { MarkdownCodeTheme } from "./Markdown";
|
|
194
|
+
export { Lightbox, type LightboxProps, type LightboxItem, type LightboxLabels } from "./Lightbox";
|
package/components/index.js
CHANGED
|
@@ -156,6 +156,7 @@ import { Markdown } from "./Markdown.js";
|
|
|
156
156
|
import { Banner } from "./Banner.js";
|
|
157
157
|
import { TableOfContents } from "./TableOfContents.js";
|
|
158
158
|
import { EditableHeading } from "./EditableHeading.js";
|
|
159
|
+
import { Lightbox } from "./Lightbox.js";
|
|
159
160
|
export {
|
|
160
161
|
Accordion,
|
|
161
162
|
AccountItem,
|
|
@@ -218,6 +219,7 @@ export {
|
|
|
218
219
|
IconSurface,
|
|
219
220
|
Indicator,
|
|
220
221
|
Input,
|
|
222
|
+
Lightbox,
|
|
221
223
|
Link,
|
|
222
224
|
LoadingOverlay,
|
|
223
225
|
LoadingState,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robert-stackflow/oneui",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.31",
|
|
4
4
|
"description": "OneUI React components, application shell and portable visual themes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -923,7 +923,13 @@
|
|
|
923
923
|
"types": "./components/SelectSettingRow.d.ts",
|
|
924
924
|
"import": "./components/SelectSettingRow.js",
|
|
925
925
|
"default": "./components/SelectSettingRow.js"
|
|
926
|
-
}
|
|
926
|
+
},
|
|
927
|
+
"./Lightbox": {
|
|
928
|
+
"types": "./components/Lightbox.d.ts",
|
|
929
|
+
"import": "./components/Lightbox.js",
|
|
930
|
+
"default": "./components/Lightbox.js"
|
|
931
|
+
},
|
|
932
|
+
"./Lightbox.module.css": "./components/Lightbox.module.css"
|
|
927
933
|
},
|
|
928
934
|
"files": [
|
|
929
935
|
"components",
|