UNPKG

@iframe-resizer/child

Version:

Keep iframes sized to their content.

21 lines (18 loc) 26.1 kB
/*! * @preserve * * @module iframe-resizer/child 5.5.1 (cjs) - 2025-08-01 * * @license GPL-3.0 for non-commercial use only. * For commercial use, you must purchase a license from * https://iframe-resizer.com/pricing * * @description Keep same and cross domain iFrames sized to their content * * @author David J. Bradshaw <info@iframe-resizer.com> * * @see {@link https://iframe-resizer.com} * * @copyright (c) 2013 - 2025, David J. Bradshaw. All rights reserved. */ "use strict";const e=require("auto-console-group"),t="5.5.1",n="iframeResizer",o=10,r="data-iframe-size",i="data-iframe-overflowed",a="data-iframe-ignore",s="bottom",l="right",c="autoResizeEnabled",u=Symbol("sizeChanged"),d="manualResize",f={},m="setOffsetSize",p="resizeObserver",h="overflowObserver",y="mutationObserver",g="visibilityObserver",b="none",v="init",z=(e,t,n,o)=>e.addEventListener(t,n,o||!1),w=e=>{if(!e)return"";let t=-559038744,n=1103547984;for(let o,r=0;r<e.length;r++)o=e.codePointAt(r),t=Math.imul(t^o,2246822519),n=Math.imul(n^o,3266489917);return t^=Math.imul(t^n>>>15,1935289751),n^=Math.imul(n^t>>>15,3405138345),t^=n>>>16,n^=t>>>16,(2097152*(n>>>0)+(t>>>11)).toString(36)},$=e=>e.replace(/[A-Za-z]/g,e=>String.fromCodePoint((e<="Z"?90:122)>=(e=e.codePointAt(0)+19)?e:e-26)),O=["spjluzl","rlf","clyzpvu"],S=["<yi>Puchspk Spjluzl Rlf</><iy><iy>","<yi>Tpzzpun Spjluzl Rlf</><iy><iy>","Aopz spiyhyf pz hchpshisl dpao ivao Jvttlyjphs huk Vwlu-Zvbyjl spjluzlz.<iy><iy><i>Jvttlyjphs Spjluzl</><iy>Mvy jvttlyjphs bzl, <p>pmyhtl-ylzpgly</> ylxbpylz h svd jvza vul aptl spjluzl mll. Mvy tvyl pumvythapvu cpzpa <b>oaawz://pmyhtl-ylzpgly.jvt/wypjpun</>.<iy><iy><i>Vwlu Zvbyjl Spjluzl</><iy>Pm fvb hyl bzpun aopz spiyhyf pu h uvu-jvttlyjphs vwlu zvbyjl wyvqlja aolu fvb jhu bzl pa mvy myll bukly aol alytz vm aol NWS C3 Spjluzl. Av jvumpyt fvb hjjlwa aolzl alytz, wslhzl zla aol <i>spjluzl</> rlf pu <p>pmyhtl-ylzpgly</> vwapvuz av <i>NWSc3</>.<iy><iy>Mvy tvyl pumvythapvu wslhzl zll: <b>oaawz://pmyhtl-ylzpgly.jvt/nws</>","<i>NWSc3 Spjluzl Clyzpvu</><iy><iy>Aopz clyzpvu vm <p>pmyhtl-ylzpgly</> pz ilpun bzlk bukly aol alytz vm aol <i>NWS C3</> spjluzl. Aopz spjluzl hssvdz fvb av bzl <p>pmyhtl-ylzpgly</> pu Vwlu Zvbyjl wyvqljaz, iba pa ylxbpylz fvby wyvqlja av il wbispj, wyvcpkl haaypibapvu huk il spjluzlk bukly clyzpvu 3 vy shaly vm aol NUB Nlulyhs Wbispj Spjluzl.<iy><iy>Pm fvb hyl bzpun aopz spiyhyf pu h uvu-vwlu zvbyjl wyvqlja vy dlizpal, fvb dpss ullk av wbyjohzl h svd jvza vul aptl jvttlyjphs spjluzl.<iy><iy>Mvy tvyl pumvythapvu cpzpa <b>oaawz://pmyhtl-ylzpgly.jvt/wypjpun</>.","<iy><yi>Zvsv spjluzl kvlz uva zbwwvya jyvzz-kvthpu</><iy><iy>Av bzl <p>pmyhtl-ylzpgly</> dpao jyvzz kvthpu pmyhtlz fvb ullk lpaoly aol Wyvmlzzpvuhs vy Ibzpulzz spjluzlz. Mvy klahpsz vu bwnyhkl wypjpun wslhzl jvuahja pumv@pmyhtl-ylzpgly.jvt."],I=["NWSc3","zvsv","wyv","ibzpulzz","vlt"],M=Object.fromEntries(["2cgs7fdf4xb","1c9ctcccr4z","1q2pc4eebgb","ueokt0969w","w2zxchhgqz","1umuxblj2e5"].map((e,t)=>[e,Math.max(0,t-1)])),T=e=>$(S[e]),E=e=>{const t=e[$(O[0])]||e[$(O[1])]||e[$(O[2])];if(!t)return-1;const n=t.split("-");let o=function(e=""){let t=-2;const n=w($(e));return n in M&&(t=M[n]),t}(n[0]);return 0===o||(e=>e[2]===w(e[0]+e[1]))(n)||(o=-2),o},j=(e,...t)=>setTimeout(()=>e(...t),0),k=e=>{let t=!1;return function(){return t?void 0:(t=!0,Reflect.apply(e,this,arguments))}},A=e=>e,N=e=>Math.round(1e3*e)/1e3,x=e=>e.charAt(0).toUpperCase()+e.slice(1),R=e=>""!=`${e}`&&void 0!==e;const P=(e,t,n)=>{if(typeof e!==t)throw new TypeError(`${n} is not a ${x(t)}`)};let C=!0,H=n;var L;const B=(L=e,L?.__esModule?L.default:L)({label:`${n}(child)`});var G;const q=(G="log",(...e)=>!C||B[G](...e));const{assert:W,debug:D,endAutoGroup:F,error:U,errorBoundary:V,event:Z,label:J,purge:_,warn:Q}=B,Y=e=>{return B.warn((t=A,e=>window.chrome?t(e.replaceAll("<br>","\n").replaceAll("<rb>","").replaceAll("</>","").replaceAll("<b>","").replaceAll("<i>","").replaceAll("<u>","")):t(e.replaceAll("<br>","\n").replaceAll(/<[/a-z]+>/gi,"")))(e));var t},X=Y,K=(e=>(t,n="renamed to")=>(o,r,i="",a="")=>e(a,`<rb>Deprecated ${t}(${o.replace("()","")})</>\n\nThe <b>${o}</> ${t.toLowerCase()} has been ${n} <b>${r}</>. ${i}Use of the old ${t.toLowerCase()} will be removed in a future version of <i>iframe-resizer</>.`))((e,t)=>Y(t)),ee=K("Method"),te=K("Method","replaced with"),ne=K("Option"),oe=["min-height","min-width","max-height","max-width"],re=new Set,ie=(e,t)=>window.getComputedStyle(e).getPropertyValue(t),ae=(e,t)=>{return(n=ie(e,t))&&"0px"!==n&&"auto"!==n&&"none"!==n;var n};function se({href:e}){re.has(e)||re.add(e)}const le=(e,t)=>function(e,t){const n=e.style[t];return n?{source:"an inline style attribute",value:n}:null}(e,t)||function(e,t){for(const n of document.styleSheets)try{for(const o of n.cssRules||[])if(o.selectorText&&e.matches(o.selectorText)){const e=o.style[t];if(e)return{source:"STYLE"===n.ownerNode.tagName?"an inline <style> block":`stylesheet (${n.href})`,value:e}}}catch(e){se(n)}return{source:"cross-origin stylesheet",value:ie(e,t)}}(e,t),ce=(e,t)=>{const{source:n,value:o}=le(e,t),r=(e=>e.tagName?e.tagName.toLowerCase():"unknown")(e);Y(`The <b>${t}</> CSS property is set to <b>${o}</> on the <b><${r}></> element via ${n}. This may cause issues with the correct operation of <i>iframe-resizer</>.\n\nIf you wish to restrict the size of the iframe, then you should set this property on the iframe element itself, not the content inside it.`)};function ue(){for(const e of[document.documentElement,document.body])for(const t of oe)ae(e,t)&&ce(e,t)}const de=e=>t=>void 0===t?void 0:e(t),fe=de(e=>"true"===e),me=de(Number),pe=new Set,he=new Set,ye=[];let ge,be=1,ve=!1,ze=0;const we=e=>{for(const t of e){const{addedNodes:e,removedNodes:n}=t;for(const t of e)pe.add(t);for(const e of n)pe.has(e)?pe.delete(e):he.add(e)}};function $e(e){ye.push(e),ve||(ze=performance.now(),ve=!0,requestAnimationFrame(ge))}function Oe(t){const n=new window.MutationObserver($e),o=document.querySelector("body"),i={attributes:!0,attributeFilter:[a,r],attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0};return ge=(t=>()=>{const n=performance.now(),o=n-ze,r=16*be+++2;if(o>r&&o<200)return Z("MutationDelay"),q("Update delayed due to heavy workload on the callStack"),q(`EventLoop busy time: %c${N(o)}ms %c> Max wait: %c${r-2}ms`,e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT),setTimeout(ge,16*be),void(ze=n);be=1,ye.forEach(we),ye.length=0,t({addedMutations:pe,removedMutations:he}),ve=!1,pe.clear(),he.clear()})(t),n.observe(o,i),q("Attached MutationObserver to body"),n}const Se=(t,n=!0)=>o=>{o>0&&q(`${n?"At":"De"}tached ${t}Observer ${n?"to":"from"} %c${o}%c element${1===o?"":"s"}`,e.HIGHLIGHT,e.NORMAL)},Ie=(e,t,n)=>e=>{let o=0;for(const r of e)n.has(r)&&(t.unobserve(r),n.delete(r),o+=1);return o},Me=e=>e.hidden||null===e.offsetParent||"none"===e.style.display,Te=(e,t)=>{const n=t.side,o={root:t.root,rootMargin:"0px",threshold:1},r=window?.requestAnimationFrame||A,a=(t=!1)=>e(t),s=(e,t)=>0===e||e>t[n],l=(e,t)=>e.toggleAttribute(i,t);const c=new IntersectionObserver(function(e){for(const t of e){const{boundingClientRect:e,rootBounds:o,target:r}=t,i=e[n],a=s(i,o)&&!Me(r);l(r,a)}r(a)},o),u=new WeakSet;return{attachObservers:function(e){let t=0;for(const n of e){const e=n.nodeType===Node.ELEMENT_NODE,o=u.has(n);e&&(W(!o,"Node already observed for overflow",n),o||(c.observe(n),u.add(n),t+=1))}return t},detachObservers:Ie(0,c,u)}},Ee="--ifr-start",je="--ifr-end",ke=[],Ae=new WeakSet,Ne=e=>"object"==typeof e&&Ae.add(e);let xe={},Re=0;function Pe(e){e.getEntries().forEach(e=>{if(e.name===je){const{duration:t}=performance.measure("--ifr-measure",Ee,je);xe=e.detail,ke.push(t),ke.length>100&&ke.shift()}})}function Ce(){q("Attached PerformanceObserver to page");new PerformanceObserver(Pe).observe({entryTypes:["mark"]}),Ne(document.documentElement),Ne(document.body),function(){const e=setInterval(()=>{if(ke.length<10)return;if(xe.hasTags&&xe.len<25)return;ke.sort();const t=Math.min(ke.reduce((e,t)=>e+t,0)/ke.length,ke[Math.floor(ke.length/2)]),n=N(t);n>Re&&(Re=n,Z("performanceObserver")),t<=4||(clearInterval(e),Y(`<rb>Performance Warning</>\n\nCalculating the page size is taking an excessive amount of time (${N(t)}ms).\n\nTo improve performance add the <b>data-iframe-size</> attribute to the ${xe.Side.toLowerCase()} most element on the page. For more details see: <u>https://iframe-resizer.com/perf</>.`))},5e3)}()}const He=Se("Resize"),Le=new WeakSet;let Be;function Ge(e){let t=0;for(const n of e){const e=n.nodeType===Node.ELEMENT_NODE,o=Le.has(n);if(!e)continue;const r=getComputedStyle(n)?.position;""!==r&&"static"!==r&&(W(!o,"Node already observed for resize",n),o||(Be.observe(n),Le.add(n),t+=1))}He(t)}const qe=e=>(t,n)=>{if(n in t){if(typeof t[n]===e)return t[n];throw new TypeError(`${n} is not a ${e}.`)}},We=qe("function"),De=qe("number"),Fe=qe("string");"undefined"!=typeof window&&function(){const w={height:()=>(Q("Custom height calculation function not defined"),Ct.auto()),width:()=>(Q("Custom width calculation function not defined"),Ht.auto())},S={},M={},A="auto",N="[iFrameSizer]",L="scroll";let G,W,D,U,K,oe,re,ie,ae,se=!0,le="",ce=0,de="",pe="",he=!1,ye=!0,ge=!1,be=!0,ve=!1,ze=!1,we=!1,$e=1,Me=A,ke="",Ae=!0,Ne={},xe=!1,Re=!0,Pe=!1,He=0,qe=!1,Ue=[],Ve="",Ze="child",Je=!1,_e="",Qe=[],Ye=window.parent,Xe="*",Ke=0,et=!1,tt=1,nt=L,ot=window,rt=()=>{Q("onMessage function not defined")},it=()=>{},at=null,st=null;function lt(i){var a,u,f;!function(e){Ve=e[0]??Ve,ce=me(e[1])??ce,ge=fe(e[2])??ge,Pe=fe(e[3])??Pe,se=fe(e[6])??se,de=e[7]??de,Me=e[8]??Me,le=e[9]??le,pe=e[10]??pe,Ke=me(e[11])??Ke,Ne.enable=fe(e[12])??!1,Ze=e[13]??Ze,nt=e[14]??nt,qe=fe(e[15])??qe,D=me(e[16])??D,U=me(e[17])??U,ye=fe(e[18])??ye,G=e[19]??G,ie=e[20]??ie,He=me(e[21])??He,Re=fe(e[23])??Re}(i),H=(a={id:Ve,enabled:Pe,expand:Re}).id||n,B.label(`${H}`),B.expand(a.expand),C=a.enabled,function(){function t(e){ae=We(e,"onBeforeResize")??ae,rt=We(e,"onMessage")??rt,it=We(e,"onReady")??it,"number"==typeof e?.offset&&(ne("offset","offsetSize"),ye&&(D=De(e,"offset")??D),ge&&(U=De(e,"offset")??U)),"number"==typeof e?.offsetSize&&(ye&&(D=De(e,"offsetSize")??D),ge&&(U=De(e,"offsetSize")??U)),W=Fe(e,$(O[0]))??W,ke=Fe(e,"ignoreSelector")??ke,_e=Fe(e,"sizeSelector")??_e,Xe=Fe(e,"targetOrigin")??Xe,Me=e?.heightCalculationMethod||Me,nt=e?.widthCalculationMethod||nt}function n(e,t){return"function"==typeof e&&(Y(`<rb>Deprecated Option(${t}CalculationMethod)</>\n\nThe use of <b>${t}CalculationMethod</> as a function is deprecated and will be removed in a future version of <i>iframe-resizer</>. Please use the new <b>onBeforeResize</> event handler instead.\n\nSee <u>https://iframe-resizer.com/api/child</> for more details.`),w[t]=e,e="custom"),e}if(1===He)return;const o=window.iframeResizer||window.iFrameResizer;"object"==typeof o&&(t(o),Me=n(Me,"height"),nt=n(nt,"width"),q(`Set targetOrigin for parent: %c${Xe}`,e.HIGHLIGHT))}(),ht(),function(){try{Je=1===He||"iframeParentListener"in window.parent}catch(e){}}(),ge===ye&&(he=!0),function(){const n=He,o=E({key:G}),r=E({key:W});if(He=Math.max(o,r),He<0){if(He=Math.min(o,r),_(),Y(`${T(He+2)}${T(2)}`),R(ie))throw T(He+2).replace(/<\/?[a-z][^>]*>|<\/>/gi,"")}else(!R(ie)||n>-1&&He>n)&&(sessionStorage.getItem("ifr")!==t&&function(t,n){console.info(`${H} %ciframe-resizer ${t}`,C||n<1?"font-weight: bold;":e.NORMAL)}(`v${t} (${(e=>$(I[e]))(He)})`,He),He<2&&X(T(3)),sessionStorage.setItem("ifr",t))}(),ie&&""!==ie&&"false"!==ie?ie!==t&&Y(`<b>Version mismatch</>\n\nThe parent and child pages are running different versions of <i>iframe resizer</>.\n\nParent page: ${ie} - Child page: ${t}.\n`):Y("<rb>Legacy version detected on parent page</>\n\nDetected legacy version of parent page script. It is recommended to update the parent page to use <b>@iframe-resizer/parent</>.\n\nSee <u>https://iframe-resizer.com/setup/</> for more details.\n"),bt(),vt(),function(){let e=!1;const t=t=>document.querySelectorAll(`[${t}]`).forEach(n=>{e=!0,n.removeAttribute(t),n.toggleAttribute(r,!0)});t("data-iframe-height"),t("data-iframe-width"),e&&Y("<rb>Deprecated Attributes</>\n \nThe <b>data-iframe-height</> and <b>data-iframe-width</> attributes have been deprecated and replaced with the single <b>data-iframe-size</> attribute. Use of the old attributes will be removed in a future version of <i>iframe-resizer</>.")}(),"BackCompat"===document.compatMode&&Y("<rb>Quirks Mode Detected</>\n\nThis iframe is running in the browser's legacy <b>Quirks Mode</>, this may cause issues with the correct operation of <i>iframe-resizer</>. It is recommended that you switch to the modern <b>Standards Mode</>.\n\nFor more information see <u>https://iframe-resizer.com/quirks-mode</>.\n"),ut(),he||ue(),1!==He&&(ot.parentIframe=Object.freeze({autoResize:e=>(P(e,"boolean","parentIframe.autoResize(enable) enable"),!1===ge&&!1===ye?(Z(c),Y(`Auto Resize can not be changed when <b>direction</> is set to '${b}'.`),!1):(!0===e&&!1===se?(se=!0,queueMicrotask(()=>Dt(c,"Auto Resize enabled"))):!1===e&&!0===se&&(se=!1),Ut(0,0,"autoResize",JSON.stringify(se)),se)),close(){Ut(0,0,"close")},getId:()=>Ve,getOrigin:()=>(ee("getOrigin()","getParentOrigin()"),K),getParentOrigin:()=>K,getPageInfo(e){if("function"==typeof e)return at=e,Ut(0,0,"pageInfo"),void te("getPageInfo()","getParentProps()","See <u>https://iframe-resizer.com/upgrade</> for details. ");at=null,Ut(0,0,"pageInfoStop")},getParentProps:e=>(P(e,"function","parentIframe.getParentProps(callback) callback"),st=e,Ut(0,0,"parentInfo"),()=>{st=null,Ut(0,0,"parentInfoStop")}),getParentProperties(e){ee("getParentProperties()","getParentProps()"),this.getParentProps(e)},moveToAnchor(e){P(e,"string","parentIframe.moveToAnchor(anchor) anchor"),Ne.findTarget(e)},reset(){!function(){const e=Me;Me=A,et||(et=!0,requestAnimationFrame(()=>{et=!1})),Ft("reset"),Me=e}()},setOffsetSize(e){P(e,"number","parentIframe.setOffsetSize(offset) offset"),D=e,U=e,Dt(m,`parentIframe.setOffsetSize(${e})`)},scrollBy(e,t){P(e,"number","parentIframe.scrollBy(x, y) x"),P(t,"number","parentIframe.scrollBy(x, y) y"),Ut(t,e,"scrollBy")},scrollTo(e,t){P(e,"number","parentIframe.scrollTo(x, y) x"),P(t,"number","parentIframe.scrollTo(x, y) y"),Ut(t,e,"scrollTo")},scrollToOffset(e,t){P(e,"number","parentIframe.scrollToOffset(x, y) x"),P(t,"number","parentIframe.scrollToOffset(x, y) y"),Ut(t,e,"scrollToOffset")},sendMessage(e,t){t&&P(t,"string","parentIframe.sendMessage(msg, targetOrigin) targetOrigin"),Ut(0,0,"message",JSON.stringify(e),t)},setHeightCalculationMethod(e){Me=e,bt()},setWidthCalculationMethod(e){nt=e,vt()},setTargetOrigin(e){P(e,"string","parentIframe.setTargetOrigin(targetOrigin) targetOrigin"),Xe=e},resize(e,t){e&&P(e,"number","parentIframe.resize(customHeight, customWidth) customHeight"),t&&P(t,"number","parentIframe.resize(customHeight, customWidth) customWidth"),Dt(d,`parentIframe.resize(${e||""}${t?`,${t}`:""})`,e,t)},size(e,t){ee("size()","resize()"),this.resize(e,t)}}),ot.parentIFrame=ot.parentIframe),function(){function e(e){Ut(0,0,e.type,`${e.screenY}:${e.screenX}`)}function t(t,n){z(window.document,t,e)}!0===qe&&(t("mouseenter"),t("mouseleave"))}(),Ne=function(){const e=()=>({x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop});function t(t){const n=t.getBoundingClientRect(),r=e();return{x:parseInt(n.left,o)+parseInt(r.x,o),y:parseInt(n.top,o)+parseInt(r.y,o)}}function n(e){function n(e){const n=t(e);Ut(n.y,n.x,"scrollToOffset")}const o=e.split("#")[1]||e,r=decodeURIComponent(o),i=document.getElementById(r)||document.getElementsByName(r)[0];void 0===i?Ut(0,0,"inPageLink",`#${o}`):n(i)}function r(){const{hash:e,href:t}=window.location;""!==e&&"#"!==e&&n(t)}function i(){for(const e of document.querySelectorAll('a[href^="#"]'))"#"!==e.getAttribute("href")&&z(e,"click",t=>{t.preventDefault(),n(e.getAttribute("href"))})}function a(){z(window,"hashchange",r)}function s(){setTimeout(r,128)}function l(){i(),a(),s()}return Ne.enable&&(1===He?Y("In page linking requires a Professional or Business license. Please see <u>https://iframe-resizer.com/pricing</> for more details."):l()),{findTarget:n}}(),void 0===de&&(de=`${ce}px`),mt("margin",(u="margin",(f=de).includes("-")&&(Q(`Negative CSS value ignored for ${u}`),f=""),f)),mt("background",le),mt("padding",pe),function(){const e=document.createElement("div");e.style.clear="both",e.style.display="block",e.style.height="0",document.body.append(e)}(),he||function(){const e=e=>e.style.setProperty("height","auto","important");e(document.documentElement),e(document.body)}(),function(e){yt({method:e,eventType:"After Print",eventName:"afterprint"}),yt({method:e,eventType:"Before Print",eventName:"beforeprint"}),yt({method:e,eventType:"Ready State Change",eventName:"readystatechange"})}("add"),function(){const e=At(document.documentElement)();Oe(Et),function(e){const t={root:document.documentElement,side:ye?s:l};oe=Te(wt,t),oe.attachObservers(e)}(e),Ce(),function(e){Be=new ResizeObserver($t),Be.observe(document.body),Le.add(document.body),q("Attached ResizeObserver to body"),re={attachObserverToNonStaticElements:Ge,detachObservers:Ie(0,Be,Le)},re.attachObserverToNonStaticElements(e)}(e),function(e){const t=new IntersectionObserver(t=>e(t[0].isIntersecting),{threshold:0}),n=document.documentElement;t.observe(n),q("Attached VisibilityObserver to page")}(Ot)}(),ct(k(it)),Dt(v,"Init message from host page",void 0,void 0,`${t}:${He}`),document.title&&""!==document.title&&Ut(0,0,"title",document.title)}function ct(e){"complete"===document.readyState?j(e):z(document,"readystatechange",()=>ct(e))}function ut(){Qe=document.querySelectorAll(`[${r}]`),we=Qe.length>0}let dt=0;function ft(){const t=document.querySelectorAll(`*[${a}]`);ve=t.length>0,ve&&t.length!==dt&&(function(t){const n=1===t.length?"":"s";Q(`%c[${a}]%c found on %c${t.length}%c element${n}`,e.BOLD,e.NORMAL,e.BOLD,e.NORMAL)}(t),dt=t.length)}function mt(t,n){void 0!==n&&""!==n&&"null"!==n&&(document.body.style.setProperty(t,n),q(`Set body ${t}: %c${n}`,e.HIGHLIGHT))}function pt(e,t,n){if(""!==n)for(const e of document.querySelectorAll(n))e.toggleAttribute(t,!0)}function ht(){pt(0,r,_e),pt(0,a,ke)}function yt(e){({add(t){function n(){Dt(e.eventName,e.eventType)}M[t]=n,z(window,t,n,{passive:!0})},remove(e){const t=M[e];var n,o;delete M[e],n=e,o=t,window.removeEventListener(n,o,!1)}})[e.method](e.eventName)}function gt(e,t,n,o){return t!==e&&(e in n||(Q(`${e} is not a valid option for ${o}CalculationMethod.`),e=t),e in S)&&Y(`<rb>Deprecated ${o}CalculationMethod (${e})</>\n\nThis version of <i>iframe-resizer</> can auto detect the most suitable ${o} calculation method. It is recommended that you ${ie?"remove this option.":"set this option to <b>'auto'</> when using an older version of <i>iframe-resizer</> on the parent page."}`),e}function bt(){Me=gt(Me,A,Ct,"height")}function vt(){nt=gt(nt,L,Ht,"width")}function zt(){const e=document.querySelectorAll(`[${i}]`);Ue=Array.from(e).filter(e=>!e.closest(`[${a}]`)),ze=Ue.length>0}function wt(e){zt(),(ze||e)&&(Ue.length>1?q("Overflowed Elements:",...Ue):ze||q("Overflow removed"),Dt(h,"Overflow updated"))}function $t(e){if(!Array.isArray(e)||0===e.length)return;const t=e[0].target;Dt(p,`Element resized <${function(e){switch(!0){case!R(e):return"";case R(e.id):return`${e.nodeName}#${e.id}`;case R(e.name):return`${e.nodeName} (${e.name}`;case R(e.className):return`${e.nodeName}.${e.className}`;default:return e.nodeName}}(t)}>`)}function Ot(e){xe=!e,Dt(g,"Visibility changed")}const St=Se("Overflow"),It=Se("Overflow",!1),Mt=Se("Resize"),Tt=Se("Resize",!1);function Et(e){!function({addedMutations:e,removedMutations:t}){Z("contentMutated"),ht(),ut(),zt();let n=0,o=0,r=0,i=0;for(const e of t){const t=At(e)();o+=oe.detachObservers(t),i+=re.detachObservers(t)}for(const t of e){const e=At(t)();n+=oe.attachObservers(e),r+=re.attachObserverToNonStaticElements(e)}It(o),Tt(i),St(n),Mt(r),F()}(e),Dt(y,"Mutation Observed")}function jt(e){performance.mark(Ee);const t=x(e);let n=0,o=document.documentElement,r=we?0:document.documentElement.getBoundingClientRect().bottom;const i=we?Qe:ze?Ue:At(document)();for(const t of i)n=t.getBoundingClientRect()[e]+parseFloat(getComputedStyle(t).getPropertyValue(`margin-${e}`)),n>r&&(r=n,o=t);return q(`${t} position calculated from:`,o),performance.mark(je,{detail:{hasTags:we,len:i.length,logging:Pe,Side:t}}),r}const kt=e=>[e.bodyOffset(),e.bodyScroll(),e.documentElementOffset(),e.documentElementScroll(),e.boundingClientRect()],At=e=>()=>{if(!(e=>e.nodeType===Node.ELEMENT_NODE)(e))return[e];const t=["* ","not(head)","not(meta)","not(base)","not(title)","not(script)","not(link)","not(style)","not(map)","not(area)","not(option)","not(optgroup)","not(template)","not(track)","not(wbr)","not(nobr)"];return ft(),ve&&t.push(`not([${a}])`,`not([${a}] *)`),[e,...e.querySelectorAll(t.join(":"))]},Nt={height:0,width:0},xt={height:0,width:0},Rt=[e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT];function Pt(t){function n(){return xt[r]=i,Nt[r]=l,i}const o=t===Ct,r=o?"height":"width",i=t.boundingClientRect(),a=Math.ceil(i),s=Math.floor(i),l=(e=>e.documentElementScroll()+Math.max(0,e.getOffset()))(t),c=`HTML: %c${i}px %cPage: %c${l}px`;let u=0;switch(!0){case!t.enabled():return l;case we:q("Found element with data-iframe-size attribute"),u=t.taggedElement();break;case!ze&&0===xt[r]&&0===Nt[r]:q(`Initial page size values: ${c}`,...Rt),u=n();break;case et&&i===xt[r]&&l===Nt[r]:q(`Size unchanged: ${c}`,...Rt),u=Math.max(i,l);break;case 0===i:q(`Page is hidden: ${c}`,...Rt),u=l;break;case!ze&&i!==xt[r]&&l<=Nt[r]:q(`New <html> size: ${c} `,...Rt),q(`Previous <html> size: %c${xt[r]}px`,e.HIGHLIGHT),u=n();break;case!o:u=t.taggedElement();break;case!ze&&i<xt[r]:q(`<html> size decreased: ${c}`,...Rt),u=n();break;case l===s||l===a:q(`<html> size equals page size: ${c}`,...Rt),u=n();break;case i>l:q(`Page size < <html> size: ${c}`,...Rt),u=n();break;case ze:q("Found element overflowing <html> "),u=t.taggedElement();break;default:q(`Using <html> size: ${c}`,...Rt),u=n()}return q(`Content ${r}: %c${u}px`,e.HIGHLIGHT),u+=function(t){const n=t.getOffset();return 0!==n&&q(`Page offsetSize: %c${n}px`,e.HIGHLIGHT),n}(t),u}const Ct={enabled:()=>ye,getOffset:()=>D,auto:()=>Pt(Ct),bodyOffset:()=>{const{body:e}=document,t=getComputedStyle(e);return e.offsetHeight+parseInt(t.marginTop,o)+parseInt(t.marginBottom,o)},bodyScroll:()=>document.body.scrollHeight,offset:()=>Ct.bodyOffset(),custom:()=>w.height(),documentElementOffset:()=>document.documentElement.offsetHeight,documentElementScroll:()=>document.documentElement.scrollHeight,boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().bottom,document.body.getBoundingClientRect().bottom),max:()=>Math.max(...kt(Ct)),min:()=>Math.min(...kt(Ct)),grow:()=>Ct.max(),lowestElement:()=>jt(s),taggedElement:()=>jt(s)},Ht={enabled:()=>ge,getOffset:()=>U,auto:()=>Pt(Ht),bodyScroll:()=>document.body.scrollWidth,bodyOffset:()=>document.body.offsetWidth,custom:()=>w.width(),documentElementScroll:()=>document.documentElement.scrollWidth,documentElementOffset:()=>document.documentElement.offsetWidth,boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().right,document.body.getBoundingClientRect().right),max:()=>Math.max(...kt(Ht)),min:()=>Math.min(...kt(Ht)),rightMostElement:()=>jt(l),scroll:()=>Math.max(Ht.bodyScroll(),Ht.documentElementScroll()),taggedElement:()=>jt(l)},Lt=(e,t)=>!(Math.abs(e-t)<=Ke);function Bt(e,t){const n=e[t]();return e.enabled()&&void 0!==ae?function(e){const t=ae(e);if(void 0===t)throw new TypeError("No value returned from onBeforeResize(), expected a numeric value");if(Number.isNaN(t))throw new TypeError(`Invalid value returned from onBeforeResize(): ${t}, expected Number`);return t}(n):n}let Gt=!1;const qt=k(()=>X(T(4)));let Wt=!1;const Dt=V((e,t,n,o,r)=>{if(performance.now(),Z(e),!0!==Gt){if(!se&&!(e in f))return q("Resizing disabled"),void F();if(xe){if(!0===Wt)return;Wt=!0}else Wt=!1,Gt=!0,requestAnimationFrame(()=>{Gt=!1}),function(e,t,n,o,r){const i=n??Bt(Ct,Me),a=o??Bt(Ht,nt);switch(ye&&Lt($e,i)||ge&&Lt(tt,a)?u:e){case v:case c:case u:$e=i,tt=a;case m:Ut($e,tt,e,r);break;case h:case y:case p:case g:_();break;default:_(),q("No change in content size detected")}}(e,0,n,o,r)}});function Ft(e){$e=Ct[Me](),tt=Ht[nt](),Ut($e,tt,e)}const Ut=V(function(t,n,o,r,i){He<-1||(Z(o),void 0!==i||(i=Xe),function(){const a=`${Ve}:${t}:${n}:${o}${void 0===r?"":`:${r}`}`;if(Je)try{window.parent.iframeParentListener(N+a)}catch(e){if(1!==He)throw e;return void qt()}else Ye.postMessage(N+a,i);q(`Sending message to parent page via ${Je?"sameOrigin":"postMessage"}: %c%c${a}`,e.ITALIC,e.HIGHLIGHT)}(),F())}),Vt=V(function(e){Z("onMessage");const{freeze:t}=Object,{parse:n}=JSON,o=e=>Ut(0,0,`${e}Stop`),r={init:function(){if("loading"===document.readyState)return;const t=e.data.slice(13).split(":");Ye=e.source,K=e.origin,lt(t),be=!1,setTimeout(()=>{Ae=!1},128)},reset(){Ae||Ft("resetPage")},resize(){Dt("parentResize","Parent window requested size check")},moveToAnchor(){Ne.findTarget(a())},inPageLink(){this.moveToAnchor()},pageInfo(){const e=a();at?j(at,n(e)):o("pageInfo")},parentInfo(){const e=(r=a(),t(n(r)));var r;st?j(st,e):o("parentInfo")},message(){const e=a();j(rt,n(e))}},i=()=>e.data.split("]")[1].split(":")[0],a=()=>e.data.slice(e.data.indexOf(":")+1),s=()=>e.data.split(":")[2]in{true:1,false:1};function l(){const t=i();Z(t),t in r?r[t]():"iframeResize"in window||void 0!==window.jQuery&&""in window.jQuery.prototype||s()||Q(`Unexpected message (${e.data})`)}N===`${e.data}`.slice(0,13)&&function(){if(!1!==be)return s()?(J(i()),Z(v),void r.init()):void 0;l()}()});function Zt(){"loading"!==document.readyState&&window.parent.postMessage("[iFrameResizerChild]Ready","*")}"iframeChildListener"in window?Q("Already setup"):(window.iframeChildListener=e=>setTimeout(()=>Vt({data:e,sameOrigin:!0})),z(window,"message",Vt),z(window,"readystatechange",Zt),Zt())}();