@data-fair/frame 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/d-frame.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=Object.defineProperty;var H=(l,c,f)=>c in l?x(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var n=(l,c,f)=>H(l,typeof c!="symbol"?c+"":c,f);(function(){"use strict";function l(e){return e[0]==="df-child"&&e[1]==="init"}function c(e){return e[0]==="df-child"&&e[1]==="height"}function f(e){return e[0]==="df-child"&&e[1]==="stateChange"}function m(e){return e[0]==="df-child"&&e[1]==="custom"}function b(e){return e[0]==="df-child"&&e[1]==="notif"}function y(e){return e[0]==="df-child"&&e[1]==="ready"}function w(e){return e.endsWith("/")?e:e===""?"/":e.slice(0,e.lastIndexOf("/")+1)}function E(e,a){if(a.origin!==e.origin)return a.href;if(a.pathname===e.pathname)return"";const t=w(e.pathname);return a.pathname.startsWith(t)?a.pathname.replace(t,"./"):a.pathname}const A=e=>e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&");function v(e){const a=[];for(const t of e.split(",")){const[s="*",i]=t.split(":"),r="^"+A(s).replace(/\\\*/g,"(.*)")+"$";a.push({regexp:new RegExp(r),append:i})}return a}function S(e,a,t,s){if(!t&&!s)return e.href;const i=new URL(a);if(t&&i.searchParams.forEach((r,d)=>{for(const h of t){if(h.append&&!d.startsWith(h.append)||d===s)continue;const o=h.append?d.replace(h.append,""):d;if(o.match(h.regexp)){e.searchParams.set(o,r);break}}}),s!==null){const r=i.searchParams.get(s);r&&(e.pathname=new URL(r,e).pathname)}return e.href}function C(e,a,t,s,i){const r=new URL(t),d=new URL(a);if(s&&(r.searchParams.forEach((h,o)=>{for(const u of s){if(u.append&&!o.startsWith(u.append))continue;const g=u.append?o.replace(u.append,""):o;if(g.match(u.regexp)){d.searchParams.get(g)===null&&r.searchParams.delete(o);break}}}),d.searchParams.forEach((h,o)=>{for(const u of s){if(!o.match(u.regexp)||(e==null?void 0:e.searchParams.get(o))===h)continue;const g=u.append?u.append+o:o;r.searchParams.set(g,h);break}})),i!==null&&e){const h=E(e,d);h?r.searchParams.set(i,h):r.searchParams.delete(i)}return r}function P(e){return e.vIframe===!0&&e.uiNotification!==void 0}function R(e){if(typeof e=="string")return{type:"default",title:e};if(e.error&&!e.errorMsg){const a=e.error.response&&(e.error.response.data||e.error.response.status)||e.error.message||e.error;return e.msg?{type:"error",title:e.msg,detail:a}:{type:"error",title:a}}return e.type==="error"?{type:e.clientError?"warning":"error",title:e.msg,detail:e.errorMsg}:{type:e.type??"default",title:e.msg}}class M{stateChange(a,t){a==="replace"&&window.history.replaceState(null,"",t),a==="push"&&window.history.pushState(null,"",t)}}const p=document.createElement("template");p.innerHTML=`<style>
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
}
|
|
@@ -11,5 +11,5 @@ var H=Object.defineProperty;var x=(l,c,f)=>c in l?H(l,c,{enumerable:!0,configura
|
|
|
11
11
|
height: 100%;
|
|
12
12
|
border: none;
|
|
13
13
|
}
|
|
14
|
-
</style><div class="d-frame-wrapper"><slot name="loading"><div style="min-height:150px;"></div></slot><iframe class="d-frame-iframe" style="visibility:hidden;position:absolute;height:0px;"></iframe></div>`;class
|
|
14
|
+
</style><div class="d-frame-wrapper"><slot name="loading"><div style="min-height:150px;"></div></slot><iframe class="d-frame-iframe" style="visibility:hidden;position:absolute;height:0px;"></iframe></div>`;class z extends HTMLElement{constructor(){super();n(this,"adapter");n(this,"connected",!1);n(this,"initialSrc");n(this,"srcUrl");n(this,"parsedSyncParams");n(this,"wrapperElement");n(this,"slotElement");n(this,"iframeElement");n(this,"width");n(this,"aspectRatioHeight");n(this,"resizedHeight");n(this,"randomId");n(this,"iframeLoaded",!1);n(this,"ready",!1);n(this,"iframeExtraAttrs",{});this.randomId=Math.random().toString(36).slice(-6);const t=p.content.cloneNode(!0);this.wrapperElement=t.childNodes[1],this.slotElement=this.wrapperElement.childNodes[0],this.iframeElement=this.wrapperElement.childNodes[1],this.iframeElement.addEventListener("load",()=>{this.iframeElement.getAttribute("src")&&(this.log("debug","iframe loaded"),this.iframeLoaded=!0,this.dispatchEvent(new CustomEvent("iframe-load")),this.resize!=="yes"&&!this.readyMessage&&(this.ready=!0,this.dispatchEvent(new CustomEvent("ready")),this.updateStyle()))}),this.attachShadow({mode:"open"}).appendChild(t),new ResizeObserver(r=>{(this.width===void 0||Math.abs(this.width-r[0].contentRect.width)>2)&&(this.width=r[0].contentRect.width,this.updateAspectRatioHeight())}).observe(this),this.adapter=new M,window.addEventListener("message",r=>this.onMessage(r))}get id(){return this.getAttribute("id")??this.randomId}set id(t){this.setAttribute("id",t)}get debug(){return this.hasAttribute("debug")}set debug(t){t?this.setAttribute("debug",""):this.removeAttribute("debug")}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t)}get aspectRatio(){const t=this.getAttribute("aspect-ratio");return t===""?"auto":t}set aspectRatio(t){t!==null?this.setAttribute("aspect-ratio",t):this.removeAttribute("aspect-ratio")}get height(){return this.getAttribute("height")}set height(t){t?this.setAttribute("height",t):this.removeAttribute("height")}set resize(t){this.setAttribute("resize",t)}get resize(){const t=this.getAttribute("resize");return t===null?"auto":t===""?"yes":t}get syncParams(){return this.getAttribute("sync-params")}set syncParams(t){t!==null?this.setAttribute("sync-params",t):this.removeAttribute("sync-params")}get syncPath(){const t=this.getAttribute("sync-path");return t===null?null:t||"p"}set syncPath(t){t!==null?this.setAttribute("sync-params",t):this.removeAttribute("sync-params")}get stateChangeEvents(){return this.hasAttribute("state-change-events")}set stateChangeEvents(t){t?this.setAttribute("state-change-events",""):this.removeAttribute("state-change-events")}get readyMessage(){return this.hasAttribute("ready-message")}set readyMessage(t){t?this.setAttribute("ready-message",""):this.removeAttribute("ready-message")}get actualAspectRatio(){return this.aspectRatio!=="auto"?Number(this.aspectRatio):!this.width||this.width<500?1:this.width<800?4/3:this.width<1200?16/9:21/9}onMessage(t){var s;if(t.source===((s=this.iframeElement)==null?void 0:s.contentWindow)){const i=t.data;if(this.log("debug","received message from child",i),Array.isArray(t.data)){if(l(i)&&(this.postMessageToChild(["df-parent","init",{id:this.id,debug:this.debug,resize:this.resize,syncParams:this.syncParams!==null,syncPath:this.syncPath!==null,stateChangeEvents:this.stateChangeEvents}]),this.init()),c(i)&&(this.resizedHeight=i[2],this.resize==="yes"&&!this.ready&&!this.readyMessage&&(this.ready=!0,this.dispatchEvent(new CustomEvent("ready"))),this.updateStyle()),f(i)){if(this.parsedSyncParams||this.syncPath){const r=C(this.srcUrl,i[3],window.location.href,this.parsedSyncParams,this.syncPath);r.href!==window.location.href&&this.adapter.stateChange(i[2],r)}this.stateChangeEvents&&this.dispatchEvent(new CustomEvent("state-change",{detail:[i[2],i[3]]}))}m(i)&&this.dispatchEvent(new CustomEvent("message",{detail:i[2]})),b(i)&&this.dispatchEvent(new CustomEvent("notif",{detail:i[2]})),y(i)&&(this.ready=!0,this.dispatchEvent(new CustomEvent("ready")),this.updateStyle())}else P(i)&&this.dispatchEvent(new CustomEvent("notif",{detail:R(i.uiNotification)}))}}init(){this.initialSrc=this.src}postMessageToChild(t){var s,i;this.log("debug","send message to child",t),(i=(s=this.iframeElement)==null?void 0:s.contentWindow)==null||i.postMessage(t)}updateSrc(){if(!this.connected)return;this.srcUrl=new URL(this.src.startsWith("/")?window.location.origin+this.src:this.src);const t=S(this.srcUrl,window.location.href,this.parsedSyncParams,this.syncPath);this.initialSrc?this.postMessageToChild(["df-parent","updateSrc",t]):(this.log("debug","set src attribute of iframe: "+t),this.iframeElement.setAttribute("src",t))}updateStyle(){if(!this.connected)return;let t;this.resizedHeight?(this.log("debug","height of iframe based on resize message: "+this.resizedHeight),t=this.resizedHeight+"px"):this.height?(this.log("debug","height of iframe based on direct attribute: "+this.height),t=this.height):this.aspectRatio!==null&&(this.log("debug","height of iframe based on aspect ratio: "+this.aspectRatioHeight),t=this.aspectRatioHeight+"px"),t!==void 0?(this.log("debug","set height iframe wrapper: "+t),this.wrapperElement.setAttribute("style",`height:${t};min-height:0;`)):this.wrapperElement.setAttribute("style",""),this.resize==="yes"||this.resize==="auto"&&this.resizedHeight?this.iframeElement.getAttribute("scrolling")!=="no"&&(this.log("debug","set scrolling attribute of iframe: no"),this.iframeElement.setAttribute("scrolling","no")):this.iframeElement.getAttribute("scrolling")!=="auto"&&(this.log("debug","set scrolling attribute of iframe: auto"),this.iframeElement.setAttribute("scrolling","auto")),this.ready&&this.iframeElement.getAttribute("style")!==""&&(this.log("debug","toggle loading slot and iframe visibility"),this.iframeElement.setAttribute("style",""),this.slotElement.setAttribute("style","display:none;"))}updateAspectRatioHeight(){this.width&&this.aspectRatio!==null&&(this.resizedHeight||this.height||(this.aspectRatioHeight=Math.ceil(this.width/this.actualAspectRatio),this.updateStyle()))}updateIframeExtraAttrs(){const t=this.iframeExtraAttrs,s={};for(const i of this.getAttributeNames())if(i.startsWith("iframe-")){const r=this.getAttribute(i);if(r!==null){const d=i.slice(7);s[d]=r}}this.log("debug","update iframe extra attributes",t,s);for(const i of Object.keys(t))i in s||this.iframeElement.removeAttribute(i);for(const i of Object.keys(s))s[i]!==t[i]&&this.iframeElement.setAttribute(i,s[i])}log(t,...s){t==="debug"&&!this.debug||(t==="debug"&&console.timeLog(`d-frame:${this.id}`,...s),t==="info"&&console.info(`d-frame:${this.id}`,...s))}connectedCallback(){if(!this.debug){const t=window.localStorage.getItem("debug");if(t){const s=t.split(",");(s.includes("d-frame")||s.includes("d-frame:"+this.id))&&(this.debug=!0)}}if(this.debug&&console.time(`d-frame:${this.id}`),!this.hasAttribute("src"))throw new Error("src is a required attribute");this.log("debug","connected"),this.connected=!0,this.adapter.onStateChange&&this.adapter.onStateChange(()=>{this.updateSrc()}),this.syncParams!==null&&(this.parsedSyncParams=v(this.syncParams||"*")),this.updateStyle(),this.updateIframeExtraAttrs(),this.updateSrc()}disconnectedCallback(){this.log("debug","disconnected"),this.debug&&console.timeEnd(`d-frame:${this.id}`)}static get observedAttributes(){return["src","aspect-ratio","height","sync-params","sync-path"]}attributeChangedCallback(t,s,i){t==="aspect-ratio"&&this.updateAspectRatioHeight(),t.startsWith("iframe-")&&this.updateIframeExtraAttrs(),this.connected&&(this.log("debug","attribute change",t,s,i),t==="src"&&this.updateSrc(),t==="height"&&this.updateStyle(),t==="sync-params"&&this.updateSrc(),t==="sync-path"&&this.updateSrc())}}customElements.get("d-frame")||customElements.define("d-frame",z)})();
|
|
15
15
|
//# sourceMappingURL=d-frame.min.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var VIframeCompatDFrameContent=function(){"use strict";var w=Object.defineProperty;var p=(
|
|
1
|
+
var VIframeCompatDFrameContent=function(){"use strict";var w=Object.defineProperty;var p=(h,s,c)=>s in h?w(h,s,{enumerable:!0,configurable:!0,writable:!0,value:c}):h[s]=c;var r=(h,s,c)=>p(h,typeof s!="symbol"?s+"":s,c);function h(n){return n[0]==="df-parent"&&n[1]==="init"}function s(n){return n[0]==="df-parent"&&n[1]==="updateSrc"}const c=["animationstart","webkitAnimationStart","animationiteration","webkitAnimationIteration","animationend","webkitAnimationEnd","input","mouseup","mousedown","orientationchange","afterprint","beforeprint","readystatechange","touchstart","touchend","touchcancel","transitionstart","webkitTransitionStart","MSTransitionStart","oTransitionStart","otransitionstart","transitioniteration","webkitTransitionIteration","MSTransitionIteration","oTransitionIteration","otransitioniteration","transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend","resize"];class u{constructor(t){r(this,"initialized",!1);r(this,"options");r(this,"pendingCheckHeight",!1);r(this,"debug",!1);r(this,"id");r(this,"throttledCheckHeight");r(this,"lastHeight",0);this.options=t??{};const e=()=>{this.checkHeight(),this.pendingCheckHeight=!1};this.throttledCheckHeight=()=>{this.pendingCheckHeight||(this.pendingCheckHeight=!0,requestAnimationFrame(e))},!(typeof window>"u")&&(window.addEventListener("message",i=>this.onMessage(i)),this.postMessageToParent(["df-child","init"]))}log(t,...e){t==="debug"&&!this.debug||(t==="debug"&&console.timeLog(`d-frame:${this.id}:content`,...e),t==="info"&&console.info(`d-frame:${this.id}:content`,...e))}onMessage(t){if(t.source===window.parent&&Array.isArray(t.data)){const e=t.data;h(e)&&(this.id=e[2].id,this.debug=!!e[2].debug,this.debug&&console.time(`d-frame:${this.id}:content`),e[2].resize!=="no"&&this.initResize(),(e[2].syncParams||e[2].syncPath||e[2].stateChangeEvents)&&this.initStateChangeWatcher(),this.initialized=!0),s(e)&&(this.options.updateSrc?this.options.updateSrc(e[2].startsWith("/")?window.location.origin+e[2]:e[2]):window.location.href=e[2])}}postMessageToParent(t){window.parent.postMessage(t)}sendNotif(t){this.postMessageToParent(["df-child","notif",t])}sendMessage(t){this.postMessageToParent(["df-child","custom",t])}ready(){this.postMessageToParent(["df-child","ready"])}initResize(){this.log("debug","initResize"),this.checkHeight(),this.createMutationObserver(),this.createWindowEventListeners()}initStateChangeWatcher(){this.log("debug","initStateChangeWatcher");const t=window.history.replaceState,e=(...a)=>{const o=t.apply(window.history,a);return this.postMessageToParent(["df-child","stateChange","push",window.location.href]),o};window.history.pushState=e;const i=(...a)=>{const o=t.apply(window.history,a);return this.postMessageToParent(["df-child","stateChange","replace",window.location.href]),o};window.history.replaceState=i}createMutationObserver(){const t=document.querySelector("body");if(!t)throw new Error("DFrameContentManager was initialized before the HTML body");new window.MutationObserver(this.throttledCheckHeight).observe(t,{attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1,childList:!0,subtree:!0})}createWindowEventListeners(){for(const t of c)window.addEventListener(t,this.throttledCheckHeight,{passive:!0})}checkHeight(){const t=document.querySelectorAll("[data-iframe-height]");let e=0,i=0;for(const a of t){const o=a.getAttribute("data-iframe-height"),d=a.getBoundingClientRect().bottom+parseFloat(getComputedStyle(a).getPropertyValue("margin-bottom")),f=o?d+parseFloat(o):d;d>e&&(e=d),f>i&&(i=f)}i=Math.ceil(i),e>0&&i!==this.lastHeight&&(this.postMessageToParent(["df-child","height",i]),this.lastHeight=i)}}const g=(n,t)=>{const e=Object.keys(n);t.forEach((i,a)=>{n[a]=i,e.splice(e.indexOf(a),1)}),e.forEach(i=>{delete n[i]})},l=new u({updateSrc:n=>{var i,a;const t=window.vIframeOptions,e=t==null?void 0:t.reactiveParams;if(e&&typeof e=="object"){const o=new URL(n);if(o.origin===window.location.origin&&o.pathname===window.location.pathname){g(e,o.searchParams);return}}if(t!=null&&t.router){let o=(i=t.router.options)==null?void 0:i.base;if(!o&&((a=t.router.options)!=null&&a.history)&&(o=t.router.options.history.base),!o)console.error("failed to access base path in router (no router.options.base nor router.options.history.base)"),window.location.href=n;else{const d=window.location.origin+o;if(n.startsWith(d)){t.router.replace(n.replace(d,""));return}}}window.location.href=n}});return window.dFrameContent=l,l}();
|
|
2
2
|
//# sourceMappingURL=d-frame-content.min.js.map
|
package/lib/DFrameElement.d.ts
CHANGED
|
@@ -8,8 +8,6 @@ export default class DFrameElement extends HTMLElement {
|
|
|
8
8
|
set id(value: string);
|
|
9
9
|
get debug(): boolean;
|
|
10
10
|
set debug(value: boolean);
|
|
11
|
-
get lazy(): boolean;
|
|
12
|
-
set lazy(value: boolean);
|
|
13
11
|
get src(): string;
|
|
14
12
|
set src(value: string);
|
|
15
13
|
get aspectRatio(): string | null;
|
package/lib/DFrameElement.js
CHANGED
|
@@ -37,13 +37,6 @@ export default class DFrameElement extends HTMLElement {
|
|
|
37
37
|
else
|
|
38
38
|
this.removeAttribute('debug');
|
|
39
39
|
}
|
|
40
|
-
get lazy() { return this.hasAttribute('lazy'); }
|
|
41
|
-
set lazy(value) {
|
|
42
|
-
if (value)
|
|
43
|
-
this.setAttribute('lazy', '');
|
|
44
|
-
else
|
|
45
|
-
this.removeAttribute('lazy');
|
|
46
|
-
}
|
|
47
40
|
get src() { return this.getAttribute('src'); }
|
|
48
41
|
set src(value) { this.setAttribute('src', value); }
|
|
49
42
|
get aspectRatio() {
|
|
@@ -141,8 +134,6 @@ export default class DFrameElement extends HTMLElement {
|
|
|
141
134
|
this.wrapperElement = root.childNodes[1];
|
|
142
135
|
this.slotElement = this.wrapperElement.childNodes[0];
|
|
143
136
|
this.iframeElement = this.wrapperElement.childNodes[1];
|
|
144
|
-
this.iframeElement.setAttribute('scrolling', this.resize === 'yes' ? 'no' : 'auto');
|
|
145
|
-
this.iframeElement.setAttribute('loading', this.lazy ? 'lazy' : 'eager');
|
|
146
137
|
this.iframeElement.addEventListener('load', () => {
|
|
147
138
|
if (this.iframeElement.getAttribute('src')) {
|
|
148
139
|
this.log('debug', 'iframe loaded');
|
|
@@ -313,6 +304,7 @@ export default class DFrameElement extends HTMLElement {
|
|
|
313
304
|
}
|
|
314
305
|
}
|
|
315
306
|
}
|
|
307
|
+
this.log('debug', 'update iframe extra attributes', previousAttrs, newAttrs);
|
|
316
308
|
for (const key of Object.keys(previousAttrs)) {
|
|
317
309
|
if (!(key in newAttrs)) {
|
|
318
310
|
this.iframeElement.removeAttribute(key);
|
|
@@ -354,8 +346,8 @@ export default class DFrameElement extends HTMLElement {
|
|
|
354
346
|
if (this.syncParams !== null)
|
|
355
347
|
this.parsedSyncParams = parseSyncParams(this.syncParams || '*');
|
|
356
348
|
this.updateStyle();
|
|
357
|
-
this.updateSrc();
|
|
358
349
|
this.updateIframeExtraAttrs();
|
|
350
|
+
this.updateSrc();
|
|
359
351
|
}
|
|
360
352
|
disconnectedCallback() {
|
|
361
353
|
this.log('debug', 'disconnected');
|
|
@@ -12,10 +12,20 @@ const dFrameContent = new DFrameContent({
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
if (vIframeOptions?.router) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// @ts-ignore vue-router v2
|
|
16
|
+
let base = vIframeOptions.router.options?.base;
|
|
17
|
+
if (!base && vIframeOptions.router.options?.history)
|
|
18
|
+
base = vIframeOptions.router.options.history.base;
|
|
19
|
+
if (!base) {
|
|
20
|
+
console.error('failed to access base path in router (no router.options.base nor router.options.history.base)');
|
|
21
|
+
window.location.href = src;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const urlPrefix = window.location.origin + base;
|
|
25
|
+
if (src.startsWith(urlPrefix)) {
|
|
26
|
+
vIframeOptions.router.replace(src.replace(urlPrefix, ''));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
window.location.href = src;
|