Skip to content

Commit 063ba01

Browse files
committed
feat: call reset on initial attribute set
1 parent df0cafd commit 063ba01

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/ModernCropper.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,26 @@ onCropperMounted(({ image }) => {
104104
})
105105
106106
function setElementAttributes(element: HTMLElement, attributes: Record<any, any>) {
107+
let doReset = false
108+
107109
Object.entries(attributes).forEach(([attribute, value]) => {
108110
if (value === undefined)
109111
return
110112
113+
if (attribute.includes('initial'))
114+
doReset = true
115+
111116
if (value === false || value === null)
112117
return element.removeAttribute(attribute)
113118
114119
element.setAttribute(attribute.replaceAll(/([a-z])([A-Z])/g, (_match, p1: string, p2: string) => `${p1}-${p2.toLowerCase()}`), value)
115120
})
121+
122+
if (doReset) {
123+
console.warn(`[ModernCropper]: "initial"-type attribute detected, will call $reset(), but the selection may disappear due to https://github.com/fengyuanchen/cropperjs/issues/1157`)
124+
// @ts-expect-error $reset don't exist on HTMLElement
125+
element.$reset()
126+
}
116127
}
117128
// process passThrough options
118129
onCropperMounted(({ image, canvas, selection, selections }) => {

0 commit comments

Comments
 (0)