@libresign/pdf-elements 0.2.3 → 0.2.5
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 +1 -0
- package/dist/pdf-elements.common.js +25289 -24966
- package/dist/pdf-elements.common.js.map +1 -1
- package/dist/pdf-elements.css +1 -1
- package/dist/pdf-elements.umd.js +25289 -24966
- package/dist/pdf-elements.umd.js.map +1 -1
- package/dist/pdf-elements.umd.min.js +2 -2
- package/dist/pdf-elements.umd.min.js.map +1 -1
- package/package.json +1 -2
- package/src/components/DraggableElement.vue +58 -22
- package/src/components/PDFElements.vue +377 -171
- package/src/components/PDFPage.vue +31 -8
- package/src/index.js +0 -5
- package/src/utils/geometry.js +20 -0
- package/src/utils/measurements.js +16 -0
- package/src/utils/objectStore.js +35 -0
- package/src/utils/pageBounds.js +13 -0
- package/src/utils/zoom.js +8 -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.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"author": "LibreCode <contact@librecode.coop>",
|
|
6
6
|
"private": false,
|
|
7
7
|
"main": "dist/pdf-elements.umd.js",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"lint:fix": "vue-cli-service lint"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"debounce": "^3.0.0",
|
|
35
34
|
"pdfjs-dist": "^5.4.530",
|
|
36
35
|
"vue": "^2.7.16"
|
|
37
36
|
},
|
|
@@ -120,6 +120,10 @@ export default {
|
|
|
120
120
|
showDefaultActions: {
|
|
121
121
|
type: Boolean,
|
|
122
122
|
default: true,
|
|
123
|
+
},
|
|
124
|
+
readOnly: {
|
|
125
|
+
type: Boolean,
|
|
126
|
+
default: false,
|
|
123
127
|
}
|
|
124
128
|
},
|
|
125
129
|
data() {
|
|
@@ -153,25 +157,44 @@ export default {
|
|
|
153
157
|
},
|
|
154
158
|
elementStyle() {
|
|
155
159
|
const scale = this.pagesScale || 1
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
+
const isDragging = this.mode === 'drag'
|
|
161
|
+
const isResizing = this.mode === 'resize'
|
|
162
|
+
const offsetX = isDragging ? this.offsetX : 0
|
|
163
|
+
const offsetY = isDragging ? this.offsetY : 0
|
|
164
|
+
const resizeOffsetX = isResizing ? this.resizeOffsetX : 0
|
|
165
|
+
const resizeOffsetY = isResizing ? this.resizeOffsetY : 0
|
|
166
|
+
const resizeOffsetW = isResizing ? this.resizeOffsetW : 0
|
|
167
|
+
const resizeOffsetH = isResizing ? this.resizeOffsetH : 0
|
|
168
|
+
const currentX = this.object.x + offsetX + resizeOffsetX
|
|
169
|
+
const currentY = this.object.y + offsetY + resizeOffsetY
|
|
170
|
+
const currentWidth = this.object.width + resizeOffsetW
|
|
171
|
+
const currentHeight = this.object.height + resizeOffsetH
|
|
160
172
|
return {
|
|
161
173
|
left: `${currentX * scale}px`,
|
|
162
174
|
top: `${currentY * scale}px`,
|
|
163
175
|
width: `${currentWidth * scale}px`,
|
|
164
176
|
height: `${currentHeight * scale}px`,
|
|
177
|
+
pointerEvents: this.readOnly ? 'none' : 'auto',
|
|
165
178
|
}
|
|
166
179
|
},
|
|
167
180
|
toolbarStyle() {
|
|
168
181
|
const scale = this.pagesScale || 1
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const
|
|
182
|
+
const isDragging = this.mode === 'drag'
|
|
183
|
+
const isResizing = this.mode === 'resize'
|
|
184
|
+
const offsetX = isDragging ? this.offsetX : 0
|
|
185
|
+
const offsetY = isDragging ? this.offsetY : 0
|
|
186
|
+
const resizeOffsetX = isResizing ? this.resizeOffsetX : 0
|
|
187
|
+
const resizeOffsetY = isResizing ? this.resizeOffsetY : 0
|
|
188
|
+
const resizeOffsetW = isResizing ? this.resizeOffsetW : 0
|
|
189
|
+
const x = this.object.x + offsetX + resizeOffsetX
|
|
190
|
+
const y = this.object.y + offsetY + resizeOffsetY
|
|
191
|
+
const width = this.object.width + resizeOffsetW
|
|
192
|
+
const toolbarOffset = 60
|
|
193
|
+
const nextTop = y - toolbarOffset
|
|
194
|
+
const top = nextTop < 0 ? (y + 8) : nextTop
|
|
172
195
|
return {
|
|
173
196
|
left: `${(x + width / 2) * scale}px`,
|
|
174
|
-
top: `${
|
|
197
|
+
top: `${top * scale}px`,
|
|
175
198
|
transform: 'translateX(-50%)',
|
|
176
199
|
}
|
|
177
200
|
},
|
|
@@ -203,6 +226,9 @@ export default {
|
|
|
203
226
|
},
|
|
204
227
|
methods: {
|
|
205
228
|
handleElementClick(event) {
|
|
229
|
+
if (this.readOnly) {
|
|
230
|
+
return
|
|
231
|
+
}
|
|
206
232
|
if (event.target.closest('.delete-handle') || event.target.closest('[data-stop-drag]') || event.target.closest('.actions-toolbar')) {
|
|
207
233
|
return
|
|
208
234
|
}
|
|
@@ -220,6 +246,7 @@ export default {
|
|
|
220
246
|
this.startResize(direction, event)
|
|
221
247
|
},
|
|
222
248
|
startDrag(event) {
|
|
249
|
+
if (this.readOnly) return
|
|
223
250
|
if (event.target.classList.contains('delete')) return
|
|
224
251
|
if (event.target.classList.contains('resize-handle')) return
|
|
225
252
|
this.mode = 'drag'
|
|
@@ -256,6 +283,7 @@ export default {
|
|
|
256
283
|
window.addEventListener('touchend', this.boundStopInteraction)
|
|
257
284
|
},
|
|
258
285
|
startResize(direction, event) {
|
|
286
|
+
if (this.readOnly) return
|
|
259
287
|
this.mode = 'resize'
|
|
260
288
|
this.direction = direction
|
|
261
289
|
this.startX = event.type.includes('touch') ? event.touches[0].clientX : event.clientX
|
|
@@ -318,7 +346,7 @@ export default {
|
|
|
318
346
|
return
|
|
319
347
|
}
|
|
320
348
|
|
|
321
|
-
const minSize = 16
|
|
349
|
+
const minSize = 16 / (this.pagesScale || 1)
|
|
322
350
|
let newWidth = this.startWidth
|
|
323
351
|
let newHeight = this.startHeight
|
|
324
352
|
let newLeft = this.startLeft
|
|
@@ -442,7 +470,7 @@ export default {
|
|
|
442
470
|
border-radius: 6px;
|
|
443
471
|
padding: 6px 8px;
|
|
444
472
|
box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.15), 0 2px 6px -2px rgba(0, 0, 0, 0.1);
|
|
445
|
-
z-index:
|
|
473
|
+
z-index: 5;
|
|
446
474
|
white-space: nowrap;
|
|
447
475
|
}
|
|
448
476
|
.action-btn {
|
|
@@ -471,35 +499,43 @@ export default {
|
|
|
471
499
|
box-shadow: inset 0 0 0 2px #2563eb;
|
|
472
500
|
}
|
|
473
501
|
.resize-handle {
|
|
502
|
+
all: unset;
|
|
474
503
|
position: absolute;
|
|
475
|
-
width:
|
|
476
|
-
height:
|
|
504
|
+
width: 12px;
|
|
505
|
+
height: 12px;
|
|
506
|
+
min-width: 0;
|
|
507
|
+
min-height: 0;
|
|
477
508
|
background: #2563eb;
|
|
478
509
|
border: 1px solid #ffffff;
|
|
479
|
-
border-radius:
|
|
510
|
+
border-radius: 3px;
|
|
480
511
|
padding: 0;
|
|
481
512
|
margin: 0;
|
|
513
|
+
line-height: 0;
|
|
514
|
+
font-size: 0;
|
|
515
|
+
box-sizing: border-box;
|
|
516
|
+
display: block;
|
|
517
|
+
appearance: none;
|
|
482
518
|
cursor: pointer;
|
|
483
|
-
z-index:
|
|
519
|
+
z-index: 5;
|
|
484
520
|
}
|
|
485
521
|
.handle-top-left {
|
|
486
|
-
top: -
|
|
487
|
-
left: -
|
|
522
|
+
top: -7px;
|
|
523
|
+
left: -7px;
|
|
488
524
|
cursor: nwse-resize;
|
|
489
525
|
}
|
|
490
526
|
.handle-top-right {
|
|
491
|
-
top: -
|
|
492
|
-
right: -
|
|
527
|
+
top: -7px;
|
|
528
|
+
right: -7px;
|
|
493
529
|
cursor: nesw-resize;
|
|
494
530
|
}
|
|
495
531
|
.handle-bottom-left {
|
|
496
|
-
bottom: -
|
|
497
|
-
left: -
|
|
532
|
+
bottom: -7px;
|
|
533
|
+
left: -7px;
|
|
498
534
|
cursor: nesw-resize;
|
|
499
535
|
}
|
|
500
536
|
.handle-bottom-right {
|
|
501
|
-
bottom: -
|
|
502
|
-
right: -
|
|
537
|
+
bottom: -7px;
|
|
538
|
+
right: -7px;
|
|
503
539
|
cursor: nwse-resize;
|
|
504
540
|
}
|
|
505
541
|
</style>
|