@open-iframe-resizer/core 1.1.0 → 1.1.2

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
@@ -1,8 +1,5 @@
1
1
  import { Settings } from './type';
2
2
  export declare const isInIframe: () => boolean;
3
- export declare const isSameOriginIframe: (iframe: HTMLIFrameElement) => iframe is HTMLIFrameElement & {
4
- contentDocument: Document;
5
- };
6
3
  export declare const isHtmlIframeElement: (element: Element) => element is HTMLIFrameElement;
7
4
  export declare const deferWhenWindowIsLoaded: (_window: Window, executable: () => void) => void;
8
5
  /**
@@ -16,3 +13,4 @@ export declare const extractIframeOrigin: (iframe: HTMLIFrameElement) => string
16
13
  export declare const removeUndefinedProperties: <T extends {
17
14
  [key: string]: unknown;
18
15
  }>(object: T) => T;
16
+ export declare const getBoundingRectHeight: (document: Document) => number | undefined;
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
- const h = () => window && window.self !== window.top, f = (e) => e instanceof HTMLIFrameElement, b = (e, n) => {
1
+ const m = () => window && window.self !== window.top, l = (e) => e instanceof HTMLIFrameElement, h = (e, n) => {
2
2
  e.document.readyState === "complete" ? n() : e.addEventListener("load", n);
3
- }, w = (e, n) => {
3
+ }, b = (e, n) => {
4
4
  n(), e.addEventListener("load", n);
5
5
  }, L = (e, n) => {
6
- var r, o;
7
- const t = ((r = e.contentWindow) == null ? void 0 : r.document.readyState) === "complete";
6
+ var i, o;
7
+ const t = ((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" && t ? n() : e.addEventListener("load", n);
9
- }, y = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), p = (e) => {
9
+ }, y = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), w = (e) => {
10
10
  try {
11
- return new URL(e.src, window.location.origin).origin === window.location.origin;
11
+ return new URL(e.src).origin === window.location.origin;
12
12
  } catch {
13
13
  return !1;
14
14
  }
15
- }, m = (e) => {
15
+ }, p = (e) => {
16
16
  try {
17
17
  const n = new URL(e.src).origin;
18
18
  if (n !== "about:blank")
@@ -20,30 +20,30 @@ const h = () => window && window.self !== window.top, f = (e) => e instanceof HT
20
20
  } catch {
21
21
  }
22
22
  return null;
23
- }, O = (e) => (Object.keys(e).forEach((n) => e[n] === void 0 && delete e[n]), e);
23
+ }, O = (e) => (Object.keys(e).forEach((n) => e[n] === void 0 && delete e[n]), e), g = (e) => {
24
+ const { height: n } = e.documentElement.getBoundingClientRect() ?? {};
25
+ return n ? Math.ceil(n) : void 0;
26
+ };
24
27
  function z(e) {
25
- w(
28
+ b(
26
29
  e,
27
30
  () => {
28
31
  var n;
29
- return (n = e.contentWindow) == null ? void 0 : n.postMessage(
30
- "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false",
31
- m(e) ?? "*"
32
- );
32
+ return (n = e.contentWindow) == null ? void 0 : n.postMessage("[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false", "*");
33
33
  }
34
34
  );
35
35
  }
36
36
  function I(e) {
37
37
  if (typeof e.data == "string" && e.data.startsWith("[iFrameSizer]")) {
38
- const [n, t] = e.data.split(":");
39
- return +t;
38
+ const [n, t] = e.data.split(":"), r = +t;
39
+ return r > 0 ? r : null;
40
40
  }
41
41
  return null;
42
42
  }
43
- const g = W(), d = [], D = (e, n) => {
44
- const t = { ...y(), ...O(e ?? {}) }, i = v(n), r = S(t, i);
45
- return i.map((o) => {
46
- const c = d.push({ iframe: o, settings: t }), s = E(o, t, r);
43
+ const f = C(), d = [], W = (e, n) => {
44
+ const t = { ...y(), ...O(e ?? {}) }, r = v(n), i = S(t, r);
45
+ return r.map((o) => {
46
+ const c = d.push({ iframe: o, settings: t }), s = R(o, t, i);
47
47
  return {
48
48
  unsubscribe: () => {
49
49
  s(), d.splice(c - 1, 1);
@@ -52,7 +52,7 @@ const g = W(), d = [], D = (e, n) => {
52
52
  });
53
53
  };
54
54
  function v(e) {
55
- return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(f) : e ? f(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
55
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(l) : e ? l(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
56
56
  }
57
57
  function S(e, n) {
58
58
  if (Array.isArray(e.checkOrigin))
@@ -60,74 +60,76 @@ function S(e, n) {
60
60
  if (!e.checkOrigin)
61
61
  return [];
62
62
  const t = [];
63
- for (const i of n) {
64
- const r = m(i);
65
- r && t.push(r);
63
+ for (const r of n) {
64
+ const i = p(r);
65
+ i && t.push(i);
66
66
  }
67
67
  return t;
68
68
  }
69
- function E(e, n, t) {
70
- return p(e) ? k(e) : R(e, n, t);
71
- }
72
69
  function R(e, n, t) {
73
- const i = (r) => {
70
+ return w(e) ? k(e) : E(e, n, t);
71
+ }
72
+ function E(e, n, t) {
73
+ const r = (i) => {
74
74
  var s;
75
- const o = !n.checkOrigin || t.includes(r.origin);
76
- if (!(!(e.contentWindow === r.source) || !o)) {
77
- if (((s = r.data) == null ? void 0 : s.type) === "iframe-resized") {
78
- const { height: a } = r.data;
79
- u({ height: a, iframe: e, settings: n });
75
+ const o = !n.checkOrigin || t.includes(i.origin);
76
+ if (!(!(e.contentWindow === i.source) || !o)) {
77
+ if (((s = i.data) == null ? void 0 : s.type) === "iframe-resized") {
78
+ const { height: a } = i.data;
79
+ a && u({ height: a, iframe: e, settings: n });
80
80
  return;
81
81
  }
82
82
  if (n.enableLegacyLibSupport) {
83
- const a = I(r);
83
+ const a = I(i);
84
84
  a !== null && u({ height: a, iframe: e, settings: n });
85
85
  return;
86
86
  }
87
87
  }
88
88
  };
89
- return window.addEventListener("message", i), n.enableLegacyLibSupport && z(e), () => window.removeEventListener("message", i);
89
+ return window.addEventListener("message", r), n.enableLegacyLibSupport && z(e), () => window.removeEventListener("message", r);
90
90
  }
91
91
  function k(e) {
92
92
  const n = () => {
93
- var i;
94
- const t = (i = e.contentDocument) == null ? void 0 : i.body;
93
+ var r;
94
+ const t = (r = e.contentDocument) == null ? void 0 : r.body;
95
95
  if (!t) {
96
96
  console.error("Unable to observe the iframe content document body");
97
97
  return;
98
98
  }
99
- g.observe(t);
99
+ f.observe(t);
100
100
  };
101
101
  return L(e, n), () => {
102
102
  var t;
103
- (t = e.contentDocument) != null && t.body && g.unobserve(e.contentDocument.body), e.removeEventListener("load", n);
103
+ (t = e.contentDocument) != null && t.body && f.unobserve(e.contentDocument.body), e.removeEventListener("load", n);
104
104
  };
105
105
  }
106
- function W() {
106
+ function C() {
107
107
  const e = ({ target: n }) => {
108
- var s;
109
- const t = d.find((a) => {
110
- var l;
111
- return ((l = a.iframe.contentDocument) == null ? void 0 : l.body) === n;
108
+ const t = d.find((c) => {
109
+ var s;
110
+ return ((s = c.iframe.contentDocument) == null ? void 0 : s.body) === n;
112
111
  });
113
112
  if (!t)
114
113
  return;
115
- const { iframe: i, settings: r } = t, { scrollHeight: o, scrollWidth: c } = ((s = i.contentDocument) == null ? void 0 : s.documentElement) ?? {};
116
- o !== void 0 && c !== void 0 && u({ height: o, iframe: i, settings: r });
114
+ const { iframe: r, settings: i } = t;
115
+ if (!r.contentDocument)
116
+ return;
117
+ const o = g(r.contentDocument);
118
+ o && u({ height: o, iframe: r, settings: i });
117
119
  };
118
120
  return new ResizeObserver((n) => n.forEach(e));
119
121
  }
120
122
  function u({ height: e, iframe: n, settings: t }) {
121
- n.style.height = `${e + t.offsetSize + 1}px`;
123
+ n.style.height = `${e + t.offsetSize}px`;
122
124
  }
123
- h() && C();
124
- function C() {
125
- b(window, () => {
125
+ m() && D();
126
+ function D() {
127
+ h(window, () => {
126
128
  const e = () => {
127
129
  const t = {
128
130
  type: "iframe-resized",
129
131
  width: document.documentElement.scrollWidth,
130
- height: document.documentElement.scrollHeight
132
+ height: g(document) ?? void 0
131
133
  };
132
134
  window.parent.postMessage(t, "*");
133
135
  };
@@ -135,6 +137,6 @@ function C() {
135
137
  });
136
138
  }
137
139
  export {
138
- D as initialize,
139
- C as initializeChildListener
140
+ W as initialize,
141
+ D as initializeChildListener
140
142
  };
@@ -1 +1 @@
1
- (function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s.iframeResizer={}))})(this,function(s){"use strict";const d=()=>window&&window.self!==window.top,g=e=>e instanceof HTMLIFrameElement,p=(e,n)=>{e.document.readyState==="complete"?n():e.addEventListener("load",n)},L=(e,n)=>{n(),e.addEventListener("load",n)},w=(e,n)=>{var i,o;const t=((i=e.contentWindow)==null?void 0:i.document.readyState)==="complete";return e.src!=="about:blank"&&((o=e.contentWindow)==null?void 0:o.location.href)!=="about:blank"&&t?n():e.addEventListener("load",n)},O=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),z=e=>{try{return new URL(e.src,window.location.origin).origin===window.location.origin}catch{return!1}},m=e=>{try{const n=new URL(e.src).origin;if(n!=="about:blank")return n}catch{}return null},I=e=>(Object.keys(e).forEach(n=>e[n]===void 0&&delete e[n]),e);function v(e){L(e,()=>{var n;return(n=e.contentWindow)==null?void 0:n.postMessage("[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false",m(e)??"*")})}function S(e){if(typeof e.data=="string"&&e.data.startsWith("[iFrameSizer]")){const[n,t]=e.data.split(":");return+t}return null}const h=D(),l=[],E=(e,n)=>{const t={...O(),...I(e??{})},r=R(n),i=k(t,r);return r.map(o=>{const u=l.push({iframe:o,settings:t}),a=W(o,t,i);return{unsubscribe:()=>{a(),l.splice(u-1,1)}}})};function R(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(g):e?g(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function k(e,n){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const t=[];for(const r of n){const i=m(r);i&&t.push(i)}return t}function W(e,n,t){return z(e)?T(e):C(e,n,t)}function C(e,n,t){const r=i=>{var a;const o=!n.checkOrigin||t.includes(i.origin);if(!(!(e.contentWindow===i.source)||!o)){if(((a=i.data)==null?void 0:a.type)==="iframe-resized"){const{height:c}=i.data;f({height:c,iframe:e,settings:n});return}if(n.enableLegacyLibSupport){const c=S(i);c!==null&&f({height:c,iframe:e,settings:n});return}}};return window.addEventListener("message",r),n.enableLegacyLibSupport&&v(e),()=>window.removeEventListener("message",r)}function T(e){const n=()=>{var r;const t=(r=e.contentDocument)==null?void 0:r.body;if(!t){console.error("Unable to observe the iframe content document body");return}h.observe(t)};return w(e,n),()=>{var t;(t=e.contentDocument)!=null&&t.body&&h.unobserve(e.contentDocument.body),e.removeEventListener("load",n)}}function D(){const e=({target:n})=>{var a;const t=l.find(c=>{var y;return((y=c.iframe.contentDocument)==null?void 0:y.body)===n});if(!t)return;const{iframe:r,settings:i}=t,{scrollHeight:o,scrollWidth:u}=((a=r.contentDocument)==null?void 0:a.documentElement)??{};o!==void 0&&u!==void 0&&f({height:o,iframe:r,settings:i})};return new ResizeObserver(n=>n.forEach(e))}function f({height:e,iframe:n,settings:t}){n.style.height=`${e+t.offsetSize+1}px`}d()&&b();function b(){p(window,()=>{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=E,s.initializeChildListener=b,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.iframeResizer={}))})(this,function(s){"use strict";const c=()=>window&&window.self!==window.top,g=e=>e instanceof HTMLIFrameElement,y=(e,n)=>{e.document.readyState==="complete"?n():e.addEventListener("load",n)},p=(e,n)=>{n(),e.addEventListener("load",n)},L=(e,n)=>{var r,o;const t=((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"&&t?n():e.addEventListener("load",n)},w=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),O=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},z=e=>{try{const n=new URL(e.src).origin;if(n!=="about:blank")return n}catch{}return null},I=e=>(Object.keys(e).forEach(n=>e[n]===void 0&&delete e[n]),e),m=e=>{const{height:n}=e.documentElement.getBoundingClientRect()??{};return n?Math.ceil(n):void 0};function v(e){p(e,()=>{var n;return(n=e.contentWindow)==null?void 0:n.postMessage("[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false","*")})}function S(e){if(typeof e.data=="string"&&e.data.startsWith("[iFrameSizer]")){const[n,t]=e.data.split(":"),i=+t;return i>0?i:null}return null}const h=T(),f=[],R=(e,n)=>{const t={...w(),...I(e??{})},i=E(n),r=k(t,i);return i.map(o=>{const u=f.push({iframe:o,settings:t}),a=C(o,t,r);return{unsubscribe:()=>{a(),f.splice(u-1,1)}}})};function E(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(g):e?g(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function k(e,n){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const t=[];for(const i of n){const r=z(i);r&&t.push(r)}return t}function C(e,n,t){return O(e)?M(e):D(e,n,t)}function D(e,n,t){const i=r=>{var a;const o=!n.checkOrigin||t.includes(r.origin);if(!(!(e.contentWindow===r.source)||!o)){if(((a=r.data)==null?void 0:a.type)==="iframe-resized"){const{height:d}=r.data;d&&l({height:d,iframe:e,settings:n});return}if(n.enableLegacyLibSupport){const d=S(r);d!==null&&l({height:d,iframe:e,settings:n});return}}};return window.addEventListener("message",i),n.enableLegacyLibSupport&&v(e),()=>window.removeEventListener("message",i)}function M(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}h.observe(t)};return L(e,n),()=>{var t;(t=e.contentDocument)!=null&&t.body&&h.unobserve(e.contentDocument.body),e.removeEventListener("load",n)}}function T(){const e=({target:n})=>{const t=f.find(u=>{var a;return((a=u.iframe.contentDocument)==null?void 0:a.body)===n});if(!t)return;const{iframe:i,settings:r}=t;if(!i.contentDocument)return;const o=m(i.contentDocument);o&&l({height:o,iframe:i,settings:r})};return new ResizeObserver(n=>n.forEach(e))}function l({height:e,iframe:n,settings:t}){n.style.height=`${e+t.offsetSize}px`}c()&&b();function b(){y(window,()=>{const e=()=>{const t={type:"iframe-resized",width:document.documentElement.scrollWidth,height:m(document)??void 0};window.parent.postMessage(t,"*")};new ResizeObserver(e).observe(document.body)})}s.initialize=R,s.initializeChildListener=b,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/dist/type.d.ts CHANGED
@@ -41,7 +41,7 @@ export type Settings = {
41
41
  export type IframeResizeEventData = {
42
42
  type: "iframe-resized";
43
43
  width: number;
44
- height: number;
44
+ height?: number;
45
45
  };
46
46
 
47
47
  export type IframeResizeEvent = MessageEvent<IframeResizeEventData>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-iframe-resizer/core",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "description": "Open-source modern iframe resizer",
6
6
  "license": "MIT",
7
7
  "repository": {