nanosplash 3.0.9 → 3.1.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/.github/workflows/ci.yml +51 -49
- package/.github/workflows/vitepress.yml +52 -52
- package/README.md +74 -6
- package/dist/cjs/ns.cjs +1 -1
- package/dist/es/ns.js +41 -60
- package/dist/iife/ns.iife.js +1 -1
- package/docs/.vitepress/{config.mts → config.ts} +5 -1
- package/docs/.vitepress/theme/vue/Exe.vue +65 -61
- package/docs/api/doc/hide.md +2 -2
- package/docs/api/doc/show.md +2 -2
- package/docs/api/start/customize.md +30 -0
- package/docs/api/start/features.md +2 -2
- package/docs/api/start/install.md +6 -4
- package/docs/api/start/usage.md +2 -2
- package/docs/index.md +4 -4
- package/package.json +90 -91
- package/src/style/ns.sass +11 -16
- package/src/ts/Nanosplash.ts +69 -79
- package/src/ts/types/NanosplashInterface.ts +21 -2
- package/src/ts/types/Types.ts +2 -1
- package/tests/Nanosplash.spec.ts +11 -11
- package/bun.lockb +0 -0
package/docs/api/doc/show.md
CHANGED
|
@@ -32,11 +32,11 @@ ns.show(text?: string, ref?: Element | string): number | null
|
|
|
32
32
|
```js
|
|
33
33
|
// DOM selector
|
|
34
34
|
const selector: string = '#my-table'
|
|
35
|
-
ns.
|
|
35
|
+
ns.show('Loading', selector)
|
|
36
36
|
|
|
37
37
|
// Element
|
|
38
38
|
const element: HTMLElement = document.getElementById('my-table')
|
|
39
|
-
ns.
|
|
39
|
+
ns.show('Loading', element)
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
::: tip
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Customize
|
|
2
|
+
|
|
3
|
+
Styling Nanosplash to your needs is easy!
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
/* Backdrop */
|
|
7
|
+
.nsh::before {
|
|
8
|
+
background-color: var(--your-bg);
|
|
9
|
+
backdrop-filter: var(--your-filter);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* Main */
|
|
13
|
+
.ns {
|
|
14
|
+
gap: var(--text-spinner-gap);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* Text */
|
|
18
|
+
.nst {
|
|
19
|
+
color: var(--color);
|
|
20
|
+
font-size: var(--size);
|
|
21
|
+
font-family: var(--font);
|
|
22
|
+
font-weight: var(--weight);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Spinner */
|
|
26
|
+
.nss {
|
|
27
|
+
width: var(--spinner-width);
|
|
28
|
+
height: var(--spinner-height);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The Nanosplash bundle is less than 2KB minified and gzipped and will not add any significant weight to your application what so ever. Go to [Bundlephobia](https://bundlephobia.com/package/nanosplash) to see for yourself.
|
|
6
6
|
|
|
7
|
-
## Simple API
|
|
7
|
+
## Simple, 2 Function API
|
|
8
8
|
|
|
9
9
|
Nanosplash was written from the ground up with simplicity in mind. The API is very simple and easy to use, and you can easily get started in seconds. Just install the package and start using `ns.show` and `ns.hide`. Go to [Getting started](/api/start/install.md) to see how.
|
|
10
10
|
|
|
@@ -12,6 +12,6 @@ Nanosplash was written from the ground up with simplicity in mind. The API is ve
|
|
|
12
12
|
|
|
13
13
|
With Nanosplash you can spawn a splash element anywhere in your DOM. You can even spawn multiple splash elements if you want to. Go to the [API Documentation](/api/doc/show#show-inside) to see how.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Node recycling
|
|
16
16
|
|
|
17
17
|
Instead of creating new elements all the time and exhausting DOM manipulations, we recycle and repurpose obsolete splash elements instead. For each time a splash element is created, we check for existing splash elements inside the parent element and use them instead of creating new ones.
|
|
@@ -12,20 +12,22 @@ CSS is included inside the JS bundle. 🎉
|
|
|
12
12
|
|
|
13
13
|
## Install via CDN
|
|
14
14
|
|
|
15
|
-
Add the following script tag
|
|
15
|
+
Add the following script tag inside of the `<body>` tag:
|
|
16
16
|
|
|
17
17
|
```html
|
|
18
18
|
<script src="https://unpkg.com/nanosplash/dist/iife/ns.iife.js"></script>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
```html{
|
|
21
|
+
```html{7}
|
|
22
22
|
<html>
|
|
23
23
|
<head>
|
|
24
24
|
<meta charset="UTF-8" />
|
|
25
25
|
<title>My awesome application 🚀</title>
|
|
26
|
-
<script src="https://unpkg.com/nanosplash/dist/iife/ns.iife.js"></script>
|
|
27
26
|
</head>
|
|
28
|
-
|
|
27
|
+
<body>
|
|
28
|
+
<script src="https://unpkg.com/nanosplash/dist/iife/ns.iife.js"></script>
|
|
29
|
+
...
|
|
30
|
+
</body>
|
|
29
31
|
</html>
|
|
30
32
|
```
|
|
31
33
|
|
package/docs/api/start/usage.md
CHANGED
package/docs/index.md
CHANGED
|
@@ -18,16 +18,16 @@ hero:
|
|
|
18
18
|
link: /api/doc/show.md
|
|
19
19
|
|
|
20
20
|
features:
|
|
21
|
-
- title:
|
|
21
|
+
- title: ✨ Tiny
|
|
22
22
|
details: Less than 2KB minified and gzipped.
|
|
23
23
|
link: /api/start/features#small-bundle-size
|
|
24
|
-
- title:
|
|
24
|
+
- title: ✌️ 2 Function API
|
|
25
25
|
details: Start using Nanosplash in seconds.
|
|
26
26
|
link: /api/start/features#simple-api
|
|
27
|
-
- title:
|
|
27
|
+
- title: 🪴 Spawning
|
|
28
28
|
details: Spawn a splash element anywhere in your DOM.
|
|
29
29
|
link: /api/start/features#spawning
|
|
30
|
-
- title:
|
|
30
|
+
- title: 🚀 Node recycling
|
|
31
31
|
details: Nanosplash will recycle existing elements.
|
|
32
32
|
link: /api/start/features#element-recycling
|
|
33
33
|
---
|
package/package.json
CHANGED
|
@@ -1,92 +1,91 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
2
|
+
"name": "nanosplash",
|
|
3
|
+
"version": "3.1.1",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Isak K. Hauge",
|
|
6
|
+
"email": "isakhauge@icloud.com",
|
|
7
|
+
"url": "https://no.linkedin.com/in/isakhauge"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/isakhauge/nanosplash.git"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/es/ns.js",
|
|
14
|
+
"module": "./dist/es/ns.js",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/jsdom": "^21.1.6",
|
|
17
|
+
"@types/node": "^20.11.29",
|
|
18
|
+
"@types/rollup": "^0.54.0",
|
|
19
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
20
|
+
"@vitest/ui": "^1.4.0",
|
|
21
|
+
"cross-env": "^7.0.3",
|
|
22
|
+
"eslint": "^8.57.0",
|
|
23
|
+
"eslint-config-prettier": "^9.1.0",
|
|
24
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
25
|
+
"jsdom": "^24.0.0",
|
|
26
|
+
"sass": "^1.72.0",
|
|
27
|
+
"stylelint-prettier": "^5.0.0",
|
|
28
|
+
"typescript": "5.4.2",
|
|
29
|
+
"typescript-eslint": "^7.2.0",
|
|
30
|
+
"vite": "^5.1.6",
|
|
31
|
+
"vitepress": "",
|
|
32
|
+
"vitest": "^1.4.0"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": {
|
|
37
|
+
"require": "./src/ts/types/global.d.ts",
|
|
38
|
+
"default": "./src/ts/types/global.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"browser": {
|
|
41
|
+
"require": "./dist/cjs/ns.cjs",
|
|
42
|
+
"default": "./dist/es/ns.js"
|
|
43
|
+
},
|
|
44
|
+
"default": {
|
|
45
|
+
"require": "./dist/cjs/ns.cjs",
|
|
46
|
+
"default": "./dist/es/ns.js"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"description": "The tiny loading screen for web artisans",
|
|
51
|
+
"homepage": "https://isakhauge.github.io/nanosplash",
|
|
52
|
+
"keywords": [
|
|
53
|
+
"loading",
|
|
54
|
+
"loader",
|
|
55
|
+
"screen",
|
|
56
|
+
"splash",
|
|
57
|
+
"nano",
|
|
58
|
+
"nanosplash",
|
|
59
|
+
"small",
|
|
60
|
+
"tiny",
|
|
61
|
+
"es",
|
|
62
|
+
"esm",
|
|
63
|
+
"ts",
|
|
64
|
+
"typescript",
|
|
65
|
+
"iife",
|
|
66
|
+
"cdn",
|
|
67
|
+
"vite"
|
|
68
|
+
],
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"private": false,
|
|
71
|
+
"source": "./src/main.ts",
|
|
72
|
+
"type": "module",
|
|
73
|
+
"types": "./src/ts/types/global.d.ts",
|
|
74
|
+
"unpkg": "./dist/iife/ns.iife.js",
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "pnpm build:all && pnpm build:docs",
|
|
77
|
+
"build:es": "tsc && cross-env entry=./src/ts/Nanosplash.ts format=es vite build -m production --c vite.config.ts",
|
|
78
|
+
"build:cjs": "tsc && cross-env entry=./src/ts/Nanosplash.ts format=cjs vite build -m production --c vite.config.ts",
|
|
79
|
+
"build:iife": "tsc && cross-env entry=./src/ts/main.ts format=iife vite build -m production --c vite.config.ts",
|
|
80
|
+
"build:all": "pnpm build:es && pnpm build:cjs && pnpm build:iife",
|
|
81
|
+
"build:docs": "pnpm docs:build",
|
|
82
|
+
"preview": "vite preview",
|
|
83
|
+
"test": "vitest",
|
|
84
|
+
"test:ui": "vitest --ui",
|
|
85
|
+
"lint": "eslint src/ts/**/*.ts --fix",
|
|
86
|
+
"coverage": "vitest --coverage",
|
|
87
|
+
"docs:dev": "pnpm exec vitepress dev docs",
|
|
88
|
+
"docs:build": "pnpm exec vitepress build docs",
|
|
89
|
+
"docs:preview": "pnpm exec vitepress preview docs"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/style/ns.sass
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Spinner animations:
|
|
2
|
-
@keyframes
|
|
2
|
+
@keyframes nsRotate
|
|
3
3
|
100%
|
|
4
4
|
transform: rotate(360deg)
|
|
5
5
|
|
|
6
|
-
@keyframes
|
|
6
|
+
@keyframes nsDash
|
|
7
7
|
0%
|
|
8
8
|
stroke-dasharray: 1, 150
|
|
9
9
|
stroke-dashoffset: 0
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
stroke-dasharray: 90, 150
|
|
15
15
|
stroke-dashoffset: -124
|
|
16
16
|
|
|
17
|
-
@keyframes
|
|
17
|
+
@keyframes nsFade
|
|
18
18
|
from
|
|
19
19
|
opacity: 0
|
|
20
20
|
to
|
|
21
21
|
opacity: 1
|
|
22
22
|
|
|
23
|
-
@keyframes
|
|
23
|
+
@keyframes nsAscend
|
|
24
24
|
from
|
|
25
25
|
opacity: 0
|
|
26
26
|
transform: translateY(13px)
|
|
@@ -85,12 +85,8 @@ body.nsh
|
|
|
85
85
|
@extend %flex-center-xy
|
|
86
86
|
position: absolute
|
|
87
87
|
z-index: calc(var(--zIdx) + 2)
|
|
88
|
-
animation:
|
|
89
|
-
|
|
90
|
-
// Nanosplash container
|
|
91
|
-
.nsc
|
|
92
|
-
@extend %flex-center-xy
|
|
93
|
-
filter: drop-shadow(0 0 0.07rem #{ rgba(Black, 0.25) })
|
|
88
|
+
animation: nsFade 2s
|
|
89
|
+
gap: var(--relSize)
|
|
94
90
|
|
|
95
91
|
// Nanosplash text
|
|
96
92
|
.nst
|
|
@@ -98,23 +94,22 @@ body.nsh
|
|
|
98
94
|
font-size: var(--size)
|
|
99
95
|
font-family: var(--font)
|
|
100
96
|
font-weight: var(--weight)
|
|
101
|
-
font-optical-sizing: auto
|
|
102
97
|
max-width: 80dvw
|
|
103
98
|
white-space: nowrap
|
|
104
99
|
text-overflow: ellipsis
|
|
105
100
|
overflow: hidden
|
|
106
|
-
margin-right: var(--relSize)
|
|
107
101
|
text-shadow: 0 0 0.06rem #{ rgba(DarkSlateGray, .25) }
|
|
108
|
-
|
|
102
|
+
filter: drop-shadow(0 0 0.07rem #{ rgba(Black, 0.25) })
|
|
103
|
+
animation: nsAscend 0.5s
|
|
109
104
|
|
|
110
105
|
// Nanosplash spinner
|
|
111
106
|
.nss
|
|
112
107
|
display: block
|
|
113
108
|
width: var(--relSize)
|
|
114
109
|
height: var(--relSize)
|
|
115
|
-
animation:
|
|
110
|
+
animation: nsAscend 0.5s
|
|
116
111
|
& > svg
|
|
117
|
-
animation:
|
|
112
|
+
animation: nsRotate 2s linear infinite
|
|
118
113
|
position: relative
|
|
119
114
|
width: inherit
|
|
120
115
|
height: inherit
|
|
@@ -122,4 +117,4 @@ body.nsh
|
|
|
122
117
|
& .path
|
|
123
118
|
stroke: var(--color)
|
|
124
119
|
stroke-linecap: round
|
|
125
|
-
animation:
|
|
120
|
+
animation: nsDash 1.5s ease-in-out infinite
|
package/src/ts/Nanosplash.ts
CHANGED
|
@@ -9,29 +9,29 @@ import {
|
|
|
9
9
|
} from './types/Types'
|
|
10
10
|
import { version } from '../../package.json'
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const styleId: string = 'ns'
|
|
13
|
+
const doc: Document = document
|
|
14
|
+
const bod: HTMLElement = doc.body
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
17
|
+
* # Scope
|
|
18
|
+
* Creates scoped selectors.
|
|
16
19
|
* @param node Node to query.
|
|
17
20
|
* @returns An object containing two, slightly different functions that
|
|
18
21
|
* retrieves elements from the DOM.
|
|
19
22
|
*/
|
|
20
|
-
const scope = (node: ParentNode): ScopedSelectors =>
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
+
const scope = (node: ParentNode): ScopedSelectors =>
|
|
24
|
+
(all => ({
|
|
23
25
|
all,
|
|
24
26
|
first: (ref: string) => all(ref)[0] ?? null,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
+
}))((ref: string) => Array.from(node.querySelectorAll(ref)))
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* # Get all
|
|
30
31
|
* @param selector CSS selector used to match nodes in the DOM.
|
|
31
32
|
* @returns An array of Element nodes.
|
|
32
33
|
*/
|
|
33
|
-
const getAll = (selector: DOMSelector): Element[] =>
|
|
34
|
-
scope(document).all(selector)
|
|
34
|
+
const getAll = (selector: DOMSelector): Element[] => scope(doc).all(selector)
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* # Get
|
|
@@ -39,28 +39,24 @@ const getAll = (selector: DOMSelector): Element[] =>
|
|
|
39
39
|
* @returns Firs Element node from the DOM matching the selector.
|
|
40
40
|
*/
|
|
41
41
|
const get = (selector: DOMSelector): Element | null =>
|
|
42
|
-
scope(
|
|
42
|
+
scope(doc).first(selector)
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* # Get All
|
|
45
|
+
* # Get All Nanosplashes
|
|
46
46
|
* @returns An array of all Nanosplash elements in the DOM.
|
|
47
47
|
*/
|
|
48
|
-
const
|
|
48
|
+
const getAllNs = (): NSElement[] => getAll('.ns') as NSElement[]
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* # Parse Ref
|
|
52
52
|
* @param ref Element reference which could be a selector or an Element.
|
|
53
53
|
* @returns The Element node or null.
|
|
54
54
|
*/
|
|
55
|
-
const parseRef = (ref: ElementReference): Element =>
|
|
56
|
-
|
|
57
|
-
const element = get(ref)
|
|
58
|
-
if (!element) throw new Error(`Selector (${ref}) returned null`)
|
|
59
|
-
return element
|
|
60
|
-
}
|
|
55
|
+
const parseRef = (ref: ElementReference): Element | null =>
|
|
56
|
+
ref instanceof Element ? ref : get(ref)
|
|
61
57
|
|
|
62
58
|
/**
|
|
63
|
-
* #
|
|
59
|
+
* # Create HTMLDivElement
|
|
64
60
|
* @param className Optional string containing class names.
|
|
65
61
|
* @param children Optional list of Nodes or strings.
|
|
66
62
|
* @returns The newly created HTMLDivElement.
|
|
@@ -69,10 +65,10 @@ const div = (
|
|
|
69
65
|
className?: string,
|
|
70
66
|
...children: (Node | string)[]
|
|
71
67
|
): HTMLDivElement => {
|
|
72
|
-
const
|
|
73
|
-
if (className)
|
|
74
|
-
|
|
75
|
-
return
|
|
68
|
+
const node: HTMLDivElement = doc.createElement('div')
|
|
69
|
+
if (className) node.classList.add(className)
|
|
70
|
+
node.append(...children)
|
|
71
|
+
return node
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
/**
|
|
@@ -81,60 +77,57 @@ const div = (
|
|
|
81
77
|
* @returns Parsed node.
|
|
82
78
|
*/
|
|
83
79
|
const parse = (html: string): Node => {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
return
|
|
80
|
+
const node: HTMLDivElement = div()
|
|
81
|
+
node.innerHTML = html
|
|
82
|
+
return node.firstChild as Node
|
|
87
83
|
}
|
|
88
84
|
|
|
89
85
|
/**
|
|
90
|
-
* #
|
|
91
|
-
* TODO: Investigate the possibility of inheritence.
|
|
86
|
+
* # Make Nanosplash Element
|
|
92
87
|
* @returns Nanpslash DOM element.
|
|
93
88
|
*/
|
|
94
|
-
const
|
|
89
|
+
const makeNs = (): NSElement => {
|
|
95
90
|
const circle: string = '<circle class=path cx=25 cy=25 r=20 fill=none />'
|
|
96
91
|
const svg = parse(`<svg viewBox="0 0 50 50">${circle}</svg>`) as Element
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
return
|
|
92
|
+
const node = div('ns', div('nst'), div('nss', svg)) as NSElement
|
|
93
|
+
node.nsId = Date.now()
|
|
94
|
+
return node
|
|
100
95
|
}
|
|
101
96
|
|
|
102
97
|
/**
|
|
103
|
-
* # Peek
|
|
98
|
+
* # Peek Nanosplash Queue
|
|
104
99
|
* Collect all Nanosplash elements in the DOM, sort them by their NS ID
|
|
105
100
|
* in ascending order, and return the first element.
|
|
106
101
|
* @returns The front of the queue.
|
|
107
102
|
*/
|
|
108
|
-
const
|
|
109
|
-
|
|
103
|
+
const peekNsQueue = (): NSElement | null =>
|
|
104
|
+
getAllNs().sort((a: NSElement, b: NSElement) => a.nsId - b.nsId)[0] ?? null
|
|
110
105
|
|
|
111
106
|
/**
|
|
112
|
-
* # Set
|
|
107
|
+
* # Set Nanosplash Text
|
|
113
108
|
* Replace the text node to trigger the animation which in turn is invoked
|
|
114
109
|
* by the connected callback in the DOM.
|
|
115
110
|
* @param ns Nanosplash element.
|
|
116
111
|
* @param text Text to display adjacent to spinner.
|
|
117
112
|
*/
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
oldNst.replaceWith(newNst)
|
|
113
|
+
const setNsText = (ns: NSElement, text: string): void => {
|
|
114
|
+
const oldNsText = scope(ns).first('.nst') as Element | null
|
|
115
|
+
if (!text) return oldNsText?.remove()
|
|
116
|
+
const newNsText = div('nst', text)
|
|
117
|
+
if (oldNsText) {
|
|
118
|
+
oldNsText.replaceWith(newNsText)
|
|
125
119
|
} else {
|
|
126
|
-
|
|
127
|
-
nsc.insertBefore(newNst, nsc.firstChild)
|
|
120
|
+
ns.insertBefore(newNsText, ns.firstChild)
|
|
128
121
|
}
|
|
129
122
|
}
|
|
130
123
|
|
|
131
124
|
/**
|
|
132
|
-
* # Set
|
|
125
|
+
* # Set Nanosplash Parent
|
|
133
126
|
* Define where inside the DOM to spawn the Nansoplash.
|
|
134
127
|
* @param ns Nanosplash element.
|
|
135
128
|
* @param parent NS element's parent to be.
|
|
136
129
|
*/
|
|
137
|
-
const
|
|
130
|
+
const setNsParent = (ns: NSElement, parent: Element): void => {
|
|
138
131
|
const child = parent.firstElementChild
|
|
139
132
|
if (child) {
|
|
140
133
|
parent.insertBefore(ns, child)
|
|
@@ -144,76 +137,73 @@ const setNSParent = (ns: NSElement, parent: Element): void => {
|
|
|
144
137
|
}
|
|
145
138
|
|
|
146
139
|
/**
|
|
147
|
-
* # Show
|
|
140
|
+
* # Show Nanosplash
|
|
148
141
|
* @param text Text to display adjacent to spinner.
|
|
149
142
|
* @param inside Selector or element in which the NS element will be spawned.
|
|
150
143
|
* @returns The ID if the NS element — which is a UTC integer.
|
|
151
144
|
*/
|
|
152
145
|
const show = (text?: string, inside?: string | Element): number | null => {
|
|
153
|
-
const parent: Element
|
|
146
|
+
const parent: Element | null = (
|
|
147
|
+
inside ? parseRef(inside) : bod
|
|
148
|
+
) as Element | null
|
|
154
149
|
let ns: NSElement
|
|
155
|
-
const recycledNs = scope(parent).first('& > .ns')
|
|
150
|
+
const recycledNs = scope(parent ?? bod).first('& > .ns')
|
|
156
151
|
if (recycledNs) {
|
|
157
152
|
ns = recycledNs as NSElement
|
|
158
153
|
} else {
|
|
159
|
-
ns =
|
|
160
|
-
|
|
154
|
+
ns = makeNs()
|
|
155
|
+
setNsParent(ns, parent as Element)
|
|
161
156
|
}
|
|
162
|
-
|
|
163
|
-
const top: string =
|
|
164
|
-
|
|
157
|
+
setNsText(ns, text ?? '')
|
|
158
|
+
const top: string = scrollY + 'px'
|
|
159
|
+
bod.style.setProperty('--ns-top', top)
|
|
165
160
|
return ns.nsId
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
/**
|
|
169
|
-
* #
|
|
164
|
+
* # Remove Nanosplash
|
|
170
165
|
* @param ns Nanosplash elememnt.
|
|
171
166
|
*/
|
|
172
|
-
const
|
|
167
|
+
const removeNs = (ns?: Element | null): void => {
|
|
173
168
|
ns?.parentElement?.classList.remove('nsh')
|
|
174
169
|
ns?.remove()
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
/**
|
|
178
|
-
* # Find
|
|
173
|
+
* # Find Nanosplash
|
|
179
174
|
* @param id The UTC integer returned from the `show` function.
|
|
180
175
|
* @returns Null or the corresponding Nanosplash element.
|
|
181
176
|
*/
|
|
182
|
-
const
|
|
177
|
+
const findNs = (id: number) => getAllNs().find(v => v.nsId === id) ?? null
|
|
183
178
|
|
|
184
179
|
/**
|
|
185
|
-
* # Hide
|
|
186
|
-
*
|
|
180
|
+
* # Hide Nanosplash
|
|
181
|
+
* Hide agnostically in FIFO order, specifically by ID, or all by the asterisk
|
|
182
|
+
* which will delete all Nanosplashes.
|
|
183
|
+
* @param id Optional ID of a Nanosplash element or '*' .
|
|
187
184
|
*/
|
|
188
|
-
const hide = (id?: number): void => {
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const hide = (id?: number | '*'): void => {
|
|
186
|
+
if (id === '*') getAll('.ns').forEach(removeNs)
|
|
187
|
+
else removeNs(typeof id === 'number' ? findNs(id) : peekNsQueue())
|
|
191
188
|
}
|
|
192
189
|
|
|
193
190
|
/**
|
|
194
|
-
* #
|
|
195
|
-
*/
|
|
196
|
-
const hideAll = (): void => getAll('.ns').forEach(deleteNS)
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* # Add style
|
|
191
|
+
* # Add CSS
|
|
200
192
|
*/
|
|
201
|
-
const
|
|
202
|
-
get('#
|
|
203
|
-
|
|
204
|
-
document.body.append(parse(html))
|
|
193
|
+
const addCssToBody = (): void => {
|
|
194
|
+
get('#' + styleId)?.remove()
|
|
195
|
+
bod.append(parse(`<style id=${styleId}>${style}</style>`))
|
|
205
196
|
}
|
|
206
197
|
|
|
207
198
|
/**
|
|
208
|
-
* # Use
|
|
199
|
+
* # Use Nanosplash
|
|
209
200
|
* @returns Nanosplash API.
|
|
210
201
|
*/
|
|
211
202
|
export const useNs = (): NanosplashInterface => {
|
|
212
|
-
|
|
213
|
-
return (window.ns =
|
|
203
|
+
addCssToBody()
|
|
204
|
+
return (window.ns = {
|
|
214
205
|
show,
|
|
215
206
|
hide,
|
|
216
|
-
hideAll,
|
|
217
207
|
version,
|
|
218
|
-
})
|
|
208
|
+
})
|
|
219
209
|
}
|