nanosplash 3.0.0 → 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 (77) 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/LICENSE +21 -0
  6. package/README.md +14 -41
  7. package/bun.lockb +0 -0
  8. package/coverage/DomUtilities.ts.html +568 -0
  9. package/coverage/Service.ts.html +718 -0
  10. package/coverage/Splash.ts.html +448 -0
  11. package/coverage/SplashQueue.ts.html +232 -0
  12. package/coverage/base.css +224 -0
  13. package/coverage/block-navigation.js +87 -0
  14. package/coverage/clover.xml +560 -0
  15. package/coverage/coverage-final.json +5 -0
  16. package/coverage/favicon.png +0 -0
  17. package/coverage/index.html +161 -0
  18. package/coverage/prettify.css +1 -0
  19. package/coverage/prettify.js +2 -0
  20. package/coverage/sort-arrow-sprite.png +0 -0
  21. package/coverage/sorter.js +196 -0
  22. package/dist/cjs/ns.cjs +2 -0
  23. package/dist/es/ns.js +342 -0
  24. package/dist/iife/ns.iife.js +2 -0
  25. package/docs/.vitepress/config.ts +75 -0
  26. package/docs/.vitepress/theme/css/style.css +157 -0
  27. package/docs/.vitepress/theme/index.ts +16 -0
  28. package/docs/.vitepress/theme/vue/Card.vue +31 -0
  29. package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
  30. package/docs/.vitepress/theme/vue/Exe.vue +86 -0
  31. package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
  32. package/docs/api/doc/hide.md +69 -0
  33. package/docs/api/doc/show.md +47 -0
  34. package/docs/api/start/features.md +17 -0
  35. package/docs/api/start/install.md +53 -0
  36. package/docs/api/start/playground.md +11 -0
  37. package/docs/api/start/usage.md +25 -0
  38. package/docs/index.md +30 -0
  39. package/package.json +86 -66
  40. package/src/style/ns.sass +95 -0
  41. package/src/ts/core/DomUtilities.ts +161 -0
  42. package/src/ts/core/Service.ts +211 -0
  43. package/src/ts/core/{Nanosplash/interfaces/NanosplashAPI.ts → ServiceInterface.ts} +18 -10
  44. package/src/ts/core/Splash.ts +121 -0
  45. package/src/ts/core/SplashInterface.ts +46 -0
  46. package/src/ts/core/SplashQueue.ts +49 -0
  47. package/src/ts/main.ts +9 -0
  48. package/src/ts/types/Types.ts +3 -0
  49. package/src/ts/types/global.d.ts +14 -0
  50. package/src/vite-env.d.ts +0 -8
  51. package/tests/DomUtilities.spec.ts +117 -0
  52. package/tests/Guid.spec.ts +5 -5
  53. package/tests/Service.spec.ts +198 -0
  54. package/tests/Splash.spec.ts +64 -0
  55. package/tests/TestUtilities.ts +48 -0
  56. package/tsconfig.json +21 -20
  57. package/vite.config.ts +14 -22
  58. package/dist/main.css +0 -1
  59. package/dist/ns.cjs.js +0 -1
  60. package/dist/ns.es.js +0 -330
  61. package/dist/ns.iife.js +0 -2
  62. package/index.html +0 -52
  63. package/src/main.ts +0 -8
  64. package/src/sass/ns.sass +0 -86
  65. package/src/ts/core/Nanosplash/Nanosplash.ts +0 -97
  66. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +0 -42
  67. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +0 -178
  68. package/src/ts/core/Nanosplash/services/NanosplashService.ts +0 -222
  69. package/src/ts/types/Alias.d.ts +0 -1
  70. package/src/ts/types/Nanosplash.d.ts +0 -18
  71. package/src/ts/types/NanosplashService.d.ts +0 -1
  72. package/src/ts/util/Guid.ts +0 -13
  73. package/src/ts/util/Stack.ts +0 -73
  74. package/tests/Nanosplash.spec.ts +0 -64
  75. package/tests/NanosplashRepository.spec.ts +0 -91
  76. package/tests/NanosplashService.spec.ts +0 -119
  77. package/tests/Stack.spec.ts +0 -56
@@ -1,64 +0,0 @@
1
- // @ts-strict
2
-
3
- import { describe, it, expect, beforeEach } from 'vitest'
4
- import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
5
- import { JSDOM } from 'jsdom'
6
-
7
- describe('Nanosplash', () => {
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 be a valid Nanosplash', () => {
18
- const ns = new Nanosplash()
19
- const element = ns.getNSElement()
20
-
21
- expect(element).not.toBeUndefined()
22
- expect(element.id).toBe(ns.getId())
23
- expect(element.classList.contains(Nanosplash.nsClassName)).toBe(true)
24
-
25
- const contentElement = ns.getNSContentElement()
26
- expect(contentElement).not.toBeUndefined()
27
-
28
- const textElement = ns.getNSTextElement()
29
- expect(textElement).not.toBeUndefined()
30
-
31
- const spinnerElement = <HTMLElement>textElement.nextElementSibling
32
- expect(spinnerElement).not.toBeUndefined()
33
-
34
- const spinnerSVGElement = <HTMLElement>spinnerElement.firstElementChild
35
- expect(spinnerSVGElement).not.toBeUndefined()
36
- })
37
-
38
- it('Should be able to set text', () => {
39
- const ns = new Nanosplash()
40
- const text = 'Hello World!'
41
- ns.setText(text)
42
- expect(ns.getNSTextElement().innerText).toBe(text)
43
- })
44
-
45
- it('Should be able to hide text', () => {
46
- const ns = new Nanosplash()
47
- ns.hideText()
48
- expect(ns.getNSTextElement().style.display).toBe('none')
49
- })
50
-
51
- it('Should be able to show text', () => {
52
- const ns = new Nanosplash()
53
- ns.setText('Hello World!')
54
- ns.hideText()
55
- ns.showText()
56
- expect(ns.getNSTextElement().style.display).toBe('flex')
57
- })
58
-
59
- it('Should be able to remove itself from DOM', () => {
60
- const ns = new Nanosplash()
61
- ns.remove()
62
- expect(ns.getNSElement()).toBeUndefined()
63
- })
64
- })
@@ -1,91 +0,0 @@
1
- // @ts-strict
2
-
3
- import { JSDOM } from 'jsdom'
4
- import { beforeEach, describe, expect, it } from 'vitest'
5
- import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
6
- import {
7
- createElement,
8
- injectAsFirstChild,
9
- prepareParentOf,
10
- cleanNSParentOf,
11
- showElement,
12
- hideElement,
13
- setNSHostClass,
14
- move,
15
- } from '../src/ts/core/Nanosplash/repositories/NanosplashRepository'
16
-
17
- describe('NanosplashRepository', () => {
18
- // Reset the DOM before each test
19
- beforeEach(() => {
20
- const dom = new JSDOM()
21
- // @ts-ignore
22
- globalThis.window = dom.window
23
- globalThis.document = dom.window.document
24
- globalThis.DOMParser = dom.window.DOMParser
25
- globalThis.Node = dom.window.Node
26
- })
27
-
28
- it('Should be able to create a Nanosplash component', () => {
29
- const getClass = (element: Element) => element.classList[0]
30
- const element = createElement()
31
- const contentElement = <Element>element.firstElementChild
32
- const textElement = <Element>contentElement.firstElementChild
33
- const spinnerElement = <Element>textElement.nextElementSibling
34
-
35
- expect(getClass(element)).toBe('ns')
36
- expect(getClass(contentElement)).toBe('ns-content')
37
- expect(getClass(textElement)).toBe('ns-text')
38
- expect(getClass(spinnerElement)).toBe('ns-spinner')
39
- })
40
-
41
- it('Should be able to inject a Nanosplash component', () => {
42
- const element = createElement()
43
- const destinationElement = document.createElement('div')
44
- injectAsFirstChild(element, destinationElement)
45
- expect(destinationElement.firstElementChild).toBe(element)
46
- })
47
-
48
- it('Should be able to prepare the parent of a Nanosplash component', () => {
49
- const ns = new Nanosplash()
50
- const parent = document.createElement('div')
51
- parent.appendChild(ns.getNSElement())
52
- prepareParentOf(ns)
53
- expect(parent.classList.contains(Nanosplash.nsHostClassName)).toBe(true)
54
- })
55
-
56
- it('Should be able to clean the parent of a Nanosplash component', () => {
57
- const ns = new Nanosplash()
58
- const parent = document.createElement('div')
59
- parent.appendChild(ns.getNSElement())
60
- parent.classList.add(Nanosplash.nsHostClassName)
61
- cleanNSParentOf(ns)
62
- expect(parent.classList.contains(Nanosplash.nsHostClassName)).toBe(false)
63
- })
64
-
65
- it('Should be able to show an element', () => {
66
- const element = document.createElement('div')
67
- showElement(element)
68
- expect(element.style.display).toBe('flex')
69
- })
70
-
71
- it('Should be able to hide an element', () => {
72
- const element = document.createElement('div')
73
- hideElement(element)
74
- expect(element.style.display).toBe('none')
75
- })
76
-
77
- it('Should be able to alter the class of a Nanosplash host', () => {
78
- const div = document.createElement('div')
79
- setNSHostClass(div, 'add')
80
- expect(div.classList.contains(Nanosplash.nsHostClassName)).toBe(true)
81
- setNSHostClass(div, 'remove')
82
- expect(div.classList.contains(Nanosplash.nsHostClassName)).toBe(false)
83
- })
84
-
85
- it('Should be able to move a Nanosplash component', () => {
86
- const ns = new Nanosplash()
87
- const destination = document.createElement('div')
88
- move(ns.getNSElement(), destination)
89
- expect(destination.firstElementChild).toBe(ns.getNSElement())
90
- })
91
- })
@@ -1,119 +0,0 @@
1
- // @ts-strict
2
-
3
- import { JSDOM } from 'jsdom'
4
- import { beforeEach, describe, expect, it } from 'vitest'
5
- import NanosplashService from '../src/ts/core/Nanosplash/services/NanosplashService'
6
- import Nanosplash from '../src/ts/core/Nanosplash/Nanosplash'
7
- import { GUIDString } from '../src/ts/types/Alias'
8
- import { getRecycledNS } from '../src/ts/core/Nanosplash/repositories/NanosplashRepository'
9
-
10
- describe('NanosplashService', () => {
11
- const nss = NanosplashService.getInstance()
12
- const getById = (id: GUIDString): Nanosplash | undefined =>
13
- nss.nsStack.items.find((ns: Nanosplash) => ns.getId() === id)
14
-
15
- // Reset the DOM before each test
16
- beforeEach(() => {
17
- const dom = new JSDOM()
18
- // @ts-ignore
19
- globalThis.window = dom.window
20
- globalThis.document = dom.window.document
21
- globalThis.DOMParser = dom.window.DOMParser
22
- globalThis.Node = dom.window.Node
23
- })
24
-
25
- it('Should be able to create an instance', () => {
26
- expect(nss).toBeInstanceOf(NanosplashService)
27
- })
28
-
29
- it('Should be able to get the same singleton instance', () => {
30
- const nss1 = NanosplashService.getInstance()
31
- const nss2 = NanosplashService.getInstance()
32
- expect(nss1).toBe(nss2)
33
- })
34
-
35
- it('Should be able to start the service', () => {
36
- NanosplashService.start()
37
- expect(window.ns).toBeInstanceOf(NanosplashService)
38
- })
39
-
40
- it('Should be able to retrieve an existing Nanosplash instance from a destination node', () => {
41
- const destinationNode = document.createElement('div')
42
- document.body.appendChild(destinationNode)
43
- destinationNode.id = 'test-id'
44
- const nsInstance1 = getRecycledNS(destinationNode) as Nanosplash
45
- expect(nsInstance1).toBeNull()
46
- let nsId = nss.showInside('erroneous-selector', 'Hello World!')
47
- expect(nsId).toBeNull()
48
- nsId = nss.showInside('div[id="test-id"]', 'Hello World!')
49
- const nsInstance2 = getRecycledNS(destinationNode)
50
- expect(nsInstance2).toBeInstanceOf(Nanosplash)
51
- expect(nsInstance2?.getId()).toBe(nsId)
52
- })
53
-
54
- it('Should be able to show a Nanosplash in the browser window', () => {
55
- const text = 'Hello World!'
56
- const nsId = nss.show(text)
57
- const element = document.getElementById(nsId)
58
- const ns = getById(nsId)
59
- const nsText = ns?.getNSTextElement().innerText
60
- expect(element).toBe(ns?.getNSElement())
61
- expect(nsText).toBe(text)
62
- })
63
-
64
- it('Should be able to show a Nanosplash over a given element', () => {
65
- const text = 'Hello World!'
66
- const destination = document.createElement('div')
67
- destination.id = 'test-id'
68
- document.body.appendChild(destination)
69
- const nsId = <string>nss.showInside('#test-id', text)
70
- const element = document.getElementById(nsId)
71
- const ns = getById(nsId)
72
- const nsText = ns?.getNSTextElement().innerText
73
- expect(element).toBe(ns?.getNSElement())
74
- expect(nsText).toBe(text)
75
- })
76
-
77
- it('Should be able to hide a Nanosplash', () => {
78
- const nsId = nss.show()
79
- nss.hide()
80
- const ns = getById(nsId)
81
- expect(ns?.getNSElement()).toBeUndefined()
82
- })
83
-
84
- it('Should be able to hide all Nanosplashes', () => {
85
- const div = (id: string) => {
86
- const d = document.createElement('div')
87
- d.id = id
88
- return d
89
- }
90
- document.body.append(div('a'), div('b'), div('c'))
91
- nss.hideAll()
92
- expect(nss.nsStack.items.length).toBe(0)
93
- nss.showInside('#a', 'A')
94
- nss.showInside('#b', 'B')
95
- nss.showInside('#c', 'C')
96
- expect(nss.nsStack.items.length).toBe(3)
97
- nss.hideAll()
98
- expect(nss.nsStack.items.length).toBe(0)
99
- })
100
-
101
- it('Should be able to hide a Nanosplash based on its ID', () => {
102
- const nsId = nss.show()
103
- nss.hideId(nsId)
104
- const ns = getById(nsId)
105
- expect(ns?.getNSElement()).toBeUndefined()
106
- })
107
-
108
- it('Should be able to hide a Nanosplash residing inside a given element', () => {
109
- const destination = document.createElement('div')
110
- destination.id = 'test-id'
111
- document.body.appendChild(destination)
112
- let nsId = nss.showInside('#test-id')
113
- nsId = nss.hideInside('erroneous-selector')
114
- expect(nsId).toBeNull()
115
- nsId = <string>nss.hideInside('#test-id')
116
- const ns = getById(nsId)
117
- expect(ns?.getNSElement()).toBeUndefined()
118
- })
119
- })
@@ -1,56 +0,0 @@
1
- // @ts-strict
2
-
3
- import { it, expect, describe } from 'vitest'
4
- import Stack from '../src/ts/util/Stack'
5
-
6
- describe('Stack', () => {
7
- it('Should add items to the stack', () => {
8
- const stack = new Stack<number>()
9
- stack.push(1)
10
- stack.push(2)
11
- stack.push(3)
12
- expect(stack.size()).toBe(3)
13
- })
14
-
15
- it('Should remove and return the item at the top of the stack', () => {
16
- const stack = new Stack<string>()
17
- stack.push('a')
18
- stack.push('b')
19
- stack.push('c')
20
- const item = stack.pop()
21
- expect(item).toBe('c')
22
- expect(stack.size()).toBe(2)
23
- })
24
-
25
- it('Should return the item at the top of the stack without removing it', () => {
26
- const stack = new Stack<number>()
27
- stack.push(1)
28
- stack.push(2)
29
- stack.push(3)
30
- const topItem = stack.peek()
31
- expect(topItem).toBe(3)
32
- expect(stack.size()).toBe(3)
33
- })
34
-
35
- it('Should return true if the stack is empty', () => {
36
- const stack = new Stack<boolean>()
37
- expect(stack.isEmpty()).toBe(true)
38
- })
39
-
40
- it('Should return the number of items in the stack', () => {
41
- const stack = new Stack<string>()
42
- stack.push('a')
43
- stack.push('b')
44
- stack.push('c')
45
- expect(stack.size()).toBe(3)
46
- })
47
-
48
- it('Should clear the stack', () => {
49
- const stack = new Stack<number>()
50
- stack.push(1)
51
- stack.push(2)
52
- stack.push(3)
53
- stack.clear()
54
- expect(stack.isEmpty()).toBe(true)
55
- })
56
- })