@withalleo/ewidget-utils 1.0.2

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/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @withalleo/ewidget-utils
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm i @withalleo/ewidget-utils
7
+ ```
8
+
9
+ ## Demo (plain HTML)
10
+
11
+ This package ships a browser bundle at `@withalleo/ewidget-utils/browser` (UMD). You can drop it into a plain HTML page and call `demo()`.
12
+
13
+ > Note: The CDN URL below is an example. Prefer pinning an exact version.
14
+
15
+ ```html
16
+ <!doctype html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="UTF-8" />
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
21
+ <title>@withalleo/ewidget-utils demo</title>
22
+ </head>
23
+ <body>
24
+ <h1>ewidget-utils demo</h1>
25
+
26
+ <!-- Browser (UMD) build -->
27
+ <script src="https://unpkg.com/@withalleo/ewidget-utils@1.0.1/dist/ewidget-utils.umd.cjs"></script>
28
+
29
+ <script>
30
+ // For the UMD build, the library is exposed on the global `AlleoEwidgetUtils`.
31
+ const alleo = AlleoEwidgetUtils.getInstance({ debug: true });
32
+ alleo.demo();
33
+ </script>
34
+ </body>
35
+ </html>
36
+ ```
37
+
38
+ ## EmbedWidgetMessenger (iframe communication)
39
+
40
+ Use this helper inside the embedded page (the iframe) to send commands to the widget and listen for widget events.
41
+
42
+ ### Module usage (recommended)
43
+
44
+ ```ts
45
+ import { EmbedWidgetMessenger } from '@withalleo/ewidget-utils'
46
+
47
+ const messenger = new EmbedWidgetMessenger({
48
+ // Use a specific origin when possible instead of '*'
49
+ targetOrigin: '*',
50
+ debug: true,
51
+ })
52
+
53
+ messenger.onSyncedStatusUpdate((status) => {
54
+ console.log('synced status', status)
55
+ })
56
+
57
+ messenger.onIncomingAction(({ actionId, data }) => {
58
+ console.log('incoming action', actionId, data)
59
+ })
60
+
61
+ messenger.requestSyncedStatus()
62
+
63
+ messenger.triggerAction('demo', {
64
+ 'demo-param': 'Hello from iframe',
65
+ })
66
+
67
+ messenger.setSyncedStatus({
68
+ phase: 'ready',
69
+ lastUpdatedAt: Date.now(),
70
+ })
71
+
72
+ messenger.addContent({
73
+ type: 'notepad',
74
+ textFormat: 'markdown',
75
+ text: '# Status\n\nAll systems go.',
76
+ })
77
+ ```
78
+
79
+ ### Browser (UMD) usage
80
+
81
+ ```html
82
+ <script src="https://unpkg.com/@withalleo/ewidget-utils@1.0.1/dist/ewidget-utils.umd.cjs"></script>
83
+ <script>
84
+ const messenger = new AlleoEwidgetUtils.EmbedWidgetMessenger({
85
+ targetOrigin: '*',
86
+ debug: true,
87
+ })
88
+
89
+ messenger.onSyncedStatusUpdate((status) => {
90
+ console.log('synced status', status)
91
+ })
92
+
93
+ messenger.requestSyncedStatus()
94
+ </script>
95
+ ```
96
+
97
+ ### Notes
98
+
99
+ - Commands available: `triggerAction`, `addContent`, `requestSyncedStatus`, `setSyncedStatus`.
100
+ - Events available: `syncedStatusUpdate`, `incomingAction`.
101
+ - Use `destroy()` to remove listeners when the iframe is torn down.
@@ -0,0 +1,25 @@
1
+ import { EmbedWidgetMessenger, type EmbedWidgetMessengerOptions } from './EmbedWidgetMessenger.js';
2
+ export type AlleoEwidgetUtilsOptions = {
3
+ autoDestroy?: boolean;
4
+ debug?: boolean;
5
+ };
6
+ export declare class AlleoEwidgetUtils {
7
+ private static readonly GLOBAL_KEY;
8
+ private readonly options;
9
+ private initialized;
10
+ private destroyed;
11
+ private onBeforeUnload?;
12
+ constructor(options?: AlleoEwidgetUtilsOptions);
13
+ get isInitialized(): boolean;
14
+ private get isBrowser();
15
+ static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils;
16
+ demo(): void;
17
+ createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger;
18
+ initialize(): void;
19
+ destroy(): void;
20
+ log(message: string, data?: unknown): void;
21
+ private attachListeners;
22
+ private detachListeners;
23
+ }
24
+ export declare const getAlleoEwidgetUtils: (options?: AlleoEwidgetUtilsOptions) => AlleoEwidgetUtils;
25
+ //# sourceMappingURL=AlleoEwidgetUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlleoEwidgetUtils.d.ts","sourceRoot":"","sources":["../src/AlleoEwidgetUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAElG,MAAM,MAAM,wBAAwB,GAAG;IACnC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAQD,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAuC;IACzE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAAC,CAAoC;gBAExC,OAAO,CAAC,EAAE,wBAAwB;IASrD,IAAW,aAAa,IAAI,OAAO,CAElC;IAED,OAAO,KAAK,SAAS,GAEpB;WAEa,WAAW,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,iBAAiB;IAiBzE,IAAI;IAIJ,0BAA0B,CAAC,OAAO,CAAC,EAAE,2BAA2B,GAAG,oBAAoB;IAIvF,UAAU,IAAI,IAAI;IAWlB,OAAO,IAAI,IAAI;IAgBf,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAQjD,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,eAAe;CAK1B;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAU,wBAAwB,KAAG,iBAA2D,CAAA"}
@@ -0,0 +1,99 @@
1
+ export type AddContentHtmlParams = {
2
+ type: 'html';
3
+ html: string;
4
+ };
5
+ export type AddContentNotepadParams = {
6
+ type: 'notepad';
7
+ text?: string | string[];
8
+ textFormat?: 'text' | 'markdown' | 'html';
9
+ };
10
+ export type AddContentStickyNoteParams = {
11
+ type: 'sticky-note';
12
+ text?: string;
13
+ color?: string;
14
+ outlineColor?: string;
15
+ shape?: string;
16
+ };
17
+ export type AddContentImageParams = {
18
+ type: 'image';
19
+ url: string;
20
+ };
21
+ export type AddContentVideoParams = {
22
+ type: 'video';
23
+ fileId: string;
24
+ };
25
+ export type AddContentParams = AddContentHtmlParams | AddContentNotepadParams | AddContentStickyNoteParams | AddContentImageParams | AddContentVideoParams;
26
+ export type EmbedWidgetCommandMap = {
27
+ triggerAction: {
28
+ actionId: string;
29
+ data?: Record<string, unknown>;
30
+ };
31
+ addContent: AddContentParams;
32
+ requestSyncedStatus: Record<string, never>;
33
+ setSyncedStatus: {
34
+ status: Record<string, unknown>;
35
+ };
36
+ };
37
+ export type EmbedWidgetCommand = keyof EmbedWidgetCommandMap;
38
+ export type EmbedWidgetCommandEnvelope<K extends EmbedWidgetCommand = EmbedWidgetCommand> = {
39
+ type: 'EmbedWidgetCommand';
40
+ command: K;
41
+ params: EmbedWidgetCommandMap[K];
42
+ };
43
+ export type EmbedWidgetMessageMap = {
44
+ syncedStatusUpdate: {
45
+ syncedStatus: Record<string, unknown>;
46
+ };
47
+ incomingAction: {
48
+ actionId: string;
49
+ data: Record<string, unknown>;
50
+ };
51
+ };
52
+ export type EmbedWidgetMessageCommand = keyof EmbedWidgetMessageMap;
53
+ export type EmbedWidgetMessageEnvelope<K extends EmbedWidgetMessageCommand = EmbedWidgetMessageCommand> = {
54
+ type: 'EmbedWidgetMessage';
55
+ command: K;
56
+ params: EmbedWidgetMessageMap[K];
57
+ };
58
+ export type EmbedWidgetMessageEvent = {
59
+ command: EmbedWidgetMessageCommand;
60
+ params: EmbedWidgetMessageMap[EmbedWidgetMessageCommand];
61
+ raw: EmbedWidgetMessageEnvelope;
62
+ };
63
+ export type EmbedWidgetMessengerOptions = {
64
+ targetOrigin?: string;
65
+ parentWindow?: Window;
66
+ autoListen?: boolean;
67
+ debug?: boolean;
68
+ };
69
+ export declare class EmbedWidgetMessenger {
70
+ private readonly targetOrigin;
71
+ private readonly parentWindow;
72
+ private readonly debugEnabled;
73
+ private listening;
74
+ private readonly syncedStatusHandlers;
75
+ private readonly incomingActionHandlers;
76
+ private readonly messageHandlers;
77
+ constructor(options?: EmbedWidgetMessengerOptions);
78
+ get isListening(): boolean;
79
+ triggerAction(actionId: string, data?: Record<string, unknown>): void;
80
+ addContent(params: AddContentParams): void;
81
+ requestSyncedStatus(): void;
82
+ setSyncedStatus(status: Record<string, unknown>): void;
83
+ onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void;
84
+ onIncomingAction(handler: (payload: EmbedWidgetMessageMap['incomingAction']) => void): () => void;
85
+ onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void;
86
+ startListening(): void;
87
+ stopListening(): void;
88
+ destroy(): void;
89
+ private get isBrowser();
90
+ private sendCommand;
91
+ private readonly handleMessageEvent;
92
+ private isSyncedStatusUpdate;
93
+ private isIncomingAction;
94
+ private emitSyncedStatusUpdate;
95
+ private emitIncomingAction;
96
+ private emitMessage;
97
+ private log;
98
+ }
99
+ //# sourceMappingURL=EmbedWidgetMessenger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbedWidgetMessenger.d.ts","sourceRoot":"","sources":["../src/EmbedWidgetMessenger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IAClC,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAA;CAC5C,CAAA;AAED,MAAM,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AO,CAAC,GAAG,IAAI;IAQrE,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAI1C,mBAAmB,IAAI,IAAI;IAI3B,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAItD,oBAAoB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAKpF,gBAAgB,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAKjG,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,GAAG,MAAM,IAAI;IAKxE,cAAc,IAAI,IAAI;IAMtB,aAAa,IAAI,IAAI;IAMrB,OAAO,IAAI,IAAI;IAOtB,OAAO,KAAK,SAAS,GAEpB;IAED,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CA+BlC;IAED,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,GAAG;CAOd"}
@@ -0,0 +1,2 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.EwidgetUtils={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{targetOrigin;parentWindow;debugEnabled;listening=!1;syncedStatusHandlers=new Set;incomingActionHandlers=new Set;messageHandlers=new Set;constructor(e){this.targetOrigin=e?.targetOrigin??`*`,this.debugEnabled=e?.debug??!1,this.parentWindow=e?.parentWindow??(this.isBrowser?window.parent:null),(e?.autoListen??!0)&&this.startListening()}get isListening(){return this.listening}triggerAction(e,t){if(!e){this.log(`triggerAction missing actionId`);return}this.sendCommand(`triggerAction`,{actionId:e,data:t})}addContent(e){this.sendCommand(`addContent`,e)}requestSyncedStatus(){this.sendCommand(`requestSyncedStatus`,{})}setSyncedStatus(e){this.sendCommand(`setSyncedStatus`,{status:e})}onSyncedStatusUpdate(e){return this.syncedStatusHandlers.add(e),()=>this.syncedStatusHandlers.delete(e)}onIncomingAction(e){return this.incomingActionHandlers.add(e),()=>this.incomingActionHandlers.delete(e)}onMessage(e){return this.messageHandlers.add(e),()=>this.messageHandlers.delete(e)}startListening(){!this.isBrowser||this.listening||(window.addEventListener(`message`,this.handleMessageEvent),this.listening=!0)}stopListening(){!this.isBrowser||!this.listening||(window.removeEventListener(`message`,this.handleMessageEvent),this.listening=!1)}destroy(){this.stopListening(),this.syncedStatusHandlers.clear(),this.incomingActionHandlers.clear(),this.messageHandlers.clear()}get isBrowser(){return typeof window<`u`&&typeof window.addEventListener==`function`}sendCommand(e,t){if(!this.parentWindow){this.log(`postMessage unavailable`);return}let n={type:`EmbedWidgetCommand`,command:e,params:t};this.parentWindow.postMessage(n,this.targetOrigin)}handleMessageEvent=e=>{if(this.parentWindow&&e.source!==this.parentWindow)return;let t=e.data;if(!t||typeof t!=`object`||t.type!==`EmbedWidgetMessage`)return;let n=t;if(this.isSyncedStatusUpdate(n)){let e=n.params.syncedStatus;e&&typeof e==`object`?this.emitSyncedStatusUpdate(e):this.emitSyncedStatusUpdate({}),this.emitMessage({command:n.command,params:n.params,raw:n});return}if(this.isIncomingAction(n)){if(typeof n.params.actionId!=`string`)return;let e=n.params.data&&typeof n.params.data==`object`?n.params.data:{};this.emitIncomingAction({actionId:n.params.actionId,data:e}),this.emitMessage({command:n.command,params:n.params,raw:n});return}this.log(`Unknown message command`,n.command)};isSyncedStatusUpdate(e){return e.command===`syncedStatusUpdate`}isIncomingAction(e){return e.command===`incomingAction`}emitSyncedStatusUpdate(e){for(let t of this.syncedStatusHandlers)t(e)}emitIncomingAction(e){for(let t of this.incomingActionHandlers)t(e)}emitMessage(e){for(let t of this.messageHandlers)t(e)}log(e,t){this.debugEnabled&&(t===void 0?console.debug(`[ewidget-utils] ${e}`):console.debug(`[ewidget-utils] ${e}`,t))}},n=class e{static GLOBAL_KEY=`__withAlleoEwidgetUtils__`;options;initialized=!1;destroyed=!1;onBeforeUnload;constructor(e){this.options={autoDestroy:e?.autoDestroy??!0,debug:e?.debug??!1},this.initialize()}get isInitialized(){return this.initialized&&!this.destroyed}get isBrowser(){return typeof window<`u`&&typeof document<`u`}static getInstance(t){let n=globalThis;if(n&&typeof n==`object`&&(n[e.GLOBAL_KEY]??={},n[e.GLOBAL_KEY].instance))return n[e.GLOBAL_KEY].instance;let r=new e(t);return n&&typeof n==`object`&&(n[e.GLOBAL_KEY].instance=r),r}demo(){this.log(`DEMO`)}createEmbedWidgetMessenger(e){return new t(e)}initialize(){this.isInitialized||(this.initialized=!0,this.isBrowser&&(this.options.autoDestroy&&this.attachListeners(),this.log(`initialized`)))}destroy(){if(this.destroyed)return;this.destroyed=!0,this.isBrowser&&this.detachListeners();let t=globalThis;if(t&&typeof t==`object`){let n=t[e.GLOBAL_KEY];n?.instance===this&&(n.instance=void 0)}this.log(`destroyed`)}log(e,t){this.options.debug&&(t===void 0?console.debug(`[ewidget-utils] ${e}`):console.debug(`[ewidget-utils] ${e}`,t))}attachListeners(){this.isBrowser&&(this.onBeforeUnload??=()=>this.destroy(),window.addEventListener(`beforeunload`,this.onBeforeUnload))}detachListeners(){this.isBrowser&&this.onBeforeUnload&&window.removeEventListener(`beforeunload`,this.onBeforeUnload)}};e.AlleoEwidgetUtils=n,e.EmbedWidgetMessenger=t,e.getAlleoEwidgetUtils=e=>n.getInstance(e)});
2
+ //# sourceMappingURL=ewidget-utils.umd.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ewidget-utils.umd.cjs","names":[],"sources":["../src/EmbedWidgetMessenger.ts","../src/AlleoEwidgetUtils.ts"],"sourcesContent":["export type AddContentHtmlParams = {\r\n type: 'html'\r\n html: string\r\n}\r\n\r\nexport type AddContentNotepadParams = {\r\n type: 'notepad'\r\n text?: string | string[]\r\n textFormat?: 'text' | 'markdown' | 'html'\r\n}\r\n\r\nexport type AddContentStickyNoteParams = {\r\n type: 'sticky-note'\r\n text?: string\r\n color?: string\r\n outlineColor?: string\r\n shape?: string\r\n}\r\n\r\nexport type AddContentImageParams = {\r\n type: 'image'\r\n url: string\r\n}\r\n\r\nexport type AddContentVideoParams = {\r\n type: 'video'\r\n fileId: string\r\n}\r\n\r\nexport type AddContentParams =\r\n | AddContentHtmlParams\r\n | AddContentNotepadParams\r\n | AddContentStickyNoteParams\r\n | AddContentImageParams\r\n | AddContentVideoParams\r\n\r\nexport type EmbedWidgetCommandMap = {\r\n triggerAction: {\r\n actionId: string\r\n data?: Record<string, unknown>\r\n }\r\n addContent: AddContentParams\r\n requestSyncedStatus: Record<string, never>\r\n setSyncedStatus: {\r\n status: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetCommand = keyof EmbedWidgetCommandMap\r\n\r\nexport type EmbedWidgetCommandEnvelope<K extends EmbedWidgetCommand = EmbedWidgetCommand> = {\r\n type: 'EmbedWidgetCommand'\r\n command: K\r\n params: EmbedWidgetCommandMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageMap = {\r\n syncedStatusUpdate: {\r\n syncedStatus: Record<string, unknown>\r\n }\r\n incomingAction: {\r\n actionId: string\r\n data: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetMessageCommand = keyof EmbedWidgetMessageMap\r\n\r\nexport type EmbedWidgetMessageEnvelope<K extends EmbedWidgetMessageCommand = EmbedWidgetMessageCommand> = {\r\n type: 'EmbedWidgetMessage'\r\n command: K\r\n params: EmbedWidgetMessageMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageEvent = {\r\n command: EmbedWidgetMessageCommand\r\n params: EmbedWidgetMessageMap[EmbedWidgetMessageCommand]\r\n raw: EmbedWidgetMessageEnvelope\r\n}\r\n\r\nexport type EmbedWidgetMessengerOptions = {\r\n targetOrigin?: string\r\n parentWindow?: Window\r\n autoListen?: boolean\r\n debug?: boolean\r\n}\r\n\r\nexport class EmbedWidgetMessenger {\r\n private readonly targetOrigin: string\r\n private readonly parentWindow: Window | null\r\n private readonly debugEnabled: boolean\r\n private listening = false\r\n private readonly syncedStatusHandlers = new Set<(status: Record<string, unknown>) => void>()\r\n private readonly incomingActionHandlers = new Set<(payload: EmbedWidgetMessageMap['incomingAction']) => void>()\r\n private readonly messageHandlers = new Set<(event: EmbedWidgetMessageEvent) => void>()\r\n\r\n public constructor(options?: EmbedWidgetMessengerOptions) {\r\n this.targetOrigin = options?.targetOrigin ?? '*'\r\n this.debugEnabled = options?.debug ?? false\r\n this.parentWindow = options?.parentWindow ?? (this.isBrowser ? window.parent : null)\r\n\r\n const autoListen = options?.autoListen ?? true\r\n if (autoListen) this.startListening()\r\n }\r\n\r\n public get isListening(): boolean {\r\n return this.listening\r\n }\r\n\r\n public triggerAction(actionId: string, data?: Record<string, unknown>): void {\r\n if (!actionId) {\r\n this.log('triggerAction missing actionId')\r\n return\r\n }\r\n this.sendCommand('triggerAction', { actionId, data })\r\n }\r\n\r\n public addContent(params: AddContentParams): void {\r\n this.sendCommand('addContent', params)\r\n }\r\n\r\n public requestSyncedStatus(): void {\r\n this.sendCommand('requestSyncedStatus', {})\r\n }\r\n\r\n public setSyncedStatus(status: Record<string, unknown>): void {\r\n this.sendCommand('setSyncedStatus', { status })\r\n }\r\n\r\n public onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void {\r\n this.syncedStatusHandlers.add(handler)\r\n return () => this.syncedStatusHandlers.delete(handler)\r\n }\r\n\r\n public onIncomingAction(handler: (payload: EmbedWidgetMessageMap['incomingAction']) => void): () => void {\r\n this.incomingActionHandlers.add(handler)\r\n return () => this.incomingActionHandlers.delete(handler)\r\n }\r\n\r\n public onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void {\r\n this.messageHandlers.add(handler)\r\n return () => this.messageHandlers.delete(handler)\r\n }\r\n\r\n public startListening(): void {\r\n if (!this.isBrowser || this.listening) return\r\n window.addEventListener('message', this.handleMessageEvent)\r\n this.listening = true\r\n }\r\n\r\n public stopListening(): void {\r\n if (!this.isBrowser || !this.listening) return\r\n window.removeEventListener('message', this.handleMessageEvent)\r\n this.listening = false\r\n }\r\n\r\n public destroy(): void {\r\n this.stopListening()\r\n this.syncedStatusHandlers.clear()\r\n this.incomingActionHandlers.clear()\r\n this.messageHandlers.clear()\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof window.addEventListener === 'function'\r\n }\r\n\r\n private sendCommand<K extends EmbedWidgetCommand>(command: K, params: EmbedWidgetCommandMap[K]): void {\r\n if (!this.parentWindow) {\r\n this.log('postMessage unavailable')\r\n return\r\n }\r\n\r\n const message: EmbedWidgetCommandEnvelope<K> = {\r\n type: 'EmbedWidgetCommand',\r\n command,\r\n params,\r\n }\r\n\r\n this.parentWindow.postMessage(message, this.targetOrigin)\r\n }\r\n\r\n private readonly handleMessageEvent = (event: MessageEvent): void => {\r\n if (this.parentWindow && event.source !== this.parentWindow) return\r\n\r\n const data = event.data\r\n if (!data || typeof data !== 'object') return\r\n if ((data as { type?: string }).type !== 'EmbedWidgetMessage') return\r\n\r\n const envelope = data as EmbedWidgetMessageEnvelope\r\n\r\n if (this.isSyncedStatusUpdate(envelope)) {\r\n const status = envelope.params.syncedStatus\r\n if (status && typeof status === 'object') {\r\n this.emitSyncedStatusUpdate(status)\r\n } else {\r\n this.emitSyncedStatusUpdate({})\r\n }\r\n\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n if (this.isIncomingAction(envelope)) {\r\n if (typeof envelope.params.actionId !== 'string') return\r\n const actionData =\r\n envelope.params.data && typeof envelope.params.data === 'object' ? envelope.params.data : {}\r\n this.emitIncomingAction({ actionId: envelope.params.actionId, data: actionData })\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n this.log('Unknown message command', envelope.command)\r\n }\r\n\r\n private isSyncedStatusUpdate(\r\n envelope: EmbedWidgetMessageEnvelope,\r\n ): envelope is EmbedWidgetMessageEnvelope<'syncedStatusUpdate'> {\r\n return envelope.command === 'syncedStatusUpdate'\r\n }\r\n\r\n private isIncomingAction(envelope: EmbedWidgetMessageEnvelope): envelope is EmbedWidgetMessageEnvelope<'incomingAction'> {\r\n return envelope.command === 'incomingAction'\r\n }\r\n\r\n private emitSyncedStatusUpdate(status: Record<string, unknown>): void {\r\n for (const handler of this.syncedStatusHandlers) handler(status)\r\n }\r\n\r\n private emitIncomingAction(payload: EmbedWidgetMessageMap['incomingAction']): void {\r\n for (const handler of this.incomingActionHandlers) handler(payload)\r\n }\r\n\r\n private emitMessage(event: EmbedWidgetMessageEvent): void {\r\n for (const handler of this.messageHandlers) handler(event)\r\n }\r\n\r\n private log(message: string, data?: unknown): void {\r\n if (!this.debugEnabled) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n}\r\n","import { EmbedWidgetMessenger, type EmbedWidgetMessengerOptions } from './EmbedWidgetMessenger.js'\r\n\r\nexport type AlleoEwidgetUtilsOptions = {\r\n autoDestroy?: boolean\r\n debug?: boolean\r\n}\r\n\r\ntype GlobalWithAlleo = typeof globalThis & {\r\n __withAlleoEwidgetUtils__?: {\r\n instance?: AlleoEwidgetUtils\r\n }\r\n}\r\n\r\nexport class AlleoEwidgetUtils {\r\n private static readonly GLOBAL_KEY = '__withAlleoEwidgetUtils__' as const\r\n private readonly options: Required<AlleoEwidgetUtilsOptions>\r\n private initialized = false\r\n private destroyed = false\r\n private onBeforeUnload?: (event: BeforeUnloadEvent) => void\r\n\r\n public constructor(options?: AlleoEwidgetUtilsOptions) {\r\n this.options = {\r\n autoDestroy: options?.autoDestroy ?? true,\r\n debug: options?.debug ?? false,\r\n }\r\n\r\n this.initialize()\r\n }\r\n\r\n public get isInitialized(): boolean {\r\n return this.initialized && !this.destroyed\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof document !== 'undefined'\r\n }\r\n\r\n public static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils {\r\n // Prefer a global singleton if running in a browser and the bundle was included multiple times.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY] ??= {}\r\n if (g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance) {\r\n return g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance!\r\n }\r\n }\r\n\r\n const instance = new AlleoEwidgetUtils(options)\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance = instance\r\n }\r\n return instance\r\n }\r\n\r\n public demo() {\r\n this.log(\"DEMO\")\r\n }\r\n\r\n public createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger {\r\n return new EmbedWidgetMessenger(options)\r\n }\r\n\r\n public initialize(): void {\r\n if (this.isInitialized) return\r\n this.initialized = true\r\n\r\n if (!this.isBrowser) return\r\n\r\n if (this.options.autoDestroy) this.attachListeners()\r\n\r\n this.log('initialized')\r\n }\r\n\r\n public destroy(): void {\r\n if (this.destroyed) return\r\n this.destroyed = true\r\n\r\n if (this.isBrowser) this.detachListeners()\r\n\r\n // If this instance is the stored global singleton, clear it so callers can recreate.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n const holder = g[AlleoEwidgetUtils.GLOBAL_KEY]\r\n if (holder?.instance === this) holder.instance = undefined\r\n }\r\n\r\n this.log('destroyed')\r\n }\r\n\r\n public log(message: string, data?: unknown): void {\r\n if (!this.options.debug) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n\r\n private attachListeners(): void {\r\n if (!this.isBrowser) return\r\n\r\n this.onBeforeUnload ??= () => this.destroy()\r\n window.addEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n\r\n private detachListeners(): void {\r\n if (!this.isBrowser) return\r\n if (!this.onBeforeUnload) return\r\n window.removeEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n}\r\n\r\nexport const getAlleoEwidgetUtils = (options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils => AlleoEwidgetUtils.getInstance(options)\r\n"],"mappings":"oRAuFA,IAAa,EAAb,KAAkC,CAC9B,aACA,aACA,aACA,UAAoB,GACpB,qBAAwC,IAAI,IAC5C,uBAA0C,IAAI,IAC9C,gBAAmC,IAAI,IAEvC,YAAmB,EAAuC,CACtD,KAAK,aAAe,GAAS,cAAgB,IAC7C,KAAK,aAAe,GAAS,OAAS,GACtC,KAAK,aAAe,GAAS,eAAiB,KAAK,UAAY,OAAO,OAAS,OAE5D,GAAS,YAAc,KAC1B,KAAK,gBAAgB,CAGzC,IAAW,aAAuB,CAC9B,OAAO,KAAK,UAGhB,cAAqB,EAAkB,EAAsC,CACzE,GAAI,CAAC,EAAU,CACX,KAAK,IAAI,iCAAiC,CAC1C,OAEJ,KAAK,YAAY,gBAAiB,CAAE,WAAU,OAAM,CAAC,CAGzD,WAAkB,EAAgC,CAC9C,KAAK,YAAY,aAAc,EAAO,CAG1C,qBAAmC,CAC/B,KAAK,YAAY,sBAAuB,EAAE,CAAC,CAG/C,gBAAuB,EAAuC,CAC1D,KAAK,YAAY,kBAAmB,CAAE,SAAQ,CAAC,CAGnD,qBAA4B,EAAgE,CAExF,OADA,KAAK,qBAAqB,IAAI,EAAQ,KACzB,KAAK,qBAAqB,OAAO,EAAQ,CAG1D,iBAAwB,EAAiF,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E,EAAkB,YAAa,SAIhD,IAAM,EAAW,IAAI,EAAkB,EAAQ,CAI/C,OAHI,GAAK,OAAO,GAAM,WAClB,EAAE,EAAkB,YAAa,SAAW,GAEzC,EAGX,MAAc,CACV,KAAK,IAAI,OAAO,CAGpB,2BAAkC,EAA6D,CAC3F,OAAO,IAAI,EAAqB,EAAQ,CAG5C,YAA0B,CAClB,KAAK,gBACT,KAAK,YAAc,GAEd,KAAK,YAEN,KAAK,QAAQ,aAAa,KAAK,iBAAiB,CAEpD,KAAK,IAAI,cAAc,GAG3B,SAAuB,CACnB,GAAI,KAAK,UAAW,OACpB,KAAK,UAAY,GAEb,KAAK,WAAW,KAAK,iBAAiB,CAG1C,IAAM,EAAI,WACV,GAAI,GAAK,OAAO,GAAM,SAAU,CAC5B,IAAM,EAAS,EAAE,EAAkB,YAC/B,GAAQ,WAAa,OAAM,EAAO,SAAW,IAAA,IAGrD,KAAK,IAAI,YAAY,CAGzB,IAAW,EAAiB,EAAsB,CACzC,KAAK,QAAQ,QAEd,IAAS,IAAA,GAAW,QAAQ,MAAM,mBAAmB,IAAU,CAE9D,QAAQ,MAAM,mBAAmB,IAAW,EAAK,EAG1D,iBAAgC,CACvB,KAAK,YAEV,KAAK,qBAAyB,KAAK,SAAS,CAC5C,OAAO,iBAAiB,eAAgB,KAAK,eAAe,EAGhE,iBAAgC,CACvB,KAAK,WACL,KAAK,gBACV,OAAO,oBAAoB,eAAgB,KAAK,eAAe,yEAIlC,GAA0D,EAAkB,YAAY,EAAQ"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{targetOrigin;parentWindow;debugEnabled;listening=!1;syncedStatusHandlers=new Set;incomingActionHandlers=new Set;messageHandlers=new Set;constructor(e){this.targetOrigin=e?.targetOrigin??`*`,this.debugEnabled=e?.debug??!1,this.parentWindow=e?.parentWindow??(this.isBrowser?window.parent:null),(e?.autoListen??!0)&&this.startListening()}get isListening(){return this.listening}triggerAction(e,t){if(!e){this.log(`triggerAction missing actionId`);return}this.sendCommand(`triggerAction`,{actionId:e,data:t})}addContent(e){this.sendCommand(`addContent`,e)}requestSyncedStatus(){this.sendCommand(`requestSyncedStatus`,{})}setSyncedStatus(e){this.sendCommand(`setSyncedStatus`,{status:e})}onSyncedStatusUpdate(e){return this.syncedStatusHandlers.add(e),()=>this.syncedStatusHandlers.delete(e)}onIncomingAction(e){return this.incomingActionHandlers.add(e),()=>this.incomingActionHandlers.delete(e)}onMessage(e){return this.messageHandlers.add(e),()=>this.messageHandlers.delete(e)}startListening(){!this.isBrowser||this.listening||(window.addEventListener(`message`,this.handleMessageEvent),this.listening=!0)}stopListening(){!this.isBrowser||!this.listening||(window.removeEventListener(`message`,this.handleMessageEvent),this.listening=!1)}destroy(){this.stopListening(),this.syncedStatusHandlers.clear(),this.incomingActionHandlers.clear(),this.messageHandlers.clear()}get isBrowser(){return typeof window<`u`&&typeof window.addEventListener==`function`}sendCommand(e,t){if(!this.parentWindow){this.log(`postMessage unavailable`);return}let n={type:`EmbedWidgetCommand`,command:e,params:t};this.parentWindow.postMessage(n,this.targetOrigin)}handleMessageEvent=e=>{if(this.parentWindow&&e.source!==this.parentWindow)return;let t=e.data;if(!t||typeof t!=`object`||t.type!==`EmbedWidgetMessage`)return;let n=t;if(this.isSyncedStatusUpdate(n)){let e=n.params.syncedStatus;e&&typeof e==`object`?this.emitSyncedStatusUpdate(e):this.emitSyncedStatusUpdate({}),this.emitMessage({command:n.command,params:n.params,raw:n});return}if(this.isIncomingAction(n)){if(typeof n.params.actionId!=`string`)return;let e=n.params.data&&typeof n.params.data==`object`?n.params.data:{};this.emitIncomingAction({actionId:n.params.actionId,data:e}),this.emitMessage({command:n.command,params:n.params,raw:n});return}this.log(`Unknown message command`,n.command)};isSyncedStatusUpdate(e){return e.command===`syncedStatusUpdate`}isIncomingAction(e){return e.command===`incomingAction`}emitSyncedStatusUpdate(e){for(let t of this.syncedStatusHandlers)t(e)}emitIncomingAction(e){for(let t of this.incomingActionHandlers)t(e)}emitMessage(e){for(let t of this.messageHandlers)t(e)}log(e,t){this.debugEnabled&&(t===void 0?console.debug(`[ewidget-utils] ${e}`):console.debug(`[ewidget-utils] ${e}`,t))}},t=class t{static GLOBAL_KEY=`__withAlleoEwidgetUtils__`;options;initialized=!1;destroyed=!1;onBeforeUnload;constructor(e){this.options={autoDestroy:e?.autoDestroy??!0,debug:e?.debug??!1},this.initialize()}get isInitialized(){return this.initialized&&!this.destroyed}get isBrowser(){return typeof window<`u`&&typeof document<`u`}static getInstance(e){let n=globalThis;if(n&&typeof n==`object`&&(n[t.GLOBAL_KEY]??={},n[t.GLOBAL_KEY].instance))return n[t.GLOBAL_KEY].instance;let r=new t(e);return n&&typeof n==`object`&&(n[t.GLOBAL_KEY].instance=r),r}demo(){this.log(`DEMO`)}createEmbedWidgetMessenger(t){return new e(t)}initialize(){this.isInitialized||(this.initialized=!0,this.isBrowser&&(this.options.autoDestroy&&this.attachListeners(),this.log(`initialized`)))}destroy(){if(this.destroyed)return;this.destroyed=!0,this.isBrowser&&this.detachListeners();let e=globalThis;if(e&&typeof e==`object`){let n=e[t.GLOBAL_KEY];n?.instance===this&&(n.instance=void 0)}this.log(`destroyed`)}log(e,t){this.options.debug&&(t===void 0?console.debug(`[ewidget-utils] ${e}`):console.debug(`[ewidget-utils] ${e}`,t))}attachListeners(){this.isBrowser&&(this.onBeforeUnload??=()=>this.destroy(),window.addEventListener(`beforeunload`,this.onBeforeUnload))}detachListeners(){this.isBrowser&&this.onBeforeUnload&&window.removeEventListener(`beforeunload`,this.onBeforeUnload)}},n=e=>t.getInstance(e);exports.AlleoEwidgetUtils=t,exports.EmbedWidgetMessenger=e,exports.getAlleoEwidgetUtils=n;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/EmbedWidgetMessenger.ts","../src/AlleoEwidgetUtils.ts"],"sourcesContent":["export type AddContentHtmlParams = {\r\n type: 'html'\r\n html: string\r\n}\r\n\r\nexport type AddContentNotepadParams = {\r\n type: 'notepad'\r\n text?: string | string[]\r\n textFormat?: 'text' | 'markdown' | 'html'\r\n}\r\n\r\nexport type AddContentStickyNoteParams = {\r\n type: 'sticky-note'\r\n text?: string\r\n color?: string\r\n outlineColor?: string\r\n shape?: string\r\n}\r\n\r\nexport type AddContentImageParams = {\r\n type: 'image'\r\n url: string\r\n}\r\n\r\nexport type AddContentVideoParams = {\r\n type: 'video'\r\n fileId: string\r\n}\r\n\r\nexport type AddContentParams =\r\n | AddContentHtmlParams\r\n | AddContentNotepadParams\r\n | AddContentStickyNoteParams\r\n | AddContentImageParams\r\n | AddContentVideoParams\r\n\r\nexport type EmbedWidgetCommandMap = {\r\n triggerAction: {\r\n actionId: string\r\n data?: Record<string, unknown>\r\n }\r\n addContent: AddContentParams\r\n requestSyncedStatus: Record<string, never>\r\n setSyncedStatus: {\r\n status: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetCommand = keyof EmbedWidgetCommandMap\r\n\r\nexport type EmbedWidgetCommandEnvelope<K extends EmbedWidgetCommand = EmbedWidgetCommand> = {\r\n type: 'EmbedWidgetCommand'\r\n command: K\r\n params: EmbedWidgetCommandMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageMap = {\r\n syncedStatusUpdate: {\r\n syncedStatus: Record<string, unknown>\r\n }\r\n incomingAction: {\r\n actionId: string\r\n data: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetMessageCommand = keyof EmbedWidgetMessageMap\r\n\r\nexport type EmbedWidgetMessageEnvelope<K extends EmbedWidgetMessageCommand = EmbedWidgetMessageCommand> = {\r\n type: 'EmbedWidgetMessage'\r\n command: K\r\n params: EmbedWidgetMessageMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageEvent = {\r\n command: EmbedWidgetMessageCommand\r\n params: EmbedWidgetMessageMap[EmbedWidgetMessageCommand]\r\n raw: EmbedWidgetMessageEnvelope\r\n}\r\n\r\nexport type EmbedWidgetMessengerOptions = {\r\n targetOrigin?: string\r\n parentWindow?: Window\r\n autoListen?: boolean\r\n debug?: boolean\r\n}\r\n\r\nexport class EmbedWidgetMessenger {\r\n private readonly targetOrigin: string\r\n private readonly parentWindow: Window | null\r\n private readonly debugEnabled: boolean\r\n private listening = false\r\n private readonly syncedStatusHandlers = new Set<(status: Record<string, unknown>) => void>()\r\n private readonly incomingActionHandlers = new Set<(payload: EmbedWidgetMessageMap['incomingAction']) => void>()\r\n private readonly messageHandlers = new Set<(event: EmbedWidgetMessageEvent) => void>()\r\n\r\n public constructor(options?: EmbedWidgetMessengerOptions) {\r\n this.targetOrigin = options?.targetOrigin ?? '*'\r\n this.debugEnabled = options?.debug ?? false\r\n this.parentWindow = options?.parentWindow ?? (this.isBrowser ? window.parent : null)\r\n\r\n const autoListen = options?.autoListen ?? true\r\n if (autoListen) this.startListening()\r\n }\r\n\r\n public get isListening(): boolean {\r\n return this.listening\r\n }\r\n\r\n public triggerAction(actionId: string, data?: Record<string, unknown>): void {\r\n if (!actionId) {\r\n this.log('triggerAction missing actionId')\r\n return\r\n }\r\n this.sendCommand('triggerAction', { actionId, data })\r\n }\r\n\r\n public addContent(params: AddContentParams): void {\r\n this.sendCommand('addContent', params)\r\n }\r\n\r\n public requestSyncedStatus(): void {\r\n this.sendCommand('requestSyncedStatus', {})\r\n }\r\n\r\n public setSyncedStatus(status: Record<string, unknown>): void {\r\n this.sendCommand('setSyncedStatus', { status })\r\n }\r\n\r\n public onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void {\r\n this.syncedStatusHandlers.add(handler)\r\n return () => this.syncedStatusHandlers.delete(handler)\r\n }\r\n\r\n public onIncomingAction(handler: (payload: EmbedWidgetMessageMap['incomingAction']) => void): () => void {\r\n this.incomingActionHandlers.add(handler)\r\n return () => this.incomingActionHandlers.delete(handler)\r\n }\r\n\r\n public onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void {\r\n this.messageHandlers.add(handler)\r\n return () => this.messageHandlers.delete(handler)\r\n }\r\n\r\n public startListening(): void {\r\n if (!this.isBrowser || this.listening) return\r\n window.addEventListener('message', this.handleMessageEvent)\r\n this.listening = true\r\n }\r\n\r\n public stopListening(): void {\r\n if (!this.isBrowser || !this.listening) return\r\n window.removeEventListener('message', this.handleMessageEvent)\r\n this.listening = false\r\n }\r\n\r\n public destroy(): void {\r\n this.stopListening()\r\n this.syncedStatusHandlers.clear()\r\n this.incomingActionHandlers.clear()\r\n this.messageHandlers.clear()\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof window.addEventListener === 'function'\r\n }\r\n\r\n private sendCommand<K extends EmbedWidgetCommand>(command: K, params: EmbedWidgetCommandMap[K]): void {\r\n if (!this.parentWindow) {\r\n this.log('postMessage unavailable')\r\n return\r\n }\r\n\r\n const message: EmbedWidgetCommandEnvelope<K> = {\r\n type: 'EmbedWidgetCommand',\r\n command,\r\n params,\r\n }\r\n\r\n this.parentWindow.postMessage(message, this.targetOrigin)\r\n }\r\n\r\n private readonly handleMessageEvent = (event: MessageEvent): void => {\r\n if (this.parentWindow && event.source !== this.parentWindow) return\r\n\r\n const data = event.data\r\n if (!data || typeof data !== 'object') return\r\n if ((data as { type?: string }).type !== 'EmbedWidgetMessage') return\r\n\r\n const envelope = data as EmbedWidgetMessageEnvelope\r\n\r\n if (this.isSyncedStatusUpdate(envelope)) {\r\n const status = envelope.params.syncedStatus\r\n if (status && typeof status === 'object') {\r\n this.emitSyncedStatusUpdate(status)\r\n } else {\r\n this.emitSyncedStatusUpdate({})\r\n }\r\n\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n if (this.isIncomingAction(envelope)) {\r\n if (typeof envelope.params.actionId !== 'string') return\r\n const actionData =\r\n envelope.params.data && typeof envelope.params.data === 'object' ? envelope.params.data : {}\r\n this.emitIncomingAction({ actionId: envelope.params.actionId, data: actionData })\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n this.log('Unknown message command', envelope.command)\r\n }\r\n\r\n private isSyncedStatusUpdate(\r\n envelope: EmbedWidgetMessageEnvelope,\r\n ): envelope is EmbedWidgetMessageEnvelope<'syncedStatusUpdate'> {\r\n return envelope.command === 'syncedStatusUpdate'\r\n }\r\n\r\n private isIncomingAction(envelope: EmbedWidgetMessageEnvelope): envelope is EmbedWidgetMessageEnvelope<'incomingAction'> {\r\n return envelope.command === 'incomingAction'\r\n }\r\n\r\n private emitSyncedStatusUpdate(status: Record<string, unknown>): void {\r\n for (const handler of this.syncedStatusHandlers) handler(status)\r\n }\r\n\r\n private emitIncomingAction(payload: EmbedWidgetMessageMap['incomingAction']): void {\r\n for (const handler of this.incomingActionHandlers) handler(payload)\r\n }\r\n\r\n private emitMessage(event: EmbedWidgetMessageEvent): void {\r\n for (const handler of this.messageHandlers) handler(event)\r\n }\r\n\r\n private log(message: string, data?: unknown): void {\r\n if (!this.debugEnabled) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n}\r\n","import { EmbedWidgetMessenger, type EmbedWidgetMessengerOptions } from './EmbedWidgetMessenger.js'\r\n\r\nexport type AlleoEwidgetUtilsOptions = {\r\n autoDestroy?: boolean\r\n debug?: boolean\r\n}\r\n\r\ntype GlobalWithAlleo = typeof globalThis & {\r\n __withAlleoEwidgetUtils__?: {\r\n instance?: AlleoEwidgetUtils\r\n }\r\n}\r\n\r\nexport class AlleoEwidgetUtils {\r\n private static readonly GLOBAL_KEY = '__withAlleoEwidgetUtils__' as const\r\n private readonly options: Required<AlleoEwidgetUtilsOptions>\r\n private initialized = false\r\n private destroyed = false\r\n private onBeforeUnload?: (event: BeforeUnloadEvent) => void\r\n\r\n public constructor(options?: AlleoEwidgetUtilsOptions) {\r\n this.options = {\r\n autoDestroy: options?.autoDestroy ?? true,\r\n debug: options?.debug ?? false,\r\n }\r\n\r\n this.initialize()\r\n }\r\n\r\n public get isInitialized(): boolean {\r\n return this.initialized && !this.destroyed\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof document !== 'undefined'\r\n }\r\n\r\n public static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils {\r\n // Prefer a global singleton if running in a browser and the bundle was included multiple times.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY] ??= {}\r\n if (g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance) {\r\n return g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance!\r\n }\r\n }\r\n\r\n const instance = new AlleoEwidgetUtils(options)\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance = instance\r\n }\r\n return instance\r\n }\r\n\r\n public demo() {\r\n this.log(\"DEMO\")\r\n }\r\n\r\n public createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger {\r\n return new EmbedWidgetMessenger(options)\r\n }\r\n\r\n public initialize(): void {\r\n if (this.isInitialized) return\r\n this.initialized = true\r\n\r\n if (!this.isBrowser) return\r\n\r\n if (this.options.autoDestroy) this.attachListeners()\r\n\r\n this.log('initialized')\r\n }\r\n\r\n public destroy(): void {\r\n if (this.destroyed) return\r\n this.destroyed = true\r\n\r\n if (this.isBrowser) this.detachListeners()\r\n\r\n // If this instance is the stored global singleton, clear it so callers can recreate.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n const holder = g[AlleoEwidgetUtils.GLOBAL_KEY]\r\n if (holder?.instance === this) holder.instance = undefined\r\n }\r\n\r\n this.log('destroyed')\r\n }\r\n\r\n public log(message: string, data?: unknown): void {\r\n if (!this.options.debug) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n\r\n private attachListeners(): void {\r\n if (!this.isBrowser) return\r\n\r\n this.onBeforeUnload ??= () => this.destroy()\r\n window.addEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n\r\n private detachListeners(): void {\r\n if (!this.isBrowser) return\r\n if (!this.onBeforeUnload) return\r\n window.removeEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n}\r\n\r\nexport const getAlleoEwidgetUtils = (options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils => AlleoEwidgetUtils.getInstance(options)\r\n"],"mappings":"mEAuFA,IAAa,EAAb,KAAkC,CAC9B,aACA,aACA,aACA,UAAoB,GACpB,qBAAwC,IAAI,IAC5C,uBAA0C,IAAI,IAC9C,gBAAmC,IAAI,IAEvC,YAAmB,EAAuC,CACtD,KAAK,aAAe,GAAS,cAAgB,IAC7C,KAAK,aAAe,GAAS,OAAS,GACtC,KAAK,aAAe,GAAS,eAAiB,KAAK,UAAY,OAAO,OAAS,OAE5D,GAAS,YAAc,KAC1B,KAAK,gBAAgB,CAGzC,IAAW,aAAuB,CAC9B,OAAO,KAAK,UAGhB,cAAqB,EAAkB,EAAsC,CACzE,GAAI,CAAC,EAAU,CACX,KAAK,IAAI,iCAAiC,CAC1C,OAEJ,KAAK,YAAY,gBAAiB,CAAE,WAAU,OAAM,CAAC,CAGzD,WAAkB,EAAgC,CAC9C,KAAK,YAAY,aAAc,EAAO,CAG1C,qBAAmC,CAC/B,KAAK,YAAY,sBAAuB,EAAE,CAAC,CAG/C,gBAAuB,EAAuC,CAC1D,KAAK,YAAY,kBAAmB,CAAE,SAAQ,CAAC,CAGnD,qBAA4B,EAAgE,CAExF,OADA,KAAK,qBAAqB,IAAI,EAAQ,KACzB,KAAK,qBAAqB,OAAO,EAAQ,CAG1D,iBAAwB,EAAiF,CAErG,OADA,KAAK,uB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hD,IAAM,EAAW,IAAI,EAAkB,EAAQ,CAI/C,OAHI,GAAK,OAAO,GAAM,WAClB,EAAE,EAAkB,YAAa,SAAW,GAEzC,EAGX,MAAc,CACV,KAAK,IAAI,OAAO,CAGpB,2BAAkC,EAA6D,CAC3F,OAAO,IAAI,EAAqB,EAAQ,CAG5C,YAA0B,CAClB,KAAK,gBACT,KAAK,YAAc,GAEd,KAAK,YAEN,KAAK,QAAQ,aAAa,KAAK,iBAAiB,CAEpD,KAAK,IAAI,cAAc,GAG3B,SAAuB,CACnB,GAAI,KAAK,UAAW,OACpB,KAAK,UAAY,GAEb,KAAK,WAAW,KAAK,iBAAiB,CAG1C,IAAM,EAAI,WACV,GAAI,GAAK,OAAO,GAAM,SAAU,CAC5B,IAAM,EAAS,EAAE,EAAkB,YAC/B,GAAQ,WAAa,OAAM,EAAO,SAAW,IAAA,IAGrD,KAAK,IAAI,YAAY,CAGzB,IAAW,EAAiB,EAAsB,CACzC,KAAK,QAAQ,QAEd,IAAS,IAAA,GAAW,QAAQ,MAAM,mBAAmB,IAAU,CAE9D,QAAQ,MAAM,mBAAmB,IAAW,EAAK,EAG1D,iBAAgC,CACvB,KAAK,YAEV,KAAK,qBAAyB,KAAK,SAAS,CAC5C,OAAO,iBAAiB,eAAgB,KAAK,eAAe,EAGhE,iBAAgC,CACvB,KAAK,WACL,KAAK,gBACV,OAAO,oBAAoB,eAAgB,KAAK,eAAe,GAI1D,EAAwB,GAA0D,EAAkB,YAAY,EAAQ"}
@@ -0,0 +1,5 @@
1
+ export { AlleoEwidgetUtils, getAlleoEwidgetUtils } from './AlleoEwidgetUtils.js';
2
+ export type { AlleoEwidgetUtilsOptions } from './AlleoEwidgetUtils.js';
3
+ export { EmbedWidgetMessenger } from './EmbedWidgetMessenger.js';
4
+ export type { AddContentHtmlParams, AddContentNotepadParams, AddContentStickyNoteParams, AddContentImageParams, AddContentVideoParams, AddContentParams, EmbedWidgetCommand, EmbedWidgetCommandEnvelope, EmbedWidgetCommandMap, EmbedWidgetMessageCommand, EmbedWidgetMessageEnvelope, EmbedWidgetMessageEvent, EmbedWidgetMessageMap, EmbedWidgetMessengerOptions, } from './EmbedWidgetMessenger.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAChF,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,YAAY,EACR,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,GAC9B,MAAM,2BAA2B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,171 @@
1
+ //#region src/EmbedWidgetMessenger.ts
2
+ var e = class {
3
+ targetOrigin;
4
+ parentWindow;
5
+ debugEnabled;
6
+ listening = !1;
7
+ syncedStatusHandlers = /* @__PURE__ */ new Set();
8
+ incomingActionHandlers = /* @__PURE__ */ new Set();
9
+ messageHandlers = /* @__PURE__ */ new Set();
10
+ constructor(e) {
11
+ this.targetOrigin = e?.targetOrigin ?? "*", this.debugEnabled = e?.debug ?? !1, this.parentWindow = e?.parentWindow ?? (this.isBrowser ? window.parent : null), (e?.autoListen ?? !0) && this.startListening();
12
+ }
13
+ get isListening() {
14
+ return this.listening;
15
+ }
16
+ triggerAction(e, t) {
17
+ if (!e) {
18
+ this.log("triggerAction missing actionId");
19
+ return;
20
+ }
21
+ this.sendCommand("triggerAction", {
22
+ actionId: e,
23
+ data: t
24
+ });
25
+ }
26
+ addContent(e) {
27
+ this.sendCommand("addContent", e);
28
+ }
29
+ requestSyncedStatus() {
30
+ this.sendCommand("requestSyncedStatus", {});
31
+ }
32
+ setSyncedStatus(e) {
33
+ this.sendCommand("setSyncedStatus", { status: e });
34
+ }
35
+ onSyncedStatusUpdate(e) {
36
+ return this.syncedStatusHandlers.add(e), () => this.syncedStatusHandlers.delete(e);
37
+ }
38
+ onIncomingAction(e) {
39
+ return this.incomingActionHandlers.add(e), () => this.incomingActionHandlers.delete(e);
40
+ }
41
+ onMessage(e) {
42
+ return this.messageHandlers.add(e), () => this.messageHandlers.delete(e);
43
+ }
44
+ startListening() {
45
+ !this.isBrowser || this.listening || (window.addEventListener("message", this.handleMessageEvent), this.listening = !0);
46
+ }
47
+ stopListening() {
48
+ !this.isBrowser || !this.listening || (window.removeEventListener("message", this.handleMessageEvent), this.listening = !1);
49
+ }
50
+ destroy() {
51
+ this.stopListening(), this.syncedStatusHandlers.clear(), this.incomingActionHandlers.clear(), this.messageHandlers.clear();
52
+ }
53
+ get isBrowser() {
54
+ return typeof window < "u" && typeof window.addEventListener == "function";
55
+ }
56
+ sendCommand(e, t) {
57
+ if (!this.parentWindow) {
58
+ this.log("postMessage unavailable");
59
+ return;
60
+ }
61
+ let n = {
62
+ type: "EmbedWidgetCommand",
63
+ command: e,
64
+ params: t
65
+ };
66
+ this.parentWindow.postMessage(n, this.targetOrigin);
67
+ }
68
+ handleMessageEvent = (e) => {
69
+ if (this.parentWindow && e.source !== this.parentWindow) return;
70
+ let t = e.data;
71
+ if (!t || typeof t != "object" || t.type !== "EmbedWidgetMessage") return;
72
+ let n = t;
73
+ if (this.isSyncedStatusUpdate(n)) {
74
+ let e = n.params.syncedStatus;
75
+ e && typeof e == "object" ? this.emitSyncedStatusUpdate(e) : this.emitSyncedStatusUpdate({}), this.emitMessage({
76
+ command: n.command,
77
+ params: n.params,
78
+ raw: n
79
+ });
80
+ return;
81
+ }
82
+ if (this.isIncomingAction(n)) {
83
+ if (typeof n.params.actionId != "string") return;
84
+ let e = n.params.data && typeof n.params.data == "object" ? n.params.data : {};
85
+ this.emitIncomingAction({
86
+ actionId: n.params.actionId,
87
+ data: e
88
+ }), this.emitMessage({
89
+ command: n.command,
90
+ params: n.params,
91
+ raw: n
92
+ });
93
+ return;
94
+ }
95
+ this.log("Unknown message command", n.command);
96
+ };
97
+ isSyncedStatusUpdate(e) {
98
+ return e.command === "syncedStatusUpdate";
99
+ }
100
+ isIncomingAction(e) {
101
+ return e.command === "incomingAction";
102
+ }
103
+ emitSyncedStatusUpdate(e) {
104
+ for (let t of this.syncedStatusHandlers) t(e);
105
+ }
106
+ emitIncomingAction(e) {
107
+ for (let t of this.incomingActionHandlers) t(e);
108
+ }
109
+ emitMessage(e) {
110
+ for (let t of this.messageHandlers) t(e);
111
+ }
112
+ log(e, t) {
113
+ this.debugEnabled && (t === void 0 ? console.debug(`[ewidget-utils] ${e}`) : console.debug(`[ewidget-utils] ${e}`, t));
114
+ }
115
+ }, t = class t {
116
+ static GLOBAL_KEY = "__withAlleoEwidgetUtils__";
117
+ options;
118
+ initialized = !1;
119
+ destroyed = !1;
120
+ onBeforeUnload;
121
+ constructor(e) {
122
+ this.options = {
123
+ autoDestroy: e?.autoDestroy ?? !0,
124
+ debug: e?.debug ?? !1
125
+ }, this.initialize();
126
+ }
127
+ get isInitialized() {
128
+ return this.initialized && !this.destroyed;
129
+ }
130
+ get isBrowser() {
131
+ return typeof window < "u" && typeof document < "u";
132
+ }
133
+ static getInstance(e) {
134
+ let n = globalThis;
135
+ if (n && typeof n == "object" && (n[t.GLOBAL_KEY] ??= {}, n[t.GLOBAL_KEY].instance)) return n[t.GLOBAL_KEY].instance;
136
+ let r = new t(e);
137
+ return n && typeof n == "object" && (n[t.GLOBAL_KEY].instance = r), r;
138
+ }
139
+ demo() {
140
+ this.log("DEMO");
141
+ }
142
+ createEmbedWidgetMessenger(t) {
143
+ return new e(t);
144
+ }
145
+ initialize() {
146
+ this.isInitialized || (this.initialized = !0, this.isBrowser && (this.options.autoDestroy && this.attachListeners(), this.log("initialized")));
147
+ }
148
+ destroy() {
149
+ if (this.destroyed) return;
150
+ this.destroyed = !0, this.isBrowser && this.detachListeners();
151
+ let e = globalThis;
152
+ if (e && typeof e == "object") {
153
+ let n = e[t.GLOBAL_KEY];
154
+ n?.instance === this && (n.instance = void 0);
155
+ }
156
+ this.log("destroyed");
157
+ }
158
+ log(e, t) {
159
+ this.options.debug && (t === void 0 ? console.debug(`[ewidget-utils] ${e}`) : console.debug(`[ewidget-utils] ${e}`, t));
160
+ }
161
+ attachListeners() {
162
+ this.isBrowser && (this.onBeforeUnload ??= () => this.destroy(), window.addEventListener("beforeunload", this.onBeforeUnload));
163
+ }
164
+ detachListeners() {
165
+ this.isBrowser && this.onBeforeUnload && window.removeEventListener("beforeunload", this.onBeforeUnload);
166
+ }
167
+ }, n = (e) => t.getInstance(e);
168
+ //#endregion
169
+ export { t as AlleoEwidgetUtils, e as EmbedWidgetMessenger, n as getAlleoEwidgetUtils };
170
+
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/EmbedWidgetMessenger.ts","../src/AlleoEwidgetUtils.ts"],"sourcesContent":["export type AddContentHtmlParams = {\r\n type: 'html'\r\n html: string\r\n}\r\n\r\nexport type AddContentNotepadParams = {\r\n type: 'notepad'\r\n text?: string | string[]\r\n textFormat?: 'text' | 'markdown' | 'html'\r\n}\r\n\r\nexport type AddContentStickyNoteParams = {\r\n type: 'sticky-note'\r\n text?: string\r\n color?: string\r\n outlineColor?: string\r\n shape?: string\r\n}\r\n\r\nexport type AddContentImageParams = {\r\n type: 'image'\r\n url: string\r\n}\r\n\r\nexport type AddContentVideoParams = {\r\n type: 'video'\r\n fileId: string\r\n}\r\n\r\nexport type AddContentParams =\r\n | AddContentHtmlParams\r\n | AddContentNotepadParams\r\n | AddContentStickyNoteParams\r\n | AddContentImageParams\r\n | AddContentVideoParams\r\n\r\nexport type EmbedWidgetCommandMap = {\r\n triggerAction: {\r\n actionId: string\r\n data?: Record<string, unknown>\r\n }\r\n addContent: AddContentParams\r\n requestSyncedStatus: Record<string, never>\r\n setSyncedStatus: {\r\n status: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetCommand = keyof EmbedWidgetCommandMap\r\n\r\nexport type EmbedWidgetCommandEnvelope<K extends EmbedWidgetCommand = EmbedWidgetCommand> = {\r\n type: 'EmbedWidgetCommand'\r\n command: K\r\n params: EmbedWidgetCommandMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageMap = {\r\n syncedStatusUpdate: {\r\n syncedStatus: Record<string, unknown>\r\n }\r\n incomingAction: {\r\n actionId: string\r\n data: Record<string, unknown>\r\n }\r\n}\r\n\r\nexport type EmbedWidgetMessageCommand = keyof EmbedWidgetMessageMap\r\n\r\nexport type EmbedWidgetMessageEnvelope<K extends EmbedWidgetMessageCommand = EmbedWidgetMessageCommand> = {\r\n type: 'EmbedWidgetMessage'\r\n command: K\r\n params: EmbedWidgetMessageMap[K]\r\n}\r\n\r\nexport type EmbedWidgetMessageEvent = {\r\n command: EmbedWidgetMessageCommand\r\n params: EmbedWidgetMessageMap[EmbedWidgetMessageCommand]\r\n raw: EmbedWidgetMessageEnvelope\r\n}\r\n\r\nexport type EmbedWidgetMessengerOptions = {\r\n targetOrigin?: string\r\n parentWindow?: Window\r\n autoListen?: boolean\r\n debug?: boolean\r\n}\r\n\r\nexport class EmbedWidgetMessenger {\r\n private readonly targetOrigin: string\r\n private readonly parentWindow: Window | null\r\n private readonly debugEnabled: boolean\r\n private listening = false\r\n private readonly syncedStatusHandlers = new Set<(status: Record<string, unknown>) => void>()\r\n private readonly incomingActionHandlers = new Set<(payload: EmbedWidgetMessageMap['incomingAction']) => void>()\r\n private readonly messageHandlers = new Set<(event: EmbedWidgetMessageEvent) => void>()\r\n\r\n public constructor(options?: EmbedWidgetMessengerOptions) {\r\n this.targetOrigin = options?.targetOrigin ?? '*'\r\n this.debugEnabled = options?.debug ?? false\r\n this.parentWindow = options?.parentWindow ?? (this.isBrowser ? window.parent : null)\r\n\r\n const autoListen = options?.autoListen ?? true\r\n if (autoListen) this.startListening()\r\n }\r\n\r\n public get isListening(): boolean {\r\n return this.listening\r\n }\r\n\r\n public triggerAction(actionId: string, data?: Record<string, unknown>): void {\r\n if (!actionId) {\r\n this.log('triggerAction missing actionId')\r\n return\r\n }\r\n this.sendCommand('triggerAction', { actionId, data })\r\n }\r\n\r\n public addContent(params: AddContentParams): void {\r\n this.sendCommand('addContent', params)\r\n }\r\n\r\n public requestSyncedStatus(): void {\r\n this.sendCommand('requestSyncedStatus', {})\r\n }\r\n\r\n public setSyncedStatus(status: Record<string, unknown>): void {\r\n this.sendCommand('setSyncedStatus', { status })\r\n }\r\n\r\n public onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void {\r\n this.syncedStatusHandlers.add(handler)\r\n return () => this.syncedStatusHandlers.delete(handler)\r\n }\r\n\r\n public onIncomingAction(handler: (payload: EmbedWidgetMessageMap['incomingAction']) => void): () => void {\r\n this.incomingActionHandlers.add(handler)\r\n return () => this.incomingActionHandlers.delete(handler)\r\n }\r\n\r\n public onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void {\r\n this.messageHandlers.add(handler)\r\n return () => this.messageHandlers.delete(handler)\r\n }\r\n\r\n public startListening(): void {\r\n if (!this.isBrowser || this.listening) return\r\n window.addEventListener('message', this.handleMessageEvent)\r\n this.listening = true\r\n }\r\n\r\n public stopListening(): void {\r\n if (!this.isBrowser || !this.listening) return\r\n window.removeEventListener('message', this.handleMessageEvent)\r\n this.listening = false\r\n }\r\n\r\n public destroy(): void {\r\n this.stopListening()\r\n this.syncedStatusHandlers.clear()\r\n this.incomingActionHandlers.clear()\r\n this.messageHandlers.clear()\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof window.addEventListener === 'function'\r\n }\r\n\r\n private sendCommand<K extends EmbedWidgetCommand>(command: K, params: EmbedWidgetCommandMap[K]): void {\r\n if (!this.parentWindow) {\r\n this.log('postMessage unavailable')\r\n return\r\n }\r\n\r\n const message: EmbedWidgetCommandEnvelope<K> = {\r\n type: 'EmbedWidgetCommand',\r\n command,\r\n params,\r\n }\r\n\r\n this.parentWindow.postMessage(message, this.targetOrigin)\r\n }\r\n\r\n private readonly handleMessageEvent = (event: MessageEvent): void => {\r\n if (this.parentWindow && event.source !== this.parentWindow) return\r\n\r\n const data = event.data\r\n if (!data || typeof data !== 'object') return\r\n if ((data as { type?: string }).type !== 'EmbedWidgetMessage') return\r\n\r\n const envelope = data as EmbedWidgetMessageEnvelope\r\n\r\n if (this.isSyncedStatusUpdate(envelope)) {\r\n const status = envelope.params.syncedStatus\r\n if (status && typeof status === 'object') {\r\n this.emitSyncedStatusUpdate(status)\r\n } else {\r\n this.emitSyncedStatusUpdate({})\r\n }\r\n\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n if (this.isIncomingAction(envelope)) {\r\n if (typeof envelope.params.actionId !== 'string') return\r\n const actionData =\r\n envelope.params.data && typeof envelope.params.data === 'object' ? envelope.params.data : {}\r\n this.emitIncomingAction({ actionId: envelope.params.actionId, data: actionData })\r\n this.emitMessage({ command: envelope.command, params: envelope.params, raw: envelope })\r\n return\r\n }\r\n\r\n this.log('Unknown message command', envelope.command)\r\n }\r\n\r\n private isSyncedStatusUpdate(\r\n envelope: EmbedWidgetMessageEnvelope,\r\n ): envelope is EmbedWidgetMessageEnvelope<'syncedStatusUpdate'> {\r\n return envelope.command === 'syncedStatusUpdate'\r\n }\r\n\r\n private isIncomingAction(envelope: EmbedWidgetMessageEnvelope): envelope is EmbedWidgetMessageEnvelope<'incomingAction'> {\r\n return envelope.command === 'incomingAction'\r\n }\r\n\r\n private emitSyncedStatusUpdate(status: Record<string, unknown>): void {\r\n for (const handler of this.syncedStatusHandlers) handler(status)\r\n }\r\n\r\n private emitIncomingAction(payload: EmbedWidgetMessageMap['incomingAction']): void {\r\n for (const handler of this.incomingActionHandlers) handler(payload)\r\n }\r\n\r\n private emitMessage(event: EmbedWidgetMessageEvent): void {\r\n for (const handler of this.messageHandlers) handler(event)\r\n }\r\n\r\n private log(message: string, data?: unknown): void {\r\n if (!this.debugEnabled) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n}\r\n","import { EmbedWidgetMessenger, type EmbedWidgetMessengerOptions } from './EmbedWidgetMessenger.js'\r\n\r\nexport type AlleoEwidgetUtilsOptions = {\r\n autoDestroy?: boolean\r\n debug?: boolean\r\n}\r\n\r\ntype GlobalWithAlleo = typeof globalThis & {\r\n __withAlleoEwidgetUtils__?: {\r\n instance?: AlleoEwidgetUtils\r\n }\r\n}\r\n\r\nexport class AlleoEwidgetUtils {\r\n private static readonly GLOBAL_KEY = '__withAlleoEwidgetUtils__' as const\r\n private readonly options: Required<AlleoEwidgetUtilsOptions>\r\n private initialized = false\r\n private destroyed = false\r\n private onBeforeUnload?: (event: BeforeUnloadEvent) => void\r\n\r\n public constructor(options?: AlleoEwidgetUtilsOptions) {\r\n this.options = {\r\n autoDestroy: options?.autoDestroy ?? true,\r\n debug: options?.debug ?? false,\r\n }\r\n\r\n this.initialize()\r\n }\r\n\r\n public get isInitialized(): boolean {\r\n return this.initialized && !this.destroyed\r\n }\r\n\r\n private get isBrowser(): boolean {\r\n return typeof window !== 'undefined' && typeof document !== 'undefined'\r\n }\r\n\r\n public static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils {\r\n // Prefer a global singleton if running in a browser and the bundle was included multiple times.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY] ??= {}\r\n if (g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance) {\r\n return g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance!\r\n }\r\n }\r\n\r\n const instance = new AlleoEwidgetUtils(options)\r\n if (g && typeof g === 'object') {\r\n g[AlleoEwidgetUtils.GLOBAL_KEY]!.instance = instance\r\n }\r\n return instance\r\n }\r\n\r\n public demo() {\r\n this.log(\"DEMO\")\r\n }\r\n\r\n public createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger {\r\n return new EmbedWidgetMessenger(options)\r\n }\r\n\r\n public initialize(): void {\r\n if (this.isInitialized) return\r\n this.initialized = true\r\n\r\n if (!this.isBrowser) return\r\n\r\n if (this.options.autoDestroy) this.attachListeners()\r\n\r\n this.log('initialized')\r\n }\r\n\r\n public destroy(): void {\r\n if (this.destroyed) return\r\n this.destroyed = true\r\n\r\n if (this.isBrowser) this.detachListeners()\r\n\r\n // If this instance is the stored global singleton, clear it so callers can recreate.\r\n const g = globalThis as GlobalWithAlleo\r\n if (g && typeof g === 'object') {\r\n const holder = g[AlleoEwidgetUtils.GLOBAL_KEY]\r\n if (holder?.instance === this) holder.instance = undefined\r\n }\r\n\r\n this.log('destroyed')\r\n }\r\n\r\n public log(message: string, data?: unknown): void {\r\n if (!this.options.debug) return\r\n // eslint-disable-next-line no-console\r\n if (data === undefined) console.debug(`[ewidget-utils] ${message}`)\r\n // eslint-disable-next-line no-console\r\n else console.debug(`[ewidget-utils] ${message}`, data)\r\n }\r\n\r\n private attachListeners(): void {\r\n if (!this.isBrowser) return\r\n\r\n this.onBeforeUnload ??= () => this.destroy()\r\n window.addEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n\r\n private detachListeners(): void {\r\n if (!this.isBrowser) return\r\n if (!this.onBeforeUnload) return\r\n window.removeEventListener('beforeunload', this.onBeforeUnload)\r\n }\r\n}\r\n\r\nexport const getAlleoEwidgetUtils = (options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils => AlleoEwidgetUtils.getInstance(options)\r\n"],"mappings":";AAuFA,IAAa,IAAb,MAAkC;CAC9B;CACA;CACA;CACA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aAAW,KAAK,iBAAiB;EAG1C,IAAM,IAAI;AACV,MAAI,KAAK,OAAO,KAAM,UAAU;GAC5B,IAAM,IAAS,EAAE,EAAkB;AACnC,GAAI,GAAQ,aAAa,SAAM,EAAO,WAAW,KAAA;;AAGrD,OAAK,IAAI,YAAY;;CAGzB,IAAW,GAAiB,GAAsB;AACzC,OAAK,QAAQ,UAEd,MAAS,KAAA,IAAW,QAAQ,MAAM,mBAAmB,IAAU,GAE9D,QAAQ,MAAM,mBAAmB,KAAW,EAAK;;CAG1D,kBAAgC;AACvB,OAAK,cAEV,KAAK,yBAAyB,KAAK,SAAS,EAC5C,OAAO,iBAAiB,gBAAgB,KAAK,eAAe;;CAGhE,kBAAgC;AACvB,OAAK,aACL,KAAK,kBACV,OAAO,oBAAoB,gBAAgB,KAAK,eAAe;;GAI1D,KAAwB,MAA0D,EAAkB,YAAY,EAAQ"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@withalleo/ewidget-utils",
3
+ "version": "1.0.2",
4
+ "description": "Alleo e-widget utility library.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/withalleo/ewidget-utils.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/withalleo/ewidget-utils/issues"
11
+ },
12
+ "homepage": "https://github.com/withalleo/ewidget-utils#readme",
13
+ "author": {
14
+ "name": "Alleo",
15
+ "url": "https://www.withalleo.com/"
16
+ },
17
+ "sideEffects": false,
18
+ "type": "module",
19
+ "files": [
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
31
+ },
32
+ "./browser": {
33
+ "default": "./dist/ewidget-utils.umd.cjs"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "provenance": false
40
+ },
41
+ "scripts": {
42
+ "clean": "rimraf dist",
43
+ "build": "vite build && tsc -p tsconfig.build.json"
44
+ },
45
+ "devDependencies": {
46
+ "@eslint/js": "^9.22.0",
47
+ "@types/node": "^22.13.10",
48
+ "@typescript-eslint/eslint-plugin": "^8.26.0",
49
+ "@typescript-eslint/parser": "^8.26.0",
50
+ "eslint": "^10.1.0",
51
+ "eslint-config-prettier": "^10.1.8",
52
+ "eslint-plugin-jsdoc": "^62.8.0",
53
+ "eslint-plugin-prefer-arrow": "^1.2.3",
54
+ "eslint-plugin-prettier": "^5.5.5",
55
+ "eslint-plugin-unused-imports": "^4.3.0",
56
+ "prettier": "^3.8.1",
57
+ "prettier-eslint": "^16.3.0",
58
+ "rimraf": "^6.0.1",
59
+ "typescript": "^5.9.3",
60
+ "typescript-eslint": "^8.26.0",
61
+ "vite": "^8.0.3"
62
+ }
63
+ }