web3dlink 2.1.16 → 2.1.18

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.
@@ -0,0 +1,195 @@
1
+ import { a as e, n as t, o as n, s as r, t as i } from "./createGameSession-DkD790Ci.js";
2
+ //#region linkFlowzsStream.js
3
+ (function(e) {
4
+ let t = "zs-stream-parent", n = "zs-stream-embed";
5
+ function r(e) {
6
+ return e ? typeof e == "string" ? document.querySelector(e) : e : null;
7
+ }
8
+ function i(e, t, n) {
9
+ let r = (e || "").replace(/\/+$/, "") || (typeof location < "u" ? location.origin : ""), i = new URLSearchParams({
10
+ template: t || "default",
11
+ autoconnect: "1",
12
+ muted: "1"
13
+ });
14
+ return n && i.set("streamId", n), `${r}/embed?${i.toString()}`;
15
+ }
16
+ function a(e, n, r) {
17
+ return e?.contentWindow ? (e.contentWindow.postMessage({
18
+ source: t,
19
+ streamId: n,
20
+ ...r
21
+ }, "*"), { ok: !0 }) : {
22
+ ok: !1,
23
+ error: "iframe 未就绪"
24
+ };
25
+ }
26
+ class o {
27
+ constructor({ streamId: t, template: n, container: i, baseUrl: a } = {}) {
28
+ if (!t) throw Error("ZsStream: streamId 必填(同页多路时用于区分)");
29
+ 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();
30
+ }
31
+ _mountIframe() {
32
+ if (!this.container) throw Error("ZsStream: container 未找到");
33
+ let e = document.createElement("iframe");
34
+ 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;
35
+ }
36
+ _onMessage(e) {
37
+ let t = e.data;
38
+ if (!t || t.source !== n || t.streamId && t.streamId !== this.streamId || t.type !== "event") return;
39
+ let r = t.event;
40
+ r === "ready" && (this._ready = !0), r === "inputready" && (this._inputReady = !0), this._emit(r, t.data);
41
+ }
42
+ _emit(e, t) {
43
+ let n = this._handlers.get(e);
44
+ if (n) for (let e of n) try {
45
+ e(t);
46
+ } catch (e) {
47
+ console.error("[ZsStream]", e);
48
+ }
49
+ }
50
+ on(e, t) {
51
+ return this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(t), () => this.off(e, t);
52
+ }
53
+ off(e, t) {
54
+ this._handlers.get(e)?.delete(t);
55
+ }
56
+ _send(e, t) {
57
+ return a(this.iframe, this.streamId, {
58
+ type: e,
59
+ ...t
60
+ });
61
+ }
62
+ invoke(e, t, n) {
63
+ return this._send("invoke", {
64
+ module: e,
65
+ action: t,
66
+ params: n ?? {}
67
+ });
68
+ }
69
+ camera(e, t) {
70
+ return this._send("camera", {
71
+ action: e,
72
+ params: t ?? {}
73
+ });
74
+ }
75
+ sendRaw(e) {
76
+ return this._send("sendRaw", { descriptor: String(e) });
77
+ }
78
+ sendCommand(e, t) {
79
+ return this._send("larkCommand", {
80
+ command: e,
81
+ params: t ?? {}
82
+ });
83
+ }
84
+ sendTextToDataChannel(e) {
85
+ let t = typeof e == "string" ? e : JSON.stringify({
86
+ command: e.command,
87
+ params: e.params ?? {}
88
+ });
89
+ return this._send("sendRaw", { descriptor: t });
90
+ }
91
+ disconnect() {
92
+ return this._send("disconnect", {});
93
+ }
94
+ destroy() {
95
+ e.removeEventListener("message", this._onMessage), this.disconnect(), this.iframe?.parentNode && this.iframe.parentNode.removeChild(this.iframe), this.iframe = null, this._handlers.clear();
96
+ }
97
+ get isReady() {
98
+ return this._ready;
99
+ }
100
+ get isInputReady() {
101
+ return this._inputReady;
102
+ }
103
+ }
104
+ class s {
105
+ constructor() {
106
+ this._streams = /* @__PURE__ */ new Map();
107
+ }
108
+ mount(e) {
109
+ let t = e?.streamId;
110
+ if (!t) throw Error("ZsStreamHub.mount: streamId 必填");
111
+ this._streams.has(t) && this._streams.get(t).destroy();
112
+ let n = new o(e);
113
+ return this._streams.set(t, n), n;
114
+ }
115
+ get(e) {
116
+ return this._streams.get(e) || null;
117
+ }
118
+ has(e) {
119
+ return this._streams.has(e);
120
+ }
121
+ destroy(e) {
122
+ let t = this._streams.get(e);
123
+ t && (t.destroy(), this._streams.delete(e));
124
+ }
125
+ destroyAll() {
126
+ for (let e of [...this._streams.keys()]) this.destroy(e);
127
+ }
128
+ list() {
129
+ return [...this._streams.keys()];
130
+ }
131
+ }
132
+ e.ZsStream = {
133
+ mount(e) {
134
+ return new o(e);
135
+ },
136
+ Hub: s,
137
+ buildEmbedSrc: i,
138
+ MSG_SOURCE_PARENT: t,
139
+ MSG_SOURCE_EMBED: n
140
+ }, e.ZsStreamHub = s;
141
+ })(typeof window < "u" ? window : globalThis);
142
+ var a = null, o = null, s = [];
143
+ function c(e) {
144
+ if (typeof e == "string") return e;
145
+ if (e == null) return null;
146
+ try {
147
+ return JSON.stringify(e);
148
+ } catch {
149
+ return null;
150
+ }
151
+ }
152
+ function l(e) {
153
+ if (typeof e != "string") return e;
154
+ try {
155
+ return JSON.parse(e.trim());
156
+ } catch {
157
+ return e;
158
+ }
159
+ }
160
+ function u(e, t, n) {
161
+ n && (e.on(t, n), s.push({
162
+ target: e,
163
+ event: t,
164
+ handler: n
165
+ }));
166
+ }
167
+ async function d(e, t = {}) {
168
+ if (!globalThis.ZsStream?.mount) throw Error("ZsStream 未加载,请确认已引入 zs-stream-parent.js");
169
+ await f(), r(e?.UELogLevel ?? !0);
170
+ let n = globalThis.ZsStream.mount(e);
171
+ a = n, u(n, "inputready", t.onInputready), u(n, "platform", t.onPlatform), u(n, "queue", t.onQueue), u(n, "error", t.onError);
172
+ let s = t.onSceneInit || t.onSceneInitialized, d = i({
173
+ sendText: (e) => n.sendTextToDataChannel(e),
174
+ commandTimeout: t.commandTimeout ?? 3e3,
175
+ onSceneInit: s ? (e) => s(l(e)) : void 0
176
+ });
177
+ o = d, u(n, "message", (e) => {
178
+ let n = c(e);
179
+ d.handleIncoming(n, e), t.onMessage && t.onMessage(e);
180
+ });
181
+ let p = d.gameAPI;
182
+ return p.destroy = () => f(), p;
183
+ }
184
+ async function f() {
185
+ if (t(s), s = [], o?.destroy(), o = null, a && typeof a.destroy == "function") try {
186
+ await a.destroy(), e("连接关闭成功");
187
+ } catch (e) {
188
+ n("连接关闭失败:", e);
189
+ }
190
+ a = null;
191
+ }
192
+ //#endregion
193
+ export { d as n, f as t };
194
+
195
+ //# sourceMappingURL=linkFlowzsStream-BPCKLTn_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linkFlowzsStream-BPCKLTn_.js","names":[],"sources":["../linkFlowzsStream.js"],"sourcesContent":["import './zs-stream-parent.js';\nimport { log, logError, setUELogEnabled } from './baseConfig/logger.js';\nimport { createGameSession, unbindAll } from './createGameSession.js';\n\nlet activeStream = null;\nlet activeSession = null;\nlet activeBindings = [];\n\nfunction toRawText(payload) {\n if (typeof payload === 'string') return payload;\n if (payload === undefined || payload === null) return null;\n try {\n return JSON.stringify(payload);\n } catch (_) {\n return null;\n }\n}\n\nfunction parseSceneInitPayload(payload) {\n if (typeof payload !== 'string') return payload;\n try {\n return JSON.parse(payload.trim());\n } catch (_) {\n return payload;\n }\n}\n\nfunction bind(target, event, handler) {\n if (!handler) return;\n target.on(event, handler);\n activeBindings.push({ target, event, handler });\n}\n\n/**\n * 挂载 ZS 推流并返回带校验的 gameAPI\n * @param {Object} config 透传给 ZsStream.mount(UELogLevel 为插件内部参数)\n * @param {Object} callbacks onInputready / onMessage / onError / onSceneInit / onPlatform / onQueue\n */\nexport async function ZsStreamMount(config, callbacks = {}) {\n if (!globalThis.ZsStream?.mount) {\n throw new Error('ZsStream 未加载,请确认已引入 zs-stream-parent.js');\n }\n\n await ZsStreamDestroy();\n\n setUELogEnabled(config?.UELogLevel ?? true);\n\n const stream = globalThis.ZsStream.mount(config);\n activeStream = stream;\n\n bind(stream, 'inputready', callbacks.onInputready);\n bind(stream, 'platform', callbacks.onPlatform);\n bind(stream, 'queue', callbacks.onQueue);\n bind(stream, 'error', callbacks.onError);\n\n // 对外正式回调名:onSceneInit(兼容 onSceneInitialized)\n const onSceneInit = callbacks.onSceneInit || callbacks.onSceneInitialized;\n const session = createGameSession({\n sendText: (text) => stream.sendTextToDataChannel(text),\n commandTimeout: callbacks.commandTimeout ?? 3000,\n onSceneInit: onSceneInit\n ? (payload) => onSceneInit(parseSceneInitPayload(payload))\n : undefined\n });\n activeSession = session;\n\n const onMessage = (payload) => {\n const raw = toRawText(payload);\n session.handleIncoming(raw, payload);\n if (callbacks.onMessage) {\n callbacks.onMessage(payload);\n }\n };\n bind(stream, 'message', onMessage);\n\n const gameAPI = session.gameAPI;\n gameAPI.destroy = () => ZsStreamDestroy();\n return gameAPI;\n}\n\n/**\n * 销毁当前 ZS 推流并清理资源\n */\nexport async function ZsStreamDestroy() {\n unbindAll(activeBindings);\n activeBindings = [];\n\n activeSession?.destroy();\n activeSession = null;\n\n if (activeStream && typeof activeStream.destroy === 'function') {\n try {\n await activeStream.destroy();\n log('连接关闭成功');\n } catch (error) {\n logError('连接关闭失败:', error);\n }\n }\n\n activeStream = null;\n}\n"],"mappings":";;CAKA,SAAI,GAAgB;CACpB,IAAI,IAAmB;CAGrB,SAAM,EAAO,GAAa;EAGxB,OAFI,IACA,OAAA,KAAA,WAAA,SAAA,cAAA,CAAA,IACA,IAFY;CAGlB;CAEA,SAAE,EAAA,GAAA,GAAA,GAAA;WACJ,KAAA,IAAA,QAAA,QAAA,EAAA,MAAA,OAAA,WAAA,MAAA,SAAA,SAAA,KAES,IAAA,IAAA,gBAAsB;GACzB,UAAS,KAAa;GACxB,aAAI;GACF,OAAE;EACJ,CAAC;EAED,OADI,KAAO,EAAA,IAAO,YAAA,CAAA,GAClB,GAAA,EAAA,SAAA,EAAA,SAAA;CACJ;CAEA,SAAS,EAAa,GAAO,GAAS,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,KAAA,KAAA,UAAA,IAAA,mBAAA,IAAA,IAAA,CAAA,GACxB,KAAA,UAAgB,IAAI,CAAA,EAAA,IAAA,CAAA;EAEpB;EAEA,IAAI,GAAI,GAAM;GACZ,KAAK,UAAM,IAAQ,CAAA,GAAA,OAAA,CAAA;EACrB;EAEA,MAAI,GAAA,GAAA;GACJ,OAAA,EAAA,KAAA,QAAA,KAAA,UAAA;IAAA;IAAA,GAAA;GAAA,CAAA;;EAGJ,OAAA,GAAA,GAAA,GAAA"}
@@ -0,0 +1,3 @@
1
+ import { n as e, r as t, t as n } from "./linkFlowLarkSR-D4p33n9x.js";
2
+ import { c as r, i, r as a } from "./createGameSession-DkD790Ci.js";
3
+ export { a as CommandManager, i as GameAPI, n as closeGameApi, e as createAndInitLarkSR, t as getLarkSR, r as version };
@@ -0,0 +1,3 @@
1
+ import { c as e, i as t, r as n } from "./createGameSession-DkD790Ci.js";
2
+ import { n as r, t as i } from "./linkFlowzsStream-BPCKLTn_.js";
3
+ export { n as CommandManager, t as GameAPI, i as ZsStreamDestroy, r as ZsStreamMount, e as version };
@@ -0,0 +1,91 @@
1
+ /**
2
+ * web3dlink 对外类型声明
3
+ *
4
+ * GameAPI 方法名由 scripts/sync-dts.mjs 根据 api/index.js 同步;发版跑 npm run build 即可。
5
+ */
6
+
7
+ export declare const version: string;
8
+
9
+ export interface CommandResult {
10
+ success: boolean;
11
+ message: string | string[];
12
+ data?: unknown;
13
+ params?: unknown;
14
+ command?: string;
15
+ }
16
+
17
+ export interface Transport {
18
+ sendTextToDataChannel(text: string): void;
19
+ bindMessageHandler(handler: (raw: string) => void): void;
20
+ }
21
+
22
+ export declare class CommandManager {
23
+ constructor(transport: Transport, options?: { timeout?: number });
24
+ destroy(): void;
25
+ sendWithDefault(
26
+ result: { errors: string[]; normalized?: object },
27
+ command: string,
28
+ options?: { timeout?: number }
29
+ ): Promise<CommandResult> | CommandResult;
30
+ }
31
+
32
+ export declare class GameAPI {
33
+ constructor(commandManager: CommandManager);
34
+
35
+ camera(api: string, params?: object): Promise<CommandResult> | CommandResult;
36
+ cesium(api: string, params?: object): Promise<CommandResult> | CommandResult;
37
+ marker(api: string, params?: object): Promise<CommandResult> | CommandResult;
38
+ floodPeak(api: string, params?: object): Promise<CommandResult> | CommandResult;
39
+ animation(api: string, params?: object): Promise<CommandResult> | CommandResult;
40
+ hydrodynamicForce(api: string, params?: object): Promise<CommandResult> | CommandResult;
41
+ sceneModel(api: string, params?: object): Promise<CommandResult> | CommandResult;
42
+ atmosphericEffects(api: string, params?: object): Promise<CommandResult> | CommandResult;
43
+ tool(api: string, params?: object): Promise<CommandResult> | CommandResult;
44
+ line(api: string, params?: object): Promise<CommandResult> | CommandResult;
45
+ level(api: string, params?: object): Promise<CommandResult> | CommandResult;
46
+ VTK(api: string, params?: object): Promise<CommandResult> | CommandResult;
47
+
48
+ oneDimensionalHydrodynamics(api: string, params?: object, options?: { timeout?: number }): Promise<CommandResult> | CommandResult;
49
+ customDomain(api: string, params?: object, options?: { timeout?: number }): Promise<CommandResult> | CommandResult;
50
+ arrow(api: string, params?: object, options?: { timeout?: number }): Promise<CommandResult> | CommandResult;
51
+ NC(api: string, params?: object, options?: { timeout?: number }): Promise<CommandResult> | CommandResult;
52
+ gateOperation(api: string, params?: object, options?: { timeout?: number }): Promise<CommandResult> | CommandResult;
53
+ }
54
+
55
+ export interface LarkSRCallbacks {
56
+ onConnected?: (larksr: unknown) => void;
57
+ onError?: (e: unknown) => void;
58
+ onInfo?: (e: unknown) => void;
59
+ onDataChannelOpen?: (e: unknown) => void;
60
+ onDatachanneltext?: (e: unknown) => void;
61
+ /** 场景初始化完成 */
62
+ onSceneInitialized?: (e: unknown) => void;
63
+ commandTimeout?: number;
64
+ [key: string]: unknown;
65
+ }
66
+
67
+ export declare function createAndInitLarkSR(
68
+ config: object,
69
+ callbacks?: LarkSRCallbacks
70
+ ): Promise<GameAPI>;
71
+
72
+ export declare function closeGameApi(): Promise<void>;
73
+ export declare function getLarkSR(): unknown;
74
+
75
+ export interface ZsStreamCallbacks {
76
+ onInputready?: (e: unknown) => void;
77
+ onMessage?: (e: unknown) => void;
78
+ onError?: (e: unknown) => void;
79
+ /** 场景初始化完成 */
80
+ onSceneInit?: (e: unknown) => void;
81
+ onPlatform?: (e: unknown) => void;
82
+ onQueue?: (e: unknown) => void;
83
+ commandTimeout?: number;
84
+ }
85
+
86
+ export declare function ZsStreamMount(
87
+ config: object,
88
+ callbacks?: ZsStreamCallbacks
89
+ ): Promise<GameAPI & { destroy: () => Promise<void> }>;
90
+
91
+ export declare function ZsStreamDestroy(): Promise<void>;