web3dlink 2.0.17 → 2.1.0

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,
@@ -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: 0
668
809
  })), t.push(...validateOptionalNumber({
669
810
  normalized: n,
670
811
  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;
@@ -1803,6 +1952,11 @@ function record(e) {
1803
1952
  "default4",
1804
1953
  "flashIcon"
1805
1954
  ]
1955
+ })), t.push(...validateOptionalNumber({
1956
+ normalized: n,
1957
+ field: "duration",
1958
+ value: e.duration,
1959
+ min: 0
1806
1960
  }));
1807
1961
  let r = n.materialType || e.materialType || "default";
1808
1962
  return validateConfig(n.config, t, r), {
@@ -2457,13 +2611,20 @@ function outline(e) {
2457
2611
  normalized: n.config,
2458
2612
  field: "meshColor",
2459
2613
  value: n.config.meshColor,
2460
- defaultValue: "#00001AFF"
2614
+ defaultValue: "#000305FF"
2461
2615
  })), t.push(...validateOptionalNumber({
2462
2616
  normalized: n.config,
2463
2617
  field: "meshBrightness",
2464
2618
  value: n.config.meshBrightness,
2465
2619
  defaultValue: 1,
2466
2620
  min: 0
2621
+ })), t.push(...validateOptionalNumber({
2622
+ normalized: n.config,
2623
+ field: "meshBrightness",
2624
+ value: n.config.meshOpacity,
2625
+ defaultValue: .02,
2626
+ min: 0,
2627
+ max: 1
2467
2628
  })), {
2468
2629
  errors: t,
2469
2630
  normalized: n
@@ -2677,6 +2838,13 @@ function addLine(e) {
2677
2838
  field: "spacing",
2678
2839
  value: e.spacing,
2679
2840
  min: 0
2841
+ })), t.push(...verifyEnumerationValue({
2842
+ normalized: n,
2843
+ field: "interpolate",
2844
+ value: e.interpolate,
2845
+ defaultValue: "smooth",
2846
+ type: "string",
2847
+ list: ["smooth", "linear"]
2680
2848
  })), t.push(...validateOptionalString({
2681
2849
  normalized: n,
2682
2850
  field: "startImg",
@@ -23480,7 +23648,38 @@ var validator = {
23480
23648
  }(), __webpack_exports__ = __webpack_exports__.default, __webpack_exports__;
23481
23649
  }();
23482
23650
  }));
23483
- })), import_larksr_web_sdk_min = require_larksr_web_sdk_min(), LoadStream = class {
23651
+ })), import_larksr_web_sdk_min = require_larksr_web_sdk_min();
23652
+ function createLarkSRTransport(e) {
23653
+ return {
23654
+ sendTextToDataChannel(t) {
23655
+ e.sendTextToDataChannel(t);
23656
+ },
23657
+ bindMessageHandler(t) {
23658
+ e.on("datachanneltext", (e) => {
23659
+ e?.type === "datachanneltext" && typeof e.data == "string" && t(e.data);
23660
+ });
23661
+ }
23662
+ };
23663
+ }
23664
+ function createZsStreamTransport(e) {
23665
+ return {
23666
+ sendTextToDataChannel(t) {
23667
+ e.sendTextToDataChannel(t);
23668
+ },
23669
+ bindMessageHandler(t) {
23670
+ e.on("message", (e) => {
23671
+ if (typeof e == "string") {
23672
+ t(e);
23673
+ return;
23674
+ }
23675
+ e != null && t(JSON.stringify(e));
23676
+ });
23677
+ }
23678
+ };
23679
+ }
23680
+ //#endregion
23681
+ //#region linkFlowLarkSR.js
23682
+ var LoadStream = class {
23484
23683
  constructor() {
23485
23684
  this._gameApi = null, this._larksr = null;
23486
23685
  }
@@ -23541,7 +23740,7 @@ var validator = {
23541
23740
  }
23542
23741
  init(e) {
23543
23742
  try {
23544
- let t = new CommandManager(e);
23743
+ let t = new CommandManager(createLarkSRTransport(e));
23545
23744
  return this._gameApi = new GameAPI(t), console.log("插件初始化成功"), this._gameApi;
23546
23745
  } catch (e) {
23547
23746
  throw console.error("插件初始化失败", e), e;
@@ -23558,7 +23757,29 @@ var validator = {
23558
23757
  getLarkSR() {
23559
23758
  return this._larksr;
23560
23759
  }
23561
- }, loadStream = new LoadStream(), createAndInitLarkSR = loadStream.constructor.createAndInitLarkSR;
23760
+ }, loadStream = new LoadStream(), activeStream = null;
23761
+ async function ZsStreamMount(e, t = {}) {
23762
+ if (!globalThis.ZsStream?.mount) throw Error("ZsStream 未加载,请确认已引入 zs-stream-parent.js");
23763
+ ZsStreamDestroy(), setUELogEnabled(e?.UELogLevel ?? !0);
23764
+ let n = globalThis.ZsStream.mount(e);
23765
+ 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) => {
23766
+ if (t.onSceneInit && typeof e == "string") try {
23767
+ let n = JSON.parse(e.trim());
23768
+ n?.message === "The level has been initialized" && t.onSceneInit(n);
23769
+ } catch {}
23770
+ t.onMessage && t.onMessage(e);
23771
+ }), t.onError && n.on("error", t.onError);
23772
+ let r = new GameAPI(new CommandManager(createZsStreamTransport(n)));
23773
+ return r.destroy = () => {
23774
+ n.destroy(), activeStream === n && (activeStream = null);
23775
+ }, r;
23776
+ }
23777
+ function ZsStreamDestroy() {
23778
+ activeStream &&= (activeStream.destroy(), null);
23779
+ }
23780
+ //#endregion
23781
+ //#region index.js
23782
+ var createAndInitLarkSR = loadStream.constructor.createAndInitLarkSR;
23562
23783
  function closeGameApi() {
23563
23784
  return loadStream.close();
23564
23785
  }
@@ -23567,6 +23788,6 @@ function getLarkSR() {
23567
23788
  }
23568
23789
  var web3dlink_default = loadStream;
23569
23790
  //#endregion
23570
- export { closeGameApi, createAndInitLarkSR, web3dlink_default as default, getLarkSR };
23791
+ export { CommandManager, GameAPI, ZsStreamDestroy, ZsStreamMount, closeGameApi, createAndInitLarkSR, createLarkSRTransport, createZsStreamTransport, web3dlink_default as default, getLarkSR };
23571
23792
 
23572
23793
  //# sourceMappingURL=web3dlink.js.map