@open-iframe-resizer/core 1.2.0 → 1.2.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.
- package/README.md +6 -2
- package/dist/index.d.ts +77 -4
- package/dist/index.js +60 -62
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
- package/dist/child.d.ts +0 -2
- package/dist/common.d.ts +0 -16
- package/dist/compat.d.ts +0 -2
- package/dist/parent.d.ts +0 -3
- package/dist/resize-handlers.d.ts +0 -8
- package/dist/type.d.ts +0 -68
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Open Iframe Resizer
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@open-iframe-resizer/core)
|
|
6
|
+
|
|
3
7
|
## Overview
|
|
4
8
|
|
|
5
9
|
A modern, lightweight alternative for resizing iframes dynamically. It is shipped under the MIT license, making it usable in commercial projects.
|
|
@@ -13,7 +17,7 @@ If you found this plugin helpful, please consider starring the repository!
|
|
|
13
17
|
```html
|
|
14
18
|
|
|
15
19
|
<script type="module">
|
|
16
|
-
import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@latest/dist/index.js";
|
|
20
|
+
import { initialize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@latest/dist/index.min.js";
|
|
17
21
|
|
|
18
22
|
initialize({}, "#my-iframe");
|
|
19
23
|
</script>
|
|
@@ -45,7 +49,7 @@ You can execute a custom function after an iframe has been resized. Also, you ca
|
|
|
45
49
|
like `updateParentScrollOnResize` to help keep the iframe within the viewport after resizing:
|
|
46
50
|
|
|
47
51
|
```javascript
|
|
48
|
-
import { initialize, updateParentScrollOnResize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@latest/dist/index.js";
|
|
52
|
+
import { initialize, updateParentScrollOnResize } from "https://cdn.jsdelivr.net/npm/@open-iframe-resizer/core@latest/dist/index.min.js";
|
|
49
53
|
|
|
50
54
|
initialize({ onIframeResize: updateParentScrollOnResize }, "#myIframe");
|
|
51
55
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,77 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
export declare type IframeResizeEvent = MessageEvent<IframeResizeEventData>;
|
|
2
|
+
|
|
3
|
+
export declare type IframeResizeEventData = {
|
|
4
|
+
type: "iframe-resized";
|
|
5
|
+
width: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export declare const initialize: InitializeFunction;
|
|
10
|
+
|
|
11
|
+
export declare function initializeChildListener(): void;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Automatically resize the selected iframes when their inner content grows.
|
|
15
|
+
* @param settings The settings for the selected iframes. The default settings properties are picked if empty.
|
|
16
|
+
* @param selector The selector for the iframe(s) or the HTMLIFrameElement to be resized. If empty, all document iframe elements will be selected.
|
|
17
|
+
* @returns A result array, which can be used to clean up the listeners if you often remove iframes from the document.
|
|
18
|
+
*/
|
|
19
|
+
export declare type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => InitializeResult[];
|
|
20
|
+
|
|
21
|
+
export declare type InitializeResult = { unsubscribe: () => void };
|
|
22
|
+
|
|
23
|
+
export declare type InteractionState = {
|
|
24
|
+
isHovered: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export declare type ResizeContext = {
|
|
28
|
+
iframe: HTMLIFrameElement;
|
|
29
|
+
settings: Settings;
|
|
30
|
+
interactionState: InteractionState;
|
|
31
|
+
previousRenderState: ResizeRenderState;
|
|
32
|
+
nextRenderState: ResizeRenderState;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export declare type ResizeRenderState = { rect: DOMRect };
|
|
36
|
+
|
|
37
|
+
export declare type Settings = {
|
|
38
|
+
/**
|
|
39
|
+
* Offset added to the resize size (in pixels).
|
|
40
|
+
*
|
|
41
|
+
* Default: `0`
|
|
42
|
+
*/
|
|
43
|
+
offsetSize: number;
|
|
44
|
+
/**
|
|
45
|
+
* Specifies whether to check the origin of incoming messages.
|
|
46
|
+
* Accepts an array of allowed origins or a boolean.
|
|
47
|
+
* If `true`, incoming messages are allowed from the origins of the registered iframes.
|
|
48
|
+
*
|
|
49
|
+
* Default: `true`
|
|
50
|
+
*/
|
|
51
|
+
checkOrigin: string[] | boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Allows the library to communicate with a cross-origin child iframe
|
|
54
|
+
* containing the original "iframe-resizer" script.
|
|
55
|
+
* Useful if you do not control the child domain.
|
|
56
|
+
*
|
|
57
|
+
* Default: `false`
|
|
58
|
+
*/
|
|
59
|
+
enableLegacyLibSupport: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Listener that is called after the iframe has been resized.
|
|
62
|
+
* You can use a predefined handler like `updateParentScrollOnResize` or create your own custom handler.
|
|
63
|
+
*
|
|
64
|
+
* Default: `undefined`
|
|
65
|
+
*/
|
|
66
|
+
onIframeResize?: (context: ResizeContext) => void;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resize handler that scrolls to restore the iframe's position in the viewport as it was before the resize.
|
|
71
|
+
*
|
|
72
|
+
* *Note:* This behavior only triggers if the iframe is currently being hovered by the user,
|
|
73
|
+
* in order to try to limit the number of scroll as it can affect the user experience.
|
|
74
|
+
*/
|
|
75
|
+
export declare const updateParentScrollOnResize: ({ previousRenderState, nextRenderState, interactionState }: ResizeContext) => void;
|
|
76
|
+
|
|
77
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const
|
|
1
|
+
const g = () => typeof window < "u", L = () => window.self !== window.top, m = (e) => e instanceof HTMLIFrameElement, w = (e, t) => {
|
|
2
2
|
e.document.readyState === "complete" ? t() : e.addEventListener("load", t);
|
|
3
|
-
},
|
|
3
|
+
}, y = (e, t) => {
|
|
4
4
|
t(), e.addEventListener("load", t);
|
|
5
|
-
},
|
|
5
|
+
}, p = (e, t) => {
|
|
6
6
|
var i, o;
|
|
7
7
|
const n = ((i = e.contentWindow) == null ? void 0 : i.document.readyState) === "complete";
|
|
8
8
|
return e.src !== "about:blank" && ((o = e.contentWindow) == null ? void 0 : o.location.href) !== "about:blank" && n ? t() : e.addEventListener("load", t);
|
|
9
|
-
},
|
|
9
|
+
}, v = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), b = (e) => {
|
|
10
10
|
try {
|
|
11
11
|
return new URL(e.src).origin === window.location.origin;
|
|
12
12
|
} catch {
|
|
13
13
|
return !1;
|
|
14
14
|
}
|
|
15
|
-
},
|
|
15
|
+
}, I = (e) => {
|
|
16
16
|
try {
|
|
17
17
|
const t = new URL(e.src).origin;
|
|
18
18
|
if (t !== "about:blank")
|
|
@@ -20,12 +20,12 @@ const h = () => window && window.self !== window.top, l = (e) => e instanceof HT
|
|
|
20
20
|
} catch {
|
|
21
21
|
}
|
|
22
22
|
return null;
|
|
23
|
-
},
|
|
23
|
+
}, R = (e) => (Object.keys(e).forEach((t) => e[t] === void 0 && delete e[t]), e), h = (e) => {
|
|
24
24
|
const { height: t } = e.documentElement.getBoundingClientRect();
|
|
25
25
|
return Math.ceil(t);
|
|
26
26
|
};
|
|
27
|
-
function
|
|
28
|
-
|
|
27
|
+
function z(e) {
|
|
28
|
+
y(
|
|
29
29
|
e,
|
|
30
30
|
() => {
|
|
31
31
|
var t;
|
|
@@ -33,94 +33,92 @@ function O(e) {
|
|
|
33
33
|
}
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function O(e) {
|
|
37
37
|
if (typeof e.data == "string" && e.data.startsWith("[iFrameSizer]")) {
|
|
38
38
|
const [t, n] = e.data.split(":"), r = +n;
|
|
39
39
|
return r > 0 ? r : null;
|
|
40
40
|
}
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
let
|
|
45
|
-
const
|
|
46
|
-
|
|
43
|
+
const a = g() ? M() : null;
|
|
44
|
+
let l = [];
|
|
45
|
+
const D = (e, t) => {
|
|
46
|
+
if (!g())
|
|
47
|
+
return [];
|
|
48
|
+
const n = { ...v(), ...R(e ?? {}) }, r = S(t), i = E(n, r);
|
|
47
49
|
return r.map((o) => {
|
|
48
|
-
const s = { iframe: o, settings: n, interactionState: { isHovered: !1 } },
|
|
49
|
-
return
|
|
50
|
+
const s = { iframe: o, settings: n, interactionState: { isHovered: !1 } }, d = C(s, i);
|
|
51
|
+
return l.push(s), {
|
|
50
52
|
unsubscribe: () => {
|
|
51
|
-
|
|
53
|
+
d(), l = l.filter((u) => u.iframe !== o);
|
|
52
54
|
}
|
|
53
55
|
};
|
|
54
56
|
});
|
|
55
57
|
};
|
|
56
|
-
function
|
|
57
|
-
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(
|
|
58
|
+
function S(e) {
|
|
59
|
+
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(m) : e ? m(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
|
|
58
60
|
}
|
|
59
|
-
function
|
|
61
|
+
function E(e, t) {
|
|
60
62
|
if (Array.isArray(e.checkOrigin))
|
|
61
63
|
return e.checkOrigin;
|
|
62
64
|
if (!e.checkOrigin)
|
|
63
65
|
return [];
|
|
64
66
|
const n = [];
|
|
65
67
|
for (const r of t) {
|
|
66
|
-
const i =
|
|
68
|
+
const i = I(r);
|
|
67
69
|
i && n.push(i);
|
|
68
70
|
}
|
|
69
71
|
return n;
|
|
70
72
|
}
|
|
71
|
-
function
|
|
72
|
-
const n =
|
|
73
|
+
function C(e, t) {
|
|
74
|
+
const n = b(e.iframe) ? B(e) : k(e, t), r = H(e);
|
|
73
75
|
return () => {
|
|
74
76
|
n(), r();
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
|
-
function
|
|
79
|
+
function k(e, t) {
|
|
78
80
|
const { iframe: n, settings: r } = e, i = (o) => {
|
|
79
|
-
var
|
|
81
|
+
var u;
|
|
80
82
|
const s = !r.checkOrigin || t.includes(o.origin);
|
|
81
83
|
if (!(!(n.contentWindow === o.source) || !s)) {
|
|
82
|
-
if (((
|
|
83
|
-
const { height:
|
|
84
|
-
|
|
84
|
+
if (((u = o.data) == null ? void 0 : u.type) === "iframe-resized") {
|
|
85
|
+
const { height: c } = o.data;
|
|
86
|
+
c && f({ newHeight: c, registeredElement: e });
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
89
|
if (r.enableLegacyLibSupport) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
+
const c = O(o);
|
|
91
|
+
c !== null && f({ newHeight: c, registeredElement: e });
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
|
-
return window.addEventListener("message", i), r.enableLegacyLibSupport &&
|
|
96
|
+
return window.addEventListener("message", i), r.enableLegacyLibSupport && z(n), () => window.removeEventListener("message", i);
|
|
95
97
|
}
|
|
96
|
-
function
|
|
97
|
-
const
|
|
98
|
-
var i;
|
|
99
|
-
const r = (i = t.contentDocument) == null ? void 0 : i.body;
|
|
100
|
-
if (!r) {
|
|
101
|
-
console.error("Unable to observe the iframe content document body");
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
m.observe(r);
|
|
105
|
-
};
|
|
106
|
-
return v(t, n), () => {
|
|
98
|
+
function B({ iframe: e }) {
|
|
99
|
+
const t = () => {
|
|
107
100
|
var r;
|
|
108
|
-
(r =
|
|
101
|
+
const n = (r = e.contentDocument) == null ? void 0 : r.body;
|
|
102
|
+
n && (a == null || a.observe(n));
|
|
103
|
+
};
|
|
104
|
+
return p(e, t), () => {
|
|
105
|
+
var n;
|
|
106
|
+
(n = e.contentDocument) != null && n.body && (a == null || a.unobserve(e.contentDocument.body)), e.removeEventListener("load", t);
|
|
109
107
|
};
|
|
110
108
|
}
|
|
111
|
-
function H(e) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
},
|
|
115
|
-
|
|
109
|
+
function H({ iframe: e, interactionState: t }) {
|
|
110
|
+
const n = () => {
|
|
111
|
+
t.isHovered = !0;
|
|
112
|
+
}, r = () => {
|
|
113
|
+
t.isHovered = !1;
|
|
116
114
|
};
|
|
117
|
-
return
|
|
118
|
-
|
|
115
|
+
return e.addEventListener("mouseenter", n), e.addEventListener("mouseleave", r), () => {
|
|
116
|
+
e.removeEventListener("mouseenter", n), e.removeEventListener("mouseleave", r);
|
|
119
117
|
};
|
|
120
118
|
}
|
|
121
|
-
function
|
|
119
|
+
function M() {
|
|
122
120
|
const e = ({ target: t }) => {
|
|
123
|
-
const n =
|
|
121
|
+
const n = l.find((o) => {
|
|
124
122
|
var s;
|
|
125
123
|
return ((s = o.iframe.contentDocument) == null ? void 0 : s.body) === t;
|
|
126
124
|
});
|
|
@@ -129,7 +127,7 @@ function B() {
|
|
|
129
127
|
const { iframe: r } = n;
|
|
130
128
|
if (!r.contentDocument)
|
|
131
129
|
return;
|
|
132
|
-
const i =
|
|
130
|
+
const i = h(r.contentDocument);
|
|
133
131
|
i && f({ newHeight: i, registeredElement: n });
|
|
134
132
|
};
|
|
135
133
|
return new ResizeObserver((t) => t.forEach(e));
|
|
@@ -138,34 +136,34 @@ function f({ registeredElement: e, newHeight: t }) {
|
|
|
138
136
|
const { iframe: n, settings: r, interactionState: i } = e, o = n.getBoundingClientRect(), s = t + r.offsetSize;
|
|
139
137
|
if (n.style.height = `${s}px`, !r.onIframeResize)
|
|
140
138
|
return;
|
|
141
|
-
const
|
|
139
|
+
const d = {
|
|
142
140
|
iframe: n,
|
|
143
141
|
settings: { ...r },
|
|
144
142
|
interactionState: { ...i },
|
|
145
143
|
previousRenderState: { rect: o },
|
|
146
144
|
nextRenderState: { rect: n.getBoundingClientRect() }
|
|
147
145
|
};
|
|
148
|
-
r.onIframeResize(
|
|
146
|
+
r.onIframeResize(d);
|
|
149
147
|
}
|
|
150
|
-
|
|
151
|
-
function
|
|
152
|
-
L(window, () => {
|
|
148
|
+
W();
|
|
149
|
+
function W() {
|
|
150
|
+
!g() || !L() || w(window, () => {
|
|
153
151
|
const e = () => {
|
|
154
152
|
const n = {
|
|
155
153
|
type: "iframe-resized",
|
|
156
154
|
width: document.documentElement.scrollWidth,
|
|
157
|
-
height:
|
|
155
|
+
height: h(document)
|
|
158
156
|
};
|
|
159
157
|
window.parent.postMessage(n, "*");
|
|
160
158
|
};
|
|
161
159
|
new ResizeObserver(e).observe(document.body);
|
|
162
160
|
});
|
|
163
161
|
}
|
|
164
|
-
const
|
|
162
|
+
const A = ({ previousRenderState: e, nextRenderState: t, interactionState: n }) => {
|
|
165
163
|
n.isHovered && window.scrollBy(0, t.rect.bottom - e.rect.bottom);
|
|
166
164
|
};
|
|
167
165
|
export {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
D as initialize,
|
|
167
|
+
W as initializeChildListener,
|
|
168
|
+
A as updateParentScrollOnResize
|
|
171
169
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.iframeResizer={}))})(this,function(a){"use strict";const c=()=>window
|
|
1
|
+
(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.iframeResizer={}))})(this,function(a){"use strict";const c=()=>typeof window<"u",p=()=>window.self!==window.top,h=e=>e instanceof HTMLIFrameElement,y=(e,t)=>{e.document.readyState==="complete"?t():e.addEventListener("load",t)},b=(e,t)=>{t(),e.addEventListener("load",t)},v=(e,t)=>{var r,o;const n=((r=e.contentWindow)==null?void 0:r.document.readyState)==="complete";return e.src!=="about:blank"&&((o=e.contentWindow)==null?void 0:o.location.href)!=="about:blank"&&n?t():e.addEventListener("load",t)},z=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),R=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},S=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},I=e=>(Object.keys(e).forEach(t=>e[t]===void 0&&delete e[t]),e),L=e=>{const{height:t}=e.documentElement.getBoundingClientRect();return Math.ceil(t)};function O(e){b(e,()=>{var t;return(t=e.contentWindow)==null?void 0:t.postMessage("[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false","*")})}function E(e){if(typeof e.data=="string"&&e.data.startsWith("[iFrameSizer]")){const[t,n]=e.data.split(":"),i=+n;return i>0?i:null}return null}const d=c()?D():null;let f=[];const C=(e,t)=>{if(!c())return[];const n={...z(),...I(e??{})},i=k(t),r=B(n,i);return i.map(o=>{const s={iframe:o,settings:n,interactionState:{isHovered:!1}},l=H(s,r);return f.push(s),{unsubscribe:()=>{l(),f=f.filter(g=>g.iframe!==o)}}})};function k(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(h):e?h(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function B(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const i of t){const r=S(i);r&&n.push(r)}return n}function H(e,t){const n=R(e.iframe)?T(e):M(e,t),i=W(e);return()=>{n(),i()}}function M(e,t){const{iframe:n,settings:i}=e,r=o=>{var g;const s=!i.checkOrigin||t.includes(o.origin);if(!(!(n.contentWindow===o.source)||!s)){if(((g=o.data)==null?void 0:g.type)==="iframe-resized"){const{height:u}=o.data;u&&m({newHeight:u,registeredElement:e});return}if(i.enableLegacyLibSupport){const u=E(o);u!==null&&m({newHeight:u,registeredElement:e});return}}};return window.addEventListener("message",r),i.enableLegacyLibSupport&&O(n),()=>window.removeEventListener("message",r)}function T({iframe:e}){const t=()=>{var i;const n=(i=e.contentDocument)==null?void 0:i.body;n&&(d==null||d.observe(n))};return v(e,t),()=>{var n;(n=e.contentDocument)!=null&&n.body&&(d==null||d.unobserve(e.contentDocument.body)),e.removeEventListener("load",t)}}function W({iframe:e,interactionState:t}){const n=()=>{t.isHovered=!0},i=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",i)}}function D(){const e=({target:t})=>{const n=f.find(o=>{var s;return((s=o.iframe.contentDocument)==null?void 0:s.body)===t});if(!n)return;const{iframe:i}=n;if(!i.contentDocument)return;const r=L(i.contentDocument);r&&m({newHeight:r,registeredElement:n})};return new ResizeObserver(t=>t.forEach(e))}function m({registeredElement:e,newHeight:t}){const{iframe:n,settings:i,interactionState:r}=e,o=n.getBoundingClientRect(),s=t+i.offsetSize;if(n.style.height=`${s}px`,!i.onIframeResize)return;const l={iframe:n,settings:{...i},interactionState:{...r},previousRenderState:{rect:o},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(l)}w();function w(){!c()||!p()||y(window,()=>{const e=()=>{const n={type:"iframe-resized",width:document.documentElement.scrollWidth,height:L(document)};window.parent.postMessage(n,"*")};new ResizeObserver(e).observe(document.body)})}const P=({previousRenderState:e,nextRenderState:t,interactionState:n})=>{n.isHovered&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)};a.initialize=C,a.initializeChildListener=w,a.updateParentScrollOnResize=P,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/dist/child.d.ts
DELETED
package/dist/common.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Settings } from './type';
|
|
2
|
-
export declare const isInIframe: () => boolean;
|
|
3
|
-
export declare const isHtmlIframeElement: (element: Element) => element is HTMLIFrameElement;
|
|
4
|
-
export declare const deferWhenWindowIsLoaded: (_window: Window, executable: () => void) => void;
|
|
5
|
-
/**
|
|
6
|
-
* Post the message twice, it assures the target to receive the message at least once
|
|
7
|
-
*/
|
|
8
|
-
export declare const safePostMessageToCrossOriginIframe: (iframe: HTMLIFrameElement, executable: () => void) => void;
|
|
9
|
-
export declare const deferWhenSameOriginIframeIsLoaded: (iframe: HTMLIFrameElement, executable: () => void) => void;
|
|
10
|
-
export declare const getDefaultSettings: () => Settings;
|
|
11
|
-
export declare const isIframeSameOrigin: (iframe: HTMLIFrameElement) => boolean;
|
|
12
|
-
export declare const extractIframeOrigin: (iframe: HTMLIFrameElement) => string | null;
|
|
13
|
-
export declare const removeUndefinedProperties: <T extends {
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
}>(object: T) => T;
|
|
16
|
-
export declare const getBoundingRectHeight: (document: Document) => number;
|
package/dist/compat.d.ts
DELETED
package/dist/parent.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ResizeContext } from './type';
|
|
2
|
-
/**
|
|
3
|
-
* Resize handler that scrolls to restore the iframe's position in the viewport as it was before the resize.
|
|
4
|
-
*
|
|
5
|
-
* *Note:* This behavior only triggers if the iframe is currently being hovered by the user,
|
|
6
|
-
* in order to try to limit the number of scroll as it can affect the user experience.
|
|
7
|
-
*/
|
|
8
|
-
export declare const updateParentScrollOnResize: ({ previousRenderState, nextRenderState, interactionState }: ResizeContext) => void;
|
package/dist/type.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
interface Window {
|
|
2
|
-
iframeResizer: {
|
|
3
|
-
initialize: InitializeFunction;
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Automatically resizes the selected iframes.
|
|
9
|
-
* @param settings The settings for the selected iframes. The default settings properties are picked if empty.
|
|
10
|
-
* @param selector The selector for the iframe(s) or the HTMLIFrameElement to be resized. If empty, all document iframe elements will be selected.
|
|
11
|
-
* @returns A result array, which can be used to clean up the listeners if you often remove iframes from the document.
|
|
12
|
-
*/
|
|
13
|
-
export type InitializeFunction = (settings?: Partial<Settings>, selector?: string | HTMLIFrameElement) => InitializeResult[];
|
|
14
|
-
export type InitializeResult = { unsubscribe: () => void };
|
|
15
|
-
|
|
16
|
-
export type Settings = {
|
|
17
|
-
/**
|
|
18
|
-
* Offset added to the resize size (in pixels).
|
|
19
|
-
*
|
|
20
|
-
* Default: `0`
|
|
21
|
-
*/
|
|
22
|
-
offsetSize: number;
|
|
23
|
-
/**
|
|
24
|
-
* Specifies whether to check the origin of incoming messages.
|
|
25
|
-
* Accepts an array of allowed origins or a boolean.
|
|
26
|
-
* If `true`, incoming messages are allowed from the origins of the registered iframes.
|
|
27
|
-
*
|
|
28
|
-
* Default: `true`
|
|
29
|
-
*/
|
|
30
|
-
checkOrigin: string[] | boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Allows the library to communicate with a cross-origin child iframe
|
|
33
|
-
* containing the original "iframe-resizer" script.
|
|
34
|
-
* Useful if you do not control the child domain.
|
|
35
|
-
*
|
|
36
|
-
* Default: `false`
|
|
37
|
-
*/
|
|
38
|
-
enableLegacyLibSupport: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Listener that is called after the iframe has been resized.
|
|
41
|
-
* You can use a predefined handler like `updateParentScrollOnResize` or create your own custom handler.
|
|
42
|
-
*
|
|
43
|
-
* Default: `undefined`
|
|
44
|
-
*/
|
|
45
|
-
onIframeResize?: (context: ResizeContext) => void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type IframeResizeEventData = {
|
|
49
|
-
type: "iframe-resized";
|
|
50
|
-
width: number;
|
|
51
|
-
height?: number;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type IframeResizeEvent = MessageEvent<IframeResizeEventData>;
|
|
55
|
-
|
|
56
|
-
export type InteractionState = {
|
|
57
|
-
isHovered: boolean;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type ResizeRenderState = { rect: DOMRect };
|
|
61
|
-
|
|
62
|
-
export type ResizeContext = {
|
|
63
|
-
iframe: HTMLIFrameElement;
|
|
64
|
-
settings: Settings;
|
|
65
|
-
interactionState: InteractionState;
|
|
66
|
-
previousRenderState: ResizeRenderState;
|
|
67
|
-
nextRenderState: ResizeRenderState;
|
|
68
|
-
};
|