nanosplash 3.0.8 → 3.0.9

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 (40) hide show
  1. package/.prettierrc +1 -1
  2. package/README.md +1 -1
  3. package/bun.lockb +0 -0
  4. package/dist/cjs/ns.cjs +1 -2
  5. package/dist/es/ns.js +61 -340
  6. package/dist/iife/ns.iife.js +1 -2
  7. package/docs/.vitepress/{config.ts → config.mts} +41 -43
  8. package/docs/.vitepress/theme/css/style.css +107 -6
  9. package/docs/.vitepress/theme/vue/CardGrid.vue +1 -1
  10. package/docs/.vitepress/theme/vue/Exe.vue +58 -28
  11. package/docs/.vitepress/theme/vue/PlayGround.vue +5 -21
  12. package/docs/api/doc/hide.md +10 -31
  13. package/docs/api/doc/show.md +12 -13
  14. package/docs/api/start/features.md +1 -1
  15. package/docs/api/start/install.md +6 -4
  16. package/docs/api/start/playground.md +1 -1
  17. package/docs/api/start/usage.md +2 -5
  18. package/docs/index.md +25 -25
  19. package/docs/public/macos.jpg +0 -0
  20. package/eslint.config.js +9 -0
  21. package/package.json +54 -48
  22. package/src/style/ns.sass +100 -70
  23. package/src/ts/Nanosplash.ts +219 -0
  24. package/src/ts/main.ts +2 -8
  25. package/src/ts/types/NanosplashInterface.ts +7 -0
  26. package/src/ts/types/Types.ts +28 -3
  27. package/src/ts/types/global.d.ts +9 -9
  28. package/tests/Nanosplash.spec.ts +35 -0
  29. package/.prettierignore +0 -1
  30. package/src/ts/core/DomUtilities.ts +0 -161
  31. package/src/ts/core/Service.ts +0 -211
  32. package/src/ts/core/ServiceInterface.ts +0 -58
  33. package/src/ts/core/Splash.ts +0 -121
  34. package/src/ts/core/SplashInterface.ts +0 -46
  35. package/src/ts/core/SplashQueue.ts +0 -49
  36. package/tests/DomUtilities.spec.ts +0 -117
  37. package/tests/Guid.spec.ts +0 -21
  38. package/tests/Service.spec.ts +0 -198
  39. package/tests/Splash.spec.ts +0 -64
  40. package/tests/TestUtilities.ts +0 -48
@@ -1,198 +0,0 @@
1
- import { beforeEach, expect, describe, it } from 'vitest'
2
- import { Service } from '../src/ts/core/Service'
3
- import { Splash } from '../src/ts/core/Splash'
4
- import { GUIDString } from '../src/ts/types/Types'
5
- import { ExpectedParsedValues, div, resetDOM } from './TestUtilities'
6
-
7
- resetDOM()
8
-
9
- declare global {
10
- interface Window {
11
- ns: Service
12
- }
13
- }
14
-
15
- describe('NanosplashService', () => {
16
- // Reset the DOM before each test
17
- beforeEach(() => {
18
- resetDOM()
19
- })
20
-
21
- it('Should be able to create an instance', () => {
22
- const nss = Service.getInstance()
23
- expect(nss).toBeInstanceOf(Service)
24
- })
25
-
26
- it('Should be a valid singleton instance', () => {
27
- const nss1 = Service.getInstance()
28
- const nss2 = Service.getInstance()
29
- expect(nss1).toBe(nss2)
30
- })
31
-
32
- it('Should be able to start the service and attach it to Window', () => {
33
- Service.start()
34
- const nss = Service.getInstance()
35
- expect(nss).toBe(window.ns)
36
- })
37
-
38
- it('Should be able to show a Nanosplash in the browser window', () => {
39
- const text = 'Hello World!'
40
- const nss = Service.getInstance()
41
- const nsId = <GUIDString>nss.show(text)
42
-
43
- // Compare the elements:
44
- const element = document.getElementById(nsId)
45
- const splash = nss.nsQueue.get(nsId)
46
- expect(element).toBe(splash?.getElement())
47
-
48
- // Compare the text:
49
- const nsText = splash?.getTextElement().innerText
50
- expect(nsText).toBe(text)
51
- })
52
-
53
- it('Should be able to show a Nanosplash over a given element', () => {
54
- const id = 'test-id'
55
- const text = 'Hello World!'
56
- const destination = document.createElement('div')
57
-
58
- // Assign ID and append to DOM
59
- destination.id = id
60
- document.body.appendChild(destination)
61
-
62
- const nss = Service.getInstance()
63
-
64
- // Show Splash inside element
65
- const nsId = nss.showInside(`#${id}`, text)
66
-
67
- // Get element from DOM with the same ID
68
- const element = document.getElementById(<string>nsId)
69
-
70
- // Get Splash instance from NS Service with the same ID
71
- const ns = nss.nsQueue.get(<string>nsId)
72
-
73
- // Compare the two
74
- expect(element).toBe(ns?.getElement())
75
-
76
- // Compare the text
77
- const nsText = ns?.getTextElement().innerText
78
- expect(nsText).toBe(text)
79
- })
80
-
81
- it('Should be able to hide a Splash', () => {
82
- const nss = Service.getInstance()
83
- const nsId = <GUIDString>nss.show()
84
- nss.hide()
85
- const splash = nss.nsQueue.get(nsId)
86
- expect(splash).toBeUndefined()
87
- })
88
-
89
- it('Should be able to hide multiple Splashes in FIFO-order', () => {
90
- document.body.append(div('a'), div('b'), div('c'))
91
-
92
- const nss = Service.getInstance()
93
- const a = nss.showInside('#a', 'A')
94
- const b = nss.showInside('#b', 'B')
95
- const c = nss.showInside('#c', 'C')
96
-
97
- expect(nss.nsQueue.queue.length).toBe(3)
98
-
99
- nss.hide()
100
- expect(nss.nsQueue.queue.length).toBe(2)
101
- expect(nss.nsQueue.get(a as string)).toBeUndefined()
102
- expect(nss.nsQueue.get(b as string)).toBeInstanceOf(Splash)
103
- expect(nss.nsQueue.get(c as string)).toBeInstanceOf(Splash)
104
-
105
- nss.hide()
106
- expect(nss.nsQueue.queue.length).toBe(1)
107
- expect(nss.nsQueue.get(a as string)).toBeUndefined()
108
- expect(nss.nsQueue.get(b as string)).toBeUndefined()
109
- expect(nss.nsQueue.get(c as string)).toBeInstanceOf(Splash)
110
-
111
- nss.hide()
112
- expect(nss.nsQueue.queue.length).toBe(0)
113
- expect(nss.nsQueue.get(a as string)).toBeUndefined()
114
- expect(nss.nsQueue.get(b as string)).toBeUndefined()
115
- expect(nss.nsQueue.get(c as string)).toBeUndefined()
116
- })
117
-
118
- it('Should be able to hide all Nanosplashes', () => {
119
- document.body.append(div('a'), div('b'), div('c'))
120
-
121
- const nss = Service.getInstance()
122
-
123
- nss.hideAll() // Reset the queue
124
- expect(nss.nsQueue.queue.length).toBe(0)
125
-
126
- // Add three Nanosplashes to the queue
127
- nss.showInside('#a', 'A')
128
- nss.showInside('#b', 'B')
129
- nss.showInside('#c', 'C')
130
-
131
- // Expect the queue to have three items
132
- expect(nss.nsQueue.queue.length).toBe(3)
133
-
134
- // Hide all Nanosplashes
135
- nss.hideAll()
136
-
137
- // Expect the queue to be empty
138
- expect(nss.nsQueue.queue.length).toBe(0)
139
- })
140
-
141
- it('Should be able to hide a Nanosplash based on its ID', () => {
142
- const nss = Service.getInstance()
143
- const nsId = <GUIDString>nss.show()
144
- nss.hideId(nsId)
145
- const splash = nss.nsQueue.get(nsId)
146
- expect(splash).toBeUndefined()
147
- })
148
-
149
- it('Should be able to hide a Nanosplash residing inside a given element', () => {
150
- const id = 'test-id'
151
- const parent = document.createElement('div')
152
- parent.id = id
153
- document.body.appendChild(parent)
154
-
155
- const nss = Service.getInstance()
156
- const nsId = <GUIDString>nss.showInside(`#${id}`)
157
-
158
- // Confirm existence.
159
- const element = document.getElementById(<string>nsId)
160
- expect(element?.parentElement).toBe(parent)
161
-
162
- // Hide using API.
163
- nss.hideInside(`#${id}`)
164
-
165
- // Confirm non-existence.
166
- expect(element?.isConnected).toBe(false)
167
- expect(nss.nsQueue.get(nsId)).toBeUndefined()
168
- })
169
-
170
- it('Should take any argument as text without breaking', () => {
171
- const nss = Service.getInstance()
172
-
173
- // Destructure the expected values
174
- const {
175
- numValues,
176
- arrValues,
177
- objValues,
178
- boolValues,
179
- nullValues,
180
- undefValues,
181
- } = ExpectedParsedValues
182
-
183
- // Create functions to test the values
184
- const testValues = (raw: any, parsed: any) => {
185
- const id = <GUIDString>nss.show(raw)
186
- const value = nss.nsQueue.get(id)?.getTextElement().innerText
187
- expect(value).toBe(parsed)
188
- }
189
-
190
- // Test the values
191
- testValues(numValues.raw, numValues.parsed)
192
- testValues(arrValues.raw, arrValues.parsed)
193
- testValues(objValues.raw, objValues.parsed)
194
- testValues(boolValues.raw, boolValues.parsed)
195
- testValues(nullValues.raw, nullValues.parsed)
196
- testValues(undefValues.raw, undefValues.parsed)
197
- })
198
- })
@@ -1,64 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest'
2
- import { Splash } from '../src/ts/core/Splash'
3
- import { resetDOM } from './TestUtilities'
4
-
5
- resetDOM()
6
-
7
- describe('Splash', () => {
8
- // Reset the DOM before each test
9
- beforeEach(() => {
10
- resetDOM()
11
- })
12
-
13
- it('Should be a valid Splash element', () => {
14
- const ns = new Splash()
15
- const element = ns.getElement() as HTMLElement
16
-
17
- // The element should be a valid HTMLDivElement
18
- expect(element).not.toBeUndefined()
19
- expect(element).toBeInstanceOf(HTMLDivElement)
20
-
21
- // The element and the splash instance should have the same ID
22
- expect(element.id).toBe(ns.getId())
23
-
24
- // The element should have the main Nanosplash CSS class
25
- expect(element.classList.contains(Splash.NSClass)).toBe(true)
26
-
27
- // The element should have the correct, inner structure
28
- const textSelector = '.nsc > .nst'
29
- const spinnerSelector = '.nsc > .nss'
30
- const textElement = element.querySelector(textSelector)
31
- const spinnerElement = element.querySelector(spinnerSelector)
32
- expect(textElement).not.toBeNull()
33
- expect(spinnerElement).not.toBeNull()
34
- })
35
-
36
- it('Should be able to set text', () => {
37
- const ns = new Splash()
38
- const text = 'Hello World!'
39
- ns.setText(text)
40
- expect(ns.getTextElement().innerText).toBe(text)
41
- })
42
-
43
- it('Should be able to hide text', () => {
44
- const ns = new Splash()
45
- ns.hideText()
46
- expect(ns.getTextElement().style.display).toBe('none')
47
- })
48
-
49
- it('Should be able to show text', () => {
50
- const ns = new Splash()
51
- ns.setText('Hello World!')
52
- ns.hideText()
53
- ns.showText()
54
- expect(ns.getTextElement().style.display).toBe('flex')
55
- })
56
-
57
- it('Should be able to remove itself from DOM', () => {
58
- const ns = new Splash()
59
- const deleteResult = ns.delete()
60
- const element = ns.getElement()
61
- expect(deleteResult).toBe(true)
62
- expect(element).toBeNull()
63
- })
64
- })
@@ -1,48 +0,0 @@
1
- import { JSDOM } from 'jsdom'
2
- import { Service } from '../src/ts/core/Service'
3
-
4
- export function resetDOM() {
5
- const dom = new JSDOM()
6
- // @ts-ignore
7
- globalThis.window = dom.window
8
- globalThis.document = dom.window.document
9
- globalThis.DOMParser = dom.window.DOMParser
10
- globalThis.Node = dom.window.Node
11
- globalThis.Element = dom.window.Element
12
- globalThis.HTMLElement = dom.window.HTMLElement
13
- globalThis.HTMLDivElement = dom.window.HTMLDivElement
14
- Service.getInstance().hideAll()
15
- }
16
-
17
- export function div(id: string): HTMLDivElement {
18
- const div = document.createElement('div')
19
- div.id = id
20
- return div
21
- }
22
-
23
- export const ExpectedParsedValues = {
24
- numValues: {
25
- raw: 123,
26
- parsed: '123',
27
- },
28
- arrValues: {
29
- raw: [1, 2, 3],
30
- parsed: '1,2,3',
31
- },
32
- objValues: {
33
- raw: {},
34
- parsed: '[object Object]',
35
- },
36
- boolValues: {
37
- raw: true,
38
- parsed: 'true',
39
- },
40
- nullValues: {
41
- raw: null,
42
- parsed: '',
43
- },
44
- undefValues: {
45
- raw: undefined,
46
- parsed: '',
47
- },
48
- }