@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.
Files changed (46) hide show
  1. package/dist/es/annotations/annotation-editor-ui-manager.js +1 -1
  2. package/dist/es/annotations/annotation-layer.js +2 -7
  3. package/dist/es/annotations/editors/free-text-editor.js +0 -1
  4. package/dist/es/annotations/editors/highlight-editor.js +2 -3
  5. package/dist/es/annotations/editors/outliner.js +2 -3
  6. package/dist/es/annotations.js +1 -1
  7. package/dist/es/common/component.js +1 -0
  8. package/dist/es/common/core.js +1 -2
  9. package/dist/es/common/dom.js +26 -0
  10. package/dist/es/types/index.js +1 -0
  11. package/dist/es/utils.js +5 -29
  12. package/dist/es/widget/page.js +1 -0
  13. package/dist/es/widget/pdfviewer.js +218 -0
  14. package/dist/es2015/annotations/annotation-editor-ui-manager.js +1 -1
  15. package/dist/es2015/annotations/annotation-layer.js +2 -7
  16. package/dist/es2015/annotations/editors/free-text-editor.js +0 -1
  17. package/dist/es2015/annotations/editors/highlight-editor.js +2 -3
  18. package/dist/es2015/annotations/editors/outliner.js +2 -3
  19. package/dist/es2015/annotations.js +1 -1
  20. package/dist/es2015/common/component.js +1 -0
  21. package/dist/es2015/common/core.js +1 -2
  22. package/dist/es2015/common/dom.js +26 -0
  23. package/dist/es2015/types/index.js +1 -0
  24. package/dist/es2015/utils.js +5 -29
  25. package/dist/es2015/widget/page.js +1 -0
  26. package/dist/es2015/widget/pdfviewer.js +218 -0
  27. package/dist/npm/annotations/annotation-editor-ui-manager.js +1 -1
  28. package/dist/npm/annotations/annotation-layer.js +2 -7
  29. package/dist/npm/annotations/editors/free-text-editor.js +0 -1
  30. package/dist/npm/annotations/editors/highlight-editor.js +2 -3
  31. package/dist/npm/annotations/editors/outliner.js +2 -3
  32. package/dist/npm/annotations.js +4 -4
  33. package/dist/npm/common/component.d.ts +1 -0
  34. package/dist/npm/common/component.js +1 -0
  35. package/dist/npm/common/core.js +1 -2
  36. package/dist/npm/common/dom.d.ts +10 -0
  37. package/dist/npm/common/dom.js +29 -1
  38. package/dist/npm/main.d.ts +2 -2
  39. package/dist/npm/types/index.d.ts +1 -0
  40. package/dist/npm/types/index.js +2 -0
  41. package/dist/npm/utils.d.ts +2 -10
  42. package/dist/npm/utils.js +12 -37
  43. package/dist/npm/widget/page.js +1 -0
  44. package/dist/npm/widget/pdfviewer.d.ts +26 -0
  45. package/dist/npm/widget/pdfviewer.js +218 -0
  46. package/package.json +27 -41
@@ -869,7 +869,7 @@ export class AnnotationEditorUIManager {
869
869
  case AnnotationEditorParamsType.CREATE:
870
870
  this.currentLayer.addNewEditor();
871
871
  return;
872
- case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
872
+ case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
873
873
  // this.#mainHighlightColorPicker?.updateColor(value);
874
874
  break;
875
875
  case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
@@ -1917,9 +1917,7 @@ class PopupElement {
1917
1917
  const popup = (__classPrivateFieldSet(this, _PopupElement_popup, document.createElement("div"), "f"));
1918
1918
  popup.className = "popup";
1919
1919
  if (__classPrivateFieldGet(this, _PopupElement_color, "f")) {
1920
- const baseColor = (popup.style.outlineColor = Util.makeHexColor(
1921
- // @ts-expect-error TS(2556):
1922
- ...__classPrivateFieldGet(this, _PopupElement_color, "f")));
1920
+ const baseColor = (popup.style.outlineColor = Util.makeHexColor(...__classPrivateFieldGet(this, _PopupElement_color, "f")));
1923
1921
  if (
1924
1922
  // (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
1925
1923
  CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
@@ -1931,9 +1929,7 @@ class PopupElement {
1931
1929
  // TODO: Use color-mix when it's supported everywhere.
1932
1930
  // Enlighten the color.
1933
1931
  const BACKGROUND_ENLIGHT = 0.7;
1934
- popup.style.backgroundColor = Util.makeHexColor(
1935
- // @ts-expect-error TS(2556):
1936
- ...__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
1932
+ popup.style.backgroundColor = Util.makeHexColor(...__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
1937
1933
  }
1938
1934
  }
1939
1935
  const header = document.createElement("span");
@@ -1954,7 +1950,6 @@ class PopupElement {
1954
1950
  }
1955
1951
  const html = __classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get);
1956
1952
  if (html) {
1957
- // @ts-expect-error TS(2556):
1958
1953
  XfaLayer.render({
1959
1954
  xfaHtml: html,
1960
1955
  intent: "richText",
@@ -530,7 +530,6 @@ class FreeTextEditor extends AnnotationEditor {
530
530
  }
531
531
  const editor = super.deserialize(data, parent, uiManager);
532
532
  __classPrivateFieldSet(editor, _FreeTextEditor_fontSize, data.fontSize, "f");
533
- // @ts-expect-error TS(2556):
534
533
  __classPrivateFieldSet(editor, _FreeTextEditor_color, Util.makeHexColor(...data.color), "f");
535
534
  __classPrivateFieldSet(editor, _FreeTextEditor_content, __classPrivateFieldGet(_a, _a, "m", _FreeTextEditor_deserializeContent).call(_a, data.value), "f");
536
535
  editor.annotationElementId = data.id || null;
@@ -126,7 +126,7 @@ class HighlightEditor extends AnnotationEditor {
126
126
  /** @inheritdoc */
127
127
  static updateDefaultParams(type, value) {
128
128
  switch (type) {
129
- case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
129
+ case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
130
130
  _a._defaultColor = value;
131
131
  break;
132
132
  case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
@@ -157,7 +157,7 @@ class HighlightEditor extends AnnotationEditor {
157
157
  static get defaultPropertiesToUpdate() {
158
158
  return [
159
159
  [
160
- AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR,
160
+ AnnotationEditorParamsType.HIGHLIGHT_COLOR,
161
161
  _a._defaultColor
162
162
  ],
163
163
  [
@@ -404,7 +404,6 @@ class HighlightEditor extends 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 = Util.makeHexColor(...color);
409
408
  __classPrivateFieldSet(editor, _HighlightEditor_opacity, data.opacity, "f");
410
409
  const [pageWidth, pageHeight] = editor.pageDimensions;
@@ -721,9 +721,8 @@ _FreeHighlightOutline_box = new WeakMap(), _FreeHighlightOutline_bbox = new Weak
721
721
  }
722
722
  }
723
723
  else {
724
- const bbox = Util.bezierBoundingBox(lastX, lastY,
725
- // @ts-expect-error(TS:2556)
726
- ...outline.slice(i, i + 6));
724
+ // pdfjs-dist legacy types declare bezierBoundingBox as void/9-arg but it returns the bbox array at runtime
725
+ const bbox = Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6));
727
726
  minX = Math.min(minX, bbox[0]);
728
727
  minY = Math.min(minY, bbox[1]);
729
728
  maxX = Math.max(maxX, bbox[2]);
@@ -1,4 +1,4 @@
1
- import { createElement, scrollToPage } from './utils';
1
+ import { createElement, scrollToPage } from './common/dom';
2
2
  class Annotation {
3
3
  constructor(container, viewport, annotation, pdfDoc, zoom, rootElement) {
4
4
  this.container = container;
@@ -1,6 +1,7 @@
1
1
  import { extend, deepExtend, isFunction } from "./core";
2
2
  export class Component {
3
3
  constructor(element, options) {
4
+ this.__isComponent = true;
4
5
  this.options = {
5
6
  events: {}
6
7
  };
@@ -1,4 +1,3 @@
1
- import { Component } from "./component";
2
1
  // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
3
2
  export const extend = (...args) => Object.assign(...args);
4
3
  export const isObject = (value) => value && typeof (value) === "object" && !Array.isArray(value);
@@ -18,7 +17,7 @@ export const deepExtend = (target, ...sources) => {
18
17
  if (key === '__proto__' || key === 'constructor') {
19
18
  continue;
20
19
  }
21
- if (source[key] instanceof Component) {
20
+ if (source[key] && source[key].__isComponent) {
22
21
  target[key] = source[key];
23
22
  }
24
23
  else if (isHtmlElement(source[key])) {
@@ -9,3 +9,29 @@ export const hasClass = (className, element) => {
9
9
  return element.classList.contains(className);
10
10
  }
11
11
  };
12
+ export const createElement = function (name, className, styles) {
13
+ const element = document.createElement(name);
14
+ if (className) {
15
+ element.className = className;
16
+ }
17
+ Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
18
+ return element;
19
+ };
20
+ /**
21
+ * Scrolls the PDFViewer document to the passed page number.
22
+ *
23
+ * @param rootElement The root HTML element of the PDFViewer component.
24
+ * @param pageNumber The page number.
25
+ */
26
+ export const scrollToPage = (rootElement, pageNumber) => {
27
+ const pages = rootElement.querySelectorAll('.k-page');
28
+ const page = pages[0];
29
+ if (page instanceof HTMLDivElement) {
30
+ const top = (page.offsetHeight + page.offsetTop) *
31
+ Math.max(0, Math.min(pageNumber, pages.length - 1));
32
+ const scrollElement = page.closest('.k-pdf-viewer-canvas');
33
+ if (scrollElement) {
34
+ scrollElement.scrollTo({ top, behavior: 'auto' });
35
+ }
36
+ }
37
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/es/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);
@@ -869,7 +869,7 @@ export class AnnotationEditorUIManager {
869
869
  case AnnotationEditorParamsType.CREATE:
870
870
  this.currentLayer.addNewEditor();
871
871
  return;
872
- case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
872
+ case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
873
873
  // this.#mainHighlightColorPicker?.updateColor(value);
874
874
  break;
875
875
  case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
@@ -1917,9 +1917,7 @@ class PopupElement {
1917
1917
  const popup = (__classPrivateFieldSet(this, _PopupElement_popup, document.createElement("div"), "f"));
1918
1918
  popup.className = "popup";
1919
1919
  if (__classPrivateFieldGet(this, _PopupElement_color, "f")) {
1920
- const baseColor = (popup.style.outlineColor = Util.makeHexColor(
1921
- // @ts-expect-error TS(2556):
1922
- ...__classPrivateFieldGet(this, _PopupElement_color, "f")));
1920
+ const baseColor = (popup.style.outlineColor = Util.makeHexColor(...__classPrivateFieldGet(this, _PopupElement_color, "f")));
1923
1921
  if (
1924
1922
  // (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
1925
1923
  CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
@@ -1931,9 +1929,7 @@ class PopupElement {
1931
1929
  // TODO: Use color-mix when it's supported everywhere.
1932
1930
  // Enlighten the color.
1933
1931
  const BACKGROUND_ENLIGHT = 0.7;
1934
- popup.style.backgroundColor = Util.makeHexColor(
1935
- // @ts-expect-error TS(2556):
1936
- ...__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
1932
+ popup.style.backgroundColor = Util.makeHexColor(...__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
1937
1933
  }
1938
1934
  }
1939
1935
  const header = document.createElement("span");
@@ -1954,7 +1950,6 @@ class PopupElement {
1954
1950
  }
1955
1951
  const html = __classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get);
1956
1952
  if (html) {
1957
- // @ts-expect-error TS(2556):
1958
1953
  XfaLayer.render({
1959
1954
  xfaHtml: html,
1960
1955
  intent: "richText",
@@ -530,7 +530,6 @@ class FreeTextEditor extends AnnotationEditor {
530
530
  }
531
531
  const editor = super.deserialize(data, parent, uiManager);
532
532
  __classPrivateFieldSet(editor, _FreeTextEditor_fontSize, data.fontSize, "f");
533
- // @ts-expect-error TS(2556):
534
533
  __classPrivateFieldSet(editor, _FreeTextEditor_color, Util.makeHexColor(...data.color), "f");
535
534
  __classPrivateFieldSet(editor, _FreeTextEditor_content, __classPrivateFieldGet(_a, _a, "m", _FreeTextEditor_deserializeContent).call(_a, data.value), "f");
536
535
  editor.annotationElementId = data.id || null;
@@ -126,7 +126,7 @@ class HighlightEditor extends AnnotationEditor {
126
126
  /** @inheritdoc */
127
127
  static updateDefaultParams(type, value) {
128
128
  switch (type) {
129
- case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
129
+ case AnnotationEditorParamsType.HIGHLIGHT_COLOR:
130
130
  _a._defaultColor = value;
131
131
  break;
132
132
  case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
@@ -157,7 +157,7 @@ class HighlightEditor extends AnnotationEditor {
157
157
  static get defaultPropertiesToUpdate() {
158
158
  return [
159
159
  [
160
- AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR,
160
+ AnnotationEditorParamsType.HIGHLIGHT_COLOR,
161
161
  _a._defaultColor
162
162
  ],
163
163
  [
@@ -404,7 +404,6 @@ class HighlightEditor extends 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 = Util.makeHexColor(...color);
409
408
  __classPrivateFieldSet(editor, _HighlightEditor_opacity, data.opacity, "f");
410
409
  const [pageWidth, pageHeight] = editor.pageDimensions;
@@ -721,9 +721,8 @@ _FreeHighlightOutline_box = new WeakMap(), _FreeHighlightOutline_bbox = new Weak
721
721
  }
722
722
  }
723
723
  else {
724
- const bbox = Util.bezierBoundingBox(lastX, lastY,
725
- // @ts-expect-error(TS:2556)
726
- ...outline.slice(i, i + 6));
724
+ // pdfjs-dist legacy types declare bezierBoundingBox as void/9-arg but it returns the bbox array at runtime
725
+ const bbox = Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6));
727
726
  minX = Math.min(minX, bbox[0]);
728
727
  minY = Math.min(minY, bbox[1]);
729
728
  maxX = Math.max(maxX, bbox[2]);
@@ -1,4 +1,4 @@
1
- import { createElement, scrollToPage } from './utils';
1
+ import { createElement, scrollToPage } from './common/dom';
2
2
  class Annotation {
3
3
  constructor(container, viewport, annotation, pdfDoc, zoom, rootElement) {
4
4
  this.container = container;
@@ -1,6 +1,7 @@
1
1
  import { extend, deepExtend, isFunction } from "./core";
2
2
  export class Component {
3
3
  constructor(element, options) {
4
+ this.__isComponent = true;
4
5
  this.options = {
5
6
  events: {}
6
7
  };
@@ -1,4 +1,3 @@
1
- import { Component } from "./component";
2
1
  // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
3
2
  export const extend = (...args) => Object.assign(...args);
4
3
  export const isObject = (value) => value && typeof (value) === "object" && !Array.isArray(value);
@@ -18,7 +17,7 @@ export const deepExtend = (target, ...sources) => {
18
17
  if (key === '__proto__' || key === 'constructor') {
19
18
  continue;
20
19
  }
21
- if (source[key] instanceof Component) {
20
+ if (source[key] && source[key].__isComponent) {
22
21
  target[key] = source[key];
23
22
  }
24
23
  else if (isHtmlElement(source[key])) {
@@ -9,3 +9,29 @@ export const hasClass = (className, element) => {
9
9
  return element.classList.contains(className);
10
10
  }
11
11
  };
12
+ export const createElement = function (name, className, styles) {
13
+ const element = document.createElement(name);
14
+ if (className) {
15
+ element.className = className;
16
+ }
17
+ Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
18
+ return element;
19
+ };
20
+ /**
21
+ * Scrolls the PDFViewer document to the passed page number.
22
+ *
23
+ * @param rootElement The root HTML element of the PDFViewer component.
24
+ * @param pageNumber The page number.
25
+ */
26
+ export const scrollToPage = (rootElement, pageNumber) => {
27
+ const pages = rootElement.querySelectorAll('.k-page');
28
+ const page = pages[0];
29
+ if (page instanceof HTMLDivElement) {
30
+ const top = (page.offsetHeight + page.offsetTop) *
31
+ Math.max(0, Math.min(pageNumber, pages.length - 1));
32
+ const scrollElement = page.closest('.k-pdf-viewer-canvas');
33
+ if (scrollElement) {
34
+ scrollElement.scrollTo({ top, behavior: 'auto' });
35
+ }
36
+ }
37
+ };
@@ -0,0 +1 @@
1
+ export {};