nanosplash 3.0.0 → 3.0.1

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +151 -17
  3. package/coverage/base.css +224 -0
  4. package/coverage/block-navigation.js +87 -0
  5. package/coverage/clover.xml +555 -0
  6. package/coverage/core/Dom.ts.html +565 -0
  7. package/coverage/core/Service.ts.html +790 -0
  8. package/coverage/core/Splash.ts.html +457 -0
  9. package/coverage/core/index.html +146 -0
  10. package/coverage/coverage-final.json +9043 -0
  11. package/coverage/favicon.png +0 -0
  12. package/coverage/index.html +131 -0
  13. package/coverage/prettify.css +1 -0
  14. package/coverage/prettify.js +2 -0
  15. package/coverage/sort-arrow-sprite.png +0 -0
  16. package/coverage/sorter.js +196 -0
  17. package/coverage/types/Types.ts.html +121 -0
  18. package/coverage/types/index.html +116 -0
  19. package/dist/latest/cjs/ns.cjs +1 -0
  20. package/dist/latest/cjs/style.css +1 -0
  21. package/dist/latest/es/ns.js +306 -0
  22. package/dist/latest/es/style.css +1 -0
  23. package/dist/latest/iife/ns.iife.js +4 -0
  24. package/dist/versioned/3.0.1/cjs/ns.cjs +1 -0
  25. package/dist/versioned/3.0.1/cjs/style.css +1 -0
  26. package/dist/versioned/3.0.1/es/ns.js +306 -0
  27. package/dist/versioned/3.0.1/es/style.css +1 -0
  28. package/dist/versioned/3.0.1/iife/ns.iife.js +2 -0
  29. package/docs/index.6d66a821.js +1 -0
  30. package/docs/index.74dbd99e.css +1 -0
  31. package/docs/index.f34144dc.js +1 -0
  32. package/docs/index.html +107 -0
  33. package/index.html +90 -37
  34. package/package.json +41 -20
  35. package/src/sass/ns.sass +38 -29
  36. package/src/ts/core/Dom.ts +160 -0
  37. package/src/ts/core/Service.ts +235 -0
  38. package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +17 -7
  39. package/src/ts/core/Splash.ts +124 -0
  40. package/src/ts/core/SplashInterface.ts +54 -0
  41. package/src/ts/main.ts +9 -0
  42. package/src/ts/types/Types.ts +12 -0
  43. package/src/ts/types/global.d.ts +14 -0
  44. package/src/vite-env.d.ts +0 -8
  45. package/tests/Dom.spec.ts +127 -0
  46. package/tests/Guid.spec.ts +2 -2
  47. package/tests/{NanosplashService.spec.ts → Service.spec.ts} +18 -18
  48. package/tests/{Nanosplash.spec.ts → Splash.spec.ts} +9 -9
  49. package/tsconfig.json +20 -20
  50. package/vite.config.ts +28 -22
  51. package/vite.demo.config.ts +16 -0
  52. package/dist/main.css +0 -1
  53. package/dist/ns.cjs.js +0 -1
  54. package/dist/ns.es.js +0 -330
  55. package/dist/ns.iife.js +0 -2
  56. package/src/main.ts +0 -8
  57. package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
  58. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
  59. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
  60. package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
  61. package/src/ts/types/Alias.d.ts +0 -1
  62. package/src/ts/types/Nanosplash.d.ts +0 -18
  63. package/src/ts/types/NanosplashService.d.ts +0 -1
  64. package/src/ts/util/Guid.ts +0 -13
  65. package/src/ts/util/Stack.ts +0 -73
  66. package/tests/NanosplashRepository.spec.ts +0 -91
  67. package/tests/Stack.spec.ts +0 -56
@@ -0,0 +1,235 @@
1
+ // @ts-strict
2
+
3
+ import { version } from '../../../package.json'
4
+ import '../../sass/ns.sass'
5
+
6
+ import { NSFinder, GUIDString, Reference } from '../types/Types'
7
+ import { cleanNSParentOf, getRecycledNS, move, elementFrom } from './Dom'
8
+ import { ServiceInterface } from './ServiceInterface'
9
+ import { Splash } from './Splash'
10
+
11
+ /**
12
+ * # Service
13
+ * A service class that handles Nanosplash instances.
14
+ * It's a singleton class and its instance resides in the Window object and
15
+ * serves the public API of the Nanosplash library.
16
+ * @see Splash
17
+ * @author Isak K. Hauge <isakhauge@icloud.com>
18
+ */
19
+ export class Service implements ServiceInterface {
20
+ /**
21
+ * # Window Accessor Key
22
+ * Key to access NanosplashService instance in the Window object.
23
+ */
24
+ public static readonly WindowAccessorKey = 'ns'
25
+
26
+ /**
27
+ * # Instance
28
+ * Singleton instance of NanosplashService.
29
+ * @private
30
+ */
31
+ private static instance: Service
32
+
33
+ /**
34
+ * # Version
35
+ */
36
+ public readonly version: string
37
+
38
+ /**
39
+ * @inheritdoc
40
+ */
41
+ public readonly nsStack: Splash[]
42
+
43
+ /**
44
+ * # Constructor
45
+ * Private constructor to prevent multiple instances.
46
+ * @private
47
+ */
48
+ private constructor() {
49
+ this.version = version
50
+ this.nsStack = []
51
+ }
52
+
53
+ /**
54
+ * # Find Index
55
+ * Find Nanosplash stack index by callback.
56
+ * @param callback Callback function that returns a boolean.
57
+ * @returns {number} Index of Nanosplash instance in the stack or -1.
58
+ * @private
59
+ */
60
+ private findIndex(callback: NSFinder): number | -1 {
61
+ return this.nsStack.findIndex(callback)
62
+ }
63
+
64
+ /**
65
+ * # Find
66
+ * Find Nanosplash in the stack by callback.
67
+ * @param callback Callback function that returns a boolean.
68
+ * @returns {Splash | undefined} Nanosplash instance or undefined
69
+ * @private
70
+ */
71
+ private find(callback: NSFinder): Splash | undefined {
72
+ return this.nsStack.find(callback)
73
+ }
74
+
75
+ /**
76
+ * # Get Instance
77
+ * Singleton instance accessor
78
+ * @returns {Service} NanosplashService instance
79
+ */
80
+ public static getInstance(): Service {
81
+ if (!Service.instance) {
82
+ Service.instance = new Service()
83
+ }
84
+ return Service.instance
85
+ }
86
+
87
+ /**
88
+ * # Assign To Window
89
+ * Assign a NanosplashService instance to the Window object.
90
+ * The NanosplashService instance can be accessed in the window object
91
+ * using the key window accessor key.
92
+ * @see WindowAccessorKey
93
+ * @private
94
+ */
95
+ private static assignToWindow(): void {
96
+ Object.defineProperty(window, Service.WindowAccessorKey, {
97
+ value: Service.getInstance(),
98
+ writable: false,
99
+ })
100
+ }
101
+
102
+ /**
103
+ * # Start
104
+ * Initialize and attach a Nanosplash Service instance to the Window object.
105
+ */
106
+ public static start(): void {
107
+ Service.assignToWindow()
108
+ window.addEventListener('load', () => {
109
+ const nss = window[Service.WindowAccessorKey]
110
+ const nssAssigned = nss instanceof Service
111
+ if (!nssAssigned) {
112
+ Service.assignToWindow()
113
+ }
114
+ })
115
+ }
116
+
117
+ /**
118
+ * # Create Nanosplash
119
+ * Return new Nanosplash instance and push it to the stack.
120
+ * @param text Text to display.
121
+ * @returns {Splash} Nanosplash instance.
122
+ * @private
123
+ */
124
+ private createNS(text?: string): Splash {
125
+ const ns = new Splash()
126
+ ns.setText(text || '')
127
+ this.nsStack.push(ns)
128
+ return ns
129
+ }
130
+
131
+ /**
132
+ * # Clean And Remove
133
+ * Remove Nanosplash from DOM and clean its parent.
134
+ * @param ns Nanosplash instance.
135
+ * @returns {GUIDString} Nanosplash ID.
136
+ * @private
137
+ */
138
+ private cleanAndRemove(ns: Splash): GUIDString {
139
+ cleanNSParentOf(ns)
140
+ return ns.remove().getId()
141
+ }
142
+
143
+ /**
144
+ * # Stack Delete
145
+ * Remove Nanosplash instance from the stack.
146
+ * @param ns Nanosplash instance.
147
+ * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
148
+ * @private
149
+ */
150
+ private stackDelete(ns: Splash): GUIDString | null {
151
+ let index = this.findIndex((o: Splash) => o.getId() === ns.getId())
152
+ if (index < 0) return null
153
+ this.nsStack.splice(index, 1)
154
+ return ns.getId()
155
+ }
156
+
157
+ /**
158
+ * # Delete NS
159
+ * Remove Nanosplash instance from both the stack and the
160
+ * @param callback Callback function.
161
+ * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
162
+ * @private
163
+ */
164
+ private deleteNS(callback: NSFinder): GUIDString | null {
165
+ const ns = this.find(callback)
166
+ if (ns) {
167
+ this.cleanAndRemove(ns)
168
+ return this.stackDelete(ns)
169
+ }
170
+ return null
171
+ }
172
+
173
+ /**
174
+ * @inheritdoc
175
+ */
176
+ public show(text?: string): GUIDString {
177
+ let ns = getRecycledNS(document.body)
178
+ if (!ns) {
179
+ ns = this.createNS()
180
+ move(ns.getNSElement(), document.body)
181
+ }
182
+ return ns.setText(text || '').getId()
183
+ }
184
+
185
+ /**
186
+ * @inheritdoc
187
+ */
188
+ public showInside(ref: Reference, text?: string): GUIDString | null {
189
+ const destinationNode: Element | null = elementFrom(ref)
190
+ if (destinationNode) {
191
+ let ns = getRecycledNS(destinationNode)
192
+ if (!ns) {
193
+ ns = this.createNS()
194
+ }
195
+ move(ns.getNSElement(), <Element>destinationNode)
196
+ return ns.setText(text || '').getId()
197
+ }
198
+
199
+ return null
200
+ }
201
+
202
+ /**
203
+ * @inheritdoc
204
+ */
205
+ public hide(): GUIDString | null {
206
+ const ns = this.nsStack.pop()
207
+ return ns ? this.cleanAndRemove(ns) : null
208
+ }
209
+
210
+ /**
211
+ * @inheritdoc
212
+ */
213
+ public hideAll(): void {
214
+ this.nsStack.forEach(this.cleanAndRemove)
215
+ this.nsStack.splice(0, this.nsStack.length)
216
+ }
217
+
218
+ /**
219
+ * @inheritdoc
220
+ */
221
+ public hideId(id: GUIDString): GUIDString | null {
222
+ return this.deleteNS((ns: Splash) => ns.getId() === id)
223
+ }
224
+
225
+ /**
226
+ * @inheritdoc
227
+ */
228
+ public hideInside(ref: Reference): GUIDString | null {
229
+ const node = elementFrom(ref)
230
+ const cb = (ns: Splash) => ns.getNSElement().parentElement === node
231
+ return node ? this.deleteNS(cb) : null
232
+ }
233
+ }
234
+
235
+ export default { Service }
@@ -1,7 +1,17 @@
1
- import { GUIDString } from '../../../types/Alias'
2
- import { Destination } from '../../../types/Nanosplash'
1
+ // @ts-strict
2
+
3
+ import { GUIDString, Reference } from '../types/Types'
4
+ import { Splash } from './Splash'
5
+
6
+ export interface ServiceInterface {
7
+ /**
8
+ * # Nanosplash Stack
9
+ * For each Nanosplash instance created, it's pushed to the stack.
10
+ * When a Nanosplash instance is removed, it's removed from the stack.
11
+ * @see Splash
12
+ */
13
+ readonly nsStack: Splash[]
3
14
 
4
- export interface NanosplashAPI {
5
15
  /**
6
16
  * # Show
7
17
  * Present a Nanosplash in the browser window displaying the given text.
@@ -13,11 +23,11 @@ export interface NanosplashAPI {
13
23
  /**
14
24
  * # Show Inside
15
25
  * Present a Nanosplash over the given element displaying the given text.
16
- * @param destination Target element.
26
+ * @param ref Reference an element.
17
27
  * @param text Text to display.
18
28
  * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
19
29
  */
20
- showInside(destination: Destination, text?: string): GUIDString | null
30
+ showInside(ref: Reference, text?: string): GUIDString | null
21
31
 
22
32
  /**
23
33
  * # Hide
@@ -43,8 +53,8 @@ export interface NanosplashAPI {
43
53
  /**
44
54
  * # Hide Inside
45
55
  * Hide Nanosplash inside the given element if it exists.
46
- * @param destination Target element.
56
+ * @param ref Reference an element.
47
57
  * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
48
58
  */
49
- hideInside(destination: Destination): GUIDString | null
59
+ hideInside(ref: Reference): GUIDString | null
50
60
  }
@@ -0,0 +1,124 @@
1
+ // @ts-strict
2
+
3
+ import { GUIDString } from '../types/Types'
4
+ import { createElement, showElement, hideElement } from './Dom'
5
+ import { SplashInterface } from './SplashInterface'
6
+
7
+ /**
8
+ * # Splash
9
+ * Small splash screen that can be used to indicate that a process
10
+ * is running.
11
+ * @author Isak K. Hauge <isakhauge@icloud.com>
12
+ */
13
+ export class Splash implements SplashInterface {
14
+ /**
15
+ * # CSS Class Name
16
+ * The main CSS class name of the root element of a Nanosplash component.
17
+ */
18
+ public static readonly NSClass = 'ns'
19
+
20
+ /**
21
+ * # Host CSS Class Name
22
+ * The CSS class name of the host element of a Nanosplash component.
23
+ * The host element is the element that the Nanosplash is attached to.
24
+ */
25
+ public static readonly NSHostClass = 'nsh'
26
+
27
+ /**
28
+ * # ID
29
+ * Each Nanosplash instance is given a unique GUID.
30
+ */
31
+ private readonly id: GUIDString
32
+
33
+ /**
34
+ * # Element
35
+ * The root element of the Nanosplash component.
36
+ */
37
+ private element?: HTMLDivElement
38
+
39
+ /**
40
+ * # Generate GUID
41
+ * @returns {GUIDString} A GUID string.
42
+ * @private
43
+ */
44
+ private static generateGUID(): GUIDString {
45
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
46
+ const r = (Math.random() * 16) | 0
47
+ const v = c === 'x' ? r : (r & 0x3) | 0x8
48
+ return v.toString(16)
49
+ })
50
+ }
51
+
52
+ /**
53
+ * # Constructor
54
+ * Creates a new Nanosplash instance.
55
+ */
56
+ public constructor() {
57
+ this.element = createElement()
58
+ this.element.id = this.id = Splash.generateGUID()
59
+ }
60
+
61
+ /**
62
+ * @inheritdoc
63
+ */
64
+ public getNSContentElement(): HTMLDivElement {
65
+ return <HTMLDivElement>this.getNSElement().firstElementChild
66
+ }
67
+
68
+ /**
69
+ * @inheritdoc
70
+ */
71
+ public getNSTextElement(): HTMLDivElement {
72
+ return <HTMLDivElement>this.getNSContentElement().firstElementChild
73
+ }
74
+
75
+ /**
76
+ * @inheritdoc
77
+ */
78
+ public getId(): GUIDString {
79
+ return this.id
80
+ }
81
+
82
+ /**
83
+ * @inheritdoc
84
+ */
85
+ public getNSElement(): HTMLDivElement {
86
+ return <HTMLDivElement>this.element
87
+ }
88
+
89
+ /**
90
+ * @inheritdoc
91
+ */
92
+ public setText(text: string): Splash {
93
+ this.getNSTextElement().innerText = text
94
+ text.length > 0 ? this.showText() : this.hideText()
95
+ return this
96
+ }
97
+
98
+ /**
99
+ * @inheritdoc
100
+ */
101
+ public showText(): Splash {
102
+ showElement(this.getNSTextElement())
103
+ return this
104
+ }
105
+
106
+ /**
107
+ * @inheritdoc
108
+ */
109
+ public hideText(): Splash {
110
+ hideElement(this.getNSTextElement())
111
+ return this
112
+ }
113
+
114
+ /**
115
+ * @inheritdoc
116
+ */
117
+ public remove(): Splash {
118
+ if (this.element) {
119
+ this.element.parentElement?.removeChild(this.element)
120
+ delete this.element
121
+ }
122
+ return this
123
+ }
124
+ }
@@ -0,0 +1,54 @@
1
+ // @ts-strict
2
+
3
+ import { GUIDString } from '../types/Types'
4
+ import { Splash } from './Splash'
5
+
6
+ export interface SplashInterface {
7
+ /**
8
+ * # Get NS Content Element
9
+ * Returns the content element of the Nanosplash.
10
+ */
11
+ getNSContentElement(): HTMLDivElement
12
+
13
+ /**
14
+ * # Get NS Text Element
15
+ * Returns the text element of the Nanosplash.
16
+ */
17
+ getNSTextElement(): HTMLDivElement
18
+
19
+ /**
20
+ * # Get ID
21
+ * Return Nanosplash instance GUID.
22
+ */
23
+ getId(): GUIDString
24
+
25
+ /**
26
+ * # Get NS Element
27
+ * Return Nanosplash instance HTMLDivElement.
28
+ */
29
+ getNSElement(): HTMLDivElement
30
+
31
+ /**
32
+ * # Set Text
33
+ * @param text The text that will be visible inside the splash.
34
+ */
35
+ setText(text: string): Splash
36
+
37
+ /**
38
+ * # Show Text
39
+ * Display text element.
40
+ */
41
+ showText(): Splash
42
+
43
+ /**
44
+ * # Hide Text
45
+ * Hide the text element.
46
+ */
47
+ hideText(): Splash
48
+
49
+ /**
50
+ * # Remove
51
+ * Delete all
52
+ */
53
+ remove(): Splash
54
+ }
package/src/ts/main.ts ADDED
@@ -0,0 +1,9 @@
1
+ // @ts-strict
2
+
3
+ import { Service } from './core/Service'
4
+
5
+ try {
6
+ Service.start()
7
+ } catch (e) {
8
+ console.warn(e)
9
+ }
@@ -0,0 +1,12 @@
1
+ import { Splash } from '../core/Splash'
2
+
3
+ export type GUIDString = string
4
+ export type CSSSelector = string
5
+ export type FindCallback<T> = (item: T, index: number) => boolean
6
+ export type NSFinder = FindCallback<Splash>
7
+ export type Reference = CSSSelector | Element
8
+
9
+ export enum ClassListAction {
10
+ Add = 'add',
11
+ Remove = 'remove',
12
+ }
@@ -0,0 +1,14 @@
1
+ import NS from '../core/Service'
2
+ import { ServiceInterface } from '../core/ServiceInterface'
3
+
4
+ export class Service extends NS.Service {}
5
+
6
+ declare global {
7
+ export const ns: ServiceInterface
8
+ export interface Window {
9
+ ns: ServiceInterface
10
+ }
11
+ export interface window {
12
+ ns: ServiceInterface
13
+ }
14
+ }
package/src/vite-env.d.ts CHANGED
@@ -1,9 +1 @@
1
1
  /// <reference types="vite/client" />
2
-
3
- import Nanosplash from "./ts/core/Nanosplash/Nanosplash";
4
-
5
- declare global {
6
- interface Window {
7
- ns2: Nanosplash
8
- }
9
- }
@@ -0,0 +1,127 @@
1
+ // @ts-strict
2
+
3
+ import { JSDOM } from 'jsdom'
4
+ import { beforeEach, describe, expect, it } from 'vitest'
5
+ import {
6
+ createElement,
7
+ injectAsFirstChild,
8
+ prepareParentOf,
9
+ cleanNSParentOf,
10
+ showElement,
11
+ hideElement,
12
+ setNSHostClass,
13
+ move,
14
+ elementFrom,
15
+ elementIsNS,
16
+ getRecycledNS,
17
+ } from '../src/ts/core/Dom'
18
+ import { Splash } from '../src/ts/core/Splash'
19
+ import { Service } from '../src/ts/core/Service'
20
+ import { ClassListAction } from '../src/ts/types/Types'
21
+
22
+ describe('DOMUtilities', () => {
23
+ // Reset the DOM before each test
24
+ beforeEach(() => {
25
+ const dom = new JSDOM()
26
+ // @ts-ignore
27
+ globalThis.window = dom.window
28
+ globalThis.document = dom.window.document
29
+ globalThis.DOMParser = dom.window.DOMParser
30
+ globalThis.Element = dom.window.Element
31
+ })
32
+
33
+ it('Should be able to create a Nanosplash component', () => {
34
+ const getClass = (element: Element) => element.classList[0]
35
+ const element = createElement()
36
+ const contentElement = <Element>element.firstElementChild
37
+ const textElement = <Element>contentElement.firstElementChild
38
+ const spinnerElement = <Element>textElement.nextElementSibling
39
+
40
+ expect(getClass(element)).toBe('ns')
41
+ expect(getClass(contentElement)).toBe('nsc')
42
+ expect(getClass(textElement)).toBe('nst')
43
+ expect(getClass(spinnerElement)).toBe('nss')
44
+ })
45
+
46
+ it('Should be able to inject a Nanosplash component', () => {
47
+ const elementA = createElement()
48
+ const elementB = createElement()
49
+ const destinationElement = document.createElement('div')
50
+ injectAsFirstChild(elementA, destinationElement)
51
+ expect(destinationElement.firstElementChild).toBe(elementA)
52
+ injectAsFirstChild(elementB, destinationElement)
53
+ expect(destinationElement.firstElementChild).toBe(elementB)
54
+ })
55
+
56
+ it('Should be able to prepare the parent of a Nanosplash component', () => {
57
+ const ns = new Splash()
58
+ const parent = document.createElement('div')
59
+ parent.appendChild(ns.getNSElement())
60
+ prepareParentOf(ns)
61
+ expect(parent.classList.contains(Splash.NSHostClass)).toBe(true)
62
+ })
63
+
64
+ it('Should be able to clean the parent of a Nanosplash component', () => {
65
+ const ns = new Splash()
66
+ const parent = document.createElement('div')
67
+ parent.appendChild(ns.getNSElement())
68
+ parent.classList.add(Splash.NSClass)
69
+ cleanNSParentOf(ns)
70
+ expect(parent.classList.contains(Splash.NSHostClass)).toBe(false)
71
+ })
72
+
73
+ it('Should be able to convert an element reference to an element', () => {
74
+ const element = document.createElement('div')
75
+ document.body.appendChild(element)
76
+ element.id = 'test-id'
77
+ element.classList.add('test-class')
78
+ element.setAttribute('data-test', 'test')
79
+ expect(elementFrom('#test-id')).toBe(element)
80
+ expect(elementFrom('.test-class')).toBe(element)
81
+ expect(elementFrom('div[data-test="test"]')).toBe(element)
82
+ expect(elementFrom(element)).toBe(element)
83
+ })
84
+
85
+ it('Should be able to check if an element is a Nanosplash element', () => {
86
+ const elementA = new Splash().getNSElement()
87
+ const elementB = document.createElement('div')
88
+ expect(elementIsNS(elementA)).toBe(true)
89
+ expect(elementIsNS(elementB)).toBe(false)
90
+ })
91
+
92
+ it('Should be able to recycle a Nanosplash component', () => {
93
+ const destination = document.createElement('div')
94
+ document.body.appendChild(destination)
95
+ const nss = Service.getInstance()
96
+ const id = nss.showInside(destination, 'Hello World!')
97
+ const recycled = getRecycledNS(destination)
98
+ expect(recycled?.getId()).toBe(id)
99
+ })
100
+
101
+ it('Should be able to show an element', () => {
102
+ const element = document.createElement('div')
103
+ showElement(element)
104
+ expect(element.style.display).toBe('flex')
105
+ })
106
+
107
+ it('Should be able to hide an element', () => {
108
+ const element = document.createElement('div')
109
+ hideElement(element)
110
+ expect(element.style.display).toBe('none')
111
+ })
112
+
113
+ it('Should be able to alter the class of a Nanosplash host', () => {
114
+ const div = document.createElement('div')
115
+ setNSHostClass(div, ClassListAction.Add)
116
+ expect(div.classList.contains(Splash.NSHostClass)).toBe(true)
117
+ setNSHostClass(div, ClassListAction.Remove)
118
+ expect(div.classList.contains(Splash.NSHostClass)).toBe(false)
119
+ })
120
+
121
+ it('Should be able to move a Nanosplash component', () => {
122
+ const ns = new Splash()
123
+ const destination = document.createElement('div')
124
+ move(ns.getNSElement(), destination)
125
+ expect(destination.firstElementChild).toBe(ns.getNSElement())
126
+ })
127
+ })
@@ -1,6 +1,6 @@
1
1
  import { beforeEach, describe, expect, it } from 'vitest'
2
- import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
3
2
  import { JSDOM } from 'jsdom'
3
+ import { Splash } from '../src/ts/core/Splash'
4
4
 
5
5
  describe('Guid', () => {
6
6
  // Reset the DOM before each test
@@ -15,7 +15,7 @@ describe('Guid', () => {
15
15
  it('Should generate a valid GUID', () => {
16
16
  const guidRegex =
17
17
  /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
18
- const value = new Nanosplash().getId()
18
+ const value = new Splash().getId()
19
19
  expect(value).toMatch(guidRegex)
20
20
  })
21
21
  })