@open-iframe-resizer/core 1.0.0-rc4 → 1.0.0-rc5
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/dist/common.d.ts +2 -3
- package/dist/index.js +58 -61
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -3
package/dist/common.d.ts
CHANGED
|
@@ -4,9 +4,8 @@ declare const isSameOriginIframe: (iframe: HTMLIFrameElement) => iframe is HTMLI
|
|
|
4
4
|
contentDocument: Document;
|
|
5
5
|
};
|
|
6
6
|
declare const isHtmlIframeElement: (element: Element) => element is HTMLIFrameElement;
|
|
7
|
-
declare const
|
|
8
|
-
declare const deferWhenPageIsLoaded: (document: Document, executable: () => void) => void;
|
|
7
|
+
declare const deferWhenIframeIsLoaded: (iframe: HTMLIFrameElement, executable: () => void) => void;
|
|
9
8
|
declare const getDefaultSettings: () => Settings;
|
|
10
9
|
declare const isIframeSameOrigin: (iframe: HTMLIFrameElement) => boolean;
|
|
11
10
|
declare function debounce<T extends (...args: any[]) => any>(f: T, delay: number): (...args: unknown[]) => void;
|
|
12
|
-
export { isInIframe, isSameOriginIframe,
|
|
11
|
+
export { isInIframe, isSameOriginIframe, isHtmlIframeElement, deferWhenIframeIsLoaded, isIframeSameOrigin, debounce, getDefaultSettings };
|
package/dist/index.js
CHANGED
|
@@ -1,111 +1,108 @@
|
|
|
1
|
-
const
|
|
1
|
+
const g = () => window && window.self !== window.top, l = (e) => e instanceof HTMLIFrameElement, h = (e, n) => {
|
|
2
|
+
var i, o;
|
|
3
|
+
const t = ((i = e.contentWindow) == null ? void 0 : i.document.readyState) === "complete", r = e.src !== "about:blank" && ((o = e.contentWindow) == null ? void 0 : o.location.href) !== "about:blank";
|
|
4
|
+
return console.log("test", r, t), r && t ? n() : e.addEventListener("load", n);
|
|
5
|
+
}, w = () => ({ offsetSize: 0, checkOrigin: !0 }), b = (e) => {
|
|
2
6
|
try {
|
|
3
7
|
return new URL(e.src, window.location.origin).origin === window.location.origin;
|
|
4
8
|
} catch {
|
|
5
9
|
return !1;
|
|
6
10
|
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
clearTimeout(n), n = setTimeout(() => e.apply(void 0, i), t);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
const f = I(), d = [], S = (e, t) => {
|
|
15
|
-
const n = { ...b(), ...e }, i = O(t), r = v(n, i);
|
|
16
|
-
return i.map((c) => {
|
|
17
|
-
const o = d.push({ iframe: c, settings: n }), s = p(c, n, r);
|
|
11
|
+
}, u = I(), a = [], R = (e, n) => {
|
|
12
|
+
const t = { ...w(), ...e }, r = y(n), i = O(t, r);
|
|
13
|
+
return r.map((o) => {
|
|
14
|
+
const s = a.push({ iframe: o, settings: t }), c = z(o, t, i);
|
|
18
15
|
return {
|
|
19
16
|
unsubscribe: () => {
|
|
20
|
-
|
|
17
|
+
c(), a.splice(s - 1, 1);
|
|
21
18
|
}
|
|
22
19
|
};
|
|
23
20
|
});
|
|
24
21
|
};
|
|
25
|
-
function
|
|
22
|
+
function y(e) {
|
|
26
23
|
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(l) : e ? l(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
|
|
27
24
|
}
|
|
28
|
-
function
|
|
25
|
+
function O(e, n) {
|
|
29
26
|
if (Array.isArray(e.checkOrigin))
|
|
30
27
|
return e.checkOrigin;
|
|
31
28
|
if (!e.checkOrigin)
|
|
32
29
|
return [];
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
const
|
|
36
|
-
|
|
30
|
+
const t = [];
|
|
31
|
+
for (const r of n) {
|
|
32
|
+
const i = v(r);
|
|
33
|
+
i && t.push(i);
|
|
37
34
|
}
|
|
38
|
-
return
|
|
35
|
+
return t;
|
|
39
36
|
}
|
|
40
|
-
function
|
|
37
|
+
function v(e) {
|
|
41
38
|
try {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
39
|
+
const n = new URL(e.src).origin;
|
|
40
|
+
if (n !== "about:blank")
|
|
41
|
+
return n;
|
|
45
42
|
} catch {
|
|
46
43
|
}
|
|
47
44
|
return null;
|
|
48
45
|
}
|
|
49
|
-
function
|
|
50
|
-
return
|
|
46
|
+
function z(e, n, t) {
|
|
47
|
+
return b(e) ? p(e) : L(e, n, t);
|
|
51
48
|
}
|
|
52
|
-
function L(e,
|
|
53
|
-
const
|
|
54
|
-
var
|
|
55
|
-
if ((!
|
|
56
|
-
const {
|
|
57
|
-
|
|
49
|
+
function L(e, n, t) {
|
|
50
|
+
const r = (i) => {
|
|
51
|
+
var s;
|
|
52
|
+
if ((!n.checkOrigin || t.includes(i.origin)) && ((s = i.data) == null ? void 0 : s.type) === "iframe-resized" && e.contentWindow === i.source) {
|
|
53
|
+
const { height: c } = i.data;
|
|
54
|
+
f({ height: c, iframe: e, settings: n });
|
|
58
55
|
}
|
|
59
56
|
};
|
|
60
|
-
return window.addEventListener("message",
|
|
57
|
+
return window.addEventListener("message", r, !1), () => window.removeEventListener("message", r, !1);
|
|
61
58
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
var
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
59
|
+
function p(e) {
|
|
60
|
+
const n = () => {
|
|
61
|
+
var r;
|
|
62
|
+
const t = (r = e.contentDocument) == null ? void 0 : r.body;
|
|
63
|
+
if (!t) {
|
|
67
64
|
console.error("Unable to observe the iframe content document body");
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
70
|
-
|
|
67
|
+
u.observe(t);
|
|
71
68
|
};
|
|
72
|
-
return e
|
|
73
|
-
var
|
|
74
|
-
(
|
|
69
|
+
return h(e, n), () => {
|
|
70
|
+
var t;
|
|
71
|
+
(t = e.contentDocument) != null && t.body && u.unobserve(e.contentDocument.body), e.removeEventListener("load", n);
|
|
75
72
|
};
|
|
76
73
|
}
|
|
77
74
|
function I() {
|
|
78
75
|
const e = ({ target: n }) => {
|
|
79
|
-
var
|
|
80
|
-
const
|
|
81
|
-
var
|
|
82
|
-
return ((
|
|
76
|
+
var c;
|
|
77
|
+
const t = a.find((m) => {
|
|
78
|
+
var d;
|
|
79
|
+
return ((d = m.iframe.contentDocument) == null ? void 0 : d.body) === n;
|
|
83
80
|
});
|
|
84
|
-
if (!
|
|
81
|
+
if (!t)
|
|
85
82
|
return;
|
|
86
|
-
const { iframe: r, settings:
|
|
87
|
-
o !== void 0 && s !== void 0 &&
|
|
88
|
-
}
|
|
89
|
-
return new ResizeObserver(
|
|
83
|
+
const { iframe: r, settings: i } = t, { scrollHeight: o, scrollWidth: s } = ((c = r.contentDocument) == null ? void 0 : c.documentElement) ?? {};
|
|
84
|
+
o !== void 0 && s !== void 0 && f({ height: o, iframe: r, settings: i });
|
|
85
|
+
};
|
|
86
|
+
return new ResizeObserver((n) => n.forEach(e));
|
|
90
87
|
}
|
|
91
|
-
function
|
|
92
|
-
n.style.
|
|
88
|
+
function f({ height: e, iframe: n, settings: t }) {
|
|
89
|
+
n.style.height = `${e + t.offsetSize}px`;
|
|
93
90
|
}
|
|
94
|
-
|
|
95
|
-
function
|
|
91
|
+
g() && E();
|
|
92
|
+
function E() {
|
|
96
93
|
window.addEventListener("load", () => {
|
|
97
|
-
const e =
|
|
98
|
-
const
|
|
94
|
+
const e = () => {
|
|
95
|
+
const t = {
|
|
99
96
|
type: "iframe-resized",
|
|
100
97
|
width: document.documentElement.scrollWidth,
|
|
101
98
|
height: document.documentElement.scrollHeight
|
|
102
99
|
};
|
|
103
|
-
window.parent.postMessage(
|
|
104
|
-
}
|
|
100
|
+
window.parent.postMessage(t, "*");
|
|
101
|
+
};
|
|
105
102
|
new ResizeObserver(e).observe(document.body);
|
|
106
103
|
});
|
|
107
104
|
}
|
|
108
105
|
export {
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
R as initialize,
|
|
107
|
+
E as initializeChildListener
|
|
111
108
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s.iframeResizer={}))})(this,function(s){"use strict";const a=()=>window&&window.self!==window.top,u=e=>e instanceof HTMLIFrameElement,b=(e,n)=>{var r,o;const t=((r=e.contentWindow)==null?void 0:r.document.readyState)==="complete",i=e.src!=="about:blank"&&((o=e.contentWindow)==null?void 0:o.location.href)!=="about:blank";return console.log("test",i,t),i&&t?n():e.addEventListener("load",n)},w=()=>({offsetSize:0,checkOrigin:!0}),y=e=>{try{return new URL(e.src,window.location.origin).origin===window.location.origin}catch{return!1}},f=R(),l=[],O=(e,n)=>{const t={...w(),...e},i=z(n),r=p(t,i);return i.map(o=>{const c=l.push({iframe:o,settings:t}),d=L(o,t,r);return{unsubscribe:()=>{d(),l.splice(c-1,1)}}})};function z(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(u):e?u(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function p(e,n){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const t=[];for(const i of n){const r=v(i);r&&t.push(r)}return t}function v(e){try{const n=new URL(e.src).origin;if(n!=="about:blank")return n}catch{}return null}function L(e,n,t){return y(e)?E(e):I(e,n,t)}function I(e,n,t){const i=r=>{var c;if((!n.checkOrigin||t.includes(r.origin))&&((c=r.data)==null?void 0:c.type)==="iframe-resized"&&e.contentWindow===r.source){const{height:d}=r.data;m({height:d,iframe:e,settings:n})}};return window.addEventListener("message",i,!1),()=>window.removeEventListener("message",i,!1)}function E(e){const n=()=>{var i;const t=(i=e.contentDocument)==null?void 0:i.body;if(!t){console.error("Unable to observe the iframe content document body");return}f.observe(t)};return b(e,n),()=>{var t;(t=e.contentDocument)!=null&&t.body&&f.unobserve(e.contentDocument.body),e.removeEventListener("load",n)}}function R(){const e=({target:n})=>{var d;const t=l.find(S=>{var h;return((h=S.iframe.contentDocument)==null?void 0:h.body)===n});if(!t)return;const{iframe:i,settings:r}=t,{scrollHeight:o,scrollWidth:c}=((d=i.contentDocument)==null?void 0:d.documentElement)??{};o!==void 0&&c!==void 0&&m({height:o,iframe:i,settings:r})};return new ResizeObserver(n=>n.forEach(e))}function m({height:e,iframe:n,settings:t}){n.style.height=`${e+t.offsetSize}px`}a()&&g();function g(){window.addEventListener("load",()=>{const e=()=>{const t={type:"iframe-resized",width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight};window.parent.postMessage(t,"*")};new ResizeObserver(e).observe(document.body)})}s.initialize=O,s.initializeChildListener=g,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-iframe-resizer/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-rc5",
|
|
5
5
|
"description": "Open-source modern iframe resizer",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"test:unit": "vitest run"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/tsdoc": "^0.14.1"
|
|
41
|
-
"picocolors": "^1.0.1"
|
|
40
|
+
"@microsoft/tsdoc": "^0.14.1"
|
|
42
41
|
}
|
|
43
42
|
}
|