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.
Files changed (143) hide show
  1. package/.nyc_output/out.json +8980 -1849
  2. package/CHANGES.md +15 -1
  3. package/README.md +6 -11
  4. package/_locales/en-US/messages.json +153 -6
  5. package/_locales/hu-HU/messages.json +153 -6
  6. package/_locales/pt-BR/messages.json +153 -6
  7. package/_locales/sv-SE/messages.json +153 -6
  8. package/babel.config.json +0 -1
  9. package/browser_action/characterSelection.js +18 -11
  10. package/browser_action/charrefConverters.js +286 -79
  11. package/browser_action/chartBuild.js +97 -27
  12. package/browser_action/encodingBehaviors.js +10 -7
  13. package/browser_action/entityBehaviors.js +42 -16
  14. package/browser_action/index-es.html +13 -1
  15. package/browser_action/index-instrumented.html +13 -1
  16. package/browser_action/index-pages.html +13 -1
  17. package/browser_action/index.html +13 -1
  18. package/browser_action/index.iife.min.js +9 -1
  19. package/browser_action/index.iife.min.js.map +1 -1
  20. package/browser_action/index.instrumented.iife.min.js +1 -1
  21. package/browser_action/index.instrumented.iife.min.js.map +1 -1
  22. package/browser_action/index.js +5 -5
  23. package/browser_action/preferences/prefDefaults.js +12 -3
  24. package/browser_action/service-worker/sw-activateCallback.js +1 -2
  25. package/browser_action/service-worker/sw-resources.json +6 -4
  26. package/browser_action/templateUtils/elements.js +12 -1
  27. package/browser_action/templateUtils/fill.js +6 -0
  28. package/browser_action/templateUtils/validation.js +4 -1
  29. package/browser_action/templates/chartBuild.js +167 -102
  30. package/browser_action/templates/index.js +227 -53
  31. package/browser_action/templatesElementCustomization/widgets.js +40 -15
  32. package/browser_action/unicode/UnicodeConverter.js +99 -73
  33. package/browser_action/unicode/charrefunicodeDb.js +100 -50
  34. package/browser_action/unicode/getScriptInfoForCodePoint.js +13 -4
  35. package/browser_action/unicode/hangul.js +27 -20
  36. package/browser_action/unicode/lastScriptNames.json +1 -1
  37. package/browser_action/unicode/parseUnihanFromTextFileStrings.js +44 -25
  38. package/browser_action/unicode/unicodeFieldInfo.js +112 -90
  39. package/browser_action/unicode/unicodeScripts.js +409 -35
  40. package/browser_action/unicode/unihan.js +4 -3
  41. package/browser_action/unicode/unihanDbPopulate.js +7 -2
  42. package/browser_action/unicode/unihanFields.js +34 -0
  43. package/browser_action/unicodecharref.js +353 -190
  44. package/browser_action/utils/DOMUtils.js +95 -34
  45. package/browser_action/utils/FetchUtils.js +7 -6
  46. package/browser_action/utils/TextUtils.js +4 -4
  47. package/browser_action/utils/TypedArrayUtils.js +9 -5
  48. package/browser_action/utils/semicolonSeparatedToArray.js +3 -3
  49. package/browser_action/utils/setupServiceWorker.js +2 -2
  50. package/eslint.config.js +11 -0
  51. package/icons/openWindow16.png +0 -0
  52. package/icons/openWindow24.png +0 -0
  53. package/lib/background.html +7 -0
  54. package/lib/background.js +2 -2
  55. package/package.json +80 -70
  56. package/pnpm-workspace.yaml +8 -0
  57. package/server.js +66 -51
  58. package/sw.js +97 -56
  59. package/tools/entities-import.js +4 -1
  60. package/tools/findEsResources.js +33 -10
  61. package/tools/fix-sw-resources-vendor-paths.js +60 -0
  62. package/tools/list-locales.js +2 -2
  63. package/tools/parseUnicodeCharts.js +126 -60
  64. package/tools/ucd-import.js +1 -10
  65. package/tools/unicode-charts.html +49 -20
  66. package/tools/unihan-import.js +45 -15
  67. package/tools/write-sw-version.js +16 -0
  68. package/tsconfig.json +23 -0
  69. package/typings/__coverage__.d.ts +5 -0
  70. package/typings/apple-system-profiler.d.ts +17 -0
  71. package/typings/commands.d.ts +19 -0
  72. package/typings/json-6.d.ts +4 -0
  73. package/typings/rollup-plugin-istanbul.d.ts +3 -0
  74. package/vendor/camelcase/index.d.ts +154 -0
  75. package/vendor/camelcase/index.js +137 -23
  76. package/vendor/fflate/esm/browser.d.ts +1539 -0
  77. package/vendor/fflate/esm/browser.js +82 -55
  78. package/vendor/intl-dom/dist/Formatter.d.ts +120 -0
  79. package/vendor/intl-dom/dist/Formatter.d.ts.map +1 -0
  80. package/vendor/intl-dom/dist/collation.d.ts +42 -0
  81. package/vendor/intl-dom/dist/collation.d.ts.map +1 -0
  82. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts +52 -0
  83. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts.map +1 -0
  84. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts +96 -0
  85. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts.map +1 -0
  86. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts +17 -0
  87. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts.map +1 -0
  88. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts +285 -0
  89. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts.map +1 -0
  90. package/vendor/intl-dom/dist/findLocaleStrings.d.ts +88 -0
  91. package/vendor/intl-dom/dist/findLocaleStrings.d.ts.map +1 -0
  92. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts +67 -0
  93. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts.map +1 -0
  94. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts +73 -0
  95. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts.map +1 -0
  96. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts +26 -0
  97. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts.map +1 -0
  98. package/vendor/intl-dom/dist/i18n.d.ts +113 -0
  99. package/vendor/intl-dom/dist/i18n.d.ts.map +1 -0
  100. package/vendor/intl-dom/dist/index.d.ts +92 -0
  101. package/vendor/intl-dom/dist/index.d.ts.map +1 -0
  102. package/vendor/intl-dom/dist/index.esm.d.ts +34 -0
  103. package/vendor/intl-dom/dist/index.esm.js +854 -896
  104. package/vendor/intl-dom/dist/index.esm.min.js +4 -0
  105. package/vendor/intl-dom/dist/index.esm.min.js.map +1 -0
  106. package/vendor/intl-dom/dist/index.umd.js +2953 -0
  107. package/vendor/intl-dom/dist/index.umd.min.js +4 -0
  108. package/vendor/intl-dom/dist/index.umd.min.js.map +1 -0
  109. package/vendor/intl-dom/dist/promiseChainForValues.d.ts +34 -0
  110. package/vendor/intl-dom/dist/promiseChainForValues.d.ts.map +1 -0
  111. package/vendor/intl-dom/dist/shared.d.ts +20 -0
  112. package/vendor/intl-dom/dist/shared.d.ts.map +1 -0
  113. package/vendor/intl-dom/dist/utils.d.ts +53 -0
  114. package/vendor/intl-dom/dist/utils.d.ts.map +1 -0
  115. package/vendor/jamilih/dist/jml.d.mts +468 -0
  116. package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +1489 -343
  117. package/vendor/jquery/dist/jquery.js +1677 -2713
  118. package/vendor/json-6/dist/index.mjs +2 -0
  119. package/vendor/miller-columns/CHANGES.md +185 -0
  120. package/vendor/miller-columns/LICENSE-MIT.txt +21 -0
  121. package/vendor/miller-columns/README.md +249 -0
  122. package/vendor/miller-columns/demos/index.html +69 -0
  123. package/vendor/miller-columns/demos/index.js +72 -0
  124. package/vendor/miller-columns/dist/index-es.js +748 -0
  125. package/vendor/miller-columns/dist/index-es.min.d.ts +25 -0
  126. package/vendor/miller-columns/dist/index-es.min.js +7 -1
  127. package/vendor/miller-columns/dist/index-umd.js +757 -0
  128. package/vendor/miller-columns/dist/index-umd.min.js +7 -0
  129. package/vendor/miller-columns/dist/index.d.ts +25 -0
  130. package/vendor/miller-columns/dist/millerColumns.d.ts +10 -0
  131. package/vendor/miller-columns/eslint.config.js +46 -0
  132. package/vendor/miller-columns/fix-declarations.js +18 -0
  133. package/vendor/miller-columns/miller-columns.css +24 -1
  134. package/vendor/miller-columns/package.json +73 -0
  135. package/vendor/miller-columns/pnpm-workspace.yaml +2 -0
  136. package/vendor/miller-columns/src/index.js +642 -0
  137. package/vendor/miller-columns/src/millerColumns.ts +12 -0
  138. package/vendor/miller-columns/tsconfig-prod.json +23 -0
  139. package/vendor/miller-columns/tsconfig.json +21 -0
  140. package/vendor/simple-prefs/dist/index.esm.d.ts +1 -0
  141. package/vendor/simple-prefs/dist/index.esm.js +164 -216
  142. package/vendor/simple-prefs/dist/simple-prefs.d.ts +117 -0
  143. package/lgtm.yml +0 -5
@@ -1,33 +1,68 @@
1
1
  /* eslint-disable camelcase -- Temporary */
2
2
  // See https://unicode.org/Public/UNIDATA/ for data use
3
3
 
4
- import {$, $$, jml} from '../vendor/jamilih/dist/jml-es.js';
4
+ import {$$, jml} from 'jamilih/dist/jml.js';
5
5
  // Todo: Filed the following to avoid both sync and callbacks:
6
6
  // https://github.com/101arrowz/fflate/issues/70
7
- import {strFromU8} from '../vendor/fflate/esm/browser.js'; // unzipSync,
7
+ import {strFromU8} from 'fflate'; // unzipSync,
8
+ import camelCase from 'camelcase';
9
+
8
10
  import {
9
11
  getUnicodeDefaults, getPrefDefaults
10
12
  } from './preferences/prefDefaults.js';
11
13
  import {chartBuild, lastStartCharCode} from './chartBuild.js';
12
14
 
13
- import camelCase from '../vendor/camelcase/index.js';
14
15
  import {insertIntoOrOverExisting} from './utils/TextUtils.js';
15
16
  import {joinChunks} from './utils/TypedArrayUtils.js';
16
17
  import {
17
18
  placeItem, removeViewChildren, createHTMLElement,
18
- showProgress
19
+ showProgress, $, $s, $i, $o, $t, $tabbox, $tabpanel
19
20
  } from './utils/DOMUtils.js';
20
21
  import getScriptInfoForCodePoint from './unicode/getScriptInfoForCodePoint.js';
21
22
  import charrefunicodeDb, {UnihanDatabase} from './unicode/charrefunicodeDb.js';
22
23
  import {getCJKTypeFromHexString} from './unicode/unihan.js';
23
24
  import unihanDbPopulate from './unicode/unihanDbPopulate.js';
25
+ import unihanFields from './unicode/unihanFields.js';
24
26
  // import parseUnihanFromTextFileStrings from
25
27
  // './unicode/parseUnihanFromTextFileStrings.js';
26
28
  import {registerDTD} from './entityBehaviors.js';
27
29
  import {entities, numericCharacterReferences} from './entities.js';
28
30
  import {findBridgeForTargetID} from './charrefConverters.js';
29
31
 
30
- let _, charrefunicodeConverter, getPref, setPref;
32
+ /* eslint-disable jsdoc/reject-any-type -- Arbitrary */
33
+ /**
34
+ * @typedef {any} AnyValue
35
+ */
36
+ /* eslint-enable jsdoc/reject-any-type -- Arbitrary */
37
+
38
+ /**
39
+ * @typedef {number} Integer
40
+ */
41
+
42
+ /** @type {import('intl-dom').I18NCallback<string>} */
43
+ let _;
44
+
45
+ /**
46
+ * @type {InstanceType<ReturnType<
47
+ * typeof import('./unicode/UnicodeConverter.js').getUnicodeConverter
48
+ * >>}
49
+ */
50
+ let charrefunicodeConverter;
51
+
52
+ /** @type {ReturnType<typeof getUnicodeDefaults>['getPref']} */
53
+ let getPref;
54
+ /** @type {ReturnType<typeof getUnicodeDefaults>['setPref']} */
55
+ let setPref;
56
+
57
+ /**
58
+ * @param {{
59
+ * _: import('intl-dom').I18NCallback<string>
60
+ * charrefunicodeConverter: InstanceType<ReturnType<
61
+ * typeof import('./unicode/UnicodeConverter.js').getUnicodeConverter
62
+ * >>
63
+ * }} cfg
64
+ * @returns {void}
65
+ */
31
66
  export const shareVars = ({_: l10n, charrefunicodeConverter: _uc}) => {
32
67
  _ = l10n;
33
68
  charrefunicodeConverter = _uc;
@@ -45,7 +80,9 @@ async function getDownloadResults () {
45
80
  /* istanbul ignore next -- For GitHub Pages only */
46
81
  ? '/unicode-input-toolconverter/download/unihan/unihan.json'
47
82
  : '/download/unihan/unihan.json',
48
- progressElement: $('#progress_element'),
83
+ progressElement: /** @type {HTMLProgressElement} */ (
84
+ $('#progress_element')
85
+ ),
49
86
  progress (percentComplete) {
50
87
  return `${_('download_progress')} ${
51
88
  percentComplete.toFixed(2)
@@ -71,6 +108,23 @@ async function getDownloadResults () {
71
108
  }
72
109
 
73
110
  const unicodecharref = {
111
+ /** @type {string[]} */
112
+ origents: [],
113
+
114
+ /** @type {number[]} */
115
+ origcharrefs: [],
116
+
117
+ /** @type {string[]} */
118
+ orignewents: [],
119
+
120
+ /** @type {(string|number)[]} */
121
+ orignewcharrefs: [],
122
+
123
+ /** @type {UnihanDatabase|null} */
124
+ unihanDatabase: null,
125
+
126
+ unihanDb_exists: false,
127
+
74
128
  async downloadUnihan () {
75
129
  $('#DownloadButtonBox').hidden = true;
76
130
  $('#DownloadProgressBox').hidden = false;
@@ -261,28 +315,32 @@ const unicodecharref = {
261
315
  }
262
316
  },
263
317
  */
318
+ /**
319
+ * @param {...string} els
320
+ */
264
321
  setupBoolChecked (...els) {
265
322
  els.forEach(async (el) => {
266
- $('#' + el).checked = await getPref(el);
323
+ /** @type {HTMLInputElement} */
324
+ ($('#' + el)).checked = /** @type {boolean} */ (await getPref(el));
267
325
  });
268
326
  },
269
327
  /**
270
- * @param {PlainObject} cfg
271
- * @param {boolean} [cfg.customProtocol]
272
- * @param {boolean} [cfg.options]
273
- * @param {string} [cfg.convert]
274
- * @param {string} [cfg.targetid]
275
- * @param {string} [cfg.selection]
276
- * @returns {Promise<void>}
277
- */
328
+ * @param {object} cfg
329
+ * @param {string|null} [cfg.customProtocol]
330
+ * @param {string|null} [cfg.options]
331
+ * @param {string|null} [cfg.convert]
332
+ * @param {string|null} [cfg.targetid]
333
+ * @param {string} [cfg.selection]
334
+ * @returns {Promise<void>}
335
+ */
278
336
  async initialize (cfg) {
279
337
  // this.refreshToolbarDropdown(); // redundant?
280
338
 
281
339
  this.unihanDb_exists = false;
282
340
  try {
283
- const namespace = 'unicode-input-toolconverter-Unihan';
341
+ // const namespace = 'unicode-input-toolconverter-Unihan';
284
342
  this.unihanDatabase = new UnihanDatabase({
285
- name: namespace,
343
+ // name: namespace,
286
344
  // We don't peg to package major version as database version may vary
287
345
  // independently
288
346
  version: 1
@@ -298,7 +356,7 @@ const unicodecharref = {
298
356
  $('#UnihanInstalled').hidden = false;
299
357
  } catch (e) {
300
358
  /* istanbul ignore if -- Only expected for transactions */
301
- if (!e.message.includes('ransaction')) {
359
+ if (!(/** @type {Error} */ (e)).message.includes('ransaction')) {
302
360
  // eslint-disable-next-line no-console -- Debug
303
361
  console.error(e);
304
362
  }
@@ -308,10 +366,11 @@ const unicodecharref = {
308
366
 
309
367
  // document.documentElement.maxWidth =
310
368
  // window.screen.availWidth-(window.screen.availWidth*1/100);
311
- $('#unicodeTabBox').style.maxWidth = window.screen.availWidth -
312
- (window.screen.availWidth * 3 / 100);
313
- $('#unicodeTabBox > .tabs').style.maxWidth =
314
- window.screen.availWidth - (window.screen.availWidth * 3 / 100);
369
+ $('#unicodeTabBox').style.maxWidth = String(window.screen.availWidth -
370
+ (window.screen.availWidth * 3 / 100));
371
+ $('#unicodeTabBox > .tabs').style.maxWidth = String(
372
+ window.screen.availWidth - (window.screen.availWidth * 3 / 100)
373
+ );
315
374
  /*
316
375
  $('#unicodeTabBox').style.maxHeight =
317
376
  window.screen.availHeight-(window.screen.availHeight*5/100);
@@ -346,15 +405,15 @@ const unicodecharref = {
346
405
  DTDtxtbxval
347
406
  // outerh, outerw
348
407
  ] = await Promise.all([
349
- getPref('lang'),
350
- getPref('font'),
408
+ /** @type {Promise<string>} */ (getPref('lang')),
409
+ /** @type {Promise<string>} */ (getPref('font')),
351
410
  getPref('initialTab'),
352
411
  getPref('multiline'),
353
412
  getPref('cssWhitespace'),
354
413
  getPref('tblrowsset'),
355
414
  getPref('tblcolsset'),
356
415
  getPref('ampspace'),
357
- getPref('DTDtextbox')
416
+ /** @type {Promise<string>} */ (getPref('DTDtextbox'))
358
417
  // getPref('outerHeight'),
359
418
  // getPref('outerWidth')
360
419
  ]);
@@ -374,7 +433,7 @@ const unicodecharref = {
374
433
  }).map(([key]) => key));
375
434
  switch (cssWhitespace) {
376
435
  case ' ':
377
- $('#CSSWhitespace').selectedIndex = 0;
436
+ $s('#CSSWhitespace').selectedIndex = 0;
378
437
  break;
379
438
  /*
380
439
  // Carriage returns shouldn't survive
@@ -386,13 +445,13 @@ const unicodecharref = {
386
445
  break;
387
446
  */
388
447
  case '\n':
389
- $('#CSSWhitespace').selectedIndex = 1;
448
+ $s('#CSSWhitespace').selectedIndex = 1;
390
449
  break;
391
450
  case '\t':
392
- $('#CSSWhitespace').selectedIndex = 2;
451
+ $s('#CSSWhitespace').selectedIndex = 2;
393
452
  break;
394
453
  case '\f':
395
- $('#CSSWhitespace').selectedIndex = 3;
454
+ $s('#CSSWhitespace').selectedIndex = 3;
396
455
  break;
397
456
  /* istanbul ignore next -- Unexpected value */
398
457
  default:
@@ -413,31 +472,33 @@ const unicodecharref = {
413
472
  // Set the size per the prefs (don't increase or decrease the value)
414
473
  await this.resizecells();
415
474
 
416
- $('#rowsset').value = tblrowsset;
417
- $('#colsset').value = tblcolsset;
475
+ /** @type {HTMLInputElement} */
476
+ ($('#rowsset')).value = String(tblrowsset);
477
+ /** @type {HTMLInputElement} */
478
+ ($('#colsset')).value = String(tblcolsset);
418
479
 
419
480
  // Save copies in case decide to reset later (i.e., not append to
420
481
  // HTML entities, then wish to append to them again)
421
- this.origents = [];
422
- this.origcharrefs = [];
423
- this.orignewents = [];
424
- this.orignewcharrefs = [];
425
482
 
426
483
  this.origents = [...entities];
427
484
  this.origcharrefs = [...numericCharacterReferences];
428
485
  this.orignewents = [...charrefunicodeConverter.newents];
429
486
  this.orignewcharrefs = [...charrefunicodeConverter.newcharrefs];
430
487
 
431
- $('#lang').value = lang;
432
- $('#font').value = font;
433
- $('#initialTab').value = $('#mi_' + initialTab).value;
488
+ $i('#lang').value = lang;
489
+ $i('#font').value = font;
490
+
491
+ $s('#initialTab').value = $o('#mi_' + initialTab).value;
434
492
 
435
- $('#DTDtextbox').value = DTDtxtbxval;
493
+ /** @type {HTMLTextAreaElement} */
494
+ ($('#DTDtextbox')).value = DTDtxtbxval;
436
495
  await registerDTD();
437
496
 
438
497
  // These defaults are necessary for the sake of the options URL
439
498
  // (when called from addons menu)
440
499
  let toconvert = null;
500
+
501
+ /** @type {string|null|undefined} */
441
502
  let targetid = '';
442
503
  // const targetid = 'context-launchunicode';
443
504
 
@@ -477,10 +538,10 @@ const unicodecharref = {
477
538
  toconvert = cfg.convert || '';
478
539
  ({targetid} = cfg);
479
540
  // toconvert = charreftoconvert.replace(/\n/g, ' ');
480
- $('#toconvert').value = toconvert;
541
+ $t('#toconvert').value = toconvert;
481
542
 
482
543
  if (ampspace) {
483
- toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gu, '&amp;$1');
544
+ toconvert = toconvert.replaceAll(/&([^;\s]*\s)/gv, '&amp;$1');
484
545
  }
485
546
 
486
547
  if (targetid) {
@@ -491,61 +552,71 @@ const unicodecharref = {
491
552
  // Detect which context menu item was selected:
492
553
  let out = ''; // converttypeid;
493
554
 
494
- if (bridgeResult !== false && bridgeResult !== undefined) {
555
+ if (
556
+ // bridgeResult !== false &&
557
+ bridgeResult !== undefined
558
+ ) {
495
559
  out = bridgeResult;
496
560
  } else {
497
561
  switch (targetid) {
498
562
  case 'context-unicodechart':
499
563
  await this.disableEnts();
500
- $('#startset').value = chr;
501
- $('#unicodeTabBox').$selectTabForTabPanel($('#charts'));
564
+ $i('#startset').value = String(chr);
565
+ $tabbox('#unicodeTabBox').$selectTabForTabPanel($tabpanel('#charts'));
502
566
  // Fallthrough
503
567
  case 'context-launchunicode':
504
568
  case 'tools-charrefunicode':
505
- out = '';
569
+ // out = '';
506
570
  break;
507
571
  case 'searchName':
508
- $('#' + targetid).value = unicodeQueryObj.get('string');
572
+ $i('#' + targetid).value = String(unicodeQueryObj?.get('string'));
509
573
  $('#' + targetid).focus();
510
574
  await this.searchUnicode({
511
- id: targetid, value: unicodeQueryObj.get('string')
575
+ id: targetid, value: String(unicodeQueryObj?.get('string'))
512
576
  }); // Assume non-CJK
513
577
  break;
514
578
  case 'searchkDefinition':
515
- $('#' + targetid).value = unicodeQueryObj.get('string');
516
- $('#' + targetid).focus();
579
+ $i('#' + targetid).value = String(unicodeQueryObj?.get('string'));
580
+ $i('#' + targetid).focus();
517
581
  await this.searchUnihan({
518
- id: targetid, value: unicodeQueryObj.get('string')
582
+ id: targetid, value: String(unicodeQueryObj?.get('string'))
519
583
  });
520
584
  break;
521
585
  default:
522
- out = ''; // Plain launcher with no values sent
586
+ // out = ''; // Plain launcher with no values sent
523
587
  // const prefstab = true;
524
588
  break;
525
589
  }
526
590
  }
527
- $('#converted').value = out;
591
+ $t('#converted').value = out;
528
592
 
529
593
  if (!customProtocol) {
530
594
  if (cfg.options) { // options menu
531
- $('#unicodeTabBox').$selectTabForTabPanel($('#prefs'));
595
+ $tabbox('#unicodeTabBox').$selectTabForTabPanel($tabpanel('#prefs'));
532
596
  } else if (toconvert !== null && targetid) {
533
597
  // Keyboard invocation or button
534
598
  // $('#unicodetabs').selectedIndex = 0; // Fix: set by preference
535
- $('#unicodeTabBox').$selectTabForTabPanel($('#conversion'));
599
+ $tabbox('#unicodeTabBox').$selectTabForTabPanel(
600
+ $tabpanel('#conversion')
601
+ );
536
602
  } else if (
537
603
  targetid !== 'context-unicodechart' &&
538
604
  targetid !== 'tools-charrefunicode'
539
605
  ) {
540
- $('#unicodeTabBox').$selectTabForTabPanel(
541
- $('#' + initialTab)
606
+ $tabbox('#unicodeTabBox').$selectTabForTabPanel(
607
+ $tabpanel('#' + initialTab)
542
608
  );
543
609
  }
544
610
  }
545
611
 
546
612
  if (targetid !== 'searchName' && targetid !== 'searchkDefinition') {
547
613
  if (toconvert || chr) { // Seemed to become necessarily suddenly
548
- await this.setCurrstartset((toconvert || chr).codePointAt() - 1);
614
+ await this.setCurrstartset(
615
+ /** @type {number} */ (
616
+ /** @type {string} */
617
+ (toconvert || chr).codePointAt(0)
618
+ ) - 1
619
+ );
549
620
  }
550
621
  await chartBuild();
551
622
  }
@@ -573,25 +644,33 @@ const unicodecharref = {
573
644
  });
574
645
  */
575
646
  },
576
- async copyToClipboard (id) {
577
- const text = $(id).value;
647
+ /**
648
+ * @param {string} sel
649
+ */
650
+ async copyToClipboard (sel) {
651
+ const text = $t(sel).value;
578
652
  await navigator.clipboard.writeText(text);
579
653
  alert(_('copiedToClipboard'));
580
654
  },
655
+ /**
656
+ * @param {{target: {type: string, id: string, value: string}}} e
657
+ */
581
658
  async setprefs (e) {
582
- switch (e.target.type) {
659
+ // eslint-disable-next-line prefer-destructuring -- TS
660
+ const target = /** @type {HTMLInputElement} */ (e.target);
661
+ switch (target.type) {
583
662
  case 'select-one': case 'text':
584
663
  return await setPref(
585
- e.target.id,
586
- e.target.value
664
+ target.id,
665
+ target.value
587
666
  );
588
667
  case 'checkbox':
589
- return await setPref(e.target.id, Boolean(e.target.checked));
668
+ return await setPref(target.id, Boolean(target.checked));
590
669
  /*
591
670
  // Should work but not in use
592
671
  case 'radio': {
593
672
  let radioid;
594
- const result = e.target.id.match(/^_(\d)+-(.*)$/u);
673
+ const result = target.id.match(/^_(\d)+-(.*)$/u);
595
674
  if (result !== null) {
596
675
  radioid = result[2]; // Extract preference name
597
676
  return await setPref(radioid, result[1] === '1');
@@ -618,18 +697,18 @@ const unicodecharref = {
618
697
  'xmlentkeep', 'ampkeep', 'appendtohtmldtd', 'cssUnambiguous'
619
698
  ], true);
620
699
 
621
- $('#ampspace').checked = false;
700
+ $i('#ampspace').checked = false;
622
701
  // $('#showComplexWindow').checked = false;
623
- $('#showAllDetailedView').checked = true;
624
- $('#showAllDetailedCJKView').checked = true;
702
+ $i('#showAllDetailedView').checked = true;
703
+ $i('#showAllDetailedCJKView').checked = true;
625
704
 
626
705
  /**
627
- * @param {string} langOrFont
628
- * @returns {string}
629
- */
706
+ * @param {string} langOrFont
707
+ * @returns {Promise<string>}
708
+ */
630
709
  async function langFont (langOrFont) { // Fix: needs to get default!
631
- const deflt = await getPref(langOrFont);
632
- $('#' + langOrFont).value = deflt;
710
+ const deflt = /** @type {string} */ (await getPref(langOrFont));
711
+ $i('#' + langOrFont).value = deflt;
633
712
  await setPref(langOrFont, deflt);
634
713
  return deflt;
635
714
  }
@@ -656,16 +735,18 @@ const unicodecharref = {
656
735
  // Don't really need to reset since user can't currently change
657
736
  // this (only for blank string entry)
658
737
  await setPref(
659
- 'startset', 'a'.codePointAt() - 1
738
+ 'startset', /** @type {number} */ ('a'.codePointAt(0)) - 1
660
739
  );
661
740
 
662
- await this.setCurrstartset(await getPref('startset'));
741
+ await this.setCurrstartset(
742
+ /** @type {number} */ (await getPref('startset'))
743
+ );
663
744
 
664
745
  // These get activated in chartBuild(); below
665
746
  await setPref('tblrowsset', 4);
666
- $('#rowsset').value = 4;
747
+ $i('#rowsset').value = '4';
667
748
  await setPref('tblcolsset', 3);
668
- $('#colsset').value = 3;
749
+ $i('#colsset').value = '3';
669
750
 
670
751
  await this.setBoolChecked([
671
752
  'entyes', 'hexyes', 'decyes', 'unicodeyes', 'buttonyes'
@@ -678,7 +759,7 @@ const unicodecharref = {
678
759
  // $('#xstyle').checked = true;
679
760
 
680
761
  await setPref('initialTab', 'charts');
681
- $('#initialTab').value = $('#mi_charts').value;
762
+ $s('#initialTab').value = $o('#mi_charts').value;
682
763
 
683
764
  await setPref('tblfontsize', 13);
684
765
  await this.resizecells();
@@ -701,20 +782,27 @@ const unicodecharref = {
701
782
  els = typeof els === 'string' ? [els] : els;
702
783
  return await Promise.all(els.map(async (el) => {
703
784
  await setPref(el, value);
704
- $('#' + el).checked = value;
785
+ $i('#' + el).checked = value;
705
786
  }));
706
787
  },
707
788
 
708
789
  // End UI bridges
709
790
 
710
- async setImagePref (ev) {
711
- await this.setprefs(ev);
791
+ /**
792
+ * @param {{target: {type: string, id: string, value: string}}} e
793
+ */
794
+ async setImagePref (e) {
795
+ await this.setprefs(e);
712
796
  if ($('#unicodeImg').firstChild) {
713
- $('#unicodeImg').firstChild.remove();
797
+ $('#unicodeImg').firstChild?.remove();
714
798
  }
715
799
  return false;
716
800
  },
717
801
 
802
+ /**
803
+ * @param {string} kent
804
+ * @param {string} khextemp
805
+ */
718
806
  async getUnicodeDescription (kent, khextemp) {
719
807
  const hideMissing = !(await getPref('showAllDetailedView'));
720
808
  const hideMissingUnihan = !(await getPref('showAllDetailedCJKView'));
@@ -724,9 +812,11 @@ const unicodecharref = {
724
812
 
725
813
  if (
726
814
  !unihanType && !hangul &&
727
- $('#viewTabs').$selectedTab() === $('#detailedCJKView')
815
+ $tabbox('#viewTabs').$selectedTab() === $('#detailedCJKView')
728
816
  ) {
729
- $('#viewTabs').$selectTabForTabPanel($('#detailedView'));
817
+ $tabbox('#viewTabs').$selectTabForTabPanel(
818
+ $tabpanel('#detailedView')
819
+ );
730
820
  }
731
821
 
732
822
  const kdectemp = Number.parseInt(khextemp, 16);
@@ -744,13 +834,13 @@ const unicodecharref = {
744
834
  if (i === this.kDefinitionIndex) {
745
835
  continue;
746
836
  }
747
- $('#_detailedCJKView' + i).value = '';
837
+ $t('#_detailedCJKView' + i).value = '';
748
838
  }
749
839
  for (const prop of this.Unihan) {
750
840
  // eslint-disable-next-line @stylistic/max-len -- Long
751
841
  /* istanbul ignore next -- May not be generated based on `showComplexWindow` */
752
- if ($('#searchk' + prop)) {
753
- $('#searchk' + prop).value = '';
842
+ if ($i('#searchk' + prop)) {
843
+ $i('#searchk' + prop).value = '';
754
844
  }
755
845
  }
756
846
  }
@@ -776,21 +866,22 @@ const unicodecharref = {
776
866
  let temp = results[camelizedField];
777
867
  if (unicodeField === 'Unicode_1_Name') {
778
868
  if (temp) {
779
- result += ';\u00A0\u00A0\u00A0\u00A0\n' +
869
+ result += ';\u{A0}\u{A0}\u{A0}\u{A0}\n' +
780
870
  _('searchUnicode_1_Name') + _('colon') + ' ' + temp;
781
871
  }
782
872
  continue;
783
873
  }
784
874
  if (temp) {
785
875
  if (hideMissing) {
786
- $('#_detailedView' + i).parentNode.hidden = false;
876
+ /** @type {HTMLElement} */
877
+ ($('#_detailedView' + i).parentNode).hidden = false;
787
878
  }
788
879
  switch (unicodeField) {
789
880
  case 'General_Category':
790
881
  temp = _('General_Category' + temp);
791
882
  break;
792
883
  case 'Canonical_Combining_Class':
793
- if (temp < 11 || temp > 132) {
884
+ if (Number(temp) < 11 || Number(temp) > 132) {
794
885
  // 199, 200, 204, 208, 210, 212 do not have members yet and
795
886
  // others from 11 to 132 do not have name listed
796
887
  temp = _('Canonical_Combining_Class' + temp);
@@ -800,9 +891,8 @@ const unicodecharref = {
800
891
  temp = _('Bidi_Class' + temp);
801
892
  break;
802
893
  case 'Bidi_Mirrored':
803
- temp = (temp === 'Y')
804
- ? _('Bidi_MirroredY')
805
- : _('Bidi_MirroredN'); // Only two choices
894
+ // Only two choices
895
+ temp = _(temp === 'Y' ? 'Bidi_MirroredY' : 'Bidi_MirroredN');
806
896
  break;
807
897
  case 'numericType': {
808
898
  const view = $('#_detailedView' + i);
@@ -836,13 +926,19 @@ const unicodecharref = {
836
926
  // eslint-disable-next-line no-script-url -- This is controlled
837
927
  a.href = 'javascript:void(0)';
838
928
 
839
- a.addEventListener('click', async (e) => {
840
- await unicodecharref.startset({
841
- value: e.target.textContent
842
- });
843
- // Probably want to start checking again since move to new page
844
- // that.noGetDescripts = false;
845
- });
929
+ a.addEventListener(
930
+ 'click',
931
+ async (e) => {
932
+ await unicodecharref.startset({
933
+ value: /** @type {HTMLElement} */ (
934
+ e.target
935
+ ).textContent
936
+ });
937
+ // Probably want to start checking again since
938
+ // move to new page
939
+ // that.noGetDescripts = false;
940
+ }
941
+ );
846
942
  const tempno = Number.parseInt(temp, 16);
847
943
  a.textContent = String.fromCodePoint(tempno);
848
944
  a.className = 'text-link';
@@ -861,41 +957,43 @@ const unicodecharref = {
861
957
  }
862
958
  // Not casing
863
959
  if (
864
- !unicodeField.includes('case_Mapping') &&
865
- unicodeField !== 'decompositionMapping'
960
+ unicodeField !== 'decompositionMapping' &&
961
+ !unicodeField.includes('case_Mapping')
866
962
  ) {
867
- $('#_detailedView' + i).value = temp;
963
+ $i('#_detailedView' + i).value = temp;
868
964
  }
869
965
  // Not casing
870
966
  } else if (
871
- !unicodeField.includes('case_Mapping') &&
872
- unicodeField !== 'decompositionMapping'
967
+ unicodeField !== 'decompositionMapping' &&
968
+ !unicodeField.includes('case_Mapping')
873
969
  ) {
874
- $('#_detailedView' + i).parentNode.hidden = hideMissing;
875
- $('#_detailedView' + i).value = '';
970
+ /** @type {HTMLElement} */
971
+ ($i('#_detailedView' + i).parentNode).hidden = hideMissing;
972
+ $i('#_detailedView' + i).value = '';
876
973
  } else {
877
- $('#_detailedView' + i).parentNode.hidden = hideMissing;
974
+ /** @type {HTMLElement} */
975
+ ($i('#_detailedView' + i).parentNode).hidden = hideMissing;
878
976
  removeViewChildren(i);
879
977
  }
880
978
  }
881
979
  }
882
980
 
883
981
  if (!unihanType) {
884
- $('#displayUnicodeDesc').value = kent +
982
+ $t('#displayUnicodeDesc').value = kent +
885
983
  'U+' + khextemp + _('colon') + ' ' + result;
886
- $('#displayUnicodeDesc2').value = kent +
984
+ $t('#displayUnicodeDesc2').value = kent +
887
985
  'U+' + khextemp + _('colon') + ' ' + result;
888
986
  }
889
987
  } catch {
890
988
  if (surrogate) {
891
- $('#displayUnicodeDesc').value = kent +
989
+ $t('#displayUnicodeDesc').value = kent +
892
990
  'U+' + khextemp + _('colon') + ' ' + surrogate;
893
- $('#displayUnicodeDesc2').value = kent +
991
+ $t('#displayUnicodeDesc2').value = kent +
894
992
  'U+' + khextemp + _('colon') + ' ' + surrogate;
895
993
  } else if (privateuse) {
896
- $('#displayUnicodeDesc').value = kent +
994
+ $t('#displayUnicodeDesc').value = kent +
897
995
  'U+' + khextemp + _('colon') + ' ' + _('Private_use_character');
898
- $('#displayUnicodeDesc2').value = kent +
996
+ $t('#displayUnicodeDesc2').value = kent +
899
997
  'U+' + khextemp + _('colon') + ' ' + _('Private_use_character');
900
998
  } else if ( // Catch noncharacters
901
999
  (kdectemp >= 0xFDD0 && kdectemp <= 0xFDEF) ||
@@ -920,22 +1018,23 @@ const unicodecharref = {
920
1018
  (kdectemp >= 0x10FFFE && kdectemp <= 0x10FFFF)
921
1019
  */
922
1020
  ) {
923
- $('#displayUnicodeDesc').value = kent +
1021
+ $t('#displayUnicodeDesc').value = kent +
924
1022
  'U+' + khextemp + _('colon') + ' ' + _('Noncharacter');
925
- $('#displayUnicodeDesc2').value = kent +
1023
+ $t('#displayUnicodeDesc2').value = kent +
926
1024
  'U+' + khextemp + _('colon') + ' ' + _('Noncharacter');
927
1025
  } else {
928
1026
  const notfoundval = 'U+' + khextemp + _('colon') + ' ' + _('Not_found');
929
- $('#displayUnicodeDesc').value = notfoundval;
930
- $('#displayUnicodeDesc2').value = notfoundval;
1027
+ $t('#displayUnicodeDesc').value = notfoundval;
1028
+ $t('#displayUnicodeDesc2').value = notfoundval;
931
1029
  }
932
1030
  for (const [j, unicodeField] of unicodecharref.Unicode.entries()) {
933
1031
  if (unicodeField === 'Unicode_1_Name') {
934
1032
  continue;
935
1033
  }
936
1034
  try {
937
- $('#_detailedView' + j).value = '';
938
- $('#_detailedView' + j).parentNode.hidden = hideMissing;
1035
+ $i('#_detailedView' + j).value = '';
1036
+ /** @type {HTMLElement} */
1037
+ ($('#_detailedView' + j).parentNode).hidden = hideMissing;
939
1038
  removeViewChildren(j);
940
1039
  /* istanbul ignore next -- Debugging */
941
1040
  } catch (err) {
@@ -951,7 +1050,7 @@ const unicodecharref = {
951
1050
  if (this.unihanDb_exists) {
952
1051
  try {
953
1052
  // $('#displayUnicodeDesc').value= _('retrieving_description');
954
- const results = await this.unihanDatabase.getUnicodeFields(khextemp);
1053
+ const results = await this.unihanDatabase?.getUnicodeFields(khextemp);
955
1054
  if (results) {
956
1055
  // Fix: display data more readably, with heading, etc. (and
957
1056
  // conditional)
@@ -978,7 +1077,8 @@ const unicodecharref = {
978
1077
  }
979
1078
  if (temp) {
980
1079
  if (hideMissingUnihan) {
981
- $('#_detailedCJKView' + i).parentNode.hidden = false;
1080
+ /** @type {HTMLElement} */
1081
+ ($('#_detailedCJKView' + i).parentNode).hidden = false;
982
1082
  }
983
1083
  /*
984
1084
  switch (i) {
@@ -992,10 +1092,12 @@ const unicodecharref = {
992
1092
  break;
993
1093
  }
994
1094
  */
995
- $('#_detailedCJKView' + i).value = temp;
1095
+ $i('#_detailedCJKView' + i).value = temp;
996
1096
  } else {
997
- $('#_detailedCJKView' + i).parentNode.hidden = hideMissingUnihan;
998
- $('#_detailedCJKView' + i).value = '';
1097
+ /** @type {HTMLElement} */
1098
+ ($i('#_detailedCJKView' + i).parentNode).hidden =
1099
+ hideMissingUnihan;
1100
+ $i('#_detailedCJKView' + i).value = '';
999
1101
  }
1000
1102
  }
1001
1103
  }
@@ -1004,11 +1106,11 @@ const unicodecharref = {
1004
1106
  // Commenting out to show general category under definition
1005
1107
  // $('#displayUnicodeDesc2').value = kent +
1006
1108
  // 'U+' + khextemp + _('colon')+' ' + result;
1007
- $('#displayUnicodeDescUnihan').value = kent +
1109
+ $t('#displayUnicodeDescUnihan').value = kent +
1008
1110
  'U+' + khextemp + _('colon') + ' ' + result;
1009
- $('#displayUnicodeDesc').value = kent +
1111
+ $t('#displayUnicodeDesc').value = kent +
1010
1112
  'U+' + khextemp + _('colon') + ' ' + result;
1011
- $('#displayUnicodeDesc2').value = kent +
1113
+ $t('#displayUnicodeDesc2').value = kent +
1012
1114
  'U+' + khextemp + _('colon') + ' ' + result;
1013
1115
  } else {
1014
1116
  const notfoundval = 'U+' + khextemp + _('colon') + ' ' +
@@ -1020,8 +1122,9 @@ const unicodecharref = {
1020
1122
  continue;
1021
1123
  }
1022
1124
  try {
1023
- $('#_detailedView' + j).value = '';
1024
- $('#_detailedView' + j).parentNode.hidden = hideMissing;
1125
+ $i('#_detailedView' + j).value = '';
1126
+ /** @type {HTMLElement} */
1127
+ ($i('#_detailedView' + j).parentNode).hidden = hideMissing;
1025
1128
  removeViewChildren(j);
1026
1129
  /* istanbul ignore next -- Debugging */
1027
1130
  } catch (e) {
@@ -1037,15 +1140,17 @@ const unicodecharref = {
1037
1140
  if (i === this.kDefinitionIndex) {
1038
1141
  continue;
1039
1142
  }
1040
- $('#_detailedCJKView' + i).parentNode.hidden = hideMissingUnihan;
1041
- $('#_detailedCJKView' + i).value = '';
1143
+ /** @type {HTMLElement} */
1144
+ ($('#_detailedCJKView' + i).parentNode).hidden =
1145
+ hideMissingUnihan;
1146
+ $i('#_detailedCJKView' + i).value = '';
1042
1147
  }
1043
1148
  }
1044
1149
 
1045
1150
  if (!cjkText) {
1046
- $('#displayUnicodeDesc').value = notfoundval;
1047
- $('#displayUnicodeDescUnihan').value = notfoundval;
1048
- $('#displayUnicodeDesc2').value = notfoundval;
1151
+ $i('#displayUnicodeDesc').value = notfoundval;
1152
+ $i('#displayUnicodeDescUnihan').value = notfoundval;
1153
+ $i('#displayUnicodeDesc2').value = notfoundval;
1049
1154
  } else {
1050
1155
  const finalval = kent +
1051
1156
  'U+' + khextemp + _('colon') + ' ' + cjkText +
@@ -1053,9 +1158,9 @@ const unicodecharref = {
1053
1158
  ? ''
1054
1159
  : ' ' + _('left_parenth') + _('No_definition') +
1055
1160
  _('right_parenth'));
1056
- $('#displayUnicodeDesc').value = finalval;
1057
- $('#displayUnicodeDesc2').value = finalval;
1058
- $('#displayUnicodeDescUnihan').value = finalval;
1161
+ $i('#displayUnicodeDesc').value = finalval;
1162
+ $i('#displayUnicodeDesc2').value = finalval;
1163
+ $i('#displayUnicodeDescUnihan').value = finalval;
1059
1164
  // $('#displayUnicodeDesc2').value = notfoundval;
1060
1165
  }
1061
1166
  }
@@ -1068,10 +1173,10 @@ const unicodecharref = {
1068
1173
  } // Excised Ajax code...
1069
1174
 
1070
1175
  if (
1071
- this.unihanDb_exists && unihanType &&
1072
- $('#viewTabs').$selectedTab() === $('#detailedView')
1176
+ unihanType && this.unihanDb_exists &&
1177
+ $tabbox('#viewTabs').$selectedTab() === $('#detailedView')
1073
1178
  ) {
1074
- $('#viewTabs').$selectTabForTabPanel($('#detailedCJKView'));
1179
+ $tabbox('#viewTabs').$selectTabForTabPanel($tabpanel('#detailedCJKView'));
1075
1180
  }
1076
1181
 
1077
1182
  const alink = createHTMLElement('a');
@@ -1084,7 +1189,7 @@ const unicodecharref = {
1084
1189
  placeItem('#pdflink', alink);
1085
1190
 
1086
1191
  // Handle plane #
1087
- const planeText = _('plane_num', {plane}) + '\u00A0';
1192
+ const planeText = _('plane_num', {plane}) + '\u{A0}';
1088
1193
  placeItem('#plane', planeText);
1089
1194
 
1090
1195
  if (await getPref('showImg')) {
@@ -1095,26 +1200,38 @@ const unicodecharref = {
1095
1200
  placeItem('#unicodeImg', img);
1096
1201
  }
1097
1202
  },
1203
+ /**
1204
+ * @param {number} size
1205
+ */
1098
1206
  async fontsizetextbox (size) { // Changes font-size
1099
- const txtbxsize = await getPref('fontsizetextbox') + size;
1207
+ const txtbxsize = /** @type {number} */ (
1208
+ await getPref('fontsizetextbox')
1209
+ ) + size;
1100
1210
  await setPref('fontsizetextbox', txtbxsize);
1101
1211
 
1102
1212
  $('#toconvert').style.fontSize = txtbxsize + 'px';
1103
1213
  $('#converted').style.fontSize = txtbxsize + 'px';
1104
1214
 
1105
1215
  /* istanbul ignore next -- Firefox only */
1106
- if (size > 0 && window.sizeToContent) {
1216
+ if (size > 0 && 'sizeToContent' in globalThis) {
1107
1217
  // On Mac at least, resizing for reducing font size, causes button to
1108
1218
  // go off screen
1109
- window.sizeToContent();
1219
+ // @ts-expect-error Firefox only
1220
+ globalThis.sizeToContent();
1110
1221
  }
1111
1222
  },
1223
+ /**
1224
+ * @param {number} size
1225
+ */
1112
1226
  async tblfontsize (size) { // Changes font-size of chart table cells
1113
- const fsize = await getPref('tblfontsize') + size;
1227
+ const fsize = /** @type {number} */ (await getPref('tblfontsize')) + size;
1114
1228
  // const tds = createHTMLElement('td');
1115
1229
  await setPref('tblfontsize', fsize);
1116
1230
  await this.resizecells({sizeToContent: size > 0});
1117
1231
  },
1232
+ /**
1233
+ * @param {{sizeToContent?: boolean}} cfg
1234
+ */
1118
1235
  async resizecells ({sizeToContent} = {}) {
1119
1236
  await Promise.all($$(
1120
1237
  "*[name='dec'],*[name='hex'],*[name='unicode']"
@@ -1128,44 +1245,75 @@ const unicodecharref = {
1128
1245
  // await getPref('tblfontsize') + 'px';
1129
1246
 
1130
1247
  /* istanbul ignore next -- Firefox only */
1131
- if (sizeToContent && window.sizeToContent) {
1248
+ if (sizeToContent && 'sizeToContent' in globalThis) {
1132
1249
  // On Mac at least, resizing for reducing font size, causes button to
1133
1250
  // go off screen
1134
- window.sizeToContent();
1251
+ // @ts-expect-error Firefox only
1252
+ globalThis.sizeToContent();
1135
1253
  }
1136
1254
  },
1255
+ /**
1256
+ * @param {{target: {type: string, id: string, value: string}}} e
1257
+ */
1137
1258
  async hexLettersCasing (e) {
1138
1259
  await this.setprefs(e);
1139
1260
  await chartBuild();
1140
1261
  return await this.resizecells();
1141
1262
  },
1263
+ /**
1264
+ * @param {{target: {type: string, id: string, value: string}}} e
1265
+ */
1142
1266
  async flip (e) {
1143
1267
  await this.setCurrstartset(lastStartCharCode);
1144
1268
  await this.setprefs(e);
1145
1269
  await chartBuild();
1146
1270
  return await this.resizecells();
1147
1271
  },
1272
+ /**
1273
+ * @param {{target: {type: string, id: string, value: string}}} e
1274
+ */
1148
1275
  async onlyentsyesflip (e) {
1149
1276
  return await this.flip(e);
1150
1277
  },
1278
+ /**
1279
+ * @param {{target: {type: string, id: string, value: string}}} e
1280
+ */
1151
1281
  async hexflip (e) {
1152
1282
  return await this.flip(e);
1153
1283
  },
1284
+ /**
1285
+ * @param {{target: {type: string, id: string, value: string}}} e
1286
+ */
1154
1287
  async decflip (e) {
1155
1288
  return await this.flip(e);
1156
1289
  },
1290
+ /**
1291
+ * @param {{target: {type: string, id: string, value: string}}} e
1292
+ */
1157
1293
  async unicodeflip (e) {
1158
1294
  return await this.flip(e);
1159
1295
  },
1296
+ /**
1297
+ * @param {{target: {type: string, id: string, value: string}}} e
1298
+ */
1160
1299
  async middleflip (e) {
1161
1300
  return await this.flip(e);
1162
1301
  },
1302
+ /**
1303
+ * @param {{target: {type: string, id: string, value: string}}} e
1304
+ */
1163
1305
  async buttonflip (e) {
1164
1306
  return await this.flip(e);
1165
1307
  },
1308
+ /**
1309
+ * @param {{target: {type: string, id: string, value: string}}} e
1310
+ */
1166
1311
  async entflip (e) {
1167
1312
  return await this.flip(e);
1168
1313
  },
1314
+ /**
1315
+ * @param {{target: {type: string, id: string, value: string}}} e
1316
+ */
1169
1317
  async cssWhitespace (e) {
1170
1318
  let {value} = e.target;
1171
1319
  // Escape \r since \r may be lost?
@@ -1207,6 +1355,9 @@ const unicodecharref = {
1207
1355
  await setPref('xstyle', currxstyle);
1208
1356
  return await chartBuild();
1209
1357
  }, */
1358
+ /**
1359
+ * @param {{target: {type: string, id: string, value: string}}} e
1360
+ */
1210
1361
  async rowsset (e) {
1211
1362
  await this.setCurrstartset(lastStartCharCode);
1212
1363
  if (e.target.value !== null && e.target.value !== '') {
@@ -1215,6 +1366,9 @@ const unicodecharref = {
1215
1366
  await chartBuild();
1216
1367
  return await this.resizecells();
1217
1368
  },
1369
+ /**
1370
+ * @param {{target: {type: string, id: string, value: string}}} e
1371
+ */
1218
1372
  async colsset (e) {
1219
1373
  await this.setCurrstartset(lastStartCharCode);
1220
1374
  if (e.target.value !== null && e.target.value !== '') {
@@ -1226,7 +1380,7 @@ const unicodecharref = {
1226
1380
 
1227
1381
  /**
1228
1382
  * @param {{value: string}} tbx
1229
- * @param {boolean} descripts
1383
+ * @param {boolean} [descripts]
1230
1384
  * @returns {Promise<void>}
1231
1385
  */
1232
1386
  async startset (tbx, descripts) {
@@ -1235,23 +1389,27 @@ const unicodecharref = {
1235
1389
  * @returns {Integer}
1236
1390
  */
1237
1391
  function convert (str) {
1238
- str = str.replace(/;$/u, '');
1239
- const hexInit = str.match(/^&?#?x/u);
1392
+ str = str.replace(/;$/v, '');
1393
+ const hexInit = str.match(/^&?#?x/v);
1240
1394
  if (hexInit) {
1241
1395
  return Number.parseInt(str.slice(hexInit[0].length), 16) - 1;
1242
1396
  }
1243
- const decInit = str.match(/^&?#/u);
1397
+ const decInit = str.match(/^&?#/v);
1244
1398
  if (decInit) {
1245
- return Number.parseInt(str.slice(decInit[0].length)) - 1;
1399
+ return Number.parseInt(str.slice(decInit[0].length), 10) - 1;
1246
1400
  }
1247
- return str.codePointAt() - 1;
1401
+ return /** @type {number} */ (str.codePointAt(0)) - 1;
1248
1402
  }
1249
1403
  await this.disableEnts();
1250
1404
  const data = tbx.value !== null &&
1251
1405
  tbx.value !== undefined &&
1252
1406
  tbx.value !== ''
1253
1407
  ? convert(tbx.value)
1254
- : (await getPref('startset') || 'a').codePointAt() - 1;
1408
+ : /** @type {number} */ (
1409
+ (
1410
+ /** @type {string} */ (await getPref('startset')) || 'a'
1411
+ ).codePointAt(0)
1412
+ ) - 1;
1255
1413
  await this.setCurrstartset(data);
1256
1414
 
1257
1415
  await chartBuild({descripts});
@@ -1266,7 +1424,9 @@ const unicodecharref = {
1266
1424
  async setCurrstartset (value) {
1267
1425
  /* istanbul ignore if -- Guard */
1268
1426
  if (typeof value !== 'number') {
1269
- const err = new Error('Bad value');
1427
+ const err = /** @type {Error & {value: AnyValue}} */ (
1428
+ new Error('Bad value')
1429
+ );
1270
1430
  err.value = value;
1271
1431
  // eslint-disable-next-line no-console -- Debugging
1272
1432
  console.error(err);
@@ -1274,6 +1434,12 @@ const unicodecharref = {
1274
1434
  'Look at trace to see where setting ' +
1275
1435
  '`currentStartCharCode` as undefined'
1276
1436
  );
1437
+ // Avoid corrupting the stored pref: `setPref` would otherwise
1438
+ // persist the literal string "undefined" (via
1439
+ // `localStorage.setItem` stringifying a JS `undefined`), which
1440
+ // then makes every future `getPref('currentStartCharCode')`
1441
+ // throw a JSON parse error indefinitely.
1442
+ return undefined;
1277
1443
  }
1278
1444
 
1279
1445
  return await setPref('currentStartCharCode', value);
@@ -1290,19 +1456,28 @@ const unicodecharref = {
1290
1456
  await chartBuild();
1291
1457
  return await this.resizecells();
1292
1458
  },
1459
+ /**
1460
+ * @param {{id: string, value: string}} obj
1461
+ */
1293
1462
  async searchUnihan (obj) {
1294
1463
  return await this.searchUnicode(obj, 'Unihan');
1295
1464
  },
1296
1465
  async disableEnts () {
1297
1466
  return await this.setBoolChecked('onlyentsyes', false);
1298
1467
  },
1468
+ /**
1469
+ * @param {{id: string, value: string}} obj
1470
+ * @param {string} [table]
1471
+ * @param {boolean} [nochart]
1472
+ * @param {boolean} [strict]
1473
+ */
1299
1474
  async searchUnicode (obj, table, nochart, strict) { // Fix: allow Jamo!
1300
1475
  await charrefunicodeConverter.searchUnicode(obj, table, nochart, strict);
1301
1476
  if (!nochart) {
1302
1477
  const tmp = await getPref('currentStartCharCode');
1303
1478
  this.startset(obj, true); // Could remember last description (?)
1304
1479
  // Set it back as it was before the search
1305
- await this.setCurrstartset(tmp);
1480
+ await this.setCurrstartset(/** @type {number} */ (tmp));
1306
1481
  this.resizecells();
1307
1482
  }
1308
1483
  // Doesn't work since name_desc_val is search value, not first
@@ -1310,25 +1485,31 @@ const unicodecharref = {
1310
1485
  // were a search, however); we need to be careful, however, since
1311
1486
  // some searches run automatically on start-up
1312
1487
  /* if (name_desc === 'Name' || name_desc === 'kDefinition') {
1313
- await this.setCurrstartset(name_desc_val.codePointAt() - 1);
1488
+ await this.setCurrstartset(name_desc_val.codePointAt(0) - 1);
1314
1489
  } */
1315
1490
  },
1316
- moveoutput (movedid) {
1317
- const insertText = $(movedid);
1318
- $('#unicodeTabBox').$selectTabForTabPanel($('#conversion'));
1319
- $('#toconvert').value = insertText.value;
1491
+ /**
1492
+ * @param {string} movedSel
1493
+ */
1494
+ moveoutput (movedSel) {
1495
+ const insertText = $i(movedSel);
1496
+ $tabbox('#unicodeTabBox').$selectTabForTabPanel($tabpanel('#conversion'));
1497
+ $t('#toconvert').value = insertText.value;
1320
1498
  },
1499
+ /**
1500
+ * @param {{target: {type: string, id: string, value: string}}} e
1501
+ */
1321
1502
  async append2htmlflip (e) {
1322
1503
  await this.setprefs(e);
1323
1504
  await registerDTD(); // (in case DTD not also changed, still need to reset)
1324
1505
  await chartBuild();
1325
1506
  await this.resizecells();
1326
1507
  },
1327
- /**
1328
- * @todo Unused
1508
+ /*
1509
+ * @ todo Unused
1329
1510
  * Sets the preference for whether to display the chosen character
1330
1511
  * in the middle of the chart (or beginning).
1331
- * @param {boolean} bool Whether to set to true or not
1512
+ * @ param {boolean} bool Whether to set to true or not
1332
1513
  */
1333
1514
  /*
1334
1515
  async startCharInMiddleOfChart (bool) {
@@ -1340,7 +1521,7 @@ const unicodecharref = {
1340
1521
  */
1341
1522
  insertent () {
1342
1523
  insertIntoOrOverExisting({
1343
- textReceptacle: $('#DTDtextbox'),
1524
+ textReceptacle: $t('#DTDtextbox'),
1344
1525
  value: '<!ENTITY "">\n'
1345
1526
  });
1346
1527
  // The following works but may be annoying if trying to insert
@@ -1407,30 +1588,11 @@ const unicodecharref = {
1407
1588
 
1408
1589
  // Build these programmatically? (and in UI?)
1409
1590
  /* Pseudo-constants */
1410
- Unihan: [ // Ordered by database array; todo: rpplace above `Unihan`?
1411
- 'kAccountingNumeric', 'kAlternateTotalStrokes', 'kBigFive', 'kCangjie',
1412
- 'kCantonese', 'kCCCII', 'kCheungBauer', 'kCheungBauerIndex', 'kCihaiT',
1413
- 'kCNS1986', 'kCNS1992', 'kCompatibilityVariant', 'kCowles', 'kDaeJaweon',
1414
- 'kDefinition', 'kEACC', 'kFenn', 'kFennIndex', 'kFourCornerCode',
1415
- 'kFrequency', 'kGB0', 'kGB1', 'kGB3', 'kGB5', 'kGB7', 'kGB8',
1416
- 'kGradeLevel', 'kGSR', 'kHangul', 'kHanYu', 'kHanyuPinlu',
1417
- 'kHanyuPinyin', 'kHDZRadBreak', 'kHKGlyph', 'kHKSCS', 'kIBMJapan',
1418
- 'kIICore', 'kIRG_GSource', 'kIRG_HSource', 'kIRG_JSource',
1419
- 'kIRG_KPSource', 'kIRG_KSource', 'kIRG_MSource', 'kIRG_SSource',
1420
- 'kIRG_TSource', 'kIRG_UKSource', 'kIRG_USource', 'kIRG_VSource',
1421
- 'kIRGDaeJaweon', 'kIRGDaiKanwaZiten', 'kIRGHanyuDaZidian',
1422
- 'kIRGKangXi', 'kJa', 'kJapaneseKun', 'kJapaneseOn', 'kJinmeiyoKanji',
1423
- 'kJis0', 'kJis1', 'kJIS0213', 'kJoyoKanji', 'kKangXi', 'kKarlgren',
1424
- 'kKorean', 'kKoreanEducationHanja', 'kKoreanName', 'kKPS0', 'kKPS1',
1425
- 'kKSC0', 'kKSC1', 'kLau', 'kMainlandTelegraph', 'kMandarin',
1426
- 'kMatthews', 'kMeyerWempe', 'kMorohashi', 'kNelson', 'kOtherNumeric',
1427
- 'kPhonetic', 'kPrimaryNumeric', 'kPseudoGB1', 'kRSAdobe_Japan1_6',
1428
- 'kRSKangXi', 'kRSUnicode', 'kSBGY', 'kSemanticVariant',
1429
- 'kSimplifiedVariant', 'kSpecializedSemanticVariant', 'kSpoofingVariant',
1430
- 'kStrange', 'kTaiwanTelegraph', 'kTang', 'kTGH', 'kTGHZ2013',
1431
- 'kTotalStrokes', 'kTraditionalVariant', 'kUnihanCore2020',
1432
- 'kVietnamese', 'kXerox', 'kXHC1983', 'kZVariant'
1433
- ],
1591
+ // Auto-generated (see `browser_action/unicode/unihanFields.js`) from the
1592
+ // exact column order used to build `download/unihan/unihan.json`;
1593
+ // values are looked up by this array's position, not by name, so this
1594
+ // must never be hand-edited independently of that data.
1595
+ Unihan: unihanFields,
1434
1596
  UnihanMenus: [], // Unused
1435
1597
  Unicode: [
1436
1598
  'General_Category', 'Canonical_Combining_Class', 'Bidi_Class',
@@ -1472,7 +1634,8 @@ const unicodecharref = {
1472
1634
  ],
1473
1635
  UnicodeMenuBidi_Mirrored: ['Y', 'N'],
1474
1636
  UnicodeMenuDigit: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1475
- UnicodeMenuDecimal: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1637
+ UnicodeMenuDecimal: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1638
+ kDefinitionIndex: -1
1476
1639
  };
1477
1640
 
1478
1641
  unicodecharref.kDefinitionIndex = unicodecharref.Unihan.indexOf('kDefinition');