@robert-stackflow/oneui 0.6.31 → 0.6.33

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.6.33
2
+
3
+ - Animate Lightbox image changes with directional transitions that retain the outgoing image, add a sliding thumbnail selection indicator and keyboard focus ring, and preserve document width in the shared nested modal scroll lock.
4
+
5
+ ## 0.6.32
6
+
7
+ - Give Lightbox an opaque black canvas and matching light controls in every document color mode; remove the dependency on an undefined background variable.
8
+
1
9
  ## 0.6.31
2
10
 
3
11
  - 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.
package/README.md CHANGED
@@ -290,4 +290,6 @@ Menu 支持 iconOnly:`<Menu iconOnly label="更多操作" items={items} />`
290
290
 
291
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
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.
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.
294
+
295
+ Image changes retain the existing outgoing image for a directional fade/slide, without remounting it for the animation. Thumbnail selection uses a moving outline and a separate keyboard focus ring. Shared modal scroll locking preserves classic scrollbar space, nested lock ownership and original document styles.
@@ -1,15 +1,38 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import {
4
+ useEffect,
5
+ useId,
6
+ useLayoutEffect,
7
+ useRef,
8
+ useState
9
+ } from "react";
4
10
  import { createPortal } from "react-dom";
5
- import { X, ChevronLeft, ChevronRight, ZoomIn, ZoomOut, LocateFixed, RotateCw } from "lucide-react";
11
+ import {
12
+ X,
13
+ ChevronLeft,
14
+ ChevronRight,
15
+ ZoomIn,
16
+ ZoomOut,
17
+ LocateFixed,
18
+ RotateCw
19
+ } from "lucide-react";
6
20
  import { IconButton } from "./IconButton.js";
7
21
  import { Skeleton } from "./Skeleton.js";
8
22
  import { usePortalRoot } from "./usePortalRoot.js";
9
23
  import { useModalScrollLock } from "./useModalScrollLock.js";
10
24
  import { useModalFocus } from "./useModalFocus.js";
11
- import { SurfacePortalContext, useSurfaceHost, useSurfacePortal } from "./surfacePortal.js";
12
- import { cancelMotion, motionDuration, reducedMotion, surfaceMotion } from "./motion.js";
25
+ import {
26
+ SurfacePortalContext,
27
+ useSurfaceHost,
28
+ useSurfacePortal
29
+ } from "./surfacePortal.js";
30
+ import {
31
+ cancelMotion,
32
+ motionDuration,
33
+ reducedMotion,
34
+ surfaceMotion
35
+ } from "./motion.js";
13
36
  import s from "./Lightbox.module.css";
14
37
  const defaults = {
15
38
  title: "Image viewer",
@@ -29,6 +52,9 @@ const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
29
52
  function Lightbox(props) {
30
53
  const portal = usePortalRoot(), owner = useSurfacePortal();
31
54
  const { ref, host, setRef } = useSurfaceHost();
55
+ const outgoingRef = useRef(null), thumbnailsRef = useRef(null);
56
+ const [indicator, setIndicator] = useState(null);
57
+ const slideAnimations = useRef([]);
32
58
  const imageRef = useRef(null), stageRef = useRef(null), closeRef = useRef(null);
33
59
  const titleId = useId(), captionId = useId();
34
60
  const live = useRef(props);
@@ -42,8 +68,28 @@ function Lightbox(props) {
42
68
  opened.current = open;
43
69
  const [closing, setClosing] = useState(false), [status, setStatus] = useState("loading");
44
70
  const [zoom, setZoom] = useState(1), [pan, setPan] = useState({ x: 0, y: 0 });
71
+ const itemKey = item ? item.id + item.src : "";
72
+ const [slide, setSlide] = useState({ key: itemKey, index, current: item, direction: 0 });
73
+ if (slide.key !== itemKey)
74
+ setSlide({
75
+ key: itemKey,
76
+ index,
77
+ current: item,
78
+ previous: open && status === "loaded" && imageRef.current?.complete && imageRef.current.naturalWidth ? slide.current : void 0,
79
+ direction: index >= slide.index ? 1 : -1
80
+ });
81
+ const slideState = useRef(slide);
82
+ slideState.current = slide;
45
83
  const pointers = useRef(/* @__PURE__ */ new Map());
46
- const gesture = useRef({ x: 0, y: 0, panX: 0, panY: 0, distance: 0, scale: 1, multi: false });
84
+ const gesture = useRef({
85
+ x: 0,
86
+ y: 0,
87
+ panX: 0,
88
+ panY: 0,
89
+ distance: 0,
90
+ scale: 1,
91
+ multi: false
92
+ });
47
93
  const locate = useRef(null), heroPending = useRef(false), hero = useRef(null);
48
94
  const { rememberFocus, restoreFocus } = useModalFocus(ref);
49
95
  const t = { ...defaults, ...props.labels };
@@ -61,26 +107,94 @@ function Lightbox(props) {
61
107
  const animateImage = (exit) => {
62
108
  const img = imageRef.current, current = items[clamp(live.current.index, 0, items.length - 1)];
63
109
  const origin = current ? live.current.sourceElement?.(current) : null;
64
- if (!img || !origin?.isConnected || !img.complete || !img.naturalWidth || reducedMotion()) return Promise.resolve();
110
+ if (!img || !origin?.isConnected || !img.complete || !img.naturalWidth || reducedMotion())
111
+ return Promise.resolve();
65
112
  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();
113
+ if (!from.width || !to.width || from.bottom <= 0 || from.top >= innerHeight || from.right <= 0 || from.left >= innerWidth)
114
+ return Promise.resolve();
67
115
  const scale = Math.max(from.width / to.width, from.height / to.height);
68
116
  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
117
  const clipPath = `inset(${Math.max(0, (to.height - from.height / scale) / 2)}px ${Math.max(0, (to.width - from.width / scale) / 2)}px)`;
70
118
  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)" });
119
+ const animation = img.animate(
120
+ exit ? [
121
+ { transform: "none", clipPath: "inset(0px)", opacity: 1 },
122
+ { transform, clipPath, opacity: 0.3 }
123
+ ] : [
124
+ { transform, clipPath, opacity: 0.3 },
125
+ { transform: "none", clipPath: "inset(0px)", opacity: 1 }
126
+ ],
127
+ {
128
+ duration: motionDuration(exit ? "--popup-exit" : "--popup-enter", 180),
129
+ easing: "cubic-bezier(.2,.7,.2,1)"
130
+ }
131
+ );
72
132
  hero.current = animation;
73
- return animation.finished.then(() => {
74
- }, () => {
75
- });
133
+ return animation.finished.then(
134
+ () => {
135
+ },
136
+ () => {
137
+ }
138
+ );
76
139
  };
140
+ const finishSlide = (key) => setSlide(
141
+ (current) => current.key === key ? { ...current, previous: void 0 } : current
142
+ );
77
143
  const onLoaded = () => {
78
144
  setStatus("loaded");
79
145
  if (heroPending.current && opened.current) {
80
146
  heroPending.current = false;
81
147
  void animateImage(false);
148
+ finishSlide(itemKey);
149
+ return;
150
+ }
151
+ if (!slide.previous || !opened.current) return;
152
+ slideAnimations.current.forEach((animation) => animation.cancel());
153
+ if (reducedMotion()) {
154
+ finishSlide(itemKey);
155
+ return;
82
156
  }
157
+ const options = {
158
+ duration: motionDuration("--popup-enter", 180),
159
+ easing: "cubic-bezier(.2,.7,.2,1)"
160
+ };
161
+ const animations = [
162
+ imageRef.current?.animate(
163
+ [
164
+ { opacity: 0, transform: `translateX(${slide.direction * 24}px)` },
165
+ { opacity: 1, transform: "none" }
166
+ ],
167
+ options
168
+ ),
169
+ outgoingRef.current?.animate(
170
+ [
171
+ { opacity: 1, transform: "none" },
172
+ { opacity: 0, transform: `translateX(${-slide.direction * 24}px)` }
173
+ ],
174
+ options
175
+ )
176
+ ].filter((value) => !!value);
177
+ slideAnimations.current = animations;
178
+ void Promise.all(
179
+ animations.map((animation) => animation.finished.catch(() => {
180
+ }))
181
+ ).then(() => {
182
+ if (slideState.current.key === itemKey) finishSlide(itemKey);
183
+ });
83
184
  };
185
+ useLayoutEffect(() => {
186
+ if (!open) return;
187
+ const thumb = thumbnailsRef.current?.querySelector(
188
+ '[aria-current="true"]'
189
+ );
190
+ if (!thumb) return;
191
+ setIndicator({
192
+ x: thumb.offsetLeft,
193
+ y: thumb.offsetTop,
194
+ width: thumb.offsetWidth,
195
+ height: thumb.offsetHeight
196
+ });
197
+ }, [open, index, portal]);
84
198
  useEffect(() => {
85
199
  if (!open) return;
86
200
  setStatus("loading");
@@ -92,8 +206,14 @@ function Lightbox(props) {
92
206
  }, [open, item?.id, item?.src]);
93
207
  useEffect(() => {
94
208
  if (!open) return;
95
- const thumb = ref.current?.querySelector('[aria-current="true"]');
96
- thumb?.scrollIntoView({ block: "nearest", inline: "nearest", behavior: reducedMotion() ? "instant" : "smooth" });
209
+ const thumb = ref.current?.querySelector(
210
+ '[aria-current="true"]'
211
+ );
212
+ thumb?.scrollIntoView({
213
+ block: "nearest",
214
+ inline: "nearest",
215
+ behavior: reducedMotion() ? "instant" : "smooth"
216
+ });
97
217
  const preload = [items[index - 1], items[index + 1]].filter(Boolean).map((entry) => {
98
218
  const img = new Image();
99
219
  img.src = entry.src;
@@ -115,6 +235,7 @@ function Lightbox(props) {
115
235
  window.removeEventListener("resize", resize);
116
236
  if (element) cancelMotion(element);
117
237
  hero.current?.cancel();
238
+ slideAnimations.current.forEach((animation) => animation.cancel());
118
239
  };
119
240
  }, [portal]);
120
241
  useLayoutEffect(() => {
@@ -140,43 +261,78 @@ function Lightbox(props) {
140
261
  dialog.inert = true;
141
262
  setClosing(true);
142
263
  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
- });
264
+ void Promise.all([surfaceMotion(dialog, "exit", "0 0"), imageExit]).then(
265
+ ([done]) => {
266
+ if (!done || opened.current) return;
267
+ dialog.close();
268
+ restoreFocus();
269
+ setClosing(false);
270
+ const target = locate.current;
271
+ locate.current = null;
272
+ if (target)
273
+ requestAnimationFrame(() => live.current.onLocate?.(target));
274
+ }
275
+ );
152
276
  }, [open, portal, rememberFocus, restoreFocus]);
153
277
  if (!portal || !item) return null;
154
278
  const toggleZoom = () => {
155
279
  const img = imageRef.current;
156
- setZoom(zoom === 1 ? clamp(img ? img.naturalWidth / Math.max(1, img.offsetWidth) : 2, 1.5, 8) : 1);
280
+ setZoom(
281
+ zoom === 1 ? clamp(
282
+ img ? img.naturalWidth / Math.max(1, img.offsetWidth) : 2,
283
+ 1.5,
284
+ 8
285
+ ) : 1
286
+ );
157
287
  setPan({ x: 0, y: 0 });
158
288
  };
159
289
  const pointerDown = (event) => {
160
290
  if (event.button !== 0 || status !== "loaded") return;
161
291
  event.currentTarget.setPointerCapture(event.pointerId);
162
- pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
292
+ pointers.current.set(event.pointerId, {
293
+ x: event.clientX,
294
+ y: event.clientY
295
+ });
163
296
  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 };
297
+ gesture.current = {
298
+ x: event.clientX,
299
+ y: event.clientY,
300
+ panX: pan.x,
301
+ panY: pan.y,
302
+ scale: zoom,
303
+ distance: points.length === 2 ? Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y) : 0,
304
+ multi: points.length > 1
305
+ };
165
306
  };
166
307
  const pointerMove = (event) => {
167
308
  if (!pointers.current.has(event.pointerId)) return;
168
- pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
309
+ pointers.current.set(event.pointerId, {
310
+ x: event.clientX,
311
+ y: event.clientY
312
+ });
169
313
  const points = [...pointers.current.values()], start = gesture.current;
170
314
  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);
315
+ const scale = clamp(
316
+ start.scale * Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y) / start.distance,
317
+ 1,
318
+ 8
319
+ );
172
320
  setZoom(scale);
173
321
  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));
322
+ } else if (zoom > 1 && !start.multi)
323
+ setPan(
324
+ bounds(
325
+ start.panX + event.clientX - start.x,
326
+ start.panY + event.clientY - start.y,
327
+ zoom
328
+ )
329
+ );
175
330
  };
176
331
  const pointerEnd = (event) => {
177
332
  const start = gesture.current, dx = event.clientX - start.x, dy = event.clientY - start.y;
178
333
  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));
334
+ if (event.type !== "pointercancel" && !start.multi && zoom === 1 && Math.abs(dx) > 64 && Math.abs(dx) > Math.abs(dy) * 1.2)
335
+ move(index + (dx < 0 ? 1 : -1));
180
336
  };
181
337
  return createPortal(
182
338
  /* @__PURE__ */ jsx(SurfacePortalContext, { value: { host, active: open }, children: /* @__PURE__ */ jsxs(
@@ -206,38 +362,166 @@ function Lightbox(props) {
206
362
  items.length
207
363
  ] }),
208
364
  /* @__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 }) }),
365
+ /* @__PURE__ */ jsx(
366
+ IconButton,
367
+ {
368
+ label: zoom > 1 ? t.zoomOut : t.zoomIn,
369
+ disabled: status !== "loaded",
370
+ onClick: toggleZoom,
371
+ children: zoom > 1 ? /* @__PURE__ */ jsx(ZoomOut, { size: 19 }) : /* @__PURE__ */ jsx(ZoomIn, { size: 19 })
372
+ }
373
+ ),
374
+ props.onLocate && /* @__PURE__ */ jsx(
375
+ IconButton,
376
+ {
377
+ label: t.locate,
378
+ onClick: () => {
379
+ locate.current = item;
380
+ props.onClose();
381
+ },
382
+ children: /* @__PURE__ */ jsx(LocateFixed, { size: 19 })
383
+ }
384
+ ),
214
385
  /* @__PURE__ */ jsx(IconButton, { ref: closeRef, label: t.close, onClick: props.onClose, children: /* @__PURE__ */ jsx(X, { size: 20 }) })
215
386
  ] })
216
387
  ] }),
217
388
  /* @__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 }) })
389
+ items.length > 1 && /* @__PURE__ */ jsx(
390
+ IconButton,
391
+ {
392
+ className: s.previous,
393
+ label: t.previous,
394
+ disabled: index === 0,
395
+ onClick: () => move(index - 1),
396
+ children: /* @__PURE__ */ jsx(ChevronLeft, { size: 24 })
397
+ }
398
+ ),
399
+ /* @__PURE__ */ jsxs(
400
+ "div",
401
+ {
402
+ ref: stageRef,
403
+ className: s.stage,
404
+ "data-zoomed": zoom > 1 || void 0,
405
+ onPointerDown: pointerDown,
406
+ onPointerMove: pointerMove,
407
+ onPointerUp: pointerEnd,
408
+ onPointerCancel: pointerEnd,
409
+ onDoubleClick: toggleZoom,
410
+ children: [
411
+ [...slide.previous ? [slide.previous] : [], item].map(
412
+ (entry, i, frames) => {
413
+ const current = i === frames.length - 1;
414
+ return /* @__PURE__ */ jsx(
415
+ "img",
416
+ {
417
+ ref: current ? imageRef : outgoingRef,
418
+ src: open || closing ? entry.src : void 0,
419
+ alt: current ? entry.alt : "",
420
+ "aria-hidden": !current || void 0,
421
+ width: entry.width,
422
+ height: entry.height,
423
+ draggable: false,
424
+ onLoad: current ? onLoaded : void 0,
425
+ onError: current ? () => {
426
+ setStatus("error");
427
+ finishSlide(itemKey);
428
+ } : void 0,
429
+ className: `${s.image} ${!current ? s.outgoing : ""}`,
430
+ "data-image-phase": current ? "current" : "outgoing",
431
+ style: {
432
+ opacity: current ? status === "loaded" ? 1 : 0 : 1,
433
+ transform: current ? `translate(${pan.x}px, ${pan.y}px) scale(${zoom})` : "none"
434
+ }
435
+ },
436
+ entry.id + entry.src
437
+ );
438
+ }
439
+ ),
440
+ status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: /* @__PURE__ */ jsx(
441
+ Skeleton,
442
+ {
443
+ width: "min(55vw, 560px)",
444
+ height: "min(45vh, 360px)",
445
+ rounded: true
446
+ }
447
+ ) }),
448
+ status === "error" && /* @__PURE__ */ jsxs("div", { className: s.feedback, role: "status", children: [
449
+ /* @__PURE__ */ jsx("span", { children: t.error }),
450
+ /* @__PURE__ */ jsx(
451
+ IconButton,
452
+ {
453
+ label: t.retry,
454
+ onClick: () => {
455
+ closeRef.current?.focus({ preventScroll: true });
456
+ setStatus("loading");
457
+ const img = imageRef.current;
458
+ if (img) {
459
+ img.removeAttribute("src");
460
+ queueMicrotask(() => {
461
+ if (img.isConnected) img.src = item.src;
462
+ });
463
+ }
464
+ },
465
+ children: /* @__PURE__ */ jsx(RotateCw, { size: 18 })
466
+ }
467
+ )
468
+ ] })
469
+ ]
470
+ }
471
+ ),
472
+ items.length > 1 && /* @__PURE__ */ jsx(
473
+ IconButton,
474
+ {
475
+ className: s.next,
476
+ label: t.next,
477
+ disabled: index === items.length - 1,
478
+ onClick: () => move(index + 1),
479
+ children: /* @__PURE__ */ jsx(ChevronRight, { size: 24 })
480
+ }
481
+ )
238
482
  ] }),
239
483
  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)) })
484
+ items.length > 1 && /* @__PURE__ */ jsxs(
485
+ "nav",
486
+ {
487
+ ref: thumbnailsRef,
488
+ className: s.thumbnails,
489
+ "aria-label": t.thumbnails,
490
+ children: [
491
+ indicator && /* @__PURE__ */ jsx(
492
+ "span",
493
+ {
494
+ "aria-hidden": "true",
495
+ className: s.thumbnailIndicator,
496
+ style: {
497
+ width: indicator.width,
498
+ height: indicator.height,
499
+ transform: `translate(${indicator.x}px, ${indicator.y}px)`
500
+ }
501
+ }
502
+ ),
503
+ items.map((entry, i) => /* @__PURE__ */ jsx(
504
+ "button",
505
+ {
506
+ type: "button",
507
+ "aria-label": `${t.image} ${i + 1}`,
508
+ "aria-current": i === index ? "true" : void 0,
509
+ onClick: () => move(i),
510
+ children: /* @__PURE__ */ jsx(
511
+ "img",
512
+ {
513
+ src: open || closing ? entry.thumbnailSrc || entry.src : void 0,
514
+ alt: "",
515
+ loading: "lazy",
516
+ draggable: false
517
+ }
518
+ )
519
+ },
520
+ entry.id
521
+ ))
522
+ ]
523
+ }
524
+ )
241
525
  ]
242
526
  }
243
527
  ) }),
@@ -7,34 +7,218 @@
7
7
  max-height: none;
8
8
  margin: 0;
9
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);
10
+ padding: max(12px, env(safe-area-inset-top))
11
+ max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
12
+ max(16px, env(safe-area-inset-left));
13
+ /* Image viewing is an opaque dark surface in every document color mode. */
14
+ color-scheme: dark;
15
+ --surface: #1d1d1d;
16
+ --fg: #f5f5f5;
17
+ --accent: var(--fg);
18
+ --accent-ink: var(--fg);
19
+ --soft: #262626;
20
+ --muted: #b5b5b5;
21
+ --hover: #ffffff18;
22
+ --line: #ffffff24;
23
+ background: #111;
12
24
  color: var(--fg);
13
25
  overflow: hidden;
14
26
  }
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; } }
27
+ .lightbox[open] {
28
+ display: grid;
29
+ grid-template-rows: auto minmax(0, 1fr) auto auto;
30
+ gap: 12px;
31
+ }
32
+ .lightbox::backdrop {
33
+ background: #111;
34
+ }
35
+ .header {
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: space-between;
39
+ min-height: 40px;
40
+ }
41
+ .counter {
42
+ color: var(--muted);
43
+ font-size: 13px;
44
+ font-variant-numeric: tabular-nums;
45
+ padding-inline: 8px;
46
+ }
47
+ .actions {
48
+ display: flex;
49
+ gap: 4px;
50
+ align-items: center;
51
+ }
52
+ .canvas {
53
+ position: relative;
54
+ min-height: 0;
55
+ display: flex;
56
+ justify-content: center;
57
+ align-items: stretch;
58
+ }
59
+ .stage {
60
+ flex: 1;
61
+ min-width: 0;
62
+ min-height: 0;
63
+ position: relative;
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+ overflow: hidden;
68
+ touch-action: none;
69
+ user-select: none;
70
+ }
71
+ .stage[data-zoomed] {
72
+ cursor: grab;
73
+ }
74
+ .stage[data-zoomed]:active {
75
+ cursor: grabbing;
76
+ }
77
+ .image {
78
+ display: block;
79
+ width: auto;
80
+ height: auto;
81
+ max-width: 100%;
82
+ max-height: 100%;
83
+ object-fit: contain;
84
+ transform-origin: center;
85
+ border-radius: 2px;
86
+ flex-shrink: 0;
87
+ }
88
+ .previous,
89
+ .next {
90
+ position: absolute;
91
+ top: calc(50% - 20px);
92
+ z-index: 1;
93
+ border-radius: 50%;
94
+ background: color-mix(in srgb, var(--surface) 90%, transparent);
95
+ }
96
+ .previous {
97
+ left: 0;
98
+ }
99
+ .next {
100
+ right: 0;
101
+ }
102
+ .feedback {
103
+ position: absolute;
104
+ inset: 0;
105
+ display: flex;
106
+ gap: 12px;
107
+ align-items: center;
108
+ justify-content: center;
109
+ color: var(--muted);
110
+ font-size: 13px;
111
+ }
112
+ .caption {
113
+ justify-self: center;
114
+ max-width: min(760px, 90vw);
115
+ max-height: 15dvh;
116
+ overflow: auto;
117
+ font-size: 13px;
118
+ line-height: 1.6;
119
+ text-align: center;
120
+ overflow-wrap: anywhere;
121
+ }
122
+ .thumbnails {
123
+ position: relative;
124
+ display: flex;
125
+ gap: 8px;
126
+ max-width: 100%;
127
+ margin-inline: auto;
128
+ overflow-x: auto;
129
+ padding: 4px;
130
+ }
131
+ .thumbnails button {
132
+ flex: 0 0 56px;
133
+ width: 56px;
134
+ height: 44px;
135
+ padding: 2px;
136
+ border: 1px solid transparent;
137
+ border-radius: var(--radius);
138
+ background: transparent;
139
+ cursor: pointer;
140
+ opacity: 0.55;
141
+ transition:
142
+ opacity var(--motion-hover),
143
+ transform var(--motion-press),
144
+ background var(--motion-hover);
145
+ }
146
+ .thumbnails button:hover,
147
+ .thumbnails button[aria-current="true"] {
148
+ opacity: 1;
149
+ }
150
+ .thumbnailIndicator {
151
+ position: absolute;
152
+ left: 0;
153
+ top: 0;
154
+ pointer-events: none;
155
+ border: 1px solid var(--fg);
156
+ border-radius: var(--radius);
157
+ transition:
158
+ transform var(--motion-segment) var(--ease),
159
+ width var(--motion-segment) var(--ease);
160
+ }
161
+ .thumbnails button:focus-visible {
162
+ outline: none;
163
+ box-shadow:
164
+ 0 0 0 2px #111,
165
+ 0 0 0 3px var(--fg);
166
+ }
167
+ .thumbnails button:focus:not(:focus-visible) {
168
+ outline: none;
169
+ }
170
+ .thumbnails button:active {
171
+ transform: scale(0.96);
172
+ }
173
+ .thumbnails img {
174
+ width: 100%;
175
+ height: 100%;
176
+ object-fit: cover;
177
+ border-radius: calc(var(--radius) - 3px);
178
+ display: block;
179
+ }
180
+ .srOnly {
181
+ position: absolute;
182
+ width: 1px;
183
+ height: 1px;
184
+ padding: 0;
185
+ margin: -1px;
186
+ overflow: hidden;
187
+ clip-path: inset(50%);
188
+ white-space: nowrap;
189
+ }
190
+ @media (min-width: 800px) {
191
+ .stage {
192
+ margin-inline: 48px;
193
+ }
194
+ }
195
+ @media (prefers-reduced-motion: reduce) {
196
+ .thumbnails button {
197
+ transition: none;
198
+ }
199
+ }
38
200
 
39
- .actions button, .canvas > button { width: 40px; height: 40px; }
40
- @media (pointer: coarse) { .actions button, .canvas > button { width: 44px; height: 44px; } }
201
+ .actions button,
202
+ .canvas > button {
203
+ width: 40px;
204
+ height: 40px;
205
+ }
206
+ @media (pointer: coarse) {
207
+ .actions button,
208
+ .canvas > button {
209
+ width: 44px;
210
+ height: 44px;
211
+ }
212
+ }
213
+
214
+ .outgoing {
215
+ position: absolute;
216
+ inset: 0;
217
+ margin: auto;
218
+ pointer-events: none;
219
+ }
220
+ @media (prefers-reduced-motion: reduce) {
221
+ .thumbnailIndicator {
222
+ transition: none;
223
+ }
224
+ }
@@ -1 +1,2 @@
1
+ /** Preserve the document's layout width while native modals hide its scrollbar. */
1
2
  export declare function useModalScrollLock(active: boolean): void;
@@ -1,16 +1,58 @@
1
1
  "use client";
2
- import { useEffect } from "react";
2
+ import { useLayoutEffect } from "react";
3
3
  let locks = 0;
4
- let previous = "";
4
+ let previous;
5
5
  function useModalScrollLock(active) {
6
- useEffect(() => {
6
+ useLayoutEffect(() => {
7
7
  if (!active) return;
8
+ const root = document.documentElement, body = document.body;
8
9
  if (locks++ === 0) {
9
- previous = document.body.style.overflow;
10
- document.body.style.overflow = "hidden";
10
+ const gap = root.clientWidth > 0 ? Math.max(0, innerWidth - root.clientWidth) : 0;
11
+ const stable = (getComputedStyle(root).scrollbarGutter || "").includes("stable");
12
+ const changedGutter = gap > 0 && !stable && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("scrollbar-gutter", "stable");
13
+ const changedPadding = gap > 0 && !stable && !changedGutter;
14
+ previous = {
15
+ overflow: body.style.getPropertyValue("overflow"),
16
+ overflowPriority: body.style.getPropertyPriority("overflow"),
17
+ gutter: root.style.getPropertyValue("scrollbar-gutter"),
18
+ gutterPriority: root.style.getPropertyPriority("scrollbar-gutter"),
19
+ padding: body.style.getPropertyValue("padding-inline-end"),
20
+ paddingPriority: body.style.getPropertyPriority("padding-inline-end"),
21
+ changedGutter,
22
+ changedPadding
23
+ };
24
+ if (changedGutter) root.style.setProperty("scrollbar-gutter", "stable");
25
+ if (changedPadding)
26
+ body.style.setProperty(
27
+ "padding-inline-end",
28
+ `${(parseFloat(getComputedStyle(body).paddingInlineEnd) || 0) + gap}px`
29
+ );
30
+ body.style.setProperty("overflow", "hidden");
11
31
  }
12
32
  return () => {
13
- if (--locks === 0) document.body.style.overflow = previous;
33
+ if (--locks !== 0 || !previous) return;
34
+ const restore = (style, name, value, priority) => value ? style.setProperty(name, value, priority) : style.removeProperty(name);
35
+ restore(
36
+ body.style,
37
+ "overflow",
38
+ previous.overflow,
39
+ previous.overflowPriority
40
+ );
41
+ if (previous.changedGutter)
42
+ restore(
43
+ root.style,
44
+ "scrollbar-gutter",
45
+ previous.gutter,
46
+ previous.gutterPriority
47
+ );
48
+ if (previous.changedPadding)
49
+ restore(
50
+ body.style,
51
+ "padding-inline-end",
52
+ previous.padding,
53
+ previous.paddingPriority
54
+ );
55
+ previous = void 0;
14
56
  };
15
57
  }, [active]);
16
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.31",
3
+ "version": "0.6.33",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [