nanosplash 2.2.4 → 2.3.2

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 (53) hide show
  1. package/.github/workflows/production.yml +57 -0
  2. package/.github/workflows/release.yml +61 -0
  3. package/README.md +17 -15
  4. package/dist/iife/nanosplash.iife.js +1 -1
  5. package/dist/module/Nanosplash.css +1 -0
  6. package/dist/module/manifest.json +6 -3
  7. package/dist/module/nanosplash.cjs.js +1 -1
  8. package/dist/module/nanosplash.es.js +244 -330
  9. package/docs/index.html +54 -430
  10. package/docs/nanosplash.iife.js +1 -1
  11. package/docs/style.css +1 -1
  12. package/docs/typedoc/assets/highlight.css +1 -50
  13. package/docs/typedoc/assets/main.js +2 -2
  14. package/docs/typedoc/assets/search.js +1 -1
  15. package/docs/typedoc/assets/style.css +32 -2
  16. package/docs/typedoc/classes/Core_Nanosplash.Nanosplash.html +1 -0
  17. package/docs/typedoc/index.html +1 -1
  18. package/docs/typedoc/modules/Core_Nanosplash.html +1 -0
  19. package/docs/typedoc/modules/types.html +1 -1
  20. package/index.html +51 -412
  21. package/jest.config.ts +194 -0
  22. package/package.json +70 -65
  23. package/src/Core/Nanosplash.ts +74 -0
  24. package/src/Core/SplashInstance.ts +154 -0
  25. package/src/Factory/NanosplashFactory.ts +73 -0
  26. package/src/Interfaces/ContextualAPIInterface.ts +8 -0
  27. package/src/Interfaces/IdentityInterface.ts +3 -0
  28. package/src/Interfaces/ImageInterface.ts +5 -0
  29. package/src/Interfaces/InsideInterface.ts +5 -0
  30. package/src/Interfaces/NanosplashInterface.ts +4 -0
  31. package/src/Interfaces/ProgressInterface.ts +5 -0
  32. package/src/Interfaces/ShowInterface.ts +5 -0
  33. package/src/Interfaces/WhileInterface.ts +5 -0
  34. package/src/main.ts +2 -6
  35. package/src/repositories/NanosplashRepository.ts +34 -55
  36. package/src/style.sass +51 -61
  37. package/src/types.d.ts +45 -200
  38. package/src/utilities/dom.spec.ts +70 -0
  39. package/src/utilities/dom.ts +17 -256
  40. package/update-all.sh +3 -0
  41. package/vite.iife.config.js +46 -18
  42. package/vite.mod.config.js +48 -12
  43. package/vite.site.config.js +0 -3
  44. package/dist/module/style.css +0 -1
  45. package/docs/typedoc/classes/Nanosplash.Nanosplash-1.html +0 -56
  46. package/docs/typedoc/classes/types.Nanosplash.html +0 -56
  47. package/docs/typedoc/modules/Nanosplash.html +0 -1
  48. package/src/Exceptions/Exception.ts +0 -12
  49. package/src/Exceptions/IllegalArgumentException.ts +0 -9
  50. package/src/Exceptions/InvalidDestinationException.ts +0 -9
  51. package/src/Exceptions/MissingResourceException.ts +0 -9
  52. package/src/Nanosplash.ts +0 -484
  53. package/update-latest.sh +0 -21
@@ -1,371 +1,285 @@
1
- class Exception extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = this.constructor.name;
5
- }
6
- getName() {
7
- return this.constructor.name;
8
- }
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);
9
23
  }
10
- class IllegalArgumentException extends Exception {
11
- constructor(message) {
12
- super(message);
24
+ function move(source, destination, asFirstChild = false) {
25
+ if (source && destination) {
26
+ destination.hasChildNodes() && asFirstChild ? destination.insertBefore(source, destination.firstChild) : destination.appendChild(source);
13
27
  }
14
28
  }
15
- class InvalidDestinationException extends Exception {
16
- constructor(message) {
17
- super(message);
18
- }
29
+ const mk = (tag) => document.createElement(tag);
30
+ function addClass(node, ...classes) {
31
+ node.classList.add(...classes);
19
32
  }
20
- class MissingResourceException extends Exception {
21
- constructor(message) {
22
- super(message);
23
- }
33
+ function setAttr(node, attribute, value) {
34
+ node.setAttribute(attribute, value);
24
35
  }
25
- const ref = (cssSelector) => document.querySelector(cssSelector);
26
- const refAll = (cssSelector) => Array.from(document.querySelectorAll(cssSelector));
27
- const create = (tag, options) => {
28
- var _a;
29
- const element = document.createElement(tag);
30
- if (options) {
31
- element.id || (element.id = options.id + "");
32
- element.className || (element.className = options.className + "");
33
- (_a = options.attributes) == null ? void 0 : _a.filter((v) => v.value).forEach(({ key, value }) => setAttribute(element, key, value));
34
- if (options.content) {
35
- if (typeof options.content === "string") {
36
- element.innerText = options.content;
37
- } else {
38
- element.append(options.content);
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}`);
39
42
  }
43
+ return element;
44
+ } else if (destination instanceof Node) {
45
+ return destination;
40
46
  }
47
+ throw new Error("Destination argument must string or Node");
48
+ }
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;
63
+ }
64
+ });
41
65
  }
42
- return element;
43
- };
44
- const display = (node, show) => {
45
- node.hidden = !show;
46
- if (show) {
47
- removeAttribute(node, "hidden");
48
- } else {
49
- setAttribute(node, "hidden", "true");
66
+ }
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);
84
+ }
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");
92
+ }
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;
50
109
  }
51
- };
52
- const move = (node) => ({
53
- to: (targetNode, asFirstChild) => {
54
- const children = Array.from(targetNode.childNodes);
55
- const noChildren = children.length < 1;
56
- if (noChildren || !asFirstChild) {
57
- targetNode.appendChild(node);
58
- return;
59
- }
60
- const firstChild = children[0];
61
- targetNode.insertBefore(node, firstChild);
62
- }
63
- });
64
- const fitToParent = (node) => {
65
- const parent = node.parentNode;
66
- if (parent) {
67
- ((domRect) => {
68
- const unit = "px";
69
- const parentIsBody = parent === document.body;
70
- let left, top, width, height;
71
- if (parentIsBody) {
72
- left = scrollX + unit;
73
- } else {
74
- left = 0 + unit;
75
- }
76
- if (parentIsBody) {
77
- top = scrollY + unit;
78
- } else {
79
- top = 0 + unit;
80
- }
81
- if (parentIsBody) {
82
- width = "100%";
83
- } else {
84
- width = domRect.width + unit;
85
- }
86
- if (parentIsBody) {
87
- height = "100vh";
88
- } else {
89
- height = domRect.height + unit;
90
- }
91
- setStyle(node, "left", left);
92
- setStyle(node, "top", top);
93
- setStyle(node, "width", width);
94
- setStyle(node, "height", height);
95
- })(parent.getBoundingClientRect());
110
+ setText(text) {
111
+ this.nsTextElement.innerText = text;
112
+ return this;
96
113
  }
97
- };
98
- const invokeOn = (dispatcher, handler, events) => (([addEventListenerLegacy, addEventListener]) => {
99
- events.forEach((event) => {
100
- if (addEventListenerLegacy) {
101
- addEventListenerLegacy(`on${event}`, handler);
102
- } else {
103
- addEventListener(event, handler, true);
104
- }
105
- });
106
- })([dispatcher.attachEvent, dispatcher.addEventListener]);
107
- const isElementOrNode = (value) => {
108
- return value instanceof Element || value instanceof Node;
109
- };
110
- const isFunction = (value) => {
111
- return value && {}.toString.call(value) === "[object Function]";
112
- };
113
- const setStyle = (node, prop, value) => {
114
- node.style[prop] = value;
115
- };
116
- const setAttribute = (node, key, value) => {
117
- node.setAttribute(key, value);
118
- };
119
- const removeAttribute = (node, key) => {
120
- node.removeAttribute(key);
121
- };
122
- class NanosplashRepository {
123
- static makeMainElement() {
124
- const mainElement = create("div", {
125
- className: "nanosplash-container",
126
- attributes: [
127
- {
128
- key: "data-splash-animation",
129
- value: this.DEFAULT.SPLASH_ANIMATION
130
- }
131
- ]
132
- });
133
- mainElement.style.backgroundColor = this.DEFAULT.BACKGROUND_COLOR;
134
- return mainElement;
135
- }
136
- static makeSplashElement() {
137
- const splashElement = create("img", {
138
- className: "nanosplash-img",
139
- attributes: [
140
- { key: "src", value: null },
141
- { key: "alt", value: "Nanosplash indicator" }
142
- ]
143
- });
144
- return splashElement;
114
+ getImgSrc() {
115
+ return this.imgSrc;
145
116
  }
146
- static makeTextElement() {
147
- return create("div", {
148
- className: "nanosplash-text",
149
- content: this.DEFAULT.TEXT
150
- });
117
+ setImgSrc(src) {
118
+ this.nsImageElement.src = src != null ? src : "";
119
+ this.nsImageElement.style.display = src ? "block" : "none";
120
+ this.assembleElementStructure();
121
+ return this;
151
122
  }
152
- }
153
- NanosplashRepository.DEFAULT = {
154
- DESTINATION_NODE: document.body,
155
- TEXT: "Loading ...",
156
- TEXT_FONT: '"Arial", sans-serif',
157
- TEXT_WEIGHT: "medium",
158
- TEXT_COLOR: "#555",
159
- TEXT_SIZE: "26px",
160
- SPLASH_WIDTH: "100px",
161
- SPLASH_HEIGHT: "auto",
162
- SPLASH_ANIMATION: "pulse",
163
- BACKGROUND_COLOR: "rgba(255, 255, 255, 0.90)",
164
- BACKGROUND_BLUR: "light"
165
- };
166
- var style = "";
167
- class Nanosplash {
168
- constructor(config) {
169
- var _a, _b, _c, _d, _e;
170
- this.cache = {
171
- parentPosition: ""
172
- };
173
- this.defaultText = (_b = (_a = config == null ? void 0 : config.default) == null ? void 0 : _a.text) != null ? _b : NanosplashRepository.DEFAULT.TEXT;
174
- this.defaultDestination = Nanosplash.getDestinationElement((_d = (_c = config == null ? void 0 : config.default) == null ? void 0 : _c.destination) != null ? _d : NanosplashRepository.DEFAULT.DESTINATION_NODE);
175
- this.mainElement = NanosplashRepository.makeMainElement();
176
- this.splashElement = NanosplashRepository.makeSplashElement();
177
- this.textElement = NanosplashRepository.makeTextElement();
178
- this.setDefaultStyles();
179
- const splashSrc = (_e = config == null ? void 0 : config.splash) == null ? void 0 : _e.src;
180
- if (splashSrc) {
181
- this.setSplashSource(splashSrc);
182
- move(this.splashElement).to(this.mainElement);
183
- }
184
- move(this.textElement).to(this.mainElement);
185
- move(this.mainElement).to(this.defaultDestination, true);
186
- display(this.mainElement, false);
187
- fitToParent(this.mainElement);
188
- if (config) {
189
- this.configure(config);
123
+ cleanup() {
124
+ const currentParent = this.nsRootElement.parentElement;
125
+ if (currentParent) {
126
+ this.restoreDOMStructure(currentParent);
190
127
  }
191
128
  }
192
- install() {
193
- Object.defineProperty(window, "loading", {
194
- value: this,
195
- writable: false
196
- });
197
- invokeOn(window, () => fitToParent(this.mainElement), ["resize", "scroll"]);
198
- Nanosplash.checkStyleResources();
129
+ resetFullscreenAttributes() {
130
+ setAttr(this.nsRootElement, "style", "");
131
+ this.nsRootElement.classList.remove("ns-fs");
199
132
  }
200
- configure(config) {
201
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
202
- if ((_a = config == null ? void 0 : config.default) == null ? void 0 : _a.destination) {
203
- this.defaultDestination = Nanosplash.getDestinationElement(config.default.destination);
204
- }
205
- this.defaultText || (this.defaultText = (_b = config.default) == null ? void 0 : _b.text);
206
- if ((_c = config.text) == null ? void 0 : _c.family) {
207
- this.setTextFontFamily(config.text.family);
208
- }
209
- if ((_d = config.text) == null ? void 0 : _d.weight) {
210
- this.setTextWeight(config.text.weight);
211
- }
212
- if ((_e = config.text) == null ? void 0 : _e.color) {
213
- this.setTextColor(config.text.color);
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);
214
139
  }
215
- if ((_f = config.text) == null ? void 0 : _f.size) {
216
- this.setTextSize(config.text.size);
217
- }
218
- if ((_g = config.background) == null ? void 0 : _g.color) {
219
- this.setBackgroundColor(config.background.color);
220
- }
221
- if ((_h = config.background) == null ? void 0 : _h.blur) {
222
- this.setBackgroundBlur(config.background.blur);
223
- }
224
- if (config.splash) {
225
- if ((_i = config.splash) == null ? void 0 : _i.src) {
226
- const hasSplashElement = this.mainElement.contains(this.splashElement);
227
- if (!hasSplashElement) {
228
- move(this.splashElement).to(this.mainElement, true);
229
- }
230
- this.setSplashSource(config.splash.src);
231
- }
232
- if ((_j = config.splash) == null ? void 0 : _j.width) {
233
- this.setSplashWidth(config.splash.width);
234
- }
235
- if ((_k = config.splash) == null ? void 0 : _k.height) {
236
- this.setSplashHeight(config.splash.height);
237
- }
238
- if ((_l = config.splash) == null ? void 0 : _l.animation) {
239
- this.setSplashAnimation(config.splash.animation);
240
- }
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();
241
151
  } else {
242
- display(this.splashElement, false);
152
+ this.resetFullscreenAttributes();
153
+ this.moveWithRegularStrategy(targetNode);
243
154
  }
244
- return this;
155
+ this.assembleNSComponent();
245
156
  }
246
- show(text) {
247
- this.setText(text != null ? text : NanosplashRepository.DEFAULT.TEXT);
248
- display(this.mainElement, true);
249
- const during = (task) => {
250
- return task.finally(() => this.hide());
251
- };
252
- return {
253
- inside: (destination) => {
254
- this.restoreParentPosition();
255
- const element = Nanosplash.getDestinationElement(destination);
256
- move(this.mainElement).to(element, true);
257
- fitToParent(this.mainElement);
258
- this.setParentPositionToRelative();
259
- return { during };
260
- },
261
- during
262
- };
157
+ forEachWrappedNode(callback) {
158
+ Array.from(this.nsWrapperElement.childNodes).forEach(callback);
263
159
  }
264
- hide() {
265
- this.restoreParentPosition();
266
- display(this.mainElement, false);
267
- this.setText(this.defaultText);
268
- move(this.mainElement).to(this.defaultDestination, true);
269
- fitToParent(this.mainElement);
270
- }
271
- setDefaultStyles() {
272
- this.setTextFontFamily(NanosplashRepository.DEFAULT.TEXT_FONT);
273
- this.setTextWeight(NanosplashRepository.DEFAULT.TEXT_WEIGHT);
274
- this.setTextColor(NanosplashRepository.DEFAULT.TEXT_COLOR);
275
- this.setTextSize(NanosplashRepository.DEFAULT.TEXT_SIZE);
276
- this.setSplashWidth(NanosplashRepository.DEFAULT.SPLASH_WIDTH);
277
- this.setSplashHeight(NanosplashRepository.DEFAULT.SPLASH_HEIGHT);
278
- this.setSplashAnimation(NanosplashRepository.DEFAULT.SPLASH_ANIMATION);
279
- this.setBackgroundColor(NanosplashRepository.DEFAULT.BACKGROUND_COLOR);
280
- this.setBackgroundBlur(NanosplashRepository.DEFAULT.BACKGROUND_BLUR);
281
- }
282
- doIfParentExist(callback) {
283
- ((parent) => {
284
- if (parent) {
285
- callback(parent);
286
- }
287
- })(this.mainElement.parentElement);
160
+ restoreDOMStructure(parentNode) {
161
+ this.forEachWrappedNode((child) => parentNode.insertBefore(child, this.nsRootElement));
288
162
  }
289
- setParentPosition(position) {
290
- this.doIfParentExist((parent) => {
291
- setStyle(parent, "position", position);
292
- });
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());
293
172
  }
294
- cacheParentPosition() {
295
- this.doIfParentExist((parent) => {
296
- this.cache.parentPosition = parent.style.position;
297
- });
298
- }
299
- restoreParentPosition() {
300
- this.setParentPosition(this.cache.parentPosition);
173
+ delete() {
174
+ this.cleanup();
175
+ this.removeElementsFromDOM();
176
+ this.nsInstance.delete(this);
301
177
  }
302
- setParentPositionToRelative() {
303
- this.cacheParentPosition();
304
- this.setParentPosition("relative");
178
+ }
179
+ class NanosplashFactory {
180
+ static ensureInstance(splash, ns, text, imgSrc) {
181
+ var _a;
182
+ if (!splash) {
183
+ splash = new SplashInstance(ns, text, imgSrc);
184
+ }
185
+ return splash.setText(text).setImgSrc((_a = splash.getImgSrc()) != null ? _a : imgSrc);
186
+ }
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
+ };
305
196
  }
306
- setText(text) {
307
- this.textElement.innerText = text;
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
+ };
308
204
  }
309
- setTextFontFamily(fontFamily) {
310
- setStyle(this.textElement, "fontFamily", fontFamily);
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
+ };
311
218
  }
312
- setTextWeight(fontWeight) {
313
- setStyle(this.textElement, "fontWeight", fontWeight);
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
+ };
314
232
  }
315
- setTextColor(color) {
316
- setStyle(this.textElement, "color", color);
233
+ }
234
+ class Nanosplash {
235
+ constructor() {
236
+ this.instances = /* @__PURE__ */ new Map();
317
237
  }
318
- setTextSize(fontSize) {
319
- setStyle(this.textElement, "fontSize", fontSize);
238
+ img(src) {
239
+ return NanosplashFactory.createImgFunction(this, new SplashInstance(this, "", src))(src);
320
240
  }
321
- setSplashSource(src) {
322
- this.splashElement.src = src;
323
- display(this.splashElement, true);
241
+ show(text) {
242
+ return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text);
324
243
  }
325
- setSplashWidth(width) {
326
- setStyle(this.splashElement, "width", width);
244
+ progress(...jobs) {
245
+ return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ""))(...jobs);
327
246
  }
328
- setSplashHeight(height) {
329
- setStyle(this.splashElement, "height", height);
247
+ while(asyncTask) {
248
+ return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ""))(asyncTask);
330
249
  }
331
- setSplashAnimation(animation) {
332
- setAttribute(this.mainElement, "data-splash-animation", animation);
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
+ }
333
258
  }
334
- setBackgroundColor(color) {
335
- setStyle(this.mainElement, "backgroundColor", color);
259
+ delete(splashInstance) {
260
+ this.instances.delete(splashInstance.getId());
336
261
  }
337
- setBackgroundBlur(blurMode) {
338
- setAttribute(this.mainElement, "data-blur", blurMode);
262
+ hideAll() {
263
+ this.instances.forEach((instance) => instance.delete());
339
264
  }
340
- static checkStyleResources() {
341
- window.addEventListener("load", async function() {
342
- const hrefElements = refAll('link[href*="nanosplash"]');
343
- const nanosplashFilter = (v) => /\.nanosplash/.test(v.innerText);
344
- const styleElements = refAll("style").filter(nanosplashFilter);
345
- const hasRequiredCss = hrefElements.length > 0 || styleElements.length > 0;
346
- if (!hasRequiredCss) {
347
- throw new MissingResourceException("Missing the Nanosplash CSS");
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}`);
348
272
  }
349
- });
350
- }
351
- static getDestinationElement(destination) {
352
- const isString = typeof destination === "string";
353
- const isCallback = isFunction(destination);
354
- const isElement = isElementOrNode(destination);
355
- let destinationNode;
356
- if (isString) {
357
- destinationNode = ref(destination);
358
- } else if (isCallback) {
359
- destinationNode = destination();
360
- } else if (isElement) {
361
- destinationNode = destination;
362
273
  } else {
363
- throw new IllegalArgumentException();
364
- }
365
- if (!destinationNode) {
366
- throw new InvalidDestinationException("Destination element is falsy");
274
+ this.fifoIterate((_, splashInstance, i) => {
275
+ const remove = i === 0;
276
+ if (remove) {
277
+ splashInstance.delete();
278
+ }
279
+ return remove;
280
+ });
367
281
  }
368
- return destinationNode;
369
282
  }
370
283
  }
284
+ Nanosplash.APP_NAME = "Nanosplash";
371
285
  export { Nanosplash };