diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/image-cropper-focus-setter.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/image-cropper-focus-setter.element.ts index 4042a2a5ec..d8d9399b94 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/image-cropper-focus-setter.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/image-cropper-focus-setter.element.ts @@ -13,9 +13,9 @@ import { @customElement('umb-image-cropper-focus-setter') export class UmbImageCropperFocusSetterElement extends LitElement { - @query('#image') imageElement!: HTMLImageElement; - @query('#wrapper') wrapperElement!: HTMLImageElement; - @query('#focal-point') focalPointElement!: HTMLImageElement; + @query('#image') imageElement?: HTMLImageElement; + @query('#wrapper') wrapperElement?: HTMLImageElement; + @query('#focal-point') focalPointElement?: HTMLImageElement; @property({ type: String }) src?: string; @property({ attribute: false }) focalPoint: UmbImageCropperFocalPoint = { left: 0.5, top: 0.5 }; @@ -35,7 +35,7 @@ export class UmbImageCropperFocusSetterElement extends LitElement { protected updated(_changedProperties: PropertyValueMap | Map): void { super.updated(_changedProperties); - if (_changedProperties.has('focalPoint')) { + if (_changedProperties.has('focalPoint') && this.focalPointElement) { this.focalPointElement.style.left = `calc(${this.focalPoint.left * 100}% - ${this.#DOT_RADIUS}px)`; this.focalPointElement.style.top = `calc(${this.focalPoint.top * 100}% - ${this.#DOT_RADIUS}px)`; } @@ -45,23 +45,28 @@ export class UmbImageCropperFocusSetterElement extends LitElement { super.firstUpdated(_changedProperties); this.style.setProperty('--dot-radius', `${this.#DOT_RADIUS}px`); - this.focalPointElement.style.left = `calc(${this.focalPoint.left * 100}% - ${this.#DOT_RADIUS}px)`; - this.focalPointElement.style.top = `calc(${this.focalPoint.top * 100}% - ${this.#DOT_RADIUS}px)`; - this.imageElement.onload = () => { - const imageAspectRatio = this.imageElement.naturalWidth / this.imageElement.naturalHeight; + if (this.focalPointElement) { + this.focalPointElement.style.left = `calc(${this.focalPoint.left * 100}% - ${this.#DOT_RADIUS}px)`; + this.focalPointElement.style.top = `calc(${this.focalPoint.top * 100}% - ${this.#DOT_RADIUS}px)`; + } + if (this.imageElement) { + this.imageElement.onload = () => { + if (!this.imageElement || !this.wrapperElement) return; + const imageAspectRatio = this.imageElement.naturalWidth / this.imageElement.naturalHeight; - if (imageAspectRatio > 1) { - this.imageElement.style.width = '100%'; - this.wrapperElement.style.width = '100%'; - } else { - this.imageElement.style.height = '100%'; - this.wrapperElement.style.height = '100%'; - } + if (imageAspectRatio > 1) { + this.imageElement.style.width = '100%'; + this.wrapperElement.style.width = '100%'; + } else { + this.imageElement.style.height = '100%'; + this.wrapperElement.style.height = '100%'; + } - this.imageElement.style.aspectRatio = `${imageAspectRatio}`; - this.wrapperElement.style.aspectRatio = `${imageAspectRatio}`; - }; + this.imageElement.style.aspectRatio = `${imageAspectRatio}`; + this.wrapperElement.style.aspectRatio = `${imageAspectRatio}`; + }; + } } async #addEventListeners() { @@ -92,6 +97,7 @@ export class UmbImageCropperFocusSetterElement extends LitElement { #onSetFocalPoint(event: MouseEvent) { event.preventDefault(); + if (!this.focalPointElement || !this.imageElement) return; const image = this.imageElement.getBoundingClientRect(); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/input-image-cropper.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/input-image-cropper.element.ts index 63282ae372..9a93d83a37 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/input-image-cropper.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-image-cropper/input-image-cropper.element.ts @@ -109,8 +109,8 @@ export class UmbInputImageCropperElement extends LitElement { .focalPoint=${this.focalPoint} .src=${this.src}>
- Remove files (NOT IMPLEMENTED YET) - Reset focal point + Remove files (NOT IMPLEMENTED YET) + Reset focal point
`; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/image-crops-configuration/property-editor-ui-image-crops-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/image-crops-configuration/property-editor-ui-image-crops-configuration.element.ts index 2077022012..bc03872c53 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/image-crops-configuration/property-editor-ui-image-crops-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/image-crops-configuration/property-editor-ui-image-crops-configuration.element.ts @@ -103,17 +103,17 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
Alias - +
Width - + px
Height - + px
@@ -130,8 +130,8 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement ${item.alias} (${item.width} x ${item.height}px)
- this.#onEdit(item)}>Edit - this.#onRemove(item.alias)}>Remove + this.#onEdit(item)}>Edit + this.#onRemove(item.alias)}>Remove
`,