@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/npm/utils.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addAdoptedStylesheet = exports.getDevicePixelRatio = exports.adjustCanvasSize = exports.currentPage = exports.
|
|
3
|
+
exports.addAdoptedStylesheet = exports.getDevicePixelRatio = exports.adjustCanvasSize = exports.currentPage = exports.calculateZoomLevel = exports.goToPreviousSearchMatch = exports.goToNextSearchMatch = exports.renderPage = exports.transforms = exports.print = exports.reloadDocument = exports.loadPDF = exports.download = exports.removeChildren = exports.parsePdfFromBase64String = exports.scale = exports.DEFAULT_ZOOM_LEVEL = exports.scrollToPage = exports.createElement = void 0;
|
|
4
4
|
const kendo_file_saver_1 = require("@progress/kendo-file-saver");
|
|
5
5
|
const kendo_common_1 = require("@progress/kendo-common");
|
|
6
6
|
const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
|
|
7
7
|
const annotations_1 = require("./annotations");
|
|
8
|
+
const dom_1 = require("./common/dom");
|
|
9
|
+
Object.defineProperty(exports, "createElement", { enumerable: true, get: function () { return dom_1.createElement; } });
|
|
10
|
+
Object.defineProperty(exports, "scrollToPage", { enumerable: true, get: function () { return dom_1.scrollToPage; } });
|
|
8
11
|
const MAX_CANVAS_WIDTH_HEIGHT_CHROME = 65535;
|
|
9
12
|
const MAX_CANVAS_AREA_CHROME_SAFARI = 268435456;
|
|
10
13
|
const MAX_CANVAS_WIDTH_HEIGHT_FIREFOX = 32767;
|
|
@@ -163,7 +166,7 @@ const reloadDocument = (params) => {
|
|
|
163
166
|
if (loadOnDemand) {
|
|
164
167
|
const page = pdfPages[currentPageIndex];
|
|
165
168
|
(0, exports.renderPage)(page, page._pageInfo.emptyPage, error);
|
|
166
|
-
(0,
|
|
169
|
+
(0, dom_1.scrollToPage)(rootElement, currentPageIndex);
|
|
167
170
|
}
|
|
168
171
|
done(pdfPages);
|
|
169
172
|
})
|
|
@@ -227,7 +230,7 @@ const createEmptyPage = (page, zoom, pdfDoc, rootElement) => {
|
|
|
227
230
|
};
|
|
228
231
|
const renderCanvas = (page, done, error) => {
|
|
229
232
|
const { canvasContext, viewport, scaleNum, canvas, pageElement } = createCanvas(page);
|
|
230
|
-
page.render({ canvasContext, viewport })
|
|
233
|
+
page.render({ canvasContext, viewport, canvas })
|
|
231
234
|
.promise.then(() => {
|
|
232
235
|
const printContent = new Image(Math.floor((viewport.width / scaleNum)), Math.floor((viewport.height / scaleNum)));
|
|
233
236
|
printContent.src = canvas.toDataURL();
|
|
@@ -240,15 +243,6 @@ const renderCanvas = (page, done, error) => {
|
|
|
240
243
|
.catch(error);
|
|
241
244
|
return viewport;
|
|
242
245
|
};
|
|
243
|
-
const createElement = function (name, className, styles) {
|
|
244
|
-
const element = document.createElement(name);
|
|
245
|
-
if (className) {
|
|
246
|
-
element.className = className;
|
|
247
|
-
}
|
|
248
|
-
Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
|
|
249
|
-
return element;
|
|
250
|
-
};
|
|
251
|
-
exports.createElement = createElement;
|
|
252
246
|
exports.transforms = {
|
|
253
247
|
'0': '',
|
|
254
248
|
'90': 'rotate(90deg) translateY(-100%)',
|
|
@@ -256,12 +250,12 @@ exports.transforms = {
|
|
|
256
250
|
'270': 'rotate(270deg) translateX(-100%)'
|
|
257
251
|
};
|
|
258
252
|
const renderPage = (page, emptyPage, error) => {
|
|
259
|
-
const { canvasContext, viewport, pageElement, styles, zoom, pdfDoc, rootElement } = emptyPage;
|
|
253
|
+
const { canvasContext, viewport, pageElement, styles, zoom, pdfDoc, rootElement, canvas } = emptyPage;
|
|
260
254
|
page._pageInfo.renderInProgress = true;
|
|
261
|
-
page.render({ canvasContext, viewport })
|
|
255
|
+
page.render({ canvasContext, viewport, canvas })
|
|
262
256
|
.promise.then(() => {
|
|
263
257
|
page.getTextContent().then((textContent) => {
|
|
264
|
-
const textLayer = (0,
|
|
258
|
+
const textLayer = (0, dom_1.createElement)('div', 'k-text-layer', styles);
|
|
265
259
|
new pdf_mjs_1.TextLayer({
|
|
266
260
|
textContentSource: textContent,
|
|
267
261
|
container: textLayer,
|
|
@@ -283,7 +277,7 @@ const renderPage = (page, emptyPage, error) => {
|
|
|
283
277
|
}).catch(error);
|
|
284
278
|
});
|
|
285
279
|
page.getAnnotations({ intent: 'display' }).then((annotations) => {
|
|
286
|
-
const annotationLayer = (0,
|
|
280
|
+
const annotationLayer = (0, dom_1.createElement)('div', 'k-annotations-layer', {
|
|
287
281
|
position: 'absolute',
|
|
288
282
|
top: '0',
|
|
289
283
|
left: '0',
|
|
@@ -379,25 +373,6 @@ const calculateZoomLevel = (zoomLevel, zoomLevelType, currentZoom, dom) => {
|
|
|
379
373
|
return calculatedZoomLevel;
|
|
380
374
|
};
|
|
381
375
|
exports.calculateZoomLevel = calculateZoomLevel;
|
|
382
|
-
/**
|
|
383
|
-
* Scrolls the PDFViewer document to the passed page number.
|
|
384
|
-
*
|
|
385
|
-
* @param rootElement The root HTML element of the PDFViewer component.
|
|
386
|
-
* @param pageNumber The page number.
|
|
387
|
-
*/
|
|
388
|
-
const scrollToPage = (rootElement, pageNumber) => {
|
|
389
|
-
const pages = rootElement.querySelectorAll('.k-page');
|
|
390
|
-
const page = pages[0];
|
|
391
|
-
if (page instanceof HTMLDivElement) {
|
|
392
|
-
const top = (page.offsetHeight + page.offsetTop) *
|
|
393
|
-
Math.max(0, Math.min(pageNumber, pages.length - 1));
|
|
394
|
-
const scrollElement = page.closest('.k-pdf-viewer-canvas');
|
|
395
|
-
if (scrollElement) {
|
|
396
|
-
scrollElement.scrollTo({ top, behavior: 'auto' });
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
exports.scrollToPage = scrollToPage;
|
|
401
376
|
/**
|
|
402
377
|
* A function which gives you the page number of the document according to the scroll position.
|
|
403
378
|
*
|
|
@@ -469,8 +444,8 @@ const createCanvas = (page, zoom = 1, cssClass = '') => {
|
|
|
469
444
|
width: Math.floor(viewport.width / scaleNum) * zoom + 'pt',
|
|
470
445
|
height: Math.floor(viewport.height / scaleNum) * zoom + 'pt'
|
|
471
446
|
};
|
|
472
|
-
const pageElement = (0,
|
|
473
|
-
const canvas = (0,
|
|
447
|
+
const pageElement = (0, dom_1.createElement)('div', cssClass, styles);
|
|
448
|
+
const canvas = (0, dom_1.createElement)('canvas', '', {
|
|
474
449
|
width: '100%',
|
|
475
450
|
height: '100%'
|
|
476
451
|
});
|
package/dist/npm/widget/page.js
CHANGED
|
@@ -572,6 +572,7 @@ class Page extends component_1.Component {
|
|
|
572
572
|
canvasContext: canvasContext,
|
|
573
573
|
// transform,
|
|
574
574
|
viewport,
|
|
575
|
+
canvas,
|
|
575
576
|
annotationMode: tslib_1.__classPrivateFieldGet(this, _Page_annotationMode, "f"),
|
|
576
577
|
// optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
577
578
|
annotationCanvasMap: this._annotationCanvasMap,
|
|
@@ -33,6 +33,18 @@ export declare class PdfViewer extends Component {
|
|
|
33
33
|
searchService: SearchService;
|
|
34
34
|
shouldPreventScroll: boolean;
|
|
35
35
|
eventBus: EventBus;
|
|
36
|
+
_isCtrlKeyDown: boolean;
|
|
37
|
+
_isPinching: boolean;
|
|
38
|
+
_touchInfo: {
|
|
39
|
+
touch0X: number;
|
|
40
|
+
touch0Y: number;
|
|
41
|
+
touch1X: number;
|
|
42
|
+
touch1Y: number;
|
|
43
|
+
} | null;
|
|
44
|
+
_wheelUnusedFactor: number;
|
|
45
|
+
_touchUnusedFactor: number;
|
|
46
|
+
_pendingPinchFactor: number;
|
|
47
|
+
_pinchAC: AbortController | null;
|
|
36
48
|
constructor(element: any, options: any);
|
|
37
49
|
destroy(): void;
|
|
38
50
|
throwIfInvalidOptions(): void;
|
|
@@ -183,6 +195,20 @@ export declare class PdfViewer extends Component {
|
|
|
183
195
|
disableScrollerEventsTracking(): void;
|
|
184
196
|
setScaleFactor(scaleFactor: number): void;
|
|
185
197
|
onDocumentWheel: (e: any) => void;
|
|
198
|
+
_isTrackpadPinch(e: WheelEvent): boolean;
|
|
199
|
+
_accumulateFactor(previousScale: number, factor: number, prop: '_wheelUnusedFactor' | '_touchUnusedFactor'): number;
|
|
200
|
+
_onKeyDown: (e: KeyboardEvent) => void;
|
|
201
|
+
_onKeyUp: (e: KeyboardEvent) => void;
|
|
202
|
+
bindPinchToZoomEvents(): void;
|
|
203
|
+
unbindPinchToZoomEvents(): void;
|
|
204
|
+
_resetPinchState(): void;
|
|
205
|
+
get _minTouchDistanceToPinch(): number;
|
|
206
|
+
_onGestureEvent: (e: Event) => void;
|
|
207
|
+
_onTouchStart: (e: TouchEvent) => void;
|
|
208
|
+
_onTouchMove: (e: TouchEvent) => void;
|
|
209
|
+
_onTouchEnd: (e: TouchEvent) => void;
|
|
210
|
+
_applyPinchTransform(prevDist: number, currDist: number): void;
|
|
211
|
+
_clearPinchTransform(): void;
|
|
186
212
|
activatePageNumber(pageNumber: any): void;
|
|
187
213
|
scrollToPage({ pageNumber }: {
|
|
188
214
|
pageNumber: any;
|
|
@@ -50,6 +50,7 @@ class PdfViewer extends main_1.Component {
|
|
|
50
50
|
maxZoom: 4,
|
|
51
51
|
zoomRate: 0.25,
|
|
52
52
|
zoomLevel: DEFAULT_ZOOM_LEVEL,
|
|
53
|
+
pinchToZoom: true,
|
|
53
54
|
zoomBeforePrint: false,
|
|
54
55
|
zoomLevelForPrint: 3,
|
|
55
56
|
renderForms: false,
|
|
@@ -151,6 +152,14 @@ class PdfViewer extends main_1.Component {
|
|
|
151
152
|
this.state = {};
|
|
152
153
|
this.pdfDocument = null;
|
|
153
154
|
this.pages = [];
|
|
155
|
+
// Pinch-to-zoom state
|
|
156
|
+
this._isCtrlKeyDown = false;
|
|
157
|
+
this._isPinching = false;
|
|
158
|
+
this._touchInfo = null;
|
|
159
|
+
this._wheelUnusedFactor = 1;
|
|
160
|
+
this._touchUnusedFactor = 1;
|
|
161
|
+
this._pendingPinchFactor = 1;
|
|
162
|
+
this._pinchAC = null;
|
|
154
163
|
this.triggerError = (e) => {
|
|
155
164
|
this.trigger(ERROR, {
|
|
156
165
|
error: e
|
|
@@ -226,6 +235,18 @@ class PdfViewer extends main_1.Component {
|
|
|
226
235
|
}
|
|
227
236
|
e.preventDefault();
|
|
228
237
|
e.stopPropagation();
|
|
238
|
+
if (this.options.pinchToZoom && this._isTrackpadPinch(e)) {
|
|
239
|
+
const scaleFactor = Math.exp(-e.deltaY / 100);
|
|
240
|
+
const newScaleFactor = this._accumulateFactor(this.state.zoomLevel, scaleFactor, '_wheelUnusedFactor');
|
|
241
|
+
if (newScaleFactor === 1) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const zoomLevel = this.state.zoomLevel * newScaleFactor;
|
|
245
|
+
this.triggerZoomStart({ zoomLevel });
|
|
246
|
+
this.zoom({ zoomLevel });
|
|
247
|
+
this.triggerZoomEnd({ zoomLevel });
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
229
250
|
const wheelDelta = (0, main_1.mousewheelDelta)(e);
|
|
230
251
|
const zoomModifier = wheelDelta < 0 ? 1 : -1;
|
|
231
252
|
const zoomLevel = this.state.zoomLevel + (zoomModifier * this.options.zoomRate);
|
|
@@ -239,6 +260,102 @@ class PdfViewer extends main_1.Component {
|
|
|
239
260
|
zoomLevel: zoomLevel
|
|
240
261
|
});
|
|
241
262
|
};
|
|
263
|
+
this._onKeyDown = (e) => {
|
|
264
|
+
if (e.key === 'Control') {
|
|
265
|
+
this._isCtrlKeyDown = true;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
this._onKeyUp = (e) => {
|
|
269
|
+
if (e.key === 'Control') {
|
|
270
|
+
this._isCtrlKeyDown = false;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
this._onGestureEvent = (e) => {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
};
|
|
276
|
+
this._onTouchStart = (e) => {
|
|
277
|
+
var _a;
|
|
278
|
+
if (!this.options.pinchToZoom) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (e.touches.length !== 2) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
// Prevent browser-native pinch-zoom from starting (required for iOS Safari
|
|
285
|
+
// where the gesture decision is made at touchstart time)
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
const touch0 = e.touches[0];
|
|
288
|
+
const touch1 = e.touches[1];
|
|
289
|
+
this._touchInfo = {
|
|
290
|
+
touch0X: touch0.screenX,
|
|
291
|
+
touch0Y: touch0.screenY,
|
|
292
|
+
touch1X: touch1.screenX,
|
|
293
|
+
touch1Y: touch1.screenY
|
|
294
|
+
};
|
|
295
|
+
this._pendingPinchFactor = 1;
|
|
296
|
+
this._touchUnusedFactor = 1;
|
|
297
|
+
const documentContainer = this.getDocumentContainer();
|
|
298
|
+
if (!documentContainer) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const signal = (_a = this._pinchAC) === null || _a === void 0 ? void 0 : _a.signal;
|
|
302
|
+
documentContainer.addEventListener('touchmove', this._onTouchMove, { passive: false, signal });
|
|
303
|
+
documentContainer.addEventListener('touchend', this._onTouchEnd, { signal });
|
|
304
|
+
documentContainer.addEventListener('touchcancel', this._onTouchEnd, { signal });
|
|
305
|
+
};
|
|
306
|
+
this._onTouchMove = (e) => {
|
|
307
|
+
if (!this._touchInfo || e.touches.length !== 2) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
e.preventDefault();
|
|
311
|
+
e.stopPropagation();
|
|
312
|
+
const touch0 = e.touches[0];
|
|
313
|
+
const touch1 = e.touches[1];
|
|
314
|
+
const prevGapX = this._touchInfo.touch1X - this._touchInfo.touch0X;
|
|
315
|
+
const prevGapY = this._touchInfo.touch1Y - this._touchInfo.touch0Y;
|
|
316
|
+
const currGapX = touch1.screenX - touch0.screenX;
|
|
317
|
+
const currGapY = touch1.screenY - touch0.screenY;
|
|
318
|
+
const prevDist = Math.hypot(prevGapX, prevGapY) || 1;
|
|
319
|
+
const currDist = Math.hypot(currGapX, currGapY) || 1;
|
|
320
|
+
if (Math.abs(prevDist - currDist) <= this._minTouchDistanceToPinch) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!this._isPinching) {
|
|
324
|
+
this._isPinching = true;
|
|
325
|
+
// Suppress panning during pinch
|
|
326
|
+
this.disableScrollerEventsTracking();
|
|
327
|
+
// Fire zoom start on first pinch movement
|
|
328
|
+
this.triggerZoomStart({ zoomLevel: this.state.zoomLevel });
|
|
329
|
+
}
|
|
330
|
+
this._applyPinchTransform(prevDist, currDist);
|
|
331
|
+
// Update stored positions for next move
|
|
332
|
+
this._touchInfo = {
|
|
333
|
+
touch0X: touch0.screenX,
|
|
334
|
+
touch0Y: touch0.screenY,
|
|
335
|
+
touch1X: touch1.screenX,
|
|
336
|
+
touch1Y: touch1.screenY
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
this._onTouchEnd = (e) => {
|
|
340
|
+
if (e.touches.length >= 2) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const documentContainer = this.getDocumentContainer();
|
|
344
|
+
if (documentContainer) {
|
|
345
|
+
documentContainer.removeEventListener('touchmove', this._onTouchMove);
|
|
346
|
+
documentContainer.removeEventListener('touchend', this._onTouchEnd);
|
|
347
|
+
documentContainer.removeEventListener('touchcancel', this._onTouchEnd);
|
|
348
|
+
}
|
|
349
|
+
if (this._isPinching) {
|
|
350
|
+
this._clearPinchTransform();
|
|
351
|
+
const zoomLevel = (0, main_1.clamp)(this.state.zoomLevel * this._pendingPinchFactor, this.options.minZoom, this.options.maxZoom);
|
|
352
|
+
this.zoom({ zoomLevel });
|
|
353
|
+
this.triggerZoomEnd({ zoomLevel });
|
|
354
|
+
// Re-enable panning
|
|
355
|
+
this.enableScrollerEventsTracking();
|
|
356
|
+
}
|
|
357
|
+
this._resetPinchState();
|
|
358
|
+
};
|
|
242
359
|
this.extendOptions(options);
|
|
243
360
|
this.throwIfInvalidOptions();
|
|
244
361
|
this.wrapper = this.element;
|
|
@@ -365,6 +482,7 @@ class PdfViewer extends main_1.Component {
|
|
|
365
482
|
}
|
|
366
483
|
bindEvents() {
|
|
367
484
|
this.bindPagesWheel();
|
|
485
|
+
this.bindPinchToZoomEvents();
|
|
368
486
|
}
|
|
369
487
|
bindPagesWheel() {
|
|
370
488
|
const documentContainer = this.getDocumentContainer();
|
|
@@ -384,6 +502,7 @@ class PdfViewer extends main_1.Component {
|
|
|
384
502
|
}
|
|
385
503
|
unbindEvents() {
|
|
386
504
|
this.unbindPagesWheel();
|
|
505
|
+
this.unbindPinchToZoomEvents();
|
|
387
506
|
}
|
|
388
507
|
unbindPagesWheel() {
|
|
389
508
|
const documentContainer = this.getDocumentContainer();
|
|
@@ -1342,6 +1461,105 @@ class PdfViewer extends main_1.Component {
|
|
|
1342
1461
|
}
|
|
1343
1462
|
setScaleFactor(scaleFactor) {
|
|
1344
1463
|
this.element.style.setProperty('--scale-factor', String(scaleFactor * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
|
|
1464
|
+
this.element.style.setProperty('--total-scale-factor', String(scaleFactor * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS));
|
|
1465
|
+
this.element.style.setProperty('--scale-round-x', '1px');
|
|
1466
|
+
this.element.style.setProperty('--scale-round-y', '1px');
|
|
1467
|
+
}
|
|
1468
|
+
_isTrackpadPinch(e) {
|
|
1469
|
+
// Trackpad pinch gestures generate wheel events with synthetic ctrlKey=true.
|
|
1470
|
+
// Real Ctrl+scroll has ctrlKey=true but the physical key is down.
|
|
1471
|
+
// Heuristic: ctrlKey is set, physical Ctrl is NOT pressed, pixel-level delta,
|
|
1472
|
+
// deltaX is 0 (no horizontal scroll), and the scale factor is small.
|
|
1473
|
+
if (this._isCtrlKeyDown) {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
if (e.deltaMode !== WheelEvent.DOM_DELTA_PIXEL) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
if (e.deltaX !== 0) {
|
|
1480
|
+
return false;
|
|
1481
|
+
}
|
|
1482
|
+
const scaleFactor = Math.exp(-e.deltaY / 100);
|
|
1483
|
+
if (Math.abs(scaleFactor - 1) >= 0.05) {
|
|
1484
|
+
return false;
|
|
1485
|
+
}
|
|
1486
|
+
return true;
|
|
1487
|
+
}
|
|
1488
|
+
_accumulateFactor(previousScale, factor, prop) {
|
|
1489
|
+
if (factor === 1) {
|
|
1490
|
+
return 1;
|
|
1491
|
+
}
|
|
1492
|
+
if ((this[prop] > 1 && factor < 1) || (this[prop] < 1 && factor > 1)) {
|
|
1493
|
+
this[prop] = 1;
|
|
1494
|
+
}
|
|
1495
|
+
const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
|
|
1496
|
+
this[prop] = factor / (newFactor || factor);
|
|
1497
|
+
return newFactor || 1;
|
|
1498
|
+
}
|
|
1499
|
+
bindPinchToZoomEvents() {
|
|
1500
|
+
if (!this.options.pinchToZoom) {
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
document.addEventListener('keydown', this._onKeyDown);
|
|
1504
|
+
document.addEventListener('keyup', this._onKeyUp);
|
|
1505
|
+
const documentContainer = this.getDocumentContainer();
|
|
1506
|
+
if (!documentContainer) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
this._pinchAC = new AbortController();
|
|
1510
|
+
const signal = this._pinchAC.signal;
|
|
1511
|
+
// Prevent the browser from handling pinch-zoom natively
|
|
1512
|
+
documentContainer.style.touchAction = 'none';
|
|
1513
|
+
documentContainer.addEventListener('touchstart', this._onTouchStart, { passive: false, signal });
|
|
1514
|
+
// iOS Safari fires proprietary GestureEvents for pinch gestures.
|
|
1515
|
+
// Suppressing them prevents the browser from zooming the page.
|
|
1516
|
+
documentContainer.addEventListener('gesturestart', this._onGestureEvent, { signal });
|
|
1517
|
+
documentContainer.addEventListener('gesturechange', this._onGestureEvent, { signal });
|
|
1518
|
+
}
|
|
1519
|
+
unbindPinchToZoomEvents() {
|
|
1520
|
+
document.removeEventListener('keydown', this._onKeyDown);
|
|
1521
|
+
document.removeEventListener('keyup', this._onKeyUp);
|
|
1522
|
+
this._isCtrlKeyDown = false;
|
|
1523
|
+
const documentContainer = this.getDocumentContainer();
|
|
1524
|
+
if (documentContainer) {
|
|
1525
|
+
documentContainer.style.touchAction = '';
|
|
1526
|
+
}
|
|
1527
|
+
if (this._pinchAC) {
|
|
1528
|
+
this._pinchAC.abort();
|
|
1529
|
+
this._pinchAC = null;
|
|
1530
|
+
}
|
|
1531
|
+
this._resetPinchState();
|
|
1532
|
+
}
|
|
1533
|
+
_resetPinchState() {
|
|
1534
|
+
this._isPinching = false;
|
|
1535
|
+
this._touchInfo = null;
|
|
1536
|
+
this._touchUnusedFactor = 1;
|
|
1537
|
+
this._wheelUnusedFactor = 1;
|
|
1538
|
+
this._pendingPinchFactor = 1;
|
|
1539
|
+
}
|
|
1540
|
+
get _minTouchDistanceToPinch() {
|
|
1541
|
+
return 32 / (window.devicePixelRatio || 1);
|
|
1542
|
+
}
|
|
1543
|
+
_applyPinchTransform(prevDist, currDist) {
|
|
1544
|
+
const rawFactor = currDist / prevDist;
|
|
1545
|
+
const newFactor = this._accumulateFactor(this.state.zoomLevel, rawFactor, '_touchUnusedFactor');
|
|
1546
|
+
this._pendingPinchFactor *= newFactor;
|
|
1547
|
+
// Clamp the visual factor to the allowed zoom range
|
|
1548
|
+
const targetZoom = this.state.zoomLevel * this._pendingPinchFactor;
|
|
1549
|
+
const clampedZoom = (0, main_1.clamp)(targetZoom, this.options.minZoom, this.options.maxZoom);
|
|
1550
|
+
const visualFactor = clampedZoom / this.state.zoomLevel;
|
|
1551
|
+
const pagesContainer = this.getPagesContainer();
|
|
1552
|
+
if (pagesContainer) {
|
|
1553
|
+
pagesContainer.style.transform = `scale(${visualFactor})`;
|
|
1554
|
+
pagesContainer.style.transformOrigin = 'center top';
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
_clearPinchTransform() {
|
|
1558
|
+
const pagesContainer = this.getPagesContainer();
|
|
1559
|
+
if (pagesContainer) {
|
|
1560
|
+
pagesContainer.style.transform = '';
|
|
1561
|
+
pagesContainer.style.transformOrigin = '';
|
|
1562
|
+
}
|
|
1345
1563
|
}
|
|
1346
1564
|
activatePageNumber(pageNumber) {
|
|
1347
1565
|
const page = this.getPageByNumber(pageNumber);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progress/kendo-pdfviewer-common",
|
|
3
3
|
"description": "Kendo UI TypeScript package exporting functions for PDFViewer component",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-develop.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Kendo UI"
|
|
7
7
|
],
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"prepare": "npx husky",
|
|
20
|
-
"test": "
|
|
21
|
-
"test:ci": "
|
|
22
|
-
"watch-test": "
|
|
20
|
+
"test": "vitest run --config vitest.config.ts",
|
|
21
|
+
"test:ci": "vitest run --config vitest.config.ts",
|
|
22
|
+
"watch-test": "vitest run --config vitest.config.ts --watch",
|
|
23
23
|
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider gulp start",
|
|
24
24
|
"lint": "npx eslint",
|
|
25
25
|
"lint:fix": "npx eslint --fix",
|
|
@@ -28,58 +28,44 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@progress/kendo-draggable": "^3.1.0",
|
|
31
|
-
"@progress/kendo-file-saver": "^1.1.
|
|
31
|
+
"@progress/kendo-file-saver": "^1.1.2"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@progress/kendo-common": "1.0.2",
|
|
35
|
-
"pdfjs-dist": "
|
|
36
|
-
"tslib": "^2.
|
|
35
|
+
"pdfjs-dist": "5.6.205",
|
|
36
|
+
"tslib": "^2.8.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@babel/preset-env": "^7.
|
|
40
|
-
"@commitlint/cli": "^
|
|
41
|
-
"@commitlint/config-conventional": "^
|
|
42
|
-
"@eslint/js": "^
|
|
43
|
-
"@progress/kendo-common-tasks": "
|
|
39
|
+
"@babel/preset-env": "^7.29.0",
|
|
40
|
+
"@commitlint/cli": "^20.4.4",
|
|
41
|
+
"@commitlint/config-conventional": "^20.4.4",
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@progress/kendo-common-tasks": "^9.0.1",
|
|
44
44
|
"@progress/kendo-draggable": "^3.1.0",
|
|
45
|
-
"@progress/kendo-file-saver": "^1.1.
|
|
46
|
-
"@progress/kendo-typescript-tasks": "
|
|
47
|
-
"
|
|
48
|
-
"@types/jest": "^23.3.14",
|
|
49
|
-
"cross-env": "^7.0.3",
|
|
45
|
+
"@progress/kendo-file-saver": "^1.1.2",
|
|
46
|
+
"@progress/kendo-typescript-tasks": "^12.0.0",
|
|
47
|
+
"cross-env": "^10.1.0",
|
|
50
48
|
"cz-conventional-changelog": "^3.3.0",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"eslint-plugin-jsdoc": "^
|
|
49
|
+
"eslint": "^10.0.3",
|
|
50
|
+
"eslint-plugin-jsdoc": "^62.8.0",
|
|
53
51
|
"gulp": "^5.0.0",
|
|
54
52
|
"husky": "^9.1.7",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"typescript": "~5.7.3",
|
|
61
|
-
"typescript-eslint": "^8.21.0"
|
|
62
|
-
},
|
|
63
|
-
"overrides": {
|
|
64
|
-
"lodash": ">=4.18.0",
|
|
65
|
-
"tmp": ">=0.2.4",
|
|
66
|
-
"tar": ">=7.5.10",
|
|
67
|
-
"@tootallnate/once": ">=3.0.1",
|
|
68
|
-
"minimatch": ">=10.2.3",
|
|
69
|
-
"webpack": ">=5.104.1",
|
|
70
|
-
"handlebars": ">=4.7.9",
|
|
71
|
-
"uuid": ">=14.0.0",
|
|
72
|
-
"picomatch": ">=2.3.2",
|
|
73
|
-
"follow-redirects": ">=1.16.0",
|
|
74
|
-
"flatted": ">=3.4.2",
|
|
75
|
-
"brace-expansion": ">=3.4.2",
|
|
76
|
-
"qs": ">=6.14.2"
|
|
53
|
+
"jsdom": "^28.0.0",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"typescript-eslint": "^8.54.0",
|
|
56
|
+
"vitest": "^4.1.3",
|
|
57
|
+
"vitest-canvas-mock": "^1.1.3"
|
|
77
58
|
},
|
|
78
59
|
"config": {
|
|
79
60
|
"commitizen": {
|
|
80
61
|
"path": "./node_modules/cz-conventional-changelog"
|
|
81
62
|
}
|
|
82
63
|
},
|
|
64
|
+
"overrides": {
|
|
65
|
+
"lodash": "^4.17.23",
|
|
66
|
+
"inquirer": "^9.2.0",
|
|
67
|
+
"uuid": "^14.0.0"
|
|
68
|
+
},
|
|
83
69
|
"repository": {
|
|
84
70
|
"type": "git",
|
|
85
71
|
"url": "https://github.com/telerik/kendo-pdfviewer-common.git"
|