@robert-stackflow/oneui 0.6.30 → 0.6.32
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 +47 -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.32
|
|
2
|
+
|
|
3
|
+
- Give Lightbox an opaque black canvas and matching light controls in every document color mode; remove the dependency on an undefined background variable.
|
|
4
|
+
|
|
5
|
+
## 0.6.31
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
1
9
|
## 0.6.30
|
|
2
10
|
|
|
3
11
|
- 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.
|
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 uses an opaque black canvas with light controls independently of the document color mode. It 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,47 @@
|
|
|
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
|
+
/* Image viewing is an opaque dark surface in every document color mode. */
|
|
12
|
+
color-scheme: dark;
|
|
13
|
+
--surface: #1d1d1d;
|
|
14
|
+
--fg: #f5f5f5;
|
|
15
|
+
--muted: #b5b5b5;
|
|
16
|
+
--hover: #ffffff18;
|
|
17
|
+
--line: #ffffff24;
|
|
18
|
+
background: #111;
|
|
19
|
+
color: var(--fg);
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
}
|
|
22
|
+
.lightbox[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 12px; }
|
|
23
|
+
.lightbox::backdrop { background: #111; }
|
|
24
|
+
.header { display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
|
|
25
|
+
.counter { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding-inline: 8px; }
|
|
26
|
+
.actions { display: flex; gap: 4px; align-items: center; }
|
|
27
|
+
.canvas { position: relative; min-height: 0; display: flex; justify-content: center; align-items: stretch; }
|
|
28
|
+
.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; }
|
|
29
|
+
.stage[data-zoomed] { cursor: grab; }
|
|
30
|
+
.stage[data-zoomed]:active { cursor: grabbing; }
|
|
31
|
+
.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; }
|
|
32
|
+
.previous, .next { position: absolute; top: calc(50% - 20px); z-index: 1; border-radius: 50%; background: color-mix(in srgb, var(--surface) 90%, transparent); }
|
|
33
|
+
.previous { left: 0; }
|
|
34
|
+
.next { right: 0; }
|
|
35
|
+
.feedback { position: absolute; inset: 0; display: flex; gap: 12px; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
|
|
36
|
+
.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; }
|
|
37
|
+
.thumbnails { display: flex; gap: 8px; max-width: 100%; margin-inline: auto; overflow-x: auto; padding: 4px; }
|
|
38
|
+
.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); }
|
|
39
|
+
.thumbnails button:hover, .thumbnails button[aria-current='true'] { opacity: 1; }
|
|
40
|
+
.thumbnails button[aria-current='true'] { border-color: var(--fg); }
|
|
41
|
+
.thumbnails img { width: 100%; height: 100%; object-fit: cover; border-radius: calc(var(--radius) - 3px); display: block; }
|
|
42
|
+
.srOnly { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
43
|
+
@media (min-width: 800px) { .stage { margin-inline: 48px; } }
|
|
44
|
+
@media (prefers-reduced-motion: reduce) { .thumbnails button { transition: none; } }
|
|
45
|
+
|
|
46
|
+
.actions button, .canvas > button { width: 40px; height: 40px; }
|
|
47
|
+
@media (pointer: coarse) { .actions button, .canvas > button { width: 44px; height: 44px; } }
|
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.32",
|
|
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",
|