nanosplash 2.5.3 → 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.
- package/.github/workflows/ci.yml +48 -0
- package/.prettierrc +10 -9
- package/LICENSE +1 -1
- package/README.md +139 -72
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +555 -0
- package/coverage/core/Dom.ts.html +565 -0
- package/coverage/core/Service.ts.html +790 -0
- package/coverage/core/Splash.ts.html +457 -0
- package/coverage/core/index.html +146 -0
- package/coverage/coverage-final.json +9043 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/types/Types.ts.html +121 -0
- package/coverage/types/index.html +116 -0
- package/dist/latest/cjs/ns.cjs +1 -0
- package/dist/latest/cjs/style.css +1 -0
- package/dist/latest/es/ns.js +306 -0
- package/dist/latest/es/style.css +1 -0
- package/dist/latest/iife/ns.iife.js +4 -0
- package/dist/versioned/3.0.1/cjs/ns.cjs +1 -0
- package/dist/versioned/3.0.1/cjs/style.css +1 -0
- package/dist/versioned/3.0.1/es/ns.js +306 -0
- package/dist/versioned/3.0.1/es/style.css +1 -0
- package/dist/versioned/3.0.1/iife/ns.iife.js +2 -0
- package/docs/index.6d66a821.js +1 -0
- package/docs/index.74dbd99e.css +1 -0
- package/docs/index.f34144dc.js +1 -0
- package/docs/index.html +90 -114
- package/index.html +87 -115
- package/package.json +50 -36
- package/src/sass/ns.sass +95 -0
- package/src/ts/core/Dom.ts +160 -0
- package/src/ts/core/Service.ts +235 -0
- package/src/ts/core/ServiceInterface.ts +60 -0
- package/src/ts/core/Splash.ts +124 -0
- package/src/ts/core/SplashInterface.ts +54 -0
- package/src/ts/main.ts +9 -0
- package/src/ts/types/Types.ts +12 -0
- package/src/ts/types/global.d.ts +14 -0
- package/tests/Dom.spec.ts +127 -0
- package/tests/Guid.spec.ts +21 -0
- package/tests/Service.spec.ts +119 -0
- package/tests/Splash.spec.ts +64 -0
- package/tsconfig.json +20 -16
- package/vite.config.ts +27 -13
- package/vite.demo.config.ts +16 -0
- package/.github/workflows/production.yml +0 -60
- package/.github/workflows/release.yml +0 -61
- package/_config.yml +0 -1
- package/dist/iife/manifest.json +0 -7
- package/dist/iife/nanosplash.iife.js +0 -1
- package/dist/module/manifest.json +0 -7
- package/dist/module/nanosplash.cjs.js +0 -1
- package/dist/module/nanosplash.es.js +0 -371
- package/dist/module/style.css +0 -1
- package/docs/nanosplash.iife.js +0 -6
- package/docs/style.css +0 -1
- package/docs/typedoc/.nojekyll +0 -1
- package/docs/typedoc/assets/highlight.css +0 -22
- package/docs/typedoc/assets/icons.css +0 -1043
- package/docs/typedoc/assets/icons.png +0 -0
- package/docs/typedoc/assets/icons@2x.png +0 -0
- package/docs/typedoc/assets/main.js +0 -52
- package/docs/typedoc/assets/search.js +0 -1
- package/docs/typedoc/assets/style.css +0 -1414
- package/docs/typedoc/assets/widgets.png +0 -0
- package/docs/typedoc/assets/widgets@2x.png +0 -0
- package/docs/typedoc/classes/Core_Nanosplash.default.html +0 -133
- package/docs/typedoc/index.html +0 -1
- package/docs/typedoc/modules/Core_Nanosplash.html +0 -1
- package/docs/typedoc/modules/types.html +0 -1
- package/favicon.svg +0 -15
- package/postcss.config.js +0 -8
- package/src/Core/Nanosplash.ts +0 -257
- package/src/Core/SplashInstance.ts +0 -298
- package/src/Exceptions/DestinationException.ts +0 -13
- package/src/Exceptions/Exception.ts +0 -9
- package/src/Exceptions/IllegalArgumentException.ts +0 -11
- package/src/Factory/NanosplashFactory.ts +0 -93
- package/src/Interfaces/ContextualAPIInterface.ts +0 -8
- package/src/Interfaces/IdentityInterface.ts +0 -3
- package/src/Interfaces/InsideInterface.ts +0 -5
- package/src/Interfaces/NanosplashInterface.ts +0 -8
- package/src/Interfaces/ProgressInterface.ts +0 -5
- package/src/Interfaces/ShowInterface.ts +0 -5
- package/src/Interfaces/WhileInterface.ts +0 -5
- package/src/Repositories/NanosplashRepository.ts +0 -82
- package/src/Tests/dom.spec.ts +0 -72
- package/src/Utilities/dom.ts +0 -49
- package/src/main.ts +0 -5
- package/src/style.sass +0 -88
- package/src/types.d.ts +0 -59
- package/update-all.sh +0 -3
- package/vite.iife.config.js +0 -72
- package/vite.mod.config.js +0 -71
- package/vite.site.config.js +0 -22
|
@@ -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,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
|
+
}
|
|
@@ -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
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { JSDOM } from 'jsdom'
|
|
3
|
+
import { Splash } from '../src/ts/core/Splash'
|
|
4
|
+
|
|
5
|
+
describe('Guid', () => {
|
|
6
|
+
// Reset the DOM before each test
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
const dom = new JSDOM()
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
globalThis.window = dom.window
|
|
11
|
+
globalThis.document = dom.window.document
|
|
12
|
+
globalThis.DOMParser = dom.window.DOMParser
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
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
|
+
const value = new Splash().getId()
|
|
19
|
+
expect(value).toMatch(guidRegex)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @ts-strict
|
|
2
|
+
|
|
3
|
+
import { JSDOM } from 'jsdom'
|
|
4
|
+
import { beforeEach, expect, describe, it } from 'vitest'
|
|
5
|
+
import { getRecycledNS } from '../src/ts/core/Dom'
|
|
6
|
+
import { Service } from '../src/ts/core/Service'
|
|
7
|
+
import { Splash } from '../src/ts/core/Splash'
|
|
8
|
+
|
|
9
|
+
describe('NanosplashService', () => {
|
|
10
|
+
const nss = Service.getInstance()
|
|
11
|
+
const getById = (id: string): Splash | undefined =>
|
|
12
|
+
nss.nsStack.find((ns: Splash) => ns.getId() === id)
|
|
13
|
+
|
|
14
|
+
// Reset the DOM before each test
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
const dom = new JSDOM()
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
globalThis.window = dom.window
|
|
19
|
+
globalThis.document = dom.window.document
|
|
20
|
+
globalThis.DOMParser = dom.window.DOMParser
|
|
21
|
+
globalThis.Node = dom.window.Node
|
|
22
|
+
globalThis.Element = dom.window.Element
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('Should be able to create an instance', () => {
|
|
26
|
+
expect(nss).toBeInstanceOf(Service)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('Should be able to get the same singleton instance', () => {
|
|
30
|
+
const nss1 = Service.getInstance()
|
|
31
|
+
const nss2 = Service.getInstance()
|
|
32
|
+
expect(nss1).toBe(nss2)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('Should be able to start the service', () => {
|
|
36
|
+
Service.start()
|
|
37
|
+
expect(nss).toBeInstanceOf(Service)
|
|
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 Splash
|
|
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(Splash)
|
|
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.length).toBe(0)
|
|
93
|
+
nss.showInside('#a', 'A')
|
|
94
|
+
nss.showInside('#b', 'B')
|
|
95
|
+
nss.showInside('#c', 'C')
|
|
96
|
+
expect(nss.nsStack.length).toBe(3)
|
|
97
|
+
nss.hideAll()
|
|
98
|
+
expect(nss.nsStack.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
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-strict
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
4
|
+
import { JSDOM } from 'jsdom'
|
|
5
|
+
import { Splash } from '../src/ts/core/Splash'
|
|
6
|
+
|
|
7
|
+
describe('Splash', () => {
|
|
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 Splash', () => {
|
|
18
|
+
const ns = new Splash()
|
|
19
|
+
const element = ns.getNSElement()
|
|
20
|
+
|
|
21
|
+
expect(element).not.toBeUndefined()
|
|
22
|
+
expect(element.id).toBe(ns.getId())
|
|
23
|
+
expect(element.classList.contains(Splash.NSClass)).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 Splash()
|
|
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 Splash()
|
|
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 Splash()
|
|
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 Splash()
|
|
61
|
+
ns.remove()
|
|
62
|
+
expect(ns.getNSElement()).toBeUndefined()
|
|
63
|
+
})
|
|
64
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM"],
|
|
7
|
+
"moduleResolution": "Node",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationDir": "dist/types",
|
|
19
|
+
"types": ["vite/client"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/ts/**/*.ts"]
|
|
18
22
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import { defineConfig } from '
|
|
1
|
+
import { LibraryFormats, defineConfig } from 'vite'
|
|
2
|
+
import { version } from './package.json'
|
|
3
|
+
import { resolve } from 'path'
|
|
4
|
+
|
|
5
|
+
const dist = 'dist'
|
|
6
|
+
const versioned = process.env?.versioned ?? false
|
|
7
|
+
const format = (process.env?.format ?? '') as LibraryFormats
|
|
8
|
+
const entry = (process.env?.entry ?? '') as string
|
|
9
|
+
|
|
10
|
+
const outDirFolders = [dist]
|
|
11
|
+
if (versioned) {
|
|
12
|
+
outDirFolders.push('versioned', version, format)
|
|
13
|
+
} else {
|
|
14
|
+
outDirFolders.push('latest', format)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const outDir = resolve(__dirname, ...outDirFolders)
|
|
2
18
|
|
|
3
19
|
export default defineConfig({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
}
|
|
20
|
+
build: {
|
|
21
|
+
outDir,
|
|
22
|
+
lib: {
|
|
23
|
+
entry,
|
|
24
|
+
name: 'Nanosplash',
|
|
25
|
+
formats: [format] as LibraryFormats[],
|
|
26
|
+
fileName: 'ns',
|
|
27
|
+
},
|
|
28
|
+
cssCodeSplit: format === 'iife',
|
|
29
|
+
},
|
|
16
30
|
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
export default defineConfig(() => ({
|
|
4
|
+
base: 'nanosplash',
|
|
5
|
+
build: {
|
|
6
|
+
outDir: 'docs',
|
|
7
|
+
rollupOptions: {
|
|
8
|
+
input: 'index.html',
|
|
9
|
+
output: {
|
|
10
|
+
entryFileNames: '[name].[hash].js',
|
|
11
|
+
chunkFileNames: '[name].[hash].js',
|
|
12
|
+
assetFileNames: '[name].[hash].[ext]',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}))
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
name: Production CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [production]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [production]
|
|
8
|
-
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Jest (TS) Testing Procedure
|
|
17
|
-
run: |
|
|
18
|
-
yarn install
|
|
19
|
-
yarn test
|
|
20
|
-
|
|
21
|
-
build:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v2
|
|
25
|
-
with:
|
|
26
|
-
fetch-depth: 0
|
|
27
|
-
|
|
28
|
-
# Checkout branch
|
|
29
|
-
- name: Checkout
|
|
30
|
-
run: |
|
|
31
|
-
git checkout production
|
|
32
|
-
git fetch
|
|
33
|
-
git pull origin
|
|
34
|
-
|
|
35
|
-
- name: Install npm packages
|
|
36
|
-
run: yarn install
|
|
37
|
-
|
|
38
|
-
- name: Transpile Typescript
|
|
39
|
-
run: yarn tsc
|
|
40
|
-
|
|
41
|
-
- name: Build IIFE bundle
|
|
42
|
-
run: yarn vite build -c vite.iife.config.js
|
|
43
|
-
|
|
44
|
-
- name: Build module bundles
|
|
45
|
-
run: yarn vite build -c vite.mod.config.js
|
|
46
|
-
|
|
47
|
-
- name: Build demo site
|
|
48
|
-
run: yarn vite build -c vite.site.config.js
|
|
49
|
-
|
|
50
|
-
- name: Build documentation site
|
|
51
|
-
run: yarn typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Nanosplash.ts src/types.d.ts
|
|
52
|
-
|
|
53
|
-
# Persist changes and push
|
|
54
|
-
- name: Commit changes and push
|
|
55
|
-
run: |
|
|
56
|
-
git config user.name github-actions
|
|
57
|
-
git config user.email github-actions@github.com
|
|
58
|
-
git add .
|
|
59
|
-
git commit -m "Github Actions CI: Build Project for Production"
|
|
60
|
-
git push
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
name: Release CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [release]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [release]
|
|
8
|
-
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
test:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Jest (TS) Testing Procedure
|
|
17
|
-
run: |
|
|
18
|
-
yarn install
|
|
19
|
-
yarn test
|
|
20
|
-
|
|
21
|
-
build:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v2
|
|
25
|
-
|
|
26
|
-
- name: Install npm packages
|
|
27
|
-
run: yarn install
|
|
28
|
-
|
|
29
|
-
- name: Transpile Typescript
|
|
30
|
-
run: yarn tsc
|
|
31
|
-
|
|
32
|
-
- name: Build IIFE bundle
|
|
33
|
-
run: yarn vite build -c vite.iife.config.js
|
|
34
|
-
|
|
35
|
-
- name: Build module bundles
|
|
36
|
-
run: yarn vite build -c vite.mod.config.js
|
|
37
|
-
|
|
38
|
-
- name: Build demo site
|
|
39
|
-
run: yarn vite build -c vite.site.config.js
|
|
40
|
-
|
|
41
|
-
- name: Build documentation site
|
|
42
|
-
run: yarn typedoc --readme none --excludePrivate --excludeInternal --out docs/typedoc --entryPoints src/Nanosplash.ts src/types.d.ts
|
|
43
|
-
|
|
44
|
-
# Persist changes and push
|
|
45
|
-
- name: Commit changes and push
|
|
46
|
-
run: |
|
|
47
|
-
git config user.name github-actions
|
|
48
|
-
git config user.email github-actions@github.com
|
|
49
|
-
git add .
|
|
50
|
-
git commit -m "Github Actions CI: Build Project for Production"
|
|
51
|
-
git push origin release
|
|
52
|
-
|
|
53
|
-
# Publish to NPM
|
|
54
|
-
publish:
|
|
55
|
-
runs-on: ubuntu-latest
|
|
56
|
-
steps:
|
|
57
|
-
- uses: actions/checkout@v2
|
|
58
|
-
- name: Publish NPM package
|
|
59
|
-
run: npm publish --access public
|
|
60
|
-
env:
|
|
61
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTOMATION_TOKEN}}
|
package/_config.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
theme: jekyll-theme-architect
|
package/dist/iife/manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=document.createElement("style");t.innerHTML=".ns-blur,body .ns-fs~*{filter:blur(5px);overflow:hidden}.ns-wrapper{position:relative}.ns-fs{left:0;min-height:100vh;min-width:100%;position:fixed;top:0;z-index:2}.ns-window{align-items:center;background-color:#fffc;display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:1}.ns-img{margin-bottom:2em;max-height:9rem;width:9rem}.ns-text-container{align-items:center}.ns-text,.ns-text-container{display:flex;justify-content:center}.ns-text{color:#5a6685}.ns-spinner{display:flex;height:1em;margin-left:1em;width:1em}.ns-spinner>svg{stroke-width:8;-webkit-animation:Rotate 2s linear infinite;animation:Rotate 2s linear infinite;height:inherit;position:relative;width:inherit}.ns-spinner .path{stroke:#5a6685;stroke-linecap:round;-webkit-animation:Dash 1.5s ease-in-out infinite;animation:Dash 1.5s ease-in-out infinite}@-webkit-keyframes Rotate{to{transform:rotate(1turn)}}@keyframes Rotate{to{transform:rotate(1turn)}}@-webkit-keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}@keyframes Dash{0%{stroke-dasharray:1,150;stroke-dashoffset:0}50%{stroke-dasharray:90,150;stroke-dashoffset:-35}to{stroke-dasharray:90,150;stroke-dashoffset:-124}}\n",document.head.appendChild(t),function(){function t(t){return document.querySelector(t)}const s=t=>document.createElement(t);function e(t,...s){t.classList.add(...s)}function i(t,s,e){t.setAttribute(s,e)}class n extends Error{constructor(t,s){super(t),this.name=this.constructor.name,this.t=s}}class r extends n{constructor(t,s,e){super(t),this.destination=s,this.t=e}}class h extends n{constructor(t,s){super(t),this.i=s}}class o{static h(s){if("string"==typeof s)try{const e=t(s);if(!e)throw new n(`No DOM match with ${s}`);return e}catch(t){throw new r(`Destination (${s}) is either invalid or non-existing in DOM`,s,t)}else if(s instanceof Node)return s;throw new h(`Destination (${s}) must be either a Node or a CSS selector`,s)}static o(t){const s={getId:()=>t.getId(),remove:()=>t.delete(),moveTo:s=>t.moveTo(s),getText:()=>t.getText(),setText:s=>t.setText(s),getImgSrc:()=>t.getImgSrc(),setImgSrc:s=>t.setImgSrc(s)};return{...s,inside:e=>(t.moveTo(e),s)}}static l(){const t=s("div");return e(t,"ns-spinner"),t.innerHTML='\n <svg viewBox="0 0 50 50">\n <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>\n </svg>\n ',t}}class a{constructor(t,e,i){var n;this.u=s("div"),this.m=s("div"),this.g=s("div"),this.p=o.l(),this.v=s("div"),this.k=s("div"),this.S=s("div"),this.D=s("img"),this.id=Math.random().toString(36).substring(2),this.I=t,this.m.innerText=e,this.N=i,this.D.src=null!=(n=this.N)?n:"",this.D.alt=u.F,this.u.style.fontSize=t.T(),this.p.style.display=t.A()?"flex":"none",this.M(),this.setImgSrc(i)}C(){e(this.S,"ns-container"),e(this.k,"ns-blur"),e(this.D,"ns-img"),e(this.m,"ns-text"),e(this.g,"ns-text-container"),e(this.p,"ns-spinner"),e(this.v,"ns","ns-window"),e(this.u,"ns-wrapper")}O(){this.g.append(this.m,this.p),this.S.append(this.D,this.g),this.v.append(this.S),this.u.append(this.k,this.v)}M(){this.u.id=this.getId(),i(this.u,"data-ctx","nanosplash"),this.O(),this.C()}getId(){return this.id}getText(){return this.m.innerText}setText(t){return this.m.innerText=t,this}getImgSrc(){return this.N}setImgSrc(t){return this.D.src=null!=t?t:"",this.D.style.display=t?"block":"none",this.O(),this}R(){return this.W}$(){const t=this.u.parentElement;t&&this.j(t)}B(){i(this.u,"style",""),this.u.classList.remove("ns-fs")}H(t){const s=t.parentNode;s&&(this.j(s),s.replaceChild(this.u,t),this.k.appendChild(t))}P(){this.u.classList.add("ns-fs"),((t,s,e=!1)=>{t&&s&&(s.hasChildNodes()&&e?s.insertBefore(t,s.firstChild):s.appendChild(t))})(this.u,document.body,!0)}V(t){this.I.q(t).filter((t=>t.getId()!==this.getId())).forEach((t=>t.delete()))}moveTo(t){try{this.$(),this.W=o.h(t),this.V(this.W),this.W===document.body?this.P():(this.B(),this.H(this.W)),this.M()}catch(t){this.delete(),this.I.debug&&console.warn(t)}}G(t){Array.from(this.k.childNodes).forEach(t)}j(t){this.G((s=>t.insertBefore(s,this.u)))}J(){[this.m,this.p,this.g,this.D,this.S,this.k,this.v,this.u].forEach((t=>t.remove()))}delete(){this.$(),this.J(),this.I.delete(this)}}class c{static K(t,s,e,i){var n;return t||(t=new a(s,e,i)),t.setText(e).setImgSrc(null!=(n=t.getImgSrc())?n:i)}static L(t,s){return e=>(s=c.K(s,t,e),t.U.set(s.getId(),s),s.moveTo(document.body),o.o(s))}static X(t,s){return(...e)=>((s=c.K(s,t,"")).moveTo(document.body),(async()=>{for(const[t,[i,n]]of e.entries())s.setText(n),await i;s.delete()})(),o.o(s))}static Y(t,s){return e=>(s=c.K(s,t,""),{show:i=>(t.U.set(s.getId(),s),s.moveTo(document.body),s.setText(i),e.finally((()=>s.delete())),o.o(s))})}}const l=class{constructor(t){var s;this.debug=void 0===(null==t?void 0:t.debug)?l.Z:t.debug,this.N=null==t?void 0:t.N,this._=void 0===(null==t?void 0:t._)?l.tt:t._,this.fontSize=null!=(s=null==t?void 0:t.fontSize)?s:"18px",this.U=new Map}setImgSrc(t){return this.N=t,this}st(t){return this._=t,this}et(t){return this.fontSize=t,this}getImgSrc(){return this.N}A(){return this._}T(){return this.fontSize}show(t){return c.L(this,new a(this,t,this.N))(t)}progress(...t){return c.X(this,new a(this,"",this.N))(...t)}while(t){return c.Y(this,new a(this,"",this.N))(t)}it(t){const s=this.U.size,e=Array.from(this.U.values());for(let i=s-1;i>=0;i--){const s=e[i];if(!t(s.getId(),s,i))break}}delete(t){this.U.delete(t.getId())}hideAll(){this.U.forEach((t=>t.delete()))}hide(s){try{if(s){const e=s instanceof Node,i=t=>{Array.from(this.U.values()).filter((s=>s.R()===t)).forEach((t=>t.delete()))};if("string"==typeof s){const e=this.U.get(s);if(e)return void e.delete();{const e=t(s);throw e&&i(e),new n(`The CSS selector (${s}) points to a non-existing DOM element.`)}}if(!e)throw new h("The ref argument must be either a string or Node",s);i(s)}else{const t=this.U.size;this.it(((s,e,i)=>{const n=i===t-1;return n&&e.delete(),n}))}}catch(t){this.debug&&console.warn(t)}}q(t){return Array.from(this.U.values()).filter((s=>s.R()===t))}};let u=l;u.F="Nanosplash",u.tt=!0,u.Z=!0,window.addEventListener("load",(()=>{window.Nanosplash=u,window.ns=new u}))}();
|