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