nanosplash 2.2.2 → 2.3.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 +57 -0
- package/.github/workflows/release.yml +61 -0
- package/README.md +33 -9
- package/dist/iife/nanosplash.iife.js +1 -1
- package/dist/module/Nanosplash.css +1 -0
- package/dist/module/manifest.json +6 -3
- package/dist/module/nanosplash.cjs.js +1 -1
- package/dist/module/nanosplash.es.js +249 -285
- package/docs/index.html +54 -415
- package/docs/nanosplash.iife.js +1 -1
- package/docs/style.css +1 -1
- package/docs/typedoc/assets/highlight.css +1 -50
- package/docs/typedoc/assets/main.js +2 -2
- package/docs/typedoc/assets/search.js +1 -1
- package/docs/typedoc/assets/style.css +32 -2
- package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +1 -0
- package/docs/typedoc/index.html +1 -1
- package/docs/typedoc/modules/types.html +1 -1
- package/index.html +51 -397
- package/jest.config.ts +194 -0
- package/package.json +71 -66
- package/src/Core/Nanosplash.ts +74 -0
- package/src/Core/SplashInstance.ts +154 -0
- package/src/Factory/NanosplashFactory.ts +73 -0
- package/src/Interfaces/ContextualAPIInterface.ts +8 -0
- package/src/Interfaces/IdentityInterface.ts +3 -0
- package/src/Interfaces/ImageInterface.ts +5 -0
- package/src/Interfaces/InsideInterface.ts +5 -0
- package/src/Interfaces/NanosplashInterface.ts +4 -0
- package/src/Interfaces/ProgressInterface.ts +5 -0
- package/src/Interfaces/ShowInterface.ts +5 -0
- package/src/Interfaces/WhileInterface.ts +5 -0
- package/src/main.ts +2 -6
- package/src/repositories/NanosplashRepository.ts +34 -57
- package/src/style.sass +36 -61
- package/src/types.d.ts +45 -197
- package/src/utilities/dom.spec.ts +70 -0
- package/src/utilities/dom.ts +17 -246
- package/update-all.sh +3 -0
- package/vite.iife.config.js +46 -18
- package/vite.mod.config.js +48 -12
- package/vite.site.config.js +0 -3
- package/dist/module/style.css +0 -1
- package/docs/typedoc/classes/Nanosplash.Nanosplash-1.html +0 -56
- package/docs/typedoc/classes/types.Nanosplash.html +0 -56
- package/docs/typedoc/modules/Nanosplash.html +0 -1
- package/src/Nanosplash.ts +0 -421
- package/src/exceptions/Exception.ts +0 -11
- package/src/exceptions/IllegalArgumentException.ts +0 -9
- package/src/exceptions/InvalidDestinationException.ts +0 -9
- package/update-latest.sh +0 -21
package/src/Nanosplash.ts
DELETED
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlurMode,
|
|
3
|
-
Config,
|
|
4
|
-
Destination,
|
|
5
|
-
DisplayController,
|
|
6
|
-
SplashAnimation,
|
|
7
|
-
} from 'nanosplash'
|
|
8
|
-
import InvalidDestinationException from './exceptions/InvalidDestinationException'
|
|
9
|
-
import { NanosplashRepository } from './repositories/NanosplashRepository'
|
|
10
|
-
import './style.sass'
|
|
11
|
-
import {
|
|
12
|
-
display,
|
|
13
|
-
fitToParent,
|
|
14
|
-
invokeOn,
|
|
15
|
-
isElementOrNode,
|
|
16
|
-
isFunction,
|
|
17
|
-
move,
|
|
18
|
-
ref,
|
|
19
|
-
setAttribute,
|
|
20
|
-
setStyle,
|
|
21
|
-
} from './utilities/dom'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Nanosplash
|
|
25
|
-
*
|
|
26
|
-
* @author Isak K. Hauge
|
|
27
|
-
*/
|
|
28
|
-
export class Nanosplash {
|
|
29
|
-
private defaultDestination: Element
|
|
30
|
-
private defaultText: string
|
|
31
|
-
private readonly mainElement: HTMLDivElement
|
|
32
|
-
private readonly splashElement: HTMLImageElement
|
|
33
|
-
private readonly textElement: HTMLDivElement
|
|
34
|
-
private cache = {
|
|
35
|
-
parentPosition: '',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Constructor
|
|
40
|
-
*
|
|
41
|
-
* @public
|
|
42
|
-
* @constructor
|
|
43
|
-
* @param {Config | undefined} config The configuration object.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```js
|
|
47
|
-
* // Instantiatie without config object.
|
|
48
|
-
* new Nanosplash()
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```js
|
|
53
|
-
* // Instantiate with config object.
|
|
54
|
-
* new Nanosplash(config)
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
public constructor(config?: Config) {
|
|
58
|
-
this.defaultText = NanosplashRepository.DEFAULT.TEXT
|
|
59
|
-
this.defaultDestination = NanosplashRepository.DEFAULT.DESTINATION_NODE
|
|
60
|
-
|
|
61
|
-
// Build UI elements
|
|
62
|
-
this.mainElement = NanosplashRepository.makeMainElement()
|
|
63
|
-
this.splashElement = NanosplashRepository.makeSplashElement()
|
|
64
|
-
this.textElement = NanosplashRepository.makeTextElement()
|
|
65
|
-
|
|
66
|
-
// Assemble UI elements
|
|
67
|
-
move(this.splashElement).to(this.mainElement)
|
|
68
|
-
move(this.textElement).to(this.mainElement)
|
|
69
|
-
|
|
70
|
-
// Insert loader into destination element
|
|
71
|
-
move(this.mainElement).to(this.defaultDestination, true)
|
|
72
|
-
display(this.mainElement, false) // Hide by default
|
|
73
|
-
fitToParent(this.mainElement)
|
|
74
|
-
|
|
75
|
-
// Set default configuration
|
|
76
|
-
this.setDefaultStyles()
|
|
77
|
-
|
|
78
|
-
if (config) {
|
|
79
|
-
this.configure(config)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Install
|
|
85
|
-
*
|
|
86
|
-
* @description Assigns itself to the Window object and sets essential event
|
|
87
|
-
* listeners that responds to changes in the browser. The instance is
|
|
88
|
-
* globally accessible through the property "loading".
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```js
|
|
92
|
-
* // Access the instance globally
|
|
93
|
-
* loading.show('Some text')
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
public install(): void {
|
|
97
|
-
Object.defineProperty(window, 'loading', {
|
|
98
|
-
value: this,
|
|
99
|
-
writable: false,
|
|
100
|
-
})
|
|
101
|
-
invokeOn(window, () => fitToParent(this.mainElement), ['resize', 'scroll'])
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Configure
|
|
106
|
-
*
|
|
107
|
-
* @param {Config} config The config object.
|
|
108
|
-
* @return {Nanosplash} The updated instance.
|
|
109
|
-
*
|
|
110
|
-
* @description Mutates the existing configuration and returns the updated
|
|
111
|
-
* instance.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```js
|
|
115
|
-
* nanosplash.configure(config)
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```js
|
|
120
|
-
* window.loading.configure(config).show(text)
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
public configure(config: Config): Nanosplash {
|
|
124
|
-
if (config?.default?.destination) {
|
|
125
|
-
this.defaultDestination = Nanosplash.getDestinationElement(
|
|
126
|
-
config.default.destination
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.defaultText ||= config.default?.text as string
|
|
131
|
-
|
|
132
|
-
// Text:
|
|
133
|
-
if (config.text?.family) {
|
|
134
|
-
this.setTextFontFamily(config.text.family)
|
|
135
|
-
}
|
|
136
|
-
if (config.text?.weight) {
|
|
137
|
-
this.setTextWeight(config.text.weight)
|
|
138
|
-
}
|
|
139
|
-
if (config.text?.color) {
|
|
140
|
-
this.setTextColor(config.text.color)
|
|
141
|
-
}
|
|
142
|
-
if (config.text?.size) {
|
|
143
|
-
this.setTextSize(config.text.size)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Background:
|
|
147
|
-
if (config.background?.color) {
|
|
148
|
-
this.setBackgroundColor(config.background.color)
|
|
149
|
-
}
|
|
150
|
-
if (config.background?.blur) {
|
|
151
|
-
this.setBackgroundBlur(config.background.blur)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Splash:
|
|
155
|
-
// TODO: Fix logical error here.
|
|
156
|
-
if (config.splash) {
|
|
157
|
-
if (config.splash?.src) {
|
|
158
|
-
this.setSplashSource(config.splash.src)
|
|
159
|
-
}
|
|
160
|
-
if (config.splash?.width) {
|
|
161
|
-
this.setSplashWidth(config.splash.width)
|
|
162
|
-
}
|
|
163
|
-
if (config.splash?.height) {
|
|
164
|
-
this.setSplashHeight(config.splash.height)
|
|
165
|
-
}
|
|
166
|
-
if (config.splash?.animation) {
|
|
167
|
-
this.setSplashAnimation(config.splash.animation)
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
display(this.splashElement, false)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return this
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Show
|
|
178
|
-
*
|
|
179
|
-
* @param {string | undefined} text The text that will be shown in the
|
|
180
|
-
* loading screen. If undefined, Nanosplash will use the default text.
|
|
181
|
-
* @return {DisplayController} An object with a function that controls the
|
|
182
|
-
* visibility and destination of the loading screen.
|
|
183
|
-
*
|
|
184
|
-
* @description Shows the loading screen. Invoking the inside function will
|
|
185
|
-
* display the loading screen within the constraints of the defined
|
|
186
|
-
* destination.
|
|
187
|
-
*
|
|
188
|
-
* Basic usage.
|
|
189
|
-
* @example
|
|
190
|
-
* ```js
|
|
191
|
-
* // Basic usage.
|
|
192
|
-
* loading.show(text)
|
|
193
|
-
* ```
|
|
194
|
-
*
|
|
195
|
-
* Display Nanosplash inside other DOM elements.
|
|
196
|
-
* @example
|
|
197
|
-
* ```js
|
|
198
|
-
* // Show loading screen within another element using CSS selector.
|
|
199
|
-
* loading.show(text).inside('#my-element')
|
|
200
|
-
* // Use DOM element reference.
|
|
201
|
-
* loading.show(text).inside(document.getElementById(id))
|
|
202
|
-
* // Use function that returns a DOM element reference.
|
|
203
|
-
* loading.show(text).inside(() => getDomReference())
|
|
204
|
-
* ```
|
|
205
|
-
*
|
|
206
|
-
* Display Nanosplash while an asynchronous task is resolving.
|
|
207
|
-
* @example
|
|
208
|
-
* ```js
|
|
209
|
-
* // Define an asynchronous task.
|
|
210
|
-
* const task = async () => await getDataFromApi()
|
|
211
|
-
* // Show loading screen while the task is running.
|
|
212
|
-
* loading.show(text).during(task)
|
|
213
|
-
* loading.show(text).inside('#my-element').during(task)
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
public show(text?: string): DisplayController {
|
|
217
|
-
this.setText(text ?? NanosplashRepository.DEFAULT.TEXT)
|
|
218
|
-
display(this.mainElement, true)
|
|
219
|
-
|
|
220
|
-
const parent = this.mainElement.parentNode
|
|
221
|
-
if (parent && parent !== document.body) {
|
|
222
|
-
fitToParent(this.mainElement)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Async task handler
|
|
226
|
-
const during = async (task: Promise<any>) => {
|
|
227
|
-
await task
|
|
228
|
-
this.hide()
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Returns a
|
|
232
|
-
return {
|
|
233
|
-
inside: (destination: Destination) => {
|
|
234
|
-
const element = Nanosplash.getDestinationElement(destination)
|
|
235
|
-
move(this.mainElement).to(element, true)
|
|
236
|
-
this.cache.parentPosition = element.style.position
|
|
237
|
-
fitToParent(this.mainElement)
|
|
238
|
-
return { during }
|
|
239
|
-
},
|
|
240
|
-
during: during,
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Hide
|
|
246
|
-
*
|
|
247
|
-
* @description Hides the loading screen and moves to its default destination.
|
|
248
|
-
* If no custom default destination is defined, it will move to the document
|
|
249
|
-
* body.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```js
|
|
253
|
-
* // Basic usage
|
|
254
|
-
* loading.hide()
|
|
255
|
-
* // Use with async functions
|
|
256
|
-
* loading.show('Loading ...')
|
|
257
|
-
* await fetchStuffFromApi()
|
|
258
|
-
* loading.hide()
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
public hide(): void {
|
|
262
|
-
const parent = this.mainElement.parentElement as HTMLElement
|
|
263
|
-
setStyle(parent, 'position', this.cache.parentPosition)
|
|
264
|
-
display(this.mainElement, false)
|
|
265
|
-
this.setText(this.defaultText)
|
|
266
|
-
move(this.mainElement).to(this.defaultDestination, true)
|
|
267
|
-
fitToParent(this.mainElement)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Set Default Styles
|
|
272
|
-
* @private
|
|
273
|
-
*/
|
|
274
|
-
private setDefaultStyles(): void {
|
|
275
|
-
this.setTextFontFamily(NanosplashRepository.DEFAULT.TEXT_FONT)
|
|
276
|
-
this.setTextWeight(NanosplashRepository.DEFAULT.TEXT_WEIGHT)
|
|
277
|
-
this.setTextColor(NanosplashRepository.DEFAULT.TEXT_COLOR)
|
|
278
|
-
this.setTextSize(NanosplashRepository.DEFAULT.TEXT_SIZE)
|
|
279
|
-
this.setSplashSource(NanosplashRepository.DEFAULT.SPLASH_SOURCE)
|
|
280
|
-
this.setSplashWidth(NanosplashRepository.DEFAULT.SPLASH_WIDTH)
|
|
281
|
-
this.setSplashHeight(NanosplashRepository.DEFAULT.SPLASH_HEIGHT)
|
|
282
|
-
this.setSplashAnimation(NanosplashRepository.DEFAULT.SPLASH_ANIMATION)
|
|
283
|
-
this.setBackgroundColor(NanosplashRepository.DEFAULT.BACKGROUND_COLOR)
|
|
284
|
-
this.setBackgroundBlur(NanosplashRepository.DEFAULT.BACKGROUND_BLUR)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Set Text
|
|
289
|
-
*
|
|
290
|
-
* @param {string} text
|
|
291
|
-
* @private
|
|
292
|
-
*/
|
|
293
|
-
private setText(text: string) {
|
|
294
|
-
this.textElement.innerText = text
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Set Text Font Family
|
|
299
|
-
*
|
|
300
|
-
* @param {string} fontFamily
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
private setTextFontFamily(fontFamily: string): void {
|
|
304
|
-
setStyle(this.textElement, 'fontFamily', fontFamily)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Set Text Font Weight
|
|
309
|
-
*
|
|
310
|
-
* @param {string} fontWeight
|
|
311
|
-
* @private
|
|
312
|
-
*/
|
|
313
|
-
private setTextWeight(fontWeight: string): void {
|
|
314
|
-
setStyle(this.textElement, 'fontWeight', fontWeight)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Set Text Color
|
|
319
|
-
*
|
|
320
|
-
* @param {string} color
|
|
321
|
-
* @private
|
|
322
|
-
*/
|
|
323
|
-
private setTextColor(color: string): void {
|
|
324
|
-
setStyle(this.textElement, 'color', color)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Set Text Size
|
|
329
|
-
*
|
|
330
|
-
* @param {string} fontSize
|
|
331
|
-
* @private
|
|
332
|
-
*/
|
|
333
|
-
private setTextSize(fontSize: string): void {
|
|
334
|
-
setStyle(this.textElement, 'fontSize', fontSize)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Set Splash Source
|
|
339
|
-
*
|
|
340
|
-
* @param {string} src
|
|
341
|
-
* @private
|
|
342
|
-
*/
|
|
343
|
-
private setSplashSource(src: string): void {
|
|
344
|
-
this.splashElement.src = src
|
|
345
|
-
display(this.splashElement, true)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Set Splash Width
|
|
350
|
-
*
|
|
351
|
-
* @param {string} width
|
|
352
|
-
* @private
|
|
353
|
-
*/
|
|
354
|
-
private setSplashWidth(width: string): void {
|
|
355
|
-
setStyle(this.splashElement, 'width', width)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Set Splash Height
|
|
360
|
-
*
|
|
361
|
-
* @param {string} height
|
|
362
|
-
* @private
|
|
363
|
-
*/
|
|
364
|
-
private setSplashHeight(height: string): void {
|
|
365
|
-
setStyle(this.splashElement, 'height', height)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Set Splash Animation
|
|
370
|
-
*
|
|
371
|
-
* @param {SplashAnimation} animation
|
|
372
|
-
* @private
|
|
373
|
-
*/
|
|
374
|
-
private setSplashAnimation(animation: SplashAnimation): void {
|
|
375
|
-
setAttribute(this.mainElement, 'data-splash-animation', animation)
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Set Background Color
|
|
380
|
-
*
|
|
381
|
-
* @param color
|
|
382
|
-
* @private
|
|
383
|
-
*/
|
|
384
|
-
private setBackgroundColor(color: string): void {
|
|
385
|
-
setStyle(this.mainElement, 'backgroundColor', color)
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Set Background Blur
|
|
390
|
-
*
|
|
391
|
-
* @param {BlurMode} blurMode
|
|
392
|
-
* @private
|
|
393
|
-
*/
|
|
394
|
-
private setBackgroundBlur(blurMode: BlurMode): void {
|
|
395
|
-
setAttribute(this.mainElement, 'data-blur', blurMode)
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* @throws InvalidDestinationException
|
|
400
|
-
* @private
|
|
401
|
-
*/
|
|
402
|
-
private static getDestinationElement(destination: Destination): HTMLElement {
|
|
403
|
-
const isString = typeof destination === 'string'
|
|
404
|
-
const isCallback = isFunction(destination)
|
|
405
|
-
const isElement = isElementOrNode(destination)
|
|
406
|
-
|
|
407
|
-
let destinationNode: HTMLElement | null
|
|
408
|
-
|
|
409
|
-
if (isString) {
|
|
410
|
-
destinationNode = ref(destination as string) as HTMLElement
|
|
411
|
-
} else if (isCallback) {
|
|
412
|
-
destinationNode = (destination as Function)() as HTMLElement
|
|
413
|
-
} else if (isElement) {
|
|
414
|
-
destinationNode = destination as HTMLElement
|
|
415
|
-
} else {
|
|
416
|
-
throw new InvalidDestinationException()
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
return destinationNode as HTMLElement
|
|
420
|
-
}
|
|
421
|
-
}
|
package/update-latest.sh
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
PACKAGES=(
|
|
3
|
-
@vitejs/plugin-vue
|
|
4
|
-
@vue/compiler-sfc
|
|
5
|
-
autoprefixer
|
|
6
|
-
cssnano
|
|
7
|
-
postcss
|
|
8
|
-
sass
|
|
9
|
-
typedoc
|
|
10
|
-
typescript
|
|
11
|
-
vite
|
|
12
|
-
vite-plugin-singlefile
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
PACKAGE_STR=""
|
|
16
|
-
|
|
17
|
-
for package in ${PACKAGES[@]}
|
|
18
|
-
do PACKAGE_STR+=" $package@latest"
|
|
19
|
-
done
|
|
20
|
-
|
|
21
|
-
yarn add -D $PACKAGE_STR
|