nanosplash 2.4.0 → 2.5.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.
- package/.github/workflows/production.yml +5 -2
- package/README.md +1 -1
- package/dist/iife/nanosplash.iife.js +1 -1
- package/dist/module/manifest.json +1 -4
- package/dist/module/nanosplash.cjs.js +1 -1
- package/dist/module/nanosplash.es.js +40 -20
- package/dist/module/{Nanosplash.css → style.css} +0 -0
- package/docs/index.html +44 -14
- package/docs/nanosplash.iife.js +3 -3
- package/docs/typedoc/assets/search.js +1 -1
- package/docs/typedoc/classes/Core_Nanosplash.default.html +135 -0
- package/docs/typedoc/modules/Core_Nanosplash.html +1 -1
- package/docs/typedoc/modules/types.html +1 -1
- package/index.html +44 -14
- package/package.json +1 -1
- package/src/Core/Nanosplash.ts +110 -22
- package/src/Core/SplashInstance.ts +5 -6
- package/src/Factory/NanosplashFactory.ts +33 -2
- package/src/Interfaces/NanosplashInterface.ts +6 -1
- package/src/main.ts +2 -5
- package/src/repositories/NanosplashRepository.ts +14 -0
- package/src/types.d.ts +16 -12
- package/src/utilities/dom.spec.ts +5 -4
- package/src/utilities/dom.ts +23 -0
- package/vite.mod.config.js +11 -3
- package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +0 -59
package/index.html
CHANGED
|
@@ -15,6 +15,21 @@
|
|
|
15
15
|
<div class="w-100 min-h-screen flex flex-col justify-center items-center">
|
|
16
16
|
<div class="text-4xl text-slate-900 drop-shadow-lg">Nanosplash</div>
|
|
17
17
|
<div class="text-pink-500 mt-3 font-mono text-sm">ns.show('text').inside('#id')</div>
|
|
18
|
+
<div class="flex gap-5">
|
|
19
|
+
<div
|
|
20
|
+
id="demo"
|
|
21
|
+
class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
|
|
22
|
+
>
|
|
23
|
+
<i class="lni lni-play"></i>
|
|
24
|
+
Display demo
|
|
25
|
+
</div>
|
|
26
|
+
<a
|
|
27
|
+
href="#example"
|
|
28
|
+
class="bg-slate-500 text-slate-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
|
|
29
|
+
>
|
|
30
|
+
Show examples
|
|
31
|
+
</a>
|
|
32
|
+
</div>
|
|
18
33
|
<div class="flex flex-col space-y-2 my-10">
|
|
19
34
|
<div class="flex space-x-2 justify-center">
|
|
20
35
|
<img src="https://badgen.net/npm/v/nanosplash" />
|
|
@@ -38,9 +53,9 @@
|
|
|
38
53
|
<a href="https://www.npmjs.com/package/nanosplash" target="_blank"><i class="lni lni-npm text-4xl hover:text-pink-500 px-5"></i></a>
|
|
39
54
|
<a href="https://github.com/isakhauge/nanosplash" target="_blank"><i class="lni lni-github-original text-2xl hover:text-pink-500 px-5"></i></a>
|
|
40
55
|
</div>
|
|
41
|
-
<a class="mt-10 text-pink-300 hover:text-pink-500" href="/typedoc">API Reference Documentation</a>
|
|
56
|
+
<a class="mt-10 text-pink-300 hover:text-pink-500" href="https://rawcdn.githack.com/isakhauge/nanosplash/0a6cdef58b0e47c0cad911952b1a329df58d2c24/docs/typedoc/index.html">API Reference Documentation</a>
|
|
42
57
|
</div>
|
|
43
|
-
<div class="grid grid-cols-1 xl:grid-cols-2 gap-1">
|
|
58
|
+
<div id="example" class="grid grid-cols-1 xl:grid-cols-2 gap-1">
|
|
44
59
|
<div id="a" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
45
60
|
<div class="text-xl mb-10">Give user progress feedback</div>
|
|
46
61
|
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
@@ -60,9 +75,7 @@
|
|
|
60
75
|
<div id="c" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
61
76
|
<div class="text-xl mb-10">Display fullscreen</div>
|
|
62
77
|
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
63
|
-
|
|
64
|
-
splash.moveTo('#myDiv')<br>
|
|
65
|
-
splash.remove()
|
|
78
|
+
ns.show('Fullscreen text')
|
|
66
79
|
</div>
|
|
67
80
|
</div>
|
|
68
81
|
<div id="d" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
@@ -70,26 +83,43 @@
|
|
|
70
83
|
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
71
84
|
ns.show('Loading component A').inside('#a')<br>
|
|
72
85
|
ns.show('Loading component B').inside('#b')<br>
|
|
73
|
-
ns.show('Loading component C').inside('#c')
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
ns.show('Loading component C').inside('#c')
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
<div id="e" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
90
|
+
<div class="text-xl mb-10">Move splash instance to another destination</div>
|
|
91
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
92
|
+
const splash = ns.show('Loading').inside('#a')<br>
|
|
93
|
+
splash.moveTo('#b')
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
<div id="f" class="p-20 bg-slate-100 flex flex-col items-center">
|
|
97
|
+
<div class="text-xl mb-10">Hide splash instances</div>
|
|
98
|
+
<div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
|
|
99
|
+
// Hides one instance at a time, in a LIFO-fashion.<br>
|
|
100
|
+
ns.hide()<br><br>
|
|
101
|
+
// Hides all instances.<br>
|
|
102
|
+
ns.hideAll()
|
|
77
103
|
</div>
|
|
78
104
|
</div>
|
|
79
105
|
</div>
|
|
80
106
|
<footer>
|
|
81
107
|
<script type="module" src="/src/main.ts"></script>
|
|
82
108
|
<script>
|
|
109
|
+
document.getElementById('demo').onclick = function () {
|
|
110
|
+
const wait = ms => new Promise(r => setTimeout(r, ms))
|
|
111
|
+
window.ns.progress(
|
|
112
|
+
[wait(2000), 'Loading data from API'],
|
|
113
|
+
[wait(4000), 'Restructuring'],
|
|
114
|
+
[wait(6000), 'Indexing'],
|
|
115
|
+
[wait(8000), 'Give this repo a star']
|
|
116
|
+
)
|
|
117
|
+
}
|
|
83
118
|
document.getElementById('copy').onclick = function () {
|
|
84
119
|
const text = document.querySelector('[data-copy]').innerText
|
|
85
120
|
navigator.clipboard.writeText(text)
|
|
86
121
|
alert('Copied to clipboard!')
|
|
87
122
|
}
|
|
88
|
-
window.onload = () => {
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
window.installNanosplash({spinner: true})
|
|
91
|
-
}, 100)
|
|
92
|
-
}
|
|
93
123
|
</script>
|
|
94
124
|
</footer>
|
|
95
125
|
<style>
|
package/package.json
CHANGED
package/src/Core/Nanosplash.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import '../style.sass'
|
|
2
|
+
import {get} from "../utilities/dom";
|
|
2
3
|
import {SplashInstance} from "./SplashInstance";
|
|
3
|
-
import {InstanceIterationCallback, NanosplashOptions, SplashJob} from "../types";
|
|
4
4
|
import {ShowInterface} from "../Interfaces/ShowInterface";
|
|
5
5
|
import {NanosplashFactory} from "../Factory/NanosplashFactory";
|
|
6
6
|
import {NanosplashInterface} from "../Interfaces/NanosplashInterface";
|
|
7
7
|
import {ContextualAPIInterface} from "../Interfaces/ContextualAPIInterface";
|
|
8
|
+
import {InstanceIterationCallback, NanosplashOptions, SplashJob} from "../types";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* # Nanosplash
|
|
11
12
|
* @author Isak K. Hauge <isakhauge@gmail.com>
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
class Nanosplash implements NanosplashInterface {
|
|
14
15
|
public static APP_NAME = 'Nanosplash'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
private static SPINNER_DEFAULT_VISIBILITY = true
|
|
17
|
+
private imgSrc: string | undefined
|
|
18
|
+
private spinner: boolean
|
|
19
|
+
private fontSize: string
|
|
18
20
|
public readonly instances: Map<string, SplashInstance>
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -22,12 +24,70 @@ export class Nanosplash implements NanosplashInterface {
|
|
|
22
24
|
* @param {NanosplashOptions | undefined} options Nanosplash options object.
|
|
23
25
|
*/
|
|
24
26
|
public constructor(options?: NanosplashOptions) {
|
|
25
|
-
this.imgSrc = options?.imgSrc
|
|
26
|
-
this.
|
|
27
|
+
this.imgSrc = options?.imgSrc
|
|
28
|
+
this.spinner = (options?.spinner === undefined)
|
|
29
|
+
? Nanosplash.SPINNER_DEFAULT_VISIBILITY
|
|
30
|
+
: options.spinner
|
|
27
31
|
this.fontSize = options?.fontSize ?? '18px'
|
|
28
32
|
this.instances = new Map<string, SplashInstance>()
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
/**
|
|
36
|
+
* # Set Image Source
|
|
37
|
+
* Set the value as undefined to display no image.
|
|
38
|
+
* @param {string | undefined} value
|
|
39
|
+
* @return Nanosplash
|
|
40
|
+
*/
|
|
41
|
+
public setImgSrc(value: string | undefined): Nanosplash {
|
|
42
|
+
this.imgSrc = value
|
|
43
|
+
return this
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* # Set Spinner
|
|
48
|
+
* Control spinner visibility.
|
|
49
|
+
* @param {boolean} value
|
|
50
|
+
* @return Nanosplash
|
|
51
|
+
*/
|
|
52
|
+
public showSpinner(value: boolean): Nanosplash {
|
|
53
|
+
this.spinner = value
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* # Set Font Size
|
|
59
|
+
* @param {string} value Use CSS compatible values.
|
|
60
|
+
* @return Nanosplash
|
|
61
|
+
*/
|
|
62
|
+
public setFontSize(value: string): Nanosplash {
|
|
63
|
+
this.fontSize = value
|
|
64
|
+
return this
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* # Get Image Source
|
|
69
|
+
* @return string | undefined
|
|
70
|
+
*/
|
|
71
|
+
public getImgSrc(): string | undefined {
|
|
72
|
+
return this.imgSrc
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* # Spinner Is Visible
|
|
77
|
+
* @return boolean
|
|
78
|
+
*/
|
|
79
|
+
public spinnerIsVisible(): boolean {
|
|
80
|
+
return this.spinner
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* # Get Font Size
|
|
85
|
+
* @return string
|
|
86
|
+
*/
|
|
87
|
+
public getFontSize(): string {
|
|
88
|
+
return this.fontSize
|
|
89
|
+
}
|
|
90
|
+
|
|
31
91
|
/**
|
|
32
92
|
* # Show
|
|
33
93
|
* @param {string} text
|
|
@@ -65,11 +125,6 @@ export class Nanosplash implements NanosplashInterface {
|
|
|
65
125
|
const n = this.instances.size
|
|
66
126
|
const instances = Array.from(this.instances.values())
|
|
67
127
|
for (let i = n - 1; i >= 0; i--) {
|
|
68
|
-
console.log({
|
|
69
|
-
size: n,
|
|
70
|
-
lastIdx: n - 1,
|
|
71
|
-
currentIdx: i
|
|
72
|
-
})
|
|
73
128
|
const instance = instances[i]
|
|
74
129
|
const id = instance.getId()
|
|
75
130
|
if (!callback(id, instance, i)) {
|
|
@@ -97,18 +152,49 @@ export class Nanosplash implements NanosplashInterface {
|
|
|
97
152
|
|
|
98
153
|
/**
|
|
99
154
|
* # Hide
|
|
100
|
-
* Delete specific Splash instance or the latest one.
|
|
101
|
-
*
|
|
155
|
+
* Delete specific Splash instance or the latest one. There are three different ways of using this function.
|
|
156
|
+
*
|
|
157
|
+
* ## Use SplashInstance IDs
|
|
158
|
+
* Every new splash instance is given a unique, randomized ID. This ID is easily retrieved by using the getId
|
|
159
|
+
* method.
|
|
160
|
+
* <br>
|
|
161
|
+
* <code>
|
|
162
|
+
* const splashInstance = ns.show('Loading');<br>
|
|
163
|
+
* ns.hide(splashInstance.getId());
|
|
164
|
+
* </code>
|
|
165
|
+
* <br>
|
|
166
|
+
*
|
|
167
|
+
* ## Use CSS Selector
|
|
168
|
+
* Pass the selector referring to the element in which the splash instance resides.
|
|
169
|
+
* <br>
|
|
170
|
+
* <code>
|
|
171
|
+
* ns.show('Loading').inside('#my-div');<br>
|
|
172
|
+
* ns.hide('#my-div');
|
|
173
|
+
* </code>
|
|
174
|
+
* <br>
|
|
175
|
+
*
|
|
176
|
+
* ## Pass no argument
|
|
177
|
+
* When calling the hide method without passing arguments, it will delete the latest splash instance added to the
|
|
178
|
+
* DOM, in other words, in a LIFO fashion.<br>
|
|
179
|
+
* <code>
|
|
180
|
+
* ns.show('Loading');<br>
|
|
181
|
+
* ns.hide();
|
|
182
|
+
* </code>
|
|
183
|
+
* <br>
|
|
184
|
+
* @param idOrSelector This can either be a SplashInstance ID or a CSS selector referring to the element in which
|
|
185
|
+
* the instance is residing.
|
|
102
186
|
*/
|
|
103
|
-
public hide(
|
|
104
|
-
if (
|
|
105
|
-
const splashInstance = this.instances.get(
|
|
187
|
+
public hide(idOrSelector?: string): void {
|
|
188
|
+
if (idOrSelector) {
|
|
189
|
+
const splashInstance = this.instances.get(idOrSelector)
|
|
106
190
|
if (splashInstance) {
|
|
107
191
|
splashInstance.delete()
|
|
108
192
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
193
|
+
Array.from(this.instances.values())
|
|
194
|
+
.filter((splashInstance: SplashInstance) => {
|
|
195
|
+
return splashInstance.getDestination() === get<HTMLElement>(idOrSelector)
|
|
196
|
+
})
|
|
197
|
+
.forEach((splashInstance: SplashInstance) => splashInstance.delete())
|
|
112
198
|
}
|
|
113
199
|
} else {
|
|
114
200
|
const n = this.instances.size
|
|
@@ -123,13 +209,15 @@ export class Nanosplash implements NanosplashInterface {
|
|
|
123
209
|
}
|
|
124
210
|
|
|
125
211
|
/**
|
|
126
|
-
* # Get
|
|
212
|
+
* # Get From Destination Node
|
|
127
213
|
* Returns Splash instances having the given destination node.
|
|
128
214
|
* @param {HTMLElement} node
|
|
129
215
|
*/
|
|
130
|
-
public
|
|
216
|
+
public getFromDestinationNode(node: HTMLElement): SplashInstance[]
|
|
131
217
|
{
|
|
132
218
|
const fnSameDestinationNode = (v: SplashInstance) => v.getDestination() === node
|
|
133
219
|
return Array.from(this.instances.values()).filter(fnSameDestinationNode)
|
|
134
220
|
}
|
|
135
221
|
}
|
|
222
|
+
|
|
223
|
+
export default Nanosplash
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Destination} from "../types";
|
|
2
|
-
import
|
|
2
|
+
import Nanosplash from "./Nanosplash";
|
|
3
3
|
import {addClass, mk, move, setAttr} from "../utilities/dom";
|
|
4
4
|
import {IdentityInterface} from "../Interfaces/IdentityInterface";
|
|
5
5
|
import {NanosplashRepository} from "../repositories/NanosplashRepository";
|
|
@@ -36,8 +36,8 @@ export class SplashInstance implements IdentityInterface {
|
|
|
36
36
|
this.nsImageElement.src = this.imgSrc ?? ''
|
|
37
37
|
this.nsImageElement.alt = Nanosplash.APP_NAME
|
|
38
38
|
|
|
39
|
-
this.nsRootElement.style.fontSize = ns.
|
|
40
|
-
this.nsSpinnerElement.style.display = ns.
|
|
39
|
+
this.nsRootElement.style.fontSize = ns.getFontSize()
|
|
40
|
+
this.nsSpinnerElement.style.display = ns.spinnerIsVisible() ? 'flex' : 'none'
|
|
41
41
|
|
|
42
42
|
this.assembleNSComponent()
|
|
43
43
|
this.setImgSrc(imgSrc)
|
|
@@ -169,7 +169,7 @@ export class SplashInstance implements IdentityInterface {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
* # Move
|
|
172
|
+
* # Move With Regular Strategy
|
|
173
173
|
* Moves the Nanosplash root element to the target node's position and essentially wraps the target node with the
|
|
174
174
|
* Nanosplash root element.
|
|
175
175
|
* @param {Node} targetNode
|
|
@@ -206,7 +206,7 @@ export class SplashInstance implements IdentityInterface {
|
|
|
206
206
|
{
|
|
207
207
|
const fnNotSameInstance = (v: SplashInstance) => v.getId() !== this.getId()
|
|
208
208
|
const fnDelete = (v: SplashInstance) => v.delete()
|
|
209
|
-
this.nsInstance.
|
|
209
|
+
this.nsInstance.getFromDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete)
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
@@ -228,7 +228,6 @@ export class SplashInstance implements IdentityInterface {
|
|
|
228
228
|
// Assess whether the destination node is the Document body or not
|
|
229
229
|
const targetIsBody = this.destinationNode === document.body
|
|
230
230
|
|
|
231
|
-
|
|
232
231
|
if (targetIsBody) {
|
|
233
232
|
this.moveWithFullscreenStrategy()
|
|
234
233
|
} else {
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {Nanosplash} from "../Core/Nanosplash";
|
|
1
|
+
import Nanosplash from "../Core/Nanosplash";
|
|
3
2
|
import {SplashInstance} from "../Core/SplashInstance";
|
|
4
3
|
import {NanosplashRepository} from "../repositories/NanosplashRepository";
|
|
4
|
+
import {ProgressFunction, ShowFunction, SplashJob, WhileFunction} from "../types";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* # Nanosplash Factory
|
|
8
|
+
* @author Isak K. Hauge
|
|
9
|
+
*/
|
|
6
10
|
export class NanosplashFactory {
|
|
11
|
+
/**
|
|
12
|
+
* # Ensure Instance
|
|
13
|
+
* Returns and modifies the splash instance, or creates a new one.
|
|
14
|
+
* @param {SplashInstance | null} splash Splash instance
|
|
15
|
+
* @param {Nanosplash} ns Nanosplash instance
|
|
16
|
+
* @param {string} text Splash text
|
|
17
|
+
* @param {string | undefined} imgSrc Splash image URL
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
7
20
|
private static ensureInstance(
|
|
8
21
|
splash: SplashInstance | null,
|
|
9
22
|
ns: Nanosplash,
|
|
@@ -17,6 +30,12 @@ export class NanosplashFactory {
|
|
|
17
30
|
return splash.setText(text).setImgSrc(splash.getImgSrc() ?? imgSrc)
|
|
18
31
|
}
|
|
19
32
|
|
|
33
|
+
/**
|
|
34
|
+
* # Create Show Function
|
|
35
|
+
* @param ns
|
|
36
|
+
* @param splash
|
|
37
|
+
* @return {ShowFunction} A curried function made for a specific splash instance.
|
|
38
|
+
*/
|
|
20
39
|
public static createShowFunction(ns: Nanosplash, splash: SplashInstance | null): ShowFunction
|
|
21
40
|
{
|
|
22
41
|
return (text: string) => {
|
|
@@ -27,6 +46,12 @@ export class NanosplashFactory {
|
|
|
27
46
|
}
|
|
28
47
|
}
|
|
29
48
|
|
|
49
|
+
/**
|
|
50
|
+
* # Create Progress Function
|
|
51
|
+
* @param ns
|
|
52
|
+
* @param splash
|
|
53
|
+
* @return {ProgressFunction} A curried API function made for a specific splash instance.
|
|
54
|
+
*/
|
|
30
55
|
public static createProgressFunction(ns: Nanosplash, splash: SplashInstance | null): ProgressFunction
|
|
31
56
|
{
|
|
32
57
|
return (...jobs: SplashJob[]) => {
|
|
@@ -43,6 +68,12 @@ export class NanosplashFactory {
|
|
|
43
68
|
}
|
|
44
69
|
}
|
|
45
70
|
|
|
71
|
+
/**
|
|
72
|
+
* # Create While Function
|
|
73
|
+
* @param ns
|
|
74
|
+
* @param splash
|
|
75
|
+
* @return {ProgressFunction} A curried API function made for a specific splash instance.
|
|
76
|
+
*/
|
|
46
77
|
public static createWhileFunction(ns: Nanosplash, splash: SplashInstance): WhileFunction
|
|
47
78
|
{
|
|
48
79
|
return (asyncTask: Promise<any>) => {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import {StrategyObject} from "../types";
|
|
2
|
+
import {SplashInstance} from "../Core/SplashInstance";
|
|
2
3
|
|
|
3
|
-
export interface NanosplashInterface extends StrategyObject {
|
|
4
|
+
export interface NanosplashInterface extends StrategyObject {
|
|
5
|
+
delete(splashInstance: SplashInstance): void
|
|
6
|
+
hideAll(): void
|
|
7
|
+
hide(id?: string): void
|
|
8
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {NanosplashOptions} from "./types";
|
|
1
|
+
import Nanosplash from "./Core/Nanosplash";
|
|
3
2
|
window.addEventListener('load', () => {
|
|
4
3
|
window.Nanosplash = Nanosplash
|
|
5
|
-
window.
|
|
6
|
-
window.ns = new Nanosplash(options)
|
|
7
|
-
}
|
|
4
|
+
window.ns = new Nanosplash()
|
|
8
5
|
})
|
|
@@ -3,6 +3,11 @@ import {SplashInstance} from "../Core/SplashInstance";
|
|
|
3
3
|
import {ContextualAPIObject, Destination} from "../types";
|
|
4
4
|
|
|
5
5
|
export class NanosplashRepository {
|
|
6
|
+
/**
|
|
7
|
+
* # Destination To Node
|
|
8
|
+
* Converts a Destination type into an HTMLElement.
|
|
9
|
+
* @param {Destination} destination Either a node or a CSS selector.
|
|
10
|
+
*/
|
|
6
11
|
public static destinationToNode(destination: Destination): HTMLElement
|
|
7
12
|
{
|
|
8
13
|
if (typeof destination === 'string') {
|
|
@@ -17,6 +22,11 @@ export class NanosplashRepository {
|
|
|
17
22
|
throw new Error('Destination argument must string or Node')
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
* # Create Contextual API Object
|
|
27
|
+
* Creates an object containing props that adhere to the ns API.
|
|
28
|
+
* @param {SplashInstance} splash
|
|
29
|
+
*/
|
|
20
30
|
public static createContextualApiObject(splash: SplashInstance): ContextualAPIObject
|
|
21
31
|
{
|
|
22
32
|
const ctx = {
|
|
@@ -37,6 +47,10 @@ export class NanosplashRepository {
|
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
/**
|
|
51
|
+
* # Create Nanosplash Spinner Element
|
|
52
|
+
* Returns a DIV element wrapping an SVG element.
|
|
53
|
+
*/
|
|
40
54
|
public static createNanosplashSpinnerElement(): HTMLDivElement
|
|
41
55
|
{
|
|
42
56
|
const div = mk('div') as HTMLDivElement
|
package/src/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Nanosplash from "./Core/Nanosplash";
|
|
2
2
|
import {SplashInstance} from "./Core/SplashInstance";
|
|
3
3
|
import {ShowInterface} from "./Interfaces/ShowInterface";
|
|
4
4
|
import {ContextualAPIInterface} from "./Interfaces/ContextualAPIInterface";
|
|
5
|
+
import {NanosplashInterface} from "./Interfaces/NanosplashInterface";
|
|
5
6
|
|
|
6
7
|
declare global {
|
|
7
8
|
interface Window {
|
|
@@ -11,8 +12,8 @@ declare global {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
type Destination = Node | string
|
|
15
|
-
type SplashJob = [Promise<any>, string]
|
|
15
|
+
export type Destination = Node | string
|
|
16
|
+
export type SplashJob = [Promise<any>, string]
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* @internal
|
|
@@ -24,17 +25,17 @@ export type ElementTag = keyof HTMLElementTagNameMap | keyof SVGElementTagNameMa
|
|
|
24
25
|
*/
|
|
25
26
|
type CSSProperty = keyof CSSStyleDeclaration
|
|
26
27
|
|
|
27
|
-
type ShowFunction = (text: string) => ContextualAPIInterface
|
|
28
|
-
type ProgressFunction = (...[]: SplashJob[]) => ContextualAPIInterface
|
|
29
|
-
type WhileFunction = (asyncTask: Promise<any>) => ShowInterface
|
|
30
|
-
type StrategyObject = {
|
|
28
|
+
export type ShowFunction = (text: string) => ContextualAPIInterface
|
|
29
|
+
export type ProgressFunction = (...[]: SplashJob[]) => ContextualAPIInterface
|
|
30
|
+
export type WhileFunction = (asyncTask: Promise<any>) => ShowInterface
|
|
31
|
+
export type StrategyObject = {
|
|
31
32
|
show: ShowFunction,
|
|
32
33
|
progress: ProgressFunction,
|
|
33
34
|
while: WhileFunction
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
type InsideFunction = (selector: string) => ContextualAPIInterface
|
|
37
|
-
type ContextualAPIObject = {
|
|
36
|
+
|
|
37
|
+
export type InsideFunction = (selector: string) => ContextualAPIInterface
|
|
38
|
+
export type ContextualAPIObject = {
|
|
38
39
|
getId: () => string,
|
|
39
40
|
inside?: InsideFunction,
|
|
40
41
|
remove: () => void
|
|
@@ -44,10 +45,13 @@ type ContextualAPIObject = {
|
|
|
44
45
|
getImgSrc: () => string | undefined,
|
|
45
46
|
setImgSrc: (src?: string) => SplashInstance
|
|
46
47
|
}
|
|
47
|
-
type InstanceIterationCallback = (id: string, splashInstance: SplashInstance, i: number) => boolean
|
|
48
48
|
|
|
49
|
-
type
|
|
49
|
+
export type InstanceIterationCallback = (id: string, splashInstance: SplashInstance, i: number) => boolean
|
|
50
|
+
|
|
51
|
+
export type NanosplashOptions = {
|
|
50
52
|
imgSrc?: string,
|
|
51
53
|
spinner?: boolean,
|
|
52
54
|
fontSize?: string
|
|
53
55
|
}
|
|
56
|
+
|
|
57
|
+
export default Nanosplash
|
|
@@ -2,7 +2,7 @@ import {addClass, get, mk, move, setAttr} from "./dom";
|
|
|
2
2
|
|
|
3
3
|
const resetDOM = () => document.body.innerHTML = ''
|
|
4
4
|
|
|
5
|
-
test('
|
|
5
|
+
test('Get DOM element function', () => {
|
|
6
6
|
const element = document.createElement('div')
|
|
7
7
|
element.id = 'a'
|
|
8
8
|
element.classList.add('b')
|
|
@@ -48,9 +48,10 @@ test('Move Element from origin to destination', () => {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
test('Make HTML Element', () => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const span = mk('span')
|
|
52
|
+
document.body.appendChild(span)
|
|
53
|
+
const spanFromDom = document.body.children.item(0) as Node
|
|
54
|
+
expect(spanFromDom instanceof HTMLSpanElement).toBe(true)
|
|
54
55
|
resetDOM()
|
|
55
56
|
})
|
|
56
57
|
|
package/src/utilities/dom.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import {ElementTag} from "../types";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* # Get
|
|
5
|
+
* Helper function to get Elements from the DOM using CSS selector.
|
|
6
|
+
* @param {string} selector CSS Selector.
|
|
7
|
+
*/
|
|
3
8
|
export function get<T>(selector: string): HTMLElement | T | null {
|
|
4
9
|
return document.querySelector(selector) as HTMLElement | T | null
|
|
5
10
|
}
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* # Move
|
|
14
|
+
* Helper function that can move a node inside another node.
|
|
15
|
+
* @param {Node} source The node to be moved.
|
|
16
|
+
* @param {Node} destination The destination node.
|
|
17
|
+
* @param {boolean} asFirstChild Append or prepend the new node inside the child list.
|
|
18
|
+
*/
|
|
7
19
|
export function move(source: Node, destination: Node, asFirstChild: boolean = false): void
|
|
8
20
|
{
|
|
9
21
|
if (source && destination) {
|
|
@@ -13,8 +25,19 @@ export function move(source: Node, destination: Node, asFirstChild: boolean = fa
|
|
|
13
25
|
}
|
|
14
26
|
}
|
|
15
27
|
|
|
28
|
+
/**
|
|
29
|
+
* # Make
|
|
30
|
+
* Short hand helper function that creates Nodes.
|
|
31
|
+
* @param {ElementTag} tag
|
|
32
|
+
*/
|
|
16
33
|
export const mk = (tag: ElementTag) => document.createElement(tag)
|
|
17
34
|
|
|
35
|
+
/**
|
|
36
|
+
* # Add Class
|
|
37
|
+
* Helper class that easily adds classes to an element.
|
|
38
|
+
* @param {HTMLElement} node The node
|
|
39
|
+
* @param {...string[]} classes
|
|
40
|
+
*/
|
|
18
41
|
export function addClass(node: HTMLElement, ...classes: string[]): void
|
|
19
42
|
{
|
|
20
43
|
node.classList.add(...classes)
|
package/vite.mod.config.js
CHANGED
|
@@ -10,7 +10,7 @@ export default defineConfig({
|
|
|
10
10
|
formats: ['es', 'cjs'],
|
|
11
11
|
},
|
|
12
12
|
outDir: 'dist/module',
|
|
13
|
-
cssCodeSplit:
|
|
13
|
+
cssCodeSplit: false,
|
|
14
14
|
minify: 'terser',
|
|
15
15
|
terserOptions: {
|
|
16
16
|
parse: {
|
|
@@ -28,7 +28,10 @@ export default defineConfig({
|
|
|
28
28
|
mangle: {
|
|
29
29
|
toplevel: true,
|
|
30
30
|
// Reserved class names
|
|
31
|
-
reserved: [
|
|
31
|
+
reserved: [
|
|
32
|
+
'Nanosplash',
|
|
33
|
+
'SplashInstance'
|
|
34
|
+
],
|
|
32
35
|
properties: {
|
|
33
36
|
reserved: [
|
|
34
37
|
'ns',
|
|
@@ -37,9 +40,12 @@ export default defineConfig({
|
|
|
37
40
|
'setText',
|
|
38
41
|
'getImgSrc',
|
|
39
42
|
'setImgSrc',
|
|
43
|
+
'showSpinner',
|
|
44
|
+
'setFontSize',
|
|
45
|
+
'getFontSize',
|
|
46
|
+
'spinnerIsVisible',
|
|
40
47
|
'moveTo',
|
|
41
48
|
'delete',
|
|
42
|
-
'img',
|
|
43
49
|
'show',
|
|
44
50
|
'inside',
|
|
45
51
|
'remove',
|
|
@@ -48,6 +54,8 @@ export default defineConfig({
|
|
|
48
54
|
'delete',
|
|
49
55
|
'hideAll',
|
|
50
56
|
'hide',
|
|
57
|
+
'getFromDestinationNode',
|
|
58
|
+
'getDestination'
|
|
51
59
|
],
|
|
52
60
|
}
|
|
53
61
|
},
|