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,91 @@
|
|
|
1
|
+
/* globals jQuery -- No ESM */
|
|
2
|
+
import {$} from '../vendor/jamilih/dist/jml-es.js';
|
|
3
|
+
import {getChartBuild, chartBuild} from './chartBuild.js';
|
|
4
|
+
import unicodecharref from './unicodecharref.js';
|
|
5
|
+
import {insertIntoOrOverExisting} from './utils/TextUtils.js';
|
|
6
|
+
import addMillerColumnPlugin from
|
|
7
|
+
'../vendor/miller-columns/dist/index-es.min.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {PlainObject} cfg
|
|
11
|
+
* @param {import('intl-dom').I18NCallback} cfg._
|
|
12
|
+
* @param {charrefunicodeConverter} cfg.charrefunicodeConverter
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
async function characterSelection ({
|
|
16
|
+
_, charrefunicodeConverter
|
|
17
|
+
}) {
|
|
18
|
+
await getChartBuild({
|
|
19
|
+
_,
|
|
20
|
+
charrefunicodeConverter,
|
|
21
|
+
textReceptacle: $('#insertText'),
|
|
22
|
+
chartContainer: $('#chartContainer'),
|
|
23
|
+
// Todo: Get working
|
|
24
|
+
insertText ({textReceptacle, value}) {
|
|
25
|
+
insertIntoOrOverExisting({textReceptacle, value});
|
|
26
|
+
|
|
27
|
+
// Save values for manipulation by entity addition function, 'insertent'
|
|
28
|
+
// Todo: Fix and use
|
|
29
|
+
/*
|
|
30
|
+
this.selst = textReceptacle.selectionStart;
|
|
31
|
+
this.selend = textReceptacle.selectionEnd;
|
|
32
|
+
*/
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await addMillerColumnPlugin(jQuery, {stylesheets: [
|
|
37
|
+
// Per our widget "standard", allow for injecting of others in parallel
|
|
38
|
+
[
|
|
39
|
+
location.href.includes('index-pages')
|
|
40
|
+
/* istanbul ignore next -- For GitHub Pages only */
|
|
41
|
+
? '/unicode-input-toolconverter/icons/openWindow24.png'
|
|
42
|
+
: '/icons/openWindow24.png',
|
|
43
|
+
{favicon: true}
|
|
44
|
+
],
|
|
45
|
+
location.href.includes('index-pages')
|
|
46
|
+
/* istanbul ignore next -- For GitHub Pages only */
|
|
47
|
+
? '/unicode-input-toolconverter/browser_action/styles/unicode-dialog.css'
|
|
48
|
+
: '/browser_action/styles/unicode-dialog.css',
|
|
49
|
+
location.href.includes('index-pages')
|
|
50
|
+
/* istanbul ignore next -- For GitHub Pages only */
|
|
51
|
+
? '/unicode-input-toolconverter//vendor/miller-columns/miller-columns.css'
|
|
52
|
+
: '/vendor/miller-columns/miller-columns.css'
|
|
53
|
+
]});
|
|
54
|
+
|
|
55
|
+
jQuery('div.miller-columns').millerColumns({
|
|
56
|
+
/*
|
|
57
|
+
preview () {
|
|
58
|
+
// $('#chart_selectchar_persist').scrollLeft = 2000;
|
|
59
|
+
return '';
|
|
60
|
+
},
|
|
61
|
+
*/
|
|
62
|
+
delay: 100, // Shorten delay until we can figure out how to fix jumpiness
|
|
63
|
+
scroll () {
|
|
64
|
+
// Due to an overflow within an overflow, we have to also force
|
|
65
|
+
// this scroll left
|
|
66
|
+
$('#chart_selectchar_persist').scrollLeft = 2000;
|
|
67
|
+
},
|
|
68
|
+
async current ($item /* , $cols */) {
|
|
69
|
+
if (!$item) { // Todo: Is this an error?
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// console.log('User selected:', $item);
|
|
73
|
+
const title = $item[0].getAttribute('title');
|
|
74
|
+
if (!title) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await unicodecharref.disableEnts();
|
|
79
|
+
|
|
80
|
+
await unicodecharref.setCurrstartset(
|
|
81
|
+
Number.parseInt(title.replace(/-.*$/u, ''), 16) - 1
|
|
82
|
+
);
|
|
83
|
+
// Free to use `chartBuild` now that we have passed set-up
|
|
84
|
+
await chartBuild(); // Todo: descripts?
|
|
85
|
+
await unicodecharref.resizecells();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
$('div.miller-columns').style.display = 'block';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default characterSelection;
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {$} from '../vendor/jamilih/dist/jml-es.js';
|
|
2
|
+
import {getUnicodeDefaults} from './preferences/prefDefaults.js';
|
|
3
|
+
|
|
4
|
+
let charrefunicodeConverter, getPref;
|
|
5
|
+
export const shareVars = ({
|
|
6
|
+
// _: l10n,
|
|
7
|
+
charrefunicodeConverter: _uc
|
|
8
|
+
}) => {
|
|
9
|
+
charrefunicodeConverter = _uc;
|
|
10
|
+
({getPref} = getUnicodeDefaults());
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {HTMLElement} el
|
|
15
|
+
* @returns {void}
|
|
16
|
+
*/
|
|
17
|
+
function classChange (el) {
|
|
18
|
+
const activeButton = $("*[class='buttonactive']");
|
|
19
|
+
if (activeButton) {
|
|
20
|
+
activeButton.className = 'reconvert';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
el.className = 'buttonactive';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const CharrefConverterBridges = {
|
|
27
|
+
charref2unicodeval (out, el) {
|
|
28
|
+
classChange(el);
|
|
29
|
+
return charrefunicodeConverter.charref2unicodeval(out);
|
|
30
|
+
},
|
|
31
|
+
async charref2htmlentsval (out, el) {
|
|
32
|
+
classChange(el);
|
|
33
|
+
return await charrefunicodeConverter.charref2htmlentsval(out);
|
|
34
|
+
},
|
|
35
|
+
async unicode2charrefDecval (unicodeToConvert, el, leaveSurrogates) {
|
|
36
|
+
classChange(el);
|
|
37
|
+
return await charrefunicodeConverter.unicode2charrefDecval(
|
|
38
|
+
unicodeToConvert, leaveSurrogates
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
async unicode2charrefHexval (unicodeToConvert, el, leaveSurrogates, type) {
|
|
42
|
+
classChange(el);
|
|
43
|
+
return await charrefunicodeConverter.unicode2charrefHexval(
|
|
44
|
+
unicodeToConvert, leaveSurrogates, type
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
async unicode2htmlentsval (unicodeToConvert, el) {
|
|
48
|
+
classChange(el);
|
|
49
|
+
return await charrefunicodeConverter.unicode2htmlentsval(
|
|
50
|
+
unicodeToConvert
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
async htmlents2charrefDecval (out, el) {
|
|
54
|
+
classChange(el);
|
|
55
|
+
return await charrefunicodeConverter.htmlents2charrefDecval(out);
|
|
56
|
+
},
|
|
57
|
+
async htmlents2charrefHexval (out, el) {
|
|
58
|
+
classChange(el);
|
|
59
|
+
return await charrefunicodeConverter.htmlents2charrefHexval(out);
|
|
60
|
+
},
|
|
61
|
+
async htmlents2unicodeval (out, el) {
|
|
62
|
+
classChange(el);
|
|
63
|
+
return await charrefunicodeConverter.htmlents2unicodeval(out);
|
|
64
|
+
},
|
|
65
|
+
hex2decval (out, el) {
|
|
66
|
+
classChange(el);
|
|
67
|
+
return charrefunicodeConverter.hex2decval(out);
|
|
68
|
+
},
|
|
69
|
+
async dec2hexval (out, el) {
|
|
70
|
+
classChange(el);
|
|
71
|
+
return await charrefunicodeConverter.dec2hexval(out);
|
|
72
|
+
},
|
|
73
|
+
async unicodeTo6Digit (e) {
|
|
74
|
+
const toconvert = $('#toconvert').value;
|
|
75
|
+
await this.unicodeTo6DigitVal(toconvert, e.target);
|
|
76
|
+
return false;
|
|
77
|
+
},
|
|
78
|
+
async unicodeTo6DigitVal (toconvert, el) {
|
|
79
|
+
classChange(el);
|
|
80
|
+
const val = await charrefunicodeConverter.unicodeTo6DigitVal(
|
|
81
|
+
toconvert
|
|
82
|
+
);
|
|
83
|
+
$('#converted').value = val;
|
|
84
|
+
return val;
|
|
85
|
+
},
|
|
86
|
+
async charref2unicode (e) {
|
|
87
|
+
let toconvert = $('#toconvert').value;
|
|
88
|
+
if (await getPref('ampspace')) {
|
|
89
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
90
|
+
}
|
|
91
|
+
$('#converted').value = this.charref2unicodeval(toconvert, e.target);
|
|
92
|
+
return false;
|
|
93
|
+
},
|
|
94
|
+
async charref2htmlents (e) {
|
|
95
|
+
let toconvert = $('#toconvert').value;
|
|
96
|
+
if (await getPref('ampspace')) {
|
|
97
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
98
|
+
}
|
|
99
|
+
$('#converted').value = await this.charref2htmlentsval(toconvert, e.target);
|
|
100
|
+
return false;
|
|
101
|
+
},
|
|
102
|
+
async unicode2charrefDec (e, leaveSurrogates) {
|
|
103
|
+
let toconvert = $('#toconvert').value;
|
|
104
|
+
if (await getPref('ampspace')) {
|
|
105
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
106
|
+
}
|
|
107
|
+
$('#converted').value = await this.unicode2charrefDecval(
|
|
108
|
+
toconvert, e.target, leaveSurrogates
|
|
109
|
+
);
|
|
110
|
+
return false;
|
|
111
|
+
},
|
|
112
|
+
async unicode2charrefDecSurrogate (e) {
|
|
113
|
+
return await this.unicode2charrefDec(e, true);
|
|
114
|
+
},
|
|
115
|
+
async unicode2charrefHex (e, leaveSurrogates) {
|
|
116
|
+
let toconvert = $('#toconvert').value;
|
|
117
|
+
if (await getPref('ampspace')) {
|
|
118
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
119
|
+
}
|
|
120
|
+
$('#converted').value = await this.unicode2charrefHexval(
|
|
121
|
+
toconvert, e.target, leaveSurrogates
|
|
122
|
+
);
|
|
123
|
+
return false;
|
|
124
|
+
},
|
|
125
|
+
async unicode2charrefHexSurrogate (e) {
|
|
126
|
+
return await this.unicode2charrefHex(e, true);
|
|
127
|
+
},
|
|
128
|
+
async unicode2htmlents (e) {
|
|
129
|
+
let toconvert = $('#toconvert').value;
|
|
130
|
+
if (await getPref('ampspace')) {
|
|
131
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
132
|
+
}
|
|
133
|
+
$('#converted').value = await this.unicode2htmlentsval(toconvert, e.target);
|
|
134
|
+
return false;
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Replace Unicode characters with their escaped description form.
|
|
138
|
+
* @param {string} toconvert The text whose Unicode characters will be
|
|
139
|
+
* replaced
|
|
140
|
+
* @param {HTMLElement} el The (button) element whose class will be changed to
|
|
141
|
+
* reflect that the action has been activated
|
|
142
|
+
* @returns {string} The passed-in string with Unicode replaced with
|
|
143
|
+
* description escape sequences
|
|
144
|
+
*/
|
|
145
|
+
async unicode2CharDescVal (toconvert, el) {
|
|
146
|
+
classChange(el);
|
|
147
|
+
const val = await charrefunicodeConverter.unicode2CharDescVal(toconvert);
|
|
148
|
+
$('#converted').value = val;
|
|
149
|
+
return val;
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Converts character description escape sequences within a string to
|
|
153
|
+
* Unicode characters.
|
|
154
|
+
* @param {string} toconvert The text to convert
|
|
155
|
+
* @param {HTMLElement} el The button element whose class should be
|
|
156
|
+
* dynamically changed (and others deactivated)
|
|
157
|
+
* @returns {Promise<string>} The converted-to-Unicode value
|
|
158
|
+
*/
|
|
159
|
+
async charDesc2UnicodeVal (toconvert, el) {
|
|
160
|
+
classChange(el);
|
|
161
|
+
const val = await charrefunicodeConverter.charDesc2UnicodeVal(toconvert);
|
|
162
|
+
$('#converted').value = val;
|
|
163
|
+
return val;
|
|
164
|
+
},
|
|
165
|
+
async charDesc2Unicode (e) {
|
|
166
|
+
const toconvert = $('#toconvert').value;
|
|
167
|
+
await this.charDesc2UnicodeVal(toconvert, e.target);
|
|
168
|
+
return false;
|
|
169
|
+
},
|
|
170
|
+
async unicode2CharDesc (e) {
|
|
171
|
+
const toconvert = $('#toconvert').value;
|
|
172
|
+
await this.unicode2CharDescVal(toconvert, e.target);
|
|
173
|
+
return false;
|
|
174
|
+
},
|
|
175
|
+
async unicode2jsescapeval (toconvert, el) {
|
|
176
|
+
classChange(el);
|
|
177
|
+
const val = await charrefunicodeConverter.unicode2jsescapeval(toconvert);
|
|
178
|
+
$('#converted').value = val;
|
|
179
|
+
return val;
|
|
180
|
+
},
|
|
181
|
+
async unicode2jsescape (e) {
|
|
182
|
+
const toconvert = $('#toconvert').value;
|
|
183
|
+
await this.unicode2jsescapeval(toconvert, e.target);
|
|
184
|
+
return false;
|
|
185
|
+
},
|
|
186
|
+
cssescape2unicode (e) {
|
|
187
|
+
const toconvert = $('#toconvert').value;
|
|
188
|
+
$('#converted').value = this.cssescape2unicodeval(toconvert, e.target);
|
|
189
|
+
return false;
|
|
190
|
+
},
|
|
191
|
+
sixDigit2UnicodeVal (toconvert, el) {
|
|
192
|
+
classChange(el);
|
|
193
|
+
const val = charrefunicodeConverter.sixDigit2UnicodeVal(toconvert);
|
|
194
|
+
$('#converted').value = val;
|
|
195
|
+
return val;
|
|
196
|
+
},
|
|
197
|
+
sixDigit2Unicode (e) {
|
|
198
|
+
const toconvert = $('#toconvert').value;
|
|
199
|
+
this.sixDigit2UnicodeVal(toconvert, e.target);
|
|
200
|
+
return false;
|
|
201
|
+
},
|
|
202
|
+
jsescape2unicode (e) {
|
|
203
|
+
const toconvert = $('#toconvert').value;
|
|
204
|
+
$('#converted').value = this.jsescape2unicodeval(toconvert, e.target);
|
|
205
|
+
return false;
|
|
206
|
+
},
|
|
207
|
+
cssescape2unicodeval (toconvert, el) {
|
|
208
|
+
classChange(el);
|
|
209
|
+
const unicode = charrefunicodeConverter.cssescape2unicodeval(toconvert);
|
|
210
|
+
return unicode;
|
|
211
|
+
},
|
|
212
|
+
// Fix: make option to avoid converting \r, etc. for javascript
|
|
213
|
+
jsescape2unicodeval (toconvert, el, mode) {
|
|
214
|
+
classChange(el);
|
|
215
|
+
const unicode = charrefunicodeConverter.jsescape2unicodeval(
|
|
216
|
+
toconvert, mode
|
|
217
|
+
);
|
|
218
|
+
return unicode;
|
|
219
|
+
},
|
|
220
|
+
async unicode2cssescapeval (toconvert, el) {
|
|
221
|
+
classChange(el);
|
|
222
|
+
const val = await charrefunicodeConverter.unicode2cssescapeval(
|
|
223
|
+
toconvert
|
|
224
|
+
);
|
|
225
|
+
$('#converted').value = val;
|
|
226
|
+
return val;
|
|
227
|
+
},
|
|
228
|
+
async unicode2cssescape (e) {
|
|
229
|
+
const toconvert = $('#toconvert').value;
|
|
230
|
+
await this.unicode2cssescapeval(toconvert, e.target);
|
|
231
|
+
return false;
|
|
232
|
+
},
|
|
233
|
+
// In this method and others like it, boolpref should be moved instead to
|
|
234
|
+
// converter function since it should be consistent across the app
|
|
235
|
+
async htmlents2charrefDec (e) {
|
|
236
|
+
let toconvert = $('#toconvert').value;
|
|
237
|
+
if (await getPref('ampspace')) {
|
|
238
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
239
|
+
}
|
|
240
|
+
$('#converted').value = await this.htmlents2charrefDecval(
|
|
241
|
+
toconvert, e.target
|
|
242
|
+
);
|
|
243
|
+
return false;
|
|
244
|
+
},
|
|
245
|
+
async htmlents2charrefHex (e) {
|
|
246
|
+
let toconvert = $('#toconvert').value;
|
|
247
|
+
if (await getPref('ampspace')) {
|
|
248
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
249
|
+
}
|
|
250
|
+
$('#converted').value = await this.htmlents2charrefHexval(
|
|
251
|
+
toconvert, e.target
|
|
252
|
+
);
|
|
253
|
+
return false;
|
|
254
|
+
},
|
|
255
|
+
async htmlents2unicode (e) {
|
|
256
|
+
let toconvert = $('#toconvert').value;
|
|
257
|
+
if (await getPref('ampspace')) {
|
|
258
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
259
|
+
}
|
|
260
|
+
$('#converted').value = await this.htmlents2unicodeval(
|
|
261
|
+
toconvert, e.target
|
|
262
|
+
);
|
|
263
|
+
return false;
|
|
264
|
+
},
|
|
265
|
+
async hex2dec (e) {
|
|
266
|
+
let toconvert = $('#toconvert').value;
|
|
267
|
+
if (await getPref('ampspace')) {
|
|
268
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
269
|
+
}
|
|
270
|
+
$('#converted').value = this.hex2decval(toconvert, e.target);
|
|
271
|
+
return false;
|
|
272
|
+
},
|
|
273
|
+
async dec2hex (e) {
|
|
274
|
+
let toconvert = $('#toconvert').value;
|
|
275
|
+
if (await getPref('ampspace')) {
|
|
276
|
+
toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&$1');
|
|
277
|
+
}
|
|
278
|
+
$('#converted').value = await this.dec2hexval(toconvert, e.target);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @param {PlainObject} cfg
|
|
285
|
+
* @param {string} cfg.toconvert
|
|
286
|
+
* @param {string} cfg.targetid
|
|
287
|
+
* @param {import('intl-dom').I18NCallback} cfg._
|
|
288
|
+
* @throws {Error}
|
|
289
|
+
* @returns {Promise<string>}
|
|
290
|
+
*/
|
|
291
|
+
async function findBridgeForTargetID ({_, toconvert, targetid}) {
|
|
292
|
+
let out;
|
|
293
|
+
switch (targetid) {
|
|
294
|
+
case 'context-charrefunicode1':
|
|
295
|
+
out = CharrefConverterBridges.charref2unicodeval(toconvert, $('#b1'));
|
|
296
|
+
break;
|
|
297
|
+
case 'context-charrefunicode2':
|
|
298
|
+
out = await CharrefConverterBridges.charref2htmlentsval(
|
|
299
|
+
toconvert, $('#b2')
|
|
300
|
+
);
|
|
301
|
+
break;
|
|
302
|
+
case 'context-charrefunicode3':
|
|
303
|
+
out = await CharrefConverterBridges.unicode2charrefDecval(
|
|
304
|
+
toconvert, $('#b3')
|
|
305
|
+
);
|
|
306
|
+
break;
|
|
307
|
+
case 'context-charrefunicode4':
|
|
308
|
+
out = await CharrefConverterBridges.unicode2charrefHexval(
|
|
309
|
+
toconvert, $('#b4')
|
|
310
|
+
);
|
|
311
|
+
break;
|
|
312
|
+
case 'context-charrefunicode5':
|
|
313
|
+
out = await CharrefConverterBridges.unicode2htmlentsval(
|
|
314
|
+
toconvert, $('#b5')
|
|
315
|
+
);
|
|
316
|
+
break;
|
|
317
|
+
case 'context-charrefunicode6':
|
|
318
|
+
out = CharrefConverterBridges.unicode2jsescapeval(toconvert, $('#b6'));
|
|
319
|
+
break;
|
|
320
|
+
case 'context-charrefunicode7':
|
|
321
|
+
out = await CharrefConverterBridges.unicodeTo6DigitVal(
|
|
322
|
+
toconvert, $('#b7')
|
|
323
|
+
);
|
|
324
|
+
break;
|
|
325
|
+
case 'context-charrefunicode8':
|
|
326
|
+
out = await CharrefConverterBridges.unicode2cssescapeval(
|
|
327
|
+
toconvert, $('#b8')
|
|
328
|
+
);
|
|
329
|
+
break;
|
|
330
|
+
case 'context-charrefunicode9':
|
|
331
|
+
out = await CharrefConverterBridges.htmlents2charrefDecval(
|
|
332
|
+
toconvert, $('#b9')
|
|
333
|
+
);
|
|
334
|
+
break;
|
|
335
|
+
case 'context-charrefunicode10':
|
|
336
|
+
out = await CharrefConverterBridges.htmlents2charrefHexval(
|
|
337
|
+
toconvert, $('#b10')
|
|
338
|
+
);
|
|
339
|
+
break;
|
|
340
|
+
case 'context-charrefunicode11':
|
|
341
|
+
out = await CharrefConverterBridges.htmlents2unicodeval(
|
|
342
|
+
toconvert, $('#b11')
|
|
343
|
+
);
|
|
344
|
+
break;
|
|
345
|
+
case 'context-charrefunicode12':
|
|
346
|
+
out = CharrefConverterBridges.hex2decval(toconvert, $('#b12'));
|
|
347
|
+
break;
|
|
348
|
+
case 'context-charrefunicode13':
|
|
349
|
+
out = CharrefConverterBridges.dec2hexval(toconvert, $('#b13'));
|
|
350
|
+
break;
|
|
351
|
+
case 'context-charrefunicode14':
|
|
352
|
+
out = CharrefConverterBridges.jsescape2unicodeval(toconvert, $('#b14'));
|
|
353
|
+
break;
|
|
354
|
+
case 'context-charrefunicode15':
|
|
355
|
+
out = CharrefConverterBridges.sixDigit2UnicodeVal(toconvert, $('#b15'));
|
|
356
|
+
break;
|
|
357
|
+
case 'context-charrefunicode16':
|
|
358
|
+
out = CharrefConverterBridges.cssescape2unicodeval(toconvert, $('#b16'));
|
|
359
|
+
break;
|
|
360
|
+
case 'context-charrefunicode17':
|
|
361
|
+
out = await CharrefConverterBridges.unicode2CharDescVal(
|
|
362
|
+
toconvert, $('#b17')
|
|
363
|
+
);
|
|
364
|
+
break;
|
|
365
|
+
case 'context-charrefunicode18':
|
|
366
|
+
out = await CharrefConverterBridges.charDesc2UnicodeVal(
|
|
367
|
+
toconvert, $('#b18')
|
|
368
|
+
);
|
|
369
|
+
break;
|
|
370
|
+
case 'context-charrefunicode3b':
|
|
371
|
+
out = await CharrefConverterBridges.unicode2charrefDecval(
|
|
372
|
+
toconvert, $('#b3b'), true
|
|
373
|
+
);
|
|
374
|
+
break;
|
|
375
|
+
case 'context-charrefunicode4b':
|
|
376
|
+
out = await CharrefConverterBridges.unicode2charrefHexval(
|
|
377
|
+
toconvert, $('#b4b'), true
|
|
378
|
+
);
|
|
379
|
+
break;
|
|
380
|
+
default:
|
|
381
|
+
alert(_(`Unexpected_target_ID`, {
|
|
382
|
+
targetid
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
385
|
+
return out;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export {findBridgeForTargetID, classChange};
|
|
389
|
+
export default CharrefConverterBridges;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {jml} from '../vendor/jamilih/dist/jml-es.js';
|
|
2
|
+
import {getUnicodeDefaults} from './preferences/prefDefaults.js';
|
|
3
|
+
import chartBuildTemplate from './templates/chartBuild.js';
|
|
4
|
+
|
|
5
|
+
let _, textReceptacle, chartContainer, insertText, charrefunicodeConverter;
|
|
6
|
+
|
|
7
|
+
const getChartBuild = async function ({
|
|
8
|
+
_: i18n,
|
|
9
|
+
descripts,
|
|
10
|
+
insertText: it, textReceptacle: tr, chartContainer: cc,
|
|
11
|
+
charrefunicodeConverter: uc
|
|
12
|
+
}) {
|
|
13
|
+
textReceptacle = tr;
|
|
14
|
+
chartContainer = cc;
|
|
15
|
+
insertText = it;
|
|
16
|
+
charrefunicodeConverter = uc;
|
|
17
|
+
_ = i18n;
|
|
18
|
+
return await chartBuild({descripts});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// // eslint-disable-next-line import/no-mutable-exports -- Easier
|
|
22
|
+
export let lastStartCharCode;
|
|
23
|
+
|
|
24
|
+
const chartBuild = async function chartBuild ({descripts} = {}) {
|
|
25
|
+
const {getPref, setPref} = getUnicodeDefaults();
|
|
26
|
+
const [
|
|
27
|
+
startCharInMiddleOfChart,
|
|
28
|
+
cols, onlyentsyes,
|
|
29
|
+
entyes, buttonyes, decyes, hexyes, unicodeyes,
|
|
30
|
+
hexLettersUpper,
|
|
31
|
+
font, lang,
|
|
32
|
+
tblrowsset, currentStartCharCodeInitial
|
|
33
|
+
] = await Promise.all([
|
|
34
|
+
'startCharInMiddleOfChart',
|
|
35
|
+
'tblcolsset', 'onlyentsyes',
|
|
36
|
+
'entyes', 'buttonyes', 'decyes', 'hexyes', 'unicodeyes',
|
|
37
|
+
'hexLettersUpper',
|
|
38
|
+
'font', 'lang',
|
|
39
|
+
'tblrowsset', 'currentStartCharCode'
|
|
40
|
+
].map((pref) => {
|
|
41
|
+
return getPref(pref);
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const current = {startCharCode: currentStartCharCodeInitial};
|
|
45
|
+
let rows = tblrowsset;
|
|
46
|
+
|
|
47
|
+
lastStartCharCode = current.startCharCode;
|
|
48
|
+
|
|
49
|
+
const resetCurrentStartCharCodeIfOutOfBounds = () => {
|
|
50
|
+
if (current.startCharCode < 0) {
|
|
51
|
+
current.startCharCode += 1114112;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (current.startCharCode > 1114111) {
|
|
55
|
+
current.startCharCode = 0;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (startCharInMiddleOfChart) {
|
|
60
|
+
current.startCharCode = Math.round(
|
|
61
|
+
current.startCharCode - ((rows * cols) / 2)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
resetCurrentStartCharCodeIfOutOfBounds();
|
|
65
|
+
|
|
66
|
+
// Todo: Document (or better name) what's going on here
|
|
67
|
+
let q, prev, arr, remainder, rowceil, colsOverRemainder;
|
|
68
|
+
const descriptsOrOnlyEnts = onlyentsyes || descripts;
|
|
69
|
+
if (descriptsOrOnlyEnts) {
|
|
70
|
+
arr = descripts
|
|
71
|
+
? charrefunicodeConverter.descripts
|
|
72
|
+
: charrefunicodeConverter.numericCharacterReferences;
|
|
73
|
+
}
|
|
74
|
+
if (arr) { // `descriptsOrOnlyEnts` and if Unihan, it is present
|
|
75
|
+
const chrreflgth = arr.length;
|
|
76
|
+
|
|
77
|
+
if ((rows * cols) > chrreflgth) {
|
|
78
|
+
const newrows = chrreflgth / cols;
|
|
79
|
+
rows = Math.ceil(newrows);
|
|
80
|
+
rowceil = rows - 1;
|
|
81
|
+
remainder = (rows * cols) - chrreflgth;
|
|
82
|
+
const hasRemainder = remainder > 0;
|
|
83
|
+
colsOverRemainder = hasRemainder && cols - remainder;
|
|
84
|
+
}
|
|
85
|
+
q = arr.indexOf(current.startCharCode);
|
|
86
|
+
if (q === -1) {
|
|
87
|
+
q = 0;
|
|
88
|
+
current.startCharCode = arr[q];
|
|
89
|
+
q = -1; // Had to add this as will increment
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let newq = q - (cols * rows);
|
|
93
|
+
if (newq < 0) { // Go backwards in the entity array
|
|
94
|
+
newq = chrreflgth + newq;
|
|
95
|
+
}
|
|
96
|
+
prev = arr[newq];
|
|
97
|
+
} else {
|
|
98
|
+
prev = current.startCharCode - (cols * rows);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
jml(textReceptacle, {
|
|
102
|
+
rows: (rows * 20) - 10,
|
|
103
|
+
cols: (cols * 20) - 10
|
|
104
|
+
});
|
|
105
|
+
chartContainer.textContent = '';
|
|
106
|
+
|
|
107
|
+
const types = {hexyes, decyes, unicodeyes, entyes};
|
|
108
|
+
const appliedFormats = [
|
|
109
|
+
'decyes', 'hexyes', 'unicodeyes'
|
|
110
|
+
].filter((t) => types[t]);
|
|
111
|
+
const displayTypes = {
|
|
112
|
+
decyes (k) {
|
|
113
|
+
return `&#${k};`;
|
|
114
|
+
},
|
|
115
|
+
hexyes (k) {
|
|
116
|
+
const kto16 = hexLettersUpper
|
|
117
|
+
? k.toString(16).toUpperCase()
|
|
118
|
+
: k.toString(16);
|
|
119
|
+
return '&#x' + kto16 + ';';
|
|
120
|
+
},
|
|
121
|
+
unicodeyes (k) {
|
|
122
|
+
return String.fromCodePoint(k);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const captioncntnt = [];
|
|
127
|
+
['unicode', 'hex', 'dec', 'ent'].forEach((type) => {
|
|
128
|
+
if (types[type + 'yes']) {
|
|
129
|
+
captioncntnt.push(_(type + '_noun'));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const captionContent = _.list([
|
|
134
|
+
// Make first letter of first word upper case
|
|
135
|
+
captioncntnt[0].replace(/^./u, (s) => s.toLocaleUpperCase(
|
|
136
|
+
_.locale
|
|
137
|
+
)),
|
|
138
|
+
...captioncntnt.slice(1)
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
chartBuildTemplate({
|
|
142
|
+
_, rows, cols, charrefunicodeConverter, current,
|
|
143
|
+
resetCurrentStartCharCodeIfOutOfBounds, descriptsOrOnlyEnts,
|
|
144
|
+
q, arr, textReceptacle, entyes, chartBuild, descripts,
|
|
145
|
+
chartContainer,
|
|
146
|
+
setPref, insertText, buttonyes, font, lang, prev,
|
|
147
|
+
rowceil, colsOverRemainder, appliedFormats, displayTypes,
|
|
148
|
+
captionContent
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Todo: Restore
|
|
152
|
+
// await this.resizecells({sizeToContent: true});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export {chartBuild, getChartBuild};
|