iframe-resizer 4.4.4 → 5.1.5-beta.1

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