/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { r as registerInstance, h, F as Fragment, H as Host } from './index-EpnuuCxl.js';
import { p as point, a as angle } from './bundle-DfdVaPrt.js';
import './geometry_pb-BPrLQ_K_.js';
import './wrappers_pb-aFAwKqIf.js';
import './wrappers_pb-Xw_x1jYm.js';
import './bundle-CLE0fYge.js';
import './streamAttributes-B6xi3kRV.js';
import { M as MeasurementOverlayManager } from './overlays-BlZ9sQii.js';
import { t as translateWorldLineToViewport } from './utils-ZqsjY8Af.js';
import './bundle-DLfw87TV.js';
import './_commonjsHelpers-CG9AChtV.js';
import './entities-BAhfr1Nx.js';

const viewerMeasurementLineCss = () => `:host{display:block;--viewer-measurement-line-stroke:var(--white);--viewer-measurement-line-stroke-opacity:0.75;--viewer-measurement-line-stroke-width:1.25px;--viewer-measurement-line-fill:var(--neutral-900);--viewer-measurement-line-fill-width:2px;--viewer-measurement-line-start-cap-visibility:initial;--viewer-measurement-line-end-cap-visibility:initial}svg{width:100%;height:100%}.line-stroke{stroke-width:calc(     var(--viewer-measurement-line-fill-width) +       var(--viewer-measurement-line-stroke-width)   );stroke:var(--viewer-measurement-line-stroke);opacity:var(--viewer-measurement-line-stroke-opacity)}.line-fill{stroke-width:var(--viewer-measurement-line-fill-width);stroke:var(--viewer-measurement-line-fill)}.start-cap{visibility:var(--viewer-measurement-line-start-cap-visibility)}.end-cap{visibility:var(--viewer-measurement-line-end-cap-visibility)}`;

const ViewerMeasurementLine = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /**
         * A point that specifies the starting point of the line.
         */
        this.start = point.create();
        /**
         * A point that specifies the ending point of the line.
         */
        this.end = point.create();
        /**
         * A length of the line cap. The line cap is a line at each end of a line.
         */
        this.capLength = 0;
        /**
         * The type of [SVG pointer
         * events](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/pointer-events)
         * that the line should respond to.
         */
        this.pointerEvents = 'none';
    }
    /**
     * @ignore
     */
    render() {
        const angle$1 = angle.fromPoints(this.start, this.end);
        const lineFillEndCaps = getEndCapPoints(this.start, this.end, angle$1, this.capLength);
        const lineStrokeEndCaps = getEndCapPoints(this.start, this.end, angle$1, this.capLength + 1);
        return (h("svg", { key: '96c8e5b4ddb2e0bfb86e622ba7414c5061000ea9' }, h("g", { key: '6b1673f801e3776db396e5912541d51ca54d23bf', class: "line-stroke", "pointer-events": this.pointerEvents }, h("line", { key: '1ae3892507d0a63701950c12abfa67cd2f02e46f', class: "line", x1: this.start.x, y1: this.start.y, x2: this.end.x, y2: this.end.y }), h("line", { key: 'ab3111d1d00653f1d68d12e0e89ad2e0fe609049', class: "start-cap", x1: lineStrokeEndCaps.startEndCap.start.x, y1: lineStrokeEndCaps.startEndCap.start.y, x2: lineStrokeEndCaps.startEndCap.end.x, y2: lineStrokeEndCaps.startEndCap.end.y }), h("line", { key: '5c3e899afe9a95af73fcd80aa670c3849dbe1f70', class: "end-cap", x1: lineStrokeEndCaps.endEndCap.start.x, y1: lineStrokeEndCaps.endEndCap.start.y, x2: lineStrokeEndCaps.endEndCap.end.x, y2: lineStrokeEndCaps.endEndCap.end.y })), h("g", { key: 'cfef2398d0c8445e3f9223c52b446c2cb187c5e9', class: "line-fill", "pointer-events": this.pointerEvents }, h("line", { key: '90653a7c0fadd495949f85a246d3b640086fbbef', class: "line", x1: this.start.x, y1: this.start.y, x2: this.end.x, y2: this.end.y }), h("line", { key: 'c92da23e39cf9248e12875136b68aa5de42b2e09', class: "start-cap", x1: lineFillEndCaps.startEndCap.start.x, y1: lineFillEndCaps.startEndCap.start.y, x2: lineFillEndCaps.startEndCap.end.x, y2: lineFillEndCaps.startEndCap.end.y }), h("line", { key: '5dbfeff2784da10f6e1a442fcf706edf91e9e4ef', class: "end-cap", x1: lineFillEndCaps.endEndCap.start.x, y1: lineFillEndCaps.endEndCap.start.y, x2: lineFillEndCaps.endEndCap.end.x, y2: lineFillEndCaps.endEndCap.end.y }))));
    }
};
function getEndCapPoints(start, end, angle, length) {
    return {
        startEndCap: getPerpendicularLine(start, angle, length),
        endEndCap: getPerpendicularLine(end, angle, length),
    };
}
function getPerpendicularLine(pt, angle, length) {
    const perpAngle = angle + Math.PI / 2;
    const start = point.add(pt, point.polar(length / 2, perpAngle));
    const end = point.add(pt, point.polar(length / 2, perpAngle + Math.PI));
    return { start, end };
}
ViewerMeasurementLine.style = viewerMeasurementLineCss();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const MeasurementOverlayView = ({ overlay, viewport, camera }) => {
    if (overlay.type === 'line') {
        return (h(LineOverlayView, { overlay: overlay, viewport: viewport, camera: camera }));
    }
    else {
        return (h(DistanceVectorOverlayView, { overlay: overlay, viewport: viewport, camera: camera }));
    }
};
const LineOverlayView = ({ overlay, camera, viewport }) => {
    const { start, end } = translateWorldLineToViewport(overlay, {
        camera,
        viewport,
    });
    return (h("vertex-viewer-measurement-line", { class: "measurement-line", start: start, end: end }));
};
const DistanceVectorOverlayView = ({ overlay: { x, y, z }, camera, viewport }) => {
    const params = { camera, viewport };
    const { start: xs, end: xe } = translateWorldLineToViewport(x, params);
    const { start: ys, end: ye } = translateWorldLineToViewport(y, params);
    const { start: zs, end: ze } = translateWorldLineToViewport(z, params);
    return (h(Fragment, null, h("vertex-viewer-measurement-line", { class: "measurement-line distance-vector-x", start: xs, end: xe }), h("vertex-viewer-measurement-line", { class: "measurement-line distance-vector-y", start: ys, end: ye }), h("vertex-viewer-measurement-line", { class: "measurement-line distance-vector-z", start: zs, end: ze })));
};

const viewerMeasurementOverlaysCss = () => `:host{display:block;position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none;--viewer-measurement-overlays-x-axis-color:var(--x-axis-color);--viewer-measurement-overlays-y-axis-color:var(--y-axis-color);--viewer-measurement-overlays-z-axis-color:var(--z-axis-color)}.measurement-line{position:absolute;width:100%;height:100%}.measurement-line.distance-vector-x{--viewer-measurement-line-fill:var(     --viewer-measurement-overlays-x-axis-color   )}.measurement-line.distance-vector-y{--viewer-measurement-line-fill:var(     --viewer-measurement-overlays-y-axis-color   )}.measurement-line.distance-vector-z{--viewer-measurement-line-fill:var(     --viewer-measurement-overlays-z-axis-color   )}`;

const ViewerMeasurementOverlays = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /**
         * The model that contains the overlays to present.
         */
        this.measurementOverlays = new MeasurementOverlayManager();
        this.overlays = [];
        this.updateCamera = () => {
            var _a, _b;
            this.camera = (_b = (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame) === null || _b === void 0 ? void 0 : _b.scene.camera;
        };
    }
    /**
     * @ignore
     */
    handleMeasurementOverlaysChanged() {
        this.removeModelListeners();
        this.addModelListeners();
        this.updateOverlays();
    }
    /**
     * @ignore
     */
    handleViewerChanged(newViewer, oldViewer) {
        this.removeViewerListeners(oldViewer);
        this.addViewerListeners();
        this.updateCamera();
    }
    /**
     * @ignore
     */
    componentWillLoad() {
        this.addModelListeners();
        this.addViewerListeners();
        this.updateOverlays();
        this.updateCamera();
    }
    addModelListeners() {
        this.onOverlaysChangedListener = this.measurementOverlays.onOverlaysChanged(() => this.updateOverlays());
    }
    removeModelListeners() {
        var _a;
        (_a = this.onOverlaysChangedListener) === null || _a === void 0 ? void 0 : _a.dispose();
        this.onOverlaysChangedListener = undefined;
    }
    addViewerListeners() {
        var _a;
        (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.addEventListener('frameReceived', this.updateCamera);
    }
    removeViewerListeners(viewer) {
        viewer === null || viewer === void 0 ? void 0 : viewer.removeEventListener('frameReceived', this.updateCamera);
    }
    updateOverlays() {
        this.overlays = this.measurementOverlays.getOverlays();
    }
    /**
     * @ignore
     */
    render() {
        return (h(Host, { key: 'fbda189899fa87c57b11615693d1319eee341fea' }, this.overlays.map((overlay) => {
            if (this.camera != null && this.viewer != null) {
                return (h(MeasurementOverlayView, { overlay: overlay, viewport: this.viewer.viewport, camera: this.camera }));
            }
        })));
    }
    static get watchers() { return {
        "measurementOverlays": [{
                "handleMeasurementOverlaysChanged": 0
            }],
        "viewer": [{
                "handleViewerChanged": 0
            }]
    }; }
};
ViewerMeasurementOverlays.style = viewerMeasurementOverlaysCss();

export { ViewerMeasurementLine as vertex_viewer_measurement_line, ViewerMeasurementOverlays as vertex_viewer_measurement_overlays };
//# sourceMappingURL=vertex-viewer-measurement-line.vertex-viewer-measurement-overlays.entry.js.map

//# sourceMappingURL=vertex-viewer-measurement-line_2.entry.js.map