nanosplash 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +151 -17
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +555 -0
- package/coverage/core/Dom.ts.html +565 -0
- package/coverage/core/Service.ts.html +790 -0
- package/coverage/core/Splash.ts.html +457 -0
- package/coverage/core/index.html +146 -0
- package/coverage/coverage-final.json +9043 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/types/Types.ts.html +121 -0
- package/coverage/types/index.html +116 -0
- package/dist/latest/cjs/ns.cjs +1 -0
- package/dist/latest/cjs/style.css +1 -0
- package/dist/latest/es/ns.js +306 -0
- package/dist/latest/es/style.css +1 -0
- package/dist/latest/iife/ns.iife.js +4 -0
- package/dist/versioned/3.0.1/cjs/ns.cjs +1 -0
- package/dist/versioned/3.0.1/cjs/style.css +1 -0
- package/dist/versioned/3.0.1/es/ns.js +306 -0
- package/dist/versioned/3.0.1/es/style.css +1 -0
- package/dist/versioned/3.0.1/iife/ns.iife.js +2 -0
- package/docs/index.6d66a821.js +1 -0
- package/docs/index.74dbd99e.css +1 -0
- package/docs/index.f34144dc.js +1 -0
- package/docs/index.html +107 -0
- package/index.html +90 -37
- package/package.json +41 -20
- package/src/sass/ns.sass +38 -29
- package/src/ts/core/Dom.ts +160 -0
- package/src/ts/core/Service.ts +235 -0
- package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +17 -7
- package/src/ts/core/Splash.ts +124 -0
- package/src/ts/core/SplashInterface.ts +54 -0
- package/src/ts/main.ts +9 -0
- package/src/ts/types/Types.ts +12 -0
- package/src/ts/types/global.d.ts +14 -0
- package/src/vite-env.d.ts +0 -8
- package/tests/Dom.spec.ts +127 -0
- package/tests/Guid.spec.ts +2 -2
- package/tests/{NanosplashService.spec.ts → Service.spec.ts} +18 -18
- package/tests/{Nanosplash.spec.ts → Splash.spec.ts} +9 -9
- package/tsconfig.json +20 -20
- package/vite.config.ts +28 -22
- package/vite.demo.config.ts +16 -0
- package/dist/main.css +0 -1
- package/dist/ns.cjs.js +0 -1
- package/dist/ns.es.js +0 -330
- package/dist/ns.iife.js +0 -2
- package/src/main.ts +0 -8
- package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
- package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
- package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
- package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
- package/src/ts/types/Alias.d.ts +0 -1
- package/src/ts/types/Nanosplash.d.ts +0 -18
- package/src/ts/types/NanosplashService.d.ts +0 -1
- package/src/ts/util/Guid.ts +0 -13
- package/src/ts/util/Stack.ts +0 -73
- package/tests/NanosplashRepository.spec.ts +0 -91
- package/tests/Stack.spec.ts +0 -56
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// @ts-strict
|
|
2
2
|
|
|
3
3
|
import { JSDOM } from 'jsdom'
|
|
4
|
-
import { beforeEach,
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { getRecycledNS } from '../src/ts/core/Nanosplash/repositories/NanosplashRepository'
|
|
4
|
+
import { beforeEach, expect, describe, it } from 'vitest'
|
|
5
|
+
import { getRecycledNS } from '../src/ts/core/Dom'
|
|
6
|
+
import { Service } from '../src/ts/core/Service'
|
|
7
|
+
import { Splash } from '../src/ts/core/Splash'
|
|
9
8
|
|
|
10
9
|
describe('NanosplashService', () => {
|
|
11
|
-
const nss =
|
|
12
|
-
const getById = (id:
|
|
13
|
-
nss.nsStack.
|
|
10
|
+
const nss = Service.getInstance()
|
|
11
|
+
const getById = (id: string): Splash | undefined =>
|
|
12
|
+
nss.nsStack.find((ns: Splash) => ns.getId() === id)
|
|
14
13
|
|
|
15
14
|
// Reset the DOM before each test
|
|
16
15
|
beforeEach(() => {
|
|
@@ -20,34 +19,35 @@ describe('NanosplashService', () => {
|
|
|
20
19
|
globalThis.document = dom.window.document
|
|
21
20
|
globalThis.DOMParser = dom.window.DOMParser
|
|
22
21
|
globalThis.Node = dom.window.Node
|
|
22
|
+
globalThis.Element = dom.window.Element
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
it('Should be able to create an instance', () => {
|
|
26
|
-
expect(nss).toBeInstanceOf(
|
|
26
|
+
expect(nss).toBeInstanceOf(Service)
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
it('Should be able to get the same singleton instance', () => {
|
|
30
|
-
const nss1 =
|
|
31
|
-
const nss2 =
|
|
30
|
+
const nss1 = Service.getInstance()
|
|
31
|
+
const nss2 = Service.getInstance()
|
|
32
32
|
expect(nss1).toBe(nss2)
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
it('Should be able to start the service', () => {
|
|
36
|
-
|
|
37
|
-
expect(
|
|
36
|
+
Service.start()
|
|
37
|
+
expect(nss).toBeInstanceOf(Service)
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
it('Should be able to retrieve an existing Nanosplash instance from a destination node', () => {
|
|
41
41
|
const destinationNode = document.createElement('div')
|
|
42
42
|
document.body.appendChild(destinationNode)
|
|
43
43
|
destinationNode.id = 'test-id'
|
|
44
|
-
const nsInstance1 = getRecycledNS(destinationNode) as
|
|
44
|
+
const nsInstance1 = getRecycledNS(destinationNode) as Splash
|
|
45
45
|
expect(nsInstance1).toBeNull()
|
|
46
46
|
let nsId = nss.showInside('erroneous-selector', 'Hello World!')
|
|
47
47
|
expect(nsId).toBeNull()
|
|
48
48
|
nsId = nss.showInside('div[id="test-id"]', 'Hello World!')
|
|
49
49
|
const nsInstance2 = getRecycledNS(destinationNode)
|
|
50
|
-
expect(nsInstance2).toBeInstanceOf(
|
|
50
|
+
expect(nsInstance2).toBeInstanceOf(Splash)
|
|
51
51
|
expect(nsInstance2?.getId()).toBe(nsId)
|
|
52
52
|
})
|
|
53
53
|
|
|
@@ -89,13 +89,13 @@ describe('NanosplashService', () => {
|
|
|
89
89
|
}
|
|
90
90
|
document.body.append(div('a'), div('b'), div('c'))
|
|
91
91
|
nss.hideAll()
|
|
92
|
-
expect(nss.nsStack.
|
|
92
|
+
expect(nss.nsStack.length).toBe(0)
|
|
93
93
|
nss.showInside('#a', 'A')
|
|
94
94
|
nss.showInside('#b', 'B')
|
|
95
95
|
nss.showInside('#c', 'C')
|
|
96
|
-
expect(nss.nsStack.
|
|
96
|
+
expect(nss.nsStack.length).toBe(3)
|
|
97
97
|
nss.hideAll()
|
|
98
|
-
expect(nss.nsStack.
|
|
98
|
+
expect(nss.nsStack.length).toBe(0)
|
|
99
99
|
})
|
|
100
100
|
|
|
101
101
|
it('Should be able to hide a Nanosplash based on its ID', () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @ts-strict
|
|
2
2
|
|
|
3
3
|
import { describe, it, expect, beforeEach } from 'vitest'
|
|
4
|
-
import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
|
|
5
4
|
import { JSDOM } from 'jsdom'
|
|
5
|
+
import { Splash } from '../src/ts/core/Splash'
|
|
6
6
|
|
|
7
|
-
describe('
|
|
7
|
+
describe('Splash', () => {
|
|
8
8
|
// Reset the DOM before each test
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
const dom = new JSDOM()
|
|
@@ -14,13 +14,13 @@ describe('Nanosplash', () => {
|
|
|
14
14
|
globalThis.DOMParser = dom.window.DOMParser
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
it('Should be a valid
|
|
18
|
-
const ns = new
|
|
17
|
+
it('Should be a valid Splash', () => {
|
|
18
|
+
const ns = new Splash()
|
|
19
19
|
const element = ns.getNSElement()
|
|
20
20
|
|
|
21
21
|
expect(element).not.toBeUndefined()
|
|
22
22
|
expect(element.id).toBe(ns.getId())
|
|
23
|
-
expect(element.classList.contains(
|
|
23
|
+
expect(element.classList.contains(Splash.NSClass)).toBe(true)
|
|
24
24
|
|
|
25
25
|
const contentElement = ns.getNSContentElement()
|
|
26
26
|
expect(contentElement).not.toBeUndefined()
|
|
@@ -36,20 +36,20 @@ describe('Nanosplash', () => {
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
it('Should be able to set text', () => {
|
|
39
|
-
const ns = new
|
|
39
|
+
const ns = new Splash()
|
|
40
40
|
const text = 'Hello World!'
|
|
41
41
|
ns.setText(text)
|
|
42
42
|
expect(ns.getNSTextElement().innerText).toBe(text)
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
it('Should be able to hide text', () => {
|
|
46
|
-
const ns = new
|
|
46
|
+
const ns = new Splash()
|
|
47
47
|
ns.hideText()
|
|
48
48
|
expect(ns.getNSTextElement().style.display).toBe('none')
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
it('Should be able to show text', () => {
|
|
52
|
-
const ns = new
|
|
52
|
+
const ns = new Splash()
|
|
53
53
|
ns.setText('Hello World!')
|
|
54
54
|
ns.hideText()
|
|
55
55
|
ns.showText()
|
|
@@ -57,7 +57,7 @@ describe('Nanosplash', () => {
|
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
it('Should be able to remove itself from DOM', () => {
|
|
60
|
-
const ns = new
|
|
60
|
+
const ns = new Splash()
|
|
61
61
|
ns.remove()
|
|
62
62
|
expect(ns.getNSElement()).toBeUndefined()
|
|
63
63
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM"],
|
|
7
|
+
"moduleResolution": "Node",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationDir": "dist/types",
|
|
19
|
+
"types": ["vite/client"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/ts/**/*.ts"]
|
|
22
22
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
1
|
+
import { LibraryFormats, defineConfig } from 'vite'
|
|
2
|
+
import { version } from './package.json'
|
|
3
|
+
import { resolve } from 'path'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
const dist = 'dist'
|
|
6
|
+
const versioned = process.env?.versioned ?? false
|
|
7
|
+
const format = (process.env?.format ?? '') as LibraryFormats
|
|
8
|
+
const entry = (process.env?.entry ?? '') as string
|
|
9
|
+
|
|
10
|
+
const outDirFolders = [dist]
|
|
11
|
+
if (versioned) {
|
|
12
|
+
outDirFolders.push('versioned', version, format)
|
|
13
|
+
} else {
|
|
14
|
+
outDirFolders.push('latest', format)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const outDir = resolve(__dirname, ...outDirFolders)
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
build: {
|
|
21
|
+
outDir,
|
|
22
|
+
lib: {
|
|
23
|
+
entry,
|
|
24
|
+
name: 'Nanosplash',
|
|
25
|
+
formats: [format] as LibraryFormats[],
|
|
26
|
+
fileName: 'ns',
|
|
27
|
+
},
|
|
28
|
+
cssCodeSplit: format === 'iife',
|
|
29
|
+
},
|
|
24
30
|
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
export default defineConfig(() => ({
|
|
4
|
+
base: 'nanosplash',
|
|
5
|
+
build: {
|
|
6
|
+
outDir: 'docs',
|
|
7
|
+
rollupOptions: {
|
|
8
|
+
input: 'index.html',
|
|
9
|
+
output: {
|
|
10
|
+
entryFileNames: '[name].[hash].js',
|
|
11
|
+
chunkFileNames: '[name].[hash].js',
|
|
12
|
+
assetFileNames: '[name].[hash].[ext]',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}))
|
package/dist/main.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/ns.iife.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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)}})();
|