UNPKG

@realsee/dnalogel

Version:
73 lines (72 loc) 3.46 kB
var h = Object.defineProperty; var c = (o, t, e) => t in o ? h(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e; var n = (o, t, e) => (c(o, typeof t != "symbol" ? t + "" : t, e), e); import { anyPositionToVector3 as l } from "./positionToVector3.js"; import * as d from "three"; import { vector3ToScreen as p } from "./five/vector3ToScreen.js"; const r = "LightTagContainer_shgjakdhwakjdhsja"; class f { constructor(t, e) { n(this, "container"); n(this, "visible", !1); n(this, "enabled", !1); n(this, "five"); n(this, "position"); n(this, "wrapper"); n(this, "disposer"); n(this, "onCameraUpdate", () => { if (this.visible === !1) return; const t = p(this.five.camera, this.position); t ? (this.container.style.opacity = "1", this.container.style.pointerEvents = "auto", this.container.style.left = t.leftPercent + "%", this.container.style.top = t.topPercent + "%") : (this.container.style.opacity = "0", this.container.style.pointerEvents = "none"); }); n(this, "onFiveEveryReady", () => { var t; if (this.visible && this.five.state.mode !== "Panorama") { const e = new d.Raycaster(); e.set(this.five.camera.position, this.position.clone().sub(this.five.camera.position)); const i = (t = this.five.model.intersectRaycaster(e)) == null ? void 0 : t[0]; (i == null ? void 0 : i.distance) > this.position.distanceTo(this.five.camera.position) ? (this.container.style.opacity = "1", this.container.style.pointerEvents = "auto") : (this.container.style.opacity = "0", this.container.style.pointerEvents = "none"); } }); this.five = t, this.position = l(e).clone(), this.container = (() => { const i = document.createElement("div"); return i.style.width = "0", i.style.height = "0", i.style.position = "absolute", i; })(), this.enable(), this.show(); } show() { this.visible = !0, this.container.style.opacity = "1", this.container.style.pointerEvents = "auto", this.container.classList.add("withAnimation"), this.onCameraUpdate(); } hide(t) { this.visible = !1, t != null && t.withAnimation ? this.container.classList.add("withAnimation") : this.container.classList.remove("withAnimation"), this.container.style.opacity = "0", this.container.style.pointerEvents = "none"; } enable() { var i; if (this.enabled) return; this.enabled = !0, this.wrapper = (i = document.getElementById(r)) != null ? i : (() => { var a; const s = document.createElement("div"); return s.id = r, s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.width = "100%", s.style.height = "100%", s.style.pointerEvents = "none", (a = this.five.getElement()) == null || a.parentElement.appendChild(s), s; })(), this.wrapper.appendChild(this.container); let t = !1; const e = () => { t || (t = !0, this.five.ready().then(() => { this.onFiveEveryReady(), t = !1; })); }; this.five.on("cameraUpdate", e), this.five.on("cameraUpdate", this.onCameraUpdate), this.disposer = () => { this.five.off("cameraUpdate", e), this.five.off("cameraUpdate", this.onCameraUpdate); }; } disable() { var t; this.enabled && (this.enabled = !1, this.wrapper.removeChild(this.container), (t = this.disposer) == null || t.call(this)); } } function u(o, t) { return new f(o, t); } export { u as tag };