“MediaWiki:Gadget-LocalObjectStorage.js”的版本间的差异

来自萌娘共享
跳转至: 导航搜索
(创建页面,内容为“User:AnnAngela/js/LocalObjectStorage.js eslint-disable: "use strict"; (function () { var __spreadArray = function (to, from) { for (var i…”
 
(代码变动:e1e15bf6 - chore: eslint by U:星海子
1个标签由机器人或全自动脚本执行的操作
 
(未显示4个用户的13个中间版本)
第1行: 第1行:
/* [[User:AnnAngela/js/LocalObjectStorage.js]] */
+
/**
/* eslint-disable */
+
* -------------------------------------------------------------------------
 +
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 +
* -------------------------------------------------------------------------
 +
*/
 +
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LocalObjectStorage/MediaWiki:Gadget-LocalObjectStorage.js|user=[[U:星海子]]|co-authors=|longId=e1e15bf6ac13a6c997a9a3208dab7f70fa6a77fb|shortId=e1e15bf6|summary=chore: eslint}}';
 +
 
 +
/* <pre> */
 +
 
 
"use strict";
 
"use strict";
 +
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
 +
    if (kind === "m") throw new TypeError("Private method is not writable");
 +
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
 +
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
 +
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
 +
};
 +
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
 +
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
 +
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
 +
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
 +
};
 +
var __read = (this && this.__read) || function (o, n) {
 +
    var m = typeof Symbol === "function" && o[Symbol.iterator];
 +
    if (!m) return o;
 +
    var i = m.call(o), r, ar = [], e;
 +
    try {
 +
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
 +
    }
 +
    catch (error) { e = { error: error }; }
 +
    finally {
 +
        try {
 +
            if (r && !r.done && (m = i["return"])) m.call(i);
 +
        }
 +
        finally { if (e) throw e.error; }
 +
    }
 +
    return ar;
 +
};
 +
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
 +
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
 +
        if (ar || !(i in from)) {
 +
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
 +
            ar[i] = from[i];
 +
        }
 +
    }
 +
    return to.concat(ar || Array.prototype.slice.call(from));
 +
};
 +
var __values = (this && this.__values) || function(o) {
 +
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
 +
    if (m) return m.call(o);
 +
    if (o && typeof o.length === "number") return {
 +
        next: function () {
 +
            if (o && i >= o.length) o = void 0;
 +
            return { value: o && o[i++], done: !o };
 +
        }
 +
    };
 +
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
 +
};
 
(function () {
 
(function () {
    var __spreadArray = function (to, from) {
 
        for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
 
            to[j] = from[i];
 
        return to;
 
    };
 
 
     var builtinTransformations = [
 
     var builtinTransformations = [
 
         {
 
         {
第13行: 第62行:
 
             match: function (t) { return typeof t === "undefined"; },
 
             match: function (t) { return typeof t === "undefined"; },
 
             encode: function () { return "undefined"; },
 
             encode: function () { return "undefined"; },
             decode: function () { return undefined; },
+
             decode: function () { return undefined; }
 
         },
 
         },
 
         {
 
         {
 
             type: "bigint",
 
             type: "bigint",
 
             match: function (t) { return typeof t === "bigint"; },
 
             match: function (t) { return typeof t === "bigint"; },
             encode: function (b) { return "" + b; },
+
             encode: function (b) { return "".concat(b); },
             decode: function (b) { return BigInt(b); },
+
             decode: function (b) { return BigInt(b); }
 
         },
 
         },
 
         {
 
         {
第25行: 第74行:
 
             match: function (t) { return t instanceof Date; },
 
             match: function (t) { return t instanceof Date; },
 
             encode: function (d) { return d.toISOString(); },
 
             encode: function (d) { return d.toISOString(); },
             decode: function (d) { return new Date(d); },
+
             decode: function (d) { return new Date(d); }
 
         },
 
         },
 
         {
 
         {
 
             type: "set",
 
             type: "set",
 
             match: function (t) { return t instanceof Set; },
 
             match: function (t) { return t instanceof Set; },
             encode: function (s) { return JSON.stringify(__spreadArray([], s.values())); },
+
             encode: function (s) { return JSON.stringify(__spreadArray([], __read(s.values()), false)); },
             decode: function (s) { return new Set(JSON.parse(s)); },
+
             decode: function (s) { return new Set(JSON.parse(s)); }
 
         },
 
         },
 
         {
 
         {
 
             type: "map",
 
             type: "map",
 
             match: function (t) { return t instanceof Map; },
 
             match: function (t) { return t instanceof Map; },
             encode: function (m) { return JSON.stringify(__spreadArray([], m.entries())); },
+
             encode: function (m) { return JSON.stringify(__spreadArray([], __read(m.entries()), false)); },
             decode: function (m) { return new Map(JSON.parse(m)); },
+
             decode: function (m) { return new Map(JSON.parse(m)); }
 
         },
 
         },
 
         {
 
         {
 
             type: "regexp",
 
             type: "regexp",
 
             match: function (t) { return t instanceof RegExp; },
 
             match: function (t) { return t instanceof RegExp; },
             encode: function (r) { return "" + r; },
+
             encode: function (r) { return "".concat(r); },
             decode: function (r) { return new RegExp(r.slice(1, r.length - 1)); },
+
             decode: function (r) { return new RegExp(r.slice(1, r.length - 1)); }
 
         },
 
         },
 
     ];
 
     ];
     var LocalObjectStorage = /** @class */ (function () {
+
    var externalTransformations = [];
 +
     var LocalObjectStorage = (function () {
 
         function LocalObjectStorage(prefix) {
 
         function LocalObjectStorage(prefix) {
 
             if (prefix === void 0) { prefix = ""; }
 
             if (prefix === void 0) { prefix = ""; }
 +
            _LocalObjectStorage_instances.add(this);
 +
            _LocalObjectStorage_keyPrefix.set(this, void 0);
 
             if (prefix === "default") {
 
             if (prefix === "default") {
                 throw new Error("LocalObjectStorage can't accept prefix \"" + prefix + "\".");
+
                 throw new Error("LocalObjectStorage can't accept prefix \"".concat(prefix, "\"."));
 
             }
 
             }
 
             if (prefix.includes("/")) {
 
             if (prefix.includes("/")) {
                 throw new Error("LocalObjectStorage can't accept prefix \"" + prefix + "\" including \"/\".");
+
                 throw new Error("LocalObjectStorage can't accept prefix \"".concat(prefix, "\" including \"/\"."));
 
             }
 
             }
             this._keyPrefix = "AnnTool-localObjectStorage/" + ((prefix === null || prefix === void 0 ? void 0 : prefix.length) > 0 ? prefix + "/" : "");
+
             __classPrivateFieldSet(this, _LocalObjectStorage_keyPrefix, "AnnTool-localObjectStorage/".concat((prefix === null || prefix === void 0 ? void 0 : prefix.length) > 0 ? "".concat(prefix, "/") : "default/"), "f");
 
         }
 
         }
         LocalObjectStorage.prototype._getAllKeys = function () {
+
        Object.defineProperty(LocalObjectStorage.prototype, "_keyPrefix", {
 +
            get: function () {
 +
                return __classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f");
 +
            },
 +
            enumerable: false,
 +
            configurable: true
 +
        });
 +
         LocalObjectStorage.prototype.getAllKeys = function () {
 
             var _this = this;
 
             var _this = this;
             return Object.keys(localStorage).filter(function (key) { return key.startsWith(_this._keyPrefix); });
+
             return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).map(function (n) { return n.replace(__classPrivateFieldGet(_this, _LocalObjectStorage_keyPrefix, "f"), ""); });
 
         };
 
         };
 
         Object.defineProperty(LocalObjectStorage.prototype, "length", {
 
         Object.defineProperty(LocalObjectStorage.prototype, "length", {
 
             get: function () {
 
             get: function () {
                 return this._getAllKeys().length;
+
                 return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).length;
 
             },
 
             },
 
             enumerable: false,
 
             enumerable: false,
第69行: 第128行:
 
         });
 
         });
 
         LocalObjectStorage.prototype.getItem = function (key, fallback) {
 
         LocalObjectStorage.prototype.getItem = function (key, fallback) {
             var value = localStorage.getItem("" + this._keyPrefix + key);
+
            var e_1, _a;
 +
             var value = localStorage.getItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key));
 
             if (value === null) {
 
             if (value === null) {
 
                 return fallback || value;
 
                 return fallback || value;
 
             }
 
             }
             for (var _i = 0, _a = builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list); _i < _a.length; _i++) {
+
             try {
                var _b = _a[_i], type = _b.type, decode = _b.decode;
+
                for (var _b = __values(builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list)), _c = _b.next(); !_c.done; _c = _b.next()) {
                if (type.includes("|")) {
+
                    var _d = _c.value, type = _d.type, decode = _d.decode;
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\" including \"|\", skip...");
+
                    if (type.includes("|")) {
                    continue;
+
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
                }
+
                        continue;
                if (type === "JSON") {
+
                    }
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\", skip...");
+
                    if (type === "JSON") {
                    continue;
+
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
                }
+
                        continue;
                if (value.startsWith(type + "|")) {
 
                    try {
 
                        return decode(value.replace(type + "|", ""));
 
 
                     }
 
                     }
                     catch (e) {
+
                     if (value.startsWith("".concat(type, "|"))) {
                        console.error("LocalObjectStorage can's transform value of key \"" + key + "\" to type \"" + type + "\" and skip...");
+
                        try {
 +
                            return decode(value.replace("".concat(type, "|"), ""));
 +
                        }
 +
                        catch (_e) {
 +
                            console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" to type \"").concat(type, "\" and skip..."));
 +
                        }
 
                     }
 
                     }
 
                 }
 
                 }
 +
            }
 +
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
 +
            finally {
 +
                try {
 +
                    if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
 +
                }
 +
                finally { if (e_1) throw e_1.error; }
 
             }
 
             }
 
             try {
 
             try {
第96行: 第165行:
 
             }
 
             }
 
             catch (e) {
 
             catch (e) {
                 console.error("LocalObjectStorage can's transform value of key \"" + key + "\" to JSON and return raw value...");
+
                 console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" to JSON and return `undefined`..."), e);
                 return value;
+
                 return undefined;
 
             }
 
             }
 
         };
 
         };
 
         LocalObjectStorage.prototype.setItem = function (key, value) {
 
         LocalObjectStorage.prototype.setItem = function (key, value) {
             for (var _i = 0, _a = builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list); _i < _a.length; _i++) {
+
             var e_2, _a;
                var _b = _a[_i], type = _b.type, match = _b.match, encode = _b.encode;
+
            try {
                if (type.includes("|")) {
+
                for (var _b = __values(builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\" including \"|\", skip...");
+
                    var _d = _c.value, type = _d.type, match = _d.match, encode = _d.encode;
                    continue;
+
                    if (type.includes("|")) {
                }
+
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
                if (type === "JSON") {
+
                        continue;
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\", skip...");
+
                    }
                    continue;
+
                    if (type === "JSON") {
                }
+
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
                if (match(value)) {
+
                         continue;
                    try {
 
                        localStorage.setItem("" + this._keyPrefix + key, type + "|" + encode(value));
 
                         return;
 
 
                     }
 
                     }
                     catch (e) {
+
                     if (match(value)) {
                        console.error("LocalObjectStorage can's transform value of key \"" + key + "\" from type \"" + type + "\" and skip...");
+
                        try {
 +
                            localStorage.setItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key), "".concat(type, "|").concat(encode(value)));
 +
                            return;
 +
                        }
 +
                        catch (e) {
 +
                            console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" from type \"").concat(type, "\" and skip..."), e);
 +
                        }
 
                     }
 
                     }
 
                 }
 
                 }
 +
            }
 +
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
 +
            finally {
 +
                try {
 +
                    if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
 +
                }
 +
                finally { if (e_2) throw e_2.error; }
 
             }
 
             }
 
             try {
 
             try {
                 localStorage.setItem("" + this._keyPrefix + key, "JSON|" + JSON.stringify(value));
+
                 localStorage.setItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key), "JSON|".concat(JSON.stringify(value)));
 
                 return;
 
                 return;
 
             }
 
             }
 
             catch (e) {
 
             catch (e) {
                 console.error("LocalObjectStorage can's transform value of key \"" + key + "\" from JSON and store raw value...");
+
                 console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" from JSON and skip..."), e);
                localStorage.setItem("" + this._keyPrefix + key, value);
 
 
             }
 
             }
 
         };
 
         };
 
         LocalObjectStorage.prototype.removeItem = function (key) {
 
         LocalObjectStorage.prototype.removeItem = function (key) {
             localStorage.removeItem("" + this._keyPrefix + key);
+
             localStorage.removeItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key));
 
         };
 
         };
 
         LocalObjectStorage.prototype.clear = function () {
 
         LocalObjectStorage.prototype.clear = function () {
             this._getAllKeys().forEach(function (key) {
+
             __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).forEach(function (key) {
 
                 localStorage.removeItem(key);
 
                 localStorage.removeItem(key);
 
             });
 
             });
第140行: 第218行:
 
         };
 
         };
 
         LocalObjectStorage.prototype.key = function (index) {
 
         LocalObjectStorage.prototype.key = function (index) {
             return this._getAllKeys()[index];
+
             return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this)[index];
 +
        };
 +
        var _LocalObjectStorage_instances, _LocalObjectStorage_keyPrefix, _LocalObjectStorage_getAllKeys;
 +
        _LocalObjectStorage_keyPrefix = new WeakMap(), _LocalObjectStorage_instances = new WeakSet(), _LocalObjectStorage_getAllKeys = function _LocalObjectStorage_getAllKeys() {
 +
            var _this = this;
 +
            return Object.keys(localStorage).filter(function (key) { return key.startsWith(__classPrivateFieldGet(_this, _LocalObjectStorage_keyPrefix, "f")); });
 +
        };
 +
        LocalObjectStorage.plugins = {
 +
            transformations: {
 +
                get list() {
 +
                    return externalTransformations.map(function (transformation) { return Object.assign(Object.create(null), transformation); });
 +
                },
 +
                add: function (_a) {
 +
                    var type = _a.type, match = _a.match, decode = _a.decode, encode = _a.encode;
 +
                    if (type.includes("|")) {
 +
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
 +
                        return false;
 +
                    }
 +
                    if (["JSON"].includes(type)) {
 +
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
 +
                        return false;
 +
                    }
 +
                    if (__spreadArray(__spreadArray([], __read(builtinTransformations), false), __read(LocalObjectStorage.plugins.transformations.list), false).some(function (_a) {
 +
                        var eType = _a.type;
 +
                        return eType === type;
 +
                    })) {
 +
                        console.error("LocalObjectStorage can't accept duplicated type name \"".concat(type, "\", skip..."));
 +
                        return false;
 +
                    }
 +
                    if (typeof match !== "function" || typeof decode !== "function" || typeof encode !== "function") {
 +
                        console.error("LocalObjectStorage can't accept broken transformation [ type: \"".concat(type, "\", match: ").concat(typeof match, ", decode: ").concat(typeof decode, ", encode: ").concat(typeof encode, " ], skip..."));
 +
                        return false;
 +
                    }
 +
                    externalTransformations.push({ type: type, match: match, decode: decode, encode: encode });
 +
                    return true;
 +
                }
 +
            }
 
         };
 
         };
 
         return LocalObjectStorage;
 
         return LocalObjectStorage;
 
     }());
 
     }());
    var externalTransformations = [];
 
    LocalObjectStorage.plugins = {
 
        transformations: {
 
            get list() {
 
                return externalTransformations;
 
            },
 
            add: function (_a) {
 
                var type = _a.type, match = _a.match, decode = _a.decode, encode = _a.encode;
 
                if (type.includes("|")) {
 
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\" including \"|\", skip...");
 
                    return false;
 
                }
 
                if (type === "JSON") {
 
                    console.error("LocalObjectStorage can't accept type name \"" + type + "\", skip...");
 
                    return false;
 
                }
 
                if (builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list).filter(function (_a) {
 
                    var eType = _a.type;
 
                    return eType === type;
 
                }).length > 0) {
 
                    console.error("LocalObjectStorage can't accept duplicated type name \"" + type + "\", skip...");
 
                    return false;
 
                }
 
                if (typeof match !== "function" || typeof decode !== "function" || typeof encode !== "function") {
 
                    console.error("LocalObjectStorage can't accept broken transformation [ type: \"" + type + "\", match: " + typeof match + ", decode: " + typeof decode + ", encode: " + typeof encode + " ], skip...");
 
                    return false;
 
                }
 
                externalTransformations.push({ type: type, match: match, decode: decode, encode: encode });
 
                return true;
 
            },
 
        },
 
    };
 
 
     window.LocalObjectStorage = LocalObjectStorage;
 
     window.LocalObjectStorage = LocalObjectStorage;
})();
+
})();  
 +
 
 +
/* </pre> */

2024年4月16日 (二) 08:51的最新版本

/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LocalObjectStorage/MediaWiki:Gadget-LocalObjectStorage.js|user=[[U:星海子]]|co-authors=|longId=e1e15bf6ac13a6c997a9a3208dab7f70fa6a77fb|shortId=e1e15bf6|summary=chore: eslint}}'; 

/* <pre> */

"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
(function () {
    var builtinTransformations = [
        {
            type: "undefined",
            match: function (t) { return typeof t === "undefined"; },
            encode: function () { return "undefined"; },
            decode: function () { return undefined; }
        },
        {
            type: "bigint",
            match: function (t) { return typeof t === "bigint"; },
            encode: function (b) { return "".concat(b); },
            decode: function (b) { return BigInt(b); }
        },
        {
            type: "date",
            match: function (t) { return t instanceof Date; },
            encode: function (d) { return d.toISOString(); },
            decode: function (d) { return new Date(d); }
        },
        {
            type: "set",
            match: function (t) { return t instanceof Set; },
            encode: function (s) { return JSON.stringify(__spreadArray([], __read(s.values()), false)); },
            decode: function (s) { return new Set(JSON.parse(s)); }
        },
        {
            type: "map",
            match: function (t) { return t instanceof Map; },
            encode: function (m) { return JSON.stringify(__spreadArray([], __read(m.entries()), false)); },
            decode: function (m) { return new Map(JSON.parse(m)); }
        },
        {
            type: "regexp",
            match: function (t) { return t instanceof RegExp; },
            encode: function (r) { return "".concat(r); },
            decode: function (r) { return new RegExp(r.slice(1, r.length - 1)); }
        },
    ];
    var externalTransformations = [];
    var LocalObjectStorage = (function () {
        function LocalObjectStorage(prefix) {
            if (prefix === void 0) { prefix = ""; }
            _LocalObjectStorage_instances.add(this);
            _LocalObjectStorage_keyPrefix.set(this, void 0);
            if (prefix === "default") {
                throw new Error("LocalObjectStorage can't accept prefix \"".concat(prefix, "\"."));
            }
            if (prefix.includes("/")) {
                throw new Error("LocalObjectStorage can't accept prefix \"".concat(prefix, "\" including \"/\"."));
            }
            __classPrivateFieldSet(this, _LocalObjectStorage_keyPrefix, "AnnTool-localObjectStorage/".concat((prefix === null || prefix === void 0 ? void 0 : prefix.length) > 0 ? "".concat(prefix, "/") : "default/"), "f");
        }
        Object.defineProperty(LocalObjectStorage.prototype, "_keyPrefix", {
            get: function () {
                return __classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f");
            },
            enumerable: false,
            configurable: true
        });
        LocalObjectStorage.prototype.getAllKeys = function () {
            var _this = this;
            return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).map(function (n) { return n.replace(__classPrivateFieldGet(_this, _LocalObjectStorage_keyPrefix, "f"), ""); });
        };
        Object.defineProperty(LocalObjectStorage.prototype, "length", {
            get: function () {
                return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).length;
            },
            enumerable: false,
            configurable: true
        });
        LocalObjectStorage.prototype.getItem = function (key, fallback) {
            var e_1, _a;
            var value = localStorage.getItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key));
            if (value === null) {
                return fallback || value;
            }
            try {
                for (var _b = __values(builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var _d = _c.value, type = _d.type, decode = _d.decode;
                    if (type.includes("|")) {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
                        continue;
                    }
                    if (type === "JSON") {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
                        continue;
                    }
                    if (value.startsWith("".concat(type, "|"))) {
                        try {
                            return decode(value.replace("".concat(type, "|"), ""));
                        }
                        catch (_e) {
                            console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" to type \"").concat(type, "\" and skip..."));
                        }
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
            try {
                return JSON.parse(value.replace("JSON|", ""));
            }
            catch (e) {
                console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" to JSON and return `undefined`..."), e);
                return undefined;
            }
        };
        LocalObjectStorage.prototype.setItem = function (key, value) {
            var e_2, _a;
            try {
                for (var _b = __values(builtinTransformations.concat(LocalObjectStorage.plugins.transformations.list)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var _d = _c.value, type = _d.type, match = _d.match, encode = _d.encode;
                    if (type.includes("|")) {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
                        continue;
                    }
                    if (type === "JSON") {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
                        continue;
                    }
                    if (match(value)) {
                        try {
                            localStorage.setItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key), "".concat(type, "|").concat(encode(value)));
                            return;
                        }
                        catch (e) {
                            console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" from type \"").concat(type, "\" and skip..."), e);
                        }
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
                }
                finally { if (e_2) throw e_2.error; }
            }
            try {
                localStorage.setItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key), "JSON|".concat(JSON.stringify(value)));
                return;
            }
            catch (e) {
                console.error("LocalObjectStorage can's transform value of key \"".concat(key, "\" from JSON and skip..."), e);
            }
        };
        LocalObjectStorage.prototype.removeItem = function (key) {
            localStorage.removeItem("".concat(__classPrivateFieldGet(this, _LocalObjectStorage_keyPrefix, "f")).concat(key));
        };
        LocalObjectStorage.prototype.clear = function () {
            __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this).forEach(function (key) {
                localStorage.removeItem(key);
            });
            this.length = 0;
        };
        LocalObjectStorage.prototype.key = function (index) {
            return __classPrivateFieldGet(this, _LocalObjectStorage_instances, "m", _LocalObjectStorage_getAllKeys).call(this)[index];
        };
        var _LocalObjectStorage_instances, _LocalObjectStorage_keyPrefix, _LocalObjectStorage_getAllKeys;
        _LocalObjectStorage_keyPrefix = new WeakMap(), _LocalObjectStorage_instances = new WeakSet(), _LocalObjectStorage_getAllKeys = function _LocalObjectStorage_getAllKeys() {
            var _this = this;
            return Object.keys(localStorage).filter(function (key) { return key.startsWith(__classPrivateFieldGet(_this, _LocalObjectStorage_keyPrefix, "f")); });
        };
        LocalObjectStorage.plugins = {
            transformations: {
                get list() {
                    return externalTransformations.map(function (transformation) { return Object.assign(Object.create(null), transformation); });
                },
                add: function (_a) {
                    var type = _a.type, match = _a.match, decode = _a.decode, encode = _a.encode;
                    if (type.includes("|")) {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\" including \"|\", skip..."));
                        return false;
                    }
                    if (["JSON"].includes(type)) {
                        console.error("LocalObjectStorage can't accept type name \"".concat(type, "\", skip..."));
                        return false;
                    }
                    if (__spreadArray(__spreadArray([], __read(builtinTransformations), false), __read(LocalObjectStorage.plugins.transformations.list), false).some(function (_a) {
                        var eType = _a.type;
                        return eType === type;
                    })) {
                        console.error("LocalObjectStorage can't accept duplicated type name \"".concat(type, "\", skip..."));
                        return false;
                    }
                    if (typeof match !== "function" || typeof decode !== "function" || typeof encode !== "function") {
                        console.error("LocalObjectStorage can't accept broken transformation [ type: \"".concat(type, "\", match: ").concat(typeof match, ", decode: ").concat(typeof decode, ", encode: ").concat(typeof encode, " ], skip..."));
                        return false;
                    }
                    externalTransformations.push({ type: type, match: match, decode: decode, encode: encode });
                    return true;
                }
            }
        };
        return LocalObjectStorage;
    }());
    window.LocalObjectStorage = LocalObjectStorage;
})(); 

/* </pre> */