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.
Files changed (66) hide show
  1. package/.github/workflows/ci.yml +50 -44
  2. package/.github/workflows/vitepress.yml +69 -0
  3. package/.prettierignore +1 -0
  4. package/.prettierrc +10 -10
  5. package/README.md +11 -172
  6. package/bun.lockb +0 -0
  7. package/coverage/{core/Dom.ts.html → DomUtilities.ts.html} +141 -138
  8. package/coverage/{core/Service.ts.html → Service.ts.html} +250 -322
  9. package/coverage/{core/Splash.ts.html → Splash.ts.html} +145 -154
  10. package/coverage/SplashQueue.ts.html +232 -0
  11. package/coverage/clover.xml +557 -552
  12. package/coverage/coverage-final.json +5 -9043
  13. package/coverage/index.html +53 -23
  14. package/dist/cjs/ns.cjs +2 -0
  15. package/dist/es/ns.js +342 -0
  16. package/dist/iife/ns.iife.js +2 -0
  17. package/docs/.vitepress/config.ts +75 -0
  18. package/docs/.vitepress/theme/css/style.css +157 -0
  19. package/docs/.vitepress/theme/index.ts +16 -0
  20. package/docs/.vitepress/theme/vue/Card.vue +31 -0
  21. package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
  22. package/docs/.vitepress/theme/vue/Exe.vue +86 -0
  23. package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
  24. package/docs/api/doc/hide.md +69 -0
  25. package/docs/api/doc/show.md +47 -0
  26. package/docs/api/start/features.md +17 -0
  27. package/docs/api/start/install.md +53 -0
  28. package/docs/api/start/playground.md +11 -0
  29. package/docs/api/start/usage.md +25 -0
  30. package/docs/index.md +30 -0
  31. package/package.json +86 -87
  32. package/src/style/ns.sass +95 -0
  33. package/src/ts/core/{Dom.ts → DomUtilities.ts} +58 -57
  34. package/src/ts/core/Service.ts +66 -90
  35. package/src/ts/core/ServiceInterface.ts +5 -7
  36. package/src/ts/core/Splash.ts +23 -26
  37. package/src/ts/core/SplashInterface.ts +12 -20
  38. package/src/ts/core/SplashQueue.ts +49 -0
  39. package/src/ts/types/Types.ts +0 -9
  40. package/tests/{Dom.spec.ts → DomUtilities.spec.ts} +13 -23
  41. package/tests/Guid.spec.ts +3 -3
  42. package/tests/Service.spec.ts +146 -67
  43. package/tests/Splash.spec.ts +26 -26
  44. package/tests/TestUtilities.ts +48 -0
  45. package/tsconfig.json +1 -0
  46. package/vite.config.ts +1 -15
  47. package/coverage/core/index.html +0 -146
  48. package/coverage/types/Types.ts.html +0 -121
  49. package/coverage/types/index.html +0 -116
  50. package/dist/latest/cjs/ns.cjs +0 -1
  51. package/dist/latest/cjs/style.css +0 -1
  52. package/dist/latest/es/ns.js +0 -306
  53. package/dist/latest/es/style.css +0 -1
  54. package/dist/latest/iife/ns.iife.js +0 -4
  55. package/dist/versioned/3.0.1/cjs/ns.cjs +0 -1
  56. package/dist/versioned/3.0.1/cjs/style.css +0 -1
  57. package/dist/versioned/3.0.1/es/ns.js +0 -306
  58. package/dist/versioned/3.0.1/es/style.css +0 -1
  59. package/dist/versioned/3.0.1/iife/ns.iife.js +0 -2
  60. package/docs/index.6d66a821.js +0 -1
  61. package/docs/index.74dbd99e.css +0 -1
  62. package/docs/index.f34144dc.js +0 -1
  63. package/docs/index.html +0 -107
  64. package/index.html +0 -105
  65. package/src/sass/ns.sass +0 -95
  66. package/vite.demo.config.ts +0 -16
package/package.json CHANGED
@@ -1,88 +1,87 @@
1
1
  {
2
- "name": "nanosplash",
3
- "description": "The tiny loading screen for web artisans",
4
- "private": false,
5
- "version": "3.0.1",
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
- "dev": "vite",
59
- "build": "yarn build:all && yarn build:all:versioned && yarn build:demo",
60
- "build:es": "tsc && cross-env entry=./src/ts/core/Service.ts format=es yarn vite build -m production --c vite.config.ts",
61
- "build:cjs": "tsc && cross-env entry=./src/ts/core/Service.ts format=cjs yarn vite build -m production --c vite.config.ts",
62
- "build:iife": "tsc && cross-env entry=./src/ts/main.ts format=iife yarn vite build -m production --c vite.config.ts",
63
- "build:es:ver": "tsc && cross-env versioned=true entry=./src/ts/core/Service.ts format=es yarn vite build -m production --c vite.config.ts",
64
- "build:cjs:ver": "tsc && cross-env versioned=true entry=./src/ts/core/Service.ts format=cjs yarn vite build -m production --c vite.config.ts",
65
- "build:iife:ver": "tsc && cross-env versioned=true entry=./src/ts/main.ts format=iife yarn vite build -m production --c vite.config.ts",
66
- "build:all": "yarn build:es && yarn build:cjs && yarn build:iife",
67
- "build:all:versioned": "yarn build:es:ver && yarn build:cjs:ver && yarn build:iife:ver",
68
- "build:demo": "tsc && vite build -m production --c vite.demo.config.ts",
69
- "preview": "vite preview",
70
- "test": "vitest",
71
- "test:ui": "vitest --ui",
72
- "coverage": "vitest --coverage"
73
- },
74
- "devDependencies": {
75
- "@types/jsdom": "^21.1.2",
76
- "@types/node": "^20.5.9",
77
- "@types/rollup": "^0.54.0",
78
- "@vitest/coverage-v8": "^0.34.3",
79
- "@vitest/ui": "^0.34.3",
80
- "cross-env": "^7.0.3",
81
- "jsdom": "^22.1.0",
82
- "sass": "^1.66.1",
83
- "terser": "^5.19.3",
84
- "typescript": "^5.2.2",
85
- "vite": "^4.4.9",
86
- "vitest": "^0.34.3"
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
- // @ts-strict
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 new DOMParser().parseFromString(
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
- 'text/html'
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
- * # Set NS Host Class
50
- * Add or remove the `nsHostClassName` class to the `element`.
51
- * @param element Element to which the `nsHostClassName` class will be added or removed.
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 setNSHostClass(
58
- element: Element | null,
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
- * # Prepare Parent Of
66
- * Add the `nsHostClassName` class to the parent of the `ns` element.
67
- * @param ns Nanosplash instance.
68
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
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 cleanNSParentOf(ns: Splash): void {
81
- setNSHostClass(ns.getNSElement().parentElement, ClassListAction.Remove)
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
- return ref instanceof Element ? ref : document.querySelector(ref || '')
115
- }
116
-
117
- /**
118
- * # Element Is NS
119
- * Check if the element is a Nanosplash element.
120
- * This is determined by the presence of the `ns` class on the element.
121
- * @param element Element to check.
122
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains
123
- */
124
- export function elementIsNS(element: Element): boolean {
125
- return element?.classList?.contains(Splash.NSClass) ?? false
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
- setNSHostClass(element.parentElement, ClassListAction.Remove)
135
+ removeNSHostClass(element.parentElement)
137
136
  // Assign new NS host element.
138
- setNSHostClass(targetElement, ClassListAction.Add)
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 getRecycledNS(targetElement: Element): Splash | null {
150
- const firstChild = targetElement.firstElementChild
151
- const hasChild = firstChild !== null
152
- const targetAlreadyHasNS = hasChild && elementIsNS(firstChild)
153
- if (targetAlreadyHasNS) {
154
- const id: GUIDString = firstChild.id
155
- const nss = Service.getInstance()
156
- return nss.nsStack.find((ns: Splash) => ns.getId() === id) ?? null
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
  }