@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 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 deferWhenDomContentIsLoaded: (document: Document, executable: () => void) => void;
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, deferWhenDomContentIsLoaded, isHtmlIframeElement, deferWhenPageIsLoaded, isIframeSameOrigin, debounce, getDefaultSettings, };
11
+ export { isInIframe, isSameOriginIframe, isHtmlIframeElement, deferWhenIframeIsLoaded, isIframeSameOrigin, debounce, getDefaultSettings };
package/dist/index.js CHANGED
@@ -1,111 +1,108 @@
1
- const w = () => window && window.self !== window.top, l = (e) => e instanceof HTMLIFrameElement, b = () => ({ offsetSize: 0, checkOrigin: !0 }), y = (e) => {
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
- function m(e, t) {
9
- let n;
10
- return (...i) => {
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
- s(), d.splice(o - 1, 1);
17
+ c(), a.splice(s - 1, 1);
21
18
  }
22
19
  };
23
20
  });
24
21
  };
25
- function O(e) {
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 v(e, t) {
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 n = [];
34
- for (const i of t) {
35
- const r = z(i);
36
- r && n.push(r);
30
+ const t = [];
31
+ for (const r of n) {
32
+ const i = v(r);
33
+ i && t.push(i);
37
34
  }
38
- return n;
35
+ return t;
39
36
  }
40
- function z(e) {
37
+ function v(e) {
41
38
  try {
42
- const t = new URL(e.src).origin;
43
- if (t !== "about:blank")
44
- return t;
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 p(e, t, n) {
50
- return y(e) ? E(e) : L(e, t, n);
46
+ function z(e, n, t) {
47
+ return b(e) ? p(e) : L(e, n, t);
51
48
  }
52
- function L(e, t, n) {
53
- const i = (r) => {
54
- var o;
55
- if ((!t.checkOrigin || n.includes(r.origin)) && ((o = r.data) == null ? void 0 : o.type) === "iframe-resized" && e.contentWindow === r.source) {
56
- const { width: s, height: a } = r.data;
57
- g({ width: s, height: a, iframe: e, settings: t });
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", i, !1), () => window.removeEventListener("message", i, !1);
57
+ return window.addEventListener("message", r, !1), () => window.removeEventListener("message", r, !1);
61
58
  }
62
- function E(e) {
63
- const t = () => {
64
- var i;
65
- const n = (i = e.contentDocument) == null ? void 0 : i.body;
66
- if (!n) {
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
- f.observe(n);
67
+ u.observe(t);
71
68
  };
72
- return e.addEventListener("load", t), () => {
73
- var n;
74
- (n = e.contentDocument) != null && n.body && f.unobserve(e.contentDocument.body), e.removeEventListener("load", t);
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 a;
80
- const i = d.find((h) => {
81
- var u;
82
- return ((u = h.iframe.contentDocument) == null ? void 0 : u.body) === n;
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 (!i)
81
+ if (!t)
85
82
  return;
86
- const { iframe: r, settings: c } = i, { scrollHeight: o, scrollWidth: s } = ((a = r.contentDocument) == null ? void 0 : a.documentElement) ?? {};
87
- o !== void 0 && s !== void 0 && g({ width: s, height: o, iframe: r, settings: c });
88
- }, t = m((n) => n.forEach(e), 10);
89
- return new ResizeObserver(t);
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 g({ width: e, height: t, iframe: n, settings: i }) {
92
- n.style.width = `${e}px`, n.style.height = `${t + i.offsetSize}px`;
88
+ function f({ height: e, iframe: n, settings: t }) {
89
+ n.style.height = `${e + t.offsetSize}px`;
93
90
  }
94
- w() && R();
95
- function R() {
91
+ g() && E();
92
+ function E() {
96
93
  window.addEventListener("load", () => {
97
- const e = m(() => {
98
- const n = {
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(n, "*");
104
- }, 10);
100
+ window.parent.postMessage(t, "*");
101
+ };
105
102
  new ResizeObserver(e).observe(document.body);
106
103
  });
107
104
  }
108
105
  export {
109
- S as initialize,
110
- R as initializeChildListener
106
+ R as initialize,
107
+ E as initializeChildListener
111
108
  };
@@ -1 +1 @@
1
- (function(o,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(o=typeof globalThis<"u"?globalThis:o||self,d(o.iframeResizer={}))})(this,function(o){"use strict";const d=()=>window&&window.self!==window.top,f=e=>e instanceof HTMLIFrameElement,y=()=>({offsetSize:0,checkOrigin:!0}),O=e=>{try{return new URL(e.src,window.location.origin).origin===window.location.origin}catch{return!1}};function m(e,i){let n;return(...t)=>{clearTimeout(n),n=setTimeout(()=>e.apply(void 0,t),i)}}const g=S(),l=[],z=(e,i)=>{const n={...y(),...e},t=p(i),r=v(n,t);return t.map(a=>{const s=l.push({iframe:a,settings:n}),c=E(a,n,r);return{unsubscribe:()=>{c(),l.splice(s-1,1)}}})};function p(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(f):e?f(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function v(e,i){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const t of i){const r=L(t);r&&n.push(r)}return n}function L(e){try{const i=new URL(e.src).origin;if(i!=="about:blank")return i}catch{}return null}function E(e,i,n){return O(e)?I(e):R(e,i,n)}function R(e,i,n){const t=r=>{var s;if((!i.checkOrigin||n.includes(r.origin))&&((s=r.data)==null?void 0:s.type)==="iframe-resized"&&e.contentWindow===r.source){const{width:c,height:u}=r.data;h({width:c,height:u,iframe:e,settings:i})}};return window.addEventListener("message",t,!1),()=>window.removeEventListener("message",t,!1)}function I(e){const i=()=>{var t;const n=(t=e.contentDocument)==null?void 0:t.body;if(!n){console.error("Unable to observe the iframe content document body");return}g.observe(n)};return e.addEventListener("load",i),()=>{var n;(n=e.contentDocument)!=null&&n.body&&g.unobserve(e.contentDocument.body),e.removeEventListener("load",i)}}function S(){const e=({target:n})=>{var u;const t=l.find(k=>{var w;return((w=k.iframe.contentDocument)==null?void 0:w.body)===n});if(!t)return;const{iframe:r,settings:a}=t,{scrollHeight:s,scrollWidth:c}=((u=r.contentDocument)==null?void 0:u.documentElement)??{};s!==void 0&&c!==void 0&&h({width:c,height:s,iframe:r,settings:a})},i=m(n=>n.forEach(e),10);return new ResizeObserver(i)}function h({width:e,height:i,iframe:n,settings:t}){n.style.width=`${e}px`,n.style.height=`${i+t.offsetSize}px`}d()&&b();function b(){window.addEventListener("load",()=>{const e=m(()=>{const n={type:"iframe-resized",width:document.documentElement.scrollWidth,height:document.documentElement.scrollHeight};window.parent.postMessage(n,"*")},10);new ResizeObserver(e).observe(document.body)})}o.initialize=z,o.initializeChildListener=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
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-rc4",
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
  }