cradova 2.0.0 → 2.1.0

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