@reuse-sh/lightbox 0.3.0 → 0.3.1

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.
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.0 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.3.1 | MIT License */
2
2
  function e(e,t,n){let r=t;return e.addEventListener(`play`,()=>r=!1,{signal:n}),{interactive:!0,ready:new Promise(t=>{e.addEventListener(`loadedmetadata`,t,{once:!0,signal:n}),e.addEventListener(`error`,t,{once:!0,signal:n})}),pause:()=>e.pause(),resume(){r&&(r=!1,e.play().catch(t=>{if(t.name===`NotAllowedError`)return e.muted=!0,e.play()}).catch(()=>{}))},unmount(){e.pause(),e.removeAttribute(`src`),e.load(),e.remove()}}}function t(){return{type:`video`,mount(t,{item:n,signal:r,autoplay:i}){let a=t.ownerDocument.createElement(`video`);return a.className=`re-lightbox-video`,a.controls=!0,a.playsInline=!0,a.preload=`metadata`,n.previewSrc&&(a.poster=n.previewSrc),a.src=n.src??``,n.alt&&a.setAttribute(`aria-label`,n.alt),t.append(a),e(a,i,r)}}}export{e as playerOf,t as video};
3
3
  //# sourceMappingURL=video.js.map
package/dist/carousel.js CHANGED
@@ -1,6 +1,14 @@
1
+ const carouselInternals = Symbol.for("@reuse-sh/carousel internals");
1
2
  export function connectCarousel(lightbox, carousel, { slideOf = (index) => index } = {}) {
3
+ const strip = carousel[carouselInternals];
2
4
  const hold = (isHeld) => carousel.hold("lightbox", isHeld);
3
- const follow = (event) => carousel.goTo(slideOf(event.index), "instant");
5
+ const follow = ({ index }) => {
6
+ const slide = slideOf(index);
7
+ const visible = strip?.willKeepVisible?.(slide) ??
8
+ carousel.getState().visible.includes(slide);
9
+ if (!visible)
10
+ carousel.goTo(slide, "instant");
11
+ };
4
12
  const stops = [
5
13
  lightbox.on("open", () => hold(true)),
6
14
  lightbox.on("settle", follow),
package/dist/index.js CHANGED
@@ -2099,27 +2099,29 @@ export function createLightbox(options = {}) {
2099
2099
  const thumb = s.thumbs[state.index];
2100
2100
  if (!ring || !strip)
2101
2101
  return;
2102
- ring.hidden = !thumb;
2103
- if (!thumb)
2102
+ if (!thumb) {
2103
+ ring.hidden = true;
2104
2104
  return;
2105
+ }
2105
2106
  const instant = !glide || !ring.style.width;
2106
- if (instant)
2107
- ring.style.transition = "none";
2108
2107
  const left = strip.offsetLeft + strip.clientLeft;
2109
2108
  const top = strip.offsetTop + strip.clientTop;
2110
- if (s.dialog.dataset.thumbnails === "side") {
2111
- ring.style.left = `${left + thumb.offsetLeft}px`;
2112
- ring.style.top = `${top + strip.clientHeight / 2}px`;
2113
- ring.style.bottom = "";
2114
- }
2115
- else {
2116
- const parent = ring.parentElement?.clientHeight ?? 0;
2117
- ring.style.left = `${left + strip.clientWidth / 2}px`;
2118
- ring.style.top = "";
2119
- ring.style.bottom = `${parent - top - thumb.offsetTop - thumb.offsetHeight}px`;
2120
- }
2121
- ring.style.width = `${thumb.offsetWidth}px`;
2122
- ring.style.height = `${thumb.offsetHeight}px`;
2109
+ const width = thumb.offsetWidth;
2110
+ const height = thumb.offsetHeight;
2111
+ const side = s.dialog.dataset.thumbnails === "side";
2112
+ const x = left + (side ? thumb.offsetLeft : strip.clientWidth / 2);
2113
+ const y = side ? `${top + strip.clientHeight / 2}px` : "";
2114
+ const bottom = side
2115
+ ? ""
2116
+ : `${(ring.parentElement?.clientHeight ?? 0) - top - thumb.offsetTop - height}px`;
2117
+ ring.hidden = false;
2118
+ if (instant)
2119
+ ring.style.transition = "none";
2120
+ ring.style.left = `${x}px`;
2121
+ ring.style.top = y;
2122
+ ring.style.bottom = bottom;
2123
+ ring.style.width = `${width}px`;
2124
+ ring.style.height = `${height}px`;
2123
2125
  if (!instant)
2124
2126
  return;
2125
2127
  void ring.offsetWidth;
@@ -2279,24 +2281,25 @@ export function createLightbox(options = {}) {
2279
2281
  target.focus(options);
2280
2282
  if (target.ownerDocument.activeElement !== target)
2281
2283
  continue;
2282
- if (quiet && matches(target, ":focus-visible"))
2284
+ if (quiet)
2283
2285
  quietFocus(target);
2284
2286
  return;
2285
2287
  }
2286
2288
  }
2287
- // Focus that still shows a ring after a pointer close, from an engine without focusVisible or
2288
- // the dialog's own focus restore, gets an attribute the theme hides the ring by.
2289
+ // Some browsers ignore focusVisible or show the ring again on a repeated Escape.
2289
2290
  function quietFocus(target) {
2291
+ if (target.hasAttribute("data-re-focus-quiet"))
2292
+ return;
2290
2293
  const stop = new AbortController();
2291
2294
  const clear = () => {
2292
2295
  target.removeAttribute("data-re-focus-quiet");
2293
2296
  stop.abort();
2294
2297
  };
2295
2298
  target.setAttribute("data-re-focus-quiet", "");
2296
- target.ownerDocument.defaultView?.addEventListener("keydown", clear, {
2297
- capture: true,
2298
- signal: stop.signal,
2299
- });
2299
+ target.addEventListener("keydown", (event) => {
2300
+ if (event.key !== "Escape")
2301
+ clear();
2302
+ }, { capture: true, signal: stop.signal });
2300
2303
  target.addEventListener("blur", clear, { signal: stop.signal });
2301
2304
  }
2302
2305
  function setZoom(scale, focus, notify) {
@@ -3723,6 +3726,9 @@ export function createLightbox(options = {}) {
3723
3726
  const previousFocus = isHTMLElement(doc.activeElement)
3724
3727
  ? doc.activeElement
3725
3728
  : null;
3729
+ const opener = doc.defaultView?.event;
3730
+ const keyboardAtOpen = opener?.type === "keydown" ||
3731
+ (previousFocus && matches(previousFocus, ":focus-visible"));
3726
3732
  (settings.container ?? doc.body).append(dialog);
3727
3733
  const restoreScroll = lockScroll(doc);
3728
3734
  try {
@@ -3939,9 +3945,15 @@ export function createLightbox(options = {}) {
3939
3945
  for (const [type, input] of [
3940
3946
  ["keydown", "keyboard"],
3941
3947
  ["pointerdown", "pointer"],
3948
+ ["wheel", "pointer"],
3942
3949
  ])
3943
- win?.addEventListener(type, () => {
3944
- s.input = input;
3950
+ win?.addEventListener(type, (event) => {
3951
+ if (type === "wheel" && state.isClosing)
3952
+ return;
3953
+ if (input === "keyboard" && event.key === "Escape")
3954
+ s.input ??= keyboardAtOpen ? "keyboard" : "pointer";
3955
+ else
3956
+ s.input = input;
3945
3957
  }, { signal: abort.signal, capture: true, passive: true });
3946
3958
  dialog.addEventListener("pointermove", (event) => {
3947
3959
  if (event.pointerType === "mouse" && event.buttons === 0)
@@ -3963,15 +3975,20 @@ export function createLightbox(options = {}) {
3963
3975
  chromeInput(s, { type: "focus" });
3964
3976
  }, { signal: abort.signal });
3965
3977
  const opening = closeButton ?? viewport;
3966
- // window.event is the click or tap that called open(); a key's click has detail 0.
3967
- const opener = win?.event;
3978
+ // Firefox gives keyboard-activated links a click detail of 1 and an empty pointerType.
3968
3979
  const pointerOpen = opener !== undefined &&
3969
3980
  (/^(pointer|touch|mouse)/.test(opener.type) ||
3970
- (opener.type === "click" && opener.detail > 0));
3971
- opening.focus(pointerOpen
3981
+ (opener.type === "click" &&
3982
+ ("pointerType" in opener
3983
+ ? Boolean(opener.pointerType)
3984
+ : opener.detail > 0)));
3985
+ if (pointerOpen)
3986
+ s.input = "pointer";
3987
+ const quietOpening = pointerOpen || (!opener && !keyboardAtOpen);
3988
+ opening.focus(quietOpening
3972
3989
  ? { preventScroll: true, focusVisible: false }
3973
3990
  : { preventScroll: true });
3974
- if (pointerOpen && matches(opening, ":focus-visible"))
3991
+ if (quietOpening && matches(opening, ":focus-visible"))
3975
3992
  quietFocus(opening);
3976
3993
  watchControls(s);
3977
3994
  readTiming(s);
@@ -4032,6 +4049,10 @@ export function createLightbox(options = {}) {
4032
4049
  dialog.popover = "manual";
4033
4050
  dialog.showPopover();
4034
4051
  s.releasedFocus = dialog.ownerDocument.activeElement;
4052
+ if (s.input === "pointer" &&
4053
+ s.previousFocus &&
4054
+ s.releasedFocus === s.previousFocus)
4055
+ quietFocus(s.previousFocus);
4035
4056
  }
4036
4057
  // closed waits for the history back, unless open() or destroy() comes first.
4037
4058
  function reportClosed(landing) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuse-sh/lightbox",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "An image lightbox on native scrolling, with thumbnail transitions, zoom, pan, and pinch.",
5
5
  "keywords": [
6
6
  "reuse",
@@ -80,8 +80,8 @@
80
80
  "@types/react": "19.3.0"
81
81
  },
82
82
  "dependencies": {
83
- "@reuse-sh/carousel": "0.2.2",
84
- "@reuse-sh/loaders": "0.0.4"
83
+ "@reuse-sh/carousel": "0.2.3",
84
+ "@reuse-sh/loaders": "0.0.5"
85
85
  },
86
86
  "publishConfig": {
87
87
  "access": "public"