nanosplash 2.5.3 → 3.0.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.
Files changed (80) hide show
  1. package/.github/workflows/ci.yml +48 -0
  2. package/.prettierrc +10 -9
  3. package/README.md +22 -89
  4. package/dist/main.css +1 -0
  5. package/dist/ns.cjs.js +1 -0
  6. package/dist/ns.es.js +330 -0
  7. package/dist/ns.iife.js +2 -0
  8. package/index.html +41 -122
  9. package/package.json +27 -34
  10. package/src/main.ts +8 -5
  11. package/src/sass/ns.sass +86 -0
  12. package/src/ts/core/Nanosplash/Nanosplash.ts +97 -0
  13. package/src/ts/core/Nanosplash/interfaces/NanosplashAPI.ts +50 -0
  14. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +42 -0
  15. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +178 -0
  16. package/src/ts/core/Nanosplash/services/NanosplashService.ts +222 -0
  17. package/src/ts/types/Alias.d.ts +1 -0
  18. package/src/ts/types/Nanosplash.d.ts +18 -0
  19. package/src/ts/types/NanosplashService.d.ts +1 -0
  20. package/src/ts/util/Guid.ts +13 -0
  21. package/src/ts/util/Stack.ts +73 -0
  22. package/src/vite-env.d.ts +8 -0
  23. package/tests/Guid.spec.ts +21 -0
  24. package/tests/Nanosplash.spec.ts +64 -0
  25. package/tests/NanosplashRepository.spec.ts +91 -0
  26. package/tests/NanosplashService.spec.ts +119 -0
  27. package/tests/Stack.spec.ts +56 -0
  28. package/tsconfig.json +9 -5
  29. package/vite.config.ts +22 -14
  30. package/.github/workflows/production.yml +0 -60
  31. package/.github/workflows/release.yml +0 -61
  32. package/LICENSE +0 -21
  33. package/_config.yml +0 -1
  34. package/dist/iife/manifest.json +0 -7
  35. package/dist/iife/nanosplash.iife.js +0 -1
  36. package/dist/module/manifest.json +0 -7
  37. package/dist/module/nanosplash.cjs.js +0 -1
  38. package/dist/module/nanosplash.es.js +0 -371
  39. package/dist/module/style.css +0 -1
  40. package/docs/index.html +0 -131
  41. package/docs/nanosplash.iife.js +0 -6
  42. package/docs/style.css +0 -1
  43. package/docs/typedoc/.nojekyll +0 -1
  44. package/docs/typedoc/assets/highlight.css +0 -22
  45. package/docs/typedoc/assets/icons.css +0 -1043
  46. package/docs/typedoc/assets/icons.png +0 -0
  47. package/docs/typedoc/assets/icons@2x.png +0 -0
  48. package/docs/typedoc/assets/main.js +0 -52
  49. package/docs/typedoc/assets/search.js +0 -1
  50. package/docs/typedoc/assets/style.css +0 -1414
  51. package/docs/typedoc/assets/widgets.png +0 -0
  52. package/docs/typedoc/assets/widgets@2x.png +0 -0
  53. package/docs/typedoc/classes/Core_Nanosplash.default.html +0 -133
  54. package/docs/typedoc/index.html +0 -1
  55. package/docs/typedoc/modules/Core_Nanosplash.html +0 -1
  56. package/docs/typedoc/modules/types.html +0 -1
  57. package/favicon.svg +0 -15
  58. package/postcss.config.js +0 -8
  59. package/src/Core/Nanosplash.ts +0 -257
  60. package/src/Core/SplashInstance.ts +0 -298
  61. package/src/Exceptions/DestinationException.ts +0 -13
  62. package/src/Exceptions/Exception.ts +0 -9
  63. package/src/Exceptions/IllegalArgumentException.ts +0 -11
  64. package/src/Factory/NanosplashFactory.ts +0 -93
  65. package/src/Interfaces/ContextualAPIInterface.ts +0 -8
  66. package/src/Interfaces/IdentityInterface.ts +0 -3
  67. package/src/Interfaces/InsideInterface.ts +0 -5
  68. package/src/Interfaces/NanosplashInterface.ts +0 -8
  69. package/src/Interfaces/ProgressInterface.ts +0 -5
  70. package/src/Interfaces/ShowInterface.ts +0 -5
  71. package/src/Interfaces/WhileInterface.ts +0 -5
  72. package/src/Repositories/NanosplashRepository.ts +0 -82
  73. package/src/Tests/dom.spec.ts +0 -72
  74. package/src/Utilities/dom.ts +0 -49
  75. package/src/style.sass +0 -88
  76. package/src/types.d.ts +0 -59
  77. package/update-all.sh +0 -3
  78. package/vite.iife.config.js +0 -72
  79. package/vite.mod.config.js +0 -71
  80. package/vite.site.config.js +0 -22
@@ -0,0 +1,48 @@
1
+ name: Build and Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - production
7
+ pull_request:
8
+ branches:
9
+ - production
10
+
11
+ jobs:
12
+ build-and-test:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v2
18
+
19
+ - name: Setup Node.js
20
+ uses: actions/setup-node@v2
21
+ with:
22
+ node-version: '20'
23
+
24
+ - name: Set up Git and update production branch
25
+ run: |
26
+ git config --global user.name "GitHub Actions"
27
+ git config --global user.email "actions@github.com"
28
+ git checkout production
29
+ git fetch
30
+ git pull --no-rebase
31
+
32
+ - name: Install dependencies
33
+ run: yarn install --frozen-lockfile
34
+
35
+ - name: Build (Vite)
36
+ run: yarn build
37
+
38
+ - name: Test (Vitest)
39
+ run: yarn test
40
+
41
+ - name: Generate Code Coverage (Vitest)
42
+ run: yarn coverage
43
+
44
+ - name: Commit and push changes
45
+ run: |
46
+ git add .
47
+ git commit --allow-empty -m "Build, test, and coverage report"
48
+ git push
package/.prettierrc CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
- "tabWidth": 2,
3
- "useTabs": true,
4
- "singleQuote": true,
5
- "bracketSpacing": true,
6
- "jsxSingleQuote": true,
7
- "endOfLine": "lf",
8
- "trailingComma": "es5",
9
- "arrowParens": "avoid",
10
- "semi": false
2
+ "tabWidth": 2,
3
+ "useTabs": true,
4
+ "singleQuote": true,
5
+ "bracketSpacing": true,
6
+ "jsxSingleQuote": true,
7
+ "endOfLine": "lf",
8
+ "trailingComma": "es5",
9
+ "arrowParens": "avoid",
10
+ "semi": false,
11
+ "printWidth": 80
11
12
  }
package/README.md CHANGED
@@ -1,124 +1,57 @@
1
- # nanosplash 🍩
1
+ # Nanosplash
2
2
 
3
- ![npm](https://img.shields.io/npm/v/nanosplash)
4
- ![Minified+gzip size](https://badgen.net/bundlephobia/minzip/nanosplash)
5
- ![Minified size](https://badgen.net/bundlephobia/dependency-count/nanosplash)
6
- ![Tree shaking](https://badgen.net/bundlephobia/tree-shaking/nanosplash)
3
+ ### Tiny loading screen for web artisans
7
4
 
8
- ![npm maintenance score](https://img.shields.io/npms-io/maintenance-score/nanosplash)
9
- ![npm quality score](https://img.shields.io/npms-io/quality-score/nanosplash)
10
- ![npm final score](https://img.shields.io/npms-io/final-score/nanosplash)
11
- ![npm popularity score](https://img.shields.io/npms-io/popularity-score/nanosplash)
5
+ <br>
12
6
 
13
- <strong>The simple, tiny loading screen</strong>
7
+ [![Build](https://github.com/isakhauge/nanosplash/actions/workflows/ci.yml/badge.svg?branch=production)](https://github.com/isakhauge/nanosplash/actions/workflows/ci.yml) [![Build Status](https://github.com/isakhauge/nanosplash/workflows/CI/badge.svg?branch=production)](https://github.com/isakhauge/nanosplash/actions?query=workflow%3ACI) [![Coverage](https://img.shields.io/badge/Coverage-98.5%25-brightgreen.svg?style=flat)](https://your-coverage-report-url) [![TypeScript](https://badges.frapsoft.com/typescript/version/typescript-next.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) [![Last Commit](https://img.shields.io/github/last-commit/isakhauge/nanosplash)](https://github.com/isakhauge/nanosplash/commits/production)
14
8
 
15
- # Getting started
9
+ <br>
16
10
 
17
- ## Import via CDN (recommended)
11
+ ## Get started
18
12
 
19
- ```html
20
- <script src="https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js"></script>
21
- ```
22
- ```js
23
- // Install Nanosplash in the browser
24
- window.installNanosplash()
25
- // Display your first Nanosplash
26
- window.ns.show('Hello world')
27
- ```
13
+ Always get the latest version.
28
14
 
29
- ## Install (advanced)
30
- ```bash
31
- yarn add nanosplash
15
+ ```html
16
+ <script src="https://unpkg.com/nanosplash/dist/ns.iife.js">
32
17
  ```
33
18
 
34
- ### Modules
19
+ ## Display loading screen
35
20
 
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.
21
+ Display spinning wheel only.
37
22
 
38
23
  ```js
39
- import 'nanosplash/dist/module/style.css'
24
+ ns.show()
40
25
  ```
41
26
 
42
- > ### Location of the stylesheet
43
- >
44
- > Full: `node_modules/nanosplash/dist/module/style.css`<br>
45
- > Relative: `nanosplash/dist/module/style.css`
46
-
47
- #### ESM (ES modules)
27
+ Display with text.
48
28
 
49
29
  ```js
50
- import { Nanosplash } from 'nanosplash'
30
+ ns.show('Loading assets')
51
31
  ```
52
32
 
53
- #### CJS (CommonJS)
33
+ Display inside another element.
54
34
 
55
35
  ```js
56
- const Nanosplash = require('nanosplash')
36
+ ns.showInside('Loading table', '#my-table')
57
37
  ```
58
38
 
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
69
- ```js
70
- const nsOptions = {
71
- spinner: true,
72
- fontSize: '18px',
73
- }
74
- window.ns = new Nanosplash(nsOptions)
75
- ```
76
-
77
- ## Basic usage
78
-
79
- ### Display the loading screen
39
+ ## Hide loading screen
80
40
 
81
- ```js
82
- ns.show('Loading the good stuff')
83
- ```
84
-
85
- ### Hide the loading screen
41
+ Hide the last loading screen (LIFO).
86
42
 
87
43
  ```js
88
- // Hide one at a time
89
44
  ns.hide()
90
-
91
- // Hide all
92
- ns.hideAll()
93
45
  ```
94
46
 
95
- ## Advanced usage
96
-
97
- ### Display the loading screen inside an element
47
+ Hide loading screen inside another element.
98
48
 
99
49
  ```js
100
- // Use CSS selector string
101
- ns.show('Loading component').inside('#my-element')
102
-
103
- // Use HTMLElement objects directly
104
- ns.show('Loading component').inside(document.getElementById('my-element'))
50
+ ns.hideInside('#my-table')
105
51
  ```
106
52
 
107
- ### Combine Nanosplash with async tasks
53
+ Hide all loading screens.
108
54
 
109
55
  ```js
110
- const task1 = new Promise(r => setTimeout(r, 3000))
111
- const task2 = async () => await getDataFromApi()
112
-
113
- ns.while(task1).show('Loading resources')
114
- ns.while(task2).show('Fetching table data').inside('#my-table')
115
-
116
- ns.progress(
117
- [task1, 'Loading data from API'],
118
- [task2, 'Processing data']
119
- ).inside('#my-table')
56
+ ns.hideAll()
120
57
  ```
121
-
122
- <hr>
123
-
124
- ## If you like it, give it a star! ⭐️
package/dist/main.css ADDED
@@ -0,0 +1 @@
1
+ .ns,.ns-host:before{width:100%;height:100%}.ns,.ns-host:before{top:0;left:0}.ns-content,.ns{display:flex;justify-content:center;align-items:center}.ns-host{--text-color: DarkSlateGray;--font-size: 20px;--proportional-size: calc(var(--font-size) * .9);--font-family: "Helvetica", "Arial", sans-serif;--font-weight: 400;--background: rgba(255, 255, 255, .8);--z-index: 999999999;--blur-filter: blur(10px)}.ns-host{position:relative;z-index:var(--z-index)}.ns-host:before{position:absolute;background-color:var(--background);content:"";backdrop-filter:var(--blur-filter);-webkit-backdrop-filter:var(--blur-filter);z-index:calc(var(--z-index) + 1)}body.ns-host{height:100vh}.ns{position:absolute;z-index:calc(var(--z-index) + 2)}.ns-text{color:var(--text-color);font-size:var(--font-size);font-family:var(--font-family);font-weight:var(--font-weight);margin-right:var(--proportional-size)}.ns-spinner{display:block;width:var(--proportional-size);height:var(--proportional-size)}.ns-spinner>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.ns-spinner .path{stroke:var(--text-color);stroke-linecap:round;animation:Dash 1.5s ease-in-out infinite}@keyframes Rotate{to{transform:rotate(360deg)}}@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/dist/ns.cjs.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var g=Object.defineProperty;var S=(e,t,n)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var i=(e,t,n)=>(S(e,typeof t!="symbol"?t+"":t,n),n);function N(){return new DOMParser().parseFromString('<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>',"text/html").body.firstChild}function w(e,t){t.children.length>0?t.insertBefore(e,t.children.item(0)):t.append(e)}function o(e,t){e==null||e.classList[t](l.nsHostClassName)}function E(e){o(e.getNSElement().parentElement,"remove")}function v(e){e.style.display="flex"}function y(e){e.style.display="none"}function a(e){let t;if(typeof e=="string")t=document.querySelector(e);else{if(e instanceof Node)return e;if(typeof e=="function"){if(t=e(),!(t instanceof Node))return null}else t=null}return t}function p(e){var t;return(t=e==null?void 0:e.classList)==null?void 0:t.contains("ns")}function u(e,t){o(e.parentElement,"remove"),o(t,"add"),w(e,t)}function m(e){const t=a(e);if(!t)return null;const n=t.firstChild;if(n!==null&&p(n)){const x=n.id;return d.getInstance().nsStack.items.find(f=>f.getId()===x)??null}return null}function I(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}const h=class{constructor(){i(this,"id");i(this,"element");this.element=N(),this.element.id=this.id=I()}getId(){return this.id}getNSElement(){return this.element}getNSContentElement(){return this.getNSElement().firstElementChild}getNSTextElement(){return this.getNSContentElement().firstElementChild}hideText(){return y(this.getNSTextElement()),this}setText(t){return this.getNSTextElement().innerText=t,t.length>0?this.showText():this.hideText(),this}showText(){return v(this.getNSTextElement()),this}remove(){var t;this.element&&((t=this.element.parentElement)==null||t.removeChild(this.element),delete this.element)}};let l=h;i(l,"nsClassName","ns"),i(l,"nsHostClassName",h.nsClassName+"-host");class C{constructor(){i(this,"_items");this._items=[]}get items(){return this._items}push(t){this._items.push(t)}pop(){return this._items.pop()}peek(){return this._items[this._items.length-1]}isEmpty(){return this._items.length===0}size(){return this._items.length}clear(){this._items=[]}}const s=class{constructor(){i(this,"nsStack");this.nsStack=new C}findIndex(t){return this.nsStack.items.findIndex(t)}find(t){return this.nsStack.items.find(t)}static getInstance(){return s.instance||(s.instance=new s),s.instance}static assignToWindow(){Object.defineProperty(window,s.WindowAccessorKey,{value:s.getInstance(),writable:!1})}static start(){s.assignToWindow(),window.addEventListener("load",()=>{window[s.WindowAccessorKey]instanceof s||s.assignToWindow()})}createNS(t){const n=new l;return n.setText(t||""),this.nsStack.push(n),n}cleanAndRemove(t){return E(t),t.remove(),t.getId()}stackDelete(t){let n=this.findIndex(r=>r.getId()===t.getId());return n<0?null:(this.nsStack.items.splice(n,1),t.getId())}deleteNS(t){const n=this.find(t);return n?(this.cleanAndRemove(n),this.stackDelete(n)):null}show(t){let n=m(document.body);return n||(n=this.createNS(),u(n.getNSElement(),document.body)),n.setText(t||""),n.getId()}showInside(t,n){const r=a(t);if(r){let c=m(r);return c||(c=this.createNS()),c.setText(n||""),u(c.getNSElement(),r),c.getId()}return null}hideAll(){this.nsStack.items.forEach(t=>{this.cleanAndRemove(t)}),this.nsStack.clear()}hide(){const t=this.nsStack.pop();return t?this.cleanAndRemove(t):null}hideId(t){return this.deleteNS(n=>n.getId()===t)}hideInside(t){const n=a(t),r=c=>c.getNSElement().parentElement===n;return n?this.deleteNS(r):null}};let d=s;i(d,"WindowAccessorKey","ns"),i(d,"instance");try{d.start()}catch(e){console.warn(e)}
package/dist/ns.es.js ADDED
@@ -0,0 +1,330 @@
1
+ var g = Object.defineProperty;
2
+ var S = (e, t, n) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var i = (e, t, n) => (S(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ function N() {
5
+ return new DOMParser().parseFromString(
6
+ '<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>',
7
+ "text/html"
8
+ ).body.firstChild;
9
+ }
10
+ function w(e, t) {
11
+ t.children.length > 0 ? t.insertBefore(e, t.children.item(0)) : t.append(e);
12
+ }
13
+ function o(e, t) {
14
+ e == null || e.classList[t](l.nsHostClassName);
15
+ }
16
+ function E(e) {
17
+ o(e.getNSElement().parentElement, "remove");
18
+ }
19
+ function v(e) {
20
+ e.style.display = "flex";
21
+ }
22
+ function y(e) {
23
+ e.style.display = "none";
24
+ }
25
+ function a(e) {
26
+ let t;
27
+ if (typeof e == "string")
28
+ t = document.querySelector(e);
29
+ else {
30
+ if (e instanceof Node)
31
+ return e;
32
+ if (typeof e == "function") {
33
+ if (t = e(), !(t instanceof Node))
34
+ return null;
35
+ } else
36
+ t = null;
37
+ }
38
+ return t;
39
+ }
40
+ function p(e) {
41
+ var t;
42
+ return (t = e == null ? void 0 : e.classList) == null ? void 0 : t.contains("ns");
43
+ }
44
+ function u(e, t) {
45
+ o(e.parentElement, "remove"), o(t, "add"), w(e, t);
46
+ }
47
+ function m(e) {
48
+ const t = a(e);
49
+ if (!t)
50
+ return null;
51
+ const n = t.firstChild;
52
+ if (n !== null && p(n)) {
53
+ const x = n.id;
54
+ return d.getInstance().nsStack.items.find((f) => f.getId() === x) ?? null;
55
+ }
56
+ return null;
57
+ }
58
+ function I() {
59
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
60
+ const t = Math.random() * 16 | 0;
61
+ return (e === "x" ? t : t & 3 | 8).toString(16);
62
+ });
63
+ }
64
+ const h = class {
65
+ constructor() {
66
+ i(this, "id");
67
+ i(this, "element");
68
+ this.element = N(), this.element.id = this.id = I();
69
+ }
70
+ /**
71
+ * @inheritDoc
72
+ */
73
+ getId() {
74
+ return this.id;
75
+ }
76
+ /**
77
+ * @inheritDoc
78
+ */
79
+ getNSElement() {
80
+ return this.element;
81
+ }
82
+ /**
83
+ * # Get NS Content Element
84
+ * Returns the content element of the Nanosplash.
85
+ */
86
+ getNSContentElement() {
87
+ return this.getNSElement().firstElementChild;
88
+ }
89
+ /**
90
+ * # Get NS Text Element
91
+ * Returns the text element of the Nanosplash.
92
+ */
93
+ getNSTextElement() {
94
+ return this.getNSContentElement().firstElementChild;
95
+ }
96
+ /**
97
+ * @inheritDoc
98
+ */
99
+ hideText() {
100
+ return y(this.getNSTextElement()), this;
101
+ }
102
+ /**
103
+ * @inheritDoc
104
+ */
105
+ setText(t) {
106
+ return this.getNSTextElement().innerText = t, t.length > 0 ? this.showText() : this.hideText(), this;
107
+ }
108
+ /**
109
+ * @inheritDoc
110
+ */
111
+ showText() {
112
+ return v(this.getNSTextElement()), this;
113
+ }
114
+ /**
115
+ * @inheritDoc
116
+ */
117
+ remove() {
118
+ var t;
119
+ this.element && ((t = this.element.parentElement) == null || t.removeChild(this.element), delete this.element);
120
+ }
121
+ };
122
+ let l = h;
123
+ i(l, "nsClassName", "ns"), i(l, "nsHostClassName", h.nsClassName + "-host");
124
+ class C {
125
+ /**
126
+ * Constructs a new stack.
127
+ */
128
+ constructor() {
129
+ i(this, "_items");
130
+ this._items = [];
131
+ }
132
+ /**
133
+ * Returns the items in the stack.
134
+ */
135
+ get items() {
136
+ return this._items;
137
+ }
138
+ /**
139
+ * Adds an item to the top of the stack.
140
+ * @param item The item to add to the stack.
141
+ */
142
+ push(t) {
143
+ this._items.push(t);
144
+ }
145
+ /**
146
+ * Removes and returns the item at the top of the stack.
147
+ * @returns The item at the top of the stack, or undefined if the stack is empty.
148
+ */
149
+ pop() {
150
+ return this._items.pop();
151
+ }
152
+ /**
153
+ * Returns the item at the top of the stack without removing it.
154
+ * @returns The item at the top of the stack, or undefined if the stack is empty.
155
+ */
156
+ peek() {
157
+ return this._items[this._items.length - 1];
158
+ }
159
+ /**
160
+ * Returns true if the stack is empty, false otherwise.
161
+ * @returns True if the stack is empty, false otherwise.
162
+ */
163
+ isEmpty() {
164
+ return this._items.length === 0;
165
+ }
166
+ /**
167
+ * Returns the number of items in the stack.
168
+ * @returns The number of items in the stack.
169
+ */
170
+ size() {
171
+ return this._items.length;
172
+ }
173
+ /**
174
+ * Removes all items from the stack.
175
+ */
176
+ clear() {
177
+ this._items = [];
178
+ }
179
+ }
180
+ const s = class {
181
+ /**
182
+ * # Constructor
183
+ * Private constructor to prevent multiple instances.
184
+ * @private
185
+ */
186
+ constructor() {
187
+ i(this, "nsStack");
188
+ this.nsStack = new C();
189
+ }
190
+ /**
191
+ * # Find Index
192
+ * Find Nanosplash stack index by callback.
193
+ * @param callback Callback function that returns a boolean.
194
+ * @returns {number} Index of Nanosplash instance in the stack or -1.
195
+ */
196
+ findIndex(t) {
197
+ return this.nsStack.items.findIndex(t);
198
+ }
199
+ /**
200
+ * # Find
201
+ * Find Nanosplash in the stack by callback.
202
+ * @param callback Callback function that returns a boolean.
203
+ * @returns {Nanosplash | undefined} Nanosplash instance or undefined
204
+ */
205
+ find(t) {
206
+ return this.nsStack.items.find(t);
207
+ }
208
+ /**
209
+ * # Get Instance
210
+ * Singleton instance accessor
211
+ * @returns {NanosplashService} NanosplashService instance
212
+ */
213
+ static getInstance() {
214
+ return s.instance || (s.instance = new s()), s.instance;
215
+ }
216
+ /**
217
+ * # Assign To Window
218
+ * Assign Nanosplash service instance to Window object.
219
+ * The NanosplashService instance can be accessed in the window object
220
+ * using the key window accessor key.
221
+ * @see WindowAccessorKey
222
+ */
223
+ static assignToWindow() {
224
+ Object.defineProperty(window, s.WindowAccessorKey, {
225
+ value: s.getInstance(),
226
+ writable: !1
227
+ });
228
+ }
229
+ /**
230
+ * # Start
231
+ * Initialize Nanosplash Service instance in Window when it's loaded.
232
+ */
233
+ static start() {
234
+ s.assignToWindow(), window.addEventListener("load", () => {
235
+ window[s.WindowAccessorKey] instanceof s || s.assignToWindow();
236
+ });
237
+ }
238
+ /**
239
+ * # Create Nanosplash
240
+ * Return new Nanosplash instance and push it to the stack.
241
+ * @param text Text to display.
242
+ * @returns {Nanosplash} Nanosplash instance.
243
+ */
244
+ createNS(t) {
245
+ const n = new l();
246
+ return n.setText(t || ""), this.nsStack.push(n), n;
247
+ }
248
+ /**
249
+ * # Clean And Remove
250
+ * Remove Nanosplash from DOM and clean its parent.
251
+ * @param ns Nanosplash instance.
252
+ * @returns {GUIDString} Nanosplash ID.
253
+ */
254
+ cleanAndRemove(t) {
255
+ return E(t), t.remove(), t.getId();
256
+ }
257
+ /**
258
+ * # Stack Delete At
259
+ * Remove Nanosplash instance from the stack.
260
+ * @param ns Nanosplash instance.
261
+ * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
262
+ */
263
+ stackDelete(t) {
264
+ let n = this.findIndex((r) => r.getId() === t.getId());
265
+ return n < 0 ? null : (this.nsStack.items.splice(n, 1), t.getId());
266
+ }
267
+ /**
268
+ * # Delete NS
269
+ * Remove Nanosplash instance from both the stack and the DOM.
270
+ * @param callback Callback function.
271
+ * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
272
+ */
273
+ deleteNS(t) {
274
+ const n = this.find(t);
275
+ return n ? (this.cleanAndRemove(n), this.stackDelete(n)) : null;
276
+ }
277
+ /**
278
+ * @inheritDoc
279
+ */
280
+ show(t) {
281
+ let n = m(document.body);
282
+ return n || (n = this.createNS(), u(n.getNSElement(), document.body)), n.setText(t || ""), n.getId();
283
+ }
284
+ /**
285
+ * @inheritDoc
286
+ */
287
+ showInside(t, n) {
288
+ const r = a(t);
289
+ if (r) {
290
+ let c = m(r);
291
+ return c || (c = this.createNS()), c.setText(n || ""), u(c.getNSElement(), r), c.getId();
292
+ }
293
+ return null;
294
+ }
295
+ /**
296
+ * @inheritDoc
297
+ */
298
+ hideAll() {
299
+ this.nsStack.items.forEach((t) => {
300
+ this.cleanAndRemove(t);
301
+ }), this.nsStack.clear();
302
+ }
303
+ /**
304
+ * @inheritDoc
305
+ */
306
+ hide() {
307
+ const t = this.nsStack.pop();
308
+ return t ? this.cleanAndRemove(t) : null;
309
+ }
310
+ /**
311
+ * @inheritDoc
312
+ */
313
+ hideId(t) {
314
+ return this.deleteNS((n) => n.getId() === t);
315
+ }
316
+ /**
317
+ * @inheritDoc
318
+ */
319
+ hideInside(t) {
320
+ const n = a(t), r = (c) => c.getNSElement().parentElement === n;
321
+ return n ? this.deleteNS(r) : null;
322
+ }
323
+ };
324
+ let d = s;
325
+ i(d, "WindowAccessorKey", "ns"), i(d, "instance");
326
+ try {
327
+ d.start();
328
+ } catch (e) {
329
+ console.warn(e);
330
+ }
@@ -0,0 +1,2 @@
1
+ var C=Object.defineProperty;var I=(r,o,c)=>o in r?C(r,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):r[o]=c;var i=(r,o,c)=>(I(r,typeof o!="symbol"?o+"":o,c),c);(function(){var r=document.createElement("style");r.textContent=`.ns,.ns-host:before{width:100%;height:100%}.ns,.ns-host:before{top:0;left:0}.ns-content,.ns{display:flex;justify-content:center;align-items:center}.ns-host{--text-color: DarkSlateGray;--font-size: 20px;--proportional-size: calc(var(--font-size) * .9);--font-family: "Helvetica", "Arial", sans-serif;--font-weight: 400;--background: rgba(255, 255, 255, .8);--z-index: 999999999;--blur-filter: blur(10px)}.ns-host{position:relative;z-index:var(--z-index)}.ns-host:before{position:absolute;background-color:var(--background);content:"";backdrop-filter:var(--blur-filter);-webkit-backdrop-filter:var(--blur-filter);z-index:calc(var(--z-index) + 1)}body.ns-host{height:100vh}.ns{position:absolute;z-index:calc(var(--z-index) + 2)}.ns-text{color:var(--text-color);font-size:var(--font-size);font-family:var(--font-family);font-weight:var(--font-weight);margin-right:var(--proportional-size)}.ns-spinner{display:block;width:var(--proportional-size);height:var(--proportional-size)}.ns-spinner>svg{animation:Rotate 2s linear infinite;position:relative;width:inherit;height:inherit;stroke-width:8}.ns-spinner .path{stroke:var(--text-color);stroke-linecap:round;animation:Dash 1.5s ease-in-out infinite}@keyframes Rotate{to{transform:rotate(360deg)}}@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
+ `,document.head.appendChild(r);const o="";function c(){return new DOMParser().parseFromString('<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>',"text/html").body.firstChild}function p(e,t){t.children.length>0?t.insertBefore(e,t.children.item(0)):t.append(e)}function u(e,t){e==null||e.classList[t](d.nsHostClassName)}function v(e){u(e.getNSElement().parentElement,"remove")}function y(e){e.style.display="flex"}function S(e){e.style.display="none"}function f(e){let t;if(typeof e=="string")t=document.querySelector(e);else{if(e instanceof Node)return e;if(typeof e=="function"){if(t=e(),!(t instanceof Node))return null}else t=null}return t}function k(e){var t;return(t=e==null?void 0:e.classList)==null?void 0:t.contains("ns")}function x(e,t){u(e.parentElement,"remove"),u(t,"add"),p(e,t)}function g(e){const t=f(e);if(!t)return null;const n=t.firstChild;if(n!==null&&k(n)){const b=n.id;return h.getInstance().nsStack.items.find(E=>E.getId()===b)??null}return null}function w(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}const m=class{constructor(){i(this,"id");i(this,"element");this.element=c(),this.element.id=this.id=w()}getId(){return this.id}getNSElement(){return this.element}getNSContentElement(){return this.getNSElement().firstElementChild}getNSTextElement(){return this.getNSContentElement().firstElementChild}hideText(){return S(this.getNSTextElement()),this}setText(t){return this.getNSTextElement().innerText=t,t.length>0?this.showText():this.hideText(),this}showText(){return y(this.getNSTextElement()),this}remove(){var t;this.element&&((t=this.element.parentElement)==null||t.removeChild(this.element),delete this.element)}};let d=m;i(d,"nsClassName","ns"),i(d,"nsHostClassName",m.nsClassName+"-host");class N{constructor(){i(this,"_items");this._items=[]}get items(){return this._items}push(t){this._items.push(t)}pop(){return this._items.pop()}peek(){return this._items[this._items.length-1]}isEmpty(){return this._items.length===0}size(){return this._items.length}clear(){this._items=[]}}const s=class{constructor(){i(this,"nsStack");this.nsStack=new N}findIndex(t){return this.nsStack.items.findIndex(t)}find(t){return this.nsStack.items.find(t)}static getInstance(){return s.instance||(s.instance=new s),s.instance}static assignToWindow(){Object.defineProperty(window,s.WindowAccessorKey,{value:s.getInstance(),writable:!1})}static start(){s.assignToWindow(),window.addEventListener("load",()=>{window[s.WindowAccessorKey]instanceof s||s.assignToWindow()})}createNS(t){const n=new d;return n.setText(t||""),this.nsStack.push(n),n}cleanAndRemove(t){return v(t),t.remove(),t.getId()}stackDelete(t){let n=this.findIndex(a=>a.getId()===t.getId());return n<0?null:(this.nsStack.items.splice(n,1),t.getId())}deleteNS(t){const n=this.find(t);return n?(this.cleanAndRemove(n),this.stackDelete(n)):null}show(t){let n=g(document.body);return n||(n=this.createNS(),x(n.getNSElement(),document.body)),n.setText(t||""),n.getId()}showInside(t,n){const a=f(t);if(a){let l=g(a);return l||(l=this.createNS()),l.setText(n||""),x(l.getNSElement(),a),l.getId()}return null}hideAll(){this.nsStack.items.forEach(t=>{this.cleanAndRemove(t)}),this.nsStack.clear()}hide(){const t=this.nsStack.pop();return t?this.cleanAndRemove(t):null}hideId(t){return this.deleteNS(n=>n.getId()===t)}hideInside(t){const n=f(t),a=l=>l.getNSElement().parentElement===n;return n?this.deleteNS(a):null}};let h=s;i(h,"WindowAccessorKey","ns"),i(h,"instance");try{h.start()}catch(e){console.warn(e)}})();