cradova 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +647 -59
- package/dist/index.js +1540 -382
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,407 +1,1565 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// lib/utils/init.ts
|
|
2
|
+
var Init = function() {
|
|
3
|
+
if (!document.querySelector("[data-cra-id=cradova-app-wrapper]")) {
|
|
4
|
+
const Wrapper = document.createElement("div");
|
|
5
|
+
Wrapper.setAttribute("data-cra-id", "cradova-app-wrapper");
|
|
6
|
+
document.body.appendChild(Wrapper);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
3
9
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
// lib/utils/fns.ts
|
|
11
|
+
var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
|
|
12
|
+
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
13
|
+
function uuid() {
|
|
14
|
+
let t = Date.now ? +Date.now() : +new Date();
|
|
15
|
+
return "cradova-id-xxxxxxxxxx".replace(/[x]/g, function(e) {
|
|
16
|
+
const r = (t + 16 * Math.random()) % 16 | 0;
|
|
17
|
+
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function Rhoda(l) {
|
|
21
|
+
const fg = new DocumentFragment();
|
|
22
|
+
for (let ch of l) {
|
|
23
|
+
if (Array.isArray(ch)) {
|
|
24
|
+
fg.appendChild(Rhoda(ch));
|
|
25
|
+
} else {
|
|
26
|
+
if (typeof ch === "function") {
|
|
27
|
+
ch = ch();
|
|
28
|
+
}
|
|
29
|
+
if (typeof ch === "function") {
|
|
30
|
+
ch = ch();
|
|
31
|
+
}
|
|
32
|
+
if (typeof ch === "string" || typeof ch === "number") {
|
|
33
|
+
fg.appendChild(document.createTextNode(ch));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (isNode(ch)) {
|
|
37
|
+
fg.appendChild(ch);
|
|
38
|
+
} else {
|
|
39
|
+
if (typeof ch !== "undefined") {
|
|
40
|
+
throw new Error(
|
|
41
|
+
" \u2718 Cradova err: invalid child type: " + ch + " (" + typeof ch + ")"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return fg;
|
|
48
|
+
}
|
|
49
|
+
function css(identifier, properties) {
|
|
50
|
+
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
51
|
+
let styTag = document.querySelector("style");
|
|
52
|
+
if (styTag !== null) {
|
|
53
|
+
identifier += styTag.textContent;
|
|
54
|
+
styTag.textContent = identifier;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
styTag = document.createElement("style");
|
|
58
|
+
styTag.textContent = identifier;
|
|
59
|
+
document.head.appendChild(styTag);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!properties) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const styS = "" + identifier + `{
|
|
66
|
+
`;
|
|
67
|
+
const styE = `}
|
|
68
|
+
`;
|
|
69
|
+
let style2 = "", totalStyle = "";
|
|
70
|
+
for (const [k, v] of Object.entries(properties)) {
|
|
71
|
+
style2 += "" + k + ": " + v + `;
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
let styleTag = document.querySelector("style");
|
|
75
|
+
if (styleTag !== null) {
|
|
76
|
+
totalStyle += styleTag.innerHTML;
|
|
77
|
+
totalStyle += styS + style2 + styE;
|
|
78
|
+
styleTag.innerHTML = totalStyle;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
styleTag = document.createElement("style");
|
|
82
|
+
totalStyle += styleTag.innerHTML + `
|
|
10
83
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
84
|
+
`;
|
|
85
|
+
totalStyle += styS + style2 + styE;
|
|
86
|
+
styleTag.innerHTML = totalStyle;
|
|
87
|
+
document.head.appendChild(styleTag);
|
|
88
|
+
}
|
|
89
|
+
function assert(condition, ...elements) {
|
|
90
|
+
if (condition) {
|
|
91
|
+
return elements;
|
|
92
|
+
}
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
function loop(datalist2, component) {
|
|
96
|
+
if (typeof component !== "function") {
|
|
97
|
+
throw new Error(
|
|
98
|
+
" \u2718 Cradova err : Invalid component type, must be a function that returns html "
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return Array.isArray(datalist2) ? datalist2.map(component) : void 0;
|
|
102
|
+
}
|
|
103
|
+
function assertOr(condition, ifTrue, ifFalse) {
|
|
104
|
+
if (condition) {
|
|
105
|
+
return ifTrue;
|
|
106
|
+
}
|
|
107
|
+
return ifFalse;
|
|
108
|
+
}
|
|
109
|
+
var Ref = class {
|
|
110
|
+
constructor(component) {
|
|
111
|
+
this.stateID = uuid();
|
|
112
|
+
this.effects = [];
|
|
113
|
+
this.effectuate = null;
|
|
114
|
+
this.rendered = false;
|
|
115
|
+
this.published = false;
|
|
116
|
+
this.hasFirstStateUpdateRun = false;
|
|
117
|
+
this.preRendered = null;
|
|
118
|
+
this.component = component.bind(this);
|
|
119
|
+
}
|
|
120
|
+
preRender(data2) {
|
|
121
|
+
const chtml = this.component(data2);
|
|
122
|
+
if (chtml instanceof HTMLElement) {
|
|
123
|
+
chtml.setAttribute("data-cra-id", this.stateID);
|
|
124
|
+
this.preRendered = chtml;
|
|
125
|
+
} else {
|
|
126
|
+
this.preRendered = chtml({ stateID: this.stateID });
|
|
127
|
+
}
|
|
128
|
+
if (typeof this.preRendered === "undefined") {
|
|
129
|
+
throw new Error(
|
|
130
|
+
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + this.preRendered
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
destroyPreRendered() {
|
|
135
|
+
this.preRendered = null;
|
|
136
|
+
}
|
|
137
|
+
render(data2, stash) {
|
|
138
|
+
this.effects = [];
|
|
139
|
+
this.rendered = false;
|
|
140
|
+
this.hasFirstStateUpdateRun = false;
|
|
141
|
+
let element = null;
|
|
142
|
+
if (!this.preRendered) {
|
|
143
|
+
const chtml = this.component(data2);
|
|
144
|
+
if (chtml instanceof HTMLElement) {
|
|
145
|
+
chtml.setAttribute("data-cra-id", this.stateID);
|
|
146
|
+
element = chtml;
|
|
147
|
+
} else {
|
|
148
|
+
element = chtml({ stateID: this.stateID });
|
|
149
|
+
}
|
|
150
|
+
if (typeof element === "undefined") {
|
|
151
|
+
throw new Error(
|
|
152
|
+
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (stash) {
|
|
157
|
+
this.stash = data2;
|
|
158
|
+
}
|
|
159
|
+
const av = async () => {
|
|
160
|
+
await this.effector.apply(this);
|
|
161
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
162
|
+
};
|
|
163
|
+
if (!this.published) {
|
|
164
|
+
this.published = true;
|
|
165
|
+
window.addEventListener("cradova-aftermount", av);
|
|
166
|
+
} else {
|
|
167
|
+
this.effector();
|
|
168
|
+
}
|
|
169
|
+
if (!element) {
|
|
170
|
+
element = this.preRendered;
|
|
171
|
+
}
|
|
172
|
+
return element;
|
|
173
|
+
}
|
|
174
|
+
instance() {
|
|
175
|
+
return dispatch(this.stateID, {
|
|
176
|
+
cradovaDispatchTrackBreak: true
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
effect(fn) {
|
|
180
|
+
if (!this.rendered) {
|
|
181
|
+
this.effects.push(fn.bind(this));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async effector() {
|
|
185
|
+
if (!this.rendered) {
|
|
186
|
+
for (const effect of this.effects) {
|
|
187
|
+
await effect.apply(this);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
191
|
+
await this.effectuate();
|
|
192
|
+
}
|
|
193
|
+
this.rendered = true;
|
|
194
|
+
this.hasFirstStateUpdateRun = true;
|
|
195
|
+
}
|
|
196
|
+
updateState(data2, stash) {
|
|
197
|
+
if (!this) {
|
|
198
|
+
console.error(
|
|
199
|
+
" \u2718 Cradova err: Ref.updateState has is passed out of scope"
|
|
200
|
+
);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!this.rendered) {
|
|
204
|
+
async function updateState(data3) {
|
|
205
|
+
await this.Activate(data3);
|
|
206
|
+
}
|
|
207
|
+
this.effectuate = updateState.bind(this, data2);
|
|
208
|
+
} else {
|
|
209
|
+
(async () => {
|
|
210
|
+
await this.Activate(data2);
|
|
211
|
+
})();
|
|
212
|
+
}
|
|
213
|
+
if (stash) {
|
|
214
|
+
this.stash = data2;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async Activate(data2) {
|
|
218
|
+
if (!data2) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const guy = dispatch(this.stateID, {
|
|
222
|
+
cradovaDispatchTrackBreak: true
|
|
223
|
+
});
|
|
224
|
+
if (!guy) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const chtml = this.component(data2);
|
|
228
|
+
let element;
|
|
229
|
+
if (chtml instanceof HTMLElement) {
|
|
230
|
+
chtml.setAttribute("data-cra-id", this.stateID);
|
|
231
|
+
element = chtml;
|
|
232
|
+
} else {
|
|
233
|
+
element = chtml({ stateID: this.stateID });
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
guy.insertAdjacentElement("beforebegin", element);
|
|
237
|
+
if (guy.parentElement) {
|
|
238
|
+
guy.parentElement.removeChild(guy);
|
|
239
|
+
} else {
|
|
240
|
+
guy.remove();
|
|
241
|
+
}
|
|
242
|
+
} catch (e0) {
|
|
243
|
+
console.error(e0);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
remove() {
|
|
247
|
+
dispatch(this.stateID, { remove: true });
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var frag = function(children) {
|
|
251
|
+
const par = document.createDocumentFragment();
|
|
252
|
+
for (let i2 = 0; i2 < children.length; i2++) {
|
|
253
|
+
let a2 = children[i2];
|
|
254
|
+
if (typeof a2 === "function") {
|
|
255
|
+
a2 = a2();
|
|
256
|
+
if (typeof a2 === "function") {
|
|
257
|
+
a2 = a2();
|
|
258
|
+
}
|
|
259
|
+
if (isNode(a2) || a2 instanceof String) {
|
|
260
|
+
par.appendChild(a2);
|
|
261
|
+
} else {
|
|
262
|
+
console.error(" \u2718 Cradova err: wrong element type" + a2);
|
|
263
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return par;
|
|
268
|
+
};
|
|
269
|
+
var svgNS = (type, props, ...children) => {
|
|
270
|
+
const sc = document.createElementNS(
|
|
271
|
+
props.xmlns || "http://www.w3.org/2000/svg",
|
|
272
|
+
type
|
|
273
|
+
);
|
|
274
|
+
delete props.xmlns;
|
|
275
|
+
for (const p2 in props) {
|
|
276
|
+
sc.setAttributeNS(null, p2, props[p2]);
|
|
277
|
+
}
|
|
278
|
+
for (let ch of children) {
|
|
279
|
+
if (typeof ch === "function") {
|
|
280
|
+
ch = ch();
|
|
281
|
+
}
|
|
282
|
+
if (typeof ch === "function") {
|
|
283
|
+
ch = ch();
|
|
284
|
+
}
|
|
285
|
+
sc.appendChild(ch);
|
|
286
|
+
}
|
|
287
|
+
return sc;
|
|
288
|
+
};
|
|
19
289
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
import { Init } from "./utils/init";
|
|
38
|
-
import { dispatch } from "./utils/track";
|
|
39
|
-
import { simpleStore } from "./utils/simplestore";
|
|
40
|
-
import { frag, isNode } from "./utils/fns";
|
|
41
|
-
// import doc from "./utils/document";
|
|
42
|
-
// importing types declarations
|
|
43
|
-
("use strict");
|
|
44
|
-
const make = function (txx) {
|
|
45
|
-
if (!txx) {
|
|
46
|
-
return {
|
|
47
|
-
tag: "div",
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
let tag;
|
|
51
|
-
let innerValue = "";
|
|
52
|
-
if (txx.includes("|")) {
|
|
53
|
-
const tc = txx.split("|");
|
|
54
|
-
innerValue = tc[1];
|
|
55
|
-
txx = tc[0] && tc[0];
|
|
56
|
-
}
|
|
57
|
-
const itemsPurifier = () => {
|
|
58
|
-
if (!txx.includes("#")) {
|
|
59
|
-
txx = txx.split(".");
|
|
60
|
-
tag = txx[0];
|
|
61
|
-
if (tag) {
|
|
62
|
-
txx.shift();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
tag = "div";
|
|
290
|
+
// lib/utils/track.ts
|
|
291
|
+
function cradovaDispatchTrack(nodes, state) {
|
|
292
|
+
for (let i2 = 0; i2 < nodes.length; i2++) {
|
|
293
|
+
const element = nodes[i2];
|
|
294
|
+
if (!element) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
298
|
+
for (const key in state) {
|
|
299
|
+
if (key === "style") {
|
|
300
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
301
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
302
|
+
element.style[k] = v;
|
|
303
|
+
} else {
|
|
304
|
+
throw new Error(
|
|
305
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
306
|
+
);
|
|
66
307
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
308
|
+
}
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
312
|
+
element.style[key] = state[key];
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (typeof element[key] === "function") {
|
|
316
|
+
element[key].apply(element);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (key === "text") {
|
|
320
|
+
element.innerText = state[key];
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
324
|
+
const classes = state[key].split(" ");
|
|
325
|
+
for (let i3 = 0; i3 < classes.length; i3++) {
|
|
326
|
+
if (classes[i3]) {
|
|
327
|
+
element.classList.add(classes[i3]);
|
|
83
328
|
}
|
|
329
|
+
}
|
|
330
|
+
continue;
|
|
84
331
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
332
|
+
if (key === "remove") {
|
|
333
|
+
if (element.parentElement) {
|
|
334
|
+
element.parentElement?.removeChild(element);
|
|
335
|
+
} else {
|
|
336
|
+
element.remove();
|
|
337
|
+
}
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (key.includes("$")) {
|
|
341
|
+
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (key === "tree") {
|
|
345
|
+
element.innerHTML = "";
|
|
346
|
+
element.appendChild(frag(state[key]));
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
if (typeof element[key] !== "undefined") {
|
|
351
|
+
element[key] = state[key];
|
|
352
|
+
} else {
|
|
353
|
+
element[key] = state[key];
|
|
354
|
+
if (key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
355
|
+
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
102
356
|
}
|
|
103
|
-
|
|
357
|
+
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
360
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
104
361
|
}
|
|
105
|
-
|
|
106
|
-
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function dispatch(stateID, state) {
|
|
369
|
+
let ele;
|
|
370
|
+
if (stateID instanceof HTMLElement) {
|
|
371
|
+
ele = stateID;
|
|
372
|
+
}
|
|
373
|
+
let updated = void 0;
|
|
374
|
+
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
375
|
+
for (const [id, eachState] of Object.entries(stateID)) {
|
|
376
|
+
const elements = document.querySelectorAll(
|
|
377
|
+
"[data-cra-id=" + id + "]"
|
|
378
|
+
);
|
|
379
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
380
|
+
cradovaDispatchTrack(elements, eachState);
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
if (typeof stateID === "string") {
|
|
384
|
+
const elements = document.querySelectorAll(
|
|
385
|
+
"[data-cra-id=" + stateID + "]"
|
|
386
|
+
);
|
|
387
|
+
if (elements.length) {
|
|
388
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
389
|
+
if (!state?.cradovaDispatchTrackBreak) {
|
|
390
|
+
cradovaDispatchTrack(elements, state);
|
|
107
391
|
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (ele) {
|
|
395
|
+
cradovaDispatchTrack([ele], state);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return updated;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// lib/utils/simplestore.ts
|
|
402
|
+
var simpleStore = class {
|
|
403
|
+
constructor(initial) {
|
|
404
|
+
this.ref = [];
|
|
405
|
+
this.value = initial;
|
|
406
|
+
}
|
|
407
|
+
set(value, shouldRefRender) {
|
|
408
|
+
if (typeof value === "function") {
|
|
409
|
+
this.value = value(this.value);
|
|
410
|
+
} else {
|
|
411
|
+
this.value = value;
|
|
412
|
+
}
|
|
413
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
414
|
+
this.updateState();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
bind(prop) {
|
|
418
|
+
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
419
|
+
return [this, prop];
|
|
420
|
+
} else {
|
|
421
|
+
throw new Error(
|
|
422
|
+
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
updateState(name) {
|
|
427
|
+
if (name) {
|
|
428
|
+
const entry = this.ref.find((ent) => ent.prop === name);
|
|
429
|
+
if (entry) {
|
|
430
|
+
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
for (let i2 = 0; i2 < this.ref.length; i2++) {
|
|
434
|
+
const entry = this.ref[i2];
|
|
435
|
+
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
setKey(name, value, shouldRefRender) {
|
|
440
|
+
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
441
|
+
if (typeof value === "function") {
|
|
442
|
+
this.value[name] = value(this.value);
|
|
443
|
+
} else {
|
|
444
|
+
this.value[name] = value;
|
|
445
|
+
}
|
|
446
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
447
|
+
this.updateState(name);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
_bindRef(ref, key, prop) {
|
|
452
|
+
if (ref && ref.updateState && prop) {
|
|
453
|
+
this.ref.push({ prop, ref, key });
|
|
454
|
+
if (ref.reader) {
|
|
455
|
+
ref.render = ref.render.bind(ref, this.value);
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
throw new Error(
|
|
459
|
+
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
114
463
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* _("p",{
|
|
130
|
-
* text: "am a p tag",
|
|
131
|
-
* style: {
|
|
132
|
-
* color: "blue"
|
|
133
|
-
* }
|
|
134
|
-
* })
|
|
135
|
-
* // or no style props it works!
|
|
136
|
-
* _("p",{
|
|
137
|
-
* text: "am a p tag",
|
|
138
|
-
* color: "blue"
|
|
139
|
-
* })
|
|
140
|
-
*
|
|
141
|
-
* // props and children
|
|
142
|
-
* _("p", // template first
|
|
143
|
-
* // property next if wanted
|
|
144
|
-
* {style: {color: "brown"}, // optional
|
|
145
|
-
* // the rest should be children or text
|
|
146
|
-
* _("span", " am a span tag text like so"),
|
|
147
|
-
* ...
|
|
148
|
-
* )
|
|
149
|
-
*
|
|
150
|
-
* // list of children
|
|
151
|
-
* _("p",
|
|
152
|
-
* // all children goes after
|
|
153
|
-
* _("span",
|
|
154
|
-
* {
|
|
155
|
-
* text:" am a span tag like so",
|
|
156
|
-
* color: "brown",
|
|
157
|
-
* }),
|
|
158
|
-
* ...
|
|
159
|
-
* )
|
|
160
|
-
*
|
|
161
|
-
* @param {...any[]} element_initials
|
|
162
|
-
* @returns function - cradova element
|
|
163
|
-
*/
|
|
164
|
-
const _ = (...element_initials) => {
|
|
165
|
-
//
|
|
166
|
-
if (typeof element_initials[0] !== "string") {
|
|
167
|
-
return frag(element_initials);
|
|
168
|
-
}
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
if (element_initials.raw) {
|
|
171
|
-
// getting the value of static cradova calls
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
element_initials[0] = element_initials["raw"][0];
|
|
174
|
-
}
|
|
175
|
-
let beforeMount = null, firstLevelChildren = [];
|
|
176
|
-
if (element_initials.length > 1) {
|
|
177
|
-
firstLevelChildren = element_initials.splice(1);
|
|
178
|
-
}
|
|
179
|
-
if (typeof element_initials !== "object") {
|
|
180
|
-
element_initials = [element_initials];
|
|
181
|
-
}
|
|
182
|
-
return (...ElementChildrenAndPropertyList) => {
|
|
183
|
-
const initials = make(element_initials[0]);
|
|
184
|
-
let props = null, text = null;
|
|
185
|
-
if (firstLevelChildren.length) {
|
|
186
|
-
ElementChildrenAndPropertyList.push(...firstLevelChildren);
|
|
187
|
-
}
|
|
188
|
-
let element;
|
|
189
|
-
try {
|
|
190
|
-
element = document.createElement(initials.tag.trim());
|
|
464
|
+
|
|
465
|
+
// lib/utils/ajax.ts
|
|
466
|
+
function Ajax(url, opts = {}) {
|
|
467
|
+
const { method, data: data2, header: header2, callbacks } = opts;
|
|
468
|
+
if (typeof url !== "string") {
|
|
469
|
+
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
470
|
+
}
|
|
471
|
+
return new Promise(function(resolve) {
|
|
472
|
+
const ajax = new XMLHttpRequest();
|
|
473
|
+
const formData = new FormData();
|
|
474
|
+
if (callbacks && typeof callbacks === "object") {
|
|
475
|
+
for (const [k, v] of Object.entries(callbacks)) {
|
|
476
|
+
if (typeof v === "function" && ajax[k]) {
|
|
477
|
+
ajax[k] = v;
|
|
191
478
|
}
|
|
192
|
-
|
|
193
|
-
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
ajax.addEventListener("load", function() {
|
|
482
|
+
resolve(ajax.response);
|
|
483
|
+
});
|
|
484
|
+
if (data2 && typeof data2 === "object") {
|
|
485
|
+
for (const [k, v] of Object.entries(data2)) {
|
|
486
|
+
let value = v;
|
|
487
|
+
if (typeof value === "object" && value && !value.name) {
|
|
488
|
+
value = JSON.stringify(value);
|
|
194
489
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
490
|
+
formData.set(k, value);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
ajax.addEventListener("error", () => {
|
|
494
|
+
console.error(
|
|
495
|
+
"\u2718 Cradova Ajax err : ",
|
|
496
|
+
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
497
|
+
);
|
|
498
|
+
if (!navigator.onLine) {
|
|
499
|
+
resolve(
|
|
500
|
+
JSON.stringify({
|
|
501
|
+
message: `the device is offline!`
|
|
502
|
+
})
|
|
503
|
+
);
|
|
504
|
+
} else {
|
|
505
|
+
resolve(
|
|
506
|
+
JSON.stringify({
|
|
507
|
+
message: `problem with the action, please try again!`
|
|
508
|
+
})
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
if (!method) {
|
|
513
|
+
ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
|
|
514
|
+
} else {
|
|
515
|
+
ajax.open(method, url, true);
|
|
516
|
+
}
|
|
517
|
+
if (header2 && typeof header2 === "object") {
|
|
518
|
+
Object.keys(header2).forEach(function(key) {
|
|
519
|
+
ajax.setRequestHeader(key, header2[key]);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
ajax.send(formData);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// lib/utils/createSignal.ts
|
|
527
|
+
var createSignal = class {
|
|
528
|
+
constructor(initial, props) {
|
|
529
|
+
this.persistName = "";
|
|
530
|
+
this.actions = {};
|
|
531
|
+
this.path = null;
|
|
532
|
+
this.value = initial;
|
|
533
|
+
if (props && props.persistName) {
|
|
534
|
+
this.persistName = props.persistName;
|
|
535
|
+
const key = localStorage.getItem(props.persistName);
|
|
536
|
+
if (key && key !== "undefined") {
|
|
537
|
+
this.value = JSON.parse(key);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
set(value, shouldRefRender) {
|
|
542
|
+
if (typeof value === "function") {
|
|
543
|
+
this.value = value(this.value);
|
|
544
|
+
} else {
|
|
545
|
+
this.value = value;
|
|
546
|
+
}
|
|
547
|
+
if (this.persistName) {
|
|
548
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
549
|
+
}
|
|
550
|
+
if (this.ref && shouldRefRender !== false) {
|
|
551
|
+
if (this.path) {
|
|
552
|
+
this.ref.updateState(this.value[this.path]);
|
|
553
|
+
} else {
|
|
554
|
+
this.ref.updateState(this.value);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (this.callback) {
|
|
558
|
+
this.callback(this.value);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
setKey(key, value, shouldRefRender) {
|
|
562
|
+
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
563
|
+
this.value[key] = value;
|
|
564
|
+
if (this.persistName) {
|
|
565
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
566
|
+
}
|
|
567
|
+
if (this.ref && shouldRefRender !== false) {
|
|
568
|
+
if (this.path) {
|
|
569
|
+
this.ref.updateState(this.value[this.path]);
|
|
570
|
+
} else {
|
|
571
|
+
this.ref.updateState(this.value);
|
|
203
572
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
573
|
+
}
|
|
574
|
+
if (this.callback) {
|
|
575
|
+
this.callback(this.value);
|
|
576
|
+
}
|
|
577
|
+
} else {
|
|
578
|
+
throw new Error(
|
|
579
|
+
`\u2718 Cradova err : can't set key ${String(
|
|
580
|
+
key
|
|
581
|
+
)} . store.value is not a javascript object`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
createAction(key, action) {
|
|
586
|
+
if (typeof key === "string" && typeof action === "function") {
|
|
587
|
+
this.actions[key] = action;
|
|
588
|
+
} else {
|
|
589
|
+
if (typeof key === "object" && !action) {
|
|
590
|
+
for (const [nam, action2] of Object.entries(key)) {
|
|
591
|
+
if (typeof nam === "string" && typeof action2 === "function") {
|
|
592
|
+
this.actions[nam] = action2;
|
|
593
|
+
} else {
|
|
594
|
+
throw new Error(`\u2718 Cradova err : can't create action ${nam}`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
} else {
|
|
598
|
+
throw new Error(`\u2718 Cradova err : can't create action ${key}`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
fireAction(key, data2) {
|
|
603
|
+
try {
|
|
604
|
+
if (!(typeof key === "string" && this.actions[key])) {
|
|
605
|
+
throw Error("");
|
|
606
|
+
}
|
|
607
|
+
} catch (_e) {
|
|
608
|
+
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
609
|
+
}
|
|
610
|
+
this.actions[key](this, data2);
|
|
611
|
+
}
|
|
612
|
+
bindRef(Ref2, path) {
|
|
613
|
+
if (Ref2 && Ref2.updateState) {
|
|
614
|
+
this.ref = Ref2;
|
|
615
|
+
if (typeof path === "string") {
|
|
616
|
+
this.path = path;
|
|
617
|
+
Ref2.render = Ref2.render.bind(Ref2, this.value[path]);
|
|
618
|
+
} else {
|
|
619
|
+
Ref2.render = Ref2.render.bind(Ref2, this.value);
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
throw new Error("\u2718 Cradova err : Invalid ref component" + Ref2);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
listen(callback) {
|
|
626
|
+
this.callback = callback;
|
|
627
|
+
}
|
|
628
|
+
clearPersist() {
|
|
629
|
+
if (this.persistName) {
|
|
630
|
+
localStorage.removeItem(this.persistName);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// lib/utils/Router.ts
|
|
636
|
+
var Router = {};
|
|
637
|
+
var RouterBox = {};
|
|
638
|
+
RouterBox["lastNavigatedRouteController"] = null;
|
|
639
|
+
RouterBox["nextRouteController"] = null;
|
|
640
|
+
RouterBox["lastNavigatedRoute"] = null;
|
|
641
|
+
RouterBox["pageShow"] = null;
|
|
642
|
+
RouterBox["pageHide"] = null;
|
|
643
|
+
RouterBox["errorHandler"] = {};
|
|
644
|
+
RouterBox["params"] = {};
|
|
645
|
+
RouterBox["routes"] = {};
|
|
646
|
+
var checker = (url) => {
|
|
647
|
+
if (RouterBox.routes[url]) {
|
|
648
|
+
return [RouterBox.routes[url], { path: url }];
|
|
649
|
+
}
|
|
650
|
+
for (const path in RouterBox.routes) {
|
|
651
|
+
if (!path.includes(":")) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
const urlFixtures = url.split("/");
|
|
655
|
+
const pathFixtures = path.split("/");
|
|
656
|
+
if (pathFixtures.length === urlFixtures.length) {
|
|
657
|
+
urlFixtures.shift();
|
|
658
|
+
pathFixtures.shift();
|
|
659
|
+
let isIt = true;
|
|
660
|
+
const routesParams = {};
|
|
661
|
+
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
662
|
+
if (!pathFixtures[i2].includes(":") && path.includes(urlFixtures[i2] + "/") && pathFixtures.indexOf(urlFixtures[i2]) === pathFixtures.lastIndexOf(urlFixtures[i2])) {
|
|
663
|
+
if (!isIt)
|
|
664
|
+
isIt = true;
|
|
665
|
+
} else {
|
|
666
|
+
if (pathFixtures[i2].includes(":")) {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
isIt = false;
|
|
670
|
+
}
|
|
671
|
+
if (!(pathFixtures.indexOf(urlFixtures[i2]) === pathFixtures.lastIndexOf(urlFixtures[i2]))) {
|
|
672
|
+
throw new Error(
|
|
673
|
+
" \u2718 Cradova err: cradova router doesn't allow paths with multiple names"
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (isIt) {
|
|
678
|
+
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
679
|
+
if (pathFixtures[i2].includes(":")) {
|
|
680
|
+
routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
routesParams.path = path;
|
|
684
|
+
return [RouterBox.routes[path], routesParams];
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return [];
|
|
689
|
+
};
|
|
690
|
+
Router.route = function(path = "/", screen) {
|
|
691
|
+
if (!screen.Activate && screen.name) {
|
|
692
|
+
console.error(" \u2718 Cradova err: not a valid screen ", screen);
|
|
693
|
+
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
694
|
+
}
|
|
695
|
+
RouterBox.routes[path] = {
|
|
696
|
+
controller: (params, force) => screen.Activate(params, force),
|
|
697
|
+
packager: async (params) => await screen.package(params),
|
|
698
|
+
deactivate: () => {
|
|
699
|
+
screen.deActivate();
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
if (typeof screen.errorHandler === "function") {
|
|
703
|
+
RouterBox["errorHandler"][path] = screen.errorHandler;
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
Router.navigate = function(href, data2 = null, force = false) {
|
|
707
|
+
if (typeof href !== "string") {
|
|
708
|
+
throw new TypeError(
|
|
709
|
+
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
if (typeof data2 === "boolean") {
|
|
713
|
+
force = true;
|
|
714
|
+
data2 = null;
|
|
715
|
+
}
|
|
716
|
+
let route = null, params, link2 = null;
|
|
717
|
+
if (href.includes("://")) {
|
|
718
|
+
window.location.href = href;
|
|
719
|
+
} else {
|
|
720
|
+
if (href === window.location.pathname) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
[route, params] = checker(href);
|
|
724
|
+
if (route) {
|
|
725
|
+
RouterBox["nextRouteController"] = route;
|
|
726
|
+
RouterBox.params.params = params;
|
|
727
|
+
RouterBox.params.data = data2 || null;
|
|
728
|
+
link2 = href;
|
|
729
|
+
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
730
|
+
window.history.pushState({}, "", link2);
|
|
731
|
+
}
|
|
732
|
+
(async () => {
|
|
733
|
+
await RouterBox.router(null, force);
|
|
734
|
+
})();
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
RouterBox.router = async function(e, force = false) {
|
|
738
|
+
let url, route, params;
|
|
739
|
+
const Alink = e && e.target.tagName === "A" && e.target;
|
|
740
|
+
if (Alink) {
|
|
741
|
+
if (Alink.href.includes("#")) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (Alink.href.includes("javascript")) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
e.preventDefault();
|
|
748
|
+
url = new URL(Alink.href).pathname;
|
|
749
|
+
}
|
|
750
|
+
if (!url) {
|
|
751
|
+
url = window.location.pathname;
|
|
752
|
+
}
|
|
753
|
+
if (url === Router["lastNavigatedRoute"]) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (RouterBox["nextRouteController"]) {
|
|
757
|
+
route = RouterBox["nextRouteController"];
|
|
758
|
+
RouterBox["nextRouteController"] = null;
|
|
759
|
+
} else {
|
|
760
|
+
[route, params] = checker(url);
|
|
761
|
+
}
|
|
762
|
+
if (route) {
|
|
763
|
+
try {
|
|
764
|
+
if (params) {
|
|
765
|
+
RouterBox.params.params = params;
|
|
766
|
+
}
|
|
767
|
+
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
|
|
768
|
+
await route.controller(force);
|
|
769
|
+
RouterBox["lastNavigatedRoute"] = url;
|
|
770
|
+
RouterBox["lastNavigatedRouteController"] = route;
|
|
771
|
+
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
772
|
+
for (const a2 of document.querySelectorAll("a")) {
|
|
773
|
+
if (a2.href.includes(window.location.origin)) {
|
|
774
|
+
a2.addEventListener("click", (e2) => {
|
|
775
|
+
e2.preventDefault();
|
|
776
|
+
Router.navigate(a2.pathname);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
} catch (error) {
|
|
781
|
+
const errorHandler = RouterBox.errorHandler["all"] || RouterBox.errorHandler[RouterBox.params.params.path];
|
|
782
|
+
if (errorHandler) {
|
|
783
|
+
errorHandler(error);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
} else {
|
|
787
|
+
if (RouterBox.routes["/404"]) {
|
|
788
|
+
RouterBox.routes["/404"].controller();
|
|
789
|
+
} else {
|
|
790
|
+
if (Object.keys(RouterBox.routes).length > 0) {
|
|
791
|
+
console.error(
|
|
792
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
Router["onPageShow"] = function(callback) {
|
|
799
|
+
if (typeof callback === "function") {
|
|
800
|
+
RouterBox["pageShow"] = callback;
|
|
801
|
+
} else {
|
|
802
|
+
throw new Error(
|
|
803
|
+
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
Router["onPageHide"] = function(callback) {
|
|
808
|
+
if (typeof callback === "function") {
|
|
809
|
+
RouterBox["pageHide"] = callback;
|
|
810
|
+
} else {
|
|
811
|
+
throw new Error(
|
|
812
|
+
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
Router.packageScreen = async function(path, data2) {
|
|
817
|
+
if (!RouterBox.routes[path]) {
|
|
818
|
+
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
819
|
+
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
820
|
+
}
|
|
821
|
+
await RouterBox.routes[path].packager(data2);
|
|
822
|
+
};
|
|
823
|
+
Router.getParams = function() {
|
|
824
|
+
return RouterBox["params"];
|
|
825
|
+
};
|
|
826
|
+
Router["addErrorHandler"] = function(callback, path) {
|
|
827
|
+
if (typeof callback === "function") {
|
|
828
|
+
RouterBox["errorHandler"][path || "all"] = callback;
|
|
829
|
+
} else {
|
|
830
|
+
throw new Error(
|
|
831
|
+
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
836
|
+
window.addEventListener("popstate", (e) => {
|
|
837
|
+
e.preventDefault();
|
|
838
|
+
RouterBox.router();
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
// lib/utils/Screen.ts
|
|
842
|
+
var Screen = class {
|
|
843
|
+
constructor(cradova_screen_initials) {
|
|
844
|
+
this.packed = false;
|
|
845
|
+
this.secondaryChildren = [];
|
|
846
|
+
this.template = document.createElement("div");
|
|
847
|
+
this.errorHandler = null;
|
|
848
|
+
this.persist = true;
|
|
849
|
+
const { template: template2, name, persist } = cradova_screen_initials;
|
|
850
|
+
if (typeof template2 !== "function") {
|
|
851
|
+
throw new Error(
|
|
852
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
this.html = template2.bind(this);
|
|
856
|
+
this.name = name;
|
|
857
|
+
this.template.setAttribute("id", "cradova-screen-set");
|
|
858
|
+
if (typeof persist === "boolean") {
|
|
859
|
+
this.persist = persist;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
setErrorHandler(errorHandler) {
|
|
863
|
+
this.errorHandler = errorHandler;
|
|
864
|
+
}
|
|
865
|
+
async package() {
|
|
866
|
+
if (typeof this.html === "function") {
|
|
867
|
+
let fuc = await this.html(this.data);
|
|
868
|
+
if (typeof fuc === "function") {
|
|
869
|
+
fuc = fuc();
|
|
870
|
+
if (fuc && !isNode(fuc) && typeof fuc !== "string") {
|
|
871
|
+
throw new Error(
|
|
872
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
873
|
+
);
|
|
874
|
+
} else {
|
|
875
|
+
if (fuc) {
|
|
876
|
+
this.template.innerHTML = "";
|
|
877
|
+
this.template.appendChild(fuc);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
} else {
|
|
881
|
+
if (!isNode(fuc) && typeof fuc !== "string") {
|
|
882
|
+
throw new Error(
|
|
883
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
884
|
+
);
|
|
885
|
+
} else {
|
|
886
|
+
this.template.innerHTML = "";
|
|
887
|
+
this.template.appendChild(fuc);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (!this.template.firstChild) {
|
|
892
|
+
throw new Error(
|
|
893
|
+
" \u2718 Cradova err: no screen is rendered, may have been past wrongly."
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
if (this.secondaryChildren.length) {
|
|
897
|
+
for (const child of this.secondaryChildren) {
|
|
898
|
+
this.template.appendChild(child);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
onActivate(cb) {
|
|
903
|
+
this.callBack = cb;
|
|
904
|
+
}
|
|
905
|
+
onDeactivate(cb) {
|
|
906
|
+
this.deCallBack = cb;
|
|
907
|
+
}
|
|
908
|
+
addChild(...addOns) {
|
|
909
|
+
this.secondaryChildren.push(frag(addOns));
|
|
910
|
+
}
|
|
911
|
+
deActivate() {
|
|
912
|
+
if (this.deCallBack) {
|
|
913
|
+
this.deCallBack();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
async Activate(force) {
|
|
917
|
+
if (!this.persist) {
|
|
918
|
+
await this.package();
|
|
919
|
+
this.packed = true;
|
|
920
|
+
} else {
|
|
921
|
+
if (!this.packed) {
|
|
922
|
+
await this.package();
|
|
923
|
+
this.packed = true;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
if (this.persist && force) {
|
|
927
|
+
await this.package();
|
|
928
|
+
this.packed = true;
|
|
929
|
+
}
|
|
930
|
+
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
931
|
+
if (!doc) {
|
|
932
|
+
throw new Error(
|
|
933
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
doc.innerHTML = "";
|
|
937
|
+
doc.appendChild(this.template);
|
|
938
|
+
document.title = this.name;
|
|
939
|
+
if (!this.persist) {
|
|
940
|
+
this.packed = false;
|
|
941
|
+
}
|
|
942
|
+
if (this.callBack) {
|
|
943
|
+
await this.callBack();
|
|
944
|
+
}
|
|
945
|
+
window.dispatchEvent(cradovaAftermountEvent);
|
|
946
|
+
window.scrollTo(0, 0);
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
// lib/utils/tags.ts
|
|
951
|
+
var cra = (element_initials) => {
|
|
952
|
+
return (...ElementChildrenAndPropertyList) => {
|
|
953
|
+
let beforeMount = null;
|
|
954
|
+
let props = null, text = null;
|
|
955
|
+
let element;
|
|
956
|
+
element = document.createElement(element_initials);
|
|
957
|
+
if (ElementChildrenAndPropertyList.length) {
|
|
958
|
+
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
959
|
+
let child = ElementChildrenAndPropertyList[i2];
|
|
960
|
+
if (typeof child === "function") {
|
|
961
|
+
child = child();
|
|
962
|
+
if (typeof child === "function") {
|
|
963
|
+
child = child();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (isNode(child)) {
|
|
967
|
+
element.appendChild(child);
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
if (Array.isArray(child)) {
|
|
971
|
+
element.appendChild(Rhoda(child));
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
975
|
+
text = child;
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
if (typeof child === "object") {
|
|
979
|
+
if (!props) {
|
|
980
|
+
props = child;
|
|
981
|
+
} else {
|
|
982
|
+
props = Object.assign(props, child);
|
|
983
|
+
}
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (typeof child !== "undefined") {
|
|
987
|
+
console.error(" \u2718 Cradova err: got", { child });
|
|
988
|
+
throw new Error(
|
|
989
|
+
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if (typeof props === "object" && element) {
|
|
995
|
+
for (const prop in props) {
|
|
996
|
+
if (prop === "style" && typeof props[prop] === "object") {
|
|
997
|
+
for (const [k, v] of Object.entries(props[prop])) {
|
|
998
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
999
|
+
element.style[k] = v;
|
|
1000
|
+
} else {
|
|
1001
|
+
throw new Error(
|
|
1002
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
1003
|
+
);
|
|
211
1004
|
}
|
|
1005
|
+
}
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1009
|
+
element.style[prop] = props[prop];
|
|
1010
|
+
continue;
|
|
212
1011
|
}
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
1012
|
+
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1013
|
+
text = props[prop];
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1017
|
+
element.classList.add(props[prop]);
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
if (prop === "beforeMount") {
|
|
1021
|
+
beforeMount = props["beforeMount"];
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
if (prop === "stateID") {
|
|
1025
|
+
element.setAttribute("data-cra-id", props[prop]);
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
if (prop.includes("$")) {
|
|
1029
|
+
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1033
|
+
element.updateState = dispatch.bind(null, element);
|
|
1034
|
+
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1038
|
+
element.updateState = dispatch.bind(null, element);
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1042
|
+
const av = () => {
|
|
1043
|
+
props["afterMount"].apply(element);
|
|
1044
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
1045
|
+
};
|
|
1046
|
+
window.addEventListener("cradova-aftermount", av);
|
|
1047
|
+
continue;
|
|
1048
|
+
}
|
|
1049
|
+
try {
|
|
1050
|
+
if (typeof element[prop] !== "undefined") {
|
|
1051
|
+
element[prop] = props[prop];
|
|
1052
|
+
} else {
|
|
1053
|
+
if (prop.includes("data-")) {
|
|
1054
|
+
element.setAttribute(prop, props[prop]);
|
|
1055
|
+
continue;
|
|
217
1056
|
}
|
|
218
|
-
|
|
219
|
-
|
|
1057
|
+
element[prop] = props[prop];
|
|
1058
|
+
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1059
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1060
|
+
prop
|
|
1061
|
+
});
|
|
1062
|
+
} else {
|
|
1063
|
+
continue;
|
|
220
1064
|
}
|
|
1065
|
+
}
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1068
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
221
1069
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (text) {
|
|
1073
|
+
element.appendChild(document.createTextNode(text));
|
|
1074
|
+
}
|
|
1075
|
+
if (typeof beforeMount === "function") {
|
|
1076
|
+
beforeMount.apply(element);
|
|
1077
|
+
}
|
|
1078
|
+
return element;
|
|
1079
|
+
};
|
|
1080
|
+
};
|
|
1081
|
+
var a = cra("a");
|
|
1082
|
+
var abbr = cra("abbr");
|
|
1083
|
+
var address = cra("address");
|
|
1084
|
+
var area = cra("area");
|
|
1085
|
+
var article = cra("article");
|
|
1086
|
+
var aside = cra("aside");
|
|
1087
|
+
var audio = cra("audio");
|
|
1088
|
+
var b = cra("b");
|
|
1089
|
+
var base = cra("base");
|
|
1090
|
+
var bdi = cra("bdi");
|
|
1091
|
+
var bdo = cra("bdo");
|
|
1092
|
+
var blockquote = cra("blockquote");
|
|
1093
|
+
var body = cra("body");
|
|
1094
|
+
var br = cra("br");
|
|
1095
|
+
var button = cra("button");
|
|
1096
|
+
var canvas = cra("canvas");
|
|
1097
|
+
var caption = cra("caption");
|
|
1098
|
+
var cite = cra("cite");
|
|
1099
|
+
var code = cra("code");
|
|
1100
|
+
var col = cra("col");
|
|
1101
|
+
var colgroup = cra("colgroup");
|
|
1102
|
+
var data = cra("data");
|
|
1103
|
+
var datalist = cra("datalist");
|
|
1104
|
+
var dd = cra("dd");
|
|
1105
|
+
var del = cra("del");
|
|
1106
|
+
var details = cra("details");
|
|
1107
|
+
var dfn = cra("dfn");
|
|
1108
|
+
var dialog = cra("dialog");
|
|
1109
|
+
var div = cra("div");
|
|
1110
|
+
var dl = cra("dl");
|
|
1111
|
+
var dt = cra("dt");
|
|
1112
|
+
var em = cra("em");
|
|
1113
|
+
var embed = cra("embed");
|
|
1114
|
+
var fieldset = cra("fieldset");
|
|
1115
|
+
var figcaption = cra("figcaption");
|
|
1116
|
+
var figure = cra("figure");
|
|
1117
|
+
var footer = cra("footer");
|
|
1118
|
+
var form = cra("form");
|
|
1119
|
+
var h1 = cra("h1");
|
|
1120
|
+
var h2 = cra("h2");
|
|
1121
|
+
var h3 = cra("h3");
|
|
1122
|
+
var h4 = cra("h4");
|
|
1123
|
+
var h5 = cra("h5");
|
|
1124
|
+
var h6 = cra("h6");
|
|
1125
|
+
var head = cra("head");
|
|
1126
|
+
var header = cra("header");
|
|
1127
|
+
var hr = cra("hr");
|
|
1128
|
+
var html = cra("html");
|
|
1129
|
+
var i = cra("i");
|
|
1130
|
+
var iframe = cra("iframe");
|
|
1131
|
+
var img = cra("img");
|
|
1132
|
+
var input = cra("input");
|
|
1133
|
+
var ins = cra("ins");
|
|
1134
|
+
var kbd = cra("kbd");
|
|
1135
|
+
var label = cra("label");
|
|
1136
|
+
var legend = cra("legend");
|
|
1137
|
+
var li = cra("li");
|
|
1138
|
+
var link = cra("link");
|
|
1139
|
+
var main = cra("main");
|
|
1140
|
+
var map = cra("map");
|
|
1141
|
+
var mark = cra("mark");
|
|
1142
|
+
var math = cra("math");
|
|
1143
|
+
var menu = cra("menu");
|
|
1144
|
+
var meta = cra("meta");
|
|
1145
|
+
var meter = cra("meter");
|
|
1146
|
+
var nav = cra("nav");
|
|
1147
|
+
var noscript = cra("noscript");
|
|
1148
|
+
var object = cra("object");
|
|
1149
|
+
var ol = cra("ol");
|
|
1150
|
+
var optgroup = cra("optgroup");
|
|
1151
|
+
var option = cra("option");
|
|
1152
|
+
var output = cra("output");
|
|
1153
|
+
var p = cra("p");
|
|
1154
|
+
var picture = cra("picture");
|
|
1155
|
+
var portal = cra("portal");
|
|
1156
|
+
var pre = cra("pre");
|
|
1157
|
+
var progress = cra("progress");
|
|
1158
|
+
var q = cra("q");
|
|
1159
|
+
var rp = cra("rp");
|
|
1160
|
+
var rt = cra("rt");
|
|
1161
|
+
var ruby = cra("ruby");
|
|
1162
|
+
var s = cra("s");
|
|
1163
|
+
var samp = cra("samp");
|
|
1164
|
+
var script = cra("script");
|
|
1165
|
+
var section = cra("section");
|
|
1166
|
+
var select = cra("select");
|
|
1167
|
+
var slot = cra("slot");
|
|
1168
|
+
var small = cra("small");
|
|
1169
|
+
var source = cra("source");
|
|
1170
|
+
var span = cra("span");
|
|
1171
|
+
var strong = cra("strong");
|
|
1172
|
+
var style = cra("style");
|
|
1173
|
+
var sub = cra("sub");
|
|
1174
|
+
var summary = cra("summary");
|
|
1175
|
+
var sup = cra("sup");
|
|
1176
|
+
var table = cra("table");
|
|
1177
|
+
var tbody = cra("tbody");
|
|
1178
|
+
var td = cra("td");
|
|
1179
|
+
var template = cra("template");
|
|
1180
|
+
var textarea = cra("textarea");
|
|
1181
|
+
var tfoot = cra("tfoot");
|
|
1182
|
+
var th = cra("th");
|
|
1183
|
+
var thead = cra("thead");
|
|
1184
|
+
var time = cra("time");
|
|
1185
|
+
var title = cra("title");
|
|
1186
|
+
var tr = cra("tr");
|
|
1187
|
+
var track = cra("track");
|
|
1188
|
+
var u = cra("u");
|
|
1189
|
+
var ul = cra("ul");
|
|
1190
|
+
var val = cra("val");
|
|
1191
|
+
var video = cra("video");
|
|
1192
|
+
var wbr = cra("wbr");
|
|
1193
|
+
|
|
1194
|
+
// lib/index.ts
|
|
1195
|
+
var make = function(txx) {
|
|
1196
|
+
if (!txx) {
|
|
1197
|
+
return {
|
|
1198
|
+
tag: "div"
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
let tag;
|
|
1202
|
+
let innerValue = "";
|
|
1203
|
+
if (txx.includes("|")) {
|
|
1204
|
+
const tc = txx.split("|");
|
|
1205
|
+
innerValue = tc[1];
|
|
1206
|
+
txx = tc[0] && tc[0];
|
|
1207
|
+
}
|
|
1208
|
+
const itemsPurifier = () => {
|
|
1209
|
+
if (!txx.includes("#")) {
|
|
1210
|
+
txx = txx.split(".");
|
|
1211
|
+
tag = txx[0];
|
|
1212
|
+
if (tag) {
|
|
1213
|
+
txx.shift();
|
|
1214
|
+
} else {
|
|
1215
|
+
tag = "div";
|
|
1216
|
+
}
|
|
1217
|
+
return [txx, []];
|
|
1218
|
+
} else {
|
|
1219
|
+
if (!txx.includes(".")) {
|
|
1220
|
+
txx = txx.split("#");
|
|
1221
|
+
tag = txx[0];
|
|
1222
|
+
if (tag) {
|
|
1223
|
+
txx.shift();
|
|
1224
|
+
} else {
|
|
1225
|
+
tag = "div";
|
|
1226
|
+
}
|
|
1227
|
+
if (txx[0].includes(" ")) {
|
|
1228
|
+
txx = [txx[0].split(" ")[1]];
|
|
1229
|
+
}
|
|
1230
|
+
return [[], txx];
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
txx = txx.split(".");
|
|
1234
|
+
const pureItems = [];
|
|
1235
|
+
const impureItems = [];
|
|
1236
|
+
tag = !txx[0].includes("#") && txx[0];
|
|
1237
|
+
if (tag) {
|
|
1238
|
+
txx.shift();
|
|
1239
|
+
}
|
|
1240
|
+
for (let i2 = 0; i2 < txx.length; i2++) {
|
|
1241
|
+
if (txx[i2].includes("#")) {
|
|
1242
|
+
const item = txx[i2].split("#");
|
|
1243
|
+
impureItems.push(item[1]);
|
|
1244
|
+
if (i2 === 0) {
|
|
1245
|
+
tag = item[0];
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
pureItems.push(item[0]);
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
pureItems.push(txx[i2]);
|
|
1252
|
+
}
|
|
1253
|
+
if (!tag) {
|
|
1254
|
+
tag = "div";
|
|
1255
|
+
}
|
|
1256
|
+
return [pureItems, impureItems];
|
|
1257
|
+
};
|
|
1258
|
+
const [classes, ids] = itemsPurifier();
|
|
1259
|
+
const ID = ids && ids[0];
|
|
1260
|
+
const className = classes && classes.join(" ");
|
|
1261
|
+
return { tag, className, ID, innerValue };
|
|
1262
|
+
};
|
|
1263
|
+
var _ = (...element_initials) => {
|
|
1264
|
+
if (typeof element_initials[0] !== "string") {
|
|
1265
|
+
return frag(element_initials);
|
|
1266
|
+
}
|
|
1267
|
+
if (element_initials.raw) {
|
|
1268
|
+
element_initials[0] = element_initials["raw"][0];
|
|
1269
|
+
}
|
|
1270
|
+
let beforeMount = null, firstLevelChildren = [];
|
|
1271
|
+
if (element_initials.length > 1) {
|
|
1272
|
+
firstLevelChildren = element_initials.splice(1);
|
|
1273
|
+
}
|
|
1274
|
+
if (typeof element_initials !== "object") {
|
|
1275
|
+
element_initials = [element_initials];
|
|
1276
|
+
}
|
|
1277
|
+
return (...ElementChildrenAndPropertyList) => {
|
|
1278
|
+
const initials = make(element_initials[0]);
|
|
1279
|
+
let props = null, text = null;
|
|
1280
|
+
if (firstLevelChildren.length) {
|
|
1281
|
+
ElementChildrenAndPropertyList.push(...firstLevelChildren);
|
|
1282
|
+
}
|
|
1283
|
+
let element;
|
|
1284
|
+
try {
|
|
1285
|
+
element = document.createElement(initials.tag.trim());
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
throw new TypeError(
|
|
1288
|
+
" \u2718 Cradova err: invalid tag given " + initials.tag
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
if (initials.className) {
|
|
1292
|
+
if (props) {
|
|
1293
|
+
props["className"] = initials.className.trim();
|
|
1294
|
+
} else {
|
|
1295
|
+
props = { className: initials.className.trim() };
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
if (initials.ID) {
|
|
1299
|
+
if (props) {
|
|
1300
|
+
props["id"] = initials.ID.trim();
|
|
1301
|
+
} else {
|
|
1302
|
+
props = { id: initials.ID.trim() };
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
if (initials.innerValue) {
|
|
1306
|
+
if (props) {
|
|
1307
|
+
props["innerText"] = initials.innerValue;
|
|
1308
|
+
} else {
|
|
1309
|
+
props = { innerText: initials.innerValue };
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (ElementChildrenAndPropertyList.length) {
|
|
1313
|
+
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
1314
|
+
let child = ElementChildrenAndPropertyList[i2];
|
|
1315
|
+
if (typeof child === "function") {
|
|
1316
|
+
child = child();
|
|
1317
|
+
}
|
|
1318
|
+
if (typeof child === "function") {
|
|
1319
|
+
child = child();
|
|
1320
|
+
}
|
|
1321
|
+
if (isNode(child)) {
|
|
1322
|
+
element.appendChild(child);
|
|
1323
|
+
continue;
|
|
285
1324
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
// before mount event
|
|
322
|
-
if (prop === "beforeMount") {
|
|
323
|
-
beforeMount = props["beforeMount"];
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
// setting state id
|
|
327
|
-
if (prop === "stateID") {
|
|
328
|
-
element.setAttribute("data-cra-id", props[prop]);
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
// setting data attribute
|
|
332
|
-
if (prop.includes("$")) {
|
|
333
|
-
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
if (Array.isArray(props[prop]) &&
|
|
337
|
-
props[prop][0] instanceof simpleStore) {
|
|
338
|
-
element.updateState = dispatch.bind(null, element);
|
|
339
|
-
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
// setting should update state key;
|
|
343
|
-
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
344
|
-
element.updateState = dispatch.bind(null, element);
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
// setting afterMount event;
|
|
348
|
-
if (prop === "afterMount" &&
|
|
349
|
-
typeof props["afterMount"] === "function") {
|
|
350
|
-
const av = () => {
|
|
351
|
-
props["afterMount"].apply(element);
|
|
352
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
353
|
-
};
|
|
354
|
-
window.addEventListener("cradova-aftermount", av);
|
|
355
|
-
continue;
|
|
356
|
-
}
|
|
357
|
-
// trying to set other values
|
|
358
|
-
try {
|
|
359
|
-
if (typeof element[prop] !== "undefined") {
|
|
360
|
-
element[prop] = props[prop];
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
if (prop.includes("data-")) {
|
|
364
|
-
element.setAttribute(prop, props[prop]);
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
element[prop] = props[prop];
|
|
368
|
-
if (prop !== "for" &&
|
|
369
|
-
prop !== "text" &&
|
|
370
|
-
prop !== "class" &&
|
|
371
|
-
prop !== "tabindex" &&
|
|
372
|
-
!prop.includes("aria")) {
|
|
373
|
-
console.error(" ✘ Cradova err: invalid html attribute ", {
|
|
374
|
-
prop,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
console.error(" ✘ Cradova err: invalid html attribute ", { props });
|
|
384
|
-
console.error(" ✘ Cradova err: ", error);
|
|
385
|
-
}
|
|
1325
|
+
if (Array.isArray(child)) {
|
|
1326
|
+
element.appendChild(Rhoda(child));
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
1330
|
+
text = child;
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
if (typeof child === "object") {
|
|
1334
|
+
if (!props) {
|
|
1335
|
+
props = child;
|
|
1336
|
+
} else {
|
|
1337
|
+
props = Object.assign(props, child);
|
|
1338
|
+
}
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
if (typeof child !== "undefined") {
|
|
1342
|
+
console.error(" \u2718 Cradova err: got", { child });
|
|
1343
|
+
throw new Error(
|
|
1344
|
+
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (typeof props === "object" && element) {
|
|
1350
|
+
for (const prop in props) {
|
|
1351
|
+
if (prop === "style" && typeof props[prop] === "object") {
|
|
1352
|
+
for (const [k, v] of Object.entries(props[prop])) {
|
|
1353
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
1354
|
+
element.style[k] = v;
|
|
1355
|
+
} else {
|
|
1356
|
+
throw new Error(
|
|
1357
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
1358
|
+
);
|
|
386
1359
|
}
|
|
1360
|
+
}
|
|
1361
|
+
continue;
|
|
387
1362
|
}
|
|
388
|
-
if (
|
|
389
|
-
|
|
1363
|
+
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1364
|
+
element.style[prop] = props[prop];
|
|
1365
|
+
continue;
|
|
390
1366
|
}
|
|
391
|
-
if (typeof
|
|
392
|
-
|
|
1367
|
+
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1368
|
+
text = props[prop];
|
|
1369
|
+
continue;
|
|
393
1370
|
}
|
|
394
|
-
|
|
395
|
-
|
|
1371
|
+
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1372
|
+
element.classList.add(props[prop]);
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
if (prop === "beforeMount") {
|
|
1376
|
+
beforeMount = props["beforeMount"];
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
if (prop === "stateID") {
|
|
1380
|
+
element.setAttribute("data-cra-id", props[prop]);
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
if (prop.includes("$")) {
|
|
1384
|
+
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1388
|
+
element.updateState = dispatch.bind(null, element);
|
|
1389
|
+
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1393
|
+
element.updateState = dispatch.bind(null, element);
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1397
|
+
const av = () => {
|
|
1398
|
+
props["afterMount"].apply(element);
|
|
1399
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
1400
|
+
};
|
|
1401
|
+
window.addEventListener("cradova-aftermount", av);
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
try {
|
|
1405
|
+
if (typeof element[prop] !== "undefined") {
|
|
1406
|
+
element[prop] = props[prop];
|
|
1407
|
+
} else {
|
|
1408
|
+
if (prop.includes("data-")) {
|
|
1409
|
+
element.setAttribute(prop, props[prop]);
|
|
1410
|
+
continue;
|
|
1411
|
+
}
|
|
1412
|
+
element[prop] = props[prop];
|
|
1413
|
+
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1414
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1415
|
+
prop
|
|
1416
|
+
});
|
|
1417
|
+
} else {
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1423
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (text) {
|
|
1428
|
+
element.appendChild(document.createTextNode(text));
|
|
1429
|
+
}
|
|
1430
|
+
if (typeof beforeMount === "function") {
|
|
1431
|
+
beforeMount.apply(element);
|
|
1432
|
+
}
|
|
1433
|
+
return element;
|
|
1434
|
+
};
|
|
396
1435
|
};
|
|
397
1436
|
Init();
|
|
398
|
-
|
|
399
|
-
export {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
1437
|
+
var lib_default = _;
|
|
1438
|
+
export {
|
|
1439
|
+
simpleStore as $,
|
|
1440
|
+
Ajax,
|
|
1441
|
+
Ref,
|
|
1442
|
+
Router,
|
|
1443
|
+
Screen,
|
|
1444
|
+
a,
|
|
1445
|
+
abbr,
|
|
1446
|
+
address,
|
|
1447
|
+
area,
|
|
1448
|
+
article,
|
|
1449
|
+
aside,
|
|
1450
|
+
assert,
|
|
1451
|
+
assertOr,
|
|
1452
|
+
audio,
|
|
1453
|
+
b,
|
|
1454
|
+
base,
|
|
1455
|
+
bdi,
|
|
1456
|
+
bdo,
|
|
1457
|
+
blockquote,
|
|
1458
|
+
body,
|
|
1459
|
+
br,
|
|
1460
|
+
button,
|
|
1461
|
+
canvas,
|
|
1462
|
+
caption,
|
|
1463
|
+
cite,
|
|
1464
|
+
code,
|
|
1465
|
+
col,
|
|
1466
|
+
colgroup,
|
|
1467
|
+
cradovaAftermountEvent,
|
|
1468
|
+
createSignal,
|
|
1469
|
+
css,
|
|
1470
|
+
data,
|
|
1471
|
+
datalist,
|
|
1472
|
+
dd,
|
|
1473
|
+
lib_default as default,
|
|
1474
|
+
del,
|
|
1475
|
+
details,
|
|
1476
|
+
dfn,
|
|
1477
|
+
dialog,
|
|
1478
|
+
dispatch,
|
|
1479
|
+
div,
|
|
1480
|
+
dl,
|
|
1481
|
+
dt,
|
|
1482
|
+
em,
|
|
1483
|
+
embed,
|
|
1484
|
+
fieldset,
|
|
1485
|
+
figcaption,
|
|
1486
|
+
figure,
|
|
1487
|
+
footer,
|
|
1488
|
+
form,
|
|
1489
|
+
h1,
|
|
1490
|
+
h2,
|
|
1491
|
+
h3,
|
|
1492
|
+
h4,
|
|
1493
|
+
h5,
|
|
1494
|
+
h6,
|
|
1495
|
+
head,
|
|
1496
|
+
header,
|
|
1497
|
+
hr,
|
|
1498
|
+
html,
|
|
1499
|
+
i,
|
|
1500
|
+
iframe,
|
|
1501
|
+
img,
|
|
1502
|
+
input,
|
|
1503
|
+
ins,
|
|
1504
|
+
kbd,
|
|
1505
|
+
label,
|
|
1506
|
+
legend,
|
|
1507
|
+
li,
|
|
1508
|
+
link,
|
|
1509
|
+
loop,
|
|
1510
|
+
main,
|
|
1511
|
+
map,
|
|
1512
|
+
mark,
|
|
1513
|
+
math,
|
|
1514
|
+
menu,
|
|
1515
|
+
meta,
|
|
1516
|
+
meter,
|
|
1517
|
+
nav,
|
|
1518
|
+
noscript,
|
|
1519
|
+
object,
|
|
1520
|
+
ol,
|
|
1521
|
+
optgroup,
|
|
1522
|
+
option,
|
|
1523
|
+
output,
|
|
1524
|
+
p,
|
|
1525
|
+
picture,
|
|
1526
|
+
portal,
|
|
1527
|
+
pre,
|
|
1528
|
+
progress,
|
|
1529
|
+
q,
|
|
1530
|
+
rp,
|
|
1531
|
+
rt,
|
|
1532
|
+
ruby,
|
|
1533
|
+
s,
|
|
1534
|
+
samp,
|
|
1535
|
+
script,
|
|
1536
|
+
section,
|
|
1537
|
+
select,
|
|
1538
|
+
slot,
|
|
1539
|
+
small,
|
|
1540
|
+
source,
|
|
1541
|
+
span,
|
|
1542
|
+
strong,
|
|
1543
|
+
style,
|
|
1544
|
+
sub,
|
|
1545
|
+
summary,
|
|
1546
|
+
sup,
|
|
1547
|
+
svgNS,
|
|
1548
|
+
table,
|
|
1549
|
+
tbody,
|
|
1550
|
+
td,
|
|
1551
|
+
template,
|
|
1552
|
+
textarea,
|
|
1553
|
+
tfoot,
|
|
1554
|
+
th,
|
|
1555
|
+
thead,
|
|
1556
|
+
time,
|
|
1557
|
+
title,
|
|
1558
|
+
tr,
|
|
1559
|
+
track,
|
|
1560
|
+
u,
|
|
1561
|
+
ul,
|
|
1562
|
+
val,
|
|
1563
|
+
video,
|
|
1564
|
+
wbr
|
|
1565
|
+
};
|