Skip to content

Commit bfea950

Browse files
authored
Merge pull request #119 from LibreSign/chore/remove-send-canvas-dimensions
Chore/remove send canvas dimensions
2 parents 0e5e816 + e4efdbc commit bfea950

7 files changed

+29
-60
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ pnpm-debug.log*
2323
# Build files
2424
dist
2525
lib
26+
27+
package-lock.json

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@libresign/vue-pdf-editor",
33
"description": "vue2 pdf editor component",
4-
"version": "1.4.4",
4+
"version": "1.4.5",
55
"author": "LibreCode",
66
"private": false,
77
"main": "dist/vue-pdf-editor.umd.js",

src/Components/Drawing.vue

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export default {
5858
'x',
5959
'y',
6060
'pageScale',
61-
'canvasWidth',
62-
'canvasHeight',
6361
'path',
6462
],
6563
data() {

src/Components/Image.vue

-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ export default {
7474
'x',
7575
'y',
7676
'pageScale',
77-
'canvasWidth',
78-
'canvasHeight',
7977
'fixSize',
8078
],
8179
data() {

src/Components/ItemEventsMixin.vue

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ export default {
55
return {
66
x_mixin: null,
77
y_mixin: null,
8+
pageWidth: 0,
9+
pageHeight: 0,
810
}
911
},
1012
mounted() {
11-
// this.$refs.canvasElement.addEventListener('mousedown', this.handleMousedown);
12-
// this.$refs.canvasElement.addEventListener('touchstart', this.handleTouchStart);
13-
},
14-
beforeDestroy() {
15-
// this.$refs.canvasElement.removeEventListener('mousedown', this.handleMousedown);
16-
// this.$refs.canvasElement.removeEventListener('touchstart', this.handleTouchStart);
13+
const page = this.$el.closest('.page')
14+
if (page) {
15+
const canvas = page.querySelector('canvas')
16+
this.pageWidth = canvas.width
17+
this.pageHeight = canvas.height
18+
}
1719
},
1820
created() {},
1921
methods: {
@@ -44,8 +46,8 @@ export default {
4446
this.y_mixin = event.clientY
4547
window.removeEventListener('mousemove', this.handlePanMove)
4648
window.removeEventListener('mouseup', this.handlePanEnd)
47-
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
48-
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
49+
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
50+
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
4951
return {
5052
detail: { x, y },
5153
}
@@ -84,19 +86,17 @@ export default {
8486
8587
window.removeEventListener('touchmove', this.handlePanMove)
8688
window.removeEventListener('touchend', this.handlePanEnd)
87-
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
88-
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
89+
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
90+
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
8991
return {
9092
detail: { x, y },
9193
}
9294
},
9395
translateCoordinates() {
94-
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
95-
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
96+
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
97+
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
9698
return 'translate(' + x + 'px, ' + y + 'px)'
9799
}
98100
},
99101
}
100102
</script>
101-
102-
<style scoped></style>

src/Components/TextItem.vue

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ export default {
149149
'y',
150150
'fontFamily',
151151
'pageScale',
152-
'canvasWidth',
153-
'canvasHeight',
154152
'currentPage',
155153
'showLineSizeSelect',
156154
'showFontSelect',

src/VuePdfEditor.vue

+12-39
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
@mousedown="selectPage(pIndex)"
113113
@touchstart="selectPage(pIndex)">
114114
<div style="display: inline-block;"
115-
class="relative shadow-lg"
115+
class="relative shadow-lg page"
116116
:class="[pIndex === selectedPageIndex ?'shadowOutline':'']">
117117
<PDFPage :ref="`page${pIndex}`"
118118
:scale="scale"
@@ -127,8 +127,6 @@
127127
<slot name="custom"
128128
:object="object"
129129
:pagesScale="pagesScale[pIndex]"
130-
:canvas-width="object.canvasWidth"
131-
:canvas-height="object.canvasHeight"
132130
@onUpdate="updateObject(object.id, $event)"
133131
@onDelete="deleteObject(object.id)" />
134132
</div>
@@ -143,8 +141,6 @@
143141
:origin-width="object.originWidth"
144142
:origin-height="object.originHeight"
145143
:page-scale="pagesScale[pIndex]"
146-
:canvas-width="object.canvasWidth"
147-
:canvas-height="object.canvasHeight"
148144
@onUpdate="updateObject(object.id, $event)"
149145
@onDelete="deleteObject(object.id)" />
150146
</div>
@@ -163,8 +159,6 @@
163159
:font-family="object.fontFamily"
164160
:current-page="object.currentPage"
165161
:page-scale="pagesScale[pIndex]"
166-
:canvas-width="object.canvasWidth"
167-
:canvas-height="object.canvasHeight"
168162
@onUpdate="updateObject(object.id, $event)"
169163
@onDelete="deleteObject(object.id)"
170164
@onSelectFont="selectFontFamily" />
@@ -178,8 +172,6 @@
178172
:origin-width="object.originWidth"
179173
:origin-height="object.originHeight"
180174
:page-scale="pagesScale[pIndex]"
181-
:canvas-width="object.canvasWidth"
182-
:canvas-height="object.canvasHeight"
183175
@onUpdate="updateObject(object.id, $event)"
184176
@onDelete="deleteObject(object.id)" />
185177
</div>
@@ -520,15 +512,17 @@ export default {
520512
measurement: [],
521513
}
522514
// Wait until all pages have been read
523-
const pages = await Promise.all(this.pages);
524-
pages.forEach((page) => {
525-
const measurement = page.getViewport().viewBox
526-
data.measurement[page.pageNumber] = {
527-
width: measurement[2],
528-
height: measurement[3],
529-
}
530-
})
531-
this.$emit('pdf-editor:end-init', data)
515+
Promise.all(this.pages)
516+
.then(pages => {
517+
pages.forEach((page) => {
518+
const measurement = page.getViewport().viewBox
519+
data.measurement[page.pageNumber] = {
520+
width: measurement[2],
521+
height: measurement[3],
522+
}
523+
})
524+
this.$emit('pdf-editor:end-init', data)
525+
})
532526
}
533527
} catch (e) {
534528
console.log('Failed to add pdf.')
@@ -555,20 +549,13 @@ export default {
555549
const id = this.genID()
556550
const { width, height } = img
557551
558-
const { canvasWidth, canvasHeight }
559-
= this.$refs[
560-
`page${this.selectedPageIndex}`
561-
][0].getCanvasMeasurement()
562-
563552
const object = {
564553
id,
565554
type: 'image',
566555
width: width * sizeNarrow,
567556
height: height * sizeNarrow,
568557
originWidth: width,
569558
originHeight: height,
570-
canvasWidth,
571-
canvasHeight,
572559
x,
573560
y,
574561
isSealImage,
@@ -590,20 +577,13 @@ export default {
590577
const id = this.genID()
591578
fetchFont(this.currentFont)
592579
593-
const { canvasWidth, canvasHeight }
594-
= this.$refs[
595-
`page${this.selectedPageIndex}`
596-
][0].getCanvasMeasurement()
597-
598580
const object = {
599581
id,
600582
text,
601583
type: 'text',
602584
size: this.textDefaultSize,
603585
lineHeight: 1.4,
604586
fontFamily: this.currentFont,
605-
canvasWidth,
606-
canvasHeight,
607587
x,
608588
y,
609589
currentPage,
@@ -620,11 +600,6 @@ export default {
620600
addDrawing(originWidth, originHeight, path, scale = 1) {
621601
const id = this.genID()
622602
623-
const { canvasWidth, canvasHeight }
624-
= this.$refs[
625-
`page${this.selectedPageIndex}`
626-
][0].getCanvasMeasurement()
627-
628603
const object = {
629604
id,
630605
path,
@@ -635,8 +610,6 @@ export default {
635610
originHeight,
636611
width: originWidth * scale,
637612
height: originHeight * scale,
638-
canvasWidth,
639-
canvasHeight,
640613
scale,
641614
}
642615
this.addObject(object)

0 commit comments

Comments
 (0)