@nypl/web-reader 5.0.0-alpha.0 → 5.0.0
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/README.md +12 -0
- package/dist/index.js +143 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -159
- package/dist/index.mjs.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-after.css.map +1 -1
- package/dist/injectable-html-styles/ReadiumCSS-before.css.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -3506,10 +3506,7 @@ function createMultiStyleConfigHelpers(parts) {
|
|
|
3506
3506
|
}
|
|
3507
3507
|
|
|
3508
3508
|
// src/ui/theme/components/tabs.ts
|
|
3509
|
-
var {
|
|
3510
|
-
defineMultiStyleConfig,
|
|
3511
|
-
definePartsStyle
|
|
3512
|
-
} = createMultiStyleConfigHelpers(["root", "tab", "tablist"]);
|
|
3509
|
+
var { defineMultiStyleConfig, definePartsStyle } = createMultiStyleConfigHelpers(["root", "tab", "tablist"]);
|
|
3513
3510
|
var getTabsStyle = (getColor2) => defineMultiStyleConfig({
|
|
3514
3511
|
variants: {
|
|
3515
3512
|
custom: definePartsStyle({
|
|
@@ -6141,14 +6138,7 @@ function Header(props) {
|
|
|
6141
6138
|
var _a, _b, _c, _d;
|
|
6142
6139
|
const [, toggleFullscreenHook] = useFullscreen();
|
|
6143
6140
|
const [isFullscreen, setIsFullScreen] = useState10(false);
|
|
6144
|
-
const {
|
|
6145
|
-
navigator,
|
|
6146
|
-
manifest,
|
|
6147
|
-
type,
|
|
6148
|
-
containerRef,
|
|
6149
|
-
currentPage,
|
|
6150
|
-
totalPages
|
|
6151
|
-
} = props;
|
|
6141
|
+
const { navigator, manifest, type, containerRef, currentPage, totalPages } = props;
|
|
6152
6142
|
const isAtStart = (_a = props.state) == null ? void 0 : _a.atStart;
|
|
6153
6143
|
const isAtEnd = (_b = props.state) == null ? void 0 : _b.atEnd;
|
|
6154
6144
|
const iconFill = useColorModeValue_default(
|
|
@@ -6774,12 +6764,8 @@ function setReflowableCss(iframeHtml, settings) {
|
|
|
6774
6764
|
}
|
|
6775
6765
|
function setFixedCss(iframeDocument, iframeContainer) {
|
|
6776
6766
|
if (!iframeContainer) return;
|
|
6777
|
-
let { contentWidth, contentHeight } = extractContentViewportSize(
|
|
6778
|
-
|
|
6779
|
-
);
|
|
6780
|
-
const { containerWidth, containerHeight } = extractContentContainerSize(
|
|
6781
|
-
iframeContainer
|
|
6782
|
-
);
|
|
6767
|
+
let { contentWidth, contentHeight } = extractContentViewportSize(iframeDocument);
|
|
6768
|
+
const { containerWidth, containerHeight } = extractContentContainerSize(iframeContainer);
|
|
6783
6769
|
contentWidth = contentWidth != null ? contentWidth : containerWidth;
|
|
6784
6770
|
contentHeight = contentHeight != null ? contentHeight : containerHeight;
|
|
6785
6771
|
const scale = Math.min(
|
|
@@ -7346,9 +7332,7 @@ function useResource(manifest, state2, getContent, injectables, dispatch) {
|
|
|
7346
7332
|
if (element) document2 == null ? void 0 : document2.head.appendChild(element);
|
|
7347
7333
|
}
|
|
7348
7334
|
injectJS(document2.body);
|
|
7349
|
-
const iframeContainer = window.document.querySelector(
|
|
7350
|
-
'main [role="progressbar"]'
|
|
7351
|
-
);
|
|
7335
|
+
const iframeContainer = window.document.querySelector('main [role="progressbar"]');
|
|
7352
7336
|
const readerSettings = {
|
|
7353
7337
|
colorMode: state2.settings.colorMode,
|
|
7354
7338
|
fontSize: state2.settings.fontSize,
|
|
@@ -7713,129 +7697,6 @@ var ChakraPage = chakra3(
|
|
|
7713
7697
|
);
|
|
7714
7698
|
var ChakraPage_default = ChakraPage;
|
|
7715
7699
|
|
|
7716
|
-
// src/PdfReader/ScrollPage.tsx
|
|
7717
|
-
import React48 from "react";
|
|
7718
|
-
import { useInView } from "react-intersection-observer";
|
|
7719
|
-
var Placeholder = ({ width, height, pageNumber }) => {
|
|
7720
|
-
return /* @__PURE__ */ React48.createElement(
|
|
7721
|
-
"div",
|
|
7722
|
-
{
|
|
7723
|
-
"data-page-number": pageNumber,
|
|
7724
|
-
style: { width, height }
|
|
7725
|
-
}
|
|
7726
|
-
);
|
|
7727
|
-
};
|
|
7728
|
-
var ScrollPage = ({
|
|
7729
|
-
scale,
|
|
7730
|
-
pageNumber,
|
|
7731
|
-
width,
|
|
7732
|
-
height,
|
|
7733
|
-
onLoadSuccess,
|
|
7734
|
-
placeholderHeight,
|
|
7735
|
-
placeholderWidth,
|
|
7736
|
-
allowInView,
|
|
7737
|
-
onInView,
|
|
7738
|
-
fitMode,
|
|
7739
|
-
rotate
|
|
7740
|
-
}) => {
|
|
7741
|
-
const { ref: loadRef, inView: loadInView } = useInView({
|
|
7742
|
-
threshold: 0,
|
|
7743
|
-
triggerOnce: true
|
|
7744
|
-
});
|
|
7745
|
-
const { ref: visibilityRef, entry } = useInView({
|
|
7746
|
-
threshold: Array.from({ length: 11 }, (_, i) => i * 0.1),
|
|
7747
|
-
triggerOnce: false
|
|
7748
|
-
});
|
|
7749
|
-
const setRefs = React48.useCallback(
|
|
7750
|
-
(el) => {
|
|
7751
|
-
if (typeof loadRef === "function") loadRef(el);
|
|
7752
|
-
if (typeof visibilityRef === "function") visibilityRef(el);
|
|
7753
|
-
},
|
|
7754
|
-
[loadRef, visibilityRef]
|
|
7755
|
-
);
|
|
7756
|
-
const handleLoadSuccess = React48.useCallback(
|
|
7757
|
-
(page) => {
|
|
7758
|
-
onLoadSuccess(page);
|
|
7759
|
-
},
|
|
7760
|
-
[onLoadSuccess]
|
|
7761
|
-
);
|
|
7762
|
-
React48.useEffect(() => {
|
|
7763
|
-
if (onInView && entry) {
|
|
7764
|
-
onInView(pageNumber, entry.intersectionRatio || 0);
|
|
7765
|
-
}
|
|
7766
|
-
}, [entry, onInView, pageNumber]);
|
|
7767
|
-
return /* @__PURE__ */ React48.createElement("div", { ref: setRefs }, loadInView ? /* @__PURE__ */ React48.createElement(
|
|
7768
|
-
ChakraPage_default,
|
|
7769
|
-
{
|
|
7770
|
-
"data-page-number": pageNumber,
|
|
7771
|
-
pageNumber,
|
|
7772
|
-
scale,
|
|
7773
|
-
width,
|
|
7774
|
-
height,
|
|
7775
|
-
onLoadSuccess: handleLoadSuccess,
|
|
7776
|
-
fitMode,
|
|
7777
|
-
rotate
|
|
7778
|
-
}
|
|
7779
|
-
) : /* @__PURE__ */ React48.createElement(
|
|
7780
|
-
Placeholder,
|
|
7781
|
-
{
|
|
7782
|
-
width: placeholderWidth,
|
|
7783
|
-
height: placeholderHeight,
|
|
7784
|
-
pageNumber
|
|
7785
|
-
}
|
|
7786
|
-
));
|
|
7787
|
-
};
|
|
7788
|
-
var ScrollPage_default = ScrollPage;
|
|
7789
|
-
|
|
7790
|
-
// src/PdfReader/useMeasure.tsx
|
|
7791
|
-
import * as React49 from "react";
|
|
7792
|
-
var DEFAULT_DIMENSION = {
|
|
7793
|
-
x: 0,
|
|
7794
|
-
y: 0,
|
|
7795
|
-
width: 0,
|
|
7796
|
-
height: 0,
|
|
7797
|
-
top: 0,
|
|
7798
|
-
left: 0,
|
|
7799
|
-
bottom: 0,
|
|
7800
|
-
right: 0
|
|
7801
|
-
};
|
|
7802
|
-
function useMeasure() {
|
|
7803
|
-
const [element, ref] = React49.useState(null);
|
|
7804
|
-
const [rect, setRect] = React49.useState(DEFAULT_DIMENSION);
|
|
7805
|
-
const observer = React49.useMemo(
|
|
7806
|
-
() => new window.ResizeObserver(
|
|
7807
|
-
(entries) => {
|
|
7808
|
-
if (entries[0]) {
|
|
7809
|
-
const {
|
|
7810
|
-
x,
|
|
7811
|
-
y,
|
|
7812
|
-
width,
|
|
7813
|
-
height,
|
|
7814
|
-
top,
|
|
7815
|
-
left,
|
|
7816
|
-
bottom,
|
|
7817
|
-
right
|
|
7818
|
-
} = entries[0].contentRect;
|
|
7819
|
-
setRect({ x, y, width, height, top, left, bottom, right });
|
|
7820
|
-
}
|
|
7821
|
-
}
|
|
7822
|
-
),
|
|
7823
|
-
[]
|
|
7824
|
-
);
|
|
7825
|
-
React49.useLayoutEffect(() => {
|
|
7826
|
-
if (!element) return;
|
|
7827
|
-
observer.observe(element);
|
|
7828
|
-
return () => {
|
|
7829
|
-
observer.disconnect();
|
|
7830
|
-
};
|
|
7831
|
-
}, [element, observer]);
|
|
7832
|
-
return [ref, rect];
|
|
7833
|
-
}
|
|
7834
|
-
|
|
7835
|
-
// src/PdfReader/index.tsx
|
|
7836
|
-
import "react-pdf/dist/Page/AnnotationLayer.css";
|
|
7837
|
-
import "react-pdf/dist/Page/TextLayer.css";
|
|
7838
|
-
|
|
7839
7700
|
// src/PdfReader/lib.ts
|
|
7840
7701
|
var SCALE_STEP = 0.1;
|
|
7841
7702
|
var START_QUERY = "start";
|
|
@@ -8067,6 +7928,116 @@ function isStartOfResource(pageNumber, resourceHref) {
|
|
|
8067
7928
|
return pageNumber === (startPage != null ? startPage : 1);
|
|
8068
7929
|
}
|
|
8069
7930
|
|
|
7931
|
+
// src/PdfReader/ScrollPage.tsx
|
|
7932
|
+
import React48 from "react";
|
|
7933
|
+
import { useInView } from "react-intersection-observer";
|
|
7934
|
+
var Placeholder = ({ width, height, pageNumber }) => {
|
|
7935
|
+
return /* @__PURE__ */ React48.createElement(
|
|
7936
|
+
"div",
|
|
7937
|
+
{
|
|
7938
|
+
"data-page-number": pageNumber,
|
|
7939
|
+
style: { width, height }
|
|
7940
|
+
}
|
|
7941
|
+
);
|
|
7942
|
+
};
|
|
7943
|
+
var ScrollPage = ({
|
|
7944
|
+
scale,
|
|
7945
|
+
pageNumber,
|
|
7946
|
+
width,
|
|
7947
|
+
height,
|
|
7948
|
+
onLoadSuccess,
|
|
7949
|
+
placeholderHeight,
|
|
7950
|
+
placeholderWidth,
|
|
7951
|
+
allowInView,
|
|
7952
|
+
onInView,
|
|
7953
|
+
fitMode,
|
|
7954
|
+
rotate
|
|
7955
|
+
}) => {
|
|
7956
|
+
const { ref: loadRef, inView: loadInView } = useInView({
|
|
7957
|
+
threshold: 0,
|
|
7958
|
+
triggerOnce: true
|
|
7959
|
+
});
|
|
7960
|
+
const { ref: visibilityRef, entry } = useInView({
|
|
7961
|
+
threshold: Array.from({ length: 11 }, (_, i) => i * 0.1),
|
|
7962
|
+
triggerOnce: false
|
|
7963
|
+
});
|
|
7964
|
+
const setRefs = React48.useCallback(
|
|
7965
|
+
(el) => {
|
|
7966
|
+
if (typeof loadRef === "function") loadRef(el);
|
|
7967
|
+
if (typeof visibilityRef === "function") visibilityRef(el);
|
|
7968
|
+
},
|
|
7969
|
+
[loadRef, visibilityRef]
|
|
7970
|
+
);
|
|
7971
|
+
const handleLoadSuccess = React48.useCallback(
|
|
7972
|
+
(page) => {
|
|
7973
|
+
onLoadSuccess(page);
|
|
7974
|
+
},
|
|
7975
|
+
[onLoadSuccess]
|
|
7976
|
+
);
|
|
7977
|
+
React48.useEffect(() => {
|
|
7978
|
+
if (allowInView && onInView && entry) {
|
|
7979
|
+
onInView(pageNumber, entry.intersectionRatio || 0);
|
|
7980
|
+
}
|
|
7981
|
+
}, [allowInView, entry, onInView, pageNumber]);
|
|
7982
|
+
return /* @__PURE__ */ React48.createElement("div", { ref: setRefs }, loadInView ? /* @__PURE__ */ React48.createElement(
|
|
7983
|
+
ChakraPage_default,
|
|
7984
|
+
{
|
|
7985
|
+
"data-page-number": pageNumber,
|
|
7986
|
+
pageNumber,
|
|
7987
|
+
scale,
|
|
7988
|
+
width,
|
|
7989
|
+
height,
|
|
7990
|
+
onLoadSuccess: handleLoadSuccess,
|
|
7991
|
+
fitMode,
|
|
7992
|
+
rotate
|
|
7993
|
+
}
|
|
7994
|
+
) : /* @__PURE__ */ React48.createElement(
|
|
7995
|
+
Placeholder,
|
|
7996
|
+
{
|
|
7997
|
+
width: placeholderWidth,
|
|
7998
|
+
height: placeholderHeight,
|
|
7999
|
+
pageNumber
|
|
8000
|
+
}
|
|
8001
|
+
));
|
|
8002
|
+
};
|
|
8003
|
+
var ScrollPage_default = ScrollPage;
|
|
8004
|
+
|
|
8005
|
+
// src/PdfReader/useMeasure.tsx
|
|
8006
|
+
import * as React49 from "react";
|
|
8007
|
+
var DEFAULT_DIMENSION = {
|
|
8008
|
+
x: 0,
|
|
8009
|
+
y: 0,
|
|
8010
|
+
width: 0,
|
|
8011
|
+
height: 0,
|
|
8012
|
+
top: 0,
|
|
8013
|
+
left: 0,
|
|
8014
|
+
bottom: 0,
|
|
8015
|
+
right: 0
|
|
8016
|
+
};
|
|
8017
|
+
function useMeasure() {
|
|
8018
|
+
const [element, ref] = React49.useState(null);
|
|
8019
|
+
const [rect, setRect] = React49.useState(DEFAULT_DIMENSION);
|
|
8020
|
+
const observer = React49.useMemo(
|
|
8021
|
+
() => new window.ResizeObserver(
|
|
8022
|
+
(entries) => {
|
|
8023
|
+
if (entries[0]) {
|
|
8024
|
+
const { x, y, width, height, top, left, bottom, right } = entries[0].contentRect;
|
|
8025
|
+
setRect({ x, y, width, height, top, left, bottom, right });
|
|
8026
|
+
}
|
|
8027
|
+
}
|
|
8028
|
+
),
|
|
8029
|
+
[]
|
|
8030
|
+
);
|
|
8031
|
+
React49.useLayoutEffect(() => {
|
|
8032
|
+
if (!element) return;
|
|
8033
|
+
observer.observe(element);
|
|
8034
|
+
return () => {
|
|
8035
|
+
observer.disconnect();
|
|
8036
|
+
};
|
|
8037
|
+
}, [element, observer]);
|
|
8038
|
+
return [ref, rect];
|
|
8039
|
+
}
|
|
8040
|
+
|
|
8070
8041
|
// src/PdfReader/index.tsx
|
|
8071
8042
|
function usePdfReader(args) {
|
|
8072
8043
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -8208,6 +8179,10 @@ function usePdfReader(args) {
|
|
|
8208
8179
|
var _a2;
|
|
8209
8180
|
if (!((_a2 = state2.settings) == null ? void 0 : _a2.isScrolling)) return;
|
|
8210
8181
|
if (!state2.rendered) return;
|
|
8182
|
+
if (scrollState.current.isInViewUpdate) {
|
|
8183
|
+
scrollState.current.isInViewUpdate = false;
|
|
8184
|
+
return;
|
|
8185
|
+
}
|
|
8211
8186
|
process.nextTick(() => {
|
|
8212
8187
|
const page = document.querySelector(
|
|
8213
8188
|
`[data-page-number="${state2.pageNumber}"]`
|
|
@@ -8252,29 +8227,38 @@ function usePdfReader(args) {
|
|
|
8252
8227
|
const setFitMode = React50.useCallback((mode) => {
|
|
8253
8228
|
dispatch({ type: "SET_FIT_MODE", fitMode: mode });
|
|
8254
8229
|
}, []);
|
|
8255
|
-
const
|
|
8256
|
-
|
|
8230
|
+
const scrollState = React50.useRef({
|
|
8231
|
+
ratios: /* @__PURE__ */ new Map(),
|
|
8232
|
+
lastVisiblepage: state2.pageNumber,
|
|
8233
|
+
hasScrolled: false,
|
|
8234
|
+
isInViewUpdate: false
|
|
8235
|
+
});
|
|
8257
8236
|
const onInView = React50.useCallback(
|
|
8258
8237
|
(pageNum, ratio) => {
|
|
8259
8238
|
var _a2;
|
|
8239
|
+
const currentScrollState = scrollState.current;
|
|
8260
8240
|
if (!((_a2 = state2.settings) == null ? void 0 : _a2.isScrolling)) return;
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8241
|
+
currentScrollState.ratios.set(pageNum, ratio);
|
|
8242
|
+
if (!currentScrollState.hasScrolled && state2.pageNumber === 1) {
|
|
8243
|
+
const container = document.querySelector(
|
|
8244
|
+
`#${MAIN_CONTENT_ID} .react-pdf__Document`
|
|
8245
|
+
);
|
|
8246
|
+
if (container && container.scrollTop > 0)
|
|
8247
|
+
currentScrollState.hasScrolled = true;
|
|
8248
|
+
else return;
|
|
8249
|
+
}
|
|
8250
|
+
let mostVisiblePage = currentScrollState.lastVisiblepage;
|
|
8267
8251
|
let maxRatio = -1;
|
|
8268
|
-
|
|
8269
|
-
for (const [page, r] of Object.entries(intersectionRatios.current)) {
|
|
8252
|
+
currentScrollState.ratios.forEach((r, p) => {
|
|
8270
8253
|
if (r > maxRatio) {
|
|
8271
8254
|
maxRatio = r;
|
|
8272
|
-
mostVisiblePage =
|
|
8255
|
+
mostVisiblePage = p;
|
|
8273
8256
|
}
|
|
8274
|
-
}
|
|
8275
|
-
if (mostVisiblePage !==
|
|
8276
|
-
|
|
8257
|
+
});
|
|
8258
|
+
if (mostVisiblePage !== currentScrollState.lastVisiblepage) {
|
|
8259
|
+
currentScrollState.lastVisiblepage = mostVisiblePage;
|
|
8277
8260
|
if (state2.pageNumber !== mostVisiblePage) {
|
|
8261
|
+
currentScrollState.isInViewUpdate = true;
|
|
8278
8262
|
dispatch({ type: "PAGE_IN_VIEW", page: mostVisiblePage });
|
|
8279
8263
|
}
|
|
8280
8264
|
}
|
|
@@ -8373,7 +8357,7 @@ function usePdfReader(args) {
|
|
|
8373
8357
|
scale: state2.scale,
|
|
8374
8358
|
pageNumber: index + 1,
|
|
8375
8359
|
onLoadSuccess: onRenderSuccess,
|
|
8376
|
-
allowInView:
|
|
8360
|
+
allowInView: state2.rendered,
|
|
8377
8361
|
onInView,
|
|
8378
8362
|
fitMode: state2.fitMode,
|
|
8379
8363
|
rotate: (_a2 = state2.rotation) != null ? _a2 : 0
|