nanosplash 2.3.2 → 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 +38 -42
- 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 +92 -41
- package/dist/module/style.css +1 -0
- package/docs/index.html +71 -19
- package/docs/nanosplash.iife.js +6 -1
- package/docs/style.css +1 -1
- package/docs/typedoc/assets/main.js +2 -2
- 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 +70 -22
- package/package.json +13 -13
- package/src/Core/Nanosplash.ts +173 -24
- package/src/Core/SplashInstance.ts +148 -11
- package/src/Factory/NanosplashFactory.ts +33 -14
- package/src/Interfaces/NanosplashInterface.ts +6 -2
- package/src/main.ts +5 -2
- package/src/repositories/NanosplashRepository.ts +29 -2
- package/src/style.sass +47 -17
- package/src/types.d.ts +23 -16
- package/src/utilities/dom.spec.ts +5 -4
- package/src/utilities/dom.ts +25 -2
- package/vite.mod.config.js +11 -3
- package/dist/module/Nanosplash.css +0 -1
- package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +0 -1
- package/src/Interfaces/ImageInterface.ts +0 -5
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import {Destination} from "../types";
|
|
2
|
-
import
|
|
2
|
+
import Nanosplash from "./Nanosplash";
|
|
3
3
|
import {addClass, mk, move, setAttr} from "../utilities/dom";
|
|
4
|
-
import {NanosplashRepository} from "../repositories/NanosplashRepository";
|
|
5
4
|
import {IdentityInterface} from "../Interfaces/IdentityInterface";
|
|
5
|
+
import {NanosplashRepository} from "../repositories/NanosplashRepository";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* SplashInstance
|
|
9
|
+
* @author Isak K. Hauge <isakhauge@gmail.com>
|
|
10
|
+
*/
|
|
7
11
|
export class SplashInstance implements IdentityInterface {
|
|
8
12
|
private readonly id: string
|
|
9
13
|
private imgSrc: string | undefined
|
|
10
14
|
private readonly nsInstance: Nanosplash
|
|
15
|
+
private destinationNode: HTMLElement | undefined
|
|
11
16
|
private readonly nsRootElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
12
|
-
private readonly
|
|
17
|
+
private readonly nsTextElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
18
|
+
private readonly nsTextContainerElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
19
|
+
private readonly nsSpinnerElement: HTMLDivElement = NanosplashRepository.createNanosplashSpinnerElement()
|
|
13
20
|
private readonly nsWindowElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
21
|
+
private readonly nsWrapperElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
14
22
|
private readonly nsContentElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
15
23
|
private readonly nsImageElement: HTMLImageElement = mk('img') as HTMLImageElement
|
|
16
|
-
private readonly nsTextElement: HTMLDivElement = mk('div') as HTMLDivElement
|
|
17
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @param {Nanosplash} ns Nanosplash instance
|
|
27
|
+
* @param {string} text Text
|
|
28
|
+
* @param {string|undefined} imgSrc Image source URL
|
|
29
|
+
*/
|
|
18
30
|
public constructor(ns: Nanosplash, text: string, imgSrc?: string) {
|
|
19
31
|
this.id = Math.random().toString(36).substring(2)
|
|
20
32
|
this.nsInstance = ns
|
|
@@ -24,27 +36,48 @@ export class SplashInstance implements IdentityInterface {
|
|
|
24
36
|
this.nsImageElement.src = this.imgSrc ?? ''
|
|
25
37
|
this.nsImageElement.alt = Nanosplash.APP_NAME
|
|
26
38
|
|
|
39
|
+
this.nsRootElement.style.fontSize = ns.getFontSize()
|
|
40
|
+
this.nsSpinnerElement.style.display = ns.spinnerIsVisible() ? 'flex' : 'none'
|
|
41
|
+
|
|
27
42
|
this.assembleNSComponent()
|
|
28
43
|
this.setImgSrc(imgSrc)
|
|
29
44
|
}
|
|
30
45
|
|
|
46
|
+
/**
|
|
47
|
+
* # Assign CSS Classes
|
|
48
|
+
* Assigns CSS class names to all elements connected to this splash instance.
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
31
51
|
private assignCSSClasses(): void
|
|
32
52
|
{
|
|
33
53
|
addClass(this.nsContentElement, 'ns-container')
|
|
34
54
|
addClass(this.nsWrapperElement, 'ns-blur')
|
|
35
55
|
addClass(this.nsImageElement, 'ns-img')
|
|
36
56
|
addClass(this.nsTextElement, 'ns-text')
|
|
57
|
+
addClass(this.nsTextContainerElement, 'ns-text-container')
|
|
58
|
+
addClass(this.nsSpinnerElement, 'ns-spinner')
|
|
37
59
|
addClass(this.nsWindowElement, 'ns', 'ns-window')
|
|
38
60
|
addClass(this.nsRootElement, 'ns-wrapper')
|
|
39
61
|
}
|
|
40
62
|
|
|
63
|
+
/**
|
|
64
|
+
* # Assemble Element Structure
|
|
65
|
+
* Assembles all elements connected to this splash instance in a fixed structure.
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
41
68
|
private assembleElementStructure(): void
|
|
42
69
|
{
|
|
43
|
-
this.
|
|
70
|
+
this.nsTextContainerElement.append(this.nsTextElement, this.nsSpinnerElement)
|
|
71
|
+
this.nsContentElement.append(this.nsImageElement, this.nsTextContainerElement)
|
|
44
72
|
this.nsWindowElement.append(this.nsContentElement)
|
|
45
73
|
this.nsRootElement.append(this.nsWrapperElement, this.nsWindowElement)
|
|
46
74
|
}
|
|
47
75
|
|
|
76
|
+
/**
|
|
77
|
+
* # Assemble Nanosplash Component
|
|
78
|
+
* Assembles all elements into one component that represents the Nanosplash component.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
48
81
|
private assembleNSComponent(): void {
|
|
49
82
|
this.nsRootElement.id = this.getId()
|
|
50
83
|
setAttr(this.nsRootElement, 'data-ctx', 'nanosplash')
|
|
@@ -52,26 +85,48 @@ export class SplashInstance implements IdentityInterface {
|
|
|
52
85
|
this.assignCSSClasses()
|
|
53
86
|
}
|
|
54
87
|
|
|
88
|
+
/**
|
|
89
|
+
* # Get ID
|
|
90
|
+
* @return string
|
|
91
|
+
*/
|
|
55
92
|
public getId(): string
|
|
56
93
|
{
|
|
57
94
|
return this.id
|
|
58
95
|
}
|
|
59
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Get Text
|
|
99
|
+
* @return string
|
|
100
|
+
*/
|
|
60
101
|
public getText(): string
|
|
61
102
|
{
|
|
62
103
|
return this.nsTextElement.innerText
|
|
63
104
|
}
|
|
64
105
|
|
|
106
|
+
/**
|
|
107
|
+
* # Set Text
|
|
108
|
+
* @param {string} text Text
|
|
109
|
+
* @return SplashInstance
|
|
110
|
+
*/
|
|
65
111
|
public setText(text: string): SplashInstance {
|
|
66
112
|
this.nsTextElement.innerText = text
|
|
67
113
|
return this
|
|
68
114
|
}
|
|
69
115
|
|
|
116
|
+
/**
|
|
117
|
+
* # Get Image Source
|
|
118
|
+
* @return string | undefined
|
|
119
|
+
*/
|
|
70
120
|
public getImgSrc(): string | undefined
|
|
71
121
|
{
|
|
72
122
|
return this.imgSrc
|
|
73
123
|
}
|
|
74
124
|
|
|
125
|
+
/**
|
|
126
|
+
* # Set Image Source
|
|
127
|
+
* @param {string|undefined} src Source URL
|
|
128
|
+
* @return SplashInstance
|
|
129
|
+
*/
|
|
75
130
|
public setImgSrc(src?: string): SplashInstance
|
|
76
131
|
{
|
|
77
132
|
this.nsImageElement.src = src ?? ''
|
|
@@ -80,7 +135,21 @@ export class SplashInstance implements IdentityInterface {
|
|
|
80
135
|
return this
|
|
81
136
|
}
|
|
82
137
|
|
|
83
|
-
|
|
138
|
+
/**
|
|
139
|
+
* # Get Destination
|
|
140
|
+
* @return HTMLElement | undefined
|
|
141
|
+
*/
|
|
142
|
+
public getDestination(): HTMLElement | undefined
|
|
143
|
+
{
|
|
144
|
+
return this.destinationNode
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* # Clean And Restore
|
|
149
|
+
* Cleans and restore the DOM structure.
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
private cleanAndRestore(): void
|
|
84
153
|
{
|
|
85
154
|
const currentParent = this.nsRootElement.parentElement
|
|
86
155
|
if (currentParent) {
|
|
@@ -88,12 +157,24 @@ export class SplashInstance implements IdentityInterface {
|
|
|
88
157
|
}
|
|
89
158
|
}
|
|
90
159
|
|
|
160
|
+
/**
|
|
161
|
+
* # Reset Fullscreen Attributes
|
|
162
|
+
* Removes the fullscreen attributes and CSS class names.
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
91
165
|
private resetFullscreenAttributes(): void
|
|
92
166
|
{
|
|
93
167
|
setAttr(this.nsRootElement, 'style', '')
|
|
94
168
|
this.nsRootElement.classList.remove('ns-fs')
|
|
95
169
|
}
|
|
96
170
|
|
|
171
|
+
/**
|
|
172
|
+
* # Move With Regular Strategy
|
|
173
|
+
* Moves the Nanosplash root element to the target node's position and essentially wraps the target node with the
|
|
174
|
+
* Nanosplash root element.
|
|
175
|
+
* @param {Node} targetNode
|
|
176
|
+
* @private
|
|
177
|
+
*/
|
|
97
178
|
private moveWithRegularStrategy(targetNode: Node): void
|
|
98
179
|
{
|
|
99
180
|
const targetParentNode = targetNode.parentNode
|
|
@@ -104,40 +185,92 @@ export class SplashInstance implements IdentityInterface {
|
|
|
104
185
|
}
|
|
105
186
|
}
|
|
106
187
|
|
|
188
|
+
/**
|
|
189
|
+
* # Move With Fullscreen Strategy
|
|
190
|
+
* Moves the Nanosplash root element inside the body element.
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
107
193
|
private moveWithFullscreenStrategy(): void
|
|
108
194
|
{
|
|
109
195
|
this.nsRootElement.classList.add('ns-fs')
|
|
110
196
|
move(this.nsRootElement, document.body, true)
|
|
111
197
|
}
|
|
112
198
|
|
|
199
|
+
/**
|
|
200
|
+
* # Replace Splash Instances Having Same Destination
|
|
201
|
+
* Delete all Splash instances residing inside the same destination node.
|
|
202
|
+
* @param {HTMLElement} destinationNode
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
private replaceSplashInstancesHavingSameDestination(destinationNode: HTMLElement): void
|
|
206
|
+
{
|
|
207
|
+
const fnNotSameInstance = (v: SplashInstance) => v.getId() !== this.getId()
|
|
208
|
+
const fnDelete = (v: SplashInstance) => v.delete()
|
|
209
|
+
this.nsInstance.getFromDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* # Move To
|
|
214
|
+
* This function moves the Nanosplash root element to a destination.
|
|
215
|
+
* @param {Destination} destination
|
|
216
|
+
*/
|
|
113
217
|
public moveTo(destination: Destination): void
|
|
114
218
|
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
219
|
+
// Clean up and restore previous location if any.
|
|
220
|
+
this.cleanAndRestore()
|
|
221
|
+
|
|
222
|
+
// Convert the destination into a DOM Node
|
|
223
|
+
this.destinationNode = NanosplashRepository.destinationToNode(destination)
|
|
224
|
+
|
|
225
|
+
// Replace splash instances having the same destination node
|
|
226
|
+
this.replaceSplashInstancesHavingSameDestination(this.destinationNode)
|
|
227
|
+
|
|
228
|
+
// Assess whether the destination node is the Document body or not
|
|
229
|
+
const targetIsBody = this.destinationNode === document.body
|
|
230
|
+
|
|
118
231
|
if (targetIsBody) {
|
|
119
232
|
this.moveWithFullscreenStrategy()
|
|
120
233
|
} else {
|
|
121
234
|
this.resetFullscreenAttributes()
|
|
122
|
-
this.moveWithRegularStrategy(
|
|
235
|
+
this.moveWithRegularStrategy(this.destinationNode)
|
|
123
236
|
}
|
|
237
|
+
|
|
238
|
+
// Assemble the Nanosplash component
|
|
124
239
|
this.assembleNSComponent()
|
|
125
240
|
}
|
|
126
241
|
|
|
242
|
+
/**
|
|
243
|
+
* # For Each Wrapped Node
|
|
244
|
+
* Invokes a callback for each wrapped node.
|
|
245
|
+
* @param {(node: Node) => void} callback
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
127
248
|
private forEachWrappedNode(callback: (node: Node) => void): void
|
|
128
249
|
{
|
|
129
250
|
Array.from(this.nsWrapperElement.childNodes).forEach(callback)
|
|
130
251
|
}
|
|
131
252
|
|
|
253
|
+
/**
|
|
254
|
+
* # Restore DOM Structure
|
|
255
|
+
* Undo the node wrapping and restore the wrapped nodes' original DOM position.
|
|
256
|
+
* @param {Node} parentNode
|
|
257
|
+
* @private
|
|
258
|
+
*/
|
|
132
259
|
private restoreDOMStructure(parentNode: Node): void
|
|
133
260
|
{
|
|
134
261
|
this.forEachWrappedNode((child: Node) => parentNode.insertBefore(child, this.nsRootElement))
|
|
135
262
|
}
|
|
136
263
|
|
|
264
|
+
/**
|
|
265
|
+
* # Remove Elements From DOM
|
|
266
|
+
* @private
|
|
267
|
+
*/
|
|
137
268
|
private removeElementsFromDOM(): void
|
|
138
269
|
{
|
|
139
270
|
[
|
|
140
271
|
this.nsTextElement,
|
|
272
|
+
this.nsSpinnerElement,
|
|
273
|
+
this.nsTextContainerElement,
|
|
141
274
|
this.nsImageElement,
|
|
142
275
|
this.nsContentElement,
|
|
143
276
|
this.nsWrapperElement,
|
|
@@ -146,8 +279,12 @@ export class SplashInstance implements IdentityInterface {
|
|
|
146
279
|
].forEach(v => v.remove())
|
|
147
280
|
}
|
|
148
281
|
|
|
282
|
+
/**
|
|
283
|
+
* # Delete
|
|
284
|
+
* Gracefully delete Splash instance and connected elements from DOM.
|
|
285
|
+
*/
|
|
149
286
|
public delete(): void {
|
|
150
|
-
this.
|
|
287
|
+
this.cleanAndRestore()
|
|
151
288
|
this.removeElementsFromDOM()
|
|
152
289
|
this.nsInstance.delete(this)
|
|
153
290
|
}
|
|
@@ -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,18 +30,12 @@ export class NanosplashFactory {
|
|
|
17
30
|
return splash.setText(text).setImgSrc(splash.getImgSrc() ?? imgSrc)
|
|
18
31
|
}
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
progress: NanosplashFactory.createProgressFunction(ns, splash),
|
|
27
|
-
while: NanosplashFactory.createWhileFunction(ns, splash)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
33
|
+
/**
|
|
34
|
+
* # Create Show Function
|
|
35
|
+
* @param ns
|
|
36
|
+
* @param splash
|
|
37
|
+
* @return {ShowFunction} A curried function made for a specific splash instance.
|
|
38
|
+
*/
|
|
32
39
|
public static createShowFunction(ns: Nanosplash, splash: SplashInstance | null): ShowFunction
|
|
33
40
|
{
|
|
34
41
|
return (text: string) => {
|
|
@@ -39,6 +46,12 @@ export class NanosplashFactory {
|
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
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
|
+
*/
|
|
42
55
|
public static createProgressFunction(ns: Nanosplash, splash: SplashInstance | null): ProgressFunction
|
|
43
56
|
{
|
|
44
57
|
return (...jobs: SplashJob[]) => {
|
|
@@ -55,6 +68,12 @@ export class NanosplashFactory {
|
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
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
|
+
*/
|
|
58
77
|
public static createWhileFunction(ns: Nanosplash, splash: SplashInstance): WhileFunction
|
|
59
78
|
{
|
|
60
79
|
return (asyncTask: Promise<any>) => {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import {StrategyObject} from "../types";
|
|
2
|
-
import {
|
|
2
|
+
import {SplashInstance} from "../Core/SplashInstance";
|
|
3
3
|
|
|
4
|
-
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,2 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
window.addEventListener('load', () =>
|
|
1
|
+
import Nanosplash from "./Core/Nanosplash";
|
|
2
|
+
window.addEventListener('load', () => {
|
|
3
|
+
window.Nanosplash = Nanosplash
|
|
4
|
+
window.ns = new Nanosplash()
|
|
5
|
+
})
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {get} from "../utilities/dom";
|
|
1
|
+
import {addClass, get, mk} from "../utilities/dom";
|
|
2
2
|
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,7 +22,13 @@ export class NanosplashRepository {
|
|
|
17
22
|
throw new Error('Destination argument must string or Node')
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
/**
|
|
26
|
+
* # Create Contextual API Object
|
|
27
|
+
* Creates an object containing props that adhere to the ns API.
|
|
28
|
+
* @param {SplashInstance} splash
|
|
29
|
+
*/
|
|
30
|
+
public static createContextualApiObject(splash: SplashInstance): ContextualAPIObject
|
|
31
|
+
{
|
|
21
32
|
const ctx = {
|
|
22
33
|
getId: () => splash.getId(),
|
|
23
34
|
remove: () => splash.delete(),
|
|
@@ -35,4 +46,20 @@ export class NanosplashRepository {
|
|
|
35
46
|
},
|
|
36
47
|
}
|
|
37
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* # Create Nanosplash Spinner Element
|
|
52
|
+
* Returns a DIV element wrapping an SVG element.
|
|
53
|
+
*/
|
|
54
|
+
public static createNanosplashSpinnerElement(): HTMLDivElement
|
|
55
|
+
{
|
|
56
|
+
const div = mk('div') as HTMLDivElement
|
|
57
|
+
addClass(div, 'ns-spinner')
|
|
58
|
+
div.innerHTML = `
|
|
59
|
+
<svg viewBox="0 0 50 50">
|
|
60
|
+
<circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
|
|
61
|
+
</svg>
|
|
62
|
+
`
|
|
63
|
+
return div
|
|
64
|
+
}
|
|
38
65
|
}
|
package/src/style.sass
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
$z-index-regular: 1
|
|
2
2
|
$z-index-fullscreen: 2
|
|
3
|
+
$text-color: #5a6685
|
|
3
4
|
$bg-color: rgba(White, 0.8)
|
|
4
5
|
|
|
5
6
|
%blur
|
|
6
7
|
overflow: hidden
|
|
7
8
|
filter: blur(5px)
|
|
8
9
|
|
|
10
|
+
// Wraps the content replaced by Nanosplash
|
|
9
11
|
.ns-wrapper
|
|
10
12
|
position: relative
|
|
11
13
|
|
|
14
|
+
// Only active while in fullscreen mode
|
|
12
15
|
.ns-fs
|
|
13
16
|
top: 0
|
|
14
17
|
left: 0
|
|
@@ -17,10 +20,11 @@ $bg-color: rgba(White, 0.8)
|
|
|
17
20
|
min-height: 100vh
|
|
18
21
|
z-index: $z-index-fullscreen
|
|
19
22
|
|
|
20
|
-
//
|
|
23
|
+
// Blurs the wrapped content
|
|
21
24
|
body .ns-fs ~ *, .ns-blur
|
|
22
25
|
@extend %blur
|
|
23
26
|
|
|
27
|
+
// Nanosplash window containing image and text
|
|
24
28
|
.ns-window
|
|
25
29
|
top: 0
|
|
26
30
|
left: 0
|
|
@@ -33,26 +37,52 @@ body .ns-fs ~ *, .ns-blur
|
|
|
33
37
|
z-index: $z-index-regular
|
|
34
38
|
background-color: $bg-color
|
|
35
39
|
|
|
40
|
+
// Image
|
|
36
41
|
.ns-img
|
|
37
|
-
|
|
42
|
+
width: 9rem
|
|
38
43
|
max-height: 9rem
|
|
39
|
-
margin-bottom:
|
|
44
|
+
margin-bottom: 2em
|
|
40
45
|
|
|
46
|
+
// Text container containing text and spinner
|
|
47
|
+
.ns-text-container
|
|
48
|
+
display: flex
|
|
49
|
+
justify-content: center
|
|
50
|
+
align-items: center
|
|
51
|
+
|
|
52
|
+
// Text node
|
|
41
53
|
.ns-text
|
|
42
|
-
color: #333
|
|
43
54
|
display: flex
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
justify-content: center
|
|
56
|
+
color: $text-color
|
|
57
|
+
|
|
58
|
+
// Spinner node
|
|
59
|
+
.ns-spinner
|
|
60
|
+
display: flex
|
|
61
|
+
margin-left: 1em
|
|
62
|
+
width: 1em
|
|
63
|
+
height: 1em
|
|
64
|
+
& > svg
|
|
65
|
+
animation: Rotate 2s linear infinite
|
|
66
|
+
position: relative
|
|
67
|
+
width: inherit
|
|
68
|
+
height: inherit
|
|
69
|
+
stroke-width: 8
|
|
70
|
+
& .path
|
|
71
|
+
stroke: $text-color
|
|
72
|
+
stroke-linecap: round
|
|
73
|
+
animation: Dash 1.5s ease-in-out infinite
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
// Spinner animations:
|
|
76
|
+
@keyframes Rotate
|
|
77
|
+
100%
|
|
78
|
+
transform: rotate(360deg)
|
|
79
|
+
@keyframes Dash
|
|
51
80
|
0%
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
stroke-dasharray: 1, 150
|
|
82
|
+
stroke-dashoffset: 0
|
|
83
|
+
50%
|
|
84
|
+
stroke-dasharray: 90, 150
|
|
85
|
+
stroke-dashoffset: -35
|
|
86
|
+
100%
|
|
87
|
+
stroke-dasharray: 90, 150
|
|
88
|
+
stroke-dashoffset: -124
|
package/src/types.d.ts
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {ShowInterface} from "./Interfaces/ShowInterface";
|
|
3
|
-
import {InsideInterface} from "./Interfaces/InsideInterface";
|
|
1
|
+
import Nanosplash from "./Core/Nanosplash";
|
|
4
2
|
import {SplashInstance} from "./Core/SplashInstance";
|
|
3
|
+
import {ShowInterface} from "./Interfaces/ShowInterface";
|
|
5
4
|
import {ContextualAPIInterface} from "./Interfaces/ContextualAPIInterface";
|
|
5
|
+
import {NanosplashInterface} from "./Interfaces/NanosplashInterface";
|
|
6
6
|
|
|
7
7
|
declare global {
|
|
8
8
|
interface Window {
|
|
9
|
+
Nanosplash: typeof Nanosplash
|
|
10
|
+
installNanosplash: (options?: NanosplashOptions) => void
|
|
9
11
|
ns: Nanosplash
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
type Destination = Node | string
|
|
14
|
-
type SplashJob = [Promise<any>, string]
|
|
15
|
+
export type Destination = Node | string
|
|
16
|
+
export type SplashJob = [Promise<any>, string]
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @internal
|
|
18
20
|
*/
|
|
19
|
-
export type
|
|
21
|
+
export type ElementTag = keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* @internal
|
|
23
25
|
*/
|
|
24
26
|
type CSSProperty = keyof CSSStyleDeclaration
|
|
25
27
|
|
|
26
|
-
type ShowFunction = (text: string) => ContextualAPIInterface
|
|
27
|
-
type ProgressFunction = (...[]: SplashJob[]) => ContextualAPIInterface
|
|
28
|
-
type WhileFunction = (asyncTask: Promise<any>) => ShowInterface
|
|
29
|
-
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 = {
|
|
30
32
|
show: ShowFunction,
|
|
31
33
|
progress: ProgressFunction,
|
|
32
34
|
while: WhileFunction
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
type InsideFunction = (selector: string) => ContextualAPIInterface
|
|
36
|
-
type ContextualAPIObject = {
|
|
36
|
+
|
|
37
|
+
export type InsideFunction = (selector: string) => ContextualAPIInterface
|
|
38
|
+
export type ContextualAPIObject = {
|
|
37
39
|
getId: () => string,
|
|
38
40
|
inside?: InsideFunction,
|
|
39
41
|
remove: () => void
|
|
@@ -44,7 +46,12 @@ type ContextualAPIObject = {
|
|
|
44
46
|
setImgSrc: (src?: string) => SplashInstance
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
export type InstanceIterationCallback = (id: string, splashInstance: SplashInstance, i: number) => boolean
|
|
50
|
+
|
|
51
|
+
export type NanosplashOptions = {
|
|
52
|
+
imgSrc?: string,
|
|
53
|
+
spinner?: boolean,
|
|
54
|
+
fontSize?: string
|
|
50
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
|
-
import {
|
|
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
|
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* # Make
|
|
30
|
+
* Short hand helper function that creates Nodes.
|
|
31
|
+
* @param {ElementTag} tag
|
|
32
|
+
*/
|
|
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)
|