/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
'use strict';

var index = require('./index-C_J7n4Dv.js');
var bundle = require('./bundle-BhTmftd-.js');
var bundle$1 = require('./bundle-96sYCpzz.js');
require('./_commonjsHelpers-CBbBosIU.js');

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

const ViewerDomGroup = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.propertyChange = index.createEvent(this, "propertyChange");
        /**
         * The local 3D position of where this element is located.
         */
        this.position = bundle.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 = bundle.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 = bundle.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 = bundle.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 (!bundle$1.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, bundle.vector3.fromJson)
                : this.position;
    }
    syncRotation() {
        this.rotation =
            this.rotationJson != null && this.rotationJson.length > 0
                ? this.parseJson('rotationJson', this.rotationJson, bundle.euler.fromJson)
                : this.rotation;
        this.syncQuaternionWithRotation();
    }
    syncQuaternionWithRotation() {
        this.quaternion =
            this.rotation != null
                ? bundle.quaternion.fromEuler(this.rotation)
                : this.quaternion;
    }
    syncQuaternion() {
        this.quaternion =
            this.quaternionJson.length > 0
                ? this.parseJson('quaternionJson', this.quaternionJson, bundle.quaternion.fromJson)
                : this.quaternion;
    }
    syncScale() {
        this.scale =
            this.scaleJson.length > 0
                ? this.parseJson('scaleJson', this.scaleJson, bundle.vector3.fromJson)
                : this.scale;
    }
    syncMatrix() {
        this.matrix = bundle.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 (index.h(index.Host, { key: '38d400024a27631bf1f111d9a4f44b01469c814d' }, index.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();

exports.vertex_viewer_dom_group = ViewerDomGroup;
//# sourceMappingURL=vertex-viewer-dom-group.entry.cjs.js.map

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