react-pdfjs-multi 0.5.1 → 1.0.0-rc.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.
- package/README.md +96 -19
- package/dist/assets/secondaryToolbarButton-rotateCcw.png +0 -0
- package/dist/assets/secondaryToolbarButton-rotateCcw@2x.png +0 -0
- package/dist/assets/secondaryToolbarButton-rotateCw.png +0 -0
- package/dist/assets/secondaryToolbarButton-rotateCw@2x.png +0 -0
- package/dist/assets/texture.png +0 -0
- package/dist/assets/toolbarButton-download.png +0 -0
- package/dist/assets/toolbarButton-download@2x.png +0 -0
- package/dist/assets/toolbarButton-menuArrows.png +0 -0
- package/dist/assets/toolbarButton-sidebarToggle.png +0 -0
- package/dist/assets/toolbarButton-sidebarToggle@2x.png +0 -0
- package/dist/assets/toolbarButton-zoomIn.png +0 -0
- package/dist/assets/toolbarButton-zoomIn@2x.png +0 -0
- package/dist/assets/toolbarButton-zoomOut.png +0 -0
- package/dist/assets/toolbarButton-zoomOut@2x.png +0 -0
- package/dist/components/PdfMultiViewer/PdfMultiViewer.d.ts +19 -0
- package/dist/components/PdfMultiViewer/PdfMultiViewerView.d.ts +20 -0
- package/dist/components/PdfMultiViewer/index.d.ts +4 -0
- package/dist/components/PdfMultiViewer/usePdfMultiViewer.d.ts +44 -0
- package/dist/components/PdfRenderer/PdfRenderer.d.ts +28 -0
- package/dist/{PdfRendererControls.d.ts → components/PdfRenderer/PdfRendererControls.d.ts} +14 -15
- package/dist/components/PdfRenderer/PdfRendererView.d.ts +20 -0
- package/dist/components/PdfRenderer/ZoomSelectBox.d.ts +9 -0
- package/dist/components/PdfRenderer/index.d.ts +7 -0
- package/dist/components/PdfRenderer/usePdfRenderer.d.ts +32 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/{I18nContext.d.ts → contexts/I18nContext.d.ts} +12 -12
- package/dist/contexts/index.d.ts +1 -0
- package/dist/index.css +6 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +815 -1767
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +826 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/filenameHelper.d.ts +1 -1
- package/dist/lib/iconStyles.d.ts +3 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/pdfjsLib.d.ts +2 -0
- package/dist/lib/resizeAutoZoomEvent.d.ts +0 -1
- package/dist/pdf.worker.min.mjs +28 -0
- package/dist/pdfjsLib-DFD5U54F.js +9 -0
- package/dist/pdfjsLib-DgdIcD_k.mjs +8 -0
- package/dist/pdfjsLib-DgdIcD_k.mjs.map +1 -0
- package/dist/pdfjsLib-cEuHH6WZ.mjs +3 -0
- package/dist/pdfjsLib-z4sS0gWp.js +41 -0
- package/dist/pdfjsLib-z4sS0gWp.js.map +1 -0
- package/dist/react-pdfjs-multi.css +4 -5
- package/dist/types/iconConfig.d.ts +10 -0
- package/package.json +45 -69
- package/dist/PdfMultiViewer.d.ts +0 -57
- package/dist/PdfRenderer.d.ts +0 -56
- package/dist/ZoomSelectBox.d.ts +0 -32
- package/dist/index.es.js +0 -1778
package/dist/index.js
CHANGED
|
@@ -1,1787 +1,835 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/* global Reflect, Promise */
|
|
25
|
-
|
|
26
|
-
var extendStatics = function(d, b) {
|
|
27
|
-
extendStatics = Object.setPrototypeOf ||
|
|
28
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
29
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
30
|
-
return extendStatics(d, b);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function __extends(d, b) {
|
|
34
|
-
extendStatics(d, b);
|
|
35
|
-
function __() { this.constructor = d; }
|
|
36
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var __assign = function() {
|
|
40
|
-
__assign = Object.assign || function __assign(t) {
|
|
41
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
42
|
-
s = arguments[i];
|
|
43
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
44
|
-
}
|
|
45
|
-
return t;
|
|
46
|
-
};
|
|
47
|
-
return __assign.apply(this, arguments);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
51
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
52
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
53
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
54
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
55
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
56
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function __generator(thisArg, body) {
|
|
61
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
62
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
63
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
64
|
-
function step(op) {
|
|
65
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
66
|
-
while (_) try {
|
|
67
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
68
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
69
|
-
switch (op[0]) {
|
|
70
|
-
case 0: case 1: t = op; break;
|
|
71
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
72
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
73
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
74
|
-
default:
|
|
75
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
76
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
77
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
78
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
79
|
-
if (t[2]) _.ops.pop();
|
|
80
|
-
_.trys.pop(); continue;
|
|
81
|
-
}
|
|
82
|
-
op = body.call(thisArg, _);
|
|
83
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
84
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function createCommonjsModule(fn, module) {
|
|
89
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** @license React v16.13.1
|
|
93
|
-
* react-is.production.min.js
|
|
94
|
-
*
|
|
95
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
96
|
-
*
|
|
97
|
-
* This source code is licensed under the MIT license found in the
|
|
98
|
-
* LICENSE file in the root directory of this source tree.
|
|
99
|
-
*/
|
|
100
|
-
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?
|
|
101
|
-
Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
|
|
102
|
-
function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}var AsyncMode=l;var ConcurrentMode=m;var ContextConsumer=k;var ContextProvider=h;var Element=c;var ForwardRef=n;var Fragment=e;var Lazy=t;var Memo=r;var Portal=d;
|
|
103
|
-
var Profiler=g;var StrictMode=f;var Suspense=p;var isAsyncMode=function(a){return A(a)||z(a)===l};var isConcurrentMode=A;var isContextConsumer=function(a){return z(a)===k};var isContextProvider=function(a){return z(a)===h};var isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};var isForwardRef=function(a){return z(a)===n};var isFragment=function(a){return z(a)===e};var isLazy=function(a){return z(a)===t};
|
|
104
|
-
var isMemo=function(a){return z(a)===r};var isPortal=function(a){return z(a)===d};var isProfiler=function(a){return z(a)===g};var isStrictMode=function(a){return z(a)===f};var isSuspense=function(a){return z(a)===p};
|
|
105
|
-
var isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};var typeOf=z;
|
|
1
|
+
const require_pdfjsLib = require('./pdfjsLib-z4sS0gWp.js');
|
|
2
|
+
let react = require("react");
|
|
3
|
+
react = require_pdfjsLib.__toESM(react);
|
|
4
|
+
require("pdfjs-dist/web/pdf_viewer.css");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
let pdfjs_dist_build_pdf_mjs = require("pdfjs-dist/build/pdf.mjs");
|
|
7
|
+
|
|
8
|
+
//#region src/lib/resizeAutoZoomEvent.ts
|
|
9
|
+
(() => {
|
|
10
|
+
const throttle = (type, name) => {
|
|
11
|
+
let running = false;
|
|
12
|
+
const func = () => {
|
|
13
|
+
if (running) return;
|
|
14
|
+
running = true;
|
|
15
|
+
requestAnimationFrame(() => {
|
|
16
|
+
window.dispatchEvent(new Event(name));
|
|
17
|
+
running = false;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
window.addEventListener(type, func);
|
|
21
|
+
};
|
|
22
|
+
throttle("resize", "resizeAutoZoom");
|
|
23
|
+
})();
|
|
106
24
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Portal: Portal,
|
|
118
|
-
Profiler: Profiler,
|
|
119
|
-
StrictMode: StrictMode,
|
|
120
|
-
Suspense: Suspense,
|
|
121
|
-
isAsyncMode: isAsyncMode,
|
|
122
|
-
isConcurrentMode: isConcurrentMode,
|
|
123
|
-
isContextConsumer: isContextConsumer,
|
|
124
|
-
isContextProvider: isContextProvider,
|
|
125
|
-
isElement: isElement,
|
|
126
|
-
isForwardRef: isForwardRef,
|
|
127
|
-
isFragment: isFragment,
|
|
128
|
-
isLazy: isLazy,
|
|
129
|
-
isMemo: isMemo,
|
|
130
|
-
isPortal: isPortal,
|
|
131
|
-
isProfiler: isProfiler,
|
|
132
|
-
isStrictMode: isStrictMode,
|
|
133
|
-
isSuspense: isSuspense,
|
|
134
|
-
isValidElementType: isValidElementType,
|
|
135
|
-
typeOf: typeOf
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/contexts/I18nContext.tsx
|
|
27
|
+
const defaultI18n = {
|
|
28
|
+
zoom: "Automatic zoom",
|
|
29
|
+
originalSize: "Original size",
|
|
30
|
+
scaleUp: "Scale up",
|
|
31
|
+
scaleDown: "Scale down",
|
|
32
|
+
rotateLeft: "Rotate left",
|
|
33
|
+
rotateRight: "Rotate right",
|
|
34
|
+
download: "Download"
|
|
136
35
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
exports.isPortal = isPortal;
|
|
302
|
-
exports.isProfiler = isProfiler;
|
|
303
|
-
exports.isStrictMode = isStrictMode;
|
|
304
|
-
exports.isSuspense = isSuspense;
|
|
305
|
-
exports.isValidElementType = isValidElementType;
|
|
306
|
-
exports.typeOf = typeOf;
|
|
307
|
-
})();
|
|
308
|
-
}
|
|
36
|
+
const I18nContext = react.default.createContext(defaultI18n);
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/components/PdfRenderer/ZoomSelectBox.tsx
|
|
40
|
+
const createSelectOptions = ({ originalSize, zoom }) => [
|
|
41
|
+
{
|
|
42
|
+
id: "automated",
|
|
43
|
+
text: `${zoom}`
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "50-percent",
|
|
47
|
+
text: "50%",
|
|
48
|
+
value: 50
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "75-percent",
|
|
52
|
+
text: "75%",
|
|
53
|
+
value: 75
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "original",
|
|
57
|
+
text: `${originalSize} (100%)`,
|
|
58
|
+
value: 100
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "125-percent",
|
|
62
|
+
text: "125%",
|
|
63
|
+
value: 125
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "150-percent",
|
|
67
|
+
text: "150%",
|
|
68
|
+
value: 150
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "200-percent",
|
|
72
|
+
text: "200%",
|
|
73
|
+
value: 200
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "300-percent",
|
|
77
|
+
text: "300%",
|
|
78
|
+
value: 300
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "400-percent",
|
|
82
|
+
text: "400%",
|
|
83
|
+
value: 400
|
|
84
|
+
},
|
|
85
|
+
{ id: "calculated" }
|
|
86
|
+
];
|
|
87
|
+
const showCalculatedScale = (scale, i18nData) => {
|
|
88
|
+
return createSelectOptions(i18nData).filter((option) => option.value === scale).length === 0 && scale % 10 === 0 ? scale : 0;
|
|
89
|
+
};
|
|
90
|
+
const ZoomSelectBox = ({ autoZoom, scale, setScale }) => {
|
|
91
|
+
const i18nData = (0, react.useContext)(I18nContext);
|
|
92
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
93
|
+
className: "dropdown-toolbar-container",
|
|
94
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
95
|
+
className: "dropdown-toolbar",
|
|
96
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
97
|
+
value: scale,
|
|
98
|
+
onChange: (e) => {
|
|
99
|
+
setScale(parseInt(e.target.value, 10));
|
|
100
|
+
},
|
|
101
|
+
children: createSelectOptions(i18nData).map(({ id, text, value }) => {
|
|
102
|
+
switch (id) {
|
|
103
|
+
case "calculated": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
104
|
+
value: showCalculatedScale(scale, i18nData),
|
|
105
|
+
hidden: true,
|
|
106
|
+
disabled: true,
|
|
107
|
+
children: `${scale}%`
|
|
108
|
+
}, `${id}-${scale}`);
|
|
109
|
+
case "automated": return autoZoom && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
110
|
+
value: -1,
|
|
111
|
+
children: text
|
|
112
|
+
}, `${id}-${scale}`);
|
|
113
|
+
default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
114
|
+
value,
|
|
115
|
+
children: text
|
|
116
|
+
}, id);
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var ZoomSelectBox_default = ZoomSelectBox;
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/components/PdfRenderer/PdfRendererControls.tsx
|
|
127
|
+
const PdfControls = ({ autoZoom, downloadBtn, onDownload, onZoomIn, onZoomOut, onRotateRight, onRotateLeft, scale, setScale }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
128
|
+
className: "renderer-controls",
|
|
129
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
130
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(I18nContext.Consumer, { children: ({ scaleDown, scaleUp }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
131
|
+
className: "button-group",
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
134
|
+
className: "renderer-controls-button",
|
|
135
|
+
type: "button",
|
|
136
|
+
onClick: onZoomOut,
|
|
137
|
+
"aria-label": scaleDown,
|
|
138
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
139
|
+
className: "zoom-out-label",
|
|
140
|
+
"aria-hidden": "true"
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "split-button-seperator" }),
|
|
144
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
145
|
+
className: "renderer-controls-button",
|
|
146
|
+
type: "button",
|
|
147
|
+
onClick: onZoomIn,
|
|
148
|
+
"aria-label": scaleUp,
|
|
149
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
150
|
+
className: "zoom-in-label",
|
|
151
|
+
"aria-hidden": "true"
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
]
|
|
155
|
+
}) }),
|
|
156
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ZoomSelectBox_default, {
|
|
157
|
+
autoZoom,
|
|
158
|
+
scale,
|
|
159
|
+
setScale
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(I18nContext.Consumer, { children: ({ rotateLeft, rotateRight, download }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
162
|
+
className: "button-group",
|
|
163
|
+
children: [
|
|
164
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
165
|
+
className: "renderer-controls-button",
|
|
166
|
+
type: "button",
|
|
167
|
+
onClick: onRotateLeft,
|
|
168
|
+
"aria-label": rotateLeft,
|
|
169
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
170
|
+
className: "rotate-left-label",
|
|
171
|
+
"aria-hidden": "true"
|
|
172
|
+
})
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "split-button-seperator" }),
|
|
175
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
176
|
+
className: "renderer-controls-button",
|
|
177
|
+
type: "button",
|
|
178
|
+
onClick: onRotateRight,
|
|
179
|
+
"aria-label": rotateRight,
|
|
180
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
181
|
+
className: "rotate-right-label",
|
|
182
|
+
"aria-hidden": "true"
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
}), downloadBtn && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
187
|
+
className: "button-group",
|
|
188
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
189
|
+
className: "renderer-controls-button",
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: onDownload,
|
|
192
|
+
"aria-label": download,
|
|
193
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
194
|
+
className: "download-label",
|
|
195
|
+
"aria-hidden": "true"
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
})] }) })
|
|
199
|
+
] })
|
|
309
200
|
});
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
module.exports = reactIs_development;
|
|
345
|
-
}
|
|
201
|
+
var PdfRendererControls_default = PdfControls;
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/components/PdfRenderer/PdfRendererView.tsx
|
|
205
|
+
const PdfRendererView = ({ autoZoom, containerRef, controls, downloadBtn, iconStyles, i18nData, isLoading, scale, setScale, onDownload, onRotateLeft, onRotateRight, onZoomIn, onZoomOut }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
206
|
+
className: "pdfjs-multi renderer-container",
|
|
207
|
+
style: iconStyles,
|
|
208
|
+
children: [controls && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(I18nContext.Provider, {
|
|
209
|
+
value: {
|
|
210
|
+
...defaultI18n,
|
|
211
|
+
...i18nData ?? {}
|
|
212
|
+
},
|
|
213
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PdfRendererControls_default, {
|
|
214
|
+
autoZoom,
|
|
215
|
+
downloadBtn,
|
|
216
|
+
scale,
|
|
217
|
+
setScale,
|
|
218
|
+
onDownload,
|
|
219
|
+
onZoomIn,
|
|
220
|
+
onZoomOut,
|
|
221
|
+
onRotateRight,
|
|
222
|
+
onRotateLeft
|
|
223
|
+
})
|
|
224
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
225
|
+
className: "renderer-stage",
|
|
226
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
227
|
+
ref: containerRef,
|
|
228
|
+
className: `renderer-target-container ${!controls ? "no-controls" : ""} `,
|
|
229
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
230
|
+
id: "viewer",
|
|
231
|
+
className: `pdfViewer ${isLoading ? "hidden" : ""}`
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
})]
|
|
346
235
|
});
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
236
|
+
var PdfRendererView_default = PdfRendererView;
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/lib/filenameHelper.ts
|
|
240
|
+
const isDataSchema = (url) => {
|
|
241
|
+
let i = 0, ii = url.length;
|
|
242
|
+
while (i < ii && url[i].trim() === "") i++;
|
|
243
|
+
return url.substring(i, i + 5).toLowerCase() === "data:";
|
|
244
|
+
};
|
|
245
|
+
const getPDFFileNameFromURL = (url, defaultFilename = "document.pdf") => {
|
|
246
|
+
if (typeof url !== "string") return defaultFilename;
|
|
247
|
+
if (isDataSchema(url)) {
|
|
248
|
+
console.warn("getPDFFileNameFromURL: ignoring \"data:\" URL for performance reasons.");
|
|
249
|
+
return defaultFilename;
|
|
361
250
|
}
|
|
251
|
+
const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
|
252
|
+
const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
|
|
253
|
+
const splitURI = reURI.exec(url);
|
|
254
|
+
let suggestedFilename = null;
|
|
255
|
+
if (splitURI) suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
|
|
256
|
+
if (suggestedFilename) {
|
|
257
|
+
suggestedFilename = suggestedFilename[0];
|
|
258
|
+
if (suggestedFilename.includes("%")) try {
|
|
259
|
+
const suggestedFilenameResult = reFilename.exec(decodeURIComponent(suggestedFilename));
|
|
260
|
+
if (suggestedFilenameResult) suggestedFilename = suggestedFilenameResult[0];
|
|
261
|
+
} catch (_ex) {}
|
|
262
|
+
}
|
|
263
|
+
return suggestedFilename || defaultFilename;
|
|
264
|
+
};
|
|
362
265
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/components/PdfRenderer/usePdfRenderer.ts
|
|
268
|
+
const SCALE = {
|
|
269
|
+
percent: 100,
|
|
270
|
+
min: 10,
|
|
271
|
+
max: 1e3,
|
|
272
|
+
roundTo: 10,
|
|
273
|
+
auto: -1,
|
|
274
|
+
default: 100
|
|
275
|
+
};
|
|
276
|
+
const AUTO_FIT = {
|
|
277
|
+
maxContainerWidth: 1020,
|
|
278
|
+
padding: 56,
|
|
279
|
+
fallbackWidth: 1019
|
|
280
|
+
};
|
|
281
|
+
const ZOOM = {
|
|
282
|
+
largeStepMin: 110,
|
|
283
|
+
largeStepMax: 990,
|
|
284
|
+
specialSteps: new Set([75, 125]),
|
|
285
|
+
roundingExceptions: new Set([125]),
|
|
286
|
+
stepLarge: 20,
|
|
287
|
+
stepDefault: 10,
|
|
288
|
+
stepSmall: 5
|
|
289
|
+
};
|
|
290
|
+
const ROTATION_STEP = 90;
|
|
291
|
+
const SCROLL_DEFAULT = 0;
|
|
292
|
+
const roundToNearest = (numToRound, numToRoundTo) => Math.round(numToRound / numToRoundTo) * numToRoundTo;
|
|
293
|
+
const usePdfRenderer = ({ activeIndex, autoZoom, pdfChangeHook, pdfDoc, rotation, scrollLeft, scrollTop, zoom }) => {
|
|
294
|
+
const containerRef = (0, react.useRef)(null);
|
|
295
|
+
const pdfViewerRef = (0, react.useRef)(null);
|
|
296
|
+
const downloadManagerRef = (0, react.useRef)(null);
|
|
297
|
+
const initialAutoZoomRef = (0, react.useRef)(autoZoom);
|
|
298
|
+
const latestPdfDocRef = (0, react.useRef)(pdfDoc);
|
|
299
|
+
const [scale, setScaleState] = (0, react.useState)(SCALE.default);
|
|
300
|
+
const [isLoading, setIsLoading] = (0, react.useState)(true);
|
|
301
|
+
const scaleRef = (0, react.useRef)(scale);
|
|
302
|
+
(0, react.useEffect)(() => {
|
|
303
|
+
scaleRef.current = scale;
|
|
304
|
+
}, [scale]);
|
|
305
|
+
(0, react.useEffect)(() => {
|
|
306
|
+
latestPdfDocRef.current = pdfDoc;
|
|
307
|
+
}, [pdfDoc]);
|
|
308
|
+
const applyScale = (0, react.useCallback)((nextScaleValue) => {
|
|
309
|
+
const nextScale = nextScaleValue >= SCALE.min ? nextScaleValue : SCALE.min;
|
|
310
|
+
setScaleState(nextScale);
|
|
311
|
+
if (pdfViewerRef.current) pdfViewerRef.current.currentScaleValue = String(nextScale / SCALE.percent);
|
|
312
|
+
}, []);
|
|
313
|
+
const autoFitScale = (0, react.useCallback)(() => {
|
|
314
|
+
const firstPage = pdfViewerRef.current?._pages?.[0];
|
|
315
|
+
if (!firstPage) return;
|
|
316
|
+
const originalWidth = firstPage.viewport.width / firstPage.scale;
|
|
317
|
+
const offsetWidth = containerRef.current?.offsetWidth;
|
|
318
|
+
const containerWidth = offsetWidth && offsetWidth < AUTO_FIT.maxContainerWidth ? offsetWidth - AUTO_FIT.padding : AUTO_FIT.fallbackWidth;
|
|
319
|
+
let nextScale = SCALE.auto;
|
|
320
|
+
if (containerRef.current) nextScale = Math.abs(containerWidth) / originalWidth;
|
|
321
|
+
applyScale(nextScale * SCALE.percent);
|
|
322
|
+
}, [applyScale]);
|
|
323
|
+
const setScale = (0, react.useCallback)((nextScaleValue) => {
|
|
324
|
+
if (autoZoom && nextScaleValue < 0) {
|
|
325
|
+
autoFitScale();
|
|
326
|
+
return;
|
|
385
327
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
328
|
+
applyScale(nextScaleValue);
|
|
329
|
+
}, [
|
|
330
|
+
applyScale,
|
|
331
|
+
autoFitScale,
|
|
332
|
+
autoZoom
|
|
333
|
+
]);
|
|
334
|
+
const setScrollTop = (0, react.useCallback)((nextScrollTop) => {
|
|
335
|
+
if (containerRef.current) containerRef.current.scrollTop = nextScrollTop ?? SCROLL_DEFAULT;
|
|
336
|
+
}, []);
|
|
337
|
+
const setScrollLeft = (0, react.useCallback)((nextScrollLeft) => {
|
|
338
|
+
if (containerRef.current) containerRef.current.scrollLeft = nextScrollLeft ?? SCROLL_DEFAULT;
|
|
339
|
+
}, []);
|
|
340
|
+
const rePosition = (0, react.useCallback)(async () => {
|
|
341
|
+
if (!pdfViewerRef.current) return;
|
|
342
|
+
await pdfViewerRef.current.firstPagePromise;
|
|
343
|
+
if (rotation) pdfViewerRef.current.pagesRotation = rotation;
|
|
344
|
+
if (zoom) setScale(zoom);
|
|
345
|
+
else if (!zoom && autoZoom) autoFitScale();
|
|
346
|
+
if (typeof scrollTop !== "undefined") setScrollTop(scrollTop ?? null);
|
|
347
|
+
if (typeof scrollLeft !== "undefined") setScrollLeft(scrollLeft ?? null);
|
|
348
|
+
}, [
|
|
349
|
+
autoFitScale,
|
|
350
|
+
autoZoom,
|
|
351
|
+
rotation,
|
|
352
|
+
scrollLeft,
|
|
353
|
+
scrollTop,
|
|
354
|
+
setScale,
|
|
355
|
+
setScrollLeft,
|
|
356
|
+
setScrollTop,
|
|
357
|
+
zoom
|
|
358
|
+
]);
|
|
359
|
+
const rePositionRef = (0, react.useRef)(rePosition);
|
|
360
|
+
(0, react.useEffect)(() => {
|
|
361
|
+
rePositionRef.current = rePosition;
|
|
362
|
+
}, [rePosition]);
|
|
363
|
+
(0, react.useEffect)(() => {
|
|
364
|
+
let cancelled = false;
|
|
365
|
+
const setupViewer = async () => {
|
|
366
|
+
const { PdfjsLib } = await Promise.resolve().then(() => require("./pdfjsLib-DFD5U54F.js"));
|
|
367
|
+
if (cancelled) return;
|
|
368
|
+
globalThis.pdfjsLib = PdfjsLib;
|
|
369
|
+
const { PDFViewer, DownloadManager, EventBus } = globalThis.__pdfjsViewer ?? await import("pdfjs-dist/web/pdf_viewer.mjs");
|
|
370
|
+
downloadManagerRef.current = new DownloadManager();
|
|
371
|
+
if (!containerRef.current) return;
|
|
372
|
+
pdfViewerRef.current = new PDFViewer({
|
|
373
|
+
container: containerRef.current,
|
|
374
|
+
eventBus: new EventBus()
|
|
375
|
+
});
|
|
376
|
+
pdfViewerRef.current.setDocument(latestPdfDocRef.current);
|
|
377
|
+
if (initialAutoZoomRef.current) window.addEventListener("resizeAutoZoom", autoFitScale);
|
|
378
|
+
await rePositionRef.current();
|
|
379
|
+
if (!cancelled) setIsLoading(false);
|
|
380
|
+
};
|
|
381
|
+
setupViewer();
|
|
382
|
+
return () => {
|
|
383
|
+
cancelled = true;
|
|
384
|
+
if (initialAutoZoomRef.current) window.removeEventListener("resizeAutoZoom", autoFitScale);
|
|
385
|
+
pdfViewerRef.current = null;
|
|
386
|
+
downloadManagerRef.current = null;
|
|
387
|
+
};
|
|
388
|
+
}, [autoFitScale]);
|
|
389
|
+
const prevPdfDocRef = (0, react.useRef)(pdfDoc);
|
|
390
|
+
const prevActiveIndexRef = (0, react.useRef)(activeIndex);
|
|
391
|
+
(0, react.useEffect)(() => {
|
|
392
|
+
if (!pdfViewerRef.current) {
|
|
393
|
+
prevPdfDocRef.current = pdfDoc;
|
|
394
|
+
prevActiveIndexRef.current = activeIndex;
|
|
395
|
+
return;
|
|
391
396
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
397
|
+
if (prevPdfDocRef.current !== pdfDoc) {
|
|
398
|
+
if (typeof pdfChangeHook === "function") pdfChangeHook(String(prevActiveIndexRef.current), {
|
|
399
|
+
zoom: scaleRef.current,
|
|
400
|
+
rotation: pdfViewerRef.current.pagesRotation,
|
|
401
|
+
scrollTop: containerRef.current?.scrollTop ?? null,
|
|
402
|
+
scrollLeft: containerRef.current?.scrollLeft ?? null
|
|
403
|
+
});
|
|
404
|
+
pdfViewerRef.current.setDocument(pdfDoc);
|
|
405
|
+
rePosition();
|
|
401
406
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
407
|
+
prevPdfDocRef.current = pdfDoc;
|
|
408
|
+
prevActiveIndexRef.current = activeIndex;
|
|
409
|
+
}, [
|
|
410
|
+
activeIndex,
|
|
411
|
+
pdfChangeHook,
|
|
412
|
+
pdfDoc,
|
|
413
|
+
rePosition
|
|
414
|
+
]);
|
|
415
|
+
const zoomIn = (0, react.useCallback)(() => {
|
|
416
|
+
const nextScale = roundToNearest(scaleRef.current, SCALE.roundTo);
|
|
417
|
+
let newScale = nextScale;
|
|
418
|
+
if (nextScale >= ZOOM.largeStepMin && nextScale < ZOOM.largeStepMax) newScale = nextScale + ZOOM.stepLarge;
|
|
419
|
+
else if (ZOOM.specialSteps.has(nextScale)) newScale = nextScale + ZOOM.stepSmall;
|
|
420
|
+
else newScale = nextScale + ZOOM.stepDefault;
|
|
421
|
+
if (newScale > SCALE.max) return;
|
|
422
|
+
setScale(newScale);
|
|
423
|
+
}, [setScale]);
|
|
424
|
+
const zoomOut = (0, react.useCallback)(() => {
|
|
425
|
+
let nextScale = scaleRef.current;
|
|
426
|
+
nextScale = ZOOM.roundingExceptions.has(nextScale) ? nextScale : roundToNearest(nextScale, SCALE.roundTo);
|
|
427
|
+
let newScale = nextScale;
|
|
428
|
+
if (nextScale > ZOOM.largeStepMin && !ZOOM.specialSteps.has(nextScale)) newScale = nextScale - ZOOM.stepLarge;
|
|
429
|
+
else if (ZOOM.specialSteps.has(nextScale)) newScale = nextScale - ZOOM.stepSmall;
|
|
430
|
+
else newScale = nextScale - ZOOM.stepDefault;
|
|
431
|
+
if (newScale <= 0) return;
|
|
432
|
+
setScale(newScale);
|
|
433
|
+
}, [setScale]);
|
|
434
|
+
const rotateRight = (0, react.useCallback)(() => {
|
|
435
|
+
if (!pdfViewerRef.current) return;
|
|
436
|
+
const currentRotation = pdfViewerRef.current.pagesRotation;
|
|
437
|
+
pdfViewerRef.current.pagesRotation = currentRotation + ROTATION_STEP;
|
|
438
|
+
}, []);
|
|
439
|
+
const rotateLeft = (0, react.useCallback)(() => {
|
|
440
|
+
if (!pdfViewerRef.current) return;
|
|
441
|
+
const currentRotation = pdfViewerRef.current.pagesRotation;
|
|
442
|
+
pdfViewerRef.current.pagesRotation = currentRotation - ROTATION_STEP;
|
|
443
|
+
}, []);
|
|
444
|
+
return {
|
|
445
|
+
containerRef,
|
|
446
|
+
download: (0, react.useCallback)(async () => {
|
|
447
|
+
if (!downloadManagerRef.current) return;
|
|
448
|
+
const url = pdfDoc._transport?._params?.url;
|
|
449
|
+
let filename = getPDFFileNameFromURL(url ?? "");
|
|
450
|
+
if (typeof pdfDoc.getMetadata === "function") try {
|
|
451
|
+
const contentDispositionFilename = (await pdfDoc.getMetadata()).contentDispositionFilename;
|
|
452
|
+
if (typeof contentDispositionFilename === "string" && contentDispositionFilename.trim()) filename = contentDispositionFilename;
|
|
453
|
+
} catch (_error) {}
|
|
454
|
+
const downloadByUrl = () => {
|
|
455
|
+
if (!url) return;
|
|
456
|
+
downloadManagerRef.current.downloadUrl(url, filename);
|
|
457
|
+
};
|
|
458
|
+
try {
|
|
459
|
+
const data = await pdfDoc.getData();
|
|
460
|
+
downloadManagerRef.current.download(data, url ?? "", filename);
|
|
461
|
+
} catch (_e) {
|
|
462
|
+
downloadByUrl();
|
|
421
463
|
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return to;
|
|
464
|
+
}, [pdfDoc]),
|
|
465
|
+
isLoading,
|
|
466
|
+
pdfViewerRef,
|
|
467
|
+
rotateLeft,
|
|
468
|
+
rotateRight,
|
|
469
|
+
scale,
|
|
470
|
+
setScale,
|
|
471
|
+
zoomIn,
|
|
472
|
+
zoomOut
|
|
473
|
+
};
|
|
435
474
|
};
|
|
436
475
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
var printWarning = function() {};
|
|
449
|
-
|
|
450
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
451
|
-
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
|
452
|
-
var loggedTypeFailures = {};
|
|
453
|
-
var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
454
|
-
|
|
455
|
-
printWarning = function(text) {
|
|
456
|
-
var message = 'Warning: ' + text;
|
|
457
|
-
if (typeof console !== 'undefined') {
|
|
458
|
-
console.error(message);
|
|
459
|
-
}
|
|
460
|
-
try {
|
|
461
|
-
// --- Welcome to debugging React ---
|
|
462
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
463
|
-
// to find the callsite that caused this warning to fire.
|
|
464
|
-
throw new Error(message);
|
|
465
|
-
} catch (x) {}
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Assert that the values match with the type specs.
|
|
471
|
-
* Error messages are memorized and will only be shown once.
|
|
472
|
-
*
|
|
473
|
-
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
474
|
-
* @param {object} values Runtime values that need to be type-checked
|
|
475
|
-
* @param {string} location e.g. "prop", "context", "child context"
|
|
476
|
-
* @param {string} componentName Name of the component for error messages.
|
|
477
|
-
* @param {?Function} getStack Returns the component stack.
|
|
478
|
-
* @private
|
|
479
|
-
*/
|
|
480
|
-
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
481
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
482
|
-
for (var typeSpecName in typeSpecs) {
|
|
483
|
-
if (has(typeSpecs, typeSpecName)) {
|
|
484
|
-
var error;
|
|
485
|
-
// Prop type validation may throw. In case they do, we don't want to
|
|
486
|
-
// fail the render phase where it didn't fail before. So we log it.
|
|
487
|
-
// After these have been cleaned up, we'll let them throw.
|
|
488
|
-
try {
|
|
489
|
-
// This is intentionally an invariant that gets caught. It's the same
|
|
490
|
-
// behavior as without this statement except with a better message.
|
|
491
|
-
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
492
|
-
var err = Error(
|
|
493
|
-
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
|
494
|
-
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
|
495
|
-
);
|
|
496
|
-
err.name = 'Invariant Violation';
|
|
497
|
-
throw err;
|
|
498
|
-
}
|
|
499
|
-
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
|
|
500
|
-
} catch (ex) {
|
|
501
|
-
error = ex;
|
|
502
|
-
}
|
|
503
|
-
if (error && !(error instanceof Error)) {
|
|
504
|
-
printWarning(
|
|
505
|
-
(componentName || 'React class') + ': type specification of ' +
|
|
506
|
-
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
|
507
|
-
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
|
508
|
-
'You may have forgotten to pass an argument to the type checker ' +
|
|
509
|
-
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
|
510
|
-
'shape all require an argument).'
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
514
|
-
// Only monitor this failure once because there tends to be a lot of the
|
|
515
|
-
// same error.
|
|
516
|
-
loggedTypeFailures[error.message] = true;
|
|
517
|
-
|
|
518
|
-
var stack = getStack ? getStack() : '';
|
|
519
|
-
|
|
520
|
-
printWarning(
|
|
521
|
-
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Resets warning cache when testing.
|
|
531
|
-
*
|
|
532
|
-
* @private
|
|
533
|
-
*/
|
|
534
|
-
checkPropTypes.resetWarningCache = function() {
|
|
535
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
536
|
-
loggedTypeFailures = {};
|
|
537
|
-
}
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/lib/iconStyles.ts
|
|
478
|
+
const iconVarMap = {
|
|
479
|
+
zoomIn: "--pdfjs-multi-control-icon-zoom-in",
|
|
480
|
+
zoomOut: "--pdfjs-multi-control-icon-zoom-out",
|
|
481
|
+
rotateLeft: "--pdfjs-multi-control-icon-rotate-left",
|
|
482
|
+
rotateRight: "--pdfjs-multi-control-icon-rotate-right",
|
|
483
|
+
download: "--pdfjs-multi-control-icon-download",
|
|
484
|
+
selectArrow: "--pdfjs-multi-select-icon",
|
|
485
|
+
toggleList: "--pdfjs-multi-control-icon-toggle-list",
|
|
486
|
+
texture: "--pdfjs-multi-texture"
|
|
538
487
|
};
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
546
|
-
printWarning$1 = function(text) {
|
|
547
|
-
var message = 'Warning: ' + text;
|
|
548
|
-
if (typeof console !== 'undefined') {
|
|
549
|
-
console.error(message);
|
|
550
|
-
}
|
|
551
|
-
try {
|
|
552
|
-
// --- Welcome to debugging React ---
|
|
553
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
554
|
-
// to find the callsite that caused this warning to fire.
|
|
555
|
-
throw new Error(message);
|
|
556
|
-
} catch (x) {}
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function emptyFunctionThatReturnsNull() {
|
|
561
|
-
return null;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
|
565
|
-
/* global Symbol */
|
|
566
|
-
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
567
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Returns the iterator method function contained on the iterable object.
|
|
571
|
-
*
|
|
572
|
-
* Be sure to invoke the function with the iterable as context:
|
|
573
|
-
*
|
|
574
|
-
* var iteratorFn = getIteratorFn(myIterable);
|
|
575
|
-
* if (iteratorFn) {
|
|
576
|
-
* var iterator = iteratorFn.call(myIterable);
|
|
577
|
-
* ...
|
|
578
|
-
* }
|
|
579
|
-
*
|
|
580
|
-
* @param {?object} maybeIterable
|
|
581
|
-
* @return {?function}
|
|
582
|
-
*/
|
|
583
|
-
function getIteratorFn(maybeIterable) {
|
|
584
|
-
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
585
|
-
if (typeof iteratorFn === 'function') {
|
|
586
|
-
return iteratorFn;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Collection of methods that allow declaration and validation of props that are
|
|
592
|
-
* supplied to React components. Example usage:
|
|
593
|
-
*
|
|
594
|
-
* var Props = require('ReactPropTypes');
|
|
595
|
-
* var MyArticle = React.createClass({
|
|
596
|
-
* propTypes: {
|
|
597
|
-
* // An optional string prop named "description".
|
|
598
|
-
* description: Props.string,
|
|
599
|
-
*
|
|
600
|
-
* // A required enum prop named "category".
|
|
601
|
-
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
602
|
-
*
|
|
603
|
-
* // A prop named "dialog" that requires an instance of Dialog.
|
|
604
|
-
* dialog: Props.instanceOf(Dialog).isRequired
|
|
605
|
-
* },
|
|
606
|
-
* render: function() { ... }
|
|
607
|
-
* });
|
|
608
|
-
*
|
|
609
|
-
* A more formal specification of how these methods are used:
|
|
610
|
-
*
|
|
611
|
-
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
612
|
-
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
613
|
-
*
|
|
614
|
-
* Each and every declaration produces a function with the same signature. This
|
|
615
|
-
* allows the creation of custom validation functions. For example:
|
|
616
|
-
*
|
|
617
|
-
* var MyLink = React.createClass({
|
|
618
|
-
* propTypes: {
|
|
619
|
-
* // An optional string or URI prop named "href".
|
|
620
|
-
* href: function(props, propName, componentName) {
|
|
621
|
-
* var propValue = props[propName];
|
|
622
|
-
* if (propValue != null && typeof propValue !== 'string' &&
|
|
623
|
-
* !(propValue instanceof URI)) {
|
|
624
|
-
* return new Error(
|
|
625
|
-
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
626
|
-
* componentName
|
|
627
|
-
* );
|
|
628
|
-
* }
|
|
629
|
-
* }
|
|
630
|
-
* },
|
|
631
|
-
* render: function() {...}
|
|
632
|
-
* });
|
|
633
|
-
*
|
|
634
|
-
* @internal
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
var ANONYMOUS = '<<anonymous>>';
|
|
638
|
-
|
|
639
|
-
// Important!
|
|
640
|
-
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
|
641
|
-
var ReactPropTypes = {
|
|
642
|
-
array: createPrimitiveTypeChecker('array'),
|
|
643
|
-
bool: createPrimitiveTypeChecker('boolean'),
|
|
644
|
-
func: createPrimitiveTypeChecker('function'),
|
|
645
|
-
number: createPrimitiveTypeChecker('number'),
|
|
646
|
-
object: createPrimitiveTypeChecker('object'),
|
|
647
|
-
string: createPrimitiveTypeChecker('string'),
|
|
648
|
-
symbol: createPrimitiveTypeChecker('symbol'),
|
|
649
|
-
|
|
650
|
-
any: createAnyTypeChecker(),
|
|
651
|
-
arrayOf: createArrayOfTypeChecker,
|
|
652
|
-
element: createElementTypeChecker(),
|
|
653
|
-
elementType: createElementTypeTypeChecker(),
|
|
654
|
-
instanceOf: createInstanceTypeChecker,
|
|
655
|
-
node: createNodeChecker(),
|
|
656
|
-
objectOf: createObjectOfTypeChecker,
|
|
657
|
-
oneOf: createEnumTypeChecker,
|
|
658
|
-
oneOfType: createUnionTypeChecker,
|
|
659
|
-
shape: createShapeTypeChecker,
|
|
660
|
-
exact: createStrictShapeTypeChecker,
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
665
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
666
|
-
*/
|
|
667
|
-
/*eslint-disable no-self-compare*/
|
|
668
|
-
function is(x, y) {
|
|
669
|
-
// SameValue algorithm
|
|
670
|
-
if (x === y) {
|
|
671
|
-
// Steps 1-5, 7-10
|
|
672
|
-
// Steps 6.b-6.e: +0 != -0
|
|
673
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
674
|
-
} else {
|
|
675
|
-
// Step 6.a: NaN == NaN
|
|
676
|
-
return x !== x && y !== y;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
/*eslint-enable no-self-compare*/
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* We use an Error-like object for backward compatibility as people may call
|
|
683
|
-
* PropTypes directly and inspect their output. However, we don't use real
|
|
684
|
-
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
685
|
-
* is prohibitively expensive if they are created too often, such as what
|
|
686
|
-
* happens in oneOfType() for any type before the one that matched.
|
|
687
|
-
*/
|
|
688
|
-
function PropTypeError(message) {
|
|
689
|
-
this.message = message;
|
|
690
|
-
this.stack = '';
|
|
691
|
-
}
|
|
692
|
-
// Make `instanceof Error` still work for returned errors.
|
|
693
|
-
PropTypeError.prototype = Error.prototype;
|
|
694
|
-
|
|
695
|
-
function createChainableTypeChecker(validate) {
|
|
696
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
697
|
-
var manualPropTypeCallCache = {};
|
|
698
|
-
var manualPropTypeWarningCount = 0;
|
|
699
|
-
}
|
|
700
|
-
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
701
|
-
componentName = componentName || ANONYMOUS;
|
|
702
|
-
propFullName = propFullName || propName;
|
|
703
|
-
|
|
704
|
-
if (secret !== ReactPropTypesSecret_1) {
|
|
705
|
-
if (throwOnDirectAccess) {
|
|
706
|
-
// New behavior only for users of `prop-types` package
|
|
707
|
-
var err = new Error(
|
|
708
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
709
|
-
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
|
710
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
711
|
-
);
|
|
712
|
-
err.name = 'Invariant Violation';
|
|
713
|
-
throw err;
|
|
714
|
-
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
|
|
715
|
-
// Old behavior for people using React.PropTypes
|
|
716
|
-
var cacheKey = componentName + ':' + propName;
|
|
717
|
-
if (
|
|
718
|
-
!manualPropTypeCallCache[cacheKey] &&
|
|
719
|
-
// Avoid spamming the console because they are often not actionable except for lib authors
|
|
720
|
-
manualPropTypeWarningCount < 3
|
|
721
|
-
) {
|
|
722
|
-
printWarning$1(
|
|
723
|
-
'You are manually calling a React.PropTypes validation ' +
|
|
724
|
-
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
|
725
|
-
'and will throw in the standalone `prop-types` package. ' +
|
|
726
|
-
'You may be seeing this warning due to a third-party PropTypes ' +
|
|
727
|
-
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
|
728
|
-
);
|
|
729
|
-
manualPropTypeCallCache[cacheKey] = true;
|
|
730
|
-
manualPropTypeWarningCount++;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (props[propName] == null) {
|
|
735
|
-
if (isRequired) {
|
|
736
|
-
if (props[propName] === null) {
|
|
737
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
738
|
-
}
|
|
739
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
740
|
-
}
|
|
741
|
-
return null;
|
|
742
|
-
} else {
|
|
743
|
-
return validate(props, propName, componentName, location, propFullName);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
var chainedCheckType = checkType.bind(null, false);
|
|
748
|
-
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
749
|
-
|
|
750
|
-
return chainedCheckType;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
function createPrimitiveTypeChecker(expectedType) {
|
|
754
|
-
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
755
|
-
var propValue = props[propName];
|
|
756
|
-
var propType = getPropType(propValue);
|
|
757
|
-
if (propType !== expectedType) {
|
|
758
|
-
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
759
|
-
// check, but we can offer a more precise error message here rather than
|
|
760
|
-
// 'of type `object`'.
|
|
761
|
-
var preciseType = getPreciseType(propValue);
|
|
762
|
-
|
|
763
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
|
764
|
-
}
|
|
765
|
-
return null;
|
|
766
|
-
}
|
|
767
|
-
return createChainableTypeChecker(validate);
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
function createAnyTypeChecker() {
|
|
771
|
-
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
function createArrayOfTypeChecker(typeChecker) {
|
|
775
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
776
|
-
if (typeof typeChecker !== 'function') {
|
|
777
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
778
|
-
}
|
|
779
|
-
var propValue = props[propName];
|
|
780
|
-
if (!Array.isArray(propValue)) {
|
|
781
|
-
var propType = getPropType(propValue);
|
|
782
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
783
|
-
}
|
|
784
|
-
for (var i = 0; i < propValue.length; i++) {
|
|
785
|
-
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
|
786
|
-
if (error instanceof Error) {
|
|
787
|
-
return error;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return null;
|
|
791
|
-
}
|
|
792
|
-
return createChainableTypeChecker(validate);
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
function createElementTypeChecker() {
|
|
796
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
797
|
-
var propValue = props[propName];
|
|
798
|
-
if (!isValidElement(propValue)) {
|
|
799
|
-
var propType = getPropType(propValue);
|
|
800
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
801
|
-
}
|
|
802
|
-
return null;
|
|
803
|
-
}
|
|
804
|
-
return createChainableTypeChecker(validate);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
function createElementTypeTypeChecker() {
|
|
808
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
809
|
-
var propValue = props[propName];
|
|
810
|
-
if (!reactIs.isValidElementType(propValue)) {
|
|
811
|
-
var propType = getPropType(propValue);
|
|
812
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
|
813
|
-
}
|
|
814
|
-
return null;
|
|
815
|
-
}
|
|
816
|
-
return createChainableTypeChecker(validate);
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
function createInstanceTypeChecker(expectedClass) {
|
|
820
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
821
|
-
if (!(props[propName] instanceof expectedClass)) {
|
|
822
|
-
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
823
|
-
var actualClassName = getClassName(props[propName]);
|
|
824
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
825
|
-
}
|
|
826
|
-
return null;
|
|
827
|
-
}
|
|
828
|
-
return createChainableTypeChecker(validate);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
function createEnumTypeChecker(expectedValues) {
|
|
832
|
-
if (!Array.isArray(expectedValues)) {
|
|
833
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
834
|
-
if (arguments.length > 1) {
|
|
835
|
-
printWarning$1(
|
|
836
|
-
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
|
|
837
|
-
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
|
|
838
|
-
);
|
|
839
|
-
} else {
|
|
840
|
-
printWarning$1('Invalid argument supplied to oneOf, expected an array.');
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
return emptyFunctionThatReturnsNull;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
847
|
-
var propValue = props[propName];
|
|
848
|
-
for (var i = 0; i < expectedValues.length; i++) {
|
|
849
|
-
if (is(propValue, expectedValues[i])) {
|
|
850
|
-
return null;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
|
855
|
-
var type = getPreciseType(value);
|
|
856
|
-
if (type === 'symbol') {
|
|
857
|
-
return String(value);
|
|
858
|
-
}
|
|
859
|
-
return value;
|
|
860
|
-
});
|
|
861
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
862
|
-
}
|
|
863
|
-
return createChainableTypeChecker(validate);
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
function createObjectOfTypeChecker(typeChecker) {
|
|
867
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
868
|
-
if (typeof typeChecker !== 'function') {
|
|
869
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
870
|
-
}
|
|
871
|
-
var propValue = props[propName];
|
|
872
|
-
var propType = getPropType(propValue);
|
|
873
|
-
if (propType !== 'object') {
|
|
874
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
875
|
-
}
|
|
876
|
-
for (var key in propValue) {
|
|
877
|
-
if (has$1(propValue, key)) {
|
|
878
|
-
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
879
|
-
if (error instanceof Error) {
|
|
880
|
-
return error;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
return null;
|
|
885
|
-
}
|
|
886
|
-
return createChainableTypeChecker(validate);
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
890
|
-
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
891
|
-
process.env.NODE_ENV !== 'production' ? printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
|
892
|
-
return emptyFunctionThatReturnsNull;
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
896
|
-
var checker = arrayOfTypeCheckers[i];
|
|
897
|
-
if (typeof checker !== 'function') {
|
|
898
|
-
printWarning$1(
|
|
899
|
-
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
|
900
|
-
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
|
901
|
-
);
|
|
902
|
-
return emptyFunctionThatReturnsNull;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
907
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
908
|
-
var checker = arrayOfTypeCheckers[i];
|
|
909
|
-
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
|
|
910
|
-
return null;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
915
|
-
}
|
|
916
|
-
return createChainableTypeChecker(validate);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
function createNodeChecker() {
|
|
920
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
921
|
-
if (!isNode(props[propName])) {
|
|
922
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
923
|
-
}
|
|
924
|
-
return null;
|
|
925
|
-
}
|
|
926
|
-
return createChainableTypeChecker(validate);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
function createShapeTypeChecker(shapeTypes) {
|
|
930
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
931
|
-
var propValue = props[propName];
|
|
932
|
-
var propType = getPropType(propValue);
|
|
933
|
-
if (propType !== 'object') {
|
|
934
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
935
|
-
}
|
|
936
|
-
for (var key in shapeTypes) {
|
|
937
|
-
var checker = shapeTypes[key];
|
|
938
|
-
if (!checker) {
|
|
939
|
-
continue;
|
|
940
|
-
}
|
|
941
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
942
|
-
if (error) {
|
|
943
|
-
return error;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
return null;
|
|
947
|
-
}
|
|
948
|
-
return createChainableTypeChecker(validate);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
function createStrictShapeTypeChecker(shapeTypes) {
|
|
952
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
953
|
-
var propValue = props[propName];
|
|
954
|
-
var propType = getPropType(propValue);
|
|
955
|
-
if (propType !== 'object') {
|
|
956
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
957
|
-
}
|
|
958
|
-
// We need to check all keys in case some are required but missing from
|
|
959
|
-
// props.
|
|
960
|
-
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
|
961
|
-
for (var key in allKeys) {
|
|
962
|
-
var checker = shapeTypes[key];
|
|
963
|
-
if (!checker) {
|
|
964
|
-
return new PropTypeError(
|
|
965
|
-
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
|
966
|
-
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
|
967
|
-
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
971
|
-
if (error) {
|
|
972
|
-
return error;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
return null;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
return createChainableTypeChecker(validate);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function isNode(propValue) {
|
|
982
|
-
switch (typeof propValue) {
|
|
983
|
-
case 'number':
|
|
984
|
-
case 'string':
|
|
985
|
-
case 'undefined':
|
|
986
|
-
return true;
|
|
987
|
-
case 'boolean':
|
|
988
|
-
return !propValue;
|
|
989
|
-
case 'object':
|
|
990
|
-
if (Array.isArray(propValue)) {
|
|
991
|
-
return propValue.every(isNode);
|
|
992
|
-
}
|
|
993
|
-
if (propValue === null || isValidElement(propValue)) {
|
|
994
|
-
return true;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
var iteratorFn = getIteratorFn(propValue);
|
|
998
|
-
if (iteratorFn) {
|
|
999
|
-
var iterator = iteratorFn.call(propValue);
|
|
1000
|
-
var step;
|
|
1001
|
-
if (iteratorFn !== propValue.entries) {
|
|
1002
|
-
while (!(step = iterator.next()).done) {
|
|
1003
|
-
if (!isNode(step.value)) {
|
|
1004
|
-
return false;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
} else {
|
|
1008
|
-
// Iterator will provide entry [k,v] tuples rather than values.
|
|
1009
|
-
while (!(step = iterator.next()).done) {
|
|
1010
|
-
var entry = step.value;
|
|
1011
|
-
if (entry) {
|
|
1012
|
-
if (!isNode(entry[1])) {
|
|
1013
|
-
return false;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
} else {
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
return true;
|
|
1023
|
-
default:
|
|
1024
|
-
return false;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
function isSymbol(propType, propValue) {
|
|
1029
|
-
// Native Symbol.
|
|
1030
|
-
if (propType === 'symbol') {
|
|
1031
|
-
return true;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// falsy value can't be a Symbol
|
|
1035
|
-
if (!propValue) {
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
1040
|
-
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
1041
|
-
return true;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
1045
|
-
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
1046
|
-
return true;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
return false;
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
1053
|
-
function getPropType(propValue) {
|
|
1054
|
-
var propType = typeof propValue;
|
|
1055
|
-
if (Array.isArray(propValue)) {
|
|
1056
|
-
return 'array';
|
|
1057
|
-
}
|
|
1058
|
-
if (propValue instanceof RegExp) {
|
|
1059
|
-
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
1060
|
-
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
1061
|
-
// passes PropTypes.object.
|
|
1062
|
-
return 'object';
|
|
1063
|
-
}
|
|
1064
|
-
if (isSymbol(propType, propValue)) {
|
|
1065
|
-
return 'symbol';
|
|
1066
|
-
}
|
|
1067
|
-
return propType;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
// This handles more types than `getPropType`. Only used for error messages.
|
|
1071
|
-
// See `createPrimitiveTypeChecker`.
|
|
1072
|
-
function getPreciseType(propValue) {
|
|
1073
|
-
if (typeof propValue === 'undefined' || propValue === null) {
|
|
1074
|
-
return '' + propValue;
|
|
1075
|
-
}
|
|
1076
|
-
var propType = getPropType(propValue);
|
|
1077
|
-
if (propType === 'object') {
|
|
1078
|
-
if (propValue instanceof Date) {
|
|
1079
|
-
return 'date';
|
|
1080
|
-
} else if (propValue instanceof RegExp) {
|
|
1081
|
-
return 'regexp';
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
return propType;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
// Returns a string that is postfixed to a warning about an invalid type.
|
|
1088
|
-
// For example, "undefined" or "of type array"
|
|
1089
|
-
function getPostfixForTypeWarning(value) {
|
|
1090
|
-
var type = getPreciseType(value);
|
|
1091
|
-
switch (type) {
|
|
1092
|
-
case 'array':
|
|
1093
|
-
case 'object':
|
|
1094
|
-
return 'an ' + type;
|
|
1095
|
-
case 'boolean':
|
|
1096
|
-
case 'date':
|
|
1097
|
-
case 'regexp':
|
|
1098
|
-
return 'a ' + type;
|
|
1099
|
-
default:
|
|
1100
|
-
return type;
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// Returns class name of the object, if any.
|
|
1105
|
-
function getClassName(propValue) {
|
|
1106
|
-
if (!propValue.constructor || !propValue.constructor.name) {
|
|
1107
|
-
return ANONYMOUS;
|
|
1108
|
-
}
|
|
1109
|
-
return propValue.constructor.name;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
ReactPropTypes.checkPropTypes = checkPropTypes_1;
|
|
1113
|
-
ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache;
|
|
1114
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
1115
|
-
|
|
1116
|
-
return ReactPropTypes;
|
|
488
|
+
const toCssValue = (value) => {
|
|
489
|
+
const trimmed = value.trim();
|
|
490
|
+
if (!trimmed) return void 0;
|
|
491
|
+
if (trimmed === "none") return "none";
|
|
492
|
+
if (/^[a-z-]+\(/i.test(trimmed)) return trimmed;
|
|
493
|
+
return `url("${trimmed.replaceAll("\"", "\\\"")}")`;
|
|
1117
494
|
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
var err = new Error(
|
|
1130
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
1131
|
-
'Use PropTypes.checkPropTypes() to call them. ' +
|
|
1132
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
1133
|
-
);
|
|
1134
|
-
err.name = 'Invariant Violation';
|
|
1135
|
-
throw err;
|
|
1136
|
-
} shim.isRequired = shim;
|
|
1137
|
-
function getShim() {
|
|
1138
|
-
return shim;
|
|
1139
|
-
} // Important!
|
|
1140
|
-
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
|
|
1141
|
-
var ReactPropTypes = {
|
|
1142
|
-
array: shim,
|
|
1143
|
-
bool: shim,
|
|
1144
|
-
func: shim,
|
|
1145
|
-
number: shim,
|
|
1146
|
-
object: shim,
|
|
1147
|
-
string: shim,
|
|
1148
|
-
symbol: shim,
|
|
1149
|
-
|
|
1150
|
-
any: shim,
|
|
1151
|
-
arrayOf: getShim,
|
|
1152
|
-
element: shim,
|
|
1153
|
-
elementType: shim,
|
|
1154
|
-
instanceOf: getShim,
|
|
1155
|
-
node: shim,
|
|
1156
|
-
objectOf: getShim,
|
|
1157
|
-
oneOf: getShim,
|
|
1158
|
-
oneOfType: getShim,
|
|
1159
|
-
shape: getShim,
|
|
1160
|
-
exact: getShim,
|
|
1161
|
-
|
|
1162
|
-
checkPropTypes: emptyFunctionWithReset,
|
|
1163
|
-
resetWarningCache: emptyFunction
|
|
1164
|
-
};
|
|
1165
|
-
|
|
1166
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
1167
|
-
|
|
1168
|
-
return ReactPropTypes;
|
|
495
|
+
const buildIconStyles = (icons) => {
|
|
496
|
+
if (!icons) return void 0;
|
|
497
|
+
const style = {};
|
|
498
|
+
for (const [key, cssVar] of Object.entries(iconVarMap)) {
|
|
499
|
+
const iconValue = icons[key];
|
|
500
|
+
if (!iconValue) continue;
|
|
501
|
+
const cssValue = toCssValue(iconValue);
|
|
502
|
+
if (!cssValue) continue;
|
|
503
|
+
style[cssVar] = cssValue;
|
|
504
|
+
}
|
|
505
|
+
return Object.keys(style).length ? style : void 0;
|
|
1169
506
|
};
|
|
1170
507
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/components/PdfRenderer/PdfRenderer.tsx
|
|
510
|
+
const PdfRenderer = (0, react.forwardRef)(({ pdfDoc, activeIndex = "0", autoZoom = true, controls = true, downloadBtn = true, icons, i18nData = defaultI18n, pdfChangeHook = null, zoom, rotation = 0, scrollTop = 0, scrollLeft = 0 }, ref) => {
|
|
511
|
+
const { containerRef, download, isLoading, pdfViewerRef, rotateLeft, rotateRight, scale, setScale, zoomIn, zoomOut } = usePdfRenderer({
|
|
512
|
+
activeIndex,
|
|
513
|
+
autoZoom,
|
|
514
|
+
pdfChangeHook,
|
|
515
|
+
pdfDoc,
|
|
516
|
+
rotation,
|
|
517
|
+
scrollLeft,
|
|
518
|
+
scrollTop,
|
|
519
|
+
zoom
|
|
520
|
+
});
|
|
521
|
+
(0, react.useImperativeHandle)(ref, () => ({ get pdfViewer() {
|
|
522
|
+
return pdfViewerRef.current;
|
|
523
|
+
} }));
|
|
524
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PdfRendererView_default, {
|
|
525
|
+
autoZoom,
|
|
526
|
+
containerRef,
|
|
527
|
+
controls,
|
|
528
|
+
downloadBtn,
|
|
529
|
+
iconStyles: buildIconStyles(icons),
|
|
530
|
+
i18nData,
|
|
531
|
+
isLoading,
|
|
532
|
+
scale,
|
|
533
|
+
setScale,
|
|
534
|
+
onDownload: download,
|
|
535
|
+
onRotateLeft: rotateLeft,
|
|
536
|
+
onRotateRight: rotateRight,
|
|
537
|
+
onZoomIn: zoomIn,
|
|
538
|
+
onZoomOut: zoomOut
|
|
539
|
+
});
|
|
1191
540
|
});
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
(
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
},
|
|
1287
|
-
{
|
|
1288
|
-
id: '50-percent',
|
|
1289
|
-
text: '50%',
|
|
1290
|
-
value: 50,
|
|
1291
|
-
},
|
|
1292
|
-
{
|
|
1293
|
-
id: '75-percent',
|
|
1294
|
-
text: '75%',
|
|
1295
|
-
value: 75,
|
|
1296
|
-
},
|
|
1297
|
-
{
|
|
1298
|
-
id: 'original',
|
|
1299
|
-
text: originalSize + " (100%)",
|
|
1300
|
-
value: 100,
|
|
1301
|
-
},
|
|
1302
|
-
{
|
|
1303
|
-
id: '125-percent',
|
|
1304
|
-
text: '125%',
|
|
1305
|
-
value: 125,
|
|
1306
|
-
},
|
|
1307
|
-
{
|
|
1308
|
-
id: '150-percent',
|
|
1309
|
-
text: '150%',
|
|
1310
|
-
value: 150,
|
|
1311
|
-
},
|
|
1312
|
-
{
|
|
1313
|
-
id: '200-percent',
|
|
1314
|
-
text: '200%',
|
|
1315
|
-
value: 200,
|
|
1316
|
-
},
|
|
1317
|
-
{
|
|
1318
|
-
id: '300-percent',
|
|
1319
|
-
text: '300%',
|
|
1320
|
-
value: 300,
|
|
1321
|
-
},
|
|
1322
|
-
{
|
|
1323
|
-
id: '400-percent',
|
|
1324
|
-
text: '400%',
|
|
1325
|
-
value: 400,
|
|
1326
|
-
},
|
|
1327
|
-
{
|
|
1328
|
-
id: 'calculated',
|
|
1329
|
-
},
|
|
1330
|
-
];
|
|
1331
|
-
};
|
|
1332
|
-
_this.showCalculatedScale = function (i18nData) {
|
|
1333
|
-
var scale = _this.props.scale;
|
|
1334
|
-
return _this.createSelectOptions(i18nData).filter(function (option) { return option.value === scale; }).length === 0 && scale % 10 === 0
|
|
1335
|
-
? scale
|
|
1336
|
-
: 0;
|
|
1337
|
-
};
|
|
1338
|
-
return _this;
|
|
1339
|
-
}
|
|
1340
|
-
ZoomSelectBox.prototype.render = function () {
|
|
1341
|
-
var _this = this;
|
|
1342
|
-
var _a = this.props, autoZoom = _a.autoZoom, scale = _a.scale, setScale = _a.setScale;
|
|
1343
|
-
return (React__default.createElement(I18nContext.Consumer, null, function (i18nData) { return (React__default.createElement("div", { className: "dropdown-toolbar-container" },
|
|
1344
|
-
React__default.createElement("span", { className: "dropdown-toolbar" },
|
|
1345
|
-
React__default.createElement("select", { value: scale, onChange: function (e) {
|
|
1346
|
-
setScale(parseInt(e.target.value, 10));
|
|
1347
|
-
} }, _this.createSelectOptions(i18nData).map(function (_a) {
|
|
1348
|
-
var id = _a.id, text = _a.text, value = _a.value;
|
|
1349
|
-
switch (id) {
|
|
1350
|
-
case 'calculated':
|
|
1351
|
-
return (React__default.createElement("option", { key: id + "-" + scale, value: _this.showCalculatedScale(i18nData), hidden: true, disabled: true }, scale + "%"));
|
|
1352
|
-
case 'automated':
|
|
1353
|
-
return (autoZoom && (React__default.createElement("option", { key: id + "-" + scale, value: -1 }, text)));
|
|
1354
|
-
default:
|
|
1355
|
-
return (React__default.createElement("option", { key: id, value: value }, text));
|
|
1356
|
-
}
|
|
1357
|
-
}))))); }));
|
|
1358
|
-
};
|
|
1359
|
-
ZoomSelectBox.propTypes = {
|
|
1360
|
-
scale: propTypes.number.isRequired,
|
|
1361
|
-
setScale: propTypes.func.isRequired,
|
|
1362
|
-
};
|
|
1363
|
-
return ZoomSelectBox;
|
|
1364
|
-
}(React.PureComponent));
|
|
1365
|
-
|
|
1366
|
-
var PdfControls = function (_a) {
|
|
1367
|
-
var autoZoom = _a.autoZoom, downloadBtn = _a.downloadBtn, onDownload = _a.onDownload, onZoomIn = _a.onZoomIn, onZoomOut = _a.onZoomOut, onRotateRight = _a.onRotateRight, onRotateLeft = _a.onRotateLeft, scale = _a.scale, setScale = _a.setScale;
|
|
1368
|
-
return (React__default.createElement("div", { className: "renderer-controls" },
|
|
1369
|
-
React__default.createElement("div", null,
|
|
1370
|
-
React__default.createElement(I18nContext.Consumer, null, function (_a) {
|
|
1371
|
-
var scaleDown = _a.scaleDown, scaleUp = _a.scaleUp;
|
|
1372
|
-
return (React__default.createElement("div", { className: "button-group" },
|
|
1373
|
-
React__default.createElement("button", { className: "renderer-controls-button", type: "button", onClick: onZoomOut },
|
|
1374
|
-
React__default.createElement("span", { className: "zoom-out-label" }, scaleDown)),
|
|
1375
|
-
React__default.createElement("div", { className: "split-button-seperator" }),
|
|
1376
|
-
React__default.createElement("button", { className: "renderer-controls-button", type: "button", onClick: onZoomIn },
|
|
1377
|
-
React__default.createElement("span", { className: "zoom-in-label" }, scaleUp))));
|
|
1378
|
-
}),
|
|
1379
|
-
React__default.createElement(ZoomSelectBox, { autoZoom: autoZoom, scale: scale, setScale: setScale }),
|
|
1380
|
-
React__default.createElement(I18nContext.Consumer, null, function (_a) {
|
|
1381
|
-
var scaleDown = _a.scaleDown, scaleUp = _a.scaleUp, download = _a.download;
|
|
1382
|
-
return (React__default.createElement(React.Fragment, null,
|
|
1383
|
-
React__default.createElement("div", { className: "button-group" },
|
|
1384
|
-
React__default.createElement("button", { className: "renderer-controls-button", type: "button", onClick: onRotateLeft },
|
|
1385
|
-
React__default.createElement("span", { className: "rotate-left-label" }, scaleDown)),
|
|
1386
|
-
React__default.createElement("div", { className: "split-button-seperator" }),
|
|
1387
|
-
React__default.createElement("button", { className: "renderer-controls-button", type: "button", onClick: onRotateRight },
|
|
1388
|
-
React__default.createElement("span", { className: "rotate-right-label" }, scaleUp))),
|
|
1389
|
-
downloadBtn && (React__default.createElement("div", { className: "button-group" },
|
|
1390
|
-
React__default.createElement("button", { className: "renderer-controls-button", type: "button", onClick: onDownload },
|
|
1391
|
-
React__default.createElement("span", { className: "download-label" }, download))))));
|
|
1392
|
-
}))));
|
|
541
|
+
PdfRenderer.displayName = "PdfRenderer";
|
|
542
|
+
var PdfRenderer_default = PdfRenderer;
|
|
543
|
+
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/components/PdfMultiViewer/PdfMultiViewerView.tsx
|
|
546
|
+
const PdfMultiViewerView = ({ activeIndex, autoZoom, controls, files, iconStyles, i18nData, listVisible, overlayMode, pdfToShow, viewerContainerRef, onRememberPosition, onSelectPdf, onToggleList }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
547
|
+
className: "pdfjs-multi pdf-multi-viewer",
|
|
548
|
+
ref: viewerContainerRef,
|
|
549
|
+
style: iconStyles,
|
|
550
|
+
children: [
|
|
551
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
552
|
+
className: "pdf-multi-viewer-option-bar",
|
|
553
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
554
|
+
className: `viewer-controls-button${listVisible ? " toggled" : ""}`,
|
|
555
|
+
onClick: onToggleList,
|
|
556
|
+
type: "button",
|
|
557
|
+
"aria-label": "Toggle list",
|
|
558
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
559
|
+
className: "toggle-list-label",
|
|
560
|
+
"aria-hidden": "true"
|
|
561
|
+
})
|
|
562
|
+
})
|
|
563
|
+
}),
|
|
564
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
565
|
+
className: `pdf-viewer-list${!listVisible ? " hidden" : ""}${overlayMode ? " overlay" : ""}`,
|
|
566
|
+
children: files.map((file, index) => {
|
|
567
|
+
const handleSelect = onSelectPdf(String(index), file);
|
|
568
|
+
const isLoading = Boolean(file.isLoading && !file.pdfProxy);
|
|
569
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
570
|
+
className: `pdf-viewer-list-item${file.pdfProxy ? " loaded" : ""}${isLoading ? " loading" : ""}${activeIndex === String(index) ? " active" : ""}`,
|
|
571
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
572
|
+
className: "pdf-viewer-list-item-button",
|
|
573
|
+
onClick: handleSelect,
|
|
574
|
+
type: "button",
|
|
575
|
+
children: [
|
|
576
|
+
file.title || file.source,
|
|
577
|
+
file.pdfProxy && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
578
|
+
className: "pdf-viewer-list-item-meta",
|
|
579
|
+
children: [
|
|
580
|
+
i18nData?.pages ?? "Pages",
|
|
581
|
+
": ",
|
|
582
|
+
file.pdfProxy.numPages
|
|
583
|
+
]
|
|
584
|
+
}),
|
|
585
|
+
isLoading && !file.pdfProxy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
586
|
+
className: "pdf-viewer-list-item-meta",
|
|
587
|
+
children: i18nData?.loading ?? "Loading..."
|
|
588
|
+
})
|
|
589
|
+
]
|
|
590
|
+
})
|
|
591
|
+
}, file.source);
|
|
592
|
+
})
|
|
593
|
+
}),
|
|
594
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
595
|
+
className: "pdf-viewer-multi-renderer",
|
|
596
|
+
children: pdfToShow?.pdfProxy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PdfRenderer_default, {
|
|
597
|
+
activeIndex,
|
|
598
|
+
autoZoom,
|
|
599
|
+
controls,
|
|
600
|
+
pdfDoc: pdfToShow.pdfProxy,
|
|
601
|
+
i18nData,
|
|
602
|
+
pdfChangeHook: onRememberPosition,
|
|
603
|
+
zoom: pdfToShow.zoom,
|
|
604
|
+
rotation: pdfToShow.rotation,
|
|
605
|
+
scrollTop: pdfToShow.scrollTop,
|
|
606
|
+
scrollLeft: pdfToShow.scrollLeft
|
|
607
|
+
}) : pdfToShow ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("output", {
|
|
608
|
+
className: "pdf-viewer-loading",
|
|
609
|
+
"aria-live": "polite",
|
|
610
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
611
|
+
className: "pdf-viewer-loading-spinner",
|
|
612
|
+
"aria-hidden": "true"
|
|
613
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
614
|
+
className: "pdf-viewer-loading-text",
|
|
615
|
+
children: i18nData?.loading ?? "Loading..."
|
|
616
|
+
})]
|
|
617
|
+
}) : null
|
|
618
|
+
})
|
|
619
|
+
]
|
|
620
|
+
});
|
|
621
|
+
var PdfMultiViewerView_default = PdfMultiViewerView;
|
|
622
|
+
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region src/components/PdfMultiViewer/usePdfMultiViewer.ts
|
|
625
|
+
const createPdfFile = (pdf) => {
|
|
626
|
+
return typeof pdf === "object" ? {
|
|
627
|
+
...pdf,
|
|
628
|
+
isLoading: false,
|
|
629
|
+
pdfProxy: null
|
|
630
|
+
} : {
|
|
631
|
+
isLoading: false,
|
|
632
|
+
source: pdf,
|
|
633
|
+
pdfProxy: null
|
|
634
|
+
};
|
|
1393
635
|
};
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
636
|
+
const usePdfMultiViewer = ({ pdfs, startIndex, i18nData, lazyLoad, initialLoadIndex, workerSrc }) => {
|
|
637
|
+
const viewerContainerRef = (0, react.useRef)(null);
|
|
638
|
+
const initialFilesRef = (0, react.useRef)(null);
|
|
639
|
+
const workerRef = (0, react.useRef)(null);
|
|
640
|
+
const loadingIndicesRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
641
|
+
const initialLoadDoneRef = (0, react.useRef)(false);
|
|
642
|
+
const [files, setFiles] = (0, react.useState)(() => {
|
|
643
|
+
const mapped = pdfs.map(createPdfFile);
|
|
644
|
+
initialFilesRef.current = mapped;
|
|
645
|
+
return mapped;
|
|
646
|
+
});
|
|
647
|
+
const [activeIndex, setActiveIndex] = (0, react.useState)(() => `${startIndex}`);
|
|
648
|
+
const [listVisible, setListVisible] = (0, react.useState)(true);
|
|
649
|
+
const [overlayMode, setOverlayMode] = (0, react.useState)(false);
|
|
650
|
+
const resolveIndex = (0, react.useCallback)((index) => {
|
|
651
|
+
const resolved = Number(index);
|
|
652
|
+
return Number.isNaN(resolved) ? 0 : resolved;
|
|
653
|
+
}, []);
|
|
654
|
+
(0, react.useEffect)(() => {
|
|
655
|
+
if (workerSrc) {
|
|
656
|
+
pdfjs_dist_build_pdf_mjs.GlobalWorkerOptions.workerSrc = workerSrc;
|
|
657
|
+
const worker = pdfjs_dist_build_pdf_mjs.PDFWorker.create({});
|
|
658
|
+
workerRef.current = worker;
|
|
659
|
+
return () => {
|
|
660
|
+
worker.destroy();
|
|
661
|
+
if (workerRef.current === worker) workerRef.current = null;
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
}, [workerSrc]);
|
|
665
|
+
const toggleList = (0, react.useCallback)(() => {
|
|
666
|
+
setListVisible((state) => !state);
|
|
667
|
+
}, []);
|
|
668
|
+
const setFileLoading = (0, react.useCallback)((index, isLoading) => {
|
|
669
|
+
setFiles((state) => state.map((pdfFile, pdfIndex) => {
|
|
670
|
+
if (pdfIndex !== index) return pdfFile;
|
|
671
|
+
return {
|
|
672
|
+
...pdfFile,
|
|
673
|
+
isLoading
|
|
674
|
+
};
|
|
675
|
+
}));
|
|
676
|
+
}, []);
|
|
677
|
+
const loadPdfDocument = (0, react.useCallback)(async (file, index) => {
|
|
678
|
+
if (file.pdfProxy) return;
|
|
679
|
+
if (loadingIndicesRef.current.has(index)) return;
|
|
680
|
+
loadingIndicesRef.current.add(index);
|
|
681
|
+
setFileLoading(index, true);
|
|
682
|
+
try {
|
|
683
|
+
const worker = workerRef.current;
|
|
684
|
+
const pdfDoc = await pdfjs_dist_build_pdf_mjs.getDocument({
|
|
685
|
+
url: file.source,
|
|
686
|
+
...worker ? { worker } : {}
|
|
687
|
+
}).promise;
|
|
688
|
+
setFiles((state) => state.map((pdfFile, pdfIndex) => {
|
|
689
|
+
if (pdfIndex !== index) return pdfFile;
|
|
690
|
+
return {
|
|
691
|
+
...pdfFile,
|
|
692
|
+
isLoading: false,
|
|
693
|
+
pdfProxy: pdfDoc
|
|
694
|
+
};
|
|
695
|
+
}));
|
|
696
|
+
} catch (_error) {
|
|
697
|
+
setFileLoading(index, false);
|
|
698
|
+
} finally {
|
|
699
|
+
loadingIndicesRef.current.delete(index);
|
|
700
|
+
}
|
|
701
|
+
}, [setFileLoading]);
|
|
702
|
+
const selectPdf = (0, react.useCallback)((nextIndex, file) => () => {
|
|
703
|
+
setActiveIndex(nextIndex);
|
|
704
|
+
if (lazyLoad && !file.pdfProxy) loadPdfDocument(file, Number(nextIndex));
|
|
705
|
+
if (overlayMode && listVisible) toggleList();
|
|
706
|
+
}, [
|
|
707
|
+
lazyLoad,
|
|
708
|
+
listVisible,
|
|
709
|
+
loadPdfDocument,
|
|
710
|
+
overlayMode,
|
|
711
|
+
toggleList
|
|
712
|
+
]);
|
|
713
|
+
const updateOverlayMode = (0, react.useCallback)((currentContainerWidth) => {
|
|
714
|
+
const containerWidth = currentContainerWidth || viewerContainerRef.current?.offsetWidth;
|
|
715
|
+
setOverlayMode((current) => {
|
|
716
|
+
if (containerWidth && containerWidth >= 330 && containerWidth <= 667 && !current) return true;
|
|
717
|
+
if (current && containerWidth && containerWidth > 667) return false;
|
|
718
|
+
return current;
|
|
719
|
+
});
|
|
720
|
+
}, []);
|
|
721
|
+
const onResizeEvent = (0, react.useCallback)(() => {
|
|
722
|
+
updateOverlayMode(viewerContainerRef.current?.offsetWidth);
|
|
723
|
+
}, [updateOverlayMode]);
|
|
724
|
+
const loadPdfDocuments = (0, react.useCallback)(() => {
|
|
725
|
+
(initialFilesRef.current ?? []).forEach(async (file, index) => {
|
|
726
|
+
await loadPdfDocument(file, index);
|
|
727
|
+
});
|
|
728
|
+
}, [loadPdfDocument]);
|
|
729
|
+
const rememberPosition = (0, react.useCallback)((index, position) => {
|
|
730
|
+
setFiles((state) => state.map((pdfFile, pdfIndex) => {
|
|
731
|
+
if (pdfIndex !== Number(index)) return pdfFile;
|
|
732
|
+
return {
|
|
733
|
+
...pdfFile,
|
|
734
|
+
...position
|
|
735
|
+
};
|
|
736
|
+
}));
|
|
737
|
+
}, []);
|
|
738
|
+
(0, react.useEffect)(() => {
|
|
739
|
+
window.addEventListener("resizeAutoZoom", onResizeEvent);
|
|
740
|
+
updateOverlayMode(viewerContainerRef.current?.offsetWidth);
|
|
741
|
+
if (!lazyLoad) loadPdfDocuments();
|
|
742
|
+
return () => {
|
|
743
|
+
window.removeEventListener("resizeAutoZoom", onResizeEvent);
|
|
744
|
+
};
|
|
745
|
+
}, [
|
|
746
|
+
lazyLoad,
|
|
747
|
+
loadPdfDocuments,
|
|
748
|
+
onResizeEvent,
|
|
749
|
+
updateOverlayMode
|
|
750
|
+
]);
|
|
751
|
+
(0, react.useEffect)(() => {
|
|
752
|
+
if (!lazyLoad) return;
|
|
753
|
+
const initialIndex = resolveIndex(initialLoadIndex ?? startIndex);
|
|
754
|
+
const nextFile = files[initialIndex];
|
|
755
|
+
if (!nextFile) return;
|
|
756
|
+
if (initialLoadDoneRef.current) return;
|
|
757
|
+
initialLoadDoneRef.current = true;
|
|
758
|
+
loadPdfDocument(nextFile, initialIndex);
|
|
759
|
+
}, [
|
|
760
|
+
files,
|
|
761
|
+
initialLoadIndex,
|
|
762
|
+
lazyLoad,
|
|
763
|
+
loadPdfDocument,
|
|
764
|
+
resolveIndex,
|
|
765
|
+
startIndex
|
|
766
|
+
]);
|
|
767
|
+
(0, react.useEffect)(() => {
|
|
768
|
+
if (!lazyLoad) return;
|
|
769
|
+
const nextIndex = resolveIndex(activeIndex);
|
|
770
|
+
const nextFile = files[nextIndex];
|
|
771
|
+
if (!nextFile) return;
|
|
772
|
+
loadPdfDocument(nextFile, nextIndex);
|
|
773
|
+
}, [
|
|
774
|
+
activeIndex,
|
|
775
|
+
files,
|
|
776
|
+
lazyLoad,
|
|
777
|
+
loadPdfDocument,
|
|
778
|
+
resolveIndex
|
|
779
|
+
]);
|
|
780
|
+
return {
|
|
781
|
+
activeIndex,
|
|
782
|
+
files,
|
|
783
|
+
i18nData,
|
|
784
|
+
listVisible,
|
|
785
|
+
overlayMode,
|
|
786
|
+
pdfToShow: files[Number(activeIndex)],
|
|
787
|
+
rememberPosition,
|
|
788
|
+
selectPdf,
|
|
789
|
+
toggleList,
|
|
790
|
+
viewerContainerRef
|
|
791
|
+
};
|
|
1431
792
|
};
|
|
1432
793
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
newScale = scale + 20;
|
|
1476
|
-
}
|
|
1477
|
-
else if (scale === 75 || scale === 125) {
|
|
1478
|
-
newScale = scale + 5;
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
newScale = scale + 10;
|
|
1482
|
-
}
|
|
1483
|
-
if (newScale > 1000)
|
|
1484
|
-
return;
|
|
1485
|
-
_this.setScale(newScale);
|
|
1486
|
-
};
|
|
1487
|
-
_this.zoomOut = function () {
|
|
1488
|
-
var scale = _this.state.scale;
|
|
1489
|
-
scale = scale === 125 ? scale : roundToNearest(scale, 10);
|
|
1490
|
-
var newScale;
|
|
1491
|
-
if (scale > 110 && scale !== 125) {
|
|
1492
|
-
newScale = scale - 20;
|
|
1493
|
-
}
|
|
1494
|
-
else if (scale === 75 || scale === 125) {
|
|
1495
|
-
newScale = scale - 5;
|
|
1496
|
-
}
|
|
1497
|
-
else {
|
|
1498
|
-
newScale = scale - 10;
|
|
1499
|
-
}
|
|
1500
|
-
if (newScale <= 0)
|
|
1501
|
-
return;
|
|
1502
|
-
_this.setScale(newScale);
|
|
1503
|
-
};
|
|
1504
|
-
_this.rotateRight = function () {
|
|
1505
|
-
var currentRotation = _this.pdfViewer.pagesRotation;
|
|
1506
|
-
_this.pdfViewer.pagesRotation = currentRotation + 90;
|
|
1507
|
-
};
|
|
1508
|
-
_this.rotateLeft = function () {
|
|
1509
|
-
var currentRotation = _this.pdfViewer.pagesRotation;
|
|
1510
|
-
_this.pdfViewer.pagesRotation = currentRotation - 90;
|
|
1511
|
-
};
|
|
1512
|
-
_this.download = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1513
|
-
var pdfDoc, url, filename, downloadByUrl, data, blob, e_1;
|
|
1514
|
-
var _this = this;
|
|
1515
|
-
return __generator(this, function (_a) {
|
|
1516
|
-
switch (_a.label) {
|
|
1517
|
-
case 0:
|
|
1518
|
-
pdfDoc = this.props.pdfDoc;
|
|
1519
|
-
url = pdfDoc._transport._params.url;
|
|
1520
|
-
filename = getPDFFileNameFromURL(url);
|
|
1521
|
-
downloadByUrl = function () {
|
|
1522
|
-
_this.downloadManager.downloadUrl(url, filename);
|
|
1523
|
-
};
|
|
1524
|
-
_a.label = 1;
|
|
1525
|
-
case 1:
|
|
1526
|
-
_a.trys.push([1, 3, , 4]);
|
|
1527
|
-
return [4, this.props.pdfDoc.getData()];
|
|
1528
|
-
case 2:
|
|
1529
|
-
data = _a.sent();
|
|
1530
|
-
blob = new Blob([data], { type: 'application/pdf' });
|
|
1531
|
-
this.downloadManager.download(blob, url, filename);
|
|
1532
|
-
return [3, 4];
|
|
1533
|
-
case 3:
|
|
1534
|
-
e_1 = _a.sent();
|
|
1535
|
-
downloadByUrl();
|
|
1536
|
-
return [3, 4];
|
|
1537
|
-
case 4: return [2];
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
}); };
|
|
1541
|
-
_this.container = React__default.createRef();
|
|
1542
|
-
_this.pdfViewer = null;
|
|
1543
|
-
_this.downloadManager = new DownloadManager({
|
|
1544
|
-
disableCreateObjectURL: false,
|
|
1545
|
-
});
|
|
1546
|
-
return _this;
|
|
1547
|
-
}
|
|
1548
|
-
PdfRenderer.prototype.componentDidMount = function () {
|
|
1549
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1550
|
-
var _a, autoZoom, pdfDoc;
|
|
1551
|
-
return __generator(this, function (_b) {
|
|
1552
|
-
_a = this.props, autoZoom = _a.autoZoom, pdfDoc = _a.pdfDoc;
|
|
1553
|
-
this.pdfViewer = new PDFViewer({
|
|
1554
|
-
container: this.container.current,
|
|
1555
|
-
eventBus: new EventBus(),
|
|
1556
|
-
});
|
|
1557
|
-
this.pdfViewer.setDocument(pdfDoc);
|
|
1558
|
-
if (autoZoom) {
|
|
1559
|
-
window.addEventListener('resizeAutoZoom', this.autoFitScale);
|
|
1560
|
-
}
|
|
1561
|
-
this.rePosition();
|
|
1562
|
-
this.setState(function () { return ({ isLoading: false }); });
|
|
1563
|
-
return [2];
|
|
1564
|
-
});
|
|
1565
|
-
});
|
|
1566
|
-
};
|
|
1567
|
-
PdfRenderer.prototype.componentDidUpdate = function (prevProps) {
|
|
1568
|
-
var _a = this.props, pdfDoc = _a.pdfDoc, pdfChangeHook = _a.pdfChangeHook;
|
|
1569
|
-
if (pdfDoc !== prevProps.pdfDoc) {
|
|
1570
|
-
if (typeof pdfChangeHook === 'function') {
|
|
1571
|
-
pdfChangeHook(String(prevProps.activeIndex), {
|
|
1572
|
-
zoom: this.state.scale,
|
|
1573
|
-
rotation: this.pdfViewer.pagesRotation,
|
|
1574
|
-
scrollTop: this.container.current && this.container.current.scrollTop,
|
|
1575
|
-
scrollLeft: this.container.current && this.container.current.scrollLeft,
|
|
1576
|
-
});
|
|
1577
|
-
}
|
|
1578
|
-
this.pdfViewer.setDocument(pdfDoc);
|
|
1579
|
-
this.rePosition();
|
|
1580
|
-
}
|
|
1581
|
-
};
|
|
1582
|
-
PdfRenderer.prototype.componentWillUnmount = function () {
|
|
1583
|
-
if (this.props.autoZoom) {
|
|
1584
|
-
window.removeEventListener('resizeAutoZoom', this.autoFitScale);
|
|
1585
|
-
}
|
|
1586
|
-
};
|
|
1587
|
-
PdfRenderer.prototype.rePosition = function () {
|
|
1588
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1589
|
-
var _a, autoZoom, zoom, rotation, scrollTop, scrollLeft;
|
|
1590
|
-
return __generator(this, function (_b) {
|
|
1591
|
-
switch (_b.label) {
|
|
1592
|
-
case 0:
|
|
1593
|
-
_a = this.props, autoZoom = _a.autoZoom, zoom = _a.zoom, rotation = _a.rotation, scrollTop = _a.scrollTop, scrollLeft = _a.scrollLeft;
|
|
1594
|
-
return [4, this.pdfViewer.firstPagePromise];
|
|
1595
|
-
case 1:
|
|
1596
|
-
_b.sent();
|
|
1597
|
-
if (rotation) {
|
|
1598
|
-
this.pdfViewer.pagesRotation = rotation;
|
|
1599
|
-
}
|
|
1600
|
-
if (zoom) {
|
|
1601
|
-
this.setScale(zoom);
|
|
1602
|
-
}
|
|
1603
|
-
else if (!zoom && autoZoom) {
|
|
1604
|
-
this.autoFitScale();
|
|
1605
|
-
}
|
|
1606
|
-
if (typeof scrollTop !== 'undefined') {
|
|
1607
|
-
this.setScrollTop(scrollTop);
|
|
1608
|
-
}
|
|
1609
|
-
if (typeof scrollLeft !== 'undefined') {
|
|
1610
|
-
this.setScrollLeft(scrollLeft);
|
|
1611
|
-
}
|
|
1612
|
-
return [2];
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
});
|
|
1616
|
-
};
|
|
1617
|
-
PdfRenderer.prototype.setScrollTop = function (scrollTop) {
|
|
1618
|
-
if (this.container.current) {
|
|
1619
|
-
this.container.current.scrollTop = scrollTop;
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
PdfRenderer.prototype.setScrollLeft = function (scrollLeft) {
|
|
1623
|
-
if (this.container.current) {
|
|
1624
|
-
this.container.current.scrollLeft = scrollLeft;
|
|
1625
|
-
}
|
|
1626
|
-
};
|
|
1627
|
-
PdfRenderer.prototype.render = function () {
|
|
1628
|
-
var _a = this.state, isLoading = _a.isLoading, scale = _a.scale;
|
|
1629
|
-
var _b = this.props, autoZoom = _b.autoZoom, controls = _b.controls, downloadBtn = _b.downloadBtn, i18nData = _b.i18nData;
|
|
1630
|
-
return (React__default.createElement("div", { className: "renderer-container" },
|
|
1631
|
-
controls && (React__default.createElement(I18nContext.Provider, { value: __assign(__assign({}, defaultI18n), i18nData) },
|
|
1632
|
-
React__default.createElement(PdfControls, { autoZoom: autoZoom, downloadBtn: downloadBtn, scale: scale, setScale: this.setScale, onDownload: this.download, onZoomIn: this.zoomIn, onZoomOut: this.zoomOut, onRotateRight: this.rotateRight, onRotateLeft: this.rotateLeft }))),
|
|
1633
|
-
React__default.createElement("div", { ref: this.container, className: "renderer-target-container " + (!controls ? 'no-controls' : '') + " " },
|
|
1634
|
-
React__default.createElement("div", { id: "viewer", className: "pdfViewer " + (isLoading ? 'hidden' : '') }))));
|
|
1635
|
-
};
|
|
1636
|
-
PdfRenderer.defaultProps = {
|
|
1637
|
-
activeIndex: '0',
|
|
1638
|
-
autoZoom: true,
|
|
1639
|
-
controls: true,
|
|
1640
|
-
downloadBtn: true,
|
|
1641
|
-
i18nData: defaultI18n,
|
|
1642
|
-
pdfChangeHook: null,
|
|
1643
|
-
rotation: 0,
|
|
1644
|
-
scrollTop: 0,
|
|
1645
|
-
scrollLeft: 0,
|
|
1646
|
-
};
|
|
1647
|
-
return PdfRenderer;
|
|
1648
|
-
}(React.PureComponent));
|
|
1649
|
-
|
|
1650
|
-
var PdfjsLib = require('pdfjs-dist/build/pdf');
|
|
1651
|
-
var initialState$1 = {
|
|
1652
|
-
files: [],
|
|
1653
|
-
activeIndex: '0',
|
|
1654
|
-
listVisible: true,
|
|
1655
|
-
overlayMode: false,
|
|
1656
|
-
};
|
|
1657
|
-
var PdfMultiViewer = (function (_super) {
|
|
1658
|
-
__extends(PdfMultiViewer, _super);
|
|
1659
|
-
function PdfMultiViewer(props) {
|
|
1660
|
-
var _this = _super.call(this, props) || this;
|
|
1661
|
-
_this.state = initialState$1;
|
|
1662
|
-
_this.changePdf = function (activeIndex, file) { return function () {
|
|
1663
|
-
var _a = _this.state, overlayMode = _a.overlayMode, listVisible = _a.listVisible;
|
|
1664
|
-
if (!file.pdfProxy)
|
|
1665
|
-
return;
|
|
1666
|
-
_this.setState(function () { return ({ activeIndex: activeIndex }); });
|
|
1667
|
-
if (overlayMode && listVisible)
|
|
1668
|
-
_this.toggleList();
|
|
1669
|
-
}; };
|
|
1670
|
-
_this.toggleList = function () {
|
|
1671
|
-
return _this.setState(function (state) { return ({ listVisible: !state.listVisible }); });
|
|
1672
|
-
};
|
|
1673
|
-
_this.setOverlayMode = function (currentContainerWidth) {
|
|
1674
|
-
var containerWidth = currentContainerWidth ||
|
|
1675
|
-
(_this.viewerContainer.current &&
|
|
1676
|
-
_this.viewerContainer.current.offsetWidth);
|
|
1677
|
-
var overlayMode = _this.state.overlayMode;
|
|
1678
|
-
if (containerWidth &&
|
|
1679
|
-
containerWidth >= 330 &&
|
|
1680
|
-
containerWidth <= 667 &&
|
|
1681
|
-
!overlayMode) {
|
|
1682
|
-
_this.setState(function () { return ({ overlayMode: true }); });
|
|
1683
|
-
}
|
|
1684
|
-
else if (overlayMode && containerWidth && containerWidth > 667) {
|
|
1685
|
-
_this.setState(function () { return ({ overlayMode: false }); });
|
|
1686
|
-
}
|
|
1687
|
-
};
|
|
1688
|
-
_this.getViewerContainerWidth = function () {
|
|
1689
|
-
return (_this.viewerContainer.current &&
|
|
1690
|
-
_this.viewerContainer.current.offsetWidth) ||
|
|
1691
|
-
undefined;
|
|
1692
|
-
};
|
|
1693
|
-
_this.onResizeEvent = function () { return _this.setOverlayMode(_this.getViewerContainerWidth()); };
|
|
1694
|
-
_this.rememberPosition = function (index, position) {
|
|
1695
|
-
return _this.setState(function (state) { return ({
|
|
1696
|
-
files: state.files.map(function (pdfFile, pdfIndex) {
|
|
1697
|
-
if (pdfIndex !== Number(index))
|
|
1698
|
-
return pdfFile;
|
|
1699
|
-
return __assign(__assign({}, pdfFile), position);
|
|
1700
|
-
}),
|
|
1701
|
-
}); });
|
|
1702
|
-
};
|
|
1703
|
-
PdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
1704
|
-
'//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.5.207/pdf.worker.js';
|
|
1705
|
-
_this.worker = new PdfjsLib.PDFWorker('pdf-viewer');
|
|
1706
|
-
_this.viewerContainer = React__default.createRef();
|
|
1707
|
-
_this.state.activeIndex = String(props.startIndex);
|
|
1708
|
-
_this.state.files = _this.props.pdfs.map(function (pdf) {
|
|
1709
|
-
return typeof pdf === 'object'
|
|
1710
|
-
? __assign(__assign({}, pdf), { pdfProxy: null }) : {
|
|
1711
|
-
source: pdf,
|
|
1712
|
-
pdfProxy: null,
|
|
1713
|
-
};
|
|
1714
|
-
});
|
|
1715
|
-
return _this;
|
|
1716
|
-
}
|
|
1717
|
-
PdfMultiViewer.prototype.loadPdfDocuments = function () {
|
|
1718
|
-
var _this = this;
|
|
1719
|
-
this.state.files.forEach(function (file, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1720
|
-
var pdfDoc;
|
|
1721
|
-
return __generator(this, function (_a) {
|
|
1722
|
-
switch (_a.label) {
|
|
1723
|
-
case 0: return [4, PdfjsLib.getDocument({
|
|
1724
|
-
url: file.source,
|
|
1725
|
-
worker: this.worker,
|
|
1726
|
-
}).promise];
|
|
1727
|
-
case 1:
|
|
1728
|
-
pdfDoc = _a.sent();
|
|
1729
|
-
this.setState(function (state) { return ({
|
|
1730
|
-
files: state.files.map(function (pdfFile, pdfIndex) {
|
|
1731
|
-
if (pdfIndex !== index)
|
|
1732
|
-
return pdfFile;
|
|
1733
|
-
return __assign(__assign({}, pdfFile), { pdfProxy: pdfDoc });
|
|
1734
|
-
}),
|
|
1735
|
-
}); });
|
|
1736
|
-
return [2];
|
|
1737
|
-
}
|
|
1738
|
-
});
|
|
1739
|
-
}); });
|
|
1740
|
-
};
|
|
1741
|
-
PdfMultiViewer.prototype.renderListItems = function () {
|
|
1742
|
-
var _this = this;
|
|
1743
|
-
var activeIndex = this.state.activeIndex;
|
|
1744
|
-
var i18nData = this.props.i18nData;
|
|
1745
|
-
return this.state.files.map(function (file, index) { return (React__default.createElement("li", { className: "pdf-viewer-list-item" + (file.pdfProxy ? ' loaded' : '') + (activeIndex === String(index) ? ' active' : ''), key: file.source, onClick: _this.changePdf(String(index), file) },
|
|
1746
|
-
file.title || file.source,
|
|
1747
|
-
file.pdfProxy && (React__default.createElement("div", { className: "pdf-viewer-list-item-meta" },
|
|
1748
|
-
i18nData.pages,
|
|
1749
|
-
": ",
|
|
1750
|
-
file.pdfProxy.numPages)))); });
|
|
1751
|
-
};
|
|
1752
|
-
PdfMultiViewer.prototype.componentDidMount = function () {
|
|
1753
|
-
window.addEventListener('resizeAutoZoom', this.onResizeEvent);
|
|
1754
|
-
this.setOverlayMode(this.getViewerContainerWidth());
|
|
1755
|
-
this.loadPdfDocuments();
|
|
1756
|
-
};
|
|
1757
|
-
PdfMultiViewer.prototype.componentWillUnmount = function () {
|
|
1758
|
-
window.removeEventListener('resizeAutoZoom', this.onResizeEvent);
|
|
1759
|
-
this.worker.destroy();
|
|
1760
|
-
};
|
|
1761
|
-
PdfMultiViewer.prototype.render = function () {
|
|
1762
|
-
var _a = this.state, activeIndex = _a.activeIndex, files = _a.files, listVisible = _a.listVisible, overlayMode = _a.overlayMode;
|
|
1763
|
-
var pdfToShow = files[Number(activeIndex)];
|
|
1764
|
-
var _b = this.props, autoZoom = _b.autoZoom, controls = _b.controls, i18nData = _b.i18nData;
|
|
1765
|
-
return (React__default.createElement("div", { className: "pdf-multi-viewer", ref: this.viewerContainer },
|
|
1766
|
-
React__default.createElement("div", { className: "pdf-multi-viewer-option-bar" },
|
|
1767
|
-
React__default.createElement("button", { className: "viewer-controls-button" + (listVisible ? ' toggled' : ''), onClick: this.toggleList },
|
|
1768
|
-
React__default.createElement("span", { className: "toggle-list-label" }, "Toggle list"))),
|
|
1769
|
-
React__default.createElement("ul", { className: "pdf-viewer-list" + (!listVisible ? ' hidden' : '') + (overlayMode ? ' overlay' : '') }, this.renderListItems()),
|
|
1770
|
-
React__default.createElement("div", { className: "pdf-viewer-multi-renderer" }, pdfToShow.pdfProxy && (React__default.createElement(PdfRenderer, { activeIndex: activeIndex, autoZoom: autoZoom, controls: controls, pdfDoc: pdfToShow.pdfProxy, i18nData: i18nData, pdfChangeHook: this.rememberPosition, zoom: pdfToShow.zoom, rotation: pdfToShow.rotation, scrollTop: pdfToShow.scrollTop, scrollLeft: pdfToShow.scrollLeft })))));
|
|
1771
|
-
};
|
|
1772
|
-
PdfMultiViewer.defaultProps = {
|
|
1773
|
-
autoZoom: true,
|
|
1774
|
-
controls: true,
|
|
1775
|
-
startIndex: '0',
|
|
1776
|
-
i18nData: {
|
|
1777
|
-
pages: 'Pages',
|
|
1778
|
-
},
|
|
1779
|
-
};
|
|
1780
|
-
return PdfMultiViewer;
|
|
1781
|
-
}(React.PureComponent));
|
|
1782
|
-
|
|
1783
|
-
var PdfjsLib$1 = require('pdfjs-dist/build/pdf');
|
|
1784
|
-
|
|
1785
|
-
exports.PdfMultiViewer = PdfMultiViewer;
|
|
1786
|
-
exports.PdfRenderer = PdfRenderer;
|
|
1787
|
-
exports.PdfjsLib = PdfjsLib$1;
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/components/PdfMultiViewer/PdfMultiViewer.tsx
|
|
796
|
+
const PdfMultiViewer = ({ pdfs, autoZoom = true, controls = true, icons, lazyLoad = true, initialLoadIndex, startIndex = "0", i18nData = {
|
|
797
|
+
loading: "Loading...",
|
|
798
|
+
pages: "Pages"
|
|
799
|
+
}, workerSrc }) => {
|
|
800
|
+
const { activeIndex, files, listVisible, overlayMode, pdfToShow, rememberPosition, selectPdf, toggleList, viewerContainerRef } = usePdfMultiViewer({
|
|
801
|
+
i18nData,
|
|
802
|
+
pdfs,
|
|
803
|
+
startIndex,
|
|
804
|
+
lazyLoad,
|
|
805
|
+
initialLoadIndex,
|
|
806
|
+
workerSrc
|
|
807
|
+
});
|
|
808
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PdfMultiViewerView_default, {
|
|
809
|
+
activeIndex,
|
|
810
|
+
autoZoom,
|
|
811
|
+
controls,
|
|
812
|
+
files,
|
|
813
|
+
iconStyles: buildIconStyles(icons),
|
|
814
|
+
i18nData,
|
|
815
|
+
listVisible,
|
|
816
|
+
onRememberPosition: rememberPosition,
|
|
817
|
+
onSelectPdf: selectPdf,
|
|
818
|
+
onToggleList: toggleList,
|
|
819
|
+
overlayMode,
|
|
820
|
+
pdfToShow,
|
|
821
|
+
viewerContainerRef
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
var PdfMultiViewer_default = PdfMultiViewer;
|
|
825
|
+
|
|
826
|
+
//#endregion
|
|
827
|
+
exports.PdfMultiViewer = PdfMultiViewer_default;
|
|
828
|
+
exports.PdfRenderer = PdfRenderer_default;
|
|
829
|
+
Object.defineProperty(exports, 'PdfjsLib', {
|
|
830
|
+
enumerable: true,
|
|
831
|
+
get: function () {
|
|
832
|
+
return pdfjs_dist_build_pdf_mjs;
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
//# sourceMappingURL=index.js.map
|