diff --git a/.gitignore b/.gitignore index 5be2a45..241560d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ pnpm-debug.log* # Build files dist lib + +package-lock.json diff --git a/package.json b/package.json index 272461b..9581a5e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@libresign/vue-pdf-editor", "description": "vue2 pdf editor component", - "version": "1.4.4", + "version": "1.4.5", "author": "LibreCode", "private": false, "main": "dist/vue-pdf-editor.umd.js", diff --git a/src/Components/Drawing.vue b/src/Components/Drawing.vue index 5da9384..2fe829d 100644 --- a/src/Components/Drawing.vue +++ b/src/Components/Drawing.vue @@ -58,8 +58,6 @@ export default { 'x', 'y', 'pageScale', - 'canvasWidth', - 'canvasHeight', 'path', ], data() { diff --git a/src/Components/Image.vue b/src/Components/Image.vue index f99bfe1..59303ec 100644 --- a/src/Components/Image.vue +++ b/src/Components/Image.vue @@ -74,8 +74,6 @@ export default { 'x', 'y', 'pageScale', - 'canvasWidth', - 'canvasHeight', 'fixSize', ], data() { diff --git a/src/Components/ItemEventsMixin.vue b/src/Components/ItemEventsMixin.vue index 31765ce..f99f3e7 100644 --- a/src/Components/ItemEventsMixin.vue +++ b/src/Components/ItemEventsMixin.vue @@ -5,15 +5,17 @@ export default { return { x_mixin: null, y_mixin: null, + pageWidth: 0, + pageHeight: 0, } }, mounted() { - // this.$refs.canvasElement.addEventListener('mousedown', this.handleMousedown); - // this.$refs.canvasElement.addEventListener('touchstart', this.handleTouchStart); - }, - beforeDestroy() { - // this.$refs.canvasElement.removeEventListener('mousedown', this.handleMousedown); - // this.$refs.canvasElement.removeEventListener('touchstart', this.handleTouchStart); + const page = this.$el.closest('.page') + if (page) { + const canvas = page.querySelector('canvas') + this.pageWidth = canvas.width + this.pageHeight = canvas.height + } }, created() {}, methods: { @@ -44,8 +46,8 @@ export default { this.y_mixin = event.clientY window.removeEventListener('mousemove', this.handlePanMove) window.removeEventListener('mouseup', this.handlePanEnd) - const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width)) - const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height)) + const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width)) + const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height)) return { detail: { x, y }, } @@ -84,19 +86,17 @@ export default { window.removeEventListener('touchmove', this.handlePanMove) window.removeEventListener('touchend', this.handlePanEnd) - const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width)) - const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height)) + const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width)) + const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height)) return { detail: { x, y }, } }, translateCoordinates() { - const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width)) - const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height)) + const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width)) + const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height)) return 'translate(' + x + 'px, ' + y + 'px)' } }, } - - diff --git a/src/Components/TextItem.vue b/src/Components/TextItem.vue index dc4dd9a..5515553 100644 --- a/src/Components/TextItem.vue +++ b/src/Components/TextItem.vue @@ -149,8 +149,6 @@ export default { 'y', 'fontFamily', 'pageScale', - 'canvasWidth', - 'canvasHeight', 'currentPage', 'showLineSizeSelect', 'showFontSelect', diff --git a/src/VuePdfEditor.vue b/src/VuePdfEditor.vue index 5d4c8e0..0bb3417 100644 --- a/src/VuePdfEditor.vue +++ b/src/VuePdfEditor.vue @@ -112,7 +112,7 @@ @mousedown="selectPage(pIndex)" @touchstart="selectPage(pIndex)">