cradova 1.0.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.
Files changed (60) hide show
  1. package/LICENSE +201 -0
  2. package/cradova.png +0 -0
  3. package/docs/README.md +0 -0
  4. package/index.d.ts +52 -0
  5. package/index.js +342 -0
  6. package/index.ts +366 -0
  7. package/package.json +36 -0
  8. package/scripts/JsonDB.d.ts +298 -0
  9. package/scripts/JsonDB.js +698 -0
  10. package/scripts/JsonDB.ts +794 -0
  11. package/scripts/Metrics.d.ts +51 -0
  12. package/scripts/Metrics.js +56 -0
  13. package/scripts/Metrics.ts +66 -0
  14. package/scripts/Router.d.ts +12 -0
  15. package/scripts/Router.js +95 -0
  16. package/scripts/Router.ts +105 -0
  17. package/scripts/Screen.d.ts +11 -0
  18. package/scripts/Screen.js +62 -0
  19. package/scripts/Screen.ts +62 -0
  20. package/scripts/animate.d.ts +25 -0
  21. package/scripts/animate.js +47 -0
  22. package/scripts/animate.ts +57 -0
  23. package/scripts/css.d.ts +20 -0
  24. package/scripts/css.js +41 -0
  25. package/scripts/css.ts +46 -0
  26. package/scripts/dispatcher.d.ts +1 -0
  27. package/scripts/dispatcher.js +57 -0
  28. package/scripts/dispatcher.ts +58 -0
  29. package/scripts/file-system.d.ts +2 -0
  30. package/scripts/file-system.js +175 -0
  31. package/scripts/file-system.ts +177 -0
  32. package/scripts/fullscreen.d.ts +4 -0
  33. package/scripts/fullscreen.js +29 -0
  34. package/scripts/fullscreen.ts +30 -0
  35. package/scripts/init.d.ts +2 -0
  36. package/scripts/init.js +17 -0
  37. package/scripts/init.ts +18 -0
  38. package/scripts/localStorage.d.ts +9 -0
  39. package/scripts/localStorage.js +26 -0
  40. package/scripts/localStorage.ts +37 -0
  41. package/scripts/media.d.ts +22 -0
  42. package/scripts/media.js +48 -0
  43. package/scripts/media.ts +51 -0
  44. package/scripts/reuse.ts +74 -0
  45. package/scripts/speaker.d.ts +2 -0
  46. package/scripts/speaker.js +16 -0
  47. package/scripts/speaker.ts +25 -0
  48. package/scripts/store.d.ts +10 -0
  49. package/scripts/store.js +56 -0
  50. package/scripts/store.ts +47 -0
  51. package/scripts/swipe.d.ts +9 -0
  52. package/scripts/swipe.js +113 -0
  53. package/scripts/swipe.ts +129 -0
  54. package/scripts/widget.d.ts +2 -0
  55. package/scripts/widget.js +19 -0
  56. package/scripts/widget.ts +23 -0
  57. package/service-worker.d.ts +2 -0
  58. package/service-worker.js +40 -0
  59. package/service-worker.ts +52 -0
  60. package/tsconfig.json +11 -0
@@ -0,0 +1,26 @@
1
+ let ls = {
2
+ store: () => console.log(),
3
+ retrieve: () => console.log(),
4
+ remove: () => console.log(),
5
+ getKey: () => console.log(),
6
+ clear: () => console.log(),
7
+ };
8
+ ls.store = (name, value) => {
9
+ if (typeof value !== "string") {
10
+ value = JSON.stringify(value);
11
+ }
12
+ localStorage.setItem(name, value);
13
+ };
14
+ ls.retrieve = (name) => {
15
+ localStorage.getItem(name);
16
+ };
17
+ ls.remove = (name) => {
18
+ localStorage.removeItem(name);
19
+ };
20
+ ls.getKey = (index) => {
21
+ window.localStorage.key(index);
22
+ };
23
+ ls.clear = () => {
24
+ localStorage.clear();
25
+ };
26
+ export default ls;
@@ -0,0 +1,37 @@
1
+ type l = {
2
+ store: (name: string, value: unknown) => void;
3
+ retrieve: (name: string) => void;
4
+ remove: (name: string) => void;
5
+ getKey: (index: number) => void;
6
+ clear: () => void;
7
+ };
8
+
9
+ let ls: l = {
10
+ store: () => console.log(),
11
+ retrieve: () => console.log(),
12
+ remove: () => console.log(),
13
+ getKey: () => console.log(),
14
+ clear: () => console.log(),
15
+ };
16
+
17
+ ls.store = (name: string, value: any) => {
18
+ if (typeof value !== "string") {
19
+ value = JSON.stringify(value);
20
+ }
21
+ localStorage.setItem(name, value);
22
+ };
23
+ ls.retrieve = (name: string) => {
24
+ localStorage.getItem(name);
25
+ };
26
+
27
+ ls.remove = (name: string) => {
28
+ localStorage.removeItem(name);
29
+ };
30
+ ls.getKey = (index: number) => {
31
+ window.localStorage.key(index);
32
+ };
33
+ ls.clear = () => {
34
+ localStorage.clear();
35
+ };
36
+
37
+ export default ls;
@@ -0,0 +1,22 @@
1
+ /**
2
+ Write CSS media in javascript
3
+
4
+ @example
5
+
6
+ _.media("min-width: 790px",
7
+ ["#container",
8
+ {
9
+ width: "100%",
10
+ height: "100%",
11
+ "background-color": "#0000"
12
+ }],
13
+
14
+ ["#header",
15
+ {
16
+ width: "100%",
17
+ height: "20%",
18
+ "background-color": "#fff"
19
+ }]
20
+ )
21
+ */
22
+ export default function media(value: string, ...properties: any[]): void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ Write CSS media in javascript
3
+
4
+ @example
5
+
6
+ _.media("min-width: 790px",
7
+ ["#container",
8
+ {
9
+ width: "100%",
10
+ height: "100%",
11
+ "background-color": "#0000"
12
+ }],
13
+
14
+ ["#header",
15
+ {
16
+ width: "100%",
17
+ height: "20%",
18
+ "background-color": "#fff"
19
+ }]
20
+ )
21
+ */
22
+ export default function media(value, ...properties) {
23
+ /* This is for creating css
24
+ @media styles using javascipt*/
25
+ const styS = "@media only screen and (" + value + ") " + "{", styE = "}";
26
+ let style = " ", aniSty = " ";
27
+ const proplen = properties.length;
28
+ let totalAnimation, Animation = " ";
29
+ const animationStep = (num) => {
30
+ for (const [k, v] of Object.entries(properties[num][1])) {
31
+ style += "" + k + ": " + v + ";";
32
+ }
33
+ aniSty += "" + properties[num][0] + "{" + style + "}";
34
+ return aniSty;
35
+ };
36
+ for (let i = 0; i < proplen; i++) {
37
+ Animation += animationStep(i);
38
+ }
39
+ let aniStyleTag = document.querySelector("style");
40
+ if (aniStyleTag === null) {
41
+ aniStyleTag = document.createElement("style");
42
+ }
43
+ aniStyleTag.media = "screen";
44
+ totalAnimation = aniStyleTag.innerHTML;
45
+ totalAnimation += styS + Animation + styE;
46
+ aniStyleTag.innerHTML = totalAnimation;
47
+ document.head.append(aniStyleTag);
48
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ Write CSS media in javascript
3
+
4
+ @example
5
+
6
+ _.media("min-width: 790px",
7
+ ["#container",
8
+ {
9
+ width: "100%",
10
+ height: "100%",
11
+ "background-color": "#0000"
12
+ }],
13
+
14
+ ["#header",
15
+ {
16
+ width: "100%",
17
+ height: "20%",
18
+ "background-color": "#fff"
19
+ }]
20
+ )
21
+ */
22
+ export default function media(value: string, ...properties: any[]) {
23
+ /* This is for creating css
24
+ @media styles using javascipt*/
25
+ const styS = "@media only screen and (" + value + ") " + "{",
26
+ styE = "}";
27
+ let style = " ",
28
+ aniSty = " ";
29
+ const proplen = properties.length;
30
+ let totalAnimation,
31
+ Animation = " ";
32
+ const animationStep = (num: number) => {
33
+ for (const [k, v] of Object.entries(properties[num][1])) {
34
+ style += "" + k + ": " + v + ";";
35
+ }
36
+ aniSty += "" + properties[num][0] + "{" + style + "}";
37
+ return aniSty;
38
+ };
39
+ for (let i = 0; i < proplen; i++) {
40
+ Animation += animationStep(i);
41
+ }
42
+ let aniStyleTag = document.querySelector("style");
43
+ if (aniStyleTag === null) {
44
+ aniStyleTag = document.createElement("style");
45
+ }
46
+ aniStyleTag.media = "screen";
47
+ totalAnimation = aniStyleTag.innerHTML;
48
+ totalAnimation += styS + Animation + styE;
49
+ aniStyleTag.innerHTML = totalAnimation;
50
+ document.head.append(aniStyleTag);
51
+ }
@@ -0,0 +1,74 @@
1
+ export default function reuse(element) {
2
+
3
+ return (...incoming) => {
4
+ let childrens2rd, props, text;
5
+
6
+ for (let i = 0; i < incoming.length; i++) {
7
+ if (
8
+ typeof incoming[i] === "function" ||
9
+ incoming[i] instanceof HTMLElement
10
+ ) {
11
+ if (Array.isArray(childrens2rd)) {
12
+ childrens2rd.push(incoming[i]);
13
+ } else {
14
+ childrens2rd = [incoming[i]];
15
+ }
16
+ continue;
17
+ }
18
+ //
19
+ if (
20
+ !(incoming[i] instanceof HTMLElement) &&
21
+ typeof incoming[i] === "object"
22
+ ) {
23
+ props = incoming[i];
24
+ continue;
25
+ }
26
+ if (typeof incoming[i] === "string") {
27
+ text = incoming[i];
28
+ continue;
29
+ }
30
+ }
31
+
32
+ //
33
+ // dynamic props
34
+ //
35
+
36
+ if (props && typeof props === "object" && !Array.isArray(props)) {
37
+ for (const prop in props) {
38
+ if (prop === "style") {
39
+ for (const [k, v] of Object.entries(props[prop])) {
40
+ element.style[k] = v;
41
+ }
42
+ continue;
43
+ }
44
+ if (prop === "text") {
45
+ element.innerText = props[prop];
46
+ continue;
47
+ }
48
+ if (prop === "class") {
49
+ element.classList.add(props[prop]);
50
+ continue;
51
+ }
52
+ element[prop] = props[prop];
53
+ }
54
+ }
55
+ if (childrens2rd && childrens2rd[0]) {
56
+ for (let i = 0; i < childrens2rd.length; i++) {
57
+ if (typeof childrens2rd[i] === "function") {
58
+ element.append(childrens2rd[i](props));
59
+ continue;
60
+ }
61
+ element.append(childrens2rd[i]);
62
+ }
63
+ }
64
+ if (text) {
65
+ element.append(text);
66
+ }
67
+ if (element.stateID) {
68
+ // adding cradova dynamic signature
69
+ element.classList.add("cra_child_doc");
70
+ }
71
+ return element;
72
+
73
+ }
74
+ }
@@ -0,0 +1,2 @@
1
+ declare const Speaker: {};
2
+ export default Speaker;
@@ -0,0 +1,16 @@
1
+ const Speaker = {};
2
+ Speaker.speak = function (text, language = "en", volume = 1, rate = 1, pitch = 1) {
3
+ // common languages (not supported by all browsers)
4
+ // en - english, it - italian, fr - french, de - german, es - spanish
5
+ // ja - japanese, ru - russian, zh - chinese, hi - hindi, ko - korean
6
+ const utterance = new SpeechSynthesisUtterance(text);
7
+ utterance.lang = language;
8
+ utterance.volume = volume;
9
+ utterance.rate = rate;
10
+ utterance.pitch = pitch;
11
+ speechSynthesis.speak(utterance);
12
+ };
13
+ Speaker.stop = () => {
14
+ return speechSynthesis && speechSynthesis.cancel();
15
+ };
16
+ export default Speaker;
@@ -0,0 +1,25 @@
1
+ const Speaker = {};
2
+
3
+ Speaker.speak = function (
4
+ text,
5
+ language = "en",
6
+ volume = 1,
7
+ rate = 1,
8
+ pitch = 1
9
+ ) {
10
+ // common languages (not supported by all browsers)
11
+ // en - english, it - italian, fr - french, de - german, es - spanish
12
+ // ja - japanese, ru - russian, zh - chinese, hi - hindi, ko - korean
13
+ const utterance = new SpeechSynthesisUtterance(text);
14
+ utterance.lang = language;
15
+ utterance.volume = volume;
16
+ utterance.rate = rate;
17
+ utterance.pitch = pitch;
18
+ speechSynthesis.speak(utterance);
19
+ };
20
+
21
+ Speaker.stop = () => {
22
+ return speechSynthesis && speechSynthesis.cancel();
23
+ };
24
+
25
+ export default Speaker;
@@ -0,0 +1,10 @@
1
+ declare class store {
2
+ #private;
3
+ constructor(initial: unknown);
4
+ status(): unknown;
5
+ set(value: unknown): void;
6
+ forward(): void;
7
+ backward(): void;
8
+ }
9
+ declare const Store: (initial: unknown) => store;
10
+ export default Store;
@@ -0,0 +1,56 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _store_index, _store_history, _store_value;
13
+ class store {
14
+ constructor(initial) {
15
+ _store_index.set(this, 0);
16
+ _store_history.set(this, []);
17
+ _store_value.set(this, null);
18
+ __classPrivateFieldSet(this, _store_value, initial, "f");
19
+ __classPrivateFieldGet(this, _store_history, "f").push(initial);
20
+ }
21
+ status() {
22
+ return __classPrivateFieldGet(this, _store_value, "f");
23
+ }
24
+ set(value) {
25
+ __classPrivateFieldSet(this, _store_value, value, "f");
26
+ __classPrivateFieldGet(this, _store_history, "f").push(value);
27
+ __classPrivateFieldSet(this, _store_index, __classPrivateFieldGet(this, _store_index, "f") + 1, "f");
28
+ }
29
+ forward() {
30
+ if (__classPrivateFieldGet(this, _store_history, "f").length > __classPrivateFieldGet(this, _store_index, "f") + 1) {
31
+ __classPrivateFieldSet(this, _store_value, __classPrivateFieldGet(this, _store_history, "f")[__classPrivateFieldGet(this, _store_index, "f") + 1], "f");
32
+ }
33
+ }
34
+ backward() {
35
+ if (__classPrivateFieldGet(this, _store_history, "f").length > 0 && __classPrivateFieldGet(this, _store_index, "f") > 0) {
36
+ __classPrivateFieldSet(this, _store_value, __classPrivateFieldGet(this, _store_history, "f")[__classPrivateFieldGet(this, _store_index, "f") - 1], "f");
37
+ __classPrivateFieldSet(this, _store_index, __classPrivateFieldGet(this, _store_index, "f") - 1, "f");
38
+ }
39
+ }
40
+ }
41
+ _store_index = new WeakMap(), _store_history = new WeakMap(), _store_value = new WeakMap();
42
+ const Store = function (initial) {
43
+ return new store(initial);
44
+ };
45
+ // const value = Store("hello world people");
46
+ // console.log(value.status());
47
+ //
48
+ // value.set("hi yall people");
49
+ // console.log(value.status());
50
+ //
51
+ // value.backward();
52
+ // console.log(value.status());
53
+ //
54
+ // value.forward();
55
+ // console.log(value.status());
56
+ export default Store;
@@ -0,0 +1,47 @@
1
+ class store {
2
+ #index = 0;
3
+ #history: unknown[] = [];
4
+ #value: unknown = null;
5
+ constructor(initial: unknown) {
6
+ this.#value = initial;
7
+ this.#history.push(initial);
8
+ }
9
+ status() {
10
+ return this.#value;
11
+ }
12
+
13
+ set(value: unknown) {
14
+ this.#value = value;
15
+ this.#history.push(value);
16
+ this.#index += 1;
17
+ }
18
+ forward() {
19
+ if (this.#history.length > this.#index + 1) {
20
+ this.#value = this.#history[this.#index + 1];
21
+ }
22
+ }
23
+ backward() {
24
+ if (this.#history.length > 0 && this.#index > 0) {
25
+ this.#value = this.#history[this.#index - 1];
26
+ this.#index -= 1;
27
+ }
28
+ }
29
+ }
30
+
31
+ const Store = function (initial: unknown) {
32
+ return new store(initial);
33
+ };
34
+
35
+ // const value = Store("hello world people");
36
+ // console.log(value.status());
37
+ //
38
+ // value.set("hi yall people");
39
+ // console.log(value.status());
40
+ //
41
+ // value.backward();
42
+ // console.log(value.status());
43
+ //
44
+ // value.forward();
45
+ // console.log(value.status());
46
+
47
+ export default Store;
@@ -0,0 +1,9 @@
1
+ declare type calls = {
2
+ up: () => void;
3
+ down: () => void;
4
+ right: () => void;
5
+ left: () => void;
6
+ touch: () => void;
7
+ };
8
+ export default function swipe(item: calls): void;
9
+ export {};
@@ -0,0 +1,113 @@
1
+ export default 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
+ document.body.addEventListener("touchstart", handleTouchStart);
53
+ document.body.addEventListener("touchend", handleTouchEnd);
54
+ const callback = {
55
+ touch(callback) {
56
+ return callback();
57
+ },
58
+ right(callback) {
59
+ return callback();
60
+ },
61
+ left(callback) {
62
+ return callback();
63
+ },
64
+ down(callback) {
65
+ return callback();
66
+ },
67
+ up(callback) {
68
+ return callback();
69
+ },
70
+ };
71
+ }
72
+ /*
73
+ *** HOW TO USE ***
74
+
75
+ function touch(){
76
+ console.log("touching")
77
+ }
78
+
79
+
80
+
81
+ function up(){
82
+ console.log("swipe up")
83
+ }
84
+
85
+
86
+ function down(){
87
+ console.log("swipe down")
88
+ }
89
+
90
+
91
+ function right(){
92
+ console.log("swipe right")
93
+ }
94
+
95
+
96
+ function left(){
97
+ console.log("swipe left")
98
+ }
99
+
100
+
101
+
102
+ let obj = {down: down,
103
+ touch: touch,
104
+ up: up,
105
+ right: right,
106
+ left: left
107
+ }
108
+
109
+ swipe(obj)
110
+
111
+
112
+
113
+ */
@@ -0,0 +1,129 @@
1
+ type calls = {
2
+ up: () => void;
3
+ down: () => void;
4
+ right: () => void;
5
+ left: () => void;
6
+ touch: () => void;
7
+ };
8
+
9
+ export default function swipe(item: calls) {
10
+ let caller: calls;
11
+ let startX = 0,
12
+ startY = 0;
13
+ if (typeof item === "object") {
14
+ caller = item;
15
+ } else {
16
+ throw new Error("no call given for the swipe handler");
17
+ }
18
+
19
+ function handleTouchStart(e: TouchEvent) {
20
+ startX = e.changedTouches[0].screenX;
21
+ startY = e.changedTouches[0].screenY;
22
+ }
23
+
24
+ function handleTouchEnd(e: TouchEvent) {
25
+ const diffX = e.changedTouches[0].screenX - startX;
26
+ const diffY = e.changedTouches[0].screenY - startY;
27
+ const ratioX = Math.abs(diffX / diffY);
28
+ const ratioY = Math.abs(diffY / diffX);
29
+ const absDiff = Math.abs(ratioX > ratioY ? diffX : diffY);
30
+
31
+ if (absDiff < 10) {
32
+ if (caller.touch) {
33
+ callback.touch(caller.touch);
34
+ }
35
+ }
36
+
37
+ if (ratioX > ratioY) {
38
+ // left and right
39
+ if (diffX >= 0) {
40
+ if (caller.right) {
41
+ callback.right(caller.right);
42
+ }
43
+ } else {
44
+ if (caller.left) {
45
+ callback.left(caller.left);
46
+ }
47
+ }
48
+
49
+ // up and down
50
+ } else {
51
+ if (diffY >= 0) {
52
+ if (caller.down) {
53
+ callback.down(caller.down);
54
+ }
55
+ } else {
56
+ if (caller.up) {
57
+ callback.up(caller.up);
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ document.body.addEventListener("touchstart", handleTouchStart);
64
+ document.body.addEventListener("touchend", handleTouchEnd);
65
+
66
+ const callback = {
67
+ touch(callback: () => void) {
68
+ return callback();
69
+ },
70
+ right(callback: () => void) {
71
+ return callback();
72
+ },
73
+
74
+ left(callback: () => void) {
75
+ return callback();
76
+ },
77
+
78
+ down(callback: () => void) {
79
+ return callback();
80
+ },
81
+
82
+ up(callback: () => void) {
83
+ return callback();
84
+ },
85
+ };
86
+ }
87
+
88
+ /*
89
+ *** HOW TO USE ***
90
+
91
+ function touch(){
92
+ console.log("touching")
93
+ }
94
+
95
+
96
+
97
+ function up(){
98
+ console.log("swipe up")
99
+ }
100
+
101
+
102
+ function down(){
103
+ console.log("swipe down")
104
+ }
105
+
106
+
107
+ function right(){
108
+ console.log("swipe right")
109
+ }
110
+
111
+
112
+ function left(){
113
+ console.log("swipe left")
114
+ }
115
+
116
+
117
+
118
+ let obj = {down: down,
119
+ touch: touch,
120
+ up: up,
121
+ right: right,
122
+ left: left
123
+ }
124
+
125
+ swipe(obj)
126
+
127
+
128
+
129
+ */
@@ -0,0 +1,2 @@
1
+ declare const w: (...childrens: HTMLElement[] | ((el: Record<string, string>) => HTMLElement)[]) => () => DocumentFragment;
2
+ export default w;