cradova 2.2.3 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,135 +1,56 @@
1
1
  // lib/utils/init.ts
2
2
  var Init = function() {
3
- if (!document.querySelector("[data-cra-id=cradova-app-wrapper]")) {
3
+ if (!document.querySelector("[data-wrapper=app]")) {
4
4
  const Wrapper = document.createElement("div");
5
- Wrapper.setAttribute("data-cra-id", "cradova-app-wrapper");
5
+ Wrapper.setAttribute("data-wrapper", "app");
6
6
  document.body.appendChild(Wrapper);
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;
10
+ // lib/utils/fns.ts
11
+ var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
12
+ var cradovaEvent = class {
13
+ constructor() {
14
+ this.listeners = {};
15
+ }
16
+ addEventListener(eventName, callback) {
17
+ if (!this.listeners[eventName]) {
18
+ this.listeners[eventName] = [];
16
19
  }
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
- }
20
+ this.listeners[eventName].push(callback);
21
+ }
22
+ removeEventListener(eventName, callback) {
23
+ if (this.listeners[eventName]) {
24
+ const index = this.listeners[eventName].indexOf(callback);
25
+ if (index !== -1) {
26
+ this.listeners[eventName].splice(index, 1);
73
27
  }
74
- } else {
75
- throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
76
28
  }
77
29
  }
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
- }
30
+ dispatchEvent(eventName, eventArgs) {
31
+ const eventListeners = this.listeners[eventName];
32
+ if (eventListeners) {
33
+ for (let i2 = 0; i2 < eventListeners.length; i2++) {
34
+ eventListeners[i2](eventArgs);
103
35
  }
104
36
  }
105
- if (ele) {
106
- cradovaDispatchTrack([ele], state);
107
- }
108
37
  }
109
- return updated;
110
- }
111
-
112
- // lib/utils/fns.ts
113
- var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
114
- var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
115
- function uuid() {
116
- let t = Date.now ? +Date.now() : +new Date();
117
- return "cradova-id-xxxxxx".replace(/[x]/g, function(e) {
118
- const r = (t + 16 * Math.random()) % 16 | 0;
119
- return ("x" === e ? r : 7 & r | 8).toString(16);
120
- });
121
- }
38
+ };
39
+ var CradovaEvent = new cradovaEvent();
122
40
  function Rhoda(l) {
123
41
  const fg = new DocumentFragment();
124
42
  for (let ch of l) {
125
43
  if (Array.isArray(ch)) {
126
44
  fg.appendChild(Rhoda(ch));
127
45
  } else {
128
- if (typeof ch === "function") {
129
- ch = ch();
46
+ if (ch?.render) {
47
+ ch = ch.render();
130
48
  }
131
49
  if (typeof ch === "function") {
132
50
  ch = ch();
51
+ if (typeof ch === "function") {
52
+ ch = ch();
53
+ }
133
54
  }
134
55
  if (typeof ch === "string" || typeof ch === "number") {
135
56
  fg.appendChild(document.createTextNode(ch));
@@ -148,45 +69,20 @@ function Rhoda(l) {
148
69
  }
149
70
  return fg;
150
71
  }
151
- function css(identifier, properties) {
152
- if (typeof identifier === "string" && typeof properties === "undefined") {
72
+ function css(identifier) {
73
+ if (Array.isArray(identifier)) {
74
+ identifier = identifier[0];
75
+ }
76
+ if (typeof identifier === "string") {
153
77
  let styTag = document.querySelector("style");
154
78
  if (styTag !== null) {
155
- identifier += styTag.textContent;
156
- styTag.textContent = identifier;
79
+ styTag.textContent = identifier + styTag.textContent;
157
80
  return;
158
81
  }
159
82
  styTag = document.createElement("style");
160
83
  styTag.textContent = identifier;
161
84
  document.head.appendChild(styTag);
162
- return;
163
85
  }
164
- if (!properties) {
165
- return;
166
- }
167
- const styS = "" + identifier + `{
168
- `;
169
- const styE = `}
170
- `;
171
- let style2 = "", totalStyle = "";
172
- for (const [k, v] of Object.entries(properties)) {
173
- style2 += "" + k + ": " + v + `;
174
- `;
175
- }
176
- let styleTag = document.querySelector("style");
177
- if (styleTag !== null) {
178
- totalStyle += styleTag.innerHTML;
179
- totalStyle += styS + style2 + styE;
180
- styleTag.innerHTML = totalStyle;
181
- return;
182
- }
183
- styleTag = document.createElement("style");
184
- totalStyle += styleTag.innerHTML + `
185
-
186
- `;
187
- totalStyle += styS + style2 + styE;
188
- styleTag.innerHTML = totalStyle;
189
- document.head.appendChild(styleTag);
190
86
  }
191
87
  function assert(condition, ...elements) {
192
88
  if (condition) {
@@ -210,28 +106,28 @@ function assertOr(condition, ifTrue, ifFalse) {
210
106
  }
211
107
  var Ref = class {
212
108
  constructor(component) {
213
- this.stateID = uuid();
214
109
  this.effects = [];
215
110
  this.effectuate = null;
216
111
  this.rendered = false;
217
112
  this.published = false;
218
113
  this.hasFirstStateUpdateRun = false;
219
114
  this.preRendered = null;
115
+ this.reference = new reference();
220
116
  this.component = component.bind(this);
221
117
  }
222
118
  preRender(data2) {
223
119
  const chtml = this.component(data2);
224
120
  if (chtml instanceof HTMLElement) {
225
- chtml.setAttribute("data-cra-id", this.stateID);
226
121
  this.preRendered = chtml;
227
122
  } else {
228
- this.preRendered = chtml({ stateID: this.stateID });
123
+ this.preRendered = chtml();
229
124
  }
230
- if (typeof this.preRendered === "undefined") {
125
+ if (!this.preRendered) {
231
126
  throw new Error(
232
- " \u2718 Cradova err : Invalid component type for cradova Ref, got - " + this.preRendered
127
+ " \u2718 Cradova err : Invalid component type for cradova Ref got - " + this.preRendered
233
128
  );
234
129
  }
130
+ this.reference._appendDomForce("reference", this.preRendered);
235
131
  }
236
132
  destroyPreRendered() {
237
133
  this.preRendered = null;
@@ -244,12 +140,11 @@ var Ref = class {
244
140
  if (!this.preRendered) {
245
141
  const chtml = this.component(data2);
246
142
  if (chtml instanceof HTMLElement) {
247
- chtml.setAttribute("data-cra-id", this.stateID);
248
143
  element = chtml;
249
144
  } else {
250
- element = chtml({ stateID: this.stateID });
145
+ element = chtml();
251
146
  }
252
- if (typeof element === "undefined") {
147
+ if (!element) {
253
148
  throw new Error(
254
149
  " \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
255
150
  );
@@ -260,21 +155,23 @@ var Ref = class {
260
155
  }
261
156
  const av = async () => {
262
157
  await this.effector.apply(this);
263
- window.removeEventListener("cradova-aftermount", av);
158
+ CradovaEvent.removeEventListener("cradovaAftermountEvent", av);
264
159
  };
265
- window.addEventListener("cradova-aftermount", av);
160
+ CradovaEvent.addEventListener("cradovaAftermountEvent", av);
266
161
  this.effector();
267
162
  this.published = true;
268
163
  this.rendered = true;
269
164
  if (!element) {
270
165
  element = this.preRendered;
271
166
  }
167
+ this.reference._appendDomForce("reference", element);
272
168
  return element;
273
169
  }
274
170
  instance() {
275
- return dispatch(this.stateID, {
276
- cradovaDispatchTrackBreak: true
277
- });
171
+ return this.reference.reference;
172
+ }
173
+ _setExtra(Extra) {
174
+ this.Signal = Extra;
278
175
  }
279
176
  effect(fn) {
280
177
  if (!this.rendered) {
@@ -320,34 +217,38 @@ var Ref = class {
320
217
  return;
321
218
  }
322
219
  this.published = false;
323
- const guy = dispatch(this.stateID, {
324
- cradovaDispatchTrackBreak: true
325
- });
326
- if (!guy) {
220
+ if (!this.reference.reference) {
327
221
  return;
328
222
  }
329
223
  const chtml = this.component(data2);
330
224
  let element;
331
225
  if (chtml instanceof HTMLElement) {
332
- chtml.setAttribute("data-cra-id", this.stateID);
333
226
  element = chtml;
334
227
  } else {
335
- element = chtml({ stateID: this.stateID });
228
+ element = chtml();
229
+ }
230
+ if (!element) {
231
+ throw new Error(
232
+ " \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
233
+ );
336
234
  }
337
235
  try {
338
- guy.insertAdjacentElement("beforebegin", element);
339
- if (guy.parentElement) {
340
- guy.parentElement.removeChild(guy);
236
+ this.reference.reference.insertAdjacentElement("beforebegin", element);
237
+ if (this.reference.reference.parentElement) {
238
+ this.reference.reference.parentElement.removeChild(
239
+ this.reference.reference
240
+ );
341
241
  } else {
342
- guy.remove();
242
+ this.reference.reference.remove();
343
243
  }
244
+ this.reference._appendDomForce("reference", element);
344
245
  } catch (e0) {
345
246
  console.error(e0);
346
247
  }
347
248
  this.published = true;
348
249
  }
349
250
  remove() {
350
- dispatch(this.stateID, { remove: true });
251
+ this.reference.reference.remove();
351
252
  }
352
253
  };
353
254
  var frag = function(children) {
@@ -368,10 +269,8 @@ var frag = function(children) {
368
269
  par.appendChild(document.createTextNode(a2));
369
270
  continue;
370
271
  }
371
- {
372
- console.error(" \u2718 Cradova err: wrong element type" + a2);
373
- throw new TypeError(" \u2718 Cradova err: invalid element");
374
- }
272
+ console.error(" \u2718 Cradova err: wrong element type" + a2);
273
+ throw new TypeError(" \u2718 Cradova err: invalid element");
375
274
  }
376
275
  return par;
377
276
  };
@@ -410,6 +309,121 @@ var lazy = class {
410
309
  this.content = this.content.default;
411
310
  }
412
311
  };
312
+ var reference = class {
313
+ bindAs(name) {
314
+ return [this, name];
315
+ }
316
+ _appendDom(name, Element) {
317
+ if (!Object.hasOwnProperty.call(this, name)) {
318
+ this[name] = Element;
319
+ } else {
320
+ if (Array.isArray(this[name])) {
321
+ this[name].push(Element);
322
+ } else {
323
+ this[name] = [this[name], Element];
324
+ }
325
+ }
326
+ }
327
+ _appendDomForce(name, Element) {
328
+ this[name] = Element;
329
+ }
330
+ };
331
+
332
+ // lib/utils/track.ts
333
+ function cradovaDispatchTrack(nodes, state) {
334
+ for (let i2 = 0; i2 < nodes.length; i2++) {
335
+ const element = nodes[i2];
336
+ if (!element) {
337
+ continue;
338
+ }
339
+ if (typeof state === "object" && !Array.isArray(state)) {
340
+ for (const key in state) {
341
+ if (key === "style") {
342
+ for (const [k, v] of Object.entries(state[key])) {
343
+ if (typeof element.style[k] !== "undefined" && k !== "src") {
344
+ element.style[k] = v;
345
+ } else {
346
+ throw new Error(
347
+ "\u2718 Cradova err : " + k + " is not a valid css style property"
348
+ );
349
+ }
350
+ }
351
+ continue;
352
+ }
353
+ if (typeof element[key] === "function") {
354
+ if (key.startsWith("on")) {
355
+ element[key] = state[key];
356
+ } else {
357
+ element[key].apply(element);
358
+ }
359
+ continue;
360
+ }
361
+ if (key === "text") {
362
+ element.innerText = state[key];
363
+ continue;
364
+ }
365
+ if (key === "tree") {
366
+ element.innerHTML = "";
367
+ element.appendChild(frag(state[key]));
368
+ continue;
369
+ }
370
+ try {
371
+ if (typeof element[key] !== "undefined") {
372
+ element[key] = state[key];
373
+ } else {
374
+ if (key.includes("data-")) {
375
+ element.setAttribute(key, state[key]);
376
+ continue;
377
+ } else {
378
+ element[key] = state[key];
379
+ }
380
+ if (key !== "for" && key !== "text" && key !== "class" && key !== "tabindex" && key !== "disabled" && !key.includes("aria")) {
381
+ console.error(" \u2718 Cradova err: invalid html attribute " + key);
382
+ }
383
+ }
384
+ } catch (error) {
385
+ console.error(" \u2718 Cradova err: Cradova got ", state);
386
+ console.error(" \u2718 Cradova err: ", error);
387
+ }
388
+ }
389
+ } else {
390
+ console.log(nodes, state);
391
+ throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
392
+ }
393
+ }
394
+ }
395
+ function dispatch(stateID, state) {
396
+ if (stateID instanceof HTMLElement) {
397
+ cradovaDispatchTrack([stateID], state);
398
+ }
399
+ let ele;
400
+ let updated = void 0;
401
+ if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
402
+ for (const [id, eachState] of Object.entries(stateID)) {
403
+ const elements = document.querySelectorAll(
404
+ "[data-cra-id=" + id + "]"
405
+ );
406
+ updated = elements.length === 1 ? elements[0] : elements;
407
+ cradovaDispatchTrack(elements, eachState);
408
+ }
409
+ } else {
410
+ if (typeof stateID === "string") {
411
+ const elements = document.querySelectorAll(
412
+ "[data-cra-id=" + stateID + "]"
413
+ );
414
+ if (elements.length) {
415
+ updated = elements.length === 1 ? elements[0] : elements;
416
+ if (!state?.cradovaDispatchTrackBreak) {
417
+ cradovaDispatchTrack(elements, state);
418
+ }
419
+ }
420
+ }
421
+ if (ele) {
422
+ cradovaDispatchTrack([ele], state);
423
+ }
424
+ }
425
+ return updated;
426
+ }
413
427
 
414
428
  // lib/utils/createSignal.ts
415
429
  var createSignal = class {
@@ -474,9 +488,9 @@ var createSignal = class {
474
488
  this.actions[key] = action;
475
489
  } else {
476
490
  if (typeof key === "object" && !action) {
477
- for (const [nam, action2] of Object.entries(key)) {
478
- if (typeof nam === "string" && typeof action2 === "function") {
479
- this.actions[nam] = action2;
491
+ for (const [nam, act] of Object.entries(key)) {
492
+ if (typeof nam === "string" && typeof action === "function") {
493
+ this.actions[nam] = act;
480
494
  } else {
481
495
  throw new Error(`\u2718 Cradova err : can't create action ${nam}`);
482
496
  }
@@ -487,14 +501,13 @@ var createSignal = class {
487
501
  }
488
502
  }
489
503
  fireAction(key, data2) {
490
- if (this.actions[key].updateState) {
491
- this.actions[key].updateState(this, data2);
492
- this._updateState(key, data2);
504
+ this._updateState(key, data2);
505
+ if (this.actions[key] && this.actions[key].updateState) {
506
+ this.actions[key].updateState(data2);
493
507
  return;
494
508
  } else {
495
509
  if (typeof this.actions[key] === "function") {
496
- this.actions[key](this, data2);
497
- this._updateState(key, data2);
510
+ this.actions[key].bind(this)(data2);
498
511
  return;
499
512
  }
500
513
  }
@@ -550,13 +563,20 @@ var createSignal = class {
550
563
  ent.ref.updateState(this.value[ent._signalProperty]);
551
564
  continue;
552
565
  }
566
+ if (!ent._element_property && !ent._signalProperty) {
567
+ ent.ref.updateState(this.value);
568
+ continue;
569
+ }
553
570
  }
554
571
  }
555
572
  }
556
- bindRef(ref, binding) {
573
+ bindRef(ref, binding = { signalProperty: "", _element_property: "" }) {
557
574
  if (ref.render) {
558
575
  ref.render = ref.render.bind(ref, this.value);
559
576
  }
577
+ if (ref._setExtra) {
578
+ ref._setExtra(this);
579
+ }
560
580
  if (ref && ref.updateState) {
561
581
  this.ref.push({
562
582
  ref,
@@ -581,7 +601,6 @@ var createSignal = class {
581
601
  };
582
602
 
583
603
  // lib/utils/Router.ts
584
- var Router = {};
585
604
  var RouterBox = {};
586
605
  RouterBox["lastNavigatedRouteController"] = null;
587
606
  RouterBox["nextRouteController"] = null;
@@ -591,6 +610,12 @@ RouterBox["pageHide"] = null;
591
610
  RouterBox["errorHandler"] = null;
592
611
  RouterBox["params"] = {};
593
612
  RouterBox["routes"] = {};
613
+ RouterBox["pageevents"] = [];
614
+ RouterBox["start_pageevents"] = function(lastR, newR) {
615
+ for (let ci = 0; ci < RouterBox["pageevents"].length; ci++) {
616
+ RouterBox["pageevents"][ci](lastR, newR);
617
+ }
618
+ };
594
619
  var checker = (url) => {
595
620
  if (RouterBox.routes[url]) {
596
621
  return [RouterBox.routes[url], { path: url }];
@@ -643,69 +668,6 @@ RouterBox.route = (path, screen) => {
643
668
  RouterBox.routes[path] = screen;
644
669
  return RouterBox.routes[path];
645
670
  };
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) {
665
- RouterBox.routes[path] = {
666
- controller: async (params, force) => await screen.Activate(params, force),
667
- packager: async (params) => await screen.package(params),
668
- deactivate: async () => {
669
- await screen.deActivate();
670
- },
671
- paramData: (data2) => {
672
- screen.paramData = data2;
673
- }
674
- };
675
- if (typeof screen.errorHandler === "function") {
676
- RouterBox["errorHandler"][path] = screen.errorHandler;
677
- }
678
- };
679
- Router.navigate = function(href, data2 = null, force = false) {
680
- if (typeof href !== "string") {
681
- throw new TypeError(
682
- " \u2718 Cradova err: href must be a defined path but got " + href + " instead"
683
- );
684
- }
685
- if (typeof data2 === "boolean") {
686
- force = true;
687
- data2 = null;
688
- }
689
- let route = null, params, link2 = null;
690
- if (href.includes("://")) {
691
- window.location.href = href;
692
- } else {
693
- if (href === window.location.pathname) {
694
- return;
695
- }
696
- [route, params] = checker(href);
697
- if (route) {
698
- RouterBox["nextRouteController"] = route;
699
- RouterBox.params.params = params;
700
- route._paramData = params;
701
- RouterBox.params.data = data2 || null;
702
- link2 = href;
703
- RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
704
- window.history.pushState({}, "", link2);
705
- }
706
- RouterBox.router(null, force);
707
- }
708
- };
709
671
  RouterBox.router = async function(e, force = false) {
710
672
  let url, route, params;
711
673
  if (e) {
@@ -726,7 +688,7 @@ RouterBox.router = async function(e, force = false) {
726
688
  if (!url) {
727
689
  url = window.location.pathname;
728
690
  }
729
- if (url === Router["lastNavigatedRoute"]) {
691
+ if (url === RouterBox["lastNavigatedRoute"]) {
730
692
  return;
731
693
  }
732
694
  if (RouterBox["nextRouteController"]) {
@@ -755,7 +717,6 @@ RouterBox.router = async function(e, force = false) {
755
717
  RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
756
718
  RouterBox["lastNavigatedRoute"] = url;
757
719
  RouterBox["lastNavigatedRouteController"] = route;
758
- RouterBox["pageShow"] && RouterBox["pageShow"](url);
759
720
  } catch (error) {
760
721
  let errorHandler;
761
722
  if (RouterBox.routes[RouterBox.params.params._path]) {
@@ -768,72 +729,115 @@ RouterBox.router = async function(e, force = false) {
768
729
  } else {
769
730
  if (RouterBox.routes["/404"]) {
770
731
  RouterBox.routes["/404"].controller();
771
- } else {
772
- if (Object.keys(RouterBox.routes).length > 0) {
773
- console.error(
774
- " \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
775
- );
776
- }
777
732
  }
778
733
  }
779
734
  };
780
- Router["onPageShow"] = function(callback) {
781
- if (typeof callback === "function") {
782
- RouterBox["pageShow"] = callback;
783
- } else {
784
- throw new Error(
785
- " \u2718 Cradova err: callback for pageShow event is not a function"
786
- );
735
+ var RouterClass = class {
736
+ constructor() {
737
+ this.getParams = function() {
738
+ return RouterBox["params"];
739
+ };
787
740
  }
788
- };
789
- Router["onPageHide"] = function(callback) {
790
- if (typeof callback === "function") {
791
- RouterBox["pageHide"] = callback;
792
- } else {
793
- throw new Error(
794
- " \u2718 Cradova err: callback for pageHide event is not a function"
795
- );
741
+ BrowserRoutes(obj) {
742
+ for (const path in obj) {
743
+ let screen = obj[path];
744
+ if (screen.catch || typeof screen === "function") {
745
+ RouterBox["routes"][path] = async () => {
746
+ if (typeof screen === "function") {
747
+ screen = await screen();
748
+ } else {
749
+ screen = await screen;
750
+ }
751
+ return RouterBox.route(path, screen.default);
752
+ };
753
+ } else {
754
+ RouterBox.route(path, screen);
755
+ }
756
+ }
757
+ this._mount();
796
758
  }
797
- };
798
- Router.packageScreen = async function(path, data2 = {}) {
799
- if (!RouterBox.routes[path]) {
800
- console.error(" \u2718 Cradova err: no screen with path " + path);
801
- throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
759
+ navigate(href, data2 = null, force = false) {
760
+ if (typeof href !== "string") {
761
+ throw new TypeError(
762
+ " \u2718 Cradova err: href must be a defined path but got " + href + " instead"
763
+ );
764
+ }
765
+ if (typeof data2 === "boolean") {
766
+ force = true;
767
+ data2 = null;
768
+ }
769
+ let route = null, params;
770
+ if (href.includes("://")) {
771
+ window.location.href = href;
772
+ } else {
773
+ const lastR = window.location.pathname;
774
+ if (href === lastR) {
775
+ return;
776
+ }
777
+ [route, params] = checker(href);
778
+ if (route) {
779
+ RouterBox["nextRouteController"] = route;
780
+ RouterBox.params.params = params;
781
+ route._paramData = params;
782
+ RouterBox.params.data = data2 || null;
783
+ window.history.pushState({}, "", href);
784
+ }
785
+ RouterBox.router(null, force);
786
+ RouterBox["start_pageevents"](lastR, href);
787
+ }
802
788
  }
803
- let [route, params] = checker(path);
804
- if (!route._Activate && typeof route === "function") {
805
- route = await route();
789
+ onPageEvent(callback) {
790
+ if (typeof callback === "function") {
791
+ RouterBox["pageevents"].push(callback);
792
+ } else {
793
+ throw new Error(
794
+ " \u2718 Cradova err: callback for pageShow event is not a function"
795
+ );
796
+ }
806
797
  }
807
- route._package(Object.assign(data2, params || {}));
808
- route._packed = true;
809
- };
810
- Router.getParams = function() {
811
- return RouterBox["params"];
812
- };
813
- Router["addErrorHandler"] = function(callback) {
814
- if (typeof callback === "function") {
815
- RouterBox["errorHandler"] = callback;
816
- } else {
817
- throw new Error(
818
- " \u2718 Cradova err: callback for ever event event is not a function"
819
- );
798
+ async packageScreen(path, data2 = {}) {
799
+ if (!RouterBox.routes[path]) {
800
+ console.error(" \u2718 Cradova err: no screen with path " + path);
801
+ throw new Error(
802
+ " \u2718 Cradova err: cradova err: Not a defined screen path"
803
+ );
804
+ }
805
+ let [route, params] = checker(path);
806
+ if (!route._Activate && typeof route === "function") {
807
+ route = await route();
808
+ }
809
+ route._package(Object.assign(data2, params || {}));
810
+ route._packed = true;
811
+ }
812
+ addErrorHandler(callback) {
813
+ if (typeof callback === "function") {
814
+ RouterBox["errorHandler"] = callback;
815
+ } else {
816
+ throw new Error(
817
+ " \u2718 Cradova err: callback for ever event event is not a function"
818
+ );
819
+ }
820
+ }
821
+ _mount() {
822
+ window.addEventListener("pageshow", RouterBox.router);
823
+ window.addEventListener("popstate", (e) => {
824
+ e.preventDefault();
825
+ RouterBox.router();
826
+ });
820
827
  }
821
828
  };
822
- Router.mount = () => {
823
- window.addEventListener("pageshow", RouterBox.router);
824
- window.addEventListener("popstate", (e) => {
825
- e.preventDefault();
826
- RouterBox.router();
827
- });
828
- };
829
+ var Router = new RouterClass();
829
830
 
830
- // lib/utils/tags.ts
831
+ // lib/utils/elements.ts
831
832
  var makeElement = (element, ...ElementChildrenAndPropertyList) => {
832
833
  let beforeMount = null;
833
834
  let props = null, text = null;
834
835
  if (ElementChildrenAndPropertyList.length) {
835
836
  for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
836
837
  let child = ElementChildrenAndPropertyList[i2];
838
+ if (child?.render) {
839
+ child = child.render();
840
+ }
837
841
  if (typeof child === "function") {
838
842
  child = child();
839
843
  if (typeof child === "function") {
@@ -917,16 +921,21 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
917
921
  });
918
922
  continue;
919
923
  }
924
+ if (prop == "reference" && Array.isArray(props[prop]) && props[prop][0] instanceof reference) {
925
+ element.updateState = dispatch.bind(null, element);
926
+ props[prop][0]._appendDom(props[prop][1], element);
927
+ continue;
928
+ }
920
929
  if (prop === "shouldUpdate" && props[prop] === true) {
921
930
  element.updateState = dispatch.bind(void 0, element);
922
931
  continue;
923
932
  }
924
933
  if (prop === "afterMount" && typeof props["afterMount"] === "function") {
925
- const av = () => {
934
+ const avi = () => {
926
935
  props["afterMount"].apply(element);
927
- window.removeEventListener("cradova-aftermount", av);
936
+ CradovaEvent.removeEventListener("cradovaAftermountEvent", avi);
928
937
  };
929
- window.addEventListener("cradova-aftermount", av);
938
+ CradovaEvent.addEventListener("cradovaAftermountEvent", avi);
930
939
  continue;
931
940
  }
932
941
  try {
@@ -958,7 +967,7 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
958
967
  if (typeof beforeMount === "function") {
959
968
  beforeMount.apply(element);
960
969
  }
961
- if (element.tagName === "A") {
970
+ if (element.tagName === "A" && window) {
962
971
  if (element.href.includes(window.location.origin)) {
963
972
  element.addEventListener("click", (e) => {
964
973
  e.preventDefault();
@@ -969,10 +978,10 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
969
978
  return element;
970
979
  };
971
980
  var cra = (element_initials) => {
972
- return (...bo) => {
981
+ return (...initials) => {
973
982
  return makeElement(
974
983
  document.createElement(element_initials),
975
- ...bo
984
+ ...initials
976
985
  );
977
986
  };
978
987
  };
@@ -1160,12 +1169,6 @@ var Screen = class {
1160
1169
  this._params = null;
1161
1170
  this._delegatedRoutesCount = -1;
1162
1171
  const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
1163
- if (typeof template2 !== "function") {
1164
- console.error(" \u2718 Cradova err: expected a screen but got ", template2);
1165
- throw new Error(
1166
- " \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
1167
- );
1168
- }
1169
1172
  this._html = template2;
1170
1173
  this._name = name;
1171
1174
  this._transition = transition || "";
@@ -1201,6 +1204,10 @@ var Screen = class {
1201
1204
  this.errorHandler = errorHandler;
1202
1205
  }
1203
1206
  async _package() {
1207
+ if (this._html.render) {
1208
+ this._template.innerHTML = "";
1209
+ this._template.appendChild(this._html.render(this._data));
1210
+ }
1204
1211
  if (typeof this._html === "function") {
1205
1212
  let fuc = await this._html.apply(this, this._data);
1206
1213
  if (typeof fuc === "function") {
@@ -1227,8 +1234,9 @@ var Screen = class {
1227
1234
  }
1228
1235
  }
1229
1236
  if (!this._template.firstChild) {
1237
+ console.error(" \u2718 Cradova err: expected a screen but got ", this._html);
1230
1238
  throw new Error(
1231
- " \u2718 Cradova err: no screen is rendered, may have been past wrongly."
1239
+ " \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
1232
1240
  );
1233
1241
  }
1234
1242
  if (this._secondaryChildren.length) {
@@ -1265,10 +1273,10 @@ var Screen = class {
1265
1273
  await this._package();
1266
1274
  }
1267
1275
  }
1268
- const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
1276
+ const doc = document.querySelector("[data-wrapper=app]");
1269
1277
  if (!doc) {
1270
1278
  throw new Error(
1271
- " \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
1279
+ " \u2718 Cradova err: Unable to render, cannot find cradova root <div data-wrapper='app'> ... </div>"
1272
1280
  );
1273
1281
  }
1274
1282
  if (this._transition) {
@@ -1280,8 +1288,10 @@ var Screen = class {
1280
1288
  if (this._callBack) {
1281
1289
  await this._callBack();
1282
1290
  }
1283
- window.dispatchEvent(cradovaAftermountEvent);
1284
- window.scrollTo(0, 0);
1291
+ CradovaEvent.dispatchEvent("cradovaAftermountEvent");
1292
+ if (window) {
1293
+ window.scrollTo(0, 0);
1294
+ }
1285
1295
  }
1286
1296
  };
1287
1297
 
@@ -1344,9 +1354,6 @@ var make = function(txx) {
1344
1354
  return [tag || "DIV", IDs[0], classes.join(" "), innerValue];
1345
1355
  };
1346
1356
  var _2 = (...element_initials) => {
1347
- if (typeof element_initials[0] !== "string") {
1348
- return frag(element_initials);
1349
- }
1350
1357
  const initials = make(element_initials.shift());
1351
1358
  let props = void 0;
1352
1359
  let element;
@@ -1382,6 +1389,7 @@ Init();
1382
1389
  var lib_default = _2;
1383
1390
  export {
1384
1391
  Ajax,
1392
+ CradovaEvent,
1385
1393
  Ref,
1386
1394
  Router,
1387
1395
  Screen,
@@ -1408,7 +1416,6 @@ export {
1408
1416
  code,
1409
1417
  col,
1410
1418
  colgroup,
1411
- cradovaAftermountEvent,
1412
1419
  createSignal,
1413
1420
  css,
1414
1421
  data,
@@ -1472,6 +1479,7 @@ export {
1472
1479
  pre,
1473
1480
  progress,
1474
1481
  q,
1482
+ reference,
1475
1483
  rp,
1476
1484
  rt,
1477
1485
  ruby,