@open-iframe-resizer/core 1.1.1 → 1.1.3

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
  /**
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
- const h = () => window && window.self !== window.top, l = (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
6
  var i, o;
7
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
- }, g = (e) => {
15
+ }, p = (e) => {
16
16
  try {
17
17
  const n = new URL(e.src).origin;
18
18
  if (n !== "about:blank")
@@ -20,36 +20,36 @@ const h = () => window && window.self !== window.top, l = (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), m = (e) => {
23
+ }, O = (e) => (Object.keys(e).forEach((n) => e[n] === void 0 && delete e[n]), e), g = (e) => {
24
24
  const { height: n } = e.documentElement.getBoundingClientRect() ?? {};
25
25
  return n ? Math.ceil(n) : void 0;
26
26
  };
27
27
  function z(e) {
28
- w(
28
+ b(
29
29
  e,
30
30
  () => {
31
31
  var n;
32
- return (n = e.contentWindow) == null ? void 0 : n.postMessage(
33
- "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false",
34
- g(e) ?? "*"
35
- );
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", "*");
36
33
  }
37
34
  );
38
35
  }
39
36
  function I(e) {
40
37
  if (typeof e.data == "string" && e.data.startsWith("[iFrameSizer]")) {
41
- const [n, t] = e.data.split(":");
42
- return +t;
38
+ const [n, t] = e.data.split(":"), r = +t;
39
+ return r > 0 ? r : null;
43
40
  }
44
41
  return null;
45
42
  }
46
- const f = C(), d = [], W = (e, n) => {
43
+ const f = C();
44
+ let d = [];
45
+ const W = (e, n) => {
47
46
  const t = { ...y(), ...O(e ?? {}) }, r = v(n), i = S(t, r);
48
47
  return r.map((o) => {
49
- const a = d.push({ iframe: o, settings: t }), s = R(o, t, i);
48
+ d.push({ iframe: o, settings: t });
49
+ const c = R(o, t, i);
50
50
  return {
51
51
  unsubscribe: () => {
52
- s(), d.splice(a - 1, 1);
52
+ c(), d = d.filter((s) => s.iframe !== o);
53
53
  }
54
54
  };
55
55
  });
@@ -64,13 +64,13 @@ function S(e, n) {
64
64
  return [];
65
65
  const t = [];
66
66
  for (const r of n) {
67
- const i = g(r);
67
+ const i = p(r);
68
68
  i && t.push(i);
69
69
  }
70
70
  return t;
71
71
  }
72
72
  function R(e, n, t) {
73
- return p(e) ? k(e) : E(e, n, t);
73
+ return w(e) ? k(e) : E(e, n, t);
74
74
  }
75
75
  function E(e, n, t) {
76
76
  const r = (i) => {
@@ -78,13 +78,13 @@ function E(e, n, t) {
78
78
  const o = !n.checkOrigin || t.includes(i.origin);
79
79
  if (!(!(e.contentWindow === i.source) || !o)) {
80
80
  if (((s = i.data) == null ? void 0 : s.type) === "iframe-resized") {
81
- const { height: c } = i.data;
82
- c && u({ height: c, iframe: e, settings: n });
81
+ const { height: a } = i.data;
82
+ a && u({ height: a, iframe: e, settings: n });
83
83
  return;
84
84
  }
85
85
  if (n.enableLegacyLibSupport) {
86
- const c = I(i);
87
- c !== null && u({ height: c, iframe: e, settings: n });
86
+ const a = I(i);
87
+ a !== null && u({ height: a, iframe: e, settings: n });
88
88
  return;
89
89
  }
90
90
  }
@@ -108,16 +108,16 @@ function k(e) {
108
108
  }
109
109
  function C() {
110
110
  const e = ({ target: n }) => {
111
- const t = d.find((a) => {
111
+ const t = d.find((c) => {
112
112
  var s;
113
- return ((s = a.iframe.contentDocument) == null ? void 0 : s.body) === n;
113
+ return ((s = c.iframe.contentDocument) == null ? void 0 : s.body) === n;
114
114
  });
115
115
  if (!t)
116
116
  return;
117
117
  const { iframe: r, settings: i } = t;
118
118
  if (!r.contentDocument)
119
119
  return;
120
- const o = m(r.contentDocument);
120
+ const o = g(r.contentDocument);
121
121
  o && u({ height: o, iframe: r, settings: i });
122
122
  };
123
123
  return new ResizeObserver((n) => n.forEach(e));
@@ -125,14 +125,14 @@ function C() {
125
125
  function u({ height: e, iframe: n, settings: t }) {
126
126
  n.style.height = `${e + t.offsetSize}px`;
127
127
  }
128
- h() && D();
128
+ m() && D();
129
129
  function D() {
130
- b(window, () => {
130
+ h(window, () => {
131
131
  const e = () => {
132
132
  const t = {
133
133
  type: "iframe-resized",
134
134
  width: document.documentElement.scrollWidth,
135
- height: m(document) ?? void 0
135
+ height: g(document) ?? void 0
136
136
  };
137
137
  window.parent.postMessage(t, "*");
138
138
  };
@@ -1 +1 @@
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,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 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)},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),h=e=>{const{height:n}=e.documentElement.getBoundingClientRect()??{};return n?Math.ceil(n):void 0};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 b=T(),f=[],R=(e,n)=>{const t={...O(),...I(e??{})},i=E(n),r=k(t,i);return i.map(o=>{const u=f.push({iframe:o,settings:t}),c=C(o,t,r);return{unsubscribe:()=>{c(),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=m(i);r&&t.push(r)}return t}function C(e,n,t){return z(e)?M(e):D(e,n,t)}function D(e,n,t){const i=r=>{var c;const o=!n.checkOrigin||t.includes(r.origin);if(!(!(e.contentWindow===r.source)||!o)){if(((c=r.data)==null?void 0:c.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}b.observe(t)};return w(e,n),()=>{var t;(t=e.contentDocument)!=null&&t.body&&b.unobserve(e.contentDocument.body),e.removeEventListener("load",n)}}function T(){const e=({target:n})=>{const t=f.find(u=>{var c;return((c=u.iframe.contentDocument)==null?void 0:c.body)===n});if(!t)return;const{iframe:i,settings:r}=t;if(!i.contentDocument)return;const o=h(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`}a()&&y();function y(){p(window,()=>{const e=()=>{const t={type:"iframe-resized",width:document.documentElement.scrollWidth,height:h(document)??void 0};window.parent.postMessage(t,"*")};new ResizeObserver(e).observe(document.body)})}s.initialize=R,s.initializeChildListener=y,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();let u=[];const R=(e,n)=>{const t={...w(),...I(e??{})},i=E(n),r=k(t,i);return i.map(o=>{u.push({iframe:o,settings:t});const f=C(o,t,r);return{unsubscribe:()=>{f(),u=u.filter(a=>a.iframe!==o)}}})};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=u.find(f=>{var a;return((a=f.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-iframe-resizer/core",
3
3
  "private": false,
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "description": "Open-source modern iframe resizer",
6
6
  "license": "MIT",
7
7
  "repository": {