@open-iframe-resizer/vue 1.6.1 → 2.1.0

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.
@@ -1,18 +1,28 @@
1
- import { defineComponent as I, ref as O, onMounted as k, onBeforeUnmount as M, createElementBlock as B, openBlock as P, mergeProps as A } from "vue";
2
- const v = () => typeof window < "u", H = () => window.self !== window.top, h = (e) => e instanceof HTMLIFrameElement, _ = (e) => {
3
- window.document.readyState === "complete" ? e() : window.addEventListener("load", e);
4
- }, D = (e, t) => {
5
- t(), e.addEventListener("load", t);
6
- }, T = (e, t) => {
1
+ import { defineComponent as P, ref as D, onMounted as A, onBeforeUnmount as H, createElementBlock as _, openBlock as T, mergeProps as W } from "vue";
2
+ const S = () => typeof window < "u", x = () => {
3
+ try {
4
+ return window.self !== window.top;
5
+ } catch {
6
+ return !0;
7
+ }
8
+ }, w = (e) => e instanceof HTMLIFrameElement, p = (e) => {
9
+ window.document.readyState === "complete" ? e() : window.addEventListener("load", e, { once: !0 });
10
+ }, C = (e, t) => {
11
+ t(), e.addEventListener("load", t, { once: !0 });
12
+ }, F = (e, t) => {
7
13
  const n = e.contentWindow?.document.readyState === "complete";
8
- return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t);
9
- }, x = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), C = (e) => {
14
+ return e.src !== "about:blank" && e.contentWindow?.location.href !== "about:blank" && n ? t() : e.addEventListener("load", t, { once: !0 });
15
+ }, $ = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 });
16
+ async function N(e) {
10
17
  try {
11
- return new URL(e.src).origin === window.location.origin;
18
+ return e.contentDocument?.URL === "about:blank" ? new Promise((t) => {
19
+ e.addEventListener("load", () => t(e.contentDocument !== null), { once: !0 });
20
+ }) : e.contentDocument !== null;
12
21
  } catch {
13
22
  return !1;
14
23
  }
15
- }, W = (e) => {
24
+ }
25
+ const U = (e) => {
16
26
  try {
17
27
  const t = new URL(e.src).origin;
18
28
  if (t !== "about:blank")
@@ -20,194 +30,220 @@ const v = () => typeof window < "u", H = () => window.self !== window.top, h = (
20
30
  } catch {
21
31
  }
22
32
  return null;
23
- }, F = (e) => (Object.keys(e).forEach((t) => {
33
+ }, j = (e) => (Object.keys(e).forEach((t) => {
24
34
  e[t] === void 0 && delete e[t];
25
- }), e), S = (e) => {
35
+ }), e), v = (e) => {
26
36
  const { height: t, width: n } = e.getBoundingClientRect();
27
37
  return { height: Math.ceil(t), width: Math.ceil(n) };
28
- }, l = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, E = (e, t) => {
38
+ }, f = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, E = (e, t) => {
29
39
  e && (t.bodyPadding && (e.body.style.padding = t.bodyPadding), t.bodyMargin && (e.body.style.margin = t.bodyMargin));
30
- }, g = (e) => e <= 100 ? 100 : e <= 120 ? 1e3 : 1e4, $ = () => "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";
31
- function N(e) {
40
+ }, y = (e) => e <= 100 ? 100 : e <= 120 ? 1e3 : 1e4, q = () => "[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";
41
+ function G(e) {
32
42
  if (typeof e.data != "string" || !e.data.startsWith("[iFrameSizer]") || !e.data.endsWith("mutationObserver") && !e.data.endsWith("resizeObserver"))
33
43
  return null;
34
44
  const [t, n] = e.data.split(":"), r = +n;
35
45
  return r > 0 ? r : null;
36
46
  }
37
- const w = Q();
38
- let f = [];
39
- const U = (e, t) => {
40
- if (!v())
47
+ const z = ee();
48
+ let m = [];
49
+ const J = async (e, t) => {
50
+ if (!S())
41
51
  return [];
42
- const n = { ...x(), ...F(e ?? {}) }, r = j(t), a = q(n, r);
43
- return r.map((i) => {
44
- const o = {
45
- iframe: i,
46
- settings: n,
47
- interactionState: { isHovered: !1 },
48
- initContext: { isInitialized: !1, retryAttempts: 0 }
49
- }, s = J(o, a);
50
- return f.push(o), {
51
- unsubscribe: () => {
52
- s(), f = f.filter((c) => c.iframe !== i);
53
- }
54
- };
55
- });
52
+ const n = { ...$(), ...j(e ?? {}) }, r = K(t), i = Q(n, r);
53
+ return Promise.all(
54
+ r.map(async (o) => {
55
+ const s = {
56
+ iframe: o,
57
+ settings: n,
58
+ interactionState: { isHovered: !1 },
59
+ initContext: { isInitialized: !1, retryAttempts: 0 }
60
+ }, { unsubscribe: a, resize: u } = await V(s, i);
61
+ return m.push(s), {
62
+ unsubscribe: () => {
63
+ a(), m = m.filter((c) => c.iframe !== o);
64
+ },
65
+ resize: u
66
+ };
67
+ })
68
+ );
56
69
  };
57
- function j(e) {
58
- return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(h) : e ? h(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
70
+ function K(e) {
71
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(w) : e ? w(e) ? [e] : [] : Array.from(document.getElementsByTagName("iframe"));
59
72
  }
60
- function q(e, t) {
73
+ function Q(e, t) {
61
74
  if (Array.isArray(e.checkOrigin))
62
75
  return e.checkOrigin;
63
76
  if (!e.checkOrigin)
64
77
  return [];
65
78
  const n = [];
66
79
  for (const r of t) {
67
- const a = W(r);
68
- a && n.push(a);
80
+ const i = U(r);
81
+ i && n.push(i);
69
82
  }
70
83
  return n;
71
84
  }
72
- function J(e, t) {
73
- const n = C(e.iframe) ? G(e) : V(e, t), r = K(e);
74
- return () => {
75
- n(), r();
85
+ async function V(e, t) {
86
+ const n = await N(e.iframe), { unsubscribe: r, resize: i } = n ? Z(e) : X(e, t), o = Y(e);
87
+ return {
88
+ unsubscribe: () => {
89
+ r(), o();
90
+ },
91
+ resize: i
76
92
  };
77
93
  }
78
- function V(e, t) {
94
+ function X(e, t) {
79
95
  const {
80
96
  iframe: n,
81
97
  initContext: r,
82
- settings: { checkOrigin: a, enableLegacyLibSupport: i, targetElementSelector: o, bodyPadding: s, bodyMargin: c }
83
- } = e, b = (u) => {
84
- const L = !a || t.includes(u.origin);
85
- if (!(n.contentWindow !== u.source || !L)) {
86
- if (u.data?.type === "iframe-resized") {
87
- const { height: d } = u.data;
88
- d && m({ newHeight: d, registeredElement: e });
98
+ settings: { checkOrigin: i, enableLegacyLibSupport: o, targetElementSelector: s, bodyPadding: a, bodyMargin: u }
99
+ } = e, c = (d) => {
100
+ const O = d.origin === "null", B = !i || O || t.includes(d.origin);
101
+ if (!(n.contentWindow !== d.source || !B)) {
102
+ if (d.data?.type === "iframe-resized") {
103
+ const { height: l } = d.data;
104
+ l && g({ newHeight: l, registeredElement: e });
89
105
  return;
90
106
  }
91
- if (i) {
92
- const d = N(u);
93
- d !== null && m({ newHeight: d, registeredElement: e });
107
+ if (o) {
108
+ const l = G(d);
109
+ l !== null && g({ newHeight: l, registeredElement: e });
94
110
  return;
95
111
  }
96
112
  }
97
113
  };
98
- window.addEventListener("message", b);
99
- const R = i ? $() : { type: "iframe-child-init", targetElementSelector: o, bodyPadding: s, bodyMargin: c }, y = () => {
100
- D(n, () => n.contentWindow?.postMessage(R, "*")), r.retryAttempts++, r.retryTimeoutId = window.setTimeout(y, g(r.retryAttempts));
114
+ window.addEventListener("message", c);
115
+ const M = o ? q() : { type: "iframe-child-init", targetElementSelector: s, bodyPadding: a, bodyMargin: u }, h = () => {
116
+ C(n, () => n.contentWindow?.postMessage(M, "*")), r.retryAttempts++, r.retryTimeoutId = window.setTimeout(h, y(r.retryAttempts));
117
+ };
118
+ return h(), {
119
+ unsubscribe: () => window.removeEventListener("message", c),
120
+ resize: () => {
121
+ const d = { type: "iframe-get-child-dimensions" };
122
+ n.contentWindow?.postMessage(d, "*");
123
+ }
101
124
  };
102
- return y(), () => window.removeEventListener("message", b);
103
125
  }
104
- function G(e) {
126
+ function Z(e) {
105
127
  const { iframe: t, settings: n } = e, { targetElementSelector: r } = n;
106
- let a = 0;
107
- const i = () => {
108
- const o = l(t.contentDocument, r);
109
- if (!t.contentDocument || !o)
110
- return a++, setTimeout(i, g(a));
111
- E(t.contentDocument, n), w().observe(o);
128
+ let i = 0;
129
+ const o = () => {
130
+ const s = f(t.contentDocument, r);
131
+ if (!t.contentDocument || !s)
132
+ return i++, setTimeout(o, y(i));
133
+ E(t.contentDocument, n), z().observe(s);
112
134
  };
113
- return T(t, i), () => {
114
- const o = l(t.contentDocument, r);
115
- o && w().unobserve(o), t.removeEventListener("load", i);
135
+ return F(t, o), {
136
+ unsubscribe: () => {
137
+ const s = f(t.contentDocument, r);
138
+ s && z().unobserve(s);
139
+ },
140
+ resize: () => R(e)
116
141
  };
117
142
  }
118
- function K({ iframe: e, interactionState: t }) {
119
- const n = () => {
143
+ function Y({ iframe: e, interactionState: t, settings: n }) {
144
+ if (!n.onBeforeIframeResize && !n.onIframeResize)
145
+ return () => {
146
+ };
147
+ const r = () => {
120
148
  t.isHovered = !0;
121
- }, r = () => {
149
+ }, i = () => {
122
150
  t.isHovered = !1;
123
151
  };
124
- return e.addEventListener("mouseenter", n), e.addEventListener("mouseleave", r), () => {
125
- e.removeEventListener("mouseenter", n), e.removeEventListener("mouseleave", r);
152
+ return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", i), () => {
153
+ e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", i);
126
154
  };
127
155
  }
128
- function Q() {
156
+ function ee() {
129
157
  let e = null;
130
158
  return () => {
131
159
  if (!e) {
132
160
  const t = ({ target: n }) => {
133
- const r = f.find(({ iframe: c }) => c.contentDocument === n.ownerDocument);
134
- if (!r)
135
- return;
136
- const { iframe: a, settings: i } = r, o = l(a.contentDocument, i.targetElementSelector);
137
- if (!o)
138
- return;
139
- const { height: s } = S(o);
140
- s && m({ newHeight: s, registeredElement: r });
161
+ const r = m.find(({ iframe: i }) => i.contentDocument === n.ownerDocument);
162
+ r && R(r);
141
163
  };
142
164
  e = new ResizeObserver((n) => n.forEach(t));
143
165
  }
144
166
  return e;
145
167
  };
146
168
  }
147
- function m({ registeredElement: e, newHeight: t }) {
148
- const { iframe: n, settings: r, interactionState: a, initContext: i } = e;
149
- if (i.isInitialized || (i.isInitialized = !0, clearTimeout(i.retryTimeoutId)), r.onBeforeIframeResize?.({ iframe: n, settings: { ...r }, observedHeight: t }) === !1)
169
+ function R(e) {
170
+ const { iframe: t, settings: n } = e, r = f(t.contentDocument, n.targetElementSelector);
171
+ if (!r)
172
+ return;
173
+ const { height: i } = v(r);
174
+ i && g({ newHeight: i, registeredElement: e });
175
+ }
176
+ function g({ registeredElement: e, newHeight: t }) {
177
+ const { iframe: n, settings: r, interactionState: i, initContext: o } = e;
178
+ if (o.isInitialized || (o.isInitialized = !0, clearTimeout(o.retryTimeoutId)), r.onBeforeIframeResize?.({ iframe: n, interactionState: { ...i }, settings: { ...r }, observedHeight: t }) === !1)
150
179
  return;
151
- const o = n.getBoundingClientRect(), s = t + r.offsetSize;
152
- if (n.style.height = `${s}px`, !r.onIframeResize)
180
+ const s = n.getBoundingClientRect(), a = t + r.offsetSize;
181
+ if (n.style.height = `${a}px`, !r.onIframeResize)
153
182
  return;
154
- const c = {
183
+ const u = {
155
184
  iframe: n,
156
185
  settings: { ...r },
157
- interactionState: { ...a },
158
- previousRenderState: { rect: o },
186
+ interactionState: { ...i },
187
+ previousRenderState: { rect: s },
159
188
  nextRenderState: { rect: n.getBoundingClientRect() }
160
189
  };
161
- r.onIframeResize(c);
162
- }
163
- const X = Z();
164
- let p = !1;
165
- Y();
166
- function Y() {
167
- !v() || !H() || window.addEventListener("message", (e) => {
168
- e.data?.type === "iframe-child-init" && _(() => z(e));
190
+ r.onIframeResize(u);
191
+ }
192
+ const te = ie();
193
+ let b = !1, L;
194
+ ne();
195
+ function ne() {
196
+ !S() || !x() || window.addEventListener("message", (e) => {
197
+ if (e.data?.type === "iframe-child-init")
198
+ return p(() => I(e));
199
+ if (e.data?.type === "iframe-get-child-dimensions")
200
+ return p(() => re(e));
169
201
  });
170
202
  }
171
- function z(e, t = 0) {
172
- const { targetElementSelector: n, bodyPadding: r, bodyMargin: a } = e.data, i = l(document, n);
173
- if (p || window.parent !== e.source)
203
+ function I(e, t = 0) {
204
+ const { targetElementSelector: n, bodyPadding: r, bodyMargin: i } = e.data, o = f(document, n);
205
+ if (b || window.parent !== e.source)
174
206
  return;
175
- if (!i)
176
- return setTimeout(() => z(e, t + 1), g(t));
177
- E(document, { bodyMargin: a, bodyPadding: r });
178
- const o = X();
179
- o.disconnect(), o.observe(i), p = !0;
207
+ if (!o)
208
+ return setTimeout(() => I(e, t + 1), y(t));
209
+ E(document, { bodyMargin: i, bodyPadding: r }), L = n;
210
+ const s = te();
211
+ s.disconnect(), s.observe(o), b = !0;
212
+ }
213
+ function re(e) {
214
+ const t = f(document, L);
215
+ !b || window.parent !== e.source || !t || k(t);
180
216
  }
181
- function Z() {
217
+ function ie() {
182
218
  let e = null;
183
219
  return () => (e || (e = new ResizeObserver((t) => {
184
- if (!t[0].target)
185
- return;
186
- const { height: n, width: r } = S(t[0].target), a = {
187
- type: "iframe-resized",
188
- width: r,
189
- height: n
190
- };
191
- window.parent.postMessage(a, "*");
220
+ t[0].target && k(t[0].target);
192
221
  })), e);
193
222
  }
194
- const ee = I({
223
+ const k = (e) => {
224
+ const { width: t, height: n } = v(e), r = {
225
+ type: "iframe-resized",
226
+ width: t,
227
+ height: n
228
+ };
229
+ window.parent.postMessage(r, "*");
230
+ }, oe = P({
195
231
  name: "ResizableIframe",
196
232
  props: {
197
233
  offsetSize: [String, Number, Object],
198
234
  checkOrigin: [Boolean, Array],
199
235
  onIframeResize: Function,
200
236
  onBeforeIframeResize: Function,
201
- targetElementSelector: [String],
237
+ targetElementSelector: String,
202
238
  bodyMargin: [String, Number],
203
239
  bodyPadding: [String, Number],
204
240
  enableLegacyLibSupport: Boolean
205
241
  },
206
242
  setup(e, { attrs: t }) {
207
- const n = O(null);
208
- let r = [];
209
- const a = (i) => {
210
- const o = {
243
+ const n = D(null);
244
+ let r = [], i = !1;
245
+ const o = async (s) => {
246
+ const a = {
211
247
  offsetSize: e.offsetSize,
212
248
  enableLegacyLibSupport: e.enableLegacyLibSupport,
213
249
  checkOrigin: e.checkOrigin,
@@ -217,36 +253,40 @@ const ee = I({
217
253
  bodyMargin: e.bodyMargin,
218
254
  bodyPadding: e.bodyPadding
219
255
  };
220
- Object.keys(o).forEach((s) => {
221
- o[s] === void 0 && delete o[s];
222
- }), r = U(o, i);
256
+ Object.keys(a).forEach((c) => {
257
+ a[c] === void 0 && delete a[c];
258
+ });
259
+ const u = await J(a, s);
260
+ i ? u.forEach((c) => {
261
+ c.unsubscribe();
262
+ }) : r = u;
223
263
  };
224
- return k(() => {
225
- n.value && a(n.value);
226
- }), M(() => {
227
- r.forEach((i) => {
228
- i.unsubscribe();
264
+ return A(() => {
265
+ n.value && o(n.value);
266
+ }), H(() => {
267
+ i = !0, r.forEach((s) => {
268
+ s.unsubscribe();
229
269
  }), r = [];
230
270
  }), {
231
271
  iframeRef: n,
232
272
  attrs: t
233
273
  };
234
274
  }
235
- }), te = (e, t) => {
275
+ }), se = (e, t) => {
236
276
  const n = e.__vccOpts || e;
237
- for (const [r, a] of t)
238
- n[r] = a;
277
+ for (const [r, i] of t)
278
+ n[r] = i;
239
279
  return n;
240
280
  };
241
- function ne(e, t, n, r, a, i) {
242
- return P(), B("iframe", A({ ref: "iframeRef" }, e.$attrs), null, 16);
281
+ function ae(e, t, n, r, i, o) {
282
+ return T(), _("iframe", W({ ref: "iframeRef" }, e.$attrs), null, 16);
243
283
  }
244
- const re = /* @__PURE__ */ te(ee, [["render", ne]]), oe = {
284
+ const ce = /* @__PURE__ */ se(oe, [["render", ae]]), de = {
245
285
  install(e) {
246
- e.component("IframeResizer", re);
286
+ e.component("IframeResizer", ce);
247
287
  }
248
288
  };
249
289
  export {
250
- re as IframeResizer,
251
- oe as IframeResizerPlugin
290
+ ce as IframeResizer,
291
+ de as IframeResizerPlugin
252
292
  };
@@ -1 +1 @@
1
- (function(u,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(u=typeof globalThis<"u"?globalThis:u||self,a(u["open-iframe-resizer-vue"]={},u.Vue))})(this,function(u,a){"use strict";const h=()=>typeof window<"u",O=()=>window.self!==window.top,p=e=>e instanceof HTMLIFrameElement,M=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e)},k=(e,t)=>{t(),e.addEventListener("load",t)},B=(e,t)=>{const n=e.contentWindow?.document.readyState==="complete";return e.src!=="about:blank"&&e.contentWindow?.location.href!=="about:blank"&&n?t():e.addEventListener("load",t)},P=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),T=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},A=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},H=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&delete e[t]}),e),w=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},m=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,S=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},y=e=>e<=100?100:e<=120?1e3:1e4,_=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function D(e){if(typeof e.data!="string"||!e.data.startsWith("[iFrameSizer]")||!e.data.endsWith("mutationObserver")&&!e.data.endsWith("resizeObserver"))return null;const[t,n]=e.data.split(":"),r=+n;return r>0?r:null}const v=q();let g=[];const x=(e,t)=>{if(!h())return[];const n={...P(),...H(e??{})},r=C(t),s=W(n,r);return r.map(i=>{const o={iframe:i,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},c=F(o,s);return g.push(o),{unsubscribe:()=>{c(),g=g.filter(d=>d.iframe!==i)}}})};function C(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(p):e?p(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function W(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const r of t){const s=A(r);s&&n.push(s)}return n}function F(e,t){const n=T(e.iframe)?j(e):$(e,t),r=N(e);return()=>{n(),r()}}function $(e,t){const{iframe:n,initContext:r,settings:{checkOrigin:s,enableLegacyLibSupport:i,targetElementSelector:o,bodyPadding:c,bodyMargin:d}}=e,L=f=>{const Z=!s||t.includes(f.origin);if(!(n.contentWindow!==f.source||!Z)){if(f.data?.type==="iframe-resized"){const{height:l}=f.data;l&&b({newHeight:l,registeredElement:e});return}if(i){const l=D(f);l!==null&&b({newHeight:l,registeredElement:e});return}}};window.addEventListener("message",L);const Y=i?_():{type:"iframe-child-init",targetElementSelector:o,bodyPadding:c,bodyMargin:d},I=()=>{k(n,()=>n.contentWindow?.postMessage(Y,"*")),r.retryAttempts++,r.retryTimeoutId=window.setTimeout(I,y(r.retryAttempts))};return I(),()=>window.removeEventListener("message",L)}function j(e){const{iframe:t,settings:n}=e,{targetElementSelector:r}=n;let s=0;const i=()=>{const o=m(t.contentDocument,r);if(!t.contentDocument||!o)return s++,setTimeout(i,y(s));S(t.contentDocument,n),v().observe(o)};return B(t,i),()=>{const o=m(t.contentDocument,r);o&&v().unobserve(o),t.removeEventListener("load",i)}}function N({iframe:e,interactionState:t}){const n=()=>{t.isHovered=!0},r=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",r),()=>{e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",r)}}function q(){let e=null;return()=>{if(!e){const t=({target:n})=>{const r=g.find(({iframe:d})=>d.contentDocument===n.ownerDocument);if(!r)return;const{iframe:s,settings:i}=r,o=m(s.contentDocument,i.targetElementSelector);if(!o)return;const{height:c}=w(o);c&&b({newHeight:c,registeredElement:r})};e=new ResizeObserver(n=>n.forEach(t))}return e}}function b({registeredElement:e,newHeight:t}){const{iframe:n,settings:r,interactionState:s,initContext:i}=e;if(i.isInitialized||(i.isInitialized=!0,clearTimeout(i.retryTimeoutId)),r.onBeforeIframeResize?.({iframe:n,settings:{...r},observedHeight:t})===!1)return;const o=n.getBoundingClientRect(),c=t+r.offsetSize;if(n.style.height=`${c}px`,!r.onIframeResize)return;const d={iframe:n,settings:{...r},interactionState:{...s},previousRenderState:{rect:o},nextRenderState:{rect:n.getBoundingClientRect()}};r.onIframeResize(d)}const U=J();let z=!1;V();function V(){!h()||!O()||window.addEventListener("message",e=>{e.data?.type==="iframe-child-init"&&M(()=>E(e))})}function E(e,t=0){const{targetElementSelector:n,bodyPadding:r,bodyMargin:s}=e.data,i=m(document,n);if(z||window.parent!==e.source)return;if(!i)return setTimeout(()=>E(e,t+1),y(t));S(document,{bodyMargin:s,bodyPadding:r});const o=U();o.disconnect(),o.observe(i),z=!0}function J(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{if(!t[0].target)return;const{height:n,width:r}=w(t[0].target),s={type:"iframe-resized",width:r,height:n};window.parent.postMessage(s,"*")})),e)}const G=a.defineComponent({name:"ResizableIframe",props:{offsetSize:[String,Number,Object],checkOrigin:[Boolean,Array],onIframeResize:Function,onBeforeIframeResize:Function,targetElementSelector:[String],bodyMargin:[String,Number],bodyPadding:[String,Number],enableLegacyLibSupport:Boolean},setup(e,{attrs:t}){const n=a.ref(null);let r=[];const s=i=>{const o={offsetSize:e.offsetSize,enableLegacyLibSupport:e.enableLegacyLibSupport,checkOrigin:e.checkOrigin,onIframeResize:e.onIframeResize,onBeforeIframeResize:e.onBeforeIframeResize,targetElementSelector:e.targetElementSelector,bodyMargin:e.bodyMargin,bodyPadding:e.bodyPadding};Object.keys(o).forEach(c=>{o[c]===void 0&&delete o[c]}),r=x(o,i)};return a.onMounted(()=>{n.value&&s(n.value)}),a.onBeforeUnmount(()=>{r.forEach(i=>{i.unsubscribe()}),r=[]}),{iframeRef:n,attrs:t}}}),K=(e,t)=>{const n=e.__vccOpts||e;for(const[r,s]of t)n[r]=s;return n};function Q(e,t,n,r,s,i){return a.openBlock(),a.createElementBlock("iframe",a.mergeProps({ref:"iframeRef"},e.$attrs),null,16)}const R=K(G,[["render",Q]]),X={install(e){e.component("IframeResizer",R)}};u.IframeResizer=R,u.IframeResizerPlugin=X,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d["open-iframe-resizer-vue"]={},d.Vue))})(this,function(d,a){"use strict";const w=()=>typeof window<"u",B=()=>{try{return window.self!==window.top}catch{return!0}},z=e=>e instanceof HTMLIFrameElement,S=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e,{once:!0})},D=(e,t)=>{t(),e.addEventListener("load",t,{once:!0})},T=(e,t)=>{const n=e.contentWindow?.document.readyState==="complete";return e.src!=="about:blank"&&e.contentWindow?.location.href!=="about:blank"&&n?t():e.addEventListener("load",t,{once:!0})},A=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1});async function H(e){try{return e.contentDocument?.URL==="about:blank"?new Promise(t=>{e.addEventListener("load",()=>t(e.contentDocument!==null),{once:!0})}):e.contentDocument!==null}catch{return!1}}const _=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},W=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&delete e[t]}),e),v=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},m=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,E=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},y=e=>e<=100?100:e<=120?1e3:1e4,x=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function C(e){if(typeof e.data!="string"||!e.data.startsWith("[iFrameSizer]")||!e.data.endsWith("mutationObserver")&&!e.data.endsWith("resizeObserver"))return null;const[t,n]=e.data.split(":"),r=+n;return r>0?r:null}const R=G();let b=[];const F=async(e,t)=>{if(!w())return[];const n={...A(),...W(e??{})},r=$(t),i=j(n,r);return Promise.all(r.map(async o=>{const s={iframe:o,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},{unsubscribe:c,resize:f}=await N(s,i);return b.push(s),{unsubscribe:()=>{c(),b=b.filter(u=>u.iframe!==o)},resize:f}}))};function $(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(z):e?z(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function j(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const r of t){const i=_(r);i&&n.push(i)}return n}async function N(e,t){const n=await H(e.iframe),{unsubscribe:r,resize:i}=n?q(e):U(e,t),o=V(e);return{unsubscribe:()=>{r(),o()},resize:i}}function U(e,t){const{iframe:n,initContext:r,settings:{checkOrigin:i,enableLegacyLibSupport:o,targetElementSelector:s,bodyPadding:c,bodyMargin:f}}=e,u=l=>{const re=l.origin==="null",ie=!i||re||t.includes(l.origin);if(!(n.contentWindow!==l.source||!ie)){if(l.data?.type==="iframe-resized"){const{height:g}=l.data;g&&h({newHeight:g,registeredElement:e});return}if(o){const g=C(l);g!==null&&h({newHeight:g,registeredElement:e});return}}};window.addEventListener("message",u);const ne=o?x():{type:"iframe-child-init",targetElementSelector:s,bodyPadding:c,bodyMargin:f},P=()=>{D(n,()=>n.contentWindow?.postMessage(ne,"*")),r.retryAttempts++,r.retryTimeoutId=window.setTimeout(P,y(r.retryAttempts))};return P(),{unsubscribe:()=>window.removeEventListener("message",u),resize:()=>{const l={type:"iframe-get-child-dimensions"};n.contentWindow?.postMessage(l,"*")}}}function q(e){const{iframe:t,settings:n}=e,{targetElementSelector:r}=n;let i=0;const o=()=>{const s=m(t.contentDocument,r);if(!t.contentDocument||!s)return i++,setTimeout(o,y(i));E(t.contentDocument,n),R().observe(s)};return T(t,o),{unsubscribe:()=>{const s=m(t.contentDocument,r);s&&R().unobserve(s)},resize:()=>I(e)}}function V({iframe:e,interactionState:t,settings:n}){if(!n.onBeforeIframeResize&&!n.onIframeResize)return()=>{};const r=()=>{t.isHovered=!0},i=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",r),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",r),e.removeEventListener("mouseleave",i)}}function G(){let e=null;return()=>{if(!e){const t=({target:n})=>{const r=b.find(({iframe:i})=>i.contentDocument===n.ownerDocument);r&&I(r)};e=new ResizeObserver(n=>n.forEach(t))}return e}}function I(e){const{iframe:t,settings:n}=e,r=m(t.contentDocument,n.targetElementSelector);if(!r)return;const{height:i}=v(r);i&&h({newHeight:i,registeredElement:e})}function h({registeredElement:e,newHeight:t}){const{iframe:n,settings:r,interactionState:i,initContext:o}=e;if(o.isInitialized||(o.isInitialized=!0,clearTimeout(o.retryTimeoutId)),r.onBeforeIframeResize?.({iframe:n,interactionState:{...i},settings:{...r},observedHeight:t})===!1)return;const s=n.getBoundingClientRect(),c=t+r.offsetSize;if(n.style.height=`${c}px`,!r.onIframeResize)return;const f={iframe:n,settings:{...r},interactionState:{...i},previousRenderState:{rect:s},nextRenderState:{rect:n.getBoundingClientRect()}};r.onIframeResize(f)}const J=X();let p=!1,L;K();function K(){!w()||!B()||window.addEventListener("message",e=>{if(e.data?.type==="iframe-child-init")return S(()=>M(e));if(e.data?.type==="iframe-get-child-dimensions")return S(()=>Q(e))})}function M(e,t=0){const{targetElementSelector:n,bodyPadding:r,bodyMargin:i}=e.data,o=m(document,n);if(p||window.parent!==e.source)return;if(!o)return setTimeout(()=>M(e,t+1),y(t));E(document,{bodyMargin:i,bodyPadding:r}),L=n;const s=J();s.disconnect(),s.observe(o),p=!0}function Q(e){const t=m(document,L);!p||window.parent!==e.source||!t||O(t)}function X(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{t[0].target&&O(t[0].target)})),e)}const O=e=>{const{width:t,height:n}=v(e),r={type:"iframe-resized",width:t,height:n};window.parent.postMessage(r,"*")},Z=a.defineComponent({name:"ResizableIframe",props:{offsetSize:[String,Number,Object],checkOrigin:[Boolean,Array],onIframeResize:Function,onBeforeIframeResize:Function,targetElementSelector:String,bodyMargin:[String,Number],bodyPadding:[String,Number],enableLegacyLibSupport:Boolean},setup(e,{attrs:t}){const n=a.ref(null);let r=[],i=!1;const o=async s=>{const c={offsetSize:e.offsetSize,enableLegacyLibSupport:e.enableLegacyLibSupport,checkOrigin:e.checkOrigin,onIframeResize:e.onIframeResize,onBeforeIframeResize:e.onBeforeIframeResize,targetElementSelector:e.targetElementSelector,bodyMargin:e.bodyMargin,bodyPadding:e.bodyPadding};Object.keys(c).forEach(u=>{c[u]===void 0&&delete c[u]});const f=await F(c,s);i?f.forEach(u=>{u.unsubscribe()}):r=f};return a.onMounted(()=>{n.value&&o(n.value)}),a.onBeforeUnmount(()=>{i=!0,r.forEach(s=>{s.unsubscribe()}),r=[]}),{iframeRef:n,attrs:t}}}),Y=(e,t)=>{const n=e.__vccOpts||e;for(const[r,i]of t)n[r]=i;return n};function ee(e,t,n,r,i,o){return a.openBlock(),a.createElementBlock("iframe",a.mergeProps({ref:"iframeRef"},e.$attrs),null,16)}const k=Y(Z,[["render",ee]]),te={install(e){e.component("IframeResizer",k)}};d.IframeResizer=k,d.IframeResizerPlugin=te,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-iframe-resizer/vue",
3
3
  "private": false,
4
- "version": "1.6.1",
4
+ "version": "2.1.0",
5
5
  "description": "Open-source modern iframe resizer component",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "test": "npx playwright install --with-deps && npx playwright test"
44
44
  },
45
45
  "dependencies": {
46
- "@open-iframe-resizer/core": "1.6.1"
46
+ "@open-iframe-resizer/core": "2.1.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@vitejs/plugin-vue": "^6.0.1",