@basthon/gui-base 0.36.4 → 0.36.8

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
@@ -16,7 +16,7 @@ export declare class GUIBase {
16
16
  /**
17
17
  * Kernel getter.
18
18
  */
19
- get kernel(): KernelBase | null;
19
+ get kernel(): KernelBase | undefined;
20
20
  /**
21
21
  * KernelLoader getter.
22
22
  */
@@ -32,7 +32,7 @@ export declare class GUIBase {
32
32
  /**
33
33
  * Notify the user with an error.
34
34
  */
35
- error(message: string): void;
35
+ error(title: string, message: string): void;
36
36
  /**
37
37
  * Ask the user to confirm or cancel.
38
38
  */
@@ -59,6 +59,10 @@ export declare class GUIBase {
59
59
  * init process, trying to do our best...
60
60
  */
61
61
  initCaller(func: () => Promise<any>, message: string, catchError: boolean): Promise<any>;
62
+ /**
63
+ * Get mode as a string (dark/light).
64
+ */
65
+ theme(): "dark" | "light" | undefined;
62
66
  /**
63
67
  * Restart the kernel.
64
68
  */
@@ -91,7 +95,7 @@ export declare class GUIBase {
91
95
  /**
92
96
  * Open an URL in a new tab or download a file.
93
97
  */
94
- static openURL(url: string, download?: string | null | undefined): void;
98
+ static openURL(url: string, download?: string): void;
95
99
  /**
96
100
  * Share content via URL.
97
101
  */
@@ -104,4 +108,12 @@ export declare class GUIBase {
104
108
  * Binding to kernel's XHR.
105
109
  */
106
110
  static xhr(params: any): Promise<unknown>;
111
+ /**
112
+ * Compress a string to another string (URL safe).
113
+ */
114
+ deflate(content: string): Promise<string>;
115
+ /**
116
+ * Reverse version of deflate.
117
+ */
118
+ inflate(content: string): Promise<string>;
107
119
  }
package/lib/main.js CHANGED
@@ -37,7 +37,7 @@ export class GUIBase {
37
37
  /**
38
38
  * Notify the user with an error.
39
39
  */
40
- error(message) { }
40
+ error(title, message) { }
41
41
  /**
42
42
  * Ask the user to confirm or cancel.
43
43
  */
@@ -58,7 +58,7 @@ export class GUIBase {
58
58
  if (message == null)
59
59
  message = error.toString();
60
60
  message = message.split('\n').join('<br>');
61
- this.error(`Erreur : ${message}`);
61
+ this.error("Erreur", `Erreur : ${message}`);
62
62
  // In case of error, force loader hiding.
63
63
  try {
64
64
  this._loader.hideLoader();
@@ -100,6 +100,10 @@ export class GUIBase {
100
100
  this.notifyError(error);
101
101
  }
102
102
  }
103
+ /**
104
+ * Get mode as a string (dark/light).
105
+ */
106
+ theme() { return; }
103
107
  /**
104
108
  * Restart the kernel.
105
109
  */
@@ -138,7 +142,7 @@ export class GUIBase {
138
142
  reader.onload = async (event) => {
139
143
  var _a, _b;
140
144
  (_a = this.kernel) === null || _a === void 0 ? void 0 : _a.putRessource(file.name, reader.result);
141
- this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this.kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
145
+ 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()}`);
142
146
  resolve();
143
147
  };
144
148
  reader.onerror = reject;
@@ -195,7 +199,7 @@ export class GUIBase {
195
199
  /**
196
200
  * Open an URL in a new tab or download a file.
197
201
  */
198
- static openURL(url, download = null) {
202
+ static openURL(url, download) {
199
203
  let anchor = document.createElement("a");
200
204
  if (download != null)
201
205
  anchor.download = download;
@@ -218,6 +222,24 @@ export class GUIBase {
218
222
  static async xhr(params) {
219
223
  return await KernelBase.xhr(params);
220
224
  }
225
+ /**
226
+ * Compress a string to another string (URL safe).
227
+ */
228
+ async deflate(content) {
229
+ // dynamic import for webpack
230
+ const pako = await import("pako");
231
+ const { Base64 } = await import("js-base64");
232
+ return Base64.fromUint8Array(pako.deflate(content), true);
233
+ }
234
+ /**
235
+ * Reverse version of deflate.
236
+ */
237
+ async inflate(content) {
238
+ // dynamic import for webpack
239
+ const pako = await import("pako");
240
+ const { Base64 } = await import("js-base64");
241
+ return pako.inflate(Base64.toUint8Array(content), { to: 'string' });
242
+ }
221
243
  }
222
244
  /**
223
245
  * 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.4",
3
+ "version": "0.36.8",
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.4",
29
- "@basthon/kernel-loader": "^0.36.4",
28
+ "@basthon/kernel-base": "^0.36.8",
29
+ "@basthon/kernel-loader": "^0.36.8",
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": "edcb6d1d099440e2fadbeb12acf34b5cc77486a2"
43
+ "gitHead": "de9fb899dd03ee4f806b065fab4d0ece03328093"
41
44
  }