feat(cropper): add aspect ratio options (1:1, 4:3, 16:9, free) and fix styling

This commit is contained in:
2026-02-04 15:41:01 +01:00
parent 3a7413e59a
commit 220599944c
9 changed files with 476 additions and 23 deletions

View File

@@ -5,6 +5,7 @@ import { directus } from '../../services/directus.js'
import { SUPPORTED_CURRENCIES } from '../../services/currency.js'
import '../location-picker.js'
import '../pow-captcha.js'
import '../image-cropper.js'
const STORAGE_KEY = 'dgray_create_draft'
@@ -359,6 +360,8 @@ class PageCreate extends HTMLElement {
</div>
` : ''}
<image-cropper id="image-cropper"></image-cropper>
<div class="form-actions">
<button type="button" class="btn btn-outline btn-lg" id="cancel-btn">
${t('create.cancel')}
@@ -436,18 +439,37 @@ class PageCreate extends HTMLElement {
handleImageSelect(e) {
const files = Array.from(e.target.files)
this.pendingFiles = [...files]
this.processNextImage()
}
processNextImage() {
if (this.pendingFiles.length === 0) return
if (this.imageFiles.length >= 5) {
this.pendingFiles = []
return
}
files.forEach(file => {
if (this.imageFiles.length >= 5) return
this.imageFiles.push(file)
const reader = new FileReader()
reader.onload = (e) => {
this.imagePreviews.push(e.target.result)
this.updateImagePreviews()
}
reader.readAsDataURL(file)
})
const file = this.pendingFiles.shift()
const cropper = this.querySelector('#image-cropper')
if (cropper) {
cropper.open(
file,
(croppedFile, previewUrl) => {
// On crop complete
this.imageFiles.push(croppedFile)
this.imagePreviews.push(previewUrl)
this.updateImagePreviews()
// Process next image
this.processNextImage()
},
() => {
// On cancel - skip this image
this.processNextImage()
}
)
}
}
updateImagePreviews() {