@iframe-resizer/jquery 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @preserve
3
3
  *
4
- * @module iframe-resizer/jquery 5.0.0 (umd) - 2024-05-19
4
+ * @module iframe-resizer/jquery 5.0.2 (umd) - 2024-05-30
5
5
  *
6
6
  * @license GPL-3.0 for non-commercial use only.
7
7
  * For commercial use, you must purchase a license from
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @desciption Keep same and cross domain iFrames sized to their content
11
11
  *
12
- * @author David J. Bradshaw <dave@bradshaw.net>
12
+ * @author David J. Bradshaw <info@iframe-resizer.com>
13
13
  *
14
14
  * @see {@link https://iframe-resizer.com}
15
15
  *
@@ -17,4 +17,1231 @@
17
17
  */
18
18
 
19
19
 
20
- !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";const e="5.0.0",i="[iFrameSizer]",t=i.length,n=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),o=(e,i,t,n)=>e.addEventListener(i,t,n||!1),r=(e,i,t)=>e.removeEventListener(i,t,!1),a="[iframe-resizer]";const s=e=>`${a}[${function(e){return window.top===window.self?`Parent page: ${e}`:window?.parentIFrame?.getId?`${window.parentIFrame.getId()}: ${e}`:`Nested parent page: ${e}`}(e)}]`,l=(e,i,...t)=>window?.console[e](s(i),...t),c=(e,...i)=>l("warn",e,...i),d=(e,i)=>console?.warn((e=>i=>window.chrome?e(i.replaceAll("<br>","\n").replaceAll("<rb>","").replaceAll("</>","").replaceAll("<b>","").replaceAll("<i>","").replaceAll("<u>","")):e(i.replaceAll("<br>","\n").replaceAll(/<[/a-z]+>/gi,"")))((e=>(...i)=>[`${a}[${e}]`,...i].join(" "))(e))(i)),u=e=>{if(!e)return"";let i=-559038744,t=1103547984;for(let n,o=0;o<e.length;o++)n=e.codePointAt(o),i=Math.imul(i^n,2246822519),t=Math.imul(t^n,3266489917);return i^=Math.imul(i^t>>>15,1935289751),t^=Math.imul(t^i>>>15,3405138345),i^=t>>>16,t^=i>>>16,(2097152*(t>>>0)+(i>>>11)).toString(36)},f=e=>e.replaceAll(/[A-Za-z]/g,(e=>String.fromCodePoint((e<="Z"?90:122)>=(e=e.codePointAt(0)+19)?e:e-26))),p=["<iy><yi>Puchspk Spjluzl Rlf</><iy><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</>."],h=["NWSc3","ihzpj","wyvmlzzpvuhs","ibzpulzz","vlt"],m=Object.fromEntries(["2cgs7fdf4xb","1c9ctcccr4z","1q2pc4eebgb","ueokt0969w","w2zxchhgqz","1umuxblj2e5"].map(((e,i)=>[e,Math.max(0,i-1)]))),y=e=>f(p[e]),g=e=>{const i=e[f("spjluzl")];if(!i)return-1;const t=i.split("-");let n=function(e=""){let i=-2;const t=u(f(e));return t in m&&(i=m[t]),i}(t[0]);return 0===n||(e=>e[2]===u(e[0]+e[1]))(t)||(n=-2),n},w={},b=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:"vertical",inPageLinks:!1,heightCalculationMethod:"auto",id:"iFrameResizer",log:!1,license:void 0,mouseEvents:!0,offsetHeight:null,offsetWidth:null,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 w[e.id].onInit&&(d(e.id,"\nDeprecated Option\n\nThe onInit() function is deprecated and has been replaced with onReady(). It will be removed in a future version of iFrame Resizer.\n "),w[e.id].onInit(e))},onResized(){},onScroll:()=>!0}),z={position:null,version:e};function v(n){function a(){S(L),M(),A("onResized",L)}function s(e){if("border-box"!==e.boxSizing)return 0;return(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}function l(e){if("border-box"!==e.boxSizing)return 0;return(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}function u(e){return H.slice(H.indexOf(":")+7+e)}const f=(e,i)=>(t,n)=>{const o={};var r,a;r=function(){x(`Send ${e} (${t})`,`${e}:${i()}`,n)},o[a=n]||(r(),o[a]=requestAnimationFrame((()=>{o[a]=null})))},p=(e,i)=>()=>{const t=i=>()=>{w[s]?e(i,s):a()};function n(e,i){i(window,"scroll",t("scroll")),i(window,"resize",t("resize window"))}function a(){n(0,r),l.disconnect(),c.disconnect()}const s=P,l=new ResizeObserver(t("page observed")),c=new ResizeObserver(t("iframe observed"));n(0,o),l.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),c.observe(w[s].iframe,{attributes:!0,childList:!1,subtree:!1}),w[s]&&(w[s][`stop${i}`]=a)},h=e=>()=>{e in w[P]&&(w[P][e](),delete w[P][e])},m=f("pageInfo",(function(){const e=document.body.getBoundingClientRect(),i=L.iframe.getBoundingClientRect(),{scrollY:t,scrollX:n,innerHeight:o,innerWidth:r}=window,{clientHeight:a,clientWidth:s}=document.documentElement;return JSON.stringify({iframeHeight:i.height,iframeWidth:i.width,clientHeight:Math.max(a,o||0),clientWidth:Math.max(s,r||0),offsetTop:parseInt(i.top-e.top,10),offsetLeft:parseInt(i.left-e.left,10),scrollTop:t,scrollLeft:n,documentHeight:a,documentWidth:s,windowHeight:o,windowWidth:r})})),y=f("parentInfo",(function(){const{iframe:e}=L,{scrollWidth:i,scrollHeight:t}=document.documentElement,{width:n,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:l,scale:c}=window.visualViewport;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:i,scrollHeight:t},viewport:{width:n,height:o,offsetLeft:r,offsetTop:a,pageLeft:s,pageTop:l,scale:c}})})),g=p(m,"PageInfo"),b=p(y,"ParentInfo"),v=h("stopPageInfo"),k=h("stopParentInfo");function N(e){const i=e.getBoundingClientRect();return T(),{x:Number(i.left)+Number(z.position.x),y:Number(i.top)+Number(z.position.y)}}function F(e){const i=e?N(L.iframe):{x:0,y:0};let t=((e,i)=>({x:e.width+i.x,y:e.height+i.y}))(L,i);window.top===window.self?(z.position=t,O(P)):window.parentIFrame?window.parentIFrame["scrollTo"+(e?"Offset":"")](t.x,t.y):c(P,"Unable to scroll to requested position, window.parentIFrame not found")}function O(e){const{x:i,y:t}=z.position,n=w[e]?.iframe;!1!==A("onScroll",{iframe:n,top:t,left:i,x:i,y:t})?M():$()}function C(e){let i={};if(0===L.width&&0===L.height){const e=u(9).split(":");i={x:e[1],y:e[0]}}else i={x:L.width,y:L.height};A(e,{iframe:L.iframe,screenX:Number(i.x),screenY:Number(i.y),type:L.type})}const A=(e,i)=>j(P,e,i);let H=n.data,L={},P=null;"[iFrameResizerChild]Ready"!==H?i===`${H}`.slice(0,t)&&H.slice(t).split(":")[0]in w&&(L=function(){const e=H.slice(t).split(":"),i=e[1]?Number(e[1]):0,n=w[e[0]]?.iframe,o=getComputedStyle(n);return{iframe:n,id:e[0],height:i+s(o)+l(o),width:Number(e[2]),type:e[3],version:e[4]}}(),P=L.id,P?(function(e){if(!w[e])throw new Error(`${L.type} No settings for ${e}. Message was: ${H}`)}(P),L.type in{true:1,false:1,undefined:1}||(w[P].loaded=!0,function(){let e=!0;return null===L.iframe&&(c(P,`The iframe (${L.id}) was not found.`),e=!1),e}()&&function(){const{origin:e,sameDomain:i}=n;if(i)return!0;let t=w[P]?.checkOrigin;if(t&&"null"!=`${e}`&&!(t.constructor===Array?function(){let i=0,n=!1;for(;i<t.length;i++)if(t[i]===e){n=!0;break}return n}():function(){const i=w[P]?.remoteHost;return e===i}()))throw new Error(`Unexpected message received from: ${e} for ${L.iframe.id}. Message was: ${n.data}. This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.`);return!0}()&&function(){switch(w[P]?.firstRun&&w[P]&&(w[P].firstRun=!1),L.type){case"close":R(L.iframe);break;case"message":t=u(6),A("onMessage",{iframe:L.iframe,message:JSON.parse(t)});break;case"mouseenter":C("onMouseEnter");break;case"mouseleave":C("onMouseLeave");break;case"autoResize":w[P].autoResize=JSON.parse(u(9));break;case"scrollTo":F(!1);break;case"scrollToOffset":F(!0);break;case"pageInfo":m("start",P),g();break;case"parentInfo":y("start",P),b();break;case"pageInfoStop":v();break;case"parentInfoStop":k();break;case"inPageLink":!function(e){const i=e.split("#")[1]||"",t=decodeURIComponent(i);let n=document.getElementById(t)||document.getElementsByName(t)[0];n?function(){const e=N(n);z.position={x:e.x,y:e.y},O(P)}():window.top!==window.self&&window.parentIFrame&&window.parentIFrame.moveToAnchor(i)}(u(9));break;case"reset":I(L);break;case"init":a(),function(e){try{w[e].sameDomain=!!w[e]?.iframe?.contentWindow?.iframeChildListener}catch(i){w[e].sameDomain=!1}}(P),(i=L.version)!==e&&(void 0!==i||d(P,"<rb>Legacy version detected in iframe</>\n\nDetected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.\n\nSee <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.\n")),E=!0,A("onReady",L.iframe);break;default:if(0===L.width&&0===L.height)return void c(`Unsupported message received (${L.type}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===L.width||0===L.height)return;if(document.hidden)return;a()}var i,t}())):c("iframeResizer received messageData without id, message was: ",H)):Object.keys(w).forEach((e=>{w[e].mode>=0&&x("iFrame requested init",W(e),e)}))}function j(e,i,t){let n=null,o=null;if(w[e]){if(n=w[e][i],"function"!=typeof n)throw new TypeError(`${i} on iFrame[${e}] is not a function`);o=n(t)}return o}function k(e){const i=e.id;delete w[i]}function R(e){const i=e.id;if(!1!==j(i,"onClose",i)){try{e.parentNode&&e.remove()}catch(e){c(e)}j(i,"onClosed",i),k(e)}}function T(e){null===z.position&&(z.position={x:window.scrollX,y:window.scrollY})}function $(){z.position=null}function M(e){null!==z.position&&(window.scrollTo(z.position.x,z.position.y),$())}function I(e){T(e.id),S(e),x("reset","reset",e.id)}function S(e){const i=e.id;function t(i){const t=`${e[i]}px`;e.iframe.style[i]=t}w[i].sizeHeight&&t("height"),w[i].sizeWidth&&t("width")}function x(e,t,n,o){w[n]&&(w[n]?.postMessageTarget?function(){const{postMessageTarget:e,targetOrigin:o}=w[n];if(w[n].sameDomain)try{return void w[n].iframe.contentWindow.iframeChildListener(i+t)}catch(e){w[n].sameDomain=!1}e.postMessage(i+t,o)}():c(n,`[${e}] IFrame(${n}) not found`),o&&w[n]?.warningTimeout&&(w[n].msgTimeout=setTimeout((function(){void 0!==w[n]&&(w[n].loaded||w[n].loadErrorShown||(w[n].loadErrorShown=!0,d(n,`\n<rb>No response from iFrame</>\n \nThe iframe (<i>${n}</>) has not responded within ${w[n].warningTimeout/1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.\n\nThis message can be ignored if everything is working, or you can set the <b>warningTimeout</> option to a higher value or zero to suppress this warning.\n`)))}),w[n].warningTimeout)))}function W(e){const i=w[e];return[e,"8",i.sizeWidth,i.log,"32",!0,i.autoResize,i.bodyMargin,i.heightCalculationMethod,i.bodyBackground,i.bodyPadding,i.tolerance,i.inPageLinks,"child",i.widthCalculationMethod,i.mouseEvents,i.offsetHeight,i.offsetWidth,i.sizeHeight,i.license,z.version,i.mode].join(":")}let N=0,E=!1,F=!1;const O=i=>t=>{function r(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)&&d(a,'<rb>Deprecated Option</>\n\nThe <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <i>"vertical"</>, <i>"horizontal"</> or <i>"horizontal"</>.\n'),e}const a=function(e){if(e&&"string"!=typeof e)throw new TypeError("Invalid id for iFrame. Expected String");return""!==e&&e||(t.id=e=function(){let e=i?.id||b.id+N++;return null!==document.getElementById(e)&&(e+=N++),e}(),(i||{}).log),e}(t.id);return a in w&&"iFrameResizer"in t?c(a,"Ignored iFrame, already setup."):(function(e){var i,n;w[a]={iframe:t,firstRun:!0,remoteHost:t?.src.split("/").slice(0,3).join("/"),...b,...r(e),mode:g(e)},function(){if("horizontal"===w[a].direction)return w[a].sizeWidth=!0,void(w[a].sizeHeight=!1);if("none"===w[a].direction)return w[a].sizeWidth=!1,w[a].sizeHeight=!1,void(w[a].autoResize=!1);if("vertical"!==w[a].direction)throw new TypeError(a,`Direction value of "${w[a].direction}" is not valid`)}(),i=e?.offset,i&&("vertical"===w[a].direction?w[a].offsetHeight=i:w[a].offsetWidth=i),null===w[a].postMessageTarget&&(w[a].postMessageTarget=t.contentWindow),w[a].targetOrigin=!0===w[a].checkOrigin?""===(n=w[a].remoteHost)||null!==n.match(/^(about:blank|javascript:|file:\/\/)/)?"*":n:"*"}(i),function(){const{mode:i}=w[a];i<0&&d("Parent",`${y(i+2)}${y(2)}`),F||i<0||(F=!0,((e,...i)=>{l("info",e,...i)})(`v${e} (${(e=>f(h[e]))(i)})`),i<1&&d("Parent",y(3)))}(),A(),function(){switch(t.style.overflow=!1===w[a]?.scrolling?"hidden":"auto",w[a]?.scrolling){case"omit":break;case!0:t.scrolling="yes";break;case!1:t.scrolling="no";break;default:t.scrolling=w[a]?w[a].scrolling:"no"}}(),function(){const{bodyMargin:e}=w[a];"number"!=typeof e&&"0"!==e||(w[a].bodyMargin=`${e}px`)}(),function(e){const{id:i}=t;w[a].mode>=0&&(o(t,"load",(function(){x("iFrame.onload",`${e}:${E}`,i,!0),function(){const e=w[a]?.firstRun,i=w[a]?.heightCalculationMethod in n;!e&&i&&I({iframe:t,height:0,width:0,type:"init"})}()})),x("init",`${e}:${E}`,i,!0))}(W(a)),function(){if(w[a]){const e={close:R.bind(null,w[a].iframe),disconnect:k.bind(null,w[a].iframe),removeListeners(){d(a,"\n<rb>Deprecated Method Name</>\n\nThe emoveListeners()</> method has been renamed to isconnect()</>.\n"),this.disconnect()},resize:x.bind(null,"Window resize","resize",a),moveToAnchor(e){x("Move to anchor",`moveToAnchor:${e}`,a)},sendMessage(e){x("Send Message",`message:${e=JSON.stringify(e)}`,a)}};w[a].iframe.iframeResizer=e,w[a].iframe.iFrameResizer=e}}()),t?.iFrameResizer};function C(){!1===document.hidden&&function(e,i){const t=e=>w[e]?.autoResize&&!w[e]?.firstRun;Object.keys(w).forEach((function(n){t(n)&&x(e,i,n)}))}("Tab Visible","resize")}const A=(e=>{let i=!1;return function(){return i?void 0:(i=!0,Reflect.apply(e,this,arguments))}})((()=>{o(window,"message",v),o(document,"visibilitychange",C),window.iframeParentListener=e=>v({data:e,sameDomain:!0})}));switch(!0){case void 0===window.jQuery:c("","Unable to bind to jQuery, it is not available.");break;case!window.jQuery.fn:c("","Unable to bind to jQuery, it is not fully loaded.");break;case window.jQuery.fn.iframeResize:c("","iframeResize is already assigned to jQuery.fn.");break;default:window.jQuery.fn.iframeResize=function(e){const i=O(e);return this.filter("iframe").each(i).end()},window.jQuery.fn.iFrameResize=function(e){return c("","Deprecated: Use the iframeResize method instead of iFrameResize"),this.iframeResize(e)}}}));
20
+ (function (factory) {
21
+ typeof define === 'function' && define.amd ? define(factory) :
22
+ factory();
23
+ })((function () { 'use strict';
24
+
25
+ const VERSION = '5.0.2';
26
+
27
+ const msgHeader = 'message';
28
+ const msgHeaderLen = msgHeader.length;
29
+ const msgId$1 = '[iFrameSizer]'; // Must match iframe msg ID
30
+ const msgIdLen = msgId$1.length;
31
+ const resetRequiredMethods = Object.freeze({
32
+ max: 1,
33
+ scroll: 1,
34
+ bodyScroll: 1,
35
+ documentElementScroll: 1,
36
+ });
37
+
38
+ const addEventListener = (el, evt, func, options) =>
39
+ el.addEventListener(evt, func, options || false);
40
+
41
+ const removeEventListener = (el, evt, func) =>
42
+ el.removeEventListener(evt, func, false);
43
+
44
+ const encode = (s) =>
45
+ s
46
+ .replaceAll('<br>', '\n')
47
+ .replaceAll('<rb>', '\u001B[31;1m')
48
+ .replaceAll('</>', '\u001B[m')
49
+ .replaceAll('<b>', '\u001B[1m')
50
+ .replaceAll('<i>', '\u001B[3m')
51
+ .replaceAll('<u>', '\u001B[4m');
52
+
53
+ const remove = (s) => s.replaceAll('<br>', '\n').replaceAll(/<[/a-z]+>/gi, '');
54
+
55
+ const formatAdvise = (formatLogMsg) => (msg) =>
56
+ window.chrome // Only show formatting in Chrome as not supported in other browsers
57
+ ? formatLogMsg(encode(msg))
58
+ : formatLogMsg(remove(msg));
59
+
60
+ const msgId = '[iframe-resizer]';
61
+
62
+ function setLogEnabled(enabled) {
63
+ }
64
+
65
+ function getMyID(iframeId) {
66
+ if (window.top === window.self) {
67
+ return `Parent page: ${iframeId}`
68
+ }
69
+
70
+ return window?.parentIFrame?.getId
71
+ ? `${window.parentIFrame.getId()}: ${iframeId}`
72
+ : `Nested parent page: ${iframeId}`
73
+ }
74
+
75
+ const formatLogHeader = (iframeId) => `${msgId}[${getMyID(iframeId)}]`;
76
+
77
+ const formatLogMsg =
78
+ (iframeId) =>
79
+ (...msg) =>
80
+ [`${msgId}[${iframeId}]`, ...msg].join(' ');
81
+
82
+ const output = (type, iframeId, ...msg) =>
83
+ // eslint-disable-next-line no-console
84
+ window?.console[type](formatLogHeader(iframeId), ...msg);
85
+
86
+ const info = (iframeId, ...msg) => output('info', iframeId, ...msg);
87
+
88
+ const warn = (iframeId, ...msg) => output('warn', iframeId, ...msg);
89
+
90
+ const advise = (iframeId, msg) =>
91
+ // eslint-disable-next-line no-console
92
+ console?.warn(formatAdvise(formatLogMsg(iframeId))(msg));
93
+
94
+ const l = (l) => {
95
+ if (!l) return ''
96
+ let p = -559038744,
97
+ y = 1103547984;
98
+ for (let z, t = 0; t < l.length; t++)
99
+ (z = l.codePointAt(t)),
100
+ (p = Math.imul(p ^ z, 2246822519)),
101
+ (y = Math.imul(y ^ z, 3266489917));
102
+ return (
103
+ (p ^= Math.imul(p ^ (y >>> 15), 1935289751)),
104
+ (y ^= Math.imul(y ^ (p >>> 15), 3405138345)),
105
+ (p ^= y >>> 16),
106
+ (y ^= p >>> 16),
107
+ (2097152 * (y >>> 0) + (p >>> 11)).toString(36)
108
+ )
109
+ },
110
+ p = (l) =>
111
+ l.replaceAll(/[A-Za-z]/g, (l) =>
112
+ String.fromCodePoint(
113
+ (l <= 'Z' ? 90 : 122) >= (l = l.codePointAt(0) + 19) ? l : l - 26,
114
+ ),
115
+ ),
116
+ y = [
117
+ '<iy><yi>Puchspk Spjluzl Rlf</><iy><iy>',
118
+ '<iy><yi>Tpzzpun Spjluzl Rlf</><iy><iy>',
119
+ '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</>',
120
+ '<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</>.',
121
+ ],
122
+ z = ['NWSc3', 'zvsv', 'wyv', 'ibzpulzz', 'vlt'],
123
+ t = Object.fromEntries(
124
+ [
125
+ '2cgs7fdf4xb',
126
+ '1c9ctcccr4z',
127
+ '1q2pc4eebgb',
128
+ 'ueokt0969w',
129
+ 'w2zxchhgqz',
130
+ '1umuxblj2e5',
131
+ ].map((l, p) => [l, Math.max(0, p - 1)]),
132
+ );
133
+ const getModeData = (l) => p(y[l]);
134
+ const getModeLabel = (l) => p(z[l]);
135
+ const setMode = (y) => {
136
+ const z = y[p('spjluzl')];
137
+ if (!z) return -1
138
+ const u = z.split('-');
139
+ let v = (function (y = '') {
140
+ let z = -2;
141
+ const u = l(p(y));
142
+ return u in t && (z = t[u]), z
143
+ })(u[0]);
144
+ return 0 === v || ((p) => p[2] === l(p[0] + p[1]))(u) || (v = -2), v
145
+ };
146
+
147
+ const once = (fn) => {
148
+ let done = false;
149
+
150
+ return function () {
151
+ return done
152
+ ? undefined
153
+ : ((done = true), Reflect.apply(fn, this, arguments))
154
+ }
155
+ };
156
+
157
+ const settings = {};
158
+
159
+ const onReadyDeprecated = (messageData) => {
160
+ if (typeof settings[messageData.id].onInit === 'function') {
161
+ advise(
162
+ messageData.id,
163
+ `
164
+ \u001B[31;1mDeprecated Option\u001B[m
165
+
166
+ The \u001B[1monInit()\u001B[m function is deprecated and has been replaced with \u001B[1monReady()\u001B[m. It will be removed in a future version of iFrame Resizer.
167
+ `,
168
+ );
169
+ settings[messageData.id].onInit(messageData);
170
+ }
171
+ };
172
+
173
+ const defaults = Object.freeze({
174
+ autoResize: true,
175
+ bodyBackground: null,
176
+ bodyMargin: null,
177
+ bodyPadding: null,
178
+ checkOrigin: true,
179
+ direction: 'vertical',
180
+ inPageLinks: false,
181
+ heightCalculationMethod: 'auto',
182
+ id: 'iFrameResizer',
183
+ log: false,
184
+ license: undefined,
185
+ mouseEvents: true,
186
+ offsetHeight: null,
187
+ offsetWidth: null,
188
+ postMessageTarget: null,
189
+ sameDomain: false,
190
+ scrolling: false,
191
+ sizeHeight: true,
192
+ sizeWidth: false,
193
+ warningTimeout: 5000,
194
+ tolerance: 0,
195
+ widthCalculationMethod: 'auto',
196
+ onClose: () => true,
197
+ onClosed() {},
198
+ onInit: false,
199
+ onMessage: null,
200
+ onMouseEnter() {},
201
+ onMouseLeave() {},
202
+ onReady: onReadyDeprecated,
203
+ onResized() {},
204
+ onScroll: () => true,
205
+ });
206
+
207
+ const page = {
208
+ position: null,
209
+ version: VERSION,
210
+ };
211
+
212
+ function iframeListener(event) {
213
+ function resizeIFrame() {
214
+ setSize(messageData);
215
+ setPagePosition();
216
+
217
+ on('onResized', messageData);
218
+ }
219
+
220
+ function getPaddingEnds(compStyle) {
221
+ if (compStyle.boxSizing !== 'border-box') {
222
+ return 0
223
+ }
224
+
225
+ const top = compStyle.paddingTop ? parseInt(compStyle.paddingTop, 10) : 0;
226
+ const bot = compStyle.paddingBottom
227
+ ? parseInt(compStyle.paddingBottom, 10)
228
+ : 0;
229
+
230
+ return top + bot
231
+ }
232
+
233
+ function getBorderEnds(compStyle) {
234
+ if (compStyle.boxSizing !== 'border-box') {
235
+ return 0
236
+ }
237
+
238
+ const top = compStyle.borderTopWidth
239
+ ? parseInt(compStyle.borderTopWidth, 10)
240
+ : 0;
241
+ const bot = compStyle.borderBottomWidth
242
+ ? parseInt(compStyle.borderBottomWidth, 10)
243
+ : 0;
244
+
245
+ return top + bot
246
+ }
247
+
248
+ function processMsg() {
249
+ const data = msg.slice(msgIdLen).split(':');
250
+ const height = data[1] ? Number(data[1]) : 0;
251
+ const iframe = settings[data[0]]?.iframe;
252
+ const compStyle = getComputedStyle(iframe);
253
+
254
+ return {
255
+ iframe,
256
+ id: data[0],
257
+ height: height + getPaddingEnds(compStyle) + getBorderEnds(compStyle),
258
+ width: Number(data[2]),
259
+ type: data[3],
260
+ version: data[4],
261
+ }
262
+ }
263
+
264
+ function isMessageFromIFrame() {
265
+ function checkAllowedOrigin() {
266
+ function checkList() {
267
+ let i = 0;
268
+ let retCode = false;
269
+
270
+ for (; i < checkOrigin.length; i++) {
271
+ if (checkOrigin[i] === origin) {
272
+ retCode = true;
273
+ break
274
+ }
275
+ }
276
+
277
+ return retCode
278
+ }
279
+
280
+ function checkSingle() {
281
+ const remoteHost = settings[iframeId]?.remoteHost;
282
+ return origin === remoteHost
283
+ }
284
+
285
+ return checkOrigin.constructor === Array ? checkList() : checkSingle()
286
+ }
287
+
288
+ const { origin, sameDomain } = event;
289
+
290
+ if (sameDomain) {
291
+ return true
292
+ }
293
+
294
+ let checkOrigin = settings[iframeId]?.checkOrigin;
295
+
296
+ if (checkOrigin && `${origin}` !== 'null' && !checkAllowedOrigin()) {
297
+ throw new Error(
298
+ `Unexpected message received from: ${origin} for ${messageData.iframe.id}. Message was: ${event.data}. This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.`,
299
+ )
300
+ }
301
+
302
+ return true
303
+ }
304
+
305
+ function isMessageForUs() {
306
+ return (
307
+ msgId$1 === `${msg}`.slice(0, msgIdLen) &&
308
+ msg.slice(msgIdLen).split(':')[0] in settings
309
+ ) // ''+Protects against non-string msg
310
+ }
311
+
312
+ function isMessageFromMetaParent() {
313
+ // Test if this message is from a parent above us. This is an ugly test, however, updating
314
+ // the message format would break backwards compatibility.
315
+ const retCode = messageData.type in { true: 1, false: 1, undefined: 1 };
316
+
317
+ return retCode
318
+ }
319
+
320
+ function getMsgBody(offset) {
321
+ return msg.slice(msg.indexOf(':') + msgHeaderLen + offset)
322
+ }
323
+
324
+ function forwardMsgFromIFrame(msgBody) {
325
+
326
+ on('onMessage', {
327
+ iframe: messageData.iframe,
328
+ message: JSON.parse(msgBody),
329
+ });
330
+ }
331
+
332
+ function getPageInfo() {
333
+ const bodyPosition = document.body.getBoundingClientRect();
334
+ const iFramePosition = messageData.iframe.getBoundingClientRect();
335
+ const { scrollY, scrollX, innerHeight, innerWidth } = window;
336
+ const { clientHeight, clientWidth } = document.documentElement;
337
+
338
+ return JSON.stringify({
339
+ iframeHeight: iFramePosition.height,
340
+ iframeWidth: iFramePosition.width,
341
+ clientHeight: Math.max(clientHeight, innerHeight || 0),
342
+ clientWidth: Math.max(clientWidth, innerWidth || 0),
343
+ offsetTop: parseInt(iFramePosition.top - bodyPosition.top, 10),
344
+ offsetLeft: parseInt(iFramePosition.left - bodyPosition.left, 10),
345
+ scrollTop: scrollY,
346
+ scrollLeft: scrollX,
347
+ documentHeight: clientHeight,
348
+ documentWidth: clientWidth,
349
+ windowHeight: innerHeight,
350
+ windowWidth: innerWidth,
351
+ })
352
+ }
353
+
354
+ function getParentProperties() {
355
+ const { iframe } = messageData;
356
+ const { scrollWidth, scrollHeight } = document.documentElement;
357
+ const { width, height, offsetLeft, offsetTop, pageLeft, pageTop, scale } =
358
+ window.visualViewport;
359
+
360
+ return JSON.stringify({
361
+ iframe: iframe.getBoundingClientRect(),
362
+ document: {
363
+ scrollWidth,
364
+ scrollHeight,
365
+ },
366
+ viewport: {
367
+ width,
368
+ height,
369
+ offsetLeft,
370
+ offsetTop,
371
+ pageLeft,
372
+ pageTop,
373
+ scale,
374
+ },
375
+ })
376
+ }
377
+
378
+ const sendInfoToIframe = (type, infoFunction) => (requestType, iframeId) => {
379
+ const gate = {};
380
+
381
+ function throttle(func, frameId) {
382
+ if (!gate[frameId]) {
383
+ func();
384
+ gate[frameId] = requestAnimationFrame(() => {
385
+ gate[frameId] = null;
386
+ });
387
+ }
388
+ }
389
+
390
+ function gatedTrigger() {
391
+ trigger(
392
+ `Send ${type} (${requestType})`,
393
+ `${type}:${infoFunction()}`,
394
+ iframeId,
395
+ );
396
+ }
397
+
398
+ throttle(gatedTrigger, iframeId);
399
+ };
400
+
401
+ const startInfoMonitor = (sendInfoToIframe, type) => () => {
402
+ const sendInfo = (requestType) => () => {
403
+ if (settings[id]) {
404
+ sendInfoToIframe(requestType, id);
405
+ } else {
406
+ stop();
407
+ }
408
+ };
409
+
410
+ function setListener(requestType, listener) {
411
+ listener(window, 'scroll', sendInfo('scroll'));
412
+ listener(window, 'resize', sendInfo('resize window'));
413
+ }
414
+
415
+ function stop() {
416
+ setListener('Remove ', removeEventListener);
417
+ pageObserver.disconnect();
418
+ iframeObserver.disconnect();
419
+ }
420
+
421
+ function start() {
422
+ setListener('Add ', addEventListener);
423
+ pageObserver.observe(document.body, {
424
+ attributes: true,
425
+ childList: true,
426
+ subtree: true,
427
+ });
428
+ iframeObserver.observe(settings[id].iframe, {
429
+ attributes: true,
430
+ childList: false,
431
+ subtree: false,
432
+ });
433
+ }
434
+
435
+ const id = iframeId; // Create locally scoped copy of iFrame ID
436
+
437
+ const pageObserver = new ResizeObserver(sendInfo('page observed'));
438
+ const iframeObserver = new ResizeObserver(sendInfo('iframe observed'));
439
+
440
+ start();
441
+
442
+ if (settings[id]) {
443
+ settings[id][`stop${type}`] = stop;
444
+ }
445
+ };
446
+
447
+ const stopInfoMonitor = (stopFunction) => () => {
448
+ if (stopFunction in settings[iframeId]) {
449
+ settings[iframeId][stopFunction]();
450
+ delete settings[iframeId][stopFunction];
451
+ }
452
+ };
453
+
454
+ const sendPageInfoToIframe = sendInfoToIframe('pageInfo', getPageInfo);
455
+ const sendParentInfoToIframe = sendInfoToIframe(
456
+ 'parentInfo',
457
+ getParentProperties,
458
+ );
459
+
460
+ const startPageInfoMonitor = startInfoMonitor(
461
+ sendPageInfoToIframe,
462
+ 'PageInfo',
463
+ );
464
+ const startParentInfoMonitor = startInfoMonitor(
465
+ sendParentInfoToIframe,
466
+ 'ParentInfo',
467
+ );
468
+
469
+ const stopPageInfoMonitor = stopInfoMonitor('stopPageInfo');
470
+ const stopParentInfoMonitor = stopInfoMonitor('stopParentInfo');
471
+
472
+ function checkIFrameExists() {
473
+ let retBool = true;
474
+
475
+ if (messageData.iframe === null) {
476
+ warn(iframeId, `The iframe (${messageData.id}) was not found.`);
477
+ retBool = false;
478
+ }
479
+
480
+ return retBool
481
+ }
482
+
483
+ function getElementPosition(target) {
484
+ const iFramePosition = target.getBoundingClientRect();
485
+
486
+ getPagePosition();
487
+
488
+ return {
489
+ x: Number(iFramePosition.left) + Number(page.position.x),
490
+ y: Number(iFramePosition.top) + Number(page.position.y),
491
+ }
492
+ }
493
+
494
+ function scrollRequestFromChild(addOffset) {
495
+ /* istanbul ignore next */ // Not testable in Karma
496
+ function reposition() {
497
+ page.position = newPosition;
498
+ scrollTo(iframeId);
499
+ }
500
+
501
+ function scrollParent() {
502
+ if (window.parentIFrame) {
503
+ window.parentIFrame[`scrollTo${addOffset ? 'Offset' : ''}`](
504
+ newPosition.x,
505
+ newPosition.y,
506
+ );
507
+ } else {
508
+ warn(
509
+ iframeId,
510
+ 'Unable to scroll to requested position, window.parentIFrame not found',
511
+ );
512
+ }
513
+ }
514
+
515
+ const calcOffset = (messageData, offset) => ({
516
+ x: messageData.width + offset.x,
517
+ y: messageData.height + offset.y,
518
+ });
519
+
520
+ const offset = addOffset
521
+ ? getElementPosition(messageData.iframe)
522
+ : { x: 0, y: 0 };
523
+
524
+ let newPosition = calcOffset(messageData, offset);
525
+
526
+ if (window.top === window.self) {
527
+ reposition();
528
+ } else {
529
+ scrollParent();
530
+ }
531
+ }
532
+
533
+ function scrollTo(iframeId) {
534
+ const { x, y } = page.position;
535
+ const iframe = settings[iframeId]?.iframe;
536
+ if (on('onScroll', { iframe, top: y, left: x, x, y }) === false) {
537
+ unsetPagePosition();
538
+ return
539
+ }
540
+ setPagePosition();
541
+ }
542
+
543
+ function findTarget(location) {
544
+ function jumpToTarget() {
545
+ const jumpPosition = getElementPosition(target);
546
+
547
+ page.position = {
548
+ x: jumpPosition.x,
549
+ y: jumpPosition.y,
550
+ };
551
+
552
+ scrollTo(iframeId);
553
+ }
554
+
555
+ function jumpToParent() {
556
+ if (window.parentIFrame) {
557
+ window.parentIFrame.moveToAnchor(hash);
558
+ return
559
+ }
560
+ }
561
+
562
+ const hash = location.split('#')[1] || '';
563
+ const hashData = decodeURIComponent(hash);
564
+
565
+ let target =
566
+ document.getElementById(hashData) ||
567
+ document.getElementsByName(hashData)[0];
568
+
569
+ if (target) {
570
+ jumpToTarget();
571
+ return
572
+ }
573
+
574
+ if (window.top === window.self) {
575
+ return
576
+ }
577
+
578
+ jumpToParent();
579
+ }
580
+
581
+ function onMouse(event) {
582
+ let mousePos = {};
583
+
584
+ if (messageData.width === 0 && messageData.height === 0) {
585
+ const data = getMsgBody(9).split(':');
586
+ mousePos = {
587
+ x: data[1],
588
+ y: data[0],
589
+ };
590
+ } else {
591
+ mousePos = {
592
+ x: messageData.width,
593
+ y: messageData.height,
594
+ };
595
+ }
596
+
597
+ on(event, {
598
+ iframe: messageData.iframe,
599
+ screenX: Number(mousePos.x),
600
+ screenY: Number(mousePos.y),
601
+ type: messageData.type,
602
+ });
603
+ }
604
+
605
+ const on = (funcName, val) => chkEvent(iframeId, funcName, val);
606
+
607
+ function checkSameDomain(id) {
608
+ try {
609
+ settings[id].sameDomain =
610
+ !!settings[id]?.iframe?.contentWindow?.iframeChildListener;
611
+ } catch (error) {
612
+ settings[id].sameDomain = false;
613
+ }
614
+ }
615
+
616
+ function checkVersion(version) {
617
+ if (version === VERSION) return
618
+ if (version === undefined) {
619
+ advise(
620
+ iframeId,
621
+ `<rb>Legacy version detected in iframe</>
622
+
623
+ Detected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.
624
+
625
+ See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.
626
+ `,
627
+ );
628
+ return
629
+ }
630
+ }
631
+
632
+ function started() {
633
+ setup = true;
634
+ }
635
+
636
+ function actionMsg() {
637
+ if (settings[iframeId]?.firstRun) firstRun();
638
+
639
+ switch (messageData.type) {
640
+ case 'close':
641
+ closeIFrame(messageData.iframe);
642
+ break
643
+
644
+ case 'message':
645
+ forwardMsgFromIFrame(getMsgBody(6));
646
+ break
647
+
648
+ case 'mouseenter':
649
+ onMouse('onMouseEnter');
650
+ break
651
+
652
+ case 'mouseleave':
653
+ onMouse('onMouseLeave');
654
+ break
655
+
656
+ case 'autoResize':
657
+ settings[iframeId].autoResize = JSON.parse(getMsgBody(9));
658
+ break
659
+
660
+ case 'scrollTo':
661
+ scrollRequestFromChild(false);
662
+ break
663
+
664
+ case 'scrollToOffset':
665
+ scrollRequestFromChild(true);
666
+ break
667
+
668
+ case 'pageInfo':
669
+ sendPageInfoToIframe('start', iframeId);
670
+ startPageInfoMonitor();
671
+ break
672
+
673
+ case 'parentInfo':
674
+ sendParentInfoToIframe('start', iframeId);
675
+ startParentInfoMonitor();
676
+ break
677
+
678
+ case 'pageInfoStop':
679
+ stopPageInfoMonitor();
680
+ break
681
+
682
+ case 'parentInfoStop':
683
+ stopParentInfoMonitor();
684
+ break
685
+
686
+ case 'inPageLink':
687
+ findTarget(getMsgBody(9));
688
+ break
689
+
690
+ case 'reset':
691
+ resetIFrame(messageData);
692
+ break
693
+
694
+ case 'init':
695
+ resizeIFrame();
696
+ checkSameDomain(iframeId);
697
+ checkVersion(messageData.version);
698
+ started();
699
+ on('onReady', messageData.iframe);
700
+ break
701
+
702
+ default:
703
+ if (messageData.width === 0 && messageData.height === 0) {
704
+ warn(
705
+ `Unsupported message received (${messageData.type}), this is likely due to the iframe containing a later ` +
706
+ `version of iframe-resizer than the parent page`,
707
+ );
708
+ return
709
+ }
710
+
711
+ if (messageData.width === 0 || messageData.height === 0) {
712
+ return
713
+ }
714
+
715
+ // Recheck document.hidden here, as only Firefox
716
+ // correctly supports this in the iframe
717
+ if (document.hidden) {
718
+ return
719
+ }
720
+
721
+ resizeIFrame();
722
+ }
723
+ }
724
+
725
+ function checkSettings(iframeId) {
726
+ if (!settings[iframeId]) {
727
+ throw new Error(
728
+ `${messageData.type} No settings for ${iframeId}. Message was: ${msg}`,
729
+ )
730
+ }
731
+ }
732
+
733
+ function iFrameReadyMsgReceived() {
734
+ Object.keys(settings).forEach((iframeId) => {
735
+ if (settings[iframeId].mode >= 0)
736
+ trigger('iFrame requested init', createOutgoingMsg(iframeId), iframeId);
737
+ });
738
+ }
739
+
740
+ function firstRun() {
741
+ if (settings[iframeId]) {
742
+ settings[iframeId].firstRun = false;
743
+ }
744
+ }
745
+
746
+ let msg = event.data;
747
+ let messageData = {};
748
+ let iframeId = null;
749
+
750
+ if (msg === '[iFrameResizerChild]Ready') {
751
+ iFrameReadyMsgReceived();
752
+ return
753
+ }
754
+
755
+ if (!isMessageForUs()) {
756
+ return
757
+ }
758
+
759
+ messageData = processMsg();
760
+ iframeId = messageData.id;
761
+
762
+ if (!iframeId) {
763
+ warn('iframeResizer received messageData without id, message was: ', msg);
764
+ return
765
+ }
766
+
767
+ checkSettings(iframeId);
768
+
769
+ if (!isMessageFromMetaParent()) {
770
+ settings[iframeId].loaded = true;
771
+
772
+ if (checkIFrameExists() && isMessageFromIFrame()) {
773
+ actionMsg();
774
+ }
775
+ }
776
+ }
777
+
778
+ function chkEvent(iframeId, funcName, val) {
779
+ let func = null;
780
+ let retVal = null;
781
+
782
+ if (settings[iframeId]) {
783
+ func = settings[iframeId][funcName];
784
+
785
+ if (typeof func === 'function') {
786
+ retVal = func(val);
787
+ } else {
788
+ throw new TypeError(
789
+ `${funcName} on iFrame[${iframeId}] is not a function`,
790
+ )
791
+ }
792
+ }
793
+
794
+ return retVal
795
+ }
796
+
797
+ function removeIframeListeners(iframe) {
798
+ const iframeId = iframe.id;
799
+ delete settings[iframeId];
800
+ }
801
+
802
+ function closeIFrame(iframe) {
803
+ const iframeId = iframe.id;
804
+ if (chkEvent(iframeId, 'onClose', iframeId) === false) {
805
+ return
806
+ }
807
+
808
+ try {
809
+ // Catch race condition error with React
810
+ if (iframe.parentNode) {
811
+ iframe.remove();
812
+ }
813
+ } catch (error) {
814
+ warn(error);
815
+ }
816
+
817
+ chkEvent(iframeId, 'onClosed', iframeId);
818
+ removeIframeListeners(iframe);
819
+ }
820
+
821
+ function getPagePosition(iframeId) {
822
+ if (page.position === null) {
823
+ page.position = {
824
+ x: window.scrollX,
825
+ y: window.scrollY,
826
+ };
827
+ }
828
+ }
829
+
830
+ function unsetPagePosition() {
831
+ page.position = null;
832
+ }
833
+
834
+ function setPagePosition(iframeId) {
835
+ if (page.position !== null) {
836
+ window.scrollTo(page.position.x, page.position.y);
837
+ unsetPagePosition();
838
+ }
839
+ }
840
+
841
+ function resetIFrame(messageData) {
842
+
843
+ getPagePosition(messageData.id);
844
+ setSize(messageData);
845
+ trigger('reset', 'reset', messageData.id);
846
+ }
847
+
848
+ function setSize(messageData) {
849
+ const iframeId = messageData.id;
850
+
851
+ function setDimension(dimension) {
852
+ const size = `${messageData[dimension]}px`;
853
+ messageData.iframe.style[dimension] = size;
854
+ }
855
+
856
+ if (settings[iframeId].sizeHeight) {
857
+ setDimension('height');
858
+ }
859
+ if (settings[iframeId].sizeWidth) {
860
+ setDimension('width');
861
+ }
862
+ }
863
+
864
+ function trigger(calleeMsg, msg, id, noResponseWarning) {
865
+ function postMessageToIFrame() {
866
+ const { postMessageTarget, targetOrigin } = settings[id];
867
+
868
+ if (settings[id].sameDomain) {
869
+ try {
870
+ settings[id].iframe.contentWindow.iframeChildListener(msgId$1 + msg);
871
+ return
872
+ } catch (error) {
873
+ settings[id].sameDomain = false;
874
+ }
875
+ }
876
+ postMessageTarget.postMessage(msgId$1 + msg, targetOrigin);
877
+ }
878
+
879
+ function iFrameNotFound() {
880
+ warn(id, `[${calleeMsg}] IFrame(${id}) not found`);
881
+ }
882
+
883
+ function chkAndSend() {
884
+ if (!settings[id]?.postMessageTarget) {
885
+ iFrameNotFound();
886
+ return
887
+ }
888
+ postMessageToIFrame();
889
+ }
890
+
891
+ function warnOnNoResponse() {
892
+ function warning() {
893
+ if (settings[id] === undefined) return // iframe has been closed while we where waiting
894
+
895
+ if (!settings[id].loaded && !settings[id].loadErrorShown) {
896
+ settings[id].loadErrorShown = true;
897
+ advise(
898
+ id,
899
+ `
900
+ <rb>No response from iFrame</>
901
+
902
+ The iframe (<i>${id}</>) has not responded within ${settings[id].warningTimeout / 1000} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.
903
+
904
+ This message can be ignored if everything is working, or you can set the <b>warningTimeout</> option to a higher value or zero to suppress this warning.
905
+ `,
906
+ );
907
+ }
908
+ }
909
+
910
+ if (!!noResponseWarning && !!settings[id]?.warningTimeout) {
911
+ settings[id].msgTimeout = setTimeout(warning, settings[id].warningTimeout);
912
+ }
913
+ }
914
+
915
+ if (settings[id]) {
916
+ chkAndSend();
917
+ warnOnNoResponse();
918
+ }
919
+ }
920
+
921
+ function createOutgoingMsg(iframeId) {
922
+ const iframeSettings = settings[iframeId];
923
+
924
+ return [
925
+ iframeId,
926
+ '8', // Backwards compatibility (PaddingV1)
927
+ iframeSettings.sizeWidth,
928
+ iframeSettings.log,
929
+ '32', // Backwards compatibility (Interval)
930
+ true, // Backwards compatibility (EnablePublicMethods)
931
+ iframeSettings.autoResize,
932
+ iframeSettings.bodyMargin,
933
+ iframeSettings.heightCalculationMethod,
934
+ iframeSettings.bodyBackground,
935
+ iframeSettings.bodyPadding,
936
+ iframeSettings.tolerance,
937
+ iframeSettings.inPageLinks,
938
+ 'child', // Backwards compatibility (resizeFrom)
939
+ iframeSettings.widthCalculationMethod,
940
+ iframeSettings.mouseEvents,
941
+ iframeSettings.offsetHeight,
942
+ iframeSettings.offsetWidth,
943
+ iframeSettings.sizeHeight,
944
+ iframeSettings.license,
945
+ page.version,
946
+ iframeSettings.mode,
947
+ ].join(':')
948
+ }
949
+
950
+ let count = 0;
951
+ let setup = false;
952
+ let vAdvised = false;
953
+
954
+ const connectResizer = (options) => (iframe) => {
955
+ function newId() {
956
+ let id = options?.id || defaults.id + count++;
957
+
958
+ if (document.getElementById(id) !== null) {
959
+ id += count++;
960
+ }
961
+
962
+ return id
963
+ }
964
+
965
+ function ensureHasId(iframeId) {
966
+ if (iframeId && typeof iframeId !== 'string') {
967
+ throw new TypeError('Invalid id for iFrame. Expected String')
968
+ }
969
+
970
+ if (iframeId === '' || !iframeId) {
971
+ // eslint-disable-next-line no-multi-assign
972
+ iframe.id = iframeId = newId();
973
+ setLogEnabled((options || {}).log);
974
+ }
975
+
976
+ return iframeId
977
+ }
978
+
979
+ function setScrolling() {
980
+
981
+ iframe.style.overflow =
982
+ settings[iframeId]?.scrolling === false ? 'hidden' : 'auto';
983
+
984
+ switch (settings[iframeId]?.scrolling) {
985
+ case 'omit':
986
+ break
987
+
988
+ case true:
989
+ iframe.scrolling = 'yes';
990
+ break
991
+
992
+ case false:
993
+ iframe.scrolling = 'no';
994
+ break
995
+
996
+ default:
997
+ iframe.scrolling = settings[iframeId]
998
+ ? settings[iframeId].scrolling
999
+ : 'no';
1000
+ }
1001
+ }
1002
+
1003
+ function setupBodyMarginValues() {
1004
+ const { bodyMargin } = settings[iframeId];
1005
+
1006
+ if (typeof bodyMargin === 'number' || bodyMargin === '0') {
1007
+ settings[iframeId].bodyMargin = `${bodyMargin}px`;
1008
+ }
1009
+ }
1010
+
1011
+ function checkReset() {
1012
+ const firstRun = settings[iframeId]?.firstRun;
1013
+ const resetRequestMethod =
1014
+ settings[iframeId]?.heightCalculationMethod in resetRequiredMethods;
1015
+
1016
+ if (!firstRun && resetRequestMethod) {
1017
+ resetIFrame({ iframe, height: 0, width: 0, type: 'init' });
1018
+ }
1019
+ }
1020
+
1021
+ function setupIFrameObject() {
1022
+ if (settings[iframeId]) {
1023
+ const resizer = {
1024
+ close: closeIFrame.bind(null, settings[iframeId].iframe),
1025
+
1026
+ disconnect: removeIframeListeners.bind(null, settings[iframeId].iframe),
1027
+
1028
+ removeListeners() {
1029
+ advise(
1030
+ iframeId,
1031
+ `
1032
+ <rb>Deprecated Method Name</>
1033
+
1034
+ The \u001B[removeListeners()</> method has been renamed to \u001B[disconnect()</>.
1035
+ `,
1036
+ );
1037
+ this.disconnect();
1038
+ },
1039
+
1040
+ resize: trigger.bind(null, 'Window resize', 'resize', iframeId),
1041
+
1042
+ moveToAnchor(anchor) {
1043
+ trigger('Move to anchor', `moveToAnchor:${anchor}`, iframeId);
1044
+ },
1045
+
1046
+ sendMessage(message) {
1047
+ message = JSON.stringify(message);
1048
+ trigger('Send Message', `message:${message}`, iframeId);
1049
+ },
1050
+ };
1051
+
1052
+ settings[iframeId].iframe.iframeResizer = resizer;
1053
+ settings[iframeId].iframe.iFrameResizer = resizer;
1054
+ }
1055
+ }
1056
+
1057
+ // We have to call trigger twice, as we can not be sure if all
1058
+ // iframes have completed loading when this code runs. The
1059
+ // event listener also catches the page changing in the iFrame.
1060
+ function init(msg) {
1061
+ function iFrameLoaded() {
1062
+ trigger('iFrame.onload', `${msg}:${setup}`, id, true);
1063
+ checkReset();
1064
+ }
1065
+
1066
+ const { id } = iframe;
1067
+
1068
+ if (settings[iframeId].mode >= 0) {
1069
+ addEventListener(iframe, 'load', iFrameLoaded);
1070
+ trigger('init', `${msg}:${setup}`, id, true);
1071
+ }
1072
+ }
1073
+
1074
+ function checkOptions(options) {
1075
+ if (!options) return {}
1076
+
1077
+ if (typeof options !== 'object') {
1078
+ throw new TypeError('Options is not an object')
1079
+ }
1080
+
1081
+ if (
1082
+ 'sizeWidth' in options ||
1083
+ 'sizeHeight' in options ||
1084
+ 'autoResize' in options
1085
+ ) {
1086
+ advise(
1087
+ iframeId,
1088
+ `<rb>Deprecated Option</>
1089
+
1090
+ The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <i>"vertical"</>, <i>"horizontal"</> or <i>"horizontal"</>.
1091
+ `,
1092
+ );
1093
+ }
1094
+
1095
+ return options
1096
+ }
1097
+
1098
+ function checkMode() {
1099
+ const { mode } = settings[iframeId];
1100
+ if (mode < 0) advise('Parent', `${getModeData(mode + 2)}${getModeData(2)}`);
1101
+ if (vAdvised || mode < 0) return
1102
+ vAdvised = true;
1103
+ info(`v${VERSION} (${getModeLabel(mode)})`);
1104
+ if (mode < 1) advise('Parent', getModeData(3));
1105
+ }
1106
+
1107
+ function setDirection() {
1108
+ if (settings[iframeId].direction === 'horizontal') {
1109
+ settings[iframeId].sizeWidth = true;
1110
+ settings[iframeId].sizeHeight = false;
1111
+ return
1112
+ }
1113
+
1114
+ if (settings[iframeId].direction === 'none') {
1115
+ settings[iframeId].sizeWidth = false;
1116
+ settings[iframeId].sizeHeight = false;
1117
+ settings[iframeId].autoResize = false;
1118
+ return
1119
+ }
1120
+
1121
+ if (settings[iframeId].direction !== 'vertical') {
1122
+ throw new TypeError(
1123
+ iframeId,
1124
+ `Direction value of "${settings[iframeId].direction}" is not valid`,
1125
+ )
1126
+ }
1127
+ }
1128
+
1129
+ function setOffset(offset) {
1130
+ if (!offset) return
1131
+ if (settings[iframeId].direction === 'vertical') {
1132
+ settings[iframeId].offsetHeight = offset;
1133
+ } else {
1134
+ settings[iframeId].offsetWidth = offset;
1135
+ }
1136
+ }
1137
+
1138
+ function getTargetOrigin(remoteHost) {
1139
+ return remoteHost === '' ||
1140
+ remoteHost.match(/^(about:blank|javascript:|file:\/\/)/) !== null
1141
+ ? '*'
1142
+ : remoteHost
1143
+ }
1144
+
1145
+ function getPostMessageTarget() {
1146
+ if (settings[iframeId].postMessageTarget === null)
1147
+ settings[iframeId].postMessageTarget = iframe.contentWindow;
1148
+ }
1149
+
1150
+ function processOptions(options) {
1151
+ settings[iframeId] = {
1152
+ iframe,
1153
+ firstRun: true,
1154
+ remoteHost: iframe?.src.split('/').slice(0, 3).join('/'),
1155
+ ...defaults,
1156
+ ...checkOptions(options),
1157
+ mode: setMode(options),
1158
+ };
1159
+
1160
+ setDirection();
1161
+ setOffset(options?.offset);
1162
+ getPostMessageTarget();
1163
+
1164
+ settings[iframeId].targetOrigin =
1165
+ settings[iframeId].checkOrigin === true
1166
+ ? getTargetOrigin(settings[iframeId].remoteHost)
1167
+ : '*';
1168
+ }
1169
+
1170
+ function beenHere() {
1171
+ return iframeId in settings && 'iFrameResizer' in iframe
1172
+ }
1173
+
1174
+ const iframeId = ensureHasId(iframe.id);
1175
+
1176
+ if (beenHere()) {
1177
+ warn(iframeId, 'Ignored iFrame, already setup.');
1178
+ } else {
1179
+ processOptions(options);
1180
+ checkMode();
1181
+ setupEventListenersOnce();
1182
+ setScrolling();
1183
+ setupBodyMarginValues();
1184
+ init(createOutgoingMsg(iframeId));
1185
+ setupIFrameObject();
1186
+ }
1187
+
1188
+ return iframe?.iFrameResizer
1189
+ };
1190
+
1191
+ function sendTriggerMsg(eventName, event) {
1192
+ function triggerEnabledIframe(iframeId) {
1193
+ if (isIFrameResizeEnabled(iframeId)) {
1194
+ trigger(eventName, event, iframeId);
1195
+ }
1196
+ }
1197
+
1198
+ const isIFrameResizeEnabled = (iframeId) =>
1199
+ settings[iframeId]?.autoResize && !settings[iframeId]?.firstRun;
1200
+
1201
+ Object.keys(settings).forEach(triggerEnabledIframe);
1202
+ }
1203
+
1204
+ function tabVisible() {
1205
+ if (document.hidden === false) {
1206
+ sendTriggerMsg('Tab Visible', 'resize');
1207
+ }
1208
+ }
1209
+
1210
+ const setupEventListenersOnce = once(() => {
1211
+ addEventListener(window, 'message', iframeListener);
1212
+ addEventListener(document, 'visibilitychange', tabVisible);
1213
+ window.iframeParentListener = (data) =>
1214
+ iframeListener({ data, sameDomain: true });
1215
+ });
1216
+
1217
+ switch (true) {
1218
+ case window.jQuery === undefined:
1219
+ warn('', 'Unable to bind to jQuery, it is not available.');
1220
+ break
1221
+
1222
+ case !window.jQuery.fn:
1223
+ warn('', 'Unable to bind to jQuery, it is not fully loaded.');
1224
+ break
1225
+
1226
+ case window.jQuery.fn.iframeResize:
1227
+ warn('', 'iframeResize is already assigned to jQuery.fn.');
1228
+ break
1229
+
1230
+ default:
1231
+ window.jQuery.fn.iframeResize = function (options) {
1232
+ const connectWithOptions = connectResizer(options);
1233
+
1234
+ return this.filter('iframe').each(connectWithOptions).end()
1235
+ };
1236
+
1237
+ window.jQuery.fn.iFrameResize = function (options) {
1238
+ warn(
1239
+ '',
1240
+ 'Deprecated: Use the iframeResize method instead of iFrameResize',
1241
+ );
1242
+
1243
+ return this.iframeResize(options)
1244
+ };
1245
+ }
1246
+
1247
+ }));