/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { r as registerInstance, c as createEvent, h, H as Host } from './index-EpnuuCxl.js';
import { v as vector3, q as quaternion, m as matrix4, h as euler } from './bundle-DfdVaPrt.js';
import { o as objects } from './bundle-DLfw87TV.js';
import './_commonjsHelpers-CG9AChtV.js';

const viewerDomGroupCss = () => `.sc-vertex-viewer-dom-group-h{display:block;transform-style:preserve-3d}`;

const ViewerDomGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.propertyChange = createEvent(this, "propertyChange");
        /**
         * The local 3D position of where this element is located.
         */
        this.position = vector3.origin();
        /**
         * The local 3D position of where this element is located, as a JSON string.
         * JSON representation can either be in the format of `[x, y, z]` or `{"x": 0,
         * "y": 0, "z": 0}`.
         */
        this.positionJson = '';
        /**
         * The local rotation of this element.
         */
        this.quaternion = quaternion.create();
        /**
         * The local rotation of this element, as a JSON string. JSON
         * representation can either be `[x, y, z, w]` or `{"x": 0, "y": 0, "z":
         * 0, "w": 1}`.
         */
        this.quaternionJson = '';
        /**
         * The local scale of this element.
         */
        this.scale = vector3.create(1, 1, 1);
        /**
         * The local scale of this element, as a JSON string. JSON string
         * representation can either be in the format of `[x, y, z]` or `{"x": 0, "y":
         * 0, "z": 0}`.
         */
        this.scaleJson = '';
        /**
         * The local matrix of this element.
         */
        this.matrix = matrix4.makeIdentity();
    }
    /**
     * @ignore
     */
    handlePositionChange() {
        this.syncMatrix();
    }
    /**
     * @ignore
     */
    handlePositionJsonChanged() {
        this.syncPosition();
    }
    /**
     * @ignore
     */
    handleRotationChanged() {
        this.syncQuaternionWithRotation();
    }
    /**
     * @ignore
     */
    handleRotationJsonChanged() {
        this.syncRotation();
    }
    /**
     * @ignore
     */
    handleQuaternionChange() {
        this.syncMatrix();
    }
    /**
     * @ignore
     */
    handleQuaternionJsonChanged() {
        this.syncQuaternion();
    }
    /**
     * @ignore
     */
    handleScaleChange() {
        this.syncMatrix();
    }
    /**
     * @ignore
     */
    handleScaleJsonChanged() {
        this.syncScale();
    }
    /**
     * @ignore
     */
    handleMatrixChanged(newMatrix, oldMatrix) {
        if (!objects.isEqual(newMatrix, oldMatrix)) {
            this.propertyChange.emit();
        }
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.syncProperties();
    }
    /**
     * @ignore
     */
    componentShouldUpdate() {
        return false;
    }
    syncProperties() {
        this.syncPosition();
        this.syncRotation();
        this.syncQuaternion();
        this.syncScale();
        this.syncMatrix();
    }
    syncPosition() {
        this.position =
            this.positionJson.length > 0
                ? this.parseJson('positionJson', this.positionJson, vector3.fromJson)
                : this.position;
    }
    syncRotation() {
        this.rotation =
            this.rotationJson != null && this.rotationJson.length > 0
                ? this.parseJson('rotationJson', this.rotationJson, euler.fromJson)
                : this.rotation;
        this.syncQuaternionWithRotation();
    }
    syncQuaternionWithRotation() {
        this.quaternion =
            this.rotation != null
                ? quaternion.fromEuler(this.rotation)
                : this.quaternion;
    }
    syncQuaternion() {
        this.quaternion =
            this.quaternionJson.length > 0
                ? this.parseJson('quaternionJson', this.quaternionJson, quaternion.fromJson)
                : this.quaternion;
    }
    syncScale() {
        this.scale =
            this.scaleJson.length > 0
                ? this.parseJson('scaleJson', this.scaleJson, vector3.fromJson)
                : this.scale;
    }
    syncMatrix() {
        this.matrix = matrix4.makeTRS(this.position, this.quaternion, this.scale);
    }
    parseJson(propName, value, parse) {
        try {
            return parse(value);
        }
        catch (e) {
            console.warn(`Could not parse \`${propName}\`. Invalid JSON.`);
            throw e;
        }
    }
    /**
     * @ignore
     */
    render() {
        return (h(Host, { key: '38d400024a27631bf1f111d9a4f44b01469c814d' }, h("slot", { key: '50ab66305307ce5c45638c562830ca55c2956835' })));
    }
    static get watchers() { return {
        "position": [{
                "handlePositionChange": 0
            }],
        "positionJson": [{
                "handlePositionJsonChanged": 0
            }],
        "rotation": [{
                "handleRotationChanged": 0
            }],
        "rotationJson": [{
                "handleRotationJsonChanged": 0
            }],
        "quaternion": [{
                "handleQuaternionChange": 0
            }],
        "quaternionJson": [{
                "handleQuaternionJsonChanged": 0
            }],
        "scale": [{
                "handleScaleChange": 0
            }],
        "scaleJson": [{
                "handleScaleJsonChanged": 0
            }],
        "matrix": [{
                "handleMatrixChanged": 0
            }]
    }; }
};
ViewerDomGroup.style = viewerDomGroupCss();

export { ViewerDomGroup as vertex_viewer_dom_group };
//# sourceMappingURL=vertex-viewer-dom-group.entry.js.map

//# sourceMappingURL=vertex-viewer-dom-group.entry.js.map