@open-iframe-resizer/core 1.6.1 → 2.0.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 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@latest/dist/index.min.js";
20
+ import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@v2.0.0/dist/index.min.js";
21
21
 
22
22
  initialize({}, "#my-iframe");
23
23
  </script>
package/dist/index.d.ts CHANGED
@@ -27,9 +27,9 @@ export declare function initializeChildListener(): void;
27
27
  * Automatically resize the selected iframes when their inner content grows.
28
28
  * @param settings The settings for the selected iframes. The default settings properties are picked if empty.
29
29
  * @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 often remove iframes from the document.
30
+ * @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
31
  */
32
- export declare type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => InitializeResult[];
32
+ export declare type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => Promise<InitializeResult[]>;
33
33
 
34
34
  export declare type InitializeResult = { unsubscribe: () => void };
35
35
 
package/dist/index.js CHANGED
@@ -1,17 +1,27 @@
1
- const v = () => typeof window < "u", S = () => window.self !== window.top, y = (e) => e instanceof HTMLIFrameElement, E = (e) => {
2
- window.document.readyState === "complete" ? e() : window.addEventListener("load", e);
3
- }, M = (e, t) => {
4
- t(), e.addEventListener("load", t);
1
+ const z = () => typeof window < "u", R = () => {
2
+ try {
3
+ return window.self !== window.top;
4
+ } catch {
5
+ return !0;
6
+ }
7
+ }, b = (e) => e instanceof HTMLIFrameElement, M = (e) => {
8
+ window.document.readyState === "complete" ? e() : window.addEventListener("load", e, { once: !0 });
5
9
  }, T = (e, t) => {
10
+ t(), e.addEventListener("load", t, { once: !0 });
11
+ }, C = (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
- }, C = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), B = (e) => {
13
+ return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t, { once: !0 });
14
+ }, D = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 });
15
+ async function k(e) {
9
16
  try {
10
- return new URL(e.src).origin === window.location.origin;
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
- }, k = (e) => {
23
+ }
24
+ const B = (e) => {
15
25
  try {
16
26
  const t = new URL(e.src).origin;
17
27
  if (t !== "about:blank")
@@ -19,7 +29,7 @@ const v = () => typeof window < "u", S = () => window.self !== window.top, y = (
19
29
  } catch {
20
30
  }
21
31
  return null;
22
- }, D = (e) => (Object.keys(e).forEach((t) => {
32
+ }, P = (e) => (Object.keys(e).forEach((t) => {
23
33
  e[t] === void 0 && delete e[t];
24
34
  }), e), p = (e) => {
25
35
  const { height: t, width: n } = e.getBoundingClientRect();
@@ -33,88 +43,90 @@ function A(e) {
33
43
  const [t, n] = e.data.split(":"), i = +n;
34
44
  return i > 0 ? i : null;
35
45
  }
36
- const b = _();
46
+ const w = q();
37
47
  let l = [];
38
- const J = (e, t) => {
39
- if (!v())
48
+ const K = async (e, t) => {
49
+ if (!z())
40
50
  return [];
41
- const n = { ...C(), ...D(e ?? {}) }, i = H(t), s = P(n, i);
42
- return i.map((r) => {
43
- const o = {
44
- iframe: r,
45
- settings: n,
46
- interactionState: { isHovered: !1 },
47
- initContext: { isInitialized: !1, retryAttempts: 0 }
48
- }, a = x(o, s);
49
- return l.push(o), {
50
- unsubscribe: () => {
51
- a(), l = l.filter((c) => c.iframe !== r);
52
- }
53
- };
54
- });
51
+ const n = { ...D(), ...P(e ?? {}) }, i = H(t), r = x(n, i);
52
+ return Promise.all(
53
+ i.map(async (o) => {
54
+ const s = {
55
+ iframe: o,
56
+ settings: n,
57
+ interactionState: { isHovered: !1 },
58
+ initContext: { isInitialized: !1, retryAttempts: 0 }
59
+ }, a = await F(s, r);
60
+ return l.push(s), {
61
+ unsubscribe: () => {
62
+ a(), l = l.filter((c) => c.iframe !== o);
63
+ }
64
+ };
65
+ })
66
+ );
55
67
  };
56
68
  function H(e) {
57
- return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(y) : e ? y(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
69
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(b) : e ? b(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
58
70
  }
59
- function P(e, t) {
71
+ function x(e, t) {
60
72
  if (Array.isArray(e.checkOrigin))
61
73
  return e.checkOrigin;
62
74
  if (!e.checkOrigin)
63
75
  return [];
64
76
  const n = [];
65
77
  for (const i of t) {
66
- const s = k(i);
67
- s && n.push(s);
78
+ const r = B(i);
79
+ r && n.push(r);
68
80
  }
69
81
  return n;
70
82
  }
71
- function x(e, t) {
72
- const n = B(e.iframe) ? N(e) : F(e, t), i = U(e);
83
+ async function F(e, t) {
84
+ const i = await k(e.iframe) ? U(e) : N(e, t), r = $(e);
73
85
  return () => {
74
- n(), i();
86
+ i(), r();
75
87
  };
76
88
  }
77
- function F(e, t) {
89
+ function N(e, t) {
78
90
  const {
79
91
  iframe: n,
80
92
  initContext: i,
81
- settings: { checkOrigin: s, enableLegacyLibSupport: r, targetElementSelector: o, bodyPadding: a, bodyMargin: c }
82
- } = e, h = (d) => {
83
- const R = !s || t.includes(d.origin);
84
- if (!(!(n.contentWindow === d.source) || !R)) {
85
- if (d.data?.type === "iframe-resized") {
86
- const { height: u } = d.data;
87
- u && g({ newHeight: u, registeredElement: e });
93
+ settings: { checkOrigin: r, enableLegacyLibSupport: o, targetElementSelector: s, bodyPadding: a, bodyMargin: c }
94
+ } = e, h = (u) => {
95
+ const S = u.origin === "null", E = !r || S || t.includes(u.origin);
96
+ if (!(!(n.contentWindow === u.source) || !E)) {
97
+ if (u.data?.type === "iframe-resized") {
98
+ const { height: d } = u.data;
99
+ d && g({ newHeight: d, registeredElement: e });
88
100
  return;
89
101
  }
90
- if (r) {
91
- const u = A(d);
92
- u !== null && g({ newHeight: u, registeredElement: e });
102
+ if (o) {
103
+ const d = A(u);
104
+ d !== null && g({ newHeight: d, registeredElement: e });
93
105
  return;
94
106
  }
95
107
  }
96
108
  };
97
109
  window.addEventListener("message", h);
98
- const O = r ? W() : { type: "iframe-child-init", targetElementSelector: o, bodyPadding: a, bodyMargin: c }, w = () => {
99
- M(n, () => n.contentWindow?.postMessage(O, "*")), i.retryAttempts++, i.retryTimeoutId = window.setTimeout(w, m(i.retryAttempts));
110
+ const I = o ? W() : { type: "iframe-child-init", targetElementSelector: s, bodyPadding: a, bodyMargin: c }, y = () => {
111
+ T(n, () => n.contentWindow?.postMessage(I, "*")), i.retryAttempts++, i.retryTimeoutId = window.setTimeout(y, m(i.retryAttempts));
100
112
  };
101
- return w(), () => window.removeEventListener("message", h);
113
+ return y(), () => window.removeEventListener("message", h);
102
114
  }
103
- function N(e) {
115
+ function U(e) {
104
116
  const { iframe: t, settings: n } = e, { targetElementSelector: i } = n;
105
- let s = 0;
106
- const r = () => {
107
- const o = f(t.contentDocument, i);
108
- if (!t.contentDocument || !o)
109
- return s++, setTimeout(r, m(s));
110
- L(t.contentDocument, n), b().observe(o);
117
+ let r = 0;
118
+ const o = () => {
119
+ const s = f(t.contentDocument, i);
120
+ if (!t.contentDocument || !s)
121
+ return r++, setTimeout(o, m(r));
122
+ L(t.contentDocument, n), w().observe(s);
111
123
  };
112
- return T(t, r), () => {
113
- const o = f(t.contentDocument, i);
114
- o && b().unobserve(o), t.removeEventListener("load", r);
124
+ return C(t, o), () => {
125
+ const s = f(t.contentDocument, i);
126
+ s && w().unobserve(s), t.removeEventListener("load", o);
115
127
  };
116
128
  }
117
- function U({ iframe: e, interactionState: t }) {
129
+ function $({ iframe: e, interactionState: t }) {
118
130
  const n = () => {
119
131
  t.isHovered = !0;
120
132
  }, i = () => {
@@ -124,7 +136,7 @@ function U({ iframe: e, interactionState: t }) {
124
136
  e.removeEventListener("mouseenter", n), e.removeEventListener("mouseleave", i);
125
137
  };
126
138
  }
127
- function _() {
139
+ function q() {
128
140
  let e = null;
129
141
  return () => {
130
142
  if (!e) {
@@ -132,10 +144,10 @@ function _() {
132
144
  const i = l.find(({ iframe: c }) => c.contentDocument === n.ownerDocument);
133
145
  if (!i)
134
146
  return;
135
- const { iframe: s, settings: r } = i, o = f(s.contentDocument, r.targetElementSelector);
136
- if (!o)
147
+ const { iframe: r, settings: o } = i, s = f(r.contentDocument, o.targetElementSelector);
148
+ if (!s)
137
149
  return;
138
- const { height: a } = p(o);
150
+ const { height: a } = p(s);
139
151
  a && g({ newHeight: a, registeredElement: i });
140
152
  };
141
153
  e = new ResizeObserver((n) => n.forEach(t));
@@ -144,57 +156,57 @@ function _() {
144
156
  };
145
157
  }
146
158
  function g({ registeredElement: e, newHeight: t }) {
147
- const { iframe: n, settings: i, interactionState: s, initContext: r } = e;
148
- if (r.isInitialized || (r.isInitialized = !0, clearTimeout(r.retryTimeoutId)), i.onBeforeIframeResize?.({ iframe: n, settings: { ...i }, observedHeight: t }) === !1)
159
+ const { iframe: n, settings: i, interactionState: r, initContext: o } = e;
160
+ if (o.isInitialized || (o.isInitialized = !0, clearTimeout(o.retryTimeoutId)), i.onBeforeIframeResize?.({ iframe: n, settings: { ...i }, observedHeight: t }) === !1)
149
161
  return;
150
- const o = n.getBoundingClientRect(), a = t + i.offsetSize;
162
+ const s = n.getBoundingClientRect(), a = t + i.offsetSize;
151
163
  if (n.style.height = `${a}px`, !i.onIframeResize)
152
164
  return;
153
165
  const c = {
154
166
  iframe: n,
155
167
  settings: { ...i },
156
- interactionState: { ...s },
157
- previousRenderState: { rect: o },
168
+ interactionState: { ...r },
169
+ previousRenderState: { rect: s },
158
170
  nextRenderState: { rect: n.getBoundingClientRect() }
159
171
  };
160
172
  i.onIframeResize(c);
161
173
  }
162
- const $ = V();
163
- let z = !1;
164
- q();
165
- function q() {
166
- !v() || !S() || window.addEventListener("message", (e) => {
167
- e.data?.type === "iframe-child-init" && E(() => I(e));
174
+ const _ = G();
175
+ let v = !1;
176
+ V();
177
+ function V() {
178
+ !z() || !R() || window.addEventListener("message", (e) => {
179
+ e.data?.type === "iframe-child-init" && M(() => O(e));
168
180
  });
169
181
  }
170
- function I(e, t = 0) {
171
- const { targetElementSelector: n, bodyPadding: i, bodyMargin: s } = e.data, r = f(document, n);
172
- if (z || window.parent !== e.source)
182
+ function O(e, t = 0) {
183
+ const { targetElementSelector: n, bodyPadding: i, bodyMargin: r } = e.data, o = f(document, n);
184
+ if (v || window.parent !== e.source)
173
185
  return;
174
- if (!r)
175
- return setTimeout(() => I(e, t + 1), m(t));
176
- L(document, { bodyMargin: s, bodyPadding: i });
177
- const o = $();
178
- o.disconnect(), o.observe(r), z = !0;
186
+ if (!o)
187
+ return setTimeout(() => O(e, t + 1), m(t));
188
+ L(document, { bodyMargin: r, bodyPadding: i });
189
+ const s = _();
190
+ s.disconnect(), s.observe(o), v = !0;
179
191
  }
180
- function V() {
192
+ function G() {
181
193
  let e = null;
182
194
  return () => (e || (e = new ResizeObserver((t) => {
183
195
  if (!t[0].target)
184
196
  return;
185
- const { height: n, width: i } = p(t[0].target), s = {
197
+ const { height: n, width: i } = p(t[0].target), r = {
186
198
  type: "iframe-resized",
187
199
  width: i,
188
200
  height: n
189
201
  };
190
- window.parent.postMessage(s, "*");
202
+ window.parent.postMessage(r, "*");
191
203
  })), e);
192
204
  }
193
- const K = ({ previousRenderState: e, nextRenderState: t, iframe: n }) => {
205
+ const Q = ({ previousRenderState: e, nextRenderState: t, iframe: n }) => {
194
206
  document.activeElement === n && window.scrollBy(0, t.rect.bottom - e.rect.bottom);
195
207
  };
196
208
  export {
197
- J as initialize,
198
- q as initializeChildListener,
199
- K as updateParentScrollOnResize
209
+ K as initialize,
210
+ V as initializeChildListener,
211
+ Q as updateParentScrollOnResize
200
212
  };
@@ -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",R=()=>window.self!==window.top,b=e=>e instanceof HTMLIFrameElement,E=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e)},T=(e,t)=>{t(),e.addEventListener("load",t)},M=(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)},C=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),B=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},k=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},D=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&delete e[t]}),e),w=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},g=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,z=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},h=e=>e<=100?100:e<=120?1e3:1e4,P=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function W(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 p=$();let m=[];const A=(e,t)=>{if(!u())return[];const n={...C(),...D(e??{})},i=H(t),s=x(n,i);return i.map(r=>{const o={iframe:r,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},c=F(o,s);return m.push(o),{unsubscribe:()=>{c(),m=m.filter(d=>d.iframe!==r)}}})};function H(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(b):e?b(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function x(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const i of t){const s=k(i);s&&n.push(s)}return n}function F(e,t){const n=B(e.iframe)?U(e):N(e,t),i=_(e);return()=>{n(),i()}}function N(e,t){const{iframe:n,initContext:i,settings:{checkOrigin:s,enableLegacyLibSupport:r,targetElementSelector:o,bodyPadding:c,bodyMargin:d}}=e,I=l=>{const J=!s||t.includes(l.origin);if(!(!(n.contentWindow===l.source)||!J)){if(l.data?.type==="iframe-resized"){const{height:f}=l.data;f&&y({newHeight:f,registeredElement:e});return}if(r){const f=W(l);f!==null&&y({newHeight:f,registeredElement:e});return}}};window.addEventListener("message",I);const G=r?P():{type:"iframe-child-init",targetElementSelector:o,bodyPadding:c,bodyMargin:d},S=()=>{T(n,()=>n.contentWindow?.postMessage(G,"*")),i.retryAttempts++,i.retryTimeoutId=window.setTimeout(S,h(i.retryAttempts))};return S(),()=>window.removeEventListener("message",I)}function U(e){const{iframe:t,settings:n}=e,{targetElementSelector:i}=n;let s=0;const r=()=>{const o=g(t.contentDocument,i);if(!t.contentDocument||!o)return s++,setTimeout(r,h(s));z(t.contentDocument,n),p().observe(o)};return M(t,r),()=>{const o=g(t.contentDocument,i);o&&p().unobserve(o),t.removeEventListener("load",r)}}function _({iframe:e,interactionState:t}){const n=()=>{t.isHovered=!0},i=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",i)}}function $(){let e=null;return()=>{if(!e){const t=({target:n})=>{const i=m.find(({iframe:d})=>d.contentDocument===n.ownerDocument);if(!i)return;const{iframe:s,settings:r}=i,o=g(s.contentDocument,r.targetElementSelector);if(!o)return;const{height:c}=w(o);c&&y({newHeight:c,registeredElement:i})};e=new ResizeObserver(n=>n.forEach(t))}return e}}function y({registeredElement:e,newHeight:t}){const{iframe:n,settings:i,interactionState:s,initContext:r}=e;if(r.isInitialized||(r.isInitialized=!0,clearTimeout(r.retryTimeoutId)),i.onBeforeIframeResize?.({iframe:n,settings:{...i},observedHeight:t})===!1)return;const o=n.getBoundingClientRect(),c=t+i.offsetSize;if(n.style.height=`${c}px`,!i.onIframeResize)return;const d={iframe:n,settings:{...i},interactionState:{...s},previousRenderState:{rect:o},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(d)}const q=V();let v=!1;L();function L(){!u()||!R()||window.addEventListener("message",e=>{e.data?.type==="iframe-child-init"&&E(()=>O(e))})}function O(e,t=0){const{targetElementSelector:n,bodyPadding:i,bodyMargin:s}=e.data,r=g(document,n);if(v||window.parent!==e.source)return;if(!r)return setTimeout(()=>O(e,t+1),h(t));z(document,{bodyMargin:s,bodyPadding:i});const o=q();o.disconnect(),o.observe(r),v=!0}function V(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{if(!t[0].target)return;const{height:n,width:i}=w(t[0].target),s={type:"iframe-resized",width:i,height:n};window.parent.postMessage(s,"*")})),e)}const j=({previousRenderState:e,nextRenderState:t,iframe:n})=>{document.activeElement===n&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)};a.initialize=A,a.initializeChildListener=L,a.updateParentScrollOnResize=j,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
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",R=()=>{try{return window.self!==window.top}catch{return!0}},b=e=>e instanceof HTMLIFrameElement,E=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e,{once:!0})},T=(e,t)=>{t(),e.addEventListener("load",t,{once:!0})},M=(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})},C=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1});async function D(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 k=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},B=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&delete e[t]}),e),w=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},g=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,z=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},h=e=>e<=100?100:e<=120?1e3:1e4,P=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function W(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 p=q();let m=[];const A=async(e,t)=>{if(!u())return[];const n={...C(),...B(e??{})},i=H(t),r=x(n,i);return Promise.all(i.map(async o=>{const s={iframe:o,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},c=await F(s,r);return m.push(s),{unsubscribe:()=>{c(),m=m.filter(d=>d.iframe!==o)}}}))};function H(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(b):e?b(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function x(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const i of t){const r=k(i);r&&n.push(r)}return n}async function F(e,t){const i=await D(e.iframe)?U(e):N(e,t),r=$(e);return()=>{i(),r()}}function N(e,t){const{iframe:n,initContext:i,settings:{checkOrigin:r,enableLegacyLibSupport:o,targetElementSelector:s,bodyPadding:c,bodyMargin:d}}=e,I=l=>{const J=l.origin==="null",K=!r||J||t.includes(l.origin);if(!(!(n.contentWindow===l.source)||!K)){if(l.data?.type==="iframe-resized"){const{height:f}=l.data;f&&y({newHeight:f,registeredElement:e});return}if(o){const f=W(l);f!==null&&y({newHeight:f,registeredElement:e});return}}};window.addEventListener("message",I);const G=o?P():{type:"iframe-child-init",targetElementSelector:s,bodyPadding:c,bodyMargin:d},S=()=>{T(n,()=>n.contentWindow?.postMessage(G,"*")),i.retryAttempts++,i.retryTimeoutId=window.setTimeout(S,h(i.retryAttempts))};return S(),()=>window.removeEventListener("message",I)}function U(e){const{iframe:t,settings:n}=e,{targetElementSelector:i}=n;let r=0;const o=()=>{const s=g(t.contentDocument,i);if(!t.contentDocument||!s)return r++,setTimeout(o,h(r));z(t.contentDocument,n),p().observe(s)};return M(t,o),()=>{const s=g(t.contentDocument,i);s&&p().unobserve(s),t.removeEventListener("load",o)}}function $({iframe:e,interactionState:t}){const n=()=>{t.isHovered=!0},i=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",i)}}function q(){let e=null;return()=>{if(!e){const t=({target:n})=>{const i=m.find(({iframe:d})=>d.contentDocument===n.ownerDocument);if(!i)return;const{iframe:r,settings:o}=i,s=g(r.contentDocument,o.targetElementSelector);if(!s)return;const{height:c}=w(s);c&&y({newHeight:c,registeredElement:i})};e=new ResizeObserver(n=>n.forEach(t))}return e}}function y({registeredElement:e,newHeight:t}){const{iframe:n,settings:i,interactionState:r,initContext:o}=e;if(o.isInitialized||(o.isInitialized=!0,clearTimeout(o.retryTimeoutId)),i.onBeforeIframeResize?.({iframe:n,settings:{...i},observedHeight:t})===!1)return;const s=n.getBoundingClientRect(),c=t+i.offsetSize;if(n.style.height=`${c}px`,!i.onIframeResize)return;const d={iframe:n,settings:{...i},interactionState:{...r},previousRenderState:{rect:s},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(d)}const _=V();let v=!1;O();function O(){!u()||!R()||window.addEventListener("message",e=>{e.data?.type==="iframe-child-init"&&E(()=>L(e))})}function L(e,t=0){const{targetElementSelector:n,bodyPadding:i,bodyMargin:r}=e.data,o=g(document,n);if(v||window.parent!==e.source)return;if(!o)return setTimeout(()=>L(e,t+1),h(t));z(document,{bodyMargin:r,bodyPadding:i});const s=_();s.disconnect(),s.observe(o),v=!0}function V(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{if(!t[0].target)return;const{height:n,width:i}=w(t[0].target),r={type:"iframe-resized",width:i,height:n};window.parent.postMessage(r,"*")})),e)}const j=({previousRenderState:e,nextRenderState:t,iframe:n})=>{document.activeElement===n&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)};a.initialize=A,a.initializeChildListener=O,a.updateParentScrollOnResize=j,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-iframe-resizer/core",
3
3
  "private": false,
4
- "version": "1.6.1",
4
+ "version": "2.0.0",
5
5
  "description": "Open-source modern iframe resizer",
6
6
  "license": "MIT",
7
7
  "repository": {