@libresign/pdf-elements 0.2.2 → 0.2.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@libresign/pdf-elements",
3
3
  "description": "PDF viewer with draggable and resizable element overlays for Vue 2",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "author": "LibreCode <contact@librecode.coop>",
6
6
  "private": false,
7
7
  "main": "dist/pdf-elements.umd.js",
@@ -213,7 +213,7 @@ export default {
213
213
  boundHandleWheel: null,
214
214
  debouncedApplyZoom: null,
215
215
  visualScale: this.initialScale,
216
- resizeObserver: null,
216
+ autoFitApplied: false,
217
217
  }
218
218
  },
219
219
  mounted() {
@@ -229,17 +229,6 @@ export default {
229
229
  window.addEventListener('resize', this.onViewportScroll)
230
230
  this.$el?.addEventListener('scroll', this.onViewportScroll, { passive: true })
231
231
  this.$el?.addEventListener('wheel', this.boundHandleWheel, { passive: false })
232
- if (this.autoFitZoom) {
233
- window.addEventListener('resize', this.adjustZoomToFit)
234
- if (typeof ResizeObserver !== 'undefined') {
235
- this.resizeObserver = new ResizeObserver(() => {
236
- this.scheduleAutoFitZoom()
237
- })
238
- if (this.$el) {
239
- this.resizeObserver.observe(this.$el)
240
- }
241
- }
242
- }
243
232
  },
244
233
  beforeUnmount() {
245
234
  if (this.zoomRafId) {
@@ -257,13 +246,6 @@ export default {
257
246
  window.removeEventListener('scroll', this.onViewportScroll)
258
247
  window.removeEventListener('resize', this.onViewportScroll)
259
248
  this.$el?.removeEventListener('scroll', this.onViewportScroll)
260
- if (this.autoFitZoom) {
261
- window.removeEventListener('resize', this.adjustZoomToFit)
262
- if (this.resizeObserver) {
263
- this.resizeObserver.disconnect()
264
- this.resizeObserver = null
265
- }
266
- }
267
249
  if (this.viewportRafId) {
268
250
  window.cancelAnimationFrame(this.viewportRafId)
269
251
  this.viewportRafId = 0
@@ -273,6 +255,7 @@ export default {
273
255
  async init() {
274
256
  if (!this.initFiles || this.initFiles.length === 0) return
275
257
  const docs = []
258
+ this.autoFitApplied = false
276
259
 
277
260
  for (let i = 0; i < this.initFiles.length; i++) {
278
261
  const file = this.initFiles[i]
@@ -852,6 +835,7 @@ export default {
852
835
  return Math.max(0.1, Math.min(2, availableWidth / maxPageWidth))
853
836
  },
854
837
  scheduleAutoFitZoom() {
838
+ if (this.autoFitApplied) return
855
839
  if (this.zoomRafId) return
856
840
  this.zoomRafId = window.requestAnimationFrame(() => {
857
841
  this.zoomRafId = 0
@@ -859,7 +843,7 @@ export default {
859
843
  })
860
844
  },
861
845
  adjustZoomToFit() {
862
- if (!this.autoFitZoom || !this.pdfDocuments.length) return
846
+ if (!this.autoFitZoom || this.autoFitApplied || !this.pdfDocuments.length) return
863
847
 
864
848
  const widths = this.pdfDocuments
865
849
  .flatMap(doc => doc.pageWidths || [])
@@ -881,6 +865,7 @@ export default {
881
865
  }
882
866
 
883
867
  const optimalScale = this.calculateOptimalScale(maxCanvasWidth)
868
+ this.autoFitApplied = true
884
869
  if (Math.abs(optimalScale - this.scale) > 0.01) {
885
870
  this.scale = optimalScale
886
871
  this.visualScale = optimalScale