@iframe-resizer/parent
Advanced tools
Comparing version 5.0.0-alpha.11 to 5.0.0-alpha.12
/*! | ||
* @preserve | ||
* | ||
* @module iframe-resizer/parent 5.0.0-alpha.11 (cjs) - 2024-04-26 | ||
* @module iframe-resizer/parent 5.0.0-alpha.12 (cjs) - 2024-04-26 | ||
* | ||
@@ -6,0 +6,0 @@ * @license GPL-3.0 for non-commercial use only. |
/*! | ||
* @preserve | ||
* | ||
* @module iframe-resizer/parent 5.0.0-alpha.11 (esm) - 2024-04-26 | ||
* @module iframe-resizer/parent 5.0.0-alpha.12 (esm) - 2024-04-26 | ||
* | ||
@@ -6,0 +6,0 @@ * @license GPL-3.0 for non-commercial use only. |
/*! | ||
* @preserve | ||
* | ||
* @module iframe-resizer/parent 5.0.0-alpha.11 (umd) - 2024-04-26 | ||
* @module iframe-resizer/parent 5.0.0-alpha.12 (umd) - 2024-04-26 | ||
* | ||
@@ -20,2 +20,2 @@ * @license GPL-3.0 for non-commercial use only. | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).iframeResize=n()}(this,(function(){"use strict";const e="[iframeResizer]";const n=n=>`${e}[${function(e){return window.top===window.self?`Host page: ${e}`:window?.parentIFrame?.getId?`${window.parentIFrame.getId()}: ${e}`:`Nested host page: ${e}`}(n)}]`,t=(e,t,...i)=>window?.console[e](n(t),...i),i=(e,...n)=>t("info",e,...n),o=(e,...n)=>t("warn",e,...n),r=(n,t)=>window?.console.warn(((n,...t)=>[`${e}[${n}]`,...t])(n,window.chrome?t:t.replaceAll(/\u001B\[[\d;]*m/gi,""))),a="5.0.0-alpha.11",s="[iFrameSizer]",c=s.length,d=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),l=(e,n,t,i)=>e.addEventListener(n,t,i||!1),f=(e,n,t)=>e.removeEventListener(n,t,!1),u=e=>!Number.isNaN(e),m=e=>{if(!e)return"";let n=-559038744,t=1103547984;for(let i,o=0;o<e.length;o++)i=e.codePointAt(o),n=Math.imul(n^i,2246822519),t=Math.imul(t^i,3266489917);return n^=Math.imul(n^t>>>15,1935289751),t^=Math.imul(t^n>>>15,3405138345),n^=t>>>16,t^=n>>>16,(2097152*(t>>>0)+(n>>>11)).toString(36)},h={},g=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:"vertical",inPageLinks:!1,enablePublicMethods:!0,heightCalculationMethod:"auto",id:"iFrameResizer",log:!0,license:void 0,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,mouseEvents:!0,offsetHeight:0,offsetWidth:0,postMessageTarget:null,sameDomain:!1,scrolling:!1,sizeHeight:!0,sizeWidth:!1,warningTimeout:5e3,tolerance:0,widthCalculationMethod:"auto",onClose:()=>!0,onClosed(){},onInit:!1,onMessage:null,onMouseEnter(){},onMouseLeave(){},onReady:e=>{"function"==typeof h[e.id].onInit&&(r(e.id,"\n[31;1mDeprecated Option[m\n\nThe [1monInit()[m function is deprecated and has been replaced with [1monReady()[m. It will be removed in a future version of iFrame Resizer.\n "),h[e.id].onInit(e))},onResized(){},onScroll:()=>!0}),p={position:null,version:a};function w(e){function n(){r("Height"),r("Width"),M(D),T(),C("onResized",D)}function t(e){if("border-box"!==e.boxSizing)return 0;return(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}function i(e){if("border-box"!==e.boxSizing)return 0;return(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}function r(e){const n=Number(h[B][`max${e}`]),t=Number(h[B][`min${e}`]),i=e.toLowerCase();let o=D[i];o<t&&(o=t),o>n&&(o=n),D[i]=o}function a(e){return L.slice(L.indexOf(":")+7+e)}const d=(e,n)=>(t,i)=>{const o={};var r,a;r=function(){x(`Send ${e} (${t})`,`${e}:${n()}`,i)},o[a=i]||(r(),o[a]=requestAnimationFrame((()=>{o[a]=null})))},u=(e,n)=>()=>{const t=n=>()=>{h[r]?e(n,r):o()};function i(e,n){n(window,"scroll",t("scroll")),n(window,"resize",t("resize window"))}function o(){i(0,f),a.disconnect()}const r=B,a=new ResizeObserver(t("iframe observed"));i(0,l),a.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),h[r]&&(h[r][`stop${n}`]=o)},m=e=>()=>{e in h[B]&&(h[B][e](),delete h[B][e])},g=d("pageInfo",(function(){const e=document.body.getBoundingClientRect(),n=D.iframe.getBoundingClientRect(),{scrollY:t,scrollX:i,innerHeight:o,innerWidth:r}=window,{clientHeight:a,clientWidth:s}=document.documentElement;return JSON.stringify({iframeHeight:n.height,iframeWidth:n.width,clientHeight:Math.max(a,o||0),clientWidth:Math.max(s,r||0),offsetTop:parseInt(n.top-e.top,10),offsetLeft:parseInt(n.left-e.left,10),scrollTop:t,scrollLeft:i,documentHeight:a,documentWidth:s,windowHeight:o,windowWidth:r})})),w=d("parentInfo",(function(){const{iframe:e}=D,{scrollWidth:n,scrollHeight:t}=document.documentElement,{width:i,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:c,scale:d}=window.visualViewport;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:n,scrollHeight:t},viewport:{width:i,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:c,scale:d}})})),y=u(g,"PageInfo"),k=u(w,"ParentInfo"),W=m("stopPageInfo"),N=m("stopParentInfo");function H(e){const n=e.getBoundingClientRect();return v(),{x:Math.floor(Number(n.left)+Number(p.position.x)),y:Math.floor(Number(n.top)+Number(p.position.y))}}function F(e){const n=e?H(D.iframe):{x:0,y:0};let t=((e,n)=>({x:e.width+n.x,y:e.height+n.y}))(D,n);window.top===window.self?(p.position=t,O()):window.parentIFrame?window.parentIFrame["scrollTo"+(e?"Offset":"")](t.x,t.y):o(B,"Unable to scroll to requested position, window.parentIFrame not found")}function O(){!1!==C("onScroll",p.position)?T():$()}function S(e){let n={};if(0===D.width&&0===D.height){const e=a(9).split(":");n={x:e[1],y:e[0]}}else n={x:D.width,y:D.height};C(e,{iframe:D.iframe,screenX:Number(n.x),screenY:Number(n.y),type:D.type})}const C=(e,n)=>b(B,e,n);let L=e.data,D={},B=null;"[iFrameResizerChild]Ready"!==L?s===`${L}`.slice(0,c)&&L.slice(c).split(":")[0]in h&&(D=function(){const e=L.slice(c).split(":"),n=e[1]?Number(e[1]):0,o=h[e[0]]?.iframe,r=getComputedStyle(o);return{iframe:o,id:e[0],height:n+t(r)+i(r),width:Number(e[2]),type:e[3]}}(),B=D.id,B?(function(e){if(!h[e])throw new Error(`${D.type} No settings for ${e}. Message was: ${L}`)}(B),D.type in{true:1,false:1,undefined:1}||(h[B].loaded=!0,function(){let e=!0;return null===D.iframe&&(o(B,`The iframe (${D.id}) was not found.`),e=!1),e}()&&function(){const{origin:n,sameDomain:t}=e;if(t)return!0;let i=h[B]?.checkOrigin;if(i&&"null"!=`${n}`&&!(i.constructor===Array?function(){let e=0,t=!1;for(;e<i.length;e++)if(i[e]===n){t=!0;break}return t}():function(){const e=h[B]?.remoteHost;return n===e}()))throw new Error(`Unexpected message received from: ${n} for ${D.iframe.id}. Message was: ${e.data}. This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.`);return!0}()&&function(){switch(h[B]?.firstRun&&h[B]&&(h[B].firstRun=!1),D.type){case"close":z(D.iframe);break;case"message":e=a(6),C("onMessage",{iframe:D.iframe,message:JSON.parse(e)});break;case"mouseenter":S("onMouseEnter");break;case"mouseleave":S("onMouseLeave");break;case"autoResize":h[B].autoResize=JSON.parse(a(9));break;case"scrollTo":F(!1);break;case"scrollToOffset":F(!0);break;case"pageInfo":g("start",B),y();break;case"parentInfo":w("start",B),k();break;case"pageInfoStop":W();break;case"parentInfoStop":N();break;case"inPageLink":!function(e){const n=e.split("#")[1]||"",t=decodeURIComponent(n);let i=document.getElementById(t)||document.getElementsByName(t)[0];i?function(){const e=H(i);p.position={x:e.x,y:e.y},O()}():window.top!==window.self&&window.parentIFrame&&window.parentIFrame.moveToAnchor(n)}(a(9));break;case"reset":R(D);break;case"init":n(),function(e){try{h[e].sameDomain=!!h[e]?.iframe?.contentWindow?.iframeChildListener}catch(n){h[e].sameDomain=!1}}(B),E=!0,C("onReady",D.iframe);break;default:if(0===D.width&&0===D.height)return void o(`Unsupported message received (${D.type}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===D.width||0===D.height)return;if(document.hidden)return;n()}var e}())):o("iframeResizer received messageData without id, message was: ",L)):Object.keys(h).forEach((e=>x("iFrame requested init",I(e),e)))}function b(e,n,t){let i=null,o=null;if(h[e]){if(i=h[e][n],"function"!=typeof i)throw new TypeError(`${n} on iFrame[${e}] is not a function`);o=i(t)}return o}function y(e){const n=e.id;delete h[n]}function z(e){const n=e.id;if(!1!==b(n,"onClose",n)){try{e.parentNode&&e.remove()}catch(e){o(e)}b(n,"onClosed",n),y(e)}}function v(e){null===p.position&&(p.position={x:window.scrollX,y:window.scrollY})}function $(){p.position=null}function T(e){null!==p.position&&(window.scrollTo(p.position.x,p.position.y),$())}function R(e){v(e.id),M(e),x("reset","reset",e.id)}function M(e){const n=e.id;function t(n){const t=`${e[n]}px`;e.iframe.style[n]=t}h[n].sizeHeight&&t("height"),h[n].sizeWidth&&t("width")}function x(e,n,t,a){h[t]&&(h[t]?.postMessageTarget?function(){const{postMessageTarget:e,targetOrigin:o}=h[t];if(h[t].sameDomain)try{return void h[t].iframe.contentWindow.iframeChildListener(s+n)}catch(e){i(t,"Same domain connection failed. Trying cross domain"),h[t].sameDomain=!1}e.postMessage(s+n,o)}():o(t,`[${e}] IFrame(${t}) not found`),a&&h[t]?.warningTimeout&&(h[t].msgTimeout=setTimeout((function(){void 0!==h[t]&&(h[t].loaded||h[t].loadErrorShown||(h[t].loadErrorShown=!0,r(t,`\n[31;1mNo response from iFrame[m\n \nThe iframe ([3m${t}[m) has not responded within ${h[t].warningTimeout/1e3} seconds. Check [1m@iframe-resizer/child[m package has been loaded in the iframe.\n\nThis message can be ignored if everything is working, or you can set the [1mwarningTimeout[m option to a higher value or zero to suppress this warning.\n`)))}),h[t].warningTimeout)))}function I(e){const n=h[e];return[e,"8",n.sizeWidth,n.log,"32",n.enablePublicMethods,n.autoResize,n.bodyMargin,n.heightCalculationMethod,n.bodyBackground,n.bodyPadding,n.tolerance,n.inPageLinks,"child",n.widthCalculationMethod,n.mouseEvents,n.offsetHeight,n.offsetWidth,n.sizeHeight,m(n.license),p.version].join(":")}let k=0,E=!1;const W=e=>n=>{function t(e){if(!e)return{};if("object"!=typeof e)throw new TypeError("Options is not an object");return("sizeWidth"in e||"sizeHeight"in e||"autoResize"in e)&&r(s,'\n[31;1mDeprecated Optionm\n\nThe [1msizeWidth[m, [1msizeHeight[m and [1mautoResize[m options have been replaced with new [1mdirection[m option which expects values of [3m"vertical"[m, [3m"horizontal"[m or [3m"horizontal"[m.\n'),e}const s=function(t){if(t&&"string"!=typeof t)throw new TypeError("Invaild id for iFrame. Expected String");return""!==t&&t||(n.id=t=function(){let n=e?.id||g.id+k++;return null!==document.getElementById(n)&&(n+=k++),n}(),(e||{}).log),t}(n.id);return s in h&&"iFrameResizer"in n?o(s,"Ignored iFrame, already setup."):(i(`v${a}`),r(n.id,"[31;1mAlpha Release[m\n \nDo not use in production, API is not stable."),function(e){var i;h[s]={iframe:n,firstRun:!0,remoteHost:n?.src.split("/").slice(0,3).join("/"),...g,...t(e)},function(){if("horizontal"===h[s].direction)return h[s].sizeWidth=!0,void(h[s].sizeHeight=!1);if("none"===h[s].direction)return h[s].sizeWidth=!1,h[s].sizeHeight=!1,void(h[s].autoResize=!1);if("vertical"!==h[s].direction)throw new TypeError(s,`Direction value of "${h[s].direction}" is not valid`)}(),null===h[s].postMessageTarget&&(h[s].postMessageTarget=n.contentWindow),h[s].targetOrigin=!0===h[s].checkOrigin?""===(i=h[s].remoteHost)||null!==i.match(/^(about:blank|javascript:|file:\/\/)/)?"*":i:"*"}(e),H(),function(){switch(n.style.overflow=!1===h[s]?.scrolling?"hidden":"auto",h[s]?.scrolling){case"omit":break;case!0:n.scrolling="yes";break;case!1:n.scrolling="no";break;default:n.scrolling=h[s]?h[s].scrolling:"no"}}(),function(){function e(e){const t=h[s][e];1/0!==t&&0!==t&&(n.style[e]=u(t)?`${t}px`:t)}function t(e){if(u(`min${e}`)&&u(`max${e}`)&&h[s][`min${e}`]>h[s][`max${e}`])throw new Error(`Value for min${e} can not be greater than max${e}`)}t("Height"),t("Width"),e("maxHeight"),e("minHeight"),e("maxWidth"),e("minWidth")}(),function(){const{bodyMargin:e}=h[s];"number"!=typeof e&&"0"!==e||(h[s].bodyMargin=`${e}px`)}(),function(e){const{id:t}=n;l(n,"load",(function(){x("iFrame.onload",`${e}:${E}`,t,!0),function(){const e=h[s]?.firstRun,t=h[s]?.heightCalculationMethod in d;!e&&t&&R({iframe:n,height:0,width:0,type:"init"})}()})),x("init",`${e}:${E}`,t,!0)}(I(s)),function(){if(h[s]){const e={close:z.bind(null,h[s].iframe),disconnect:y.bind(null,h[s].iframe),removeListeners(){r(s,"\n[31;1mDeprecated Method Namem\n\nThe [removeListeners()[m method has been renamed to [disconnect()[m.\n"),this.disconnect()},resize:x.bind(null,"Window resize","resize",s),moveToAnchor(e){x("Move to anchor",`moveToAnchor:${e}`,s)},sendMessage(e){x("Send Message",`message:${e=JSON.stringify(e)}`,s)}};h[s].iframe.iframeResizer=e,h[s].iframe.iFrameResizer=e}}()),n?.iFrameResizer};function N(){!1===document.hidden&&function(e,n){const t=e=>h[e]?.autoResize&&!h[e]?.firstRun;Object.keys(h).forEach((function(i){t(i)&&x(e,n,i)}))}("Tab Visible","resize")}const H=(e=>{let n=!1;return function(){return n?void 0:(n=!0,Reflect.apply(e,this,arguments))}})((()=>{l(window,"message",w),l(document,"visibilitychange",N),window.iframeParentListener=e=>w({data:e,sameDomain:!0})})),F="[iframeResizer] ";const O=function(){function e(e){switch(!0){case!e:throw new TypeError(`${F}iframe is not defined`);case!e.tagName:throw new TypeError(`${F}Not a valid DOM element`);case"IFRAME"!==e.tagName.toUpperCase():throw new TypeError(`${F}Expected <IFRAME> tag, found <${e.tagName}>`);default:n(e),t.push(e)}}let n,t;return function(i,o){if("undefined"==typeof window)return[];switch(n=W(i),t=[],typeof o){case"undefined":case"string":document.querySelectorAll(o||"iframe").forEach(e);break;case"object":e(o);break;default:throw new TypeError(`${F}Unexpected data type (${typeof o})`)}return Object.freeze(t)}}();return"undefined"!=typeof window&&(window.iFrameResize=function(...e){r("","Deprecated: iFrameResize(), please use iframeResize()"),O(...e)}),O})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).iframeResize=n()}(this,(function(){"use strict";const e="[iframeResizer]";const n=n=>`${e}[${function(e){return window.top===window.self?`Host page: ${e}`:window?.parentIFrame?.getId?`${window.parentIFrame.getId()}: ${e}`:`Nested host page: ${e}`}(n)}]`,t=(e,t,...i)=>window?.console[e](n(t),...i),i=(e,...n)=>t("info",e,...n),o=(e,...n)=>t("warn",e,...n),r=(n,t)=>window?.console.warn(((n,...t)=>[`${e}[${n}]`,...t])(n,window.chrome?t:t.replaceAll(/\u001B\[[\d;]*m/gi,""))),a="5.0.0-alpha.12",s="[iFrameSizer]",c=s.length,d=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),l=(e,n,t,i)=>e.addEventListener(n,t,i||!1),f=(e,n,t)=>e.removeEventListener(n,t,!1),u=e=>!Number.isNaN(e),m=e=>{if(!e)return"";let n=-559038744,t=1103547984;for(let i,o=0;o<e.length;o++)i=e.codePointAt(o),n=Math.imul(n^i,2246822519),t=Math.imul(t^i,3266489917);return n^=Math.imul(n^t>>>15,1935289751),t^=Math.imul(t^n>>>15,3405138345),n^=t>>>16,t^=n>>>16,(2097152*(t>>>0)+(n>>>11)).toString(36)},h={},g=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:"vertical",inPageLinks:!1,enablePublicMethods:!0,heightCalculationMethod:"auto",id:"iFrameResizer",log:!0,license:void 0,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,mouseEvents:!0,offsetHeight:0,offsetWidth:0,postMessageTarget:null,sameDomain:!1,scrolling:!1,sizeHeight:!0,sizeWidth:!1,warningTimeout:5e3,tolerance:0,widthCalculationMethod:"auto",onClose:()=>!0,onClosed(){},onInit:!1,onMessage:null,onMouseEnter(){},onMouseLeave(){},onReady:e=>{"function"==typeof h[e.id].onInit&&(r(e.id,"\n[31;1mDeprecated Option[m\n\nThe [1monInit()[m function is deprecated and has been replaced with [1monReady()[m. It will be removed in a future version of iFrame Resizer.\n "),h[e.id].onInit(e))},onResized(){},onScroll:()=>!0}),p={position:null,version:a};function w(e){function n(){r("Height"),r("Width"),M(D),T(),C("onResized",D)}function t(e){if("border-box"!==e.boxSizing)return 0;return(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}function i(e){if("border-box"!==e.boxSizing)return 0;return(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}function r(e){const n=Number(h[B][`max${e}`]),t=Number(h[B][`min${e}`]),i=e.toLowerCase();let o=D[i];o<t&&(o=t),o>n&&(o=n),D[i]=o}function a(e){return L.slice(L.indexOf(":")+7+e)}const d=(e,n)=>(t,i)=>{const o={};var r,a;r=function(){x(`Send ${e} (${t})`,`${e}:${n()}`,i)},o[a=i]||(r(),o[a]=requestAnimationFrame((()=>{o[a]=null})))},u=(e,n)=>()=>{const t=n=>()=>{h[r]?e(n,r):o()};function i(e,n){n(window,"scroll",t("scroll")),n(window,"resize",t("resize window"))}function o(){i(0,f),a.disconnect()}const r=B,a=new ResizeObserver(t("iframe observed"));i(0,l),a.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),h[r]&&(h[r][`stop${n}`]=o)},m=e=>()=>{e in h[B]&&(h[B][e](),delete h[B][e])},g=d("pageInfo",(function(){const e=document.body.getBoundingClientRect(),n=D.iframe.getBoundingClientRect(),{scrollY:t,scrollX:i,innerHeight:o,innerWidth:r}=window,{clientHeight:a,clientWidth:s}=document.documentElement;return JSON.stringify({iframeHeight:n.height,iframeWidth:n.width,clientHeight:Math.max(a,o||0),clientWidth:Math.max(s,r||0),offsetTop:parseInt(n.top-e.top,10),offsetLeft:parseInt(n.left-e.left,10),scrollTop:t,scrollLeft:i,documentHeight:a,documentWidth:s,windowHeight:o,windowWidth:r})})),w=d("parentInfo",(function(){const{iframe:e}=D,{scrollWidth:n,scrollHeight:t}=document.documentElement,{width:i,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:c,scale:d}=window.visualViewport;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:n,scrollHeight:t},viewport:{width:i,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:c,scale:d}})})),y=u(g,"PageInfo"),k=u(w,"ParentInfo"),W=m("stopPageInfo"),N=m("stopParentInfo");function H(e){const n=e.getBoundingClientRect();return v(),{x:Math.floor(Number(n.left)+Number(p.position.x)),y:Math.floor(Number(n.top)+Number(p.position.y))}}function F(e){const n=e?H(D.iframe):{x:0,y:0};let t=((e,n)=>({x:e.width+n.x,y:e.height+n.y}))(D,n);window.top===window.self?(p.position=t,O()):window.parentIFrame?window.parentIFrame["scrollTo"+(e?"Offset":"")](t.x,t.y):o(B,"Unable to scroll to requested position, window.parentIFrame not found")}function O(){!1!==C("onScroll",p.position)?T():$()}function S(e){let n={};if(0===D.width&&0===D.height){const e=a(9).split(":");n={x:e[1],y:e[0]}}else n={x:D.width,y:D.height};C(e,{iframe:D.iframe,screenX:Number(n.x),screenY:Number(n.y),type:D.type})}const C=(e,n)=>b(B,e,n);let L=e.data,D={},B=null;"[iFrameResizerChild]Ready"!==L?s===`${L}`.slice(0,c)&&L.slice(c).split(":")[0]in h&&(D=function(){const e=L.slice(c).split(":"),n=e[1]?Number(e[1]):0,o=h[e[0]]?.iframe,r=getComputedStyle(o);return{iframe:o,id:e[0],height:n+t(r)+i(r),width:Number(e[2]),type:e[3]}}(),B=D.id,B?(function(e){if(!h[e])throw new Error(`${D.type} No settings for ${e}. Message was: ${L}`)}(B),D.type in{true:1,false:1,undefined:1}||(h[B].loaded=!0,function(){let e=!0;return null===D.iframe&&(o(B,`The iframe (${D.id}) was not found.`),e=!1),e}()&&function(){const{origin:n,sameDomain:t}=e;if(t)return!0;let i=h[B]?.checkOrigin;if(i&&"null"!=`${n}`&&!(i.constructor===Array?function(){let e=0,t=!1;for(;e<i.length;e++)if(i[e]===n){t=!0;break}return t}():function(){const e=h[B]?.remoteHost;return n===e}()))throw new Error(`Unexpected message received from: ${n} for ${D.iframe.id}. Message was: ${e.data}. This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.`);return!0}()&&function(){switch(h[B]?.firstRun&&h[B]&&(h[B].firstRun=!1),D.type){case"close":z(D.iframe);break;case"message":e=a(6),C("onMessage",{iframe:D.iframe,message:JSON.parse(e)});break;case"mouseenter":S("onMouseEnter");break;case"mouseleave":S("onMouseLeave");break;case"autoResize":h[B].autoResize=JSON.parse(a(9));break;case"scrollTo":F(!1);break;case"scrollToOffset":F(!0);break;case"pageInfo":g("start",B),y();break;case"parentInfo":w("start",B),k();break;case"pageInfoStop":W();break;case"parentInfoStop":N();break;case"inPageLink":!function(e){const n=e.split("#")[1]||"",t=decodeURIComponent(n);let i=document.getElementById(t)||document.getElementsByName(t)[0];i?function(){const e=H(i);p.position={x:e.x,y:e.y},O()}():window.top!==window.self&&window.parentIFrame&&window.parentIFrame.moveToAnchor(n)}(a(9));break;case"reset":R(D);break;case"init":n(),function(e){try{h[e].sameDomain=!!h[e]?.iframe?.contentWindow?.iframeChildListener}catch(n){h[e].sameDomain=!1}}(B),E=!0,C("onReady",D.iframe);break;default:if(0===D.width&&0===D.height)return void o(`Unsupported message received (${D.type}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===D.width||0===D.height)return;if(document.hidden)return;n()}var e}())):o("iframeResizer received messageData without id, message was: ",L)):Object.keys(h).forEach((e=>x("iFrame requested init",I(e),e)))}function b(e,n,t){let i=null,o=null;if(h[e]){if(i=h[e][n],"function"!=typeof i)throw new TypeError(`${n} on iFrame[${e}] is not a function`);o=i(t)}return o}function y(e){const n=e.id;delete h[n]}function z(e){const n=e.id;if(!1!==b(n,"onClose",n)){try{e.parentNode&&e.remove()}catch(e){o(e)}b(n,"onClosed",n),y(e)}}function v(e){null===p.position&&(p.position={x:window.scrollX,y:window.scrollY})}function $(){p.position=null}function T(e){null!==p.position&&(window.scrollTo(p.position.x,p.position.y),$())}function R(e){v(e.id),M(e),x("reset","reset",e.id)}function M(e){const n=e.id;function t(n){const t=`${e[n]}px`;e.iframe.style[n]=t}h[n].sizeHeight&&t("height"),h[n].sizeWidth&&t("width")}function x(e,n,t,a){h[t]&&(h[t]?.postMessageTarget?function(){const{postMessageTarget:e,targetOrigin:o}=h[t];if(h[t].sameDomain)try{return void h[t].iframe.contentWindow.iframeChildListener(s+n)}catch(e){i(t,"Same domain connection failed. Trying cross domain"),h[t].sameDomain=!1}e.postMessage(s+n,o)}():o(t,`[${e}] IFrame(${t}) not found`),a&&h[t]?.warningTimeout&&(h[t].msgTimeout=setTimeout((function(){void 0!==h[t]&&(h[t].loaded||h[t].loadErrorShown||(h[t].loadErrorShown=!0,r(t,`\n[31;1mNo response from iFrame[m\n \nThe iframe ([3m${t}[m) has not responded within ${h[t].warningTimeout/1e3} seconds. Check [1m@iframe-resizer/child[m package has been loaded in the iframe.\n\nThis message can be ignored if everything is working, or you can set the [1mwarningTimeout[m option to a higher value or zero to suppress this warning.\n`)))}),h[t].warningTimeout)))}function I(e){const n=h[e];return[e,"8",n.sizeWidth,n.log,"32",n.enablePublicMethods,n.autoResize,n.bodyMargin,n.heightCalculationMethod,n.bodyBackground,n.bodyPadding,n.tolerance,n.inPageLinks,"child",n.widthCalculationMethod,n.mouseEvents,n.offsetHeight,n.offsetWidth,n.sizeHeight,m(n.license),p.version].join(":")}let k=0,E=!1;const W=e=>n=>{function t(e){if(!e)return{};if("object"!=typeof e)throw new TypeError("Options is not an object");return("sizeWidth"in e||"sizeHeight"in e||"autoResize"in e)&&r(s,'\n[31;1mDeprecated Optionm\n\nThe [1msizeWidth[m, [1msizeHeight[m and [1mautoResize[m options have been replaced with new [1mdirection[m option which expects values of [3m"vertical"[m, [3m"horizontal"[m or [3m"horizontal"[m.\n'),e}const s=function(t){if(t&&"string"!=typeof t)throw new TypeError("Invaild id for iFrame. Expected String");return""!==t&&t||(n.id=t=function(){let n=e?.id||g.id+k++;return null!==document.getElementById(n)&&(n+=k++),n}(),(e||{}).log),t}(n.id);return s in h&&"iFrameResizer"in n?o(s,"Ignored iFrame, already setup."):(i(`v${a}`),r(n.id,"[31;1mAlpha Release[m\n \nDo not use in production, API is not stable."),function(e){var i;h[s]={iframe:n,firstRun:!0,remoteHost:n?.src.split("/").slice(0,3).join("/"),...g,...t(e)},function(){if("horizontal"===h[s].direction)return h[s].sizeWidth=!0,void(h[s].sizeHeight=!1);if("none"===h[s].direction)return h[s].sizeWidth=!1,h[s].sizeHeight=!1,void(h[s].autoResize=!1);if("vertical"!==h[s].direction)throw new TypeError(s,`Direction value of "${h[s].direction}" is not valid`)}(),null===h[s].postMessageTarget&&(h[s].postMessageTarget=n.contentWindow),h[s].targetOrigin=!0===h[s].checkOrigin?""===(i=h[s].remoteHost)||null!==i.match(/^(about:blank|javascript:|file:\/\/)/)?"*":i:"*"}(e),H(),function(){switch(n.style.overflow=!1===h[s]?.scrolling?"hidden":"auto",h[s]?.scrolling){case"omit":break;case!0:n.scrolling="yes";break;case!1:n.scrolling="no";break;default:n.scrolling=h[s]?h[s].scrolling:"no"}}(),function(){function e(e){const t=h[s][e];1/0!==t&&0!==t&&(n.style[e]=u(t)?`${t}px`:t)}function t(e){if(u(`min${e}`)&&u(`max${e}`)&&h[s][`min${e}`]>h[s][`max${e}`])throw new Error(`Value for min${e} can not be greater than max${e}`)}t("Height"),t("Width"),e("maxHeight"),e("minHeight"),e("maxWidth"),e("minWidth")}(),function(){const{bodyMargin:e}=h[s];"number"!=typeof e&&"0"!==e||(h[s].bodyMargin=`${e}px`)}(),function(e){const{id:t}=n;l(n,"load",(function(){x("iFrame.onload",`${e}:${E}`,t,!0),function(){const e=h[s]?.firstRun,t=h[s]?.heightCalculationMethod in d;!e&&t&&R({iframe:n,height:0,width:0,type:"init"})}()})),x("init",`${e}:${E}`,t,!0)}(I(s)),function(){if(h[s]){const e={close:z.bind(null,h[s].iframe),disconnect:y.bind(null,h[s].iframe),removeListeners(){r(s,"\n[31;1mDeprecated Method Namem\n\nThe [removeListeners()[m method has been renamed to [disconnect()[m.\n"),this.disconnect()},resize:x.bind(null,"Window resize","resize",s),moveToAnchor(e){x("Move to anchor",`moveToAnchor:${e}`,s)},sendMessage(e){x("Send Message",`message:${e=JSON.stringify(e)}`,s)}};h[s].iframe.iframeResizer=e,h[s].iframe.iFrameResizer=e}}()),n?.iFrameResizer};function N(){!1===document.hidden&&function(e,n){const t=e=>h[e]?.autoResize&&!h[e]?.firstRun;Object.keys(h).forEach((function(i){t(i)&&x(e,n,i)}))}("Tab Visible","resize")}const H=(e=>{let n=!1;return function(){return n?void 0:(n=!0,Reflect.apply(e,this,arguments))}})((()=>{l(window,"message",w),l(document,"visibilitychange",N),window.iframeParentListener=e=>w({data:e,sameDomain:!0})})),F="[iframeResizer] ";const O=function(){function e(e){switch(!0){case!e:throw new TypeError(`${F}iframe is not defined`);case!e.tagName:throw new TypeError(`${F}Not a valid DOM element`);case"IFRAME"!==e.tagName.toUpperCase():throw new TypeError(`${F}Expected <IFRAME> tag, found <${e.tagName}>`);default:n(e),t.push(e)}}let n,t;return function(i,o){if("undefined"==typeof window)return[];switch(n=W(i),t=[],typeof o){case"undefined":case"string":document.querySelectorAll(o||"iframe").forEach(e);break;case"object":e(o);break;default:throw new TypeError(`${F}Unexpected data type (${typeof o})`)}return Object.freeze(t)}}();return"undefined"!=typeof window&&(window.iFrameResize=function(...e){r("","Deprecated: iFrameResize(), please use iframeResize()"),O(...e)}),O})); |
{ | ||
"name": "@iframe-resizer/parent", | ||
"version": "5.0.0-alpha.11", | ||
"version": "5.0.0-alpha.12", | ||
"license": "GPL-3.0", | ||
@@ -45,4 +45,4 @@ "homepage": "http://iframe-resizer.com", | ||
"dependencies": { | ||
"@iframe-resizer/core": "5.0.0-alpha.11" | ||
"@iframe-resizer/core": "5.0.0-alpha.12" | ||
} | ||
} |
@@ -5,6 +5,4 @@ <img src="https://iframe-resizer.com/logo-full.png" alt="" title="" /> | ||
> _Keep same and cross domain iframes sized to their content_ | ||
This package is an alpha release of version 5 of _iframe-resizer_, for the production version see the [iframe-resizer](https://www.npmjs.com/package/iframe-resizer) package. | ||
This package is an alpha release of version 5 of _iframe-resizer_ for the production version see the [iframe-resizer](https://www.npmjs.com/package/iframe-resizer) package. | ||
This version has an unstable API and should not be used on production sites. | ||
@@ -16,2 +14,2 @@ | ||
_iframe-resizer version 5.0.0-alpha.11 2024-04-26 - 12:19:19.804Z_ | ||
_iframe-resizer version 5.0.0-alpha.12 2024-04-26 - 15:47:40.987Z_ |
59034
14