graphico 1.2.0 → 1.2.1
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/dist/canvas.js +18 -34
- package/package.json +1 -1
- package/types/canvas.d.ts +3 -3
- package/types/types.d.ts +0 -4
package/dist/canvas.js
CHANGED
|
@@ -418,13 +418,10 @@ var Canvas = /** @class */ (function () {
|
|
|
418
418
|
*/
|
|
419
419
|
Canvas.prototype.saveData = function (data, name) {
|
|
420
420
|
if (name === void 0) { name = 'data'; }
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
localStorage.setItem(key, value);
|
|
426
|
-
this.log("Saved \"".concat(name, ".").concat(rawkey, "\" = \"").concat(rawval, ".").concat(typeof rawval, "\" as \"").concat(key, "\" = \"").concat(value, "\"."));
|
|
427
|
-
}
|
|
421
|
+
var key = this.encode(name);
|
|
422
|
+
var value = this.encode(data);
|
|
423
|
+
localStorage.setItem(key, value);
|
|
424
|
+
this.log("Saved \"".concat(data, "\" in ").concat(name, "."));
|
|
428
425
|
};
|
|
429
426
|
/**
|
|
430
427
|
* Load arbitrary data from the browser storage.
|
|
@@ -433,24 +430,20 @@ var Canvas = /** @class */ (function () {
|
|
|
433
430
|
* @returns The data object loaded from browser storage
|
|
434
431
|
*/
|
|
435
432
|
Canvas.prototype.loadData = function (name) {
|
|
436
|
-
var _a;
|
|
437
433
|
if (name === void 0) { name = 'data'; }
|
|
438
|
-
var
|
|
439
|
-
|
|
440
|
-
|
|
434
|
+
var key = this.encode(name);
|
|
435
|
+
var value = localStorage.getItem(key);
|
|
436
|
+
if (value) {
|
|
441
437
|
try {
|
|
442
|
-
var
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
loaded[decodedKey[1]] = decodedVal[0];
|
|
446
|
-
this.log("Loaded \"".concat(decodedKey.join('.'), "\" = \"").concat(decodedVal.join('.'), "\" from \"").concat(key, "\""));
|
|
447
|
-
}
|
|
438
|
+
var decoded = this.decode(value);
|
|
439
|
+
this.log("Loaded \"".concat(decoded, "\" from ").concat(name, "."));
|
|
440
|
+
return decoded;
|
|
448
441
|
}
|
|
449
|
-
catch (
|
|
450
|
-
this.log("
|
|
442
|
+
catch (_a) {
|
|
443
|
+
this.log("Failed to load ".concat(name, "."));
|
|
451
444
|
}
|
|
452
445
|
}
|
|
453
|
-
return
|
|
446
|
+
return undefined;
|
|
454
447
|
};
|
|
455
448
|
/**
|
|
456
449
|
* Clear **all** saved data. This action is permanent!
|
|
@@ -458,30 +451,21 @@ var Canvas = /** @class */ (function () {
|
|
|
458
451
|
*/
|
|
459
452
|
Canvas.prototype.clearData = function (name) {
|
|
460
453
|
if (name === void 0) { name = 'data'; }
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (this.decode(key)[0] === name) {
|
|
465
|
-
localStorage.removeItem(key);
|
|
466
|
-
this.log("Removed ".concat(key, " from storage."));
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
catch (_b) {
|
|
470
|
-
this.log("Skipping \"".concat(key, "\"..."));
|
|
471
|
-
}
|
|
472
|
-
}
|
|
454
|
+
var key = this.encode(name);
|
|
455
|
+
localStorage.removeItem(key);
|
|
456
|
+
this.log("Removed ".concat(name, " from storage."));
|
|
473
457
|
};
|
|
474
458
|
/**
|
|
475
459
|
* Encode data for local browser storage.
|
|
476
460
|
*/
|
|
477
461
|
Canvas.prototype.encode = function (raw) {
|
|
478
|
-
return
|
|
462
|
+
return btoa(encodeURIComponent(JSON.stringify(raw)));
|
|
479
463
|
};
|
|
480
464
|
/**
|
|
481
465
|
* Decode data from local browser storage.
|
|
482
466
|
*/
|
|
483
467
|
Canvas.prototype.decode = function (code) {
|
|
484
|
-
return
|
|
468
|
+
return JSON.parse(decodeURIComponent(atob(code)));
|
|
485
469
|
};
|
|
486
470
|
/**
|
|
487
471
|
* Log a message to the debug console.
|
package/package.json
CHANGED
package/types/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Drawable, Options
|
|
1
|
+
import { Drawable, Options } from '.';
|
|
2
2
|
/**
|
|
3
3
|
* Represents a canvas for drawing and animating
|
|
4
4
|
*/
|
|
@@ -161,14 +161,14 @@ export declare class Canvas {
|
|
|
161
161
|
* @param data The arbirary data object to save
|
|
162
162
|
* @param name An optional "namespace" to store the data, which can be assigned when a user has multiple profiles, for example
|
|
163
163
|
*/
|
|
164
|
-
saveData<T
|
|
164
|
+
saveData<T>(data: T, name?: string): void;
|
|
165
165
|
/**
|
|
166
166
|
* Load arbitrary data from the browser storage.
|
|
167
167
|
* **Warning:** The loaded data object is not strictly type-checked or sanitized, so it may have missing fields or contain extra fields. It's good practice to manually validate the data once it's loaded from storage.
|
|
168
168
|
* @param name An optional "namespace" to load data from, assigned when saving data
|
|
169
169
|
* @returns The data object loaded from browser storage
|
|
170
170
|
*/
|
|
171
|
-
loadData<T
|
|
171
|
+
loadData<T>(name?: string): Partial<T> | undefined;
|
|
172
172
|
/**
|
|
173
173
|
* Clear **all** saved data. This action is permanent!
|
|
174
174
|
* @param name An optional "namespace" to clear data from.
|