@basthon/gui-base 0.36.2 → 0.36.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/main.d.ts CHANGED
@@ -1,10 +1,5 @@
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
  */
@@ -13,7 +8,7 @@ export declare class GUIBase {
13
8
  private readonly _loaded;
14
9
  private _loader;
15
10
  private _console_error;
16
- constructor(language: string);
11
+ constructor(kernelRootPath: string, language: string);
17
12
  /**
18
13
  * Language getter.
19
14
  */
@@ -37,7 +32,7 @@ export declare class GUIBase {
37
32
  /**
38
33
  * Notify the user with an error.
39
34
  */
40
- error(message: string): void;
35
+ error(title: string, message: string): void;
41
36
  /**
42
37
  * Ask the user to confirm or cancel.
43
38
  */
@@ -109,4 +104,12 @@ export declare class GUIBase {
109
104
  * Binding to kernel's XHR.
110
105
  */
111
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>;
112
115
  }
package/lib/main.js CHANGED
@@ -5,17 +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
10
  /* console errors redirected to notification system */
11
11
  this._console_error = console.error;
12
12
  this._language = language;
13
- this._loader = new KernelLoader(language);
13
+ this._loader = new KernelLoader(kernelRootPath, language);
14
14
  // loading Basthon (errors are fatal)
15
15
  this._loader.showLoader("Chargement de Basthon...", false);
16
- this._loader.kernelAvailable().then((kernel) => {
17
- window.Basthon = kernel;
18
- });
19
16
  }
20
17
  /**
21
18
  * Language getter.
@@ -40,7 +37,7 @@ export class GUIBase {
40
37
  /**
41
38
  * Notify the user with an error.
42
39
  */
43
- error(message) { }
40
+ error(title, message) { }
44
41
  /**
45
42
  * Ask the user to confirm or cancel.
46
43
  */
@@ -61,7 +58,7 @@ export class GUIBase {
61
58
  if (message == null)
62
59
  message = error.toString();
63
60
  message = message.split('\n').join('<br>');
64
- this.error(`Erreur : ${message}`);
61
+ this.error("Erreur", `Erreur : ${message}`);
65
62
  // In case of error, force loader hiding.
66
63
  try {
67
64
  this._loader.hideLoader();
@@ -141,7 +138,7 @@ export class GUIBase {
141
138
  reader.onload = async (event) => {
142
139
  var _a, _b;
143
140
  (_a = this.kernel) === null || _a === void 0 ? void 0 : _a.putRessource(file.name, reader.result);
144
- this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this.kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
141
+ this.info("Fichier utilisable depuis ${this.kernel?.languageName()", `${file.name} est maintenant utilisable depuis ${(_b = this.kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
145
142
  resolve();
146
143
  };
147
144
  reader.onerror = reject;
@@ -221,6 +218,24 @@ export class GUIBase {
221
218
  static async xhr(params) {
222
219
  return await KernelBase.xhr(params);
223
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
+ }
224
239
  }
225
240
  /**
226
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.2",
3
+ "version": "0.36.6",
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.2",
29
- "@basthon/kernel-loader": "^0.36.2",
28
+ "@basthon/kernel-base": "^0.36.6",
29
+ "@basthon/kernel-loader": "^0.36.6",
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": "8fe755fb31a810261ca52b797c491dea633c17a9"
43
+ "gitHead": "fb7ba80accf982becc0fd5f5d64e09b4e4c2096c"
41
44
  }