@open-iframe-resizer/vue 1.4.1 → 1.4.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as
|
|
1
|
+
import { defineComponent as O, ref as k, onMounted as M, onBeforeUnmount as P, createElementBlock as A, openBlock as B, mergeProps as _ } from "vue";
|
|
2
2
|
const S = () => typeof window < "u", D = () => window.self !== window.top, v = (e) => e instanceof HTMLIFrameElement, H = (e) => {
|
|
3
3
|
window.document.readyState === "complete" ? e() : window.addEventListener("load", e);
|
|
4
4
|
}, T = (e, t) => {
|
|
@@ -7,13 +7,13 @@ const S = () => typeof window < "u", D = () => window.self !== window.top, v = (
|
|
|
7
7
|
var n, r;
|
|
8
8
|
const i = ((n = e.contentWindow) == null ? void 0 : n.document.readyState) === "complete";
|
|
9
9
|
return e.src !== "about:blank" && ((r = e.contentWindow) == null ? void 0 : r.location.href) !== "about:blank" && i ? t() : e.addEventListener("load", t);
|
|
10
|
-
}, C = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }),
|
|
10
|
+
}, C = () => ({ offsetSize: 0, checkOrigin: !0, enableLegacyLibSupport: !1 }), W = (e) => {
|
|
11
11
|
try {
|
|
12
12
|
return new URL(e.src).origin === window.location.origin;
|
|
13
13
|
} catch {
|
|
14
14
|
return !1;
|
|
15
15
|
}
|
|
16
|
-
},
|
|
16
|
+
}, $ = (e) => {
|
|
17
17
|
try {
|
|
18
18
|
const t = new URL(e.src).origin;
|
|
19
19
|
if (t !== "about:blank")
|
|
@@ -21,25 +21,24 @@ const S = () => typeof window < "u", D = () => window.self !== window.top, v = (
|
|
|
21
21
|
} catch {
|
|
22
22
|
}
|
|
23
23
|
return null;
|
|
24
|
-
},
|
|
24
|
+
}, F = (e) => (Object.keys(e).forEach((t) => e[t] === void 0 && delete e[t]), e), E = (e) => {
|
|
25
25
|
const { height: t, width: n } = e.getBoundingClientRect();
|
|
26
26
|
return { height: Math.ceil(t), width: Math.ceil(n) };
|
|
27
27
|
}, f = (e, t) => e ? t ? e.querySelector(t) : e.documentElement : null, z = (e, t) => {
|
|
28
28
|
e && (t.bodyPadding && (e.body.style.padding = t.bodyPadding), t.bodyMargin && (e.body.style.margin = t.bodyMargin));
|
|
29
29
|
}, g = (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";
|
|
30
30
|
function U(e) {
|
|
31
|
-
if (typeof e.data
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return null;
|
|
31
|
+
if (typeof e.data != "string" || !e.data.startsWith("[iFrameSizer]") || !e.data.endsWith("mutationObserver") && !e.data.endsWith("resizeObserver"))
|
|
32
|
+
return null;
|
|
33
|
+
const [t, n] = e.data.split(":"), r = +n;
|
|
34
|
+
return r > 0 ? r : null;
|
|
36
35
|
}
|
|
37
36
|
const w = X();
|
|
38
37
|
let l = [];
|
|
39
38
|
const j = (e, t) => {
|
|
40
39
|
if (!S())
|
|
41
40
|
return [];
|
|
42
|
-
const n = { ...C(), ...
|
|
41
|
+
const n = { ...C(), ...F(e ?? {}) }, r = q(t), i = G(n, r);
|
|
43
42
|
return r.map((o) => {
|
|
44
43
|
const a = {
|
|
45
44
|
iframe: o,
|
|
@@ -49,7 +48,7 @@ const j = (e, t) => {
|
|
|
49
48
|
}, s = K(a, i);
|
|
50
49
|
return l.push(a), {
|
|
51
50
|
unsubscribe: () => {
|
|
52
|
-
s(), l = l.filter((
|
|
51
|
+
s(), l = l.filter((d) => d.iframe !== o);
|
|
53
52
|
}
|
|
54
53
|
};
|
|
55
54
|
});
|
|
@@ -64,13 +63,13 @@ function G(e, t) {
|
|
|
64
63
|
return [];
|
|
65
64
|
const n = [];
|
|
66
65
|
for (const r of t) {
|
|
67
|
-
const i =
|
|
66
|
+
const i = $(r);
|
|
68
67
|
i && n.push(i);
|
|
69
68
|
}
|
|
70
69
|
return n;
|
|
71
70
|
}
|
|
72
71
|
function K(e, t) {
|
|
73
|
-
const n =
|
|
72
|
+
const n = W(e.iframe) ? J(e) : V(e, t), r = Q(e);
|
|
74
73
|
return () => {
|
|
75
74
|
n(), r();
|
|
76
75
|
};
|
|
@@ -79,31 +78,31 @@ function V(e, t) {
|
|
|
79
78
|
const {
|
|
80
79
|
iframe: n,
|
|
81
80
|
initContext: r,
|
|
82
|
-
settings: { checkOrigin: i, enableLegacyLibSupport: o, targetElementSelector: a, bodyPadding: s, bodyMargin:
|
|
83
|
-
} = e,
|
|
81
|
+
settings: { checkOrigin: i, enableLegacyLibSupport: o, targetElementSelector: a, bodyPadding: s, bodyMargin: d }
|
|
82
|
+
} = e, b = (c) => {
|
|
84
83
|
var h;
|
|
85
84
|
const I = !i || t.includes(c.origin);
|
|
86
85
|
if (!(n.contentWindow !== c.source || !I)) {
|
|
87
86
|
if (((h = c.data) == null ? void 0 : h.type) === "iframe-resized") {
|
|
88
|
-
const { height:
|
|
89
|
-
|
|
87
|
+
const { height: u } = c.data;
|
|
88
|
+
u && m({ newHeight: u, registeredElement: e });
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
91
|
if (o) {
|
|
93
|
-
const
|
|
94
|
-
|
|
92
|
+
const u = U(c);
|
|
93
|
+
u !== null && m({ newHeight: u, registeredElement: e });
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
|
-
window.addEventListener("message",
|
|
100
|
-
const R = o ? N() : { type: "iframe-child-init", targetElementSelector: a, bodyPadding: s, bodyMargin:
|
|
98
|
+
window.addEventListener("message", b);
|
|
99
|
+
const R = o ? N() : { type: "iframe-child-init", targetElementSelector: a, bodyPadding: s, bodyMargin: d }, y = () => {
|
|
101
100
|
T(n, () => {
|
|
102
101
|
var c;
|
|
103
102
|
return (c = n.contentWindow) == null ? void 0 : c.postMessage(R, "*");
|
|
104
|
-
}), r.retryAttempts++, r.retryTimeoutId = window.setTimeout(
|
|
103
|
+
}), r.retryAttempts++, r.retryTimeoutId = window.setTimeout(y, g(r.retryAttempts));
|
|
105
104
|
};
|
|
106
|
-
return
|
|
105
|
+
return y(), () => window.removeEventListener("message", b);
|
|
107
106
|
}
|
|
108
107
|
function J(e) {
|
|
109
108
|
const { iframe: t, settings: n } = e, { targetElementSelector: r } = n;
|
|
@@ -134,7 +133,7 @@ function X() {
|
|
|
134
133
|
return () => {
|
|
135
134
|
if (!e) {
|
|
136
135
|
const t = ({ target: n }) => {
|
|
137
|
-
const r = l.find(({ iframe:
|
|
136
|
+
const r = l.find(({ iframe: d }) => d.contentDocument === n.ownerDocument);
|
|
138
137
|
if (!r)
|
|
139
138
|
return;
|
|
140
139
|
const { iframe: i, settings: o } = r, a = f(i.contentDocument, o.targetElementSelector);
|
|
@@ -154,14 +153,14 @@ function m({ registeredElement: e, newHeight: t }) {
|
|
|
154
153
|
const a = n.getBoundingClientRect(), s = t + r.offsetSize;
|
|
155
154
|
if (n.style.height = `${s}px`, !r.onIframeResize)
|
|
156
155
|
return;
|
|
157
|
-
const
|
|
156
|
+
const d = {
|
|
158
157
|
iframe: n,
|
|
159
158
|
settings: { ...r },
|
|
160
159
|
interactionState: { ...i },
|
|
161
160
|
previousRenderState: { rect: a },
|
|
162
161
|
nextRenderState: { rect: n.getBoundingClientRect() }
|
|
163
162
|
};
|
|
164
|
-
r.onIframeResize(
|
|
163
|
+
r.onIframeResize(d);
|
|
165
164
|
}
|
|
166
165
|
const Y = ee();
|
|
167
166
|
let p = !1;
|
|
@@ -195,7 +194,7 @@ function ee() {
|
|
|
195
194
|
window.parent.postMessage(i, "*");
|
|
196
195
|
})), e);
|
|
197
196
|
}
|
|
198
|
-
const te =
|
|
197
|
+
const te = O({
|
|
199
198
|
name: "ResizableIframe",
|
|
200
199
|
props: {
|
|
201
200
|
offsetSize: [String, Number, Object],
|
|
@@ -207,7 +206,7 @@ const te = k({
|
|
|
207
206
|
enableLegacyLibSupport: Boolean
|
|
208
207
|
},
|
|
209
208
|
setup(e, { attrs: t }) {
|
|
210
|
-
const n =
|
|
209
|
+
const n = k(null);
|
|
211
210
|
let r = [];
|
|
212
211
|
const i = (o) => {
|
|
213
212
|
const a = {
|
|
@@ -223,7 +222,7 @@ const te = k({
|
|
|
223
222
|
a[s] === void 0 && delete a[s];
|
|
224
223
|
}), r = j(a, o);
|
|
225
224
|
};
|
|
226
|
-
return
|
|
225
|
+
return M(() => {
|
|
227
226
|
n.value && i(n.value);
|
|
228
227
|
}), P(() => {
|
|
229
228
|
r.forEach((o) => o.unsubscribe()), r = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d["open-iframe-resizer-vue"]={},d.Vue))})(this,function(d,s){"use strict";const h=()=>typeof window<"u",
|
|
1
|
+
(function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d["open-iframe-resizer-vue"]={},d.Vue))})(this,function(d,s){"use strict";const h=()=>typeof window<"u",M=()=>window.self!==window.top,p=e=>e instanceof HTMLIFrameElement,k=e=>{window.document.readyState==="complete"?e():window.addEventListener("load",e)},P=(e,t)=>{t(),e.addEventListener("load",t)},T=(e,t)=>{var n,r;const i=((n=e.contentWindow)==null?void 0:n.document.readyState)==="complete";return e.src!=="about:blank"&&((r=e.contentWindow)==null?void 0:r.location.href)!=="about:blank"&&i?t():e.addEventListener("load",t)},A=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1}),B=e=>{try{return new URL(e.src).origin===window.location.origin}catch{return!1}},_=e=>{try{const t=new URL(e.src).origin;if(t!=="about:blank")return t}catch{}return null},D=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,w=(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,H=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function x(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 S=U();let g=[];const C=(e,t)=>{if(!h())return[];const n={...A(),...D(e??{})},r=W(t),i=$(n,r);return r.map(o=>{const a={iframe:o,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},c=F(a,i);return g.push(a),{unsubscribe:()=>{c(),g=g.filter(l=>l.iframe!==o)}}})};function W(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)).filter(p):e?p(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function $(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}function F(e,t){const n=B(e.iframe)?N(e):j(e,t),r=q(e);return()=>{n(),r()}}function j(e,t){const{iframe:n,initContext:r,settings:{checkOrigin:i,enableLegacyLibSupport:o,targetElementSelector:a,bodyPadding:c,bodyMargin:l}}=e,R=u=>{var O;const ee=!i||t.includes(u.origin);if(!(n.contentWindow!==u.source||!ee)){if(((O=u.data)==null?void 0:O.type)==="iframe-resized"){const{height:f}=u.data;f&&b({newHeight:f,registeredElement:e});return}if(o){const f=x(u);f!==null&&b({newHeight:f,registeredElement:e});return}}};window.addEventListener("message",R);const Z=o?H():{type:"iframe-child-init",targetElementSelector:a,bodyPadding:c,bodyMargin:l},I=()=>{P(n,()=>{var u;return(u=n.contentWindow)==null?void 0:u.postMessage(Z,"*")}),r.retryAttempts++,r.retryTimeoutId=window.setTimeout(I,y(r.retryAttempts))};return I(),()=>window.removeEventListener("message",R)}function N(e){const{iframe:t,settings:n}=e,{targetElementSelector:r}=n;let i=0;const o=()=>{const a=m(t.contentDocument,r);if(!t.contentDocument||!a)return i++,setTimeout(o,y(i));w(t.contentDocument,n),S().observe(a)};return T(t,o),()=>{const a=m(t.contentDocument,r);a&&S().unobserve(a),t.removeEventListener("load",o)}}function q({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=g.find(({iframe:l})=>l.contentDocument===n.ownerDocument);if(!r)return;const{iframe:i,settings:o}=r,a=m(i.contentDocument,o.targetElementSelector);if(!a)return;const{height:c}=v(a);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:i,initContext:o}=e;o.isInitialized||(o.isInitialized=!0,clearTimeout(o.retryTimeoutId));const a=n.getBoundingClientRect(),c=t+r.offsetSize;if(n.style.height=`${c}px`,!r.onIframeResize)return;const l={iframe:n,settings:{...r},interactionState:{...i},previousRenderState:{rect:a},nextRenderState:{rect:n.getBoundingClientRect()}};r.onIframeResize(l)}const V=K();let E=!1;G();function G(){!h()||!M()||window.addEventListener("message",e=>{var t;((t=e.data)==null?void 0:t.type)==="iframe-child-init"&&k(()=>z(e))})}function z(e,t=0){const{targetElementSelector:n,bodyPadding:r,bodyMargin:i}=e.data,o=m(document,n);if(E||window.parent!==e.source)return;if(!o)return setTimeout(()=>z(e,t+1),y(t));w(document,{bodyMargin:i,bodyPadding:r});const a=V();a.disconnect(),a.observe(o),E=!0}function K(){let e=null;return()=>(e||(e=new ResizeObserver(t=>{if(!t[0].target)return;const{height:n,width:r}=v(t[0].target),i={type:"iframe-resized",width:r,height:n};window.parent.postMessage(i,"*")})),e)}const J=s.defineComponent({name:"ResizableIframe",props:{offsetSize:[String,Number,Object],checkOrigin:[Boolean,Array],onIframeResize:Function,targetElementSelector:[String],bodyMargin:[String,Number],bodyPadding:[String,Number],enableLegacyLibSupport:Boolean},setup(e,{attrs:t}){const n=s.ref(null);let r=[];const i=o=>{const a={offsetSize:e.offsetSize,enableLegacyLibSupport:e.enableLegacyLibSupport,checkOrigin:e.checkOrigin,onIframeResize:e.onIframeResize,targetElementSelector:e.targetElementSelector,bodyMargin:e.bodyMargin,bodyPadding:e.bodyPadding};Object.keys(a).forEach(c=>{a[c]===void 0&&delete a[c]}),r=C(a,o)};return s.onMounted(()=>{n.value&&i(n.value)}),s.onBeforeUnmount(()=>{r.forEach(o=>o.unsubscribe()),r=[]}),{iframeRef:n,attrs:t}}}),Q=(e,t)=>{const n=e.__vccOpts||e;for(const[r,i]of t)n[r]=i;return n};function X(e,t,n,r,i,o){return s.openBlock(),s.createElementBlock("iframe",s.mergeProps({ref:"iframeRef"},e.$attrs),null,16)}const L=Q(J,[["render",X]]),Y={install(e){e.component("IframeResizer",L)}};d.IframeResizer=L,d.IframeResizerPlugin=Y,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.4.
|
|
4
|
+
"version": "1.4.3",
|
|
5
5
|
"description": "Open-source modern iframe resizer component",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -42,8 +42,10 @@
|
|
|
42
42
|
"serve": "concurrently \"vite --port 5552\" \"vite --port 5553\"",
|
|
43
43
|
"test": "npx playwright install --with-deps && npx playwright test"
|
|
44
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@open-iframe-resizer/core": "1.4.3"
|
|
47
|
+
},
|
|
45
48
|
"devDependencies": {
|
|
46
|
-
"@open-iframe-resizer/core": "1.4.1",
|
|
47
49
|
"@vitejs/plugin-vue": "^5.2.3",
|
|
48
50
|
"@vue/tsconfig": "^0.7.0",
|
|
49
51
|
"vue": "^3.5.13",
|