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.
Files changed (57) hide show
  1. package/.prettierrc +1 -1
  2. package/README.md +52 -4
  3. package/bun.lockb +0 -0
  4. package/dist/cjs/ns.cjs +1 -2
  5. package/dist/es/ns.js +42 -340
  6. package/dist/iife/ns.iife.js +1 -2
  7. package/docs/.vitepress/.temp/@localSearchIndexroot.Ba2B1gNE.js +4 -0
  8. package/docs/.vitepress/.temp/Card.Ce4dbGEn.js +30 -0
  9. package/docs/.vitepress/.temp/VPLocalSearchBox.DV6bivXX.js +382 -0
  10. package/docs/.vitepress/.temp/api_doc_hide.md.js +25 -0
  11. package/docs/.vitepress/.temp/api_doc_show.md.js +25 -0
  12. package/docs/.vitepress/.temp/api_start_customize.md.js +42 -0
  13. package/docs/.vitepress/.temp/api_start_features.md.js +19 -0
  14. package/docs/.vitepress/.temp/api_start_install.md.js +35 -0
  15. package/docs/.vitepress/.temp/api_start_playground.md.js +213 -0
  16. package/docs/.vitepress/.temp/api_start_usage.md.js +36 -0
  17. package/docs/.vitepress/.temp/app.js +5090 -0
  18. package/docs/.vitepress/.temp/assets/style.lcyfX_uc.css +5374 -0
  19. package/docs/.vitepress/.temp/index.md.js +19 -0
  20. package/docs/.vitepress/.temp/macos.jpg +0 -0
  21. package/docs/.vitepress/.temp/package.json +1 -0
  22. package/docs/.vitepress/.temp/plugin-vue_export-helper.1tPrXgE0.js +10 -0
  23. package/docs/.vitepress/{config.ts → config.mts} +46 -44
  24. package/docs/.vitepress/theme/css/style.css +107 -6
  25. package/docs/.vitepress/theme/vue/CardGrid.vue +1 -1
  26. package/docs/.vitepress/theme/vue/Exe.vue +58 -28
  27. package/docs/.vitepress/theme/vue/PlayGround.vue +5 -21
  28. package/docs/api/doc/hide.md +12 -33
  29. package/docs/api/doc/show.md +12 -13
  30. package/docs/api/start/customize.md +30 -0
  31. package/docs/api/start/features.md +3 -3
  32. package/docs/api/start/install.md +12 -8
  33. package/docs/api/start/playground.md +1 -1
  34. package/docs/api/start/usage.md +4 -7
  35. package/docs/index.md +25 -25
  36. package/docs/public/macos.jpg +0 -0
  37. package/eslint.config.js +9 -0
  38. package/package.json +54 -48
  39. package/src/style/ns.sass +98 -73
  40. package/src/ts/Nanosplash.ts +209 -0
  41. package/src/ts/main.ts +2 -8
  42. package/src/ts/types/NanosplashInterface.ts +26 -0
  43. package/src/ts/types/Types.ts +29 -3
  44. package/src/ts/types/global.d.ts +9 -9
  45. package/tests/Nanosplash.spec.ts +33 -0
  46. package/.prettierignore +0 -1
  47. package/src/ts/core/DomUtilities.ts +0 -161
  48. package/src/ts/core/Service.ts +0 -211
  49. package/src/ts/core/ServiceInterface.ts +0 -58
  50. package/src/ts/core/Splash.ts +0 -121
  51. package/src/ts/core/SplashInterface.ts +0 -46
  52. package/src/ts/core/SplashQueue.ts +0 -49
  53. package/tests/DomUtilities.spec.ts +0 -117
  54. package/tests/Guid.spec.ts +0 -21
  55. package/tests/Service.spec.ts +0 -198
  56. package/tests/Splash.spec.ts +0 -64
  57. package/tests/TestUtilities.ts +0 -48
@@ -1,49 +0,0 @@
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,117 +0,0 @@
1
- // @ts-strict
2
-
3
- import { JSDOM } from 'jsdom'
4
- import { beforeEach, describe, expect, it } from 'vitest'
5
- import {
6
- createElement,
7
- injectAsFirstChild,
8
- showElement,
9
- hideElement,
10
- move,
11
- elementFrom,
12
- getRecycledSplash,
13
- addNSHostClass,
14
- removeNSHostClass,
15
- } from '../src/ts/core/DomUtilities'
16
- import { Splash } from '../src/ts/core/Splash'
17
- import { Service } from '../src/ts/core/Service'
18
-
19
- describe('DOMUtilities', () => {
20
- // Reset the DOM before each test
21
- beforeEach(() => {
22
- const dom = new JSDOM()
23
- // @ts-ignore
24
- globalThis.window = dom.window
25
- globalThis.document = dom.window.document
26
- globalThis.DOMParser = dom.window.DOMParser
27
- globalThis.Element = dom.window.Element
28
- })
29
-
30
- it('Should be able to create a Nanosplash component', () => {
31
- const getClass = (element: Element) => element.classList[0]
32
- const element = createElement()
33
- const contentElement = <Element>element.firstElementChild
34
- const textElement = <Element>contentElement.firstElementChild
35
- const spinnerElement = <Element>textElement.nextElementSibling
36
-
37
- expect(getClass(element)).toBe('ns')
38
- expect(getClass(contentElement)).toBe('nsc')
39
- expect(getClass(textElement)).toBe('nst')
40
- expect(getClass(spinnerElement)).toBe('nss')
41
- })
42
-
43
- it('Should be able to inject a Nanosplash component', () => {
44
- const elementA = createElement()
45
- const elementB = createElement()
46
- const destinationElement = document.createElement('div')
47
- injectAsFirstChild(elementA, destinationElement)
48
- expect(destinationElement.firstElementChild).toBe(elementA)
49
- injectAsFirstChild(elementB, destinationElement)
50
- expect(destinationElement.firstElementChild).toBe(elementB)
51
- })
52
-
53
- it('Should be able to prepare the parent of a Nanosplash component', () => {
54
- const ns = new Splash()
55
- const parent = document.createElement('div')
56
- parent.appendChild(ns.getElement() as Element)
57
- addNSHostClass(parent)
58
- expect(parent.classList.contains(Splash.NSHostClass)).toBe(true)
59
- })
60
-
61
- it('Should be able to clean the parent of a Nanosplash component', () => {
62
- const ns = new Splash()
63
- const parent = document.createElement('div')
64
- parent.appendChild(ns.getElement() as Element)
65
- parent.classList.add(Splash.NSClass)
66
- removeNSHostClass(parent)
67
- expect(parent.classList.contains(Splash.NSHostClass)).toBe(false)
68
- })
69
-
70
- it('Should be able to convert an element reference to an element', () => {
71
- const element = document.createElement('div')
72
- document.body.appendChild(element)
73
- element.id = 'test-id'
74
- element.classList.add('test-class')
75
- element.setAttribute('data-test', 'test')
76
- expect(elementFrom('#test-id')).toBe(element)
77
- expect(elementFrom('.test-class')).toBe(element)
78
- expect(elementFrom('div[data-test="test"]')).toBe(element)
79
- expect(elementFrom(element)).toBe(element)
80
- })
81
-
82
- it('Should be able to recycle a Nanosplash component', () => {
83
- const destination = document.createElement('div')
84
- document.body.appendChild(destination)
85
- const nss = Service.getInstance()
86
- const id = nss.showInside(destination, 'Hello World!')
87
- const recycled = getRecycledSplash(destination)
88
- expect(recycled?.getId()).toBe(id)
89
- })
90
-
91
- it('Should be able to show an element', () => {
92
- const element = document.createElement('div')
93
- showElement(element)
94
- expect(element.style.display).toBe('flex')
95
- })
96
-
97
- it('Should be able to hide an element', () => {
98
- const element = document.createElement('div')
99
- hideElement(element)
100
- expect(element.style.display).toBe('none')
101
- })
102
-
103
- it('Should be able to alter the class of a Nanosplash host', () => {
104
- const div = document.createElement('div')
105
- addNSHostClass(div)
106
- expect(div.classList.contains(Splash.NSHostClass)).toBe(true)
107
- removeNSHostClass(div)
108
- expect(div.classList.contains(Splash.NSHostClass)).toBe(false)
109
- })
110
-
111
- it('Should be able to move a Nanosplash component', () => {
112
- const ns = new Splash()
113
- const destination = document.createElement('div')
114
- move(ns.getElement() as Element, destination)
115
- expect(destination.firstElementChild).toBe(ns.getElement())
116
- })
117
- })
@@ -1,21 +0,0 @@
1
- import { beforeEach, describe, expect, it } from 'vitest'
2
- import { JSDOM } from 'jsdom'
3
- import { Splash } from '../src/ts/core/Splash'
4
-
5
- const rgx = /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
6
-
7
- describe('Guid', () => {
8
- // Reset the DOM before each test
9
- beforeEach(() => {
10
- const dom = new JSDOM()
11
- // @ts-ignore
12
- globalThis.window = dom.window
13
- globalThis.document = dom.window.document
14
- globalThis.DOMParser = dom.window.DOMParser
15
- })
16
-
17
- it('Should generate a valid GUID', () => {
18
- const value = new Splash().getId()
19
- expect(value).toMatch(rgx)
20
- })
21
- })
@@ -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
- }