nanosplash 2.3.2 → 2.5.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.
@@ -24,10 +24,13 @@ jobs:
24
24
  - uses: actions/checkout@v2
25
25
  with:
26
26
  fetch-depth: 0
27
-
27
+
28
28
  # Checkout branch
29
29
  - name: Checkout
30
- run: git checkout production
30
+ run: |
31
+ git checkout production
32
+ git fetch
33
+ git pull origin
31
34
 
32
35
  - name: Install npm packages
33
36
  run: yarn install
package/README.md CHANGED
@@ -12,33 +12,26 @@
12
12
 
13
13
  <strong>The simple, tiny loading screen</strong>
14
14
 
15
- > <em>No dependencies, pure JS</em>
16
-
17
- # Installation
15
+ # Getting started
18
16
 
19
- ## Yarn
17
+ ## Import via CDN (recommended)
20
18
 
21
- ```bash
22
- yarn add nanosplash
19
+ ```html
20
+ <script src="https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js"></script>
23
21
  ```
24
-
25
- ## NPM
26
-
27
- ```bash
28
- npm install nanosplash
22
+ ```js
23
+ // Install Nanosplash in the browser
24
+ window.installNanosplash()
25
+ // Display your first Nanosplash
26
+ window.ns.show('Hello world')
29
27
  ```
30
28
 
31
- # Import
32
-
33
- ## Import via CDN (recommended)
34
-
35
- When you import the IIFE script there is no need to invoke the `install` function.
36
-
37
- ```html
38
- <script src="https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js">
29
+ ## Install (advanced)
30
+ ```bash
31
+ yarn add nanosplash
39
32
  ```
40
33
 
41
- ## Modules
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
- ### ESM (ES modules)
47
+ #### ESM (ES modules)
55
48
 
56
49
  ```js
57
50
  import { Nanosplash } from 'nanosplash'
58
51
  ```
59
52
 
60
- ### CJS (CommonJS)
53
+ #### CJS (CommonJS)
61
54
 
62
55
  ```js
63
56
  const Nanosplash = require('nanosplash')
64
57
  ```
65
58
 
66
- # Getting started
67
-
68
- ## Inject Nanosplash into global scope
69
-
70
- > When imported through the CDN, the instance is already injected into the `Window` object and accessible through the global variable `loading`.
71
-
72
- If you are importing Nanosplash through modules, invoking the `install` function is essential in order to make it react to changes in the browser.
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 ns = new Nanosplash()
76
- window.ns = ns
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 ...').inside('#my-element')
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(() => r(), 3000))
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 ...').inside('#my-table')
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,e=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(e,i,s)=>i in e?t(e,i,{t:!0,i:!0,writable:!0,value:s}):e[i]=s,h=document.createElement("style");h.innerHTML='@charset "UTF-8";.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:1rem;max-height:9rem;max-width:9rem}.ns-text{color:#333;display:flex;text-align:center}.ns-text:after{-webkit-animation:anim 1s infinite;animation:anim 1s infinite;content:"\\a0\\a0\\a0";margin-left:.25em}@-webkit-keyframes anim{0%{content:"\\a0\\a0\\a0"}30%{content:".\\a0\\a0"}60%{content:"..\\a0"}90%{content:"..."}}@keyframes anim{0%{content:"\\a0\\a0\\a0"}30%{content:".\\a0\\a0"}60%{content:"..\\a0"}90%{content:"..."}}\n',document.head.appendChild(h),function(){const t=t=>document.createElement(t);function h(t,...e){t.classList.add(...e)}function a(t,e,i){t.setAttribute(e,i)}class c{static o(t){if("string"==typeof t){const i=(e=t,document.querySelector(e));if(!i)throw new Error(`No match with ${t}`);return i}if(t instanceof Node)return t;var e;throw new Error("Destination argument must string or Node")}static h(t){const h={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:e=>t.moveTo(e),getText:()=>t.getText(),setText:e=>t.setText(e),getImgSrc:()=>t.getImgSrc(),setImgSrc:e=>t.setImgSrc(e)};return a=((t,e)=>{for(var i in e||(e={}))n.call(e,i)&&o(t,i,e[i]);if(s)for(var i of s(e))r.call(e,i)&&o(t,i,e[i]);return t})({},h),e(a,i({inside:e=>(t.moveTo(e),h)}));var a}}class u{constructor(e,i,s){var n;this.u=t("div"),this.l=t("div"),this.m=t("div"),this.g=t("div"),this.p=t("img"),this.v=t("div"),this.id=Math.random().toString(36).substring(2),this.S=e,this.v.innerText=i,this.I=s,this.p.src=null!=(n=this.I)?n:"",this.p.alt=m.O,this.j(),this.setImgSrc(s)}F(){h(this.g,"ns-container"),h(this.l,"ns-blur"),h(this.p,"ns-img"),h(this.v,"ns-text"),h(this.m,"ns","ns-window"),h(this.u,"ns-wrapper")}T(){this.g.append(this.p,this.v),this.m.append(this.g),this.u.append(this.l,this.m)}j(){this.u.id=this.getId(),a(this.u,"data-ctx","nanosplash"),this.T(),this.F()}getId(){return this.id}getText(){return this.v.innerText}setText(t){return this.v.innerText=t,this}getImgSrc(){return this.I}setImgSrc(t){return this.p.src=null!=t?t:"",this.p.style.display=t?"block":"none",this.T(),this}k(){const t=this.u.parentElement;t&&this.N(t)}C(){a(this.u,"style",""),this.u.classList.remove("ns-fs")}A(t){const e=t.parentNode;e&&(this.N(e),e.replaceChild(this.u,t),this.l.appendChild(t))}M(){this.u.classList.add("ns-fs"),((t,e,i=!1)=>{t&&e&&(e.hasChildNodes()&&i?e.insertBefore(t,e.firstChild):e.appendChild(t))})(this.u,document.body,!0)}moveTo(t){this.k();const e=c.o(t);e===document.body?this.M():(this.C(),this.A(e)),this.j()}W(t){Array.from(this.l.childNodes).forEach(t)}N(t){this.W((e=>t.insertBefore(e,this.u)))}D(){[this.v,this.p,this.g,this.l,this.m,this.u].forEach((t=>t.remove()))}delete(){this.k(),this.D(),this.S.delete(this)}}class l{static $(t,e,i,s){var n;return t||(t=new u(e,i,s)),t.setText(i).setImgSrc(null!=(n=t.getImgSrc())?n:s)}static P(t,e){return i=>(e=l.$(e,t,"",i),{show:l.R(t,e),progress:l.U(t,e),while:l.q(t,e)})}static R(t,e){return i=>(e=l.$(e,t,i),t.B.set(e.getId(),e),e.moveTo(document.body),c.h(e))}static U(t,e){return(...i)=>((e=l.$(e,t,"")).moveTo(document.body),(async()=>{for(const[t,[s,n]]of i.entries())e.setText(n),await s;e.delete()})(),c.h(e))}static q(t,e){return i=>(e=l.$(e,t,""),{show:s=>(t.B.set(e.getId(),e),e.moveTo(document.body),e.setText(s),i.finally((()=>e.delete())),c.h(e))})}}class m{constructor(){this.B=new Map}img(t){return l.P(this,new u(this,"",t))(t)}show(t){return l.R(this,new u(this,t))(t)}progress(...t){return l.U(this,new u(this,""))(...t)}while(t){return l.q(this,new u(this,""))(t)}G(t){let e=0;const i=this.B.entries();for(const[s,n]of i)if(!t(s,n,e++))break}delete(t){this.B.delete(t.getId())}hideAll(){this.B.forEach((t=>t.delete()))}hide(t){if(t){const e=this.B.get(t);if(!e)throw new Error(`Could not find element with id: ${t}`);e.delete()}else this.G(((t,e,i)=>{const s=0===i;return s&&e.delete(),s}))}}m.O="Nanosplash",window.addEventListener("load",(()=>window.ns=new m))}();
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}))}();
@@ -2,9 +2,6 @@
2
2
  "src/Core/Nanosplash.ts": {
3
3
  "file": "nanosplash.cjs.js",
4
4
  "src": "src/Core/Nanosplash.ts",
5
- "isEntry": true,
6
- "css": [
7
- "Nanosplash.css"
8
- ]
5
+ "isEntry": true
9
6
  }
10
7
  }
@@ -1 +1 @@
1
- var t=Object.defineProperty,s=Object.defineProperties,e=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,h=(s,e,i)=>e in s?t(s,e,{t:!0,i:!0,writable:!0,value:i}):s[e]=i;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,e){t.setAttribute(s,e)}class u{static o(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 u(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 e in s||(s={}))r.call(s,e)&&h(t,e,s[e]);if(i)for(var e of i(s))n.call(s,e)&&h(t,e,s[e]);return t})({},o),s(c,e({inside:s=>(t.moveTo(s),o)}));var c}}class l{constructor(t,s,e){var i;this.l=o("div"),this.m=o("div"),this.g=o("div"),this.v=o("div"),this.p=o("img"),this.S=o("div"),this.id=Math.random().toString(36).substring(2),this.O=t,this.S.innerText=s,this.I=e,this.p.src=null!=(i=this.I)?i:"",this.p.alt=d.j,this.F(),this.setImgSrc(e)}N(){c(this.v,"ns-container"),c(this.m,"ns-blur"),c(this.p,"ns-img"),c(this.S,"ns-text"),c(this.g,"ns","ns-window"),c(this.l,"ns-wrapper")}T(){this.v.append(this.p,this.S),this.g.append(this.v),this.l.append(this.m,this.g)}F(){this.l.id=this.getId(),a(this.l,"data-ctx","nanosplash"),this.T(),this.N()}getId(){return this.id}getText(){return this.S.innerText}setText(t){return this.S.innerText=t,this}getImgSrc(){return this.I}setImgSrc(t){return this.p.src=null!=t?t:"",this.p.style.display=t?"block":"none",this.T(),this}M(){const t=this.l.parentElement;t&&this.C(t)}A(){a(this.l,"style",""),this.l.classList.remove("ns-fs")}W(t){const s=t.parentNode;s&&(this.C(s),s.replaceChild(this.l,t),this.m.appendChild(t))}D(){this.l.classList.add("ns-fs"),((t,s,e=!1)=>{t&&s&&(s.hasChildNodes()&&e?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.l,document.body,!0)}moveTo(t){this.M();const s=u.o(t);s===document.body?this.D():(this.A(),this.W(s)),this.F()}k(t){Array.from(this.m.childNodes).forEach(t)}C(t){this.k((s=>t.insertBefore(s,this.l)))}$(){[this.S,this.p,this.v,this.m,this.g,this.l].forEach((t=>t.remove()))}delete(){this.M(),this.$(),this.O.delete(this)}}class m{static _(t,s,e,i){var r;return t||(t=new l(s,e,i)),t.setText(e).setImgSrc(null!=(r=t.getImgSrc())?r:i)}static P(t,s){return e=>(s=m._(s,t,"",e),{show:m.R(t,s),progress:m.q(t,s),while:m.B(t,s)})}static R(t,s){return e=>(s=m._(s,t,e),t.G.set(s.getId(),s),s.moveTo(document.body),u.u(s))}static q(t,s){return(...e)=>((s=m._(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[i,r]]of e.entries())s.setText(r),await i;s.delete()})(),u.u(s))}static B(t,s){return e=>(s=m._(s,t,""),{show:i=>(t.G.set(s.getId(),s),s.moveTo(document.body),s.setText(i),e.finally((()=>s.delete())),u.u(s))})}}class d{constructor(){this.G=new Map}img(t){return m.P(this,new l(this,"",t))(t)}show(t){return m.R(this,new l(this,t))(t)}progress(...t){return m.q(this,new l(this,""))(...t)}while(t){return m.B(this,new l(this,""))(t)}H(t){let s=0;const e=this.G.entries();for(const[i,r]of e)if(!t(i,r,s++))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);if(!s)throw new Error(`Could not find element with id: ${t}`);s.delete()}else this.H(((t,s,e)=>{const i=0===e;return i&&s.delete(),i}))}}d.j="Nanosplash",exports.Nanosplash=d;
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;
@@ -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.nsWrapperElement = mk("div");
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.getFontSize();
95
+ this.nsSpinnerElement.style.display = ns.spinnerIsVisible() ? "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.nsContentElement.append(this.nsImageElement, this.nsTextElement);
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
- cleanup() {
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.getFromDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete);
169
+ }
145
170
  moveTo(destination) {
146
- this.cleanup();
147
- const targetNode = NanosplashRepository.destinationToNode(destination);
148
- const targetIsBody = targetNode === document.body;
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(targetNode);
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.cleanup();
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);
@@ -231,27 +249,51 @@ class NanosplashFactory {
231
249
  };
232
250
  }
233
251
  }
234
- class Nanosplash {
235
- constructor() {
252
+ const _Nanosplash = class {
253
+ constructor(options) {
254
+ var _a;
255
+ this.imgSrc = options == null ? void 0 : options.imgSrc;
256
+ this.spinner = (options == null ? void 0 : options.spinner) === void 0 ? _Nanosplash.SPINNER_DEFAULT_VISIBILITY : options.spinner;
257
+ this.fontSize = (_a = options == null ? void 0 : options.fontSize) != null ? _a : "18px";
236
258
  this.instances = /* @__PURE__ */ new Map();
237
259
  }
238
- img(src) {
239
- return NanosplashFactory.createImgFunction(this, new SplashInstance(this, "", src))(src);
260
+ setImgSrc(value) {
261
+ this.imgSrc = value;
262
+ return this;
263
+ }
264
+ showSpinner(value) {
265
+ this.spinner = value;
266
+ return this;
267
+ }
268
+ setFontSize(value) {
269
+ this.fontSize = value;
270
+ return this;
271
+ }
272
+ getImgSrc() {
273
+ return this.imgSrc;
274
+ }
275
+ spinnerIsVisible() {
276
+ return this.spinner;
277
+ }
278
+ getFontSize() {
279
+ return this.fontSize;
240
280
  }
241
281
  show(text) {
242
- return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text);
282
+ return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text, this.imgSrc))(text);
243
283
  }
244
284
  progress(...jobs) {
245
- return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ""))(...jobs);
285
+ return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, "", this.imgSrc))(...jobs);
246
286
  }
247
287
  while(asyncTask) {
248
- return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ""))(asyncTask);
249
- }
250
- fifoIterate(callback) {
251
- let i = 0;
252
- const instanceEntries = this.instances.entries();
253
- for (const [id, splashInstance] of instanceEntries) {
254
- if (!callback(id, splashInstance, i++)) {
288
+ return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, "", this.imgSrc))(asyncTask);
289
+ }
290
+ lifoIterate(callback) {
291
+ const n = this.instances.size;
292
+ const instances = Array.from(this.instances.values());
293
+ for (let i = n - 1; i >= 0; i--) {
294
+ const instance = instances[i];
295
+ const id = instance.getId();
296
+ if (!callback(id, instance, i)) {
255
297
  break;
256
298
  }
257
299
  }
@@ -262,17 +304,20 @@ class Nanosplash {
262
304
  hideAll() {
263
305
  this.instances.forEach((instance) => instance.delete());
264
306
  }
265
- hide(id) {
266
- if (id) {
267
- const splashInstance = this.instances.get(id);
307
+ hide(idOrSelector) {
308
+ if (idOrSelector) {
309
+ const splashInstance = this.instances.get(idOrSelector);
268
310
  if (splashInstance) {
269
311
  splashInstance.delete();
270
312
  } else {
271
- throw new Error(`Could not find element with id: ${id}`);
313
+ Array.from(this.instances.values()).filter((splashInstance2) => {
314
+ return splashInstance2.getDestination() === get(idOrSelector);
315
+ }).forEach((splashInstance2) => splashInstance2.delete());
272
316
  }
273
317
  } else {
274
- this.fifoIterate((_, splashInstance, i) => {
275
- const remove = i === 0;
318
+ const n = this.instances.size;
319
+ this.lifoIterate((_, splashInstance, i) => {
320
+ const remove = i === n - 1;
276
321
  if (remove) {
277
322
  splashInstance.delete();
278
323
  }
@@ -280,6 +325,12 @@ class Nanosplash {
280
325
  });
281
326
  }
282
327
  }
283
- }
328
+ getFromDestinationNode(node) {
329
+ const fnSameDestinationNode = (v) => v.getDestination() === node;
330
+ return Array.from(this.instances.values()).filter(fnSameDestinationNode);
331
+ }
332
+ };
333
+ let Nanosplash = _Nanosplash;
284
334
  Nanosplash.APP_NAME = "Nanosplash";
285
- export { Nanosplash };
335
+ Nanosplash.SPINNER_DEFAULT_VISIBILITY = true;
336
+ export { Nanosplash as default };
@@ -0,0 +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: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}}
package/docs/index.html CHANGED
@@ -15,8 +15,23 @@
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-3xl">Nanosplash</div>
19
- <div class="mt-3">Small. Simple. Reliable.</div>
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
+ <div class="flex gap-5">
21
+ <div
22
+ id="demo"
23
+ class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
24
+ >
25
+ <i class="lni lni-play"></i>
26
+ Display demo
27
+ </div>
28
+ <a
29
+ href="#example"
30
+ class="bg-slate-500 text-slate-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
31
+ >
32
+ Show examples
33
+ </a>
34
+ </div>
20
35
  <div class="flex flex-col space-y-2 my-10">
21
36
  <div class="flex space-x-2 justify-center">
22
37
  <img src="https://badgen.net/npm/v/nanosplash" />
@@ -30,13 +45,23 @@
30
45
  />
31
46
  </div>
32
47
  </div>
33
- <div class="text-white bg-slate-700 p-3 rounded shadow-xl font-mono text-sm">ns.show('text').inside('#myDiv')</div>
48
+ <div class="flex rounded-xl text-slate-400 shadow-xl overflow-hidden">
49
+ <div data-copy class="p-3 bg-slate-800 text-slate-400 font-mono">
50
+ &lt;script src=&quot;https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js&quot;&gt;
51
+ </div>
52
+ <div id="copy" class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white">Copy</div>
53
+ </div>
54
+ <div class="mt-10 flex justify-content items-center divide-x-2 text-slate-400">
55
+ <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>
56
+ <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>
57
+ </div>
58
+ <a class="mt-10 text-pink-300 hover:text-pink-500" href="https://rawcdn.githack.com/isakhauge/nanosplash/0a6cdef58b0e47c0cad911952b1a329df58d2c24/docs/typedoc/index.html">API Reference Documentation</a>
34
59
  </div>
35
- <div class="grid grid-cols-2 gap-1">
60
+ <div id="example" class="grid grid-cols-1 xl:grid-cols-2 gap-1">
36
61
  <div id="a" class="p-20 bg-slate-100 flex flex-col items-center">
37
62
  <div class="text-xl mb-10">Give user progress feedback</div>
38
- <div class="text-white bg-slate-800 p-5 rounded-lg shadow-2xl font-mono text-sm">
39
- ns.img(src).progress(<br>
63
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
64
+ ns.progress(<br>
40
65
  &nbsp;&nbsp;[promise1, 'Loading A'],<br>
41
66
  &nbsp;&nbsp;[promise2, 'Loading B'],<br>
42
67
  &nbsp;&nbsp;[promise3, 'Loading C'],<br>
@@ -45,33 +70,60 @@
45
70
  </div>
46
71
  <div id="b" class="p-20 bg-slate-100 flex flex-col items-center">
47
72
  <div class="text-xl mb-10">Handle async functions</div>
48
- <div class="text-white bg-slate-800 p-5 rounded-lg shadow-2xl font-mono text-sm">
73
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
49
74
  ns.while(promise).show('Loading ...').inside('#myDiv')
50
75
  </div>
51
76
  </div>
52
77
  <div id="c" class="p-20 bg-slate-100 flex flex-col items-center">
53
78
  <div class="text-xl mb-10">Display fullscreen</div>
54
- <div class="text-white bg-slate-800 p-5 rounded-lg shadow-2xl font-mono text-sm">
55
- const splash = ns.show('Fullscreen text')<br>
56
- splash.moveTo('#myDiv')<br>
57
- splash.remove()
79
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
80
+ ns.show('Fullscreen text')
58
81
  </div>
59
82
  </div>
60
83
  <div id="d" class="p-20 bg-slate-100 flex flex-col items-center">
61
84
  <div class="text-xl mb-10">Display multiple, independent instances</div>
62
- <div class="text-white bg-slate-800 p-5 rounded-lg shadow-2xl font-mono text-sm">
63
- ns.img(src).show('Loading component A').inside('#a')<br>
64
- ns.show('Loading component A').inside('#b')<br>
65
- ns.show('Loading component A').inside('#c')<br>
66
- <br><br>
67
- ns.hide() // Removes instances in a FIFO manner.<br>
68
- ns.hideAll() // Removes all instances.
85
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
86
+ ns.show('Loading component A').inside('#a')<br>
87
+ ns.show('Loading component B').inside('#b')<br>
88
+ ns.show('Loading component C').inside('#c')
89
+ </div>
90
+ </div>
91
+ <div id="e" class="p-20 bg-slate-100 flex flex-col items-center">
92
+ <div class="text-xl mb-10">Move splash instance to another destination</div>
93
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
94
+ const splash = ns.show('Loading').inside('#a')<br>
95
+ splash.moveTo('#b')
96
+ </div>
97
+ </div>
98
+ <div id="f" class="p-20 bg-slate-100 flex flex-col items-center">
99
+ <div class="text-xl mb-10">Hide splash instances</div>
100
+ <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
101
+ // Hides one instance at a time, in a LIFO-fashion.<br>
102
+ ns.hide()<br><br>
103
+ // Hides all instances.<br>
104
+ ns.hideAll()
69
105
  </div>
70
106
  </div>
71
107
  </div>
72
108
  <footer>
73
109
 
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
+ }
125
+ </script>
74
126
  </footer>
75
- <style>body{min-height:100vh}.pill{font-size:10px;padding:.2em .5em}</style>
127
+ <style>body{min-height:100vh}</style>
76
128
  </body>
77
129
  </html>