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.
- package/LICENSE +201 -0
- package/cradova.png +0 -0
- package/docs/README.md +0 -0
- package/index.d.ts +52 -0
- package/index.js +342 -0
- package/index.ts +366 -0
- package/package.json +36 -0
- package/scripts/JsonDB.d.ts +298 -0
- package/scripts/JsonDB.js +698 -0
- package/scripts/JsonDB.ts +794 -0
- package/scripts/Metrics.d.ts +51 -0
- package/scripts/Metrics.js +56 -0
- package/scripts/Metrics.ts +66 -0
- package/scripts/Router.d.ts +12 -0
- package/scripts/Router.js +95 -0
- package/scripts/Router.ts +105 -0
- package/scripts/Screen.d.ts +11 -0
- package/scripts/Screen.js +62 -0
- package/scripts/Screen.ts +62 -0
- package/scripts/animate.d.ts +25 -0
- package/scripts/animate.js +47 -0
- package/scripts/animate.ts +57 -0
- package/scripts/css.d.ts +20 -0
- package/scripts/css.js +41 -0
- package/scripts/css.ts +46 -0
- package/scripts/dispatcher.d.ts +1 -0
- package/scripts/dispatcher.js +57 -0
- package/scripts/dispatcher.ts +58 -0
- package/scripts/file-system.d.ts +2 -0
- package/scripts/file-system.js +175 -0
- package/scripts/file-system.ts +177 -0
- package/scripts/fullscreen.d.ts +4 -0
- package/scripts/fullscreen.js +29 -0
- package/scripts/fullscreen.ts +30 -0
- package/scripts/init.d.ts +2 -0
- package/scripts/init.js +17 -0
- package/scripts/init.ts +18 -0
- package/scripts/localStorage.d.ts +9 -0
- package/scripts/localStorage.js +26 -0
- package/scripts/localStorage.ts +37 -0
- package/scripts/media.d.ts +22 -0
- package/scripts/media.js +48 -0
- package/scripts/media.ts +51 -0
- package/scripts/reuse.ts +74 -0
- package/scripts/speaker.d.ts +2 -0
- package/scripts/speaker.js +16 -0
- package/scripts/speaker.ts +25 -0
- package/scripts/store.d.ts +10 -0
- package/scripts/store.js +56 -0
- package/scripts/store.ts +47 -0
- package/scripts/swipe.d.ts +9 -0
- package/scripts/swipe.js +113 -0
- package/scripts/swipe.ts +129 -0
- package/scripts/widget.d.ts +2 -0
- package/scripts/widget.js +19 -0
- package/scripts/widget.ts +23 -0
- package/service-worker.d.ts +2 -0
- package/service-worker.js +40 -0
- package/service-worker.ts +52 -0
- package/tsconfig.json +11 -0
package/scripts/css.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Write CSS styles in Javascript
|
|
3
|
+
@example
|
|
4
|
+
|
|
5
|
+
css("#container",
|
|
6
|
+
{
|
|
7
|
+
height: "100%",
|
|
8
|
+
height: "100%",
|
|
9
|
+
background-color: "#ff9800"
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
css(".btn:hover",
|
|
13
|
+
{
|
|
14
|
+
height: "100%",
|
|
15
|
+
height: "100%",
|
|
16
|
+
background-color: "#ff9800"
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
export default function css(indentifier, properties) {
|
|
21
|
+
/*This is for creating
|
|
22
|
+
css styles using javascipt*/
|
|
23
|
+
const styS = "" + indentifier + "{";
|
|
24
|
+
const styE = "}";
|
|
25
|
+
let style = "", totalStyle = "";
|
|
26
|
+
for (const [k, v] of Object.entries(properties)) {
|
|
27
|
+
style += "" + k + ": " + v + ";";
|
|
28
|
+
}
|
|
29
|
+
let styleTag = document.querySelector("style");
|
|
30
|
+
if (styleTag !== null) {
|
|
31
|
+
totalStyle += styleTag.innerHTML;
|
|
32
|
+
totalStyle += styS + style + styE;
|
|
33
|
+
styleTag.innerHTML = totalStyle;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
styleTag = document.createElement("style");
|
|
37
|
+
totalStyle += styleTag.innerHTML;
|
|
38
|
+
totalStyle += styS + style + styE;
|
|
39
|
+
styleTag.innerHTML = totalStyle;
|
|
40
|
+
document.head.append(styleTag);
|
|
41
|
+
}
|
package/scripts/css.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Write CSS styles in Javascript
|
|
3
|
+
@example
|
|
4
|
+
|
|
5
|
+
css("#container",
|
|
6
|
+
{
|
|
7
|
+
height: "100%",
|
|
8
|
+
height: "100%",
|
|
9
|
+
background-color: "#ff9800"
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
css(".btn:hover",
|
|
13
|
+
{
|
|
14
|
+
height: "100%",
|
|
15
|
+
height: "100%",
|
|
16
|
+
background-color: "#ff9800"
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export default function css(
|
|
22
|
+
indentifier: string,
|
|
23
|
+
properties: Record<string, string>
|
|
24
|
+
) {
|
|
25
|
+
/*This is for creating
|
|
26
|
+
css styles using javascipt*/
|
|
27
|
+
const styS = "" + indentifier + "{";
|
|
28
|
+
const styE = "}";
|
|
29
|
+
let style = "",
|
|
30
|
+
totalStyle = "";
|
|
31
|
+
for (const [k, v] of Object.entries(properties)) {
|
|
32
|
+
style += "" + k + ": " + v + ";";
|
|
33
|
+
}
|
|
34
|
+
let styleTag = document.querySelector("style");
|
|
35
|
+
if (styleTag !== null) {
|
|
36
|
+
totalStyle += styleTag.innerHTML;
|
|
37
|
+
totalStyle += styS + style + styE;
|
|
38
|
+
styleTag.innerHTML = totalStyle;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
styleTag = document.createElement("style");
|
|
42
|
+
totalStyle += styleTag.innerHTML;
|
|
43
|
+
totalStyle += styS + style + styE;
|
|
44
|
+
styleTag.innerHTML = totalStyle;
|
|
45
|
+
document.head.append(styleTag);
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function dispatch(state: any, stateID: any): any;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// the global dispatcher
|
|
2
|
+
import fullScreen from "./fullscreen.js";
|
|
3
|
+
export default function dispatch(state, stateID) {
|
|
4
|
+
const nodes = document.querySelectorAll(".cra_child_doc");
|
|
5
|
+
window._.globalState = { state: state, stateID: stateID };
|
|
6
|
+
let node;
|
|
7
|
+
nodes.forEach((element) => {
|
|
8
|
+
// check if the element is mounted
|
|
9
|
+
if (!element.parentElement && !element.parentElement.parentElement) {
|
|
10
|
+
throw new Error("can't render an unmouted element");
|
|
11
|
+
}
|
|
12
|
+
// abort rendering if the state is not for this element
|
|
13
|
+
if (!element.stateID && element.stateID !== window._.globalState.stateID) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (element.stateID !== window._.globalState.stateID) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// updating the element's state
|
|
20
|
+
for (const key in window._.globalState.state) {
|
|
21
|
+
if (key === "style") {
|
|
22
|
+
for (const [k, v] of Object.entries(window._.globalState.state[key])) {
|
|
23
|
+
element.style[k] = v;
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (key === "text") {
|
|
28
|
+
element.innerText = window._.globalState.state[key];
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (key === "fullscreen") {
|
|
32
|
+
if (window._.globalState.state[key]) {
|
|
33
|
+
fullScreen(element).set();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
fullScreen(element).exist();
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (key === "class") {
|
|
41
|
+
element.classList.add(window._.globalState.state[key]);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (key === "toggleclass") {
|
|
45
|
+
element.classList.toggle(window._.globalState.state[key]);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (key === "removeclass") {
|
|
49
|
+
element.classList.remove(window._.globalState.state[key]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
element[key] = window._.globalState.state[key];
|
|
53
|
+
}
|
|
54
|
+
node = element;
|
|
55
|
+
});
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// the global dispatcher
|
|
2
|
+
import fullScreen from "./fullscreen.js";
|
|
3
|
+
|
|
4
|
+
export default function dispatch(state, stateID) {
|
|
5
|
+
const nodes = document.querySelectorAll(".cra_child_doc");
|
|
6
|
+
window._.globalState = { state: state, stateID: stateID };
|
|
7
|
+
let node;
|
|
8
|
+
nodes.forEach((element) => {
|
|
9
|
+
// check if the element is mounted
|
|
10
|
+
if (!element.parentElement && !element.parentElement.parentElement) {
|
|
11
|
+
throw new Error("can't render an unmouted element");
|
|
12
|
+
}
|
|
13
|
+
// abort rendering if the state is not for this element
|
|
14
|
+
if (!element.stateID && element.stateID !== window._.globalState.stateID) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (element.stateID !== window._.globalState.stateID) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// updating the element's state
|
|
22
|
+
for (const key in window._.globalState.state) {
|
|
23
|
+
if (key === "style") {
|
|
24
|
+
for (const [k, v] of Object.entries(window._.globalState.state[key])) {
|
|
25
|
+
element.style[k] = v;
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (key === "text") {
|
|
30
|
+
element.innerText = window._.globalState.state[key];
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (key === "fullscreen") {
|
|
34
|
+
if (window._.globalState.state[key]) {
|
|
35
|
+
fullScreen(element).set();
|
|
36
|
+
} else {
|
|
37
|
+
fullScreen(element).exist();
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (key === "class") {
|
|
42
|
+
element.classList.add(window._.globalState.state[key]);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (key === "toggleclass") {
|
|
46
|
+
element.classList.toggle(window._.globalState.state[key]);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (key === "removeclass") {
|
|
50
|
+
element.classList.remove(window._.globalState.state[key]);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
element[key] = window._.globalState.state[key];
|
|
54
|
+
}
|
|
55
|
+
node = element;
|
|
56
|
+
});
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const fs = {};
|
|
11
|
+
/**
|
|
12
|
+
* Open a handle to an existing file on the local file system.
|
|
13
|
+
*
|
|
14
|
+
* @return {!Promise<FileSystemFileHandle>} Handle to the existing file.
|
|
15
|
+
*/
|
|
16
|
+
fs.getFileHandle = function () {
|
|
17
|
+
// For Chrome 86 and later...
|
|
18
|
+
if ("showOpenFilePicker" in window) {
|
|
19
|
+
return window.showOpenFilePicker().then((handles) => handles[0]);
|
|
20
|
+
}
|
|
21
|
+
// For Chrome 85 and earlier...
|
|
22
|
+
return window.chooseFileSystemEntries();
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Create a handle to a new (text) file on the local file system.
|
|
26
|
+
*
|
|
27
|
+
* @return {!Promise<FileSystemFileHandle>} Handle to the new file.
|
|
28
|
+
*/
|
|
29
|
+
fs.getNewFileHandle = function () {
|
|
30
|
+
// For Chrome 86 and later...
|
|
31
|
+
if ("showSaveFilePicker" in window) {
|
|
32
|
+
const opts = {
|
|
33
|
+
types: [
|
|
34
|
+
{
|
|
35
|
+
description: "Text file",
|
|
36
|
+
accept: { "text/plain": [".txt"] },
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
return window.showSaveFilePicker(opts);
|
|
41
|
+
}
|
|
42
|
+
// For Chrome 85 and earlier...
|
|
43
|
+
const opts = {
|
|
44
|
+
type: "save-file",
|
|
45
|
+
accepts: [
|
|
46
|
+
{
|
|
47
|
+
description: "Text file",
|
|
48
|
+
extensions: ["txt"],
|
|
49
|
+
mimeTypes: ["text/plain"],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
return window.chooseFileSystemEntries(opts);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Reads the raw text from a file.
|
|
57
|
+
*
|
|
58
|
+
* @param {File} file
|
|
59
|
+
* @return {!Promise<string>} A promise that resolves to the parsed string.
|
|
60
|
+
*/
|
|
61
|
+
fs.readFile = function (file) {
|
|
62
|
+
// If the new .text() reader is available, use it.
|
|
63
|
+
if (file.text) {
|
|
64
|
+
return file.text();
|
|
65
|
+
}
|
|
66
|
+
// Otherwise use the traditional file reading technique.
|
|
67
|
+
return fs.readFileLegacy(file);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Reads the raw text from a file.
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
* @param {File} file
|
|
74
|
+
* @return {Promise<string>} A promise that resolves to the parsed string.
|
|
75
|
+
*/
|
|
76
|
+
fs.readFileLegacy = function (file) {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const reader = new FileReader();
|
|
79
|
+
reader.addEventListener("loadend", (e) => {
|
|
80
|
+
const text = e.srcElement.result;
|
|
81
|
+
resolve(text);
|
|
82
|
+
});
|
|
83
|
+
reader.readAsText(file);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Writes the contents to disk.
|
|
88
|
+
*
|
|
89
|
+
* @param {FileSystemFileHandle} fileHandle File handle to write to.
|
|
90
|
+
* @param {string} contents Contents to write.
|
|
91
|
+
*/
|
|
92
|
+
fs.writeFile = function (fileHandle, contents) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// Support for Chrome 82 and earlier.
|
|
95
|
+
if (fileHandle.createWriter) {
|
|
96
|
+
// Create a writer (request permission if necessary).
|
|
97
|
+
const writer = yield fileHandle.createWriter();
|
|
98
|
+
// Write the full length of the contents
|
|
99
|
+
yield writer.write(0, contents);
|
|
100
|
+
// Close the file and write the contents to disk
|
|
101
|
+
yield writer.close();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// For Chrome 83 and later.
|
|
105
|
+
// Create a FileSystemWritableFileStream to write to.
|
|
106
|
+
const writable = yield fileHandle.createWritable();
|
|
107
|
+
// Write the contents of the file to the stream.
|
|
108
|
+
yield writable.write(contents);
|
|
109
|
+
// Close the file and write the contents to disk.
|
|
110
|
+
yield writable.close();
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Verify the user has granted permission to read or write to the file, if
|
|
115
|
+
* permission hasn't been granted, request permission.
|
|
116
|
+
*
|
|
117
|
+
* @param {FileSystemFileHandle} fileHandle File handle to check.
|
|
118
|
+
* @param {boolean} withWrite True if write permission should be checked.
|
|
119
|
+
* @return {boolean} True if the user has granted read/write permission.
|
|
120
|
+
*/
|
|
121
|
+
fs.verifyPermission = function (fileHandle, withWrite) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const opts = {};
|
|
124
|
+
if (withWrite) {
|
|
125
|
+
opts.writable = true;
|
|
126
|
+
// For Chrome 86 and later...
|
|
127
|
+
opts.mode = "readwrite";
|
|
128
|
+
}
|
|
129
|
+
// Check if we already have permission, if so, return true.
|
|
130
|
+
if ((yield fileHandle.queryPermission(opts)) === "granted") {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
// Request permission to the file, if the user grants permission, return true.
|
|
134
|
+
if ((yield fileHandle.requestPermission(opts)) === "granted") {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
// The user did nt grant permission, return false.
|
|
138
|
+
return false;
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Uses the <input type="file"> to open a new file
|
|
143
|
+
*
|
|
144
|
+
* @return {!Promise<File>} File selected by the user.
|
|
145
|
+
*/
|
|
146
|
+
fs.getFileLegacy = () => {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
filePicker.onchange = (e) => {
|
|
149
|
+
const file = filePicker.files[0];
|
|
150
|
+
if (file) {
|
|
151
|
+
resolve(file);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
reject(new Error("AbortError"));
|
|
155
|
+
};
|
|
156
|
+
filePicker.click();
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Saves a file by creating a downloadable instance, and clicking on the
|
|
161
|
+
* download link.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} filename Filename to save the file as.
|
|
164
|
+
* @param {string} contents Contents of the file to save.
|
|
165
|
+
*/
|
|
166
|
+
// function saveAsLegacy(filename, contents) {
|
|
167
|
+
fs.saveAsLegacy = (filename, contents) => {
|
|
168
|
+
filename = filename || "Untitled.txt";
|
|
169
|
+
const opts = { type: "text/plain" };
|
|
170
|
+
const file = new File([contents], "", opts);
|
|
171
|
+
aDownloadFile.href = window.URL.createObjectURL(file);
|
|
172
|
+
aDownloadFile.setAttribute("download", filename);
|
|
173
|
+
aDownloadFile.click();
|
|
174
|
+
};
|
|
175
|
+
export default fs;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const fs = {};
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Open a handle to an existing file on the local file system.
|
|
5
|
+
*
|
|
6
|
+
* @return {!Promise<FileSystemFileHandle>} Handle to the existing file.
|
|
7
|
+
*/
|
|
8
|
+
fs.getFileHandle = function (): Promise<FileSystemFileHandle> {
|
|
9
|
+
// For Chrome 86 and later...
|
|
10
|
+
if ("showOpenFilePicker" in window) {
|
|
11
|
+
return window.showOpenFilePicker().then((handles: any[]) => handles[0]);
|
|
12
|
+
}
|
|
13
|
+
// For Chrome 85 and earlier...
|
|
14
|
+
return window.chooseFileSystemEntries();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a handle to a new (text) file on the local file system.
|
|
19
|
+
*
|
|
20
|
+
* @return {!Promise<FileSystemFileHandle>} Handle to the new file.
|
|
21
|
+
*/
|
|
22
|
+
fs.getNewFileHandle = function (): Promise<FileSystemFileHandle> {
|
|
23
|
+
// For Chrome 86 and later...
|
|
24
|
+
if ("showSaveFilePicker" in window) {
|
|
25
|
+
const opts = {
|
|
26
|
+
types: [
|
|
27
|
+
{
|
|
28
|
+
description: "Text file",
|
|
29
|
+
accept: { "text/plain": [".txt"] },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
return window.showSaveFilePicker(opts);
|
|
34
|
+
}
|
|
35
|
+
// For Chrome 85 and earlier...
|
|
36
|
+
const opts = {
|
|
37
|
+
type: "save-file",
|
|
38
|
+
accepts: [
|
|
39
|
+
{
|
|
40
|
+
description: "Text file",
|
|
41
|
+
extensions: ["txt"],
|
|
42
|
+
mimeTypes: ["text/plain"],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
return window.chooseFileSystemEntries(opts);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Reads the raw text from a file.
|
|
51
|
+
*
|
|
52
|
+
* @param {File} file
|
|
53
|
+
* @return {!Promise<string>} A promise that resolves to the parsed string.
|
|
54
|
+
*/
|
|
55
|
+
fs.readFile = function (file: File): Promise<string> {
|
|
56
|
+
// If the new .text() reader is available, use it.
|
|
57
|
+
if (file.text) {
|
|
58
|
+
return file.text();
|
|
59
|
+
}
|
|
60
|
+
// Otherwise use the traditional file reading technique.
|
|
61
|
+
return fs.readFileLegacy(file);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reads the raw text from a file.
|
|
66
|
+
*
|
|
67
|
+
* @private
|
|
68
|
+
* @param {File} file
|
|
69
|
+
* @return {Promise<string>} A promise that resolves to the parsed string.
|
|
70
|
+
*/
|
|
71
|
+
fs.readFileLegacy = function (file: File): Promise<string> {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
const reader = new FileReader();
|
|
74
|
+
reader.addEventListener("loadend", (e) => {
|
|
75
|
+
const text = e.srcElement.result;
|
|
76
|
+
resolve(text);
|
|
77
|
+
});
|
|
78
|
+
reader.readAsText(file);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Writes the contents to disk.
|
|
84
|
+
*
|
|
85
|
+
* @param {FileSystemFileHandle} fileHandle File handle to write to.
|
|
86
|
+
* @param {string} contents Contents to write.
|
|
87
|
+
*/
|
|
88
|
+
fs.writeFile = async function (
|
|
89
|
+
fileHandle: FileSystemFileHandle,
|
|
90
|
+
contents: string
|
|
91
|
+
) {
|
|
92
|
+
// Support for Chrome 82 and earlier.
|
|
93
|
+
if (fileHandle.createWriter) {
|
|
94
|
+
// Create a writer (request permission if necessary).
|
|
95
|
+
const writer = await fileHandle.createWriter();
|
|
96
|
+
// Write the full length of the contents
|
|
97
|
+
await writer.write(0, contents);
|
|
98
|
+
// Close the file and write the contents to disk
|
|
99
|
+
await writer.close();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// For Chrome 83 and later.
|
|
103
|
+
// Create a FileSystemWritableFileStream to write to.
|
|
104
|
+
const writable = await fileHandle.createWritable();
|
|
105
|
+
// Write the contents of the file to the stream.
|
|
106
|
+
await writable.write(contents);
|
|
107
|
+
// Close the file and write the contents to disk.
|
|
108
|
+
await writable.close();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Verify the user has granted permission to read or write to the file, if
|
|
113
|
+
* permission hasn't been granted, request permission.
|
|
114
|
+
*
|
|
115
|
+
* @param {FileSystemFileHandle} fileHandle File handle to check.
|
|
116
|
+
* @param {boolean} withWrite True if write permission should be checked.
|
|
117
|
+
* @return {boolean} True if the user has granted read/write permission.
|
|
118
|
+
*/
|
|
119
|
+
fs.verifyPermission = async function (
|
|
120
|
+
fileHandle: FileSystemFileHandle,
|
|
121
|
+
withWrite: boolean
|
|
122
|
+
): boolean {
|
|
123
|
+
const opts = {};
|
|
124
|
+
if (withWrite) {
|
|
125
|
+
opts.writable = true;
|
|
126
|
+
// For Chrome 86 and later...
|
|
127
|
+
opts.mode = "readwrite";
|
|
128
|
+
}
|
|
129
|
+
// Check if we already have permission, if so, return true.
|
|
130
|
+
if ((await fileHandle.queryPermission(opts)) === "granted") {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
// Request permission to the file, if the user grants permission, return true.
|
|
134
|
+
if ((await fileHandle.requestPermission(opts)) === "granted") {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
// The user did nt grant permission, return false.
|
|
138
|
+
return false;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Uses the <input type="file"> to open a new file
|
|
143
|
+
*
|
|
144
|
+
* @return {!Promise<File>} File selected by the user.
|
|
145
|
+
*/
|
|
146
|
+
fs.getFileLegacy = (): Promise<File> => {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
filePicker.onchange = (e: any) => {
|
|
149
|
+
const file = filePicker.files[0];
|
|
150
|
+
if (file) {
|
|
151
|
+
resolve(file);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
reject(new Error("AbortError"));
|
|
155
|
+
};
|
|
156
|
+
filePicker.click();
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Saves a file by creating a downloadable instance, and clicking on the
|
|
162
|
+
* download link.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} filename Filename to save the file as.
|
|
165
|
+
* @param {string} contents Contents of the file to save.
|
|
166
|
+
*/
|
|
167
|
+
// function saveAsLegacy(filename, contents) {
|
|
168
|
+
fs.saveAsLegacy = (filename: string, contents: string) => {
|
|
169
|
+
filename = filename || "Untitled.txt";
|
|
170
|
+
const opts = { type: "text/plain" };
|
|
171
|
+
const file = new File([contents], "", opts);
|
|
172
|
+
aDownloadFile.href = window.URL.createObjectURL(file);
|
|
173
|
+
aDownloadFile.setAttribute("download", filename);
|
|
174
|
+
aDownloadFile.click();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export default fs;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// for making the dom elements fulscreen
|
|
2
|
+
export default function fullScreen(e) {
|
|
3
|
+
return {
|
|
4
|
+
set() {
|
|
5
|
+
e.requestFullscreen().catch((err) => {
|
|
6
|
+
throw err;
|
|
7
|
+
});
|
|
8
|
+
},
|
|
9
|
+
exist() {
|
|
10
|
+
document.exitFullscreen();
|
|
11
|
+
},
|
|
12
|
+
// toggle: () => {
|
|
13
|
+
// if (!document.fullscreenElement) {
|
|
14
|
+
// e.requestFullscreen().catch((err) => {
|
|
15
|
+
// throw err;
|
|
16
|
+
// });
|
|
17
|
+
// } else {
|
|
18
|
+
// document.exitFullscreen();
|
|
19
|
+
// }
|
|
20
|
+
// },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/*
|
|
24
|
+
*** HOW TO USE ***
|
|
25
|
+
|
|
26
|
+
u("#container").fullscreen().toggle()
|
|
27
|
+
u("#container").fullscreen().exist()
|
|
28
|
+
u("#container").fullscreen().set()
|
|
29
|
+
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// for making the dom elements fulscreen
|
|
2
|
+
export default function fullScreen(e: HTMLElement) {
|
|
3
|
+
return {
|
|
4
|
+
set() {
|
|
5
|
+
e.requestFullscreen().catch((err) => {
|
|
6
|
+
throw err;
|
|
7
|
+
});
|
|
8
|
+
},
|
|
9
|
+
exist() {
|
|
10
|
+
document.exitFullscreen();
|
|
11
|
+
},
|
|
12
|
+
// toggle: () => {
|
|
13
|
+
// if (!document.fullscreenElement) {
|
|
14
|
+
// e.requestFullscreen().catch((err) => {
|
|
15
|
+
// throw err;
|
|
16
|
+
// });
|
|
17
|
+
// } else {
|
|
18
|
+
// document.exitFullscreen();
|
|
19
|
+
// }
|
|
20
|
+
// },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
*** HOW TO USE ***
|
|
26
|
+
|
|
27
|
+
u("#container").fullscreen().toggle()
|
|
28
|
+
u("#container").fullscreen().exist()
|
|
29
|
+
u("#container").fullscreen().set()
|
|
30
|
+
*/
|
package/scripts/init.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import css from "./css.js";
|
|
2
|
+
const Init = function (config) {
|
|
3
|
+
const Wrapper = document.createElement("div");
|
|
4
|
+
Wrapper.className = "Cradova-app-wrappper";
|
|
5
|
+
Wrapper.id = "app-wrapper";
|
|
6
|
+
css(".Cradova-app-wrappper", {
|
|
7
|
+
display: "flex",
|
|
8
|
+
"align-items": "center",
|
|
9
|
+
"justify-content": "center",
|
|
10
|
+
"flex-direction": "column",
|
|
11
|
+
width: "100%",
|
|
12
|
+
});
|
|
13
|
+
// Wrapper.stateID = "Cradova-app-wrappper-id";
|
|
14
|
+
document.body.append(Wrapper);
|
|
15
|
+
return Wrapper;
|
|
16
|
+
};
|
|
17
|
+
export default Init;
|
package/scripts/init.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import css from "./css.js";
|
|
2
|
+
const Init = function (config: Record<string, string>) {
|
|
3
|
+
const Wrapper = document.createElement("div");
|
|
4
|
+
Wrapper.className = "Cradova-app-wrappper";
|
|
5
|
+
Wrapper.id = "app-wrapper";
|
|
6
|
+
css(".Cradova-app-wrappper", {
|
|
7
|
+
display: "flex",
|
|
8
|
+
"align-items": "center",
|
|
9
|
+
"justify-content": "center",
|
|
10
|
+
"flex-direction": "column",
|
|
11
|
+
width: "100%",
|
|
12
|
+
});
|
|
13
|
+
// Wrapper.stateID = "Cradova-app-wrappper-id";
|
|
14
|
+
document.body.append(Wrapper);
|
|
15
|
+
return Wrapper;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default Init;
|