@basthon/gui-base 0.36.1 → 0.36.5
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/main.d.ts +9 -7
- package/lib/main.js +28 -15
- package/package.json +7 -4
package/lib/main.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { KernelBase } from "@basthon/kernel-base";
|
|
2
2
|
import { KernelLoader } from "@basthon/kernel-loader";
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
Basthon?: any;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
/**
|
|
9
4
|
* Base class for console and notebook GUI.
|
|
10
5
|
*/
|
|
11
6
|
export declare class GUIBase {
|
|
12
7
|
private readonly _language;
|
|
13
8
|
private readonly _loaded;
|
|
14
|
-
private _kernel;
|
|
15
9
|
private _loader;
|
|
16
10
|
private _console_error;
|
|
17
|
-
constructor(language: string);
|
|
11
|
+
constructor(kernelRootPath: string, language: string);
|
|
18
12
|
/**
|
|
19
13
|
* Language getter.
|
|
20
14
|
*/
|
|
@@ -110,4 +104,12 @@ export declare class GUIBase {
|
|
|
110
104
|
* Binding to kernel's XHR.
|
|
111
105
|
*/
|
|
112
106
|
static xhr(params: any): Promise<unknown>;
|
|
107
|
+
/**
|
|
108
|
+
* Compress a string to another string (URL safe).
|
|
109
|
+
*/
|
|
110
|
+
deflate(content: string): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Reverse version of deflate.
|
|
113
|
+
*/
|
|
114
|
+
inflate(content: string): Promise<string>;
|
|
113
115
|
}
|
package/lib/main.js
CHANGED
|
@@ -5,19 +5,14 @@ import { KernelLoader } from "@basthon/kernel-loader";
|
|
|
5
5
|
* Base class for console and notebook GUI.
|
|
6
6
|
*/
|
|
7
7
|
export class GUIBase {
|
|
8
|
-
constructor(language) {
|
|
8
|
+
constructor(kernelRootPath, language) {
|
|
9
9
|
this._loaded = new PromiseDelegate();
|
|
10
|
-
this._kernel = null;
|
|
11
10
|
/* console errors redirected to notification system */
|
|
12
11
|
this._console_error = console.error;
|
|
13
12
|
this._language = language;
|
|
14
|
-
this._loader = new KernelLoader(language);
|
|
13
|
+
this._loader = new KernelLoader(kernelRootPath, language);
|
|
15
14
|
// loading Basthon (errors are fatal)
|
|
16
15
|
this._loader.showLoader("Chargement de Basthon...", false);
|
|
17
|
-
this._loader.kernelAvailable().then(() => {
|
|
18
|
-
this._kernel = this._loader.kernel;
|
|
19
|
-
window.Basthon = this._kernel;
|
|
20
|
-
});
|
|
21
16
|
}
|
|
22
17
|
/**
|
|
23
18
|
* Language getter.
|
|
@@ -26,7 +21,7 @@ export class GUIBase {
|
|
|
26
21
|
/**
|
|
27
22
|
* Kernel getter.
|
|
28
23
|
*/
|
|
29
|
-
get kernel() { return this.
|
|
24
|
+
get kernel() { return this._loader.kernel; }
|
|
30
25
|
/**
|
|
31
26
|
* KernelLoader getter.
|
|
32
27
|
*/
|
|
@@ -108,7 +103,7 @@ export class GUIBase {
|
|
|
108
103
|
/**
|
|
109
104
|
* Restart the kernel.
|
|
110
105
|
*/
|
|
111
|
-
kernelRestart() { var _a; (_a = this.
|
|
106
|
+
kernelRestart() { var _a; (_a = this.kernel) === null || _a === void 0 ? void 0 : _a.restart(); }
|
|
112
107
|
/**
|
|
113
108
|
* Load ressources from URL (common part to files and modules).
|
|
114
109
|
*/
|
|
@@ -118,7 +113,7 @@ export class GUIBase {
|
|
|
118
113
|
for (let fileURL of url.searchParams.getAll(key)) {
|
|
119
114
|
fileURL = decodeURIComponent(fileURL);
|
|
120
115
|
const filename = fileURL.split('/').pop() || "";
|
|
121
|
-
let promise =
|
|
116
|
+
let promise = GUIBase.xhr({
|
|
122
117
|
method: "GET",
|
|
123
118
|
url: fileURL,
|
|
124
119
|
responseType: "arraybuffer"
|
|
@@ -143,7 +138,7 @@ export class GUIBase {
|
|
|
143
138
|
reader.onload = async (event) => {
|
|
144
139
|
var _a, _b;
|
|
145
140
|
(_a = this.kernel) === null || _a === void 0 ? void 0 : _a.putRessource(file.name, reader.result);
|
|
146
|
-
this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this.
|
|
141
|
+
this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this.kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
|
|
147
142
|
resolve();
|
|
148
143
|
};
|
|
149
144
|
reader.onerror = reject;
|
|
@@ -153,17 +148,17 @@ export class GUIBase {
|
|
|
153
148
|
* Load auxiliary files submited via URL (aux= parameter) (async).
|
|
154
149
|
*/
|
|
155
150
|
async loadURLAux() {
|
|
156
|
-
if (this.
|
|
151
|
+
if (this.kernel == null)
|
|
157
152
|
return;
|
|
158
|
-
await this._loadFromURL('aux', this.
|
|
153
|
+
await this._loadFromURL('aux', this.kernel.putFile.bind(this.kernel));
|
|
159
154
|
}
|
|
160
155
|
/**
|
|
161
156
|
* Load modules submited via URL (module= parameter) (async).
|
|
162
157
|
*/
|
|
163
158
|
async loadURLModules() {
|
|
164
|
-
if (this.
|
|
159
|
+
if (this.kernel == null)
|
|
165
160
|
return;
|
|
166
|
-
await this._loadFromURL('module', this.
|
|
161
|
+
await this._loadFromURL('module', this.kernel.putModule.bind(this.kernel));
|
|
167
162
|
}
|
|
168
163
|
/**
|
|
169
164
|
* Opening file: If it has ext as extension, loading it in
|
|
@@ -223,6 +218,24 @@ export class GUIBase {
|
|
|
223
218
|
static async xhr(params) {
|
|
224
219
|
return await KernelBase.xhr(params);
|
|
225
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Compress a string to another string (URL safe).
|
|
223
|
+
*/
|
|
224
|
+
async deflate(content) {
|
|
225
|
+
// dynamic import for webpack
|
|
226
|
+
const pako = await import("pako");
|
|
227
|
+
const { Base64 } = await import("js-base64");
|
|
228
|
+
return Base64.fromUint8Array(pako.deflate(content), true);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Reverse version of deflate.
|
|
232
|
+
*/
|
|
233
|
+
async inflate(content) {
|
|
234
|
+
// dynamic import for webpack
|
|
235
|
+
const pako = await import("pako");
|
|
236
|
+
const { Base64 } = await import("js-base64");
|
|
237
|
+
return pako.inflate(Base64.toUint8Array(content), { to: 'string' });
|
|
238
|
+
}
|
|
226
239
|
}
|
|
227
240
|
/**
|
|
228
241
|
* Copy a text to clipboard.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basthon/gui-base",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.5",
|
|
4
4
|
"description": "Basthon - Base GUI",
|
|
5
5
|
"homepage": "https://basthon.fr",
|
|
6
6
|
"bugs": {
|
|
@@ -25,11 +25,14 @@
|
|
|
25
25
|
"clean": "rm -rf lib/"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@basthon/kernel-base": "^0.36.
|
|
29
|
-
"@basthon/kernel-loader": "^0.36.
|
|
28
|
+
"@basthon/kernel-base": "^0.36.5",
|
|
29
|
+
"@basthon/kernel-loader": "^0.36.5",
|
|
30
|
+
"js-base64": "^3.7.2",
|
|
31
|
+
"pako": "^2.0.4",
|
|
30
32
|
"promise-delegate": "^1.0.1"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
35
|
+
"@types/pako": "^1.0.2",
|
|
33
36
|
"gulp": "^4.0.2",
|
|
34
37
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
35
38
|
"typescript": "~4.4.4"
|
|
@@ -37,5 +40,5 @@
|
|
|
37
40
|
"publishConfig": {
|
|
38
41
|
"access": "public"
|
|
39
42
|
},
|
|
40
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9d7e47b7e7fa8ba8cbaa4bcf77fe1f282fca79d0"
|
|
41
44
|
}
|