cradova 2.1.2 → 2.2.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 CHANGED
@@ -7,12 +7,114 @@ var Init = function() {
7
7
  }
8
8
  };
9
9
 
10
+ // lib/utils/track.ts
11
+ function cradovaDispatchTrack(nodes, state) {
12
+ for (let i2 = 0; i2 < nodes.length; i2++) {
13
+ const element = nodes[i2];
14
+ if (!element) {
15
+ continue;
16
+ }
17
+ if (typeof state === "object" && !Array.isArray(state)) {
18
+ for (const key in state) {
19
+ if (key === "style") {
20
+ for (const [k, v] of Object.entries(state[key])) {
21
+ if (typeof element.style[k] !== "undefined" && k !== "src") {
22
+ element.style[k] = v;
23
+ } else {
24
+ throw new Error(
25
+ "\u2718 Cradova err : " + k + " is not a valid css style property"
26
+ );
27
+ }
28
+ }
29
+ continue;
30
+ }
31
+ if (typeof element[key] === "function") {
32
+ if (key.startsWith("on")) {
33
+ element[key] = state[key];
34
+ } else {
35
+ element[key].apply(element);
36
+ }
37
+ continue;
38
+ }
39
+ if (key === "text") {
40
+ element.innerText = state[key];
41
+ continue;
42
+ }
43
+ if (key === "remove") {
44
+ if (element.parentElement) {
45
+ element.parentElement?.removeChild(element);
46
+ } else {
47
+ element.remove();
48
+ }
49
+ continue;
50
+ }
51
+ if (key.includes("$")) {
52
+ element.setAttribute("data-" + key.split("$")[1], state[key]);
53
+ continue;
54
+ }
55
+ if (key === "tree") {
56
+ element.innerHTML = "";
57
+ element.appendChild(frag(state[key]));
58
+ continue;
59
+ }
60
+ try {
61
+ if (typeof element[key] !== "undefined") {
62
+ element[key] = state[key];
63
+ } else {
64
+ element[key] = state[key];
65
+ if (key !== "for" && key !== "text" && key !== "class" && key !== "tabindex" && key !== "disabled" && !key.includes("aria")) {
66
+ console.error(" \u2718 Cradova err: invalid html attribute " + key);
67
+ }
68
+ }
69
+ } catch (error) {
70
+ console.error(" \u2718 Cradova err: Cradova got ", state);
71
+ console.error(" \u2718 Cradova err: ", error);
72
+ }
73
+ }
74
+ } else {
75
+ throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
76
+ }
77
+ }
78
+ }
79
+ function dispatch(stateID, state) {
80
+ let ele;
81
+ if (stateID instanceof HTMLElement) {
82
+ ele = stateID;
83
+ }
84
+ let updated = void 0;
85
+ if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
86
+ for (const [id, eachState] of Object.entries(stateID)) {
87
+ const elements = document.querySelectorAll(
88
+ "[data-cra-id=" + id + "]"
89
+ );
90
+ updated = elements.length === 1 ? elements[0] : elements;
91
+ cradovaDispatchTrack(elements, eachState);
92
+ }
93
+ } else {
94
+ if (typeof stateID === "string") {
95
+ const elements = document.querySelectorAll(
96
+ "[data-cra-id=" + stateID + "]"
97
+ );
98
+ if (elements.length) {
99
+ updated = elements.length === 1 ? elements[0] : elements;
100
+ if (!state?.cradovaDispatchTrackBreak) {
101
+ cradovaDispatchTrack(elements, state);
102
+ }
103
+ }
104
+ }
105
+ if (ele) {
106
+ cradovaDispatchTrack([ele], state);
107
+ }
108
+ }
109
+ return updated;
110
+ }
111
+
10
112
  // lib/utils/fns.ts
11
113
  var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
12
114
  var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
13
115
  function uuid() {
14
116
  let t = Date.now ? +Date.now() : +new Date();
15
- return "cradova-id-xxxxxxxxxx".replace(/[x]/g, function(e) {
117
+ return "cradova-id-xxxxxx".replace(/[x]/g, function(e) {
16
118
  const r = (t + 16 * Math.random()) % 16 | 0;
17
119
  return ("x" === e ? r : 7 & r | 8).toString(16);
18
120
  });
@@ -160,12 +262,10 @@ var Ref = class {
160
262
  await this.effector.apply(this);
161
263
  window.removeEventListener("cradova-aftermount", av);
162
264
  };
163
- if (!this.published) {
164
- this.published = true;
165
- window.addEventListener("cradova-aftermount", av);
166
- } else {
167
- this.effector();
168
- }
265
+ window.addEventListener("cradova-aftermount", av);
266
+ this.effector();
267
+ this.published = true;
268
+ this.rendered = true;
169
269
  if (!element) {
170
270
  element = this.preRendered;
171
271
  }
@@ -183,14 +283,13 @@ var Ref = class {
183
283
  }
184
284
  async effector() {
185
285
  if (!this.rendered) {
186
- for (const effect of this.effects) {
187
- await effect.apply(this);
286
+ for (let i2 = 0; i2 < this.effects.length; i2++) {
287
+ await this.effects[i2].apply(this);
188
288
  }
189
289
  }
190
290
  if (!this.hasFirstStateUpdateRun && this.effectuate) {
191
291
  await this.effectuate();
192
292
  }
193
- this.rendered = true;
194
293
  this.hasFirstStateUpdateRun = true;
195
294
  }
196
295
  updateState(data2, stash) {
@@ -206,9 +305,11 @@ var Ref = class {
206
305
  }
207
306
  this.effectuate = updateState.bind(this, data2);
208
307
  } else {
209
- (async () => {
210
- await this.Activate(data2);
211
- })();
308
+ if (this.published) {
309
+ (async () => {
310
+ await this.Activate(data2);
311
+ })();
312
+ }
212
313
  }
213
314
  if (stash) {
214
315
  this.stash = data2;
@@ -218,6 +319,7 @@ var Ref = class {
218
319
  if (!data2) {
219
320
  return;
220
321
  }
322
+ this.published = false;
221
323
  const guy = dispatch(this.stateID, {
222
324
  cradovaDispatchTrackBreak: true
223
325
  });
@@ -242,6 +344,7 @@ var Ref = class {
242
344
  } catch (e0) {
243
345
  console.error(e0);
244
346
  }
347
+ this.published = true;
245
348
  }
246
349
  remove() {
247
350
  dispatch(this.stateID, { remove: true });
@@ -253,15 +356,21 @@ var frag = function(children) {
253
356
  let a2 = children[i2];
254
357
  if (typeof a2 === "function") {
255
358
  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
- }
359
+ }
360
+ if (typeof a2 === "function") {
361
+ a2 = a2();
362
+ }
363
+ if (isNode(a2)) {
364
+ par.appendChild(a2);
365
+ continue;
366
+ }
367
+ if (a2 instanceof String) {
368
+ par.appendChild(document.createTextNode(a2));
369
+ continue;
370
+ }
371
+ {
372
+ console.error(" \u2718 Cradova err: wrong element type" + a2);
373
+ throw new TypeError(" \u2718 Cradova err: invalid element");
265
374
  }
266
375
  }
267
376
  return par;
@@ -286,123 +395,43 @@ var svgNS = (type, props, ...children) => {
286
395
  }
287
396
  return sc;
288
397
  };
289
-
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
- );
307
- }
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]);
328
- }
329
- }
330
- continue;
331
- }
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);
356
- }
357
- }
358
- } catch (error) {
359
- console.error(" \u2718 Cradova err: Cradova got ", state);
360
- console.error(" \u2718 Cradova err: ", error);
361
- }
362
- }
398
+ var lazy = class {
399
+ constructor(cb) {
400
+ this.content = void 0;
401
+ this._cb = cb;
402
+ }
403
+ async load() {
404
+ this.content = await this._cb();
405
+ if (typeof this.content === "function") {
406
+ this.content = await this.content;
363
407
  } 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);
391
- }
392
- }
393
- }
394
- if (ele) {
395
- cradovaDispatchTrack([ele], state);
408
+ this.content = await this.content;
396
409
  }
410
+ this.content = this.content.default;
397
411
  }
398
- return updated;
399
- }
412
+ };
400
413
 
401
- // lib/utils/simplestore.ts
402
- var simpleStore = class {
403
- constructor(initial) {
414
+ // lib/utils/createSignal.ts
415
+ var createSignal = class {
416
+ constructor(initial, props) {
417
+ this.persistName = "";
418
+ this.actions = {};
404
419
  this.ref = [];
405
420
  this.value = initial;
421
+ if (props && props.persistName) {
422
+ this.persistName = props.persistName;
423
+ const key = localStorage.getItem(props.persistName);
424
+ if (key && key !== "undefined") {
425
+ this.value = JSON.parse(key);
426
+ }
427
+ if (typeof initial === "object") {
428
+ for (const key2 in initial) {
429
+ if (!Object.prototype.hasOwnProperty.call(this.value, key2)) {
430
+ this.value[key2] = initial[key2];
431
+ }
432
+ }
433
+ }
434
+ }
406
435
  }
407
436
  set(value, shouldRefRender) {
408
437
  if (typeof value === "function") {
@@ -410,166 +439,24 @@ var simpleStore = class {
410
439
  } else {
411
440
  this.value = value;
412
441
  }
413
- if (this.ref.length && shouldRefRender !== false) {
414
- this.updateState();
442
+ if (this.persistName) {
443
+ localStorage.setItem(this.persistName, JSON.stringify(this.value));
415
444
  }
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
- );
445
+ if (this.ref.length && shouldRefRender !== false) {
446
+ this._updateState();
424
447
  }
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
- }
448
+ if (this.callback) {
449
+ this.callback(this.value);
437
450
  }
438
451
  }
439
- setKey(name, value, shouldRefRender) {
452
+ setKey(key, value, shouldRefRender) {
440
453
  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;
454
+ this.value[key] = value;
455
+ if (this.persistName) {
456
+ localStorage.setItem(this.persistName, JSON.stringify(this.value));
445
457
  }
446
458
  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
- }
463
- };
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;
478
- }
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);
489
- }
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);
572
- }
459
+ this._updateState();
573
460
  }
574
461
  if (this.callback) {
575
462
  this.callback(this.value);
@@ -583,7 +470,7 @@ var createSignal = class {
583
470
  }
584
471
  }
585
472
  createAction(key, action) {
586
- if (typeof key === "string" && typeof action === "function") {
473
+ if (typeof key === "string") {
587
474
  this.actions[key] = action;
588
475
  } else {
589
476
  if (typeof key === "object" && !action) {
@@ -600,27 +487,88 @@ var createSignal = class {
600
487
  }
601
488
  }
602
489
  fireAction(key, data2) {
603
- try {
604
- if (!(typeof key === "string" && this.actions[key])) {
605
- throw Error("");
490
+ if (this.actions[key].updateState) {
491
+ this.actions[key].updateState(this, data2);
492
+ this._updateState(key, data2);
493
+ return;
494
+ } else {
495
+ if (typeof this.actions[key] === "function") {
496
+ this.actions[key](this, data2);
497
+ this._updateState(key, data2);
498
+ return;
606
499
  }
607
- } catch (_e) {
608
- throw Error("\u2718 Cradova err : action " + key + " does not exist!");
609
500
  }
610
- this.actions[key](this, data2);
501
+ throw Error("\u2718 Cradova err : action " + key + " does not exist!");
611
502
  }
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
- }
503
+ bind(prop) {
504
+ if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
505
+ return [this, prop];
506
+ } else {
507
+ throw new Error(
508
+ "\u2718 Cradova err : can't bind an unavailable property! " + prop
509
+ );
510
+ }
511
+ }
512
+ _updateState(name, data2) {
513
+ if (name && data2) {
514
+ this.ref.map((ent) => {
515
+ if (ent._event === name) {
516
+ if (ent._element_property && ent._signalProperty) {
517
+ ent.ref.updateState({
518
+ [ent._element_property]: data2[ent._signalProperty]
519
+ });
520
+ return;
521
+ }
522
+ if (ent._element_property) {
523
+ ent.ref.updateState({
524
+ [ent._element_property]: data2
525
+ });
526
+ return;
527
+ }
528
+ if (ent._signalProperty) {
529
+ ent.ref.updateState(data2[ent._signalProperty]);
530
+ return;
531
+ }
532
+ }
533
+ });
621
534
  } else {
622
- throw new Error("\u2718 Cradova err : Invalid ref component" + Ref2);
535
+ for (let i2 = 0; i2 < this.ref.length; i2++) {
536
+ const ent = this.ref[i2];
537
+ if (ent._element_property && ent._signalProperty) {
538
+ ent.ref.updateState({
539
+ [ent._element_property]: this.value[ent._signalProperty]
540
+ });
541
+ continue;
542
+ }
543
+ if (ent._element_property) {
544
+ ent.ref.updateState({
545
+ [ent._element_property]: this.value
546
+ });
547
+ continue;
548
+ }
549
+ if (ent._signalProperty) {
550
+ ent.ref.updateState(this.value[ent._signalProperty]);
551
+ continue;
552
+ }
553
+ }
554
+ }
555
+ }
556
+ bindRef(ref, binding) {
557
+ if (ref.render) {
558
+ ref.render = ref.render.bind(ref, this.value);
559
+ }
560
+ if (ref && ref.updateState) {
561
+ this.ref.push({
562
+ ref,
563
+ _signalProperty: binding.signalProperty,
564
+ _element_property: binding._element_property,
565
+ _event: binding.event
566
+ });
567
+ return;
623
568
  }
569
+ throw new Error(
570
+ "\u2718 Cradova err : Invalid parameters for binding ref to simple store"
571
+ );
624
572
  }
625
573
  listen(callback) {
626
574
  this.callback = callback;
@@ -640,63 +588,88 @@ RouterBox["nextRouteController"] = null;
640
588
  RouterBox["lastNavigatedRoute"] = null;
641
589
  RouterBox["pageShow"] = null;
642
590
  RouterBox["pageHide"] = null;
643
- RouterBox["errorHandler"] = {};
591
+ RouterBox["errorHandler"] = null;
644
592
  RouterBox["params"] = {};
645
593
  RouterBox["routes"] = {};
646
594
  var checker = (url) => {
647
595
  if (RouterBox.routes[url]) {
648
596
  return [RouterBox.routes[url], { path: url }];
649
597
  }
598
+ if (RouterBox.routes[url + "/"]) {
599
+ return [RouterBox.routes[url], { path: url }];
600
+ }
650
601
  for (const path in RouterBox.routes) {
651
602
  if (!path.includes(":")) {
652
603
  continue;
653
604
  }
605
+ if (url.endsWith("/")) {
606
+ url = url.slice(0, path.length - 2);
607
+ }
654
608
  const urlFixtures = url.split("/");
655
609
  const pathFixtures = path.split("/");
610
+ let fixturesX = 0;
611
+ let fixturesY = 0;
612
+ urlFixtures.shift();
613
+ pathFixtures.shift();
656
614
  if (pathFixtures.length === urlFixtures.length) {
657
- urlFixtures.shift();
658
- pathFixtures.shift();
659
- let isIt = true;
660
- const routesParams = {};
615
+ const routesParams = { _path: "" };
661
616
  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;
617
+ if (pathFixtures[i2].includes(":")) {
618
+ fixturesY += 1;
619
+ continue;
670
620
  }
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
- );
621
+ if (urlFixtures[i2] === pathFixtures[i2] && pathFixtures.indexOf(urlFixtures[i2]) === pathFixtures.lastIndexOf(urlFixtures[i2])) {
622
+ fixturesX += 1;
675
623
  }
676
624
  }
677
- if (isIt) {
625
+ if (fixturesX + fixturesY === pathFixtures.length) {
678
626
  for (let i2 = 0; i2 < pathFixtures.length; i2++) {
679
627
  if (pathFixtures[i2].includes(":")) {
680
628
  routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
681
629
  }
682
630
  }
683
- routesParams.path = path;
631
+ routesParams._path = path;
684
632
  return [RouterBox.routes[path], routesParams];
685
633
  }
686
634
  }
687
635
  }
688
636
  return [];
689
637
  };
690
- Router.route = function(path = "/", screen) {
691
- if (!screen.Activate && screen.name) {
638
+ RouterBox.route = (path, screen) => {
639
+ if (!screen || !screen._Activate) {
692
640
  console.error(" \u2718 Cradova err: not a valid screen ", screen);
693
641
  throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
694
642
  }
643
+ RouterBox.routes[path] = screen;
644
+ return RouterBox.routes[path];
645
+ };
646
+ Router.BrowserRoutes = function(obj) {
647
+ for (const path in obj) {
648
+ let screen = obj[path];
649
+ if (screen.catch || typeof screen === "function") {
650
+ RouterBox["routes"][path] = async () => {
651
+ if (typeof screen === "function") {
652
+ screen = await screen();
653
+ } else {
654
+ screen = await screen;
655
+ }
656
+ return RouterBox.route(path, screen.default);
657
+ };
658
+ } else {
659
+ RouterBox.route(path, screen);
660
+ }
661
+ }
662
+ Router.mount();
663
+ };
664
+ Router.delegateScreen = function(path = "/", screen) {
695
665
  RouterBox.routes[path] = {
696
- controller: (params, force) => screen.Activate(params, force),
666
+ controller: async (params, force) => await screen.Activate(params, force),
697
667
  packager: async (params) => await screen.package(params),
698
- deactivate: () => {
699
- screen.deActivate();
668
+ deactivate: async () => {
669
+ await screen.deActivate();
670
+ },
671
+ paramData: (data2) => {
672
+ screen.paramData = data2;
700
673
  }
701
674
  };
702
675
  if (typeof screen.errorHandler === "function") {
@@ -724,28 +697,31 @@ Router.navigate = function(href, data2 = null, force = false) {
724
697
  if (route) {
725
698
  RouterBox["nextRouteController"] = route;
726
699
  RouterBox.params.params = params;
700
+ route._paramData = params;
727
701
  RouterBox.params.data = data2 || null;
728
702
  link2 = href;
729
703
  RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
730
704
  window.history.pushState({}, "", link2);
731
705
  }
732
- (async () => {
733
- await RouterBox.router(null, force);
734
- })();
706
+ RouterBox.router(null, force);
735
707
  }
736
708
  };
737
709
  RouterBox.router = async function(e, force = false) {
738
710
  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;
711
+ if (e) {
712
+ const Alink = e.target.tagName === "A" && e.target;
713
+ if (Alink) {
714
+ if (Alink.href.includes("#")) {
715
+ const l = Alink.href.split("#");
716
+ document.getElementById("#" + l[l.length - 1])?.scrollIntoView();
717
+ return;
718
+ }
719
+ if (Alink.href.includes("javascript")) {
720
+ return;
721
+ }
722
+ e.preventDefault();
723
+ url = new URL(Alink.href).pathname;
746
724
  }
747
- e.preventDefault();
748
- url = new URL(Alink.href).pathname;
749
725
  }
750
726
  if (!url) {
751
727
  url = window.location.pathname;
@@ -759,26 +735,29 @@ RouterBox.router = async function(e, force = false) {
759
735
  } else {
760
736
  [route, params] = checker(url);
761
737
  }
762
- if (route) {
738
+ if (typeof route !== "undefined") {
763
739
  try {
764
740
  if (params) {
765
741
  RouterBox.params.params = params;
766
742
  }
767
- RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
768
- await route.controller(force);
743
+ if (!route._Activate && typeof route === "function") {
744
+ route = await route();
745
+ }
746
+ if (route._delegatedRoutes !== -1 && route._delegatedRoutes !== 1) {
747
+ route._delegatedRoutes = true;
748
+ route = new Screen({
749
+ name: route._name,
750
+ template: route._html
751
+ });
752
+ RouterBox.routes[url] = route;
753
+ }
754
+ await route._Activate(force);
755
+ RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
769
756
  RouterBox["lastNavigatedRoute"] = url;
770
757
  RouterBox["lastNavigatedRouteController"] = route;
771
758
  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
759
  } catch (error) {
781
- const errorHandler = RouterBox.errorHandler["all"] || RouterBox.errorHandler[RouterBox.params.params.path];
760
+ const errorHandler = RouterBox.routes[RouterBox.params.params._path].errorHandler || RouterBox.errorHandler;
782
761
  if (errorHandler) {
783
762
  errorHandler(error);
784
763
  }
@@ -818,264 +797,180 @@ Router.packageScreen = async function(path, data2) {
818
797
  console.error(" \u2718 Cradova err: no screen with path " + path);
819
798
  throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
820
799
  }
821
- await RouterBox.routes[path].packager(data2);
800
+ let [route, params] = checker(path);
801
+ if (!route._Activate && typeof route === "function") {
802
+ route = await route();
803
+ }
804
+ route._package(Object.assign(data2, params || {}));
805
+ route._packed = true;
822
806
  };
823
807
  Router.getParams = function() {
824
808
  return RouterBox["params"];
825
809
  };
826
- Router["addErrorHandler"] = function(callback, path) {
810
+ Router["addErrorHandler"] = function(callback) {
827
811
  if (typeof callback === "function") {
828
- RouterBox["errorHandler"][path || "all"] = callback;
812
+ RouterBox["errorHandler"] = callback;
829
813
  } else {
830
814
  throw new Error(
831
815
  " \u2718 Cradova err: callback for ever event event is not a function"
832
816
  );
833
817
  }
834
818
  };
835
- window.addEventListener("pageshow", RouterBox.router);
836
- window.addEventListener("popstate", (e) => {
837
- e.preventDefault();
838
- RouterBox.router();
839
- });
819
+ Router.mount = () => {
820
+ window.addEventListener("pageshow", RouterBox.router);
821
+ window.addEventListener("popstate", (e) => {
822
+ e.preventDefault();
823
+ RouterBox.router();
824
+ });
825
+ };
840
826
 
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;
827
+ // lib/utils/tags.ts
828
+ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
829
+ let beforeMount = null;
830
+ let props = null, text = null;
831
+ if (ElementChildrenAndPropertyList.length) {
832
+ for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
833
+ let child = ElementChildrenAndPropertyList[i2];
834
+ if (typeof child === "function") {
835
+ child = child();
836
+ if (typeof child === "function") {
837
+ child = child();
838
+ }
839
+ }
840
+ try {
841
+ if (isNode(child)) {
842
+ element.appendChild(child);
843
+ continue;
844
+ }
845
+ } catch (error) {
846
+ console.log(element, ElementChildrenAndPropertyList);
847
+ console.log(error);
848
+ }
849
+ if (Array.isArray(child)) {
850
+ element.appendChild(Rhoda(child));
851
+ continue;
852
+ }
853
+ if (typeof child === "string" || typeof child === "number") {
854
+ text = child;
855
+ continue;
856
+ }
857
+ if (typeof child === "object") {
858
+ if (!props) {
859
+ props = child;
860
+ } else {
861
+ props = Object.assign(props, child);
862
+ }
863
+ continue;
864
+ }
865
+ if (typeof child !== "undefined") {
866
+ console.error(" \u2718 Cradova err: got", { child });
867
+ throw new Error(
868
+ " \u2718 Cradova err: invalid child type: (" + typeof child + ")"
869
+ );
870
+ }
860
871
  }
872
+ } else {
873
+ return element;
861
874
  }
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);
875
+ if (typeof props === "object" && element) {
876
+ for (const prop in props) {
877
+ if (prop === "style" && typeof props[prop] === "object") {
878
+ for (const [k, v] of Object.entries(props[prop])) {
879
+ if (typeof element.style[k] !== "undefined" && k !== "src") {
880
+ element.style[k] = v;
881
+ } else {
882
+ throw new Error(
883
+ "\u2718 Cradova err : " + k + " is not a valid css style property"
884
+ );
878
885
  }
879
886
  }
880
- } else {
881
- if (!isNode(fuc) && typeof fuc !== "string") {
882
- throw new Error(
883
- " \u2718 Cradova err: only parent with descendants is valid"
884
- );
887
+ continue;
888
+ }
889
+ if (typeof element.style[prop] !== "undefined" && prop !== "src") {
890
+ element.style[prop] = props[prop];
891
+ continue;
892
+ }
893
+ if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
894
+ text = props[prop];
895
+ continue;
896
+ }
897
+ if (prop === "beforeMount") {
898
+ beforeMount = props["beforeMount"];
899
+ continue;
900
+ }
901
+ if (prop === "stateID") {
902
+ element.setAttribute("data-cra-id", props[prop]);
903
+ continue;
904
+ }
905
+ if (prop.includes("$")) {
906
+ element.setAttribute("data-" + prop.split("$")[1], props[prop]);
907
+ continue;
908
+ }
909
+ if (Array.isArray(props[prop]) && props[prop][0] instanceof createSignal) {
910
+ element.updateState = dispatch.bind(null, element);
911
+ props[prop][0].bindRef(element, {
912
+ _element_property: prop,
913
+ signalProperty: props[prop][1]
914
+ });
915
+ continue;
916
+ }
917
+ if (prop === "shouldUpdate" && props[prop] === true) {
918
+ element.updateState = dispatch.bind(void 0, element);
919
+ continue;
920
+ }
921
+ if (prop === "afterMount" && typeof props["afterMount"] === "function") {
922
+ const av = () => {
923
+ props["afterMount"].apply(element);
924
+ window.removeEventListener("cradova-aftermount", av);
925
+ };
926
+ window.addEventListener("cradova-aftermount", av);
927
+ continue;
928
+ }
929
+ try {
930
+ if (typeof element[prop] !== "undefined") {
931
+ element[prop] = props[prop];
885
932
  } else {
886
- this.template.innerHTML = "";
887
- this.template.appendChild(fuc);
933
+ if (prop.includes("data-")) {
934
+ element.setAttribute(prop, props[prop]);
935
+ continue;
936
+ }
937
+ element[prop] = props[prop];
938
+ if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && prop !== "disabled" && !prop.includes("aria")) {
939
+ console.warn(" \u2718 Cradova err: invalid html attribute ", {
940
+ prop
941
+ });
942
+ } else {
943
+ continue;
944
+ }
888
945
  }
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);
946
+ } catch (error) {
947
+ console.error(" \u2718 Cradova err: invalid html attribute ", { props });
948
+ console.error(" \u2718 Cradova err: ", error);
899
949
  }
900
950
  }
901
951
  }
902
- onActivate(cb) {
903
- this.callBack = cb;
952
+ if (text) {
953
+ element.appendChild(document.createTextNode(text));
904
954
  }
905
- onDeactivate(cb) {
906
- this.deCallBack = cb;
955
+ if (typeof beforeMount === "function") {
956
+ beforeMount.apply(element);
907
957
  }
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();
958
+ if (element.tagName === "A") {
959
+ if (element.href.includes(window.location.origin)) {
960
+ element.addEventListener("click", (e) => {
961
+ e.preventDefault();
962
+ Router.navigate(element.pathname);
963
+ });
944
964
  }
945
- window.dispatchEvent(cradovaAftermountEvent);
946
- window.scrollTo(0, 0);
947
965
  }
966
+ return element;
948
967
  };
949
-
950
- // lib/utils/tags.ts
951
968
  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
- );
1004
- }
1005
- }
1006
- continue;
1007
- }
1008
- if (typeof element.style[prop] !== "undefined" && prop !== "src") {
1009
- element.style[prop] = props[prop];
1010
- continue;
1011
- }
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;
1056
- }
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;
1064
- }
1065
- }
1066
- } catch (error) {
1067
- console.error(" \u2718 Cradova err: invalid html attribute ", { props });
1068
- console.error(" \u2718 Cradova err: ", error);
1069
- }
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;
969
+ return (...bo) => {
970
+ return makeElement(
971
+ document.createElement(element_initials),
972
+ ...bo
973
+ );
1079
974
  };
1080
975
  };
1081
976
  var a = cra("a");
@@ -1191,6 +1086,203 @@ var val = cra("val");
1191
1086
  var video = cra("video");
1192
1087
  var wbr = cra("wbr");
1193
1088
 
1089
+ // lib/utils/ajax.ts
1090
+ function Ajax(url, opts = {}) {
1091
+ const { method, data: data2, header: header2, callbacks } = opts;
1092
+ if (typeof url !== "string") {
1093
+ throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
1094
+ }
1095
+ return new Promise(function(resolve) {
1096
+ const ajax = new XMLHttpRequest();
1097
+ const formData = new FormData();
1098
+ if (callbacks && typeof callbacks === "object") {
1099
+ for (const [k, v] of Object.entries(callbacks)) {
1100
+ if (typeof v === "function" && ajax[k]) {
1101
+ ajax[k] = v;
1102
+ }
1103
+ }
1104
+ }
1105
+ ajax.addEventListener("load", function() {
1106
+ resolve(ajax.response);
1107
+ });
1108
+ if (data2 && typeof data2 === "object") {
1109
+ for (const [k, v] of Object.entries(data2)) {
1110
+ let value = v;
1111
+ if (typeof value === "object" && value && !value.name) {
1112
+ value = JSON.stringify(value);
1113
+ }
1114
+ formData.set(k, value);
1115
+ }
1116
+ }
1117
+ ajax.addEventListener("error", () => {
1118
+ console.error(
1119
+ "\u2718 Cradova Ajax err : ",
1120
+ ajax.response || "ERR_INTERNET_DISCONNECTED"
1121
+ );
1122
+ if (!navigator.onLine) {
1123
+ resolve(
1124
+ JSON.stringify({
1125
+ message: `this device is offline!`
1126
+ })
1127
+ );
1128
+ } else {
1129
+ resolve(
1130
+ JSON.stringify({
1131
+ message: `problem with the action, please try again!`
1132
+ })
1133
+ );
1134
+ }
1135
+ });
1136
+ if (!method) {
1137
+ ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
1138
+ } else {
1139
+ ajax.open(method, url, true);
1140
+ }
1141
+ if (header2 && typeof header2 === "object") {
1142
+ Object.keys(header2).forEach(function(key) {
1143
+ ajax.setRequestHeader(key, header2[key]);
1144
+ });
1145
+ }
1146
+ ajax.send(formData);
1147
+ });
1148
+ }
1149
+
1150
+ // lib/utils/Screen.ts
1151
+ var Screen = class {
1152
+ constructor(cradova_screen_initials) {
1153
+ this._secondaryChildren = [];
1154
+ this.errorHandler = null;
1155
+ this._packed = false;
1156
+ this._template = document.createElement("div");
1157
+ this._persist = true;
1158
+ this._params = null;
1159
+ this._delegatedRoutesCount = -1;
1160
+ const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
1161
+ if (typeof template2 !== "function") {
1162
+ console.error(" \u2718 Cradova err: expected a screen but got ", template2);
1163
+ throw new Error(
1164
+ " \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
1165
+ );
1166
+ }
1167
+ this._html = template2;
1168
+ this._name = name;
1169
+ this._transition = transition || "";
1170
+ this._template.setAttribute("id", "cradova-screen-set");
1171
+ if (renderInParallel === true) {
1172
+ this._delegatedRoutesCount = 1;
1173
+ } else {
1174
+ if (typeof persist === "boolean") {
1175
+ this._persist = persist;
1176
+ }
1177
+ }
1178
+ }
1179
+ get _delegatedRoutes() {
1180
+ if (this._delegatedRoutesCount > 1e3) {
1181
+ return -1;
1182
+ }
1183
+ return this._delegatedRoutesCount;
1184
+ }
1185
+ set _delegatedRoutes(count) {
1186
+ if (count) {
1187
+ this._delegatedRoutesCount += 1;
1188
+ }
1189
+ }
1190
+ get _paramData() {
1191
+ return this._params;
1192
+ }
1193
+ set _paramData(params) {
1194
+ if (params) {
1195
+ this._params = params;
1196
+ }
1197
+ }
1198
+ setErrorHandler(errorHandler) {
1199
+ this.errorHandler = errorHandler;
1200
+ }
1201
+ async _package() {
1202
+ if (typeof this._html === "function") {
1203
+ let fuc = await this._html.apply(this, this._data);
1204
+ if (typeof fuc === "function") {
1205
+ fuc = fuc();
1206
+ if (!isNode(fuc)) {
1207
+ throw new Error(
1208
+ " \u2718 Cradova err: only parent with descendants is valid"
1209
+ );
1210
+ } else {
1211
+ if (fuc) {
1212
+ this._template.innerHTML = "";
1213
+ this._template.appendChild(fuc);
1214
+ }
1215
+ }
1216
+ } else {
1217
+ if (!isNode(fuc) && typeof fuc !== "string") {
1218
+ throw new Error(
1219
+ " \u2718 Cradova err: only parent with descendants is valid"
1220
+ );
1221
+ } else {
1222
+ this._template.innerHTML = "";
1223
+ this._template.appendChild(fuc);
1224
+ }
1225
+ }
1226
+ }
1227
+ if (!this._template.firstChild) {
1228
+ throw new Error(
1229
+ " \u2718 Cradova err: no screen is rendered, may have been past wrongly."
1230
+ );
1231
+ }
1232
+ if (this._secondaryChildren.length) {
1233
+ let i2 = 0;
1234
+ while (this._secondaryChildren.length - i2 !== 0) {
1235
+ this.template.appendChild(this._secondaryChildren[i2]);
1236
+ i2++;
1237
+ }
1238
+ }
1239
+ }
1240
+ onActivate(cb) {
1241
+ this._callBack = cb;
1242
+ }
1243
+ onDeactivate(cb) {
1244
+ this._deCallBack = cb;
1245
+ }
1246
+ addChild(...addOns) {
1247
+ this._secondaryChildren.push(frag(addOns));
1248
+ }
1249
+ async _deActivate() {
1250
+ if (this._deCallBack) {
1251
+ await this._deCallBack();
1252
+ }
1253
+ if (this._transition) {
1254
+ this._template.classList.remove(this._transition);
1255
+ }
1256
+ }
1257
+ async _Activate(force) {
1258
+ if (!this._persist || force) {
1259
+ await this._package();
1260
+ } else {
1261
+ if (!this._packed) {
1262
+ this._packed = true;
1263
+ await this._package();
1264
+ }
1265
+ }
1266
+ const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
1267
+ if (!doc) {
1268
+ throw new Error(
1269
+ " \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
1270
+ );
1271
+ }
1272
+ if (this._transition) {
1273
+ this._template.classList.add(this._transition);
1274
+ }
1275
+ doc.innerHTML = "";
1276
+ doc.appendChild(this._template);
1277
+ document.title = this._name;
1278
+ if (this._callBack) {
1279
+ await this._callBack();
1280
+ }
1281
+ window.dispatchEvent(cradovaAftermountEvent);
1282
+ window.scrollTo(0, 0);
1283
+ }
1284
+ };
1285
+
1194
1286
  // lib/index.ts
1195
1287
  var make = function(txx) {
1196
1288
  if (!txx) {
@@ -1260,183 +1352,47 @@ var make = function(txx) {
1260
1352
  const className = classes && classes.join(" ");
1261
1353
  return { tag, className, ID, innerValue };
1262
1354
  };
1263
- var _ = (...element_initials) => {
1264
- if (typeof element_initials[0] !== "string") {
1265
- return frag(element_initials);
1266
- }
1267
- if (element_initials.raw) {
1355
+ var _2 = (...element_initials) => {
1356
+ if (element_initials[0].raw) {
1268
1357
  element_initials[0] = element_initials["raw"][0];
1269
1358
  }
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];
1359
+ if (typeof element_initials[0] !== "string") {
1360
+ return frag(element_initials);
1276
1361
  }
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;
1324
- }
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
- );
1359
- }
1360
- }
1361
- continue;
1362
- }
1363
- if (typeof element.style[prop] !== "undefined" && prop !== "src") {
1364
- element.style[prop] = props[prop];
1365
- continue;
1366
- }
1367
- if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
1368
- text = props[prop];
1369
- continue;
1370
- }
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
- }
1362
+ const initials = make(element_initials.shift());
1363
+ let props = void 0;
1364
+ let element;
1365
+ try {
1366
+ element = document.createElement(initials.tag.trim());
1367
+ } catch (error) {
1368
+ throw new TypeError(" \u2718 Cradova err: invalid tag given " + initials.tag);
1369
+ }
1370
+ if (initials.className) {
1371
+ if (props) {
1372
+ props["className"] = initials.className.trim();
1373
+ } else {
1374
+ props = { className: initials.className.trim() };
1426
1375
  }
1427
- if (text) {
1428
- element.appendChild(document.createTextNode(text));
1376
+ }
1377
+ if (initials.ID) {
1378
+ if (props) {
1379
+ props["id"] = initials.ID.trim();
1380
+ } else {
1381
+ props = { id: initials.ID.trim() };
1429
1382
  }
1430
- if (typeof beforeMount === "function") {
1431
- beforeMount.apply(element);
1383
+ }
1384
+ if (initials.innerValue) {
1385
+ if (props) {
1386
+ props["innerText"] = initials.innerValue;
1387
+ } else {
1388
+ props = { innerText: initials.innerValue };
1432
1389
  }
1433
- return element;
1434
- };
1390
+ }
1391
+ return makeElement(element, props, ...element_initials);
1435
1392
  };
1436
1393
  Init();
1437
- var lib_default = _;
1394
+ var lib_default = _2;
1438
1395
  export {
1439
- simpleStore as $,
1440
1396
  Ajax,
1441
1397
  Ref,
1442
1398
  Router,
@@ -1503,11 +1459,13 @@ export {
1503
1459
  ins,
1504
1460
  kbd,
1505
1461
  label,
1462
+ lazy,
1506
1463
  legend,
1507
1464
  li,
1508
1465
  link,
1509
1466
  loop,
1510
1467
  main,
1468
+ makeElement,
1511
1469
  map,
1512
1470
  mark,
1513
1471
  math,
@@ -1563,3 +1521,4 @@ export {
1563
1521
  video,
1564
1522
  wbr
1565
1523
  };
1524
+ //! value could be a promise