nanosplash 3.0.1 → 3.0.2
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 +50 -44
- package/.github/workflows/vitepress.yml +69 -0
- package/.prettierignore +1 -0
- package/.prettierrc +10 -10
- package/README.md +11 -172
- package/bun.lockb +0 -0
- package/coverage/{core/Dom.ts.html → DomUtilities.ts.html} +141 -138
- package/coverage/{core/Service.ts.html → Service.ts.html} +250 -322
- package/coverage/{core/Splash.ts.html → Splash.ts.html} +145 -154
- package/coverage/SplashQueue.ts.html +232 -0
- package/coverage/clover.xml +557 -552
- package/coverage/coverage-final.json +5 -9043
- package/coverage/index.html +53 -23
- package/dist/cjs/ns.cjs +2 -0
- package/dist/es/ns.js +342 -0
- package/dist/iife/ns.iife.js +2 -0
- package/docs/.vitepress/config.ts +75 -0
- package/docs/.vitepress/theme/css/style.css +157 -0
- package/docs/.vitepress/theme/index.ts +16 -0
- package/docs/.vitepress/theme/vue/Card.vue +31 -0
- package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
- package/docs/.vitepress/theme/vue/Exe.vue +86 -0
- package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
- package/docs/api/doc/hide.md +69 -0
- package/docs/api/doc/show.md +47 -0
- package/docs/api/start/features.md +17 -0
- package/docs/api/start/install.md +53 -0
- package/docs/api/start/playground.md +11 -0
- package/docs/api/start/usage.md +25 -0
- package/docs/index.md +30 -0
- package/package.json +86 -87
- package/src/style/ns.sass +95 -0
- package/src/ts/core/{Dom.ts → DomUtilities.ts} +58 -57
- package/src/ts/core/Service.ts +66 -90
- package/src/ts/core/ServiceInterface.ts +5 -7
- package/src/ts/core/Splash.ts +23 -26
- package/src/ts/core/SplashInterface.ts +12 -20
- package/src/ts/core/SplashQueue.ts +49 -0
- package/src/ts/types/Types.ts +0 -9
- package/tests/{Dom.spec.ts → DomUtilities.spec.ts} +13 -23
- package/tests/Guid.spec.ts +3 -3
- package/tests/Service.spec.ts +146 -67
- package/tests/Splash.spec.ts +26 -26
- package/tests/TestUtilities.ts +48 -0
- package/tsconfig.json +1 -0
- package/vite.config.ts +1 -15
- package/coverage/core/index.html +0 -146
- package/coverage/types/Types.ts.html +0 -121
- package/coverage/types/index.html +0 -116
- package/dist/latest/cjs/ns.cjs +0 -1
- package/dist/latest/cjs/style.css +0 -1
- package/dist/latest/es/ns.js +0 -306
- package/dist/latest/es/style.css +0 -1
- package/dist/latest/iife/ns.iife.js +0 -4
- package/dist/versioned/3.0.1/cjs/ns.cjs +0 -1
- package/dist/versioned/3.0.1/cjs/style.css +0 -1
- package/dist/versioned/3.0.1/es/ns.js +0 -306
- package/dist/versioned/3.0.1/es/style.css +0 -1
- package/dist/versioned/3.0.1/iife/ns.iife.js +0 -2
- package/docs/index.6d66a821.js +0 -1
- package/docs/index.74dbd99e.css +0 -1
- package/docs/index.f34144dc.js +0 -1
- package/docs/index.html +0 -107
- package/index.html +0 -105
- package/src/sass/ns.sass +0 -95
- package/vite.demo.config.ts +0 -16
package/package.json
CHANGED
|
@@ -1,88 +1,87 @@
|
|
|
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
|
-
}
|
|
2
|
+
"name": "nanosplash",
|
|
3
|
+
"description": "The tiny loading screen for web artisans",
|
|
4
|
+
"private": false,
|
|
5
|
+
"version": "3.0.2",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Isak K. Hauge",
|
|
9
|
+
"email": "isakhauge@icloud.com",
|
|
10
|
+
"url": "https://no.linkedin.com/in/isakhauge"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"loading",
|
|
14
|
+
"loader",
|
|
15
|
+
"screen",
|
|
16
|
+
"splash",
|
|
17
|
+
"nano",
|
|
18
|
+
"nanosplash",
|
|
19
|
+
"small",
|
|
20
|
+
"tiny",
|
|
21
|
+
"es",
|
|
22
|
+
"esm",
|
|
23
|
+
"ts",
|
|
24
|
+
"typescript",
|
|
25
|
+
"iife",
|
|
26
|
+
"cdn",
|
|
27
|
+
"vite"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://isakhauge.github.io/nanosplash",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/isakhauge/nanosplash.git"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"main": "./dist/latest/es/ns.js",
|
|
36
|
+
"module": "./dist/latest/es/ns.js",
|
|
37
|
+
"source": "./src/main.ts",
|
|
38
|
+
"unpkg": "./dist/latest/iife/ns.iife.js",
|
|
39
|
+
"style": "./dist/latest/es/style.css",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": {
|
|
43
|
+
"require": "./src/ts/types/global.d.ts",
|
|
44
|
+
"default": "./src/ts/types/global.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"browser": {
|
|
47
|
+
"require": "./dist/latest/cjs/ns.cjs",
|
|
48
|
+
"default": "./dist/latest/es/ns.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"require": "./dist/latest/cjs/ns.cjs",
|
|
52
|
+
"default": "./dist/latest/es/ns.js"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"types": "./src/ts/types/global.d.ts",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "bun build:all && bun build:docs",
|
|
59
|
+
"build:es": "tsc && cross-env entry=./src/ts/core/Service.ts format=es bun vite build -m production --c vite.config.ts",
|
|
60
|
+
"build:cjs": "tsc && cross-env entry=./src/ts/core/Service.ts format=cjs bun vite build -m production --c vite.config.ts",
|
|
61
|
+
"build:iife": "tsc && cross-env entry=./src/ts/main.ts format=iife bun vite build -m production --c vite.config.ts",
|
|
62
|
+
"build:all": "bun build:es && bun build:cjs && bun build:iife",
|
|
63
|
+
"build:docs": "bun docs:build",
|
|
64
|
+
"preview": "vite preview",
|
|
65
|
+
"test": "vitest",
|
|
66
|
+
"test:ui": "vitest --ui",
|
|
67
|
+
"coverage": "vitest --coverage",
|
|
68
|
+
"docs:dev": "vitepress dev docs",
|
|
69
|
+
"docs:build": "vitepress build docs",
|
|
70
|
+
"docs:preview": "vitepress preview docs"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/jsdom": "^21.1.3",
|
|
74
|
+
"@types/node": "^20.8.6",
|
|
75
|
+
"@types/rollup": "^0.54.0",
|
|
76
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
77
|
+
"@vitest/ui": "^0.34.6",
|
|
78
|
+
"cross-env": "^7.0.3",
|
|
79
|
+
"jsdom": "^22.1.0",
|
|
80
|
+
"sass": "^1.69.3",
|
|
81
|
+
"terser": "^5.22.0",
|
|
82
|
+
"typescript": "^5.2.2",
|
|
83
|
+
"vite": "^4.4.11",
|
|
84
|
+
"vitepress": "1.0.0-rc.22",
|
|
85
|
+
"vitest": "^0.34.6"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
%maximize
|
|
2
|
+
width: 100%
|
|
3
|
+
height: 100%
|
|
4
|
+
|
|
5
|
+
%upper-left
|
|
6
|
+
top: 0
|
|
7
|
+
left: 0
|
|
8
|
+
|
|
9
|
+
%flex-center-xy
|
|
10
|
+
display: flex
|
|
11
|
+
justify-content: center
|
|
12
|
+
align-items: center
|
|
13
|
+
|
|
14
|
+
// Nanosplash host scoped varibles
|
|
15
|
+
.nsh
|
|
16
|
+
--color: DarkSlateGray
|
|
17
|
+
--size: 20px
|
|
18
|
+
--relSize: calc(var(--size) * 0.9)
|
|
19
|
+
--font: 'Helvetica', 'Arial', sans-serif
|
|
20
|
+
--weight: 400
|
|
21
|
+
--bg: #{ rgba(White, 0.8) }
|
|
22
|
+
--zIdx: 999999999
|
|
23
|
+
--blur: blur(10px)
|
|
24
|
+
|
|
25
|
+
// Nanosplash host
|
|
26
|
+
.nsh
|
|
27
|
+
position: relative
|
|
28
|
+
z-index: var(--zIdx)
|
|
29
|
+
&::before
|
|
30
|
+
@extend %maximize
|
|
31
|
+
@extend %upper-left
|
|
32
|
+
position: absolute
|
|
33
|
+
background-color: var(--bg)
|
|
34
|
+
content: ''
|
|
35
|
+
backdrop-filter: var(--blur)
|
|
36
|
+
-webkit-backdrop-filter: var(--blur)
|
|
37
|
+
z-index: calc(var(--zIdx) + 1)
|
|
38
|
+
border-radius: inherit
|
|
39
|
+
|
|
40
|
+
// When Nanosplash host is the document body
|
|
41
|
+
body.nsh
|
|
42
|
+
height: 100vh
|
|
43
|
+
|
|
44
|
+
// Nanosplash (main element)
|
|
45
|
+
.ns
|
|
46
|
+
@extend %maximize
|
|
47
|
+
@extend %upper-left
|
|
48
|
+
@extend %flex-center-xy
|
|
49
|
+
position: absolute
|
|
50
|
+
z-index: calc(var(--zIdx) + 2)
|
|
51
|
+
|
|
52
|
+
// Nanosplash container
|
|
53
|
+
.nsc
|
|
54
|
+
@extend %flex-center-xy
|
|
55
|
+
filter: drop-shadow(0 0 0.1rem #{ rgba(LightGray, 0.5) })
|
|
56
|
+
|
|
57
|
+
// Nanosplash text
|
|
58
|
+
.nst
|
|
59
|
+
color: var(--color)
|
|
60
|
+
font-size: var(--size)
|
|
61
|
+
font-family: var(--font)
|
|
62
|
+
font-weight: var(--weight)
|
|
63
|
+
margin-right: var(--relSize)
|
|
64
|
+
text-shadow: 0 0 0.06rem #{ rgba(DarkSlateGray, .25) }
|
|
65
|
+
|
|
66
|
+
// Nanosplash spinner
|
|
67
|
+
.nss
|
|
68
|
+
display: block
|
|
69
|
+
width: var(--relSize)
|
|
70
|
+
height: var(--relSize)
|
|
71
|
+
& > svg
|
|
72
|
+
animation: Rotate 2s linear infinite
|
|
73
|
+
position: relative
|
|
74
|
+
width: inherit
|
|
75
|
+
height: inherit
|
|
76
|
+
stroke-width: 8
|
|
77
|
+
& .path
|
|
78
|
+
stroke: var(--color)
|
|
79
|
+
stroke-linecap: round
|
|
80
|
+
animation: Dash 1.5s ease-in-out infinite
|
|
81
|
+
|
|
82
|
+
// Spinner animations:
|
|
83
|
+
@keyframes Rotate
|
|
84
|
+
100%
|
|
85
|
+
transform: rotate(360deg)
|
|
86
|
+
@keyframes Dash
|
|
87
|
+
0%
|
|
88
|
+
stroke-dasharray: 1, 150
|
|
89
|
+
stroke-dashoffset: 0
|
|
90
|
+
50%
|
|
91
|
+
stroke-dasharray: 90, 150
|
|
92
|
+
stroke-dashoffset: -35
|
|
93
|
+
100%
|
|
94
|
+
stroke-dasharray: 90, 150
|
|
95
|
+
stroke-dashoffset: -124
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Reference, GUIDString, ClassListAction } from '../types/Types'
|
|
1
|
+
import { Reference } from '../types/Types'
|
|
4
2
|
import { Service } from './Service'
|
|
5
3
|
import { Splash } from './Splash'
|
|
6
4
|
|
|
@@ -12,15 +10,27 @@ import { Splash } from './Splash'
|
|
|
12
10
|
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
13
11
|
*/
|
|
14
12
|
|
|
13
|
+
/**
|
|
14
|
+
* # Render
|
|
15
|
+
* @param html HTML string to render.
|
|
16
|
+
* @returns Rendered HTML element.
|
|
17
|
+
*/
|
|
18
|
+
export function render(html: string): HTMLElement {
|
|
19
|
+
return (div =>
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
(() => div.firstChild as HTMLElement)((div.innerHTML = html)))(
|
|
22
|
+
document.createElement('div')
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
/**
|
|
16
27
|
* # Create Element
|
|
17
28
|
* Return the main Nanosplash element.
|
|
18
29
|
*/
|
|
19
30
|
export function createElement(): HTMLDivElement {
|
|
20
|
-
return
|
|
21
|
-
'<div class=ns><div class=nsc><div class=nst></div><div class=nss><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>'
|
|
22
|
-
|
|
23
|
-
).body.firstChild as HTMLDivElement
|
|
31
|
+
return render(
|
|
32
|
+
'<div class=ns><div class=nsc><div class=nst></div><div class=nss><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>'
|
|
33
|
+
) as HTMLDivElement
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
/**
|
|
@@ -46,39 +56,25 @@ export function injectAsFirstChild(
|
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
/**
|
|
49
|
-
* #
|
|
50
|
-
* Add
|
|
51
|
-
* @param element Element to which the `nsHostClassName` class will be added
|
|
52
|
-
* @param action Action to perform ('add' or 'remove').
|
|
59
|
+
* # Add NS Host Class
|
|
60
|
+
* Add the `nsHostClassName` class to the `element`.
|
|
61
|
+
* @param element Element to which the `nsHostClassName` class will be added.
|
|
53
62
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
|
|
54
63
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add
|
|
55
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove
|
|
56
64
|
*/
|
|
57
|
-
export function
|
|
58
|
-
element
|
|
59
|
-
action: ClassListAction
|
|
60
|
-
): void {
|
|
61
|
-
element?.classList[action](Splash.NSHostClass)
|
|
65
|
+
export function addNSHostClass(element: Element | null): void {
|
|
66
|
+
element?.classList.add(Splash.NSHostClass)
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
|
-
* #
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/
|
|
69
|
-
|
|
70
|
-
export function prepareParentOf(ns: Splash): void {
|
|
71
|
-
setNSHostClass(ns.getNSElement().parentElement, ClassListAction.Add)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* # Clean NS Parent Of
|
|
76
|
-
* Remove the `nsHostClassName` class from the parent of the `ns` element.
|
|
77
|
-
* @param ns Nanosplash instance.
|
|
78
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
|
|
70
|
+
* # Remove NS Host Class
|
|
71
|
+
* Remove the `nsHostClassName` class from the `element`.
|
|
72
|
+
* @param element Element from which the `nsHostClassName` class will be removed.
|
|
73
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
|
|
74
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove
|
|
79
75
|
*/
|
|
80
|
-
export function
|
|
81
|
-
|
|
76
|
+
export function removeNSHostClass(element: Element | null): void {
|
|
77
|
+
element?.classList.remove(Splash.NSHostClass)
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
/**
|
|
@@ -111,18 +107,21 @@ export function hideElement(element: HTMLElement): void {
|
|
|
111
107
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
112
108
|
*/
|
|
113
109
|
export function elementFrom(ref: Reference): Element | null {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
switch (typeof ref) {
|
|
111
|
+
case 'object':
|
|
112
|
+
const isBody = ref === document.body
|
|
113
|
+
const isElement = ref instanceof Element
|
|
114
|
+
if (isBody || isElement) {
|
|
115
|
+
return ref
|
|
116
|
+
}
|
|
117
|
+
throw new Error(
|
|
118
|
+
'Reference is an object but not an Element instance.'
|
|
119
|
+
)
|
|
120
|
+
case 'string':
|
|
121
|
+
return document.querySelector(ref)
|
|
122
|
+
default:
|
|
123
|
+
throw new Error('Reference is not an object or a string.')
|
|
124
|
+
}
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
/**
|
|
@@ -133,9 +132,9 @@ export function elementIsNS(element: Element): boolean {
|
|
|
133
132
|
*/
|
|
134
133
|
export function move(element: Element, targetElement: Element): void {
|
|
135
134
|
// Clean the current NS host element.
|
|
136
|
-
|
|
135
|
+
removeNSHostClass(element.parentElement)
|
|
137
136
|
// Assign new NS host element.
|
|
138
|
-
|
|
137
|
+
addNSHostClass(targetElement)
|
|
139
138
|
injectAsFirstChild(element, targetElement)
|
|
140
139
|
}
|
|
141
140
|
|
|
@@ -146,15 +145,17 @@ export function move(element: Element, targetElement: Element): void {
|
|
|
146
145
|
* @returns { Nanosplash | null } Nanosplash instance or null.
|
|
147
146
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/firstElementChild
|
|
148
147
|
*/
|
|
149
|
-
export function
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
148
|
+
export function getRecycledSplash(targetElement: Element): Splash | null {
|
|
149
|
+
const children = Array.from(targetElement.children || [])
|
|
150
|
+
const nss = Service.getInstance()
|
|
151
|
+
let splash: Splash | null = null
|
|
152
|
+
const n = children.length
|
|
153
|
+
for (let i = 0; i < n; i++) {
|
|
154
|
+
const child = children[i]
|
|
155
|
+
if (child.classList.contains(Splash.NSClass)) {
|
|
156
|
+
splash = nss.nsQueue.get(child.id) ?? null
|
|
157
|
+
break
|
|
158
|
+
}
|
|
157
159
|
}
|
|
158
|
-
|
|
159
|
-
return null
|
|
160
|
+
return splash
|
|
160
161
|
}
|