@realsee/dnalogel
Version:
64 lines (63 loc) • 3.02 kB
JavaScript
var $ = Object.defineProperty, j = Object.defineProperties;
var w = Object.getOwnPropertyDescriptors;
var P = Object.getOwnPropertySymbols;
var H = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
var u = (e, n, t) => n in e ? $(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, b = (e, n) => {
for (var t in n || (n = {}))
H.call(n, t) && u(e, t, n[t]);
if (P)
for (var t of P(n))
z.call(n, t) && u(e, t, n[t]);
return e;
}, y = (e, n) => j(e, w(n));
var C = (e, n, t) => (u(e, typeof n != "symbol" ? n + "" : n, t), t);
import { ItemDom as F } from "./base.js";
import { Vector2 as I } from "three";
import { isNDCPointInFront as g } from "../isNDCPointInScreen.js";
import { centerPoint as Y } from "../../../shared-utils/three/centerPoint.js";
class A extends F {
constructor(t) {
var o;
t.contentStyle = y(b({}, t.contentStyle), {
background: "rgba(195,195,195,0.70)",
border: "0.5px solid rgba(255,255,255,0.6)",
borderRadius: "999px"
});
super(t);
C(this, "line");
this.line = t.line, (o = this.params.userDistanceItem) != null && o.element ? this.containerDom.appendChild(this.params.userDistanceItem.element) : this.containerDom.appendChild(this.contentDom);
}
update(t) {
var D;
if (this.line.mesh.visible === !1) {
this.hide();
return;
}
const o = t.getElement();
if (!o)
return;
const a = o.clientWidth, r = o.clientHeight, d = a / 2, c = r / 2;
if (this.line.points.length < 2)
return;
const [l, h] = this.line.points, i = l.position.clone().project(t.camera), s = h.position.clone().project(t.camera), m = Y(l.position, h.position).clone().project(t.camera), p = new I(i.x * d, i.y * c), f = new I(s.x * d, s.y * c), x = p.distanceTo(f);
if ((() => !(Math.abs(i.z) > 1 || Math.abs(s.z) > 1 || !g(i) && !g(s) || !g(m) || x === 0))() === !1) {
this.hide();
return;
}
const S = (m.x + 1) / 2 * a, E = -(m.y - 1) / 2 * r, M = -(Math.atan((p.y - f.y) / (p.x - f.x)) * 180) / Math.PI, T = this.containerDom.parentElement && this.contentDom.clientWidth > x ? -20 : 0;
this.containerDom.style.transform = `translate(${S}px, ${E}px) rotate(${M}deg) translateY(${T}px)`, this.show(), (D = this.params.userDistanceItem) == null || D.update({ line: this.line, polyline: this.line.getPolyline() });
const W = this.getCurrentContent();
this.contentDom.innerText = W;
}
/** 获取内容文本 */
getCurrentContent() {
var l, h, i, s;
if (this.line.points.length < 2)
return "";
const [t, o] = this.line.points, a = t.position.clone().distanceTo(o.position), r = (h = this.line.text) != null ? h : (l = this.line.model.config) == null ? void 0 : l.defaultText, d = (s = (i = this.line.model.config) == null ? void 0 : i.getDistanceText) == null ? void 0 : s.call(i, a), c = r != null ? r : d;
return c != null ? c : a.toFixed(2) + "m";
}
}
export {
A as DistanceItem
};