refactor: replace cropperjs with @github/image-crop-element (#40530)

Replace cropperjs, which was stuck on v1 because v2 was too complex to
migrate to, with `@github/image-crop-element`, the cropper GitHub uses
(2.3 KB vs 14.5 KB gzipped). A full selection of a square image uploads
the original file so animated avatars keep working, any other selection
uploads the selected square as PNG.

Custom element events are now typed via `HTMLElementEventMap`, removing
event casts.

<img width="208" height="208" alt="Avatar crop panel with the Gitea
logo"
src="https://github.com/user-attachments/assets/dbdc2744-592a-45ea-91d2-356c34a0d52b">

Ref: https://github.com/go-gitea/gitea/pull/33827

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
silverwind
2026-11-26 13:40:23 +00:00
committed by GitHub
parent 34ef7ae9e4
commit 14d2bdc19a
12 changed files with 97 additions and 73 deletions

View File

@@ -121,3 +121,7 @@ img.ui.avatar {
max-width: 80px;
}
}
.cropper-panel image-crop {
max-width: 400px;
}

View File

@@ -1,6 +0,0 @@
@import "cropperjs/dist/cropper.css";
.avatar-file-with-cropper + .cropper-panel .cropper-wrapper {
max-width: 400px;
max-height: 400px;
}

View File

@@ -45,7 +45,6 @@
@import "./features/imagediff.css";
@import "./features/projects.css";
@import "./features/expander.css";
@import "./features/cropper.css";
@import "./features/console.css";
@import "./features/captcha.css";