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
|
@@ -1,321 +1,285 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var style = "";
|
|
21
|
+
function get(selector) {
|
|
22
|
+
return document.querySelector(selector);
|
|
8
23
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
24
|
+
function move(source, destination, asFirstChild = false) {
|
|
25
|
+
if (source && destination) {
|
|
26
|
+
destination.hasChildNodes() && asFirstChild ? destination.insertBefore(source, destination.firstChild) : destination.appendChild(source);
|
|
12
27
|
}
|
|
13
28
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const mk = (tag) => document.createElement(tag);
|
|
30
|
+
function addClass(node, ...classes) {
|
|
31
|
+
node.classList.add(...classes);
|
|
32
|
+
}
|
|
33
|
+
function setAttr(node, attribute, value) {
|
|
34
|
+
node.setAttribute(attribute, value);
|
|
35
|
+
}
|
|
36
|
+
class NanosplashRepository {
|
|
37
|
+
static destinationToNode(destination) {
|
|
38
|
+
if (typeof destination === "string") {
|
|
39
|
+
const element = get(destination);
|
|
40
|
+
if (!element) {
|
|
41
|
+
throw new Error(`No match with ${destination}`);
|
|
27
42
|
}
|
|
43
|
+
return element;
|
|
44
|
+
} else if (destination instanceof Node) {
|
|
45
|
+
return destination;
|
|
28
46
|
}
|
|
47
|
+
throw new Error("Destination argument must string or Node");
|
|
29
48
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (noChildren || !asFirstChild) {
|
|
45
|
-
targetNode.appendChild(node);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const firstChild = children[0];
|
|
49
|
-
targetNode.insertBefore(node, firstChild);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const fitToParent = (node) => {
|
|
53
|
-
const parent = node.parentNode;
|
|
54
|
-
if (parent) {
|
|
55
|
-
((domRect) => {
|
|
56
|
-
parent.style.position = "relative";
|
|
57
|
-
const unit = "px";
|
|
58
|
-
const parentIsBody = parent === document.body;
|
|
59
|
-
let left, top, width, height;
|
|
60
|
-
if (parentIsBody) {
|
|
61
|
-
left = scrollX + unit;
|
|
62
|
-
} else {
|
|
63
|
-
left = 0 + unit;
|
|
64
|
-
}
|
|
65
|
-
if (parentIsBody) {
|
|
66
|
-
top = scrollY + unit;
|
|
67
|
-
} else {
|
|
68
|
-
top = 0 + unit;
|
|
69
|
-
}
|
|
70
|
-
if (parentIsBody) {
|
|
71
|
-
width = "100%";
|
|
72
|
-
} else {
|
|
73
|
-
width = domRect.width + unit;
|
|
74
|
-
}
|
|
75
|
-
if (parentIsBody) {
|
|
76
|
-
height = "100vh";
|
|
77
|
-
} else {
|
|
78
|
-
height = domRect.height + unit;
|
|
49
|
+
static createContextualApiObject(splash) {
|
|
50
|
+
const ctx = {
|
|
51
|
+
getId: () => splash.getId(),
|
|
52
|
+
remove: () => splash.delete(),
|
|
53
|
+
moveTo: (selector) => splash.moveTo(selector),
|
|
54
|
+
getText: () => splash.getText(),
|
|
55
|
+
setText: (text) => splash.setText(text),
|
|
56
|
+
getImgSrc: () => splash.getImgSrc(),
|
|
57
|
+
setImgSrc: (src) => splash.setImgSrc(src)
|
|
58
|
+
};
|
|
59
|
+
return __spreadProps(__spreadValues({}, ctx), {
|
|
60
|
+
inside: (selector) => {
|
|
61
|
+
splash.moveTo(selector);
|
|
62
|
+
return ctx;
|
|
79
63
|
}
|
|
80
|
-
setStyle(parent, "position", "relative");
|
|
81
|
-
setStyle(node, "left", left);
|
|
82
|
-
setStyle(node, "top", top);
|
|
83
|
-
setStyle(node, "width", width);
|
|
84
|
-
setStyle(node, "height", height);
|
|
85
|
-
})(parent.getBoundingClientRect());
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const invokeOn = (dispatcher, handler, events) => (([addEventListenerLegacy, addEventListener]) => {
|
|
89
|
-
events.forEach((event) => {
|
|
90
|
-
if (addEventListenerLegacy) {
|
|
91
|
-
addEventListenerLegacy(`on${event}`, handler);
|
|
92
|
-
} else {
|
|
93
|
-
addEventListener(event, handler, true);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
})([dispatcher.attachEvent, dispatcher.addEventListener]);
|
|
97
|
-
const isElementOrNode = (value) => {
|
|
98
|
-
return value instanceof Element || value instanceof Node;
|
|
99
|
-
};
|
|
100
|
-
const isFunction = (value) => {
|
|
101
|
-
return value && {}.toString.call(value) === "[object Function]";
|
|
102
|
-
};
|
|
103
|
-
const setStyle = (node, prop, value) => {
|
|
104
|
-
node.style[prop] = value;
|
|
105
|
-
};
|
|
106
|
-
const setAttribute = (node, key, value) => {
|
|
107
|
-
node.setAttribute(key, value);
|
|
108
|
-
};
|
|
109
|
-
const removeAttribute = (node, key) => {
|
|
110
|
-
node.removeAttribute(key);
|
|
111
|
-
};
|
|
112
|
-
class NanosplashRepository {
|
|
113
|
-
static makeMainElement() {
|
|
114
|
-
const mainElement = create("div", {
|
|
115
|
-
className: "nanosplash-container",
|
|
116
|
-
attributes: [
|
|
117
|
-
{
|
|
118
|
-
key: "data-splash-animation",
|
|
119
|
-
value: this.DEFAULT.SPLASH_ANIMATION
|
|
120
|
-
}
|
|
121
|
-
]
|
|
122
|
-
});
|
|
123
|
-
mainElement.style.backgroundColor = this.DEFAULT.BACKGROUND_COLOR;
|
|
124
|
-
return mainElement;
|
|
125
|
-
}
|
|
126
|
-
static makeSplashElement() {
|
|
127
|
-
const splashElement = create("img", {
|
|
128
|
-
className: "nanosplash-img",
|
|
129
|
-
attributes: [
|
|
130
|
-
{ key: "src", value: this.DEFAULT.SPLASH_SOURCE },
|
|
131
|
-
{ key: "alt", value: "Nanosplash indicator" }
|
|
132
|
-
]
|
|
133
|
-
});
|
|
134
|
-
display(splashElement, false);
|
|
135
|
-
return splashElement;
|
|
136
|
-
}
|
|
137
|
-
static makeTextElement() {
|
|
138
|
-
return create("div", {
|
|
139
|
-
className: "nanosplash-text",
|
|
140
|
-
content: this.DEFAULT.TEXT
|
|
141
64
|
});
|
|
142
65
|
}
|
|
143
66
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.cache = {
|
|
162
|
-
parentPosition: ""
|
|
163
|
-
};
|
|
164
|
-
this.defaultText = NanosplashRepository.DEFAULT.TEXT;
|
|
165
|
-
this.defaultDestination = NanosplashRepository.DEFAULT.DESTINATION_NODE;
|
|
166
|
-
this.mainElement = NanosplashRepository.makeMainElement();
|
|
167
|
-
this.splashElement = NanosplashRepository.makeSplashElement();
|
|
168
|
-
this.textElement = NanosplashRepository.makeTextElement();
|
|
169
|
-
move(this.splashElement).to(this.mainElement);
|
|
170
|
-
move(this.textElement).to(this.mainElement);
|
|
171
|
-
move(this.mainElement).to(this.defaultDestination, true);
|
|
172
|
-
display(this.mainElement, false);
|
|
173
|
-
fitToParent(this.mainElement);
|
|
174
|
-
this.setDefaultStyles();
|
|
175
|
-
if (config) {
|
|
176
|
-
this.configure(config);
|
|
177
|
-
}
|
|
67
|
+
class SplashInstance {
|
|
68
|
+
constructor(ns, text, imgSrc) {
|
|
69
|
+
var _a;
|
|
70
|
+
this.nsRootElement = mk("div");
|
|
71
|
+
this.nsWrapperElement = mk("div");
|
|
72
|
+
this.nsWindowElement = mk("div");
|
|
73
|
+
this.nsContentElement = mk("div");
|
|
74
|
+
this.nsImageElement = mk("img");
|
|
75
|
+
this.nsTextElement = mk("div");
|
|
76
|
+
this.id = Math.random().toString(36).substring(2);
|
|
77
|
+
this.nsInstance = ns;
|
|
78
|
+
this.nsTextElement.innerText = text;
|
|
79
|
+
this.imgSrc = imgSrc;
|
|
80
|
+
this.nsImageElement.src = (_a = this.imgSrc) != null ? _a : "";
|
|
81
|
+
this.nsImageElement.alt = Nanosplash.APP_NAME;
|
|
82
|
+
this.assembleNSComponent();
|
|
83
|
+
this.setImgSrc(imgSrc);
|
|
178
84
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
85
|
+
assignCSSClasses() {
|
|
86
|
+
addClass(this.nsContentElement, "ns-container");
|
|
87
|
+
addClass(this.nsWrapperElement, "ns-blur");
|
|
88
|
+
addClass(this.nsImageElement, "ns-img");
|
|
89
|
+
addClass(this.nsTextElement, "ns-text");
|
|
90
|
+
addClass(this.nsWindowElement, "ns", "ns-window");
|
|
91
|
+
addClass(this.nsRootElement, "ns-wrapper");
|
|
185
92
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
93
|
+
assembleElementStructure() {
|
|
94
|
+
this.nsContentElement.append(this.nsImageElement, this.nsTextElement);
|
|
95
|
+
this.nsWindowElement.append(this.nsContentElement);
|
|
96
|
+
this.nsRootElement.append(this.nsWrapperElement, this.nsWindowElement);
|
|
97
|
+
}
|
|
98
|
+
assembleNSComponent() {
|
|
99
|
+
this.nsRootElement.id = this.getId();
|
|
100
|
+
setAttr(this.nsRootElement, "data-ctx", "nanosplash");
|
|
101
|
+
this.assembleElementStructure();
|
|
102
|
+
this.assignCSSClasses();
|
|
103
|
+
}
|
|
104
|
+
getId() {
|
|
105
|
+
return this.id;
|
|
106
|
+
}
|
|
107
|
+
getText() {
|
|
108
|
+
return this.nsTextElement.innerText;
|
|
109
|
+
}
|
|
110
|
+
setText(text) {
|
|
111
|
+
this.nsTextElement.innerText = text;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
getImgSrc() {
|
|
115
|
+
return this.imgSrc;
|
|
116
|
+
}
|
|
117
|
+
setImgSrc(src) {
|
|
118
|
+
this.nsImageElement.src = src != null ? src : "";
|
|
119
|
+
this.nsImageElement.style.display = src ? "block" : "none";
|
|
120
|
+
this.assembleElementStructure();
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
cleanup() {
|
|
124
|
+
const currentParent = this.nsRootElement.parentElement;
|
|
125
|
+
if (currentParent) {
|
|
126
|
+
this.restoreDOMStructure(currentParent);
|
|
206
127
|
}
|
|
207
|
-
|
|
208
|
-
|
|
128
|
+
}
|
|
129
|
+
resetFullscreenAttributes() {
|
|
130
|
+
setAttr(this.nsRootElement, "style", "");
|
|
131
|
+
this.nsRootElement.classList.remove("ns-fs");
|
|
132
|
+
}
|
|
133
|
+
moveWithRegularStrategy(targetNode) {
|
|
134
|
+
const targetParentNode = targetNode.parentNode;
|
|
135
|
+
if (targetParentNode) {
|
|
136
|
+
this.restoreDOMStructure(targetParentNode);
|
|
137
|
+
targetParentNode.replaceChild(this.nsRootElement, targetNode);
|
|
138
|
+
this.nsWrapperElement.appendChild(targetNode);
|
|
209
139
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.setSplashAnimation(config.splash.animation);
|
|
222
|
-
}
|
|
140
|
+
}
|
|
141
|
+
moveWithFullscreenStrategy() {
|
|
142
|
+
this.nsRootElement.classList.add("ns-fs");
|
|
143
|
+
move(this.nsRootElement, document.body, true);
|
|
144
|
+
}
|
|
145
|
+
moveTo(destination) {
|
|
146
|
+
this.cleanup();
|
|
147
|
+
const targetNode = NanosplashRepository.destinationToNode(destination);
|
|
148
|
+
const targetIsBody = targetNode === document.body;
|
|
149
|
+
if (targetIsBody) {
|
|
150
|
+
this.moveWithFullscreenStrategy();
|
|
223
151
|
} else {
|
|
224
|
-
|
|
152
|
+
this.resetFullscreenAttributes();
|
|
153
|
+
this.moveWithRegularStrategy(targetNode);
|
|
225
154
|
}
|
|
226
|
-
|
|
155
|
+
this.assembleNSComponent();
|
|
227
156
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
157
|
+
forEachWrappedNode(callback) {
|
|
158
|
+
Array.from(this.nsWrapperElement.childNodes).forEach(callback);
|
|
159
|
+
}
|
|
160
|
+
restoreDOMStructure(parentNode) {
|
|
161
|
+
this.forEachWrappedNode((child) => parentNode.insertBefore(child, this.nsRootElement));
|
|
162
|
+
}
|
|
163
|
+
removeElementsFromDOM() {
|
|
164
|
+
[
|
|
165
|
+
this.nsTextElement,
|
|
166
|
+
this.nsImageElement,
|
|
167
|
+
this.nsContentElement,
|
|
168
|
+
this.nsWrapperElement,
|
|
169
|
+
this.nsWindowElement,
|
|
170
|
+
this.nsRootElement
|
|
171
|
+
].forEach((v) => v.remove());
|
|
172
|
+
}
|
|
173
|
+
delete() {
|
|
174
|
+
this.cleanup();
|
|
175
|
+
this.removeElementsFromDOM();
|
|
176
|
+
this.nsInstance.delete(this);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
class NanosplashFactory {
|
|
180
|
+
static ensureInstance(splash, ns, text, imgSrc) {
|
|
181
|
+
var _a;
|
|
182
|
+
if (!splash) {
|
|
183
|
+
splash = new SplashInstance(ns, text, imgSrc);
|
|
234
184
|
}
|
|
235
|
-
|
|
236
|
-
await task;
|
|
237
|
-
this.hide();
|
|
238
|
-
};
|
|
239
|
-
return {
|
|
240
|
-
inside: (destination) => {
|
|
241
|
-
const element = Nanosplash.getDestinationElement(destination);
|
|
242
|
-
move(this.mainElement).to(element, true);
|
|
243
|
-
this.cache.parentPosition = element.style.position;
|
|
244
|
-
fitToParent(this.mainElement);
|
|
245
|
-
return { during };
|
|
246
|
-
},
|
|
247
|
-
during
|
|
248
|
-
};
|
|
185
|
+
return splash.setText(text).setImgSrc((_a = splash.getImgSrc()) != null ? _a : imgSrc);
|
|
249
186
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.setTextFontFamily(NanosplashRepository.DEFAULT.TEXT_FONT);
|
|
260
|
-
this.setTextWeight(NanosplashRepository.DEFAULT.TEXT_WEIGHT);
|
|
261
|
-
this.setTextColor(NanosplashRepository.DEFAULT.TEXT_COLOR);
|
|
262
|
-
this.setTextSize(NanosplashRepository.DEFAULT.TEXT_SIZE);
|
|
263
|
-
this.setSplashSource(NanosplashRepository.DEFAULT.SPLASH_SOURCE);
|
|
264
|
-
this.setSplashWidth(NanosplashRepository.DEFAULT.SPLASH_WIDTH);
|
|
265
|
-
this.setSplashHeight(NanosplashRepository.DEFAULT.SPLASH_HEIGHT);
|
|
266
|
-
this.setSplashAnimation(NanosplashRepository.DEFAULT.SPLASH_ANIMATION);
|
|
267
|
-
this.setBackgroundColor(NanosplashRepository.DEFAULT.BACKGROUND_COLOR);
|
|
268
|
-
this.setBackgroundBlur(NanosplashRepository.DEFAULT.BACKGROUND_BLUR);
|
|
187
|
+
static createImgFunction(ns, splash) {
|
|
188
|
+
return (src) => {
|
|
189
|
+
splash = NanosplashFactory.ensureInstance(splash, ns, "", src);
|
|
190
|
+
return {
|
|
191
|
+
show: NanosplashFactory.createShowFunction(ns, splash),
|
|
192
|
+
progress: NanosplashFactory.createProgressFunction(ns, splash),
|
|
193
|
+
while: NanosplashFactory.createWhileFunction(ns, splash)
|
|
194
|
+
};
|
|
195
|
+
};
|
|
269
196
|
}
|
|
270
|
-
|
|
271
|
-
|
|
197
|
+
static createShowFunction(ns, splash) {
|
|
198
|
+
return (text) => {
|
|
199
|
+
splash = NanosplashFactory.ensureInstance(splash, ns, text);
|
|
200
|
+
ns.instances.set(splash.getId(), splash);
|
|
201
|
+
splash.moveTo(document.body);
|
|
202
|
+
return NanosplashRepository.createContextualApiObject(splash);
|
|
203
|
+
};
|
|
272
204
|
}
|
|
273
|
-
|
|
274
|
-
|
|
205
|
+
static createProgressFunction(ns, splash) {
|
|
206
|
+
return (...jobs) => {
|
|
207
|
+
splash = NanosplashFactory.ensureInstance(splash, ns, "");
|
|
208
|
+
splash.moveTo(document.body);
|
|
209
|
+
(async () => {
|
|
210
|
+
for (const [_, [job, text]] of jobs.entries()) {
|
|
211
|
+
splash.setText(text);
|
|
212
|
+
await job;
|
|
213
|
+
}
|
|
214
|
+
splash.delete();
|
|
215
|
+
})();
|
|
216
|
+
return NanosplashRepository.createContextualApiObject(splash);
|
|
217
|
+
};
|
|
275
218
|
}
|
|
276
|
-
|
|
277
|
-
|
|
219
|
+
static createWhileFunction(ns, splash) {
|
|
220
|
+
return (asyncTask) => {
|
|
221
|
+
splash = NanosplashFactory.ensureInstance(splash, ns, "");
|
|
222
|
+
return {
|
|
223
|
+
show(text) {
|
|
224
|
+
ns.instances.set(splash.getId(), splash);
|
|
225
|
+
splash.moveTo(document.body);
|
|
226
|
+
splash.setText(text);
|
|
227
|
+
asyncTask.finally(() => splash.delete());
|
|
228
|
+
return NanosplashRepository.createContextualApiObject(splash);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
};
|
|
278
232
|
}
|
|
279
|
-
|
|
280
|
-
|
|
233
|
+
}
|
|
234
|
+
class Nanosplash {
|
|
235
|
+
constructor() {
|
|
236
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
281
237
|
}
|
|
282
|
-
|
|
283
|
-
|
|
238
|
+
img(src) {
|
|
239
|
+
return NanosplashFactory.createImgFunction(this, new SplashInstance(this, "", src))(src);
|
|
284
240
|
}
|
|
285
|
-
|
|
286
|
-
this
|
|
287
|
-
display(this.splashElement, true);
|
|
241
|
+
show(text) {
|
|
242
|
+
return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text);
|
|
288
243
|
}
|
|
289
|
-
|
|
290
|
-
|
|
244
|
+
progress(...jobs) {
|
|
245
|
+
return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ""))(...jobs);
|
|
291
246
|
}
|
|
292
|
-
|
|
293
|
-
|
|
247
|
+
while(asyncTask) {
|
|
248
|
+
return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ""))(asyncTask);
|
|
294
249
|
}
|
|
295
|
-
|
|
296
|
-
|
|
250
|
+
fifoIterate(callback) {
|
|
251
|
+
let i = 0;
|
|
252
|
+
const instanceEntries = this.instances.entries();
|
|
253
|
+
for (const [id, splashInstance] of instanceEntries) {
|
|
254
|
+
if (!callback(id, splashInstance, i++)) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
297
258
|
}
|
|
298
|
-
|
|
299
|
-
|
|
259
|
+
delete(splashInstance) {
|
|
260
|
+
this.instances.delete(splashInstance.getId());
|
|
300
261
|
}
|
|
301
|
-
|
|
302
|
-
|
|
262
|
+
hideAll() {
|
|
263
|
+
this.instances.forEach((instance) => instance.delete());
|
|
303
264
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
destinationNode = destination();
|
|
313
|
-
} else if (isElement) {
|
|
314
|
-
destinationNode = destination;
|
|
265
|
+
hide(id) {
|
|
266
|
+
if (id) {
|
|
267
|
+
const splashInstance = this.instances.get(id);
|
|
268
|
+
if (splashInstance) {
|
|
269
|
+
splashInstance.delete();
|
|
270
|
+
} else {
|
|
271
|
+
throw new Error(`Could not find element with id: ${id}`);
|
|
272
|
+
}
|
|
315
273
|
} else {
|
|
316
|
-
|
|
274
|
+
this.fifoIterate((_, splashInstance, i) => {
|
|
275
|
+
const remove = i === 0;
|
|
276
|
+
if (remove) {
|
|
277
|
+
splashInstance.delete();
|
|
278
|
+
}
|
|
279
|
+
return remove;
|
|
280
|
+
});
|
|
317
281
|
}
|
|
318
|
-
return destinationNode;
|
|
319
282
|
}
|
|
320
283
|
}
|
|
284
|
+
Nanosplash.APP_NAME = "Nanosplash";
|
|
321
285
|
export { Nanosplash };
|