cradova 3.2.1 → 3.3.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/README.md +54 -15
- package/dist/index.d.ts +109 -65
- package/dist/index.js +4 -1408
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -8,1417 +8,13 @@
|
|
|
8
8
|
╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ████████ ╚███╔╝ ██║ ██║
|
|
9
9
|
╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚══╝ ╚═╝ ╚═╝
|
|
10
10
|
=============================================================================
|
|
11
|
-
Cradova
|
|
12
|
-
@version 3.
|
|
11
|
+
Cradova
|
|
12
|
+
@version 3.3.0
|
|
13
13
|
License: Apache V2
|
|
14
14
|
Copyright 2022 Friday Candour.
|
|
15
15
|
Repository - https://github.com/fridaycandour/cradova
|
|
16
16
|
=============================================================================
|
|
17
17
|
*/
|
|
18
|
-
// lib/parts/fns.ts
|
|
19
|
-
var isNode = (element) => element instanceof HTMLElement || element instanceof DocumentFragment;
|
|
20
|
-
var cradovaEvent = class {
|
|
21
|
-
constructor() {
|
|
22
|
-
this.listeners = {};
|
|
23
|
-
}
|
|
24
|
-
async addEventListener(eventName, callback) {
|
|
25
|
-
if (!this.listeners[eventName]) {
|
|
26
|
-
this.listeners[eventName] = [];
|
|
27
|
-
}
|
|
28
|
-
this.listeners[eventName].push(callback);
|
|
29
|
-
}
|
|
30
|
-
// removeEventListener(eventName: string, num: number) {
|
|
31
|
-
// this.listeners[eventName].splice(num, 1);
|
|
32
|
-
// }
|
|
33
|
-
async dispatchEvent(eventName, eventArgs) {
|
|
34
|
-
const eventListeners = this.listeners[eventName] || [];
|
|
35
|
-
for (; eventListeners.length !== 0; ) {
|
|
36
|
-
eventListeners.shift()?.call(void 0, eventArgs);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var CradovaEvent = new cradovaEvent();
|
|
41
|
-
function Rhoda(l) {
|
|
42
|
-
const fg = new DocumentFragment();
|
|
43
|
-
for (let ch of l) {
|
|
44
|
-
if (Array.isArray(ch)) {
|
|
45
|
-
fg.appendChild(Rhoda(ch));
|
|
46
|
-
} else {
|
|
47
|
-
if (ch instanceof Ref) {
|
|
48
|
-
ch = ch.render(void 0);
|
|
49
|
-
}
|
|
50
|
-
if (typeof ch === "function") {
|
|
51
|
-
ch = ch();
|
|
52
|
-
if (typeof ch === "function") {
|
|
53
|
-
ch = ch();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (typeof ch === "string" || typeof ch === "number") {
|
|
57
|
-
fg.appendChild(document.createTextNode(ch));
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (isNode(ch)) {
|
|
61
|
-
fg.appendChild(ch);
|
|
62
|
-
} else {
|
|
63
|
-
if (typeof ch !== "undefined") {
|
|
64
|
-
throw new Error(
|
|
65
|
-
" \u2718 Cradova err: invalid child type: " + ch + " (" + typeof ch + ")"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return fg;
|
|
72
|
-
}
|
|
73
|
-
function css(identifier) {
|
|
74
|
-
if (Array.isArray(identifier)) {
|
|
75
|
-
identifier = identifier[0];
|
|
76
|
-
}
|
|
77
|
-
if (typeof identifier === "string") {
|
|
78
|
-
let styTag = document.querySelector("style");
|
|
79
|
-
if (styTag !== null) {
|
|
80
|
-
styTag.textContent = identifier + styTag.textContent;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
styTag = document.createElement("style");
|
|
84
|
-
styTag.textContent = identifier;
|
|
85
|
-
document.head.appendChild(styTag);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function assert(condition, ...elements) {
|
|
89
|
-
if (condition) {
|
|
90
|
-
return elements;
|
|
91
|
-
}
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
function assertOr(condition, ifTrue, ifFalse) {
|
|
95
|
-
if (condition) {
|
|
96
|
-
return ifTrue;
|
|
97
|
-
}
|
|
98
|
-
return ifFalse;
|
|
99
|
-
}
|
|
100
|
-
function loop(datalist2, component) {
|
|
101
|
-
if (typeof component !== "function") {
|
|
102
|
-
throw new Error(
|
|
103
|
-
" \u2718 Cradova err : Invalid component type, must be a function that returns html "
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
return Array.isArray(datalist2) ? datalist2.map(component) : void 0;
|
|
107
|
-
}
|
|
108
|
-
function SNRU(url) {
|
|
109
|
-
let key = 0;
|
|
110
|
-
for (let i2 = 0; i2 < url.length; i2++) {
|
|
111
|
-
key += url.charCodeAt(i2);
|
|
112
|
-
}
|
|
113
|
-
return key.toString();
|
|
114
|
-
}
|
|
115
|
-
var Ref = class {
|
|
116
|
-
constructor(component) {
|
|
117
|
-
this.effects = [];
|
|
118
|
-
this.effectuate = null;
|
|
119
|
-
this.rendered = false;
|
|
120
|
-
this.published = false;
|
|
121
|
-
this.preRendered = null;
|
|
122
|
-
this.reference = new reference();
|
|
123
|
-
//? hooks management
|
|
124
|
-
this._state = [];
|
|
125
|
-
this._state_track = {};
|
|
126
|
-
this._state_index = 0;
|
|
127
|
-
this.component = component.bind(this);
|
|
128
|
-
CradovaEvent.addEventListener("onTransition", () => {
|
|
129
|
-
this.current_id = SNRU(location.href);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
preRender(data2, stash) {
|
|
133
|
-
this.reference._appendDomForce(
|
|
134
|
-
this.current_id,
|
|
135
|
-
this.render(data2, stash)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
destroyPreRendered() {
|
|
139
|
-
this.preRendered = null;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Cradova Ref
|
|
143
|
-
* ---
|
|
144
|
-
* returns html with cradova reference
|
|
145
|
-
* @param data
|
|
146
|
-
* @returns () => HTMLElement
|
|
147
|
-
*/
|
|
148
|
-
render(data2, stash) {
|
|
149
|
-
this.effects = [];
|
|
150
|
-
this.rendered = false;
|
|
151
|
-
let html = this.component(data2);
|
|
152
|
-
if (typeof html === "function") {
|
|
153
|
-
html = html();
|
|
154
|
-
}
|
|
155
|
-
if (!html) {
|
|
156
|
-
html = this.preRendered;
|
|
157
|
-
}
|
|
158
|
-
if (stash) {
|
|
159
|
-
this.stash = data2;
|
|
160
|
-
}
|
|
161
|
-
if (isNode(html)) {
|
|
162
|
-
this.current_id = SNRU(location.href);
|
|
163
|
-
this.reference._appendDomForce(
|
|
164
|
-
this.current_id,
|
|
165
|
-
html
|
|
166
|
-
);
|
|
167
|
-
this.effector.apply(this);
|
|
168
|
-
this.rendered = true;
|
|
169
|
-
this.published = true;
|
|
170
|
-
} else {
|
|
171
|
-
console.error(" \u2718 Cradova err : Invalid html content, got - " + html);
|
|
172
|
-
}
|
|
173
|
-
return html;
|
|
174
|
-
}
|
|
175
|
-
instance() {
|
|
176
|
-
this.current_id = SNRU(location.href);
|
|
177
|
-
return this.reference[this.current_id];
|
|
178
|
-
}
|
|
179
|
-
_setExtra(Extra) {
|
|
180
|
-
this.Signal = Extra;
|
|
181
|
-
}
|
|
182
|
-
_roll_state(data2, idx, get = false) {
|
|
183
|
-
if (!get) {
|
|
184
|
-
this._state[idx] = data2;
|
|
185
|
-
}
|
|
186
|
-
return this._state[idx];
|
|
187
|
-
}
|
|
188
|
-
_effect(fn) {
|
|
189
|
-
if (!this.rendered) {
|
|
190
|
-
this.effects.push(fn.bind(this));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async effector() {
|
|
194
|
-
if (!this.rendered) {
|
|
195
|
-
for (let i2 = 0; i2 < this.effects.length; i2++) {
|
|
196
|
-
await this.effects[i2].apply(this);
|
|
197
|
-
}
|
|
198
|
-
this.effects = [];
|
|
199
|
-
}
|
|
200
|
-
if (this.effectuate) {
|
|
201
|
-
this.effectuate();
|
|
202
|
-
this.effectuate = null;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Cradova Ref
|
|
207
|
-
* ---
|
|
208
|
-
* update ref component with new data and update the dom.
|
|
209
|
-
* @param data
|
|
210
|
-
* @returns
|
|
211
|
-
*/
|
|
212
|
-
updateState(data2, stash) {
|
|
213
|
-
if (!this.rendered) {
|
|
214
|
-
this.effectuate = () => {
|
|
215
|
-
if (this.published) {
|
|
216
|
-
this.current_id = SNRU(location.href);
|
|
217
|
-
this.Activate(data2);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
} else {
|
|
221
|
-
if (this.published) {
|
|
222
|
-
this.Activate(data2);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (stash) {
|
|
226
|
-
this.stash = data2;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async Activate(data2) {
|
|
230
|
-
this._state_index = 0;
|
|
231
|
-
this.published = false;
|
|
232
|
-
if (!this.rendered) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
let html = this.component(data2);
|
|
236
|
-
if (typeof html === "function") {
|
|
237
|
-
html = html();
|
|
238
|
-
}
|
|
239
|
-
if (isNode(html)) {
|
|
240
|
-
this.reference[this.current_id].insertAdjacentElement(
|
|
241
|
-
"beforebegin",
|
|
242
|
-
html
|
|
243
|
-
);
|
|
244
|
-
this.reference[this.current_id].remove();
|
|
245
|
-
this.published = true;
|
|
246
|
-
this.reference._appendDomForce(
|
|
247
|
-
this.current_id,
|
|
248
|
-
html
|
|
249
|
-
);
|
|
250
|
-
CradovaEvent.dispatchEvent("onmountEvent");
|
|
251
|
-
} else {
|
|
252
|
-
console.error(" \u2718 Cradova err : Invalid html content, got - " + html);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var frag = function(children) {
|
|
257
|
-
const par = document.createDocumentFragment();
|
|
258
|
-
for (let i2 = 0; i2 < children.length; i2++) {
|
|
259
|
-
let a2 = children[i2];
|
|
260
|
-
if (typeof a2 === "function") {
|
|
261
|
-
a2 = a2();
|
|
262
|
-
}
|
|
263
|
-
if (isNode(a2)) {
|
|
264
|
-
par.appendChild(a2);
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
if (a2 instanceof String) {
|
|
268
|
-
par.appendChild(document.createTextNode(a2));
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
console.error(" \u2718 Cradova err: wrong element type" + a2);
|
|
272
|
-
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
273
|
-
}
|
|
274
|
-
return par;
|
|
275
|
-
};
|
|
276
|
-
var lazy = class {
|
|
277
|
-
constructor(cb) {
|
|
278
|
-
this._cb = cb;
|
|
279
|
-
}
|
|
280
|
-
async load() {
|
|
281
|
-
let content = await this._cb();
|
|
282
|
-
if (typeof content === "function") {
|
|
283
|
-
content = await content();
|
|
284
|
-
} else {
|
|
285
|
-
content = await content;
|
|
286
|
-
}
|
|
287
|
-
const def = content;
|
|
288
|
-
if (def.default) {
|
|
289
|
-
this.content = def?.default;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var reference = class {
|
|
294
|
-
/**
|
|
295
|
-
* Bind a DOM element to a reference name.
|
|
296
|
-
* @param name - The name to reference the DOM element by.
|
|
297
|
-
*/
|
|
298
|
-
bindAs(name) {
|
|
299
|
-
return [this, name];
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Retrieve a referenced DOM element.
|
|
303
|
-
* @param name - The name of the referenced DOM element.
|
|
304
|
-
*/
|
|
305
|
-
dom(name) {
|
|
306
|
-
return this[name];
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Append a DOM element to the reference, overwriting any existing reference.
|
|
310
|
-
* @param name - The name to reference the DOM element by.
|
|
311
|
-
* @param element - The DOM element to reference.
|
|
312
|
-
*/
|
|
313
|
-
_appendDomForce(name, Element) {
|
|
314
|
-
this[name] = Element;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
function useState(initialValue, ActiveRef) {
|
|
318
|
-
ActiveRef._state_index += 1;
|
|
319
|
-
const idx = ActiveRef._state_index;
|
|
320
|
-
if (!ActiveRef._state_track[idx]) {
|
|
321
|
-
ActiveRef._roll_state(initialValue, idx);
|
|
322
|
-
ActiveRef._state_track[idx] = true;
|
|
323
|
-
}
|
|
324
|
-
function setState(newState) {
|
|
325
|
-
ActiveRef._roll_state(newState, idx);
|
|
326
|
-
ActiveRef.updateState(newState);
|
|
327
|
-
}
|
|
328
|
-
return [ActiveRef._roll_state(null, idx, true), setState];
|
|
329
|
-
}
|
|
330
|
-
function useEffect(effect, ActiveRef) {
|
|
331
|
-
ActiveRef._effect(effect);
|
|
332
|
-
}
|
|
333
|
-
function useRef() {
|
|
334
|
-
return new reference();
|
|
335
|
-
}
|
|
18
|
+
var p=r=>r instanceof HTMLElement||r instanceof DocumentFragment,T=class{constructor(){this.listeners={};this.active_listeners={};}async addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t);}async addActiveEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.active_listeners[e].push(t);}async dispatchEvent(e,t){let n=this.listeners[e]||[];for(;n.length!==0;)n.shift()(t);}async dispatchActiveEvent(e,t){let n=this.listeners[e]||[];n.length&&w();for(let o=0;o<n.length;o++)n[o](t);}},f=new T;function E(r){let e=new DocumentFragment;for(let t of r)if(Array.isArray(t))e.appendChild(E(t));else {if(t instanceof v&&(t=t.render(void 0)),typeof t=="function"&&(t=t(),typeof t=="function"&&(t=t())),typeof t=="string"||typeof t=="number"){e.appendChild(document.createTextNode(t));continue}if(p(t))e.appendChild(t);else if(typeof t<"u")throw new Error(" \u2718 Cradova err: invalid child type: "+t+" ("+typeof t+")")}return e}function k(r){if(Array.isArray(r)&&(r=r[0]),typeof r=="string"){let e=document.querySelector("style");if(e!==null){e.textContent=r+e.textContent;return}e=document.createElement("style"),e.textContent=r,document.head.appendChild(e);}}function S(r,...e){if(r)return e}function C(r,e,t){return r?e:t}function R(r,...e){return t=>{if(t===r)return e}}function D(r,...e){if(e.length)for(let t=0;t<e.length;t++){let n=e[t],o=n(r);if(o)return o}}function P(r,e){if(typeof e!="function")throw new Error(" \u2718 Cradova err : Invalid component type, must be a function that returns html ");return Array.isArray(r)?r.map(e):void 0}var d;function w(){let r=0,e=window.location.href;for(let t=0;t<e.length;t++)r+=e.charCodeAt(t);d=r.toString();}var v=class{constructor(e,t){this.effects=[];this.effectuate=null;this.rendered=!1;this.published=!1;this.preRendered=null;this.reference=new u;this._state=[];this._state_track={};this._state_index=0;this.component=e.bind(this),t&&(t===!0||t.active)&&f.addActiveEventListener("active-Refs",()=>{this.updateState(this.stash);});}preRender(e,t){this.reference._appendDomForce("html",this.render(e,t));}destroyPreRendered(){this.preRendered=null;}define(e,t){typeof e=="string"&&typeof t=="function"&&!Object.prototype.hasOwnProperty.call(this,e)?this[e]=t.bind(this):console.error(" \u2718 Cradova err : Invalid Ref.define parameters");}render(e,t){this.effects=[],this.rendered=!1;let n=this.component(e);return typeof n=="function"&&(n=n()),n||(n=this.preRendered),t&&(this.stash=e),p(n)?(this.reference._appendDomForce("html",n),this.effector.apply(this),this.rendered=!0,this.published=!0):console.error(" \u2718 Cradova err : Invalid html content, got - "+n),n}instance(){return this.reference.current("html")}_setExtra(e){this.Signal=e;}_roll_state(e,t,n=!1){return n||(this._state[t]=e),this._state[t]}_effect(e){this.rendered||this.effects.push(e.bind(this));}async effector(){if(!this.rendered){for(let e=0;e<this.effects.length;e++)await this.effects[e].apply(this);this.effects=[];}this.effectuate&&(this.effectuate(),this.effectuate=null);}updateState(e,t){this.rendered?this.published&&this.Activate(e):this.effectuate=()=>{this.published&&this.Activate(e);},t&&(this.stash=e);}async Activate(e){if(this._state_index=0,this.published=!1,!this.rendered)return;let t=this.component(e);if(typeof t=="function"&&(t=t()),p(t)){let n=this.reference.current("html");n&&(n.insertAdjacentElement("beforebegin",t),n.remove()),this.published=!0,this.reference._appendDomForce("html",t),f.dispatchEvent("onmountEvent");}else console.error(" \u2718 Cradova err : Invalid html content, got - "+t);}},A=function(r){let e=document.createDocumentFragment();for(let t=0;t<r.length;t++){let n=r[t];if(typeof n=="function"&&(n=n()),p(n)){e.appendChild(n);continue}if(n instanceof String){e.appendChild(document.createTextNode(n));continue}throw console.error(" \u2718 Cradova err: wrong element type"+n),new TypeError(" \u2718 Cradova err: invalid element")}return e},H=class{constructor(e){this._cb=e;}async load(){let e=await this._cb();typeof e=="function"?e=await e():e=await e;let t=e;t.default&&(this.content=t?.default);}},u=class{constructor(){this.tree={};this.globalTree={};}bindAs(e){return [this,e]}current(e){return this.tree[d]?this.tree[d][e]:null}_appendDomForce(e,t){this.tree[d]?this.tree[d][e]=t:(this.tree[d]={},this.tree[d][e]=t);}_appendDomForceGlobal(e,t){this.globalTree[e]=t;}};function N(r,e){e._state_index+=1;let t=e._state_index;e._state_track[t]||(e._roll_state(r,t),e._state_track[t]=!0);function n(o){e._roll_state(o,t),e.updateState(o);}return [e._roll_state(null,t,!0),n]}function F(r,e){e._effect(r);}function V(){return new u}var y=class{constructor(e,t){this.persistName="";this.actions={};this.ref=[];if(this.value=e,t&&t.persistName){this.persistName=t.persistName;let n=localStorage.getItem(t.persistName);if(n&&n!=="undefined"&&(this.value=JSON.parse(n)),typeof e=="object")for(let o in e)Object.prototype.hasOwnProperty.call(this.value,o)||(this.value[o]=e[o]);}}set(e,t){typeof e=="function"?this.value=e(this.value):this.value=e,this.persistName&&localStorage.setItem(this.persistName,JSON.stringify(this.value)),this.ref.length&&t!==!1&&this._updateState(),this.callback&&this.callback(this.value);}setKey(e,t,n){if(typeof this.value=="object"&&!Array.isArray(this.value))this.value[e]=t,this.persistName&&localStorage.setItem(this.persistName,JSON.stringify(this.value)),this.ref.length&&n!==!1&&this._updateState(),this.callback&&this.callback(this.value);else throw new Error(`\u2718 Cradova err : can't set key ${String(e)} . store.value is not a javascript object`)}createAction(e,t){if(typeof e=="string"&&typeof t=="function")this.actions[e]=t;else throw new Error(`\u2718 Cradova err : can't create action, ${e} is not a function`)}createActions(e){for(let[t,n]of Object.entries(e))if(typeof t=="string"&&typeof n=="function")this.actions[t]=n;else throw new Error(`\u2718 Cradova err : can't create action, ${t} is not a function`)}fireAction(e,t){if(this._updateState(e,t),typeof this.actions[e]=="function")return this.actions[e].call(this,t);throw Error("\u2718 Cradova err : action "+e+" does not exist!")}bind(e){if(typeof this.value=="object"&&typeof this.value[e]<"u")return [this,e];throw new Error("\u2718 Cradova err : can't bind an unavailable property! "+e)}_updateState(e,t){if(e&&t)this.ref.map(n=>{if(n._event===e){if(n._element_property&&n._signalProperty){n.ref?.updateState({[n._element_property]:t[n._signalProperty]});return}if(n._element_property){n.ref.updateState({[n._element_property]:t});return}if(n._signalProperty){n.ref.updateState(t[n._signalProperty]);return}}});else for(let n=0;n<this.ref.length;n++){let o=this.ref[n];if(o._element_property&&o._signalProperty){o.ref.updateState({[o._element_property]:this.value[o._signalProperty]});continue}if(o._element_property){o.ref.updateState({[o._element_property]:this.value});continue}if(o._signalProperty){o.ref.updateState(this.value[o._signalProperty]);continue}if(!o._element_property&&!o._signalProperty){o.ref.updateState(this.value);continue}}}bindRef(e,t={signalProperty:"",_element_property:""}){if(e.render&&(e.render=e.render.bind(e,this.value)),e._setExtra&&e._setExtra(this),e&&e.updateState){this.ref.push({ref:e,_signalProperty:t.signalProperty,_element_property:t._element_property,_event:t.event});return}throw new Error("\u2718 Cradova err : Invalid parameters for binding ref to Signal")}listen(e){this.callback=e;}clearPersist(){this.persistName&&localStorage.removeItem(this.persistName);}};var m=new u,h=class{constructor(e){this._packed=!1;this._template=document.createElement("div");this._persist=!0;this._delegatedRoutesCount=-1;this._dropped=!1;this._errorHandler=null;let{template:t,name:n,persist:o,renderInParallel:s}=e;this._html=t,this._name=n||"Document",this._template.setAttribute("id","cradova-screen-set"),s===!0?(this._delegatedRoutesCount=0,this._persist=!1):typeof o=="boolean"&&(this._persist=o);}_derive(){return {_name:this._name,_callBack:this._callBack,_deCallBack:this._deCallBack}}_apply_derivation(e){this._name=e._name,this._callBack=e._callBack,this._deCallBack=e._deCallBack;}get _delegatedRoutes(){return this._delegatedRoutesCount>100?-1:this._delegatedRoutesCount}set _delegatedRoutes(e){e&&(this._delegatedRoutesCount+=1);}setErrorHandler(e){this._errorHandler=e;}async _package(){if(typeof this._html=="function"){let e=await this._html.apply(this);if(typeof e=="function")e=e(),p(e)&&(this._template.innerHTML="",this._template.appendChild(e));else if(p(e))this._template.innerHTML="",this._template.appendChild(e);else throw new Error(` \u2718 Cradova err: template function for the screen with name '${this._name}' returned ${e} instead of html`)}}onActivate(e){this._callBack=e;}onDeactivate(e){this._deCallBack=e;}async _deActivate(){this._deCallBack&&await this._deCallBack(m.globalTree.doc);}drop(e){if(typeof e=="boolean"){this._dropped=e;return}else return this._dropped}async _Activate(e=!1){if(this._dropped){history.go(-1);return}!this._persist||e||!this._packed?(w(),await this._package(),this._packed=!0):f.dispatchActiveEvent("active-Refs"),document.title=this._name,m.globalTree.doc.innerHTML="",m.globalTree.doc.appendChild(this._template),f.dispatchEvent("onmountEvent"),window.scrollTo({top:0,left:0,behavior:"instant"}),this._callBack&&await this._callBack(m.globalTree.doc);}};var a={};a.lastNavigatedRouteController=null;a.nextRouteController=null;a.lastNavigatedRoute=null;a.pageShow=null;a.pageHide=null;a.errorHandler=null;a.loadingScreen=null;a.params={};a.routes={};a.pageevents=[];a.paused=!1;a.start_pageevents=async function(r){setTimeout(()=>{for(let e=0;e<a.pageevents.length;e++)a.pageevents[e](r);},100);};var L=r=>{if(a.routes[r])return [a.routes[r],{path:r}];if(a.routes[r+"/"])return [a.routes[r],{path:r}];for(let e in a.routes){if(!e.includes(":"))continue;let t=r.split("/"),n=e.split("/");r.endsWith("/")&&t.pop();let o=0,s=0;if(t.shift(),n.shift(),n.length===t.length){let l={_path:""};for(let c=0;c<n.length;c++){if(n[c].includes(":")){s++;continue}t[c]===n[c]&&o++;}if(o+s===n.length){for(let c=0;c<n.length;c++)n[c].includes(":")&&(l[n[c].split(":")[1]]=t[c]);return l._path=e,[a.routes[e],l]}}}return []};a.route=(r,e)=>{if(typeof e<"u"){if(e&&!e._Activate)throw console.error(" \u2718 Cradova err: not a valid screen ",e),new Error(" \u2718 Cradova err: Not a valid cradova screen component");return a.routes[r]=e}};a.router=async function(r,e){let t=window.location.pathname,n,o;if(a.paused){window.location.hash="paused";return}if(t!==a.lastNavigatedRoute)if(a.nextRouteController?(n=a.nextRouteController,a.nextRouteController=null):[n,o]=L(t),typeof n<"u")try{if(typeof n=="function"&&(a.LoadingScreen&&a.LoadingScreen._Activate&&await a.LoadingScreen._Activate(),n=await n(),!n)){a.lastNavigatedRoute&&history.pushState({},t,a.lastNavigatedRoute);return}if(n._delegatedRoutes!==-1){n._delegatedRoutes=!0;let s=n._derive();n=new h({template:n._html}),n._apply_derivation(s),a.routes[t]=n;}o&&(a.params.params=o),await n._Activate(e),a.start_pageevents(t),a.lastNavigatedRouteController&&a.lastNavigatedRouteController._deActivate(),a.lastNavigatedRoute=t,a.lastNavigatedRouteController=n;}catch(s){if(n&&n._errorHandler)n._errorHandler(s);else if(a.errorHandler)a.errorHandler(s);else throw console.error(s),new Error(" \u2718 Cradova err: consider adding error boundary to the specific screen ")}else a.routes["*"]&&await a.routes["*"]._Activate(e);};var g=class{static BrowserRoutes(e){for(let t in e){let n=e[t];typeof n=="object"&&typeof n.then=="function"||typeof n=="function"?a.routes[t]=async()=>(n=await(typeof n=="function"?await n():await n),a.route(t,n?.default||n)):a.route(t,n);}g._mount();}static back(){history.go(-1);}static forward(){history.go(1);}static pauseNaviagtion(){a.paused=!0,window.location.hash="paused";}static resumeNaviagtion(){a.paused=!1,window.location.replace(window.location.pathname+window.location.search),history.go(-1);}static navigate(e,t=null,n=!1){if(typeof e!="string")throw new TypeError(" \u2718 Cradova err: href must be a defined path but got "+e+" instead");let o=null,s;if(e.includes("://"))window.location.href=e;else {if(e===window.location.pathname)return;[o,s]=L(e),o&&(a.nextRouteController=o,window.history.pushState({},"",e)),a.params.params=s,a.params.data=t,a.router(null,n);}}static navigateNauturally(e){if(typeof e!="string")throw new TypeError(" \u2718 Cradova err: pathname must be a defined path but got "+e+" instead");window.location.pathname=e;}static setLoadingScreen(e){if(e instanceof h)a.LoadingScreen=e;else throw new Error(" \u2718 Cradova err: Loading Screen should be a cradova screen class")}static onPageEvent(e){if(typeof e=="function")a.pageevents.push(e);else throw new Error(" \u2718 Cradova err: callback for pageShow event is not a function")}static async packageScreen(e,t={}){if(!a.routes[e])throw console.error(" \u2718 Cradova err: no screen with path "+e),new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");let[n,o]=L(e);!n._Activate&&typeof n=="function"&&(n=await n()),n._delegatedRoutes!==-1&&(n._delegatedRoutes=!0,n=new h({name:n._name,template:n._html}),a.routes[e]=n),n._package(Object.assign(t,o||{})),n._packed=!0;}static getParams(){return a.params}static addErrorHandler(e){if(typeof e=="function")a.errorHandler=e;else throw new Error(" \u2718 Cradova err: callback for error event is not a function")}static _mount(){let e=document.querySelector("[data-wrapper=app]");e?m._appendDomForceGlobal("doc",e):(e=document.createElement("div"),e.setAttribute("data-wrapper","app"),document.body.appendChild(e),m._appendDomForceGlobal("doc",e)),window.addEventListener("pageshow",a.router),window.addEventListener("popstate",t=>{t.preventDefault(),a.router();});}};var _=(r,e)=>{let t={},n=null;if(e.length!==0)for(let o=0;o<e.length;o++){let s=e[o];if(typeof s=="function"&&(s=s()),s instanceof v&&(s=s.render()),p(s)){r.appendChild(s);continue}if(Array.isArray(s)){r.appendChild(E(s));continue}if(typeof s=="string"||typeof s=="number"){n=s;continue}if(typeof s=="object"){t=Object.assign(t,s);continue}}else return r;if(typeof t=="object"&&r)for(let[o,s]of Object.entries(t)){if(o==="style"&&typeof s=="object"){Object.assign(r.style,s);continue}if(Array.isArray(s)){if(o=="reference"&&s[0]instanceof u){s[0]._appendDomForce(s[1],r);continue}if(s[0]instanceof y){s[0].bindRef(r,{_element_property:o,signalProperty:s[1]});continue}}if(o==="onmount"&&typeof t.onmount=="function"){let l=()=>{t.onmount?.apply(r),t.onmount=void 0;};f.addEventListener("onmountEvent",l);continue}if(o.includes("data-")){r.setAttribute(o,s);continue}if(o.includes("aria-")){r.setAttribute(o,s);continue}if(o==="href"&&typeof s=="string"){let l=s||"";l.includes("://")||r.addEventListener("click",c=>{c.preventDefault(),g.navigate(r.pathname);if(l.includes("#")){let b=l.split("#").at(-1);document.getElementById("#"+b)?.scrollIntoView();}}),r.setAttribute(o,s);continue}if(typeof r.style[o]<"u"&&o!=="src"){r.style[o]=s;continue}r[o]=s;}return n&&r.appendChild(document.createTextNode(n)),r},x=function(r){if(typeof r!="string")return [];Array.isArray(r)&&(r=r[0]);let e="";if(r.includes("|")&&([r,e]=r.split("|"),!r))return ["P",void 0,void 0,e];let t;if(r.includes("#")){if(!r.includes("."))return r=r.split("#"),t=r.shift(),t||(t="DIV"),r[0].includes(" ")&&(r=[r[0].split(" ")[1]]),[t,r[0],void 0,e]}else return r=r.split("."),t=r.shift(),t||(t="DIV"),[t,void 0,r.join(" "),e];r=r.split(".");let n=[],o=[];t=!r[0].includes("#")&&r.shift(),t||(t="DIV");for(let s=0;s<r.length;s++){if(r[s].includes("#")){let l=r[s].split("#");if(o.push(l[1]),s===0){t=l[0];continue}n.push(l[0]);continue}n.push(r[s]);}return [t,o[0],n.join(" "),e]},i=r=>(...t)=>_(document.createElement(r),t),Q=i("a"),W=i("article"),X=i("audio"),Z=i("br"),z=i("button"),ee=i("canvas"),te=i("caption"),ne=i("col"),re=i("colgroup"),oe=i("datalist"),ae=i("details"),ie=i("dialog"),se=i("div"),le=i("em"),ce=i("embed"),pe=i("figure"),ue=i("footer"),de=i("form"),fe=i("h1"),me=i("h2"),he=i("h3"),ge=i("h4"),ve=i("h5"),ye=i("h6"),_e=i("head"),Te=i("header"),Ee=i("hr"),we=i("i"),Le=i("iframe"),He=i("img"),xe=i("input"),be=i("label"),Me=i("li"),ke=i("main"),Se=i("nav"),Ce=i("ol"),Re=i("optgroup"),De=i("option"),Pe=i("p"),Ae=i("progress"),Ne=i("q"),Fe=i("section"),Ve=i("select"),Be=i("source"),Je=i("span"),Ie=i("strong"),je=i("summary"),Oe=i("table"),Ye=i("tbody"),$e=i("td"),Ge=i("template"),Ue=i("textarea"),qe=i("th"),Ke=i("title"),Qe=i("tr"),We=i("track"),Xe=i("u"),Ze=i("ul"),ze=i("video"),et=(r,e)=>{let t=document.createElement("span");return t.innerHTML=r,_(t,[e])},tt=r=>{let e=document.createElement("div");return e.innerHTML=r,Array.from(e.children)};var M=(...r)=>{let{0:e,1:t,2:n,3:o}=x(r[0]),s=e?document.createElement(e):new DocumentFragment;return e&&(n&&(s.className=n),t&&(s.id=t),o&&(s.innerText=o),r.shift()),_(s,r)},ot=M;
|
|
336
19
|
|
|
337
|
-
|
|
338
|
-
function dispatch(element, state) {
|
|
339
|
-
if (!element) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
if (typeof state === "object" && !Array.isArray(state)) {
|
|
343
|
-
for (const key in state) {
|
|
344
|
-
if (key === "style" && typeof state[key] === "object") {
|
|
345
|
-
for (const [k, v] of Object.entries(state[key])) {
|
|
346
|
-
if (typeof element.style[k] !== "undefined" && k !== "src" && typeof v === "string") {
|
|
347
|
-
element.style[k] = v;
|
|
348
|
-
} else {
|
|
349
|
-
throw new Error(
|
|
350
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
const stateK = state;
|
|
357
|
-
if (typeof element[key] === "function") {
|
|
358
|
-
if (key.startsWith("on")) {
|
|
359
|
-
element[key] = stateK[key];
|
|
360
|
-
} else {
|
|
361
|
-
element[key].apply(element);
|
|
362
|
-
}
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
if (key === "text") {
|
|
366
|
-
element.innerText = stateK[key];
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
if (key === "tree") {
|
|
370
|
-
element.innerHTML = "";
|
|
371
|
-
element.appendChild(frag([stateK[key]]));
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
if (key.includes("data-")) {
|
|
375
|
-
element.setAttribute(key, stateK[key]);
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
element[key] = stateK[key];
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
if (typeof state === "string") {
|
|
382
|
-
element.innerText = state;
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
if (typeof state === "function") {
|
|
386
|
-
element.appendChild(frag([state]));
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
if (state instanceof HTMLElement) {
|
|
390
|
-
element.appendChild(state);
|
|
391
|
-
}
|
|
392
|
-
if (!(typeof state === "object" && !Array.isArray(state))) {
|
|
393
|
-
throw new Error(
|
|
394
|
-
" \u2718 Cradova err: Cradova got invalid state => \n" + String(state)
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// lib/parts/createSignal.ts
|
|
400
|
-
var createSignal = class {
|
|
401
|
-
constructor(initial, props) {
|
|
402
|
-
this.persistName = "";
|
|
403
|
-
this.actions = {};
|
|
404
|
-
this.ref = [];
|
|
405
|
-
this.value = initial;
|
|
406
|
-
if (props && props.persistName) {
|
|
407
|
-
this.persistName = props.persistName;
|
|
408
|
-
const key = localStorage.getItem(props.persistName);
|
|
409
|
-
if (key && key !== "undefined") {
|
|
410
|
-
this.value = JSON.parse(key);
|
|
411
|
-
}
|
|
412
|
-
if (typeof initial === "object") {
|
|
413
|
-
for (const key2 in initial) {
|
|
414
|
-
if (!Object.prototype.hasOwnProperty.call(this.value, key2)) {
|
|
415
|
-
this.value[key2] = initial[key2];
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Cradova Signal
|
|
423
|
-
* ----
|
|
424
|
-
* set signal value
|
|
425
|
-
* @param value - signal value
|
|
426
|
-
* @returns void
|
|
427
|
-
*/
|
|
428
|
-
set(value, shouldRefRender) {
|
|
429
|
-
if (typeof value === "function") {
|
|
430
|
-
this.value = value(this.value);
|
|
431
|
-
} else {
|
|
432
|
-
this.value = value;
|
|
433
|
-
}
|
|
434
|
-
if (this.persistName) {
|
|
435
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
436
|
-
}
|
|
437
|
-
if (this.ref.length && shouldRefRender !== false) {
|
|
438
|
-
this._updateState();
|
|
439
|
-
}
|
|
440
|
-
if (this.callback) {
|
|
441
|
-
this.callback(this.value);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Cradova Signal
|
|
446
|
-
* ----
|
|
447
|
-
* set a key value if it's an object
|
|
448
|
-
* @param key - key of the key
|
|
449
|
-
* @param value - value of the key
|
|
450
|
-
* @returns void
|
|
451
|
-
*/
|
|
452
|
-
setKey(key, value, shouldRefRender) {
|
|
453
|
-
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
454
|
-
this.value[key] = value;
|
|
455
|
-
if (this.persistName) {
|
|
456
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
457
|
-
}
|
|
458
|
-
if (this.ref.length && shouldRefRender !== false) {
|
|
459
|
-
this._updateState();
|
|
460
|
-
}
|
|
461
|
-
if (this.callback) {
|
|
462
|
-
this.callback(this.value);
|
|
463
|
-
}
|
|
464
|
-
} else {
|
|
465
|
-
throw new Error(
|
|
466
|
-
`\u2718 Cradova err : can't set key ${String(
|
|
467
|
-
key
|
|
468
|
-
)} . store.value is not a javascript object`
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Cradova Signal
|
|
474
|
-
* ----
|
|
475
|
-
* set a key to signal an action
|
|
476
|
-
* @param name - name of the action
|
|
477
|
-
* @param action function to execute
|
|
478
|
-
*/
|
|
479
|
-
createAction(name, action) {
|
|
480
|
-
if (typeof name === "string" && typeof action === "function") {
|
|
481
|
-
this.actions[name] = action;
|
|
482
|
-
} else {
|
|
483
|
-
throw new Error(
|
|
484
|
-
`\u2718 Cradova err : can't create action, ${name} is not a function`
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Cradova Signal
|
|
490
|
-
* ----
|
|
491
|
-
* creates man y actions at a time
|
|
492
|
-
* @param name - name of the action
|
|
493
|
-
* @param action function to execute
|
|
494
|
-
*/
|
|
495
|
-
createActions(Actions) {
|
|
496
|
-
for (const [name, action] of Object.entries(Actions)) {
|
|
497
|
-
if (typeof name === "string" && typeof action === "function") {
|
|
498
|
-
this.actions[name] = action;
|
|
499
|
-
} else {
|
|
500
|
-
throw new Error(
|
|
501
|
-
`\u2718 Cradova err : can't create action, ${name} is not a function`
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Cradova Signal
|
|
508
|
-
* ----
|
|
509
|
-
* fires an action if available
|
|
510
|
-
* @param key - string key of the action
|
|
511
|
-
* @param data - data for the action
|
|
512
|
-
*/
|
|
513
|
-
fireAction(key, data2) {
|
|
514
|
-
this._updateState(key, data2);
|
|
515
|
-
if (typeof this.actions[key] === "function") {
|
|
516
|
-
return this.actions[key].call(this, data2);
|
|
517
|
-
} else {
|
|
518
|
-
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Cradova
|
|
523
|
-
* ---
|
|
524
|
-
* is used to bind signal data to elements and Refs
|
|
525
|
-
*
|
|
526
|
-
* @param prop
|
|
527
|
-
* @returns something
|
|
528
|
-
*/
|
|
529
|
-
bind(prop) {
|
|
530
|
-
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
531
|
-
return [this, prop];
|
|
532
|
-
} else {
|
|
533
|
-
throw new Error(
|
|
534
|
-
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
_updateState(name, data2) {
|
|
539
|
-
if (name && data2) {
|
|
540
|
-
this.ref.map((ent) => {
|
|
541
|
-
if (ent._event === name) {
|
|
542
|
-
if (ent._element_property && ent._signalProperty) {
|
|
543
|
-
ent.ref?.updateState({
|
|
544
|
-
[ent._element_property]: data2[ent._signalProperty]
|
|
545
|
-
});
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
if (ent._element_property) {
|
|
549
|
-
ent.ref.updateState({
|
|
550
|
-
[ent._element_property]: data2
|
|
551
|
-
});
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
if (ent._signalProperty) {
|
|
555
|
-
ent.ref.updateState(data2[ent._signalProperty]);
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
} else {
|
|
561
|
-
for (let i2 = 0; i2 < this.ref.length; i2++) {
|
|
562
|
-
const ent = this.ref[i2];
|
|
563
|
-
if (ent._element_property && ent._signalProperty) {
|
|
564
|
-
ent.ref.updateState({
|
|
565
|
-
[ent._element_property]: this.value[ent._signalProperty]
|
|
566
|
-
});
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
if (ent._element_property) {
|
|
570
|
-
ent.ref.updateState({
|
|
571
|
-
[ent._element_property]: this.value
|
|
572
|
-
});
|
|
573
|
-
continue;
|
|
574
|
-
}
|
|
575
|
-
if (ent._signalProperty) {
|
|
576
|
-
ent.ref.updateState(this.value[ent._signalProperty]);
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
if (!ent._element_property && !ent._signalProperty) {
|
|
580
|
-
ent.ref.updateState(this.value);
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Cradova Signal
|
|
588
|
-
* ----
|
|
589
|
-
* set a auto - rendering component for this store
|
|
590
|
-
*
|
|
591
|
-
* @param Ref component to bind to.
|
|
592
|
-
* @param path a property in the object to send to attached ref
|
|
593
|
-
*/
|
|
594
|
-
bindRef(ref, binding = { signalProperty: "", _element_property: "" }) {
|
|
595
|
-
if (ref.render) {
|
|
596
|
-
ref.render = ref.render.bind(ref, this.value);
|
|
597
|
-
}
|
|
598
|
-
if (ref._setExtra) {
|
|
599
|
-
ref._setExtra(this);
|
|
600
|
-
}
|
|
601
|
-
if (ref && ref.updateState) {
|
|
602
|
-
this.ref.push({
|
|
603
|
-
ref,
|
|
604
|
-
_signalProperty: binding.signalProperty,
|
|
605
|
-
_element_property: binding._element_property,
|
|
606
|
-
_event: binding.event
|
|
607
|
-
});
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
throw new Error(
|
|
611
|
-
"\u2718 Cradova err : Invalid parameters for binding ref to Signal"
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Cradova Signal
|
|
616
|
-
* ----
|
|
617
|
-
* set a update listener on value changes
|
|
618
|
-
* @param callback
|
|
619
|
-
*/
|
|
620
|
-
listen(callback) {
|
|
621
|
-
this.callback = callback;
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* Cradova Signal
|
|
625
|
-
* ----
|
|
626
|
-
* clear the history on local storage
|
|
627
|
-
*
|
|
628
|
-
*/
|
|
629
|
-
clearPersist() {
|
|
630
|
-
if (this.persistName) {
|
|
631
|
-
localStorage.removeItem(this.persistName);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
// lib/parts/Screen.ts
|
|
637
|
-
var localTree = new reference();
|
|
638
|
-
var Screen = class {
|
|
639
|
-
constructor(cradova_screen_initials) {
|
|
640
|
-
/**
|
|
641
|
-
* error handler for the screen
|
|
642
|
-
*/
|
|
643
|
-
this._errorHandler = null;
|
|
644
|
-
this._packed = false;
|
|
645
|
-
this._template = document.createElement("div");
|
|
646
|
-
this._persist = true;
|
|
647
|
-
this._delegatedRoutesCount = -1;
|
|
648
|
-
this._dropped = false;
|
|
649
|
-
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
650
|
-
this._html = template2;
|
|
651
|
-
this._name = name;
|
|
652
|
-
this._transition = transition;
|
|
653
|
-
this._template.setAttribute("id", "cradova-screen-set");
|
|
654
|
-
if (renderInParallel === true) {
|
|
655
|
-
this._delegatedRoutesCount = 0;
|
|
656
|
-
this._persist = false;
|
|
657
|
-
} else {
|
|
658
|
-
if (typeof persist === "boolean") {
|
|
659
|
-
this._persist = persist;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
get _delegatedRoutes() {
|
|
664
|
-
if (this._delegatedRoutesCount > 100) {
|
|
665
|
-
return -1;
|
|
666
|
-
}
|
|
667
|
-
return this._delegatedRoutesCount;
|
|
668
|
-
}
|
|
669
|
-
set _delegatedRoutes(count) {
|
|
670
|
-
if (count) {
|
|
671
|
-
this._delegatedRoutesCount += 1;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
setErrorHandler(errorHandler) {
|
|
675
|
-
this._errorHandler = errorHandler;
|
|
676
|
-
}
|
|
677
|
-
async _package() {
|
|
678
|
-
if (typeof this._html === "function") {
|
|
679
|
-
let fuc = await this._html.apply(this);
|
|
680
|
-
if (typeof fuc === "function") {
|
|
681
|
-
fuc = fuc();
|
|
682
|
-
if (isNode(fuc)) {
|
|
683
|
-
this._template.innerHTML = "";
|
|
684
|
-
this._template.appendChild(fuc);
|
|
685
|
-
}
|
|
686
|
-
} else {
|
|
687
|
-
if (isNode(fuc)) {
|
|
688
|
-
this._template.innerHTML = "";
|
|
689
|
-
this._template.appendChild(fuc);
|
|
690
|
-
} else {
|
|
691
|
-
throw new Error(
|
|
692
|
-
` \u2718 Cradova err: template function for the screen with name '${this._name}' returned ${fuc} instead of html`
|
|
693
|
-
);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
onActivate(cb) {
|
|
699
|
-
this._callBack = cb;
|
|
700
|
-
}
|
|
701
|
-
onDeactivate(cb) {
|
|
702
|
-
this._deCallBack = cb;
|
|
703
|
-
}
|
|
704
|
-
async _deActivate() {
|
|
705
|
-
if (this._deCallBack) {
|
|
706
|
-
await this._deCallBack();
|
|
707
|
-
}
|
|
708
|
-
if (this._transition) {
|
|
709
|
-
this._template.classList.remove(this._transition);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
drop(state) {
|
|
713
|
-
if (typeof state === "boolean") {
|
|
714
|
-
this._dropped = state;
|
|
715
|
-
return void 0;
|
|
716
|
-
} else
|
|
717
|
-
return this._dropped;
|
|
718
|
-
}
|
|
719
|
-
async _Activate(force = false) {
|
|
720
|
-
if (this._dropped) {
|
|
721
|
-
history.go(-1);
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
if (!this._persist || force || !this._packed) {
|
|
725
|
-
await this._package();
|
|
726
|
-
this._packed = true;
|
|
727
|
-
}
|
|
728
|
-
if (this._transition) {
|
|
729
|
-
this._template.classList.add(this._transition);
|
|
730
|
-
}
|
|
731
|
-
document.title = this._name;
|
|
732
|
-
localTree.doc.innerHTML = "";
|
|
733
|
-
localTree.doc.appendChild(this._template);
|
|
734
|
-
CradovaEvent.dispatchEvent("onmountEvent");
|
|
735
|
-
window.scrollTo({
|
|
736
|
-
top: 0,
|
|
737
|
-
left: 0,
|
|
738
|
-
// @ts-ignore
|
|
739
|
-
behavior: "instant"
|
|
740
|
-
});
|
|
741
|
-
if (this._callBack) {
|
|
742
|
-
await this._callBack();
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
// lib/parts/Router.ts
|
|
748
|
-
var RouterBox = {};
|
|
749
|
-
RouterBox["lastNavigatedRouteController"] = null;
|
|
750
|
-
RouterBox["nextRouteController"] = null;
|
|
751
|
-
RouterBox["lastNavigatedRoute"] = null;
|
|
752
|
-
RouterBox["pageShow"] = null;
|
|
753
|
-
RouterBox["pageHide"] = null;
|
|
754
|
-
RouterBox["errorHandler"] = null;
|
|
755
|
-
RouterBox["loadingScreen"] = null;
|
|
756
|
-
RouterBox["params"] = {};
|
|
757
|
-
RouterBox["routes"] = {};
|
|
758
|
-
RouterBox["pageevents"] = [];
|
|
759
|
-
RouterBox["paused"] = false;
|
|
760
|
-
RouterBox["start_pageevents"] = async function(url) {
|
|
761
|
-
setTimeout(() => {
|
|
762
|
-
for (let ci = 0; ci < RouterBox["pageevents"].length; ci++) {
|
|
763
|
-
RouterBox["pageevents"][ci](url);
|
|
764
|
-
}
|
|
765
|
-
}, 100);
|
|
766
|
-
};
|
|
767
|
-
var checker = (url) => {
|
|
768
|
-
if (RouterBox.routes[url]) {
|
|
769
|
-
return [RouterBox.routes[url], { path: url }];
|
|
770
|
-
}
|
|
771
|
-
if (RouterBox.routes[url + "/"]) {
|
|
772
|
-
return [RouterBox.routes[url], { path: url }];
|
|
773
|
-
}
|
|
774
|
-
for (const path in RouterBox.routes) {
|
|
775
|
-
if (!path.includes(":")) {
|
|
776
|
-
continue;
|
|
777
|
-
}
|
|
778
|
-
const urlFixtures = url.split("/");
|
|
779
|
-
const pathFixtures = path.split("/");
|
|
780
|
-
if (url.endsWith("/")) {
|
|
781
|
-
urlFixtures.pop();
|
|
782
|
-
}
|
|
783
|
-
let fixturesX = 0;
|
|
784
|
-
let fixturesY = 0;
|
|
785
|
-
urlFixtures.shift();
|
|
786
|
-
pathFixtures.shift();
|
|
787
|
-
if (pathFixtures.length === urlFixtures.length) {
|
|
788
|
-
const routesParams = { _path: "" };
|
|
789
|
-
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
790
|
-
if (pathFixtures[i2].includes(":")) {
|
|
791
|
-
fixturesY++;
|
|
792
|
-
continue;
|
|
793
|
-
}
|
|
794
|
-
if (urlFixtures[i2] === pathFixtures[i2]) {
|
|
795
|
-
fixturesX++;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
799
|
-
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
800
|
-
if (pathFixtures[i2].includes(":")) {
|
|
801
|
-
routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
routesParams._path = path;
|
|
805
|
-
return [RouterBox.routes[path], routesParams];
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
return [];
|
|
810
|
-
};
|
|
811
|
-
RouterBox.route = (path, screen) => {
|
|
812
|
-
if (typeof screen !== "undefined") {
|
|
813
|
-
if (screen && !screen._Activate) {
|
|
814
|
-
console.error(" \u2718 Cradova err: not a valid screen ", screen);
|
|
815
|
-
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
816
|
-
}
|
|
817
|
-
return RouterBox.routes[path] = screen;
|
|
818
|
-
}
|
|
819
|
-
return void 0;
|
|
820
|
-
};
|
|
821
|
-
RouterBox.router = async function(_e, _force) {
|
|
822
|
-
let url = window.location.pathname, route, params;
|
|
823
|
-
if (RouterBox["paused"]) {
|
|
824
|
-
window.location.hash = "paused";
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
if (url === RouterBox["lastNavigatedRoute"]) {
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
if (RouterBox["nextRouteController"]) {
|
|
831
|
-
route = RouterBox["nextRouteController"];
|
|
832
|
-
RouterBox["nextRouteController"] = null;
|
|
833
|
-
} else {
|
|
834
|
-
[route, params] = checker(url);
|
|
835
|
-
}
|
|
836
|
-
if (typeof route !== "undefined") {
|
|
837
|
-
try {
|
|
838
|
-
if (typeof route === "function") {
|
|
839
|
-
if (RouterBox["LoadingScreen"] && RouterBox["LoadingScreen"]._Activate) {
|
|
840
|
-
await RouterBox["LoadingScreen"]._Activate();
|
|
841
|
-
}
|
|
842
|
-
route = await route();
|
|
843
|
-
if (!route) {
|
|
844
|
-
if (RouterBox["lastNavigatedRoute"]) {
|
|
845
|
-
history.pushState({}, url, RouterBox["lastNavigatedRoute"]);
|
|
846
|
-
}
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
if (route._delegatedRoutes !== -1) {
|
|
851
|
-
route._delegatedRoutes = true;
|
|
852
|
-
route = new Screen({
|
|
853
|
-
name: route._name,
|
|
854
|
-
template: route._html
|
|
855
|
-
});
|
|
856
|
-
RouterBox.routes[url] = route;
|
|
857
|
-
CradovaEvent.dispatchEvent("onTransition");
|
|
858
|
-
}
|
|
859
|
-
if (params) {
|
|
860
|
-
RouterBox.params.params = params;
|
|
861
|
-
}
|
|
862
|
-
await route._Activate(_force);
|
|
863
|
-
RouterBox["start_pageevents"](url);
|
|
864
|
-
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
|
|
865
|
-
RouterBox["lastNavigatedRoute"] = url;
|
|
866
|
-
RouterBox["lastNavigatedRouteController"] = route;
|
|
867
|
-
} catch (error) {
|
|
868
|
-
if (route && route["_errorHandler"]) {
|
|
869
|
-
route._errorHandler(error);
|
|
870
|
-
} else {
|
|
871
|
-
if (RouterBox["errorHandler"]) {
|
|
872
|
-
RouterBox["errorHandler"](error);
|
|
873
|
-
} else {
|
|
874
|
-
console.error(error);
|
|
875
|
-
throw new Error(
|
|
876
|
-
" \u2718 Cradova err: consider adding error boundary to the specific screen "
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
} else {
|
|
882
|
-
if (RouterBox.routes["/*"]) {
|
|
883
|
-
await RouterBox.routes["/*"]._Activate(_force);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
var Router = class {
|
|
888
|
-
/** cradova router
|
|
889
|
-
* ---
|
|
890
|
-
* Registers a route.
|
|
891
|
-
*
|
|
892
|
-
* accepts an object containing
|
|
893
|
-
*
|
|
894
|
-
* @param {string} path Route path.
|
|
895
|
-
* @param screen the cradova screen.
|
|
896
|
-
*/
|
|
897
|
-
static BrowserRoutes(obj) {
|
|
898
|
-
for (const path in obj) {
|
|
899
|
-
let screen = obj[path];
|
|
900
|
-
if (typeof screen === "object" && typeof screen.then === "function" || typeof screen === "function") {
|
|
901
|
-
RouterBox["routes"][path] = async () => {
|
|
902
|
-
screen = await (typeof screen === "function" ? await screen() : await screen);
|
|
903
|
-
return RouterBox.route(path, screen?.default || screen);
|
|
904
|
-
};
|
|
905
|
-
} else {
|
|
906
|
-
RouterBox.route(path, screen);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
Router._mount();
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
Go back in Navigation history
|
|
913
|
-
*/
|
|
914
|
-
static back() {
|
|
915
|
-
history.go(-1);
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
Go forward in Navigation history
|
|
919
|
-
*/
|
|
920
|
-
static forward() {
|
|
921
|
-
history.go(1);
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
Pause navigation
|
|
925
|
-
*/
|
|
926
|
-
static pauseNaviagtion() {
|
|
927
|
-
RouterBox["paused"] = true;
|
|
928
|
-
window.location.hash = "paused";
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
resume navigation
|
|
932
|
-
*/
|
|
933
|
-
static resumeNaviagtion() {
|
|
934
|
-
RouterBox["paused"] = false;
|
|
935
|
-
window.location.replace(window.location.pathname + window.location.search);
|
|
936
|
-
history.go(-1);
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Cradova Router
|
|
940
|
-
* ------
|
|
941
|
-
*
|
|
942
|
-
* Navigates to a designated screen in your app
|
|
943
|
-
*
|
|
944
|
-
* @param href string
|
|
945
|
-
* @param data object
|
|
946
|
-
* @param force boolean
|
|
947
|
-
*/
|
|
948
|
-
static navigate(href, data2 = null, force = false) {
|
|
949
|
-
if (typeof href !== "string") {
|
|
950
|
-
throw new TypeError(
|
|
951
|
-
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
952
|
-
);
|
|
953
|
-
}
|
|
954
|
-
let route = null, params;
|
|
955
|
-
if (href.includes("://")) {
|
|
956
|
-
window.location.href = href;
|
|
957
|
-
} else {
|
|
958
|
-
if (href === window.location.pathname) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
|
-
[route, params] = checker(href);
|
|
962
|
-
if (route) {
|
|
963
|
-
RouterBox["nextRouteController"] = route;
|
|
964
|
-
window.history.pushState({}, "", href);
|
|
965
|
-
}
|
|
966
|
-
RouterBox.params.params = params;
|
|
967
|
-
RouterBox.params.data = data2;
|
|
968
|
-
RouterBox.router(null, force);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Cradova Router
|
|
973
|
-
* ------
|
|
974
|
-
*
|
|
975
|
-
* Navigates to a designated screen in your app by loading a seperate page;
|
|
976
|
-
*
|
|
977
|
-
* @param pathname string
|
|
978
|
-
*/
|
|
979
|
-
static navigateNauturally(pathname) {
|
|
980
|
-
if (typeof pathname !== "string") {
|
|
981
|
-
throw new TypeError(
|
|
982
|
-
" \u2718 Cradova err: pathname must be a defined path but got " + pathname + " instead"
|
|
983
|
-
);
|
|
984
|
-
}
|
|
985
|
-
window.location.pathname = pathname;
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Cradova
|
|
989
|
-
* ---
|
|
990
|
-
* Loading screen for your app
|
|
991
|
-
*
|
|
992
|
-
* lazy loaded loading use
|
|
993
|
-
*
|
|
994
|
-
* @param screen
|
|
995
|
-
*/
|
|
996
|
-
static setLoadingScreen(screen) {
|
|
997
|
-
if (screen instanceof Screen) {
|
|
998
|
-
RouterBox["LoadingScreen"] = screen;
|
|
999
|
-
} else {
|
|
1000
|
-
throw new Error(
|
|
1001
|
-
" \u2718 Cradova err: Loading Screen should be a cradova screen class"
|
|
1002
|
-
);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
/** cradova router
|
|
1006
|
-
* ---
|
|
1007
|
-
* Listen for navigation events
|
|
1008
|
-
*
|
|
1009
|
-
* @param callback () => void
|
|
1010
|
-
*/
|
|
1011
|
-
static onPageEvent(callback) {
|
|
1012
|
-
if (typeof callback === "function") {
|
|
1013
|
-
RouterBox["pageevents"].push(callback);
|
|
1014
|
-
} else {
|
|
1015
|
-
throw new Error(
|
|
1016
|
-
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
1017
|
-
);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
/** cradova router
|
|
1021
|
-
* ---
|
|
1022
|
-
* get a screen ready before time.
|
|
1023
|
-
*
|
|
1024
|
-
* @param {string} path Route path.
|
|
1025
|
-
* @param data data for the screen.
|
|
1026
|
-
*/
|
|
1027
|
-
static async packageScreen(path, data2 = {}) {
|
|
1028
|
-
if (!RouterBox.routes[path]) {
|
|
1029
|
-
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
1030
|
-
throw new Error(
|
|
1031
|
-
" \u2718 Cradova err: cradova err: Not a defined screen path"
|
|
1032
|
-
);
|
|
1033
|
-
}
|
|
1034
|
-
let [route, params] = checker(path);
|
|
1035
|
-
if (!route._Activate && typeof route === "function") {
|
|
1036
|
-
route = await route();
|
|
1037
|
-
}
|
|
1038
|
-
if (route._delegatedRoutes !== -1) {
|
|
1039
|
-
route._delegatedRoutes = true;
|
|
1040
|
-
route = new Screen({
|
|
1041
|
-
name: route._name,
|
|
1042
|
-
template: route._html
|
|
1043
|
-
});
|
|
1044
|
-
RouterBox.routes[path] = route;
|
|
1045
|
-
}
|
|
1046
|
-
route._package(Object.assign(data2, params || {}));
|
|
1047
|
-
route._packed = true;
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
* Cradova Router
|
|
1051
|
-
* ------
|
|
1052
|
-
*
|
|
1053
|
-
* return last set router params
|
|
1054
|
-
*
|
|
1055
|
-
* .
|
|
1056
|
-
*/
|
|
1057
|
-
static getParams() {
|
|
1058
|
-
return RouterBox["params"];
|
|
1059
|
-
}
|
|
1060
|
-
/**
|
|
1061
|
-
* Cradova
|
|
1062
|
-
* ---
|
|
1063
|
-
* Error Handler for your app
|
|
1064
|
-
*
|
|
1065
|
-
* @param callback
|
|
1066
|
-
* @param path? page path
|
|
1067
|
-
*/
|
|
1068
|
-
static addErrorHandler(callback) {
|
|
1069
|
-
if (typeof callback === "function") {
|
|
1070
|
-
RouterBox["errorHandler"] = callback;
|
|
1071
|
-
} else {
|
|
1072
|
-
throw new Error(
|
|
1073
|
-
" \u2718 Cradova err: callback for error event is not a function"
|
|
1074
|
-
);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
static _mount() {
|
|
1078
|
-
let doc = document.querySelector("[data-wrapper=app]");
|
|
1079
|
-
if (!doc) {
|
|
1080
|
-
doc = document.createElement("div");
|
|
1081
|
-
doc.setAttribute("data-wrapper", "app");
|
|
1082
|
-
document.body.appendChild(doc);
|
|
1083
|
-
localTree._appendDomForce("doc", doc);
|
|
1084
|
-
} else {
|
|
1085
|
-
localTree._appendDomForce("doc", doc);
|
|
1086
|
-
}
|
|
1087
|
-
window.addEventListener("pageshow", RouterBox.router);
|
|
1088
|
-
window.addEventListener("popstate", (_e) => {
|
|
1089
|
-
_e.preventDefault();
|
|
1090
|
-
RouterBox.router();
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
// lib/parts/elements.ts
|
|
1096
|
-
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
1097
|
-
let props = {}, text = null;
|
|
1098
|
-
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
1099
|
-
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
1100
|
-
let child = ElementChildrenAndPropertyList[i2];
|
|
1101
|
-
if (typeof child === "function") {
|
|
1102
|
-
child = child();
|
|
1103
|
-
}
|
|
1104
|
-
if (child instanceof Ref) {
|
|
1105
|
-
child = child.render();
|
|
1106
|
-
}
|
|
1107
|
-
if (isNode(child)) {
|
|
1108
|
-
element.appendChild(child);
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
if (Array.isArray(child)) {
|
|
1112
|
-
element.appendChild(Rhoda(child));
|
|
1113
|
-
continue;
|
|
1114
|
-
}
|
|
1115
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
1116
|
-
text = child;
|
|
1117
|
-
continue;
|
|
1118
|
-
}
|
|
1119
|
-
if (typeof child === "object") {
|
|
1120
|
-
props = Object.assign(props, child);
|
|
1121
|
-
continue;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
} else {
|
|
1125
|
-
return element;
|
|
1126
|
-
}
|
|
1127
|
-
if (typeof props === "object" && element) {
|
|
1128
|
-
for (const [prop, value] of Object.entries(props)) {
|
|
1129
|
-
if (prop === "style" && typeof value === "object") {
|
|
1130
|
-
Object.assign(element.style, value);
|
|
1131
|
-
continue;
|
|
1132
|
-
}
|
|
1133
|
-
if (Array.isArray(value)) {
|
|
1134
|
-
if (value[0] instanceof createSignal) {
|
|
1135
|
-
element["updateState"] = dispatch.bind(null, element);
|
|
1136
|
-
value[0].bindRef(
|
|
1137
|
-
element,
|
|
1138
|
-
{
|
|
1139
|
-
_element_property: prop,
|
|
1140
|
-
signalProperty: value[1]
|
|
1141
|
-
}
|
|
1142
|
-
);
|
|
1143
|
-
continue;
|
|
1144
|
-
}
|
|
1145
|
-
if (prop == "reference" && value[0] instanceof reference) {
|
|
1146
|
-
element["updateState"] = dispatch.bind(null, element);
|
|
1147
|
-
value[0]._appendDomForce(
|
|
1148
|
-
value[1],
|
|
1149
|
-
element
|
|
1150
|
-
);
|
|
1151
|
-
continue;
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
if (prop === "onmount" && typeof props["onmount"] === "function") {
|
|
1155
|
-
const ev = () => {
|
|
1156
|
-
props.onmount?.apply(element);
|
|
1157
|
-
props["onmount"] = void 0;
|
|
1158
|
-
};
|
|
1159
|
-
CradovaEvent.addEventListener("onmountEvent", ev);
|
|
1160
|
-
continue;
|
|
1161
|
-
}
|
|
1162
|
-
if (prop.includes("data-")) {
|
|
1163
|
-
element.setAttribute(prop, value);
|
|
1164
|
-
continue;
|
|
1165
|
-
}
|
|
1166
|
-
if (prop.includes("aria-")) {
|
|
1167
|
-
element.setAttribute(prop, value);
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
if (prop === "href" && typeof value === "string") {
|
|
1171
|
-
const href = value || "";
|
|
1172
|
-
if (!href.includes("://")) {
|
|
1173
|
-
element.addEventListener(
|
|
1174
|
-
"click",
|
|
1175
|
-
(e) => {
|
|
1176
|
-
e.preventDefault();
|
|
1177
|
-
Router.navigate(
|
|
1178
|
-
element.pathname
|
|
1179
|
-
);
|
|
1180
|
-
if (href.includes("#")) {
|
|
1181
|
-
const l = href.split("#").at(-1);
|
|
1182
|
-
document.getElementById("#" + l)?.scrollIntoView();
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
element.setAttribute(prop, value);
|
|
1188
|
-
continue;
|
|
1189
|
-
}
|
|
1190
|
-
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1191
|
-
element.style[prop] = value;
|
|
1192
|
-
continue;
|
|
1193
|
-
}
|
|
1194
|
-
element[prop] = value;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
if (text) {
|
|
1198
|
-
element.appendChild(document.createTextNode(text));
|
|
1199
|
-
}
|
|
1200
|
-
return element;
|
|
1201
|
-
};
|
|
1202
|
-
var make = function(descriptor) {
|
|
1203
|
-
if (typeof descriptor !== "string") {
|
|
1204
|
-
return [];
|
|
1205
|
-
}
|
|
1206
|
-
if (Array.isArray(descriptor)) {
|
|
1207
|
-
descriptor = descriptor[0];
|
|
1208
|
-
}
|
|
1209
|
-
let innerValue = "";
|
|
1210
|
-
if (descriptor.includes("|")) {
|
|
1211
|
-
[descriptor, innerValue] = descriptor.split("|");
|
|
1212
|
-
if (!descriptor) {
|
|
1213
|
-
return ["P", void 0, void 0, innerValue];
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
let tag;
|
|
1217
|
-
if (!descriptor.includes("#")) {
|
|
1218
|
-
descriptor = descriptor.split(".");
|
|
1219
|
-
tag = descriptor.shift();
|
|
1220
|
-
if (!tag) {
|
|
1221
|
-
tag = "DIV";
|
|
1222
|
-
}
|
|
1223
|
-
return [tag, void 0, descriptor.join(" "), innerValue];
|
|
1224
|
-
} else {
|
|
1225
|
-
if (!descriptor.includes(".")) {
|
|
1226
|
-
descriptor = descriptor.split("#");
|
|
1227
|
-
tag = descriptor.shift();
|
|
1228
|
-
if (!tag) {
|
|
1229
|
-
tag = "DIV";
|
|
1230
|
-
}
|
|
1231
|
-
if (descriptor[0].includes(" ")) {
|
|
1232
|
-
descriptor = [descriptor[0].split(" ")[1]];
|
|
1233
|
-
}
|
|
1234
|
-
return [tag, descriptor[0], void 0, innerValue];
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
descriptor = descriptor.split(".");
|
|
1238
|
-
const classes = [];
|
|
1239
|
-
const IDs = [];
|
|
1240
|
-
tag = !descriptor[0].includes("#") && descriptor.shift();
|
|
1241
|
-
if (!tag) {
|
|
1242
|
-
tag = "DIV";
|
|
1243
|
-
}
|
|
1244
|
-
for (let i2 = 0; i2 < descriptor.length; i2++) {
|
|
1245
|
-
if (descriptor[i2].includes("#")) {
|
|
1246
|
-
const item = descriptor[i2].split("#");
|
|
1247
|
-
IDs.push(item[1]);
|
|
1248
|
-
if (i2 === 0) {
|
|
1249
|
-
tag = item[0];
|
|
1250
|
-
continue;
|
|
1251
|
-
}
|
|
1252
|
-
classes.push(item[0]);
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
classes.push(descriptor[i2]);
|
|
1256
|
-
}
|
|
1257
|
-
return [tag, IDs[0], classes.join(" "), innerValue];
|
|
1258
|
-
};
|
|
1259
|
-
var cra = (tag) => {
|
|
1260
|
-
const extend = (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
|
|
1261
|
-
return extend;
|
|
1262
|
-
};
|
|
1263
|
-
var a = cra("a");
|
|
1264
|
-
var area = cra("area");
|
|
1265
|
-
var article = cra("article");
|
|
1266
|
-
var aside = cra("aside");
|
|
1267
|
-
var audio = cra("audio");
|
|
1268
|
-
var b = cra("b");
|
|
1269
|
-
var base = cra("base");
|
|
1270
|
-
var blockquote = cra("blockquote");
|
|
1271
|
-
var br = cra("br");
|
|
1272
|
-
var button = cra("button");
|
|
1273
|
-
var canvas = cra("canvas");
|
|
1274
|
-
var caption = cra("caption");
|
|
1275
|
-
var code = cra("code");
|
|
1276
|
-
var col = cra("col");
|
|
1277
|
-
var colgroup = cra("colgroup");
|
|
1278
|
-
var data = cra("data");
|
|
1279
|
-
var datalist = cra("datalist");
|
|
1280
|
-
var details = cra("details");
|
|
1281
|
-
var dialog = cra("dialog");
|
|
1282
|
-
var div = cra("div");
|
|
1283
|
-
var em = cra("em");
|
|
1284
|
-
var embed = cra("embed");
|
|
1285
|
-
var figure = cra("figure");
|
|
1286
|
-
var footer = cra("footer");
|
|
1287
|
-
var form = cra("form");
|
|
1288
|
-
var h1 = cra("h1");
|
|
1289
|
-
var h2 = cra("h2");
|
|
1290
|
-
var h3 = cra("h3");
|
|
1291
|
-
var h4 = cra("h4");
|
|
1292
|
-
var h5 = cra("h5");
|
|
1293
|
-
var h6 = cra("h6");
|
|
1294
|
-
var head = cra("head");
|
|
1295
|
-
var header = cra("header");
|
|
1296
|
-
var hr = cra("hr");
|
|
1297
|
-
var i = cra("i");
|
|
1298
|
-
var iframe = cra("iframe");
|
|
1299
|
-
var img = cra("img");
|
|
1300
|
-
var input = cra("input");
|
|
1301
|
-
var label = cra("label");
|
|
1302
|
-
var legend = cra("legend");
|
|
1303
|
-
var li = cra("li");
|
|
1304
|
-
var link = cra("link");
|
|
1305
|
-
var main = cra("main");
|
|
1306
|
-
var menu = cra("menu");
|
|
1307
|
-
var nav = cra("nav");
|
|
1308
|
-
var object = cra("object");
|
|
1309
|
-
var ol = cra("ol");
|
|
1310
|
-
var optgroup = cra("optgroup");
|
|
1311
|
-
var option = cra("option");
|
|
1312
|
-
var p = cra("p");
|
|
1313
|
-
var pre = cra("pre");
|
|
1314
|
-
var progress = cra("progress");
|
|
1315
|
-
var q = cra("q");
|
|
1316
|
-
var section = cra("section");
|
|
1317
|
-
var select = cra("select");
|
|
1318
|
-
var source = cra("source");
|
|
1319
|
-
var span = cra("span");
|
|
1320
|
-
var strong = cra("strong");
|
|
1321
|
-
var summary = cra("summary");
|
|
1322
|
-
var table = cra("table");
|
|
1323
|
-
var tbody = cra("tbody");
|
|
1324
|
-
var td = cra("td");
|
|
1325
|
-
var template = cra("template");
|
|
1326
|
-
var textarea = cra("textarea");
|
|
1327
|
-
var th = cra("th");
|
|
1328
|
-
var title = cra("title");
|
|
1329
|
-
var tr = cra("tr");
|
|
1330
|
-
var track = cra("track");
|
|
1331
|
-
var u = cra("u");
|
|
1332
|
-
var ul = cra("ul");
|
|
1333
|
-
var video = cra("video");
|
|
1334
|
-
var svg = (svg2, properties) => {
|
|
1335
|
-
const span2 = document.createElement("span");
|
|
1336
|
-
span2.innerHTML = svg2;
|
|
1337
|
-
return makeElement(span2, [properties]);
|
|
1338
|
-
};
|
|
1339
|
-
|
|
1340
|
-
// lib/parts/ajax.ts
|
|
1341
|
-
function Ajax(url, opts = {}) {
|
|
1342
|
-
const { method, data: data2, header: header2, callbacks } = opts;
|
|
1343
|
-
if (typeof url !== "string") {
|
|
1344
|
-
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
1345
|
-
}
|
|
1346
|
-
return new Promise(function(resolve, reject) {
|
|
1347
|
-
const ajax = new XMLHttpRequest();
|
|
1348
|
-
const formData = new FormData();
|
|
1349
|
-
if (callbacks && typeof callbacks === "object") {
|
|
1350
|
-
for (const [k, v] of Object.entries(callbacks)) {
|
|
1351
|
-
ajax.addEventListener(k, v);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
ajax.addEventListener("load", function() {
|
|
1355
|
-
resolve(ajax.response);
|
|
1356
|
-
});
|
|
1357
|
-
if (data2 && typeof data2 === "object") {
|
|
1358
|
-
for (const [k, v] of Object.entries(data2)) {
|
|
1359
|
-
let value = v;
|
|
1360
|
-
if (typeof value === "object" && value && !value.name) {
|
|
1361
|
-
value = JSON.stringify(value);
|
|
1362
|
-
formData.set(k, value);
|
|
1363
|
-
}
|
|
1364
|
-
if (typeof value === "string") {
|
|
1365
|
-
formData.set(k, value);
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
ajax.addEventListener("error", () => {
|
|
1370
|
-
if (!navigator.onLine) {
|
|
1371
|
-
reject(
|
|
1372
|
-
JSON.stringify({
|
|
1373
|
-
message: `this device is offline!`
|
|
1374
|
-
})
|
|
1375
|
-
);
|
|
1376
|
-
} else {
|
|
1377
|
-
reject(
|
|
1378
|
-
JSON.stringify({
|
|
1379
|
-
message: `problem with the action, please try again!`
|
|
1380
|
-
})
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
if (!method) {
|
|
1385
|
-
ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
|
|
1386
|
-
} else {
|
|
1387
|
-
ajax.open(method, url, true);
|
|
1388
|
-
}
|
|
1389
|
-
if (header2 && typeof header2 === "object") {
|
|
1390
|
-
Object.keys(header2).forEach(function(key) {
|
|
1391
|
-
ajax.setRequestHeader(key, header2[key]);
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
ajax.send(formData);
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
// lib/index.ts
|
|
1399
|
-
var _2 = (...element_initials) => {
|
|
1400
|
-
const {
|
|
1401
|
-
0: tag,
|
|
1402
|
-
1: id,
|
|
1403
|
-
2: className,
|
|
1404
|
-
3: innerText
|
|
1405
|
-
} = make(element_initials[0]);
|
|
1406
|
-
const element = tag ? document.createElement(tag) : new DocumentFragment();
|
|
1407
|
-
if (tag) {
|
|
1408
|
-
if (className) {
|
|
1409
|
-
element.className = className;
|
|
1410
|
-
}
|
|
1411
|
-
if (id) {
|
|
1412
|
-
element.id = id;
|
|
1413
|
-
}
|
|
1414
|
-
if (innerText) {
|
|
1415
|
-
element.innerText = innerText;
|
|
1416
|
-
}
|
|
1417
|
-
element_initials.shift();
|
|
1418
|
-
}
|
|
1419
|
-
return makeElement(element, element_initials);
|
|
1420
|
-
};
|
|
1421
|
-
var lib_default = _2;
|
|
1422
|
-
//! get url hash here and scroll into view
|
|
1423
|
-
|
|
1424
|
-
export { Ajax, CradovaEvent, Ref, Rhoda, Router, Screen, a, area, article, aside, assert, assertOr, audio, b, base, blockquote, br, button, canvas, caption, code, col, colgroup, createSignal, css, data, datalist, lib_default as default, details, dialog, div, em, embed, figure, footer, form, frag, h1, h2, h3, h4, h5, h6, head, header, hr, i, iframe, img, input, isNode, label, lazy, legend, li, link, loop, main, make, makeElement, menu, nav, object, ol, optgroup, option, p, pre, progress, q, reference, section, select, source, span, strong, summary, svg, table, tbody, td, template, textarea, th, title, tr, track, u, ul, useEffect, useRef, useState, video };
|
|
20
|
+
export { R as $case, S as $if, C as $ifelse, D as $switch, f as CradovaEvent, v as Ref, E as Rhoda, g as Router, h as Screen, Q as a, W as article, X as audio, Z as br, z as button, ee as canvas, te as caption, ne as col, re as colgroup, y as createSignal, k as css, oe as datalist, ot as default, ae as details, ie as dialog, se as div, le as em, ce as embed, pe as figure, ue as footer, de as form, A as frag, fe as h1, me as h2, he as h3, ge as h4, ve as h5, ye as h6, _e as head, Te as header, Ee as hr, we as i, Le as iframe, He as img, xe as input, p as isNode, be as label, H as lazy, Me as li, P as loop, ke as main, x as make, _ as makeElement, w as memo_SNRU, Se as nav, Ce as ol, Re as optgroup, De as option, Pe as p, Ae as progress, Ne as q, tt as raw, u as reference, Fe as section, Ve as select, Be as source, Je as span, Ie as strong, je as summary, et as svg, Oe as table, Ye as tbody, $e as td, Ge as template, Ue as textarea, qe as th, Ke as title, Qe as tr, We as track, Xe as u, Ze as ul, F as useEffect, V as useRef, N as useState, ze as video };
|