@kensio/pinyinjs 1.7.7 → 1.7.9

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 (110) hide show
  1. package/README.md +20 -4
  2. package/data/core.entries +2259 -2259
  3. package/data/core.freq +0 -0
  4. package/data/full.counts +0 -0
  5. package/data/full.entries +2289 -2289
  6. package/data/full.freq +0 -0
  7. package/data/manifest.json +13 -6
  8. package/data/standard.entries +2257 -2257
  9. package/data/standard.freq +0 -0
  10. package/dist/cli/flag-lists.d.ts +2 -1
  11. package/dist/cli/flag-lists.d.ts.map +1 -1
  12. package/dist/cli/flag-lists.js.map +1 -1
  13. package/dist/cli/format-options.d.ts +5 -1
  14. package/dist/cli/format-options.d.ts.map +1 -1
  15. package/dist/cli/format-options.js +9 -2
  16. package/dist/cli/format-options.js.map +1 -1
  17. package/dist/cli/html-commands.d.ts.map +1 -1
  18. package/dist/cli/html-commands.js +15 -3
  19. package/dist/cli/html-commands.js.map +1 -1
  20. package/dist/cli/systems.d.ts +15 -43
  21. package/dist/cli/systems.d.ts.map +1 -1
  22. package/dist/cli/systems.js +9 -12
  23. package/dist/cli/systems.js.map +1 -1
  24. package/dist/decode/guo-rule.d.ts +64 -0
  25. package/dist/decode/guo-rule.d.ts.map +1 -0
  26. package/dist/decode/guo-rule.js +138 -0
  27. package/dist/decode/guo-rule.js.map +1 -0
  28. package/dist/decode/reading-rules.d.ts +1 -0
  29. package/dist/decode/reading-rules.d.ts.map +1 -1
  30. package/dist/decode/reading-rules.js +3 -0
  31. package/dist/decode/reading-rules.js.map +1 -1
  32. package/dist/dictionary/artifact-claims.d.ts +8 -0
  33. package/dist/dictionary/artifact-claims.d.ts.map +1 -1
  34. package/dist/dictionary/artifact-claims.js +11 -1
  35. package/dist/dictionary/artifact-claims.js.map +1 -1
  36. package/dist/dictionary/artifact.d.ts.map +1 -1
  37. package/dist/dictionary/artifact.js +3 -5
  38. package/dist/dictionary/artifact.js.map +1 -1
  39. package/dist/dictionary/frequency-table.d.ts +46 -0
  40. package/dist/dictionary/frequency-table.d.ts.map +1 -1
  41. package/dist/dictionary/frequency-table.js +37 -8
  42. package/dist/dictionary/frequency-table.js.map +1 -1
  43. package/dist/dictionary/merge-types.d.ts +12 -0
  44. package/dist/dictionary/merge-types.d.ts.map +1 -1
  45. package/dist/dictionary/merge-types.js.map +1 -1
  46. package/dist/dictionary/merge-word.d.ts.map +1 -1
  47. package/dist/dictionary/merge-word.js +2 -2
  48. package/dist/dictionary/merge-word.js.map +1 -1
  49. package/dist/dictionary/merge.d.ts.map +1 -1
  50. package/dist/dictionary/merge.js +11 -1
  51. package/dist/dictionary/merge.js.map +1 -1
  52. package/dist/dictionary/name-mass.d.ts +42 -0
  53. package/dist/dictionary/name-mass.d.ts.map +1 -0
  54. package/dist/dictionary/name-mass.js +66 -0
  55. package/dist/dictionary/name-mass.js.map +1 -0
  56. package/dist/dictionary/proper-noun.d.ts +8 -1
  57. package/dist/dictionary/proper-noun.d.ts.map +1 -1
  58. package/dist/dictionary/proper-noun.js +13 -3
  59. package/dist/dictionary/proper-noun.js.map +1 -1
  60. package/dist/dictionary/script-pairings.d.ts +12 -0
  61. package/dist/dictionary/script-pairings.d.ts.map +1 -1
  62. package/dist/dictionary/script-pairings.js +20 -0
  63. package/dist/dictionary/script-pairings.js.map +1 -1
  64. package/dist/dictionary/source.d.ts +22 -0
  65. package/dist/dictionary/source.d.ts.map +1 -1
  66. package/dist/dictionary/source.js +24 -0
  67. package/dist/dictionary/source.js.map +1 -1
  68. package/dist/dictionary/traditional-carry.d.ts +23 -0
  69. package/dist/dictionary/traditional-carry.d.ts.map +1 -0
  70. package/dist/dictionary/traditional-carry.js +201 -0
  71. package/dist/dictionary/traditional-carry.js.map +1 -0
  72. package/dist/dictionary/word-counts.d.ts +74 -0
  73. package/dist/dictionary/word-counts.d.ts.map +1 -0
  74. package/dist/dictionary/word-counts.js +142 -0
  75. package/dist/dictionary/word-counts.js.map +1 -0
  76. package/dist/format/annotate.d.ts.map +1 -1
  77. package/dist/format/annotate.js +3 -3
  78. package/dist/format/annotate.js.map +1 -1
  79. package/dist/format/html.d.ts +41 -6
  80. package/dist/format/html.d.ts.map +1 -1
  81. package/dist/format/html.js +34 -83
  82. package/dist/format/html.js.map +1 -1
  83. package/dist/format/language-tag.d.ts +57 -0
  84. package/dist/format/language-tag.d.ts.map +1 -0
  85. package/dist/format/language-tag.js +76 -0
  86. package/dist/format/language-tag.js.map +1 -0
  87. package/dist/format/syllable-span.d.ts +10 -0
  88. package/dist/format/syllable-span.d.ts.map +1 -0
  89. package/dist/format/syllable-span.js +87 -0
  90. package/dist/format/syllable-span.js.map +1 -0
  91. package/dist/format/transcribed.d.ts +36 -0
  92. package/dist/format/transcribed.d.ts.map +1 -0
  93. package/dist/format/transcribed.js +38 -0
  94. package/dist/format/transcribed.js.map +1 -0
  95. package/dist/format/transcription.d.ts.map +1 -1
  96. package/dist/format/transcription.js +7 -19
  97. package/dist/format/transcription.js.map +1 -1
  98. package/dist/index.d.ts +5 -2
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +4 -2
  101. package/dist/index.js.map +1 -1
  102. package/dist/transcription/systems.d.ts +82 -0
  103. package/dist/transcription/systems.d.ts.map +1 -0
  104. package/dist/transcription/systems.js +64 -0
  105. package/dist/transcription/systems.js.map +1 -0
  106. package/package.json +1 -1
  107. package/dist/cli/system-table.d.ts +0 -12
  108. package/dist/cli/system-table.d.ts.map +0 -1
  109. package/dist/cli/system-table.js +0 -48
  110. package/dist/cli/system-table.js.map +0 -1
@@ -1,5 +1,14 @@
1
+ /**
2
+ * A conversion as markup, and the options that decide what the markup carries.
3
+ *
4
+ * One element per syllable, which is what lets a page colour a tone or mark a
5
+ * guess. What goes inside one of those elements is `syllable-span.ts` and the
6
+ * ruby that puts the reading over the hanzi is `annotate.ts`.
7
+ */
1
8
  export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
2
9
  import type { ConvertedPiece, ConvertOptions } from "../decode/convert.js";
10
+ import type { TranscriptionSystem } from "../transcription/systems.js";
11
+ export { writePiece } from "./syllable-span.js";
3
12
  /**
4
13
  * How a conversion is marked up.
5
14
  */
@@ -15,18 +24,32 @@ export interface HtmlOptions extends ConvertOptions {
15
24
  * Whether readings the decode was guessing at are marked. Defaults to true.
16
25
  *
17
26
  * `py-uncertain`, plus a `data-alternatives` attribute listing what was
18
- * rejected. See {@link isUncertain} for what qualifies and how often it is
19
- * wrong.
27
+ * rejected. See `isUncertain` for what qualifies and how often it is wrong.
20
28
  */
21
29
  readonly markUncertain?: boolean;
22
30
  /**
23
31
  * Whether each syllable declares what language it is in. Defaults to true.
24
32
  *
25
33
  * `lang="zh-Latn-CN-pinyin"`, or `zh-Latn-TW-pinyin` where the conversion
26
- * reads `zh-TW`. See {@link languageTag} for why that matters, and what to
27
- * do instead of turning it off.
34
+ * reads `zh-TW`. See `languageTag` for why that matters, and what to do
35
+ * instead of turning it off.
28
36
  */
29
37
  readonly lang?: boolean;
38
+ /**
39
+ * A system to write the reading in instead of pinyin.
40
+ *
41
+ * `BOPOMOFO`, `WADE_GILES`, `YALE`, `GWOYEU` or `IPA`, or a
42
+ * {@link TranscriptionSystem} of the caller's own. Left out, the reading is
43
+ * the pinyin the conversion wrote.
44
+ *
45
+ * The word segmentation is the conversion's either way and only the join
46
+ * changes, which is the division `toTranscription` makes and for the same
47
+ * reason. What a word is belongs to the language, and how its syllables are
48
+ * run together belongs to the system. Everything else a syllable carries is
49
+ * untouched, so tone classes, `py-uncertain` and `data-alternatives` mean
50
+ * what they always did.
51
+ */
52
+ readonly transcription?: TranscriptionSystem;
30
53
  }
31
54
  /**
32
55
  * Escape text for markup.
@@ -39,9 +62,21 @@ export interface HtmlOptions extends ConvertOptions {
39
62
  */
40
63
  export declare function escape(text: string): string;
41
64
  /**
42
- * Mark up one piece of a conversion.
65
+ * Mark up a run of pieces, with the system's join between two syllables.
66
+ *
67
+ * Pinyin needs none. Its syllables are run together and the marks that divide
68
+ * them are pieces of their own. Every other system decides the join for itself,
69
+ * and the join is what separates the five at this level, so it is written
70
+ * between the spans rather than inside one. `<span>Pei³</span>-<span>ching¹
71
+ * </span>` is one word in Wade-Giles and leaves each syllable its own element
72
+ * to carry a tone class on.
73
+ *
74
+ * A piece that wrote nothing does not break the run, which is what carries the
75
+ * join over pinyin's own hyphen: 干干净净 is four syllables of one word, and
76
+ * the mark between the second and the third is dropped rather than counted as a
77
+ * gap.
43
78
  */
44
- export declare function writePiece(piece: ConvertedPiece, options: HtmlOptions): string;
79
+ export declare function writePieces(pieces: readonly ConvertedPiece[], options: HtmlOptions): string;
45
80
  /**
46
81
  * Mark up a converted text, one element per syllable.
47
82
  *
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3E;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAwDD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3C;AAwBD;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,WAAW,GACnB,MAAM,CA4BR;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER"}
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;CAC9C;AAYD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,EAAE,WAAW,GACnB,MAAM,CAgBR;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER"}
@@ -1,49 +1,13 @@
1
- import { isUncertain } from "../decode/confidence.js";
2
- export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
3
- import { READING_CHARGE } from "../decode/lattice.js";
4
- import { DEFAULT_LOCALE } from "../script/script.js";
5
- import { writeSyllable } from "../syllable/syllable.js";
6
- /**
7
- * The class every syllable carries, whatever else it carries.
8
- */
9
- const SYLLABLE_CLASS = "py-syllable";
10
- const UNCERTAIN_CLASS = "py-uncertain";
11
1
  /**
12
- * What a syllable declares itself to be, in the reading standard it was read in.
13
- *
14
- * A syllable element holds Mandarin written in the Latin alphabet, which is
15
- * neither the `zh` of the surrounding page nor the `en` of a page that quotes
16
- * it — and nothing about `yín` on its own says so. The tag is what a screen
17
- * reader consults before deciding how to pronounce it, and what a browser
18
- * consults for hyphenation and font selection; without one, `xíng` is read as
19
- * whatever the page around it claims to be, which is how pinyin ends up
20
- * spoken as English.
21
- *
22
- * The subtags are all registered and mean exactly this: `Latn` for the script,
23
- * the region for the reading standard, and the `pinyin` variant, whose prefix
24
- * in the IANA registry is `zh-Latn`. The region is the one distinction the
25
- * conversion itself makes — 垃圾 is `lājī` under `zh-CN` and `lèsè` under
26
- * `zh-TW` — so it is read off {@link ConvertOptions.locale} rather than
27
- * guessed at.
2
+ * A conversion as markup, and the options that decide what the markup carries.
28
3
  *
29
- * Tone notation does not enter into it. `hang2` is pinyin spelt with a tone
30
- * number, not another romanisation, so it takes the same tag as `háng`.
31
- *
32
- * The cost is the tag repeated on every syllable, which is the price of
33
- * wrapping nothing around the whole conversion. A caller who would rather
34
- * declare it once can set `lang: false` and put the same tag on a wrapper of
35
- * their own, which is inherited by everything inside it.
4
+ * One element per syllable, which is what lets a page colour a tone or mark a
5
+ * guess. What goes inside one of those elements is `syllable-span.ts` and the
6
+ * ruby that puts the reading over the hanzi is `annotate.ts`.
36
7
  */
37
- function languageTag(locale = DEFAULT_LOCALE) {
38
- switch (locale) {
39
- case "zh-CN": {
40
- return "zh-Latn-CN-pinyin";
41
- }
42
- case "zh-TW": {
43
- return "zh-Latn-TW-pinyin";
44
- }
45
- }
46
- }
8
+ export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
9
+ import { writePiece } from "./syllable-span.js";
10
+ export { writePiece } from "./syllable-span.js";
47
11
  /**
48
12
  * How each character that means something in markup is written as text.
49
13
  */
@@ -69,49 +33,36 @@ export function escape(text) {
69
33
  });
70
34
  }
71
35
  /**
72
- * The readings a syllable was chosen over, as the reader would write them.
36
+ * Mark up a run of pieces, with the system's join between two syllables.
73
37
  *
74
- * Only the ones that made it uncertain: a rival dearer than
75
- * {@link READING_CHARGE} could only be taken by breaking a dictionary word
76
- * apart, so it was never really in the running and listing it would suggest
77
- * otherwise.
78
- */
79
- function alternativesOf(confidence, options) {
80
- const written = confidence.alternatives
81
- .filter((alternative) => alternative.cost < READING_CHARGE)
82
- .map((alternative) => alternative.reading
83
- .map((syllable) => writeSyllable(syllable, options.notation))
84
- .join(""));
85
- return [...new Set(written)];
86
- }
87
- /**
88
- * Mark up one piece of a conversion.
38
+ * Pinyin needs none. Its syllables are run together and the marks that divide
39
+ * them are pieces of their own. Every other system decides the join for itself,
40
+ * and the join is what separates the five at this level, so it is written
41
+ * between the spans rather than inside one. `<span>Pei³</span>-<span>ching¹
42
+ * </span>` is one word in Wade-Giles and leaves each syllable its own element
43
+ * to carry a tone class on.
44
+ *
45
+ * A piece that wrote nothing does not break the run, which is what carries the
46
+ * join over pinyin's own hyphen: 干干净净 is four syllables of one word, and
47
+ * the mark between the second and the third is dropped rather than counted as a
48
+ * gap.
89
49
  */
90
- export function writePiece(piece, options) {
91
- const { toneClasses = true, markUncertain = true, lang = true } = options;
92
- if (piece.syllable === undefined) {
93
- return escape(piece.text);
50
+ export function writePieces(pieces, options) {
51
+ const { transcription } = options;
52
+ if (transcription === undefined) {
53
+ return pieces.map((piece) => writePiece(piece, options)).join("");
94
54
  }
95
- const classes = [SYLLABLE_CLASS];
96
- if (toneClasses && piece.syllable.tone !== undefined) {
97
- classes.push(`py-tone-${String(piece.syllable.tone)}`);
98
- }
99
- const alternatives = markUncertain &&
100
- piece.confidence !== undefined &&
101
- isUncertain(piece.confidence)
102
- ? alternativesOf(piece.confidence, options)
103
- : [];
104
- if (alternatives.length > 0) {
105
- classes.push(UNCERTAIN_CLASS);
106
- }
107
- const attributes = [`class="${classes.join(" ")}"`];
108
- if (lang) {
109
- attributes.push(`lang="${languageTag(options.locale)}"`);
110
- }
111
- if (alternatives.length > 0) {
112
- attributes.push(`data-alternatives="${escape(alternatives.join(" "))}"`);
55
+ const written = [];
56
+ let isJoined = false;
57
+ for (const piece of pieces) {
58
+ const markup = writePiece(piece, options);
59
+ if (piece.syllable !== undefined && isJoined) {
60
+ written.push(transcription.separator);
61
+ }
62
+ written.push(markup);
63
+ isJoined = piece.syllable !== undefined || (isJoined && markup === "");
113
64
  }
114
- return `<span ${attributes.join(" ")}>${escape(piece.text)}</span>`;
65
+ return written.join("");
115
66
  }
116
67
  /**
117
68
  * Mark up a converted text, one element per syllable.
@@ -120,6 +71,6 @@ export function writePiece(piece, options) {
120
71
  * once and render more than one way.
121
72
  */
122
73
  export function toHtml(pieces, options = {}) {
123
- return pieces.map((piece) => writePiece(piece, options)).join("");
74
+ return writePieces(pieces, options);
124
75
  }
125
76
  //# sourceMappingURL=html.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA0B,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AA+BxD;;GAEG;AACH,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,MAAM,eAAe,GAAG,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAS,WAAW,CAAC,MAAM,GAAW,cAAc;IAClD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,EAAE,CAAC;YACb,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QACD,K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OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1C,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,EAAE,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,QAAQ,GAAG,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,QAAQ,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CACpB,MAAiC,EACjC,OAAO,GAAgB,EAAE;IAEzB,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * What a written reading declares itself to be, in BCP 47.
3
+ *
4
+ * One place that knows the subtags and the order they go in, since the tag is
5
+ * the same question whether the reading is pinyin or one of the five systems
6
+ * that can stand in for it.
7
+ */
8
+ import { type Locale } from "../script/script.js";
9
+ import type { TranscriptionSystem } from "../transcription/systems.js";
10
+ /**
11
+ * The BCP 47 region subtag for a reading standard.
12
+ */
13
+ export declare function regionOf(locale: Locale): string;
14
+ /**
15
+ * What a syllable declares itself to be, in the system it was written in.
16
+ *
17
+ * A syllable element holds Mandarin written in some script that is not the `zh`
18
+ * of the surrounding page and not the `en` of a page that quotes it, and
19
+ * nothing about `yín` on its own says so. The tag is what a screen reader
20
+ * consults before deciding how to pronounce it, and what a browser consults for
21
+ * hyphenation and font selection. Without one, `xíng` is read as whatever the
22
+ * page around it claims to be, which is how pinyin ends up spoken as English.
23
+ *
24
+ * The subtags are registered and mean exactly this. The script is `Latn` for a
25
+ * romanisation and `Bopo` for bopomofo, the region is the reading standard, and
26
+ * the variant names the system where the IANA registry has one. It has `pinyin`
27
+ * and `wadegile`, both with the prefix `zh-Latn`, and `fonipa` for the IPA.
28
+ *
29
+ * | System | `zh-CN` | `zh-TW` |
30
+ * | --- | --- | --- |
31
+ * | pinyin | `zh-Latn-CN-pinyin` | `zh-Latn-TW-pinyin` |
32
+ * | bopomofo | `zh-Bopo-CN` | `zh-Bopo-TW` |
33
+ * | Wade-Giles | `zh-Latn-CN-wadegile` | `zh-Latn-TW-wadegile` |
34
+ * | Yale | `zh-Latn-CN` | `zh-Latn-TW` |
35
+ * | Gwoyeu Romatzyh | `zh-Latn-CN` | `zh-Latn-TW` |
36
+ * | IPA | `zh-Latn-CN-fonipa` | `zh-Latn-TW-fonipa` |
37
+ *
38
+ * **The region is carried by every one of them**, because the distinction it
39
+ * marks is in the reading rather than in the spelling. 垃圾 is `lājī` under
40
+ * `zh-CN` and `lèsè` under `zh-TW`, and it is two different words in bopomofo
41
+ * for the same reason, so the region is read off {@link ConvertOptions.locale}
42
+ * rather than guessed at.
43
+ *
44
+ * Yale and Gwoyeu Romatzyh name themselves nowhere, the registry having no
45
+ * variant for either, so both go out saying only that they are Mandarin in the
46
+ * Latin alphabet. See {@link TranscriptionSystem.variant}.
47
+ *
48
+ * Tone notation does not enter into it. `hang2` is pinyin spelt with a tone
49
+ * number, not another romanisation, so it takes the same tag as `háng`.
50
+ *
51
+ * The cost is the tag repeated on every syllable, which is the price of
52
+ * wrapping nothing around the whole conversion. A caller who would rather
53
+ * declare it once can set `lang: false` and put the same tag on a wrapper of
54
+ * their own, which is inherited by everything inside it.
55
+ */
56
+ export declare function languageTag(locale?: Locale, system?: TranscriptionSystem): string;
57
+ //# sourceMappingURL=language-tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-tag.d.ts","sourceRoot":"","sources":["../../src/format/language-tag.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AASvE;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,WAAW,CACzB,MAAM,GAAE,MAAuB,EAC/B,MAAM,CAAC,EAAE,mBAAmB,GAC3B,MAAM,CAKR"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * What a written reading declares itself to be, in BCP 47.
3
+ *
4
+ * One place that knows the subtags and the order they go in, since the tag is
5
+ * the same question whether the reading is pinyin or one of the five systems
6
+ * that can stand in for it.
7
+ */
8
+ import { DEFAULT_LOCALE } from "../script/script.js";
9
+ /**
10
+ * The pinyin variant's script and its own subtag, which a conversion writes by
11
+ * default.
12
+ */
13
+ const PINYIN_SCRIPT = "Latn";
14
+ const PINYIN_VARIANT = "pinyin";
15
+ /**
16
+ * The BCP 47 region subtag for a reading standard.
17
+ */
18
+ export function regionOf(locale) {
19
+ switch (locale) {
20
+ case "zh-CN": {
21
+ return "CN";
22
+ }
23
+ case "zh-TW": {
24
+ return "TW";
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * What a syllable declares itself to be, in the system it was written in.
30
+ *
31
+ * A syllable element holds Mandarin written in some script that is not the `zh`
32
+ * of the surrounding page and not the `en` of a page that quotes it, and
33
+ * nothing about `yín` on its own says so. The tag is what a screen reader
34
+ * consults before deciding how to pronounce it, and what a browser consults for
35
+ * hyphenation and font selection. Without one, `xíng` is read as whatever the
36
+ * page around it claims to be, which is how pinyin ends up spoken as English.
37
+ *
38
+ * The subtags are registered and mean exactly this. The script is `Latn` for a
39
+ * romanisation and `Bopo` for bopomofo, the region is the reading standard, and
40
+ * the variant names the system where the IANA registry has one. It has `pinyin`
41
+ * and `wadegile`, both with the prefix `zh-Latn`, and `fonipa` for the IPA.
42
+ *
43
+ * | System | `zh-CN` | `zh-TW` |
44
+ * | --- | --- | --- |
45
+ * | pinyin | `zh-Latn-CN-pinyin` | `zh-Latn-TW-pinyin` |
46
+ * | bopomofo | `zh-Bopo-CN` | `zh-Bopo-TW` |
47
+ * | Wade-Giles | `zh-Latn-CN-wadegile` | `zh-Latn-TW-wadegile` |
48
+ * | Yale | `zh-Latn-CN` | `zh-Latn-TW` |
49
+ * | Gwoyeu Romatzyh | `zh-Latn-CN` | `zh-Latn-TW` |
50
+ * | IPA | `zh-Latn-CN-fonipa` | `zh-Latn-TW-fonipa` |
51
+ *
52
+ * **The region is carried by every one of them**, because the distinction it
53
+ * marks is in the reading rather than in the spelling. 垃圾 is `lājī` under
54
+ * `zh-CN` and `lèsè` under `zh-TW`, and it is two different words in bopomofo
55
+ * for the same reason, so the region is read off {@link ConvertOptions.locale}
56
+ * rather than guessed at.
57
+ *
58
+ * Yale and Gwoyeu Romatzyh name themselves nowhere, the registry having no
59
+ * variant for either, so both go out saying only that they are Mandarin in the
60
+ * Latin alphabet. See {@link TranscriptionSystem.variant}.
61
+ *
62
+ * Tone notation does not enter into it. `hang2` is pinyin spelt with a tone
63
+ * number, not another romanisation, so it takes the same tag as `háng`.
64
+ *
65
+ * The cost is the tag repeated on every syllable, which is the price of
66
+ * wrapping nothing around the whole conversion. A caller who would rather
67
+ * declare it once can set `lang: false` and put the same tag on a wrapper of
68
+ * their own, which is inherited by everything inside it.
69
+ */
70
+ export function languageTag(locale = DEFAULT_LOCALE, system) {
71
+ const script = system?.script ?? PINYIN_SCRIPT;
72
+ const variant = system === undefined ? PINYIN_VARIANT : system.variant;
73
+ const tag = `zh-${script}-${regionOf(locale)}`;
74
+ return variant === undefined ? tag : `${tag}-${variant}`;
75
+ }
76
+ //# sourceMappingURL=language-tag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-tag.js","sourceRoot":"","sources":["../../src/format/language-tag.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAGlE;;;GAGG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAM,GAAW,cAAc,EAC/B,MAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC;IAC/C,MAAM,OAAO,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;IACvE,MAAM,GAAG,GAAG,MAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/C,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ConvertedPiece } from "../decode/convert.js";
2
+ import { type HtmlOptions } from "./html.js";
3
+ /**
4
+ * Mark up one piece of a conversion.
5
+ *
6
+ * A piece that is pinyin's own mark writes nothing where a transcription is
7
+ * asked for, since {@link writePieces} puts the system's own join in its place.
8
+ */
9
+ export declare function writePiece(piece: ConvertedPiece, options: HtmlOptions): string;
10
+ //# sourceMappingURL=syllable-span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syllable-span.d.ts","sourceRoot":"","sources":["../../src/format/syllable-span.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAuDrD;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,WAAW,GACnB,MAAM,CAiCR"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * One syllable of a conversion, as the element that carries it.
3
+ *
4
+ * The classes, the language tag and the attribute naming what the decode
5
+ * rejected all hang off a single syllable, so they are decided in one place and
6
+ * `html.ts` is left with the run.
7
+ */
8
+ import { isUncertain } from "../decode/confidence.js";
9
+ import { READING_CHARGE } from "../decode/lattice.js";
10
+ import { writeSyllable } from "../syllable/syllable.js";
11
+ import { escape } from "./html.js";
12
+ import { languageTag } from "./language-tag.js";
13
+ import { capitalised, isCapitalised, isPinyinMark } from "./transcribed.js";
14
+ /**
15
+ * The class every syllable carries, whatever else it carries.
16
+ */
17
+ const SYLLABLE_CLASS = "py-syllable";
18
+ const UNCERTAIN_CLASS = "py-uncertain";
19
+ /**
20
+ * The readings a syllable was chosen over, as the reader would write them.
21
+ *
22
+ * Only the ones that made it uncertain: a rival dearer than
23
+ * {@link READING_CHARGE} could only be taken by breaking a dictionary word
24
+ * apart, so it was never really in the running and listing it would suggest
25
+ * otherwise.
26
+ */
27
+ function alternativesOf(confidence, options) {
28
+ const written = confidence.alternatives
29
+ .filter((alternative) => alternative.cost < READING_CHARGE)
30
+ .map((alternative) => alternative.reading
31
+ .map((syllable) => writeSyllable(syllable, options.notation))
32
+ .join(""));
33
+ return [...new Set(written)];
34
+ }
35
+ /**
36
+ * How one syllable is written, in pinyin or in the system that replaces it.
37
+ *
38
+ * The capital comes from the pinyin the conversion settled rather than from the
39
+ * syllable, for the reason {@link isCapitalised} gives, and only the systems
40
+ * that write capitals at all take it.
41
+ */
42
+ function readingOf(piece, syllable, options) {
43
+ const { transcription } = options;
44
+ if (transcription === undefined) {
45
+ return piece.text;
46
+ }
47
+ const written = transcription.write(syllable, options.notation !== "none");
48
+ return transcription.capitals && isCapitalised(piece.text)
49
+ ? capitalised(written)
50
+ : written;
51
+ }
52
+ /**
53
+ * Mark up one piece of a conversion.
54
+ *
55
+ * A piece that is pinyin's own mark writes nothing where a transcription is
56
+ * asked for, since {@link writePieces} puts the system's own join in its place.
57
+ */
58
+ export function writePiece(piece, options) {
59
+ const { toneClasses = true, markUncertain = true, lang = true } = options;
60
+ if (piece.syllable === undefined) {
61
+ return options.transcription !== undefined && isPinyinMark(piece)
62
+ ? ""
63
+ : escape(piece.text);
64
+ }
65
+ const classes = [SYLLABLE_CLASS];
66
+ if (toneClasses && piece.syllable.tone !== undefined) {
67
+ classes.push(`py-tone-${String(piece.syllable.tone)}`);
68
+ }
69
+ const alternatives = markUncertain &&
70
+ piece.confidence !== undefined &&
71
+ isUncertain(piece.confidence)
72
+ ? alternativesOf(piece.confidence, options)
73
+ : [];
74
+ if (alternatives.length > 0) {
75
+ classes.push(UNCERTAIN_CLASS);
76
+ }
77
+ const attributes = [`class="${classes.join(" ")}"`];
78
+ if (lang) {
79
+ attributes.push(`lang="${languageTag(options.locale, options.transcription)}"`);
80
+ }
81
+ if (alternatives.length > 0) {
82
+ attributes.push(`data-alternatives="${escape(alternatives.join(" "))}"`);
83
+ }
84
+ const reading = readingOf(piece, piece.syllable, options);
85
+ return `<span ${attributes.join(" ")}>${escape(reading)}</span>`;
86
+ }
87
+ //# sourceMappingURL=syllable-span.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syllable-span.js","sourceRoot":"","sources":["../../src/format/syllable-span.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,WAAW,EAA0B,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAi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IACD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,UAAU,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1D,OAAO,SAAS,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;AACnE,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What the two transcription paths agree about.
3
+ *
4
+ * `toTranscription` writes a string and `toHtml` writes markup, and both have
5
+ * to put the capitals back and both have to decide what becomes of pinyin's own
6
+ * orthography. Keeping the answers here is what stops the two from drifting.
7
+ */
8
+ import type { ConvertedPiece } from "../decode/convert.js";
9
+ /**
10
+ * Whether a piece was written with a capital.
11
+ *
12
+ * Read off the text the conversion produced rather than recomputed, because
13
+ * capitalisation is settled by `convertPieces` against the whole sentence (a
14
+ * proper noun, or the first word after a full stop) and none of that survives
15
+ * in a bare syllable.
16
+ */
17
+ export declare function isCapitalised(text: string): boolean;
18
+ /**
19
+ * Put a capital back on a transcribed word.
20
+ */
21
+ export declare function capitalised(text: string): string;
22
+ /**
23
+ * Whether a piece is a mark pinyin writes and another system does not.
24
+ *
25
+ * The hyphen of `gāngān-jìngjìng` is the whole of it. GB/T 16159 puts it inside
26
+ * one orthographic word, and every other system joins the syllables of a word
27
+ * its own way. Wade-Giles hyphenates all of them, bopomofo spaces them, Yale
28
+ * and Gwoyeu Romatzyh and the IPA run them together, so carrying pinyin's mark
29
+ * across writes `ㄍㄢ ㄍㄢ-ㄐㄧㄥˋ ㄐㄧㄥˋ`, a hyphen in a script that has none.
30
+ *
31
+ * A piece naming no source is pinyin's own, which is the distinction
32
+ * `sourcePiece` exists to draw. The space between two words is pinyin's too and
33
+ * is kept, since every system puts one there.
34
+ */
35
+ export declare function isPinyinMark(piece: ConvertedPiece): boolean;
36
+ //# sourceMappingURL=transcribed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcribed.d.ts","sourceRoot":"","sources":["../../src/format/transcribed.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGnD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAM3D"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Whether a piece was written with a capital.
3
+ *
4
+ * Read off the text the conversion produced rather than recomputed, because
5
+ * capitalisation is settled by `convertPieces` against the whole sentence (a
6
+ * proper noun, or the first word after a full stop) and none of that survives
7
+ * in a bare syllable.
8
+ */
9
+ export function isCapitalised(text) {
10
+ const first = /\p{L}/u.exec(text)?.[0];
11
+ return first !== undefined && first !== first.toLowerCase();
12
+ }
13
+ /**
14
+ * Put a capital back on a transcribed word.
15
+ */
16
+ export function capitalised(text) {
17
+ // Not global: only the first letter of the word takes the capital.
18
+ return text.replace(/\p{L}/u, (letter) => letter.toUpperCase());
19
+ }
20
+ /**
21
+ * Whether a piece is a mark pinyin writes and another system does not.
22
+ *
23
+ * The hyphen of `gāngān-jìngjìng` is the whole of it. GB/T 16159 puts it inside
24
+ * one orthographic word, and every other system joins the syllables of a word
25
+ * its own way. Wade-Giles hyphenates all of them, bopomofo spaces them, Yale
26
+ * and Gwoyeu Romatzyh and the IPA run them together, so carrying pinyin's mark
27
+ * across writes `ㄍㄢ ㄍㄢ-ㄐㄧㄥˋ ㄐㄧㄥˋ`, a hyphen in a script that has none.
28
+ *
29
+ * A piece naming no source is pinyin's own, which is the distinction
30
+ * `sourcePiece` exists to draw. The space between two words is pinyin's too and
31
+ * is kept, since every system puts one there.
32
+ */
33
+ export function isPinyinMark(piece) {
34
+ return (piece.syllable === undefined &&
35
+ piece.source === undefined &&
36
+ piece.text.trim() !== "");
37
+ }
38
+ //# sourceMappingURL=transcribed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcribed.js","sourceRoot":"","sources":["../../src/format/transcribed.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,mEAAmE;IACnE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,KAAqB;IAChD,OAAO,CACL,KAAK,CAAC,QAAQ,KAAK,SAAS;QAC5B,KAAK,CAAC,MAAM,KAAK,SAAS;QAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CACzB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"transcription.d.ts","sourceRoot":"","sources":["../../src/format/transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MA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,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,MAAM,CASR"}
@@ -1,24 +1,6 @@
1
1
  import { convertPieces, } from "../decode/convert.js";
2
2
  import { writeWadeGilesWord } from "../transcription/wade-giles.js";
3
- /**
4
- * Whether a piece was written with a capital.
5
- *
6
- * Read off the text the conversion produced rather than recomputed, because
7
- * capitalisation is settled by {@link convertPieces} against the whole sentence
8
- * — a proper noun, or the first word after a full stop — and none of that
9
- * survives in a bare {@link Syllable}.
10
- */
11
- function isCapitalised(text) {
12
- const first = /\p{L}/u.exec(text)?.[0];
13
- return first !== undefined && first !== first.toLowerCase();
14
- }
15
- /**
16
- * Put a capital back on a transcribed word.
17
- */
18
- function capitalised(text) {
19
- // Not global: only the first letter of the word takes the capital.
20
- return text.replace(/\p{L}/u, (letter) => letter.toUpperCase());
21
- }
3
+ import { capitalised, isCapitalised, isPinyinMark } from "./transcribed.js";
22
4
  /**
23
5
  * Write a conversion in another transcription system, word by word.
24
6
  *
@@ -64,6 +46,12 @@ export function toTranscription(pieces, writeWord, options = {}) {
64
46
  };
65
47
  for (const piece of pieces) {
66
48
  if (piece.syllable === undefined) {
49
+ // A mark pinyin writes and this system does not is dropped rather than
50
+ // ending the word, so the system's own join covers it. See
51
+ // {@link isPinyinMark}.
52
+ if (isPinyinMark(piece)) {
53
+ continue;
54
+ }
67
55
  flush();
68
56
  written.push(piece.text);
69
57
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"transcription.js","sourceRoot":"","sources":["../../src/format/transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAiCpE;;;;;;;GAOG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,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