From c9e590f301a4aa0ec471b0eee2359aabb8d8f72c Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:40:13 +0000 Subject: [PATCH 1/5] test: verify cropper owns uploaded signature selection size Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/tests/components/Draw/FileUpload.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tests/components/Draw/FileUpload.spec.ts b/src/tests/components/Draw/FileUpload.spec.ts index de01f9d014..4b78fcbfc5 100644 --- a/src/tests/components/Draw/FileUpload.spec.ts +++ b/src/tests/components/Draw/FileUpload.spec.ts @@ -102,6 +102,18 @@ describe('FileUpload.vue - Uploaded signature flow', () => { expect(wrapper.vm.defaultStencilSize).toEqual({ width: 350, height: 100 }) }) + it('delegates initial crop selection size to the cropper', async () => { + const wrapper = mountComponent() + + wrapper.vm.image = 'data:image/png;base64,uploaded' + await wrapper.vm.$nextTick() + + const cropper = wrapper.findComponent({ name: 'Cropper' }) + expect(cropper.exists()).toBe(true) + expect(cropper.props('defaultSize')).toBeUndefined() + expect(cropper.props('stencilProps')).toEqual({ aspectRatio: 3.5 }) + }) + it('loads the selected file as a data URL', () => { const wrapper = mountComponent() const listeners = new Map void>>() From 86587f9c835619a4a45198de83cc94ae409c6aed Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:47:06 +0000 Subject: [PATCH 2/5] fix: restore cropper default selection for uploaded signatures Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/components/Draw/FileUpload.vue | 81 ++------------------ src/tests/components/Draw/FileUpload.spec.ts | 24 +----- 2 files changed, 10 insertions(+), 95 deletions(-) diff --git a/src/components/Draw/FileUpload.vue b/src/components/Draw/FileUpload.vue index babdd5745b..51dc9aafe0 100644 --- a/src/components/Draw/FileUpload.vue +++ b/src/components/Draw/FileUpload.vue @@ -20,11 +20,10 @@ @change="fileSelect"> -
+
@@ -117,7 +116,7 @@ import { mdiMagnifyMinusOutline, mdiMagnifyPlusOutline, } from '@mdi/js' -import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue' +import { computed, nextTick, ref, watch } from 'vue' import { Cropper } from 'vue-advanced-cropper' import { getCapabilities } from '@nextcloud/capabilities' @@ -152,11 +151,6 @@ type CropperInstance = { getResult?: () => CropperResult } -type ResizeObserverLike = { - disconnect: () => void - observe: (target: Element) => void -} - defineOptions({ name: 'FileUpload', }) @@ -187,13 +181,10 @@ const confirmSignatureDialogTitle = t('libresign', 'Confirm your signature') const file = ref(null) const cropper = ref(null) -const cropperContainer = ref(null) -const resizeObserver = ref(null) const modal = ref(false) const image = ref('') const imageData = ref('') -const containerWidth = ref(0) const pendingFitCenter = ref(false) const zoomLevel = ref(1) const zoomMin = 0.1 @@ -226,37 +217,6 @@ const stencilProps = computed(() => ({ aspectRatio: stencilAspectRatio.value, })) -const defaultStencilSize = computed(() => { - if (!containerWidth.value) { - return { - width: stencilBaseWidth, - height: stencilBaseHeight, - } - } - const availableWidth = Math.max(0, containerWidth.value - 24) - const scale = Math.min(1, availableWidth / stencilBaseWidth) - return { - width: Math.floor(stencilBaseWidth * scale), - height: Math.floor(stencilBaseHeight * scale), - } -}) - -function initResizeObserver() { - if (!window.ResizeObserver || !cropperContainer.value) { - return - } - if (!resizeObserver.value) { - resizeObserver.value = new window.ResizeObserver(() => updateContainerWidth()) as ResizeObserverLike - } else { - resizeObserver.value.disconnect() - } - resizeObserver.value.observe(cropperContainer.value) -} - -function updateContainerWidth() { - containerWidth.value = cropperContainer.value?.offsetWidth || 0 -} - function updateZoomLevel(result?: CropperResult) { if (result) { updateZoomLevelFromResult(result) @@ -394,35 +354,12 @@ function close() { emit('close') } -onMounted(() => { - updateContainerWidth() - if (window.ResizeObserver) { - void nextTick(() => { - initResizeObserver() - }) - } else { - window.addEventListener('resize', updateContainerWidth) - } -}) - -onBeforeUnmount(() => { - resizeObserver.value?.disconnect() - window.removeEventListener('resize', updateContainerWidth) -}) - watch(hasImage, value => { - if (value) { - void nextTick(() => { - updateContainerWidth() - initResizeObserver() - }) - return + if (!value) { + zoomLevel.value = 1 + pendingFitCenter.value = false + imageData.value = '' } - resizeObserver.value?.disconnect() - containerWidth.value = 0 - zoomLevel.value = 1 - pendingFitCenter.value = false - imageData.value = '' }) defineExpose({ @@ -432,12 +369,9 @@ defineExpose({ mdiFitToPageOutline, file, cropper, - cropperContainer, - resizeObserver, modal, image, imageData, - containerWidth, pendingFitCenter, zoomLevel, zoomMin, @@ -450,9 +384,6 @@ defineExpose({ zoomPercentValue, stencilAspectRatio, stencilProps, - defaultStencilSize, - initResizeObserver, - updateContainerWidth, updateZoomLevel, updateZoomLevelFromResult, zoomBy, diff --git a/src/tests/components/Draw/FileUpload.spec.ts b/src/tests/components/Draw/FileUpload.spec.ts index 4b78fcbfc5..f2b19d05ff 100644 --- a/src/tests/components/Draw/FileUpload.spec.ts +++ b/src/tests/components/Draw/FileUpload.spec.ts @@ -75,31 +75,18 @@ vi.mock('vue-advanced-cropper', () => ({ describe('FileUpload.vue - Uploaded signature flow', () => { beforeEach(() => { vi.clearAllMocks() - vi.stubGlobal('ResizeObserver', class { - observe = vi.fn() - disconnect = vi.fn() - }) }) function mountComponent() { return mount(FileUpload) } - it('initializes stencil dimensions from capabilities', () => { + it('keeps the configured signature aspect ratio', () => { const wrapper = mountComponent() expect(wrapper.vm.stencilBaseWidth).toBe(700) expect(wrapper.vm.stencilBaseHeight).toBe(200) - expect(wrapper.vm.defaultStencilSize).toEqual({ width: 700, height: 200 }) - }) - - it('scales the default stencil size to fit the cropper container', async () => { - const wrapper = mountComponent() - - wrapper.vm.containerWidth = 374 - await wrapper.vm.$nextTick() - - expect(wrapper.vm.defaultStencilSize).toEqual({ width: 350, height: 100 }) + expect(wrapper.vm.stencilAspectRatio).toBe(3.5) }) it('delegates initial crop selection size to the cropper', async () => { @@ -245,22 +232,19 @@ describe('FileUpload.vue - Uploaded signature flow', () => { }) it('resets crop state when the image is cleared', async () => { - const disconnect = vi.fn() const wrapper = mountComponent() - wrapper.vm.resizeObserver = { observe: vi.fn(), disconnect } - wrapper.vm.containerWidth = 480 wrapper.vm.zoomLevel = 2.4 wrapper.vm.pendingFitCenter = true wrapper.vm.image = 'data:image/png;base64,existing' + wrapper.vm.imageData = 'data:image/png;base64,old-crop' await wrapper.vm.$nextTick() wrapper.vm.image = '' await wrapper.vm.$nextTick() - expect(disconnect).toHaveBeenCalled() - expect(wrapper.vm.containerWidth).toBe(0) expect(wrapper.vm.zoomLevel).toBe(1) expect(wrapper.vm.pendingFitCenter).toBe(false) + expect(wrapper.vm.imageData).toBe('') }) }) From 99f34daa41dcf0bb4025ee2a697e5fe3cd62871c Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:26:37 +0000 Subject: [PATCH 3/5] test: bound cropped signature output dimensions Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/tests/components/Draw/FileUpload.spec.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/tests/components/Draw/FileUpload.spec.ts b/src/tests/components/Draw/FileUpload.spec.ts index f2b19d05ff..cb8e6fbb67 100644 --- a/src/tests/components/Draw/FileUpload.spec.ts +++ b/src/tests/components/Draw/FileUpload.spec.ts @@ -59,7 +59,7 @@ vi.mock('vue-advanced-cropper', () => ({ Cropper: { name: 'Cropper', template: '
', - props: ['src', 'defaultSize', 'stencilProps', 'imageRestriction'], + props: ['src', 'defaultSize', 'stencilProps', 'imageRestriction', 'canvas'], emits: ['change'], methods: { zoom: vi.fn(), @@ -101,6 +101,23 @@ describe('FileUpload.vue - Uploaded signature flow', () => { expect(cropper.props('stencilProps')).toEqual({ aspectRatio: 3.5 }) }) + it('limits exported PNG dimensions while retaining source resolution for small images', async () => { + const wrapper = mountComponent() + wrapper.vm.image = 'data:image/png;base64,uploaded' + await wrapper.vm.$nextTick() + + const cropper = wrapper.findComponent({ name: 'Cropper' }) + const canvas = cropper.props('canvas') + + expect(canvas).toEqual({ + maxWidth: 2100, + maxHeight: 600, + maxArea: 1_000_000, + }) + expect(canvas).not.toHaveProperty('width') + expect(canvas).not.toHaveProperty('height') + }) + it('loads the selected file as a data URL', () => { const wrapper = mountComponent() const listeners = new Map void>>() From 8a619469a23c1b7d191ed42092e436794cfb7dfd Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:27:05 +0000 Subject: [PATCH 4/5] fix: cap cropped signature PNG to backend size budget Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/components/Draw/FileUpload.vue | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/Draw/FileUpload.vue b/src/components/Draw/FileUpload.vue index 51dc9aafe0..38c2f2cbd1 100644 --- a/src/components/Draw/FileUpload.vue +++ b/src/components/Draw/FileUpload.vue @@ -25,6 +25,7 @@ ref="cropper" :src="image" :stencil-props="stencilProps" + :canvas="canvasConstraints" image-restriction="none" @change="change" />
@@ -217,6 +218,16 @@ const stencilProps = computed(() => ({ aspectRatio: stencilAspectRatio.value, })) +// Keep the source resolution where possible, but bound the exported PNG. +// A one-megapixel RGBA canvas stays under the backend's 5000 KiB image limit. +const canvasConstraints = computed(() => ({ + maxWidth: Number.isFinite(stencilBaseWidth) && stencilBaseWidth > 0 + ? stencilBaseWidth * 3 : undefined, + maxHeight: Number.isFinite(stencilBaseHeight) && stencilBaseHeight > 0 + ? stencilBaseHeight * 3 : undefined, + maxArea: 1_000_000, +})) + function updateZoomLevel(result?: CropperResult) { if (result) { updateZoomLevelFromResult(result) From 19a560b595bcfc5ea35762bffc4cb4aae7b997f1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:30:59 +0000 Subject: [PATCH 5/5] style: format cropper canvas constraints for ESLint Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/components/Draw/FileUpload.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Draw/FileUpload.vue b/src/components/Draw/FileUpload.vue index 38c2f2cbd1..a90b9e7d6c 100644 --- a/src/components/Draw/FileUpload.vue +++ b/src/components/Draw/FileUpload.vue @@ -222,9 +222,11 @@ const stencilProps = computed(() => ({ // A one-megapixel RGBA canvas stays under the backend's 5000 KiB image limit. const canvasConstraints = computed(() => ({ maxWidth: Number.isFinite(stencilBaseWidth) && stencilBaseWidth > 0 - ? stencilBaseWidth * 3 : undefined, + ? stencilBaseWidth * 3 + : undefined, maxHeight: Number.isFinite(stencilBaseHeight) && stencilBaseHeight > 0 - ? stencilBaseHeight * 3 : undefined, + ? stencilBaseHeight * 3 + : undefined, maxArea: 1_000_000, }))