@open-iframe-resizer/core 1.4.1 → 1.4.2
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/dist/index.js +22 -23
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,25 +20,24 @@ const p = () => typeof window < "u", R = () => window.self !== window.top, b = (
|
|
|
20
20
|
} catch {
|
|
21
21
|
}
|
|
22
22
|
return null;
|
|
23
|
-
},
|
|
23
|
+
}, W = (e) => (Object.keys(e).forEach((t) => e[t] === void 0 && delete e[t]), e), L = (e) => {
|
|
24
24
|
const { height: t, width: n } = e.getBoundingClientRect();
|
|
25
25
|
return { height: Math.ceil(t), width: Math.ceil(n) };
|
|
26
|
-
}, f = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null,
|
|
26
|
+
}, f = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, O = (e, t) => {
|
|
27
27
|
e && (t.bodyPadding && (e.body.style.padding = t.bodyPadding), t.bodyMargin && (e.body.style.margin = t.bodyMargin));
|
|
28
|
-
}, m = (e) => e <= 100 ? 100 : e <= 120 ? 1e3 : 1e4,
|
|
29
|
-
function
|
|
30
|
-
if (typeof e.data
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return null;
|
|
28
|
+
}, m = (e) => e <= 100 ? 100 : e <= 120 ? 1e3 : 1e4, A = () => "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";
|
|
29
|
+
function H(e) {
|
|
30
|
+
if (typeof e.data != "string" || !e.data.startsWith("[iFrameSizer]") || !e.data.endsWith("mutationObserver") && !e.data.endsWith("resizeObserver"))
|
|
31
|
+
return null;
|
|
32
|
+
const [t, n] = e.data.split(":"), i = +n;
|
|
33
|
+
return i > 0 ? i : null;
|
|
35
34
|
}
|
|
36
|
-
const
|
|
35
|
+
const z = q();
|
|
37
36
|
let l = [];
|
|
38
37
|
const K = (e, t) => {
|
|
39
38
|
if (!p())
|
|
40
39
|
return [];
|
|
41
|
-
const n = { ...k(), ...
|
|
40
|
+
const n = { ...k(), ...W(e ?? {}) }, i = P(t), o = x(n, i);
|
|
42
41
|
return i.map((r) => {
|
|
43
42
|
const s = {
|
|
44
43
|
iframe: r,
|
|
@@ -53,7 +52,7 @@ const K = (e, t) => {
|
|
|
53
52
|
};
|
|
54
53
|
});
|
|
55
54
|
};
|
|
56
|
-
function
|
|
55
|
+
function P(e) {
|
|
57
56
|
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(b) : e ? b(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
|
|
58
57
|
}
|
|
59
58
|
function x(e, t) {
|
|
@@ -89,14 +88,14 @@ function N(e, t) {
|
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
90
|
if (r) {
|
|
92
|
-
const u =
|
|
91
|
+
const u = H(c);
|
|
93
92
|
u !== null && g({ newHeight: u, registeredElement: e });
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
};
|
|
98
97
|
window.addEventListener("message", h);
|
|
99
|
-
const S = r ?
|
|
98
|
+
const S = r ? A() : { type: "iframe-child-init", targetElementSelector: s, bodyPadding: a, bodyMargin: d }, w = () => {
|
|
100
99
|
T(n, () => {
|
|
101
100
|
var c;
|
|
102
101
|
return (c = n.contentWindow) == null ? void 0 : c.postMessage(S, "*");
|
|
@@ -111,11 +110,11 @@ function U(e) {
|
|
|
111
110
|
const s = f(t.contentDocument, i);
|
|
112
111
|
if (!t.contentDocument || !s)
|
|
113
112
|
return o++, setTimeout(r, m(o));
|
|
114
|
-
|
|
113
|
+
O(t.contentDocument, n), z().observe(s);
|
|
115
114
|
};
|
|
116
115
|
return C(t, r), () => {
|
|
117
116
|
const s = f(t.contentDocument, i);
|
|
118
|
-
s &&
|
|
117
|
+
s && z().unobserve(s), t.removeEventListener("load", r);
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
function $({ iframe: e, interactionState: t }) {
|
|
@@ -163,23 +162,23 @@ function g({ registeredElement: e, newHeight: t }) {
|
|
|
163
162
|
i.onIframeResize(d);
|
|
164
163
|
}
|
|
165
164
|
const V = G();
|
|
166
|
-
let
|
|
165
|
+
let v = !1;
|
|
167
166
|
_();
|
|
168
167
|
function _() {
|
|
169
168
|
!p() || !R() || window.addEventListener("message", (e) => {
|
|
170
169
|
var t;
|
|
171
|
-
((t = e.data) == null ? void 0 : t.type) === "iframe-child-init" && M(() =>
|
|
170
|
+
((t = e.data) == null ? void 0 : t.type) === "iframe-child-init" && M(() => I(e));
|
|
172
171
|
});
|
|
173
172
|
}
|
|
174
|
-
function
|
|
173
|
+
function I(e, t = 0) {
|
|
175
174
|
const { targetElementSelector: n, bodyPadding: i, bodyMargin: o } = e.data, r = f(document, n);
|
|
176
|
-
if (
|
|
175
|
+
if (v || window.parent !== e.source)
|
|
177
176
|
return;
|
|
178
177
|
if (!r)
|
|
179
|
-
return setTimeout(() =>
|
|
180
|
-
|
|
178
|
+
return setTimeout(() => I(e, t + 1), m(t));
|
|
179
|
+
O(document, { bodyMargin: o, bodyPadding: i });
|
|
181
180
|
const s = V();
|
|
182
|
-
s.disconnect(), s.observe(r),
|
|
181
|
+
s.disconnect(), s.observe(r), v = !0;
|
|
183
182
|
}
|
|
184
183
|
function G() {
|
|
185
184
|
let e = null;
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.iframeResizer={}))})(this,function(a){"use strict";const l=()=>typeof window<"u",E=()=>window.self!==window.top,w=e=>e instanceof HTMLIFrameElement,T=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e)},M=(e,t)=>{t(),e.addEventListener("load",t)},C=(e,t)=>{var o,r;const n=((o=e.contentWindow)==null?void 0:o.document.readyState)==="complete";return e.src!=="about:blank"&&((r=e.contentWindow)==null?void 0:r.location.href)!=="about:blank"&&n?t():e.addEventListener("load",t)},k=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),B=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},D=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},P=e=>(Object.keys(e).forEach(t=>e[t]===void 0&&delete e[t]),e),b=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,
|
|
1
|
+
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.iframeResizer={}))})(this,function(a){"use strict";const l=()=>typeof window<"u",E=()=>window.self!==window.top,w=e=>e instanceof HTMLIFrameElement,T=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e)},M=(e,t)=>{t(),e.addEventListener("load",t)},C=(e,t)=>{var o,r;const n=((o=e.contentWindow)==null?void 0:o.document.readyState)==="complete";return e.src!=="about:blank"&&((r=e.contentWindow)==null?void 0:r.location.href)!=="about:blank"&&n?t():e.addEventListener("load",t)},k=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),B=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},D=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},P=e=>(Object.keys(e).forEach(t=>e[t]===void 0&&delete e[t]),e),b=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,W=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function A(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=V();let m=[];const H=(e,t)=>{if(!l())return[];const n={...k(),...P(e??{})},i=x(t),o=F(n,i);return i.map(r=>{const s={iframe:r,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},c=N(s,o);return m.push(s),{unsubscribe:()=>{c(),m=m.filter(u=>u.iframe!==r)}}})};function x(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(w):e?w(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function F(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const i of t){const o=D(i);o&&n.push(o)}return n}function N(e,t){const n=B(e.iframe)?$(e):U(e,t),i=q(e);return()=>{n(),i()}}function U(e,t){const{iframe:n,initContext:i,settings:{checkOrigin:o,enableLegacyLibSupport:r,targetElementSelector:s,bodyPadding:c,bodyMargin:u}}=e,I=d=>{var R;const K=!o||t.includes(d.origin);if(!(!(n.contentWindow===d.source)||!K)){if(((R=d.data)==null?void 0:R.type)==="iframe-resized"){const{height:f}=d.data;f&&y({newHeight:f,registeredElement:e});return}if(r){const f=A(d);f!==null&&y({newHeight:f,registeredElement:e});return}}};window.addEventListener("message",I);const J=r?W():{type:"iframe-child-init",targetElementSelector:s,bodyPadding:c,bodyMargin:u},S=()=>{M(n,()=>{var d;return(d=n.contentWindow)==null?void 0:d.postMessage(J,"*")}),i.retryAttempts++,i.retryTimeoutId=window.setTimeout(S,h(i.retryAttempts))};return S(),()=>window.removeEventListener("message",I)}function $(e){const{iframe:t,settings:n}=e,{targetElementSelector:i}=n;let o=0;const r=()=>{const s=g(t.contentDocument,i);if(!t.contentDocument||!s)return o++,setTimeout(r,h(o));z(t.contentDocument,n),p().observe(s)};return C(t,r),()=>{const s=g(t.contentDocument,i);s&&p().unobserve(s),t.removeEventListener("load",r)}}function q({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 V(){let e=null;return()=>{if(!e){const t=({target:n})=>{const i=m.find(({iframe:u})=>u.contentDocument===n.ownerDocument);if(!i)return;const{iframe:o,settings:r}=i,s=g(o.contentDocument,r.targetElementSelector);if(!s)return;const{height:c}=b(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:o,initContext:r}=e;r.isInitialized||(r.isInitialized=!0,clearTimeout(r.retryTimeoutId));const s=n.getBoundingClientRect(),c=t+i.offsetSize;if(n.style.height=`${c}px`,!i.onIframeResize)return;const u={iframe:n,settings:{...i},interactionState:{...o},previousRenderState:{rect:s},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(u)}const _=j();let v=!1;L();function L(){!l()||!E()||window.addEventListener("message",e=>{var t;((t=e.data)==null?void 0:t.type)==="iframe-child-init"&&T(()=>O(e))})}function O(e,t=0){const{targetElementSelector:n,bodyPadding:i,bodyMargin:o}=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:o,bodyPadding:i});const s=_();s.disconnect(),s.observe(r),v=!0}function j(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{if(!t[0].target)return;const{height:n,width:i}=b(t[0].target),o={type:"iframe-resized",width:i,height:n};window.parent.postMessage(o,"*")})),e)}const G=({previousRenderState:e,nextRenderState:t,iframe:n})=>{document.activeElement===n&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)};a.initialize=H,a.initializeChildListener=L,a.updateParentScrollOnResize=G,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|