nanosplash 3.0.8 → 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/.prettierrc +1 -1
- package/README.md +52 -4
- package/bun.lockb +0 -0
- package/dist/cjs/ns.cjs +1 -2
- package/dist/es/ns.js +42 -340
- package/dist/iife/ns.iife.js +1 -2
- 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.ts → config.mts} +46 -44
- package/docs/.vitepress/theme/css/style.css +107 -6
- package/docs/.vitepress/theme/vue/CardGrid.vue +1 -1
- package/docs/.vitepress/theme/vue/Exe.vue +58 -28
- package/docs/.vitepress/theme/vue/PlayGround.vue +5 -21
- package/docs/api/doc/hide.md +12 -33
- package/docs/api/doc/show.md +12 -13
- package/docs/api/start/customize.md +30 -0
- package/docs/api/start/features.md +3 -3
- package/docs/api/start/install.md +12 -8
- package/docs/api/start/playground.md +1 -1
- package/docs/api/start/usage.md +4 -7
- package/docs/index.md +25 -25
- package/docs/public/macos.jpg +0 -0
- package/eslint.config.js +9 -0
- package/package.json +54 -48
- package/src/style/ns.sass +98 -73
- package/src/ts/Nanosplash.ts +209 -0
- package/src/ts/main.ts +2 -8
- package/src/ts/types/NanosplashInterface.ts +26 -0
- package/src/ts/types/Types.ts +29 -3
- package/src/ts/types/global.d.ts +9 -9
- package/tests/Nanosplash.spec.ts +33 -0
- package/.prettierignore +0 -1
- package/src/ts/core/DomUtilities.ts +0 -161
- package/src/ts/core/Service.ts +0 -211
- package/src/ts/core/ServiceInterface.ts +0 -58
- package/src/ts/core/Splash.ts +0 -121
- package/src/ts/core/SplashInterface.ts +0 -46
- package/src/ts/core/SplashQueue.ts +0 -49
- package/tests/DomUtilities.spec.ts +0 -117
- package/tests/Guid.spec.ts +0 -21
- package/tests/Service.spec.ts +0 -198
- package/tests/Splash.spec.ts +0 -64
- package/tests/TestUtilities.ts +0 -48
package/src/ts/types/Types.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type
|
|
1
|
+
import { NanosplashInterface } from './NanosplashInterface'
|
|
2
|
+
|
|
3
|
+
export type Integer = number
|
|
4
|
+
export type UTCInteger = Integer
|
|
5
|
+
export type DOMSelector = string
|
|
6
|
+
export type ElementReference = DOMSelector | Element
|
|
7
|
+
|
|
8
|
+
export interface ScopedSelectors {
|
|
9
|
+
/**
|
|
10
|
+
* @param selector Selector to match with a DOM element.
|
|
11
|
+
* @returns An array of elements matching with the selector.
|
|
12
|
+
*/
|
|
13
|
+
all: (selector: DOMSelector) => Element[]
|
|
14
|
+
/**
|
|
15
|
+
* @param selector Selector to match with a DOM element.
|
|
16
|
+
* @returns Null or the first element in the DOM to match the selector.
|
|
17
|
+
*/
|
|
18
|
+
first: (selector: DOMSelector) => Element | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface NSElement extends HTMLDivElement {
|
|
22
|
+
nsId: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window {
|
|
27
|
+
ns: NanosplashInterface
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/ts/types/global.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ServiceInterface } from '../core/ServiceInterface'
|
|
1
|
+
import { NanosplashInterface } from './NanosplashInterface'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
interface IWindow {
|
|
4
|
+
ns: NanosplashInterface
|
|
5
|
+
}
|
|
5
6
|
|
|
6
7
|
declare global {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ns: ServiceInterface
|
|
8
|
+
interface Window extends IWindow {}
|
|
9
|
+
interface window extends IWindow {}
|
|
10
|
+
interface globalThis extends globalThis {
|
|
11
|
+
Window: IWindow
|
|
12
|
+
window: IWindow
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, test, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { useNs } from '../src/ts/Nanosplash'
|
|
3
|
+
import { JSDOM } from 'jsdom'
|
|
4
|
+
import { NanosplashInterface } from '../src/ts/types/NanosplashInterface'
|
|
5
|
+
|
|
6
|
+
let document: Document | null = null
|
|
7
|
+
let ns: NanosplashInterface | null = null
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
const dom = new JSDOM()
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
globalThis.window = dom.window
|
|
13
|
+
document = globalThis.document = dom.window.document
|
|
14
|
+
ns = globalThis.window.ns = useNs()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('Nanosplash API', () => {
|
|
18
|
+
it('should be defined', () => {
|
|
19
|
+
expect(window.ns).toBeDefined()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should have the "show" method', () => {
|
|
23
|
+
expect(window.ns.show).toBeDefined()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should have the "hide" method', () => {
|
|
27
|
+
expect(window.ns.hide).toBeDefined()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should have the global instance', () => {
|
|
31
|
+
expect(window.ns).toBe(ns)
|
|
32
|
+
})
|
|
33
|
+
})
|
package/.prettierignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*.sass
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Reference } from '../types/Types'
|
|
2
|
-
import { Service } from './Service'
|
|
3
|
-
import { Splash } from './Splash'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* # DOM Utilities
|
|
7
|
-
* A collection of functions that are used by the Nanosplash classes.
|
|
8
|
-
* @see Splash
|
|
9
|
-
* @see Service
|
|
10
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
11
|
-
*/
|
|
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
|
-
|
|
26
|
-
/**
|
|
27
|
-
* # Create Element
|
|
28
|
-
* Return the main Nanosplash element.
|
|
29
|
-
*/
|
|
30
|
-
export function createElement(): 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
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* # Inject as First Child
|
|
38
|
-
* Insert element into the target element as its first child.
|
|
39
|
-
* @param element Element to inject.
|
|
40
|
-
* @param targetElement Element in which the first element is to be injected.
|
|
41
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/children
|
|
42
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
|
|
43
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
|
|
44
|
-
* @see https://developer.mozilla.org/docs/Web/API/NodeList/item
|
|
45
|
-
*/
|
|
46
|
-
export function injectAsFirstChild(
|
|
47
|
-
element: Element,
|
|
48
|
-
targetElement: Element
|
|
49
|
-
): void {
|
|
50
|
-
const targetHasChild = targetElement.children.length > 0
|
|
51
|
-
if (targetHasChild) {
|
|
52
|
-
targetElement.insertBefore(element, targetElement.children.item(0))
|
|
53
|
-
} else {
|
|
54
|
-
targetElement.append(element)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
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.
|
|
62
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
|
|
63
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add
|
|
64
|
-
*/
|
|
65
|
-
export function addNSHostClass(element: Element | null): void {
|
|
66
|
-
element?.classList.add(Splash.NSHostClass)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
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
|
|
75
|
-
*/
|
|
76
|
-
export function removeNSHostClass(element: Element | null): void {
|
|
77
|
-
element?.classList.remove(Splash.NSHostClass)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* # Show Element
|
|
82
|
-
* Set the `display` property of the `element` to `flex`.
|
|
83
|
-
* @param element Element to show.
|
|
84
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
85
|
-
*/
|
|
86
|
-
export function showElement(element: HTMLElement): void {
|
|
87
|
-
element.style.display = 'flex'
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* # Hide Element
|
|
92
|
-
* Set the `display` property of the `element` to `none`.
|
|
93
|
-
* @param element Element to hide.
|
|
94
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
|
|
95
|
-
*/
|
|
96
|
-
export function hideElement(element: HTMLElement): void {
|
|
97
|
-
element.style.display = 'none'
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* # Element From
|
|
102
|
-
* Convert the element reference to an element.
|
|
103
|
-
* @param ref Reference to an element.
|
|
104
|
-
* @returns { Element | null } Element or null.
|
|
105
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
106
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
107
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
108
|
-
*/
|
|
109
|
-
export function elementFrom(ref: Reference): Element | null {
|
|
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
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* # Move
|
|
129
|
-
* Move an Element to another Element.
|
|
130
|
-
* @param element Element to move
|
|
131
|
-
* @param targetElement Target element
|
|
132
|
-
*/
|
|
133
|
-
export function move(element: Element, targetElement: Element): void {
|
|
134
|
-
// Clean the current NS host element.
|
|
135
|
-
removeNSHostClass(element.parentElement)
|
|
136
|
-
// Assign new NS host element.
|
|
137
|
-
addNSHostClass(targetElement)
|
|
138
|
-
injectAsFirstChild(element, targetElement)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* # Get Recycled NS
|
|
143
|
-
* Return the Nanosplash instance inside the target element if it exists.
|
|
144
|
-
* @param targetElement Element wherein the Nanosplash instance is to reside.
|
|
145
|
-
* @returns { Nanosplash | null } Nanosplash instance or null.
|
|
146
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/firstElementChild
|
|
147
|
-
*/
|
|
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
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return splash
|
|
161
|
-
}
|
package/src/ts/core/Service.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { version } from '../../../package.json'
|
|
2
|
-
|
|
3
|
-
import { Reference, GUIDString } from '../types/Types'
|
|
4
|
-
import {
|
|
5
|
-
getRecycledSplash,
|
|
6
|
-
move,
|
|
7
|
-
elementFrom,
|
|
8
|
-
render,
|
|
9
|
-
removeNSHostClass,
|
|
10
|
-
} from './DomUtilities'
|
|
11
|
-
import { ServiceInterface } from './ServiceInterface'
|
|
12
|
-
import { Splash } from './Splash'
|
|
13
|
-
import css from '../../style/ns.sass?inline'
|
|
14
|
-
import { SplashQueue } from './SplashQueue'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* # Service
|
|
18
|
-
* A service class that handles Nanosplash instances.
|
|
19
|
-
* It's a singleton class and its instance resides in the Window object and
|
|
20
|
-
* serves the public API of the Nanosplash library.
|
|
21
|
-
* @see Splash
|
|
22
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
23
|
-
*/
|
|
24
|
-
export class Service implements ServiceInterface {
|
|
25
|
-
/**
|
|
26
|
-
* # Window Accessor Key
|
|
27
|
-
* Key to access NanosplashService instance in the Window object.
|
|
28
|
-
*/
|
|
29
|
-
public static readonly WindowAccessorKey = 'ns'
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* # Instance
|
|
33
|
-
* Singleton instance of NanosplashService.
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
private static instance: Service
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* # Version
|
|
40
|
-
*/
|
|
41
|
-
public readonly version: string
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @inheritdoc
|
|
45
|
-
*/
|
|
46
|
-
public readonly nsQueue: SplashQueue
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* # Constructor
|
|
50
|
-
* Private constructor to prevent multiple instances.
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
private constructor() {
|
|
54
|
-
this.version = version
|
|
55
|
-
this.nsQueue = new SplashQueue()
|
|
56
|
-
Service.addStyle()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**e
|
|
60
|
-
* # Add Style
|
|
61
|
-
* Add Nanosplash CSS to the DOM.
|
|
62
|
-
*/
|
|
63
|
-
private static addStyle(): void {
|
|
64
|
-
const style = render(`<style>${css}</style>`) as HTMLStyleElement
|
|
65
|
-
document.body.append(style)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* # Get Instance
|
|
70
|
-
* Singleton instance accessor
|
|
71
|
-
* @returns {Service} NanosplashService instance
|
|
72
|
-
*/
|
|
73
|
-
public static getInstance(): Service {
|
|
74
|
-
if (!Service.instance) {
|
|
75
|
-
Service.instance = new Service()
|
|
76
|
-
}
|
|
77
|
-
return Service.instance
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* # Assign To Window
|
|
82
|
-
* Assign a NanosplashService instance to the Window object.
|
|
83
|
-
* The NanosplashService instance can be accessed in the window object
|
|
84
|
-
* using the key window accessor key.
|
|
85
|
-
* @see WindowAccessorKey
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
private static assignToWindow(): void {
|
|
89
|
-
Object.defineProperty(window, Service.WindowAccessorKey, {
|
|
90
|
-
value: Service.getInstance(),
|
|
91
|
-
writable: false,
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* # Start
|
|
97
|
-
* Initialize and attach a Nanosplash Service instance to the Window object.
|
|
98
|
-
*/
|
|
99
|
-
public static start(): void {
|
|
100
|
-
const nss = window[Service.WindowAccessorKey]
|
|
101
|
-
if (!nss) {
|
|
102
|
-
Service.assignToWindow()
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* # Create Nanosplash
|
|
108
|
-
* Return new Nanosplash instance and push it to the stack.
|
|
109
|
-
* @param text Text to display.
|
|
110
|
-
* @returns {Splash} Nanosplash instance.
|
|
111
|
-
* @private
|
|
112
|
-
*/
|
|
113
|
-
private createNS(text?: string): Splash {
|
|
114
|
-
const ns = new Splash().setText(text || '')
|
|
115
|
-
this.nsQueue.enqueue(ns)
|
|
116
|
-
return ns
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* # Clean And Remove From DOM
|
|
121
|
-
* Remove Nanosplash from DOM and clean its parent.
|
|
122
|
-
* @param ns Nanosplash instance.
|
|
123
|
-
* @returns True if Nanosplash was removed from DOM.
|
|
124
|
-
* @private
|
|
125
|
-
*/
|
|
126
|
-
private cleanAndRemoveFromDOM(ns: Splash | null): boolean {
|
|
127
|
-
if (ns) {
|
|
128
|
-
removeNSHostClass(ns.getElement()?.parentElement ?? null)
|
|
129
|
-
return ns.delete()
|
|
130
|
-
}
|
|
131
|
-
return false
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* # Delete NS
|
|
136
|
-
* Remove Nanosplash instance from both the stack and the
|
|
137
|
-
* @param guid Nanosplash ID.
|
|
138
|
-
* @returns True if Nanosplash was removed from DOM.
|
|
139
|
-
* @private
|
|
140
|
-
*/
|
|
141
|
-
private deleteNS(guid: GUIDString): boolean {
|
|
142
|
-
return this.cleanAndRemoveFromDOM(this.nsQueue.delete(guid) ?? null)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @inheritdoc
|
|
147
|
-
*/
|
|
148
|
-
public show(text?: string): GUIDString | null {
|
|
149
|
-
return this.showInside(document.body, text)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @inheritdoc
|
|
154
|
-
*/
|
|
155
|
-
public showInside(ref: Reference, text?: string): GUIDString | null {
|
|
156
|
-
try {
|
|
157
|
-
const destinationNode = elementFrom(ref) as Element
|
|
158
|
-
const ns = getRecycledSplash(destinationNode) ?? this.createNS()
|
|
159
|
-
move(ns.getElement() as Element, destinationNode)
|
|
160
|
-
const parsedText = text ? String(text) : ''
|
|
161
|
-
return ns.setText(parsedText).getId()
|
|
162
|
-
} catch (e) {
|
|
163
|
-
console.error(e)
|
|
164
|
-
return null
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @inheritdoc
|
|
170
|
-
*/
|
|
171
|
-
public hide(): GUIDString | null {
|
|
172
|
-
const ns = this.nsQueue.dequeue()
|
|
173
|
-
if (!ns) return null
|
|
174
|
-
this.cleanAndRemoveFromDOM(ns)
|
|
175
|
-
return ns.getId()
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @inheritdoc
|
|
180
|
-
*/
|
|
181
|
-
public hideAll(): void {
|
|
182
|
-
let ns = this.nsQueue.dequeue()
|
|
183
|
-
while (ns) {
|
|
184
|
-
this.cleanAndRemoveFromDOM(ns)
|
|
185
|
-
ns = this.nsQueue.dequeue()
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @inheritdoc
|
|
191
|
-
*/
|
|
192
|
-
public hideId(id: GUIDString): GUIDString | null {
|
|
193
|
-
return this.deleteNS(id) ? id : null
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @inheritdoc
|
|
198
|
-
*/
|
|
199
|
-
public hideInside(ref: Reference): GUIDString | null {
|
|
200
|
-
try {
|
|
201
|
-
const ns = getRecycledSplash(elementFrom(ref) as Element)
|
|
202
|
-
const guid = ns?.getId() ?? ''
|
|
203
|
-
return this.deleteNS(guid ?? '') ? guid : null
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error(e)
|
|
206
|
-
return null
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export default { Service }
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { GUIDString, Reference } from '../types/Types'
|
|
2
|
-
import { SplashQueue } from './SplashQueue'
|
|
3
|
-
|
|
4
|
-
export interface ServiceInterface {
|
|
5
|
-
/**
|
|
6
|
-
* # Nanosplash Stack
|
|
7
|
-
* For each Nanosplash instance created, it's pushed to the stack.
|
|
8
|
-
* When a Nanosplash instance is removed, it's removed from the stack.
|
|
9
|
-
* @see Splash
|
|
10
|
-
*/
|
|
11
|
-
readonly nsQueue: SplashQueue
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* # Show
|
|
15
|
-
* Present a Nanosplash in the browser window displaying the given text.
|
|
16
|
-
* @param text Text to display.
|
|
17
|
-
* @returns {GUIDString | null} Nanosplash ID.
|
|
18
|
-
*/
|
|
19
|
-
show(text?: string): GUIDString | null
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* # Show Inside
|
|
23
|
-
* Present a Nanosplash over the given element displaying the given text.
|
|
24
|
-
* @param ref Reference an element.
|
|
25
|
-
* @param text Text to display.
|
|
26
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
27
|
-
*/
|
|
28
|
-
showInside(ref: Reference, text?: string): GUIDString | null
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* # Hide
|
|
32
|
-
* Hide the oldest Nanosplash.
|
|
33
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
34
|
-
*/
|
|
35
|
-
hide(): GUIDString | null
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* # Hide All
|
|
39
|
-
* Hide all Nanosplashes.
|
|
40
|
-
*/
|
|
41
|
-
hideAll(): void
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* # Hide ID
|
|
45
|
-
* Hide Nanosplash by its ID.
|
|
46
|
-
* @param id Nanosplash ID.
|
|
47
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
48
|
-
*/
|
|
49
|
-
hideId(id: GUIDString): GUIDString | null
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* # Hide Inside
|
|
53
|
-
* Hide Nanosplash inside the given element if it exists.
|
|
54
|
-
* @param ref Reference an element.
|
|
55
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
56
|
-
*/
|
|
57
|
-
hideInside(ref: Reference): GUIDString | null
|
|
58
|
-
}
|
package/src/ts/core/Splash.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { GUIDString } from '../types/Types'
|
|
2
|
-
import { createElement, showElement, hideElement } from './DomUtilities'
|
|
3
|
-
import { SplashInterface } from './SplashInterface'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* # Splash
|
|
7
|
-
* Small splash screen that can be used to indicate that a process
|
|
8
|
-
* is running.
|
|
9
|
-
* @author Isak K. Hauge <isakhauge@icloud.com>
|
|
10
|
-
*/
|
|
11
|
-
export class Splash implements SplashInterface {
|
|
12
|
-
/**
|
|
13
|
-
* # CSS Class Name
|
|
14
|
-
* The main CSS class name of the root element of a Nanosplash component.
|
|
15
|
-
*/
|
|
16
|
-
public static readonly NSClass = 'ns'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* # Host CSS Class Name
|
|
20
|
-
* The CSS class name of the host element of a Nanosplash component.
|
|
21
|
-
* The host element is the element that the Nanosplash is attached to.
|
|
22
|
-
*/
|
|
23
|
-
public static readonly NSHostClass = 'nsh'
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* # ID
|
|
27
|
-
* Each Nanosplash instance is given a unique GUID.
|
|
28
|
-
*/
|
|
29
|
-
private id: GUIDString | null
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* # Element
|
|
33
|
-
* The root element of the Nanosplash component.
|
|
34
|
-
*/
|
|
35
|
-
private element: HTMLDivElement | null
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* # Generate GUID
|
|
39
|
-
* @returns {GUIDString} A GUID string.
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
private static generateGUID(): GUIDString {
|
|
43
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
44
|
-
const r = (Math.random() * 16) | 0
|
|
45
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
46
|
-
return v.toString(16)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* # Constructor
|
|
52
|
-
* Creates a new Nanosplash instance.
|
|
53
|
-
*/
|
|
54
|
-
public constructor() {
|
|
55
|
-
this.element = createElement()
|
|
56
|
-
this.element.id = this.id = Splash.generateGUID()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @inheritdoc
|
|
61
|
-
*/
|
|
62
|
-
public getId(): GUIDString | null {
|
|
63
|
-
return this.id
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @inheritdoc
|
|
68
|
-
*/
|
|
69
|
-
public getElement(): HTMLDivElement | null {
|
|
70
|
-
return <HTMLDivElement>this.element
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @inheritdoc
|
|
75
|
-
*/
|
|
76
|
-
public getTextElement(): HTMLDivElement {
|
|
77
|
-
return (
|
|
78
|
-
<HTMLDivElement>(
|
|
79
|
-
this.getElement()?.firstElementChild?.firstElementChild
|
|
80
|
-
) ?? null
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @inheritdoc
|
|
86
|
-
*/
|
|
87
|
-
public setText(text: string): Splash {
|
|
88
|
-
this.getTextElement().innerText = text
|
|
89
|
-
text.length > 0 ? this.showText() : this.hideText()
|
|
90
|
-
return this
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @inheritdoc
|
|
95
|
-
*/
|
|
96
|
-
public showText(): Splash {
|
|
97
|
-
showElement(this.getTextElement())
|
|
98
|
-
return this
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @inheritdoc
|
|
103
|
-
*/
|
|
104
|
-
public hideText(): Splash {
|
|
105
|
-
hideElement(this.getTextElement())
|
|
106
|
-
return this
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @inheritdoc
|
|
111
|
-
*/
|
|
112
|
-
public delete(): boolean {
|
|
113
|
-
this.id = null
|
|
114
|
-
if (this.element !== null) {
|
|
115
|
-
this.element.innerHTML = ''
|
|
116
|
-
this.element.remove()
|
|
117
|
-
this.element = null
|
|
118
|
-
}
|
|
119
|
-
return this.element === null
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { GUIDString } from '../types/Types'
|
|
2
|
-
import { Splash } from './Splash'
|
|
3
|
-
|
|
4
|
-
export interface SplashInterface {
|
|
5
|
-
/**
|
|
6
|
-
* # Get ID
|
|
7
|
-
* Return Nanosplash instance GUID.
|
|
8
|
-
*/
|
|
9
|
-
getId(): GUIDString | null
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* # Get Element
|
|
13
|
-
* Return Nanosplash instance HTMLDivElement.
|
|
14
|
-
*/
|
|
15
|
-
getElement(): HTMLDivElement | null
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* # Get Text Element
|
|
19
|
-
* Returns the text element of the Nanosplash.
|
|
20
|
-
*/
|
|
21
|
-
getTextElement(): HTMLDivElement | null
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* # Set Text
|
|
25
|
-
* @param text The text that will be visible inside the splash.
|
|
26
|
-
*/
|
|
27
|
-
setText(text: string): Splash
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* # Show Text
|
|
31
|
-
* Display text element.
|
|
32
|
-
*/
|
|
33
|
-
showText(): Splash
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* # Hide Text
|
|
37
|
-
* Hide the text element.
|
|
38
|
-
*/
|
|
39
|
-
hideText(): Splash
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* # Delete
|
|
43
|
-
* Remove from DOM and delete internal data.
|
|
44
|
-
*/
|
|
45
|
-
delete(): boolean
|
|
46
|
-
}
|