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