yomitan-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +485 -0
  2. package/dist/anki-connect-BQyCGW3O.cjs +513 -0
  3. package/dist/anki-connect-BQyCGW3O.cjs.map +1 -0
  4. package/dist/anki-connect-CPPuhyiQ.js +6 -0
  5. package/dist/anki-connect-DbrQHphS.js +495 -0
  6. package/dist/anki-connect-DbrQHphS.js.map +1 -0
  7. package/dist/anki-connect-DcheJrp-.cjs +6 -0
  8. package/dist/anki.cjs +1758 -0
  9. package/dist/anki.cjs.map +1 -0
  10. package/dist/anki.d.cts +751 -0
  11. package/dist/anki.d.cts.map +1 -0
  12. package/dist/anki.d.ts +751 -0
  13. package/dist/anki.d.ts.map +1 -0
  14. package/dist/anki.js +1751 -0
  15. package/dist/anki.js.map +1 -0
  16. package/dist/audio-D9DvYyB7.d.cts +48 -0
  17. package/dist/audio-D9DvYyB7.d.cts.map +1 -0
  18. package/dist/audio-DQulUkDM.d.ts +48 -0
  19. package/dist/audio-DQulUkDM.d.ts.map +1 -0
  20. package/dist/audio-url-generator-BXvQaqUi.cjs +4 -0
  21. package/dist/audio-url-generator-Dy2hb2Mm.cjs +414 -0
  22. package/dist/audio-url-generator-Dy2hb2Mm.cjs.map +1 -0
  23. package/dist/audio-url-generator-Qi0rfzHz.js +4 -0
  24. package/dist/audio-url-generator-pFQAB5Nb.js +390 -0
  25. package/dist/audio-url-generator-pFQAB5Nb.js.map +1 -0
  26. package/dist/audio.cjs +7 -0
  27. package/dist/audio.d.cts +86 -0
  28. package/dist/audio.d.cts.map +1 -0
  29. package/dist/audio.d.ts +86 -0
  30. package/dist/audio.d.ts.map +1 -0
  31. package/dist/audio.js +4 -0
  32. package/dist/batch-processor-BR-gB3H3.js +84 -0
  33. package/dist/batch-processor-BR-gB3H3.js.map +1 -0
  34. package/dist/batch-processor-CSF1acTw.cjs +3 -0
  35. package/dist/batch-processor-DFqM_L-_.cjs +91 -0
  36. package/dist/batch-processor-DFqM_L-_.cjs.map +1 -0
  37. package/dist/batch-processor-Quo9jUyf.js +3 -0
  38. package/dist/chunk-BCwAaXi7.cjs +31 -0
  39. package/dist/cjk-util-Dp0ZU0sh.cjs +167 -0
  40. package/dist/cjk-util-Dp0ZU0sh.cjs.map +1 -0
  41. package/dist/cjk-util-DubXBGDG.js +94 -0
  42. package/dist/cjk-util-DubXBGDG.js.map +1 -0
  43. package/dist/core-BUpclilG.d.cts +102 -0
  44. package/dist/core-BUpclilG.d.cts.map +1 -0
  45. package/dist/core-DFUj5GtA.d.ts +102 -0
  46. package/dist/core-DFUj5GtA.d.ts.map +1 -0
  47. package/dist/database.cjs +7 -0
  48. package/dist/database.d.cts +4 -0
  49. package/dist/database.d.ts +4 -0
  50. package/dist/database.js +5 -0
  51. package/dist/dictionary-D7l-qFt1.d.cts +316 -0
  52. package/dist/dictionary-D7l-qFt1.d.cts.map +1 -0
  53. package/dist/dictionary-_vzfBLWi.d.ts +316 -0
  54. package/dist/dictionary-_vzfBLWi.d.ts.map +1 -0
  55. package/dist/dictionary-data-util-CHnRdYZ9.cjs +378 -0
  56. package/dist/dictionary-data-util-CHnRdYZ9.cjs.map +1 -0
  57. package/dist/dictionary-data-util-CfOLfEDE.js +323 -0
  58. package/dist/dictionary-data-util-CfOLfEDE.js.map +1 -0
  59. package/dist/dictionary-database-BDC2f9zc.d.ts +58 -0
  60. package/dist/dictionary-database-BDC2f9zc.d.ts.map +1 -0
  61. package/dist/dictionary-database-CU4TsvCC.js +393 -0
  62. package/dist/dictionary-database-CU4TsvCC.js.map +1 -0
  63. package/dist/dictionary-database-DsOi04Sg.d.cts +58 -0
  64. package/dist/dictionary-database-DsOi04Sg.d.cts.map +1 -0
  65. package/dist/dictionary-database-lvFvftnO.cjs +412 -0
  66. package/dist/dictionary-database-lvFvftnO.cjs.map +1 -0
  67. package/dist/dictionary-importer-BkQQSBhm.d.ts +237 -0
  68. package/dist/dictionary-importer-BkQQSBhm.d.ts.map +1 -0
  69. package/dist/dictionary-importer-Cen1z6co.js +1821 -0
  70. package/dist/dictionary-importer-Cen1z6co.js.map +1 -0
  71. package/dist/dictionary-importer-DYmmWmcX.cjs +8 -0
  72. package/dist/dictionary-importer-Da3AuTZw.d.cts +237 -0
  73. package/dist/dictionary-importer-Da3AuTZw.d.cts.map +1 -0
  74. package/dist/dictionary-importer-Dhn75iZ4.cjs +1834 -0
  75. package/dist/dictionary-importer-Dhn75iZ4.cjs.map +1 -0
  76. package/dist/dictionary-importer-xWkel0h-.js +8 -0
  77. package/dist/dictionary-update-checker-BNE4pGTx.js +4 -0
  78. package/dist/dictionary-update-checker-Byjvifd2.cjs +75 -0
  79. package/dist/dictionary-update-checker-Byjvifd2.cjs.map +1 -0
  80. package/dist/dictionary-update-checker-YdpalZ41.cjs +4 -0
  81. package/dist/dictionary-update-checker-kKukiovj.js +69 -0
  82. package/dist/dictionary-update-checker-kKukiovj.js.map +1 -0
  83. package/dist/display-generator-BGVWiI0t.js +746 -0
  84. package/dist/display-generator-BGVWiI0t.js.map +1 -0
  85. package/dist/display-generator-BMQmG5Ov.cjs +9 -0
  86. package/dist/display-generator-BxZ7mBjP.js +9 -0
  87. package/dist/display-generator-DyP-HNzP.cjs +758 -0
  88. package/dist/display-generator-DyP-HNzP.cjs.map +1 -0
  89. package/dist/errors-BSezaJwm.cjs +35 -0
  90. package/dist/errors-BSezaJwm.cjs.map +1 -0
  91. package/dist/errors-DuuDSO5N.js +22 -0
  92. package/dist/errors-DuuDSO5N.js.map +1 -0
  93. package/dist/frequency-ranking-BXjfhhUQ.js +3 -0
  94. package/dist/frequency-ranking-Cx1kkIrw.cjs +3 -0
  95. package/dist/frequency-ranking-DEJMTMdg.js +159 -0
  96. package/dist/frequency-ranking-DEJMTMdg.js.map +1 -0
  97. package/dist/frequency-ranking-DVYxTXN-.cjs +166 -0
  98. package/dist/frequency-ranking-DVYxTXN-.cjs.map +1 -0
  99. package/dist/furigana-5HK97CY8.js +4 -0
  100. package/dist/furigana-9bBI9-qe.d.ts +47 -0
  101. package/dist/furigana-9bBI9-qe.d.ts.map +1 -0
  102. package/dist/furigana-B3-0y231.js +471 -0
  103. package/dist/furigana-B3-0y231.js.map +1 -0
  104. package/dist/furigana-CjOhzvZt.d.cts +47 -0
  105. package/dist/furigana-CjOhzvZt.d.cts.map +1 -0
  106. package/dist/furigana-DpZLcues.cjs +609 -0
  107. package/dist/furigana-DpZLcues.cjs.map +1 -0
  108. package/dist/furigana-h3v2ub4-.cjs +4 -0
  109. package/dist/import.cjs +12 -0
  110. package/dist/import.d.cts +107 -0
  111. package/dist/import.d.cts.map +1 -0
  112. package/dist/import.d.ts +107 -0
  113. package/dist/import.d.ts.map +1 -0
  114. package/dist/import.js +9 -0
  115. package/dist/index.cjs +275 -0
  116. package/dist/index.cjs.map +1 -0
  117. package/dist/index.d.cts +211 -0
  118. package/dist/index.d.cts.map +1 -0
  119. package/dist/index.d.ts +211 -0
  120. package/dist/index.d.ts.map +1 -0
  121. package/dist/index.js +238 -0
  122. package/dist/index.js.map +1 -0
  123. package/dist/json-DGd-cunA.js +17 -0
  124. package/dist/json-DGd-cunA.js.map +1 -0
  125. package/dist/json-DKWp-B7Y.cjs +30 -0
  126. package/dist/json-DKWp-B7Y.cjs.map +1 -0
  127. package/dist/language-KN_u-nTR.d.ts +104 -0
  128. package/dist/language-KN_u-nTR.d.ts.map +1 -0
  129. package/dist/language-xAbQxgXc.d.cts +104 -0
  130. package/dist/language-xAbQxgXc.d.cts.map +1 -0
  131. package/dist/language.cjs +15626 -0
  132. package/dist/language.cjs.map +1 -0
  133. package/dist/language.d.cts +959 -0
  134. package/dist/language.d.cts.map +1 -0
  135. package/dist/language.d.ts +959 -0
  136. package/dist/language.d.ts.map +1 -0
  137. package/dist/language.js +15522 -0
  138. package/dist/language.js.map +1 -0
  139. package/dist/log-D8KtR3aP.cjs +67 -0
  140. package/dist/log-D8KtR3aP.cjs.map +1 -0
  141. package/dist/log-hgSll-dS.js +60 -0
  142. package/dist/log-hgSll-dS.js.map +1 -0
  143. package/dist/lookup.cjs +13 -0
  144. package/dist/lookup.d.cts +161 -0
  145. package/dist/lookup.d.cts.map +1 -0
  146. package/dist/lookup.d.ts +161 -0
  147. package/dist/lookup.d.ts.map +1 -0
  148. package/dist/lookup.js +10 -0
  149. package/dist/media-loader-BABA_E4W.js +3 -0
  150. package/dist/media-loader-Ce9cuANS.cjs +21 -0
  151. package/dist/media-loader-Ce9cuANS.cjs.map +1 -0
  152. package/dist/media-loader-qRti-Q6h.js +14 -0
  153. package/dist/media-loader-qRti-Q6h.js.map +1 -0
  154. package/dist/media-loader-xlUGaJrx.cjs +3 -0
  155. package/dist/multi-language-transformer-AlxOM6b3.js +637 -0
  156. package/dist/multi-language-transformer-AlxOM6b3.js.map +1 -0
  157. package/dist/multi-language-transformer-MdbQBBOt.cjs +685 -0
  158. package/dist/multi-language-transformer-MdbQBBOt.cjs.map +1 -0
  159. package/dist/multi-language-transformer-SEhcJXEB.d.ts +63 -0
  160. package/dist/multi-language-transformer-SEhcJXEB.d.ts.map +1 -0
  161. package/dist/multi-language-transformer-Ul9mbRce.d.cts +63 -0
  162. package/dist/multi-language-transformer-Ul9mbRce.d.cts.map +1 -0
  163. package/dist/pronunciation-generator-BtBc4q_V.js +397 -0
  164. package/dist/pronunciation-generator-BtBc4q_V.js.map +1 -0
  165. package/dist/pronunciation-generator-CBYdXYou.js +4 -0
  166. package/dist/pronunciation-generator-CFbZlf5J.cjs +445 -0
  167. package/dist/pronunciation-generator-CFbZlf5J.cjs.map +1 -0
  168. package/dist/pronunciation-generator-DOz9hEuk.cjs +4 -0
  169. package/dist/render.cjs +2796 -0
  170. package/dist/render.cjs.map +1 -0
  171. package/dist/render.d.cts +424 -0
  172. package/dist/render.d.cts.map +1 -0
  173. package/dist/render.d.ts +424 -0
  174. package/dist/render.d.ts.map +1 -0
  175. package/dist/render.js +2777 -0
  176. package/dist/render.js.map +1 -0
  177. package/dist/sentence-parser-BPAJNzqW.js +126 -0
  178. package/dist/sentence-parser-BPAJNzqW.js.map +1 -0
  179. package/dist/sentence-parser-BVIOI64h.cjs +132 -0
  180. package/dist/sentence-parser-BVIOI64h.cjs.map +1 -0
  181. package/dist/sentence-parser-BoHO3cHn.js +5 -0
  182. package/dist/sentence-parser-DQVLSW0z.cjs +5 -0
  183. package/dist/structured-content-generator-BtOApkTW.cjs +4 -0
  184. package/dist/structured-content-generator-Bx62RYa8.js +4 -0
  185. package/dist/structured-content-generator-CLnybumI.js +276 -0
  186. package/dist/structured-content-generator-CLnybumI.js.map +1 -0
  187. package/dist/structured-content-generator-DrwkB0-k.cjs +282 -0
  188. package/dist/structured-content-generator-DrwkB0-k.cjs.map +1 -0
  189. package/dist/text-utilities-B7PIythe.js +8 -0
  190. package/dist/text-utilities-B7PIythe.js.map +1 -0
  191. package/dist/text-utilities-Del2Ivkg.cjs +15 -0
  192. package/dist/text-utilities-Del2Ivkg.cjs.map +1 -0
  193. package/dist/translator-CRPlPzqi.cjs +1545 -0
  194. package/dist/translator-CRPlPzqi.cjs.map +1 -0
  195. package/dist/translator-CWgG5drA.js +1539 -0
  196. package/dist/translator-CWgG5drA.js.map +1 -0
  197. package/dist/translator-CaGtJvnQ.cjs +6 -0
  198. package/dist/translator-Cc6OGxrW.d.ts +180 -0
  199. package/dist/translator-Cc6OGxrW.d.ts.map +1 -0
  200. package/dist/translator-CcA-s-W4.d.cts +180 -0
  201. package/dist/translator-CcA-s-W4.d.cts.map +1 -0
  202. package/dist/translator-CuJOTK6l.js +6 -0
  203. package/dist/utilities-C-lbZaJE.cjs +52 -0
  204. package/dist/utilities-C-lbZaJE.cjs.map +1 -0
  205. package/dist/utilities-bi3EF-q5.js +33 -0
  206. package/dist/utilities-bi3EF-q5.js.map +1 -0
  207. package/package.json +102 -0
@@ -0,0 +1,758 @@
1
+ "use strict";
2
+ const require_dictionary_data_util = require('./dictionary-data-util-CHnRdYZ9.cjs');
3
+ const require_furigana = require('./furigana-DpZLcues.cjs');
4
+ const require_text_utilities = require('./text-utilities-Del2Ivkg.cjs');
5
+ const require_pronunciation_generator = require('./pronunciation-generator-CFbZlf5J.cjs');
6
+ const require_structured_content_generator = require('./structured-content-generator-DrwkB0-k.cjs');
7
+
8
+ //#region src/render/html-template-collection.ts
9
+ /**
10
+ * A collection of HTML templates parsed from raw HTML strings.
11
+ * Templates are identified by their `id` attribute, which must end with `-template`.
12
+ * The prefix before `-template` is used as the template name.
13
+ */
14
+ var HtmlTemplateCollection = class {
15
+ _templates;
16
+ _document;
17
+ /**
18
+ * Creates a new HtmlTemplateCollection.
19
+ * @param doc - The Document object to use for DOM operations.
20
+ */
21
+ constructor(doc) {
22
+ this._templates = new Map();
23
+ this._document = doc;
24
+ }
25
+ /**
26
+ * Loads templates from a raw HTML string.
27
+ * @param html - The HTML string containing `<template>` elements.
28
+ */
29
+ loadFromString(html) {
30
+ const parser = new this._document.defaultView.DOMParser();
31
+ const templatesDocument = parser.parseFromString(html, "text/html");
32
+ this.load(templatesDocument);
33
+ }
34
+ /**
35
+ * Loads templates from a Document source.
36
+ * @param source - The Document containing template elements.
37
+ */
38
+ load(source) {
39
+ const pattern = /^([\w\W]+)-template$/;
40
+ for (const template of Array.from(source.querySelectorAll("template"))) {
41
+ const match = pattern.exec(template.id);
42
+ if (match === null) continue;
43
+ this._prepareTemplate(template);
44
+ this._templates.set(match[1], template);
45
+ }
46
+ }
47
+ /**
48
+ * Instantiates a template by name, returning the first element child as a deep clone.
49
+ * @param name - The template name (without the `-template` suffix).
50
+ * @returns The cloned first element child.
51
+ * @throws Error if the template or its content element is not found.
52
+ */
53
+ instantiate(name) {
54
+ const { firstElementChild } = this.getTemplateContent(name);
55
+ if (firstElementChild === null) throw new Error(`Failed to find template content element: ${name}`);
56
+ return this._document.importNode(firstElementChild, true);
57
+ }
58
+ /**
59
+ * Instantiates a template by name, returning the entire content as a DocumentFragment clone.
60
+ * @param name - The template name (without the `-template` suffix).
61
+ * @returns The cloned DocumentFragment.
62
+ */
63
+ instantiateFragment(name) {
64
+ return this._document.importNode(this.getTemplateContent(name), true);
65
+ }
66
+ /**
67
+ * Gets the content DocumentFragment of a named template.
68
+ * @param name - The template name (without the `-template` suffix).
69
+ * @returns The template's content DocumentFragment.
70
+ * @throws Error if the template is not found.
71
+ */
72
+ getTemplateContent(name) {
73
+ const template = this._templates.get(name);
74
+ if (typeof template === "undefined") throw new Error(`Failed to find template: ${name}`);
75
+ return template.content;
76
+ }
77
+ /**
78
+ * Returns an iterator over all template elements.
79
+ */
80
+ getAllTemplates() {
81
+ return this._templates.values();
82
+ }
83
+ _prepareTemplate(template) {
84
+ if (template.dataset.removeWhitespaceText === "true") this._removeWhitespaceText(template);
85
+ }
86
+ _removeWhitespaceText(template) {
87
+ const { content } = template;
88
+ const { TEXT_NODE } = this._document.defaultView ? this._document.defaultView.Node : { TEXT_NODE: 3 };
89
+ const iterator = this._document.createNodeIterator(
90
+ content,
91
+ 4
92
+ /* NodeFilter.SHOW_TEXT */
93
+ );
94
+ const removeNodes = [];
95
+ while (true) {
96
+ const node = iterator.nextNode();
97
+ if (node === null) break;
98
+ if (node.nodeType === TEXT_NODE && (node.nodeValue ?? "").trim().length === 0) removeNodes.push(node);
99
+ }
100
+ for (const node of removeNodes) {
101
+ const { parentNode } = node;
102
+ if (parentNode !== null) parentNode.removeChild(node);
103
+ }
104
+ }
105
+ };
106
+
107
+ //#endregion
108
+ //#region src/render/display-generator.ts
109
+ /**
110
+ * Generates DOM elements for displaying dictionary entries.
111
+ * This is the main rendering class that creates term entries, kanji entries,
112
+ * and all associated sub-elements (headwords, definitions, tags, frequencies, etc.).
113
+ */
114
+ var DisplayGenerator = class {
115
+ _contentManager;
116
+ _templates;
117
+ _structuredContentGenerator;
118
+ _pronunciationGenerator;
119
+ _language;
120
+ _document;
121
+ /**
122
+ * Creates a new DisplayGenerator.
123
+ * @param doc - The Document object to use for DOM operations.
124
+ * @param contentManager - The content manager for loading media.
125
+ * @param templateHtml - The HTML string containing display templates.
126
+ */
127
+ constructor(doc, contentManager, templateHtml) {
128
+ this._document = doc;
129
+ this._contentManager = contentManager;
130
+ this._templates = new HtmlTemplateCollection(doc);
131
+ this._templates.loadFromString(templateHtml);
132
+ this._structuredContentGenerator = new require_structured_content_generator.StructuredContentGenerator(this._contentManager, doc);
133
+ this._pronunciationGenerator = new require_pronunciation_generator.PronunciationGenerator(doc);
134
+ this._language = "ja";
135
+ }
136
+ /** The current content manager. */
137
+ get contentManager() {
138
+ return this._contentManager;
139
+ }
140
+ set contentManager(contentManager) {
141
+ this._contentManager = contentManager;
142
+ }
143
+ /**
144
+ * Updates the target language for rendering.
145
+ * @param language - The BCP 47 language tag (e.g. 'ja', 'zh').
146
+ */
147
+ updateLanguage(language) {
148
+ this._language = language;
149
+ }
150
+ /**
151
+ * Creates a complete term entry element from a dictionary entry.
152
+ * @param dictionaryEntry - The term dictionary entry data.
153
+ * @param dictionaryInfo - Array of dictionary summary information.
154
+ * @returns An HTMLElement representing the full term entry.
155
+ */
156
+ createTermEntry(dictionaryEntry, dictionaryInfo) {
157
+ const node = this._instantiate("term-entry");
158
+ const headwordsContainer = this._querySelector(node, ".headword-list");
159
+ const inflectionRuleChainsContainer = this._querySelector(node, ".inflection-rule-chains");
160
+ const groupedPronunciationsContainer = this._querySelector(node, ".pronunciation-group-list");
161
+ const frequencyGroupListContainer = this._querySelector(node, ".frequency-group-list");
162
+ const definitionsContainer = this._querySelector(node, ".definition-list");
163
+ const headwordTagsContainer = this._querySelector(node, ".headword-list-tag-list");
164
+ const { headwords, type, inflectionRuleChainCandidates, definitions, frequencies, pronunciations } = dictionaryEntry;
165
+ const groupedPronunciations = require_dictionary_data_util.getGroupedPronunciations(dictionaryEntry);
166
+ const pronunciationCount = groupedPronunciations.reduce((i, v) => i + v.pronunciations.length, 0);
167
+ const groupedFrequencies = require_dictionary_data_util.groupTermFrequencies(dictionaryEntry, dictionaryInfo);
168
+ const termTags = require_dictionary_data_util.groupTermTags(dictionaryEntry);
169
+ const uniqueTerms = new Set();
170
+ const uniqueReadings = new Set();
171
+ const primaryMatchTypes = new Set();
172
+ for (const { term, reading, sources } of headwords) {
173
+ uniqueTerms.add(term);
174
+ uniqueReadings.add(reading);
175
+ for (const { matchType, isPrimary } of sources) {
176
+ if (!isPrimary) continue;
177
+ primaryMatchTypes.add(matchType);
178
+ }
179
+ }
180
+ node.dataset.format = type;
181
+ node.dataset.headwordCount = `${headwords.length}`;
182
+ node.dataset.definitionCount = `${definitions.length}`;
183
+ node.dataset.pronunciationDictionaryCount = `${groupedPronunciations.length}`;
184
+ node.dataset.pronunciationCount = `${pronunciationCount}`;
185
+ node.dataset.uniqueTermCount = `${uniqueTerms.size}`;
186
+ node.dataset.uniqueReadingCount = `${uniqueReadings.size}`;
187
+ node.dataset.frequencyCount = `${frequencies.length}`;
188
+ node.dataset.groupedFrequencyCount = `${groupedFrequencies.length}`;
189
+ node.dataset.primaryMatchTypes = [...primaryMatchTypes].join(" ");
190
+ for (let i = 0, ii = headwords.length; i < ii; ++i) {
191
+ const node2 = this._createTermHeadword(headwords[i], i, pronunciations);
192
+ node2.dataset.index = `${i}`;
193
+ headwordsContainer.appendChild(node2);
194
+ }
195
+ headwordsContainer.dataset.count = `${headwords.length}`;
196
+ this._appendMultiple(inflectionRuleChainsContainer, this._createInflectionRuleChain.bind(this), inflectionRuleChainCandidates);
197
+ this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false);
198
+ this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations);
199
+ this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length);
200
+ for (const term of uniqueTerms) headwordTagsContainer.appendChild(this._createSearchTag(term));
201
+ for (const reading of uniqueReadings) {
202
+ if (uniqueTerms.has(reading)) continue;
203
+ headwordTagsContainer.appendChild(this._createSearchTag(reading));
204
+ }
205
+ const dictionaryTag = this._createDictionaryTag("");
206
+ for (let i = 0, ii = definitions.length; i < ii; ++i) {
207
+ const definition = definitions[i];
208
+ const { dictionary, dictionaryAlias } = definition;
209
+ if (dictionaryTag.dictionaries.includes(dictionary)) dictionaryTag.redundant = true;
210
+ else {
211
+ dictionaryTag.redundant = false;
212
+ dictionaryTag.dictionaries.push(dictionary);
213
+ dictionaryTag.name = dictionaryAlias;
214
+ dictionaryTag.content = [dictionary];
215
+ const currentDictionaryInfo = dictionaryInfo.find(({ title }) => title === dictionary);
216
+ if (currentDictionaryInfo) {
217
+ const dictionaryContentArray = [];
218
+ dictionaryContentArray.push(currentDictionaryInfo.title);
219
+ if (currentDictionaryInfo.author) dictionaryContentArray.push(`Author: ${currentDictionaryInfo.author}`);
220
+ if (currentDictionaryInfo.description) dictionaryContentArray.push(`Description: ${currentDictionaryInfo.description}`);
221
+ if (currentDictionaryInfo.url) dictionaryContentArray.push(`URL: ${currentDictionaryInfo.url}`);
222
+ const totalTerms = currentDictionaryInfo?.counts?.terms?.total;
223
+ if (totalTerms !== void 0 && totalTerms > 0) dictionaryContentArray.push(`Term Count: ${totalTerms.toString()}`);
224
+ dictionaryTag.content = dictionaryContentArray;
225
+ }
226
+ }
227
+ const node2 = this._createTermDefinition(definition, dictionaryTag, headwords, uniqueTerms, uniqueReadings);
228
+ node2.dataset.index = `${i}`;
229
+ definitionsContainer.appendChild(node2);
230
+ }
231
+ definitionsContainer.dataset.count = `${definitions.length}`;
232
+ return node;
233
+ }
234
+ /**
235
+ * Creates a complete kanji entry element from a dictionary entry.
236
+ * @param dictionaryEntry - The kanji dictionary entry data.
237
+ * @param dictionaryInfo - Array of dictionary summary information.
238
+ * @returns An HTMLElement representing the full kanji entry.
239
+ */
240
+ createKanjiEntry(dictionaryEntry, dictionaryInfo) {
241
+ const node = this._instantiate("kanji-entry");
242
+ node.dataset.dictionary = dictionaryEntry.dictionary;
243
+ const glyphContainer = this._querySelector(node, ".kanji-glyph");
244
+ const frequencyGroupListContainer = this._querySelector(node, ".frequency-group-list");
245
+ const tagContainer = this._querySelector(node, ".kanji-tag-list");
246
+ const definitionsContainer = this._querySelector(node, ".kanji-gloss-list");
247
+ const chineseReadingsContainer = this._querySelector(node, ".kanji-readings-chinese");
248
+ const japaneseReadingsContainer = this._querySelector(node, ".kanji-readings-japanese");
249
+ const statisticsContainer = this._querySelector(node, ".kanji-statistics");
250
+ const classificationsContainer = this._querySelector(node, ".kanji-classifications");
251
+ const codepointsContainer = this._querySelector(node, ".kanji-codepoints");
252
+ const dictionaryIndicesContainer = this._querySelector(node, ".kanji-dictionary-indices");
253
+ this._setTextContent(glyphContainer, dictionaryEntry.character, this._language);
254
+ if (this._language === "ja") glyphContainer.style.fontFamily = "kanji-stroke-orders, sans-serif";
255
+ const groupedFrequencies = require_dictionary_data_util.groupKanjiFrequencies(dictionaryEntry.frequencies, dictionaryInfo);
256
+ const dictionaryTag = this._createDictionaryTag("");
257
+ dictionaryTag.name = dictionaryEntry.dictionaryAlias;
258
+ dictionaryTag.content = [dictionaryEntry.dictionary];
259
+ const currentDictionaryInfo = dictionaryInfo.find(({ title }) => title === dictionaryEntry.dictionary);
260
+ if (currentDictionaryInfo) {
261
+ const dictionaryContentArray = [];
262
+ dictionaryContentArray.push(currentDictionaryInfo.title);
263
+ if (currentDictionaryInfo.author) dictionaryContentArray.push(`Author: ${currentDictionaryInfo.author}`);
264
+ if (currentDictionaryInfo.description) dictionaryContentArray.push(`Description: ${currentDictionaryInfo.description}`);
265
+ if (currentDictionaryInfo.url) dictionaryContentArray.push(`URL: ${currentDictionaryInfo.url}`);
266
+ const totalKanji = currentDictionaryInfo?.counts?.kanji?.total;
267
+ if (totalKanji !== void 0 && totalKanji > 0) dictionaryContentArray.push(`Kanji Count: ${totalKanji.toString()}`);
268
+ dictionaryTag.content = dictionaryContentArray;
269
+ }
270
+ this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true);
271
+ this._appendMultiple(tagContainer, this._createTag.bind(this), [...dictionaryEntry.tags, dictionaryTag]);
272
+ this._appendMultiple(definitionsContainer, this._createKanjiDefinition.bind(this), dictionaryEntry.definitions);
273
+ this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.onyomi);
274
+ this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.kunyomi);
275
+ statisticsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.misc));
276
+ classificationsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.class));
277
+ codepointsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.code));
278
+ dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.index));
279
+ return node;
280
+ }
281
+ /**
282
+ * Creates an empty footer notification element.
283
+ */
284
+ createEmptyFooterNotification() {
285
+ return this._instantiate("footer-notification");
286
+ }
287
+ /**
288
+ * Instantiates a named template, returning the first element child.
289
+ * @param name - The template name.
290
+ */
291
+ instantiateTemplate(name) {
292
+ return this._instantiate(name);
293
+ }
294
+ /**
295
+ * Instantiates a named template, returning the full DocumentFragment.
296
+ * @param name - The template name.
297
+ */
298
+ instantiateTemplateFragment(name) {
299
+ return this._templates.instantiateFragment(name);
300
+ }
301
+ _createTermHeadword(headword, headwordIndex, pronunciations) {
302
+ const { term, reading, tags, sources } = headword;
303
+ let isPrimaryAny = false;
304
+ const matchTypes = new Set();
305
+ const matchSources = new Set();
306
+ for (const { matchType, matchSource, isPrimary } of sources) {
307
+ if (isPrimary) isPrimaryAny = true;
308
+ matchTypes.add(matchType);
309
+ matchSources.add(matchSource);
310
+ }
311
+ const node = this._instantiate("headword");
312
+ const termContainer = this._querySelector(node, ".headword-term");
313
+ node.dataset.isPrimary = `${isPrimaryAny}`;
314
+ node.dataset.readingIsSame = `${reading === term}`;
315
+ node.dataset.frequency = require_dictionary_data_util.getTermFrequency(tags);
316
+ node.dataset.matchTypes = [...matchTypes].join(" ");
317
+ node.dataset.matchSources = [...matchSources].join(" ");
318
+ const { wordClasses } = headword;
319
+ const pronunciationCategories = this._getPronunciationCategories(reading, pronunciations, wordClasses, headwordIndex);
320
+ if (pronunciationCategories !== null) node.dataset.pronunciationCategories = pronunciationCategories;
321
+ if (wordClasses.length > 0) node.dataset.wordClasses = wordClasses.join(" ");
322
+ const headwordReading = this._querySelector(node, ".headword-reading");
323
+ this._setTextContent(headwordReading, reading);
324
+ this._appendFurigana(termContainer, term, reading, this._appendKanjiLinks.bind(this));
325
+ return node;
326
+ }
327
+ _createInflectionRuleChain(inflectionRuleChain) {
328
+ const { source, inflectionRules } = inflectionRuleChain;
329
+ if (!Array.isArray(inflectionRules) || inflectionRules.length === 0) return null;
330
+ const fragment = this._instantiate("inflection-rule-chain");
331
+ const sourceIcon = this._getInflectionSourceIcon(source);
332
+ fragment.appendChild(sourceIcon);
333
+ this._appendMultiple(fragment, this._createTermInflection.bind(this), inflectionRules);
334
+ return fragment;
335
+ }
336
+ _getInflectionSourceIcon(source) {
337
+ const icon = this._document.createElement("span");
338
+ icon.classList.add("inflection-source-icon");
339
+ icon.dataset.inflectionSource = source;
340
+ switch (source) {
341
+ case "dictionary":
342
+ icon.title = "Dictionary Deinflection";
343
+ return icon;
344
+ case "algorithm":
345
+ icon.title = "Algorithm Deinflection";
346
+ return icon;
347
+ case "both":
348
+ icon.title = "Dictionary and Algorithm Deinflection";
349
+ return icon;
350
+ }
351
+ }
352
+ _createTermInflection(inflection) {
353
+ const { name, description } = inflection;
354
+ const fragment = this._templates.instantiateFragment("inflection");
355
+ const node = this._querySelector(fragment, ".inflection");
356
+ this._setTextContent(node, name);
357
+ if (description) node.title = description;
358
+ node.dataset.reason = name;
359
+ return fragment;
360
+ }
361
+ _createTermDefinition(definition, dictionaryTag, headwords, uniqueTerms, uniqueReadings) {
362
+ const { dictionary, tags, headwordIndices, entries } = definition;
363
+ const disambiguations = require_dictionary_data_util.getDisambiguations(headwords, headwordIndices, uniqueTerms, uniqueReadings);
364
+ const node = this._instantiate("definition-item");
365
+ const tagListContainer = this._querySelector(node, ".definition-tag-list");
366
+ const onlyListContainer = this._querySelector(node, ".definition-disambiguation-list");
367
+ const entriesContainer = this._querySelector(node, ".gloss-list");
368
+ node.dataset.dictionary = dictionary;
369
+ this._appendMultiple(tagListContainer, this._createTag.bind(this), [...tags, dictionaryTag]);
370
+ this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), disambiguations);
371
+ this._appendMultiple(entriesContainer, this._createTermDefinitionEntry.bind(this), entries, dictionary);
372
+ return node;
373
+ }
374
+ _createTermDefinitionEntry(entry, dictionary) {
375
+ switch (typeof entry) {
376
+ case "string": return this._createTermDefinitionEntryText(entry);
377
+ case "object": {
378
+ switch (entry.type) {
379
+ case "image": return this._createTermDefinitionEntryImage(entry, dictionary);
380
+ case "structured-content": return this._createTermDefinitionEntryStructuredContent(entry.content, dictionary);
381
+ case "text": break;
382
+ }
383
+ break;
384
+ }
385
+ }
386
+ return null;
387
+ }
388
+ _createTermDefinitionEntryText(text) {
389
+ const node = this._instantiate("gloss-item");
390
+ const container = this._querySelector(node, ".gloss-content");
391
+ this._setMultilineTextContent(container, text);
392
+ return node;
393
+ }
394
+ _createTermDefinitionEntryImage(data, dictionary) {
395
+ const { description } = data;
396
+ const node = this._instantiate("gloss-item");
397
+ const contentContainer = this._querySelector(node, ".gloss-content");
398
+ const image = this._structuredContentGenerator.createDefinitionImage(data, dictionary);
399
+ contentContainer.appendChild(image);
400
+ if (typeof description === "string") {
401
+ const fragment = this._templates.instantiateFragment("gloss-item-image-description");
402
+ const container = this._querySelector(fragment, ".gloss-image-description");
403
+ this._setMultilineTextContent(container, description);
404
+ contentContainer.appendChild(fragment);
405
+ }
406
+ return node;
407
+ }
408
+ _createTermDefinitionEntryStructuredContent(content, dictionary) {
409
+ const node = this._instantiate("gloss-item");
410
+ const contentContainer = this._querySelector(node, ".gloss-content");
411
+ this._structuredContentGenerator.appendStructuredContent(contentContainer, content, dictionary);
412
+ return node;
413
+ }
414
+ _createTermDisambiguation(disambiguation) {
415
+ const node = this._instantiate("definition-disambiguation");
416
+ node.dataset.term = disambiguation;
417
+ this._setTextContent(node, disambiguation, this._language);
418
+ return node;
419
+ }
420
+ _createKanjiLink(character) {
421
+ const node = this._document.createElement("a");
422
+ node.className = "headword-kanji-link";
423
+ this._setTextContent(node, character, this._language);
424
+ return node;
425
+ }
426
+ _createKanjiDefinition(text) {
427
+ const node = this._instantiate("kanji-gloss-item");
428
+ const container = this._querySelector(node, ".kanji-gloss-content");
429
+ this._setMultilineTextContent(container, text);
430
+ return node;
431
+ }
432
+ _createKanjiReading(reading) {
433
+ const node = this._instantiate("kanji-reading");
434
+ this._setTextContent(node, reading, this._language);
435
+ return node;
436
+ }
437
+ _createKanjiInfoTable(details) {
438
+ const node = this._instantiate("kanji-info-table");
439
+ const container = this._querySelector(node, ".kanji-info-table-body");
440
+ const count = this._appendMultiple(container, this._createKanjiInfoTableItem.bind(this), details);
441
+ if (count === 0) {
442
+ const n = this._createKanjiInfoTableItemEmpty();
443
+ container.appendChild(n);
444
+ }
445
+ return node;
446
+ }
447
+ _createKanjiInfoTableItem(details) {
448
+ const { content, name, value } = details;
449
+ const node = this._instantiate("kanji-info-table-item");
450
+ const nameNode = this._querySelector(node, ".kanji-info-table-item-header");
451
+ const valueNode = this._querySelector(node, ".kanji-info-table-item-value");
452
+ this._setTextContent(nameNode, content.length > 0 ? content : name);
453
+ this._setTextContent(valueNode, typeof value === "string" ? value : `${value}`);
454
+ return node;
455
+ }
456
+ _createKanjiInfoTableItemEmpty() {
457
+ return this._instantiate("kanji-info-table-empty");
458
+ }
459
+ _createTag(tag) {
460
+ const { content, name, category, redundant } = tag;
461
+ const node = this._instantiate("tag");
462
+ const inner = this._querySelector(node, ".tag-label-content");
463
+ const contentString = content.join("\n");
464
+ node.title = contentString;
465
+ this._setTextContent(inner, name);
466
+ node.dataset.details = contentString.length > 0 ? contentString : name;
467
+ node.dataset.category = category;
468
+ if (redundant) node.dataset.redundant = "true";
469
+ return node;
470
+ }
471
+ _createTermTag(tagInfo, totalHeadwordCount) {
472
+ const { tag, headwordIndices } = tagInfo;
473
+ const node = this._createTag(tag);
474
+ node.dataset.headwords = headwordIndices.join(" ");
475
+ node.dataset.totalHeadwordCount = `${totalHeadwordCount}`;
476
+ node.dataset.matchedHeadwordCount = `${headwordIndices.length}`;
477
+ node.dataset.unmatchedHeadwordCount = `${Math.max(0, totalHeadwordCount - headwordIndices.length)}`;
478
+ return node;
479
+ }
480
+ _createTagData(name, category) {
481
+ return {
482
+ name,
483
+ category,
484
+ order: 0,
485
+ score: 0,
486
+ content: [],
487
+ dictionaries: [],
488
+ redundant: false
489
+ };
490
+ }
491
+ _createSearchTag(text) {
492
+ return this._createTag(this._createTagData(text, "search"));
493
+ }
494
+ _createGroupedPronunciation(details) {
495
+ const { dictionary, dictionaryAlias, pronunciations } = details;
496
+ const node = this._instantiate("pronunciation-group");
497
+ node.dataset.dictionary = dictionary;
498
+ node.dataset.pronunciationsMulti = "true";
499
+ node.dataset.pronunciationsCount = `${pronunciations.length}`;
500
+ const n1 = this._querySelector(node, ".pronunciation-group-tag-list");
501
+ const tag = this._createTag(this._createTagData(dictionaryAlias, "pronunciation-dictionary"));
502
+ tag.dataset.details = dictionary;
503
+ n1.appendChild(tag);
504
+ let hasTags = false;
505
+ for (const { pronunciation: { tags } } of pronunciations) if (tags.length > 0) {
506
+ hasTags = true;
507
+ break;
508
+ }
509
+ const n = this._querySelector(node, ".pronunciation-list");
510
+ n.dataset.hasTags = `${hasTags}`;
511
+ this._appendMultiple(n, this._createPronunciation.bind(this), pronunciations);
512
+ return node;
513
+ }
514
+ _createPronunciation(details) {
515
+ const { pronunciation } = details;
516
+ switch (pronunciation.type) {
517
+ case "pitch-accent": return this._createPronunciationPitchAccent(pronunciation, details);
518
+ case "phonetic-transcription": return this._createPronunciationPhoneticTranscription(pronunciation, details);
519
+ }
520
+ }
521
+ _createPronunciationPhoneticTranscription(pronunciation, details) {
522
+ const { ipa, tags } = pronunciation;
523
+ const { exclusiveTerms, exclusiveReadings } = details;
524
+ const node = this._instantiate("pronunciation");
525
+ node.dataset.pronunciationType = pronunciation.type;
526
+ node.dataset.tagCount = `${tags.length}`;
527
+ let n = this._querySelector(node, ".pronunciation-tag-list");
528
+ this._appendMultiple(n, this._createTag.bind(this), tags);
529
+ n = this._querySelector(node, ".pronunciation-disambiguation-list");
530
+ this._createPronunciationDisambiguations(n, exclusiveTerms, exclusiveReadings);
531
+ n = this._querySelector(node, ".pronunciation-text-container");
532
+ this._setTextContent(n, ipa);
533
+ return node;
534
+ }
535
+ _createPronunciationPitchAccent(pitchAccent, details) {
536
+ const { positions, nasalPositions, devoicePositions, tags } = pitchAccent;
537
+ const { reading, exclusiveTerms, exclusiveReadings } = details;
538
+ const morae = require_pronunciation_generator.getKanaMorae(reading);
539
+ const node = this._instantiate("pronunciation");
540
+ node.dataset.pitchAccentDownstepPosition = `${positions}`;
541
+ node.dataset.pronunciationType = pitchAccent.type;
542
+ if (nasalPositions.length > 0) node.dataset.nasalMoraPosition = nasalPositions.join(" ");
543
+ if (devoicePositions.length > 0) node.dataset.devoiceMoraPosition = devoicePositions.join(" ");
544
+ node.dataset.tagCount = `${tags.length}`;
545
+ let n = this._querySelector(node, ".pronunciation-tag-list");
546
+ this._appendMultiple(n, this._createTag.bind(this), tags);
547
+ n = this._querySelector(node, ".pronunciation-disambiguation-list");
548
+ this._createPronunciationDisambiguations(n, exclusiveTerms, exclusiveReadings);
549
+ n = this._querySelector(node, ".pronunciation-downstep-notation-container");
550
+ n.appendChild(this._pronunciationGenerator.createPronunciationDownstepPosition(positions));
551
+ n = this._querySelector(node, ".pronunciation-text-container");
552
+ n.lang = this._language;
553
+ n.appendChild(this._pronunciationGenerator.createPronunciationText(morae, positions, nasalPositions, devoicePositions));
554
+ n = this._querySelector(node, ".pronunciation-graph-container");
555
+ n.appendChild(this._pronunciationGenerator.createPronunciationGraph(morae, positions));
556
+ return node;
557
+ }
558
+ _createPronunciationDisambiguations(container, exclusiveTerms, exclusiveReadings) {
559
+ const templateName = "pronunciation-disambiguation";
560
+ for (const term of exclusiveTerms) {
561
+ const node = this._instantiate(templateName);
562
+ node.dataset.type = "term";
563
+ this._setTextContent(node, term, this._language);
564
+ container.appendChild(node);
565
+ }
566
+ for (const exclusiveReading of exclusiveReadings) {
567
+ const node = this._instantiate(templateName);
568
+ node.dataset.type = "reading";
569
+ this._setTextContent(node, exclusiveReading, this._language);
570
+ container.appendChild(node);
571
+ }
572
+ container.dataset.count = `${exclusiveTerms.length + exclusiveReadings.length}`;
573
+ container.dataset.termCount = `${exclusiveTerms.length}`;
574
+ container.dataset.readingCount = `${exclusiveReadings.length}`;
575
+ }
576
+ _createFrequencyGroup(details, kanji) {
577
+ const { dictionary, dictionaryAlias, frequencies, freqCount } = details;
578
+ const node = this._instantiate("frequency-group-item");
579
+ const body = this._querySelector(node, ".tag-body-content");
580
+ const tagLabel = this._querySelector(node, ".tag-label-content");
581
+ const tag = this._querySelector(node, ".tag");
582
+ this._setTextContent(tagLabel, dictionaryAlias);
583
+ const ii = frequencies.length;
584
+ for (let i = 0; i < ii; ++i) {
585
+ const item = frequencies[i];
586
+ const itemNode = kanji ? this._createKanjiFrequency(item, dictionary, dictionaryAlias, freqCount?.toString()) : this._createTermFrequency(item, dictionary, dictionaryAlias, freqCount?.toString());
587
+ itemNode.dataset.index = `${i}`;
588
+ body.appendChild(itemNode);
589
+ }
590
+ body.dataset.count = `${ii}`;
591
+ node.dataset.count = `${ii}`;
592
+ node.dataset.details = dictionary;
593
+ tag.dataset.details = `${dictionary}\nDictionary size: ${freqCount?.toString()}${kanji ? " kanji" : " terms"}`;
594
+ return node;
595
+ }
596
+ _createTermFrequency(details, dictionary, dictionaryAlias, freqCount) {
597
+ const { term, reading, values } = details;
598
+ const node = this._instantiate("term-frequency-item");
599
+ const tagLabel = this._querySelector(node, ".tag-label-content");
600
+ const tag = this._querySelector(node, ".tag");
601
+ const disambiguationTerm = this._querySelector(node, ".frequency-disambiguation-term");
602
+ const disambiguationReading = this._querySelector(node, ".frequency-disambiguation-reading");
603
+ const frequencyValueList = this._querySelector(node, ".frequency-value-list");
604
+ this._setTextContent(tagLabel, dictionaryAlias);
605
+ this._setTextContent(disambiguationTerm, term, this._language);
606
+ this._setTextContent(disambiguationReading, reading !== null ? reading : "", this._language);
607
+ this._populateFrequencyValueList(frequencyValueList, values);
608
+ node.dataset.term = term;
609
+ if (typeof reading === "string") node.dataset.reading = reading;
610
+ node.dataset.hasReading = `${reading !== null}`;
611
+ node.dataset.readingIsSame = `${reading === term}`;
612
+ node.dataset.dictionary = dictionary;
613
+ node.dataset.details = dictionary;
614
+ tag.dataset.details = `${dictionary}\nDictionary size: ${freqCount ?? ""} terms`;
615
+ return node;
616
+ }
617
+ _createKanjiFrequency(details, dictionary, dictionaryAlias, freqCount) {
618
+ const { character, values } = details;
619
+ const node = this._instantiate("kanji-frequency-item");
620
+ const tagLabel = this._querySelector(node, ".tag-label-content");
621
+ const tag = this._querySelector(node, ".tag");
622
+ const frequencyValueList = this._querySelector(node, ".frequency-value-list");
623
+ this._setTextContent(tagLabel, dictionaryAlias);
624
+ this._populateFrequencyValueList(frequencyValueList, values);
625
+ node.dataset.character = character;
626
+ node.dataset.dictionary = dictionary;
627
+ node.dataset.details = dictionary;
628
+ tag.dataset.details = `${dictionary}\nDictionary size: ${freqCount ?? ""} kanji`;
629
+ return node;
630
+ }
631
+ _populateFrequencyValueList(node, values) {
632
+ let fullFrequency = "";
633
+ for (let i = 0, ii = values.length; i < ii; ++i) {
634
+ const { frequency, displayValue } = values[i];
635
+ const frequencyString = `${frequency}`;
636
+ const text = displayValue !== null ? displayValue : `${frequency}`;
637
+ if (i > 0) {
638
+ const node2$1 = this._document.createElement("span");
639
+ node2$1.className = "frequency-value";
640
+ node2$1.dataset.frequency = `${frequency}`;
641
+ node2$1.textContent = ", ";
642
+ node.appendChild(node2$1);
643
+ fullFrequency += ", ";
644
+ }
645
+ const node2 = this._document.createElement("span");
646
+ node2.className = "frequency-value";
647
+ node2.dataset.frequency = frequencyString;
648
+ if (displayValue !== null) {
649
+ node2.dataset.displayValue = `${displayValue}`;
650
+ if (displayValue !== frequencyString) node2.title = frequencyString;
651
+ }
652
+ this._setTextContent(node2, text, this._language);
653
+ node.appendChild(node2);
654
+ fullFrequency += text;
655
+ }
656
+ node.dataset.frequency = fullFrequency;
657
+ }
658
+ _appendKanjiLinks(container, text) {
659
+ let part = "";
660
+ for (const c of text) if (require_pronunciation_generator.isCodePointKanji(c.codePointAt(0))) {
661
+ if (part.length > 0) {
662
+ container.appendChild(this._document.createTextNode(part));
663
+ part = "";
664
+ }
665
+ const link = this._createKanjiLink(c);
666
+ container.appendChild(link);
667
+ } else part += c;
668
+ if (part.length > 0) container.appendChild(this._document.createTextNode(part));
669
+ }
670
+ _appendMultiple(container, createItem, detailsArray, arg) {
671
+ let count = 0;
672
+ const ELEMENT_NODE = 1;
673
+ if (Array.isArray(detailsArray)) for (const details of detailsArray) {
674
+ const item = createItem(details, arg);
675
+ if (item === null) continue;
676
+ container.appendChild(item);
677
+ if (item.nodeType === ELEMENT_NODE) item.dataset.index = `${count}`;
678
+ ++count;
679
+ }
680
+ container.dataset.count = `${count}`;
681
+ return count;
682
+ }
683
+ _appendFurigana(container, term, reading, addText) {
684
+ container.lang = this._language;
685
+ const segments = require_furigana.distributeFurigana(term, reading);
686
+ for (const { text, reading: furigana } of segments) if (furigana) {
687
+ const ruby = this._document.createElement("ruby");
688
+ const rt = this._document.createElement("rt");
689
+ addText(ruby, text);
690
+ ruby.appendChild(rt);
691
+ rt.appendChild(this._document.createTextNode(furigana));
692
+ container.appendChild(ruby);
693
+ } else addText(container, text);
694
+ }
695
+ _createDictionaryTag(dictionary) {
696
+ return this._createTagData(dictionary, "dictionary");
697
+ }
698
+ _setTextContent(node, value, language) {
699
+ this._setElementLanguage(node, language, value);
700
+ node.textContent = value;
701
+ }
702
+ _setMultilineTextContent(node, value, language) {
703
+ this._setElementLanguage(node, language, value);
704
+ let start = 0;
705
+ while (true) {
706
+ const end = value.indexOf("\n", start);
707
+ if (end < 0) break;
708
+ node.appendChild(this._document.createTextNode(value.substring(start, end)));
709
+ node.appendChild(this._document.createElement("br"));
710
+ start = end + 1;
711
+ }
712
+ if (start < value.length) node.appendChild(this._document.createTextNode(start === 0 ? value : value.substring(start)));
713
+ }
714
+ _setElementLanguage(element, language, content) {
715
+ if (typeof language === "string") element.lang = language;
716
+ else {
717
+ const language2 = require_text_utilities.getLanguageFromText(content, this._language);
718
+ if (language2 !== null) element.lang = language2;
719
+ }
720
+ }
721
+ _getPronunciationCategories(reading, termPronunciations, wordClasses, headwordIndex) {
722
+ if (termPronunciations.length === 0) return null;
723
+ const isVerbOrAdjective = require_dictionary_data_util.isNonNounVerbOrAdjective(wordClasses);
724
+ const categories = new Set();
725
+ for (const termPronunciation of termPronunciations) {
726
+ if (termPronunciation.headwordIndex !== headwordIndex) continue;
727
+ for (const pronunciation of termPronunciation.pronunciations) {
728
+ if (pronunciation.type !== "pitch-accent") continue;
729
+ const category = require_pronunciation_generator.getPitchCategory(reading, pronunciation.positions, isVerbOrAdjective);
730
+ if (category !== null) categories.add(category);
731
+ }
732
+ }
733
+ return categories.size > 0 ? [...categories].join(" ") : null;
734
+ }
735
+ _instantiate(name) {
736
+ return this._templates.instantiate(name);
737
+ }
738
+ _querySelector(element, selector) {
739
+ const result = element.querySelector(selector);
740
+ if (result === null) throw new Error(`Failed to find element: ${selector}`);
741
+ return result;
742
+ }
743
+ };
744
+
745
+ //#endregion
746
+ Object.defineProperty(exports, 'DisplayGenerator', {
747
+ enumerable: true,
748
+ get: function () {
749
+ return DisplayGenerator;
750
+ }
751
+ });
752
+ Object.defineProperty(exports, 'HtmlTemplateCollection', {
753
+ enumerable: true,
754
+ get: function () {
755
+ return HtmlTemplateCollection;
756
+ }
757
+ });
758
+ //# sourceMappingURL=display-generator-DyP-HNzP.cjs.map