@pexip-engage-public/plugin 1.1.26-canary-20250728202825 → 1.1.26

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.
@@ -1,64 +0,0 @@
1
- import { isBrowser, } from "./common.js";
2
- export function initialize(iframe) {
3
- if (!isBrowser()) {
4
- return { unsubscribe() { } };
5
- }
6
- const registeredElement = {
7
- iframe,
8
- initContext: { isInitialized: false, retryAttempts: 0 },
9
- };
10
- const unsubscribe = addCrossOriginChildResizeListener(registeredElement);
11
- return { unsubscribe };
12
- }
13
- function addCrossOriginChildResizeListener(registeredElement) {
14
- const { iframe, initContext } = registeredElement;
15
- function handleIframeResizedMessage(event) {
16
- const isIframeTarget = iframe.contentWindow === event.source;
17
- if (!isIframeTarget) {
18
- return;
19
- }
20
- if (event.data?.type === "iframe-resized") {
21
- const { height } = event.data;
22
- height && resizeIframe({ newHeight: height, registeredElement });
23
- return;
24
- }
25
- if (event.data?.type === "iframe-scroll-to-offset") {
26
- const { top } = event.data;
27
- const iFramePosition = iframe.getBoundingClientRect();
28
- window.scrollTo({ top: iFramePosition.top + window.scrollY + top });
29
- return;
30
- }
31
- }
32
- window.addEventListener("message", handleIframeResizedMessage);
33
- const initMessage = { type: "iframe-child-init" };
34
- function sendInitializationMessageToChild() {
35
- postMessageSafelyToCrossOriginIframe(iframe, () => iframe.contentWindow?.postMessage(initMessage, "*"));
36
- initContext.retryAttempts++;
37
- initContext.retryTimeoutId = window.setTimeout(sendInitializationMessageToChild, getExponentialBackoffDelay(initContext.retryAttempts));
38
- }
39
- sendInitializationMessageToChild();
40
- return () => window.removeEventListener("message", handleIframeResizedMessage);
41
- }
42
- function resizeIframe({ registeredElement, newHeight, }) {
43
- const { iframe, initContext } = registeredElement;
44
- if (!initContext.isInitialized) {
45
- initContext.isInitialized = true;
46
- clearTimeout(initContext.retryTimeoutId);
47
- }
48
- iframe.style.height = `${newHeight}px`;
49
- }
50
- /** Post the message twice, it assures the target to receive the message at least once */
51
- function postMessageSafelyToCrossOriginIframe(iframe, executable) {
52
- executable();
53
- iframe.addEventListener("load", executable);
54
- }
55
- function getExponentialBackoffDelay(nthRetry) {
56
- if (nthRetry <= 100) {
57
- return 100; // for 10 seconds
58
- }
59
- if (nthRetry <= 120) {
60
- return 1000; // for 20 seconds
61
- }
62
- return 10000;
63
- }
64
- //# sourceMappingURL=parent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parent.js","sourceRoot":"","sources":["../../src/resizer/parent.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,GAEV,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,UAAU,CAAC,MAAyB;IAClD,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,OAAO,EAAE,WAAW,KAAI,CAAC,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,iBAAiB,GAAsB;QAC3C,MAAM;QACN,WAAW,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,EAAE;KACxD,CAAC;IACF,MAAM,WAAW,GAAG,iCAAiC,CAAC,iBAAiB,CAAC,CAAC;IAEzE,OAAO,EAAE,WAAW,EAAE,CAAC;AACzB,CAAC;AAED,SAAS,iCAAiC,CAAC,iBAAoC;IAC7E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,iBAAiB,CAAC;IAElD,SAAS,0BAA0B,CAAC,KAAmB;QACrD,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,KAAK,KAAK,CAAC,MAAM,CAAC;QAE7D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC1C,MAAM,EAAE,MAAM,EAAE,GAAI,KAA2B,CAAC,IAAI,CAAC;YACrD,MAAM,IAAI,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;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C,MAAM,GAAG,GAAG,SAAS,IAAI,CAAC;AACzC,CAAC;AAED,yFAAyF;AACzF,SAAS,oCAAoC,CAAC,MAAyB,EAAE,UAAsB;IAC7F,UAAU,EAAE,CAAC;IACb,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,0BAA0B,CAAC,QAAgB;IAClD,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;QACpB,OAAO,GAAG,CAAC,CAAC,iBAAiB;IAC/B,CAAC;IAED,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,CAAC,iBAAiB;IAChC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,138 +0,0 @@
1
- import type {
2
- IFrameMessage,
3
- IFrameObjectMessage,
4
- IframeChildMessageEventData,
5
- IframeParentMessageEventData,
6
- } from "../events/index.js";
7
- import {
8
- type IframeChildInitEventData,
9
- type IframeResizeEventData,
10
- type IframeScrollData,
11
- isBrowser,
12
- } from "./common.js";
13
-
14
- export class IframeChildInstance {
15
- #queue: IFrameMessage[] = [];
16
- #isQueueConsumed = false;
17
- #initialized = false;
18
- #_resizeObserver: ResizeObserver | null = null;
19
- get #resizeObserver() {
20
- if (!this.#_resizeObserver) {
21
- this.#_resizeObserver = new ResizeObserver((entries) => {
22
- if (!entries[0]?.target) {
23
- return;
24
- }
25
-
26
- const clientRect = entries[0].target.getBoundingClientRect();
27
- const height = Math.ceil(clientRect.height);
28
- const width = Math.ceil(clientRect.width);
29
-
30
- const data: IframeResizeEventData = {
31
- height,
32
- type: "iframe-resized",
33
- width,
34
- };
35
-
36
- window.parent.postMessage(data, "*");
37
- });
38
- }
39
-
40
- return this.#_resizeObserver;
41
- }
42
-
43
- #handleInitializeSignal = (event: MessageEvent<IframeChildInitEventData>) => {
44
- const elementToObserve = document.documentElement;
45
-
46
- if (this.#initialized || window.parent !== event.source) {
47
- return;
48
- }
49
-
50
- this.#resizeObserver.disconnect();
51
- this.#resizeObserver.observe(elementToObserve);
52
- this.#initialized = true;
53
- this.#isQueueConsumed = true;
54
- this.#queue.forEach((message) => this.sendMessage(message));
55
- this.#queue.length = 0;
56
-
57
- this.#onReady();
58
- };
59
-
60
- sendMessage = (message: IFrameMessage) => {
61
- if (!this.#isQueueConsumed && isInIframe()) {
62
- this.#queue.push(message);
63
-
64
- return;
65
- }
66
-
67
- const data: IframeParentMessageEventData = {
68
- message,
69
- type: "iframe-parent-message",
70
- };
71
-
72
- this.#sendMessage(data);
73
- };
74
-
75
- scrollToOffset = (offset: { top: number }) => {
76
- const data: IframeScrollData = {
77
- top: offset.top,
78
- type: "iframe-scroll-to-offset",
79
- };
80
-
81
- this.#sendMessage(data);
82
- };
83
-
84
- #sendMessage(data: IframeScrollData | IframeParentMessageEventData) {
85
- if (!isBrowser() || !isInIframe()) return;
86
-
87
- window.parent.postMessage(data, "*");
88
- }
89
-
90
- #handleMessage = (
91
- event: MessageEvent<IframeChildInitEventData | IframeChildMessageEventData>,
92
- ) => {
93
- if (event.data?.type === "iframe-child-init") {
94
- return deferWhenWindowDocumentIsLoaded(() =>
95
- this.#handleInitializeSignal(event as MessageEvent<IframeChildInitEventData>),
96
- );
97
- }
98
-
99
- if (event.data?.type === "iframe-child-message") {
100
- this.#onMessage(event.data.message);
101
- }
102
- };
103
-
104
- readonly #onReady: () => void;
105
- readonly #onMessage: (message: IFrameObjectMessage) => void;
106
-
107
- constructor({
108
- onReady,
109
- onMessage,
110
- }: {
111
- onReady: () => void;
112
- onMessage: (message: IFrameObjectMessage) => void;
113
- }) {
114
- this.#onReady = onReady;
115
- this.#onMessage = onMessage;
116
- }
117
-
118
- initialize = () => {
119
- if (!isBrowser() || !isInIframe()) return;
120
-
121
- window.addEventListener("message", this.#handleMessage);
122
- };
123
-
124
- unsubscribe = () => {
125
- window.removeEventListener("message", this.#handleMessage);
126
- this.#resizeObserver.disconnect();
127
- };
128
- }
129
-
130
- function isInIframe() {
131
- return window.self !== window.top;
132
- }
133
-
134
- function deferWhenWindowDocumentIsLoaded(executable: () => void) {
135
- window.document.readyState === "complete"
136
- ? executable()
137
- : window.addEventListener("load", executable);
138
- }
@@ -1,28 +0,0 @@
1
- export function isBrowser() {
2
- return typeof window !== "undefined";
3
- }
4
-
5
- export type InitializeResult = { unsubscribe: () => void };
6
-
7
- export type IframeResizeEventData = {
8
- type: "iframe-resized";
9
- width: number;
10
- height?: number;
11
- };
12
-
13
- export type IframeScrollData = {
14
- type: "iframe-scroll-to-offset";
15
- top: number;
16
- };
17
-
18
- export type IframeChildInitEventData = {
19
- type: "iframe-child-init";
20
- };
21
-
22
- export type IframeResizeEvent = MessageEvent<IframeResizeEventData>;
23
- export type IframeScrollEvent = MessageEvent<IframeScrollData>;
24
-
25
- export interface RegisteredElement {
26
- iframe: HTMLIFrameElement;
27
- initContext: { isInitialized: boolean; retryAttempts: number; retryTimeoutId?: number };
28
- }
@@ -1,102 +0,0 @@
1
- import {
2
- type IframeChildInitEventData,
3
- type IframeResizeEvent,
4
- type IframeScrollEvent,
5
- type InitializeResult,
6
- isBrowser,
7
- type RegisteredElement,
8
- } from "./common.js";
9
-
10
- export function initialize(iframe: HTMLIFrameElement): InitializeResult {
11
- if (!isBrowser()) {
12
- return { unsubscribe() {} };
13
- }
14
-
15
- const registeredElement: RegisteredElement = {
16
- iframe,
17
- initContext: { isInitialized: false, retryAttempts: 0 },
18
- };
19
- const unsubscribe = addCrossOriginChildResizeListener(registeredElement);
20
-
21
- return { unsubscribe };
22
- }
23
-
24
- function addCrossOriginChildResizeListener(registeredElement: RegisteredElement) {
25
- const { iframe, initContext } = registeredElement;
26
-
27
- function handleIframeResizedMessage(event: MessageEvent) {
28
- const isIframeTarget = iframe.contentWindow === event.source;
29
-
30
- if (!isIframeTarget) {
31
- return;
32
- }
33
-
34
- if (event.data?.type === "iframe-resized") {
35
- const { height } = (event as IframeResizeEvent).data;
36
- height && resizeIframe({ newHeight: height, registeredElement });
37
-
38
- return;
39
- }
40
-
41
- if (event.data?.type === "iframe-scroll-to-offset") {
42
- const { top } = (event as IframeScrollEvent).data;
43
- const iFramePosition = iframe.getBoundingClientRect();
44
-
45
- window.scrollTo({ top: iFramePosition.top + window.scrollY + top });
46
-
47
- return;
48
- }
49
- }
50
-
51
- window.addEventListener("message", handleIframeResizedMessage);
52
-
53
- const initMessage: IframeChildInitEventData = { type: "iframe-child-init" };
54
-
55
- function sendInitializationMessageToChild() {
56
- postMessageSafelyToCrossOriginIframe(iframe, () =>
57
- iframe.contentWindow?.postMessage(initMessage, "*"),
58
- );
59
- initContext.retryAttempts++;
60
- initContext.retryTimeoutId = window.setTimeout(
61
- sendInitializationMessageToChild,
62
- getExponentialBackoffDelay(initContext.retryAttempts),
63
- );
64
- }
65
- sendInitializationMessageToChild();
66
-
67
- return () => window.removeEventListener("message", handleIframeResizedMessage);
68
- }
69
-
70
- function resizeIframe({
71
- registeredElement,
72
- newHeight,
73
- }: {
74
- registeredElement: RegisteredElement;
75
- newHeight: number;
76
- }) {
77
- const { iframe, initContext } = registeredElement;
78
- if (!initContext.isInitialized) {
79
- initContext.isInitialized = true;
80
- clearTimeout(initContext.retryTimeoutId);
81
- }
82
-
83
- iframe.style.height = `${newHeight}px`;
84
- }
85
-
86
- /** Post the message twice, it assures the target to receive the message at least once */
87
- function postMessageSafelyToCrossOriginIframe(iframe: HTMLIFrameElement, executable: () => void) {
88
- executable();
89
- iframe.addEventListener("load", executable);
90
- }
91
-
92
- function getExponentialBackoffDelay(nthRetry: number) {
93
- if (nthRetry <= 100) {
94
- return 100; // for 10 seconds
95
- }
96
-
97
- if (nthRetry <= 120) {
98
- return 1000; // for 20 seconds
99
- }
100
-
101
- return 10000;
102
- }