@open-iframe-resizer/core 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +126 -102
- 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@v2.
|
|
20
|
+
import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@v2.2.0/dist/index.min.js";
|
|
21
21
|
|
|
22
22
|
initialize({}, "#my-iframe");
|
|
23
23
|
</script>
|
|
@@ -45,6 +45,12 @@ npm install @open-iframe-resizer/react
|
|
|
45
45
|
npm install @open-iframe-resizer/vue
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### Angular
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @open-iframe-resizer/angular
|
|
52
|
+
```
|
|
53
|
+
|
|
48
54
|
## Full documentation
|
|
49
55
|
|
|
50
56
|
Explore the [full documentation](https://lemick.github.io/open-iframe-resizer/guides/getting-started/#_top)
|
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 = {
|
|
@@ -31,7 +36,7 @@ export declare function initializeChildListener(): void;
|
|
|
31
36
|
*/
|
|
32
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,18 +1,18 @@
|
|
|
1
|
-
const
|
|
1
|
+
const v = () => typeof window < "u", C = () => {
|
|
2
2
|
try {
|
|
3
3
|
return window.self !== window.top;
|
|
4
4
|
} catch {
|
|
5
5
|
return !0;
|
|
6
6
|
}
|
|
7
|
-
},
|
|
7
|
+
}, w = (e) => e instanceof HTMLIFrameElement, z = (e) => {
|
|
8
8
|
window.document.readyState === "complete" ? e() : window.addEventListener("load", e, { once: !0 });
|
|
9
|
-
},
|
|
9
|
+
}, B = (e, t) => {
|
|
10
10
|
t(), e.addEventListener("load", t, { once: !0 });
|
|
11
|
-
},
|
|
11
|
+
}, k = (e, t) => {
|
|
12
12
|
const n = e.contentWindow?.document.readyState === "complete";
|
|
13
13
|
return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t, { once: !0 });
|
|
14
|
-
},
|
|
15
|
-
async function
|
|
14
|
+
}, W = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 });
|
|
15
|
+
async function A(e) {
|
|
16
16
|
try {
|
|
17
17
|
return e.contentDocument?.URL === "about:blank" ? new Promise((n) => {
|
|
18
18
|
e.addEventListener("load", () => n(e.contentDocument !== null), { once: !0 });
|
|
@@ -21,7 +21,7 @@ async function k(e) {
|
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const P = (e) => {
|
|
25
25
|
try {
|
|
26
26
|
const t = new URL(e.src).origin;
|
|
27
27
|
if (t !== "about:blank")
|
|
@@ -29,184 +29,208 @@ const B = (e) => {
|
|
|
29
29
|
} catch {
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
|
-
},
|
|
32
|
+
}, H = (e) => (Object.keys(e).forEach((t) => {
|
|
33
33
|
e[t] === void 0 && delete e[t];
|
|
34
|
-
}), e),
|
|
34
|
+
}), e), I = (e) => {
|
|
35
35
|
const { height: t, width: n } = e.getBoundingClientRect();
|
|
36
36
|
return { height: Math.ceil(t), width: Math.ceil(n) };
|
|
37
|
-
},
|
|
37
|
+
}, l = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, O = (e, t) => {
|
|
38
38
|
e && (t.bodyPadding && (e.body.style.padding = t.bodyPadding), t.bodyMargin && (e.body.style.margin = t.bodyMargin));
|
|
39
|
-
},
|
|
40
|
-
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) {
|
|
41
41
|
if (typeof e.data != "string" || !e.data.startsWith("[iFrameSizer]") || !e.data.endsWith("mutationObserver") && !e.data.endsWith("resizeObserver"))
|
|
42
42
|
return null;
|
|
43
43
|
const [t, n] = e.data.split(":"), i = +n;
|
|
44
44
|
return i > 0 ? i : null;
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
let
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
46
|
+
const p = V();
|
|
47
|
+
let m = [];
|
|
48
|
+
const Z = async (e, t) => {
|
|
49
|
+
if (!v())
|
|
50
50
|
return [];
|
|
51
|
-
const n = { ...
|
|
51
|
+
const n = { ...W(), ...H(e ?? {}) }, i = N(t), r = U(n, i);
|
|
52
52
|
return Promise.all(
|
|
53
|
-
i.map(async (
|
|
54
|
-
const
|
|
55
|
-
iframe:
|
|
53
|
+
i.map(async (s) => {
|
|
54
|
+
const o = {
|
|
55
|
+
iframe: s,
|
|
56
56
|
settings: n,
|
|
57
57
|
interactionState: { isHovered: !1 },
|
|
58
58
|
initContext: { isInitialized: !1, retryAttempts: 0 }
|
|
59
|
-
},
|
|
60
|
-
return
|
|
59
|
+
}, { unsubscribe: c, resize: u } = await $(o, r);
|
|
60
|
+
return m.push(o), {
|
|
61
61
|
unsubscribe: () => {
|
|
62
|
-
|
|
63
|
-
}
|
|
62
|
+
c(), m = m.filter((f) => f.iframe !== s);
|
|
63
|
+
},
|
|
64
|
+
resize: u
|
|
64
65
|
};
|
|
65
66
|
})
|
|
66
67
|
);
|
|
67
68
|
};
|
|
68
|
-
function
|
|
69
|
-
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"));
|
|
70
71
|
}
|
|
71
|
-
function
|
|
72
|
+
function U(e, t) {
|
|
72
73
|
if (Array.isArray(e.checkOrigin))
|
|
73
74
|
return e.checkOrigin;
|
|
74
75
|
if (!e.checkOrigin)
|
|
75
76
|
return [];
|
|
76
77
|
const n = [];
|
|
77
78
|
for (const i of t) {
|
|
78
|
-
const r =
|
|
79
|
+
const r = P(i);
|
|
79
80
|
r && n.push(r);
|
|
80
81
|
}
|
|
81
82
|
return n;
|
|
82
83
|
}
|
|
83
|
-
async function
|
|
84
|
-
const
|
|
85
|
-
return
|
|
86
|
-
|
|
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
|
|
87
91
|
};
|
|
88
92
|
}
|
|
89
|
-
function
|
|
93
|
+
function q(e, t) {
|
|
90
94
|
const {
|
|
91
95
|
iframe: n,
|
|
92
96
|
initContext: i,
|
|
93
|
-
settings: { checkOrigin: r, enableLegacyLibSupport:
|
|
94
|
-
} = e,
|
|
95
|
-
const
|
|
96
|
-
if (!(!(n.contentWindow ===
|
|
97
|
-
if (
|
|
98
|
-
const { height: d } =
|
|
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;
|
|
99
103
|
d && g({ newHeight: d, registeredElement: e });
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
|
-
if (
|
|
103
|
-
const d =
|
|
106
|
+
if (s) {
|
|
107
|
+
const d = F(a);
|
|
104
108
|
d !== null && g({ newHeight: d, registeredElement: e });
|
|
105
109
|
return;
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
|
-
window.addEventListener("message",
|
|
110
|
-
const
|
|
111
|
-
|
|
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
|
+
}
|
|
112
123
|
};
|
|
113
|
-
return y(), () => window.removeEventListener("message", h);
|
|
114
124
|
}
|
|
115
|
-
function
|
|
125
|
+
function _(e) {
|
|
116
126
|
const { iframe: t, settings: n } = e, { targetElementSelector: i } = n;
|
|
117
127
|
let r = 0;
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
if (!t.contentDocument || !
|
|
121
|
-
return r++, setTimeout(
|
|
122
|
-
|
|
128
|
+
const s = () => {
|
|
129
|
+
const o = l(t.contentDocument, i);
|
|
130
|
+
if (!t.contentDocument || !o)
|
|
131
|
+
return r++, setTimeout(s, b(r));
|
|
132
|
+
O(t.contentDocument, n), p().observe(o);
|
|
123
133
|
};
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
return k(t, s), {
|
|
135
|
+
unsubscribe: () => {
|
|
136
|
+
const o = l(t.contentDocument, i);
|
|
137
|
+
o && p().unobserve(o);
|
|
138
|
+
},
|
|
139
|
+
resize: () => L(e)
|
|
127
140
|
};
|
|
128
141
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
142
|
+
function G({ iframe: e, interactionState: t, settings: n }) {
|
|
143
|
+
if (!n.onBeforeIframeResize && !n.onIframeResize)
|
|
144
|
+
return () => {
|
|
145
|
+
};
|
|
146
|
+
const i = () => {
|
|
131
147
|
t.isHovered = !0;
|
|
132
|
-
},
|
|
148
|
+
}, r = () => {
|
|
133
149
|
t.isHovered = !1;
|
|
134
150
|
};
|
|
135
|
-
return e.addEventListener("mouseenter",
|
|
136
|
-
e.removeEventListener("mouseenter",
|
|
151
|
+
return e.addEventListener("mouseenter", i), e.addEventListener("mouseleave", r), () => {
|
|
152
|
+
e.removeEventListener("mouseenter", i), e.removeEventListener("mouseleave", r);
|
|
137
153
|
};
|
|
138
154
|
}
|
|
139
|
-
function
|
|
155
|
+
function V() {
|
|
140
156
|
let e = null;
|
|
141
157
|
return () => {
|
|
142
158
|
if (!e) {
|
|
143
159
|
const t = ({ target: n }) => {
|
|
144
|
-
const i =
|
|
145
|
-
|
|
146
|
-
return;
|
|
147
|
-
const { iframe: r, settings: o } = i, s = f(r.contentDocument, o.targetElementSelector);
|
|
148
|
-
if (!s)
|
|
149
|
-
return;
|
|
150
|
-
const { height: a } = p(s);
|
|
151
|
-
a && g({ newHeight: a, registeredElement: i });
|
|
160
|
+
const i = m.find(({ iframe: r }) => r.contentDocument === n.ownerDocument);
|
|
161
|
+
i && L(i);
|
|
152
162
|
};
|
|
153
163
|
e = new ResizeObserver((n) => n.forEach(t));
|
|
154
164
|
}
|
|
155
165
|
return e;
|
|
156
166
|
};
|
|
157
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
|
+
}
|
|
158
175
|
function g({ registeredElement: e, newHeight: t }) {
|
|
159
|
-
const { iframe: n, settings: i, interactionState: r, initContext:
|
|
160
|
-
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)
|
|
161
178
|
return;
|
|
162
|
-
const
|
|
163
|
-
if (n.style.height = `${
|
|
179
|
+
const o = n.getBoundingClientRect(), c = t + i.offsetSize;
|
|
180
|
+
if (n.style.height = `${c}px`, !i.onIframeResize)
|
|
164
181
|
return;
|
|
165
|
-
const
|
|
182
|
+
const u = {
|
|
166
183
|
iframe: n,
|
|
167
184
|
settings: { ...i },
|
|
168
185
|
interactionState: { ...r },
|
|
169
|
-
previousRenderState: { rect:
|
|
186
|
+
previousRenderState: { rect: o },
|
|
170
187
|
nextRenderState: { rect: n.getBoundingClientRect() }
|
|
171
188
|
};
|
|
172
|
-
i.onIframeResize(
|
|
189
|
+
i.onIframeResize(u);
|
|
173
190
|
}
|
|
174
|
-
const
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
function
|
|
178
|
-
!
|
|
179
|
-
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));
|
|
180
200
|
});
|
|
181
201
|
}
|
|
182
|
-
function
|
|
183
|
-
const { targetElementSelector: n, bodyPadding: i, bodyMargin: r } = e.data,
|
|
184
|
-
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)
|
|
185
205
|
return;
|
|
186
|
-
if (!
|
|
187
|
-
return setTimeout(() =>
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
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;
|
|
211
|
+
}
|
|
212
|
+
function Q(e) {
|
|
213
|
+
const t = l(document, R);
|
|
214
|
+
!h || window.parent !== e.source || !t || E(t);
|
|
191
215
|
}
|
|
192
|
-
function
|
|
216
|
+
function X() {
|
|
193
217
|
let e = null;
|
|
194
218
|
return () => (e || (e = new ResizeObserver((t) => {
|
|
195
|
-
|
|
196
|
-
return;
|
|
197
|
-
const { height: n, width: i } = p(t[0].target), r = {
|
|
198
|
-
type: "iframe-resized",
|
|
199
|
-
width: i,
|
|
200
|
-
height: n
|
|
201
|
-
};
|
|
202
|
-
window.parent.postMessage(r, "*");
|
|
219
|
+
t[0].target && E(t[0].target);
|
|
203
220
|
})), e);
|
|
204
221
|
}
|
|
205
|
-
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 }) => {
|
|
206
230
|
document.activeElement === n && window.scrollBy(0, t.rect.bottom - e.rect.bottom);
|
|
207
231
|
};
|
|
208
232
|
export {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
233
|
+
Z as initialize,
|
|
234
|
+
K as initializeChildListener,
|
|
235
|
+
j as updateParentScrollOnResize
|
|
212
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"})}));
|