nanosplash 2.3.1 → 2.4.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 +38 -42
- package/dist/iife/nanosplash.iife.js +1 -1
- package/dist/module/Nanosplash.css +1 -1
- package/dist/module/nanosplash.cjs.js +1 -1
- package/dist/module/nanosplash.es.js +66 -35
- package/docs/index.html +36 -14
- package/docs/nanosplash.iife.js +6 -1
- package/docs/style.css +1 -1
- package/docs/typedoc/assets/main.js +2 -2
- package/docs/typedoc/assets/search.js +1 -1
- package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +59 -0
- package/docs/typedoc/index.html +1 -1
- package/docs/typedoc/modules/Core_Nanosplash.html +1 -0
- package/docs/typedoc/modules/types.html +1 -0
- package/index.html +35 -17
- package/package.json +13 -13
- package/src/Core/Nanosplash.ts +80 -19
- package/src/Core/SplashInstance.ts +148 -10
- package/src/Factory/NanosplashFactory.ts +1 -13
- package/src/Interfaces/NanosplashInterface.ts +1 -2
- package/src/main.ts +7 -1
- package/src/repositories/NanosplashRepository.ts +15 -2
- package/src/style.sass +47 -17
- package/src/types.d.ts +9 -6
- package/src/utilities/dom.ts +2 -2
- package/src/Interfaces/ImageInterface.ts +0 -5
package/README.md
CHANGED
|
@@ -12,33 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
<strong>The simple, tiny loading screen</strong>
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# Installation
|
|
18
|
-
|
|
19
|
-
## Yarn
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn add nanosplash
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## NPM
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install nanosplash
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
# Import
|
|
15
|
+
# Getting started
|
|
32
16
|
|
|
33
17
|
## Import via CDN (recommended)
|
|
34
18
|
|
|
35
|
-
When you import the IIFE script there is no need to invoke the `install` function.
|
|
36
|
-
|
|
37
19
|
```html
|
|
38
20
|
<script src="https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js">
|
|
39
21
|
```
|
|
22
|
+
```js
|
|
23
|
+
// Install Nanosplash in the browser
|
|
24
|
+
window.installNanosplash()
|
|
25
|
+
// Display your first Nanosplash
|
|
26
|
+
window.ns.show('Hello world')
|
|
27
|
+
```
|
|
40
28
|
|
|
41
|
-
##
|
|
29
|
+
## Install (advanced)
|
|
30
|
+
```bash
|
|
31
|
+
yarn add nanosplash
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Modules
|
|
42
35
|
|
|
43
36
|
When including either ES or CJS modules, you need the CSS in the dist folder, whereas in the IIFE variant, everything is included. If you are using a modern bundler e.g Vite, NextJS, NuxtJS, you can import the CSS directly into your code.
|
|
44
37
|
|
|
@@ -51,29 +44,34 @@ import 'nanosplash/dist/module/style.css'
|
|
|
51
44
|
> Full: `node_modules/nanosplash/dist/module/style.css`<br>
|
|
52
45
|
> Relative: `nanosplash/dist/module/style.css`
|
|
53
46
|
|
|
54
|
-
|
|
47
|
+
#### ESM (ES modules)
|
|
55
48
|
|
|
56
49
|
```js
|
|
57
50
|
import { Nanosplash } from 'nanosplash'
|
|
58
51
|
```
|
|
59
52
|
|
|
60
|
-
|
|
53
|
+
#### CJS (CommonJS)
|
|
61
54
|
|
|
62
55
|
```js
|
|
63
56
|
const Nanosplash = require('nanosplash')
|
|
64
57
|
```
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
### Inject Nanosplash into global scope
|
|
60
|
+
#### Using CDN
|
|
61
|
+
```js
|
|
62
|
+
const nsOptions = {
|
|
63
|
+
spinner: true,
|
|
64
|
+
fontSize: '18px',
|
|
65
|
+
}
|
|
66
|
+
window.installNanosplash(nsOptions)
|
|
67
|
+
```
|
|
68
|
+
#### Using modules
|
|
74
69
|
```js
|
|
75
|
-
const
|
|
76
|
-
|
|
70
|
+
const nsOptions = {
|
|
71
|
+
spinner: true,
|
|
72
|
+
fontSize: '18px',
|
|
73
|
+
}
|
|
74
|
+
window.ns = new Nanosplash(nsOptions)
|
|
77
75
|
```
|
|
78
76
|
|
|
79
77
|
## Basic usage
|
|
@@ -81,7 +79,7 @@ window.ns = ns
|
|
|
81
79
|
### Display the loading screen
|
|
82
80
|
|
|
83
81
|
```js
|
|
84
|
-
ns.show('Loading the good stuff
|
|
82
|
+
ns.show('Loading the good stuff')
|
|
85
83
|
```
|
|
86
84
|
|
|
87
85
|
### Hide the loading screen
|
|
@@ -100,26 +98,24 @@ ns.hideAll()
|
|
|
100
98
|
|
|
101
99
|
```js
|
|
102
100
|
// Use CSS selector string
|
|
103
|
-
ns.show('Loading component
|
|
101
|
+
ns.show('Loading component').inside('#my-element')
|
|
104
102
|
|
|
105
103
|
// Use HTMLElement objects directly
|
|
106
|
-
ns
|
|
107
|
-
.show('Loading component ...')
|
|
108
|
-
.inside(document.getElementById('my-element'))
|
|
104
|
+
ns.show('Loading component').inside(document.getElementById('my-element'))
|
|
109
105
|
```
|
|
110
106
|
|
|
111
107
|
### Combine Nanosplash with async tasks
|
|
112
108
|
|
|
113
109
|
```js
|
|
114
|
-
const task1 = new Promise(r => setTimeout(
|
|
110
|
+
const task1 = new Promise(r => setTimeout(r, 3000))
|
|
115
111
|
const task2 = async () => await getDataFromApi()
|
|
116
112
|
|
|
117
|
-
ns.while(task1).show('Loading resources
|
|
118
|
-
ns.while(task2).show('Fetching table data
|
|
113
|
+
ns.while(task1).show('Loading resources')
|
|
114
|
+
ns.while(task2).show('Fetching table data').inside('#my-table')
|
|
119
115
|
|
|
120
116
|
ns.progress(
|
|
121
|
-
[task1, 'Loading data from API
|
|
122
|
-
[task2, 'Processing data
|
|
117
|
+
[task1, 'Loading data from API'],
|
|
118
|
+
[task2, 'Processing data']
|
|
123
119
|
).inside('#my-table')
|
|
124
120
|
```
|
|
125
121
|
|
|
@@ -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:
|
|
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(){const t=t=>document.createElement(t);function o(t,...s){t.classList.add(...s)}function a(t,s,e){t.setAttribute(s,e)}class c{static h(t){if("string"==typeof t){const e=(s=t,document.querySelector(s));if(!e)throw new Error(`No match with ${t}`);return e}if(t instanceof Node)return t;var 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 s=t("div");return o(s,"ns-spinner"),s.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',s}}class l{constructor(s,e,i){var n;this.u=t("div"),this.m=t("div"),this.g=t("div"),this.p=c.l(),this.v=t("div"),this.k=t("div"),this.S=t("div"),this.I=t("img"),this.id=Math.random().toString(36).substring(2),this.D=s,this.m.innerText=e,this.j=i,this.I.src=null!=(n=this.j)?n:"",this.I.alt=u.N,this.u.style.fontSize=s.fontSize,this.p.style.display=s.O?"flex":"none",this.A(),this.setImgSrc(i)}T(){o(this.S,"ns-container"),o(this.k,"ns-blur"),o(this.I,"ns-img"),o(this.m,"ns-text"),o(this.g,"ns-text-container"),o(this.p,"ns-spinner"),o(this.v,"ns","ns-window"),o(this.u,"ns-wrapper")}F(){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(),a(this.u,"data-ctx","nanosplash"),this.F(),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.F(),this}R(){return this.C}W(){const t=this.u.parentElement;t&&this.M(t)}$(){a(this.u,"style",""),this.u.classList.remove("ns-fs")}B(t){const s=t.parentNode;s&&(this.M(s),s.replaceChild(this.u,t),this.k.appendChild(t))}H(){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)}P(t){this.D.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){this.W(),this.C=c.h(t),this.P(this.C),this.C===document.body?this.H():(this.$(),this.B(this.C)),this.A()}G(t){Array.from(this.k.childNodes).forEach(t)}M(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 l(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),c.o(s))}static V(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()})(),c.o(s))}static X(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())),c.o(s))})}}class u{constructor(t){var s,e,i;this.j=null!=(s=null==t?void 0:t.j)?s:void 0,this.O=null!=(e=null==t?void 0:t.Y)&&e,this.fontSize=null!=(i=null==t?void 0:t.fontSize)?i:"18px",this.U=new Map}show(t){return d.L(this,new l(this,t,this.j))(t)}progress(...t){return d.V(this,new l(this,"",this.j))(...t)}while(t){return d.X(this,new l(this,"",this.j))(t)}Z(t){const s=this.U.size,e=Array.from(this.U.values());for(let i=s-1;i>=0;i--){console.log({size:s,_:s-1,tt:i});const n=e[i];if(!t(n.getId(),n,i))break}}delete(t){this.U.delete(t.getId())}hideAll(){this.U.forEach((t=>t.delete()))}hide(t){if(t){const s=this.U.get(t);if(!s)throw new Error(`Could not find element with id: ${t}`);s.delete()}else{const t=this.U.size;this.Z(((s,e,i)=>{const n=i===t-1;return n&&e.delete(),n}))}}q(t){return Array.from(this.U.values()).filter((s=>s.R()===t))}}u.N="Nanosplash",window.addEventListener("load",(()=>{window.Nanosplash=u,window.installNanosplash=t=>{window.ns=new u(t)}}))}();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.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:
|
|
1
|
+
.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}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty,s=Object.defineProperties,
|
|
1
|
+
var t=Object.defineProperty,s=Object.defineProperties,i=Object.getOwnPropertyDescriptors,e=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,r=(s,i,e)=>i in s?t(s,i,{t:!0,i:!0,writable:!0,value:e}):s[i]=e;Object.defineProperties(exports,{h:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=t=>document.createElement(t);function c(t,...s){t.classList.add(...s)}function a(t,s,i){t.setAttribute(s,i)}class l{static o(t){if("string"==typeof t){const i=(s=t,document.querySelector(s));if(!i)throw new Error(`No match with ${t}`);return i}if(t instanceof Node)return t;var s;throw new Error("Destination argument must string or Node")}static l(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)&&r(t,i,s[i]);if(e)for(var i of e(s))h.call(s,i)&&r(t,i,s[i]);return t})({},o),s(c,i({inside:s=>(t.moveTo(s),o)}));var c}static u(){const t=o("div");return c(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,i){var e;this.m=o("div"),this.v=o("div"),this.g=o("div"),this.p=l.u(),this.S=o("div"),this.I=o("div"),this.O=o("div"),this.N=o("img"),this.id=Math.random().toString(36).substring(2),this.j=t,this.v.innerText=s,this.A=i,this.N.src=null!=(e=this.A)?e:"",this.N.alt=m.T,this.m.style.fontSize=t.fontSize,this.p.style.display=t.D?"flex":"none",this.F(),this.setImgSrc(i)}M(){c(this.O,"ns-container"),c(this.I,"ns-blur"),c(this.N,"ns-img"),c(this.v,"ns-text"),c(this.g,"ns-text-container"),c(this.p,"ns-spinner"),c(this.S,"ns","ns-window"),c(this.m,"ns-wrapper")}C(){this.g.append(this.v,this.p),this.O.append(this.N,this.g),this.S.append(this.O),this.m.append(this.I,this.S)}F(){this.m.id=this.getId(),a(this.m,"data-ctx","nanosplash"),this.C(),this.M()}getId(){return this.id}getText(){return this.v.innerText}setText(t){return this.v.innerText=t,this}getImgSrc(){return this.A}setImgSrc(t){return this.N.src=null!=t?t:"",this.N.style.display=t?"block":"none",this.C(),this}W(){return this.k}R(){const t=this.m.parentElement;t&&this.$(t)}_(){a(this.m,"style",""),this.m.classList.remove("ns-fs")}B(t){const s=t.parentNode;s&&(this.$(s),s.replaceChild(this.m,t),this.I.appendChild(t))}H(){this.m.classList.add("ns-fs"),((t,s,i=!1)=>{t&&s&&(s.hasChildNodes()&&i?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.m,document.body,!0)}P(t){this.j.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){this.R(),this.k=l.o(t),this.P(this.k),this.k===document.body?this.H():(this._(),this.B(this.k)),this.F()}G(t){Array.from(this.I.childNodes).forEach(t)}$(t){this.G((s=>t.insertBefore(s,this.m)))}J(){[this.v,this.p,this.g,this.N,this.O,this.I,this.S,this.m].forEach((t=>t.remove()))}delete(){this.R(),this.J(),this.j.delete(this)}}class d{static K(t,s,i,e){var n;return t||(t=new u(s,i,e)),t.setText(i).setImgSrc(null!=(n=t.getImgSrc())?n:e)}static L(t,s){return i=>(s=d.K(s,t,i),t.U.set(s.getId(),s),s.moveTo(document.body),l.l(s))}static V(t,s){return(...i)=>((s=d.K(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[e,n]]of i.entries())s.setText(n),await e;s.delete()})(),l.l(s))}static X(t,s){return i=>(s=d.K(s,t,""),{show:e=>(t.U.set(s.getId(),s),s.moveTo(document.body),s.setText(e),i.finally((()=>s.delete())),l.l(s))})}}class m{constructor(t){var s,i,e;this.A=null!=(s=null==t?void 0:t.A)?s:void 0,this.D=null!=(i=null==t?void 0:t.Y)&&i,this.fontSize=null!=(e=null==t?void 0:t.fontSize)?e:"18px",this.U=new Map}show(t){return d.L(this,new u(this,t,this.A))(t)}progress(...t){return d.V(this,new u(this,"",this.A))(...t)}while(t){return d.X(this,new u(this,"",this.A))(t)}Z(t){const s=this.U.size,i=Array.from(this.U.values());for(let e=s-1;e>=0;e--){console.log({size:s,tt:s-1,st:e});const n=i[e];if(!t(n.getId(),n,e))break}}delete(t){this.U.delete(t.getId())}hideAll(){this.U.forEach((t=>t.delete()))}hide(t){if(t){const s=this.U.get(t);if(!s)throw new Error(`Could not find element with id: ${t}`);s.delete()}else{const t=this.U.size;this.Z(((s,i,e)=>{const n=e===t-1;return n&&i.delete(),n}))}}q(t){return Array.from(this.U.values()).filter((s=>s.W()===t))}}m.T="Nanosplash",exports.Nanosplash=m;
|
|
@@ -17,7 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var style = "";
|
|
20
|
+
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
21
|
function get(selector) {
|
|
22
22
|
return document.querySelector(selector);
|
|
23
23
|
}
|
|
@@ -63,22 +63,36 @@ class NanosplashRepository {
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
+
static createNanosplashSpinnerElement() {
|
|
67
|
+
const div = mk("div");
|
|
68
|
+
addClass(div, "ns-spinner");
|
|
69
|
+
div.innerHTML = `
|
|
70
|
+
<svg viewBox="0 0 50 50">
|
|
71
|
+
<circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
|
|
72
|
+
</svg>
|
|
73
|
+
`;
|
|
74
|
+
return div;
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
class SplashInstance {
|
|
68
78
|
constructor(ns, text, imgSrc) {
|
|
69
79
|
var _a;
|
|
70
80
|
this.nsRootElement = mk("div");
|
|
71
|
-
this.
|
|
81
|
+
this.nsTextElement = mk("div");
|
|
82
|
+
this.nsTextContainerElement = mk("div");
|
|
83
|
+
this.nsSpinnerElement = NanosplashRepository.createNanosplashSpinnerElement();
|
|
72
84
|
this.nsWindowElement = mk("div");
|
|
85
|
+
this.nsWrapperElement = mk("div");
|
|
73
86
|
this.nsContentElement = mk("div");
|
|
74
87
|
this.nsImageElement = mk("img");
|
|
75
|
-
this.nsTextElement = mk("div");
|
|
76
88
|
this.id = Math.random().toString(36).substring(2);
|
|
77
89
|
this.nsInstance = ns;
|
|
78
90
|
this.nsTextElement.innerText = text;
|
|
79
91
|
this.imgSrc = imgSrc;
|
|
80
92
|
this.nsImageElement.src = (_a = this.imgSrc) != null ? _a : "";
|
|
81
93
|
this.nsImageElement.alt = Nanosplash.APP_NAME;
|
|
94
|
+
this.nsRootElement.style.fontSize = ns.fontSize;
|
|
95
|
+
this.nsSpinnerElement.style.display = ns.showSpinner ? "flex" : "none";
|
|
82
96
|
this.assembleNSComponent();
|
|
83
97
|
this.setImgSrc(imgSrc);
|
|
84
98
|
}
|
|
@@ -87,11 +101,14 @@ class SplashInstance {
|
|
|
87
101
|
addClass(this.nsWrapperElement, "ns-blur");
|
|
88
102
|
addClass(this.nsImageElement, "ns-img");
|
|
89
103
|
addClass(this.nsTextElement, "ns-text");
|
|
104
|
+
addClass(this.nsTextContainerElement, "ns-text-container");
|
|
105
|
+
addClass(this.nsSpinnerElement, "ns-spinner");
|
|
90
106
|
addClass(this.nsWindowElement, "ns", "ns-window");
|
|
91
107
|
addClass(this.nsRootElement, "ns-wrapper");
|
|
92
108
|
}
|
|
93
109
|
assembleElementStructure() {
|
|
94
|
-
this.
|
|
110
|
+
this.nsTextContainerElement.append(this.nsTextElement, this.nsSpinnerElement);
|
|
111
|
+
this.nsContentElement.append(this.nsImageElement, this.nsTextContainerElement);
|
|
95
112
|
this.nsWindowElement.append(this.nsContentElement);
|
|
96
113
|
this.nsRootElement.append(this.nsWrapperElement, this.nsWindowElement);
|
|
97
114
|
}
|
|
@@ -120,7 +137,10 @@ class SplashInstance {
|
|
|
120
137
|
this.assembleElementStructure();
|
|
121
138
|
return this;
|
|
122
139
|
}
|
|
123
|
-
|
|
140
|
+
getDestination() {
|
|
141
|
+
return this.destinationNode;
|
|
142
|
+
}
|
|
143
|
+
cleanAndRestore() {
|
|
124
144
|
const currentParent = this.nsRootElement.parentElement;
|
|
125
145
|
if (currentParent) {
|
|
126
146
|
this.restoreDOMStructure(currentParent);
|
|
@@ -142,15 +162,21 @@ class SplashInstance {
|
|
|
142
162
|
this.nsRootElement.classList.add("ns-fs");
|
|
143
163
|
move(this.nsRootElement, document.body, true);
|
|
144
164
|
}
|
|
165
|
+
replaceSplashInstancesHavingSameDestination(destinationNode) {
|
|
166
|
+
const fnNotSameInstance = (v) => v.getId() !== this.getId();
|
|
167
|
+
const fnDelete = (v) => v.delete();
|
|
168
|
+
this.nsInstance.getSplashesWithDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete);
|
|
169
|
+
}
|
|
145
170
|
moveTo(destination) {
|
|
146
|
-
this.
|
|
147
|
-
|
|
148
|
-
|
|
171
|
+
this.cleanAndRestore();
|
|
172
|
+
this.destinationNode = NanosplashRepository.destinationToNode(destination);
|
|
173
|
+
this.replaceSplashInstancesHavingSameDestination(this.destinationNode);
|
|
174
|
+
const targetIsBody = this.destinationNode === document.body;
|
|
149
175
|
if (targetIsBody) {
|
|
150
176
|
this.moveWithFullscreenStrategy();
|
|
151
177
|
} else {
|
|
152
178
|
this.resetFullscreenAttributes();
|
|
153
|
-
this.moveWithRegularStrategy(
|
|
179
|
+
this.moveWithRegularStrategy(this.destinationNode);
|
|
154
180
|
}
|
|
155
181
|
this.assembleNSComponent();
|
|
156
182
|
}
|
|
@@ -163,6 +189,8 @@ class SplashInstance {
|
|
|
163
189
|
removeElementsFromDOM() {
|
|
164
190
|
[
|
|
165
191
|
this.nsTextElement,
|
|
192
|
+
this.nsSpinnerElement,
|
|
193
|
+
this.nsTextContainerElement,
|
|
166
194
|
this.nsImageElement,
|
|
167
195
|
this.nsContentElement,
|
|
168
196
|
this.nsWrapperElement,
|
|
@@ -171,7 +199,7 @@ class SplashInstance {
|
|
|
171
199
|
].forEach((v) => v.remove());
|
|
172
200
|
}
|
|
173
201
|
delete() {
|
|
174
|
-
this.
|
|
202
|
+
this.cleanAndRestore();
|
|
175
203
|
this.removeElementsFromDOM();
|
|
176
204
|
this.nsInstance.delete(this);
|
|
177
205
|
}
|
|
@@ -184,16 +212,6 @@ class NanosplashFactory {
|
|
|
184
212
|
}
|
|
185
213
|
return splash.setText(text).setImgSrc((_a = splash.getImgSrc()) != null ? _a : imgSrc);
|
|
186
214
|
}
|
|
187
|
-
static createImgFunction(ns, splash) {
|
|
188
|
-
return (src) => {
|
|
189
|
-
splash = NanosplashFactory.ensureInstance(splash, ns, "", src);
|
|
190
|
-
return {
|
|
191
|
-
show: NanosplashFactory.createShowFunction(ns, splash),
|
|
192
|
-
progress: NanosplashFactory.createProgressFunction(ns, splash),
|
|
193
|
-
while: NanosplashFactory.createWhileFunction(ns, splash)
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
215
|
static createShowFunction(ns, splash) {
|
|
198
216
|
return (text) => {
|
|
199
217
|
splash = NanosplashFactory.ensureInstance(splash, ns, text);
|
|
@@ -232,26 +250,34 @@ class NanosplashFactory {
|
|
|
232
250
|
}
|
|
233
251
|
}
|
|
234
252
|
class Nanosplash {
|
|
235
|
-
constructor() {
|
|
253
|
+
constructor(options) {
|
|
254
|
+
var _a, _b, _c;
|
|
255
|
+
this.imgSrc = (_a = options == null ? void 0 : options.imgSrc) != null ? _a : void 0;
|
|
256
|
+
this.showSpinner = (_b = options == null ? void 0 : options.spinner) != null ? _b : false;
|
|
257
|
+
this.fontSize = (_c = options == null ? void 0 : options.fontSize) != null ? _c : "18px";
|
|
236
258
|
this.instances = /* @__PURE__ */ new Map();
|
|
237
259
|
}
|
|
238
|
-
img(src) {
|
|
239
|
-
return NanosplashFactory.createImgFunction(this, new SplashInstance(this, "", src))(src);
|
|
240
|
-
}
|
|
241
260
|
show(text) {
|
|
242
|
-
return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text);
|
|
261
|
+
return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text, this.imgSrc))(text);
|
|
243
262
|
}
|
|
244
263
|
progress(...jobs) {
|
|
245
|
-
return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ""))(...jobs);
|
|
264
|
+
return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, "", this.imgSrc))(...jobs);
|
|
246
265
|
}
|
|
247
266
|
while(asyncTask) {
|
|
248
|
-
return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ""))(asyncTask);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
for (
|
|
254
|
-
|
|
267
|
+
return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, "", this.imgSrc))(asyncTask);
|
|
268
|
+
}
|
|
269
|
+
lifoIterate(callback) {
|
|
270
|
+
const n = this.instances.size;
|
|
271
|
+
const instances = Array.from(this.instances.values());
|
|
272
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
273
|
+
console.log({
|
|
274
|
+
size: n,
|
|
275
|
+
lastIdx: n - 1,
|
|
276
|
+
currentIdx: i
|
|
277
|
+
});
|
|
278
|
+
const instance = instances[i];
|
|
279
|
+
const id = instance.getId();
|
|
280
|
+
if (!callback(id, instance, i)) {
|
|
255
281
|
break;
|
|
256
282
|
}
|
|
257
283
|
}
|
|
@@ -271,8 +297,9 @@ class Nanosplash {
|
|
|
271
297
|
throw new Error(`Could not find element with id: ${id}`);
|
|
272
298
|
}
|
|
273
299
|
} else {
|
|
274
|
-
|
|
275
|
-
|
|
300
|
+
const n = this.instances.size;
|
|
301
|
+
this.lifoIterate((_, splashInstance, i) => {
|
|
302
|
+
const remove = i === n - 1;
|
|
276
303
|
if (remove) {
|
|
277
304
|
splashInstance.delete();
|
|
278
305
|
}
|
|
@@ -280,6 +307,10 @@ class Nanosplash {
|
|
|
280
307
|
});
|
|
281
308
|
}
|
|
282
309
|
}
|
|
310
|
+
getSplashesWithDestinationNode(node) {
|
|
311
|
+
const fnSameDestinationNode = (v) => v.getDestination() === node;
|
|
312
|
+
return Array.from(this.instances.values()).filter(fnSameDestinationNode);
|
|
313
|
+
}
|
|
283
314
|
}
|
|
284
315
|
Nanosplash.APP_NAME = "Nanosplash";
|
|
285
316
|
export { Nanosplash };
|
package/docs/index.html
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
</head>
|
|
16
16
|
<body class="flex flex-col justify-between">
|
|
17
17
|
<div class="w-100 min-h-screen flex flex-col justify-center items-center">
|
|
18
|
-
<div class="text-
|
|
19
|
-
<div class="mt-3">
|
|
18
|
+
<div class="text-4xl text-slate-900 drop-shadow-lg">Nanosplash</div>
|
|
19
|
+
<div class="text-pink-500 mt-3 font-mono text-sm">ns.show('text').inside('#id')</div>
|
|
20
20
|
<div class="flex flex-col space-y-2 my-10">
|
|
21
21
|
<div class="flex space-x-2 justify-center">
|
|
22
22
|
<img src="https://badgen.net/npm/v/nanosplash" />
|
|
@@ -30,13 +30,23 @@
|
|
|
30
30
|
/>
|
|
31
31
|
</div>
|
|
32
32
|
</div>
|
|
33
|
-
<div class="
|
|
33
|
+
<div class="flex rounded-xl text-slate-400 shadow-xl overflow-hidden">
|
|
34
|
+
<div data-copy class="p-3 bg-slate-800 text-slate-400 font-mono">
|
|
35
|
+
<script src="https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js">
|
|
36
|
+
</div>
|
|
37
|
+
<div id="copy" class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white">Copy</div>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="mt-10 flex justify-content items-center divide-x-2 text-slate-400">
|
|
40
|
+
<a href="https://www.npmjs.com/package/nanosplash" target="_blank"><i class="lni lni-npm text-4xl hover:text-pink-500 px-5"></i></a>
|
|
41
|
+
<a href="https://github.com/isakhauge/nanosplash" target="_blank"><i class="lni lni-github-original text-2xl hover:text-pink-500 px-5"></i></a>
|
|
42
|
+
</div>
|
|
43
|
+
<a class="mt-10 text-pink-300 hover:text-pink-500" href="/typedoc">API Reference Documentation</a>
|
|
34
44
|
</div>
|
|
35
|
-
<div class="grid grid-cols-2 gap-1">
|
|
45
|
+
<div class="grid grid-cols-1 xl:grid-cols-2 gap-1">
|
|
36
46
|
<div id="a" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
37
47
|
<div class="text-xl mb-10">Give user progress feedback</div>
|
|
38
|
-
<div class="text-white bg-slate-800 p-5 rounded-
|
|
39
|
-
ns.
|
|
48
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
49
|
+
ns.progress(<br>
|
|
40
50
|
[promise1, 'Loading A'],<br>
|
|
41
51
|
[promise2, 'Loading B'],<br>
|
|
42
52
|
[promise3, 'Loading C'],<br>
|
|
@@ -45,13 +55,13 @@
|
|
|
45
55
|
</div>
|
|
46
56
|
<div id="b" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
47
57
|
<div class="text-xl mb-10">Handle async functions</div>
|
|
48
|
-
<div class="text-white bg-slate-800 p-5 rounded-
|
|
58
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
49
59
|
ns.while(promise).show('Loading ...').inside('#myDiv')
|
|
50
60
|
</div>
|
|
51
61
|
</div>
|
|
52
62
|
<div id="c" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
53
63
|
<div class="text-xl mb-10">Display fullscreen</div>
|
|
54
|
-
<div class="text-white bg-slate-800 p-5 rounded-
|
|
64
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
55
65
|
const splash = ns.show('Fullscreen text')<br>
|
|
56
66
|
splash.moveTo('#myDiv')<br>
|
|
57
67
|
splash.remove()
|
|
@@ -59,19 +69,31 @@
|
|
|
59
69
|
</div>
|
|
60
70
|
<div id="d" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
61
71
|
<div class="text-xl mb-10">Display multiple, independent instances</div>
|
|
62
|
-
<div class="text-white bg-slate-800 p-5 rounded-
|
|
63
|
-
ns.
|
|
64
|
-
ns.show('Loading component
|
|
65
|
-
ns.show('Loading component
|
|
72
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
73
|
+
ns.show('Loading component A').inside('#a')<br>
|
|
74
|
+
ns.show('Loading component B').inside('#b')<br>
|
|
75
|
+
ns.show('Loading component C').inside('#c')<br>
|
|
66
76
|
<br><br>
|
|
67
|
-
ns.hide() // Removes instances in a
|
|
77
|
+
ns.hide() // Removes instances in a LIFO manner.<br>
|
|
68
78
|
ns.hideAll() // Removes all instances.
|
|
69
79
|
</div>
|
|
70
80
|
</div>
|
|
71
81
|
</div>
|
|
72
82
|
<footer>
|
|
73
83
|
|
|
84
|
+
<script>
|
|
85
|
+
document.getElementById('copy').onclick = function () {
|
|
86
|
+
const text = document.querySelector('[data-copy]').innerText
|
|
87
|
+
navigator.clipboard.writeText(text)
|
|
88
|
+
alert('Copied to clipboard!')
|
|
89
|
+
}
|
|
90
|
+
window.onload = () => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
window.installNanosplash({spinner: true})
|
|
93
|
+
}, 100)
|
|
94
|
+
}
|
|
95
|
+
</script>
|
|
74
96
|
</footer>
|
|
75
|
-
<style>body{min-height:100vh}
|
|
97
|
+
<style>body{min-height:100vh}</style>
|
|
76
98
|
</body>
|
|
77
99
|
</html>
|
package/docs/nanosplash.iife.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I=Object.defineProperty,v=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var S=(l,o,a)=>o in l?I(l,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):l[o]=a,w=(l,o)=>{for(var a in o||(o={}))T.call(o,a)&&S(l,a,o[a]);if(p)for(var a of p(o))N.call(o,a)&&S(l,a,o[a]);return l},y=(l,o)=>v(l,b(o));(function(){"use strict";const l=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&s(c)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerpolicy&&(i.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?i.credentials="include":n.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}};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(r){return document.querySelector(r)}function x(r,e,t=!1){r&&e&&(e.hasChildNodes()&&t?e.insertBefore(r,e.firstChild):e.appendChild(r))}const m=r=>document.createElement(r);function h(r,...e){r.classList.add(...e)}function E(r,e,t){r.setAttribute(e,t)}class u{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:s=>e.moveTo(s),getText:()=>e.getText(),setText:s=>e.setText(s),getImgSrc:()=>e.getImgSrc(),setImgSrc:s=>e.setImgSrc(s)};return y(w({},t),{inside:s=>(e.moveTo(s),t)})}static createNanosplashSpinnerElement(){const e=m("div");return h(e,"ns-spinner"),e.innerHTML=`
|
|
3
|
+
<svg viewBox="0 0 50 50">
|
|
4
|
+
<circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
|
|
5
|
+
</svg>
|
|
6
|
+
`,e}}class f{constructor(e,t,s){var n;this.nsRootElement=m("div"),this.nsTextElement=m("div"),this.nsTextContainerElement=m("div"),this.nsSpinnerElement=u.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=s,this.nsImageElement.src=(n=this.imgSrc)!=null?n:"",this.nsImageElement.alt=g.APP_NAME,this.nsRootElement.style.fontSize=e.fontSize,this.nsSpinnerElement.style.display=e.showSpinner?"flex":"none",this.assembleNSComponent(),this.setImgSrc(s)}assignCSSClasses(){h(this.nsContentElement,"ns-container"),h(this.nsWrapperElement,"ns-blur"),h(this.nsImageElement,"ns-img"),h(this.nsTextElement,"ns-text"),h(this.nsTextContainerElement,"ns-text-container"),h(this.nsSpinnerElement,"ns-spinner"),h(this.nsWindowElement,"ns","ns-window"),h(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=n=>n.getId()!==this.getId(),s=n=>n.delete();this.nsInstance.getSplashesWithDestinationNode(e).filter(t).forEach(s)}moveTo(e){this.cleanAndRestore(),this.destinationNode=u.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 d{static ensureInstance(e,t,s,n){var i;return e||(e=new f(t,s,n)),e.setText(s).setImgSrc((i=e.getImgSrc())!=null?i:n)}static createShowFunction(e,t){return s=>(t=d.ensureInstance(t,e,s),e.instances.set(t.getId(),t),t.moveTo(document.body),u.createContextualApiObject(t))}static createProgressFunction(e,t){return(...s)=>(t=d.ensureInstance(t,e,""),t.moveTo(document.body),(async()=>{for(const[n,[i,c]]of s.entries())t.setText(c),await i;t.delete()})(),u.createContextualApiObject(t))}static createWhileFunction(e,t){return s=>(t=d.ensureInstance(t,e,""),{show(n){return e.instances.set(t.getId(),t),t.moveTo(document.body),t.setText(n),s.finally(()=>t.delete()),u.createContextualApiObject(t)}})}}class g{constructor(e){var t,s,n;this.imgSrc=(t=e==null?void 0:e.imgSrc)!=null?t:void 0,this.showSpinner=(s=e==null?void 0:e.spinner)!=null?s:!1,this.fontSize=(n=e==null?void 0:e.fontSize)!=null?n:"18px",this.instances=new Map}show(e){return d.createShowFunction(this,new f(this,e,this.imgSrc))(e)}progress(...e){return d.createProgressFunction(this,new f(this,"",this.imgSrc))(...e)}while(e){return d.createWhileFunction(this,new f(this,"",this.imgSrc))(e)}lifoIterate(e){const t=this.instances.size,s=Array.from(this.instances.values());for(let n=t-1;n>=0;n--){console.log({size:t,lastIdx:t-1,currentIdx:n});const i=s[n],c=i.getId();if(!e(c,i,n))break}}delete(e){this.instances.delete(e.getId())}hideAll(){this.instances.forEach(e=>e.delete())}hide(e){if(e){const t=this.instances.get(e);if(t)t.delete();else throw new Error(`Could not find element with id: ${e}`)}else{const t=this.instances.size;this.lifoIterate((s,n,i)=>{const c=i===t-1;return c&&n.delete(),c})}}getSplashesWithDestinationNode(e){const t=s=>s.getDestination()===e;return Array.from(this.instances.values()).filter(t)}}g.APP_NAME="Nanosplash",window.addEventListener("load",()=>{window.Nanosplash=g,window.installNanosplash=r=>{window.ns=new g(r)}})})();
|
package/docs/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.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:
|
|
1
|
+
.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}}
|