nanosplash 2.2.3 → 2.3.1
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 +17 -14
- 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 +245 -329
- package/docs/index.html +54 -430
- 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/index.html +1 -1
- package/index.html +51 -412
- 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 -55
- package/src/style.sass +51 -61
- package/src/types.d.ts +45 -200
- package/src/utilities/dom.spec.ts +70 -0
- package/src/utilities/dom.ts +17 -256
- 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/docs/typedoc/modules/types.html +0 -1
- package/src/Nanosplash.ts +0 -482
- package/src/exceptions/Exception.ts +0 -12
- package/src/exceptions/IllegalArgumentException.ts +0 -9
- package/src/exceptions/InvalidDestinationException.ts +0 -9
- package/src/exceptions/MissingResourceException.ts +0 -9
- package/update-latest.sh +0 -21
|
@@ -1,369 +1,285 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
29
|
+
const mk = (tag) => document.createElement(tag);
|
|
30
|
+
function addClass(node, ...classes) {
|
|
31
|
+
node.classList.add(...classes);
|
|
19
32
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
super(message);
|
|
23
|
-
}
|
|
33
|
+
function setAttr(node, attribute, value) {
|
|
34
|
+
node.setAttribute(attribute, value);
|
|
24
35
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
this.
|
|
204
|
-
|
|
205
|
-
|
|
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);
|
|
214
|
-
}
|
|
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
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
display(this.splashElement, false);
|
|
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);
|
|
243
139
|
}
|
|
244
|
-
return this;
|
|
245
140
|
}
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
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
|
-
};
|
|
141
|
+
moveWithFullscreenStrategy() {
|
|
142
|
+
this.nsRootElement.classList.add("ns-fs");
|
|
143
|
+
move(this.nsRootElement, document.body, true);
|
|
263
144
|
}
|
|
264
|
-
|
|
265
|
-
this.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
this.
|
|
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);
|
|
145
|
+
moveTo(destination) {
|
|
146
|
+
this.cleanup();
|
|
147
|
+
const targetNode = NanosplashRepository.destinationToNode(destination);
|
|
148
|
+
const targetIsBody = targetNode === document.body;
|
|
149
|
+
if (targetIsBody) {
|
|
150
|
+
this.moveWithFullscreenStrategy();
|
|
151
|
+
} else {
|
|
152
|
+
this.resetFullscreenAttributes();
|
|
153
|
+
this.moveWithRegularStrategy(targetNode);
|
|
154
|
+
}
|
|
155
|
+
this.assembleNSComponent();
|
|
288
156
|
}
|
|
289
|
-
|
|
290
|
-
this.
|
|
291
|
-
setStyle(parent, "position", position);
|
|
292
|
-
});
|
|
157
|
+
forEachWrappedNode(callback) {
|
|
158
|
+
Array.from(this.nsWrapperElement.childNodes).forEach(callback);
|
|
293
159
|
}
|
|
294
|
-
|
|
295
|
-
this.
|
|
296
|
-
this.cache.parentPosition = parent.style.position;
|
|
297
|
-
});
|
|
160
|
+
restoreDOMStructure(parentNode) {
|
|
161
|
+
this.forEachWrappedNode((child) => parentNode.insertBefore(child, this.nsRootElement));
|
|
298
162
|
}
|
|
299
|
-
|
|
300
|
-
|
|
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());
|
|
301
172
|
}
|
|
302
|
-
|
|
303
|
-
this.
|
|
304
|
-
this.
|
|
173
|
+
delete() {
|
|
174
|
+
this.cleanup();
|
|
175
|
+
this.removeElementsFromDOM();
|
|
176
|
+
this.nsInstance.delete(this);
|
|
305
177
|
}
|
|
306
|
-
|
|
307
|
-
|
|
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
|
+
};
|
|
308
196
|
}
|
|
309
|
-
|
|
310
|
-
|
|
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
|
+
};
|
|
311
204
|
}
|
|
312
|
-
|
|
313
|
-
|
|
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
|
+
};
|
|
314
218
|
}
|
|
315
|
-
|
|
316
|
-
|
|
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
|
+
};
|
|
317
232
|
}
|
|
318
|
-
|
|
319
|
-
|
|
233
|
+
}
|
|
234
|
+
class Nanosplash {
|
|
235
|
+
constructor() {
|
|
236
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
320
237
|
}
|
|
321
|
-
|
|
322
|
-
this
|
|
323
|
-
display(this.splashElement, true);
|
|
238
|
+
img(src) {
|
|
239
|
+
return NanosplashFactory.createImgFunction(this, new SplashInstance(this, "", src))(src);
|
|
324
240
|
}
|
|
325
|
-
|
|
326
|
-
|
|
241
|
+
show(text) {
|
|
242
|
+
return NanosplashFactory.createShowFunction(this, new SplashInstance(this, text))(text);
|
|
327
243
|
}
|
|
328
|
-
|
|
329
|
-
|
|
244
|
+
progress(...jobs) {
|
|
245
|
+
return NanosplashFactory.createProgressFunction(this, new SplashInstance(this, ""))(...jobs);
|
|
330
246
|
}
|
|
331
|
-
|
|
332
|
-
|
|
247
|
+
while(asyncTask) {
|
|
248
|
+
return NanosplashFactory.createWhileFunction(this, new SplashInstance(this, ""))(asyncTask);
|
|
333
249
|
}
|
|
334
|
-
|
|
335
|
-
|
|
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
|
+
}
|
|
336
258
|
}
|
|
337
|
-
|
|
338
|
-
|
|
259
|
+
delete(splashInstance) {
|
|
260
|
+
this.instances.delete(splashInstance.getId());
|
|
339
261
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const nanosplashFilter = (v) => /\.nanosplash/.test(v.innerText);
|
|
343
|
-
const styleElements = refAll("style").filter(nanosplashFilter);
|
|
344
|
-
const hasRequiredCss = hrefElements.length > 0 || styleElements.length > 0;
|
|
345
|
-
if (!hasRequiredCss) {
|
|
346
|
-
throw new MissingResourceException("Missing the Nanosplash CSS");
|
|
347
|
-
}
|
|
262
|
+
hideAll() {
|
|
263
|
+
this.instances.forEach((instance) => instance.delete());
|
|
348
264
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
destinationNode = destination();
|
|
358
|
-
} else if (isElement) {
|
|
359
|
-
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
|
+
}
|
|
360
273
|
} else {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
274
|
+
this.fifoIterate((_, splashInstance, i) => {
|
|
275
|
+
const remove = i === 0;
|
|
276
|
+
if (remove) {
|
|
277
|
+
splashInstance.delete();
|
|
278
|
+
}
|
|
279
|
+
return remove;
|
|
280
|
+
});
|
|
365
281
|
}
|
|
366
|
-
return destinationNode;
|
|
367
282
|
}
|
|
368
283
|
}
|
|
284
|
+
Nanosplash.APP_NAME = "Nanosplash";
|
|
369
285
|
export { Nanosplash };
|