cradova 1.4.0 → 1.4.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/dist/index.js +961 -920
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,761 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
23
|
-
element.style[key] = state[key];
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
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();
|
|
39
|
-
}
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
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
|
-
}
|
|
48
|
-
}
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (key === "toggleclass" && state[key] !== "") {
|
|
52
|
-
element.classList.toggle(state[key]);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
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();
|
|
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);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function dispatch(stateID, state) {
|
|
119
|
-
let ele;
|
|
120
|
-
if (stateID instanceof HTMLElement) {
|
|
121
|
-
ele = stateID;
|
|
122
|
-
}
|
|
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);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
if (typeof stateID === "string") {
|
|
134
|
-
const elements = document.querySelectorAll(
|
|
135
|
-
"[data-cra-id=" + stateID + "]"
|
|
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);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return updated;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// lib/scripts/fns.ts
|
|
152
|
-
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
153
|
-
var err = function(errors, err2, type) {
|
|
154
|
-
for (let er = 0; er < errors.length; er++) {
|
|
155
|
-
console.error(" \u2718 Cradova err: ", errors[er]);
|
|
156
|
-
}
|
|
157
|
-
if (!type) {
|
|
158
|
-
throw new Error(" \u2718 Cradova err: " + err2);
|
|
159
|
-
} else {
|
|
160
|
-
throw new TypeError(" \u2718 Cradova err: " + err2);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
function uuid() {
|
|
164
|
-
let t = Date.now ? +Date.now() : +new Date();
|
|
165
|
-
return "cradova-id-xxxxxxxxxx".replace(/[x]/g, function(e) {
|
|
166
|
-
const r = (t + 16 * Math.random()) % 16 | 0;
|
|
167
|
-
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function css(identifier, properties) {
|
|
171
|
-
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
172
|
-
let styTag = document.querySelector("style");
|
|
173
|
-
if (styTag !== null) {
|
|
174
|
-
identifier += styTag.textContent;
|
|
175
|
-
styTag.textContent = identifier;
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
styTag = document.createElement("style");
|
|
179
|
-
styTag.textContent = identifier;
|
|
180
|
-
document.head.append(styTag);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (!properties) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const styS = "" + identifier + `{
|
|
187
|
-
`;
|
|
188
|
-
const styE = `}
|
|
189
|
-
`;
|
|
190
|
-
let style = "", totalStyle = "";
|
|
191
|
-
for (const [k, v] of Object.entries(properties)) {
|
|
192
|
-
style += "" + k + ": " + v + `;
|
|
193
|
-
`;
|
|
194
|
-
}
|
|
195
|
-
let styleTag = document.querySelector("style");
|
|
196
|
-
if (styleTag !== null) {
|
|
197
|
-
totalStyle += styleTag.innerHTML;
|
|
198
|
-
totalStyle += styS + style + styE;
|
|
199
|
-
styleTag.innerHTML = totalStyle;
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
styleTag = document.createElement("style");
|
|
203
|
-
totalStyle += styleTag.innerHTML + `
|
|
204
|
-
|
|
205
|
-
`;
|
|
206
|
-
totalStyle += styS + style + styE;
|
|
207
|
-
styleTag.innerHTML = totalStyle;
|
|
208
|
-
document.head.append(styleTag);
|
|
209
|
-
}
|
|
210
|
-
function assert(condition, ...callback) {
|
|
211
|
-
if (condition) {
|
|
212
|
-
return callback;
|
|
213
|
-
}
|
|
214
|
-
return "";
|
|
215
|
-
}
|
|
216
|
-
function assertOr(condition, ifTrue, ifFalse) {
|
|
217
|
-
if (condition) {
|
|
218
|
-
return ifTrue;
|
|
219
|
-
}
|
|
220
|
-
return ifFalse;
|
|
221
|
-
}
|
|
222
|
-
var ls = {};
|
|
223
|
-
ls.store = (name, value) => {
|
|
224
|
-
localStorage.setItem(name, JSON.stringify(value));
|
|
225
|
-
};
|
|
226
|
-
ls.retrieve = (name) => {
|
|
227
|
-
return localStorage.getItem(name);
|
|
228
|
-
};
|
|
229
|
-
ls.remove = (name) => {
|
|
230
|
-
localStorage.removeItem(name);
|
|
231
|
-
};
|
|
232
|
-
ls.getKey = (index) => {
|
|
233
|
-
return window.localStorage.key(index);
|
|
234
|
-
};
|
|
235
|
-
ls.clear = () => {
|
|
236
|
-
localStorage.clear();
|
|
237
|
-
};
|
|
238
|
-
function fullScreen(e) {
|
|
239
|
-
return {
|
|
240
|
-
set() {
|
|
241
|
-
e.requestFullscreen().catch((err2) => {
|
|
242
|
-
throw err2;
|
|
243
|
-
});
|
|
244
|
-
},
|
|
245
|
-
exist() {
|
|
246
|
-
document.exitFullscreen();
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
var Ref = class {
|
|
251
|
-
constructor(component) {
|
|
252
|
-
this.stateID = uuid();
|
|
253
|
-
this.rendered = false;
|
|
254
|
-
this.effects = [];
|
|
255
|
-
this.effectuate = null;
|
|
256
|
-
this.hasFirstStateUpdateRun = false;
|
|
257
|
-
this.component = component.bind(this);
|
|
258
|
-
}
|
|
259
|
-
render(data) {
|
|
260
|
-
const chtml = this.component(data);
|
|
261
|
-
if (typeof chtml !== "function") {
|
|
262
|
-
throw new Error(
|
|
263
|
-
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + chtml
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
const element = chtml({ stateID: this.stateID });
|
|
267
|
-
if (!(element instanceof HTMLElement)) {
|
|
268
|
-
err(
|
|
269
|
-
[
|
|
270
|
-
`
|
|
271
|
-
\x1B[35m Exception: ref only a function that returns cradova element or cradova element tree. \x1B[35m
|
|
272
|
-
|
|
273
|
-
to track and debug this element add a
|
|
274
|
-
beforeMount or afterMount prop to the element
|
|
275
|
-
`
|
|
276
|
-
],
|
|
277
|
-
`Cradova can't render component make sure it's a valid component`
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
const av = () => {
|
|
281
|
-
this.effector.apply(this);
|
|
282
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
283
|
-
};
|
|
284
|
-
window.addEventListener("cradova-aftermount", av);
|
|
285
|
-
return () => element;
|
|
286
|
-
}
|
|
287
|
-
instance() {
|
|
288
|
-
return dispatch(this.stateID, {
|
|
289
|
-
cradovaDispatchTrackBreak: true
|
|
290
|
-
});
|
|
291
|
-
}
|
|
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
|
-
);
|
|
311
|
-
}
|
|
312
|
-
async effector() {
|
|
313
|
-
await Promise.allSettled(this.effects);
|
|
314
|
-
this.rendered = true;
|
|
315
|
-
this.hasFirstStateUpdateRun = true;
|
|
316
|
-
}
|
|
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) {
|
|
335
|
-
if (!data) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
if (!this) {
|
|
339
|
-
console.error(
|
|
340
|
-
" \u2718 Cradova err: Ref.updateState has is passed out of scope"
|
|
341
|
-
);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const guy = dispatch(this.stateID, {
|
|
345
|
-
cradovaDispatchTrackBreak: true
|
|
346
|
-
});
|
|
347
|
-
if (!guy) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
const chtml = this.component(data);
|
|
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 });
|
|
357
|
-
}
|
|
358
|
-
try {
|
|
359
|
-
guy.insertAdjacentElement("beforebegin", element);
|
|
360
|
-
if (guy.parentElement) {
|
|
361
|
-
guy.parentElement.removeChild(guy);
|
|
362
|
-
} else {
|
|
363
|
-
guy.remove();
|
|
364
|
-
}
|
|
365
|
-
} catch (e0) {
|
|
366
|
-
console.error(e0);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
remove() {
|
|
370
|
-
dispatch(this.stateID, { remove: true });
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
var frag = function(...children) {
|
|
374
|
-
const par = document.createDocumentFragment();
|
|
375
|
-
for (let i = 0; i < children.length; i++) {
|
|
376
|
-
if (typeof children[i] === "function") {
|
|
377
|
-
const a = children[i]();
|
|
378
|
-
if (typeof a === "function") {
|
|
379
|
-
const b = a();
|
|
380
|
-
if (b instanceof HTMLElement) {
|
|
381
|
-
par.append(b);
|
|
382
|
-
} else {
|
|
383
|
-
if (!(b instanceof HTMLElement)) {
|
|
384
|
-
console.error(" \u2718 Cradova err: wrong element type" + b);
|
|
385
|
-
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
} else {
|
|
389
|
-
if (a instanceof HTMLElement) {
|
|
390
|
-
par.append(a);
|
|
391
|
-
} else {
|
|
392
|
-
if (!(a instanceof HTMLElement)) {
|
|
393
|
-
console.error(" \u2718 Cradova err: wrong element type" + a);
|
|
394
|
-
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
console.error(" \u2718 Cradova err: wrong element type" + children[i]);
|
|
400
|
-
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return par;
|
|
404
|
-
};
|
|
405
|
-
|
|
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
|
-
);
|
|
422
|
-
}
|
|
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);
|
|
439
|
-
}
|
|
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);
|
|
478
|
-
}
|
|
479
|
-
this.template.innerHTML = "";
|
|
480
|
-
this.template.appendChild(fuc);
|
|
481
|
-
}
|
|
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;
|
|
590
|
-
}
|
|
591
|
-
isIt = false;
|
|
592
|
-
}
|
|
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
|
-
);
|
|
597
|
-
}
|
|
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];
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
routesParams.path = path;
|
|
606
|
-
return [RouterBox.routes[path], routesParams];
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
}
|
|
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");
|
|
616
|
-
}
|
|
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();
|
|
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;
|
|
638
|
-
} else {
|
|
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
|
-
}
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
655
20
|
};
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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);
|
|
21
|
+
|
|
22
|
+
// lib/scripts/ajax.ts
|
|
23
|
+
function Ajax(url, opts = {}) {
|
|
24
|
+
const { method, data, header, callbacks } = opts;
|
|
25
|
+
if (typeof url !== "string") {
|
|
26
|
+
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
682
27
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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);
|
|
28
|
+
return new Promise(function(resolve) {
|
|
29
|
+
const ajax = new XMLHttpRequest();
|
|
30
|
+
const formData = new FormData();
|
|
31
|
+
if (callbacks && typeof callbacks === "object") {
|
|
32
|
+
for (const [k, v] of Object.entries(callbacks)) {
|
|
33
|
+
if (typeof v === "function" && ajax[k]) {
|
|
34
|
+
ajax[k] = v;
|
|
35
|
+
}
|
|
698
36
|
}
|
|
699
37
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
38
|
+
ajax.addEventListener("load", function() {
|
|
39
|
+
resolve(ajax.response);
|
|
40
|
+
});
|
|
41
|
+
if (data && typeof data === "object") {
|
|
42
|
+
for (const [k, v] of Object.entries(data)) {
|
|
43
|
+
let value = v;
|
|
44
|
+
if (typeof value === "object" && value && !value.name) {
|
|
45
|
+
value = JSON.stringify(value);
|
|
46
|
+
}
|
|
47
|
+
formData.set(k, value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
ajax.addEventListener("error", () => {
|
|
51
|
+
console.error(
|
|
52
|
+
"\u2718 Cradova Ajax err : ",
|
|
53
|
+
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
54
|
+
);
|
|
55
|
+
if (!navigator.onLine) {
|
|
56
|
+
resolve(
|
|
57
|
+
JSON.stringify({
|
|
58
|
+
message: `the device is offline!`
|
|
59
|
+
})
|
|
708
60
|
);
|
|
709
61
|
} else {
|
|
710
|
-
|
|
711
|
-
|
|
62
|
+
resolve(
|
|
63
|
+
JSON.stringify({
|
|
64
|
+
message: `problem with the action, please try again!`
|
|
65
|
+
})
|
|
712
66
|
);
|
|
713
67
|
}
|
|
68
|
+
});
|
|
69
|
+
if (!method) {
|
|
70
|
+
ajax.open(data && typeof data === "object" ? "POST" : "GET", url, true);
|
|
71
|
+
} else {
|
|
72
|
+
ajax.open(method, url, true);
|
|
714
73
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
-
});
|
|
74
|
+
if (header && typeof header === "object") {
|
|
75
|
+
Object.keys(header).forEach(function(key) {
|
|
76
|
+
ajax.setRequestHeader(key, header[key]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
ajax.send(formData);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
759
82
|
|
|
760
83
|
// lib/scripts/createSignal.ts
|
|
761
84
|
var createSignal = class {
|
|
@@ -922,130 +245,416 @@ var createSignal = class {
|
|
|
922
245
|
}
|
|
923
246
|
};
|
|
924
247
|
|
|
925
|
-
// lib/scripts/
|
|
926
|
-
var
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
this.value = initial;
|
|
248
|
+
// lib/scripts/fns.ts
|
|
249
|
+
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
250
|
+
var err = function(errors, err2, type) {
|
|
251
|
+
for (let er = 0; er < errors.length; er++) {
|
|
252
|
+
console.error(" \u2718 Cradova err: ", errors[er]);
|
|
931
253
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
254
|
+
if (!type) {
|
|
255
|
+
throw new Error(" \u2718 Cradova err: " + err2);
|
|
256
|
+
} else {
|
|
257
|
+
throw new TypeError(" \u2718 Cradova err: " + err2);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
function uuid() {
|
|
261
|
+
let t = Date.now ? +Date.now() : +new Date();
|
|
262
|
+
return "cradova-id-xxxxxxxxxx".replace(/[x]/g, function(e) {
|
|
263
|
+
const r = (t + 16 * Math.random()) % 16 | 0;
|
|
264
|
+
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function css(identifier, properties) {
|
|
268
|
+
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
269
|
+
let styTag = document.querySelector("style");
|
|
270
|
+
if (styTag !== null) {
|
|
271
|
+
identifier += styTag.textContent;
|
|
272
|
+
styTag.textContent = identifier;
|
|
273
|
+
return;
|
|
937
274
|
}
|
|
938
|
-
|
|
939
|
-
|
|
275
|
+
styTag = document.createElement("style");
|
|
276
|
+
styTag.textContent = identifier;
|
|
277
|
+
document.head.append(styTag);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!properties) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const styS = "" + identifier + `{
|
|
284
|
+
`;
|
|
285
|
+
const styE = `}
|
|
286
|
+
`;
|
|
287
|
+
let style = "", totalStyle = "";
|
|
288
|
+
for (const [k, v] of Object.entries(properties)) {
|
|
289
|
+
style += "" + k + ": " + v + `;
|
|
290
|
+
`;
|
|
291
|
+
}
|
|
292
|
+
let styleTag = document.querySelector("style");
|
|
293
|
+
if (styleTag !== null) {
|
|
294
|
+
totalStyle += styleTag.innerHTML;
|
|
295
|
+
totalStyle += styS + style + styE;
|
|
296
|
+
styleTag.innerHTML = totalStyle;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
styleTag = document.createElement("style");
|
|
300
|
+
totalStyle += styleTag.innerHTML + `
|
|
301
|
+
|
|
302
|
+
`;
|
|
303
|
+
totalStyle += styS + style + styE;
|
|
304
|
+
styleTag.innerHTML = totalStyle;
|
|
305
|
+
document.head.append(styleTag);
|
|
306
|
+
}
|
|
307
|
+
function assert(condition, ...callback) {
|
|
308
|
+
if (condition) {
|
|
309
|
+
return callback;
|
|
310
|
+
}
|
|
311
|
+
return "";
|
|
312
|
+
}
|
|
313
|
+
function assertOr(condition, ifTrue, ifFalse) {
|
|
314
|
+
if (condition) {
|
|
315
|
+
return ifTrue;
|
|
316
|
+
}
|
|
317
|
+
return ifFalse;
|
|
318
|
+
}
|
|
319
|
+
var ls = {};
|
|
320
|
+
ls.store = (name, value) => {
|
|
321
|
+
localStorage.setItem(name, JSON.stringify(value));
|
|
322
|
+
};
|
|
323
|
+
ls.retrieve = (name) => {
|
|
324
|
+
return localStorage.getItem(name);
|
|
325
|
+
};
|
|
326
|
+
ls.remove = (name) => {
|
|
327
|
+
localStorage.removeItem(name);
|
|
328
|
+
};
|
|
329
|
+
ls.getKey = (index) => {
|
|
330
|
+
return window.localStorage.key(index);
|
|
331
|
+
};
|
|
332
|
+
ls.clear = () => {
|
|
333
|
+
localStorage.clear();
|
|
334
|
+
};
|
|
335
|
+
function fullScreen(e) {
|
|
336
|
+
return {
|
|
337
|
+
set() {
|
|
338
|
+
e.requestFullscreen().catch((err2) => {
|
|
339
|
+
throw err2;
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
exist() {
|
|
343
|
+
document.exitFullscreen();
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
var Ref = class {
|
|
348
|
+
constructor(component) {
|
|
349
|
+
this.stateID = uuid();
|
|
350
|
+
this.rendered = false;
|
|
351
|
+
this.effects = [];
|
|
352
|
+
this.effectuate = null;
|
|
353
|
+
this.hasFirstStateUpdateRun = false;
|
|
354
|
+
this.component = component.bind(this);
|
|
355
|
+
}
|
|
356
|
+
render(data) {
|
|
357
|
+
const chtml = this.component(data);
|
|
358
|
+
if (typeof chtml !== "function") {
|
|
359
|
+
throw new Error(
|
|
360
|
+
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + chtml
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
const element = chtml({ stateID: this.stateID });
|
|
364
|
+
if (!(element instanceof HTMLElement)) {
|
|
365
|
+
err(
|
|
366
|
+
[
|
|
367
|
+
`
|
|
368
|
+
\x1B[35m Exception: ref only a function that returns cradova element or cradova element tree. \x1B[35m
|
|
369
|
+
|
|
370
|
+
to track and debug this element add a
|
|
371
|
+
beforeMount or afterMount prop to the element
|
|
372
|
+
`
|
|
373
|
+
],
|
|
374
|
+
`Cradova can't render component make sure it's a valid component`
|
|
375
|
+
);
|
|
940
376
|
}
|
|
377
|
+
const av = () => {
|
|
378
|
+
this.effector.apply(this);
|
|
379
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
380
|
+
};
|
|
381
|
+
window.addEventListener("cradova-aftermount", av);
|
|
382
|
+
return () => element;
|
|
941
383
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
384
|
+
instance() {
|
|
385
|
+
return dispatch(this.stateID, {
|
|
386
|
+
cradovaDispatchTrackBreak: true
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
effect(fn) {
|
|
390
|
+
if (this.rendered) {
|
|
391
|
+
return;
|
|
949
392
|
}
|
|
393
|
+
fn = fn.bind(this);
|
|
394
|
+
this.effects.push(
|
|
395
|
+
new Promise((res, rej) => __async(this, null, function* () {
|
|
396
|
+
try {
|
|
397
|
+
yield fn();
|
|
398
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
399
|
+
this.hasFirstStateUpdateRun = true;
|
|
400
|
+
yield this.effectuate();
|
|
401
|
+
}
|
|
402
|
+
res(void 0);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
rej(error);
|
|
405
|
+
}
|
|
406
|
+
}))
|
|
407
|
+
);
|
|
950
408
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
409
|
+
effector() {
|
|
410
|
+
return __async(this, null, function* () {
|
|
411
|
+
yield Promise.allSettled(this.effects);
|
|
412
|
+
this.rendered = true;
|
|
413
|
+
this.hasFirstStateUpdateRun = true;
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
updateState(data) {
|
|
417
|
+
if (!this.rendered) {
|
|
418
|
+
this.rendered = true;
|
|
419
|
+
function updateState(data2) {
|
|
420
|
+
return __async(this, null, function* () {
|
|
421
|
+
if (this.instance()) {
|
|
422
|
+
yield this.Activate(data2);
|
|
423
|
+
} else {
|
|
424
|
+
setTimeout(updateState.bind(this, data2), 4);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
956
427
|
}
|
|
428
|
+
this.effectuate = updateState.bind(this, data);
|
|
957
429
|
} else {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
430
|
+
(() => __async(this, null, function* () {
|
|
431
|
+
yield this.Activate(data);
|
|
432
|
+
})).bind(this)();
|
|
962
433
|
}
|
|
963
434
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
if (
|
|
967
|
-
|
|
435
|
+
Activate(data) {
|
|
436
|
+
return __async(this, null, function* () {
|
|
437
|
+
if (!data) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (!this) {
|
|
441
|
+
console.error(
|
|
442
|
+
" \u2718 Cradova err: Ref.updateState has is passed out of scope"
|
|
443
|
+
);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const guy = dispatch(this.stateID, {
|
|
447
|
+
cradovaDispatchTrackBreak: true
|
|
448
|
+
});
|
|
449
|
+
if (!guy) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const chtml = this.component(data);
|
|
453
|
+
let element;
|
|
454
|
+
if (chtml instanceof HTMLElement) {
|
|
455
|
+
chtml.setAttribute("data-cra-id", this.stateID);
|
|
456
|
+
element = chtml;
|
|
968
457
|
} else {
|
|
969
|
-
this.
|
|
458
|
+
element = chtml({ stateID: this.stateID });
|
|
970
459
|
}
|
|
971
|
-
|
|
972
|
-
|
|
460
|
+
try {
|
|
461
|
+
guy.insertAdjacentElement("beforebegin", element);
|
|
462
|
+
if (guy.parentElement) {
|
|
463
|
+
guy.parentElement.removeChild(guy);
|
|
464
|
+
} else {
|
|
465
|
+
guy.remove();
|
|
466
|
+
}
|
|
467
|
+
} catch (e0) {
|
|
468
|
+
console.error(e0);
|
|
973
469
|
}
|
|
974
|
-
}
|
|
470
|
+
});
|
|
975
471
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
472
|
+
remove() {
|
|
473
|
+
dispatch(this.stateID, { remove: true });
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var frag = function(...children) {
|
|
477
|
+
const par = document.createDocumentFragment();
|
|
478
|
+
for (let i = 0; i < children.length; i++) {
|
|
479
|
+
if (typeof children[i] === "function") {
|
|
480
|
+
const a = children[i]();
|
|
481
|
+
if (typeof a === "function") {
|
|
482
|
+
const b = a();
|
|
483
|
+
if (b instanceof HTMLElement) {
|
|
484
|
+
par.append(b);
|
|
485
|
+
} else {
|
|
486
|
+
if (!(b instanceof HTMLElement)) {
|
|
487
|
+
console.error(" \u2718 Cradova err: wrong element type" + b);
|
|
488
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
} else {
|
|
492
|
+
if (a instanceof HTMLElement) {
|
|
493
|
+
par.append(a);
|
|
494
|
+
} else {
|
|
495
|
+
if (!(a instanceof HTMLElement)) {
|
|
496
|
+
console.error(" \u2718 Cradova err: wrong element type" + a);
|
|
497
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
498
|
+
}
|
|
499
|
+
}
|
|
981
500
|
}
|
|
982
501
|
} else {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
);
|
|
502
|
+
console.error(" \u2718 Cradova err: wrong element type" + children[i]);
|
|
503
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
986
504
|
}
|
|
987
505
|
}
|
|
506
|
+
return par;
|
|
988
507
|
};
|
|
989
508
|
|
|
990
|
-
// lib/scripts/
|
|
991
|
-
function
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
const ajax = new XMLHttpRequest();
|
|
998
|
-
const formData = new FormData();
|
|
999
|
-
if (callbacks && typeof callbacks === "object") {
|
|
1000
|
-
for (const [k, v] of Object.entries(callbacks)) {
|
|
1001
|
-
if (typeof v === "function" && ajax[k]) {
|
|
1002
|
-
ajax[k] = v;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
509
|
+
// lib/scripts/track.ts
|
|
510
|
+
function cradovaDispatchTrack(nodes, state) {
|
|
511
|
+
var _a;
|
|
512
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
513
|
+
const element = nodes[i];
|
|
514
|
+
if (!element) {
|
|
515
|
+
continue;
|
|
1005
516
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
517
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
518
|
+
for (const key in state) {
|
|
519
|
+
if (key === "style") {
|
|
520
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
521
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
522
|
+
element.style[k] = v;
|
|
523
|
+
} else {
|
|
524
|
+
throw new Error(
|
|
525
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
532
|
+
element.style[key] = state[key];
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (typeof element[key] === "function") {
|
|
536
|
+
element[key](element);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (key === "text") {
|
|
540
|
+
element.innerText = state[key];
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (key === "fullscreen") {
|
|
544
|
+
if (state[key]) {
|
|
545
|
+
fullScreen(element).set();
|
|
546
|
+
} else {
|
|
547
|
+
fullScreen(element).exist();
|
|
548
|
+
}
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
552
|
+
const classes = state[key].split(" ");
|
|
553
|
+
for (let i2 = 0; i2 < classes.length; i2++) {
|
|
554
|
+
if (classes[i2]) {
|
|
555
|
+
element.classList.add(classes[i2]);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
if (key === "toggleclass" && state[key] !== "") {
|
|
561
|
+
element.classList.toggle(state[key]);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (key === "removeclass" && state[key] !== "") {
|
|
565
|
+
element.classList.remove(state[key]);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (key === "remove") {
|
|
569
|
+
if (element.parentElement) {
|
|
570
|
+
(_a = element.parentElement) == null ? void 0 : _a.removeChild(element);
|
|
571
|
+
} else {
|
|
572
|
+
element.remove();
|
|
573
|
+
}
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
if (key.includes("$")) {
|
|
577
|
+
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (key === "tree") {
|
|
581
|
+
if (typeof state[key] === "function") {
|
|
582
|
+
state[key] = state[key]();
|
|
583
|
+
} else {
|
|
584
|
+
throw new TypeError(
|
|
585
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (typeof state[key] === "function") {
|
|
589
|
+
state[key] = state[key]();
|
|
590
|
+
}
|
|
591
|
+
if (Array.isArray(state[key])) {
|
|
592
|
+
throw new TypeError(
|
|
593
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
if (!(state[key] instanceof HTMLElement)) {
|
|
597
|
+
console.error(
|
|
598
|
+
" \u2718 Cradova err: wrong element type: can't update tree using " + state[key]
|
|
599
|
+
);
|
|
600
|
+
throw new TypeError(
|
|
601
|
+
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
element.innerHTML = "";
|
|
605
|
+
element.appendChild(state[key]);
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
if (typeof element[key] !== "undefined") {
|
|
610
|
+
element[key] = state[key];
|
|
611
|
+
} else {
|
|
612
|
+
element[key] = state[key];
|
|
613
|
+
if (key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
614
|
+
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
} catch (error) {
|
|
618
|
+
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
619
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
1014
620
|
}
|
|
1015
|
-
formData.set(k, value);
|
|
1016
621
|
}
|
|
622
|
+
} else {
|
|
623
|
+
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function dispatch(stateID, state) {
|
|
628
|
+
let ele;
|
|
629
|
+
if (stateID instanceof HTMLElement) {
|
|
630
|
+
ele = stateID;
|
|
631
|
+
}
|
|
632
|
+
let updated = void 0;
|
|
633
|
+
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
634
|
+
for (const [id, eachState] of Object.entries(stateID)) {
|
|
635
|
+
const elements = document.querySelectorAll(
|
|
636
|
+
"[data-cra-id=" + id + "]"
|
|
637
|
+
);
|
|
638
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
639
|
+
cradovaDispatchTrack(elements, eachState);
|
|
1017
640
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
641
|
+
} else {
|
|
642
|
+
if (typeof stateID === "string") {
|
|
643
|
+
const elements = document.querySelectorAll(
|
|
644
|
+
"[data-cra-id=" + stateID + "]"
|
|
1022
645
|
);
|
|
1023
|
-
if (
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
);
|
|
1029
|
-
} else {
|
|
1030
|
-
resolve(
|
|
1031
|
-
JSON.stringify({
|
|
1032
|
-
message: `problem with the action, please try again!`
|
|
1033
|
-
})
|
|
1034
|
-
);
|
|
646
|
+
if (elements.length) {
|
|
647
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
648
|
+
if (!(state == null ? void 0 : state.cradovaDispatchTrackBreak)) {
|
|
649
|
+
cradovaDispatchTrack(elements, state);
|
|
650
|
+
}
|
|
1035
651
|
}
|
|
1036
|
-
});
|
|
1037
|
-
if (!method) {
|
|
1038
|
-
ajax.open(data && typeof data === "object" ? "POST" : "GET", url, true);
|
|
1039
|
-
} else {
|
|
1040
|
-
ajax.open(method, url, true);
|
|
1041
652
|
}
|
|
1042
|
-
if (
|
|
1043
|
-
|
|
1044
|
-
ajax.setRequestHeader(key, header[key]);
|
|
1045
|
-
});
|
|
653
|
+
if (ele) {
|
|
654
|
+
cradovaDispatchTrack([ele], state);
|
|
1046
655
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
656
|
+
}
|
|
657
|
+
return updated;
|
|
1049
658
|
}
|
|
1050
659
|
|
|
1051
660
|
// lib/sacho/loadCss.ts
|
|
@@ -1153,99 +762,531 @@ function loadCradovaUICss(seconds = 0.3) {
|
|
|
1153
762
|
to {
|
|
1154
763
|
transform: scale(0);
|
|
1155
764
|
}
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
@keyframes scale-out {
|
|
1160
|
-
from {
|
|
1161
|
-
transform: scale(0);
|
|
1162
|
-
}
|
|
1163
|
-
to {
|
|
1164
|
-
transform: scale(1);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
@keyframes slide-right {
|
|
1169
|
-
from {
|
|
1170
|
-
margin-left: -140%;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
@keyframes scale-out {
|
|
769
|
+
from {
|
|
770
|
+
transform: scale(0);
|
|
771
|
+
}
|
|
772
|
+
to {
|
|
773
|
+
transform: scale(1);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
@keyframes slide-right {
|
|
778
|
+
from {
|
|
779
|
+
margin-left: -140%;
|
|
780
|
+
}
|
|
781
|
+
to {
|
|
782
|
+
margin-left: 0%;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
@keyframes slide-left {
|
|
787
|
+
from {
|
|
788
|
+
margin-left: 140%;
|
|
789
|
+
}
|
|
790
|
+
to {
|
|
791
|
+
margin-left: 0%;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
@keyframes slide-up {
|
|
796
|
+
from {
|
|
797
|
+
margin-top: 140%;
|
|
798
|
+
}
|
|
799
|
+
to {
|
|
800
|
+
margin-top: 0%;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
@keyframes slide-down {
|
|
805
|
+
from {
|
|
806
|
+
margin-top: -140%;
|
|
807
|
+
}
|
|
808
|
+
to {
|
|
809
|
+
margin-top: 0%;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
@keyframes fade-in {
|
|
814
|
+
from {
|
|
815
|
+
opacity: 0;
|
|
816
|
+
}
|
|
817
|
+
to {
|
|
818
|
+
opacity: 1;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
@keyframes fade-out {
|
|
823
|
+
from {
|
|
824
|
+
opacity: 1;
|
|
825
|
+
}
|
|
826
|
+
to {
|
|
827
|
+
opacity: 0;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/* ultility animations */
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
@keyframes fadeoff {
|
|
835
|
+
50%{
|
|
836
|
+
opacity: 0;
|
|
837
|
+
}
|
|
838
|
+
100% {
|
|
839
|
+
opacity: 0;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
@keyframes fadein {
|
|
844
|
+
0% {
|
|
845
|
+
opacity: 0;
|
|
846
|
+
}
|
|
847
|
+
70%{
|
|
848
|
+
opacity: 1;
|
|
849
|
+
}
|
|
850
|
+
100% {
|
|
851
|
+
opacity: 1;
|
|
852
|
+
}
|
|
853
|
+
} `;
|
|
854
|
+
const style = document.createElement("style");
|
|
855
|
+
style.innerHTML = css2;
|
|
856
|
+
document.head.appendChild(style);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// lib/scripts/Router.ts
|
|
860
|
+
var Router = {};
|
|
861
|
+
var RouterBox = {};
|
|
862
|
+
RouterBox["lastNavigatedRouteController"] = null;
|
|
863
|
+
RouterBox["nextRouteController"] = null;
|
|
864
|
+
RouterBox["lastNavigatedRoute"] = null;
|
|
865
|
+
RouterBox["pageShow"] = null;
|
|
866
|
+
RouterBox["pageHide"] = null;
|
|
867
|
+
RouterBox["errorHandler"] = {};
|
|
868
|
+
RouterBox["params"] = {};
|
|
869
|
+
RouterBox["routes"] = {};
|
|
870
|
+
var checker = (url) => {
|
|
871
|
+
if (RouterBox.routes[url]) {
|
|
872
|
+
return [RouterBox.routes[url], null];
|
|
873
|
+
}
|
|
874
|
+
for (const path in RouterBox.routes) {
|
|
875
|
+
if (!path.includes(":")) {
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
const urlFixtures = url.split("/");
|
|
879
|
+
const pathFixtures = path.split("/");
|
|
880
|
+
if (pathFixtures.length === urlFixtures.length) {
|
|
881
|
+
urlFixtures.shift();
|
|
882
|
+
pathFixtures.shift();
|
|
883
|
+
let isIt = true;
|
|
884
|
+
const routesParams = {};
|
|
885
|
+
for (let i = 0; i < pathFixtures.length; i++) {
|
|
886
|
+
if (!pathFixtures[i].includes(":") && path.includes(urlFixtures[i] + "/") && pathFixtures.indexOf(urlFixtures[i]) === pathFixtures.lastIndexOf(urlFixtures[i])) {
|
|
887
|
+
if (!isIt)
|
|
888
|
+
isIt = true;
|
|
889
|
+
} else {
|
|
890
|
+
if (pathFixtures[i].includes(":")) {
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
isIt = false;
|
|
894
|
+
}
|
|
895
|
+
if (!(pathFixtures.indexOf(urlFixtures[i]) === pathFixtures.lastIndexOf(urlFixtures[i]))) {
|
|
896
|
+
throw new Error(
|
|
897
|
+
" \u2718 Cradova err: cradova router doesn't allow paths with multiple names"
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (isIt) {
|
|
902
|
+
for (let i = 0; i < pathFixtures.length; i++) {
|
|
903
|
+
if (pathFixtures[i].includes(":")) {
|
|
904
|
+
routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
routesParams.path = path;
|
|
908
|
+
return [RouterBox.routes[path], routesParams];
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return [];
|
|
913
|
+
};
|
|
914
|
+
Router.route = function(path = "/", screen) {
|
|
915
|
+
if (!screen.Activate && screen.name) {
|
|
916
|
+
console.error(" \u2718 Cradova err: not a valid screen " + screen);
|
|
917
|
+
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
918
|
+
}
|
|
919
|
+
RouterBox.routes[path] = {
|
|
920
|
+
controller: (params, force) => screen.Activate(params, force),
|
|
921
|
+
packager: (params) => __async(this, null, function* () {
|
|
922
|
+
return yield screen.package(params);
|
|
923
|
+
}),
|
|
924
|
+
deactivate: () => {
|
|
925
|
+
screen.deActivate();
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
};
|
|
929
|
+
Router.navigate = function(href, data = null, force = false) {
|
|
930
|
+
if (typeof href !== "string") {
|
|
931
|
+
throw new TypeError(
|
|
932
|
+
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
if (typeof data === "boolean") {
|
|
936
|
+
force = true;
|
|
937
|
+
data = null;
|
|
938
|
+
}
|
|
939
|
+
let route = null, params, link = null;
|
|
940
|
+
if (href.includes("://")) {
|
|
941
|
+
window.location.href = href;
|
|
942
|
+
} else {
|
|
943
|
+
if (href === window.location.pathname) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
[route, params] = checker(href);
|
|
947
|
+
if (route) {
|
|
948
|
+
RouterBox["nextRouteController"] = route;
|
|
949
|
+
RouterBox.params.params = params || null;
|
|
950
|
+
RouterBox.params.data = data || null;
|
|
951
|
+
link = href;
|
|
952
|
+
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
953
|
+
window.history.pushState({}, "", link);
|
|
954
|
+
(() => __async(this, null, function* () {
|
|
955
|
+
yield RouterBox.router(null, force);
|
|
956
|
+
}))();
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
RouterBox.router = function(e, force = false) {
|
|
961
|
+
return __async(this, null, function* () {
|
|
962
|
+
let url, route, params;
|
|
963
|
+
const Alink = e && e.target.tagName === "A" && e.target;
|
|
964
|
+
if (Alink) {
|
|
965
|
+
if (Alink.href.includes("#")) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (Alink.href.includes("javascript")) {
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
e.preventDefault();
|
|
972
|
+
url = new URL(Alink.href).pathname;
|
|
973
|
+
}
|
|
974
|
+
if (!url) {
|
|
975
|
+
url = window.location.pathname;
|
|
976
|
+
}
|
|
977
|
+
if (url === Router["lastNavigatedRoute"]) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
if (RouterBox["nextRouteController"]) {
|
|
981
|
+
route = RouterBox["nextRouteController"];
|
|
982
|
+
RouterBox["nextRouteController"] = null;
|
|
983
|
+
params = RouterBox.params.params;
|
|
984
|
+
RouterBox.params.params = null;
|
|
985
|
+
} else {
|
|
986
|
+
[route, params] = checker(url);
|
|
987
|
+
}
|
|
988
|
+
if (route) {
|
|
989
|
+
try {
|
|
990
|
+
RouterBox.params.event = e;
|
|
991
|
+
RouterBox.params.params = params || RouterBox.params.params || null;
|
|
992
|
+
RouterBox.params.data = RouterBox.params.data || null;
|
|
993
|
+
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
|
|
994
|
+
yield route.controller(force);
|
|
995
|
+
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
996
|
+
RouterBox["lastNavigatedRoute"] = url;
|
|
997
|
+
RouterBox["lastNavigatedRouteController"] = route;
|
|
998
|
+
RouterBox.params.params = null;
|
|
999
|
+
Array.from(window.document.querySelectorAll("a")).forEach((a) => {
|
|
1000
|
+
if (a.href.includes(window.location.origin)) {
|
|
1001
|
+
a.addEventListener("click", (e2) => {
|
|
1002
|
+
e2.preventDefault();
|
|
1003
|
+
Router.navigate(a.pathname);
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
1009
|
+
if (errorHandler) {
|
|
1010
|
+
errorHandler(error);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
} else {
|
|
1014
|
+
if (RouterBox.routes["/404"]) {
|
|
1015
|
+
RouterBox.routes["/404"].controller(RouterBox.params);
|
|
1016
|
+
} else {
|
|
1017
|
+
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
1018
|
+
if (errorHandler) {
|
|
1019
|
+
errorHandler(
|
|
1020
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
1021
|
+
);
|
|
1022
|
+
} else {
|
|
1023
|
+
console.error(
|
|
1024
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
};
|
|
1031
|
+
Router["onPageShow"] = function(callback) {
|
|
1032
|
+
if (typeof callback === "function") {
|
|
1033
|
+
RouterBox["pageShow"] = callback;
|
|
1034
|
+
} else {
|
|
1035
|
+
throw new Error(
|
|
1036
|
+
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
Router["onPageHide"] = function(callback) {
|
|
1041
|
+
if (typeof callback === "function") {
|
|
1042
|
+
RouterBox["pageHide"] = callback;
|
|
1043
|
+
} else {
|
|
1044
|
+
throw new Error(
|
|
1045
|
+
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
1046
|
+
);
|
|
1171
1047
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1048
|
+
};
|
|
1049
|
+
Router.packageScreen = function(path, data) {
|
|
1050
|
+
return __async(this, null, function* () {
|
|
1051
|
+
if (!RouterBox.routes[path]) {
|
|
1052
|
+
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
1053
|
+
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
1054
|
+
}
|
|
1055
|
+
yield RouterBox.routes[path].packager(data);
|
|
1056
|
+
});
|
|
1057
|
+
};
|
|
1058
|
+
Router.getParams = function() {
|
|
1059
|
+
return RouterBox["params"];
|
|
1060
|
+
};
|
|
1061
|
+
Router["addErrorHandler"] = function(callback, path) {
|
|
1062
|
+
if (typeof callback === "function") {
|
|
1063
|
+
RouterBox["errorHandler"][path || "all"] = callback;
|
|
1064
|
+
} else {
|
|
1065
|
+
throw new Error(
|
|
1066
|
+
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
1067
|
+
);
|
|
1174
1068
|
}
|
|
1175
|
-
}
|
|
1069
|
+
};
|
|
1070
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
1071
|
+
window.addEventListener("popstate", (e) => {
|
|
1072
|
+
e.preventDefault();
|
|
1073
|
+
RouterBox.router();
|
|
1074
|
+
});
|
|
1176
1075
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1076
|
+
// lib/scripts/Screen.ts
|
|
1077
|
+
var Screen = class {
|
|
1078
|
+
constructor(cradova_screen_initials) {
|
|
1079
|
+
this.packed = false;
|
|
1080
|
+
this.secondaryChildren = [];
|
|
1081
|
+
this.template = document.createElement("div");
|
|
1082
|
+
this.persist = true;
|
|
1083
|
+
this.rendered = false;
|
|
1084
|
+
this.hasFirstStateUpdateRun = false;
|
|
1085
|
+
this.effects = [];
|
|
1086
|
+
this.effectuate = null;
|
|
1087
|
+
const { template, name, transition, persist } = cradova_screen_initials;
|
|
1088
|
+
if (typeof template !== "function") {
|
|
1089
|
+
throw new Error(
|
|
1090
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
this.html = template.bind(this);
|
|
1094
|
+
this.name = name;
|
|
1095
|
+
this.template.id = "cradova-screen-set";
|
|
1096
|
+
this.transition = transition;
|
|
1097
|
+
if (typeof persist === "boolean") {
|
|
1098
|
+
this.persist = persist;
|
|
1099
|
+
}
|
|
1180
1100
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1101
|
+
effect(fn) {
|
|
1102
|
+
if (!this.rendered) {
|
|
1103
|
+
this.effects.push(fn);
|
|
1104
|
+
}
|
|
1183
1105
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1106
|
+
effector() {
|
|
1107
|
+
return __async(this, null, function* () {
|
|
1108
|
+
if (!this.rendered) {
|
|
1109
|
+
for (const effect of this.effects) {
|
|
1110
|
+
yield effect.apply(this);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
1114
|
+
this.hasFirstStateUpdateRun = true;
|
|
1115
|
+
yield this.effectuate();
|
|
1116
|
+
}
|
|
1117
|
+
this.rendered = true;
|
|
1118
|
+
});
|
|
1189
1119
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1120
|
+
updateState(data) {
|
|
1121
|
+
if (!this.rendered) {
|
|
1122
|
+
function updateState(data2) {
|
|
1123
|
+
return __async(this, null, function* () {
|
|
1124
|
+
this.data = data2;
|
|
1125
|
+
yield this.Activate(true);
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
this.effectuate = updateState.bind(this, data);
|
|
1129
|
+
} else {
|
|
1130
|
+
(() => __async(this, null, function* () {
|
|
1131
|
+
this.data = data;
|
|
1132
|
+
yield this.Activate(true);
|
|
1133
|
+
})).bind(this)();
|
|
1134
|
+
}
|
|
1192
1135
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1136
|
+
package() {
|
|
1137
|
+
return __async(this, null, function* () {
|
|
1138
|
+
if (typeof this.html === "function") {
|
|
1139
|
+
let fuc = yield this.html(this.data);
|
|
1140
|
+
if (typeof fuc === "function") {
|
|
1141
|
+
fuc = fuc();
|
|
1142
|
+
if (!(fuc instanceof HTMLElement)) {
|
|
1143
|
+
throw new Error(
|
|
1144
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1145
|
+
);
|
|
1146
|
+
} else {
|
|
1147
|
+
if (this.transition) {
|
|
1148
|
+
this.template.classList.add("CRADOVA-UI-" + this.transition);
|
|
1149
|
+
}
|
|
1150
|
+
this.template.innerHTML = "";
|
|
1151
|
+
this.template.appendChild(fuc);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if (!this.template.firstChild) {
|
|
1156
|
+
throw new Error(
|
|
1157
|
+
" \u2718 Cradova err: no screen is rendered, may have been past wrongly."
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
if (this.secondaryChildren.length) {
|
|
1161
|
+
this.template.append(this.secondaryChildren);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1198
1164
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1165
|
+
onActivate(cb) {
|
|
1166
|
+
this.callBack = cb;
|
|
1201
1167
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
@keyframes fade-in {
|
|
1205
|
-
from {
|
|
1206
|
-
opacity: 0;
|
|
1168
|
+
addChild(...addOns) {
|
|
1169
|
+
this.secondaryChildren.push(frag(...addOns));
|
|
1207
1170
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1171
|
+
deActivate() {
|
|
1172
|
+
if (this.transition) {
|
|
1173
|
+
this.template.classList.remove("CRADOVA-UI-" + this.transition);
|
|
1174
|
+
}
|
|
1175
|
+
if (!this.persist) {
|
|
1176
|
+
this.rendered = false;
|
|
1177
|
+
}
|
|
1210
1178
|
}
|
|
1211
|
-
|
|
1179
|
+
Activate(force) {
|
|
1180
|
+
return __async(this, null, function* () {
|
|
1181
|
+
if (!this.persist) {
|
|
1182
|
+
yield this.package();
|
|
1183
|
+
this.packed = true;
|
|
1184
|
+
} else {
|
|
1185
|
+
if (!this.packed) {
|
|
1186
|
+
yield this.package();
|
|
1187
|
+
this.packed = true;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (this.persist && force) {
|
|
1191
|
+
yield this.package();
|
|
1192
|
+
this.packed = true;
|
|
1193
|
+
}
|
|
1194
|
+
document.title = this.name;
|
|
1195
|
+
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
1196
|
+
if (!doc) {
|
|
1197
|
+
throw new Error(
|
|
1198
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
doc.innerHTML = "";
|
|
1202
|
+
doc.appendChild(this.template);
|
|
1203
|
+
if (!this.persist) {
|
|
1204
|
+
this.packed = false;
|
|
1205
|
+
}
|
|
1206
|
+
yield this.effector();
|
|
1207
|
+
if (this.callBack) {
|
|
1208
|
+
yield this.callBack();
|
|
1209
|
+
}
|
|
1210
|
+
window.dispatchEvent(cradovaAftermountEvent);
|
|
1211
|
+
window.scrollTo(0, 0);
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
Screen.SCALE_IN = "SCALE-IN";
|
|
1216
|
+
Screen.SCALE_OUT = "SCALE-OUT";
|
|
1217
|
+
Screen.CIRCLE_IN = "CIRCLE-IN";
|
|
1218
|
+
Screen.CIRCLE_OUT = "CIRCLE-OUT";
|
|
1219
|
+
Screen.FADE_OUT = "FADE-OUT";
|
|
1220
|
+
Screen.FADE_IN = "FADE-IN";
|
|
1221
|
+
Screen.SLIDE_UP = "SLIDE-UP";
|
|
1222
|
+
Screen.SLIDE_DOWN = "SLIDE-DOWN";
|
|
1223
|
+
Screen.SLIDE_LEFT = "SLIDE-LEFT";
|
|
1224
|
+
Screen.SLIDE_RIGHT = "SLIDE-RIGHT";
|
|
1212
1225
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1226
|
+
// lib/scripts/simplestore.ts
|
|
1227
|
+
var simpleStore = class {
|
|
1228
|
+
constructor(initial) {
|
|
1229
|
+
this.ref = [];
|
|
1230
|
+
this.value = null;
|
|
1231
|
+
this.value = initial;
|
|
1216
1232
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1233
|
+
set(value, shouldRefRender) {
|
|
1234
|
+
if (typeof value === "function") {
|
|
1235
|
+
this.value = value(this.value);
|
|
1236
|
+
} else {
|
|
1237
|
+
this.value = value;
|
|
1238
|
+
}
|
|
1239
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
1240
|
+
this.updateState();
|
|
1241
|
+
}
|
|
1219
1242
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1243
|
+
bind(prop) {
|
|
1244
|
+
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
1245
|
+
return [this, prop];
|
|
1246
|
+
} else {
|
|
1247
|
+
throw new Error(
|
|
1248
|
+
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1228
1251
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1252
|
+
updateState(name) {
|
|
1253
|
+
if (name) {
|
|
1254
|
+
const entry = this.ref.find((ent) => ent.prop === name);
|
|
1255
|
+
if (entry) {
|
|
1256
|
+
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
for (let i = 0; i < this.ref.length; i++) {
|
|
1260
|
+
const entry = this.ref[i];
|
|
1261
|
+
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1231
1264
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1265
|
+
setKey(name, value, shouldRefRender) {
|
|
1266
|
+
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
1267
|
+
if (typeof value === "function") {
|
|
1268
|
+
this.value[name] = value(this.value);
|
|
1269
|
+
} else {
|
|
1270
|
+
this.value[name] = value;
|
|
1271
|
+
}
|
|
1272
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
1273
|
+
this.updateState(name);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1240
1276
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1277
|
+
bindRef(ref, key, prop) {
|
|
1278
|
+
if (ref && ref.updateState && prop) {
|
|
1279
|
+
this.ref.push({ prop, ref, key });
|
|
1280
|
+
if (ref.reader) {
|
|
1281
|
+
ref.render = ref.render.bind(ref, this.value);
|
|
1282
|
+
}
|
|
1283
|
+
} else {
|
|
1284
|
+
throw new Error(
|
|
1285
|
+
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1243
1288
|
}
|
|
1244
|
-
}
|
|
1245
|
-
const style = document.createElement("style");
|
|
1246
|
-
style.innerHTML = css2;
|
|
1247
|
-
document.head.appendChild(style);
|
|
1248
|
-
}
|
|
1289
|
+
};
|
|
1249
1290
|
|
|
1250
1291
|
// lib/scripts/init.ts
|
|
1251
1292
|
var Init = function() {
|