@react-devtools-plus/core 0.2.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.
@@ -0,0 +1,124 @@
1
+ import { d as ClientFunctions, e as ServerFunctions } from '../types-BU_SaMGj.cjs';
2
+
3
+ /**
4
+ * RPC types for React DevTools
5
+ * React DevTools RPC 类型定义
6
+ */
7
+
8
+ /**
9
+ * RPC channel interface
10
+ * RPC 通道接口
11
+ */
12
+ interface RPCChannel {
13
+ /**
14
+ * Send message
15
+ * 发送消息
16
+ */
17
+ send: (message: any) => void;
18
+ /**
19
+ * Receive message handler
20
+ * 接收消息处理器
21
+ */
22
+ onMessage: (handler: (message: any) => void) => () => void;
23
+ /**
24
+ * Close channel
25
+ * 关闭通道
26
+ */
27
+ close?: () => void;
28
+ }
29
+ /**
30
+ * RPC options
31
+ * RPC 选项
32
+ */
33
+ interface RPCOptions {
34
+ /**
35
+ * Timeout for RPC calls (ms)
36
+ * RPC 调用超时时间(毫秒)
37
+ * @default 30000
38
+ */
39
+ timeout?: number;
40
+ /**
41
+ * Enable logging
42
+ * 启用日志
43
+ * @default false
44
+ */
45
+ logging?: boolean;
46
+ }
47
+ /**
48
+ * RPC connection state
49
+ * RPC 连接状态
50
+ */
51
+ type RPCConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
52
+ /**
53
+ * RPC connection info
54
+ * RPC 连接信息
55
+ */
56
+ interface RPCConnectionInfo {
57
+ state: RPCConnectionState;
58
+ error?: Error;
59
+ connectedAt?: number;
60
+ }
61
+ /**
62
+ * Client RPC instance type
63
+ * 客户端 RPC 实例类型
64
+ */
65
+ interface ClientRPC extends ClientFunctions {
66
+ $functions: ClientFunctions;
67
+ $channel: RPCChannel;
68
+ $state: RPCConnectionInfo;
69
+ $close: () => void;
70
+ }
71
+ /**
72
+ * Server RPC instance type
73
+ * 服务端 RPC 实例类型
74
+ */
75
+ interface ServerRPC extends ServerFunctions {
76
+ $functions: ServerFunctions;
77
+ $channel: RPCChannel;
78
+ $state: RPCConnectionInfo;
79
+ $close: () => void;
80
+ }
81
+
82
+ /**
83
+ * RPC channels for different communication methods
84
+ * 不同通信方式的 RPC 通道
85
+ */
86
+
87
+ /**
88
+ * Create a BroadcastChannel-based RPC channel
89
+ * 创建基于 BroadcastChannel 的 RPC 通道
90
+ */
91
+ declare function createBroadcastChannel(channelName: string): RPCChannel;
92
+ /**
93
+ * Create a PostMessage-based RPC channel (for iframe communication)
94
+ * 创建基于 PostMessage 的 RPC 通道(用于 iframe 通信)
95
+ */
96
+ declare function createPostMessageChannel(target: Window, origin?: string): RPCChannel;
97
+ /**
98
+ * Create a WebSocket-based RPC channel
99
+ * 创建基于 WebSocket 的 RPC 通道
100
+ */
101
+ declare function createWebSocketChannel(url: string): RPCChannel;
102
+ /**
103
+ * Create a custom event-based RPC channel (for in-page communication)
104
+ * 创建基于自定义事件的 RPC 通道(用于页面内通信)
105
+ */
106
+ declare function createCustomEventChannel(eventName: string): RPCChannel;
107
+
108
+ /**
109
+ * RPC system for React DevTools
110
+ * React DevTools RPC 系统
111
+ */
112
+
113
+ /**
114
+ * Create client RPC instance
115
+ * 创建客户端 RPC 实例
116
+ */
117
+ declare function createClientRPC(functions: ClientFunctions, channel: RPCChannel, options?: RPCOptions): ClientRPC;
118
+ /**
119
+ * Create server RPC instance
120
+ * 创建服务端 RPC 实例
121
+ */
122
+ declare function createServerRPC(functions: ServerFunctions, channel: RPCChannel, options?: RPCOptions): ServerRPC;
123
+
124
+ export { type ClientRPC, type RPCChannel, type RPCConnectionInfo, type RPCConnectionState, type RPCOptions, type ServerRPC, createBroadcastChannel, createClientRPC, createCustomEventChannel, createPostMessageChannel, createServerRPC, createWebSocketChannel };
@@ -0,0 +1,124 @@
1
+ import { d as ClientFunctions, e as ServerFunctions } from '../types-BU_SaMGj.js';
2
+
3
+ /**
4
+ * RPC types for React DevTools
5
+ * React DevTools RPC 类型定义
6
+ */
7
+
8
+ /**
9
+ * RPC channel interface
10
+ * RPC 通道接口
11
+ */
12
+ interface RPCChannel {
13
+ /**
14
+ * Send message
15
+ * 发送消息
16
+ */
17
+ send: (message: any) => void;
18
+ /**
19
+ * Receive message handler
20
+ * 接收消息处理器
21
+ */
22
+ onMessage: (handler: (message: any) => void) => () => void;
23
+ /**
24
+ * Close channel
25
+ * 关闭通道
26
+ */
27
+ close?: () => void;
28
+ }
29
+ /**
30
+ * RPC options
31
+ * RPC 选项
32
+ */
33
+ interface RPCOptions {
34
+ /**
35
+ * Timeout for RPC calls (ms)
36
+ * RPC 调用超时时间(毫秒)
37
+ * @default 30000
38
+ */
39
+ timeout?: number;
40
+ /**
41
+ * Enable logging
42
+ * 启用日志
43
+ * @default false
44
+ */
45
+ logging?: boolean;
46
+ }
47
+ /**
48
+ * RPC connection state
49
+ * RPC 连接状态
50
+ */
51
+ type RPCConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
52
+ /**
53
+ * RPC connection info
54
+ * RPC 连接信息
55
+ */
56
+ interface RPCConnectionInfo {
57
+ state: RPCConnectionState;
58
+ error?: Error;
59
+ connectedAt?: number;
60
+ }
61
+ /**
62
+ * Client RPC instance type
63
+ * 客户端 RPC 实例类型
64
+ */
65
+ interface ClientRPC extends ClientFunctions {
66
+ $functions: ClientFunctions;
67
+ $channel: RPCChannel;
68
+ $state: RPCConnectionInfo;
69
+ $close: () => void;
70
+ }
71
+ /**
72
+ * Server RPC instance type
73
+ * 服务端 RPC 实例类型
74
+ */
75
+ interface ServerRPC extends ServerFunctions {
76
+ $functions: ServerFunctions;
77
+ $channel: RPCChannel;
78
+ $state: RPCConnectionInfo;
79
+ $close: () => void;
80
+ }
81
+
82
+ /**
83
+ * RPC channels for different communication methods
84
+ * 不同通信方式的 RPC 通道
85
+ */
86
+
87
+ /**
88
+ * Create a BroadcastChannel-based RPC channel
89
+ * 创建基于 BroadcastChannel 的 RPC 通道
90
+ */
91
+ declare function createBroadcastChannel(channelName: string): RPCChannel;
92
+ /**
93
+ * Create a PostMessage-based RPC channel (for iframe communication)
94
+ * 创建基于 PostMessage 的 RPC 通道(用于 iframe 通信)
95
+ */
96
+ declare function createPostMessageChannel(target: Window, origin?: string): RPCChannel;
97
+ /**
98
+ * Create a WebSocket-based RPC channel
99
+ * 创建基于 WebSocket 的 RPC 通道
100
+ */
101
+ declare function createWebSocketChannel(url: string): RPCChannel;
102
+ /**
103
+ * Create a custom event-based RPC channel (for in-page communication)
104
+ * 创建基于自定义事件的 RPC 通道(用于页面内通信)
105
+ */
106
+ declare function createCustomEventChannel(eventName: string): RPCChannel;
107
+
108
+ /**
109
+ * RPC system for React DevTools
110
+ * React DevTools RPC 系统
111
+ */
112
+
113
+ /**
114
+ * Create client RPC instance
115
+ * 创建客户端 RPC 实例
116
+ */
117
+ declare function createClientRPC(functions: ClientFunctions, channel: RPCChannel, options?: RPCOptions): ClientRPC;
118
+ /**
119
+ * Create server RPC instance
120
+ * 创建服务端 RPC 实例
121
+ */
122
+ declare function createServerRPC(functions: ServerFunctions, channel: RPCChannel, options?: RPCOptions): ServerRPC;
123
+
124
+ export { type ClientRPC, type RPCChannel, type RPCConnectionInfo, type RPCConnectionState, type RPCOptions, type ServerRPC, createBroadcastChannel, createClientRPC, createCustomEventChannel, createPostMessageChannel, createServerRPC, createWebSocketChannel };
@@ -0,0 +1,277 @@
1
+ // ../../node_modules/.pnpm/birpc@0.2.19/node_modules/birpc/dist/index.mjs
2
+ var DEFAULT_TIMEOUT = 6e4;
3
+ function defaultSerialize(i) {
4
+ return i;
5
+ }
6
+ var defaultDeserialize = defaultSerialize;
7
+ var { clearTimeout, setTimeout } = globalThis;
8
+ var random = Math.random.bind(Math);
9
+ function createBirpc(functions, options) {
10
+ const {
11
+ post,
12
+ on,
13
+ off = () => {
14
+ },
15
+ eventNames = [],
16
+ serialize = defaultSerialize,
17
+ deserialize = defaultDeserialize,
18
+ resolver,
19
+ bind = "rpc",
20
+ timeout = DEFAULT_TIMEOUT
21
+ } = options;
22
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
23
+ let _promise;
24
+ let closed = false;
25
+ const rpc = new Proxy({}, {
26
+ get(_, method) {
27
+ if (method === "$functions")
28
+ return functions;
29
+ if (method === "$close")
30
+ return close;
31
+ if (method === "then" && !eventNames.includes("then") && !("then" in functions))
32
+ return void 0;
33
+ const sendEvent = (...args) => {
34
+ post(serialize({ m: method, a: args, t: "q" }));
35
+ };
36
+ if (eventNames.includes(method)) {
37
+ sendEvent.asEvent = sendEvent;
38
+ return sendEvent;
39
+ }
40
+ const sendCall = async (...args) => {
41
+ if (closed)
42
+ throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
43
+ if (_promise) {
44
+ try {
45
+ await _promise;
46
+ } finally {
47
+ _promise = void 0;
48
+ }
49
+ }
50
+ return new Promise((resolve, reject) => {
51
+ var _a;
52
+ const id = nanoid();
53
+ let timeoutId;
54
+ if (timeout >= 0) {
55
+ timeoutId = setTimeout(() => {
56
+ var _a2;
57
+ try {
58
+ (_a2 = options.onTimeoutError) == null ? void 0 : _a2.call(options, method, args);
59
+ throw new Error(`[birpc] timeout on calling "${method}"`);
60
+ } catch (e) {
61
+ reject(e);
62
+ }
63
+ rpcPromiseMap.delete(id);
64
+ }, timeout);
65
+ if (typeof timeoutId === "object")
66
+ timeoutId = (_a = timeoutId.unref) == null ? void 0 : _a.call(timeoutId);
67
+ }
68
+ rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
69
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
70
+ });
71
+ };
72
+ sendCall.asEvent = sendEvent;
73
+ return sendCall;
74
+ }
75
+ });
76
+ function close() {
77
+ closed = true;
78
+ rpcPromiseMap.forEach(({ reject, method }) => {
79
+ reject(new Error(`[birpc] rpc is closed, cannot call "${method}"`));
80
+ });
81
+ rpcPromiseMap.clear();
82
+ off(onMessage);
83
+ }
84
+ async function onMessage(data, ...extra) {
85
+ const msg = deserialize(data);
86
+ if (msg.t === "q") {
87
+ const { m: method, a: args } = msg;
88
+ let result, error;
89
+ const fn = resolver ? resolver(method, functions[method]) : functions[method];
90
+ if (!fn) {
91
+ error = new Error(`[birpc] function "${method}" not found`);
92
+ } else {
93
+ try {
94
+ result = await fn.apply(bind === "rpc" ? rpc : functions, args);
95
+ } catch (e) {
96
+ error = e;
97
+ }
98
+ }
99
+ if (msg.i) {
100
+ if (error && options.onError)
101
+ options.onError(error, method, args);
102
+ post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
103
+ }
104
+ } else {
105
+ const { i: ack, r: result, e: error } = msg;
106
+ const promise = rpcPromiseMap.get(ack);
107
+ if (promise) {
108
+ clearTimeout(promise.timeoutId);
109
+ if (error)
110
+ promise.reject(error);
111
+ else
112
+ promise.resolve(result);
113
+ }
114
+ rpcPromiseMap.delete(ack);
115
+ }
116
+ }
117
+ _promise = on(onMessage);
118
+ return rpc;
119
+ }
120
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
121
+ function nanoid(size = 21) {
122
+ let id = "";
123
+ let i = size;
124
+ while (i--)
125
+ id += urlAlphabet[random() * 64 | 0];
126
+ return id;
127
+ }
128
+
129
+ // src/rpc/channel.ts
130
+ function createBroadcastChannel(channelName) {
131
+ const channel = new BroadcastChannel(channelName);
132
+ const handlers = /* @__PURE__ */ new Set();
133
+ channel.addEventListener("message", (event) => {
134
+ handlers.forEach((handler) => handler(event.data));
135
+ });
136
+ return {
137
+ send: (message) => {
138
+ channel.postMessage(message);
139
+ },
140
+ onMessage: (handler) => {
141
+ handlers.add(handler);
142
+ return () => handlers.delete(handler);
143
+ },
144
+ close: () => {
145
+ channel.close();
146
+ handlers.clear();
147
+ }
148
+ };
149
+ }
150
+ function createPostMessageChannel(target, origin = "*") {
151
+ const handlers = /* @__PURE__ */ new Set();
152
+ const messageHandler = (event) => {
153
+ if (origin !== "*" && event.origin !== origin)
154
+ return;
155
+ handlers.forEach((handler) => handler(event.data));
156
+ };
157
+ window.addEventListener("message", messageHandler);
158
+ return {
159
+ send: (message) => {
160
+ target.postMessage(message, origin);
161
+ },
162
+ onMessage: (handler) => {
163
+ handlers.add(handler);
164
+ return () => handlers.delete(handler);
165
+ },
166
+ close: () => {
167
+ window.removeEventListener("message", messageHandler);
168
+ handlers.clear();
169
+ }
170
+ };
171
+ }
172
+ function createWebSocketChannel(url) {
173
+ const ws = new WebSocket(url);
174
+ const handlers = /* @__PURE__ */ new Set();
175
+ ws.addEventListener("message", (event) => {
176
+ try {
177
+ const data = JSON.parse(event.data);
178
+ handlers.forEach((handler) => handler(data));
179
+ } catch (error) {
180
+ console.error("[RPC] Failed to parse WebSocket message:", error);
181
+ }
182
+ });
183
+ return {
184
+ send: (message) => {
185
+ if (ws.readyState === WebSocket.OPEN) {
186
+ ws.send(JSON.stringify(message));
187
+ }
188
+ },
189
+ onMessage: (handler) => {
190
+ handlers.add(handler);
191
+ return () => handlers.delete(handler);
192
+ },
193
+ close: () => {
194
+ ws.close();
195
+ handlers.clear();
196
+ }
197
+ };
198
+ }
199
+ function createCustomEventChannel(eventName) {
200
+ const handlers = /* @__PURE__ */ new Set();
201
+ const eventHandler = (event) => {
202
+ handlers.forEach((handler) => handler(event.detail));
203
+ };
204
+ window.addEventListener(eventName, eventHandler);
205
+ return {
206
+ send: (message) => {
207
+ window.dispatchEvent(new CustomEvent(eventName, { detail: message }));
208
+ },
209
+ onMessage: (handler) => {
210
+ handlers.add(handler);
211
+ return () => handlers.delete(handler);
212
+ },
213
+ close: () => {
214
+ window.removeEventListener(eventName, eventHandler);
215
+ handlers.clear();
216
+ }
217
+ };
218
+ }
219
+
220
+ // src/rpc/index.ts
221
+ function createClientRPC(functions, channel, options = {}) {
222
+ const { timeout = 3e4 } = options;
223
+ const rpc = createBirpc(functions, {
224
+ post: (data) => {
225
+ channel.send(data);
226
+ },
227
+ on: (fn) => {
228
+ return channel.onMessage(fn);
229
+ },
230
+ timeout
231
+ });
232
+ return Object.assign(rpc, functions, {
233
+ $functions: functions,
234
+ $channel: channel,
235
+ $state: {
236
+ state: "connected",
237
+ connectedAt: Date.now()
238
+ },
239
+ $close: () => {
240
+ var _a;
241
+ (_a = channel.close) == null ? void 0 : _a.call(channel);
242
+ }
243
+ });
244
+ }
245
+ function createServerRPC(functions, channel, options = {}) {
246
+ const { timeout = 3e4 } = options;
247
+ const rpc = createBirpc(functions, {
248
+ post: (data) => {
249
+ channel.send(data);
250
+ },
251
+ on: (fn) => {
252
+ return channel.onMessage(fn);
253
+ },
254
+ timeout
255
+ });
256
+ return Object.assign(rpc, functions, {
257
+ $functions: functions,
258
+ $channel: channel,
259
+ $state: {
260
+ state: "connected",
261
+ connectedAt: Date.now()
262
+ },
263
+ $close: () => {
264
+ var _a;
265
+ (_a = channel.close) == null ? void 0 : _a.call(channel);
266
+ }
267
+ });
268
+ }
269
+ export {
270
+ createBroadcastChannel,
271
+ createClientRPC,
272
+ createCustomEventChannel,
273
+ createPostMessageChannel,
274
+ createServerRPC,
275
+ createWebSocketChannel
276
+ };
277
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../node_modules/.pnpm/birpc@0.2.19/node_modules/birpc/dist/index.mjs","../../src/rpc/channel.ts","../../src/rpc/index.ts"],"sourcesContent":["const DEFAULT_TIMEOUT = 6e4;\nfunction defaultSerialize(i) {\n return i;\n}\nconst defaultDeserialize = defaultSerialize;\nconst { clearTimeout, setTimeout } = globalThis;\nconst random = Math.random.bind(Math);\nfunction createBirpc(functions, options) {\n const {\n post,\n on,\n off = () => {\n },\n eventNames = [],\n serialize = defaultSerialize,\n deserialize = defaultDeserialize,\n resolver,\n bind = \"rpc\",\n timeout = DEFAULT_TIMEOUT\n } = options;\n const rpcPromiseMap = /* @__PURE__ */ new Map();\n let _promise;\n let closed = false;\n const rpc = new Proxy({}, {\n get(_, method) {\n if (method === \"$functions\")\n return functions;\n if (method === \"$close\")\n return close;\n if (method === \"then\" && !eventNames.includes(\"then\") && !(\"then\" in functions))\n return void 0;\n const sendEvent = (...args) => {\n post(serialize({ m: method, a: args, t: \"q\" }));\n };\n if (eventNames.includes(method)) {\n sendEvent.asEvent = sendEvent;\n return sendEvent;\n }\n const sendCall = async (...args) => {\n if (closed)\n throw new Error(`[birpc] rpc is closed, cannot call \"${method}\"`);\n if (_promise) {\n try {\n await _promise;\n } finally {\n _promise = void 0;\n }\n }\n return new Promise((resolve, reject) => {\n const id = nanoid();\n let timeoutId;\n if (timeout >= 0) {\n timeoutId = setTimeout(() => {\n try {\n options.onTimeoutError?.(method, args);\n throw new Error(`[birpc] timeout on calling \"${method}\"`);\n } catch (e) {\n reject(e);\n }\n rpcPromiseMap.delete(id);\n }, timeout);\n if (typeof timeoutId === \"object\")\n timeoutId = timeoutId.unref?.();\n }\n rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });\n post(serialize({ m: method, a: args, i: id, t: \"q\" }));\n });\n };\n sendCall.asEvent = sendEvent;\n return sendCall;\n }\n });\n function close() {\n closed = true;\n rpcPromiseMap.forEach(({ reject, method }) => {\n reject(new Error(`[birpc] rpc is closed, cannot call \"${method}\"`));\n });\n rpcPromiseMap.clear();\n off(onMessage);\n }\n async function onMessage(data, ...extra) {\n const msg = deserialize(data);\n if (msg.t === \"q\") {\n const { m: method, a: args } = msg;\n let result, error;\n const fn = resolver ? resolver(method, functions[method]) : functions[method];\n if (!fn) {\n error = new Error(`[birpc] function \"${method}\" not found`);\n } else {\n try {\n result = await fn.apply(bind === \"rpc\" ? rpc : functions, args);\n } catch (e) {\n error = e;\n }\n }\n if (msg.i) {\n if (error && options.onError)\n options.onError(error, method, args);\n post(serialize({ t: \"s\", i: msg.i, r: result, e: error }), ...extra);\n }\n } else {\n const { i: ack, r: result, e: error } = msg;\n const promise = rpcPromiseMap.get(ack);\n if (promise) {\n clearTimeout(promise.timeoutId);\n if (error)\n promise.reject(error);\n else\n promise.resolve(result);\n }\n rpcPromiseMap.delete(ack);\n }\n }\n _promise = on(onMessage);\n return rpc;\n}\nconst cacheMap = /* @__PURE__ */ new WeakMap();\nfunction cachedMap(items, fn) {\n return items.map((i) => {\n let r = cacheMap.get(i);\n if (!r) {\n r = fn(i);\n cacheMap.set(i, r);\n }\n return r;\n });\n}\nfunction createBirpcGroup(functions, channels, options = {}) {\n const getChannels = () => typeof channels === \"function\" ? channels() : channels;\n const getClients = (channels2 = getChannels()) => cachedMap(channels2, (s) => createBirpc(functions, { ...options, ...s }));\n const broadcastProxy = new Proxy({}, {\n get(_, method) {\n const client = getClients();\n const callbacks = client.map((c) => c[method]);\n const sendCall = (...args) => {\n return Promise.all(callbacks.map((i) => i(...args)));\n };\n sendCall.asEvent = (...args) => {\n callbacks.map((i) => i.asEvent(...args));\n };\n return sendCall;\n }\n });\n function updateChannels(fn) {\n const channels2 = getChannels();\n fn?.(channels2);\n return getClients(channels2);\n }\n getClients();\n return {\n get clients() {\n return getClients();\n },\n functions,\n updateChannels,\n broadcast: broadcastProxy,\n /**\n * @deprecated use `broadcast`\n */\n // @ts-expect-error deprecated\n boardcast: broadcastProxy\n };\n}\nconst urlAlphabet = \"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict\";\nfunction nanoid(size = 21) {\n let id = \"\";\n let i = size;\n while (i--)\n id += urlAlphabet[random() * 64 | 0];\n return id;\n}\n\nexport { DEFAULT_TIMEOUT, cachedMap, createBirpc, createBirpcGroup };\n","/**\n * RPC channels for different communication methods\n * 不同通信方式的 RPC 通道\n */\n\nimport type { RPCChannel } from './types'\n\n/**\n * Create a BroadcastChannel-based RPC channel\n * 创建基于 BroadcastChannel 的 RPC 通道\n */\nexport function createBroadcastChannel(channelName: string): RPCChannel {\n const channel = new BroadcastChannel(channelName)\n const handlers = new Set<(message: any) => void>()\n\n channel.addEventListener('message', (event) => {\n handlers.forEach(handler => handler(event.data))\n })\n\n return {\n send: (message: any) => {\n channel.postMessage(message)\n },\n onMessage: (handler: (message: any) => void) => {\n handlers.add(handler)\n return () => handlers.delete(handler)\n },\n close: () => {\n channel.close()\n handlers.clear()\n },\n }\n}\n\n/**\n * Create a PostMessage-based RPC channel (for iframe communication)\n * 创建基于 PostMessage 的 RPC 通道(用于 iframe 通信)\n */\nexport function createPostMessageChannel(\n target: Window,\n origin: string = '*',\n): RPCChannel {\n const handlers = new Set<(message: any) => void>()\n\n const messageHandler = (event: MessageEvent) => {\n if (origin !== '*' && event.origin !== origin)\n return\n\n handlers.forEach(handler => handler(event.data))\n }\n\n window.addEventListener('message', messageHandler)\n\n return {\n send: (message: any) => {\n target.postMessage(message, origin)\n },\n onMessage: (handler: (message: any) => void) => {\n handlers.add(handler)\n return () => handlers.delete(handler)\n },\n close: () => {\n window.removeEventListener('message', messageHandler)\n handlers.clear()\n },\n }\n}\n\n/**\n * Create a WebSocket-based RPC channel\n * 创建基于 WebSocket 的 RPC 通道\n */\nexport function createWebSocketChannel(url: string): RPCChannel {\n const ws = new WebSocket(url)\n const handlers = new Set<(message: any) => void>()\n\n ws.addEventListener('message', (event) => {\n try {\n const data = JSON.parse(event.data)\n handlers.forEach(handler => handler(data))\n }\n catch (error) {\n console.error('[RPC] Failed to parse WebSocket message:', error)\n }\n })\n\n return {\n send: (message: any) => {\n if (ws.readyState === WebSocket.OPEN) {\n ws.send(JSON.stringify(message))\n }\n },\n onMessage: (handler: (message: any) => void) => {\n handlers.add(handler)\n return () => handlers.delete(handler)\n },\n close: () => {\n ws.close()\n handlers.clear()\n },\n }\n}\n\n/**\n * Create a custom event-based RPC channel (for in-page communication)\n * 创建基于自定义事件的 RPC 通道(用于页面内通信)\n */\nexport function createCustomEventChannel(eventName: string): RPCChannel {\n const handlers = new Set<(message: any) => void>()\n\n const eventHandler = (event: CustomEvent) => {\n handlers.forEach(handler => handler(event.detail))\n }\n\n window.addEventListener(eventName, eventHandler as EventListener)\n\n return {\n send: (message: any) => {\n window.dispatchEvent(new CustomEvent(eventName, { detail: message }))\n },\n onMessage: (handler: (message: any) => void) => {\n handlers.add(handler)\n return () => handlers.delete(handler)\n },\n close: () => {\n window.removeEventListener(eventName, eventHandler as EventListener)\n handlers.clear()\n },\n }\n}\n","/**\n * RPC system for React DevTools\n * React DevTools RPC 系统\n */\n\nimport type { ClientFunctions, ServerFunctions } from '../types'\nimport type { ClientRPC, RPCChannel, RPCOptions, ServerRPC } from './types'\nimport { createBirpc } from 'birpc'\n\n/**\n * Create client RPC instance\n * 创建客户端 RPC 实例\n */\nexport function createClientRPC(\n functions: ClientFunctions,\n channel: RPCChannel,\n options: RPCOptions = {},\n): ClientRPC {\n const { timeout = 30000 } = options\n\n const rpc = createBirpc<ServerFunctions, ClientFunctions>(functions, {\n post: (data) => {\n channel.send(data)\n },\n on: (fn) => {\n return channel.onMessage(fn)\n },\n timeout,\n })\n\n return Object.assign(rpc, functions, {\n $functions: functions,\n $channel: channel,\n $state: {\n state: 'connected' as const,\n connectedAt: Date.now(),\n },\n $close: () => {\n channel.close?.()\n },\n }) as unknown as ClientRPC\n}\n\n/**\n * Create server RPC instance\n * 创建服务端 RPC 实例\n */\nexport function createServerRPC(\n functions: ServerFunctions,\n channel: RPCChannel,\n options: RPCOptions = {},\n): ServerRPC {\n const { timeout = 30000 } = options\n\n const rpc = createBirpc<ClientFunctions, ServerFunctions>(functions, {\n post: (data) => {\n channel.send(data)\n },\n on: (fn) => {\n return channel.onMessage(fn)\n },\n timeout,\n })\n\n return Object.assign(rpc, functions, {\n $functions: functions,\n $channel: channel,\n $state: {\n state: 'connected' as const,\n connectedAt: Date.now(),\n },\n $close: () => {\n channel.close?.()\n },\n }) as unknown as ServerRPC\n}\n\n// Export channel creators\nexport * from './channel'\nexport * from './types'\n"],"mappings":";AAAA,IAAM,kBAAkB;AACxB,SAAS,iBAAiB,GAAG;AAC3B,SAAO;AACT;AACA,IAAM,qBAAqB;AAC3B,IAAM,EAAE,cAAc,WAAW,IAAI;AACrC,IAAM,SAAS,KAAK,OAAO,KAAK,IAAI;AACpC,SAAS,YAAY,WAAW,SAAS;AACvC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,I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