Skip to content

Commit 14bf95d

Browse files
jtydhr88DrJKL
authored andcommitted
crop box
1 parent 202dc3b commit 14bf95d

File tree

9 files changed

+692
-1
lines changed

9 files changed

+692
-1
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<template>
2+
<div
3+
class="widget-expands relative h-full w-full"
4+
@pointerdown.stop
5+
@pointermove.stop
6+
@pointerup.stop
7+
>
8+
<div
9+
ref="containerEl"
10+
class="relative h-full w-full overflow-hidden rounded-[5px] bg-node-component-surface"
11+
>
12+
<div v-if="isLoading" class="flex size-full items-center justify-center">
13+
<span class="text-sm">{{ $t('imageCrop.loading') }}</span>
14+
</div>
15+
16+
<div
17+
v-else-if="!imageUrl"
18+
class="flex size-full flex-col items-center justify-center text-center"
19+
>
20+
<i class="mb-2 icon-[lucide--image] h-12 w-12" />
21+
<p class="text-sm">{{ $t('imageCrop.noInputImage') }}</p>
22+
</div>
23+
24+
<img
25+
v-else
26+
ref="imageEl"
27+
:src="imageUrl"
28+
:alt="$t('imageCrop.cropPreviewAlt')"
29+
draggable="false"
30+
class="block size-full object-contain select-none brightness-50"
31+
@load="handleImageLoad"
32+
@error="handleImageError"
33+
@dragstart.prevent
34+
/>
35+
36+
<div
37+
v-if="imageUrl && !isLoading"
38+
class="absolute box-border cursor-move overflow-hidden border-2 border-white"
39+
:style="cropBoxStyle"
40+
@pointerdown="handleDragStart"
41+
@pointermove="handleDragMove"
42+
@pointerup="handleDragEnd"
43+
>
44+
<div class="pointer-events-none size-full" :style="cropImageStyle" />
45+
</div>
46+
47+
<div
48+
v-for="handle in resizeHandles"
49+
v-show="imageUrl && !isLoading"
50+
:key="handle.direction"
51+
:class="['absolute', handle.class]"
52+
:style="handle.style"
53+
@pointerdown="(e) => handleResizeStart(e, handle.direction)"
54+
@pointermove="handleResizeMove"
55+
@pointerup="handleResizeEnd"
56+
/>
57+
</div>
58+
</div>
59+
</template>
60+
61+
<script setup lang="ts">
62+
import { useImageCrop } from '@/composables/useImageCrop'
63+
import type { NodeId } from '@/platform/workflow/validation/schemas/workflowSchema'
64+
65+
const props = defineProps<{
66+
nodeId: NodeId
67+
}>()
68+
69+
const {
70+
imageEl,
71+
containerEl,
72+
73+
imageUrl,
74+
isLoading,
75+
76+
cropBoxStyle,
77+
cropImageStyle,
78+
resizeHandles,
79+
80+
handleImageLoad,
81+
handleImageError,
82+
handleDragStart,
83+
handleDragMove,
84+
handleDragEnd,
85+
handleResizeStart,
86+
handleResizeMove,
87+
handleResizeEnd
88+
} = useImageCrop(props.nodeId)
89+
</script>

0 commit comments

Comments
 (0)