@iframe-resizer/core 6.0.0-beta.4 → 6.0.0-beta.6

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/index.esm.js CHANGED
@@ -1,967 +1,21 @@
1
- import { PARENT as H, LABEL as ce, BOLD as Ge, AUTO as F, VERTICAL as x, COLLAPSE as S, LOG_COLLAPSED as ae, LOG_EXPANDED as fe, EXPAND as v, LOG_DISABLED as le, MESSAGE_ID as W, INIT_EVENTS as Z, SEPARATOR as R, RESIZE as ue, MESSAGE_ID_LENGTH as G, VERSION as C, FUNCTION as Ue, MESSAGE_HEADER_LENGTH as Ve, HEIGHT as je, WIDTH as qe, INIT as P, RESET as U, LOAD as V, SCROLL as X, PAGE_INFO as ge, PARENT_INFO as de, TITLE as Ye, SCROLL_TO_OFFSET as Ze, SCROLL_TO as Xe, SCROLL_BY as Je, PARENT_INFO_STOP as Ke, PAGE_INFO_STOP as Qe, MOUSE_LEAVE as et, MOUSE_ENTER as tt, MESSAGE as z, IN_PAGE_LINK as nt, CLOSE as ot, BEFORE_UNLOAD as it, AUTO_RESIZE as he, CHILD_READY_MESSAGE as rt, STRING as me, NEW_LINE as D, CHILD as st, NUMBER as ct, OBJECT as at, INIT_FROM_IFRAME as ft, LAZY as lt, RESET_REQUIRED_METHODS as ut, MIN_SIZE as J, ONLOAD as gt, HORIZONTAL as pe, BOTH as be, NONE as we, REMOVED_NEXT_VERSION as dt, OFFSET_SIZE as ht, OFFSET as mt, HIDDEN as pt, OMIT as bt, LOG_OPTIONS as wt } from "@iframe-resizer/common/consts";
2
- import { LOG_COLLAPSED as $o, LOG_DISABLED as Mo, LOG_EXPANDED as Lo } from "@iframe-resizer/common/consts";
3
- import { esModuleInterop as Et, id as Ot, isString as Ee, isIframe as Tt, isolateUserCode as It, once as yt, typeAssert as $t, hasOwn as k, isObject as Mt } from "@iframe-resizer/common/utils";
4
- import Lt from "@iframe-resizer/common/deprecate";
5
- import Oe from "@iframe-resizer/common/format-advise";
6
- import St, { NORMAL as vt, HIGHLIGHT as a, FOREGROUND as E } from "auto-console-group";
7
- import { addEventListener as A, removeEventListener as K } from "@iframe-resizer/common/listeners";
8
- import Rt, { getModeData as I, getModeLabel as kt } from "@iframe-resizer/common/mode";
9
- const o = {}, Te = Et(St);
10
- let q = !0;
11
- const At = Te({
12
- expand: !1,
13
- label: H
14
- }), Pt = (e) => window.top === window.self ? `parent(${e})` : `nested parent(${e})`, Nt = (e) => o[e] ? o[e].log : q;
15
- function Ct({
16
- enabled: e,
17
- expand: t,
18
- iframeId: n
19
- }) {
20
- const i = Te({
21
- expand: t,
22
- label: Pt(n)
23
- });
24
- q = e, o[n] || (o[n] = {
25
- console: i
26
- });
27
- }
28
- const $ = (e) => (t, ...n) => o[t] ? o[t].console[e](...n) : At[e](...n), Ie = (e) => (t, ...n) => Nt(t) === !0 ? $(e)(t, ...n) : null, l = Ie("log"), b = l, zt = Ie("debug"), O = $("warn"), _t = $("error"), w = $("event"), xt = $("purge"), Dt = $("endAutoGroup"), ye = $("errorBoundary");
29
- function Bt(e, t) {
30
- queueMicrotask(
31
- () => (
32
- // eslint-disable-next-line no-console
33
- console.info(
34
- `%ciframe-resizer ${e}`,
35
- q || t < 1 ? Ge : vt
36
- )
37
- )
38
- );
39
- }
40
- const Ht = (e) => (...t) => [`${ce}(${e})`, ...t].join(" "), Ft = Oe(Ot), p = (e, ...t) => o[e] ? o[e].console.warn(...t.map(Ft)) : queueMicrotask(() => {
41
- const n = Oe(Ht(e));
42
- console?.warn(...t.map(n));
43
- }), Y = Lt(p);
44
- Y("Function");
45
- Y("Method");
46
- Y("Option");
47
- const _ = Object.freeze({
48
- autoResize: !0,
49
- bodyBackground: null,
50
- bodyMargin: null,
51
- bodyPadding: null,
52
- checkOrigin: !0,
53
- direction: x,
54
- firstRun: !0,
55
- inPageLinks: !1,
56
- heightCalculationMethod: F,
57
- id: "iframeResizer",
58
- log: !1,
59
- logExpand: !1,
60
- license: void 0,
61
- mouseEvents: !0,
62
- offsetHeight: null,
63
- offsetWidth: null,
64
- postMessageTarget: null,
65
- sameDomain: !1,
66
- scrolling: !1,
67
- sizeHeight: !0,
68
- // sizeSelector: '',
69
- sizeWidth: !1,
70
- tolerance: 0,
71
- waitForLoad: !1,
72
- warningTimeout: 5e3,
73
- widthCalculationMethod: F,
74
- onBeforeClose: () => !0,
75
- onAfterClose() {
76
- },
77
- onMessage: null,
78
- onMouseEnter() {
79
- },
80
- onMouseLeave() {
81
- },
82
- onReady() {
83
- },
84
- onResized() {
85
- },
86
- onScroll: () => !0
87
- });
88
- let Q = 0;
89
- function Wt(e) {
90
- const t = e?.id || _.id + Q++;
91
- return document.getElementById(t) === null ? t : `${t}${Q++}`;
92
- }
93
- function Gt(e, t) {
94
- let { id: n } = e;
95
- if (n && !Ee(n))
96
- throw new TypeError("Invalid id for iframe. Expected String");
97
- return (!n || n === "") && (n = Wt(t), e.id = n, w(n, "assignId"), l(n, `Added missing iframe ID: ${n} (${e.src})`)), n;
98
- }
99
- function Ut(e) {
100
- const { search: t } = window.location;
101
- if (t.includes("ifrlog"))
102
- switch (new URLSearchParams(t).get("ifrlog")) {
103
- case String(le): {
104
- e.log = !1;
105
- break;
106
- }
107
- case v:
108
- case String(fe): {
109
- e.log = v;
110
- break;
111
- }
112
- case S:
113
- case String(ae): {
114
- e.log = S;
115
- break;
116
- }
117
- default:
118
- e.log = S;
119
- }
120
- }
121
- const Vt = (e) => e.split(R).filter((t, n) => n !== 19).join(R);
122
- function jt(e, t, n) {
123
- function i(u) {
124
- const g = e in Z ? Vt(t) : t;
125
- b(n, u, a, E, a), b(n, `Message data: %c${g}`, a);
126
- }
127
- const { iframe: r, postMessageTarget: f, sameOrigin: s, targetOrigin: c } = o[n];
128
- if (s)
129
- try {
130
- r.contentWindow.iframeChildListener(W + t), i(`Sending message to iframe %c${n}%c via same origin%c`);
131
- return;
132
- } catch {
133
- e in Z ? (o[n].sameOrigin = !1, l(n, "New iframe does not support same origin")) : O(n, "Same origin messaging failed, falling back to postMessage");
134
- }
135
- i(
136
- `Sending message to iframe: %c${n}%c targetOrigin: %c${c.join(", ")}`
137
- );
138
- for (const u of c)
139
- f.postMessage(W + t, u);
140
- }
141
- function L(e, t, n) {
142
- if (w(n, e), !o[n]?.postMessageTarget) {
143
- O(n, "Iframe not found");
144
- return;
145
- }
146
- jt(e, t, n);
147
- }
148
- const qt = (e, t) => Object.values(o).filter(({ autoResize: n, firstRun: i }) => n && !i).forEach(({ iframe: n }) => L(e, t, n.id));
149
- function Yt() {
150
- document.hidden !== !0 && qt("tabVisible", ue);
151
- }
152
- function Zt(e) {
153
- if (e.boxSizing !== "border-box") return 0;
154
- const t = e.paddingTop ? parseInt(e.paddingTop, 10) : 0, n = e.paddingBottom ? parseInt(e.paddingBottom, 10) : 0;
155
- return t + n;
156
- }
157
- function Xt(e) {
158
- if (e.boxSizing !== "border-box") return 0;
159
- const t = e.borderTopWidth ? parseInt(e.borderTopWidth, 10) : 0, n = e.borderBottomWidth ? parseInt(e.borderBottomWidth, 10) : 0;
160
- return t + n;
161
- }
162
- function Jt(e) {
163
- const t = e.slice(G).split(":"), n = t[1] ? Number(t[1]) : 0, i = o[t[0]]?.iframe, r = i ? getComputedStyle(i) : null, f = r ? Zt(r) + Xt(r) : 0, s = {
164
- iframe: i,
165
- id: t[0],
166
- height: n + f,
167
- width: Number(t[2]),
168
- type: t[3],
169
- msg: t[4],
170
- message: t[4]
171
- };
172
- return t[5] && (s.mode = t[5]), s;
173
- }
174
- const Kt = { true: 1, false: 1, undefined: 1 };
175
- function Qt(e) {
176
- const { id: t, msg: n, iframe: i } = e, r = Tt(i);
177
- return r || (l(t, `Received: %c${n}`, a), O(t, "The target iframe was not found.")), r;
178
- }
179
- function en(e, t) {
180
- const { id: n } = e, { data: i, origin: r } = t;
181
- if ("sameOrigin" in t && t.sameOrigin) return !0;
182
- const s = o[n]?.checkOrigin;
183
- function c() {
184
- function u() {
185
- l(
186
- n,
187
- `Checking connection is from allowed list of origins: %c${s}`,
188
- a
189
- );
190
- for (const d of s)
191
- if (d === r)
192
- return !0;
193
- return !1;
194
- }
195
- function g() {
196
- const d = o[n]?.remoteHost;
197
- return l(n, `Checking connection is from: %c${d}`, a), r === d;
198
- }
199
- return s.constructor === Array ? u() : g();
200
- }
201
- if (s && `${r}` != "null" && !c())
202
- throw new Error(
203
- `Unexpected message received from: ${r} for ${n}. Message was: ${i}. This error can be disabled by setting the checkOrigin: false option or by providing an array of trusted domains.`
204
- );
205
- return !0;
206
- }
207
- const tn = (e) => W === `${e}`.slice(0, G) && e.slice(G).split(":")[0] in o;
208
- function nn(e) {
209
- const { id: t, type: n } = e, i = n in Kt;
210
- return i && l(t, "Ignoring init message from meta parent page"), i;
211
- }
212
- function on(e) {
213
- try {
214
- o[e].sameOrigin = !!o[e]?.iframe?.contentWindow?.iframeChildListener;
215
- } catch {
216
- o[e].sameOrigin = !1;
217
- }
218
- l(e, `sameOrigin: %c${o[e].sameOrigin}`, a);
219
- }
220
- function rn(e, t) {
221
- if (t !== C) {
222
- if (t === void 0) {
223
- p(
224
- e,
225
- `<rb>Legacy version detected in iframe</>
1
+ /*!
2
+ * @preserve
3
+ *
4
+ * @module iframe-resizer/core 6.0.0-beta.6 (esm) - 2026-04-10
5
+ *
6
+ * @license GPL-3.0 For use with GPL compliant sites (fully published front & backend source code)
7
+ * Alternatively for commercial use, you can purchase a license from
8
+ * https://iframe-resizer.com/pricing
9
+ *
10
+ * @description Keep same and cross domain iframes sized to their content
11
+ *
12
+ * @author David J. Bradshaw <info@iframe-resizer.com>
13
+ *
14
+ * @see {@link https://iframe-resizer.com}
15
+ *
16
+ * @copyright (c) 2013 - 2026, David J. Bradshaw. All rights reserved.
17
+ */
226
18
 
227
- Detected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.
228
19
 
229
- See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.
230
- `
231
- );
232
- return;
233
- }
234
- l(
235
- e,
236
- `Version mismatch (Child: %c${t}%c !== Parent: %c${C})`,
237
- a,
238
- E,
239
- a
240
- );
241
- }
242
- }
243
- function y(e, t, n) {
244
- if (!o[e]) return null;
245
- const i = o[e][t];
246
- if (typeof i !== Ue)
247
- throw new TypeError(`${t} on iframe[${e}] is not a function`);
248
- if (t !== "onBeforeClose" && t !== "onScroll")
249
- return It(i, n);
250
- try {
251
- return i(n);
252
- } catch (r) {
253
- return console.error(r), O(e, `Error in ${t} callback`), null;
254
- }
255
- }
256
- function sn(e, t) {
257
- const { id: n, iframe: i } = e;
258
- l(
259
- n,
260
- `onMessage passed: {iframe: %c${n}%c, message: %c${t}%c}`,
261
- a,
262
- E,
263
- a,
264
- E
265
- ), y(n, "onMessage", {
266
- iframe: i,
267
- message: JSON.parse(t)
268
- });
269
- }
270
- function N(e, t) {
271
- const { lastMessage: n } = o[e];
272
- return n.slice(
273
- n.indexOf(R) + Ve + t
274
- );
275
- }
276
- function ee(e, t) {
277
- const { id: n, iframe: i, height: r, type: f, width: s } = t;
278
- let c = { x: 0, y: 0 };
279
- if (s === 0 && r === 0) {
280
- const u = N(n, 9).split(R);
281
- c = {
282
- x: u[1],
283
- y: u[0]
284
- };
285
- } else
286
- c = {
287
- x: s,
288
- y: r
289
- };
290
- y(n, e, {
291
- iframe: i,
292
- screenX: Number(c.x),
293
- screenY: Number(c.y),
294
- type: f
295
- });
296
- }
297
- const h = {
298
- position: null,
299
- version: C
300
- };
301
- function $e() {
302
- h.position = null;
303
- }
304
- const cn = () => h.position;
305
- function an(e) {
306
- h.position = e;
307
- }
308
- function Me(e) {
309
- return h.position === null && (h.position = {
310
- x: window.scrollX,
311
- y: window.scrollY
312
- }), l(
313
- e,
314
- `Get page position: %c${h.position.x}%c, %c${h.position.y}`,
315
- a,
316
- E,
317
- a
318
- ), h.position;
319
- }
320
- function Le(e) {
321
- h.position !== null && (window.scrollTo(h.position.x, h.position.y), b(
322
- e,
323
- `Set page position: %c${h.position.x}%c, %c${h.position.y}`,
324
- a,
325
- E,
326
- a
327
- ), $e());
328
- }
329
- function te(e, t) {
330
- const { id: n } = t, i = `${t[e]}px`;
331
- o[n].iframe.style[e] = i, b(n, `Set ${e}: %c${i}`, a);
332
- }
333
- function Se(e) {
334
- const { id: t } = e, { sizeHeight: n, sizeWidth: i } = o[t];
335
- n && te(je, e), i && te(qe, e);
336
- }
337
- function ne(e) {
338
- const { id: t } = e;
339
- Se(e), Le(t), y(t, "onResized", e);
340
- }
341
- function ve(e) {
342
- const { id: t } = e;
343
- l(t, "Disconnected from iframe"), delete o[t], delete e.iframeResizer;
344
- }
345
- function Re(e) {
346
- const { id: t } = e;
347
- if (y(t, "onBeforeClose", t) === !1) {
348
- l(t, "Close iframe cancelled by onBeforeClose");
349
- return;
350
- }
351
- l(t, `Removing iframe: %c${t}`, a);
352
- try {
353
- e.parentNode && e.remove();
354
- } catch (n) {
355
- O(t, n);
356
- }
357
- y(t, "onAfterClose", t), ve(e);
358
- }
359
- function ke(e) {
360
- const { id: t, type: n } = e;
361
- l(
362
- t,
363
- `Size reset requested by ${n === P ? "parent page" : "child page"}`
364
- ), Me(t), Se(e), L(U, U, t);
365
- }
366
- const Ae = (e, t) => {
367
- const n = {};
368
- return (i, r) => {
369
- const { iframe: f } = o[r];
370
- function s(u, g) {
371
- n[g] || (u(), n[g] = requestAnimationFrame(() => {
372
- n[g] = null;
373
- }));
374
- }
375
- function c() {
376
- L(`${i} (${e})`, `${e}:${t(f)}`, r);
377
- }
378
- s(c, r);
379
- };
380
- }, Pe = (e) => (t) => {
381
- e in o[t] && (o[t][e](), delete o[t][e]);
382
- }, Ne = (
383
- // eslint-disable-next-line @typescript-eslint/no-shadow
384
- ((e, t) => (n) => {
385
- let i = !1;
386
- const r = (m) => () => {
387
- o[n] ? (!i || i === m) && (e(m, n), i = m, requestAnimationFrame(() => {
388
- i = !1;
389
- })) : d();
390
- }, f = r(X), s = r("resize window"), c = new ResizeObserver(r("pageObserver")), u = new ResizeObserver(r("iframeObserver"));
391
- function g(m, T) {
392
- l(n, `${m}listeners for send${t}`), T(window, X, f), T(window, ue, s);
393
- }
394
- function d() {
395
- w(n, `stop${t}`), g("Remove ", K), c.disconnect(), u.disconnect(), o[n] && K(o[n].iframe, V, d);
396
- }
397
- function M() {
398
- g("Add ", A), c.observe(document.body), u.observe(o[n].iframe);
399
- }
400
- o[n] && (o[n][`stop${t}`] = d, A(o[n].iframe, V, d), M());
401
- })
402
- );
403
- function fn(e) {
404
- const t = document.body.getBoundingClientRect(), n = e.getBoundingClientRect(), { scrollY: i, scrollX: r, innerHeight: f, innerWidth: s } = window, { clientHeight: c, clientWidth: u } = document.documentElement;
405
- return JSON.stringify({
406
- iframeHeight: n.height,
407
- iframeWidth: n.width,
408
- clientHeight: Math.max(c, f || 0),
409
- clientWidth: Math.max(u, s || 0),
410
- offsetTop: Math.trunc(n.top - t.top),
411
- offsetLeft: Math.trunc(n.left - t.left),
412
- scrollTop: i,
413
- scrollLeft: r,
414
- documentHeight: c,
415
- documentWidth: u,
416
- windowHeight: f,
417
- windowWidth: s
418
- });
419
- }
420
- const ln = Ae(ge, fn), un = Ne(
421
- ln,
422
- "PageInfo"
423
- ), gn = Pe("stopPageInfo");
424
- function dn(e) {
425
- const { scrollWidth: t, scrollHeight: n } = document.documentElement, i = typeof window < "u" && window.visualViewport ? window.visualViewport : {}, {
426
- width: r = 0,
427
- height: f = 0,
428
- offsetLeft: s = 0,
429
- offsetTop: c = 0,
430
- pageLeft: u = 0,
431
- pageTop: g = 0,
432
- scale: d = 1
433
- } = i;
434
- return JSON.stringify({
435
- iframe: e.getBoundingClientRect(),
436
- document: {
437
- scrollWidth: t,
438
- scrollHeight: n
439
- },
440
- viewport: {
441
- width: r,
442
- height: f,
443
- offsetLeft: s,
444
- offsetTop: c,
445
- pageLeft: u,
446
- pageTop: g,
447
- scale: d
448
- }
449
- });
450
- }
451
- const hn = Ae(de, dn), mn = Ne(
452
- hn,
453
- "ParentInfo"
454
- ), pn = Pe("stopParentInfo");
455
- function Ce(e) {
456
- const t = e.getBoundingClientRect(), n = Me(e.id);
457
- return {
458
- x: Number(t.left) + Number(n.x),
459
- y: Number(t.top) + Number(n.y)
460
- };
461
- }
462
- function ze(e) {
463
- const { x: t, y: n } = cn(), i = o[e]?.iframe;
464
- if (y(e, "onScroll", { iframe: i, top: n, left: t, x: t, y: n }) === !1) {
465
- $e();
466
- return;
467
- }
468
- Le(e);
469
- }
470
- function bn(e) {
471
- const { id: t, height: n, width: i } = e, r = window.parentIframe || window.parentIFrame || window;
472
- b(
473
- t,
474
- `scrollBy: x: %c${i}%c y: %c${n}`,
475
- a,
476
- E,
477
- a
478
- ), r.scrollBy(i, n);
479
- }
480
- const _e = (e) => (t) => {
481
- const { id: n, iframe: i, height: r, width: f } = t;
482
- function s(m) {
483
- an(m), ze(n);
484
- }
485
- function c(m, T) {
486
- m[`scrollTo${e ? "Offset" : ""}`](
487
- T.x,
488
- T.y
489
- );
490
- }
491
- const u = (m) => ({
492
- x: f + m.x,
493
- y: r + m.y
494
- }), g = e ? Ce(i) : { x: 0, y: 0 }, d = u(g), M = window.parentIframe || window.parentIFrame;
495
- b(
496
- n,
497
- `Reposition requested (offset x:%c${g.x}%c y:%c${g.y})`,
498
- a,
499
- E,
500
- a
501
- ), M ? c(M, d) : s(d);
502
- }, wn = _e(!1), En = _e(!0);
503
- function On(e, t, n) {
504
- const { x: i, y: r } = Ce(n);
505
- b(e, `Moving to in page link: %c#${t}`, a), h.position = { x: i, y: r }, ze(e), window.location.hash = t;
506
- }
507
- function Tn(e, t) {
508
- const n = window.parentIframe || window.parentIFrame;
509
- if (!n) {
510
- l(e, `In page link #${t} not found`);
511
- return;
512
- }
513
- n.moveToAnchor(t);
514
- }
515
- function In(e, t) {
516
- const n = t.split("#")[1] || "", i = decodeURIComponent(n), r = document.getElementById(i) || document.getElementsByName(i)[0];
517
- if (r) {
518
- On(e, n, r);
519
- return;
520
- }
521
- if (window.top === window.self) {
522
- l(e, `In page link #${n} not found`);
523
- return;
524
- }
525
- Tn(e, n);
526
- }
527
- function yn(e) {
528
- const t = o[e]?.iframe?.title;
529
- return t === "" || t === void 0;
530
- }
531
- function $n(e, t) {
532
- o[e]?.syncTitle && (o[e].iframe.title = t, b(e, `Set iframe title attribute: %c${t}`, a));
533
- }
534
- let j = !1, xe = !1;
535
- function De(e, t = -3) {
536
- if (j) return;
537
- const n = Math.max(o[e].mode, t);
538
- if (n > o[e].mode && (o[e].mode = n), n < 0)
539
- throw xt(e), o[e].vAdvised || p(e || "Parent", `${I(n + 2)}${I(2)}`), o[e].vAdvised = !0, I(n + 2).replace(/<\/?[a-z][^>]*>|<\/>/gi, "");
540
- switch (n > 5 && xe || Bt(`v${C} (${kt(n)})`, n), n) {
541
- case 1:
542
- case 2:
543
- case 3:
544
- p("Parent", I(6));
545
- break;
546
- case 4:
547
- p("Parent", I(7));
548
- break;
549
- case 5:
550
- p("Parent", I(8));
551
- break;
552
- default:
553
- n < 1 && p("Parent", I(3));
554
- }
555
- j = !0;
556
- }
557
- function Mn(e) {
558
- if (j) return;
559
- const { mode: t } = o[e];
560
- t > 5 && De(e, t);
561
- }
562
- function Ln(e) {
563
- e?.log === -1 && (e.log = !1, xe = !0);
564
- }
565
- function Sn(e, t) {
566
- o[e] && (l(e, `First run for ${e}`), De(e, t === void 0 ? void 0 : Number(t)), o[e].firstRun = !1);
567
- }
568
- function vn(e) {
569
- const { height: t, id: n, iframe: i, mode: r, message: f, type: s, width: c } = e, { lastMessage: u } = o[n];
570
- switch (o[n]?.firstRun && Sn(n, r), l(n, `Received: %c${u}`, a), s) {
571
- case he:
572
- o[n].autoResize = JSON.parse(N(n, 9));
573
- break;
574
- case it:
575
- b(n, "Ready state reset"), o[n].initialised = !1;
576
- break;
577
- case ot:
578
- Re(i);
579
- break;
580
- case nt:
581
- In(n, N(n, 9));
582
- break;
583
- case P:
584
- ne(e), on(n), rn(n, f), o[n].initialised = !0, y(n, "onReady", i);
585
- break;
586
- case z:
587
- sn(e, N(n, 6));
588
- break;
589
- case tt:
590
- ee("onMouseEnter", e);
591
- break;
592
- case et:
593
- ee("onMouseLeave", e);
594
- break;
595
- case ge:
596
- un(n);
597
- break;
598
- case de:
599
- mn(n);
600
- break;
601
- case Qe:
602
- gn(n);
603
- break;
604
- case Ke:
605
- pn(n);
606
- break;
607
- case U:
608
- ke(e);
609
- break;
610
- case Je:
611
- bn(e);
612
- break;
613
- case Xe:
614
- wn(e);
615
- break;
616
- case Ze:
617
- En(e);
618
- break;
619
- case Ye:
620
- $n(n, f);
621
- break;
622
- default:
623
- if (c === 0 && t === 0) {
624
- O(
625
- n,
626
- `Unsupported message received (${s}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`
627
- );
628
- return;
629
- }
630
- if (c === 0 || t === 0) {
631
- l(n, "Ignoring message with 0 height or width");
632
- return;
633
- }
634
- if (document.hidden) {
635
- l(n, "Page hidden - ignored resize request");
636
- return;
637
- }
638
- ne(e);
639
- }
640
- }
641
- const Rn = (e) => ({
642
- initChild: t,
643
- postMessageTarget: n
644
- }) => {
645
- e === n && t();
646
- }, kn = (e) => Object.values(o).forEach(Rn(e));
647
- function oe(e) {
648
- const t = e.data;
649
- if (t === rt) {
650
- kn(e.source);
651
- return;
652
- }
653
- if (!tn(t)) {
654
- if (typeof t !== me) return;
655
- w(H, "ignoredMessage"), zt(H, t);
656
- return;
657
- }
658
- const n = Jt(t), { id: i, type: r } = n;
659
- switch (w(i, r), !0) {
660
- case !o[i]:
661
- throw new Error(`${r} No settings for ${i}. Message was: ${t}`);
662
- case !Qt(n):
663
- case nn(n):
664
- case !en(n, e):
665
- return;
666
- default:
667
- o[i].lastMessage = e.data, ye(i, vn)(n);
668
- }
669
- }
670
- const An = yt(() => {
671
- A(window, z, oe), A(document, "visibilitychange", Yt), window.iframeParentListener = (e) => setTimeout(() => oe({ data: e, sameOrigin: !0 }));
672
- }), ie = {};
673
- function Pn(e) {
674
- if (ie[e] === !0) return !1;
675
- const t = document.querySelectorAll(`iframe#${CSS.escape(e)}`);
676
- if (t.length <= 1) return !0;
677
- ie[e] = !0;
678
- const n = Array.from(t).flatMap((i) => [
679
- D,
680
- i,
681
- D
682
- ]);
683
- return p(
684
- e,
685
- `<rb>Duplicate ID attributes detected</>
686
-
687
- The <b>${e}</> ID is not unique. Having multiple iframes on the same page with the same ID causes problems with communication between the iframe and parent page. Please ensure that the ID of each iframe has a unique value.
688
-
689
- Found <bb>${t.length}</> iframes with the <b>${e}</> ID:`,
690
- ...n,
691
- D
692
- ), !1;
693
- }
694
- function Nn(e) {
695
- if (o[e]) {
696
- const { iframe: t } = o[e];
697
- t.iframeResizer = {
698
- close: Re.bind(null, t),
699
- disconnect: ve.bind(null, t),
700
- moveToAnchor(n) {
701
- $t(n, me, "moveToAnchor(anchor) anchor"), L("Move to anchor", `moveToAnchor:${n}`, e);
702
- },
703
- sendMessage(n) {
704
- n = JSON.stringify(n), L(z, `${z}:${n}`, e);
705
- }
706
- };
707
- }
708
- }
709
- const Cn = "8", zn = "32", _n = st, xn = !0;
710
- function Dn(e) {
711
- const {
712
- autoResize: t,
713
- bodyBackground: n,
714
- bodyMargin: i,
715
- bodyPadding: r,
716
- heightCalculationMethod: f,
717
- inPageLinks: s,
718
- license: c,
719
- log: u,
720
- logExpand: g,
721
- mouseEvents: d,
722
- offsetHeight: M,
723
- offsetWidth: m,
724
- mode: T,
725
- sizeHeight: Be,
726
- // sizeSelector,
727
- sizeWidth: He,
728
- tolerance: Fe,
729
- widthCalculationMethod: We
730
- } = o[e];
731
- return [
732
- e,
733
- Cn,
734
- He,
735
- u,
736
- zn,
737
- xn,
738
- t,
739
- i,
740
- f,
741
- n,
742
- r,
743
- Fe,
744
- s,
745
- _n,
746
- We,
747
- d,
748
- M,
749
- m,
750
- Be,
751
- c,
752
- h.version,
753
- T,
754
- "",
755
- // sizeSelector,
756
- g
757
- ].join(R);
758
- }
759
- const Bn = "0";
760
- function Hn(e) {
761
- const { bodyMargin: t } = o[e];
762
- (typeof t === ct || t === Bn) && (o[e].bodyMargin = `${t}px`);
763
- }
764
- const Fn = (e) => {
765
- try {
766
- return new URL(e).origin;
767
- } catch {
768
- return null;
769
- }
770
- }, Wn = (e) => typeof e === at && e.length > 0 && !(e.contains("allow-scripts") && e.contains("allow-same-origin"));
771
- function Gn(e, t) {
772
- const {
773
- checkOrigin: n,
774
- iframe: { src: i, sandbox: r },
775
- initialisedFirstPage: f,
776
- waitForLoad: s
777
- } = t[e], c = Fn(i);
778
- w(e, "noResponse"), p(
779
- e,
780
- `<rb>No response from iframe</>
781
-
782
- The iframe (<i>${e}</>) has not responded within ${t[e].warningTimeout / 1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.
783
- ${n && c ? `
784
- The <b>checkOrigin</> option is currently enabled. If the iframe redirects away from <i>${c}</>, then the connection to the iframe may be blocked by the browser. To disable this option, set <b>checkOrigin</> to <bb>false</> or an array of allowed origins. See <u>https://iframe-resizer.com/checkorigin</> for more information.
785
- ` : ""}${s && !f ? `
786
- The <b>waitForLoad</> option is currently set to <bb>true</>. If the iframe loads before <i>iframe-resizer</> runs, this option will prevent <i>iframe-resizer</> initialising. To disable this option, set <b>waitForLoad</> to <bb>false</>.
787
- ` : ""}${Wn(r) ? `
788
- The iframe has the <b>sandbox</> attribute, please ensure it contains both the <bb>allow-same-origin</> and <bb>allow-scripts</> values.
789
- ` : ""}
790
- This message can be ignored if everything is working, or you can set the <b>warningTimeout</> option to a higher value or zero to suppress this warning.
791
- `
792
- );
793
- }
794
- function Un(e, t) {
795
- function n() {
796
- if (t[e] === void 0) return;
797
- const { initialised: f, loadErrorShown: s } = t[e];
798
- if (t[e].msgTimeout = void 0, f) {
799
- t[e].initialisedFirstPage = !0;
800
- return;
801
- }
802
- s || (t[e].loadErrorShown = !0, Gn(e, t));
803
- }
804
- const { msgTimeout: i, warningTimeout: r } = t[e];
805
- r && (i && clearTimeout(i), t[e].msgTimeout = setTimeout(n, r));
806
- }
807
- const Vn = 1, jn = (e) => e.loading === lt, qn = (e) => e === P;
808
- function Yn(e) {
809
- o[e]?.heightCalculationMethod in ut && ke({
810
- id: e,
811
- iframe: o[e].iframe,
812
- height: J,
813
- width: J,
814
- type: P
815
- });
816
- }
817
- function Zn(e, t) {
818
- A(e, V, () => setTimeout(t, Vn));
819
- }
820
- const Xn = (e) => {
821
- const { src: t, srcdoc: n } = e;
822
- return !n && (t == null || t === "" || t === "about:blank");
823
- };
824
- function Jn(e, t) {
825
- const { iframe: n, waitForLoad: i } = o[e];
826
- if (i !== !0) {
827
- if (Xn(n)) {
828
- setTimeout(() => {
829
- w(e, "noContent"), b(e, "No content detected in the iframe, delaying initialisation");
830
- });
831
- return;
832
- }
833
- setTimeout(t);
834
- }
835
- }
836
- function Kn(e, t) {
837
- const n = (r) => () => {
838
- if (!o[e]) return;
839
- const { firstRun: f, iframe: s } = o[e];
840
- L(r, t, e), qn(r) && jn(s) || Un(e, o), f || Yn(e);
841
- }, { iframe: i } = o[e];
842
- o[e].initChild = n(ft), Zn(i, n(gt)), Jn(e, n(P));
843
- }
844
- function Qn(e, t) {
845
- return t ? (("sizeWidth" in t || "sizeHeight" in t || he in t) && p(
846
- e,
847
- `<rb>Deprecated Option</>
848
-
849
- The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <bb>${x}</>, <bb>${pe}</>, <bb>${be}</> or <bb>${we}</>.
850
- `
851
- ), t) : {};
852
- }
853
- function eo(e) {
854
- o[e].warningTimeout || b(e, "warningTimeout:%c disabled", a);
855
- }
856
- function to(e, { offset: t, offsetSize: n }) {
857
- const i = n || t;
858
- i && (o[e].direction === x ? (o[e].offsetHeight = i, l(e, `Offset height: %c${i}`, a)) : (o[e].offsetWidth = i, l(e, `Offset width: %c${i}`, a)));
859
- }
860
- function no(e) {
861
- const { direction: t } = o[e];
862
- switch (t) {
863
- case x:
864
- break;
865
- case pe:
866
- o[e].sizeHeight = !1;
867
- // eslint-disable-next-line no-fallthrough
868
- case be:
869
- o[e].sizeWidth = !0;
870
- break;
871
- case we:
872
- o[e].sizeWidth = !1, o[e].sizeHeight = !1, o[e].autoResize = !1;
873
- break;
874
- default:
875
- throw new TypeError(`Direction value of "${t}" is not valid`);
876
- }
877
- l(e, `direction: %c${t}`, a);
878
- }
879
- const re = (e) => e === "" || e.match(/^(about:blank|javascript:|file:\/\/)/) !== null ? "*" : e;
880
- function oo(e) {
881
- const { checkOrigin: t, remoteHost: n } = o[e];
882
- Array.isArray(t) && t.length === 0 && O(
883
- e,
884
- "checkOrigin is an empty array — no messages will be sent to the iframe"
885
- ), o[e].targetOrigin = Array.isArray(t) ? t.map(re) : [t === !1 ? "*" : re(n)];
886
- }
887
- function io(e) {
888
- const { id: t } = e;
889
- o[t].postMessageTarget === null && (o[t].postMessageTarget = e.contentWindow);
890
- }
891
- function B(e, t, n) {
892
- k(o[e], t) && (p(
893
- e,
894
- `<rb>Deprecated option</>
895
-
896
- The <b>${t}</> option has been renamed to <b>${n}</>. ${dt}`
897
- ), o[e][n] = o[e][t], delete o[e][t]);
898
- }
899
- function ro(e) {
900
- B(e, mt, ht), B(e, "onClose", "onBeforeClose"), B(e, "onClosed", "onAfterClose");
901
- }
902
- const so = (e) => k(e, "onMouseEnter") || k(e, "onMouseLeave");
903
- function co(e, t) {
904
- const { id: n } = e;
905
- o[n] = {
906
- ...o[n],
907
- iframe: e,
908
- remoteHost: e?.src.split("/").slice(0, 3).join("/"),
909
- ..._,
910
- ...Qn(n, t),
911
- mouseEvents: so(t),
912
- mode: Rt(t),
913
- syncTitle: yn(n)
914
- }, ro(n), no(n), to(n, t), eo(n), io(e), oo(n);
915
- }
916
- const ao = "yes", se = "no";
917
- function fo(e) {
918
- const { id: t } = e;
919
- switch (l(
920
- t,
921
- `Iframe scrolling ${o[t]?.scrolling ? "enabled" : "disabled"} for ${t}`
922
- ), e.style.overflow = o[t]?.scrolling === !1 ? pt : F, o[t]?.scrolling) {
923
- case bt:
924
- break;
925
- case !0:
926
- e.scrolling = ao;
927
- break;
928
- case !1:
929
- e.scrolling = se;
930
- break;
931
- default:
932
- e.scrolling = o[t]?.scrolling || se;
933
- }
934
- }
935
- function lo(e, t, n) {
936
- co(t, n), l(e, `src: %c${t.srcdoc || t.src}`, a), Mn(e), fo(t), Hn(e), Kn(e, Dn(e)), Nn(e), l(e, "Setup complete");
937
- }
938
- function uo(e, t) {
939
- const { id: n } = e;
940
- w(n, "setup"), Pn(n) && lo(n, e, t), Dt(n);
941
- }
942
- function go(e, t) {
943
- t.log === le ? t.log = !1 : t.log === ae ? t.log = S : t.log === fe && (t.log = v);
944
- const n = k(t, "log"), i = Ee(t.log), r = n ? i ? !0 : t.log : _.log;
945
- k(t, "logExpand") || (t.logExpand = n && i ? t.log === v : _.logExpand), Ln(t), Ct({
946
- enabled: r,
947
- expand: t.logExpand,
948
- iframeId: e
949
- }), i && !(t.log in wt) && _t(
950
- e,
951
- `Invalid value for options.log: Accepted values are "${v}" and "${S}"`
952
- ), t.log = r;
953
- }
954
- function To(e) {
955
- if (!Mt(e)) throw new TypeError("Options is not an object");
956
- return An(), Ut(e), (t) => {
957
- const n = Gt(t, e);
958
- return ce in t ? (w(n, "alreadySetup"), O(n, `Ignored iframe (${n}), already setup.`)) : (go(n, e), ye(n, uo)(t, e)), t?.iframeResizer;
959
- };
960
- }
961
- export {
962
- $o as LOG_COLLAPSED,
963
- Mo as LOG_DISABLED,
964
- Lo as LOG_EXPANDED,
965
- To as default
966
- };
20
+ import{esModuleInterop as e,PARENT as n,createFormatAdvise as i,id as t,deprecate as o,LABEL as r,BOLD as s,AUTO as a,VERTICAL as c,isString as d,COLLAPSE as l,LOG_COLLAPSED as f,LOG_EXPANDED as u,EXPAND as g,LOG_DISABLED as m,MESSAGE_ID as h,INIT_EVENTS as p,SEPARATOR as b,RESIZE as w,MESSAGE_ID_LENGTH as y,isIframe as $,VERSION as v,FUNCTION as k,isolateUserCode as T,MESSAGE_HEADER_LENGTH as x,HEIGHT as z,WIDTH as O,INIT as M,RESET as I,addEventListener as E,LOAD as S,removeEventListener as R,SCROLL as C,PAGE_INFO as L,PARENT_INFO as A,getModeData as W,getModeLabel as P,TITLE as B,SCROLL_TO_OFFSET as D,SCROLL_TO as H,SCROLL_BY as N,PARENT_INFO_STOP as F,PAGE_INFO_STOP as j,MOUSE_LEAVE as q,MOUSE_ENTER as G,MESSAGE as _,IN_PAGE_LINK as J,CLOSE as U,BEFORE_UNLOAD as X,AUTO_RESIZE as V,once as Y,CHILD_READY_MESSAGE as K,STRING as Q,NEW_LINE as Z,typeAssert as ee,CHILD as ne,NUMBER as ie,OBJECT as te,INIT_FROM_IFRAME as oe,LAZY as re,RESET_REQUIRED_METHODS as se,MIN_SIZE as ae,ONLOAD as ce,HORIZONTAL as de,BOTH as le,NONE as fe,hasOwn as ue,REMOVED_NEXT_VERSION as ge,OFFSET_SIZE as me,OFFSET as he,setMode as pe,HIDDEN as be,OMIT as we,LOG_OPTIONS as ye,isObject as $e}from"@iframe-resizer/common";import{LOG_COLLAPSED as ve,LOG_DISABLED as ke,LOG_EXPANDED as Te}from"@iframe-resizer/common";import xe,{NORMAL as ze,HIGHLIGHT as Oe,FOREGROUND as Me}from"auto-console-group";const Ie={},Ee=e(xe);let Se=!0;const Re=Ee({expand:!1,label:n}),Ce=e=>window.top===window.self?`parent(${e})`:`nested parent(${e})`;const Le=e=>(n,...i)=>Ie[n]?Ie[n].console[e](...i):Re[e](...i),Ae=e=>(n,...i)=>!0===(e=>Ie[e]?Ie[e].log:Se)(n)?Le(e)(n,...i):null,We=Ae("log"),Pe=We,Be=Ae("debug"),De=Le("warn"),He=Le("error"),Ne=Le("event"),Fe=Le("purge"),je=Le("endAutoGroup"),qe=Le("errorBoundary");const Ge=i(t),_e=(e,...n)=>Ie[e]?Ie[e].console.warn(...n.map(Ge)):queueMicrotask(()=>{const t=i((e=>(...n)=>[`${r}(${e})`,...n].join(" "))(e));console?.warn(...n.map(t))}),Je=o(_e);Je("Function"),Je("Method"),Je("Option");const Ue=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:c,firstRun:!0,inPageLinks:!1,heightCalculationMethod:a,id:"iframeResizer",log:!1,logExpand:!1,license:void 0,mouseEvents:!0,offsetHeight:null,offsetWidth:null,postMessageTarget:null,sameDomain:!1,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,waitForLoad:!1,warningTimeout:5e3,widthCalculationMethod:a,onBeforeClose:()=>!0,onAfterClose(){},onMessage:null,onMouseEnter(){},onMouseLeave(){},onReady(){},onResized(){},onScroll:()=>!0});let Xe=0;function Ve(e,n){let{id:i}=e;if(i&&!d(i))throw new TypeError("Invalid id for iframe. Expected String");return i&&""!==i||(i=function(e){const n=e?.id||Ue.id+Xe++;return null===document.getElementById(n)?n:`${n}${Xe++}`}(n),e.id=i,Ne(i,"assignId"),We(i,`Added missing iframe ID: ${i} (${e.src})`)),i}function Ye(e,n,i){function t(t){const o=e in p?(e=>e.split(b).filter((e,n)=>19!==n).join(b))(n):n;Pe(i,t,Oe,Me,Oe),Pe(i,`Message data: %c${o}`,Oe)}const{iframe:o,postMessageTarget:r,sameOrigin:s,targetOrigin:a}=Ie[i];if(s)try{return o.contentWindow.iframeChildListener(h+n),void t(`Sending message to iframe %c${i}%c via same origin%c`)}catch(c){e in p?(Ie[i].sameOrigin=!1,We(i,"New iframe does not support same origin")):De(i,"Same origin messaging failed, falling back to postMessage")}t(`Sending message to iframe: %c${i}%c targetOrigin: %c${a.join(", ")}`);for(const d of a)r.postMessage(h+n,d)}function Ke(e,n,i){Ne(i,e),Ie[i]?.postMessageTarget?Ye(e,n,i):De(i,"Iframe not found")}function Qe(){var e,n;!0!==document.hidden&&(e="tabVisible",n=w,Object.values(Ie).filter(({autoResize:e,firstRun:n})=>e&&!n).forEach(({iframe:i})=>Ke(e,n,i.id)))}function Ze(e){const n=e.slice(y).split(":"),i=n[1]?Number(n[1]):0,t=Ie[n[0]]?.iframe,o=t?getComputedStyle(t):null,r=o?function(e){return"border-box"!==e.boxSizing?0:(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}(o)+function(e){return"border-box"!==e.boxSizing?0:(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}(o):0,s={iframe:t,id:n[0],height:i+r,width:Number(n[2]),type:n[3],msg:n[4],message:n[4]};return n[5]&&(s.mode=n[5]),s}const en={true:1,false:1,undefined:1};function nn(e,n,i){if(!Ie[e])return null;const t=Ie[e][n];if(typeof t!==k)throw new TypeError(`${n} on iframe[${e}] is not a function`);if("onBeforeClose"!==n&&"onScroll"!==n)return T(t,i);try{return t(i)}catch(o){return console.error(o),De(e,`Error in ${n} callback`),null}}function tn(e,n){const{lastMessage:i}=Ie[e];return i.slice(i.indexOf(b)+x+n)}function on(e,n){const{id:i,iframe:t,height:o,type:r,width:s}=n;let a={x:0,y:0};if(0===s&&0===o){const e=tn(i,9).split(b);a={x:e[1],y:e[0]}}else a={x:s,y:o};nn(i,e,{iframe:t,screenX:Number(a.x),screenY:Number(a.y),type:r})}const rn={position:null,version:v};function sn(){rn.position=null}function an(e){return null===rn.position&&(rn.position={x:window.scrollX,y:window.scrollY}),We(e,`Get page position: %c${rn.position.x}%c, %c${rn.position.y}`,Oe,Me,Oe),rn.position}function cn(e){null!==rn.position&&(window.scrollTo(rn.position.x,rn.position.y),Pe(e,`Set page position: %c${rn.position.x}%c, %c${rn.position.y}`,Oe,Me,Oe),sn())}function dn(e,n){const{id:i}=n,t=`${n[e]}px`;Ie[i].iframe.style[e]=t,Pe(i,`Set ${e}: %c${t}`,Oe)}function ln(e){const{id:n}=e,{sizeHeight:i,sizeWidth:t}=Ie[n];i&&dn(z,e),t&&dn(O,e)}function fn(e){const{id:n}=e;ln(e),cn(n),nn(n,"onResized",e)}function un(e){const{id:n}=e;We(n,"Disconnected from iframe"),delete Ie[n],delete e.iframeResizer}function gn(e){const{id:n}=e;if(!1!==nn(n,"onBeforeClose",n)){We(n,`Removing iframe: %c${n}`,Oe);try{e.parentNode&&e.remove()}catch(i){De(n,i)}nn(n,"onAfterClose",n),un(e)}else We(n,"Close iframe cancelled by onBeforeClose")}function mn(e){const{id:n,type:i}=e;We(n,"Size reset requested by "+(i===M?"parent page":"child page")),an(n),ln(e),Ke(I,I,n)}const hn=(e,n)=>{const i={};return(t,o)=>{const{iframe:r}=Ie[o];var s,a;s=function(){Ke(`${t} (${e})`,`${e}:${n(r)}`,o)},i[a=o]||(s(),i[a]=requestAnimationFrame(()=>{i[a]=null}))}},pn=e=>n=>{e in Ie[n]&&(Ie[n][e](),delete Ie[n][e])},bn=(e,n)=>i=>{let t=!1;const o=n=>()=>{Ie[i]?t&&t!==n||(e(n,i),t=n,requestAnimationFrame(()=>{t=!1})):l()},r=o(C),s=o("resize window"),a=new ResizeObserver(o("pageObserver")),c=new ResizeObserver(o("iframeObserver"));function d(e,t){We(i,`${e}listeners for send${n}`),t(window,C,r),t(window,w,s)}function l(){Ne(i,`stop${n}`),d("Remove ",R),a.disconnect(),c.disconnect(),Ie[i]&&R(Ie[i].iframe,S,l)}Ie[i]&&(Ie[i][`stop${n}`]=l,E(Ie[i].iframe,S,l),d("Add ",E),a.observe(document.body),c.observe(Ie[i].iframe))};const wn=bn(hn(L,function(e){const n=document.body.getBoundingClientRect(),i=e.getBoundingClientRect(),{scrollY:t,scrollX:o,innerHeight:r,innerWidth:s}=window,{clientHeight:a,clientWidth:c}=document.documentElement;return JSON.stringify({iframeHeight:i.height,iframeWidth:i.width,clientHeight:Math.max(a,r||0),clientWidth:Math.max(c,s||0),offsetTop:Math.trunc(i.top-n.top),offsetLeft:Math.trunc(i.left-n.left),scrollTop:t,scrollLeft:o,documentHeight:a,documentWidth:c,windowHeight:r,windowWidth:s})}),"PageInfo"),yn=pn("stopPageInfo");const $n=bn(hn(A,function(e){const{scrollWidth:n,scrollHeight:i}=document.documentElement,t="undefined"!=typeof window&&window.visualViewport?window.visualViewport:{},{width:o=0,height:r=0,offsetLeft:s=0,offsetTop:a=0,pageLeft:c=0,pageTop:d=0,scale:l=1}=t;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:n,scrollHeight:i},viewport:{width:o,height:r,offsetLeft:s,offsetTop:a,pageLeft:c,pageTop:d,scale:l}})}),"ParentInfo"),vn=pn("stopParentInfo");function kn(e){const n=e.getBoundingClientRect(),i=an(e.id);return{x:Number(n.left)+Number(i.x),y:Number(n.top)+Number(i.y)}}function Tn(e){const{x:n,y:i}=rn.position,t=Ie[e]?.iframe;!1!==nn(e,"onScroll",{iframe:t,top:i,left:n,x:n,y:i})?cn(e):sn()}const xn=e=>n=>{const{id:i,iframe:t,height:o,width:r}=n;const s=e?kn(t):{x:0,y:0},a={x:r+(c=s).x,y:o+c.y};var c;const d=window.parentIframe||window.parentIFrame;var l;Pe(i,`Reposition requested (offset x:%c${s.x}%c y:%c${s.y})`,Oe,Me,Oe),d?(l=a,d["scrollTo"+(e?"Offset":"")](l.x,l.y)):function(e){var n;n=e,rn.position=n,Tn(i)}(a)},zn=xn(!1),On=xn(!0);function Mn(e,n){const i=n.split("#")[1]||"",t=decodeURIComponent(i),o=document.getElementById(t)||document.getElementsByName(t)[0];o?function(e,n,i){const{x:t,y:o}=kn(i);Pe(e,`Moving to in page link: %c#${n}`,Oe),rn.position={x:t,y:o},Tn(e),window.location.hash=n}(e,i,o):window.top!==window.self?function(e,n){const i=window.parentIframe||window.parentIFrame;i?i.moveToAnchor(n):We(e,`In page link #${n} not found`)}(e,i):We(e,`In page link #${i} not found`)}function In(e){const n=Ie[e]?.iframe?.title;return""===n||void 0===n}let En=!1,Sn=!1;function Rn(e,n=-3){if(En)return;const i=Math.max(Ie[e].mode,n);if(i>Ie[e].mode&&(Ie[e].mode=i),i<0)throw Fe(e),Ie[e].vAdvised||_e(e||"Parent",`${W(i+2)}${W(2)}`),Ie[e].vAdvised=!0,W(i+2).replace(/<\/?[a-z][^>]*>|<\/>/gi,"");switch(i>5&&Sn||function(e,n){queueMicrotask(()=>console.info(`%ciframe-resizer ${e}`,Se||n<1?s:ze))}(`v${v} (${P(i)})`,i),i){case 1:case 2:case 3:_e("Parent",W(6));break;case 4:_e("Parent",W(7));break;case 5:_e("Parent",W(8));break;default:i<1&&_e("Parent",W(3))}En=!0}function Cn(e){const{height:n,id:i,iframe:t,mode:o,message:r,type:s,width:a}=e,{lastMessage:c}=Ie[i];switch(Ie[i]?.firstRun&&function(e,n){Ie[e]&&(We(e,`First run for ${e}`),Rn(e,void 0===n?void 0:Number(n)),Ie[e].firstRun=!1)}(i,o),We(i,`Received: %c${c}`,Oe),s){case V:Ie[i].autoResize=JSON.parse(tn(i,9));break;case X:Pe(i,"Ready state reset"),Ie[i].initialised=!1;break;case U:gn(t);break;case J:Mn(i,tn(i,9));break;case M:fn(e),function(e){try{Ie[e].sameOrigin=!!Ie[e]?.iframe?.contentWindow?.iframeChildListener}catch(n){Ie[e].sameOrigin=!1}We(e,`sameOrigin: %c${Ie[e].sameOrigin}`,Oe)}(i),function(e,n){n!==v&&(void 0!==n?We(e,`Version mismatch (Child: %c${n}%c !== Parent: %c${v})`,Oe,Me,Oe):_e(e,"<rb>Legacy version detected in iframe</>\n\nDetected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.\n\nSee <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.\n"))}(i,r),Ie[i].initialised=!0,nn(i,"onReady",t);break;case _:!function(e,n){const{id:i,iframe:t}=e;We(i,`onMessage passed: {iframe: %c${i}%c, message: %c${n}%c}`,Oe,Me,Oe,Me),nn(i,"onMessage",{iframe:t,message:JSON.parse(n)})}(e,tn(i,6));break;case G:on("onMouseEnter",e);break;case q:on("onMouseLeave",e);break;case L:wn(i);break;case A:$n(i);break;case j:yn(i);break;case F:vn(i);break;case I:mn(e);break;case N:!function(e){const{id:n,height:i,width:t}=e,o=window.parentIframe||window.parentIFrame||window;Pe(n,`scrollBy: x: %c${t}%c y: %c${i}`,Oe,Me,Oe),o.scrollBy(t,i)}(e);break;case H:zn(e);break;case D:On(e);break;case B:!function(e,n){Ie[e]?.syncTitle&&(Ie[e].iframe.title=n,Pe(e,`Set iframe title attribute: %c${n}`,Oe))}(i,r);break;default:if(0===a&&0===n)return void De(i,`Unsupported message received (${s}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===a||0===n)return void We(i,"Ignoring message with 0 height or width");if(document.hidden)return void We(i,"Page hidden - ignored resize request");fn(e)}}function Ln(e){const i=e.data;if(i===K)return t=e.source,void Object.values(Ie).forEach((e=>({initChild:n,postMessageTarget:i})=>{e===i&&n()})(t));var t,o;if(h!==`${o=i}`.slice(0,y)||!(o.slice(y).split(":")[0]in Ie)){if(typeof i!==Q)return;return Ne(n,"ignoredMessage"),void Be(n,i)}const r=Ze(i),{id:s,type:a}=r;switch(Ne(s,a),!0){case!Ie[s]:throw new Error(`${a} No settings for ${s}. Message was: ${i}`);case!function(e){const{id:n,msg:i,iframe:t}=e,o=$(t);return o||(We(n,`Received: %c${i}`,Oe),De(n,"The target iframe was not found.")),o}(r):case function(e){const{id:n,type:i}=e,t=i in en;return t&&We(n,"Ignoring init message from meta parent page"),t}(r):case!function(e,n){const{id:i}=e,{data:t,origin:o}=n;if("sameOrigin"in n&&n.sameOrigin)return!0;const r=Ie[i]?.checkOrigin;if(r&&"null"!=`${o}`&&!(r.constructor===Array?function(){We(i,`Checking connection is from allowed list of origins: %c${r}`,Oe);for(const e of r)if(e===o)return!0;return!1}():function(){const e=Ie[i]?.remoteHost;return We(i,`Checking connection is from: %c${e}`,Oe),o===e}()))throw new Error(`Unexpected message received from: ${o} for ${i}. Message was: ${t}. This error can be disabled by setting the checkOrigin: false option or by providing an array of trusted domains.`);return!0}(r,e):return;default:Ie[s].lastMessage=e.data,qe(s,Cn)(r)}}const An=Y(()=>{E(window,_,Ln),E(document,"visibilitychange",Qe),window.iframeParentListener=e=>setTimeout(()=>Ln({data:e,sameOrigin:!0}))}),Wn={};const Pn="8",Bn="32",Dn=ne,Hn=!0;function Nn(e,n){const{checkOrigin:i,iframe:{src:t,sandbox:o},initialisedFirstPage:r,waitForLoad:s}=n[e],a=(e=>{try{return new URL(e).origin}catch(n){return null}})(t);Ne(e,"noResponse"),_e(e,`<rb>No response from iframe</>\n\nThe iframe (<i>${e}</>) has not responded within ${n[e].warningTimeout/1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.\n${i&&a?`\nThe <b>checkOrigin</> option is currently enabled. If the iframe redirects away from <i>${a}</>, then the connection to the iframe may be blocked by the browser. To disable this option, set <b>checkOrigin</> to <bb>false</> or an array of allowed origins. See <u>https://iframe-resizer.com/checkorigin</> for more information.\n`:""}${s&&!r?"\nThe <b>waitForLoad</> option is currently set to <bb>true</>. If the iframe loads before <i>iframe-resizer</> runs, this option will prevent <i>iframe-resizer</> initialising. To disable this option, set <b>waitForLoad</> to <bb>false</>.\n":""}${(e=>typeof e===te&&e.length>0&&!(e.contains("allow-scripts")&&e.contains("allow-same-origin")))(o)?"\nThe iframe has the <b>sandbox</> attribute, please ensure it contains both the <bb>allow-same-origin</> and <bb>allow-scripts</> values.\n":""}\nThis message can be ignored if everything is working, or you can set the <b>warningTimeout</> option to a higher value or zero to suppress this warning.\n`)}function Fn(e,n){const i=i=>()=>{if(!Ie[e])return;const{firstRun:t,iframe:o}=Ie[e];Ke(i,n,e),(e=>e===M)(i)&&(e=>e.loading===re)(o)||function(e,n){const{msgTimeout:i,warningTimeout:t}=n[e];t&&(i&&clearTimeout(i),n[e].msgTimeout=setTimeout(function(){if(void 0===n[e])return;const{initialised:i,loadErrorShown:t}=n[e];n[e].msgTimeout=void 0,i?n[e].initialisedFirstPage=!0:t||(n[e].loadErrorShown=!0,Nn(e,n))},t))}(e,Ie),t||function(e){Ie[e]?.heightCalculationMethod in se&&mn({id:e,iframe:Ie[e].iframe,height:ae,width:ae,type:M})}(e)},{iframe:t}=Ie[e];Ie[e].initChild=i(oe),function(e,n){E(e,S,()=>setTimeout(n,1))}(t,i(ce)),function(e,n){const{iframe:i,waitForLoad:t}=Ie[e];!0!==t&&((e=>{const{src:n,srcdoc:i}=e;return!i&&(null==n||""===n||"about:blank"===n)})(i)?setTimeout(()=>{Ne(e,"noContent"),Pe(e,"No content detected in the iframe, delaying initialisation")}):setTimeout(n))}(e,i(M))}function jn(e,n){return n?(("sizeWidth"in n||"sizeHeight"in n||V in n)&&_e(e,`<rb>Deprecated Option</>\n\nThe <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <bb>${c}</>, <bb>${de}</>, <bb>${le}</> or <bb>${fe}</>.\n`),n):{}}const qn=e=>""===e||null!==e.match(/^(about:blank|javascript:|file:\/\/)/)?"*":e;function Gn(e,n,i){ue(Ie[e],n)&&(_e(e,`<rb>Deprecated option</>\n\nThe <b>${n}</> option has been renamed to <b>${i}</>. ${ge}`),Ie[e][i]=Ie[e][n],delete Ie[e][n])}const _n=e=>ue(e,"onMouseEnter")||ue(e,"onMouseLeave");function Jn(e,n){const{id:i}=e;Ie[i]={...Ie[i],iframe:e,remoteHost:e?.src.split("/").slice(0,3).join("/"),...Ue,...jn(i,n),mouseEvents:_n(n),mode:pe(n),syncTitle:In(i)},function(e){Gn(e,he,me),Gn(e,"onClose","onBeforeClose"),Gn(e,"onClosed","onAfterClose")}(i),function(e){const{direction:n}=Ie[e];switch(n){case c:break;case de:Ie[e].sizeHeight=!1;case le:Ie[e].sizeWidth=!0;break;case fe:Ie[e].sizeWidth=!1,Ie[e].sizeHeight=!1,Ie[e].autoResize=!1;break;default:throw new TypeError(`Direction value of "${n}" is not valid`)}We(e,`direction: %c${n}`,Oe)}(i),function(e,{offset:n,offsetSize:i}){const t=i||n;t&&(Ie[e].direction===c?(Ie[e].offsetHeight=t,We(e,`Offset height: %c${t}`,Oe)):(Ie[e].offsetWidth=t,We(e,`Offset width: %c${t}`,Oe)))}(i,n),function(e){Ie[e].warningTimeout||Pe(e,"warningTimeout:%c disabled",Oe)}(i),function(e){const{id:n}=e;null===Ie[n].postMessageTarget&&(Ie[n].postMessageTarget=e.contentWindow)}(e),function(e){const{checkOrigin:n,remoteHost:i}=Ie[e];Array.isArray(n)&&0===n.length&&De(e,"checkOrigin is an empty array — no messages will be sent to the iframe"),Ie[e].targetOrigin=Array.isArray(n)?n.map(qn):[!1===n?"*":qn(i)]}(i)}function Un(e,n,i){Jn(n,i),We(e,`src: %c${n.srcdoc||n.src}`,Oe),function(e){if(En)return;const{mode:n}=Ie[e];n>5&&Rn(e,n)}(e),function(e){const{id:n}=e;switch(We(n,`Iframe scrolling ${Ie[n]?.scrolling?"enabled":"disabled"} for ${n}`),e.style.overflow=!1===Ie[n]?.scrolling?be:a,Ie[n]?.scrolling){case we:break;case!0:e.scrolling="yes";break;case!1:e.scrolling="no";break;default:e.scrolling=Ie[n]?.scrolling||"no"}}(n),function(e){const{bodyMargin:n}=Ie[e];typeof n!==ie&&"0"!==n||(Ie[e].bodyMargin=`${n}px`)}(e),Fn(e,function(e){const{autoResize:n,bodyBackground:i,bodyMargin:t,bodyPadding:o,heightCalculationMethod:r,inPageLinks:s,license:a,log:c,logExpand:d,mouseEvents:l,offsetHeight:f,offsetWidth:u,mode:g,sizeHeight:m,sizeWidth:h,tolerance:p,widthCalculationMethod:w}=Ie[e];return[e,Pn,h,c,Bn,Hn,n,t,r,i,o,p,s,Dn,w,l,f,u,m,a,rn.version,g,"",d].join(b)}(e)),function(e){if(Ie[e]){const{iframe:n}=Ie[e];n.iframeResizer={close:gn.bind(null,n),disconnect:un.bind(null,n),moveToAnchor(n){ee(n,Q,"moveToAnchor(anchor) anchor"),Ke("Move to anchor",`moveToAnchor:${n}`,e)},sendMessage(n){n=JSON.stringify(n),Ke(_,`${_}:${n}`,e)}}}}(e),We(e,"Setup complete")}function Xn(e,n){const{id:i}=e;Ne(i,"setup"),function(e){if(!0===Wn[e])return!1;const n=document.querySelectorAll(`iframe#${CSS.escape(e)}`);if(n.length<=1)return!0;Wn[e]=!0;const i=Array.from(n).flatMap(e=>[Z,e,Z]);return _e(e,`<rb>Duplicate ID attributes detected</>\n\nThe <b>${e}</> ID is not unique. Having multiple iframes on the same page with the same ID causes problems with communication between the iframe and parent page. Please ensure that the ID of each iframe has a unique value.\n\nFound <bb>${n.length}</> iframes with the <b>${e}</> ID:`,...i,Z),!1}(i)&&Un(i,e,n),je(i)}function Vn(e,n){n.log===m?n.log=!1:n.log===f?n.log=l:n.log===u&&(n.log=g);const i=ue(n,"log"),t=d(n.log),o=i?!!t||n.log:Ue.log;ue(n,"logExpand")||(n.logExpand=i&&t?n.log===g:Ue.logExpand),function(e){-1===e?.log&&(e.log=!1,Sn=!0)}(n),function({enabled:e,expand:n,iframeId:i}){const t=Ee({expand:n,label:Ce(i)});Se=e,Ie[i]||(Ie[i]={console:t})}({enabled:o,expand:n.logExpand,iframeId:e}),t&&!(n.log in ye)&&He(e,`Invalid value for options.log: Accepted values are "${g}" and "${l}"`),n.log=o}function Yn(e){if(!$e(e))throw new TypeError("Options is not an object");return An(),function(e){const{search:n}=window.location;if(n.includes("ifrlog"))switch(new URLSearchParams(n).get("ifrlog")){case String(m):e.log=!1;break;case g:case String(u):e.log=g;break;case l:case String(f):default:e.log=l}}(e),n=>{const i=Ve(n,e);return r in n?(Ne(i,"alreadySetup"),De(i,`Ignored iframe (${i}), already setup.`)):(Vn(i,e),qe(i,Xn)(n,e)),n?.iframeResizer}}export{ve as LOG_COLLAPSED,ke as LOG_DISABLED,Te as LOG_EXPANDED,Yn as default};
967
21
  //# sourceMappingURL=index.esm.js.map