nanosplash 2.5.0 → 2.5.1

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 +1 @@
1
- var t=Object.defineProperty,s=Object.defineProperties,e=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,h=(s,e,i)=>e in s?t(s,e,{t:!0,i:!0,writable:!0,value:i}):s[e]=i,o=document.createElement("style");o.innerHTML=".ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}\n",document.head.appendChild(o),function(){function t(t){return document.querySelector(t)}const o=t=>document.createElement(t);function a(t,...s){t.classList.add(...s)}function c(t,s,e){t.setAttribute(s,e)}class l{static h(s){if("string"==typeof s){const e=t(s);if(!e)throw new Error(`No match with ${s}`);return e}if(s instanceof Node)return s;throw new Error("Destination argument must string or Node")}static o(t){const o={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return a=((t,s)=>{for(var e in s||(s={}))n.call(s,e)&&h(t,e,s[e]);if(i)for(var e of i(s))r.call(s,e)&&h(t,e,s[e]);return t})({},o),s(a,e({inside:s=>(t.moveTo(s),o)}));var a}static l(){const t=o("div");return a(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class u{constructor(t,s,e){var i;this.u=o("div"),this.m=o("div"),this.g=o("div"),this.p=l.l(),this.v=o("div"),this.k=o("div"),this.S=o("div"),this.I=o("img"),this.id=Math.random().toString(36).substring(2),this.D=t,this.m.innerText=s,this.j=e,this.I.src=null!=(i=this.j)?i:"",this.I.alt=m.F,this.u.style.fontSize=t.N(),this.p.style.display=t.O()?"flex":"none",this.A(),this.setImgSrc(e)}T(){a(this.S,"ns-container"),a(this.k,"ns-blur"),a(this.I,"ns-img"),a(this.m,"ns-text"),a(this.g,"ns-text-container"),a(this.p,"ns-spinner"),a(this.v,"ns","ns-window"),a(this.u,"ns-wrapper")}R(){this.g.append(this.m,this.p),this.S.append(this.I,this.g),this.v.append(this.S),this.u.append(this.k,this.v)}A(){this.u.id=this.getId(),c(this.u,"data-ctx","nanosplash"),this.R(),this.T()}getId(){return this.id}getText(){return this.m.innerText}setText(t){return this.m.innerText=t,this}getImgSrc(){return this.j}setImgSrc(t){return this.I.src=null!=t?t:"",this.I.style.display=t?"block":"none",this.R(),this}C(){return this.M}W(){const t=this.u.parentElement;t&&this.B(t)}H(){c(this.u,"style",""),this.u.classList.remove("ns-fs")}P(t){const s=t.parentNode;s&&(this.B(s),s.replaceChild(this.u,t),this.k.appendChild(t))}V(){this.u.classList.add("ns-fs"),((t,s,e=!1)=>{t&&s&&(s.hasChildNodes()&&e?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}$(t){this.D.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){this.W(),this.M=l.h(t),this.$(this.M),this.M===document.body?this.V():(this.H(),this.P(this.M)),this.A()}G(t){Array.from(this.k.childNodes).forEach(t)}B(t){this.G((s=>t.insertBefore(s,this.u)))}J(){[this.m,this.p,this.g,this.I,this.S,this.k,this.v,this.u].forEach((t=>t.remove()))}delete(){this.W(),this.J(),this.D.delete(this)}}class d{static K(t,s,e,i){var n;return t||(t=new u(s,e,i)),t.setText(e).setImgSrc(null!=(n=t.getImgSrc())?n:i)}static L(t,s){return e=>(s=d.K(s,t,e),t.U.set(s.getId(),s),s.moveTo(document.body),l.o(s))}static X(t,s){return(...e)=>((s=d.K(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[i,n]]of e.entries())s.setText(n),await i;s.delete()})(),l.o(s))}static Y(t,s){return e=>(s=d.K(s,t,""),{show:i=>(t.U.set(s.getId(),s),s.moveTo(document.body),s.setText(i),e.finally((()=>s.delete())),l.o(s))})}}const f=class{constructor(t){var s;this.j=null==t?void 0:t.j,this.Z=void 0===(null==t?void 0:t.Z)?f._:t.Z,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.U=new Map}setImgSrc(t){return this.j=t,this}tt(t){return this.Z=t,this}st(t){return this.fontSize=t,this}getImgSrc(){return this.j}O(){return this.Z}N(){return this.fontSize}show(t){return d.L(this,new u(this,t,this.j))(t)}progress(...t){return d.X(this,new u(this,"",this.j))(...t)}while(t){return d.Y(this,new u(this,"",this.j))(t)}et(t){const s=this.U.size,e=Array.from(this.U.values());for(let i=s-1;i>=0;i--){const s=e[i];if(!t(s.getId(),s,i))break}}delete(t){this.U.delete(t.getId())}hideAll(){this.U.forEach((t=>t.delete()))}hide(s){if(s){const e=this.U.get(s);e?e.delete():Array.from(this.U.values()).filter((e=>e.C()===t(s))).forEach((t=>t.delete()))}else{const t=this.U.size;this.et(((s,e,i)=>{const n=i===t-1;return n&&e.delete(),n}))}}q(t){return Array.from(this.U.values()).filter((s=>s.C()===t))}};let m=f;m.F="Nanosplash",m._=!0,window.addEventListener("load",(()=>{window.Nanosplash=m,window.ns=new m}))}();
1
+ var t=document.createElement("style");t.innerHTML=".ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}\n",document.head.appendChild(t),function(){function t(t){return document.querySelector(t)}const s=t=>document.createElement(t);function e(t,...s){t.classList.add(...s)}function i(t,s,e){t.setAttribute(s,e)}class n extends Error{constructor(t,s){super(t),this.name=this.constructor.name,this.t=s}}class r extends n{constructor(t,s,e){super(t),this.destination=s,this.t=e}}class h extends n{constructor(t,s){super(t),this.i=s}}class o{static h(s){if("string"==typeof s)try{const e=t(s);if(!e)throw new n(`No DOM match with ${s}`);return e}catch(t){throw new r(`Destination (${s}) is either invalid or non-existing in DOM`,s,t)}else if(s instanceof Node)return s;throw new h(`Destination (${s}) must be either a Node or a CSS selector`,s)}static o(t){const s={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return{...s,inside:e=>(t.moveTo(e),s)}}static l(){const t=s("div");return e(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class a{constructor(t,e,i){var n;this.u=s("div"),this.m=s("div"),this.g=s("div"),this.p=o.l(),this.v=s("div"),this.k=s("div"),this.S=s("div"),this.D=s("img"),this.id=Math.random().toString(36).substring(2),this.I=t,this.m.innerText=e,this.N=i,this.D.src=null!=(n=this.N)?n:"",this.D.alt=u.F,this.u.style.fontSize=t.A(),this.p.style.display=t.T()?"flex":"none",this.M(),this.setImgSrc(i)}R(){e(this.S,"ns-container"),e(this.k,"ns-blur"),e(this.D,"ns-img"),e(this.m,"ns-text"),e(this.g,"ns-text-container"),e(this.p,"ns-spinner"),e(this.v,"ns","ns-window"),e(this.u,"ns-wrapper")}C(){this.g.append(this.m,this.p),this.S.append(this.D,this.g),this.v.append(this.S),this.u.append(this.k,this.v)}M(){this.u.id=this.getId(),i(this.u,"data-ctx","nanosplash"),this.C(),this.R()}getId(){return this.id}getText(){return this.m.innerText}setText(t){return this.m.innerText=t,this}getImgSrc(){return this.N}setImgSrc(t){return this.D.src=null!=t?t:"",this.D.style.display=t?"block":"none",this.C(),this}O(){return this.W}j(){const t=this.u.parentElement;t&&this.$(t)}B(){i(this.u,"style",""),this.u.classList.remove("ns-fs")}H(t){const s=t.parentNode;s&&(this.$(s),s.replaceChild(this.u,t),this.k.appendChild(t))}P(){this.u.classList.add("ns-fs"),((t,s,e=!1)=>{t&&s&&(s.hasChildNodes()&&e?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}V(t){this.I.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){try{this.j(),this.W=o.h(t),this.V(this.W),this.W===document.body?this.P():(this.B(),this.H(this.W)),this.M()}catch(t){console.warn(t)}}G(t){Array.from(this.k.childNodes).forEach(t)}$(t){this.G((s=>t.insertBefore(s,this.u)))}J(){[this.m,this.p,this.g,this.D,this.S,this.k,this.v,this.u].forEach((t=>t.remove()))}delete(){this.j(),this.J(),this.I.delete(this)}}class c{static K(t,s,e,i){var n;return t||(t=new a(s,e,i)),t.setText(e).setImgSrc(null!=(n=t.getImgSrc())?n:i)}static L(t,s){return e=>(s=c.K(s,t,e),t.U.set(s.getId(),s),s.moveTo(document.body),o.o(s))}static X(t,s){return(...e)=>((s=c.K(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[i,n]]of e.entries())s.setText(n),await i;s.delete()})(),o.o(s))}static Y(t,s){return e=>(s=c.K(s,t,""),{show:i=>(t.U.set(s.getId(),s),s.moveTo(document.body),s.setText(i),e.finally((()=>s.delete())),o.o(s))})}}const l=class{constructor(t){var s;this.N=null==t?void 0:t.N,this.Z=void 0===(null==t?void 0:t.Z)?l._:t.Z,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.U=new Map}setImgSrc(t){return this.N=t,this}tt(t){return this.Z=t,this}st(t){return this.fontSize=t,this}getImgSrc(){return this.N}T(){return this.Z}A(){return this.fontSize}show(t){return c.L(this,new a(this,t,this.N))(t)}progress(...t){return c.X(this,new a(this,"",this.N))(...t)}while(t){return c.Y(this,new a(this,"",this.N))(t)}et(t){const s=this.U.size,e=Array.from(this.U.values());for(let i=s-1;i>=0;i--){const s=e[i];if(!t(s.getId(),s,i))break}}delete(t){this.U.delete(t.getId())}hideAll(){this.U.forEach((t=>t.delete()))}hide(s){if(s){const e=s instanceof Node,i=t=>{Array.from(this.U.values()).filter((s=>s.O()===t)).forEach((t=>t.delete()))};if("string"==typeof s){const e=this.U.get(s);if(e)e.delete();else{const e=t(s);e&&i(e)}}else e&&i(s)}else{const t=this.U.size;this.et(((s,e,i)=>{const n=i===t-1;return n&&e.delete(),n}))}}q(t){return Array.from(this.U.values()).filter((s=>s.O()===t))}};let u=l;u.F="Nanosplash",u._=!0,window.addEventListener("load",(()=>{window.Nanosplash=u,window.ns=new u}))}();
@@ -1 +1 @@
1
- var t=Object.defineProperty,s=Object.defineProperties,i=Object.getOwnPropertyDescriptors,e=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,h=(s,i,e)=>i in s?t(s,i,{t:!0,i:!0,writable:!0,value:e}):s[i]=e;function o(t){return document.querySelector(t)}const c=t=>document.createElement(t);function a(t,...s){t.classList.add(...s)}function u(t,s,i){t.setAttribute(s,i)}class l{static h(t){if("string"==typeof t){const s=o(t);if(!s)throw new Error(`No match with ${t}`);return s}if(t instanceof Node)return t;throw new Error("Destination argument must string or Node")}static o(t){const o={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return c=((t,s)=>{for(var i in s||(s={}))n.call(s,i)&&h(t,i,s[i]);if(e)for(var i of e(s))r.call(s,i)&&h(t,i,s[i]);return t})({},o),s(c,i({inside:s=>(t.moveTo(s),o)}));var c}static u(){const t=c("div");return a(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class SplashInstance{constructor(t,s,i){var e;this.l=c("div"),this.m=c("div"),this.g=c("div"),this.v=l.u(),this.p=c("div"),this.S=c("div"),this.I=c("div"),this.F=c("img"),this.id=Math.random().toString(36).substring(2),this.N=t,this.m.innerText=s,this.O=i,this.F.src=null!=(e=this.O)?e:"",this.F.alt=Nanosplash.A,this.l.style.fontSize=t.getFontSize(),this.v.style.display=t.spinnerIsVisible()?"flex":"none",this.j(),this.setImgSrc(i)}T(){a(this.I,"ns-container"),a(this.S,"ns-blur"),a(this.F,"ns-img"),a(this.m,"ns-text"),a(this.g,"ns-text-container"),a(this.v,"ns-spinner"),a(this.p,"ns","ns-window"),a(this.l,"ns-wrapper")}D(){this.g.append(this.m,this.v),this.I.append(this.F,this.g),this.p.append(this.I),this.l.append(this.S,this.p)}j(){this.l.id=this.getId(),u(this.l,"data-ctx","nanosplash"),this.D(),this.T()}getId(){return this.id}getText(){return this.m.innerText}setText(t){return this.m.innerText=t,this}getImgSrc(){return this.O}setImgSrc(t){return this.F.src=null!=t?t:"",this.F.style.display=t?"block":"none",this.D(),this}getDestination(){return this.C}M(){const t=this.l.parentElement;t&&this.W(t)}k(){u(this.l,"style",""),this.l.classList.remove("ns-fs")}R(t){const s=t.parentNode;s&&(this.W(s),s.replaceChild(this.l,t),this.S.appendChild(t))}B(){this.l.classList.add("ns-fs"),((t,s,i=!1)=>{t&&s&&(s.hasChildNodes()&&i?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.l,document.body,!0)}H(t){this.N.getFromDestinationNode(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){this.M(),this.C=l.h(t),this.H(this.C),this.C===document.body?this.B():(this.k(),this.R(this.C)),this.j()}P(t){Array.from(this.S.childNodes).forEach(t)}W(t){this.P((s=>t.insertBefore(s,this.l)))}V(){[this.m,this.v,this.g,this.F,this.I,this.S,this.p,this.l].forEach((t=>t.remove()))}delete(){this.M(),this.V(),this.N.delete(this)}}class d{static $(t,s,i,e){var n;return t||(t=new SplashInstance(s,i,e)),t.setText(i).setImgSrc(null!=(n=t.getImgSrc())?n:e)}static q(t,s){return i=>(s=d.$(s,t,i),t.G.set(s.getId(),s),s.moveTo(document.body),l.o(s))}static J(t,s){return(...i)=>((s=d.$(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[e,n]]of i.entries())s.setText(n),await e;s.delete()})(),l.o(s))}static K(t,s){return i=>(s=d.$(s,t,""),{show:e=>(t.G.set(s.getId(),s),s.moveTo(document.body),s.setText(e),i.finally((()=>s.delete())),l.o(s))})}}const m=class{constructor(t){var s;this.O=null==t?void 0:t.O,this.L=void 0===(null==t?void 0:t.L)?m.U:t.L,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.G=new Map}setImgSrc(t){return this.O=t,this}showSpinner(t){return this.L=t,this}setFontSize(t){return this.fontSize=t,this}getImgSrc(){return this.O}spinnerIsVisible(){return this.L}getFontSize(){return this.fontSize}show(t){return d.q(this,new SplashInstance(this,t,this.O))(t)}progress(...t){return d.J(this,new SplashInstance(this,"",this.O))(...t)}while(t){return d.K(this,new SplashInstance(this,"",this.O))(t)}X(t){const s=this.G.size,i=Array.from(this.G.values());for(let e=s-1;e>=0;e--){const s=i[e];if(!t(s.getId(),s,e))break}}delete(t){this.G.delete(t.getId())}hideAll(){this.G.forEach((t=>t.delete()))}hide(t){if(t){const s=this.G.get(t);s?s.delete():Array.from(this.G.values()).filter((s=>s.getDestination()===o(t))).forEach((t=>t.delete()))}else{const t=this.G.size;this.X(((s,i,e)=>{const n=e===t-1;return n&&i.delete(),n}))}}getFromDestinationNode(t){return Array.from(this.G.values()).filter((s=>s.getDestination()===t))}};let Nanosplash=m;Nanosplash.A="Nanosplash",Nanosplash.U=!0,module.exports=Nanosplash;
1
+ function t(t){return document.querySelector(t)}const s=t=>document.createElement(t);function i(t,...s){t.classList.add(...s)}function e(t,s,i){t.setAttribute(s,i)}class Exception extends Error{constructor(t,s){super(t),this.name=this.constructor.name,this.t=s}}class DestinationException extends Exception{constructor(t,s,i){super(t),this.destination=s,this.t=i}}class IllegalArgumentException extends Exception{constructor(t,s){super(t),this.i=s}}class NanosplashRepository{static h(s){if("string"==typeof s)try{const i=t(s);if(!i)throw new Exception(`No DOM match with ${s}`);return i}catch(t){throw new DestinationException(`Destination (${s}) is either invalid or non-existing in DOM`,s,t)}else if(s instanceof Node)return s;throw new IllegalArgumentException(`Destination (${s}) must be either a Node or a CSS selector`,s)}static o(t){const s={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return{...s,inside:i=>(t.moveTo(i),s)}}static l(){const t=s("div");return i(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class SplashInstance{constructor(t,i,e){var n;this.u=s("div"),this.p=s("div"),this.m=s("div"),this.g=NanosplashRepository.l(),this.S=s("div"),this.v=s("div"),this.N=s("div"),this.I=s("img"),this.id=Math.random().toString(36).substring(2),this.F=t,this.p.innerText=i,this.D=e,this.I.src=null!=(n=this.D)?n:"",this.I.alt=h.A,this.u.style.fontSize=t.getFontSize(),this.g.style.display=t.spinnerIsVisible()?"flex":"none",this.R(),this.setImgSrc(e)}T(){i(this.N,"ns-container"),i(this.v,"ns-blur"),i(this.I,"ns-img"),i(this.p,"ns-text"),i(this.m,"ns-text-container"),i(this.g,"ns-spinner"),i(this.S,"ns","ns-window"),i(this.u,"ns-wrapper")}M(){this.m.append(this.p,this.g),this.N.append(this.I,this.m),this.S.append(this.N),this.u.append(this.v,this.S)}R(){this.u.id=this.getId(),e(this.u,"data-ctx","nanosplash"),this.M(),this.T()}getId(){return this.id}getText(){return this.p.innerText}setText(t){return this.p.innerText=t,this}getImgSrc(){return this.D}setImgSrc(t){return this.I.src=null!=t?t:"",this.I.style.display=t?"block":"none",this.M(),this}getDestination(){return this.C}O(){const t=this.u.parentElement;t&&this.W(t)}$(){e(this.u,"style",""),this.u.classList.remove("ns-fs")}k(t){const s=t.parentNode;s&&(this.W(s),s.replaceChild(this.u,t),this.v.appendChild(t))}j(){this.u.classList.add("ns-fs"),((t,s,i=!1)=>{t&&s&&(s.hasChildNodes()&&i?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}B(t){this.F.getFromDestinationNode(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){try{this.O(),this.C=NanosplashRepository.h(t),this.B(this.C),this.C===document.body?this.j():(this.$(),this.k(this.C)),this.R()}catch(t){console.warn(t)}}H(t){Array.from(this.v.childNodes).forEach(t)}W(t){this.H((s=>t.insertBefore(s,this.u)))}P(){[this.p,this.g,this.m,this.I,this.N,this.v,this.S,this.u].forEach((t=>t.remove()))}delete(){this.O(),this.P(),this.F.delete(this)}}class NanosplashFactory{static V(t,s,i,e){var n;return t||(t=new SplashInstance(s,i,e)),t.setText(i).setImgSrc(null!=(n=t.getImgSrc())?n:e)}static q(t,s){return i=>(s=NanosplashFactory.V(s,t,i),t.G.set(s.getId(),s),s.moveTo(document.body),NanosplashRepository.o(s))}static J(t,s){return(...i)=>((s=NanosplashFactory.V(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[e,n]]of i.entries())s.setText(n),await e;s.delete()})(),NanosplashRepository.o(s))}static K(t,s){return i=>(s=NanosplashFactory.V(s,t,""),{show:e=>(t.G.set(s.getId(),s),s.moveTo(document.body),s.setText(e),i.finally((()=>s.delete())),NanosplashRepository.o(s))})}}const n=class{constructor(t){var s;this.D=null==t?void 0:t.D,this.L=void 0===(null==t?void 0:t.L)?n.U:t.L,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.G=new Map}setImgSrc(t){return this.D=t,this}showSpinner(t){return this.L=t,this}setFontSize(t){return this.fontSize=t,this}getImgSrc(){return this.D}spinnerIsVisible(){return this.L}getFontSize(){return this.fontSize}show(t){return NanosplashFactory.q(this,new SplashInstance(this,t,this.D))(t)}progress(...t){return NanosplashFactory.J(this,new SplashInstance(this,"",this.D))(...t)}while(t){return NanosplashFactory.K(this,new SplashInstance(this,"",this.D))(t)}X(t){const s=this.G.size,i=Array.from(this.G.values());for(let e=s-1;e>=0;e--){const s=i[e];if(!t(s.getId(),s,e))break}}delete(t){this.G.delete(t.getId())}hideAll(){this.G.forEach((t=>t.delete()))}hide(s){if(s){const i=s instanceof Node,e=t=>{Array.from(this.G.values()).filter((s=>s.getDestination()===t)).forEach((t=>t.delete()))};if("string"==typeof s){const i=this.G.get(s);if(i)i.delete();else{const i=t(s);i&&e(i)}}else i&&e(s)}else{const t=this.G.size;this.X(((s,i,e)=>{const n=e===t-1;return n&&i.delete(),n}))}}getFromDestinationNode(t){return Array.from(this.G.values()).filter((s=>s.getDestination()===t))}};let h=n;h.A="Nanosplash",h.U=!0,module.exports=h;
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  var style = /* @__PURE__ */ (() => ".ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}\n")();
21
2
  function get(selector) {
22
3
  return document.querySelector(selector);
@@ -33,18 +14,42 @@ function addClass(node, ...classes) {
33
14
  function setAttr(node, attribute, value) {
34
15
  node.setAttribute(attribute, value);
35
16
  }
17
+ class Exception extends Error {
18
+ constructor(message, cause) {
19
+ super(message);
20
+ this.name = this.constructor.name;
21
+ this.cause = cause;
22
+ }
23
+ }
24
+ class DestinationException extends Exception {
25
+ constructor(message, destination, cause) {
26
+ super(message);
27
+ this.destination = destination;
28
+ this.cause = cause;
29
+ }
30
+ }
31
+ class IllegalArgumentException extends Exception {
32
+ constructor(message, argument) {
33
+ super(message);
34
+ this.argument = argument;
35
+ }
36
+ }
36
37
  class NanosplashRepository {
37
38
  static destinationToNode(destination) {
38
39
  if (typeof destination === "string") {
39
- const element = get(destination);
40
- if (!element) {
41
- throw new Error(`No match with ${destination}`);
40
+ try {
41
+ const element = get(destination);
42
+ if (!element) {
43
+ throw new Exception(`No DOM match with ${destination}`);
44
+ }
45
+ return element;
46
+ } catch (e) {
47
+ throw new DestinationException(`Destination (${destination}) is either invalid or non-existing in DOM`, destination, e);
42
48
  }
43
- return element;
44
49
  } else if (destination instanceof Node) {
45
50
  return destination;
46
51
  }
47
- throw new Error("Destination argument must string or Node");
52
+ throw new IllegalArgumentException(`Destination (${destination}) must be either a Node or a CSS selector`, destination);
48
53
  }
49
54
  static createContextualApiObject(splash) {
50
55
  const ctx = {
@@ -56,12 +61,13 @@ class NanosplashRepository {
56
61
  getImgSrc: () => splash.getImgSrc(),
57
62
  setImgSrc: (src) => splash.setImgSrc(src)
58
63
  };
59
- return __spreadProps(__spreadValues({}, ctx), {
64
+ return {
65
+ ...ctx,
60
66
  inside: (selector) => {
61
67
  splash.moveTo(selector);
62
68
  return ctx;
63
69
  }
64
- });
70
+ };
65
71
  }
66
72
  static createNanosplashSpinnerElement() {
67
73
  const div = mk("div");
@@ -168,17 +174,21 @@ class SplashInstance {
168
174
  this.nsInstance.getFromDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete);
169
175
  }
170
176
  moveTo(destination) {
171
- this.cleanAndRestore();
172
- this.destinationNode = NanosplashRepository.destinationToNode(destination);
173
- this.replaceSplashInstancesHavingSameDestination(this.destinationNode);
174
- const targetIsBody = this.destinationNode === document.body;
175
- if (targetIsBody) {
176
- this.moveWithFullscreenStrategy();
177
- } else {
178
- this.resetFullscreenAttributes();
179
- this.moveWithRegularStrategy(this.destinationNode);
177
+ try {
178
+ this.cleanAndRestore();
179
+ this.destinationNode = NanosplashRepository.destinationToNode(destination);
180
+ this.replaceSplashInstancesHavingSameDestination(this.destinationNode);
181
+ const targetIsBody = this.destinationNode === document.body;
182
+ if (targetIsBody) {
183
+ this.moveWithFullscreenStrategy();
184
+ } else {
185
+ this.resetFullscreenAttributes();
186
+ this.moveWithRegularStrategy(this.destinationNode);
187
+ }
188
+ this.assembleNSComponent();
189
+ } catch (e) {
190
+ console.warn(e);
180
191
  }
181
- this.assembleNSComponent();
182
192
  }
183
193
  forEachWrappedNode(callback) {
184
194
  Array.from(this.nsWrapperElement.childNodes).forEach(callback);
@@ -304,15 +314,25 @@ const _Nanosplash = class {
304
314
  hideAll() {
305
315
  this.instances.forEach((instance) => instance.delete());
306
316
  }
307
- hide(idOrSelector) {
308
- if (idOrSelector) {
309
- const splashInstance = this.instances.get(idOrSelector);
310
- if (splashInstance) {
311
- splashInstance.delete();
312
- } else {
313
- Array.from(this.instances.values()).filter((splashInstance2) => {
314
- return splashInstance2.getDestination() === get(idOrSelector);
315
- }).forEach((splashInstance2) => splashInstance2.delete());
317
+ hide(ref) {
318
+ if (ref) {
319
+ const isString = typeof ref === "string";
320
+ const isNode = ref instanceof Node;
321
+ const deleteInstancesWhereDestination = (destination) => {
322
+ Array.from(this.instances.values()).filter((v) => v.getDestination() === destination).forEach((v) => v.delete());
323
+ };
324
+ if (isString) {
325
+ const splashInstance = this.instances.get(ref);
326
+ if (splashInstance) {
327
+ splashInstance.delete();
328
+ } else {
329
+ const element = get(ref);
330
+ if (element) {
331
+ deleteInstancesWhereDestination(element);
332
+ }
333
+ }
334
+ } else if (isNode) {
335
+ deleteInstancesWhereDestination(ref);
316
336
  }
317
337
  } else {
318
338
  const n = this.instances.size;
package/docs/index.html CHANGED
@@ -108,20 +108,22 @@
108
108
  <footer>
109
109
 
110
110
  <script>
111
- document.getElementById('demo').onclick = function () {
112
- const wait = ms => new Promise(r => setTimeout(r, ms))
113
- window.ns.progress(
114
- [wait(2000), 'Loading data from API'],
115
- [wait(4000), 'Restructuring'],
116
- [wait(6000), 'Indexing'],
117
- [wait(8000), 'Give this repo a star']
118
- )
119
- }
120
- document.getElementById('copy').onclick = function () {
121
- const text = document.querySelector('[data-copy]').innerText
122
- navigator.clipboard.writeText(text)
123
- alert('Copied to clipboard!')
124
- }
111
+ window.addEventListener('load', () => {
112
+ document.getElementById('demo').onclick = function () {
113
+ const wait = ms => new Promise(r => setTimeout(r, ms))
114
+ window.ns.progress(
115
+ [wait(2000), 'Loading data from API'],
116
+ [wait(4000), 'Restructuring'],
117
+ [wait(6000), 'Indexing'],
118
+ [wait(8000), 'Give this repo a star']
119
+ )
120
+ }
121
+ document.getElementById('copy').onclick = function () {
122
+ const text = document.querySelector('[data-copy]').innerText
123
+ navigator.clipboard.writeText(text)
124
+ alert('Copied to clipboard!')
125
+ }
126
+ })
125
127
  </script>
126
128
  </footer>
127
129
  <style>body{min-height:100vh}</style>
@@ -1,6 +1,6 @@
1
- var v=Object.defineProperty,b=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var I=(l,o,a)=>o in l?v(l,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):l[o]=a,y=(l,o)=>{for(var a in o||(o={}))N.call(o,a)&&I(l,a,o[a]);if(S)for(var a of S(o))k.call(o,a)&&I(l,a,o[a]);return l},w=(l,o)=>b(l,T(o));(function(){"use strict";const l=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const f of r.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&i(f)}).observe(document,{childList:!0,subtree:!0});function t(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerpolicy&&(r.referrerPolicy=s.referrerpolicy),s.crossorigin==="use-credentials"?r.credentials="include":s.crossorigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=t(s);fetch(s.href,r)}};var o=(()=>`.ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}
2
- `)();function a(n){return document.querySelector(n)}function x(n,e,t=!1){n&&e&&(e.hasChildNodes()&&t?e.insertBefore(n,e.firstChild):e.appendChild(n))}const m=n=>document.createElement(n);function c(n,...e){n.classList.add(...e)}function E(n,e,t){n.setAttribute(e,t)}class d{static destinationToNode(e){if(typeof e=="string"){const t=a(e);if(!t)throw new Error(`No match with ${e}`);return t}else if(e instanceof Node)return e;throw new Error("Destination argument must string or Node")}static createContextualApiObject(e){const t={getId:()=>e.getId(),remove:()=>e.delete(),moveTo:i=>e.moveTo(i),getText:()=>e.getText(),setText:i=>e.setText(i),getImgSrc:()=>e.getImgSrc(),setImgSrc:i=>e.setImgSrc(i)};return w(y({},t),{inside:i=>(e.moveTo(i),t)})}static createNanosplashSpinnerElement(){const e=m("div");return c(e,"ns-spinner"),e.innerHTML=`
1
+ (function(){"use strict";const y=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const m of r.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&i(m)}).observe(document,{childList:!0,subtree:!0});function t(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerpolicy&&(r.referrerPolicy=s.referrerpolicy),s.crossorigin==="use-credentials"?r.credentials="include":s.crossorigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=t(s);fetch(s.href,r)}};var x=(()=>`.ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}
2
+ `)();function f(n){return document.querySelector(n)}function p(n,e,t=!1){n&&e&&(e.hasChildNodes()&&t?e.insertBefore(n,e.firstChild):e.appendChild(n))}const a=n=>document.createElement(n);function o(n,...e){n.classList.add(...e)}function g(n,e,t){n.setAttribute(e,t)}class u extends Error{constructor(e,t){super(e),this.name=this.constructor.name,this.cause=t}}class S extends u{constructor(e,t,i){super(e),this.destination=t,this.cause=i}}class I extends u{constructor(e,t){super(e),this.argument=t}}class l{static destinationToNode(e){if(typeof e=="string")try{const t=f(e);if(!t)throw new u(`No DOM match with ${e}`);return t}catch(t){throw new S(`Destination (${e}) is either invalid or non-existing in DOM`,e,t)}else if(e instanceof Node)return e;throw new I(`Destination (${e}) must be either a Node or a CSS selector`,e)}static createContextualApiObject(e){const t={getId:()=>e.getId(),remove:()=>e.delete(),moveTo:i=>e.moveTo(i),getText:()=>e.getText(),setText:i=>e.setText(i),getImgSrc:()=>e.getImgSrc(),setImgSrc:i=>e.setImgSrc(i)};return{...t,inside:i=>(e.moveTo(i),t)}}static createNanosplashSpinnerElement(){const e=a("div");return o(e,"ns-spinner"),e.innerHTML=`
3
3
  <svg viewBox="0 0 50 50">
4
4
  <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
5
5
  </svg>
6
- `,e}}class g{constructor(e,t,i){var s;this.nsRootElement=m("div"),this.nsTextElement=m("div"),this.nsTextContainerElement=m("div"),this.nsSpinnerElement=d.createNanosplashSpinnerElement(),this.nsWindowElement=m("div"),this.nsWrapperElement=m("div"),this.nsContentElement=m("div"),this.nsImageElement=m("img"),this.id=Math.random().toString(36).substring(2),this.nsInstance=e,this.nsTextElement.innerText=t,this.imgSrc=i,this.nsImageElement.src=(s=this.imgSrc)!=null?s:"",this.nsImageElement.alt=u.APP_NAME,this.nsRootElement.style.fontSize=e.getFontSize(),this.nsSpinnerElement.style.display=e.spinnerIsVisible()?"flex":"none",this.assembleNSComponent(),this.setImgSrc(i)}assignCSSClasses(){c(this.nsContentElement,"ns-container"),c(this.nsWrapperElement,"ns-blur"),c(this.nsImageElement,"ns-img"),c(this.nsTextElement,"ns-text"),c(this.nsTextContainerElement,"ns-text-container"),c(this.nsSpinnerElement,"ns-spinner"),c(this.nsWindowElement,"ns","ns-window"),c(this.nsRootElement,"ns-wrapper")}assembleElementStructure(){this.nsTextContainerElement.append(this.nsTextElement,this.nsSpinnerElement),this.nsContentElement.append(this.nsImageElement,this.nsTextContainerElement),this.nsWindowElement.append(this.nsContentElement),this.nsRootElement.append(this.nsWrapperElement,this.nsWindowElement)}assembleNSComponent(){this.nsRootElement.id=this.getId(),E(this.nsRootElement,"data-ctx","nanosplash"),this.assembleElementStructure(),this.assignCSSClasses()}getId(){return this.id}getText(){return this.nsTextElement.innerText}setText(e){return this.nsTextElement.innerText=e,this}getImgSrc(){return this.imgSrc}setImgSrc(e){return this.nsImageElement.src=e!=null?e:"",this.nsImageElement.style.display=e?"block":"none",this.assembleElementStructure(),this}getDestination(){return this.destinationNode}cleanAndRestore(){const e=this.nsRootElement.parentElement;e&&this.restoreDOMStructure(e)}resetFullscreenAttributes(){E(this.nsRootElement,"style",""),this.nsRootElement.classList.remove("ns-fs")}moveWithRegularStrategy(e){const t=e.parentNode;t&&(this.restoreDOMStructure(t),t.replaceChild(this.nsRootElement,e),this.nsWrapperElement.appendChild(e))}moveWithFullscreenStrategy(){this.nsRootElement.classList.add("ns-fs"),x(this.nsRootElement,document.body,!0)}replaceSplashInstancesHavingSameDestination(e){const t=s=>s.getId()!==this.getId(),i=s=>s.delete();this.nsInstance.getFromDestinationNode(e).filter(t).forEach(i)}moveTo(e){this.cleanAndRestore(),this.destinationNode=d.destinationToNode(e),this.replaceSplashInstancesHavingSameDestination(this.destinationNode),this.destinationNode===document.body?this.moveWithFullscreenStrategy():(this.resetFullscreenAttributes(),this.moveWithRegularStrategy(this.destinationNode)),this.assembleNSComponent()}forEachWrappedNode(e){Array.from(this.nsWrapperElement.childNodes).forEach(e)}restoreDOMStructure(e){this.forEachWrappedNode(t=>e.insertBefore(t,this.nsRootElement))}removeElementsFromDOM(){[this.nsTextElement,this.nsSpinnerElement,this.nsTextContainerElement,this.nsImageElement,this.nsContentElement,this.nsWrapperElement,this.nsWindowElement,this.nsRootElement].forEach(e=>e.remove())}delete(){this.cleanAndRestore(),this.removeElementsFromDOM(),this.nsInstance.delete(this)}}class h{static ensureInstance(e,t,i,s){var r;return e||(e=new g(t,i,s)),e.setText(i).setImgSrc((r=e.getImgSrc())!=null?r:s)}static createShowFunction(e,t){return i=>(t=h.ensureInstance(t,e,i),e.instances.set(t.getId(),t),t.moveTo(document.body),d.createContextualApiObject(t))}static createProgressFunction(e,t){return(...i)=>(t=h.ensureInstance(t,e,""),t.moveTo(document.body),(async()=>{for(const[s,[r,f]]of i.entries())t.setText(f),await r;t.delete()})(),d.createContextualApiObject(t))}static createWhileFunction(e,t){return i=>(t=h.ensureInstance(t,e,""),{show(s){return e.instances.set(t.getId(),t),t.moveTo(document.body),t.setText(s),i.finally(()=>t.delete()),d.createContextualApiObject(t)}})}}const p=class{constructor(n){var e;this.imgSrc=n==null?void 0:n.imgSrc,this.spinner=(n==null?void 0:n.spinner)===void 0?p.SPINNER_DEFAULT_VISIBILITY:n.spinner,this.fontSize=(e=n==null?void 0:n.fontSize)!=null?e:"18px",this.instances=new Map}setImgSrc(n){return this.imgSrc=n,this}showSpinner(n){return this.spinner=n,this}setFontSize(n){return this.fontSize=n,this}getImgSrc(){return this.imgSrc}spinnerIsVisible(){return this.spinner}getFontSize(){return this.fontSize}show(n){return h.createShowFunction(this,new g(this,n,this.imgSrc))(n)}progress(...n){return h.createProgressFunction(this,new g(this,"",this.imgSrc))(...n)}while(n){return h.createWhileFunction(this,new g(this,"",this.imgSrc))(n)}lifoIterate(n){const e=this.instances.size,t=Array.from(this.instances.values());for(let i=e-1;i>=0;i--){const s=t[i],r=s.getId();if(!n(r,s,i))break}}delete(n){this.instances.delete(n.getId())}hideAll(){this.instances.forEach(n=>n.delete())}hide(n){if(n){const e=this.instances.get(n);e?e.delete():Array.from(this.instances.values()).filter(t=>t.getDestination()===a(n)).forEach(t=>t.delete())}else{const e=this.instances.size;this.lifoIterate((t,i,s)=>{const r=s===e-1;return r&&i.delete(),r})}}getFromDestinationNode(n){const e=t=>t.getDestination()===n;return Array.from(this.instances.values()).filter(e)}};let u=p;u.APP_NAME="Nanosplash",u.SPINNER_DEFAULT_VISIBILITY=!0,window.addEventListener("load",()=>{window.Nanosplash=u,window.ns=new u})})();
6
+ `,e}}class d{constructor(e,t,i){var s;this.nsRootElement=a("div"),this.nsTextElement=a("div"),this.nsTextContainerElement=a("div"),this.nsSpinnerElement=l.createNanosplashSpinnerElement(),this.nsWindowElement=a("div"),this.nsWrapperElement=a("div"),this.nsContentElement=a("div"),this.nsImageElement=a("img"),this.id=Math.random().toString(36).substring(2),this.nsInstance=e,this.nsTextElement.innerText=t,this.imgSrc=i,this.nsImageElement.src=(s=this.imgSrc)!=null?s:"",this.nsImageElement.alt=h.APP_NAME,this.nsRootElement.style.fontSize=e.getFontSize(),this.nsSpinnerElement.style.display=e.spinnerIsVisible()?"flex":"none",this.assembleNSComponent(),this.setImgSrc(i)}assignCSSClasses(){o(this.nsContentElement,"ns-container"),o(this.nsWrapperElement,"ns-blur"),o(this.nsImageElement,"ns-img"),o(this.nsTextElement,"ns-text"),o(this.nsTextContainerElement,"ns-text-container"),o(this.nsSpinnerElement,"ns-spinner"),o(this.nsWindowElement,"ns","ns-window"),o(this.nsRootElement,"ns-wrapper")}assembleElementStructure(){this.nsTextContainerElement.append(this.nsTextElement,this.nsSpinnerElement),this.nsContentElement.append(this.nsImageElement,this.nsTextContainerElement),this.nsWindowElement.append(this.nsContentElement),this.nsRootElement.append(this.nsWrapperElement,this.nsWindowElement)}assembleNSComponent(){this.nsRootElement.id=this.getId(),g(this.nsRootElement,"data-ctx","nanosplash"),this.assembleElementStructure(),this.assignCSSClasses()}getId(){return this.id}getText(){return this.nsTextElement.innerText}setText(e){return this.nsTextElement.innerText=e,this}getImgSrc(){return this.imgSrc}setImgSrc(e){return this.nsImageElement.src=e!=null?e:"",this.nsImageElement.style.display=e?"block":"none",this.assembleElementStructure(),this}getDestination(){return this.destinationNode}cleanAndRestore(){const e=this.nsRootElement.parentElement;e&&this.restoreDOMStructure(e)}resetFullscreenAttributes(){g(this.nsRootElement,"style",""),this.nsRootElement.classList.remove("ns-fs")}moveWithRegularStrategy(e){const t=e.parentNode;t&&(this.restoreDOMStructure(t),t.replaceChild(this.nsRootElement,e),this.nsWrapperElement.appendChild(e))}moveWithFullscreenStrategy(){this.nsRootElement.classList.add("ns-fs"),p(this.nsRootElement,document.body,!0)}replaceSplashInstancesHavingSameDestination(e){const t=s=>s.getId()!==this.getId(),i=s=>s.delete();this.nsInstance.getFromDestinationNode(e).filter(t).forEach(i)}moveTo(e){try{this.cleanAndRestore(),this.destinationNode=l.destinationToNode(e),this.replaceSplashInstancesHavingSameDestination(this.destinationNode),this.destinationNode===document.body?this.moveWithFullscreenStrategy():(this.resetFullscreenAttributes(),this.moveWithRegularStrategy(this.destinationNode)),this.assembleNSComponent()}catch(t){console.warn(t)}}forEachWrappedNode(e){Array.from(this.nsWrapperElement.childNodes).forEach(e)}restoreDOMStructure(e){this.forEachWrappedNode(t=>e.insertBefore(t,this.nsRootElement))}removeElementsFromDOM(){[this.nsTextElement,this.nsSpinnerElement,this.nsTextContainerElement,this.nsImageElement,this.nsContentElement,this.nsWrapperElement,this.nsWindowElement,this.nsRootElement].forEach(e=>e.remove())}delete(){this.cleanAndRestore(),this.removeElementsFromDOM(),this.nsInstance.delete(this)}}class c{static ensureInstance(e,t,i,s){var r;return e||(e=new d(t,i,s)),e.setText(i).setImgSrc((r=e.getImgSrc())!=null?r:s)}static createShowFunction(e,t){return i=>(t=c.ensureInstance(t,e,i),e.instances.set(t.getId(),t),t.moveTo(document.body),l.createContextualApiObject(t))}static createProgressFunction(e,t){return(...i)=>(t=c.ensureInstance(t,e,""),t.moveTo(document.body),(async()=>{for(const[s,[r,m]]of i.entries())t.setText(m),await r;t.delete()})(),l.createContextualApiObject(t))}static createWhileFunction(e,t){return i=>(t=c.ensureInstance(t,e,""),{show(s){return e.instances.set(t.getId(),t),t.moveTo(document.body),t.setText(s),i.finally(()=>t.delete()),l.createContextualApiObject(t)}})}}const E=class{constructor(n){var e;this.imgSrc=n==null?void 0:n.imgSrc,this.spinner=(n==null?void 0:n.spinner)===void 0?E.SPINNER_DEFAULT_VISIBILITY:n.spinner,this.fontSize=(e=n==null?void 0:n.fontSize)!=null?e:"18px",this.instances=new Map}setImgSrc(n){return this.imgSrc=n,this}showSpinner(n){return this.spinner=n,this}setFontSize(n){return this.fontSize=n,this}getImgSrc(){return this.imgSrc}spinnerIsVisible(){return this.spinner}getFontSize(){return this.fontSize}show(n){return c.createShowFunction(this,new d(this,n,this.imgSrc))(n)}progress(...n){return c.createProgressFunction(this,new d(this,"",this.imgSrc))(...n)}while(n){return c.createWhileFunction(this,new d(this,"",this.imgSrc))(n)}lifoIterate(n){const e=this.instances.size,t=Array.from(this.instances.values());for(let i=e-1;i>=0;i--){const s=t[i],r=s.getId();if(!n(r,s,i))break}}delete(n){this.instances.delete(n.getId())}hideAll(){this.instances.forEach(n=>n.delete())}hide(n){if(n){const e=typeof n=="string",t=n instanceof Node,i=s=>{Array.from(this.instances.values()).filter(r=>r.getDestination()===s).forEach(r=>r.delete())};if(e){const s=this.instances.get(n);if(s)s.delete();else{const r=f(n);r&&i(r)}}else t&&i(n)}else{const e=this.instances.size;this.lifoIterate((t,i,s)=>{const r=s===e-1;return r&&i.delete(),r})}}getFromDestinationNode(n){const e=t=>t.getDestination()===n;return Array.from(this.instances.values()).filter(e)}};let h=E;h.APP_NAME="Nanosplash",h.SPINNER_DEFAULT_VISIBILITY=!0,window.addEventListener("load",()=>{window.Nanosplash=h,window.ns=new h})})();