nanosplash 3.0.0 → 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/LICENSE +21 -0
- package/README.md +14 -41
- package/bun.lockb +0 -0
- package/coverage/DomUtilities.ts.html +568 -0
- package/coverage/Service.ts.html +718 -0
- package/coverage/Splash.ts.html +448 -0
- package/coverage/SplashQueue.ts.html +232 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +560 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +161 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- 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 -66
- package/src/style/ns.sass +95 -0
- package/src/ts/core/DomUtilities.ts +161 -0
- package/src/ts/core/Service.ts +211 -0
- package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +18 -10
- package/src/ts/core/Splash.ts +121 -0
- package/src/ts/core/SplashInterface.ts +46 -0
- package/src/ts/core/SplashQueue.ts +49 -0
- package/src/ts/main.ts +9 -0
- package/src/ts/types/Types.ts +3 -0
- package/src/ts/types/global.d.ts +14 -0
- package/src/vite-env.d.ts +0 -8
- package/tests/DomUtilities.spec.ts +117 -0
- package/tests/Guid.spec.ts +5 -5
- package/tests/Service.spec.ts +198 -0
- package/tests/Splash.spec.ts +64 -0
- package/tests/TestUtilities.ts +48 -0
- package/tsconfig.json +21 -20
- package/vite.config.ts +14 -22
- package/dist/main.css +0 -1
- package/dist/ns.cjs.js +0 -1
- package/dist/ns.es.js +0 -330
- package/dist/ns.iife.js +0 -2
- package/index.html +0 -52
- package/src/main.ts +0 -8
- package/src/sass/ns.sass +0 -86
- package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
- package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
- package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
- package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
- package/src/ts/types/Alias.d.ts +0 -1
- package/src/ts/types/Nanosplash.d.ts +0 -18
- package/src/ts/types/NanosplashService.d.ts +0 -1
- package/src/ts/util/Guid.ts +0 -13
- package/src/ts/util/Stack.ts +0 -73
- package/tests/Nanosplash.spec.ts +0 -64
- package/tests/NanosplashRepository.spec.ts +0 -91
- package/tests/NanosplashService.spec.ts +0 -119
- package/tests/Stack.spec.ts +0 -56
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
|
-
import '../../../sass/ns.sass'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
createElement,
|
|
7
|
-
hideElement,
|
|
8
|
-
showElement,
|
|
9
|
-
} from './repositories/NanosplashRepository'
|
|
10
|
-
import type { NanosplashInterface } from './interfaces/NanosplashInterface'
|
|
11
|
-
import type { GUIDString } from '../../types/Alias'
|
|
12
|
-
import { guid } from '../../util/Guid'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* # Nanosplash
|
|
16
|
-
* Nanosplash is a small splash screen that can be used to indicate that a
|
|
17
|
-
* process is running.
|
|
18
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
19
|
-
*/
|
|
20
|
-
class Nanosplash implements NanosplashInterface {
|
|
21
|
-
public static readonly nsClassName = 'ns'
|
|
22
|
-
public static readonly nsHostClassName = Nanosplash.nsClassName + '-host'
|
|
23
|
-
|
|
24
|
-
private readonly id: GUIDString
|
|
25
|
-
private element?: HTMLDivElement
|
|
26
|
-
|
|
27
|
-
public constructor() {
|
|
28
|
-
this.element = createElement()
|
|
29
|
-
this.element.id = this.id = guid()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
public getId(): GUIDString {
|
|
36
|
-
return this.id
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @inheritDoc
|
|
41
|
-
*/
|
|
42
|
-
public getNSElement(): HTMLDivElement {
|
|
43
|
-
return <HTMLDivElement>this.element
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* # Get NS Content Element
|
|
48
|
-
* Returns the content element of the Nanosplash.
|
|
49
|
-
*/
|
|
50
|
-
public getNSContentElement(): HTMLDivElement {
|
|
51
|
-
return <HTMLDivElement>this.getNSElement().firstElementChild
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* # Get NS Text Element
|
|
56
|
-
* Returns the text element of the Nanosplash.
|
|
57
|
-
*/
|
|
58
|
-
public getNSTextElement(): HTMLDivElement {
|
|
59
|
-
return <HTMLDivElement>this.getNSContentElement().firstElementChild
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
|
-
public hideText(): Nanosplash {
|
|
66
|
-
hideElement(this.getNSTextElement())
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @inheritDoc
|
|
72
|
-
*/
|
|
73
|
-
public setText(text: string): Nanosplash {
|
|
74
|
-
this.getNSTextElement().innerText = text
|
|
75
|
-
text.length > 0 ? this.showText() : this.hideText()
|
|
76
|
-
return this
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @inheritDoc
|
|
81
|
-
*/
|
|
82
|
-
public showText(): Nanosplash {
|
|
83
|
-
showElement(this.getNSTextElement())
|
|
84
|
-
return this
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @inheritDoc
|
|
89
|
-
*/
|
|
90
|
-
public remove(): void {
|
|
91
|
-
if (!this.element) return
|
|
92
|
-
this.element.parentElement?.removeChild(this.element)
|
|
93
|
-
delete this.element
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default Nanosplash
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
|
-
import type { GUIDString } from '../../../types/Alias'
|
|
4
|
-
import type Nanosplash from '../Nanosplash'
|
|
5
|
-
|
|
6
|
-
export interface NanosplashInterface {
|
|
7
|
-
/**
|
|
8
|
-
* # Get ID
|
|
9
|
-
* Return Nanosplash instance GUID.
|
|
10
|
-
*/
|
|
11
|
-
getId(): GUIDString
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* # Get NS Element
|
|
15
|
-
* Return Nanosplash instance HTMLDivElement.
|
|
16
|
-
*/
|
|
17
|
-
getNSElement(): HTMLDivElement
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* # Set Text
|
|
21
|
-
* @param text The text that will be visible inside the splash.
|
|
22
|
-
*/
|
|
23
|
-
setText(text: string): Nanosplash
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* # Show Text
|
|
27
|
-
* Display text element.
|
|
28
|
-
*/
|
|
29
|
-
showText(): Nanosplash
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* # Hide Text
|
|
33
|
-
* Hide the text element.
|
|
34
|
-
*/
|
|
35
|
-
hideText(): Nanosplash
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* # Remove
|
|
39
|
-
* Delete all
|
|
40
|
-
*/
|
|
41
|
-
remove(): void
|
|
42
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* # Nanosplash Repository
|
|
5
|
-
* A repository of functions that are used by the Nanosplash classes.
|
|
6
|
-
* @see Nanosplash
|
|
7
|
-
* @see NanosplashService
|
|
8
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { GUIDString } from '../../../types/Alias'
|
|
12
|
-
import type { Destination, DestinationNode } from '../../../types/Nanosplash'
|
|
13
|
-
import Nanosplash from '../Nanosplash'
|
|
14
|
-
import NanosplashService from '../services/NanosplashService'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* # Create
|
|
18
|
-
* Return the main Nanosplash element.
|
|
19
|
-
*/
|
|
20
|
-
export function createElement(): HTMLDivElement {
|
|
21
|
-
return new DOMParser().parseFromString(
|
|
22
|
-
'<div class=ns><div class=ns-content><div class=ns-text></div><div class=ns-spinner><svg viewBox="0 0 50 50"><circle class=path cx=25 cy=25 r=20 fill=none></circle></svg></div></div></div>',
|
|
23
|
-
'text/html'
|
|
24
|
-
).body.firstChild as HTMLDivElement
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* # Inject as First Child
|
|
29
|
-
* Insert the `node` into the `destinationNode` as its first child.
|
|
30
|
-
* @param node Node to inject.
|
|
31
|
-
* @param destinationNode Node in which the first node is to be injected.
|
|
32
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes
|
|
33
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
|
|
34
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
|
|
35
|
-
* @see https://developer.mozilla.org/docs/Web/API/NodeList/item
|
|
36
|
-
*/
|
|
37
|
-
export function injectAsFirstChild(
|
|
38
|
-
node: Element,
|
|
39
|
-
destinationNode: Element
|
|
40
|
-
): void {
|
|
41
|
-
const destinationNodeHasChildren = destinationNode.children.length > 0
|
|
42
|
-
if (destinationNodeHasChildren) {
|
|
43
|
-
destinationNode.insertBefore(node, destinationNode.children.item(0))
|
|
44
|
-
} else {
|
|
45
|
-
destinationNode.append(node)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* # Set NS Host Class
|
|
51
|
-
* Add or remove the `nsHostClassName` class to the `element`.
|
|
52
|
-
* @param element Element to which the `nsHostClassName` class will be added or removed.
|
|
53
|
-
* @param action Action to perform ('add' or 'remove').
|
|
54
|
-
*/
|
|
55
|
-
export function setNSHostClass(
|
|
56
|
-
element: Element | null,
|
|
57
|
-
action: 'add' | 'remove'
|
|
58
|
-
): void {
|
|
59
|
-
element?.classList[action](Nanosplash.nsHostClassName)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* # Prepare Parent
|
|
64
|
-
* Add the `nsHostClassName` class to the parent of the `ns` element.
|
|
65
|
-
* @param ns Nanosplash instance.
|
|
66
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
|
|
67
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add
|
|
68
|
-
*/
|
|
69
|
-
export function prepareParentOf(ns: Nanosplash): void {
|
|
70
|
-
setNSHostClass(ns.getNSElement().parentElement, 'add')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* # Clean Parent
|
|
75
|
-
* Remove the `nsHostClassName` class from the parent of the `ns` element.
|
|
76
|
-
* @param ns Nanosplash instance.
|
|
77
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/parentElement
|
|
78
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove
|
|
79
|
-
*/
|
|
80
|
-
export function cleanNSParentOf(ns: Nanosplash): void {
|
|
81
|
-
setNSHostClass(ns.getNSElement().parentElement, 'remove')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* # Show Element
|
|
86
|
-
* Set the `display` property of the `element` to `flex`.
|
|
87
|
-
* @param element Element to show.
|
|
88
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
89
|
-
*/
|
|
90
|
-
export function showElement(element: HTMLElement): void {
|
|
91
|
-
element.style.display = 'flex'
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* # Hide Element
|
|
96
|
-
* Set the `display` property of the `element` to `none`.
|
|
97
|
-
* @param element Element to hide.
|
|
98
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
99
|
-
*/
|
|
100
|
-
export function hideElement(element: HTMLElement): void {
|
|
101
|
-
element.style.display = 'none'
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* # Node From
|
|
106
|
-
* Convert the `destination` to a HTMLElement, Element, Node or null.
|
|
107
|
-
* @param destination Destination of the node.
|
|
108
|
-
* @returns Node from the `destination`.
|
|
109
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
110
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
111
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
112
|
-
*/
|
|
113
|
-
export function nodeFrom(destination: Destination): DestinationNode | null {
|
|
114
|
-
let elem: HTMLElement | null
|
|
115
|
-
|
|
116
|
-
if (typeof destination === 'string') {
|
|
117
|
-
elem = document.querySelector(destination)
|
|
118
|
-
} else if (destination instanceof Node) {
|
|
119
|
-
return destination
|
|
120
|
-
} else if (typeof destination === 'function') {
|
|
121
|
-
elem = <HTMLElement>destination()
|
|
122
|
-
if (!(elem instanceof Node)) {
|
|
123
|
-
return null
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
elem = null
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return elem
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* # Element Is NS
|
|
134
|
-
* Check if the element is Nanosplash element.
|
|
135
|
-
* This is determined by the presence of the `ns` class on the element.
|
|
136
|
-
* @param element Element to check.
|
|
137
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains
|
|
138
|
-
*/
|
|
139
|
-
export function elementIsNS(element: Element): boolean {
|
|
140
|
-
return element?.classList?.contains('ns')
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* # Move
|
|
145
|
-
* Move an Element to another Element.
|
|
146
|
-
* @param element Element to move
|
|
147
|
-
* @param destinationElement Target element
|
|
148
|
-
*/
|
|
149
|
-
export function move(element: Element, destinationElement: Element): void {
|
|
150
|
-
// Clean the current NS host element.
|
|
151
|
-
setNSHostClass(element.parentElement, 'remove')
|
|
152
|
-
// Assign new NS host element.
|
|
153
|
-
setNSHostClass(destinationElement, 'add')
|
|
154
|
-
injectAsFirstChild(element, destinationElement)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* # Get Recycled NS
|
|
159
|
-
* Return the Nanosplash instance inside the `destination` if it exists.
|
|
160
|
-
* @param destination Destination of the Nanosplash instance.
|
|
161
|
-
* @returns { Nanosplash | null } Nanosplash instance or null.
|
|
162
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild
|
|
163
|
-
*/
|
|
164
|
-
export function getRecycledNS(destination: Destination): Nanosplash | null {
|
|
165
|
-
const destinationNode = nodeFrom(destination)
|
|
166
|
-
if (!destinationNode) return null
|
|
167
|
-
const firstChild = <Element>destinationNode.firstChild
|
|
168
|
-
const hasChild = firstChild !== null
|
|
169
|
-
const destinationAlreadyHasNS = hasChild && elementIsNS(firstChild)
|
|
170
|
-
|
|
171
|
-
if (destinationAlreadyHasNS) {
|
|
172
|
-
const id: GUIDString = firstChild.id
|
|
173
|
-
const nss = NanosplashService.getInstance()
|
|
174
|
-
return nss.nsStack.items.find((ns: Nanosplash) => ns.getId() === id) ?? null
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return null
|
|
178
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
|
-
import Nanosplash from '../Nanosplash'
|
|
4
|
-
import Stack from '../../../util/Stack'
|
|
5
|
-
import {
|
|
6
|
-
cleanNSParentOf,
|
|
7
|
-
getRecycledNS,
|
|
8
|
-
move,
|
|
9
|
-
nodeFrom,
|
|
10
|
-
} from '../repositories/NanosplashRepository'
|
|
11
|
-
import type { Destination, DestinationNode } from '../../../types/Nanosplash'
|
|
12
|
-
import type { GUIDString } from '../../../types/Alias'
|
|
13
|
-
import { FindCallback } from '../../../types/NanosplashService'
|
|
14
|
-
import { NanosplashAPI } from '../interfaces/NanosplashAPI'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* # Nanosplash Service
|
|
18
|
-
* A service class that handles Nanosplash instances.
|
|
19
|
-
* It's a singleton class and it's instance resides in the Window object and
|
|
20
|
-
* serves the public API of the Nanosplash library.
|
|
21
|
-
* @see Nanosplash
|
|
22
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
23
|
-
*/
|
|
24
|
-
class NanosplashService implements NanosplashAPI {
|
|
25
|
-
private static readonly WindowAccessorKey = 'ns'
|
|
26
|
-
private static instance: NanosplashService
|
|
27
|
-
|
|
28
|
-
public readonly nsStack: Stack<Nanosplash>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* # Constructor
|
|
32
|
-
* Private constructor to prevent multiple instances.
|
|
33
|
-
* @private
|
|
34
|
-
*/
|
|
35
|
-
private constructor() {
|
|
36
|
-
this.nsStack = new Stack<Nanosplash>()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* # Find Index
|
|
41
|
-
* Find Nanosplash stack index by callback.
|
|
42
|
-
* @param callback Callback function that returns a boolean.
|
|
43
|
-
* @returns {number} Index of Nanosplash instance in the stack or -1.
|
|
44
|
-
*/
|
|
45
|
-
private findIndex(callback: FindCallback): number | -1 {
|
|
46
|
-
return this.nsStack.items.findIndex(callback)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* # Find
|
|
51
|
-
* Find Nanosplash in the stack by callback.
|
|
52
|
-
* @param callback Callback function that returns a boolean.
|
|
53
|
-
* @returns {Nanosplash | undefined} Nanosplash instance or undefined
|
|
54
|
-
*/
|
|
55
|
-
private find(callback: FindCallback): Nanosplash | undefined {
|
|
56
|
-
return this.nsStack.items.find(callback)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* # Get Instance
|
|
61
|
-
* Singleton instance accessor
|
|
62
|
-
* @returns {NanosplashService} NanosplashService instance
|
|
63
|
-
*/
|
|
64
|
-
public static getInstance(): NanosplashService {
|
|
65
|
-
if (!NanosplashService.instance) {
|
|
66
|
-
NanosplashService.instance = new NanosplashService()
|
|
67
|
-
}
|
|
68
|
-
return NanosplashService.instance
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* # Assign To Window
|
|
73
|
-
* Assign Nanosplash service instance to Window object.
|
|
74
|
-
* The NanosplashService instance can be accessed in the window object
|
|
75
|
-
* using the key window accessor key.
|
|
76
|
-
* @see WindowAccessorKey
|
|
77
|
-
*/
|
|
78
|
-
private static assignToWindow(): void {
|
|
79
|
-
Object.defineProperty(window, NanosplashService.WindowAccessorKey, {
|
|
80
|
-
value: NanosplashService.getInstance(),
|
|
81
|
-
writable: false,
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* # Start
|
|
87
|
-
* Initialize Nanosplash Service instance in Window when it's loaded.
|
|
88
|
-
*/
|
|
89
|
-
public static start(): void {
|
|
90
|
-
NanosplashService.assignToWindow()
|
|
91
|
-
window.addEventListener('load', () => {
|
|
92
|
-
const nss = window[NanosplashService.WindowAccessorKey]
|
|
93
|
-
const nssAssigned = nss instanceof NanosplashService
|
|
94
|
-
if (!nssAssigned) {
|
|
95
|
-
NanosplashService.assignToWindow()
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* # Create Nanosplash
|
|
102
|
-
* Return new Nanosplash instance and push it to the stack.
|
|
103
|
-
* @param text Text to display.
|
|
104
|
-
* @returns {Nanosplash} Nanosplash instance.
|
|
105
|
-
*/
|
|
106
|
-
private createNS(text?: string): Nanosplash {
|
|
107
|
-
const ns = new Nanosplash()
|
|
108
|
-
ns.setText(text || '')
|
|
109
|
-
this.nsStack.push(ns)
|
|
110
|
-
return ns
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* # Clean And Remove
|
|
115
|
-
* Remove Nanosplash from DOM and clean its parent.
|
|
116
|
-
* @param ns Nanosplash instance.
|
|
117
|
-
* @returns {GUIDString} Nanosplash ID.
|
|
118
|
-
*/
|
|
119
|
-
private cleanAndRemove(ns: Nanosplash): GUIDString {
|
|
120
|
-
cleanNSParentOf(ns)
|
|
121
|
-
ns.remove()
|
|
122
|
-
return ns.getId()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* # Stack Delete At
|
|
127
|
-
* Remove Nanosplash instance from the stack.
|
|
128
|
-
* @param ns Nanosplash instance.
|
|
129
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
130
|
-
*/
|
|
131
|
-
private stackDelete(ns: Nanosplash): GUIDString | null {
|
|
132
|
-
let index = this.findIndex((o: Nanosplash) => o.getId() === ns.getId())
|
|
133
|
-
if (index < 0) return null
|
|
134
|
-
this.nsStack.items.splice(index, 1)
|
|
135
|
-
return ns.getId()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* # Delete NS
|
|
140
|
-
* Remove Nanosplash instance from both the stack and the DOM.
|
|
141
|
-
* @param callback Callback function.
|
|
142
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
143
|
-
*/
|
|
144
|
-
private deleteNS(callback: FindCallback): GUIDString | null {
|
|
145
|
-
const ns = this.find(callback)
|
|
146
|
-
if (ns) {
|
|
147
|
-
this.cleanAndRemove(ns)
|
|
148
|
-
return this.stackDelete(ns)
|
|
149
|
-
}
|
|
150
|
-
return null
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @inheritDoc
|
|
155
|
-
*/
|
|
156
|
-
public show(text?: string): GUIDString {
|
|
157
|
-
let ns = getRecycledNS(document.body)
|
|
158
|
-
if (!ns) {
|
|
159
|
-
ns = this.createNS()
|
|
160
|
-
move(ns.getNSElement(), document.body)
|
|
161
|
-
}
|
|
162
|
-
ns.setText(text || '')
|
|
163
|
-
return ns.getId()
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @inheritDoc
|
|
168
|
-
*/
|
|
169
|
-
public showInside(
|
|
170
|
-
destination: Destination,
|
|
171
|
-
text?: string
|
|
172
|
-
): GUIDString | null {
|
|
173
|
-
const destinationNode: DestinationNode | null = nodeFrom(destination)
|
|
174
|
-
if (destinationNode) {
|
|
175
|
-
let ns = getRecycledNS(destinationNode)
|
|
176
|
-
if (!ns) {
|
|
177
|
-
ns = this.createNS()
|
|
178
|
-
}
|
|
179
|
-
ns.setText(text || '')
|
|
180
|
-
move(ns.getNSElement(), <Element>destinationNode)
|
|
181
|
-
return ns.getId()
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return null
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @inheritDoc
|
|
189
|
-
*/
|
|
190
|
-
public hideAll(): void {
|
|
191
|
-
this.nsStack.items.forEach((ns: Nanosplash) => {
|
|
192
|
-
this.cleanAndRemove(ns)
|
|
193
|
-
})
|
|
194
|
-
this.nsStack.clear()
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @inheritDoc
|
|
199
|
-
*/
|
|
200
|
-
public hide(): GUIDString | null {
|
|
201
|
-
const ns = this.nsStack.pop()
|
|
202
|
-
return ns ? this.cleanAndRemove(ns) : null
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @inheritDoc
|
|
207
|
-
*/
|
|
208
|
-
public hideId(id: GUIDString): GUIDString | null {
|
|
209
|
-
return this.deleteNS((ns: Nanosplash) => ns.getId() === id)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @inheritDoc
|
|
214
|
-
*/
|
|
215
|
-
public hideInside(destination: Destination): GUIDString | null {
|
|
216
|
-
const node = nodeFrom(destination)
|
|
217
|
-
const cb = (ns: Nanosplash) => ns.getNSElement().parentElement === node
|
|
218
|
-
return node ? this.deleteNS(cb) : null
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export default NanosplashService
|
package/src/ts/types/Alias.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type GUIDString = string
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type DestinationSelector = string
|
|
2
|
-
|
|
3
|
-
export type DestinationNode = Node | Element | HTMLElement
|
|
4
|
-
|
|
5
|
-
export type DestinationCallback = () =>
|
|
6
|
-
| DestinationNode
|
|
7
|
-
| Promise<DestinationNode>
|
|
8
|
-
|
|
9
|
-
export type Destination =
|
|
10
|
-
| DestinationSelector
|
|
11
|
-
| DestinationNode
|
|
12
|
-
| DestinationCallback
|
|
13
|
-
|
|
14
|
-
declare global {
|
|
15
|
-
interface Window {
|
|
16
|
-
ns: NanosplashService
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type FindCallback = (ns: Nanosplash, index: number) => boolean
|
package/src/ts/util/Guid.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { GUIDString } from '../types/Alias'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* # GUID
|
|
5
|
-
* @returns {GUIDString} A GUID string.
|
|
6
|
-
*/
|
|
7
|
-
export function guid(): GUIDString {
|
|
8
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
9
|
-
const r = (Math.random() * 16) | 0
|
|
10
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
11
|
-
return v.toString(16)
|
|
12
|
-
})
|
|
13
|
-
}
|
package/src/ts/util/Stack.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A stack data structure.
|
|
5
|
-
* @template T The type of item stored in the stack.
|
|
6
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
7
|
-
*/
|
|
8
|
-
class Stack<T> {
|
|
9
|
-
private _items: T[]
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Constructs a new stack.
|
|
13
|
-
*/
|
|
14
|
-
constructor() {
|
|
15
|
-
this._items = []
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns the items in the stack.
|
|
20
|
-
*/
|
|
21
|
-
public get items(): T[] {
|
|
22
|
-
return this._items
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Adds an item to the top of the stack.
|
|
27
|
-
* @param item The item to add to the stack.
|
|
28
|
-
*/
|
|
29
|
-
public push(item: T): void {
|
|
30
|
-
this._items.push(item)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Removes and returns the item at the top of the stack.
|
|
35
|
-
* @returns The item at the top of the stack, or undefined if the stack is empty.
|
|
36
|
-
*/
|
|
37
|
-
public pop(): T | undefined {
|
|
38
|
-
return this._items.pop()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Returns the item at the top of the stack without removing it.
|
|
43
|
-
* @returns The item at the top of the stack, or undefined if the stack is empty.
|
|
44
|
-
*/
|
|
45
|
-
public peek(): T | undefined {
|
|
46
|
-
return this._items[this._items.length - 1]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns true if the stack is empty, false otherwise.
|
|
51
|
-
* @returns True if the stack is empty, false otherwise.
|
|
52
|
-
*/
|
|
53
|
-
public isEmpty(): boolean {
|
|
54
|
-
return this._items.length === 0
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns the number of items in the stack.
|
|
59
|
-
* @returns The number of items in the stack.
|
|
60
|
-
*/
|
|
61
|
-
public size(): number {
|
|
62
|
-
return this._items.length
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Removes all items from the stack.
|
|
67
|
-
*/
|
|
68
|
-
public clear(): void {
|
|
69
|
-
this._items = []
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export default Stack
|