@basthon/kernel-base 0.60.4 → 0.60.6
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/lib/kernel.d.ts +8 -2
- package/lib/kernel.js +75 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
package/lib/kernel.d.ts
CHANGED
|
@@ -44,8 +44,14 @@ export declare class KernelBase {
|
|
|
44
44
|
putFile(filename: string, content: ArrayBuffer): Promise<void>;
|
|
45
45
|
putModule(filename: string, content: ArrayBuffer): Promise<void>;
|
|
46
46
|
userModules(): string[];
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Get a file content from the VFS.
|
|
49
|
+
*/
|
|
50
|
+
getFile(path: string): Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* Get a user module file content.
|
|
53
|
+
*/
|
|
54
|
+
getUserModuleFile(filename: string): Uint8Array;
|
|
49
55
|
more(source: string): boolean;
|
|
50
56
|
complete(code: string): [string[], number] | [];
|
|
51
57
|
banner(): string;
|
package/lib/kernel.js
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
import { PromiseDelegate } from "promise-delegate";
|
|
2
2
|
import { VERSION } from "./version";
|
|
3
|
+
const _localfsScheme = "filesystem:/";
|
|
4
|
+
/* we mock the fetch function to redirect queries to local FS */
|
|
5
|
+
(function () {
|
|
6
|
+
var _a;
|
|
7
|
+
const toDataURL = async (content) => {
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const reader = new FileReader();
|
|
10
|
+
reader.onloadend = () => {
|
|
11
|
+
resolve(reader.result);
|
|
12
|
+
};
|
|
13
|
+
reader.onerror = reject;
|
|
14
|
+
reader.readAsDataURL(new Blob([content]));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
window._fetch = (_a = window._fetch) !== null && _a !== void 0 ? _a : window.fetch;
|
|
19
|
+
window.fetch = async function (request, opts) {
|
|
20
|
+
var _a;
|
|
21
|
+
//@ts-ignore
|
|
22
|
+
const url = (_a = request.url) !== null && _a !== void 0 ? _a : request.toString();
|
|
23
|
+
const prefix = _localfsScheme;
|
|
24
|
+
if (url.startsWith(prefix)) {
|
|
25
|
+
const path = url.slice(prefix.length);
|
|
26
|
+
let content = null;
|
|
27
|
+
const options = {
|
|
28
|
+
status: 200,
|
|
29
|
+
statusText: "OK",
|
|
30
|
+
headers: new Headers(),
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
content = window.Basthon.getFile(path);
|
|
35
|
+
const dataURL = await toDataURL(content);
|
|
36
|
+
const mime = dataURL.substring(dataURL.indexOf(":") + 1, dataURL.indexOf(";"));
|
|
37
|
+
content = content.buffer;
|
|
38
|
+
options.headers.append("Content-Type", mime);
|
|
39
|
+
options.headers.append("Content-Length", content.byteLength);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
options.status = 404;
|
|
43
|
+
options.statusText = "Not Found";
|
|
44
|
+
}
|
|
45
|
+
return new Response(content, options);
|
|
46
|
+
}
|
|
47
|
+
//@ts-ignore
|
|
48
|
+
return await window._fetch(request, opts);
|
|
49
|
+
};
|
|
50
|
+
const desc = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, "src");
|
|
51
|
+
Object.defineProperty(HTMLImageElement.prototype, "src", {
|
|
52
|
+
...desc,
|
|
53
|
+
get: function () {
|
|
54
|
+
var _a;
|
|
55
|
+
return (_a = desc === null || desc === void 0 ? void 0 : desc.get) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
56
|
+
},
|
|
57
|
+
set: function (e) {
|
|
58
|
+
var _a;
|
|
59
|
+
const prefix = _localfsScheme;
|
|
60
|
+
if (e.startsWith(prefix)) {
|
|
61
|
+
const path = e.slice(prefix.length);
|
|
62
|
+
//@ts-ignore
|
|
63
|
+
const content = window.Basthon.getFile(path).buffer;
|
|
64
|
+
(async () => { var _a; return (_a = desc === null || desc === void 0 ? void 0 : desc.set) === null || _a === void 0 ? void 0 : _a.call(this, await toDataURL(content)); })();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(_a = desc === null || desc === void 0 ? void 0 : desc.set) === null || _a === void 0 ? void 0 : _a.call(this, e);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
})();
|
|
3
72
|
/**
|
|
4
73
|
* An error thrown by not implemented API functions.
|
|
5
74
|
*/
|
|
@@ -89,9 +158,15 @@ export class KernelBase {
|
|
|
89
158
|
userModules() {
|
|
90
159
|
return [];
|
|
91
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a file content from the VFS.
|
|
163
|
+
*/
|
|
92
164
|
getFile(path) {
|
|
93
165
|
throw new NotImplementedError("getFile");
|
|
94
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Get a user module file content.
|
|
169
|
+
*/
|
|
95
170
|
getUserModuleFile(filename) {
|
|
96
171
|
throw new NotImplementedError("getUserModuleFile");
|
|
97
172
|
}
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.60.
|
|
1
|
+
export declare const VERSION = "0.60.6";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.60.
|
|
1
|
+
export const VERSION = "0.60.6";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basthon/kernel-base",
|
|
3
|
-
"version": "0.60.
|
|
3
|
+
"version": "0.60.6",
|
|
4
4
|
"description": "Basthon - Base Kernel",
|
|
5
5
|
"homepage": "https://basthon.fr",
|
|
6
6
|
"bugs": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "b1b63785d8ab975312827c7df9e9e8e529f9a091"
|
|
40
40
|
}
|