UNPKG

@realsee/dnalogel

Version:
359 lines (358 loc) 14.4 kB
var q = Object.defineProperty, K = Object.defineProperties; var Q = Object.getOwnPropertyDescriptors; var F = Object.getOwnPropertySymbols; var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable; var _ = (l, s, e) => s in l ? q(l, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[s] = e, b = (l, s) => { for (var e in s || (s = {})) Y.call(s, e) && _(l, e, s[e]); if (F) for (var e of F(s)) Z.call(s, e) && _(l, e, s[e]); return l; }, V = (l, s) => K(l, Q(s)); var f = (l, s, e) => (_(l, typeof s != "symbol" ? s + "" : s, e), e); import { defaultGlobalConfig as ee } from "../typings/tag/TagConfig.js"; import { objectAssignDeepExports as y } from "../../vendor/object-assign-deep/objectAssignDeep.js"; import * as ie from "three"; import { DefaultConfig as te } from "../tag.config.js"; import { anyPositionToVector3 as C } from "../../shared-utils/positionToVector3.js"; import { planeNormal as w } from "../utils/planeNormal.js"; import { getTagCenterPosition as R } from "../utils/tagPosition.js"; import { normalPositionToPositions as oe } from "../utils/normalPositionToPositions.js"; import { TagCache as ne } from "./TagCache.js"; import { writable as re } from "../../vendor/svelte/store/index.js"; import { isIOSWX as se } from "../../shared-utils/device.js"; import { Five as fe } from "@realsee/five"; import { isMediaPlaneTag as ae, isMediaModelTag as B, isPlaneTag as ce, isPoint3DTag as le } from "../utils/tag/tagCheck.js"; import { VideoPlane as de } from "../utils/model/mediaPlane.js"; import { FiveDomEvents as he } from "../../shared-utils/five/FiveDomEvents.js"; import N from "../utils/tag/adaptConfig.js"; import { isPanoramaLike as E, isModelLike as $ } from "../../shared-utils/five/mode.js"; import "hammerjs"; import "../../vendor/@tweenjs/tween/dist/tween.esm.js.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRender.js"; import "../../CSS3DRenderPlugin/utils/generateBehindFiveElement.js"; import "animejs"; import { entries as z } from "../../shared-utils/typescript/entries.js"; import { getUrlExt as H } from "../../shared-utils/url/getUrl.js"; import { transformPosition as J } from "../../shared-utils/five/transformPosition.js"; import { WorkUtil as ge } from "../../shared-utils/Utils/WorkUtil.js"; import "../../shared-utils/three/centerPoint.js"; import "../../base/BasePlugin.js"; import "../../shared-utils/Subscribe.js"; import "../../shared-utils/url/absoluteUrl.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRenderer.js"; import "three/examples/jsm/renderers/CSS3DRenderer"; import "../../CSS3DRenderPlugin/utils/getAllCSS3DObject.js"; import "../../shared-utils/util.js"; import "../../CSS3DRenderPlugin/utils/createResizeObserver.js"; import "../../CSS3DRenderPlugin/utils/even.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DObject.js"; import "../../CSS3DRenderPlugin/utils/three/OpacityMesh.js"; import "../../shared-utils/three/getObjectVisible.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DScene.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DGroup.js"; import "../../vendor/svelte/internal/index.js"; import "../../shared-utils/three/loadTexture.js"; import "../../shared-utils/three/Quadrangle.js"; import "../../shared-utils/math/pointIsRectangle.js"; import "../../shared-utils/three/loadVideoTexture.js"; import "../Assets/Icon.js"; import "../../shared-utils/three/getPositionsByObjectFit.js"; import "../../shared-utils/three/FragmentTransparencyMaterial.js"; import "../../shared-utils/three/getNormal.js"; import "../../shared-utils/five/calculateThreeMouse.js"; import "../../shared-utils/Utils/BaseUtil.js"; class hi extends ne { constructor(e) { super(e); f(this, "tags", []); f(this, "config", te); f(this, "tagsLengthWillUpdate", !0); f(this, "workUtil", new ge(this.five)); f(this, "mediaStore", re({ currentMediaElement: null })); /** css3DRenderPlugin */ f(this, "css3DRenderPlugin"); f(this, "store", { disposers: [], disposed: !1, resizeObserverDisposerAdding: !1, css3DRenderDisposer: /* @__PURE__ */ new Map() }); f(this, "domEvents", new he(this.five)); f(this, "_cache_pointTag"); f(this, "_cache_2DPointTag"); f(this, "_cache_imagePlane"); f(this, "_cache_mediaModel"); f(this, "_cache_css3DTag"); f(this, "loadVideoFirstFrame", () => { se && this.hooks.emit("loadVideoFirstFrame"); }); this.mediaStore.subscribe(({ currentMediaElement: t }) => { this.tags.forEach((i) => { var o; if (i.mediaPlane instanceof de && t !== i.mediaPlane.videoInstance) { if (!((o = i.mediaPlane.videoInstance) != null && o.src) || t === i.mediaPlane.videoInstance) return; i.mediaPlane.pause(); } }); }); } set workCode(e) { this.workUtil.workCode = e; } get workCode() { return this.workUtil.workCode; } getTagById(e) { const t = this.tags.find((i) => i.id === e); if (!t) { console.warn(`getTagById Error: can't find tag id: ${e}`); return; } return t; } /** 暂停当前标签内进行的所有多媒体 */ pauseCurrentMedia() { this.mediaStore.set({ currentMediaElement: null }); } /** * @description 获取标签配置 */ getTagConfig(e, t) { var r, a, d; const i = this.calculateTagConfig(e, { useCache: t == null ? void 0 : t.useCache }), o = (r = t == null ? void 0 : t.fiveMode) != null ? r : this.five.getCurrentState().mode, n = (a = i.configWithFiveMode) == null ? void 0 : a[o]; return (d = n != null ? n : i) != null ? d : {}; } /** * @description 获取标签当前状态 */ getCurrentVisibleState(e) { return !(!this.state.enabled || !this.state.visible || !e.enabled || !e.state.visible); } updateTagConfig() { this.clearCache(), this.tags.forEach((e) => { var o; const t = this.getTagConfig(e, { useCache: !1 }); e.computedConfig = t; const i = this.getTagConfig(e); if (e.config = i, e.config.initialData) { const n = JSON.parse(JSON.stringify(e.data)); e.data = (o = i.initialData) != null && o.important ? y(e.data, n, i.initialData) : y(e.data, i.initialData, n); } }); } can(e, t) { const i = t, o = this.getTagConfig(i); if (!o || typeof o != "object") return !0; if (e === "show" || e === "hide") { if (!o.visibleConfig || typeof o.visibleConfig != "object") return !0; if (e === "show" && o.visibleConfig.keep === "hidden" || e === "hide" && (o.visibleConfig.keep === "visible" || o.visibleConfig.alwaysShowWhenMovePano)) return !1; } if (e === "fold" || e === "unfold") { if (!o.unfoldedConfig || typeof o.unfoldedConfig != "object") return !0; if (e === "fold" && o.unfoldedConfig.keep === "unfolded" || e === "unfold" && o.unfoldedConfig.keep === "folded") return !1; } return !0; } getRenderType(e) { const t = (() => { if (e.stickType === "3DPoint") return "Dom"; const i = this.getTagConfig(e); if (!i || typeof i != "object" || !i.renderType) return; const o = e.data.mediaData; if (!(!o || o.length === 0) && i.renderType === "Mesh") { if (ae(e)) { if (o.length === 1) { if (o[0].type === "Video") return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 && navigator.userAgent.toLowerCase().indexOf("mobile") > -1 ? "Dom" : "Mesh"; if (o[0].type === "Image") return H(o[0].url) === "gif" ? "Dom" : "Mesh"; } } else if (B(e)) return o.length === 1 && o[0].type === "Image" ? H(o[0].url) === "gif" ? "Dom" : "Mesh" : "BehindDom"; } })(); return t != null ? t : "Dom"; } /** * @description 获取角度 */ getAngle(e, t) { const i = t != null ? t : this.five.getCurrentState().panoIndex; if (i === void 0) throw new Error(`getAngle(): fivePanoIndex is ${i}`); const o = this.getPanoIndexCache({ panoIndex: t, id: e.id }); if (o.angle !== void 0) return o.angle; { const n = this.workUtil.getObserverPosition(i); if (n === void 0) throw new Error(`getAngle(): observerPosition is ${n}`); const r = (() => e.stickType === "3DPoint" ? C(e.normal) : w(e.position))(); if (!r) return; const a = R(e); if (!a) return; const d = new ie.Vector3().copy(n).sub(a), m = r.angleTo(d) * 180 / Math.PI; return o.angle = m, o.angle; } } /** * @description 获取距离 */ getDistance(e, t) { const i = b(b({}, this.five.getCurrentState()), t), { panoIndex: o, mode: n } = i, r = E(n) ? this.getPanoIndexCache({ panoIndex: o, id: e.id }) : void 0; if ((r == null ? void 0 : r.distance) !== void 0) return r.distance; const a = R(e); if (!a) return -1; if (E(n)) { const d = this.workUtil.getObserverPosition(o); if (d === void 0) return -1; const m = d.distanceTo(a); return r && (r.distance = m), m; } if ($(n)) return this.five.camera.position.distanceTo(a); } getPositions(e) { if (ce(e)) return e.position; if (B(e)) return e.data.mediaPosition; if (le(e)) return oe(this.five.camera.position, C(e.position), C(e.normal)); } addObjectClickHandler(e, t, i) { if (!t || !this.domEvents) return () => { }; const o = () => !(!this.getCurrentVisibleState(e) || e.loading), n = (r) => { if (!o()) return !1; i(r.origDomEvent); }; return this.domEvents.addEventListener(t, "click", n), () => { var r; (r = this.domEvents) == null || r.removeEventListener(t, "click", n); }; } getTagNormal(e) { if (e.normal) return C(e.normal); if (e.stickType === "Plane") return w(e.position); if (e.stickType === "Model") return w(this.getPositions(e)); } get filterPointTag() { var t; const e = this.tags.filter((i) => i.stickType === "2DPoint" || i.stickType === "3DPoint").filter((i) => i.position); return this.tagsLengthWillUpdate && (this._cache_pointTag = e, this.tagsLengthWillUpdate = !1), (t = this._cache_pointTag) != null ? t : e; } get filter2DPointTag() { var t; const e = this.tags.filter((i) => i.stickType === "2DPoint").filter((i) => i.position); return this.tagsLengthWillUpdate && (this._cache_2DPointTag = e, this.tagsLengthWillUpdate = !1), (t = this._cache_2DPointTag) != null ? t : e; } get filterImagePlane() { var t; const e = this.tags.filter( (i) => i.contentType === "MediaPlane" && i.stickType === "Plane" && this.getRenderType(i) === "Mesh" ); return this.tagsLengthWillUpdate && (this._cache_imagePlane = e, this.tagsLengthWillUpdate = !1), (t = this._cache_imagePlane) != null ? t : e; } get filterMediaModel() { var t; const e = this.tags.filter((i) => i.stickType === "Model" && i.contentType === "MediaModel"); return this.tagsLengthWillUpdate && (this._cache_mediaModel = e, this.tagsLengthWillUpdate = !1), (t = this._cache_mediaModel) != null ? t : e; } get filterCSS3DTag() { var t; const e = this.tags.filter( (i) => i.stickType === "3DPoint" || i.stickType === "Plane" || i.stickType === "Model" && i.contentType === "MediaModel" ).filter((i) => { const o = this.getRenderType(i); return o === "BehindDom" || o === "Dom"; }); return this.tagsLengthWillUpdate && (this._cache_css3DTag = e, this.tagsLengthWillUpdate = !1), (t = this._cache_css3DTag) != null ? t : e; } getTransformedPostion(e) { if (!e) return; const t = this.workUtil.transform; return Array.isArray(e) && e.length === 4 ? e.map(C).map((i) => J(i, t)) : J(C(e), t); } /** * @description 检查是否已经销毁 * @returns isDisposed; 已经销毁返回 true,否则返回 false */ checkDisposed() { return this.store.disposed ? (console.error("PanoTagPluginController has been disposed"), !0) : !1; } /** * @description 获取merge后的配置 */ calculateTagConfig(e, t) { var W, L, U, A, O; const i = (W = t == null ? void 0 : t.useCache) != null ? W : !0; if (!e) return (L = this.config.globalConfig) != null ? L : {}; if (i) { if ((U = e == null ? void 0 : e.computedConfig) != null && U._isMerged) return e.computedConfig; if ((A = e == null ? void 0 : e.config) != null && A._isMerged) return e.config; } const o = {}, n = {}, r = {}; this.config.contentTypeConfig && Object.entries(this.config.contentTypeConfig).forEach(([h, g]) => { var S, I; const c = h, D = c.split("-"), j = h.startsWith("["), T = j ? D[0].slice(1, -1) : void 0, p = j ? D.slice(1) : D, v = T ? ["PanoramaLike", "ModelLike"].includes(T) ? (S = n[T]) != null ? S : n[T] = {} : (I = r[T]) != null ? I : r[T] = {} : o; if (!v[c]) { if (p.length === 0 && (v[c] = g), p.length === 1) { const [u] = p; (e.contentType === u || u === "Any") && (v[c] = g); } if (p.length === 2) { const [u = "Any", M = "Any"] = p; u === "Mixin" && e.contentType === M && (v[c] = g), (e.stickType === u || u === "Any") && (e.contentType === M || M === "Any") && (v[c] = g); } if (p.length === 3) { const [u = "Any", M, X] = p; if (M === "Audio" && e.contentType === "Audio") { const x = e; (x.stickType === u || u === "Any") && x.data.appearance === X && (v[c] = g); } } } }); const a = (O = e.initialConfig) != null ? O : {}, d = y({}, ee, this.config.globalConfig, ...Object.values(o)), m = y({}, d, a), P = {}, G = Object.values(fe.Mode); z(n).forEach(([h, g]) => { G.forEach((c) => { (h === "PanoramaLike" && E(c) || h === "ModelLike" && $(c)) && (P[c] = y({}, d, ...Object.values(g), a, { _isMerged: !0 })); }); }), z(r).forEach(([h, g]) => { const c = P[h]; P[h] = y({}, d, c, ...Object.values(g), a, { _isMerged: !0 }); }); const k = V(b({}, m), { configWithFiveMode: P }); return N(k), Object.values(P).forEach((h) => N(h)), k._isMerged = !0, k; } } export { hi as TagUtil };