@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/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.3",
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 currentX = this.object.x + this.offsetX + this.resizeOffsetX
157
- const currentY = this.object.y + this.offsetY + this.resizeOffsetY
158
- const currentWidth = this.object.width + this.resizeOffsetW
159
- const currentHeight = this.object.height + this.resizeOffsetH
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 x = this.object.x + this.offsetX + this.resizeOffsetX
170
- const y = this.object.y + this.offsetY + this.resizeOffsetY
171
- const width = this.object.width + this.resizeOffsetW
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: `${(y - 48) * scale}px`,
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: 100;
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: 10px;
476
- height: 10px;
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: 2px;
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: 200;
519
+ z-index: 5;
484
520
  }
485
521
  .handle-top-left {
486
- top: -6px;
487
- left: -6px;
522
+ top: -7px;
523
+ left: -7px;
488
524
  cursor: nwse-resize;
489
525
  }
490
526
  .handle-top-right {
491
- top: -6px;
492
- right: -6px;
527
+ top: -7px;
528
+ right: -7px;
493
529
  cursor: nesw-resize;
494
530
  }
495
531
  .handle-bottom-left {
496
- bottom: -6px;
497
- left: -6px;
532
+ bottom: -7px;
533
+ left: -7px;
498
534
  cursor: nesw-resize;
499
535
  }
500
536
  .handle-bottom-right {
501
- bottom: -6px;
502
- right: -6px;
537
+ bottom: -7px;
538
+ right: -7px;
503
539
  cursor: nwse-resize;
504
540
  }
505
541
  </style>