@iframe-resizer/child 6.0.0-beta.4 → 6.0.0-beta.6
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 +1 -1
- package/index.cjs.js +20 -27
- package/index.cjs.js.map +1 -1
- package/index.esm.js +20 -1274
- package/index.esm.js.map +1 -1
- package/index.umd.js +20 -27
- package/index.umd.js.map +1 -1
- package/package.json +2 -2
package/index.umd.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Calculating the page size is taking an excessive amount of time (${u.round(e)}ms).
|
|
21
|
-
|
|
22
|
-
To improve performance add the <b>data-iframe-size</> attribute to the ${K.Side.toLowerCase()} most element on the page. For more details see: <u>https://iframe-resizer.com/perf</>.`))},mn)}function pn(e){e.getEntries().forEach(t=>{if(t.name===Q)try{const{duration:n}=performance.measure(Ke,de,Q);K=t.detail,O.push(n),O.length>En&&O.shift()}catch{}})}function On(){f("Attached%c PerformanceObserver%c to page",i.HIGHLIGHT,i.FOREGROUND);const e=new PerformanceObserver(pn);return e.observe({entryTypes:["mark"]}),In(),{disconnect:()=>{Xe(),clearInterval(le),e.disconnect(),f("Detached%c PerformanceObserver",i.HIGHLIGHT)}}}const Sn=e=>`:not(${e})`,Tn=`* ${Array.from(o.IGNORE_TAGS).map(Sn).join("")}`,fe=e=>e.querySelectorAll(Tn);function Rn(){const{hasOverflow:e,hasTags:t,overflowedNodeSet:n,taggedElements:r}=a;return t?r:e?Array.from(n):fe(document.documentElement)}function vn(e,t){const n=`margin-${t}`;let r,s=document.documentElement,m=a.hasTags?o.MIN_SIZE:document.documentElement.getBoundingClientRect().bottom;for(const l of e)r=l.getBoundingClientRect()[t]+parseFloat(getComputedStyle(l).getPropertyValue(n)),r>m&&(m=r,s=l);return{maxEl:s,maxVal:m}}function et(e){performance.mark(de);const t=u.capitalizeFirstLetter(e),{logging:n}=c,{hasTags:r}=a,s=Rn(),{maxEl:m,maxVal:l}=vn(s,e);return f(`${t} position calculated from:`,m),f(`Checked %c${s.length}%c elements`,i.HIGHLIGHT,i.FOREGROUND),performance.mark(Q,{detail:{hasTags:r,len:s.length,logging:n,Side:t}}),l}const ue={label:o.HEIGHT,enabled:()=>c.calculateHeight,getOffset:()=>c.offsetHeight,auto:()=>Qe(ue),boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().bottom,document.body.getBoundingClientRect().bottom),documentElementScroll:()=>document.documentElement.scrollHeight,taggedElement:()=>et(o.HEIGHT_EDGE)},me={label:o.WIDTH,enabled:()=>c.calculateWidth,getOffset:()=>c.offsetWidth,auto:()=>Qe(me),boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().right,document.body.getBoundingClientRect().right),documentElementScroll:()=>document.documentElement.scrollWidth,taggedElement:()=>et(o.WIDTH_EDGE)};function wn(e,t,n){const r=c.onBeforeResize(e,t,n);if(r===void 0)throw new TypeError("No value returned from onBeforeResize(), expected a numeric value");if(Number.isNaN(r))throw new TypeError(`Invalid value returned from onBeforeResize(): ${r}, expected Number`);if(r<o.MIN_SIZE)throw new RangeError(`Out of range value returned from onBeforeResize(): ${r}, must be at least ${o.MIN_SIZE}`);return r}const tt=(e,t)=>(n,r)=>{const s=e[n]();return e.enabled()&&c.onBeforeResize!==void 0?wn(s,r,t):s},bn=tt(ue,o.HEIGHT),yn=tt(me,o.WIDTH);function Hn(){(window.scrollY!==0||window.scrollX!==0)&&(f("Reset iframe scroll position to (0, 0)"),window.scrollTo(0,0))}function An(e,t,n,r){const{heightCalcMode:s,widthCalcMode:m}=c;Hn();const l=n??bn(s,e),g=r??yn(m,e),T=ln(l,g)?o.SIZE_CHANGE_DETECTED:e;switch(d(`Resize event: %c${t}`,i.HIGHLIGHT),T){case o.INIT:case o.ENABLE:case o.SIZE_CHANGE_DETECTED:case o.MANUAL_RESIZE_REQUEST:case o.PARENT_RESIZE_REQUEST:a.height=l,a.width=g;case o.SET_OFFSET_SIZE:return a;case o.OVERFLOW_OBSERVER:case o.MUTATION_OBSERVER:case o.RESIZE_OBSERVER:case o.VISIBILITY_OBSERVER:{d(o.NO_CHANGE);break}default:f(o.NO_CHANGE)}return null}let J=!1,ge=!1,B=null;function Nn(e,t,n,r,s){const{autoResize:m}=c,{isHidden:l}=a;switch(I(e),!0){case(l===!0&&!(e in o.IGNORE_DISABLE_RESIZE)):{if(ge===!0)break;d("Iframe hidden - Ignored resize request"),ge=!0,J=!1,cancelAnimationFrame(B),B=null;break}case(J===!0&&e!==o.OVERFLOW_OBSERVER&&!(e in o.IGNORE_DISABLE_RESIZE)):{d("Resize already pending - Ignored resize request");break}case(!m&&!(e in o.IGNORE_DISABLE_RESIZE)):{f("Resizing disabled");break}default:{ge=!1,J=!0,a.totalTime=performance.now(),a.timerActive=!0;const g=An(e,t,n,r);g&&Ze(g.height,g.width,e,s),B||(B=requestAnimationFrame(()=>{J=!1,B=null,I("requestAnimationFrame"),j(`Reset sendPending: %c${e}`,i.HIGHLIGHT)})),a.timerActive=!1}}z()}const w=se(Nn);function nt({eventType:e,eventName:t}){L(window,t,()=>w(t,e),{passive:!0})}function Ln(){nt({eventType:"After Print",eventName:"afterprint"}),nt({eventType:"Before Print",eventName:"beforeprint"})}function Gn(){if(a.triggerLocked){d("TriggerLock blocked calculation");return}a.triggerLocked=!0,j("Trigger event lock on"),requestAnimationFrame(()=>{a.triggerLocked=!1,j("Trigger event lock off")})}function ot(e){const{heightCalcMode:t,widthCalcMode:n}=c,r=ue[t](),s=me[n]();d(`Reset trigger event: %c${e}`,i.HIGHLIGHT),S(r,s,e)}function Mn(e){const t=c.heightCalcMode;d(`Reset trigger event: %c${e}`,i.HIGHLIGHT),c.heightCalcMode=o.HEIGHT_CALC_MODE_DEFAULT,Gn(),ot("reset"),c.heightCalcMode=t}const zn=`Auto Resize can not be changed when <b>direction</> is set to '${o.NONE}'.`;function $n(e){u.typeAssert(e,o.BOOLEAN,"parentIframe.autoResize(enable) enable");const{autoResize:t,calculateHeight:n,calculateWidth:r}=c;return r===!1&&n===!1?(I(o.ENABLE),R(zn),!1):(e===!0&&t===!1?(c.autoResize=!0,queueMicrotask(()=>w(o.ENABLE,"Auto Resize enabled"))):e===!1&&t===!0&&(c.autoResize=!1),S(0,0,o.AUTO_RESIZE,JSON.stringify(c.autoResize)),c.autoResize)}function _n(e){u.typeAssert(e,o.STRING,"parentIframe.moveToAnchor(anchor) anchor"),a.inPageLinks.findTarget(e)}function kn(e){u.typeAssert(e,o.NUMBER,"parentIframe.setOffsetSize(offset) offset"),c.offsetHeight=e,c.offsetWidth=e,w(o.SET_OFFSET_SIZE,`parentIframe.setOffsetSize(${e})`)}const Cn=()=>a.origin;function Dn(e){u.typeAssert(e,o.STRING,"parentIframe.setTargetOrigin(targetOrigin) targetOrigin"),d(`Set targetOrigin: %c${e}`,i.HIGHLIGHT),c.targetOrigin=e}function Pn(e){return u.typeAssert(e,o.FUNCTION,"parentIframe.getParentProps(callback) callback"),a.onParentInfo=e,S(0,0,o.PARENT_INFO),()=>{a.onParentInfo=null,S(0,0,o.PARENT_INFO_STOP)}}function Bn(e,t){e!==void 0&&u.typeAssert(e,o.NUMBER,"parentIframe.resize(customHeight, customWidth) customHeight"),t!==void 0&&u.typeAssert(t,o.NUMBER,"parentIframe.resize(customHeight, customWidth) customWidth");const n=e===void 0?"":e,r=t===void 0?"":`,${t}`,s=`${n}${r}`;w(o.MANUAL_RESIZE_REQUEST,`parentIframe.resize(${s})`,e,t)}const he=e=>(t,n)=>{u.typeAssert(t,o.NUMBER,`parentIframe.${e}(x, y) x`),u.typeAssert(n,o.NUMBER,`parentIframe.${e}(x, y) y`),S(n,t,e)},Fn=he(o.SCROLL_BY),Un=he(o.SCROLL_TO),xn=he(o.SCROLL_TO_OFFSET);function Vn(e,t){t&&u.typeAssert(t,o.STRING,"parentIframe.sendMessage(msg, targetOrigin) targetOrigin"),S(0,0,o.MESSAGE,JSON.stringify(e),t)}const Wn=()=>S(0,0,o.CLOSE),qn=()=>c.parentId,Zn=()=>Mn("parentIframe.reset");function jn(){const{win:e}=a;c.mode!==1&&(e.parentIframe=Object.freeze({autoResize:$n,close:Wn,getId:qn,getParentOrigin:Cn,getParentProps:Pn,moveToAnchor:_n,reset:Zn,setOffsetSize:kn,scrollBy:Fn,scrollTo:Un,scrollToOffset:xn,sendMessage:Vn,setTargetOrigin:Dn,resize:Bn}))}const F=(e="")=>t=>n=>{n.size>0&&j(`${t}Observer ${e}:`,...Array.from(n).flatMap(r=>[o.NEW_LINE,r]))},Yn=(e="")=>t=>n=>{n.size>0&&Me(`${t}Observer ${e}:`,...Array.from(n).flatMap(r=>[o.NEW_LINE,r]))},rt=F("attached to"),it=Yn("already attached"),Qn=F("detached from"),X=(e,t=!0)=>n=>{n>0&&f(`${t?"At":"De"}tached %c${e}Observer%c ${t?"to":"from"} %c${n}%c element${n===1?"":"s"}`,i.HIGHLIGHT,i.NORMAL,i.HIGHLIGHT,i.NORMAL)},st=(e,t,n,r)=>{const s=Qn(e);return m=>{const l=new Set;let g=0;for(const T of m)n.has(T)&&(t.unobserve(T),n.delete(T),l.add(T),g+=1);s(l),r(g),l.clear()}},at=16,ct=2,Kn=200,Ee="Mutation",b=new Set,M=new Set,Ie=new Set,ee=[],Jn={attributes:!0,attributeFilter:[o.IGNORE_ATTR,o.SIZE_ATTR],attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0};let pe=1,Oe,Se=!1,Te=0;const Xn=F("added")(Ee),eo=F("removed (page)")(Ee),to=F("removed (added)")(Ee),dt=e=>e.nodeType!==Node.ELEMENT_NODE||o.IGNORE_TAGS.has(e.tagName.toLowerCase());function no(e){const t=e.addedNodes;for(const n of t)dt(n)||b.add(n)}function oo(e){const t=e.removedNodes;for(const n of t)dt(n)||(b.has(n)?(b.delete(n),Ie.add(n)):M.add(n))}const ro=e=>{f("Mutations:",e);for(const t of e)no(t),oo(t);Xn(b),eo(M),to(Ie),Ie.clear()};function io(){M.size>0&&d(`Detected %c${M.size} %cremoved element${M.size>1?"s":""}`,i.HIGHLIGHT,i.FOREGROUND),b.size>0&&d(`Found %c${b.size} %cnew element${b.size>1?"s":""}`,i.HIGHLIGHT,i.FOREGROUND)}const so=e=>()=>{const t=performance.now(),n=t-Te,r=at*pe+++ct;if(n>r&&n<Kn){I("mutationThrottled"),f("Update delayed due to heavy workload on the callStack"),f(`EventLoop busy time: %c${u.round(n)}ms %c> Max wait: %c${r-ct}ms`,i.HIGHLIGHT,i.FOREGROUND,i.HIGHLIGHT),setTimeout(Oe,at*pe),Te=t;return}pe=1,ee.forEach(ro),ee.length=0,Se=!1,io(),e({addedNodes:b,removedNodes:M}),b.clear(),M.clear()};function ao(e){ee.push(e),!Se&&(Te=performance.now(),Se=!0,requestAnimationFrame(Oe))}function co(e){const t=new window.MutationObserver(ao),n=document.body||document.documentElement;return Oe=so(e),t.observe(n,Jn),f("Attached%c MutationObserver%c to body",i.HIGHLIGHT,i.FOREGROUND),{disconnect:()=>{b.clear(),M.clear(),ee.length=0,t.disconnect(),f("Detached%c MutationObserver",i.HIGHLIGHT)}}}const lo={characterData:!0,childList:!0,subtree:!0};function fo(e){const t=document.querySelector("title")??document.head??document.documentElement,n=new MutationObserver(e);return n.observe(t,lo),f("Attached%c TitleObserver%c to head",i.HIGHLIGHT,i.FOREGROUND),setTimeout(e),{disconnect:()=>{n.disconnect(),f("Detached%c TitleObserver",i.HIGHLIGHT)}}}function uo(e){const t=new IntersectionObserver(r=>e(r.at(-1)?.isIntersecting??!1),{threshold:0}),n=document.documentElement;return t.observe(n),f("Attached%c VisibilityObserver%c to page",i.HIGHLIGHT,i.FOREGROUND),{disconnect:()=>{t.disconnect(),f("Detached%c VisibilityObserver",i.HIGHLIGHT)}}}let lt=new Set;function mo(e){const t=new Set,n=new Set;for(const r of e)r.closest(`[${o.IGNORE_ATTR}]`)?n.add(r):t.add(r);return n.size>0&&queueMicrotask(()=>{I("overflowIgnored"),f(`Ignoring elements with [data-iframe-ignore] > *:
|
|
23
|
-
`,n),z()}),t}function ft(){const e=document.querySelectorAll(`[${o.OVERFLOW_ATTR}]`),t=mo(e);let n=!0;return typeof Set.prototype.symmetricDifference===o.FUNCTION&&(n=t.symmetricDifference(lt).size>0),lt=t,a.overflowedNodeSet=t,a.hasOverflow=t.size>0,{hasOverflowUpdated:n,overflowedNodeSet:t}}const y={},ut=e=>{const t=new Set;for(const n of e)if(n instanceof Element){t.add(n);for(const r of fe(n))t.add(r)}return f(`Inspecting:
|
|
24
|
-
`,t),t},go=e=>{if(e.size===0)return;I("addObservers");const t=ut(e);y.overflow.attachObservers(t),y.resize.attachObserverToNonStaticElements(t),z()},ho=e=>{if(e.size===0)return;I("removeObservers");const t=ut(e);y.overflow.detachObservers(t),y.resize.detachObservers(t),z()};function Eo({addedNodes:e,removedNodes:t}){I("contentMutated"),a.applySelectors(),qe(),ft(),z(),ho(t),go(e)}function Io(e){Eo(e),w(o.MUTATION_OBSERVER,"Mutation Observed")}const U="Overflow",po=X(U),Oo=X(U,!1),So=rt(U),To=it(U),Ro=e=>e instanceof HTMLElement&&(!!e.hidden||e.offsetParent===null||e.style.display===o.NONE),vo=(e,t)=>{const n=t.side||o.HEIGHT_EDGE,r={root:t.root,rootMargin:"0px",threshold:1},s=window?.requestAnimationFrame||u.id,m=(H=!1)=>e(H),l=(H,N)=>H===0||H>N[n],g=(H,N)=>{H.toggleAttribute(o.OVERFLOW_ATTR,N)};function T(H){for(const N of H){const{boundingClientRect:q,rootBounds:Z,target:A}=N;if(!Z)continue;const Or=q[n],Sr=l(Or,Z)&&!(A instanceof HTMLElement&&Ro(A));g(A,Sr)}s(m)}const h=new IntersectionObserver(T,r),v=new WeakSet;function p(H){const N=new Set,q=new Set;let Z=0;for(const A of H)if(A instanceof Element){if(v.has(A)){N.add(A);continue}h.observe(A),v.add(A),q.add(A),Z+=1}To(N),So(q),po(Z),q.clear(),N.clear()}return{attachObservers:p,detachObservers:st(U,h,v,Oo),disconnect:()=>{h.disconnect(),f("Detached%c OverflowObserver",i.HIGHLIGHT)}}};function wo(){const{hasOverflow:e}=a,{hasOverflowUpdated:t,overflowedNodeSet:n}=ft();switch(!0){case!t:return;case n.size>1:f("Overflowed Elements:",n);break;case e:break;default:f("No overflow detected")}w(o.OVERFLOW_OBSERVER,"Overflow updated")}function bo(e){const t={root:document.documentElement,side:c.calculateHeight?o.HEIGHT_EDGE:o.WIDTH_EDGE};return y.overflow=vo(wo,t),y.overflow.attachObservers(e),y.overflow}const x="Resize",yo=X(x),Ho=X(x,!1),Ao=rt(x),No=it(x),te=new WeakSet,Re=new Set,ve=new Set;let V;function Lo(e){let t=0;for(const n of e){if(!(n instanceof Element))continue;const r=getComputedStyle(n)?.position;if(!(r===""||r==="static")){if(te.has(n)){Re.add(n);continue}V.observe(n),te.add(n),ve.add(n),t+=1}}No(Re),Ao(ve),yo(t),ve.clear(),Re.clear()}const Go=e=>(V=new ResizeObserver(e),V.observe(document.body),te.add(document.body),f("Attached%c ResizeObserver%c to body",i.HIGHLIGHT,i.FOREGROUND),{attachObserverToNonStaticElements:Lo,detachObservers:st(x,V,te,Ho),disconnect:()=>{V.disconnect(),f("Detached%c ResizeObserver",i.HIGHLIGHT)}});function Mo(e){if(!Array.isArray(e)||e.length===0)return;const t=e[0].target;w(o.RESIZE_OBSERVER,`Element resized <${u.getElementName(t)}>`)}function zo(e){return y.resize=Go(Mo),y.resize.attachObserverToNonStaticElements(e),y.resize}let mt;function $o(){const e=document.title;e!==mt&&(mt=e,d(`Title: %c${e}`,i.HIGHLIGHT),e&&S(0,0,o.TITLE,e))}function _o(e){d(`Visible: %c${e}`,i.HIGHLIGHT),a.isHidden=!e,w(o.VISIBILITY_OBSERVER,"Visibility changed")}function ko(e){ce.push(...e.map(t=>t.disconnect))}function Co(){I("attachObservers");const e=fe(document.documentElement),t=[co(Io),bo(e),On(),zo(e),fo($o),uo(_o)];ko(t)}const gt=(e,t,n)=>{if(n!==""){d(`${e}: %c${n}`,i.HIGHLIGHT);for(const r of document.querySelectorAll(n))d(`Applying ${t} to:`,r),r.toggleAttribute(t,!0)}};function Do({sizeSelector:e,ignoreSelector:t}){return()=>{gt("sizeSelector",o.SIZE_ATTR,e),gt("ignoreSelector",o.IGNORE_ATTR,t)}}function Po(){const e=document.createElement("div");e.style.clear="both",e.style.display="block",e.style.height="0",document.body.append(e)}function Bo(e,t){return t.includes("-")&&(_(`Negative CSS value ignored for ${e}`),t=""),t}function we(e,t){t===void 0||t===""||t===o.NULL||(document.body.style.setProperty(e,t),f(`Set body ${e}: %c${t}`,i.HIGHLIGHT))}function Fo({bodyMarginStr:e,bodyMargin:t}){e===void 0&&(e=`${t}px`),we("margin",Bo("margin",e))}const Uo=()=>({x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop});function xo(e){const t=e.getBoundingClientRect(),n=Uo();return{x:Math.round(t.left+n.x),y:Math.round(t.top+n.y)}}function Vo(e,t){const n=xo(t);d(`Moving to in page link (%c#${e}%c) at x: %c${n.x}%c y: %c${n.y}`,i.HIGHLIGHT,i.FOREGROUND,i.HIGHLIGHT,i.FOREGROUND,i.HIGHLIGHT),S(n.y,n.x,o.SCROLL_TO_OFFSET)}function be(e){const t=e.split("#")[1]||e,n=decodeURIComponent(t),r=document.getElementById(n)||document.getElementsByName(n)[0];if(r!==void 0){Vo(t,r);return}d(`In page link (#${t}) not found in iframe, so sending to parent`),S(0,0,o.IN_PAGE_LINK,`#${t}`)}function ht(){const{hash:e,href:t}=window.location;e!==""&&e!=="#"&&be(t)}function Wo(){for(const e of document.querySelectorAll('a[href^="#"]'))e.getAttribute("href")!=="#"&&L(e,"click",t=>{t.preventDefault(),be(e.getAttribute("href"))})}function qo(){L(window,"hashchange",ht)}function Zo(){setTimeout(ht,o.EVENT_CANCEL_TIMER)}function jo(){d("Setting up location.hash handlers"),Wo(),qo(),Zo(),a.inPageLinks={findTarget:be}}function Yo(e){const{mode:t}=c;e?E.checkMode(t)?R(E.getModeData(5)):jo():d("In page linking not enabled")}const Qo="important";function Ko(){const e=t=>t.style.setProperty(o.HEIGHT,o.AUTO,Qo);e(document.documentElement),e(document.body),d("Set HTML & body height: %cauto !important",i.HIGHLIGHT)}const ye=e=>(t,n)=>{if(n in t){if(typeof t[n]===e)return t[n];throw new TypeError(`${n} is not a ${e}.`)}},He=ye(o.FUNCTION),Et=ye(o.NUMBER),ne=ye(o.STRING),Jo=e=>e!==null&&typeof e===o.OBJECT&&!Array.isArray(e);function Xo(e){const{calculateHeight:t,calculateWidth:n}=c;let r,s;return typeof e?.offsetSize===o.NUMBER&&(t&&(r=Et(e,o.OFFSET_SIZE)),n&&(s=Et(e,o.OFFSET_SIZE))),{offsetHeight:r,offsetWidth:s}}function er(e){d("Reading data from page:",Object.keys(e));const{offsetHeight:t,offsetWidth:n}=Xo(e);return{offsetHeight:t,offsetWidth:n,ignoreSelector:ne(e,"ignoreSelector"),[E.getKey(3)]:ne(e,E.getKey(0)),sizeSelector:ne(e,"sizeSelector"),targetOrigin:ne(e,"targetOrigin"),onBeforeResize:He(e,"onBeforeResize"),onMessage:He(e,"onMessage"),onReady:He(e,"onReady")}}function tr(){const{mode:e}=c;if(E.checkMode(e))return{};const t=window.iframeResizer||window.iFrameResizer;return Jo(t)?er(t):{}}const nr=e=>e==="true",It=e=>t=>t===void 0?void 0:e(t),$=It(nr),W=It(Number),or=e=>({parentId:e[0],bodyMargin:W(e[1]),calculateWidth:$(e[2]),logging:$(e[3]),autoResize:$(e[6]),bodyMarginStr:e[7],bodyBackground:e[9],bodyPadding:e[10],tolerance:W(e[11]),inPageLinks:$(e[12]),mouseEvents:$(e[15]),offsetHeight:W(e[16]),offsetWidth:W(e[17]),calculateHeight:$(e[18]),key:e[19],version:e[20],mode:W(e[21]),logExpand:$(e[23])});function rr(e){const{mode:t}=c;e.forEach(n=>{try{n()}catch(r){if(t<0)throw r;R(`<rb>Error in setup function</>
|
|
25
|
-
<i>iframe-resizer</> detected an error during setup.
|
|
26
|
-
|
|
27
|
-
Please report the following error message at <u>https://github.com/davidjbradshaw/iframe-resizer/issues</>`),Me(r)}})}function pt(e){for(const[t,n]of Object.entries(e))n!==void 0&&(c[t]=n)}function ir({logExpand:e,logging:t,parentId:n=""}){vt({id:n,enabled:t,expand:e}),I("initReceived"),d(`Initialising iframe v${o.VERSION} ${window.location.href}`)}function sr(e){I("ready"),We(u.once(e)),d("Initialization complete",(({key:t,key2:n,...r})=>r)(c))}function ar({bodyBackground:e,bodyPadding:t,inPageLinks:n,onReady:r}){const s=Bt(c),m=[xt,Ft,jt,qe,Qt,s?u.id:Pt,()=>Fo(c),()=>we("background",e),()=>we("padding",t),s?u.id:Ko,Po,a.applySelectors,()=>Yo(n),Ln,()=>sn(c),dn,()=>jn(),()=>w(o.INIT,"Init message from host page",void 0,void 0,`${o.VERSION}:${c.mode}`),Co,z];Xt(c),Wt(c),rr(m),sr(r)}function cr(e){a.firstRun&&(pt(or(e)),ir(c),pt(tr()),a.applySelectors=Do(c),ar(c))}function dr(e){if(document.readyState==="loading"){d("Page not ready, ignoring init message");return}const t=e.data.slice(o.MESSAGE_ID_LENGTH).split(o.SEPARATOR);a.target=e.source,a.origin=e.origin,cr(t),a.firstRun=!1,setTimeout(()=>{a.initLock=!1},o.EVENT_CANCEL_TIMER)}const{freeze:lr}=Object,{parse:Ae}=JSON,Ne=e=>lr(Ae(e)),Ot=e=>S(0,0,`${e}Stop`),oe=e=>e.data.slice(e.data.indexOf(o.SEPARATOR)+1),fr=e=>Nt(e)?o.INIT:e.data.split("]")[1].split(o.SEPARATOR)[0];function ur(e){const t=oe(e);d("onMessage called from parent:%c",i.HIGHLIGHT,Ne(t)),u.isolateUserCode(c.onMessage,Ae(t))}function mr(e){const{onPageInfo:t}=a,n=oe(e);d("PageInfo received from parent:",Ne(n)),t?u.isolateUserCode(t,Ae(n)):Ot(o.PAGE_INFO)}function gr(e){const{onParentInfo:t}=a,n=Ne(oe(e));d("ParentInfo received from parent:",n),t?u.isolateUserCode(t,n):Ot(o.PARENT_INFO)}function hr(){if(a.initLock){d("Page reset ignored by init");return}d("Page size reset by host page"),ot("resetPage")}function Er(){d("Resize requested by host page"),w(o.PARENT_RESIZE_REQUEST,"Parent window requested size check")}const St=e=>a.inPageLinks.findTarget(oe(e)),Tt={init:dr,reset:hr,resize:Er,moveToAnchor:St,inPageLink:St,pageInfo:mr,parentInfo:gr,message:ur};function Ir(e){const{firstRun:t}=a,n=fr(e);switch(I(n),!0){case n in Tt:Tt[n](e);break;case(t&&At()):_(`Ignored message of type "${n}". Received before initialization.`);break;default:_(`Unexpected message (${e.data}), this is likely due to a newer version of iframe-resizer running on the parent page.`)}}const re=se(e=>{Ht(e)&&Ir(e)});function pr(){if("iframeChildListener"in window){_("Already setup");return}window.iframeChildListener=(t=>{setTimeout(()=>re({data:t,sameOrigin:!0}))}),I("listen"),L(window,o.MESSAGE,re),L(document,o.READY_STATE_CHANGE,De),De();function e(t){return re(t),a.win}try{top?.document?.getElementById("banner")&&(a.win={},window.mockMsgListener=e,_e(window,o.MESSAGE,re),typeof window.define=="function"&&window.define([],()=>e))}catch{}}typeof window!==o.UNDEFINED&&pr()}));
|
|
1
|
+
/*!
|
|
2
|
+
* @preserve
|
|
3
|
+
*
|
|
4
|
+
* @module iframe-resizer/child 6.0.0-beta.6 (esm) - 2026-04-10
|
|
5
|
+
*
|
|
6
|
+
* @license GPL-3.0 For use with GPL compliant sites (fully published front & backend source code)
|
|
7
|
+
* Alternatively for commercial use, you can purchase a license from
|
|
8
|
+
* https://iframe-resizer.com/pricing
|
|
9
|
+
*
|
|
10
|
+
* @description Keep same and cross domain iframes sized to their content
|
|
11
|
+
*
|
|
12
|
+
* @author David J. Bradshaw <info@iframe-resizer.com>
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://iframe-resizer.com}
|
|
15
|
+
*
|
|
16
|
+
* @copyright (c) 2013 - 2026, David J. Bradshaw. All rights reserved.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@iframe-resizer/common"),require("auto-console-group")):"function"==typeof define&&define.amd?define(["@iframe-resizer/common","auto-console-group"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).common,e.acg)}(this,function(e,t){"use strict";let n=!0,o=e.LABEL;const r=e.esModuleInterop(t)({label:`${e.LABEL}(child)`,expand:!1});const i=e=>(...t)=>!n||r[e](...t),a=i("log"),s=a,c=i("debug");const{assert:d,endAutoGroup:l,error:u,errorBoundary:f,event:g,label:m,purge:h,warn:E}=r,I=e.createFormatAdvise(e.id),p=(...e)=>r.warn(...e.map(I)),T=e.deprecate((e,t)=>p(t));T("Method"),T("Method","replaced with"),T("Option");const O=[];function R(e,n){a(`${e} event listener: %c${n}`,t.HIGHLIGHT)}const H=(e,t,n,o)=>{e.removeEventListener(t,n,o),R("Removed",t)},S=(e,t,n,o=!1)=>{e.addEventListener(t,n,o),O.push(()=>H(e,t,n,o)),R("Added",t)},b={applySelectors:null,firstRun:!0,hasTags:!1,hasOverflow:!1,height:0,isHidden:!1,initLock:!0,inPageLinks:{},origin:void 0,hasOverflowUpdated:!0,overflowedNodeSet:new Set,sameOrigin:!1,taggedElements:[],target:window?.parent,timerActive:!1,totalTime:0,triggerLocked:!1,width:0,win:window,onPageInfo:null,onParentInfo:null};let y=!1;function w(t){const n=window?.iframeResizer?.targetOrigin||"*",o=Array.isArray(n)?n:[n];for(const r of o)t.postMessage(e.CHILD_READY_MESSAGE,r)}function v(){if("loading"===document.readyState||!b.firstRun||y)return;const{parent:e,top:n}=window;g("ready"),a("Sending%c ready%c to parent from",t.HIGHLIGHT,t.FOREGROUND,window.location.href),w(e),e!==n&&w(n),y=!0}const G="iframeResize",N=["min-height","min-width","max-height","max-width"],A=new Set,L=e=>e.tagName?e.tagName.toLowerCase():"unknown",M=(e,t)=>window.getComputedStyle(e).getPropertyValue(t),$=(t,n)=>{return!!(o=M(t,n))&&"0px"!==o&&o!==e.AUTO&&o!==e.NONE;var o};function z({href:e}){A.has(e)||(a("Unable to access stylesheet:",e),A.add(e))}const _=(e,t)=>function(e,t){const n=e.style.getPropertyValue(t);return n?{source:"an inline style attribute",value:n}:null}(e,t)||function(e,t){for(const o of document.styleSheets)try{for(const n of o.cssRules||[]){if(!("selectorText"in n))continue;const r=n;if(!e.matches(r.selectorText))continue;const i=r.style.getPropertyValue(t);if(!i)continue;const{ownerNode:a}=o;return{source:a instanceof Element&&"STYLE"===a.tagName?"an inline <style> block":`stylesheet (${o.href})`,value:i}}}catch(n){z(o)}return{source:"cross-origin stylesheet",value:M(e,t)}}(e,t),k=(e,t)=>{const{source:n,value:o}=_(e,t),r=L(e);p(`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 D(){for(const e of[document.documentElement,document.body])for(const t of N)a(`Checking <${L(e)}> for blocking CSS: ${t}`),$(e,t)&&k(e,t)}const C={autoResize:!0,bodyBackground:"",bodyMargin:0,bodyMarginStr:"",bodyPadding:"",calculateHeight:!0,calculateWidth:!1,heightCalcMode:e.AUTO,ignoreSelector:"",inPageLinks:!1,logging:!1,logExpand:!1,mode:0,mouseEvents:!1,offsetHeight:0,offsetWidth:0,parentId:void 0,sizeSelector:"",targetOrigin:"*",tolerance:0,widthCalcMode:e.AUTO,onBeforeResize:void 0,onMessage:()=>{E("onMessage function not defined")},onReady:()=>{}};function P(){try{b.sameOrigin=1===C.mode||"iframeParentListener"in window.parent}catch(e){a("Cross domain iframe detected")}}let B=0;function F(){const n=document.querySelectorAll(`*[${e.IGNORE_ATTR}]`),o=n.length>0;return o&&n.length!==B&&(!function(n){const o=1===n.length?"":"s";E(`%c[${e.IGNORE_ATTR}]%c found on %c${n.length}%c element${o}`,t.BOLD,t.NORMAL,t.BOLD,t.NORMAL)}(n),B=n.length),o}function U(o,r,i){(!e.isDef(i)||r>-1&&o>r)&&(function(o,r){console.info(`%ciframe-resizer ${o}`,n||r<1?e.BOLD:t.NORMAL)}(`v${e.VERSION} (${e.getModeLabel(o)})`,o),0===o&&((...e)=>{console.warn(...e.map(I))})(e.getModeData(3)))}function x(){"BackCompat"===document.compatMode&&p("<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")}let V=!1;function W(t){"complete"===document.readyState?e.isolateUserCode(t):V||S(document,e.READY_STATE_CHANGE,()=>W(t)),V=!0}const Z=()=>{s(`Set targetOrigin for parent: %c${C.targetOrigin}`,t.HIGHLIGHT),!0!==C.autoResize&&a("Auto Resize disabled")};function q(){b.taggedElements=document.querySelectorAll(`[${e.SIZE_ATTR}]`),b.hasTags=b.taggedElements.length>0,a(`Tagged elements found: %c${b.hasTags}`,t.HIGHLIGHT)}function j({version:t}){t&&""!==t&&t!==e.FALSE?t!==e.VERSION&&p((t=>`<b>Version mismatch</>\n\nThe parent and child pages are running different versions of <i>iframe resizer</>.\n\nParent page: ${t} - Child page: ${e.VERSION}.\n`)(t)):p("<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")}const Y=e.once(()=>p(e.getModeData(4)));function Q(n,o){const{mode:r}=C,{sameOrigin:i,target:s}=b;if(i)try{window.parent.iframeParentListener(e.MESSAGE_ID+n)}catch(c){if(!e.checkMode(r))throw new Error(c);return Y(),!1}else{d(s,"Internal error: postMessage target is undefined");const r=function(e){return void 0===e?e=C.targetOrigin:a(`Message targetOrigin: %c${e}`,t.HIGHLIGHT),e}(o),i=Array.isArray(r)?r:[r];for(const t of i)s.postMessage(e.MESSAGE_ID+n,t)}return!0}function J(n,o,r,i,c){const{parentId:d}=C,{sameOrigin:l}=b,u=`${d}:${`${n}:${o}`}:${r}${void 0===i?"":`:${i}`}`;if(C.mode<-1)return;Q(u,c)&&(!function(n){if(!b.timerActive)return;const o=e.round(performance.now()-b.totalTime),r=n===e.INIT?`Initialised iframe in %c${o}ms`:`Size calculated in %c${o}ms`;a(r,t.HIGHLIGHT)}(r),s(`Sending message to parent page via ${l?"sameOrigin":"postMessage"}: %c%c${u}`,t.ITALIC,t.HIGHLIGHT))}const K=f((e,t,n,o,r)=>{g(n),J(e,t,n,o,r),l()}),X=e=>K(0,0,e.type,`${e.screenY}:${e.screenX}`);function ee(e,n){a(`Add event listener: %c${n}`,t.HIGHLIGHT),S(window.document,e,X)}function te({persisted:t}){t||K(0,0,e.BEFORE_UNLOAD),g(e.PAGE_HIDE),s("Page persisted:",t),t||O.forEach(e.invoke)}const ne=()=>S(window,e.lower(e.PAGE_HIDE),te),oe=(e,t)=>!(Math.abs(e-t)<=C.tolerance);const re=[t.HIGHLIGHT,t.FOREGROUND,t.HIGHLIGHT],ie={height:0,width:0},ae={height:0,width:0};function se(e,t,n){return ae[e]=t,ie[e]=n,t}function ce(n){const{hasOverflow:o,hasTags:r,triggerLocked:i}=b,a=n.label,c=a===e.HEIGHT,d=n.boundingClientRect(),l=Math.ceil(d),u=Math.floor(d),f=(e=>e.documentElementScroll()+Math.max(0,e.getOffset()))(n),g=`HTML: %c${d}px %cPage: %c${f}px`;let m;switch(!0){case!n.enabled():return Math.max(f,e.MIN_SIZE);case r:s("Found element with data-iframe-size attribute"),m=n.taggedElement();break;case!o&&b.firstRun&&0===ae[a]&&0===ie[a]:s(`Initial page size values: ${g}`,...re),m=se(a,d,f);break;case i&&d===ae[a]&&f===ie[a]:s(`Size unchanged: ${g}`,...re),m=Math.max(d,f);break;case 0===d&&0!==f:s(`Page is hidden: ${g}`,...re),m=f;break;case!o&&d!==ae[a]&&f<=ie[a]:s(`New <html> size: ${g} `,...re),s(`Previous <html> size: %c${ae[a]}px`,t.HIGHLIGHT),m=se(a,d,f);break;case!c:m=n.taggedElement();break;case!o&&d<ae[a]:s(`<html> size decreased: ${g}`,...re),m=se(a,d,f);break;case f===u||f===l:s(`<html> size equals page size: ${g}`,...re),m=se(a,d,f);break;case d>f:s(`Page size < <html> size: ${g}`,...re),m=se(a,d,f);break;case o:s("Found elements possibly overflowing <html> "),m=n.taggedElement();break;default:s(`Using <html> size: ${g}`,...re),m=se(a,d,f)}return s(`Content ${a}: %c${m}px`,t.HIGHLIGHT),m+=function(e){const n=e.getOffset();return 0!==n&&s(`Page offsetSize: %c${n}px`,t.HIGHLIGHT),n}(n),Math.max(m,e.MIN_SIZE)}const de="--ifr-start",le="--ifr-end",ue="--ifr-measure",fe=[];let ge,me={},he=0;function Ee(){try{performance.clearMarks(de),performance.clearMarks(le),performance.clearMeasures(ue)}catch{}}function Ie(e){e.getEntries().forEach(e=>{if(e.name===le)try{const{duration:t}=performance.measure(ue,de,le);me=e.detail,fe.push(t),fe.length>100&&fe.shift()}catch{}})}function pe(){s("Attached%c PerformanceObserver%c to page",t.HIGHLIGHT,t.FOREGROUND);const n=new PerformanceObserver(Ie);return n.observe({entryTypes:["mark"]}),ge=setInterval(()=>{if(fe.length<10)return;if(me.hasTags&&me.len<25)return;fe.sort();const t=Math.min(fe.reduce((e,t)=>e+t,0)/fe.length,fe[Math.floor(fe.length/2)]),n=e.round(t);n>he&&(he=n,g("performanceObserver"),a("Mean time:",e.round(fe[Math.floor(fe.length/2)])),a("Median time:",e.round(fe.reduce((e,t)=>e+t,0)/fe.length)),a("Average time:",n),a("Max time:",e.round(Math.max(...fe)))),Ee(),t<=4||(clearInterval(ge),p(`<rb>Performance Warning</>\n\nCalculating the page size is taking an excessive amount of time (${e.round(t)}ms).\n\nTo improve performance add the <b>data-iframe-size</> attribute to the ${me.Side.toLowerCase()} most element on the page. For more details see: <u>https://iframe-resizer.com/perf</>.`))},5e3),{disconnect:()=>{Ee(),clearInterval(ge),n.disconnect(),s("Detached%c PerformanceObserver",t.HIGHLIGHT)}}}const Te=`* ${Array.from(e.IGNORE_TAGS).map(e=>`:not(${e})`).join("")}`,Oe=e=>e.querySelectorAll(Te);function Re(n){performance.mark(de);const o=e.capitalizeFirstLetter(n),{logging:r}=C,{hasTags:i}=b,a=function(){const{hasOverflow:e,hasTags:t,overflowedNodeSet:n,taggedElements:o}=b;return t?o:e?Array.from(n):Oe(document.documentElement)}(),{maxEl:c,maxVal:d}=function(t,n){const o=`margin-${n}`;let r,i=document.documentElement,a=b.hasTags?e.MIN_SIZE:document.documentElement.getBoundingClientRect().bottom;for(const e of t)r=e.getBoundingClientRect()[n]+parseFloat(getComputedStyle(e).getPropertyValue(o)),r>a&&(a=r,i=e);return{maxEl:i,maxVal:a}}(a,n);return s(`${o} position calculated from:`,c),s(`Checked %c${a.length}%c elements`,t.HIGHLIGHT,t.FOREGROUND),performance.mark(le,{detail:{hasTags:i,len:a.length,logging:r,Side:o}}),d}const He={label:e.HEIGHT,enabled:()=>C.calculateHeight,getOffset:()=>C.offsetHeight,auto:()=>ce(He),boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().bottom,document.body.getBoundingClientRect().bottom),documentElementScroll:()=>document.documentElement.scrollHeight,taggedElement:()=>Re(e.HEIGHT_EDGE)},Se={label:e.WIDTH,enabled:()=>C.calculateWidth,getOffset:()=>C.offsetWidth,auto:()=>ce(Se),boundingClientRect:()=>Math.max(document.documentElement.getBoundingClientRect().right,document.body.getBoundingClientRect().right),documentElementScroll:()=>document.documentElement.scrollWidth,taggedElement:()=>Re(e.WIDTH_EDGE)};const be=(t,n)=>(o,r)=>{const i=t[o]();return t.enabled()&&void 0!==C.onBeforeResize?function(t,n,o){const r=C.onBeforeResize(t,n,o);if(void 0===r)throw new TypeError("No value returned from onBeforeResize(), expected a numeric value");if(Number.isNaN(r))throw new TypeError(`Invalid value returned from onBeforeResize(): ${r}, expected Number`);if(r<e.MIN_SIZE)throw new RangeError(`Out of range value returned from onBeforeResize(): ${r}, must be at least ${e.MIN_SIZE}`);return r}(i,r,n):i},ye=be(He,e.HEIGHT),we=be(Se,e.WIDTH);function ve(n,o,r,i){const{heightCalcMode:c,widthCalcMode:d}=C;0===window.scrollY&&0===window.scrollX||(s("Reset iframe scroll position to (0, 0)"),window.scrollTo(0,0));const l=r??ye(c,n),u=i??we(d,n),f=function(e,t){const{calculateHeight:n,calculateWidth:o}=C,{height:r,width:i}=b;return n&&oe(r,e)||o&&oe(i,t)}(l,u)?e.SIZE_CHANGE_DETECTED:n;switch(a(`Resize event: %c${o}`,t.HIGHLIGHT),f){case e.INIT:case e.ENABLE:case e.SIZE_CHANGE_DETECTED:case e.MANUAL_RESIZE_REQUEST:case e.PARENT_RESIZE_REQUEST:b.height=l,b.width=u;case e.SET_OFFSET_SIZE:return b;case e.OVERFLOW_OBSERVER:case e.MUTATION_OBSERVER:case e.RESIZE_OBSERVER:case e.VISIBILITY_OBSERVER:a(e.NO_CHANGE);break;default:s(e.NO_CHANGE)}return null}let Ge=!1,Ne=!1,Ae=null;const Le=f(function(n,o,r,i,d){const{autoResize:u}=C,{isHidden:f}=b;switch(g(n),!0){case!0===f&&!(n in e.IGNORE_DISABLE_RESIZE):if(!0===Ne)break;a("Iframe hidden - Ignored resize request"),Ne=!0,Ge=!1,cancelAnimationFrame(Ae),Ae=null;break;case!0===Ge&&n!==e.OVERFLOW_OBSERVER&&!(n in e.IGNORE_DISABLE_RESIZE):a("Resize already pending - Ignored resize request");break;case!u&&!(n in e.IGNORE_DISABLE_RESIZE):s("Resizing disabled");break;default:{Ne=!1,Ge=!0,b.totalTime=performance.now(),b.timerActive=!0;const e=ve(n,o,r,i);e&&J(e.height,e.width,n,d),Ae||(Ae=requestAnimationFrame(()=>{Ge=!1,Ae=null,g("requestAnimationFrame"),c(`Reset sendPending: %c${n}`,t.HIGHLIGHT)})),b.timerActive=!1}}l()});function Me({eventType:e,eventName:t}){S(window,t,()=>Le(t,e),{passive:!0})}function $e(){Me({eventType:"After Print",eventName:"afterprint"}),Me({eventType:"Before Print",eventName:"beforeprint"})}function ze(e){const{heightCalcMode:n,widthCalcMode:o}=C,r=He[n](),i=Se[o]();a(`Reset trigger event: %c${e}`,t.HIGHLIGHT),K(r,i,e)}function _e(n){const o=C.heightCalcMode;a(`Reset trigger event: %c${n}`,t.HIGHLIGHT),C.heightCalcMode=e.HEIGHT_CALC_MODE_DEFAULT,b.triggerLocked?a("TriggerLock blocked calculation"):(b.triggerLocked=!0,c("Trigger event lock on"),requestAnimationFrame(()=>{b.triggerLocked=!1,c("Trigger event lock off")})),ze("reset"),C.heightCalcMode=o}const ke=`Auto Resize can not be changed when <b>direction</> is set to '${e.NONE}'.`;function De(t){e.typeAssert(t,e.BOOLEAN,"parentIframe.autoResize(enable) enable");const{autoResize:n,calculateHeight:o,calculateWidth:r}=C;return!1===r&&!1===o?(g(e.ENABLE),p(ke),!1):(!0===t&&!1===n?(C.autoResize=!0,queueMicrotask(()=>Le(e.ENABLE,"Auto Resize enabled"))):!1===t&&!0===n&&(C.autoResize=!1),K(0,0,e.AUTO_RESIZE,JSON.stringify(C.autoResize)),C.autoResize)}function Ce(t){e.typeAssert(t,e.STRING,"parentIframe.moveToAnchor(anchor) anchor"),b.inPageLinks.findTarget(t)}function Pe(t){e.typeAssert(t,e.NUMBER,"parentIframe.setOffsetSize(offset) offset"),C.offsetHeight=t,C.offsetWidth=t,Le(e.SET_OFFSET_SIZE,`parentIframe.setOffsetSize(${t})`)}const Be=()=>b.origin;function Fe(n){e.typeAssert(n,e.STRING,"parentIframe.setTargetOrigin(targetOrigin) targetOrigin"),a(`Set targetOrigin: %c${n}`,t.HIGHLIGHT),C.targetOrigin=n}function Ue(t){return e.typeAssert(t,e.FUNCTION,"parentIframe.getParentProps(callback) callback"),b.onParentInfo=t,K(0,0,e.PARENT_INFO),()=>{b.onParentInfo=null,K(0,0,e.PARENT_INFO_STOP)}}function xe(t,n){void 0!==t&&e.typeAssert(t,e.NUMBER,"parentIframe.resize(customHeight, customWidth) customHeight"),void 0!==n&&e.typeAssert(n,e.NUMBER,"parentIframe.resize(customHeight, customWidth) customWidth");const o=`${void 0===t?"":t}${void 0===n?"":`,${n}`}`;Le(e.MANUAL_RESIZE_REQUEST,`parentIframe.resize(${o})`,t,n)}const Ve=t=>(n,o)=>{e.typeAssert(n,e.NUMBER,`parentIframe.${t}(x, y) x`),e.typeAssert(o,e.NUMBER,`parentIframe.${t}(x, y) y`),K(o,n,t)},We=Ve(e.SCROLL_BY),Ze=Ve(e.SCROLL_TO),qe=Ve(e.SCROLL_TO_OFFSET);function je(t,n){n&&e.typeAssert(n,e.STRING,"parentIframe.sendMessage(msg, targetOrigin) targetOrigin"),K(0,0,e.MESSAGE,JSON.stringify(t),n)}const Ye=()=>K(0,0,e.CLOSE),Qe=()=>C.parentId,Je=()=>_e("parentIframe.reset");const Ke=(t="")=>n=>o=>{o.size>0&&c(`${n}Observer ${t}:`,...Array.from(o).flatMap(t=>[e.NEW_LINE,t]))},Xe=Ke("attached to"),et=((t="")=>n=>o=>{o.size>0&&u(`${n}Observer ${t}:`,...Array.from(o).flatMap(t=>[e.NEW_LINE,t]))})("already attached"),tt=Ke("detached from"),nt=(e,n=!0)=>o=>{o>0&&s(`${n?"At":"De"}tached %c${e}Observer%c ${n?"to":"from"} %c${o}%c element${1===o?"":"s"}`,t.HIGHLIGHT,t.NORMAL,t.HIGHLIGHT,t.NORMAL)},ot=(e,t,n,o)=>{const r=tt(e);return e=>{const i=new Set;let a=0;for(const o of e)n.has(o)&&(t.unobserve(o),n.delete(o),i.add(o),a+=1);r(i),o(a),i.clear()}},rt="Mutation",it=new Set,at=new Set,st=new Set,ct=[],dt={attributes:!0,attributeFilter:[e.IGNORE_ATTR,e.SIZE_ATTR],attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0};let lt,ut=1,ft=!1,gt=0;const mt=Ke("added")(rt),ht=Ke("removed (page)")(rt),Et=Ke("removed (added)")(rt),It=t=>t.nodeType!==Node.ELEMENT_NODE||e.IGNORE_TAGS.has(t.tagName.toLowerCase());function pt(e){const t=e.addedNodes;for(const n of t)It(n)||it.add(n)}function Tt(e){const t=e.removedNodes;for(const n of t)It(n)||(it.has(n)?(it.delete(n),st.add(n)):at.add(n))}const Ot=e=>{s("Mutations:",e);for(const t of e)pt(t),Tt(t);mt(it),ht(at),Et(st),st.clear()};const Rt=n=>()=>{const o=performance.now(),r=o-gt,i=16*ut+++2;if(r>i&&r<200)return g("mutationThrottled"),s("Update delayed due to heavy workload on the callStack"),s(`EventLoop busy time: %c${e.round(r)}ms %c> Max wait: %c${i-2}ms`,t.HIGHLIGHT,t.FOREGROUND,t.HIGHLIGHT),setTimeout(lt,16*ut),void(gt=o);ut=1,ct.forEach(Ot),ct.length=0,ft=!1,at.size>0&&a(`Detected %c${at.size} %cremoved element${at.size>1?"s":""}`,t.HIGHLIGHT,t.FOREGROUND),it.size>0&&a(`Found %c${it.size} %cnew element${it.size>1?"s":""}`,t.HIGHLIGHT,t.FOREGROUND),n({addedNodes:it,removedNodes:at}),it.clear(),at.clear()};function Ht(e){ct.push(e),ft||(gt=performance.now(),ft=!0,requestAnimationFrame(lt))}function St(e){const n=new window.MutationObserver(Ht),o=document.body||document.documentElement;return lt=Rt(e),n.observe(o,dt),s("Attached%c MutationObserver%c to body",t.HIGHLIGHT,t.FOREGROUND),{disconnect:()=>{it.clear(),at.clear(),ct.length=0,n.disconnect(),s("Detached%c MutationObserver",t.HIGHLIGHT)}}}const bt={characterData:!0,childList:!0,subtree:!0};function yt(e){const n=document.querySelector("title")??document.head??document.documentElement,o=new MutationObserver(e);return o.observe(n,bt),s("Attached%c TitleObserver%c to head",t.HIGHLIGHT,t.FOREGROUND),setTimeout(e),{disconnect:()=>{o.disconnect(),s("Detached%c TitleObserver",t.HIGHLIGHT)}}}function wt(e){const n=new IntersectionObserver(t=>e(t.at(-1)?.isIntersecting??!1),{threshold:0}),o=document.documentElement;return n.observe(o),s("Attached%c VisibilityObserver%c to page",t.HIGHLIGHT,t.FOREGROUND),{disconnect:()=>{n.disconnect(),s("Detached%c VisibilityObserver",t.HIGHLIGHT)}}}let vt=new Set;function Gt(){const t=function(t){const n=new Set,o=new Set;for(const r of t)r.closest(`[${e.IGNORE_ATTR}]`)?o.add(r):n.add(r);return o.size>0&&queueMicrotask(()=>{g("overflowIgnored"),s("Ignoring elements with [data-iframe-ignore] > *:\n",o),l()}),n}(document.querySelectorAll(`[${e.OVERFLOW_ATTR}]`));let n=!0;return typeof Set.prototype.symmetricDifference===e.FUNCTION&&(n=t.symmetricDifference(vt).size>0),vt=t,b.overflowedNodeSet=t,b.hasOverflow=t.size>0,{hasOverflowUpdated:n,overflowedNodeSet:t}}const Nt={},At=e=>{const t=new Set;for(const n of e)if(n instanceof Element){t.add(n);for(const e of Oe(n))t.add(e)}return s("Inspecting:\n",t),t};function Lt({addedNodes:e,removedNodes:t}){g("contentMutated"),b.applySelectors(),q(),Gt(),l(),(e=>{if(0===e.size)return;g("removeObservers");const t=At(e);Nt.overflow.detachObservers(t),Nt.resize.detachObservers(t),l()})(t),(e=>{if(0===e.size)return;g("addObservers");const t=At(e);Nt.overflow.attachObservers(t),Nt.resize.attachObserverToNonStaticElements(t),l()})(e)}function Mt(t){Lt(t),Le(e.MUTATION_OBSERVER,"Mutation Observed")}const $t="Overflow",zt=nt($t),_t=nt($t,!1),kt=Xe($t),Dt=et($t),Ct=t=>t instanceof HTMLElement&&(!!t.hidden||null===t.offsetParent||t.style.display===e.NONE);function Pt(){const{hasOverflow:t}=b,{hasOverflowUpdated:n,overflowedNodeSet:o}=Gt();switch(!0){case!n:return;case o.size>1:s("Overflowed Elements:",o);break;case t:break;default:s("No overflow detected")}Le(e.OVERFLOW_OBSERVER,"Overflow updated")}function Bt(n){const o={root:document.documentElement,side:C.calculateHeight?e.HEIGHT_EDGE:e.WIDTH_EDGE};return Nt.overflow=((n,o)=>{const r=o.side||e.HEIGHT_EDGE,i={root:o.root,rootMargin:"0px",threshold:1},a=window?.requestAnimationFrame||e.id,c=(e=!1)=>n(e),d=(e,t)=>0===e||e>t[r],l=(t,n)=>{t.toggleAttribute(e.OVERFLOW_ATTR,n)},u=new IntersectionObserver(function(e){for(const t of e){const{boundingClientRect:e,rootBounds:n,target:o}=t;if(!n)continue;const i=e[r],a=d(i,n)&&!(o instanceof HTMLElement&&Ct(o));l(o,a)}a(c)},i),f=new WeakSet;return{attachObservers:function(e){const t=new Set,n=new Set;let o=0;for(const r of e)r instanceof Element&&(f.has(r)?t.add(r):(u.observe(r),f.add(r),n.add(r),o+=1));Dt(t),kt(n),zt(o),n.clear(),t.clear()},detachObservers:ot($t,u,f,_t),disconnect:()=>{u.disconnect(),s("Detached%c OverflowObserver",t.HIGHLIGHT)}}})(Pt,o),Nt.overflow.attachObservers(n),Nt.overflow}const Ft="Resize",Ut=nt(Ft),xt=nt(Ft,!1),Vt=Xe(Ft),Wt=et(Ft),Zt=new WeakSet,qt=new Set,jt=new Set;let Yt;function Qt(e){let t=0;for(const n of e){if(!(n instanceof Element))continue;const e=getComputedStyle(n)?.position;""!==e&&"static"!==e&&(Zt.has(n)?qt.add(n):(Yt.observe(n),Zt.add(n),jt.add(n),t+=1))}Wt(qt),Vt(jt),Ut(t),jt.clear(),qt.clear()}function Jt(t){if(!Array.isArray(t)||0===t.length)return;const n=t[0].target;Le(e.RESIZE_OBSERVER,`Element resized <${e.getElementName(n)}>`)}function Kt(e){return Nt.resize=(Yt=new ResizeObserver(Jt),Yt.observe(document.body),Zt.add(document.body),s("Attached%c ResizeObserver%c to body",t.HIGHLIGHT,t.FOREGROUND),{attachObserverToNonStaticElements:Qt,detachObservers:ot(Ft,Yt,Zt,xt),disconnect:()=>{Yt.disconnect(),s("Detached%c ResizeObserver",t.HIGHLIGHT)}}),Nt.resize.attachObserverToNonStaticElements(e),Nt.resize}let Xt;function en(){const n=document.title;n!==Xt&&(Xt=n,a(`Title: %c${n}`,t.HIGHLIGHT),n&&K(0,0,e.TITLE,n))}function tn(n){a(`Visible: %c${n}`,t.HIGHLIGHT),b.isHidden=!n,Le(e.VISIBILITY_OBSERVER,"Visibility changed")}function nn(){g("attachObservers");const e=Oe(document.documentElement);!function(e){O.push(...e.map(e=>e.disconnect))}([St(Mt),Bt(e),pe(),Kt(e),yt(en),wt(tn)])}const on=(e,n,o)=>{if(""!==o){a(`${e}: %c${o}`,t.HIGHLIGHT);for(const e of document.querySelectorAll(o))a(`Applying ${n} to:`,e),e.toggleAttribute(n,!0)}};function rn(){const e=document.createElement("div");e.style.clear="both",e.style.display="block",e.style.height="0",document.body.append(e)}function an(n,o){void 0!==o&&""!==o&&o!==e.NULL&&(document.body.style.setProperty(n,o),s(`Set body ${n}: %c${o}`,t.HIGHLIGHT))}function sn({bodyMarginStr:e,bodyMargin:t}){var n,o;void 0===e&&(e=`${t}px`),an("margin",(n="margin",(o=e).includes("-")&&(E(`Negative CSS value ignored for ${n}`),o=""),o))}function cn(e){const t=e.getBoundingClientRect(),n={x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop};return{x:Math.round(t.left+n.x),y:Math.round(t.top+n.y)}}function dn(n){const o=n.split("#")[1]||n,r=decodeURIComponent(o),i=document.getElementById(r)||document.getElementsByName(r)[0];void 0===i?(a(`In page link (#${o}) not found in iframe, so sending to parent`),K(0,0,e.IN_PAGE_LINK,`#${o}`)):function(n,o){const r=cn(o);a(`Moving to in page link (%c#${n}%c) at x: %c${r.x}%c y: %c${r.y}`,t.HIGHLIGHT,t.FOREGROUND,t.HIGHLIGHT,t.FOREGROUND,t.HIGHLIGHT),K(r.y,r.x,e.SCROLL_TO_OFFSET)}(o,i)}function ln(){const{hash:e,href:t}=window.location;""!==e&&"#"!==e&&dn(t)}function un(){a("Setting up location.hash handlers"),function(){for(const e of document.querySelectorAll('a[href^="#"]'))"#"!==e.getAttribute("href")&&S(e,"click",t=>{t.preventDefault(),dn(e.getAttribute("href"))})}(),S(window,"hashchange",ln),setTimeout(ln,e.EVENT_CANCEL_TIMER),b.inPageLinks={findTarget:dn}}function fn(){const n=t=>t.style.setProperty(e.HEIGHT,e.AUTO,"important");n(document.documentElement),n(document.body),a("Set HTML & body height: %cauto !important",t.HIGHLIGHT)}const gn=e=>(t,n)=>{if(n in t){if(typeof t[n]===e)return t[n];throw new TypeError(`${n} is not a ${e}.`)}},mn=gn(e.FUNCTION),hn=gn(e.NUMBER),En=gn(e.STRING);function In(t){a("Reading data from page:",Object.keys(t));const{offsetHeight:n,offsetWidth:o}=function(t){const{calculateHeight:n,calculateWidth:o}=C;let r,i;return typeof t?.offsetSize===e.NUMBER&&(n&&(r=hn(t,e.OFFSET_SIZE)),o&&(i=hn(t,e.OFFSET_SIZE))),{offsetHeight:r,offsetWidth:i}}(t);return{offsetHeight:n,offsetWidth:o,ignoreSelector:En(t,"ignoreSelector"),[e.getKey(3)]:En(t,e.getKey(0)),sizeSelector:En(t,"sizeSelector"),targetOrigin:En(t,"targetOrigin"),onBeforeResize:mn(t,"onBeforeResize"),onMessage:mn(t,"onMessage"),onReady:mn(t,"onReady")}}function pn(){const{mode:t}=C;if(e.checkMode(t))return{};const n=window.iframeResizer||window.iFrameResizer;return null===(o=n)||typeof o!==e.OBJECT||Array.isArray(o)?{}:In(n);var o}const Tn=e=>t=>void 0===t?void 0:e(t),On=Tn(e=>"true"===e),Rn=Tn(Number);function Hn(e){for(const[t,n]of Object.entries(e))void 0!==n&&(C[t]=n)}function Sn({logExpand:t,logging:i,parentId:s=""}){var c;o=(c={id:s,enabled:i,expand:t}).id||e.LABEL,r.label(`${o}`),r.expand(c.expand),n=c.enabled,g("initReceived"),a(`Initialising iframe v${e.VERSION} ${window.location.href}`)}function bn(t){g("ready"),W(e.once(t)),a("Initialization complete",(({key:e,key2:t,...n})=>n)(C))}function yn({bodyBackground:t,bodyPadding:n,inPageLinks:o,onReady:r}){const i=(({calculateWidth:e,calculateHeight:t})=>e===t)(C),s=[F,P,x,q,Z,i?e.id:D,()=>sn(C),()=>an("background",t),()=>an("padding",n),i?e.id:fn,rn,b.applySelectors,()=>function(t){const{mode:n}=C;t?e.checkMode(n)?p(e.getModeData(5)):un():a("In page linking not enabled")}(o),$e,()=>function({mouseEvents:t}){!0===t&&(ee(e.MOUSE_ENTER,"Mouse Enter"),ee(e.MOUSE_LEAVE,"Mouse Leave"))}(C),ne,()=>function(){const{win:e}=b;1!==C.mode&&(e.parentIframe=Object.freeze({autoResize:De,close:Ye,getId:Qe,getParentOrigin:Be,getParentProps:Ue,moveToAnchor:Ce,reset:Je,setOffsetSize:Pe,scrollBy:We,scrollTo:Ze,scrollToOffset:qe,sendMessage:je,setTargetOrigin:Fe,resize:xe}))}(),()=>Le(e.INIT,"Init message from host page",void 0,void 0,`${e.VERSION}:${C.mode}`),nn,l];j(C),function({key:t,key2:n,mode:o,version:r}){const i=o,a=e.isDef(t)?e.setMode({key:t}):-1,s=e.isDef(n)?e.setMode({key:n}):-1;let c;switch(o=Math.max(a,s)){case-2:case-1:c=`${e.getModeData(Math.min(a,s)+2)}${e.getModeData(2)}`,b.firstRun=!1;break;case 1:case 2:case 3:c=e.getModeData(6);break;case 4:c=e.getModeData(7);break;case 5:c=e.getModeData(8)}if(o>=0&&U(o,i,r),(!e.isDef(r)||!b.firstRun)&&(c&&p(c),o<0))throw p(e.getModeData(9)),c.split("<br>")[0].replace(/<\/?[a-z][^>]*>|<\/>/gi,"");C.mode=o}(C),function(e){const{mode:t}=C;e.forEach(e=>{try{e()}catch(n){if(t<0)throw n;p("<rb>Error in setup function</>\n<i>iframe-resizer</> detected an error during setup.\n\nPlease report the following error message at <u>https://github.com/davidjbradshaw/iframe-resizer/issues</>"),u(n)}})}(s),bn(r)}function wn(t){b.firstRun&&(Hn((e=>({parentId:e[0],bodyMargin:Rn(e[1]),calculateWidth:On(e[2]),logging:On(e[3]),autoResize:On(e[6]),bodyMarginStr:e[7],bodyBackground:e[9],bodyPadding:e[10],tolerance:Rn(e[11]),inPageLinks:On(e[12]),mouseEvents:On(e[15]),offsetHeight:Rn(e[16]),offsetWidth:Rn(e[17]),calculateHeight:On(e[18]),key:e[19],version:e[20],mode:Rn(e[21]),logExpand:On(e[23])}))(t)),Sn(C),Hn(pn()),b.applySelectors=function({sizeSelector:t,ignoreSelector:n}){return()=>{on("sizeSelector",e.SIZE_ATTR,t),on("ignoreSelector",e.IGNORE_ATTR,n)}}(C),yn(C))}const{freeze:vn}=Object,{parse:Gn}=JSON,Nn=e=>vn(Gn(e)),An=e=>K(0,0,`${e}Stop`),Ln=t=>t.data.slice(t.data.indexOf(e.SEPARATOR)+1),Mn=t=>(t=>t.data.split(e.SEPARATOR)[2]in{true:1,false:1})(t)?e.INIT:t.data.split("]")[1].split(e.SEPARATOR)[0];const $n=e=>b.inPageLinks.findTarget(Ln(e)),zn={init:function(t){if("loading"===document.readyState)return void a("Page not ready, ignoring init message");const n=t.data.slice(e.MESSAGE_ID_LENGTH).split(e.SEPARATOR);b.target=t.source,b.origin=t.origin,wn(n),b.firstRun=!1,setTimeout(()=>{b.initLock=!1},e.EVENT_CANCEL_TIMER)},reset:function(){b.initLock?a("Page reset ignored by init"):(a("Page size reset by host page"),ze("resetPage"))},resize:function(){a("Resize requested by host page"),Le(e.PARENT_RESIZE_REQUEST,"Parent window requested size check")},moveToAnchor:$n,inPageLink:$n,pageInfo:function(t){const{onPageInfo:n}=b,o=Ln(t);a("PageInfo received from parent:",Nn(o)),n?e.isolateUserCode(n,Gn(o)):An(e.PAGE_INFO)},parentInfo:function(t){const{onParentInfo:n}=b,o=Nn(Ln(t));a("ParentInfo received from parent:",o),n?e.isolateUserCode(n,o):An(e.PARENT_INFO)},message:function(n){const o=Ln(n);a("onMessage called from parent:%c",t.HIGHLIGHT,Nn(o)),e.isolateUserCode(C.onMessage,Gn(o))}};function _n(e){const{firstRun:t}=b,n=Mn(e);switch(g(n),!0){case n in zn:zn[n](e);break;case t&&(G in window||void 0!==window.jQuery&&G in window.jQuery.prototype):E(`Ignored message of type "${n}". Received before initialization.`);break;default:E(`Unexpected message (${e.data}), this is likely due to a newer version of iframe-resizer running on the parent page.`)}}const kn=f(t=>{(t=>e.MESSAGE_ID===`${t.data}`.slice(0,e.MESSAGE_ID_LENGTH))(t)&&_n(t)});typeof window!==e.UNDEFINED&&function(){if("iframeChildListener"in window)E("Already setup");else{window.iframeChildListener=e=>{setTimeout(()=>kn({data:e,sameOrigin:!0}))},g("listen"),S(window,e.MESSAGE,kn),S(document,e.READY_STATE_CHANGE,v),v();try{top?.document?.getElementById("banner")&&(b.win={},window.mockMsgListener=t,H(window,e.MESSAGE,kn),"function"==typeof window.define&&window.define([],()=>t))}catch(n){}}function t(e){return kn(e),b.win}}()});
|
|
28
21
|
//# sourceMappingURL=index.umd.js.map
|