@iframe-resizer/core 6.0.0-beta.10 → 6.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.cjs.js +3 -3
- package/index.cjs.js.map +1 -1
- package/index.d.ts +31 -26
- package/index.esm.js +3 -3
- package/index.esm.js.map +1 -1
- package/index.umd.js +3 -3
- package/index.umd.js.map +1 -1
- package/package.json +3 -4
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BOTH } from '@iframe-resizer/common/consts';
|
|
|
3
3
|
import { COLLAPSE } from '@iframe-resizer/common/consts';
|
|
4
4
|
import { EXPAND } from '@iframe-resizer/common/consts';
|
|
5
5
|
import { HORIZONTAL } from '@iframe-resizer/common/consts';
|
|
6
|
+
import { IFrameVersion } from '@iframe-resizer/common';
|
|
6
7
|
import { LOG_COLLAPSED } from '@iframe-resizer/common/consts';
|
|
7
8
|
import { LOG_DISABLED } from '@iframe-resizer/common/consts';
|
|
8
9
|
import { LOG_EXPANDED } from '@iframe-resizer/common/consts';
|
|
@@ -10,42 +11,44 @@ import { NONE } from '@iframe-resizer/common/consts';
|
|
|
10
11
|
import { OMIT } from '@iframe-resizer/common/consts';
|
|
11
12
|
import { VERTICAL } from '@iframe-resizer/common/consts';
|
|
12
13
|
|
|
13
|
-
declare function connectResizer(options:
|
|
14
|
+
declare function connectResizer(options: IFrameOptions): (iframe: HTMLIFrameElement) => IFrameObject | undefined;
|
|
14
15
|
export default connectResizer;
|
|
15
16
|
|
|
16
17
|
/** HTMLIFrameElement with the `iframeResizer` control object attached. */
|
|
17
|
-
export declare interface
|
|
18
|
-
iframeResizer:
|
|
18
|
+
export declare interface IFrameComponent extends HTMLIFrameElement {
|
|
19
|
+
iframeResizer: IFrameObject;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export declare type
|
|
22
|
+
export declare type IFrameDirection = typeof VERTICAL | typeof HORIZONTAL | typeof NONE | typeof BOTH;
|
|
22
23
|
|
|
23
|
-
export declare type
|
|
24
|
+
export declare type IFrameLogOption = boolean | typeof EXPAND | typeof COLLAPSE | number;
|
|
24
25
|
|
|
25
|
-
export declare interface
|
|
26
|
-
iframe:
|
|
26
|
+
export declare interface IFrameMessageData {
|
|
27
|
+
iframe: IFrameComponent;
|
|
27
28
|
message: any;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export declare interface
|
|
31
|
-
iframe:
|
|
31
|
+
export declare interface IFrameMouseData {
|
|
32
|
+
iframe: IFrameComponent;
|
|
32
33
|
screenX: number;
|
|
33
34
|
screenY: number;
|
|
34
35
|
type: string;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export declare interface
|
|
38
|
+
export declare interface IFrameObject {
|
|
38
39
|
/** Remove the iframe from the page. */
|
|
39
40
|
close(): void;
|
|
40
41
|
/** Disconnect iframe-resizer from the iframe. */
|
|
41
42
|
disconnect(): void;
|
|
43
|
+
/** Returns the child and parent iframe-resizer versions. */
|
|
44
|
+
getVersion(): IFrameVersion;
|
|
42
45
|
/** Move the page in the iframe to the specified anchor. */
|
|
43
46
|
moveToAnchor(anchor: string): void;
|
|
44
47
|
/** Send a message to the iframe. */
|
|
45
48
|
sendMessage(message: any, targetOrigin?: string): void;
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
export declare interface
|
|
51
|
+
export declare interface IFrameOptions {
|
|
49
52
|
/** Override the body background style in the iframe. */
|
|
50
53
|
bodyBackground?: string | null;
|
|
51
54
|
/**
|
|
@@ -68,7 +71,7 @@ export declare interface IframeOptions {
|
|
|
68
71
|
*/
|
|
69
72
|
checkOrigin?: boolean | string[];
|
|
70
73
|
/** Set the resizing direction of the iframe. */
|
|
71
|
-
direction?:
|
|
74
|
+
direction?: IFrameDirection;
|
|
72
75
|
/** Custom iframe id. */
|
|
73
76
|
id?: string;
|
|
74
77
|
/**
|
|
@@ -79,17 +82,17 @@ export declare interface IframeOptions {
|
|
|
79
82
|
/** Set iframe-resizer license key. */
|
|
80
83
|
license: string;
|
|
81
84
|
/** Enable/disable console logging. */
|
|
82
|
-
log?:
|
|
85
|
+
log?: IFrameLogOption;
|
|
83
86
|
/** Set offset size of iframe content. */
|
|
84
87
|
offsetSize?: number;
|
|
85
88
|
/** Enable scroll bars in the iframe. */
|
|
86
|
-
scrolling?:
|
|
89
|
+
scrolling?: IFrameScrollOption;
|
|
87
90
|
/**
|
|
88
91
|
* Set the number of pixels the iframe content size has to change by,
|
|
89
92
|
* before triggering a resize of the iframe.
|
|
90
93
|
*/
|
|
91
94
|
tolerance?: number;
|
|
92
|
-
/**
|
|
95
|
+
/** @deprecated No longer required in modern browsers. */
|
|
93
96
|
waitForLoad?: boolean;
|
|
94
97
|
/** Timeout in ms before warning if iframe has not responded. */
|
|
95
98
|
warningTimeout?: number;
|
|
@@ -102,38 +105,38 @@ export declare interface IframeOptions {
|
|
|
102
105
|
/** Called after iframe is closed. */
|
|
103
106
|
onAfterClose?(iframeId: string): void;
|
|
104
107
|
/** Called when pointer enters the iframe. */
|
|
105
|
-
onMouseEnter?(data:
|
|
108
|
+
onMouseEnter?(data: IFrameMouseData): void;
|
|
106
109
|
/** Called when pointer leaves the iframe. */
|
|
107
|
-
onMouseLeave?(data:
|
|
110
|
+
onMouseLeave?(data: IFrameMouseData): void;
|
|
108
111
|
/** Called when iframe-resizer has been initialized. */
|
|
109
|
-
onReady?(iframe:
|
|
112
|
+
onReady?(iframe: IFrameComponent): void;
|
|
110
113
|
/**
|
|
111
114
|
* Receive message posted from the iframe with the
|
|
112
115
|
* parentIframe.sendMessage() method.
|
|
113
116
|
*/
|
|
114
|
-
onMessage?(data:
|
|
117
|
+
onMessage?(data: IFrameMessageData): void;
|
|
115
118
|
/**
|
|
116
119
|
* Called after iframe resized. Passes event data containing the iframe,
|
|
117
120
|
* height, width and the type of event that triggered the resize.
|
|
118
121
|
*/
|
|
119
|
-
onResized?(data:
|
|
122
|
+
onResized?(data: IFrameResizedData): void;
|
|
120
123
|
/**
|
|
121
124
|
* Called before the page is repositioned after a request from the iframe.
|
|
122
125
|
* If this function returns false, it will stop the library from
|
|
123
126
|
* repositioning the page, so that you can implement your own scrolling.
|
|
124
127
|
*/
|
|
125
|
-
onScroll?(data:
|
|
128
|
+
onScroll?(data: IFrameScrollData): boolean | void;
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
export declare interface
|
|
129
|
-
iframe:
|
|
131
|
+
export declare interface IFrameResizedData {
|
|
132
|
+
iframe: IFrameComponent;
|
|
130
133
|
height: number;
|
|
131
134
|
width: number;
|
|
132
135
|
type: string;
|
|
133
136
|
}
|
|
134
137
|
|
|
135
|
-
export declare interface
|
|
136
|
-
iframe:
|
|
138
|
+
export declare interface IFrameScrollData {
|
|
139
|
+
iframe: IFrameComponent;
|
|
137
140
|
top: number;
|
|
138
141
|
left: number;
|
|
139
142
|
/** @deprecated Use `left` instead. */
|
|
@@ -142,7 +145,9 @@ export declare interface IframeScrollData {
|
|
|
142
145
|
y: number;
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
export declare type
|
|
148
|
+
export declare type IFrameScrollOption = boolean | typeof AUTO | typeof OMIT;
|
|
149
|
+
|
|
150
|
+
export { IFrameVersion }
|
|
146
151
|
|
|
147
152
|
export { LOG_COLLAPSED }
|
|
148
153
|
|
package/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @preserve
|
|
3
3
|
*
|
|
4
|
-
* @module iframe-resizer/core 6.0.0-beta.
|
|
4
|
+
* @module iframe-resizer/core 6.0.0-beta.11 (esm) - 2026-04-21
|
|
5
5
|
*
|
|
6
|
-
* @license GPL-3.0 For use with GPL compliant sites (fully published front & backend source code)
|
|
6
|
+
* @license GPL-3.0-only For use with GPL compliant sites (fully published front & backend source code)
|
|
7
7
|
* Alternatively for commercial use, you can purchase a license from
|
|
8
8
|
* https://iframe-resizer.com/pricing
|
|
9
9
|
*
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
import{esModuleInterop as e,createFormatAdvise as n,id as i,deprecate as t,isString as o,isIframe as r,isolateUserCode as s,addEventListener as a,removeEventListener as c,getModeData as d,getModeLabel as l,once as f,typeAssert as u,hasOwn as g,setMode as m,isObject as h}from"@iframe-resizer/common";import{PARENT as p,LABEL as b,BOLD as w,AUTO as y,VERTICAL as $,COLLAPSE as v,LOG_COLLAPSED as k,LOG_EXPANDED as T,EXPAND as z,LOG_DISABLED as x,MESSAGE_ID as O,INIT_EVENTS as M,SEPARATOR as I,RESIZE as E,MESSAGE_ID_LENGTH as S,VERSION as R,FUNCTION as C,MESSAGE_HEADER_LENGTH as L,HEIGHT as A,WIDTH as W,INIT as P,RESET as B,LOAD as D,SCROLL as H,PAGE_INFO as N,PARENT_INFO as F,TITLE as j,SCROLL_TO_OFFSET as q,SCROLL_TO as G,SCROLL_BY as _,PARENT_INFO_STOP as J,PAGE_INFO_STOP as U,MOUSE_LEAVE as X,MOUSE_ENTER as V,MESSAGE as Y,IN_PAGE_LINK as K,CLOSE as Q,BEFORE_UNLOAD as Z,AUTO_RESIZE as ee,CHILD_READY_MESSAGE as ne,STRING as ie,NEW_LINE as te,CHILD as oe,NUMBER as re,OBJECT as se,INIT_FROM_IFRAME as ae,LAZY as ce,RESET_REQUIRED_METHODS as de,MIN_SIZE as le,ONLOAD as fe,HORIZONTAL as ue,BOTH as ge,NONE as me,REMOVED_NEXT_VERSION as he,OFFSET_SIZE as pe,OFFSET as be,HIDDEN as we,OMIT as ye,LOG_OPTIONS as $e}from"@iframe-resizer/common/consts";import{LOG_COLLAPSED as ve,LOG_DISABLED as ke,LOG_EXPANDED as Te}from"@iframe-resizer/common/consts";import ze,{NORMAL as xe,HIGHLIGHT as Oe,FOREGROUND as Me}from"auto-console-group";const Ie={},Ee=e(ze);let Se=!0;const Re=Ee({expand:!1,label:p}),Ce=e=>window.top===window.self?`parent(${e})`:`nested parent(${e})`;const Le=e=>(n,...i)=>Ie[n]?Ie[n].console[e](...i):Re[e](...i),Ae=e=>(n,...i)=>!0===(e=>Ie[e]?Ie[e].log:Se)(n)?Le(e)(n,...i):null,We=Ae("log"),Pe=We,Be=Ae("debug"),De=Le("warn"),He=Le("error"),Ne=Le("event"),Fe=Le("purge"),je=Le("endAutoGroup"),qe=Le("errorBoundary");const Ge=n(i),_e=(e,...i)=>Ie[e]?Ie[e].console.warn(...i.map(Ge)):queueMicrotask(()=>{const t=n((e=>(...n)=>[`${b}(${e})`,...n].join(" "))(e));console?.warn(...i.map(t))}),Je=t(_e);Je("Function"),Je("Method"),Je("Option");const Ue=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:$,firstRun:!0,inPageLinks:!1,heightCalculationMethod:y,id:"iframeResizer",log:!1,logExpand:!1,license:void 0,mouseEvents:!0,offsetHeight:null,offsetWidth:null,postMessageTarget:null,sameDomain:!1,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,waitForLoad:!1,warningTimeout:5e3,widthCalculationMethod:y,onBeforeClose:()=>!0,onAfterClose(){},onMessage(){console.warn("","onMessage function not defined")},onMouseEnter(){},onMouseLeave(){},onReady(){},onResized(){},onScroll:()=>!0});let Xe=0;function Ve(e,n){let{id:i}=e;if(i&&!o(i))throw new TypeError("Invalid id for iframe. Expected String");return i&&""!==i||(i=function(e){const n=e?.id||Ue.id+Xe++;return null===document.getElementById(n)?n:`${n}${Xe++}`}(n),e.id=i,Ne(i,"assignId"),We(i,`Added missing iframe ID: ${i} (${e.src})`)),i}function Ye(e,n,i){function t(t){const o=e in M?(e=>e.split(I).filter((e,n)=>19!==n).join(I))(n):n;Pe(i,t,Oe,Me,Oe),Pe(i,`Message data: %c${o}`,Oe)}const{iframe:o,postMessageTarget:r,sameOrigin:s,targetOrigin:a}=Ie[i];if(s)try{return o.contentWindow.iframeChildListener(O+n),void t(`Sending message to iframe %c${i}%c via same origin%c`)}catch(c){e in M?(Ie[i].sameOrigin=!1,We(i,"New iframe does not support same origin")):De(i,"Same origin messaging failed, falling back to postMessage")}t(`Sending message to iframe: %c${i}%c targetOrigin: %c${a.join(", ")}`);for(const d of a)r.postMessage(O+n,d)}function Ke(e,n,i){Ne(i,e),Ie[i]?.postMessageTarget?Ye(e,n,i):De(i,"Iframe not found")}function Qe(){var e,n;!0!==document.hidden&&(e="tabVisible",n=E,Object.values(Ie).filter(({autoResize:e,firstRun:n})=>e&&!n).forEach(({iframe:i})=>Ke(e,n,i.id)))}function Ze(e){const n=e.slice(S).split(":"),i=n[1]?Number(n[1]):0,t=Ie[n[0]]?.iframe,o=t?getComputedStyle(t):null,r=o?function(e){return"border-box"!==e.boxSizing?0:(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}(o)+function(e){return"border-box"!==e.boxSizing?0:(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}(o):0,s={iframe:t,id:n[0],height:i+r,width:Number(n[2]),type:n[3],message:n[4]};return n[5]&&(s.mode=n[5]),s}const en={true:1,false:1,undefined:1};function nn(e,n,i){if(!Ie[e])return null;const t=Ie[e][n];if(typeof t!==C)throw new TypeError(`${n} on iframe[${e}] is not a function`);if("onBeforeClose"!==n&&"onScroll"!==n)return s(t,i);try{return t(i)}catch(o){return console.error(o),De(e,`Error in ${n} callback`),null}}function tn(e,n){const{lastMessage:i}=Ie[e];return i.slice(i.indexOf(I)+L+n)}function on(e,n){const{id:i,iframe:t,height:o,type:r,width:s}=n;let a={x:0,y:0};if(0===s&&0===o){const e=tn(i,9).split(I);a={x:e[1],y:e[0]}}else a={x:s,y:o};nn(i,e,{iframe:t,screenX:Number(a.x),screenY:Number(a.y),type:r})}const rn={position:null,version:R};function sn(){rn.position=null}function an(e){return null===rn.position&&(rn.position={x:window.scrollX,y:window.scrollY}),We(e,`Get page position: %c${rn.position.x}%c, %c${rn.position.y}`,Oe,Me,Oe),rn.position}function cn(e){null!==rn.position&&(window.scrollTo(rn.position.x,rn.position.y),Pe(e,`Set page position: %c${rn.position.x}%c, %c${rn.position.y}`,Oe,Me,Oe),sn())}function dn(e,n){const{id:i}=n,t=`${n[e]}px`;Ie[i].iframe.style[e]=t,Pe(i,`Set ${e}: %c${t}`,Oe)}function ln(e){const{id:n}=e,{sizeHeight:i,sizeWidth:t}=Ie[n];i&&dn(A,e),t&&dn(W,e)}function fn(e){const{id:n}=e;ln(e),cn(n),nn(n,"onResized",e)}function un(e){const{id:n}=e;We(n,"Disconnected from iframe"),delete Ie[n],delete e.iframeResizer}function gn(e){const{id:n}=e;if(!1!==nn(n,"onBeforeClose",n)){We(n,`Removing iframe: %c${n}`,Oe);try{e.parentNode&&e.remove()}catch(i){De(n,i)}nn(n,"onAfterClose",n),un(e)}else We(n,"Close iframe cancelled by onBeforeClose")}function mn(e){const{id:n,type:i}=e;We(n,"Size reset requested by "+(i===P?"parent page":"child page")),an(n),ln(e),Ke(B,B,n)}const hn=(e,n)=>{const i={};return(t,o)=>{const{iframe:r}=Ie[o];var s,a;s=function(){Ke(`${t} (${e})`,`${e}:${n(r)}`,o)},i[a=o]||(s(),i[a]=requestAnimationFrame(()=>{i[a]=null}))}},pn=e=>n=>{e in Ie[n]&&(Ie[n][e](),delete Ie[n][e])},bn=(e,n)=>i=>{let t=!1;const o=n=>()=>{Ie[i]?t&&t!==n||(e(n,i),t=n,requestAnimationFrame(()=>{t=!1})):u()},r=o(H),s=o("resize window"),d=new ResizeObserver(o("pageObserver")),l=new ResizeObserver(o("iframeObserver"));function f(e,t){We(i,`${e}listeners for send${n}`),t(window,H,r),t(window,E,s)}function u(){Ne(i,`stop${n}`),f("Remove ",c),d.disconnect(),l.disconnect(),Ie[i]&&c(Ie[i].iframe,D,u)}Ie[i]&&(Ie[i][`stop${n}`]=u,a(Ie[i].iframe,D,u),f("Add ",a),d.observe(document.body),l.observe(Ie[i].iframe))};const wn=bn(hn(N,function(e){const n=document.body.getBoundingClientRect(),i=e.getBoundingClientRect(),{scrollY:t,scrollX:o,innerHeight:r,innerWidth:s}=window,{clientHeight:a,clientWidth:c}=document.documentElement;return JSON.stringify({iframeHeight:i.height,iframeWidth:i.width,clientHeight:Math.max(a,r||0),clientWidth:Math.max(c,s||0),offsetTop:Math.trunc(i.top-n.top),offsetLeft:Math.trunc(i.left-n.left),scrollTop:t,scrollLeft:o,documentHeight:a,documentWidth:c,windowHeight:r,windowWidth:s})}),"PageInfo"),yn=pn("stopPageInfo");const $n=bn(hn(F,function(e){const{scrollWidth:n,scrollHeight:i}=document.documentElement,t="undefined"!=typeof window&&window.visualViewport?window.visualViewport:{},{width:o=0,height:r=0,offsetLeft:s=0,offsetTop:a=0,pageLeft:c=0,pageTop:d=0,scale:l=1}=t;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:n,scrollHeight:i},viewport:{width:o,height:r,offsetLeft:s,offsetTop:a,pageLeft:c,pageTop:d,scale:l}})}),"ParentInfo"),vn=pn("stopParentInfo");function kn(e){const n=e.getBoundingClientRect(),i=an(e.id);return{x:Number(n.left)+Number(i.x),y:Number(n.top)+Number(i.y)}}function Tn(e){const{x:n,y:i}=rn.position,t=Ie[e]?.iframe;!1!==nn(e,"onScroll",{iframe:t,top:i,left:n,x:n,y:i})?cn(e):sn()}const zn=e=>n=>{const{id:i,iframe:t,height:o,width:r}=n;const s=e?kn(t):{x:0,y:0},a={x:r+(c=s).x,y:o+c.y};var c;const d=window.parentIframe||window.parentIFrame;var l;Pe(i,`Reposition requested (offset x:%c${s.x}%c y:%c${s.y})`,Oe,Me,Oe),d?(l=a,d["scrollTo"+(e?"Offset":"")](l.x,l.y)):function(e){var n;n=e,rn.position=n,Tn(i)}(a)},xn=zn(!1),On=zn(!0);function Mn(e,n){const i=n.split("#")[1]||"",t=decodeURIComponent(i),o=document.getElementById(t)||document.getElementsByName(t)[0];o?function(e,n,i){const{x:t,y:o}=kn(i);Pe(e,`Moving to in page link: %c#${n}`,Oe),rn.position={x:t,y:o},Tn(e),window.location.hash=n}(e,i,o):window.top!==window.self?function(e,n){const i=window.parentIframe||window.parentIFrame;i?i.moveToAnchor(n):We(e,`In page link #${n} not found`)}(e,i):We(e,`In page link #${i} not found`)}function In(e){const n=Ie[e]?.iframe?.title;return""===n||void 0===n}let En=!1,Sn=!1;function Rn(e,n=-3){if(En)return;const i=Math.max(Ie[e].mode,n);if(i>Ie[e].mode&&(Ie[e].mode=i),i<0)throw Fe(e),Ie[e].vAdvised||_e(e||"Parent",`${d(i+2)}${d(2)}`),Ie[e].vAdvised=!0,d(i+2).replace(/<\/?[a-z][^>]*>|<\/>/gi,"");switch(i>5&&Sn||function(e,n){queueMicrotask(()=>console.info(`%ciframe-resizer ${e}`,Se||n<1?w:xe))}(`v${R} (${l(i)})`,i),i){case 1:case 2:case 3:_e("Parent",d(6));break;case 4:_e("Parent",d(7));break;case 5:_e("Parent",d(8));break;default:i<1&&_e("Parent",d(3))}En=!0}function Cn(e){const{height:n,id:i,iframe:t,mode:o,message:r,type:s,width:a}=e,{lastMessage:c}=Ie[i];switch(Ie[i]?.firstRun&&function(e,n){Ie[e]&&(We(e,`First run for ${e}`),Rn(e,void 0===n?void 0:Number(n)),Ie[e].firstRun=!1)}(i,o),We(i,`Received: %c${c}`,Oe),s){case ee:Ie[i].autoResize=JSON.parse(tn(i,9));break;case Z:Pe(i,"Ready state reset"),Ie[i].initialised=!1;break;case Q:gn(t);break;case K:Mn(i,tn(i,9));break;case P:fn(e),function(e){try{Ie[e].sameOrigin=!!Ie[e]?.iframe?.contentWindow?.iframeChildListener}catch(n){Ie[e].sameOrigin=!1}We(e,`sameOrigin: %c${Ie[e].sameOrigin}`,Oe)}(i),function(e,n){n!==R&&(void 0!==n?We(e,`Version mismatch (Child: %c${n}%c !== Parent: %c${R})`,Oe,Me,Oe):_e(e,"<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"))}(i,r),Ie[i].initialised=!0,nn(i,"onReady",t);break;case Y:!function(e,n){const{id:i,iframe:t}=e;We(i,`onMessage passed: {iframe: %c${i}%c, message: %c${n}%c}`,Oe,Me,Oe,Me),nn(i,"onMessage",{iframe:t,message:JSON.parse(n)})}(e,tn(i,6));break;case V:on("onMouseEnter",e);break;case X:on("onMouseLeave",e);break;case N:wn(i);break;case F:$n(i);break;case U:yn(i);break;case J:vn(i);break;case B:mn(e);break;case _:!function(e){const{id:n,height:i,width:t}=e,o=window.parentIframe||window.parentIFrame||window;Pe(n,`scrollBy: x: %c${t}%c y: %c${i}`,Oe,Me,Oe),o.scrollBy(t,i)}(e);break;case G:xn(e);break;case q:On(e);break;case j:!function(e,n){Ie[e]?.syncTitle&&(Ie[e].iframe.title=n,Pe(e,`Set iframe title attribute: %c${n}`,Oe))}(i,r);break;default:if(0===a&&0===n)return void De(i,`Unsupported message received (${s}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===a||0===n)return void We(i,"Ignoring message with 0 height or width");if(document.hidden)return void We(i,"Page hidden - ignored resize request");fn(e)}}function Ln(e){const n=e.data;if(n===ne)return i=e.source,void Object.values(Ie).forEach((e=>({initChild:n,postMessageTarget:i})=>{e===i&&n()})(i));var i,t;if(O!==`${t=n}`.slice(0,S)||!(t.slice(S).split(":")[0]in Ie)){if(typeof n!==ie)return;return Ne(p,"ignoredMessage"),void Be(p,n)}const o=Ze(n),{id:s,type:a}=o;switch(Ne(s,a),!0){case!Ie[s]:throw new Error(`${a} No settings for ${s}. Message was: ${n}`);case!function(e){const{id:n,message:i,iframe:t}=e,o=r(t);return o||(We(n,`Received: %c${i}`,Oe),De(n,"The target iframe was not found.")),o}(o):case function(e){const{id:n,type:i}=e,t=i in en;return t&&We(n,"Ignoring init message from meta parent page"),t}(o):case!function(e,n){const{id:i}=e,{data:t,origin:o}=n;if("sameOrigin"in n&&n.sameOrigin)return!0;const r=Ie[i]?.checkOrigin;if(r&&"null"!=`${o}`&&!(r.constructor===Array?function(){We(i,`Checking connection is from allowed list of origins: %c${r}`,Oe);for(const e of r)if(e===o)return!0;return!1}():function(){const e=Ie[i]?.remoteHost;return We(i,`Checking connection is from: %c${e}`,Oe),o===e}()))throw new Error(`Unexpected message received from: ${o} for ${i}. Message was: ${t}. This error can be disabled by setting the checkOrigin: false option or by providing an array of trusted domains.`);return!0}(o,e):return;default:Ie[s].lastMessage=e.data,qe(s,Cn)(o)}}const An=f(()=>{a(window,Y,Ln),a(document,"visibilitychange",Qe),window.iframeParentListener=e=>setTimeout(()=>Ln({data:e,sameOrigin:!0}))}),Wn={};const Pn="8",Bn="32",Dn=oe,Hn=!0;function Nn(e,n){const{checkOrigin:i,iframe:{src:t,sandbox:o},initialisedFirstPage:r,waitForLoad:s}=n[e],a=(e=>{try{return new URL(e).origin}catch(n){return null}})(t);Ne(e,"noResponse"),_e(e,`<rb>No response from iframe</>\n\nThe iframe (<i>${e}</>) has not responded within ${n[e].warningTimeout/1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.\n${i&&a?`\nThe <b>checkOrigin</> option is currently enabled. If the iframe redirects away from <i>${a}</>, then the connection to the iframe may be blocked by the browser. To disable this option, set <b>checkOrigin</> to <bb>false</> or an array of allowed origins. See <u>https://iframe-resizer.com/checkorigin</> for more information.\n`:""}${s&&!r?"\nThe <b>waitForLoad</> option is currently set to <bb>true</>. If the iframe loads before <i>iframe-resizer</> runs, this option will prevent <i>iframe-resizer</> initialising. To disable this option, set <b>waitForLoad</> to <bb>false</>.\n":""}${(e=>typeof e===se&&e.length>0&&!(e.contains("allow-scripts")&&e.contains("allow-same-origin")))(o)?"\nThe iframe has the <b>sandbox</> attribute, please ensure it contains both the <bb>allow-same-origin</> and <bb>allow-scripts</> values.\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`)}function Fn(e,n){const i=i=>()=>{if(!Ie[e])return;const{firstRun:t,iframe:o}=Ie[e];Ke(i,n,e),(e=>e===P)(i)&&(e=>e.loading===ce)(o)||function(e,n){const{msgTimeout:i,warningTimeout:t}=n[e];t&&(i&&clearTimeout(i),n[e].msgTimeout=setTimeout(function(){if(void 0===n[e])return;const{initialised:i,loadErrorShown:t}=n[e];n[e].msgTimeout=void 0,i?n[e].initialisedFirstPage=!0:t||(n[e].loadErrorShown=!0,Nn(e,n))},t))}(e,Ie),t||function(e){Ie[e]?.heightCalculationMethod in de&&mn({id:e,iframe:Ie[e].iframe,height:le,width:le,type:P})}(e)},{iframe:t}=Ie[e];Ie[e].initChild=i(ae),function(e,n){a(e,D,()=>setTimeout(n,1))}(t,i(fe)),function(e,n){const{iframe:i,waitForLoad:t}=Ie[e];!0!==t&&((e=>{const{src:n,srcdoc:i}=e;return!i&&(null==n||""===n||"about:blank"===n)})(i)?setTimeout(()=>{Ne(e,"noContent"),Pe(e,"No content detected in the iframe, delaying initialisation")}):setTimeout(n))}(e,i(P))}function jn(e,n){return n?(("sizeWidth"in n||"sizeHeight"in n||ee in n)&&_e(e,`<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 <bb>${$}</>, <bb>${ue}</>, <bb>${ge}</> or <bb>${me}</>.\n`),n):{}}const qn=e=>""===e||null!==e.match(/^(about:blank|javascript:|file:\/\/)/)?"*":e;function Gn(e,n,i){g(Ie[e],n)&&(_e(e,`<rb>Deprecated option</>\n\nThe <b>${n}</> option has been renamed to <b>${i}</>. ${he}`),Ie[e][i]=Ie[e][n],delete Ie[e][n])}const _n=e=>g(e,"onMouseEnter")||g(e,"onMouseLeave");function Jn(e,n){const{id:i}=e;Ie[i]={...Ie[i],iframe:e,remoteHost:e?.src.split("/").slice(0,3).join("/"),...Ue,...jn(i,n),mouseEvents:_n(n),mode:m(n),syncTitle:In(i)},function(e){Gn(e,be,pe),Gn(e,"onClose","onBeforeClose"),Gn(e,"onClosed","onAfterClose")}(i),function(e){const{direction:n}=Ie[e];switch(n){case $:break;case ue:Ie[e].sizeHeight=!1;case ge:Ie[e].sizeWidth=!0;break;case me:Ie[e].sizeWidth=!1,Ie[e].sizeHeight=!1,Ie[e].autoResize=!1;break;default:throw new TypeError(`Direction value of "${n}" is not valid`)}We(e,`direction: %c${n}`,Oe)}(i),function(e,{offset:n,offsetSize:i}){const t=i||n;t&&(Ie[e].direction===$?(Ie[e].offsetHeight=t,We(e,`Offset height: %c${t}`,Oe)):(Ie[e].offsetWidth=t,We(e,`Offset width: %c${t}`,Oe)))}(i,n),function(e){Ie[e].warningTimeout||Pe(e,"warningTimeout:%c disabled",Oe)}(i),function(e){const{id:n}=e;null===Ie[n].postMessageTarget&&(Ie[n].postMessageTarget=e.contentWindow)}(e),function(e){const{checkOrigin:n,remoteHost:i}=Ie[e];Array.isArray(n)&&0===n.length&&De(e,"checkOrigin is an empty array — no messages will be sent to the iframe"),Ie[e].targetOrigin=Array.isArray(n)?n.map(qn):[!1===n?"*":qn(i)]}(i)}function Un(e,n,i){Jn(n,i),We(e,`src: %c${n.srcdoc||n.src}`,Oe),function(e){if(En)return;const{mode:n}=Ie[e];n>5&&Rn(e,n)}(e),function(e){const{id:n}=e;switch(We(n,`Iframe scrolling ${Ie[n]?.scrolling?"enabled":"disabled"} for ${n}`),e.style.overflow=!1===Ie[n]?.scrolling?we:y,Ie[n]?.scrolling){case ye:break;case!0:e.scrolling="yes";break;case!1:e.scrolling="no";break;default:e.scrolling=Ie[n]?.scrolling||"no"}}(n),function(e){const{bodyMargin:n}=Ie[e];typeof n!==re&&"0"!==n||(Ie[e].bodyMargin=`${n}px`)}(e),Fn(e,function(e){const{autoResize:n,bodyBackground:i,bodyMargin:t,bodyPadding:o,heightCalculationMethod:r,inPageLinks:s,license:a,log:c,logExpand:d,mouseEvents:l,offsetHeight:f,offsetWidth:u,mode:g,sizeHeight:m,sizeWidth:h,tolerance:p,widthCalculationMethod:b}=Ie[e];return[e,Pn,h,c,Bn,Hn,n,t,r,i,o,p,s,Dn,b,l,f,u,m,a,rn.version,g,"",d].join(I)}(e)),function(e){if(Ie[e]){const{iframe:n}=Ie[e];n.iframeResizer={close:gn.bind(null,n),disconnect:un.bind(null,n),moveToAnchor(n){u(n,ie,"moveToAnchor(anchor) anchor"),Ke("Move to anchor",`moveToAnchor:${n}`,e)},sendMessage(n){n=JSON.stringify(n),Ke(Y,`${Y}:${n}`,e)}}}}(e),We(e,"Setup complete")}function Xn(e,n){const{id:i}=e;Ne(i,"setup"),function(e){if(!0===Wn[e])return!1;const n=document.querySelectorAll(`iframe#${CSS.escape(e)}`);if(n.length<=1)return!0;Wn[e]=!0;const i=Array.from(n).flatMap(e=>[te,e,te]);return _e(e,`<rb>Duplicate ID attributes detected</>\n\nThe <b>${e}</> ID is not unique. Having multiple iframes on the same page with the same ID causes problems with communication between the iframe and parent page. Please ensure that the ID of each iframe has a unique value.\n\nFound <bb>${n.length}</> iframes with the <b>${e}</> ID:`,...i,te),!1}(i)&&Un(i,e,n),je(i)}function Vn(e,n){n.log===x?n.log=!1:n.log===k?n.log=v:n.log===T&&(n.log=z);const i=g(n,"log"),t=o(n.log),r=i?!!t||n.log:Ue.log;g(n,"logExpand")||(n.logExpand=i&&t?n.log===z:Ue.logExpand),function(e){-1===e?.log&&(e.log=!1,Sn=!0)}(n),function({enabled:e,expand:n,iframeId:i}){const t=Ee({expand:n,label:Ce(i)});Se=e,Ie[i]||(Ie[i]={console:t})}({enabled:r,expand:n.logExpand,iframeId:e}),t&&!(n.log in $e)&&He(e,`Invalid value for options.log: Accepted values are "${z}" and "${v}"`),n.log=r}function Yn(e){if(!h(e))throw new TypeError("Options is not an object");return An(),function(e){const{search:n}=window.location;if(n.includes("ifrlog"))switch(new URLSearchParams(n).get("ifrlog")){case String(x):e.log=!1;break;case z:case String(T):e.log=z;break;case v:case String(k):default:e.log=v}}(e),n=>{const i=Ve(n,e);return b in n?(Ne(i,"alreadySetup"),De(i,`Ignored iframe (${i}), already setup.`)):(Vn(i,e),qe(i,Xn)(n,e)),n.iframeResizer}}export{ve as LOG_COLLAPSED,ke as LOG_DISABLED,Te as LOG_EXPANDED,Yn as default};
|
|
20
|
+
import{esModuleInterop as e,createFormatAdvise as n,id as i,deprecate as t,isString as o,isIframe as r,isolateUserCode as s,addEventListener as a,removeEventListener as c,getModeData as d,getModeLabel as l,once as f,typeAssert as u,hasOwn as g,setMode as m,isObject as h}from"@iframe-resizer/common";import{PARENT as p,LABEL as b,BOLD as w,AUTO as y,VERTICAL as $,COLLAPSE as v,LOG_COLLAPSED as k,LOG_EXPANDED as T,EXPAND as O,LOG_DISABLED as z,MESSAGE_ID as x,INIT_EVENTS as M,SEPARATOR as I,RESIZE as E,MESSAGE_ID_LENGTH as S,VERSION as R,FUNCTION as C,MESSAGE_HEADER_LENGTH as L,HEIGHT as A,WIDTH as W,INIT as P,RESET as B,LOAD as D,SCROLL as H,PAGE_INFO as N,PARENT_INFO as F,TITLE as j,SCROLL_TO_OFFSET as q,SCROLL_TO as G,SCROLL_BY as V,PARENT_INFO_STOP as _,PAGE_INFO_STOP as J,MOUSE_LEAVE as U,MOUSE_ENTER as X,MESSAGE as Y,IN_PAGE_LINK as K,CLOSE as Q,BEFORE_UNLOAD as Z,AUTO_RESIZE as ee,CHILD_READY_MESSAGE as ne,STRING as ie,NEW_LINE as te,CHILD as oe,NUMBER as re,OBJECT as se,INIT_FROM_IFRAME as ae,LAZY as ce,RESET_REQUIRED_METHODS as de,MIN_SIZE as le,ONLOAD as fe,HORIZONTAL as ue,BOTH as ge,NONE as me,REMOVED_NEXT_VERSION as he,OFFSET_SIZE as pe,OFFSET as be,HIDDEN as we,OMIT as ye,LOG_OPTIONS as $e}from"@iframe-resizer/common/consts";import{LOG_COLLAPSED as ve,LOG_DISABLED as ke,LOG_EXPANDED as Te}from"@iframe-resizer/common/consts";import Oe,{NORMAL as ze,HIGHLIGHT as xe,FOREGROUND as Me}from"auto-console-group";const Ie={},Ee=e(Oe);let Se=!0;const Re=Ee({expand:!1,label:p}),Ce=e=>window.top===window.self?`parent(${e})`:`nested parent(${e})`;const Le=e=>(n,...i)=>Ie[n]?Ie[n].console[e](...i):Re[e](...i),Ae=e=>(n,...i)=>!0===(e=>Ie[e]?Ie[e].log:Se)(n)?Le(e)(n,...i):null,We=Ae("log"),Pe=We,Be=Ae("debug"),De=Le("warn"),He=Le("error"),Ne=Le("event"),Fe=Le("purge"),je=Le("endAutoGroup"),qe=Le("errorBoundary");const Ge=n(i),Ve=(e,...i)=>Ie[e]?Ie[e].console.warn(...i.map(Ge)):queueMicrotask(()=>{const t=n((e=>(...n)=>[`${b}(${e})`,...n].join(" "))(e));console?.warn(...i.map(t))}),_e=t(Ve);_e("Function"),_e("Method"),_e("Option");const Je=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:$,firstRun:!0,inPageLinks:!1,heightCalculationMethod:y,id:"iframeResizer",log:!1,logExpand:!1,license:void 0,mouseEvents:!0,offsetHeight:null,offsetWidth:null,postMessageTarget:null,sameOrigin:!0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,waitForLoad:!1,warningTimeout:5e3,widthCalculationMethod:y,onBeforeClose:()=>!0,onAfterClose(){},onMessage(){console.warn("","onMessage function not defined")},onMouseEnter(){},onMouseLeave(){},onReady(){},onResized(){},onScroll:()=>!0});let Ue=0;function Xe(e,n){let{id:i}=e;if(i&&!o(i))throw new TypeError("Invalid id for iframe. Expected String");return i&&""!==i||(i=function(e){const n=e?.id||Je.id+Ue++;return null===document.getElementById(n)?n:`${n}${Ue++}`}(n),e.id=i,Ne(i,"assignId"),We(i,`Added missing iframe ID: ${i} (${e.src})`)),i}function Ye(e,n,i){function t(t){const o=e in M?(e=>e.split(I).filter((e,n)=>19!==n).join(I))(n):n;Pe(i,t,xe,Me,xe),Pe(i,`Message data: %c${o}`,xe)}const{iframe:o,postMessageTarget:r,sameOrigin:s,targetOrigin:a}=Ie[i];if(s)try{return o.contentWindow.iframeChildListener(x+n),void t(`Sending message to iframe %c${i}%c via same origin%c`)}catch(c){e in M?(Ie[i].sameOrigin=!1,We(i,"New iframe does not support same origin")):De(i,"Same origin messaging failed, falling back to postMessage")}t(`Sending message to iframe: %c${i}%c targetOrigin: %c${a.join(", ")}`);for(const d of a)r.postMessage(x+n,d)}function Ke(e,n,i){Ne(i,e),Ie[i]?.postMessageTarget?Ye(e,n,i):De(i,"Iframe not found")}function Qe(){var e,n;!0!==document.hidden&&(e="tabVisible",n=E,Object.values(Ie).filter(({autoResize:e,firstRun:n})=>e&&!n).forEach(({iframe:i})=>Ke(e,n,i.id)))}function Ze(e){const n=e.slice(S).split(":"),i=n[1]?Number(n[1]):0,t=Ie[n[0]]?.iframe,o=t?getComputedStyle(t):null,r=o?function(e){return"border-box"!==e.boxSizing?0:(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}(o)+function(e){return"border-box"!==e.boxSizing?0:(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}(o):0,s={iframe:t,id:n[0],height:i+r,width:Number(n[2]),type:n[3],message:n[4]};return n[5]&&(s.mode=n[5]),s}const en={true:1,false:1,undefined:1};function nn(e,n,i){if(!Ie[e])return null;const t=Ie[e][n];if(typeof t!==C)throw new TypeError(`${n} on iframe[${e}] is not a function`);if("onBeforeClose"!==n&&"onScroll"!==n)return s(t,i);try{return t(i)}catch(o){return console.error(o),De(e,`Error in ${n} callback`),null}}function tn(e,n){const{lastMessage:i}=Ie[e];return i.slice(i.indexOf(I)+L+n)}function on(e,n){const{id:i,iframe:t,height:o,type:r,width:s}=n;let a={x:0,y:0};if(0===s&&0===o){const e=tn(i,9).split(I);a={x:e[1],y:e[0]}}else a={x:s,y:o};nn(i,e,{iframe:t,screenX:Number(a.x),screenY:Number(a.y),type:r})}const rn={position:null,version:R};function sn(){rn.position=null}function an(e){return null===rn.position&&(rn.position={x:window.scrollX,y:window.scrollY}),We(e,`Get page position: %c${rn.position.x}%c, %c${rn.position.y}`,xe,Me,xe),rn.position}function cn(e){null!==rn.position&&(window.scrollTo(rn.position.x,rn.position.y),Pe(e,`Set page position: %c${rn.position.x}%c, %c${rn.position.y}`,xe,Me,xe),sn())}function dn(e,n){const{id:i}=n,t=`${n[e]}px`;Ie[i].iframe.style[e]=t,Pe(i,`Set ${e}: %c${t}`,xe)}function ln(e){const{id:n}=e,{sizeHeight:i,sizeWidth:t}=Ie[n];i&&dn(A,e),t&&dn(W,e)}function fn(e){const{id:n}=e;ln(e),cn(n),nn(n,"onResized",e)}function un(e){const{id:n}=e;We(n,"Disconnected from iframe"),delete Ie[n],delete e.iframeResizer}function gn(e){const{id:n}=e;if(!1!==nn(n,"onBeforeClose",n)){We(n,`Removing iframe: %c${n}`,xe);try{e.parentNode&&e.remove()}catch(i){De(n,i)}nn(n,"onAfterClose",n),un(e)}else We(n,"Close iframe cancelled by onBeforeClose")}function mn(e){const{id:n,type:i}=e;We(n,"Size reset requested by "+(i===P?"parent page":"child page")),an(n),ln(e),Ke(B,B,n)}const hn=(e,n)=>{const i={};return(t,o)=>{const{iframe:r}=Ie[o];var s,a;s=function(){Ke(`${t} (${e})`,`${e}:${n(r)}`,o)},i[a=o]||(s(),i[a]=requestAnimationFrame(()=>{i[a]=null}))}},pn=e=>n=>{e in Ie[n]&&(Ie[n][e](),delete Ie[n][e])},bn=(e,n)=>i=>{let t=!1;const o=n=>()=>{Ie[i]?t&&t!==n||(e(n,i),t=n,requestAnimationFrame(()=>{t=!1})):u()},r=o(H),s=o("resize window"),d=new ResizeObserver(o("pageObserver")),l=new ResizeObserver(o("iframeObserver"));function f(e,t){We(i,`${e}listeners for send${n}`),t(window,H,r),t(window,E,s)}function u(){Ne(i,`stop${n}`),f("Remove ",c),d.disconnect(),l.disconnect(),Ie[i]&&c(Ie[i].iframe,D,u)}Ie[i]&&(Ie[i][`stop${n}`]=u,a(Ie[i].iframe,D,u),f("Add ",a),d.observe(document.body),l.observe(Ie[i].iframe))};const wn=bn(hn(N,function(e){const n=document.body.getBoundingClientRect(),i=e.getBoundingClientRect(),{scrollY:t,scrollX:o,innerHeight:r,innerWidth:s}=window,{clientHeight:a,clientWidth:c}=document.documentElement;return JSON.stringify({iframeHeight:i.height,iframeWidth:i.width,clientHeight:Math.max(a,r||0),clientWidth:Math.max(c,s||0),offsetTop:Math.trunc(i.top-n.top),offsetLeft:Math.trunc(i.left-n.left),scrollTop:t,scrollLeft:o,documentHeight:a,documentWidth:c,windowHeight:r,windowWidth:s})}),"PageInfo"),yn=pn("stopPageInfo");const $n=bn(hn(F,function(e){const{scrollWidth:n,scrollHeight:i}=document.documentElement,t="undefined"!=typeof window&&window.visualViewport?window.visualViewport:{},{width:o=0,height:r=0,offsetLeft:s=0,offsetTop:a=0,pageLeft:c=0,pageTop:d=0,scale:l=1}=t;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:n,scrollHeight:i},viewport:{width:o,height:r,offsetLeft:s,offsetTop:a,pageLeft:c,pageTop:d,scale:l}})}),"ParentInfo"),vn=pn("stopParentInfo");function kn(e){const n=e.getBoundingClientRect(),i=an(e.id);return{x:Number(n.left)+Number(i.x),y:Number(n.top)+Number(i.y)}}function Tn(e){const{x:n,y:i}=rn.position,t=Ie[e]?.iframe;!1!==nn(e,"onScroll",{iframe:t,top:i,left:n,x:n,y:i})?cn(e):sn()}const On=e=>n=>{const{id:i,iframe:t,height:o,width:r}=n;const s=e?kn(t):{x:0,y:0},a={x:r+(c=s).x,y:o+c.y};var c;const d=window.parentIframe||window.parentIFrame;var l;Pe(i,`Reposition requested (offset x:%c${s.x}%c y:%c${s.y})`,xe,Me,xe),d?(l=a,d["scrollTo"+(e?"Offset":"")](l.x,l.y)):function(e){var n;n=e,rn.position=n,Tn(i)}(a)},zn=On(!1),xn=On(!0);function Mn(e,n){const i=n.split("#")[1]||"",t=decodeURIComponent(i),o=document.getElementById(t)||document.getElementsByName(t)[0];o?function(e,n,i){const{x:t,y:o}=kn(i);Pe(e,`Moving to in page link: %c#${n}`,xe),rn.position={x:t,y:o},Tn(e),window.location.hash=n}(e,i,o):window.top!==window.self?function(e,n){const i=window.parentIframe||window.parentIFrame;i?i.moveToAnchor(n):We(e,`In page link #${n} not found`)}(e,i):We(e,`In page link #${i} not found`)}function In(e){const n=Ie[e]?.iframe?.title;return""===n||void 0===n}let En=!1,Sn=!1;function Rn(e,n=-3){if(En)return;const i=Math.max(Ie[e].mode,n);if(i>Ie[e].mode&&(Ie[e].mode=i),i<0)throw Fe(e),Ie[e].vAdvised||Ve(e||"Parent",`${d(i+2)}${d(2)}`),Ie[e].vAdvised=!0,d(i+2).replace(/<\/?[a-z][^>]*>|<\/>/gi,"");switch(i>5&&Sn||function(e,n){queueMicrotask(()=>console.info(`%ciframe-resizer ${e}`,Se||n<1?w:ze))}(`v${R} (${l(i)})`,i),i){case 1:case 2:case 3:Ve("Parent",d(6));break;case 4:Ve("Parent",d(7));break;case 5:Ve("Parent",d(8));break;default:i<1&&Ve("Parent",d(3))}En=!0}function Cn(e){const{height:n,id:i,iframe:t,mode:o,message:r,type:s,width:a}=e,{lastMessage:c}=Ie[i];switch(Ie[i]?.firstRun&&function(e,n){Ie[e]&&(We(e,`First run for ${e}`),Rn(e,void 0===n?void 0:Number(n)),Ie[e].firstRun=!1)}(i,o),We(i,`Received: %c${c}`,xe),s){case ee:Ie[i].autoResize=JSON.parse(tn(i,9));break;case Z:Pe(i,"Ready state reset"),Ie[i].initialised=!1;break;case Q:gn(t);break;case K:Mn(i,tn(i,9));break;case P:fn(e),function(e){try{Ie[e].sameOrigin=!!Ie[e]?.iframe?.contentWindow?.iframeChildListener}catch(n){Ie[e].sameOrigin=!1}We(e,`sameOrigin: %c${Ie[e].sameOrigin}`,xe)}(i),function(e,n){Ie[e]&&(Ie[e].childVersion=n),n!==R&&(void 0!==n?We(e,`Version mismatch (Child: %c${n}%c !== Parent: %c${R})`,xe,Me,xe):Ve(e,"<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"))}(i,r),Ie[i].initialised=!0,nn(i,"onReady",t);break;case Y:!function(e,n){const{id:i,iframe:t}=e;We(i,`onMessage passed: {iframe: %c${i}%c, message: %c${n}%c}`,xe,Me,xe,Me),nn(i,"onMessage",{iframe:t,message:JSON.parse(n)})}(e,tn(i,6));break;case X:on("onMouseEnter",e);break;case U:on("onMouseLeave",e);break;case N:wn(i);break;case F:$n(i);break;case J:yn(i);break;case _:vn(i);break;case B:mn(e);break;case V:!function(e){const{id:n,height:i,width:t}=e,o=window.parentIframe||window.parentIFrame||window;Pe(n,`scrollBy: x: %c${t}%c y: %c${i}`,xe,Me,xe),o.scrollBy(t,i)}(e);break;case G:zn(e);break;case q:xn(e);break;case j:!function(e,n){Ie[e]?.syncTitle&&(Ie[e].iframe.title=n,Pe(e,`Set iframe title attribute: %c${n}`,xe))}(i,r);break;default:if(0===a&&0===n)return void De(i,`Unsupported message received (${s}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===a||0===n)return void We(i,"Ignoring message with 0 height or width");if(document.hidden)return void We(i,"Page hidden - ignored resize request");fn(e)}}function Ln(e){const n=e.data;if(n===ne)return i=e.source,void Object.values(Ie).forEach((e=>({initChild:n,postMessageTarget:i})=>{e===i&&n()})(i));var i,t;if(x!==`${t=n}`.slice(0,S)||!(t.slice(S).split(":")[0]in Ie)){if(typeof n!==ie)return;return Ne(p,"ignoredMessage"),void Be(p,n)}const o=Ze(n),{id:s,type:a}=o;switch(Ne(s,a),!0){case!Ie[s]:throw new Error(`${a} No settings for ${s}. Message was: ${n}`);case!function(e){const{id:n,message:i,iframe:t}=e,o=r(t);return o||(We(n,`Received: %c${i}`,xe),De(n,"The target iframe was not found.")),o}(o):case function(e){const{id:n,type:i}=e,t=i in en;return t&&We(n,"Ignoring init message from meta parent page"),t}(o):case!function(e,n){const{id:i}=e,{data:t,origin:o}=n;if("sameOrigin"in n&&n.sameOrigin)return!0;const r=Ie[i]?.checkOrigin;if(r&&"null"!=`${o}`&&!(r.constructor===Array?function(){We(i,`Checking connection is from allowed list of origins: %c${r}`,xe);for(const e of r)if(e===o)return!0;return!1}():function(){const e=Ie[i]?.remoteHost;return We(i,`Checking connection is from: %c${e}`,xe),o===e}()))throw new Error(`Unexpected message received from: ${o} for ${i}. Message was: ${t}. This error can be disabled by setting the checkOrigin: false option or by providing an array of trusted domains.`);return!0}(o,e):return;default:Ie[s].lastMessage=e.data,qe(s,Cn)(o)}}const An=f(()=>{a(window,Y,Ln),a(document,"visibilitychange",Qe),window.iframeParentListener=e=>setTimeout(()=>Ln({data:e,sameOrigin:!0}))}),Wn={};const Pn="8",Bn="32",Dn=oe,Hn=!0;function Nn(e,n){const{checkOrigin:i,iframe:{src:t,sandbox:o},initialisedFirstPage:r,waitForLoad:s}=n[e],a=(e=>{try{return new URL(e).origin}catch(n){return null}})(t);Ne(e,"noResponse"),Ve(e,`<rb>No response from iframe</>\n\nThe iframe (<i>${e}</>) has not responded within ${n[e].warningTimeout/1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.\n${i&&a?`\nThe <b>checkOrigin</> option is currently enabled. If the iframe redirects away from <i>${a}</>, then the connection to the iframe may be blocked by the browser. To disable this option, set <b>checkOrigin</> to <bb>false</> or an array of allowed origins. See <u>https://iframe-resizer.com/checkorigin</> for more information.\n`:""}${s&&!r?"\nThe <b>waitForLoad</> option is currently set to <bb>true</>. If the iframe loads before <i>iframe-resizer</> runs, this option will prevent <i>iframe-resizer</> initialising. To disable this option, set <b>waitForLoad</> to <bb>false</>.\n":""}${(e=>typeof e===se&&e.length>0&&!(e.contains("allow-scripts")&&e.contains("allow-same-origin")))(o)?"\nThe iframe has the <b>sandbox</> attribute, please ensure it contains both the <bb>allow-same-origin</> and <bb>allow-scripts</> values.\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`)}function Fn(e,n){const i=i=>()=>{if(!Ie[e])return;const{firstRun:t,iframe:o}=Ie[e];t&&(Ie[e].sameOrigin=!0),Ke(i,n,e),(e=>e===P)(i)&&(e=>e.loading===ce)(o)||function(e,n){const{msgTimeout:i,warningTimeout:t}=n[e];t&&(i&&clearTimeout(i),n[e].msgTimeout=setTimeout(function(){if(void 0===n[e])return;const{initialised:i,loadErrorShown:t}=n[e];n[e].msgTimeout=void 0,i?n[e].initialisedFirstPage=!0:t||(n[e].loadErrorShown=!0,Nn(e,n))},t))}(e,Ie),t||function(e){Ie[e]?.heightCalculationMethod in de&&mn({id:e,iframe:Ie[e].iframe,height:le,width:le,type:P})}(e)},{iframe:t}=Ie[e];Ie[e].initChild=i(ae),function(e,n){a(e,D,()=>setTimeout(n,1))}(t,i(fe)),function(e,n){const{iframe:i,waitForLoad:t}=Ie[e];!0!==t&&((e=>{const{src:n,srcdoc:i}=e;return!i&&(null==n||""===n||"about:blank"===n)})(i)?setTimeout(()=>{Ne(e,"noContent"),Pe(e,"No content detected in the iframe, delaying initialisation")}):setTimeout(n))}(e,i(P))}function jn(e,n){return n?(("sizeWidth"in n||"sizeHeight"in n||ee in n)&&Ve(e,`<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 <bb>${$}</>, <bb>${ue}</>, <bb>${ge}</> or <bb>${me}</>.\n`),n):{}}const qn=e=>""===e||null!==e.match(/^(about:blank|javascript:|file:\/\/)/)?"*":e;function Gn(e,n,i){g(Ie[e],n)&&(Ve(e,`<rb>Deprecated option</>\n\nThe <b>${n}</> option has been renamed to <b>${i}</>. ${he}`),Ie[e][i]=Ie[e][n],delete Ie[e][n])}const Vn=e=>g(e,"onMouseEnter")||g(e,"onMouseLeave");function _n(e,n){const{id:i}=e;Ie[i]={...Ie[i],iframe:e,remoteHost:e?.src.split("/").slice(0,3).join("/"),...Je,...jn(i,n),mouseEvents:Vn(n),mode:m(n),syncTitle:In(i)},function(e){Gn(e,be,pe),Gn(e,"onClose","onBeforeClose"),Gn(e,"onClosed","onAfterClose")}(i),function(e){const{direction:n}=Ie[e];switch(n){case $:break;case ue:Ie[e].sizeHeight=!1;case ge:Ie[e].sizeWidth=!0;break;case me:Ie[e].sizeWidth=!1,Ie[e].sizeHeight=!1,Ie[e].autoResize=!1;break;default:throw new TypeError(`Direction value of "${n}" is not valid`)}We(e,`direction: %c${n}`,xe)}(i),function(e,{offset:n,offsetSize:i}){const t=i||n;t&&(Ie[e].direction===$?(Ie[e].offsetHeight=t,We(e,`Offset height: %c${t}`,xe)):(Ie[e].offsetWidth=t,We(e,`Offset width: %c${t}`,xe)))}(i,n),function(e){Ie[e].warningTimeout||Pe(e,"warningTimeout:%c disabled",xe)}(i),function(e){const{id:n}=e;null===Ie[n].postMessageTarget&&(Ie[n].postMessageTarget=e.contentWindow)}(e),function(e){const{checkOrigin:n,remoteHost:i}=Ie[e];Array.isArray(n)&&0===n.length&&De(e,"checkOrigin is an empty array — no messages will be sent to the iframe"),Ie[e].targetOrigin=Array.isArray(n)?n.map(qn):[!1===n?"*":qn(i)]}(i)}function Jn(e,n,i){_n(n,i),We(e,`src: %c${n.srcdoc||n.src}`,xe),function(e){if(En)return;const{mode:n}=Ie[e];n>5&&Rn(e,n)}(e),function(e){const{id:n}=e;switch(We(n,`Iframe scrolling ${Ie[n]?.scrolling?"enabled":"disabled"} for ${n}`),e.style.overflow=!1===Ie[n]?.scrolling?we:y,Ie[n]?.scrolling){case ye:break;case!0:e.scrolling="yes";break;case!1:e.scrolling="no";break;default:e.scrolling=Ie[n]?.scrolling||"no"}}(n),function(e){const{bodyMargin:n}=Ie[e];typeof n!==re&&"0"!==n||(Ie[e].bodyMargin=`${n}px`)}(e),Fn(e,function(e){const{autoResize:n,bodyBackground:i,bodyMargin:t,bodyPadding:o,heightCalculationMethod:r,inPageLinks:s,license:a,log:c,logExpand:d,mouseEvents:l,offsetHeight:f,offsetWidth:u,mode:g,sizeHeight:m,sizeWidth:h,tolerance:p,widthCalculationMethod:b}=Ie[e];return[e,Pn,h,c,Bn,Hn,n,t,r,i,o,p,s,Dn,b,l,f,u,m,a,rn.version,g,"",d].join(I)}(e)),function(e){if(Ie[e]){const{iframe:n}=Ie[e];n.iframeResizer={close:gn.bind(null,n),disconnect:un.bind(null,n),getVersion:()=>({child:Ie[e]?.childVersion||"legacy",parent:R}),moveToAnchor(n){u(n,ie,"moveToAnchor(anchor) anchor"),Ke("Move to anchor",`moveToAnchor:${n}`,e)},sendMessage(n){n=JSON.stringify(n),Ke(Y,`${Y}:${n}`,e)}}}}(e),We(e,"Setup complete")}function Un(e,n){const{id:i}=e;Ne(i,"setup"),function(e){if(!0===Wn[e])return!1;const n=document.querySelectorAll(`iframe#${CSS.escape(e)}`);if(n.length<=1)return!0;Wn[e]=!0;const i=Array.from(n).flatMap(e=>[te,e,te]);return Ve(e,`<rb>Duplicate ID attributes detected</>\n\nThe <b>${e}</> ID is not unique. Having multiple iframes on the same page with the same ID causes problems with communication between the iframe and parent page. Please ensure that the ID of each iframe has a unique value.\n\nFound <bb>${n.length}</> iframes with the <b>${e}</> ID:`,...i,te),!1}(i)&&Jn(i,e,n),je(i)}function Xn(e,n){n.log===z?n.log=!1:n.log===k?n.log=v:n.log===T&&(n.log=O);const i=g(n,"log"),t=o(n.log),r=i?!!t||n.log:Je.log;g(n,"logExpand")||(n.logExpand=i&&t?n.log===O:Je.logExpand),function(e){-1===e?.log&&(e.log=!1,Sn=!0)}(n),function({enabled:e,expand:n,iframeId:i}){const t=Ee({expand:n,label:Ce(i)});Se=e,Ie[i]||(Ie[i]={console:t})}({enabled:r,expand:n.logExpand,iframeId:e}),t&&!(n.log in $e)&&He(e,`Invalid value for options.log: Accepted values are "${O}" and "${v}"`),n.log=r}function Yn(e){if(!h(e))throw new TypeError("Options is not an object");return An(),function(e){const{search:n}=window.location;if(n.includes("ifrlog"))switch(new URLSearchParams(n).get("ifrlog")){case String(z):e.log=!1;break;case O:case String(T):e.log=O;break;case v:case String(k):default:e.log=v}}(e),n=>{const i=Xe(n,e);return b in n?(Ne(i,"alreadySetup"),De(i,`Ignored iframe (${i}), already setup.`)):(Xn(i,e),qe(i,Un)(n,e)),n.iframeResizer}}export{ve as LOG_COLLAPSED,ke as LOG_DISABLED,Te as LOG_EXPANDED,Yn as default};
|
|
21
21
|
//# sourceMappingURL=index.esm.js.map
|