@open-iframe-resizer/core 2.1.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.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.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",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"})});
|
|
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"})}));
|