web3dlink 2.0.17 → 2.1.1

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.
package/dist/web3dlink.js CHANGED
@@ -1,6 +1,147 @@
1
1
  //#region \0rolldown/runtime.js
2
2
  var __commonJSMin = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports);
3
3
  //#endregion
4
+ //#region zs-stream-parent.js
5
+ (function(e) {
6
+ let t = "zs-stream-parent", n = "zs-stream-embed";
7
+ function r(e) {
8
+ return e ? typeof e == "string" ? document.querySelector(e) : e : null;
9
+ }
10
+ function i(e, t, n) {
11
+ let r = (e || "").replace(/\/+$/, "") || (typeof location < "u" ? location.origin : ""), i = new URLSearchParams({
12
+ template: t || "default",
13
+ autoconnect: "1",
14
+ muted: "1"
15
+ });
16
+ return n && i.set("streamId", n), `${r}/embed?${i.toString()}`;
17
+ }
18
+ function a(e, n, r) {
19
+ return e?.contentWindow ? (e.contentWindow.postMessage({
20
+ source: t,
21
+ streamId: n,
22
+ ...r
23
+ }, "*"), { ok: !0 }) : {
24
+ ok: !1,
25
+ error: "iframe 未就绪"
26
+ };
27
+ }
28
+ class o {
29
+ constructor({ streamId: t, template: n, container: i, baseUrl: a } = {}) {
30
+ if (!t) throw Error("ZsStream: streamId 必填(同页多路时用于区分)");
31
+ this.streamId = t, this.template = n || "default", this.baseUrl = a, this.container = r(i), this.iframe = null, this._handlers = /* @__PURE__ */ new Map(), this._ready = !1, this._inputReady = !1, this._onMessage = this._onMessage.bind(this), e.addEventListener("message", this._onMessage), this._mountIframe();
32
+ }
33
+ _mountIframe() {
34
+ if (!this.container) throw Error("ZsStream: container 未找到");
35
+ let e = document.createElement("iframe");
36
+ e.src = i(this.baseUrl, this.template, this.streamId), e.style.width = "100%", e.style.height = "100%", e.style.border = "0", e.setAttribute("allow", "autoplay; fullscreen; encrypted-media"), e.title = `ZS Stream ${this.streamId}`, this.container.innerHTML = "", this.container.appendChild(e), this.iframe = e;
37
+ }
38
+ _onMessage(e) {
39
+ let t = e.data;
40
+ if (!t || t.source !== n || t.streamId && t.streamId !== this.streamId || t.type !== "event") return;
41
+ let r = t.event;
42
+ r === "ready" && (this._ready = !0), r === "inputready" && (this._inputReady = !0), this._emit(r, t.data);
43
+ }
44
+ _emit(e, t) {
45
+ let n = this._handlers.get(e);
46
+ if (n) for (let e of n) try {
47
+ e(t);
48
+ } catch (e) {
49
+ console.error("[ZsStream]", e);
50
+ }
51
+ }
52
+ on(e, t) {
53
+ return this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(t), () => this.off(e, t);
54
+ }
55
+ off(e, t) {
56
+ this._handlers.get(e)?.delete(t);
57
+ }
58
+ _send(e, t) {
59
+ return a(this.iframe, this.streamId, {
60
+ type: e,
61
+ ...t
62
+ });
63
+ }
64
+ invoke(e, t, n) {
65
+ return this._send("invoke", {
66
+ module: e,
67
+ action: t,
68
+ params: n ?? {}
69
+ });
70
+ }
71
+ camera(e, t) {
72
+ return this._send("camera", {
73
+ action: e,
74
+ params: t ?? {}
75
+ });
76
+ }
77
+ sendRaw(e) {
78
+ return this._send("sendRaw", { descriptor: String(e) });
79
+ }
80
+ sendCommand(e, t) {
81
+ return this._send("larkCommand", {
82
+ command: e,
83
+ params: t ?? {}
84
+ });
85
+ }
86
+ sendTextToDataChannel(e) {
87
+ let t = typeof e == "string" ? e : JSON.stringify({
88
+ command: e.command,
89
+ params: e.params ?? {}
90
+ });
91
+ return this._send("sendRaw", { descriptor: t });
92
+ }
93
+ disconnect() {
94
+ return this._send("disconnect", {});
95
+ }
96
+ destroy() {
97
+ e.removeEventListener("message", this._onMessage), this.disconnect(), this.iframe?.parentNode && this.iframe.parentNode.removeChild(this.iframe), this.iframe = null, this._handlers.clear();
98
+ }
99
+ get isReady() {
100
+ return this._ready;
101
+ }
102
+ get isInputReady() {
103
+ return this._inputReady;
104
+ }
105
+ }
106
+ class s {
107
+ constructor() {
108
+ this._streams = /* @__PURE__ */ new Map();
109
+ }
110
+ mount(e) {
111
+ let t = e?.streamId;
112
+ if (!t) throw Error("ZsStreamHub.mount: streamId 必填");
113
+ this._streams.has(t) && this._streams.get(t).destroy();
114
+ let n = new o(e);
115
+ return this._streams.set(t, n), n;
116
+ }
117
+ get(e) {
118
+ return this._streams.get(e) || null;
119
+ }
120
+ has(e) {
121
+ return this._streams.has(e);
122
+ }
123
+ destroy(e) {
124
+ let t = this._streams.get(e);
125
+ t && (t.destroy(), this._streams.delete(e));
126
+ }
127
+ destroyAll() {
128
+ for (let e of [...this._streams.keys()]) this.destroy(e);
129
+ }
130
+ list() {
131
+ return [...this._streams.keys()];
132
+ }
133
+ }
134
+ e.ZsStream = {
135
+ mount(e) {
136
+ return new o(e);
137
+ },
138
+ Hub: s,
139
+ buildEmbedSrc: i,
140
+ MSG_SOURCE_PARENT: t,
141
+ MSG_SOURCE_EMBED: n
142
+ }, e.ZsStreamHub = s;
143
+ })(typeof window < "u" ? window : globalThis);
144
+ //#endregion
4
145
  //#region ../baseConfig/responses.js
5
146
  function createSuccessResponse(e, t, n) {
6
147
  return {
@@ -41,7 +182,7 @@ function log(...e) {
41
182
  //#region commFlow.js
42
183
  var CommandManager = class {
43
184
  constructor(e) {
44
- this.larkClient = e, this.callbacks = {}, this.requestId = 0, this.timeout = 3e3, this.markerEventCallbacks = {
185
+ this.transport = e, this.callbacks = {}, this.requestId = 0, this.timeout = 3e3, this.markerEventCallbacks = {
45
186
  Hovered: {},
46
187
  Click: {},
47
188
  Unhovered: {}
@@ -53,8 +194,8 @@ var CommandManager = class {
53
194
  Hovered: {},
54
195
  Click: {},
55
196
  Unhovered: {}
56
- }, this.animationOnDataCallback = { Change: [] }, this.mouseClickCallback = { MouseClick: [] }, this.vtkMouseClickCallback = {}, this.larkClient.on("datachanneltext", (e) => {
57
- this._handleResponse(e);
197
+ }, this.animationOnDataCallback = { Change: [] }, this.mouseClickCallback = { MouseClick: [] }, this.vtkMouseClickCallback = {}, e.bindMessageHandler((e) => {
198
+ this._handleRawResponse(e);
58
199
  });
59
200
  }
60
201
  sendWithDefault(e, t, n = {}) {
@@ -74,7 +215,7 @@ var CommandManager = class {
74
215
  requestId: i,
75
216
  params: r
76
217
  };
77
- return log("消息下发成功:", s), this.larkClient.sendTextToDataChannel(JSON.stringify(s)), o.then((e) => {
218
+ return log("消息下发成功:", s), this.transport.sendTextToDataChannel(JSON.stringify(s)), o.then((e) => {
78
219
  if (e && e.command && e.command === t) switch (e.status) {
79
220
  case "info": return createSuccessResponse("操作执行成功", e.data, t);
80
221
  case "warn": return createWarnResponse(e.message, e.data, t);
@@ -83,26 +224,26 @@ var CommandManager = class {
83
224
  return createErrorResponse("返回数据格式错乱【请注意command参数】", e?.command, t);
84
225
  }).catch((e) => e && e.message ? e.message === "Command timeout with no results" ? createWarnResponse(e.message, r, t) : createErrorResponse(e.message, r, t) : createErrorResponse("数据返回发生错误", r, t));
85
226
  }
86
- _handleResponse(e) {
87
- if (!(e.type === "datachanneltext" && typeof e.data == "string")) return console.error("数据第一步解析失败:", e), null;
227
+ _handleRawResponse(e) {
228
+ if (!e) return console.error("数据第一步解析失败:", e), null;
88
229
  let t;
89
230
  try {
90
- let n = JSON.parse(e.data.trim());
231
+ let n = JSON.parse(String(e).trim());
91
232
  if (t = {
92
233
  command: n.command || "",
93
234
  message: n.message || "",
94
235
  data: n.data || {},
95
236
  status: n.status || "error",
96
237
  requestId: n.requestId || ""
97
- }, t.message === "The data channel has been connected.") return null;
238
+ }, t.message === "The data channel has been connected." || t.message === "The level has been initialized") return null;
98
239
  } catch {
99
240
  return console.error("数据第二步解析失败:", e), null;
100
241
  }
101
242
  if (this._processEventResponse(t)) return;
102
243
  let { command: n, message: r, data: i, status: a, requestId: o } = t;
103
244
  if (o && this.callbacks[o]) {
104
- let { resolve: e, reject: t, timeoutId: s } = this.callbacks[o];
105
- clearTimeout(s), delete this.callbacks[o], e({
245
+ let { resolve: e, timeoutId: t } = this.callbacks[o];
246
+ clearTimeout(t), delete this.callbacks[o], e({
106
247
  command: n,
107
248
  message: r,
108
249
  data: i,
@@ -650,7 +791,7 @@ function config(e) {
650
791
  value: e.fov,
651
792
  defaultValue: 90,
652
793
  min: 1,
653
- max: 179
794
+ max: 180
654
795
  })), {
655
796
  errors: t,
656
797
  normalized: n
@@ -663,8 +804,8 @@ function flyTo(e) {
663
804
  field: "pitch",
664
805
  value: e.pitch,
665
806
  defaultValue: 0,
666
- min: -90,
667
- max: 90
807
+ min: -180,
808
+ max: 180
668
809
  })), t.push(...validateOptionalNumber({
669
810
  normalized: n,
670
811
  field: "yaw",
@@ -694,8 +835,8 @@ function focusToID(e) {
694
835
  normalized: n,
695
836
  field: "pitch",
696
837
  value: e.pitch,
697
- min: -90,
698
- max: 90
838
+ min: -180,
839
+ max: 180
699
840
  })), t.push(...validateOptionalNumber({
700
841
  normalized: n,
701
842
  field: "yaw",
@@ -728,8 +869,8 @@ function focusToPoint(e) {
728
869
  field: "pitch",
729
870
  value: e.pitch,
730
871
  defaultValue: 0,
731
- min: -90,
732
- max: 90
872
+ min: -180,
873
+ max: 180
733
874
  })), t.push(...validateOptionalNumber({
734
875
  normalized: n,
735
876
  field: "yaw",
@@ -801,8 +942,8 @@ function aroundMode(e = {}) {
801
942
  field: "pitch",
802
943
  value: e.pitch,
803
944
  defaultValue: 0,
804
- min: -90,
805
- max: 90
945
+ min: -180,
946
+ max: 180
806
947
  })), t.push(...validateOptionalNumber({
807
948
  normalized: n,
808
949
  field: "yaw",
@@ -876,8 +1017,8 @@ function firstPersonMode(e = {}) {
876
1017
  field: "pitch",
877
1018
  value: e.pitch,
878
1019
  defaultValue: 0,
879
- min: -90,
880
- max: 90
1020
+ min: -180,
1021
+ max: 180
881
1022
  })), t.push(...validateOptionalNumber({
882
1023
  normalized: n,
883
1024
  field: "yaw",
@@ -902,6 +1043,13 @@ function firstPersonMode(e = {}) {
902
1043
  normalized: n
903
1044
  };
904
1045
  }
1046
+ function viewLock(e = {}) {
1047
+ let t = [], n = { ...e };
1048
+ return validateOptionalBoolean(n, "state", e.state, t, !1), {
1049
+ errors: t,
1050
+ normalized: n
1051
+ };
1052
+ }
905
1053
  //#endregion
906
1054
  //#region ../api/camera/cameraApi.js
907
1055
  var validator$10 = {
@@ -913,7 +1061,8 @@ var validator$10 = {
913
1061
  config,
914
1062
  aroundMode,
915
1063
  dragMode,
916
- firstPersonMode
1064
+ firstPersonMode,
1065
+ viewLock
917
1066
  }, CameraAPI = class {
918
1067
  constructor(e) {
919
1068
  this.commandManager = e;
@@ -1388,7 +1537,9 @@ function validateCaptureConfig(e, t) {
1388
1537
  normalized: e,
1389
1538
  field: "pitch",
1390
1539
  value: e.pitch,
1391
- defaultValue: 0
1540
+ defaultValue: 0,
1541
+ min: -180,
1542
+ max: 180
1392
1543
  })), t.push(...validateOptionalNumber({
1393
1544
  normalized: e,
1394
1545
  field: "yaw",
@@ -1803,6 +1954,11 @@ function record(e) {
1803
1954
  "default4",
1804
1955
  "flashIcon"
1805
1956
  ]
1957
+ })), t.push(...validateOptionalNumber({
1958
+ normalized: n,
1959
+ field: "duration",
1960
+ value: e.duration,
1961
+ min: 0
1806
1962
  }));
1807
1963
  let r = n.materialType || e.materialType || "default";
1808
1964
  return validateConfig(n.config, t, r), {
@@ -1823,15 +1979,21 @@ function cameraFollow(e) {
1823
1979
  "x",
1824
1980
  "y",
1825
1981
  "z",
1826
- "yaw",
1827
- "pitch"
1982
+ "yaw"
1828
1983
  ]) t.push(...validateOptionalNumber({
1829
1984
  normalized: n,
1830
1985
  field: r,
1831
1986
  value: e[r],
1832
1987
  defaultValue: 0
1833
1988
  }));
1834
- return {
1989
+ return t.push(...validateOptionalNumber({
1990
+ normalized: n,
1991
+ field: "pitch",
1992
+ value: e.pitch,
1993
+ defaultValue: 0,
1994
+ min: -180,
1995
+ max: 180
1996
+ })), {
1835
1997
  errors: t,
1836
1998
  normalized: n
1837
1999
  };
@@ -2457,13 +2619,20 @@ function outline(e) {
2457
2619
  normalized: n.config,
2458
2620
  field: "meshColor",
2459
2621
  value: n.config.meshColor,
2460
- defaultValue: "#00001AFF"
2622
+ defaultValue: "#000305FF"
2461
2623
  })), t.push(...validateOptionalNumber({
2462
2624
  normalized: n.config,
2463
2625
  field: "meshBrightness",
2464
2626
  value: n.config.meshBrightness,
2465
2627
  defaultValue: 1,
2466
2628
  min: 0
2629
+ })), t.push(...validateOptionalNumber({
2630
+ normalized: n.config,
2631
+ field: "meshBrightness",
2632
+ value: n.config.meshOpacity,
2633
+ defaultValue: .02,
2634
+ min: 0,
2635
+ max: 1
2467
2636
  })), {
2468
2637
  errors: t,
2469
2638
  normalized: n
@@ -2677,6 +2846,13 @@ function addLine(e) {
2677
2846
  field: "spacing",
2678
2847
  value: e.spacing,
2679
2848
  min: 0
2849
+ })), t.push(...verifyEnumerationValue({
2850
+ normalized: n,
2851
+ field: "interpolate",
2852
+ value: e.interpolate,
2853
+ defaultValue: "smooth",
2854
+ type: "string",
2855
+ list: ["smooth", "linear"]
2680
2856
  })), t.push(...validateOptionalString({
2681
2857
  normalized: n,
2682
2858
  field: "startImg",
@@ -23480,7 +23656,38 @@ var validator = {
23480
23656
  }(), __webpack_exports__ = __webpack_exports__.default, __webpack_exports__;
23481
23657
  }();
23482
23658
  }));
23483
- })), import_larksr_web_sdk_min = require_larksr_web_sdk_min(), LoadStream = class {
23659
+ })), import_larksr_web_sdk_min = require_larksr_web_sdk_min();
23660
+ function createLarkSRTransport(e) {
23661
+ return {
23662
+ sendTextToDataChannel(t) {
23663
+ e.sendTextToDataChannel(t);
23664
+ },
23665
+ bindMessageHandler(t) {
23666
+ e.on("datachanneltext", (e) => {
23667
+ e?.type === "datachanneltext" && typeof e.data == "string" && t(e.data);
23668
+ });
23669
+ }
23670
+ };
23671
+ }
23672
+ function createZsStreamTransport(e) {
23673
+ return {
23674
+ sendTextToDataChannel(t) {
23675
+ e.sendTextToDataChannel(t);
23676
+ },
23677
+ bindMessageHandler(t) {
23678
+ e.on("message", (e) => {
23679
+ if (typeof e == "string") {
23680
+ t(e);
23681
+ return;
23682
+ }
23683
+ e != null && t(JSON.stringify(e));
23684
+ });
23685
+ }
23686
+ };
23687
+ }
23688
+ //#endregion
23689
+ //#region linkFlowLarkSR.js
23690
+ var LoadStream = class {
23484
23691
  constructor() {
23485
23692
  this._gameApi = null, this._larksr = null;
23486
23693
  }
@@ -23541,7 +23748,7 @@ var validator = {
23541
23748
  }
23542
23749
  init(e) {
23543
23750
  try {
23544
- let t = new CommandManager(e);
23751
+ let t = new CommandManager(createLarkSRTransport(e));
23545
23752
  return this._gameApi = new GameAPI(t), console.log("插件初始化成功"), this._gameApi;
23546
23753
  } catch (e) {
23547
23754
  throw console.error("插件初始化失败", e), e;
@@ -23558,7 +23765,29 @@ var validator = {
23558
23765
  getLarkSR() {
23559
23766
  return this._larksr;
23560
23767
  }
23561
- }, loadStream = new LoadStream(), createAndInitLarkSR = loadStream.constructor.createAndInitLarkSR;
23768
+ }, loadStream = new LoadStream(), activeStream = null;
23769
+ async function ZsStreamMount(e, t = {}) {
23770
+ if (!globalThis.ZsStream?.mount) throw Error("ZsStream 未加载,请确认已引入 zs-stream-parent.js");
23771
+ ZsStreamDestroy(), setUELogEnabled(e?.UELogLevel ?? !0);
23772
+ let n = globalThis.ZsStream.mount(e);
23773
+ activeStream = n, t.onInputready && n.on("inputready", t.onInputready), t.onPlatform && n.on("platform", t.onPlatform), t.onQueue && n.on("queue", t.onQueue), n.on("message", (e) => {
23774
+ if (t.onSceneInit && typeof e == "string") try {
23775
+ let n = JSON.parse(e.trim());
23776
+ n?.message === "The level has been initialized" && t.onSceneInit(n);
23777
+ } catch {}
23778
+ t.onMessage && t.onMessage(e);
23779
+ }), t.onError && n.on("error", t.onError);
23780
+ let r = new GameAPI(new CommandManager(createZsStreamTransport(n)));
23781
+ return r.destroy = () => {
23782
+ n.destroy(), activeStream === n && (activeStream = null);
23783
+ }, r;
23784
+ }
23785
+ function ZsStreamDestroy() {
23786
+ activeStream &&= (activeStream.destroy(), null);
23787
+ }
23788
+ //#endregion
23789
+ //#region index.js
23790
+ var createAndInitLarkSR = loadStream.constructor.createAndInitLarkSR;
23562
23791
  function closeGameApi() {
23563
23792
  return loadStream.close();
23564
23793
  }
@@ -23567,6 +23796,6 @@ function getLarkSR() {
23567
23796
  }
23568
23797
  var web3dlink_default = loadStream;
23569
23798
  //#endregion
23570
- export { closeGameApi, createAndInitLarkSR, web3dlink_default as default, getLarkSR };
23799
+ export { CommandManager, GameAPI, ZsStreamDestroy, ZsStreamMount, closeGameApi, createAndInitLarkSR, createLarkSRTransport, createZsStreamTransport, web3dlink_default as default, getLarkSR };
23571
23800
 
23572
23801
  //# sourceMappingURL=web3dlink.js.map