@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 +34 -0
- package/dist/open-iframe-resizer-vue.es.js +143 -119
- package/dist/open-iframe-resizer-vue.umd.js +1 -1
- package/package.json +2 -2
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
|
|
2
|
-
const
|
|
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
|
-
},
|
|
8
|
+
}, w = (e) => e instanceof HTMLIFrameElement, p = (e) => {
|
|
9
9
|
window.document.readyState === "complete" ? e() : window.addEventListener("load", e, { once: !0 });
|
|
10
|
-
},
|
|
10
|
+
}, C = (e, t) => {
|
|
11
11
|
t(), e.addEventListener("load", t, { once: !0 });
|
|
12
|
-
},
|
|
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
|
-
},
|
|
16
|
-
async function
|
|
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
|
|
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
|
-
},
|
|
33
|
+
}, j = (e) => (Object.keys(e).forEach((t) => {
|
|
34
34
|
e[t] === void 0 && delete e[t];
|
|
35
|
-
}), 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
|
-
},
|
|
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,
|
|
41
|
-
function
|
|
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
|
|
48
|
-
let
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
47
|
+
const z = ee();
|
|
48
|
+
let m = [];
|
|
49
|
+
const J = async (e, t) => {
|
|
50
|
+
if (!S())
|
|
51
51
|
return [];
|
|
52
|
-
const n = {
|
|
52
|
+
const n = { ...$(), ...j(e ?? {}) }, r = K(t), i = Q(n, r);
|
|
53
53
|
return Promise.all(
|
|
54
|
-
r.map(async (
|
|
55
|
-
const
|
|
56
|
-
iframe:
|
|
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
|
-
},
|
|
61
|
-
return
|
|
60
|
+
}, { unsubscribe: a, resize: u } = await V(s, i);
|
|
61
|
+
return m.push(s), {
|
|
62
62
|
unsubscribe: () => {
|
|
63
|
-
|
|
64
|
-
}
|
|
63
|
+
a(), m = m.filter((c) => c.iframe !== o);
|
|
64
|
+
},
|
|
65
|
+
resize: u
|
|
65
66
|
};
|
|
66
67
|
})
|
|
67
68
|
);
|
|
68
69
|
};
|
|
69
|
-
function
|
|
70
|
-
return typeof e == "string" ? Array.from(document.querySelectorAll(e)).filter(
|
|
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
|
|
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 =
|
|
80
|
+
const i = U(r);
|
|
80
81
|
i && n.push(i);
|
|
81
82
|
}
|
|
82
83
|
return n;
|
|
83
84
|
}
|
|
84
|
-
async function
|
|
85
|
-
const n = await
|
|
86
|
-
return
|
|
87
|
-
|
|
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
|
|
94
|
+
function X(e, t) {
|
|
91
95
|
const {
|
|
92
96
|
iframe: n,
|
|
93
97
|
initContext: r,
|
|
94
|
-
settings: { checkOrigin: i, enableLegacyLibSupport:
|
|
95
|
-
} = e,
|
|
96
|
-
const
|
|
97
|
-
if (!(n.contentWindow !== d.source || !
|
|
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 (
|
|
104
|
-
const l =
|
|
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",
|
|
111
|
-
const
|
|
112
|
-
|
|
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
|
|
126
|
+
function Z(e) {
|
|
117
127
|
const { iframe: t, settings: n } = e, { targetElementSelector: r } = n;
|
|
118
128
|
let i = 0;
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
if (!t.contentDocument || !
|
|
122
|
-
return i++, setTimeout(
|
|
123
|
-
E(t.contentDocument, n),
|
|
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
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
131
|
-
|
|
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
|
-
},
|
|
149
|
+
}, i = () => {
|
|
134
150
|
t.isHovered = !1;
|
|
135
151
|
};
|
|
136
|
-
return e.addEventListener("mouseenter",
|
|
137
|
-
e.removeEventListener("mouseenter",
|
|
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
|
|
156
|
+
function ee() {
|
|
141
157
|
let e = null;
|
|
142
158
|
return () => {
|
|
143
159
|
if (!e) {
|
|
144
160
|
const t = ({ target: n }) => {
|
|
145
|
-
const r =
|
|
146
|
-
|
|
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:
|
|
161
|
-
if (
|
|
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
|
|
164
|
-
if (n.style.height = `${
|
|
180
|
+
const s = n.getBoundingClientRect(), a = t + r.offsetSize;
|
|
181
|
+
if (n.style.height = `${a}px`, !r.onIframeResize)
|
|
165
182
|
return;
|
|
166
|
-
const
|
|
183
|
+
const u = {
|
|
167
184
|
iframe: n,
|
|
168
185
|
settings: { ...r },
|
|
169
186
|
interactionState: { ...i },
|
|
170
|
-
previousRenderState: { rect:
|
|
187
|
+
previousRenderState: { rect: s },
|
|
171
188
|
nextRenderState: { rect: n.getBoundingClientRect() }
|
|
172
189
|
};
|
|
173
|
-
r.onIframeResize(
|
|
190
|
+
r.onIframeResize(u);
|
|
174
191
|
}
|
|
175
|
-
const
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
function
|
|
179
|
-
!
|
|
180
|
-
e.data?.type === "iframe-child-init"
|
|
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
|
|
184
|
-
const { targetElementSelector: n, bodyPadding: r, bodyMargin: i } = e.data,
|
|
185
|
-
if (
|
|
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 (!
|
|
188
|
-
return setTimeout(() =>
|
|
189
|
-
E(document, { bodyMargin: i, bodyPadding: r });
|
|
190
|
-
const
|
|
191
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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 =
|
|
243
|
+
const n = D(null);
|
|
220
244
|
let r = [], i = !1;
|
|
221
|
-
const
|
|
222
|
-
const
|
|
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(
|
|
233
|
-
|
|
256
|
+
Object.keys(a).forEach((c) => {
|
|
257
|
+
a[c] === void 0 && delete a[c];
|
|
234
258
|
});
|
|
235
|
-
const
|
|
236
|
-
i ?
|
|
237
|
-
|
|
238
|
-
}) : r =
|
|
259
|
+
const u = await J(a, s);
|
|
260
|
+
i ? u.forEach((c) => {
|
|
261
|
+
c.unsubscribe();
|
|
262
|
+
}) : r = u;
|
|
239
263
|
};
|
|
240
|
-
return
|
|
241
|
-
n.value &&
|
|
242
|
-
}),
|
|
243
|
-
i = !0, r.forEach((
|
|
244
|
-
|
|
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
|
-
}),
|
|
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
|
|
258
|
-
return
|
|
281
|
+
function ae(e, t, n, r, i, o) {
|
|
282
|
+
return T(), _("iframe", W({ ref: "iframeRef" }, e.$attrs), null, 16);
|
|
259
283
|
}
|
|
260
|
-
const
|
|
284
|
+
const ce = /* @__PURE__ */ se(oe, [["render", ae]]), de = {
|
|
261
285
|
install(e) {
|
|
262
|
-
e.component("IframeResizer",
|
|
286
|
+
e.component("IframeResizer", ce);
|
|
263
287
|
}
|
|
264
288
|
};
|
|
265
289
|
export {
|
|
266
|
-
|
|
267
|
-
|
|
290
|
+
ce as IframeResizer,
|
|
291
|
+
de as IframeResizerPlugin
|
|
268
292
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,
|
|
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.
|
|
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.
|
|
46
|
+
"@open-iframe-resizer/core": "2.2.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@vitejs/plugin-vue": "^6.0.1",
|