cradova 1.0.1 → 1.0.2
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 +53 -19
- package/dist/index.d.ts +26 -0
- package/dist/index.js +468 -0
- package/dist/rolled-cradova.js +2366 -0
- package/dist/scripts/JsonDB.d.ts +287 -0
- package/dist/scripts/JsonDB.js +633 -0
- package/dist/scripts/Router.d.ts +5 -0
- package/dist/scripts/Router.js +170 -0
- package/dist/scripts/Screen.d.ts +51 -0
- package/dist/scripts/Screen.js +107 -0
- package/dist/scripts/ajax.d.ts +28 -0
- package/dist/scripts/ajax.js +63 -0
- package/dist/scripts/fns.d.ts +84 -0
- package/dist/scripts/fns.js +307 -0
- package/dist/scripts/init.d.ts +1 -0
- package/dist/scripts/init.js +25 -0
- package/dist/scripts/loadCss.d.ts +1 -0
- package/dist/scripts/loadCss.js +194 -0
- package/dist/scripts/memory.d.ts +12 -0
- package/dist/scripts/memory.js +46 -0
- package/dist/scripts/store.d.ts +12 -0
- package/dist/scripts/store.js +64 -0
- package/dist/scripts/swipe.d.ts +1 -0
- package/dist/scripts/swipe.js +114 -0
- package/dist/scripts/track.d.ts +12 -0
- package/dist/scripts/track.js +150 -0
- package/dist/scripts/widget.d.ts +8 -0
- package/dist/scripts/widget.js +21 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +1 -0
- package/index.ts +336 -147
- package/package.json +18 -11
- package/scripts/JsonDB.ts +134 -130
- package/scripts/Router.ts +94 -24
- package/scripts/Screen.ts +99 -39
- package/scripts/{littleAxios.ts → ajax.ts} +44 -6
- package/scripts/fns.ts +341 -0
- package/scripts/init.ts +11 -4
- package/scripts/loadCss.ts +194 -0
- package/scripts/memory.ts +44 -0
- package/scripts/store.ts +32 -21
- package/scripts/style.css +189 -0
- package/scripts/swipe.ts +4 -4
- package/scripts/track.ts +171 -0
- package/scripts/widget.ts +17 -15
- package/tsconfig.json +18 -98
- package/types.ts +15 -1
- package/{online-only-after-initial-cache.ts → workers/online-only-after-initial-cache.ts} +14 -11
- package/{service-worker.ts → workers/service-worker.ts} +17 -10
- package/docs/README.md +0 -0
- package/manifest.json +0 -38
- package/scripts/Metrics.ts +0 -66
- package/scripts/animate.ts +0 -55
- package/scripts/createState.ts +0 -27
- package/scripts/css.ts +0 -47
- package/scripts/dispatcher.ts +0 -158
- package/scripts/fetcher.ts +0 -31
- package/scripts/file-system.ts +0 -173
- package/scripts/fullscreen.ts +0 -21
- package/scripts/localStorage.ts +0 -19
- package/scripts/media.ts +0 -51
- package/scripts/promptbeforeleave.ts +0 -10
- package/scripts/reuse.ts +0 -79
- package/scripts/speaker.ts +0 -25
- package/scripts/uuid.ts +0 -10
- package/types.d.ts +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export function swipe(item) {
|
|
2
|
+
let caller;
|
|
3
|
+
let startX = 0, startY = 0;
|
|
4
|
+
if (typeof item === "object") {
|
|
5
|
+
caller = item;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
throw new Error("no call given for the swipe handler");
|
|
9
|
+
}
|
|
10
|
+
function handleTouchStart(e) {
|
|
11
|
+
startX = e.changedTouches[0].screenX;
|
|
12
|
+
startY = e.changedTouches[0].screenY;
|
|
13
|
+
}
|
|
14
|
+
function handleTouchEnd(e) {
|
|
15
|
+
const diffX = e.changedTouches[0].screenX - startX;
|
|
16
|
+
const diffY = e.changedTouches[0].screenY - startY;
|
|
17
|
+
const ratioX = Math.abs(diffX / diffY);
|
|
18
|
+
const ratioY = Math.abs(diffY / diffX);
|
|
19
|
+
const absDiff = Math.abs(ratioX > ratioY ? diffX : diffY);
|
|
20
|
+
if (absDiff < 10) {
|
|
21
|
+
if (caller.touch) {
|
|
22
|
+
callback.touch(caller.touch);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (ratioX > ratioY) {
|
|
26
|
+
// left and right
|
|
27
|
+
if (diffX >= 0) {
|
|
28
|
+
if (caller.right) {
|
|
29
|
+
callback.right(caller.right);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (caller.left) {
|
|
34
|
+
callback.left(caller.left);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// up and down
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (diffY >= 0) {
|
|
41
|
+
if (caller.down) {
|
|
42
|
+
callback.down(caller.down);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (caller.up) {
|
|
47
|
+
callback.up(caller.up);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const escapeTSError = document.body;
|
|
53
|
+
escapeTSError.addEventListener("touchstart", handleTouchStart);
|
|
54
|
+
escapeTSError.addEventListener("touchend", handleTouchEnd);
|
|
55
|
+
const callback = {
|
|
56
|
+
touch(callback) {
|
|
57
|
+
return callback();
|
|
58
|
+
},
|
|
59
|
+
right(callback) {
|
|
60
|
+
return callback();
|
|
61
|
+
},
|
|
62
|
+
left(callback) {
|
|
63
|
+
return callback();
|
|
64
|
+
},
|
|
65
|
+
down(callback) {
|
|
66
|
+
return callback();
|
|
67
|
+
},
|
|
68
|
+
up(callback) {
|
|
69
|
+
return callback();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
*** HOW TO USE ***
|
|
75
|
+
|
|
76
|
+
function touch(){
|
|
77
|
+
console.log("touching")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function up(){
|
|
83
|
+
console.log("swipe up")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function down(){
|
|
88
|
+
console.log("swipe down")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function right(){
|
|
93
|
+
console.log("swipe right")
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function left(){
|
|
98
|
+
console.log("swipe left")
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
let obj = {down: down,
|
|
104
|
+
touch: touch,
|
|
105
|
+
up: up,
|
|
106
|
+
right: right,
|
|
107
|
+
left: left
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
swipe(obj)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send a new state to specified element with stateID
|
|
3
|
+
*
|
|
4
|
+
* @param stateID
|
|
5
|
+
* @param state
|
|
6
|
+
* @returns element(s)
|
|
7
|
+
*/
|
|
8
|
+
export declare function dispatch(stateID: string | Record<string, any>, state?: Record<string, any>): HTMLElement[];
|
|
9
|
+
export declare function fullScreen(e: Element): {
|
|
10
|
+
set(): void;
|
|
11
|
+
exist(): void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// the global dispatcher
|
|
2
|
+
function cradovaDispatchtrack(nodes /*NodeListOf<Element>*/, stateID, state) {
|
|
3
|
+
const updated = [];
|
|
4
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
5
|
+
const element = nodes[i];
|
|
6
|
+
// abort re-rendering if the state is not for this element
|
|
7
|
+
if (!element.stateID || element.stateID !== stateID) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
updated.push(element);
|
|
11
|
+
if (typeof state === "object") {
|
|
12
|
+
// updating the element's state
|
|
13
|
+
for (const key in state) {
|
|
14
|
+
// updating element styling
|
|
15
|
+
if (key === "style") {
|
|
16
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
17
|
+
element.style[k] = v;
|
|
18
|
+
}
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (element.style[key] && key !== "src") {
|
|
22
|
+
element.style[key] = state[key];
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (element.style[key] === "" && key !== "src") {
|
|
26
|
+
element.style[key] = state[key];
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (typeof element[key] === "function") {
|
|
30
|
+
element[key]();
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// updating element's inner text
|
|
34
|
+
if (key === "text") {
|
|
35
|
+
element.innerText = state[key];
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
// setting element dimesion to full screen
|
|
39
|
+
if (key === "fullscreen") {
|
|
40
|
+
if (state[key]) {
|
|
41
|
+
fullScreen(element).set();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
fullScreen(element).exist();
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// adding class name to element
|
|
49
|
+
if (key === "class" && typeof state[key] === "string") {
|
|
50
|
+
const classes = state[key].split(" ");
|
|
51
|
+
for (let i = 0; i < classes.length; i++) {
|
|
52
|
+
if (classes[i]) {
|
|
53
|
+
element.classList.add(classes[i]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// console.log(element.className, "cl");
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// toggling element class
|
|
60
|
+
if (key === "toggleclass") {
|
|
61
|
+
element.classList.toggle(state[key]);
|
|
62
|
+
// console.log(element.className, "tc");
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
//removing element class
|
|
66
|
+
if (key === "removeclass") {
|
|
67
|
+
element.classList.remove(state[key]);
|
|
68
|
+
// console.log(element.className, "rm");
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
//removing element class
|
|
72
|
+
if (key === "remove") {
|
|
73
|
+
element.parentElement?.remove(element);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// changing the element children tree
|
|
77
|
+
if (key === "tree") {
|
|
78
|
+
if (typeof state[key] === "function") {
|
|
79
|
+
state[key] = state[key]();
|
|
80
|
+
}
|
|
81
|
+
if (typeof state[key] === "function") {
|
|
82
|
+
state[key] = state[key]();
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(state[key])) {
|
|
85
|
+
throw new TypeError("cradova err invalid element, should be a single element or parent element from cradova");
|
|
86
|
+
}
|
|
87
|
+
if (!(state[key] instanceof HTMLElement)) {
|
|
88
|
+
console.error("cradova err wrong element type: can't create element state on " +
|
|
89
|
+
state[key]);
|
|
90
|
+
throw new TypeError("cradova err invalid element, should be a html element from cradova");
|
|
91
|
+
}
|
|
92
|
+
// destroy the component tree
|
|
93
|
+
element.innerHTML = "";
|
|
94
|
+
// rebuild the component tree
|
|
95
|
+
// console.log(state[key]);
|
|
96
|
+
element.append(state[key]);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
element[key] = state[key];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return updated;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Send a new state to specified element with stateID
|
|
107
|
+
*
|
|
108
|
+
* @param stateID
|
|
109
|
+
* @param state
|
|
110
|
+
* @returns element(s)
|
|
111
|
+
*/
|
|
112
|
+
export function dispatch(stateID, state) {
|
|
113
|
+
// TODO: this will be updated to use data-stateid soon
|
|
114
|
+
// speed test still going on
|
|
115
|
+
const nodes = document.querySelectorAll(".cra_child_doc");
|
|
116
|
+
let updated = [];
|
|
117
|
+
if (typeof state === "undefined" && typeof stateID === "object") {
|
|
118
|
+
for (const [id, eachState] of Object.entries(stateID)) {
|
|
119
|
+
const node = cradovaDispatchtrack(nodes, id, eachState);
|
|
120
|
+
updated.push(...node);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (typeof stateID === "string") {
|
|
125
|
+
const node = cradovaDispatchtrack(nodes, stateID, state);
|
|
126
|
+
updated.push(...node);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return updated;
|
|
130
|
+
}
|
|
131
|
+
// for making the dom elements fulscreen
|
|
132
|
+
export function fullScreen(e) {
|
|
133
|
+
return {
|
|
134
|
+
set() {
|
|
135
|
+
e.requestFullscreen().catch((err) => {
|
|
136
|
+
throw err;
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
exist() {
|
|
140
|
+
document.exitFullscreen();
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/*
|
|
145
|
+
*** HOW TO USE ***
|
|
146
|
+
|
|
147
|
+
u("#container").fullscreen().toggle()
|
|
148
|
+
u("#container").fullscreen().exist()
|
|
149
|
+
u("#container").fullscreen().set()
|
|
150
|
+
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document fragment
|
|
3
|
+
* @param childrens
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export const fragment = function (...childrens) {
|
|
7
|
+
const par = document.createDocumentFragment();
|
|
8
|
+
// building it's children tree.
|
|
9
|
+
for (let i = 0; i < childrens.length; i++) {
|
|
10
|
+
const ch = childrens[i];
|
|
11
|
+
if (typeof ch === "function") {
|
|
12
|
+
par.append(ch());
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (ch instanceof HTMLElement) {
|
|
16
|
+
par.append(ch);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return () => par;
|
|
21
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type CradovaElemetType = HTMLElement & Record<string, any> & {
|
|
2
|
+
style: Record<string, unknown>;
|
|
3
|
+
stateID: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type CradovaHTMLElemetType = (...element_initials: any[]) => ((...element_initials: any[]) => "empty cradova call") | ((...element_initials: any[]) => HTMLElement | undefined);
|
|
6
|
+
export declare type CradovaScreenType = {
|
|
7
|
+
name: string;
|
|
8
|
+
template: Function | HTMLElement;
|
|
9
|
+
transition?: string;
|
|
10
|
+
callBack?: (html?: any, data?: Record<string, any>) => void;
|
|
11
|
+
persist?: boolean;
|
|
12
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|