nanosplash 2.5.2 → 3.0.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.
Files changed (80) hide show
  1. package/.github/workflows/ci.yml +48 -0
  2. package/.prettierrc +10 -9
  3. package/README.md +22 -89
  4. package/dist/main.css +1 -0
  5. package/dist/ns.cjs.js +1 -0
  6. package/dist/ns.es.js +330 -0
  7. package/dist/ns.iife.js +2 -0
  8. package/index.html +41 -122
  9. package/package.json +27 -34
  10. package/src/main.ts +8 -5
  11. package/src/sass/ns.sass +86 -0
  12. package/src/ts/core/Nanosplash/Nanosplash.ts +97 -0
  13. package/src/ts/core/Nanosplash/interfaces/NanosplashAPI.ts +50 -0
  14. package/src/ts/core/Nanosplash/interfaces/NanosplashInterface.ts +42 -0
  15. package/src/ts/core/Nanosplash/repositories/NanosplashRepository.ts +178 -0
  16. package/src/ts/core/Nanosplash/services/NanosplashService.ts +222 -0
  17. package/src/ts/types/Alias.d.ts +1 -0
  18. package/src/ts/types/Nanosplash.d.ts +18 -0
  19. package/src/ts/types/NanosplashService.d.ts +1 -0
  20. package/src/ts/util/Guid.ts +13 -0
  21. package/src/ts/util/Stack.ts +73 -0
  22. package/src/vite-env.d.ts +8 -0
  23. package/tests/Guid.spec.ts +21 -0
  24. package/tests/Nanosplash.spec.ts +64 -0
  25. package/tests/NanosplashRepository.spec.ts +91 -0
  26. package/tests/NanosplashService.spec.ts +119 -0
  27. package/tests/Stack.spec.ts +56 -0
  28. package/tsconfig.json +9 -5
  29. package/vite.config.ts +22 -14
  30. package/.github/workflows/production.yml +0 -60
  31. package/.github/workflows/release.yml +0 -61
  32. package/LICENSE +0 -21
  33. package/_config.yml +0 -1
  34. package/dist/iife/manifest.json +0 -7
  35. package/dist/iife/nanosplash.iife.js +0 -1
  36. package/dist/module/manifest.json +0 -7
  37. package/dist/module/nanosplash.cjs.js +0 -1
  38. package/dist/module/nanosplash.es.js +0 -371
  39. package/dist/module/style.css +0 -1
  40. package/docs/index.html +0 -131
  41. package/docs/nanosplash.iife.js +0 -6
  42. package/docs/style.css +0 -1
  43. package/docs/typedoc/.nojekyll +0 -1
  44. package/docs/typedoc/assets/highlight.css +0 -22
  45. package/docs/typedoc/assets/icons.css +0 -1043
  46. package/docs/typedoc/assets/icons.png +0 -0
  47. package/docs/typedoc/assets/icons@2x.png +0 -0
  48. package/docs/typedoc/assets/main.js +0 -52
  49. package/docs/typedoc/assets/search.js +0 -1
  50. package/docs/typedoc/assets/style.css +0 -1414
  51. package/docs/typedoc/assets/widgets.png +0 -0
  52. package/docs/typedoc/assets/widgets@2x.png +0 -0
  53. package/docs/typedoc/classes/Core_Nanosplash.default.html +0 -133
  54. package/docs/typedoc/index.html +0 -1
  55. package/docs/typedoc/modules/Core_Nanosplash.html +0 -1
  56. package/docs/typedoc/modules/types.html +0 -1
  57. package/favicon.svg +0 -15
  58. package/postcss.config.js +0 -8
  59. package/src/Core/Nanosplash.ts +0 -257
  60. package/src/Core/SplashInstance.ts +0 -298
  61. package/src/Exceptions/DestinationException.ts +0 -13
  62. package/src/Exceptions/Exception.ts +0 -9
  63. package/src/Exceptions/IllegalArgumentException.ts +0 -11
  64. package/src/Factory/NanosplashFactory.ts +0 -93
  65. package/src/Interfaces/ContextualAPIInterface.ts +0 -8
  66. package/src/Interfaces/IdentityInterface.ts +0 -3
  67. package/src/Interfaces/InsideInterface.ts +0 -5
  68. package/src/Interfaces/NanosplashInterface.ts +0 -8
  69. package/src/Interfaces/ProgressInterface.ts +0 -5
  70. package/src/Interfaces/ShowInterface.ts +0 -5
  71. package/src/Interfaces/WhileInterface.ts +0 -5
  72. package/src/Repositories/NanosplashRepository.ts +0 -82
  73. package/src/Tests/dom.spec.ts +0 -72
  74. package/src/Utilities/dom.ts +0 -49
  75. package/src/style.sass +0 -88
  76. package/src/types.d.ts +0 -59
  77. package/update-all.sh +0 -3
  78. package/vite.iife.config.js +0 -72
  79. package/vite.mod.config.js +0 -71
  80. package/vite.site.config.js +0 -22
@@ -1,371 +0,0 @@
1
- var style = /* @__PURE__ */ (() => ".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")();
2
- function get(selector) {
3
- return document.querySelector(selector);
4
- }
5
- function move(source, destination, asFirstChild = false) {
6
- if (source && destination) {
7
- destination.hasChildNodes() && asFirstChild ? destination.insertBefore(source, destination.firstChild) : destination.appendChild(source);
8
- }
9
- }
10
- const mk = (tag) => document.createElement(tag);
11
- function addClass(node, ...classes) {
12
- node.classList.add(...classes);
13
- }
14
- function setAttr(node, attribute, value) {
15
- node.setAttribute(attribute, value);
16
- }
17
- class Exception extends Error {
18
- constructor(message, cause) {
19
- super(message);
20
- this.name = this.constructor.name;
21
- this.cause = cause;
22
- }
23
- }
24
- class DestinationException extends Exception {
25
- constructor(message, destination, cause) {
26
- super(message);
27
- this.destination = destination;
28
- this.cause = cause;
29
- }
30
- }
31
- class IllegalArgumentException extends Exception {
32
- constructor(message, argument) {
33
- super(message);
34
- this.argument = argument;
35
- }
36
- }
37
- class NanosplashRepository {
38
- static destinationToNode(destination) {
39
- if (typeof destination === "string") {
40
- try {
41
- const element = get(destination);
42
- if (!element) {
43
- throw new Exception(`No DOM match with ${destination}`);
44
- }
45
- return element;
46
- } catch (e) {
47
- throw new DestinationException(`Destination (${destination}) is either invalid or non-existing in DOM`, destination, e);
48
- }
49
- } else if (destination instanceof Node) {
50
- return destination;
51
- }
52
- throw new IllegalArgumentException(`Destination (${destination}) must be either a Node or a CSS selector`, destination);
53
- }
54
- static createContextualApiObject(splash) {
55
- const ctx = {
56
- getId: () => splash.getId(),
57
- remove: () => splash.delete(),
58
- moveTo: (selector) => splash.moveTo(selector),
59
- getText: () => splash.getText(),
60
- setText: (text) => splash.setText(text),
61
- getImgSrc: () => splash.getImgSrc(),
62
- setImgSrc: (src) => splash.setImgSrc(src)
63
- };
64
- return {
65
- ...ctx,
66
- inside: (selector) => {
67
- splash.moveTo(selector);
68
- return ctx;
69
- }
70
- };
71
- }
72
- static createNanosplashSpinnerElement() {
73
- const div = mk("div");
74
- addClass(div, "ns-spinner");
75
- div.innerHTML = `
76
- <svg viewBox="0 0 50 50">
77
- <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
78
- </svg>
79
- `;
80
- return div;
81
- }
82
- }
83
- class SplashInstance {
84
- constructor(ns, text, imgSrc) {
85
- var _a;
86
- this.nsRootElement = mk("div");
87
- this.nsTextElement = mk("div");
88
- this.nsTextContainerElement = mk("div");
89
- this.nsSpinnerElement = NanosplashRepository.createNanosplashSpinnerElement();
90
- this.nsWindowElement = mk("div");
91
- this.nsWrapperElement = mk("div");
92
- this.nsContentElement = mk("div");
93
- this.nsImageElement = mk("img");
94
- this.id = Math.random().toString(36).substring(2);
95
- this.nsInstance = ns;
96
- this.nsTextElement.innerText = text;
97
- this.imgSrc = imgSrc;
98
- this.nsImageElement.src = (_a = this.imgSrc) != null ? _a : "";
99
- this.nsImageElement.alt = Nanosplash.APP_NAME;
100
- this.nsRootElement.style.fontSize = ns.getFontSize();
101
- this.nsSpinnerElement.style.display = ns.spinnerIsVisible() ? "flex" : "none";
102
- this.assembleNSComponent();
103
- this.setImgSrc(imgSrc);
104
- }
105
- assignCSSClasses() {
106
- addClass(this.nsContentElement, "ns-container");
107
- addClass(this.nsWrapperElement, "ns-blur");
108
- addClass(this.nsImageElement, "ns-img");
109
- addClass(this.nsTextElement, "ns-text");
110
- addClass(this.nsTextContainerElement, "ns-text-container");
111
- addClass(this.nsSpinnerElement, "ns-spinner");
112
- addClass(this.nsWindowElement, "ns", "ns-window");
113
- addClass(this.nsRootElement, "ns-wrapper");
114
- }
115
- assembleElementStructure() {
116
- this.nsTextContainerElement.append(this.nsTextElement, this.nsSpinnerElement);
117
- this.nsContentElement.append(this.nsImageElement, this.nsTextContainerElement);
118
- this.nsWindowElement.append(this.nsContentElement);
119
- this.nsRootElement.append(this.nsWrapperElement, this.nsWindowElement);
120
- }
121
- assembleNSComponent() {
122
- this.nsRootElement.id = this.getId();
123
- setAttr(this.nsRootElement, "data-ctx", "nanosplash");
124
- this.assembleElementStructure();
125
- this.assignCSSClasses();
126
- }
127
- getId() {
128
- return this.id;
129
- }
130
- getText() {
131
- return this.nsTextElement.innerText;
132
- }
133
- setText(text) {
134
- this.nsTextElement.innerText = text;
135
- return this;
136
- }
137
- getImgSrc() {
138
- return this.imgSrc;
139
- }
140
- setImgSrc(src) {
141
- this.nsImageElement.src = src != null ? src : "";
142
- this.nsImageElement.style.display = src ? "block" : "none";
143
- this.assembleElementStructure();
144
- return this;
145
- }
146
- getDestination() {
147
- return this.destinationNode;
148
- }
149
- cleanAndRestore() {
150
- const currentParent = this.nsRootElement.parentElement;
151
- if (currentParent) {
152
- this.restoreDOMStructure(currentParent);
153
- }
154
- }
155
- resetFullscreenAttributes() {
156
- setAttr(this.nsRootElement, "style", "");
157
- this.nsRootElement.classList.remove("ns-fs");
158
- }
159
- moveWithRegularStrategy(targetNode) {
160
- const targetParentNode = targetNode.parentNode;
161
- if (targetParentNode) {
162
- this.restoreDOMStructure(targetParentNode);
163
- targetParentNode.replaceChild(this.nsRootElement, targetNode);
164
- this.nsWrapperElement.appendChild(targetNode);
165
- }
166
- }
167
- moveWithFullscreenStrategy() {
168
- this.nsRootElement.classList.add("ns-fs");
169
- move(this.nsRootElement, document.body, true);
170
- }
171
- replaceSplashInstancesHavingSameDestination(destinationNode) {
172
- const fnNotSameInstance = (v) => v.getId() !== this.getId();
173
- const fnDelete = (v) => v.delete();
174
- this.nsInstance.getFromDestinationNode(destinationNode).filter(fnNotSameInstance).forEach(fnDelete);
175
- }
176
- moveTo(destination) {
177
- try {
178
- this.cleanAndRestore();
179
- this.destinationNode = NanosplashRepository.destinationToNode(destination);
180
- this.replaceSplashInstancesHavingSameDestination(this.destinationNode);
181
- const targetIsBody = this.destinationNode === document.body;
182
- if (targetIsBody) {
183
- this.moveWithFullscreenStrategy();
184
- } else {
185
- this.resetFullscreenAttributes();
186
- this.moveWithRegularStrategy(this.destinationNode);
187
- }
188
- this.assembleNSComponent();
189
- } catch (e) {
190
- this.delete();
191
- if (this.nsInstance.debug) {
192
- console.warn(e);
193
- }
194
- }
195
- }
196
- forEachWrappedNode(callback) {
197
- Array.from(this.nsWrapperElement.childNodes).forEach(callback);
198
- }
199
- restoreDOMStructure(parentNode) {
200
- this.forEachWrappedNode((child) => parentNode.insertBefore(child, this.nsRootElement));
201
- }
202
- removeElementsFromDOM() {
203
- [
204
- this.nsTextElement,
205
- this.nsSpinnerElement,
206
- this.nsTextContainerElement,
207
- this.nsImageElement,
208
- this.nsContentElement,
209
- this.nsWrapperElement,
210
- this.nsWindowElement,
211
- this.nsRootElement
212
- ].forEach((v) => v.remove());
213
- }
214
- delete() {
215
- this.cleanAndRestore();
216
- this.removeElementsFromDOM();
217
- this.nsInstance.delete(this);
218
- }
219
- }
220
- class NanosplashFactory {
221
- static ensureInstance(splash, ns, text, imgSrc) {
222
- var _a;
223
- if (!splash) {
224
- splash = new SplashInstance(ns, text, imgSrc);
225
- }
226
- return splash.setText(text).setImgSrc((_a = splash.getImgSrc()) != null ? _a : imgSrc);
227
- }
228
- static createShowFunction(ns, splash) {
229
- return (text) => {
230
- splash = NanosplashFactory.ensureInstance(splash, ns, text);
231
- ns.instances.set(splash.getId(), splash);
232
- splash.moveTo(document.body);
233
- return NanosplashRepository.createContextualApiObject(splash);
234
- };
235
- }
236
- static createProgressFunction(ns, splash) {
237
- return (...jobs) => {
238
- splash = NanosplashFactory.ensureInstance(splash, ns, "");
239
- splash.moveTo(document.body);
240
- (async () => {
241
- for (const [_, [job, text]] of jobs.entries()) {
242
- splash.setText(text);
243
- await job;
244
- }
245
- splash.delete();
246
- })();
247
- return NanosplashRepository.createContextualApiObject(splash);
248
- };
249
- }
250
- static createWhileFunction(ns, splash) {
251
- return (asyncTask) => {
252
- splash = NanosplashFactory.ensureInstance(splash, ns, "");
253
- return {
254
- show(text) {
255
- ns.instances.set(splash.getId(), splash);
256
- splash.moveTo(document.body);
257
- splash.setText(text);
258
- asyncTask.finally(() => splash.delete());
259
- return NanosplashRepository.createContextualApiObject(splash);
260
- }
261
- };
262
- };
263
- }
264
- }
265
- const _Nanosplash = class {
266
- constructor(options) {
267
- var _a;
268
- this.debug = (options == null ? void 0 : options.debug) === void 0 ? _Nanosplash.DEBUG : options.spinner;
269
- this.imgSrc = options == null ? void 0 : options.imgSrc;
270
- this.spinner = (options == null ? void 0 : options.spinner) === void 0 ? _Nanosplash.SPINNER_DEFAULT_VISIBILITY : options.spinner;
271
- this.fontSize = (_a = options == null ? void 0 : options.fontSize) != null ? _a : "18px";
272
- this.instances = /* @__PURE__ */ new Map();
273
- }
274
- setImgSrc(value) {
275
- this.imgSrc = value;
276
- return this;
277
- }
278
- showSpinner(value) {
279
- this.spinner = value;
280
- return this;
281
- }
282
- setFontSize(value) {
283
- this.fontSize = value;
284
- return this;
285
- }
286
- getImgSrc() {
287
- return this.imgSrc;
288
- }
289
- spinnerIsVisible() {
290
- return this.spinner;
291
- }
292
- getFontSize() {
293
- return this.fontSize;
294
- }
295
- show(text) {
296
- return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text, this.imgSrc))(text);
297
- }
298
- progress(...jobs) {
299
- return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, "", this.imgSrc))(...jobs);
300
- }
301
- while(asyncTask) {
302
- return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, "", this.imgSrc))(asyncTask);
303
- }
304
- lifoIterate(callback) {
305
- const n = this.instances.size;
306
- const instances = Array.from(this.instances.values());
307
- for (let i = n - 1; i >= 0; i--) {
308
- const instance = instances[i];
309
- const id = instance.getId();
310
- if (!callback(id, instance, i)) {
311
- break;
312
- }
313
- }
314
- }
315
- delete(splashInstance) {
316
- this.instances.delete(splashInstance.getId());
317
- }
318
- hideAll() {
319
- this.instances.forEach((instance) => instance.delete());
320
- }
321
- hide(ref) {
322
- try {
323
- if (ref) {
324
- const isString = typeof ref === "string";
325
- const isNode = ref instanceof Node;
326
- const deleteInstancesWhereDestination = (destination) => {
327
- Array.from(this.instances.values()).filter((v) => v.getDestination() === destination).forEach((v) => v.delete());
328
- };
329
- if (isString) {
330
- const splashInstance = this.instances.get(ref);
331
- if (splashInstance) {
332
- splashInstance.delete();
333
- return;
334
- } else {
335
- const element = get(ref);
336
- if (element) {
337
- deleteInstancesWhereDestination(element);
338
- }
339
- throw new Exception(`The CSS selector (${ref}) points to a non-existing DOM element.`);
340
- }
341
- } else if (isNode) {
342
- deleteInstancesWhereDestination(ref);
343
- } else {
344
- throw new IllegalArgumentException("The ref argument must be either a string or Node", ref);
345
- }
346
- } else {
347
- const n = this.instances.size;
348
- this.lifoIterate((_, splashInstance, i) => {
349
- const remove = i === n - 1;
350
- if (remove) {
351
- splashInstance.delete();
352
- }
353
- return remove;
354
- });
355
- }
356
- } catch (e) {
357
- if (this.debug) {
358
- console.warn(e);
359
- }
360
- }
361
- }
362
- getFromDestinationNode(node) {
363
- const fnSameDestinationNode = (v) => v.getDestination() === node;
364
- return Array.from(this.instances.values()).filter(fnSameDestinationNode);
365
- }
366
- };
367
- let Nanosplash = _Nanosplash;
368
- Nanosplash.APP_NAME = "Nanosplash";
369
- Nanosplash.SPINNER_DEFAULT_VISIBILITY = true;
370
- Nanosplash.DEBUG = true;
371
- export { Nanosplash as default };
@@ -1 +0,0 @@
1
- .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}}
package/docs/index.html DELETED
@@ -1,131 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UT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ss.com"></script>
7
- <link href="https://cdn.lineicons.com/3.0/lineicons.css" rel="stylesheet" />
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
- <title>Nanosplash</title>
10
- <meta name="description" content="The tiny loading screen" />
11
- <meta name="keywords" content="splash, screen, loading" />
12
- <meta name="author" content="Isak Hauge" />
13
- <script type="module" crossorigin src="/nanosplash.iife.js"></script>
14
- <link rel="stylesheet" href="/style.css">
15
- </head>
16
- <body class="flex flex-col justify-between">
17
- <div class="w-100 min-h-screen flex flex-col justify-center items-center">
18
- <div class="text-4xl text-slate-900 drop-shadow-lg">Nanosplash</div>
19
- <div class="text-pink-500 mt-3 font-mono text-sm">ns.show('text').inside('#id')</div>
20
- <div class="flex gap-5">
21
- <div
22
- id="demo"
23
- class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
24
- >
25
- <i class="lni lni-play"></i>
26
- Display demo
27
- </div>
28
- <a
29
- href="#example"
30
- class="bg-slate-500 text-slate-200 p-3 cursor-pointer hover:text-white rounded-xl shadow-xl mt-8"
31
- >
32
- Show examples
33
- </a>
34
- </div>
35
- <div class="flex flex-col space-y-2 my-10">
36
- <div class="flex space-x-2 justify-center">
37
- <img src="https://badgen.net/npm/v/nanosplash" />
38
- <img src="https://badgen.net/npm/types/nanosplash" />
39
- <img src="https://badgen.net/npm/dw/nanosplash" />
40
- </div>
41
- <div class="flex space-x-2 justify-center">
42
- <img src="https://badgen.net/bundlephobia/min/nanosplash" />
43
- <img
44
- src="https://badgen.net/bundlephobia/tree-shaking/nanosplash"
45
- />
46
- </div>
47
- </div>
48
- <div class="flex rounded-xl text-slate-400 shadow-xl overflow-hidden">
49
- <div data-copy class="p-3 bg-slate-800 text-slate-400 font-mono">
50
- &lt;script src=&quot;https://unpkg.com/nanosplash/dist/iife/nanosplash.iife.js&quot;&gt;
51
- </div>
52
- <div id="copy" class="bg-pink-500 text-pink-200 p-3 cursor-pointer hover:text-white">Copy</div>
53
- </div>
54
- <div class="mt-10 flex justify-content items-center divide-x-2 text-slate-400">
55
- <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>
56
- <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>
57
- </div>
58
- <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>
59
- </div>
60
- <div id="example" class="grid grid-cols-1 xl:grid-cols-2 gap-1">
61
- <div id="a" class="p-20 bg-slate-100 flex flex-col items-center">
62
- <div class="text-xl mb-10">Give user progress feedback</div>
63
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
64
- ns.progress(<br>
65
- &nbsp;&nbsp;[promise1, 'Loading A'],<br>
66
- &nbsp;&nbsp;[promise2, 'Loading B'],<br>
67
- &nbsp;&nbsp;[promise3, 'Loading C'],<br>
68
- ).inside('#myDiv')
69
- </div>
70
- </div>
71
- <div id="b" class="p-20 bg-slate-100 flex flex-col items-center">
72
- <div class="text-xl mb-10">Handle async functions</div>
73
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
74
- ns.while(promise).show('Loading ...').inside('#myDiv')
75
- </div>
76
- </div>
77
- <div id="c" class="p-20 bg-slate-100 flex flex-col items-center">
78
- <div class="text-xl mb-10">Display fullscreen</div>
79
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
80
- ns.show('Fullscreen text')
81
- </div>
82
- </div>
83
- <div id="d" class="p-20 bg-slate-100 flex flex-col items-center">
84
- <div class="text-xl mb-10">Display multiple, independent instances</div>
85
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
86
- ns.show('Loading component A').inside('#a')<br>
87
- ns.show('Loading component B').inside('#b')<br>
88
- ns.show('Loading component C').inside('#c')
89
- </div>
90
- </div>
91
- <div id="e" class="p-20 bg-slate-100 flex flex-col items-center">
92
- <div class="text-xl mb-10">Move splash instance to another destination</div>
93
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
94
- const splash = ns.show('Loading').inside('#a')<br>
95
- splash.moveTo('#b')
96
- </div>
97
- </div>
98
- <div id="f" class="p-20 bg-slate-100 flex flex-col items-center">
99
- <div class="text-xl mb-10">Hide splash instances</div>
100
- <div class="text-white bg-slate-800 p-5 rounded-xl shadow-2xl font-mono text-sm break-all">
101
- // Hides one instance at a time, in a LIFO-fashion.<br>
102
- ns.hide()<br><br>
103
- // Hides all instances.<br>
104
- ns.hideAll()
105
- </div>
106
- </div>
107
- </div>
108
- <footer>
109
-
110
- <script>
111
- window.addEventListener('load', () => {
112
- document.getElementById('demo').onclick = function () {
113
- const wait = ms => new Promise(r => setTimeout(r, ms))
114
- window.ns.progress(
115
- [wait(2000), 'Loading data from API'],
116
- [wait(4000), 'Restructuring'],
117
- [wait(6000), 'Indexing'],
118
- [wait(8000), 'Give this repo a star']
119
- )
120
- }
121
- document.getElementById('copy').onclick = function () {
122
- const text = document.querySelector('[data-copy]').innerText
123
- navigator.clipboard.writeText(text)
124
- alert('Copied to clipboard!')
125
- }
126
- })
127
- </script>
128
- </footer>
129
- <style>body{min-height:100vh}</style>
130
- </body>
131
- </html>
@@ -1,6 +0,0 @@
1
- (function(){"use strict";const w=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const m of r.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&i(m)}).observe(document,{childList:!0,subtree:!0});function t(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerpolicy&&(r.referrerPolicy=s.referrerpolicy),s.crossorigin==="use-credentials"?r.credentials="include":s.crossorigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=t(s);fetch(s.href,r)}};var y=(()=>`.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}}
2
- `)();function g(n){return document.querySelector(n)}function p(n,e,t=!1){n&&e&&(e.hasChildNodes()&&t?e.insertBefore(n,e.firstChild):e.appendChild(n))}const a=n=>document.createElement(n);function o(n,...e){n.classList.add(...e)}function E(n,e,t){n.setAttribute(e,t)}class d extends Error{constructor(e,t){super(e),this.name=this.constructor.name,this.cause=t}}class I extends d{constructor(e,t,i){super(e),this.destination=t,this.cause=i}}class S extends d{constructor(e,t){super(e),this.argument=t}}class h{static destinationToNode(e){if(typeof e=="string")try{const t=g(e);if(!t)throw new d(`No DOM match with ${e}`);return t}catch(t){throw new I(`Destination (${e}) is either invalid or non-existing in DOM`,e,t)}else if(e instanceof Node)return e;throw new S(`Destination (${e}) must be either a Node or a CSS selector`,e)}static createContextualApiObject(e){const t={getId:()=>e.getId(),remove:()=>e.delete(),moveTo:i=>e.moveTo(i),getText:()=>e.getText(),setText:i=>e.setText(i),getImgSrc:()=>e.getImgSrc(),setImgSrc:i=>e.setImgSrc(i)};return{...t,inside:i=>(e.moveTo(i),t)}}static createNanosplashSpinnerElement(){const e=a("div");return o(e,"ns-spinner"),e.innerHTML=`
3
- <svg viewBox="0 0 50 50">
4
- <circle class="path" cx="25" cy="25" r="20" fill="none"></circle>
5
- </svg>
6
- `,e}}class u{constructor(e,t,i){var s;this.nsRootElement=a("div"),this.nsTextElement=a("div"),this.nsTextContainerElement=a("div"),this.nsSpinnerElement=h.createNanosplashSpinnerElement(),this.nsWindowElement=a("div"),this.nsWrapperElement=a("div"),this.nsContentElement=a("div"),this.nsImageElement=a("img"),this.id=Math.random().toString(36).substring(2),this.nsInstance=e,this.nsTextElement.innerText=t,this.imgSrc=i,this.nsImageElement.src=(s=this.imgSrc)!=null?s:"",this.nsImageElement.alt=l.APP_NAME,this.nsRootElement.style.fontSize=e.getFontSize(),this.nsSpinnerElement.style.display=e.spinnerIsVisible()?"flex":"none",this.assembleNSComponent(),this.setImgSrc(i)}assignCSSClasses(){o(this.nsContentElement,"ns-container"),o(this.nsWrapperElement,"ns-blur"),o(this.nsImageElement,"ns-img"),o(this.nsTextElement,"ns-text"),o(this.nsTextContainerElement,"ns-text-container"),o(this.nsSpinnerElement,"ns-spinner"),o(this.nsWindowElement,"ns","ns-window"),o(this.nsRootElement,"ns-wrapper")}assembleElementStructure(){this.nsTextContainerElement.append(this.nsTextElement,this.nsSpinnerElement),this.nsContentElement.append(this.nsImageElement,this.nsTextContainerElement),this.nsWindowElement.append(this.nsContentElement),this.nsRootElement.append(this.nsWrapperElement,this.nsWindowElement)}assembleNSComponent(){this.nsRootElement.id=this.getId(),E(this.nsRootElement,"data-ctx","nanosplash"),this.assembleElementStructure(),this.assignCSSClasses()}getId(){return this.id}getText(){return this.nsTextElement.innerText}setText(e){return this.nsTextElement.innerText=e,this}getImgSrc(){return this.imgSrc}setImgSrc(e){return this.nsImageElement.src=e!=null?e:"",this.nsImageElement.style.display=e?"block":"none",this.assembleElementStructure(),this}getDestination(){return this.destinationNode}cleanAndRestore(){const e=this.nsRootElement.parentElement;e&&this.restoreDOMStructure(e)}resetFullscreenAttributes(){E(this.nsRootElement,"style",""),this.nsRootElement.classList.remove("ns-fs")}moveWithRegularStrategy(e){const t=e.parentNode;t&&(this.restoreDOMStructure(t),t.replaceChild(this.nsRootElement,e),this.nsWrapperElement.appendChild(e))}moveWithFullscreenStrategy(){this.nsRootElement.classList.add("ns-fs"),p(this.nsRootElement,document.body,!0)}replaceSplashInstancesHavingSameDestination(e){const t=s=>s.getId()!==this.getId(),i=s=>s.delete();this.nsInstance.getFromDestinationNode(e).filter(t).forEach(i)}moveTo(e){try{this.cleanAndRestore(),this.destinationNode=h.destinationToNode(e),this.replaceSplashInstancesHavingSameDestination(this.destinationNode),this.destinationNode===document.body?this.moveWithFullscreenStrategy():(this.resetFullscreenAttributes(),this.moveWithRegularStrategy(this.destinationNode)),this.assembleNSComponent()}catch(t){this.delete(),this.nsInstance.debug&&console.warn(t)}}forEachWrappedNode(e){Array.from(this.nsWrapperElement.childNodes).forEach(e)}restoreDOMStructure(e){this.forEachWrappedNode(t=>e.insertBefore(t,this.nsRootElement))}removeElementsFromDOM(){[this.nsTextElement,this.nsSpinnerElement,this.nsTextContainerElement,this.nsImageElement,this.nsContentElement,this.nsWrapperElement,this.nsWindowElement,this.nsRootElement].forEach(e=>e.remove())}delete(){this.cleanAndRestore(),this.removeElementsFromDOM(),this.nsInstance.delete(this)}}class c{static ensureInstance(e,t,i,s){var r;return e||(e=new u(t,i,s)),e.setText(i).setImgSrc((r=e.getImgSrc())!=null?r:s)}static createShowFunction(e,t){return i=>(t=c.ensureInstance(t,e,i),e.instances.set(t.getId(),t),t.moveTo(document.body),h.createContextualApiObject(t))}static createProgressFunction(e,t){return(...i)=>(t=c.ensureInstance(t,e,""),t.moveTo(document.body),(async()=>{for(const[s,[r,m]]of i.entries())t.setText(m),await r;t.delete()})(),h.createContextualApiObject(t))}static createWhileFunction(e,t){return i=>(t=c.ensureInstance(t,e,""),{show(s){return e.instances.set(t.getId(),t),t.moveTo(document.body),t.setText(s),i.finally(()=>t.delete()),h.createContextualApiObject(t)}})}}const f=class{constructor(n){var e;this.debug=(n==null?void 0:n.debug)===void 0?f.DEBUG:n.spinner,this.imgSrc=n==null?void 0:n.imgSrc,this.spinner=(n==null?void 0:n.spinner)===void 0?f.SPINNER_DEFAULT_VISIBILITY:n.spinner,this.fontSize=(e=n==null?void 0:n.fontSize)!=null?e:"18px",this.instances=new Map}setImgSrc(n){return this.imgSrc=n,this}showSpinner(n){return this.spinner=n,this}setFontSize(n){return this.fontSize=n,this}getImgSrc(){return this.imgSrc}spinnerIsVisible(){return this.spinner}getFontSize(){return this.fontSize}show(n){return c.createShowFunction(this,new u(this,n,this.imgSrc))(n)}progress(...n){return c.createProgressFunction(this,new u(this,"",this.imgSrc))(...n)}while(n){return c.createWhileFunction(this,new u(this,"",this.imgSrc))(n)}lifoIterate(n){const e=this.instances.size,t=Array.from(this.instances.values());for(let i=e-1;i>=0;i--){const s=t[i],r=s.getId();if(!n(r,s,i))break}}delete(n){this.instances.delete(n.getId())}hideAll(){this.instances.forEach(n=>n.delete())}hide(n){try{if(n){const e=typeof n=="string",t=n instanceof Node,i=s=>{Array.from(this.instances.values()).filter(r=>r.getDestination()===s).forEach(r=>r.delete())};if(e){const s=this.instances.get(n);if(s){s.delete();return}else{const r=g(n);throw r&&i(r),new d(`The CSS selector (${n}) points to a non-existing DOM element.`)}}else if(t)i(n);else throw new S("The ref argument must be either a string or Node",n)}else{const e=this.instances.size;this.lifoIterate((t,i,s)=>{const r=s===e-1;return r&&i.delete(),r})}}catch(e){this.debug&&console.warn(e)}}getFromDestinationNode(n){const e=t=>t.getDestination()===n;return Array.from(this.instances.values()).filter(e)}};let l=f;l.APP_NAME="Nanosplash",l.SPINNER_DEFAULT_VISIBILITY=!0,l.DEBUG=!0,window.addEventListener("load",()=>{window.Nanosplash=l,window.ns=new l})})();
package/docs/style.css DELETED
@@ -1 +0,0 @@
1
- .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}}
@@ -1 +0,0 @@
1
- TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -1,22 +0,0 @@
1
- :root {
2
- --light-code-background: #F5F5F5;
3
- --dark-code-background: #1E1E1E;
4
- }
5
-
6
- @media (prefers-color-scheme: light) { :root {
7
- --code-background: var(--light-code-background);
8
- } }
9
-
10
- @media (prefers-color-scheme: dark) { :root {
11
- --code-background: var(--dark-code-background);
12
- } }
13
-
14
- body.light {
15
- --code-background: var(--light-code-background);
16
- }
17
-
18
- body.dark {
19
- --code-background: var(--dark-code-background);
20
- }
21
-
22
- pre, code { background: var(--code-background); }