unicode-input-toolconverter 0.2.0
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/.babelrc.json +3 -0
- package/.editorconfig +16 -0
- package/.nojekyll +0 -0
- package/.nyc_output/out.json +173804 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/CHANGES.md +11 -0
- package/COPYING.LESSER.txt +180 -0
- package/COPYING.txt +687 -0
- package/README.md +65 -0
- package/_locales/en-US/messages.json +3126 -0
- package/_locales/hu-HU/messages.json +3126 -0
- package/_locales/pt-BR/messages.json +3126 -0
- package/_locales/sv-SE/messages.json +3126 -0
- package/babel.config.json +5 -0
- package/browser_action/characterSelection.js +91 -0
- package/browser_action/charrefConverters.js +389 -0
- package/browser_action/chartBuild.js +155 -0
- package/browser_action/encodingBehaviors.js +72 -0
- package/browser_action/encodings.js +97 -0
- package/browser_action/entities.js +12 -0
- package/browser_action/entityBehaviors.js +96 -0
- package/browser_action/index-es.html +15 -0
- package/browser_action/index-instrumented.html +16 -0
- package/browser_action/index-pages.html +16 -0
- package/browser_action/index.html +16 -0
- package/browser_action/index.iife.min.js +2 -0
- package/browser_action/index.iife.min.js.map +1 -0
- package/browser_action/index.instrumented.iife.min.js +2 -0
- package/browser_action/index.instrumented.iife.min.js.map +1 -0
- package/browser_action/index.js +95 -0
- package/browser_action/preferences/prefDefaults.js +52 -0
- package/browser_action/service-worker/sw-activateCallback.js +53 -0
- package/browser_action/service-worker/sw-locales.json +6 -0
- package/browser_action/service-worker/sw-resources.json +73 -0
- package/browser_action/service-worker/sw-unicode-data.json +3 -0
- package/browser_action/styles/unicode-dialog.css +391 -0
- package/browser_action/templateUtils/elements.js +12 -0
- package/browser_action/templateUtils/fill.js +3 -0
- package/browser_action/templateUtils/validation.js +6 -0
- package/browser_action/templates/chartBuild.js +185 -0
- package/browser_action/templates/index.js +1304 -0
- package/browser_action/templatesElementCustomization/widgets.js +56 -0
- package/browser_action/unicode/UnicodeConverter.js +793 -0
- package/browser_action/unicode/charrefunicodeDb.js +258 -0
- package/browser_action/unicode/getScriptInfoForCodePoint.js +646 -0
- package/browser_action/unicode/hangul.js +253 -0
- package/browser_action/unicode/lastScriptNames.json +5 -0
- package/browser_action/unicode/parseUnihanFromTextFileStrings.js +56 -0
- package/browser_action/unicode/unicodeFieldInfo.js +120 -0
- package/browser_action/unicode/unicodeScripts.js +4912 -0
- package/browser_action/unicode/unihan.js +129 -0
- package/browser_action/unicode/unihanDbPopulate.js +26 -0
- package/browser_action/unicodecharref.js +1480 -0
- package/browser_action/utils/DOMUtils.js +122 -0
- package/browser_action/utils/FetchUtils.js +19 -0
- package/browser_action/utils/TextUtils.js +28 -0
- package/browser_action/utils/TypedArrayUtils.js +21 -0
- package/browser_action/utils/semicolonSeparatedToArray.js +12 -0
- package/browser_action/utils/setupServiceWorker.js +193 -0
- package/cypress.config.js +21 -0
- package/download/entities/copyright-software-20021231.html +70 -0
- package/download/entities/html5-uppercase.ent +54 -0
- package/download/entities/htmlmathml-f.ent +2164 -0
- package/download/entities/isoamsa.ent +201 -0
- package/download/entities/isoamsb.ent +177 -0
- package/download/entities/isoamsc.ent +77 -0
- package/download/entities/isoamsn.ent +148 -0
- package/download/entities/isoamso.ent +107 -0
- package/download/entities/isoamsr.ent +238 -0
- package/download/entities/isobox.ent +95 -0
- package/download/entities/isocyr1.ent +122 -0
- package/download/entities/isocyr2.ent +81 -0
- package/download/entities/isodia.ent +69 -0
- package/download/entities/isogrk1.ent +104 -0
- package/download/entities/isogrk2.ent +75 -0
- package/download/entities/isogrk3.ent +98 -0
- package/download/entities/isogrk4.ent +98 -0
- package/download/entities/isolat1.ent +117 -0
- package/download/entities/isolat2.ent +176 -0
- package/download/entities/isomfrk.ent +107 -0
- package/download/entities/isomopf.ent +81 -0
- package/download/entities/isomscr.ent +107 -0
- package/download/entities/isonum.ent +131 -0
- package/download/entities/isopub.ent +140 -0
- package/download/entities/isotech.ent +216 -0
- package/download/entities/mmlalias.ent +598 -0
- package/download/entities/mmlextra.ent +154 -0
- package/download/entities/predefined.ent +52 -0
- package/download/entities/w3centities-f.ent +2276 -0
- package/download/entities/xhtml1-lat1.ent +143 -0
- package/download/entities/xhtml1-special.ent +78 -0
- package/download/entities/xhtml1-symbol.ent +171 -0
- package/eslint.config.js +66 -0
- package/icons/openWindow16.png +0 -0
- package/icons/openWindow24.png +0 -0
- package/lgtm.yml +5 -0
- package/lib/background.html +11 -0
- package/lib/background.js +13 -0
- package/lib/overlay.css +6 -0
- package/manifest.json +37 -0
- package/package.json +121 -0
- package/polyfills/browser-polyfill.min.js +8 -0
- package/polyfills/browser-polyfill.min.js.map +1 -0
- package/server.js +61 -0
- package/sw.js +259 -0
- package/tools/entities-import.js +62 -0
- package/tools/findEsResources.js +30 -0
- package/tools/list-locales.js +17 -0
- package/tools/parseUnicodeCharts.js +428 -0
- package/tools/ucd-import.js +24 -0
- package/tools/unicode-charts.html +596 -0
- package/tools/unihan-import.js +72 -0
- package/unicode_copyright.txt +46 -0
- package/vendor/camelcase/index.js +110 -0
- package/vendor/fflate/esm/browser.js +2665 -0
- package/vendor/intl-dom/dist/index.esm.js +2962 -0
- package/vendor/jamilih/dist/jml-es.js +2359 -0
- package/vendor/jquery/dist/jquery.js +10716 -0
- package/vendor/json-6/dist/index.mjs +1783 -0
- package/vendor/miller-columns/dist/index-es.min.js +1 -0
- package/vendor/miller-columns/miller-columns.css +75 -0
- package/vendor/simple-prefs/dist/index.esm.js +286 -0
- package/web-ext-config.cjs +13 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// Todo: Review `fromCharCode`, `charCodeAt`, and `charAt` on whether
|
|
2
|
+
// need modern substitutions
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
class UnicodeDB {
|
|
8
|
+
/**
|
|
9
|
+
* @param {PlainObject} cfg
|
|
10
|
+
* @param {string} cfg.name
|
|
11
|
+
* @param {PositiveInteger} [cfg.version]
|
|
12
|
+
*/
|
|
13
|
+
constructor ({name = 'unicode', version = 1} = {}) {
|
|
14
|
+
Object.assign(this, {name, version});
|
|
15
|
+
this.db = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
21
|
+
close () {
|
|
22
|
+
this.db.close();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} storeName
|
|
27
|
+
* @param {string} key
|
|
28
|
+
* @returns {Promise<object>}
|
|
29
|
+
*/
|
|
30
|
+
getAll (storeName, key) {
|
|
31
|
+
const tx = this.db.transaction(storeName, 'readonly');
|
|
32
|
+
const store = tx.objectStore(storeName);
|
|
33
|
+
|
|
34
|
+
const req = store.getAll(key);
|
|
35
|
+
// eslint-disable-next-line promise/avoid-new -- No API
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
req.addEventListener('success', () => {
|
|
38
|
+
resolve(req.result);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
req.addEventListener('error', () => {
|
|
42
|
+
reject(req.error);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* eslint-disable class-methods-use-this -- Abstract */
|
|
48
|
+
/**
|
|
49
|
+
* @abstract
|
|
50
|
+
*/
|
|
51
|
+
upgradeneeded () {
|
|
52
|
+
throw new Error('`UnicodeDB.upgradeneeded` is an abstract method');
|
|
53
|
+
}
|
|
54
|
+
/* eslint-enable class-methods-use-this -- Abstract */
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {object} [cfg]
|
|
58
|
+
* @param {JSON} [cfg.updateUnicodeData]
|
|
59
|
+
* @param {GenericFunction} [cfg.versionchange]
|
|
60
|
+
* @returns {Promise<void>}
|
|
61
|
+
*/
|
|
62
|
+
connect ({updateUnicodeData, versionchange} = {}) {
|
|
63
|
+
/* eslint-disable promise/avoid-new -- No Promise API */
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const req = indexedDB.open(
|
|
66
|
+
this.name, updateUnicodeData ? this.version : undefined
|
|
67
|
+
);
|
|
68
|
+
if (updateUnicodeData) {
|
|
69
|
+
req.addEventListener('upgradeneeded', (e) => {
|
|
70
|
+
const {result: db} = e.target;
|
|
71
|
+
this.db = db;
|
|
72
|
+
this.upgradeneeded({updateUnicodeData});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
req.addEventListener('success', ({target}) => {
|
|
76
|
+
this.db = target.result;
|
|
77
|
+
if (versionchange) {
|
|
78
|
+
this.db.addEventListener('versionchange', (ev) => {
|
|
79
|
+
versionchange(ev);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
resolve(this.db);
|
|
83
|
+
});
|
|
84
|
+
req.addEventListener('error', () => {
|
|
85
|
+
reject(req.error);
|
|
86
|
+
});
|
|
87
|
+
req.addEventListener('blocked', () => {
|
|
88
|
+
reject(new Error('blocked'));
|
|
89
|
+
});
|
|
90
|
+
/* eslint-enable promise/avoid-new -- No Promise API */
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
export class UnihanDatabase extends UnicodeDB {
|
|
99
|
+
/**
|
|
100
|
+
* @param {PlainObject} cfg
|
|
101
|
+
* @param {PositiveInteger} cfg.version
|
|
102
|
+
*/
|
|
103
|
+
constructor ({version} = {}) {
|
|
104
|
+
// We create a separate database so updates do not clobber both databases
|
|
105
|
+
super({name: 'unicode-input-toolconverter-Unihan', version});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @param {string} codePoint
|
|
109
|
+
* @throws {Error}
|
|
110
|
+
* @returns {Promise<string[]>}
|
|
111
|
+
*/
|
|
112
|
+
getUnicodeFields (codePoint) {
|
|
113
|
+
const tx = this.db.transaction(['Unihan'], 'readonly');
|
|
114
|
+
const store = tx.objectStore('Unihan');
|
|
115
|
+
|
|
116
|
+
const request = store.get(codePoint);
|
|
117
|
+
// eslint-disable-next-line promise/avoid-new -- No Promise API
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
request.addEventListener('success', () => {
|
|
120
|
+
resolve(request.result?.columns);
|
|
121
|
+
});
|
|
122
|
+
request.addEventListener('error', () => {
|
|
123
|
+
reject(request.error);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} key
|
|
130
|
+
* @returns {Promise<object>}
|
|
131
|
+
*/
|
|
132
|
+
getAll (key) {
|
|
133
|
+
return super.getAll('Unihan', key);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {JSON} updateUnicodeData
|
|
138
|
+
* @returns {void}
|
|
139
|
+
*/
|
|
140
|
+
upgradeneeded ({updateUnicodeData}) {
|
|
141
|
+
const store = this.db.createObjectStore('Unihan', {
|
|
142
|
+
keyPath: 'codePoint'
|
|
143
|
+
});
|
|
144
|
+
store.createIndex('code-point', 'codePoint', {
|
|
145
|
+
unique: true
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
updateUnicodeData.forEach((
|
|
149
|
+
[codePoint, ...codePointInfoRow]
|
|
150
|
+
) => {
|
|
151
|
+
store.put({
|
|
152
|
+
codePoint,
|
|
153
|
+
columns: codePointInfoRow
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
*/
|
|
162
|
+
export class UnicodeDatabase extends UnicodeDB {
|
|
163
|
+
/**
|
|
164
|
+
* @param {PlainObject} cfg
|
|
165
|
+
* @param {PositiveInteger} cfg.version
|
|
166
|
+
*/
|
|
167
|
+
constructor ({version} = {}) {
|
|
168
|
+
super({name: 'unicode-input-toolconverter', version});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {string} key
|
|
173
|
+
* @returns {Promise<object>}
|
|
174
|
+
*/
|
|
175
|
+
getAll (key) {
|
|
176
|
+
return super.getAll('UnicodeData', key);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {JSON} updateUnicodeData
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
upgradeneeded ({updateUnicodeData}) {
|
|
184
|
+
const store = this.db.createObjectStore('UnicodeData', {
|
|
185
|
+
keyPath: 'codePoint'
|
|
186
|
+
});
|
|
187
|
+
store.createIndex('code-point', 'codePoint', {
|
|
188
|
+
unique: true
|
|
189
|
+
});
|
|
190
|
+
updateUnicodeData.forEach((codePointInfoRow) => {
|
|
191
|
+
// http://www.unicode.org/reports/tr44/#UnicodeData.txt
|
|
192
|
+
const [
|
|
193
|
+
codePoint, name, generalCategory, canonicalCombiningClass, bidiClass,
|
|
194
|
+
decomposition, numeric6, numeric7, numeric8,
|
|
195
|
+
bidiMirrored, unicode1Name, isoComment,
|
|
196
|
+
simpleUppercaseMapping, simpleLowercaseMapping, simpleTitlecaseMapping
|
|
197
|
+
] = codePointInfoRow;
|
|
198
|
+
const {groups: {
|
|
199
|
+
decompositionType,
|
|
200
|
+
decompositionMapping
|
|
201
|
+
}} = (
|
|
202
|
+
/<(?<decompositionType>[^>]*)>\s+(?<decompositionMapping>.*)/u
|
|
203
|
+
).exec(
|
|
204
|
+
decomposition
|
|
205
|
+
) ?? {groups: {}};
|
|
206
|
+
let numericType = 'None';
|
|
207
|
+
if (numeric6) {
|
|
208
|
+
numericType = 'Decimal';
|
|
209
|
+
} else if (numeric7) {
|
|
210
|
+
numericType = 'Digit';
|
|
211
|
+
} else if (numeric8) {
|
|
212
|
+
numericType = 'Numeric';
|
|
213
|
+
}
|
|
214
|
+
const numericValue = numericType ? numeric8 : Number.NaN;
|
|
215
|
+
|
|
216
|
+
store.put({
|
|
217
|
+
codePoint, name, generalCategory, canonicalCombiningClass, bidiClass,
|
|
218
|
+
decompositionType, decompositionMapping, numericType, numericValue,
|
|
219
|
+
bidiMirrored, unicode1Name, isoComment,
|
|
220
|
+
simpleUppercaseMapping, simpleLowercaseMapping, simpleTitlecaseMapping
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @param {string} codePoint
|
|
227
|
+
* @returns {Promise<string[]>}
|
|
228
|
+
*/
|
|
229
|
+
getUnicodeFields (codePoint) {
|
|
230
|
+
// const entityInParentheses = '(' + entity + ') ';
|
|
231
|
+
// Todo: Should this not be padded to 6??
|
|
232
|
+
// const currentStartCharCodeUpperCaseHexPadded =
|
|
233
|
+
// currentStartCharCode.toString(16).toUpperCase().padStart(4, '0');
|
|
234
|
+
const tx = this.db.transaction(['UnicodeData'], 'readonly');
|
|
235
|
+
const store = tx.objectStore('UnicodeData');
|
|
236
|
+
const request = store.get(codePoint);
|
|
237
|
+
// eslint-disable-next-line promise/avoid-new -- No Promise API
|
|
238
|
+
return new Promise((resolve, reject) => {
|
|
239
|
+
request.addEventListener('success', () => {
|
|
240
|
+
if (!request.result) {
|
|
241
|
+
reject(new Error('Unexpected code point'));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
resolve(request.result);
|
|
245
|
+
});
|
|
246
|
+
request.addEventListener('error', () => {
|
|
247
|
+
reject(request.error);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const charrefunicodeDb = new UnicodeDatabase();
|
|
254
|
+
/*
|
|
255
|
+
const unihanDb = new UnihanDatabase();
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
export default charrefunicodeDb;
|