nanosplash 2.5.2 → 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.
- package/.github/workflows/ci.yml +48 -0
- package/.prettierrc +10 -9
- package/README.md +22 -89
- package/dist/main.css +1 -0
- package/dist/ns.cjs.js +1 -0
- package/dist/ns.es.js +330 -0
- package/dist/ns.iife.js +2 -0
- package/index.html +41 -122
- package/package.json +27 -34
- package/src/main.ts +8 -5
- package/src/sass/ns.sass +86 -0
- package/src/ts/core/Nanosplash/Nanosplash.ts +97 -0
- package/src/ts/core/Nanosplash/interfaces/NanosplashAPI.ts +50 -0
- package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +42 -0
- package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +178 -0
- package/src/ts/core/Nanosplash/services/NanosplashService.ts +222 -0
- package/src/ts/types/Alias.d.ts +1 -0
- package/src/ts/types/Nanosplash.d.ts +18 -0
- package/src/ts/types/NanosplashService.d.ts +1 -0
- package/src/ts/util/Guid.ts +13 -0
- package/src/ts/util/Stack.ts +73 -0
- package/src/vite-env.d.ts +8 -0
- package/tests/Guid.spec.ts +21 -0
- package/tests/Nanosplash.spec.ts +64 -0
- package/tests/NanosplashRepository.spec.ts +91 -0
- package/tests/NanosplashService.spec.ts +119 -0
- package/tests/Stack.spec.ts +56 -0
- package/tsconfig.json +9 -5
- package/vite.config.ts +22 -14
- package/.github/workflows/production.yml +0 -60
- package/.github/workflows/release.yml +0 -61
- package/LICENSE +0 -21
- package/_config.yml +0 -1
- package/dist/iife/manifest.json +0 -7
- package/dist/iife/nanosplash.iife.js +0 -1
- package/dist/module/manifest.json +0 -7
- package/dist/module/nanosplash.cjs.js +0 -1
- package/dist/module/nanosplash.es.js +0 -371
- package/dist/module/style.css +0 -1
- package/docs/index.html +0 -131
- package/docs/nanosplash.iife.js +0 -6
- package/docs/style.css +0 -1
- package/docs/typedoc/.nojekyll +0 -1
- package/docs/typedoc/assets/highlight.css +0 -22
- package/docs/typedoc/assets/icons.css +0 -1043
- package/docs/typedoc/assets/icons.png +0 -0
- package/docs/typedoc/assets/icons@2x.png +0 -0
- package/docs/typedoc/assets/main.js +0 -52
- package/docs/typedoc/assets/search.js +0 -1
- package/docs/typedoc/assets/style.css +0 -1414
- package/docs/typedoc/assets/widgets.png +0 -0
- package/docs/typedoc/assets/widgets@2x.png +0 -0
- package/docs/typedoc/classes/Core_Nanosplash.default.html +0 -133
- package/docs/typedoc/index.html +0 -1
- package/docs/typedoc/modules/Core_Nanosplash.html +0 -1
- package/docs/typedoc/modules/types.html +0 -1
- package/favicon.svg +0 -15
- package/postcss.config.js +0 -8
- package/src/Core/Nanosplash.ts +0 -257
- package/src/Core/SplashInstance.ts +0 -298
- package/src/Exceptions/DestinationException.ts +0 -13
- package/src/Exceptions/Exception.ts +0 -9
- package/src/Exceptions/IllegalArgumentException.ts +0 -11
- package/src/Factory/NanosplashFactory.ts +0 -93
- package/src/Interfaces/ContextualAPIInterface.ts +0 -8
- package/src/Interfaces/IdentityInterface.ts +0 -3
- package/src/Interfaces/InsideInterface.ts +0 -5
- package/src/Interfaces/NanosplashInterface.ts +0 -8
- package/src/Interfaces/ProgressInterface.ts +0 -5
- package/src/Interfaces/ShowInterface.ts +0 -5
- package/src/Interfaces/WhileInterface.ts +0 -5
- package/src/Repositories/NanosplashRepository.ts +0 -82
- package/src/Tests/dom.spec.ts +0 -72
- package/src/Utilities/dom.ts +0 -49
- package/src/style.sass +0 -88
- package/src/types.d.ts +0 -59
- package/update-all.sh +0 -3
- package/vite.iife.config.js +0 -72
- package/vite.mod.config.js +0 -71
- package/vite.site.config.js +0 -22
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @ts-strict
|
|
2
|
+
|
|
3
|
+
import { JSDOM } from 'jsdom'
|
|
4
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
5
|
+
import NanosplashService from '../src/ts/core/Nanosplash/services/NanosplashService'
|
|
6
|
+
import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
|
|
7
|
+
import { GUIDString } from '../src/ts/types/Alias'
|
|
8
|
+
import { getRecycledNS } from '../src/ts/core/Nanosplash/repositories/NanosplashRepository'
|
|
9
|
+
|
|
10
|
+
describe('NanosplashService', () => {
|
|
11
|
+
const nss = NanosplashService.getInstance()
|
|
12
|
+
const getById = (id: GUIDString): Nanosplash | undefined =>
|
|
13
|
+
nss.nsStack.items.find((ns: Nanosplash) => ns.getId() === id)
|
|
14
|
+
|
|
15
|
+
// Reset the DOM before each test
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
const dom = new JSDOM()
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
globalThis.window = dom.window
|
|
20
|
+
globalThis.document = dom.window.document
|
|
21
|
+
globalThis.DOMParser = dom.window.DOMParser
|
|
22
|
+
globalThis.Node = dom.window.Node
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('Should be able to create an instance', () => {
|
|
26
|
+
expect(nss).toBeInstanceOf(NanosplashService)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('Should be able to get the same singleton instance', () => {
|
|
30
|
+
const nss1 = NanosplashService.getInstance()
|
|
31
|
+
const nss2 = NanosplashService.getInstance()
|
|
32
|
+
expect(nss1).toBe(nss2)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('Should be able to start the service', () => {
|
|
36
|
+
NanosplashService.start()
|
|
37
|
+
expect(window.ns).toBeInstanceOf(NanosplashService)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('Should be able to retrieve an existing Nanosplash instance from a destination node', () => {
|
|
41
|
+
const destinationNode = document.createElement('div')
|
|
42
|
+
document.body.appendChild(destinationNode)
|
|
43
|
+
destinationNode.id = 'test-id'
|
|
44
|
+
const nsInstance1 = getRecycledNS(destinationNode) as Nanosplash
|
|
45
|
+
expect(nsInstance1).toBeNull()
|
|
46
|
+
let nsId = nss.showInside('erroneous-selector', 'Hello World!')
|
|
47
|
+
expect(nsId).toBeNull()
|
|
48
|
+
nsId = nss.showInside('div[id="test-id"]', 'Hello World!')
|
|
49
|
+
const nsInstance2 = getRecycledNS(destinationNode)
|
|
50
|
+
expect(nsInstance2).toBeInstanceOf(Nanosplash)
|
|
51
|
+
expect(nsInstance2?.getId()).toBe(nsId)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('Should be able to show a Nanosplash in the browser window', () => {
|
|
55
|
+
const text = 'Hello World!'
|
|
56
|
+
const nsId = nss.show(text)
|
|
57
|
+
const element = document.getElementById(nsId)
|
|
58
|
+
const ns = getById(nsId)
|
|
59
|
+
const nsText = ns?.getNSTextElement().innerText
|
|
60
|
+
expect(element).toBe(ns?.getNSElement())
|
|
61
|
+
expect(nsText).toBe(text)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Should be able to show a Nanosplash over a given element', () => {
|
|
65
|
+
const text = 'Hello World!'
|
|
66
|
+
const destination = document.createElement('div')
|
|
67
|
+
destination.id = 'test-id'
|
|
68
|
+
document.body.appendChild(destination)
|
|
69
|
+
const nsId = <string>nss.showInside('#test-id', text)
|
|
70
|
+
const element = document.getElementById(nsId)
|
|
71
|
+
const ns = getById(nsId)
|
|
72
|
+
const nsText = ns?.getNSTextElement().innerText
|
|
73
|
+
expect(element).toBe(ns?.getNSElement())
|
|
74
|
+
expect(nsText).toBe(text)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('Should be able to hide a Nanosplash', () => {
|
|
78
|
+
const nsId = nss.show()
|
|
79
|
+
nss.hide()
|
|
80
|
+
const ns = getById(nsId)
|
|
81
|
+
expect(ns?.getNSElement()).toBeUndefined()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('Should be able to hide all Nanosplashes', () => {
|
|
85
|
+
const div = (id: string) => {
|
|
86
|
+
const d = document.createElement('div')
|
|
87
|
+
d.id = id
|
|
88
|
+
return d
|
|
89
|
+
}
|
|
90
|
+
document.body.append(div('a'), div('b'), div('c'))
|
|
91
|
+
nss.hideAll()
|
|
92
|
+
expect(nss.nsStack.items.length).toBe(0)
|
|
93
|
+
nss.showInside('#a', 'A')
|
|
94
|
+
nss.showInside('#b', 'B')
|
|
95
|
+
nss.showInside('#c', 'C')
|
|
96
|
+
expect(nss.nsStack.items.length).toBe(3)
|
|
97
|
+
nss.hideAll()
|
|
98
|
+
expect(nss.nsStack.items.length).toBe(0)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('Should be able to hide a Nanosplash based on its ID', () => {
|
|
102
|
+
const nsId = nss.show()
|
|
103
|
+
nss.hideId(nsId)
|
|
104
|
+
const ns = getById(nsId)
|
|
105
|
+
expect(ns?.getNSElement()).toBeUndefined()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('Should be able to hide a Nanosplash residing inside a given element', () => {
|
|
109
|
+
const destination = document.createElement('div')
|
|
110
|
+
destination.id = 'test-id'
|
|
111
|
+
document.body.appendChild(destination)
|
|
112
|
+
let nsId = nss.showInside('#test-id')
|
|
113
|
+
nsId = nss.hideInside('erroneous-selector')
|
|
114
|
+
expect(nsId).toBeNull()
|
|
115
|
+
nsId = <string>nss.hideInside('#test-id')
|
|
116
|
+
const ns = getById(nsId)
|
|
117
|
+
expect(ns?.getNSElement()).toBeUndefined()
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-strict
|
|
2
|
+
|
|
3
|
+
import { it, expect, describe } from 'vitest'
|
|
4
|
+
import Stack from '../src/ts/util/Stack'
|
|
5
|
+
|
|
6
|
+
describe('Stack', () => {
|
|
7
|
+
it('Should add items to the stack', () => {
|
|
8
|
+
const stack = new Stack<number>()
|
|
9
|
+
stack.push(1)
|
|
10
|
+
stack.push(2)
|
|
11
|
+
stack.push(3)
|
|
12
|
+
expect(stack.size()).toBe(3)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('Should remove and return the item at the top of the stack', () => {
|
|
16
|
+
const stack = new Stack<string>()
|
|
17
|
+
stack.push('a')
|
|
18
|
+
stack.push('b')
|
|
19
|
+
stack.push('c')
|
|
20
|
+
const item = stack.pop()
|
|
21
|
+
expect(item).toBe('c')
|
|
22
|
+
expect(stack.size()).toBe(2)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('Should return the item at the top of the stack without removing it', () => {
|
|
26
|
+
const stack = new Stack<number>()
|
|
27
|
+
stack.push(1)
|
|
28
|
+
stack.push(2)
|
|
29
|
+
stack.push(3)
|
|
30
|
+
const topItem = stack.peek()
|
|
31
|
+
expect(topItem).toBe(3)
|
|
32
|
+
expect(stack.size()).toBe(3)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('Should return true if the stack is empty', () => {
|
|
36
|
+
const stack = new Stack<boolean>()
|
|
37
|
+
expect(stack.isEmpty()).toBe(true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('Should return the number of items in the stack', () => {
|
|
41
|
+
const stack = new Stack<string>()
|
|
42
|
+
stack.push('a')
|
|
43
|
+
stack.push('b')
|
|
44
|
+
stack.push('c')
|
|
45
|
+
expect(stack.size()).toBe(3)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('Should clear the stack', () => {
|
|
49
|
+
const stack = new Stack<number>()
|
|
50
|
+
stack.push(1)
|
|
51
|
+
stack.push(2)
|
|
52
|
+
stack.push(3)
|
|
53
|
+
stack.clear()
|
|
54
|
+
expect(stack.isEmpty()).toBe(true)
|
|
55
|
+
})
|
|
56
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
5
|
"module": "ESNext",
|
|
6
6
|
"lib": ["ESNext", "DOM"],
|
|
7
7
|
"moduleResolution": "Node",
|
|
8
8
|
"strict": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
9
|
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
11
|
"esModuleInterop": true,
|
|
12
|
+
"noEmit": true,
|
|
12
13
|
"noUnusedLocals": true,
|
|
13
14
|
"noUnusedParameters": true,
|
|
14
15
|
"noImplicitReturns": true,
|
|
15
|
-
"
|
|
16
|
+
"skipLibCheck": true
|
|
16
17
|
},
|
|
17
|
-
"include": [
|
|
18
|
+
"include": [
|
|
19
|
+
"src",
|
|
20
|
+
"tests"
|
|
21
|
+
]
|
|
18
22
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { defineConfig } from '
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
2
|
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
export default defineConfig(({ command, mode, ssrBuild }) => {
|
|
4
|
+
if (command === 'serve') {
|
|
5
|
+
return {
|
|
6
|
+
// dev specific config
|
|
7
|
+
}
|
|
8
|
+
} else {
|
|
9
|
+
// command === 'build'
|
|
10
|
+
return {
|
|
11
|
+
build: {
|
|
12
|
+
lib: {
|
|
13
|
+
entry: './src/main.ts',
|
|
14
|
+
name: 'Nanosplash',
|
|
15
|
+
formats: ['iife', 'es', 'cjs'],
|
|
16
|
+
fileName: module => {
|
|
17
|
+
return `ns.${module}.js`
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
cssCodeSplit: true,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
name: Production CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [production]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [production]
|
|
8
|
-
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Jest (TS) Testing Procedure
|
|
17
|
-
run: |
|
|
18
|
-
yarn install
|
|
19
|
-
yarn test
|
|
20
|
-
|
|
21
|
-
build:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v2
|
|
25
|
-
with:
|
|
26
|
-
fetch-depth: 0
|
|
27
|
-
|
|
28
|
-
# Checkout branch
|
|
29
|
-
- name: Checkout
|
|
30
|
-
run: |
|
|
31
|
-
git checkout production
|
|
32
|
-
git fetch
|
|
33
|
-
git pull origin
|
|
34
|
-
|
|
35
|
-
- name: Install npm packages
|
|
36
|
-
run: yarn install
|
|
37
|
-
|
|
38
|
-
- name: Transpile Typescript
|
|
39
|
-
run: yarn tsc
|
|
40
|
-
|
|
41
|
-
- name: Build IIFE bundle
|
|
42
|
-
run: yarn vite build -c vite.iife.config.js
|
|
43
|
-
|
|
44
|
-
- name: Build module bundles
|
|
45
|
-
run: yarn vite build -c vite.mod.config.js
|
|
46
|
-
|
|
47
|
-
- name: Build demo site
|
|
48
|
-
run: yarn vite build -c vite.site.config.js
|
|
49
|
-
|
|
50
|
-
- name: Build documentation site
|
|
51
|
-
run: yarn typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Nanosplash.ts src/types.d.ts
|
|
52
|
-
|
|
53
|
-
# Persist changes and push
|
|
54
|
-
- name: Commit changes and push
|
|
55
|
-
run: |
|
|
56
|
-
git config user.name github-actions
|
|
57
|
-
git config user.email github-actions@github.com
|
|
58
|
-
git add .
|
|
59
|
-
git commit -m "Github Actions CI: Build Project for Production"
|
|
60
|
-
git push
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
name: Release CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [release]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [release]
|
|
8
|
-
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Jest (TS) Testing Procedure
|
|
17
|
-
run: |
|
|
18
|
-
yarn install
|
|
19
|
-
yarn test
|
|
20
|
-
|
|
21
|
-
build:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v2
|
|
25
|
-
|
|
26
|
-
- name: Install npm packages
|
|
27
|
-
run: yarn install
|
|
28
|
-
|
|
29
|
-
- name: Transpile Typescript
|
|
30
|
-
run: yarn tsc
|
|
31
|
-
|
|
32
|
-
- name: Build IIFE bundle
|
|
33
|
-
run: yarn vite build -c vite.iife.config.js
|
|
34
|
-
|
|
35
|
-
- name: Build module bundles
|
|
36
|
-
run: yarn vite build -c vite.mod.config.js
|
|
37
|
-
|
|
38
|
-
- name: Build demo site
|
|
39
|
-
run: yarn vite build -c vite.site.config.js
|
|
40
|
-
|
|
41
|
-
- name: Build documentation site
|
|
42
|
-
run: yarn typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Nanosplash.ts src/types.d.ts
|
|
43
|
-
|
|
44
|
-
# Persist changes and push
|
|
45
|
-
- name: Commit changes and push
|
|
46
|
-
run: |
|
|
47
|
-
git config user.name github-actions
|
|
48
|
-
git config user.email github-actions@github.com
|
|
49
|
-
git add .
|
|
50
|
-
git commit -m "Github Actions CI: Build Project for Production"
|
|
51
|
-
git push origin release
|
|
52
|
-
|
|
53
|
-
# Publish to NPM
|
|
54
|
-
publish:
|
|
55
|
-
runs-on: ubuntu-latest
|
|
56
|
-
steps:
|
|
57
|
-
- uses: actions/checkout@v2
|
|
58
|
-
- name: Publish NPM package
|
|
59
|
-
run: npm publish --access public
|
|
60
|
-
env:
|
|
61
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTOMATION_TOKEN}}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Isak Hauge
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/_config.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
theme: jekyll-theme-architect
|
package/dist/iife/manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=document.createElement("style");t.innerHTML=".ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}\n",document.head.appendChild(t),function(){function t(t){return document.querySelector(t)}const s=t=>document.createElement(t);function e(t,...s){t.classList.add(...s)}function i(t,s,e){t.setAttribute(s,e)}class n extends Error{constructor(t,s){super(t),this.name=this.constructor.name,this.t=s}}class r extends n{constructor(t,s,e){super(t),this.destination=s,this.t=e}}class h extends n{constructor(t,s){super(t),this.i=s}}class o{static h(s){if("string"==typeof s)try{const e=t(s);if(!e)throw new n(`No DOM match with ${s}`);return e}catch(t){throw new r(`Destination (${s}) is either invalid or non-existing in DOM`,s,t)}else if(s instanceof Node)return s;throw new h(`Destination (${s}) must be either a Node or a CSS selector`,s)}static o(t){const s={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return{...s,inside:e=>(t.moveTo(e),s)}}static l(){const t=s("div");return e(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class a{constructor(t,e,i){var n;this.u=s("div"),this.m=s("div"),this.g=s("div"),this.p=o.l(),this.v=s("div"),this.k=s("div"),this.S=s("div"),this.D=s("img"),this.id=Math.random().toString(36).substring(2),this.I=t,this.m.innerText=e,this.N=i,this.D.src=null!=(n=this.N)?n:"",this.D.alt=u.F,this.u.style.fontSize=t.T(),this.p.style.display=t.A()?"flex":"none",this.M(),this.setImgSrc(i)}C(){e(this.S,"ns-container"),e(this.k,"ns-blur"),e(this.D,"ns-img"),e(this.m,"ns-text"),e(this.g,"ns-text-container"),e(this.p,"ns-spinner"),e(this.v,"ns","ns-window"),e(this.u,"ns-wrapper")}O(){this.g.append(this.m,this.p),this.S.append(this.D,this.g),this.v.append(this.S),this.u.append(this.k,this.v)}M(){this.u.id=this.getId(),i(this.u,"data-ctx","nanosplash"),this.O(),this.C()}getId(){return this.id}getText(){return this.m.innerText}setText(t){return this.m.innerText=t,this}getImgSrc(){return this.N}setImgSrc(t){return this.D.src=null!=t?t:"",this.D.style.display=t?"block":"none",this.O(),this}R(){return this.W}$(){const t=this.u.parentElement;t&&this.j(t)}B(){i(this.u,"style",""),this.u.classList.remove("ns-fs")}H(t){const s=t.parentNode;s&&(this.j(s),s.replaceChild(this.u,t),this.k.appendChild(t))}P(){this.u.classList.add("ns-fs"),((t,s,e=!1)=>{t&&s&&(s.hasChildNodes()&&e?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}V(t){this.I.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){try{this.$(),this.W=o.h(t),this.V(this.W),this.W===document.body?this.P():(this.B(),this.H(this.W)),this.M()}catch(t){this.delete(),this.I.debug&&console.warn(t)}}G(t){Array.from(this.k.childNodes).forEach(t)}j(t){this.G((s=>t.insertBefore(s,this.u)))}J(){[this.m,this.p,this.g,this.D,this.S,this.k,this.v,this.u].forEach((t=>t.remove()))}delete(){this.$(),this.J(),this.I.delete(this)}}class c{static K(t,s,e,i){var n;return t||(t=new a(s,e,i)),t.setText(e).setImgSrc(null!=(n=t.getImgSrc())?n:i)}static L(t,s){return e=>(s=c.K(s,t,e),t.U.set(s.getId(),s),s.moveTo(document.body),o.o(s))}static X(t,s){return(...e)=>((s=c.K(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[i,n]]of e.entries())s.setText(n),await i;s.delete()})(),o.o(s))}static Y(t,s){return e=>(s=c.K(s,t,""),{show:i=>(t.U.set(s.getId(),s),s.moveTo(document.body),s.setText(i),e.finally((()=>s.delete())),o.o(s))})}}const l=class{constructor(t){var s;this.debug=void 0===(null==t?void 0:t.debug)?l.Z:t._,this.N=null==t?void 0:t.N,this._=void 0===(null==t?void 0:t._)?l.tt:t._,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.U=new Map}setImgSrc(t){return this.N=t,this}st(t){return this._=t,this}et(t){return this.fontSize=t,this}getImgSrc(){return this.N}A(){return this._}T(){return this.fontSize}show(t){return c.L(this,new a(this,t,this.N))(t)}progress(...t){return c.X(this,new a(this,"",this.N))(...t)}while(t){return c.Y(this,new a(this,"",this.N))(t)}it(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){try{if(s){const e=s instanceof Node,i=t=>{Array.from(this.U.values()).filter((s=>s.R()===t)).forEach((t=>t.delete()))};if("string"==typeof s){const e=this.U.get(s);if(e)return void e.delete();{const e=t(s);throw e&&i(e),new n(`The CSS selector (${s}) points to a non-existing DOM element.`)}}if(!e)throw new h("The ref argument must be either a string or Node",s);i(s)}else{const t=this.U.size;this.it(((s,e,i)=>{const n=i===t-1;return n&&e.delete(),n}))}}catch(t){this.debug&&console.warn(t)}}q(t){return Array.from(this.U.values()).filter((s=>s.R()===t))}};let u=l;u.F="Nanosplash",u.tt=!0,u.Z=!0,window.addEventListener("load",(()=>{window.Nanosplash=u,window.ns=new u}))}();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t){return document.querySelector(t)}const s=t=>document.createElement(t);function i(t,...s){t.classList.add(...s)}function e(t,s,i){t.setAttribute(s,i)}class Exception extends Error{constructor(t,s){super(t),this.name=this.constructor.name,this.t=s}}class DestinationException extends Exception{constructor(t,s,i){super(t),this.destination=s,this.t=i}}class IllegalArgumentException extends Exception{constructor(t,s){super(t),this.i=s}}class NanosplashRepository{static h(s){if("string"==typeof s)try{const i=t(s);if(!i)throw new Exception(`No DOM match with ${s}`);return i}catch(t){throw new DestinationException(`Destination (${s}) is either invalid or non-existing in DOM`,s,t)}else if(s instanceof Node)return s;throw new IllegalArgumentException(`Destination (${s}) must be either a Node or a CSS selector`,s)}static o(t){const s={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return{...s,inside:i=>(t.moveTo(i),s)}}static l(){const t=s("div");return i(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class SplashInstance{constructor(t,i,e){var n;this.u=s("div"),this.p=s("div"),this.g=s("div"),this.m=NanosplashRepository.l(),this.S=s("div"),this.v=s("div"),this.N=s("div"),this.I=s("img"),this.id=Math.random().toString(36).substring(2),this.F=t,this.p.innerText=i,this.D=e,this.I.src=null!=(n=this.D)?n:"",this.I.alt=h.A,this.u.style.fontSize=t.getFontSize(),this.m.style.display=t.spinnerIsVisible()?"flex":"none",this.T(),this.setImgSrc(e)}R(){i(this.N,"ns-container"),i(this.v,"ns-blur"),i(this.I,"ns-img"),i(this.p,"ns-text"),i(this.g,"ns-text-container"),i(this.m,"ns-spinner"),i(this.S,"ns","ns-window"),i(this.u,"ns-wrapper")}M(){this.g.append(this.p,this.m),this.N.append(this.I,this.g),this.S.append(this.N),this.u.append(this.v,this.S)}T(){this.u.id=this.getId(),e(this.u,"data-ctx","nanosplash"),this.M(),this.R()}getId(){return this.id}getText(){return this.p.innerText}setText(t){return this.p.innerText=t,this}getImgSrc(){return this.D}setImgSrc(t){return this.I.src=null!=t?t:"",this.I.style.display=t?"block":"none",this.M(),this}getDestination(){return this.C}O(){const t=this.u.parentElement;t&&this.W(t)}$(){e(this.u,"style",""),this.u.classList.remove("ns-fs")}k(t){const s=t.parentNode;s&&(this.W(s),s.replaceChild(this.u,t),this.v.appendChild(t))}j(){this.u.classList.add("ns-fs"),((t,s,i=!1)=>{t&&s&&(s.hasChildNodes()&&i?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}B(t){this.F.getFromDestinationNode(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){try{this.O(),this.C=NanosplashRepository.h(t),this.B(this.C),this.C===document.body?this.j():(this.$(),this.k(this.C)),this.T()}catch(t){this.delete(),this.F.debug&&console.warn(t)}}H(t){Array.from(this.v.childNodes).forEach(t)}W(t){this.H((s=>t.insertBefore(s,this.u)))}P(){[this.p,this.m,this.g,this.I,this.N,this.v,this.S,this.u].forEach((t=>t.remove()))}delete(){this.O(),this.P(),this.F.delete(this)}}class NanosplashFactory{static V(t,s,i,e){var n;return t||(t=new SplashInstance(s,i,e)),t.setText(i).setImgSrc(null!=(n=t.getImgSrc())?n:e)}static q(t,s){return i=>(s=NanosplashFactory.V(s,t,i),t.G.set(s.getId(),s),s.moveTo(document.body),NanosplashRepository.o(s))}static J(t,s){return(...i)=>((s=NanosplashFactory.V(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[e,n]]of i.entries())s.setText(n),await e;s.delete()})(),NanosplashRepository.o(s))}static K(t,s){return i=>(s=NanosplashFactory.V(s,t,""),{show:e=>(t.G.set(s.getId(),s),s.moveTo(document.body),s.setText(e),i.finally((()=>s.delete())),NanosplashRepository.o(s))})}}const n=class{constructor(t){var s;this.debug=void 0===(null==t?void 0:t.debug)?n.L:t.U,this.D=null==t?void 0:t.D,this.U=void 0===(null==t?void 0:t.U)?n.X:t.U,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.G=new Map}setImgSrc(t){return this.D=t,this}showSpinner(t){return this.U=t,this}setFontSize(t){return this.fontSize=t,this}getImgSrc(){return this.D}spinnerIsVisible(){return this.U}getFontSize(){return this.fontSize}show(t){return NanosplashFactory.q(this,new SplashInstance(this,t,this.D))(t)}progress(...t){return NanosplashFactory.J(this,new SplashInstance(this,"",this.D))(...t)}while(t){return NanosplashFactory.K(this,new SplashInstance(this,"",this.D))(t)}Y(t){const s=this.G.size,i=Array.from(this.G.values());for(let e=s-1;e>=0;e--){const s=i[e];if(!t(s.getId(),s,e))break}}delete(t){this.G.delete(t.getId())}hideAll(){this.G.forEach((t=>t.delete()))}hide(s){try{if(s){const i=s instanceof Node,e=t=>{Array.from(this.G.values()).filter((s=>s.getDestination()===t)).forEach((t=>t.delete()))};if("string"==typeof s){const i=this.G.get(s);if(i)return void i.delete();{const i=t(s);throw i&&e(i),new Exception(`The CSS selector (${s}) points to a non-existing DOM element.`)}}if(!i)throw new IllegalArgumentException("The ref argument must be either a string or Node",s);e(s)}else{const t=this.G.size;this.Y(((s,i,e)=>{const n=e===t-1;return n&&i.delete(),n}))}}catch(t){this.debug&&console.warn(t)}}getFromDestinationNode(t){return Array.from(this.G.values()).filter((s=>s.getDestination()===t))}};let h=n;h.A="Nanosplash",h.X=!0,h.L=!0,module.exports=h;
|