unicode-input-toolconverter 0.2.0 → 0.2.3
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/.nyc_output/out.json +8980 -1849
- package/CHANGES.md +15 -1
- package/README.md +6 -11
- package/_locales/en-US/messages.json +153 -6
- package/_locales/hu-HU/messages.json +153 -6
- package/_locales/pt-BR/messages.json +153 -6
- package/_locales/sv-SE/messages.json +153 -6
- package/babel.config.json +0 -1
- package/browser_action/characterSelection.js +18 -11
- package/browser_action/charrefConverters.js +286 -79
- package/browser_action/chartBuild.js +97 -27
- package/browser_action/encodingBehaviors.js +10 -7
- package/browser_action/entityBehaviors.js +42 -16
- package/browser_action/index-es.html +13 -1
- package/browser_action/index-instrumented.html +13 -1
- package/browser_action/index-pages.html +13 -1
- package/browser_action/index.html +13 -1
- package/browser_action/index.iife.min.js +9 -1
- package/browser_action/index.iife.min.js.map +1 -1
- package/browser_action/index.instrumented.iife.min.js +1 -1
- package/browser_action/index.instrumented.iife.min.js.map +1 -1
- package/browser_action/index.js +5 -5
- package/browser_action/preferences/prefDefaults.js +12 -3
- package/browser_action/service-worker/sw-activateCallback.js +1 -2
- package/browser_action/service-worker/sw-resources.json +6 -4
- package/browser_action/templateUtils/elements.js +12 -1
- package/browser_action/templateUtils/fill.js +6 -0
- package/browser_action/templateUtils/validation.js +4 -1
- package/browser_action/templates/chartBuild.js +167 -102
- package/browser_action/templates/index.js +227 -53
- package/browser_action/templatesElementCustomization/widgets.js +40 -15
- package/browser_action/unicode/UnicodeConverter.js +99 -73
- package/browser_action/unicode/charrefunicodeDb.js +100 -50
- package/browser_action/unicode/getScriptInfoForCodePoint.js +13 -4
- package/browser_action/unicode/hangul.js +27 -20
- package/browser_action/unicode/lastScriptNames.json +1 -1
- package/browser_action/unicode/parseUnihanFromTextFileStrings.js +44 -25
- package/browser_action/unicode/unicodeFieldInfo.js +112 -90
- package/browser_action/unicode/unicodeScripts.js +409 -35
- package/browser_action/unicode/unihan.js +4 -3
- package/browser_action/unicode/unihanDbPopulate.js +7 -2
- package/browser_action/unicode/unihanFields.js +34 -0
- package/browser_action/unicodecharref.js +353 -190
- package/browser_action/utils/DOMUtils.js +95 -34
- package/browser_action/utils/FetchUtils.js +7 -6
- package/browser_action/utils/TextUtils.js +4 -4
- package/browser_action/utils/TypedArrayUtils.js +9 -5
- package/browser_action/utils/semicolonSeparatedToArray.js +3 -3
- package/browser_action/utils/setupServiceWorker.js +2 -2
- package/eslint.config.js +11 -0
- package/icons/openWindow16.png +0 -0
- package/icons/openWindow24.png +0 -0
- package/lib/background.html +7 -0
- package/lib/background.js +2 -2
- package/package.json +80 -70
- package/pnpm-workspace.yaml +8 -0
- package/server.js +66 -51
- package/sw.js +97 -56
- package/tools/entities-import.js +4 -1
- package/tools/findEsResources.js +33 -10
- package/tools/fix-sw-resources-vendor-paths.js +60 -0
- package/tools/list-locales.js +2 -2
- package/tools/parseUnicodeCharts.js +126 -60
- package/tools/ucd-import.js +1 -10
- package/tools/unicode-charts.html +49 -20
- package/tools/unihan-import.js +45 -15
- package/tools/write-sw-version.js +16 -0
- package/tsconfig.json +23 -0
- package/typings/__coverage__.d.ts +5 -0
- package/typings/apple-system-profiler.d.ts +17 -0
- package/typings/commands.d.ts +19 -0
- package/typings/json-6.d.ts +4 -0
- package/typings/rollup-plugin-istanbul.d.ts +3 -0
- package/vendor/camelcase/index.d.ts +154 -0
- package/vendor/camelcase/index.js +137 -23
- package/vendor/fflate/esm/browser.d.ts +1539 -0
- package/vendor/fflate/esm/browser.js +82 -55
- package/vendor/intl-dom/dist/Formatter.d.ts +120 -0
- package/vendor/intl-dom/dist/Formatter.d.ts.map +1 -0
- package/vendor/intl-dom/dist/collation.d.ts +42 -0
- package/vendor/intl-dom/dist/collation.d.ts.map +1 -0
- package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts +52 -0
- package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts.map +1 -0
- package/vendor/intl-dom/dist/defaultInsertNodes.d.ts +96 -0
- package/vendor/intl-dom/dist/defaultInsertNodes.d.ts.map +1 -0
- package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts +17 -0
- package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts.map +1 -0
- package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts +285 -0
- package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts.map +1 -0
- package/vendor/intl-dom/dist/findLocaleStrings.d.ts +88 -0
- package/vendor/intl-dom/dist/findLocaleStrings.d.ts.map +1 -0
- package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts +67 -0
- package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts.map +1 -0
- package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts +73 -0
- package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts.map +1 -0
- package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts +26 -0
- package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts.map +1 -0
- package/vendor/intl-dom/dist/i18n.d.ts +113 -0
- package/vendor/intl-dom/dist/i18n.d.ts.map +1 -0
- package/vendor/intl-dom/dist/index.d.ts +92 -0
- package/vendor/intl-dom/dist/index.d.ts.map +1 -0
- package/vendor/intl-dom/dist/index.esm.d.ts +34 -0
- package/vendor/intl-dom/dist/index.esm.js +854 -896
- package/vendor/intl-dom/dist/index.esm.min.js +4 -0
- package/vendor/intl-dom/dist/index.esm.min.js.map +1 -0
- package/vendor/intl-dom/dist/index.umd.js +2953 -0
- package/vendor/intl-dom/dist/index.umd.min.js +4 -0
- package/vendor/intl-dom/dist/index.umd.min.js.map +1 -0
- package/vendor/intl-dom/dist/promiseChainForValues.d.ts +34 -0
- package/vendor/intl-dom/dist/promiseChainForValues.d.ts.map +1 -0
- package/vendor/intl-dom/dist/shared.d.ts +20 -0
- package/vendor/intl-dom/dist/shared.d.ts.map +1 -0
- package/vendor/intl-dom/dist/utils.d.ts +53 -0
- package/vendor/intl-dom/dist/utils.d.ts.map +1 -0
- package/vendor/jamilih/dist/jml.d.mts +468 -0
- package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +1489 -343
- package/vendor/jquery/dist/jquery.js +1677 -2713
- package/vendor/json-6/dist/index.mjs +2 -0
- package/vendor/miller-columns/CHANGES.md +185 -0
- package/vendor/miller-columns/LICENSE-MIT.txt +21 -0
- package/vendor/miller-columns/README.md +249 -0
- package/vendor/miller-columns/demos/index.html +69 -0
- package/vendor/miller-columns/demos/index.js +72 -0
- package/vendor/miller-columns/dist/index-es.js +748 -0
- package/vendor/miller-columns/dist/index-es.min.d.ts +25 -0
- package/vendor/miller-columns/dist/index-es.min.js +7 -1
- package/vendor/miller-columns/dist/index-umd.js +757 -0
- package/vendor/miller-columns/dist/index-umd.min.js +7 -0
- package/vendor/miller-columns/dist/index.d.ts +25 -0
- package/vendor/miller-columns/dist/millerColumns.d.ts +10 -0
- package/vendor/miller-columns/eslint.config.js +46 -0
- package/vendor/miller-columns/fix-declarations.js +18 -0
- package/vendor/miller-columns/miller-columns.css +24 -1
- package/vendor/miller-columns/package.json +73 -0
- package/vendor/miller-columns/pnpm-workspace.yaml +2 -0
- package/vendor/miller-columns/src/index.js +642 -0
- package/vendor/miller-columns/src/millerColumns.ts +12 -0
- package/vendor/miller-columns/tsconfig-prod.json +23 -0
- package/vendor/miller-columns/tsconfig.json +21 -0
- package/vendor/simple-prefs/dist/index.esm.d.ts +1 -0
- package/vendor/simple-prefs/dist/index.esm.js +164 -216
- package/vendor/simple-prefs/dist/simple-prefs.d.ts +117 -0
- package/lgtm.yml +0 -5
|
@@ -1,47 +1,18 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _defineProperties(target, props) {
|
|
7
|
-
for (var i = 0; i < props.length; i++) {
|
|
8
|
-
var descriptor = props[i];
|
|
9
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
-
descriptor.configurable = true;
|
|
11
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
19
|
-
writable: false
|
|
20
|
-
});
|
|
21
|
-
return Constructor;
|
|
22
|
-
}
|
|
23
|
-
function _toPrimitive(input, hint) {
|
|
24
|
-
if (typeof input !== "object" || input === null) return input;
|
|
25
|
-
var prim = input[Symbol.toPrimitive];
|
|
26
|
-
if (prim !== undefined) {
|
|
27
|
-
var res = prim.call(input, hint || "default");
|
|
28
|
-
if (typeof res !== "object") return res;
|
|
29
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
30
|
-
}
|
|
31
|
-
return (hint === "string" ? String : Number)(input);
|
|
32
|
-
}
|
|
33
|
-
function _toPropertyKey(arg) {
|
|
34
|
-
var key = _toPrimitive(arg, "string");
|
|
35
|
-
return typeof key === "symbol" ? key : String(key);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
1
|
/**
|
|
39
|
-
* @typedef {{[key: string]:
|
|
40
|
-
*/
|
|
2
|
+
* @typedef {{[key: string]: JSONValue}} Defaults
|
|
3
|
+
*/
|
|
41
4
|
|
|
42
5
|
/**
|
|
43
|
-
* @typedef {boolean|number|string}
|
|
44
|
-
*/
|
|
6
|
+
* @typedef {null|boolean|number|string} JSONPrimitive
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {JSONValue[]} JSONArray
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {JSONPrimitive | JSONArray | {
|
|
13
|
+
* [key in string]: JSONValue
|
|
14
|
+
* }} JSONValue
|
|
15
|
+
*/
|
|
45
16
|
|
|
46
17
|
/**
|
|
47
18
|
* Preferences storage.
|
|
@@ -60,15 +31,23 @@ function _await(value, then, direct) {
|
|
|
60
31
|
/**
|
|
61
32
|
* Defaults for SimplePrefs.
|
|
62
33
|
*/
|
|
63
|
-
|
|
34
|
+
|
|
35
|
+
function _call(body, then, direct) {
|
|
36
|
+
try {
|
|
37
|
+
var result = Promise.resolve(body());
|
|
38
|
+
return then ? result.then(then) : result;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return Promise.reject(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class SimplePrefs {
|
|
64
44
|
/**
|
|
65
45
|
* @param {object} cfg
|
|
66
46
|
* @param {string} [cfg.namespace] Avoid clashes with other apps
|
|
67
47
|
* @param {Defaults} [cfg.defaults]
|
|
68
48
|
* @param {SimplePrefsDefaults} [cfg.prefDefaults]
|
|
69
49
|
*/
|
|
70
|
-
|
|
71
|
-
_classCallCheck(this, SimplePrefs);
|
|
50
|
+
constructor(cfg) {
|
|
72
51
|
this.configurePrefs(cfg);
|
|
73
52
|
|
|
74
53
|
/** @type {((e: StorageEvent) => void)[]} */
|
|
@@ -81,205 +60,174 @@ var SimplePrefs = /*#__PURE__*/function () {
|
|
|
81
60
|
* @param {SimplePrefsDefaults} [cfg.prefDefaults]
|
|
82
61
|
* @returns {void}
|
|
83
62
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* value (defaulting if necessary)
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
/** @type {GetPref} */
|
|
104
|
-
}, {
|
|
105
|
-
key: "getPref",
|
|
106
|
-
value: function getPref(key) {
|
|
107
|
-
try {
|
|
108
|
-
var _this = this;
|
|
109
|
-
var result = localStorage.getItem(_this.namespace + key);
|
|
110
|
-
return _await(_await(result === null ? /** @type {SimplePrefsDefaults} */_this.prefDefaults.getPrefDefault(key) : JSON.parse(result), void 0, !(result === null)));
|
|
111
|
-
} catch (e) {
|
|
112
|
-
return Promise.reject(e);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Set a stringifiable preference value; returns `Promise` in anticipation
|
|
117
|
-
* of https://domenic.github.io/async-local-storage/ .
|
|
118
|
-
* @callback SetPref
|
|
119
|
-
* @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
|
|
120
|
-
* @param {Value} val Stringifiable value
|
|
121
|
-
* @returns {Promise<void>} Resolves after setting the item (Not currently
|
|
122
|
-
* in use)
|
|
123
|
-
*/
|
|
124
|
-
/** @type {SetPref} */
|
|
125
|
-
}, {
|
|
126
|
-
key: "setPref",
|
|
127
|
-
value: function setPref(key, val) {
|
|
128
|
-
try {
|
|
129
|
-
var _this2 = this;
|
|
130
|
-
return _await(localStorage.setItem(_this2.namespace + key, JSON.stringify(val)));
|
|
131
|
-
} catch (e) {
|
|
132
|
-
return Promise.reject(e);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @typedef {object} GetPrefSetPref
|
|
137
|
-
* @property {GetPref} getPref
|
|
138
|
-
* @property {SetPref} setPref
|
|
139
|
-
*/
|
|
140
|
-
/**
|
|
141
|
-
* Convenience utility to return two main methods `getPref` and
|
|
142
|
-
* `setPref` bound to the current object.
|
|
143
|
-
* @returns {GetPrefSetPref}
|
|
144
|
-
*/
|
|
145
|
-
}, {
|
|
146
|
-
key: "bind",
|
|
147
|
-
value: function bind() {
|
|
148
|
-
return {
|
|
149
|
-
getPref: this.getPref.bind(this),
|
|
150
|
-
setPref: this.setPref.bind(this)
|
|
151
|
-
};
|
|
152
|
-
}
|
|
63
|
+
configurePrefs({
|
|
64
|
+
namespace,
|
|
65
|
+
defaults,
|
|
66
|
+
prefDefaults = simplePrefsDefaults(defaults)
|
|
67
|
+
}) {
|
|
68
|
+
this.namespace = namespace ?? '';
|
|
69
|
+
this.prefDefaults = prefDefaults;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get parsed preference value; returns `Promise` in anticipation
|
|
73
|
+
* of https://domenic.github.io/async-local-storage/ .
|
|
74
|
+
* @callback GetPref
|
|
75
|
+
* @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
|
|
76
|
+
* @returns {Promise<JSONValue>} Resolves to the parsed
|
|
77
|
+
* value (defaulting if necessary)
|
|
78
|
+
*/
|
|
153
79
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
80
|
+
/** @type {GetPref} */
|
|
81
|
+
getPref(key) {
|
|
82
|
+
const _this = this;
|
|
83
|
+
return _call(function () {
|
|
84
|
+
const result = localStorage.getItem(_this.namespace + key);
|
|
85
|
+
return _await(_await(result === null ? /** @type {SimplePrefsDefaults} */_this.prefDefaults.getPrefDefault(key) : JSON.parse(result), void 0, !(result === null)));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set a stringifiable preference value; returns `Promise` in anticipation
|
|
90
|
+
* of https://domenic.github.io/async-local-storage/ .
|
|
91
|
+
* @callback SetPref
|
|
92
|
+
* @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
|
|
93
|
+
* @param {JSONValue} val Stringifiable value
|
|
94
|
+
* @returns {Promise<void>} Resolves after setting the item (Not currently
|
|
95
|
+
* in use)
|
|
96
|
+
*/
|
|
97
|
+
/** @type {SetPref} */
|
|
98
|
+
setPref(key, val) {
|
|
99
|
+
const _this2 = this;
|
|
100
|
+
return _call(function () {
|
|
101
|
+
return _await(localStorage.setItem(_this2.namespace + key, JSON.stringify(val)));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @typedef {object} GetPrefSetPref
|
|
106
|
+
* @property {GetPref} getPref
|
|
107
|
+
* @property {SetPref} setPref
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Convenience utility to return two main methods `getPref` and
|
|
111
|
+
* `setPref` bound to the current object.
|
|
112
|
+
* @returns {GetPrefSetPref}
|
|
113
|
+
*/
|
|
114
|
+
bind() {
|
|
115
|
+
return {
|
|
116
|
+
getPref: this.getPref.bind(this),
|
|
117
|
+
setPref: this.setPref.bind(this)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
159
120
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*/
|
|
166
|
-
}, {
|
|
167
|
-
key: "listen",
|
|
168
|
-
value: function listen(key, cb) {
|
|
169
|
-
var _this3 = this;
|
|
170
|
-
if (typeof key === 'function') {
|
|
171
|
-
cb = key;
|
|
172
|
-
key = undefined;
|
|
173
|
-
}
|
|
121
|
+
/**
|
|
122
|
+
* @callback PreferenceCallback
|
|
123
|
+
* @param {StorageEvent} e
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
174
126
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} else {
|
|
186
|
-
if (!e.key.startsWith( /** @type {string} */_this3.namespace)) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (key !== undefined && !e.key.startsWith( /** @type {string} */_this3.namespace + key)) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
cb(e);
|
|
194
|
-
};
|
|
195
|
-
window.addEventListener('storage', listener);
|
|
196
|
-
this.listeners.push(listener);
|
|
197
|
-
return listener;
|
|
127
|
+
/* eslint-disable promise/prefer-await-to-callbacks -- Repeating event */
|
|
128
|
+
/**
|
|
129
|
+
* @param {string|PreferenceCallback|undefined} key
|
|
130
|
+
* @param {PreferenceCallback} cb
|
|
131
|
+
* @returns {PreferenceCallback}
|
|
132
|
+
*/
|
|
133
|
+
listen(key, cb) {
|
|
134
|
+
if (typeof key === 'function') {
|
|
135
|
+
cb = key;
|
|
136
|
+
key = undefined;
|
|
198
137
|
}
|
|
199
138
|
|
|
200
139
|
/**
|
|
201
|
-
* @param {
|
|
202
|
-
* @returns {void}
|
|
140
|
+
* @param {StorageEvent} e
|
|
203
141
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
142
|
+
const listener = e => {
|
|
143
|
+
if (e.key === null) {
|
|
144
|
+
// `null` for clear browser action or user `clear()`
|
|
145
|
+
if (key === undefined) {
|
|
146
|
+
// Only trigger when no key supplied
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
if (!e.key.startsWith(/** @type {string} */this.namespace)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (key !== undefined && !e.key.startsWith(/** @type {string} */this.namespace + key)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
cb(e);
|
|
158
|
+
};
|
|
159
|
+
globalThis.addEventListener('storage', listener);
|
|
160
|
+
this.listeners.push(listener);
|
|
161
|
+
return listener;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param {EventListener} listener
|
|
166
|
+
* @returns {void}
|
|
167
|
+
*/
|
|
168
|
+
unlisten(listener) {
|
|
169
|
+
if (listener) {
|
|
170
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
171
|
+
if (listener === this.listeners[i]) {
|
|
172
|
+
this.listeners.splice(i, 1);
|
|
173
|
+
globalThis.removeEventListener('storage', listener);
|
|
174
|
+
return;
|
|
214
175
|
}
|
|
215
176
|
}
|
|
216
|
-
this.listeners.forEach(function (listenerItem) {
|
|
217
|
-
window.removeEventListener('storage', listenerItem);
|
|
218
|
-
});
|
|
219
177
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
178
|
+
this.listeners.forEach(listenerItem => {
|
|
179
|
+
globalThis.removeEventListener('storage', listenerItem);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/* eslint-enable promise/prefer-await-to-callbacks -- Repeating event */
|
|
183
|
+
}
|
|
184
|
+
class SimplePrefsDefaults {
|
|
225
185
|
/**
|
|
226
186
|
*
|
|
227
187
|
* @param {{defaults: Defaults}} defaults
|
|
228
188
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
189
|
+
constructor({
|
|
190
|
+
defaults
|
|
191
|
+
}) {
|
|
232
192
|
this.defaults = defaults;
|
|
233
193
|
}
|
|
234
194
|
/**
|
|
235
195
|
* Get parsed default value for a preference.
|
|
236
196
|
* @param {string} key Preference key
|
|
237
|
-
* @returns {Promise<
|
|
197
|
+
* @returns {Promise<JSONValue>}
|
|
238
198
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
var _this5 = this;
|
|
263
|
-
var oldValue = (_this5$defaults$key = _this5.defaults[key]) !== null && _this5$defaults$key !== void 0 ? _this5$defaults$key : null;
|
|
264
|
-
_this5.defaults[key] = value;
|
|
265
|
-
return _await(oldValue);
|
|
266
|
-
} catch (e) {
|
|
267
|
-
return Promise.reject(e);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}]);
|
|
271
|
-
return SimplePrefsDefaults;
|
|
272
|
-
}();
|
|
199
|
+
getPrefDefault(key) {
|
|
200
|
+
const _this3 = this;
|
|
201
|
+
return _call(function () {
|
|
202
|
+
return _await(_this3.defaults[key], function (_this3$defaults$key) {
|
|
203
|
+
return _this3$defaults$key ?? null;
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Set parsed default value for a preference.
|
|
209
|
+
* @param {string} key Preference key
|
|
210
|
+
* @param {JSONValue} value
|
|
211
|
+
* @returns {Promise<JSONValue>} The old value
|
|
212
|
+
*/
|
|
213
|
+
setPrefDefault(key, value) {
|
|
214
|
+
const _this4 = this;
|
|
215
|
+
return _call(function () {
|
|
216
|
+
const oldValue = _this4.defaults[key] ?? null;
|
|
217
|
+
_this4.defaults[key] = value;
|
|
218
|
+
return _await(oldValue);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
273
222
|
|
|
274
223
|
/**
|
|
275
224
|
* Simplified factory for `SimplePrefsDefaults`
|
|
276
225
|
* @param {Defaults} [defaults]
|
|
277
226
|
* @returns {SimplePrefsDefaults}
|
|
278
227
|
*/
|
|
279
|
-
function simplePrefsDefaults() {
|
|
280
|
-
var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
228
|
+
function simplePrefsDefaults(defaults = {}) {
|
|
281
229
|
return new SimplePrefsDefaults({
|
|
282
|
-
defaults
|
|
230
|
+
defaults
|
|
283
231
|
});
|
|
284
232
|
}
|
|
285
233
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simplified factory for `SimplePrefsDefaults`
|
|
3
|
+
* @param {Defaults} [defaults]
|
|
4
|
+
* @returns {SimplePrefsDefaults}
|
|
5
|
+
*/
|
|
6
|
+
export function simplePrefsDefaults(defaults?: Defaults): SimplePrefsDefaults;
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{[key: string]: JSONValue}} Defaults
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {null|boolean|number|string} JSONPrimitive
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {JSONValue[]} JSONArray
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {JSONPrimitive | JSONArray | {
|
|
18
|
+
* [key in string]: JSONValue
|
|
19
|
+
* }} JSONValue
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Preferences storage.
|
|
23
|
+
*/
|
|
24
|
+
export class SimplePrefs {
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} cfg
|
|
27
|
+
* @param {string} [cfg.namespace] Avoid clashes with other apps
|
|
28
|
+
* @param {Defaults} [cfg.defaults]
|
|
29
|
+
* @param {SimplePrefsDefaults} [cfg.prefDefaults]
|
|
30
|
+
*/
|
|
31
|
+
constructor(cfg: {
|
|
32
|
+
namespace?: string | undefined;
|
|
33
|
+
defaults?: Defaults | undefined;
|
|
34
|
+
prefDefaults?: SimplePrefsDefaults | undefined;
|
|
35
|
+
});
|
|
36
|
+
/** @type {((e: StorageEvent) => void)[]} */
|
|
37
|
+
listeners: ((e: StorageEvent) => void)[];
|
|
38
|
+
/**
|
|
39
|
+
* @param {object} cfg
|
|
40
|
+
* @param {string} [cfg.namespace] Avoid clashes with other apps
|
|
41
|
+
* @param {Defaults} [cfg.defaults]
|
|
42
|
+
* @param {SimplePrefsDefaults} [cfg.prefDefaults]
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
45
|
+
configurePrefs({ namespace, defaults, prefDefaults }: {
|
|
46
|
+
namespace?: string | undefined;
|
|
47
|
+
defaults?: Defaults | undefined;
|
|
48
|
+
prefDefaults?: SimplePrefsDefaults | undefined;
|
|
49
|
+
}): void;
|
|
50
|
+
namespace: string | undefined;
|
|
51
|
+
prefDefaults: SimplePrefsDefaults | undefined;
|
|
52
|
+
getPref(key: string): Promise<JSONValue>;
|
|
53
|
+
setPref(key: string, val: JSONValue): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} GetPrefSetPref
|
|
56
|
+
* @property {GetPref} getPref
|
|
57
|
+
* @property {SetPref} setPref
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Convenience utility to return two main methods `getPref` and
|
|
61
|
+
* `setPref` bound to the current object.
|
|
62
|
+
* @returns {GetPrefSetPref}
|
|
63
|
+
*/
|
|
64
|
+
bind(): {
|
|
65
|
+
getPref: (key: string) => Promise<JSONValue>;
|
|
66
|
+
setPref: (key: string, val: JSONValue) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* @callback PreferenceCallback
|
|
70
|
+
* @param {StorageEvent} e
|
|
71
|
+
* @returns {void}
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* @param {string|PreferenceCallback|undefined} key
|
|
75
|
+
* @param {PreferenceCallback} cb
|
|
76
|
+
* @returns {PreferenceCallback}
|
|
77
|
+
*/
|
|
78
|
+
listen(key: string | ((e: StorageEvent) => void) | undefined, cb: (e: StorageEvent) => void): (e: StorageEvent) => void;
|
|
79
|
+
/**
|
|
80
|
+
* @param {EventListener} listener
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
unlisten(listener: EventListener): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Defaults for SimplePrefs.
|
|
87
|
+
*/
|
|
88
|
+
export class SimplePrefsDefaults {
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {{defaults: Defaults}} defaults
|
|
92
|
+
*/
|
|
93
|
+
constructor({ defaults }: {
|
|
94
|
+
defaults: Defaults;
|
|
95
|
+
});
|
|
96
|
+
defaults: Defaults;
|
|
97
|
+
/**
|
|
98
|
+
* Get parsed default value for a preference.
|
|
99
|
+
* @param {string} key Preference key
|
|
100
|
+
* @returns {Promise<JSONValue>}
|
|
101
|
+
*/
|
|
102
|
+
getPrefDefault(key: string): Promise<JSONValue>;
|
|
103
|
+
/**
|
|
104
|
+
* Set parsed default value for a preference.
|
|
105
|
+
* @param {string} key Preference key
|
|
106
|
+
* @param {JSONValue} value
|
|
107
|
+
* @returns {Promise<JSONValue>} The old value
|
|
108
|
+
*/
|
|
109
|
+
setPrefDefault(key: string, value: JSONValue): Promise<JSONValue>;
|
|
110
|
+
}
|
|
111
|
+
export type Defaults = {
|
|
112
|
+
[key: string]: JSONValue;
|
|
113
|
+
};
|
|
114
|
+
export type JSONPrimitive = null | boolean | number | string;
|
|
115
|
+
export type JSONArray = JSONValue[];
|
|
116
|
+
export type JSONValue = JSONPrimitive | JSONArray | { [key in string]: JSONValue; };
|
|
117
|
+
//# sourceMappingURL=simple-prefs.d.ts.map
|