@libresign/pdf-elements 1.0.1 → 1.1.0

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { defineComponent as I, openBlock as m, createElementBlock as v, normalizeStyle as E, renderSlot as M, createElementVNode as P, withModifiers as R, createCommentVNode as $, normalizeClass as Y, Fragment as z, renderList as B, markRaw as y, resolveComponent as Z, createVNode as G, createBlock as J, withCtx as N, toDisplayString as U } from "vue";
2
- const Q = I({
1
+ import { defineComponent as V, openBlock as m, createElementBlock as v, normalizeStyle as R, renderSlot as M, createElementVNode as P, withModifiers as E, createCommentVNode as C, normalizeClass as Y, Fragment as z, renderList as H, markRaw as y, resolveComponent as I, createVNode as x, createBlock as J, withCtx as N, toDisplayString as U } from "vue";
2
+ const Q = V({
3
3
  name: "PDFPage",
4
4
  emits: ["onMeasure"],
5
5
  props: {
@@ -79,16 +79,16 @@ const Q = I({
79
79
  }
80
80
  }
81
81
  }
82
- }), V = (e, t) => {
82
+ }), Z = (e, t) => {
83
83
  const i = e.__vccOpts || e;
84
- for (const [s, o] of t)
85
- i[s] = o;
84
+ for (const [s, n] of t)
85
+ i[s] = n;
86
86
  return i;
87
87
  }, _ = { ref: "canvas" };
88
- function ee(e, t, i, s, o, a) {
88
+ function ee(e, t, i, s, n, a) {
89
89
  return m(), v("canvas", _, null, 512);
90
90
  }
91
- const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"]]), ie = I({
91
+ const te = /* @__PURE__ */ Z(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"]]), ie = V({
92
92
  name: "DraggableElement",
93
93
  props: {
94
94
  object: {
@@ -208,7 +208,7 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
208
208
  return ["top-left", "top-right", "bottom-left", "bottom-right"];
209
209
  },
210
210
  elementStyle() {
211
- const e = this.pagesScale || 1, t = this.mode === "drag", i = this.mode === "resize", s = t ? this.offsetX : 0, o = t ? this.offsetY : 0, a = i ? this.resizeOffsetX : 0, n = i ? this.resizeOffsetY : 0, h = i ? this.resizeOffsetW : 0, r = i ? this.resizeOffsetH : 0, l = this.object.x + s + a, u = this.object.y + o + n, c = this.object.width + h, d = this.object.height + r;
211
+ const e = this.pagesScale || 1, t = this.mode === "drag", i = this.mode === "resize", s = t ? this.offsetX : 0, n = t ? this.offsetY : 0, a = i ? this.resizeOffsetX : 0, o = i ? this.resizeOffsetY : 0, r = i ? this.resizeOffsetW : 0, h = i ? this.resizeOffsetH : 0, l = this.object.x + s + a, u = this.object.y + n + o, c = this.object.width + r, d = this.object.height + h;
212
212
  return {
213
213
  left: `${l * e}px`,
214
214
  top: `${u * e}px`,
@@ -218,9 +218,9 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
218
218
  };
219
219
  },
220
220
  toolbarStyle() {
221
- const e = this.pagesScale || 1, t = this.mode === "drag", i = this.mode === "resize", s = t ? this.offsetX : 0, o = t ? this.offsetY : 0, a = i ? this.resizeOffsetX : 0, n = i ? this.resizeOffsetY : 0, h = i ? this.resizeOffsetW : 0, r = this.object.x + s + a, l = this.object.y + o + n, u = this.object.width + h, d = l - 60, g = d < 0 ? l + 8 : d;
221
+ const e = this.pagesScale || 1, t = this.mode === "drag", i = this.mode === "resize", s = t ? this.offsetX : 0, n = t ? this.offsetY : 0, a = i ? this.resizeOffsetX : 0, o = i ? this.resizeOffsetY : 0, r = i ? this.resizeOffsetW : 0, h = this.object.x + s + a, l = this.object.y + n + o, u = this.object.width + r, d = l - 60, g = d < 0 ? l + 8 : d;
222
222
  return {
223
- left: `${(r + u / 2) * e}px`,
223
+ left: `${(h + u / 2) * e}px`,
224
224
  top: `${g * e}px`,
225
225
  transform: "translateX(-50%)"
226
226
  };
@@ -261,9 +261,9 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
261
261
  this.currentPageRect = i;
262
262
  let s = { x: 0, y: 0 };
263
263
  if (i) {
264
- const o = i.left + this.object.x * this.pagesScale, a = i.top + this.object.y * this.pagesScale;
264
+ const n = i.left + this.object.x * this.pagesScale, a = i.top + this.object.y * this.pagesScale;
265
265
  s = {
266
- x: t.left - o,
266
+ x: t.left - n,
267
267
  y: t.top - a
268
268
  };
269
269
  }
@@ -277,14 +277,14 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
277
277
  const t = e.type.includes("touch") ? e.touches[0]?.clientX : e.clientX, i = e.type.includes("touch") ? e.touches[0]?.clientY : e.clientY;
278
278
  if (t === void 0 || i === void 0) return;
279
279
  this.lastMouseX = t, this.lastMouseY = i;
280
- const s = (t - this.startX) / this.pagesScale, o = (i - this.startY) / this.pagesScale;
280
+ const s = (t - this.startX) / this.pagesScale, n = (i - this.startY) / this.pagesScale;
281
281
  if (this.mode === "drag") {
282
282
  const c = this.currentPageRect;
283
283
  if (c) {
284
284
  const d = t - this.pointerOffsetDoc.x, g = i - this.pointerOffsetDoc.y, f = (d - c.left) / this.pagesScale, b = (g - c.top) / this.pagesScale;
285
285
  this.offsetX = f - this.object.x, this.offsetY = b - this.object.y;
286
286
  } else
287
- this.offsetX = s, this.offsetY = o;
287
+ this.offsetX = s, this.offsetY = n;
288
288
  this.onDragMove(t, i), this.isBeingDraggedGlobally && this.onUpdate({
289
289
  _globalDrag: !0,
290
290
  _mouseX: t,
@@ -293,25 +293,25 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
293
293
  return;
294
294
  }
295
295
  const a = 16 / (this.pagesScale || 1);
296
- let n = this.startWidth, h = this.startHeight, r = this.startLeft, l = this.startTop;
296
+ let o = this.startWidth, r = this.startHeight, h = this.startLeft, l = this.startTop;
297
297
  const u = this.direction.includes("right") ? s : this.direction.includes("left") ? -s : 0;
298
- if (n = this.startWidth + u, n < a && (n = a), h = n / this.aspectRatio, this.direction.includes("left") && (r = this.startLeft + (this.startWidth - n), r < 0)) {
299
- const c = -r;
300
- r = 0, n = n - c, h = n / this.aspectRatio;
298
+ if (o = this.startWidth + u, o < a && (o = a), r = o / this.aspectRatio, this.direction.includes("left") && (h = this.startLeft + (this.startWidth - o), h < 0)) {
299
+ const c = -h;
300
+ h = 0, o = o - c, r = o / this.aspectRatio;
301
301
  }
302
- if (this.direction.includes("top") && (l = this.startTop + (this.startHeight - h), l < 0)) {
302
+ if (this.direction.includes("top") && (l = this.startTop + (this.startHeight - r), l < 0)) {
303
303
  const c = -l;
304
- l = 0, h = h - c, n = h * this.aspectRatio, this.direction.includes("left") && (r = this.startLeft + (this.startWidth - n));
304
+ l = 0, r = r - c, o = r * this.aspectRatio, this.direction.includes("left") && (h = this.startLeft + (this.startWidth - o));
305
305
  }
306
- if (r + n > this.pageWidth) {
307
- const c = r + n - this.pageWidth;
308
- n -= c, h = n / this.aspectRatio;
306
+ if (h + o > this.pageWidth) {
307
+ const c = h + o - this.pageWidth;
308
+ o -= c, r = o / this.aspectRatio;
309
309
  }
310
- if (l + h > this.pageHeight) {
311
- const c = l + h - this.pageHeight;
312
- h -= c, n = h * this.aspectRatio, this.direction.includes("left") && (r = this.startLeft + (this.startWidth - n));
310
+ if (l + r > this.pageHeight) {
311
+ const c = l + r - this.pageHeight;
312
+ r -= c, o = r * this.aspectRatio, this.direction.includes("left") && (h = this.startLeft + (this.startWidth - o));
313
313
  }
314
- this.resizeOffsetX = r - this.object.x, this.resizeOffsetY = l - this.object.y, this.resizeOffsetW = n - this.object.width, this.resizeOffsetH = h - this.object.height, this.rafId = null;
314
+ this.resizeOffsetX = h - this.object.x, this.resizeOffsetY = l - this.object.y, this.resizeOffsetW = o - this.object.width, this.resizeOffsetH = r - this.object.height, this.rafId = null;
315
315
  })));
316
316
  },
317
317
  stopInteraction() {
@@ -348,12 +348,12 @@ const te = /* @__PURE__ */ V(Q, [["render", ee], ["__scopeId", "data-v-2a60d679"
348
348
  }
349
349
  }
350
350
  }), se = { class: "draggable-wrapper" }, ne = ["onMousedown", "onTouchstart"];
351
- function oe(e, t, i, s, o, a) {
351
+ function oe(e, t, i, s, n, a) {
352
352
  return m(), v("div", se, [
353
353
  e.isSelected && !e.isBeingDraggedGlobally && e.showSelectionUi && e.showDefaultActions ? (m(), v("div", {
354
354
  key: 0,
355
355
  class: "actions-toolbar",
356
- style: E(e.toolbarStyle)
356
+ style: R(e.toolbarStyle)
357
357
  }, [
358
358
  M(e.$slots, "actions", {
359
359
  object: e.object,
@@ -364,7 +364,7 @@ function oe(e, t, i, s, o, a) {
364
364
  class: "action-btn",
365
365
  type: "button",
366
366
  title: "Duplicate",
367
- onClick: t[0] || (t[0] = R((...n) => e.onDuplicate && e.onDuplicate(...n), ["stop"]))
367
+ onClick: t[0] || (t[0] = E((...o) => e.onDuplicate && e.onDuplicate(...o), ["stop"]))
368
368
  }, [...t[5] || (t[5] = [
369
369
  P("svg", {
370
370
  width: "16",
@@ -379,7 +379,7 @@ function oe(e, t, i, s, o, a) {
379
379
  class: "action-btn",
380
380
  type: "button",
381
381
  title: "Delete",
382
- onClick: t[1] || (t[1] = R((...n) => e.onDelete && e.onDelete(...n), ["stop"]))
382
+ onClick: t[1] || (t[1] = E((...o) => e.onDelete && e.onDelete(...o), ["stop"]))
383
383
  }, [...t[6] || (t[6] = [
384
384
  P("svg", {
385
385
  width: "16",
@@ -391,15 +391,15 @@ function oe(e, t, i, s, o, a) {
391
391
  ], -1)
392
392
  ])])
393
393
  ], !0)
394
- ], 4)) : $("", !0),
394
+ ], 4)) : C("", !0),
395
395
  P("div", {
396
396
  class: Y(["draggable-element", { selected: e.isSelected && e.showSelectionUi }]),
397
397
  draggable: "false",
398
- onDragstart: t[2] || (t[2] = R(() => {
398
+ onDragstart: t[2] || (t[2] = E(() => {
399
399
  }, ["prevent"])),
400
- style: E([e.elementStyle, e.dragElementStyle]),
401
- onMousedown: t[3] || (t[3] = (...n) => e.handleElementClick && e.handleElementClick(...n)),
402
- onTouchstart: t[4] || (t[4] = (...n) => e.handleElementClick && e.handleElementClick(...n))
400
+ style: R([e.elementStyle, e.dragElementStyle]),
401
+ onMousedown: t[3] || (t[3] = (...o) => e.handleElementClick && e.handleElementClick(...o)),
402
+ onTouchstart: t[4] || (t[4] = (...o) => e.handleElementClick && e.handleElementClick(...o))
403
403
  }, [
404
404
  M(e.$slots, "default", {
405
405
  object: e.object,
@@ -407,81 +407,89 @@ function oe(e, t, i, s, o, a) {
407
407
  onDelete: e.onDelete,
408
408
  onResize: e.startResizeFromSlot
409
409
  }, void 0, !0),
410
- e.isSelected && e.showSelectionUi ? (m(!0), v(z, { key: 0 }, B(e.resizeDirections, (n) => (m(), v("button", {
411
- key: n,
412
- class: Y(["resize-handle", `handle-${n}`]),
410
+ e.isSelected && e.showSelectionUi ? (m(!0), v(z, { key: 0 }, H(e.resizeDirections, (o) => (m(), v("button", {
411
+ key: o,
412
+ class: Y(["resize-handle", `handle-${o}`]),
413
413
  type: "button",
414
- onMousedown: R((h) => e.startResize(n, h), ["stop", "prevent"]),
415
- onTouchstart: R((h) => e.startResize(n, h), ["stop", "prevent"])
416
- }, null, 42, ne))), 128)) : $("", !0)
414
+ onMousedown: E((r) => e.startResize(o, r), ["stop", "prevent"]),
415
+ onTouchstart: E((r) => e.startResize(o, r), ["stop", "prevent"])
416
+ }, null, 42, ne))), 128)) : C("", !0)
417
417
  ], 38)
418
418
  ]);
419
419
  }
420
- const ae = /* @__PURE__ */ V(ie, [["render", oe], ["__scopeId", "data-v-c700849e"]]);
421
- let H = null, A = null, W = null, X = null;
422
- function re() {
423
- return A || (A = import("./pdf-uHvE5neP.mjs")), A;
420
+ const ae = /* @__PURE__ */ Z(ie, [["render", oe], ["__scopeId", "data-v-c700849e"]]);
421
+ let B = null, A = null, W = null, X = null;
422
+ function re(e) {
423
+ const t = e;
424
+ return t.default?.PDFWorker ? t.default : t;
424
425
  }
425
426
  function he() {
426
- return W || (W = import("./pdf.worker.min-DmO9Xdfo.mjs").then(
427
+ return A || (A = import("./pdf-l6QfMa5e.mjs").then(re)), A;
428
+ }
429
+ function le() {
430
+ return W || (W = import("./pdf.worker.min-eBwwJm95.mjs").then(
427
431
  (e) => e.default
428
432
  )), W;
429
433
  }
430
- async function le(e) {
431
- if (X) {
432
- e.GlobalWorkerOptions.workerSrc = X;
433
- return;
434
+ async function ce(e) {
435
+ if (e?.GlobalWorkerOptions) {
436
+ if (X) {
437
+ e.GlobalWorkerOptions.workerSrc = X;
438
+ return;
439
+ }
440
+ e.GlobalWorkerOptions.workerSrc || (e.GlobalWorkerOptions.workerSrc = await le());
434
441
  }
435
- e.GlobalWorkerOptions.workerSrc || (e.GlobalWorkerOptions.workerSrc = await he());
436
442
  }
437
- async function ce(e) {
438
- return H || (await le(e), H = new e.PDFWorker({})), H;
443
+ async function de(e) {
444
+ return B || (await ce(e), B = new e.PDFWorker({})), B;
439
445
  }
440
446
  function je(e) {
441
- X = e, A && A.then((t) => {
442
- t.GlobalWorkerOptions.workerSrc = e;
447
+ X = e, B = null, A && A.then((t) => {
448
+ t?.GlobalWorkerOptions && (t.GlobalWorkerOptions.workerSrc = e);
449
+ }).catch((t) => {
450
+ console.warn("setWorkerPath: failed to update pdfjs workerSrc immediately", t);
443
451
  });
444
452
  }
445
- function K(e) {
453
+ function G(e) {
446
454
  return new Promise((t, i) => {
447
455
  const s = new FileReader();
448
456
  s.onload = () => t(s.result), s.onerror = i, s.readAsArrayBuffer(e);
449
457
  });
450
458
  }
451
- async function x(e, t = {}) {
452
- const i = await re(), s = await ce(i), o = e instanceof ArrayBuffer, a = ArrayBuffer.isView(e), n = typeof Blob < "u" && e instanceof Blob;
453
- if (e && typeof e == "object" && !o && !a && !n)
459
+ async function K(e, t = {}) {
460
+ const i = await he(), s = await de(i), n = e instanceof ArrayBuffer, a = ArrayBuffer.isView(e), o = typeof Blob < "u" && e instanceof Blob;
461
+ if (e && typeof e == "object" && !n && !a && !o)
454
462
  return i.getDocument({ ...e, ...t, worker: s }).promise;
455
463
  if (typeof e == "string")
456
464
  return i.getDocument({ url: e, ...t, worker: s }).promise;
457
- if (n) {
458
- const r = await K(e);
459
- return i.getDocument({ data: r, ...t, worker: s }).promise;
465
+ if (o) {
466
+ const h = await G(e);
467
+ return i.getDocument({ data: h, ...t, worker: s }).promise;
460
468
  }
461
- const h = o ? e : new Uint8Array(
469
+ const r = n ? e : new Uint8Array(
462
470
  e.buffer,
463
471
  e.byteOffset,
464
472
  e.byteLength
465
473
  );
466
- return i.getDocument({ data: h, ...t, worker: s }).promise;
474
+ return i.getDocument({ data: r, ...t, worker: s }).promise;
467
475
  }
468
- function F(e, t, i, s, o, a) {
476
+ function L(e, t, i, s, n, a) {
469
477
  return {
470
- x: Math.max(0, Math.min(e, o - i)),
478
+ x: Math.max(0, Math.min(e, n - i)),
471
479
  y: Math.max(0, Math.min(t, a - s))
472
480
  };
473
481
  }
474
- function de(e, t, i, s, o, a) {
475
- const n = Math.max(0, e), h = Math.max(0, t), r = Math.min(o, e + i), l = Math.min(a, t + s);
476
- return r <= n || l <= h ? 0 : (r - n) * (l - h);
482
+ function ge(e, t, i, s, n, a) {
483
+ const o = Math.max(0, e), r = Math.max(0, t), h = Math.min(n, e + i), l = Math.min(a, t + s);
484
+ return h <= o || l <= r ? 0 : (h - o) * (l - r);
477
485
  }
478
- function ge(e, t, i = 300) {
486
+ function ue(e, t, i = 300) {
479
487
  return {
480
488
  minY: Math.max(0, e - i),
481
489
  maxY: e + t + i
482
490
  };
483
491
  }
484
- function ue(e, t, i, s) {
492
+ function fe(e, t, i, s) {
485
493
  return !(e + t < i || e > s);
486
494
  }
487
495
  function q(e, t) {
@@ -489,39 +497,39 @@ function q(e, t) {
489
497
  i.pagesScale = i.pagesScale.map(() => t);
490
498
  });
491
499
  }
492
- function fe(e, t) {
500
+ function pe(e, t) {
493
501
  return !e || !t ? !1 : e.allObjects.some((i) => i.some((s) => s.id === t));
494
502
  }
495
- function L(e, t) {
503
+ function F(e, t) {
496
504
  if (!(!e || !t)) {
497
505
  for (let i = 0; i < e.allObjects.length; i++)
498
506
  if (e.allObjects[i].some((s) => s.id === t))
499
507
  return i;
500
508
  }
501
509
  }
502
- function pe(e, t, i, s) {
503
- const o = e?.allObjects?.[t];
504
- if (!o) return !1;
505
- const a = o.findIndex((n) => n.id === i);
506
- return a === -1 ? !1 : (o.splice(a, 1, { ...o[a], ...s }), !0);
510
+ function me(e, t, i, s) {
511
+ const n = e?.allObjects?.[t];
512
+ if (!n) return !1;
513
+ const a = n.findIndex((o) => o.id === i);
514
+ return a === -1 ? !1 : (n.splice(a, 1, { ...n[a], ...s }), !0);
507
515
  }
508
- function me(e, t, i) {
516
+ function ve(e, t, i) {
509
517
  const s = e?.allObjects?.[t];
510
518
  if (!s) return !1;
511
- const o = s.findIndex((a) => a.id === i);
512
- return o === -1 ? !1 : (s.splice(o, 1), !0);
519
+ const n = s.findIndex((a) => a.id === i);
520
+ return n === -1 ? !1 : (s.splice(n, 1), !0);
513
521
  }
514
- function ve(e, t, i, s) {
515
- const o = e[t];
516
- if (o)
517
- return o;
518
- const a = i.getCanvasMeasurement(), n = {
522
+ function we(e, t, i, s) {
523
+ const n = e[t];
524
+ if (n)
525
+ return n;
526
+ const a = i.getCanvasMeasurement(), o = {
519
527
  width: a.canvasWidth / s,
520
528
  height: a.canvasHeight / s
521
529
  };
522
- return e[t] = n, n;
530
+ return e[t] = o, o;
523
531
  }
524
- const we = I({
532
+ const be = V({
525
533
  name: "PDFElements",
526
534
  emits: ["pdf-elements:end-init", "pdf-elements:delete-object", "pdf-elements:object-click"],
527
535
  components: {
@@ -585,6 +593,10 @@ const we = I({
585
593
  type: Boolean,
586
594
  default: !1
587
595
  },
596
+ pageAriaLabel: {
597
+ type: Function,
598
+ default: null
599
+ },
588
600
  pdfjsOptions: {
589
601
  type: Object,
590
602
  default: () => ({})
@@ -650,29 +662,29 @@ const we = I({
650
662
  this.autoFitApplied = !1;
651
663
  for (let t = 0; t < this.initFiles.length; t++) {
652
664
  const i = this.initFiles[t], s = this.initFileNames[t] || `document-${t + 1}.pdf`;
653
- let o;
665
+ let n;
654
666
  if (i instanceof Blob) {
655
- const r = await K(i);
656
- o = await x({ data: r }, this.pdfjsOptions);
667
+ const h = await G(i);
668
+ n = await K({ data: h }, this.pdfjsOptions);
657
669
  } else
658
- o = await x(i, this.pdfjsOptions);
659
- const a = [], n = Array(o.numPages).fill(0);
660
- for (let r = 1; r <= o.numPages; r++) {
661
- const l = o.getPage(r);
670
+ n = await K(i, this.pdfjsOptions);
671
+ const a = [], o = Array(n.numPages).fill(0);
672
+ for (let h = 1; h <= n.numPages; h++) {
673
+ const l = n.getPage(h);
662
674
  l.then((u) => {
663
- n.splice(r - 1, 1, u.getViewport({ scale: 1 }).width), this.autoFitZoom && this.scheduleAutoFitZoom();
675
+ o.splice(h - 1, 1, u.getViewport({ scale: 1 }).width), this.autoFitZoom && this.scheduleAutoFitZoom();
664
676
  }), a.push(l);
665
677
  }
666
- const h = y(a);
678
+ const r = y(a);
667
679
  e.push({
668
680
  name: s,
669
681
  file: i,
670
- pdfDoc: y(o),
671
- numPages: o.numPages,
672
- pages: h,
673
- pageWidths: n,
674
- pagesScale: Array(o.numPages).fill(this.scale),
675
- allObjects: Array(o.numPages).fill(0).map(() => [])
682
+ pdfDoc: y(n),
683
+ numPages: n.numPages,
684
+ pages: r,
685
+ pageWidths: o,
686
+ pagesScale: Array(n.numPages).fill(this.scale),
687
+ allObjects: Array(n.numPages).fill(0).map(() => [])
676
688
  });
677
689
  }
678
690
  this.pdfDocuments = e, this._pageMeasurementCache = y({}), e.length && (this.selectedDocIndex = 0, this.selectedPageIndex = 0, this.$emit("pdf-elements:end-init", { docsCount: e.length }), this.$nextTick(() => {
@@ -682,14 +694,14 @@ const we = I({
682
694
  selectPage(e, t) {
683
695
  this.selectedDocIndex = e, this.selectedPageIndex = t;
684
696
  },
685
- startDraggingElement(e, t, i, s, o, a, n) {
686
- this.isDraggingElement = !0, this.draggingObject = { ...i }, this.draggingDocIndex = e, this.draggingPageIndex = t, this.draggingScale = this.getDisplayedPageScale(e, t), this.lastMouseClientPos.x = s, this.lastMouseClientPos.y = o, this.draggingElementShift = n && typeof n.x == "number" && typeof n.y == "number" ? n : { x: 0, y: 0 }, this.cachePageBounds();
687
- const h = this.getPageRect(e, t);
697
+ startDraggingElement(e, t, i, s, n, a, o) {
698
+ this.isDraggingElement = !0, this.draggingObject = { ...i }, this.draggingDocIndex = e, this.draggingPageIndex = t, this.draggingScale = this.getDisplayedPageScale(e, t), this.lastMouseClientPos.x = s, this.lastMouseClientPos.y = n, this.draggingElementShift = o && typeof o.x == "number" && typeof o.y == "number" ? o : { x: 0, y: 0 }, this.cachePageBounds();
699
+ const r = this.getPageRect(e, t);
688
700
  if (a && typeof a.x == "number" && typeof a.y == "number")
689
- this.draggingInitialMouseOffset.x = a.x, this.draggingInitialMouseOffset.y = a.y, this.draggingClientPosition.x = s - this.draggingInitialMouseOffset.x, this.draggingClientPosition.y = o - this.draggingInitialMouseOffset.y;
690
- else if (h) {
691
- const r = h.left + i.x * this.draggingScale, l = h.top + i.y * this.draggingScale;
692
- this.draggingInitialMouseOffset.x = s - r, this.draggingInitialMouseOffset.y = o - l, this.draggingClientPosition.x = s - this.draggingInitialMouseOffset.x, this.draggingClientPosition.y = o - this.draggingInitialMouseOffset.y;
701
+ this.draggingInitialMouseOffset.x = a.x, this.draggingInitialMouseOffset.y = a.y, this.draggingClientPosition.x = s - this.draggingInitialMouseOffset.x, this.draggingClientPosition.y = n - this.draggingInitialMouseOffset.y;
702
+ else if (r) {
703
+ const h = r.left + i.x * this.draggingScale, l = r.top + i.y * this.draggingScale;
704
+ this.draggingInitialMouseOffset.x = s - h, this.draggingInitialMouseOffset.y = n - l, this.draggingClientPosition.x = s - this.draggingInitialMouseOffset.x, this.draggingClientPosition.y = n - this.draggingInitialMouseOffset.y;
693
705
  }
694
706
  },
695
707
  updateDraggingPosition(e, t) {
@@ -709,8 +721,8 @@ const we = I({
709
721
  );
710
722
  i !== void 0 && this.$nextTick(() => {
711
723
  this.selectPage(t, i);
712
- const s = `draggable${t}-${i}-${e}`, o = this.$refs[s];
713
- o && Array.isArray(o) && o[0] && (o[0].isSelected = !0);
724
+ const s = `draggable${t}-${i}-${e}`, n = this.$refs[s];
725
+ n && Array.isArray(n) && n[0] && (n[0].isSelected = !0);
714
726
  });
715
727
  }
716
728
  this.isDraggingElement = !1, this.draggingObject = null, this.draggingDocIndex = -1, this.draggingPageIndex = -1, this.draggingElementShift = { x: 0, y: 0 }, this.pendingDragClientPos = null;
@@ -719,33 +731,33 @@ const we = I({
719
731
  this.pdfDocuments.length && (this.attachAddingListeners(), this.isAddingMode = !0, this.previewElement = { ...e }, this.previewPageDocIndex = 0, this.previewPageIndex = 0, this.previewVisible = !1, this.previewScale = { x: 1, y: 1 }, this.cachePageBounds());
720
732
  },
721
733
  cachePageBounds() {
722
- const e = {}, t = [], i = this.$el, s = i?.scrollTop || 0, o = i?.clientHeight || 0;
723
- if (!this.isAddingMode && !this.isDraggingElement && s === this._lastPageBoundsScrollTop && o === this._lastPageBoundsClientHeight)
734
+ const e = {}, t = [], i = this.$el, s = i?.scrollTop || 0, n = i?.clientHeight || 0;
735
+ if (!this.isAddingMode && !this.isDraggingElement && s === this._lastPageBoundsScrollTop && n === this._lastPageBoundsClientHeight)
724
736
  return;
725
- this._lastPageBoundsScrollTop = s, this._lastPageBoundsClientHeight = o;
726
- const { minY: a, maxY: n } = ge(s, o);
727
- for (let h = 0; h < this.pdfDocuments.length; h++)
728
- for (let r = 0; r < this.pdfDocuments[h].pages.length; r++) {
729
- const l = this.getPageCanvasElement(h, r);
737
+ this._lastPageBoundsScrollTop = s, this._lastPageBoundsClientHeight = n;
738
+ const { minY: a, maxY: o } = ue(s, n);
739
+ for (let r = 0; r < this.pdfDocuments.length; r++)
740
+ for (let h = 0; h < this.pdfDocuments[r].pages.length; h++) {
741
+ const l = this.getPageCanvasElement(r, h);
730
742
  if (!l) continue;
731
- if (o) {
743
+ if (n) {
732
744
  const d = l.closest(".page-wrapper") || l, g = d.offsetTop || 0, f = d.offsetHeight || 0;
733
- if (!ue(g, f, a, n))
745
+ if (!fe(g, f, a, o))
734
746
  continue;
735
747
  }
736
748
  const u = l.getBoundingClientRect(), c = {
737
- docIndex: h,
738
- pageIndex: r,
749
+ docIndex: r,
750
+ pageIndex: h,
739
751
  rect: u
740
752
  };
741
- e[`${h}-${r}`] = c, t.push(c);
753
+ e[`${r}-${h}`] = c, t.push(c);
742
754
  }
743
755
  this._pagesBoundingRects = y(e), this._pagesBoundingRectsList = y(t), this.pageBoundsVersion++;
744
756
  },
745
757
  cachePageBoundsForPage(e, t) {
746
758
  const i = this.getPageCanvasElement(e, t);
747
759
  if (!i) return;
748
- const s = i.getBoundingClientRect(), o = {
760
+ const s = i.getBoundingClientRect(), n = {
749
761
  ...this._pagesBoundingRects,
750
762
  [`${e}-${t}`]: {
751
763
  docIndex: e,
@@ -753,7 +765,7 @@ const we = I({
753
765
  rect: s
754
766
  }
755
767
  };
756
- this._pagesBoundingRects = y(o), this._pagesBoundingRectsList = y(Object.values(o)), this.pageBoundsVersion++;
768
+ this._pagesBoundingRects = y(n), this._pagesBoundingRectsList = y(Object.values(n)), this.pageBoundsVersion++;
757
769
  },
758
770
  getPageBoundsMap() {
759
771
  return this._pagesBoundingRects || {};
@@ -787,8 +799,8 @@ const we = I({
787
799
  if (l && s)
788
800
  return l / s;
789
801
  }
790
- const n = i.pagesScale[t] || 1, h = this.visualScale && this.scale ? this.visualScale / this.scale : 1;
791
- return n * h;
802
+ const o = i.pagesScale[t] || 1, r = this.visualScale && this.scale ? this.visualScale / this.scale : 1;
803
+ return o * r;
792
804
  },
793
805
  getPageComponent(e, t) {
794
806
  const i = this.$refs[`page${e}-${t}`];
@@ -800,8 +812,8 @@ const we = I({
800
812
  },
801
813
  onViewportScroll() {
802
814
  this.viewportRafId || (this.viewportRafId = window.requestAnimationFrame(() => {
803
- const e = this.$el, t = e?.scrollTop || 0, i = e?.clientWidth || 0, s = t !== this.lastScrollTop, o = i !== this.lastClientWidth;
804
- this.lastScrollTop = t, this.lastClientWidth = i, (this.isAddingMode || this.isDraggingElement) && (s || o) && this.cachePageBounds(), this.autoFitZoom && !this.isAddingMode && !this.isDraggingElement && i && o && (this.lastContainerWidth = i, this.autoFitApplied = !1, this.scheduleAutoFitZoom()), this.viewportRafId = 0;
815
+ const e = this.$el, t = e?.scrollTop || 0, i = e?.clientWidth || 0, s = t !== this.lastScrollTop, n = i !== this.lastClientWidth;
816
+ this.lastScrollTop = t, this.lastClientWidth = i, (this.isAddingMode || this.isDraggingElement) && (s || n) && this.cachePageBounds(), this.autoFitZoom && !this.isAddingMode && !this.isDraggingElement && i && n && (this.lastContainerWidth = i, this.autoFitApplied = !1, this.scheduleAutoFitZoom()), this.viewportRafId = 0;
805
817
  }));
806
818
  },
807
819
  handleMouseMove(e) {
@@ -811,10 +823,10 @@ const we = I({
811
823
  this.hoverRafId = 0;
812
824
  const s = this.pendingHoverClientPos;
813
825
  if (!s) return;
814
- const o = s.x, a = s.y;
815
- let n = null;
816
- if (this.lastHoverRect && o >= this.lastHoverRect.left && o <= this.lastHoverRect.right && a >= this.lastHoverRect.top && a <= this.lastHoverRect.bottom)
817
- n = {
826
+ const n = s.x, a = s.y;
827
+ let o = null;
828
+ if (this.lastHoverRect && n >= this.lastHoverRect.left && n <= this.lastHoverRect.right && a >= this.lastHoverRect.top && a <= this.lastHoverRect.bottom)
829
+ o = {
818
830
  docIndex: this.previewPageDocIndex,
819
831
  pageIndex: this.previewPageIndex,
820
832
  rect: this.lastHoverRect
@@ -822,37 +834,37 @@ const we = I({
822
834
  else {
823
835
  const S = this.getPageBoundsList().length ? this.getPageBoundsList() : Object.values(this.getPageBoundsMap());
824
836
  for (let w = 0; w < S.length; w++) {
825
- const j = S[w], C = j.rect;
826
- if (o >= C.left && o <= C.right && a >= C.top && a <= C.bottom) {
827
- n = j;
837
+ const $ = S[w], j = $.rect;
838
+ if (n >= j.left && n <= j.right && a >= j.top && a <= j.bottom) {
839
+ o = $;
828
840
  break;
829
841
  }
830
842
  }
831
843
  }
832
- if (!n) {
844
+ if (!o) {
833
845
  this.previewVisible = !1, this.previewScale = { x: 1, y: 1 }, this.lastHoverRect = null;
834
846
  return;
835
847
  }
836
- this.previewPageDocIndex = n.docIndex, this.previewPageIndex = n.pageIndex, this.lastHoverRect = n.rect;
837
- const h = this.getPageCanvasElement(n.docIndex, n.pageIndex), r = this.pdfDocuments[n.docIndex]?.pagesScale?.[n.pageIndex] || 1, l = h?.width || n.rect.width, u = h?.height || n.rect.height, c = l ? n.rect.width / l : 1, d = u ? n.rect.height / u : 1, g = (o - n.rect.left) / c / r, f = (a - n.rect.top) / d / r, b = l / r, D = u / r;
838
- this.previewScale.x = r, this.previewScale.y = r;
839
- let p = g - this.previewElement.width / 2, O = f - this.previewElement.height / 2;
840
- p = Math.max(0, Math.min(p, b - this.previewElement.width)), O = Math.max(0, Math.min(O, D - this.previewElement.height)), this.previewPosition.x = p, this.previewPosition.y = O, this.previewVisible = !0;
848
+ this.previewPageDocIndex = o.docIndex, this.previewPageIndex = o.pageIndex, this.lastHoverRect = o.rect;
849
+ const r = this.getPageCanvasElement(o.docIndex, o.pageIndex), h = this.pdfDocuments[o.docIndex]?.pagesScale?.[o.pageIndex] || 1, l = r?.width || o.rect.width, u = r?.height || o.rect.height, c = l ? o.rect.width / l : 1, d = u ? o.rect.height / u : 1, g = (n - o.rect.left) / c / h, f = (a - o.rect.top) / d / h, b = l / h, O = u / h;
850
+ this.previewScale.x = h, this.previewScale.y = h;
851
+ let p = g - this.previewElement.width / 2, D = f - this.previewElement.height / 2;
852
+ p = Math.max(0, Math.min(p, b - this.previewElement.width)), D = Math.max(0, Math.min(D, O - this.previewElement.height)), this.previewPosition.x = p, this.previewPosition.y = D, this.previewVisible = !0;
841
853
  })));
842
854
  },
843
855
  handleOverlayClick(e, t, i) {
844
856
  if (!this.emitObjectClick) return;
845
- const { x: s, y: o } = this.getPointerPosition(i);
846
- if (!Number.isFinite(s) || !Number.isFinite(o)) return;
857
+ const { x: s, y: n } = this.getPointerPosition(i);
858
+ if (!Number.isFinite(s) || !Number.isFinite(n)) return;
847
859
  this.cachePageBoundsForPage(e, t);
848
860
  const a = this.getPageRect(e, t);
849
861
  if (!a) return;
850
- const n = this.getDisplayedPageScale(e, t) || 1, h = (s - a.left) / n, r = (o - a.top) / n, u = this.pdfDocuments?.[e]?.allObjects?.[t] || [];
862
+ const o = this.getDisplayedPageScale(e, t) || 1, r = (s - a.left) / o, h = (n - a.top) / o, u = this.pdfDocuments?.[e]?.allObjects?.[t] || [];
851
863
  if (u.length === 0) return;
852
864
  let c = null;
853
865
  for (let d = u.length - 1; d >= 0; d--) {
854
- const g = u[d], f = Number(g.x), b = Number(g.y), D = Number(g.width), p = Number(g.height);
855
- if ([f, b, D, p].every(Number.isFinite) && h >= f && h <= f + D && r >= b && r <= b + p) {
866
+ const g = u[d], f = Number(g.x), b = Number(g.y), O = Number(g.width), p = Number(g.height);
867
+ if ([f, b, O, p].every(Number.isFinite) && r >= f && r <= f + O && h >= b && h <= b + p) {
856
868
  c = g;
857
869
  break;
858
870
  }
@@ -867,6 +879,22 @@ const we = I({
867
879
  handleKeyDown(e) {
868
880
  e.key === "Escape" && this.isAddingMode && this.cancelAdding();
869
881
  },
882
+ getOverlayAriaLabel(e, t) {
883
+ const i = this.pdfDocuments?.[e], s = i?.name ?? `Document ${e + 1}`, n = this.pdfDocuments?.length ?? 1, a = i?.numPages ?? 0, o = t + 1;
884
+ if (this.pageAriaLabel)
885
+ return this.pageAriaLabel({ docIndex: e, docName: s, totalDocs: n, pageNumber: o, totalPages: a, isAddingMode: this.isAddingMode });
886
+ const r = n > 1 ? `Document ${e + 1} of ${n} (${s}), ` : "";
887
+ return this.isAddingMode ? `${r}Page ${o} of ${a}. Press Enter or Space to place here.` : `${r}Page ${o} of ${a}.`;
888
+ },
889
+ handleOverlayKeyDown(e, t, i) {
890
+ if (!this.isAddingMode || !this.previewElement || i.key !== "Enter" && i.key !== " ") return;
891
+ i.preventDefault();
892
+ const s = this.getPageWidth(e, t), n = this.getPageHeight(e, t), a = this.getDisplayedPageScale(e, t) || 1;
893
+ this.previewPageDocIndex = e, this.previewPageIndex = t, this.previewScale = { x: a, y: a }, this.previewPosition = {
894
+ x: Math.round((s - this.previewElement.width) / 2),
895
+ y: Math.round((n - this.previewElement.height) / 2)
896
+ }, this.previewVisible = !0, this.finishAdding();
897
+ },
870
898
  handleWheel(e) {
871
899
  if (!e.ctrlKey) return;
872
900
  e.preventDefault();
@@ -892,10 +920,10 @@ const we = I({
892
920
  return;
893
921
  }
894
922
  t.allObjects[this.previewPageIndex].push(e);
895
- const o = this.previewPageIndex, a = this.previewPageDocIndex, n = e.id;
923
+ const n = this.previewPageIndex, a = this.previewPageDocIndex, o = e.id;
896
924
  this.cancelAdding(), this.$nextTick(() => {
897
- const h = `draggable${a}-${o}-${n}`, r = this.$refs[h];
898
- r && Array.isArray(r) && r[0] && (r[0].isSelected = !0);
925
+ const r = `draggable${a}-${n}-${o}`, h = this.$refs[r];
926
+ h && Array.isArray(h) && h[0] && (h[0].isSelected = !0);
899
927
  });
900
928
  },
901
929
  cancelAdding() {
@@ -913,45 +941,45 @@ const we = I({
913
941
  },
914
942
  addObjectToPage(e, t = this.selectedPageIndex, i = this.selectedDocIndex) {
915
943
  if (i < 0 || i >= this.pdfDocuments.length || t < 0 || t >= this.pdfDocuments[i].pages.length) return !1;
916
- const s = this.pdfDocuments[i], o = this.getPageComponent(i, t);
917
- if (!o) return !1;
944
+ const s = this.pdfDocuments[i], n = this.getPageComponent(i, t);
945
+ if (!n) return !1;
918
946
  let a = e;
919
947
  (!a.id || this.objectIdExists(i, a.id)) && (a = { ...a, id: this.generateObjectId() });
920
- const n = this.getCachedMeasurement(i, t, o), h = n.width, r = n.height;
921
- return a.x < 0 || a.y < 0 || a.x + a.width > h || a.y + a.height > r ? !1 : (s.allObjects[t].push(a), this.objectIndexCache[`${i}-${a.id}`] = t, !0);
948
+ const o = this.getCachedMeasurement(i, t, n), r = o.width, h = o.height;
949
+ return a.x < 0 || a.y < 0 || a.x + a.width > r || a.y + a.height > h ? !1 : (s.allObjects[t].push(a), this.objectIndexCache[`${i}-${a.id}`] = t, !0);
922
950
  },
923
951
  objectIdExists(e, t) {
924
952
  if (!t) return !1;
925
953
  const i = `${e}-${t}`;
926
954
  if (this.objectIndexCache[i] !== void 0) return !0;
927
955
  const s = this.pdfDocuments[e];
928
- return fe(s, t);
956
+ return pe(s, t);
929
957
  },
930
958
  updateObjectInPage(e, t, i, s) {
931
- const o = this.pdfDocuments[e];
932
- pe(o, t, i, s);
959
+ const n = this.pdfDocuments[e];
960
+ me(n, t, i, s);
933
961
  },
934
962
  removeObjectFromPage(e, t, i) {
935
963
  const s = this.pdfDocuments[e];
936
- me(s, t, i);
964
+ ve(s, t, i);
937
965
  },
938
966
  getAllObjects(e = this.selectedDocIndex) {
939
967
  if (e < 0 || e >= this.pdfDocuments.length) return [];
940
968
  const t = this.pdfDocuments[e], i = [];
941
- return t.allObjects.forEach((s, o) => {
942
- const a = this.getPageComponent(e, o);
969
+ return t.allObjects.forEach((s, n) => {
970
+ const a = this.getPageComponent(e, n);
943
971
  if (!a) return;
944
- const h = this.getCachedMeasurement(e, o, a).height, r = t.pagesScale[o] || 1;
972
+ const r = this.getCachedMeasurement(e, n, a).height, h = t.pagesScale[n] || 1;
945
973
  s.forEach((l) => {
946
974
  i.push({
947
975
  ...l,
948
- pageIndex: o,
949
- pageNumber: o + 1,
950
- scale: r,
976
+ pageIndex: n,
977
+ pageNumber: n + 1,
978
+ scale: h,
951
979
  normalizedCoordinates: {
952
980
  llx: Math.round(l.x),
953
- lly: Math.round(h - l.y),
954
- ury: Math.round(h - l.y - l.height),
981
+ lly: Math.round(r - l.y),
982
+ ury: Math.round(r - l.y - l.height),
955
983
  width: Math.round(l.width),
956
984
  height: Math.round(l.height)
957
985
  }
@@ -961,46 +989,46 @@ const we = I({
961
989
  },
962
990
  updateObject(e, t, i) {
963
991
  if (e < 0 || e >= this.pdfDocuments.length) return;
964
- const s = this.pdfDocuments[e], o = `${e}-${t}`;
965
- let a = this.objectIndexCache[o];
966
- if (a === void 0 && (a = L(s, t), a !== void 0 && (this.objectIndexCache[o] = a)), a === void 0) return;
967
- const n = s.allObjects[a]?.find((h) => h.id === t);
968
- if (n) {
992
+ const s = this.pdfDocuments[e], n = `${e}-${t}`;
993
+ let a = this.objectIndexCache[n];
994
+ if (a === void 0 && (a = F(s, t), a !== void 0 && (this.objectIndexCache[n] = a)), a === void 0) return;
995
+ const o = s.allObjects[a]?.find((r) => r.id === t);
996
+ if (o) {
969
997
  if (i._globalDrag && i._mouseX !== void 0 && i._mouseY !== void 0) {
970
- const h = i._mouseX, r = i._mouseY, l = this.getPageBoundsMap();
998
+ const r = i._mouseX, h = i._mouseY, l = this.getPageBoundsMap();
971
999
  (!l || Object.keys(l).length === 0) && this.cachePageBounds();
972
1000
  const u = this.getPageRect(e, a);
973
1001
  if (u) {
974
- const c = this.getDisplayedPageScale(e, a), d = (h - u.left - this.draggingElementShift.x) / c - this.draggingInitialMouseOffset.x / c, g = (r - u.top - this.draggingElementShift.y) / c - this.draggingInitialMouseOffset.y / c;
1002
+ const c = this.getDisplayedPageScale(e, a), d = (r - u.left - this.draggingElementShift.x) / c - this.draggingInitialMouseOffset.x / c, g = (h - u.top - this.draggingElementShift.y) / c - this.draggingInitialMouseOffset.y / c;
975
1003
  this.updateObjectInPage(e, a, t, { x: d, y: g });
976
1004
  }
977
1005
  return;
978
1006
  }
979
1007
  if (i.x !== void 0 || i.y !== void 0) {
980
- const h = i.x !== void 0 ? i.x : n.x, r = i.y !== void 0 ? i.y : n.y, l = i.width !== void 0 ? i.width : n.width, u = i.height !== void 0 ? i.height : n.height, { width: c, height: d } = this.getPageSize(e, a);
981
- if (h >= 0 && r >= 0 && h + l <= c && r + u <= d) {
1008
+ const r = i.x !== void 0 ? i.x : o.x, h = i.y !== void 0 ? i.y : o.y, l = i.width !== void 0 ? i.width : o.width, u = i.height !== void 0 ? i.height : o.height, { width: c, height: d } = this.getPageSize(e, a);
1009
+ if (r >= 0 && h >= 0 && r + l <= c && h + u <= d) {
982
1010
  this.updateObjectInPage(e, a, t, i);
983
1011
  return;
984
1012
  }
985
1013
  let g = a, f = 0;
986
1014
  for (let p = 0; p < s.pages.length; p++) {
987
- const O = this.getPageWidth(e, p), S = this.getPageHeight(e, p), w = de(h, r, l, u, O, S);
1015
+ const D = this.getPageWidth(e, p), S = this.getPageHeight(e, p), w = ge(r, h, l, u, D, S);
988
1016
  w > f && (f = w, g = p);
989
1017
  }
990
1018
  if (g !== a) {
991
- const { width: p, height: O } = this.getPageSize(e, g), { x: S, y: w } = F(h, r, l, u, p, O);
1019
+ const { width: p, height: D } = this.getPageSize(e, g), { x: S, y: w } = L(r, h, l, u, p, D);
992
1020
  this.removeObjectFromPage(e, a, t);
993
- const j = {
994
- ...n,
1021
+ const $ = {
1022
+ ...o,
995
1023
  ...i,
996
1024
  x: S,
997
1025
  y: w
998
1026
  };
999
- s.allObjects[g].push(j), this.objectIndexCache[`${e}-${t}`] = g;
1027
+ s.allObjects[g].push($), this.objectIndexCache[`${e}-${t}`] = g;
1000
1028
  return;
1001
1029
  }
1002
- const { width: b, height: D } = this.getPageSize(e, a);
1003
- if (h < 0 || r < 0 || h + l > b || r + u > D)
1030
+ const { width: b, height: O } = this.getPageSize(e, a);
1031
+ if (r < 0 || h < 0 || r + l > b || h + u > O)
1004
1032
  return;
1005
1033
  }
1006
1034
  this.updateObjectInPage(e, a, t, i);
@@ -1009,30 +1037,30 @@ const we = I({
1009
1037
  deleteObject(e, t) {
1010
1038
  if (e < 0 || e >= this.pdfDocuments.length) return;
1011
1039
  const i = this.pdfDocuments[e];
1012
- let s = null, o = -1;
1013
- i.allObjects.some((a, n) => {
1014
- const h = a.findIndex((r) => r.id === t);
1015
- return h === -1 ? !1 : (s = a[h], o = n, a.splice(h, 1), !0);
1040
+ let s = null, n = -1;
1041
+ i.allObjects.some((a, o) => {
1042
+ const r = a.findIndex((h) => h.id === t);
1043
+ return r === -1 ? !1 : (s = a[r], n = o, a.splice(r, 1), !0);
1016
1044
  }), delete this.objectIndexCache[`${e}-${t}`], s && this.$emit("pdf-elements:delete-object", {
1017
1045
  object: s,
1018
1046
  docIndex: e,
1019
- pageIndex: o
1047
+ pageIndex: n
1020
1048
  });
1021
1049
  },
1022
1050
  duplicateObject(e, t) {
1023
1051
  if (e < 0 || e >= this.pdfDocuments.length) return;
1024
1052
  const i = this.pdfDocuments[e], s = `${e}-${t}`;
1025
- let o = this.objectIndexCache[s];
1026
- if (o === void 0 && (o = L(i, t), o !== void 0 && (this.objectIndexCache[s] = o)), o === void 0) return;
1027
- const a = i.allObjects[o]?.find((g) => g.id === t);
1053
+ let n = this.objectIndexCache[s];
1054
+ if (n === void 0 && (n = F(i, t), n !== void 0 && (this.objectIndexCache[s] = n)), n === void 0) return;
1055
+ const a = i.allObjects[n]?.find((g) => g.id === t);
1028
1056
  if (!a) return;
1029
- const { width: n, height: h } = this.getPageSize(e, o), r = 12, { x: l, y: u } = F(
1030
- a.x + r,
1031
- a.y + r,
1057
+ const { width: o, height: r } = this.getPageSize(e, n), h = 12, { x: l, y: u } = L(
1058
+ a.x + h,
1059
+ a.y + h,
1032
1060
  a.width,
1033
1061
  a.height,
1034
- n,
1035
- h
1062
+ o,
1063
+ r
1036
1064
  );
1037
1065
  let c = a.signer;
1038
1066
  c?.element && Object.prototype.hasOwnProperty.call(c.element, "elementId") && (c = {
@@ -1046,42 +1074,42 @@ const we = I({
1046
1074
  y: u,
1047
1075
  signer: c
1048
1076
  };
1049
- i.allObjects[o].push(d), this.objectIndexCache[`${e}-${d.id}`] = o, this.$nextTick(() => {
1050
- const g = `draggable${e}-${o}-${d.id}`, f = this.$refs[g];
1077
+ i.allObjects[n].push(d), this.objectIndexCache[`${e}-${d.id}`] = n, this.$nextTick(() => {
1078
+ const g = `draggable${e}-${n}-${d.id}`, f = this.$refs[g];
1051
1079
  f && Array.isArray(f) && f[0] && (f[0].isSelected = !0);
1052
1080
  });
1053
1081
  },
1054
1082
  checkAndMoveObjectPage(e, t, i, s) {
1055
1083
  if (e < 0 || e >= this.pdfDocuments.length) return;
1056
- const o = this.pdfDocuments[e], a = `${e}-${t}`;
1057
- let n = this.objectIndexCache[a];
1058
- if (n === void 0 && (n = L(o, t), n !== void 0 && (this.objectIndexCache[a] = n)), n === void 0) return;
1059
- const h = o.allObjects[n]?.find((w) => w.id === t);
1060
- if (!h) return n;
1061
- let r = n;
1084
+ const n = this.pdfDocuments[e], a = `${e}-${t}`;
1085
+ let o = this.objectIndexCache[a];
1086
+ if (o === void 0 && (o = F(n, t), o !== void 0 && (this.objectIndexCache[a] = o)), o === void 0) return;
1087
+ const r = n.allObjects[o]?.find((w) => w.id === t);
1088
+ if (!r) return o;
1089
+ let h = o;
1062
1090
  const l = this.getPageBoundsList(), u = this.getPageBoundsMap(), c = l.length ? l : Object.values(u);
1063
1091
  for (let w = 0; w < c.length; w++) {
1064
- const { docIndex: j, pageIndex: C, rect: k } = c[w];
1065
- if (j === e && i >= k.left && i <= k.right && s >= k.top && s <= k.bottom) {
1066
- r = C;
1092
+ const { docIndex: $, pageIndex: j, rect: k } = c[w];
1093
+ if ($ === e && i >= k.left && i <= k.right && s >= k.top && s <= k.bottom) {
1094
+ h = j;
1067
1095
  break;
1068
1096
  }
1069
1097
  }
1070
- const d = this.getPageRect(e, r);
1071
- if (!d) return n;
1072
- const g = this.getDisplayedPageScale(e, r), f = (i - d.left - this.draggingElementShift.x) / g - this.draggingInitialMouseOffset.x / g, b = (s - d.top - this.draggingElementShift.y) / g - this.draggingInitialMouseOffset.y / g, { width: D, height: p } = this.getPageSize(e, r), { x: O, y: S } = F(
1098
+ const d = this.getPageRect(e, h);
1099
+ if (!d) return o;
1100
+ const g = this.getDisplayedPageScale(e, h), f = (i - d.left - this.draggingElementShift.x) / g - this.draggingInitialMouseOffset.x / g, b = (s - d.top - this.draggingElementShift.y) / g - this.draggingInitialMouseOffset.y / g, { width: O, height: p } = this.getPageSize(e, h), { x: D, y: S } = L(
1073
1101
  f,
1074
1102
  b,
1075
- h.width,
1076
- h.height,
1077
- D,
1103
+ r.width,
1104
+ r.height,
1105
+ O,
1078
1106
  p
1079
1107
  );
1080
- return r !== n ? (this.removeObjectFromPage(e, n, t), o.allObjects[r].push({
1081
- ...h,
1082
- x: O,
1108
+ return h !== o ? (this.removeObjectFromPage(e, o, t), n.allObjects[h].push({
1109
+ ...r,
1110
+ x: D,
1083
1111
  y: S
1084
- }), this.objectIndexCache[a] = r) : (O !== h.x || S !== h.y) && this.updateObjectInPage(e, n, t, { x: O, y: S }), r;
1112
+ }), this.objectIndexCache[a] = h) : (D !== r.x || S !== r.y) && this.updateObjectInPage(e, o, t, { x: D, y: S }), h;
1085
1113
  },
1086
1114
  onMeasure(e, t, i) {
1087
1115
  t < 0 || t >= this.pdfDocuments.length || (this.pdfDocuments[t].pagesScale.splice(i, 1, e.scale), this._pageMeasurementCache[`${t}-${i}`] = null, this.cachePageBoundsForPage(t, i), this.autoFitZoom && this.scheduleAutoFitZoom());
@@ -1105,7 +1133,7 @@ const we = I({
1105
1133
  },
1106
1134
  getCachedMeasurement(e, t, i) {
1107
1135
  const s = `${e}-${t}`, a = this.pdfDocuments[e].pagesScale[t] || 1;
1108
- return ve(this._pageMeasurementCache, s, i, a);
1136
+ return we(this._pageMeasurementCache, s, i, a);
1109
1137
  },
1110
1138
  calculateOptimalScale(e) {
1111
1139
  const t = this.$el?.clientWidth || 0;
@@ -1132,29 +1160,29 @@ const we = I({
1132
1160
  const s = this.$el?.querySelectorAll("canvas");
1133
1161
  if (!s?.length) return;
1134
1162
  t = Math.max(...Array.from(s).map(
1135
- (o) => o.width / (this.scale || 1)
1163
+ (n) => n.width / (this.scale || 1)
1136
1164
  ));
1137
1165
  }
1138
1166
  const i = this.calculateOptimalScale(t);
1139
1167
  this.autoFitApplied = !0, Math.abs(i - this.scale) > 0.01 && (this.scale = i, this.visualScale = i, q(this.pdfDocuments, this.scale), this._pageMeasurementCache = y({}), this.cachePageBounds());
1140
1168
  }
1141
1169
  }
1142
- }), be = {
1170
+ }), ye = {
1143
1171
  key: 0,
1144
1172
  class: "pages-container"
1145
- }, ye = ["onMousedown", "onTouchstart"], Pe = ["onClick", "onTouchend"], Oe = {
1173
+ }, Pe = ["onMousedown", "onTouchstart"], De = ["role", "tabindex", "aria-label", "onClick", "onTouchend", "onKeydown"], Oe = {
1146
1174
  key: 0,
1147
1175
  class: "page-footer"
1148
1176
  };
1149
- function De(e, t, i, s, o, a) {
1150
- const n = Z("PDFPage"), h = Z("DraggableElement");
1177
+ function Se(e, t, i, s, n, a) {
1178
+ const o = I("PDFPage"), r = I("DraggableElement");
1151
1179
  return m(), v("div", {
1152
- style: E({ width: e.width, height: e.height }),
1180
+ style: R({ width: e.width, height: e.height }),
1153
1181
  class: "pdf-elements-root"
1154
1182
  }, [
1155
- e.pdfDocuments.length ? (m(), v("div", be, [
1156
- (m(!0), v(z, null, B(e.pdfDocuments, (r, l) => (m(), v("div", { key: l }, [
1157
- (m(!0), v(z, null, B(r.pages, (u, c) => (m(), v("div", {
1183
+ e.pdfDocuments.length ? (m(), v("div", ye, [
1184
+ (m(!0), v(z, null, H(e.pdfDocuments, (h, l) => (m(), v("div", { key: l }, [
1185
+ (m(!0), v(z, null, H(h.pages, (u, c) => (m(), v("div", {
1158
1186
  key: `${l}-${c}`,
1159
1187
  class: "page-slot"
1160
1188
  }, [
@@ -1166,7 +1194,7 @@ function De(e, t, i, s, o, a) {
1166
1194
  P("div", {
1167
1195
  class: Y(["page-canvas", { "shadow-outline": l === e.selectedDocIndex && c === e.selectedPageIndex }])
1168
1196
  }, [
1169
- G(n, {
1197
+ x(o, {
1170
1198
  ref_for: !0,
1171
1199
  ref: `page${l}-${c}`,
1172
1200
  page: u,
@@ -1175,15 +1203,20 @@ function De(e, t, i, s, o, a) {
1175
1203
  }, null, 8, ["page", "scale", "onOnMeasure"]),
1176
1204
  P("div", {
1177
1205
  class: "overlay",
1206
+ role: e.isAddingMode ? "button" : void 0,
1207
+ tabindex: e.isAddingMode ? 0 : -1,
1208
+ "aria-label": e.getOverlayAriaLabel(l, c),
1178
1209
  onMousemove: t[0] || (t[0] = (...d) => e.handleMouseMove && e.handleMouseMove(...d)),
1179
1210
  onTouchmove: t[1] || (t[1] = (...d) => e.handleMouseMove && e.handleMouseMove(...d)),
1180
1211
  onClick: (d) => e.handleOverlayClick(l, c, d),
1181
- onTouchend: (d) => e.handleOverlayClick(l, c, d)
1212
+ onTouchend: (d) => e.handleOverlayClick(l, c, d),
1213
+ onKeydown: (d) => e.handleOverlayKeyDown(l, c, d)
1182
1214
  }, [
1183
1215
  e.isAddingMode && e.previewPageDocIndex === l && e.previewPageIndex === c && e.previewElement && e.previewVisible ? (m(), v("div", {
1184
1216
  key: 0,
1185
1217
  class: "preview-element",
1186
- style: E({
1218
+ "aria-hidden": "true",
1219
+ style: R({
1187
1220
  left: `${e.previewPosition.x * e.previewScale.x}px`,
1188
1221
  top: `${e.previewPosition.y * e.previewScale.y}px`,
1189
1222
  width: `${e.previewElement.width * e.previewScale.x}px`,
@@ -1199,8 +1232,8 @@ function De(e, t, i, s, o, a) {
1199
1232
  isSelected: !1
1200
1233
  }, void 0, !0)
1201
1234
  ], !0)
1202
- ], 4)) : $("", !0),
1203
- (m(!0), v(z, null, B(r.allObjects[c], (d) => (m(), J(h, {
1235
+ ], 4)) : C("", !0),
1236
+ (m(!0), v(z, null, H(h.allObjects[c], (d) => (m(), J(r, {
1204
1237
  key: d.id,
1205
1238
  ref_for: !0,
1206
1239
  ref: `draggable${l}-${c}-${d.id}`,
@@ -1212,7 +1245,7 @@ function De(e, t, i, s, o, a) {
1212
1245
  "on-update": (g) => e.updateObject(l, d.id, g),
1213
1246
  "on-delete": () => e.deleteObject(l, d.id),
1214
1247
  "on-duplicate": () => e.duplicateObject(l, d.id),
1215
- "on-drag-start": (g, f, b, D) => e.startDraggingElement(l, c, d, g, f, b, D),
1248
+ "on-drag-start": (g, f, b, O) => e.startDraggingElement(l, c, d, g, f, b, O),
1216
1249
  "on-drag-move": e.updateDraggingPosition,
1217
1250
  "on-drag-end": e.stopDraggingElement,
1218
1251
  "is-being-dragged-globally": e.isDraggingElement && e.draggingObject && e.draggingObject.id === d.id,
@@ -1247,20 +1280,20 @@ function De(e, t, i, s, o, a) {
1247
1280
  ]),
1248
1281
  _: 2
1249
1282
  }, 1032, ["object", "pages-scale", "page-width", "page-height", "read-only", "on-update", "on-delete", "on-duplicate", "on-drag-start", "on-drag-move", "on-drag-end", "is-being-dragged-globally", "dragging-client-pos", "current-doc-index", "current-page-index", "global-drag-doc-index", "global-drag-page-index", "show-selection-ui", "show-default-actions", "ignore-click-outside-selectors"]))), 128))
1250
- ], 40, Pe)
1283
+ ], 40, De)
1251
1284
  ], 2),
1252
1285
  e.showPageFooter ? (m(), v("div", Oe, [
1253
- P("span", null, U(r.name), 1),
1254
- P("span", null, U(e.formatPageNumber(c + 1, r.numPages)), 1)
1255
- ])) : $("", !0)
1256
- ], 40, ye)
1286
+ P("span", null, U(h.name), 1),
1287
+ P("span", null, U(e.formatPageNumber(c + 1, h.numPages)), 1)
1288
+ ])) : C("", !0)
1289
+ ], 40, Pe)
1257
1290
  ]))), 128))
1258
1291
  ]))), 128))
1259
- ])) : $("", !0),
1292
+ ])) : C("", !0),
1260
1293
  e.isDraggingElement && e.draggingObject ? (m(), v("div", {
1261
1294
  key: 1,
1262
1295
  class: "drag-portal",
1263
- style: E({
1296
+ style: R({
1264
1297
  position: "fixed",
1265
1298
  left: `${e.draggingClientPosition.x}px`,
1266
1299
  top: `${e.draggingClientPosition.y}px`,
@@ -1278,14 +1311,14 @@ function De(e, t, i, s, o, a) {
1278
1311
  isSelected: !1
1279
1312
  }, void 0, !0)
1280
1313
  ], !0)
1281
- ], 4)) : $("", !0)
1314
+ ], 4)) : C("", !0)
1282
1315
  ], 4);
1283
1316
  }
1284
- const T = /* @__PURE__ */ V(we, [["render", De], ["__scopeId", "data-v-eb792162"]]), Se = (e) => {
1317
+ const T = /* @__PURE__ */ Z(be, [["render", Se], ["__scopeId", "data-v-d63caaf3"]]), Me = (e) => {
1285
1318
  const t = T.name || "PDFElements";
1286
1319
  e.component(t, T);
1287
1320
  };
1288
- T.install = Se;
1321
+ T.install = Me;
1289
1322
  export {
1290
1323
  T as PDFElements,
1291
1324
  T as default,