@libresign/pdf-elements 0.1.2 → 0.2.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/README.md +14 -12
- package/dist/pdf-elements.common.js +31 -4
- package/dist/pdf-elements.common.js.map +1 -1
- package/dist/pdf-elements.css +1 -1
- package/dist/pdf-elements.umd.js +31 -4
- package/dist/pdf-elements.umd.js.map +1 -1
- package/dist/pdf-elements.umd.min.js +1 -1
- package/dist/pdf-elements.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/PDFElements.vue +33 -0
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.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"author": "LibreCode <contact@librecode.coop>",
|
|
6
6
|
"private": false,
|
|
7
7
|
"main": "dist/pdf-elements.umd.js",
|
|
@@ -179,6 +179,10 @@ export default {
|
|
|
179
179
|
type: String,
|
|
180
180
|
default: '{currentPage} of {totalPages}',
|
|
181
181
|
},
|
|
182
|
+
autoFitZoom: {
|
|
183
|
+
type: Boolean,
|
|
184
|
+
default: false,
|
|
185
|
+
},
|
|
182
186
|
},
|
|
183
187
|
data() {
|
|
184
188
|
return {
|
|
@@ -224,6 +228,9 @@ export default {
|
|
|
224
228
|
window.addEventListener('resize', this.onViewportScroll)
|
|
225
229
|
this.$el?.addEventListener('scroll', this.onViewportScroll, { passive: true })
|
|
226
230
|
this.$el?.addEventListener('wheel', this.boundHandleWheel, { passive: false })
|
|
231
|
+
if (this.autoFitZoom) {
|
|
232
|
+
window.addEventListener('resize', this.adjustZoomToFit)
|
|
233
|
+
}
|
|
227
234
|
},
|
|
228
235
|
beforeUnmount() {
|
|
229
236
|
if (this.zoomRafId) {
|
|
@@ -241,6 +248,9 @@ export default {
|
|
|
241
248
|
window.removeEventListener('scroll', this.onViewportScroll)
|
|
242
249
|
window.removeEventListener('resize', this.onViewportScroll)
|
|
243
250
|
this.$el?.removeEventListener('scroll', this.onViewportScroll)
|
|
251
|
+
if (this.autoFitZoom) {
|
|
252
|
+
window.removeEventListener('resize', this.adjustZoomToFit)
|
|
253
|
+
}
|
|
244
254
|
if (this.viewportRafId) {
|
|
245
255
|
window.cancelAnimationFrame(this.viewportRafId)
|
|
246
256
|
this.viewportRafId = 0
|
|
@@ -804,6 +814,29 @@ export default {
|
|
|
804
814
|
const pagesScale = doc.pagesScale[pageIndex] || 1
|
|
805
815
|
return pageRef.getCanvasMeasurement().canvasHeight / pagesScale
|
|
806
816
|
},
|
|
817
|
+
calculateOptimalScale(maxPageWidth) {
|
|
818
|
+
const containerWidth = this.$el?.clientWidth || 0
|
|
819
|
+
if (!containerWidth || !maxPageWidth) return 1
|
|
820
|
+
|
|
821
|
+
const availableWidth = containerWidth - 40
|
|
822
|
+
return Math.max(0.1, Math.min(2, availableWidth / maxPageWidth))
|
|
823
|
+
},
|
|
824
|
+
adjustZoomToFit() {
|
|
825
|
+
if (!this.autoFitZoom || !this.pdfDocuments.length) return
|
|
826
|
+
|
|
827
|
+
const canvases = this.$el?.querySelectorAll('canvas')
|
|
828
|
+
if (!canvases?.length) return
|
|
829
|
+
|
|
830
|
+
const maxCanvasWidth = Math.max(...Array.from(canvases).map(canvas =>
|
|
831
|
+
canvas.width / (this.scale || 1),
|
|
832
|
+
))
|
|
833
|
+
|
|
834
|
+
const optimalScale = this.calculateOptimalScale(maxCanvasWidth)
|
|
835
|
+
if (Math.abs(optimalScale - this.scale) > 0.01) {
|
|
836
|
+
this.scale = optimalScale
|
|
837
|
+
this.visualScale = optimalScale
|
|
838
|
+
}
|
|
839
|
+
},
|
|
807
840
|
},
|
|
808
841
|
}
|
|
809
842
|
</script>
|