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