/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
/* eslint-disable @typescript-eslint/member-ordering */
import { h, Host, } from "@stencil/core";
import { Euler, Matrix4, Quaternion, Vector3 } from "@vertexvis/geometry";
import { Objects } from "@vertexvis/utils";
export class ViewerDomGroup {
    constructor() {
        /**
         * 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 is() { return "vertex-viewer-dom-group"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["viewer-dom-group.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["viewer-dom-group.css"]
        };
    }
    static get properties() {
        return {
            "position": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Vector3.Vector3",
                    "resolved": "Vector3",
                    "references": {
                        "Vector3": {
                            "location": "import",
                            "path": "@vertexvis/geometry",
                            "id": "../geometry/dist/index.d.ts::\"/home/runner/work/vertex-web-sdk/vertex-web-sdk/packages/geometry/dist/vector3\"",
                            "referenceLocation": "Vector3"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local 3D position of where this element is located."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "Vector3.origin()"
            },
            "positionJson": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local 3D position of where this element is located, as a JSON string.\nJSON representation can either be in the format of `[x, y, z]` or `{\"x\": 0,\n\"y\": 0, \"z\": 0}`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "position",
                "defaultValue": "''"
            },
            "rotation": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Euler.Euler",
                    "resolved": "Euler | undefined",
                    "references": {
                        "Euler": {
                            "location": "import",
                            "path": "@vertexvis/geometry",
                            "id": "../geometry/dist/index.d.ts::\"/home/runner/work/vertex-web-sdk/vertex-web-sdk/packages/geometry/dist/euler\"",
                            "referenceLocation": "Euler"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The local rotation of this element in Euler angles."
                },
                "getter": false,
                "setter": false
            },
            "rotationJson": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string | undefined",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The local rotation of this element in Euler angles, as a JSON string. JSON\nrepresentation can either be `[x, y, z, order]` or `{\"x\": 0, \"y\": 0, \"z\":\n0, \"order\": \"xyz\"}`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "rotation"
            },
            "quaternion": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Quaternion.Quaternion",
                    "resolved": "Quaternion",
                    "references": {
                        "Quaternion": {
                            "location": "import",
                            "path": "@vertexvis/geometry",
                            "id": "../geometry/dist/index.d.ts::\"/home/runner/work/vertex-web-sdk/vertex-web-sdk/packages/geometry/dist/quaternion\"",
                            "referenceLocation": "Quaternion"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local rotation of this element."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "Quaternion.create()"
            },
            "quaternionJson": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local rotation of this element, as a JSON string. JSON\nrepresentation can either be `[x, y, z, w]` or `{\"x\": 0, \"y\": 0, \"z\":\n0, \"w\": 1}`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "quaternion",
                "defaultValue": "''"
            },
            "scale": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Vector3.Vector3",
                    "resolved": "Vector3",
                    "references": {
                        "Vector3": {
                            "location": "import",
                            "path": "@vertexvis/geometry",
                            "id": "../geometry/dist/index.d.ts::\"/home/runner/work/vertex-web-sdk/vertex-web-sdk/packages/geometry/dist/vector3\"",
                            "referenceLocation": "Vector3"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local scale of this element."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "Vector3.create(1, 1, 1)"
            },
            "scaleJson": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local scale of this element, as a JSON string. JSON string\nrepresentation can either be in the format of `[x, y, z]` or `{\"x\": 0, \"y\":\n0, \"z\": 0}`."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "scale",
                "defaultValue": "''"
            },
            "matrix": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "Matrix4.Matrix4",
                    "resolved": "[number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]",
                    "references": {
                        "Matrix4": {
                            "location": "import",
                            "path": "@vertexvis/geometry",
                            "id": "../geometry/dist/index.d.ts::\"/home/runner/work/vertex-web-sdk/vertex-web-sdk/packages/geometry/dist/matrix4\"",
                            "referenceLocation": "Matrix4"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The local matrix of this element."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "Matrix4.makeIdentity()"
            }
        };
    }
    static get events() {
        return [{
                "method": "propertyChange",
                "name": "propertyChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "An event that is emitted when any property on the dom group changes"
                },
                "complexType": {
                    "original": "void",
                    "resolved": "void",
                    "references": {}
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "position",
                "methodName": "handlePositionChange"
            }, {
                "propName": "positionJson",
                "methodName": "handlePositionJsonChanged"
            }, {
                "propName": "rotation",
                "methodName": "handleRotationChanged"
            }, {
                "propName": "rotationJson",
                "methodName": "handleRotationJsonChanged"
            }, {
                "propName": "quaternion",
                "methodName": "handleQuaternionChange"
            }, {
                "propName": "quaternionJson",
                "methodName": "handleQuaternionJsonChanged"
            }, {
                "propName": "scale",
                "methodName": "handleScaleChange"
            }, {
                "propName": "scaleJson",
                "methodName": "handleScaleJsonChanged"
            }, {
                "propName": "matrix",
                "methodName": "handleMatrixChanged"
            }];
    }
}
//# sourceMappingURL=viewer-dom-group.js.map
