@file-viewer/renderer-pdf 2.2.6 → 2.2.7
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/pdf.js +48 -14
- package/package.json +2 -2
package/dist/pdf.js
CHANGED
|
@@ -343,6 +343,8 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
343
343
|
let scrollStateFrame = 0;
|
|
344
344
|
let rotationOperationVersion = 0;
|
|
345
345
|
let pendingUserRotationAnchor = null;
|
|
346
|
+
let zoomOperationVersion = 0;
|
|
347
|
+
let pendingUserZoomAnchor = null;
|
|
346
348
|
let pdfSearchState = createPdfSearchState();
|
|
347
349
|
let pdfMatchesCount = { current: 0, total: 0 };
|
|
348
350
|
let pdfSearchOptions;
|
|
@@ -1068,11 +1070,16 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1068
1070
|
pendingUserRotationAnchor = null;
|
|
1069
1071
|
rotationOperationVersion += 1;
|
|
1070
1072
|
};
|
|
1071
|
-
const
|
|
1073
|
+
const cancelPendingUserZoomRestore = () => {
|
|
1074
|
+
if (!pendingUserZoomAnchor) {
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
pendingUserZoomAnchor = null;
|
|
1078
|
+
zoomOperationVersion += 1;
|
|
1079
|
+
};
|
|
1080
|
+
const restorePdfPageAnchor = (anchor, isActive, release) => {
|
|
1072
1081
|
const apply = () => {
|
|
1073
|
-
if (destroyed ||
|
|
1074
|
-
operationVersion !== rotationOperationVersion ||
|
|
1075
|
-
pendingUserRotationAnchor !== anchor) {
|
|
1082
|
+
if (destroyed || !isActive()) {
|
|
1076
1083
|
return false;
|
|
1077
1084
|
}
|
|
1078
1085
|
const pageElement = getPdfPageElement(anchor.page);
|
|
@@ -1106,14 +1113,19 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1106
1113
|
});
|
|
1107
1114
|
targetWindow.setTimeout(() => {
|
|
1108
1115
|
apply();
|
|
1109
|
-
if (
|
|
1110
|
-
|
|
1111
|
-
pendingUserRotationAnchor = null;
|
|
1112
|
-
}
|
|
1116
|
+
if (isActive())
|
|
1117
|
+
release();
|
|
1113
1118
|
}, 180);
|
|
1114
1119
|
};
|
|
1120
|
+
const restoreUserRotationAnchor = (anchor, operationVersion) => restorePdfPageAnchor(anchor, () => operationVersion === rotationOperationVersion && pendingUserRotationAnchor === anchor, () => {
|
|
1121
|
+
pendingUserRotationAnchor = null;
|
|
1122
|
+
});
|
|
1123
|
+
const restoreUserZoomAnchor = (anchor, operationVersion) => restorePdfPageAnchor(anchor, () => operationVersion === zoomOperationVersion && pendingUserZoomAnchor === anchor, () => {
|
|
1124
|
+
pendingUserZoomAnchor = null;
|
|
1125
|
+
});
|
|
1115
1126
|
const recordUserScrollIntent = () => {
|
|
1116
1127
|
cancelPendingUserRotationRestore();
|
|
1128
|
+
cancelPendingUserZoomRestore();
|
|
1117
1129
|
userScrollIntentUntil = Date.now() + 750;
|
|
1118
1130
|
suppressScrollEventUntil = 0;
|
|
1119
1131
|
markFitInteraction('user');
|
|
@@ -1283,6 +1295,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1283
1295
|
if (!pdfContext.viewer) {
|
|
1284
1296
|
return;
|
|
1285
1297
|
}
|
|
1298
|
+
cancelPendingUserZoomRestore();
|
|
1286
1299
|
userScrollIntentUntil = 0;
|
|
1287
1300
|
suppressProgrammaticScrollEvents();
|
|
1288
1301
|
autoFitWidth = true;
|
|
@@ -1294,6 +1307,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1294
1307
|
};
|
|
1295
1308
|
const applyPdfFit = async (request) => {
|
|
1296
1309
|
var _a, _b, _c;
|
|
1310
|
+
cancelPendingUserZoomRestore();
|
|
1297
1311
|
userScrollIntentUntil = 0;
|
|
1298
1312
|
activeFitRequest = { ...request };
|
|
1299
1313
|
if (!pdfContext.viewer || loadStatus !== 'ready') {
|
|
@@ -1381,13 +1395,30 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1381
1395
|
fitToWidth('viewer');
|
|
1382
1396
|
});
|
|
1383
1397
|
};
|
|
1398
|
+
const setAnchoredScale = (scale, action, source) => {
|
|
1399
|
+
if (!pdfContext.viewer) {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
cancelPendingUserRotationRestore();
|
|
1403
|
+
pendingUserZoomAnchor || (pendingUserZoomAnchor = captureCurrentPdfPageAnchor());
|
|
1404
|
+
const pageAnchor = pendingUserZoomAnchor;
|
|
1405
|
+
const operationVersion = ++zoomOperationVersion;
|
|
1406
|
+
if (pageAnchor) {
|
|
1407
|
+
suppressProgrammaticScrollEvents();
|
|
1408
|
+
currentPage = pageAnchor.page;
|
|
1409
|
+
}
|
|
1410
|
+
setScale(scale, action, source);
|
|
1411
|
+
if (pageAnchor) {
|
|
1412
|
+
restoreUserZoomAnchor(pageAnchor, operationVersion);
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1384
1415
|
const zoomIn = (source = 'user') => {
|
|
1385
1416
|
markFitInteraction(source);
|
|
1386
|
-
|
|
1417
|
+
setAnchoredScale(currentScale + SCALE_STEP, 'zoom-in', source);
|
|
1387
1418
|
};
|
|
1388
1419
|
const zoomOut = (source = 'user') => {
|
|
1389
1420
|
markFitInteraction(source);
|
|
1390
|
-
|
|
1421
|
+
setAnchoredScale(currentScale - SCALE_STEP, 'zoom-out', source);
|
|
1391
1422
|
};
|
|
1392
1423
|
const reapplyFitAfterLayout = (source, notifyViewState = true) => {
|
|
1393
1424
|
if (activeFitRequest) {
|
|
@@ -1407,6 +1438,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1407
1438
|
markFitInteraction(source);
|
|
1408
1439
|
const normalized = normalizeRotation(rotation);
|
|
1409
1440
|
if (source === 'user' && pdfContext.viewer) {
|
|
1441
|
+
cancelPendingUserZoomRestore();
|
|
1410
1442
|
pendingUserRotationAnchor || (pendingUserRotationAnchor = captureCurrentPdfPageAnchor());
|
|
1411
1443
|
}
|
|
1412
1444
|
else {
|
|
@@ -1474,6 +1506,7 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1474
1506
|
}
|
|
1475
1507
|
if (source === 'user') {
|
|
1476
1508
|
cancelPendingUserRotationRestore();
|
|
1509
|
+
cancelPendingUserZoomRestore();
|
|
1477
1510
|
}
|
|
1478
1511
|
markFitInteraction(source);
|
|
1479
1512
|
const nextPage = Math.min(pageCount, Math.max(1, pageNumber));
|
|
@@ -1721,8 +1754,9 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1721
1754
|
}
|
|
1722
1755
|
});
|
|
1723
1756
|
eventBus.on('pagechanging', ({ pageNumber }) => {
|
|
1724
|
-
|
|
1725
|
-
|
|
1757
|
+
const pendingPageAnchor = pendingUserRotationAnchor || pendingUserZoomAnchor;
|
|
1758
|
+
if (pendingPageAnchor && pageNumber !== pendingPageAnchor.page) {
|
|
1759
|
+
currentPage = pendingPageAnchor.page;
|
|
1726
1760
|
syncUi();
|
|
1727
1761
|
return;
|
|
1728
1762
|
}
|
|
@@ -1945,12 +1979,12 @@ export default async function renderPdf(buffer, target, context) {
|
|
|
1945
1979
|
},
|
|
1946
1980
|
resetZoom: () => {
|
|
1947
1981
|
markFitInteraction('api');
|
|
1948
|
-
|
|
1982
|
+
setAnchoredScale(1, 'zoom-reset', 'api');
|
|
1949
1983
|
return getPdfZoomState();
|
|
1950
1984
|
},
|
|
1951
1985
|
setZoom: scale => {
|
|
1952
1986
|
markFitInteraction('api');
|
|
1953
|
-
|
|
1987
|
+
setAnchoredScale(scale, 'zoom-change', 'api');
|
|
1954
1988
|
return getPdfZoomState();
|
|
1955
1989
|
},
|
|
1956
1990
|
fit: applyPdfFit,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-pdf",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone PDF renderer plugin for File Viewer powered by PDF.js.",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"LICENSE"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@file-viewer/core": "2.2.
|
|
57
|
+
"@file-viewer/core": "2.2.7",
|
|
58
58
|
"@fontsource-variable/noto-sans-sc": "5.2.10",
|
|
59
59
|
"pdf-lib": "1.17.1",
|
|
60
60
|
"pdfjs-dist": "5.4.624"
|