cradova 3.3.8 → 3.3.10

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
@@ -5,8 +5,8 @@ function Rhoda(l) {
5
5
  if (Array.isArray(ch)) {
6
6
  fg.appendChild(Rhoda(ch));
7
7
  } else {
8
- if (ch instanceof Ref) {
9
- ch = ch.render(undefined);
8
+ if (ch instanceof Comp) {
9
+ ch = ch.render();
10
10
  }
11
11
  if (typeof ch === "function") {
12
12
  ch = ch();
@@ -14,16 +14,12 @@ function Rhoda(l) {
14
14
  ch = ch();
15
15
  }
16
16
  }
17
- if (typeof ch === "string" || typeof ch === "number") {
18
- fg.appendChild(document.createTextNode(ch));
19
- continue;
20
- }
21
17
  if (ch instanceof HTMLElement || ch instanceof DocumentFragment) {
22
18
  fg.appendChild(ch);
23
- } else {
24
- if (typeof ch !== "undefined") {
25
- throw new Error(" \u2718 Cradova err: invalid child type: " + ch + " (" + typeof ch + ")");
26
- }
19
+ continue;
20
+ }
21
+ if (typeof ch === "string") {
22
+ fg.appendChild(document.createTextNode(ch));
27
23
  }
28
24
  }
29
25
  }
@@ -66,34 +62,35 @@ function loop(datalist, component) {
66
62
  }
67
63
  return Array.isArray(datalist) ? datalist.map(component) : undefined;
68
64
  }
69
- function useState(initialValue, ActiveRef) {
70
- ActiveRef._state_index += 1;
71
- const idx = ActiveRef._state_index;
72
- if (!ActiveRef._state_track[idx]) {
73
- ActiveRef._roll_state(initialValue, idx);
74
- ActiveRef._state_track[idx] = true;
65
+ function useState(initialValue, Comp2) {
66
+ Comp2._state_index += 1;
67
+ const idx = Comp2._state_index;
68
+ if (!Comp2._state_track[idx]) {
69
+ Comp2._roll_state(initialValue, idx);
70
+ Comp2._state_track[idx] = true;
75
71
  }
76
72
  function setState(newState) {
77
- ActiveRef._roll_state(newState, idx);
78
- ActiveRef.updateState();
73
+ Comp2._roll_state(newState, idx);
74
+ Comp2.recall();
79
75
  }
80
- return [ActiveRef._roll_state(null, idx, true), setState];
76
+ return [Comp2._roll_state(null, idx, true), setState];
81
77
  }
82
- function useEffect(effect, ActiveRef) {
83
- ActiveRef._effect(effect);
78
+ function useEffect(effect, Comp2) {
79
+ Comp2._effect(effect);
84
80
  }
85
81
  function useRef() {
86
- return new reference;
82
+ return new __raw_ref;
87
83
  }
88
84
  var makeElement = (element, ElementChildrenAndPropertyList) => {
89
- let props = {}, text = null;
85
+ const props = {};
86
+ let text = undefined;
90
87
  if (ElementChildrenAndPropertyList.length !== 0) {
91
88
  for (let i = 0;i < ElementChildrenAndPropertyList.length; i++) {
92
89
  let child = ElementChildrenAndPropertyList[i];
93
90
  if (typeof child === "function") {
94
91
  child = child();
95
92
  }
96
- if (child instanceof Ref) {
93
+ if (child instanceof Comp) {
97
94
  child = child.render();
98
95
  }
99
96
  if (child instanceof HTMLElement || child instanceof DocumentFragment) {
@@ -104,12 +101,12 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
104
101
  element.appendChild(Rhoda(child));
105
102
  continue;
106
103
  }
107
- if (typeof child === "string" || typeof child === "number") {
104
+ if (typeof child === "string") {
108
105
  text = child;
109
106
  continue;
110
107
  }
111
108
  if (typeof child === "object") {
112
- props = Object.assign(props, child);
109
+ Object.assign(props, child);
113
110
  continue;
114
111
  }
115
112
  }
@@ -122,21 +119,12 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
122
119
  Object.assign(element.style, value);
123
120
  continue;
124
121
  }
125
- if (prop.includes("data-")) {
126
- element.setAttribute(prop, value);
127
- continue;
128
- }
129
- if (prop.includes("aria-")) {
130
- element.setAttribute(prop, value);
131
- continue;
132
- }
133
- if (prop === "href" && typeof value === "string") {
122
+ if (prop === "href") {
134
123
  const href = value || "";
135
124
  if (!href.includes("://")) {
136
125
  element.addEventListener("click", (e) => {
137
126
  e.preventDefault();
138
127
  Router.navigate(element.pathname);
139
- //! get url hash here and scroll into view
140
128
  if (href.includes("#")) {
141
129
  const l = href.split("#").at(-1);
142
130
  document.getElementById("#" + l)?.scrollIntoView();
@@ -146,12 +134,8 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
146
134
  element.setAttribute(prop, value);
147
135
  continue;
148
136
  }
149
- if (typeof element.style[prop] !== "undefined" && prop !== "src") {
150
- element.style[prop] = value;
151
- continue;
152
- }
153
137
  if (Array.isArray(value)) {
154
- if (prop == "reference" && value[0] instanceof reference) {
138
+ if (prop == "reference" && value[0] instanceof __raw_ref) {
155
139
  value[0]._appendDomForce(value[1], element);
156
140
  continue;
157
141
  }
@@ -165,23 +149,30 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
165
149
  }
166
150
  if (prop === "onmount" && typeof props["onmount"] === "function") {
167
151
  const ev = () => {
168
- props.onmount?.apply(element);
152
+ props["onmount"]?.apply(element);
169
153
  props["onmount"] = undefined;
170
154
  };
171
- CradovaEvent.addEventListener("onmountEvent", ev);
155
+ CradovaEvent.addAfterMount(ev);
156
+ continue;
157
+ }
158
+ if (prop.includes("data-")) {
159
+ element.setAttribute(prop, value);
160
+ continue;
161
+ }
162
+ if (prop.includes("aria-")) {
163
+ element.setAttribute(prop, value);
172
164
  continue;
173
165
  }
174
166
  element[prop] = value;
175
167
  }
176
168
  }
177
- if (text) {
169
+ if (text !== undefined) {
178
170
  element.appendChild(document.createTextNode(text));
179
171
  }
180
172
  return element;
181
173
  };
182
174
  var cra = (tag) => {
183
- const extend = (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
184
- return extend;
175
+ return (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
185
176
  };
186
177
  var SNRU = {
187
178
  snru: "",
@@ -217,78 +208,59 @@ var frag = function(children) {
217
208
 
218
209
  // src/primitives/classes.ts
219
210
  class cradovaEvent {
220
- listeners = {};
221
- active_listeners = {};
222
- async addEventListener(eventName, callback) {
223
- if (!this.listeners[eventName]) {
224
- this.listeners[eventName] = [];
211
+ afterMount = [];
212
+ beforeMountActive = [];
213
+ async addAfterMount(callback) {
214
+ if (!this.addAfterMount) {
215
+ this.afterMount = [];
225
216
  }
226
- this.listeners[eventName].push(callback);
217
+ this.afterMount.push(callback);
227
218
  }
228
- async addActiveEventListener(eventName, callback) {
229
- if (!this.active_listeners[eventName]) {
230
- this.active_listeners[eventName] = [];
219
+ async addBeforeMountActive(callback) {
220
+ if (!this.beforeMountActive) {
221
+ this.beforeMountActive = [];
231
222
  }
232
- this.active_listeners[eventName].push(callback);
223
+ this.beforeMountActive.push(callback);
233
224
  }
234
- async dispatchEvent(eventName, eventArgs) {
235
- const eventListeners = this.listeners[eventName] || [];
236
- for (;eventListeners.length !== 0; ) {
237
- eventListeners.shift()(eventArgs);
238
- }
239
- }
240
- async dispatchActiveEvent(eventName, eventArgs) {
241
- const eventListeners = this.active_listeners[eventName] || [];
242
- eventListeners.length && SNRU.memo_SNRU();
225
+ dispatchEvent(eventName) {
226
+ const eventListeners = this[eventName] || [];
243
227
  for (let i = 0;i < eventListeners.length; i++) {
244
- eventListeners[i](eventArgs);
228
+ if (eventName.includes("Active")) {
229
+ eventListeners[i]();
230
+ } else {
231
+ eventListeners.shift()();
232
+ }
245
233
  }
246
234
  }
247
235
  }
248
236
  var CradovaEvent = new cradovaEvent;
249
237
 
250
- class Ref {
238
+ class Comp {
251
239
  component;
252
240
  effects = [];
253
241
  effectuate = null;
254
- methods = {};
255
242
  rendered = false;
256
243
  published = false;
257
244
  preRendered = null;
258
- reference = new reference;
245
+ reference = new __raw_ref;
259
246
  Signal;
260
247
  _state = [];
261
248
  _state_track = {};
262
249
  _state_index = 0;
263
- stash;
264
250
  constructor(component) {
265
251
  this.component = component.bind(this);
266
- CradovaEvent.addActiveEventListener("active-Refs", () => {
267
- this._state_index = 0;
252
+ CradovaEvent.addBeforeMountActive(() => {
268
253
  this.published = false;
269
254
  });
270
255
  }
271
- preRender(data, stash) {
272
- this.preRendered = this.render(data, stash);
256
+ preRender() {
257
+ this.preRendered = this.render();
273
258
  }
274
- destroyPreRendered() {
275
- this.preRendered = null;
276
- }
277
- define(methodName, method) {
278
- if (typeof methodName == "string" && typeof method == "function" && !Object.prototype.hasOwnProperty.call(this, methodName)) {
279
- this.methods[methodName] = method.bind(this);
280
- } else {
281
- console.error(" \u2718 Cradova err : Invalid Ref.define parameters");
282
- }
283
- }
284
- render(data, stash) {
259
+ render() {
285
260
  this.effects = [];
286
261
  this.rendered = false;
287
- if (stash) {
288
- this.stash = data;
289
- }
290
262
  if (!this.preRendered) {
291
- const html = this.component(data);
263
+ const html = this.component();
292
264
  if (html instanceof HTMLElement || html instanceof DocumentFragment) {
293
265
  this.reference._appendDomForce("html", html);
294
266
  this.effector.apply(this);
@@ -310,6 +282,9 @@ class Ref {
310
282
  }
311
283
  _roll_state(data, idx, get = false) {
312
284
  if (!get) {
285
+ if (idx !== 0) {
286
+ this._state[idx - 1] = undefined;
287
+ }
313
288
  this._state[idx] = data;
314
289
  }
315
290
  return this._state[idx];
@@ -329,29 +304,26 @@ class Ref {
329
304
  this.effectuate = null;
330
305
  }
331
306
  }
332
- updateState(data, stash) {
307
+ recall() {
333
308
  if (!this.rendered) {
334
309
  this.effectuate = () => {
335
310
  if (this.published) {
336
- this.Activate(data);
311
+ this.activate();
337
312
  }
338
313
  };
339
314
  } else {
340
315
  if (this.published) {
341
- this.Activate(data);
316
+ this.activate();
342
317
  }
343
318
  }
344
- if (stash) {
345
- this.stash = data;
346
- }
347
319
  }
348
- async Activate(data) {
320
+ async activate() {
349
321
  this._state_index = 0;
350
322
  this.published = false;
351
323
  if (!this.rendered) {
352
324
  return;
353
325
  }
354
- const html = this.component(data);
326
+ const html = this.component();
355
327
  if (html instanceof HTMLElement || html instanceof DocumentFragment) {
356
328
  const node = this.reference.current("html");
357
329
  if (node) {
@@ -360,9 +332,9 @@ class Ref {
360
332
  }
361
333
  this.published = true;
362
334
  this.reference._appendDomForce("html", html);
363
- CradovaEvent.dispatchEvent("onmountEvent");
335
+ CradovaEvent.dispatchEvent("afterMount");
364
336
  } else {
365
- console.error(" \u2718 Cradova err : Invalid html content, got - " + html);
337
+ console.error(" \u2718 Cradova err : Invalid html, got - " + html);
366
338
  }
367
339
  }
368
340
  }
@@ -387,7 +359,7 @@ class lazy {
387
359
  }
388
360
  }
389
361
 
390
- class reference {
362
+ class __raw_ref {
391
363
  tree = {};
392
364
  globalTree = {};
393
365
  bindAs(name) {
@@ -411,13 +383,13 @@ class reference {
411
383
  this.globalTree[name] = Element;
412
384
  }
413
385
  }
414
- var localTree = new reference;
386
+ var localTree = new __raw_ref;
415
387
 
416
388
  class createSignal {
417
389
  callback;
418
390
  persistName = "";
419
391
  actions = {};
420
- ref = [];
392
+ comp = [];
421
393
  value;
422
394
  constructor(initial, props) {
423
395
  this.value = initial;
@@ -445,8 +417,8 @@ class createSignal {
445
417
  if (this.persistName) {
446
418
  localStorage.setItem(this.persistName, JSON.stringify(this.value));
447
419
  }
448
- if (this.ref.length && shouldRefRender !== false) {
449
- this._updateState();
420
+ if (this.comp.length && shouldRefRender !== false) {
421
+ this.updateState();
450
422
  }
451
423
  if (this.callback) {
452
424
  this.callback(this.value);
@@ -458,21 +430,21 @@ class createSignal {
458
430
  if (this.persistName) {
459
431
  localStorage.setItem(this.persistName, JSON.stringify(this.value));
460
432
  }
461
- if (this.ref.length && shouldRefRender !== false) {
462
- this._updateState();
433
+ if (this.comp.length && shouldRefRender !== false) {
434
+ this.updateState();
463
435
  }
464
436
  if (this.callback) {
465
437
  this.callback(this.value);
466
438
  }
467
439
  } else {
468
- throw new Error(`\u2718 Cradova err : can't set key ${String(key)} . store.value is not a javascript object`);
440
+ throw new Error(`\u2718 Cradova err : can't set key ${String(key)} store.value is not an object`);
469
441
  }
470
442
  }
471
443
  createAction(name, action) {
472
444
  if (typeof name === "string" && typeof action === "function") {
473
- this.actions[name] = action;
445
+ this.actions[name] = action.bind(this);
474
446
  } else {
475
- throw new Error(`\u2718 Cradova err : can't create action, ${name} is not a function`);
447
+ throw new Error(`\u2718 Cradova err : can't create action ${name}, check values`);
476
448
  }
477
449
  }
478
450
  createActions(Actions) {
@@ -480,13 +452,13 @@ class createSignal {
480
452
  if (typeof name === "string" && typeof action === "function") {
481
453
  this.actions[name] = action;
482
454
  } else {
483
- throw new Error(`\u2718 Cradova err : can't create action, ${name} is not a function`);
455
+ throw new Error(`\u2718 Cradova err : can't create action ${name} check values`);
484
456
  }
485
457
  }
486
458
  }
487
459
  fireAction(key, data) {
488
- this._updateState(key, data);
489
460
  if (typeof this.actions[key] === "function") {
461
+ this.updateState(key, data);
490
462
  return this.actions[key].call(this, data);
491
463
  } else {
492
464
  throw Error("\u2718 Cradova err : action " + key + " does not exist!");
@@ -499,59 +471,51 @@ class createSignal {
499
471
  throw new Error("\u2718 Cradova err : can't bind an unavailable property! " + prop);
500
472
  }
501
473
  }
502
- _updateState(name, data) {
474
+ updateState(name, data) {
503
475
  if (name && data) {
504
- this.ref.map((ent) => {
476
+ this.comp.map((ent) => {
505
477
  if (ent._event === name) {
506
478
  if (ent._element_property && ent._signalProperty) {
507
- ent.ref.updateState({
508
- [ent._element_property]: data[ent._signalProperty]
509
- });
479
+ ent.comp.recall();
510
480
  return;
511
481
  }
512
482
  if (ent._element_property) {
513
- ent.ref.updateState({
514
- [ent._element_property]: data
515
- });
483
+ ent.comp.recall();
516
484
  return;
517
485
  }
518
486
  if (ent._signalProperty) {
519
- ent.ref.updateState(data[ent._signalProperty]);
487
+ ent.comp.recall();
520
488
  return;
521
489
  }
522
490
  }
523
491
  });
524
492
  } else {
525
- for (let i = 0;i < this.ref.length; i++) {
526
- const ent = this.ref[i];
493
+ for (let i = 0;i < this.comp.length; i++) {
494
+ const ent = this.comp[i];
527
495
  if (ent._element_property && ent._signalProperty) {
528
- ent.ref.updateState({
529
- [ent._element_property]: this.value[ent._signalProperty]
530
- });
496
+ ent.comp.recall();
531
497
  continue;
532
498
  }
533
499
  if (ent._element_property) {
534
- ent.ref.updateState({
535
- [ent._element_property]: this.value
536
- });
500
+ ent.comp.recall();
537
501
  continue;
538
502
  }
539
503
  if (ent._signalProperty) {
540
- ent.ref.updateState(this.value[ent._signalProperty]);
504
+ ent.comp.recall();
541
505
  continue;
542
506
  }
543
507
  if (!ent._element_property && !ent._signalProperty) {
544
- ent.ref.updateState(this.value);
508
+ ent.comp.recall();
545
509
  continue;
546
510
  }
547
511
  }
548
512
  }
549
513
  }
550
- bindRef(ref, binding = { signalProperty: "", _element_property: "" }) {
551
- ref.render = ref.render.bind(ref, this.value);
552
- ref._setExtra(this);
553
- this.ref.push({
554
- ref,
514
+ bindRef(comp, binding = { signalProperty: "", _element_property: "" }) {
515
+ comp.render = comp.render.bind(comp);
516
+ comp._setExtra(this);
517
+ this.comp.push({
518
+ comp,
555
519
  _signalProperty: binding.signalProperty,
556
520
  _element_property: binding._element_property,
557
521
  _event: binding.event
@@ -567,81 +531,23 @@ class createSignal {
567
531
  }
568
532
  }
569
533
 
570
- class Screen {
534
+ class Page {
571
535
  _name;
572
536
  _html;
573
- _packed = false;
574
537
  _template = document.createElement("div");
575
538
  _callBack;
576
539
  _deCallBack;
577
- _persist = true;
578
- _delegatedRoutesCount = -1;
579
540
  _dropped = false;
580
541
  _errorHandler = null;
581
- constructor(cradova_screen_initials) {
582
- const { template, name, persist, renderInParallel } = cradova_screen_initials;
583
- if (template instanceof Ref) {
584
- this._html = () => template.render({});
585
- } else {
586
- this._html = template;
587
- }
542
+ constructor(cradova_page_initials) {
543
+ const { template, name } = cradova_page_initials;
544
+ this._html = template;
588
545
  this._name = name || "Document";
589
- this._template.setAttribute("id", "cradova-screen-set");
590
- if (renderInParallel === true) {
591
- this._delegatedRoutesCount = 0;
592
- this._persist = false;
593
- } else {
594
- if (typeof persist === "boolean") {
595
- this._persist = persist;
596
- }
597
- }
598
- }
599
- _derive() {
600
- return {
601
- _name: this._name,
602
- _callBack: this._callBack,
603
- _deCallBack: this._deCallBack
604
- };
605
- }
606
- _apply_derivation(derivation) {
607
- this._name = derivation._name;
608
- this._callBack = derivation._callBack;
609
- this._deCallBack = derivation._deCallBack;
610
- }
611
- get _delegatedRoutes() {
612
- if (this._delegatedRoutesCount > 100) {
613
- return -1;
614
- }
615
- return this._delegatedRoutesCount;
616
- }
617
- set _delegatedRoutes(count) {
618
- if (count) {
619
- this._delegatedRoutesCount += 1;
620
- }
546
+ this._template.setAttribute("id", "page");
621
547
  }
622
- setErrorHandler(errorHandler) {
548
+ set errorHandler(errorHandler) {
623
549
  this._errorHandler = errorHandler;
624
550
  }
625
- async _package() {
626
- SNRU.memo_SNRU();
627
- if (typeof this._html === "function") {
628
- let html = await this._html.apply(this);
629
- if (typeof html === "function") {
630
- html = html();
631
- if (html instanceof HTMLElement || html instanceof DocumentFragment) {
632
- this._template.innerHTML = "";
633
- this._template.appendChild(html);
634
- }
635
- } else {
636
- if (html instanceof HTMLElement || html instanceof DocumentFragment) {
637
- this._template.innerHTML = "";
638
- this._template.appendChild(html);
639
- } else {
640
- throw new Error(` \u2718 Cradova err: template function for the screen with name '${this._name}' returned ${html} instead of html`);
641
- }
642
- }
643
- }
644
- }
645
551
  onActivate(cb) {
646
552
  this._callBack = cb;
647
553
  }
@@ -649,7 +555,7 @@ class Screen {
649
555
  this._deCallBack = cb;
650
556
  }
651
557
  async _deActivate() {
652
- this._deCallBack && await this._deCallBack(localTree.globalTree["doc"]);
558
+ this._deCallBack && await this._deCallBack();
653
559
  }
654
560
  drop(state) {
655
561
  if (typeof state === "boolean") {
@@ -658,26 +564,30 @@ class Screen {
658
564
  } else
659
565
  return this._dropped;
660
566
  }
661
- async _Activate(force = false) {
567
+ async _activate() {
662
568
  if (this._dropped) {
663
569
  history.go(-1);
664
570
  return;
665
571
  }
666
- CradovaEvent.dispatchActiveEvent("active-Refs");
667
- if (!this._persist || force || !this._packed) {
668
- await this._package();
669
- this._packed = true;
572
+ SNRU.memo_SNRU();
573
+ let html = this._html.apply(this);
574
+ if (html instanceof HTMLElement) {
575
+ this._template.innerHTML = "";
576
+ this._template.appendChild(html);
577
+ } else {
578
+ throw new Error(` \u2718 Cradova err: template function for the page returned ${html} instead of html`);
670
579
  }
671
580
  document.title = this._name;
672
581
  localTree.globalTree["doc"].innerHTML = "";
582
+ CradovaEvent.dispatchEvent("beforeMountActive");
673
583
  localTree.globalTree["doc"].appendChild(this._template);
674
- CradovaEvent.dispatchEvent("onmountEvent");
584
+ CradovaEvent.dispatchEvent("afterMount");
675
585
  window.scrollTo({
676
586
  top: 0,
677
587
  left: 0,
678
588
  behavior: "instant"
679
589
  });
680
- this._callBack && await this._callBack(localTree.globalTree["doc"]);
590
+ this._callBack && await this._callBack();
681
591
  }
682
592
  }
683
593
 
@@ -688,7 +598,7 @@ class RouterBoxClass {
688
598
  pageShow = null;
689
599
  pageHide = null;
690
600
  errorHandler;
691
- loadingScreen = null;
601
+ loadingPage = null;
692
602
  params = {};
693
603
  routes = {};
694
604
  pageevents = [];
@@ -700,13 +610,13 @@ class RouterBoxClass {
700
610
  }
701
611
  }, 50);
702
612
  }
703
- route(path, screen) {
704
- if (typeof screen !== "undefined") {
705
- if (screen && !screen) {
706
- console.error(" \u2718 Cradova err: not a valid screen ", screen);
707
- throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
613
+ route(path, page) {
614
+ if (typeof page !== "undefined") {
615
+ if (page && !page) {
616
+ console.error(" \u2718 Cradova err: not a valid page ", page);
617
+ throw new Error(" \u2718 Cradova err: Not a valid cradova page component");
708
618
  }
709
- return this.routes[path] = screen;
619
+ return this.routes[path] = page;
710
620
  }
711
621
  return;
712
622
  }
@@ -728,8 +638,8 @@ class RouterBoxClass {
728
638
  if (typeof route !== "undefined") {
729
639
  try {
730
640
  if (typeof route === "function") {
731
- if (this.loadingScreen instanceof Screen) {
732
- await this.loadingScreen._Activate();
641
+ if (this.loadingPage instanceof Page) {
642
+ await this.loadingPage._activate();
733
643
  }
734
644
  route = await route();
735
645
  if (!route) {
@@ -739,19 +649,10 @@ class RouterBoxClass {
739
649
  return;
740
650
  }
741
651
  }
742
- if (route._delegatedRoutes !== -1) {
743
- route._delegatedRoutes = 1;
744
- const a = route._derive();
745
- route = new Screen({
746
- template: route._html
747
- });
748
- route._apply_derivation(a);
749
- this.routes[url] = route;
750
- }
751
652
  if (params) {
752
653
  this.params.params = params;
753
654
  }
754
- await route._Activate(_force);
655
+ await route._activate();
755
656
  this.start_pageevents(url);
756
657
  this.lastNavigatedRouteController && this.lastNavigatedRouteController._deActivate();
757
658
  this.lastNavigatedRoute = url;
@@ -764,55 +665,69 @@ class RouterBoxClass {
764
665
  this.errorHandler(error);
765
666
  } else {
766
667
  console.error(error);
767
- throw new Error(" \u2718 Cradova err: consider adding error boundary to the specific screen ");
668
+ throw new Error(" \u2718 Cradova err: consider adding error boundary to the specific page ");
768
669
  }
769
670
  }
770
671
  }
771
672
  } else {
772
673
  if (this.routes["*"]) {
773
- await this.routes["*"]._Activate(_force);
674
+ await this.routes["*"]._activate();
774
675
  }
775
676
  }
776
677
  }
777
678
  checker(url) {
679
+ if (url[0] !== "/") {
680
+ url = url.slice(url.indexOf("/", 7));
681
+ }
778
682
  if (this.routes[url]) {
779
683
  return [this.routes[url], { path: url }];
780
684
  }
781
685
  if (this.routes[url + "/"]) {
782
- return [this.routes[url], { path: url }];
686
+ return [this.routes[url + "/"], { path: url }];
783
687
  }
784
- for (const path in this.routes) {
785
- if (!path.includes(":")) {
786
- continue;
787
- }
788
- const urlFixtures = url.split("/");
789
- const pathFixtures = path.split("/");
790
- if (url.endsWith("/")) {
791
- urlFixtures.pop();
688
+ if (url.includes("/?")) {
689
+ const sraw = [...new URLSearchParams(url).entries()];
690
+ const search = {};
691
+ for (const idx in sraw) {
692
+ search[sraw[idx][0].includes("?") ? sraw[idx][0].split("?")[1] : sraw[idx][0]] = sraw[idx][1];
792
693
  }
793
- let fixturesX = 0;
794
- let fixturesY = 0;
795
- urlFixtures.shift();
796
- pathFixtures.shift();
797
- if (pathFixtures.length === urlFixtures.length) {
798
- const routesParams = { _path: "" };
799
- for (let i = 0;i < pathFixtures.length; i++) {
800
- if (pathFixtures[i].includes(":")) {
801
- fixturesY++;
802
- continue;
803
- }
804
- if (urlFixtures[i] === pathFixtures[i]) {
805
- fixturesX++;
806
- }
694
+ const path = url.slice(0, url.indexOf("/?") + 2);
695
+ return [this.routes[path], { path, search }];
696
+ }
697
+ for (const path in this.routes) {
698
+ if (path.includes(":")) {
699
+ const urlFixtures = url.split("/");
700
+ const pathFixtures = path.split("/");
701
+ if (url.endsWith("/")) {
702
+ urlFixtures.pop();
807
703
  }
808
- if (fixturesX + fixturesY === pathFixtures.length) {
704
+ let fixturesX = 0;
705
+ let fixturesY = 0;
706
+ if (pathFixtures.length === urlFixtures.length) {
809
707
  for (let i = 0;i < pathFixtures.length; i++) {
810
708
  if (pathFixtures[i].includes(":")) {
811
- routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
709
+ fixturesY++;
710
+ continue;
812
711
  }
712
+ if (urlFixtures[i] === pathFixtures[i]) {
713
+ fixturesX++;
714
+ }
715
+ }
716
+ if (fixturesX + fixturesY === pathFixtures.length) {
717
+ const routesParams = {};
718
+ for (let i = 0;i < pathFixtures.length; i++) {
719
+ if (pathFixtures[i].includes(":")) {
720
+ routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
721
+ }
722
+ }
723
+ return [this.routes[path], { param: routesParams }];
813
724
  }
814
- routesParams["_path"] = path;
815
- return [this.routes[path], routesParams];
725
+ }
726
+ }
727
+ if (path.includes("*")) {
728
+ const p = path.slice(0, -1);
729
+ if (url.startsWith(p)) {
730
+ return [this.routes[path], { extraPath: url.slice(p.length) }];
816
731
  }
817
732
  }
818
733
  }
@@ -824,14 +739,14 @@ var RouterBox = new RouterBoxClass;
824
739
  class Router {
825
740
  static BrowserRoutes(obj) {
826
741
  for (const path in obj) {
827
- let screen = obj[path];
828
- if (typeof screen === "object" && typeof screen.then === "function" || typeof screen === "function") {
742
+ let page = obj[path];
743
+ if (typeof page === "object" && typeof page.then === "function" || typeof page === "function") {
829
744
  RouterBox.routes[path] = async () => {
830
- screen = await (typeof screen === "function" ? await screen() : await screen);
831
- return RouterBox.route(path, screen?.default || screen);
745
+ page = await (typeof page === "function" ? await page() : await page);
746
+ return RouterBox.route(path, page?.default || page);
832
747
  };
833
748
  } else {
834
- RouterBox.route(path, screen);
749
+ RouterBox.route(path, page);
835
750
  }
836
751
  }
837
752
  Router._mount();
@@ -851,12 +766,12 @@ class Router {
851
766
  window.location.replace(window.location.pathname + window.location.search);
852
767
  history.go(-1);
853
768
  }
854
- static navigate(href, data = null, force = false) {
769
+ static navigate(href, data = null) {
855
770
  if (typeof href !== "string") {
856
771
  throw new TypeError(" \u2718 Cradova err: href must be a defined path but got " + href + " instead");
857
772
  }
858
773
  let route = null, params;
859
- if (href.includes("://")) {
774
+ if (href.includes(".")) {
860
775
  window.location.href = href;
861
776
  } else {
862
777
  if (href === window.location.pathname) {
@@ -869,14 +784,14 @@ class Router {
869
784
  }
870
785
  RouterBox.params.params = params;
871
786
  RouterBox.params.data = data;
872
- RouterBox.router(null, force);
787
+ RouterBox.router(null);
873
788
  }
874
789
  }
875
- static setLoadingScreen(screen) {
876
- if (screen instanceof Screen) {
877
- RouterBox.loadingScreen = screen;
790
+ static setLoadingPage(page) {
791
+ if (page instanceof Page) {
792
+ RouterBox.loadingPage = page;
878
793
  } else {
879
- throw new Error(" \u2718 Cradova err: Loading Screen should be a cradova screen class");
794
+ throw new Error(" \u2718 Cradova err: Loading Page should be a cradova page class");
880
795
  }
881
796
  }
882
797
  static onPageEvent(callback) {
@@ -886,27 +801,6 @@ class Router {
886
801
  throw new Error(" \u2718 Cradova err: callback for pageShow event is not a function");
887
802
  }
888
803
  }
889
- static async packageScreen(path) {
890
- if (!RouterBox.routes[path]) {
891
- console.error(" \u2718 Cradova err: no screen with path " + path);
892
- throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
893
- }
894
- let [route] = RouterBox.checker(path);
895
- if (typeof route === "function") {
896
- route = await route();
897
- }
898
- if (route._delegatedRoutes !== -1) {
899
- route._delegatedRoutes = 1;
900
- const a = route._derive();
901
- route = new Screen({
902
- template: route._html
903
- });
904
- route._apply_derivation(a);
905
- RouterBox.routes[path] = route;
906
- }
907
- route._package();
908
- route._packed = true;
909
- }
910
804
  static get Params() {
911
805
  return RouterBox.params;
912
806
  }
@@ -936,19 +830,15 @@ class Router {
936
830
  }
937
831
  // src/primitives/dom-objects.ts
938
832
  var a = cra("a");
939
- var article = cra("article");
940
833
  var audio = cra("audio");
941
834
  var br = cra("br");
942
835
  var button = cra("button");
943
836
  var canvas = cra("canvas");
944
837
  var caption = cra("caption");
945
- var col = cra("col");
946
- var colgroup = cra("colgroup");
947
838
  var datalist = cra("datalist");
948
839
  var details = cra("details");
949
840
  var dialog = cra("dialog");
950
841
  var div = cra("div");
951
- var figure = cra("figure");
952
842
  var footer = cra("footer");
953
843
  var form = cra("form");
954
844
  var h1 = cra("h1");
@@ -983,12 +873,10 @@ var summary = cra("summary");
983
873
  var table = cra("table");
984
874
  var tbody = cra("tbody");
985
875
  var td = cra("td");
986
- var template = cra("template");
987
876
  var textarea = cra("textarea");
988
877
  var th = cra("th");
989
878
  var title = cra("title");
990
879
  var tr = cra("tr");
991
- var track = cra("track");
992
880
  var u = cra("u");
993
881
  var ul = cra("ul");
994
882
  var video = cra("video");
@@ -999,22 +887,17 @@ var svg = (svg2, properties) => {
999
887
  };
1000
888
  var raw = (html) => {
1001
889
  const div2 = document.createElement("div");
1002
- div2.innerHTML = html;
890
+ if (Array.isArray(html)) {
891
+ div2.innerHTML = html[0];
892
+ } else {
893
+ if (typeof html === "string") {
894
+ div2.innerHTML = html;
895
+ }
896
+ }
1003
897
  const df = new DocumentFragment;
1004
898
  df.append(...Array.from(div2.children));
1005
899
  return df;
1006
900
  };
1007
-
1008
- // src/index.ts
1009
- /*! *****************************************************************************
1010
- Copyright 2022 Friday Candour. All rights reserved.
1011
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1012
- this file except in compliance with the License. You may obtain a copy of the
1013
- License at http://www.apache.org/licenses/LICENSE-2.0
1014
-
1015
- See the Apache Version 2.0 License for specific language governing permissions
1016
- and limitations under the License.
1017
- ********************************************************************************/
1018
901
  export {
1019
902
  video,
1020
903
  useState,
@@ -1022,12 +905,10 @@ export {
1022
905
  useEffect,
1023
906
  ul,
1024
907
  u,
1025
- track,
1026
908
  tr,
1027
909
  title,
1028
910
  th,
1029
911
  textarea,
1030
- template,
1031
912
  td,
1032
913
  tbody,
1033
914
  table,
@@ -1038,7 +919,6 @@ export {
1038
919
  source,
1039
920
  select,
1040
921
  section,
1041
- reference,
1042
922
  raw,
1043
923
  q,
1044
924
  progress,
@@ -1069,28 +949,25 @@ export {
1069
949
  frag,
1070
950
  form,
1071
951
  footer,
1072
- figure,
1073
952
  div,
1074
953
  dialog,
1075
954
  details,
1076
955
  datalist,
1077
956
  createSignal,
1078
957
  cra,
1079
- colgroup,
1080
- col,
1081
958
  caption,
1082
959
  canvas,
1083
960
  button,
1084
961
  br,
1085
962
  audio,
1086
- article,
1087
963
  a,
1088
- Screen,
964
+ __raw_ref,
1089
965
  SNRU,
1090
966
  Router,
1091
967
  Rhoda,
1092
- Ref,
968
+ Page,
1093
969
  CradovaEvent,
970
+ Comp,
1094
971
  $switch,
1095
972
  $ifelse,
1096
973
  $if,