alphabet.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.INTERVALS = exports.Base = exports.Embellish = exports.Font = void 0;
  4. exports.makeInterval = makeInterval;
  5. exports.makeMultiInterval = makeMultiInterval;
  6. exports.makeCodeInterval = makeCodeInterval;
  7. exports.alphabetName = alphabetName;
  8. var Font;
  9. (function (Font) {
  10. Font["BOLD"] = "bold";
  11. Font["BOLDFRAKTUR"] = "bold-fraktur";
  12. Font["BOLDITALIC"] = "bold-italic";
  13. Font["BOLDSCRIPT"] = "bold-script";
  14. Font["DOUBLESTRUCK"] = "double-struck";
  15. Font["DOUBLESTRUCKITALIC"] = "double-struck-italic";
  16. Font["FULLWIDTH"] = "fullwidth";
  17. Font["FRAKTUR"] = "fraktur";
  18. Font["ITALIC"] = "italic";
  19. Font["MONOSPACE"] = "monospace";
  20. Font["NORMAL"] = "normal";
  21. Font["SCRIPT"] = "script";
  22. Font["SANSSERIF"] = "sans-serif";
  23. Font["SANSSERIFITALIC"] = "sans-serif-italic";
  24. Font["SANSSERIFBOLD"] = "sans-serif-bold";
  25. Font["SANSSERIFBOLDITALIC"] = "sans-serif-bold-italic";
  26. })(Font || (exports.Font = Font = {}));
  27. var Embellish;
  28. (function (Embellish) {
  29. Embellish["SUPER"] = "super";
  30. Embellish["SUB"] = "sub";
  31. Embellish["CIRCLED"] = "circled";
  32. Embellish["PARENTHESIZED"] = "parenthesized";
  33. Embellish["PERIOD"] = "period";
  34. Embellish["NEGATIVECIRCLED"] = "negative-circled";
  35. Embellish["DOUBLECIRCLED"] = "double-circled";
  36. Embellish["CIRCLEDSANSSERIF"] = "circled-sans-serif";
  37. Embellish["NEGATIVECIRCLEDSANSSERIF"] = "negative-circled-sans-serif";
  38. Embellish["COMMA"] = "comma";
  39. Embellish["SQUARED"] = "squared";
  40. Embellish["NEGATIVESQUARED"] = "negative-squared";
  41. })(Embellish || (exports.Embellish = Embellish = {}));
  42. var Base;
  43. (function (Base) {
  44. Base["LATINCAP"] = "latinCap";
  45. Base["LATINSMALL"] = "latinSmall";
  46. Base["GREEKCAP"] = "greekCap";
  47. Base["GREEKSMALL"] = "greekSmall";
  48. Base["DIGIT"] = "digit";
  49. })(Base || (exports.Base = Base = {}));
  50. function num2str(num) {
  51. const str = num.toString(16).toUpperCase();
  52. return str.length > 3 ? str : ('000' + str).slice(-4);
  53. }
  54. function makeInterval([a, b], subst) {
  55. const start = parseInt(a, 16);
  56. const end = parseInt(b, 16);
  57. const result = [];
  58. for (let i = start; i <= end; i++) {
  59. let key = num2str(i);
  60. const sub = subst[key];
  61. if (sub === false) {
  62. continue;
  63. }
  64. key = subst[key] || key;
  65. result.push(key);
  66. }
  67. return result;
  68. }
  69. function makeCharInterval(int, subst = {}) {
  70. return makeInterval(int, subst).map((x) => String.fromCodePoint(parseInt(x, 16)));
  71. }
  72. function makeMultiInterval(ints) {
  73. let result = [];
  74. for (const int of ints) {
  75. if (Array.isArray(int)) {
  76. result = result.concat(makeCharInterval(int));
  77. continue;
  78. }
  79. result.push(String.fromCodePoint(parseInt(int, 16)));
  80. }
  81. return result;
  82. }
  83. function makeCodeInterval(ints) {
  84. let result = [];
  85. for (const int of ints) {
  86. if (Array.isArray(int)) {
  87. result = result.concat(makeInterval(int, {}).map((x) => parseInt(x, 16)));
  88. continue;
  89. }
  90. result.push(parseInt(int, 16));
  91. }
  92. return result;
  93. }
  94. const PROTO_INTERVALS = [
  95. {
  96. interval: ['1D400', '1D419'],
  97. base: Base.LATINCAP,
  98. subst: {},
  99. capital: true,
  100. category: 'Lu',
  101. font: Font.BOLD
  102. },
  103. {
  104. interval: ['1D41A', '1D433'],
  105. base: Base.LATINSMALL,
  106. subst: {},
  107. capital: false,
  108. category: 'Ll',
  109. font: Font.BOLD
  110. },
  111. {
  112. interval: ['1D56C', '1D585'],
  113. base: Base.LATINCAP,
  114. subst: {},
  115. capital: true,
  116. category: 'Lu',
  117. font: Font.BOLDFRAKTUR
  118. },
  119. {
  120. interval: ['1D586', '1D59F'],
  121. base: Base.LATINSMALL,
  122. subst: {},
  123. capital: false,
  124. category: 'Ll',
  125. font: Font.BOLDFRAKTUR
  126. },
  127. {
  128. interval: ['1D468', '1D481'],
  129. base: Base.LATINCAP,
  130. subst: {},
  131. capital: true,
  132. category: 'Lu',
  133. font: Font.BOLDITALIC
  134. },
  135. {
  136. interval: ['1D482', '1D49B'],
  137. base: Base.LATINSMALL,
  138. subst: {},
  139. capital: false,
  140. category: 'Ll',
  141. font: Font.BOLDITALIC
  142. },
  143. {
  144. interval: ['1D4D0', '1D4E9'],
  145. base: Base.LATINCAP,
  146. subst: {},
  147. capital: true,
  148. category: 'Lu',
  149. font: Font.BOLDSCRIPT
  150. },
  151. {
  152. interval: ['1D4EA', '1D503'],
  153. base: Base.LATINSMALL,
  154. subst: {},
  155. capital: false,
  156. category: 'Ll',
  157. font: Font.BOLDSCRIPT
  158. },
  159. {
  160. interval: ['1D538', '1D551'],
  161. base: Base.LATINCAP,
  162. subst: {
  163. '1D53A': '2102',
  164. '1D53F': '210D',
  165. '1D545': '2115',
  166. '1D547': '2119',
  167. '1D548': '211A',
  168. '1D549': '211D',
  169. '1D551': '2124'
  170. },
  171. capital: true,
  172. category: 'Lu',
  173. font: Font.DOUBLESTRUCK
  174. },
  175. {
  176. interval: ['1D552', '1D56B'],
  177. base: Base.LATINSMALL,
  178. subst: {},
  179. capital: false,
  180. category: 'Ll',
  181. font: Font.DOUBLESTRUCK
  182. },
  183. {
  184. interval: ['1D504', '1D51D'],
  185. base: Base.LATINCAP,
  186. subst: {
  187. '1D506': '212D',
  188. '1D50B': '210C',
  189. '1D50C': '2111',
  190. '1D515': '211C',
  191. '1D51D': '2128'
  192. },
  193. capital: true,
  194. category: 'Lu',
  195. font: Font.FRAKTUR
  196. },
  197. {
  198. interval: ['1D51E', '1D537'],
  199. base: Base.LATINSMALL,
  200. subst: {},
  201. capital: false,
  202. category: 'Ll',
  203. font: Font.FRAKTUR
  204. },
  205. {
  206. interval: ['FF21', 'FF3A'],
  207. base: Base.LATINCAP,
  208. subst: {},
  209. capital: true,
  210. category: 'Lu',
  211. font: Font.FULLWIDTH
  212. },
  213. {
  214. interval: ['FF41', 'FF5A'],
  215. base: Base.LATINSMALL,
  216. subst: {},
  217. capital: false,
  218. category: 'Ll',
  219. font: Font.FULLWIDTH
  220. },
  221. {
  222. interval: ['1D434', '1D44D'],
  223. base: Base.LATINCAP,
  224. subst: {},
  225. capital: true,
  226. category: 'Lu',
  227. font: Font.ITALIC
  228. },
  229. {
  230. interval: ['1D44E', '1D467'],
  231. base: Base.LATINSMALL,
  232. subst: { '1D455': '210E' },
  233. capital: false,
  234. category: 'Ll',
  235. font: Font.ITALIC
  236. },
  237. {
  238. interval: ['1D670', '1D689'],
  239. base: Base.LATINCAP,
  240. subst: {},
  241. capital: true,
  242. category: 'Lu',
  243. font: Font.MONOSPACE
  244. },
  245. {
  246. interval: ['1D68A', '1D6A3'],
  247. base: Base.LATINSMALL,
  248. subst: {},
  249. capital: false,
  250. category: 'Ll',
  251. font: Font.MONOSPACE
  252. },
  253. {
  254. interval: ['0041', '005A'],
  255. base: Base.LATINCAP,
  256. subst: {},
  257. capital: true,
  258. category: 'Lu',
  259. font: Font.NORMAL
  260. },
  261. {
  262. interval: ['0061', '007A'],
  263. base: Base.LATINSMALL,
  264. subst: {},
  265. capital: false,
  266. category: 'Ll',
  267. font: Font.NORMAL
  268. },
  269. {
  270. interval: ['1D49C', '1D4B5'],
  271. base: Base.LATINCAP,
  272. subst: {
  273. '1D49D': '212C',
  274. '1D4A0': '2130',
  275. '1D4A1': '2131',
  276. '1D4A3': '210B',
  277. '1D4A4': '2110',
  278. '1D4A7': '2112',
  279. '1D4A8': '2133',
  280. '1D4AD': '211B'
  281. },
  282. capital: true,
  283. category: 'Lu',
  284. font: Font.SCRIPT
  285. },
  286. {
  287. interval: ['1D4B6', '1D4CF'],
  288. base: Base.LATINSMALL,
  289. subst: { '1D4BA': '212F', '1D4BC': '210A', '1D4C4': '2134' },
  290. capital: false,
  291. category: 'Ll',
  292. font: Font.SCRIPT
  293. },
  294. {
  295. interval: ['1D5A0', '1D5B9'],
  296. base: Base.LATINCAP,
  297. subst: {},
  298. capital: true,
  299. category: 'Lu',
  300. font: Font.SANSSERIF
  301. },
  302. {
  303. interval: ['1D5BA', '1D5D3'],
  304. base: Base.LATINSMALL,
  305. subst: {},
  306. capital: false,
  307. category: 'Ll',
  308. font: Font.SANSSERIF
  309. },
  310. {
  311. interval: ['1D608', '1D621'],
  312. base: Base.LATINCAP,
  313. subst: {},
  314. capital: true,
  315. category: 'Lu',
  316. font: Font.SANSSERIFITALIC
  317. },
  318. {
  319. interval: ['1D622', '1D63B'],
  320. base: Base.LATINSMALL,
  321. subst: {},
  322. capital: false,
  323. category: 'Ll',
  324. font: Font.SANSSERIFITALIC
  325. },
  326. {
  327. interval: ['1D5D4', '1D5ED'],
  328. base: Base.LATINCAP,
  329. subst: {},
  330. capital: true,
  331. category: 'Lu',
  332. font: Font.SANSSERIFBOLD
  333. },
  334. {
  335. interval: ['1D5EE', '1D607'],
  336. base: Base.LATINSMALL,
  337. subst: {},
  338. capital: false,
  339. category: 'Ll',
  340. font: Font.SANSSERIFBOLD
  341. },
  342. {
  343. interval: ['1D63C', '1D655'],
  344. base: Base.LATINCAP,
  345. subst: {},
  346. capital: true,
  347. category: 'Lu',
  348. font: Font.SANSSERIFBOLDITALIC
  349. },
  350. {
  351. interval: ['1D656', '1D66F'],
  352. base: Base.LATINSMALL,
  353. subst: {},
  354. capital: false,
  355. category: 'Ll',
  356. font: Font.SANSSERIFBOLDITALIC
  357. },
  358. {
  359. interval: ['0391', '03A9'],
  360. base: Base.GREEKCAP,
  361. subst: { '03A2': '03F4' },
  362. capital: true,
  363. category: 'Lu',
  364. font: Font.NORMAL
  365. },
  366. {
  367. interval: ['03B0', '03D0'],
  368. base: Base.GREEKSMALL,
  369. subst: {
  370. '03B0': '2207',
  371. '03CA': '2202',
  372. '03CB': '03F5',
  373. '03CC': '03D1',
  374. '03CD': '03F0',
  375. '03CE': '03D5',
  376. '03CF': '03F1',
  377. '03D0': '03D6'
  378. },
  379. capital: false,
  380. category: 'Ll',
  381. font: Font.NORMAL
  382. },
  383. {
  384. interval: ['1D6A8', '1D6C0'],
  385. base: Base.GREEKCAP,
  386. subst: {},
  387. capital: true,
  388. category: 'Lu',
  389. font: Font.BOLD
  390. },
  391. {
  392. interval: ['1D6C1', '1D6E1'],
  393. base: Base.GREEKSMALL,
  394. subst: {},
  395. capital: false,
  396. category: 'Ll',
  397. font: Font.BOLD
  398. },
  399. {
  400. interval: ['1D6E2', '1D6FA'],
  401. base: Base.GREEKCAP,
  402. subst: {},
  403. capital: true,
  404. category: 'Lu',
  405. font: Font.ITALIC
  406. },
  407. {
  408. interval: ['1D6FB', '1D71B'],
  409. base: Base.GREEKSMALL,
  410. subst: {},
  411. capital: false,
  412. category: 'Ll',
  413. font: Font.ITALIC
  414. },
  415. {
  416. interval: ['1D71C', '1D734'],
  417. base: Base.GREEKCAP,
  418. subst: {},
  419. capital: true,
  420. category: 'Lu',
  421. font: Font.BOLDITALIC
  422. },
  423. {
  424. interval: ['1D735', '1D755'],
  425. base: Base.GREEKSMALL,
  426. subst: {},
  427. capital: false,
  428. category: 'Ll',
  429. font: Font.BOLDITALIC
  430. },
  431. {
  432. interval: ['1D756', '1D76E'],
  433. base: Base.GREEKCAP,
  434. subst: {},
  435. capital: true,
  436. category: 'Lu',
  437. font: Font.SANSSERIFBOLD
  438. },
  439. {
  440. interval: ['1D76F', '1D78F'],
  441. base: Base.GREEKSMALL,
  442. subst: {},
  443. capital: false,
  444. category: 'Ll',
  445. font: Font.SANSSERIFBOLD
  446. },
  447. {
  448. interval: ['1D790', '1D7A8'],
  449. base: Base.GREEKCAP,
  450. subst: {},
  451. capital: true,
  452. category: 'Lu',
  453. font: Font.SANSSERIFBOLDITALIC
  454. },
  455. {
  456. interval: ['1D7A9', '1D7C9'],
  457. base: Base.GREEKSMALL,
  458. subst: {},
  459. capital: false,
  460. category: 'Ll',
  461. font: Font.SANSSERIFBOLDITALIC
  462. },
  463. {
  464. interval: ['0030', '0039'],
  465. base: Base.DIGIT,
  466. subst: {},
  467. offset: 0,
  468. category: 'Nd',
  469. font: Font.NORMAL
  470. },
  471. {
  472. interval: ['2070', '2079'],
  473. base: Base.DIGIT,
  474. subst: { 2071: '00B9', 2072: '00B2', 2073: '00B3' },
  475. offset: 0,
  476. category: 'No',
  477. font: Embellish.SUPER
  478. },
  479. {
  480. interval: ['2080', '2089'],
  481. base: Base.DIGIT,
  482. subst: {},
  483. offset: 0,
  484. category: 'No',
  485. font: Embellish.SUB
  486. },
  487. {
  488. interval: ['245F', '2473'],
  489. base: Base.DIGIT,
  490. subst: { '245F': '24EA' },
  491. offset: 0,
  492. category: 'No',
  493. font: Embellish.CIRCLED
  494. },
  495. {
  496. interval: ['3251', '325F'],
  497. base: Base.DIGIT,
  498. subst: {},
  499. offset: 21,
  500. category: 'No',
  501. font: Embellish.CIRCLED
  502. },
  503. {
  504. interval: ['32B1', '32BF'],
  505. base: Base.DIGIT,
  506. subst: {},
  507. offset: 36,
  508. category: 'No',
  509. font: Embellish.CIRCLED
  510. },
  511. {
  512. interval: ['2474', '2487'],
  513. base: Base.DIGIT,
  514. subst: {},
  515. offset: 1,
  516. category: 'No',
  517. font: Embellish.PARENTHESIZED
  518. },
  519. {
  520. interval: ['2487', '249B'],
  521. base: Base.DIGIT,
  522. subst: { 2487: '1F100' },
  523. offset: 0,
  524. category: 'No',
  525. font: Embellish.PERIOD
  526. },
  527. {
  528. interval: ['2775', '277F'],
  529. base: Base.DIGIT,
  530. subst: { 2775: '24FF' },
  531. offset: 0,
  532. category: 'No',
  533. font: Embellish.NEGATIVECIRCLED
  534. },
  535. {
  536. interval: ['24EB', '24F4'],
  537. base: Base.DIGIT,
  538. subst: {},
  539. offset: 11,
  540. category: 'No',
  541. font: Embellish.NEGATIVECIRCLED
  542. },
  543. {
  544. interval: ['24F5', '24FE'],
  545. base: Base.DIGIT,
  546. subst: {},
  547. offset: 1,
  548. category: 'No',
  549. font: Embellish.DOUBLECIRCLED
  550. },
  551. {
  552. interval: ['277F', '2789'],
  553. base: Base.DIGIT,
  554. subst: { '277F': '1F10B' },
  555. offset: 0,
  556. category: 'No',
  557. font: Embellish.CIRCLEDSANSSERIF
  558. },
  559. {
  560. interval: ['2789', '2793'],
  561. base: Base.DIGIT,
  562. subst: { 2789: '1F10C' },
  563. offset: 0,
  564. category: 'No',
  565. font: Embellish.NEGATIVECIRCLEDSANSSERIF
  566. },
  567. {
  568. interval: ['FF10', 'FF19'],
  569. base: Base.DIGIT,
  570. subst: {},
  571. offset: 0,
  572. category: 'Nd',
  573. font: Font.FULLWIDTH
  574. },
  575. {
  576. interval: ['1D7CE', '1D7D7'],
  577. base: Base.DIGIT,
  578. subst: {},
  579. offset: 0,
  580. category: 'Nd',
  581. font: Font.BOLD
  582. },
  583. {
  584. interval: ['1D7D8', '1D7E1'],
  585. base: Base.DIGIT,
  586. subst: {},
  587. offset: 0,
  588. category: 'Nd',
  589. font: Font.DOUBLESTRUCK
  590. },
  591. {
  592. interval: ['1D7E2', '1D7EB'],
  593. base: Base.DIGIT,
  594. subst: {},
  595. offset: 0,
  596. category: 'Nd',
  597. font: Font.SANSSERIF
  598. },
  599. {
  600. interval: ['1D7EC', '1D7F5'],
  601. base: Base.DIGIT,
  602. subst: {},
  603. offset: 0,
  604. category: 'Nd',
  605. font: Font.SANSSERIFBOLD
  606. },
  607. {
  608. interval: ['1D7F6', '1D7FF'],
  609. base: Base.DIGIT,
  610. subst: {},
  611. offset: 0,
  612. category: 'Nd',
  613. font: Font.MONOSPACE
  614. },
  615. {
  616. interval: ['1F101', '1F10A'],
  617. base: Base.DIGIT,
  618. subst: {},
  619. offset: 0,
  620. category: 'No',
  621. font: Embellish.COMMA
  622. },
  623. {
  624. interval: ['24B6', '24CF'],
  625. base: Base.LATINCAP,
  626. subst: {},
  627. capital: true,
  628. category: 'So',
  629. font: Embellish.CIRCLED
  630. },
  631. {
  632. interval: ['24D0', '24E9'],
  633. base: Base.LATINSMALL,
  634. subst: {},
  635. capital: false,
  636. category: 'So',
  637. font: Embellish.CIRCLED
  638. },
  639. {
  640. interval: ['1F110', '1F129'],
  641. base: Base.LATINCAP,
  642. subst: {},
  643. capital: true,
  644. category: 'So',
  645. font: Embellish.PARENTHESIZED
  646. },
  647. {
  648. interval: ['249C', '24B5'],
  649. base: Base.LATINSMALL,
  650. subst: {},
  651. capital: false,
  652. category: 'So',
  653. font: Embellish.PARENTHESIZED
  654. },
  655. {
  656. interval: ['1F130', '1F149'],
  657. base: Base.LATINCAP,
  658. subst: {},
  659. capital: true,
  660. category: 'So',
  661. font: Embellish.SQUARED
  662. },
  663. {
  664. interval: ['1F170', '1F189'],
  665. base: Base.LATINCAP,
  666. subst: {},
  667. capital: true,
  668. category: 'So',
  669. font: Embellish.NEGATIVESQUARED
  670. },
  671. {
  672. interval: ['1F150', '1F169'],
  673. base: Base.LATINCAP,
  674. subst: {},
  675. capital: true,
  676. category: 'So',
  677. font: Embellish.NEGATIVECIRCLED
  678. }
  679. ];
  680. exports.INTERVALS = new Map();
  681. function alphabetName(base, font) {
  682. const capFont = font
  683. .split('-')
  684. .map((x) => x[0].toUpperCase() + x.slice(1))
  685. .join('');
  686. return base + capFont;
  687. }
  688. for (const proto of PROTO_INTERVALS) {
  689. const key = alphabetName(proto.base, proto.font);
  690. const interval = makeCharInterval(proto.interval, proto.subst);
  691. let alphabet = exports.INTERVALS.get(key);
  692. if (alphabet) {
  693. alphabet.unicode = alphabet.unicode.concat(interval);
  694. continue;
  695. }
  696. alphabet = proto;
  697. alphabet.unicode = interval;
  698. exports.INTERVALS.set(key, alphabet);
  699. }