@realsee/dnalogel 3.77.5 → 3.77.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +15 -11
  2. package/dist/PanoTagPlugin/controller/Tag/BaseTag.d.ts +5 -1
  3. package/dist/PanoTagPlugin/controller/Tag/BoxTag.d.ts +119 -0
  4. package/dist/PanoTagPlugin/controller/Tag/MaskTag.d.ts +257 -0
  5. package/dist/PanoTagPlugin/controller/Tag/MaskTag.shaders.d.ts +10 -0
  6. package/dist/PanoTagPlugin/controller/Tag/PolygonTag.d.ts +112 -0
  7. package/dist/PanoTagPlugin/controller/TagRender.d.ts +1 -1
  8. package/dist/PanoTagPlugin/controller/index.d.ts +55 -2
  9. package/dist/PanoTagPlugin/typings/controller.d.ts +10 -0
  10. package/dist/PanoTagPlugin/typings/tag/Tag.d.ts +8 -3
  11. package/dist/PanoTagPlugin/typings/tag/Utils.d.ts +50 -1
  12. package/dist/PanoTagPlugin/utils/sculptDataToBoxPosition.d.ts +6 -0
  13. package/dist/PanoTagPlugin/utils/tag/tagCheck.d.ts +6 -0
  14. package/dist/PanoTagPlugin/utils/tagPosition.d.ts +12 -3
  15. package/dist/index.cjs.js +178 -95
  16. package/dist/index.js +11346 -9788
  17. package/dist/index.umd.js +173 -90
  18. package/libs/CruisePlugin/Move.js +7 -2
  19. package/libs/CruisePlugin/Work.js +7 -2
  20. package/libs/CruisePlugin/index.js +11 -6
  21. package/libs/GuideLinePlugin/Controller.js +9 -4
  22. package/libs/GuideLinePlugin/GuideLineItem.js +7 -2
  23. package/libs/GuideLinePlugin/GuideLineModeItem.js +7 -2
  24. package/libs/GuideLinePlugin/index.js +11 -6
  25. package/libs/PanoTagPlugin/Components/TagItem.js +122 -122
  26. package/libs/PanoTagPlugin/controller/Tag/BaseTag.d.ts +5 -1
  27. package/libs/PanoTagPlugin/controller/Tag/BaseTag.js +320 -289
  28. package/libs/PanoTagPlugin/controller/Tag/BoxTag.d.ts +119 -0
  29. package/libs/PanoTagPlugin/controller/Tag/BoxTag.js +515 -0
  30. package/libs/PanoTagPlugin/controller/Tag/MaskTag.d.ts +257 -0
  31. package/libs/PanoTagPlugin/controller/Tag/MaskTag.js +815 -0
  32. package/libs/PanoTagPlugin/controller/Tag/MaskTag.shaders.d.ts +10 -0
  33. package/libs/PanoTagPlugin/controller/Tag/MaskTag.shaders.js +94 -0
  34. package/libs/PanoTagPlugin/controller/Tag/PolygonTag.d.ts +112 -0
  35. package/libs/PanoTagPlugin/controller/Tag/PolygonTag.js +478 -0
  36. package/libs/PanoTagPlugin/controller/TagRender.d.ts +1 -1
  37. package/libs/PanoTagPlugin/controller/TagUtil.js +19 -17
  38. package/libs/PanoTagPlugin/controller/index.d.ts +55 -2
  39. package/libs/PanoTagPlugin/controller/index.js +261 -148
  40. package/libs/PanoTagPlugin/index.js +16 -11
  41. package/libs/PanoTagPlugin/typings/controller.d.ts +10 -0
  42. package/libs/PanoTagPlugin/typings/tag/Tag.d.ts +8 -3
  43. package/libs/PanoTagPlugin/typings/tag/Utils.d.ts +50 -1
  44. package/libs/PanoTagPlugin/utils/addDebugPoints.js +27 -13
  45. package/libs/PanoTagPlugin/utils/index.js +29 -26
  46. package/libs/PanoTagPlugin/utils/sculptDataToBoxPosition.d.ts +6 -0
  47. package/libs/PanoTagPlugin/utils/sculptDataToBoxPosition.js +18 -0
  48. package/libs/PanoTagPlugin/utils/tag/tagCheck.d.ts +6 -0
  49. package/libs/PanoTagPlugin/utils/tag/tagCheck.js +26 -14
  50. package/libs/PanoTagPlugin/utils/tagPosition.d.ts +12 -3
  51. package/libs/PanoTagPlugin/utils/tagPosition.js +49 -16
  52. package/libs/base/BasePlugin.js +1 -1
  53. package/libs/index.js +163 -158
  54. package/libs/shared-utils/logger.js +1 -1
  55. package/package.json +1 -1
@@ -0,0 +1,815 @@
1
+ var F = Object.defineProperty;
2
+ var R = Object.getOwnPropertySymbols;
3
+ var B = Object.prototype.hasOwnProperty, A = Object.prototype.propertyIsEnumerable;
4
+ var E = (m, c, e) => c in m ? F(m, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[c] = e, v = (m, c) => {
5
+ for (var e in c || (c = {}))
6
+ B.call(c, e) && E(m, e, c[e]);
7
+ if (R)
8
+ for (var e of R(c))
9
+ A.call(c, e) && E(m, e, c[e]);
10
+ return m;
11
+ };
12
+ var x = (m, c, e) => (E(m, typeof c != "symbol" ? c + "" : c, e), e);
13
+ var S = (m, c, e) => new Promise((s, t) => {
14
+ var o = (l) => {
15
+ try {
16
+ r(e.next(l));
17
+ } catch (n) {
18
+ t(n);
19
+ }
20
+ }, i = (l) => {
21
+ try {
22
+ r(e.throw(l));
23
+ } catch (n) {
24
+ t(n);
25
+ }
26
+ }, r = (l) => l.done ? s(l.value) : Promise.resolve(l.value).then(o, i);
27
+ r((e = e.apply(m, c)).next());
28
+ });
29
+ import { BaseTag as D } from "./BaseTag.js";
30
+ import * as g from "three";
31
+ import { anime as $ } from "../../../vendor/animejs/lib/anime.es.js";
32
+ import { maskVertexShader as z, maskFragmentShaderMulti as G } from "./MaskTag.shaders.js";
33
+ import { transformPosition as L } from "../../../shared-utils/five/transformPosition.js";
34
+ import "../../../shared-utils/Subscribe.js";
35
+ import "../../utils/tag/calculateTagConfig.js";
36
+ import "../../../vendor/object-assign-deep/objectAssignDeep.js";
37
+ import "../../../shared-utils/typescript/entries.js";
38
+ import "../../utils/tag/adaptConfig.js";
39
+ import "../../typings/tag/TagConfig.js";
40
+ import "@realsee/five";
41
+ import "../../../shared-utils/tag.js";
42
+ import "../../../shared-utils/positionToVector3.js";
43
+ import "../../../shared-utils/five/vector3ToScreen.js";
44
+ import "../../../shared-utils/five/getFiveModel.js";
45
+ import "../../../shared-utils/Utils/FiveUtil.js";
46
+ import "../../../shared-utils/Utils/BaseUtil.js";
47
+ import "../../../shared-utils/Utils/WorkUtil.js";
48
+ import "../../../shared-utils/three/temp.js";
49
+ import "../../../shared-utils/three/core/Raycaster.js";
50
+ import "../../../shared-utils/dom/resizeObserver.js";
51
+ import "../../../shared-utils/five/fiveEveryReadyListener.js";
52
+ import "../../../shared-utils/throttle.js";
53
+ import "../../../vendor/hammerjs/hammer.js";
54
+ import "../../../shared-utils/three/PointSelector/index.js";
55
+ import "../../../shared-utils/three/PointSelector/utils/PointSelectorHelper.js";
56
+ import "../../../shared-utils/three/Magnifier.js";
57
+ import "../../../shared-utils/three/PointSelector/utils/PointHelper.js";
58
+ import "../../../shared-utils/three/Assets/index.js";
59
+ import "../../../CSS3DRenderPlugin/utils/three/CSS3DObject.js";
60
+ import "../../../shared-utils/even.js";
61
+ import "../../../shared-utils/CSS3DRender/OpacityMesh.js";
62
+ import "../../../shared-utils/three/centerPoint.js";
63
+ import "../../../shared-utils/three/getObjectVisible.js";
64
+ import "../../../shared-utils/three/CSS3DRenderer/index.js";
65
+ import "../../../CSS3DRenderPlugin/utils/generateBehindFiveElement.js";
66
+ import "@realsee/five/line";
67
+ import "../../../shared-utils/isNil.js";
68
+ import "../../../shared-utils/three/core/Five_LineMaterial2.js";
69
+ import "../../../shared-utils/three/core/Sphere.js";
70
+ import "../../../shared-utils/three/blink.js";
71
+ import "../../../shared-utils/util.js";
72
+ import "../../../vendor/@tweenjs/tween/dist/tween.esm.js.js";
73
+ import "../../../CSS3DRenderPlugin/utils/three/CSS3DRender.js";
74
+ import "../../../shared-utils/CSS3DRender/CSS3DRenderer.js";
75
+ import "../../../shared-utils/createResizeObserver.js";
76
+ import "../../../CSS3DRenderPlugin/utils/three/CSS3DScene.js";
77
+ import "../../../CSS3DRenderPlugin/utils/getAllCSS3DObject.js";
78
+ import "../../../CSS3DRenderPlugin/utils/three/CSS3DGroup.js";
79
+ import "../../../shared-utils/three/PointSelector/utils/html.js";
80
+ import "../../../shared-utils/CSS3DRender/index.js";
81
+ import "../../../shared-utils/five/fiveModelLoad.js";
82
+ import "../../../shared-utils/three/PointSelector/utils/PointHelper2.js";
83
+ import "../../../Sculpt/Meshes/Line.js";
84
+ import "../../../Sculpt/typings/style.js";
85
+ import "../../../shared-utils/three/IObject3D.js";
86
+ import "../../../Sculpt/utils/Meshes/getLengthHTML.js";
87
+ import "../../../shared-utils/three/applyObjectMatrixWorld.js";
88
+ import "../../../shared-utils/three/core/LineGeometry.js";
89
+ import "../../../shared-utils/three/core/LineMaterial.js";
90
+ import "../../../shared-utils/three/core/Line2.js";
91
+ import "../../../shared-utils/three/core/LineMaterial2.js";
92
+ import "../../../Sculpt/utils/unit.js";
93
+ import "../../../Sculpt/utils/renderDom.js";
94
+ import "../../../vendor/earcut/src/earcut.js";
95
+ import "../../../shared-utils/five/FivePuppet.js";
96
+ import "../../../CSS3DRenderPlugin/utils/three/CSS3DSprite.js";
97
+ import "../../../shared-utils/isTouchDevice.js";
98
+ import "../../../shared-utils/five/getPosition.js";
99
+ import "../../../shared-utils/five/getRaycasterByNdcPosition.js";
100
+ import "../../../shared-utils/three/PointSelector/utils/contents.js";
101
+ import "../../../Sculpt/utils/three/rayOnLine.js";
102
+ import "../../../shared-utils/five/mode.js";
103
+ import "../../utils/tag/format.js";
104
+ import "../../../shared-utils/url/defaultUrls.js";
105
+ import "../../../shared-utils/vectorToCoordinate.js";
106
+ import "../../../shared-utils/formatRad.js";
107
+ import "../../../shared-utils/five/lookPoint.js";
108
+ import "../../../shared-utils/uuid.js";
109
+ import "../../utils/tagPosition.js";
110
+ import "../../utils/tag/tagCheck.js";
111
+ import "../../utils/checkRange.js";
112
+ import "../../../shared-utils/url/getUrl.js";
113
+ import "../../../shared-utils/five/getFloorIndex.js";
114
+ import "../../../shared-utils/safeObj.js";
115
+ import "../../utils/Cache.js";
116
+ import "../../../shared-utils/promise/withResolvers.js";
117
+ function w(m) {
118
+ if (Array.isArray(m))
119
+ return m;
120
+ if (typeof m == "number")
121
+ return [m >> 16 & 255, m >> 8 & 255, m & 255];
122
+ if (typeof m == "string") {
123
+ let c = m.trim().replace(/^#/, "");
124
+ if (c.length === 3 && (c = c[0] + c[0] + c[1] + c[1] + c[2] + c[2]), c.length === 6) {
125
+ const e = parseInt(c.substring(0, 2), 16), s = parseInt(c.substring(2, 4), 16), t = parseInt(c.substring(4, 6), 16);
126
+ if (!isNaN(e) && !isNaN(s) && !isNaN(t))
127
+ return [e, s, t];
128
+ }
129
+ console.warn("[MaskTag] Invalid hex color string:", m);
130
+ }
131
+ return [0, 0, 0];
132
+ }
133
+ const h = class extends D {
134
+ constructor(e, s) {
135
+ var i;
136
+ super(e, s);
137
+ /**
138
+ * mask 图片 URL 或 Canvas 元素(2:1 全景图格式)
139
+ */
140
+ x(this, "maskUrl");
141
+ /**
142
+ * 目标颜色(RGB 格式)
143
+ */
144
+ x(this, "targetColor");
145
+ /**
146
+ * mask 渲染的 mesh 对象(使用 Sphere)
147
+ */
148
+ x(this, "maskMesh");
149
+ /**
150
+ * mask 纹理对象
151
+ */
152
+ x(this, "maskTexture");
153
+ /**
154
+ * 是否正在加载 mask
155
+ */
156
+ x(this, "loadingMask", !1);
157
+ /**
158
+ * 资源是否已释放
159
+ */
160
+ x(this, "_disposed", !1);
161
+ /**
162
+ * 标签样式配置
163
+ */
164
+ x(this, "tagStyle");
165
+ /**
166
+ * 点击事件清理函数
167
+ */
168
+ x(this, "clickEventDispose");
169
+ /** 当前 tag 在共享 style 纹理中的下标(color 即 id) */
170
+ x(this, "sharedStyleIndex", -1);
171
+ /** 共享 mesh 的 registry key,用于 updateMaskStyle / dispose 查找 entry */
172
+ x(this, "_sharedMeshKey", null);
173
+ const t = (i = s.mask) != null ? i : s.maskUrl;
174
+ this.maskUrl = t instanceof HTMLCanvasElement || typeof t == "string" && t ? t : "";
175
+ const o = s.color;
176
+ this.targetColor = w(o), o || console.warn(`[MaskTag] No color provided for tag ${s.id}, using default [0, 0, 0]`), this.tagStyle = s.style, this.updateVisible(), this.currentVisible && this.initializeMaskMesh();
177
+ }
178
+ getColorKey() {
179
+ return `${this.targetColor[0]},${this.targetColor[1]},${this.targetColor[2]}`;
180
+ }
181
+ /** 同点位共用一个 mesh,key 仅用 panoIndex(string/canvas 切换时不会因 key 不同而重复创建) */
182
+ static getMeshKey(e) {
183
+ return String(e);
184
+ }
185
+ /**
186
+ * 初始化/挂载到同点位共享 mesh,用 appendStyleToMaterial 注册本 tag 的 style(color 即 id)
187
+ */
188
+ initializeMaskMesh() {
189
+ return S(this, null, function* () {
190
+ var s;
191
+ if (this._disposed || !this.maskUrl)
192
+ return;
193
+ const e = (s = this.fiveState) == null ? void 0 : s.panoIndex;
194
+ if (typeof e == "number") {
195
+ this.loadingMask = !0;
196
+ try {
197
+ const t = yield h.loadMaskTexture(this.maskUrl);
198
+ this.maskTexture = t;
199
+ const o = h.getMeshKey(e);
200
+ this._sharedMeshKey = o;
201
+ let i = h.sharedMeshRegistry.get(o);
202
+ const r = this.getColorKey(), l = this.buildStyleForMaterial();
203
+ i ? i.maskSource !== this.maskUrl && (h.releaseMaskTexture(i.maskSource), i.maskTexture = t, i.maskSource = this.maskUrl, i.material.uniforms.map.value = t) : (i = h.createSharedMesh(t, this.maskUrl, this.plugin), h.sharedMeshRegistry.set(o, i), this.plugin.imagePlaneGroup.add(i.mesh));
204
+ const n = i.styleIndexByColorKey.get(r);
205
+ n !== void 0 ? (this.sharedStyleIndex = n, this.maskMesh = i.mesh, this.updateStyleSlotInMaterial(i.material, n, l)) : (i.tagsByColorKey.set(r, this), this.appendStyleToMaterial(i.material, l), this.sharedStyleIndex = i.tagsByColorKey.size - 1, i.styleIndexByColorKey.set(r, this.sharedStyleIndex), this.maskMesh = i.mesh), this.setupSharedMeshRaycast(i), this.updateMeshTransform(), this.setupClickEvents(), this.updateScreenPosition(), i.mesh.visible = !0;
206
+ } finally {
207
+ this.loadingMask = !1;
208
+ }
209
+ }
210
+ });
211
+ }
212
+ /** 构建用于 mergedTexture 的 style 对象(color 作 id),tolerance 0–255 */
213
+ buildStyleForMaterial() {
214
+ const e = this.getMaskStyle(), s = e.tolerance, t = s <= 1 ? s * 255 : s;
215
+ return {
216
+ color: [this.targetColor[0], this.targetColor[1], this.targetColor[2], 1],
217
+ tolerance: t,
218
+ highlightColor: e.highlightColor,
219
+ opacity: this.enabled && this.visible ? e.opacity : 0
220
+ };
221
+ }
222
+ static createSharedMesh(e, s, t) {
223
+ const r = Math.max(1, Math.ceil(Math.sqrt(0))), l = 1, n = new Float32Array(r * l * 4), a = new g.DataTexture(n, r, l, g.RGBAFormat, g.FloatType);
224
+ a.needsUpdate = !0;
225
+ const d = new g.ShaderMaterial({
226
+ vertexShader: z,
227
+ fragmentShader: G,
228
+ uniforms: {
229
+ map: { value: e },
230
+ mergedTexture: { value: a },
231
+ groupCount: { value: 0 },
232
+ textureWidth: { value: r },
233
+ pixelsPerGroup: { value: 3 }
234
+ },
235
+ depthWrite: !1,
236
+ depthTest: !1,
237
+ transparent: !0
238
+ }), u = new g.SphereGeometry(1, 60, 40);
239
+ u.rotateY(-Math.PI / 2), u.scale(-1, 1, 1);
240
+ const p = new g.Mesh(u, d);
241
+ return p.renderOrder = -1e3, p.__maskMesh = !0, {
242
+ mesh: p,
243
+ material: d,
244
+ maskTexture: e,
245
+ maskSource: s,
246
+ tagsByColorKey: /* @__PURE__ */ new Map(),
247
+ styleIndexByColorKey: /* @__PURE__ */ new Map()
248
+ };
249
+ }
250
+ /** 仅更新材质中某一 slot 的 style(用于 enable/disable/updateMaskStyle) */
251
+ updateStyleSlotInMaterial(e, s, t) {
252
+ const i = e.uniforms.mergedTexture.value, r = i.image.data, n = s * 3, a = n * 4;
253
+ r[a] = t.color[0] / 255, r[a + 1] = t.color[1] / 255, r[a + 2] = t.color[2] / 255, r[a + 3] = t.color[3];
254
+ const d = (n + 1) * 4;
255
+ r[d] = t.tolerance / 255, r[d + 1] = t.highlightColor[0] / 255, r[d + 2] = t.highlightColor[1] / 255, r[d + 3] = t.highlightColor[2] / 255;
256
+ const u = (n + 2) * 4;
257
+ r[u] = t.opacity, i.needsUpdate = !0, this.five.needsRender = !0;
258
+ }
259
+ setupSharedMeshRaycast(e) {
260
+ const s = e.mesh;
261
+ if (s.__maskRaycastSet)
262
+ return;
263
+ s.__maskRaycastSet = !0;
264
+ let t = null, o = null;
265
+ const i = () => {
266
+ const l = e.maskTexture;
267
+ if (!(l != null && l.image))
268
+ return null;
269
+ if (o === l && t)
270
+ return t;
271
+ o = l;
272
+ try {
273
+ const n = document.createElement("canvas"), a = n.getContext("2d");
274
+ if (!a)
275
+ return null;
276
+ const d = l.image;
277
+ return n.width = d.width, n.height = d.height, a.drawImage(d, 0, 0), t = a.getImageData(0, 0, d.width, d.height), t;
278
+ } catch (n) {
279
+ return null;
280
+ }
281
+ }, r = s.raycast.bind(s);
282
+ s.raycast = (l, n) => {
283
+ var k, I;
284
+ const a = [];
285
+ if (r(l, a), a.length === 0)
286
+ return;
287
+ const d = a[0];
288
+ if (!d.uv || !((k = e.maskTexture) != null && k.image))
289
+ return;
290
+ const u = i();
291
+ if (!u)
292
+ return;
293
+ const p = Math.floor(d.uv.x * u.width), y = (Math.floor((1 - d.uv.y) * u.height) * u.width + p) * 4, f = [u.data[y], u.data[y + 1], u.data[y + 2]], M = 0.5 / 255;
294
+ for (const [, T] of e.tagsByColorKey) {
295
+ if (!T.enabled || ((I = T.config) == null ? void 0 : I.clickable) === !1)
296
+ continue;
297
+ const [K, P, U] = T.targetColor;
298
+ if (Math.abs(f[0] / 255 - K / 255) + Math.abs(f[1] / 255 - P / 255) + Math.abs(f[2] / 255 - U / 255) <= M) {
299
+ s.userData.__lastHitTag = T, n.push(d);
300
+ return;
301
+ }
302
+ }
303
+ };
304
+ }
305
+ /**
306
+ * 计算法向量
307
+ * Mask 标签返回向上的法向量(因为是贴在 cube 面上)
308
+ */
309
+ computeNormal() {
310
+ return new g.Vector3(0, 1, 0);
311
+ }
312
+ /**
313
+ * 不把共享 mesh 作为 blink 目标,闪烁通过本 tag 的 style opacity 动画实现
314
+ */
315
+ getAdditionalBlinkTargets() {
316
+ return null;
317
+ }
318
+ /**
319
+ * 闪烁仅针对本 tag:通过改变本 tag 在 merged texture 中的 opacity 实现
320
+ */
321
+ blink(e) {
322
+ return S(this, null, function* () {
323
+ var a, d, u;
324
+ if (!this.maskMesh || this._sharedMeshKey === null || this.sharedStyleIndex < 0)
325
+ return;
326
+ const s = h.sharedMeshRegistry.get(this._sharedMeshKey);
327
+ if (!s)
328
+ return;
329
+ const i = { opacity: this.buildStyleForMaterial().opacity }, r = (a = e == null ? void 0 : e.duration) != null ? a : 300, l = (d = e == null ? void 0 : e.loop) != null ? d : 4, n = $({
330
+ targets: i,
331
+ opacity: [0, 1],
332
+ duration: r,
333
+ easing: (u = e == null ? void 0 : e.easing) != null ? u : "easeInOutQuad",
334
+ direction: "alternate",
335
+ loop: l,
336
+ update: () => {
337
+ const p = this.buildStyleForMaterial();
338
+ p.opacity = i.opacity, this.updateStyleSlotInMaterial(s.material, this.sharedStyleIndex, p);
339
+ }
340
+ });
341
+ try {
342
+ yield n.finished;
343
+ } catch (p) {
344
+ } finally {
345
+ this.updateMaskStyle();
346
+ }
347
+ });
348
+ }
349
+ /**
350
+ * 更新标签数据
351
+ */
352
+ set(e, s = !0) {
353
+ var o, i;
354
+ super.set(e, s), e.style && (this.tagStyle = v(v({}, this.tagStyle), e.style), (o = e.style) != null && o.mask && this.updateMaskStyle());
355
+ const t = (i = e.mask) != null ? i : e.maskUrl;
356
+ t && t !== this.maskUrl && (this.maskUrl = t, this.updateSharedMeshTexture()), e.color !== void 0 && (this.targetColor = w(e.color), this.updateMaskStyle()), this.maskMesh && this.updateMaskStyle();
357
+ }
358
+ /** 供 rebuildEntryMaterial 使用:返回当前 tag 的 style 对象 */
359
+ getStyleForMaterial() {
360
+ return this.buildStyleForMaterial();
361
+ }
362
+ /**
363
+ * 重写 getVisible 方法
364
+ * Mask 标签仅在当前点位可见
365
+ */
366
+ getVisible(e) {
367
+ var s;
368
+ try {
369
+ if (!this.enabled || !this.plugin.state.enabled || !this.fiveUtil.model || !this.maskUrl)
370
+ return !1;
371
+ const t = v(v({}, this.five.getCurrentState()), e), { panoIndex: o } = t;
372
+ return o !== ((s = this.fiveState) == null ? void 0 : s.panoIndex) ? !1 : super.getVisible(t);
373
+ } catch (t) {
374
+ return !1;
375
+ }
376
+ }
377
+ /**
378
+ * 重写 computeVisible 方法
379
+ * 增加 Mask 特有的可见性检查逻辑,用于 whyHide 功能
380
+ */
381
+ computeVisible(e) {
382
+ var o, i, r;
383
+ const s = v(v({}, this.five.getCurrentState()), e), { panoIndex: t } = s;
384
+ return t !== ((o = this.fiveState) == null ? void 0 : o.panoIndex) ? {
385
+ value: !1,
386
+ reason: {
387
+ type: "panoIndex mismatch",
388
+ detail: `Mask 标签仅在当前点位可见。当前点位: ${t}, 标签点位: ${(i = this.fiveState) == null ? void 0 : i.panoIndex}`,
389
+ currentPanoIndex: t,
390
+ tagPanoIndex: (r = this.fiveState) == null ? void 0 : r.panoIndex
391
+ }
392
+ } : super.computeVisible(e);
393
+ }
394
+ /**
395
+ * 点击事件处理
396
+ */
397
+ onClick(e) {
398
+ e.target === "TagMaskModel" && this.unfoldAndFoldOthers();
399
+ }
400
+ /**
401
+ * 展开自己,收起其他标签
402
+ */
403
+ unfoldAndFoldOthers() {
404
+ if (this.isPopoverConfigEnabled())
405
+ return;
406
+ const e = this.can("fold"), s = this.can("unfold");
407
+ e && s && (this.state.unfolded = !this.state.unfolded, this.manuallyOperated = !0, this.plugin.addRenderQueue({ type: "TagContainerSvelte", keys: ["tags"] }), this.state.unfolded && this.plugin.tags.forEach((t) => {
408
+ t.id !== this.id && t.fold();
409
+ }));
410
+ }
411
+ /**
412
+ * 展开标签详情
413
+ */
414
+ unfold() {
415
+ this.isPopoverConfigEnabled() || this.setUnfold(!0);
416
+ }
417
+ /**
418
+ * 折叠标签详情
419
+ */
420
+ fold() {
421
+ this.isPopoverConfigEnabled() || this.setUnfold(!1);
422
+ }
423
+ /**
424
+ * 设置展开/折叠状态
425
+ */
426
+ setUnfold(e) {
427
+ if (this.isPopoverConfigEnabled())
428
+ return;
429
+ const s = this.can("fold"), t = this.can("unfold");
430
+ s && t && (this.state.unfolded = e, this.hooks.emit(e ? "unfolded" : "folded"), this.plugin.addRenderQueue({ type: "TagContainerSvelte", keys: ["tags"] }));
431
+ }
432
+ /**
433
+ * 更新屏幕位置
434
+ */
435
+ updateScreenPosition() {
436
+ if (!this.currentVisible || !this.position || !Array.isArray(this.position)) {
437
+ this.screenPosition = null, this.plugin.addRenderQueue({ type: "TagContainerSvelte", keys: ["tags"] });
438
+ return;
439
+ }
440
+ const s = new g.Vector3(...this.position).clone().project(this.five.camera);
441
+ if (this.five.renderer) {
442
+ const t = this.five.renderer.getSize(new g.Vector2());
443
+ this.screenPosition = {
444
+ leftPx: (s.x + 1) / 2 * t.x,
445
+ topPx: (-s.y + 1) / 2 * t.y,
446
+ scale: 1
447
+ };
448
+ }
449
+ this.plugin.addRenderQueue({ type: "TagContainerSvelte", keys: ["tags"] });
450
+ }
451
+ /**
452
+ * 应用可见性变化(通过 style opacity 控制展示,共享 mesh 保持 visible)
453
+ */
454
+ applyVisible() {
455
+ try {
456
+ if (!this.maskUrl)
457
+ return;
458
+ this.visible && !this.loadingMask && this.initializeMaskMesh(), this.maskMesh && (this.updateMaskStyle(), this.updateMeshTransform()), this.updateScreenPosition();
459
+ } catch (e) {
460
+ console.error(`[MaskTag] Error in applyVisible for tag ${this.id}:`, e);
461
+ }
462
+ }
463
+ /**
464
+ * 更新 mesh 的位置和旋转(跟随观察者)
465
+ * 参考 itemMask 实现
466
+ */
467
+ updateMeshTransform() {
468
+ var r;
469
+ if (!this.maskMesh)
470
+ return;
471
+ const e = (r = this.fiveState) == null ? void 0 : r.panoIndex;
472
+ if (e === void 0)
473
+ return;
474
+ const s = this.workUtil.getObserver(e);
475
+ if (!s)
476
+ return;
477
+ this.maskMesh.position.copy(L(s.position, this.workUtil.transform)), this.maskMesh.quaternion.copy(s.quaternion);
478
+ const t = new g.Vector3(), o = new g.Quaternion(), i = new g.Vector3();
479
+ this.workUtil.transform.decompose(t, o, i), this.maskMesh.quaternion.multiply(o), this.five.needsRender = !0;
480
+ }
481
+ /**
482
+ * 步骤1:从材质中解析出 styleList
483
+ * @param {THREE.ShaderMaterial} material - 目标材质
484
+ * @returns {Array} 解析后的 styleList
485
+ */
486
+ parseStyleListFromMaterial(e) {
487
+ const s = e.uniforms, t = s.groupCount.value, o = s.pixelsPerGroup.value, r = s.mergedTexture.value.image.data, l = [];
488
+ for (let n = 0; n < t; n++) {
489
+ const a = n * o, d = a * 4, u = r[d] * 255, p = r[d + 1] * 255, C = r[d + 2] * 255, y = r[d + 3], f = (a + 1) * 4, M = r[f] * 255, k = r[f + 1] * 255, I = r[f + 2] * 255, T = r[f + 3] * 255, K = (a + 2) * 4, P = r[K];
490
+ l.push({
491
+ color: [Math.round(u), Math.round(p), Math.round(C), y],
492
+ tolerance: Math.round(M),
493
+ highlightColor: [Math.round(k), Math.round(I), Math.round(T)],
494
+ opacity: P
495
+ });
496
+ }
497
+ return l;
498
+ }
499
+ /**
500
+ * 步骤2:更新材质的样式纹理(追加新元素后)
501
+ * @param {THREE.ShaderMaterial} material - 目标材质
502
+ * @param {Array} newStyle - 要追加的新样式对象
503
+ */
504
+ appendStyleToMaterial(e, s) {
505
+ const t = this.parseStyleListFromMaterial(e);
506
+ Array.isArray(s) ? t.push(...s) : t.push(s);
507
+ const o = t.length, i = 3, l = o * i, n = 1, a = new Float32Array(l * n * 4);
508
+ t.forEach((p, C) => {
509
+ const y = C * i, f = y * 4;
510
+ a[f] = p.color[0] / 255, a[f + 1] = p.color[1] / 255, a[f + 2] = p.color[2] / 255, a[f + 3] = p.color[3];
511
+ const M = (y + 1) * 4;
512
+ a[M] = p.tolerance / 255, a[M + 1] = p.highlightColor[0] / 255, a[M + 2] = p.highlightColor[1] / 255, a[M + 3] = p.highlightColor[2] / 255;
513
+ const k = (y + 2) * 4;
514
+ a[k] = p.opacity, a[k + 1] = 0, a[k + 2] = 0, a[k + 3] = 0;
515
+ });
516
+ const d = e.uniforms.mergedTexture.value, u = d.image;
517
+ u.data = a, u.width = l, u.height = n, d.needsUpdate = !0, e.uniforms.groupCount.value = o, e.uniforms.textureWidth.value = l, console.log(`成功追加样式,当前总组数:${o}`);
518
+ }
519
+ /**
520
+ * 获取 Mask 样式配置(合并用户配置和默认值)
521
+ */
522
+ getMaskStyle() {
523
+ var t, o, i;
524
+ const e = ((t = this.tagStyle) == null ? void 0 : t.mask) || {};
525
+ let s = [255, 255, 255];
526
+ return e.color !== void 0 ? s = w(e.color) : e.highlightColor !== void 0 && (s = w(e.highlightColor)), {
527
+ tolerance: (o = e.tolerance) != null ? o : 1e-3,
528
+ // 参考 itemMask 默认 0.001(归一化后的值)
529
+ highlightColor: s,
530
+ opacity: (i = e.opacity) != null ? i : 0.6
531
+ // 默认 0.6(用于填充区域)
532
+ };
533
+ }
534
+ /**
535
+ * 设置点击事件(仅当 raycast 命中本 tag 的 color 时触发)
536
+ */
537
+ setupClickEvents() {
538
+ var s;
539
+ if (!this.maskMesh || ((s = this.config) == null ? void 0 : s.clickable) === !1)
540
+ return;
541
+ this.cleanupClickEvents();
542
+ const e = (t) => {
543
+ var i, r;
544
+ ((r = (i = this.maskMesh) == null ? void 0 : i.userData) == null ? void 0 : r.__lastHitTag) === this && this.plugin.hooks.emit("click", { event: t, target: "TagMaskModel", tag: this });
545
+ };
546
+ requestAnimationFrame(() => {
547
+ !this.maskMesh || !this.plugin.domEvents || (this.clickEventDispose = this.addObjectClickHandler(this, this.maskMesh, e));
548
+ });
549
+ }
550
+ /**
551
+ * 清理点击事件
552
+ */
553
+ cleanupClickEvents() {
554
+ this.clickEventDispose && (this.clickEventDispose(), this.clickEventDispose = void 0);
555
+ }
556
+ /**
557
+ * 重新加载 mask 图:从旧点位 mesh 注销,再按新 maskUrl 初始化
558
+ */
559
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- 保留参数与 set() 调用一致
560
+ reloadMask(e) {
561
+ var i;
562
+ const s = (i = this.fiveState) == null ? void 0 : i.panoIndex, t = this.getColorKey(), o = typeof s == "number" ? h.getMeshKey(s) : this._sharedMeshKey;
563
+ if (o) {
564
+ const r = h.sharedMeshRegistry.get(o);
565
+ r && (r.tagsByColorKey.delete(t), r.styleIndexByColorKey.delete(t), r.tagsByColorKey.size === 0 && (r.mesh.parent && r.mesh.parent.remove(r.mesh), r.mesh.geometry.dispose(), r.mesh.material.dispose(), r.material.uniforms.mergedTexture.value.dispose(), h.releaseMaskTexture(r.maskSource), h.sharedMeshRegistry.delete(o)));
566
+ }
567
+ this.maskMesh = void 0, this._sharedMeshKey = null, this.sharedStyleIndex = -1, this.maskTexture = void 0, this.visible && !this.loadingMask && this.initializeMaskMesh();
568
+ }
569
+ /**
570
+ * changeTagById 改 mask 时:只更新共享 mesh 的 texture,不 unregister
571
+ * 有 entry 则换图;无 entry 则走完整初始化
572
+ */
573
+ updateSharedMeshTexture() {
574
+ return S(this, null, function* () {
575
+ var i;
576
+ if (this._disposed || !this.maskUrl)
577
+ return;
578
+ const e = (i = this.fiveState) == null ? void 0 : i.panoIndex;
579
+ if (typeof e != "number")
580
+ return;
581
+ const s = h.getMeshKey(e), t = h.sharedMeshRegistry.get(s);
582
+ if (!t) {
583
+ yield this.initializeMaskMesh();
584
+ return;
585
+ }
586
+ if (t.maskSource === this.maskUrl)
587
+ return;
588
+ const o = yield h.loadMaskTexture(this.maskUrl);
589
+ this.maskTexture = o, h.releaseMaskTexture(t.maskSource), t.maskTexture = o, t.maskSource = this.maskUrl, t.material.uniforms.map.value = o, this.five.needsRender = !0;
590
+ });
591
+ }
592
+ /**
593
+ * 更新当前 tag 在共享材质中的 style slot(color/style 控制展示)
594
+ */
595
+ updateMaskStyle() {
596
+ if (!this.maskMesh || this._sharedMeshKey === null || this.sharedStyleIndex < 0)
597
+ return;
598
+ const e = h.sharedMeshRegistry.get(this._sharedMeshKey);
599
+ e && this.updateStyleSlotInMaterial(e.material, this.sharedStyleIndex, this.buildStyleForMaterial());
600
+ }
601
+ /**
602
+ * 更新 Canvas 纹理(仅当 maskUrl 为 Canvas 时有效)
603
+ * 当 canvas 内容发生变化时,调用此方法更新渲染
604
+ */
605
+ updateCanvasTexture() {
606
+ if (!this.maskTexture || typeof this.maskUrl == "string") {
607
+ console.warn("[MaskTag] updateCanvasTexture only works for Canvas-based masks");
608
+ return;
609
+ }
610
+ this.maskTexture instanceof g.CanvasTexture && (this.maskTexture.needsUpdate = !0, this.five.needsRender = !0, console.log("[MaskTag] Canvas texture updated"));
611
+ }
612
+ /**
613
+ * 清理当前标签:从共享材质中删除本 tag 的样式槽,并更新材质;
614
+ * 若该点位已无其他 tag 则销毁 mesh 并释放纹理。
615
+ */
616
+ disposeMaskResources() {
617
+ if (this._disposed)
618
+ return;
619
+ this._disposed = !0, this.cleanupClickEvents();
620
+ const e = this._sharedMeshKey, s = this.getColorKey();
621
+ if (e) {
622
+ const t = h.sharedMeshRegistry.get(e);
623
+ t && (t.tagsByColorKey.delete(s), t.styleIndexByColorKey.delete(s), t.tagsByColorKey.size === 0 ? (t.mesh.parent && t.mesh.parent.remove(t.mesh), t.mesh.geometry.dispose(), t.mesh.material.dispose(), t.material.uniforms.mergedTexture.value.dispose(), h.releaseMaskTexture(t.maskSource), h.sharedMeshRegistry.delete(e)) : h.rebuildEntryMaterial(t));
624
+ }
625
+ this.maskMesh = void 0, this._sharedMeshKey = null, this.sharedStyleIndex = -1, this.maskTexture = void 0;
626
+ }
627
+ /**
628
+ * 清理 MaskTag 特有的资源(公开方法)
629
+ */
630
+ dispose() {
631
+ this.disposeMaskResources();
632
+ }
633
+ /**
634
+ * 禁用标签(通过 style opacity=0 隐藏,不拆 mesh)
635
+ */
636
+ disable() {
637
+ super.disable(), this.updateMaskStyle();
638
+ }
639
+ /**
640
+ * 启用标签(恢复 style 展示)
641
+ */
642
+ enable() {
643
+ super.enable(), this.updateMaskStyle();
644
+ }
645
+ /**
646
+ * 销毁标签(重写父类方法)
647
+ */
648
+ destroy() {
649
+ this.disposeMaskResources(), super.destroy();
650
+ }
651
+ /**
652
+ * 清除所有点位共享 mesh(重新 load 数据前调用)
653
+ */
654
+ static clearSharedMeshRegistry() {
655
+ h.sharedMeshRegistry.forEach((e) => {
656
+ e.tagsByColorKey.forEach((s) => {
657
+ s.maskMesh = void 0, s._sharedMeshKey = null, s.sharedStyleIndex = -1;
658
+ }), e.mesh.parent && e.mesh.parent.remove(e.mesh), e.mesh.geometry.dispose(), e.mesh.material.dispose(), e.material.uniforms.mergedTexture.value.dispose(), h.releaseMaskTexture(e.maskSource);
659
+ }), h.sharedMeshRegistry.clear();
660
+ }
661
+ /**
662
+ * 将 style 列表写入材质(用于重建材质)
663
+ */
664
+ static writeStyleListToMaterial(e, s) {
665
+ const t = s.length, o = 3, r = t * o, l = 1, n = new Float32Array(r * l * 4);
666
+ s.forEach((u, p) => {
667
+ const C = p * o, y = C * 4;
668
+ n[y] = u.color[0] / 255, n[y + 1] = u.color[1] / 255, n[y + 2] = u.color[2] / 255, n[y + 3] = u.color[3];
669
+ const f = (C + 1) * 4;
670
+ n[f] = u.tolerance / 255, n[f + 1] = u.highlightColor[0] / 255, n[f + 2] = u.highlightColor[1] / 255, n[f + 3] = u.highlightColor[2] / 255;
671
+ const M = (C + 2) * 4;
672
+ n[M] = u.opacity;
673
+ });
674
+ const a = e.uniforms.mergedTexture.value, d = a.image;
675
+ d.data = n, d.width = r, d.height = l, a.needsUpdate = !0, e.uniforms.groupCount.value = t, e.uniforms.textureWidth.value = r;
676
+ }
677
+ /**
678
+ * destroy 后重建该点位材质,更新剩余 tag 的 styleIndex
679
+ */
680
+ static rebuildEntryMaterial(e) {
681
+ const s = Array.from(e.tagsByColorKey.values()).sort((o, i) => o.sharedStyleIndex - i.sharedStyleIndex);
682
+ if (s.length === 0)
683
+ return;
684
+ const t = s.map((o) => o.getStyleForMaterial());
685
+ h.writeStyleListToMaterial(e.material, t), s.forEach((o, i) => {
686
+ o.sharedStyleIndex = i, e.styleIndexByColorKey.set(`${o.targetColor[0]},${o.targetColor[1]},${o.targetColor[2]}`, i);
687
+ });
688
+ }
689
+ /**
690
+ * 获取 mask 的缓存 key
691
+ * @param maskSource mask URL 或 Canvas
692
+ * @returns 缓存 key
693
+ */
694
+ static getMaskCacheKey(e) {
695
+ if (typeof e == "string")
696
+ return e;
697
+ {
698
+ let s = h.canvasSymbolMap.get(e);
699
+ return s || (s = Symbol("canvas-mask"), h.canvasSymbolMap.set(e, s)), s;
700
+ }
701
+ }
702
+ /**
703
+ * 加载 Mask 纹理(静态方法,支持缓存和引用计数)
704
+ * @param maskSource mask 图片 URL 或 Canvas 元素
705
+ * @returns Promise<THREE.Texture>
706
+ */
707
+ static loadMaskTexture(e) {
708
+ return S(this, null, function* () {
709
+ const s = h.getMaskCacheKey(e), t = h.maskTextureCache.get(s);
710
+ if (t)
711
+ return t.refCount++, t.texture;
712
+ const o = performance.now(), i = new AbortController();
713
+ try {
714
+ let r;
715
+ if (typeof e == "string") {
716
+ const a = new g.TextureLoader();
717
+ r = yield new Promise((d, u) => {
718
+ if (i.signal.aborted) {
719
+ u(new Error("Load aborted"));
720
+ return;
721
+ }
722
+ a.load(
723
+ e,
724
+ (p) => {
725
+ i.signal.aborted ? (p.dispose(), u(new Error("Load aborted"))) : d(p);
726
+ },
727
+ void 0,
728
+ (p) => {
729
+ u(p);
730
+ }
731
+ ), i.signal.addEventListener("abort", () => {
732
+ u(new Error("Load aborted"));
733
+ });
734
+ });
735
+ } else
736
+ r = new g.CanvasTexture(e), r.needsUpdate = !0, console.log("[MaskTag] Created texture from canvas, size:", e.width, "x", e.height);
737
+ r.wrapS = g.ClampToEdgeWrapping, r.wrapT = g.ClampToEdgeWrapping, r.minFilter = g.LinearFilter, r.magFilter = g.LinearFilter, r.anisotropy = 4, r instanceof g.CanvasTexture && (r.needsUpdate = !0), h.maskTextureCache.set(s, {
738
+ texture: r,
739
+ refCount: 1,
740
+ abortController: i
741
+ });
742
+ const l = performance.now() - o, n = typeof e == "string" ? e.substring(0, 50) : "Canvas";
743
+ if (console.log(`[MaskTag Performance] Texture loaded in ${l.toFixed(2)}ms, source: ${n}`), r.image) {
744
+ const a = (r.image.width * r.image.height * 4 / 1048576).toFixed(2);
745
+ console.log(`[MaskTag Memory] Texture size: ${r.image.width}x${r.image.height}, estimated memory: ${a}MB`);
746
+ }
747
+ return r;
748
+ } catch (r) {
749
+ throw console.error("[MaskTag] Failed to load mask texture:", typeof e == "string" ? e : "Canvas", r), r;
750
+ }
751
+ });
752
+ }
753
+ /**
754
+ * 释放 Mask 纹理(静态方法)
755
+ * @param maskSource mask 图片 URL 或 Canvas 元素
756
+ */
757
+ static releaseMaskTexture(e) {
758
+ var o;
759
+ const s = h.getMaskCacheKey(e), t = h.maskTextureCache.get(s);
760
+ if (t && (t.refCount--, t.refCount <= 0)) {
761
+ const i = typeof e == "string" ? e.substring(0, 50) : "Canvas";
762
+ console.log(`[MaskTag Memory] Releasing texture (refCount=0): ${i}`), (o = t.abortController) == null || o.abort(), t.texture.dispose(), h.maskTextureCache.delete(s);
763
+ }
764
+ }
765
+ /**
766
+ * 获取当前缓存的纹理统计信息(用于性能监控和调试)
767
+ * @returns 缓存统计信息
768
+ */
769
+ static getCacheStats() {
770
+ let e = 0, s = 0;
771
+ const t = [];
772
+ return h.maskTextureCache.forEach((o, i) => {
773
+ e += o.refCount;
774
+ let r = 0;
775
+ if (o.texture.image) {
776
+ const n = o.texture.image.width || 0, a = o.texture.image.height || 0;
777
+ r = n * a * 4 / (1024 * 1024), s += r;
778
+ }
779
+ const l = typeof i == "string" ? i.substring(0, 80) : "[Canvas]";
780
+ t.push({
781
+ source: l,
782
+ refCount: o.refCount,
783
+ sizeMB: parseFloat(r.toFixed(2))
784
+ });
785
+ }), {
786
+ totalCached: h.maskTextureCache.size,
787
+ totalRefCount: e,
788
+ estimatedMemoryMB: parseFloat(s.toFixed(2)),
789
+ cacheEntries: t
790
+ };
791
+ }
792
+ /**
793
+ * 强制清理所有缓存的纹理(用于内存管理,谨慎使用)
794
+ * 注意:这会释放所有纹理,即使它们仍在使用中
795
+ */
796
+ static clearAllCache() {
797
+ console.warn("[MaskTag] Clearing all texture cache"), h.maskTextureCache.forEach((e) => {
798
+ var s;
799
+ (s = e.abortController) == null || s.abort(), e.texture.dispose();
800
+ }), h.maskTextureCache.clear();
801
+ }
802
+ };
803
+ let b = h;
804
+ /**
805
+ * Mask 纹理缓存(静态,所有 MaskTag 实例共享)
806
+ * key: mask URL 或 canvas 的 symbol, value: { texture: THREE.Texture, refCount: number, abortController?: AbortController }
807
+ */
808
+ x(b, "maskTextureCache", /* @__PURE__ */ new Map()), /**
809
+ * Canvas 到 Symbol 的映射(用于缓存 canvas 纹理)
810
+ */
811
+ x(b, "canvasSymbolMap", /* @__PURE__ */ new WeakMap()), /** 同点位共用 mesh:key = meshKey(panoIndex + maskKey), value = 共享数据 */
812
+ x(b, "sharedMeshRegistry", /* @__PURE__ */ new Map());
813
+ export {
814
+ b as MaskTag
815
+ };