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
@@ -1,12 +1,17 @@
1
- // @ts-strict
2
-
3
1
  import { version } from '../../../package.json'
4
- import '../../sass/ns.sass'
5
2
 
6
- import { NSFinder, GUIDString, Reference } from '../types/Types'
7
- import { cleanNSParentOf, getRecycledNS, move, elementFrom } from './Dom'
3
+ import { Reference, GUIDString } from '../types/Types'
4
+ import {
5
+ getRecycledSplash,
6
+ move,
7
+ elementFrom,
8
+ render,
9
+ removeNSHostClass,
10
+ } from './DomUtilities'
8
11
  import { ServiceInterface } from './ServiceInterface'
9
12
  import { Splash } from './Splash'
13
+ import css from '../../style/ns.sass?inline'
14
+ import { SplashQueue } from './SplashQueue'
10
15
 
11
16
  /**
12
17
  * # Service
@@ -38,7 +43,7 @@ export class Service implements ServiceInterface {
38
43
  /**
39
44
  * @inheritdoc
40
45
  */
41
- public readonly nsStack: Splash[]
46
+ public readonly nsQueue: SplashQueue
42
47
 
43
48
  /**
44
49
  * # Constructor
@@ -47,29 +52,17 @@ export class Service implements ServiceInterface {
47
52
  */
48
53
  private constructor() {
49
54
  this.version = version
50
- this.nsStack = []
55
+ this.nsQueue = new SplashQueue()
56
+ Service.addStyle()
51
57
  }
52
58
 
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
+ /**e
60
+ * # Add Style
61
+ * Add Nanosplash CSS to the DOM.
59
62
  */
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)
63
+ private static addStyle(): void {
64
+ const style = render(`<style>${css}</style>`) as HTMLStyleElement
65
+ document.body.append(style)
73
66
  }
74
67
 
75
68
  /**
@@ -104,14 +97,10 @@ export class Service implements ServiceInterface {
104
97
  * Initialize and attach a Nanosplash Service instance to the Window object.
105
98
  */
106
99
  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
- })
100
+ const nss = window[Service.WindowAccessorKey]
101
+ if (!nss) {
102
+ Service.assignToWindow()
103
+ }
115
104
  }
116
105
 
117
106
  /**
@@ -122,113 +111,100 @@ export class Service implements ServiceInterface {
122
111
  * @private
123
112
  */
124
113
  private createNS(text?: string): Splash {
125
- const ns = new Splash()
126
- ns.setText(text || '')
127
- this.nsStack.push(ns)
114
+ const ns = new Splash().setText(text || '')
115
+ this.nsQueue.enqueue(ns)
128
116
  return ns
129
117
  }
130
118
 
131
119
  /**
132
- * # Clean And Remove
120
+ * # Clean And Remove From DOM
133
121
  * Remove Nanosplash from DOM and clean its parent.
134
122
  * @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.
123
+ * @returns True if Nanosplash was removed from DOM.
148
124
  * @private
149
125
  */
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()
126
+ private cleanAndRemoveFromDOM(ns: Splash | null): boolean {
127
+ if (ns) {
128
+ removeNSHostClass(ns.getElement()?.parentElement ?? null)
129
+ return ns.delete()
130
+ }
131
+ return false
155
132
  }
156
133
 
157
134
  /**
158
135
  * # Delete NS
159
136
  * 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.
137
+ * @param guid Nanosplash ID.
138
+ * @returns True if Nanosplash was removed from DOM.
162
139
  * @private
163
140
  */
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
141
+ private deleteNS(guid: GUIDString): boolean {
142
+ return this.cleanAndRemoveFromDOM(this.nsQueue.delete(guid) ?? null)
171
143
  }
172
144
 
173
145
  /**
174
146
  * @inheritdoc
175
147
  */
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()
148
+ public show(text?: string): GUIDString | null {
149
+ return this.showInside(document.body, text)
183
150
  }
184
151
 
185
152
  /**
186
153
  * @inheritdoc
187
154
  */
188
155
  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()
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
197
165
  }
198
-
199
- return null
200
166
  }
201
167
 
202
168
  /**
203
169
  * @inheritdoc
204
170
  */
205
171
  public hide(): GUIDString | null {
206
- const ns = this.nsStack.pop()
207
- return ns ? this.cleanAndRemove(ns) : null
172
+ const ns = this.nsQueue.dequeue()
173
+ if (!ns) return null
174
+ this.cleanAndRemoveFromDOM(ns)
175
+ return ns.getId()
208
176
  }
209
177
 
210
178
  /**
211
179
  * @inheritdoc
212
180
  */
213
181
  public hideAll(): void {
214
- this.nsStack.forEach(this.cleanAndRemove)
215
- this.nsStack.splice(0, this.nsStack.length)
182
+ let ns = this.nsQueue.dequeue()
183
+ while (ns) {
184
+ this.cleanAndRemoveFromDOM(ns)
185
+ ns = this.nsQueue.dequeue()
186
+ }
216
187
  }
217
188
 
218
189
  /**
219
190
  * @inheritdoc
220
191
  */
221
192
  public hideId(id: GUIDString): GUIDString | null {
222
- return this.deleteNS((ns: Splash) => ns.getId() === id)
193
+ return this.deleteNS(id) ? id : null
223
194
  }
224
195
 
225
196
  /**
226
197
  * @inheritdoc
227
198
  */
228
199
  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
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
+ }
232
208
  }
233
209
  }
234
210
 
@@ -1,7 +1,5 @@
1
- // @ts-strict
2
-
3
1
  import { GUIDString, Reference } from '../types/Types'
4
- import { Splash } from './Splash'
2
+ import { SplashQueue } from './SplashQueue'
5
3
 
6
4
  export interface ServiceInterface {
7
5
  /**
@@ -10,15 +8,15 @@ export interface ServiceInterface {
10
8
  * When a Nanosplash instance is removed, it's removed from the stack.
11
9
  * @see Splash
12
10
  */
13
- readonly nsStack: Splash[]
11
+ readonly nsQueue: SplashQueue
14
12
 
15
13
  /**
16
14
  * # Show
17
15
  * Present a Nanosplash in the browser window displaying the given text.
18
16
  * @param text Text to display.
19
- * @returns {GUIDString} Nanosplash ID.
17
+ * @returns {GUIDString | null} Nanosplash ID.
20
18
  */
21
- show(text?: string): GUIDString
19
+ show(text?: string): GUIDString | null
22
20
 
23
21
  /**
24
22
  * # Show Inside
@@ -31,7 +29,7 @@ export interface ServiceInterface {
31
29
 
32
30
  /**
33
31
  * # Hide
34
- * Hide the last created Nanosplash.
32
+ * Hide the oldest Nanosplash.
35
33
  * @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
36
34
  */
37
35
  hide(): GUIDString | null
@@ -1,7 +1,5 @@
1
- // @ts-strict
2
-
3
1
  import { GUIDString } from '../types/Types'
4
- import { createElement, showElement, hideElement } from './Dom'
2
+ import { createElement, showElement, hideElement } from './DomUtilities'
5
3
  import { SplashInterface } from './SplashInterface'
6
4
 
7
5
  /**
@@ -28,13 +26,13 @@ export class Splash implements SplashInterface {
28
26
  * # ID
29
27
  * Each Nanosplash instance is given a unique GUID.
30
28
  */
31
- private readonly id: GUIDString
29
+ private id: GUIDString | null
32
30
 
33
31
  /**
34
32
  * # Element
35
33
  * The root element of the Nanosplash component.
36
34
  */
37
- private element?: HTMLDivElement
35
+ private element: HTMLDivElement | null
38
36
 
39
37
  /**
40
38
  * # Generate GUID
@@ -61,36 +59,33 @@ export class Splash implements SplashInterface {
61
59
  /**
62
60
  * @inheritdoc
63
61
  */
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
62
+ public getId(): GUIDString | null {
63
+ return this.id
73
64
  }
74
65
 
75
66
  /**
76
67
  * @inheritdoc
77
68
  */
78
- public getId(): GUIDString {
79
- return this.id
69
+ public getElement(): HTMLDivElement | null {
70
+ return <HTMLDivElement>this.element
80
71
  }
81
72
 
82
73
  /**
83
74
  * @inheritdoc
84
75
  */
85
- public getNSElement(): HTMLDivElement {
86
- return <HTMLDivElement>this.element
76
+ public getTextElement(): HTMLDivElement {
77
+ return (
78
+ <HTMLDivElement>(
79
+ this.getElement()?.firstElementChild?.firstElementChild
80
+ ) ?? null
81
+ )
87
82
  }
88
83
 
89
84
  /**
90
85
  * @inheritdoc
91
86
  */
92
87
  public setText(text: string): Splash {
93
- this.getNSTextElement().innerText = text
88
+ this.getTextElement().innerText = text
94
89
  text.length > 0 ? this.showText() : this.hideText()
95
90
  return this
96
91
  }
@@ -99,7 +94,7 @@ export class Splash implements SplashInterface {
99
94
  * @inheritdoc
100
95
  */
101
96
  public showText(): Splash {
102
- showElement(this.getNSTextElement())
97
+ showElement(this.getTextElement())
103
98
  return this
104
99
  }
105
100
 
@@ -107,18 +102,20 @@ export class Splash implements SplashInterface {
107
102
  * @inheritdoc
108
103
  */
109
104
  public hideText(): Splash {
110
- hideElement(this.getNSTextElement())
105
+ hideElement(this.getTextElement())
111
106
  return this
112
107
  }
113
108
 
114
109
  /**
115
110
  * @inheritdoc
116
111
  */
117
- public remove(): Splash {
118
- if (this.element) {
119
- this.element.parentElement?.removeChild(this.element)
120
- delete this.element
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
121
118
  }
122
- return this
119
+ return this.element === null
123
120
  }
124
121
  }
@@ -1,32 +1,24 @@
1
- // @ts-strict
2
-
3
1
  import { GUIDString } from '../types/Types'
4
2
  import { Splash } from './Splash'
5
3
 
6
4
  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
5
  /**
20
6
  * # Get ID
21
7
  * Return Nanosplash instance GUID.
22
8
  */
23
- getId(): GUIDString
9
+ getId(): GUIDString | null
24
10
 
25
11
  /**
26
- * # Get NS Element
12
+ * # Get Element
27
13
  * Return Nanosplash instance HTMLDivElement.
28
14
  */
29
- getNSElement(): HTMLDivElement
15
+ getElement(): HTMLDivElement | null
16
+
17
+ /**
18
+ * # Get Text Element
19
+ * Returns the text element of the Nanosplash.
20
+ */
21
+ getTextElement(): HTMLDivElement | null
30
22
 
31
23
  /**
32
24
  * # Set Text
@@ -47,8 +39,8 @@ export interface SplashInterface {
47
39
  hideText(): Splash
48
40
 
49
41
  /**
50
- * # Remove
51
- * Delete all
42
+ * # Delete
43
+ * Remove from DOM and delete internal data.
52
44
  */
53
- remove(): Splash
45
+ delete(): boolean
54
46
  }
@@ -0,0 +1,49 @@
1
+ import { GUIDString } from '../types/Types'
2
+ import { Splash } from './Splash'
3
+
4
+ export class SplashQueue {
5
+ public queue: Array<Splash>
6
+
7
+ constructor() {
8
+ this.queue = []
9
+ }
10
+
11
+ /**
12
+ * # Enqueue
13
+ * Add a new item to the queue.
14
+ * @param item The item to add to the queue.
15
+ */
16
+ public enqueue(item: Splash): SplashQueue {
17
+ this.queue.push(item)
18
+ return this
19
+ }
20
+
21
+ /**
22
+ * # Dequeue
23
+ * Remove the first item from the queue.
24
+ * @returns The first item from the queue.
25
+ */
26
+ public dequeue(): Splash | undefined {
27
+ return this.queue.shift()
28
+ }
29
+
30
+ /**
31
+ * # Get
32
+ * @param id The GUID of the Nanosplash to get.
33
+ * @returns The Nanosplash with the given GUID.
34
+ */
35
+ public get(id: GUIDString): Splash | undefined {
36
+ return this.queue.find(item => item.getId() === id)
37
+ }
38
+
39
+ /**
40
+ * # Delete
41
+ * @param id The GUID of the Nanosplash to delete.
42
+ * @returns The deleted Nanosplash.
43
+ */
44
+ public delete(id: GUIDString): Splash | undefined {
45
+ const index = this.queue.findIndex(item => item.getId() === id)
46
+ if (index === -1) return undefined
47
+ return this.queue.splice(index, 1)[0]
48
+ }
49
+ }
@@ -1,12 +1,3 @@
1
- import { Splash } from '../core/Splash'
2
-
3
1
  export type GUIDString = string
4
2
  export type CSSSelector = string
5
- export type FindCallback<T> = (item: T, index: number) => boolean
6
- export type NSFinder = FindCallback<Splash>
7
3
  export type Reference = CSSSelector | Element
8
-
9
- export enum ClassListAction {
10
- Add = 'add',
11
- Remove = 'remove',
12
- }
@@ -5,19 +5,16 @@ import { beforeEach, describe, expect, it } from 'vitest'
5
5
  import {
6
6
  createElement,
7
7
  injectAsFirstChild,
8
- prepareParentOf,
9
- cleanNSParentOf,
10
8
  showElement,
11
9
  hideElement,
12
- setNSHostClass,
13
10
  move,
14
11
  elementFrom,
15
- elementIsNS,
16
- getRecycledNS,
17
- } from '../src/ts/core/Dom'
12
+ getRecycledSplash,
13
+ addNSHostClass,
14
+ removeNSHostClass,
15
+ } from '../src/ts/core/DomUtilities'
18
16
  import { Splash } from '../src/ts/core/Splash'
19
17
  import { Service } from '../src/ts/core/Service'
20
- import { ClassListAction } from '../src/ts/types/Types'
21
18
 
22
19
  describe('DOMUtilities', () => {
23
20
  // Reset the DOM before each test
@@ -56,17 +53,17 @@ describe('DOMUtilities', () => {
56
53
  it('Should be able to prepare the parent of a Nanosplash component', () => {
57
54
  const ns = new Splash()
58
55
  const parent = document.createElement('div')
59
- parent.appendChild(ns.getNSElement())
60
- prepareParentOf(ns)
56
+ parent.appendChild(ns.getElement() as Element)
57
+ addNSHostClass(parent)
61
58
  expect(parent.classList.contains(Splash.NSHostClass)).toBe(true)
62
59
  })
63
60
 
64
61
  it('Should be able to clean the parent of a Nanosplash component', () => {
65
62
  const ns = new Splash()
66
63
  const parent = document.createElement('div')
67
- parent.appendChild(ns.getNSElement())
64
+ parent.appendChild(ns.getElement() as Element)
68
65
  parent.classList.add(Splash.NSClass)
69
- cleanNSParentOf(ns)
66
+ removeNSHostClass(parent)
70
67
  expect(parent.classList.contains(Splash.NSHostClass)).toBe(false)
71
68
  })
72
69
 
@@ -82,19 +79,12 @@ describe('DOMUtilities', () => {
82
79
  expect(elementFrom(element)).toBe(element)
83
80
  })
84
81
 
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
82
  it('Should be able to recycle a Nanosplash component', () => {
93
83
  const destination = document.createElement('div')
94
84
  document.body.appendChild(destination)
95
85
  const nss = Service.getInstance()
96
86
  const id = nss.showInside(destination, 'Hello World!')
97
- const recycled = getRecycledNS(destination)
87
+ const recycled = getRecycledSplash(destination)
98
88
  expect(recycled?.getId()).toBe(id)
99
89
  })
100
90
 
@@ -112,16 +102,16 @@ describe('DOMUtilities', () => {
112
102
 
113
103
  it('Should be able to alter the class of a Nanosplash host', () => {
114
104
  const div = document.createElement('div')
115
- setNSHostClass(div, ClassListAction.Add)
105
+ addNSHostClass(div)
116
106
  expect(div.classList.contains(Splash.NSHostClass)).toBe(true)
117
- setNSHostClass(div, ClassListAction.Remove)
107
+ removeNSHostClass(div)
118
108
  expect(div.classList.contains(Splash.NSHostClass)).toBe(false)
119
109
  })
120
110
 
121
111
  it('Should be able to move a Nanosplash component', () => {
122
112
  const ns = new Splash()
123
113
  const destination = document.createElement('div')
124
- move(ns.getNSElement(), destination)
125
- expect(destination.firstElementChild).toBe(ns.getNSElement())
114
+ move(ns.getElement() as Element, destination)
115
+ expect(destination.firstElementChild).toBe(ns.getElement())
126
116
  })
127
117
  })
@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it } from 'vitest'
2
2
  import { JSDOM } from 'jsdom'
3
3
  import { Splash } from '../src/ts/core/Splash'
4
4
 
5
+ const rgx = /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
6
+
5
7
  describe('Guid', () => {
6
8
  // Reset the DOM before each test
7
9
  beforeEach(() => {
@@ -13,9 +15,7 @@ describe('Guid', () => {
13
15
  })
14
16
 
15
17
  it('Should generate a valid GUID', () => {
16
- const guidRegex =
17
- /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
18
18
  const value = new Splash().getId()
19
- expect(value).toMatch(guidRegex)
19
+ expect(value).toMatch(rgx)
20
20
  })
21
21
  })