nanosplash 3.0.9 → 3.1.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/README.md +52 -4
- package/bun.lockb +0 -0
- package/dist/cjs/ns.cjs +1 -1
- package/dist/es/ns.js +30 -49
- package/dist/iife/ns.iife.js +1 -1
- package/docs/.vitepress/.temp/@localSearchIndexroot.Ba2B1gNE.js +4 -0
- package/docs/.vitepress/.temp/Card.Ce4dbGEn.js +30 -0
- package/docs/.vitepress/.temp/VPLocalSearchBox.DV6bivXX.js +382 -0
- package/docs/.vitepress/.temp/api_doc_hide.md.js +25 -0
- package/docs/.vitepress/.temp/api_doc_show.md.js +25 -0
- package/docs/.vitepress/.temp/api_start_customize.md.js +42 -0
- package/docs/.vitepress/.temp/api_start_features.md.js +19 -0
- package/docs/.vitepress/.temp/api_start_install.md.js +35 -0
- package/docs/.vitepress/.temp/api_start_playground.md.js +213 -0
- package/docs/.vitepress/.temp/api_start_usage.md.js +36 -0
- package/docs/.vitepress/.temp/app.js +5090 -0
- package/docs/.vitepress/.temp/assets/style.lcyfX_uc.css +5374 -0
- package/docs/.vitepress/.temp/index.md.js +19 -0
- package/docs/.vitepress/.temp/macos.jpg +0 -0
- package/docs/.vitepress/.temp/package.json +1 -0
- package/docs/.vitepress/.temp/plugin-vue_export-helper.1tPrXgE0.js +10 -0
- package/docs/.vitepress/config.mts +5 -1
- package/docs/.vitepress/theme/vue/Exe.vue +3 -3
- 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 +10 -10
- package/src/style/ns.sass +11 -16
- package/src/ts/Nanosplash.ts +28 -38
- package/src/ts/types/NanosplashInterface.ts +21 -2
- package/src/ts/types/Types.ts +2 -1
- package/tests/Nanosplash.spec.ts +5 -7
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ssrRenderAttrs } from "vue/server-renderer";
|
|
2
|
+
import { useSSRContext } from "vue";
|
|
3
|
+
import { _ as _export_sfc } from "./plugin-vue_export-helper.1tPrXgE0.js";
|
|
4
|
+
const __pageData = JSON.parse('{"title":"","description":"","frontmatter":{"layout":"home","hero":{"name":"Nanosplash","text":"","tagline":"The tiny loading screen for web artisans","actions":[{"theme":"brand","text":"Get started","link":"/api/start/install.md"},{"theme":"alt","text":"Playground","link":"/api/start/playground.md"},{"theme":"alt","text":"API Documentation","link":"/api/doc/show.md"}]},"features":[{"title":"✨ Tiny","details":"Less than 2KB minified and gzipped.","link":"/api/start/features#small-bundle-size"},{"title":"✌️ 2 Function API","details":"Start using Nanosplash in seconds.","link":"/api/start/features#simple-api"},{"title":"🪴 Spawning","details":"Spawn a splash element anywhere in your DOM.","link":"/api/start/features#spawning"},{"title":"🚀 Node recycling","details":"Nanosplash will recycle existing elements.","link":"/api/start/features#element-recycling"}]},"headers":[],"relativePath":"index.md","filePath":"index.md"}');
|
|
5
|
+
const _sfc_main = { name: "index.md" };
|
|
6
|
+
function _sfc_ssrRender(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
|
|
7
|
+
_push(`<div${ssrRenderAttrs(_attrs)}></div>`);
|
|
8
|
+
}
|
|
9
|
+
const _sfc_setup = _sfc_main.setup;
|
|
10
|
+
_sfc_main.setup = (props, ctx) => {
|
|
11
|
+
const ssrContext = useSSRContext();
|
|
12
|
+
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("index.md");
|
|
13
|
+
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
14
|
+
};
|
|
15
|
+
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["ssrRender", _sfc_ssrRender]]);
|
|
16
|
+
export {
|
|
17
|
+
__pageData,
|
|
18
|
+
index as default
|
|
19
|
+
};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "private": true, "type": "module" }
|
|
@@ -30,6 +30,10 @@ export default defineConfig({
|
|
|
30
30
|
text: 'Playground',
|
|
31
31
|
link: '/api/start/playground',
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
text: 'Customize',
|
|
35
|
+
link: '/api/start/customize',
|
|
36
|
+
},
|
|
33
37
|
],
|
|
34
38
|
},
|
|
35
39
|
{
|
|
@@ -68,7 +72,7 @@ export default defineConfig({
|
|
|
68
72
|
|
|
69
73
|
footer: {
|
|
70
74
|
message:
|
|
71
|
-
'Made with
|
|
75
|
+
'Made with 💖 by <a href="https://twitter.com/isakhauge">Isak Hauge</a>',
|
|
72
76
|
},
|
|
73
77
|
},
|
|
74
78
|
})
|
|
@@ -12,7 +12,7 @@ const Commands = {
|
|
|
12
12
|
ShowFullScreen: 'ns.show("Loading window")',
|
|
13
13
|
Progress: 'Progressive Demo',
|
|
14
14
|
Hide: 'ns.hide()',
|
|
15
|
-
HideAll: 'ns.
|
|
15
|
+
HideAll: 'ns.hide("*")',
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const rCommandString = ref('')
|
|
@@ -55,14 +55,14 @@ async function onClickExe() {
|
|
|
55
55
|
ns.hide()
|
|
56
56
|
break
|
|
57
57
|
case Commands.HideAll:
|
|
58
|
-
ns.
|
|
58
|
+
ns.hide('*')
|
|
59
59
|
break
|
|
60
60
|
case Commands.Progress:
|
|
61
61
|
for (const phrase of phrases) {
|
|
62
62
|
ns.show(phrase)
|
|
63
63
|
await wait(1500)
|
|
64
64
|
}
|
|
65
|
-
ns.
|
|
65
|
+
ns.hide('*')
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
</script>
|
package/docs/api/doc/hide.md
CHANGED
|
@@ -36,7 +36,7 @@ used to hide a specific Nanosplash at a later time.
|
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
38
|
const id = ns.show('Loading')
|
|
39
|
-
ns.
|
|
39
|
+
ns.hide(id)
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## Hide all
|
|
@@ -44,5 +44,5 @@ ns.hideId(id)
|
|
|
44
44
|
Hides all Nanosplashes in the `window`.
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
|
-
ns.
|
|
47
|
+
ns.hide('*'): void
|
|
48
48
|
```
|
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
|
+
Stying 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nanosplash",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Isak K. Hauge",
|
|
6
6
|
"email": "isakhauge@icloud.com",
|
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
"module": "./dist/es/ns.js",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/jsdom": "^21.1.6",
|
|
17
|
-
"@types/node": "^20.11.
|
|
17
|
+
"@types/node": "^20.11.28",
|
|
18
18
|
"@types/rollup": "^0.54.0",
|
|
19
|
-
"@vitest/coverage-v8": "^1.
|
|
20
|
-
"@vitest/ui": "^1.
|
|
19
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
20
|
+
"@vitest/ui": "^1.4.0",
|
|
21
21
|
"cross-env": "^7.0.3",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"eslint-config-prettier": "^9.1.0",
|
|
24
24
|
"eslint-plugin-prettier": "^5.1.3",
|
|
25
25
|
"jsdom": "^24.0.0",
|
|
26
|
-
"sass": "^1.
|
|
26
|
+
"sass": "^1.72.0",
|
|
27
27
|
"stylelint-prettier": "^5.0.0",
|
|
28
|
-
"terser": "^5.29.
|
|
29
|
-
"typescript": "5.
|
|
30
|
-
"typescript-eslint": "^7.
|
|
31
|
-
"vite": "^5.1.
|
|
28
|
+
"terser": "^5.29.2",
|
|
29
|
+
"typescript": "5.4.2",
|
|
30
|
+
"typescript-eslint": "^7.2.0",
|
|
31
|
+
"vite": "^5.1.6",
|
|
32
32
|
"vitepress": "1.0.0-rc.45",
|
|
33
|
-
"vitest": "^1.
|
|
33
|
+
"vitest": "^1.4.0"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
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
|
@@ -10,20 +10,20 @@ import {
|
|
|
10
10
|
import { version } from '../../package.json'
|
|
11
11
|
|
|
12
12
|
const StyleID: string = 'nscss'
|
|
13
|
+
const b = () => document.body
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* # Scope
|
|
17
|
+
* Creates scoped selectors.
|
|
16
18
|
* @param node Node to query.
|
|
17
19
|
* @returns An object containing two, slightly different functions that
|
|
18
20
|
* retrieves elements from the DOM.
|
|
19
21
|
*/
|
|
20
|
-
const scope = (node: ParentNode): ScopedSelectors =>
|
|
21
|
-
|
|
22
|
-
return {
|
|
22
|
+
const scope = (node: ParentNode): ScopedSelectors =>
|
|
23
|
+
(all => ({
|
|
23
24
|
all,
|
|
24
25
|
first: (ref: string) => all(ref)[0] ?? null,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
26
|
+
}))((ref: string) => Array.from(node.querySelectorAll(ref)))
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* # Get all
|
|
@@ -52,12 +52,8 @@ const getAllNS = (): NSElement[] => getAll('.ns') as NSElement[]
|
|
|
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
|
* # Div
|
|
@@ -69,7 +65,7 @@ const div = (
|
|
|
69
65
|
className?: string,
|
|
70
66
|
...children: (Node | string)[]
|
|
71
67
|
): HTMLDivElement => {
|
|
72
|
-
const el = document.createElement('div')
|
|
68
|
+
const el: HTMLDivElement = document.createElement('div')
|
|
73
69
|
if (className) el.classList.add(className)
|
|
74
70
|
el.append(...children)
|
|
75
71
|
return el
|
|
@@ -88,13 +84,12 @@ const parse = (html: string): Node => {
|
|
|
88
84
|
|
|
89
85
|
/**
|
|
90
86
|
* # Create NS
|
|
91
|
-
* TODO: Investigate the possibility of inheritence.
|
|
92
87
|
* @returns Nanpslash DOM element.
|
|
93
88
|
*/
|
|
94
89
|
const createNS = (): 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 el = div('ns', div('
|
|
92
|
+
const el = div('ns', div('nst'), div('nss', svg)) as NSElement
|
|
98
93
|
el.nsId = Date.now()
|
|
99
94
|
return el
|
|
100
95
|
}
|
|
@@ -123,8 +118,7 @@ const setNSText = (ns: NSElement, text: string): void => {
|
|
|
123
118
|
if (oldNst) {
|
|
124
119
|
oldNst.replaceWith(newNst)
|
|
125
120
|
} else {
|
|
126
|
-
|
|
127
|
-
nsc.insertBefore(newNst, nsc.firstChild)
|
|
121
|
+
ns.insertBefore(newNst, ns.firstChild)
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
124
|
|
|
@@ -150,9 +144,11 @@ const setNSParent = (ns: NSElement, parent: Element): void => {
|
|
|
150
144
|
* @returns The ID if the NS element — which is a UTC integer.
|
|
151
145
|
*/
|
|
152
146
|
const show = (text?: string, inside?: string | Element): number | null => {
|
|
153
|
-
const parent: Element
|
|
147
|
+
const parent: Element | null = (
|
|
148
|
+
inside ? parseRef(inside) : b
|
|
149
|
+
) as Element | null
|
|
154
150
|
let ns: NSElement
|
|
155
|
-
const recycledNs = scope(parent).first('& > .ns')
|
|
151
|
+
const recycledNs = scope(parent ?? b()).first('& > .ns')
|
|
156
152
|
if (recycledNs) {
|
|
157
153
|
ns = recycledNs as NSElement
|
|
158
154
|
} else {
|
|
@@ -161,7 +157,7 @@ const show = (text?: string, inside?: string | Element): number | null => {
|
|
|
161
157
|
}
|
|
162
158
|
setNSText(ns, text ?? '')
|
|
163
159
|
const top: string = window.scrollY + 'px'
|
|
164
|
-
|
|
160
|
+
b().style.setProperty('--ns-top', top)
|
|
165
161
|
return ns.nsId
|
|
166
162
|
}
|
|
167
163
|
|
|
@@ -183,37 +179,31 @@ const findNS = (id: number) => getAllNS().find(v => v.nsId === id) ?? null
|
|
|
183
179
|
|
|
184
180
|
/**
|
|
185
181
|
* # Hide
|
|
186
|
-
*
|
|
182
|
+
* Hide agnostically in FIFO order, specifically by ID, or all by the asterisk
|
|
183
|
+
* which will delete all Nanosplashes.
|
|
184
|
+
* @param id Optional ID of a Nanosplash element or '*' .
|
|
187
185
|
*/
|
|
188
|
-
const hide = (id?: number): void => {
|
|
189
|
-
|
|
190
|
-
deleteNS(
|
|
186
|
+
const hide = (id?: number | '*'): void => {
|
|
187
|
+
if (id === '*') getAll('.ns').forEach(deleteNS)
|
|
188
|
+
else deleteNS(typeof id === 'number' ? findNS(id) : peek())
|
|
191
189
|
}
|
|
192
190
|
|
|
193
|
-
/**
|
|
194
|
-
* # Hide All
|
|
195
|
-
*/
|
|
196
|
-
const hideAll = (): void => getAll('.ns').forEach(deleteNS)
|
|
197
|
-
|
|
198
191
|
/**
|
|
199
192
|
* # Add style
|
|
200
193
|
*/
|
|
201
194
|
const addStyle = (): void => {
|
|
202
195
|
get('#nscss')?.remove()
|
|
203
|
-
|
|
204
|
-
document.body.append(parse(html))
|
|
196
|
+
b().append(parse(`<style id=${StyleID}>${style}</style>`))
|
|
205
197
|
}
|
|
206
198
|
|
|
207
199
|
/**
|
|
208
200
|
* # Use NS
|
|
209
201
|
* @returns Nanosplash API.
|
|
210
202
|
*/
|
|
211
|
-
export const useNs = (): NanosplashInterface =>
|
|
212
|
-
addStyle
|
|
213
|
-
|
|
203
|
+
export const useNs = (): NanosplashInterface =>
|
|
204
|
+
!!new Promise(addStyle) &&
|
|
205
|
+
(window.ns = {
|
|
214
206
|
show,
|
|
215
207
|
hide,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}))
|
|
219
|
-
}
|
|
208
|
+
version: version,
|
|
209
|
+
})
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { DOMSelector, UTCInteger } from './Types'
|
|
2
2
|
|
|
3
3
|
export interface NanosplashInterface {
|
|
4
|
+
/**
|
|
5
|
+
* # Show
|
|
6
|
+
* Display Nanosplash inside the window.
|
|
7
|
+
* @param {string | undefined} text Optional text
|
|
8
|
+
* @param {string | Element | undefined} inside Optional element reference
|
|
9
|
+
* @returns {number | null} The internal ID of the created Nanosplash.
|
|
10
|
+
*/
|
|
4
11
|
show(text?: string, inside?: DOMSelector | HTMLElement): UTCInteger | null
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
/**
|
|
13
|
+
* # Hide
|
|
14
|
+
* Remove Nanosplash in multiple ways depending on the passed argument.
|
|
15
|
+
* - Pass ID: Remove specific.
|
|
16
|
+
* - Pass '*': Remove all in window.
|
|
17
|
+
* - Pass nothing: Remove in FIFO order.
|
|
18
|
+
* @param id The internal ID, an asterisk, or nothing.
|
|
19
|
+
*/
|
|
20
|
+
hide(id?: UTCInteger | '*'): void
|
|
21
|
+
/**
|
|
22
|
+
* # Version
|
|
23
|
+
* The current version of Nanosplash.
|
|
24
|
+
*/
|
|
25
|
+
version: string
|
|
7
26
|
}
|
package/src/ts/types/Types.ts
CHANGED
package/tests/Nanosplash.spec.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { describe, it, test, expect, beforeEach } from 'vitest'
|
|
2
2
|
import { useNs } from '../src/ts/Nanosplash'
|
|
3
3
|
import { JSDOM } from 'jsdom'
|
|
4
|
+
import { NanosplashInterface } from '../src/ts/types/NanosplashInterface'
|
|
4
5
|
|
|
5
|
-
let
|
|
6
|
+
let document: Document | null = null
|
|
7
|
+
let ns: NanosplashInterface | null = null
|
|
6
8
|
|
|
7
9
|
beforeEach(() => {
|
|
8
10
|
const dom = new JSDOM()
|
|
9
11
|
// @ts-ignore
|
|
10
12
|
globalThis.window = dom.window
|
|
11
|
-
globalThis.document = window.document
|
|
12
|
-
globalThis.window.ns =
|
|
13
|
+
document = globalThis.document = dom.window.document
|
|
14
|
+
ns = globalThis.window.ns = useNs()
|
|
13
15
|
})
|
|
14
16
|
|
|
15
17
|
describe('Nanosplash API', () => {
|
|
@@ -25,10 +27,6 @@ describe('Nanosplash API', () => {
|
|
|
25
27
|
expect(window.ns.hide).toBeDefined()
|
|
26
28
|
})
|
|
27
29
|
|
|
28
|
-
it('should have the "hideAll" method', () => {
|
|
29
|
-
expect(window.ns.hideAll).toBeDefined()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
30
|
it('should have the global instance', () => {
|
|
33
31
|
expect(window.ns).toBe(ns)
|
|
34
32
|
})
|