@nypl/web-reader 4.3.4 → 4.3.5
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/dist/index.d.ts +12 -9
- package/dist/index.js +60 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6725,7 +6725,7 @@ var getResourceUrl = (index, readingOrder) => {
|
|
|
6725
6725
|
}
|
|
6726
6726
|
return readingOrder[index].href;
|
|
6727
6727
|
};
|
|
6728
|
-
var
|
|
6728
|
+
var fetchAsUint8Array = (resourceUrl, proxyUrl) => __async(void 0, null, function* () {
|
|
6729
6729
|
const url = proxyUrl ? `${proxyUrl}${encodeURIComponent(resourceUrl)}` : resourceUrl;
|
|
6730
6730
|
const response = yield fetch(url, { mode: "cors" });
|
|
6731
6731
|
const array = new Uint8Array(yield response.arrayBuffer());
|
|
@@ -6879,6 +6879,12 @@ function makePdfReducer(args) {
|
|
|
6879
6879
|
// end of the PDF that was just parsed
|
|
6880
6880
|
pageNumber: state2.pageNumber === -1 ? action.numPages : state2.pageNumber
|
|
6881
6881
|
});
|
|
6882
|
+
case "PDF_LOAD_ERROR":
|
|
6883
|
+
return __spreadProps(__spreadValues({}, state2), {
|
|
6884
|
+
state: "ERROR",
|
|
6885
|
+
error: action.error,
|
|
6886
|
+
settings: DEFAULT_SETTINGS
|
|
6887
|
+
});
|
|
6882
6888
|
case "SET_SCROLL":
|
|
6883
6889
|
if (state2.state !== "ACTIVE") {
|
|
6884
6890
|
return handleInvalidTransition(state2, action);
|
|
@@ -6934,7 +6940,7 @@ function usePdfReader(args) {
|
|
|
6934
6940
|
webpubManifestUrl,
|
|
6935
6941
|
manifest,
|
|
6936
6942
|
proxyUrl,
|
|
6937
|
-
getContent,
|
|
6943
|
+
getContent = fetchAsUint8Array,
|
|
6938
6944
|
injectablesReflowable,
|
|
6939
6945
|
injectablesFixed,
|
|
6940
6946
|
height = DEFAULT_HEIGHT,
|
|
@@ -6990,17 +6996,22 @@ function usePdfReader(args) {
|
|
|
6990
6996
|
if (!manifest.readingOrder || !manifest.readingOrder.length) {
|
|
6991
6997
|
throw new Error("Manifest has no Reading Order");
|
|
6992
6998
|
}
|
|
6993
|
-
const
|
|
6999
|
+
const currentResource = getResourceUrl(
|
|
6994
7000
|
state2.resourceIndex,
|
|
6995
7001
|
manifest.readingOrder
|
|
6996
7002
|
);
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7003
|
+
const fetchResource = () => __async(this, null, function* () {
|
|
7004
|
+
getContent(currentResource, proxyUrl).then((data) => {
|
|
7005
|
+
dispatch({
|
|
7006
|
+
type: "RESOURCE_FETCH_SUCCESS",
|
|
7007
|
+
resource: { data }
|
|
7008
|
+
});
|
|
7001
7009
|
});
|
|
7002
7010
|
});
|
|
7003
|
-
|
|
7011
|
+
if (manifest.readingOrder && manifest.readingOrder.length) {
|
|
7012
|
+
fetchResource();
|
|
7013
|
+
}
|
|
7014
|
+
}, [state2.resourceIndex, manifest, proxyUrl, getContent]);
|
|
7004
7015
|
const resizePage = React34.useCallback(
|
|
7005
7016
|
(pdfWidth, pdfHeight, containerSize2) => {
|
|
7006
7017
|
const wRatio = pdfWidth / containerSize2.width;
|
|
@@ -7089,12 +7100,20 @@ function usePdfReader(args) {
|
|
|
7089
7100
|
state: null
|
|
7090
7101
|
};
|
|
7091
7102
|
}
|
|
7103
|
+
if (state2.state === "ERROR")
|
|
7104
|
+
throw state2.error;
|
|
7092
7105
|
const onDocumentLoadSuccess = ({ numPages }) => {
|
|
7093
7106
|
dispatch({
|
|
7094
7107
|
type: "PDF_PARSED",
|
|
7095
7108
|
numPages
|
|
7096
7109
|
});
|
|
7097
7110
|
};
|
|
7111
|
+
const onDocumentLoadError = (error2) => {
|
|
7112
|
+
dispatch({
|
|
7113
|
+
type: "PDF_LOAD_ERROR",
|
|
7114
|
+
error: error2
|
|
7115
|
+
});
|
|
7116
|
+
};
|
|
7098
7117
|
function onRenderSuccess(page) {
|
|
7099
7118
|
if (!page.height || !page.width)
|
|
7100
7119
|
throw new Error(
|
|
@@ -7134,28 +7153,36 @@ function usePdfReader(args) {
|
|
|
7134
7153
|
overflow-y: auto;
|
|
7135
7154
|
}
|
|
7136
7155
|
`),
|
|
7137
|
-
/* @__PURE__ */ React34.createElement(
|
|
7138
|
-
|
|
7156
|
+
/* @__PURE__ */ React34.createElement(
|
|
7157
|
+
Document,
|
|
7139
7158
|
{
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
+
file: state2.resource,
|
|
7160
|
+
onLoadSuccess: onDocumentLoadSuccess,
|
|
7161
|
+
onLoadError: onDocumentLoadError
|
|
7162
|
+
},
|
|
7163
|
+
isParsed && state2.numPages && /* @__PURE__ */ React34.createElement(React34.Fragment, null, state2.settings.isScrolling && Array.from(new Array(state2.numPages), (_, index) => /* @__PURE__ */ React34.createElement(
|
|
7164
|
+
ScrollPage_default,
|
|
7165
|
+
{
|
|
7166
|
+
key: `page_${index + 1}`,
|
|
7167
|
+
width: containerSize.width,
|
|
7168
|
+
placeholderHeight: state2.pdfHeight,
|
|
7169
|
+
placeholderWidth: state2.pdfWidth,
|
|
7170
|
+
scale: state2.scale,
|
|
7171
|
+
pageNumber: index + 1,
|
|
7172
|
+
onLoadSuccess: onRenderSuccess
|
|
7173
|
+
}
|
|
7174
|
+
)), !state2.settings.isScrolling && /* @__PURE__ */ React34.createElement(
|
|
7175
|
+
ChakraPage_default,
|
|
7176
|
+
{
|
|
7177
|
+
pageNumber: state2.pageNumber,
|
|
7178
|
+
onLoadSuccess: onRenderSuccess,
|
|
7179
|
+
width: state2.pageWidth,
|
|
7180
|
+
height: state2.pageHeight,
|
|
7181
|
+
scale: state2.scale,
|
|
7182
|
+
loading: /* @__PURE__ */ React34.createElement(React34.Fragment, null)
|
|
7183
|
+
}
|
|
7184
|
+
))
|
|
7185
|
+
)
|
|
7159
7186
|
),
|
|
7160
7187
|
state: state2,
|
|
7161
7188
|
manifest,
|
|
@@ -8394,11 +8421,13 @@ function useWebReader(args) {
|
|
|
8394
8421
|
const readerType = getReaderType(
|
|
8395
8422
|
manifest ? manifest.metadata.conformsTo : null
|
|
8396
8423
|
);
|
|
8424
|
+
const getContentHtml = getContent;
|
|
8425
|
+
const getContentPdf = getContent;
|
|
8397
8426
|
const htmlReader = useHtmlReader(
|
|
8398
8427
|
readerType === "HTML" && manifest ? {
|
|
8399
8428
|
webpubManifestUrl,
|
|
8400
8429
|
manifest,
|
|
8401
|
-
getContent,
|
|
8430
|
+
getContent: getContentHtml,
|
|
8402
8431
|
injectablesReflowable,
|
|
8403
8432
|
injectablesFixed,
|
|
8404
8433
|
height,
|
|
@@ -8411,6 +8440,7 @@ function useWebReader(args) {
|
|
|
8411
8440
|
readerType === "PDF" && manifest ? {
|
|
8412
8441
|
webpubManifestUrl,
|
|
8413
8442
|
manifest,
|
|
8443
|
+
getContent: getContentPdf,
|
|
8414
8444
|
proxyUrl,
|
|
8415
8445
|
pdfWorkerSrc,
|
|
8416
8446
|
height,
|