Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ A Vue 2 component for rendering PDFs with draggable and resizable element overla
| `hideSelectionUI` | Boolean | `false` | Hide selection handles and actions UI |
| `showSelectionHandles` | Boolean | `true` | Show resize/move handles on selected elements |
| `showElementActions` | Boolean | `true` | Show action buttons on selected elements |
| `readOnly` | Boolean | `false` | Disable drag, resize, and actions for elements |
| `pageCountFormat` | String | `'{currentPage} of {totalPages}'` | Format string for page counter |
| `autoFitZoom` | Boolean | `false` | Automatically adjust zoom to fit viewport on window resize |

Expand Down
10 changes: 10 additions & 0 deletions src/components/DraggableElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export default {
showDefaultActions: {
type: Boolean,
default: true,
},
readOnly: {
type: Boolean,
default: false,
}
},
data() {
Expand Down Expand Up @@ -170,6 +174,7 @@ export default {
top: `${currentY * scale}px`,
width: `${currentWidth * scale}px`,
height: `${currentHeight * scale}px`,
pointerEvents: this.readOnly ? 'none' : 'auto',
}
},
toolbarStyle() {
Expand Down Expand Up @@ -218,6 +223,9 @@ export default {
},
methods: {
handleElementClick(event) {
if (this.readOnly) {
return
}
if (event.target.closest('.delete-handle') || event.target.closest('[data-stop-drag]') || event.target.closest('.actions-toolbar')) {
return
}
Expand All @@ -235,6 +243,7 @@ export default {
this.startResize(direction, event)
},
startDrag(event) {
if (this.readOnly) return
if (event.target.classList.contains('delete')) return
if (event.target.classList.contains('resize-handle')) return
this.mode = 'drag'
Expand Down Expand Up @@ -271,6 +280,7 @@ export default {
window.addEventListener('touchend', this.boundStopInteraction)
},
startResize(direction, event) {
if (this.readOnly) return
this.mode = 'resize'
this.direction = direction
this.startX = event.type.includes('touch') ? event.touches[0].clientX : event.clientX
Expand Down
14 changes: 14 additions & 0 deletions src/components/PDFElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
:pages-scale="getRenderPageScale(docIndex, pIndex)"
:page-width="getPageWidth(docIndex, pIndex)"
:page-height="getPageHeight(docIndex, pIndex)"
:read-only="readOnly"
:on-update="(payload) => updateObject(docIndex, object.id, payload)"
:on-delete="() => deleteObject(docIndex, object.id)"
:on-drag-start="(mouseX, mouseY, pointerOffset, dragShift) => startDraggingElement(docIndex, pIndex, object, mouseX, mouseY, pointerOffset, dragShift)"
Expand Down Expand Up @@ -183,6 +184,10 @@ export default {
type: Boolean,
default: true,
},
readOnly: {
type: Boolean,
default: false,
},
pageCountFormat: {
type: String,
default: '{currentPage} of {totalPages}',
Expand Down Expand Up @@ -222,6 +227,7 @@ export default {
debouncedApplyZoom: null,
visualScale: this.initialScale,
autoFitApplied: false,
lastContainerWidth: 0,
}
},
mounted() {
Expand Down Expand Up @@ -450,6 +456,14 @@ export default {
if (this.isAddingMode || this.isDraggingElement) {
this.cachePageBounds()
}
if (this.autoFitZoom && !this.isAddingMode && !this.isDraggingElement) {
const containerWidth = this.$el?.clientWidth || 0
if (containerWidth && containerWidth !== this.lastContainerWidth) {
this.lastContainerWidth = containerWidth
this.autoFitApplied = false
this.scheduleAutoFitZoom()
}
}
this.viewportRafId = 0
})
},
Expand Down