cradova 1.3.0 → 1.4.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/LICENSE +0 -0
- package/README.md +32 -79
- package/dist/index.d.ts +122 -191
- package/dist/index.js +568 -918
- package/dist/types.ts +38 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,398 +1,155 @@
|
|
|
1
|
-
// lib/scripts/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.persist = true;
|
|
8
|
-
this.rendered = false;
|
|
9
|
-
this.pushed = false;
|
|
10
|
-
this.effects = [];
|
|
11
|
-
const { template, name, transition, persist } = cradova_screen_initials;
|
|
12
|
-
if (typeof template !== "function") {
|
|
13
|
-
throw new Error(
|
|
14
|
-
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
this.html = template.bind(this);
|
|
18
|
-
this.name = name;
|
|
19
|
-
this.template.id = "cradova-screen-set";
|
|
20
|
-
this.transition = transition;
|
|
21
|
-
if (typeof persist === "boolean") {
|
|
22
|
-
this.persist = persist;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
effect(fn) {
|
|
26
|
-
if (!this.rendered && !this.pushed) {
|
|
27
|
-
this.effects.push(
|
|
28
|
-
new Promise(async (res, rej) => {
|
|
29
|
-
try {
|
|
30
|
-
res(await fn());
|
|
31
|
-
} catch (error) {
|
|
32
|
-
rej(error);
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async effector() {
|
|
39
|
-
if (this.rendered) {
|
|
40
|
-
await Promise.allSettled(this.effects);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async updateState(data) {
|
|
44
|
-
if (this.rendered) {
|
|
45
|
-
await this.Activate(data, true);
|
|
1
|
+
// lib/scripts/track.ts
|
|
2
|
+
function cradovaDispatchTrack(nodes, state) {
|
|
3
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
4
|
+
const element = nodes[i];
|
|
5
|
+
if (!element) {
|
|
6
|
+
continue;
|
|
46
7
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (this.transition) {
|
|
59
|
-
fuc.classList.add("CRADOVA-UI-" + this.transition);
|
|
8
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
9
|
+
for (const key in state) {
|
|
10
|
+
if (key === "style") {
|
|
11
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
12
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
13
|
+
element.style[k] = v;
|
|
14
|
+
} else {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
60
19
|
}
|
|
61
|
-
|
|
20
|
+
continue;
|
|
62
21
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw new Error(
|
|
67
|
-
" \u2718 Cradova err: no screen is rendered, may have been past wrongly, try ()=> screen; in cradova Router.route(name, screen)"
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
if (this.secondaryChildren.length) {
|
|
71
|
-
this.template.append(this.secondaryChildren);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
onActivate(cb) {
|
|
75
|
-
this.callBack = cb;
|
|
76
|
-
}
|
|
77
|
-
addChild(...addOns) {
|
|
78
|
-
for (let i = 0; i < addOns.length; i++) {
|
|
79
|
-
if (addOns[i] && addOns[i] instanceof HTMLElement) {
|
|
80
|
-
this.secondaryChildren.push(addOns[i]);
|
|
81
|
-
}
|
|
82
|
-
if (addOns[i] && typeof addOns[i] === "function") {
|
|
83
|
-
let a = addOns[i]();
|
|
84
|
-
if (a && a instanceof HTMLElement) {
|
|
85
|
-
this.secondaryChildren.push(a);
|
|
22
|
+
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
23
|
+
element.style[key] = state[key];
|
|
24
|
+
continue;
|
|
86
25
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
26
|
+
if (typeof element[key] === "function") {
|
|
27
|
+
element[key](element);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (key === "text") {
|
|
31
|
+
element.innerText = state[key];
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (key === "fullscreen") {
|
|
35
|
+
if (state[key]) {
|
|
36
|
+
fullScreen(element).set();
|
|
37
|
+
} else {
|
|
38
|
+
fullScreen(element).exist();
|
|
91
39
|
}
|
|
40
|
+
continue;
|
|
92
41
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async Activate(data, force) {
|
|
102
|
-
if (!this.persist) {
|
|
103
|
-
await this.package(data);
|
|
104
|
-
this.packed = true;
|
|
105
|
-
} else {
|
|
106
|
-
if (!this.packed) {
|
|
107
|
-
await this.package(data);
|
|
108
|
-
this.packed = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (this.persist && force) {
|
|
112
|
-
await this.package(data);
|
|
113
|
-
this.packed = true;
|
|
114
|
-
this.rendered = false;
|
|
115
|
-
}
|
|
116
|
-
if (!this.pushed) {
|
|
117
|
-
this.pushed = true;
|
|
118
|
-
}
|
|
119
|
-
document.title = this.name;
|
|
120
|
-
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
121
|
-
if (!doc) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root [data-cra-id=cradova-app-wrapper]"
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
doc?.replaceChildren(this.template);
|
|
127
|
-
if (!this.persist) {
|
|
128
|
-
this.packed = false;
|
|
129
|
-
}
|
|
130
|
-
if (this.effects.length) {
|
|
131
|
-
await this.effector();
|
|
132
|
-
this.rendered = true;
|
|
133
|
-
}
|
|
134
|
-
if (doc?.firstChild?.firstChild?.afterMount) {
|
|
135
|
-
const c = doc?.firstChild;
|
|
136
|
-
c?.firstChild.afterMount();
|
|
137
|
-
}
|
|
138
|
-
if (this.callBack) {
|
|
139
|
-
await this.callBack(data);
|
|
140
|
-
}
|
|
141
|
-
window.scrollTo(0, 0);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
Screen.SCALE_IN = "SCALE-IN";
|
|
145
|
-
Screen.SCALE_OUT = "SCALE-OUT";
|
|
146
|
-
Screen.CIRCLE_IN = "CIRCLE-IN";
|
|
147
|
-
Screen.CIRCLE_OUT = "CIRCLE-OUT";
|
|
148
|
-
Screen.FADE_OUT = "FADE-OUT";
|
|
149
|
-
Screen.FADE_IN = "FADE-IN";
|
|
150
|
-
Screen.SLIDE_UP = "SLIDE-UP";
|
|
151
|
-
Screen.SLIDE_DOWN = "SLIDE-DOWN";
|
|
152
|
-
Screen.SLIDE_LEFT = "SLIDE-LEFT";
|
|
153
|
-
Screen.SLIDE_RIGHT = "SLIDE-RIGHT";
|
|
154
|
-
|
|
155
|
-
// lib/scripts/Scaffold.ts
|
|
156
|
-
var Scaffold = class {
|
|
157
|
-
constructor() {
|
|
158
|
-
this.history = [];
|
|
159
|
-
this.Scaffolds = {};
|
|
160
|
-
}
|
|
161
|
-
async push(label, data, force) {
|
|
162
|
-
if (this.Scaffolds[label]) {
|
|
163
|
-
if (this.history.length) {
|
|
164
|
-
this.Scaffolds[this.history[this.history.length - 1]].deActivate();
|
|
165
|
-
}
|
|
166
|
-
if (data) {
|
|
167
|
-
await this.Scaffolds[label].Activate(data, force);
|
|
168
|
-
} else {
|
|
169
|
-
await this.Scaffolds[label].Activate();
|
|
170
|
-
}
|
|
171
|
-
this.history.push(label);
|
|
172
|
-
} else {
|
|
173
|
-
throw new Error(
|
|
174
|
-
"\u2718 Cradova err : no Scaffold labeled " + label + " provided!"
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async pop(data, force) {
|
|
179
|
-
if (!this.history.length || this.history.length === 1) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
this.Scaffolds[this.history[this.history.length - 1]].deActivate();
|
|
183
|
-
this.history.pop();
|
|
184
|
-
await this.Scaffolds[this.history[this.history.length - 1]].Activate(
|
|
185
|
-
data,
|
|
186
|
-
force
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
async addScaffolds(scaffolds) {
|
|
190
|
-
let i = 0, lab = "";
|
|
191
|
-
for (const label in scaffolds) {
|
|
192
|
-
const scaffold = scaffolds[label];
|
|
193
|
-
if (scaffold.template) {
|
|
194
|
-
this.Scaffolds[label] = scaffold;
|
|
195
|
-
} else {
|
|
196
|
-
console.error("\u2718 Cradova got", scaffold);
|
|
197
|
-
throw new Error(
|
|
198
|
-
"\u2718 Cradova err : Scaffold of label '" + label + "' didn't receive a invalid Scaffold component type"
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
if (i === 0) {
|
|
202
|
-
lab = label;
|
|
203
|
-
}
|
|
204
|
-
i++;
|
|
205
|
-
}
|
|
206
|
-
if (lab) {
|
|
207
|
-
await this.push(lab);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
throw new Error("\u2718 Cradova err : no Scaffold given!");
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// lib/scripts/Router.ts
|
|
215
|
-
var Router = {};
|
|
216
|
-
var RouterBox = {};
|
|
217
|
-
RouterBox["lastNavigatedRouteController"] = null;
|
|
218
|
-
RouterBox["nextRouteController"] = null;
|
|
219
|
-
RouterBox["lastNavigatedRoute"] = null;
|
|
220
|
-
RouterBox["pageShow"] = null;
|
|
221
|
-
RouterBox["pageHide"] = null;
|
|
222
|
-
RouterBox["params"] = {};
|
|
223
|
-
RouterBox["routes"] = {};
|
|
224
|
-
var checker = (url) => {
|
|
225
|
-
if (RouterBox.routes[url]) {
|
|
226
|
-
return [RouterBox.routes[url], null];
|
|
227
|
-
}
|
|
228
|
-
for (const path in RouterBox.routes) {
|
|
229
|
-
if (!path.includes(":")) {
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
const urlFixtures = url.split("/");
|
|
233
|
-
const pathFixtures = path.split("/");
|
|
234
|
-
if (pathFixtures.length === urlFixtures.length) {
|
|
235
|
-
urlFixtures.shift();
|
|
236
|
-
pathFixtures.shift();
|
|
237
|
-
let isIt = true;
|
|
238
|
-
const routesParams = {};
|
|
239
|
-
for (let i = 0; i < pathFixtures.length; i++) {
|
|
240
|
-
if (!pathFixtures[i].includes(":") && path.includes(urlFixtures[i] + "/") && pathFixtures.indexOf(urlFixtures[i]) === pathFixtures.lastIndexOf(urlFixtures[i])) {
|
|
241
|
-
if (!isIt)
|
|
242
|
-
isIt = true;
|
|
243
|
-
} else {
|
|
244
|
-
if (pathFixtures[i].includes(":")) {
|
|
245
|
-
continue;
|
|
42
|
+
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
43
|
+
const classes = state[key].split(" ");
|
|
44
|
+
for (let i2 = 0; i2 < classes.length; i2++) {
|
|
45
|
+
if (classes[i2]) {
|
|
46
|
+
element.classList.add(classes[i2]);
|
|
47
|
+
}
|
|
246
48
|
}
|
|
247
|
-
|
|
49
|
+
continue;
|
|
248
50
|
}
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
);
|
|
51
|
+
if (key === "toggleclass" && state[key] !== "") {
|
|
52
|
+
element.classList.toggle(state[key]);
|
|
53
|
+
continue;
|
|
253
54
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
55
|
+
if (key === "removeclass" && state[key] !== "") {
|
|
56
|
+
element.classList.remove(state[key]);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (key === "remove") {
|
|
60
|
+
if (element.parentElement) {
|
|
61
|
+
element.parentElement?.removeChild(element);
|
|
62
|
+
} else {
|
|
63
|
+
element.remove();
|
|
259
64
|
}
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (key.includes("$")) {
|
|
68
|
+
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (key === "tree") {
|
|
72
|
+
if (typeof state[key] === "function") {
|
|
73
|
+
state[key] = state[key]();
|
|
74
|
+
} else {
|
|
75
|
+
throw new TypeError(
|
|
76
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (typeof state[key] === "function") {
|
|
80
|
+
state[key] = state[key]();
|
|
81
|
+
}
|
|
82
|
+
if (Array.isArray(state[key])) {
|
|
83
|
+
throw new TypeError(
|
|
84
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (!(state[key] instanceof HTMLElement)) {
|
|
88
|
+
console.error(
|
|
89
|
+
" \u2718 Cradova err: wrong element type: can't update tree using " + state[key]
|
|
90
|
+
);
|
|
91
|
+
throw new TypeError(
|
|
92
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
element.innerHTML = "";
|
|
96
|
+
element.appendChild(state[key]);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
if (typeof element[key] !== "undefined") {
|
|
101
|
+
element[key] = state[key];
|
|
102
|
+
} else {
|
|
103
|
+
element[key] = state[key];
|
|
104
|
+
if (key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
105
|
+
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
110
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
260
111
|
}
|
|
261
|
-
return [RouterBox.routes[path], routesParams];
|
|
262
112
|
}
|
|
113
|
+
} else {
|
|
114
|
+
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
263
115
|
}
|
|
264
116
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
117
|
+
}
|
|
118
|
+
function dispatch(stateID, state) {
|
|
119
|
+
let ele;
|
|
120
|
+
if (stateID instanceof HTMLElement) {
|
|
121
|
+
ele = stateID;
|
|
271
122
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
123
|
+
let updated = void 0;
|
|
124
|
+
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
125
|
+
for (const [id, eachState] of Object.entries(stateID)) {
|
|
126
|
+
const elements = document.querySelectorAll(
|
|
127
|
+
"[data-cra-id=" + id + "]"
|
|
128
|
+
);
|
|
129
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
130
|
+
cradovaDispatchTrack(elements, eachState);
|
|
277
131
|
}
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
Router.navigate = function(href, data = null, force = false) {
|
|
281
|
-
if (typeof href !== "string") {
|
|
282
|
-
throw new TypeError(
|
|
283
|
-
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
if (typeof data === "boolean") {
|
|
287
|
-
force = true;
|
|
288
|
-
data = null;
|
|
289
|
-
}
|
|
290
|
-
let route = null, params, link = null;
|
|
291
|
-
if (href.includes("://")) {
|
|
292
|
-
window.location.href = href;
|
|
293
132
|
} else {
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
[route, params] = checker(href);
|
|
298
|
-
if (route) {
|
|
299
|
-
RouterBox["nextRouteController"] = route;
|
|
300
|
-
RouterBox.params.params = params || null;
|
|
301
|
-
RouterBox.params.data = data || null;
|
|
302
|
-
link = href;
|
|
303
|
-
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
304
|
-
window.history.pushState({}, "", link);
|
|
305
|
-
(async () => {
|
|
306
|
-
await RouterBox.router(null, force);
|
|
307
|
-
})();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
RouterBox.router = async function(e, force = false) {
|
|
312
|
-
let Alink, url, route, params;
|
|
313
|
-
if (e && e.target.tagName) {
|
|
314
|
-
Alink = e.target;
|
|
315
|
-
if (Alink && Alink.href.includes("#")) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (Alink && Alink.href.includes("javascript")) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
e.preventDefault();
|
|
322
|
-
if (Alink) {
|
|
323
|
-
url = new URL(Alink.href).pathname;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (!url) {
|
|
327
|
-
url = window.location.pathname;
|
|
328
|
-
}
|
|
329
|
-
if (url === Router["lastNavigatedRoute"]) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (RouterBox["nextRouteController"]) {
|
|
333
|
-
route = RouterBox["nextRouteController"];
|
|
334
|
-
RouterBox["nextRouteController"] = null;
|
|
335
|
-
params = RouterBox.params.params;
|
|
336
|
-
} else {
|
|
337
|
-
[route, params] = checker(url);
|
|
338
|
-
}
|
|
339
|
-
if (route) {
|
|
340
|
-
RouterBox.params.event = e;
|
|
341
|
-
RouterBox.params.params = params || null;
|
|
342
|
-
RouterBox.params.data = RouterBox.params.data || null;
|
|
343
|
-
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
|
|
344
|
-
await route.controller(RouterBox.params, force);
|
|
345
|
-
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
346
|
-
RouterBox["lastNavigatedRoute"] = url;
|
|
347
|
-
RouterBox["lastNavigatedRouteController"] = route;
|
|
348
|
-
Array.from(window.document.querySelectorAll("a")).forEach((a) => {
|
|
349
|
-
a.addEventListener("click", (e2) => {
|
|
350
|
-
e2.preventDefault();
|
|
351
|
-
Router.navigate(a.pathname);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
} else {
|
|
355
|
-
if (RouterBox.routes["/404"]) {
|
|
356
|
-
RouterBox.routes["/404"].controller(RouterBox.params);
|
|
357
|
-
} else {
|
|
358
|
-
console.error(
|
|
359
|
-
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
133
|
+
if (typeof stateID === "string") {
|
|
134
|
+
const elements = document.querySelectorAll(
|
|
135
|
+
"[data-cra-id=" + stateID + "]"
|
|
360
136
|
);
|
|
137
|
+
if (elements.length) {
|
|
138
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
139
|
+
if (!state?.cradovaDispatchTrackBreak) {
|
|
140
|
+
cradovaDispatchTrack(elements, state);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (ele) {
|
|
145
|
+
cradovaDispatchTrack([ele], state);
|
|
361
146
|
}
|
|
362
147
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (typeof callback === "function") {
|
|
366
|
-
RouterBox["pageShow"] = callback;
|
|
367
|
-
} else {
|
|
368
|
-
throw new Error(
|
|
369
|
-
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
Router["onPageHide"] = function(callback) {
|
|
374
|
-
if (typeof callback === "function") {
|
|
375
|
-
RouterBox["pageHide"] = callback;
|
|
376
|
-
} else {
|
|
377
|
-
throw new Error(
|
|
378
|
-
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
Router.packageScreen = async function(path, data) {
|
|
383
|
-
if (!RouterBox.routes[path]) {
|
|
384
|
-
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
385
|
-
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
386
|
-
}
|
|
387
|
-
await RouterBox.routes[path].packager(data);
|
|
388
|
-
};
|
|
389
|
-
window.addEventListener("pageshow", RouterBox.router);
|
|
390
|
-
window.addEventListener("popstate", (e) => {
|
|
391
|
-
e.preventDefault();
|
|
392
|
-
RouterBox.router(e);
|
|
393
|
-
});
|
|
148
|
+
return updated;
|
|
149
|
+
}
|
|
394
150
|
|
|
395
151
|
// lib/scripts/fns.ts
|
|
152
|
+
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
396
153
|
var err = function(errors, err2, type) {
|
|
397
154
|
for (let er = 0; er < errors.length; er++) {
|
|
398
155
|
console.error(" \u2718 Cradova err: ", errors[er]);
|
|
@@ -403,46 +160,6 @@ var err = function(errors, err2, type) {
|
|
|
403
160
|
throw new TypeError(" \u2718 Cradova err: " + err2);
|
|
404
161
|
}
|
|
405
162
|
};
|
|
406
|
-
var controls = function() {
|
|
407
|
-
const svg = `<svg width="20" height="20" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
408
|
-
<path d="M4.49975 5.625C4.3402 5.6242 4.18282 5.58788 4.03904 5.5187C3.89526 5.44951 3.76869 5.34919 3.6685 5.225L1.03725 2.0375C0.8835 1.84561 0.786745 1.61438 0.758014 1.37017C0.729283 1.12596 0.769733 0.878589 0.874753 0.65625C0.959928 0.463017 1.09892 0.298383 1.27514 0.182014C1.45136 0.0656449 1.65734 0.00245816 1.8685 0H7.131C7.34216 0.00245816 7.54815 0.0656449 7.72437 0.182014C7.90058 0.298383 8.03958 0.463017 8.12475 0.65625C8.22977 0.878589 8.27023 1.12596 8.24149 1.37017C8.21276 1.61438 8.11601 1.84561 7.96226 2.0375L5.331 5.225C5.23082 5.34919 5.10424 5.44951 4.96047 5.5187C4.81669 5.58788 4.65931 5.6242 4.49975 5.625Z" fill="#2c3e50"/>
|
|
409
|
-
</svg>
|
|
410
|
-
`;
|
|
411
|
-
const icon = (styles) => lib_default("div", { ...styles, innerHTML: svg });
|
|
412
|
-
const constr = lib_default(
|
|
413
|
-
"div",
|
|
414
|
-
{
|
|
415
|
-
display: "flex",
|
|
416
|
-
position: "fixed",
|
|
417
|
-
alignContent: "center",
|
|
418
|
-
justifyContent: "space-around",
|
|
419
|
-
flexDirection: "row",
|
|
420
|
-
width: "80px",
|
|
421
|
-
top: "4px",
|
|
422
|
-
right: "4px",
|
|
423
|
-
backgroundColor: "#fff",
|
|
424
|
-
transform: "rotate(0deg)",
|
|
425
|
-
border: "aqua 2px solid",
|
|
426
|
-
borderRadius: "6px"
|
|
427
|
-
},
|
|
428
|
-
icon({
|
|
429
|
-
transform: "rotate(90deg)",
|
|
430
|
-
onclick() {
|
|
431
|
-
window.history.back();
|
|
432
|
-
}
|
|
433
|
-
}),
|
|
434
|
-
icon({
|
|
435
|
-
transform: "rotate(270deg)",
|
|
436
|
-
onclick() {
|
|
437
|
-
window.history.forward();
|
|
438
|
-
}
|
|
439
|
-
})
|
|
440
|
-
);
|
|
441
|
-
const cont = constr();
|
|
442
|
-
if (cont) {
|
|
443
|
-
document.body.append(cont);
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
163
|
function uuid() {
|
|
447
164
|
let t = Date.now ? +Date.now() : +new Date();
|
|
448
165
|
return "cradova-id-xxxxxxxxxx".replace(/[x]/g, function(e) {
|
|
@@ -450,53 +167,6 @@ function uuid() {
|
|
|
450
167
|
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
451
168
|
});
|
|
452
169
|
}
|
|
453
|
-
function PromptBeforeLeave(callback) {
|
|
454
|
-
window.history.pushState(
|
|
455
|
-
"forward",
|
|
456
|
-
"",
|
|
457
|
-
window.location.pathname + "#forward"
|
|
458
|
-
);
|
|
459
|
-
window.addEventListener("popstate", (e) => {
|
|
460
|
-
if (callback) {
|
|
461
|
-
callback(e);
|
|
462
|
-
} else {
|
|
463
|
-
alert("Are you sure, you want to go back?");
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
function media(value, ...properties) {
|
|
468
|
-
const styS = "@media only screen and (" + value + `) {
|
|
469
|
-
`, styE = `}
|
|
470
|
-
`;
|
|
471
|
-
let style = " ", aniSty = " ";
|
|
472
|
-
const proplen = properties.length;
|
|
473
|
-
let totalAnimation, Animation = " ";
|
|
474
|
-
const animationStep = (num) => {
|
|
475
|
-
style = " ";
|
|
476
|
-
for (const [k, v] of Object.entries(properties[num][1])) {
|
|
477
|
-
style += "" + k + ": " + v + `;
|
|
478
|
-
`;
|
|
479
|
-
}
|
|
480
|
-
aniSty += "" + properties[num][0] + `{
|
|
481
|
-
` + style + `}
|
|
482
|
-
`;
|
|
483
|
-
return aniSty;
|
|
484
|
-
};
|
|
485
|
-
for (let i = 0; i < proplen; i++) {
|
|
486
|
-
Animation += animationStep(i);
|
|
487
|
-
}
|
|
488
|
-
let aniStyleTag = document.querySelector("style");
|
|
489
|
-
if (aniStyleTag === null) {
|
|
490
|
-
aniStyleTag = document.createElement("style");
|
|
491
|
-
}
|
|
492
|
-
aniStyleTag.media = "screen";
|
|
493
|
-
totalAnimation = aniStyleTag.innerHTML + `
|
|
494
|
-
|
|
495
|
-
`;
|
|
496
|
-
totalAnimation += styS + Animation + styE;
|
|
497
|
-
aniStyleTag.innerHTML = totalAnimation;
|
|
498
|
-
document.head.append(aniStyleTag);
|
|
499
|
-
}
|
|
500
170
|
function css(identifier, properties) {
|
|
501
171
|
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
502
172
|
let styTag = document.querySelector("style");
|
|
@@ -537,82 +207,17 @@ function css(identifier, properties) {
|
|
|
537
207
|
styleTag.innerHTML = totalStyle;
|
|
538
208
|
document.head.append(styleTag);
|
|
539
209
|
}
|
|
540
|
-
function animate(identifier, ...properties) {
|
|
541
|
-
const styS = "@keyframes " + identifier + ` {
|
|
542
|
-
`, styE = `}
|
|
543
|
-
`, proplen = properties.length;
|
|
544
|
-
let style = " ", aniSty = " ", Animation = " ", totalAnimation = null;
|
|
545
|
-
const animationStep = (num) => {
|
|
546
|
-
style = " ";
|
|
547
|
-
for (const [k, v] of Object.entries(properties[num][1])) {
|
|
548
|
-
style += "" + k + ": " + v + `;
|
|
549
|
-
`;
|
|
550
|
-
}
|
|
551
|
-
aniSty += "" + properties[num][0] + `{
|
|
552
|
-
` + style + `}
|
|
553
|
-
`;
|
|
554
|
-
return aniSty;
|
|
555
|
-
};
|
|
556
|
-
for (let i = 0; i < proplen; i++) {
|
|
557
|
-
Animation += animationStep(i);
|
|
558
|
-
}
|
|
559
|
-
let aniStyleTag = document.querySelector("style");
|
|
560
|
-
if (aniStyleTag === null) {
|
|
561
|
-
aniStyleTag = document.createElement("style");
|
|
562
|
-
}
|
|
563
|
-
aniStyleTag.media = "screen";
|
|
564
|
-
totalAnimation = aniStyleTag.innerHTML + `
|
|
565
|
-
|
|
566
|
-
`;
|
|
567
|
-
totalAnimation += styS + Animation + styE;
|
|
568
|
-
aniStyleTag.innerHTML = totalAnimation;
|
|
569
|
-
document.head.append(aniStyleTag);
|
|
570
|
-
}
|
|
571
210
|
function assert(condition, ...callback) {
|
|
572
211
|
if (condition) {
|
|
573
212
|
return callback;
|
|
574
213
|
}
|
|
575
|
-
return "";
|
|
576
|
-
}
|
|
577
|
-
function assertOr(condition, ifTrue, ifFalse) {
|
|
578
|
-
if (condition) {
|
|
579
|
-
return ifTrue;
|
|
580
|
-
}
|
|
581
|
-
return ifFalse;
|
|
582
|
-
}
|
|
583
|
-
function RefElement(element_initials = "div", props = {}, ...other) {
|
|
584
|
-
const stateID = uuid();
|
|
585
|
-
if (typeof props === "object" && !Array.isArray(element_initials[1])) {
|
|
586
|
-
other = props;
|
|
587
|
-
props = { stateID };
|
|
588
|
-
} else {
|
|
589
|
-
props["stateID"] = stateID;
|
|
590
|
-
}
|
|
591
|
-
const element = lib_default(element_initials, props, other);
|
|
592
|
-
return {
|
|
593
|
-
render(data) {
|
|
594
|
-
return element(data);
|
|
595
|
-
},
|
|
596
|
-
r(data) {
|
|
597
|
-
return element(data);
|
|
598
|
-
},
|
|
599
|
-
instance() {
|
|
600
|
-
return dispatch(stateID, {
|
|
601
|
-
cradovaDispatchTrackBreak: true
|
|
602
|
-
});
|
|
603
|
-
},
|
|
604
|
-
i() {
|
|
605
|
-
return dispatch(stateID, {
|
|
606
|
-
cradovaDispatchTrackBreak: true
|
|
607
|
-
});
|
|
608
|
-
},
|
|
609
|
-
updateState(state) {
|
|
610
|
-
dispatch(stateID, state);
|
|
611
|
-
},
|
|
612
|
-
u(state) {
|
|
613
|
-
dispatch(stateID, state);
|
|
614
|
-
}
|
|
615
|
-
};
|
|
214
|
+
return "";
|
|
215
|
+
}
|
|
216
|
+
function assertOr(condition, ifTrue, ifFalse) {
|
|
217
|
+
if (condition) {
|
|
218
|
+
return ifTrue;
|
|
219
|
+
}
|
|
220
|
+
return ifFalse;
|
|
616
221
|
}
|
|
617
222
|
var ls = {};
|
|
618
223
|
ls.store = (name, value) => {
|
|
@@ -642,89 +247,15 @@ function fullScreen(e) {
|
|
|
642
247
|
}
|
|
643
248
|
};
|
|
644
249
|
}
|
|
645
|
-
var RefList = class {
|
|
646
|
-
constructor(component) {
|
|
647
|
-
this.stateID = uuid();
|
|
648
|
-
this.parentElement = null;
|
|
649
|
-
this.component = component.bind(this);
|
|
650
|
-
}
|
|
651
|
-
r(d) {
|
|
652
|
-
return this.render(d);
|
|
653
|
-
}
|
|
654
|
-
render(datas = []) {
|
|
655
|
-
if (!Array.isArray(datas)) {
|
|
656
|
-
throw new Error(
|
|
657
|
-
" \u2718 Cradova err: RefList cannot render non-array input"
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
const elements = [];
|
|
661
|
-
const data = datas.length;
|
|
662
|
-
for (let i = 0; i < data; i++) {
|
|
663
|
-
elements.push(this.component(datas[i], i)({ stateID: this.stateID }));
|
|
664
|
-
}
|
|
665
|
-
if (elements.length) {
|
|
666
|
-
return elements;
|
|
667
|
-
}
|
|
668
|
-
return lib_default("div")({ stateID: this.stateID });
|
|
669
|
-
}
|
|
670
|
-
updateState(datas) {
|
|
671
|
-
if (!datas) {
|
|
672
|
-
throw new Error(" \u2718 Cradova err: Ref cannot be rendered without input");
|
|
673
|
-
}
|
|
674
|
-
if (!Array.isArray(datas)) {
|
|
675
|
-
throw new Error(
|
|
676
|
-
" \u2718 Cradova err: RefList cannot render non-array input"
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
if (!datas[0]) {
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
if (!this.parentElement) {
|
|
683
|
-
this.parentElement = dispatch(this.stateID, {
|
|
684
|
-
cradovaDispatchTrackBreak: true
|
|
685
|
-
})?.parentElement;
|
|
686
|
-
}
|
|
687
|
-
if (!this.parentElement) {
|
|
688
|
-
throw new Error(
|
|
689
|
-
"\u2718 Cradova err : cannot update list, the RefList was never rendered!"
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
const elements = [];
|
|
693
|
-
for (let i = 0; i < datas.length; i++) {
|
|
694
|
-
elements.push(this.component(datas[i], i)({ stateID: this.stateID }));
|
|
695
|
-
}
|
|
696
|
-
try {
|
|
697
|
-
this.parentElement.replaceChildren(...elements);
|
|
698
|
-
} catch (err2) {
|
|
699
|
-
console.error(err2);
|
|
700
|
-
throw new Error(" \u2718 Cradova err: an error occured");
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
remove() {
|
|
704
|
-
dispatch(this.stateID, { remove: true });
|
|
705
|
-
}
|
|
706
|
-
instance() {
|
|
707
|
-
return dispatch(this.stateID, {
|
|
708
|
-
cradovaDispatchTrackBreak: true
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
i() {
|
|
712
|
-
return dispatch(this.stateID, {
|
|
713
|
-
cradovaDispatchTrackBreak: true
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
250
|
var Ref = class {
|
|
718
251
|
constructor(component) {
|
|
719
252
|
this.stateID = uuid();
|
|
253
|
+
this.rendered = false;
|
|
254
|
+
this.effects = [];
|
|
255
|
+
this.effectuate = null;
|
|
256
|
+
this.hasFirstStateUpdateRun = false;
|
|
720
257
|
this.component = component.bind(this);
|
|
721
258
|
}
|
|
722
|
-
r(d) {
|
|
723
|
-
return this.render(d);
|
|
724
|
-
}
|
|
725
|
-
u(d) {
|
|
726
|
-
return this.updateState(d);
|
|
727
|
-
}
|
|
728
259
|
render(data) {
|
|
729
260
|
const chtml = this.component(data);
|
|
730
261
|
if (typeof chtml !== "function") {
|
|
@@ -741,25 +272,16 @@ var Ref = class {
|
|
|
741
272
|
|
|
742
273
|
to track and debug this element add a
|
|
743
274
|
beforeMount or afterMount prop to the element
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
element stateID: \x1B[4m \x1B[33m ${this.stateID} \x1B[33m \x1B[4m`
|
|
275
|
+
`
|
|
747
276
|
],
|
|
748
277
|
`Cradova can't render component make sure it's a valid component`
|
|
749
278
|
);
|
|
750
279
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
afterMount();
|
|
757
|
-
};
|
|
758
|
-
} else {
|
|
759
|
-
if (this.upcb) {
|
|
760
|
-
element.afterMount = this.upcb.bind(null, data);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
280
|
+
const av = () => {
|
|
281
|
+
this.effector.apply(this);
|
|
282
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
283
|
+
};
|
|
284
|
+
window.addEventListener("cradova-aftermount", av);
|
|
763
285
|
return () => element;
|
|
764
286
|
}
|
|
765
287
|
instance() {
|
|
@@ -767,59 +289,81 @@ var Ref = class {
|
|
|
767
289
|
cradovaDispatchTrackBreak: true
|
|
768
290
|
});
|
|
769
291
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
292
|
+
effect(fn) {
|
|
293
|
+
if (this.rendered) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
fn = fn.bind(this);
|
|
297
|
+
this.effects.push(
|
|
298
|
+
new Promise(async (res, rej) => {
|
|
299
|
+
try {
|
|
300
|
+
await fn();
|
|
301
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
302
|
+
this.hasFirstStateUpdateRun = true;
|
|
303
|
+
await this.effectuate();
|
|
304
|
+
}
|
|
305
|
+
res(void 0);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
rej(error);
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
);
|
|
774
311
|
}
|
|
775
|
-
|
|
776
|
-
this.
|
|
312
|
+
async effector() {
|
|
313
|
+
await Promise.allSettled(this.effects);
|
|
314
|
+
this.rendered = true;
|
|
315
|
+
this.hasFirstStateUpdateRun = true;
|
|
777
316
|
}
|
|
778
317
|
updateState(data) {
|
|
318
|
+
if (!this.rendered) {
|
|
319
|
+
this.rendered = true;
|
|
320
|
+
async function updateState(data2) {
|
|
321
|
+
if (this.instance()) {
|
|
322
|
+
await this.Activate(data2);
|
|
323
|
+
} else {
|
|
324
|
+
setTimeout(updateState.bind(this, data2), 4);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.effectuate = updateState.bind(this, data);
|
|
328
|
+
} else {
|
|
329
|
+
(async () => {
|
|
330
|
+
await this.Activate(data);
|
|
331
|
+
}).bind(this)();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async Activate(data) {
|
|
779
335
|
if (!data) {
|
|
780
336
|
return;
|
|
781
337
|
}
|
|
782
338
|
if (!this) {
|
|
783
339
|
console.error(
|
|
784
|
-
" \u2718 Cradova err:
|
|
785
|
-
);
|
|
786
|
-
console.error(
|
|
787
|
-
" \u2718 Cradova err: Then call as ref.updateState({ your new data }) = ui state"
|
|
340
|
+
" \u2718 Cradova err: Ref.updateState has is passed out of scope"
|
|
788
341
|
);
|
|
342
|
+
return;
|
|
789
343
|
}
|
|
790
344
|
const guy = dispatch(this.stateID, {
|
|
791
345
|
cradovaDispatchTrackBreak: true
|
|
792
346
|
});
|
|
793
347
|
if (!guy) {
|
|
794
|
-
|
|
795
|
-
" \u2718 Cradova err: Ref is not rendered but updateState was called",
|
|
796
|
-
this.component
|
|
797
|
-
);
|
|
348
|
+
return;
|
|
798
349
|
}
|
|
799
350
|
const chtml = this.component(data);
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
" \u2718 Cradova err: Ref got an invalid datatype for ref updateSate call got >>> ' " + chtml + "';"
|
|
807
|
-
);
|
|
808
|
-
}
|
|
351
|
+
let element;
|
|
352
|
+
if (chtml instanceof HTMLElement) {
|
|
353
|
+
chtml.setAttribute("data-cra-id", this.stateID);
|
|
354
|
+
element = chtml;
|
|
355
|
+
} else {
|
|
356
|
+
element = chtml({ stateID: this.stateID });
|
|
809
357
|
}
|
|
810
|
-
const element = chtml({ stateID: this.stateID });
|
|
811
|
-
const fn = element.afterMount;
|
|
812
|
-
element.afterMount = void 0;
|
|
813
358
|
try {
|
|
814
|
-
guy.
|
|
815
|
-
if (
|
|
816
|
-
|
|
359
|
+
guy.insertAdjacentElement("beforebegin", element);
|
|
360
|
+
if (guy.parentElement) {
|
|
361
|
+
guy.parentElement.removeChild(guy);
|
|
362
|
+
} else {
|
|
363
|
+
guy.remove();
|
|
817
364
|
}
|
|
818
365
|
} catch (e0) {
|
|
819
|
-
console.
|
|
820
|
-
}
|
|
821
|
-
if (this.upcb) {
|
|
822
|
-
this.upcb(data);
|
|
366
|
+
console.error(e0);
|
|
823
367
|
}
|
|
824
368
|
}
|
|
825
369
|
remove() {
|
|
@@ -838,9 +382,7 @@ var frag = function(...children) {
|
|
|
838
382
|
} else {
|
|
839
383
|
if (!(b instanceof HTMLElement)) {
|
|
840
384
|
console.error(" \u2718 Cradova err: wrong element type" + b);
|
|
841
|
-
throw new TypeError(
|
|
842
|
-
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
843
|
-
);
|
|
385
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
844
386
|
}
|
|
845
387
|
}
|
|
846
388
|
} else {
|
|
@@ -849,157 +391,371 @@ var frag = function(...children) {
|
|
|
849
391
|
} else {
|
|
850
392
|
if (!(a instanceof HTMLElement)) {
|
|
851
393
|
console.error(" \u2718 Cradova err: wrong element type" + a);
|
|
852
|
-
throw new TypeError(
|
|
853
|
-
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
854
|
-
);
|
|
394
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
855
395
|
}
|
|
856
396
|
}
|
|
857
397
|
}
|
|
398
|
+
} else {
|
|
399
|
+
console.error(" \u2718 Cradova err: wrong element type" + children[i]);
|
|
400
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
858
401
|
}
|
|
859
402
|
}
|
|
860
403
|
return par;
|
|
861
404
|
};
|
|
862
405
|
|
|
863
|
-
// lib/scripts/
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
406
|
+
// lib/scripts/Screen.ts
|
|
407
|
+
var Screen = class {
|
|
408
|
+
constructor(cradova_screen_initials) {
|
|
409
|
+
this.packed = false;
|
|
410
|
+
this.secondaryChildren = [];
|
|
411
|
+
this.template = document.createElement("div");
|
|
412
|
+
this.persist = true;
|
|
413
|
+
this.rendered = false;
|
|
414
|
+
this.hasFirstStateUpdateRun = false;
|
|
415
|
+
this.effects = [];
|
|
416
|
+
this.effectuate = null;
|
|
417
|
+
const { template, name, transition, persist } = cradova_screen_initials;
|
|
418
|
+
if (typeof template !== "function") {
|
|
419
|
+
throw new Error(
|
|
420
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
421
|
+
);
|
|
869
422
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
423
|
+
this.html = template.bind(this);
|
|
424
|
+
this.name = name;
|
|
425
|
+
this.template.id = "cradova-screen-set";
|
|
426
|
+
this.transition = transition;
|
|
427
|
+
if (typeof persist === "boolean") {
|
|
428
|
+
this.persist = persist;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
effect(fn) {
|
|
432
|
+
if (!this.rendered) {
|
|
433
|
+
this.effects.push(
|
|
434
|
+
new Promise(async (res, rej) => {
|
|
435
|
+
try {
|
|
436
|
+
res(await fn());
|
|
437
|
+
} catch (error) {
|
|
438
|
+
rej(error);
|
|
881
439
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
440
|
+
})
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async effector() {
|
|
445
|
+
this.rendered = true;
|
|
446
|
+
await Promise.allSettled(this.effects);
|
|
447
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
448
|
+
this.hasFirstStateUpdateRun = true;
|
|
449
|
+
await this.effectuate();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
updateState(data) {
|
|
453
|
+
if (!this.rendered) {
|
|
454
|
+
async function updateState(data2) {
|
|
455
|
+
this.data = data2;
|
|
456
|
+
await this.Activate(true);
|
|
457
|
+
}
|
|
458
|
+
this.effectuate = updateState.bind(this, data);
|
|
459
|
+
} else {
|
|
460
|
+
(async () => {
|
|
461
|
+
this.data = data;
|
|
462
|
+
await this.Activate(true);
|
|
463
|
+
}).bind(this)();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async package() {
|
|
467
|
+
if (typeof this.html === "function") {
|
|
468
|
+
let fuc = await this.html(this.data);
|
|
469
|
+
if (typeof fuc === "function") {
|
|
470
|
+
fuc = fuc();
|
|
471
|
+
if (!(fuc instanceof HTMLElement)) {
|
|
472
|
+
throw new Error(
|
|
473
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
474
|
+
);
|
|
475
|
+
} else {
|
|
476
|
+
if (this.transition) {
|
|
477
|
+
this.template.classList.add("CRADOVA-UI-" + this.transition);
|
|
901
478
|
}
|
|
902
|
-
|
|
479
|
+
this.template.innerHTML = "";
|
|
480
|
+
this.template.appendChild(fuc);
|
|
903
481
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (!this.template.firstChild) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
" \u2718 Cradova err: no screen is rendered, may have been past wrongly."
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
if (this.secondaryChildren.length) {
|
|
490
|
+
this.template.append(this.secondaryChildren);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
onActivate(cb) {
|
|
494
|
+
this.callBack = cb;
|
|
495
|
+
}
|
|
496
|
+
addChild(...addOns) {
|
|
497
|
+
this.secondaryChildren.push(frag(...addOns));
|
|
498
|
+
}
|
|
499
|
+
deActivate() {
|
|
500
|
+
if (this.transition) {
|
|
501
|
+
this.template.classList.remove("CRADOVA-UI-" + this.transition);
|
|
502
|
+
}
|
|
503
|
+
if (!this.persist) {
|
|
504
|
+
this.rendered = false;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
async Activate(force) {
|
|
508
|
+
if (!this.persist) {
|
|
509
|
+
await this.package();
|
|
510
|
+
this.packed = true;
|
|
511
|
+
} else {
|
|
512
|
+
if (!this.packed) {
|
|
513
|
+
await this.package();
|
|
514
|
+
this.packed = true;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (this.persist && force) {
|
|
518
|
+
await this.package();
|
|
519
|
+
this.packed = true;
|
|
520
|
+
}
|
|
521
|
+
document.title = this.name;
|
|
522
|
+
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
523
|
+
if (!doc) {
|
|
524
|
+
throw new Error(
|
|
525
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root [data-cra-id=cradova-app-wrapper]"
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
doc.innerHTML = "";
|
|
529
|
+
doc.appendChild(this.template);
|
|
530
|
+
if (!this.persist) {
|
|
531
|
+
this.packed = false;
|
|
532
|
+
}
|
|
533
|
+
if (doc?.firstChild?.firstChild?.afterMount) {
|
|
534
|
+
const c = doc?.firstChild;
|
|
535
|
+
await c?.firstChild.afterMount();
|
|
536
|
+
delete c?.firstChild.afterMount;
|
|
537
|
+
}
|
|
538
|
+
window.dispatchEvent(cradovaAftermountEvent);
|
|
539
|
+
await this.effector();
|
|
540
|
+
if (this.callBack) {
|
|
541
|
+
await this.callBack();
|
|
542
|
+
}
|
|
543
|
+
window.scrollTo(0, 0);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
Screen.SCALE_IN = "SCALE-IN";
|
|
547
|
+
Screen.SCALE_OUT = "SCALE-OUT";
|
|
548
|
+
Screen.CIRCLE_IN = "CIRCLE-IN";
|
|
549
|
+
Screen.CIRCLE_OUT = "CIRCLE-OUT";
|
|
550
|
+
Screen.FADE_OUT = "FADE-OUT";
|
|
551
|
+
Screen.FADE_IN = "FADE-IN";
|
|
552
|
+
Screen.SLIDE_UP = "SLIDE-UP";
|
|
553
|
+
Screen.SLIDE_DOWN = "SLIDE-DOWN";
|
|
554
|
+
Screen.SLIDE_LEFT = "SLIDE-LEFT";
|
|
555
|
+
Screen.SLIDE_RIGHT = "SLIDE-RIGHT";
|
|
556
|
+
|
|
557
|
+
// lib/scripts/Router.ts
|
|
558
|
+
var Router = {};
|
|
559
|
+
var RouterBox = {};
|
|
560
|
+
RouterBox["lastNavigatedRouteController"] = null;
|
|
561
|
+
RouterBox["nextRouteController"] = null;
|
|
562
|
+
RouterBox["lastNavigatedRoute"] = null;
|
|
563
|
+
RouterBox["pageShow"] = null;
|
|
564
|
+
RouterBox["pageHide"] = null;
|
|
565
|
+
RouterBox["errorHandler"] = {};
|
|
566
|
+
RouterBox["params"] = {};
|
|
567
|
+
RouterBox["routes"] = {};
|
|
568
|
+
var checker = (url) => {
|
|
569
|
+
if (RouterBox.routes[url]) {
|
|
570
|
+
return [RouterBox.routes[url], null];
|
|
571
|
+
}
|
|
572
|
+
for (const path in RouterBox.routes) {
|
|
573
|
+
if (!path.includes(":")) {
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const urlFixtures = url.split("/");
|
|
577
|
+
const pathFixtures = path.split("/");
|
|
578
|
+
if (pathFixtures.length === urlFixtures.length) {
|
|
579
|
+
urlFixtures.shift();
|
|
580
|
+
pathFixtures.shift();
|
|
581
|
+
let isIt = true;
|
|
582
|
+
const routesParams = {};
|
|
583
|
+
for (let i = 0; i < pathFixtures.length; i++) {
|
|
584
|
+
if (!pathFixtures[i].includes(":") && path.includes(urlFixtures[i] + "/") && pathFixtures.indexOf(urlFixtures[i]) === pathFixtures.lastIndexOf(urlFixtures[i])) {
|
|
585
|
+
if (!isIt)
|
|
586
|
+
isIt = true;
|
|
587
|
+
} else {
|
|
588
|
+
if (pathFixtures[i].includes(":")) {
|
|
589
|
+
continue;
|
|
910
590
|
}
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
if (key === "toggleclass" && state[key] !== "") {
|
|
914
|
-
element.classList.toggle(state[key]);
|
|
915
|
-
continue;
|
|
916
|
-
}
|
|
917
|
-
if (key === "removeclass" && state[key] !== "") {
|
|
918
|
-
element.classList.remove(state[key]);
|
|
919
|
-
continue;
|
|
920
|
-
}
|
|
921
|
-
if (key === "remove") {
|
|
922
|
-
element.parentElement?.removeChild(element);
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
if (key.includes("$")) {
|
|
926
|
-
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
927
|
-
continue;
|
|
591
|
+
isIt = false;
|
|
928
592
|
}
|
|
929
|
-
if (
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (typeof state[key] === "function") {
|
|
934
|
-
state[key] = state[key]();
|
|
935
|
-
}
|
|
936
|
-
if (Array.isArray(state[key])) {
|
|
937
|
-
throw new TypeError(
|
|
938
|
-
" \u2718 Cradova err: invalid tree element type, should be a single element or parent element from cradova"
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
if (!(state[key] instanceof HTMLElement)) {
|
|
942
|
-
console.error(
|
|
943
|
-
" \u2718 Cradova err: wrong element type: can't update tree using " + state[key]
|
|
944
|
-
);
|
|
945
|
-
throw new TypeError(
|
|
946
|
-
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
947
|
-
);
|
|
948
|
-
}
|
|
949
|
-
element.replaceChildren(state[key]);
|
|
950
|
-
continue;
|
|
593
|
+
if (!(pathFixtures.indexOf(urlFixtures[i]) === pathFixtures.lastIndexOf(urlFixtures[i]))) {
|
|
594
|
+
throw new Error(
|
|
595
|
+
" \u2718 Cradova err: cradova router doesn't allow paths with multiple names"
|
|
596
|
+
);
|
|
951
597
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
if (key !== "afterMount" && key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
958
|
-
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
959
|
-
}
|
|
598
|
+
}
|
|
599
|
+
if (isIt) {
|
|
600
|
+
for (let i = 0; i < pathFixtures.length; i++) {
|
|
601
|
+
if (pathFixtures[i].includes(":")) {
|
|
602
|
+
routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
|
|
960
603
|
}
|
|
961
|
-
} catch (error) {
|
|
962
|
-
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
963
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
964
604
|
}
|
|
605
|
+
routesParams.path = path;
|
|
606
|
+
return [RouterBox.routes[path], routesParams];
|
|
965
607
|
}
|
|
966
|
-
} else {
|
|
967
|
-
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
968
608
|
}
|
|
969
609
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
if (
|
|
974
|
-
|
|
610
|
+
return [];
|
|
611
|
+
};
|
|
612
|
+
Router.route = function(path = "/", screen) {
|
|
613
|
+
if (!screen.Activate && screen.name) {
|
|
614
|
+
console.error(" \u2718 Cradova err: not a valid screen " + screen);
|
|
615
|
+
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
975
616
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
);
|
|
982
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
983
|
-
cradovaDispatchTrack(elements, eachState);
|
|
617
|
+
RouterBox.routes[path] = {
|
|
618
|
+
controller: (params, force) => screen.Activate(params, force),
|
|
619
|
+
packager: async (params) => await screen.package(params),
|
|
620
|
+
deactivate: () => {
|
|
621
|
+
screen.deActivate();
|
|
984
622
|
}
|
|
623
|
+
};
|
|
624
|
+
};
|
|
625
|
+
Router.navigate = function(href, data = null, force = false) {
|
|
626
|
+
if (typeof href !== "string") {
|
|
627
|
+
throw new TypeError(
|
|
628
|
+
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
if (typeof data === "boolean") {
|
|
632
|
+
force = true;
|
|
633
|
+
data = null;
|
|
634
|
+
}
|
|
635
|
+
let route = null, params, link = null;
|
|
636
|
+
if (href.includes("://")) {
|
|
637
|
+
window.location.href = href;
|
|
985
638
|
} else {
|
|
986
|
-
if (
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
639
|
+
if (href === window.location.pathname) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
[route, params] = checker(href);
|
|
643
|
+
if (route) {
|
|
644
|
+
RouterBox["nextRouteController"] = route;
|
|
645
|
+
RouterBox.params.params = params || null;
|
|
646
|
+
RouterBox.params.data = data || null;
|
|
647
|
+
link = href;
|
|
648
|
+
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
649
|
+
window.history.pushState({}, "", link);
|
|
650
|
+
(async () => {
|
|
651
|
+
await RouterBox.router(null, force);
|
|
652
|
+
})();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
RouterBox.router = async function(e, force = false) {
|
|
657
|
+
let url, route, params;
|
|
658
|
+
const Alink = e && e.target.tagName === "A" && e.target;
|
|
659
|
+
if (Alink) {
|
|
660
|
+
if (Alink.href.includes("#")) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (Alink.href.includes("javascript")) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
e.preventDefault();
|
|
667
|
+
url = new URL(Alink.href).pathname;
|
|
668
|
+
}
|
|
669
|
+
if (!url) {
|
|
670
|
+
url = window.location.pathname;
|
|
671
|
+
}
|
|
672
|
+
if (url === Router["lastNavigatedRoute"]) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (RouterBox["nextRouteController"]) {
|
|
676
|
+
route = RouterBox["nextRouteController"];
|
|
677
|
+
RouterBox["nextRouteController"] = null;
|
|
678
|
+
params = RouterBox.params.params;
|
|
679
|
+
RouterBox.params.params = null;
|
|
680
|
+
} else {
|
|
681
|
+
[route, params] = checker(url);
|
|
682
|
+
}
|
|
683
|
+
if (route) {
|
|
684
|
+
try {
|
|
685
|
+
RouterBox.params.event = e;
|
|
686
|
+
RouterBox.params.params = params || RouterBox.params.params || null;
|
|
687
|
+
RouterBox.params.data = RouterBox.params.data || null;
|
|
688
|
+
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
|
|
689
|
+
await route.controller(force);
|
|
690
|
+
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
691
|
+
RouterBox["lastNavigatedRoute"] = url;
|
|
692
|
+
RouterBox["lastNavigatedRouteController"] = route;
|
|
693
|
+
RouterBox.params.params = null;
|
|
694
|
+
} catch (error) {
|
|
695
|
+
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
696
|
+
if (errorHandler) {
|
|
697
|
+
errorHandler(error);
|
|
995
698
|
}
|
|
996
699
|
}
|
|
997
|
-
|
|
998
|
-
|
|
700
|
+
} else {
|
|
701
|
+
if (RouterBox.routes["/404"]) {
|
|
702
|
+
RouterBox.routes["/404"].controller(RouterBox.params);
|
|
703
|
+
} else {
|
|
704
|
+
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
705
|
+
if (errorHandler) {
|
|
706
|
+
errorHandler(
|
|
707
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
708
|
+
);
|
|
709
|
+
} else {
|
|
710
|
+
console.error(
|
|
711
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
712
|
+
);
|
|
713
|
+
}
|
|
999
714
|
}
|
|
1000
715
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
716
|
+
};
|
|
717
|
+
Router["onPageShow"] = function(callback) {
|
|
718
|
+
if (typeof callback === "function") {
|
|
719
|
+
RouterBox["pageShow"] = callback;
|
|
720
|
+
} else {
|
|
721
|
+
throw new Error(
|
|
722
|
+
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
Router["onPageHide"] = function(callback) {
|
|
727
|
+
if (typeof callback === "function") {
|
|
728
|
+
RouterBox["pageHide"] = callback;
|
|
729
|
+
} else {
|
|
730
|
+
throw new Error(
|
|
731
|
+
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
Router.packageScreen = async function(path, data) {
|
|
736
|
+
if (!RouterBox.routes[path]) {
|
|
737
|
+
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
738
|
+
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
739
|
+
}
|
|
740
|
+
await RouterBox.routes[path].packager(data);
|
|
741
|
+
};
|
|
742
|
+
Router.getParams = function() {
|
|
743
|
+
return RouterBox["params"];
|
|
744
|
+
};
|
|
745
|
+
Router["addErrorHandler"] = function(callback, path) {
|
|
746
|
+
if (typeof callback === "function") {
|
|
747
|
+
RouterBox["errorHandler"][path || "all"] = callback;
|
|
748
|
+
} else {
|
|
749
|
+
throw new Error(
|
|
750
|
+
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
755
|
+
window.addEventListener("popstate", (e) => {
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
RouterBox.router();
|
|
758
|
+
});
|
|
1003
759
|
|
|
1004
760
|
// lib/scripts/createSignal.ts
|
|
1005
761
|
var createSignal = class {
|
|
@@ -1132,9 +888,9 @@ var createSignal = class {
|
|
|
1132
888
|
this.ref = Ref2;
|
|
1133
889
|
if (typeof path === "string") {
|
|
1134
890
|
this.path = path;
|
|
1135
|
-
Ref2.
|
|
891
|
+
Ref2.render = Ref2.render.bind(Ref2, this.value[path]);
|
|
1136
892
|
} else {
|
|
1137
|
-
Ref2.
|
|
893
|
+
Ref2.render = Ref2.render.bind(Ref2, this.value);
|
|
1138
894
|
}
|
|
1139
895
|
} else {
|
|
1140
896
|
throw new Error("\u2718 Cradova err : Invalid ref component" + Ref2);
|
|
@@ -1161,7 +917,7 @@ var createSignal = class {
|
|
|
1161
917
|
}
|
|
1162
918
|
clearPersist() {
|
|
1163
919
|
if (this.persistName) {
|
|
1164
|
-
localStorage.setItem(this.persistName,
|
|
920
|
+
localStorage.setItem(this.persistName, "");
|
|
1165
921
|
}
|
|
1166
922
|
}
|
|
1167
923
|
};
|
|
@@ -1201,7 +957,7 @@ var simpleStore = class {
|
|
|
1201
957
|
} else {
|
|
1202
958
|
for (let i = 0; i < this.ref.length; i++) {
|
|
1203
959
|
const entry = this.ref[i];
|
|
1204
|
-
entry.ref.updateState({ [entry.
|
|
960
|
+
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
1205
961
|
}
|
|
1206
962
|
}
|
|
1207
963
|
}
|
|
@@ -1235,7 +991,7 @@ var simpleStore = class {
|
|
|
1235
991
|
function Ajax(url, opts = {}) {
|
|
1236
992
|
const { method, data, header, callbacks } = opts;
|
|
1237
993
|
if (typeof url !== "string") {
|
|
1238
|
-
throw new Error("\u2718 Cradova err :
|
|
994
|
+
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
1239
995
|
}
|
|
1240
996
|
return new Promise(function(resolve) {
|
|
1241
997
|
const ajax = new XMLHttpRequest();
|
|
@@ -1259,8 +1015,11 @@ function Ajax(url, opts = {}) {
|
|
|
1259
1015
|
formData.set(k, value);
|
|
1260
1016
|
}
|
|
1261
1017
|
}
|
|
1262
|
-
ajax.addEventListener("error", (
|
|
1263
|
-
console.error(
|
|
1018
|
+
ajax.addEventListener("error", () => {
|
|
1019
|
+
console.error(
|
|
1020
|
+
"\u2718 Cradova Ajax err : ",
|
|
1021
|
+
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
1022
|
+
);
|
|
1264
1023
|
if (!navigator.onLine) {
|
|
1265
1024
|
resolve(
|
|
1266
1025
|
JSON.stringify({
|
|
@@ -1289,97 +1048,6 @@ function Ajax(url, opts = {}) {
|
|
|
1289
1048
|
});
|
|
1290
1049
|
}
|
|
1291
1050
|
|
|
1292
|
-
// lib/sacho/swipe1.ts
|
|
1293
|
-
function swipe(callback, touching = false, element) {
|
|
1294
|
-
if (!(typeof callback === "function")) {
|
|
1295
|
-
throw new Error(
|
|
1296
|
-
" \u2718 Cradova err: no function given for the swipe handler"
|
|
1297
|
-
);
|
|
1298
|
-
}
|
|
1299
|
-
let touchingState = false;
|
|
1300
|
-
let touchstartX = 0;
|
|
1301
|
-
let touchstartY = 0;
|
|
1302
|
-
let touchendX = 0;
|
|
1303
|
-
let touchendY = 0;
|
|
1304
|
-
function handleTouchStart(event) {
|
|
1305
|
-
touchstartX = Math.round(event.changedTouches[0].clientX);
|
|
1306
|
-
touchstartY = Math.round(event.changedTouches[0].clientY);
|
|
1307
|
-
}
|
|
1308
|
-
const capturedGesture = {
|
|
1309
|
-
top: 0,
|
|
1310
|
-
tap: 0,
|
|
1311
|
-
down: 0,
|
|
1312
|
-
left: 0,
|
|
1313
|
-
right: 0,
|
|
1314
|
-
touch: 0
|
|
1315
|
-
};
|
|
1316
|
-
function handleGesture(event) {
|
|
1317
|
-
touchendX = Math.round(
|
|
1318
|
-
event.changedTouches[event.changedTouches.length - 1].clientX
|
|
1319
|
-
);
|
|
1320
|
-
touchendY = Math.round(
|
|
1321
|
-
event.changedTouches[event.changedTouches.length - 1].clientY
|
|
1322
|
-
);
|
|
1323
|
-
if (touching) {
|
|
1324
|
-
capturedGesture.top = capturedGesture.down = capturedGesture.right = capturedGesture.left = capturedGesture.tap = capturedGesture.touch = 0;
|
|
1325
|
-
}
|
|
1326
|
-
if (touching) {
|
|
1327
|
-
if (touchingState) {
|
|
1328
|
-
handleTouchStart(event);
|
|
1329
|
-
touchingState = false;
|
|
1330
|
-
} else {
|
|
1331
|
-
capturedGesture.top = capturedGesture.down = capturedGesture.right = capturedGesture.left = capturedGesture.tap = capturedGesture.touch = 0;
|
|
1332
|
-
touchingState = true;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
if (touchendX > touchstartX) {
|
|
1336
|
-
capturedGesture.right = touchendX - touchstartX;
|
|
1337
|
-
}
|
|
1338
|
-
if (touchendX < touchstartX) {
|
|
1339
|
-
capturedGesture.left = touchstartX - touchendX;
|
|
1340
|
-
}
|
|
1341
|
-
if (touchendY > touchstartY) {
|
|
1342
|
-
capturedGesture.down = touchendY - touchstartY;
|
|
1343
|
-
}
|
|
1344
|
-
if (touchendY < touchstartY) {
|
|
1345
|
-
capturedGesture.top = touchstartY - touchendY;
|
|
1346
|
-
}
|
|
1347
|
-
if (touchendY == touchstartY) {
|
|
1348
|
-
capturedGesture.tap = touching ? 0 : 1;
|
|
1349
|
-
capturedGesture.touch = touching ? 1 : 0;
|
|
1350
|
-
}
|
|
1351
|
-
const keys = Object.keys(capturedGesture);
|
|
1352
|
-
let max = keys[0];
|
|
1353
|
-
for (let i = 1; i < keys.length; i++) {
|
|
1354
|
-
const value = keys[i];
|
|
1355
|
-
if (capturedGesture[value] > capturedGesture[max])
|
|
1356
|
-
max = value;
|
|
1357
|
-
}
|
|
1358
|
-
if (callback) {
|
|
1359
|
-
callback({ [max]: capturedGesture[max] });
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
const escapeTSError = element || document.body;
|
|
1363
|
-
return {
|
|
1364
|
-
start() {
|
|
1365
|
-
if (touching) {
|
|
1366
|
-
escapeTSError?.addEventListener("touchmove", handleGesture);
|
|
1367
|
-
} else {
|
|
1368
|
-
escapeTSError?.addEventListener("touchstart", handleTouchStart);
|
|
1369
|
-
escapeTSError?.addEventListener("touchend", handleGesture);
|
|
1370
|
-
}
|
|
1371
|
-
},
|
|
1372
|
-
stop() {
|
|
1373
|
-
if (touching) {
|
|
1374
|
-
escapeTSError?.removeEventListener("touchmove", handleGesture);
|
|
1375
|
-
} else {
|
|
1376
|
-
escapeTSError?.removeEventListener("touchstart", handleTouchStart);
|
|
1377
|
-
escapeTSError?.removeEventListener("touchend", handleGesture);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
1051
|
// lib/sacho/loadCss.ts
|
|
1384
1052
|
function loadCradovaUICss(seconds = 0.3) {
|
|
1385
1053
|
const css2 = `:root {
|
|
@@ -1579,12 +1247,6 @@ function loadCradovaUICss(seconds = 0.3) {
|
|
|
1579
1247
|
document.head.appendChild(style);
|
|
1580
1248
|
}
|
|
1581
1249
|
|
|
1582
|
-
// lib/scripts/utils.ts
|
|
1583
|
-
function IsElementInView(element) {
|
|
1584
|
-
const rect = element.getBoundingClientRect();
|
|
1585
|
-
return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || window.document.documentElement.clientHeight) && rect.right <= (window.innerWidth || window.document.documentElement.clientWidth);
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
1250
|
// lib/scripts/init.ts
|
|
1589
1251
|
var Init = function() {
|
|
1590
1252
|
if (document.querySelector("[data-cra-id=cradova-app-wrapper]")) {
|
|
@@ -1714,11 +1376,7 @@ var _ = (...element_initials) => {
|
|
|
1714
1376
|
}
|
|
1715
1377
|
try {
|
|
1716
1378
|
if (child2 instanceof HTMLElement || child2 instanceof DocumentFragment) {
|
|
1717
|
-
element.
|
|
1718
|
-
}
|
|
1719
|
-
if (child2 && child2.afterMount) {
|
|
1720
|
-
child2.afterMount(child2);
|
|
1721
|
-
child2.afterMount = void 0;
|
|
1379
|
+
element.appendChild(child2);
|
|
1722
1380
|
}
|
|
1723
1381
|
} catch (error) {
|
|
1724
1382
|
console.error(" \u2718 Cradova err: ", error);
|
|
@@ -1731,7 +1389,7 @@ var _ = (...element_initials) => {
|
|
|
1731
1389
|
continue;
|
|
1732
1390
|
}
|
|
1733
1391
|
if (secondLevelChildren[i] instanceof HTMLElement || secondLevelChildren[i] instanceof DocumentFragment) {
|
|
1734
|
-
element.
|
|
1392
|
+
element.appendChild(secondLevelChildren[i]);
|
|
1735
1393
|
continue;
|
|
1736
1394
|
}
|
|
1737
1395
|
if (Array.isArray(secondLevelChildren[i])) {
|
|
@@ -1756,11 +1414,7 @@ var _ = (...element_initials) => {
|
|
|
1756
1414
|
}
|
|
1757
1415
|
const child = secondLevelChildren[i];
|
|
1758
1416
|
if (child instanceof HTMLElement || child instanceof DocumentFragment) {
|
|
1759
|
-
element.
|
|
1760
|
-
if (child.afterMount) {
|
|
1761
|
-
child.afterMount(child);
|
|
1762
|
-
child.afterMount = void 0;
|
|
1763
|
-
}
|
|
1417
|
+
element.appendChild(child);
|
|
1764
1418
|
} else {
|
|
1765
1419
|
if (typeof child === "object" && !Array.isArray(child) && !(child instanceof HTMLElement)) {
|
|
1766
1420
|
if (!props) {
|
|
@@ -1791,7 +1445,6 @@ var _ = (...element_initials) => {
|
|
|
1791
1445
|
if (props) {
|
|
1792
1446
|
if (props.beforeMount) {
|
|
1793
1447
|
beforeMount = props["beforeMount"];
|
|
1794
|
-
props["beforeMount"] = void 0;
|
|
1795
1448
|
}
|
|
1796
1449
|
for (const prop in props) {
|
|
1797
1450
|
if (prop === "style" && typeof props[prop] === "object") {
|
|
@@ -1820,7 +1473,6 @@ var _ = (...element_initials) => {
|
|
|
1820
1473
|
}
|
|
1821
1474
|
if (prop === "beforeMount") {
|
|
1822
1475
|
beforeMount = props["beforeMount"];
|
|
1823
|
-
props["beforeMount"] = void 0;
|
|
1824
1476
|
continue;
|
|
1825
1477
|
}
|
|
1826
1478
|
if (prop === "stateID") {
|
|
@@ -1840,12 +1492,20 @@ var _ = (...element_initials) => {
|
|
|
1840
1492
|
element.updateState = dispatch.bind(null, element);
|
|
1841
1493
|
continue;
|
|
1842
1494
|
}
|
|
1495
|
+
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1496
|
+
const av = () => {
|
|
1497
|
+
props["afterMount"].apply(element);
|
|
1498
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
1499
|
+
};
|
|
1500
|
+
window.addEventListener("cradova-aftermount", av);
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1843
1503
|
try {
|
|
1844
1504
|
if (typeof element[prop] !== "undefined") {
|
|
1845
1505
|
element[prop] = props[prop];
|
|
1846
1506
|
} else {
|
|
1847
1507
|
element[prop] = props[prop];
|
|
1848
|
-
if (prop !== "
|
|
1508
|
+
if (prop !== "for" && prop !== "text" && prop !== "class" && !prop.includes("aria")) {
|
|
1849
1509
|
console.error(" \u2718 Cradova err: invalid html attribute " + prop);
|
|
1850
1510
|
}
|
|
1851
1511
|
}
|
|
@@ -1858,8 +1518,8 @@ var _ = (...element_initials) => {
|
|
|
1858
1518
|
if (text) {
|
|
1859
1519
|
element.innerText = text;
|
|
1860
1520
|
}
|
|
1861
|
-
if (beforeMount) {
|
|
1862
|
-
beforeMount(element);
|
|
1521
|
+
if (typeof beforeMount === "function") {
|
|
1522
|
+
beforeMount.apply(element);
|
|
1863
1523
|
}
|
|
1864
1524
|
return element;
|
|
1865
1525
|
};
|
|
@@ -1867,29 +1527,19 @@ var _ = (...element_initials) => {
|
|
|
1867
1527
|
Init();
|
|
1868
1528
|
var lib_default = _;
|
|
1869
1529
|
export {
|
|
1870
|
-
|
|
1530
|
+
simpleStore as $,
|
|
1871
1531
|
Ajax,
|
|
1872
|
-
IsElementInView,
|
|
1873
|
-
PromptBeforeLeave,
|
|
1874
1532
|
Ref,
|
|
1875
|
-
RefList,
|
|
1876
1533
|
Router,
|
|
1877
|
-
Scaffold,
|
|
1878
1534
|
Screen,
|
|
1879
|
-
animate,
|
|
1880
1535
|
assert,
|
|
1881
1536
|
assertOr,
|
|
1882
|
-
|
|
1537
|
+
cradovaAftermountEvent,
|
|
1883
1538
|
createSignal,
|
|
1884
1539
|
css,
|
|
1885
1540
|
lib_default as default,
|
|
1886
1541
|
dispatch,
|
|
1887
1542
|
frag,
|
|
1888
|
-
fullScreen,
|
|
1889
1543
|
loadCradovaUICss,
|
|
1890
|
-
ls
|
|
1891
|
-
media,
|
|
1892
|
-
simpleStore,
|
|
1893
|
-
swipe,
|
|
1894
|
-
uuid
|
|
1544
|
+
ls
|
|
1895
1545
|
};
|