@open-iframe-resizer/core 1.6.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +148 -112
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ If you found this project helpful, please consider starring the repository!
|
|
|
17
17
|
```html
|
|
18
18
|
|
|
19
19
|
<script type="module">
|
|
20
|
-
import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@
|
|
20
|
+
import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@v2.1.0/dist/index.min.js";
|
|
21
21
|
|
|
22
22
|
initialize({}, "#my-iframe");
|
|
23
23
|
</script>
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare type BeforeResizeContext = {
|
|
|
2
2
|
iframe: HTMLIFrameElement;
|
|
3
3
|
settings: Settings;
|
|
4
4
|
observedHeight: number;
|
|
5
|
+
interactionState: InteractionState;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export declare type IframeChildInitEventData = {
|
|
@@ -11,6 +12,10 @@ export declare type IframeChildInitEventData = {
|
|
|
11
12
|
bodyMargin?: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
export declare type IframeGetChildDimensionsEventData = {
|
|
16
|
+
type: "iframe-get-child-dimensions";
|
|
17
|
+
};
|
|
18
|
+
|
|
14
19
|
export declare type IframeResizeEvent = MessageEvent<IframeResizeEventData>;
|
|
15
20
|
|
|
16
21
|
export declare type IframeResizeEventData = {
|
|
@@ -27,11 +32,11 @@ export declare function initializeChildListener(): void;
|
|
|
27
32
|
* Automatically resize the selected iframes when their inner content grows.
|
|
28
33
|
* @param settings The settings for the selected iframes. The default settings properties are picked if empty.
|
|
29
34
|
* @param selector The selector for the iframe(s) or the HTMLIFrameElement to be resized. If empty, all document iframe elements will be selected.
|
|
30
|
-
* @returns A result array, which can be used to clean up the listeners if you
|
|
35
|
+
* @returns A result array Promise, which can be used to clean up the listeners if you remove iframes from the document and want to clean all associated listeners.
|
|
31
36
|
*/
|
|
32
|
-
export declare type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => InitializeResult[]
|
|
37
|
+
export declare type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => Promise<InitializeResult[]>;
|
|
33
38
|
|
|
34
|
-
export declare type InitializeResult = { unsubscribe: () => void };
|
|
39
|
+
export declare type InitializeResult = { unsubscribe: () => void; resize: () => void };
|
|
35
40
|
|
|
36
41
|
export declare type InteractionState = {
|
|
37
42
|
isHovered: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
const v = () => typeof window < "u",
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const v = () => typeof window < "u", C = () => {
|
|
2
|
+
try {
|
|
3
|
+
return window.self !== window.top;
|
|
4
|
+
} catch {
|
|
5
|
+
return !0;
|
|
6
|
+
}
|
|
7
|
+
}, w = (e) => e instanceof HTMLIFrameElement, z = (e) => {
|
|
8
|
+
window.document.readyState === "complete" ? e() : window.addEventListener("load", e, { once: !0 });
|
|
9
|
+
}, B = (e, t) => {
|
|
10
|
+
t(), e.addEventListener("load", t, { once: !0 });
|
|
11
|
+
}, k = (e, t) => {
|
|
6
12
|
const n = e.contentWindow?.document.readyState === "complete";
|
|
7
|
-
return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t);
|
|
8
|
-
},
|
|
13
|
+
return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t, { once: !0 });
|
|
14
|
+
}, W = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 });
|
|
15
|
+
async function A(e) {
|
|
9
16
|
try {
|
|
10
|
-
return new
|
|
17
|
+
return e.contentDocument?.URL === "about:blank" ? new Promise((n) => {
|
|
18
|
+
e.addEventListener("load", () => n(e.contentDocument !== null), { once: !0 });
|
|
19
|
+
}) : e.contentDocument !== null;
|
|
11
20
|
} catch {
|
|
12
21
|
return !1;
|
|
13
22
|
}
|
|
14
|
-
}
|
|
23
|
+
}
|
|
24
|
+
const P = (e) => {
|
|
15
25
|
try {
|
|
16
26
|
const t = new URL(e.src).origin;
|
|
17
27
|
if (t !== "about:blank")
|
|
@@ -19,182 +29,208 @@ const v = () => typeof window < "u", S = () => window.self !== window.top, y = (
|
|
|
19
29
|
} catch {
|
|
20
30
|
}
|
|
21
31
|
return null;
|
|
22
|
-
},
|
|
32
|
+
}, H = (e) => (Object.keys(e).forEach((t) => {
|
|
23
33
|
e[t] === void 0 && delete e[t];
|
|
24
|
-
}), e),
|
|
34
|
+
}), e), I = (e) => {
|
|
25
35
|
const { height: t, width: n } = e.getBoundingClientRect();
|
|
26
36
|
return { height: Math.ceil(t), width: Math.ceil(n) };
|
|
27
|
-
},
|
|
37
|
+
}, l = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, O = (e, t) => {
|
|
28
38
|
e && (t.bodyPadding && (e.body.style.padding = t.bodyPadding), t.bodyMargin && (e.body.style.margin = t.bodyMargin));
|
|
29
|
-
},
|
|
30
|
-
function
|
|
39
|
+
}, b = (e) => e <= 100 ? 100 : e <= 120 ? 1e3 : 1e4, x = () => "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";
|
|
40
|
+
function F(e) {
|
|
31
41
|
if (typeof e.data != "string" || !e.data.startsWith("[iFrameSizer]") || !e.data.endsWith("mutationObserver") && !e.data.endsWith("resizeObserver"))
|
|
32
42
|
return null;
|
|
33
43
|
const [t, n] = e.data.split(":"), i = +n;
|
|
34
44
|
return i > 0 ? i : null;
|
|
35
45
|
}
|
|
36
|
-
const
|
|
37
|
-
let
|
|
38
|
-
const
|
|
46
|
+
const p = V();
|
|
47
|
+
let m = [];
|
|
48
|
+
const Z = async (e, t) => {
|
|
39
49
|
if (!v())
|
|
40
50
|
return [];
|
|
41
|
-
const n = { ...
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
const n = { ...W(), ...H(e ?? {}) }, i = N(t), r = U(n, i);
|
|
52
|
+
return Promise.all(
|
|
53
|
+
i.map(async (s) => {
|
|
54
|
+
const o = {
|
|
55
|
+
iframe: s,
|
|
56
|
+
settings: n,
|
|
57
|
+
interactionState: { isHovered: !1 },
|
|
58
|
+
initContext: { isInitialized: !1, retryAttempts: 0 }
|
|
59
|
+
}, { unsubscribe: c, resize: u } = await $(o, r);
|
|
60
|
+
return m.push(o), {
|
|
61
|
+
unsubscribe: () => {
|
|
62
|
+
c(), m = m.filter((f) => f.iframe !== s);
|
|
63
|
+
},
|
|
64
|
+
resize: u
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
);
|
|
55
68
|
};
|
|
56
|
-
function
|
|
57
|
-
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(
|
|
69
|
+
function N(e) {
|
|
70
|
+
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(w) : e ? w(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
|
|
58
71
|
}
|
|
59
|
-
function
|
|
72
|
+
function U(e, t) {
|
|
60
73
|
if (Array.isArray(e.checkOrigin))
|
|
61
74
|
return e.checkOrigin;
|
|
62
75
|
if (!e.checkOrigin)
|
|
63
76
|
return [];
|
|
64
77
|
const n = [];
|
|
65
78
|
for (const i of t) {
|
|
66
|
-
const
|
|
67
|
-
|
|
79
|
+
const r = P(i);
|
|
80
|
+
r && n.push(r);
|
|
68
81
|
}
|
|
69
82
|
return n;
|
|
70
83
|
}
|
|
71
|
-
function
|
|
72
|
-
const n =
|
|
73
|
-
return
|
|
74
|
-
|
|
84
|
+
async function $(e, t) {
|
|
85
|
+
const n = await A(e.iframe), { unsubscribe: i, resize: r } = n ? _(e) : q(e, t), s = G(e);
|
|
86
|
+
return {
|
|
87
|
+
unsubscribe: () => {
|
|
88
|
+
i(), s();
|
|
89
|
+
},
|
|
90
|
+
resize: r
|
|
75
91
|
};
|
|
76
92
|
}
|
|
77
|
-
function
|
|
93
|
+
function q(e, t) {
|
|
78
94
|
const {
|
|
79
95
|
iframe: n,
|
|
80
96
|
initContext: i,
|
|
81
|
-
settings: { checkOrigin:
|
|
82
|
-
} = e,
|
|
83
|
-
const
|
|
84
|
-
if (!(!(n.contentWindow ===
|
|
85
|
-
if (
|
|
86
|
-
const { height:
|
|
87
|
-
|
|
97
|
+
settings: { checkOrigin: r, enableLegacyLibSupport: s, targetElementSelector: o, bodyPadding: c, bodyMargin: u }
|
|
98
|
+
} = e, f = (a) => {
|
|
99
|
+
const T = a.origin === "null", D = !r || T || t.includes(a.origin);
|
|
100
|
+
if (!(!(n.contentWindow === a.source) || !D)) {
|
|
101
|
+
if (a.data?.type === "iframe-resized") {
|
|
102
|
+
const { height: d } = a.data;
|
|
103
|
+
d && g({ newHeight: d, registeredElement: e });
|
|
88
104
|
return;
|
|
89
105
|
}
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
92
|
-
|
|
106
|
+
if (s) {
|
|
107
|
+
const d = F(a);
|
|
108
|
+
d !== null && g({ newHeight: d, registeredElement: e });
|
|
93
109
|
return;
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
};
|
|
97
|
-
window.addEventListener("message",
|
|
98
|
-
const
|
|
99
|
-
|
|
113
|
+
window.addEventListener("message", f);
|
|
114
|
+
const M = s ? x() : { type: "iframe-child-init", targetElementSelector: o, bodyPadding: c, bodyMargin: u }, y = () => {
|
|
115
|
+
B(n, () => n.contentWindow?.postMessage(M, "*")), i.retryAttempts++, i.retryTimeoutId = window.setTimeout(y, b(i.retryAttempts));
|
|
116
|
+
};
|
|
117
|
+
return y(), {
|
|
118
|
+
unsubscribe: () => window.removeEventListener("message", f),
|
|
119
|
+
resize: () => {
|
|
120
|
+
const a = { type: "iframe-get-child-dimensions" };
|
|
121
|
+
n.contentWindow?.postMessage(a, "*");
|
|
122
|
+
}
|
|
100
123
|
};
|
|
101
|
-
return w(), () => window.removeEventListener("message", h);
|
|
102
124
|
}
|
|
103
|
-
function
|
|
125
|
+
function _(e) {
|
|
104
126
|
const { iframe: t, settings: n } = e, { targetElementSelector: i } = n;
|
|
105
|
-
let
|
|
106
|
-
const
|
|
107
|
-
const o =
|
|
127
|
+
let r = 0;
|
|
128
|
+
const s = () => {
|
|
129
|
+
const o = l(t.contentDocument, i);
|
|
108
130
|
if (!t.contentDocument || !o)
|
|
109
|
-
return
|
|
110
|
-
|
|
131
|
+
return r++, setTimeout(s, b(r));
|
|
132
|
+
O(t.contentDocument, n), p().observe(o);
|
|
111
133
|
};
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
return k(t, s), {
|
|
135
|
+
unsubscribe: () => {
|
|
136
|
+
const o = l(t.contentDocument, i);
|
|
137
|
+
o && p().unobserve(o);
|
|
138
|
+
},
|
|
139
|
+
resize: () => L(e)
|
|
115
140
|
};
|
|
116
141
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
142
|
+
function G({ iframe: e, interactionState: t, settings: n }) {
|
|
143
|
+
if (!n.onBeforeIframeResize && !n.onIframeResize)
|
|
144
|
+
return () => {
|
|
145
|
+
};
|
|
146
|
+
const i = () => {
|
|
119
147
|
t.isHovered = !0;
|
|
120
|
-
},
|
|
148
|
+
}, r = () => {
|
|
121
149
|
t.isHovered = !1;
|
|
122
150
|
};
|
|
123
|
-
return e.addEventListener("mouseenter",
|
|
124
|
-
e.removeEventListener("mouseenter",
|
|
151
|
+
return e.addEventListener("mouseenter", i), e.addEventListener("mouseleave", r), () => {
|
|
152
|
+
e.removeEventListener("mouseenter", i), e.removeEventListener("mouseleave", r);
|
|
125
153
|
};
|
|
126
154
|
}
|
|
127
|
-
function
|
|
155
|
+
function V() {
|
|
128
156
|
let e = null;
|
|
129
157
|
return () => {
|
|
130
158
|
if (!e) {
|
|
131
159
|
const t = ({ target: n }) => {
|
|
132
|
-
const i =
|
|
133
|
-
|
|
134
|
-
return;
|
|
135
|
-
const { iframe: s, settings: r } = i, o = f(s.contentDocument, r.targetElementSelector);
|
|
136
|
-
if (!o)
|
|
137
|
-
return;
|
|
138
|
-
const { height: a } = p(o);
|
|
139
|
-
a && g({ newHeight: a, registeredElement: i });
|
|
160
|
+
const i = m.find(({ iframe: r }) => r.contentDocument === n.ownerDocument);
|
|
161
|
+
i && L(i);
|
|
140
162
|
};
|
|
141
163
|
e = new ResizeObserver((n) => n.forEach(t));
|
|
142
164
|
}
|
|
143
165
|
return e;
|
|
144
166
|
};
|
|
145
167
|
}
|
|
168
|
+
function L(e) {
|
|
169
|
+
const { iframe: t, settings: n } = e, i = l(t.contentDocument, n.targetElementSelector);
|
|
170
|
+
if (!i)
|
|
171
|
+
return;
|
|
172
|
+
const { height: r } = I(i);
|
|
173
|
+
r && g({ newHeight: r, registeredElement: e });
|
|
174
|
+
}
|
|
146
175
|
function g({ registeredElement: e, newHeight: t }) {
|
|
147
|
-
const { iframe: n, settings: i, interactionState:
|
|
148
|
-
if (
|
|
176
|
+
const { iframe: n, settings: i, interactionState: r, initContext: s } = e;
|
|
177
|
+
if (s.isInitialized || (s.isInitialized = !0, clearTimeout(s.retryTimeoutId)), i.onBeforeIframeResize?.({ iframe: n, interactionState: { ...r }, settings: { ...i }, observedHeight: t }) === !1)
|
|
149
178
|
return;
|
|
150
|
-
const o = n.getBoundingClientRect(),
|
|
151
|
-
if (n.style.height = `${
|
|
179
|
+
const o = n.getBoundingClientRect(), c = t + i.offsetSize;
|
|
180
|
+
if (n.style.height = `${c}px`, !i.onIframeResize)
|
|
152
181
|
return;
|
|
153
|
-
const
|
|
182
|
+
const u = {
|
|
154
183
|
iframe: n,
|
|
155
184
|
settings: { ...i },
|
|
156
|
-
interactionState: { ...
|
|
185
|
+
interactionState: { ...r },
|
|
157
186
|
previousRenderState: { rect: o },
|
|
158
187
|
nextRenderState: { rect: n.getBoundingClientRect() }
|
|
159
188
|
};
|
|
160
|
-
i.onIframeResize(
|
|
189
|
+
i.onIframeResize(u);
|
|
161
190
|
}
|
|
162
|
-
const
|
|
163
|
-
let
|
|
164
|
-
|
|
165
|
-
function
|
|
166
|
-
!v() || !
|
|
167
|
-
e.data?.type === "iframe-child-init"
|
|
191
|
+
const J = X();
|
|
192
|
+
let h = !1, R;
|
|
193
|
+
K();
|
|
194
|
+
function K() {
|
|
195
|
+
!v() || !C() || window.addEventListener("message", (e) => {
|
|
196
|
+
if (e.data?.type === "iframe-child-init")
|
|
197
|
+
return z(() => S(e));
|
|
198
|
+
if (e.data?.type === "iframe-get-child-dimensions")
|
|
199
|
+
return z(() => Q(e));
|
|
168
200
|
});
|
|
169
201
|
}
|
|
170
|
-
function
|
|
171
|
-
const { targetElementSelector: n, bodyPadding: i, bodyMargin:
|
|
172
|
-
if (
|
|
202
|
+
function S(e, t = 0) {
|
|
203
|
+
const { targetElementSelector: n, bodyPadding: i, bodyMargin: r } = e.data, s = l(document, n);
|
|
204
|
+
if (h || window.parent !== e.source)
|
|
173
205
|
return;
|
|
174
|
-
if (!
|
|
175
|
-
return setTimeout(() =>
|
|
176
|
-
|
|
177
|
-
const o =
|
|
178
|
-
o.disconnect(), o.observe(
|
|
206
|
+
if (!s)
|
|
207
|
+
return setTimeout(() => S(e, t + 1), b(t));
|
|
208
|
+
O(document, { bodyMargin: r, bodyPadding: i }), R = n;
|
|
209
|
+
const o = J();
|
|
210
|
+
o.disconnect(), o.observe(s), h = !0;
|
|
179
211
|
}
|
|
180
|
-
function
|
|
212
|
+
function Q(e) {
|
|
213
|
+
const t = l(document, R);
|
|
214
|
+
!h || window.parent !== e.source || !t || E(t);
|
|
215
|
+
}
|
|
216
|
+
function X() {
|
|
181
217
|
let e = null;
|
|
182
218
|
return () => (e || (e = new ResizeObserver((t) => {
|
|
183
|
-
|
|
184
|
-
return;
|
|
185
|
-
const { height: n, width: i } = p(t[0].target), s = {
|
|
186
|
-
type: "iframe-resized",
|
|
187
|
-
width: i,
|
|
188
|
-
height: n
|
|
189
|
-
};
|
|
190
|
-
window.parent.postMessage(s, "*");
|
|
219
|
+
t[0].target && E(t[0].target);
|
|
191
220
|
})), e);
|
|
192
221
|
}
|
|
193
|
-
const
|
|
222
|
+
const E = (e) => {
|
|
223
|
+
const { width: t, height: n } = I(e), i = {
|
|
224
|
+
type: "iframe-resized",
|
|
225
|
+
width: t,
|
|
226
|
+
height: n
|
|
227
|
+
};
|
|
228
|
+
window.parent.postMessage(i, "*");
|
|
229
|
+
}, j = ({ previousRenderState: e, nextRenderState: t, iframe: n }) => {
|
|
194
230
|
document.activeElement === n && window.scrollBy(0, t.rect.bottom - e.rect.bottom);
|
|
195
231
|
};
|
|
196
232
|
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
233
|
+
Z as initialize,
|
|
234
|
+
K as initializeChildListener,
|
|
235
|
+
j as updateParentScrollOnResize
|
|
200
236
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.iframeResizer={}))})(this,function(a){"use strict";const u=()=>typeof window<"u",
|
|
1
|
+
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.iframeResizer={}))})(this,function(a){"use strict";const u=()=>typeof window<"u",C=()=>{try{return window.self!==window.top}catch{return!0}},w=e=>e instanceof HTMLIFrameElement,p=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e,{once:!0})},D=(e,t)=>{t(),e.addEventListener("load",t,{once:!0})},B=(e,t)=>{const n=e.contentWindow?.document.readyState==="complete";return e.src!=="about:blank"&&e.contentWindow?.location.href!=="about:blank"&&n?t():e.addEventListener("load",t,{once:!0})},k=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1});async function P(e){try{return e.contentDocument?.URL==="about:blank"?new Promise(n=>{e.addEventListener("load",()=>n(e.contentDocument!==null),{once:!0})}):e.contentDocument!==null}catch{return!1}}const W=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},A=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&delete e[t]}),e),O=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},d=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,v=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},b=e=>e<=100?100:e<=120?1e3:1e4,H=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function x(e){if(typeof e.data!="string"||!e.data.startsWith("[iFrameSizer]")||!e.data.endsWith("mutationObserver")&&!e.data.endsWith("resizeObserver"))return null;const[t,n]=e.data.split(":"),i=+n;return i>0?i:null}const I=V();let g=[];const F=async(e,t)=>{if(!u())return[];const n={...k(),...A(e??{})},i=N(t),r=U(n,i);return Promise.all(i.map(async s=>{const o={iframe:s,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},{unsubscribe:l,resize:f}=await $(o,r);return g.push(o),{unsubscribe:()=>{l(),g=g.filter(h=>h.iframe!==s)},resize:f}}))};function N(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(w):e?w(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function U(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const i of t){const r=W(i);r&&n.push(r)}return n}async function $(e,t){const n=await P(e.iframe),{unsubscribe:i,resize:r}=n?_(e):q(e,t),s=G(e);return{unsubscribe:()=>{i(),s()},resize:r}}function q(e,t){const{iframe:n,initContext:i,settings:{checkOrigin:r,enableLegacyLibSupport:s,targetElementSelector:o,bodyPadding:l,bodyMargin:f}}=e,h=c=>{const Y=c.origin==="null",Z=!r||Y||t.includes(c.origin);if(!(!(n.contentWindow===c.source)||!Z)){if(c.data?.type==="iframe-resized"){const{height:m}=c.data;m&&y({newHeight:m,registeredElement:e});return}if(s){const m=x(c);m!==null&&y({newHeight:m,registeredElement:e});return}}};window.addEventListener("message",h);const X=s?H():{type:"iframe-child-init",targetElementSelector:o,bodyPadding:l,bodyMargin:f},T=()=>{D(n,()=>n.contentWindow?.postMessage(X,"*")),i.retryAttempts++,i.retryTimeoutId=window.setTimeout(T,b(i.retryAttempts))};return T(),{unsubscribe:()=>window.removeEventListener("message",h),resize:()=>{const c={type:"iframe-get-child-dimensions"};n.contentWindow?.postMessage(c,"*")}}}function _(e){const{iframe:t,settings:n}=e,{targetElementSelector:i}=n;let r=0;const s=()=>{const o=d(t.contentDocument,i);if(!t.contentDocument||!o)return r++,setTimeout(s,b(r));v(t.contentDocument,n),I().observe(o)};return B(t,s),{unsubscribe:()=>{const o=d(t.contentDocument,i);o&&I().unobserve(o)},resize:()=>L(e)}}function G({iframe:e,interactionState:t,settings:n}){if(!n.onBeforeIframeResize&&!n.onIframeResize)return()=>{};const i=()=>{t.isHovered=!0},r=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",r),()=>{e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",r)}}function V(){let e=null;return()=>{if(!e){const t=({target:n})=>{const i=g.find(({iframe:r})=>r.contentDocument===n.ownerDocument);i&&L(i)};e=new ResizeObserver(n=>n.forEach(t))}return e}}function L(e){const{iframe:t,settings:n}=e,i=d(t.contentDocument,n.targetElementSelector);if(!i)return;const{height:r}=O(i);r&&y({newHeight:r,registeredElement:e})}function y({registeredElement:e,newHeight:t}){const{iframe:n,settings:i,interactionState:r,initContext:s}=e;if(s.isInitialized||(s.isInitialized=!0,clearTimeout(s.retryTimeoutId)),i.onBeforeIframeResize?.({iframe:n,interactionState:{...r},settings:{...i},observedHeight:t})===!1)return;const o=n.getBoundingClientRect(),l=t+i.offsetSize;if(n.style.height=`${l}px`,!i.onIframeResize)return;const f={iframe:n,settings:{...i},interactionState:{...r},previousRenderState:{rect:o},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(f)}const j=K();let z=!1,R;S();function S(){!u()||!C()||window.addEventListener("message",e=>{if(e.data?.type==="iframe-child-init")return p(()=>E(e));if(e.data?.type==="iframe-get-child-dimensions")return p(()=>J(e))})}function E(e,t=0){const{targetElementSelector:n,bodyPadding:i,bodyMargin:r}=e.data,s=d(document,n);if(z||window.parent!==e.source)return;if(!s)return setTimeout(()=>E(e,t+1),b(t));v(document,{bodyMargin:r,bodyPadding:i}),R=n;const o=j();o.disconnect(),o.observe(s),z=!0}function J(e){const t=d(document,R);!z||window.parent!==e.source||!t||M(t)}function K(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{t[0].target&&M(t[0].target)})),e)}const M=e=>{const{width:t,height:n}=O(e),i={type:"iframe-resized",width:t,height:n};window.parent.postMessage(i,"*")},Q=({previousRenderState:e,nextRenderState:t,iframe:n})=>{document.activeElement===n&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)};a.initialize=F,a.initializeChildListener=S,a.updateParentScrollOnResize=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|