@iss-ai/window-message-bus 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, ng1007<https://github.com/ng1007>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,374 @@
1
+ # @iss-ai/window-message-bus
2
+
3
+ Window 消息封装为 bus,提供基于 `postMessage` 的跨窗口通信解决方案。支持主窗口与 iframe 之间的双向消息传递,以及编辑器场景下的专用通信协议。
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ ## 特性
8
+
9
+ - 🚀 **跨窗口通信**:支持主窗口与 iframe 之间的双向消息传递
10
+ - 🔒 **安全验证**:支持来源域名白名单验证
11
+ - 📦 **多格式构建**:同时提供 CJS、ESM、UMD、IIFE 四种模块格式
12
+ - 🎯 **类型安全**:完整的 TypeScript 类型定义
13
+ - 🛠️ **编辑器专用**:内置 EditorMessageBus 用于编辑器与 iframe 通信
14
+ - 🧪 **测试友好**:基于 Jest 和 jsdom 的完整测试覆盖
15
+
16
+ ## 安装
17
+
18
+ ```bash
19
+ npm install @iss-ai/window-message-bus
20
+ ```
21
+
22
+
23
+
24
+ ```bash
25
+ pnpm add @iss-ai/window-message-bus
26
+ ```
27
+
28
+ ## 快速开始
29
+
30
+ ### 基础用法 - WindowMessageBus
31
+
32
+ ```typescript
33
+ import { WindowMessageBus } from '@iss-ai/window-message-bus';
34
+
35
+ // 创建实例
36
+ const bus = new WindowMessageBus({
37
+ sourceId: 'main-window',
38
+ debug: true,
39
+ });
40
+
41
+ // 监听消息
42
+ bus.on('custom-event', (data, context) => {
43
+ console.log('收到消息:', data, context);
44
+ });
45
+
46
+ // 发送消息到父窗口
47
+ bus.emitTo('parent', 'custom-event', { message: 'Hello from iframe!' });
48
+
49
+ // 发送消息到指定窗口
50
+ bus.emitTo(window.parent, 'custom-event', { message: 'Hello parent!' });
51
+ ```
52
+
53
+ ### 编辑器场景 - EditorMessageBus
54
+
55
+ ```typescript
56
+ import { EditorMessageBus } from '@iss-ai/window-message-bus';
57
+
58
+ // 主窗口(编辑器容器)
59
+ const editorBus = new EditorMessageBus({
60
+ sourceId: 'editor-main',
61
+ debug: true,
62
+ });
63
+
64
+ // 监听编辑器就绪
65
+ editorBus.onReady((data) => {
66
+ console.log('编辑器已就绪:', data);
67
+ });
68
+
69
+ // 设置编辑器数据
70
+ editorBus.setData({ nodes: [], edges: [] });
71
+
72
+ // 监听内容变更
73
+ editorBus.onChange((change) => {
74
+ console.log('内容变更:', change);
75
+ });
76
+
77
+ // 监听保存
78
+ editorBus.onSave((data) => {
79
+ console.log('保存数据:', data);
80
+ });
81
+
82
+ // 发送保存指令
83
+ editorBus.save();
84
+
85
+ // iframe 端
86
+ const iframeEditorBus = new EditorMessageBus({
87
+ sourceId: 'editor-iframe',
88
+ debug: true,
89
+ });
90
+
91
+ // 通知主窗口已就绪
92
+ iframeEditorBus.isReady({ version: '1.0.0' });
93
+
94
+ // 接收设置数据指令
95
+ iframeEditorBus.onSetData((data) => {
96
+ renderEditor(data);
97
+ });
98
+
99
+ // 内容变更时通知主窗口
100
+ iframeEditorBus.change({ type: 'update', elementId: 'node-1' });
101
+
102
+ // 导出数据
103
+ const data = await iframeEditorBus.exportData();
104
+ ```
105
+
106
+ ## API 文档
107
+
108
+ ### WindowMessageBus
109
+
110
+ #### 构造函数选项
111
+
112
+ | 参数 | 类型 | 默认值 | 说明 |
113
+ |------|------|--------|------|
114
+ | `debug` | `boolean` | `false` | 是否开启调试模式 |
115
+ | `debugPrefix` | `string` | `'[WindowMessageBus]'` | 调试日志前缀 |
116
+ | `sourceId` | `string` | 自动生成 | 当前实例的唯一标识 |
117
+ | `allowedOrigins` | `string[]` | `['*']` | 允许的消息源域名 |
118
+ | `serialize` | `(data: any) => string` | `JSON.stringify` | 消息序列化函数 |
119
+ | `deserialize` | `(str: string) => any` | `JSON.parse` | 消息反序列化函数 |
120
+
121
+ #### 主要方法
122
+
123
+ | 方法 | 说明 |
124
+ |------|------|
125
+ | `emitTo(target, type, data)` | 向指定目标发送消息 |
126
+ | `on(type, handler)` | 监听消息事件 |
127
+ | `off(type, handler)` | 取消监听消息事件 |
128
+ | `once(type, handler)` | 监听一次消息事件 |
129
+ | `getSourceId()` | 获取当前实例的 sourceId |
130
+
131
+ #### PostMessageTarget 类型
132
+
133
+ ```typescript
134
+ type PostMessageTarget = WindowProxy | 'parent' | 'self' | 'top';
135
+ ```
136
+
137
+ ### EditorMessageBus
138
+
139
+ 继承自 `WindowMessageBus`,提供以下专用方法:
140
+
141
+ #### 就绪相关
142
+
143
+ | 方法 | 说明 |
144
+ |------|------|
145
+ | `isReady(data, target?)` | 发送编辑器已就绪消息 |
146
+ | `onReady(handler)` | 监听编辑器已就绪事件 |
147
+
148
+ #### 数据设置
149
+
150
+ | 方法 | 说明 |
151
+ |------|------|
152
+ | `setData(data, target?)` | 设置编辑器数据 |
153
+ | `onSetData(handler)` | 监听设置数据事件 |
154
+
155
+ #### 配置设置
156
+
157
+ | 方法 | 说明 |
158
+ |------|------|
159
+ | `setConfig(config, target?)` | 设置编辑器配置 |
160
+ | `onSetConfig(handler)` | 监听设置配置事件 |
161
+
162
+ #### 内容变更
163
+
164
+ | 方法 | 说明 |
165
+ |------|------|
166
+ | `change(changeData, target?)` | 发送内容变更消息 |
167
+ | `onChange(handler)` | 监听内容变更事件 |
168
+
169
+ #### 保存
170
+
171
+ | 方法 | 说明 |
172
+ |------|------|
173
+ | `save(options?, target?)` | 发送保存消息 |
174
+ | `onSave(handler)` | 监听保存事件 |
175
+
176
+ #### 导出功能
177
+
178
+ | 方法 | 说明 |
179
+ |------|------|
180
+ | `exportSVG(options?, target?)` | 导出 SVG |
181
+ | `onExportSVG(handler)` | 监听 SVG 导出响应 |
182
+ | `exportPNG(options?, target?)` | 导出 PNG |
183
+ | `onExportPNG(handler)` | 监听 PNG 导出响应 |
184
+ | `exportData(options?, target?)` | 导出数据 |
185
+ | `onExportData(handler)` | 监听数据导出响应 |
186
+
187
+ #### 其他功能
188
+
189
+ | 方法 | 说明 |
190
+ |------|------|
191
+ | `getData(target?)` | 获取编辑器数据 |
192
+ | `onGetData(handler)` | 监听获取数据响应 |
193
+ | `thumbnail(options?, target?)` | 生成缩略图 |
194
+ | `onThumnail(handler)` | 监听缩略图响应 |
195
+ | `preview(options?, target?)` | 预览 |
196
+ | `onPreview(handler)` | 监听预览响应 |
197
+
198
+ ## 类型定义
199
+
200
+ ### MessageData
201
+
202
+ ```typescript
203
+ interface MessageData {
204
+ type: string; // 事件类型
205
+ data: any; // 消息数据
206
+ messageId?: string; // 消息 ID
207
+ sourceId?: string; // 来源标识
208
+ }
209
+ ```
210
+
211
+ ### MessageContext
212
+
213
+ ```typescript
214
+ interface MessageContext {
215
+ origin: string; // 消息来源域名
216
+ source: WindowProxy; // 消息来源窗口引用
217
+ messageId?: string; // 消息 ID
218
+ sourceId?: string; // 消息来源标识
219
+ }
220
+ ```
221
+
222
+ ### EditorData
223
+
224
+ ```typescript
225
+ interface EditorData {
226
+ [key: string]: any;
227
+ }
228
+ ```
229
+
230
+ ### EditorConfig
231
+
232
+ ```typescript
233
+ interface EditorConfig {
234
+ canvas?: {
235
+ width?: number;
236
+ height?: number;
237
+ backgroundColor?: string;
238
+ grid?: {
239
+ enabled?: boolean;
240
+ size?: number;
241
+ color?: string;
242
+ };
243
+ snapToGrid?: boolean;
244
+ };
245
+ toolbar?: {
246
+ enabled?: boolean;
247
+ position?: 'top' | 'bottom' | 'left' | 'right';
248
+ items?: string[];
249
+ };
250
+ propertiesPanel?: {
251
+ enabled?: boolean;
252
+ position?: 'left' | 'right';
253
+ width?: number;
254
+ };
255
+ minimap?: {
256
+ enabled?: boolean;
257
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
258
+ };
259
+ interaction?: {
260
+ zoom?: { enabled?: boolean; minScale?: number; maxScale?: number };
261
+ pan?: { enabled?: boolean; sensitivity?: number };
262
+ selection?: { enabled?: boolean; multiple?: boolean };
263
+ drag?: { enabled?: boolean; snap?: boolean };
264
+ };
265
+ theme?: {
266
+ mode?: 'light' | 'dark' | 'auto';
267
+ colors?: {
268
+ primary?: string;
269
+ secondary?: string;
270
+ background?: string;
271
+ surface?: string;
272
+ };
273
+ };
274
+ [key: string]: any;
275
+ }
276
+ ```
277
+
278
+ ## 使用示例
279
+
280
+ ### 主窗口与 iframe 通信
281
+
282
+ **主窗口代码:**
283
+
284
+ ```html
285
+ <!DOCTYPE html>
286
+ <html>
287
+ <head>
288
+ <title>Main Window</title>
289
+ </head>
290
+ <body>
291
+ <iframe id="editor" src="editor.html"></iframe>
292
+ <script src="https://unpkg.com/@iss-ai/window-message-bus"></script>
293
+ <script>
294
+ const bus = new WindowMessageBus.WindowMessageBus({
295
+ sourceId: 'main-window',
296
+ debug: true,
297
+ });
298
+
299
+ // 监听 iframe 消息
300
+ bus.on('editor:message', (data) => {
301
+ console.log('收到 iframe 消息:', data);
302
+ });
303
+
304
+ // 向 iframe 发送消息
305
+ setTimeout(() => {
306
+ bus.emitTo('parent', 'init-editor', { config: { theme: 'dark' } });
307
+ }, 1000);
308
+ </script>
309
+ </body>
310
+ </html>
311
+ ```
312
+
313
+ **iframe 代码:**
314
+
315
+ ```html
316
+ <!DOCTYPE html>
317
+ <html>
318
+ <head>
319
+ <title>Iframe Editor</title>
320
+ </head>
321
+ <body>
322
+ <div id="editor">Editor Content</div>
323
+ <script src="https://unpkg.com/@iss-ai/window-message-bus"></script>
324
+ <script>
325
+ const bus = new WindowMessageBus.WindowMessageBus({
326
+ sourceId: 'iframe-editor',
327
+ debug: true,
328
+ });
329
+
330
+ // 监听主窗口消息
331
+ bus.on('init-editor', (data) => {
332
+ console.log('初始化编辑器:', data);
333
+ });
334
+
335
+ // 向主窗口发送消息
336
+ bus.emitTo('parent', 'editor:message', { content: 'Hello from iframe!' });
337
+ </script>
338
+ </body>
339
+ </html>
340
+ ```
341
+
342
+ ## 脚本命令
343
+
344
+ ```bash
345
+ # 构建
346
+ npm run build
347
+
348
+ # 测试
349
+ npm test
350
+
351
+ # 发布
352
+ npm run pub
353
+
354
+ # 覆盖率
355
+ npm run coveralls
356
+
357
+ # TypeScript 检查
358
+ npm run tsc
359
+ ```
360
+
361
+ ## 浏览器支持
362
+
363
+ - Chrome >= 60
364
+ - Firefox >= 55
365
+ - Safari >= 11
366
+ - Edge >= 79
367
+
368
+ ## 许可证
369
+
370
+ MIT License
371
+
372
+ ## 贡献
373
+
374
+ 欢迎提交 Issue 和 Pull Request!
@@ -0,0 +1,375 @@
1
+ import { WindowMessageBus, PostMessageTarget } from './WindowMessageBus';
2
+ /**
3
+ * 编辑器消息类型
4
+ */
5
+ export type EditorMessageType = 'isReady' | 'onReady' | 'setData' | 'onSetData' | 'setConfig' | 'onSetConfig' | 'change' | 'onChange' | 'save' | 'onSave' | 'exportSVG' | 'onExportSVG' | 'exportPNG' | 'onExportPNG' | 'exportData' | 'onExportData' | 'getData' | 'onGetData' | 'thumnail' | 'onThumnail' | 'preview' | 'onPreview';
6
+ /**
7
+ * 编辑器数据接口
8
+ */
9
+ export interface EditorData {
10
+ [key: string]: any;
11
+ }
12
+ /**
13
+ * 编辑器配置接口
14
+ */
15
+ export interface EditorConfig {
16
+ /** 画布配置 */
17
+ canvas?: {
18
+ width?: number;
19
+ height?: number;
20
+ backgroundColor?: string;
21
+ grid?: {
22
+ enabled?: boolean;
23
+ size?: number;
24
+ color?: string;
25
+ };
26
+ snapToGrid?: boolean;
27
+ [key: string]: any;
28
+ };
29
+ /** 工具栏配置 */
30
+ toolbar?: {
31
+ enabled?: boolean;
32
+ position?: 'top' | 'bottom' | 'left' | 'right';
33
+ items?: string[];
34
+ [key: string]: any;
35
+ };
36
+ /** 属性面板配置 */
37
+ propertiesPanel?: {
38
+ enabled?: boolean;
39
+ position?: 'left' | 'right';
40
+ width?: number;
41
+ };
42
+ /** 最小化/最大化配置 */
43
+ minimap?: {
44
+ enabled?: boolean;
45
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
46
+ };
47
+ /** 交互配置 */
48
+ interaction?: {
49
+ zoom?: {
50
+ enabled?: boolean;
51
+ minScale?: number;
52
+ maxScale?: number;
53
+ };
54
+ pan?: {
55
+ enabled?: boolean;
56
+ sensitivity?: number;
57
+ };
58
+ selection?: {
59
+ enabled?: boolean;
60
+ multiple?: boolean;
61
+ };
62
+ drag?: {
63
+ enabled?: boolean;
64
+ snap?: boolean;
65
+ };
66
+ };
67
+ /** 主题配置 */
68
+ theme?: {
69
+ mode?: 'light' | 'dark' | 'auto';
70
+ colors?: {
71
+ primary?: string;
72
+ secondary?: string;
73
+ background?: string;
74
+ surface?: string;
75
+ };
76
+ [key: string]: any;
77
+ };
78
+ /** 其他自定义配置 */
79
+ [key: string]: any;
80
+ }
81
+ /**
82
+ * 编辑器内容变更数据
83
+ */
84
+ export interface EditorChangeData {
85
+ /** 变更类型 */
86
+ type?: 'add' | 'remove' | 'update' | 'clear';
87
+ /** 变更的元素 ID */
88
+ elementId?: string;
89
+ /** 变更前的数据 */
90
+ oldValue?: EditorData;
91
+ /** 变更后的数据 */
92
+ newValue?: EditorData;
93
+ /** 时间戳 */
94
+ timestamp?: number;
95
+ }
96
+ /**
97
+ * 导出选项
98
+ */
99
+ export interface ExportOptions {
100
+ /** 宽度 */
101
+ width?: number;
102
+ /** 高度 */
103
+ height?: number;
104
+ /** 背景颜色 */
105
+ backgroundColor?: string;
106
+ /** 缩放比例 */
107
+ scale?: number;
108
+ /** 是否包含画布外元素 */
109
+ includeOverflow?: boolean;
110
+ [key: string]: any;
111
+ }
112
+ /**
113
+ * 缩略图选项
114
+ */
115
+ export interface ThumbnailOptions {
116
+ /** 缩略图宽度 */
117
+ width?: number;
118
+ /** 缩略图高度 */
119
+ height?: number;
120
+ /** 质量 (0-1) */
121
+ quality?: number;
122
+ [key: string]: any;
123
+ }
124
+ /**
125
+ * 预览选项
126
+ */
127
+ export interface PreviewOptions {
128
+ /** 预览模式:'full' 全屏预览,'modal' 模态框预览,'panel' 面板预览 */
129
+ mode?: 'full' | 'modal' | 'panel' | any;
130
+ /** 预览宽度 */
131
+ width?: number;
132
+ /** 预览高度 */
133
+ height?: number;
134
+ /** 是否显示工具栏 */
135
+ showToolbar?: boolean;
136
+ /** 是否显示缩放控制 */
137
+ showZoomControls?: boolean;
138
+ /** 是否允许下载 */
139
+ allowDownload?: boolean;
140
+ /** 是否允许打印 */
141
+ allowPrint?: boolean;
142
+ [key: string]: any;
143
+ }
144
+ /**
145
+ * 编辑器消息总线配置
146
+ */
147
+ export interface EditorMessageBusOptions {
148
+ /** 是否开启调试模式 */
149
+ debug?: boolean;
150
+ /** 当前实例的唯一标识 */
151
+ sourceId?: string;
152
+ /** 允许的消息源域名 */
153
+ allowedOrigins?: string[];
154
+ /** 编辑器容器选择器或引用 */
155
+ container?: string | HTMLElement;
156
+ }
157
+ /**
158
+ * 编辑器消息总线类
159
+ * 基于 WindowMessageBus 实现,专门用于编辑器与 iframe 之间的通信
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // 主窗口(编辑器容器)
164
+ * const editorBus = new EditorMessageBus({ sourceId: 'editor-main', debug: true });
165
+ *
166
+ * // 监听编辑器就绪
167
+ * editorBus.onReady((data) => console.log('编辑器已就绪:', data));
168
+ *
169
+ * // 设置编辑器数据
170
+ * editorBus.setData({ nodes: [], edges: [] });
171
+ *
172
+ * // 监听内容变更
173
+ * editorBus.onChange((change) => console.log('内容变更:', change));
174
+ *
175
+ * // 监听保存
176
+ * editorBus.onSave((data) => console.log('保存数据:', data));
177
+ *
178
+ * // 发送保存指令
179
+ * editorBus.save();
180
+ *
181
+ * // iframe 端
182
+ * const iframeEditorBus = new EditorMessageBus({ sourceId: 'editor-iframe', debug: true });
183
+ *
184
+ * // 通知主窗口已就绪
185
+ * iframeEditorBus.isReady({ version: '1.0.0' });
186
+ *
187
+ * // 接收设置数据指令
188
+ * iframeEditorBus.onSetData((data) => {
189
+ * // 渲染数据到编辑器
190
+ * renderEditor(data);
191
+ * });
192
+ *
193
+ * // 内容变更时通知主窗口
194
+ * iframeEditorBus.change({ type: 'update', elementId: 'node-1', timestamp: Date.now() });
195
+ *
196
+ * // 导出数据
197
+ * const data = await iframeEditorBus.exportData();
198
+ * ```
199
+ */
200
+ export declare class EditorMessageBus extends WindowMessageBus {
201
+ private _defaultTarget;
202
+ constructor(options?: EditorMessageBusOptions);
203
+ /**
204
+ * 获取默认消息发送目标
205
+ */
206
+ getDefaultTarget(): PostMessageTarget;
207
+ /**
208
+ * 发送编辑器已就绪消息
209
+ * @param data 就绪数据
210
+ * @param target 可选的目标,默认为默认目标
211
+ */
212
+ isReady(data?: {
213
+ sourceId?: string;
214
+ version?: string;
215
+ timestamp?: number;
216
+ }, target?: PostMessageTarget): void;
217
+ /**
218
+ * 监听编辑器已就绪消息
219
+ * @param handler 处理函数
220
+ * @returns 取消监听函数
221
+ */
222
+ onReady(handler: (data: {
223
+ sourceId?: string;
224
+ timestamp?: number;
225
+ [key: string]: any;
226
+ }) => void): () => void;
227
+ /**
228
+ * 发送设置编辑器数据消息
229
+ * @param data 要设置的数据
230
+ * @param target 可选的目标,默认为默认目标
231
+ */
232
+ setData(data: EditorData, target?: PostMessageTarget): void;
233
+ /**
234
+ * 监听设置编辑器数据消息
235
+ * @param handler 处理函数
236
+ * @returns 取消监听函数
237
+ */
238
+ onSetData(handler: (data: EditorData) => void): () => void;
239
+ /**
240
+ * 发送设置编辑器配置消息
241
+ * @param config 要设置的配置
242
+ * @param target 可选的目标,默认为默认目标
243
+ */
244
+ setConfig(config: EditorConfig, target?: PostMessageTarget): void;
245
+ /**
246
+ * 监听设置编辑器配置消息
247
+ * @param handler 处理函数
248
+ * @returns 取消监听函数
249
+ */
250
+ onSetConfig(handler: (config: EditorConfig) => void): () => void;
251
+ /**
252
+ * 发送编辑器内容变更消息
253
+ * @param changeData 变更数据
254
+ * @param target 可选的目标,默认为默认目标
255
+ */
256
+ change(changeData: EditorChangeData, target?: PostMessageTarget): void;
257
+ /**
258
+ * 监听编辑器内容变更消息
259
+ * @param handler 处理函数
260
+ * @returns 取消监听函数
261
+ */
262
+ onChange(handler: (changeData: EditorChangeData) => void): () => void;
263
+ /**
264
+ * 发送保存消息
265
+ * @param options 保存选项
266
+ * @param target 可选的目标,默认为默认目标
267
+ */
268
+ save(options?: {
269
+ format?: string;
270
+ includeMetadata?: boolean;
271
+ }, target?: PostMessageTarget): void;
272
+ /**
273
+ * 监听保存消息
274
+ * @param handler 处理函数
275
+ * @returns 取消监听函数
276
+ */
277
+ onSave(handler: (options?: {
278
+ format?: string;
279
+ includeMetadata?: boolean;
280
+ }) => void): () => void;
281
+ /**
282
+ * 发送导出 SVG 消息
283
+ * @param options 导出选项
284
+ * @param target 可选的目标,默认为默认目标
285
+ */
286
+ exportSVG(options?: ExportOptions, target?: PostMessageTarget): void;
287
+ /**
288
+ * 监听导出 SVG 消息
289
+ * @param handler 处理函数
290
+ * @returns 取消监听函数
291
+ */
292
+ onExportSVG(handler: (options?: ExportOptions) => void): () => void;
293
+ /**
294
+ * 发送导出 PNG 消息
295
+ * @param options 导出选项
296
+ * @param target 可选的目标,默认为默认目标
297
+ */
298
+ exportPNG(options?: ExportOptions, target?: PostMessageTarget): void;
299
+ /**
300
+ * 监听导出 PNG 消息
301
+ * @param handler 处理函数
302
+ * @returns 取消监听函数
303
+ */
304
+ onExportPNG(handler: (options?: ExportOptions) => void): () => void;
305
+ /**
306
+ * 发送导出数据消息
307
+ * @param options 导出选项
308
+ * @param target 可选的目标,默认为默认目标
309
+ */
310
+ exportData(options?: {
311
+ format?: string;
312
+ includeMetadata?: boolean;
313
+ }, target?: PostMessageTarget): void;
314
+ /**
315
+ * 监听导出数据消息
316
+ * @param handler 处理函数
317
+ * @returns 取消监听函数
318
+ */
319
+ onExportData(handler: (options?: {
320
+ format?: string;
321
+ includeMetadata?: boolean;
322
+ }) => void): () => void;
323
+ /**
324
+ * 发送获取数据消息
325
+ * @param options 获取选项
326
+ * @param target 可选的目标,默认为默认目标
327
+ */
328
+ getData(options?: {
329
+ includeMetadata?: boolean;
330
+ }, target?: PostMessageTarget): void;
331
+ /**
332
+ * 监听获取数据消息
333
+ * @param handler 处理函数
334
+ * @returns 取消监听函数
335
+ */
336
+ onGetData(handler: (options?: {
337
+ includeMetadata?: boolean;
338
+ }) => void): () => void;
339
+ /**
340
+ * 发送生成缩略图消息
341
+ * @param options 缩略图选项
342
+ * @param target 可选的目标,默认为默认目标
343
+ */
344
+ thumnail(options?: ThumbnailOptions, target?: PostMessageTarget): void;
345
+ /**
346
+ * 监听生成缩略图消息
347
+ * @param handler 处理函数
348
+ * @returns 取消监听函数
349
+ */
350
+ onThumnail(handler: (options?: ThumbnailOptions) => void): () => void;
351
+ /**
352
+ * 发送预览消息
353
+ * @param options 预览选项
354
+ * @param target 可选的目标,默认为默认目标
355
+ */
356
+ preview(options?: PreviewOptions, target?: PostMessageTarget): void;
357
+ /**
358
+ * 监听预览消息
359
+ * @param handler 处理函数
360
+ * @returns 取消监听函数
361
+ */
362
+ onPreview(handler: (options?: PreviewOptions) => void): () => void;
363
+ /**
364
+ * 创建取消监听函数
365
+ */
366
+ private _createUnsubscribe;
367
+ /**
368
+ * 销毁实例,清理资源
369
+ */
370
+ destroy(): void;
371
+ }
372
+ /**
373
+ * 创建 EditorMessageBus 实例的工厂函数
374
+ */
375
+ export declare function createEditorMessageBus(options?: EditorMessageBusOptions): EditorMessageBus;
@@ -0,0 +1,135 @@
1
+ import SampleEventBus, { EventHandler } from '@iss-ai/sample-event-bus';
2
+ /**
3
+ * 消息数据结构
4
+ */
5
+ export interface MessageData {
6
+ /** 事件类型 */
7
+ type: string;
8
+ /** 消息数据 */
9
+ data: any;
10
+ /** 消息 ID,用于追踪 */
11
+ messageId?: string;
12
+ /** 来源标识 */
13
+ sourceId?: string;
14
+ }
15
+ /**
16
+ * WindowMessageBus 配置选项
17
+ */
18
+ export interface WindowMessageBusOptions {
19
+ /** 是否开启调试模式 */
20
+ debug?: boolean;
21
+ /** 调试日志前缀 */
22
+ debugPrefix?: string;
23
+ /** 当前实例的唯一标识 */
24
+ sourceId?: string;
25
+ /** 允许的消息源域名,'*' 表示允许所有 */
26
+ allowedOrigins?: string[];
27
+ /** 消息序列化函数 */
28
+ serialize?: (data: any) => string;
29
+ /** 消息反序列化函数 */
30
+ deserialize?: (str: string) => any;
31
+ }
32
+ /**
33
+ * postMessage 的目标参数类型
34
+ */
35
+ export type PostMessageTarget = WindowProxy | 'parent' | 'self' | 'top';
36
+ /**
37
+ * 接收消息的上下文信息
38
+ */
39
+ export interface MessageContext {
40
+ /** 消息来源域名 */
41
+ origin: string;
42
+ /** 消息来源窗口引用 */
43
+ source: WindowProxy | null;
44
+ /** 消息 ID */
45
+ messageId?: string;
46
+ /** 消息来源标识 */
47
+ sourceId?: string;
48
+ }
49
+ /**
50
+ * 浏览器窗口消息总线
51
+ * 继承自 SampleEventBus,支持 window 与 iframe 消息互通
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // 主窗口
56
+ * const bus = new WindowMessageBus({ sourceId: 'main-window' });
57
+ * bus.on('iframe:message', (data) => console.log('收到 iframe 消息:', data));
58
+ * bus.emitTo('parent', 'main:message', { content: 'hello' });
59
+ *
60
+ * // iframe
61
+ * const iframeBus = new WindowMessageBus({ sourceId: 'iframe-1' });
62
+ * iframeBus.on('main:message', (data) => console.log('收到主窗口消息:', data));
63
+ * iframeBus.emitTo('parent', 'iframe:message', { content: 'hi' });
64
+ * ```
65
+ */
66
+ export declare class WindowMessageBus extends SampleEventBus {
67
+ protected _sourceId: string;
68
+ protected _allowedOrigins: string[];
69
+ protected _serialize: (data: any) => string;
70
+ protected _deserialize: (str: string) => any;
71
+ protected _messageHandler: (event: MessageEvent) => void;
72
+ constructor(options?: WindowMessageBusOptions);
73
+ /**
74
+ * 附加到 window message 事件监听
75
+ */
76
+ protected _attachMessageListener(): void;
77
+ /**
78
+ * 移除 window message 事件监听
79
+ */
80
+ protected _detachMessageListener(): void;
81
+ /**
82
+ * 验证消息源是否被允许
83
+ */
84
+ protected _isAllowedOrigin(origin: string): boolean;
85
+ /**
86
+ * 处理接收到的消息
87
+ */
88
+ protected _handleMessage(event: MessageEvent): void;
89
+ /**
90
+ * 获取目标窗口引用
91
+ */
92
+ protected _getTargetWindow(target: PostMessageTarget): WindowProxy | null;
93
+ /**
94
+ * 构建消息数据
95
+ */
96
+ buildMessage(type: string, data: any): MessageData;
97
+ /**
98
+ * 向指定目标发送消息
99
+ * @param target 目标窗口或标识
100
+ * @param type 事件类型
101
+ * @param args 消息数据
102
+ */
103
+ emitTo<T extends any[]>(target: PostMessageTarget, type: string, ...args: T): void;
104
+ /**
105
+ * 向所有已知子窗口广播消息
106
+ * @param type 事件类型
107
+ * @param args 消息数据
108
+ */
109
+ emitToChildren<T extends any[]>(type: string, ...args: T): void;
110
+ /**
111
+ * 获取当前实例的 sourceId
112
+ */
113
+ getSourceId(): string;
114
+ /**
115
+ * 更新允许的源域名列表
116
+ */
117
+ updateAllowedOrigins(origins: string[]): void;
118
+ /**
119
+ * 添加允许的源域名
120
+ */
121
+ addAllowedOrigin(origin: string): void;
122
+ /**
123
+ * 移除允许的源域名
124
+ */
125
+ removeAllowedOrigin(origin: string): void;
126
+ /**
127
+ * 销毁实例,清理资源
128
+ */
129
+ destroy(): void;
130
+ }
131
+ /**
132
+ * 创建 WindowMessageBus 实例的工厂函数
133
+ */
134
+ export declare function createWindowMessageBus(options?: WindowMessageBusOptions): WindowMessageBus;
135
+ export type { EventHandler };
@@ -0,0 +1 @@
1
+ "use strict";var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};function e(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}var o=function(){return o=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function n(t,e,o,n){return new(o||(o=Promise))((function(e,r){function i(t){try{a(n.next(t))}catch(t){r(t)}}function s(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(i,s)}a((n=n.apply(t,[])).next())}))}function r(t,e){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((r=(r=i.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],n=0}finally{o=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(t,e,o){if(2===arguments.length)for(var n,r=0,i=e.length;r<i;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;var s=function(){function t(t){var e,o;void 0===t&&(t={}),this._events=new Map,this._debug=null!==(e=t.debug)&&void 0!==e&&e,this._debugPrefix=null!==(o=t.debugPrefix)&&void 0!==o?o:"[SampleEventBus]"}return t.prototype.log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this._debug&&console.log.apply(console,i(["".concat((new Date).toLocaleString(),":").concat(this._debugPrefix,": ").concat(t)],e,!1))},t.prototype.enableDebug=function(t){return this._debug=!0,t&&(this._debugPrefix=t),this.log("Debug mode enabled"),this},t.prototype.disableDebug=function(){return this.log("Debug mode disabled"),this._debug=!1,this},t.prototype.isDebugEnabled=function(){return this._debug},t.prototype.on=function(t,e){if("function"!=typeof e)throw new TypeError("Handler must be a function");var o=this._events.get(t);return o?Array.isArray(o)?(o.push(e),this.log("Added listener #".concat(o.length,' for "').concat(t,'"'))):(this._events.set(t,[o,e]),this.log('Converted to multi-listener for "'.concat(t,'", count: 2'))):(this._events.set(t,e),this.log('Registered first listener for "'.concat(t,'"'))),this},t.prototype.emit=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];return n(this,0,void 0,(function(){var o,s,a=this;return r(this,(function(c){switch(c.label){case 0:return(o=this._events.get(t))?(s=Array.isArray(o)?o:[o],this.log.apply(this,i(['Emitting "'.concat(t,'" to ').concat(s.length," listener(s)")],e,!1)),[4,Promise.all(s.map((function(o,i){return n(a,0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.log("Calling listener #".concat(i+1,' for "').concat(t,'"')),[4,o.apply(void 0,e)];case 1:return r.sent(),this.log("Listener #".concat(i+1,' for "').concat(t,'" completed')),[3,3];case 2:return n=r.sent(),console.error("".concat(this._debugPrefix," Error in listener #").concat(i+1,' for "').concat(t,'":'),n),[3,3];case 3:return[2]}}))}))})))]):(this.log('No listeners for "'.concat(t,'", skipping')),[2]);case 1:return c.sent(),this.log('All listeners for "'.concat(t,'" finished')),[2]}}))}))},t.prototype.off=function(t,e){var o=this._events.get(t);if(!o)return this.log('No listeners to remove for "'.concat(t,'"')),this;if(!e){var n=Array.isArray(o)?o.length:1;return this._events.delete(t),this.log("Removed all ".concat(n,' listener(s) for "').concat(t,'"')),this}if("function"==typeof o)o===e?(this._events.delete(t),this.log('Removed only listener for "'.concat(t,'"'))):this.log('Handler not found for "'.concat(t,'"'));else{var r=o.indexOf(e);r>-1?(o.splice(r,1),this.log("Removed listener #".concat(r+1,' for "').concat(t,'", ').concat(o.length," remaining")),0===o.length?(this._events.delete(t),this.log('No more listeners for "'.concat(t,'"'))):1===o.length&&(this._events.set(t,o[0]),this.log('Converted back to single listener for "'.concat(t,'"')))):this.log("Handler not found in ".concat(o.length,' listeners for "').concat(t,'"'))}return this},t.prototype.once=function(t,e){var o=this;if("function"!=typeof e)throw new TypeError("Handler must be a function");this.log('Registering once listener for "'.concat(t,'"'));var i=function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return n(o,0,void 0,(function(){return r(this,(function(o){switch(o.label){case 0:return this.log('Once listener triggered for "'.concat(t,'", removing')),this.off(t,i),[4,e.apply(void 0,s)];case 1:return o.sent(),[2]}}))}))};return this.on(t,i)},t.prototype.has=function(t){var e=this._events.has(t);return this.log('Checking "'.concat(t,'": ').concat(e?"has listeners":"no listeners")),e},t.prototype.listenerCount=function(t){var e=this._events.get(t),o=e?Array.isArray(e)?e.length:1:0;return this.log('Listener count for "'.concat(t,'": ').concat(o)),o},t.prototype.clear=function(){var t=this._events.size;this._events.clear(),this.log("Cleared all ".concat(t," event(s)"))},t}();function a(){return"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9))}var c=function(t){function o(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,debugPrefix:e.debugPrefix||"[WindowMessageBus]"})||this;return o._sourceId=e.sourceId||"wmb-".concat(a().slice(0,8)),o._allowedOrigins=e.allowedOrigins||["*"],o._serialize=e.serialize||JSON.stringify,o._deserialize=e.deserialize||JSON.parse,o._messageHandler=o._handleMessage.bind(o),o._attachMessageListener(),o}return e(o,t),o.prototype._attachMessageListener=function(){"undefined"!=typeof window&&(window.addEventListener("message",this._messageHandler,!1),this.log("Attached to window message event"))},o.prototype._detachMessageListener=function(){"undefined"!=typeof window&&(window.removeEventListener("message",this._messageHandler,!1),this.log("Detached from window message event"))},o.prototype._isAllowedOrigin=function(t){return!!this._allowedOrigins.includes("*")||this._allowedOrigins.includes(t)},o.prototype._handleMessage=function(e){try{var o=e.data,n=e.origin,r=e.source,i=o;if("string"==typeof o)try{i=this._deserialize(o)}catch(t){return void this.log("Failed to deserialize message data:",t)}if(!i||"object"!=typeof i||!("type"in i))return;var s=i;if(r&&!this._isAllowedOrigin(n))return void this.log("Blocked message from disallowed origin: ".concat(n));if(s.sourceId===this._sourceId)return void this.log("Ignored own message: ".concat(s.type));this.log("Received message: ".concat(s.type," from ").concat(n),s.data),t.prototype.emit.call(this,s.type,s.data,{origin:n,source:r,messageId:s.messageId,sourceId:s.sourceId})}catch(t){this.log("Error handling message:",t)}},o.prototype._getTargetWindow=function(t){return"undefined"==typeof window?null:"parent"===t?window.parent:"self"===t?window:"top"===t?window.top:t},o.prototype.buildMessage=function(t,e){return{type:t,data:e,messageId:a(),sourceId:this._sourceId}},o.prototype.emitTo=function(t,e){for(var o,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=this._getTargetWindow(t);if(i){var s=this.buildMessage(e,1===n.length?n[0]:n),a=this._serialize(s);try{var c="*";"string"==typeof t&&("parent"===t&&window.parent.location?c=window.parent.location.origin:"top"===t&&(null===(o=window.top)||void 0===o?void 0:o.location)&&(c=window.top.location.origin)),i.postMessage(a,c),this.log("Sent message: ".concat(e," to ").concat(t),s)}catch(t){throw this.log("Failed to send message: ".concat(e),t),new Error("Failed to post message: ".concat(t))}}else this.log('Cannot send message: no target window for "'.concat(t,'"'))},o.prototype.emitToChildren=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if("undefined"!=typeof window&&window.frames)for(var n=this.buildMessage(t,1===e.length?e[0]:e),r=this._serialize(n),i=0;i<window.frames.length;i++){var s=window.frames[i];if(s&&s!==window)try{s.postMessage(r,"*"),this.log("Broadcasted message: ".concat(t," to frame[").concat(i,"]"),n)}catch(t){this.log("Failed to broadcast to frame[".concat(i,"]"),t)}}},o.prototype.getSourceId=function(){return this._sourceId},o.prototype.updateAllowedOrigins=function(t){this._allowedOrigins=t,this.log("Updated allowed origins: ".concat(t.join(", ")))},o.prototype.addAllowedOrigin=function(t){this._allowedOrigins.includes(t)||(this._allowedOrigins.push(t),this.log("Added allowed origin: ".concat(t)))},o.prototype.removeAllowedOrigin=function(t){var e=this._allowedOrigins.indexOf(t);e>-1&&(this._allowedOrigins.splice(e,1),this.log("Removed allowed origin: ".concat(t)))},o.prototype.destroy=function(){this._detachMessageListener(),this.clear(),this.log("WindowMessageBus destroyed")},o}(s);var l=function(t){function n(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,sourceId:e.sourceId,allowedOrigins:e.allowedOrigins})||this;return"undefined"!=typeof window?o._defaultTarget=window.self!==window.top?"parent":"self":o._defaultTarget="self",o}return e(n,t),n.prototype.getDefaultTarget=function(){return this._defaultTarget},n.prototype.isReady=function(t,e){void 0===t&&(t={});var n=e||this._defaultTarget;this.emitTo(n,"isReady",o({sourceId:this.getSourceId(),timestamp:Date.now()},t))},n.prototype.onReady=function(t){return this._createUnsubscribe("onReady",t)},n.prototype.setData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setData",{data:t,timestamp:Date.now()})},n.prototype.onSetData=function(t){return this._createUnsubscribe("onSetData",(function(e){t(null==e?void 0:e.data)}))},n.prototype.setConfig=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setConfig",{config:t,timestamp:Date.now()})},n.prototype.onSetConfig=function(t){return this._createUnsubscribe("onSetConfig",(function(e){t(null==e?void 0:e.config)}))},n.prototype.change=function(t,e){var n=e||this._defaultTarget;this.emitTo(n,"change",o(o({},t),{timestamp:t.timestamp||Date.now()}))},n.prototype.onChange=function(t){return this._createUnsubscribe("onChange",t)},n.prototype.save=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"save",{options:t,timestamp:Date.now()})},n.prototype.onSave=function(t){return this._createUnsubscribe("onSave",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportSVG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportSVG",{options:t,timestamp:Date.now()})},n.prototype.onExportSVG=function(t){return this._createUnsubscribe("onExportSVG",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportPNG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportPNG",{options:t,timestamp:Date.now()})},n.prototype.onExportPNG=function(t){return this._createUnsubscribe("onExportPNG",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportData",{options:t,timestamp:Date.now()})},n.prototype.onExportData=function(t){return this._createUnsubscribe("onExportData",(function(e){t(null==e?void 0:e.options)}))},n.prototype.getData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"getData",{options:t,timestamp:Date.now()})},n.prototype.onGetData=function(t){return this._createUnsubscribe("onGetData",(function(e){t(null==e?void 0:e.options)}))},n.prototype.thumnail=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"thumnail",{options:t,timestamp:Date.now()})},n.prototype.onThumnail=function(t){return this._createUnsubscribe("onThumnail",(function(e){t(null==e?void 0:e.options)}))},n.prototype.preview=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"preview",{options:t,timestamp:Date.now()})},n.prototype.onPreview=function(t){return this._createUnsubscribe("onPreview",(function(e){t(null==e?void 0:e.options)}))},n.prototype._createUnsubscribe=function(t,e){var o=e;this.on(t,o);var n=!1,r=o;return this.on(t,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!n)return r.apply(this,t)})),function(){n=!0}},n.prototype.destroy=function(){t.prototype.destroy.call(this),this.isDebugEnabled()&&console.log("".concat((new Date).toLocaleString(),":[EditorMessageBus]: EditorMessageBus destroyed"))},n}(c);exports.EditorMessageBus=l,exports.WindowMessageBus=c,exports.createEditorMessageBus=function(t){return new l(t)},exports.createWindowMessageBus=function(t){return new c(t)};
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { WindowMessageBus, createWindowMessageBus } from './WindowMessageBus';
2
+ export type { MessageData, WindowMessageBusOptions, PostMessageTarget, MessageContext, EventHandler } from './WindowMessageBus';
3
+ export { EditorMessageBus, createEditorMessageBus } from './EditorMessageBus';
4
+ export type { EditorMessageType, EditorData, EditorConfig, EditorChangeData, ExportOptions, ThumbnailOptions, PreviewOptions, EditorMessageBusOptions, } from './EditorMessageBus';
@@ -0,0 +1 @@
1
+ var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};function e(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}var o=function(){return o=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function n(t,e,o,n){return new(o||(o=Promise))((function(e,r){function i(t){try{a(n.next(t))}catch(t){r(t)}}function s(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(i,s)}a((n=n.apply(t,[])).next())}))}function r(t,e){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((r=(r=i.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],n=0}finally{o=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(t,e,o){if(2===arguments.length)for(var n,r=0,i=e.length;r<i;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;var s=function(){function t(t){var e,o;void 0===t&&(t={}),this._events=new Map,this._debug=null!==(e=t.debug)&&void 0!==e&&e,this._debugPrefix=null!==(o=t.debugPrefix)&&void 0!==o?o:"[SampleEventBus]"}return t.prototype.log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this._debug&&console.log.apply(console,i(["".concat((new Date).toLocaleString(),":").concat(this._debugPrefix,": ").concat(t)],e,!1))},t.prototype.enableDebug=function(t){return this._debug=!0,t&&(this._debugPrefix=t),this.log("Debug mode enabled"),this},t.prototype.disableDebug=function(){return this.log("Debug mode disabled"),this._debug=!1,this},t.prototype.isDebugEnabled=function(){return this._debug},t.prototype.on=function(t,e){if("function"!=typeof e)throw new TypeError("Handler must be a function");var o=this._events.get(t);return o?Array.isArray(o)?(o.push(e),this.log("Added listener #".concat(o.length,' for "').concat(t,'"'))):(this._events.set(t,[o,e]),this.log('Converted to multi-listener for "'.concat(t,'", count: 2'))):(this._events.set(t,e),this.log('Registered first listener for "'.concat(t,'"'))),this},t.prototype.emit=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];return n(this,0,void 0,(function(){var o,s,a=this;return r(this,(function(c){switch(c.label){case 0:return(o=this._events.get(t))?(s=Array.isArray(o)?o:[o],this.log.apply(this,i(['Emitting "'.concat(t,'" to ').concat(s.length," listener(s)")],e,!1)),[4,Promise.all(s.map((function(o,i){return n(a,0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.log("Calling listener #".concat(i+1,' for "').concat(t,'"')),[4,o.apply(void 0,e)];case 1:return r.sent(),this.log("Listener #".concat(i+1,' for "').concat(t,'" completed')),[3,3];case 2:return n=r.sent(),console.error("".concat(this._debugPrefix," Error in listener #").concat(i+1,' for "').concat(t,'":'),n),[3,3];case 3:return[2]}}))}))})))]):(this.log('No listeners for "'.concat(t,'", skipping')),[2]);case 1:return c.sent(),this.log('All listeners for "'.concat(t,'" finished')),[2]}}))}))},t.prototype.off=function(t,e){var o=this._events.get(t);if(!o)return this.log('No listeners to remove for "'.concat(t,'"')),this;if(!e){var n=Array.isArray(o)?o.length:1;return this._events.delete(t),this.log("Removed all ".concat(n,' listener(s) for "').concat(t,'"')),this}if("function"==typeof o)o===e?(this._events.delete(t),this.log('Removed only listener for "'.concat(t,'"'))):this.log('Handler not found for "'.concat(t,'"'));else{var r=o.indexOf(e);r>-1?(o.splice(r,1),this.log("Removed listener #".concat(r+1,' for "').concat(t,'", ').concat(o.length," remaining")),0===o.length?(this._events.delete(t),this.log('No more listeners for "'.concat(t,'"'))):1===o.length&&(this._events.set(t,o[0]),this.log('Converted back to single listener for "'.concat(t,'"')))):this.log("Handler not found in ".concat(o.length,' listeners for "').concat(t,'"'))}return this},t.prototype.once=function(t,e){var o=this;if("function"!=typeof e)throw new TypeError("Handler must be a function");this.log('Registering once listener for "'.concat(t,'"'));var i=function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return n(o,0,void 0,(function(){return r(this,(function(o){switch(o.label){case 0:return this.log('Once listener triggered for "'.concat(t,'", removing')),this.off(t,i),[4,e.apply(void 0,s)];case 1:return o.sent(),[2]}}))}))};return this.on(t,i)},t.prototype.has=function(t){var e=this._events.has(t);return this.log('Checking "'.concat(t,'": ').concat(e?"has listeners":"no listeners")),e},t.prototype.listenerCount=function(t){var e=this._events.get(t),o=e?Array.isArray(e)?e.length:1:0;return this.log('Listener count for "'.concat(t,'": ').concat(o)),o},t.prototype.clear=function(){var t=this._events.size;this._events.clear(),this.log("Cleared all ".concat(t," event(s)"))},t}();function a(){return"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9))}var c=function(t){function o(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,debugPrefix:e.debugPrefix||"[WindowMessageBus]"})||this;return o._sourceId=e.sourceId||"wmb-".concat(a().slice(0,8)),o._allowedOrigins=e.allowedOrigins||["*"],o._serialize=e.serialize||JSON.stringify,o._deserialize=e.deserialize||JSON.parse,o._messageHandler=o._handleMessage.bind(o),o._attachMessageListener(),o}return e(o,t),o.prototype._attachMessageListener=function(){"undefined"!=typeof window&&(window.addEventListener("message",this._messageHandler,!1),this.log("Attached to window message event"))},o.prototype._detachMessageListener=function(){"undefined"!=typeof window&&(window.removeEventListener("message",this._messageHandler,!1),this.log("Detached from window message event"))},o.prototype._isAllowedOrigin=function(t){return!!this._allowedOrigins.includes("*")||this._allowedOrigins.includes(t)},o.prototype._handleMessage=function(e){try{var o=e.data,n=e.origin,r=e.source,i=o;if("string"==typeof o)try{i=this._deserialize(o)}catch(t){return void this.log("Failed to deserialize message data:",t)}if(!i||"object"!=typeof i||!("type"in i))return;var s=i;if(r&&!this._isAllowedOrigin(n))return void this.log("Blocked message from disallowed origin: ".concat(n));if(s.sourceId===this._sourceId)return void this.log("Ignored own message: ".concat(s.type));this.log("Received message: ".concat(s.type," from ").concat(n),s.data),t.prototype.emit.call(this,s.type,s.data,{origin:n,source:r,messageId:s.messageId,sourceId:s.sourceId})}catch(t){this.log("Error handling message:",t)}},o.prototype._getTargetWindow=function(t){return"undefined"==typeof window?null:"parent"===t?window.parent:"self"===t?window:"top"===t?window.top:t},o.prototype.buildMessage=function(t,e){return{type:t,data:e,messageId:a(),sourceId:this._sourceId}},o.prototype.emitTo=function(t,e){for(var o,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=this._getTargetWindow(t);if(i){var s=this.buildMessage(e,1===n.length?n[0]:n),a=this._serialize(s);try{var c="*";"string"==typeof t&&("parent"===t&&window.parent.location?c=window.parent.location.origin:"top"===t&&(null===(o=window.top)||void 0===o?void 0:o.location)&&(c=window.top.location.origin)),i.postMessage(a,c),this.log("Sent message: ".concat(e," to ").concat(t),s)}catch(t){throw this.log("Failed to send message: ".concat(e),t),new Error("Failed to post message: ".concat(t))}}else this.log('Cannot send message: no target window for "'.concat(t,'"'))},o.prototype.emitToChildren=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if("undefined"!=typeof window&&window.frames)for(var n=this.buildMessage(t,1===e.length?e[0]:e),r=this._serialize(n),i=0;i<window.frames.length;i++){var s=window.frames[i];if(s&&s!==window)try{s.postMessage(r,"*"),this.log("Broadcasted message: ".concat(t," to frame[").concat(i,"]"),n)}catch(t){this.log("Failed to broadcast to frame[".concat(i,"]"),t)}}},o.prototype.getSourceId=function(){return this._sourceId},o.prototype.updateAllowedOrigins=function(t){this._allowedOrigins=t,this.log("Updated allowed origins: ".concat(t.join(", ")))},o.prototype.addAllowedOrigin=function(t){this._allowedOrigins.includes(t)||(this._allowedOrigins.push(t),this.log("Added allowed origin: ".concat(t)))},o.prototype.removeAllowedOrigin=function(t){var e=this._allowedOrigins.indexOf(t);e>-1&&(this._allowedOrigins.splice(e,1),this.log("Removed allowed origin: ".concat(t)))},o.prototype.destroy=function(){this._detachMessageListener(),this.clear(),this.log("WindowMessageBus destroyed")},o}(s);function l(t){return new c(t)}var u=function(t){function n(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,sourceId:e.sourceId,allowedOrigins:e.allowedOrigins})||this;return"undefined"!=typeof window?o._defaultTarget=window.self!==window.top?"parent":"self":o._defaultTarget="self",o}return e(n,t),n.prototype.getDefaultTarget=function(){return this._defaultTarget},n.prototype.isReady=function(t,e){void 0===t&&(t={});var n=e||this._defaultTarget;this.emitTo(n,"isReady",o({sourceId:this.getSourceId(),timestamp:Date.now()},t))},n.prototype.onReady=function(t){return this._createUnsubscribe("onReady",t)},n.prototype.setData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setData",{data:t,timestamp:Date.now()})},n.prototype.onSetData=function(t){return this._createUnsubscribe("onSetData",(function(e){t(null==e?void 0:e.data)}))},n.prototype.setConfig=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setConfig",{config:t,timestamp:Date.now()})},n.prototype.onSetConfig=function(t){return this._createUnsubscribe("onSetConfig",(function(e){t(null==e?void 0:e.config)}))},n.prototype.change=function(t,e){var n=e||this._defaultTarget;this.emitTo(n,"change",o(o({},t),{timestamp:t.timestamp||Date.now()}))},n.prototype.onChange=function(t){return this._createUnsubscribe("onChange",t)},n.prototype.save=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"save",{options:t,timestamp:Date.now()})},n.prototype.onSave=function(t){return this._createUnsubscribe("onSave",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportSVG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportSVG",{options:t,timestamp:Date.now()})},n.prototype.onExportSVG=function(t){return this._createUnsubscribe("onExportSVG",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportPNG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportPNG",{options:t,timestamp:Date.now()})},n.prototype.onExportPNG=function(t){return this._createUnsubscribe("onExportPNG",(function(e){t(null==e?void 0:e.options)}))},n.prototype.exportData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportData",{options:t,timestamp:Date.now()})},n.prototype.onExportData=function(t){return this._createUnsubscribe("onExportData",(function(e){t(null==e?void 0:e.options)}))},n.prototype.getData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"getData",{options:t,timestamp:Date.now()})},n.prototype.onGetData=function(t){return this._createUnsubscribe("onGetData",(function(e){t(null==e?void 0:e.options)}))},n.prototype.thumnail=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"thumnail",{options:t,timestamp:Date.now()})},n.prototype.onThumnail=function(t){return this._createUnsubscribe("onThumnail",(function(e){t(null==e?void 0:e.options)}))},n.prototype.preview=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"preview",{options:t,timestamp:Date.now()})},n.prototype.onPreview=function(t){return this._createUnsubscribe("onPreview",(function(e){t(null==e?void 0:e.options)}))},n.prototype._createUnsubscribe=function(t,e){var o=e;this.on(t,o);var n=!1,r=o;return this.on(t,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!n)return r.apply(this,t)})),function(){n=!0}},n.prototype.destroy=function(){t.prototype.destroy.call(this),this.isDebugEnabled()&&console.log("".concat((new Date).toLocaleString(),":[EditorMessageBus]: EditorMessageBus destroyed"))},n}(c);function p(t){return new u(t)}export{u as EditorMessageBus,c as WindowMessageBus,p as createEditorMessageBus,l as createWindowMessageBus};
@@ -0,0 +1 @@
1
+ !function(t){"use strict";var e=function(t,o){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},e(t,o)};function o(t,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};function r(t,e,o,n){return new(o||(o=Promise))((function(e,r){function i(t){try{a(n.next(t))}catch(t){r(t)}}function s(t){try{a(n.throw(t))}catch(t){r(t)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(i,s)}a((n=n.apply(t,[])).next())}))}function i(t,e){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((r=(r=i.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],n=0}finally{o=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function s(t,e,o){if(2===arguments.length)for(var n,r=0,i=e.length;r<i;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;var a=function(){function t(t){var e,o;void 0===t&&(t={}),this._events=new Map,this._debug=null!==(e=t.debug)&&void 0!==e&&e,this._debugPrefix=null!==(o=t.debugPrefix)&&void 0!==o?o:"[SampleEventBus]"}return t.prototype.log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this._debug&&console.log.apply(console,s(["".concat((new Date).toLocaleString(),":").concat(this._debugPrefix,": ").concat(t)],e,!1))},t.prototype.enableDebug=function(t){return this._debug=!0,t&&(this._debugPrefix=t),this.log("Debug mode enabled"),this},t.prototype.disableDebug=function(){return this.log("Debug mode disabled"),this._debug=!1,this},t.prototype.isDebugEnabled=function(){return this._debug},t.prototype.on=function(t,e){if("function"!=typeof e)throw new TypeError("Handler must be a function");var o=this._events.get(t);return o?Array.isArray(o)?(o.push(e),this.log("Added listener #".concat(o.length,' for "').concat(t,'"'))):(this._events.set(t,[o,e]),this.log('Converted to multi-listener for "'.concat(t,'", count: 2'))):(this._events.set(t,e),this.log('Registered first listener for "'.concat(t,'"'))),this},t.prototype.emit=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];return r(this,0,void 0,(function(){var o,n,a=this;return i(this,(function(c){switch(c.label){case 0:return(o=this._events.get(t))?(n=Array.isArray(o)?o:[o],this.log.apply(this,s(['Emitting "'.concat(t,'" to ').concat(n.length," listener(s)")],e,!1)),[4,Promise.all(n.map((function(o,n){return r(a,0,void 0,(function(){var r;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),this.log("Calling listener #".concat(n+1,' for "').concat(t,'"')),[4,o.apply(void 0,e)];case 1:return i.sent(),this.log("Listener #".concat(n+1,' for "').concat(t,'" completed')),[3,3];case 2:return r=i.sent(),console.error("".concat(this._debugPrefix," Error in listener #").concat(n+1,' for "').concat(t,'":'),r),[3,3];case 3:return[2]}}))}))})))]):(this.log('No listeners for "'.concat(t,'", skipping')),[2]);case 1:return c.sent(),this.log('All listeners for "'.concat(t,'" finished')),[2]}}))}))},t.prototype.off=function(t,e){var o=this._events.get(t);if(!o)return this.log('No listeners to remove for "'.concat(t,'"')),this;if(!e){var n=Array.isArray(o)?o.length:1;return this._events.delete(t),this.log("Removed all ".concat(n,' listener(s) for "').concat(t,'"')),this}if("function"==typeof o)o===e?(this._events.delete(t),this.log('Removed only listener for "'.concat(t,'"'))):this.log('Handler not found for "'.concat(t,'"'));else{var r=o.indexOf(e);r>-1?(o.splice(r,1),this.log("Removed listener #".concat(r+1,' for "').concat(t,'", ').concat(o.length," remaining")),0===o.length?(this._events.delete(t),this.log('No more listeners for "'.concat(t,'"'))):1===o.length&&(this._events.set(t,o[0]),this.log('Converted back to single listener for "'.concat(t,'"')))):this.log("Handler not found in ".concat(o.length,' listeners for "').concat(t,'"'))}return this},t.prototype.once=function(t,e){var o=this;if("function"!=typeof e)throw new TypeError("Handler must be a function");this.log('Registering once listener for "'.concat(t,'"'));var n=function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return r(o,0,void 0,(function(){return i(this,(function(o){switch(o.label){case 0:return this.log('Once listener triggered for "'.concat(t,'", removing')),this.off(t,n),[4,e.apply(void 0,s)];case 1:return o.sent(),[2]}}))}))};return this.on(t,n)},t.prototype.has=function(t){var e=this._events.has(t);return this.log('Checking "'.concat(t,'": ').concat(e?"has listeners":"no listeners")),e},t.prototype.listenerCount=function(t){var e=this._events.get(t),o=e?Array.isArray(e)?e.length:1:0;return this.log('Listener count for "'.concat(t,'": ').concat(o)),o},t.prototype.clear=function(){var t=this._events.size;this._events.clear(),this.log("Cleared all ".concat(t," event(s)"))},t}();function c(){return"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9))}var l=function(t){function e(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,debugPrefix:e.debugPrefix||"[WindowMessageBus]"})||this;return o._sourceId=e.sourceId||"wmb-".concat(c().slice(0,8)),o._allowedOrigins=e.allowedOrigins||["*"],o._serialize=e.serialize||JSON.stringify,o._deserialize=e.deserialize||JSON.parse,o._messageHandler=o._handleMessage.bind(o),o._attachMessageListener(),o}return o(e,t),e.prototype._attachMessageListener=function(){"undefined"!=typeof window&&(window.addEventListener("message",this._messageHandler,!1),this.log("Attached to window message event"))},e.prototype._detachMessageListener=function(){"undefined"!=typeof window&&(window.removeEventListener("message",this._messageHandler,!1),this.log("Detached from window message event"))},e.prototype._isAllowedOrigin=function(t){return!!this._allowedOrigins.includes("*")||this._allowedOrigins.includes(t)},e.prototype._handleMessage=function(e){try{var o=e.data,n=e.origin,r=e.source,i=o;if("string"==typeof o)try{i=this._deserialize(o)}catch(t){return void this.log("Failed to deserialize message data:",t)}if(!i||"object"!=typeof i||!("type"in i))return;var s=i;if(r&&!this._isAllowedOrigin(n))return void this.log("Blocked message from disallowed origin: ".concat(n));if(s.sourceId===this._sourceId)return void this.log("Ignored own message: ".concat(s.type));this.log("Received message: ".concat(s.type," from ").concat(n),s.data),t.prototype.emit.call(this,s.type,s.data,{origin:n,source:r,messageId:s.messageId,sourceId:s.sourceId})}catch(t){this.log("Error handling message:",t)}},e.prototype._getTargetWindow=function(t){return"undefined"==typeof window?null:"parent"===t?window.parent:"self"===t?window:"top"===t?window.top:t},e.prototype.buildMessage=function(t,e){return{type:t,data:e,messageId:c(),sourceId:this._sourceId}},e.prototype.emitTo=function(t,e){for(var o,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=this._getTargetWindow(t);if(i){var s=this.buildMessage(e,1===n.length?n[0]:n),a=this._serialize(s);try{var c="*";"string"==typeof t&&("parent"===t&&window.parent.location?c=window.parent.location.origin:"top"===t&&(null===(o=window.top)||void 0===o?void 0:o.location)&&(c=window.top.location.origin)),i.postMessage(a,c),this.log("Sent message: ".concat(e," to ").concat(t),s)}catch(t){throw this.log("Failed to send message: ".concat(e),t),new Error("Failed to post message: ".concat(t))}}else this.log('Cannot send message: no target window for "'.concat(t,'"'))},e.prototype.emitToChildren=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if("undefined"!=typeof window&&window.frames)for(var n=this.buildMessage(t,1===e.length?e[0]:e),r=this._serialize(n),i=0;i<window.frames.length;i++){var s=window.frames[i];if(s&&s!==window)try{s.postMessage(r,"*"),this.log("Broadcasted message: ".concat(t," to frame[").concat(i,"]"),n)}catch(t){this.log("Failed to broadcast to frame[".concat(i,"]"),t)}}},e.prototype.getSourceId=function(){return this._sourceId},e.prototype.updateAllowedOrigins=function(t){this._allowedOrigins=t,this.log("Updated allowed origins: ".concat(t.join(", ")))},e.prototype.addAllowedOrigin=function(t){this._allowedOrigins.includes(t)||(this._allowedOrigins.push(t),this.log("Added allowed origin: ".concat(t)))},e.prototype.removeAllowedOrigin=function(t){var e=this._allowedOrigins.indexOf(t);e>-1&&(this._allowedOrigins.splice(e,1),this.log("Removed allowed origin: ".concat(t)))},e.prototype.destroy=function(){this._detachMessageListener(),this.clear(),this.log("WindowMessageBus destroyed")},e}(a);var u=function(t){function e(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,sourceId:e.sourceId,allowedOrigins:e.allowedOrigins})||this;return"undefined"!=typeof window?o._defaultTarget=window.self!==window.top?"parent":"self":o._defaultTarget="self",o}return o(e,t),e.prototype.getDefaultTarget=function(){return this._defaultTarget},e.prototype.isReady=function(t,e){void 0===t&&(t={});var o=e||this._defaultTarget;this.emitTo(o,"isReady",n({sourceId:this.getSourceId(),timestamp:Date.now()},t))},e.prototype.onReady=function(t){return this._createUnsubscribe("onReady",t)},e.prototype.setData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setData",{data:t,timestamp:Date.now()})},e.prototype.onSetData=function(t){return this._createUnsubscribe("onSetData",(function(e){t(null==e?void 0:e.data)}))},e.prototype.setConfig=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setConfig",{config:t,timestamp:Date.now()})},e.prototype.onSetConfig=function(t){return this._createUnsubscribe("onSetConfig",(function(e){t(null==e?void 0:e.config)}))},e.prototype.change=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"change",n(n({},t),{timestamp:t.timestamp||Date.now()}))},e.prototype.onChange=function(t){return this._createUnsubscribe("onChange",t)},e.prototype.save=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"save",{options:t,timestamp:Date.now()})},e.prototype.onSave=function(t){return this._createUnsubscribe("onSave",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportSVG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportSVG",{options:t,timestamp:Date.now()})},e.prototype.onExportSVG=function(t){return this._createUnsubscribe("onExportSVG",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportPNG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportPNG",{options:t,timestamp:Date.now()})},e.prototype.onExportPNG=function(t){return this._createUnsubscribe("onExportPNG",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportData",{options:t,timestamp:Date.now()})},e.prototype.onExportData=function(t){return this._createUnsubscribe("onExportData",(function(e){t(null==e?void 0:e.options)}))},e.prototype.getData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"getData",{options:t,timestamp:Date.now()})},e.prototype.onGetData=function(t){return this._createUnsubscribe("onGetData",(function(e){t(null==e?void 0:e.options)}))},e.prototype.thumnail=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"thumnail",{options:t,timestamp:Date.now()})},e.prototype.onThumnail=function(t){return this._createUnsubscribe("onThumnail",(function(e){t(null==e?void 0:e.options)}))},e.prototype.preview=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"preview",{options:t,timestamp:Date.now()})},e.prototype.onPreview=function(t){return this._createUnsubscribe("onPreview",(function(e){t(null==e?void 0:e.options)}))},e.prototype._createUnsubscribe=function(t,e){var o=e;this.on(t,o);var n=!1,r=o;return this.on(t,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!n)return r.apply(this,t)})),function(){n=!0}},e.prototype.destroy=function(){t.prototype.destroy.call(this),this.isDebugEnabled()&&console.log("".concat((new Date).toLocaleString(),":[EditorMessageBus]: EditorMessageBus destroyed"))},e}(l);t.EditorMessageBus=u,t.WindowMessageBus=l,t.createEditorMessageBus=function(t){return new u(t)},t.createWindowMessageBus=function(t){return new l(t)}}({});
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WindowMessageBus={})}(this,(function(t){"use strict";var e=function(t,o){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},e(t,o)};function o(t,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function i(t,e,o,n){return new(o||(o=Promise))((function(e,i){function r(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(r,s)}a((n=n.apply(t,[])).next())}))}function r(t,e){var o,n,i,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(r=0)),r;)try{if(o=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!((i=(i=r.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(6===a[0]&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(t){a=[6,t],n=0}finally{o=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function s(t,e,o){if(2===arguments.length)for(var n,i=0,r=e.length;i<r;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;var a=function(){function t(t){var e,o;void 0===t&&(t={}),this._events=new Map,this._debug=null!==(e=t.debug)&&void 0!==e&&e,this._debugPrefix=null!==(o=t.debugPrefix)&&void 0!==o?o:"[SampleEventBus]"}return t.prototype.log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this._debug&&console.log.apply(console,s(["".concat((new Date).toLocaleString(),":").concat(this._debugPrefix,": ").concat(t)],e,!1))},t.prototype.enableDebug=function(t){return this._debug=!0,t&&(this._debugPrefix=t),this.log("Debug mode enabled"),this},t.prototype.disableDebug=function(){return this.log("Debug mode disabled"),this._debug=!1,this},t.prototype.isDebugEnabled=function(){return this._debug},t.prototype.on=function(t,e){if("function"!=typeof e)throw new TypeError("Handler must be a function");var o=this._events.get(t);return o?Array.isArray(o)?(o.push(e),this.log("Added listener #".concat(o.length,' for "').concat(t,'"'))):(this._events.set(t,[o,e]),this.log('Converted to multi-listener for "'.concat(t,'", count: 2'))):(this._events.set(t,e),this.log('Registered first listener for "'.concat(t,'"'))),this},t.prototype.emit=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];return i(this,0,void 0,(function(){var o,n,a=this;return r(this,(function(c){switch(c.label){case 0:return(o=this._events.get(t))?(n=Array.isArray(o)?o:[o],this.log.apply(this,s(['Emitting "'.concat(t,'" to ').concat(n.length," listener(s)")],e,!1)),[4,Promise.all(n.map((function(o,n){return i(a,0,void 0,(function(){var i;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.log("Calling listener #".concat(n+1,' for "').concat(t,'"')),[4,o.apply(void 0,e)];case 1:return r.sent(),this.log("Listener #".concat(n+1,' for "').concat(t,'" completed')),[3,3];case 2:return i=r.sent(),console.error("".concat(this._debugPrefix," Error in listener #").concat(n+1,' for "').concat(t,'":'),i),[3,3];case 3:return[2]}}))}))})))]):(this.log('No listeners for "'.concat(t,'", skipping')),[2]);case 1:return c.sent(),this.log('All listeners for "'.concat(t,'" finished')),[2]}}))}))},t.prototype.off=function(t,e){var o=this._events.get(t);if(!o)return this.log('No listeners to remove for "'.concat(t,'"')),this;if(!e){var n=Array.isArray(o)?o.length:1;return this._events.delete(t),this.log("Removed all ".concat(n,' listener(s) for "').concat(t,'"')),this}if("function"==typeof o)o===e?(this._events.delete(t),this.log('Removed only listener for "'.concat(t,'"'))):this.log('Handler not found for "'.concat(t,'"'));else{var i=o.indexOf(e);i>-1?(o.splice(i,1),this.log("Removed listener #".concat(i+1,' for "').concat(t,'", ').concat(o.length," remaining")),0===o.length?(this._events.delete(t),this.log('No more listeners for "'.concat(t,'"'))):1===o.length&&(this._events.set(t,o[0]),this.log('Converted back to single listener for "'.concat(t,'"')))):this.log("Handler not found in ".concat(o.length,' listeners for "').concat(t,'"'))}return this},t.prototype.once=function(t,e){var o=this;if("function"!=typeof e)throw new TypeError("Handler must be a function");this.log('Registering once listener for "'.concat(t,'"'));var n=function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return i(o,0,void 0,(function(){return r(this,(function(o){switch(o.label){case 0:return this.log('Once listener triggered for "'.concat(t,'", removing')),this.off(t,n),[4,e.apply(void 0,s)];case 1:return o.sent(),[2]}}))}))};return this.on(t,n)},t.prototype.has=function(t){var e=this._events.has(t);return this.log('Checking "'.concat(t,'": ').concat(e?"has listeners":"no listeners")),e},t.prototype.listenerCount=function(t){var e=this._events.get(t),o=e?Array.isArray(e)?e.length:1:0;return this.log('Listener count for "'.concat(t,'": ').concat(o)),o},t.prototype.clear=function(){var t=this._events.size;this._events.clear(),this.log("Cleared all ".concat(t," event(s)"))},t}();function c(){return"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9))}var l=function(t){function e(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,debugPrefix:e.debugPrefix||"[WindowMessageBus]"})||this;return o._sourceId=e.sourceId||"wmb-".concat(c().slice(0,8)),o._allowedOrigins=e.allowedOrigins||["*"],o._serialize=e.serialize||JSON.stringify,o._deserialize=e.deserialize||JSON.parse,o._messageHandler=o._handleMessage.bind(o),o._attachMessageListener(),o}return o(e,t),e.prototype._attachMessageListener=function(){"undefined"!=typeof window&&(window.addEventListener("message",this._messageHandler,!1),this.log("Attached to window message event"))},e.prototype._detachMessageListener=function(){"undefined"!=typeof window&&(window.removeEventListener("message",this._messageHandler,!1),this.log("Detached from window message event"))},e.prototype._isAllowedOrigin=function(t){return!!this._allowedOrigins.includes("*")||this._allowedOrigins.includes(t)},e.prototype._handleMessage=function(e){try{var o=e.data,n=e.origin,i=e.source,r=o;if("string"==typeof o)try{r=this._deserialize(o)}catch(t){return void this.log("Failed to deserialize message data:",t)}if(!r||"object"!=typeof r||!("type"in r))return;var s=r;if(i&&!this._isAllowedOrigin(n))return void this.log("Blocked message from disallowed origin: ".concat(n));if(s.sourceId===this._sourceId)return void this.log("Ignored own message: ".concat(s.type));this.log("Received message: ".concat(s.type," from ").concat(n),s.data),t.prototype.emit.call(this,s.type,s.data,{origin:n,source:i,messageId:s.messageId,sourceId:s.sourceId})}catch(t){this.log("Error handling message:",t)}},e.prototype._getTargetWindow=function(t){return"undefined"==typeof window?null:"parent"===t?window.parent:"self"===t?window:"top"===t?window.top:t},e.prototype.buildMessage=function(t,e){return{type:t,data:e,messageId:c(),sourceId:this._sourceId}},e.prototype.emitTo=function(t,e){for(var o,n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];var r=this._getTargetWindow(t);if(r){var s=this.buildMessage(e,1===n.length?n[0]:n),a=this._serialize(s);try{var c="*";"string"==typeof t&&("parent"===t&&window.parent.location?c=window.parent.location.origin:"top"===t&&(null===(o=window.top)||void 0===o?void 0:o.location)&&(c=window.top.location.origin)),r.postMessage(a,c),this.log("Sent message: ".concat(e," to ").concat(t),s)}catch(t){throw this.log("Failed to send message: ".concat(e),t),new Error("Failed to post message: ".concat(t))}}else this.log('Cannot send message: no target window for "'.concat(t,'"'))},e.prototype.emitToChildren=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if("undefined"!=typeof window&&window.frames)for(var n=this.buildMessage(t,1===e.length?e[0]:e),i=this._serialize(n),r=0;r<window.frames.length;r++){var s=window.frames[r];if(s&&s!==window)try{s.postMessage(i,"*"),this.log("Broadcasted message: ".concat(t," to frame[").concat(r,"]"),n)}catch(t){this.log("Failed to broadcast to frame[".concat(r,"]"),t)}}},e.prototype.getSourceId=function(){return this._sourceId},e.prototype.updateAllowedOrigins=function(t){this._allowedOrigins=t,this.log("Updated allowed origins: ".concat(t.join(", ")))},e.prototype.addAllowedOrigin=function(t){this._allowedOrigins.includes(t)||(this._allowedOrigins.push(t),this.log("Added allowed origin: ".concat(t)))},e.prototype.removeAllowedOrigin=function(t){var e=this._allowedOrigins.indexOf(t);e>-1&&(this._allowedOrigins.splice(e,1),this.log("Removed allowed origin: ".concat(t)))},e.prototype.destroy=function(){this._detachMessageListener(),this.clear(),this.log("WindowMessageBus destroyed")},e}(a);var u=function(t){function e(e){void 0===e&&(e={});var o=t.call(this,{debug:e.debug,sourceId:e.sourceId,allowedOrigins:e.allowedOrigins})||this;return"undefined"!=typeof window?o._defaultTarget=window.self!==window.top?"parent":"self":o._defaultTarget="self",o}return o(e,t),e.prototype.getDefaultTarget=function(){return this._defaultTarget},e.prototype.isReady=function(t,e){void 0===t&&(t={});var o=e||this._defaultTarget;this.emitTo(o,"isReady",n({sourceId:this.getSourceId(),timestamp:Date.now()},t))},e.prototype.onReady=function(t){return this._createUnsubscribe("onReady",t)},e.prototype.setData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setData",{data:t,timestamp:Date.now()})},e.prototype.onSetData=function(t){return this._createUnsubscribe("onSetData",(function(e){t(null==e?void 0:e.data)}))},e.prototype.setConfig=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"setConfig",{config:t,timestamp:Date.now()})},e.prototype.onSetConfig=function(t){return this._createUnsubscribe("onSetConfig",(function(e){t(null==e?void 0:e.config)}))},e.prototype.change=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"change",n(n({},t),{timestamp:t.timestamp||Date.now()}))},e.prototype.onChange=function(t){return this._createUnsubscribe("onChange",t)},e.prototype.save=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"save",{options:t,timestamp:Date.now()})},e.prototype.onSave=function(t){return this._createUnsubscribe("onSave",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportSVG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportSVG",{options:t,timestamp:Date.now()})},e.prototype.onExportSVG=function(t){return this._createUnsubscribe("onExportSVG",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportPNG=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportPNG",{options:t,timestamp:Date.now()})},e.prototype.onExportPNG=function(t){return this._createUnsubscribe("onExportPNG",(function(e){t(null==e?void 0:e.options)}))},e.prototype.exportData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"exportData",{options:t,timestamp:Date.now()})},e.prototype.onExportData=function(t){return this._createUnsubscribe("onExportData",(function(e){t(null==e?void 0:e.options)}))},e.prototype.getData=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"getData",{options:t,timestamp:Date.now()})},e.prototype.onGetData=function(t){return this._createUnsubscribe("onGetData",(function(e){t(null==e?void 0:e.options)}))},e.prototype.thumnail=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"thumnail",{options:t,timestamp:Date.now()})},e.prototype.onThumnail=function(t){return this._createUnsubscribe("onThumnail",(function(e){t(null==e?void 0:e.options)}))},e.prototype.preview=function(t,e){var o=e||this._defaultTarget;this.emitTo(o,"preview",{options:t,timestamp:Date.now()})},e.prototype.onPreview=function(t){return this._createUnsubscribe("onPreview",(function(e){t(null==e?void 0:e.options)}))},e.prototype._createUnsubscribe=function(t,e){var o=e;this.on(t,o);var n=!1,i=o;return this.on(t,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!n)return i.apply(this,t)})),function(){n=!0}},e.prototype.destroy=function(){t.prototype.destroy.call(this),this.isDebugEnabled()&&console.log("".concat((new Date).toLocaleString(),":[EditorMessageBus]: EditorMessageBus destroyed"))},e}(l);t.EditorMessageBus=u,t.WindowMessageBus=l,t.createEditorMessageBus=function(t){return new u(t)},t.createWindowMessageBus=function(t){return new l(t)}}));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.35.0_tslib@2.8.1_typescript@5.8.2/node_modules/tslib/tslib.es6.js","../node_modules/.pnpm/@iss-ai+sample-event-bus@0.0.2/node_modules/@iss-ai/sample-event-bus/lib/index.esm.js","../src/WindowMessageBus.ts","../src/EditorMessageBus.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\r\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\r\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nvar ownKeys = function(o) {\r\n ownKeys = Object.getOwnPropertyNames || function (o) {\r\n var ar = [];\r\n for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;\r\n return ar;\r\n };\r\n return ownKeys(o);\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== \"default\") __createBinding(result, mod, k[i]);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose, inner;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n if (async) inner = dispose;\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n var r, s = 0;\r\n function next() {\r\n while (r = env.stack.pop()) {\r\n try {\r\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\r\n if (r.dispose) {\r\n var result = r.dispose.call(r.value);\r\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n else s |= 1;\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport function __rewriteRelativeImportExtension(path, preserveJsx) {\r\n if (typeof path === \"string\" && /^\\.\\.?\\//.test(path)) {\r\n return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {\r\n return tsx ? preserveJsx ? \".jsx\" : \".js\" : d && (!ext || !cm) ? m : (d + ext + \".\" + cm.toLowerCase() + \"js\");\r\n });\r\n }\r\n return path;\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __esDecorate: __esDecorate,\r\n __runInitializers: __runInitializers,\r\n __propKey: __propKey,\r\n __setFunctionName: __setFunctionName,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n __rewriteRelativeImportExtension: __rewriteRelativeImportExtension,\r\n};\r\n","function t(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{a(o.next(t))}catch(t){i(t)}}function c(t){try{a(o.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}a((o=o.apply(t,e||[])).next())}))}function e(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create((\"function\"==typeof Iterator?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),\"function\"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(c){return function(a){return function(c){if(n)throw new TypeError(\"Generator is already executing.\");for(;s&&(s=0,c[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&c[0]?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,o=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){i.label=c[1];break}if(6===c[0]&&i.label<r[1]){i.label=r[1],r=c;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(c);break}r[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],o=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function n(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}\"function\"==typeof SuppressedError&&SuppressedError;var o=function(){function o(t){var e,n;void 0===t&&(t={}),this._events=new Map,this._debug=null!==(e=t.debug)&&void 0!==e&&e,this._debugPrefix=null!==(n=t.debugPrefix)&&void 0!==n?n:\"[SampleEventBus]\"}return o.prototype.log=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this._debug&&console.log.apply(console,n([\"\".concat((new Date).toLocaleString(),\":\").concat(this._debugPrefix,\": \").concat(t)],e,!1))},o.prototype.enableDebug=function(t){return this._debug=!0,t&&(this._debugPrefix=t),this.log(\"Debug mode enabled\"),this},o.prototype.disableDebug=function(){return this.log(\"Debug mode disabled\"),this._debug=!1,this},o.prototype.isDebugEnabled=function(){return this._debug},o.prototype.on=function(t,e){if(\"function\"!=typeof e)throw new TypeError(\"Handler must be a function\");var n=this._events.get(t);return n?Array.isArray(n)?(n.push(e),this.log(\"Added listener #\".concat(n.length,' for \"').concat(t,'\"'))):(this._events.set(t,[n,e]),this.log('Converted to multi-listener for \"'.concat(t,'\", count: 2'))):(this._events.set(t,e),this.log('Registered first listener for \"'.concat(t,'\"'))),this},o.prototype.emit=function(o){for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];return t(this,void 0,void 0,(function(){var i,s,c=this;return e(this,(function(a){switch(a.label){case 0:return(i=this._events.get(o))?(s=Array.isArray(i)?i:[i],this.log.apply(this,n(['Emitting \"'.concat(o,'\" to ').concat(s.length,\" listener(s)\")],r,!1)),[4,Promise.all(s.map((function(n,i){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.log(\"Calling listener #\".concat(i+1,' for \"').concat(o,'\"')),[4,n.apply(void 0,r)];case 1:return e.sent(),this.log(\"Listener #\".concat(i+1,' for \"').concat(o,'\" completed')),[3,3];case 2:return t=e.sent(),console.error(\"\".concat(this._debugPrefix,\" Error in listener #\").concat(i+1,' for \"').concat(o,'\":'),t),[3,3];case 3:return[2]}}))}))})))]):(this.log('No listeners for \"'.concat(o,'\", skipping')),[2]);case 1:return a.sent(),this.log('All listeners for \"'.concat(o,'\" finished')),[2]}}))}))},o.prototype.off=function(t,e){var n=this._events.get(t);if(!n)return this.log('No listeners to remove for \"'.concat(t,'\"')),this;if(!e){var o=Array.isArray(n)?n.length:1;return this._events.delete(t),this.log(\"Removed all \".concat(o,' listener(s) for \"').concat(t,'\"')),this}if(\"function\"==typeof n)n===e?(this._events.delete(t),this.log('Removed only listener for \"'.concat(t,'\"'))):this.log('Handler not found for \"'.concat(t,'\"'));else{var r=n.indexOf(e);r>-1?(n.splice(r,1),this.log(\"Removed listener #\".concat(r+1,' for \"').concat(t,'\", ').concat(n.length,\" remaining\")),0===n.length?(this._events.delete(t),this.log('No more listeners for \"'.concat(t,'\"'))):1===n.length&&(this._events.set(t,n[0]),this.log('Converted back to single listener for \"'.concat(t,'\"')))):this.log(\"Handler not found in \".concat(n.length,' listeners for \"').concat(t,'\"'))}return this},o.prototype.once=function(n,o){var r=this;if(\"function\"!=typeof o)throw new TypeError(\"Handler must be a function\");this.log('Registering once listener for \"'.concat(n,'\"'));var i=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return t(r,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.log('Once listener triggered for \"'.concat(n,'\", removing')),this.off(n,i),[4,o.apply(void 0,s)];case 1:return t.sent(),[2]}}))}))};return this.on(n,i)},o.prototype.has=function(t){var e=this._events.has(t);return this.log('Checking \"'.concat(t,'\": ').concat(e?\"has listeners\":\"no listeners\")),e},o.prototype.listenerCount=function(t){var e=this._events.get(t),n=e?Array.isArray(e)?e.length:1:0;return this.log('Listener count for \"'.concat(t,'\": ').concat(n)),n},o.prototype.clear=function(){var t=this._events.size;this._events.clear(),this.log(\"Cleared all \".concat(t,\" event(s)\"))},o}();export{o as default};\n",null,null],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__extends","TypeError","String","__","this","constructor","create","__assign","assign","t","s","i","n","arguments","length","apply","e","o","Promise","r","a","next","c","throw","done","value","then","label","sent","trys","ops","Iterator","return","Symbol","iterator","pop","push","slice","concat","SuppressedError","_events","Map","_debug","debug","_debugPrefix","debugPrefix","log","console","Date","toLocaleString","enableDebug","disableDebug","isDebugEnabled","on","get","isArray","set","emit","all","map","error","off","delete","indexOf","splice","once","has","listenerCount","clear","size","generateMessageId","now","Math","random","toString","WindowMessageBus","_super","options","_this","_sourceId","sourceId","_allowedOrigins","allowedOrigins","_serialize","serialize","JSON","stringify","_deserialize","deserialize","parse","_messageHandler","_handleMessage","bind","_attachMessageListener","window","addEventListener","_detachMessageListener","removeEventListener","_isAllowedOrigin","origin","includes","event","data","origin_1","source","messageData","message","type","messageId","_getTargetWindow","target","parent","top","buildMessage","emitTo","args","_i","targetWindow","serialized","targetOrigin","location","_a","postMessage","Error","emitToChildren","frames","frame","getSourceId","updateAllowedOrigins","origins","join","addAllowedOrigin","removeAllowedOrigin","index","destroy","SampleEventBus","EditorMessageBus","_defaultTarget","self","getDefaultTarget","isReady","targetToUse","timestamp","onReady","handler","_createUnsubscribe","setData","onSetData","setConfig","config","onSetConfig","change","changeData","onChange","save","onSave","exportSVG","onExportSVG","exportPNG","onExportPNG","exportData","onExportData","getData","onGetData","thumnail","onThumnail","preview","onPreview","wrappedHandler","removed","originalHandler"],"mappings":"wPAgBA,IAAIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB,CAAEC,UAAW,cAAgBC,OAAS,SAAUL,EAAGC,GAAKD,EAAEI,UAAYH,CAAE,GACzE,SAAUD,EAAGC,GAAK,IAAK,IAAIK,KAAKL,EAAOC,OAAOK,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,KACzFP,EAAcC,EAAGC,EAC5B,EAEO,SAASS,EAAUV,EAAGC,GACzB,GAAiB,mBAANA,GAA0B,OAANA,EAC3B,MAAM,IAAIU,UAAU,uBAAyBC,OAAOX,GAAK,iCAE7D,SAASY,IAAOC,KAAKC,YAAcf,CAAI,CADvCD,EAAcC,EAAGC,GAEjBD,EAAEO,UAAkB,OAANN,EAAaC,OAAOc,OAAOf,IAAMY,EAAGN,UAAYN,EAAEM,UAAW,IAAIM,EACnF,CAEO,IAAII,EAAW,WAQlB,OAPAA,EAAWf,OAAOgB,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAIf,KADTc,EAAIG,UAAUF,GACOnB,OAAOK,UAAUC,eAAeC,KAAKW,EAAGd,KAAIa,EAAEb,GAAKc,EAAEd,IAE9E,OAAOa,CACV,EACMF,EAASQ,MAAMX,KAAMS,UAChC,ECxCA,SAASJ,EAAEA,EAAEO,EAAEJ,EAAEK,GAAG,OAAO,IAAIL,IAAIA,EAAEM,WAAW,SAASC,EAAER,GAAG,SAASD,EAAED,GAAG,IAAIW,EAAEH,EAAEI,KAAKZ,GAAG,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AAI,GAAAR,QAAG,IAAIU,MAAOC,iBAAiE,mDAE9F,EACFuF,CAAD,CA/YA,CAAsC7D,sEAoZhC,SAAiCE,GACrC,OAAO,IAAI2D,EAAiB3D,EAC9B,2BDpTM,SAAiCA,GACrC,OAAO,IAAIF,EAAiBE,EAC9B","x_google_ignoreList":[0,1]}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@iss-ai/window-message-bus",
3
+ "description": "window消息封装为bus",
4
+ "version": "0.0.1",
5
+ "author": "",
6
+ "keywords": [
7
+ "utils",
8
+ "typescript",
9
+ "rollup",
10
+ "jest",
11
+ "esm",
12
+ "umd",
13
+ "cjs"
14
+ ],
15
+ "homepage": "",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": ""
19
+ },
20
+ "bugs": {
21
+ "url": ""
22
+ },
23
+ "private": false,
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": ""
27
+ },
28
+ "license": "MIT",
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ },
32
+ "browserslist": [
33
+ "last 2 versions",
34
+ "> 5%",
35
+ "not ie <= 9"
36
+ ],
37
+ "main": "lib/index.cjs.js",
38
+ "module": "lib/index.esm.js",
39
+ "jsnext:main": "lib/index.esm.js",
40
+ "browser": "lib/index.umd.js",
41
+ "unpkg": "lib/index.min.js",
42
+ "scripts": {
43
+ "build": "rollup -c",
44
+ "test": "jest",
45
+ "pub": "node script/publish.js",
46
+ "coveralls": "jest --coverage",
47
+ "tsc": "tsc"
48
+ },
49
+ "files": [
50
+ "lib"
51
+ ],
52
+ "types": "lib/index.d.ts",
53
+ "devDependencies": {
54
+ "@babel/core": "^7.23.3",
55
+ "@babel/preset-env": "^7.23.3",
56
+ "@rollup/plugin-alias": "^5.1.0",
57
+ "@rollup/plugin-commonjs": "^25.0.7",
58
+ "@rollup/plugin-json": "^6.1.0",
59
+ "@rollup/plugin-node-resolve": "^15.2.3",
60
+ "@rollup/plugin-terser": "^0.4.4",
61
+ "@rollup/plugin-typescript": "^11.1.5",
62
+ "@types/jest": "^29.5.14",
63
+ "@types/json-bigint": "^1.0.4",
64
+ "@types/lodash-es": "^4.17.10",
65
+ "@types/node": "^25.5.0",
66
+ "@types/nprogress": "^0.2.3",
67
+ "babel-jest": "^29.7.0",
68
+ "chalk": "^5.4.1",
69
+ "jest": "^29.7.0",
70
+ "jest-environment-jsdom": "^29.7.0",
71
+ "jest-less-loader": "^0.2.0",
72
+ "less": "^4.2.0",
73
+ "postcss": "^8.4.31",
74
+ "prettier": "^3.1.0",
75
+ "rollup": "^4.4.1",
76
+ "rollup-plugin-postcss": "^4.0.2",
77
+ "shelljs": "^0.9.2",
78
+ "ts-jest": "^29.2.5",
79
+ "ts-node": "^10.9.2",
80
+ "tslib": "^2.6.2",
81
+ "typescript": "^5.6.3"
82
+ },
83
+ "dependencies": {
84
+ "@iss-ai/sample-event-bus": "^0.0.2"
85
+ }
86
+ }