@progress/kendo-pdfviewer-common 0.6.5-develop.2 → 1.0.0-develop.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/annotations/annotation-editor-ui-manager.js +1 -1
- package/dist/es/annotations/annotation-layer.js +2 -7
- package/dist/es/annotations/editors/free-text-editor.js +0 -1
- package/dist/es/annotations/editors/highlight-editor.js +2 -3
- package/dist/es/annotations/editors/outliner.js +2 -3
- package/dist/es/annotations.js +1 -1
- package/dist/es/common/component.js +1 -0
- package/dist/es/common/core.js +1 -2
- package/dist/es/common/dom.js +26 -0
- package/dist/es/types/index.js +1 -0
- package/dist/es/utils.js +5 -29
- package/dist/es/widget/page.js +1 -0
- package/dist/es/widget/pdfviewer.js +218 -0
- package/dist/es2015/annotations/annotation-editor-ui-manager.js +1 -1
- package/dist/es2015/annotations/annotation-layer.js +2 -7
- package/dist/es2015/annotations/editors/free-text-editor.js +0 -1
- package/dist/es2015/annotations/editors/highlight-editor.js +2 -3
- package/dist/es2015/annotations/editors/outliner.js +2 -3
- package/dist/es2015/annotations.js +1 -1
- package/dist/es2015/common/component.js +1 -0
- package/dist/es2015/common/core.js +1 -2
- package/dist/es2015/common/dom.js +26 -0
- package/dist/es2015/types/index.js +1 -0
- package/dist/es2015/utils.js +5 -29
- package/dist/es2015/widget/page.js +1 -0
- package/dist/es2015/widget/pdfviewer.js +218 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.js +1 -1
- package/dist/npm/annotations/annotation-layer.js +2 -7
- package/dist/npm/annotations/editors/free-text-editor.js +0 -1
- package/dist/npm/annotations/editors/highlight-editor.js +2 -3
- package/dist/npm/annotations/editors/outliner.js +2 -3
- package/dist/npm/annotations.js +4 -4
- package/dist/npm/common/component.d.ts +1 -0
- package/dist/npm/common/component.js +1 -0
- package/dist/npm/common/core.js +1 -2
- package/dist/npm/common/dom.d.ts +10 -0
- package/dist/npm/common/dom.js +29 -1
- package/dist/npm/main.d.ts +2 -2
- package/dist/npm/types/index.d.ts +1 -0
- package/dist/npm/types/index.js +2 -0
- package/dist/npm/utils.d.ts +2 -10
- package/dist/npm/utils.js +12 -37
- package/dist/npm/widget/page.js +1 -0
- package/dist/npm/widget/pdfviewer.d.ts +26 -0
- package/dist/npm/widget/pdfviewer.js +218 -0
- package/package.json +27 -41
package/dist/es2015/utils.js
CHANGED
|
@@ -2,6 +2,8 @@ import { saveAs } from '@progress/kendo-file-saver';
|
|
|
2
2
|
import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
|
|
3
3
|
import { getDocument, TextLayer } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
4
4
|
import { LinkAnnotation } from './annotations';
|
|
5
|
+
import { createElement, scrollToPage } from './common/dom';
|
|
6
|
+
export { createElement, scrollToPage };
|
|
5
7
|
const MAX_CANVAS_WIDTH_HEIGHT_CHROME = 65535;
|
|
6
8
|
const MAX_CANVAS_AREA_CHROME_SAFARI = 268435456;
|
|
7
9
|
const MAX_CANVAS_WIDTH_HEIGHT_FIREFOX = 32767;
|
|
@@ -217,7 +219,7 @@ const createEmptyPage = (page, zoom, pdfDoc, rootElement) => {
|
|
|
217
219
|
};
|
|
218
220
|
const renderCanvas = (page, done, error) => {
|
|
219
221
|
const { canvasContext, viewport, scaleNum, canvas, pageElement } = createCanvas(page);
|
|
220
|
-
page.render({ canvasContext, viewport })
|
|
222
|
+
page.render({ canvasContext, viewport, canvas })
|
|
221
223
|
.promise.then(() => {
|
|
222
224
|
const printContent = new Image(Math.floor((viewport.width / scaleNum)), Math.floor((viewport.height / scaleNum)));
|
|
223
225
|
printContent.src = canvas.toDataURL();
|
|
@@ -230,14 +232,6 @@ const renderCanvas = (page, done, error) => {
|
|
|
230
232
|
.catch(error);
|
|
231
233
|
return viewport;
|
|
232
234
|
};
|
|
233
|
-
export const createElement = function (name, className, styles) {
|
|
234
|
-
const element = document.createElement(name);
|
|
235
|
-
if (className) {
|
|
236
|
-
element.className = className;
|
|
237
|
-
}
|
|
238
|
-
Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
|
|
239
|
-
return element;
|
|
240
|
-
};
|
|
241
235
|
export const transforms = {
|
|
242
236
|
'0': '',
|
|
243
237
|
'90': 'rotate(90deg) translateY(-100%)',
|
|
@@ -245,9 +239,9 @@ export const transforms = {
|
|
|
245
239
|
'270': 'rotate(270deg) translateX(-100%)'
|
|
246
240
|
};
|
|
247
241
|
export const renderPage = (page, emptyPage, error) => {
|
|
248
|
-
const { canvasContext, viewport, pageElement, styles, zoom, pdfDoc, rootElement } = emptyPage;
|
|
242
|
+
const { canvasContext, viewport, pageElement, styles, zoom, pdfDoc, rootElement, canvas } = emptyPage;
|
|
249
243
|
page._pageInfo.renderInProgress = true;
|
|
250
|
-
page.render({ canvasContext, viewport })
|
|
244
|
+
page.render({ canvasContext, viewport, canvas })
|
|
251
245
|
.promise.then(() => {
|
|
252
246
|
page.getTextContent().then((textContent) => {
|
|
253
247
|
const textLayer = createElement('div', 'k-text-layer', styles);
|
|
@@ -364,24 +358,6 @@ export const calculateZoomLevel = (zoomLevel, zoomLevelType, currentZoom, dom) =
|
|
|
364
358
|
}
|
|
365
359
|
return calculatedZoomLevel;
|
|
366
360
|
};
|
|
367
|
-
/**
|
|
368
|
-
* Scrolls the PDFViewer document to the passed page number.
|
|
369
|
-
*
|
|
370
|
-
* @param rootElement The root HTML element of the PDFViewer component.
|
|
371
|
-
* @param pageNumber The page number.
|
|
372
|
-
*/
|
|
373
|
-
export const scrollToPage = (rootElement, pageNumber) => {
|
|
374
|
-
const pages = rootElement.querySelectorAll('.k-page');
|
|
375
|
-
const page = pages[0];
|
|
376
|
-
if (page instanceof HTMLDivElement) {
|
|
377
|
-
const top = (page.offsetHeight + page.offsetTop) *
|
|
378
|
-
Math.max(0, Math.min(pageNumber, pages.length - 1));
|
|
379
|
-
const scrollElement = page.closest('.k-pdf-viewer-canvas');
|
|
380
|
-
if (scrollElement) {
|
|
381
|
-
scrollElement.scrollTo({ top, behavior: 'auto' });
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
361
|
/**
|
|
386
362
|
* A function which gives you the page number of the document according to the scroll position.
|
|
387
363
|
*
|
|
@@ -572,6 +572,7 @@ export class Page extends Component {
|
|
|
572
572
|
canvasContext: canvasContext,
|
|
573
573
|
// transform,
|
|
574
574
|
viewport,
|
|
575
|
+
canvas,
|
|
575
576
|
annotationMode: __classPrivateFieldGet(this, _Page_annotationMode, "f"),
|
|
576
577
|
// optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
577
578
|
annotationCanvasMap: this._annotationCanvasMap,
|
|
@@ -47,6 +47,7 @@ export class PdfViewer extends Component {
|
|
|
47
47
|
maxZoom: 4,
|
|
48
48
|
zoomRate: 0.25,
|
|
49
49
|
zoomLevel: DEFAULT_ZOOM_LEVEL,
|
|
50
|
+
pinchToZoom: true,
|
|
50
51
|
zoomBeforePrint: false,
|
|
51
52
|
zoomLevelForPrint: 3,
|
|
52
53
|
renderForms: false,
|
|
@@ -148,6 +149,14 @@ export class PdfViewer extends Component {
|
|
|
148
149
|
this.state = {};
|
|
149
150
|
this.pdfDocument = null;
|
|
150
151
|
this.pages = [];
|
|
152
|
+
// Pinch-to-zoom state
|
|
153
|
+
this._isCtrlKeyDown = false;
|
|
154
|
+
this._isPinching = false;
|
|
155
|
+
this._touchInfo = null;
|
|
156
|
+
this._wheelUnusedFactor = 1;
|
|
157
|
+
this._touchUnusedFactor = 1;
|
|
158
|
+
this._pendingPinchFactor = 1;
|
|
159
|
+
this._pinchAC = null;
|
|
151
160
|
this.triggerError = (e) => {
|
|
152
161
|
this.trigger(ERROR, {
|
|
153
162
|
error: e
|
|
@@ -223,6 +232,18 @@ export class PdfViewer extends Component {
|
|
|
223
232
|
}
|
|
224
233
|
e.preventDefault();
|
|
225
234
|
e.stopPropagation();
|
|
235
|
+
if (this.options.pinchToZoom && this._isTrackpadPinch(e)) {
|
|
236
|
+
const scaleFactor = Math.exp(-e.deltaY / 100);
|
|
237
|
+
const newScaleFactor = this._accumulateFactor(this.state.zoomLevel, scaleFactor, '_wheelUnusedFactor');
|
|
238
|
+
if (newScaleFactor === 1) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const zoomLevel = this.state.zoomLevel * newScaleFactor;
|
|
242
|
+
this.triggerZoomStart({ zoomLevel });
|
|
243
|
+
this.zoom({ zoomLevel });
|
|
244
|
+
this.triggerZoomEnd({ zoomLevel });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
226
247
|
const wheelDelta = mousewheelDelta(e);
|
|
227
248
|
const zoomModifier = wheelDelta < 0 ? 1 : -1;
|
|
228
249
|
const zoomLevel = this.state.zoomLevel + (zoomModifier * this.options.zoomRate);
|
|
@@ -236,6 +257,102 @@ export class PdfViewer extends Component {
|
|
|
236
257
|
zoomLevel: zoomLevel
|
|
237
258
|
});
|
|
238
259
|
};
|
|
260
|
+
this._onKeyDown = (e) => {
|
|
261
|
+
if (e.key === 'Control') {
|
|
262
|
+
this._isCtrlKeyDown = true;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
this._onKeyUp = (e) => {
|
|
266
|
+
if (e.key === 'Control') {
|
|
267
|
+
this._isCtrlKeyDown = false;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
this._onGestureEvent = (e) => {
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
};
|
|
273
|
+
this._onTouchStart = (e) => {
|
|
274
|
+
var _a;
|
|
275
|
+
if (!this.options.pinchToZoom) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (e.touches.length !== 2) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
// Prevent browser-native pinch-zoom from starting (required for iOS Safari
|
|
282
|
+
// where the gesture decision is made at touchstart time)
|
|
283
|
+
e.preventDefault();
|
|
284
|
+
const touch0 = e.touches[0];
|
|
285
|
+
const touch1 = e.touches[1];
|
|
286
|
+
this._touchInfo = {
|
|
287
|
+
touch0X: touch0.screenX,
|
|
288
|
+
touch0Y: touch0.screenY,
|
|
289
|
+
touch1X: touch1.screenX,
|
|
290
|
+
touch1Y: touch1.screenY
|
|
291
|
+
};
|
|
292
|
+
this._pendingPinchFactor = 1;
|
|
293
|
+
this._touchUnusedFactor = 1;
|
|
294
|
+
const documentContainer = this.getDocumentContainer();
|
|
295
|
+
if (!documentContainer) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const signal = (_a = this._pinchAC) === null || _a === void 0 ? void 0 : _a.signal;
|
|
299
|
+
documentContainer.addEventListener('touchmove', this._onTouchMove, { passive: false, signal });
|
|
300
|
+
documentContainer.addEventListener('touchend', this._onTouchEnd, { signal });
|
|
301
|
+
documentContainer.addEventListener('touchcancel', this._onTouchEnd, { signal });
|
|
302
|
+
};
|
|
303
|
+
this._onTouchMove = (e) => {
|
|
304
|
+
if (!this._touchInfo || e.touches.length !== 2) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
e.stopPropagation();
|
|
309
|
+
const touch0 = e.touches[0];
|
|
310
|
+
const touch1 = e.touches[1];
|
|
311
|
+
const prevGapX = this._touchInfo.touch1X - this._touchInfo.touch0X;
|
|
312
|
+
const prevGapY = this._touchInfo.touch1Y - this._touchInfo.touch0Y;
|
|
313
|
+
const currGapX = touch1.screenX - touch0.screenX;
|
|
314
|
+
const currGapY = touch1.screenY - touch0.screenY;
|
|
315
|
+
const prevDist = Math.hypot(prevGapX, prevGapY) || 1;
|
|
316
|
+
const currDist = Math.hypot(currGapX, currGapY) || 1;
|
|
317
|
+
if (Math.abs(prevDist - currDist) <= this._minTouchDistanceToPinch) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (!this._isPinching) {
|
|
321
|
+
this._isPinching = true;
|
|
322
|
+
// Suppress panning during pinch
|
|
323
|
+
this.disableScrollerEventsTracking();
|
|
324
|
+
// Fire zoom start on first pinch movement
|
|
325
|
+
this.triggerZoomStart({ zoomLevel: this.state.zoomLevel });
|
|
326
|
+
}
|
|
327
|
+
this._applyPinchTransform(prevDist, currDist);
|
|
328
|
+
// Update stored positions for next move
|
|
329
|
+
this._touchInfo = {
|
|
330
|
+
touch0X: touch0.screenX,
|
|
331
|
+
touch0Y: touch0.screenY,
|
|
332
|
+
touch1X: touch1.screenX,
|
|
333
|
+
touch1Y: touch1.screenY
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
this._onTouchEnd = (e) => {
|
|
337
|
+
if (e.touches.length >= 2) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const documentContainer = this.getDocumentContainer();
|
|
341
|
+
if (documentContainer) {
|
|
342
|
+
documentContainer.removeEventListener('touchmove', this._onTouchMove);
|
|
343
|
+
documentContainer.removeEventListener('touchend', this._onTouchEnd);
|
|
344
|
+
documentContainer.removeEventListener('touchcancel', this._onTouchEnd);
|
|
345
|
+
}
|
|
346
|
+
if (this._isPinching) {
|
|
347
|
+
this._clearPinchTransform();
|
|
348
|
+
const zoomLevel = clamp(this.state.zoomLevel * this._pendingPinchFactor, this.options.minZoom, this.options.maxZoom);
|
|
349
|
+
this.zoom({ zoomLevel });
|
|
350
|
+
this.triggerZoomEnd({ zoomLevel });
|
|
351
|
+
// Re-enable panning
|
|
352
|
+
this.enableScrollerEventsTracking();
|
|
353
|
+
}
|
|
354
|
+
this._resetPinchState();
|
|
355
|
+
};
|
|
239
356
|
this.extendOptions(options);
|
|
240
357
|
this.throwIfInvalidOptions();
|
|
241
358
|
this.wrapper = this.element;
|
|
@@ -362,6 +479,7 @@ export class PdfViewer extends Component {
|
|
|
362
479
|
}
|
|
363
480
|
bindEvents() {
|
|
364
481
|
this.bindPagesWheel();
|
|
482
|
+
this.bindPinchToZoomEvents();
|
|
365
483
|
}
|
|
366
484
|
bindPagesWheel() {
|
|
367
485
|
const documentContainer = this.getDocumentContainer();
|
|
@@ -381,6 +499,7 @@ export class PdfViewer extends Component {
|
|
|
381
499
|
}
|
|
382
500
|
unbindEvents() {
|
|
383
501
|
this.unbindPagesWheel();
|
|
502
|
+
this.unbindPinchToZoomEvents();
|
|
384
503
|
}
|
|
385
504
|
unbindPagesWheel() {
|
|
386
505
|
const documentContainer = this.getDocumentContainer();
|
|
@@ -1339,6 +1458,105 @@ export class PdfViewer extends Component {
|
|
|
1339
1458
|
}
|
|
1340
1459
|
setScaleFactor(scaleFactor) {
|
|
1341
1460
|
this.element.style.setProperty('--scale-factor', String(scaleFactor * PixelsPerInch.PDF_TO_CSS_UNITS));
|
|
1461
|
+
this.element.style.setProperty('--total-scale-factor', String(scaleFactor * PixelsPerInch.PDF_TO_CSS_UNITS));
|
|
1462
|
+
this.element.style.setProperty('--scale-round-x', '1px');
|
|
1463
|
+
this.element.style.setProperty('--scale-round-y', '1px');
|
|
1464
|
+
}
|
|
1465
|
+
_isTrackpadPinch(e) {
|
|
1466
|
+
// Trackpad pinch gestures generate wheel events with synthetic ctrlKey=true.
|
|
1467
|
+
// Real Ctrl+scroll has ctrlKey=true but the physical key is down.
|
|
1468
|
+
// Heuristic: ctrlKey is set, physical Ctrl is NOT pressed, pixel-level delta,
|
|
1469
|
+
// deltaX is 0 (no horizontal scroll), and the scale factor is small.
|
|
1470
|
+
if (this._isCtrlKeyDown) {
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
if (e.deltaMode !== WheelEvent.DOM_DELTA_PIXEL) {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
if (e.deltaX !== 0) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
const scaleFactor = Math.exp(-e.deltaY / 100);
|
|
1480
|
+
if (Math.abs(scaleFactor - 1) >= 0.05) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
_accumulateFactor(previousScale, factor, prop) {
|
|
1486
|
+
if (factor === 1) {
|
|
1487
|
+
return 1;
|
|
1488
|
+
}
|
|
1489
|
+
if ((this[prop] > 1 && factor < 1) || (this[prop] < 1 && factor > 1)) {
|
|
1490
|
+
this[prop] = 1;
|
|
1491
|
+
}
|
|
1492
|
+
const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
|
|
1493
|
+
this[prop] = factor / (newFactor || factor);
|
|
1494
|
+
return newFactor || 1;
|
|
1495
|
+
}
|
|
1496
|
+
bindPinchToZoomEvents() {
|
|
1497
|
+
if (!this.options.pinchToZoom) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
document.addEventListener('keydown', this._onKeyDown);
|
|
1501
|
+
document.addEventListener('keyup', this._onKeyUp);
|
|
1502
|
+
const documentContainer = this.getDocumentContainer();
|
|
1503
|
+
if (!documentContainer) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
this._pinchAC = new AbortController();
|
|
1507
|
+
const signal = this._pinchAC.signal;
|
|
1508
|
+
// Prevent the browser from handling pinch-zoom natively
|
|
1509
|
+
documentContainer.style.touchAction = 'none';
|
|
1510
|
+
documentContainer.addEventListener('touchstart', this._onTouchStart, { passive: false, signal });
|
|
1511
|
+
// iOS Safari fires proprietary GestureEvents for pinch gestures.
|
|
1512
|
+
// Suppressing them prevents the browser from zooming the page.
|
|
1513
|
+
documentContainer.addEventListener('gesturestart', this._onGestureEvent, { signal });
|
|
1514
|
+
documentContainer.addEventListener('gesturechange', this._onGestureEvent, { signal });
|
|
1515
|
+
}
|
|
1516
|
+
unbindPinchToZoomEvents() {
|
|
1517
|
+
document.removeEventListener('keydown', this._onKeyDown);
|
|
1518
|
+
document.removeEventListener('keyup', this._onKeyUp);
|
|
1519
|
+
this._isCtrlKeyDown = false;
|
|
1520
|
+
const documentContainer = this.getDocumentContainer();
|
|
1521
|
+
if (documentContainer) {
|
|
1522
|
+
documentContainer.style.touchAction = '';
|
|
1523
|
+
}
|
|
1524
|
+
if (this._pinchAC) {
|
|
1525
|
+
this._pinchAC.abort();
|
|
1526
|
+
this._pinchAC = null;
|
|
1527
|
+
}
|
|
1528
|
+
this._resetPinchState();
|
|
1529
|
+
}
|
|
1530
|
+
_resetPinchState() {
|
|
1531
|
+
this._isPinching = false;
|
|
1532
|
+
this._touchInfo = null;
|
|
1533
|
+
this._touchUnusedFactor = 1;
|
|
1534
|
+
this._wheelUnusedFactor = 1;
|
|
1535
|
+
this._pendingPinchFactor = 1;
|
|
1536
|
+
}
|
|
1537
|
+
get _minTouchDistanceToPinch() {
|
|
1538
|
+
return 32 / (window.devicePixelRatio || 1);
|
|
1539
|
+
}
|
|
1540
|
+
_applyPinchTransform(prevDist, currDist) {
|
|
1541
|
+
const rawFactor = currDist / prevDist;
|
|
1542
|
+
const newFactor = this._accumulateFactor(this.state.zoomLevel, rawFactor, '_touchUnusedFactor');
|
|
1543
|
+
this._pendingPinchFactor *= newFactor;
|
|
1544
|
+
// Clamp the visual factor to the allowed zoom range
|
|
1545
|
+
const targetZoom = this.state.zoomLevel * this._pendingPinchFactor;
|
|
1546
|
+
const clampedZoom = clamp(targetZoom, this.options.minZoom, this.options.maxZoom);
|
|
1547
|
+
const visualFactor = clampedZoom / this.state.zoomLevel;
|
|
1548
|
+
const pagesContainer = this.getPagesContainer();
|
|
1549
|
+
if (pagesContainer) {
|
|
1550
|
+
pagesContainer.style.transform = `scale(${visualFactor})`;
|
|
1551
|
+
pagesContainer.style.transformOrigin = 'center top';
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
_clearPinchTransform() {
|
|
1555
|
+
const pagesContainer = this.getPagesContainer();
|
|
1556
|
+
if (pagesContainer) {
|
|
1557
|
+
pagesContainer.style.transform = '';
|
|
1558
|
+
pagesContainer.style.transformOrigin = '';
|
|
1559
|
+
}
|
|
1342
1560
|
}
|
|
1343
1561
|
activatePageNumber(pageNumber) {
|
|
1344
1562
|
const page = this.getPageByNumber(pageNumber);
|
|
@@ -872,7 +872,7 @@ class AnnotationEditorUIManager {
|
|
|
872
872
|
case pdf_mjs_1.AnnotationEditorParamsType.CREATE:
|
|
873
873
|
this.currentLayer.addNewEditor();
|
|
874
874
|
return;
|
|
875
|
-
case pdf_mjs_1.AnnotationEditorParamsType.
|
|
875
|
+
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_COLOR:
|
|
876
876
|
// this.#mainHighlightColorPicker?.updateColor(value);
|
|
877
877
|
break;
|
|
878
878
|
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
|
|
@@ -1920,9 +1920,7 @@ class PopupElement {
|
|
|
1920
1920
|
const popup = (tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, document.createElement("div"), "f"));
|
|
1921
1921
|
popup.className = "popup";
|
|
1922
1922
|
if (tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")) {
|
|
1923
|
-
const baseColor = (popup.style.outlineColor = pdf_mjs_1.Util.makeHexColor(
|
|
1924
|
-
// @ts-expect-error TS(2556):
|
|
1925
|
-
...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")));
|
|
1923
|
+
const baseColor = (popup.style.outlineColor = pdf_mjs_1.Util.makeHexColor(...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")));
|
|
1926
1924
|
if (
|
|
1927
1925
|
// (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
1928
1926
|
CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
|
|
@@ -1934,9 +1932,7 @@ class PopupElement {
|
|
|
1934
1932
|
// TODO: Use color-mix when it's supported everywhere.
|
|
1935
1933
|
// Enlighten the color.
|
|
1936
1934
|
const BACKGROUND_ENLIGHT = 0.7;
|
|
1937
|
-
popup.style.backgroundColor = pdf_mjs_1.Util.makeHexColor(
|
|
1938
|
-
// @ts-expect-error TS(2556):
|
|
1939
|
-
...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
|
|
1935
|
+
popup.style.backgroundColor = pdf_mjs_1.Util.makeHexColor(...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
|
|
1940
1936
|
}
|
|
1941
1937
|
}
|
|
1942
1938
|
const header = document.createElement("span");
|
|
@@ -1957,7 +1953,6 @@ class PopupElement {
|
|
|
1957
1953
|
}
|
|
1958
1954
|
const html = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get);
|
|
1959
1955
|
if (html) {
|
|
1960
|
-
// @ts-expect-error TS(2556):
|
|
1961
1956
|
pdf_mjs_1.XfaLayer.render({
|
|
1962
1957
|
xfaHtml: html,
|
|
1963
1958
|
intent: "richText",
|
|
@@ -533,7 +533,6 @@ class FreeTextEditor extends annotation_editor_1.AnnotationEditor {
|
|
|
533
533
|
}
|
|
534
534
|
const editor = super.deserialize(data, parent, uiManager);
|
|
535
535
|
tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_fontSize, data.fontSize, "f");
|
|
536
|
-
// @ts-expect-error TS(2556):
|
|
537
536
|
tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_color, pdf_mjs_1.Util.makeHexColor(...data.color), "f");
|
|
538
537
|
tslib_1.__classPrivateFieldSet(editor, _FreeTextEditor_content, tslib_1.__classPrivateFieldGet(_a, _a, "m", _FreeTextEditor_deserializeContent).call(_a, data.value), "f");
|
|
539
538
|
editor.annotationElementId = data.id || null;
|
|
@@ -126,7 +126,7 @@ class HighlightEditor extends annotation_editor_1.AnnotationEditor {
|
|
|
126
126
|
/** @inheritdoc */
|
|
127
127
|
static updateDefaultParams(type, value) {
|
|
128
128
|
switch (type) {
|
|
129
|
-
case pdf_mjs_1.AnnotationEditorParamsType.
|
|
129
|
+
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_COLOR:
|
|
130
130
|
_a._defaultColor = value;
|
|
131
131
|
break;
|
|
132
132
|
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
|
|
@@ -157,7 +157,7 @@ class HighlightEditor extends annotation_editor_1.AnnotationEditor {
|
|
|
157
157
|
static get defaultPropertiesToUpdate() {
|
|
158
158
|
return [
|
|
159
159
|
[
|
|
160
|
-
pdf_mjs_1.AnnotationEditorParamsType.
|
|
160
|
+
pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_COLOR,
|
|
161
161
|
_a._defaultColor
|
|
162
162
|
],
|
|
163
163
|
[
|
|
@@ -404,7 +404,6 @@ class HighlightEditor extends annotation_editor_1.AnnotationEditor {
|
|
|
404
404
|
static deserialize(data, parent, uiManager) {
|
|
405
405
|
const editor = super.deserialize(data, parent, uiManager);
|
|
406
406
|
const { rect: [blX, blY, trX, trY], color, quadPoints } = data;
|
|
407
|
-
// @ts-expect-error TS()
|
|
408
407
|
editor.color = pdf_mjs_1.Util.makeHexColor(...color);
|
|
409
408
|
tslib_1.__classPrivateFieldSet(editor, _HighlightEditor_opacity, data.opacity, "f");
|
|
410
409
|
const [pageWidth, pageHeight] = editor.pageDimensions;
|
|
@@ -726,9 +726,8 @@ _FreeHighlightOutline_box = new WeakMap(), _FreeHighlightOutline_bbox = new Weak
|
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
728
|
else {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
...outline.slice(i, i + 6));
|
|
729
|
+
// pdfjs-dist legacy types declare bezierBoundingBox as void/9-arg but it returns the bbox array at runtime
|
|
730
|
+
const bbox = pdf_mjs_1.Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6));
|
|
732
731
|
minX = Math.min(minX, bbox[0]);
|
|
733
732
|
minY = Math.min(minY, bbox[1]);
|
|
734
733
|
maxX = Math.max(maxX, bbox[2]);
|
package/dist/npm/annotations.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LinkAnnotation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const dom_1 = require("./common/dom");
|
|
5
5
|
class Annotation {
|
|
6
6
|
constructor(container, viewport, annotation, pdfDoc, zoom, rootElement) {
|
|
7
7
|
this.container = container;
|
|
@@ -43,7 +43,7 @@ class LinkAnnotation extends Annotation {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
goToPage(pageNumber) {
|
|
46
|
-
(0,
|
|
46
|
+
(0, dom_1.scrollToPage)(this.rootElement, pageNumber);
|
|
47
47
|
}
|
|
48
48
|
renderAnnotation() {
|
|
49
49
|
const annotation = this.annotation, viewport = this.viewport, rect = annotation.rect, boundingRect = [
|
|
@@ -52,12 +52,12 @@ class LinkAnnotation extends Annotation {
|
|
|
52
52
|
], rawHeight = viewport.rawDims.pageHeight;
|
|
53
53
|
const left = Math.min(boundingRect[0][0], boundingRect[1][0]) * this.zoom, top = (rawHeight - Math.max(boundingRect[0][1], boundingRect[1][1])) * this.zoom, width = (boundingRect[1][0] - boundingRect[0][0]) * this.zoom, height = (boundingRect[1][1] - boundingRect[0][1]) * this.zoom;
|
|
54
54
|
const url = annotation.url || (annotation.dest && `#${encodeURI(annotation.dest)}`);
|
|
55
|
-
const annotationElement = (0,
|
|
55
|
+
const annotationElement = (0, dom_1.createElement)('span', '', {
|
|
56
56
|
position: 'absolute',
|
|
57
57
|
left: left + 'pt',
|
|
58
58
|
top: top + 'pt'
|
|
59
59
|
});
|
|
60
|
-
const linkElement = this.linkElement = (0,
|
|
60
|
+
const linkElement = this.linkElement = (0, dom_1.createElement)('a', '', {
|
|
61
61
|
width: width + 'pt',
|
|
62
62
|
height: height + 'pt',
|
|
63
63
|
display: 'inline-block',
|
package/dist/npm/common/core.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPromise = exports.mousewheelDelta = exports.toClassSelector = exports.toPixel = exports.convertToHtml = exports.noop = exports.hasValue = exports.isNotNull = exports.isDefined = exports.toArray = exports.isString = exports.isFunction = exports.deepExtend = exports.isDotNetObject = exports.isDomElement = exports.isHtmlElement = exports.isObject = exports.extend = void 0;
|
|
4
|
-
const component_1 = require("./component");
|
|
5
4
|
// @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
|
|
6
5
|
const extend = (...args) => Object.assign(...args);
|
|
7
6
|
exports.extend = extend;
|
|
@@ -26,7 +25,7 @@ const deepExtend = (target, ...sources) => {
|
|
|
26
25
|
if (key === '__proto__' || key === 'constructor') {
|
|
27
26
|
continue;
|
|
28
27
|
}
|
|
29
|
-
if (source[key]
|
|
28
|
+
if (source[key] && source[key].__isComponent) {
|
|
30
29
|
target[key] = source[key];
|
|
31
30
|
}
|
|
32
31
|
else if ((0, exports.isHtmlElement)(source[key])) {
|
package/dist/npm/common/dom.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export declare const addClass: (className: any, element: any) => void;
|
|
2
2
|
export declare const removeClass: (className: any, element: any) => void;
|
|
3
3
|
export declare const hasClass: (className: any, element: any) => boolean;
|
|
4
|
+
export declare const createElement: <T>(name: string, className: string, styles: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}) => T;
|
|
7
|
+
/**
|
|
8
|
+
* Scrolls the PDFViewer document to the passed page number.
|
|
9
|
+
*
|
|
10
|
+
* @param rootElement The root HTML element of the PDFViewer component.
|
|
11
|
+
* @param pageNumber The page number.
|
|
12
|
+
*/
|
|
13
|
+
export declare const scrollToPage: (rootElement: HTMLElement, pageNumber: number) => void;
|
package/dist/npm/common/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasClass = exports.removeClass = exports.addClass = void 0;
|
|
3
|
+
exports.scrollToPage = exports.createElement = exports.hasClass = exports.removeClass = exports.addClass = void 0;
|
|
4
4
|
const addClass = (className, element) => {
|
|
5
5
|
element.classList.add(className);
|
|
6
6
|
};
|
|
@@ -15,3 +15,31 @@ const hasClass = (className, element) => {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
exports.hasClass = hasClass;
|
|
18
|
+
const createElement = function (name, className, styles) {
|
|
19
|
+
const element = document.createElement(name);
|
|
20
|
+
if (className) {
|
|
21
|
+
element.className = className;
|
|
22
|
+
}
|
|
23
|
+
Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
|
|
24
|
+
return element;
|
|
25
|
+
};
|
|
26
|
+
exports.createElement = createElement;
|
|
27
|
+
/**
|
|
28
|
+
* Scrolls the PDFViewer document to the passed page number.
|
|
29
|
+
*
|
|
30
|
+
* @param rootElement The root HTML element of the PDFViewer component.
|
|
31
|
+
* @param pageNumber The page number.
|
|
32
|
+
*/
|
|
33
|
+
const scrollToPage = (rootElement, pageNumber) => {
|
|
34
|
+
const pages = rootElement.querySelectorAll('.k-page');
|
|
35
|
+
const page = pages[0];
|
|
36
|
+
if (page instanceof HTMLDivElement) {
|
|
37
|
+
const top = (page.offsetHeight + page.offsetTop) *
|
|
38
|
+
Math.max(0, Math.min(pageNumber, pages.length - 1));
|
|
39
|
+
const scrollElement = page.closest('.k-pdf-viewer-canvas');
|
|
40
|
+
if (scrollElement) {
|
|
41
|
+
scrollElement.scrollTo({ top, behavior: 'auto' });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.scrollToPage = scrollToPage;
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export * from './search';
|
|
|
3
3
|
export * from './utils';
|
|
4
4
|
export * from './widget/pdfviewer';
|
|
5
5
|
export * from './enums/PdfViewerInteractionMode';
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
6
|
+
export type { TypedArray } from "./types";
|
|
7
|
+
export type { PDFDocumentProxy } from 'pdfjs-dist/types/src/display/api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
package/dist/npm/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SaveOptions } from '@progress/kendo-file-saver';
|
|
2
2
|
import { PDFPageProxy, PDFDocumentProxy } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
3
3
|
import { TypedArray } from "pdfjs-dist/types/src/display/api";
|
|
4
|
+
import { createElement, scrollToPage } from './common/dom';
|
|
5
|
+
export { createElement, scrollToPage };
|
|
4
6
|
/**
|
|
5
7
|
* @hidden
|
|
6
8
|
*/
|
|
@@ -75,9 +77,6 @@ export declare const reloadDocument: (params: PDFReloadParameters) => void;
|
|
|
75
77
|
* @hidden
|
|
76
78
|
*/
|
|
77
79
|
export declare const print: (pages: PDFPageProxy[], done: () => void, error: ErrorFn) => void;
|
|
78
|
-
export declare const createElement: <T>(name: string, className: string, styles: {
|
|
79
|
-
[key: string]: string;
|
|
80
|
-
}) => T;
|
|
81
80
|
export declare const transforms: {
|
|
82
81
|
[rotation: string]: string;
|
|
83
82
|
};
|
|
@@ -94,13 +93,6 @@ export declare const goToPreviousSearchMatch: (ref: any) => void;
|
|
|
94
93
|
* @hidden
|
|
95
94
|
*/
|
|
96
95
|
export declare const calculateZoomLevel: (zoomLevel: number, zoomLevelType: string, currentZoom: number, dom: HTMLDivElement) => number;
|
|
97
|
-
/**
|
|
98
|
-
* Scrolls the PDFViewer document to the passed page number.
|
|
99
|
-
*
|
|
100
|
-
* @param rootElement The root HTML element of the PDFViewer component.
|
|
101
|
-
* @param pageNumber The page number.
|
|
102
|
-
*/
|
|
103
|
-
export declare const scrollToPage: (rootElement: HTMLElement, pageNumber: number) => void;
|
|
104
96
|
/**
|
|
105
97
|
* A function which gives you the page number of the document according to the scroll position.
|
|
106
98
|
*
|