@page-speed/lightbox 0.1.2 → 0.1.3

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.
@@ -7,4 +7,4 @@ import { LightboxProps } from "../types";
7
7
  * That keeps it easy to integrate into the Semantic Site Builder while
8
8
  * still providing strong defaults for keyboard and scroll handling.
9
9
  */
10
- export declare function Lightbox(props: LightboxProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function Lightbox(props: LightboxProps): import("react/jsx-runtime").JSX.Element | null;
@@ -9064,10 +9064,10 @@ var require_pdf = __commonJS({
9064
9064
  value: true
9065
9065
  });
9066
9066
  exports2.GlobalWorkerOptions = void 0;
9067
- const GlobalWorkerOptions2 = /* @__PURE__ */ Object.create(null);
9068
- exports2.GlobalWorkerOptions = GlobalWorkerOptions2;
9069
- GlobalWorkerOptions2.workerPort = null;
9070
- GlobalWorkerOptions2.workerSrc = "";
9067
+ const GlobalWorkerOptions = /* @__PURE__ */ Object.create(null);
9068
+ exports2.GlobalWorkerOptions = GlobalWorkerOptions;
9069
+ GlobalWorkerOptions.workerPort = null;
9070
+ GlobalWorkerOptions.workerSrc = "";
9071
9071
  }),
9072
9072
  /* 15 */
9073
9073
  /***/
@@ -18069,7 +18069,7 @@ var require_pdf = __commonJS({
18069
18069
  }
18070
18070
  });
18071
18071
 
18072
- // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18072
+ // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18073
18073
  var dist_exports = {};
18074
18074
  __export(dist_exports, {
18075
18075
  PDFCanvas: () => PDFCanvas,
@@ -18091,12 +18091,12 @@ __export(dist_exports, {
18091
18091
  useZoom: () => useZoom
18092
18092
  });
18093
18093
  import { useEffect as useEffect42 } from "react";
18094
- import { useState as useState5, useEffect as useEffect7 } from "react";
18094
+ import { useState as useState5, useEffect as useEffect7, useRef as useRef3 } from "react";
18095
18095
  import { useState as useState22, useCallback as useCallback4 } from "react";
18096
- import { useRef as useRef3, useState as useState32, useCallback as useCallback22 } from "react";
18096
+ import { useRef as useRef22, useState as useState32, useCallback as useCallback22 } from "react";
18097
18097
  import { useState as useState42, useCallback as useCallback32 } from "react";
18098
18098
  import { useState as useState52, useCallback as useCallback42 } from "react";
18099
- import { useEffect as useEffect22, useRef as useRef22, useState as useState6 } from "react";
18099
+ import { useEffect as useEffect22, useRef as useRef32, useState as useState6 } from "react";
18100
18100
  import { jsx as jsx4 } from "react/jsx-runtime";
18101
18101
  import { jsx as jsx22, jsxs } from "react/jsx-runtime";
18102
18102
  import { useEffect as useEffect32, useState as useState7 } from "react";
@@ -18107,12 +18107,19 @@ function usePDFDocument(url, onError) {
18107
18107
  const [loading, setLoading] = useState5(true);
18108
18108
  const [error, setError] = useState5(null);
18109
18109
  const [pdfDoc, setPdfDoc] = useState5(null);
18110
+ const pdfjsInitialized = useRef3(false);
18110
18111
  useEffect7(() => {
18111
18112
  if (!url) return;
18113
+ if (typeof window === "undefined") return;
18112
18114
  setLoading(true);
18113
18115
  setError(null);
18114
18116
  const loadPDF = async () => {
18115
18117
  try {
18118
+ const pdfjsLib = await Promise.resolve().then(() => __toESM(require_pdf()));
18119
+ if (!pdfjsInitialized.current) {
18120
+ pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18121
+ pdfjsInitialized.current = true;
18122
+ }
18116
18123
  const loadingTask = pdfjsLib.getDocument({
18117
18124
  url,
18118
18125
  withCredentials: true,
@@ -18177,7 +18184,7 @@ function usePageState({
18177
18184
  };
18178
18185
  }
18179
18186
  function usePageRenderer(pdfDoc) {
18180
- const cacheRef = useRef3(/* @__PURE__ */ new Map());
18187
+ const cacheRef = useRef22(/* @__PURE__ */ new Map());
18181
18188
  const [rendering, setRendering] = useState32(false);
18182
18189
  const [pageInfo, setPageInfo] = useState32(null);
18183
18190
  const renderPage = useCallback22(
@@ -18335,7 +18342,7 @@ function PDFCanvas({
18335
18342
  scale,
18336
18343
  onRender
18337
18344
  }) {
18338
- const containerRef = useRef22(null);
18345
+ const containerRef = useRef32(null);
18339
18346
  const [canvas, setCanvas] = useState6(null);
18340
18347
  useEffect22(() => {
18341
18348
  const render = async () => {
@@ -18676,13 +18683,10 @@ function createProgressiveFetchHandler(onProgress) {
18676
18683
  return response.arrayBuffer();
18677
18684
  };
18678
18685
  }
18679
- var pdfjsLib, DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18686
+ var DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18680
18687
  var init_dist = __esm({
18681
- "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18682
- pdfjsLib = __toESM(require_pdf());
18683
- if (typeof window !== "undefined") {
18684
- pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18685
- }
18688
+ "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18689
+ "use client";
18686
18690
  DEFAULT_SCALE = 1.5;
18687
18691
  CACHE_SIZE = 50 * 1024 * 1024;
18688
18692
  MIN_ZOOM = 0.5;
@@ -18720,8 +18724,10 @@ import {
18720
18724
  useCallback as useCallback5,
18721
18725
  useEffect as useEffect8,
18722
18726
  useMemo as useMemo3,
18723
- useRef as useRef4
18727
+ useRef as useRef4,
18728
+ useState as useState8
18724
18729
  } from "react";
18730
+ import { createPortal } from "react-dom";
18725
18731
 
18726
18732
  // src/hooks/useGalleryState.ts
18727
18733
  import { useState, useCallback } from "react";
@@ -19838,31 +19844,24 @@ function Lightbox(props) {
19838
19844
  return "horizontal";
19839
19845
  }, [props.layout, breakpoint]);
19840
19846
  const didCloseRef = useRef4(false);
19847
+ const [isMounted, setIsMounted] = useState8(false);
19848
+ useEffect8(() => {
19849
+ setIsMounted(true);
19850
+ }, []);
19841
19851
  useEffect8(() => {
19842
19852
  props.onOpen?.();
19843
19853
  if (props.disableScroll === false) {
19844
- return () => {
19845
- if (!didCloseRef.current) {
19846
- props.onClose?.();
19847
- }
19848
- };
19854
+ return;
19849
19855
  }
19850
19856
  if (typeof document === "undefined") {
19851
- return () => {
19852
- if (!didCloseRef.current) {
19853
- props.onClose?.();
19854
- }
19855
- };
19857
+ return;
19856
19858
  }
19857
19859
  const previousOverflow = document.body.style.overflow;
19858
19860
  document.body.style.overflow = "hidden";
19859
19861
  return () => {
19860
19862
  document.body.style.overflow = previousOverflow;
19861
- if (!didCloseRef.current) {
19862
- props.onClose?.();
19863
- }
19864
19863
  };
19865
- }, [props.disableScroll, props.onOpen, props.onClose]);
19864
+ }, [props.disableScroll, props.onOpen]);
19866
19865
  const handleClose = useCallback5(() => {
19867
19866
  if (didCloseRef.current) return;
19868
19867
  didCloseRef.current = true;
@@ -19948,7 +19947,7 @@ function Lightbox(props) {
19948
19947
  layoutComponent = /* @__PURE__ */ jsx14(HorizontalLayout, { ...layoutProps });
19949
19948
  break;
19950
19949
  }
19951
- return /* @__PURE__ */ jsxs10("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19950
+ const lightboxContent = /* @__PURE__ */ jsxs10("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19952
19951
  /* @__PURE__ */ jsx14(
19953
19952
  LightboxOverlay,
19954
19953
  {
@@ -19958,6 +19957,10 @@ function Lightbox(props) {
19958
19957
  ),
19959
19958
  layoutComponent
19960
19959
  ] });
19960
+ if (isMounted && typeof document !== "undefined") {
19961
+ return createPortal(lightboxContent, document.body);
19962
+ }
19963
+ return null;
19961
19964
  }
19962
19965
  export {
19963
19966
  CustomSlideLayout,
package/dist/index.cjs CHANGED
@@ -9060,10 +9060,10 @@ var require_pdf = __commonJS({
9060
9060
  value: true
9061
9061
  });
9062
9062
  exports2.GlobalWorkerOptions = void 0;
9063
- const GlobalWorkerOptions2 = /* @__PURE__ */ Object.create(null);
9064
- exports2.GlobalWorkerOptions = GlobalWorkerOptions2;
9065
- GlobalWorkerOptions2.workerPort = null;
9066
- GlobalWorkerOptions2.workerSrc = "";
9063
+ const GlobalWorkerOptions = /* @__PURE__ */ Object.create(null);
9064
+ exports2.GlobalWorkerOptions = GlobalWorkerOptions;
9065
+ GlobalWorkerOptions.workerPort = null;
9066
+ GlobalWorkerOptions.workerSrc = "";
9067
9067
  }),
9068
9068
  /* 15 */
9069
9069
  /***/
@@ -18065,7 +18065,7 @@ var require_pdf = __commonJS({
18065
18065
  }
18066
18066
  });
18067
18067
 
18068
- // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18068
+ // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18069
18069
  var dist_exports = {};
18070
18070
  __export(dist_exports, {
18071
18071
  PDFCanvas: () => PDFCanvas,
@@ -18091,12 +18091,19 @@ function usePDFDocument(url, onError) {
18091
18091
  const [loading, setLoading] = (0, import_react9.useState)(true);
18092
18092
  const [error, setError] = (0, import_react9.useState)(null);
18093
18093
  const [pdfDoc, setPdfDoc] = (0, import_react9.useState)(null);
18094
+ const pdfjsInitialized = (0, import_react9.useRef)(false);
18094
18095
  (0, import_react9.useEffect)(() => {
18095
18096
  if (!url) return;
18097
+ if (typeof window === "undefined") return;
18096
18098
  setLoading(true);
18097
18099
  setError(null);
18098
18100
  const loadPDF = async () => {
18099
18101
  try {
18102
+ const pdfjsLib = await Promise.resolve().then(() => __toESM(require_pdf()));
18103
+ if (!pdfjsInitialized.current) {
18104
+ pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18105
+ pdfjsInitialized.current = true;
18106
+ }
18100
18107
  const loadingTask = pdfjsLib.getDocument({
18101
18108
  url,
18102
18109
  withCredentials: true,
@@ -18660,12 +18667,12 @@ function createProgressiveFetchHandler(onProgress) {
18660
18667
  return response.arrayBuffer();
18661
18668
  };
18662
18669
  }
18663
- var import_react8, import_react9, pdfjsLib, import_react10, import_react11, import_react12, import_react13, import_react14, import_jsx_runtime5, import_jsx_runtime6, import_react15, import_jsx_runtime7, import_jsx_runtime8, DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18670
+ var import_react8, import_react9, import_react10, import_react11, import_react12, import_react13, import_react14, import_jsx_runtime5, import_jsx_runtime6, import_react15, import_jsx_runtime7, import_jsx_runtime8, DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18664
18671
  var init_dist = __esm({
18665
- "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18672
+ "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18673
+ "use client";
18666
18674
  import_react8 = require("react");
18667
18675
  import_react9 = require("react");
18668
- pdfjsLib = __toESM(require_pdf());
18669
18676
  import_react10 = require("react");
18670
18677
  import_react11 = require("react");
18671
18678
  import_react12 = require("react");
@@ -18676,9 +18683,6 @@ var init_dist = __esm({
18676
18683
  import_react15 = require("react");
18677
18684
  import_jsx_runtime7 = require("react/jsx-runtime");
18678
18685
  import_jsx_runtime8 = require("react/jsx-runtime");
18679
- if (typeof window !== "undefined") {
18680
- pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18681
- }
18682
18686
  DEFAULT_SCALE = 1.5;
18683
18687
  CACHE_SIZE = 50 * 1024 * 1024;
18684
18688
  MIN_ZOOM = 0.5;
@@ -18737,6 +18741,7 @@ module.exports = __toCommonJS(index_exports);
18737
18741
 
18738
18742
  // src/components/Lightbox.tsx
18739
18743
  var import_react17 = require("react");
18744
+ var import_react_dom = require("react-dom");
18740
18745
 
18741
18746
  // src/hooks/useGalleryState.ts
18742
18747
  var import_react = require("react");
@@ -19853,31 +19858,24 @@ function Lightbox(props) {
19853
19858
  return "horizontal";
19854
19859
  }, [props.layout, breakpoint]);
19855
19860
  const didCloseRef = (0, import_react17.useRef)(false);
19861
+ const [isMounted, setIsMounted] = (0, import_react17.useState)(false);
19862
+ (0, import_react17.useEffect)(() => {
19863
+ setIsMounted(true);
19864
+ }, []);
19856
19865
  (0, import_react17.useEffect)(() => {
19857
19866
  props.onOpen?.();
19858
19867
  if (props.disableScroll === false) {
19859
- return () => {
19860
- if (!didCloseRef.current) {
19861
- props.onClose?.();
19862
- }
19863
- };
19868
+ return;
19864
19869
  }
19865
19870
  if (typeof document === "undefined") {
19866
- return () => {
19867
- if (!didCloseRef.current) {
19868
- props.onClose?.();
19869
- }
19870
- };
19871
+ return;
19871
19872
  }
19872
19873
  const previousOverflow = document.body.style.overflow;
19873
19874
  document.body.style.overflow = "hidden";
19874
19875
  return () => {
19875
19876
  document.body.style.overflow = previousOverflow;
19876
- if (!didCloseRef.current) {
19877
- props.onClose?.();
19878
- }
19879
19877
  };
19880
- }, [props.disableScroll, props.onOpen, props.onClose]);
19878
+ }, [props.disableScroll, props.onOpen]);
19881
19879
  const handleClose = (0, import_react17.useCallback)(() => {
19882
19880
  if (didCloseRef.current) return;
19883
19881
  didCloseRef.current = true;
@@ -19963,7 +19961,7 @@ function Lightbox(props) {
19963
19961
  layoutComponent = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(HorizontalLayout, { ...layoutProps });
19964
19962
  break;
19965
19963
  }
19966
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19964
+ const lightboxContent = /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19967
19965
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
19968
19966
  LightboxOverlay,
19969
19967
  {
@@ -19973,6 +19971,10 @@ function Lightbox(props) {
19973
19971
  ),
19974
19972
  layoutComponent
19975
19973
  ] });
19974
+ if (isMounted && typeof document !== "undefined") {
19975
+ return (0, import_react_dom.createPortal)(lightboxContent, document.body);
19976
+ }
19977
+ return null;
19976
19978
  }
19977
19979
 
19978
19980
  // src/hooks/useLightboxState.ts
package/dist/index.js CHANGED
@@ -9064,10 +9064,10 @@ var require_pdf = __commonJS({
9064
9064
  value: true
9065
9065
  });
9066
9066
  exports2.GlobalWorkerOptions = void 0;
9067
- const GlobalWorkerOptions2 = /* @__PURE__ */ Object.create(null);
9068
- exports2.GlobalWorkerOptions = GlobalWorkerOptions2;
9069
- GlobalWorkerOptions2.workerPort = null;
9070
- GlobalWorkerOptions2.workerSrc = "";
9067
+ const GlobalWorkerOptions = /* @__PURE__ */ Object.create(null);
9068
+ exports2.GlobalWorkerOptions = GlobalWorkerOptions;
9069
+ GlobalWorkerOptions.workerPort = null;
9070
+ GlobalWorkerOptions.workerSrc = "";
9071
9071
  }),
9072
9072
  /* 15 */
9073
9073
  /***/
@@ -18069,7 +18069,7 @@ var require_pdf = __commonJS({
18069
18069
  }
18070
18070
  });
18071
18071
 
18072
- // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18072
+ // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18073
18073
  var dist_exports = {};
18074
18074
  __export(dist_exports, {
18075
18075
  PDFCanvas: () => PDFCanvas,
@@ -18091,12 +18091,12 @@ __export(dist_exports, {
18091
18091
  useZoom: () => useZoom
18092
18092
  });
18093
18093
  import { useEffect as useEffect42 } from "react";
18094
- import { useState as useState5, useEffect as useEffect7 } from "react";
18094
+ import { useState as useState5, useEffect as useEffect7, useRef as useRef3 } from "react";
18095
18095
  import { useState as useState22, useCallback as useCallback4 } from "react";
18096
- import { useRef as useRef3, useState as useState32, useCallback as useCallback22 } from "react";
18096
+ import { useRef as useRef22, useState as useState32, useCallback as useCallback22 } from "react";
18097
18097
  import { useState as useState42, useCallback as useCallback32 } from "react";
18098
18098
  import { useState as useState52, useCallback as useCallback42 } from "react";
18099
- import { useEffect as useEffect22, useRef as useRef22, useState as useState6 } from "react";
18099
+ import { useEffect as useEffect22, useRef as useRef32, useState as useState6 } from "react";
18100
18100
  import { jsx as jsx4 } from "react/jsx-runtime";
18101
18101
  import { jsx as jsx22, jsxs } from "react/jsx-runtime";
18102
18102
  import { useEffect as useEffect32, useState as useState7 } from "react";
@@ -18107,12 +18107,19 @@ function usePDFDocument(url, onError) {
18107
18107
  const [loading, setLoading] = useState5(true);
18108
18108
  const [error, setError] = useState5(null);
18109
18109
  const [pdfDoc, setPdfDoc] = useState5(null);
18110
+ const pdfjsInitialized = useRef3(false);
18110
18111
  useEffect7(() => {
18111
18112
  if (!url) return;
18113
+ if (typeof window === "undefined") return;
18112
18114
  setLoading(true);
18113
18115
  setError(null);
18114
18116
  const loadPDF = async () => {
18115
18117
  try {
18118
+ const pdfjsLib = await Promise.resolve().then(() => __toESM(require_pdf()));
18119
+ if (!pdfjsInitialized.current) {
18120
+ pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18121
+ pdfjsInitialized.current = true;
18122
+ }
18116
18123
  const loadingTask = pdfjsLib.getDocument({
18117
18124
  url,
18118
18125
  withCredentials: true,
@@ -18177,7 +18184,7 @@ function usePageState({
18177
18184
  };
18178
18185
  }
18179
18186
  function usePageRenderer(pdfDoc) {
18180
- const cacheRef = useRef3(/* @__PURE__ */ new Map());
18187
+ const cacheRef = useRef22(/* @__PURE__ */ new Map());
18181
18188
  const [rendering, setRendering] = useState32(false);
18182
18189
  const [pageInfo, setPageInfo] = useState32(null);
18183
18190
  const renderPage = useCallback22(
@@ -18335,7 +18342,7 @@ function PDFCanvas({
18335
18342
  scale,
18336
18343
  onRender
18337
18344
  }) {
18338
- const containerRef = useRef22(null);
18345
+ const containerRef = useRef32(null);
18339
18346
  const [canvas, setCanvas] = useState6(null);
18340
18347
  useEffect22(() => {
18341
18348
  const render = async () => {
@@ -18676,13 +18683,10 @@ function createProgressiveFetchHandler(onProgress) {
18676
18683
  return response.arrayBuffer();
18677
18684
  };
18678
18685
  }
18679
- var pdfjsLib, DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18686
+ var DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18680
18687
  var init_dist = __esm({
18681
- "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18682
- pdfjsLib = __toESM(require_pdf());
18683
- if (typeof window !== "undefined") {
18684
- pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18685
- }
18688
+ "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18689
+ "use client";
18686
18690
  DEFAULT_SCALE = 1.5;
18687
18691
  CACHE_SIZE = 50 * 1024 * 1024;
18688
18692
  MIN_ZOOM = 0.5;
@@ -18720,8 +18724,10 @@ import {
18720
18724
  useCallback as useCallback5,
18721
18725
  useEffect as useEffect8,
18722
18726
  useMemo as useMemo3,
18723
- useRef as useRef4
18727
+ useRef as useRef4,
18728
+ useState as useState8
18724
18729
  } from "react";
18730
+ import { createPortal } from "react-dom";
18725
18731
 
18726
18732
  // src/hooks/useGalleryState.ts
18727
18733
  import { useState, useCallback } from "react";
@@ -19838,31 +19844,24 @@ function Lightbox(props) {
19838
19844
  return "horizontal";
19839
19845
  }, [props.layout, breakpoint]);
19840
19846
  const didCloseRef = useRef4(false);
19847
+ const [isMounted, setIsMounted] = useState8(false);
19848
+ useEffect8(() => {
19849
+ setIsMounted(true);
19850
+ }, []);
19841
19851
  useEffect8(() => {
19842
19852
  props.onOpen?.();
19843
19853
  if (props.disableScroll === false) {
19844
- return () => {
19845
- if (!didCloseRef.current) {
19846
- props.onClose?.();
19847
- }
19848
- };
19854
+ return;
19849
19855
  }
19850
19856
  if (typeof document === "undefined") {
19851
- return () => {
19852
- if (!didCloseRef.current) {
19853
- props.onClose?.();
19854
- }
19855
- };
19857
+ return;
19856
19858
  }
19857
19859
  const previousOverflow = document.body.style.overflow;
19858
19860
  document.body.style.overflow = "hidden";
19859
19861
  return () => {
19860
19862
  document.body.style.overflow = previousOverflow;
19861
- if (!didCloseRef.current) {
19862
- props.onClose?.();
19863
- }
19864
19863
  };
19865
- }, [props.disableScroll, props.onOpen, props.onClose]);
19864
+ }, [props.disableScroll, props.onOpen]);
19866
19865
  const handleClose = useCallback5(() => {
19867
19866
  if (didCloseRef.current) return;
19868
19867
  didCloseRef.current = true;
@@ -19948,7 +19947,7 @@ function Lightbox(props) {
19948
19947
  layoutComponent = /* @__PURE__ */ jsx14(HorizontalLayout, { ...layoutProps });
19949
19948
  break;
19950
19949
  }
19951
- return /* @__PURE__ */ jsxs10("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19950
+ const lightboxContent = /* @__PURE__ */ jsxs10("div", { className: Lightbox_default.lightboxPortal, role: "dialog", "aria-modal": "true", children: [
19952
19951
  /* @__PURE__ */ jsx14(
19953
19952
  LightboxOverlay,
19954
19953
  {
@@ -19958,16 +19957,20 @@ function Lightbox(props) {
19958
19957
  ),
19959
19958
  layoutComponent
19960
19959
  ] });
19960
+ if (isMounted && typeof document !== "undefined") {
19961
+ return createPortal(lightboxContent, document.body);
19962
+ }
19963
+ return null;
19961
19964
  }
19962
19965
 
19963
19966
  // src/hooks/useLightboxState.ts
19964
- import { useState as useState8, useCallback as useCallback6, useEffect as useEffect9 } from "react";
19967
+ import { useState as useState9, useCallback as useCallback6, useEffect as useEffect9 } from "react";
19965
19968
  function useLightboxState({
19966
19969
  onOpen,
19967
19970
  onClose,
19968
19971
  disableScroll = true
19969
19972
  }) {
19970
- const [isOpen, setIsOpen] = useState8(false);
19973
+ const [isOpen, setIsOpen] = useState9(false);
19971
19974
  const open = useCallback6(() => {
19972
19975
  setIsOpen(true);
19973
19976
  onOpen?.();
@@ -9064,10 +9064,10 @@ var require_pdf = __commonJS({
9064
9064
  value: true
9065
9065
  });
9066
9066
  exports2.GlobalWorkerOptions = void 0;
9067
- const GlobalWorkerOptions2 = /* @__PURE__ */ Object.create(null);
9068
- exports2.GlobalWorkerOptions = GlobalWorkerOptions2;
9069
- GlobalWorkerOptions2.workerPort = null;
9070
- GlobalWorkerOptions2.workerSrc = "";
9067
+ const GlobalWorkerOptions = /* @__PURE__ */ Object.create(null);
9068
+ exports2.GlobalWorkerOptions = GlobalWorkerOptions;
9069
+ GlobalWorkerOptions.workerPort = null;
9070
+ GlobalWorkerOptions.workerSrc = "";
9071
9071
  }),
9072
9072
  /* 15 */
9073
9073
  /***/
@@ -18069,7 +18069,7 @@ var require_pdf = __commonJS({
18069
18069
  }
18070
18070
  });
18071
18071
 
18072
- // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18072
+ // node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js
18073
18073
  var dist_exports = {};
18074
18074
  __export(dist_exports, {
18075
18075
  PDFCanvas: () => PDFCanvas,
@@ -18091,12 +18091,12 @@ __export(dist_exports, {
18091
18091
  useZoom: () => useZoom
18092
18092
  });
18093
18093
  import { useEffect as useEffect42 } from "react";
18094
- import { useState as useState3, useEffect as useEffect5 } from "react";
18094
+ import { useState as useState3, useEffect as useEffect5, useRef as useRef3 } from "react";
18095
18095
  import { useState as useState22, useCallback as useCallback3 } from "react";
18096
- import { useRef as useRef3, useState as useState32, useCallback as useCallback22 } from "react";
18096
+ import { useRef as useRef22, useState as useState32, useCallback as useCallback22 } from "react";
18097
18097
  import { useState as useState4, useCallback as useCallback32 } from "react";
18098
18098
  import { useState as useState5, useCallback as useCallback4 } from "react";
18099
- import { useEffect as useEffect22, useRef as useRef22, useState as useState6 } from "react";
18099
+ import { useEffect as useEffect22, useRef as useRef32, useState as useState6 } from "react";
18100
18100
  import { jsx as jsx3 } from "react/jsx-runtime";
18101
18101
  import { jsx as jsx22, jsxs } from "react/jsx-runtime";
18102
18102
  import { useEffect as useEffect32, useState as useState7 } from "react";
@@ -18107,12 +18107,19 @@ function usePDFDocument(url, onError) {
18107
18107
  const [loading, setLoading] = useState3(true);
18108
18108
  const [error, setError] = useState3(null);
18109
18109
  const [pdfDoc, setPdfDoc] = useState3(null);
18110
+ const pdfjsInitialized = useRef3(false);
18110
18111
  useEffect5(() => {
18111
18112
  if (!url) return;
18113
+ if (typeof window === "undefined") return;
18112
18114
  setLoading(true);
18113
18115
  setError(null);
18114
18116
  const loadPDF = async () => {
18115
18117
  try {
18118
+ const pdfjsLib = await Promise.resolve().then(() => __toESM(require_pdf()));
18119
+ if (!pdfjsInitialized.current) {
18120
+ pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18121
+ pdfjsInitialized.current = true;
18122
+ }
18116
18123
  const loadingTask = pdfjsLib.getDocument({
18117
18124
  url,
18118
18125
  withCredentials: true,
@@ -18177,7 +18184,7 @@ function usePageState({
18177
18184
  };
18178
18185
  }
18179
18186
  function usePageRenderer(pdfDoc) {
18180
- const cacheRef = useRef3(/* @__PURE__ */ new Map());
18187
+ const cacheRef = useRef22(/* @__PURE__ */ new Map());
18181
18188
  const [rendering, setRendering] = useState32(false);
18182
18189
  const [pageInfo, setPageInfo] = useState32(null);
18183
18190
  const renderPage = useCallback22(
@@ -18335,7 +18342,7 @@ function PDFCanvas({
18335
18342
  scale,
18336
18343
  onRender
18337
18344
  }) {
18338
- const containerRef = useRef22(null);
18345
+ const containerRef = useRef32(null);
18339
18346
  const [canvas, setCanvas] = useState6(null);
18340
18347
  useEffect22(() => {
18341
18348
  const render = async () => {
@@ -18676,13 +18683,10 @@ function createProgressiveFetchHandler(onProgress) {
18676
18683
  return response.arrayBuffer();
18677
18684
  };
18678
18685
  }
18679
- var pdfjsLib, DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18686
+ var DEFAULT_SCALE, CACHE_SIZE, MIN_ZOOM, MAX_ZOOM, ZOOM_STEP, PDFViewer_default, linearizedPDFConfig;
18680
18687
  var init_dist = __esm({
18681
- "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18682
- pdfjsLib = __toESM(require_pdf());
18683
- if (typeof window !== "undefined") {
18684
- pdfjsLib.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
18685
- }
18688
+ "node_modules/.pnpm/@page-speed+pdf-viewer@0.1.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@page-speed/pdf-viewer/dist/index.js"() {
18689
+ "use client";
18686
18690
  DEFAULT_SCALE = 1.5;
18687
18691
  CACHE_SIZE = 50 * 1024 * 1024;
18688
18692
  MIN_ZOOM = 0.5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@page-speed/lightbox",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "High-performance, feature-rich lightbox for OpenSite platform",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -80,6 +80,6 @@
80
80
  },
81
81
  "dependencies": {
82
82
  "@page-speed/img": "^0.4.3",
83
- "@page-speed/pdf-viewer": "0.1.0"
83
+ "@page-speed/pdf-viewer": "0.1.1"
84
84
  }
85
85
  }